Imported Upstream version 0.3.2
[anytun.git] / src / Makefile
1 ##
2 ##  anytun
3 ##
4 ##  The secure anycast tunneling protocol (satp) defines a protocol used
5 ##  for communication between any combination of unicast and anycast
6 ##  tunnel endpoints.  It has less protocol overhead than IPSec in Tunnel
7 ##  mode and allows tunneling of every ETHER TYPE protocol (e.g.
8 ##  ethernet, ip, arp ...). satp directly includes cryptography and
9 ##  message authentication based on the methodes used by SRTP.  It is
10 ##  intended to deliver a generic, scaleable and secure solution for
11 ##  tunneling and relaying of packets of any protocol.
12 ##
13 ##
14 ##  Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, 
15 ##                          Christian Pointner <satp@wirdorange.org>
16 ##
17 ##  This file is part of Anytun.
18 ##
19 ##  Anytun is free software: you can redistribute it and/or modify
20 ##  it under the terms of the GNU General Public License as published by
21 ##  the Free Software Foundation, either version 3 of the License, or
22 ##  any later version.
23 ##
24 ##  Anytun is distributed in the hope that it will be useful,
25 ##  but WITHOUT ANY WARRANTY; without even the implied warranty of
26 ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27 ##  GNU General Public License for more details.
28 ##
29 ##  You should have received a copy of the GNU General Public License
30 ##  along with anytun.  If not, see <http://www.gnu.org/licenses/>.
31 ##
32
33 ifneq ($(MAKECMDGOALS),distclean)
34 include include.mk
35 endif
36
37 OBJS := tunDevice.o \
38         packetSource.o \
39         buffer.o \
40         syncBuffer.o \
41         plainPacket.o \
42         encryptedPacket.o \
43         cipher.o \
44         authAlgo.o \
45         keyDerivation.o \
46         cipherFactory.o \
47         authAlgoFactory.o \
48         keyDerivationFactory.o \
49         connectionList.o \
50         connectionParam.o \
51         networkAddress.o \
52         networkPrefix.o \
53         routingTable.o \
54         signalController.o \
55         log.o \
56         logTargets.o \
57         sysExec.o \
58         anytunError.o \
59         options.o \
60         seqWindow.o \
61         routingTreeNode.o \
62         resolver.o
63
64 SYNCOBJS := syncServer.o \
65             syncClient.o \
66             syncQueue.o \
67             syncCommand.o \
68             syncRouteCommand.o \
69             syncConnectionCommand.o \
70             syncTcpConnection.o
71
72 ANYCTROBJS := signalController.o \
73               anyCtrOptions.o \
74               buffer.o \
75               log.o \
76               logTargets.o \
77               anytunError.o \
78               syncTcpConnection.o \
79               syncServer.o \
80               resolver.o
81
82 ANYCONFOBJS := log.o \
83                logTargets.o \
84                anytunError.o \
85                buffer.o \
86                keyDerivation.o \
87                keyDerivationFactory.o \
88                networkAddress.o \
89                networkPrefix.o \
90                connectionList.o \
91                connectionParam.o \
92                routingTreeNode.o \
93                anyConfOptions.o \
94                routingTable.o \
95                seqWindow.o \
96                syncQueue.o \
97                syncBuffer.o \
98                syncCommand.o \
99                syncServer.o \
100                syncTcpConnection.o \
101                syncRouteCommand.o \
102                syncConnectionCommand.o \
103                resolver.o
104
105 EXECUTABLES := anytun anytun-config anytun-controld anytun-showtables anytun-nosync
106 EXEOBJS := anytun.o anytun-config.o anytun-controld.o anytun-showtables.o
107
108 SRCS := $(OBJS:%.o=%.cpp)
109 SYNCSRCS := $(SYNCOBJS:%.o=%.cpp)
110 ANYCTRSRCS := $(ANYCTROBJS:%.o=%.cpp)
111 ANYCONFSRCS := $(ANYCONFOBJS:%.o=%.cpp)
112 EXESRCS := $(EXEOBJS:%.o=%.cpp)
113
114 .PHONY: distclean cleanall clean manpage install install-bin install-etc install-man uninstall remove purge
115
116 all: $(EXECUTABLES) #libAnysync.a 
117
118 %.d: %.cpp
119         @set -e; rm -f $@;                                    \
120    $(CXX) -MM $(CXXFLAGS) $< > $@.$$$$;                 \
121    sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@;  \
122    rm -f $@.$$$$; echo '(re)building $@'
123
124 ifneq ($(MAKECMDGOALS),distclean)
125 -include $(SRCS:%.cpp=%.d) $(SYNCSRCS:%.cpp=%.d) $(ANYCTRSRCS:%.cpp=%.d) $(ANYCONFSRCS:%.cpp=%.d) $(EXESRCS:%.cpp=%.d)
126 endif
127
128 strip: $(EXECUTABLES)
129         $(STRIP) -s $(EXECUTABLES) 
130
131 anytun: $(OBJS) $(SYNCOBJS) anytun.o
132         $(LD) $(OBJS) $(SYNCOBJS) anytun.o -o $@ $(LDFLAGS)
133
134 anytun-static: $(OBJS) $(SYNCOBJS) anytun-noprivdrop.o
135         $(LD) $(OBJS) $(SYNCOBJS) anytun-noprivdrop.o -o $@ -Bstatic -lstdc++ -static $(LDFLAGS) -lpthread
136         $(STRIP) -s anytun-static
137
138 anytun-nosync: $(OBJS) anytun-nosync.o
139         $(LD) $(OBJS) anytun-nosync.o -o $@ $(LDFLAGS)
140
141 anytun-nosync.o: anytun.cpp
142         $(CXX) $(CXXFLAGS) -DANYTUN_NOSYNC $< -c -o anytun-nosync.o
143
144 anytun-noprivdrop.o: anytun.cpp
145         $(CXX) $(CXXFLAGS) -DNO_PRIVDROP $< -c -o anytun-noprivdrop.o
146
147 anytun-showtables: $(OBJS) $(SYNCOBJS) anytun-showtables.o
148         $(LD) $(OBJS) $(SYNCOBJS) anytun-showtables.o -o $@ $(LDFLAGS)
149
150 anytun-config: $(ANYCONFOBJS) anytun-config.o
151         $(LD) $(ANYCONFOBJS) anytun-config.o -o $@ $(LDFLAGS)
152
153 anytun-controld: $(ANYCTROBJS) anytun-controld.o
154         $(LD) $(ANYCTROBJS) anytun-controld.o -o $@ $(LDFLAGS)
155
156
157 options.o: options.cpp 
158         $(CXX) $(CXXFLAGS) -DANYTUN_OPTIONS $< -c -o $@
159
160 anyCtrOptions.o: options.cpp 
161         $(CXX) $(CXXFLAGS) -DANYCTR_OPTIONS $< -c -o $@
162
163 anyConfOptions.o: options.cpp 
164         $(CXX) $(CXXFLAGS) -DANYCONF_OPTIONS $< -c -o $@
165
166 %.o: %.cpp
167         $(CXX) $(CXXFLAGS) $< -c
168
169
170 libAnysync.a: $(OBJS)
171         ar cru $@ $(OBJS)
172         ranlib $@
173
174 anyrtpproxy: anytun
175         $(MAKE) --directory=$(CURDIR)/anyrtpproxy
176
177
178 distclean: cleanall
179         find . -name *.o -exec rm -f {} \;
180         rm -f config.sub config.guess
181         rm -f tunDevice.cpp
182         rm -f include.mk
183
184 cleanall: clean
185         $(MAKE) --directory=$(CURDIR)/man clean
186
187 clean:
188         rm -f *.o
189         rm -f *.d
190         rm -f *.d.*
191         rm -f $(EXECUTABLES)
192         rm -f anytun-nosync
193         rm -f -r doc/html/*
194         rm -f -r doc/latex/*
195         rm -f libAnysync.a
196         $(MAKE) --directory=$(CURDIR)/anyrtpproxy clean
197
198 manpage:
199         @cd man ; $(MAKE)
200
201
202 INSTALL_TARGETS := install-bin install-etc
203 REMOVE_TARGETS := remove-bin remove-etc
204
205 ifdef MANDIR
206 INSTALL_TARGETS += install-man
207 REMOVE_TARGETS += remove-man
208 endif
209
210 ifdef EXAMPLESDIR
211 INSTALL_TARGETS += install-examples
212 REMOVE_TARGETS += remove-examples
213 endif
214
215 install: all $(INSTALL_TARGETS)
216
217 install-bin: $(EXECUTABLES)
218         $(INSTALL) -d $(DESTDIR)$(SBINDIR)
219         $(INSTALL) -m 755 anytun $(DESTDIR)$(SBINDIR)
220         $(INSTALL) -d $(DESTDIR)$(BINDIR)
221         $(INSTALL) -m 755 anytun-config $(DESTDIR)$(BINDIR)
222         $(INSTALL) -m 755 anytun-controld $(DESTDIR)$(BINDIR)
223         $(INSTALL) -m 755 anytun-showtables $(DESTDIR)$(BINDIR)
224
225 install-etc:
226         $(INSTALL) -d $(DESTDIR)$(ETCDIR)/anytun
227         @ echo "example configurations can be found at $(EXAMPLESDIR)/anytun" > $(DESTDIR)$(ETCDIR)/anytun/README
228         $(INSTALL) -d $(DESTDIR)$(ETCDIR)/init.d
229         @ sed -e 's#DAEMON=/usr/sbin/anytun#DAEMON=$(SBINDIR)/anytun#'                               \
230         -e 's#ANYTUNCONFIG=/usr/bin/anytun-config#ANYTUNCONFIG=$(BINDIR)/anytun-config#'       \
231         -e 's#CONTROLDAEMON=/usr/bin/anytun-controld#CONTROLDAEMON=$(BINDIR)/anytun-controld#' \
232         -e 's#CONFIG_DIR=/etc/anytun#CONFIG_DIR=$(ETCDIR)/anytun#' ../etc/init.d/anytun > ../etc/init.d/anytun.bak
233         $(INSTALL) -m 755 ../etc/init.d/anytun.bak $(DESTDIR)$(ETCDIR)/init.d/anytun
234         rm -f ../etc/init.d/anytun.bak
235
236 install-examples:
237         $(INSTALL) -d $(DESTDIR)$(EXAMPLESDIR)/anytun
238         $(INSTALL) -m 644 ../etc/anytun/autostart $(DESTDIR)$(EXAMPLESDIR)/anytun/autostart
239         @( cd '../etc/anytun/' ;                                                                   \
240      for dir in `ls`; do                                                                     \
241        if [ -d $$dir ]; then                                                                 \
242          echo "install $$dir configuration" ;                                                \
243          cd $$dir ;                                                                          \
244          $(INSTALL) -d $(DESTDIR)$(EXAMPLESDIR)/anytun/$$dir ;                               \
245          $(INSTALL) -m 600 config $(DESTDIR)$(EXAMPLESDIR)/anytun/$$dir/config ;             \
246          if [ -e 'post-up.sh' ]; then                                                        \
247            $(INSTALL) -m 755 post-up.sh $(DESTDIR)$(EXAMPLESDIR)/anytun/$$dir/post-up.sh ;   \
248          fi ;                                                                                \
249          if [ -d 'conf.d' ]; then                                                            \
250            $(INSTALL) -d $(DESTDIR)$(EXAMPLESDIR)/anytun/$$dir/conf.d ;                      \
251            cd conf.d ;                                                                       \
252            for file in `ls`; do                                                              \
253              if [ -f $$file ]; then                                                          \
254                $(INSTALL) -m 644 $$file $(DESTDIR)$(EXAMPLESDIR)/anytun/$$dir/conf.d ;       \
255              fi ;                                                                            \
256            done ;                                                                            \
257            cd .. ;                                                                           \
258          fi ;                                                                                \
259          cd .. ;                                                                             \
260        fi ;                                                                                  \
261      done                                                                                    \
262    )
263
264 install-man: manpage
265         $(INSTALL) -d $(DESTDIR)$(MANDIR)/man8/
266         $(INSTALL) -m 644 man/anytun.8 $(DESTDIR)$(MANDIR)/man8/
267         $(INSTALL) -m 644 man/anytun-config.8 $(DESTDIR)$(MANDIR)/man8/
268         $(INSTALL) -m 644 man/anytun-controld.8 $(DESTDIR)$(MANDIR)/man8/
269         $(INSTALL) -m 644 man/anytun-showtables.8 $(DESTDIR)$(MANDIR)/man8/
270
271 uninstall: remove
272
273
274 remove: $(REMOVE_TARGETS)
275
276 remove-bin:
277         rm -f $(DESTDIR)$(SBINDIR)/anytun
278         rm -f $(DESTDIR)$(BINDIR)/anytun-config
279         rm -f $(DESTDIR)$(BINDIR)/anytun-controld
280         rm -f $(DESTDIR)$(BINDIR)/anytun-showtables
281
282 remove-etc:
283         rm -f $(DESTDIR)$(ETCDIR)/init.d/anytun
284
285 remove-examples:
286         rm -rf $(DESTDIR)$(EXAMPLESDIR)/anytun/
287
288 remove-man:
289         rm -f $(DESTDIR)$(MANDIR)/man8/anytun.8
290         rm -f $(DESTDIR)$(MANDIR)/man8/anytun-config.8
291         rm -f $(DESTDIR)$(MANDIR)/man8/anytun-controld.8
292         rm -f $(DESTDIR)$(MANDIR)/man8/anytun-showtables.8
293
294 purge: remove
295         rm -rf $(DESTDIR)$(ETCDIR)/anytun/