Imported Upstream version 0.3
[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 version 3 as
25 #  published by the Free Software Foundation.
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 TARGET=`uname -s`
37
38 CFLAGS='-g -O2'
39 LDFLAGS='-g -Wall -O2'
40
41 CRYPTO_LIB='gcrypt'
42 PASSPHRASE=1
43 V4_MAPPED=1
44
45 PREFIX='/usr/local'
46 USERNAME='uanytun'
47 USERHOME='/var/run/uanytun'
48
49 print_usage() {
50   echo "configure --help                    print this"
51   echo "          --target=<TARGET>         build target i.e. Linux (default: autodetect)"
52   echo "          --prefix=<PREFIX>         the installation prefix (default: /usr/local)"
53   echo "          --username=<USERNAME>     create this user when installing (default: uanytun)"
54   echo "          --userhome=<PATH>         the home directory of the user to be created  (default: /var/run/uanytun)"
55   echo "          --use-ssl-crypto          use ssl crypto library instead of libgcrypt"
56   echo "          --no-crypto               disable crypto at all (only NULL cipher)"
57   echo "          --disable-passphrase      disable master key and salt passphrase"
58   echo "          --enable-passphrase       enable master key and salt passphrase"
59   echo "          --disable-v4-mapped       disable V4-Mapped addresses (this means to disable"
60   echo "                                    simultanious use of IPv4 and IPv6)"
61   echo "          --enable-v4-mapped        enable V4-Mapped addresses"
62 }
63
64 for arg
65 do
66   case $arg in
67   --target=*)
68     TARGET=${arg#--target=}
69   ;;
70   --prefix=*)
71     PREFIX=${arg#--prefix=}
72   ;;
73   --username=*)
74     USERNAME=${arg#--username=}
75   ;;
76   --userhome=*)
77     USERHOME=${arg#--userhome=}
78   ;;
79   --use-ssl-crypto)
80     CRYPTO_LIB='ssl'
81   ;;
82   --no-crypto)
83     CRYPTO_LIB='none'
84   ;; 
85   --disable-passphrase)
86     PASSPHRASE=0
87   ;;
88   --enable-passphrase)
89     PASSPHRASE=1
90   ;;
91   --disable-v4-mapped)
92     V4_MAPPED=0 
93   ;; 
94   --enable-v4-mapped)
95     V4_MAPPED=2
96   ;; 
97   --help)
98     print_usage
99     exit 0
100   ;;
101   *)
102     echo "Unknown argument: $arg"
103     print_usage
104     exit 1
105   ;;
106   esac
107 done
108
109 rm -f include.mk
110 case $TARGET in 
111   Linux)
112     rm -f tun.c
113     ln -sf linux/tun.c
114     echo "loading Linux specific TUN Device"
115   ;;
116   OpenBSD|FreeBSD|NetBSD)
117     rm -f tun.c
118     ln -sf bsd/tun.c
119     echo "loading BSD specific TUN Device"
120     CFLAGS=$CFLAGS' -I/usr/local/include'
121     LDFLAGS=$LDFLAGS' -L/usr/local/lib'
122     if [ $V4_MAPPED -ne 2 ]; then
123       V4_MAPPED=0
124     fi
125   ;;
126   *)
127     echo "Plattform not supported"
128     exit 1;
129   ;;
130 esac
131
132
133 case $CRYPTO_LIB in
134   gcrypt)
135     LDFLAGS=$LDFLAGS' -lgcrypt'
136     echo "using libgcrypt library"
137   ;;
138   ssl)
139     CFLAGS=$CFLAGS' -DUSE_SSL_CRYPTO'
140     LDFLAGS=$LDFLAGS' -lcrypto'
141     echo "using ssl crypto library"
142   ;;
143   none)
144     CFLAGS=$CFLAGS' -DNO_CRYPT'
145     echo "NO_CRYPT_OBJ = 1" >> include.mk
146     echo "disabling crypto"
147   ;;
148 esac
149
150 if [ $PASSPHRASE -eq 0 ]; then
151   CFLAGS=$CFLAGS' -DNO_PASSPHRASE'
152   echo "disabling master key and salt passphrase"
153 fi
154
155 if [ $V4_MAPPED -eq 0 ]; then
156   CFLAGS=$CFLAGS' -DNO_V4MAPPED'
157   echo "WARNING: disabling V4 mapped addresses, this prevents uanytun from using IPv6 and IPv4 Sockets at the same time"
158 fi
159
160 if [ "x$PREFIX" = "x/usr" ]; then
161  ETCDIR=/etc
162 else
163  ETCDIR=$PREFIX/etc
164 fi
165
166 cat >> include.mk <<EOF
167 # this file was created automatically
168 # do not edit this file directly 
169 # use ./configure instead
170
171 TARGET := $TARGET
172 CC := gcc
173 CFLAGS := $CFLAGS
174 LDFLAGS := $LDFLAGS
175
176 SBINDIR := $PREFIX/sbin
177 MANDIR := $PREFIX/share/man
178 ETCDIR := $ETCDIR
179 USERNAME := $USERNAME
180 USERHOME := $USERHOME
181 EOF
182
183 exit 0