1# This file is part of libmicrohttpd.
2# (C) 2006-2015 Christian Grothoff (and other contributing authors)
3#
4# libmicrohttpd is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published
6# by the Free Software Foundation; either version 3, or (at your
7# option) any later version.
8#
9# libmicrohttpd is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12# General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with libmicrohttpd; see the file COPYING.  If not, write to the
16# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17# Boston, MA 02111-1307, USA.
18#
19#
20# Process this file with autoconf to produce a configure script.
21#
22#
23AC_PREREQ([2.60])
24LT_PREREQ([2.4.0])
25AC_INIT([libmicrohttpd],[0.9.42],[libmicrohttpd@gnu.org])
26AM_INIT_AUTOMAKE([silent-rules] [subdir-objects])
27AC_CONFIG_HEADERS([MHD_config.h])
28AC_CONFIG_MACRO_DIR([m4])
29AH_TOP([#define _GNU_SOURCE  1])
30
31LIB_VERSION_CURRENT=42
32LIB_VERSION_REVISION=0
33LIB_VERSION_AGE=32
34AC_SUBST(LIB_VERSION_CURRENT)
35AC_SUBST(LIB_VERSION_REVISION)
36AC_SUBST(LIB_VERSION_AGE)
37
38LIBSPDY_VERSION_CURRENT=0
39LIBSPDY_VERSION_REVISION=0
40LIBSPDY_VERSION_AGE=0
41AC_SUBST(LIBSPDY_VERSION_CURRENT)
42AC_SUBST(LIBSPDY_VERSION_REVISION)
43AC_SUBST(LIBSPDY_VERSION_AGE)
44
45
46if test `uname -s` = "OS/390"
47then
48# configure binaries for z/OS
49  if test -z "$CC"
50  then
51    CC=`pwd`"/contrib/xcc"
52    chmod +x $CC || true
53  fi
54  if test -z "$CPP"
55  then
56    CPP="c89 -E"
57  fi
58  if test -z "$CXXCPP"
59  then
60    CXXCPP="c++ -E -+"
61  fi
62#  _CCC_CCMODE=1
63#  _C89_CCMODE=1
64fi
65
66# Checks for programs.
67AC_PROG_AWK
68AC_PROG_INSTALL
69AC_PROG_LN_S
70AC_PROG_MAKE_SET
71AC_CANONICAL_HOST
72AM_PROG_CC_C_O
73LT_INIT([win32-dll])
74LT_LANG([Windows Resource])
75
76PACKAGE_VERSION_MAJOR=${PACKAGE_VERSION%.*.*}
77PACKAGE_VERSION_MINOR=${PACKAGE_VERSION%.*}; PACKAGE_VERSION_MINOR=${PACKAGE_VERSION_MINOR#*.}
78PACKAGE_VERSION_SUBMINOR=${PACKAGE_VERSION#*.*.}
79AC_SUBST([PACKAGE_VERSION_MAJOR])
80AC_SUBST([PACKAGE_VERSION_MINOR])
81AC_SUBST([PACKAGE_VERSION_SUBMINOR])
82AC_CONFIG_FILES([src/microhttpd/microhttpd_dll_res.rc])
83
84MHD_LIB_CPPFLAGS=""
85MHD_LIB_CFLAGS=""
86MHD_LIB_LDFLAGS=""
87MHD_LIBDEPS=""
88
89AC_ARG_WITH([threads],
90   [AC_HELP_STRING([--with-threads=LIB],[choose threading library (posix, w32, auto) [auto]])],
91   [], [with_threads='auto'])
92test "x$with_threads" = "xwin32" && with_threads='w32'
93test "x$with_threads" = "xpthreads" && with_threads='posix'
94
95# Check for posix threads support
96AX_PTHREAD([HAVE_POSIX_THREADS='yes'],[HAVE_POSIX_THREADS='no'])
97AM_CONDITIONAL([HAVE_POSIX_THREADS],[test "x$HAVE_POSIX_THREADS" = "xyes"])
98# Simple check for W32 threads support
99AC_CHECK_HEADER([windows.h],
100  [
101    AC_MSG_CHECKING([for CreateThread()])
102    AC_LINK_IFELSE(
103      [AC_LANG_PROGRAM([#include <windows.h>], [ HANDLE h = CreateThread(NULL, 0, NULL, NULL, 0, NULL);])],
104      [
105        AC_MSG_RESULT([yes])
106        HAVE_W32_THREADS='yes'
107      ],
108      [
109        AC_MSG_RESULT([no])
110        HAVE_W32_THREADS='no'
111      ])
112  ],
113  [HAVE_W32_THREADS='no'])
114
115# for pkg-config
116MHD_LIBDEPS=""
117MHD_REQ_PRIVATE=''
118# Check system type
119case "$host_os" in
120*darwin* | *rhapsody* | *macosx*)
121     AC_DEFINE_UNQUOTED(OSX,1,[This is an OS X system])
122     CFLAGS="-no-cpp-precomp -fno-common $CFLAGS"
123     ;;
124freebsd*)
125     AC_DEFINE_UNQUOTED(SOMEBSD,1,[This is a BSD system])
126     AC_DEFINE_UNQUOTED(FREEBSD,1,[This is a FreeBSD system])
127     ;;
128openbsd*)
129     AC_DEFINE_UNQUOTED(SOMEBSD,1,[This is a BSD system])
130     AC_DEFINE_UNQUOTED(OPENBSD,1,[This is an OpenBSD system])
131     ;;
132netbsd*)
133     AC_DEFINE_UNQUOTED(SOMEBSD,1,[This is a BSD system])
134     AC_DEFINE_UNQUOTED(NETBSD,1,[This is a NetBSD system])
135     ;;
136*solaris*)
137     AC_DEFINE_UNQUOTED(SOLARIS,1,[This is a Solaris system])
138     AC_DEFINE_UNQUOTED(_REENTRANT,1,[Need with solaris or errno doesnt work])
139     AC_SEARCH_LIBS(gethostbyname, nsl)
140     AC_SEARCH_LIBS(socket, socket)
141     ;;
142*arm-linux*)
143     AC_DEFINE_UNQUOTED(LINUX,1,[This is a Linux kernel])
144     AC_DEFINE_UNQUOTED(HAVE_LISTEN_SHUTDOWN,1,[can use shutdown on listen sockets])
145     CFLAGS="-fPIC -pipe $CFLAGS"
146     ;;
147*linux*)
148     AC_DEFINE_UNQUOTED(LINUX,1,[This is a Linux kernel])
149     AC_DEFINE_UNQUOTED(HAVE_LISTEN_SHUTDOWN,1,[can use shutdown on listen sockets])
150     ;;
151*cygwin*)
152     AC_DEFINE_UNQUOTED(CYGWIN,1,[This is a Cygwin system])
153     os_is_windows=yes
154     ;;
155*mingw*)
156     AC_DEFINE_UNQUOTED(MINGW,1,[This is a MinGW system])
157     AC_DEFINE_UNQUOTED(WINDOWS,1,[This is a Windows system])
158     LIBS="$LIBS -lws2_32"
159     AC_CHECK_HEADERS([winsock2.h ws2tcpip.h],, AC_MSG_ERROR([[Winsock2 headers are required for W32]]))
160     AC_CACHE_CHECK([for MS lib utility], [ac_cv_use_ms_lib_tool],
161       [[mslibcheck=`lib 2>&1`
162        if [[ $mslibcheck = "Microsoft (R) Library Manager"* ]]; then
163          ac_cv_use_ms_lib_tool=yes
164        else
165          ac_cv_use_ms_lib_tool=no
166        fi
167         ]])
168     if test "x$ac_cv_use_ms_lib_tool" = "xyes"; then
169       AC_SUBST([MS_LIB_TOOL], [[lib]])
170     fi
171     AC_SUBST([lt_cv_objdir])
172     os_is_windows=yes
173     os_is_native_w32=yes
174     ;;
175*openedition*)
176     AC_DEFINE_UNQUOTED(OS390,1,[This is a OS/390 system])
177    ;;
178*)
179     AC_MSG_WARN([Unrecognised OS $host_os])
180     AC_DEFINE_UNQUOTED(OTHEROS,1,[Some strange OS])
181#    You might want to find out if your OS supports shutdown on listen sockets,
182#    and extend the switch statement; if we do not have 'HAVE_LISTEN_SHUTDOWN',
183#    pipes are used instead to signal 'select'.
184#    AC_DEFINE_UNQUOTED(HAVE_LISTEN_SHUTDOWN,1,[can use shutdown on listen sockets])
185;;
186esac
187
188if test "x$with_threads" = "xposix"; then
189# forced posix threads
190  if test "x$HAVE_POSIX_THREADS" = "xyes"; then
191    USE_THREADS='posix'
192  else
193    if test "x$HAVE_W32_THREADS" = "xyes"; then
194      AC_MSG_ERROR([[Posix threads are not available. Try to configure --with-threads=auto]])
195    else
196      AC_MSG_ERROR([[Posix threads are not available]])
197    fi
198  fi
199elif test "x$with_threads" = "xw32"; then
200# forced w32 threads
201  if test "x$HAVE_W32_THREADS" = "xyes"; then
202    USE_THREADS='w32'
203  else
204    if test "x$HAVE_POSIX_THREADS" = "xyes"; then
205      AC_MSG_ERROR([[W32 threads are not available. Try to configure --with-threads=auto]])
206    else
207      AC_MSG_ERROR([[W32 threads are not available]])
208    fi
209  fi
210else
211# automatic threads lib selection
212  if test "x$HAVE_POSIX_THREADS" = "xyes" && test "x$HAVE_W32_THREADS" = "xyes"; then
213    if test "x$os_is_native_w32" = "xyes"; then
214      USE_THREADS='w32'
215    else
216      USE_THREADS='posix'
217    fi
218  elif test "x$HAVE_POSIX_THREADS" = "xyes"; then
219    USE_THREADS='posix'
220  elif test "x$HAVE_W32_THREADS" = "xyes"; then
221    USE_THREADS='w32'
222  else
223    AC_MSG_ERROR([[No threading lib is available. Cosider installing pthreads]])
224  fi
225fi
226
227if test "x$USE_THREADS" = "xposix"; then
228  CC="$PTHREAD_CC"
229  AC_DEFINE([MHD_USE_POSIX_THREADS],[1],[define to use pthreads])
230  MHD_LIB_CFLAGS="$MHD_LIB_CFLAGS $PTHREAD_CFLAGS"
231  MHD_LIBDEPS="$PTHREAD_LIBS $MHD_LIBDEPS"
232elif test "x$USE_THREADS" = "xw32"; then
233  AC_DEFINE([MHD_USE_W32_THREADS],[1],[define to use W32 threads])
234fi
235AM_CONDITIONAL([USE_POSIX_THREADS], [test "x$USE_THREADS" = "xposix"])
236AM_CONDITIONAL([USE_W32_THREADS], [test "x$USE_THREADS" = "xw32"])
237
238
239AM_CONDITIONAL(HAVE_W32, [test "x$os_is_native_w32" = "xyes"])
240w32_shared_lib_exp=no
241if test "x$enable_shared" = "xyes" && test "x$os_is_native_w32" = "xyes"; then
242  if test "x$ac_cv_use_ms_lib_tool" = "xyes" || test -n "$DLLTOOL"; then
243    w32_shared_lib_exp=yes
244  else
245    AC_MSG_WARN([[GNU dlltool or MS lib.exe is required for creating shared library export on W32]])
246    AC_MSG_WARN([[Export library libmicrohttpd.lib will not be created]])
247  fi
248fi
249AM_CONDITIONAL(W32_SHARED_LIB_EXP, [test "x$w32_shared_lib_exp" = "xyes"])
250AM_CONDITIONAL(USE_MS_LIB_TOOL, [test "x$ac_cv_use_ms_lib_tool" = "xyes"])
251
252# set GCC options
253# use '-fno-strict-aliasing', but only if the compiler
254# and linker can take it
255AX_CHECK_LINK_FLAG([-fno-strict-aliasing],
256  [AX_APPEND_COMPILE_FLAGS([-fno-strict-aliasing])])
257
258AC_C_BIGENDIAN
259
260AC_CHECK_PROG([HAVE_CURL_BINARY],[curl],[yes],[no])
261AM_CONDITIONAL([HAVE_CURL_BINARY],[test "x$HAVE_CURL_BINARY" = "xyes"])
262AC_CHECK_PROG([HAVE_MAKEINFO_BINARY],[makeinfo],[yes],[no])
263AM_CONDITIONAL([HAVE_MAKEINFO_BINARY],[test "x$HAVE_MAKEINFO_BINARY" = "xyes"])
264AM_CONDITIONAL(W32_STATIC_LIB, [test "x$os_is_native_w32" = "xyes"  && test "x$enable_static" = "xyes"])
265
266
267AC_ARG_ENABLE([[doc]],
268  [AS_HELP_STRING([[--disable-doc]], [do not build any documentation])], ,
269    [enable_doc=yes])
270test "x$enable_doc" = "xno" || enable_doc=yes
271AM_CONDITIONAL([BUILD_DOC], [test "x$enable_doc" = "xyes"])
272
273AC_ARG_ENABLE([[examples]],
274  [AS_HELP_STRING([[--disable-examples]], [do not build any examples])], ,
275    [enable_examples=yes])
276test "x$enable_examples" = "xno" || enable_examples=yes
277AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$enable_examples" = "xyes"])
278
279AC_ARG_ENABLE([[poll]],
280  [AS_HELP_STRING([[--enable-poll[=ARG]]], [enable poll support (yes, no, auto) [auto]])],
281    [enable_poll=${enableval}],
282    [enable_poll='auto']
283  )
284
285if test "$enable_poll" != "no"; then
286  if test "$os_is_native_w32" != "yes"; then
287    AC_CHECK_HEADERS([poll.h],
288      [
289        AC_CHECK_FUNCS([poll], [have_poll='yes'], [have_poll='no'])
290      ])
291  else
292    AC_MSG_CHECKING([for WSAPoll()])
293    AC_LINK_IFELSE([
294      AC_LANG_PROGRAM([[#include <winsock2.h>]], [[
295WSAPOLLFD fda[2];
296WSAPoll(fda, 2, 0);]])],
297        [
298          have_poll='yes'
299          AC_DEFINE([HAVE_POLL],[1])
300        ], [have_poll='no'])
301    AC_MSG_RESULT([$have_poll])
302  fi
303  if test "$enable_poll" = "yes" && test "$have_poll" != "yes"; then
304    AC_MSG_ERROR([[Support for poll was explicitly requested but cannot be enabled on this platform.]])
305  fi
306  enable_poll="$have_poll"
307fi
308
309AC_ARG_ENABLE([[epoll]],
310  [AS_HELP_STRING([[--enable-epoll[=ARG]]], [enable epoll support (yes, no, auto) [auto]])],
311    [enable_epoll=${enableval}],
312    [enable_epoll='auto']
313  )
314
315if test "$enable_epoll" != "no"; then
316  AX_HAVE_EPOLL
317  if test "${ax_cv_have_epoll}" = "yes"; then
318    AC_DEFINE([EPOLL_SUPPORT],[1],[define to 1 to enable epoll support])
319    enable_epoll='yes'
320  else
321    AC_DEFINE([EPOLL_SUPPORT],[0],[define to 0 to disable epoll support])
322    if test "$enable_epoll" = "yes"; then
323      AC_MSG_ERROR([[Support for epoll was explicitly requested but cannot be enabled on this platform.]])
324    fi
325    enable_epoll='no'
326  fi
327fi
328
329if test "x$enable_epoll" = "xyes"; then
330  AC_CACHE_CHECK([for epoll_create1()], [mhd_cv_have_epoll_create1], [
331    AC_LINK_IFELSE([
332      AC_LANG_PROGRAM([[#include <sys/epoll.h>]], [[
333int fd;
334fd = epoll_create1(EPOLL_CLOEXEC);]])],
335      [mhd_cv_have_epoll_create1=yes],
336      [mhd_cv_have_epoll_create1=no])])
337  AS_IF([test "x$mhd_cv_have_epoll_create1" = "xyes"],[
338    AC_DEFINE([[HAVE_EPOLL_CREATE1]], [[1]], [Define if you have epoll_create1 function.])])
339fi
340
341if test "x$HAVE_POSIX_THREADS" = "xyes"; then
342  # Check for pthread_setname_np()
343  SAVE_LIBS="$LIBS"
344  SAVE_CFLAGS="$CFLAGS"
345  LIBS="$PTHREAD_LIBS $LIBS"
346  CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
347  AC_MSG_CHECKING([[for pthread_setname_np]])
348  AC_LINK_IFELSE(
349    [AC_LANG_PROGRAM([[#include <pthread.h>]], [[  pthread_setname_np(pthread_self(), "name")]])],
350    [AC_DEFINE([[HAVE_PTHREAD_SETNAME_NP]], [[1]], [Define if you have pthread_setname_np function.])
351     AC_MSG_RESULT([[yes]])],
352    [AC_MSG_RESULT([[no]])] )
353  LIBS="$SAVE_LIBS"
354  CFLAGS="$SAVE_CFLAGS"
355fi
356
357# Check for headers that are ALWAYS required
358AC_CHECK_HEADERS([fcntl.h math.h errno.h limits.h stdio.h locale.h sys/stat.h sys/types.h pthread.h],,AC_MSG_ERROR([Compiling libmicrohttpd requires standard UNIX headers files]))
359
360# Check for optional headers
361AC_CHECK_HEADERS([sys/types.h sys/time.h sys/msg.h netdb.h netinet/in.h netinet/tcp.h time.h sys/socket.h sys/mman.h arpa/inet.h sys/select.h search.h])
362AM_CONDITIONAL([HAVE_TSEARCH], [test "x$ac_cv_header_search_h" = "xyes"])
363
364AC_CHECK_MEMBER([struct sockaddr_in.sin_len],
365   [ AC_DEFINE(HAVE_SOCKADDR_IN_SIN_LEN, 1, [Do we have sockaddr_in.sin_len?])
366   ],
367   [],
368   [
369    #ifdef HAVE_SYS_TYPES_H
370      #include <sys/types.h>
371    #endif
372    #ifdef HAVE_SYS_SOCKET_H
373      #include <sys/socket.h>
374    #endif
375    #ifdef HAVE_NETINET_IN_H
376      #include <netinet/in.h>
377    #endif
378   ])
379
380
381# Check for pipe/socketpair signaling
382AC_MSG_CHECKING([[whether to enable signaling by socketpair]])
383
384AC_ARG_ENABLE([[socketpair]],
385	[AS_HELP_STRING([[--enable-socketpair[=ARG]]], [disable internal singalling by pipes and use socket pair instead (yes, no, try) [no]])], ,
386	[AS_IF([[test "x$os_is_windows" = "xyes"]], [enable_socketpair=yes], [enable_socketpair=no])]
387  )
388
389AS_IF(
390       [[test "x$enable_socketpair" != "xno"]],
391         [AS_IF([[test "x$os_is_windows" = "xyes"]],
392           [ AC_MSG_RESULT([[yes, forced on W32]]) ],
393           [ AC_LINK_IFELSE(
394             [ AC_LANG_PROGRAM([[
395				#ifdef HAVE_SYS_TYPES_H
396				#include <sys/types.h>
397				#endif
398				#ifdef HAVE_SYS_SOCKET_H
399				#include <sys/socket.h>
400				#endif
401				]],[[
402				  int sv[2];
403				  if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) != 0) return 1
404				]])
405             ],
406             [ AC_MSG_RESULT([[yes, socketpair in available]]) ],
407             [ AC_MSG_RESULT([[no, socketpair in not available]])
408              AS_IF([[test "x$enable_socketpair" = "xyes"]], [ AC_MSG_ERROR([[socketpair signalling cannot be enabled.]]) ])
409             ]
410             )
411           ]
412          )
413         ],
414       [
415        AC_MSG_RESULT([[no]])
416        AS_IF([[test "x$os_is_windows" = "xyes"]], [ AC_MSG_ERROR([[socketpair must be enabled on W32]]) ])
417       ]
418     )
419if test "x$enable_socketpair" = "xyes"; then
420	AC_DEFINE([[MHD_DONT_USE_PIPES]], [[1]], [Define to use pair of sockets instead of pipes for signaling])
421fi
422
423AC_CHECK_FUNCS_ONCE([memmem accept4])
424AC_MSG_CHECKING([[for gmtime_s]])
425AC_LINK_IFELSE(
426  [AC_LANG_PROGRAM(
427    [[ #include <time.h>]], [[struct tm now; time_t t; time (&t); gmtime_s (&now, &t)]])
428  ],
429  [
430    AC_DEFINE([HAVE_GMTIME_S], [1], [Define to 1 if you have `gmtime_s' function (only for W32).])
431    AC_MSG_RESULT([[yes]])
432  ],
433  [AC_MSG_RESULT([[no]])
434  ])
435
436
437AC_CHECK_DECLS([SOCK_NONBLOCK], [AC_DEFINE([HAVE_SOCK_NONBLOCK], [1], [SOCK_NONBLOCK is defined in a socket header])], [],
438                   [
439                    #if defined HAVE_SYS_TYPES_H
440                    #  include <sys/types.h>
441                    #endif
442                    #if defined HAVE_SYS_SOCKET_H
443                    #  include <sys/socket.h>
444                    #elif defined HAVE_WINSOCK2_H
445                    #  include <winsock2.h>
446                    #endif
447                   ])
448
449
450AC_SEARCH_LIBS([clock_gettime], [rt], [
451				AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Have clock_gettime])
452])
453
454# IPv6
455AC_MSG_CHECKING(for IPv6)
456AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
457#include <stdio.h>
458#if HAVE_NETINET_IN_H
459#include <netinet/in.h>
460#endif
461#if HAVE_SYS_SOCKET_H
462#include <sys/socket.h>
463#endif
464#if HAVE_WINSOCK2_H
465#include <winsock2.h>
466#endif
467#if HAVE_WS2TCPIP_H
468#include <ws2tcpip.h>
469#endif
470]], [[
471int af=AF_INET6;
472int pf=PF_INET6;
473struct sockaddr_in6 sa;
474printf("%d %d %p\n", af, pf, &sa);
475]])],[
476have_inet6=yes;
477AC_DEFINE([HAVE_INET6], [1], [Provides IPv6 headers])
478],[
479have_inet6=no
480])
481AC_MSG_RESULT($have_inet6)
482
483# TCP_CORK and TCP_NOPUSH
484AC_CHECK_DECLS([TCP_CORK, TCP_NOPUSH], [], [], [[#include <netinet/tcp.h>]])
485
486HIDDEN_VISIBILITY_CFLAGS=""
487case "$host" in
488  *-*-mingw*)
489    dnl on mingw32 we do -fvisibility=hidden and __declspec(dllexport)
490    AC_DEFINE([_MHD_EXTERN], [__attribute__((visibility("default"))) __declspec(dllexport) extern],
491              [defines how to decorate public symbols while building])
492    HIDDEN_VISIBILITY_CFLAGS="-fvisibility=hidden"
493    ;;
494  *)
495    dnl on other compilers, check if we can do -fvisibility=hidden
496    AX_CHECK_LINK_FLAG([-fvisibility=hidden],
497      [AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],
498                           [AC_DEFINE([_MHD_EXTERN], [__attribute__((visibility("default"))) extern],
499                                       [defines how to decorate public symbols while building])
500                            HIDDEN_VISIBILITY_CFLAGS="-fvisibility=hidden"])])
501    ;;
502esac
503AC_SUBST(HIDDEN_VISIBILITY_CFLAGS)
504
505# libcurl (required for testing)
506AC_ARG_ENABLE([curl],
507  [AS_HELP_STRING([--disable-curl],[disable cURL based testcases])],
508  [enable_curl=${enableval}])
509curl=0
510if test "$enable_curl" != "no"
511then
512  LIBCURL_CHECK_CONFIG([yes],[7.16.4],[enable_curl=yes],
513    [
514      if test "x$enable_curl" = "xyes"; then
515        AC_MSG_WARN([[cURL-based tests cannot be enabled because libcurl is missing]])
516      fi
517      enable_curl=no
518    ])
519fi
520if test "$enable_curl" != "no"
521then
522# Lib cURL & cURL - OpenSSL versions
523  AC_DEFINE([MHD_REQ_CURL_VERSION], ["7.16.4"], [required cURL version to run tests])
524  AC_DEFINE([MHD_REQ_CURL_OPENSSL_VERSION], ["0.9.8"], [required cURL SSL version to run tests])
525  AC_DEFINE([MHD_REQ_CURL_GNUTLS_VERSION], ["2.8.6"], [gnuTLS lib version - used in conjunction with cURL])
526  AC_DEFINE([MHD_REQ_CURL_NSS_VERSION], ["3.12.0"], [NSS lib version - used in conjunction with cURL])
527fi
528AM_CONDITIONAL([HAVE_CURL], [test "x$enable_curl" = "xyes"])
529
530AC_CHECK_LIB([[magic]], [[magic_open]],
531  [AC_CHECK_HEADERS([magic.h],
532   AM_CONDITIONAL(HAVE_MAGIC, true),
533   AM_CONDITIONAL(HAVE_MAGIC, false))],
534  AM_CONDITIONAL(HAVE_MAGIC, false))
535
536
537# optional: libmicrospdy support. Enabled by default if not on W32
538AC_ARG_ENABLE([spdy],
539		AS_HELP_STRING([--enable-spdy],
540			[enable build libmicrospdy (yes, no, auto) [auto]]),
541		[enable_spdy=${enableval}],
542		[ AS_IF([[test "x$os_is_windows" = "xyes"]], [enable_spdy=no]) ])
543
544if test "$enable_spdy" != "no"
545then
546  AX_CHECK_OPENSSL([ have_openssl=yes ],[ have_openssl=no ])
547  if test "x$have_openssl" = "xyes"
548  then
549    # check OpenSSL headers
550    SAVE_CPP_FLAGS="$CPPFLAGS"
551    CPPFLAGS="$OPENSSL_INCLUDES $CPPFLAGS"
552    AC_CHECK_HEADERS([openssl/evp.h openssl/rsa.h openssl/rand.h openssl/err.h openssl/sha.h openssl/pem.h openssl/engine.h], [ have_openssl=yes ],[ have_openssl=no ])
553    if test "x$have_openssl" = "xyes"
554    then
555      # check OpenSSL libs
556      SAVE_LIBS="$LIBS"
557      SAVE_LD_FLAGS="$LDFLAGS"
558      LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS"
559      LIBS="$OPENSSL_LIBS $LIBS"
560      AC_CHECK_FUNC([SSL_CTX_set_next_protos_advertised_cb],
561        [
562          AC_CHECK_FUNC([SSL_library_init], [ have_openssl=yes ],[ have_openssl=no ])
563        ],[ have_openssl=no ])
564      LIBS="$SAVE_LIBS"
565      LDFLAGS="$SAVE_LD_FLAGS"
566    fi
567    CPPFLAGS="$SAVE_CPP_FLAGS"
568  fi
569  if test "x$have_openssl" = "xyes"
570  then
571    enable_spdy=yes
572  else
573    AS_IF([[test "x$enable_spdy" = "xyes" ]], [AC_MSG_ERROR([[libmicrospdy cannot be enabled without OpenSSL.]])])
574    have_openssl=no
575    enable_spdy=no
576  fi
577else
578  # OpenSSL is used only for libmicrospdy
579  have_openssl=no
580fi
581AM_CONDITIONAL([HAVE_OPENSSL], [test "x$have_openssl" = "xyes"])
582
583if test "$enable_spdy" = "yes"
584then
585 AC_DEFINE([SPDY_SUPPORT],[1],[include libmicrospdy support])
586else
587 AC_DEFINE([SPDY_SUPPORT],[0],[disable libmicrospdy support])
588fi
589AM_CONDITIONAL(ENABLE_SPDY, [test "x$enable_spdy" != "xno"])
590AC_MSG_CHECKING(whether we have OpenSSL and thus can support libmicrospdy)
591AC_MSG_RESULT($enable_spdy)
592
593# for pkg-config
594SPDY_LIBDEPS="$OPENSSL_LIBS"
595
596SPDY_LIB_LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS"
597SPDY_LIB_CFLAGS="$CFLAGS"
598SPDY_LIB_CPPFLAGS="$OPENSSL_INCLUDES $CPPFLAGS"
599AC_SUBST(SPDY_LIB_LDFLAGS)
600AC_SUBST(SPDY_LIB_CFLAGS)
601AC_SUBST(SPDY_LIB_CPPFLAGS)
602# for pkg-config
603AC_SUBST(SPDY_LIBDEPS)
604
605AC_CHECK_HEADERS([spdylay/spdylay.h], [ have_spdylay="yes" ], [have_spdylay="no"])
606AM_CONDITIONAL(HAVE_SPDYLAY, [test "x$have_spdylay" = "xyes"])
607
608# large file support (> 4 GB)
609AC_SYS_LARGEFILE
610AC_FUNC_FSEEKO
611
612# optional: have error messages ?
613AC_MSG_CHECKING(whether to generate error messages)
614AC_ARG_ENABLE([messages],
615   [AS_HELP_STRING([--disable-messages],
616               [disable MHD error messages])],
617   [enable_messages=${enableval}],
618   [enable_messages=yes])
619AC_MSG_RESULT($enable_messages)
620if test "$enable_messages" = "yes"
621then
622 AC_DEFINE([HAVE_MESSAGES],[1],[Include error messages])
623else
624 AC_DEFINE([HAVE_MESSAGES],[0],[Disable error messages])
625fi
626
627
628# optional: have postprocessor?
629AC_MSG_CHECKING(whether to enable postprocessor)
630AC_ARG_ENABLE([postprocessor],
631   [AS_HELP_STRING([--disable-postprocessor],
632               [disable MHD PostProcessor functionality])],
633   [enable_postprocessor=${enableval}],
634   [enable_postprocessor=yes])
635test "x$enable_postprocessor" = "xno" || enable_postprocessor=yes
636AC_MSG_RESULT([[$enable_postprocessor]])
637AM_CONDITIONAL([HAVE_POSTPROCESSOR],test "x$enable_postprocessor" != "xno")
638if test "x$enable_postprocessor" != "xno"
639then
640 AC_DEFINE([HAVE_POSTPROCESSOR],[1],[define to 1 if MHD was build with postprocessor.c])
641fi
642
643
644# optional: have zzuf, socat?
645AC_CHECK_PROG([have_zzuf],[zzuf], [yes], [no])
646AC_CHECK_PROG([have_socat],[socat], [yes], [no])
647AM_CONDITIONAL([HAVE_ZZUF], [test "x$have_zzuf" = "xyes"])
648AM_CONDITIONAL([HAVE_SOCAT], [test "x$have_socat" = "xyes"])
649
650
651# libgcrypt linkage: required for HTTPS support
652AM_PATH_LIBGCRYPT([1.2.2], [have_gcrypt=yes], [have_gcrypt=no])
653if test "x$have_gcrypt" = "xyes"
654then
655  SAVE_CFLAGS="$CFLAGS"
656  CFLAGS="$CFLAGS $LIBGCRYPT_CFLAGS"
657  # LIBGCRYPT_CFLAGS can be actually a CPPFLAGS, so check them both
658  SAVE_CPPFLAGS="$CPPFLAGS"
659  CPPFLAGS="$CPPFLAGS $LIBGCRYPT_CFLAGS"
660  AC_CHECK_HEADERS([gcrypt.h], [], [have_gcrypt=no])
661  CFLAGS="$SAVE_CFLAGS"
662  CPPFLAGS="$SAVE_CPPFLAGS"
663fi
664
665# gnutls
666GNUTLS_CPPFLAGS=""
667GNUTLS_LDFLAGS=""
668have_gnutls=no
669have_gnutls_sni=no
670have_gnutls_pkgcfg=no
671AC_MSG_CHECKING([[how to find GnuTLS library]])
672AC_ARG_WITH([[gnutls]],
673   [AC_HELP_STRING([[--with-gnutls[=PFX]]],[use GnuTLS for HTTPS support, optional PFX overrides pkg-config data for GnuTLS headers (PFX/include) and libs (PFX/lib)])],
674   [
675    case $with_gnutls in
676      no)
677        AC_MSG_RESULT([[GnuTLS disabled]])
678        ;;
679      yes)
680        AC_MSG_RESULT([[automatically, forced]])
681        ;;
682      *)
683        AC_MSG_RESULT([[-I$with_gnutls/include -L$with_gnutls/lib -lgnutls]])
684        SAVE_LDFLAGS="$LDFLAGS"
685        SAVE_CPPFLAGS="$CPPFLAGS"
686        LDFLAGS="-L$with_gnutls/lib $LDFLAGS"
687        CPPFLAGS="-I$with_gnutls/include $CPPFLAGS"
688        have_gnutls_pkgcfg=no
689          AC_CHECK_HEADERS([gnutls/gnutls.h],
690            [AC_CHECK_LIB([gnutls], [gnutls_priority_set],
691              [
692                GNUTLS_CPPFLAGS="-I$with_gnutls/include"
693                GNUTLS_LDFLAGS="-L$with_gnutls/lib"
694                GNUTLS_LIBS="-lgnutls"
695                AC_CHECK_LIB([gnutls], [gnutls_load_file], [AC_CHECK_LIB([gnutls], [gnutls_privkey_import_x509_raw], [have_gnutls_sni=yes])])
696                have_gnutls=yes
697              ])])
698        AS_IF([test "x$have_gnutls" != "xyes"], [AC_MSG_ERROR([can't find usable libgnutls at specified prefix $with_gnutls])])
699        LDFLAGS="$SAVE_LDFLAGS"
700        CPPFLAGS="$SAVE_CPPFLAGS"
701        ;;
702    esac
703   ],
704   [AC_MSG_RESULT([[automatically]])
705   ])
706
707AS_IF([test "x$with_gnutls" != "xno" && test "x$have_gnutls" != "xyes"],
708  [
709    PKG_CHECK_MODULES(GNUTLS, [[gnutls]],
710      [
711       have_gnutls_pkgcfg='yes'
712       SAVE_CPPFLAGS="$CPPFLAGS"
713       SAVE_CFLAGS="$CFLAGS"
714       SAVE_LDFLAGS="$LDFLAGS"
715       SAVE_LIBS="$LIBS"
716       CPPFLAGS="$GNUTLS_CFLAGS $CPPFLAGS"
717       CFLAGS="$GNUTLS_CFLAGS $CFLAGS"
718       LDFLAGS="$GNUTLS_LIBS $LDFLAGS"
719       LIBS="$LIBS $GNUTLS_LIBS"
720       AC_MSG_CHECKING([[whether GnuTLS is usable]])
721       AC_LINK_IFELSE([
722         AC_LANG_PROGRAM([[#include <gnutls/gnutls.h>]], [[
723                gnutls_session_t session;
724                gnutls_priority_t priorities;
725                gnutls_global_init();
726                gnutls_priority_init(&priorities, "NORMAL", NULL);
727                gnutls_init(&session, GNUTLS_SERVER);
728                gnutls_priority_set(session, priorities);
729          ]])],
730          [
731           AC_MSG_RESULT([[yes]])
732           have_gnutls=yes
733           GNUTLS_CPPLAGS="$GNUTLS_CFLAGS"
734           GNUTLS_LDFLAGS="$GNUTLS_LIBS"
735           AC_MSG_CHECKING([[for gnutls_privkey_import_x509_raw()]])
736           AC_LINK_IFELSE([
737             AC_LANG_PROGRAM([[#include <gnutls/gnutls.h>]], [[
738                    gnutls_datum_t data;
739                    gnutls_privkey_t key;
740                    gnutls_load_file("key.pem", &data);
741                    gnutls_privkey_import_x509_raw(key, &data, GNUTLS_X509_FMT_PEM, NULL, 0);
742                    gnutls_free(data.data);
743                  ]])], [[have_gnutls_sni=yes]], [[have_gnutls_sni=no]])
744           AC_MSG_RESULT([[$have_gnutls_sni]])
745          ],
746          [
747           AC_MSG_RESULT([[no]])
748           have_gnutls=no
749          ])
750
751       AS_IF([test "x$have_gnutls" != "xyes"], [AC_MSG_WARN([pkg-config reports that GnuTLS is present, but GnuTLS can't be used])])
752       CPPFLAGS="$SAVE_CPPFLAGS"
753       CFLAGS="$SAVE_CFLAGS"
754       LDFLAGS="$SAVE_LDFLAGS"
755       LIBS="$SAVE_LIBS"
756      ],
757      [
758       have_gnutls_pkgcfg='no'
759       AC_CHECK_HEADERS([gnutls/gnutls.h],
760        [AC_CHECK_LIB([gnutls], [gnutls_priority_set],
761          [
762            GNUTLS_LIBS="-lgnutls"
763            AC_CHECK_LIB([gnutls], [gnutls_load_file], [AC_CHECK_LIB([gnutls], [gnutls_privkey_import_x509_raw], [have_gnutls_sni=yes])])
764            have_gnutls=yes
765          ])])
766      ])
767  ])
768
769AS_IF([test "x$have_gnutls" != "xyes" && test "x$with_gnutls" = "xyes"], [AC_MSG_ERROR([[can't find usable libgnutls]])])
770
771AM_CONDITIONAL(HAVE_GNUTLS, test "x$have_gnutls" = "xyes")
772AM_CONDITIONAL([HAVE_GNUTLS_SNI], [test "x$have_gnutls_sni" = "xyes"])
773
774AC_SUBST([GNUTLS_CPPFLAGS])
775AC_SUBST([GNUTLS_CFLAGS])
776AC_SUBST([GNUTLS_LDFLAGS])
777AC_SUBST([GNUTLS_LIBS])
778
779# optional: HTTPS support.  Enabled by default
780AC_MSG_CHECKING(whether to support HTTPS)
781AC_ARG_ENABLE([https],
782   [AS_HELP_STRING([--enable-https],
783               [enable HTTPS support (yes, no, auto)[auto]])],
784   [enable_https=${enableval}])
785if test "x$enable_https" != "xno"
786then
787  AS_IF([test "x$have_gnutls" = "xyes" && test "x$have_gcrypt" = "xyes"], [
788          AC_DEFINE([HTTPS_SUPPORT],[1],[include HTTPS support])
789          MHD_LIB_CPPFLAGS="$MHD_LIB_CPPFLAGS $LIBGCRYPT_CFLAGS $GNUTLS_CPPFLAGS"
790          MHD_LIB_CFLAGS="$MHD_LIB_CFLAGS $LIBGCRYPT_CFLAGS $GNUTLS_CFLAGS"
791          MHD_LIB_LDFLAGS="$MHD_LIB_LDFLAGS $GNUTLS_LDFLAGS"
792          MHD_LIBDEPS="$GNUTLS_LIBS $LIBGCRYPT_LIBS $MHD_LIBDEPS"
793          enable_https=yes
794          MSG_HTTPS="yes (using libgnutls and libgcrypt)"
795        ], [
796          AS_IF([test "x$have_gnutls" = "xyes"], [crypt_missing="libgrypt"],
797                [test "x$have_gcrypt" = "xyes"], [crypt_missing="libgnutls"],
798                                                 [crypt_missing="libgrypt and libgnutls"])
799          AS_IF([[test "x$enable_https" = "xyes" ]], [AC_MSG_ERROR([[HTTPS support cannot be enabled without $crypt_missing.]])])
800          AC_DEFINE([HTTPS_SUPPORT],[0],[no libgcrypt or libgnutls])
801          enable_https=no
802          MSG_HTTPS="no (lacking $crypt_missing)"
803        ])
804else
805  AC_DEFINE([HTTPS_SUPPORT],[0],[disable HTTPS support])
806  MSG_HTTPS="no (disabled)"
807fi
808AC_MSG_RESULT([$MSG_HTTPS])
809
810AM_CONDITIONAL([ENABLE_HTTPS], [test "x$enable_https" = "xyes"])
811
812# optional: HTTP Basic Auth support. Enabled by default
813AC_MSG_CHECKING(whether to support HTTP basic authentication)
814AC_ARG_ENABLE([bauth],
815		AS_HELP_STRING([--disable-bauth],
816			[disable HTTP basic Auth support]),
817		[enable_bauth=${enableval}],
818		[enable_bauth=yes])
819if test "x$enable_bauth" != "xno"
820then
821 enable_bauth=yes
822 AC_DEFINE([BAUTH_SUPPORT],[1],[include basic Auth support])
823else
824 AC_DEFINE([BAUTH_SUPPORT],[0],[disable basic Auth support])
825fi
826AC_MSG_RESULT($enable_bauth)
827AM_CONDITIONAL(ENABLE_BAUTH, [test "x$enable_bauth" != "xno"])
828
829# optional: HTTP Digest Auth support. Enabled by default
830AC_MSG_CHECKING(whether to support HTTP digest authentication)
831AC_ARG_ENABLE([dauth],
832		AS_HELP_STRING([--disable-dauth],
833			[disable HTTP basic and digest Auth support]),
834		[enable_dauth=${enableval}],
835		[enable_dauth=yes])
836if test "x$enable_dauth" != "xno"
837then
838 enable_dauth=yes
839 AC_DEFINE([DAUTH_SUPPORT],[1],[include digest Auth support])
840else
841 AC_DEFINE([DAUTH_SUPPORT],[0],[disable digest Auth support])
842fi
843AC_MSG_RESULT($enable_dauth)
844AM_CONDITIONAL(ENABLE_DAUTH, [test "x$enable_dauth" != "xno"])
845
846
847
848MHD_LIB_LDFLAGS="$MHD_LIB_LDFLAGS -export-dynamic -no-undefined"
849
850# gcov compilation
851AC_MSG_CHECKING(whether to compile with support for code coverage analysis)
852AC_ARG_ENABLE([coverage],
853              AS_HELP_STRING([--enable-coverage],
854                             [compile the library with code coverage support]),
855              [use_gcov=${enableval}],
856              [use_gcov=no])
857AC_MSG_RESULT($use_gcov)
858AM_CONDITIONAL([USE_COVERAGE], [test "x$use_gcov" = "xyes"])
859
860AX_COUNT_CPUS
861AC_SUBST([CPU_COUNT])
862
863AC_SUBST(MHD_LIB_CPPFLAGS)
864AC_SUBST(MHD_LIB_CFLAGS)
865AC_SUBST(MHD_LIB_LDFLAGS)
866
867# for pkg-config
868AS_IF([[test "x$enable_https" = "xyes" && test "x$have_gnutls_pkgcfg" = "xyes" ]],
869 [ # remove GnuTLS from private libs in .pc file as it defined in Requires.private
870   MHD_REQ_PRIVATE='gnutls'
871   MHD_LIBDEPS_PKGCFG="${MHD_LIBDEPS//$GNUTLS_LIBS/}"
872 ],
873 [
874   MHD_REQ_PRIVATE=''
875   MHD_LIBDEPS_PKGCFG="$MHD_LIBDEPS"
876 ])
877AC_SUBST([MHD_REQ_PRIVATE])
878AC_SUBST([MHD_LIBDEPS_PKGCFG])
879AC_SUBST(MHD_LIBDEPS)
880
881AC_SUBST(CPPFLAGS)
882AC_SUBST(LIBS)
883AC_SUBST(LDFLAGS)
884
885AC_CONFIG_FILES([
886libmicrohttpd.pc
887libmicrospdy.pc
888w32/VS2013/microhttpd_dll_res_vc.rc
889Makefile
890contrib/Makefile
891doc/Makefile
892doc/doxygen/Makefile
893doc/examples/Makefile
894m4/Makefile
895src/Makefile
896src/include/Makefile
897src/platform/Makefile
898src/microhttpd/Makefile
899src/microspdy/Makefile
900src/spdy2http/Makefile
901src/examples/Makefile
902src/testcurl/Makefile
903src/testcurl/https/Makefile
904src/testspdy/Makefile
905src/testzzuf/Makefile])
906AC_OUTPUT
907
908# Finally: summary
909if test "x$enable_curl" != "xyes"; then
910 MSG_CURL="no, many unit tests will not run"
911else
912 MSG_CURL="yes"
913fi
914
915AC_MSG_NOTICE([Configuration Summary:
916  Operating System:  ${host_os}
917  Threading lib:     ${USE_THREADS}
918  libcurl (testing): ${MSG_CURL}
919  Target directory:  ${prefix}
920  Messages:          ${enable_messages}
921  Basic auth.:       ${enable_bauth}
922  Digest auth.:      ${enable_dauth}
923  Postproc:          ${enable_postprocessor}
924  HTTPS support:     ${MSG_HTTPS}
925  poll support:      ${enable_poll=no}
926  epoll support:     ${enable_epoll=no}
927  build docs:        ${enable_doc}
928  build examples:    ${enable_examples}
929  libmicrospdy:      ${enable_spdy}
930  spdylay (testing): ${have_spdylay}
931])
932
933if test "x$enable_https" = "xyes"
934then
935 AC_MSG_NOTICE([HTTPS subsystem configuration:
936  License         :  LGPL only
937 ])
938else
939 AC_MSG_NOTICE([
940  License         :  LGPL or eCos
941])
942fi
943
944if test "x$enable_bauth" != "xyes" -o \
945        "x$enable_dauth" != "xyes" -o \
946        "x$enable_postprocessor" != "xyes"
947then
948 AC_MSG_NOTICE([WARNING: This will be a custom build with missing symbols. Do NOT use this build in a distribution. Building with these kinds of configure options is only for custom builds for embedded systems.])
949fi
950