Imported Upstream version 0.3.4
[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 -lpthread'
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 rm -f version.h
146 case $TARGET in
147   Linux)
148     rm -f tunDevice.cpp
149     ln -sf linux/tunDevice.cpp
150     rm -f signalHandler.hpp
151     ln -sf posix/signalHandler.hpp
152     rm -f sysExec.hpp
153     ln -sf posix/sysExec.hpp
154     rm -f daemonService.h daemonService.cpp
155     ln -sf posix/posixDaemon.h daemonService.h
156     ln -sf posix/posixDaemon.cpp daemonService.cpp
157     echo "loading Linux specific TUN Device"
158   ;;
159   OpenBSD|FreeBSD|NetBSD|GNU/kFreeBSD)
160     rm -f tunDevice.cpp
161     ln -sf bsd/tunDevice.cpp
162     rm -f signalHandler.hpp
163     ln -sf posix/signalHandler.hpp
164     rm -f sysExec.hpp
165     ln -sf posix/sysExec.hpp
166     rm -f daemonService.h daemonService.cpp
167     ln -sf posix/posixDaemon.h daemonService.h
168     ln -sf posix/posixDaemon.cpp daemonService.cpp
169     echo "loading BSD specific TUN Device"
170     CXXFLAGS=$CXXFLAGS' -I/usr/local/include'
171     LDFLAGS=$LDFLAGS' -L/usr/local/lib'
172   ;;
173   *)
174     echo "platform not supported"
175     exit 1
176   ;;
177 esac
178
179 case $CRYPTO_LIB in
180   gcrypt)
181     LDFLAGS=$LDFLAGS' -lgcrypt -lgpg-error'
182     echo "using libgcrypt library"
183   ;;
184   ssl)
185     CXXFLAGS=$CXXFLAGS' -DUSE_SSL_CRYPTO'
186     LDFLAGS=$LDFLAGS' -lcrypto'
187     echo "using ssl crypto library"
188   ;;
189   none)
190     CXXFLAGS=$CXXFLAGS' -DNO_CRYPT'
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 = g++
232 CXXFLAGS = $CXXFLAGS
233 LD = g++
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 [ $CRYPTO_LIB = "none" ]; then
245   echo "NO_CRYPT_OBJ = 1" >> include.mk
246 fi
247
248 if [ $INSTALLMANPAGE -eq 1 ]; then
249   echo "MANDIR := $MANDIR" >> include.mk
250   echo "installing manpage"
251 else
252   echo "not installing manpage"
253 fi
254
255 if [ $INSTALLEXAMPLES -eq 1 ]; then
256   echo "EXAMPLESDIR := $EXAMPLESDIR" >> include.mk
257   echo "installing example files"
258 else
259   echo "not installing example files"
260 fi
261
262 VERSION=`cat ../version`
263 if which svn >/dev/null; then
264   SVN_REV=`svn info 2> /dev/null | grep "^Revision: " | awk '{print($2)}'`
265   if [ -n "$SVN_REV" ]; then
266     VERSION="$VERSION (svn$SVN_REV)"
267   fi
268 fi
269 HOSTNAME=`hostname`
270 DATE=`date +"%d.%m.%Y %H:%M:%S %Z"`
271
272 cat > version.h <<EOF
273 /*
274  * anytun version info
275  *
276  * this file was created automatically
277  * do not edit this file directly
278  * use ./configure instead
279  */
280
281 #ifndef ANYTUN_version_h_INCLUDED
282 #define ANYTUN_version_h_INCLUDED
283
284 #define VERSION_STRING_0 " version $VERSION"
285 #define VERSION_STRING_1 "built on $HOSTNAME, $DATE"
286
287 #endif
288
289 EOF
290
291 exit 0