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