configure.ac 11 KB

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