Imported Upstream version 0.3.5
[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 methods 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-2014 Markus Grüneis, 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 #  In addition, as a special exception, the copyright holders give
34 #  permission to link the code of portions of this program with the
35 #  OpenSSL library under certain conditions as described in each
36 #  individual source file, and distribute linked combinations
37 #  including the two.
38 #  You must obey the GNU General Public License in all respects
39 #  for all of the code used other than OpenSSL.  If you modify
40 #  file(s) with this exception, you may extend this exception to your
41 #  version of the file(s), but you are not obligated to do so.  If you
42 #  do not wish to do so, delete this exception statement from your
43 #  version.  If you delete this exception statement from all source
44 #  files in the program, then also delete it here.
45 #
46
47 TARGET=`uname -s`
48
49 EBUILD_COMPAT=0
50
51 CROSS_PREFIX=''
52
53 USE_CLANG=0
54
55 CRYPTO_LIB='gcrypt'
56 PASSPHRASE=1
57 ROUTING=1
58
59 PREFIX='/usr/local'
60 BINDIR=''
61 SBINDIR=''
62 ETCDIR=''
63 MANDIR=''
64 INSTALLMANPAGE=1
65 EXAMPLESDIR=''
66 INSTALLEXAMPLES=1
67
68 BOOST_PREFIX=''
69 GCRYPT_PREFIX=''
70 NETTLE_PREFIX=''
71 OPENSSL_PREFIX=''
72
73 print_usage() {
74   echo "configure --help                    print this"
75   echo "          --target=<TARGET>         build target i.e. Linux (default: autodetect)"
76   echo "          --prefix=<PREFIX>         the installation prefix (default: /usr/local)"
77   echo "          --bindir=<DIR>            the path to the bin directory (default: $PREFIX/bin)"
78   echo "          --sbindir=<DIR>           the path to the sbin directory (default: $PREFIX/sbin)"
79   echo "          --sysconfdir=<DIR>        the path to the system configuration directory (default: $PREFIX/etc"
80   echo "          --mandir=<DIR>            the path to the system man pages (default: $PREFIX/share/man)"
81   echo "          --no-manpage              dont't install manpages"
82   echo "          --examplesdir=<DIR>       the path to the examples files (default: $PREFIX/share/examples)"
83   echo "          --no-examples             dont't install example files"
84   echo "          --use-gcrypt              use libgcrypt (this is the default)"
85   echo "          --use-nettle              use libnettle instead of libgcrypt"
86   echo "          --use-ssl-crypto          use openssl crypto library instead of libgcrypt"
87   echo "          --no-crypto               disable crypto at all (only NULL cipher)"
88   echo "          --disable-passphrase      disable master key and salt passphrase"
89   echo "          --enable-passphrase       enable master key and salt passphrase"
90   echo "          --disable-routing         disable built-in routing capability"
91   echo "          --enable-routing          enable built-in routing capability"
92   echo "          --cross-prefix=<PREFIX>   add PREFIX to compiler calls"
93   echo "          --with-boost=<PREFIX>     don't use systemwide boost"
94   echo "          --with-gcrypt=<PREFIX>    don't use systemwide gcrypt"
95   echo "          --with-nettle=<PREFIX>    don't use systemwide nettle"
96   echo "          --with-openssl=<PREFIX>   don't use systemwide openssl"
97   echo "          --use-clang               use clang/llvm as compiler/linker"
98 }
99
100 for arg
101 do
102   case $arg in
103   --target=*)
104     TARGET=${arg#--target=}
105   ;;
106   --use-clang)
107     USE_CLANG=1
108   ;;
109   --prefix=*)
110     PREFIX=${arg#--prefix=}
111   ;;
112   --bindir=*)
113     SBINDIR=${arg#--bindir=}
114   ;;
115   --sbindir=*)
116     SBINDIR=${arg#--sbindir=}
117   ;;
118   --sysconfdir=*)
119     ETCDIR=${arg#--sysconfdir=}
120   ;;
121   --mandir=*)
122     MANDIR=${arg#--mandir=}
123   ;;
124   --no-manpage)
125     INSTALLMANPAGE=0
126   ;;
127   --examplesdir=*)
128     EXAMPLESDIR=${arg#--examplesdir=}
129   ;;
130   --no-examples)
131     INSTALLEXAMPLES=0
132   ;;
133   --use-gcrypt)
134     CRYPTO_LIB='gcrypt'
135   ;;
136   --use-nettle)
137     CRYPTO_LIB='nettle'
138   ;;
139   --use-ssl-crypto)
140     CRYPTO_LIB='ssl'
141   ;;
142   --no-crypto)
143     CRYPTO_LIB='none'
144   ;;
145   --enable-passphrase)
146     PASSPHRASE=1
147   ;;
148   --disable-passphrase)
149     PASSPHRASE=0
150   ;;
151   --enable-routing)
152     ROUTING=1
153   ;;
154   --disable-routing)
155     ROUTING=0
156   ;;
157   --ebuild-compat)
158     EBUILD_COMPAT=1
159   ;;
160   --cross-prefix=*)
161     CROSS_PREFIX=${arg#--cross-prefix=}
162   ;;
163   --with-boost=*)
164     BOOST_PREFIX=${arg#--with-boost=}
165   ;;
166   --with-gcrypt=*)
167     GCRYPT_PREFIX=${arg#--with-gcrypt=}
168   ;;
169   --with-nettle=*)
170     NETTLE_PREFIX=${arg#--with-nettle=}
171   ;;
172   --with-openssl=*)
173     OPENSSL_PREFIX=${arg#--with-openssl=}
174   ;;
175   --help)
176     print_usage
177     exit 0
178   ;;
179   *)
180     ERRORS="$ERRORS $arg"
181   ;;
182   esac
183 done
184
185 if [ -n "$ERRORS" ] && [ $EBUILD_COMPAT -ne 1 ]; then
186   for error in $ERRORS; do
187     echo "Unknown argument: $error"
188   done
189
190   print_usage
191   exit 1
192 fi
193
194 if [ $USE_CLANG -eq 0 ]; then
195   CXXFLAGS='-g -Wall -O2'
196   LDFLAGS='-g -Wall -O2'
197   COMPILER='g++'
198 else
199   CXXFLAGS='-g -O2'
200   LDFLAGS='-g -O2'
201   COMPILER='clang++'
202 fi
203
204 rm -f include.mk
205 rm -f version.h
206 case $TARGET in
207   Linux)
208     rm -f tunDevice.cpp
209     ln -sf linux/tunDevice.cpp
210     rm -f signalHandler.hpp
211     ln -sf posix/signalHandler.hpp
212     rm -f sysExec.hpp
213     ln -sf posix/sysExec.hpp
214     rm -f daemonService.h daemonService.cpp
215     ln -sf posix/posixDaemon.h daemonService.h
216     ln -sf posix/posixDaemon.cpp daemonService.cpp
217     echo "loading Linux specific TUN Device"
218     LDFLAGS=$LDFLAGS' -lboost_thread -lboost_serialization -lboost_system -lboost_date_time -lpthread'
219     LOG_TARGETS='-DLOG_SYSLOG -DLOG_FILE -DLOG_STDOUT'
220   ;;
221   OpenBSD|FreeBSD|NetBSD|GNU/kFreeBSD)
222     rm -f tunDevice.cpp
223     ln -sf bsd/tunDevice.cpp
224     rm -f signalHandler.hpp
225     ln -sf posix/signalHandler.hpp
226     rm -f sysExec.hpp
227     ln -sf posix/sysExec.hpp
228     rm -f daemonService.h daemonService.cpp
229     ln -sf posix/posixDaemon.h daemonService.h
230     ln -sf posix/posixDaemon.cpp daemonService.cpp
231     echo "loading BSD specific TUN Device"
232     CXXFLAGS=$CXXFLAGS' -I/usr/local/include'
233     LDFLAGS=$LDFLAGS' -L/usr/local/lib  -lboost_thread -lboost_serialization -lboost_system -lboost_date_time -lpthread'
234     LOG_TARGETS='-DLOG_SYSLOG -DLOG_FILE -DLOG_STDOUT'
235   ;;
236   mingw)
237     rm -f tunDevice.cpp
238     rm -f signalHandler.hpp
239     rm -f sysExec.hpp
240     rm -f daemonService.h daemonService.cpp
241     echo "loading Windows specific TUN Device"
242     CXXFLAGS=$CXXFLAGS' -DMINGW -D_WIN32_WINNT=0x0501 -DWIN32_LEAN_AND_MEAN -DBOOST_WINDOWS -fno-strict-aliasing -DBOOST_THREAD_USE_LIB'
243     LDFLAGS=$LDFLAGS'  -lboost_thread_win32 -lboost_serialization -lboost_system -lboost_date_time -lwsock32 -lws2_32'
244     LOG_TARGETS='-DWIN_EVENTLOG -DLOG_FILE -DLOG_STDOUT'
245   ;;
246   *)
247     echo "platform not supported"
248     exit 1
249   ;;
250 esac
251
252 CXXFLAGS="$CXXFLAGS $LOG_TARGETS"
253
254 if [ -n "$BOOST_PREFIX" ]; then
255   CXXFLAGS="$CXXFLAGS -I\"$BOOST_PREFIX/include\""
256   LDFLAGS="$LDFLAGS -L\"$BOOST_PREFIX/lib\""
257 fi
258
259 case $CRYPTO_LIB in
260   gcrypt)
261     CXXFLAGS=$CXXFLAGS' -DUSE_GCRYPT'
262     LDFLAGS=$LDFLAGS' -lgcrypt -lgpg-error'
263     if [ -n "$GCRYPT_PREFIX" ]; then
264       CXXFLAGS="$CXXFLAGS -I\"$GCRYPT_PREFIX/include\""
265       LDFLAGS="$LDFLAGS -L\"$GCRYPT_PREFIX/lib\""
266     fi
267     echo "using gcrypt library"
268   ;;
269   nettle)
270     CXXFLAGS=$CXXFLAGS' -DUSE_NETTLE'
271     LDFLAGS=$LDFLAGS' -lnettle'
272     if [ -n "$NETTLE_PREFIX" ]; then
273       CXXFLAGS="$CXXFLAGS -I\"$NETTLE_PREFIX/include\""
274       LDFLAGS="$LDFLAGS -L\"$NETTLE_PREFIX/lib\""
275     fi
276     echo "using nettle library"
277   ;;
278   ssl)
279     CXXFLAGS=$CXXFLAGS' -DUSE_SSL_CRYPTO'
280     LDFLAGS=$LDFLAGS' -lcrypto'
281     if [ -n "$OPENSSL_PREFIX" ]; then
282       CXXFLAGS="$CXXFLAGS -I\"$OPENSSL_PREFIX/include\""
283       LDFLAGS="$LDFLAGS -L\"$OPENSSL_PREFIX/lib\""
284     fi
285     echo "using openssl crypto library"
286   ;;
287   none)
288     CXXFLAGS=$CXXFLAGS' -DNO_CRYPT'
289     echo "disabling crypto"
290   ;;
291 esac
292
293 if [ $PASSPHRASE -eq 0 ]; then
294   CXXFLAGS=$CXXFLAGS' -DNO_PASSPHRASE'
295   echo "disabling master key and salt passphrase"
296 fi
297
298 if [ $ROUTING -eq 0 ]; then
299   CXXFLAGS=$CXXFLAGS' -DNO_ROUTING'
300   echo "disabling built-in routing capability"
301 fi
302
303 if [ -z "$BINDIR" ]; then
304   BINDIR=$PREFIX/bin
305 fi
306
307 if [ -z "$SBINDIR" ]; then
308   SBINDIR=$PREFIX/sbin
309 fi
310
311 if [ -z "$ETCDIR" ]; then
312   ETCDIR=$PREFIX/etc
313 fi
314
315 if [ -z "$MANDIR" ]; then
316   MANDIR=$PREFIX/share/man
317 fi
318
319 if [ -z "$EXAMPLESDIR" ]; then
320   EXAMPLESDIR=$PREFIX/share/examples
321 fi
322
323 cat > include.mk <<EOF
324 # this file was created automatically
325 # do not edit this file directly
326 # use ./configure instead
327
328 TARGET = $TARGET
329 CXX = ${CROSS_PREFIX}$COMPILER
330 CXXFLAGS = $CXXFLAGS
331 LD = ${CROSS_PREFIX}$COMPILER
332 LDFLAGS = $LDFLAGS
333 STRIP = ${CROSS_PREFIX}strip
334 INSTALL = install
335
336 PREFIX := $PREFIX
337 BINDIR := $BINDIR
338 SBINDIR := $SBINDIR
339 ETCDIR := $ETCDIR
340 EOF
341
342 if [ $CRYPTO_LIB = "none" ]; then
343   echo "NO_CRYPT_OBJ = 1" >> include.mk
344 fi
345
346 if [ $INSTALLMANPAGE -eq 1 ]; then
347   echo "MANDIR := $MANDIR" >> include.mk
348   echo "installing manpage"
349 else
350   echo "not installing manpage"
351 fi
352
353 if [ $INSTALLEXAMPLES -eq 1 ]; then
354   echo "EXAMPLESDIR := $EXAMPLESDIR" >> include.mk
355   echo "installing example files"
356 else
357   echo "not installing example files"
358 fi
359
360 VERSION=`cat ../version`
361 if which svn >/dev/null; then
362   SVN_REV=`svn info 2> /dev/null | grep "^Revision: " | awk '{print($2)}'`
363   if [ -n "$SVN_REV" ]; then
364     VERSION="$VERSION (svn$SVN_REV)"
365   fi
366 fi
367 HOSTNAME=`hostname`
368 DATE=`date +"%d.%m.%Y %H:%M:%S %Z"`
369
370 cat > version.h <<EOF
371 /*
372  * anytun version info
373  *
374  * this file was created automatically
375  * do not edit this file directly
376  * use ./configure instead
377  */
378
379 #ifndef ANYTUN_version_h_INCLUDED
380 #define ANYTUN_version_h_INCLUDED
381
382 #define VERSION_STRING_0 " version $VERSION"
383 #define VERSION_STRING_1 "built on $HOSTNAME, $DATE"
384
385 #endif
386
387 EOF
388
389 exit 0