Imported Upstream version 0.3.3
[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
38 ANYTUNOBJS := tunDevice.o \
39               packetSource.o \
40               authAlgo.o \
41               authAlgoFactory.o \
42               cipher.o \
43               cipherFactory.o \
44               plainPacket.o \
45               encryptedPacket.o \
46               options.o \
47               signalController.o \
48               daemonService.o \
49               sysExec.o \
50               resolver.o \
51               buffer.o \
52               syncBuffer.o \
53               keyDerivation.o \
54               keyDerivationFactory.o \
55               connectionList.o \
56               connectionParam.o \
57               networkAddress.o \
58               networkPrefix.o \
59               routingTable.o \
60               routingTreeNode.o \
61               log.o \
62               logTargets.o \
63               anytunError.o \
64               seqWindow.o
65
66 ANYSHOWOBJS := buffer.o \
67                syncBuffer.o \
68                keyDerivation.o \
69                keyDerivationFactory.o \
70                connectionList.o \
71                connectionParam.o \
72                networkAddress.o \
73                networkPrefix.o \
74                routingTable.o \
75                routingTreeNode.o \
76                log.o \
77                logTargets.o \
78                anytunError.o \
79                seqWindow.o \
80                nullOptions.o \
81                resolver.o
82
83 SYNCOBJS := syncServer.o \
84             syncClient.o \
85             syncQueue.o \
86             syncCommand.o \
87             syncRouteCommand.o \
88             syncConnectionCommand.o \
89             syncTcpConnection.o
90
91 ANYCTROBJS := signalController.o \
92               daemonService.o \
93               anyCtrOptions.o \
94               buffer.o \
95               log.o \
96               logTargets.o \
97               anytunError.o \
98               syncTcpConnection.o \
99               syncServer.o \
100               resolver.o
101
102 ANYCONFOBJS := log.o \
103                logTargets.o \
104                anytunError.o \
105                buffer.o \
106                keyDerivation.o \
107                keyDerivationFactory.o \
108                networkAddress.o \
109                networkPrefix.o \
110                connectionList.o \
111                connectionParam.o \
112                routingTreeNode.o \
113                anyConfOptions.o \
114                routingTable.o \
115                seqWindow.o \
116                syncQueue.o \
117                syncBuffer.o \
118                syncCommand.o \
119                syncServer.o \
120                syncTcpConnection.o \
121                syncRouteCommand.o \
122                syncConnectionCommand.o \
123                resolver.o
124
125 EXECUTABLES := anytun anytun-config anytun-controld anytun-showtables anytun-nosync
126 EXEOBJS := anytun.o anytun-config.o anytun-controld.o anytun-showtables.o
127
128 ANYTUNSRCS := $(ANYTUNOBJS:%.o=%.cpp)
129 ANYSHOWSRCS := $(ANYSHOWOBJS:%.o=%.cpp)
130 SYNCSRCS := $(SYNCOBJS:%.o=%.cpp)
131 ANYCTRSRCS := $(ANYCTROBJS:%.o=%.cpp)
132 ANYCONFSRCS := $(ANYCONFOBJS:%.o=%.cpp)
133 EXESRCS := $(EXEOBJS:%.o=%.cpp)
134
135 .PHONY: distclean cleanall clean manpage install install-bin install-etc install-man uninstall remove purge
136
137 all: $(EXECUTABLES) #libAnysync.a 
138
139 %.d: %.cpp
140         @set -e; rm -f $@;                                    \
141    $(CXX) -MM $(CXXFLAGS) $< > $@.$$$$;                 \
142    sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@;  \
143    rm -f $@.$$$$; echo '(re)building $@'
144
145 ifneq ($(MAKECMDGOALS),distclean)
146 -include $(ANYTUNSRCS:%.cpp=%.d) $(ANYSHOWSRCS:%.cpp=%.d) $(SYNCSRCS:%.cpp=%.d) $(ANYCTRSRCS:%.cpp=%.d) $(ANYCONFSRCS:%.cpp=%.d) $(EXESRCS:%.cpp=%.d)
147 endif
148
149 strip: $(EXECUTABLES)
150         $(STRIP) -s $(EXECUTABLES) 
151
152 anytun: $(ANYTUNOBJS) $(SYNCOBJS) anytun.o
153         $(LD) $(ANYTUNOBJS) $(SYNCOBJS) anytun.o -o $@ $(LDFLAGS)
154
155 anytun-static: $(ANYTUNOBJS) $(SYNCOBJS) anytun-noprivdrop.o
156         $(LD) $(ANYTUNOBJS) $(SYNCOBJS) anytun-noprivdrop.o -o $@ -Bstatic -lstdc++ -static $(LDFLAGS) -lpthread
157         $(STRIP) -s anytun-static
158
159 anytun-nosync: $(ANYTUNOBJS) anytun-nosync.o
160         $(LD) $(ANYTUNOBJS) anytun-nosync.o -o $@ $(LDFLAGS)
161
162 anytun-nosync.o: anytun.cpp
163         $(CXX) $(CXXFLAGS) -DANYTUN_NOSYNC $< -c -o anytun-nosync.o
164
165 anytun-showtables: $(ANYSHOWOBJS) $(SYNCOBJS) anytun-showtables.o
166         $(LD) $(ANYSHOWOBJS) $(SYNCOBJS) anytun-showtables.o -o $@ $(LDFLAGS)
167
168 anytun-config: $(ANYCONFOBJS) anytun-config.o
169         $(LD) $(ANYCONFOBJS) anytun-config.o -o $@ $(LDFLAGS)
170
171 anytun-controld: $(ANYCTROBJS) anytun-controld.o
172         $(LD) $(ANYCTROBJS) anytun-controld.o -o $@ $(LDFLAGS)
173
174
175 options.o: options.cpp 
176         $(CXX) $(CXXFLAGS) -DANYTUN_OPTIONS $< -c -o $@
177
178 anyCtrOptions.o: options.cpp 
179         $(CXX) $(CXXFLAGS) -DANYCTR_OPTIONS $< -c -o $@
180
181 anyConfOptions.o: options.cpp 
182         $(CXX) $(CXXFLAGS) -DANYCONF_OPTIONS $< -c -o $@
183
184 nullOptions.o: options.cpp
185         $(CXX) $(CXXFLAGS) $< -c -o $@
186
187 %.o: %.cpp
188         $(CXX) $(CXXFLAGS) $< -c
189
190
191 libAnysync.a: $(OBJS)
192         ar cru $@ $(OBJS)
193         ranlib $@
194
195 anyrtpproxy: anytun
196         $(MAKE) --directory=$(CURDIR)/anyrtpproxy
197
198
199 distclean: cleanall
200         find . -name *.o -exec rm -f {} \;
201         rm -f config.sub config.guess
202         rm -f daemonService.h
203         rm -f daemonService.cpp
204         rm -f signalHandler.hpp
205         rm -f sysExec.hpp
206         rm -f version.h
207         rm -f tunDevice.cpp
208         rm -f include.mk
209
210 cleanall: clean
211         $(MAKE) --directory="../doc" clean
212
213 clean:
214         rm -f *.o
215         rm -f *.d
216         rm -f *.d.*
217         rm -f $(EXECUTABLES)
218         rm -f anytun-nosync
219         rm -f -r doc/html/*
220         rm -f -r doc/latex/*
221         rm -f libAnysync.a
222         $(MAKE) --directory=$(CURDIR)/anyrtpproxy clean
223
224 manpage:
225         $(MAKE) --directory="../doc" manpage
226
227
228 INSTALL_TARGETS := install-bin install-etc
229 REMOVE_TARGETS := remove-bin remove-etc
230
231 ifdef MANDIR
232 INSTALL_TARGETS += install-man
233 REMOVE_TARGETS += remove-man
234 endif
235
236 ifdef EXAMPLESDIR
237 INSTALL_TARGETS += install-examples
238 REMOVE_TARGETS += remove-examples
239 endif
240
241 install: all $(INSTALL_TARGETS)
242
243 install-bin: $(EXECUTABLES)
244         $(INSTALL) -d $(DESTDIR)$(SBINDIR)
245         $(INSTALL) -m 755 anytun $(DESTDIR)$(SBINDIR)
246         $(INSTALL) -d $(DESTDIR)$(BINDIR)
247         $(INSTALL) -m 755 anytun-config $(DESTDIR)$(BINDIR)
248         $(INSTALL) -m 755 anytun-controld $(DESTDIR)$(BINDIR)
249         $(INSTALL) -m 755 anytun-showtables $(DESTDIR)$(BINDIR)
250
251 install-etc:
252         $(INSTALL) -d $(DESTDIR)$(ETCDIR)/anytun
253         @ echo "example configurations can be found at $(EXAMPLESDIR)/anytun" > $(DESTDIR)$(ETCDIR)/anytun/README
254         $(INSTALL) -d $(DESTDIR)$(ETCDIR)/init.d
255         @ sed -e 's#DAEMON=/usr/sbin/anytun#DAEMON=$(SBINDIR)/anytun#'                               \
256         -e 's#ANYTUNCONFIG=/usr/bin/anytun-config#ANYTUNCONFIG=$(BINDIR)/anytun-config#'       \
257         -e 's#CONTROLDAEMON=/usr/bin/anytun-controld#CONTROLDAEMON=$(BINDIR)/anytun-controld#' \
258         -e 's#CONFIG_DIR=/etc/anytun#CONFIG_DIR=$(ETCDIR)/anytun#' ../etc/init.d/anytun > ../etc/init.d/anytun.bak
259         $(INSTALL) -m 755 ../etc/init.d/anytun.bak $(DESTDIR)$(ETCDIR)/init.d/anytun
260         rm -f ../etc/init.d/anytun.bak
261
262 install-examples:
263         $(INSTALL) -d $(DESTDIR)$(EXAMPLESDIR)/anytun
264         $(INSTALL) -m 644 ../etc/anytun/autostart $(DESTDIR)$(EXAMPLESDIR)/anytun/autostart
265         @( cd '../etc/anytun/' ;                                                                   \
266      for dir in `ls`; do                                                                     \
267        if [ -d $$dir ]; then                                                                 \
268          echo "install $$dir configuration" ;                                                \
269          cd $$dir ;                                                                          \
270          $(INSTALL) -d $(DESTDIR)$(EXAMPLESDIR)/anytun/$$dir ;                               \
271          $(INSTALL) -m 600 config $(DESTDIR)$(EXAMPLESDIR)/anytun/$$dir/config ;             \
272          if [ -e 'post-up.sh' ]; then                                                        \
273            $(INSTALL) -m 755 post-up.sh $(DESTDIR)$(EXAMPLESDIR)/anytun/$$dir/post-up.sh ;   \
274          fi ;                                                                                \
275          if [ -d 'conf.d' ]; then                                                            \
276            $(INSTALL) -d $(DESTDIR)$(EXAMPLESDIR)/anytun/$$dir/conf.d ;                      \
277            cd conf.d ;                                                                       \
278            for file in `ls`; do                                                              \
279              if [ -f $$file ]; then                                                          \
280                $(INSTALL) -m 600 $$file $(DESTDIR)$(EXAMPLESDIR)/anytun/$$dir/conf.d ;       \
281              fi ;                                                                            \
282            done ;                                                                            \
283            cd .. ;                                                                           \
284          fi ;                                                                                \
285          cd .. ;                                                                             \
286        fi ;                                                                                  \
287      done                                                                                    \
288    )
289
290 install-man: manpage
291         $(INSTALL) -d $(DESTDIR)$(MANDIR)/man8/
292         $(INSTALL) -m 644 ../doc/anytun.8 $(DESTDIR)$(MANDIR)/man8/
293         $(INSTALL) -m 644 ../doc/anytun-config.8 $(DESTDIR)$(MANDIR)/man8/
294         $(INSTALL) -m 644 ../doc/anytun-controld.8 $(DESTDIR)$(MANDIR)/man8/
295         $(INSTALL) -m 644 ../doc/anytun-showtables.8 $(DESTDIR)$(MANDIR)/man8/
296
297 uninstall: remove
298
299
300 remove: $(REMOVE_TARGETS)
301
302 remove-bin:
303         rm -f $(DESTDIR)$(SBINDIR)/anytun
304         rm -f $(DESTDIR)$(BINDIR)/anytun-config
305         rm -f $(DESTDIR)$(BINDIR)/anytun-controld
306         rm -f $(DESTDIR)$(BINDIR)/anytun-showtables
307
308 remove-etc:
309         rm -f $(DESTDIR)$(ETCDIR)/init.d/anytun
310
311 remove-examples:
312         rm -rf $(DESTDIR)$(EXAMPLESDIR)/anytun/
313
314 remove-man:
315         rm -f $(DESTDIR)$(MANDIR)/man8/anytun.8
316         rm -f $(DESTDIR)$(MANDIR)/man8/anytun-config.8
317         rm -f $(DESTDIR)$(MANDIR)/man8/anytun-controld.8
318         rm -f $(DESTDIR)$(MANDIR)/man8/anytun-showtables.8
319
320 purge: remove
321         rm -rf $(DESTDIR)$(ETCDIR)/anytun/