GHOST/XR: support Wayland via XrGraphicsBindingOpenGLWaylandKHR
[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 define HELP_TEXT
28
29 Blender Convenience Targets
30    Provided for building Blender, (multiple at once can be used).
31
32    * debug:         Build a debug binary.
33    * full:          Enable all supported dependencies & options.
34    * lite:          Disable non essential features for a smaller binary and faster build.
35    * release:       Complete build with all options enabled including CUDA and Optix, matching the releases on blender.org
36    * headless:      Build without an interface (renderfarm or server automation).
37    * cycles:        Build Cycles standalone only, without Blender.
38    * bpy:           Build as a python module which can be loaded from python directly.
39    * developer:     Enable faster builds, error checking and tests, recommended for developers.
40    * ninja:         Use ninja build tool for faster builds.
41    * ccache:        Use ccache for faster rebuilds.
42
43    Note: passing the argument 'BUILD_DIR=path' when calling make will override the default build dir.
44    Note: passing the argument 'BUILD_CMAKE_ARGS=args' lets you add cmake arguments.
45
46 Other Convenience Targets
47    Provided for other building operations.
48
49    * config:        Run cmake configuration tool to set build options.
50    * deps:          Build library dependencies (intended only for platform maintainers).
51
52                     The existance of locally build dependancies overrides the pre-built dependencies from subversion.
53                     These must be manually removed from '../lib/' to go back to using the pre-compiled libraries.
54
55 Project Files
56    Generate project files for development environments.
57
58    * project_qtcreator:     QtCreator Project Files.
59    * project_netbeans:      NetBeans Project Files.
60    * project_eclipse:       Eclipse CDT4 Project Files.
61
62 Package Targets
63
64    * package_debian:    Build a debian package.
65    * package_pacman:    Build an arch linux pacman package.
66    * package_archive:   Build an archive package.
67
68 Testing Targets
69    Not associated with building Blender.
70
71    * test:
72      Run automated tests with ctest.
73    * test_cmake:
74      Runs our own cmake file checker
75      which detects errors in the cmake file list definitions
76    * test_pep8:
77      Checks all python script are pep8
78      which are tagged to use the stricter formatting
79    * test_deprecated:
80      Checks for deprecation tags in our code which may need to be removed
81
82 Static Source Code Checking
83    Not associated with building Blender.
84
85    * check_cppcheck:        Run blender source through cppcheck (C & C++).
86    * check_clang_array:     Run blender source through clang array checking script (C & C++).
87    * check_splint:          Run blenders source through splint (C only).
88    * check_sparse:          Run blenders source through sparse (C only).
89    * check_smatch:          Run blenders source through smatch (C only).
90    * check_descriptions:    Check for duplicate/invalid descriptions.
91
92 Spell Checkers
93    This runs the spell checker from the developer tools repositor.
94
95    * check_spelling_c:      Check for spelling errors (C/C++ only),
96    * check_spelling_osl:    Check for spelling errors (OSL only).
97    * check_spelling_py:     Check for spelling errors (Python only).
98
99    Note: an additional word-list is maintained at: 'source/tools/check_source/check_spelling_c_config.py'
100
101    Note: that spell checkers can take a 'CHECK_SPELLING_CACHE' filepath argument,
102    so re-running does not need to re-check unchanged files.
103
104    Example:
105       make check_spelling_c CHECK_SPELLING_CACHE=../spelling_cache.data
106
107 Utilities
108    Not associated with building Blender.
109
110    * icons:
111      Updates PNG icons from SVG files.
112
113      Optionally pass in variables: 'BLENDER_BIN', 'INKSCAPE_BIN'
114      otherwise default paths are used.
115
116      Example
117         make icons INKSCAPE_BIN=/path/to/inkscape
118
119    * icons_geom:
120      Updates Geometry icons from BLEND file.
121
122      Optionally pass in variable: 'BLENDER_BIN'
123      otherwise default paths are used.
124
125      Example
126         make icons_geom BLENDER_BIN=/path/to/blender
127
128    * source_archive:
129      Create a compressed archive of the source code.
130
131    * source_archive_complete:
132      Create a compressed archive of the source code and all the libraries of dependencies.
133
134    * update:
135      Updates git and all submodules and svn.
136
137    * update_code:
138      Updates git and all submodules but not svn.
139
140    * format:
141      Format source code using clang (uses PATHS if passed in). For example::
142
143         make format PATHS="source/blender/blenlib source/blender/blenkernel"
144
145 Environment Variables
146
147    * BUILD_CMAKE_ARGS:      Arguments passed to CMake.
148    * BUILD_DIR:             Override default build path.
149    * PYTHON:                Use this for the Python command (used for checking tools).
150    * NPROCS:                Number of processes to use building (auto-detect when omitted).
151
152 Documentation Targets
153    Not associated with building Blender.
154
155    * doc_py:        Generate sphinx python api docs.
156    * doc_doxy:      Generate doxygen C/C++ docs.
157    * doc_dna:       Generate blender file format reference.
158    * doc_man:       Generate manpage.
159
160 Information
161
162    * help:              This help message.
163    * help_features:     Show a list of optional features when building.
164
165 endef
166 # HELP_TEXT (end)
167
168 # This makefile is not meant for Windows
169 ifeq ($(OS),Windows_NT)
170     $(error On Windows, use "cmd //c make.bat" instead of "make")
171 endif
172
173 # System Vars
174 OS:=$(shell uname -s)
175 OS_NCASE:=$(shell uname -s | tr '[A-Z]' '[a-z]')
176 CPU:=$(shell uname -m)
177
178
179 # Source and Build DIR's
180 BLENDER_DIR:=$(shell pwd -P)
181 BUILD_TYPE:=Release
182
183 # CMake arguments, assigned to local variable to make it mutable.
184 CMAKE_CONFIG_ARGS := $(BUILD_CMAKE_ARGS)
185
186 ifndef BUILD_DIR
187         BUILD_DIR:=$(shell dirname "$(BLENDER_DIR)")/build_$(OS_NCASE)
188 endif
189
190 # Dependencies DIR's
191 DEPS_SOURCE_DIR:=$(BLENDER_DIR)/build_files/build_environment
192
193 ifndef DEPS_BUILD_DIR
194         DEPS_BUILD_DIR:=$(BUILD_DIR)/deps
195 endif
196
197 ifndef DEPS_INSTALL_DIR
198         DEPS_INSTALL_DIR:=$(shell dirname "$(BLENDER_DIR)")/lib/$(OS_NCASE)
199
200         # Add processor type to directory name, except for darwin x86_64
201         # which by convention does not have it.
202         ifeq ($(OS_NCASE),darwin)
203                 ifneq ($(CPU),x86_64)
204                         DEPS_INSTALL_DIR:=$(DEPS_INSTALL_DIR)_$(CPU)
205                 endif
206         else
207                 DEPS_INSTALL_DIR:=$(DEPS_INSTALL_DIR)_$(CPU)
208         endif
209 endif
210
211 # Allow to use alternative binary (pypy3, etc)
212 ifndef PYTHON
213         PYTHON:=python3
214 endif
215
216 # For macOS python3 is not installed by default, so fallback to python binary
217 # in libraries, or python 2 for running make update to get it.
218 ifeq ($(OS_NCASE),darwin)
219         ifeq (, $(shell command -v $(PYTHON)))
220                 PYTHON:=$(DEPS_INSTALL_DIR)/python/bin/python3.7m
221                 ifeq (, $(shell command -v $(PYTHON)))
222                         PYTHON:=python
223                 endif
224         endif
225 endif
226
227 # -----------------------------------------------------------------------------
228 # additional targets for the build configuration
229
230 # support 'make debug'
231 ifneq "$(findstring debug, $(MAKECMDGOALS))" ""
232         BUILD_DIR:=$(BUILD_DIR)_debug
233         BUILD_TYPE:=Debug
234 endif
235 ifneq "$(findstring full, $(MAKECMDGOALS))" ""
236         BUILD_DIR:=$(BUILD_DIR)_full
237         CMAKE_CONFIG_ARGS:=-C"$(BLENDER_DIR)/build_files/cmake/config/blender_full.cmake" $(CMAKE_CONFIG_ARGS)
238 endif
239 ifneq "$(findstring lite, $(MAKECMDGOALS))" ""
240         BUILD_DIR:=$(BUILD_DIR)_lite
241         CMAKE_CONFIG_ARGS:=-C"$(BLENDER_DIR)/build_files/cmake/config/blender_lite.cmake" $(CMAKE_CONFIG_ARGS)
242 endif
243 ifneq "$(findstring release, $(MAKECMDGOALS))" ""
244         BUILD_DIR:=$(BUILD_DIR)_release
245         CMAKE_CONFIG_ARGS:=-C"$(BLENDER_DIR)/build_files/cmake/config/blender_release.cmake" $(CMAKE_CONFIG_ARGS)
246 endif
247 ifneq "$(findstring cycles, $(MAKECMDGOALS))" ""
248         BUILD_DIR:=$(BUILD_DIR)_cycles
249         CMAKE_CONFIG_ARGS:=-C"$(BLENDER_DIR)/build_files/cmake/config/cycles_standalone.cmake" $(CMAKE_CONFIG_ARGS)
250 endif
251 ifneq "$(findstring headless, $(MAKECMDGOALS))" ""
252         BUILD_DIR:=$(BUILD_DIR)_headless
253         CMAKE_CONFIG_ARGS:=-C"$(BLENDER_DIR)/build_files/cmake/config/blender_headless.cmake" $(CMAKE_CONFIG_ARGS)
254 endif
255 ifneq "$(findstring bpy, $(MAKECMDGOALS))" ""
256         BUILD_DIR:=$(BUILD_DIR)_bpy
257         CMAKE_CONFIG_ARGS:=-C"$(BLENDER_DIR)/build_files/cmake/config/bpy_module.cmake" $(CMAKE_CONFIG_ARGS)
258 endif
259
260 ifneq "$(findstring developer, $(MAKECMDGOALS))" ""
261         CMAKE_CONFIG_ARGS:=-C"$(BLENDER_DIR)/build_files/cmake/config/blender_developer.cmake" $(CMAKE_CONFIG_ARGS)
262 endif
263
264 ifneq "$(findstring ccache, $(MAKECMDGOALS))" ""
265         CMAKE_CONFIG_ARGS:=-DWITH_COMPILER_CCACHE=YES $(CMAKE_CONFIG_ARGS)
266 endif
267
268 # -----------------------------------------------------------------------------
269 # build tool
270
271 ifneq "$(findstring ninja, $(MAKECMDGOALS))" ""
272         CMAKE_CONFIG_ARGS:=$(CMAKE_CONFIG_ARGS) -G Ninja
273         BUILD_COMMAND:=ninja
274         DEPS_BUILD_COMMAND:=ninja
275 else
276         ifneq ("$(wildcard $(BUILD_DIR)/build.ninja)","")
277                 BUILD_COMMAND:=ninja
278         else
279                 BUILD_COMMAND:=make -s
280         endif
281
282         ifneq ("$(wildcard $(DEPS_BUILD_DIR)/build.ninja)","")
283                 DEPS_BUILD_COMMAND:=ninja
284         else
285                 DEPS_BUILD_COMMAND:=make -s
286         endif
287 endif
288
289 # -----------------------------------------------------------------------------
290 # Blender binary path
291
292 # Allow passing in own BLENDER_BIN so developers who don't
293 # use the default build path can still use utility helpers.
294 ifeq ($(OS), Darwin)
295         BLENDER_BIN?="$(BUILD_DIR)/bin/Blender.app/Contents/MacOS/Blender"
296 else
297         BLENDER_BIN?="$(BUILD_DIR)/bin/blender"
298 endif
299
300
301 # -----------------------------------------------------------------------------
302 # Get the number of cores for threaded build
303 ifndef NPROCS
304         NPROCS:=1
305         ifeq ($(OS), Linux)
306                 NPROCS:=$(shell nproc)
307         endif
308         ifeq ($(OS), NetBSD)
309                 NPROCS:=$(shell getconf NPROCESSORS_ONLN)
310         endif
311         ifneq (,$(filter $(OS),Darwin FreeBSD))
312                 NPROCS:=$(shell sysctl -n hw.ncpu)
313         endif
314 endif
315
316
317 # -----------------------------------------------------------------------------
318 # Macro for configuring cmake
319
320 CMAKE_CONFIG = cmake $(CMAKE_CONFIG_ARGS) \
321                      -H"$(BLENDER_DIR)" \
322                      -B"$(BUILD_DIR)" \
323                      -DCMAKE_BUILD_TYPE_INIT:STRING=$(BUILD_TYPE)
324
325
326 # -----------------------------------------------------------------------------
327 # Tool for 'make config'
328
329 # X11 spesific
330 ifdef DISPLAY
331         CMAKE_CONFIG_TOOL = cmake-gui
332 else
333         CMAKE_CONFIG_TOOL = ccmake
334 endif
335
336
337 # -----------------------------------------------------------------------------
338 # Build Blender
339 all: .FORCE
340         @echo
341         @echo Configuring Blender in \"$(BUILD_DIR)\" ...
342
343 #       # if test ! -f $(BUILD_DIR)/CMakeCache.txt ; then \
344 #       #       $(CMAKE_CONFIG); \
345 #       # fi
346
347 #       # do this always incase of failed initial build, could be smarter here...
348         @$(CMAKE_CONFIG)
349
350         @echo
351         @echo Building Blender ...
352         $(BUILD_COMMAND) -C "$(BUILD_DIR)" -j $(NPROCS) install
353         @echo
354         @echo edit build configuration with: "$(BUILD_DIR)/CMakeCache.txt" run make again to rebuild.
355         @echo Blender successfully built, run from: $(BLENDER_BIN)
356         @echo
357
358 debug: all
359 full: all
360 lite: all
361 release: all
362 cycles: all
363 headless: all
364 bpy: all
365 developer: all
366 ninja: all
367 ccache: all
368
369 # -----------------------------------------------------------------------------
370 # Build dependencies
371 DEPS_TARGET = install
372 ifneq "$(findstring clean, $(MAKECMDGOALS))" ""
373         DEPS_TARGET = clean
374 endif
375
376 deps: .FORCE
377         @echo
378         @echo Configuring dependencies in \"$(DEPS_BUILD_DIR)\"
379
380         @cmake -H"$(DEPS_SOURCE_DIR)" \
381                -B"$(DEPS_BUILD_DIR)" \
382                    -DHARVEST_TARGET=$(DEPS_INSTALL_DIR)
383
384         @echo
385         @echo Building dependencies ...
386         $(DEPS_BUILD_COMMAND) -C "$(DEPS_BUILD_DIR)" -j $(NPROCS) $(DEPS_TARGET)
387         @echo
388         @echo Dependencies successfully built and installed to $(DEPS_INSTALL_DIR).
389         @echo
390
391 # -----------------------------------------------------------------------------
392 # Configuration (save some cd'ing around)
393 config: .FORCE
394         $(CMAKE_CONFIG_TOOL) "$(BUILD_DIR)"
395
396
397 # -----------------------------------------------------------------------------
398 # Help for build targets
399 export HELP_TEXT
400 help: .FORCE
401         @echo "$$HELP_TEXT"
402
403 # -----------------------------------------------------------------------------
404 # Packages
405 #
406 package_debian: .FORCE
407         cd build_files/package_spec ; DEB_BUILD_OPTIONS="parallel=$(NPROCS)" sh ./build_debian.sh
408
409 package_pacman: .FORCE
410         cd build_files/package_spec/pacman ; MAKEFLAGS="-j$(NPROCS)" makepkg
411
412 package_archive: .FORCE
413         make -C "$(BUILD_DIR)" -s package_archive
414         @echo archive in "$(BUILD_DIR)/release"
415
416
417 # -----------------------------------------------------------------------------
418 # Tests
419 #
420 test: .FORCE
421         $(PYTHON) ./build_files/utils/make_test.py "$(BUILD_DIR)"
422
423 # run pep8 check check on scripts we distribute.
424 test_pep8: .FORCE
425         $(PYTHON) tests/python/pep8.py > test_pep8.log 2>&1
426         @echo "written: test_pep8.log"
427
428 # run some checks on our cmakefiles.
429 test_cmake: .FORCE
430         $(PYTHON) build_files/cmake/cmake_consistency_check.py > test_cmake_consistency.log 2>&1
431         @echo "written: test_cmake_consistency.log"
432
433 # run deprecation tests, see if we have anything to remove.
434 test_deprecated: .FORCE
435         $(PYTHON) tests/check_deprecated.py
436
437
438 # -----------------------------------------------------------------------------
439 # Project Files
440 #
441
442 project_qtcreator: .FORCE
443         $(PYTHON) build_files/cmake/cmake_qtcreator_project.py --build-dir "$(BUILD_DIR)"
444
445 project_netbeans: .FORCE
446         $(PYTHON) build_files/cmake/cmake_netbeans_project.py "$(BUILD_DIR)"
447
448 project_eclipse: .FORCE
449         cmake -G"Eclipse CDT4 - Unix Makefiles" -H"$(BLENDER_DIR)" -B"$(BUILD_DIR)"
450
451
452 # -----------------------------------------------------------------------------
453 # Static Checking
454 #
455
456 check_cppcheck: .FORCE
457         $(CMAKE_CONFIG)
458         cd "$(BUILD_DIR)" ; \
459         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_cppcheck.py" 2> \
460             "$(BLENDER_DIR)/check_cppcheck.txt"
461         @echo "written: check_cppcheck.txt"
462
463 check_clang_array: .FORCE
464         $(CMAKE_CONFIG)
465         cd "$(BUILD_DIR)" ; \
466         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_clang_array.py"
467
468 check_splint: .FORCE
469         $(CMAKE_CONFIG)
470         cd "$(BUILD_DIR)" ; \
471         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_splint.py"
472
473 check_sparse: .FORCE
474         $(CMAKE_CONFIG)
475         cd "$(BUILD_DIR)" ; \
476         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_sparse.py"
477
478 check_smatch: .FORCE
479         $(CMAKE_CONFIG)
480         cd "$(BUILD_DIR)" ; \
481         $(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_static_check_smatch.py"
482
483 check_mypy: .FORCE
484         $(PYTHON) "$(BLENDER_DIR)/source/tools/check_source/check_mypy.py"
485
486 check_spelling_py: .FORCE
487         cd "$(BUILD_DIR)" ; \
488         PYTHONIOENCODING=utf_8 $(PYTHON) \
489             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
490             "$(BLENDER_DIR)/release/scripts"
491
492 check_spelling_c: .FORCE
493         cd "$(BUILD_DIR)" ; \
494         PYTHONIOENCODING=utf_8 $(PYTHON) \
495             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
496             --cache-file=$(CHECK_SPELLING_CACHE) \
497             "$(BLENDER_DIR)/source" \
498             "$(BLENDER_DIR)/intern/cycles" \
499             "$(BLENDER_DIR)/intern/guardedalloc" \
500             "$(BLENDER_DIR)/intern/ghost" \
501
502 check_spelling_osl: .FORCE
503         cd "$(BUILD_DIR)" ;\
504         PYTHONIOENCODING=utf_8 $(PYTHON) \
505             "$(BLENDER_DIR)/source/tools/check_source/check_spelling.py" \
506             --cache-file=$(CHECK_SPELLING_CACHE) \
507             "$(BLENDER_DIR)/intern/cycles/kernel/shaders"
508
509 check_descriptions: .FORCE
510         $(BLENDER_BIN) --background -noaudio --factory-startup --python \
511             "$(BLENDER_DIR)/source/tools/check_source/check_descriptions.py"
512
513 # -----------------------------------------------------------------------------
514 # Utilities
515 #
516
517 source_archive: .FORCE
518         python3 ./build_files/utils/make_source_archive.py
519
520 source_archive_complete: .FORCE
521         cmake -S "$(BLENDER_DIR)/build_files/build_environment" -B"$(BUILD_DIR)/source_archive" \
522                 -DCMAKE_BUILD_TYPE_INIT:STRING=$(BUILD_TYPE) -DPACKAGE_USE_UPSTREAM_SOURCES=OFF
523 # This assumes CMake is still using a default `PACKAGE_DIR` variable:
524         python3 ./build_files/utils/make_source_archive.py --include-packages "$(BUILD_DIR)/source_archive/packages"
525
526
527 INKSCAPE_BIN?="inkscape"
528 icons: .FORCE
529         BLENDER_BIN=$(BLENDER_BIN) INKSCAPE_BIN=$(INKSCAPE_BIN) \
530                 "$(BLENDER_DIR)/release/datafiles/blender_icons_update.py"
531         BLENDER_BIN=$(BLENDER_BIN) INKSCAPE_BIN=$(INKSCAPE_BIN) \
532                 "$(BLENDER_DIR)/release/datafiles/prvicons_update.py"
533
534 icons_geom: .FORCE
535         BLENDER_BIN=$(BLENDER_BIN) \
536             "$(BLENDER_DIR)/release/datafiles/blender_icons_geom_update.py"
537
538 update: .FORCE
539         $(PYTHON) ./build_files/utils/make_update.py
540
541 update_code: .FORCE
542         $(PYTHON) ./build_files/utils/make_update.py --no-libraries
543
544 format: .FORCE
545         PATH="../lib/${OS_NCASE}_${CPU}/llvm/bin/:../lib/${OS_NCASE}_centos7_${CPU}/llvm/bin/:../lib/${OS_NCASE}/llvm/bin/:$(PATH)" \
546                 $(PYTHON) source/tools/utils_maintenance/clang_format_paths.py $(PATHS)
547
548
549 # -----------------------------------------------------------------------------
550 # Documentation
551 #
552
553 # Simple version of ./doc/python_api/sphinx_doc_gen.sh with no PDF generation.
554 doc_py: .FORCE
555         ASAN_OPTIONS=halt_on_error=0:${ASAN_OPTIONS} \
556         $(BLENDER_BIN) --background -noaudio --factory-startup \
557                 --python doc/python_api/sphinx_doc_gen.py
558         sphinx-build -b html -j $(NPROCS) doc/python_api/sphinx-in doc/python_api/sphinx-out
559         @echo "docs written into: '$(BLENDER_DIR)/doc/python_api/sphinx-out/index.html'"
560
561 doc_doxy: .FORCE
562         cd doc/doxygen; doxygen Doxyfile
563         @echo "docs written into: '$(BLENDER_DIR)/doc/doxygen/html/index.html'"
564
565 doc_dna: .FORCE
566         $(BLENDER_BIN) --background -noaudio --factory-startup \
567                 --python doc/blender_file_format/BlendFileDnaExporter_25.py
568         @echo "docs written into: '$(BLENDER_DIR)/doc/blender_file_format/dna.html'"
569
570 doc_man: .FORCE
571         $(PYTHON) doc/manpage/blender.1.py $(BLENDER_BIN) blender.1
572
573 help_features: .FORCE
574         @$(PYTHON) "$(BLENDER_DIR)/build_files/cmake/cmake_print_build_options.py" $(BLENDER_DIR)"/CMakeLists.txt"
575
576 clean: .FORCE
577         $(BUILD_COMMAND) -C "$(BUILD_DIR)" clean
578
579 .PHONY: all
580
581 .FORCE: