Imported Upstream version 0.3.2
[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 -rf tunDevice.cpp
148                 ln -sf linux/tunDevice.cpp 
149     echo "loading Linux specific TUN Device"
150         ;;
151         OpenBSD|FreeBSD|NetBSD)
152                 rm -rf tunDevice.cpp
153                 ln -sf bsd/tunDevice.cpp 
154     echo "loading BSD specific TUN Device"
155     CXXFLAGS=$CXXFLAGS' -I/usr/local/include'
156     LDFLAGS=$LDFLAGS' -L/usr/local/lib'
157         ;;
158         *)
159                 echo "Plattform not supported"
160     exit 1
161         ;;
162 esac
163
164 case $CRYPTO_LIB in
165   gcrypt)
166     LDFLAGS=$LDFLAGS' -lgcrypt -lgpg-error'
167     echo "using libgcrypt library"
168   ;;
169   ssl)
170     CXXFLAGS=$CXXFLAGS' -DUSE_SSL_CRYPTO'
171     LDFLAGS=$LDFLAGS' -lcrypto'
172     echo "using ssl crypto library"
173   ;;
174   none)
175     CXXFLAGS=$CXXFLAGS' -DNO_CRYPT'
176     echo "NO_CRYPT_OBJ = 1" >> include.mk
177     echo "disabling crypto"
178   ;;
179 esac
180
181 if [ $PASSPHRASE -eq 0 ]; then
182   CXXFLAGS=$CXXFLAGS' -DNO_PASSPHRASE'
183   echo "disabling master key and salt passphrase"
184 fi
185
186 if [ $ROUTING -eq 0 ]; then
187   CXXFLAGS=$CXXFLAGS' -DNO_ROUTING'
188   echo "disabling built-in routing capability"
189 fi
190
191 if [ -z "$BINDIR" ]; then
192   BINDIR=$PREFIX/bin
193 fi
194
195 if [ -z "$SBINDIR" ]; then
196   SBINDIR=$PREFIX/sbin
197 fi
198
199 if [ -z "$ETCDIR" ]; then
200   ETCDIR=$PREFIX/etc
201 fi
202
203 if [ -z "$MANDIR" ]; then
204   MANDIR=$PREFIX/share/man
205 fi
206
207 if [ -z "$EXAMPLESDIR" ]; then
208   EXAMPLESDIR=$PREFIX/share/examples
209 fi
210
211 cat >> include.mk <<EOF
212 # this file was created automatically
213 # do not edit this file directly 
214 # use ./configure instead
215
216 TARGET = $TARGET
217 CXX = gcc
218 CXXFLAGS = $CXXFLAGS
219 LD = gcc
220 LDFLAGS = $LDFLAGS
221 STRIP = strip
222 INSTALL = install
223
224 PREFIX := $PREFIX
225 BINDIR := $BINDIR
226 SBINDIR := $SBINDIR
227 ETCDIR := $ETCDIR
228 EOF
229
230 if [ $INSTALLMANPAGE -eq 1 ]; then
231   echo "MANDIR := $MANDIR" >> include.mk
232   echo "installing manpage"
233 else
234   echo "not installing manpage"
235 fi
236
237 if [ $INSTALLEXAMPLES -eq 1 ]; then
238   echo "EXAMPLESDIR := $EXAMPLESDIR" >> include.mk
239   echo "installing example files"
240 else
241   echo "not installing example files"
242 fi
243
244 exit 0