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