Support alternate python command
[blender.git] / GNUmakefile
1 # -*- mode: gnumakefile; tab-width: 8; 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 # Allow to use alternative binary (pypy3, etc)
47 ifndef PYTHON
48         PYTHON:=python3
49 endif
50
51
52 # -----------------------------------------------------------------------------
53 # additional targets for the build configuration
54
55 # support 'make debug'
56 ifneq "$(findstring debug, $(MAKECMDGOALS))" ""
57         BUILD_DIR:=$(BUILD_DIR)_debug
58         BUILD_TYPE:=Debug
59 endif
60 ifneq "$(findstring full, $(MAKECMDGOALS))" ""
61         BUILD_DIR:=$(BUILD_DIR)_full
62         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/blender_full.cmake"
63 endif
64 ifneq "$(findstring lite, $(MAKECMDGOALS))" ""
65         BUILD_DIR:=$(BUILD_DIR)_lite
66         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/blender_lite.cmake"
67 endif
68 ifneq "$(findstring cycles, $(MAKECMDGOALS))" ""
69         BUILD_DIR:=$(BUILD_DIR)_cycles
70         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/cycles_standalone.cmake"
71 endif
72 ifneq "$(findstring headless, $(MAKECMDGOALS))" ""
73         BUILD_DIR:=$(BUILD_DIR)_headless
74         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/blender_headless.cmake"
75 endif
76 ifneq "$(findstring bpy, $(MAKECMDGOALS))" ""
77         BUILD_DIR:=$(BUILD_DIR)_bpy
78         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/bpy_module.cmake"
79 endif
80
81
82 # -----------------------------------------------------------------------------
83 # Get the number of cores for threaded build
84 NPROCS:=1
85 ifeq ($(OS), Linux)
86         NPROCS:=$(shell nproc)
87 endif
88 ifeq ($(OS), Darwin)
89         NPROCS:=$(shell sysctl -a | grep "hw.ncpu" | cut -d" " -f3)
90 endif
91 ifeq ($(OS), FreeBSD)
92         NPROCS:=$(shell sysctl -a | grep "hw.ncpu" | cut -d" " -f2 )
93 endif
94 ifeq ($(OS), NetBSD)
95         NPROCS:=$(shell sysctl -a | grep "hw.ncpu" | cut -d" " -f2 )
96 endif
97
98
99 # -----------------------------------------------------------------------------
100 # Macro for configuring cmake
101
102 CMAKE_CONFIG = cmake $(BUILD_CMAKE_ARGS) \
103                      -H"$(BLENDER_DIR)" \
104                      -B"$(BUILD_DIR)" \
105                      -DCMAKE_BUILD_TYPE:STRING=$(BUILD_TYPE)
106
107
108 # -----------------------------------------------------------------------------
109 # Tool for 'make config'
110
111 # X11 spesific
112 ifdef DISPLAY
113         CMAKE_CONFIG_TOOL = cmake-gui
114 else 
115         CMAKE_CONFIG_TOOL = ccmake
116 endif
117
118
119 # -----------------------------------------------------------------------------
120 # Build Blender
121 all: FORCE
122         @echo
123         @echo Configuring Blender ...
124
125         # if test ! -f $(BUILD_DIR)/CMakeCache.txt ; then \
126         #       $(CMAKE_CONFIG); \
127         # fi
128         
129         # do this always incase of failed initial build, could be smarter here...
130         $(CMAKE_CONFIG)
131
132         @echo
133         @echo Building Blender ...
134         $(MAKE) -C "$(BUILD_DIR)" -s -j $(NPROCS) install
135         @echo
136         @echo edit build configuration with: "$(BUILD_DIR)/CMakeCache.txt" run make again to rebuild.
137         @echo blender installed, run from: "$(BUILD_DIR)/bin/blender"
138         @echo
139
140 debug: all
141 full: all
142 lite: all
143 cycles: all
144 headless: all
145 bpy: all
146
147
148 # -----------------------------------------------------------------------------
149 # Configuration (save some cd'ing around)
150 config: FORCE
151         $(CMAKE_CONFIG_TOOL) "$(BUILD_DIR)"
152
153
154 # -----------------------------------------------------------------------------
155 # Help for build targets
156 help: FORCE
157         @echo ""
158         @echo "Convenience targets provided for building blender, (multiple at once can be used)"
159         @echo "  * debug     - build a debug binary"
160         @echo "  * full      - enable all supported dependencies & options"
161         @echo "  * lite      - disable non essential features for a smaller binary and faster build"
162         @echo "  * headless  - build without an interface (renderfarm or server automation)"
163         @echo "  * cycles    - build Cycles standalone only, without Blender"
164         @echo "  * bpy       - build as a python module which can be loaded from python directly"
165         @echo ""
166         @echo "  * config    - run cmake configuration tool to set build options"
167         @echo ""
168         @echo "  Note, passing the argument 'BUILD_DIR=path' when calling make will override the default build dir."
169         @echo "  Note, passing the argument 'BUILD_CMAKE_ARGS=args' lets you add cmake arguments."
170         @echo ""
171         @echo ""
172         @echo "Project Files for IDE's"
173         @echo "  * project_qtcreator - QtCreator Project Files"
174         @echo "  * project_netbeans  - NetBeans Project Files"
175         @echo "  * project_eclipse   - Eclipse CDT4 Project Files"
176         @echo ""
177         @echo "Package Targets"
178         @echo "  * package_debian  - build a debian package"
179         @echo "  * package_pacman  - build an arch linux pacman package"
180         @echo "  * package_archive - build an archive package"
181         @echo ""
182         @echo "Testing Targets (not associated with building blender)"
183         @echo "  * test               - run ctest, currently tests import/export, operator execution and that python modules load"
184         @echo "  * test_cmake         - runs our own cmake file checker which detects errors in the cmake file list definitions"
185         @echo "  * test_pep8          - checks all python script are pep8 which are tagged to use the stricter formatting"
186         @echo "  * test_deprecated    - checks for deprecation tags in our code which may need to be removed"
187         @echo "  * test_style_c       - checks C/C++ conforms with blenders style guide: http://wiki.blender.org/index.php/Dev:Doc/CodeStyle"
188         @echo "  * test_style_c_qtc   - same as test_style but outputs QtCreator tasks format"
189         @echo "  * test_style_osl     - checks OpenShadingLanguage conforms with blenders style guide: http://wiki.blender.org/index.php/Dev:Doc/CodeStyle"
190         @echo "  * test_style_osl_qtc - checks OpenShadingLanguage conforms with blenders style guide: http://wiki.blender.org/index.php/Dev:Doc/CodeStyle"
191         @echo ""
192         @echo "Static Source Code Checking (not associated with building blender)"
193         @echo "  * check_cppcheck       - run blender source through cppcheck (C & C++)"
194         @echo "  * check_clang_array    - run blender source through clang array checking script (C & C++)"
195         @echo "  * check_splint         - run blenders source through splint (C only)"
196         @echo "  * check_sparse         - run blenders source through sparse (C only)"
197         @echo "  * check_smatch         - run blenders source through smatch (C only)"
198         @echo "  * check_spelling_c     - check for spelling errors (C/C++ only)"
199         @echo "  * check_spelling_c_qtc - same as check_spelling_c but outputs QtCreator tasks format"
200         @echo "  * check_spelling_osl   - check for spelling errors (OSL only)"
201         @echo "  * check_spelling_py    - check for spelling errors (Python only)"
202         @echo "  * check_descriptions   - check for duplicate/invalid descriptions"
203         @echo ""
204         @echo "Utilities (not associated with building blender)"
205         @echo "  * icons    - updates PNG icons from SVG files."
206         @echo "  * tgz      - create a compressed archive of the source code."
207         @echo "  * update   - updates git and all submodules"
208         @echo ""
209         @echo "Environment Variables"
210         @echo "  * BUILD_CMAKE_ARGS    - arguments passed to CMake."
211         @echo "  * BUILD_DIR           - override default build path."
212         @echo "  * PYTHON              - use this for the Python command (used for checking tools)."
213         @echo ""
214         @echo "Documentation Targets (not associated with building blender)"
215         @echo "  * doc_py   - generate sphinx python api docs"
216         @echo "  * doc_doxy - generate doxygen C/C++ docs"
217         @echo "  * doc_dna  - generate blender file format reference"
218         @echo "  * doc_man  - generate manpage"
219         @echo ""
220         @echo "Information"
221         @echo "  * help          - this help message"
222         @echo "  * help_features - show a list of optional features when building"
223         @echo ""
224
225 # -----------------------------------------------------------------------------
226 # Packages
227 #
228 package_debian: FORCE
229         cd build_files/package_spec ; DEB_BUILD_OPTIONS="parallel=$(NPROCS)" sh ./build_debian.sh
230
231 package_pacman: FORCE
232         cd build_files/package_spec/pacman ; MAKEFLAGS="-j$(NPROCS)" makepkg
233
234 package_archive: FORCE
235         make -C "$(BUILD_DIR)" -s package_archive
236         @echo archive in "$(BUILD_DIR)/release"
237
238
239 # -----------------------------------------------------------------------------
240 # Tests
241 #
242 test: FORCE
243         cd $(BUILD_DIR) ; ctest . --output-on-failure
244
245 # run pep8 check check on scripts we distribute.
246 test_pep8: FORCE
247         $(PYTHON) tests/python/pep8.py > test_pep8.log 2>&1
248         @echo "written: test_pep8.log"
249
250 # run some checks on our cmakefiles.
251 test_cmake: FORCE
252         $(PYTHON) build_files/cmake/cmake_consistency_check.py > test_cmake_consistency.log 2>&1
253         @echo "written: test_cmake_consistency.log"
254
255 # run deprecation tests, see if we have anything to remove.
256 test_deprecated: FORCE
257         $(PYTHON) tests/check_deprecated.py
258
259 test_style_c: FORCE
260         # run our own checks on C/C++ style
261         PYTHONIOENCODING=utf_8 $(PYTHON) \
262             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
263             "$(BLENDER_DIR)/source/blender" \
264             "$(BLENDER_DIR)/source/creator" \
265             --no-length-check
266
267 test_style_c_qtc: FORCE
268         # run our own checks on C/C++ style
269         USE_QTC_TASK=1 \
270         PYTHONIOENCODING=utf_8 $(PYTHON) \
271             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
272             "$(BLENDER_DIR)/source/blender" \
273             "$(BLENDER_DIR)/source/creator" \
274             --no-length-check \
275             > \
276             "$(BLENDER_DIR)/test_style.tasks"
277         @echo "written: test_style.tasks"
278
279
280 test_style_osl: FORCE
281         # run our own checks on C/C++ style
282         PYTHONIOENCODING=utf_8 $(PYTHON) \
283             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
284             "$(BLENDER_DIR)/intern/cycles/kernel/shaders" \
285             "$(BLENDER_DIR)/release/scripts/templates_osl"
286
287
288 test_style_osl_qtc: FORCE
289         # run our own checks on C/C++ style
290         USE_QTC_TASK=1 \
291         PYTHONIOENCODING=utf_8 $(PYTHON) \
292             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
293             "$(BLENDER_DIR)/intern/cycles/kernel/shaders" \
294             "$(BLENDER_DIR)/release/scripts/templates_osl" \
295             > \
296             "$(BLENDER_DIR)/test_style.tasks"
297         @echo "written: test_style.tasks"
298
299 # -----------------------------------------------------------------------------
300 # Project Files
301 #
302
303 project_qtcreator: FORCE
304         $(PYTHON) build_files/cmake/cmake_qtcreator_project.py "$(BUILD_DIR)"
305
306 project_netbeans: FORCE
307         $(PYTHON) build_files/cmake/cmake_netbeans_project.py "$(BUILD_DIR)"
308
309 project_eclipse: FORCE
310         cmake -G"Eclipse CDT4 - Unix Makefiles" -H"$(BLENDER_DIR)" -B"$(BUILD_DIR)"
311
312
313 # -----------------------------------------------------------------------------
314 # Static Checking
315 #
316
317 check_cppcheck: FORCE
318         $(CMAKE_CONFIG)
319         cd "$(BUILD_DIR)" ; \
320         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_cppcheck.py" 2> \
321             "$(BLENDER_DIR)/check_cppcheck.txt"
322         @echo "written: check_cppcheck.txt"
323
324 check_clang_array: FORCE
325         $(CMAKE_CONFIG)
326         cd "$(BUILD_DIR)" ; \
327         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_clang_array.py"
328
329 check_splint: FORCE
330         $(CMAKE_CONFIG)
331         cd "$(BUILD_DIR)" ; \
332         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_splint.py"
333
334 check_sparse: FORCE
335         $(CMAKE_CONFIG)
336         cd "$(BUILD_DIR)" ; \
337         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_sparse.py"
338
339 check_smatch: FORCE
340         $(CMAKE_CONFIG)
341         cd "$(BUILD_DIR)" ; \
342         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_smatch.py"
343
344 check_spelling_py: FORCE
345         cd "$(BUILD_DIR)" ; \
346         PYTHONIOENCODING=utf_8 $(PYTHON) \
347             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
348             "$(BLENDER_DIR)/release/scripts"
349
350 check_spelling_c: FORCE
351         cd "$(BUILD_DIR)" ; \
352         PYTHONIOENCODING=utf_8 $(PYTHON) \
353             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
354             "$(BLENDER_DIR)/source" \
355             "$(BLENDER_DIR)/intern/cycles" \
356             "$(BLENDER_DIR)/intern/guardedalloc" \
357             "$(BLENDER_DIR)/intern/ghost" \
358
359 check_spelling_c_qtc: FORCE
360         cd "$(BUILD_DIR)" ; USE_QTC_TASK=1 \
361         PYTHONIOENCODING=utf_8 $(PYTHON) \
362             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
363             "$(BLENDER_DIR)/source" \
364             "$(BLENDER_DIR)/intern/cycles" \
365             "$(BLENDER_DIR)/intern/guardedalloc" \
366             "$(BLENDER_DIR)/intern/ghost" \
367             > \
368             "$(BLENDER_DIR)/check_spelling_c.tasks"
369
370 check_spelling_osl: FORCE
371         cd "$(BUILD_DIR)" ;\
372         PYTHONIOENCODING=utf_8 $(PYTHON) \
373             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
374             "$(BLENDER_DIR)/intern/cycles/kernel/shaders"
375
376 check_descriptions: FORCE
377         "$(BUILD_DIR)/bin/blender" --background -noaudio --factory-startup --python \
378             "$(BLENDER_DIR)/source/tools/check_source/check_descriptions.py"
379
380 # -----------------------------------------------------------------------------
381 # Utilities
382 #
383
384 tgz: FORCE
385         ./build_files/utils/build_tgz.sh
386
387 icons: FORCE
388         "$(BLENDER_DIR)/release/datafiles/blender_icons_update.py"
389         "$(BLENDER_DIR)/release/datafiles/prvicons_update.py"
390
391 update: FORCE
392         if [ -d "../lib" ]; then \
393                 svn update ../lib/* ; \
394         fi
395         git pull --rebase
396         git submodule foreach git pull --rebase origin master
397
398
399 # -----------------------------------------------------------------------------
400 # Documentation
401 #
402
403 # Simple version of ./doc/python_api/sphinx_doc_gen.sh with no PDF generation.
404 doc_py: FORCE
405         "$(BUILD_DIR)/bin/blender" --background -noaudio --factory-startup --python doc/python_api/sphinx_doc_gen.py
406         cd doc/python_api ; sphinx-build -b html sphinx-in sphinx-out
407         @echo "docs written into: '$(BLENDER_DIR)/doc/python_api/sphinx-out/contents.html'"
408
409 doc_doxy: FORCE
410         cd doc/doxygen; doxygen Doxyfile
411         @echo "docs written into: '$(BLENDER_DIR)/doc/doxygen/html/index.html'"
412
413 doc_dna: FORCE
414         "$(BUILD_DIR)/bin/blender" --background -noaudio --factory-startup --python doc/blender_file_format/BlendFileDnaExporter_25.py
415         @echo "docs written into: '$(BLENDER_DIR)/doc/blender_file_format/dna.html'"
416
417 doc_man: FORCE
418         $(PYTHON) doc/manpage/blender.1.py "$(BUILD_DIR)/bin/blender"
419
420 help_features: FORCE
421         @$(PYTHON) -c \
422                 "import re; \
423                 print('\n'.join([ \
424                 w for l in open('"$(BLENDER_DIR)"/CMakeLists.txt', 'r').readlines() \
425                 if not l.lstrip().startswith('#') \
426                 for w in (re.sub(\
427                     r'.*\boption\s*\(\s*(WITH_[a-zA-Z0-9_]+)\s+(\".*\")\s*.*', r'\g<1> - \g<2>', l).strip('() \n'),) \
428                 if w.startswith('WITH_')]))" | uniq
429
430
431 clean: FORCE
432         $(MAKE) -C "$(BUILD_DIR)" clean
433
434 .PHONY: all
435
436 FORCE: