Apply patch based on the one from Cyril Brulebois for anytun to fix FTBFS on GNU...
[debian/uanytun.git] / src / configure
1 #!/bin/sh
2 #
3 #  uAnytun
4 #
5 #  uAnytun is a tiny implementation of SATP. Unlike Anytun which is a full
6 #  featured implementation uAnytun has no support for multiple connections
7 #  or synchronisation. It is a small single threaded implementation intended
8 #  to act as a client on small platforms.
9 #  The secure anycast tunneling protocol (satp) defines a protocol used
10 #  for communication between any combination of unicast and anycast
11 #  tunnel endpoints.  It has less protocol overhead than IPSec in Tunnel
12 #  mode and allows tunneling of every ETHER TYPE protocol (e.g.
13 #  ethernet, ip, arp ...). satp directly includes cryptography and
14 #  message authentication based on the methodes used by SRTP.  It is
15 #  intended to deliver a generic, scaleable and secure solution for
16 #  tunneling and relaying of packets of any protocol.
17 #  
18 #
19 #  Copyright (C) 2007-2008 Christian Pointner <equinox@anytun.org>
20 #
21 #  This file is part of uAnytun.
22 #
23 #  uAnytun is free software: you can redistribute it and/or modify
24 #  it under the terms of the GNU General Public License as published by
25 #  the Free Software Foundation, either version 3 of the License, or
26 #  any later version.
27 #
28 #  uAnytun is distributed in the hope that it will be useful,
29 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
30 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31 #  GNU General Public License for more details.
32 #
33 #  You should have received a copy of the GNU General Public License
34 #  along with uAnytun. If not, see <http://www.gnu.org/licenses/>.
35 #
36
37 TARGET=`uname -s`
38
39 EBUILD_COMPAT=0
40
41 CFLAGS='-g -O2'
42 LDFLAGS='-g -Wall -O2'
43
44 CRYPTO_LIB='gcrypt'
45 PASSPHRASE=1
46 V4_MAPPED=1
47
48 PREFIX='/usr/local'
49 SBINDIR=''
50 ETCDIR=''
51 MANDIR=''
52 INSTALLMANPAGE=1
53 EXAMPLESDIR=''
54 INSTALLEXAMPLES=1
55
56 print_usage() {
57   echo "configure --help                    print this"
58   echo "          --target=<TARGET>         build target i.e. Linux (default: autodetect)"
59   echo "          --prefix=<PREFIX>         the installation prefix (default: /usr/local)"
60   echo "          --sbindir=<DIR>           the path to the sbin directory (default: $PREFIX/sbin)"
61   echo "          --sysconfdir=<DIR>        the path to the system configuration directory (default: $PREFIX/etc"
62   echo "          --mandir=<DIR>            the path to the system man pages (default: $PREFIX/share/man)"
63   echo "          --no-manpage              dont't install manpage"
64   echo "          --examplesdir=<DIR>       the path to the examples files (default: $PREFIX/share/examples)"
65   echo "          --no-examples             dont't install example files"
66   echo "          --use-ssl-crypto          use ssl crypto library instead of libgcrypt"
67   echo "          --no-crypto               disable crypto at all (only NULL cipher)"
68   echo "          --disable-passphrase      disable master key and salt passphrase"
69   echo "          --enable-passphrase       enable master key and salt passphrase"
70   echo "          --disable-v4-mapped       disable V4-Mapped addresses (this means to disable"
71   echo "                                    simultanious use of IPv4 and IPv6)"
72   echo "          --enable-v4-mapped        enable V4-Mapped addresses"
73 }
74
75 for arg
76 do
77   case $arg in
78   --target=*)
79     TARGET=${arg#--target=}
80   ;;
81   --prefix=*)
82     PREFIX=${arg#--prefix=}
83   ;;
84   --sbindir=*)
85     SBINDIR=${arg#--sbindir=}
86   ;;
87   --sysconfdir=*)
88     ETCDIR=${arg#--sysconfdir=}
89   ;;
90   --mandir=*)
91     MANDIR=${arg#--mandir=}
92   ;;
93   --no-manpage)
94     INSTALLMANPAGE=0
95   ;;
96   --examplesdir=*)
97     EXAMPLESDIR=${arg#--examplesdir=}
98   ;;
99   --no-examples)
100     INSTALLEXAMPLES=0
101   ;;
102   --use-ssl-crypto)
103     CRYPTO_LIB='ssl'
104   ;;
105   --no-crypto)
106     CRYPTO_LIB='none'
107   ;; 
108   --disable-passphrase)
109     PASSPHRASE=0
110   ;;
111   --enable-passphrase)
112     PASSPHRASE=1
113   ;;
114   --disable-v4-mapped)
115     V4_MAPPED=0 
116   ;; 
117   --enable-v4-mapped)
118     V4_MAPPED=2
119   ;; 
120   --ebuild-compat)
121     EBUILD_COMPAT=1
122   ;;
123   --help)
124     print_usage
125     exit 0
126   ;;
127   *)
128     ERRORS="$ERRORS $arg"
129   ;;
130   esac
131 done
132
133 if [ -n "$ERRORS" ] && [ $EBUILD_COMPAT -ne 1 ]; then
134   for error in $ERRORS; do
135     echo "Unknown argument: $error"
136   done
137
138   print_usage
139   exit 1
140 fi
141
142
143 rm -f include.mk
144 case $TARGET in 
145   Linux)
146     rm -f tun.c
147     ln -sf linux/tun.c
148     echo "loading Linux specific TUN Device"
149   ;;
150   OpenBSD|FreeBSD|NetBSD|GNU/kFreeBSD)
151     rm -f tun.c
152     ln -sf bsd/tun.c
153     echo "loading BSD specific TUN Device"
154     CFLAGS=$CFLAGS' -I/usr/local/include'
155     LDFLAGS=$LDFLAGS' -L/usr/local/lib'
156     if [ $V4_MAPPED -ne 2 ]; then
157       V4_MAPPED=0
158     fi
159   ;;
160   *)
161     echo "Plattform not supported"
162     exit 1;
163   ;;
164 esac
165
166
167 case $CRYPTO_LIB in
168   gcrypt)
169     LDFLAGS=$LDFLAGS' -lgcrypt'
170     echo "using libgcrypt library"
171   ;;
172   ssl)
173     CFLAGS=$CFLAGS' -DUSE_SSL_CRYPTO'
174     LDFLAGS=$LDFLAGS' -lcrypto'
175     echo "using ssl crypto library"
176   ;;
177   none)
178     CFLAGS=$CFLAGS' -DNO_CRYPT'
179     echo "NO_CRYPT_OBJ = 1" >> include.mk
180     echo "disabling crypto"
181   ;;
182 esac
183
184 if [ $PASSPHRASE -eq 0 ]; then
185   CFLAGS=$CFLAGS' -DNO_PASSPHRASE'
186   echo "disabling master key and salt passphrase"
187 fi
188
189 if [ $V4_MAPPED -eq 0 ]; then
190   CFLAGS=$CFLAGS' -DNO_V4MAPPED'
191   echo "WARNING: disabling V4 mapped addresses, this prevents uanytun from using IPv6 and IPv4 Sockets at the same time"
192 fi
193
194 if [ -z "$SBINDIR" ]; then
195   SBINDIR=$PREFIX/sbin
196 fi
197
198 if [ -z "$ETCDIR" ]; then
199   ETCDIR=$PREFIX/etc
200 fi
201
202 if [ -z "$MANDIR" ]; then
203   MANDIR=$PREFIX/share/man
204 fi
205
206 if [ -z "$EXAMPLESDIR" ]; then
207   EXAMPLESDIR=$PREFIX/share/examples
208 fi
209
210 cat >> include.mk <<EOF
211 # this file was created automatically
212 # do not edit this file directly 
213 # use ./configure instead
214
215 TARGET := $TARGET
216 CC := gcc
217 CFLAGS := $CFLAGS
218 LDFLAGS := $LDFLAGS
219 STRIP := strip
220 INSTALL := install
221
222 PREFIX := $PREFIX
223 SBINDIR := $SBINDIR
224 ETCDIR := $ETCDIR
225 EOF
226
227 if [ $INSTALLMANPAGE -eq 1 ]; then
228   echo "MANDIR := $MANDIR" >> include.mk
229   echo "installing manpage"
230 else
231   echo "not installing manpage"
232 fi
233
234 if [ $INSTALLEXAMPLES -eq 1 ]; then
235   echo "EXAMPLESDIR := $EXAMPLESDIR" >> include.mk
236   echo "installing example files"
237 else
238   echo "not installing example files"
239 fi
240
241 exit 0