macOS: officially upgrade to 10.9 libraries from lib/darwin.
[blender.git] / GNUmakefile
1 # -*- mode: gnumakefile; tab-width: 4; indent-tabs-mode: t; -*-
2 # vim: tabstop=4
3 #
4 # ##### BEGIN GPL LICENSE BLOCK #####
5 #
6 #  This program is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU General Public License
8 #  as published by the Free Software Foundation; either version 2
9 #  of the License, or (at your option) any later version.
10 #
11 #  This program is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #  GNU General Public License for more details.
15 #
16 #  You should have received a copy of the GNU General Public License
17 #  along with this program; if not, write to the Free Software Foundation,
18 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #
20 # ##### END GPL LICENSE BLOCK #####
21
22 # This Makefile does an out-of-source CMake build in ../build_`OS`_`CPU`
23 # eg:
24 #   ../build_linux_i386
25 # This is for users who like to configure & build blender with a single command.
26
27
28 # System Vars
29 OS:=$(shell uname -s)
30 OS_NCASE:=$(shell uname -s | tr '[A-Z]' '[a-z]')
31 # CPU:=$(shell uname -m)  # UNUSED
32
33
34 # Source and Build DIR's
35 BLENDER_DIR:=$(shell pwd -P)
36 BUILD_TYPE:=Release
37
38 ifndef BUILD_CMAKE_ARGS
39         BUILD_CMAKE_ARGS:=
40 endif
41
42 ifndef BUILD_DIR
43         BUILD_DIR:=$(shell dirname "$(BLENDER_DIR)")/build_$(OS_NCASE)
44 endif
45
46 # Dependencies DIR's
47 DEPS_SOURCE_DIR:=$(BLENDER_DIR)/build_files/build_environment
48 DEPS_BUILD_DIR:=$(BUILD_DIR)/deps
49 DEPS_INSTALL_DIR:=$(shell dirname "$(BLENDER_DIR)")/lib/$(OS_NCASE)
50
51 # Allow to use alternative binary (pypy3, etc)
52 ifndef PYTHON
53         PYTHON:=python3
54 endif
55
56
57 # -----------------------------------------------------------------------------
58 # additional targets for the build configuration
59
60 # support 'make debug'
61 ifneq "$(findstring debug, $(MAKECMDGOALS))" ""
62         BUILD_DIR:=$(BUILD_DIR)_debug
63         BUILD_TYPE:=Debug
64 endif
65 ifneq "$(findstring full, $(MAKECMDGOALS))" ""
66         BUILD_DIR:=$(BUILD_DIR)_full
67         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/blender_full.cmake"
68 endif
69 ifneq "$(findstring lite, $(MAKECMDGOALS))" ""
70         BUILD_DIR:=$(BUILD_DIR)_lite
71         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/blender_lite.cmake"
72 endif
73 ifneq "$(findstring cycles, $(MAKECMDGOALS))" ""
74         BUILD_DIR:=$(BUILD_DIR)_cycles
75         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/cycles_standalone.cmake"
76 endif
77 ifneq "$(findstring headless, $(MAKECMDGOALS))" ""
78         BUILD_DIR:=$(BUILD_DIR)_headless
79         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/blender_headless.cmake"
80 endif
81 ifneq "$(findstring bpy, $(MAKECMDGOALS))" ""
82         BUILD_DIR:=$(BUILD_DIR)_bpy
83         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/bpy_module.cmake"
84 endif
85
86
87 # -----------------------------------------------------------------------------
88 # Get the number of cores for threaded build
89 ifndef NPROCS
90         NPROCS:=1
91         ifeq ($(OS), Linux)
92                 NPROCS:=$(shell nproc)
93         endif
94         ifneq (,$(filter $(OS),Darwin FreeBSD NetBSD))
95                 NPROCS:=$(shell sysctl -n hw.ncpu)
96         endif
97 endif
98
99
100 # -----------------------------------------------------------------------------
101 # Macro for configuring cmake
102
103 CMAKE_CONFIG = cmake $(BUILD_CMAKE_ARGS) \
104                      -H"$(BLENDER_DIR)" \
105                      -B"$(BUILD_DIR)" \
106                      -DCMAKE_BUILD_TYPE_INIT:STRING=$(BUILD_TYPE)
107
108
109 # -----------------------------------------------------------------------------
110 # Tool for 'make config'
111
112 # X11 spesific
113 ifdef DISPLAY
114         CMAKE_CONFIG_TOOL = cmake-gui
115 else
116         CMAKE_CONFIG_TOOL = ccmake
117 endif
118
119
120 # -----------------------------------------------------------------------------
121 # Build Blender
122 all: .FORCE
123         @echo
124         @echo Configuring Blender in \"$(BUILD_DIR)\" ...
125
126 #       # if test ! -f $(BUILD_DIR)/CMakeCache.txt ; then \
127 #       #       $(CMAKE_CONFIG); \
128 #       # fi
129
130 #       # do this always incase of failed initial build, could be smarter here...
131         @$(CMAKE_CONFIG)
132
133         @echo
134         @echo Building Blender ...
135         $(MAKE) -C "$(BUILD_DIR)" -s -j $(NPROCS) install
136         @echo
137         @echo edit build configuration with: "$(BUILD_DIR)/CMakeCache.txt" run make again to rebuild.
138         @echo Blender successfully built, run from: "$(BUILD_DIR)/bin/blender"
139         @echo
140
141 debug: all
142 full: all
143 lite: all
144 cycles: all
145 headless: all
146 bpy: all
147
148 # -----------------------------------------------------------------------------
149 # Build dependencies
150 DEPS_TARGET = install
151 ifneq "$(findstring clean, $(MAKECMDGOALS))" ""
152         DEPS_TARGET = clean
153 endif
154
155 deps: .FORCE
156         @echo
157         @echo Configuring dependencies in \"$(DEPS_BUILD_DIR)\"
158
159         @cmake -H"$(DEPS_SOURCE_DIR)" \
160                -B"$(DEPS_BUILD_DIR)" \
161                    -DHARVEST_TARGET=$(DEPS_INSTALL_DIR)
162
163         @echo
164         @echo Building dependencies ...
165         $(MAKE) -C "$(DEPS_BUILD_DIR)" -s -j $(NPROCS) $(DEPS_TARGET)
166         @echo
167         @echo Dependencies successfully built and installed to $(DEPS_INSTALL_DIR).
168         @echo
169
170 # -----------------------------------------------------------------------------
171 # Configuration (save some cd'ing around)
172 config: .FORCE
173         $(CMAKE_CONFIG_TOOL) "$(BUILD_DIR)"
174
175
176 # -----------------------------------------------------------------------------
177 # Help for build targets
178 help: .FORCE
179         @echo ""
180         @echo "Convenience targets provided for building blender, (multiple at once can be used)"
181         @echo "  * debug     - build a debug binary"
182         @echo "  * full      - enable all supported dependencies & options"
183         @echo "  * lite      - disable non essential features for a smaller binary and faster build"
184         @echo "  * headless  - build without an interface (renderfarm or server automation)"
185         @echo "  * cycles    - build Cycles standalone only, without Blender"
186         @echo "  * bpy       - build as a python module which can be loaded from python directly"
187         @echo "  * deps      - build library dependencies (intended only for platform maintainers)"
188         @echo ""
189         @echo "  * config    - run cmake configuration tool to set build options"
190         @echo ""
191         @echo "  Note, passing the argument 'BUILD_DIR=path' when calling make will override the default build dir."
192         @echo "  Note, passing the argument 'BUILD_CMAKE_ARGS=args' lets you add cmake arguments."
193         @echo ""
194         @echo ""
195         @echo "Project Files for IDE's"
196         @echo "  * project_qtcreator - QtCreator Project Files"
197         @echo "  * project_netbeans  - NetBeans Project Files"
198         @echo "  * project_eclipse   - Eclipse CDT4 Project Files"
199         @echo ""
200         @echo "Package Targets"
201         @echo "  * package_debian  - build a debian package"
202         @echo "  * package_pacman  - build an arch linux pacman package"
203         @echo "  * package_archive - build an archive package"
204         @echo ""
205         @echo "Testing Targets (not associated with building blender)"
206         @echo "  * test               - run ctest, currently tests import/export,"
207         @echo "                         operator execution and that python modules load"
208         @echo "  * test_cmake         - runs our own cmake file checker"
209         @echo "                         which detects errors in the cmake file list definitions"
210         @echo "  * test_pep8          - checks all python script are pep8"
211         @echo "                         which are tagged to use the stricter formatting"
212         @echo "  * test_deprecated    - checks for deprecation tags in our code which may need to be removed"
213         @echo "  * test_style_c       - checks C/C++ conforms with blenders style guide:"
214         @echo "                         http://wiki.blender.org/index.php/Dev:Doc/CodeStyle"
215         @echo "  * test_style_c_qtc   - same as test_style but outputs QtCreator tasks format"
216         @echo "  * test_style_osl     - checks OpenShadingLanguage conforms with blenders style guide:"
217         @echo "                         http://wiki.blender.org/index.php/Dev:Doc/CodeStyle"
218         @echo "  * test_style_osl_qtc - checks OpenShadingLanguage conforms with blenders style guide:"
219         @echo "                         http://wiki.blender.org/index.php/Dev:Doc/CodeStyle"
220         @echo ""
221         @echo "Static Source Code Checking (not associated with building blender)"
222         @echo "  * check_cppcheck       - run blender source through cppcheck (C & C++)"
223         @echo "  * check_clang_array    - run blender source through clang array checking script (C & C++)"
224         @echo "  * check_splint         - run blenders source through splint (C only)"
225         @echo "  * check_sparse         - run blenders source through sparse (C only)"
226         @echo "  * check_smatch         - run blenders source through smatch (C only)"
227         @echo "  * check_spelling_c     - check for spelling errors (C/C++ only)"
228         @echo "  * check_spelling_c_qtc - same as check_spelling_c but outputs QtCreator tasks format"
229         @echo "  * check_spelling_osl   - check for spelling errors (OSL only)"
230         @echo "  * check_spelling_py    - check for spelling errors (Python only)"
231         @echo "  * check_descriptions   - check for duplicate/invalid descriptions"
232         @echo ""
233         @echo "Utilities (not associated with building blender)"
234         @echo "  * icons    - updates PNG icons from SVG files."
235         @echo "  * tgz      - create a compressed archive of the source code."
236         @echo "  * update   - updates git and all submodules"
237         @echo ""
238         @echo "Environment Variables"
239         @echo "  * BUILD_CMAKE_ARGS    - arguments passed to CMake."
240         @echo "  * BUILD_DIR           - override default build path."
241         @echo "  * PYTHON              - use this for the Python command (used for checking tools)."
242         @echo "  * NPROCS              - number of processes to use building (auto-detect when omitted)."
243         @echo ""
244         @echo "Documentation Targets (not associated with building blender)"
245         @echo "  * doc_py   - generate sphinx python api docs"
246         @echo "  * doc_doxy - generate doxygen C/C++ docs"
247         @echo "  * doc_dna  - generate blender file format reference"
248         @echo "  * doc_man  - generate manpage"
249         @echo ""
250         @echo "Information"
251         @echo "  * help          - this help message"
252         @echo "  * help_features - show a list of optional features when building"
253         @echo ""
254
255 # -----------------------------------------------------------------------------
256 # Packages
257 #
258 package_debian: .FORCE
259         cd build_files/package_spec ; DEB_BUILD_OPTIONS="parallel=$(NPROCS)" sh ./build_debian.sh
260
261 package_pacman: .FORCE
262         cd build_files/package_spec/pacman ; MAKEFLAGS="-j$(NPROCS)" makepkg
263
264 package_archive: .FORCE
265         make -C "$(BUILD_DIR)" -s package_archive
266         @echo archive in "$(BUILD_DIR)/release"
267
268
269 # -----------------------------------------------------------------------------
270 # Tests
271 #
272 test: .FORCE
273         cd $(BUILD_DIR) ; ctest . --output-on-failure
274
275 # run pep8 check check on scripts we distribute.
276 test_pep8: .FORCE
277         $(PYTHON) tests/python/pep8.py > test_pep8.log 2>&1
278         @echo "written: test_pep8.log"
279
280 # run some checks on our cmakefiles.
281 test_cmake: .FORCE
282         $(PYTHON) build_files/cmake/cmake_consistency_check.py > test_cmake_consistency.log 2>&1
283         @echo "written: test_cmake_consistency.log"
284
285 # run deprecation tests, see if we have anything to remove.
286 test_deprecated: .FORCE
287         $(PYTHON) tests/check_deprecated.py
288
289 test_style_c: .FORCE
290         # run our own checks on C/C++ style
291         PYTHONIOENCODING=utf_8 $(PYTHON) \
292             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
293             "$(BLENDER_DIR)/source/blender" \
294             "$(BLENDER_DIR)/source/creator" \
295             --no-length-check
296
297 test_style_c_qtc: .FORCE
298         # run our own checks on C/C++ style
299         USE_QTC_TASK=1 \
300         PYTHONIOENCODING=utf_8 $(PYTHON) \
301             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
302             "$(BLENDER_DIR)/source/blender" \
303             "$(BLENDER_DIR)/source/creator" \
304             --no-length-check \
305             > \
306             "$(BLENDER_DIR)/test_style.tasks"
307         @echo "written: test_style.tasks"
308
309
310 test_style_osl: .FORCE
311         # run our own checks on C/C++ style
312         PYTHONIOENCODING=utf_8 $(PYTHON) \
313             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
314             "$(BLENDER_DIR)/intern/cycles/kernel/shaders" \
315             "$(BLENDER_DIR)/release/scripts/templates_osl"
316
317
318 test_style_osl_qtc: .FORCE
319         # run our own checks on C/C++ style
320         USE_QTC_TASK=1 \
321         PYTHONIOENCODING=utf_8 $(PYTHON) \
322             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
323             "$(BLENDER_DIR)/intern/cycles/kernel/shaders" \
324             "$(BLENDER_DIR)/release/scripts/templates_osl" \
325             > \
326             "$(BLENDER_DIR)/test_style.tasks"
327         @echo "written: test_style.tasks"
328
329 # -----------------------------------------------------------------------------
330 # Project Files
331 #
332
333 project_qtcreator: .FORCE
334         $(PYTHON) build_files/cmake/cmake_qtcreator_project.py "$(BUILD_DIR)"
335
336 project_netbeans: .FORCE
337         $(PYTHON) build_files/cmake/cmake_netbeans_project.py "$(BUILD_DIR)"
338
339 project_eclipse: .FORCE
340         cmake -G"Eclipse CDT4 - Unix Makefiles" -H"$(BLENDER_DIR)" -B"$(BUILD_DIR)"
341
342
343 # -----------------------------------------------------------------------------
344 # Static Checking
345 #
346
347 check_cppcheck: .FORCE
348         $(CMAKE_CONFIG)
349         cd "$(BUILD_DIR)" ; \
350         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_cppcheck.py" 2> \
351             "$(BLENDER_DIR)/check_cppcheck.txt"
352         @echo "written: check_cppcheck.txt"
353
354 check_clang_array: .FORCE
355         $(CMAKE_CONFIG)
356         cd "$(BUILD_DIR)" ; \
357         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_clang_array.py"
358
359 check_splint: .FORCE
360         $(CMAKE_CONFIG)
361         cd "$(BUILD_DIR)" ; \
362         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_splint.py"
363
364 check_sparse: .FORCE
365         $(CMAKE_CONFIG)
366         cd "$(BUILD_DIR)" ; \
367         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_sparse.py"
368
369 check_smatch: .FORCE
370         $(CMAKE_CONFIG)
371         cd "$(BUILD_DIR)" ; \
372         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_smatch.py"
373
374 check_spelling_py: .FORCE
375         cd "$(BUILD_DIR)" ; \
376         PYTHONIOENCODING=utf_8 $(PYTHON) \
377             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
378             "$(BLENDER_DIR)/release/scripts"
379
380 check_spelling_c: .FORCE
381         cd "$(BUILD_DIR)" ; \
382         PYTHONIOENCODING=utf_8 $(PYTHON) \
383             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
384             "$(BLENDER_DIR)/source" \
385             "$(BLENDER_DIR)/intern/cycles" \
386             "$(BLENDER_DIR)/intern/guardedalloc" \
387             "$(BLENDER_DIR)/intern/ghost" \
388
389 check_spelling_c_qtc: .FORCE
390         cd "$(BUILD_DIR)" ; USE_QTC_TASK=1 \
391         PYTHONIOENCODING=utf_8 $(PYTHON) \
392             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
393             "$(BLENDER_DIR)/source" \
394             "$(BLENDER_DIR)/intern/cycles" \
395             "$(BLENDER_DIR)/intern/guardedalloc" \
396             "$(BLENDER_DIR)/intern/ghost" \
397             > \
398             "$(BLENDER_DIR)/check_spelling_c.tasks"
399
400 check_spelling_osl: .FORCE
401         cd "$(BUILD_DIR)" ;\
402         PYTHONIOENCODING=utf_8 $(PYTHON) \
403             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
404             "$(BLENDER_DIR)/intern/cycles/kernel/shaders"
405
406 check_descriptions: .FORCE
407         "$(BUILD_DIR)/bin/blender" --background -noaudio --factory-startup --python \
408             "$(BLENDER_DIR)/source/tools/check_source/check_descriptions.py"
409
410 # -----------------------------------------------------------------------------
411 # Utilities
412 #
413
414 tgz: .FORCE
415         ./build_files/utils/build_tgz.sh
416
417 icons: .FORCE
418         "$(BLENDER_DIR)/release/datafiles/blender_icons_update.py"
419         "$(BLENDER_DIR)/release/datafiles/prvicons_update.py"
420
421 update: .FORCE
422         if [ "$(OS_NCASE)" == "darwin" ] && [ ! -d "../lib/$(OS_NCASE)" ]; then \
423                 svn checkout https://svn.blender.org/svnroot/bf-blender/trunk/lib/$(OS_NCASE) ../lib/$(OS_NCASE) ; \
424         fi
425         if [ -d "../lib" ]; then \
426                 svn cleanup ../lib/* ; \
427                 svn update ../lib/* ; \
428         fi
429         git submodule update --init --recursive
430         git submodule foreach git checkout master
431         git submodule foreach git pull --rebase origin master
432
433
434 # -----------------------------------------------------------------------------
435 # Documentation
436 #
437
438 # Simple version of ./doc/python_api/sphinx_doc_gen.sh with no PDF generation.
439 doc_py: .FORCE
440         "$(BUILD_DIR)/bin/blender" --background -noaudio --factory-startup \
441                 --python doc/python_api/sphinx_doc_gen.py
442         cd doc/python_api ; sphinx-build -b html sphinx-in sphinx-out
443         @echo "docs written into: '$(BLENDER_DIR)/doc/python_api/sphinx-out/contents.html'"
444
445 doc_doxy: .FORCE
446         cd doc/doxygen; doxygen Doxyfile
447         @echo "docs written into: '$(BLENDER_DIR)/doc/doxygen/html/index.html'"
448
449 doc_dna: .FORCE
450         "$(BUILD_DIR)/bin/blender" --background -noaudio --factory-startup \
451                 --python doc/blender_file_format/BlendFileDnaExporter_25.py
452         @echo "docs written into: '$(BLENDER_DIR)/doc/blender_file_format/dna.html'"
453
454 doc_man: .FORCE
455         $(PYTHON) doc/manpage/blender.1.py "$(BUILD_DIR)/bin/blender"
456
457 help_features: .FORCE
458         @$(PYTHON) -c \
459                 "import re; \
460                 print('\n'.join([ \
461                 w for l in open('"$(BLENDER_DIR)"/CMakeLists.txt', 'r').readlines() \
462                 if not l.lstrip().startswith('#') \
463                 for w in (re.sub(\
464                     r'.*\boption\s*\(\s*(WITH_[a-zA-Z0-9_]+)\s+(\".*\")\s*.*', r'\g<1> - \g<2>', l).strip('() \n'),) \
465                 if w.startswith('WITH_')]))" | uniq
466
467
468 clean: .FORCE
469         $(MAKE) -C "$(BUILD_DIR)" clean
470
471 .PHONY: all
472
473 .FORCE: