-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
71 lines (52 loc) · 1.73 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
SRCDIR := src
TESTDIR := test
OBJDIR := obj
DEPDIR := dep
BINDIR := bin
SOBJDIR := obj/src
SDEPDIR := dep/src
TOBJDIR := obj/test
TDEPDIR := dep/test
TESTEXEC := test.out
MAINEXEC := main.out
SRCS := $(shell find $(SRCDIR) -name "*.cpp")
SOBJS := $(SRCS:$(SRCDIR)/%.cpp=$(SOBJDIR)/%.o)
SDEPS := $(SRCS:$(SRCDIR)/%.cpp=$(SDEPDIR)/%.d)
STREE := $(patsubst %/,%,$(dir $(SOBJS)))
TESTS := $(shell find $(TESTDIR) -name "*.cpp")
TOBJS := $(TESTS:$(TESTDIR)/%.cpp=$(TOBJDIR)/%.o)
TDEPS := $(TESTS:$(TESTDIR)/%.cpp=$(TDEPDIR)/%.d)
TTREE := $(patsubst %/,%,$(dir $(TOBJS)))
SCPPFLAGS = -MMD -MP -MF $(@:$(SOBJDIR)/%.o=$(SDEPDIR)/%.d)
TCPPFLAGS = -MMD -MP -MF $(@:$(TOBJDIR)/%.o=$(TDEPDIR)/%.d)
BCXXFLAGS = -I$(SRCDIR) -I$(TESTDIR) `pkg-config --cflags libsodium` -O0 -g -std=c++2a -fcoroutines-ts -stdlib=libc++
BLINKERFLAGS = `pkg-config --libs libsodium` -stdlib=libc++ -lc++abi -pthread
all: CXXFLAGS = $(BCXXFLAGS) -D __main__
test: CXXFLAGS = $(BCXXFLAGS) -D __test__
.PHONY: all test clean
all: $(BINDIR)/$(MAINEXEC)
test: $(BINDIR)/$(TESTEXEC)
$(BINDIR)/$(TESTEXEC)
clean:
$(RM) -r $(OBJDIR) $(DEPDIR) $(BINDIR)
.SECONDEXPANSION:
$(SOBJDIR)/%.o: $(SRCDIR)/%.cpp | $$(@D)
$(CXX) $(SCPPFLAGS) $(CXXFLAGS) -o $@ -c $<
$(TOBJDIR)/%.o: $(TESTDIR)/%.cpp | $$(@D)
$(CXX) $(TCPPFLAGS) $(CXXFLAGS) -o $@ -c $<
$(BINDIR):
mkdir -p $(BINDIR)
$(STREE): %:
mkdir -p $@
mkdir -p $(@:$(SOBJDIR)%=$(SDEPDIR)%)
$(TTREE): %:
mkdir -p $@
mkdir -p $(@:$(TOBJDIR)%=$(TDEPDIR)%)
$(BINDIR)/$(TESTEXEC): $(SOBJS) $(TOBJS) $(BINDIR)
$(CXX) -o $(BINDIR)/$(TESTEXEC) $(SOBJS) $(TOBJS)
$(BINDIR)/$(MAINEXEC): $(SOBJS) $(BINDIR)
$(CXX) $(BLINKERFLAGS) $(LINKERFLAGS) -o $(BINDIR)/$(MAINEXEC) $(SOBJS)
ifeq "$(MAKECMDGOALS)" ""
-include $(SDEPS)
-include $(TDEPS)
endif