-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
73 lines (61 loc) · 1.99 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
-include targets.mk # Userdefined Targets.
-include buildflags.mk # Userdefined Build Flags
all: $(target) compile_commands.json
SOURCES != find src -regextype awk -regex '.*\.(c|cc|cpp)'
HEADERS != find include -regextype awk -regex '.*\.(h|hh|hpp)'
OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
DEPENDS := $(addsuffix .d,$(basename $(SOURCES)))
COMPDB := $(addsuffix .compdb,$(SOURCES) $(HEADERS))
PATTERN := %
override LDFLAGS += -L $(realpath .)
override CPPFLAGS += -Iinclude -Isrc
.LIBPATTERNS:=
.PHONY: all clean mostlyclean
.SECONDARY: $(static:%=-l%) $(shared:%=-l%) $(shared) $(static)
.SECONDARY: $(COMPDB) $(OBJECTS)
.DEFAULT_GOAL:=all
# Generate Dependencies
ifeq ($(MAKECMDGOALS),clean)
else ifeq ($(MAKECMDGOALS),mostlyclean)
else
-include $(DEPENDS)
%.d: %.c; @$(CC) $(CPPFLAGS) $< -MM -MT $*.o -MT $@ > $@
%.d: %.cc; @$(CXX) $(CPPFLAGS) $< -MM -MT $*.o -MT $@ > $@
%.d: %.cpp; @$(CXX) $(CPPFLAGS) $< -MM -MT $*.o -MT $@ > $@
endif
# Generate compile_commands.json
-include compdb.mk
compile_commands.json: $(COMPDB)
# Depend on buildflags
$(OBJECTS) $(COMPDB): buildflags.mk
# Build Instructions
.SECONDEXPANSION:
$(target): $$(filter src/$$@/%,$(OBJECTS))
$(LINK.o) $^ $(LDLIBS) -o $@
test: export LD_LIBRARY_PATH=$(CURDIR)
test: $(addprefix test_, $(tested))
test_%: %
./$* $(TEST_FLAGS)
# Shared Library Dependency chain
-l%: lib%.so;
$(shared:%=lib%.so): lib%.so: $$*;
$(shared): override CXXFLAGS += -fPIC
$(shared): $$(filter src/$$@/%,$(OBJECTS))
$(LINK.o) -shared -Wl,-soname,[email protected] $^ $(LDLIBS) -o [email protected]
# Static Library Dependency chain
-l%: lib%.a;
$(static:%=lib%.a) : lib%.a : $$*;
$(static): $$(filter src/$$@/%,$(OBJECTS))
$(AR) $(ARFLAGS) [email protected] $?
# Profiling support.
profile-generate profile-use: % :
@$(MAKE) clean
@$(MAKE) all CXXFLAGS=-f$*
# static analysis
clang-check: $(SOURCES)
@clang-check $^
mostlyclean:
@rm -f $(OBJECTS) $(DEPENDS) $(COMPDB)
clean: mostlyclean
@rm -f compile_commands.json $(target)
@rm -f $(shared:%=lib%.so) $(static:%=lib%.a)