-
Notifications
You must be signed in to change notification settings - Fork 2
/
macros.mk
234 lines (196 loc) · 5.25 KB
/
macros.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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#
# Enhanced Seccomp Library Build Macros
#
# Copyright (c) 2012 Red Hat <[email protected]>
# Author: Paul Moore <[email protected]>
#
#
# This library is free software; you can redistribute it and/or modify it
# under the terms of version 2.1 of the GNU Lesser General Public License as
# published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
# for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library; if not, see <http://www.gnu.org/licenses>.
#
SHELL = /bin/bash
#
# simple /bin/bash script to find the top of the tree
#
TOPDIR := $(shell \
ftd() { \
cd $$1; \
if [[ -r "macros.mk" ]]; then \
pwd; \
else \
ftd "../"; \
fi \
}; \
ftd .)
#
# build configuration
#
V ?= 0
CPPFLAGS += -I$(TOPDIR) -I$(TOPDIR)/include
LIBFLAGS =
CFLAGS ?= -Wl,-z,relro -Wall -O0 -g -fvisibility=hidden
CFLAGS += -fPIC
PYCFLAGS ?= -fvisibility=default
LDFLAGS ?= -z relro -g
#
# build tools
#
LN ?= ln
MV ?= mv
CAT ?= cat
ECHO ?= echo
TAR ?= tar
MKDIR ?= mkdir
SED ?= sed
AWK ?= awk
PYTHON ?= /usr/bin/env python
# we require gcc specific functionality
GCC ?= gcc
INSTALL ?= install
ifeq ($(V),0)
MAKE += --quiet --no-print-directory
ECHO_INFO ?= $(ECHO) ">> INFO:"
else
ECHO_INFO ?= /bin/true || $(ECHO) ">> INFO:"
endif
#
# auto dependencies
#
MAKEDEP = @$(GCC) $(CPPFLAGS) -MM -MF $(patsubst %.o,%.d,$@) $<;
MAKEDEP_EXEC = \
@$(GCC) $(CPPFLAGS) -MM -MT $(patsubst %.d,%,$@) \
-MF $@ $(patsubst %.d,%.c,$@);
ADDDEP = \
@adddep_func() { \
$(MV) $$1 $$1.dtmp; \
$(CAT) $$1.dtmp | $(SED) -e 's/\([^\]\)$$/\1 \\/' | \
( $(CAT) - && $(ECHO) " $$2" ) > $$1; \
$(RM) -f [email protected]; \
}; \
adddep_func
#
# build constants
#
VERSION_HDR = version.h
#
# build macros
#
PY_DISTUTILS = \
VERSION_RELEASE="$(VERSION_RELEASE)" \
CFLAGS="$(CFLAGS) $(CPPFLAGS) $(PYCFLAGS)" LDFLAGS="$(LDFLAGS)" \
$(PYTHON) ./setup.py
ifeq ($(V),0)
PY_BUILD = @echo " PYTHON build";
endif
PY_BUILD += $(PY_DISTUTILS)
ifeq ($(V),0)
PY_BUILD += -q
endif
PY_BUILD += build
ifeq ($(V),0)
PY_INSTALL = @echo " PYTHON install";
endif
PY_INSTALL += $(PY_DISTUTILS)
ifeq ($(V),0)
PY_INSTALL += -q
endif
PY_INSTALL += install
ifeq ($(V),0)
COMPILE = @echo " CC $@";
endif
COMPILE += $(GCC) $(CFLAGS) $(CPPFLAGS) -o $@ -c $<;
ifeq ($(V),0)
COMPILE_EXEC = @echo " CC $@";
endif
COMPILE_EXEC += $(GCC) $(CFLAGS) $(CPPFLAGS) -o $@ $< $(LDFLAGS);
ifeq ($(V),0)
ARCHIVE = @echo " AR $@";
endif
ARCHIVE += $(AR) -cru $@ $?;
ifeq ($(V),0)
LINK_EXEC = @echo " LD $@";
endif
LINK_EXEC += $(GCC) $(LDFLAGS) -o $@ $^ $(LIBFLAGS);
ifeq ($(V),0)
LINK_LIB = @echo " LD $@" \
"($(patsubst %.so.$(VERSION_RELEASE),%.so.$(VERSION_MAJOR),$@))";
endif
LINK_LIB += $(GCC) $(LDFLAGS) -o $@ $^ -shared \
-Wl,-soname=$(patsubst %.so.$(VERSION_RELEASE),%.so.$(VERSION_MAJOR),$@)
#
# install macros
#
ifeq ($(V),0)
INSTALL_LIB_MACRO = @echo " INSTALL $^ ($(INSTALL_LIB_DIR)/$^)";
endif
INSTALL_LIB_MACRO += \
basename=$$(echo $^ | sed -e 's/.so.*$$/.so/'); \
soname=$$(objdump -p $^ | grep "SONAME" | awk '{print $$2}'); \
$(INSTALL) -o $(INSTALL_OWNER) -g $(INSTALL_GROUP) \
-d "$(INSTALL_LIB_DIR)"; \
$(INSTALL) -o $(INSTALL_OWNER) -g $(INSTALL_GROUP) -m 0755 \
$^ "$(INSTALL_LIB_DIR)"; \
(cd "$(INSTALL_LIB_DIR)"; $(RM) $$soname); \
(cd "$(INSTALL_LIB_DIR)"; $(LN) -s $^ $$soname); \
(cd "$(INSTALL_LIB_DIR)"; $(RM) $$basname); \
(cd "$(INSTALL_LIB_DIR)"; $(LN) -s $^ $$basename);
ifeq ($(V),0)
INSTALL_BIN_MACRO = @echo " INSTALL $^ ($(INSTALL_BIN_DIR)/$^)";
endif
INSTALL_BIN_MACRO += \
$(INSTALL) -o $(INSTALL_OWNER) -g $(INSTALL_GROUP) \
-d "$(INSTALL_BIN_DIR)"; \
$(INSTALL) -o $(INSTALL_OWNER) -g $(INSTALL_GROUP) -m 0755 \
$^ "$(INSTALL_BIN_DIR)";
ifeq ($(V),0)
INSTALL_PC_MACRO = \
@echo " INSTALL $$(cat /proc/$$$$/cmdline | awk '{print $$(NF)}')" \
" ($(INSTALL_LIB_DIR)/pkgconfig)";
endif
INSTALL_PC_MACRO += \
$(INSTALL) -o $(INSTALL_OWNER) -g $(INSTALL_GROUP) \
-d "$(INSTALL_LIB_DIR)/pkgconfig"; \
$(INSTALL) -o $(INSTALL_OWNER) -g $(INSTALL_GROUP) -m 0644 \
"$$(cat /proc/$$$$/cmdline | awk '{print $$(NF)}')" \
"$(INSTALL_LIB_DIR)/pkgconfig"; \#
ifeq ($(V),0)
INSTALL_INC_MACRO = @echo " INSTALL $^ ($(INSTALL_INC_DIR))";
endif
INSTALL_INC_MACRO += \
$(INSTALL) -o $(INSTALL_OWNER) -g $(INSTALL_GROUP) \
-d "$(INSTALL_INC_DIR)"; \
$(INSTALL) -o $(INSTALL_OWNER) -g $(INSTALL_GROUP) -m 0644 \
$^ "$(INSTALL_INC_DIR)";
ifeq ($(V),0)
INSTALL_MAN1_MACRO = \
@echo " INSTALL manpages ($(INSTALL_MAN_DIR)/man1)";
endif
INSTALL_MAN1_MACRO += \
$(INSTALL) -o $(INSTALL_OWNER) -g $(INSTALL_GROUP) \
-d "$(INSTALL_MAN_DIR)/man1"; \
$(INSTALL) -o $(INSTALL_OWNER) -g $(INSTALL_GROUP) -m 0644 \
$^ "$(INSTALL_MAN_DIR)/man1";
ifeq ($(V),0)
INSTALL_MAN3_MACRO = \
@echo " INSTALL manpages ($(INSTALL_MAN_DIR)/man3)";
endif
INSTALL_MAN3_MACRO += \
$(INSTALL) -o $(INSTALL_OWNER) -g $(INSTALL_GROUP) \
-d "$(INSTALL_MAN_DIR)/man3"; \
$(INSTALL) -o $(INSTALL_OWNER) -g $(INSTALL_GROUP) -m 0644 \
$^ "$(INSTALL_MAN_DIR)/man3";
#
# default build targets
#
%.o: %.c
$(MAKEDEP)
$(COMPILE)