Index: configure
--- configure.orig	2003-03-18 15:19:12 +0100
+++ configure	2005-06-13 09:18:51 +0200
@@ -822,9 +822,13 @@
       sparc*-*-netbsd*)	machine=sparc ;;
       vax-*-netbsd*)	machine=vax ;;
       arm-*-netbsd*)	machine=arm ;;
+      x86_64-*-netbsd*)	machine=amd64 ;;
     esac
   ;;
 
+  ## Darwin / Mac OS X
+  powerpc-apple-darwin* )
+    machine=powermac opsys=darwin ;;
   ## OpenBSD ports
   *-*-openbsd* )
     opsys=openbsd
@@ -1628,8 +1632,20 @@
   ;;
 
   ## IA-64
-  ia64*-*-linux* )
-    machine=ia64 opsys=gnu-linux
+  ia64*-*-* )
+    machine=ia64
+    case "${canonical}" in
+      *-linux-gnu* )        opsys=gnu-linux ;;
+      *-freebsd* )          opsys=freebsd ;;
+    esac
+  ;;
+
+  amd64*-*-* )
+    machine=amd64
+    case "${canonical}" in
+      *-linux-gnu* )        opsys=gnu-linux ;;
+      *-freebsd* )          opsys=freebsd ;;
+    esac
   ;;
 
   ## Intel 386 machines where we don't care about the manufacturer
@@ -1659,6 +1675,7 @@
       *-sysv4.2uw* )	  	opsys=unixware; NON_GNU_CPP=/lib/cpp ;;
       *-386bsd* )	        opsys=386bsd ;;
       *-freebsd* )	        opsys=freebsd ;;
+      *-dragonfly* )	        opsys=freebsd ;;
       *-nextstep* )             opsys=nextstep ;;
       ## Otherwise, we'll fall through to the generic opsys code at the bottom.
     esac
@@ -9124,6 +9141,22 @@
 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
+
 # Set up the CFLAGS for real compilation, so we can substitute it.
 CFLAGS="$REAL_CFLAGS"
 CPPFLAGS="$REAL_CPPFLAGS"
Index: src/Makefile.in
--- src/Makefile.in.orig	2003-01-23 11:34:06 +0100
+++ src/Makefile.in	2005-06-13 09:18:51 +0200
@@ -155,8 +155,12 @@
 /* This holds special options for linking temacs
    that should be used for linking anything else.  */
 #ifndef LD_SWITCH_SYSTEM_TEMACS
+#if defined(__FreeBSD_version) && (__FreeBSD_version >= 500042)
+#define LD_SWITCH_SYSTEM_TEMACS -znocombreloc
+#else
 #define LD_SWITCH_SYSTEM_TEMACS
 #endif
+#endif
 
 /* Some m/MACHINE.h files define this to request special switches in ld.  */
 #ifndef LD_SWITCH_MACHINE
Index: src/alloc.c
--- src/alloc.c.orig	2003-01-17 14:45:13 +0100
+++ src/alloc.c	2005-06-13 09:18:51 +0200
@@ -3723,8 +3723,12 @@
   /* This trick flushes the register windows so that all the state of
      the process is contained in the stack.  */
 #ifdef sparc
+#ifdef __sparc64__
+  asm ("flushw");
+#else
   asm ("ta 3");
 #endif
+#endif
   
   /* Save registers that we need to see on the stack.  We need to see
      registers used to hold register variables and registers used to
Index: src/config.in
--- src/config.in.orig	2002-07-09 00:23:31 +0200
+++ src/config.in	2005-06-13 09:18:51 +0200
@@ -354,6 +354,12 @@
 /* Define for large files, on AIX-style hosts.  */
 #undef _LARGE_FILES
 
+/* On NetBSD, Define HAVE_NETBSD_CRT{I,N} if a given system has crt{i,n}.o
+   installed under /usr/lib.  These should be linked against temacs,
+   or it won't boot.  */
+#undef HAVE_NETBSD_CRTI
+#undef HAVE_NETBSD_CRTN
+
 #undef EMACS_CONFIGURATION
 
 #undef EMACS_CONFIG_OPTIONS
Index: src/m/alpha.h
--- src/m/alpha.h.orig	2000-10-02 16:30:39 +0200
+++ src/m/alpha.h	2005-06-13 09:18:51 +0200
@@ -198,7 +198,7 @@
 
 #ifndef NOT_C_CODE
 /* We need these because pointers are larger than the default ints.  */
-#if !defined(__NetBSD__) && !defined(__OpenBSD__)
+#if !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__FreeBSD__)
 #include <alloca.h>
 #endif
 
Index: src/m/amd64.h
--- /dev/null	2005-06-13 09:33:35 +0200
+++ src/m/amd64.h	2005-06-13 09:18:51 +0200
@@ -0,0 +1,131 @@
+/* machine description file for AMD x86-64.
+   Copyright (C) 2002 Free Software Foundation, Inc.
+
+This file is part of GNU Emacs.
+
+GNU Emacs is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Emacs is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Emacs; see the file COPYING.  If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA.  */
+
+
+/* The following line tells the configuration script what sort of 
+   operating system this machine is likely to run.
+   USUAL-OPSYS="linux"  */
+
+#define BITS_PER_LONG           64
+#define BITS_PER_EMACS_INT      64
+
+/* Define WORDS_BIG_ENDIAN iff lowest-numbered byte in a word
+   is the most significant byte.  */
+
+#undef WORDS_BIG_ENDIAN
+
+/* Define NO_ARG_ARRAY if you cannot take the address of the first of a
+ * group of arguments and treat it as an array of the arguments.  */
+
+#define NO_ARG_ARRAY
+
+/* Define WORD_MACHINE if addresses and such have
+ * to be corrected before they can be used as byte counts.  */
+
+/* #define WORD_MACHINE  */
+
+/* Now define a symbol for the cpu type, if your compiler
+   does not define it automatically:
+   Ones defined so far include vax, m68000, ns16000, pyramid,
+   orion, tahoe, APOLLO and many others */
+/* __x86_64 defined automatically.  */
+
+/* Use type int rather than a union, to represent Lisp_Object */
+/* This is desirable for most machines.  */
+
+#define NO_UNION_TYPE
+
+/* Define the type to use.  */
+#define EMACS_INT               long
+#define EMACS_UINT              unsigned long
+#define SPECIAL_EMACS_INT
+
+/* Define EXPLICIT_SIGN_EXTEND if XINT must explicitly sign-extend
+   the 24-bit bit field into an int.  In other words, if bit fields
+   are always unsigned.
+
+   If you use NO_UNION_TYPE, this flag does not matter.  */
+
+#define EXPLICIT_SIGN_EXTEND
+
+/* Data type of load average, as read out of kmem.  */
+
+#define LOAD_AVE_TYPE long
+
+/* Convert that into an integer that is 100 for a load average of 1.0  */
+
+#define LOAD_AVE_CVT(x) (int) (((double) (x)) * 100.0 / FSCALE)
+
+/* Define CANNOT_DUMP on machines where unexec does not work.
+   Then the function dump-emacs will not be defined
+   and temacs will do (load "loadup") automatically unless told otherwise.  */
+
+/* #define CANNOT_DUMP */
+
+/* Define VIRT_ADDR_VARIES if the virtual addresses of
+   pure and impure space as loaded can vary, and even their
+   relative order cannot be relied on.
+
+   Otherwise Emacs assumes that text space precedes data space,
+   numerically.  */
+
+#define VIRT_ADDR_VARIES  /* XXX */
+
+/* Define C_ALLOCA if this machine does not support a true alloca
+   and the one written in C should be used instead.
+   Define HAVE_ALLOCA to say that the system provides a properly
+   working alloca function and it should be used.
+   Define neither one if an assembler-language alloca
+   in the file alloca.s should be used.  */
+
+/* #define C_ALLOCA */      /* XXX */
+#define HAVE_ALLOCA
+
+/* Define NO_REMAP if memory segmentation makes it not work well
+   to change the boundary between the text section and data section
+   when Emacs is dumped.  If you define this, the preloaded Lisp
+   code will not be sharable; but that's better than failing completely.  */
+
+#define NO_REMAP  /* XXX */
+
+#define PNTR_COMPARISON_TYPE unsigned long
+
+/* On the 64 bit architecture, we can use 60 bits for addresses */
+
+#define VALBITS         60
+
+/* This definition of MARKBIT is necessary because of the comparison of
+   ARRAY_MARK_FLAG and MARKBIT in an #if in lisp.h, which cpp doesn't like. */
+
+#define MARKBIT         0x8000000000000000L
+
+/* Define XINT and XUINT so that they can take arguments of type int */
+#define XINT(a)  (((long) (a) << (BITS_PER_LONG - VALBITS)) >> (BITS_PER_LONG - VALBITS))
+#define XUINT(a) ((long) (a) & VALMASK)
+
+/* Define XPNTR to avoid or'ing with DATA_SEG_BITS */
+
+#define XPNTR(a) XUINT (a)
+
+/* #undef START_FILES */ /* XXX */
+/* #define START_FILES pre-crt0.o /usr/lib64/crt1.o /usr/lib64/crti.o */ /* XXX */
+
+/* #undef LIB_STANDARD */                                    /* XXX */
+/* #define LIB_STANDARD -lgcc -lc -lgcc /usr/lib64/crtn.o */ /* XXX */
Index: src/m/ia64.h
--- src/m/ia64.h.orig	2000-09-29 15:00:37 +0200
+++ src/m/ia64.h	2005-06-13 09:41:30 +0200
@@ -147,7 +147,7 @@
 
 #ifndef NOT_C_CODE
 /* We need these because pointers are larger than the default ints.  */
-# if !defined(__NetBSD__) && !defined(__OpenBSD__)
+# if !defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(__FreeBSD__)
 #  include <alloca.h>
 # else
 #  include <stdlib.h>
@@ -178,6 +178,6 @@
 
 #endif /* not NOT_C_CODE */
 
-#define DATA_SEG_BITS	0x6000000000000000
+#define DATA_SEG_BITS	0x2000000000000000
 
 #define HAVE_TEXT_START
Index: src/m/sparc.h
--- src/m/sparc.h.orig	2000-09-26 15:02:21 +0200
+++ src/m/sparc.h	2005-06-13 09:18:51 +0200
@@ -89,7 +89,7 @@
 #define PURESIZE 130000
 #endif
 
-#if !defined (__NetBSD__) && !defined (__linux__) && !defined (__OpenBSD__)
+#if !defined (__NetBSD__) && !defined (__linux__) && !defined (__OpenBSD__) && !defined(__FreeBSD__)
 /* This really belongs in s/sun.h.  */
 
 /* Say that the text segment of a.out includes the header;
Index: src/s/freebsd.h
--- src/s/freebsd.h.orig	2001-02-20 11:52:17 +0100
+++ src/s/freebsd.h	2005-06-13 09:18:51 +0200
@@ -68,6 +68,11 @@
 #define LIBS_SYSTEM -lutil
 #if __FreeBSD_version < 400000
 #define LIBS_TERMCAP -ltermcap
+#else
+#ifdef HAVE_LIBNCURSES
+#define TERMINFO
+#define LIBS_TERMCAP -lncurses
+#endif
 #endif
 
 #define SYSV_SYSTEM_DIR
Index: src/s/netbsd.h
--- src/s/netbsd.h.orig	2002-05-31 18:29:02 +0200
+++ src/s/netbsd.h	2005-06-13 09:18:51 +0200
@@ -60,9 +60,17 @@
 #endif /* not NO_SHARED_LIBS and not ELF */
 
 #if !defined (NO_SHARED_LIBS) && defined (__ELF__)
+#if defined(HAVE_NETBSD_CRTI)
+#define START_FILES pre-crt0.o /usr/lib/crt0.o /usr/lib/crti.o /usr/lib/crtbegin.o
+#else
 #define START_FILES pre-crt0.o /usr/lib/crt0.o /usr/lib/crtbegin.o
+#endif
 #define UNEXEC unexelf.o
+#if defined(HAVE_NETBSD_CRTN)
+#define LIB_STANDARD -lgcc -lc -lgcc /usr/lib/crtend.o /usr/lib/crtn.o
+#else
 #define LIB_STANDARD -lgcc -lc -lgcc /usr/lib/crtend.o
+#endif
 #undef LIB_GCC
 #define LIB_GCC
 #endif
@@ -123,3 +131,7 @@
 
 #define GC_MARK_STACK	GC_MAKE_GCPROS_NOOPS
 
+/* Use sigprocmask(2) and friends instead of sigblock(2); the man page
+   of sigblock says it is obsolete.  */
+
+#define POSIX_SIGNALS		1
Index: src/s/sol2-4.h
--- src/s/sol2-4.h.orig	1998-08-29 01:38:20 +0200
+++ src/s/sol2-4.h	2005-06-13 09:18:51 +0200
@@ -24,7 +24,7 @@
 /* We use ./prefix-args because we don't know whether LD_SWITCH_X_SITE_AUX
    has anything in it.  It can be empty.
    This works ok in temacs.  */
-#define LD_SWITCH_SYSTEM_TEMACS -L/usr/ccs/lib \
+#define LD_SWITCH_SYSTEM_TEMACS -z nocombreloc -L/usr/ccs/lib \
  `./prefix-args -Xlinker LD_SWITCH_X_SITE_AUX` \
   `NOT_USING_MOTIF || echo ' -R/usr/dt/lib -L/usr/dt/lib'`
 #endif /* GCC */
Index: src/s/sol2-8.h
--- /dev/null	2005-06-13 09:33:35 +0200
+++ src/s/sol2-8.h	2005-06-13 09:18:51 +0200
@@ -0,0 +1,10 @@
+/* Handle Solaris 2.8 and 2.9 */
+
+#include "sol2-5.h"
+
+/* Avoid conflict between strings.h and iso/string_iso.h */
+
+#undef bcmp
+#undef bcopy
+#undef bzero
+
