forked from varnishcache/varnish-cache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.inc.phk
246 lines (189 loc) · 5.72 KB
/
Makefile.inc.phk
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
235
236
237
238
239
240
241
242
243
244
245
246
.PHONY: default
default: all
WARNS ?= 1
.PHONY: depend all clean install test
depend all clean install test:
@$(MAKE) --no-print-directory -f Makefile.phk TGT=$@ real-$@ \
$(shell env CC=$(CC) WARNS=$(WARNS) \
sh ${TOPDIR}/config.phk $(TOPDIR) $(CURDIR) )
CFLAGS += $(CF_CFLAGS) $(CF_CWFLAGS)
CFLAGS += -I$(CURDIR)
CFLAGS += -I$(TOPDIR)
CFLAGS += -I$(TOPDIR)/include
CFLAGS += -I$(TOPDIR)/lib/libvgz
CFLAGS += -I/usr/local/include
SHLIB_LDFLAGS += -shared -Wl,-x -Wl,--fatal-warnings -Wl,--warn-shared-textrel
VMOD_LDFLAGS += ${SHLIB_LDFLAGS}
#######################################################################
INSTALL_BASE ?= $(TOPDIR)/_install
#######################################################################
LIB_VARNISH = -L $(TOPDIR)/lib/libvarnish -lvarnish
LIB_VARNISHAPI = $(TOPDIR)/lib/libvarnishapi/libvarnishapi.a
LIB_VARNISHTOOLS = -L $(TOPDIR)/lib/libvarnishtools -lvarnishtools
LIB_VCC = -L $(TOPDIR)/lib/libvcc -lvcc
LIB_VGZ = -L $(TOPDIR)/lib/libvgz -lvgz
LIB_PCRE = -L /usr/local/lib -lpcre
LIB_EXECINFO = ${CFG_EXECINFO}
LIB_CURSES = -lcurses
LIB_READLINE = ${CFG_LINEDISC}
#######################################################################
ifdef USE_THREADS
CFLAGS += -pthread -D_THREAD_SAFE -g -O2
PROG_LDFLAGS += -pthread -D_THREAD_SAFE -g -O2
endif
ifdef USE_DLOPEN
PROG_LDFLAGS += -Wl,-E
PROG_LIBS += ${CFG_LIBDL}
endif
#######################################################################
ifdef SUBDIRS
ifeq "$(findstring k,$(MAKEFLAGS))" ""
EOPT=set -e
else
EOPT=set +e
endif
define run-subdirs
$(EOPT) ; for dir in $(SUBDIRS); do \
echo "->> $$dir $(@:real-%=%)" ; \
$(MAKE) -C $$dir -f Makefile.phk $(@:real-%=%) ; \
done
endef
else
define run-subdirs
endef
endif
#######################################################################
ifdef NOWORK
ifdef SUBDIRS
.PHONY: subdirs $(SUBDIRS)
subdirs: $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $@ -f Makefile.phk $(@:real-%=%)
TODO += subdirs
endif
endif
#######################################################################
.SUFFIXES: .So
.c.So:
${CC} $(CFLAGS) -fPIC -c $< -o $@
#######################################################################
TODO_DEPEND += $(MADE_FILES)
TODO_ALL += $(MADE_FILES)
CLEAN_FILES += $(MADE_FILES)
MADE_SRC = $(filter %.c, $(MADE_FILES))
#######################################################################
ifdef PROG_SRC
PROGNAME = $(notdir $(CURDIR))
MANNAME=$(PROGNAME).1
TODO_DEPEND += _.depprog
TODO_ALL += $(PROGNAME)
TODO_INSTALL += prog_install
PROG_SRC += $(MADE_SRC)
PROG_OBJ = $(notdir $(PROG_SRC:.c=.o))
CLEAN_FILES += $(PROGNAME) $(PROG_OBJ) _.depprog $(MANNAME)
_.depprog: ${PROG_SRC} ${MADE_FILES}
$(CC) $(CFLAGS) -MM $^ > _.depprog
ifeq ($(TGT), all)
include _.depprog
endif
$(PROGNAME): $(PROG_OBJ)
$(CC) $(PROG_LDFLAGS) -o $(PROGNAME) $^ $(PROG_LIBS) $(LD_ADD)
.PHONY: prog_install
prog_install: $(PROGNAME)
@cp $(PROGNAME) $(INSTALL_BASE)/bin/
@[ ! -f $(MANNAME) ] || cp $(MANNAME) $(INSTALL_BASE)/man/
endif
#######################################################################
ifdef SHLIB_SRC
SHLIBNAME = $(notdir $(CURDIR))
TODO_ALL += $(SHLIBNAME).so
TODO_DEPEND += _.depshlib
TODO_INSTALL += shlib_install
SHLIB_SRC += $(MADE_SRC)
SHLIB_OBJ = $(notdir $(SHLIB_SRC:.c=.So))
CLEAN_FILES += $(SHLIB_OBJ) $(SHLIBNAME).so _.depshlib
_.depshlib: ${SHLIB_SRC} ${MADE_FILES}
$(CC) $(CFLAGS) -MM $^ |sed 's/o:/So:/' > _.depshlib
ifeq ($(TGT), all)
include _.depshlib
endif
$(SHLIBNAME).so: $(SHLIB_OBJ)
$(CC) $(SHLIB_LDFLAGS) -o $(SHLIBNAME).so $^
.PHONY: shlib_install
shlib_install: $(SHLIBNAME).so
@cp $(SHLIBNAME).so $(INSTALL_BASE)/lib/
endif
#######################################################################
ifdef LIB_SRC
LIBNAME = $(notdir $(CURDIR))
TODO_ALL += $(LIBNAME).a
TODO_DEPEND += _.deplib
LIB_SRC += $(MADE_SRC)
LIB_OBJ = $(notdir $(LIB_SRC:.c=.o))
CLEAN_FILES += $(LIB_OBJ) $(LIBNAME).a _.deplib
_.deplib: ${LIB_SRC} ${MADE_FILES}
$(CC) $(CFLAGS) -MM $^ > _.deplib
ifeq ($(TGT), all)
include _.deplib
endif
$(LIBNAME).a: $(LIB_OBJ)
$(AR) -rc $(LIBNAME).a $^
ranlib $(LIBNAME).a
endif
#######################################################################
ifdef VMOD_SRC
#VMODNAME = $(subst libvmod_,,$(notdir $(CURDIR)))
VMODNAME = $(notdir $(CURDIR))
TODO_ALL += vcc_if.h vcc_if.c $(VMODNAME).so
TODO_DEPEND += _.depvmod
TODO_INSTALL += vmod_install
VMOD_SRC += $(MADE_SRC)
VMOD_SRC += vcc_if.c
VMOD_OBJ = $(notdir $(VMOD_SRC:.c=.So))
CLEAN_FILES += $(VMOD_OBJ) vcc_if.c vcc_if.h $(VMODNAME).so _.depvmod
CFLAGS += -I$(TOPDIR)/bin/varnishd
_.depvmod: ${VMOD_SRC} ${MADE_FILES}
$(CC) $(CFLAGS) -MM $^ |sed 's/o:/So:/' > _.depvmod
ifeq ($(TGT), all)
include _.depvmod
endif
vcc_if.c vcc_if.h: vmod.vcc $(TOPDIR)/lib/libvcc/vmodtool.py
${PYTHON} $(TOPDIR)/lib/libvcc/vmodtool.py
$(VMODNAME).so: $(VMOD_OBJ)
$(CC) $(VMOD_LDFLAGS) -o $(VMODNAME).so $^
mkdir -p .libs
(cd .libs && ln -sf ../$(VMODNAME).so)
.PHONY: vmod_install
vmod_install: $(VMODNAME).so
@cp $(VMODNAME).so $(INSTALL_BASE)/libexec/
endif
#######################################################################
ifdef RST_MAN
ifdef HAVE_RST2HTML
TODO_ALL += ${MANNAME}
${MANNAME}: ${RST_MAN}
rst2man ${RST_MAN} $(MANNAME)
endif
endif
#######################################################################
.PHONY: real-depend
real-depend: $(TODO) $(TODO_DEPEND)
@$(run-subdirs)
@true
.PHONY: real-all
real-all: $(TODO) $(TODO_ALL)
@$(run-subdirs)
@true
.PHONY: real-clean
real-clean: $(TODO) $(TODO_CLEAN)
@$(run-subdirs)
@[ "x$(CLEAN_FILES)" = "x" ] || rm -f $(CLEAN_FILES)
.PHONY: real-install
real-install: $(TODO_INSTALL)
@$(run-subdirs)
@true
.PHONY: real-test
real-test: $(TODO_TEST)
@$(run-subdirs)
@true
#######################################################################