-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
185 lines (143 loc) · 3.9 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# SPDX-License-Identifier: GPL-2.0-only
VERSION = 0
PATCHLEVEL = 0
SUBLEVEL = 0
EXTRAVERSION =
NAME = Hurt but don't want to go
TARGET = libhpcemerg
TARGET_BIN = $(TARGET).so
ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),clean_all)
include config-host.mak
endif
endif
override USER_CFLAGS := $(CFLAGS)
override USER_CXXFLAGS := $(CXXFLAGS)
override USER_LDFLAGS := $(LDFLAGS)
override USER_LIB_LDFLAGS := $(LIB_LDFLAGS)
MKDIR := mkdir
BASE_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
BASE_DIR := $(strip $(patsubst %/, %, $(BASE_DIR)))
BASE_DEP_DIR := $(BASE_DIR)/.deps
MAKEFILE_FILE := $(lastword $(MAKEFILE_LIST))
INCLUDE_DIR = -I$(BASE_DIR) -I$(BASE_DIR)/src
PACKAGE_NAME := $(TARGET)-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
ifndef DEBUG_MODE
DEBUG_MODE := 0
endif
ifndef OPTIMIZATION_FLAG
OPTIMIZATION_FLAG := -O2
endif
# This will be appended to {C,CXX,LD}FLAGS only when DEBUG_MODE is 1.
DEBUG_OPTIMIZATION_FLAG := -O0
STACK_USAGE_WARN := 4096
override PIC_FLAGS := -fpic -fPIC
override LDFLAGS := -ggdb3 -rdynamic $(LDFLAGS)
override LIB_LDFLAGS := -lpthread $(LIB_LDFLAGS)
override C_CXX_FLAGS := \
-ggdb3 \
-fstrict-aliasing \
-fno-stack-protector \
-fdata-sections \
-ffunction-sections \
-D_GNU_SOURCE \
-DVERSION=$(VERSION) \
-DPATCHLEVEL=$(PATCHLEVEL) \
-DSUBLEVEL=$(SUBLEVEL) \
-DEXTRAVERSION="\"$(EXTRAVERSION)\"" \
-DNAME="\"$(NAME)\"" \
-include $(BASE_DIR)/config-host.h $(C_CXX_FLAGS)
override C_CXX_FLAGS_DEBUG := $(C_CXX_FLAGS_DEBUG)
override GCC_WARN_FLAGS := \
-Wall \
-Wextra \
-Wformat \
-Wformat-security \
-Wformat-signedness \
-Wsequence-point \
-Wstrict-aliasing=3 \
-Wstack-usage=$(STACK_USAGE_WARN) \
-Wunsafe-loop-optimizations $(GCC_WARN_FLAGS)
override CLANG_WARN_FLAGS := \
-Wall \
-Wextra \
$(CLANG_WARN_FLAGS)
include $(BASE_DIR)/scripts/build/flags.mk
include $(BASE_DIR)/scripts/build/print.mk
#
# These empty assignments force the variables to be a simple variable.
#
OBJ_CC :=
#
# OBJ_PRE_CC is a collection of object files which the compile rules are
# defined in sub Makefile.
#
OBJ_PRE_CC :=
#
# OBJ_TMP_CC is a temporary variable which is used in the sub Makefile.
#
OBJ_TMP_CC :=
#
# Extension dependency file, not always supposed to be compiled.
#
EXT_DEP_FILE := $(MAKEFILE_FILE) config-host.mak config-host.h
all: __all
config-host.mak: configure
@if [ ! -e "$@" ]; then \
echo "Running configure ..."; \
LDFLAGS="$(USER_LDFLAGS)" \
LIB_LDFLAGS="$(USER_LIB_LDFLAGS)" \
CFLAGS="$(USER_CFLAGS)" \
CXXFLAGS="$(USER_CXXFLAGS)" \
./configure; \
else \
echo "$@ is out-of-date"; \
echo "Running configure ..."; \
LDFLAGS="$(USER_LDFLAGS)" \
LIB_LDFLAGS="$(USER_LIB_LDFLAGS)" \
CFLAGS="$(USER_CFLAGS)" \
CXXFLAGS="$(USER_CXXFLAGS)" \
sed -n "/.*Configured with/s/[^:]*: //p" "$@" | sh; \
fi
include $(BASE_DIR)/src/Makefile
include $(BASE_DIR)/tests/Makefile
#
# Create dependency directories
#
$(DEP_DIRS):
$(MKDIR_PRINT)
$(Q)$(MKDIR) -p $(@)
#
# Add more dependency chain to objects that are not compiled from the main
# Makefile (the main Makefile is *this* Makefile).
#
$(OBJ_CC): $(EXT_DEP_FILE) | $(DEP_DIRS)
$(OBJ_PRE_CC): $(EXT_DEP_FILE) | $(DEP_DIRS)
#
# Compile object from the main Makefile (the main Makefile is *this* Makefile).
#
$(OBJ_CC):
$(CC_PRINT)
$(Q)$(CC) $(PIC_FLAGS) $(DEPFLAGS) $(CFLAGS) -c $(O_TO_C) -o $(@)
#
# Include generated dependencies
#
-include $(OBJ_CC:$(BASE_DIR)/%.o=$(BASE_DEP_DIR)/%.d)
-include $(OBJ_PRE_CC:$(BASE_DIR)/%.o=$(BASE_DEP_DIR)/%.d)
#
# Link the target bin.
#
$(TARGET_BIN): $(OBJ_CC) $(OBJ_PRE_CC)
$(LD_PRINT)
$(Q)$(LD) $(PIC_FLAGS) $(LDFLAGS) $(^) -shared -o "$(@)" $(LIB_LDFLAGS)
__all: $(EXT_DEP_FILE) $(TARGET_BIN)
clean: clean_test
$(Q)$(RM) -vf \
$(TARGET_BIN) \
$(OBJ_CC) \
$(OBJ_PRE_CC) \
config-host.mak \
config-host.h \
config.log;
clean_all: clean
.PHONY: __all all clean clean_all