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