forked from Expensify/Bedrock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
137 lines (114 loc) · 6.09 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
# Set the compiler, if it's not set by the environment.
ifndef GXX
GXX = g++-9
endif
ifndef CC
CC = gcc-9
endif
GIT_REVISION = $(shell git rev-parse --short HEAD)
PROJECT = $(shell git rev-parse --show-toplevel)
INCLUDE = -I$(PROJECT) -I$(PROJECT)/mbedtls/include
CXXFLAGS = -g -std=c++17 -fpic -O2 $(BEDROCK_OPTIM_COMPILE_FLAG) -Wall -Werror -Wformat-security -DGIT_REVISION=$(GIT_REVISION) $(INCLUDE)
LDFLAGS +=-Wl,-Bsymbolic-functions -Wl,-z,relro
# We'll stick object and dependency files in here so we don't need to look at them.
INTERMEDIATEDIR = .build
# These targets aren't actual files.
.PHONY: all test clustertest clean testplugin
# This sets our default by being the first target, and also sets `all` in case someone types `make all`.
all: bedrock test clustertest
test: test/test
clustertest: test/clustertest/clustertest testplugin
testplugin:
cd test/clustertest/testplugin && $(MAKE)
# Set up our precompiled header. This makes building *way* faster (roughly twice as fast).
# Including it here causes it to be generated.
# Depends on one of our mbedtls files, to make sure the submodule gets pulled and built.
PRECOMPILE_D =libstuff/libstuff.d
PRECOMPILE_INCLUDE =-include libstuff/libstuff.h
libstuff/libstuff.h.gch libstuff/libstuff.d: libstuff/libstuff.h mbedtls/library/libmbedcrypto.a
$(GXX) $(CXXFLAGS) -MD -MF libstuff/libstuff.d -MT libstuff/libstuff.h.gch -c libstuff/libstuff.h
ifneq ($(MAKECMDGOALS),clean)
-include libstuff/libstuff.d
endif
clean:
rm -rf $(INTERMEDIATEDIR)
rm -rf libstuff.a
rm -rf libbedrock.a
rm -rf bedrock
rm -rf test/test
rm -rf test/clustertest/clustertest
rm -rf libstuff/libstuff.d
rm -rf libstuff/libstuff.h.gch
# If we've never run `make`, `mbedtls/Makefile` does not exist. Add a `test
# -f` check and `|| true` so it doesn't cause `make clean` to exit nonzero
(test -f mbedtls/Makefile && cd mbedtls && $(MAKE) clean) || true
cd test/clustertest/testplugin && $(MAKE) clean
# The mbedtls libraries are all built the same way.
mbedtls/library/libmbedcrypto.a mbedtls/library/libmbedtls.a mbedtls/library/libmbedx509.a:
git submodule init
git submodule update
cd mbedtls && git checkout -q 04a049bda1ceca48060b57bc4bcf5203ce591421
cd mbedtls && $(MAKE) no_test && touch library/libmbedcrypto.a && touch library/libmbedtls.a && touch library/libmbedx509.a
# Ok, that's the end of our magic PCH code. The only other mention of it is in the build line where we include it.
# We're going to build a shared library from every CPP file in this directory or it's children.
STUFFCPP = $(shell find libstuff -name '*.cpp')
STUFFC = $(shell find libstuff -name '*.c')
STUFFOBJ = $(STUFFCPP:%.cpp=$(INTERMEDIATEDIR)/%.o) $(STUFFC:%.c=$(INTERMEDIATEDIR)/%.o)
STUFFDEP = $(STUFFCPP:%.cpp=$(INTERMEDIATEDIR)/%.d)
LIBBEDROCKCPP = $(shell find * -name '*.cpp' -not -name main.cpp -not -path 'test*' -not -path 'libstuff*')
LIBBEDROCKOBJ = $(LIBBEDROCKCPP:%.cpp=$(INTERMEDIATEDIR)/%.o)
LIBBEDROCKDEP = $(LIBBEDROCKCPP:%.cpp=$(INTERMEDIATEDIR)/%.d)
BEDROCKCPP = main.cpp
BEDROCKOBJ = $(BEDROCKCPP:%.cpp=$(INTERMEDIATEDIR)/%.o)
BEDROCKDEP = $(BEDROCKCPP:%.cpp=$(INTERMEDIATEDIR)/%.d)
TESTCPP = $(shell find test -name '*.cpp' -not -path 'test/clustertest*')
TESTOBJ = $(TESTCPP:%.cpp=$(INTERMEDIATEDIR)/%.o)
TESTDEP = $(TESTCPP:%.cpp=$(INTERMEDIATEDIR)/%.d)
CLUSTERTESTCPP = $(shell find test -name '*.cpp' -not -path 'test/tests*' -not -path "test/main.cpp")
CLUSTERTESTCPP += test/tests/jobs/JobTestHelper.cpp
CLUSTERTESTOBJ = $(CLUSTERTESTCPP:%.cpp=$(INTERMEDIATEDIR)/%.o)
CLUSTERTESTDEP = $(CLUSTERTESTCPP:%.cpp=$(INTERMEDIATEDIR)/%.d)
# Our static libraries just depend on their object files.
libstuff.a: $(STUFFOBJ)
ar crv $@ $(STUFFOBJ)
libbedrock.a: $(LIBBEDROCKOBJ)
ar crv $@ $(LIBBEDROCKOBJ)
# We use the same library paths and required libraries for both binaries.
LIBPATHS =-Lmbedtls/library -L$(PROJECT)
LIBRARIES =-lbedrock -lstuff -lbedrock -ldl -lpcrecpp -lpthread -lmbedtls -lmbedx509 -lmbedcrypto -lz
# The prerequisites for both binaries are the same. We only include one of the mbedtls libs to avoid building three
# times in parallel.
BINPREREQS = libbedrock.a libstuff.a mbedtls/library/libmbedcrypto.a
# All of our binaries build in the same way.
bedrock: $(BEDROCKOBJ) $(BINPREREQS)
echo $(BEDROCKOBJ)
$(GXX) -o $@ $(BEDROCKOBJ) $(LIBPATHS) -rdynamic $(LIBRARIES)
test/test: $(TESTOBJ) $(BINPREREQS)
$(GXX) -o $@ $(TESTOBJ) $(LIBPATHS) -rdynamic $(LIBRARIES)
test/clustertest/clustertest: $(CLUSTERTESTOBJ) $(BINPREREQS)
$(GXX) -o $@ $(CLUSTERTESTOBJ) $(LIBPATHS) -rdynamic $(LIBRARIES)
# Make dependency files from cpp files, putting them in $INTERMEDIATEDIR.
# This is the same as making the object files, both dependencies and object files are built together. The only
# difference is that here, the fie passed as `-MF` is the target, and the output file is a modified version of that,
# where for the object file rule, the reverse is true.
$(INTERMEDIATEDIR)/%.d: %.cpp $(PRECOMPILE_D)
@mkdir -p $(dir $@)
$(GXX) $(CXXFLAGS) -MD -MF $@ $(PRECOMPILE_INCLUDE) -o $(INTERMEDIATEDIR)/$*.o -c $<
# .o files depend on .d files to prevent simultaneous jobs from trying to create both.
$(INTERMEDIATEDIR)/%.o: %.cpp $(INTERMEDIATEDIR)/%.d
@mkdir -p $(dir $@)
$(GXX) $(CXXFLAGS) -MD -MF $(INTERMEDIATEDIR)/$*.d $(PRECOMPILE_INCLUDE) -o $@ -c $<
# Build c files. This is basically just for sqlite, so we don't bother with dependencies for it.
# SQLITE_MAX_MMAP_SIZE is set to 16TB.
$(INTERMEDIATEDIR)/%.o: %.c
@mkdir -p $(dir $@)
$(CC) -O2 $(BEDROCK_OPTIM_COMPILE_FLAG) -Wno-unused-but-set-variable -DSQLITE_ENABLE_STAT4 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_SESSION -DSQLITE_ENABLE_PREUPDATE_HOOK -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT -DSQLITE_ENABLE_NOOP_UPDATE -DSQLITE_MUTEX_ALERT_MILLISECONDS=20 -DHAVE_USLEEP=1 -DSQLITE_MAX_MMAP_SIZE=17592186044416ull -DSQLITE_SHARED_MAPPING -DSQLITE_ENABLE_NORMALIZE -o $@ -c $<
# Bring in the dependency files. This will cause them to be created if necessary. This is skipped if we're cleaning, as
# they'll just get deleted anyway.
ifneq ($(MAKECMDGOALS),clean)
-include $(STUFFDEP)
-include $(LIBBEDROCKDEP)
-include $(BEDROCKDEP)
#-include $(TESTDEP)
#-include $(CLUSTERTESTDEP)
endif