-
Notifications
You must be signed in to change notification settings - Fork 2
/
common.mk
122 lines (94 loc) · 4.08 KB
/
common.mk
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Get the current OS and architecture
OS ?= $(shell uname -s)
CPU ?= $(shell uname -m)
PLATFORM ?= $(OS).$(CPU)
# Set the default compilers and flags
CC = clang
CXX = clang++
CFLAGS ?=
CXXFLAGS ?= $(CFLAGS)
LINKFLAGS ?=
include $(ROOT)/platforms/$(PLATFORM).mk
# Set the default shared library filename suffix
SHLIB_SUFFIX ?= so
# Don't build into subdirectories by default
DIRS ?=
# Don't require any libraries by default
LIBS ?=
# Set the default include directories
INCLUDE_DIRS += $(ROOT)/include
# Recurse into subdirectories for the 'clean' and 'build' targets
RECURSIVE_TARGETS ?= clean build
# Build by default
all: debug
# Just remove the targets
clean::
ifneq ($(TARGETS),)
@rm -f $(TARGETS)
endif
# Set the default source and include files with wildcards
SRCS ?= $(wildcard *.c) $(wildcard *.cpp) $(wildcard *.cc) $(wildcard *.C)
OBJS ?= $(addprefix obj/, $(patsubst %.c, %.o, $(patsubst %.cpp, %.o, $(patsubst %.cc, %.o, $(patsubst %.C, %.o, $(SRCS))))))
INCLUDES ?= $(wildcard *.h) $(wildcard *.hpp) $(wildcard *.hh) $(wildcard *.H) $(wildcard $(addsuffix /*.h, $(INCLUDE_DIRS))) $(wildcard $(addsuffix /*.hpp, $(INCLUDE_DIRS))) $(wildcard $(addsuffix /*.hh, $(INCLUDE_DIRS))) $(wildcard $(addsuffix /*.H, $(INCLUDE_DIRS)))
# Clean up objects
clean::
ifneq ($(OBJS),)
@rm -f $(OBJS)
endif
INDENT +=" "
export INDENT
# Generate flags to link required libraries and get includes
LIBFLAGS = $(addprefix -l, $(LIBS))
INCFLAGS = $(addprefix -I, $(INCLUDE_DIRS))
SHARED_LIB_TARGETS = $(filter %.$(SHLIB_SUFFIX), $(TARGETS))
STATIC_LIB_TARGETS = $(filter %.a, $(TARGETS))
OTHER_TARGETS = $(filter-out %.$(SHLIB_SUFFIX), $(filter-out %.a, $(TARGETS)))
release: DEBUG=
release: $(ROOT)/.release build
debug: DEBUG=1
debug: $(ROOT)/.debug build
$(ROOT)/.release:
@echo $(INDENT)[build] Cleaning up after Debug build
@$(MAKE) -C $(ROOT) clean > /dev/null
@rm -f $(ROOT)/.debug
@touch $(ROOT)/.release
$(ROOT)/.debug:
@echo $(INDENT)[build] Cleaning up after Release build
@$(MAKE) -C $(ROOT) clean > /dev/null
@rm -f $(ROOT)/.release
@touch $(ROOT)/.debug
build:: $(TARGETS) $(INCLUDE_DIRS)
obj/%.o:: %.c Makefile $(ROOT)/common.mk $(INCLUDE_DIRS) $(INCLUDES)
@mkdir -p obj
@echo $(INDENT)[$(notdir $(firstword $(CC)))] Compiling $< for $(if $(DEBUG),Debug,Release) build
@$(CC) $(CFLAGS) $(if $(DEBUG),-g,-DNDEBUG) $(INCFLAGS) -c $< -o $@
obj/%.o:: %.cpp Makefile $(ROOT)/common.mk $(INCLUDE_DIRS) $(INCLUDES)
@mkdir -p obj
@echo $(INDENT)[$(notdir $(firstword $(CXX)))] Compiling $< for $(if $(DEBUG),Debug,Release) build
@$(CXX) $(CXXFLAGS) $(if $(DEBUG),-g,-DNDEBUG) $(INCFLAGS) -c $< -o $@
obj/%.o:: %.cc Makefile $(ROOT)/common.mk $(INCLUDE_DIRS) $(INCLUDES)
@mkdir -p obj
@echo $(INDENT)[$(notdir $(firstword $(CXX)))] Compiling $< for $(if $(DEBUG),Debug,Release) build
@$(CXX) $(CXXFLAGS) $(if $(DEBUG),-g,-DNDEBUG) $(INCFLAGS) -c $< -o $@
obj/%.o:: %.C Makefile $(ROOT)/common.mk $(INCLUDE_DIRS) $(INCLUDES)
@mkdir -p obj
@echo $(INDENT)[$(notdir $(firstword $(CXX)))] Compiling $< for $(if $(DEBUG),Debug,Release) build
@$(CXX) $(CXXFLAGS) $(if $(DEBUG),-g,-DNDEBUG) $(INCFLAGS) -c $< -o $@
$(SHARED_LIB_TARGETS):: $(OBJS) $(INCLUDE_DIRS) $(INCLUDES) Makefile $(ROOT)/common.mk
@echo $(INDENT)[$(notdir $(firstword $(CXXLIB)))] Linking $@ for $(if $(DEBUG),Debug,Release) build
@$(CXXLIB) $(CXXFLAGS) $(INCFLAGS) $(OBJS) -o $@ $(LIBFLAGS)
$(STATIC_LIB_TARGETS):: $(OBJS) $(INCLUDE_DIRS) $(INCLUDES) Makefile $(ROOT)/common.mk
@echo $(INDENT)[ar] Linking $@ for $(if $(DEBUG),Debug,Release) build
@ar rcs $@ $(OBJS)
$(OTHER_TARGETS):: $(OBJS) $(INCLUDE_DIRS) $(INCLUDES) Makefile $(ROOT)/common.mk
@echo $(INDENT)[$(notdir $(firstword $(CXX)))] Linking $@ for $(if $(DEBUG),Debug,Release) build
@$(CXX) $(CXXFLAGS) $(LINKFLAGS) $(if $(DEBUG),-g,-DNDEBUG) $(INCFLAGS) $(OBJS) -o $@ $(LIBFLAGS)
$(RECURSIVE_TARGETS)::
@for dir in $(DIRS); do \
echo "$(INDENT)[$@] Entering $$dir"; \
$(MAKE) -C $$dir $@ DEBUG=$(DEBUG); \
done
$(ROOT)/Heap-Layers:
@ echo $(INDENT)[git] Checking out Heap-Layers
@rm -rf $(ROOT)/Heap-Layers
@git clone https://github.com/emeryberger/Heap-Layers.git $(ROOT)/Heap-Layers