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