Imported Upstream version 0.3.3
[anytun.git] / src / configure
1 #!/bin/sh
2 #
3 #  anytun
4 #
5 #  The secure anycast tunneling protocol (satp) defines a protocol used
6 #  for communication between any combination of unicast and anycast
7 #  tunnel endpoints.  It has less protocol overhead than IPSec in Tunnel
8 #  mode and allows tunneling of every ETHER TYPE protocol (e.g.
9 #  ethernet, ip, arp ...). satp directly includes cryptography and
10 #  message authentication based on the methodes used by SRTP.  It is
11 #  intended to deliver a generic, scaleable and secure solution for
12 #  tunneling and relaying of packets of any protocol.
13 #
14 #
15 #  Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl, 
16 #                          Christian Pointner <satp@wirdorange.org>
17 #
18 #  This file is part of Anytun.
19 #
20 #  Anytun is free software: you can redistribute it and/or modify
21 #  it under the terms of the GNU General Public License as published by
22 #  the Free Software Foundation, either version 3 of the License, or
23 #  any later version.
24 #
25 #  Anytun is distributed in the hope that it will be useful,
26 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
27 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28 #  GNU General Public License for more details.
29 #
30 #  You should have received a copy of the GNU General Public License
31 #  along with anytun.  If not, see <http://www.gnu.org/licenses/>.
32 #
33
34 TARGET=`uname -s`
35
36 EBUILD_COMPAT=0
37
38 CXXFLAGS='-g -Wall -O2 -DLOG_SYSLOG -DLOG_FILE -DLOG_STDOUT'
39 LDFLAGS='-g -Wall -O2 -lboost_thread -lboost_serialization -lboost_system -lboost_date_time'
40
41 CRYPTO_LIB='gcrypt'
42 PASSPHRASE=1
43 ROUTING=1
44
45 PREFIX='/usr/local'
46 BINDIR=''
47 SBINDIR=''
48 ETCDIR=''
49 MANDIR=''
50 INSTALLMANPAGE=1
51 EXAMPLESDIR=''
52 INSTALLEXAMPLES=1
53
54 print_usage() {
55   echo "configure --help                    print this"
56   echo "          --target=<TARGET>         build target i.e. Linux (default: autodetect)"
57   echo "          --prefix=<PREFIX>         the installation prefix (default: /usr/local)"
58   echo "          --bindir=<DIR>            the path to the bin directory (default: $PREFIX/bin)"
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 manpages"
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   echo "          --disable-routing         disable built-in routing capability"
70   echo "          --enable-routing          enable built-in routing capability"
71 }
72
73 for arg
74 do
75   case $arg in
76   --target=*)
77     TARGET=${arg#--target=}
78   ;;
79   --prefix=*)
80     PREFIX=${arg#--prefix=}
81   ;;
82   --bindir=*)
83     SBINDIR=${arg#--bindir=}
84   ;;
85   --sbindir=*)
86     SBINDIR=${arg#--sbindir=}
87   ;;
88   --sysconfdir=*)
89     ETCDIR=${arg#--sysconfdir=}
90   ;;
91   --mandir=*)
92     MANDIR=${arg#--mandir=}
93   ;;
94   --no-manpage)
95     INSTALLMANPAGE=0
96   ;;
97   --examplesdir=*)
98     EXAMPLESDIR=${arg#--examplesdir=}
99   ;;
100   --no-examples)
101     INSTALLEXAMPLES=0
102   ;;
103   --use-ssl-crypto)
104     CRYPTO_LIB='ssl'
105   ;;
106   --no-crypto)
107     CRYPTO_LIB='none'
108   ;; 
109   --enable-passphrase)
110     PASSPHRASE=1
111   ;;
112   --disable-passphrase)
113     PASSPHRASE=0
114   ;;
115   --enable-routing)
116     ROUTING=1
117   ;;
118   --disable-routing)
119     ROUTING=0
120   ;;
121   --ebuild-compat)
122     EBUILD_COMPAT=1
123   ;;
124   --help)
125     print_usage
126     exit 0
127   ;;
128   *)
129     ERRORS="$ERRORS $arg"
130   ;;
131   esac
132 done
133
134 if [ -n "$ERRORS" ] && [ $EBUILD_COMPAT -ne 1 ]; then
135   for error in $ERRORS; do
136     echo "Unknown argument: $error"
137   done
138
139   print_usage
140   exit 1
141 fi
142
143
144 rm -f include.mk
145 case $TARGET in 
146   Linux)
147     rm -f tunDevice.cpp
148     ln -sf linux/tunDevice.cpp 
149     rm -f signalHandler.hpp
150     ln -sf posix/signalHandler.hpp
151     rm -f sysExec.hpp
152     ln -sf posix/sysExec.hpp
153     rm -f daemonService.h daemonService.cpp
154     ln -sf posix/posixDaemon.h daemonService.h
155     ln -sf posix/posixDaemon.cpp daemonService.cpp
156     echo "loading Linux specific TUN Device"
157   ;;
158   OpenBSD|FreeBSD|NetBSD|GNU/kFreeBSD)
159     rm -f tunDevice.cpp
160     ln -sf bsd/tunDevice.cpp 
161     rm -f signalHandler.hpp
162     ln -sf posix/signalHandler.hpp
163     rm -f sysExec.hpp
164     ln -sf posix/sysExec.hpp
165     rm -f daemonService.h daemonService.cpp
166     ln -sf posix/posixDaemon.h daemonService.h
167     ln -sf posix/posixDaemon.cpp daemonService.cpp
168     echo "loading BSD specific TUN Device"
169     CXXFLAGS=$CXXFLAGS' -I/usr/local/include'
170     LDFLAGS=$LDFLAGS' -L/usr/local/lib'
171   ;;
172   *)
173     echo "platform not supported"
174     exit 1
175   ;;
176 esac
177
178 case $CRYPTO_LIB in
179   gcrypt)
180     LDFLAGS=$LDFLAGS' -lgcrypt -lgpg-error'
181     echo "using libgcrypt library"
182   ;;
183   ssl)
184     CXXFLAGS=$CXXFLAGS' -DUSE_SSL_CRYPTO'
185     LDFLAGS=$LDFLAGS' -lcrypto'
186     echo "using ssl crypto library"
187   ;;
188   none)
189     CXXFLAGS=$CXXFLAGS' -DNO_CRYPT'
190     echo "NO_CRYPT_OBJ = 1" >> include.mk
191     echo "disabling crypto"
192   ;;
193 esac
194
195 if [ $PASSPHRASE -eq 0 ]; then
196   CXXFLAGS=$CXXFLAGS' -DNO_PASSPHRASE'
197   echo "disabling master key and salt passphrase"
198 fi
199
200 if [ $ROUTING -eq 0 ]; then
201   CXXFLAGS=$CXXFLAGS' -DNO_ROUTING'
202   echo "disabling built-in routing capability"
203 fi
204
205 if [ -z "$BINDIR" ]; then
206   BINDIR=$PREFIX/bin
207 fi
208
209 if [ -z "$SBINDIR" ]; then
210   SBINDIR=$PREFIX/sbin
211 fi
212
213 if [ -z "$ETCDIR" ]; then
214   ETCDIR=$PREFIX/etc
215 fi
216
217 if [ -z "$MANDIR" ]; then
218   MANDIR=$PREFIX/share/man
219 fi
220
221 if [ -z "$EXAMPLESDIR" ]; then
222   EXAMPLESDIR=$PREFIX/share/examples
223 fi
224
225 cat >> include.mk <<EOF
226 # this file was created automatically
227 # do not edit this file directly 
228 # use ./configure instead
229
230 TARGET = $TARGET
231 CXX = gcc
232 CXXFLAGS = $CXXFLAGS
233 LD = gcc
234 LDFLAGS = $LDFLAGS
235 STRIP = strip
236 INSTALL = install
237
238 PREFIX := $PREFIX
239 BINDIR := $BINDIR
240 SBINDIR := $SBINDIR
241 ETCDIR := $ETCDIR
242 EOF
243
244 if [ $INSTALLMANPAGE -eq 1 ]; then
245   echo "MANDIR := $MANDIR" >> include.mk
246   echo "installing manpage"
247 else
248   echo "not installing manpage"
249 fi
250
251 if [ $INSTALLEXAMPLES -eq 1 ]; then
252   echo "EXAMPLESDIR := $EXAMPLESDIR" >> include.mk
253   echo "installing example files"
254 else
255   echo "not installing example files"
256 fi
257
258 VERSION=`cat ../version`
259 if which svn >/dev/null; then
260   SVN_REV=`svn info | grep "^Revision: " | awk '{print($2)}'`
261   if [ -n "$SVN_REV" ]; then
262     VERSION="$VERSION (svn$SVN_REV)"
263   fi
264 fi
265 HOSTNAME=`hostname`
266 DATE=`date +"%d.%m.%Y %H:%M:%S %Z"`
267
268 cat >> version.h <<EOF
269 /* 
270  * anytun version info
271  *
272  * this file was created automatically
273  * do not edit this file directly
274  * use ./configure instead
275  */
276
277 #ifndef ANYTUN_version_h_INCLUDED
278 #define ANYTUN_version_h_INCLUDED
279
280 #define VERSION_STRING_0 " version $VERSION"
281 #define VERSION_STRING_1 "built on $HOSTNAME, $DATE"
282
283 #endif
284
285 EOF
286
287 exit 0