-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGNUmakefile
102 lines (78 loc) · 2.36 KB
/
GNUmakefile
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
# -*- coding:utf-8-unix -*-
.PHONY: all build clean depend cov gcov lib test
all: build lib
depend:
include .project.mk
DEFAULT_CFLAGS ?=
DEFAULT_CFLAGS += -MMD
DEFAULT_CFLAGS += -pedantic-errors -Wall -Wpedantic -Wextra
DEFAULT_CFLAGS += -Winit-self -Wno-missing-field-initializers
CFLAGS ?=
CFLAGS += $(DEFAULT_CFLAGS)
CXXFLAGS ?=
CXXFLAGS += $(DEFAULT_CFLAGS)
TESTFLAGS ?=
SRCDIR ?= src
OBJDIR ?= obj
SRCS = $(shell find $(SRCDIR) -type f \
-name '*.c' -o \
-name '*.cpp' -o \
-name '*.cxx')
OBJS = $(patsubst $(SRCDIR)/%.c, $(OBJDIR)/%.o, \
$(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, \
$(patsubst $(SRCDIR)/%.cxx, $(OBJDIR)/%.o, \
$(SRCS))))
DEPS = $(patsubst %.o, %.d, $(OBJS))
COVS = $(patsubst %.o, %.gcda, $(OBJS)) $(patsubst %.o, %.gcno, $(OBJS))
LIBOBJS = $(filter-out %/main.o, $(OBJS))
ifdef TARGET
TEST_COMMAND ?= ./$(TARGET) $(TESTFLAGS)
endif
build: $(TARGET)
lib: $(LIBTARGET)
test: build
$(info [TEST] $(TEST_COMMAND))
@$(TEST_COMMAND)
clean:
@rm -f $(TARGET) $(TARGET).exe $(LIBTARGET) $(OBJS) $(DEPS) $(COVS) *~
@rm -f *.gcov $(OBJDIR)/*.gcov
@rm -rf $(OBJDIR)
@rm -df bin lib
# `make cov`: build and test for coverage test
# To make coverage report:
# 1. do `make cov` for ALL (sub)project, then
# 2. do `gcov [options] -o obj src/*` for each (sub)project,
# or do `bash <(curl -s https://codecov.io/bash)`
cov: CFLAGS += -coverage
cov: CXXFLAGS += -coverage
cov: LDFLAGS += -coverage
cov: all test
# 'make gcov': generates coverage report
gcov:
$(foreach d, $(sort $(dir $(SRCS))), \
gcov -abcpu \
-o $(patsubst $(SRCDIR)/%, $(OBJDIR)/%, $(d)) \
$(wildcard $(d)*.c $(d)*.cpp $(d)*.cxx) ;)
$(TARGET):: depend
$(TARGET):: $(OBJS)
$(info [LD] Build : $@ [$(notdir $(CURDIR))])
@mkdir -p $(dir $@)
@$(CXX) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LDLIBS)
$(LIBTARGET):: depend
$(LIBTARGET):: $(LIBOBJS)
$(info [AR] Build : $@ [$(notdir $(CURDIR))])
@mkdir -p $(dir $@)
@$(AR) cr $@ $^
$(OBJDIR)/%.o: $(SRCDIR)/%.c
$(info [C] Compile : $@ ($<))
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) -c -o $@ $<
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
$(info [C++] Compile : $@ ($<))
@mkdir -p $(dir $@)
@$(CXX) $(CXXFLAGS) -c -o $@ $<
$(OBJDIR)/%.o: $(SRCDIR)/%.cxx
$(info [C++] Compile : $@ ($<))
@mkdir -p $(dir $@)
@$(CXX) $(CXXFLAGS) -c -o $@ $<
-include $(DEPS)