Merge with trunk r41625
[blender.git] / GNUmakefile
1 # -*- mode: gnumakefile; tab-width: 8; 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 BUILD_CMAKE_ARGS:=
38
39 ifndef BUILD_DIR
40         BUILD_DIR:=$(shell dirname $(BLENDER_DIR))/build/$(OS_NCASE)
41 endif
42
43
44 # -----------------------------------------------------------------------------
45 # additional targets for the build configuration
46
47 # support 'make debug'
48 ifneq "$(findstring debug, $(MAKECMDGOALS))" ""
49         BUILD_DIR:=$(BUILD_DIR)_debug
50         BUILD_TYPE:=Debug
51 endif
52 ifneq "$(findstring lite, $(MAKECMDGOALS))" ""
53         BUILD_DIR:=$(BUILD_DIR)_lite
54         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C$(BLENDER_DIR)/build_files/cmake/config/blender_lite.cmake
55 endif
56 ifneq "$(findstring headless, $(MAKECMDGOALS))" ""
57         BUILD_DIR:=$(BUILD_DIR)_bpy
58         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C$(BLENDER_DIR)/build_files/cmake/config/blender_headless.cmake
59 endif
60 ifneq "$(findstring bpy, $(MAKECMDGOALS))" ""
61         BUILD_DIR:=$(BUILD_DIR)_bpy
62         BUILD_CMAKE_ARGS:=$(BUILD_CMAKE_ARGS) -C$(BLENDER_DIR)/build_files/cmake/config/bpy_module.cmake
63 endif
64
65
66 # -----------------------------------------------------------------------------
67 # Get the number of cores for threaded build
68 NPROCS:=1
69 ifeq ($(OS), Linux)
70         NPROCS:=$(shell grep -c ^processor /proc/cpuinfo)
71 endif
72 ifeq ($(OS), Darwin)
73         NPROCS:=$(shell sysctl -a | grep "hw.ncpu " | cut -d" " -f3)
74 endif
75 ifeq ($(OS), FreeBSD)
76         NPROCS:=$(shell sysctl -a | grep "hw.ncpu " | cut -d" " -f3 )
77 endif
78 ifeq ($(OS), NetBSD)
79         NPROCS:=$(shell sysctl -a | grep "hw.ncpu " | cut -d" " -f3 )
80 endif
81
82
83 # -----------------------------------------------------------------------------
84 # Macro for configuring cmake
85
86 CMAKE_CONFIG = cmake $(BUILD_CMAKE_ARGS) \
87                      -H$(BLENDER_DIR) \
88                      -B$(BUILD_DIR) \
89                      -DCMAKE_BUILD_TYPE:STRING=$(BUILD_TYPE)
90
91
92 # -----------------------------------------------------------------------------
93 # Build Blender
94 all:
95         @echo
96         @echo Configuring Blender ...
97
98         if test ! -f $(BUILD_DIR)/CMakeCache.txt ; then \
99                 $(CMAKE_CONFIG); \
100         fi
101
102         @echo
103         @echo Building Blender ...
104         $(MAKE) -C $(BUILD_DIR) -s -j $(NPROCS) install
105         @echo
106         @echo edit build configuration with: "$(BUILD_DIR)/CMakeCache.txt" run make again to rebuild.
107         @echo blender installed, run from: "$(BUILD_DIR)/bin/blender"
108         @echo
109
110 debug: all
111 lite: all
112 headless: all
113 bpy: all
114
115 # -----------------------------------------------------------------------------
116 # Helo for build targets
117 help:
118         @echo ""
119         @echo "Convenience targets provided for building blender, (multiple at once can be used)"
120         @echo "  * debug     - build a debug binary"
121         @echo "  * lite      - disable non essential features for a smaller binary and faster build"
122         @echo "  * headless  - build without an interface (renderfarm or server automation)"
123         @echo "  * bpy       - build as a python module which can be loaded from python directly"
124         @echo ""
125         @echo "  Note, passing the argument 'BUILD_DIR=path' when calling make will override the default build dir."
126         @echo ""
127         @echo ""
128         @echo "Project Files for IDE's"
129         @echo "  * project_qtcreator - QtCreator Project Files"
130         @echo "  * project_netbeans  - NetBeans Project Files"
131         @echo "  * project_eclipse   - Eclipse CDT4 Project Files"
132         @echo ""
133         @echo "Package Targets"
134         @echo "  * package_debian  - build a debian package"
135         @echo "  * package_pacman  - build an arch linux pacmanpackage"
136         @echo "  * package_archive - build an archive package"
137         @echo ""
138         @echo "Testing Targets (not assosiated with building blender)"
139         @echo "  * test            - run ctest, currently tests import/export, operator execution and that python modules load"
140         @echo "  * test_cmake      - runs our own cmake file checker which detects errors in the cmake file list definitions"
141         @echo "  * test_pep8       - checks all python script are pep8 which are tagged to use the stricter formatting"
142         @echo "  * test_deprecated - checks for deprecation tags in our code which may need to be removed"
143         @echo ""
144         @echo "Static Source Code Checking (not assosiated with building blender)"
145         @echo "  * check_cppcheck  - run blender source through cppcheck (C & C++)"
146         @echo "  * check_splint    - run blenders source through splint (C only)"
147         @echo "  * check_sparse    - run blenders source through sparse (C only)"
148         @echo ""
149         @echo "Documentation Targets (not assosiated with building blender)"
150         @echo "  * doc_py   - generate sphinx python api docs"
151         @echo "  * doc_doxy - generate doxygen C/C++ docs"
152         @echo "  * doc_dna  - generate blender file format reference"
153         @echo "  * doc_man  - generate manpage"
154         @echo ""
155
156 # -----------------------------------------------------------------------------
157 # Packages
158 #
159 package_debian:
160         cd build_files/package_spec ; DEB_BUILD_OPTIONS="parallel=$(NPROCS)" sh ./build_debian.sh
161
162 package_pacman:
163         cd build_files/package_spec/pacman ; MAKEFLAGS="-j$(NPROCS)" makepkg --asroot
164
165 package_archive:
166         make -C $(BUILD_DIR) -s package_archive
167         @echo archive in "$(BUILD_DIR)/release"
168
169
170 # -----------------------------------------------------------------------------
171 # Tests
172 #
173 test:
174         cd $(BUILD_DIR) ; ctest . --output-on-failure
175
176 # run pep8 check check on scripts we distribute.
177 test_pep8:
178         python3 source/tests/pep8.py > test_pep8.log 2>&1
179         @echo "written: test_pep8.log"
180
181 # run some checks on our cmakefiles.
182 test_cmake:
183         python3 build_files/cmake/cmake_consistency_check.py > test_cmake_consistency.log 2>&1
184         @echo "written: test_cmake_consistency.log"
185
186 # run deprecation tests, see if we have anything to remove.
187 test_deprecated:
188         python3 source/tests/check_deprecated.py
189
190
191 # -----------------------------------------------------------------------------
192 # Project Files
193 #
194
195 project_qtcreator:
196         python3 build_files/cmake/cmake_qtcreator_project.py $(BUILD_DIR)
197
198 project_netbeans:
199         python3 build_files/cmake/cmake_netbeans_project.py $(BUILD_DIR)
200
201 project_eclipse:
202         cmake -G"Eclipse CDT4 - Unix Makefiles" -H$(BLENDER_DIR) -B$(BUILD_DIR)
203
204
205 # -----------------------------------------------------------------------------
206 # Static Checking
207 #
208
209 check_cppcheck:
210         $(CMAKE_CONFIG)
211         cd $(BUILD_DIR) ; python3 $(BLENDER_DIR)/build_files/cmake/cmake_static_check_cppcheck.py
212
213 check_splint:
214         $(CMAKE_CONFIG)
215         cd $(BUILD_DIR) ; python3 $(BLENDER_DIR)/build_files/cmake/cmake_static_check_splint.py
216
217 check_sparse:
218         $(CMAKE_CONFIG)
219         cd $(BUILD_DIR) ; python3 $(BLENDER_DIR)/build_files/cmake/cmake_static_check_sparse.py
220
221
222 # -----------------------------------------------------------------------------
223 # Documentation
224 #
225
226 # Simple version of ./doc/python_api/sphinx_doc_gen.sh with no PDF generation.
227 doc_py:
228         $(BUILD_DIR)/bin/blender --background -noaudio --factory-startup --python doc/python_api/sphinx_doc_gen.py
229         cd doc/python_api ; sphinx-build -b html sphinx-in sphinx-out
230         @echo "docs written into: '$(BLENDER_DIR)/doc/python_api/sphinx-out/contents.html'"
231
232 doc_doxy:
233         cd doc/doxygen; doxygen 
234         @echo "docs written into: '$(BLENDER_DIR)/doc/doxygen/html/index.html'"
235
236 doc_dna:
237         $(BUILD_DIR)/bin/blender --background -noaudio --factory-startup --python doc/blender_file_format/BlendFileDnaExporter_25.py
238         @echo "docs written into: '$(BLENDER_DIR)/doc/blender_file_format/dna.html'"
239
240 doc_man:
241         python3 doc/manpage/blender.1.py $(BUILD_DIR)/bin/blender
242
243
244 clean:
245         $(MAKE) -C $(BUILD_DIR) clean
246
247 .PHONY: all