xref: /freebsd/contrib/ntp/sntp/m4/ntp_openssl.m4 (revision f5f40dd63bc7acbb5312b26ac1ea1103c12352a6)
12b15cb3dSCy Schubertdnl ####################################################################
22b15cb3dSCy Schubertdnl OpenSSL support shared by top-level and sntp/configure.ac
32b15cb3dSCy Schubertdnl
42b15cb3dSCy Schubertdnl Provides command-line option --with-crypto, as well as deprecated
5*f5f40dd6SCy Schubertdnl options --with-openssl-incdir, --with-openssl-libdir..
62b15cb3dSCy Schubertdnl
7*f5f40dd6SCy Schubertdnl Specifying --with-openssl-libdir or --with-openssl-incdir skips
8*f5f40dd6SCy Schubertdnl pkg-config search.
9*f5f40dd6SCy Schubertdnl
10*f5f40dd6SCy Schubertdnl In the past, use of crypto would be silently disabled if the needed
11*f5f40dd6SCy Schubertdnl headers and library were not found.  Now --without-crypto must be
12*f5f40dd6SCy Schubertdnl used or configure will fail with an error.  It is now uncommon
13*f5f40dd6SCy Schubertdnl to want to build ntpd without crypto, so don't be quiet about it.
142b15cb3dSCy Schubertdnl
152b15cb3dSCy Schubertdnl Output AC_DEFINEs (for config.h)
162b15cb3dSCy Schubertdnl	OPENSSL		defined only if using OpenSSL
172b15cb3dSCy Schubertdnl
182b15cb3dSCy Schubertdnl Output variables:
192b15cb3dSCy Schubertdnl	ntp_openssl	yes if using OpenSSL, no otherwise
20*f5f40dd6SCy Schubertdnl	VER_SUFFIX	"o" if using OpenSSL
212b15cb3dSCy Schubertdnl
222b15cb3dSCy Schubertdnl Output substitutions:
232b15cb3dSCy Schubertdnl	CFLAGS_NTP	OpenSSL-specific flags added as needed, and
242b15cb3dSCy Schubertdnl			-Wstrict-prototypes for gcc if it does not
252b15cb3dSCy Schubertdnl			trigger a flood of warnings for each file
262b15cb3dSCy Schubertdnl			including OpenSSL headers.
272b15cb3dSCy Schubertdnl	CPPFLAGS_NTP	OpenSSL -Iincludedir flags added as needed.
282b15cb3dSCy Schubertdnl	LDADD_NTP	OpenSSL -L and -l flags added as needed.
29*f5f40dd6SCy Schubertdnl	LDFLAGS_NTP	OpenSSL runpath flags as needed.
302b15cb3dSCy Schubertdnl
312b15cb3dSCy Schubertdnl ####################################################################
32*f5f40dd6SCy Schubertdnl
332b15cb3dSCy SchubertAC_DEFUN([NTP_OPENSSL], [
34*f5f40dd6SCy SchubertAC_REQUIRE([AC_PROG_SED])dnl
352b15cb3dSCy SchubertAC_REQUIRE([NTP_PKG_CONFIG])dnl
362b15cb3dSCy SchubertAC_REQUIRE([NTP_VER_SUFFIX])dnl
37*f5f40dd6SCy SchubertAC_REQUIRE([NTP_OPENSSL_VERBOSE_MSG])dnl
382b15cb3dSCy Schubert
392b15cb3dSCy SchubertAC_ARG_WITH(
402b15cb3dSCy Schubert    [crypto],
412b15cb3dSCy Schubert    [AS_HELP_STRING(
422b15cb3dSCy Schubert	[--with-crypto],
432b15cb3dSCy Schubert	[+ =openssl,libcrypto]
44*f5f40dd6SCy Schubert    )],
45*f5f40dd6SCy Schubert    [	dnl if given
46*f5f40dd6SCy Schubert	case "$with_crypto" in
47*f5f40dd6SCy Schubert	 yes)
48*f5f40dd6SCy Schubert	    with_crypto=openssl,libcrypto
49*f5f40dd6SCy Schubert	esac
50*f5f40dd6SCy Schubert    ],
51*f5f40dd6SCy Schubert    [with_crypto=openssl,libcrypto]	dnl if not given
522b15cb3dSCy Schubert)
532b15cb3dSCy SchubertAC_ARG_WITH(
542b15cb3dSCy Schubert    [openssl-libdir],
552b15cb3dSCy Schubert    [AS_HELP_STRING(
562b15cb3dSCy Schubert	[--with-openssl-libdir],
572b15cb3dSCy Schubert	[+ =/something/reasonable]
582b15cb3dSCy Schubert    )]
592b15cb3dSCy Schubert)
602b15cb3dSCy SchubertAC_ARG_WITH(
612b15cb3dSCy Schubert    [openssl-incdir],
622b15cb3dSCy Schubert    [AS_HELP_STRING(
632b15cb3dSCy Schubert	[--with-openssl-incdir],
64*f5f40dd6SCy Schubert	[+ =search likely dirs]
652b15cb3dSCy Schubert    )]
662b15cb3dSCy Schubert)
67*f5f40dd6SCy SchubertAC_ARG_ENABLE(
68*f5f40dd6SCy Schubert    [verbose-ssl],
692b15cb3dSCy Schubert    [AS_HELP_STRING(
70*f5f40dd6SCy Schubert	[--enable-verbose-ssl],
71*f5f40dd6SCy Schubert	[- show crypto lib detection details]
72*f5f40dd6SCy Schubert    )],
73*f5f40dd6SCy Schubert    [],
74*f5f40dd6SCy Schubert    [enable_verbose_ssl=no]	dnl default to quiet
752b15cb3dSCy Schubert)
76f0574f5cSXin LI
772b15cb3dSCy Schubertntp_openssl=no
782b15cb3dSCy Schubertntp_openssl_from_pkg_config=no
79*f5f40dd6SCy Schubertntp_ssl_incdir=
80*f5f40dd6SCy Schubertntp_ssl_cflags=
81*f5f40dd6SCy Schubertntp_ssl_cppflags=
82*f5f40dd6SCy Schubertntp_ssl_libdir=
83*f5f40dd6SCy Schubertntp_ssl_libs_L=
84*f5f40dd6SCy Schubertntp_ssl_libs_l=
85*f5f40dd6SCy Schubertntp_ssl_libs=
86*f5f40dd6SCy Schubertntp_ssl_ldflags=
87f0574f5cSXin LI
88*f5f40dd6SCy SchubertNTPSSL_SAVED_CFLAGS="$CFLAGS"
89*f5f40dd6SCy SchubertNTPSSL_SAVED_CPPFLAGS="$CPPFLAGS"
90*f5f40dd6SCy SchubertNTPSSL_SAVED_LIBS="$LIBS"
91*f5f40dd6SCy SchubertNTPSSL_SAVED_LDFLAGS="$LDFLAGS"
92*f5f40dd6SCy Schubert
93*f5f40dd6SCy SchubertAC_PATH_PROG([PATH_OPENSSL], [openssl])
94*f5f40dd6SCy Schubert
95*f5f40dd6SCy Schubertstr="$with_crypto:${PKG_CONFIG:+notempty}:${with_openssl_libdir-notgiven}:${with_openssl_incdir-notgiven}"
96*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([$str])
97*f5f40dd6SCy SchubertAS_UNSET([str])
98*f5f40dd6SCy Schubert
99*f5f40dd6SCy Schubert# Make sure neither/both --with_openssl-{inc,lib}dir are given
100*f5f40dd6SCy Schubertcase "${with_openssl_libdir-notgiven}:${with_openssl_incdir-notgiven}" in
101*f5f40dd6SCy Schubert notgiven:notgiven) ;;
102*f5f40dd6SCy Schubert *notgiven*)
103*f5f40dd6SCy Schubert    AC_MSG_ERROR([only one of --with-openssl-{inc,lib}dir=... given - provide both or neither])
104*f5f40dd6SCy Schubert    ;;
1052b15cb3dSCy Schubertesac
106f0574f5cSXin LI
107*f5f40dd6SCy Schubert# HMS: Today there are only 2 case options.  We probably want a third
108*f5f40dd6SCy Schubert# *:*:notgiven:notgiven
109*f5f40dd6SCy Schubert# and in that case we would validate the path in PKG_CONFIG_PATH.
110*f5f40dd6SCy Schubert# Unless we can do it with 2 cases, where the 2nd case is *:*:...
111*f5f40dd6SCy Schubert# and we do a reality check on execpath and the headers/libraries.
112*f5f40dd6SCy Schubert#
113*f5f40dd6SCy Schubert##
114*f5f40dd6SCy Schubert# if $with_crypto is not "no":
115*f5f40dd6SCy Schubert#   if --with-openssl-{inc,lib}dir are not given:
116*f5f40dd6SCy Schubert#     we should use pkg-config to find openssl
117*f5f40dd6SCy Schubert#     if we don't have pkg-config, if openssl is in the base OS, use that.
118*f5f40dd6SCy Schubert##
1192b15cb3dSCy Schubertcase "$with_crypto:${PKG_CONFIG:+notempty}:${with_openssl_libdir-notgiven}:${with_openssl_incdir-notgiven}" in
1202b15cb3dSCy Schubert no:*) ;;
1212b15cb3dSCy Schubert *:notempty:notgiven:notgiven)
122*f5f40dd6SCy Schubert    # If PKG_CONFIG is notempty and we haven't been given openssl paths,
123*f5f40dd6SCy Schubert    # then let's make sure that the openssl executable's path corresponds
124*f5f40dd6SCy Schubert    # to the path in openssl.pc, and 'openssl version' matches the Version
125*f5f40dd6SCy Schubert    # in openssl.pc.  If $PKG_CONFIG tells us an INCPATH and/or a LIBPATH,
126*f5f40dd6SCy Schubert    # then should we reality check them?
127*f5f40dd6SCy Schubert    ## INCPATH
128*f5f40dd6SCy Schubert    # harlan@ntp-testbuild.tal1> openssl version
129*f5f40dd6SCy Schubert    # OpenSSL 1.1.1t  7 Feb 2023
130*f5f40dd6SCy Schubert    # harlan@ntp-testbuild.tal1> grep 1.1.1t /ntpbuild/include/openssl/*
131*f5f40dd6SCy Schubert    # /ntpbuild/include/openssl/opensslv.h:# define OPENSSL_VERSION_TEXT    "OpenSSL 1.1.1t  7 Feb 2023"
132*f5f40dd6SCy Schubert    # harlan@ntp-testbuild.tal1>
133*f5f40dd6SCy Schubert    ## LIBPATH
134*f5f40dd6SCy Schubert    # harlan@ntp-testbuild.tal1> strings -a /ntpbuild/lib/libcrypto.* | fgrep 1.1.1t
135*f5f40dd6SCy Schubert    # OpenSSL 1.1.1t  7 Feb 2023
136*f5f40dd6SCy Schubert    # OpenSSL 1.1.1t  7 Feb 2023
137*f5f40dd6SCy Schubert    # OpenSSL 1.1.1t  7 Feb 2023
138*f5f40dd6SCy Schubert    # harlan@ntp-testbuild.tal1> ls /ntpbuild/lib/libcrypto.*
139*f5f40dd6SCy Schubert    # /ntpbuild/lib/libcrypto.a       /ntpbuild/lib/libcrypto.so.1.1*
140*f5f40dd6SCy Schubert    # /ntpbuild/lib/libcrypto.so@
141*f5f40dd6SCy Schubert    # harlan@ntp-testbuild.tal1>
142*f5f40dd6SCy Schubert    ##
143*f5f40dd6SCy Schubert    # Having said this, do we really care if the openssl executable that
144*f5f40dd6SCy Schubert    # we have found is matched with the INCPATH and LIBPATH?
145*f5f40dd6SCy Schubert    # One answer: Probably not, but we should complain on a mismatch as
146*f5f40dd6SCy Schubert    # otherwise runtime differences could easily cause problems/drama.
147*f5f40dd6SCy Schubert
148*f5f40dd6SCy Schubert    ##BO
149*f5f40dd6SCy Schubert    # ntp_cv_build_framework_help=yes
150*f5f40dd6SCy Schubert    save_PKG_CONFIG_PATH=${PKG_CONFIG_PATH}
151*f5f40dd6SCy Schubert    for pkg in `echo $with_crypto | $SED -e 's/,/ /'`; do
152*f5f40dd6SCy Schubert        case "$pkg" in
153*f5f40dd6SCy Schubert	 openssl)
154*f5f40dd6SCy Schubert	    if $PKG_CONFIG --exists $pkg ; then
155*f5f40dd6SCy Schubert		# Found it - yay
156*f5f40dd6SCy Schubert		# Do we want to check we found the right one?
157*f5f40dd6SCy Schubert		# --modver
158*f5f40dd6SCy Schubert		# --variable={libdir,includedir} (varname)
159*f5f40dd6SCy Schubert		overf=`openssl version`
160*f5f40dd6SCy Schubert		overs=`echo $overf | awk '{print $2}'`
161*f5f40dd6SCy Schubert		case "$overs" in
162*f5f40dd6SCy Schubert		 0.*) ;;	# Should we squawk?
163*f5f40dd6SCy Schubert		 1.0.*) ;;	# Should we squawk?
164*f5f40dd6SCy Schubert		 1.1.*) ;;	# Should we squawk?
165*f5f40dd6SCy Schubert		 3.*)
166*f5f40dd6SCy Schubert		    oinc=`openssl --variable=includedir`
167*f5f40dd6SCy Schubert		    olib=`openssl --variable=libdir`
168*f5f40dd6SCy Schubert		    # How should we use these?
169*f5f40dd6SCy Schubert		    ;;
170*f5f40dd6SCy Schubert		 *) ;;	# Should we squawk?
171*f5f40dd6SCy Schubert		esac
172*f5f40dd6SCy Schubert		# /ntpbuild/include/openssl/opensslv.h:# define OPENSSL_VERSION_TEXT    "OpenSSL 1.1.1t  7 Feb 2023"
173*f5f40dd6SCy Schubert		# grep 1.1.1t /ntpbuild/lib/libcrypto.a
174*f5f40dd6SCy Schubert		# strings -a /ntpbuild/lib/libcrypto.a | grep 1.1.1t
175*f5f40dd6SCy Schubert		# OpenSSL 1.1.1t  7 Feb 2023
176*f5f40dd6SCy Schubert		# harlan@ntp-testbuild.tal1>
177*f5f40dd6SCy Schubert		# which should match $overf
178*f5f40dd6SCy Schubert		##
179*f5f40dd6SCy Schubert		# harlan@ntp-testbuild.tal1> echo '"OpenSSL 1.1.1t  7 Feb 2023"' | cut -f 2 -d\"
180*f5f40dd6SCy Schubert		# OpenSSL 1.1.1t  7 Feb 2023
181*f5f40dd6SCy Schubert		# harlan@ntp-testbuild.tal1> grep OPENSSL_VERSION_TEXT /ntpbuild/include/openssl/opensslv.h
182*f5f40dd6SCy Schubert		# # define OPENSSL_VERSION_TEXT    "OpenSSL 1.1.1t  7 Feb 2023"
183*f5f40dd6SCy Schubert		# harlan@ntp-testbuild.tal1>
184*f5f40dd6SCy Schubert		##
185*f5f40dd6SCy Schubert
186*f5f40dd6SCy Schubert	    else
187*f5f40dd6SCy Schubert		# This is a hack, but it's reasonable.
188*f5f40dd6SCy Schubert		pkgpath="`echo $PATH_OPENSSL | sed -e 's:/bin/openssl$::'`/lib/pkgconfig"
189*f5f40dd6SCy Schubert		test -d "$pkgpath" || pkgpath=
190*f5f40dd6SCy Schubert		# echo "pkgpath is <$pkgpath>"
191*f5f40dd6SCy Schubert		# echo "PKG_CONFIG_PATH is <$PKG_CONFIG_PATH>"
192*f5f40dd6SCy Schubert		case "$pkgpath" in
193*f5f40dd6SCy Schubert		 '') ;;	# Nothing to see here...
194*f5f40dd6SCy Schubert		 *) case ":$PKG_CONFIG_PATH:" in
195*f5f40dd6SCy Schubert		     ::)
196*f5f40dd6SCy Schubert			PKG_CONFIG_PATH=$pkgpath
197*f5f40dd6SCy Schubert			export PKG_CONFIG_PATH
198*f5f40dd6SCy Schubert			;;
199*f5f40dd6SCy Schubert		     *:$pkgpath:*)
200*f5f40dd6SCy Schubert			# Already there...
201*f5f40dd6SCy Schubert			;;
202*f5f40dd6SCy Schubert		     *)
203*f5f40dd6SCy Schubert			PKG_CONFIG_PATH="$pkgpath:$PKG_CONFIG_PATH"
204*f5f40dd6SCy Schubert			export PKG_CONFIG_PATH
205*f5f40dd6SCy Schubert			;;
206*f5f40dd6SCy Schubert		    esac
207*f5f40dd6SCy Schubert		    ;;
208*f5f40dd6SCy Schubert		esac
209*f5f40dd6SCy Schubert	    fi
210*f5f40dd6SCy Schubert	    ;;
211*f5f40dd6SCy Schubert        esac
212*f5f40dd6SCy Schubert    done
213*f5f40dd6SCy Schubert    ##EO
214*f5f40dd6SCy Schubert
215*f5f40dd6SCy Schubert    for pkg in `echo $with_crypto | $SED -e 's/,/ /'`; do
2162b15cb3dSCy Schubert	AC_MSG_CHECKING([pkg-config for $pkg])
2172b15cb3dSCy Schubert	if $PKG_CONFIG --exists $pkg ; then
218*f5f40dd6SCy Schubert	    ntp_ssl_cppflags="`$PKG_CONFIG --cflags-only-I $pkg`"
219*f5f40dd6SCy Schubert	    case "$ntp_ssl_cppflags" in
220*f5f40dd6SCy Schubert	     '')
221*f5f40dd6SCy Schubert		ntp_ssl_incdir='not needed'
222*f5f40dd6SCy Schubert		;;
223*f5f40dd6SCy Schubert	     *)
224*f5f40dd6SCy Schubert		ntp_ssl_incdir="`echo $ntp_ssl_cppflags | $SED -e 's/-I//'`"
225*f5f40dd6SCy Schubert	    esac
226*f5f40dd6SCy Schubert	    ntp_ssl_cflags="`$PKG_CONFIG --cflags-only-other $pkg`"
227*f5f40dd6SCy Schubert	    ntp_ssl_libs_L="`$PKG_CONFIG --libs-only-L $pkg`"
228*f5f40dd6SCy Schubert	    case "$ntp_ssl_libs_L" in
229*f5f40dd6SCy Schubert	     '')
230*f5f40dd6SCy Schubert		ntp_ssl_libdir='not needed'
231*f5f40dd6SCy Schubert		;;
232*f5f40dd6SCy Schubert	     *)
233*f5f40dd6SCy Schubert		ntp_ssl_libdir="`echo $ntp_ssl_libs_L | $SED -e 's/-L//'`"
234*f5f40dd6SCy Schubert	    esac
235*f5f40dd6SCy Schubert	    ntp_ssl_libs_l="`$PKG_CONFIG --libs-only-l $pkg`"
236*f5f40dd6SCy Schubert	    ntp_ssl_libs="$ntp_ssl_libs_L $ntp_ssl_libs_l"
237*f5f40dd6SCy Schubert	    ntp_ssl_ldflags="`$PKG_CONFIG --libs-only-other $pkg`"
2382b15cb3dSCy Schubert	    ntp_openssl=yes
2392b15cb3dSCy Schubert	    ntp_openssl_from_pkg_config=yes
24009100258SXin LI	    ntp_openssl_version="`$PKG_CONFIG --modversion $pkg`"
24109100258SXin LI	    case "$ntp_openssl_version" in
24209100258SXin LI	     *.*) ;;
24309100258SXin LI	     *) ntp_openssl_version='(unknown)' ;;
24409100258SXin LI	    esac
24509100258SXin LI	    AC_MSG_RESULT([yes, version $ntp_openssl_version])
2462b15cb3dSCy Schubert
2472b15cb3dSCy Schubert	    break
2482b15cb3dSCy Schubert	fi
2492b15cb3dSCy Schubert	AC_MSG_RESULT([no])
2502b15cb3dSCy Schubert    done
251*f5f40dd6SCy Schubert    AS_UNSET([pkg])
2522b15cb3dSCy Schubertesac
253*f5f40dd6SCy Schubertcase "$with_crypto" in
254*f5f40dd6SCy Schubert no) ;;
2552b15cb3dSCy Schubert *)
2562b15cb3dSCy Schubert    case "$with_openssl_libdir" in
257*f5f40dd6SCy Schubert     '') ;;
2582b15cb3dSCy Schubert     *)
259*f5f40dd6SCy Schubert	ntp_ssl_libdir="$with_openssl_libdir"
260*f5f40dd6SCy Schubert	ntp_ssl_libs_L="-L$with_openssl_libdir"
261*f5f40dd6SCy Schubert	ntp_ssl_libs_l="-lcrypto"
262*f5f40dd6SCy Schubert	ntp_ssl_libs="$ntp_ssl_libs_L $ntp_ssl_libs_l"
2632b15cb3dSCy Schubert    esac
2642b15cb3dSCy Schubert    case "$with_openssl_incdir" in
265*f5f40dd6SCy Schubert     '') ;;
266*f5f40dd6SCy Schubert     *)
267*f5f40dd6SCy Schubert	ntp_ssl_incdir="$with_openssl_incdir"
268*f5f40dd6SCy Schubert	ntp_ssl_cppflags="-I$with_openssl_incdir"
2692b15cb3dSCy Schubert    esac
2702b15cb3dSCy Schubertesac
271*f5f40dd6SCy Schubert
272*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([OpenSSL Phase I checks:])
273*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([CPPFLAGS_NTP: ($CPPFLAGS_NTP)])
274*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([CFLAGS_NTP:   ($CFLAGS_NTP)])
275*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([LDADD_NTP:    ($LDADD_NTP)])
276*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([LDFLAGS_NTP:  ($LDFLAGS_NTP)])
277*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([ntp_openssl_from_pkg_config: $ntp_openssl_from_pkg_config])
278*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([ntp_ssl_incdir:   ($ntp_ssl_incdir)])
279*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([ntp_ssl_libdir:   ($ntp_ssl_libdir)])
280*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([ntp_ssl_cflags:   ($ntp_ssl_cflags)])
281*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([ntp_ssl_cppflags: ($ntp_ssl_cppflags)])
282*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([ntp_ssl_libs_L:   ($ntp_ssl_libs_L)])
283*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([ntp_ssl_libs_l:   ($ntp_ssl_libs_l)])
284*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([ntp_ssl_libs:     ($ntp_ssl_libs)])
285*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([ntp_ssl_ldflags:  ($ntp_ssl_ldflags)])
286*f5f40dd6SCy Schubert
287*f5f40dd6SCy Schubertcase "$with_crypto" in
288*f5f40dd6SCy Schubert no)
2892b15cb3dSCy Schubert    ntp_openssl=no
290*f5f40dd6SCy Schubert    ;;
291*f5f40dd6SCy Schubert *)
292*f5f40dd6SCy Schubert    ntp_ssl_libs_l="${ntp_ssl_libs_l:--lcrypto}"
293*f5f40dd6SCy Schubert    ntp_ssl_libs="$ntp_ssl_libs_L $ntp_ssl_libs_l"
294*f5f40dd6SCy Schubert    case "$ntp_ssl_libdir" in
295*f5f40dd6SCy Schubert     '')
296*f5f40dd6SCy Schubert	dnl ### set ntp_ssl_libdir ###
297*f5f40dd6SCy Schubert
298*f5f40dd6SCy Schubert	dnl unconventional, using AC_CHECK_LIB repeatedly, clear cached result.
299*f5f40dd6SCy Schubert	AS_UNSET([ac_cv_lib_crypto_EVP_MD_CTX_new])
300*f5f40dd6SCy Schubert	AC_MSG_NOTICE([Searching for libcrypto without -L])
301*f5f40dd6SCy Schubert	AC_CHECK_LIB(
302*f5f40dd6SCy Schubert	    [crypto],
303*f5f40dd6SCy Schubert	    [EVP_MD_CTX_new],
304*f5f40dd6SCy Schubert	    [ntp_ssl_libdir='not needed']
305*f5f40dd6SCy Schubert	)
306*f5f40dd6SCy Schubert	dnl unconventional, using AC_CHECK_LIB repeatedly, clear cached result.
307*f5f40dd6SCy Schubert	AS_UNSET([ac_cv_lib_crypto_EVP_MD_CTX_new])
308*f5f40dd6SCy Schubert    esac
309*f5f40dd6SCy Schubert    case "$ntp_ssl_libdir" in
310*f5f40dd6SCy Schubert     '')
311*f5f40dd6SCy Schubert	ntp_ssl_libdir_search="/usr/lib /usr/lib/openssl /usr/sfw/lib"
312*f5f40dd6SCy Schubert	ntp_ssl_libdir_search="$ntp_ssl_libdir_search /usr/local/lib"
313*f5f40dd6SCy Schubert	ntp_ssl_libdir_search="$ntp_ssl_libdir_search /usr/local/ssl/lib"
314*f5f40dd6SCy Schubert	ntp_ssl_libdir_search="$ntp_ssl_libdir_search /opt/local/lib"
315*f5f40dd6SCy Schubert	ntp_ssl_libdir_search="$ntp_ssl_libdir_search /lib /lib64"
316*f5f40dd6SCy Schubert	;;
317*f5f40dd6SCy Schubert     *)
318*f5f40dd6SCy Schubert	ntp_ssl_libdir_search="$ntp_ssl_libdir"
319*f5f40dd6SCy Schubert    esac
320*f5f40dd6SCy Schubert    case $ntp_ssl_libdir_search in
321*f5f40dd6SCy Schubert     'not needed') ;;
322*f5f40dd6SCy Schubert     *)
323*f5f40dd6SCy Schubert	for i in $ntp_ssl_libdir_search not_found
324*f5f40dd6SCy Schubert	do
325*f5f40dd6SCy Schubert	    case "$i" in
326*f5f40dd6SCy Schubert	     not_found) ;;
327*f5f40dd6SCy Schubert	     *)
328*f5f40dd6SCy Schubert		AC_MSG_NOTICE([Searching for libcrypto in $i])
329*f5f40dd6SCy Schubert		LIBS="-L$i $NTPSSL_SAVED_LIBS"
330*f5f40dd6SCy Schubert		AC_CHECK_LIB(
331*f5f40dd6SCy Schubert		    [crypto],
332*f5f40dd6SCy Schubert		    [EVP_MD_CTX_new],
333*f5f40dd6SCy Schubert		    [break]
334*f5f40dd6SCy Schubert		)
335*f5f40dd6SCy Schubert		dnl unconventional, using AC_CHECK_LIB repeatedly, clear cached result.
336*f5f40dd6SCy Schubert		AS_UNSET([ac_cv_lib_crypto_EVP_MD_CTX_new])
337*f5f40dd6SCy Schubert	    esac
338*f5f40dd6SCy Schubert	done
339*f5f40dd6SCy Schubert	ntp_ssl_libdir="$i"
340*f5f40dd6SCy Schubert	ntp_ssl_libs_L="-L$i"
341*f5f40dd6SCy Schubert	ntp_ssl_libs="$ntp_ssl_libs_L $ntp_ssl_libs_l"
342*f5f40dd6SCy Schubert	LIBS="$NTPSSL_SAVED_LIBS"
343*f5f40dd6SCy Schubert	case "$ntp_ssl_libdir" in
344*f5f40dd6SCy Schubert	 not_found)
345*f5f40dd6SCy Schubert	    AC_MSG_ERROR(
346*f5f40dd6SCy Schubert[You may want to use --without-crypto, or add
347*f5f40dd6SCy Schubertopenssl.pc/libcrypto.pc to PKG_CONFIG_PATH, or use the
348*f5f40dd6SCy Schubert--with-openssl-libdir=/some/path option to configure.
349*f5f40dd6SCy Schubertlibcrypto not found in any of the following directories:
350*f5f40dd6SCy Schubert$ntp_ssl_libdir_search]
351*f5f40dd6SCy Schubert	    )
352*f5f40dd6SCy Schubert	esac
353*f5f40dd6SCy Schubert	AC_MSG_NOTICE([libcrypto found in $ntp_ssl_libdir])
354*f5f40dd6SCy Schubert    esac
355*f5f40dd6SCy Schubert
356*f5f40dd6SCy Schubert    case "$ntp_openssl_from_pkg_config:$ntp_ssl_incdir" in
357*f5f40dd6SCy Schubert     'yes:not needed' | no:)
358*f5f40dd6SCy Schubert	AC_MSG_NOTICE([Searching for openssl/evp.h without -I])
359*f5f40dd6SCy Schubert	dnl force uncached AC_CHECK_HEADER
360*f5f40dd6SCy Schubert	AS_UNSET([ac_cv_header_openssl_evp_h])
361*f5f40dd6SCy Schubert	AC_CHECK_HEADER(
362*f5f40dd6SCy Schubert	    [openssl/evp.h],
363*f5f40dd6SCy Schubert	    [ntp_ssl_incdir='not needed']
364*f5f40dd6SCy Schubert	    )
365*f5f40dd6SCy Schubert    esac
366*f5f40dd6SCy Schubert    case "$ntp_ssl_incdir" in
367*f5f40dd6SCy Schubert     'not needed')
368*f5f40dd6SCy Schubert	ntp_ssl_incdir_search="$ntp_ssl_incdir"
369*f5f40dd6SCy Schubert	;;
370*f5f40dd6SCy Schubert     *)
371*f5f40dd6SCy Schubert	AC_MSG_NOTICE([Searching for openssl include directory])
372*f5f40dd6SCy Schubert	case "$with_openssl_incdir" in
373*f5f40dd6SCy Schubert	 '')
374*f5f40dd6SCy Schubert	    case "$ntp_ssl_incdir" in
375*f5f40dd6SCy Schubert	     '')
376*f5f40dd6SCy Schubert		ntp_ssl_incdir_search="/usr/include /usr/sfw/include"
377*f5f40dd6SCy Schubert		ntp_ssl_incdir_search="$ntp_ssl_incdir_search /usr/local/include"
378*f5f40dd6SCy Schubert		ntp_ssl_incdir_search="$ntp_ssl_incdir_search /opt/local/include"
379*f5f40dd6SCy Schubert		ntp_ssl_incdir_search="$ntp_ssl_incdir_search /usr/local/ssl/include"
380*f5f40dd6SCy Schubert		;;
381*f5f40dd6SCy Schubert	     *)
382*f5f40dd6SCy Schubert	    esac
383*f5f40dd6SCy Schubert	    ;;
384*f5f40dd6SCy Schubert	 *)
385*f5f40dd6SCy Schubert	    ntp_ssl_incdir_search="$with_openssl_incdir"
386*f5f40dd6SCy Schubert	esac
387*f5f40dd6SCy Schubert	case $ntp_ssl_incdir_search in
388*f5f40dd6SCy Schubert	 'not needed') ;;
389*f5f40dd6SCy Schubert	 *)
390*f5f40dd6SCy Schubert	    for i in $ntp_ssl_incdir_search
391*f5f40dd6SCy Schubert	    do
392*f5f40dd6SCy Schubert		AC_MSG_NOTICE([Searching for openssl/evp.h in $i])
393*f5f40dd6SCy Schubert		CPPFLAGS="$NTPSSL_SAVED_CPPFLAGS -I$i"
394*f5f40dd6SCy Schubert		dnl force uncached AC_CHECK_HEADER
395*f5f40dd6SCy Schubert		AS_UNSET([ac_cv_header_openssl_evp_h])
396*f5f40dd6SCy Schubert		AC_CHECK_HEADER(
397*f5f40dd6SCy Schubert		    [openssl/evp.h],
398*f5f40dd6SCy Schubert		    [ntp_ssl_incdir="$i" ; break]
399*f5f40dd6SCy Schubert		    )
400*f5f40dd6SCy Schubert	    done
401*f5f40dd6SCy Schubert	    AS_UNSET([ac_cv_header_openssl_evp_h])
402*f5f40dd6SCy Schubert	    AS_UNSET([i])
403*f5f40dd6SCy Schubert	    CPPFLAGS="$NTPSSL_SAVED_CPPFLAGS"
404*f5f40dd6SCy Schubert	    case "$ntp_ssl_incdir" in
405*f5f40dd6SCy Schubert	     '')
406*f5f40dd6SCy Schubert		AC_MSG_ERROR(
407*f5f40dd6SCy Schubert[You may want to use --without-crypto, or add
408*f5f40dd6SCy Schubertopenssl.pc/libcrypto.pc to PKG_CONFIG_PATH, or use the
409*f5f40dd6SCy Schubert-with-openssl-incdir=/some/path option to configure.
410*f5f40dd6SCy SchubertNo usable openssl/evp.h found in any of the following direcotries:
411*f5f40dd6SCy Schubert$ntp_ssl_incdir_search]
412*f5f40dd6SCy Schubert		)
413*f5f40dd6SCy Schubert	    esac
414*f5f40dd6SCy Schubert	    ntp_ssl_cppflags="-I$ntp_ssl_incdir"
415*f5f40dd6SCy Schubert	    AC_MSG_NOTICE([Found evp.h in $ntp_ssl_incdir/openssl])
416*f5f40dd6SCy Schubert	esac
417*f5f40dd6SCy Schubert    esac
4182b15cb3dSCy Schubert    ntp_openssl=yes
419*f5f40dd6SCy Schubertesac	dnl building with SSL ($with_crypto not "no")
420*f5f40dd6SCy Schubert
421*f5f40dd6SCy Schubertcase "$ntp_openssl:$ntp_ssl_libdir" in
422*f5f40dd6SCy Schubert 'yes:not needed')
423*f5f40dd6SCy Schubert    ;;
424*f5f40dd6SCy Schubert yes:*)
425*f5f40dd6SCy Schubert    CFLAGS="$NTPSSL_SAVED_CFLAGS $ntp_ssl_cflags"
426*f5f40dd6SCy Schubert    CPPFLAGS="$NTPSSL_SAVED_CPPFLAGS $ntp_ssl_cppflags"
427*f5f40dd6SCy Schubert    LIBS="$ntp_ssl_libs $NTPSSL_SAVED_LIBS"
428*f5f40dd6SCy Schubert    LDFLAGS="$ntp_ssl_ldflags $NTPSSL_SAVED_LDFLAGS"
429*f5f40dd6SCy Schubert    dnl ### test if runpath is needed for crypto ###
430*f5f40dd6SCy Schubert    AC_CACHE_CHECK(
431*f5f40dd6SCy Schubert	[if crypto works without runpath],
432*f5f40dd6SCy Schubert	[ntp_cv_ssl_without_runpath],
433*f5f40dd6SCy Schubert	[AC_RUN_IFELSE(
434*f5f40dd6SCy Schubert	    [AC_LANG_PROGRAM(
435*f5f40dd6SCy Schubert		[[
436*f5f40dd6SCy Schubert		    #include "openssl/evp.h"
437*f5f40dd6SCy Schubert		]],
438*f5f40dd6SCy Schubert		[[
439*f5f40dd6SCy Schubert		    if (!EVP_MD_CTX_new()) {
440*f5f40dd6SCy Schubert			return 1;
441*f5f40dd6SCy Schubert		    }
442*f5f40dd6SCy Schubert		]]
443*f5f40dd6SCy Schubert	    )],
444*f5f40dd6SCy Schubert	    [ntp_cv_ssl_without_runpath=yes],
445*f5f40dd6SCy Schubert	    [ntp_cv_ssl_without_runpath=no],
446*f5f40dd6SCy Schubert	    [ntp_cv_ssl_without_runpath=yes]		dnl cross-compile
447*f5f40dd6SCy Schubert	)]
448*f5f40dd6SCy Schubert    )
449*f5f40dd6SCy Schubert    case "$ntp_cv_ssl_without_runpath" in
450*f5f40dd6SCy Schubert     no)
451*f5f40dd6SCy Schubert	AC_CACHE_CHECK(
452*f5f40dd6SCy Schubert	    [if crypto needs -Wl,-rpath,$ntp_ssl_libdir],
453*f5f40dd6SCy Schubert	    [ntp_cv_ssl_needs_dashWl_rpath],
454*f5f40dd6SCy Schubert	    [
455*f5f40dd6SCy Schubert		LDFLAGS="$ntp_ssl_ldflags -Wl,-rpath,$ntp_ssl_libdir $NTPSSL_SAVED_LDFLAGS"
456*f5f40dd6SCy Schubert		AC_RUN_IFELSE(
457*f5f40dd6SCy Schubert		    [AC_LANG_PROGRAM(
458*f5f40dd6SCy Schubert			[[
459*f5f40dd6SCy Schubert			    #include "openssl/evp.h"
460*f5f40dd6SCy Schubert			]],
461*f5f40dd6SCy Schubert			[[
462*f5f40dd6SCy Schubert			    if (!EVP_MD_CTX_new()) {
463*f5f40dd6SCy Schubert				return 1;
464*f5f40dd6SCy Schubert			    }
465*f5f40dd6SCy Schubert			]]
466*f5f40dd6SCy Schubert		    )],
467*f5f40dd6SCy Schubert		    [ntp_cv_ssl_needs_dashWl_rpath=yes],
468*f5f40dd6SCy Schubert		    [ntp_cv_ssl_needs_dashWl_rpath=no]
469*f5f40dd6SCy Schubert		)
470*f5f40dd6SCy Schubert	    ]
471*f5f40dd6SCy Schubert	)
472*f5f40dd6SCy Schubert	case "$ntp_cv_ssl_needs_dashWl_rpath" in
4732b15cb3dSCy Schubert	 yes)
474*f5f40dd6SCy Schubert	    ntp_ssl_ldflags="$ntp_ssl_ldflags -Wl,-rpath,$ntp_ssl_libdir"
4752b15cb3dSCy Schubert	    ;;
476*f5f40dd6SCy Schubert	 no)
477*f5f40dd6SCy Schubert	    AC_CACHE_CHECK(
478*f5f40dd6SCy Schubert		[if crypto needs -R$ntp_ssl_libdir],
479*f5f40dd6SCy Schubert		[ntp_cv_ssl_needs_dashR],
480*f5f40dd6SCy Schubert		[
481*f5f40dd6SCy Schubert		    LDFLAGS="$NTPSSL_SAVED_LDFLAGS $ntp_ssl_ldflags -R$ntp_ssl_libdir"
482*f5f40dd6SCy Schubert		    AC_RUN_IFELSE(
483*f5f40dd6SCy Schubert			[AC_LANG_PROGRAM(
484*f5f40dd6SCy Schubert			    [[
485*f5f40dd6SCy Schubert				#include "openssl/evp.h"
486*f5f40dd6SCy Schubert			    ]],
487*f5f40dd6SCy Schubert			    [[
488*f5f40dd6SCy Schubert				if (!EVP_MD_CTX_new()) {
489*f5f40dd6SCy Schubert				    return 1;
490*f5f40dd6SCy Schubert				}
491*f5f40dd6SCy Schubert			    ]]
492*f5f40dd6SCy Schubert			)],
493*f5f40dd6SCy Schubert			[ntp_cv_ssl_needs_dashR=yes],
494*f5f40dd6SCy Schubert			[ntp_cv_ssl_needs_dashR=no]
495*f5f40dd6SCy Schubert		    )
496*f5f40dd6SCy Schubert		]
497*f5f40dd6SCy Schubert	    )
498*f5f40dd6SCy Schubert	    case "$ntp_cv_ssl_needs_dashR" in
4992b15cb3dSCy Schubert	     yes)
500*f5f40dd6SCy Schubert		ntp_ssl_ldflags="$ntp_ssl_ldflags -R$ntp_ssl_libdir"
5012b15cb3dSCy Schubert	    esac
502*f5f40dd6SCy Schubert	    case "$build:$ntp_cv_ssl_needs_dashR" in
503*f5f40dd6SCy Schubert	     $host:no)
504*f5f40dd6SCy Schubert		AC_MSG_FAILURE(
505*f5f40dd6SCy Schubert[Unable to run program using crypto, check openssl.pc
506*f5f40dd6SCy Schubertor libcrypto.pc are in PKG_CONFIG_PATH, or provide the
507*f5f40dd6SCy Schubert --with-openssl-libdir=/some/path option to configure.]
508*f5f40dd6SCy Schubert		)
5092b15cb3dSCy Schubert	    esac
510*f5f40dd6SCy Schubert	esac
511*f5f40dd6SCy Schubert    esac
512*f5f40dd6SCy Schubertesac	dnl ntp_openssl was yes
5132b15cb3dSCy Schubert
514*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([OpenSSL Phase II checks:])
515*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([ntp_ssl_incdir:   ($ntp_ssl_incdir)])
516*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([ntp_ssl_libdir:   ($ntp_ssl_libdir)])
517*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([ntp_ssl_cflags:   ($ntp_ssl_cflags)])
518*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([ntp_ssl_cppflags: ($ntp_ssl_cppflags)])
519*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([ntp_ssl_libs_L:   ($ntp_ssl_libs_L)])
520*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([ntp_ssl_libs_l:   ($ntp_ssl_libs_l)])
521*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([ntp_ssl_libs:     ($ntp_ssl_libs)])
522*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([ntp_ssl_ldflags:  ($ntp_ssl_ldflags)])
5232b15cb3dSCy Schubert
524*f5f40dd6SCy Schubertdnl check for linking with -lcrypto failure, and try -lcrypto -lz.
525*f5f40dd6SCy Schubertdnl Helps m68k-atari-mint
526*f5f40dd6SCy Schubertdnl
527*f5f40dd6SCy Schubertdnl Needs work with the changes to run-test whether runpath is needed.
528*f5f40dd6SCy Schubertdnl Probably needs to be moved ahead of runpath testing.
529*f5f40dd6SCy Schubertdnl hart@ is reaching out to MiNT users to try to find a tester.
530*f5f40dd6SCy Schubertdnl Meanwhile can be forced by passing both ntp_cv_bare_lcrypto=no
531*f5f40dd6SCy Schubertdnl and ntp_cv_lcrypto_lz=yes on the configure command line.
532*f5f40dd6SCy Schubertdnl
5332b15cb3dSCy Schubertcase "$ntp_openssl:$ntp_openssl_from_pkg_config" in
5342b15cb3dSCy Schubert yes:no)
535*f5f40dd6SCy Schubert    CFLAGS="$NTPSSL_SAVED_CFLAGS $ntp_ssl_cflags"
536*f5f40dd6SCy Schubert    CPPFLAGS="$NTPSSL_SAVED_CPPFLAGS $ntp_ssl_cppflags"
537*f5f40dd6SCy Schubert    LIBS="$ntp_ssl_libs $NTPSSL_SAVED_LIBS"
538*f5f40dd6SCy Schubert    LDFLAGS="$ntp_ssl_ldflags $NTPSSL_SAVED_LDFLAGS"
5392b15cb3dSCy Schubert    AC_CACHE_CHECK(
540*f5f40dd6SCy Schubert	[if linking with $ntp_ssl_libs_l alone works],
5412b15cb3dSCy Schubert	[ntp_cv_bare_lcrypto],
5422b15cb3dSCy Schubert	[AC_LINK_IFELSE(
5432b15cb3dSCy Schubert	    [AC_LANG_PROGRAM(
5442b15cb3dSCy Schubert		[[
5452b15cb3dSCy Schubert		    #include "openssl/evp.h"
5462b15cb3dSCy Schubert		]],
5472b15cb3dSCy Schubert		[[
548*f5f40dd6SCy Schubert		    EVP_MD_CTX_new();
5492b15cb3dSCy Schubert		]]
5502b15cb3dSCy Schubert	    )],
5512b15cb3dSCy Schubert	    [ntp_cv_bare_lcrypto=yes],
5522b15cb3dSCy Schubert	    [ntp_cv_bare_lcrypto=no]
5532b15cb3dSCy Schubert	)]
5542b15cb3dSCy Schubert    )
5552b15cb3dSCy Schubert    case "$ntp_cv_bare_lcrypto" in
5562b15cb3dSCy Schubert     no)
557*f5f40dd6SCy Schubert	LIBS="-$ntp_ssl_libs -lz $NTPSSL_SAVED_LIBS"
5582b15cb3dSCy Schubert	AC_CACHE_CHECK(
559*f5f40dd6SCy Schubert	    [if linking with $ntp_ssl_libs_l -lz works],
5602b15cb3dSCy Schubert	    [ntp_cv_lcrypto_lz],
5612b15cb3dSCy Schubert	    [AC_LINK_IFELSE(
5622b15cb3dSCy Schubert		[AC_LANG_PROGRAM(
5632b15cb3dSCy Schubert		    [[
5642b15cb3dSCy Schubert			#include "openssl/evp.h"
5652b15cb3dSCy Schubert		    ]],
5662b15cb3dSCy Schubert		    [[
567*f5f40dd6SCy Schubert			EVP_MD_CTX_new();
5682b15cb3dSCy Schubert		    ]]
5692b15cb3dSCy Schubert		)],
5702b15cb3dSCy Schubert		[ntp_cv_lcrypto_lz=yes],
5712b15cb3dSCy Schubert		[ntp_cv_lcrypto_lz=no]
5722b15cb3dSCy Schubert	    )]
5732b15cb3dSCy Schubert	)
5742b15cb3dSCy Schubert	case "$ntp_cv_lcrypto_lz" in
5752b15cb3dSCy Schubert	 yes)
576*f5f40dd6SCy Schubert	     ntp_ssl_libs_l="$ntp_ssl_libs_l -lz"
577*f5f40dd6SCy Schubert	     ntp_ssl_libs="$ntp_ssl_libs_L $ntp_ssl_libs_l"
5782b15cb3dSCy Schubert	esac
579*f5f40dd6SCy Schubert    esac	dnl linking with -lcrypto alone fails
580*f5f40dd6SCy Schubertesac		dnl using SSL and not from pkg-config
5812b15cb3dSCy Schubert
582*f5f40dd6SCy Schubertdnl
583*f5f40dd6SCy Schubertdnl Older OpenSSL headers have a number of callback prototypes inside
584*f5f40dd6SCy Schubertdnl other function prototypes which trigger copious warnings with gcc's
585*f5f40dd6SCy Schubertdnl -Wstrict-prototypes, which is included in -Wall.
586*f5f40dd6SCy Schubertdnl
587*f5f40dd6SCy Schubertdnl An example:
588*f5f40dd6SCy Schubertdnl
589*f5f40dd6SCy Schubertdnl int i2d_RSA_NET(const RSA *a, unsigned char **pp,
590*f5f40dd6SCy Schubertdnl		  int (*cb)(), int sgckey);
591*f5f40dd6SCy Schubertdnl		  ^^^^^^^^^^^
592*f5f40dd6SCy Schubertdnl
5932b15cb3dSCy Schubertcase "$ntp_openssl:$GCC" in
5942b15cb3dSCy Schubert yes:yes)
595*f5f40dd6SCy Schubert    CFLAGS="$NTP_SAVED_CFLAGS $ntp_ssl_cflags -Werror"
596*f5f40dd6SCy Schubert    CPPFLAGS="$NTPSSL_SAVED_CPPFLAGS $ntp_ssl_cppflags"
597*f5f40dd6SCy Schubert    LIBS="$ntp_ssl_libs $NTPSSL_SAVED_LIBS"
598*f5f40dd6SCy Schubert    LDFLAGS="$ntp_ssl_ldflags $NTPSSL_SAVED_LDFLAGS"
599*f5f40dd6SCy Schubert    AC_CACHE_CHECK(
600*f5f40dd6SCy Schubert	[If $CC supports -Werror],
601*f5f40dd6SCy Schubert	[ntp_cv_gcc_supports_Werror],
602*f5f40dd6SCy Schubert	[AC_COMPILE_IFELSE(
603*f5f40dd6SCy Schubert	    [AC_LANG_PROGRAM([], [])],
604*f5f40dd6SCy Schubert	    [ntp_cv_gcc_supports_Werror=yes],
605*f5f40dd6SCy Schubert	    [ntp_cv_gcc_supports_Werror=no]
606*f5f40dd6SCy Schubert	)]
6072b15cb3dSCy Schubert    )
608*f5f40dd6SCy Schubert    case "ntp_cv_gcc_supports_Werror" in
6092b15cb3dSCy Schubert     no)
610*f5f40dd6SCy Schubert	ntp_use_Wstrict_prototypes=yes
6112b15cb3dSCy Schubert	;;
6122b15cb3dSCy Schubert     yes)
6132b15cb3dSCy Schubert	CFLAGS="$CFLAGS -Wstrict-prototypes"
614*f5f40dd6SCy Schubert	AC_CACHE_CHECK(
615*f5f40dd6SCy Schubert	    [if OpenSSL triggers warnings],
616*f5f40dd6SCy Schubert	    [ntp_cv_ssl_triggers_warnings],
617*f5f40dd6SCy Schubert	    [AC_COMPILE_IFELSE(
6182b15cb3dSCy Schubert		[AC_LANG_PROGRAM(
6192b15cb3dSCy Schubert		    [[
6202b15cb3dSCy Schubert			#include "openssl/asn1_mac.h"
6212b15cb3dSCy Schubert			#include "openssl/bn.h"
6222b15cb3dSCy Schubert			#include "openssl/err.h"
6232b15cb3dSCy Schubert			#include "openssl/evp.h"
6242b15cb3dSCy Schubert			#include "openssl/pem.h"
6252b15cb3dSCy Schubert			#include "openssl/rand.h"
6262b15cb3dSCy Schubert			#include "openssl/x509v3.h"
6272b15cb3dSCy Schubert		    ]],
6282b15cb3dSCy Schubert		    [[
6292b15cb3dSCy Schubert			/* empty body */
6302b15cb3dSCy Schubert		    ]]
6312b15cb3dSCy Schubert		)],
632*f5f40dd6SCy Schubert		[ntp_cv_ssl_triggers_warnings=no],
633*f5f40dd6SCy Schubert		[ntp_cv_ssl_triggers_warnings=yes]
634*f5f40dd6SCy Schubert	    )]
6352b15cb3dSCy Schubert	)
636*f5f40dd6SCy Schubert	case "$ntp_cv_ssl_triggers_warnings" in
6372b15cb3dSCy Schubert	 yes)
638*f5f40dd6SCy Schubert	    ntp_use_Wstrict_prototypes=no
6392b15cb3dSCy Schubert	    ;;
6402b15cb3dSCy Schubert	 *)
641*f5f40dd6SCy Schubert	    ntp_use_Wstrict_prototypes=yes
642*f5f40dd6SCy Schubert	esac
643*f5f40dd6SCy Schubert    esac
644*f5f40dd6SCy Schubert    case "$ntp_use_Wstrict_prototypes" in
645*f5f40dd6SCy Schubert     no)
646*f5f40dd6SCy Schubert	ntp_ssl_cflags="$ntp_ssl_cflags -Wno-strict-prototypes"
647*f5f40dd6SCy Schubert	;;
648*f5f40dd6SCy Schubert     *)
649*f5f40dd6SCy Schubert	ntp_ssl_cflags="$ntp_ssl_cflags -Wstrict-prototypes"
6502b15cb3dSCy Schubert    esac
6512b15cb3dSCy Schubert    ;;
6522b15cb3dSCy Schubert no:yes)
653*f5f40dd6SCy Schubert    dnl gcc without OpenSSL
654*f5f40dd6SCy Schubert    ntp_ssl_cflags="$ntp_ssl_cflags -Wstrict-prototypes"
655*f5f40dd6SCy Schubertesac	dnl checking for gcc problems with -Werror and -Wstrict-prototypes
6562b15cb3dSCy Schubert
657*f5f40dd6SCy SchubertAC_MSG_CHECKING([if we will link to ssl library])
658*f5f40dd6SCy SchubertAC_MSG_RESULT([$ntp_openssl])
659276da39aSCy Schubert
660276da39aSCy Schubertcase "$ntp_openssl" in
661276da39aSCy Schubert yes)
662*f5f40dd6SCy Schubert    VER_SUFFIX=o
663*f5f40dd6SCy Schubert    AC_CHECK_HEADERS(
664*f5f40dd6SCy Schubert	[openssl/cmac.h],
665*f5f40dd6SCy Schubert	[ntp_enable_cmac=yes],
666*f5f40dd6SCy Schubert	[ntp_enable_cmac=no]
667*f5f40dd6SCy Schubert    )
668*f5f40dd6SCy Schubert    case "$ntp_enable_cmac" in
669*f5f40dd6SCy Schubert     yes)
670*f5f40dd6SCy Schubert    	AC_DEFINE([ENABLE_CMAC], [1], [Enable CMAC support?])
671*f5f40dd6SCy Schubert    esac
672*f5f40dd6SCy Schubert    AC_DEFINE([OPENSSL], [], [Use OpenSSL?])
673*f5f40dd6SCy Schubert    dnl OpenSSL 3 deprecates a bunch of functions used by Autokey.
674*f5f40dd6SCy Schubert    dnl Adapting our code to the bold new way is not a priority
675*f5f40dd6SCy Schubert    dnl for us because we do not want to require OpenSSL 3 yet.
676*f5f40dd6SCy Schubert    dnl The deprecation warnings clutter up the build output
677*f5f40dd6SCy Schubert    dnl encouraging the habit of ignoring warnings.
678*f5f40dd6SCy Schubert    dnl So, tell it to the hand, OpenSSL deprecation warnings...
679*f5f40dd6SCy Schubert    AC_DEFINE([OPENSSL_SUPPRESS_DEPRECATED], [1],
680*f5f40dd6SCy Schubert	      [Suppress OpenSSL 3 deprecation warnings])
681*f5f40dd6SCy Schubert    dnl We don't want -Werror for the EVP_MD_do_all_sorted check
682*f5f40dd6SCy Schubert    CFLAGS="$NTPSSL_SAVED_CFLAGS"
683276da39aSCy Schubert    AC_CHECK_FUNCS([EVP_MD_do_all_sorted])
684*f5f40dd6SCy Schubert    CPPFLAGS_NTP="$CPPFLAGS_NTP $ntp_ssl_cppflags"
685*f5f40dd6SCy Schubert    CFLAGS_NTP="$CFLAGS_NTP $ntp_ssl_cflags"
686*f5f40dd6SCy Schubert    LDADD_NTP="$ntp_ssl_libs $LDADD_NTP"
687*f5f40dd6SCy Schubert    LDFLAGS_NTP="$ntp_ssl_ldflags $LDFLAGS_NTP"
688276da39aSCy Schubertesac
689276da39aSCy Schubert
690*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([OpenSSL final checks:])
691*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([ntp_openssl:  $ntp_openssl])
692*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([CPPFLAGS_NTP: ($CPPFLAGS_NTP)])
693*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([CFLAGS_NTP:   ($CFLAGS_NTP)])
694*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([LDADD_NTP:    ($LDADD_NTP)])
695*f5f40dd6SCy SchubertNTP_OPENSSL_VERBOSE_MSG([LDFLAGS_NTP:  ($LDFLAGS_NTP)])
696f0574f5cSXin LI
697*f5f40dd6SCy SchubertCFLAGS="$NTPSSL_SAVED_CFLAGS"
698*f5f40dd6SCy SchubertCPPFLAGS="$NTPSSL_SAVED_CPPFLAGS"
699*f5f40dd6SCy SchubertLIBS="$NTPSSL_SAVED_LIBS"
700*f5f40dd6SCy SchubertLDFLAGS="$NTPSSL_SAVED_LDFLAGS"
701*f5f40dd6SCy Schubert
702*f5f40dd6SCy SchubertAS_UNSET([NTPSSL_SAVED_CFLAGS])
703*f5f40dd6SCy SchubertAS_UNSET([NTPSSL_SAVED_CPPFLAGS])
704*f5f40dd6SCy SchubertAS_UNSET([NTPSSL_SAVED_LIBS])
705*f5f40dd6SCy SchubertAS_UNSET([NTPSSL_SAVED_LDFLAGS])
706*f5f40dd6SCy SchubertAS_UNSET([ntp_enable_cmac])
707*f5f40dd6SCy SchubertAS_UNSET([ntp_use_Wstrict_prototypes])
7082b15cb3dSCy SchubertAS_UNSET([ntp_openssl_from_pkg_config])
709*f5f40dd6SCy SchubertAS_UNSET([ntp_openssl_version])
710*f5f40dd6SCy SchubertAS_UNSET([ntp_ssl_cflags])
711*f5f40dd6SCy SchubertAS_UNSET([ntp_ssl_cppflags])
712*f5f40dd6SCy SchubertAS_UNSET([ntp_ssl_libdir_search])
713*f5f40dd6SCy SchubertAS_UNSET([ntp_ssl_incdir_search])
714*f5f40dd6SCy SchubertAS_UNSET([ntp_ssl_libdir])
715*f5f40dd6SCy SchubertAS_UNSET([ntp_ssl_incdir])
716*f5f40dd6SCy SchubertAS_UNSET([ntp_ssl_libs_l])
717*f5f40dd6SCy SchubertAS_UNSET([ntp_ssl_libs_L])
718*f5f40dd6SCy SchubertAS_UNSET([ntp_ssl_ldflags])
719*f5f40dd6SCy Schubert
7202b15cb3dSCy Schubert])
721*f5f40dd6SCy Schubertdnl end of AC_DEFUN([NTP_OPENSSL])
722*f5f40dd6SCy Schubertdnl
723*f5f40dd6SCy SchubertAC_DEFUN(
724*f5f40dd6SCy Schubert    [NTP_OPENSSL_VERBOSE_MSG],
725*f5f40dd6SCy Schubert    [dnl
726*f5f40dd6SCy Schubert	case "$enable_verbose_ssl" in
727*f5f40dd6SCy Schubert	 yes) AC_MSG_NOTICE([$1])
728*f5f40dd6SCy Schubert	esac
729*f5f40dd6SCy Schubert    ]
730*f5f40dd6SCy Schubert)
731*f5f40dd6SCy Schubertdnl
7322b15cb3dSCy Schubertdnl ======================================================================
733