New upstream version 0.3.6
[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 methods 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-2014 Markus Grüneis, 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 ##  In addition, as a special exception, the copyright holders give
33 ##  permission to link the code of portions of this program with the
34 ##  OpenSSL library under certain conditions as described in each
35 ##  individual source file, and distribute linked combinations
36 ##  including the two.
37 ##  You must obey the GNU General Public License in all respects
38 ##  for all of the code used other than OpenSSL.  If you modify
39 ##  file(s) with this exception, you may extend this exception to your
40 ##  version of the file(s), but you are not obligated to do so.  If you
41 ##  do not wish to do so, delete this exception statement from your
42 ##  version.  If you delete this exception statement from all source
43 ##  files in the program, then also delete it here.
44 ##
45
46 ifneq ($(MAKECMDGOALS),distclean)
47 include include.mk
48 endif
49
50 ANYTUNOBJS := packetSource.o \
51               authAlgo.o \
52               authAlgoFactory.o \
53               cipher.o \
54               cipherFactory.o \
55               plainPacket.o \
56               encryptedPacket.o \
57               options.o \
58               signalController.o \
59               sysExec.o \
60               resolver.o \
61               buffer.o \
62               syncBuffer.o \
63               keyDerivation.o \
64               keyDerivationFactory.o \
65               connectionList.o \
66               connectionParam.o \
67               networkAddress.o \
68               networkPrefix.o \
69               routingTable.o \
70               routingTreeNode.o \
71               log.o \
72               logTargets.o \
73               anytunError.o \
74               seqWindow.o
75
76 ifneq ($(TARGET),mingw)
77 ANYTUNOBJS := $(ANYTUNOBJS) \
78               tunDevice.o \
79               daemonService.o
80 else
81 ANYTUNOBJS := $(ANYTUNOBJS) \
82               win32/tunDevice.o \
83               nullDaemon.o \
84               win32/winService.o \
85               win32/registryKey.o
86 endif
87
88
89 ANYSHOWOBJS := buffer.o \
90                syncBuffer.o \
91                keyDerivation.o \
92                keyDerivationFactory.o \
93                connectionList.o \
94                connectionParam.o \
95                networkAddress.o \
96                networkPrefix.o \
97                routingTable.o \
98                routingTreeNode.o \
99                log.o \
100                logTargets.o \
101                anytunError.o \
102                seqWindow.o \
103                nullOptions.o \
104                resolver.o
105
106
107 SYNCOBJS := syncServer.o \
108             syncClient.o \
109             syncQueue.o \
110             syncCommand.o \
111             syncRouteCommand.o \
112             syncConnectionCommand.o \
113             syncTcpConnection.o
114
115
116 ANYCTROBJS := signalController.o \
117               anyCtrOptions.o \
118               buffer.o \
119               log.o \
120               logTargets.o \
121               anytunError.o \
122               syncTcpConnection.o \
123               syncServer.o \
124               resolver.o
125
126 ifneq ($(TARGET),mingw)
127 ANYCTROBJS := $(ANYCTROBJS) \
128               daemonService.o
129 else
130 ANYCTROBJS := $(ANYCTROBJS) \
131               nullDaemon.o
132 endif
133
134
135 ANYCONFOBJS := log.o \
136                logTargets.o \
137                anytunError.o \
138                buffer.o \
139                keyDerivation.o \
140                keyDerivationFactory.o \
141                networkAddress.o \
142                networkPrefix.o \
143                connectionList.o \
144                connectionParam.o \
145                routingTreeNode.o \
146                anyConfOptions.o \
147                routingTable.o \
148                seqWindow.o \
149                syncQueue.o \
150                syncBuffer.o \
151                syncCommand.o \
152                syncServer.o \
153                syncTcpConnection.o \
154                syncRouteCommand.o \
155                syncConnectionCommand.o \
156                resolver.o
157
158 ifneq ($(TARGET),mingw)
159   EXE :=
160 else
161   EXE := .exe
162 endif
163
164 EXECUTABLES := anytun$(EXE) anytun-config$(EXE) anytun-controld$(EXE) anytun-showtables$(EXE) anytun-nosync$(EXE)
165 EXEOBJS := anytun.o anytun-config.o anytun-controld.o anytun-showtables.o
166
167 ANYTUNSRCS := $(ANYTUNOBJS:%.o=%.cpp)
168 ANYSHOWSRCS := $(ANYSHOWOBJS:%.o=%.cpp)
169 SYNCSRCS := $(SYNCOBJS:%.o=%.cpp)
170 ANYCTRSRCS := $(ANYCTROBJS:%.o=%.cpp)
171 ANYCONFSRCS := $(ANYCONFOBJS:%.o=%.cpp)
172 EXESRCS := $(EXEOBJS:%.o=%.cpp)
173
174 .PHONY: distclean cleanall clean manpage install install-bin install-etc install-man uninstall remove purge remove-systemd install-systemd remove-bin remove-man remove-examples
175
176 all: $(EXECUTABLES) #libAnysync.a
177
178 %.d: %.cpp
179         @set -e; rm -f $@;                                    \
180    $(CXX) -MM $(CXXFLAGS) $< > $@.$$$$;                 \
181    sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@;  \
182    rm -f $@.$$$$; echo '(re)building $@'
183
184 ifneq ($(MAKECMDGOALS),distclean)
185 -include $(ANYTUNSRCS:%.cpp=%.d) $(ANYSHOWSRCS:%.cpp=%.d) $(SYNCSRCS:%.cpp=%.d) $(ANYCTRSRCS:%.cpp=%.d) $(ANYCONFSRCS:%.cpp=%.d) $(EXESRCS:%.cpp=%.d)
186 endif
187
188 strip: $(EXECUTABLES)
189         $(STRIP) -s $(EXECUTABLES)
190
191 anytun$(EXE): $(ANYTUNOBJS) $(SYNCOBJS) anytun.o
192         $(LD) $(ANYTUNOBJS) $(SYNCOBJS) anytun.o -o $@ $(LDFLAGS)
193
194 anytun-static: $(ANYTUNOBJS) $(SYNCOBJS) anytun-noprivdrop.o
195         $(LD) $(ANYTUNOBJS) $(SYNCOBJS) anytun-noprivdrop.o -o $@ -Bstatic -lstdc++ -static $(LDFLAGS) -lpthread
196         $(STRIP) -s anytun-static
197
198 anytun-nosync$(EXE): $(ANYTUNOBJS) anytun-nosync.o
199         $(LD) $(ANYTUNOBJS) anytun-nosync.o -o $@ $(LDFLAGS)
200
201 anytun-nosync.o: anytun.cpp
202         $(CXX) $(CXXFLAGS) -DANYTUN_NOSYNC $< -c -o anytun-nosync.o
203
204 anytun-showtables$(EXE): $(ANYSHOWOBJS) $(SYNCOBJS) anytun-showtables.o
205         $(LD) $(ANYSHOWOBJS) $(SYNCOBJS) anytun-showtables.o -o $@ $(LDFLAGS)
206
207 anytun-config$(EXE): $(ANYCONFOBJS) anytun-config.o
208         $(LD) $(ANYCONFOBJS) anytun-config.o -o $@ $(LDFLAGS)
209
210 anytun-controld$(EXE): $(ANYCTROBJS) anytun-controld.o
211         $(LD) $(ANYCTROBJS) anytun-controld.o -o $@ $(LDFLAGS)
212
213
214 options.o: options.cpp
215         $(CXX) $(CXXFLAGS) -DANYTUN_OPTIONS $< -c -o $@
216
217 anyCtrOptions.o: options.cpp
218         $(CXX) $(CXXFLAGS) -DANYCTR_OPTIONS $< -c -o $@
219
220 anyConfOptions.o: options.cpp
221         $(CXX) $(CXXFLAGS) -DANYCONF_OPTIONS $< -c -o $@
222
223 nullOptions.o: options.cpp
224         $(CXX) $(CXXFLAGS) $< -c -o $@
225
226 %.o: %.cpp
227         $(CXX) $(CXXFLAGS) $< -c -o $@
228
229
230 libAnysync.a: $(OBJS)
231         ar cru $@ $(OBJS)
232         ranlib $@
233
234 anyrtpproxy: anytun
235         $(MAKE) --directory=$(CURDIR)/anyrtpproxy
236
237 distclean: cleanall
238         find . -name *.o -exec rm -f {} \;
239         rm -f config.sub config.guess
240         rm -f daemonService.h
241         rm -f daemonService.cpp
242         rm -f signalHandler.hpp
243         rm -f sysExec.hpp
244         rm -f version.h
245         rm -f tunDevice.cpp
246         rm -f include.mk
247
248 cleanall: clean
249         $(MAKE) --directory="../doc" clean
250
251 clean:
252         rm -f *.o
253         rm -f *.d
254         rm -f *.d.*
255         rm -f win32/*.o
256         rm -f win32/*.d
257         rm -f win32/*.d.*
258         rm -f $(EXECUTABLES)
259         rm -f *.exe
260         rm -f anytun-nosync
261         rm -f -r doc/html/*
262         rm -f -r doc/latex/*
263         rm -f libAnysync.a
264         $(MAKE) --directory=$(CURDIR)/anyrtpproxy clean
265
266 manpage:
267         $(MAKE) --directory="../doc" manpage
268
269
270 INSTALL_TARGETS := install-bin install-etc
271 REMOVE_TARGETS := remove-bin remove-etc
272
273 ifdef MANDIR
274 INSTALL_TARGETS += install-man
275 REMOVE_TARGETS += remove-man
276 endif
277
278 ifdef EXAMPLESDIR
279 INSTALL_TARGETS += install-examples
280 REMOVE_TARGETS += remove-examples
281 endif
282
283 ifdef SYSTEMDDIR
284 INSTALL_TARGETS += install-systemd
285 REMOVE_TARGETS := remove-systemd
286 endif
287
288 install: all $(INSTALL_TARGETS)
289
290 install-bin: $(EXECUTABLES)
291         $(INSTALL) -d $(DESTDIR)$(SBINDIR)
292         $(INSTALL) -m 755 anytun $(DESTDIR)$(SBINDIR)
293         $(INSTALL) -d $(DESTDIR)$(BINDIR)
294         $(INSTALL) -m 755 anytun-config $(DESTDIR)$(BINDIR)
295         $(INSTALL) -m 755 anytun-controld $(DESTDIR)$(BINDIR)
296         $(INSTALL) -m 755 anytun-showtables $(DESTDIR)$(BINDIR)
297         $(INSTALL) -d $(DESTDIR)$(LIBDIR)
298         @ sed -e 's#/usr/local/sbin#$(SBINDIR)#' -e 's#/usr/local/bin#$(BINDIR)#' \
299         -e 's#/usr/local/etc#$(ETCDIR)#' ../usr/lib/anytun-launcher > ../usr/lib/anytun-launcher.bak
300         $(INSTALL) -m 755 ../usr/lib/anytun-launcher.bak $(DESTDIR)$(LIBDIR)/anytun-launcher
301         rm -f ../usr/lib/anytun-launcher.bak
302
303 install-etc:
304         $(INSTALL) -d $(DESTDIR)$(ETCDIR)/anytun
305         @ echo "example configurations can be found at $(EXAMPLESDIR)/anytun" > $(DESTDIR)$(ETCDIR)/anytun/README
306         $(INSTALL) -d $(DESTDIR)$(ETCDIR)/init.d
307         @ sed -e 's#/usr/local/bin#$(BINDIR)#' -e 's#/usr/local/lib#$(LIBDIR)#' -e 's#/usr/local/etc#$(ETCDIR)#' ../etc/init.d/anytun > ../etc/init.d/anytun.bak
308         $(INSTALL) -m 755 ../etc/init.d/anytun.bak $(DESTDIR)$(ETCDIR)/init.d/anytun
309         rm -f ../etc/init.d/anytun.bak
310
311 install-systemd:
312         $(INSTALL) -d $(DESTDIR)$(SYSTEMDDIR)
313         $(INSTALL) -m 644 ../usr/lib/systemd/system/anytun.service $(DESTDIR)$(SYSTEMDDIR)/anytun.service
314         @ sed -e 's#/usr/local/lib#$(LIBDIR)#' ../usr/lib/systemd/system/anytun@.service > ../usr/lib/systemd/system/anytun@.service.bak
315         @ sed -e 's#/usr/local/lib#$(LIBDIR)#' ../usr/lib/systemd/system/anytun-controld@.service > ../usr/lib/systemd/system/anytun-controld@.service.bak
316         $(INSTALL) -m 644 ../usr/lib/systemd/system/anytun@.service.bak $(DESTDIR)$(SYSTEMDDIR)/anytun@.service
317         $(INSTALL) -m 644 ../usr/lib/systemd/system/anytun-controld@.service.bak $(DESTDIR)$(SYSTEMDDIR)/anytun-controld@.service
318         rm -f ../usr/lib/systemd/system/anytun@.service.bak
319         rm -f ../usr/lib/systemd/system/anytun-controld@.service.bak
320         $(INSTALL) -d $(DESTDIR)$(SYSTEMDGENERATORDIR)
321         @ sed -e 's#/usr/local/etc#$(ETCDIR)#' ../usr/lib/systemd/system-generator/anytun-generator > ../usr/lib/systemd/system-generator/anytun-generator.bak
322         $(INSTALL) -m 755 ../usr/lib/systemd/system-generator/anytun-generator.bak $(DESTDIR)$(SYSTEMDGENERATORDIR)/anytun-generator
323         rm -f ../usr/lib/systemd/system-generator/anytun-generator.bak
324         $(INSTALL) -d $(DESTDIR)$(TMPFILESDDIR)
325         $(INSTALL) -m 644 ../usr/lib/tmpfiles.d/anytun.conf $(DESTDIR)$(TMPFILESDDIR)/anytun.conf
326
327 install-examples:
328         $(INSTALL) -d $(DESTDIR)$(EXAMPLESDIR)/anytun
329         $(INSTALL) -m 644 ../etc/anytun/autostart $(DESTDIR)$(EXAMPLESDIR)/anytun/autostart
330         @( cd '../etc/anytun/' ;                                                                   \
331      for dir in `ls`; do                                                                     \
332        if [ -d $$dir ]; then                                                                 \
333          echo "install $$dir configuration" ;                                                \
334          cd $$dir ;                                                                          \
335          $(INSTALL) -d $(DESTDIR)$(EXAMPLESDIR)/anytun/$$dir ;                               \
336          $(INSTALL) -m 600 config $(DESTDIR)$(EXAMPLESDIR)/anytun/$$dir/config ;             \
337          if [ -e 'post-up.sh' ]; then                                                        \
338            $(INSTALL) -m 755 post-up.sh $(DESTDIR)$(EXAMPLESDIR)/anytun/$$dir/post-up.sh ;   \
339          fi ;                                                                                \
340          if [ -d 'conf.d' ]; then                                                            \
341            $(INSTALL) -d $(DESTDIR)$(EXAMPLESDIR)/anytun/$$dir/conf.d ;                      \
342            cd conf.d ;                                                                       \
343            for file in `ls`; do                                                              \
344              if [ -f $$file ]; then                                                          \
345                $(INSTALL) -m 600 $$file $(DESTDIR)$(EXAMPLESDIR)/anytun/$$dir/conf.d ;       \
346              fi ;                                                                            \
347            done ;                                                                            \
348            cd .. ;                                                                           \
349          fi ;                                                                                \
350          cd .. ;                                                                             \
351        fi ;                                                                                  \
352      done                                                                                    \
353    )
354
355 install-man: manpage
356         $(INSTALL) -d $(DESTDIR)$(MANDIR)/man8/
357         $(INSTALL) -m 644 ../doc/anytun.8 $(DESTDIR)$(MANDIR)/man8/
358         $(INSTALL) -m 644 ../doc/anytun-config.8 $(DESTDIR)$(MANDIR)/man8/
359         $(INSTALL) -m 644 ../doc/anytun-controld.8 $(DESTDIR)$(MANDIR)/man8/
360         $(INSTALL) -m 644 ../doc/anytun-showtables.8 $(DESTDIR)$(MANDIR)/man8/
361
362 uninstall: remove
363
364
365 remove: $(REMOVE_TARGETS)
366
367 remove-bin:
368         rm -f $(DESTDIR)$(SBINDIR)/anytun
369         rm -f $(DESTDIR)$(BINDIR)/anytun-config
370         rm -f $(DESTDIR)$(BINDIR)/anytun-controld
371         rm -f $(DESTDIR)$(BINDIR)/anytun-showtables
372
373 remove-etc:
374         rm -f $(DESTDIR)$(ETCDIR)/init.d/anytun
375
376 remove-systemd:
377         rm -f $(DESTDIR)$(SYSTEMDDIR)/anytun.service
378         rm -f $(DESTDIR)$(SYSTEMDDIR)/anytun@.service
379         rm -f $(DESTDIR)$(SYSTEMDDIR)/anytun-controld@.service
380         rm -f $(DESTDIR)$(SYSTEMDGENERATORDIR)/anytun-generator
381         rm -f $(DESTDIR)$(TMPFILESDDIR)/anytun.conf
382
383 remove-examples:
384         rm -rf $(DESTDIR)$(EXAMPLESDIR)/anytun/
385
386 remove-man:
387         rm -f $(DESTDIR)$(MANDIR)/man8/anytun.8
388         rm -f $(DESTDIR)$(MANDIR)/man8/anytun-config.8
389         rm -f $(DESTDIR)$(MANDIR)/man8/anytun-controld.8
390         rm -f $(DESTDIR)$(MANDIR)/man8/anytun-showtables.8
391
392 purge: remove
393         rm -rf $(DESTDIR)$(ETCDIR)/anytun/