Add --with-pkgconfigdir to allow different environments like FreeBSD
[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(getline, [AC_DEFINE(HAVE_GETLINE, 1)], [symver_getline="openconnect__getline;"])
90 AC_CHECK_FUNC(strcasestr, [AC_DEFINE(HAVE_STRCASESTR, 1)], [])
91 AC_CHECK_FUNC(asprintf, [AC_DEFINE(HAVE_ASPRINTF, 1)], [symver_asprintf="openconnect__asprintf;"])
92 if test -n "$symver_asprintf"; then
93   AC_MSG_CHECKING([for va_copy])
94   AC_LINK_IFELSE([AC_LANG_PROGRAM([
95         #include <stdarg.h>
96         va_list a;],[
97         va_list b;
98         va_copy(b,a);
99         va_end(b);])],
100         [AC_DEFINE(HAVE_VA_COPY, 1)
101         AC_MSG_RESULT(va_copy)],
102         [AC_LINK_IFELSE([AC_LANG_PROGRAM([
103                 #include <stdarg.h>
104                 va_list a;],[
105                 va_list b;
106                 __va_copy(b,a);
107                 va_end(b);])],
108                 [AC_DEFINE(HAVE___VA_COPY, 1)
109                 AC_MSG_RESULT(__va_copy)],
110                 [AC_MSG_RESULT(no)
111                 AC_MSG_ERROR([Your system lacks asprintf() and va_copy()])])
112         ])
113 fi
114 AC_SUBST(SYMVER_TIME, $symver_time)
115 AC_SUBST(SYMVER_GETLINE, $symver_getline)
116 AC_SUBST(SYMVER_ASPRINTF, $symver_asprintf)
117
118 AS_COMPILER_FLAGS(CFLAGS,
119         "-Wall
120          -Wextra
121          -Wno-missing-field-initializers
122          -Wno-sign-compare
123          -Wno-unused-parameter
124          -Werror=pointer-to-int-cast
125          -Wdeclaration-after-statement
126          -Werror-implicit-function-declaration
127          -Wformat-nonliteral
128          -Wformat-security
129          -Winit-self
130          -Wmissing-declarations
131          -Wmissing-include-dirs
132          -Wnested-externs
133          -Wpointer-arith
134          -Wwrite-strings")
135
136 AC_ENABLE_SHARED
137 AC_DISABLE_STATIC
138
139 AC_ARG_ENABLE([nls],
140         [ --disable-nls           do not use Native Language Support],
141         [USE_NLS=$enableval], [USE_NLS=yes])
142 LIBINTL=
143 if test "$USE_NLS" = "yes"; then
144    AC_PATH_PROG(MSGFMT, msgfmt)
145    if test "$MSGFMT" = ""; then
146       AC_ERROR([msgfmt could not be found. Try configuring with --disable-nls])
147    fi
148 fi
149 LIBINTL=
150 if test "$USE_NLS" = "yes"; then
151    AC_MSG_CHECKING([for functional NLS support])
152    AC_LINK_IFELSE([AC_LANG_PROGRAM([
153     #include <locale.h>
154     #include <libintl.h>],[
155     setlocale(LC_ALL, "");
156     bindtextdomain("openconnect", "/tmp");
157     (void)dgettext("openconnect", "foo");])],
158     [AC_MSG_RESULT(yes)],
159     [oldLIBS="$LIBS"
160      LIBS="$LIBS -lintl"
161      AC_LINK_IFELSE([AC_LANG_PROGRAM([
162       #include <locale.h>
163       #include <libintl.h>],[
164       setlocale(LC_ALL, "");
165       bindtextdomain("openconnect", "/tmp");
166       (void)dgettext("openconnect", "foo");])],
167       [AC_MSG_RESULT(yes (with -lintl))]
168        LIBINTL="-lintl",
169       [AC_MSG_RESULT(no)
170        USE_NLS=no])
171      LIBS="$oldLIBS"])
172 fi
173
174 if test "$USE_NLS" = "yes"; then
175    AC_SUBST(LIBINTL)
176    AC_DEFINE(ENABLE_NLS, 1)
177 fi
178 AM_CONDITIONAL(USE_NLS, [test "$USE_NLS" = "yes"])
179
180 AC_ARG_WITH([openssl],
181             AS_HELP_STRING([--with-openssl],
182                            [Location of OpenSSL build dir]),
183             [OPENSSL_CFLAGS="-I${with_openssl}/include"
184              OPENSSL_LIBS="${with_openssl}/libssl.a ${with_openssl}/libcrypto.a -ldl -lz"
185              AC_SUBST(OPENSSL_CFLAGS)
186              AC_SUBST(OPENSSL_LIBS)
187              enable_static=yes
188              enable_shared=no],
189             [PKG_CHECK_MODULES(OPENSSL, openssl, [],
190                                [oldLIBS="$LIBS"
191                                LIBS="$LIBS -lssl -lcrypto"
192                                AC_MSG_CHECKING([for OpenSSL without pkg-config])
193                                AC_LINK_IFELSE([AC_LANG_PROGRAM([
194                                 #include <openssl/ssl.h>
195                                 #include <openssl/err.h>],[
196                                 SSL_library_init();
197                                 ERR_clear_error();
198                                 SSL_load_error_strings();
199                                 OpenSSL_add_all_algorithms();])],
200                                [AC_MSG_RESULT(yes)
201                                 AC_SUBST([OPENSSL_LIBS], ["-lssl -lcrypto"])
202                                 AC_SUBST([OPENSSL_CFLAGS], [])],
203                                [AC_MSG_RESULT(no)
204                                 AC_ERROR([Could not build against OpenSSL])])
205                                 LIBS="$oldLIBS"])])
206
207 # Needs to happen after we default to static/shared libraries based on OpenSSL
208 AC_PROG_LIBTOOL
209
210 # Ick. This seems like it's likely to be very fragile, but I can't see a better
211 # way. I shall console myself with the observation that the failure mode isn't
212 # particularly horrible — you just don't get symbol versioning if it fails.
213 symvers=no
214 if test "$enable_shared" = "yes" ; then
215    AC_MSG_CHECKING([if library symbol versioning is available]);
216    echo 'FOO { global: foo; local: *; };' > conftest.map
217    echo 'int foo = 0;' > conftest.$ac_ext
218    if AC_TRY_EVAL(ac_compile); then
219       soname=conftest
220       libobjs=conftest.$ac_objext
221       if AC_TRY_EVAL(archive_cmds ${wl}--version-script ${wl}conftest.map); then
222          AC_SUBST(VERSION_SCRIPT_ARG, [--version-script])
223          symvers="yes (with --version-script)"
224       elif AC_TRY_EVAL(archive_cmds ${wl}-M ${wl}conftest.map); then
225          AC_SUBST(VERSION_SCRIPT_ARG, [-M])
226          symvers="yes (with -M)"
227       fi
228    fi
229    AC_MSG_RESULT(${symvers})
230 fi
231 AM_CONDITIONAL(HAVE_SYMBOL_VERSIONING, [test "${symvers}" != "no"])
232
233 PKG_CHECK_MODULES(LIBXML2, libxml-2.0)
234
235 PKG_CHECK_MODULES(ZLIB, zlib, [],
236                   [oldLIBS="$LIBS"
237                   LIBS="$LIBS -lz" 
238                   AC_MSG_CHECKING([for zlib without pkg-config])
239                   AC_LINK_IFELSE([AC_LANG_PROGRAM([
240                    #include <zlib.h>],[
241                    z_stream zs;
242                    deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
243                                 -12, 9, Z_DEFAULT_STRATEGY);])],
244                   [AC_MSG_RESULT(yes)
245                    AC_SUBST([ZLIB_LIBS], [-lz])
246                    AC_SUBST([ZLIB_CFLAGS], [])],
247                   [AC_MSG_RESULT(no)
248                    AC_ERROR([Could not build against zlib])])
249                   LIBS="$oldLIBS"])
250
251 PKG_CHECK_MODULES(LIBPROXY, libproxy-1.0,
252                 [AC_SUBST(LIBPROXY_PC, libproxy-1.0)
253                  AC_DEFINE([LIBPROXY_HDR], ["proxy.h"])
254                  libproxy_pkg=yes],
255                  libproxy_pkg=no)
256 dnl Libproxy *can* exist without a .pc file, and its header may be called
257 dnl libproxy.h in that case.
258 if (test "$libproxy_pkg" = "no"); then
259    AC_MSG_CHECKING([for libproxy])
260    oldLIBS="$LIBS"
261    LIBS="$LIBS -lproxy"
262    AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <libproxy.h>],
263                            [(void)px_proxy_factory_new();])],
264           [AC_MSG_RESULT(yes (with libproxy.h))
265            AC_DEFINE([LIBPROXY_HDR], ["libproxy.h"])
266            AC_SUBST([LIBPROXY_LIBS], [-lproxy])],
267           [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <proxy.h>],
268                                   [(void)px_proxy_factory_new();])],
269                   [AC_MSG_RESULT(yes (with proxy.h))
270                    AC_DEFINE([LIBPROXY_HDR], ["proxy.h"])
271                    AC_SUBST([LIBPROXY_LIBS], [-lproxy])],
272                    [AC_MSG_RESULT(no)])])
273    LIBS="$oldLIBS"
274 fi
275
276 AC_CHECK_HEADER([if_tun.h],
277     [AC_DEFINE([IF_TUN_HDR], ["if_tun.h"])],
278     [AC_CHECK_HEADER([linux/if_tun.h],
279         [AC_DEFINE([IF_TUN_HDR], ["linux/if_tun.h"])],
280         [AC_CHECK_HEADER([net/if_tun.h],
281             [AC_DEFINE([IF_TUN_HDR], ["net/if_tun.h"])],
282             [AC_CHECK_HEADER([net/tun/if_tun.h],
283                 [AC_DEFINE([IF_TUN_HDR], ["net/tun/if_tun.h"])])])])])
284
285 oldLIBS="$LIBS"
286 LIBS="$LIBS $OPENSSL_LIBS"
287
288 AC_MSG_CHECKING([for ENGINE_by_id() in OpenSSL])
289 AC_LINK_IFELSE([AC_LANG_PROGRAM(
290         [#include <openssl/engine.h>],
291         [ENGINE_by_id("foo");])],
292         [AC_MSG_RESULT(yes)
293          AC_DEFINE(HAVE_ENGINE, [1], [OpenSSL has ENGINE support])],
294         [AC_MSG_RESULT(no)
295          AC_MSG_NOTICE([Building without OpenSSL TPM ENGINE support])])
296
297 AC_MSG_CHECKING([for dtls1_stop_timer() in OpenSSL])
298 AC_LINK_IFELSE([AC_LANG_PROGRAM(
299         [#include <openssl/ssl.h>
300          #include <stdlib.h>
301          extern void dtls1_stop_timer(SSL *);],
302         [dtls1_stop_timer(NULL);])],
303         [AC_MSG_RESULT(yes)
304          AC_DEFINE(HAVE_DTLS1_STOP_TIMER, [1], [OpenSSL has dtls1_stop_timer() function])],
305         [AC_MSG_RESULT(no)])
306 LIBS="$oldLIBS"
307
308 AC_PATH_PROG(PYTHON, [python], [], $PATH:/bin:/usr/bin)
309 if (test -n "${ac_cv_path_PYTHON}"); then
310    AC_SUBST(PYTHON, ${ac_cv_path_PYTHON})
311 else
312    AC_MSG_NOTICE([Python not found; not building HTML pages])
313 fi
314 AM_CONDITIONAL(BUILD_WWW, [test -n "${ac_cv_path_PYTHON}"])
315
316 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/po/LINGUAS $(top_srcdir)/openconnect.h'])
317 RAWLINGUAS=`sed -e "/^#/d" -e "s/#.*//" "${srcdir}/po/LINGUAS"`
318 # Remove newlines
319 LINGUAS=`echo $RAWLINGUAS`
320 AC_SUBST(LINGUAS)
321
322 APIMAJOR="`sed -n 's/^#define OPENCONNECT_API_VERSION_MAJOR \(.*\)/\1/p' openconnect.h`"
323 APIMINOR="`sed -n 's/^#define OPENCONNECT_API_VERSION_MINOR \(.*\)/\1/p' openconnect.h`"
324 AC_SUBST(APIMAJOR)
325 AC_SUBST(APIMINOR)
326
327 # We want version.c to depend on the files that would affect the
328 # output of version.sh. But we cannot assume that they'll exist,
329 # and we cannot use $(wildcard) in a non-GNU makefile. So we just
330 # depend on the files which happen to exist at configure time.
331 GITVERSIONDEPS=
332 for a in .git/index .git/packed-refs .git/refs/tags .git/HEAD; do
333     if test -r $a ; then
334        GITVERSIONDEPS="$GITVERSIONDEPS $a"
335     fi
336 done
337 AC_SUBST(GITVERSIONDEPS)
338
339 AC_OUTPUT(Makefile openconnect.pc po/Makefile www/Makefile libopenconnect.map \
340           www/styles/Makefile www/inc/Makefile www/images/Makefile)