-
Notifications
You must be signed in to change notification settings - Fork 43
/
makefile
368 lines (311 loc) · 9.7 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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# Make file for console Find_Orb, using regular Curses
# Use 'bsdmake' for BSD
# GNU MAKE Makefile for Find_Orb
#
# Usage: make -f [path/]linmake [CLANG=Y] [W32=Y] [W64=Y] [MSWIN=Y] [X=Y] [VT=Y] [tgt]
#
# where tgt can be any of:
# [all|find_orb|fo|fo_serve|clean|clean_temp|eph2tle|cssfield|neat_xvt]
#
# 'W32'/'W64' = cross-compile for 32- or 64-bit Windows, using MinGW-w64,
# on a Linux box
# 'MSWIN' = compile for Windows, using MinGW and PDCurses, on a Windows machine
# 'CLANG' = use clang instead of GCC; Linux only
# 'X' = use PDCurses instead of ncurses
# 'VT' = use PDCurses with VT platform (see github.com/Bill-Gray/PDCurses/vt)
# 'CXX=g++-4.8' = use that version of g++; helpful when testing older compilers
# None of these: compile using g++ on Linux, for Linux
#
# 'clean_temp' removes various temporary files made by Find_Orb and friends:
# orbital elements, covariance matrices, etc. 'clean' removes these _and_
# the more usual object and executable files.
# As CXX is an implicit variable, a simple CXX?=g++ doesn't work.
# We have to use this trick from https://stackoverflow.com/a/42958970
ifeq ($(origin CXX),default)
ifdef CLANG
CXX=clang++
CC=clang
else
CXX=g++
CC=gcc
endif
endif
LIBSADDED=-L $(INSTALL_DIR)/lib -lm
EXE=
RM=rm -f
ifeq ($(shell uname -s),FreeBSD)
CC=cc
CXX=c++
endif
ifeq ($(OS),Windows_NT)
detected_OS := Windows
else
detected_OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
endif
ifeq ($(detected_OS),Linux)
CP = cp -u
else
CP = cp
endif
# I'm using 'mkdir -p' to avoid error messages if the directory exists.
# It may fail on very old systems, and will probably fail on non-POSIX
# systems. If so, change to '-mkdir' and ignore errors.
ifdef MSWIN
LIBSADDED=-static-libgcc
EXE=.exe
CURSES_LIB=-lpdcurses
MKDIR=-mkdir
DEFAULT_PREFIX=..
else
MKDIR=mkdir -p
DEFAULT_PREFIX=~
endif
# You can have your include files in ~/include and libraries in
# ~/lib, in which case only the current user can use them; or
# (with root privileges) you can install them to /usr/local/include
# and /usr/local/lib for all to enjoy.
PREFIX?=$(DEFAULT_PREFIX)
ifdef GLOBAL
INSTALL_DIR=/usr/local
else
INSTALL_DIR=$(PREFIX)
endif
ifneq ($(PREFIX),$(DEFAULT_PREFIX))
# enable the automatic setup of ../.find_orb dir from
# $PREFIX/share/openorb. This at the moment requires C++17 features
# and works on Linux and macOS
CXXFLAGS+=-DCONFIG_DIR_AUTOCOPY=1 -std=c++17
endif
ifdef X
CURSES_FLAGS=-DXCURSES -I../PDCursesMod
CURSES_LIB=-lXCurses -lXaw -lXmu -lXt -lX11 -lSM -lICE -lXext -lXpm
endif
ifdef VT
CURSES_FLAGS=-DVT -I$(HOME)/PDCursesMod
CURSES_LIB=-lpdcurses
endif
ifdef DRM
CURSES_FLAGS=-DVT -I$(HOME)/PDCursesMod
CURSES_LIB=$(HOME)/PDCursesMod/fb/libpdcurses.a -ldrm
endif
LIB_DIR=$(INSTALL_DIR)/lib
ifdef W64
MINGW=x86_64-w64-mingw32-
LIB_DIR=$(INSTALL_DIR)/win_lib
BITS=64
endif
ifdef W32
MINGW=i686-w64-mingw32-
LIB_DIR=$(INSTALL_DIR)/win_lib32
BITS=32
endif
ifdef MINGW
CXX=$(MINGW)gcc
CC=$(MINGW)gcc
WINDRES=$(MINGW)windres
CURSES_FLAGS=-I../PDCursesMod
EXE=.exe
CURSES_LIB=-lpdcurses
LIBSADDED=-L $(LIB_DIR) -lm -lgdi32 -luser32 -mwindows -static-libgcc
FO_EXE=fo$(BITS).exe
FIND_ORB_EXE=find_o$(BITS).exe
RES_FILENAME=find_orb.res
endif
ifndef FO_EXE
FO_EXE=fo
FIND_ORB_EXE=find_orb
endif
all: $(FO_EXE) $(FIND_ORB_EXE) fo_serve.cgi eph2tle$(EXE)
CXXFLAGS+=-c -Wall -pedantic -Wextra $(ADDED_CXXFLAGS) -I $(INSTALL_DIR)/include
ifndef NO_ERRORS
CXXFLAGS += -Werror
endif
ifdef UCHAR
CXXFLAGS += -funsigned-char
endif
ifdef DEBUG
CXXFLAGS += -g -Og
else
CXXFLAGS += -O3
endif
OBJS=ades_out.o b32_eph.o bc405.o bias.o collide.o conv_ele.o details.o eigen.o \
elem2tle.o elem_out.o elem_ou2.o ephem0.o errors.o expcalc.o gauss.o \
geo_pot.o healpix.o lsquare.o miscell.o monte0.o \
mpc_obs.o orb_func.o orb_fun2.o pl_cache.o roots.o \
runge.o shellsor.o sigma.o simplex.o sm_vsop.o sr.o stackall.o
miscell.o: prefix.h
LIBS=$(LIBSADDED) -llunar -ljpl -lsatell
FIND_ORB_OBJS = clipfunc.o getstrex.o
# If no Curses library has been specified, we use ncursesw if it's
# available. Otherwise, we use the ncurses lib and hope it actually
# supports wide characters (Unicode).
ifeq ($(CURSES_LIB),)
ifeq ($(shell $(CXX) -lncursesw 2>&1 > /dev/null | grep -E '(find|found)'),)
CURSES_LIB=-lncursesw
else
CURSES_LIB=-lncurses
endif
endif
#
# This magic is from https://stackoverflow.com/a/26147844
# (with mjuric's modifications to support POSIX sh).
# It ensures the code gets rebuilt if $PREFIX changes.
#
define DEPENDABLE_VAR
.PHONY: phony
$1: phony
@if [ "$$$$(cat $1 2>&1)"x != '$($1)'x ]; then \
/bin/echo -n '$($1)' > $1 ; \
fi
endef
#declare PREFIX to be dependable
$(eval $(call DEPENDABLE_VAR,PREFIX))
prefix.h: PREFIX
@echo "// AUTOGENERATED BY makefile; DONT EDIT BY HAND!!!" > prefix.h
@echo '#define PREFIX "$(PREFIX)"' >> prefix.h
@echo "Generated prefix.h"
$(FIND_ORB_EXE): findorb.o $(FIND_ORB_OBJS) $(OBJS) $(RES_FILENAME)
$(CXX) -o $(FIND_ORB_EXE) findorb.o $(FIND_ORB_OBJS) $(OBJS) $(LIBS) $(CURSES_LIB) $(RES_FILENAME) $(LDFLAGS)
findorb.o: findorb.cpp
$(CXX) $(CXXFLAGS) $(CURSES_FLAGS) $<
clipfunc.o: clipfunc.cpp
$(CXX) $(CXXFLAGS) $(CURSES_FLAGS) $<
getstrex.o: getstrex.cpp
$(CXX) $(CXXFLAGS) $(CURSES_FLAGS) $<
$(FO_EXE): fo.o $(OBJS) $(RES_FILENAME)
$(CXX) -o $(FO_EXE) fo.o $(OBJS) $(LIBS) $(RES_FILENAME) $(LDFLAGS)
eph2tle$(EXE): eph2tle.o conv_ele.o elem2tle.o simplex.o lsquare.o
$(CXX) -o eph2tle$(EXE) eph2tle.o conv_ele.o elem2tle.o simplex.o lsquare.o $(LIBS)
cssfield$(EXE): cssfield.o
$(CXX) -o cssfield$(EXE) cssfield.o $(LIBS)
expcalc$(EXE): expcalc.cpp
$(CXX) -o expcalc$(EXE) -Wall -Wextra -pedantic -DTEST_CODE expcalc.cpp
geo_max$(EXE): geo_max.o geo_pot.o
$(CXX) -o geo_max$(EXE) geo_max.o geo_pot.o
geo_test$(EXE): geo_test.o geo_pot.o
$(CXX) -o geo_test$(EXE) geo_test.o geo_pot.o
roottest$(EXE): roottest.o roots.o
$(CXX) -o roottest$(EXE) roottest.o roots.o
neat_xvt$(EXE): neat_xvt.o
$(CXX) -o neat_xvt$(EXE) neat_xvt.o
fo_serve.cgi: fo_serve.o $(OBJS)
$(CXX) -o fo_serve.cgi fo_serve.o $(OBJS) $(LIBS)
cvt_elem.cgi: cvt_elem.o
$(CXX) -o cvt_elem.cgi cvt_elem.o $(LIBS)
cvt_elem.o: conv_ele.cpp
$(CXX) $(CXXFLAGS) -o cvt_elem.o -DCGI_VERSION $<
IDIR=$(PREFIX)/share/findorb/data
ifeq ($(PREFIX),$(DEFAULT_PREFIX))
# backwards compatibility
IDIR=../.find_orb
endif
clean:
$(RM) $(OBJS) fo.o findorb.o fo_serve.o $(FIND_ORB_EXE) $(FO_EXE)
$(RM) fo_serve.cgi eph2tle.o eph2tle$(EXE) cssfield$(EXE)
$(RM) $(FIND_ORB_OBJS) cssfield.o neat_xvt.o neat_xvt$(EXE)
$(RM) prefix.h PREFIX
$(RM) geo_test.o geo_test geo_max.o geo_max
ifdef RES_FILENAME
$(RM) $(RES_FILENAME)
$(RES_FILENAME): find_orb.ico find_orb.rc
$(WINDRES) find_orb.rc -O coff -o $(RES_FILENAME)
endif
clean_temp:
$(RM) $(IDIR)/artsat.json
$(RM) $(IDIR)/bc405pre.txt
$(RM) $(IDIR)/cmt_sof.txt
$(RM) $(IDIR)/combined.json
$(RM) $(IDIR)/covar.txt
$(RM) $(IDIR)/covar.json
$(RM) $(IDIR)/covar?.txt
$(RM) $(IDIR)/covar?.json
$(RM) $(IDIR)/debug.txt
$(RM) $(IDIR)/dummy.txt
$(RM) $(IDIR)/elem_?.json
$(RM) $(IDIR)/eleme?.txt
$(RM) $(IDIR)/eleme?.json
$(RM) $(IDIR)/elements.txt
$(RM) $(IDIR)/elements.json
$(RM) $(IDIR)/elem_short.json
$(RM) $(IDIR)/ephemeri.txt
$(RM) $(IDIR)/ephemeri.json
$(RM) $(IDIR)/gauss.out
$(RM) $(IDIR)/guide.txt
$(RM) $(IDIR)/guide?.txt
$(RM) $(IDIR)/linkage.json
$(RM) $(IDIR)/lock.txt
$(RM) $(IDIR)/monte.txt
$(RM) $(IDIR)/monte?.txt
$(RM) $(IDIR)/mpcorb.dat
$(RM) $(IDIR)/mpc_f?.txt
$(RM) $(IDIR)/mpc_fmt.txt
$(RM) $(IDIR)/mpc_s?.txt
$(RM) $(IDIR)/mpec.htm
$(RM) $(IDIR)/obser?.txt
$(RM) $(IDIR)/observe.txt
$(RM) $(IDIR)/observe.xml
$(RM) $(IDIR)/obs_temp.txt
$(RM) $(IDIR)/residual.txt
$(RM) $(IDIR)/sof.txt
$(RM) $(IDIR)/sof?.txt
$(RM) $(IDIR)/sofv?.txt
$(RM) $(IDIR)/sr_el?.txt
$(RM) $(IDIR)/sr_elems.txt
$(RM) $(IDIR)/state.txt
$(RM) $(IDIR)/state?.txt
$(RM) $(IDIR)/total.json
$(RM) $(IDIR)/total?.json
$(RM) $(IDIR)/vectors.txt
$(RM) $(IDIR)/virtu?.txt
$(RM) $(IDIR)/virtual.txt
INSTALL_FILES= \
bright.pgm bright2.pgm calendar.txt cometdef.sof command.txt cospar.txt \
details.txt dosephem.txt dos_help.txt elem_pop.txt environ.def \
eph2tle.txt eph_expl.txt eph_type.txt ?findorb.txt frame_he.txt \
geo_rect.txt header.htm hints.def jpl_eph.txt link_def.json mpc_area.txt \
mpcorb.hdr mu1.txt nongravs.txt obj_help.txt obj_name.txt \
ObsCodes.htm ObsCodesF.html observer.htm obslinks.htm \
odd_name.txt openfile.txt orbitdef.sof previous.def progcode.txt \
radecfmt.txt residfmt.txt rovers.txt sat_xref.txt scope.json \
scopes.txt splash.txt sigma.txt site_310.txt timehelp.txt xdesig.txt
install: all
$(MKDIR) $(IDIR)
ifdef EXE
$(CP) $(FIND_ORB_EXE) $(IDIR)
$(CP) $(FO_EXE) $(IDIR)
else
$(CP) $(FIND_ORB_EXE) $(INSTALL_DIR)/bin
$(CP) $(FO_EXE) $(INSTALL_DIR)/bin
endif
$(CP) $(INSTALL_FILES) $(IDIR)
uninstall:
ifdef EXE
rm -f $(IDIR)/$(FIND_ORB_EXE)
rm -f $(IDIR)/$(FO_EXE)
else
rm -f $(INSTALL_DIR)/bin/$(FIND_ORB_EXE)
rm -f $(INSTALL_DIR)/bin/$(FO_EXE)
endif
rm -f $(IDIR)/*
rmdir $(IDIR)
DEB_DIR=/tmp/find-orb_1.0-1_amd64
make_deb:
$(MKDIR) $(DEB_DIR)/DEBIAN
$(CP) control postinst $(DEB_DIR)/DEBIAN
chmod 755 $(DEB_DIR)/DEBIAN/postinst
$(MKDIR) $(DEB_DIR)/tmp/exes
$(CP) $(FIND_ORB_EXE) $(DEB_DIR)/tmp/exes
$(CP) $(FO_EXE) $(DEB_DIR)/tmp/exes
$(MKDIR) $(DEB_DIR)/tmp/config_files
$(CP) $(INSTALL_FILES) $(DEB_DIR)/tmp/config_files
dpkg-deb --build $(DEB_DIR)
rm -f $(DEB_DIR)/DEBIAN/*
rm -f $(DEB_DIR)/tmp/config_files/*
rm -f $(DEB_DIR)/tmp/exes/*
rmdir $(DEB_DIR)/DEBIAN
rmdir $(DEB_DIR)/tmp/config_files/
rmdir $(DEB_DIR)/tmp/exes
rmdir $(DEB_DIR)/tmp/
rmdir $(DEB_DIR)
.cpp.o:
$(CXX) $(CXXFLAGS) $<