Merge branch 'blender-v2.81-release'
[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 define HELP_TEXT
28
29 Convenience Targets
30    Provided for building Blender, (multiple at once can be used).
31
32    * debug:         Build a debug binary.
33    * full:          Enable all supported dependencies & options.
34    * lite:          Disable non essential features for a smaller binary and faster build.
35    * headless:      Build without an interface (renderfarm or server automation).
36    * cycles:        Build Cycles standalone only, without Blender.
37    * bpy:           Build as a python module which can be loaded from python directly.
38    * deps:          Build library dependencies (intended only for platform maintainers).
39
40    * developer:     Enable faster builds, error checking and tests, recommended for developers.
41    * config:        Run cmake configuration tool to set build options.
42    * ninja:         Use ninja build tool for faster builds.
43
44    Note: passing the argument 'BUILD_DIR=path' when calling make will override the default build dir.
45    Note: passing the argument 'BUILD_CMAKE_ARGS=args' lets you add cmake arguments.
46
47
48 Project Files
49    Generate project files for development environments.
50
51    * project_qtcreator:     QtCreator Project Files.
52    * project_netbeans:      NetBeans Project Files.
53    * project_eclipse:       Eclipse CDT4 Project Files.
54
55 Package Targets
56
57    * package_debian:    Build a debian package.
58    * package_pacman:    Build an arch linux pacman package.
59    * package_archive:   Build an archive package.
60
61 Testing Targets
62    Not associated with building Blender.
63
64    * test:
65      Run automated tests with ctest.
66    * test_cmake:
67      Runs our own cmake file checker
68      which detects errors in the cmake file list definitions
69    * test_pep8:
70      Checks all python script are pep8
71      which are tagged to use the stricter formatting
72    * test_deprecated:
73      Checks for deprecation tags in our code which may need to be removed
74    * test_style_c:
75      Checks C/C++ conforms with blenders style guide:
76      https://wiki.blender.org/wiki/Source/Code_Style
77    * test_style_c_qtc:
78      Same as test_style but outputs QtCreator tasks format
79    * test_style_osl:
80      Checks OpenShadingLanguage conforms with blenders style guide:
81      https://wiki.blender.org/wiki/Source/Code_Style
82    * test_style_osl_qtc:
83      Checks OpenShadingLanguage conforms with blenders style guide:
84      https://wiki.blender.org/wiki/Source/Code_Style
85
86 Static Source Code Checking
87    Not associated with building Blender.
88
89    * check_cppcheck:        Run blender source through cppcheck (C & C++).
90    * check_clang_array:     Run blender source through clang array checking script (C & C++).
91    * check_splint:          Run blenders source through splint (C only).
92    * check_sparse:          Run blenders source through sparse (C only).
93    * check_smatch:          Run blenders source through smatch (C only).
94    * check_spelling_c:      Check for spelling errors (C/C++ only).
95    * check_spelling_c_qtc:  Same as check_spelling_c but outputs QtCreator tasks format.
96    * check_spelling_osl:    Check for spelling errors (OSL only).
97    * check_spelling_py:     Check for spelling errors (Python only).
98    * check_descriptions:    Check for duplicate/invalid descriptions.
99
100 Utilities
101    Not associated with building Blender.
102
103    * icons:
104      Updates PNG icons from SVG files.
105
106      Optionally pass in variables: 'BLENDER_BIN', 'INKSCAPE_BIN'
107      otherwise default paths are used.
108
109      Example
110         make icons INKSCAPE_BIN=/path/to/inkscape
111
112    * icons_geom:
113      Updates Geometry icons from BLEND file.
114
115      Optionally pass in variable: 'BLENDER_BIN'
116      otherwise default paths are used.
117
118      Example
119         make icons_geom BLENDER_BIN=/path/to/blender
120
121    * source_archive:
122      Create a compressed archive of the source code.
123
124    * update:
125      updates git and all submodules
126
127    * format
128      Format source code using clang (uses PATHS if passed in). For example::
129
130         make format PATHS="source/blender/blenlib source/blender/blenkernel"
131
132 Environment Variables
133
134    * BUILD_CMAKE_ARGS:      Arguments passed to CMake.
135    * BUILD_DIR:             Override default build path.
136    * PYTHON:                Use this for the Python command (used for checking tools).
137    * NPROCS:                Number of processes to use building (auto-detect when omitted).
138
139 Documentation Targets
140    Not associated with building Blender.
141
142    * doc_py:        Generate sphinx python api docs.
143    * doc_doxy:      Generate doxygen C/C++ docs.
144    * doc_dna:       Generate blender file format reference.
145    * doc_man:       Generate manpage.
146
147 Information
148
149    * help:              This help message.
150    * help_features:     Show a list of optional features when building.
151
152 endef
153 # HELP_TEXT (end)
154
155
156 # System Vars
157 OS:=$(shell uname -s)
158 OS_NCASE:=$(shell uname -s | tr '[A-Z]' '[a-z]')
159 CPU:=$(shell uname -m)
160
161
162 # Source and Build DIR's
163 BLENDER_DIR:=$(shell pwd -P)
164 BUILD_TYPE:=Release
165
166 ifndef BUILD_CMAKE_ARGS
167         BUILD_CMAKE_ARGS:=
168 endif
169
170 ifndef BUILD_DIR
171         BUILD_DIR:=$(shell dirname "$(BLENDER_DIR)")/build_$(OS_NCASE)
172 endif
173
174 # Dependencies DIR's
175 DEPS_SOURCE_DIR:=$(BLENDER_DIR)/build_files/build_environment
176
177 ifndef DEPS_BUILD_DIR
178         DEPS_BUILD_DIR:=$(BUILD_DIR)/deps
179 endif
180
181 ifndef DEPS_INSTALL_DIR
182         DEPS_INSTALL_DIR:=$(shell dirname "$(BLENDER_DIR)")/lib/$(OS_NCASE)
183
184         ifneq ($(OS_NCASE),darwin)
185                 # Add processor type to directory name
186                 DEPS_INSTALL_DIR:=$(DEPS_INSTALL_DIR)_$(CPU)
187         endif
188 endif
189
190 # Allow to use alternative binary (pypy3, etc)
191 ifndef PYTHON
192         PYTHON:=python3
193 endif
194
195 # For macOS python3 is not installed by default, so fallback to python binary
196 # in libraries, or python 2 for running make update to get it.
197 ifeq ($(OS_NCASE),darwin)
198         ifeq (, $(shell command -v $(PYTHON)))
199                 PYTHON:=../lib/darwin/python/bin/python3.7m
200                 ifeq (, $(shell command -v $(PYTHON)))
201                         PYTHON:=python
202                 endif
203         endif
204 endif
205
206 # -----------------------------------------------------------------------------
207 # additional targets for the build configuration
208
209 # support 'make debug'
210 ifneq "$(findstring debug, $(MAKECMDGOALS))" ""
211         BUILD_DIR:=$(BUILD_DIR)_debug
212         BUILD_TYPE:=Debug
213 endif
214 ifneq "$(findstring full, $(MAKECMDGOALS))" ""
215         BUILD_DIR:=$(BUILD_DIR)_full
216         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/blender_full.cmake"
217 endif
218 ifneq "$(findstring lite, $(MAKECMDGOALS))" ""
219         BUILD_DIR:=$(BUILD_DIR)_lite
220         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/blender_lite.cmake"
221 endif
222 ifneq "$(findstring cycles, $(MAKECMDGOALS))" ""
223         BUILD_DIR:=$(BUILD_DIR)_cycles
224         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/cycles_standalone.cmake"
225 endif
226 ifneq "$(findstring headless, $(MAKECMDGOALS))" ""
227         BUILD_DIR:=$(BUILD_DIR)_headless
228         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/blender_headless.cmake"
229 endif
230 ifneq "$(findstring bpy, $(MAKECMDGOALS))" ""
231         BUILD_DIR:=$(BUILD_DIR)_bpy
232         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/bpy_module.cmake"
233 endif
234
235 ifneq "$(findstring developer, $(MAKECMDGOALS))" ""
236         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/blender_developer.cmake"
237 endif
238
239 # -----------------------------------------------------------------------------
240 # build tool
241
242 ifneq "$(findstring ninja, $(MAKECMDGOALS))" ""
243         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -G Ninja
244         BUILD_COMMAND:=ninja
245         DEPS_BUILD_COMMAND:=ninja
246 else
247         ifneq ("$(wildcard $(BUILD_DIR)/build.ninja)","")
248                 BUILD_COMMAND:=ninja
249         else
250                 BUILD_COMMAND:=make -s
251         endif
252
253         ifneq ("$(wildcard $(DEPS_BUILD_DIR)/build.ninja)","")
254                 DEPS_BUILD_COMMAND:=ninja
255         else
256                 DEPS_BUILD_COMMAND:=make -s
257         endif
258 endif
259
260 # -----------------------------------------------------------------------------
261 # Blender binary path
262
263 # Allow passing in own BLENDER_BIN so developers who don't
264 # use the default build path can still use utility helpers.
265 ifeq ($(OS), Darwin)
266         BLENDER_BIN?="$(BUILD_DIR)/bin/Blender.app/Contents/MacOS/Blender"
267 else
268         BLENDER_BIN?="$(BUILD_DIR)/bin/blender"
269 endif
270
271
272 # -----------------------------------------------------------------------------
273 # Get the number of cores for threaded build
274 ifndef NPROCS
275         NPROCS:=1
276         ifeq ($(OS), Linux)
277                 NPROCS:=$(shell nproc)
278         endif
279         ifneq (,$(filter $(OS),Darwin FreeBSD NetBSD))
280                 NPROCS:=$(shell sysctl -n hw.ncpu)
281         endif
282 endif
283
284
285 # -----------------------------------------------------------------------------
286 # Macro for configuring cmake
287
288 CMAKE_CONFIG = cmake $(BUILD_CMAKE_ARGS) \
289                      -H"$(BLENDER_DIR)" \
290                      -B"$(BUILD_DIR)" \
291                      -DCMAKE_BUILD_TYPE_INIT:STRING=$(BUILD_TYPE)
292
293
294 # -----------------------------------------------------------------------------
295 # Tool for 'make config'
296
297 # X11 spesific
298 ifdef DISPLAY
299         CMAKE_CONFIG_TOOL = cmake-gui
300 else
301         CMAKE_CONFIG_TOOL = ccmake
302 endif
303
304
305 # -----------------------------------------------------------------------------
306 # Build Blender
307 all: .FORCE
308         @echo
309         @echo Configuring Blender in \"$(BUILD_DIR)\" ...
310
311 #       # if test ! -f $(BUILD_DIR)/CMakeCache.txt ; then \
312 #       #       $(CMAKE_CONFIG); \
313 #       # fi
314
315 #       # do this always incase of failed initial build, could be smarter here...
316         @$(CMAKE_CONFIG)
317
318         @echo
319         @echo Building Blender ...
320         $(BUILD_COMMAND) -C "$(BUILD_DIR)" -j $(NPROCS) install
321         @echo
322         @echo edit build configuration with: "$(BUILD_DIR)/CMakeCache.txt" run make again to rebuild.
323         @echo Blender successfully built, run from: $(BLENDER_BIN)
324         @echo
325
326 debug: all
327 full: all
328 lite: all
329 cycles: all
330 headless: all
331 bpy: all
332 developer: all
333 ninja: all
334
335 # -----------------------------------------------------------------------------
336 # Build dependencies
337 DEPS_TARGET = install
338 ifneq "$(findstring clean, $(MAKECMDGOALS))" ""
339         DEPS_TARGET = clean
340 endif
341
342 deps: .FORCE
343         @echo
344         @echo Configuring dependencies in \"$(DEPS_BUILD_DIR)\"
345
346         @cmake -H"$(DEPS_SOURCE_DIR)" \
347                -B"$(DEPS_BUILD_DIR)" \
348                    -DHARVEST_TARGET=$(DEPS_INSTALL_DIR)
349
350         @echo
351         @echo Building dependencies ...
352         $(DEPS_BUILD_COMMAND) -C "$(DEPS_BUILD_DIR)" -j $(NPROCS) $(DEPS_TARGET)
353         @echo
354         @echo Dependencies successfully built and installed to $(DEPS_INSTALL_DIR).
355         @echo
356
357 # -----------------------------------------------------------------------------
358 # Configuration (save some cd'ing around)
359 config: .FORCE
360         $(CMAKE_CONFIG_TOOL) "$(BUILD_DIR)"
361
362
363 # -----------------------------------------------------------------------------
364 # Help for build targets
365 export HELP_TEXT
366 help: .FORCE
367         @echo "$$HELP_TEXT"
368
369 # -----------------------------------------------------------------------------
370 # Packages
371 #
372 package_debian: .FORCE
373         cd build_files/package_spec ; DEB_BUILD_OPTIONS="parallel=$(NPROCS)" sh ./build_debian.sh
374
375 package_pacman: .FORCE
376         cd build_files/package_spec/pacman ; MAKEFLAGS="-j$(NPROCS)" makepkg
377
378 package_archive: .FORCE
379         make -C "$(BUILD_DIR)" -s package_archive
380         @echo archive in "$(BUILD_DIR)/release"
381
382
383 # -----------------------------------------------------------------------------
384 # Tests
385 #
386 test: .FORCE
387         $(PYTHON) ./build_files/utils/make_test.py "$(BUILD_DIR)"
388
389 # run pep8 check check on scripts we distribute.
390 test_pep8: .FORCE
391         $(PYTHON) tests/python/pep8.py > test_pep8.log 2>&1
392         @echo "written: test_pep8.log"
393
394 # run some checks on our cmakefiles.
395 test_cmake: .FORCE
396         $(PYTHON) build_files/cmake/cmake_consistency_check.py > test_cmake_consistency.log 2>&1
397         @echo "written: test_cmake_consistency.log"
398
399 # run deprecation tests, see if we have anything to remove.
400 test_deprecated: .FORCE
401         $(PYTHON) tests/check_deprecated.py
402
403 test_style_c: .FORCE
404         # run our own checks on C/C++ style
405         PYTHONIOENCODING=utf_8 $(PYTHON) \
406             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
407             "$(BLENDER_DIR)/source/blender" \
408             "$(BLENDER_DIR)/source/creator" \
409             --no-length-check
410
411 test_style_c_qtc: .FORCE
412         # run our own checks on C/C++ style
413         USE_QTC_TASK=1 \
414         PYTHONIOENCODING=utf_8 $(PYTHON) \
415             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
416             "$(BLENDER_DIR)/source/blender" \
417             "$(BLENDER_DIR)/source/creator" \
418             --no-length-check \
419             > \
420             "$(BLENDER_DIR)/test_style.tasks"
421         @echo "written: test_style.tasks"
422
423
424 test_style_osl: .FORCE
425         # run our own checks on C/C++ style
426         PYTHONIOENCODING=utf_8 $(PYTHON) \
427             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
428             "$(BLENDER_DIR)/intern/cycles/kernel/shaders" \
429             "$(BLENDER_DIR)/release/scripts/templates_osl"
430
431
432 test_style_osl_qtc: .FORCE
433         # run our own checks on C/C++ style
434         USE_QTC_TASK=1 \
435         PYTHONIOENCODING=utf_8 $(PYTHON) \
436             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
437             "$(BLENDER_DIR)/intern/cycles/kernel/shaders" \
438             "$(BLENDER_DIR)/release/scripts/templates_osl" \
439             > \
440             "$(BLENDER_DIR)/test_style.tasks"
441         @echo "written: test_style.tasks"
442
443 # -----------------------------------------------------------------------------
444 # Project Files
445 #
446
447 project_qtcreator: .FORCE
448         $(PYTHON) build_files/cmake/cmake_qtcreator_project.py --build-dir "$(BUILD_DIR)"
449
450 project_netbeans: .FORCE
451         $(PYTHON) build_files/cmake/cmake_netbeans_project.py "$(BUILD_DIR)"
452
453 project_eclipse: .FORCE
454         cmake -G"Eclipse CDT4 - Unix Makefiles" -H"$(BLENDER_DIR)" -B"$(BUILD_DIR)"
455
456
457 # -----------------------------------------------------------------------------
458 # Static Checking
459 #
460
461 check_cppcheck: .FORCE
462         $(CMAKE_CONFIG)
463         cd "$(BUILD_DIR)" ; \
464         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_cppcheck.py" 2> \
465             "$(BLENDER_DIR)/check_cppcheck.txt"
466         @echo "written: check_cppcheck.txt"
467
468 check_clang_array: .FORCE
469         $(CMAKE_CONFIG)
470         cd "$(BUILD_DIR)" ; \
471         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_clang_array.py"
472
473 check_splint: .FORCE
474         $(CMAKE_CONFIG)
475         cd "$(BUILD_DIR)" ; \
476         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_splint.py"
477
478 check_sparse: .FORCE
479         $(CMAKE_CONFIG)
480         cd "$(BUILD_DIR)" ; \
481         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_sparse.py"
482
483 check_smatch: .FORCE
484         $(CMAKE_CONFIG)
485         cd "$(BUILD_DIR)" ; \
486         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_smatch.py"
487
488 check_spelling_py: .FORCE
489         cd "$(BUILD_DIR)" ; \
490         PYTHONIOENCODING=utf_8 $(PYTHON) \
491             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
492             "$(BLENDER_DIR)/release/scripts"
493
494 check_spelling_c: .FORCE
495         cd "$(BUILD_DIR)" ; \
496         PYTHONIOENCODING=utf_8 $(PYTHON) \
497             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
498             "$(BLENDER_DIR)/source" \
499             "$(BLENDER_DIR)/intern/cycles" \
500             "$(BLENDER_DIR)/intern/guardedalloc" \
501             "$(BLENDER_DIR)/intern/ghost" \
502
503 check_spelling_c_qtc: .FORCE
504         cd "$(BUILD_DIR)" ; USE_QTC_TASK=1 \
505         PYTHONIOENCODING=utf_8 $(PYTHON) \
506             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
507             "$(BLENDER_DIR)/source" \
508             "$(BLENDER_DIR)/intern/cycles" \
509             "$(BLENDER_DIR)/intern/guardedalloc" \
510             "$(BLENDER_DIR)/intern/ghost" \
511             > \
512             "$(BLENDER_DIR)/check_spelling_c.tasks"
513
514 check_spelling_osl: .FORCE
515         cd "$(BUILD_DIR)" ;\
516         PYTHONIOENCODING=utf_8 $(PYTHON) \
517             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
518             "$(BLENDER_DIR)/intern/cycles/kernel/shaders"
519
520 check_descriptions: .FORCE
521         $(BLENDER_BIN) --background -noaudio --factory-startup --python \
522             "$(BLENDER_DIR)/source/tools/check_source/check_descriptions.py"
523
524 # -----------------------------------------------------------------------------
525 # Utilities
526 #
527
528 source_archive: .FORCE
529         ./build_files/utils/make_source_archive.sh
530
531 INKSCAPE_BIN?="inkscape"
532 icons: .FORCE
533         BLENDER_BIN=$(BLENDER_BIN) INKSCAPE_BIN=$(INKSCAPE_BIN) \
534                 "$(BLENDER_DIR)/release/datafiles/blender_icons_update.py"
535         BLENDER_BIN=$(BLENDER_BIN) INKSCAPE_BIN=$(INKSCAPE_BIN) \
536                 "$(BLENDER_DIR)/release/datafiles/prvicons_update.py"
537
538 icons_geom: .FORCE
539         BLENDER_BIN=$(BLENDER_BIN) \
540             "$(BLENDER_DIR)/release/datafiles/blender_icons_geom_update.py"
541
542 update: .FORCE
543         $(PYTHON) ./build_files/utils/make_update.py
544
545 format: .FORCE
546         PATH="../lib/${OS_NCASE}/llvm/bin/:$(PATH)" \
547                 $(PYTHON) source/tools/utils_maintenance/clang_format_paths.py $(PATHS)
548
549
550 # -----------------------------------------------------------------------------
551 # Documentation
552 #
553
554 # Simple version of ./doc/python_api/sphinx_doc_gen.sh with no PDF generation.
555 doc_py: .FORCE
556         ASAN_OPTIONS=halt_on_error=0 \
557         $(BLENDER_BIN) --background -noaudio --factory-startup \
558                 --python doc/python_api/sphinx_doc_gen.py
559         cd doc/python_api ; sphinx-build -b html sphinx-in sphinx-out
560         @echo "docs written into: '$(BLENDER_DIR)/doc/python_api/sphinx-out/index.html'"
561
562 doc_doxy: .FORCE
563         cd doc/doxygen; doxygen Doxyfile
564         @echo "docs written into: '$(BLENDER_DIR)/doc/doxygen/html/index.html'"
565
566 doc_dna: .FORCE
567         $(BLENDER_BIN) --background -noaudio --factory-startup \
568                 --python doc/blender_file_format/BlendFileDnaExporter_25.py
569         @echo "docs written into: '$(BLENDER_DIR)/doc/blender_file_format/dna.html'"
570
571 doc_man: .FORCE
572         $(PYTHON) doc/manpage/blender.1.py $(BLENDER_BIN) blender.1
573
574 help_features: .FORCE
575         @$(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_print_build_options.py" $(BLENDER_DIR)"/CMakeLists.txt"
576
577 clean: .FORCE
578         $(BUILD_COMMAND) -C "$(BUILD_DIR)" clean
579
580 .PHONY: all
581
582 .FORCE: