-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
324 lines (270 loc) · 7.63 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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# gmake CC=gcc EXTRA_LDFLAGS=-Lvendor/gsl/mingw/x64
OS ?= $(shell uname -s)
CC ?= cc
CXX ?= c++
RM ?= rm -f
CP ?= cp -a
MKDIR ?= mkdir
RMDIR ?= rmdir
WINDRES ?= windres
# Solaris/Illumos flavors
# ginstall from coreutils
ifeq ($(OS),SunOS)
INSTALL ?= ginstall
endif
INSTALL ?= install
CFLAGS ?= -Wall
CXXFLAGS ?= -Wall
LDFLAGS ?= -Wall
OPTIMIZE ?= -O3
LDLIBS ?=
CFLAGS += -fno-omit-frame-pointer
CXXFLAGS += -fno-omit-frame-pointer
LDFLAGS += -fno-omit-frame-pointer
ifdef COVERAGE
OPTIMIZE = -O1
CFLAGS += -g -pipe -DNDEBUG
CXXFLAGS += -g -pipe -DNDEBUG
LDFLAGS += -g -pipe -DNDEBUG
endif
ifdef ASAN
OPTIMIZE = -O1
CFLAGS += -g -fsanitize=address -fno-omit-frame-pointer
CXXFLAGS += -g -fsanitize=address -fno-omit-frame-pointer
LDFLAGS += -g -fsanitize=address -fno-omit-frame-pointer
LDLIBS += -lasan
endif
ifeq "$(ANLIB_GPO)" "generate"
CFLAGS += -fprofile-generate
CXXFLAGS += -fprofile-generate
LDFLAGS += -fprofile-generate -Wl,-fprofile-instr-generate
endif
ifeq "$(ANLIB_GPO)" "use"
CFLAGS += -fprofile-use
CXXFLAGS += -fprofile-use
LDFLAGS += -fprofile-use -Wl,-fprofile-instr-use
endif
CAT ?= $(if $(filter $(OS),Windows_NT),type,cat)
ifneq (,$(findstring /cygdrive/,$(PATH)))
UNAME := Cygwin
else
ifneq (,$(findstring Windows_NT,$(OS)))
UNAME := Windows
else
ifneq (,$(findstring mingw32,$(MAKE)))
UNAME := Windows
else
ifneq (,$(findstring MINGW32,$(shell uname -s)))
UNAME := Windows
else
UNAME := $(shell uname -s)
endif
endif
endif
endif
ifndef ANLIB_VERSION
ifneq ($(wildcard ./.git/ ),)
ANLIB_VERSION ?= $(shell git describe --abbrev=4 --dirty --always --tags)
endif
ifneq ($(wildcard VERSION),)
ANLIB_VERSION ?= $(shell $(CAT) VERSION)
endif
endif
ifdef ANLIB_VERSION
CFLAGS += -DANLIB_VERSION="\"$(ANLIB_VERSION)\""
CXXFLAGS += -DANLIB_VERSION="\"$(ANLIB_VERSION)\""
endif
# CXXFLAGS += -std=c++11
# LDFLAGS += -std=c++11
ifeq (Windows,$(UNAME))
# ifneq ($(BUILD),shared)
# STATIC_ALL ?= 1
# endif
STATIC_LIBGCC ?= 1
STATIC_LIBSTDCPP ?= 1
else
STATIC_ALL ?= 0
STATIC_LIBGCC ?= 0
STATIC_LIBSTDCPP ?= 0
endif
ifndef ANLIB_PATH
ANLIB_PATH = $(CURDIR)/astrometrylib
endif
ifdef ANLIB_PATH
CFLAGS += -I $(ANLIB_PATH)/src/include
CXXFLAGS += -I $(ANLIB_PATH)/src/include
else
# this is needed for mingw
CFLAGS += -I include
CXXFLAGS += -I include
endif
ifndef GSL_PATH
GSL_PATH += $(CURDIR)/vendor/gsl
endif
ifndef STB_PATH
STB_PATH += $(CURDIR)/vendor/stb
endif
ifndef SEP_PATH
SEP_PATH += $(CURDIR)/vendor/sep
endif
CFLAGS += $(OPTIMIZE)
CXXFLAGS += $(OPTIMIZE)
LDFLAGS += $(OPTIMIZE)
CFLAGS += -I $(GSL_PATH)
CXXFLAGS += -I $(GSL_PATH)
CFLAGS += -I $(STB_PATH)
CXXFLAGS += -I $(STB_PATH)
CFLAGS += -I $(SEP_PATH)
CXXFLAGS += -I $(SEP_PATH)
CFLAGS += -I $(ANLIB_PATH)
CXXFLAGS += -I $(ANLIB_PATH)
CFLAGS += $(EXTRA_CFLAGS)
CXXFLAGS += $(EXTRA_CXXFLAGS)
LDFLAGS += $(EXTRA_LDFLAGS)
LDLIBS += -lgsl -lgslcblas -lpthread
ifneq ($(BUILD),shared)
ifneq ($(STATIC_LIBSTDCPP),1)
LDLIBS += -lstdc++
endif
endif
# link statically into lib
# makes it a lot more portable
# increases size by about 50KB
ifeq ($(STATIC_ALL),1)
LDFLAGS += -static
endif
ifeq ($(STATIC_LIBGCC),1)
LDFLAGS += -static-libgcc
endif
ifeq ($(STATIC_LIBSTDCPP),1)
LDFLAGS += -static-libstdc++
endif
ifeq ($(UNAME),Darwin)
CFLAGS += -stdlib=libc++
CXXFLAGS += -stdlib=libc++
LDFLAGS += -stdlib=libc++
endif
ifneq (Windows,$(UNAME))
ifneq (FreeBSD,$(UNAME))
ifneq (OpenBSD,$(UNAME))
LDFLAGS += -ldl
LDLIBS += -ldl
endif
endif
endif
ifneq ($(BUILD),shared)
BUILD := static
endif
ifeq ($(DEBUG),1)
BUILD := debug-$(BUILD)
endif
ifndef TRAVIS_BUILD_DIR
ifeq ($(OS),SunOS)
PREFIX ?= /opt/local
else
PREFIX ?= /usr/local
endif
else
PREFIX ?= $(TRAVIS_BUILD_DIR)
endif
DEMO_EXE = demo/demo
RESOURCES =
STATICLIB = lib/astrometrylib.a
SHAREDLIB = lib/astrometrylib.so
LIB_STATIC = $(ANLIB_PATH)/lib/astrometrylib.a
LIB_SHARED = $(ANLIB_PATH)/lib/astrometrylib.so
ifeq ($(UNAME),Darwin)
SHAREDLIB = lib/astrometrylib.dylib
LIB_SHARED = $(ANLIB_PATH)/lib/astrometrylib.dylib
endif
ifeq (Windows,$(UNAME))
DEMO_EXE = demo/demo.exe
RESOURCES += res/resource.rc
SHAREDLIB = lib/astrometrylib.dll
ifeq (shared,$(BUILD))
CFLAGS += -D ADD_EXPORTS
CXXFLAGS += -D ADD_EXPORTS
LIB_SHARED = $(ANLIB_PATH)/lib/astrometrylib.dll
endif
else
ifneq (Cygwin,$(UNAME))
CFLAGS += -fPIC
CXXFLAGS += -fPIC
LDFLAGS += -fPIC
endif
endif
include Makefile.conf
COBJECTS = $(addprefix ./,$(CFILES:.cpp=.o))
CPPOBJECTS = $(addprefix ./,$(CPPFILES:.c=.o))
HEADOBJS = $(addprefix ./,$(HPPFILES:.hpp=.hpp.gch))
RCOBJECTS = $(RESOURCES:.rc=.o)
DEBUG_LVL ?= NONE
CLEANUPS ?=
CLEANUPS += $(RCOBJECTS)
CLEANUPS += $(CPPOBJECTS)
CLEANUPS += $(COBJECTS)
CLEANUPS += $(HEADOBJS)
CLEANUPS += $(ANLIB_LIB)
demog.exe: $(BUILD)
$(CXX) $(COBJECTS) $(CPPOBJECTS) $(LDFLAGS) $(LDLIBS) -o $(DEMO_EXE)
all: demo.exe
debug: $(BUILD)
debug-static: LDFLAGS := -g $(filter-out -O2,$(LDFLAGS))
debug-static: CFLAGS := -g -DDEBUG -DDEBUG_LVL="$(DEBUG_LVL)" $(filter-out -O2,$(CFLAGS))
debug-static: CXXFLAGS := -g -DDEBUG -DDEBUG_LVL="$(DEBUG_LVL)" $(filter-out -O2,$(CXXFLAGS))
debug-static: static
debug-shared: LDFLAGS := -g $(filter-out -O2,$(LDFLAGS))
debug-shared: CFLAGS := -g -DDEBUG -DDEBUG_LVL="$(DEBUG_LVL)" $(filter-out -O2,$(CFLAGS))
debug-shared: CXXFLAGS := -g -DDEBUG -DDEBUG_LVL="$(DEBUG_LVL)" $(filter-out -O2,$(CXXFLAGS))
debug-shared: shared
lib:
$(MKDIR) lib
lib/astrometrylib.a: $(CPPOBJECTS) $(COBJECTS) | lib
$(AR) rcvs $@ $(CPPOBJECTS) $(COBJECTS)
lib/astrometrylib.so: $(CPPOBJECTS) $(COBJECTS) | lib
$(CXX) -shared $(LDFLAGS) -o $@ $(CPPOBJECTS) $(COBJECTS) $(LDLIBS)
lib/astrometrylib.dylib: $(CPPOBJECTS) $(COBJECTS) | lib
$(CXX) -shared $(LDFLAGS) -o $@ $(CPPOBJECTS) $(COBJECTS) $(LDLIBS) \
-install_name @rpath/astrometrylib.dylib
lib/astrometrylib.dll: $(CPPOBJECTS) $(COBJECTS) $(RCOBJECTS) | lib
$(CXX) -shared $(LDFLAGS) -o $@ $(CPPOBJECTS) $(COBJECTS) $(RCOBJECTS) $(LDLIBS) \
-s -Wl,--subsystem,windows,--out-implib,lib/astrometrylib.a
$(RCOBJECTS): %.o: %.rc
$(WINDRES) -i $< -o $@
$(COBJECTS): %.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
$(CPPOBJECTS): %.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
$(HEADOBJS): %.hpp.gch: %.hpp
$(CXX) $(CXXFLAGS) -x c++-header -c -o $@ $<
%: %.o static
$(CXX) $(CXXFLAGS) -o $@ $+ $(LDFLAGS) $(LDLIBS)
static: $(STATICLIB)
shared: $(SHAREDLIB)
$(DESTDIR)$(PREFIX):
$(MKDIR) $(DESTDIR)$(PREFIX)
$(DESTDIR)$(PREFIX)/lib: | $(DESTDIR)$(PREFIX)
$(MKDIR) $(DESTDIR)$(PREFIX)/lib
$(DESTDIR)$(PREFIX)/include: | $(DESTDIR)$(PREFIX)
$(MKDIR) $(DESTDIR)$(PREFIX)/include
$(DESTDIR)$(PREFIX)/lib/%.a: lib/%.a \
| $(DESTDIR)$(PREFIX)/lib
@$(INSTALL) -v -m0755 "$<" "$@"
$(DESTDIR)$(PREFIX)/lib/%.so: lib/%.so \
| $(DESTDIR)$(PREFIX)/lib
@$(INSTALL) -v -m0755 "$<" "$@"
$(DESTDIR)$(PREFIX)/lib/%.dll: lib/%.dll \
| $(DESTDIR)$(PREFIX)/lib
@$(INSTALL) -v -m0755 "$<" "$@"
$(DESTDIR)$(PREFIX)/lib/%.dylib: lib/%.dylib \
| $(DESTDIR)$(PREFIX)/lib
@$(INSTALL) -v -m0755 "$<" "$@"
test: test_build
clean-objects: | lib
-$(RM) lib/*.a lib/*.so lib/*.dll lib/*.dylib lib/*.la $(DEMO_EXE)
-$(RMDIR) lib
clean: clean-objects
$(RM) $(CLEANUPS)
.PHONY: all static shared version \
clean clean-objects
.DELETE_ON_ERROR: