1 dnl ####################################################################
2 dnl OpenSSL support shared by top-level and sntp/configure.ac
4 dnl Provides command-line option --with-crypto, as well as deprecated
5 dnl options --with-openssl-incdir, --with-openssl-libdir, and the
6 dnl latter's suboption --with-rpath.
8 dnl Specifying --with-openssl-libdir or --with-openssl-incdir causes any
9 dnl pkg-config openssl information to be ignored in favor of the legacy
10 dnl manual search for directories and specified library names.
12 dnl Output AC_DEFINEs (for config.h)
13 dnl OPENSSL defined only if using OpenSSL
16 dnl ntp_openssl yes if using OpenSSL, no otherwise
18 dnl Output substitutions:
19 dnl CFLAGS_NTP OpenSSL-specific flags added as needed, and
20 dnl -Wstrict-prototypes for gcc if it does not
21 dnl trigger a flood of warnings for each file
22 dnl including OpenSSL headers.
23 dnl CPPFLAGS_NTP OpenSSL -Iincludedir flags added as needed.
24 dnl LDADD_NTP OpenSSL -L and -l flags added as needed.
25 dnl LDFLAGS_NTP Other OpenSSL link flags added as needed.
27 dnl ####################################################################
28 AC_DEFUN([NTP_OPENSSL], [
29 AC_REQUIRE([NTP_PKG_CONFIG])dnl
30 AC_REQUIRE([NTP_VER_SUFFIX])dnl
36 [+ =openssl,libcrypto]
42 [--with-openssl-libdir],
43 [+ =/something/reasonable]
49 [--with-openssl-incdir],
50 [+ =/something/reasonable]
57 [s Disable auto-added -R linker paths]
61 ntp_openssl_from_pkg_config=no
62 with_crypto=${with_crypto:-openssl,libcrypto}
63 case "$with_crypto" in
65 with_crypto=openssl,libcrypto
67 case "$with_crypto:${PKG_CONFIG:+notempty}:${with_openssl_libdir-notgiven}:${with_openssl_incdir-notgiven}" in
69 *:notempty:notgiven:notgiven)
70 for pkg in `echo $with_crypto | sed -e 's/,/ /'`; do
71 AC_MSG_CHECKING([pkg-config for $pkg])
72 if $PKG_CONFIG --exists $pkg ; then
73 CPPFLAGS_NTP="$CPPFLAGS_NTP `$PKG_CONFIG --cflags-only-I $pkg`"
74 CFLAGS_NTP="$CFLAGS_NTP `$PKG_CONFIG --cflags-only-other $pkg`"
75 LDADD_NTP="$LDADD_NTP `$PKG_CONFIG --libs-only-L $pkg`"
76 LDADD_NTP="$LDADD_NTP `$PKG_CONFIG --libs-only-l $pkg`"
77 LDFLAGS_NTP="$LDFLAGS_NTP `$PKG_CONFIG --libs-only-other $pkg`"
80 ntp_openssl_from_pkg_config=yes
88 case "$with_crypto:$ntp_openssl" in
93 case "${with_rpath-notgiven}" in
95 # Lame - what to do if we need -Wl... but not -R?
101 # This may really only be true for gcc
114 AC_MSG_CHECKING([for openssl library directory])
115 with_openssl_libdir=${with_openssl_libdir-notgiven}
116 case "$with_openssl_libdir" in
120 with_openssl_libdir=default
123 with_openssl_libdir=no
127 case "$with_openssl_libdir" in
130 with_openssl_libdir="/usr/lib /usr/lib/openssl /usr/sfw/lib"
131 with_openssl_libdir="$with_openssl_libdir /usr/local/lib"
132 with_openssl_libdir="$with_openssl_libdir /usr/local/ssl/lib /lib"
134 case "$with_openssl_libdir" in
137 *) # Look for libcrypto.a and libssl.a:
138 for i in $with_openssl_libdir no
142 test -f $i/libcrypto.dylib -a -f $i/libssl.dylib && break
145 test -f $i/libcrypto.so -a -f $i/libssl.so && break
146 test -f $i/libcrypto.a -a -f $i/libssl.a && break
153 AC_MSG_RESULT([$openssl_libdir])
154 case "$openssl_libdir" in
157 AC_MSG_WARN([libcrypto and libssl not found in any of $with_openssl_libdir])
160 AC_MSG_CHECKING([for openssl include directory])
161 with_openssl_incdir=${with_openssl_incdir-notgiven}
162 case "$with_openssl_incdir" in
165 with_openssl_incdir="/usr/include /usr/sfw/include"
166 with_openssl_incdir="$with_openssl_incdir /usr/local/include"
167 with_openssl_incdir="$with_openssl_incdir /usr/local/ssl/include"
169 case "$with_openssl_incdir" in
172 *) # look for openssl/evp.h:
173 for i in $with_openssl_incdir no
175 test -f $i/openssl/evp.h && break
181 AC_MSG_RESULT([$openssl_incdir])
182 case "$openssl_incdir" in
185 AC_MSG_WARN([did not find openssl/evp.h in any of $with_openssl_incdir])
187 if test -z "$openssl_libdir" -o -z "$openssl_incdir"
194 case "$ntp_openssl" in
196 # We have OpenSSL inc/lib dirs - use them.
197 case "$openssl_incdir" in
201 CPPFLAGS_NTP="$CPPFLAGS_NTP -I$openssl_incdir"
204 case "$openssl_libdir" in
208 LDADD_NTP="$LDADD_NTP -L$openssl_libdir"
209 case "$need_dash_r" in
211 LDFLAGS_NTP="$LDFLAGS_NTP -R$openssl_libdir"
213 case "$need_dash_Wlrpath" in
215 LDFLAGS_NTP="$LDFLAGS_NTP -Wl,-rpath,$openssl_libdir"
219 LDADD_NTP="$LDADD_NTP -lcrypto"
223 AC_MSG_CHECKING([if we will use crypto])
224 AC_MSG_RESULT([$ntp_openssl])
226 case "$ntp_openssl" in
228 AC_DEFINE([OPENSSL], [], [Use OpenSSL?])
229 case "$VER_SUFFIX" in
231 *) AC_MSG_ERROR([OPENSSL set but no 'o' in VER_SUFFIX!]) ;;
236 NTPO_SAVED_CPPFLAGS="$CPPFLAGS"
237 CPPFLAGS="$CPPFLAGS $CPPFLAGS_NTP"
238 NTPO_SAVED_LIBS="$LIBS"
241 # check for linking with -lcrypto failure, and try -lcrypto -lz.
242 # Helps m68k-atari-mint
244 case "$ntp_openssl:$ntp_openssl_from_pkg_config" in
246 LIBS="$NTPO_SAVED_LIBS $LDADD_NTP"
248 [if linking with -lcrypto alone works],
249 [ntp_cv_bare_lcrypto],
253 #include "openssl/err.h"
254 #include "openssl/evp.h"
257 ERR_load_crypto_strings();
258 OpenSSL_add_all_algorithms();
261 [ntp_cv_bare_lcrypto=yes],
262 [ntp_cv_bare_lcrypto=no]
265 case "$ntp_cv_bare_lcrypto" in
267 LIBS="$NTPO_SAVED_LIBS $LDADD_NTP -lz"
269 [if linking with -lcrypto -lz works],
274 #include "openssl/err.h"
275 #include "openssl/evp.h"
278 ERR_load_crypto_strings();
279 OpenSSL_add_all_algorithms();
282 [ntp_cv_lcrypto_lz=yes],
283 [ntp_cv_lcrypto_lz=no]
286 case "$ntp_cv_lcrypto_lz" in
288 LDADD_NTP="$LDADD_NTP -lz"
294 # Older OpenSSL headers have a number of callback prototypes inside
295 # other function prototypes which trigger copious warnings with gcc's
296 # -Wstrict-prototypes, which is included in -Wall.
300 # int i2d_RSA_NET(const RSA *a, unsigned char **pp,
301 # int (*cb)(), int sgckey);
306 openssl_triggers_warnings=unknown
307 NTPO_SAVED_CFLAGS="$CFLAGS"
309 case "$ntp_openssl:$GCC" in
311 CFLAGS="$CFLAGS -Werror"
317 /* see if -Werror breaks gcc */
320 [gcc_handles_Werror=yes],
321 [gcc_handles_Werror=no]
323 case "$gcc_handles_Werror" in
325 # if this gcc doesn't do -Werror go ahead and use
326 # -Wstrict-prototypes.
327 openssl_triggers_warnings=yes
330 CFLAGS="$CFLAGS -Wstrict-prototypes"
334 #include "openssl/asn1_mac.h"
335 #include "openssl/bn.h"
336 #include "openssl/err.h"
337 #include "openssl/evp.h"
338 #include "openssl/pem.h"
339 #include "openssl/rand.h"
340 #include "openssl/x509v3.h"
346 [openssl_triggers_warnings=no],
347 [openssl_triggers_warnings=yes]
350 case "$openssl_triggers_warnings" in
352 CFLAGS_NTP="$CFLAGS_NTP -Wno-strict-prototypes"
355 CFLAGS_NTP="$CFLAGS_NTP -Wstrict-prototypes"
359 # gcc without OpenSSL
360 CFLAGS_NTP="$CFLAGS_NTP -Wstrict-prototypes"
363 # Because we don't want -Werror for the EVP_MD_do_all_sorted check
364 CFLAGS="$NTPO_SAVED_CFLAGS"
366 case "$ntp_openssl" in
368 LIBS="$NTPO_SAVED_LIBS $LDADD_NTP"
369 AC_CHECK_FUNCS([EVP_MD_do_all_sorted])
373 CPPFLAGS="$NTPO_SAVED_CPPFLAGS"
374 LIBS="$NTPO_SAVED_LIBS"
375 AS_UNSET([NTPO_SAVED_CFLAGS])
376 AS_UNSET([NTPO_SAVED_CPPFLAGS])
377 AS_UNSET([NTPO_SAVED_LIBS])
378 AS_UNSET([openssl_triggers_warnings])
379 AS_UNSET([ntp_openssl_from_pkg_config])
381 dnl ======================================================================