$NetBSD: patch-ab,v 1.7 2015/02/19 14:18:52 wiz Exp $

Caution: the extra cpp checking (the three hunks containing "Should be
one line") is manually hacked and not reflected in configure.in; do
not regenerate configure with autoconf without merging it. This
checking is required because somewhere between gcc 4.1 and 4.5 cpp
started doing regrettable things with backslash-escaped newlines.

* Fix build on NetBSD 6.99.23, gcc -E -traditional-cpp with native X
  results syntax error. Use -traditional-cpp for Makefile generation only.

--- configure.orig	2003-03-18 09:19:12.000000000 -0500
+++ configure	2015-02-16 21:19:13.000000000 -0500
@@ -821,10 +821,18 @@ case "${canonical}" in
       powerpc-*-netbsd*) machine=macppc ;;
       sparc*-*-netbsd*)	machine=sparc ;;
       vax-*-netbsd*)	machine=vax ;;
-      arm-*-netbsd*)	machine=arm ;;
+      arm*-*-netbsd*)	machine=arm ;;
+      x86_64-*-netbsd*)	machine=amd64 ;;
+      hppa-*-netbsd*)	machine=hp800 ;;
+      shle-*-netbsd*)	machine=sh3el ;;
     esac
   ;;
 
+  ## Darwin / Mac OS X
+  powerpc-apple-darwin* )
+    machine=powermac opsys=darwin ;;
+  i386-apple-darwin* )
+    machine=intel386 opsys=darwin ;;
   ## OpenBSD ports
   *-*-openbsd* )
     opsys=openbsd
@@ -909,6 +917,10 @@ case "${canonical}" in
     machine=macppc opsys=gnu-linux
   ;;
 
+  x86_64-*-linux* )
+    machine=amd64 opsys=gnu-linux
+  ;;
+
   ## Altos 3068
   m68*-altos-sysv* )
     machine=altos opsys=usg5-2
@@ -1659,6 +1671,7 @@ case "${canonical}" in
       *-sysv4.2uw* )	  	opsys=unixware; NON_GNU_CPP=/lib/cpp ;;
       *-386bsd* )	        opsys=386bsd ;;
       *-freebsd* )	        opsys=freebsd ;;
+      *-dragonfly* )	        opsys=dragonfly ;;
       *-nextstep* )             opsys=nextstep ;;
       ## Otherwise, we'll fall through to the generic opsys code at the bottom.
     esac
@@ -2052,15 +2065,20 @@ else
   CPP="${CC-cc} -E"
   # On the NeXT, cc -E runs the code through the compiler's parser,
   # not just through cpp.
+  # And, gcc 4.5? and up does not preserve escaped newlines, which is
+  # fatal for preprocessing makefiles.
   cat > conftest.$ac_ext <<EOF
 #line 2057 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
+Should be one line.
 EOF
-ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+ac_try="$ac_cpp conftest.$ac_ext >conftest2.out 2>conftest.out"
 { (eval echo configure:2063: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"; \
+    grep -L "Should  *be one line" conftest2.out \
+    `
 if test -z "$ac_err"; then
   :
 else
@@ -2068,16 +2086,19 @@ else
   echo "configure: failed program was:" >&5
   cat conftest.$ac_ext >&5
   rm -rf conftest*
-  CPP="${CC-cc} -E -traditional-cpp"
+  CPP="${CC-cc} -E"
   cat > conftest.$ac_ext <<EOF
 #line 2074 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
+Should be one line.
 EOF
-ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+ac_try="$ac_cpp conftest.$ac_ext >conftest2.out 2>conftest.out"
 { (eval echo configure:2080: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"; \
+    grep -L "Should  *be one line" conftest2.out \
+    `
 if test -z "$ac_err"; then
   :
 else
@@ -2091,10 +2112,13 @@ else
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
+Should be one line.
 EOF
-ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+ac_try="$ac_cpp conftest.$ac_ext >conftest2.out 2>conftest.out"
 { (eval echo configure:2097: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
-ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"; \
+    grep -L "Should  *be one line" conftest2.out \
+    `
 if test -z "$ac_err"; then
   :
 else
@@ -2416,7 +2440,7 @@ ac_link="$ac_link $ld_switch_machine $ld
 if test x"${OVERRIDE_CPPFLAGS}" != x; then
   CPPFLAGS="${OVERRIDE_CPPFLAGS}"
 else
-  CPPFLAGS="$c_switch_system $c_switch_machine $CPPFLAGS"
+  CPPFLAGS="`echo $c_switch_system $c_switch_machine $CPPFLAGS | sed 's,-L[^ ]*,,g'`"
 fi
 
 
@@ -5583,24 +5607,24 @@ if eval "test \"`echo '$ac_cv_header_'$a
   echo "$ac_t""yes" 1>&6
   # EGifPutExtensionLast only exists from version libungif-4.1.0b1.
 # Earlier versions can crash Emacs.
-      echo $ac_n "checking for EGifPutExtensionLast in -lungif""... $ac_c" 1>&6
-echo "configure:5588: checking for EGifPutExtensionLast in -lungif" >&5
-ac_lib_var=`echo ungif'_'EGifPutExtensionLast | sed 'y%./+-%__p_%'`
+      echo $ac_n "checking for EGifPutExtensionTrailer in -lgif""... $ac_c" 1>&6
+echo "configure:5588: checking for EGifPutExtensionTrailer in -lgif" >&5
+ac_lib_var=`echo ungif'_'EGifPutExtensionTrailer | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_save_LIBS="$LIBS"
-LIBS="-lungif  $LIBS"
+LIBS="-lgif  $LIBS"
 cat > conftest.$ac_ext <<EOF
 #line 5596 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
     builtin and then its argument prototype would still apply.  */
-char EGifPutExtensionLast();
+char EGifPutExtensionTrailer();
 
 int main() {
-EGifPutExtensionLast()
+EGifPutExtensionTrailer()
 ; return 0; }
 EOF
 if { (eval echo configure:5607: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
@@ -9124,6 +9148,60 @@ EOF
 fi
 
 
+# NETBSD: NetBSD's newer run-time linker fix.
+if test $opsys = netbsd; then
+  if test -f /usr/lib/crti.o; then
+    cat >> confdefs.h <<\EOF
+#define HAVE_NETBSD_CRTI 1
+EOF
+
+  fi
+  if test -f /usr/lib/crtn.o; then
+    cat >> confdefs.h <<\EOF
+#define HAVE_NETBSD_CRTN 1
+EOF
+
+  fi
+fi
+
+# XXX: handcoded test for ptyfs
+echo $ac_n "checking for ptyfs""... $ac_c" 1>&6
+echo "configure:9095: checking for ptyfs" >&5
+cat > conftest.$ac_ext <<EOF
+#include "confdefs.h"
+#include <stdlib.h>
+#include <fcntl.h>
+
+int
+main(void)
+{
+	int fd;
+
+	fd = posix_openpt(O_RDWR);
+	if (fd == -1)
+		return 1;
+	close(fd);
+	return 0;
+}
+EOF
+if { (eval echo configure:9185: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+then
+  ac_cv_have_ptyfs=yes
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -fr conftest*
+  ac_cv_have_ptyfs=no
+fi
+rm -fr conftest*
+
+echo "$ac_t""$ac_cv_have_ptyfs" 1>&6
+if test $ac_cv_have_ptyfs = yes; then
+  cat >> confdefs.h <<\EOF
+#define HAVE_PTYFS 1
+EOF
+fi
+
 # Set up the CFLAGS for real compilation, so we can substitute it.
 CFLAGS="$REAL_CFLAGS"
 CPPFLAGS="$REAL_CPPFLAGS"
@@ -9735,7 +9813,7 @@ echo creating lib-src/Makefile
   sed -e '1,/start of cpp stuff/d'\
       -e 's,/\*\*/#\(.*\)$,/* \1 */,' \
       < Makefile.c > junk.c
-  $CPP $undefs -I. -I$top_srcdir/src $CPPFLAGS junk.c | \
+  $TRADCPP $undefs -I. -I$top_srcdir/src $CPPFLAGS junk.c | \
       sed -e 's/^ /	/' -e '/^#/d' -e '/^[ 	]*$/d' > junk2.c
   cat junk1.c junk2.c > Makefile.new
   rm -f junk.c junk1.c junk2.c
@@ -9751,7 +9829,7 @@ echo creating src/Makefile
   sed -e '1,/start of cpp stuff/d'\
       -e 's,/\*\*/#\(.*\)$,/* \1 */,' \
       < Makefile.c > junk.c
-  $CPP $undefs -I. -I$top_srcdir/src $CPPFLAGS junk.c | \
+  $TRADCPP $undefs -I. -I$top_srcdir/src $CPPFLAGS junk.c | \
       sed -e 's/^ /	/' -e '/^#/d' -e '/^[ 	]*$/d' > junk2.c
   cat junk1.c junk2.c > Makefile.new
   rm -f junk.c junk1.c junk2.c
