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