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