-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile.default
98 lines (71 loc) · 2.33 KB
/
Makefile.default
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
## Common Makefile rules
### defaults and output ########################################################
CHECK ?= sparse
ifneq ($(V),1)
Q := @
NULL := 2>/dev/null
endif
### build dir ##################################################################
BUILD_DIR ?= build
VERSION := $(shell git describe --tags --dirty=+ 2>/dev/null)
# function for removing duplicates in a list
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
OBJS = $(addprefix $(BUILD_DIR)/, $(SRC:.c=.o))
OBJ_DIRS := $(call remduplicates, $(dir $(OBJS)))
### common flags ###############################################################
DEFS += -DVERSION=\"$(VERSION)\"
CPPFLAGS += -MD
CFLAGS += $(INCLUDES)
CPPFLAGS += $(DEFS)
ifeq ($(DEBUG),1)
CFLAGS += -DDEBUG=1
endif
### targets ####################################################################
.PHONY: force
# common targets
bin: $(BUILD_DIR)/$(NAME)
lib-static: $(BUILD_DIR)/$(NAME).a
lib-dynamic: $(BUILD_DIR)/$(NAME).so
dir: $(OBJ_DIRS)
@printf " DIR $(BUILD_DIR)\n"
$(OBJ_DIRS):
$(Q)mkdir -p $@
# binary
$(BUILD_DIR)/$(NAME): $(OBJS)
@printf " LD $@\n"
$(Q)$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
# static library
$(BUILD_DIR)/$(NAME).a: $(OBJS)
@printf " AR $@\n"
$(Q)$(AR) rcs $@ $(OBJS)
# dynamic library
$(BUILD_DIR)/$(NAME).so: $(OBJS)
@printf " LD $@\n"
$(Q)$(CC) $(LDFLAGS) -shared -Wl,-soname,$@.1 -o $@ $(OBJS) $(LIBS)
$(Q)-ln -sfn $(NAME).so $@.1
$(BUILD_DIR)/%.o: %.c
@printf " CC $(*).c\n"
$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) $(ARCH_FLAGS) -o $(BUILD_DIR)/$(*).o -c $(*).c
$(BUILD_DIR)/%.o: %.cpp
@printf " CXX $(*).cpp\n"
$(Q)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(ARCH_FLAGS) -o $(BUILD_DIR)/$(*).o -c $(*).cpp
# build flags
$(BUILD_DIR)/buildflags: force
@#@printf " FLAGS\n"
$(Q)mkdir -p $(BUILD_DIR)
$(Q)echo '$(CFLAGS) $(CPPFLAGS)' | cmp -s - $@ || echo '$(CFLAGS) $(CPPFLAGS)' > $@
$(OBJS): dir $(BUILD_DIR)/buildflags
check: $(filter-out libs%,$(SRC))
@printf " CHECK $^\n"
$(Q)$(CHECK) $(CFLAGS) $(CPPFLAGS) $(CHECK_FLAGS) $^
clean: $(EXTRA_CLEAN)
@printf " CLEAN\n"
$(Q)-rm -f $(OBJS) $(OBJS:.o=.d) *~
$(Q)-rm -f $(NAME) $(NAME).a $(NAME).so*
$(Q)-rm -f .objdeps.mk
ifneq (.,$(BUILD_DIR))
ifneq (..,$(BUILD_DIR))
$(Q)$(RM) -r $(BUILD_DIR)
endif
endif
-include $(OBJS:.o=.d)