1#
2# Copyright 2011-2019 Branimir Karadzic. All rights reserved.
3# License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
4#
5
6UNAME := $(shell uname)
7ifeq ($(UNAME),$(filter $(UNAME),Linux Darwin FreeBSD GNU/kFreeBSD))
8ifeq ($(UNAME),$(filter $(UNAME),Darwin))
9OS=darwin
10else
11ifeq ($(UNAME),$(filter $(UNAME),FreeBSD GNU/kFreeBSD))
12OS=bsd
13else
14OS=linux
15endif
16endif
17else
18OS=windows
19
20help: projgen
21
22endif
23
24# $(info $(OS))
25
26BX_DIR?=../bx
27GENIE?=$(BX_DIR)/tools/bin/$(OS)/genie
28NINJA?=$(BX_DIR)/tools/bin/$(OS)/ninja
29
30.PHONY: help
31
32help:
33	@echo Available targets:
34	@grep -E "^[a-zA-Z0-9_-]+:.*?## .*$$" $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
35
36clean: ## Clean all intermediate files.
37	@echo Cleaning...
38	-@rm -rf .build
39	@mkdir .build
40
41projgen: ## Generate project files for all configurations.
42	$(GENIE) --with-tools --with-combined-examples --with-shared-lib                       vs2017
43	$(GENIE) --with-tools --with-combined-examples                   --vs=winstore100      vs2017
44	$(GENIE) --with-tools --with-combined-examples --with-shared-lib --gcc=mingw-gcc       gmake
45	$(GENIE) --with-tools --with-combined-examples --with-shared-lib --gcc=linux-gcc       gmake
46	$(GENIE) --with-tools --with-combined-examples --with-shared-lib --gcc=osx             gmake
47	$(GENIE) --with-tools --with-combined-examples --with-shared-lib --xcode=osx           xcode8
48	$(GENIE) --with-tools --with-combined-examples --with-shared-lib --xcode=ios           xcode8
49	$(GENIE)              --with-combined-examples --with-shared-lib --gcc=freebsd         gmake
50	$(GENIE)              --with-combined-examples                   --gcc=android-arm     gmake
51	$(GENIE)              --with-combined-examples                   --gcc=android-arm64   gmake
52	$(GENIE)              --with-combined-examples                   --gcc=android-x86     gmake
53	$(GENIE)              --with-examples                            --gcc=asmjs           gmake
54	$(GENIE)              --with-combined-examples                   --gcc=ios-arm         gmake
55	$(GENIE)              --with-combined-examples                   --gcc=ios-arm64       gmake
56	$(GENIE)              --with-combined-examples                   --gcc=ios-simulator   gmake
57	$(GENIE)              --with-combined-examples                   --gcc=ios-simulator64 gmake
58	$(GENIE)              --with-combined-examples                   --gcc=rpi             gmake
59
60idl: ## Generate code from IDL.
61	@echo Generating code from IDL.
62	$(GENIE) idl
63
64.build/projects/gmake-android-arm:
65	$(GENIE) --gcc=android-arm gmake
66android-arm-debug: .build/projects/gmake-android-arm ## Build - Android ARM Debug
67	$(MAKE) -R -C .build/projects/gmake-android-arm config=debug
68android-arm-release: .build/projects/gmake-android-arm ## Build - Android ARM Release
69	$(MAKE) -R -C .build/projects/gmake-android-arm config=release
70android-arm: android-arm-debug android-arm-release ## Build - Android ARM Debug and Release
71
72.build/projects/gmake-android-arm64:
73	$(GENIE) --gcc=android-arm64 gmake
74android-arm64-debug: .build/projects/gmake-android-arm64 ## Build - Android ARM64 Debug
75	$(MAKE) -R -C .build/projects/gmake-android-arm64 config=debug
76android-arm64-release: .build/projects/gmake-android-arm64 ## Build - Android ARM64 Release
77	$(MAKE) -R -C .build/projects/gmake-android-arm64 config=release
78android-arm64: android-arm64-debug android-arm64-release ## Build - Android ARM64 Debug and Release
79
80.build/projects/gmake-android-x86:
81	$(GENIE) --gcc=android-x86 gmake
82android-x86-debug: .build/projects/gmake-android-x86 ## Build - Android x86 Debug and Release
83	$(MAKE) -R -C .build/projects/gmake-android-x86 config=debug
84android-x86-release: .build/projects/gmake-android-x86 ## Build - Android x86 Debug and Release
85	$(MAKE) -R -C .build/projects/gmake-android-x86 config=release
86android-x86: android-x86-debug android-x86-release ## Build - Android x86 Debug and Release
87
88.build/projects/gmake-asmjs:
89	$(GENIE) --gcc=asmjs gmake
90asmjs-debug: .build/projects/gmake-asmjs ## Build - Emscripten Debug
91	$(MAKE) -R -C .build/projects/gmake-asmjs config=debug
92asmjs-release: .build/projects/gmake-asmjs ## Build - Emscripten Release
93	$(MAKE) -R -C .build/projects/gmake-asmjs config=release
94asmjs: asmjs-debug asmjs-release ## Build - Emscripten Debug and Release
95
96.build/projects/gmake-linux:
97	$(GENIE) --with-tools --with-combined-examples --with-shared-lib --gcc=linux-gcc gmake
98linux-debug64: .build/projects/gmake-linux ## Build - Linux x64 Debug
99	$(MAKE) -R -C .build/projects/gmake-linux config=debug64
100linux-release64: .build/projects/gmake-linux ## Build - Linux x64 Release
101	$(MAKE) -R -C .build/projects/gmake-linux config=release64
102linux: linux-debug64 linux-release64 ## Build - Linux x86/x64 Debug and Release
103
104.build/projects/gmake-freebsd:
105	$(GENIE) --with-tools --with-combined-examples --with-shared-lib --gcc=freebsd gmake
106freebsd-debug32: .build/projects/gmake-freebsd ## Build - FreeBSD x86 Debug
107	$(MAKE) -R -C .build/projects/gmake-freebsd config=debug32
108freebsd-release32: .build/projects/gmake-freebsd ## Build - FreeBSD x86 Release
109	$(MAKE) -R -C .build/projects/gmake-freebsd config=release32
110freebsd-debug64: .build/projects/gmake-freebsd ## Build - FreeBSD x86 Debug
111	$(MAKE) -R -C .build/projects/gmake-freebsd config=debug64
112freebsd-release64: .build/projects/gmake-freebsd ## Build - FreeBSD x86 Release
113	$(MAKE) -R -C .build/projects/gmake-freebsd config=release64
114freebsd: freebsd-debug32 freebsd-release32 freebsd-debug64 freebsd-release64 ## Build - FreeBSD x86/x64 Debug and Release
115
116.build/projects/gmake-mingw-gcc:
117	$(GENIE) --with-tools --with-combined-examples --with-shared-lib --os=windows --gcc=mingw-gcc gmake
118mingw-gcc-debug32: .build/projects/gmake-mingw-gcc ## Build - MinGW GCC x86 Debug
119	$(MAKE) -R -C .build/projects/gmake-mingw-gcc config=debug32
120mingw-gcc-release32: .build/projects/gmake-mingw-gcc ## Build - MinGW GCC x86 Release
121	$(MAKE) -R -C .build/projects/gmake-mingw-gcc config=release32
122mingw-gcc-debug64: .build/projects/gmake-mingw-gcc ## Build - MinGW GCC x64 Debug
123	$(MAKE) -R -C .build/projects/gmake-mingw-gcc config=debug64
124mingw-gcc-release64: .build/projects/gmake-mingw-gcc ## Build - MinGW GCC x64 Release
125	$(MAKE) -R -C .build/projects/gmake-mingw-gcc config=release64
126mingw-gcc: mingw-gcc-debug32 mingw-gcc-release32 mingw-gcc-debug64 mingw-gcc-release64 ## Build - MinGW GCC x86/x64 Debug and Release
127
128.build/projects/gmake-mingw-clang:
129	$(GENIE) --gcc=mingw-clang gmake
130mingw-clang-debug32: .build/projects/gmake-mingw-clang ## Build - MinGW Clang x86 Debug
131	$(MAKE) -R -C .build/projects/gmake-mingw-clang config=debug32
132mingw-clang-release32: .build/projects/gmake-mingw-clang ## Build - MinGW Clang x86 Release
133	$(MAKE) -R -C .build/projects/gmake-mingw-clang config=release32
134mingw-clang-debug64: .build/projects/gmake-mingw-clang ## Build - MinGW Clang x64 Debug
135	$(MAKE) -R -C .build/projects/gmake-mingw-clang config=debug64
136mingw-clang-release64: .build/projects/gmake-mingw-clang ## Build - MinGW Clang x64 Release
137	$(MAKE) -R -C .build/projects/gmake-mingw-clang config=release64
138mingw-clang: mingw-clang-debug32 mingw-clang-release32 mingw-clang-debug64 mingw-clang-release64 ## Build - MinGW Clang x86/x64 Debug and Release
139
140.build/projects/vs2017:
141	$(GENIE) --with-tools --with-combined-examples --with-shared-lib vs2017
142vs2017-debug32: .build/projects/vs2017 ## Build - vs2017 x86 Debug
143	devenv .build/projects/vs2017/bgfx.sln /Build "Debug|Win32"
144vs2017-release32: .build/projects/vs2017 ## Build - vs2017 x86 Release
145	devenv .build/projects/vs2017/bgfx.sln /Build "Release|Win32"
146vs2017-debug64: .build/projects/vs2017 ## Build - vs2017 x64 Debug
147	devenv .build/projects/vs2017/bgfx.sln /Build "Debug|x64"
148vs2017-release64: .build/projects/vs2017 ## Build - vs2017 x64 Release
149	devenv .build/projects/vs2017/bgfx.sln /Build "Release|x64"
150vs2017: vs2017-debug32 vs2017-release32 vs2017-debug64 vs2017-release64 ## Build - vs2017 x86/x64 Debug and Release
151
152.build/projects/vs2017-winstore100:
153	$(GENIE) --with-combined-examples --vs=winstore100 vs2017
154vs2017-winstore100-debug32: .build/projects/vs2017-winstore100 ## Build - vs2017-winstore100 x86 Debug
155	devenv .build/projects/vs2017-winstore100/bgfx.sln /Build "Debug|Win32"
156vs2017-winstore100-release32: .build/projects/vs2017-winstore100 ## Build - vs2017-winstore100 x86 Release
157	devenv .build/projects/vs2017-winstore100/bgfx.sln /Build "Release|Win32"
158vs2017-winstore100-debug64: .build/projects/vs2017-winstore100 ## Build - vs2017-winstore100 x64 Debug
159	devenv .build/projects/vs2017-winstore100/bgfx.sln /Build "Debug|x64"
160vs2017-winstore100-release64: .build/projects/vs2017-winstore100 ## Build - vs2017-winstore100 x64 Release
161	devenv .build/projects/vs2017-winstore100/bgfx.sln /Build "Release|x64"
162vs2017-winstore100: vs2017-winstore100-debug32 vs2017-winstore100-release32 vs2017-winstore100-debug64 vs2017-winstore100-release64 ## Build - vs2017-winstore100 x86/x64 Debug and Release
163
164.build/projects/gmake-osx:
165	$(GENIE) --with-tools --with-combined-examples --with-shared-lib --gcc=osx gmake
166osx-debug64: .build/projects/gmake-osx ## Build - OSX x64 Debug
167	$(MAKE) -C .build/projects/gmake-osx config=debug64
168osx-release64: .build/projects/gmake-osx ## Build - OSX x64 Release
169	$(MAKE) -C .build/projects/gmake-osx config=release64
170osx: osx-debug64 osx-release64 ## Build - OSX x64 Debug and Release
171
172.build/projects/gmake-ios-arm:
173	$(GENIE) --gcc=ios-arm gmake
174ios-arm-debug: .build/projects/gmake-ios-arm ## Build - iOS ARM Debug
175	$(MAKE) -R -C .build/projects/gmake-ios-arm config=debug
176ios-arm-release: .build/projects/gmake-ios-arm ## Build - iOS ARM Release
177	$(MAKE) -R -C .build/projects/gmake-ios-arm config=release
178ios-arm: ios-arm-debug ios-arm-release ## Build - iOS ARM Debug and Release
179
180.build/projects/gmake-ios-arm64:
181	$(GENIE) --gcc=ios-arm64 gmake
182ios-arm64-debug: .build/projects/gmake-ios-arm64 ## Build - iOS ARM64 Debug
183	$(MAKE) -R -C .build/projects/gmake-ios-arm64 config=debug
184ios-arm64-release: .build/projects/gmake-ios-arm64 ## Build - iOS ARM64 Release
185	$(MAKE) -R -C .build/projects/gmake-ios-arm64 config=release
186ios-arm64: ios-arm64-debug ios-arm64-release ## Build - iOS ARM64 Debug and Release
187
188.build/projects/gmake-ios-simulator:
189	$(GENIE) --gcc=ios-simulator gmake
190ios-simulator-debug: .build/projects/gmake-ios-simulator ## Build - iOS Simulator Debug
191	$(MAKE) -R -C .build/projects/gmake-ios-simulator config=debug
192ios-simulator-release: .build/projects/gmake-ios-simulator ## Build - iOS Simulator Release
193	$(MAKE) -R -C .build/projects/gmake-ios-simulator config=release
194ios-simulator: ios-simulator-debug ios-simulator-release ## Build - iOS Simulator Debug and Release
195
196.build/projects/gmake-ios-simulator64:
197	$(GENIE) --gcc=ios-simulator64 gmake
198ios-simulator64-debug: .build/projects/gmake-ios-simulator64 ## Build - iOS Simulator Debug
199	$(MAKE) -R -C .build/projects/gmake-ios-simulator64 config=debug
200ios-simulator64-release: .build/projects/gmake-ios-simulator64 ## Build - iOS Simulator Release
201	$(MAKE) -R -C .build/projects/gmake-ios-simulator64 config=release
202ios-simulator64: ios-simulator64-debug ios-simulator64-release ## Build - iOS Simulator Debug and Release
203
204.build/projects/gmake-rpi:
205	$(GENIE) --gcc=rpi gmake
206rpi-debug: .build/projects/gmake-rpi ## Build - RasberryPi Debug
207	$(MAKE) -R -C .build/projects/gmake-rpi config=debug
208rpi-release: .build/projects/gmake-rpi ## Build - RasberryPi Release
209	$(MAKE) -R -C .build/projects/gmake-rpi config=release
210rpi: rpi-debug rpi-release ## Build - RasberryPi Debug and Release
211
212build-darwin: osx
213
214build-linux: linux-debug64 linux-release64
215
216build-windows: mingw-gcc
217
218build: build-$(OS)
219
220rebuild-shaders:
221	$(MAKE) -R -C examples rebuild
222
223assets: # Build assets.
224	$(NINJA) -C scripts
225
226analyze:
227	cppcheck src/
228	cppcheck examples/
229
230docs:
231	doxygen scripts/bgfx.doxygen
232	markdown README.md > .build/docs/readme.html
233
234###
235
236SILENT ?= @
237
238UNAME := $(shell uname)
239ifeq ($(UNAME),$(filter $(UNAME),Linux Darwin FreeBSD GNU/kFreeBSD))
240ifeq ($(UNAME),$(filter $(UNAME),Darwin))
241OS=darwin
242BUILD_PROJECT_DIR=gmake-osx
243BUILD_OUTPUT_DIR=osx64_clang
244BUILD_TOOLS_CONFIG=release64
245BUILD_TOOLS_SUFFIX=Release
246EXE=
247else
248ifeq ($(UNAME),$(filter $(UNAME),FreeBSD GNU/kFreeBSD))
249OS=bsd
250BUILD_PROJECT_DIR=gmake-freebsd
251BUILD_OUTPUT_DIR=freebsd64_gcc
252BUILD_TOOLS_CONFIG=release64
253BUILD_TOOLS_SUFFIX=Release
254EXE=
255else
256OS=linux
257BUILD_PROJECT_DIR=gmake-linux
258BUILD_OUTPUT_DIR=linux64_gcc
259BUILD_TOOLS_CONFIG=release64
260BUILD_TOOLS_SUFFIX=Release
261EXE=
262endif
263endif
264else
265OS=windows
266BUILD_PROJECT_DIR=gmake-mingw-gcc
267BUILD_OUTPUT_DIR=win64_mingw-gcc
268BUILD_TOOLS_CONFIG=release64
269BUILD_TOOLS_SUFFIX=Release
270EXE=.exe
271endif
272
273geometryc: .build/projects/$(BUILD_PROJECT_DIR) ## Build geometryc tool.
274	$(SILENT) $(MAKE) -C .build/projects/$(BUILD_PROJECT_DIR) geometryc config=$(BUILD_TOOLS_CONFIG)
275	$(SILENT) cp .build/$(BUILD_OUTPUT_DIR)/bin/geometryc$(BUILD_TOOLS_SUFFIX)$(EXE) tools/bin/$(OS)/geometryc$(EXE)
276
277geometryv: .build/projects/$(BUILD_PROJECT_DIR) ## Build geometryv tool.
278	$(SILENT) $(MAKE) -C .build/projects/$(BUILD_PROJECT_DIR) geometryv config=$(BUILD_TOOLS_CONFIG)
279	$(SILENT) cp .build/$(BUILD_OUTPUT_DIR)/bin/geometryv$(BUILD_TOOLS_SUFFIX)$(EXE) tools/bin/$(OS)/geometryv$(EXE)
280
281shaderc: .build/projects/$(BUILD_PROJECT_DIR) ## Build shaderc tool.
282	$(SILENT) $(MAKE) -C .build/projects/$(BUILD_PROJECT_DIR) shaderc config=$(BUILD_TOOLS_CONFIG)
283	$(SILENT) cp .build/$(BUILD_OUTPUT_DIR)/bin/shaderc$(BUILD_TOOLS_SUFFIX)$(EXE) tools/bin/$(OS)/shaderc$(EXE)
284
285texturec: .build/projects/$(BUILD_PROJECT_DIR) ## Build texturec tool.
286	$(SILENT) $(MAKE) -C .build/projects/$(BUILD_PROJECT_DIR) texturec config=$(BUILD_TOOLS_CONFIG)
287	$(SILENT) cp .build/$(BUILD_OUTPUT_DIR)/bin/texturec$(BUILD_TOOLS_SUFFIX)$(EXE) tools/bin/$(OS)/texturec$(EXE)
288
289texturev: .build/projects/$(BUILD_PROJECT_DIR) ## Build texturev tool.
290	$(SILENT) $(MAKE) -C .build/projects/$(BUILD_PROJECT_DIR) texturev config=$(BUILD_TOOLS_CONFIG)
291	$(SILENT) cp .build/$(BUILD_OUTPUT_DIR)/bin/texturev$(BUILD_TOOLS_SUFFIX)$(EXE) tools/bin/$(OS)/texturev$(EXE)
292
293tools: geometryc geometryv shaderc texturec texturev ## Build tools.
294
295clean-tools: ## Clean tools projects.
296	-$(SILENT) rm -r .build/projects/$(BUILD_PROJECT_DIR)
297
298dist-windows: .build/projects/gmake-mingw-gcc
299	$(SILENT) $(MAKE) -C .build/projects/gmake-mingw-gcc config=release64 -j 6 geometryc
300	$(SILENT) cp .build/win64_mingw-gcc/bin/geometrycRelease.exe tools/bin/windows/geometryc.exe
301	$(SILENT) $(MAKE) -C .build/projects/gmake-mingw-gcc config=release64 -j 6 geometryv
302	$(SILENT) cp .build/win64_mingw-gcc/bin/geometryvRelease.exe tools/bin/windows/geometryv.exe
303	$(SILENT) $(MAKE) -C .build/projects/gmake-mingw-gcc config=release64 -j 6 shaderc
304	$(SILENT) cp .build/win64_mingw-gcc/bin/shadercRelease.exe   tools/bin/windows/shaderc.exe
305	$(SILENT) $(MAKE) -C .build/projects/gmake-mingw-gcc config=release64 -j 6 texturec
306	$(SILENT) cp .build/win64_mingw-gcc/bin/texturecRelease.exe  tools/bin/windows/texturec.exe
307	$(SILENT) $(MAKE) -C .build/projects/gmake-mingw-gcc config=release64 -j 6 texturev
308	$(SILENT) cp .build/win64_mingw-gcc/bin/texturevRelease.exe tools/bin/windows/texturev.exe
309
310dist-linux: .build/projects/gmake-linux
311	$(SILENT) $(MAKE) -C .build/projects/gmake-linux     config=release64 -j 6 geometryc
312	$(SILENT) cp .build/linux64_gcc/bin/geometrycRelease tools/bin/linux/geometryc
313	$(SILENT) $(MAKE) -C .build/projects/gmake-linux     config=release64 -j 6 geometryv
314	$(SILENT) cp .build/linux64_gcc/bin/geometryvRelease tools/bin/linux/geometryv
315	$(SILENT) $(MAKE) -C .build/projects/gmake-linux     config=release64 -j 6 shaderc
316	$(SILENT) cp .build/linux64_gcc/bin/shadercRelease   tools/bin/linux/shaderc
317	$(SILENT) $(MAKE) -C .build/projects/gmake-linux     config=release64 -j 6 texturec
318	$(SILENT) cp .build/linux64_gcc/bin/texturecRelease  tools/bin/linux/texturec
319	$(SILENT) $(MAKE) -C .build/projects/gmake-linux     config=release64 -j 6 texturev
320	$(SILENT) cp .build/linux64_gcc/bin/texturevRelease  tools/bin/linux/texturev
321
322dist-darwin: .build/projects/gmake-osx
323	$(SILENT) $(MAKE) -C .build/projects/gmake-osx       config=release64 -j 6 geometryc
324	$(SILENT) cp .build/osx64_clang/bin/geometrycRelease tools/bin/darwin/geometryc
325	$(SILENT) $(MAKE) -C .build/projects/gmake-osx       config=release64 -j 6 geometryv
326	$(SILENT) cp .build/osx64_clang/bin/geometryvRelease tools/bin/darwin/geometryv
327	$(SILENT) $(MAKE) -C .build/projects/gmake-osx       config=release64 -j 6 shaderc
328	$(SILENT) cp .build/osx64_clang/bin/shadercRelease   tools/bin/darwin/shaderc
329	$(SILENT) $(MAKE) -C .build/projects/gmake-osx       config=release64 -j 6 texturec
330	$(SILENT) cp .build/osx64_clang/bin/texturecRelease  tools/bin/darwin/texturec
331	$(SILENT) $(MAKE) -C .build/projects/gmake-osx       config=release64 -j 6 texturev
332	$(SILENT) cp .build/osx64_clang/bin/texturevRelease  tools/bin/darwin/texturev
333
334dist: clean dist-windows dist-linux dist-darwin
335