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