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