-
Notifications
You must be signed in to change notification settings - Fork 1
/
makefile
164 lines (119 loc) · 3.44 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
# project targets
all: atone
atone: build
build: before-build 3rd-party build-core after-build
rebuild: clean build
FORCE: ;
.PHONY: clean build rebuild atone 3rd-party
# project configuration
PRECOMPILE+=src/atone.h
LIBRARY+=rt
LIBRARY+=cron
LIBRARY+=optparse
LIBRARY+=yaml-cpp
LIBRARY_PATH+=3rd-party/cron/$(BUILDDIR)/$(TARGET)/bin
LIBRARY_PATH+=3rd-party/optparse/$(BUILDDIR)/$(TARGET)/bin
LIBRARY_PATH+=3rd-party/yaml-cpp/$(BUILDDIR)/$(TARGET)/bin
INCLUDE_PATH+=$(SRCDIR)
INCLUDE_PATH+=3rd-party/cron/include
INCLUDE_PATH+=3rd-party/optparse/include
INCLUDE_PATH+=3rd-party/yaml-cpp/include
CXXFLAGS+=-Wall
CXXFLAGS+=-fdiagnostics-color=always
CXXFLAGS+=-std=c++17
CXXFLAGS+=-MMD
#-----------------------------------------------------------------------
# default directories
SRCDIR?=src
BUILDDIR?=build
TARGETDIR?=$(BUILDDIR)/$(TARGET)
OUTDIR?=$(TARGETDIR)/bin
OBJDIR?=$(TARGETDIR)/obj
PCHDIR?=$(TARGETDIR)/pch
#cleanup
CLEAN+=$(OUTDIR)
CLEAN+=$(OBJDIR)
CLEAN+=$(PCHDIR)
# input parameters
DEBUG?=0
VERBOSE?=0
ifneq ($(DEBUG), 0)
TARGET=debug
CXXFLAGS+=-g
CXXFLAGS+=-Og
else
TARGET=release
CXXFLAGS+=-Os -ffunction-sections -fdata-sections
LDFLAGS+=-Wl,--gc-sections -s
endif
ifneq ($(VERBOSE), 0)
CXXFLAGS+=-v
endif
ifdef ATONE_BUILD_VERSION
CXXFLAGS+=-D "ATONE_BUILD_VERSION=\"$(ATONE_BUILD_VERSION)\""
endif
ifdef ATONE_BUILD_NUMBER
CXXFLAGS+=-D "ATONE_BUILD_NUMBER=\"$(ATONE_BUILD_NUMBER)\""
endif
ifdef ATONE_DEVELOPMENT_MODE
CXXFLAGS+=-D "ATONE_DEVELOPMENT_MODE=\"$(ATONE_DEVELOPMENT_MODE)\""
endif
# artifacts
SOURCES=$(shell find "$(SRCDIR)" -name *.cpp)
OBJECTS=$(SOURCES:%.cpp=$(OBJDIR)/%.o)
PCHS=$(PRECOMPILE:%=$(PCHDIR)/%.gch)
# expand variables
CXXFLAGS+=$(foreach d, $(INCLUDE_PATH), -I$d)
LDFLAGS+=$(foreach d, $(LIBRARY_PATH), -L$d)
LDLIBS+=$(foreach d, $(LIBRARY), -l$d)
PCHINCS+=$(foreach d, $(PCHDIR)/$(PRECOMPILE), -include $d)
PCHFLAGS+=$(CXXFLAGS) -x c++-header
# internal targets
# BUILD
before-build:
@echo "Building..."
@echo " Target: $(TARGET)"
@echo " Output directory: $(OUTDIR)"
@-mkdir -p $(OUTDIR) $(dir $(OBJECTS)) $(dir $(PCHDIR)/$(PRECOMPILE))
build-core: $(PCHS) $(OUTDIR)/atone
$(OUTDIR)/atone: $(OBJECTS) 3rd-party
@echo " Linking $@"
@$(CXX) $(LDFLAGS) -o $(OUTDIR)/atone $(OBJECTS) $(LDLIBS)
$(OBJECTS): $(OBJDIR)/%.o: %.cpp
@echo " Compiling $<"
@$(CXX) $(PCHINCS) $(CXXFLAGS) -o $@ -c $<
$(PCHS): $(PCHDIR)/%.gch: %
@echo " Precompiling $<"
@$(CXX) $(PCHFLAGS) -c $< -o $(PCHDIR)/$<.gch
after-build:
@echo "Build completed"
# 3rd-party
3rd-party: \
3rd-party/cron/$(BUILDDIR)/$(TARGET)/bin/libcron.a \
3rd-party/optparse/$(BUILDDIR)/$(TARGET)/bin/liboptparse.a \
3rd-party/yaml-cpp/$(BUILDDIR)/$(TARGET)/bin/libyaml-cpp.a
3rd-party/cron/$(BUILDDIR)/$(TARGET)/bin/libcron.a: FORCE
@echo "Building libcron"
@$(MAKE) -C 3rd-party/cron
3rd-party/optparse/$(BUILDDIR)/$(TARGET)/bin/liboptparse.a: FORCE
@echo "Building optparse"
@$(MAKE) -C 3rd-party/optparse
3rd-party/yaml-cpp/$(BUILDDIR)/$(TARGET)/bin/libyaml-cpp.a: FORCE
@echo "Building yaml-cpp"
@$(MAKE) -C 3rd-party/yaml-cpp
# CLEAN
clean:
@-rm -rv -- $(CLEAN) || true
clean-all:
@-rm -rv -- $(BUILDDIR) || true
@$(MAKE) -C 3rd-party/cron clean-all
@$(MAKE) -C 3rd-party/optparse clean-all
@$(MAKE) -C 3rd-party/yaml-cpp clean-all
$(TARGETDIR)/.marker: makefile
@-mkdir -p $(TARGETDIR)
@touch $@
$(MAKE) clean
# includes
-include $(OBJECTS:.o=.d)
-include $(PCHS:.gch=.d)
-include $(TARGETDIR)/.marker