feccbaae6602ad4449719b5072a29fd886c88fea
[debian/uanytun.git] / src / Makefile
1 ##
2 ##  uAnytun
3 ##
4 ##  uAnytun is a tiny implementation of SATP. Unlike Anytun which is a full
5 ##  featured implementation uAnytun has no support for multiple connections
6 ##  or synchronisation. It is a small single threaded implementation intended
7 ##  to act as a client on small platforms.
8 ##  The secure anycast tunneling protocol (satp) defines a protocol used
9 ##  for communication between any combination of unicast and anycast
10 ##  tunnel endpoints.  It has less protocol overhead than IPSec in Tunnel
11 ##  mode and allows tunneling of every ETHER TYPE protocol (e.g.
12 ##  ethernet, ip, arp ...). satp directly includes cryptography and
13 ##  message authentication based on the methods used by SRTP.  It is
14 ##  intended to deliver a generic, scaleable and secure solution for
15 ##  tunneling and relaying of packets of any protocol.
16 ##
17 ##
18 ##  Copyright (C) 2007-2014 Christian Pointner <equinox@anytun.org>
19 ##
20 ##  This file is part of uAnytun.
21 ##
22 ##  uAnytun is free software: you can redistribute it and/or modify
23 ##  it under the terms of the GNU General Public License as published by
24 ##  the Free Software Foundation, either version 3 of the License, or
25 ##  any later version.
26 ##
27 ##  uAnytun is distributed in the hope that it will be useful,
28 ##  but WITHOUT ANY WARRANTY; without even the implied warranty of
29 ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30 ##  GNU General Public License for more details.
31 ##
32 ##  You should have received a copy of the GNU General Public License
33 ##  along with uAnytun. If not, see <http://www.gnu.org/licenses/>.
34 ##
35 ##  In addition, as a special exception, the copyright holders give
36 ##  permission to link the code of portions of this program with the
37 ##  OpenSSL library under certain conditions as described in each
38 ##  individual source file, and distribute linked combinations
39 ##  including the two.
40 ##  You must obey the GNU General Public License in all respects
41 ##  for all of the code used other than OpenSSL.  If you modify
42 ##  file(s) with this exception, you may extend this exception to your
43 ##  version of the file(s), but you are not obligated to do so.  If you
44 ##  do not wish to do so, delete this exception statement from your
45 ##  version.  If you delete this exception statement from all source
46 ##  files in the program, then also delete it here.
47 ##
48
49 ifneq ($(MAKECMDGOALS),distclean)
50 include include.mk
51 endif
52
53 EXECUTABLE := uanytun
54
55 CRYPT_OBJ := key_derivation.o \
56              auth_algo.o
57 OBJ := log.o \
58        string_list.o \
59        sig_handler.o \
60        sysexec.o \
61        options.o \
62        tun.o \
63        udp.o \
64        plain_packet.o \
65        encrypted_packet.o \
66        seq_window.o \
67        cipher.o \
68        uanytun.o
69
70
71 ifndef NO_CRYPT_OBJ
72 OBJ += $(CRYPT_OBJ)
73 endif
74
75 SRC := $(OBJ:%.o=%.c)
76
77 .PHONY: clean cleanall distclean manpage install install-bin install-etc install-man uninstall remove purge
78
79 all: $(EXECUTABLE)
80
81 %.d: %.c
82         @set -e; rm -f $@; \
83   $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
84   sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
85   rm -f $@.$$$$; echo '(re)building $@'
86
87 ifneq ($(MAKECMDGOALS),distclean)
88 -include $(SRC:%.c=%.d)
89 endif
90
91 $(EXECUTABLE): $(OBJ)
92         $(CC) $(OBJ) -o $@ $(LDFLAGS)
93
94 %.o: %.c
95         $(CC) $(CFLAGS) -c $<
96
97
98 strip: $(EXECUTABLE)
99         $(STRIP) -s $(EXECUTABLE)
100
101 distclean: cleanall
102         find . -name *.o -exec rm -f {} \;
103         find . -name "*.\~*" -exec rm -rf {} \;
104         rm -f include.mk
105         rm -f version.h
106         rm -f tun.c
107
108 clean:
109         rm -f *.o
110         rm -f *.d
111         rm -f *.d.*
112         rm -f $(EXECUTABLE)
113
114 cleanall: clean
115         $(MAKE) --directory="../doc/" clean
116
117 manpage:
118         $(MAKE) --directory="../doc/" manpage
119
120
121 INSTALL_TARGETS := install-bin install-etc
122 REMOVE_TARGETS := remove-bin remove-etc
123
124 ifdef MANDIR
125 INSTALL_TARGETS += install-man
126 REMOVE_TARGETS += remove-man
127 endif
128
129 ifdef EXAMPLESDIR
130 INSTALL_TARGETS += install-examples
131 REMOVE_TARGETS += remove-examples
132 endif
133
134 install: all $(INSTALL_TARGETS)
135
136 install-bin: $(EXECUTABLE)
137         $(INSTALL) -d $(DESTDIR)$(SBINDIR)
138         $(INSTALL) -m 755 $(EXECUTABLE) $(DESTDIR)$(SBINDIR)
139
140 install-etc:
141         $(INSTALL) -d $(DESTDIR)$(ETCDIR)/$(EXECUTABLE)
142         @ echo "example configurations can be found at $(EXAMPLESDIR)/$(EXECUTABLE)" > $(DESTDIR)$(ETCDIR)/$(EXECUTABLE)/README
143         $(INSTALL) -d $(DESTDIR)$(ETCDIR)/init.d
144         @ sed -e 's#DAEMON=/usr/sbin/uanytun#DAEMON=$(SBINDIR)/$(EXECUTABLE)#' \
145         -e 's#CONFIG_DIR=/etc/uanytun#CONFIG_DIR=$(ETCDIR)/uanytun#' ../etc/init.d/uanytun > ../etc/init.d/uanytun.bak
146         $(INSTALL) -m 755 ../etc/init.d/uanytun.bak $(DESTDIR)$(ETCDIR)/init.d/$(EXECUTABLE)
147         rm -f ../etc/init.d/uanytun.bak
148
149 install-examples:
150         $(INSTALL) -d $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)
151         $(INSTALL) -m 644 ../etc/uanytun/autostart $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/autostart
152         @( cd '../etc/uanytun/' ;                                                                        \
153      for dir in `ls`; do                                                                           \
154        if [ -d $$dir ]; then                                                                       \
155          echo "install $$dir configuration" ;                                                      \
156          cd $$dir ;                                                                                \
157          $(INSTALL) -d $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/$$dir ;                              \
158          $(INSTALL) -m 600 config $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/$$dir/config ;            \
159          if [ -e 'post-up.sh' ]; then                                                              \
160            $(INSTALL) -m 755 post-up.sh $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/$$dir/post-up.sh ;  \
161          fi ;                                                                                      \
162          cd .. ;                                                                                   \
163        fi ;                                                                                        \
164      done                                                                                          \
165    )
166
167 install-man: manpage
168         $(INSTALL) -d $(DESTDIR)$(MANDIR)/man8/
169         $(INSTALL) -m 644 ../doc/uanytun.8 $(DESTDIR)$(MANDIR)/man8/$(EXECUTABLE).8
170
171 uninstall: remove
172
173 remove: $(REMOVE_TARGETS)
174
175 remove-bin:
176         rm -f $(DESTDIR)$(SBINDIR)/$(EXECUTABLE)
177
178 remove-etc:
179         rm -f $(DESTDIR)$(ETCDIR)/init.d/$(EXECUTABLE)
180
181 remove-examples:
182         rm -rf $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/
183
184 remove-man:
185         rm -f $(DESTDIR)$(MANDIR)/man8/$(EXECUTABLE).8
186
187 purge: remove
188         rm -rf $(DESTDIR)$(ETCDIR)/$(EXECUTABLE)/