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