Don't leave stray zlib in $LIBS
[platform/upstream/openconnect.git] / configure.ac
1
2 AC_INIT(openconnect, 3.16)
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_ENABLE([nls],
19         [ --disable-nls           do not use Native Language Support],
20         [USE_NLS=$enableval], [USE_NLS=yes])
21 LIBINTL=
22 if test "$USE_NLS" = "yes"; then
23    AC_PATH_PROG(MSGFMT, msgfmt)
24    if test "$MSGFMT" = ""; then
25       AC_ERROR([msgfmt could not be found. Try configuring with --disable-nls])
26    fi
27 fi
28 LIBINTL=
29 if test "$USE_NLS" = "yes"; then
30    AC_MSG_CHECKING([for functional NLS support])
31    AC_LINK_IFELSE([AC_LANG_PROGRAM([
32     #include <locale.h>
33     #include <libintl.h>],[
34     setlocale(LC_ALL, "");
35     bindtextdomain("openconnect", "/tmp");
36     (void)dgettext("openconnect", "foo");])],
37     [AC_MSG_RESULT(yes)],
38     [oldLIBS="$LIBS"
39      LIBS="$LIBS -lintl"
40      AC_LINK_IFELSE([AC_LANG_PROGRAM([
41       #include <locale.h>
42       #include <libintl.h>],[
43       setlocale(LC_ALL, "");
44       bindtextdomain("openconnect", "/tmp");
45       (void)dgettext("openconnect", "foo");])],
46       [AC_MSG_RESULT(yes (with -lintl))]
47        LIBINTL="-lintl",
48       [AC_MSG_RESULT(no)
49        USE_NLS=no])
50      LIBS="$oldLIBS"])
51 fi
52
53 if test "$USE_NLS" = "yes"; then
54    AC_SUBST(LIBINTL)
55    AC_DEFINE(ENABLE_NLS, 1)
56 fi
57 AM_CONDITIONAL(USE_NLS, [test "$USE_NLS" = "yes"])
58
59 case $host_os in
60  *linux* | *gnu*)
61     AC_MSG_NOTICE([Applying feature macros for GNU build])
62     AC_DEFINE(_POSIX_C_SOURCE, 200112L)
63     # For strcasecmp() 
64     AC_DEFINE(_BSD_SOURCE)
65     # For asprintf()
66     AC_DEFINE(_GNU_SOURCE)
67     ;;
68  *netbsd*)
69     AC_MSG_NOTICE([Applying feature macros for NetBSD build])
70     AC_DEFINE(_POSIX_C_SOURCE, 200112L)
71     AC_DEFINE(_NETBSD_SOURCE)
72     ;;
73  *)
74     # On FreeBSD the only way to get vsyslog() visible is to define
75     #  *nothing*, which makes absolutely everything visible.
76     # On Darwin enabling _POSIX_C_SOURCE breaks <sys/mount.h> because
77     # u_long and other types don't get defined. OpenBSD is similar.
78     ;;
79 esac
80
81 AS_COMPILER_FLAGS(CFLAGS,
82         "-Wall
83          -Wextra
84          -Wno-missing-field-initializers
85          -Wno-sign-compare
86          -Wno-unused-parameter
87          -Werror=pointer-to-int-cast
88          -Wdeclaration-after-statement
89          -Werror-implicit-function-declaration
90          -Wformat-nonliteral
91          -Wformat-security
92          -Winit-self
93          -Wmissing-declarations
94          -Wmissing-include-dirs
95          -Wnested-externs
96          -Wpointer-arith
97          -Wwrite-strings")
98
99 AC_ARG_WITH([openssl],
100             AS_HELP_STRING([--with-openssl],
101                            [Location of OpenSSL build dir]),
102             [OPENSSL_CFLAGS="-I${with_openssl}/include"
103              OPENSSL_LIBS="${with_openssl}/libssl.a ${with_openssl}/libcrypto.a -ldl -lz"
104              AC_SUBST(OPENSSL_CFLAGS)
105              AC_SUBST(OPENSSL_LIBS)
106              AC_ENABLE_STATIC
107              AC_DISABLE_SHARED],
108             [PKG_CHECK_MODULES(OPENSSL, openssl, [],
109                                [oldLIBS="$LIBS"
110                                LIBS="$LIBS -lssl -lcrypto"
111                                AC_MSG_CHECKING([for OpenSSL without pkg-config])
112                                AC_LINK_IFELSE([AC_LANG_PROGRAM([
113                                 #include <openssl/ssl.h>
114                                 #include <openssl/err.h>],[
115                                 SSL_library_init();
116                                 ERR_clear_error();
117                                 SSL_load_error_strings();
118                                 OpenSSL_add_all_algorithms();])],
119                                [AC_MSG_RESULT(yes)
120                                 AC_SUBST([OPENSSL_LIBS], ["-lssl -lcrypto"])
121                                 AC_SUBST([OPENSSL_CFLAGS], [])],
122                                [AC_MSG_RESULT(no)
123                                 AC_ERROR([Could not build against OpenSSL])])
124                                 LIBS="$oldLIBS"])
125              AC_ENABLE_SHARED
126              AC_DISABLE_STATIC])
127
128 # Needs to happen after we default to static/shared libraries based on OpenSSL
129 AC_PROG_LIBTOOL
130
131 PKG_CHECK_MODULES(LIBXML2, libxml-2.0)
132
133 PKG_CHECK_MODULES(ZLIB, zlib, [],
134                   [oldLIBS="$LIBS"
135                   LIBS="$LIBS -lz" 
136                   AC_MSG_CHECKING([for zlib without pkg-config])
137                   AC_LINK_IFELSE([AC_LANG_PROGRAM([
138                    #include <zlib.h>],[
139                    z_stream zs;
140                    deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
141                                 -12, 9, Z_DEFAULT_STRATEGY);])],
142                   [AC_MSG_RESULT(yes)
143                    AC_SUBST([ZLIB_LIBS], [-lz])
144                    AC_SUBST([ZLIB_CFLAGS], [])],
145                   [AC_MSG_RESULT(no)
146                    AC_ERROR([Could not build against zlib])])
147                   LIBS="$oldLIBS"])
148
149 PKG_CHECK_MODULES(LIBPROXY, libproxy-1.0,
150                 [AC_SUBST(LIBPROXY_PC, libproxy-1.0)
151                  AC_DEFINE([LIBPROXY_HDR], ["proxy.h"])
152                  libproxy_pkg=yes],
153                  libproxy_pkg=no)
154 dnl Libproxy *can* exist without a .pc file, and its header may be called
155 dnl libproxy.h in that case.
156 if (test "$libproxy_pkg" = "no"); then
157    AC_MSG_CHECKING([for libproxy])
158    oldLIBS="$LIBS"
159    LIBS="$LIBS -lproxy"
160    AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <libproxy.h>],
161                            [(void)px_proxy_factory_new();])],
162           [AC_MSG_RESULT(yes (with libproxy.h))
163            AC_DEFINE([LIBPROXY_HDR], ["libproxy.h"])
164            AC_SUBST([LIBPROXY_LIBS], [-lproxy])],
165           [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <proxy.h>],
166                                   [(void)px_proxy_factory_new();])],
167                   [AC_MSG_RESULT(yes (with proxy.h))
168                    AC_DEFINE([LIBPROXY_HDR], ["proxy.h"])
169                    AC_SUBST([LIBPROXY_LIBS], [-lproxy])],
170                    [AC_MSG_RESULT(no)])])
171    LIBS="$oldLIBS"
172 fi
173
174 AC_CHECK_HEADER([if_tun.h],
175     [AC_DEFINE([IF_TUN_HDR], ["if_tun.h"])],
176     [AC_CHECK_HEADER([linux/if_tun.h],
177         [AC_DEFINE([IF_TUN_HDR], ["linux/if_tun.h"])],
178         [AC_CHECK_HEADER([net/if_tun.h],
179             [AC_DEFINE([IF_TUN_HDR], ["net/if_tun.h"])],
180             [AC_CHECK_HEADER([net/tun/if_tun.h],
181                 [AC_DEFINE([IF_TUN_HDR], ["net/tun/if_tun.h"])])])])])
182
183 AC_CHECK_LIB(ssl, ENGINE_by_id,
184              AC_DEFINE(HAVE_ENGINE, [1], [OpenSSL has ENGINE support]),
185              AC_MSG_NOTICE([Building without OpenSSL TPM ENGINE support]),
186              ${OPENSSL_LIBS})
187
188 AC_CHECK_LIB(ssl, dtls1_stop_timer,
189                   AC_DEFINE(HAVE_DTLS1_STOP_TIMER, [1], [OpenSSL has dtls1_stop_timer() function]),
190                   ,,${OPENSSL_LIBS})
191
192 AC_PATH_PROG(PYTHON, [python], [], $PATH:/bin:/usr/bin)
193 if (test -n "${ac_cv_path_PYTHON}"); then
194    AC_SUBST(PYTHON, ${ac_cv_path_PYTHON})
195 else
196    AC_MSG_NOTICE([Python not found; not building HTML pages])
197 fi
198 AM_CONDITIONAL(BUILD_WWW, [test -n "${ac_cv_path_PYTHON}"])
199
200 AC_SUBST([CONFIG_STATUS_DEPENDENCIES], ['$(top_srcdir)/po/LINGUAS'])
201 RAWLINGUAS=`sed -e "/^#/d" -e "s/#.*//" "${srcdir}/po/LINGUAS"`
202 # Remove newlines
203 LINGUAS=`echo $RAWLINGUAS`
204 AC_SUBST(LINGUAS)
205
206 # We want version.c to depend on the files that would affect the
207 # output of version.sh. But we cannot assume that they'll exist,
208 # and we cannot use $(wildcard) in a non-GNU makefile. So we just
209 # depend on the files which happen to exist at configure time.
210 GITVERSIONDEPS=
211 for a in .git/index .git/packed-refs .git/refs/tags .git/HEAD; do
212     if test -r $a ; then
213        GITVERSIONDEPS="$GITVERSIONDEPS $a"
214     fi
215 done
216 AC_SUBST(GITVERSIONDEPS)
217
218 AC_OUTPUT(Makefile openconnect.pc po/Makefile www/Makefile \
219           www/styles/Makefile www/inc/Makefile www/images/Makefile)