New upstream version 0.3.7
[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 LIBDIR=''
63 ETCDIR=''
64 MANDIR=''
65 INSTALLMANPAGE=1
66 EXAMPLESDIR=''
67 INSTALLEXAMPLES=1
68 SYSTEMDDIR=''
69 SYSTEMDGENERATORDIR=''
70 TMPFILESDDIR=''
71 INSTALLSYSTEMD=1
72
73 BOOST_PREFIX=''
74 GCRYPT_PREFIX=''
75 NETTLE_PREFIX=''
76 OPENSSL_PREFIX=''
77
78 print_usage() {
79   echo "configure --help                             print this"
80   echo "          --target=<TARGET>                  build target i.e. Linux (default: autodetect)"
81   echo "          --prefix=<PREFIX>                  the installation prefix (default: /usr/local)"
82   echo "          --bindir=<DIR>                     the path to the bin directory (default: $PREFIX/bin)"
83   echo "          --sbindir=<DIR>                    the path to the sbin directory (default: $PREFIX/sbin)"
84   echo "          --libdir=<DIR>                     the path to the lib directory (default: $PREFIX/lib)"
85   echo "          --sysconfdir=<DIR>                 the path to the system configuration directory (default: $PREFIX/etc"
86   echo "          --mandir=<DIR>                     the path to the system man pages (default: $PREFIX/share/man)"
87   echo "          --no-manpage                       don't install manpages"
88   echo "          --examplesdir=<DIR>                the path to the examples files (default: $PREFIX/share/examples)"
89   echo "          --no-examples                      don't install example files"
90   echo "          --systemddir=<DIR>                 the path to the systemd service unit directory (default: from pkg-config)"
91   echo "          --systemdgeneratordir=<DIR>        the path to the systemd generator directory (default: from pkg-config)"
92   echo "          --tmpfilesddir=<DIR>               the path to the systemd tmpfiles.d configuration file (default: from pkg-config)"
93   echo "          --no-systemd                       don't install systemd units"
94   echo "          --use-gcrypt                       use libgcrypt (this is the default)"
95   echo "          --use-nettle                       use libnettle instead of libgcrypt"
96   echo "          --use-ssl-crypto                   use openssl crypto library instead of libgcrypt"
97   echo "          --no-crypto                        disable crypto at all (only NULL cipher)"
98   echo "          --disable-passphrase               disable master key and salt passphrase"
99   echo "          --enable-passphrase                enable master key and salt passphrase"
100   echo "          --disable-routing                  disable built-in routing capability"
101   echo "          --enable-routing                   enable built-in routing capability"
102   echo "          --cross-prefix=<PREFIX>            add PREFIX to compiler calls"
103   echo "          --with-boost=<PREFIX>              don't use systemwide boost"
104   echo "          --with-gcrypt=<PREFIX>             don't use systemwide gcrypt"
105   echo "          --with-nettle=<PREFIX>             don't use systemwide nettle"
106   echo "          --with-openssl=<PREFIX>            don't use systemwide openssl"
107   echo "          --use-clang                        use clang/llvm as compiler/linker"
108 }
109
110 for arg
111 do
112   case $arg in
113   --target=*)
114     TARGET=${arg#--target=}
115   ;;
116   --use-clang)
117     USE_CLANG=1
118   ;;
119   --prefix=*)
120     PREFIX=${arg#--prefix=}
121   ;;
122   --bindir=*)
123     SBINDIR=${arg#--bindir=}
124   ;;
125   --sbindir=*)
126     SBINDIR=${arg#--sbindir=}
127   ;;
128   --libdir=*)
129     LIBDIR=${arg#--libdir=}
130   ;;
131   --sysconfdir=*)
132     ETCDIR=${arg#--sysconfdir=}
133   ;;
134   --mandir=*)
135     MANDIR=${arg#--mandir=}
136   ;;
137   --no-manpage)
138     INSTALLMANPAGE=0
139   ;;
140   --examplesdir=*)
141     EXAMPLESDIR=${arg#--examplesdir=}
142   ;;
143   --no-examples)
144     INSTALLEXAMPLES=0
145   ;;
146   --systemddir=*)
147     SYSTEMDDIR=${arg#--systemddir=}
148   ;;
149   --systemdgeneratordir=*)
150     SYSTEMDGENERATORDIR=${arg#--systemdgeneratordir=}
151   ;;
152   --tmpfilesddir=*)
153     TMPFILESDDIR=${arg#--tmpfilesddir=}
154   ;;
155   --no-systemd)
156     INSTALLSYSTEMD=0
157   ;;
158   --use-gcrypt)
159     CRYPTO_LIB='gcrypt'
160   ;;
161   --use-nettle)
162     CRYPTO_LIB='nettle'
163   ;;
164   --use-ssl-crypto)
165     CRYPTO_LIB='ssl'
166   ;;
167   --no-crypto)
168     CRYPTO_LIB='none'
169   ;;
170   --enable-passphrase)
171     PASSPHRASE=1
172   ;;
173   --disable-passphrase)
174     PASSPHRASE=0
175   ;;
176   --enable-routing)
177     ROUTING=1
178   ;;
179   --disable-routing)
180     ROUTING=0
181   ;;
182   --ebuild-compat)
183     EBUILD_COMPAT=1
184   ;;
185   --cross-prefix=*)
186     CROSS_PREFIX=${arg#--cross-prefix=}
187   ;;
188   --with-boost=*)
189     BOOST_PREFIX=${arg#--with-boost=}
190   ;;
191   --with-gcrypt=*)
192     GCRYPT_PREFIX=${arg#--with-gcrypt=}
193   ;;
194   --with-nettle=*)
195     NETTLE_PREFIX=${arg#--with-nettle=}
196   ;;
197   --with-openssl=*)
198     OPENSSL_PREFIX=${arg#--with-openssl=}
199   ;;
200   --help)
201     print_usage
202     exit 0
203   ;;
204   *)
205     ERRORS="$ERRORS $arg"
206   ;;
207   esac
208 done
209
210 if [ -n "$ERRORS" ] && [ $EBUILD_COMPAT -ne 1 ]; then
211   for error in $ERRORS; do
212     echo "Unknown argument: $error"
213   done
214
215   print_usage
216   exit 1
217 fi
218
219 if [ $USE_CLANG -eq 0 ]; then
220   CXXFLAGS='-g -Wall -Werror -Wno-error=unused-variable -O2'
221   LDFLAGS='-g -Wall -Werror -O2'
222   COMPILER='g++'
223 else
224   CXXFLAGS='-g -O2'
225   LDFLAGS='-g -O2'
226   COMPILER='clang++'
227 fi
228
229 rm -f include.mk
230 rm -f version.h
231 case $TARGET in
232   Linux)
233     rm -f tunDevice.cpp
234     ln -sf linux/tunDevice.cpp
235     rm -f signalHandler.hpp
236     ln -sf posix/signalHandler.hpp
237     rm -f sysExec.hpp
238     ln -sf posix/sysExec.hpp
239     rm -f daemonService.h daemonService.cpp
240     ln -sf posix/posixDaemon.h daemonService.h
241     ln -sf posix/posixDaemon.cpp daemonService.cpp
242     echo "loading Linux specific TUN Device"
243     LDFLAGS=$LDFLAGS' -lboost_thread -lboost_serialization -lboost_system -lboost_date_time -lpthread'
244     LOG_TARGETS='-DLOG_SYSLOG -DLOG_FILE -DLOG_STDOUT'
245   ;;
246   OpenBSD|FreeBSD|NetBSD|GNU/kFreeBSD)
247     rm -f tunDevice.cpp
248     ln -sf bsd/tunDevice.cpp
249     rm -f signalHandler.hpp
250     ln -sf posix/signalHandler.hpp
251     rm -f sysExec.hpp
252     ln -sf posix/sysExec.hpp
253     rm -f daemonService.h daemonService.cpp
254     ln -sf posix/posixDaemon.h daemonService.h
255     ln -sf posix/posixDaemon.cpp daemonService.cpp
256     echo "loading BSD specific TUN Device"
257     CXXFLAGS=$CXXFLAGS' -I/usr/local/include'
258     LDFLAGS=$LDFLAGS' -L/usr/local/lib  -lboost_thread -lboost_serialization -lboost_system -lboost_date_time -lpthread'
259     LOG_TARGETS='-DLOG_SYSLOG -DLOG_FILE -DLOG_STDOUT'
260     INSTALLSYSTEMD=0
261   ;;
262   mingw)
263     rm -f tunDevice.cpp
264     rm -f signalHandler.hpp
265     rm -f sysExec.hpp
266     rm -f daemonService.h daemonService.cpp
267     echo "loading Windows specific TUN Device"
268     CXXFLAGS=$CXXFLAGS' -DMINGW -D_WIN32_WINNT=0x0501 -DWIN32_LEAN_AND_MEAN -DBOOST_WINDOWS -fno-strict-aliasing -DBOOST_THREAD_USE_LIB'
269     LDFLAGS=$LDFLAGS'  -lboost_thread_win32 -lboost_serialization -lboost_system -lboost_date_time -lwsock32 -lws2_32'
270     LOG_TARGETS='-DWIN_EVENTLOG -DLOG_FILE -DLOG_STDOUT'
271     INSTALLSYSTEMD=0
272   ;;
273   *)
274     echo "platform not supported"
275     exit 1
276   ;;
277 esac
278
279 CXXFLAGS="$CXXFLAGS $LOG_TARGETS"
280
281 if [ -n "$BOOST_PREFIX" ]; then
282   CXXFLAGS="$CXXFLAGS -I\"$BOOST_PREFIX/include\""
283   LDFLAGS="$LDFLAGS -L\"$BOOST_PREFIX/lib\""
284 fi
285
286 CRYPTO_LIB_NAME=""
287 case $CRYPTO_LIB in
288   gcrypt)
289     CXXFLAGS=$CXXFLAGS' -DUSE_GCRYPT'
290     LDFLAGS=$LDFLAGS' -lgcrypt -lgpg-error'
291     if [ -n "$GCRYPT_PREFIX" ]; then
292       CXXFLAGS="$CXXFLAGS -I\"$GCRYPT_PREFIX/include\""
293       LDFLAGS="$LDFLAGS -L\"$GCRYPT_PREFIX/lib\""
294     fi
295     CRYPTO_LIB_NAME="libgcrypt"
296     echo "using gcrypt library"
297   ;;
298   nettle)
299     CXXFLAGS=$CXXFLAGS' -DUSE_NETTLE'
300     LDFLAGS=$LDFLAGS' -lnettle'
301     if [ -n "$NETTLE_PREFIX" ]; then
302       CXXFLAGS="$CXXFLAGS -I\"$NETTLE_PREFIX/include\""
303       LDFLAGS="$LDFLAGS -L\"$NETTLE_PREFIX/lib\""
304     fi
305     CRYPTO_LIB_NAME="Nettle"
306     echo "using nettle library"
307   ;;
308   ssl)
309     CXXFLAGS=$CXXFLAGS' -DUSE_SSL_CRYPTO'
310     LDFLAGS=$LDFLAGS' -lcrypto'
311     if [ -n "$OPENSSL_PREFIX" ]; then
312       CXXFLAGS="$CXXFLAGS -I\"$OPENSSL_PREFIX/include\""
313       LDFLAGS="$LDFLAGS -L\"$OPENSSL_PREFIX/lib\""
314     fi
315     CRYPTO_LIB_NAME="OpenSSL"
316     echo "using openssl crypto library"
317   ;;
318   none)
319     CXXFLAGS=$CXXFLAGS' -DNO_CRYPT'
320     CRYPTO_LIB_NAME="none"
321     echo "disabling crypto"
322   ;;
323 esac
324
325 if [ $PASSPHRASE -eq 0 ]; then
326   CXXFLAGS=$CXXFLAGS' -DNO_PASSPHRASE'
327   echo "disabling master key and salt passphrase"
328 fi
329
330 if [ $ROUTING -eq 0 ]; then
331   CXXFLAGS=$CXXFLAGS' -DNO_ROUTING'
332   echo "disabling built-in routing capability"
333 fi
334
335 if [ -z "$BINDIR" ]; then
336   BINDIR=$PREFIX/bin
337 fi
338
339 if [ -z "$SBINDIR" ]; then
340   SBINDIR=$PREFIX/sbin
341 fi
342
343 if [ -z "$LIBDIR" ]; then
344   LIBDIR=$PREFIX/lib
345 fi
346
347 if [ -z "$ETCDIR" ]; then
348   ETCDIR=$PREFIX/etc
349 fi
350
351 if [ -z "$MANDIR" ]; then
352   MANDIR=$PREFIX/share/man
353 fi
354
355 if [ -z "$EXAMPLESDIR" ]; then
356   EXAMPLESDIR=$PREFIX/share/examples
357 fi
358
359 if [ $INSTALLSYSTEMD -eq 1 ]; then
360   if [ -z "$SYSTEMDDIR" ]; then
361     SYSTEMDDIR=`pkg-config systemd --variable=systemdsystemunitdir`
362   fi
363   if [ -z "$SYSTEMDGENERATORDIR" ]; then
364     SYSTEMDGENERATORDIR=`pkg-config systemd --variable=systemdsystemgeneratordir`
365   fi
366   if [ -z "$TMPFILESDDIR" ]; then
367     TMPFILESDDIR=`pkg-config systemd --variable=tmpfilesdir`
368   fi
369 fi
370
371 cat > include.mk <<EOF
372 # this file was created automatically
373 # do not edit this file directly
374 # use ./configure instead
375
376 TARGET = $TARGET
377 CXX = ${CROSS_PREFIX}$COMPILER
378 CXXFLAGS = $CXXFLAGS
379 LD = ${CROSS_PREFIX}$COMPILER
380 LDFLAGS = $LDFLAGS
381 STRIP = ${CROSS_PREFIX}strip
382 INSTALL = install
383
384 prefix := $PREFIX
385 BINDIR := $BINDIR
386 SBINDIR := $SBINDIR
387 LIBDIR := $LIBDIR
388 ETCDIR := $ETCDIR
389 EOF
390
391 if [ $CRYPTO_LIB = "none" ]; then
392   echo "NO_CRYPT_OBJ = 1" >> include.mk
393 fi
394
395 if [ $INSTALLMANPAGE -eq 1 ]; then
396   echo "MANDIR := $MANDIR" >> include.mk
397   echo "installing manpage"
398 else
399   echo "not installing manpage"
400 fi
401
402 if [ $INSTALLEXAMPLES -eq 1 ]; then
403   echo "EXAMPLESDIR := $EXAMPLESDIR" >> include.mk
404   echo "installing example files"
405 else
406   echo "not installing example files"
407 fi
408
409 if [ $INSTALLSYSTEMD -eq 1 ]; then
410   echo "SYSTEMDDIR := $SYSTEMDDIR" >> include.mk
411   echo "SYSTEMDGENERATORDIR := $SYSTEMDGENERATORDIR" >> include.mk
412   echo "TMPFILESDDIR := $TMPFILESDDIR" >> include.mk
413   echo "installing systemd units"
414 else
415   echo "not installing systemd units"
416 fi
417
418 VERSION=`cat ../version`
419 if which git >/dev/null; then
420     GIT_HASH=`git rev-parse HEAD 2> /dev/null`
421     if [ -n "$GIT_HASH" ]; then
422         VERSION="$VERSION (git $GIT_HASH)"
423     fi
424 fi
425
426 cat > version.h <<EOF
427 /*
428  * anytun version info
429  *
430  * this file was created automatically
431  * do not edit this file directly
432  * use ./configure instead
433  */
434
435 #ifndef ANYTUN_version_h_INCLUDED
436 #define ANYTUN_version_h_INCLUDED
437
438 #define VERSION_STRING " version $VERSION"
439 #define CRYPTO_LIB_NAME "$CRYPTO_LIB_NAME"
440
441 #endif
442 EOF
443
444 exit 0