aboutsummaryrefslogblamecommitdiffstats
path: root/lib/crypto/configure.in
blob: a3b6673f299d00d153dc10fb2751c3c4b3eb78c2 (plain) (tree)
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775



































































                                                                             


































































































































































































































































































































































































































































































































































































































































































































                                                                                                                                                        
dnl Process this file with autoconf to produce a configure script. -*-m4-*-
dnl
dnl %CopyrightBegin%
dnl
dnl Copyright Ericsson AB 2018. All Rights Reserved.
dnl
dnl Licensed under the Apache License, Version 2.0 (the "License");
dnl you may not use this file except in compliance with the License.
dnl You may obtain a copy of the License at
dnl
dnl     http://www.apache.org/licenses/LICENSE-2.0
dnl
dnl Unless required by applicable law or agreed to in writing, software
dnl distributed under the License is distributed on an "AS IS" BASIS,
dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dnl See the License for the specific language governing permissions and
dnl limitations under the License.
dnl
dnl %CopyrightEnd%
dnl

dnl define([AC_CACHE_LOAD], )dnl
dnl define([AC_CACHE_SAVE], )dnl


AC_INIT(vsn.mk)

if test -z "$ERL_TOP" || test ! -d "$ERL_TOP" ; then
  AC_CONFIG_AUX_DIRS(autoconf)
else
  erl_top=${ERL_TOP}
  AC_CONFIG_AUX_DIRS($erl_top/erts/autoconf)
fi

if test "X$host" != "Xfree_source" -a "X$host" != "Xwin32"; then
    AC_CANONICAL_HOST
else
    host_os=win32
fi

LM_PRECIOUS_VARS

if test "$cross_compiling" = "yes"; then
    CROSS_COMPILING=yes
else
    CROSS_COMPILING=no
fi
AC_SUBST(CROSS_COMPILING)

ERL_XCOMP_SYSROOT_INIT

AC_PROG_CC
LM_WINDOWS_ENVIRONMENT

ERL_DED

dnl
dnl SSL, SSH and CRYPTO need the OpenSSL libraries
dnl
dnl Check flags --with-ssl, --without-ssl --with-ssl=PATH.
dnl If no option is given or --with-ssl is set without a path then we
dnl search for OpenSSL libraries and header files in the standard locations. 
dnl If set to --without-ssl we disable the use of SSL, SSH and CRYPTO.
dnl If set to --with-ssl=PATH we use that path as the prefix, i.e. we
dnl use "PATH/include" and "PATH/lib".

AC_CHECK_SIZEOF(void *)

std_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 /"

AC_ARG_WITH(ssl-zlib,
AS_HELP_STRING([--with-ssl-zlib=PATH],
               [specify location of ZLib to be used by OpenSSL])
AS_HELP_STRING([--with-ssl-zlib],
               [link SSL with  Zlib (default if found)])
AS_HELP_STRING([--without-ssl-zlib],
               [don't link SSL with ZLib]))

if  test "x$with_ssl_zlib" = "xno"; then
	SSL_LINK_WITH_ZLIB=no
	STATIC_ZLIB_LIBS=
elif test "x$with_ssl_zlib" = "xyes" || test "x$with_ssl_zlib" = "x"; then
	if test $erl_xcomp_without_sysroot = yes; then
		AC_MSG_WARN([Cannot search for zlib; missing cross system root (erl_xcomp_sysroot).])
		SSL_LINK_WITH_ZLIB=no	
		STATIC_ZLIB_LIBS=	
	elif  test "x$MIXED_CYGWIN" = "xyes" -o "x$MIXED_MSYS" = "xyes"; then
		SSL_LINK_WITH_ZLIB=no	
		STATIC_ZLIB_LIBS=	
	else
		SSL_LINK_WITH_ZLIB=no
		STATIC_ZLIB_LIBS=
		AC_MSG_CHECKING(for static ZLib to be used by SSL in standard locations) 
		for rdir in $std_ssl_locations; do
			dir="$erl_xcomp_sysroot$rdir"
			if test "x$ac_cv_sizeof_void_p" = "x8"; then
				if test -f "$dir/lib64/libz.a"; then
					SSL_LINK_WITH_ZLIB=yes
					STATIC_ZLIB_LIBS="$dir/lib64/libz.a"
					break
				elif test -f "$dir/lib/64/libz.a"; then
					SSL_LINK_WITH_ZLIB=yes
					STATIC_ZLIB_LIBS="$dir/lib/64/libz.a"
					break
				fi
			fi
			if test -f "$dir/lib/libz.a"; then
					SSL_LINK_WITH_ZLIB=yes
				STATIC_ZLIB_LIBS="$dir/lib/libz.a"
				break
			fi
		done
		if test "x$SSL_LINK_WITH_ZLIB" = "xno"; then
		       	AC_MSG_RESULT([no])
		else
			AC_MSG_RESULT([$STATIC_ZLIB_LIBS])
		fi
	fi				
else
	SSL_LINK_WITH_ZLIB=no
	STATIC_ZLIB_LIBS=
	if test -f "$with_ssl_zlib/libz.a"; then
		SSL_LINK_WITH_ZLIB=yes
		STATIC_ZLIB_LIBS=$with_ssl_zlib/libz.a
	elif test -f "$with_ssl_zlib/lib/libz.a"; then
		SSL_LINK_WITH_ZLIB=yes
		STATIC_ZLIB_LIBS=$with_ssl_zlib/lib/libz.a
	fi
	if test "x$ac_cv_sizeof_void_p" = "x8"; then
		if test -f "$with_ssl_zlib/lib64/libz.a"; then
			SSL_LINK_WITH_ZLIB=yes
			STATIC_ZLIB_LIBS=$with_ssl_zlib/lib64/libz.a
		elif test -f "$with_ssl_zlib/lib/64/libz.a"; then
			SSL_LINK_WITH_ZLIB=yes
			STATIC_ZLIB_LIBS=$with_ssl_zlib/lib/64/libz.a
		fi
	fi
	if test "x$SSL_LINK_WITH_ZLIB" = "xno"; then
	       	AC_MSG_ERROR(Invalid path to option --with-ssl-zlib=PATH)
	fi
fi
		
			
AC_ARG_WITH(ssl,
AS_HELP_STRING([--with-ssl=PATH], [specify location of OpenSSL include and lib])
AS_HELP_STRING([--with-ssl], [use SSL (default)])
AS_HELP_STRING([--without-ssl], [don't use SSL]))

AC_ARG_WITH(ssl-incl,
AS_HELP_STRING([--with-ssl-incl=PATH], [location of OpenSSL include dir, if different than specified by --with-ssl=PATH]),
[
case X$with_ssl in
    X | Xyes | Xno) AC_MSG_ERROR([--with-ssl-incl=PATH set without --with-ssl=PATH]);;
esac
],
[with_ssl_incl=$with_ssl]) #default

AC_ARG_WITH(ssl-rpath,
AS_HELP_STRING([--with-ssl-rpath=yes|no|PATHS],
               [runtime library path for OpenSSL. Default is "yes", which equates to a
	       number of standard locations. If "no", then no runtime
	       library paths will be used. Anything else should be a
	       comma separated list of paths.]),
[
case X$with_ssl in
    Xno) AC_MSG_ERROR([--with-ssl-rpath set without --with-ssl]);;
esac
],
[with_ssl_rpath=yes]) #default


AC_ARG_ENABLE(dynamic-ssl-lib,
AS_HELP_STRING([--disable-dynamic-ssl-lib],
               [disable using dynamic openssl libraries]),
[ case "$enableval" in
    no) enable_dynamic_ssl=no ;;
    *)  enable_dynamic_ssl=yes ;;
  esac ], enable_dynamic_ssl=yes)

#----------------------------------------------------------------------
# We actually might do the SSL tests twice due to late discovery of 
# kerberos problems with static linking, in case we redo it all trying
# dynamic SSL libraries instead.
#----------------------------------------------------------------------

ssl_done=no

while test "x$ssl_done" != "xyes"; do

ssl_done=yes # Default only one run

# Remove all SKIP files from previous runs
for a in ssl crypto ssh; do
  rm -f "$ERL_TOP/lib/$a/SKIP"
done

SSL_DYNAMIC_ONLY=$enable_dynamic_ssl
SSL_STATIC_ONLY=no

case "$erl_xcomp_without_sysroot-$with_ssl" in
  yes-* | no-no)
    SSL_APP=
    CRYPTO_APP=
    SSH_APP=
    if test "$with_ssl" = "no"; then
	skip="User gave --without-ssl option"
    else
	skip="Cannot search for ssl; missing cross system root (erl_xcomp_sysroot)."
    fi
    for a in ssl crypto ssh; do
        echo "$skip" > $ERL_TOP/lib/$a/SKIP
    done
    ;;
  no-yes | no- )
    # On windows, we could try to find the installation
    # of Shining Light OpenSSL, which can be found by poking in
    # the uninstall section in the registry, it's worth a try...
    extra_dir=""
    if  test "x$MIXED_CYGWIN" = "xyes"; then
    	AC_CHECK_PROG(REGTOOL, regtool, regtool, false)
	if test "$ac_cv_prog_REGTOOL" != false; then
		wrp="/machine/software/microsoft/windows/currentversion/"
	   	if test "x$ac_cv_sizeof_void_p" = "x8"; then
		   urp="uninstall/openssl (64-bit)_is1/inno setup: app path"
		   regtool_subsystem=-w
		else
		   urp="uninstall/openssl (32-bit)_is1/inno setup: app path"
		   regtool_subsystem=-W
		fi	
		rp="$wrp$urp"
		if regtool -q $regtool_subsystem get "$rp" > /dev/null; then
		   true
		else
		   # Fallback to unspecified wordlength
		   urp="uninstall/openssl_is1/inno setup: app path"
		   rp="$wrp$urp"
		fi	
		if regtool -q $regtool_subsystem get "$rp" > /dev/null; then
			ssl_install_dir=`regtool -q $regtool_subsystem get "$rp"`
			# Try hard to get rid of spaces...
			if cygpath -d "$ssl_install_dir" > /dev/null 2>&1; then
				ssl_install_dir=`cygpath -d "$ssl_install_dir"`
			fi
			extra_dir=`cygpath $ssl_install_dir`
		fi
	fi
    elif test "x$MIXED_MSYS" = "xyes"; then
    	AC_CHECK_PROG(REGTOOL, reg_query.sh, reg_query.sh, false)
	if test "$ac_cv_prog_REGTOOL" != false; then
	   	if test "x$ac_cv_sizeof_void_p" = "x8"; then
		   rp="HKLM/SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall/OpenSSL (64-bit)_is1"
		else
		   rp="HKLM/SOFTWARE/Microsoft/Windows/CurrentVersion/Uninstall/OpenSSL_is1"
		fi	
		key="Inno Setup: App Path"
		if "$ac_cv_prog_REGTOOL" "$rp" "$key" > /dev/null; then
			ssl_install_dir=`"$ac_cv_prog_REGTOOL" "$rp" "$key"`
			extra_dir=`win2msys_path.sh "$ssl_install_dir"`
		fi
	fi
    fi
    # We search for OpenSSL in the common OS standard locations.
    SSL_APP=ssl
    CRYPTO_APP=crypto
    SSH_APP=ssh

    SSL_CRYPTO_LIBNAME=crypto
    SSL_SSL_LIBNAME=ssl
    
    if  test "x$MIXED_CYGWIN" = "xyes" -o "x$MIXED_MSYS" = "xyes"; then
    	if test "x$ac_cv_sizeof_void_p" = "x8"; then
	  std_win_ssl_locations="/cygdrive/c/OpenSSL-Win64 /c/OpenSSL-Win64 /opt/local64/pgm/OpenSSL"
	else
	  std_win_ssl_locations="/cygdrive/c/OpenSSL-Win32 /c/OpenSSL-Win32 /cygdrive/c/OpenSSL /c/OpenSSL /opt/local/pgm/OpenSSL"
	fi
    else
        std_win_ssl_locations=""
    fi


    AC_MSG_CHECKING(for OpenSSL >= 0.9.8c in standard locations)
    for rdir in $extra_dir $std_win_ssl_locations $std_ssl_locations; do
	dir="$erl_xcomp_sysroot$rdir"
	if test -f "$erl_xcomp_isysroot$rdir/include/openssl/opensslv.h"; then
		is_real_ssl=yes
		SSL_INCDIR="$dir"
		if test "x$MIXED_CYGWIN" = "xyes" -o "x$MIXED_MSYS" = "xyes"; then
			if test -f "$dir/lib/VC/libeay32.lib"; then
				SSL_RUNTIME_LIBDIR="$rdir/lib/VC"
				SSL_LIBDIR="$dir/lib/VC"
				SSL_CRYPTO_LIBNAME=libeay32
				SSL_SSL_LIBNAME=ssleay32
			elif test -f "$dir/lib/VC/openssl.lib"; then 
				SSL_RUNTIME_LIBDIR="$rdir/lib/VC"
				SSL_LIBDIR="$dir/lib/VC"
			elif test -f $dir/lib/VC/libeay32MD.lib; then
		            SSL_CRYPTO_LIBNAME=libeay32MD
		            SSL_SSL_LIBNAME=ssleay32MD
			    if test "x$enable_dynamic_ssl" = "xno" && \
	                       test -f  $dir/lib/VC/static/libeay32MD.lib; then
				  SSL_RUNTIME_LIBDIR="$rdir/lib/VC/static"
				  SSL_LIBDIR="$dir/lib/VC/static"
		            else
			          SSL_RUNTIME_LIBDIR="$rdir/lib/VC"
				  SSL_LIBDIR="$dir/lib/VC"
                            fi 
			elif test -f "$dir/lib/libeay32.lib"; then
				SSL_RUNTIME_LIBDIR="$rdir/lib"
				SSL_LIBDIR="$dir/lib"
				SSL_CRYPTO_LIBNAME=libeay32
				SSL_SSL_LIBNAME=ssleay32
			elif test -f "$dir/lib/openssl.lib"; then
				SSL_RUNTIME_LIBDIR="$rdir/lib"
				SSL_LIBDIR="$dir/lib"
			else
				is_real_ssl=no
			fi
		elif test -f "$dir/lib/powerpc/libsslcrypto.a"; then
			SSL_CRYPTO_LIBNAME=sslcrypto
			SSL_LIBDIR="$dir/lib/powerpc/"
			SSL_RUNTIME_LIBDIR="$rdir/lib/powerpc/"
		else
			if test "x$ac_cv_sizeof_void_p" = "x8"; then
				if test -f "$dir/lib64/libcrypto.a"; then
					SSL_RUNTIME_LIBDIR="$rdir/lib64"
					SSL_LIBDIR="$dir/lib64"
				elif test -f "$dir/lib/64/libcrypto.a"; then
					SSL_RUNTIME_LIBDIR="$rdir/lib/64"
					SSL_LIBDIR="$dir/lib/64"
				elif test -f "$dir/lib64/libcrypto.so"; then
					SSL_RUNTIME_LIBDIR="$rdir/lib64"
					SSL_LIBDIR="$dir/lib64"
				elif test -f "$dir/lib/64/libcrypto.so"; then
					SSL_RUNTIME_LIBDIR="$rdir/lib/64"
					SSL_LIBDIR="$dir/lib/64"
				else
					SSL_RUNTIME_LIBDIR="$rdir/lib"
					SSL_LIBDIR="$dir/lib"
				fi
			else	 
				SSL_RUNTIME_LIBDIR="$rdir/lib"
				SSL_LIBDIR="$dir/lib"
			fi
		fi
		if test '!' -f "$SSL_LIBDIR/lib${SSL_CRYPTO_LIBNAME}.a"; then
			SSL_DYNAMIC_ONLY=yes
		elif test '!' -f "$SSL_LIBDIR/lib${SSL_CRYPTO_LIBNAME}.so" -a '!' -f "$SSL_LIBDIR/lib${SSL_CRYPTO_LIBNAME}.dylib"; then
			SSL_STATIC_ONLY=yes
		fi
		SSL_BINDIR="$rdir/bin"
		if test "x$is_real_ssl" = "xyes" ; then
			SSL_INCLUDE="-I$dir/include"
			old_CPPFLAGS=$CPPFLAGS
			CPPFLAGS=$SSL_INCLUDE
			AC_EGREP_CPP(^yes$,[
#include <openssl/opensslv.h>
#if OPENSSL_VERSION_NUMBER >= 0x0090803fL
yes
#endif
			],[
			ssl_found=yes
			],[
			SSL_APP=
			ssl_found=no
         		])
         		CPPFLAGS=$old_CPPFLAGS
			if test "x$ssl_found" = "xyes"; then
			   	if test "x$MIXED_CYGWIN" = "xyes" -o "x$MIXED_MSYS" = "xyes"; then
				   	ssl_linkable=yes
				elif test "x${SSL_CRYPTO_LIBNAME}" = "xsslcrypto"; then
				# This should only be triggered seen OSE
					ssl_linkable=yes
				else
					saveCFLAGS="$CFLAGS"
 					saveLDFLAGS="$LDFLAGS"
					saveLIBS="$LIBS"
 					CFLAGS="$CFLAGS $SSL_INCLUDE"
					if test "x$SSL_STATIC_ONLY" = "xyes"; then
						LIBS="${SSL_LIBDIR}/lib${SSL_CRYPTO_LIBNAME}.a"
					else
						LDFLAGS="$LDFLAGS -L$SSL_LIBDIR"
						LIBS="$LIBS -l${SSL_CRYPTO_LIBNAME}"
					fi
 					AC_TRY_LINK([
					#include <stdio.h>
 					#include <openssl/hmac.h>],
 					[ 
					HMAC(0, 0, 0, 0, 0, 0, 0);
 					],
 					[ssl_linkable=yes],
 					[ssl_linkable=no])
 					CFLAGS="$saveCFLAGS"
 					LDFLAGS="$saveLDFLAGS"
					LIBS="$saveLIBS"
				fi
 			fi
	 		if test "x$ssl_found" = "xyes" && test "x$ssl_linkable" = "xyes"; then
			 	AC_MSG_RESULT([$dir])
	   			break;
         		fi
		fi	
       fi
    done

    if test "x$ssl_found" != "xyes" ; then
	dnl 
	dnl If no SSL found above, check whether we are running on OpenBSD.
	dnl
	case $host_os in
	openbsd*)
	       if test -f "$erl_xcomp_isysroot/usr/include/openssl/opensslv.h"; then
		  # Trust OpenBSD to have everything the in the correct locations.
		  ssl_found=yes
		  ssl_linkable=yes
		  SSL_INCDIR="$erl_xcomp_sysroot/usr"
	          AC_MSG_RESULT([$SSL_INCDIR])
		  SSL_RUNTIME_LIB="/usr/lib"
		  SSL_LIB="$erl_xcomp_sysroot/usr/lib"
		  SSL_BINDIR="/usr/sbin"
		  dnl OpenBSD requires us to link with -L and -l
		  SSL_DYNAMIC_ONLY="yes" 
		fi
		;;
	esac
    fi
dnl		Now, certain linuxes have a 64bit libcrypto
dnl		that cannot build shared libraries (i.e. not PIC)
dnl		One could argue that this is wrong, but
dnl		so it is - be adoptable
    if test "$ssl_found" = "yes" && test "$ssl_linkable" = "yes" && test "$SSL_DYNAMIC_ONLY" != "yes"; then
	case $host_os in
		linux*)
			saveCFLAGS="$CFLAGS"
 			saveLDFLAGS="$LDFLAGS"
			saveLIBS="$LIBS"
 			CFLAGS="$DED_CFLAGS $SSL_INCLUDE"
 			LDFLAGS="$DED_LDFLAGS"
			LIBS="$SSL_LIBDIR/libcrypto.a $STATIC_ZLIB_LIBS"
 			AC_TRY_LINK([
			#include <stdio.h>
 			#include <openssl/hmac.h>],
 			[ 
			HMAC(0, 0, 0, 0, 0, 0, 0);
 			],
 			[ssl_dyn_linkable=yes],
 			[ssl_dyn_linkable=no])
 			CFLAGS="$saveCFLAGS"
 			LDFLAGS="$saveLDFLAGS"
			LIBS="$saveLIBS"
			if test "x$ssl_dyn_linkable" != "xyes"; then
				SSL_DYNAMIC_ONLY=yes
				AC_MSG_WARN([SSL will be linked against dynamic lib as static lib is not purely relocatable])
			fi
			;;
	esac
    fi					
	
				


    if test "x$ssl_found" != "xyes" || test  "x$ssl_linkable" != "xyes"; then
       if test "x$ssl_found" = "xyes"; then 
       		AC_MSG_RESULT([found; but not usable])
       else
       		AC_MSG_RESULT([no])
       fi
       SSL_APP=
       CRYPTO_APP=
       SSH_APP=
       AC_MSG_WARN([No (usable) OpenSSL found, skipping ssl, ssh and crypto applications])

       for a in ssl crypto ssh; do
           echo "No usable OpenSSL found" > $ERL_TOP/lib/$a/SKIP
       done
    fi
    ;;
  *)
    # Option given with PATH to package
    if test ! -d "$with_ssl" ; then
       AC_MSG_ERROR(Invalid path to option --with-ssl=PATH)
    fi
    if test ! -d "$with_ssl_incl" ; then
       AC_MSG_ERROR(Invalid path to option --with-ssl-incl=PATH)
    fi
    SSL_INCDIR="$with_ssl_incl"
    SSL_CRYPTO_LIBNAME=crypto
    SSL_SSL_LIBNAME=ssl
    if test "x$MIXED_CYGWIN" = "xyes" -o "x$MIXED_MSYS" = "xyes" && test -d "$with_ssl/lib/VC"; then
	if test -f "$with_ssl/lib/VC/libeay32.lib"; then
	    SSL_LIBDIR="$with_ssl/lib/VC"
	    SSL_CRYPTO_LIBNAME=libeay32
	    SSL_SSL_LIBNAME=ssleay32
	elif test -f "$with_ssl/lib/VC/openssl.lib"; then 
	    SSL_LIBDIR="$with_ssl/lib/VC"
	elif test -f $with_ssl/lib/VC/libeay32MD.lib; then
	    SSL_CRYPTO_LIBNAME=libeay32MD
            SSL_SSL_LIBNAME=ssleay32MD
	    if test "x$enable_dynamic_ssl" = "xno" && \
	       test -f  $with_ssl/lib/VC/static/libeay32MD.lib; then
		SSL_LIBDIR="$with_ssl/lib/VC/static"
	    else
		SSL_LIBDIR="$with_ssl/lib/VC"
            fi 
	elif test -f "$with_ssl/lib/libeay32.lib"; then
	    SSL_LIBDIR="$with_ssl/lib"
	    SSL_CRYPTO_LIBNAME=libeay32
	    SSL_SSL_LIBNAME=ssleay32
	else
	    # This probably wont work, but that's what the user said, so...
	    SSL_LIBDIR="$with_ssl/lib"
	fi
    elif test -f "$dir/lib/powerpc/libsslcrypto.a"; then
	    SSL_CRYPTO_LIBNAME=sslcrypto
	    SSL_LIBDIR="$with_ssl/lib/powerpc/"
    elif test "x$ac_cv_sizeof_void_p" = "x8"; then
	if test -f "$with_ssl/lib64/libcrypto.a"; then
		SSL_LIBDIR="$with_ssl/lib64"
	elif test -f "$with_ssl/lib/64/libcrypto.a"; then
		SSL_LIBDIR="$with_ssl/lib/64"
	elif test -f "$with_ssl/lib64/libcrypto.so"; then
		SSL_LIBDIR="$with_ssl/lib64"
	elif test -f "$with_ssl/lib/64/libcrypto.so"; then
		SSL_LIBDIR="$with_ssl/lib/64"
	else
		SSL_LIBDIR="$with_ssl/lib"
	fi
    else	 
	SSL_LIBDIR="$with_ssl/lib"
    fi
    if test '!' -f "${SSL_LIBDIR}/lib${SSL_CRYPTO_LIBNAME}.a"; then
	SSL_DYNAMIC_ONLY=yes
    elif test '!' -f ${SSL_LIBDIR}/lib${SSL_CRYPTO_LIBNAME}.so -a '!' -f "$SSL_LIBDIR/lib${SSL_CRYPTO_LIBNAME}.dylib"; then
	SSL_STATIC_ONLY=yes
    fi
    SSL_INCLUDE="-I$with_ssl_incl/include"
    SSL_APP=ssl
    CRYPTO_APP=crypto
    SSH_APP=ssh
    if test "$cross_compiling" = "yes"; then
	SSL_RUNTIME_LIBDIR=`echo "$SSL_LIBDIR" | sed -n "s|^$erl_xcomp_sysroot\(/*\)\(.*\)\$|/\2|p"`
    else
	SSL_RUNTIME_LIBDIR="$SSL_LIBDIR"
    fi
esac

if test "x$SSL_APP" != "x" ; then
    dnl We found openssl, now check if we use kerberos 5 support
    dnl FIXME: Do we still support platforms that have Kerberos?
    AC_MSG_CHECKING(for OpenSSL kerberos 5 support)
    old_CPPFLAGS=$CPPFLAGS
    CPPFLAGS=$SSL_INCLUDE
    AC_EGREP_CPP(^yes$,[
#include <openssl/opensslv.h>
#include <openssl/opensslconf.h>
#if OPENSSL_VERSION_NUMBER < 0x1010000fL && !defined(OPENSSL_NO_KRB5)
yes
#endif
      ],[
      AC_MSG_RESULT([yes])
      ssl_krb5_enabled=yes
      if test "x$SSL_DYNAMIC_ONLY" != "xyes"; then
          if test -f "$SSL_LIBDIR/libkrb5.a"; then
              SSL_LINK_WITH_KERBEROS=yes
	      STATIC_KERBEROS_LIBS="$SSL_LIBDIR/libkrb5.a"
	      if test -f "$SSL_LIBDIR/libkrb5support.a"; then
		  STATIC_KERBEROS_LIBS="$STATIC_KERBEROS_LIBS $SSL_LIBDIR/libkrb5support.a"
	      fi
	      if test -f "$SSL_LIBDIR/libk5crypto.a"; then
		  STATIC_KERBEROS_LIBS="$STATIC_KERBEROS_LIBS $SSL_LIBDIR/libk5crypto.a"
	      fi
	      if test -f "$SSL_LIBDIR/libresolv.a"; then
		  STATIC_KERBEROS_LIBS="$STATIC_KERBEROS_LIBS $SSL_LIBDIR/libresolv.a"
	      fi
	      if test -f "$SSL_LIBDIR/libcom_err.a"; then
		  STATIC_KERBEROS_LIBS="$STATIC_KERBEROS_LIBS $SSL_LIBDIR/libcom_err.a"
	      fi
          else
	      AC_MSG_WARN([Kerberos needed but no kerberos static libraries found])
	      AC_MSG_WARN([Rescanning for dynamic SSL libraries])
	      enable_dynamic_ssl=yes
	      ssl_done=no
	      SSL_LINK_WITH_KERBEROS=no
	      STATIC_KERBEROS_LIBS=""
	      ssl_krb5_enabled=no
	      SSL_WITH_KERBEROS=no
          fi
      else 	
	      SSL_LINK_WITH_KERBEROS=no
	      STATIC_KERBEROS_LIBS=""
      fi
      ],[
      AC_MSG_RESULT([no])
      ssl_krb5_enabled=no
      SSL_WITH_KERBEROS=no
      ])
    CPPFLAGS=$old_CPPFLAGS
    SSL_KRB5_INCLUDE=
    if test "x$ssl_krb5_enabled" = "xyes" ; then
        AC_MSG_CHECKING(for krb5.h in standard locations)
	for dir in $extra_dir "$SSL_INCDIR/include" "$SSL_INCDIR/include/openssl" \
		"$SSL_INCDIR/include/kerberos" \
		"$erl_xcomp_isysroot/cygdrive/c/kerberos/include" \
		"$erl_xcomp_isysroot/usr/local/kerberos/include" \
		"$erl_xcomp_isysroot/usr/kerberos/include" \
		"$erl_xcomp_isysroot/usr/include"
	do
            if test -f "$dir/krb5.h" ; then
                SSL_KRB5_INCLUDE="$dir"
		break
            fi
        done
        if test "x$SSL_KRB5_INCLUDE" = "x" ; then
	    AC_MSG_RESULT([not found])
	    SSL_APP=
	    CRYPTO_APP=
	    SSH_APP=
	    AC_MSG_WARN([OpenSSL is configured for kerberos but no krb5.h found])
	    for a in ssl crypto ssh ; do
	 	echo "OpenSSL is configured for kerberos but no krb5.h found" > $ERL_TOP/lib/$a/SKIP
	    done
        else
            AC_MSG_RESULT([found in $SSL_KRB5_INCLUDE])
            SSL_INCLUDE="$SSL_INCLUDE -I$SSL_KRB5_INCLUDE"
        fi
    fi
fi

done # while test ssl_done != yes

SSL_DED_LD_RUNTIME_LIBRARY_PATH=
ded_ld_rflg="$DED_LD_FLAG_RUNTIME_LIBRARY_PATH"


case "$with_ssl_rpath" in

yes)   # Use standard lib locations for ssl runtime library path

  if test "$SSL_APP" != "" && test "$SSL_DYNAMIC_ONLY" = "yes" && test "$ded_ld_rflg" != ""; then

    AC_MSG_CHECKING(for ssl runtime library path to use)

    libdirs="/lib"

    if test "$ac_cv_sizeof_void_p" = "8"; then
	dir_lib64=no
	dir_lib_64=no

	case "$SSL_RUNTIME_LIBDIR" in
	    */lib/64 | */lib/64/ ) dir_lib_64=yes;;
	    */lib64 | */lib64/ ) dir_lib64=yes;;
	    *) ;;
	esac

	for dir in $std_ssl_locations; do
	    test $dir_lib_64 = no &&
	    	test -d "$erl_xcomp_sysroot$dir/lib/64" &&
		    dir_lib_64=yes
	    test $dir_lib64 = no &&
		test -d "$erl_xcomp_sysroot$dir/lib64" &&
		    dir_lib64=yes
	done

	test $dir_lib_64 = yes && libdirs="/lib/64 $libdirs"
	test $dir_lib64 = yes && libdirs="/lib64 $libdirs"
    fi

    for type in std x_std curr; do

        ded_ld_rpath="$ded_ld_rflg$SSL_RUNTIME_LIBDIR"
	rpath="$SSL_RUNTIME_LIBDIR"

	if test $type != curr; then
	    for ldir in $libdirs; do
		for dir in $std_ssl_locations; do
		    test "$SSL_LIBDIR" != "$dir$ldir" || continue
		    test $type != x_std || test -d "$dir$ldir" || continue
		    if test "$dir" = "/"; then
			libdir="$ldir"
		    else
			libdir="$dir$ldir"
		    fi
		    ded_ld_rpath="$ded_ld_rpath $ded_ld_rflg$libdir"
		    rpath="$rpath:$libdir"
                done
	    done
	fi

	saveCFLAGS="$CFLAGS"
	saveLDFLAGS="$LDFLAGS"
	saveLIBS="$LIBS"
	CFLAGS="$CFLAGS $SSL_INCLUDE"
	LDFLAGS="$LDFLAGS $ld_rpath -L$SSL_LIBDIR"
	LIBS="-lcrypto"
	AC_TRY_LINK([
                         #include <stdio.h>
                         #include <openssl/hmac.h>
                    ],
                    [ 
			 HMAC(0, 0, 0, 0, 0, 0, 0);
                    ],
                    [rpath_success=yes],
                    [rpath_success=no])
	CFLAGS="$saveCFLAGS"
	LDFLAGS="$saveLDFLAGS"
	LIBS="$saveLIBS"

	test "$rpath_success" = "yes" && break
    done

    test "$rpath_success" = "yes" || { ded_ld_rpath=; rpath=; }

    SSL_DED_LD_RUNTIME_LIBRARY_PATH="$ded_ld_rpath"

    AC_MSG_RESULT([$rpath])
    test "$rpath" != "" || AC_MSG_WARN([Cannot set run path during linking])
  fi
  ;;

no)   # Use no ssl runtime library path
  SSL_DED_LD_RUNTIME_LIBRARY_PATH=
  ;;

*)    # Use ssl runtime library paths set by --with-ssl-rpath (without any check)
  ded_ld_rpath=
  delimit=
  for dir in `echo $with_ssl_rpath | sed "s/,/ /g"`; do
      ded_ld_rpath="$ded_ld_rpath$delimit$ded_ld_rflg$dir"
      delimit=" "
  done
  SSL_DED_LD_RUNTIME_LIBRARY_PATH="$ded_ld_rpath"
  ;;

esac


AC_ARG_ENABLE(fips,
AS_HELP_STRING([--enable-fips], [enable OpenSSL FIPS mode support])
AS_HELP_STRING([--disable-fips], [disable OpenSSL FIPS mode support (default)]),
[ case "$enableval" in
    yes) enable_fips_support=yes ;;
    *)   enable_fips_support=no ;;
  esac ], enable_fips_support=no)

if test "x$enable_fips_support" = "xyes" && test "$CRYPTO_APP" != ""; then
   saveCFLAGS="$CFLAGS"
   saveLDFLAGS="$LDFLAGS"
   saveLIBS="$LIBS"
   CFLAGS="$CFLAGS $SSL_INCLUDE"
   LDFLAGS="$LDFLAGS $ded_ld_rpath -L$SSL_LIBDIR"
   LIBS="-lcrypto"
   AC_CHECK_FUNC([FIPS_mode_set],
   [SSL_FLAGS="-DFIPS_SUPPORT"],
   [SSL_FLAGS=])
   CFLAGS="$saveCFLAGS"
   LDFLAGS="$saveLDFLAGS"
   LIBS="$saveLIBS"
else
   SSL_FLAGS=
fi

AC_SUBST(SSL_INCLUDE)
AC_SUBST(SSL_INCDIR)
AC_SUBST(SSL_LIBDIR)
AC_SUBST(SSL_FLAGS)
AC_SUBST(SSL_CRYPTO_LIBNAME)
AC_SUBST(SSL_SSL_LIBNAME)
AC_SUBST(SSL_DED_LD_RUNTIME_LIBRARY_PATH)
AC_SUBST(SSL_DYNAMIC_ONLY)
AC_SUBST(SSL_LINK_WITH_KERBEROS)
AC_SUBST(STATIC_KERBEROS_LIBS)
AC_SUBST(SSL_LINK_WITH_ZLIB)
AC_SUBST(STATIC_ZLIB_LIBS)

AC_OUTPUT(c_src/$host/Makefile:c_src/Makefile.in)