ee8058211d801146a2903da8a5c30b5646d3a574
[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-2010 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
47 PREFIX='/usr/local'
48 SBINDIR=''
49 ETCDIR=''
50 MANDIR=''
51 INSTALLMANPAGE=1
52 EXAMPLESDIR=''
53 INSTALLEXAMPLES=1
54
55 print_usage() {
56   echo "configure --help                    print this"
57   echo "          --target=<TARGET>         build target i.e. Linux (default: autodetect)"
58   echo "          --prefix=<PREFIX>         the installation prefix (default: /usr/local)"
59   echo "          --sbindir=<DIR>           the path to the sbin directory (default: $PREFIX/sbin)"
60   echo "          --sysconfdir=<DIR>        the path to the system configuration directory (default: $PREFIX/etc"
61   echo "          --mandir=<DIR>            the path to the system man pages (default: $PREFIX/share/man)"
62   echo "          --no-manpage              dont't install manpage"
63   echo "          --examplesdir=<DIR>       the path to the examples files (default: $PREFIX/share/examples)"
64   echo "          --no-examples             dont't install example files"
65   echo "          --use-ssl-crypto          use ssl crypto library instead of libgcrypt"
66   echo "          --no-crypto               disable crypto at all (only NULL cipher)"
67   echo "          --disable-passphrase      disable master key and salt passphrase"
68   echo "          --enable-passphrase       enable master key and salt passphrase"
69 }
70
71 for arg
72 do
73   case $arg in
74   --target=*)
75     TARGET=${arg#--target=}
76   ;;
77   --prefix=*)
78     PREFIX=${arg#--prefix=}
79   ;;
80   --sbindir=*)
81     SBINDIR=${arg#--sbindir=}
82   ;;
83   --sysconfdir=*)
84     ETCDIR=${arg#--sysconfdir=}
85   ;;
86   --mandir=*)
87     MANDIR=${arg#--mandir=}
88   ;;
89   --no-manpage)
90     INSTALLMANPAGE=0
91   ;;
92   --examplesdir=*)
93     EXAMPLESDIR=${arg#--examplesdir=}
94   ;;
95   --no-examples)
96     INSTALLEXAMPLES=0
97   ;;
98   --use-ssl-crypto)
99     CRYPTO_LIB='ssl'
100   ;;
101   --no-crypto)
102     CRYPTO_LIB='none'
103   ;; 
104   --disable-passphrase)
105     PASSPHRASE=0
106   ;;
107   --enable-passphrase)
108     PASSPHRASE=1
109   ;;
110   --ebuild-compat)
111     EBUILD_COMPAT=1
112   ;;
113   --help)
114     print_usage
115     exit 0
116   ;;
117   *)
118     ERRORS="$ERRORS $arg"
119   ;;
120   esac
121 done
122
123 if [ -n "$ERRORS" ] && [ $EBUILD_COMPAT -ne 1 ]; then
124   for error in $ERRORS; do
125     echo "Unknown argument: $error"
126   done
127
128   print_usage
129   exit 1
130 fi
131
132 rm -f version.h
133 rm -f include.mk
134 case $TARGET in 
135   Linux)
136     rm -f tun.c
137     ln -sf linux/tun.c
138     echo "loading Linux specific TUN Device"
139   ;;
140   OpenBSD|FreeBSD|NetBSD|GNU/kFreeBSD)
141     rm -f tun.c
142     ln -sf bsd/tun.c
143     echo "loading BSD specific TUN Device"
144     CFLAGS=$CFLAGS' -I/usr/local/include'
145     LDFLAGS=$LDFLAGS' -L/usr/local/lib'
146   ;;
147   *)
148     echo "platform not supported"
149     exit 1;
150   ;;
151 esac
152
153
154 case $CRYPTO_LIB in
155   gcrypt)
156     LDFLAGS=$LDFLAGS' -lgcrypt'
157     echo "using libgcrypt library"
158   ;;
159   ssl)
160     CFLAGS=$CFLAGS' -DUSE_SSL_CRYPTO'
161     LDFLAGS=$LDFLAGS' -lcrypto'
162     echo "using ssl crypto library"
163   ;;
164   none)
165     CFLAGS=$CFLAGS' -DNO_CRYPT'
166     echo "NO_CRYPT_OBJ = 1" >> include.mk
167     echo "disabling crypto"
168   ;;
169 esac
170
171 if [ $PASSPHRASE -eq 0 ]; then
172   CFLAGS=$CFLAGS' -DNO_PASSPHRASE'
173   echo "disabling master key and salt passphrase"
174 fi
175
176 if [ -z "$SBINDIR" ]; then
177   SBINDIR=$PREFIX/sbin
178 fi
179
180 if [ -z "$ETCDIR" ]; then
181   ETCDIR=$PREFIX/etc
182 fi
183
184 if [ -z "$MANDIR" ]; then
185   MANDIR=$PREFIX/share/man
186 fi
187
188 if [ -z "$EXAMPLESDIR" ]; then
189   EXAMPLESDIR=$PREFIX/share/examples
190 fi
191
192 cat >> include.mk <<EOF
193 # this file was created automatically
194 # do not edit this file directly 
195 # use ./configure instead
196
197 TARGET := $TARGET
198 CC := gcc
199 CFLAGS := $CFLAGS
200 LDFLAGS := $LDFLAGS
201 STRIP := strip
202 INSTALL := install
203
204 PREFIX := $PREFIX
205 SBINDIR := $SBINDIR
206 ETCDIR := $ETCDIR
207 EOF
208
209 if [ $INSTALLMANPAGE -eq 1 ]; then
210   echo "MANDIR := $MANDIR" >> include.mk
211   echo "installing manpage"
212 else
213   echo "not installing manpage"
214 fi
215
216 if [ $INSTALLEXAMPLES -eq 1 ]; then
217   echo "EXAMPLESDIR := $EXAMPLESDIR" >> include.mk
218   echo "installing example files"
219 else
220   echo "not installing example files"
221 fi
222
223 VERSION=`cat ../version`
224 if which svn >/dev/null; then
225   SVN_REV=`svn info | grep "^Revision: " | awk '{print($2)}'`
226   if [ -n "$SVN_REV" ]; then
227     VERSION="$VERSION (svn$SVN_REV)"
228   fi
229 fi
230 HOSTNAME=`hostname`
231 DATE=`date +"%d.%m.%Y %H:%M:%S %Z"`
232
233 cat >> version.h <<EOF
234 /* 
235  * uanytun version info
236  *
237  * this file was created automatically
238  * do not edit this file directly
239  * use ./configure instead
240  */
241
242 #ifndef UANYTUN_version_h_INCLUDED
243 #define UANYTUN_version_h_INCLUDED
244
245 #define VERSION_STRING_0 "uanytun version $VERSION"
246 #define VERSION_STRING_1 "built on $HOSTNAME, $DATE"
247
248 #endif
249
250 EOF
251
252 exit 0