-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
328 lines (257 loc) · 8.78 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
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
# BEGIN CONFIGURABLE SETTINGS
# Compile-time features
L2TP_FEATURE_LAC_SUPPORT= y
L2TP_FEATURE_LNS_SUPPORT= y
L2TP_FEATURE_RPC_MANAGEMENT= y
L2TP_FEATURE_LAIC_SUPPORT= y
L2TP_FEATURE_LAOC_SUPPORT= y
L2TP_FEATURE_LNIC_SUPPORT= y
L2TP_FEATURE_LNOC_SUPPORT= y
L2TP_FEATURE_LOCAL_CONF_FILE= y
#L2TP_FEATURE_LOCAL_STAT_FILE= y
# Define USE_DMALLOC to enable dmalloc memory debugging
# USE_DMALLOC= y
# Define to include test code. This must be defined to run the
# regression tests
# L2TP_TEST= y
# Define to compile in debug code. Also makes default trace flags
# enable all messages
# L2TP_DEBUG= y
# Use asynchronous RPC requests where appropriate
# Affects only L2TP-PPP-IPPOOL interfaces, not management interfaces.
L2TP_USE_ASYNC_RPC= y
# Build for UML environment?
# UML_TARGET= y
SYS_LIBDIR=/usr/lib
# Points to pppd install. By default, pppd headers are assumed to be
# in the pppd subdirectory of the compiler's default search path
# (e.g. /usr/include/pppd). but can be pointed to another directory if
# desired.
PPPD_VERSION= 2.4.5
# PPPD_INCDIR= /usr/include/pppd
# PPPD_LIBDIR= $(SYS_LIBDIR)/pppd/$(PPPD_VERSION)
# Points to readline install root. READLINE_DIR should have lib/ &
# include/ subdirs If not defined, readline is assumed to be installed
# in the standard places that the compiler looks.
READLINE_DIR=
# For cross-compiling
CROSS_COMPILE=
# END CONFIGURABLE SETTINGS
AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc
AR = $(CROSS_COMPILE)ar
NM = $(CROSS_COMPILE)nm
STRIP = $(CROSS_COMPILE)strip
INSTALL = $(CROSS_COMPILE)install
ifneq ($(READLINE_DIR),)
READLINE_LDFLAGS= -L $(READLINE_DIR)/lib
READLINE_CFLAGS= -I $(READLINE_DIR)/include
endif
export PPPD_VERSION PPPD_SRCDIR PPPD_LIBDIR READLINE_LDFLAGS READLINE_CFLAGS
export CROSS_COMPILE AS LD CC AR NM STRIP OBJCOPY OBJDUMP INSTALL UML_TARGET
export DESTDIR SYS_LIBDIR
# Feature options are exported to sub-makes
export L2TP_FEATURE_LAC_SUPPORT
export L2TP_FEATURE_LNS_SUPPORT
export L2TP_FEATURE_RPC_MANAGEMENT
export L2TP_FEATURE_LAIC_SUPPORT
export L2TP_FEATURE_LAOC_SUPPORT
export L2TP_FEATURE_LNIC_SUPPORT
export L2TP_FEATURE_LNOC_SUPPORT
export L2TP_FEATURE_LOCAL_CONF_FILE
export L2TP_FEATURE_LOCAL_STAT_FILE
# Build pppd dir only if ppp version is earlier than 2.4.5 since the
# openl2tp plugins were integrated in ppp-2.4.5.
PPPD_SUBDIR=pppd
ifeq ($(PPPD_VERSION),2.4.5)
PPPD_SUBDIR=
endif
SUBDIRS= usl cli plugins $(PPPD_SUBDIR) test doc
.PHONY: $(SUBDIRS:%=subdir-%)
L2TP_RPC_STEM= l2tp_rpc
RPC_FILES= $(L2TP_RPC_STEM).h
ifeq ($(L2TP_FEATURE_RPC_MANAGEMENT),y)
RPC_FILES+= $(L2TP_RPC_STEM)_server.c $(L2TP_RPC_STEM)_client.c $(L2TP_RPC_STEM)_xdr.c
endif
ifeq ($(L2TP_FEATURE_LOCAL_CONF_FILE),y)
PARSE_FILES= l2tp_config_token.c l2tp_config_parse.c l2tp_config_parse.h
endif
L2TPD_SRCS.c= l2tp_main.c l2tp_common.c l2tp_avp.c l2tp_packet.c \
l2tp_network.c l2tp_tunnel.c l2tp_peer.c l2tp_transport.c \
l2tp_session.c l2tp_ppp.c \
l2tp_plugin.c l2tp_event.c l2tp_test.c md5.c
ifeq ($(L2TP_FEATURE_RPC_MANAGEMENT),y)
L2TPD_SRCS.c+= l2tp_api.c
endif
ifeq ($(L2TP_FEATURE_LOCAL_STAT_FILE),y)
L2TPD_SRCS.c+= l2tp_statusfile.c
endif
L2TPD_SRCS.h= l2tp_api.h l2tp_avp.h l2tp_private.h md5.h
ifeq ($(L2TP_TEST),y)
CPPFLAGS.l2tptest= -DL2TP_TEST
endif
L2TPCONFIG_SRCS.c= l2tp_config.c
L2TPD_SRCS.o= $(L2TPD_SRCS.c:%.c=%.o)
ifeq ($(L2TP_FEATURE_RPC_MANAGEMENT),y)
L2TPD_SRCS.o+= $(L2TP_RPC_STEM)_server.o $(L2TP_RPC_STEM)_xdr.o
endif
L2TPCONFIG_SRCS.o= $(L2TPCONFIG_SRCS.c:%.c=%.o) $(L2TP_RPC_STEM)_client.o $(L2TP_RPC_STEM)_xdr.o
L2TPD_SRCS.o+= $(filter-out l2tp_config_parse.h, $(PARSE_FILES:%.c=%.o))
ifeq ($(USE_DMALLOC),y)
CPPFLAGS.dmalloc= -DL2TP_DMALLOC
LIBS.dmalloc= -ldmalloc
export USE_DMALLOC
endif
CPPFLAGS= $(CPPFLAGS.l2tptest) $(CPPFLAGS-y)
CFLAGS= -I. -Iusl -Icli -isystem include \
-MMD -Wall -Wno-strict-aliasing \
$(CPPFLAGS) $(CPPFLAGS.dmalloc) \
-DSYS_LIBDIR=$(SYS_LIBDIR)
LDFLAGS.l2tpd= -Wl,-E -L. -Lusl -lusl -ldl $(LIBS.dmalloc) -lc
LDFLAGS.l2tpconfig= -Lcli -lcli -lreadline $(LIBS.dmalloc) $(READLINE_LDFLAGS) -lc
OPT_CFLAGS?= -O
ifeq ($(L2TP_DEBUG),y)
CFLAGS.optimize= -g
CFLAGS.optimize+= -DDEBUG
else
CFLAGS.optimize= $(OPT_CFLAGS)
endif
export CFLAGS.optimize
CFLAGS+= $(CFLAGS.optimize)
ifeq ($(L2TP_USE_ASYNC_RPC),y)
CPPFLAGS+= -DL2TP_ASYNC_RPC
endif
ifeq ($(L2TP_FEATURE_RPC_MANAGEMENT),y)
APP= l2tpconfig
endif
RPCGEN= rpcgen
RPCGENFLAGS= -N -M -C -L
.PHONY: all clean distclean install daemon app test
all: generated-files daemon $(APP)
daemon: generated-files $(SUBDIRS:%=subdir-%) openl2tpd
app: generated-files l2tpconfig
test: subdir-test
$(MAKE) -C $@ $(MFLAGS) $@
.PHONY: $(SUBDIRS:%=subdir-%)
$(SUBDIRS:%=subdir-%): FORCE
$(MAKE) -C $(@:subdir-%=%) $(MFLAGS) EXTRA_CFLAGS="$(CPPFLAGS)"
ifeq ($(L2TP_FEATURE_LOCAL_CONF_FILE),y)
# Config file parser
LEX= flex
YACC= bison
LDFLAGS.l2tpd+= -lfl
%.c: %.l
$(LEX) -o$@ $<
%.h %.c: %.y
$(YACC) -d -o l2tp_config_parse.c $<
l2tp_config_token.o: l2tp_config_token.c
$(CC) -I. -MMD -w $(CFLAGS.optimize) -c -DYY_NO_UNPUT $<
l2tp_config_parse.o: l2tp_config_parse.c l2tp_config_parse.h
$(CC) -I. -MMD -w $(CFLAGS.optimize) -c -DYY_NO_UNPUT $<
endif
# Compile without -Wall because rpcgen-generated code is full of warnings.
%_xdr.o: %_xdr.c
$(CC) -I. -MMD -w $(CFLAGS.optimize) -c $(CPPFLAGS) $<
%_client.o: %_client.c
$(CC) -I. -MMD -w $(CFLAGS.optimize) -c $(CPPFLAGS) $<
%_server.o: %_server.c
$(CC) -I. -MMD -w $(CFLAGS.optimize) -c $(CPPFLAGS) $<
%_xdr.c: %.x
-$(RM) $@
$(RPCGEN) $(RPCGENFLAGS) -c -o $@ $<
%_server.c: %.x
-$(RM) $@ [email protected]
$(RPCGEN) $(RPCGENFLAGS) -m -o [email protected] $<
cat [email protected] | sed -e 's/switch (rqstp->rq_proc) {/if (l2tp_api_rpc_check_request(transp) < 0) return; switch (rqstp->rq_proc) {/' > $@
%_client.c: %.x
-$(RM) $@
$(RPCGEN) $(RPCGENFLAGS) -l -o $@ $<
%.h: %.x
-$(RM) $@
$(RPCGEN) $(RPCGENFLAGS) -h -o $@ $<
.PHONY: generated-files plugins clean distclean
generated-files: $(RPC_FILES) $(PARSE_FILES) l2tp_options.h
clean:
@for d in $(SUBDIRS); do $(MAKE) -C $$d $(MFLAGS) $@; if [ $$? -ne 0 ]; then exit 1; fi; done
-$(MAKE) -C redhat $(MFLAGS) $@
-$(RM) $(L2TPD_SRCS.o) $(L2TPCONFIG_SRCS.o) openl2tpd l2tpconfig $(RPC_FILES)
-$(RM) l2tp_options.h l2tp_options.h.tmp
-$(RM) l2tp_config_parse.c l2tp_config_parse.h l2tp_config_token.c
-$(RM) $(wildcard *.d)
-$(RM) $(wildcard l2tp_*rpc_*.tmp)
distclean: clean
-$(RM) TAGS
TAGS:
@for d in $(SUBDIRS); do $(MAKE) -C $$d $(MFLAGS) $@; done
etags $(wildcard *.c) $(wildcard *.h)
openl2tpd: $(L2TPD_SRCS.o)
$(CC) -o $@ $^ $(LDFLAGS.l2tpd) -ltirpc -lportablexdr
l2tpconfig: $(L2TPCONFIG_SRCS.o)
$(CC) -o $@ $^ $(LDFLAGS.l2tpconfig) -ltirpc -lportablexdr -lncursesw
%.o: %.c
$(CC) -c $(CFLAGS) $< -o $@
l2tp_options.h: FORCE
@rm -f [email protected]
@echo '/* This file is auto-generated. DO NOT EDIT. */' >> [email protected]
@echo '#ifndef L2TP_OPTIONS_H' >> [email protected]
@echo '#define L2TP_OPTIONS_H' >> [email protected]
@echo >> [email protected]
ifeq ($(L2TP_FEATURE_LOCAL_CONF_FILE),y)
@echo '#define L2TP_FEATURE_LOCAL_CONF_FILE' >> [email protected]
endif
ifeq ($(L2TP_FEATURE_LOCAL_STAT_FILE),y)
@echo '#define L2TP_FEATURE_LOCAL_STAT_FILE' >> [email protected]
endif
ifeq ($(L2TP_FEATURE_LAC_SUPPORT),y)
@echo '#define L2TP_FEATURE_LAC_SUPPORT' >> [email protected]
endif
ifeq ($(L2TP_FEATURE_LNS_SUPPORT),y)
@echo '#define L2TP_FEATURE_LNS_SUPPORT' >> [email protected]
endif
ifeq ($(L2TP_FEATURE_LAIC_SUPPORT),y)
@echo '#define L2TP_FEATURE_LAIC_SUPPORT' >> [email protected]
endif
ifeq ($(L2TP_FEATURE_LAOC_SUPPORT),y)
@echo '#define L2TP_FEATURE_LAOC_SUPPORT' >> [email protected]
endif
ifeq ($(L2TP_FEATURE_LNIC_SUPPORT),y)
@echo '#define L2TP_FEATURE_LNIC_SUPPORT' >> [email protected]
endif
ifeq ($(L2TP_FEATURE_LNOC_SUPPORT),y)
@echo '#define L2TP_FEATURE_LNOC_SUPPORT' >> [email protected]
endif
ifeq ($(L2TP_FEATURE_RPC_MANAGEMENT),y)
@echo '#define L2TP_FEATURE_RPC_MANAGEMENT' >> [email protected]
endif
@echo >> [email protected]
@echo '#endif' >> [email protected]
@if [ -e $@ ]; then \
diff -q $@ [email protected] > /dev/null ;\
if [ $$? -ne 0 ]; then \
mv [email protected] $@ ;\
fi ;\
else \
mv [email protected] $@ ;\
fi
.PHONY: all install-all install-daemon install-app
install: install-all
install-all: all install-daemon install-app
install-daemon:
@for d in $(filter-out usl,$(SUBDIRS)); do $(MAKE) -C $$d $(MFLAGS) EXTRA_CFLAGS="$(CPPFLAGS)" install; if [ $$? -ne 0 ]; then exit 1; fi; done
$(INSTALL) -d $(DESTDIR)/usr/sbin
$(INSTALL) openl2tpd $(DESTDIR)/usr/sbin
install-app:
$(INSTALL) -d $(DESTDIR)/usr/bin
ifeq ($(L2TP_FEATURE_RPC_MANAGEMENT),y)
$(INSTALL) l2tpconfig $(DESTDIR)/usr/bin
endif
$(INSTALL) -d $(DESTDIR)$(SYS_LIBDIR)/openl2tp
$(INSTALL) -m 0644 l2tp_rpc.x $(DESTDIR)$(SYS_LIBDIR)/openl2tp/l2tp_rpc.x
$(INSTALL) -m 0644 l2tp_event.h $(DESTDIR)$(SYS_LIBDIR)/openl2tp/l2tp_event.h
FORCE:
huh:
@set
@echo $(_libdir)
@echo $(LIBDIR)
sinclude $(wildcard *.d) /dev/null