New upstream version 0.3.6
[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 case $CRYPTO_LIB in
287   gcrypt)
288     CXXFLAGS=$CXXFLAGS' -DUSE_GCRYPT'
289     LDFLAGS=$LDFLAGS' -lgcrypt -lgpg-error'
290     if [ -n "$GCRYPT_PREFIX" ]; then
291       CXXFLAGS="$CXXFLAGS -I\"$GCRYPT_PREFIX/include\""
292       LDFLAGS="$LDFLAGS -L\"$GCRYPT_PREFIX/lib\""
293     fi
294     echo "using gcrypt library"
295   ;;
296   nettle)
297     CXXFLAGS=$CXXFLAGS' -DUSE_NETTLE'
298     LDFLAGS=$LDFLAGS' -lnettle'
299     if [ -n "$NETTLE_PREFIX" ]; then
300       CXXFLAGS="$CXXFLAGS -I\"$NETTLE_PREFIX/include\""
301       LDFLAGS="$LDFLAGS -L\"$NETTLE_PREFIX/lib\""
302     fi
303     echo "using nettle library"
304   ;;
305   ssl)
306     CXXFLAGS=$CXXFLAGS' -DUSE_SSL_CRYPTO'
307     LDFLAGS=$LDFLAGS' -lcrypto'
308     if [ -n "$OPENSSL_PREFIX" ]; then
309       CXXFLAGS="$CXXFLAGS -I\"$OPENSSL_PREFIX/include\""
310       LDFLAGS="$LDFLAGS -L\"$OPENSSL_PREFIX/lib\""
311     fi
312     echo "using openssl crypto library"
313   ;;
314   none)
315     CXXFLAGS=$CXXFLAGS' -DNO_CRYPT'
316     echo "disabling crypto"
317   ;;
318 esac
319
320 if [ $PASSPHRASE -eq 0 ]; then
321   CXXFLAGS=$CXXFLAGS' -DNO_PASSPHRASE'
322   echo "disabling master key and salt passphrase"
323 fi
324
325 if [ $ROUTING -eq 0 ]; then
326   CXXFLAGS=$CXXFLAGS' -DNO_ROUTING'
327   echo "disabling built-in routing capability"
328 fi
329
330 if [ -z "$BINDIR" ]; then
331   BINDIR=$PREFIX/bin
332 fi
333
334 if [ -z "$SBINDIR" ]; then
335   SBINDIR=$PREFIX/sbin
336 fi
337
338 if [ -z "$LIBDIR" ]; then
339   LIBDIR=$PREFIX/lib
340 fi
341
342 if [ -z "$ETCDIR" ]; then
343   ETCDIR=$PREFIX/etc
344 fi
345
346 if [ -z "$MANDIR" ]; then
347   MANDIR=$PREFIX/share/man
348 fi
349
350 if [ -z "$EXAMPLESDIR" ]; then
351   EXAMPLESDIR=$PREFIX/share/examples
352 fi
353
354 if [ $INSTALLSYSTEMD -eq 1 ]; then
355   if [ -z "$SYSTEMDDIR" ]; then
356     SYSTEMDDIR=`pkg-config systemd --variable=systemdsystemunitdir`
357   fi
358   if [ -z "$SYSTEMDGENERATORDIR" ]; then
359     SYSTEMDGENERATORDIR=`pkg-config systemd --variable=systemdsystemgeneratordir`
360   fi
361   if [ -z "$TMPFILESDDIR" ]; then
362     TMPFILESDDIR=`pkg-config systemd --variable=tmpfilesdir`
363   fi
364 fi
365
366 cat > include.mk <<EOF
367 # this file was created automatically
368 # do not edit this file directly
369 # use ./configure instead
370
371 TARGET = $TARGET
372 CXX = ${CROSS_PREFIX}$COMPILER
373 CXXFLAGS = $CXXFLAGS
374 LD = ${CROSS_PREFIX}$COMPILER
375 LDFLAGS = $LDFLAGS
376 STRIP = ${CROSS_PREFIX}strip
377 INSTALL = install
378
379 prefix := $PREFIX
380 BINDIR := $BINDIR
381 SBINDIR := $SBINDIR
382 LIBDIR := $LIBDIR
383 ETCDIR := $ETCDIR
384 EOF
385
386 if [ $CRYPTO_LIB = "none" ]; then
387   echo "NO_CRYPT_OBJ = 1" >> include.mk
388 fi
389
390 if [ $INSTALLMANPAGE -eq 1 ]; then
391   echo "MANDIR := $MANDIR" >> include.mk
392   echo "installing manpage"
393 else
394   echo "not installing manpage"
395 fi
396
397 if [ $INSTALLEXAMPLES -eq 1 ]; then
398   echo "EXAMPLESDIR := $EXAMPLESDIR" >> include.mk
399   echo "installing example files"
400 else
401   echo "not installing example files"
402 fi
403
404 if [ $INSTALLSYSTEMD -eq 1 ]; then
405   echo "SYSTEMDDIR := $SYSTEMDDIR" >> include.mk
406   echo "SYSTEMDGENERATORDIR := $SYSTEMDGENERATORDIR" >> include.mk
407   echo "TMPFILESDDIR := $TMPFILESDDIR" >> include.mk
408   echo "installing systemd units"
409 else
410   echo "not installing systemd units"
411 fi
412
413 VERSION=`cat ../version`
414 if which git >/dev/null; then
415     GIT_HASH=`git rev-parse HEAD 2> /dev/null`
416     if [ -n "$GIT_HASH" ]; then
417         VERSION="$VERSION (git $GIT_HASH)"
418     fi
419 fi
420 HOSTNAME=`hostname`
421 DATE=`date +"%d.%m.%Y %H:%M:%S %Z"`
422
423 cat > version.h <<EOF
424 /*
425  * anytun version info
426  *
427  * this file was created automatically
428  * do not edit this file directly
429  * use ./configure instead
430  */
431
432 #ifndef ANYTUN_version_h_INCLUDED
433 #define ANYTUN_version_h_INCLUDED
434
435 #define VERSION_STRING_0 " version $VERSION"
436 #define VERSION_STRING_1 "built on $HOSTNAME, $DATE"
437
438 #endif
439 EOF
440
441 exit 0