$NetBSD: patch-at,v 1.28 2012/06/24 08:27:31 sbd Exp $

. Include CFLAGS in bytecccompopts and LDFLAGS in bytecclinkopts.
. Add cases for dragonfly support.
. Use the portable `test x = y', not `test x == y' GNUism.
. Enable native dynamic loading on NetBSD/i386 and NetBSD/amd64.
. Fix pattern to match Solaris versions.
. Add cases for interix support.
. Add cases for NetBSD/arm support.
. Update Darwin patterns to match versions >=10.
. Enable profiling support on BSD/powerpc.
. Skip X11 library and header file checks when X11 support is disabled.
. Frobnicate dbm detection.
. Enable suport for x86_64-DragonFly
. Enable profiling and native dynamic loading for all DragonFly platforms
. Add pkgsrc X11 checks in case X11 support is enabled in the future
. When linking with X11 add an rpath to X11 libdir.
. Fix SunOS linker and as args
. On Linux libieee can only appear once on the linker command line.

--- configure.orig	2011-07-04 21:15:01.000000000 +0000
+++ configure
@@ -328,6 +328,8 @@ case "$bytecc,$host" in
   gcc*)
     bytecccompopts="-fno-defer-pop $gcc_warnings";;
 esac
+bytecccompopts="$bytecccompopts $CFLAGS"
+bytecclinkopts="$bytecclinkopts $LDFLAGS"
 
 # Configure compiler to use in further tests
 
@@ -521,7 +523,7 @@ if test $withsharedlibs = "yes"; then
       mksharedlib="$flexlink"
       mkmaindll="$flexlink -maindll"
       shared_libraries_supported=true;;
-    *-*-linux-gnu|*-*-linux|*-*-freebsd[3-9]*|*-*-openbsd*|*-*-netbsd*|*-*-gnu*)
+    *-*-linux-gnu|*-*-linux|*-*-freebsd[3-9]*|*-*-openbsd*|*-*-netbsd*|*-*-gnu*|*-*-dragonfly)
       sharedcccompopts="-fPIC"
       mksharedlib="$bytecc -shared"
       bytecclinkopts="$bytecclinkopts -Wl,-E"
@@ -621,7 +623,7 @@ if test $withsharedlibs = "yes"; then
     i[3456]86-*-linux*)           natdynlink=true;;
     x86_64-*-linux*)              natdynlink=true;;
     i[3456]86-*-darwin10.*)
-      if test $arch64 == true; then
+      if test $arch64 = true; then
         natdynlink=true
       fi;;
     i[3456]86-*-darwin[89]*)      natdynlink=true;;
@@ -635,6 +637,8 @@ if test $withsharedlibs = "yes"; then
     x86_64-*-openbsd*)            natdynlink=true;;
     i[345]86-*-netbsd*)           natdynlink=true;;
     x86_64-*-netbsd*)             natdynlink=true;;
+    i[3456]86-*-dragonfly)        natdynlink=true;;
+    x86_64-*-dragonfly)           natdynlink=true;;
     i386-*-gnu0.3)                natdynlink=true;;
   esac
 fi
@@ -660,12 +664,13 @@ case "$host" in
   alpha*-*-netbsd*)             arch=alpha; system=netbsd;;
   alpha*-*-openbsd*)            arch=alpha; system=openbsd;;
   sparc*-*-sunos4.*)            arch=sparc; system=sunos;;
-  sparc*-*-solaris2.*)          arch=sparc; system=solaris;;
+  sparc*-*-solaris2*)           arch=sparc; system=solaris;;
   sparc*-*-*bsd*)               arch=sparc; system=bsd;;
   sparc*-*-linux*)              arch=sparc; system=linux;;
   sparc*-*-gnu*)                arch=sparc; system=gnu;;
   i[3456]86-*-linux*)           arch=i386; system=linux_`sh ./runtest elf.c`;;
   i[3456]86-*-*bsd*)            arch=i386; system=bsd_`sh ./runtest elf.c`;;
+  i[3456]86-*-dragonfly*)       arch=i386; system=bsd_`sh ./runtest elf.c`;;
   i[3456]86-*-nextstep*)        arch=i386; system=nextstep;;
   i[3456]86-*-solaris*)         if $arch64; then
                                   arch=amd64; system=solaris
@@ -674,6 +679,7 @@ case "$host" in
                                 fi;;
   i[3456]86-*-beos*)            arch=i386; system=beos;;
   i[3456]86-*-cygwin*)          arch=i386; system=cygwin;;
+  i[3456]86-*-interix3*)        arch=i386; system=interix3;;
   i[3456]86-*-darwin*)          if $arch64; then
                                   arch=amd64; system=macosx
                                 else
@@ -690,17 +696,21 @@ case "$host" in
   powerpc-*-rhapsody*)          arch=power; model=ppc; system=rhapsody;;
   powerpc-*-darwin*)            arch=power; system=rhapsody
                                 if $arch64; then model=ppc64; else model=ppc; fi;;
+  arm*-*-netbsd*)               arch=arm; system=netbsd;;
   arm*-*-linux*)                arch=arm; system=linux;;
   arm*-*-gnu*)                  arch=arm; system=gnu;;
   ia64-*-linux*)                arch=ia64; system=linux;;
   ia64-*-gnu*)                  arch=ia64; system=gnu;;
   ia64-*-freebsd*)              arch=ia64; system=freebsd;;
+  x86_64-*-dragonfly*)          arch=amd64; system=dragonfly;;
   x86_64-*-linux*)              arch=amd64; system=linux;;
   x86_64-*-gnu*)                arch=amd64; system=gnu;;
   x86_64-*-freebsd*)            arch=amd64; system=freebsd;;
   x86_64-*-netbsd*)             arch=amd64; system=netbsd;;
   x86_64-*-openbsd*)            arch=amd64; system=openbsd;;
+  x86_64-*-solaris*)            arch=amd64; system=solaris;;
   x86_64-*-darwin9.5)           arch=amd64; system=macosx;;
+  x86_64-*-darwin1[0-9]*)       arch=amd64; system=macosx;;
 esac
 
 # Some platforms exist both in 32-bit and 64-bit variants, not distinguished
@@ -740,7 +750,7 @@ case "$arch,$nativecc,$system,$host_type
                        if $arch64; then partialld="ld -r -arch ppc64"; fi;;
   *,gcc*,cygwin,*)     nativecccompopts="$gcc_warnings -U_WIN32";;
   amd64,gcc*,macosx,*) partialld="ld -r -arch x86_64";;
-  amd64,gcc*,solaris,*) partialld="ld -r -m elf_x86_64";;
+  amd64,gcc*,solaris,*) partialld="ld -r -64";;
   *,gcc*,*,*)          nativecccompopts="$gcc_warnings";;
 esac
 
@@ -763,7 +773,7 @@ case "$arch,$model,$system" in
   hppa,*,*)         as='as';
                     aspp='gcc -traditional -c';;
   i386,*,solaris)   as='as'
-                    aspp='/usr/ccs/bin/as -P';;
+                    aspp='gcc -traditional -c';;
   i386,*,*)         as='as'
                     aspp='gcc -c';;
   ia64,*,*)         as='as -xexplicit'
@@ -801,6 +811,8 @@ case "$arch,$model,$system" in
     case "$nativecc" in gcc*) ;; *) cc_profile='-xpg';; esac;;
   amd64,*,linux) profiling='prof';;
   amd64,*,gnu) profiling='prof';;
+  power,*,bsd) profiling='prof';;
+  *,*,dragonfly) profiling='prof';;
   *) profiling='noprof';;
 esac
 
@@ -1205,6 +1217,8 @@ if test "$pthread_wanted" = "yes"; then
                    pthread_caml_link="-cclib -lpthread -cclib -lposix4";;
     *-*-freebsd*)  pthread_link="-pthread"
                    pthread_caml_link="-cclib -pthread";;
+    *-*-dragonfly*) pthread_link="-pthread"
+                   pthread_caml_link="-cclib -pthread";;
     *-*-openbsd*)  pthread_link="-pthread"
                    pthread_caml_link="-cclib -pthread";;
     *)             pthread_link="-lpthread"
@@ -1256,6 +1270,7 @@ fi
 x11_include="not found"
 x11_link="not found"
 
+if test "$disable_x11" != "yes"; then
 for dir in \
     $x11_include_dir          \
                               \
@@ -1294,6 +1309,7 @@ for dir in \
     /usr/XFree86/include/X11  \
                               \
     /usr/include              \
+    /usr/pkg/include          \
     /usr/local/include        \
     /usr/unsupported/include  \
     /usr/athena/include       \
@@ -1308,6 +1324,7 @@ do
     break
   fi
 done
+fi
 
 if test "$x11_include" = "not found"; then
   x11_try_lib_dir=''
@@ -1350,6 +1367,7 @@ for dir in \
                           \
     /usr/lib64            \
     /usr/lib              \
+    /usr/pkg/lib/         \
     /usr/local/lib        \
     /usr/unsupported/lib  \
     /usr/athena/lib       \
@@ -1368,11 +1386,8 @@ do
     if test $dir = /usr/lib; then
       x11_link="-lX11"
     else
-      x11_libs="-L$dir"
-      case "$host" in
-        *-*-*bsd*) x11_link="-R$dir -L$dir -lX11";;
-        *) x11_link="-L$dir -lX11";;
-      esac
+      x11_libs="-L$dir ${COMPILER_RPATH_FLAG}$dir"
+      x11_link="-L$dir ${COMPILER_RPATH_FLAG}$dir -lX11"
     fi
     break
   fi
@@ -1402,31 +1417,8 @@ dbm_include="not found"
 dbm_link="not found"
 use_gdbm_ndbm=no
 
-for dir in /usr/include /usr/include/db1 /usr/include/gdbm; do
-  if test -f $dir/ndbm.h; then
-    dbm_include=$dir
-    if sh ./hasgot dbm_open; then
-      dbm_link=""
-    elif sh ./hasgot -lndbm dbm_open; then
-      dbm_link="-lndbm"
-    elif sh ./hasgot -ldb1 dbm_open; then
-      dbm_link="-ldb1"
-    elif sh ./hasgot -lgdbm dbm_open; then
-      dbm_link="-lgdbm"
-    elif sh ./hasgot -lgdbm_compat -lgdbm dbm_open; then
-      dbm_link="-lgdbm_compat -lgdbm"
-    fi
-    break
-  fi
-  if test -f $dir/gdbm-ndbm.h; then
-    dbm_include=$dir
-    use_gdbm_ndbm=yes
-    if sh ./hasgot -lgdbm_compat -lgdbm dbm_open; then
-      dbm_link="-lgdbm_compat -lgdbm"
-    fi
-    break
-  fi
-done
+dbm_include=/usr/include
+dbm_link=${BDB_LIBS}
 if test "$dbm_include" = "not found" || test "$dbm_link" = "not found"; then
   echo "NDBM not found, the \"dbm\" library will not be supported."
 else
@@ -1436,8 +1428,8 @@ else
   else
     dbm_include="-I$dbm_include"
   fi
-  if test "$use_gdbm_ndbm" = "yes"; then
-    echo "#define DBM_USES_GDBM_NDBM" >> s.h
+  if test ${BDB_BUILTIN} = "yes"; then
+    echo "#define DBM_USES_DB" >> s.h
   fi
   otherlibraries="$otherlibraries dbm"
 fi
@@ -1500,6 +1492,9 @@ if test $has_tk = true; then
   fi
 fi
 
+case "$host" in
+  *-*-linux*) tk_libs=`echo $tk_libs | sed -e's,-lieee,,'`;;
+esac
 tkauxlibs="$mathlib $dllib"
 tcllib=''
 tklib=''
