Imported Upstream version 0.3.3
[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-2010 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 version.h
93         rm -f tun.c
94
95 clean:
96         rm -f *.o
97         rm -f *.d
98         rm -f *.d.*
99         rm -f $(EXECUTABLE)
100
101 cleanall: clean
102         $(MAKE) --directory="../doc/" clean
103
104 manpage:
105         $(MAKE) --directory="../doc/" manpage
106
107
108 INSTALL_TARGETS := install-bin install-etc
109 REMOVE_TARGETS := remove-bin remove-etc
110
111 ifdef MANDIR
112 INSTALL_TARGETS += install-man
113 REMOVE_TARGETS += remove-man
114 endif
115
116 ifdef EXAMPLESDIR
117 INSTALL_TARGETS += install-examples
118 REMOVE_TARGETS += remove-examples
119 endif
120
121 install: all $(INSTALL_TARGETS)
122
123 install-bin: $(EXECUTABLE)
124         $(INSTALL) -d $(DESTDIR)$(SBINDIR)
125         $(INSTALL) -m 755 $(EXECUTABLE) $(DESTDIR)$(SBINDIR)
126
127 install-etc:
128         $(INSTALL) -d $(DESTDIR)$(ETCDIR)/$(EXECUTABLE)
129         @ echo "example configurations can be found at $(EXAMPLESDIR)/$(EXECUTABLE)" > $(DESTDIR)$(ETCDIR)/$(EXECUTABLE)/README
130         $(INSTALL) -d $(DESTDIR)$(ETCDIR)/init.d
131         @ sed -e 's#DAEMON=/usr/sbin/uanytun#DAEMON=$(SBINDIR)/$(EXECUTABLE)#' \
132         -e 's#CONFIG_DIR=/etc/uanytun#CONFIG_DIR=$(ETCDIR)/uanytun#' ../etc/init.d/uanytun > ../etc/init.d/uanytun.bak
133         $(INSTALL) -m 755 ../etc/init.d/uanytun.bak $(DESTDIR)$(ETCDIR)/init.d/$(EXECUTABLE)
134         rm -f ../etc/init.d/uanytun.bak
135
136 install-examples:
137         $(INSTALL) -d $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)
138         $(INSTALL) -m 644 ../etc/uanytun/autostart $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/autostart
139         @( cd '../etc/uanytun/' ;                                                                        \
140      for dir in `ls`; do                                                                           \
141        if [ -d $$dir ]; then                                                                       \
142          echo "install $$dir configuration" ;                                                      \
143          cd $$dir ;                                                                                \
144          $(INSTALL) -d $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/$$dir ;                              \
145          $(INSTALL) -m 600 config $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/$$dir/config ;            \
146          if [ -e 'post-up.sh' ]; then                                                              \
147            $(INSTALL) -m 755 post-up.sh $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/$$dir/post-up.sh ;  \
148          fi ;                                                                                      \
149          cd .. ;                                                                                   \
150        fi ;                                                                                        \
151      done                                                                                          \
152    )
153
154 install-man: manpage
155         $(INSTALL) -d $(DESTDIR)$(MANDIR)/man8/
156         $(INSTALL) -m 644 ../doc/uanytun.8 $(DESTDIR)$(MANDIR)/man8/$(EXECUTABLE).8
157
158 uninstall: remove
159
160 remove: $(REMOVE_TARGETS)
161
162 remove-bin:
163         rm -f $(DESTDIR)$(SBINDIR)/$(EXECUTABLE)
164
165 remove-etc:
166         rm -f $(DESTDIR)$(ETCDIR)/init.d/$(EXECUTABLE)
167
168 remove-examples:
169         rm -rf $(DESTDIR)$(EXAMPLESDIR)/$(EXECUTABLE)/
170
171 remove-man:
172         rm -f $(DESTDIR)$(MANDIR)/man8/$(EXECUTABLE).8
173
174 purge: remove
175         rm -rf $(DESTDIR)$(ETCDIR)/$(EXECUTABLE)/