$NetBSD: patch-Configure,v 1.7 2018/10/29 14:25:25 sevan Exp $

* Use "uname -r" to get OS version for *BSD.
* Move $loclibpth to the end of $dlist, instead of the beginning.
* Detect systems which have <fenv.h> but where using it fails.
* Honor more ldflags in shared objects.
* Add Minix
* Several other changes.

--- Configure.orig	Mon May 21 12:29:23 2018
+++ Configure	Mon Oct 29 01:18:22 2018
@@ -3471,13 +3471,14 @@
 			osvers="$3"
 			;;
 		dragonfly) osname=dragonfly
-			osvers="$3"
+			osvers=`$uname -r | UU/tr '[A-Z]' '[a-z]'`
 			;;
 		dynixptx*) osname=dynixptx
 			osvers=`echo "$4"|sed 's/^v//'`
 			;;
 		freebsd) osname=freebsd
-			osvers="$3" ;;
+			osvers=`$uname -r | UU/tr '[A-Z]' '[a-z]'`
+			;;
 		genix)	osname=genix ;;
 		gnu)	osname=gnu
 			osvers="$3" ;;
@@ -3499,8 +3500,11 @@
 			;;
 		MiNT)	osname=mint
 			;;
+		minix*) osname=minix
+			osvers=`$uname -r`
+			;;
 		netbsd*) osname=netbsd
-			osvers="$3"
+			osvers=`$uname -r | UU/tr '[A-Z]' '[a-z]'`
 			;;
 		news-os) osvers="$3"
 			case "$3" in
@@ -3510,7 +3514,7 @@
 			;;
 		nonstop-ux) osname=nonstopux ;;
 		openbsd) osname=openbsd
-			osvers="$3"
+			osvers=`$uname -r | UU/tr '[A-Z]' '[a-z]'`
 			;;
 		os2)	osname=os2
 			osvers="$4"
@@ -3525,6 +3529,9 @@
 		qnx) osname=qnx
 			osvers="$4"
 			;;
+		sco_sv) osname=sco_sv
+			osvers=`$uname -r`v`$uname -v`
+			;;
 		solaris) osname=solaris
 			case "$3" in
 			5*) osvers=`echo $3 | $sed 's/^5/2/g'` ;;
@@ -4963,7 +4970,7 @@
 # If using gcc or clang, we can get better values for libpth, incpth
 # and usrinc directly from the compiler.
 # Note that ccname for clang is also gcc.
-case "$ccname" in
+case "xx$ccname" in
     gcc)
 	$echo 'extern int foo;' > try.c
 	set X `$cppstdin -v try.c 2>&1 | $awk '/^#include </,/^End of search /'|$cppfilter $grep '/include'`
@@ -5039,14 +5046,14 @@
 esac
 case "$libpth" in
 ' ') dlist='';;
-'') dlist="$loclibpth $plibpth $glibpth";;
+'') dlist="$plibpth $glibpth $loclibpth";;
 *) dlist="$libpth";;
 esac
 
 : Now check and see which directories actually exist, avoiding duplicates
 for xxx in $dlist
 do
-    if $test -d $xxx; then
+    if $test -d $xxx -o "$xxx" = "$prefix/lib"; then
 		case " $libpth " in
 		*" $xxx "*) ;;
 		*) libpth="$libpth $xxx";;
@@ -5162,7 +5169,7 @@
 obj_ext=$_o
 path_sep=$p_
 
-rm_try="$rm -f try try$_exe a.out .out try.[cho] try.$_o core core.try* try.core*"
+rm_try="@TOOLS_RM@ -f try try$_exe a.out .out try.[cho] try.$_o core core.try* try.core*"
 
 : Which makefile gets called first.  This is used by make depend.
 case "$firstmakefile" in
@@ -5493,7 +5500,7 @@
 	# thing. (NWC)
 	case "$osname" in
 	amigaos) ;; # -fstack-protector builds but doesn't work
-	*)	case "$gccversion" in
+	nothing) case "$gccversion" in
 		?*)	set stack-protector-strong -fstack-protector-strong
 			eval $checkccflag
 			case "$dflt" in
@@ -6477,6 +6484,15 @@
 	;;
 esac
 
+: Mac OS X 10.7 is different
+case "$osname" in
+    darwin)
+	case "$osvers" in
+	    11.*)
+		libnames="$libnames /usr/lib/system/libsystem_*.dylib"
+	esac
+esac
+
 : Figure out where the libc is located
 case "$runnm" in
 true)
@@ -7604,7 +7620,9 @@
 . ./getfile
 prefixvar=sitelib
 . ./setprefixvar
-sitelib_stem=`echo "$sitelibexp" | sed "s,/$version$,,"`
+if $test -z "$sitelib_stem"; then
+	sitelib_stem=`echo "$sitelibexp" | sed "s,/$version$,,"`
+fi
 
 : Determine list of previous versions to include in @INC
 $cat > getverlist <<EOPL
@@ -8015,7 +8033,9 @@
 	vendorlibexp="$ansexp"
 	;;
 esac
-vendorlib_stem=`echo "$vendorlibexp" | sed "s,/$version$,,"`
+if $test -z "$vendorlib_stem"; then
+	vendorlib_stem=`echo "$vendorlibexp" | sed "s,/$version$,,"`
+fi
 prefixvar=vendorlib
 . ./installprefix
 
@@ -8511,6 +8531,7 @@
 			  esac
 			  ;;
 		    *linux*|irix*|gnu*)  dflt="-shared $optimize" ;;
+		    sco_sv) dflt='-shared' ;;
 		    solaris) # See [perl #66604].
 			    # On Solaris 11, gcc -m64 on amd64
 			    # appears not to understand -G.  gcc versions at
@@ -8550,7 +8571,7 @@
 	esac
 	for thisflag in $ldflags; do
 	    case "$thisflag" in
-		-L*|-R*|-Wl,-R*)
+		-L*|-R*|-Wl,-R*|-Wl,-z*)
 		    case " $dflt " in
 			*" $thisflag "*) ;;
 			*) dflt="$dflt $thisflag" ;;
@@ -8803,12 +8824,16 @@
 	solaris)
 		xxx="-R $shrpdir"
 		;;
-	freebsd|mirbsd|netbsd|openbsd|interix|dragonfly|bitrig)
+	freebsd|minix|mirbsd|netbsd|openbsd|interix|dragonfly|bitrig)
 		xxx="-Wl,-R$shrpdir"
 		;;
 	bsdos|linux|irix*|dec_osf|gnu*|haiku)
 		xxx="-Wl,-rpath,$shrpdir"
 		;;
+	haiku)
+		# Haiku doesn't like the default, either.
+		xxx="-Wl,-rpath,$shrpdir"
+		;;
 	hpux*)
 		# hpux doesn't like the default, either.
 		tmp_shrpenv="env LDOPTS=\"+s +b${shrpdir}\""
@@ -8816,6 +8841,9 @@
 	cygwin)
 		# cygwin needs only ldlibpth
 		;;
+	sco_sv)
+		xxx="-Wl,-R$shrpdir"
+		;;
 	*)
 		tmp_shrpenv="env LD_RUN_PATH=$shrpdir"
 		;;
@@ -9896,6 +9924,13 @@
 : Check if we want perlio
 useperlio="$define"
 
+: Look for a hint-file generated 'call-back-unit'.  We need
+: to set some defaults for building perl in pkgsrc.
+if $test -f pkgsrc.cbu; then
+	echo "Setting pkgsrc-specific hints regarding compiler/linker flags..."
+	. ./pkgsrc.cbu
+fi
+
 : Set the vendorbin variables
 case "$vendorprefix" in
 '')	d_vendorbin="$undef"
@@ -19825,7 +19860,15 @@
 ACAT(Cir,cus)
 EOCP
 $cppstdin $cppflags $cppminus <cpp_stuff.c >cpp_stuff.out 2>&1
-if $contains 'Circus' cpp_stuff.out >/dev/null 2>&1; then
+# yuck, what a hack.
+# MIPSPro compiler/preprocessor behaves differently if invoked on
+# stdin vs file.  Here we test for stdin, but lateron we use files.
+# So force it to work the way we know it does:
+if [ x"${OPSYS}" = x"IRIX" ]; then
+	echo "Hacking MIPSPro on file vs. stdin..." >&4
+	echo "We know we can catify or stringify, separately or together!"
+	cpp_stuff=42
+elif $contains 'Circus' cpp_stuff.out >/dev/null 2>&1; then
 	echo "Oh!  Smells like ANSI's been here." >&4
 	echo "We can catify or stringify, separately or together!"
 	cpp_stuff=42
@@ -22641,6 +22684,21 @@
 set fenv.h i_fenv
 eval $inhdr
 
+: And really validate that it is OK to include it
+: On NetBSD 6.x non-amd64 non-i386 and non-sparc this fails
+cat > try.c <<EOCP
+#include <fenv.h>
+int main() {
+	printf("runs ok too\n");
+	exit(0);
+}
+EOCP
+set try
+if ! eval $compile_ok; then
+	echo "<fenv.h> found to be unusable, disabling" >&4
+	i_fenv=$undef
+fi
+
 : see if this is a fp.h system
 set fp.h i_fp
 eval $inhdr
@@ -25015,4 +25073,3 @@
 $rm -rf UU
 
 : End of Configure
-
