-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
81 lines (61 loc) · 2 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
OS := ($(shell uname))
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)
ifeq ($(OS),Darwin)
BCXXFLAGS = -I$(SRCDIR) -I$(TESTDIR) -O3 -std=c++1z -stdlib=libstdc++
BLINKERFLAGS = -stdlib=libstdc++
CXXFLAGS = -D __apple__
else
BCXXFLAGS = -I$(SRCDIR) -I$(TESTDIR) -O3 -std=c++1z -fPIC
endif
all: CXXFLAGS += $(BCXXFLAGS) -D __main__
test: CXXFLAGS += $(BCXXFLAGS) -D __test__
graphics: CXXFLAGS += $(BCXXFLAGS) -D __main__ -D __graphics__ -I/usr/X11/include -I/usr/local/include
graphics: LINKERFLAGS += -L/usr/local/lib64 -lGG -lGL -lGLU -lXt -lX11 -lXext
.PHONY: all test clean graphics
all: $(BINDIR)/$(MAINEXEC)
graphics: $(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) -o $(BINDIR)/$(MAINEXEC) $(SOBJS) $(BLINKERFLAGS) $(LINKERFLAGS)
ifeq "$(MAKECMDGOALS)" ""
-include $(SDEPS)
-include $(TDEPS)
endif