794edd015486f896eb95f97e7803873067d4aa19
[platform/upstream/openconnect.git] / configure.ac
1 AC_INIT(openconnect, 3.18)
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 AC_ARG_WITH([vpnc-script],
18         [AS_HELP_STRING([--with-vpnc-script],
19           [default location of vpnc-script helper])])
20
21 if test "$with_vpnc_script" = "yes" || test "$with_vpnc_script" = ""; then
22    with_vpnc_script=/etc/vpnc/vpnc-script
23    if ! test -x "$with_vpnc_script"; then
24       AC_MSG_ERROR([${with_vpnc_script} does not seem to be executable.]
25     [OpenConnect will not function correctly without a vpnc-script.]
26     [See http://www.infradead.org/openconnect/vpnc-script.html for more details.]
27     []
28     [If you are building a distribution package, please ensure that your]
29     [packaging is correct, and that a vpnc-script will be installed when the]
30     [user installs your package. You should provide a --with-vpnc-script=]
31     [argument to this configure script, giving the full path where the script]
32     [will be installed.]
33     []
34     [The standard location is ${with_vpnc_script}. To bypass this error and]
35     [build OpenConnect to use the script from this location, even though it's]
36     [not present at the time you are building OpenConnect, pass the argument]
37     ["--with-vpnc-script=${with_vpnc_script}"])
38   fi
39 elif test "$with_vpnc_script" = "no"; then
40    AC_ERROR([You cannot disable vpnc-script.]
41    [OpenConnect will not function correctly without it.]
42    [See http://www.infradead.org/openconnect/vpnc-script.html])
43 fi
44
45 AC_DEFINE_UNQUOTED(DEFAULT_VPNCSCRIPT, "${with_vpnc_script}")
46
47 case $host_os in
48  *linux* | *gnu*)
49     AC_MSG_NOTICE([Applying feature macros for GNU build])
50     AC_DEFINE(_POSIX_C_SOURCE, 200112L)
51     # For strcasecmp() 
52     AC_DEFINE(_BSD_SOURCE)
53     # For asprintf()
54     AC_DEFINE(_GNU_SOURCE)
55     ;;
56  *netbsd*)
57     AC_MSG_NOTICE([Applying feature macros for NetBSD build])
58     AC_DEFINE(_POSIX_C_SOURCE, 200112L)
59     AC_DEFINE(_NETBSD_SOURCE)
60     ;;
61  *)
62     # On FreeBSD the only way to get vsyslog() visible is to define
63     #  *nothing*, which makes absolutely everything visible.
64     # On Darwin enabling _POSIX_C_SOURCE breaks <sys/mount.h> because
65     # u_long and other types don't get defined. OpenBSD is similar.
66     ;;
67 esac
68
69 symver_time=
70 symver_getline=
71 symver_asprintf=
72
73 case $host_os in
74  *solaris*|*sunos*)
75     symver_time="openconnect__time;"
76     ;;
77 esac
78
79 AC_CHECK_FUNC(getline, [AC_DEFINE(HAVE_GETLINE, 1)], [symver_getline="openconnect__getline;"])
80 AC_CHECK_FUNC(strcasestr, [AC_DEFINE(HAVE_STRCASESTR, 1)], [])
81 AC_CHECK_FUNC(asprintf, [AC_DEFINE(HAVE_ASPRINTF, 1)], [symver_asprintf="openconnect__asprintf;"])
82 if test -n "$symver_asprintf"; then
83   AC_MSG_CHECKING([for va_copy])
84   AC_LINK_IFELSE([AC_LANG_PROGRAM([
85         #include <stdarg.h>
86         va_list a;],[
87         va_list b;
88         va_copy(b,a);
89         va_end(b);])],
90         [AC_DEFINE(HAVE_VA_COPY, 1)
91         AC_MSG_RESULT(va_copy)],
92         [AC_LINK_IFELSE([AC_LANG_PROGRAM([
93                 #include <stdarg.h>
94                 va_list a;],[
95                 va_list b;
96                 __va_copy(b,a);
97                 va_end(b);])],
98                 [AC_DEFINE(HAVE___VA_COPY, 1)
99                 AC_MSG_RESULT(__va_copy)],
100                 [AC_MSG_RESULT(no)
101                 AC_MSG_ERROR([Your system lacks asprintf() and va_copy()])])
102         ])
103 fi
104 AC_SUBST(SYMVER_TIME, $symver_time)
105 AC_SUBST(SYMVER_GETLINE, $symver_getline)
106 AC_SUBST(SYMVER_ASPRINTF, $symver_asprintf)
107
108 AS_COMPILER_FLAGS(CFLAGS,
109         "-Wall
110          -Wextra
111          -Wno-missing-field-initializers
112          -Wno-sign-compare
113          -Wno-unused-parameter
114          -Werror=pointer-to-int-cast
115          -Wdeclaration-after-statement
116          -Werror-implicit-function-declaration
117          -Wformat-nonliteral
118          -Wformat-security
119          -Winit-self
120          -Wmissing-declarations
121          -Wmissing-include-dirs
122          -Wnested-externs
123          -Wpointer-arith
124          -Wwrite-strings")
125
126 AC_ENABLE_SHARED
127 AC_DISABLE_STATIC
128
129 AC_ARG_ENABLE([nls],
130         [ --disable-nls           do not use Native Language Support],
131         [USE_NLS=$enableval], [USE_NLS=yes])
132 LIBINTL=
133 if test "$USE_NLS" = "yes"; then
134    AC_PATH_PROG(MSGFMT, msgfmt)
135    if test "$MSGFMT" = ""; then
136       AC_ERROR([msgfmt could not be found. Try configuring with --disable-nls])
137    fi
138 fi
139 LIBINTL=
140 if test "$USE_NLS" = "yes"; then
141    AC_MSG_CHECKING([for functional NLS support])
142    AC_LINK_IFELSE([AC_LANG_PROGRAM([
143     #include <locale.h>
144     #include <libintl.h>],[
145     setlocale(LC_ALL, "");
146     bindtextdomain("openconnect", "/tmp");
147     (void)dgettext("openconnect", "foo");])],
148     [AC_MSG_RESULT(yes)],
149     [oldLIBS="$LIBS"
150      LIBS="$LIBS -lintl"
151      AC_LINK_IFELSE([AC_LANG_PROGRAM([
152       #include <locale.h>
153       #include <libintl.h>],[
154       setlocale(LC_ALL, "");
155       bindtextdomain("openconnect", "/tmp");
156       (void)dgettext("openconnect", "foo");])],
157       [AC_MSG_RESULT(yes (with -lintl))]
158        LIBINTL="-lintl",
159       [AC_MSG_RESULT(no)
160        USE_NLS=no])
161      LIBS="$oldLIBS"])
162 fi
163
164 if test "$USE_NLS" = "yes"; then
165    AC_SUBST(LIBINTL)
166    AC_DEFINE(ENABLE_NLS, 1)
167 fi
168 AM_CONDITIONAL(USE_NLS, [test "$USE_NLS" = "yes"])
169
170 AC_ARG_WITH([openssl],
171             AS_HELP_STRING([--with-openssl],
172                            [Location of OpenSSL build dir]),
173             [OPENSSL_CFLAGS="-I${with_openssl}/include"
174              OPENSSL_LIBS="${with_openssl}/libssl.a ${with_openssl}/libcrypto.a -ldl -lz"
175              AC_SUBST(OPENSSL_CFLAGS)
176              AC_SUBST(OPENSSL_LIBS)
177              enable_static=yes
178              enable_shared=no],
179             [PKG_CHECK_MODULES(OPENSSL, openssl, [],
180                                [oldLIBS="$LIBS"
181                                LIBS="$LIBS -lssl -lcrypto"
182                                AC_MSG_CHECKING([for OpenSSL without pkg-config])
183                                AC_LINK_IFELSE([AC_LANG_PROGRAM([
184                                 #include <openssl/ssl.h>
185                                 #include <openssl/err.h>],[
186                                 SSL_library_init();
187                                 ERR_clear_error();
188                                 SSL_load_error_strings();
189                                 OpenSSL_add_all_algorithms();])],
190                                [AC_MSG_RESULT(yes)
191                                 AC_SUBST([OPENSSL_LIBS], ["-lssl -lcrypto"])
192                                 AC_SUBST([OPENSSL_CFLAGS], [])],
193                                [AC_MSG_RESULT(no)
194                                 AC_ERROR([Could not build against OpenSSL])])
195                                 LIBS="$oldLIBS"])])
196
197 # Needs to happen after we default to static/shared libraries based on OpenSSL
198 AC_PROG_LIBTOOL
199
200 # Ick. This seems like it's likely to be very fragile, but I can't see a better
201 # way. I shall console myself with the observation that the failure mode isn't
202 # particularly horrible — you just don't get symbol versioning if it fails.
203 symvers=no
204 if test "$enable_shared" = "yes" ; then
205    AC_MSG_CHECKING([if library symbol versioning is available]);
206    echo 'FOO { global: foo; local: *; };' > conftest.map
207    echo 'int foo = 0;' > conftest.$ac_ext
208    if AC_TRY_EVAL(ac_compile); then
209       soname=conftest
210       libobjs=conftest.$ac_objext
211       if AC_TRY_EVAL(archive_cmds ${wl}--version-script ${wl}conftest.map); then
212          AC_SUBST(VERSION_SCRIPT_ARG, [--version-script])
213          symvers="yes (with --version-script)"
214       elif AC_TRY_EVAL(archive_cmds ${wl}-M ${wl}conftest.map); then
215          AC_SUBST(VERSION_SCRIPT_ARG, [-M])
216          symvers="yes (with -M)"
217       fi
218    fi
219    AC_MSG_RESULT(${symvers})
220 fi
221 AM_CONDITIONAL(HAVE_SYMBOL_VERSIONING, [test "${symvers}" != "no"])
222
223 PKG_CHECK_MODULES(LIBXML2, libxml-2.0)
224
225 PKG_CHECK_MODULES(ZLIB, zlib, [],
226                   [oldLIBS="$LIBS"
227                   LIBS="$LIBS -lz" 
228                   AC_MSG_CHECKING([for zlib without pkg-config])
229                   AC_LINK_IFELSE([AC_LANG_PROGRAM([
230                    #include <zlib.h>],[
231                    z_stream zs;
232                    deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
233                                 -12, 9, Z_DEFAULT_STRATEGY);])],
234                   [AC_MSG_RESULT(yes)
235                    AC_SUBST([ZLIB_LIBS], [-lz])
236                    AC_SUBST([ZLIB_CFLAGS], [])],
237                   [AC_MSG_RESULT(no)
238                    AC_ERROR([Could not build against zlib])])
239                   LIBS="$oldLIBS"])
240
241 PKG_CHECK_MODULES(LIBPROXY, libproxy-1.0,
242                 [AC_SUBST(LIBPROXY_PC, libproxy-1.0)
243                  AC_DEFINE([LIBPROXY_HDR], ["proxy.h"])
244                  libproxy_pkg=yes],
245                  libproxy_pkg=no)
246 dnl Libproxy *can* exist without a .pc file, and its header may be called
247 dnl libproxy.h in that case.
248 if (test "$libproxy_pkg" = "no"); then
249    AC_MSG_CHECKING([for libproxy])
250    oldLIBS="$LIBS"
251    LIBS="$LIBS -lproxy"
252    AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <libproxy.h>],
253                            [(void)px_proxy_factory_new();])],
254           [AC_MSG_RESULT(yes (with libproxy.h))
255            AC_DEFINE([LIBPROXY_HDR], ["libproxy.h"])
256            AC_SUBST([LIBPROXY_LIBS], [-lproxy])],
257           [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <proxy.h>],
258                                   [(void)px_proxy_factory_new();])],
259                   [AC_MSG_RESULT(yes (with proxy.h))
260                    AC_DEFINE([LIBPROXY_HDR], ["proxy.h"])
261                    AC_SUBST([LIBPROXY_LIBS], [-lproxy])],
262                    [AC_MSG_RESULT(no)])])
263    LIBS="$oldLIBS"
264 fi
265
266 AC_CHECK_HEADER([if_tun.h],
267     [AC_DEFINE([IF_TUN_HDR], ["if_tun.h"])],
268     [AC_CHECK_HEADER([linux/if_tun.h],
269         [AC_DEFINE([IF_TUN_HDR], ["linux/if_tun.h"])],
270         [AC_CHECK_HEADER([net/if_tun.h],
271             [AC_DEFINE([IF_TUN_HDR], ["net/if_tun.h"])],
272             [AC_CHECK_HEADER([net/tun/if_tun.h],
273                 [AC_DEFINE([IF_TUN_HDR], ["net/tun/if_tun.h"])])])])])
274
275 oldLIBS="$LIBS"
276 LIBS="$LIBS $OPENSSL_LIBS"
277
278 AC_MSG_CHECKING([for ENGINE_by_id() in OpenSSL])
279 AC_LINK_IFELSE([AC_LANG_PROGRAM(
280         [#include <openssl/engine.h>],
281         [ENGINE_by_id("foo");])],
282         [AC_MSG_RESULT(yes)
283          AC_DEFINE(HAVE_ENGINE, [1], [OpenSSL has ENGINE support])],
284         [AC_MSG_RESULT(no)
285          AC_MSG_NOTICE([Building without OpenSSL TPM ENGINE support])])
286
287 AC_MSG_CHECKING([for dtls1_stop_timer() in OpenSSL])
288 AC_LINK_IFELSE([AC_LANG_PROGRAM(
289         [#include <openssl/ssl.h>
290          #include <stdlib.h>
291          extern void dtls1_stop_timer(SSL *);],
292         [dtls1_stop_timer(NULL);])],
293         [AC_MSG_RESULT(yes)
294          AC_DEFINE(HAVE_DTLS1_STOP_TIMER, [1], [OpenSSL has dtls1_stop_timer() function])],
295         [AC_MSG_RESULT(no)])
296 LIBS="$oldLIBS"
297
298 AC_PATH_PROG(PYTHON, [python], [], $PATH:/bin:/usr/bin)
299 if (test -n "${ac_cv_path_PYTHON}"); then
300    AC_SUBST(PYTHON, ${ac_cv_path_PYTHON})
301 else
302    AC_MSG_NOTICE([Python not found; not building HTML pages])
303 fi
304 AM_CONDITIONAL(BUILD_WWW, [test -n "${ac_cv_path_PYTHON}"])
305
306 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/po/LINGUAS'])
307 RAWLINGUAS=`sed -e "/^#/d" -e "s/#.*//" "${srcdir}/po/LINGUAS"`
308 # Remove newlines
309 LINGUAS=`echo $RAWLINGUAS`
310 AC_SUBST(LINGUAS)
311
312 # We want version.c to depend on the files that would affect the
313 # output of version.sh. But we cannot assume that they'll exist,
314 # and we cannot use $(wildcard) in a non-GNU makefile. So we just
315 # depend on the files which happen to exist at configure time.
316 GITVERSIONDEPS=
317 for a in .git/index .git/packed-refs .git/refs/tags .git/HEAD; do
318     if test -r $a ; then
319        GITVERSIONDEPS="$GITVERSIONDEPS $a"
320     fi
321 done
322 AC_SUBST(GITVERSIONDEPS)
323
324 AC_OUTPUT(Makefile openconnect.pc po/Makefile www/Makefile libopenconnect.map \
325           www/styles/Makefile www/inc/Makefile www/images/Makefile)