afd1a4880b7f05a9bdf76bc16d2a861bec1a9542
[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 # Allow passing in own BLENDER_BIN so developers who don't
216 # use the default build path can still use utility helpers.
217 ifeq ($(OS), Darwin)
218         BLENDER_BIN?="$(BUILD_DIR)/bin/blender.app/Contents/MacOS/blender"
219 else
220         BLENDER_BIN?="$(BUILD_DIR)/bin/blender"
221 endif
222
223
224 # -----------------------------------------------------------------------------
225 # Get the number of cores for threaded build
226 ifndef NPROCS
227         NPROCS:=1
228         ifeq ($(OS), Linux)
229                 NPROCS:=$(shell nproc)
230         endif
231         ifneq (,$(filter $(OS),Darwin FreeBSD NetBSD))
232                 NPROCS:=$(shell sysctl -n hw.ncpu)
233         endif
234 endif
235
236
237 # -----------------------------------------------------------------------------
238 # Macro for configuring cmake
239
240 CMAKE_CONFIG = cmake $(BUILD_CMAKE_ARGS) \
241                      -H"$(BLENDER_DIR)" \
242                      -B"$(BUILD_DIR)" \
243                      -DCMAKE_BUILD_TYPE_INIT:STRING=$(BUILD_TYPE)
244
245
246 # -----------------------------------------------------------------------------
247 # Tool for 'make config'
248
249 # X11 spesific
250 ifdef DISPLAY
251         CMAKE_CONFIG_TOOL = cmake-gui
252 else
253         CMAKE_CONFIG_TOOL = ccmake
254 endif
255
256
257 # -----------------------------------------------------------------------------
258 # Build Blender
259 all: .FORCE
260         @echo
261         @echo Configuring Blender in \"$(BUILD_DIR)\" ...
262
263 #       # if test ! -f $(BUILD_DIR)/CMakeCache.txt ; then \
264 #       #       $(CMAKE_CONFIG); \
265 #       # fi
266
267 #       # do this always incase of failed initial build, could be smarter here...
268         @$(CMAKE_CONFIG)
269
270         @echo
271         @echo Building Blender ...
272         $(MAKE) -C "$(BUILD_DIR)" -s -j $(NPROCS) install
273         @echo
274         @echo edit build configuration with: "$(BUILD_DIR)/CMakeCache.txt" run make again to rebuild.
275         @echo Blender successfully built, run from: $(BLENDER_BIN)
276         @echo
277
278 debug: all
279 full: all
280 lite: all
281 cycles: all
282 headless: all
283 bpy: all
284
285 # -----------------------------------------------------------------------------
286 # Build dependencies
287 DEPS_TARGET = install
288 ifneq "$(findstring clean, $(MAKECMDGOALS))" ""
289         DEPS_TARGET = clean
290 endif
291
292 deps: .FORCE
293         @echo
294         @echo Configuring dependencies in \"$(DEPS_BUILD_DIR)\"
295
296         @cmake -H"$(DEPS_SOURCE_DIR)" \
297                -B"$(DEPS_BUILD_DIR)" \
298                    -DHARVEST_TARGET=$(DEPS_INSTALL_DIR)
299
300         @echo
301         @echo Building dependencies ...
302         $(MAKE) -C "$(DEPS_BUILD_DIR)" -s -j $(NPROCS) $(DEPS_TARGET)
303         @echo
304         @echo Dependencies successfully built and installed to $(DEPS_INSTALL_DIR).
305         @echo
306
307 # -----------------------------------------------------------------------------
308 # Configuration (save some cd'ing around)
309 config: .FORCE
310         $(CMAKE_CONFIG_TOOL) "$(BUILD_DIR)"
311
312
313 # -----------------------------------------------------------------------------
314 # Help for build targets
315 export HELP_TEXT
316 help: .FORCE
317         @echo "$$HELP_TEXT"
318
319 # -----------------------------------------------------------------------------
320 # Packages
321 #
322 package_debian: .FORCE
323         cd build_files/package_spec ; DEB_BUILD_OPTIONS="parallel=$(NPROCS)" sh ./build_debian.sh
324
325 package_pacman: .FORCE
326         cd build_files/package_spec/pacman ; MAKEFLAGS="-j$(NPROCS)" makepkg
327
328 package_archive: .FORCE
329         make -C "$(BUILD_DIR)" -s package_archive
330         @echo archive in "$(BUILD_DIR)/release"
331
332
333 # -----------------------------------------------------------------------------
334 # Tests
335 #
336 test: .FORCE
337         cd $(BUILD_DIR) ; ctest . --output-on-failure
338
339 # run pep8 check check on scripts we distribute.
340 test_pep8: .FORCE
341         $(PYTHON) tests/python/pep8.py > test_pep8.log 2>&1
342         @echo "written: test_pep8.log"
343
344 # run some checks on our cmakefiles.
345 test_cmake: .FORCE
346         $(PYTHON) build_files/cmake/cmake_consistency_check.py > test_cmake_consistency.log 2>&1
347         @echo "written: test_cmake_consistency.log"
348
349 # run deprecation tests, see if we have anything to remove.
350 test_deprecated: .FORCE
351         $(PYTHON) tests/check_deprecated.py
352
353 test_style_c: .FORCE
354         # run our own checks on C/C++ style
355         PYTHONIOENCODING=utf_8 $(PYTHON) \
356             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
357             "$(BLENDER_DIR)/source/blender" \
358             "$(BLENDER_DIR)/source/creator" \
359             --no-length-check
360
361 test_style_c_qtc: .FORCE
362         # run our own checks on C/C++ style
363         USE_QTC_TASK=1 \
364         PYTHONIOENCODING=utf_8 $(PYTHON) \
365             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
366             "$(BLENDER_DIR)/source/blender" \
367             "$(BLENDER_DIR)/source/creator" \
368             --no-length-check \
369             > \
370             "$(BLENDER_DIR)/test_style.tasks"
371         @echo "written: test_style.tasks"
372
373
374 test_style_osl: .FORCE
375         # run our own checks on C/C++ style
376         PYTHONIOENCODING=utf_8 $(PYTHON) \
377             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
378             "$(BLENDER_DIR)/intern/cycles/kernel/shaders" \
379             "$(BLENDER_DIR)/release/scripts/templates_osl"
380
381
382 test_style_osl_qtc: .FORCE
383         # run our own checks on C/C++ style
384         USE_QTC_TASK=1 \
385         PYTHONIOENCODING=utf_8 $(PYTHON) \
386             "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
387             "$(BLENDER_DIR)/intern/cycles/kernel/shaders" \
388             "$(BLENDER_DIR)/release/scripts/templates_osl" \
389             > \
390             "$(BLENDER_DIR)/test_style.tasks"
391         @echo "written: test_style.tasks"
392
393 # -----------------------------------------------------------------------------
394 # Project Files
395 #
396
397 project_qtcreator: .FORCE
398         $(PYTHON) build_files/cmake/cmake_qtcreator_project.py "$(BUILD_DIR)"
399
400 project_netbeans: .FORCE
401         $(PYTHON) build_files/cmake/cmake_netbeans_project.py "$(BUILD_DIR)"
402
403 project_eclipse: .FORCE
404         cmake -G"Eclipse CDT4 - Unix Makefiles" -H"$(BLENDER_DIR)" -B"$(BUILD_DIR)"
405
406
407 # -----------------------------------------------------------------------------
408 # Static Checking
409 #
410
411 check_cppcheck: .FORCE
412         $(CMAKE_CONFIG)
413         cd "$(BUILD_DIR)" ; \
414         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_cppcheck.py" 2> \
415             "$(BLENDER_DIR)/check_cppcheck.txt"
416         @echo "written: check_cppcheck.txt"
417
418 check_clang_array: .FORCE
419         $(CMAKE_CONFIG)
420         cd "$(BUILD_DIR)" ; \
421         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_clang_array.py"
422
423 check_splint: .FORCE
424         $(CMAKE_CONFIG)
425         cd "$(BUILD_DIR)" ; \
426         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_splint.py"
427
428 check_sparse: .FORCE
429         $(CMAKE_CONFIG)
430         cd "$(BUILD_DIR)" ; \
431         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_sparse.py"
432
433 check_smatch: .FORCE
434         $(CMAKE_CONFIG)
435         cd "$(BUILD_DIR)" ; \
436         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_smatch.py"
437
438 check_spelling_py: .FORCE
439         cd "$(BUILD_DIR)" ; \
440         PYTHONIOENCODING=utf_8 $(PYTHON) \
441             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
442             "$(BLENDER_DIR)/release/scripts"
443
444 check_spelling_c: .FORCE
445         cd "$(BUILD_DIR)" ; \
446         PYTHONIOENCODING=utf_8 $(PYTHON) \
447             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
448             "$(BLENDER_DIR)/source" \
449             "$(BLENDER_DIR)/intern/cycles" \
450             "$(BLENDER_DIR)/intern/guardedalloc" \
451             "$(BLENDER_DIR)/intern/ghost" \
452
453 check_spelling_c_qtc: .FORCE
454         cd "$(BUILD_DIR)" ; USE_QTC_TASK=1 \
455         PYTHONIOENCODING=utf_8 $(PYTHON) \
456             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
457             "$(BLENDER_DIR)/source" \
458             "$(BLENDER_DIR)/intern/cycles" \
459             "$(BLENDER_DIR)/intern/guardedalloc" \
460             "$(BLENDER_DIR)/intern/ghost" \
461             > \
462             "$(BLENDER_DIR)/check_spelling_c.tasks"
463
464 check_spelling_osl: .FORCE
465         cd "$(BUILD_DIR)" ;\
466         PYTHONIOENCODING=utf_8 $(PYTHON) \
467             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
468             "$(BLENDER_DIR)/intern/cycles/kernel/shaders"
469
470 check_descriptions: .FORCE
471         $(BLENDER_BIN) --background -noaudio --factory-startup --python \
472             "$(BLENDER_DIR)/source/tools/check_source/check_descriptions.py"
473
474 # -----------------------------------------------------------------------------
475 # Utilities
476 #
477
478 tgz: .FORCE
479         ./build_files/utils/build_tgz.sh
480
481 icons: .FORCE
482         "$(BLENDER_DIR)/release/datafiles/blender_icons_update.py"
483         "$(BLENDER_DIR)/release/datafiles/prvicons_update.py"
484
485 icons_geom: .FORCE
486         BLENDER_BIN=$(BLENDER_BIN) \
487             "$(BLENDER_DIR)/release/datafiles/blender_icons_geom_update.py"
488
489 update: .FORCE
490         if [ "$(OS_NCASE)" = "darwin" ] && [ ! -d "../lib/$(OS_NCASE)" ]; then \
491                 svn checkout https://svn.blender.org/svnroot/bf-blender/trunk/lib/$(OS_NCASE) ../lib/$(OS_NCASE) ; \
492         fi
493         if [ -d "../lib" ]; then \
494                 svn cleanup ../lib/* ; \
495                 svn update ../lib/* ; \
496         fi
497         git pull --rebase
498         git submodule update --init --recursive
499         git submodule foreach git checkout master
500         git submodule foreach git pull --rebase origin master
501
502
503 # -----------------------------------------------------------------------------
504 # Documentation
505 #
506
507 # Simple version of ./doc/python_api/sphinx_doc_gen.sh with no PDF generation.
508 doc_py: .FORCE
509         ASAN_OPTIONS=halt_on_error=0 \
510         $(BLENDER_BIN) --background -noaudio --factory-startup \
511                 --python doc/python_api/sphinx_doc_gen.py
512         cd doc/python_api ; sphinx-build -b html sphinx-in sphinx-out
513         @echo "docs written into: '$(BLENDER_DIR)/doc/python_api/sphinx-out/index.html'"
514
515 doc_doxy: .FORCE
516         cd doc/doxygen; doxygen Doxyfile
517         @echo "docs written into: '$(BLENDER_DIR)/doc/doxygen/html/index.html'"
518
519 doc_dna: .FORCE
520         $(BLENDER_BIN) --background -noaudio --factory-startup \
521                 --python doc/blender_file_format/BlendFileDnaExporter_25.py
522         @echo "docs written into: '$(BLENDER_DIR)/doc/blender_file_format/dna.html'"
523
524 doc_man: .FORCE
525         $(PYTHON) doc/manpage/blender.1.py $(BLENDER_BIN) blender.1
526
527 help_features: .FORCE
528         @$(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_print_build_options.py" $(BLENDER_DIR)"/CMakeLists.txt"
529
530 clean: .FORCE
531         $(MAKE) -C "$(BUILD_DIR)" clean
532
533 .PHONY: all
534
535 .FORCE: