1# AC_PREREQ(2.57)
2AC_INIT(libssh2, [-], libssh2-devel@cool.haxx.se)
3AC_CONFIG_MACRO_DIR([m4])
4AC_CONFIG_SRCDIR([src])
5AC_CONFIG_HEADERS([src/libssh2_config.h example/libssh2_config.h])
6AM_MAINTAINER_MODE
7m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
8
9dnl SED is needed by some of the tools
10AC_PATH_PROG( SED, sed, sed-was-not-found-by-configure,
11              $PATH:/usr/bin:/usr/local/bin)
12AC_SUBST(SED)
13
14if test "x$SED" = "xsed-was-not-found-by-configure"; then
15  AC_MSG_WARN([sed was not found, this may ruin your chances to build fine])
16fi
17
18dnl figure out the libssh2 version
19LIBSSH2VER=`$SED -ne 's/^#define LIBSSH2_VERSION *"\(.*\)"/\1/p' ${srcdir}/include/libssh2.h`
20AM_INIT_AUTOMAKE
21AC_MSG_CHECKING([libssh2 version])
22AC_MSG_RESULT($LIBSSH2VER)
23
24AC_SUBST(LIBSSH2VER)
25
26AB_VERSION=$LIBSSH2VER
27
28AB_INIT
29
30# Check for the OS.
31# Daniel's note: this should not be necessary and we need to work to
32# get this removed.
33AC_CANONICAL_HOST
34case "$host" in
35    *-mingw*)
36    CFLAGS="$CFLAGS -DLIBSSH2_WIN32"
37    LIBS="$LIBS -lws2_32"
38    ;;
39	*-cygwin)
40	CFLAGS="$CFLAGS -DLIBSSH2_WIN32"
41    ;;
42	*darwin*)
43	CFLAGS="$CFLAGS -DLIBSSH2_DARWIN"
44	;;
45    *hpux*)
46    ;;
47    *osf*)
48    CFLAGS="$CFLAGS -D_POSIX_PII_SOCKET"
49    ;;
50    *)
51    ;;
52esac
53
54AC_CHECK_TYPE(long long,
55   [AC_DEFINE(HAVE_LONGLONG, 1,
56      [Define to 1 if the compiler supports the 'long long' data type.])]
57   longlong="yes"
58)
59
60dnl Our configure and build reentrant settings
61CURL_CONFIGURE_REENTRANT
62
63# Some systems (Solaris?) have socket() in -lsocket.
64AC_SEARCH_LIBS(socket, socket)
65
66# Solaris has inet_addr() in -lnsl.
67AC_SEARCH_LIBS(inet_addr, nsl)
68
69AC_SUBST(LIBS)
70
71AC_PROG_CC
72AC_PROG_INSTALL
73AC_PROG_LN_S
74AC_PROG_MAKE_SET
75AC_PATH_PROGS(SSHD, [sshd], [],
76     [$PATH$PATH_SEPARATOR/usr/libexec$PATH_SEPARATOR]dnl
77     [/usr/sbin$PATH_SEPARATOR/usr/etc$PATH_SEPARATOR/etc])
78AM_CONDITIONAL(SSHD, test -n "$SSHD")
79AC_LIBTOOL_WIN32_DLL
80AC_PROG_LIBTOOL
81AC_C_BIGENDIAN
82
83dnl check for how to do large files
84AC_SYS_LARGEFILE
85
86# Crypto backends
87
88found_crypto=none
89found_crypto_str=""
90support_clear_memory=no
91crypto_errors=""
92
93m4_set_add([crypto_backends], [openssl])
94m4_set_add([crypto_backends], [libgcrypt])
95m4_set_add([crypto_backends], [mbedtls])
96m4_set_add([crypto_backends], [wincng])
97
98AC_ARG_WITH([crypto],
99  AC_HELP_STRING([--with-crypto=auto|]m4_set_contents([crypto_backends], [|]),
100    [Select crypto backend (default: auto)]),
101  use_crypto=$withval,
102  use_crypto=auto
103)
104
105case "${use_crypto}" in
106  auto|m4_set_contents([crypto_backends], [|]))
107    m4_set_map([crypto_backends], [LIBSSH2_CHECK_CRYPTO])
108    ;;
109  yes|"")
110    crypto_errors="No crypto backend specified!"
111    ;;
112  *)
113    crypto_errors="Unknown crypto backend '${use_crypto}' specified!"
114    ;;
115esac
116
117if test "$found_crypto" = "none"; then
118  crypto_errors="${crypto_errors}
119Specify --with-crypto=\$backend and/or the neccessary library search prefix.
120
121Known crypto backends: auto, m4_set_contents([crypto_backends], [, ])"
122  AS_MESSAGE([ERROR: ${crypto_errors}])
123else
124  test "$found_crypto_str" = "" && found_crypto_str="$found_crypto"
125fi
126
127m4_set_foreach([crypto_backends], [backend],
128  [AM_CONDITIONAL(m4_toupper(backend), test "$found_crypto" = "backend")]
129)
130m4_undefine([backend])
131
132
133# libz
134
135AC_ARG_WITH([libz],
136  AC_HELP_STRING([--with-libz],[Use libz for compression]),
137  use_libz=$withval,
138  use_libz=auto)
139
140found_libz=no
141libz_errors=""
142
143if test "$use_libz" != no; then
144  AC_LIB_HAVE_LINKFLAGS([z], [], [#include <zlib.h>])
145  if test "$ac_cv_libz" != yes; then
146    if test "$use_libz" = auto; then
147      AC_MSG_NOTICE([Cannot find libz, disabling compression])
148      found_libz="disabled; no libz found"
149    else
150      libz_errors="No libz found!
151Try --with-libz-prefix=PATH if you know that you have it."
152      AS_MESSAGE([ERROR: $libz_errors])
153    fi
154  else
155    AC_DEFINE(LIBSSH2_HAVE_ZLIB, 1, [Compile in zlib support])
156    LIBSREQUIRED="$LIBSREQUIRED${LIBSREQUIRED:+ }zlib"
157    found_libz="yes"
158  fi
159fi
160
161AC_SUBST(LIBSREQUIRED)
162
163#
164# Optional Settings
165#
166AC_ARG_ENABLE(crypt-none,
167  AC_HELP_STRING([--enable-crypt-none],[Permit "none" cipher -- NOT RECOMMENDED]),
168  [AC_DEFINE(LIBSSH2_CRYPT_NONE, 1, [Enable "none" cipher -- NOT RECOMMENDED])])
169
170AC_ARG_ENABLE(mac-none,
171  AC_HELP_STRING([--enable-mac-none],[Permit "none" MAC -- NOT RECOMMENDED]),
172  [AC_DEFINE(LIBSSH2_MAC_NONE, 1, [Enable "none" MAC -- NOT RECOMMENDED])])
173
174AC_ARG_ENABLE(gex-new,
175  AC_HELP_STRING([--disable-gex-new],[Disable "new" diffie-hellman-group-exchange-sha1 method]),
176  [GEX_NEW=$enableval])
177if test "$GEX_NEW" != "no"; then
178  AC_DEFINE(LIBSSH2_DH_GEX_NEW, 1, [Enable newer diffie-hellman-group-exchange-sha1 syntax])
179fi
180
181AC_ARG_ENABLE(clear-memory,
182  AC_HELP_STRING([--disable-clear-memory],[Disable clearing of memory before being freed]),
183  [CLEAR_MEMORY=$enableval])
184if test "$CLEAR_MEMORY" != "no"; then
185  if test "$support_clear_memory" = "yes"; then
186    AC_DEFINE(LIBSSH2_CLEAR_MEMORY, 1, [Enable clearing of memory before being freed])
187    enable_clear_memory=yes
188  else
189    if test "$CLEAR_MEMORY" = "yes"; then
190      AC_MSG_ERROR([secure clearing/zeroing of memory is not supported by the selected crypto backend])
191    else
192      AC_MSG_WARN([secure clearing/zeroing of memory is not supported by the selected crypto backend])
193    fi
194    enable_clear_memory=unsupported
195  fi
196else
197  if test "$support_clear_memory" = "yes"; then
198    enable_clear_memory=no
199  else
200    AC_MSG_WARN([secure clearing/zeroing of memory is not supported by the selected crypto backend])
201    enable_clear_memory=unsupported
202  fi
203fi
204
205dnl ************************************************************
206dnl option to switch on compiler debug options
207dnl
208AC_MSG_CHECKING([whether to enable pedantic and debug compiler options])
209AC_ARG_ENABLE(debug,
210AC_HELP_STRING([--enable-debug],[Enable pedantic and debug options])
211AC_HELP_STRING([--disable-debug],[Disable debug options]),
212[ case "$enable_debug" in
213  no)
214       AC_MSG_RESULT(no)
215       CPPFLAGS="$CPPFLAGS -DNDEBUG"
216       ;;
217  *)   AC_MSG_RESULT(yes)
218    enable_debug=yes
219    CPPFLAGS="$CPPFLAGS -DLIBSSH2DEBUG"
220    CFLAGS="$CFLAGS -g"
221
222    dnl set compiler "debug" options to become more picky, and remove
223    dnl optimize options from CFLAGS
224    CURL_CC_DEBUG_OPTS
225       ;;
226  esac
227 ],
228       enable_debug=no
229       AC_MSG_RESULT(no)
230)
231
232dnl ************************************************************
233dnl Enable hiding of internal symbols in library to reduce its size and
234dnl speed dynamic linking of applications.  This currently is only supported
235dnl on gcc >= 4.0 and SunPro C.
236dnl
237AC_MSG_CHECKING([whether to enable hidden symbols in the library])
238AC_ARG_ENABLE(hidden-symbols,
239AC_HELP_STRING([--enable-hidden-symbols],[Hide internal symbols in library])
240AC_HELP_STRING([--disable-hidden-symbols],[Leave all symbols with default visibility in library]),
241[ case "$enableval" in
242  no)
243       AC_MSG_RESULT(no)
244       ;;
245  *)
246       AC_MSG_CHECKING([whether $CC supports it])
247       if test "$GCC" = yes ; then
248         if $CC --help --verbose 2>&1 | grep fvisibility= > /dev/null ; then
249           AC_MSG_RESULT(yes)
250           AC_DEFINE(LIBSSH2_API, [__attribute__ ((visibility ("default")))], [to make a symbol visible])
251           CFLAGS="$CFLAGS -fvisibility=hidden"
252         else
253            AC_MSG_RESULT(no)
254          fi
255
256       else
257         dnl Test for SunPro cc
258         if $CC 2>&1 | grep flags >/dev/null && $CC -flags | grep xldscope= >/dev/null ; then
259           AC_MSG_RESULT(yes)
260           AC_DEFINE(LIBSSH2_API, [__global], [to make a symbol visible])
261           CFLAGS="$CFLAGS -xldscope=hidden"
262         else
263           AC_MSG_RESULT(no)
264         fi
265       fi
266       ;;
267  esac ],
268       AC_MSG_RESULT(no)
269)
270
271# Build example applications?
272AC_MSG_CHECKING([whether to build example applications])
273AC_ARG_ENABLE([examples-build],
274AC_HELP_STRING([--enable-examples-build], [Build example applications (this is the default)])
275AC_HELP_STRING([--disable-examples-build], [Do not build example applications]),
276[case "$enableval" in
277  no | false)
278    build_examples='no'
279    ;;
280  *)
281    build_examples='yes'
282    ;;
283esac], [build_examples='yes'])
284AC_MSG_RESULT($build_examples)
285AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != "xno"])
286
287# Checks for header files.
288# AC_HEADER_STDC
289AC_CHECK_HEADERS([errno.h fcntl.h stdio.h stdlib.h unistd.h sys/uio.h])
290AC_CHECK_HEADERS([sys/select.h sys/socket.h sys/ioctl.h sys/time.h])
291AC_CHECK_HEADERS([arpa/inet.h netinet/in.h])
292AC_CHECK_HEADERS([sys/un.h], [have_sys_un_h=yes], [have_sys_un_h=no])
293AM_CONDITIONAL([HAVE_SYS_UN_H], test "x$have_sys_un_h" = xyes)
294
295case $host in
296  *-*-cygwin* | *-*-cegcc*)
297    # These are POSIX-like systems using BSD-like sockets API.
298    ;;
299  *)
300    AC_CHECK_HEADERS([windows.h winsock2.h ws2tcpip.h])
301    ;;
302esac
303
304case $host in
305  *darwin*|*interix*)
306    dnl poll() does not work on these platforms
307    dnl Interix: "does provide poll(), but the implementing developer must
308    dnl have been in a bad mood, because poll() only works on the /proc
309    dnl filesystem here"
310    dnl Mac OS X's poll has funny behaviors, like:
311    dnl not being able to do poll on no fildescriptors (10.3?)
312    dnl not being able to poll on some files (like anything in /dev)
313    dnl not having reliable timeout support
314    dnl inconsistent return of POLLHUP where other implementations give POLLIN
315    AC_MSG_NOTICE([poll use is disabled on this platform])
316    ;;
317  *)
318    AC_CHECK_FUNCS(poll)
319    ;;
320esac
321
322AC_CHECK_FUNCS(gettimeofday select strtoll memset_s)
323
324dnl Check for select() into ws2_32 for Msys/Mingw
325if test "$ac_cv_func_select" != "yes"; then
326  AC_MSG_CHECKING([for select in ws2_32])
327  AC_TRY_LINK([
328#ifdef HAVE_WINSOCK2_H
329#ifndef WIN32_LEAN_AND_MEAN
330#define WIN32_LEAN_AND_MEAN
331#endif
332#include <winsock2.h>
333#endif
334    ],[
335      select(0,(fd_set *)NULL,(fd_set *)NULL,(fd_set *)NULL,(struct timeval *)NULL);
336    ],[
337      AC_MSG_RESULT([yes])
338      HAVE_SELECT="1"
339      AC_DEFINE_UNQUOTED(HAVE_SELECT, 1,
340        [Define to 1 if you have the select function.])
341    ],[
342      AC_MSG_RESULT([no])
343  ])
344fi
345
346AC_FUNC_ALLOCA
347
348# Checks for typedefs, structures, and compiler characteristics.
349AC_C_CONST
350AC_C_INLINE
351
352CURL_CHECK_NONBLOCKING_SOCKET
353
354missing_required_deps=0
355
356if test "${libz_errors}" != ""; then
357  AS_MESSAGE([ERROR: ${libz_errors}])
358  missing_required_deps=1
359fi
360
361if test "$found_crypto" = "none"; then
362  AS_MESSAGE([ERROR: ${crypto_errors}])
363  missing_required_deps=1
364fi
365
366if test $missing_required_deps = 1; then
367  AC_MSG_ERROR([Required dependencies are missing!])
368fi
369
370# Configure parameters
371LIBSSH2_CHECK_OPTION_WERROR
372
373AC_CONFIG_FILES([Makefile
374                 src/Makefile
375                 tests/Makefile
376                 example/Makefile
377                 docs/Makefile
378                 libssh2.pc])
379AC_OUTPUT
380
381AC_MSG_NOTICE([summary of build options:
382
383  version:          ${LIBSSH2VER}
384  Host type:        ${host}
385  Install prefix:   ${prefix}
386  Compiler:         ${CC}
387  Compiler flags:   ${CFLAGS}
388  Library types:    Shared=${enable_shared}, Static=${enable_static}
389  Crypto library:   ${found_crypto_str}
390  Clear memory:     $enable_clear_memory
391  Debug build:      $enable_debug
392  Build examples:   $build_examples
393  Path to sshd:     $ac_cv_path_SSHD (only for self-tests)
394  zlib compression: ${found_libz}
395])
396