29799e4e72b0b3b7484e6df91349bb31d8e7f8e2
[l2tpns.git] / Makefile
1 DESTDIR =
2 bindir = /usr/sbin
3 etcdir = /etc/l2tpns
4 libdir = /usr/lib/l2tpns
5 man5dir = /usr/share/man/man5
6 man8dir = /usr/share/man/man8
7 statedir = /var/lib/l2tpns
8
9 DEFINES =
10 DEFINES += -DLIBDIR='"$(libdir)"'
11 DEFINES += -DETCDIR='"$(etcdir)"'
12
13 DEB_CFLAGS_MAINT_APPEND=-Wall -O3 -Wno-format-zero-length
14
15 CC = gcc
16 LD = gcc
17 INCLUDES = -I.
18 CPPFLAGS = `dpkg-buildflags --get CPPFLAGS` $(INCLUDES) $(DEFINES)
19 CFLAGS = `dpkg-buildflags --get CFLAGS`
20 LDFLAGS = `dpkg-buildflags --get LDFLAGS`
21 LDLIBS =
22 INSTALL = install -c -D -o root -g root
23
24 l2tpns.LIBS = -lcli -ldl
25
26 OBJS = arp.o cli.o cluster.o constants.o control.o icmp.o l2tpns.o \
27 ll.o md5.o ppp.o radius.o tbf.o util.o pppoe.o l2tplac.o
28
29 PROGRAMS = l2tpns nsctl
30 PLUGINS = autosnoop.so autothrottle.so garden.so sessionctl.so \
31 setrxspeed.so snoopctl.so stripdomain.so throttlectl.so
32
33 DEFINES += -DSTATISTICS
34 DEFINES += -DSTAT_CALLS
35 DEFINES += -DRINGBUFFER
36
37 ifneq (2.4, $(shell uname -r | perl -pe 's/^(\d+\.\d+).*/$$1/'))
38 DEFINES += -DHAVE_EPOLL
39 endif
40
41 DEFINES += -DBGP
42 OBJS += bgp.o
43
44 all: programs plugins
45 programs: $(PROGRAMS)
46 plugins: $(PLUGINS)
47
48 clean:
49 rm -f *.o test/*.o $(PROGRAMS) $(PLUGINS) Makefile.tmp Makefile.bak
50
51 depend:
52 (sed -n 'p; /^## Dependencies: (autogenerated) ##/q' Makefile && \
53 gcc -MM $(CPPFLAGS) $(OBJS:.o=.c) && \
54 gcc -MM $(CPPFLAGS) $(PLUGINS:.so=.c) | sed 's/\.o/.so/') >Makefile.tmp
55 mv Makefile Makefile.bak
56 mv Makefile.tmp Makefile
57
58 l2tpns: $(OBJS)
59 $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) $($@.LIBS)
60
61 nsctl: nsctl.o control.o
62 $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) $($@.LIBS)
63
64 %.o: %.c
65 $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
66
67 %.so: %.c
68 $(CC) -fPIC -shared $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $<
69
70 install: all
71 $(INSTALL) -m 0755 l2tpns $(DESTDIR)$(bindir)/l2tpns
72 $(INSTALL) -m 0755 nsctl $(DESTDIR)$(bindir)/nsctl
73
74 $(INSTALL) -m 0644 Docs/startup-config.5 $(DESTDIR)$(man5dir)/startup-config.5
75 $(INSTALL) -m 0644 Docs/l2tpns.8 $(DESTDIR)$(man8dir)/l2tpns.8
76 $(INSTALL) -m 0644 Docs/nsctl.8 $(DESTDIR)$(man8dir)/nsctl.8
77
78 gzip --best --force $(DESTDIR)$(man5dir)/*.5 $(DESTDIR)$(man8dir)/*.8
79
80 @for config in startup-config users ip_pool; \
81 do \
82 suffix=; \
83 mode=0600; [ $$config = ip_pool ] && mode=0644; \
84 if [ -f $(DESTDIR)$(etcdir)/$$config ]; \
85 then \
86 cmp -s etc/$$config.default $(DESTDIR)$(etcdir)/$$config && continue; \
87 suffix=.default; \
88 fi; \
89 echo $(INSTALL) -m $$mode etc/$$config.default $(DESTDIR)$(etcdir)/$$config$$suffix; \
90 $(INSTALL) -m $$mode etc/$$config.default $(DESTDIR)$(etcdir)/$$config$$suffix; \
91 done
92
93 @for plugin in $(PLUGINS); \
94 do \
95 echo $(INSTALL) -m 0755 $$plugin $(DESTDIR)$(libdir)/$$plugin; \
96 $(INSTALL) -m 0755 $$plugin $(DESTDIR)$(libdir)/$$plugin; \
97 done
98
99 @if [ -z $(DESTDIR) ] && [ ! -e /dev/net/tun ]; \
100 then \
101 mkdir /dev/net; \
102 echo mknod /dev/net/tun c 10 200; \
103 mknod /dev/net/tun c 10 200; \
104 fi
105
106 .PHONY: all clean depend install
107
108 ## Dependencies: (autogenerated) ##
109 arp.o: arp.c l2tpns.h
110 cli.o: cli.c l2tpns.h constants.h util.h cluster.h tbf.h ll.h bgp.h \
111 l2tplac.h
112 cluster.o: cluster.c l2tpns.h cluster.h util.h tbf.h pppoe.h bgp.h
113 constants.o: constants.c constants.h
114 control.o: control.c l2tpns.h control.h
115 icmp.o: icmp.c l2tpns.h pppoe.h
116 l2tpns.o: l2tpns.c md5.h l2tpns.h cluster.h plugin.h ll.h constants.h \
117 control.h util.h tbf.h bgp.h l2tplac.h pppoe.h
118 ll.o: ll.c ll.h
119 md5.o: md5.c md5.h
120 ppp.o: ppp.c l2tpns.h constants.h plugin.h util.h tbf.h cluster.h \
121 l2tplac.h pppoe.h
122 radius.o: radius.c md5.h constants.h l2tpns.h plugin.h util.h cluster.h \
123 l2tplac.h pppoe.h
124 tbf.o: tbf.c l2tpns.h util.h tbf.h
125 util.o: util.c l2tpns.h bgp.h
126 pppoe.o: pppoe.c l2tpns.h cluster.h constants.h md5.h util.h
127 l2tplac.o: l2tplac.c md5.h l2tpns.h util.h cluster.h l2tplac.h pppoe.h
128 bgp.o: bgp.c l2tpns.h bgp.h util.h
129 autosnoop.so: autosnoop.c l2tpns.h plugin.h
130 autothrottle.so: autothrottle.c l2tpns.h plugin.h
131 garden.so: garden.c l2tpns.h plugin.h control.h
132 sessionctl.so: sessionctl.c l2tpns.h plugin.h control.h
133 setrxspeed.so: setrxspeed.c l2tpns.h plugin.h
134 snoopctl.so: snoopctl.c l2tpns.h plugin.h control.h
135 stripdomain.so: stripdomain.c l2tpns.h plugin.h
136 throttlectl.so: throttlectl.c l2tpns.h plugin.h control.h