-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
202 lines (170 loc) · 5.95 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
# auto dependency generation logic here is thanks to:
# http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/
DEBUG ?= 0
VERBOSE ?= 0
CURL_OPTS ?=
# NOTE: Change this to increment release version
VERSION := 1.8.0
MKDIR_P := mkdir -p
CURL := curl
OS_NAME := $(shell uname -o | sed -e 's:/:_:g')
IS_WSL := $(shell uname -r | grep -i microsoft)
ifeq ($(IS_WSL),)
REL_NAME := $(OS_NAME)
else
REL_NAME := WSL
endif
GIT_COMMIT := $(shell git rev-parse --short HEAD)
DIRTY := $(shell git status -s)
ifneq ($(DIRTY),)
DIRTY := -dirty
else
DIRTY :=
endif
ifeq ($(DEBUG),1)
TYPE := Debug
else
TYPE := Release
endif
ifeq ($(VERBOSE),1)
PREFIX :=
CURL_QUIET :=
else
PREFIX := @
CURL_QUIET := -s
endif
BUILD_VERSION := $(VERSION)@@$(GIT_COMMIT)$(DIRTY)
RELEASE_ROOT := teditor-$(VERSION)
RELEASE_DIR := $(RELEASE_ROOT)/$(REL_NAME)
BINROOT := bin/$(REL_NAME)
BINDIR := $(BINROOT)/$(TYPE)
DEPDIR := $(BINDIR)/deps
EXE := $(BINDIR)/teditor
TESTEXE := $(BINDIR)/teditor-tests
ifeq ($(OS_NAME),Cygwin)
STDCXX := gnu++14
else
STDCXX := c++14
endif
SRC := src
TESTS := unittests
MAIN := main
CATCH2_DIR := $(BINROOT)/Catch2
CATCH2_HEADER := https://raw.githubusercontent.com/catchorg/Catch2/v2.x/single_include/catch2/catch.hpp
INCLUDES := $(SRC) \
$(TESTS) \
$(CATCH2_DIR)
LIBS :=
INCS := $(foreach inc,$(INCLUDES),-I$(inc))
CXX := g++
CXXFLAGS := -std=$(STDCXX) -Wall -Werror $(INCS) -Wno-error=unused-function
LD := g++
LDFLAGS :=
ifeq ($(OS_NAME),GNU_Linux)
LIBS += -L/usr/lib64 -lpthread
CXXFLAGS += -Wno-unused-function
endif
CPPSRC := $(shell find $(SRC) -name "*.cpp")
CORE_OBJS := $(patsubst %.cpp,$(BINDIR)/%.o,$(CPPSRC))
TESTSRC := $(shell find $(TESTS) -name "*.cpp")
TEST_OBJS := $(patsubst %.cpp,$(BINDIR)/%.o,$(TESTSRC))
MAINSRC := $(shell find $(MAIN) -name "*.cpp")
MAIN_OBJS := $(patsubst %.cpp,$(BINDIR)/%.o,$(MAINSRC))
SRC_DEPS := $(patsubst %.cpp,$(DEPDIR)/%.d,$(CPPSRC))
TEST_DEPS := $(patsubst %.cpp,$(DEPDIR)/%.d,$(TESTSRC))
MAIN_DEPS := $(patsubst %.cpp,$(DEPDIR)/%.d,$(MAINSRC))
DEPFILES := $(SRC_DEPS) $(TEST_DEPS) $(MAIN_DEPS)
ifeq ($(DEBUG),1)
CXXFLAGS += -g -DDEBUG_BUILD
LDFLAGS += -g
else
CXXFLAGS += -O3 -UDEBUG_BUILD
LDFLAGS += -O3
endif
CXXFLAGS += -DTEDITOR_VERSION_INFO='"$(BUILD_VERSION)"'
default:
@echo "make what? Available targets are:"
@echo " doc - Build doxygen documentation"
@echo " clean - Clean the build files"
@echo " clean_all - Clean even the build files"
@echo " release - Prepare release package"
@echo " package - After preparing release packages for all"
@echo " supported platforms, tarball this folder."
@echo " stats - Source code statistics"
@echo " teditor - Build the editor"
@echo " tests - Build the unit-tests and run them"
@echo "Flags to customize behavior:"
@echo " DEBUG - Get a debug build if it is 1. Also enables debug"
@echo " logging in Logger class. [$(DEBUG)]"
@echo " VERBOSE - Print the actual commands. [$(VERBOSE)]"
@echo " BINROOT - Root directory where to store build files. [$(BINROOT)]"
@echo " CUSTOM_LEDGER_FILE - Path to a ledger file which can be passed"
@echo " to unit-tests to parse in order to verify"
@echo " its correctness. A quick-n-dirty way to"
@echo " debug your ledger file when it causes issues"
@echo " with the editor! [$(CUSTOM_LEDGER_FILE)]"
release:
$(MKDIR_P) $(RELEASE_DIR)
$(MAKE) clean_all
$(MAKE) -j teditor tests
$(MKDIR_P) $(RELEASE_DIR)/Release
cp $(BINROOT)/Release/teditor $(RELEASE_DIR)/Release
$(MAKE) -j DEBUG=1 teditor tests
$(MKDIR_P) $(RELEASE_DIR)/Debug
cp $(BINROOT)/Debug/teditor $(RELEASE_DIR)/Debug
package:
$(MAKE) doc
rm -rf $(RELEASE_ROOT)/html
cp -r $(BINROOT)/html $(RELEASE_ROOT)
tar cjf $(RELEASE_ROOT).tar.gz $(RELEASE_ROOT)
teditor: $(EXE)
$(EXE): $(MAIN_OBJS) $(CORE_OBJS)
@if [ "$(VERBOSE)" = "0" ]; then \
echo "Building $@ ..."; \
fi
$(PREFIX)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
tests: $(TESTEXE)
$(TESTEXE)
$(TEST_OBJS): $(CATCH2_DIR)
$(TESTEXE): $(CORE_OBJS) $(TEST_OBJS)
@if [ "$(VERBOSE)" = "0" ]; then \
echo "Building $@ ..."; \
fi
$(PREFIX)$(LD) $(LDFLAGS) -o $@ $^ $(LIBS)
$(BINDIR)/%.o: %.cpp $(DEPDIR)/%.d
@if [ "$(VERBOSE)" = "0" ]; then \
echo "Compiling CXX $< ..."; \
fi
$(PREFIX)$(MKDIR_P) $(shell dirname $@)
$(PREFIX)$(MKDIR_P) $(shell dirname $(DEPDIR)/$*d)
$(PREFIX)$(CXX) -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td $(CXXFLAGS) -c -o $@ $<
$(PREFIX)mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d && touch $@
clean:
rm -rf $(CORE_OBJS) $(MAIN_OBJS) $(EXE)
rm -rf $(TEST_OBJS) $(TESTEXE)
rm -rf $(DEPFILES)
clean_all:
rm -rf $(BINROOT)
stats:
@echo -n "CORE: Line/Word/Char counts: "
@find $(MAIN) $(SRC)/core -name "*.cpp" -o -name "*.h" | xargs wc -lwc | tail -n1
@echo -n "EXT: Line/Word/Char counts: "
@find $(SRC)/extensions -name "*.cpp" -o -name "*.h" | xargs wc -lwc | tail -n1
@echo -n "TESTS: Line/Word/Char counts: "
@find $(TESTS) -name "*.cpp" -o -name "*.h" | xargs wc -lwc | tail -n1
doc:
rm -rf $(BINROOT)/html
$(MKDIR_P) $(BINDIR)
sed -e "s/PROJECT_NUMBER =/PROJECT_NUMBER = $(BUILD_VERSION)/" \
-e "s:OUTPUT_DIRECTORY =:OUTPUT_DIRECTORY = $(BINROOT):" \
< Doxyfile > $(BINROOT)/Doxyfile
doxygen -v
doxygen $(BINROOT)/Doxyfile
$(CATCH2_DIR):
@if [ "$(VERBOSE)" = "0" ]; then \
echo "Downloading $@ ..."; \
fi
$(PREFIX)$(MKDIR_P) $@
$(PREFIX)$(CURL) $(CURL_QUIET) $(CURL_OPTS) -o $@/catch.hpp $(CATCH2_HEADER)
$(DEPFILES):
include $(wildcard $(DEPFILES))