-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
72 lines (56 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
72
LIBNAME := libtyra.a
LIBDIR := lib
TBINDIR := bin/test
TESTDIR := test
SRCDIR := src
INCDIR := inc
OBJDIR := .objs
DEPDIR := .deps
SRCS := $(notdir $(wildcard $(SRCDIR)/*.cpp)) # All the source files
OBJS := $(SRCS:%.cpp=$(OBJDIR)/%.o) # All the object files
TSRCS := $(notdir $(wildcard $(TESTDIR)/test_*.cpp))
TBINS := $(TSRCS:%.cpp=$(TBINDIR)/%)
$(shell mkdir -p $(DEPDIR) >/dev/null)
CXXFLAGS = -std=c++14 -I $(INCDIR) -I . -fdiagnostics-color=always
CXXFLAGS += -Wall -Wextra -Wpedantic -Weffc++
CXXFLAGS += -Wfatal-errors -Wwrite-strings -Wno-parentheses -Warray-bounds -Wconversion -Wshadow
RELFLAGS := -O3
DBGFLAGS := -g
DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td
COMPILE = $(CXX) $(DEPFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(CXXFLAGS2) $(TARGET_ARCH)
POSTCOMPILE = @mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d && touch $@
all: debug;
test: $(TBINS)
test_%: $(TBINDIR)/test_%;
$(TBINDIR)/%: debug
$(TBINDIR)/%: CXXFLAGS+=$(DBGFLAGS)
$(TBINDIR)/%: $(OBJS) $(OBJDIR)/main.o $(OBJDIR)/%.o
@mkdir -p $(@D)
$(COMPILE) $(OUTPUT_OPTION) $^
$(OBJDIR)/%.o: CXXFLAGS+=$(DBGFLAGS)
$(OBJDIR)/%.o: $(TESTDIR)/%.cpp
@mkdir -p $(@D)
$(COMPILE) $(OUTPUT_OPTION) -c $<
$(POSTCOMPILE)
debug: CXXFLAGS+=$(DBGFLAGS)
debug: $(LIBDIR)/$(LIBNAME)
release: CXXFLAGS+=$(RELFLAGS)
release: $(LIBDIR)/$(LIBNAME)
$(LIBDIR)/$(LIBNAME): $(OBJS)
@mkdir -p $(@D)
ar rsvc $(LIBDIR)/$(LIBNAME) $^
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp $(DEPDIR)/%.d
@mkdir -p $(@D)
$(COMPILE) $(OUTPUT_OPTION) -c $<
$(POSTCOMPILE)
$(DEPDIR)/%.d: ;
.PRECIOUS: $(DEPDIR)/%.d
.PRECIOUS: $(OBJDIR)/%.o
include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS))))
.PHONY: clean
clean:
@rm -rf $(TBINDIR)
@rm -rf $(LIBDIR)
@rm -rf $(OBJDIR)
@rm -rf $(DEPDIR)