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