358c612e403c601f87bda857625bdc8f8277a026
[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 version 3 as
24 ##  published by the Free Software Foundation.
25 ##
26 ##  uAnytun is distributed in the hope that it will be useful,
27 ##  but WITHOUT ANY WARRANTY; without even the implied warranty of
28 ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29 ##  GNU General Public License for more details.
30 ##
31 ##  You should have received a copy of the GNU General Public License
32 ##  along with uAnytun. If not, see <http://www.gnu.org/licenses/>.
33 ##
34
35 ifneq ($(MAKECMDGOALS),distclean)
36 include include.mk
37 endif
38
39 EXECUTABLE := uanytun
40
41 CRYPT_OBJ := key_derivation.o \
42             auth_algo.o
43 OBJ := log.o \
44       string_list.o \
45       sig_handler.o \
46       options.o \
47       tun.o \
48       udp.o \
49       plain_packet.o \
50       encrypted_packet.o \
51       seq_window.o \
52       cipher.o \
53       uanytun.o
54
55
56 ifndef NO_CRYPT_OBJ
57 OBJ += $(CRYPT_OBJ)
58 endif
59
60 SRC := $(OBJ:%.o=%.c)
61
62 .PHONY: clean distclean manpage install install-bin install-etc install-man remove purge
63
64 all: $(EXECUTABLE)
65
66 %.d: %.c
67         @set -e; rm -f $@; \
68          $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
69    sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
70    rm -f $@.$$$$; echo '(re)building $@'
71
72 ifneq ($(MAKECMDGOALS),distclean)
73 -include $(SRC:%.c=%.d)
74 endif
75
76 uanytun: $(OBJ)
77         $(CC) $(OBJ) -o $@ $(LDFLAGS)
78
79 %.o: %.c
80         $(CC) $(CFLAGS) -c $<
81
82
83 distclean: clean
84         find . -name *.o -exec rm -f {} \;
85         find . -name "*.\~*" -exec rm -rf {} \;
86         rm -f include.mk
87         rm -f tun.c
88
89 clean:
90         rm -f *.o
91         rm -f *.d
92         rm -f *.d.*
93         rm -f $(EXECUTABLE)
94
95 manpage:
96         $(MAKE) --directory="../doc/" manpage
97
98 install: all install-bin install-etc install-man add-user
99
100 install-bin: $(EXECUTABLE)
101         mkdir -p $(DESTDIR)$(SBINDIR)
102         install -m 755 $(EXECUTABLE) $(DESTDIR)$(SBINDIR)
103         $(STRIP) $(DESTDIR)$(SBINDIR)/$(EXECUTABLE)
104
105 install-etc:
106         mkdir -p $(DESTDIR)$(ETCDIR)/uanytun
107         install -m 644 ../etc/uanytun/autostart $(DESTDIR)$(ETCDIR)/uanytun/autostart
108         @( cd '../etc/uanytun/' ;                                                                                \
109      for dir in `ls`; do                                                                                   \
110        if [ -d $$dir ]; then                                                                               \
111          echo "install $$dir configuration" ;                                                              \
112          cd $$dir ;                                                                                        \
113          mkdir -p $(DESTDIR)$(ETCDIR)/uanytun/$$dir ;                                                      \
114          install -m 600 config $(DESTDIR)$(ETCDIR)/uanytun/$$dir/config ;                                  \
115          sed -i 's#username uanytun#username $(USERNAME)#' $(DESTDIR)$(ETCDIR)/uanytun/$$dir/config ;      \
116          sed -i 's#groupname uanytun#groupname $(USERNAME)#' $(DESTDIR)$(ETCDIR)/uanytun/$$dir/config ;    \
117          sed -i 's#chroot /var/run/uanytun#chroot $(USERHOME)#' $(DESTDIR)$(ETCDIR)/uanytun/$$dir/config ; \
118          if [ -e 'post-up.sh' ]; then                                                                      \
119            install -m 755 post-up.sh $(DESTDIR)$(ETCDIR)/uanytun/$$dir/post-up.sh ;                        \
120          fi ;                                                                                              \
121          cd .. ;                                                                                           \
122        fi ;                                                                                                \
123      done                                                                                                  \
124    )
125         mkdir -p $(DESTDIR)$(ETCDIR)/init.d
126         install -m 755 ../etc/init.d/uanytun $(DESTDIR)$(ETCDIR)/init.d/$(EXECUTABLE)
127         @ sed -i 's#DAEMON=/usr/sbin/uanytun#DAEMON=$(SBINDIR)/$(EXECUTABLE)#' $(DESTDIR)$(ETCDIR)/init.d/$(EXECUTABLE)
128         @ sed -i 's#CONFIG_DIR=/etc/uanytun#CONFIG_DIR=$(ETCDIR)/uanytun#' $(DESTDIR)$(ETCDIR)/init.d/$(EXECUTABLE)
129
130 install-man: manpage
131         mkdir -p $(DESTDIR)$(MANDIR)/man8/
132         cp ../doc/uanytun.8 $(DESTDIR)$(MANDIR)/man8/$(EXECUTABLE).8
133         gzip $(DESTDIR)$(MANDIR)/man8/$(EXECUTABLE).8
134
135 add-user:
136         @ adduser --system --group --home $(USERHOME) $(USERNAME)
137
138 remove-user: 
139         @ deluser $(USERNAME)
140         @ rm -rf $(USERHOME)
141
142 remove:
143         rm -f $(DESTDIR)$(SBINDIR)/$(EXECUTABLE)
144         rm -f $(DESTDIR)$(MANDIR)/man8/$(EXECUTABLE).8.gz
145         rm -f $(DESTDIR)$(ETCDIR)/init.d/$(EXECUTABLE)
146
147 purge: remove remove-user
148         rm -rf $(DESTDIR)$(ETCDIR)/uanytun/