libssh2
/
configure.ac
453 строки · 12.5 Кб
1# Copyright (C) The libssh2 project and its contributors.
2#
3# SPDX-License-Identifier: BSD-3-Clause
4#
5
6# AC_PREREQ(2.59)
7AC_INIT([libssh2],[-],[libssh2-devel@lists.haxx.se])
8AC_CONFIG_MACRO_DIR([m4])
9AC_CONFIG_SRCDIR([src])
10AC_CONFIG_HEADERS([src/libssh2_config.h])
11AC_REQUIRE_AUX_FILE([tap-driver.sh])
12AM_MAINTAINER_MODE
13m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
14
15dnl SED is needed by some of the tools
16AC_PATH_PROG( SED, sed, sed-was-not-found-by-configure,
17$PATH:/usr/bin:/usr/local/bin)
18AC_SUBST(SED)
19
20if test "x$SED" = "xsed-was-not-found-by-configure"; then
21AC_MSG_WARN([sed was not found, this may ruin your chances to build fine])
22fi
23
24dnl figure out the libssh2 version
25LIBSSH2_VERSION=`$SED -ne 's/^#define LIBSSH2_VERSION *"\(.*\)"/\1/p' ${srcdir}/include/libssh2.h`
26AM_INIT_AUTOMAKE
27AC_MSG_CHECKING([libssh2 version])
28AC_MSG_RESULT($LIBSSH2_VERSION)
29
30AC_SUBST(LIBSSH2_VERSION)
31
32# Check for the OS.
33# Daniel's note: this should not be necessary and we need to work to
34# get this removed.
35AC_CANONICAL_HOST
36case "$host" in
37*-mingw*)
38LIBS="$LIBS -lws2_32"
39;;
40*darwin*)
41;;
42*hpux*)
43;;
44*osf*)
45CFLAGS="$CFLAGS -D_POSIX_PII_SOCKET"
46;;
47*)
48;;
49esac
50
51dnl Our configure and build reentrant settings
52CURL_CONFIGURE_REENTRANT
53
54# Some systems (Solaris?) have socket() in -lsocket.
55AC_SEARCH_LIBS(socket, socket)
56
57# Solaris has inet_addr() in -lnsl.
58AC_SEARCH_LIBS(inet_addr, nsl)
59
60AC_SUBST(LIBS)
61
62AC_PROG_CC
63AC_PROG_CXX
64AC_PROG_INSTALL
65AC_PROG_LN_S
66AC_PROG_MAKE_SET
67AC_PATH_PROGS(SSHD, [sshd], [],
68[$PATH$PATH_SEPARATOR/usr/libexec$PATH_SEPARATOR]dnl
69[/usr/sbin$PATH_SEPARATOR/usr/etc$PATH_SEPARATOR/etc])
70AM_CONDITIONAL(SSHD, test -n "$SSHD")
71m4_ifdef([LT_INIT],
72[dnl
73LT_INIT([win32-dll])
74],[dnl
75AC_LIBTOOL_WIN32_DLL
76AC_PROG_LIBTOOL
77])
78AC_C_BIGENDIAN
79
80LT_LANG([Windows Resource])
81
82dnl check for windows.h
83case $host in
84*-*-msys | *-*-cygwin* | *-*-cegcc*)
85# These are POSIX-like systems using BSD-like sockets API.
86;;
87*)
88AC_CHECK_HEADERS([windows.h], [have_windows_h=yes], [have_windows_h=no])
89;;
90esac
91
92dnl check for how to do large files
93AC_SYS_LARGEFILE
94
95# Crypto backends
96
97found_crypto=none
98found_crypto_str=""
99crypto_errors=""
100
101m4_set_add([crypto_backends], [openssl])
102m4_set_add([crypto_backends], [libgcrypt])
103m4_set_add([crypto_backends], [mbedtls])
104m4_set_add([crypto_backends], [wincng])
105m4_set_add([crypto_backends], [wolfssl])
106
107AC_ARG_WITH([crypto],
108AS_HELP_STRING([--with-crypto=auto|]m4_set_contents([crypto_backends], [|]),
109[Select crypto backend (default: auto)]),
110use_crypto=$withval,
111use_crypto=auto
112)
113
114case "${use_crypto}" in
115auto|m4_set_contents([crypto_backends], [|]))
116m4_set_map([crypto_backends], [LIBSSH2_CHECK_CRYPTO])
117;;
118yes|"")
119crypto_errors="No crypto backend specified."
120;;
121*)
122crypto_errors="Unknown crypto backend '${use_crypto}' specified."
123;;
124esac
125
126if test "$found_crypto" = "none"; then
127crypto_errors="${crypto_errors}
128Specify --with-crypto=\$backend and/or the necessary library search prefix.
129
130Known crypto backends: auto, m4_set_contents([crypto_backends], [, ])"
131AS_MESSAGE([ERROR: ${crypto_errors}])
132else
133test "$found_crypto_str" = "" && found_crypto_str="$found_crypto"
134fi
135
136# ECDSA support with WinCNG
137AC_ARG_ENABLE(ecdsa-wincng,
138AS_HELP_STRING([--enable-ecdsa-wincng],
139WinCNG ECDSA support (requires Windows 10 or later)),
140[wincng_ecdsa=$enableval])
141if test "$wincng_ecdsa" = yes; then
142AC_DEFINE(LIBSSH2_ECDSA_WINCNG, 1, [Enable WinCNG ECDSA support])
143else
144wincng_ecdsa=no
145fi
146
147# libz
148
149AC_ARG_WITH([libz],
150AS_HELP_STRING([--with-libz],[Use libz for compression]),
151use_libz=$withval,
152use_libz=auto)
153
154found_libz=no
155libz_errors=""
156
157if test "$use_libz" != no; then
158AC_LIB_HAVE_LINKFLAGS([z], [], [#include <zlib.h>])
159if test "$ac_cv_libz" != yes; then
160if test "$use_libz" = auto; then
161AC_MSG_NOTICE([Cannot find libz, disabling compression])
162found_libz="disabled; no libz found"
163else
164libz_errors="No libz found.
165Try --with-libz-prefix=PATH if you know that you have it."
166AS_MESSAGE([ERROR: $libz_errors])
167fi
168else
169AC_DEFINE(LIBSSH2_HAVE_ZLIB, 1, [Compile in zlib support])
170LIBSSH2_PC_REQUIRES_PRIVATE="$LIBSSH2_PC_REQUIRES_PRIVATE${LIBSSH2_PC_REQUIRES_PRIVATE:+,}zlib"
171found_libz="yes"
172fi
173fi
174
175AC_SUBST(LIBSSH2_PC_REQUIRES_PRIVATE)
176
177#
178# Optional Settings
179#
180AC_ARG_ENABLE(clear-memory,
181AS_HELP_STRING([--disable-clear-memory],[Disable clearing of memory before being freed]),
182[CLEAR_MEMORY=$enableval])
183if test "$CLEAR_MEMORY" = "no"; then
184AC_DEFINE(LIBSSH2_NO_CLEAR_MEMORY, 1, [Disable clearing of memory before being freed])
185enable_clear_memory=no
186else
187enable_clear_memory=yes
188fi
189
190LIBSSH2_CFLAG_EXTRAS=""
191
192LIBSSH2_CHECK_OPTION_WERROR
193
194dnl ************************************************************
195dnl option to switch on compiler debug options
196dnl
197AC_MSG_CHECKING([whether to enable pedantic and debug compiler options])
198AC_ARG_ENABLE(debug,
199AS_HELP_STRING([--enable-debug],[Enable pedantic and debug options])
200AS_HELP_STRING([--disable-debug],[Disable debug options]),
201[ case "$enable_debug" in
202no)
203AC_MSG_RESULT(no)
204CPPFLAGS="$CPPFLAGS -DNDEBUG"
205;;
206*) AC_MSG_RESULT(yes)
207enable_debug=yes
208CPPFLAGS="$CPPFLAGS -DLIBSSH2DEBUG"
209CFLAGS="$CFLAGS -g"
210
211dnl set compiler "debug" options to become more picky, and remove
212dnl optimize options from CFLAGS
213CURL_CC_DEBUG_OPTS
214;;
215esac
216],
217enable_debug=no
218AC_MSG_RESULT(no)
219)
220
221AC_SUBST(LIBSSH2_CFLAG_EXTRAS)
222
223dnl ************************************************************
224dnl Enable hiding of internal symbols in library to reduce its size and
225dnl speed dynamic linking of applications. This currently is only supported
226dnl on gcc >= 4.0 and SunPro C.
227dnl
228AC_MSG_CHECKING([whether to enable hidden symbols in the library])
229AC_ARG_ENABLE(hidden-symbols,
230AS_HELP_STRING([--enable-hidden-symbols],[Hide internal symbols in library])
231AS_HELP_STRING([--disable-hidden-symbols],[Leave all symbols with default visibility in library (default)]),
232[ case "$enableval" in
233no)
234AC_MSG_RESULT(no)
235;;
236*)
237AC_MSG_CHECKING([whether $CC supports it])
238if test "$GCC" = yes ; then
239if $CC --help --verbose 2>&1 | grep fvisibility= > /dev/null ; then
240AC_MSG_RESULT(yes)
241AC_DEFINE(LIBSSH2_API, [__attribute__ ((visibility ("default")))], [to make a symbol visible])
242CFLAGS="$CFLAGS -fvisibility=hidden"
243else
244AC_MSG_RESULT(no)
245fi
246
247else
248dnl Test for SunPro cc
249if $CC 2>&1 | grep flags >/dev/null && $CC -flags | grep xldscope= >/dev/null ; then
250AC_MSG_RESULT(yes)
251AC_DEFINE(LIBSSH2_API, [__global], [to make a symbol visible])
252CFLAGS="$CFLAGS -xldscope=hidden"
253else
254AC_MSG_RESULT(no)
255fi
256fi
257;;
258esac ],
259AC_MSG_RESULT(no)
260)
261
262dnl Build without deprecated APIs?
263AC_ARG_ENABLE([deprecated],
264[AS_HELP_STRING([--disable-deprecated], [Build without deprecated APIs @<:@default=no@:>@])],
265[case "$enableval" in
266*)
267with_deprecated="no"
268CPPFLAGS="$CPPFLAGS -DLIBSSH2_NO_DEPRECATED"
269;;
270esac],
271[with_deprecated="yes"])
272
273# Run Docker tests?
274AC_ARG_ENABLE([docker-tests],
275[AS_HELP_STRING([--disable-docker-tests],
276[Do not run tests requiring Docker])],
277[run_docker_tests=no], [run_docker_tests=yes])
278AM_CONDITIONAL([RUN_DOCKER_TESTS], [test "x$run_docker_tests" != "xno"])
279
280# Run sshd tests?
281AC_ARG_ENABLE([sshd-tests],
282[AS_HELP_STRING([--disable-sshd-tests],
283[Do not run tests requiring sshd])],
284[run_sshd_tests=no], [run_sshd_tests=yes])
285AM_CONDITIONAL([RUN_SSHD_TESTS], [test "x$run_sshd_tests" != "xno"])
286
287# Build example applications?
288AC_MSG_CHECKING([whether to build example applications])
289AC_ARG_ENABLE([examples-build],
290AS_HELP_STRING([--enable-examples-build], [Build example applications (this is the default)])
291AS_HELP_STRING([--disable-examples-build], [Do not build example applications]),
292[case "$enableval" in
293no | false)
294build_examples='no'
295;;
296*)
297build_examples='yes'
298;;
299esac], [build_examples='yes'])
300AC_MSG_RESULT($build_examples)
301AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$build_examples" != "xno"])
302
303
304# Build OSS fuzzing targets?
305AC_ARG_ENABLE([ossfuzzers],
306[AS_HELP_STRING([--enable-ossfuzzers],
307[Whether to generate the fuzzers for OSS-Fuzz])],
308[have_ossfuzzers=yes], [have_ossfuzzers=no])
309AM_CONDITIONAL([USE_OSSFUZZERS], [test "x$have_ossfuzzers" = "xyes"])
310
311
312# Set the correct flags for the given fuzzing engine.
313AC_SUBST([LIB_FUZZING_ENGINE])
314AM_CONDITIONAL([USE_OSSFUZZ_FLAG], [test "x$LIB_FUZZING_ENGINE" = "x-fsanitize=fuzzer"])
315AM_CONDITIONAL([USE_OSSFUZZ_STATIC], [test -f "$LIB_FUZZING_ENGINE"])
316
317
318# Checks for header files.
319AC_CHECK_HEADERS([errno.h fcntl.h stdio.h unistd.h sys/param.h sys/uio.h])
320AC_CHECK_HEADERS([sys/select.h sys/socket.h sys/ioctl.h sys/time.h])
321AC_CHECK_HEADERS([arpa/inet.h netinet/in.h])
322AC_CHECK_HEADERS([sys/un.h])
323
324case $host in
325*darwin*|*interix*)
326dnl poll() does not work on these platforms
327dnl Interix: "does provide poll(), but the implementing developer must
328dnl have been in a bad mood, because poll() only works on the /proc
329dnl filesystem here"
330dnl macOS poll() has funny behaviors, like:
331dnl not being able to do poll on no fildescriptors (10.3?)
332dnl not being able to poll on some files (like anything in /dev)
333dnl not having reliable timeout support
334dnl inconsistent return of POLLHUP where other implementations give POLLIN
335AC_MSG_NOTICE([poll use is disabled on this platform])
336;;
337*)
338AC_CHECK_FUNCS(poll)
339;;
340esac
341
342AC_CHECK_FUNCS(gettimeofday select strtoll explicit_bzero explicit_memset memset_s snprintf)
343
344dnl Check for select() into ws2_32 for Msys/Mingw
345if test "$ac_cv_func_select" != "yes"; then
346AC_MSG_CHECKING([for select in ws2_32])
347AC_LINK_IFELSE([AC_LANG_PROGRAM([[
348#ifdef HAVE_WINDOWS_H
349#ifndef WIN32_LEAN_AND_MEAN
350#define WIN32_LEAN_AND_MEAN
351#endif
352#include <winsock2.h>
353#endif
354]], [[
355select(0,(fd_set *)NULL,(fd_set *)NULL,(fd_set *)NULL,(struct timeval *)NULL);
356]])],[
357AC_MSG_RESULT([yes])
358HAVE_SELECT="1"
359AC_DEFINE_UNQUOTED(HAVE_SELECT, 1,
360[Define to 1 if you have the select function.])
361],[
362AC_MSG_RESULT([no])
363])
364fi
365
366AC_FUNC_ALLOCA
367
368# Checks for typedefs, structures, and compiler characteristics.
369AC_C_CONST
370AC_C_INLINE
371
372CURL_CHECK_NONBLOCKING_SOCKET
373
374missing_required_deps=0
375
376if test "${libz_errors}" != ""; then
377AS_MESSAGE([ERROR: ${libz_errors}])
378missing_required_deps=1
379fi
380
381if test "$found_crypto" = "none"; then
382AS_MESSAGE([ERROR: ${crypto_errors}])
383missing_required_deps=1
384fi
385
386if test $missing_required_deps = 1; then
387AC_MSG_ERROR([Required dependencies are missing.])
388fi
389
390AM_CONDITIONAL([HAVE_WINDRES],
391[test "x$have_windows_h" = "xyes" && test "x${enable_shared}" = "xyes" && test -n "${RC}"])
392
393AM_CONDITIONAL([HAVE_LIB_STATIC], [test "x$enable_static" != "xno"])
394
395# Configure parameters
396
397# Append crypto lib
398if test "$found_crypto" = "openssl"; then
399LIBS="${LIBS} ${LTLIBSSL}"
400elif test "$found_crypto" = "wolfssl"; then
401LIBS="${LIBS} ${LTLIBWOLFSSL}"
402elif test "$found_crypto" = "libgcrypt"; then
403LIBS="${LIBS} ${LTLIBGCRYPT}"
404elif test "$found_crypto" = "wincng"; then
405LIBS="${LIBS} ${LTLIBBCRYPT}"
406elif test "$found_crypto" = "mbedtls"; then
407LIBS="${LIBS} ${LTLIBMBEDCRYPTO}"
408fi
409
410LIBS="${LIBS} ${LTLIBZ}"
411
412LIBSSH2_PC_LIBS_PRIVATE=$LIBS
413AC_SUBST(LIBSSH2_PC_LIBS_PRIVATE)
414
415dnl merge the pkg-config private fields into public ones when static-only
416if test "x$enable_shared" = "xyes"; then
417LIBSSH2_PC_REQUIRES=
418LIBSSH2_PC_LIBS=
419else
420LIBSSH2_PC_REQUIRES=$LIBSSH2_PC_REQUIRES_PRIVATE
421LIBSSH2_PC_LIBS=$LIBSSH2_PC_LIBS_PRIVATE
422fi
423AC_SUBST(LIBSSH2_PC_REQUIRES)
424AC_SUBST(LIBSSH2_PC_LIBS)
425
426AC_CONFIG_FILES([Makefile
427src/Makefile
428tests/Makefile
429tests/ossfuzz/Makefile
430example/Makefile
431docs/Makefile
432libssh2.pc])
433AC_OUTPUT
434
435AC_MSG_NOTICE([summary of build options:
436
437version: ${LIBSSH2_VERSION}
438Host type: ${host}
439Install prefix: ${prefix}
440Compiler: ${CC}
441Compiler flags: ${CFLAGS}
442Library types: Shared=${enable_shared}, Static=${enable_static}
443Crypto library: ${found_crypto_str}
444WinCNG ECDSA: $wincng_ecdsa
445zlib compression: ${found_libz}
446Clear memory: $enable_clear_memory
447Deprecated APIs: $with_deprecated
448Debug build: $enable_debug
449Build examples: $build_examples
450Run Docker tests: $run_docker_tests
451Run sshd tests: $run_sshd_tests
452Path to sshd: $ac_cv_path_SSHD (only for self-tests)
453])
454