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         ifeq ($(OS), NetBSD)
280                 NPROCS:=$(shell getconf NPROCESSORS_ONLN)
281         endif
282         ifneq (,$(filter $(OS),Darwin FreeBSD))
283                 NPROCS:=$(shell sysctl -n hw.ncpu)
284         endif
285 endif
286
287
288 # -----------------------------------------------------------------------------
289 # Macro for configuring cmake
290
291 CMAKE_CONFIG = cmake $(BUILD_CMAKE_ARGS) \
292                      -H"$(BLENDER_DIR)" \
293                      -B"$(BUILD_DIR)" \
294                      -DCMAKE_BUILD_TYPE_INIT:STRING=$(BUILD_TYPE)
295
296
297 # -----------------------------------------------------------------------------
298 # Tool for 'make config'
299
300 # X11 spesific
301 ifdef DISPLAY
302         CMAKE_CONFIG_TOOL = cmake-gui
303 else
304         CMAKE_CONFIG_TOOL = ccmake
305 endif
306
307
308 # -----------------------------------------------------------------------------
309 # Build Blender
310 all: .FORCE
311         @echo
312         @echo Configuring Blender in \"$(BUILD_DIR)\" ...
313
314 #       # if test ! -f $(BUILD_DIR)/CMakeCache.txt ; then \
315 #       #       $(CMAKE_CONFIG); \
316 #       # fi
317
318 #       # do this always incase of failed initial build, could be smarter here...
319         @$(CMAKE_CONFIG)
320
321         @echo
322         @echo Building Blender ...
323         $(BUILD_COMMAND) -C "$(BUILD_DIR)" -j $(NPROCS) install
324         @echo
325         @echo edit build configuration with: "$(BUILD_DIR)/CMakeCache.txt" run make again to rebuild.
326         @echo Blender successfully built, run from: $(BLENDER_BIN)
327         @echo
328
329 debug: all
330 full: all
331 lite: all
332 cycles: all
333 headless: all
334 bpy: all
335 developer: all
336 ninja: all
337
338 # -----------------------------------------------------------------------------
339 # Build dependencies
340 DEPS_TARGET = install
341 ifneq "$(findstring clean, $(MAKECMDGOALS))" ""
342         DEPS_TARGET = clean
343 endif
344
345 deps: .FORCE
346         @echo
347         @echo Configuring dependencies in \"$(DEPS_BUILD_DIR)\"
348
349         @cmake -H"$(DEPS_SOURCE_DIR)" \
350                -B"$(DEPS_BUILD_DIR)" \
351                    -DHARVEST_TARGET=$(DEPS_INSTALL_DIR)
352
353         @echo
354         @echo Building dependencies ...
355         $(DEPS_BUILD_COMMAND) -C "$(DEPS_BUILD_DIR)" -j $(NPROCS) $(DEPS_TARGET)
356         @echo
357         @echo Dependencies successfully built and installed to $(DEPS_INSTALL_DIR).
358         @echo
359
360 # -----------------------------------------------------------------------------
361 # Configuration (save some cd'ing around)
362 config: .FORCE
363         $(CMAKE_CONFIG_TOOL) "$(BUILD_DIR)"
364
365
366 # -----------------------------------------------------------------------------
367 # Help for build targets
368 export HELP_TEXT
369 help: .FORCE
370         @echo "$$HELP_TEXT"
371
372 # -----------------------------------------------------------------------------
373 # Packages
374 #
375 package_debian: .FORCE
376         cd build_files/package_spec ; DEB_BUILD_OPTIONS="parallel=$(NPROCS)" sh ./build_debian.sh
377
378 package_pacman: .FORCE
379         cd build_files/package_spec/pacman ; MAKEFLAGS="-j$(NPROCS)" makepkg
380
381 package_archive: .FORCE
382         make -C "$(BUILD_DIR)" -s package_archive
383         @echo archive in "$(BUILD_DIR)/release"
384
385
386 # -----------------------------------------------------------------------------
387 # Tests
388 #
389 test: .FORCE
390         $(PYTHON) ./build_files/utils/make_test.py "$(BUILD_DIR)"
391
392 # run pep8 check check on scripts we distribute.
393 test_pep8: .FORCE
394         $(PYTHON) tests/python/pep8.py > test_pep8.log 2>&1
395         @echo "written: test_pep8.log"
396
397 # run some checks on our cmakefiles.
398 test_cmake: .FORCE
399         $(PYTHON) build_files/cmake/cmake_consistency_check.py > test_cmake_consistency.log 2>&1
400         @echo "written: test_cmake_consistency.log"
401
402 # run deprecation tests, see if we have anything to remove.
403 test_deprecated: .FORCE
404         $(PYTHON) tests/check_deprecated.py
405
406 test_style_c: .FORCE
407         # run our own checks on C/C++ style
408         PYTHONIOENCODING=utf_8 $(PYTHON) \
409             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
410             "$(BLENDER_DIR)/source/blender" \
411             "$(BLENDER_DIR)/source/creator" \
412             --no-length-check
413
414 test_style_c_qtc: .FORCE
415         # run our own checks on C/C++ style
416         USE_QTC_TASK=1 \
417         PYTHONIOENCODING=utf_8 $(PYTHON) \
418             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
419             "$(BLENDER_DIR)/source/blender" \
420             "$(BLENDER_DIR)/source/creator" \
421             --no-length-check \
422             > \
423             "$(BLENDER_DIR)/test_style.tasks"
424         @echo "written: test_style.tasks"
425
426
427 test_style_osl: .FORCE
428         # run our own checks on C/C++ style
429         PYTHONIOENCODING=utf_8 $(PYTHON) \
430             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
431             "$(BLENDER_DIR)/intern/cycles/kernel/shaders" \
432             "$(BLENDER_DIR)/release/scripts/templates_osl"
433
434
435 test_style_osl_qtc: .FORCE
436         # run our own checks on C/C++ style
437         USE_QTC_TASK=1 \
438         PYTHONIOENCODING=utf_8 $(PYTHON) \
439             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
440             "$(BLENDER_DIR)/intern/cycles/kernel/shaders" \
441             "$(BLENDER_DIR)/release/scripts/templates_osl" \
442             > \
443             "$(BLENDER_DIR)/test_style.tasks"
444         @echo "written: test_style.tasks"
445
446 # -----------------------------------------------------------------------------
447 # Project Files
448 #
449
450 project_qtcreator: .FORCE
451         $(PYTHON) build_files/cmake/cmake_qtcreator_project.py --build-dir "$(BUILD_DIR)"
452
453 project_netbeans: .FORCE
454         $(PYTHON) build_files/cmake/cmake_netbeans_project.py "$(BUILD_DIR)"
455
456 project_eclipse: .FORCE
457         cmake -G"Eclipse CDT4 - Unix Makefiles" -H"$(BLENDER_DIR)" -B"$(BUILD_DIR)"
458
459
460 # -----------------------------------------------------------------------------
461 # Static Checking
462 #
463
464 check_cppcheck: .FORCE
465         $(CMAKE_CONFIG)
466         cd "$(BUILD_DIR)" ; \
467         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_cppcheck.py" 2> \
468             "$(BLENDER_DIR)/check_cppcheck.txt"
469         @echo "written: check_cppcheck.txt"
470
471 check_clang_array: .FORCE
472         $(CMAKE_CONFIG)
473         cd "$(BUILD_DIR)" ; \
474         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_clang_array.py"
475
476 check_splint: .FORCE
477         $(CMAKE_CONFIG)
478         cd "$(BUILD_DIR)" ; \
479         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_splint.py"
480
481 check_sparse: .FORCE
482         $(CMAKE_CONFIG)
483         cd "$(BUILD_DIR)" ; \
484         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_sparse.py"
485
486 check_smatch: .FORCE
487         $(CMAKE_CONFIG)
488         cd "$(BUILD_DIR)" ; \
489         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_smatch.py"
490
491 check_spelling_py: .FORCE
492         cd "$(BUILD_DIR)" ; \
493         PYTHONIOENCODING=utf_8 $(PYTHON) \
494             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
495             "$(BLENDER_DIR)/release/scripts"
496
497 check_spelling_c: .FORCE
498         cd "$(BUILD_DIR)" ; \
499         PYTHONIOENCODING=utf_8 $(PYTHON) \
500             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
501             "$(BLENDER_DIR)/source" \
502             "$(BLENDER_DIR)/intern/cycles" \
503             "$(BLENDER_DIR)/intern/guardedalloc" \
504             "$(BLENDER_DIR)/intern/ghost" \
505
506 check_spelling_c_qtc: .FORCE
507         cd "$(BUILD_DIR)" ; USE_QTC_TASK=1 \
508         PYTHONIOENCODING=utf_8 $(PYTHON) \
509             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
510             "$(BLENDER_DIR)/source" \
511             "$(BLENDER_DIR)/intern/cycles" \
512             "$(BLENDER_DIR)/intern/guardedalloc" \
513             "$(BLENDER_DIR)/intern/ghost" \
514             > \
515             "$(BLENDER_DIR)/check_spelling_c.tasks"
516
517 check_spelling_osl: .FORCE
518         cd "$(BUILD_DIR)" ;\
519         PYTHONIOENCODING=utf_8 $(PYTHON) \
520             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
521             "$(BLENDER_DIR)/intern/cycles/kernel/shaders"
522
523 check_descriptions: .FORCE
524         $(BLENDER_BIN) --background -noaudio --factory-startup --python \
525             "$(BLENDER_DIR)/source/tools/check_source/check_descriptions.py"
526
527 # -----------------------------------------------------------------------------
528 # Utilities
529 #
530
531 source_archive: .FORCE
532         ./build_files/utils/make_source_archive.sh
533
534 INKSCAPE_BIN?="inkscape"
535 icons: .FORCE
536         BLENDER_BIN=$(BLENDER_BIN) INKSCAPE_BIN=$(INKSCAPE_BIN) \
537                 "$(BLENDER_DIR)/release/datafiles/blender_icons_update.py"
538         BLENDER_BIN=$(BLENDER_BIN) INKSCAPE_BIN=$(INKSCAPE_BIN) \
539                 "$(BLENDER_DIR)/release/datafiles/prvicons_update.py"
540
541 icons_geom: .FORCE
542         BLENDER_BIN=$(BLENDER_BIN) \
543             "$(BLENDER_DIR)/release/datafiles/blender_icons_geom_update.py"
544
545 update: .FORCE
546         $(PYTHON) ./build_files/utils/make_update.py
547
548 format: .FORCE
549         PATH="../lib/${OS_NCASE}/llvm/bin/:$(PATH)" \
550                 $(PYTHON) source/tools/utils_maintenance/clang_format_paths.py $(PATHS)
551
552
553 # -----------------------------------------------------------------------------
554 # Documentation
555 #
556
557 # Simple version of ./doc/python_api/sphinx_doc_gen.sh with no PDF generation.
558 doc_py: .FORCE
559         ASAN_OPTIONS=halt_on_error=0 \
560         $(BLENDER_BIN) --background -noaudio --factory-startup \
561                 --python doc/python_api/sphinx_doc_gen.py
562         cd doc/python_api ; sphinx-build -b html sphinx-in sphinx-out
563         @echo "docs written into: '$(BLENDER_DIR)/doc/python_api/sphinx-out/index.html'"
564
565 doc_doxy: .FORCE
566         cd doc/doxygen; doxygen Doxyfile
567         @echo "docs written into: '$(BLENDER_DIR)/doc/doxygen/html/index.html'"
568
569 doc_dna: .FORCE
570         $(BLENDER_BIN) --background -noaudio --factory-startup \
571                 --python doc/blender_file_format/BlendFileDnaExporter_25.py
572         @echo "docs written into: '$(BLENDER_DIR)/doc/blender_file_format/dna.html'"
573
574 doc_man: .FORCE
575         $(PYTHON) doc/manpage/blender.1.py $(BLENDER_BIN) blender.1
576
577 help_features: .FORCE
578         @$(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_print_build_options.py" $(BLENDER_DIR)"/CMakeLists.txt"
579
580 clean: .FORCE
581         $(BUILD_COMMAND) -C "$(BUILD_DIR)" clean
582
583 .PHONY: all
584
585 .FORCE: