1 # -*- mode: gnumakefile; tab-width: 4; indent-tabs-mode: t; -*-
4 # ##### BEGIN GPL LICENSE BLOCK #####
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.
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.
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.
20 # ##### END GPL LICENSE BLOCK #####
22 # This Makefile does an out-of-source CMake build in ../build_`OS`_`CPU`
25 # This is for users who like to configure & build blender with a single command.
30 OS_NCASE:=$(shell uname -s | tr '[A-Z]' '[a-z]')
31 # CPU:=$(shell uname -m) # UNUSED
34 # Source and Build DIR's
35 BLENDER_DIR:=$(shell pwd -P)
38 ifndef BUILD_CMAKE_ARGS
43 BUILD_DIR:=$(shell dirname "$(BLENDER_DIR)")/build_$(OS_NCASE)
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)
51 # Allow to use alternative binary (pypy3, etc)
57 # -----------------------------------------------------------------------------
58 # additional targets for the build configuration
60 # support 'make debug'
61 ifneq "$(findstring debug, $(MAKECMDGOALS))" ""
62 BUILD_DIR:=$(BUILD_DIR)_debug
65 ifneq "$(findstring full, $(MAKECMDGOALS))" ""
66 BUILD_DIR:=$(BUILD_DIR)_full
67 BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/blender_full.cmake"
69 ifneq "$(findstring lite, $(MAKECMDGOALS))" ""
70 BUILD_DIR:=$(BUILD_DIR)_lite
71 BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/blender_lite.cmake"
73 ifneq "$(findstring cycles, $(MAKECMDGOALS))" ""
74 BUILD_DIR:=$(BUILD_DIR)_cycles
75 BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/cycles_standalone.cmake"
77 ifneq "$(findstring headless, $(MAKECMDGOALS))" ""
78 BUILD_DIR:=$(BUILD_DIR)_headless
79 BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/blender_headless.cmake"
81 ifneq "$(findstring bpy, $(MAKECMDGOALS))" ""
82 BUILD_DIR:=$(BUILD_DIR)_bpy
83 BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C"$(BLENDER_DIR)/build_files/cmake/config/bpy_module.cmake"
87 # -----------------------------------------------------------------------------
88 # Get the number of cores for threaded build
92 NPROCS:=$(shell nproc)
94 ifneq (,$(filter $(OS),Darwin FreeBSD NetBSD))
95 NPROCS:=$(shell sysctl -n hw.ncpu)
100 # -----------------------------------------------------------------------------
101 # Macro for configuring cmake
103 CMAKE_CONFIG = cmake $(BUILD_CMAKE_ARGS) \
106 -DCMAKE_BUILD_TYPE_INIT:STRING=$(BUILD_TYPE)
109 # -----------------------------------------------------------------------------
110 # Tool for 'make config'
114 CMAKE_CONFIG_TOOL = cmake-gui
116 CMAKE_CONFIG_TOOL = ccmake
120 # -----------------------------------------------------------------------------
124 @echo Configuring Blender in \"$(BUILD_DIR)\" ...
126 # # if test ! -f $(BUILD_DIR)/CMakeCache.txt ; then \
127 # # $(CMAKE_CONFIG); \
130 # # do this always incase of failed initial build, could be smarter here...
134 @echo Building Blender ...
135 $(MAKE) -C "$(BUILD_DIR)" -s -j $(NPROCS) install
137 @echo edit build configuration with: "$(BUILD_DIR)/CMakeCache.txt" run make again to rebuild.
138 @echo Blender successfully built, run from: "$(BUILD_DIR)/bin/blender"
148 # -----------------------------------------------------------------------------
150 DEPS_TARGET = install
151 ifneq "$(findstring clean, $(MAKECMDGOALS))" ""
157 @echo Configuring dependencies in \"$(DEPS_BUILD_DIR)\"
159 @cmake -H"$(DEPS_SOURCE_DIR)" \
160 -B"$(DEPS_BUILD_DIR)" \
161 -DHARVEST_TARGET=$(DEPS_INSTALL_DIR)
164 @echo Building dependencies ...
165 $(MAKE) -C "$(DEPS_BUILD_DIR)" -s -j $(NPROCS) $(DEPS_TARGET)
167 @echo Dependencies successfully built and installed to $(DEPS_INSTALL_DIR).
170 # -----------------------------------------------------------------------------
171 # Configuration (save some cd'ing around)
173 $(CMAKE_CONFIG_TOOL) "$(BUILD_DIR)"
176 # -----------------------------------------------------------------------------
177 # Help for build targets
180 @echo "Convenience targets provided for building blender, (multiple at once can be used)"
181 @echo " * debug - build a debug binary"
182 @echo " * full - enable all supported dependencies & options"
183 @echo " * lite - disable non essential features for a smaller binary and faster build"
184 @echo " * headless - build without an interface (renderfarm or server automation)"
185 @echo " * cycles - build Cycles standalone only, without Blender"
186 @echo " * bpy - build as a python module which can be loaded from python directly"
187 @echo " * deps - build library dependencies (intended only for platform maintainers)"
189 @echo " * config - run cmake configuration tool to set build options"
191 @echo " Note, passing the argument 'BUILD_DIR=path' when calling make will override the default build dir."
192 @echo " Note, passing the argument 'BUILD_CMAKE_ARGS=args' lets you add cmake arguments."
195 @echo "Project Files for IDE's"
196 @echo " * project_qtcreator - QtCreator Project Files"
197 @echo " * project_netbeans - NetBeans Project Files"
198 @echo " * project_eclipse - Eclipse CDT4 Project Files"
200 @echo "Package Targets"
201 @echo " * package_debian - build a debian package"
202 @echo " * package_pacman - build an arch linux pacman package"
203 @echo " * package_archive - build an archive package"
205 @echo "Testing Targets (not associated with building blender)"
206 @echo " * test - run ctest, currently tests import/export,"
207 @echo " operator execution and that python modules load"
208 @echo " * test_cmake - runs our own cmake file checker"
209 @echo " which detects errors in the cmake file list definitions"
210 @echo " * test_pep8 - checks all python script are pep8"
211 @echo " which are tagged to use the stricter formatting"
212 @echo " * test_deprecated - checks for deprecation tags in our code which may need to be removed"
213 @echo " * test_style_c - checks C/C++ conforms with blenders style guide:"
214 @echo " http://wiki.blender.org/index.php/Dev:Doc/CodeStyle"
215 @echo " * test_style_c_qtc - same as test_style but outputs QtCreator tasks format"
216 @echo " * test_style_osl - checks OpenShadingLanguage conforms with blenders style guide:"
217 @echo " http://wiki.blender.org/index.php/Dev:Doc/CodeStyle"
218 @echo " * test_style_osl_qtc - checks OpenShadingLanguage conforms with blenders style guide:"
219 @echo " http://wiki.blender.org/index.php/Dev:Doc/CodeStyle"
221 @echo "Static Source Code Checking (not associated with building blender)"
222 @echo " * check_cppcheck - run blender source through cppcheck (C & C++)"
223 @echo " * check_clang_array - run blender source through clang array checking script (C & C++)"
224 @echo " * check_splint - run blenders source through splint (C only)"
225 @echo " * check_sparse - run blenders source through sparse (C only)"
226 @echo " * check_smatch - run blenders source through smatch (C only)"
227 @echo " * check_spelling_c - check for spelling errors (C/C++ only)"
228 @echo " * check_spelling_c_qtc - same as check_spelling_c but outputs QtCreator tasks format"
229 @echo " * check_spelling_osl - check for spelling errors (OSL only)"
230 @echo " * check_spelling_py - check for spelling errors (Python only)"
231 @echo " * check_descriptions - check for duplicate/invalid descriptions"
233 @echo "Utilities (not associated with building blender)"
234 @echo " * icons - updates PNG icons from SVG files."
235 @echo " * tgz - create a compressed archive of the source code."
236 @echo " * update - updates git and all submodules"
238 @echo "Environment Variables"
239 @echo " * BUILD_CMAKE_ARGS - arguments passed to CMake."
240 @echo " * BUILD_DIR - override default build path."
241 @echo " * PYTHON - use this for the Python command (used for checking tools)."
242 @echo " * NPROCS - number of processes to use building (auto-detect when omitted)."
244 @echo "Documentation Targets (not associated with building blender)"
245 @echo " * doc_py - generate sphinx python api docs"
246 @echo " * doc_doxy - generate doxygen C/C++ docs"
247 @echo " * doc_dna - generate blender file format reference"
248 @echo " * doc_man - generate manpage"
251 @echo " * help - this help message"
252 @echo " * help_features - show a list of optional features when building"
255 # -----------------------------------------------------------------------------
258 package_debian: .FORCE
259 cd build_files/package_spec ; DEB_BUILD_OPTIONS="parallel=$(NPROCS)" sh ./build_debian.sh
261 package_pacman: .FORCE
262 cd build_files/package_spec/pacman ; MAKEFLAGS="-j$(NPROCS)" makepkg
264 package_archive: .FORCE
265 make -C "$(BUILD_DIR)" -s package_archive
266 @echo archive in "$(BUILD_DIR)/release"
269 # -----------------------------------------------------------------------------
273 cd $(BUILD_DIR) ; ctest . --output-on-failure
275 # run pep8 check check on scripts we distribute.
277 $(PYTHON) tests/python/pep8.py > test_pep8.log 2>&1
278 @echo "written: test_pep8.log"
280 # run some checks on our cmakefiles.
282 $(PYTHON) build_files/cmake/cmake_consistency_check.py > test_cmake_consistency.log 2>&1
283 @echo "written: test_cmake_consistency.log"
285 # run deprecation tests, see if we have anything to remove.
286 test_deprecated: .FORCE
287 $(PYTHON) tests/check_deprecated.py
290 # run our own checks on C/C++ style
291 PYTHONIOENCODING=utf_8 $(PYTHON) \
292 "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
293 "$(BLENDER_DIR)/source/blender" \
294 "$(BLENDER_DIR)/source/creator" \
297 test_style_c_qtc: .FORCE
298 # run our own checks on C/C++ style
300 PYTHONIOENCODING=utf_8 $(PYTHON) \
301 "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
302 "$(BLENDER_DIR)/source/blender" \
303 "$(BLENDER_DIR)/source/creator" \
306 "$(BLENDER_DIR)/test_style.tasks"
307 @echo "written: test_style.tasks"
310 test_style_osl: .FORCE
311 # run our own checks on C/C++ style
312 PYTHONIOENCODING=utf_8 $(PYTHON) \
313 "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
314 "$(BLENDER_DIR)/intern/cycles/kernel/shaders" \
315 "$(BLENDER_DIR)/release/scripts/templates_osl"
318 test_style_osl_qtc: .FORCE
319 # run our own checks on C/C++ style
321 PYTHONIOENCODING=utf_8 $(PYTHON) \
322 "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
323 "$(BLENDER_DIR)/intern/cycles/kernel/shaders" \
324 "$(BLENDER_DIR)/release/scripts/templates_osl" \
326 "$(BLENDER_DIR)/test_style.tasks"
327 @echo "written: test_style.tasks"
329 # -----------------------------------------------------------------------------
333 project_qtcreator: .FORCE
334 $(PYTHON) build_files/cmake/cmake_qtcreator_project.py "$(BUILD_DIR)"
336 project_netbeans: .FORCE
337 $(PYTHON) build_files/cmake/cmake_netbeans_project.py "$(BUILD_DIR)"
339 project_eclipse: .FORCE
340 cmake -G"Eclipse CDT4 - Unix Makefiles" -H"$(BLENDER_DIR)" -B"$(BUILD_DIR)"
343 # -----------------------------------------------------------------------------
347 check_cppcheck: .FORCE
349 cd "$(BUILD_DIR)" ; \
350 $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_cppcheck.py" 2> \
351 "$(BLENDER_DIR)/check_cppcheck.txt"
352 @echo "written: check_cppcheck.txt"
354 check_clang_array: .FORCE
356 cd "$(BUILD_DIR)" ; \
357 $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_clang_array.py"
361 cd "$(BUILD_DIR)" ; \
362 $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_splint.py"
366 cd "$(BUILD_DIR)" ; \
367 $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_sparse.py"
371 cd "$(BUILD_DIR)" ; \
372 $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_smatch.py"
374 check_spelling_py: .FORCE
375 cd "$(BUILD_DIR)" ; \
376 PYTHONIOENCODING=utf_8 $(PYTHON) \
377 "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
378 "$(BLENDER_DIR)/release/scripts"
380 check_spelling_c: .FORCE
381 cd "$(BUILD_DIR)" ; \
382 PYTHONIOENCODING=utf_8 $(PYTHON) \
383 "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
384 "$(BLENDER_DIR)/source" \
385 "$(BLENDER_DIR)/intern/cycles" \
386 "$(BLENDER_DIR)/intern/guardedalloc" \
387 "$(BLENDER_DIR)/intern/ghost" \
389 check_spelling_c_qtc: .FORCE
390 cd "$(BUILD_DIR)" ; USE_QTC_TASK=1 \
391 PYTHONIOENCODING=utf_8 $(PYTHON) \
392 "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
393 "$(BLENDER_DIR)/source" \
394 "$(BLENDER_DIR)/intern/cycles" \
395 "$(BLENDER_DIR)/intern/guardedalloc" \
396 "$(BLENDER_DIR)/intern/ghost" \
398 "$(BLENDER_DIR)/check_spelling_c.tasks"
400 check_spelling_osl: .FORCE
402 PYTHONIOENCODING=utf_8 $(PYTHON) \
403 "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
404 "$(BLENDER_DIR)/intern/cycles/kernel/shaders"
406 check_descriptions: .FORCE
407 "$(BUILD_DIR)/bin/blender" --background -noaudio --factory-startup --python \
408 "$(BLENDER_DIR)/source/tools/check_source/check_descriptions.py"
410 # -----------------------------------------------------------------------------
415 ./build_files/utils/build_tgz.sh
418 "$(BLENDER_DIR)/release/datafiles/blender_icons_update.py"
419 "$(BLENDER_DIR)/release/datafiles/prvicons_update.py"
422 if [ "$(OS_NCASE)" == "darwin" ] && [ ! -d "../lib/$(OS_NCASE)" ]; then \
423 svn checkout https://svn.blender.org/svnroot/bf-blender/trunk/lib/$(OS_NCASE) ../lib/$(OS_NCASE) ; \
425 if [ -d "../lib" ]; then \
426 svn cleanup ../lib/* ; \
427 svn update ../lib/* ; \
430 git submodule update --init --recursive
431 git submodule foreach git checkout master
432 git submodule foreach git pull --rebase origin master
435 # -----------------------------------------------------------------------------
439 # Simple version of ./doc/python_api/sphinx_doc_gen.sh with no PDF generation.
441 "$(BUILD_DIR)/bin/blender" --background -noaudio --factory-startup \
442 --python doc/python_api/sphinx_doc_gen.py
443 cd doc/python_api ; sphinx-build -b html sphinx-in sphinx-out
444 @echo "docs written into: '$(BLENDER_DIR)/doc/python_api/sphinx-out/contents.html'"
447 cd doc/doxygen; doxygen Doxyfile
448 @echo "docs written into: '$(BLENDER_DIR)/doc/doxygen/html/index.html'"
451 "$(BUILD_DIR)/bin/blender" --background -noaudio --factory-startup \
452 --python doc/blender_file_format/BlendFileDnaExporter_25.py
453 @echo "docs written into: '$(BLENDER_DIR)/doc/blender_file_format/dna.html'"
456 $(PYTHON) doc/manpage/blender.1.py "$(BUILD_DIR)/bin/blender"
458 help_features: .FORCE
462 w for l in open('"$(BLENDER_DIR)"/CMakeLists.txt', 'r').readlines() \
463 if not l.lstrip().startswith('#') \
465 r'.*\boption\s*\(\s*(WITH_[a-zA-Z0-9_]+)\s+(\".*\")\s*.*', r'\g<1> - \g<2>', l).strip('() \n'),) \
466 if w.startswith('WITH_')]))" | uniq
470 $(MAKE) -C "$(BUILD_DIR)" clean