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]
62 ntp_openssl_from_pkg_config=no
64 with_crypto=${with_crypto:-openssl,libcrypto}
65 case "$with_crypto" in
67 with_crypto=openssl,libcrypto
70 dnl AC_MSG_NOTICE(['%with_crypto:%{PKG_CONFIG:+notempty}:%{with_openssl_libdir-notgiven}:%{with_openssl_incdir-notgiven}'])
71 dnl str="$with_crypto:${PKG_CONFIG:+notempty}:${with_openssl_libdir-notgiven}:${with_openssl_incdir-notgiven}"
72 dnl AC_MSG_NOTICE([$str])
74 case "$with_crypto:${PKG_CONFIG:+notempty}:${with_openssl_libdir-notgiven}:${with_openssl_incdir-notgiven}" in
76 *:notempty:notgiven:notgiven)
77 for pkg in `echo $with_crypto | sed -e 's/,/ /'`; do
78 AC_MSG_CHECKING([pkg-config for $pkg])
79 if $PKG_CONFIG --exists $pkg ; then
80 CPPFLAGS_NTP="$CPPFLAGS_NTP `$PKG_CONFIG --cflags-only-I $pkg`"
81 CFLAGS_NTP="$CFLAGS_NTP `$PKG_CONFIG --cflags-only-other $pkg`"
82 LDADD_NTP="$LDADD_NTP `$PKG_CONFIG --libs-only-L $pkg`"
83 LDADD_NTP="$LDADD_NTP `$PKG_CONFIG --libs-only-l --static $pkg`"
84 LDFLAGS_NTP="$LDFLAGS_NTP `$PKG_CONFIG --libs-only-other $pkg`"
87 ntp_openssl_from_pkg_config=yes
95 dnl AC_MSG_NOTICE([OpenSSL Phase I checks:])
96 dnl AC_MSG_NOTICE([CPPFLAGS_NTP: $CPPFLAGS_NTP])
97 dnl AC_MSG_NOTICE([CFLAGS_NTP: $CFLAGS_NTP])
98 dnl AC_MSG_NOTICE([LDADD_NTP: $LDADD_NTP])
99 dnl AC_MSG_NOTICE([LDFLAGS_NTP: $LDFLAGS_NTP])
100 case "$with_crypto:$ntp_openssl" in
105 case "${with_rpath-notgiven}" in
107 # Lame - what to do if we need -Wl... but not -R?
113 # This may really only be true for gcc
126 AC_MSG_CHECKING([for openssl library directory])
127 with_openssl_libdir=${with_openssl_libdir-notgiven}
128 case "$with_openssl_libdir" in
132 with_openssl_libdir=default
135 with_openssl_libdir=no
139 case "$with_openssl_libdir" in
142 with_openssl_libdir="/usr/lib /usr/lib/openssl /usr/sfw/lib"
143 with_openssl_libdir="$with_openssl_libdir /usr/local/lib"
144 with_openssl_libdir="$with_openssl_libdir /usr/local/ssl/lib /lib"
146 case "$with_openssl_libdir" in
149 *) # Look for libcrypto.a and libssl.a:
150 for i in $with_openssl_libdir no
154 test -f $i/libcrypto.dylib -a -f $i/libssl.dylib && break
157 test -f $i/libcrypto.so -a -f $i/libssl.so && break
158 test -f $i/libcrypto.a -a -f $i/libssl.a && break
165 AC_MSG_RESULT([$openssl_libdir])
166 case "$openssl_libdir" in
169 AC_MSG_WARN([libcrypto and libssl not found in any of $with_openssl_libdir])
172 AC_MSG_CHECKING([for openssl include directory])
173 with_openssl_incdir=${with_openssl_incdir-notgiven}
174 case "$with_openssl_incdir" in
177 with_openssl_incdir="/usr/include /usr/sfw/include"
178 with_openssl_incdir="$with_openssl_incdir /usr/local/include"
179 with_openssl_incdir="$with_openssl_incdir /usr/local/ssl/include"
181 case "$with_openssl_incdir" in
184 *) # look for openssl/evp.h:
185 for i in $with_openssl_incdir no
187 test -f $i/openssl/evp.h && break
193 AC_MSG_RESULT([$openssl_incdir])
194 case "$openssl_incdir" in
197 AC_MSG_WARN([did not find openssl/evp.h in any of $with_openssl_incdir])
199 if test -z "$openssl_libdir" -o -z "$openssl_incdir"
206 case "$ntp_openssl" in
208 # We have OpenSSL inc/lib dirs - use them.
209 case "$openssl_incdir" in
213 CPPFLAGS_NTP="$CPPFLAGS_NTP -I$openssl_incdir"
216 case "$openssl_libdir" in
220 LDADD_NTP="$LDADD_NTP -L$openssl_libdir"
221 case "$need_dash_r" in
223 LDFLAGS_NTP="$LDFLAGS_NTP -R$openssl_libdir"
225 case "$need_dash_Wlrpath" in
227 LDFLAGS_NTP="$LDFLAGS_NTP -Wl,-rpath,$openssl_libdir"
231 LDADD_NTP="$LDADD_NTP -lcrypto"
235 AC_MSG_CHECKING([if we will use crypto])
236 AC_MSG_RESULT([$ntp_openssl])
238 case "$ntp_openssl" in
240 AC_DEFINE([OPENSSL], [], [Use OpenSSL?])
241 case "$VER_SUFFIX" in
243 *) AC_MSG_ERROR([OPENSSL set but no 'o' in VER_SUFFIX!]) ;;
248 NTPO_SAVED_CPPFLAGS="$CPPFLAGS"
249 CPPFLAGS="$CPPFLAGS $CPPFLAGS_NTP"
250 NTPO_SAVED_LIBS="$LIBS"
253 # check for linking with -lcrypto failure, and try -lcrypto -lz.
254 # Helps m68k-atari-mint
256 case "$ntp_openssl:$ntp_openssl_from_pkg_config" in
258 LIBS="$NTPO_SAVED_LIBS $LDADD_NTP"
260 [if linking with -lcrypto alone works],
261 [ntp_cv_bare_lcrypto],
265 #include "openssl/err.h"
266 #include "openssl/evp.h"
269 ERR_load_crypto_strings();
270 OpenSSL_add_all_algorithms();
273 [ntp_cv_bare_lcrypto=yes],
274 [ntp_cv_bare_lcrypto=no]
277 case "$ntp_cv_bare_lcrypto" in
279 LIBS="$NTPO_SAVED_LIBS $LDADD_NTP -lz"
281 [if linking with -lcrypto -lz works],
286 #include "openssl/err.h"
287 #include "openssl/evp.h"
290 ERR_load_crypto_strings();
291 OpenSSL_add_all_algorithms();
294 [ntp_cv_lcrypto_lz=yes],
295 [ntp_cv_lcrypto_lz=no]
298 case "$ntp_cv_lcrypto_lz" in
300 LDADD_NTP="$LDADD_NTP -lz"
306 # Older OpenSSL headers have a number of callback prototypes inside
307 # other function prototypes which trigger copious warnings with gcc's
308 # -Wstrict-prototypes, which is included in -Wall.
312 # int i2d_RSA_NET(const RSA *a, unsigned char **pp,
313 # int (*cb)(), int sgckey);
318 openssl_triggers_warnings=unknown
319 NTPO_SAVED_CFLAGS="$CFLAGS"
321 case "$ntp_openssl:$GCC" in
323 CFLAGS="$CFLAGS -Werror"
329 /* see if -Werror breaks gcc */
332 [gcc_handles_Werror=yes],
333 [gcc_handles_Werror=no]
335 case "$gcc_handles_Werror" in
337 # if this gcc doesn't do -Werror go ahead and use
338 # -Wstrict-prototypes.
339 openssl_triggers_warnings=yes
342 CFLAGS="$CFLAGS -Wstrict-prototypes"
346 #include "openssl/asn1_mac.h"
347 #include "openssl/bn.h"
348 #include "openssl/err.h"
349 #include "openssl/evp.h"
350 #include "openssl/pem.h"
351 #include "openssl/rand.h"
352 #include "openssl/x509v3.h"
358 [openssl_triggers_warnings=no],
359 [openssl_triggers_warnings=yes]
362 case "$openssl_triggers_warnings" in
364 CFLAGS_NTP="$CFLAGS_NTP -Wno-strict-prototypes"
367 CFLAGS_NTP="$CFLAGS_NTP -Wstrict-prototypes"
371 # gcc without OpenSSL
372 CFLAGS_NTP="$CFLAGS_NTP -Wstrict-prototypes"
375 # Because we don't want -Werror for the EVP_MD_do_all_sorted check
376 CFLAGS="$NTPO_SAVED_CFLAGS"
378 case "$ntp_openssl" in
380 LIBS="$NTPO_SAVED_LIBS $LDADD_NTP"
381 AC_CHECK_FUNCS([EVP_MD_do_all_sorted])
385 dnl AC_MSG_NOTICE([OpenSSL final checks:])
386 dnl AC_MSG_NOTICE([CPPFLAGS_NTP: $CPPFLAGS_NTP])
387 dnl AC_MSG_NOTICE([CFLAGS_NTP: $CFLAGS_NTP])
388 dnl AC_MSG_NOTICE([LDADD_NTP: $LDADD_NTP])
389 dnl AC_MSG_NOTICE([LDFLAGS_NTP: $LDFLAGS_NTP])
391 CPPFLAGS="$NTPO_SAVED_CPPFLAGS"
392 LIBS="$NTPO_SAVED_LIBS"
393 AS_UNSET([NTPO_SAVED_CFLAGS])
394 AS_UNSET([NTPO_SAVED_CPPFLAGS])
395 AS_UNSET([NTPO_SAVED_LIBS])
396 AS_UNSET([openssl_triggers_warnings])
397 AS_UNSET([ntp_openssl_from_pkg_config])
399 dnl ======================================================================