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