-
Notifications
You must be signed in to change notification settings - Fork 75
/
Makefile
285 lines (233 loc) · 8.42 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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
RM = rm -f
MKDIR = mkdir -p
INSTALL_X = install -m 0755
INSTALL_F = install -m 0644
CFLAGS ?= -Wall
CPPFLAGS = -Ilua/src -Isrc -Iunittest/googletest/googletest/include -Iunittest/googletest/googletest -MMD -MP -DHAVE_GIT_INFO
CXXFLAGS ?= $(CFLAGS) -fno-exceptions
CXXLIBFLAGS ?=
LDFLAGS += -L$(BUILDDIR) -ltundra
PREFIX ?= /usr/local
# Handle travis builds specially - just trust what the CI tells us.
ifdef GITHUB_SHA
GIT_BRANCH := "releases"
else
GIT_BRANCH := $(shell (git branch --no-color 2>/dev/null) | sed -n '/^\*/s/^\* //p')
ifeq ($(GIT_BRANCH),)
GIT_BRANCH := unknown
GIT_FILE := dummy_version_file
else
GIT_FILE := .git/refs/heads/$(GIT_BRANCH)
endif
endif
CHECKED ?= no
ifeq ($(CHECKED), no)
CFLAGS += -O3 -DNDEBUG
BUILDDIR := build
else
CFLAGS += -g -D_DEBUG
BUILDDIR := build.checked
endif
CROSSMINGW ?= no
EXESUFFIX =
ifeq ($(CROSSMINGW), yes)
# Cross-compiling for windows on unix-like platform.
CROSS ?= x86_64-w64-mingw32-
CC := $(CROSS)gcc
CXX := $(CROSS)g++
AR := $(CROSS)ar rcus
CXXFLAGS += -std=gnu++11
CPPFLAGS += -D_WIN32 -DWINVER=0x0600 -D_WIN32_WINNT=0x0600 -D__MSVCRT_VERSION__=0x0601 -DFORCEINLINE='__inline __attribute__((always_inline))'
BUILDDIR := build.mingw
EXESUFFIX := .exe
else
CC ?= clang
CXX ?= clang++
AR= ar rcus
# Not cross-compiling. Detect options based on uname output.
UNAME := $(shell uname)
ifeq ($(UNAME), $(filter $(UNAME), FreeBSD NetBSD OpenBSD))
CC := clang
CXX := clang++
CXXFLAGS += -std=c++11
LDFLAGS += -lpthread
else
ifeq ($(UNAME), $(filter $(UNAME), Linux))
CC := clang
CXX := clang++
CXXFLAGS += -std=c++11
LDFLAGS += -pthread
else
ifeq ($(UNAME), $(filter $(UNAME), Darwin))
CXXFLAGS += -std=c++11
CXXFLAGS += -stdlib=libc++
LDFLAGS += -stdlib=libc++
else
ifeq ($(UNAME), $(filter $(UNAME), MINGW32_NT-5.1))
CXXFLAGS += -std=gnu++11
CPPFLAGS += -D_WIN32 -DWINVER=0x0501 -D_WIN32_WINNT=0x0501 -U__STRICT_ANSI__
EXESUFFIX := .exe
else
ifeq (MINGW32_NT, $(findstring MINGW32_NT, $(UNAME)))
CXXFLAGS += -std=gnu++11
CPPFLAGS += -D_WIN32 -DWINVER=0x0600 -D_WIN32_WINNT=0x0600 -D__MSVCRT_VERSION__=0x0601 -U__STRICT_ANSI__
EXESUFFIX := .exe
else
$(error "unknown platform $(UNAME)")
endif
endif
endif
endif
endif
endif
VPATH = lua/src:src:$(BUILDDIR):unittest
LUA_SOURCES = \
lapi.c lauxlib.c lbaselib.c lcode.c \
ldblib.c ldebug.c ldo.c ldump.c \
lfunc.c lgc.c linit.c liolib.c \
llex.c lmathlib.c lmem.c loadlib.c \
lobject.c lopcodes.c loslib.c lparser.c \
lstate.c lstring.c lstrlib.c ltable.c \
ltablib.c ltm.c lundump.c lvm.c \
lzio.c
LIBTUNDRA_SOURCES = \
BinaryWriter.cpp BuildQueue.cpp Common.cpp DagGenerator.cpp \
Driver.cpp FileInfo.cpp Hash.cpp HashTable.cpp \
IncludeScanner.cpp JsonParse.cpp MemAllocHeap.cpp \
MemAllocLinear.cpp MemoryMappedFile.cpp PathUtil.cpp Profiler.cpp \
ScanCache.cpp Scanner.cpp SignalHandler.cpp StatCache.cpp \
TargetSelect.cpp Thread.cpp TerminalIo.cpp \
ExecUnix.cpp ExecWin32.cpp DigestCache.cpp FileSign.cpp \
HashSha1.cpp HashFast.cpp ConditionVar.cpp ReadWriteLock.cpp
T2LUA_SOURCES = LuaMain.cpp LuaInterface.cpp LuaInterpolate.cpp LuaJsonWriter.cpp \
LuaPath.cpp LuaProfiler.cpp
T2INSPECT_SOURCES = InspectMain.cpp
UNITTEST_SOURCES = \
TestHarness.cpp Test_BitFuncs.cpp Test_Buffer.cpp Test_Djb2.cpp Test_Hash.cpp \
Test_IncludeScanner.cpp Test_Json.cpp Test_MemAllocLinear.cpp Test_Pow2.cpp \
Test_TargetSelect.cpp test_PathUtil.cpp Test_HashTable.cpp
TUNDRA_SOURCES = Main.cpp
PATHCONTROL_SOURCES = PathControl.cpp
LUA_OBJECTS := $(addprefix $(BUILDDIR)/,$(LUA_SOURCES:.c=.o))
LIBTUNDRA_OBJECTS := $(addprefix $(BUILDDIR)/,$(LIBTUNDRA_SOURCES:.cpp=.o))
LIBTUNDRA_OBJECTS := $(LIBTUNDRA_OBJECTS:.c=.o)
T2LUA_OBJECTS := $(addprefix $(BUILDDIR)/,$(T2LUA_SOURCES:.cpp=.o))
T2INSPECT_OBJECTS := $(addprefix $(BUILDDIR)/,$(T2INSPECT_SOURCES:.cpp=.o))
UNITTEST_OBJECTS := $(addprefix $(BUILDDIR)/,$(UNITTEST_SOURCES:.cpp=.o))
TUNDRA_OBJECTS := $(addprefix $(BUILDDIR)/,$(TUNDRA_SOURCES:.cpp=.o))
ALL_SOURCES = \
$(TUNDRA_SOURCES) \
$(LIBTUNDRA_SOURCES) \
$(LUA_SOURCES) \
$(T2LUA_SOURCES) \
$(T2INSPECT_SOURCES) \
$(PATHCONTROL_SOURCES)
ALL_DEPS = $(ALL_SOURCES:.cpp=.d)
ALL_DEPS := $(addprefix $(BUILDDIR)/,$(ALL_DEPS:.c=.d))
INSTALL_BASE = $(DESTDIR)$(PREFIX)
INSTALL_BIN = $(INSTALL_BASE)/bin
INSTALL_SCRIPT = $(INSTALL_BASE)/share/tundra
INSTALL_DIRS = $(INSTALL_BIN) $(INSTALL_SCRIPT)
UNINSTALL_DIRS = $(INSTALL_SCRIPT)
FILES_BIN = tundra2$(EXESUFFIX) t2-lua$(EXESUFFIX) t2-inspect$(EXESUFFIX)
all: $(BUILDDIR)/tundra2$(EXESUFFIX) \
$(BUILDDIR)/t2-lua$(EXESUFFIX) \
$(BUILDDIR)/t2-inspect$(EXESUFFIX) \
$(BUILDDIR)/t2-unittest$(EXESUFFIX)
ifdef GITHUB_SHA
$(BUILDDIR)/git_version_$(GIT_BRANCH).c:
echo "const char g_GitVersion[] = \"$(GITHUB_SHA)\";" > $@ && \
echo "const char g_GitBranch[] = \"$(GITHUB_REF)\";" >> $@
else
$(BUILDDIR)/git_version_$(GIT_BRANCH).c: $(GIT_FILE)
sed 's/^\(.*\)/const char g_GitVersion[] = "\1";/' < $^ > $@ && \
echo 'const char g_GitBranch[] ="'$(GIT_BRANCH)'";' >> $@
endif
$(BUILDDIR)/git_version_$(GIT_BRANCH).o: $(BUILDDIR)/git_version_$(GIT_BRANCH).c
GIT_OBJS = $(BUILDDIR)/git_version_$(GIT_BRANCH).o
#Q ?= @
#E ?= @echo
Q ?=
E ?= @:
$(BUILDDIR):
$(MKDIR) $(BUILDDIR)
$(BUILDDIR)/%.o: %.c
@mkdir -p $(BUILDDIR)
$(E) "CC $<"
$(Q) $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $<
$(BUILDDIR)/%.o: %.cpp
@mkdir -p $(BUILDDIR)
$(E) "CXX $<"
$(Q) $(CXX) -c -o $@ $(CPPFLAGS) $(CXXFLAGS) $<
$(BUILDDIR)/libtundralua.a: $(LUA_OBJECTS)
$(E) "AR $@"
$(Q) $(AR) $@ $^
$(BUILDDIR)/libtundra.a: $(LIBTUNDRA_OBJECTS)
$(E) "AR $@"
$(Q) $(AR) $@ $^
$(BUILDDIR)/tundra2$(EXESUFFIX): $(TUNDRA_OBJECTS) $(BUILDDIR)/libtundra.a $(GIT_OBJS)
$(E) "LINK $@"
$(Q) $(CXX) -o $@ $(CXXLIBFLAGS) $(GIT_OBJS) $(TUNDRA_OBJECTS) $(LDFLAGS)
$(BUILDDIR)/t2-lua$(EXESUFFIX): $(T2LUA_OBJECTS) $(BUILDDIR)/libtundra.a $(BUILDDIR)/libtundralua.a
$(E) "LINK $@"
$(Q) $(CXX) -o $@ $(CXXLIBFLAGS) $(T2LUA_OBJECTS) $(LDFLAGS) -ltundralua
$(BUILDDIR)/t2-inspect$(EXESUFFIX): $(T2INSPECT_OBJECTS) $(BUILDDIR)/libtundra.a
$(E) "LINK $@"
$(Q) $(CXX) -o $@ $(CXXLIBFLAGS) $(T2INSPECT_OBJECTS) $(LDFLAGS)
$(BUILDDIR)/t2-unittest$(EXESUFFIX): $(UNITTEST_OBJECTS) $(BUILDDIR)/libtundra.a
$(E) "LINK $@"
$(Q) $(CXX) -o $@ $(CXXLIBFLAGS) $(UNITTEST_OBJECTS) $(LDFLAGS)
$(BUILDDIR)/PathControl$(EXESUFFIX): PathControl.cpp
@mkdir -p $(BUILDDIR)
$(E) "LINK $@"
$(Q) $(CXX) -o $@ $(CPPFLAGS) $(CXXFLAGS) $(CXXLIBFLAGS) -DUNICODE $^
install:
@echo "Installing Tundra2 to $(INSTALL_BASE)"
$(MKDIR) $(INSTALL_DIRS)
cd $(BUILDDIR) && $(INSTALL_X) $(FILES_BIN) $(INSTALL_BIN)
cp -r scripts/* $(INSTALL_SCRIPT)
@echo "Installation complete"
uninstall:
@echo "Uninstalling Tundra2 from $(INSTALL_BASE)"
$(RM) -r $(UNINSTALL_DIRS)
for file in $(FILES_BIN); do \
$(RM) $(INSTALL_BIN)/$$file; \
done
@echo "Uninstallation complete"
clean:
$(RM) -r $(BUILDDIR)
$(BUILDDIR)/tundra-manual.html: doc/manual.asciidoc
asciidoc -o $@ $^
ALL_SCRIPTS := $(shell find scripts -name \*.lua -or -name \*.xml)
INSTALL_PRODUCTS = \
$(BUILDDIR)/tundra2$(EXESUFFIX) \
$(BUILDDIR)/t2-inspect$(EXESUFFIX) \
$(BUILDDIR)/t2-lua$(EXESUFFIX) \
$(BUILDDIR)/PathControl$(EXESUFFIX) \
$(BUILDDIR)/tundra-manual.html \
$(ALL_SCRIPTS)
installer: $(BUILDDIR)/Tundra-Setup.exe
windows-zip: $(BUILDDIR)/Tundra-Binaries.zip
$(BUILDDIR)/Tundra-Binaries.zip: $(INSTALL_PRODUCTS)
mkdir $(BUILDDIR)/__zip && \
mkdir $(BUILDDIR)/__zip/tundra && \
mkdir $(BUILDDIR)/__zip/tundra/bin && \
mkdir $(BUILDDIR)/__zip/tundra/doc && \
ln -s $$PWD/$(BUILDDIR)/tundra2$(EXESUFFIX) $(BUILDDIR)/__zip/tundra/bin/ && \
ln -s $$PWD/$(BUILDDIR)/t2-inspect$(EXESUFFIX) $(BUILDDIR)/__zip/tundra/bin/ && \
ln -s $$PWD/$(BUILDDIR)/t2-lua$(EXESUFFIX) $(BUILDDIR)/__zip/tundra/bin/ && \
ln -s $$PWD/$(BUILDDIR)/tundra-manual.html $(BUILDDIR)/__zip/tundra/doc/ && \
ln -s $$PWD/scripts $(BUILDDIR)/__zip/tundra/ && \
(cd $(BUILDDIR)/__zip && zip -r -9 ../Tundra-Binaries.zip tundra) && \
rm -rf $(BUILDDIR)/__zip
$(BUILDDIR)/Tundra-Setup.exe: \
$(INSTALL_PRODUCTS) \
windows-installer/tundra.nsi
makensis -NOCD -DBUILDDIR=$(BUILDDIR) windows-installer/tundra.nsi > $(BUILDDIR)/nsis.log 2>&1
.PHONY: clean all install uninstall installer win-zip run-unit-tests run-functional-tests run-all-tests
run-unit-tests: $(BUILDDIR)/t2-unittest$(EXESUFFIX)
$(BUILDDIR)/t2-unittest$(EXESUFFIX)
run-functional-tests: $(BUILDDIR)/tundra2$(EXESUFFIX)
perl run-tests.pl $(BUILDDIR)/tundra2$(EXESUFFIX)
run-all-tests: run-unit-tests run-functional-tests
-include $(ALL_DEPS)