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