4124575fb42ca751892996b2b6f9b9835d014527
[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 methodes 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-2008 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
36 ifneq ($(MAKECMDGOALS),distclean)
37 include include.mk
38 endif
39
40 EXECUTABLE := uanytun
41
42 CRYPT_OBJ := key_derivation.o \
43              auth_algo.o
44 OBJ := log.o \
45        string_list.o \
46        sig_handler.o \
47        sysexec.o \
48        options.o \
49        tun.o \
50        udp.o \
51        plain_packet.o \
52        encrypted_packet.o \
53        seq_window.o \
54        cipher.o \
55        uanytun.o
56
57
58 ifndef NO_CRYPT_OBJ
59 OBJ += $(CRYPT_OBJ)
60 endif
61
62 SRC := $(OBJ:%.o=%.c)
63
64 .PHONY: clean cleanall distclean manpage install install-bin install-etc install-man uninstall remove purge
65
66 all: $(EXECUTABLE)
67
68 %.d: %.c
69         @set -e; rm -f $@; \
70   $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
71   sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
72   rm -f $@.$$$$; echo '(re)building $@'
73
74 ifneq ($(MAKECMDGOALS),distclean)
75 -include $(SRC:%.c=%.d)
76 endif
77
78 $(EXECUTABLE): $(OBJ)
79         $(CC) $(OBJ) -o $@ $(LDFLAGS)
80
81 %.o: %.c
82         $(CC) $(CFLAGS) -c $<
83
84
85 strip: $(EXECUTABLE)
86         $(STRIP) -s $(EXECUTABLE)
87
88 distclean: cleanall
89         find . -name *.o -exec rm -f {} \;
90         find . -name "*.\~*" -exec rm -rf {} \;
91         rm -f include.mk
92         rm -f tun.c
93
94 clean:
95         rm -f *.o
96         rm -f *.d
97         rm -f *.d.*
98         rm -f $(EXECUTABLE)
99
100 cleanall: clean
101         $(MAKE) --directory="../doc/" clean
102
103 manpage:
104         $(MAKE) --directory="../doc/" manpage
105
106
107 INSTALL_TARGETS := install-bin install-etc
108 REMOVE_TARGETS := remove-bin remove-etc
109
110 ifdef MANDIR
111 INSTALL_TARGETS += install-man
112 REMOVE_TARGETS += remove-man
113 endif
114
115 ifdef EXAMPLESDIR
116 INSTALL_TARGETS += install-examples
117 REMOVE_TARGETS += remove-examples
118 endif
119
120 install: all $(INSTALL_TARGETS)
121
122 install-bin: $(EXECUTABLE)
123         $(INSTALL) -d $(DESTDIR)$(SBINDIR)
124         $(INSTALL) -m 755 $(EXECUTABLE) $(DESTDIR)$(SBINDIR)
125
126 install-etc:
127         $(INSTALL) -d $(DESTDIR)$(ETCDIR)/$(EXECUTABLE)
128         @ echo "example configurations can be found at $(EXAMPLESDIR)/$(EXECUTABLE)" > $(DESTDIR)$(ETCDIR)/$(EXECUTABLE)/README
129         $(INSTALL) -d $(DESTDIR)$(ETCDIR)/init.d
130         @ sed -e 's#DAEMON=/usr/sbin/uanytun#DAEMON=$(SBINDIR)/$(EXECUTABLE)#' \
131         -e 's#CONFIG_DIR=/etc/uanytun#CONFIG_DIR=$(ETCDIR)/uanytun#' ../etc/init.d/uanytun > ../etc/init.d/uanytun.bak
132         $(INSTALL) -m 755 ../etc/init.d/uanytun.bak $(DESTDIR)$(ETCDIR)/init.d/$(EXECUTABLE)
133         rm -f ../etc/init.d/uanytun.bak
134
135 install-examples:
136         $(INSTALL) -d $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)
137         $(INSTALL) -m 644 ../etc/uanytun/autostart $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/autostart
138         @( cd '../etc/uanytun/' ;                                                                        \
139      for dir in `ls`; do                                                                           \
140        if [ -d $$dir ]; then                                                                       \
141          echo "install $$dir configuration" ;                                                      \
142          cd $$dir ;                                                                                \
143          $(INSTALL) -d $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/$$dir ;                              \
144          $(INSTALL) -m 600 config $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/$$dir/config ;            \
145          if [ -e 'post-up.sh' ]; then                                                              \
146            $(INSTALL) -m 755 post-up.sh $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/$$dir/post-up.sh ;  \
147          fi ;                                                                                      \
148          cd .. ;                                                                                   \
149        fi ;                                                                                        \
150      done                                                                                          \
151    )
152
153 install-man: manpage
154         $(INSTALL) -d $(DESTDIR)$(MANDIR)/man8/
155         $(INSTALL) -m 644 ../doc/uanytun.8 $(DESTDIR)$(MANDIR)/man8/$(EXECUTABLE).8
156
157 uninstall: remove
158
159 remove: $(REMOVE_TARGETS)
160
161 remove-bin:
162         rm -f $(DESTDIR)$(SBINDIR)/$(EXECUTABLE)
163
164 remove-etc:
165         rm -f $(DESTDIR)$(ETCDIR)/init.d/$(EXECUTABLE)
166
167 remove-examples:
168         rm -rf $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/
169
170 remove-man:
171         rm -f $(DESTDIR)$(MANDIR)/man8/$(EXECUTABLE).8
172
173 purge: remove
174         rm -rf $(DESTDIR)$(ETCDIR)/$(EXECUTABLE)/