-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
149 lines (115 loc) · 3.66 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
.PHONY: all build-external curl pugixml sqlite remake directories clean cleaner cleandb
# File Extensions
SRCEXT := cpp
OBJEXT := o
TARGETEXT :=
# Paths
SRCPATH := src
EXTPATH := external
BUILDPATH := build
TARGETPATH := bin
# Compiler
CXX := g++
CXXFLAGS := -std=c++17 -g -O2 #-Wall
INCFLAGS := -I include
# Includes
INCFLAGS += -I ${EXTPATH}/curl/include \
-I ${EXTPATH}/nlohmann/single_include \
-I ${EXTPATH}/pugixml/src \
-I ${BUILDPATH}/sqlite
# Build and Link Externals
EXTBUILDS :=
OPENSSLFLAG :=
PUGIXMLSRC := ${EXTPATH}/pugixml/src/pugixml.cpp
PUGIXMLOBJ := ${BUILDPATH}/pugixml.${OBJEXT}
DEPOBJECTS := ${PUGIXMLOBJ}
LDFLAGS := -L ${BUILDPATH}/curl/lib/.libs -l curl
LDFLAGS += -L ${BUILDPATH}/sqlite/.libs -l sqlite3
# Build (Project Sources and Objects)
SOURCES := $(wildcard $(SRCPATH)/*.${SRCEXT})
OBJECTS := $(patsubst ${SRCPATH}/%.${SRCEXT},${BUILDPATH}/%.${OBJEXT},${SOURCES})
# Adjust Variables depending on Environment
ifeq ($(filter ${shell uname}, Linux), Linux) #Linux
TARGETEXT :=
OPENSSLFLAG := --with-openssl
else ($(filter ${shell uname}, Darwin), Darwin) #macOS
TARGETEXT :=
OPENSSLFLAG := --with-openssl=/opt/homebrew/opt/openssl
else #Windows
TARGETEXT := .exe
OPENSSLFLAG := --with-openssl
endif
# Target
TARGET := ${TARGETPATH}/subway-logger${TARGETEXT}
# =============================================================================
all: directories build-external ${TARGET}
${TARGET}: ${OBJECTS} ${DEPOBJECTS}
@echo building ${TARGET}...
@echo
@${CXX} ${CXXFLAGS} ${INCFLAGS} $^ ${LDFLAGS} -o $@ ||:
${OBJECTS}: ${BUILDPATH}/%.${OBJEXT}: ${SRCPATH}/%.${SRCEXT}
@echo building $<...
@echo
@${CXX} -c ${CXXFLAGS} ${INCFLAGS} $< -o $@ ||:
# nlohmann's json does not need to be compiled individually
# =============================================================================
# Find Which Libraries Need to Be Built
ifeq ($(wildcard ${BUILDPATH}/curl/lib/.libs/libcurl.a),)
EXTBUILDS += curl
endif
ifeq ($(wildcard ${BUILDPATH}/pugixml.${OBJEXT}),)
EXTBUILDS += pugixml
endif
ifeq ($(wildcard ${BUILDPATH}/sqlite/sqlite3.h),)
EXTBUILDS += sqlite
endif
build-external: directories ${EXTBUILDS}
curl:
@echo building curl...
@echo
@cd ${EXTPATH}/curl ||:; \
autoreconf -fi ||:; \
cd ../.. ||:; \
mkdir ${BUILDPATH}/curl ||:; \
cd ${BUILDPATH}/curl ||:; \
../../${EXTPATH}/curl/configure ${OPENSSLFLAG} ||:; \
make ||:;
pugixml: ${PUGIXMLSRC}
@echo building pugixml...
@echo
@${CXX} -c ${CXXFLAGS} ${INCFLAGS} $< -o ${PUGIXMLOBJ} ||:
sqlite:
@echo building sqlite...
@echo step1
@mkdir ${BUILDPATH}/sqlite ||:; \
echo step2 ||:; \
cd ${BUILDPATH}/sqlite ||:; \
echo step3 ||:; \
../../${EXTPATH}/sqlite/configure ||:; \
echo step4 ||:; \
make ||:; \
echo step5 ||:; \
make sqlite3.c ||:;
# =============================================================================
remake: cleaner all
directories:
@mkdir ${BUILDPATH} ||:
@mkdir ${TARGETPATH} ||:
clean:
-rm -rf ${BUILDPATH}
@echo cleaning curl...
@cd ${EXTPATH}/curl ||:; \
git clean -fdx ||:; \
cleaner: clean
-rm -rf ${TARGETPATH}
cleandb:
-rm -f nyc-subway-tracker.db
# =============================================================================
# Unused
# =============================================================================
ROUTES_TARGET := routes_fix.exe
routes_fix: ${ROUTES_TARGET}
${ROUTES_TARGET}: routes_fix.o
${CXX} ${CXXFLAGS} $< -o src/misc/$@
routes_fix.o: src/misc/routes_fix.cpp
${CXX} ${CXXFLAGS} -c $< -o $@