version bump
[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 += -DSTATISTICS
11 DEFINES += -DSTAT_CALLS
12 DEFINES += -DRINGBUFFER
13 DEFINES += -DBGP
14 DEFINES += -DLIBDIR='"$(libdir)"'
15 DEFINES += -DETCDIR='"$(etcdir)"'
16 DEFINES += -DSTATEDIR='"$(statedir)"'
17
18 OPTIM = -g
19 OPTIM += -O3
20 OPTIM += -funroll-loops
21 OPTIM += -fomit-frame-pointer
22 OPTIM += -finline-functions
23 #OPTIM += -fstrength-reduce
24
25 CC = gcc
26 LD = gcc
27 INCLUDES = -I.
28 CPPFLAGS = $(INCLUDES) $(DEFINES)
29 CFLAGS = -Wall $(OPTIM)
30 LDFLAGS =
31 LDLIBS =
32 INSTALL = install -c -D -o root -g root
33
34 l2tpns.LIBS = -lm -lcli -ldl
35
36 OBJS = arp.o bgp.o cli.o cluster.o constants.o control.o icmp.o \
37 l2tpns.o ll.o md5.o ppp.o radius.o tbf.o util.o
38
39 PROGRAMS = l2tpns nsctl
40 PLUGINS = garden.so throttlectl.so autothrottle.so snoopctl.so \
41 autosnoop.so stripdomain.so setrxspeed.so
42
43 TESTS = generateload bounce
44
45 all: programs plugins tests
46 programs: $(PROGRAMS)
47 plugins: $(PLUGINS)
48 tests: $(TESTS)
49
50 clean:
51 rm -f *.o test/*.o $(PROGRAMS) $(PLUGINS) $(TESTS) Makefile.tmp Makefile.bak
52
53 depend:
54 (sed -n 'p; /^## Dependencies: (autogenerated) ##/q' Makefile && \
55 gcc -MM $(CPPFLAGS) $(OBJS:.o=.c) && \
56 gcc -MM $(CPPFLAGS) $(PLUGINS:.so=.c) | sed 's/\.o/.so/') >Makefile.tmp
57 mv Makefile Makefile.bak
58 mv Makefile.tmp Makefile
59
60 l2tpns: $(OBJS)
61 $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) $($@.LIBS)
62
63 nsctl: nsctl.o control.o
64 $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) $($@.LIBS)
65
66 generateload: test/generateload.o
67 $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) $($@.LIBS)
68
69 bounce: test/bounce.o
70 $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS) $($@.LIBS)
71
72 %.o: %.c
73 $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
74
75 %.so: %.c
76 $(CC) -fPIC -shared $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -o $@ $<
77
78 # install config files only if a startup-config does not exist yet
79 # this does not interfere when building rpms or debs and makes
80 # fast upgrading via make install possible
81
82 install: all
83 $(INSTALL) -m 0755 l2tpns $(DESTDIR)$(bindir)/l2tpns
84 $(INSTALL) -m 0755 nsctl $(DESTDIR)$(bindir)/nsctl
85
86 $(INSTALL) -m 0644 Docs/startup-config.5 $(DESTDIR)$(man5dir)/startup-config.5
87 $(INSTALL) -m 0644 Docs/l2tpns.8 $(DESTDIR)$(man8dir)/l2tpns.8
88 $(INSTALL) -m 0644 Docs/nsctl.8 $(DESTDIR)$(man8dir)/nsctl.8
89
90 gzip $(DESTDIR)$(man5dir)/*.5 $(DESTDIR)$(man8dir)/*.8
91
92 @if [ -f $(DESTDIR)$(etcdir)/startup-config ]; then \
93 echo '***' Installing default config files in $(DESTDIR)$(etcdir) as .defaults; \
94 suffix=.default; \
95 else \
96 echo '***' Installing default config files in $(DESTDIR)$(etcdir) - remember to adjust them; \
97 suffix=; \
98 fi; \
99
100 $(INSTALL) -m 0600 etc/startup-config.default $(DESTDIR)$(etcdir)/startup-config$$suffix; \
101 $(INSTALL) -m 0644 etc/ip_pool.default $(DESTDIR)$(etcdir)/ip_pool$$suffix; \
102 $(INSTALL) -m 0600 etc/users.default $(DESTDIR)$(etcdir)/users$$suffix
103
104 for plugin in $(PLUGINS); do \
105 $(INSTALL) -m 0755 $$plugin $(DESTDIR)$(libdir)/$$plugin; \
106 done
107
108 if [ -z $(DESTDIR) ] && [ ! -e /dev/net/tun ]; then \
109 mkdir /dev/net; \
110 mknod /dev/net/tun c 10 200; \
111 fi
112
113 .PHONY: all clean depend install
114
115 ## Dependencies: (autogenerated) ##
116 arp.o: arp.c l2tpns.h
117 bgp.o: bgp.c l2tpns.h bgp.h util.h
118 cli.o: cli.c l2tpns.h util.h cluster.h tbf.h ll.h bgp.h
119 cluster.o: cluster.c l2tpns.h cluster.h util.h tbf.h bgp.h
120 constants.o: constants.c constants.h
121 control.o: control.c l2tpns.h control.h
122 icmp.o: icmp.c l2tpns.h
123 l2tpns.o: l2tpns.c md5.h l2tpns.h cluster.h plugin.h ll.h constants.h \
124 control.h util.h tbf.h bgp.h
125 ll.o: ll.c ll.h
126 md5.o: md5.c md5.h
127 ppp.o: ppp.c l2tpns.h constants.h plugin.h util.h tbf.h cluster.h
128 radius.o: radius.c md5.h constants.h l2tpns.h plugin.h util.h
129 tbf.o: tbf.c l2tpns.h util.h tbf.h
130 util.o: util.c l2tpns.h bgp.h
131 garden.so: garden.c l2tpns.h plugin.h control.h
132 throttlectl.so: throttlectl.c l2tpns.h plugin.h control.h
133 autothrottle.so: autothrottle.c l2tpns.h plugin.h
134 snoopctl.so: snoopctl.c l2tpns.h plugin.h control.h
135 autosnoop.so: autosnoop.c l2tpns.h plugin.h
136 stripdomain.so: stripdomain.c l2tpns.h plugin.h
137 setrxspeed.so: setrxspeed.c l2tpns.h plugin.h