-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·271 lines (233 loc) · 8.24 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/usr/bin/make
#
# Copyright 2006 Sony Computer Entertainment Inc.
#
# Licensed under the MIT Open Source License, for details please see license.txt or the website
# http://www.opensource.org/licenses/mit-license.php
#
# Set oldMakeExport=yes to generate a makefile suitable for use with a pre-3.80
# version of make.
ifeq ($(oldMakeExport),yes)
printCommands := yes
printMessages := no
endif
printCommands := yes
printMessages := no
# By default, build messages are printed. These messages let the user know
# what's happening during the build.
ifneq ($(printMessages),no)
define printMessage
$(if $(not $(findstring plainEcho,$(2))),@)echo $(1)
endef
else
define printMessage
endef
endif
# By default, the actual build commands aren't printed.
ifneq ($(printCommands),yes)
.SILENT:
endif
# os: 'linux', 'mac', 'windows', or 'ps3'. Use the 'uname' command to decide the
# default value. To detect when we're on Windows we'll check to see if we're
# running on Cygwin or MinGW.
os := linux
ifneq ($(shell uname | grep -i darwin),)
os := mac
## This may have been valuable once, but as of 2014-01-24 it breaks the build
## CXX:=g++-4.0
# align with build-variables/variables as of 2016-08-24
# all except for -stdlib=libc++; we'll get there
MACFLAGS := -fno-stack-protector -O2 -fPIC -gdwarf-2 -mmacosx-version-min=10.7 -DMAC_OS_X_VERSION_MIN_REQUIRED=1070 -iwithsysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/
CXXFLAGS:= $(MACFLAGS)
LDFLAGS:= $(MACFLAGS)
else ifneq ($(or $(shell uname | grep -i cygwin),$(shell uname | grep -i mingw)),)
os := windows
else
#linux system, ensure we're using gcc-4.1 if nothing else specified
## Hopelessly outdated as of 2014-01-24
## CXX:=g++-4.1
endif
# nativeArch: For internal use. Don't override this, instead override 'arch'.
nativeArch := x86
ifneq ($(shell uname -p | grep -i powerpc),)
nativeArch := ppc
endif
# arch: x86 (or i386), x64 (or x86_64), ppc, ppc64
arch ?= i386
# project: 'dom', 'domTest', or 'all'
# project := minizip dom
project ?= dom domTest
# Release/debug configuration: 'release', 'debug', or 'all'
conf := all
# Collada version: '1.4', '1.5', or 'all'
colladaVersion := 1.4
# parser: 'libxml', 'tinyxml', or 'all'.
parser := libxml
# file: Set this to the name of a source file (eg 'dae.cpp') to build just that file
file :=
# Include any custom build settings
#-include ~/.collada-dom/customSettings.mk # Disabled as being appalling beyond bearing
-include make/customSettings.mk
-include make/installPrefix.mk
ifneq ($(findstring test,$(MAKECMDGOALS)),)
# If we're running the automated tests, make sure that everything gets a chance to build
project := all
endif
# Initialize the build variables
define setBuildVar
$(1)s := $(subst all,$(2),$($(1)))
ifneq ($$(filter-out $(2),$$($(1)s)),)
$$(error Invalid setting: $(1)=$($(1)))
endif
endef
oss := $(sort $(os))
ifneq ($(filter-out linux mac ps3 windows,$(oss)),)
$(error Invalid setting os=$(os))
endif
archs := $(sort $(subst i386,x86,$(arch)))
ifneq ($(filter-out x86 ppc x86_64 arm64,$(archs)),)
$(error Invalid setting arch=$(arch))
endif
$(eval $(call setBuildVar,project,minizip dom domTest))
$(eval $(call setBuildVar,colladaVersion,1.4 1.5))
$(eval $(call setBuildVar,conf,debug release))
$(eval $(call setBuildVar,parser,libxml tinyxml))
comma := ,
domMajorVersion := 2
domMinorVersion := 3
domVersion := $(domMajorVersion).$(domMinorVersion)
domVersionNoDots := $(subst .,,$(domVersion))
# Have make automatically delete a target if there's an error in one of the rule commands
.DELETE_ON_ERROR:
allOutputFiles :=
allTargets :=
define includeConfig
override project := $(1)
override os := $(2)
override colladaVersion := $(3)
override conf := $(4)
include make/$(1).mk
allOutputFiles += $$(outputFiles)
allTargets += $$(targets)
endef
$(foreach _project,$(projects),\
$(foreach _os,$(oss),\
$(foreach _colladaVersion,$(colladaVersions),\
$(foreach _conf,$(confs),\
$(eval $(call includeConfig,$(_project),$(_os),$(_colladaVersion),$(_conf)))))))
buildObj := $(filter %$(file:.cpp=.o),$(filter %.o,$(allOutputFiles)))
.DEFAULT_GOAL := all
.PHONY: all
ifeq ($(file),)
# Do a normal build of all targets
all: $(allTargets)
else ifneq ($(buildObj),)
# Just build the source files the user requested
all: $(buildObj)
else
$(error Invalid source file - $(file))
endif
allOutputPaths := $(sort $(dir $(allOutputFiles)))
$(allOutputPaths):
if [ ! -d $@ ] ; then mkdir -p $@; fi;
##############################################
# clean
#
.PHONY: clean
clean:
$(call printMessage,Removing build files.)
# Delete all the output files
rm -rf $(allOutputFiles)
# Delete each empty output folder
for path in $(allOutputPaths); do \
if [ -d $$path ] && [ `find $$path -type f | wc -l` -eq 0 ]; then rm -r $$path ; fi \
done;
# Delete the build folder if it's empty
if [ -d build ] && [ `find build -type f | wc -l` -eq 0 ] ; then rm -r build ; fi
##############################################
# test target for running the automated tests.
#
# Note: I originally had a separate target for each test, one reason being so that each
# test suite could be run in parallel. However when running in parallel I'd get weird errors where
# some of the tests would fail and some would succeed, with error messages like this:
# I/O error : No such file or directory
# I/O error : No such file or directory
# error : xmlNewTextWriterFilename : out of memory!
# To work around this, I changed to using a single target with a shell loop to run each test program.
# This way the tests are forced to run serially.
domTestOpts := -all
domTestExes := $(filter %domTest,$(allTargets))
.PHONY: test
test: $(domTestExes)
@for testExe in $(domTestExes); do \
$(call printMessage,$$testExe $(domTestOpts);,plainEcho) \
$$testExe $(domTestOpts); \
done
##############################################
# install/uninstall
#
ifneq ($(filter install uninstall installTest,$(MAKECMDGOALS)),)
# You can only install on Mac or Linux. Check for that.
ifeq ($(oss),linux)
prefix := /usr/local
else ifeq ($(oss),mac)
prefix := /Library/Frameworks
else
$(error You can only install with 'os' set to 'mac' or 'linux')
endif
endif
.PHONY: uninstall
ifneq ($(installPrefix),)
ifeq ($(oss),linux)
uninstall:
$(call printMessage,Uninstalling from $(installPrefix))
rm -rf $(installPrefix)/include/colladadom
rm -f $(installPrefix)/lib/libcollada*dom*
else ifeq ($(oss),mac)
uninstall:
$(call printMessage,Uninstalling from $(prefix))
rm -rf $(installPrefix)/libcollada*dom*.framework
endif
else ifneq ($(findstring uninstall,$(MAKECMDGOALS)),)
$(error Can't uninstall because we don't know what path we installed to (missing make/installPrefix.mk file))
else
uninstall:
endif
# 1st param is build path, 2nd param is framework name, 3rd param is framework version number
# e.g. $(call installMacFrameworkCmd,build/mac-1.4,libcollada14dom.framework,2.0)
define installMacFrameworkCmd
if [ -d $(1) ]; then \
cp -R $(1)/$(2) $(prefix)/$(2); \
install_name_tool -id $(prefix)/$(2)/Versions/$(3)/$(basename $(2)) $(prefix)/$(2)/$(basename $(2)); \
fi;
endef
.PHONY: install
ifeq ($(oss),linux)
install: uninstall
$(call printMessage,Installing to $(prefix))
# Write the install prefix to the file make/installPrefix.mk so we can retrieve it for uninstalling.
echo 'installPrefix := $(prefix)' > make/installPrefix.mk
# Install headers
cp -R include $(prefix)/include/colladadom
# We write this as a loop to avoid an error when there are no files to remove
for svndir in $(find $(prefix)/include/colladadom -name '.svn'); do rm -rf $svndir; done
# Install linux-1.4 libs
if [ -d build/linux-1.4 ]; then cp -P build/linux-1.4/libcollada*dom* $(prefix)/lib; fi;
# Install linux-1.4-d libs
if [ -d build/linux-1.4-d ]; then cp -P build/linux-1.4-d/libcollada*dom* $(prefix)/lib; fi;
else ifeq ($(oss),mac)
install: uninstall
$(call printMessage,Installing to $(prefix))
echo 'installPrefix := $(prefix)' > make/installPrefix.mk
$(call installMacFrameworkCmd,build/mac-1.4,libcollada14dom.framework,$(domVersion))
$(call installMacFrameworkCmd,build/mac-1.4-d,libcollada14dom-d.framework,$(domVersion))
endif
.PHONY: installTest
installTest:
$(MAKE) install
$(MAKE) clean project=domTest
$(MAKE) test installTest=yes
$(MAKE) uninstall
$(MAKE) clean project=domTest
$(MAKE) project=domTest
$(call printMessage,installTest done)