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