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