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)
95 NPROCS:=$(shell sysctl -n hw.ncpu)
98 NPROCS:=$(shell sysctl -n hw.ncpu)
101 NPROCS:=$(shell sysctl -n hw.ncpu)
106 # -----------------------------------------------------------------------------
107 # Macro for configuring cmake
109 CMAKE_CONFIG = cmake $(BUILD_CMAKE_ARGS) \
112 -DCMAKE_BUILD_TYPE_INIT:STRING=$(BUILD_TYPE)
115 # -----------------------------------------------------------------------------
116 # Tool for 'make config'
120 CMAKE_CONFIG_TOOL = cmake-gui
122 CMAKE_CONFIG_TOOL = ccmake
126 # -----------------------------------------------------------------------------
130 @echo Configuring Blender in \"$(BUILD_DIR)\" ...
132 # # if test ! -f $(BUILD_DIR)/CMakeCache.txt ; then \
133 # # $(CMAKE_CONFIG); \
136 # # do this always incase of failed initial build, could be smarter here...
140 @echo Building Blender ...
141 $(MAKE) -C "$(BUILD_DIR)" -s -j $(NPROCS) install
143 @echo edit build configuration with: "$(BUILD_DIR)/CMakeCache.txt" run make again to rebuild.
144 @echo Blender successfully built, run from: "$(BUILD_DIR)/bin/blender"
154 # -----------------------------------------------------------------------------
156 DEPS_TARGET = install
157 ifneq "$(findstring clean, $(MAKECMDGOALS))" ""
163 @echo Configuring dependencies in \"$(DEPS_BUILD_DIR)\"
165 @cmake -H"$(DEPS_SOURCE_DIR)" \
166 -B"$(DEPS_BUILD_DIR)" \
167 -DHARVEST_TARGET=$(DEPS_INSTALL_DIR)
170 @echo Building dependencies ...
171 $(MAKE) -C "$(DEPS_BUILD_DIR)" -s -j $(NPROCS) $(DEPS_TARGET)
173 @echo Dependencies successfully built and installed to $(DEPS_INSTALL_DIR).
176 # -----------------------------------------------------------------------------
177 # Configuration (save some cd'ing around)
179 $(CMAKE_CONFIG_TOOL) "$(BUILD_DIR)"
182 # -----------------------------------------------------------------------------
183 # Help for build targets
186 @echo "Convenience targets provided for building blender, (multiple at once can be used)"
187 @echo " * debug - build a debug binary"
188 @echo " * full - enable all supported dependencies & options"
189 @echo " * lite - disable non essential features for a smaller binary and faster build"
190 @echo " * headless - build without an interface (renderfarm or server automation)"
191 @echo " * cycles - build Cycles standalone only, without Blender"
192 @echo " * bpy - build as a python module which can be loaded from python directly"
193 @echo " * deps - build library dependencies (intended only for platform maintainers)"
195 @echo " * config - run cmake configuration tool to set build options"
197 @echo " Note, passing the argument 'BUILD_DIR=path' when calling make will override the default build dir."
198 @echo " Note, passing the argument 'BUILD_CMAKE_ARGS=args' lets you add cmake arguments."
201 @echo "Project Files for IDE's"
202 @echo " * project_qtcreator - QtCreator Project Files"
203 @echo " * project_netbeans - NetBeans Project Files"
204 @echo " * project_eclipse - Eclipse CDT4 Project Files"
206 @echo "Package Targets"
207 @echo " * package_debian - build a debian package"
208 @echo " * package_pacman - build an arch linux pacman package"
209 @echo " * package_archive - build an archive package"
211 @echo "Testing Targets (not associated with building blender)"
212 @echo " * test - run ctest, currently tests import/export,"
213 @echo " operator execution and that python modules load"
214 @echo " * test_cmake - runs our own cmake file checker"
215 @echo " which detects errors in the cmake file list definitions"
216 @echo " * test_pep8 - checks all python script are pep8"
217 @echo " which are tagged to use the stricter formatting"
218 @echo " * test_deprecated - checks for deprecation tags in our code which may need to be removed"
219 @echo " * test_style_c - checks C/C++ conforms with blenders style guide:"
220 @echo " http://wiki.blender.org/index.php/Dev:Doc/CodeStyle"
221 @echo " * test_style_c_qtc - same as test_style but outputs QtCreator tasks format"
222 @echo " * test_style_osl - checks OpenShadingLanguage conforms with blenders style guide:"
223 @echo " http://wiki.blender.org/index.php/Dev:Doc/CodeStyle"
224 @echo " * test_style_osl_qtc - checks OpenShadingLanguage conforms with blenders style guide:"
225 @echo " http://wiki.blender.org/index.php/Dev:Doc/CodeStyle"
227 @echo "Static Source Code Checking (not associated with building blender)"
228 @echo " * check_cppcheck - run blender source through cppcheck (C & C++)"
229 @echo " * check_clang_array - run blender source through clang array checking script (C & C++)"
230 @echo " * check_splint - run blenders source through splint (C only)"
231 @echo " * check_sparse - run blenders source through sparse (C only)"
232 @echo " * check_smatch - run blenders source through smatch (C only)"
233 @echo " * check_spelling_c - check for spelling errors (C/C++ only)"
234 @echo " * check_spelling_c_qtc - same as check_spelling_c but outputs QtCreator tasks format"
235 @echo " * check_spelling_osl - check for spelling errors (OSL only)"
236 @echo " * check_spelling_py - check for spelling errors (Python only)"
237 @echo " * check_descriptions - check for duplicate/invalid descriptions"
239 @echo "Utilities (not associated with building blender)"
240 @echo " * icons - updates PNG icons from SVG files."
241 @echo " * tgz - create a compressed archive of the source code."
242 @echo " * update - updates git and all submodules"
244 @echo "Environment Variables"
245 @echo " * BUILD_CMAKE_ARGS - arguments passed to CMake."
246 @echo " * BUILD_DIR - override default build path."
247 @echo " * PYTHON - use this for the Python command (used for checking tools)."
248 @echo " * NPROCS - number of processes to use building (auto-detect when omitted)."
250 @echo "Documentation Targets (not associated with building blender)"
251 @echo " * doc_py - generate sphinx python api docs"
252 @echo " * doc_doxy - generate doxygen C/C++ docs"
253 @echo " * doc_dna - generate blender file format reference"
254 @echo " * doc_man - generate manpage"
257 @echo " * help - this help message"
258 @echo " * help_features - show a list of optional features when building"
261 # -----------------------------------------------------------------------------
264 package_debian: .FORCE
265 cd build_files/package_spec ; DEB_BUILD_OPTIONS="parallel=$(NPROCS)" sh ./build_debian.sh
267 package_pacman: .FORCE
268 cd build_files/package_spec/pacman ; MAKEFLAGS="-j$(NPROCS)" makepkg
270 package_archive: .FORCE
271 make -C "$(BUILD_DIR)" -s package_archive
272 @echo archive in "$(BUILD_DIR)/release"
275 # -----------------------------------------------------------------------------
279 cd $(BUILD_DIR) ; ctest . --output-on-failure
281 # run pep8 check check on scripts we distribute.
283 $(PYTHON) tests/python/pep8.py > test_pep8.log 2>&1
284 @echo "written: test_pep8.log"
286 # run some checks on our cmakefiles.
288 $(PYTHON) build_files/cmake/cmake_consistency_check.py > test_cmake_consistency.log 2>&1
289 @echo "written: test_cmake_consistency.log"
291 # run deprecation tests, see if we have anything to remove.
292 test_deprecated: .FORCE
293 $(PYTHON) tests/check_deprecated.py
296 # run our own checks on C/C++ style
297 PYTHONIOENCODING=utf_8 $(PYTHON) \
298 "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
299 "$(BLENDER_DIR)/source/blender" \
300 "$(BLENDER_DIR)/source/creator" \
303 test_style_c_qtc: .FORCE
304 # run our own checks on C/C++ style
306 PYTHONIOENCODING=utf_8 $(PYTHON) \
307 "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
308 "$(BLENDER_DIR)/source/blender" \
309 "$(BLENDER_DIR)/source/creator" \
312 "$(BLENDER_DIR)/test_style.tasks"
313 @echo "written: test_style.tasks"
316 test_style_osl: .FORCE
317 # run our own checks on C/C++ style
318 PYTHONIOENCODING=utf_8 $(PYTHON) \
319 "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
320 "$(BLENDER_DIR)/intern/cycles/kernel/shaders" \
321 "$(BLENDER_DIR)/release/scripts/templates_osl"
324 test_style_osl_qtc: .FORCE
325 # run our own checks on C/C++ style
327 PYTHONIOENCODING=utf_8 $(PYTHON) \
328 "$(BLENDER_DIR)/source/tools/check_source/check_style_c.py" \
329 "$(BLENDER_DIR)/intern/cycles/kernel/shaders" \
330 "$(BLENDER_DIR)/release/scripts/templates_osl" \
332 "$(BLENDER_DIR)/test_style.tasks"
333 @echo "written: test_style.tasks"
335 # -----------------------------------------------------------------------------
339 project_qtcreator: .FORCE
340 $(PYTHON) build_files/cmake/cmake_qtcreator_project.py "$(BUILD_DIR)"
342 project_netbeans: .FORCE
343 $(PYTHON) build_files/cmake/cmake_netbeans_project.py "$(BUILD_DIR)"
345 project_eclipse: .FORCE
346 cmake -G"Eclipse CDT4 - Unix Makefiles" -H"$(BLENDER_DIR)" -B"$(BUILD_DIR)"
349 # -----------------------------------------------------------------------------
353 check_cppcheck: .FORCE
355 cd "$(BUILD_DIR)" ; \
356 $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_cppcheck.py" 2> \
357 "$(BLENDER_DIR)/check_cppcheck.txt"
358 @echo "written: check_cppcheck.txt"
360 check_clang_array: .FORCE
362 cd "$(BUILD_DIR)" ; \
363 $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_clang_array.py"
367 cd "$(BUILD_DIR)" ; \
368 $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_splint.py"
372 cd "$(BUILD_DIR)" ; \
373 $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_sparse.py"
377 cd "$(BUILD_DIR)" ; \
378 $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_smatch.py"
380 check_spelling_py: .FORCE
381 cd "$(BUILD_DIR)" ; \
382 PYTHONIOENCODING=utf_8 $(PYTHON) \
383 "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
384 "$(BLENDER_DIR)/release/scripts"
386 check_spelling_c: .FORCE
387 cd "$(BUILD_DIR)" ; \
388 PYTHONIOENCODING=utf_8 $(PYTHON) \
389 "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
390 "$(BLENDER_DIR)/source" \
391 "$(BLENDER_DIR)/intern/cycles" \
392 "$(BLENDER_DIR)/intern/guardedalloc" \
393 "$(BLENDER_DIR)/intern/ghost" \
395 check_spelling_c_qtc: .FORCE
396 cd "$(BUILD_DIR)" ; USE_QTC_TASK=1 \
397 PYTHONIOENCODING=utf_8 $(PYTHON) \
398 "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
399 "$(BLENDER_DIR)/source" \
400 "$(BLENDER_DIR)/intern/cycles" \
401 "$(BLENDER_DIR)/intern/guardedalloc" \
402 "$(BLENDER_DIR)/intern/ghost" \
404 "$(BLENDER_DIR)/check_spelling_c.tasks"
406 check_spelling_osl: .FORCE
408 PYTHONIOENCODING=utf_8 $(PYTHON) \
409 "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
410 "$(BLENDER_DIR)/intern/cycles/kernel/shaders"
412 check_descriptions: .FORCE
413 "$(BUILD_DIR)/bin/blender" --background -noaudio --factory-startup --python \
414 "$(BLENDER_DIR)/source/tools/check_source/check_descriptions.py"
416 # -----------------------------------------------------------------------------
421 ./build_files/utils/build_tgz.sh
424 "$(BLENDER_DIR)/release/datafiles/blender_icons_update.py"
425 "$(BLENDER_DIR)/release/datafiles/prvicons_update.py"
428 if [ -d "../lib" ]; then \
429 svn update ../lib/* ; \
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