Add DTLS support for GnuTLS
[platform/upstream/openconnect.git] / configure.ac
1 AC_INIT(openconnect, 3.20)
2 PKG_PROG_PKG_CONFIG
3 AC_LANG_C
4 AC_CANONICAL_HOST
5 AM_MAINTAINER_MODE([enable])
6 AM_INIT_AUTOMAKE([foreign])
7 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
8
9 # Define htmldir and localedir for users of ancient autoconf building from git
10 AC_PREREQ([2.59c], [], [AC_SUBST([htmldir], [m4_ifset([AC_PACKAGE_TARNAME],
11           ['${datadir}/doc/${PACKAGE_TARNAME}'],
12           ['${datadir}/doc/${PACKAGE}'])
13 ])])
14
15 AC_PREREQ([2.60], [], [AC_SUBST([localedir], ['$(datadir)/locale'])])
16
17 # Upstream's pkg.m4 (since 0.27) offers this now, but define our own
18 # compatible version in case the local version of pkgconfig isn't new enough.
19 # https://bugs.freedesktop.org/show_bug.cgi?id=48743
20 m4_ifdef([PKG_INSTALLDIR], [PKG_INSTALLDIR],
21           [AC_ARG_WITH([pkgconfigdir],
22                        [AS_HELP_STRING([--with-pkgconfigdir],
23                        [install directory for openconnect.pc pkg-config file])],
24                         [],[with_pkgconfigdir='$(libdir)/pkgconfig'])
25            AC_SUBST([pkgconfigdir], [${with_pkgconfigdir}])])
26
27 AC_ARG_WITH([vpnc-script],
28         [AS_HELP_STRING([--with-vpnc-script],
29           [default location of vpnc-script helper])])
30
31 if test "$with_vpnc_script" = "yes" || test "$with_vpnc_script" = ""; then
32    with_vpnc_script=/etc/vpnc/vpnc-script
33    if ! test -x "$with_vpnc_script"; then
34       AC_MSG_ERROR([${with_vpnc_script} does not seem to be executable.]
35     [OpenConnect will not function correctly without a vpnc-script.]
36     [See http://www.infradead.org/openconnect/vpnc-script.html for more details.]
37     []
38     [If you are building a distribution package, please ensure that your]
39     [packaging is correct, and that a vpnc-script will be installed when the]
40     [user installs your package. You should provide a --with-vpnc-script=]
41     [argument to this configure script, giving the full path where the script]
42     [will be installed.]
43     []
44     [The standard location is ${with_vpnc_script}. To bypass this error and]
45     [build OpenConnect to use the script from this location, even though it's]
46     [not present at the time you are building OpenConnect, pass the argument]
47     ["--with-vpnc-script=${with_vpnc_script}"])
48   fi
49 elif test "$with_vpnc_script" = "no"; then
50    AC_ERROR([You cannot disable vpnc-script.]
51    [OpenConnect will not function correctly without it.]
52    [See http://www.infradead.org/openconnect/vpnc-script.html])
53 fi
54
55 AC_DEFINE_UNQUOTED(DEFAULT_VPNCSCRIPT, "${with_vpnc_script}")
56
57 case $host_os in
58  *linux* | *gnu*)
59     AC_MSG_NOTICE([Applying feature macros for GNU build])
60     AC_DEFINE(_POSIX_C_SOURCE, 200112L)
61     # For strcasecmp() 
62     AC_DEFINE(_BSD_SOURCE)
63     # For asprintf()
64     AC_DEFINE(_GNU_SOURCE)
65     ;;
66  *netbsd*)
67     AC_MSG_NOTICE([Applying feature macros for NetBSD build])
68     AC_DEFINE(_POSIX_C_SOURCE, 200112L)
69     AC_DEFINE(_NETBSD_SOURCE)
70     ;;
71  *)
72     # On FreeBSD the only way to get vsyslog() visible is to define
73     #  *nothing*, which makes absolutely everything visible.
74     # On Darwin enabling _POSIX_C_SOURCE breaks <sys/mount.h> because
75     # u_long and other types don't get defined. OpenBSD is similar.
76     ;;
77 esac
78
79 symver_time=
80 symver_getline=
81 symver_asprintf=
82
83 case $host_os in
84  *solaris*|*sunos*)
85     symver_time="openconnect__time;"
86     ;;
87 esac
88
89 AC_CHECK_FUNC(fdevname_r, [AC_DEFINE(HAVE_FDEVNAME_R, 1)], [])
90 AC_CHECK_FUNC(getline, [AC_DEFINE(HAVE_GETLINE, 1)], [symver_getline="openconnect__getline;"])
91 AC_CHECK_FUNC(strcasestr, [AC_DEFINE(HAVE_STRCASESTR, 1)], [])
92 AC_CHECK_FUNC(asprintf, [AC_DEFINE(HAVE_ASPRINTF, 1)], [symver_asprintf="openconnect__asprintf;"])
93 if test -n "$symver_asprintf"; then
94   AC_MSG_CHECKING([for va_copy])
95   AC_LINK_IFELSE([AC_LANG_PROGRAM([
96         #include <stdarg.h>
97         va_list a;],[
98         va_list b;
99         va_copy(b,a);
100         va_end(b);])],
101         [AC_DEFINE(HAVE_VA_COPY, 1)
102         AC_MSG_RESULT(va_copy)],
103         [AC_LINK_IFELSE([AC_LANG_PROGRAM([
104                 #include <stdarg.h>
105                 va_list a;],[
106                 va_list b;
107                 __va_copy(b,a);
108                 va_end(b);])],
109                 [AC_DEFINE(HAVE___VA_COPY, 1)
110                 AC_MSG_RESULT(__va_copy)],
111                 [AC_MSG_RESULT(no)
112                 AC_MSG_ERROR([Your system lacks asprintf() and va_copy()])])
113         ])
114 fi
115 AC_SUBST(SYMVER_TIME, $symver_time)
116 AC_SUBST(SYMVER_GETLINE, $symver_getline)
117 AC_SUBST(SYMVER_ASPRINTF, $symver_asprintf)
118
119 AS_COMPILER_FLAGS(CFLAGS,
120         "-Wall
121          -Wextra
122          -Wno-missing-field-initializers
123          -Wno-sign-compare
124          -Wno-unused-parameter
125          -Werror=pointer-to-int-cast
126          -Wdeclaration-after-statement
127          -Werror-implicit-function-declaration
128          -Wformat-nonliteral
129          -Wformat-security
130          -Winit-self
131          -Wmissing-declarations
132          -Wmissing-include-dirs
133          -Wnested-externs
134          -Wpointer-arith
135          -Wwrite-strings")
136
137 AC_ENABLE_SHARED
138 AC_DISABLE_STATIC
139
140 AC_ARG_ENABLE([nls],
141         [  --disable-nls           do not use Native Language Support],
142         [USE_NLS=$enableval], [USE_NLS=yes])
143 LIBINTL=
144 if test "$USE_NLS" = "yes"; then
145    AC_PATH_PROG(MSGFMT, msgfmt)
146    if test "$MSGFMT" = ""; then
147       AC_ERROR([msgfmt could not be found. Try configuring with --disable-nls])
148    fi
149 fi
150 LIBINTL=
151 if test "$USE_NLS" = "yes"; then
152    AC_MSG_CHECKING([for functional NLS support])
153    AC_LINK_IFELSE([AC_LANG_PROGRAM([
154     #include <locale.h>
155     #include <libintl.h>],[
156     setlocale(LC_ALL, "");
157     bindtextdomain("openconnect", "/tmp");
158     (void)dgettext("openconnect", "foo");])],
159     [AC_MSG_RESULT(yes)],
160     [oldLIBS="$LIBS"
161      LIBS="$LIBS -lintl"
162      AC_LINK_IFELSE([AC_LANG_PROGRAM([
163       #include <locale.h>
164       #include <libintl.h>],[
165       setlocale(LC_ALL, "");
166       bindtextdomain("openconnect", "/tmp");
167       (void)dgettext("openconnect", "foo");])],
168       [AC_MSG_RESULT(yes (with -lintl))]
169        LIBINTL="-lintl",
170       [AC_MSG_RESULT(no)
171        USE_NLS=no])
172      LIBS="$oldLIBS"])
173 fi
174
175 if test "$USE_NLS" = "yes"; then
176    AC_SUBST(LIBINTL)
177    AC_DEFINE(ENABLE_NLS, 1)
178 fi
179 AM_CONDITIONAL(USE_NLS, [test "$USE_NLS" = "yes"])
180
181 AC_ARG_WITH([gnutls],
182         AS_HELP_STRING([--with-gnutls], 
183                        [Use GnuTLS instead of OpenSSL (EXPERIMENTAL)]))
184 AC_ARG_WITH([openssl],
185             AS_HELP_STRING([--with-openssl],
186                            [Location of OpenSSL build dir]))
187 ssl_library=
188
189 if test "$with_gnutls" = "yes"; then
190     AC_MSG_ERROR([GnuTLS support is experimental. It does not work yet.])
191 elif test "$with_gnutls" = "shibboleet"; then
192     if test "$with_openssl" != "no" && test "$with_openssl" != ""; then
193         AC_MSG_ERROR([Cannot use both OpenSSL and GnuTLS simultaneously])
194     fi
195     PKG_CHECK_MODULES(GNUTLS, gnutls)
196     if ! $PKG_CONFIG --atleast-version=2.12.16 gnutls; then
197        AC_MSG_ERROR([Your GnuTLS is too old. At least v2.12.16 is required])
198     fi
199     with_openssl=no
200     ssl_library=gnutls
201     oldlibs="$LIBS"
202     LIBS="$LIBS $GNUTLS_LIBS"
203     AC_CHECK_FUNC(gnutls_pkcs12_simple_parse,
204                  [AC_DEFINE(HAVE_GNUTLS_PKCS12_SIMPLE_PARSE, 1)], [])
205     AC_CHECK_FUNC(gnutls_session_set_master,
206                  [AC_DEFINE(HAVE_GNUTLS_SESSION_SET_MASTER, 1)], [])
207     LIBS="$oldLIBS"
208 elif test "$with_gnutls" != "" && test "$with_gnutls" != "no"; then
209     AC_MSG_ERROR([Values other than 'yes' or 'no' for --with-gnutls are not supported])
210 fi
211
212 if test "$with_openssl" = "yes" || test "$with_openssl" = "" ; then
213     PKG_CHECK_MODULES(OPENSSL, openssl, [],
214         [oldLIBS="$LIBS"
215          LIBS="$LIBS -lssl -lcrypto"
216          AC_MSG_CHECKING([for OpenSSL without pkg-config])
217          AC_LINK_IFELSE([AC_LANG_PROGRAM([
218                                 #include <openssl/ssl.h>
219                                 #include <openssl/err.h>],[
220                                 SSL_library_init();
221                                 ERR_clear_error();
222                                 SSL_load_error_strings();
223                                 OpenSSL_add_all_algorithms();])],
224                         [AC_MSG_RESULT(yes)
225                          AC_SUBST([OPENSSL_LIBS], ["-lssl -lcrypto"])
226                          AC_SUBST([OPENSSL_CFLAGS], [])],
227                         [AC_MSG_RESULT(no)
228                          AC_ERROR([Could not build against OpenSSL])])
229          LIBS="$oldLIBS"])
230     ssl_library=openssl
231 elif test "$with_openssl" != "no" ; then
232     OPENSSL_CFLAGS="-I${with_openssl}/include"
233     OPENSSL_LIBS="${with_openssl}/libssl.a ${with_openssl}/libcrypto.a -ldl -lz"
234     AC_SUBST(OPENSSL_CFLAGS)
235     AC_SUBST(OPENSSL_LIBS)
236     enable_static=yes
237     enable_shared=no
238     ssl_library=openssl
239 fi
240
241 case "$ssl_library" in
242     gnutls)
243         AC_DEFINE(OPENCONNECT_GNUTLS, 1)
244         AC_SUBST(SSL_LIBS, [$GNUTLS_LIBS])
245         AC_SUBST(SSL_CFLAGS, [$GNUTLS_CFLAGS])
246         AC_SUBST(SSL_DEFINE, [-DOPENCONNECT_GNUTLS])
247         ;;
248     openssl)
249         AC_DEFINE(OPENCONNECT_OPENSSL, 1)
250         AC_SUBST(SSL_LIBS, [$OPENSSL_LIBS])
251         AC_SUBST(SSL_CFLAGS, [$OPENSSL_CFLAGS])
252         AC_SUBST(SSL_DEFINE, [-DOPENCONNECT_OPENSSL])
253         ;;
254     *)
255         AC_MSG_ERROR([Neither OpenSSL nor GnuTLS selected for SSL.])
256         ;;
257 esac
258 AC_SUBST(SSL_LIBRARY, $ssl_library)
259
260 # Needs to happen after we default to static/shared libraries based on OpenSSL
261 AC_PROG_LIBTOOL
262
263 # Ick. This seems like it's likely to be very fragile, but I can't see a better
264 # way. I shall console myself with the observation that the failure mode isn't
265 # particularly horrible — you just don't get symbol versioning if it fails.
266 symvers=no
267 if test "$enable_shared" = "yes" ; then
268    AC_MSG_CHECKING([if library symbol versioning is available]);
269    echo 'FOO { global: foo; local: *; };' > conftest.map
270    echo 'int foo = 0;' > conftest.$ac_ext
271    if AC_TRY_EVAL(ac_compile); then
272       soname=conftest
273       libobjs=conftest.$ac_objext
274       if AC_TRY_EVAL(archive_cmds ${wl}--version-script ${wl}conftest.map); then
275          AC_SUBST(VERSION_SCRIPT_ARG, [--version-script])
276          symvers="yes (with --version-script)"
277       elif AC_TRY_EVAL(archive_cmds ${wl}-M ${wl}conftest.map); then
278          AC_SUBST(VERSION_SCRIPT_ARG, [-M])
279          symvers="yes (with -M)"
280       fi
281    fi
282    AC_MSG_RESULT(${symvers})
283 fi
284 AM_CONDITIONAL(HAVE_SYMBOL_VERSIONING, [test "${symvers}" != "no"])
285
286 PKG_CHECK_MODULES(LIBXML2, libxml-2.0)
287
288 PKG_CHECK_MODULES(ZLIB, zlib, [],
289                   [oldLIBS="$LIBS"
290                   LIBS="$LIBS -lz" 
291                   AC_MSG_CHECKING([for zlib without pkg-config])
292                   AC_LINK_IFELSE([AC_LANG_PROGRAM([
293                    #include <zlib.h>],[
294                    z_stream zs;
295                    deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
296                                 -12, 9, Z_DEFAULT_STRATEGY);])],
297                   [AC_MSG_RESULT(yes)
298                    AC_SUBST([ZLIB_LIBS], [-lz])
299                    AC_SUBST([ZLIB_CFLAGS], [])],
300                   [AC_MSG_RESULT(no)
301                    AC_ERROR([Could not build against zlib])])
302                   LIBS="$oldLIBS"])
303
304 PKG_CHECK_MODULES(LIBPROXY, libproxy-1.0,
305                 [AC_SUBST(LIBPROXY_PC, libproxy-1.0)
306                  AC_DEFINE([LIBPROXY_HDR], ["proxy.h"])
307                  libproxy_pkg=yes],
308                  libproxy_pkg=no)
309 dnl Libproxy *can* exist without a .pc file, and its header may be called
310 dnl libproxy.h in that case.
311 if (test "$libproxy_pkg" = "no"); then
312    AC_MSG_CHECKING([for libproxy])
313    oldLIBS="$LIBS"
314    LIBS="$LIBS -lproxy"
315    AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <libproxy.h>],
316                            [(void)px_proxy_factory_new();])],
317           [AC_MSG_RESULT(yes (with libproxy.h))
318            AC_DEFINE([LIBPROXY_HDR], ["libproxy.h"])
319            AC_SUBST([LIBPROXY_LIBS], [-lproxy])],
320           [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <proxy.h>],
321                                   [(void)px_proxy_factory_new();])],
322                   [AC_MSG_RESULT(yes (with proxy.h))
323                    AC_DEFINE([LIBPROXY_HDR], ["proxy.h"])
324                    AC_SUBST([LIBPROXY_LIBS], [-lproxy])],
325                    [AC_MSG_RESULT(no)])])
326    LIBS="$oldLIBS"
327 fi
328
329 AC_CHECK_HEADER([if_tun.h],
330     [AC_DEFINE([IF_TUN_HDR], ["if_tun.h"])],
331     [AC_CHECK_HEADER([linux/if_tun.h],
332         [AC_DEFINE([IF_TUN_HDR], ["linux/if_tun.h"])],
333         [AC_CHECK_HEADER([net/if_tun.h],
334             [AC_DEFINE([IF_TUN_HDR], ["net/if_tun.h"])],
335             [AC_CHECK_HEADER([net/tun/if_tun.h],
336                 [AC_DEFINE([IF_TUN_HDR], ["net/tun/if_tun.h"])])])])])
337
338 if test "${ssl_library}" = "openssl"; then
339     oldLIBS="$LIBS"
340     LIBS="$LIBS $OPENSSL_LIBS"
341
342     AC_MSG_CHECKING([for ENGINE_by_id() in OpenSSL])
343     AC_LINK_IFELSE([AC_LANG_PROGRAM(
344         [#include <openssl/engine.h>],
345         [ENGINE_by_id("foo");])],
346         [AC_MSG_RESULT(yes)
347          AC_DEFINE(HAVE_ENGINE, [1], [OpenSSL has ENGINE support])],
348         [AC_MSG_RESULT(no)
349          AC_MSG_NOTICE([Building without OpenSSL TPM ENGINE support])])
350
351     AC_MSG_CHECKING([for dtls1_stop_timer() in OpenSSL])
352     AC_LINK_IFELSE([AC_LANG_PROGRAM(
353         [#include <openssl/ssl.h>
354          #include <stdlib.h>
355          extern void dtls1_stop_timer(SSL *);],
356         [dtls1_stop_timer(NULL);])],
357         [AC_MSG_RESULT(yes)
358          AC_DEFINE(HAVE_DTLS1_STOP_TIMER, [1], [OpenSSL has dtls1_stop_timer() function])],
359         [AC_MSG_RESULT(no)])
360     LIBS="$oldLIBS"
361 fi
362
363 AC_PATH_PROG(PYTHON, [python], [], $PATH:/bin:/usr/bin)
364 if (test -n "${ac_cv_path_PYTHON}"); then
365    AC_SUBST(PYTHON, ${ac_cv_path_PYTHON})
366 else
367    AC_MSG_NOTICE([Python not found; not building HTML pages])
368 fi
369 AM_CONDITIONAL(BUILD_WWW, [test -n "${ac_cv_path_PYTHON}"])
370
371 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/po/LINGUAS $(top_srcdir)/openconnect.h'])
372 RAWLINGUAS=`sed -e "/^#/d" -e "s/#.*//" "${srcdir}/po/LINGUAS"`
373 # Remove newlines
374 LINGUAS=`echo $RAWLINGUAS`
375 AC_SUBST(LINGUAS)
376
377 APIMAJOR="`sed -n 's/^#define OPENCONNECT_API_VERSION_MAJOR \(.*\)/\1/p' ${srcdir}/openconnect.h`"
378 APIMINOR="`sed -n 's/^#define OPENCONNECT_API_VERSION_MINOR \(.*\)/\1/p' ${srcdir}/openconnect.h`"
379 AC_SUBST(APIMAJOR)
380 AC_SUBST(APIMINOR)
381
382 # We want version.c to depend on the files that would affect the
383 # output of version.sh. But we cannot assume that they'll exist,
384 # and we cannot use $(wildcard) in a non-GNU makefile. So we just
385 # depend on the files which happen to exist at configure time.
386 GITVERSIONDEPS=
387 for a in .git/index .git/packed-refs .git/refs/tags .git/HEAD; do
388     if test -r $a ; then
389        GITVERSIONDEPS="$GITVERSIONDEPS $a"
390     fi
391 done
392 AC_SUBST(GITVERSIONDEPS)
393
394 AC_OUTPUT(Makefile openconnect.pc po/Makefile www/Makefile libopenconnect.map \
395           www/styles/Makefile www/inc/Makefile www/images/Makefile)