1dnl Process this file with autoconf to produce a configure script. -*-m4-*-
2dnl
3dnl %CopyrightBegin%
4dnl
5dnl Copyright Ericsson AB 2018-2020. All Rights Reserved.
6dnl
7dnl Licensed under the Apache License, Version 2.0 (the "License");
8dnl you may not use this file except in compliance with the License.
9dnl You may obtain a copy of the License at
10dnl
11dnl     http://www.apache.org/licenses/LICENSE-2.0
12dnl
13dnl Unless required by applicable law or agreed to in writing, software
14dnl distributed under the License is distributed on an "AS IS" BASIS,
15dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16dnl See the License for the specific language governing permissions and
17dnl limitations under the License.
18dnl
19dnl %CopyrightEnd%
20dnl
21
22dnl define([AC_CACHE_LOAD], )dnl
23dnl define([AC_CACHE_SAVE], )dnl
24
25
26AC_INIT(vsn.mk)
27
28AC_CONFIG_AUX_DIRS(${ERL_TOP}/erts/autoconf)
29
30if test "X$host" != "Xfree_source" -a "X$host" != "Xwin32"; then
31    AC_CANONICAL_HOST
32else
33    host_os=win32
34fi
35
36LM_PRECIOUS_VARS
37
38if test "$cross_compiling" = "yes"; then
39    CROSS_COMPILING=yes
40else
41    CROSS_COMPILING=no
42fi
43AC_SUBST(CROSS_COMPILING)
44
45ERL_XCOMP_SYSROOT_INIT
46
47AC_PROG_CC
48LM_WINDOWS_ENVIRONMENT
49
50ERL_DED
51
52dnl
53dnl SSL, SSH and CRYPTO need the OpenSSL libraries
54dnl
55dnl Check flags --with-ssl, --without-ssl --with-ssl=PATH.
56dnl If no option is given or --with-ssl is set without a path then we
57dnl search for OpenSSL libraries and header files in the standard locations.
58dnl If set to --without-ssl we disable the use of SSL, SSH and CRYPTO.
59dnl If set to --with-ssl=PATH we use that path as the prefix, i.e. we
60dnl use "PATH/include" and "PATH/lib".
61
62AC_CHECK_SIZEOF(void *)
63
64std_ssl_locations="/usr/local /usr/sfw /usr /opt/local /usr/pkg /usr/local/openssl /usr/lib/openssl /usr/openssl /usr/local/ssl /usr/lib/ssl /usr/ssl /"
65
66AC_ARG_WITH(ssl-zlib,
67AS_HELP_STRING([--with-ssl-zlib=PATH],
68               [specify location of ZLib to be used by OpenSSL])
69AS_HELP_STRING([--with-ssl-zlib],
70               [link SSL with  Zlib (default if found)])
71AS_HELP_STRING([--without-ssl-zlib],
72               [don't link SSL with ZLib]))
73
74if  test "x$with_ssl_zlib" = "xno"; then
75	SSL_LINK_WITH_ZLIB=no
76	STATIC_ZLIB_LIBS=
77elif test "x$with_ssl_zlib" = "xyes" || test "x$with_ssl_zlib" = "x"; then
78	if test $erl_xcomp_without_sysroot = yes; then
79		AC_MSG_WARN([Cannot search for zlib; missing cross system root (erl_xcomp_sysroot).])
80		SSL_LINK_WITH_ZLIB=no
81		STATIC_ZLIB_LIBS=
82	elif  test "$host_os" = "win32"; then
83		SSL_LINK_WITH_ZLIB=no
84		STATIC_ZLIB_LIBS=
85	else
86		SSL_LINK_WITH_ZLIB=no
87		STATIC_ZLIB_LIBS=
88		AC_MSG_CHECKING(for static ZLib to be used by SSL in standard locations)
89		for rdir in $std_ssl_locations; do
90			dir="$erl_xcomp_sysroot$rdir"
91			if test "x$ac_cv_sizeof_void_p" = "x8"; then
92				if test -f "$dir/lib64/libz.a"; then
93					SSL_LINK_WITH_ZLIB=yes
94					STATIC_ZLIB_LIBS="$dir/lib64/libz.a"
95					break
96				elif test -f "$dir/lib/64/libz.a"; then
97					SSL_LINK_WITH_ZLIB=yes
98					STATIC_ZLIB_LIBS="$dir/lib/64/libz.a"
99					break
100				fi
101			fi
102			if test -f "$dir/lib/libz.a"; then
103					SSL_LINK_WITH_ZLIB=yes
104				STATIC_ZLIB_LIBS="$dir/lib/libz.a"
105				break
106			fi
107		done
108		if test "x$SSL_LINK_WITH_ZLIB" = "xno"; then
109		       	AC_MSG_RESULT([no])
110		else
111			AC_MSG_RESULT([$STATIC_ZLIB_LIBS])
112		fi
113	fi
114else
115	SSL_LINK_WITH_ZLIB=no
116	STATIC_ZLIB_LIBS=
117	if test -f "$with_ssl_zlib/libz.a"; then
118		SSL_LINK_WITH_ZLIB=yes
119		STATIC_ZLIB_LIBS=$with_ssl_zlib/libz.a
120	elif test -f "$with_ssl_zlib/lib/libz.a"; then
121		SSL_LINK_WITH_ZLIB=yes
122		STATIC_ZLIB_LIBS=$with_ssl_zlib/lib/libz.a
123	fi
124	if test "x$ac_cv_sizeof_void_p" = "x8"; then
125		if test -f "$with_ssl_zlib/lib64/libz.a"; then
126			SSL_LINK_WITH_ZLIB=yes
127			STATIC_ZLIB_LIBS=$with_ssl_zlib/lib64/libz.a
128		elif test -f "$with_ssl_zlib/lib/64/libz.a"; then
129			SSL_LINK_WITH_ZLIB=yes
130			STATIC_ZLIB_LIBS=$with_ssl_zlib/lib/64/libz.a
131		fi
132	fi
133	if test "x$SSL_LINK_WITH_ZLIB" = "xno"; then
134	       	AC_MSG_ERROR(Invalid path to option --with-ssl-zlib=PATH)
135	fi
136fi
137
138
139AC_ARG_WITH(ssl,
140AS_HELP_STRING([--with-ssl=PATH], [specify location of OpenSSL include and lib])
141AS_HELP_STRING([--with-ssl], [use SSL (default)])
142AS_HELP_STRING([--without-ssl], [don't use SSL]))
143
144AC_ARG_WITH(ssl-incl,
145AS_HELP_STRING([--with-ssl-incl=PATH], [location of OpenSSL include dir, if different than specified by --with-ssl=PATH]),
146[
147case X$with_ssl in
148    X | Xyes | Xno) AC_MSG_ERROR([--with-ssl-incl=PATH set without --with-ssl=PATH]);;
149esac
150],
151[with_ssl_incl=$with_ssl]) #default
152
153AC_ARG_WITH(ssl-rpath,
154AS_HELP_STRING([--with-ssl-rpath=yes|no|PATHS],
155               [runtime library path for OpenSSL. Default is "yes", which equates to a
156	       number of standard locations. If "no", then no runtime
157	       library paths will be used. Anything else should be a
158	       comma separated list of paths.]),
159[
160case X$with_ssl in
161    Xno) AC_MSG_ERROR([--with-ssl-rpath set without --with-ssl]);;
162esac
163],
164[with_ssl_rpath=yes]) #default
165
166
167AC_ARG_ENABLE(dynamic-ssl-lib,
168AS_HELP_STRING([--disable-dynamic-ssl-lib],
169               [disable using dynamic openssl libraries]),
170[ case "$enableval" in
171    no) enable_dynamic_ssl=no ;;
172    *)  enable_dynamic_ssl=yes ;;
173  esac ], enable_dynamic_ssl=yes)
174
175AC_ARG_ENABLE(evp-dh,
176AS_HELP_STRING([--disable-evp-dh],
177	       [intentionally undocumented workaround]),
178[ case "$enableval" in
179    no)   DISABLE_EVP_DH=1;;
180    *)    DISABLE_EVP_DH=0;;
181  esac ], DISABLE_EVP_DH=0)
182
183
184AC_ARG_ENABLE(evp-hmac,
185AS_HELP_STRING([--disable-evp-hmac],
186	       [intentionally undocumented workaround]),
187[ case "$enableval" in
188    no)   DISABLE_EVP_HMAC=1;;
189    *)    DISABLE_EVP_HMAC=0;;
190  esac ], DISABLE_EVP_HMAC=0)
191
192
193#----------------------------------------------------------------------
194# We actually might do the SSL tests twice due to late discovery of
195# kerberos problems with static linking, in case we redo it all trying
196# dynamic SSL libraries instead.
197#----------------------------------------------------------------------
198
199ssl_done=no
200
201while test "x$ssl_done" != "xyes"; do
202
203ssl_done=yes # Default only one run
204
205# Remove all SKIP files from previous runs
206for a in ssl crypto ssh; do
207  rm -f "$ERL_TOP/lib/$a/SKIP"
208done
209
210SSL_DYNAMIC_ONLY=$enable_dynamic_ssl
211SSL_STATIC_ONLY=no
212
213case "$erl_xcomp_without_sysroot-$with_ssl" in
214  yes-* | no-no)
215    SSL_APP=
216    CRYPTO_APP=
217    SSH_APP=
218    if test "$with_ssl" = "no"; then
219	skip="User gave --without-ssl option"
220    else
221	skip="Cannot search for ssl; missing cross system root (erl_xcomp_sysroot)."
222    fi
223    for a in ssl crypto ssh; do
224        echo "$skip" > $ERL_TOP/lib/$a/SKIP
225    done
226    ;;
227  no-yes | no- )
228    # On windows, we could try to find the installation
229    # of Shining Light OpenSSL, which can be found by poking in
230    # the uninstall section in the registry, it's worth a try...
231    extra_dir=""
232    if  test "$host_os" = "win32"; then
233    	AC_CHECK_PROG(REGTOOL, reg_query.sh, reg_query.sh, false)
234	if test "$ac_cv_prog_REGTOOL" != false; then
235	   	if test "x$ac_cv_sizeof_void_p" = "x8"; then
236		   rp="HKLM/SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall/OpenSSL (64-bit)_is1"
237		else
238		   rp="HKLM/SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall/OpenSSL_is1"
239		fi
240		key="Inno Setup: App Path"
241		if "$ac_cv_prog_REGTOOL" "$rp" "$key" > /dev/null; then
242			ssl_install_dir=`"$ac_cv_prog_REGTOOL" "$rp" "$key"`
243			extra_dir=`w32_path.sh -u "$ssl_install_dir"`
244		fi
245	fi
246    fi
247    # We search for OpenSSL in the common OS standard locations.
248    SSL_APP=ssl
249    CRYPTO_APP=crypto
250    SSH_APP=ssh
251
252    SSL_CRYPTO_LIBNAME=crypto
253    SSL_SSL_LIBNAME=ssl
254    SSL_EXTRA_LIBS=""
255
256    if  test "$host_os" = "win32" ; then
257    	if test "x$ac_cv_sizeof_void_p" = "x8"; then
258	  std_win_ssl_locations="/mnt/c/OpenSSL-Win64 /c/OpenSSL-Win64 /mnt/c/opt/local64/pgm/OpenSSL /opt/local64/pgm/OpenSSL /cygdrive/c/OpenSSL-Win64"
259	  lib_bits=64
260	else
261	  std_win_ssl_locations="/mnt/c/OpenSSL-Win32 /c/OpenSSL-Win32 /mnt/c/OpenSSL /c/OpenSSL /cygdrive/c/OpenSSL /opt/local/pgm/OpenSSL /opt/local32/pgm/OpenSSL /mnt/c/opt/local/pgm/OpenSSL /mnt/c/opt/local32/pgm/OpenSSL /cygdrive/c/OpenSSL-Win32"
262	  lib_bits=32
263	fi
264    else
265        std_win_ssl_locations=""
266    fi
267
268
269    AC_MSG_CHECKING(for OpenSSL >= 0.9.8c in standard locations)
270    for rdir in "$extra_dir" $std_win_ssl_locations $std_ssl_locations; do
271	dir="$erl_xcomp_sysroot$rdir"
272	if test -f "$erl_xcomp_isysroot$rdir/include/openssl/opensslv.h"; then
273		is_real_ssl=yes
274		SSL_INCDIR="$dir"
275		if test "$host_os" = "win32" ; then
276			if test -f "$dir/lib/VC/libeay32.lib"; then
277				SSL_RUNTIME_LIBDIR="$rdir/lib/VC"
278				SSL_LIBDIR="$dir/lib/VC"
279				SSL_CRYPTO_LIBNAME=libeay32
280				SSL_SSL_LIBNAME=ssleay32
281			elif test -f "$dir/lib/VC/openssl.lib"; then
282				SSL_RUNTIME_LIBDIR="$rdir/lib/VC"
283				SSL_LIBDIR="$dir/lib/VC"
284			elif test -f "$dir/lib/VC/libeay32MD.lib"; then
285		            SSL_CRYPTO_LIBNAME=libeay32MD
286		            SSL_SSL_LIBNAME=ssleay32MD
287			    if test "x$enable_dynamic_ssl" = "xno" && \
288	                       test -f "$dir/lib/VC/static/libeay32MD.lib"; then
289				  SSL_RUNTIME_LIBDIR="$rdir/lib/VC/static"
290				  SSL_LIBDIR="$dir/lib/VC/static"
291		            else
292			          SSL_RUNTIME_LIBDIR="$rdir/lib/VC"
293				  SSL_LIBDIR="$dir/lib/VC"
294                            fi
295			elif test -f "$dir/lib/libeay32.lib"; then
296				SSL_RUNTIME_LIBDIR="$rdir/lib"
297				SSL_LIBDIR="$dir/lib"
298				SSL_CRYPTO_LIBNAME=libeay32
299				SSL_SSL_LIBNAME=ssleay32
300			elif test -f "$dir/lib/VC/libcrypto${lib_bits}MD.lib"; then
301		            SSL_CRYPTO_LIBNAME=libcrypto${lib_bits}MD
302			    # NOTE: Additional ugly extra libs at the end
303		            SSL_SSL_LIBNAME="libssl${lib_bits}MD"
304			    if test "x$enable_dynamic_ssl" = "xno" && \
305	                       test -f "$dir/lib/VC/static/$SSL_CRYPTO_LIBNAME.lib"; then
306       			          SSL_EXTRA_LIBS="-lCRYPT32 -lWS2_32"
307				  SSL_RUNTIME_LIBDIR="$rdir/lib/VC/static"
308				  SSL_LIBDIR="$dir/lib/VC/static"
309		            else
310			          SSL_RUNTIME_LIBDIR="$rdir/lib/VC"
311				  SSL_LIBDIR="$dir/lib/VC"
312                            fi
313			elif test -f "$dir/lib/openssl.lib"; then
314				SSL_RUNTIME_LIBDIR="$rdir/lib"
315				SSL_LIBDIR="$dir/lib"
316			else
317				is_real_ssl=no
318			fi
319		elif test -f "$dir/lib/powerpc/libsslcrypto.a"; then
320			SSL_CRYPTO_LIBNAME=sslcrypto
321			SSL_LIBDIR="$dir/lib/powerpc/"
322			SSL_RUNTIME_LIBDIR="$rdir/lib/powerpc/"
323		else
324			if test "x$ac_cv_sizeof_void_p" = "x8"; then
325				if test -f "$dir/lib64/libcrypto.a"; then
326					SSL_RUNTIME_LIBDIR="$rdir/lib64"
327					SSL_LIBDIR="$dir/lib64"
328				elif test -f "$dir/lib/64/libcrypto.a"; then
329					SSL_RUNTIME_LIBDIR="$rdir/lib/64"
330					SSL_LIBDIR="$dir/lib/64"
331				elif test -f "$dir/lib64/libcrypto.so"; then
332					SSL_RUNTIME_LIBDIR="$rdir/lib64"
333					SSL_LIBDIR="$dir/lib64"
334				elif test -f "$dir/lib/64/libcrypto.so"; then
335					SSL_RUNTIME_LIBDIR="$rdir/lib/64"
336					SSL_LIBDIR="$dir/lib/64"
337				else
338					SSL_RUNTIME_LIBDIR="$rdir/lib"
339					SSL_LIBDIR="$dir/lib"
340				fi
341			else
342				SSL_RUNTIME_LIBDIR="$rdir/lib"
343				SSL_LIBDIR="$dir/lib"
344			fi
345		fi
346		if test '!' -f "$SSL_LIBDIR/lib${SSL_CRYPTO_LIBNAME}.a"; then
347			SSL_DYNAMIC_ONLY=yes
348		elif test '!' -f "$SSL_LIBDIR/lib${SSL_CRYPTO_LIBNAME}.so" -a '!' -f "$SSL_LIBDIR/lib${SSL_CRYPTO_LIBNAME}.dylib"; then
349			SSL_STATIC_ONLY=yes
350		fi
351		SSL_BINDIR="$rdir/bin"
352		if test "x$is_real_ssl" = "xyes" ; then
353			SSL_INCLUDE="-I$dir/include"
354			old_CPPFLAGS=$CPPFLAGS
355			CPPFLAGS=$SSL_INCLUDE
356			AC_EGREP_CPP(^yes.?$,[
357#include <openssl/opensslv.h>
358#if OPENSSL_VERSION_NUMBER >= 0x0090803fL
359yes
360#endif
361			],[
362			ssl_found=yes
363			],[
364			SSL_APP=
365			ssl_found=no
366         		])
367         		CPPFLAGS=$old_CPPFLAGS
368			if test "x$ssl_found" = "xyes"; then
369			   	if test "x$host_os" = "xwin32" ; then
370				   	ssl_linkable=yes
371				elif test "x${SSL_CRYPTO_LIBNAME}" = "xsslcrypto"; then
372				# This should only be triggered seen OSE
373					ssl_linkable=yes
374				else
375					saveCFLAGS="$CFLAGS"
376 					saveLDFLAGS="$LDFLAGS"
377					saveLIBS="$LIBS"
378 					CFLAGS="$CFLAGS $SSL_INCLUDE"
379					if test "x$SSL_STATIC_ONLY" = "xyes"; then
380						LIBS="${SSL_LIBDIR}/lib${SSL_CRYPTO_LIBNAME}.a"
381					else
382						LDFLAGS="$LDFLAGS -L$SSL_LIBDIR"
383						LIBS="$LIBS -l${SSL_CRYPTO_LIBNAME}"
384					fi
385 					AC_TRY_LINK([
386					#include <stdio.h>
387 					#include <openssl/hmac.h>],
388 					[
389					HMAC(0, 0, 0, 0, 0, 0, 0);
390 					],
391 					[ssl_linkable=yes],
392 					[ssl_linkable=no])
393 					CFLAGS="$saveCFLAGS"
394 					LDFLAGS="$saveLDFLAGS"
395					LIBS="$saveLIBS"
396				fi
397 			fi
398	 		if test "x$ssl_found" = "xyes" && test "x$ssl_linkable" = "xyes"; then
399			 	AC_MSG_RESULT([$dir])
400	   			break;
401         		fi
402		fi
403       fi
404    done
405
406    if test "x$ssl_found" != "xyes" ; then
407	dnl
408	dnl If no SSL found above, check whether we are running on OpenBSD.
409	dnl
410	case $host_os in
411	openbsd*)
412	       if test -f "$erl_xcomp_isysroot/usr/include/openssl/opensslv.h"; then
413		  # Trust OpenBSD to have everything the in the correct locations.
414		  ssl_found=yes
415		  ssl_linkable=yes
416		  SSL_INCDIR="$erl_xcomp_sysroot/usr"
417	          AC_MSG_RESULT([$SSL_INCDIR])
418		  SSL_RUNTIME_LIB="/usr/lib"
419		  SSL_LIB="$erl_xcomp_sysroot/usr/lib"
420		  SSL_BINDIR="/usr/sbin"
421		  dnl OpenBSD requires us to link with -L and -l
422		  SSL_DYNAMIC_ONLY="yes"
423		fi
424		;;
425	esac
426    fi
427dnl		Now, certain linuxes have a 64bit libcrypto
428dnl		that cannot build shared libraries (i.e. not PIC)
429dnl		One could argue that this is wrong, but
430dnl		so it is - be adoptable
431    if test "$ssl_found" = "yes" && test "$ssl_linkable" = "yes" && test "$SSL_DYNAMIC_ONLY" != "yes"; then
432	case $host_os in
433		linux*)
434			saveCFLAGS="$CFLAGS"
435 			saveLDFLAGS="$LDFLAGS"
436			saveLIBS="$LIBS"
437 			CFLAGS="$DED_CFLAGS $SSL_INCLUDE"
438 			LDFLAGS="$DED_LDFLAGS"
439			LIBS="$SSL_LIBDIR/libcrypto.a $STATIC_ZLIB_LIBS"
440 			AC_TRY_LINK([
441			#include <stdio.h>
442 			#include <openssl/hmac.h>],
443 			[
444			HMAC(0, 0, 0, 0, 0, 0, 0);
445 			],
446 			[ssl_dyn_linkable=yes],
447 			[ssl_dyn_linkable=no])
448 			CFLAGS="$saveCFLAGS"
449 			LDFLAGS="$saveLDFLAGS"
450			LIBS="$saveLIBS"
451			if test "x$ssl_dyn_linkable" != "xyes"; then
452				SSL_DYNAMIC_ONLY=yes
453				AC_MSG_WARN([SSL will be linked against dynamic lib as static lib is not purely relocatable])
454			fi
455			;;
456	esac
457    fi
458
459
460
461
462    if test "x$ssl_found" != "xyes" || test  "x$ssl_linkable" != "xyes"; then
463       if test "x$ssl_found" = "xyes"; then
464       		AC_MSG_RESULT([found; but not usable])
465       else
466       		AC_MSG_RESULT([no])
467       fi
468       SSL_APP=
469       CRYPTO_APP=
470       SSH_APP=
471       AC_MSG_WARN([No (usable) OpenSSL found, skipping ssl, ssh and crypto applications])
472
473       for a in ssl crypto ssh; do
474           echo "No usable OpenSSL found" > $ERL_TOP/lib/$a/SKIP
475       done
476    fi
477    ;;
478  *)
479    # Option given with PATH to package
480    if test ! -d "$with_ssl" ; then
481       AC_MSG_ERROR(Invalid path to option --with-ssl=PATH)
482    fi
483    if test ! -d "$with_ssl_incl" ; then
484       AC_MSG_ERROR(Invalid path to option --with-ssl-incl=PATH)
485    fi
486    SSL_INCDIR="$with_ssl_incl"
487    SSL_CRYPTO_LIBNAME=crypto
488    SSL_SSL_LIBNAME=ssl
489    SSL_EXTRA_LIBS=""
490    if test "x$host_os" = "xwin32" && test -d "$with_ssl/lib/VC"; then
491	if test -f "$with_ssl/lib/VC/libeay32.lib"; then
492	    SSL_LIBDIR="$with_ssl/lib/VC"
493	    SSL_CRYPTO_LIBNAME=libeay32
494	    SSL_SSL_LIBNAME=ssleay32
495	elif test -f "$with_ssl/lib/VC/openssl.lib"; then
496	    SSL_LIBDIR="$with_ssl/lib/VC"
497	elif test -f $with_ssl/lib/VC/libeay32MD.lib; then
498	    SSL_CRYPTO_LIBNAME=libeay32MD
499            SSL_SSL_LIBNAME=ssleay32MD
500	    if test "x$enable_dynamic_ssl" = "xno" && \
501	       test -f  $with_ssl/lib/VC/static/libeay32MD.lib; then
502		SSL_LIBDIR="$with_ssl/lib/VC/static"
503	    else
504		SSL_LIBDIR="$with_ssl/lib/VC"
505            fi
506	elif test -f "$dir/lib/VC/libcrypto${lib_bits}MD.lib"; then
507            SSL_CRYPTO_LIBNAME=libcrypto${lib_bits}MD
508	    # NOTE: Additional ugly extra libs at the end
509            SSL_SSL_LIBNAME="libssl${lib_bits}MD"
510	    if test "x$enable_dynamic_ssl" = "xno" && \
511               test -f "$dir/lib/VC/static/$SSL_CRYPTO_LIBNAME.lib"; then
512	          SSL_EXTRA_LIBS="-lCRYPT32 -lWS2_32"
513		  SSL_RUNTIME_LIBDIR="$rdir/lib/VC/static"
514		  SSL_LIBDIR="$dir/lib/VC/static"
515            else
516	          SSL_RUNTIME_LIBDIR="$rdir/lib/VC"
517		  SSL_LIBDIR="$dir/lib/VC"
518            fi
519	elif test -f "$with_ssl/lib/libeay32.lib"; then
520	    SSL_LIBDIR="$with_ssl/lib"
521	    SSL_CRYPTO_LIBNAME=libeay32
522	    SSL_SSL_LIBNAME=ssleay32
523	elif test -f "$dir/lib/openssl.lib"; then
524	    SSL_RUNTIME_LIBDIR="$rdir/lib"
525	    SSL_LIBDIR="$dir/lib"
526	    SSL_CRYPTO_LIBNAME=libcrypto
527	    SSL_SSL_LIBNAME=openssl
528	else
529	    # This probably wont work, but that's what the user said, so...
530	    SSL_LIBDIR="$with_ssl/lib"
531	fi
532    elif test -f "$dir/lib/powerpc/libsslcrypto.a"; then
533	    SSL_CRYPTO_LIBNAME=sslcrypto
534	    SSL_LIBDIR="$with_ssl/lib/powerpc/"
535    elif test "x$ac_cv_sizeof_void_p" = "x8"; then
536	if test -f "$with_ssl/lib64/libcrypto.a"; then
537		SSL_LIBDIR="$with_ssl/lib64"
538	elif test -f "$with_ssl/lib/64/libcrypto.a"; then
539		SSL_LIBDIR="$with_ssl/lib/64"
540	elif test -f "$with_ssl/lib64/libcrypto.so"; then
541		SSL_LIBDIR="$with_ssl/lib64"
542	elif test -f "$with_ssl/lib/64/libcrypto.so"; then
543		SSL_LIBDIR="$with_ssl/lib/64"
544	else
545		SSL_LIBDIR="$with_ssl/lib"
546	fi
547    else
548	SSL_LIBDIR="$with_ssl/lib"
549    fi
550    if test '!' -f "${SSL_LIBDIR}/lib${SSL_CRYPTO_LIBNAME}.a"; then
551	SSL_DYNAMIC_ONLY=yes
552    elif test '!' -f ${SSL_LIBDIR}/lib${SSL_CRYPTO_LIBNAME}.so -a '!' -f "$SSL_LIBDIR/lib${SSL_CRYPTO_LIBNAME}.dylib"; then
553    	SSL_STATIC_ONLY=yes
554    fi
555    SSL_INCLUDE="-I$with_ssl_incl/include"
556    SSL_APP=ssl
557    CRYPTO_APP=crypto
558    SSH_APP=ssh
559    if test "$cross_compiling" = "yes"; then
560	SSL_RUNTIME_LIBDIR=`echo "$SSL_LIBDIR" | sed -n "s|^$erl_xcomp_sysroot\(/*\)\(.*\)\$|/\2|p"`
561    else
562	SSL_RUNTIME_LIBDIR="$SSL_LIBDIR"
563    fi
564esac
565
566if test "x$SSL_APP" != "x" ; then
567    dnl We found openssl, now check if we use kerberos 5 support
568    dnl FIXME: Do we still support platforms that have Kerberos?
569    AC_MSG_CHECKING(for OpenSSL kerberos 5 support)
570    old_CPPFLAGS=$CPPFLAGS
571    CPPFLAGS=$SSL_INCLUDE
572    AC_EGREP_CPP(^yes$,[
573#include <openssl/opensslv.h>
574#include <openssl/opensslconf.h>
575#if OPENSSL_VERSION_NUMBER < 0x1010000fL && !defined(OPENSSL_NO_KRB5)
576yes
577#endif
578      ],[
579      AC_MSG_RESULT([yes])
580      ssl_krb5_enabled=yes
581      if test "x$SSL_DYNAMIC_ONLY" != "xyes"; then
582          if test -f "$SSL_LIBDIR/libkrb5.a"; then
583              SSL_LINK_WITH_KERBEROS=yes
584	      STATIC_KERBEROS_LIBS="$SSL_LIBDIR/libkrb5.a"
585	      if test -f "$SSL_LIBDIR/libkrb5support.a"; then
586		  STATIC_KERBEROS_LIBS="$STATIC_KERBEROS_LIBS $SSL_LIBDIR/libkrb5support.a"
587	      fi
588	      if test -f "$SSL_LIBDIR/libk5crypto.a"; then
589		  STATIC_KERBEROS_LIBS="$STATIC_KERBEROS_LIBS $SSL_LIBDIR/libk5crypto.a"
590	      fi
591	      if test -f "$SSL_LIBDIR/libresolv.a"; then
592		  STATIC_KERBEROS_LIBS="$STATIC_KERBEROS_LIBS $SSL_LIBDIR/libresolv.a"
593	      fi
594	      if test -f "$SSL_LIBDIR/libcom_err.a"; then
595		  STATIC_KERBEROS_LIBS="$STATIC_KERBEROS_LIBS $SSL_LIBDIR/libcom_err.a"
596	      fi
597          else
598	      AC_MSG_WARN([Kerberos needed but no kerberos static libraries found])
599	      AC_MSG_WARN([Rescanning for dynamic SSL libraries])
600	      enable_dynamic_ssl=yes
601	      ssl_done=no
602	      SSL_LINK_WITH_KERBEROS=no
603	      STATIC_KERBEROS_LIBS=""
604	      ssl_krb5_enabled=no
605	      SSL_WITH_KERBEROS=no
606          fi
607      else
608	      SSL_LINK_WITH_KERBEROS=no
609	      STATIC_KERBEROS_LIBS=""
610      fi
611      ],[
612      AC_MSG_RESULT([no])
613      ssl_krb5_enabled=no
614      SSL_WITH_KERBEROS=no
615      ])
616    CPPFLAGS=$old_CPPFLAGS
617    SSL_KRB5_INCLUDE=
618    if test "x$ssl_krb5_enabled" = "xyes" ; then
619        AC_MSG_CHECKING(for krb5.h in standard locations)
620	for dir in $extra_dir "$SSL_INCDIR/include" "$SSL_INCDIR/include/openssl" \
621		"$SSL_INCDIR/include/kerberos" \
622		"$erl_xcomp_isysroot/cygdrive/c/kerberos/include" \
623		"$erl_xcomp_isysroot/usr/local/kerberos/include" \
624		"$erl_xcomp_isysroot/usr/kerberos/include" \
625		"$erl_xcomp_isysroot/usr/include"
626	do
627            if test -f "$dir/krb5.h" ; then
628                SSL_KRB5_INCLUDE="$dir"
629		break
630            fi
631        done
632        if test "x$SSL_KRB5_INCLUDE" = "x" ; then
633	    AC_MSG_RESULT([not found])
634	    SSL_APP=
635	    CRYPTO_APP=
636	    SSH_APP=
637	    AC_MSG_WARN([OpenSSL is configured for kerberos but no krb5.h found])
638	    for a in ssl crypto ssh ; do
639	 	echo "OpenSSL is configured for kerberos but no krb5.h found" > $ERL_TOP/lib/$a/SKIP
640	    done
641        else
642            AC_MSG_RESULT([found in $SSL_KRB5_INCLUDE])
643            SSL_INCLUDE="$SSL_INCLUDE -I$SSL_KRB5_INCLUDE"
644        fi
645    fi
646fi
647
648done # while test ssl_done != yes
649
650SSL_DED_LD_RUNTIME_LIBRARY_PATH=
651ded_ld_rflg="$DED_LD_FLAG_RUNTIME_LIBRARY_PATH"
652
653
654case "$with_ssl_rpath" in
655
656yes)   # Use standard lib locations for ssl runtime library path
657
658  if test "$SSL_APP" != "" && test "$SSL_DYNAMIC_ONLY" = "yes" && test "$ded_ld_rflg" != ""; then
659
660    AC_MSG_CHECKING(for ssl runtime library path to use)
661
662    libdirs="/lib"
663
664    if test "$ac_cv_sizeof_void_p" = "8"; then
665	dir_lib64=no
666	dir_lib_64=no
667
668	case "$SSL_RUNTIME_LIBDIR" in
669	    */lib/64 | */lib/64/ ) dir_lib_64=yes;;
670	    */lib64 | */lib64/ ) dir_lib64=yes;;
671	    *) ;;
672	esac
673
674	for dir in $std_ssl_locations; do
675	    test $dir_lib_64 = no &&
676	    	test -d "$erl_xcomp_sysroot$dir/lib/64" &&
677		    dir_lib_64=yes
678	    test $dir_lib64 = no &&
679		test -d "$erl_xcomp_sysroot$dir/lib64" &&
680		    dir_lib64=yes
681	done
682
683	test $dir_lib_64 = yes && libdirs="/lib/64 $libdirs"
684	test $dir_lib64 = yes && libdirs="/lib64 $libdirs"
685    fi
686
687    for type in std x_std curr; do
688
689        ded_ld_rpath="$ded_ld_rflg$SSL_RUNTIME_LIBDIR"
690	rpath="$SSL_RUNTIME_LIBDIR"
691
692	if test $type != curr; then
693	    for ldir in $libdirs; do
694		for dir in $std_ssl_locations; do
695		    test "$SSL_LIBDIR" != "$dir$ldir" || continue
696		    test $type != x_std || test -d "$dir$ldir" || continue
697		    if test "$dir" = "/"; then
698			libdir="$ldir"
699		    else
700			libdir="$dir$ldir"
701		    fi
702		    ded_ld_rpath="$ded_ld_rpath $ded_ld_rflg$libdir"
703		    rpath="$rpath:$libdir"
704                done
705	    done
706	fi
707
708	saveCFLAGS="$CFLAGS"
709	saveLDFLAGS="$LDFLAGS"
710	saveLIBS="$LIBS"
711	CFLAGS="$CFLAGS $SSL_INCLUDE"
712	LDFLAGS="$LDFLAGS $ld_rpath -L$SSL_LIBDIR"
713	LIBS="-lcrypto"
714	AC_TRY_LINK([
715                         #include <stdio.h>
716                         #include <openssl/hmac.h>
717                    ],
718                    [
719			 HMAC(0, 0, 0, 0, 0, 0, 0);
720                    ],
721                    [rpath_success=yes],
722                    [rpath_success=no])
723	CFLAGS="$saveCFLAGS"
724	LDFLAGS="$saveLDFLAGS"
725	LIBS="$saveLIBS"
726
727	test "$rpath_success" = "yes" && break
728    done
729
730    test "$rpath_success" = "yes" || { ded_ld_rpath=; rpath=; }
731
732    SSL_DED_LD_RUNTIME_LIBRARY_PATH="$ded_ld_rpath"
733
734    AC_MSG_RESULT([$rpath])
735    test "$rpath" != "" || AC_MSG_WARN([Cannot set run path during linking])
736  fi
737  ;;
738
739no)   # Use no ssl runtime library path
740  SSL_DED_LD_RUNTIME_LIBRARY_PATH=
741  ;;
742
743*)    # Use ssl runtime library paths set by --with-ssl-rpath (without any check)
744  ded_ld_rpath=
745  delimit=
746  for dir in `echo $with_ssl_rpath | sed "s/,/ /g"`; do
747      ded_ld_rpath="$ded_ld_rpath$delimit$ded_ld_rflg$dir"
748      delimit=" "
749  done
750  SSL_DED_LD_RUNTIME_LIBRARY_PATH="$ded_ld_rpath"
751  ;;
752
753esac
754
755
756AC_ARG_ENABLE(fips,
757AS_HELP_STRING([--enable-fips], [enable OpenSSL FIPS mode support])
758AS_HELP_STRING([--disable-fips], [disable OpenSSL FIPS mode support (default)]),
759[ case "$enableval" in
760    yes) enable_fips_support=yes ;;
761    *)   enable_fips_support=no ;;
762  esac ], enable_fips_support=no)
763
764if test "x$enable_fips_support" = "xyes" && test "$CRYPTO_APP" != ""; then
765   saveCFLAGS="$CFLAGS"
766   saveLDFLAGS="$LDFLAGS"
767   saveLIBS="$LIBS"
768   CFLAGS="$CFLAGS $SSL_INCLUDE"
769   LDFLAGS="$LDFLAGS $ded_ld_rpath -L$SSL_LIBDIR"
770   LIBS="-lcrypto"
771   AC_CHECK_FUNC([FIPS_mode_set],
772   [SSL_FLAGS="-DFIPS_SUPPORT"],
773   [SSL_FLAGS=])
774   CFLAGS="$saveCFLAGS"
775   LDFLAGS="$saveLDFLAGS"
776   LIBS="$saveLIBS"
777else
778   SSL_FLAGS=
779fi
780
781AC_SUBST(SSL_INCLUDE)
782AC_SUBST(SSL_INCDIR)
783AC_SUBST(SSL_LIBDIR)
784AC_SUBST(SSL_FLAGS)
785AC_SUBST(SSL_CRYPTO_LIBNAME)
786AC_SUBST(SSL_SSL_LIBNAME)
787AC_SUBST(SSL_EXTRA_LIBS)
788AC_SUBST(SSL_DED_LD_RUNTIME_LIBRARY_PATH)
789AC_SUBST(SSL_DYNAMIC_ONLY)
790AC_SUBST(SSL_LINK_WITH_KERBEROS)
791AC_SUBST(STATIC_KERBEROS_LIBS)
792AC_SUBST(SSL_LINK_WITH_ZLIB)
793AC_SUBST(STATIC_ZLIB_LIBS)
794AC_SUBST(DISABLE_EVP_DH)
795AC_SUBST(DISABLE_EVP_HMAC)
796
797AC_OUTPUT(c_src/$host/Makefile:c_src/Makefile.in)
798
799