$NetBSD: patch-aa,v 1.4 2014/01/25 13:38:48 ryoon Exp $

* Add t-crtstuff to tmake_file on NetBSD.
* Add netbsd-stdint.h to tm_file on NetBSD.
* wrap the system stdint.h on NetBSD.

* Add Dragonfly support.

--- gcc/config.gcc.orig	2013-03-06 17:40:07.000000000 +0000
+++ gcc/config.gcc
@@ -561,6 +561,33 @@ case ${target} in
   # need_64bit_hwint=yes # system compiler has this for all arch!
   use_gcc_stdint=wrap
   ;;
+*-*-dragonfly*)
+  gas=yes
+  gnu_ld=yes
+  extra_parts="crtbegin.o crtend.o crtbeginS.o crtendS.o"
+  case ${target} in
+    *-*-dragonfly1 | *-*-dragonfly[1].*)
+      tm_defines="${tm_defines} DFBSD_MAJOR=1" ;;
+    *-*-dragonfly2 | *-*-dragonfly[2].*)
+      tm_defines="${tm_defines} DFBSD_MAJOR=2" ;;
+    *-*-dragonfly3 | *-*-dragonfly[3].*)
+      tm_defines="${tm_defines} DFBSD_MAJOR=3" ;;
+    *-*-dragonfly4 | *-*-dragonfly[4].*)
+      tm_defines="${tm_defines} DFBSD_MAJOR=4" ;;
+    *)
+      echo 'Please update *-*-dragonfly* in gcc/config.gcc'
+      exit 1
+      ;;
+  esac
+  tmake_file="t-slibgcc-elf-ver t-dragonfly"
+  case ${enable_threads} in
+    "" | yes | posix)
+      thread_file='posix'
+      tmake_file="${tmake_file} t-dragonfly-thread"
+      ;;
+  esac
+  dfbsd_tm_file="${dfbsd_tm_file} dragonfly-spec.h dragonfly.h"
+  ;;
 *-*-linux* | frv-*-*linux* | *-*-kfreebsd*-gnu | *-*-knetbsd*-gnu | *-*-gnu* | *-*-kopensolaris*-gnu)
   extra_options="$extra_options gnu-user.opt"
   extra_parts="crtbegin.o crtbeginS.o crtbeginT.o crtend.o crtendS.o"
@@ -655,6 +682,7 @@ case ${target} in
       default_use_cxa_atexit=yes
       ;;
   esac
+  use_gcc_stdint=wrap
   ;;
 *-*-openbsd*)
   tmake_file="t-libc-ok t-openbsd t-libgcc-pic"
@@ -668,6 +696,14 @@ case ${target} in
     *-*-openbsd2.*|*-*-openbsd3.[012])
       tm_defines="${tm_defines} HAS_LIBC_R=1" ;;
   esac
+  case ${target} in
+    *-*-openbsd[0-3].*|*-*-openbsd4.[012])
+      # keep default of no cxa_atexit support for these older releases
+      ;;
+    *)
+      default_use_cxa_atexit=yes
+      ;;
+  esac
   ;;
 *-*-rtems*)
   case ${enable_threads} in
@@ -741,7 +777,7 @@ alpha*-*-netbsd*)
 	tmake_file="${tmake_file} alpha/t-alpha alpha/t-ieee"
 	;;
 alpha*-*-openbsd*)
-	tm_defines="${tm_defines} OBSD_HAS_DECLARE_FUNCTION_NAME OBSD_HAS_DECLARE_FUNCTION_SIZE OBSD_HAS_DECLARE_OBJECT"
+	tm_defines="${tm_defines} OBSD_HAS_DECLARE_FUNCTION_NAME OBSD_HAS_DECLARE_FUNCTION_SIZE OBSD_HAS_DECLARE_OBJECT PIE_DEFAULT=2"
 	tm_file="alpha/alpha.h alpha/elf.h openbsd.h openbsd-stdint.h alpha/openbsd.h openbsd-libpthread.h"
 	extra_options="${extra_options} openbsd.opt alpha/elf.opt"
 	# default x-alpha is only appropriate for dec-osf.
@@ -1057,10 +1093,14 @@ hppa*-*-linux*)
 	    tmake_file="$tmake_file pa/t-slibgcc-dwarf-ver"
 	fi
 	;;
-# port not yet contributed.
-#hppa*-*-openbsd*)
-#	target_cpu_default="MASK_PA_11"
-#	;;
+hppa*-*-openbsd*)
+	target_cpu_default="MASK_PA_11"
+	tm_defines="${tm_defines} PIE_DEFAULT=1"
+	tm_file="${tm_file} dbxelf.h elfos.h openbsd-libpthread.h \
+		pa/pa32-regs.h pa/openbsd.h openbsd.h"
+	tmake_file="${tmake_file} pa/t-openbsd"
+	extra_options="${extra_options} openbsd.opt"
+	;;
 hppa[12]*-*-hpux10*)
 	case ${target} in
 	hppa1.1-*-* | hppa2*-*-*)
@@ -1223,19 +1263,26 @@ x86_64-*-freebsd*)
 	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h ${fbsd_tm_file} i386/x86-64.h i386/freebsd.h i386/freebsd64.h"
 	tmake_file="${tmake_file} i386/t-crtstuff"
 	;;
+x86_64-*-dragonfly*)
+	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h ${dfbsd_tm_file} i386/x86-64.h i386/dragonfly.h i386/dragonfly64.h"
+	;;
+i[34567]86-*-dragonfly*)
+	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h ${dfbsd_tm_file} i386/dragonfly.h"
+	;;
 i[34567]86-*-netbsdelf*)
-	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h netbsd.h netbsd-elf.h i386/netbsd-elf.h"
+	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h netbsd.h netbsd-elf.h i386/netbsd-elf.h netbsd-stdint.h"
 	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
+	tmake_file="${tmake_file} i386/t-crtstuff"
 	;;
 i[34567]86-*-netbsd*)
-	tm_file="${tm_file} i386/unix.h i386/bsd.h i386/gas.h i386/gstabs.h netbsd.h netbsd-aout.h i386/netbsd.h"
+	tm_file="${tm_file} i386/unix.h i386/bsd.h i386/gas.h i386/gstabs.h netbsd.h netbsd-aout.h i386/netbsd.h netbsd-stdint.h"
 	extra_options="${extra_options} netbsd.opt"
 	tmake_file="${tmake_file} t-netbsd"
 	extra_parts=""
 	use_collect2=yes
 	;;
 x86_64-*-netbsd*)
-	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h netbsd.h netbsd-elf.h i386/x86-64.h i386/netbsd64.h"
+	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h netbsd.h netbsd-elf.h i386/x86-64.h i386/netbsd64.h netbsd-stdint.h"
 	extra_options="${extra_options} netbsd.opt netbsd-elf.opt"
 	tmake_file="${tmake_file} i386/t-crtstuff"
 	;;
@@ -1248,12 +1295,19 @@ i[34567]86-*-openbsd2.*|i[34567]86-*open
 	use_collect2=yes
 	;;
 i[34567]86-*-openbsd*)
+	tm_defines="${tm_defines} PIE_DEFAULT=1"
 	tm_file="${tm_file} i386/unix.h i386/att.h dbxelf.h elfos.h"
 	tm_file="${tm_file} openbsd.h openbsd-stdint.h openbsd-libpthread.h i386/openbsdelf.h"
 	extra_options="${extra_options} openbsd.opt"
 	gas=yes
 	gnu_ld=yes
 	;;
+x86_64-*-openbsd*)
+	tm_defines="${tm_defines} PIE_DEFAULT=1"
+	tm_file="i386/biarch64.h i386/i386.h i386/unix.h i386/att.h dbxelf.h elfos.h openbsd.h openbsd-libpthread.h i386/x86-64.h i386/openbsd64.h"
+	tm_file="${tm_file} exec-stack.h"
+	tmake_file="t-libc-ok t-openbsd i386/t-openbsd"
+	;;
 i[34567]86-*-linux* | i[34567]86-*-kfreebsd*-gnu | i[34567]86-*-knetbsd*-gnu | i[34567]86-*-gnu* | i[34567]86-*-kopensolaris*-gnu)
 			# Intel 80386's running GNU/*
 			# with ELF format using glibc 2
@@ -1914,14 +1968,15 @@ mips*-*-linux*)				# Linux MIPS, either 
 	test x$with_llsc != x || with_llsc=yes
 	;;
 mips*-*-openbsd*)
-	tm_defines="${tm_defines} OBSD_HAS_DECLARE_FUNCTION_NAME OBSD_HAS_DECLARE_OBJECT OBSD_HAS_CORRECT_SPECS"
-	target_cpu_default="MASK_ABICALLS"
-	tm_file="mips/mips.h openbsd.h openbsd-stdint.h openbsd-libpthread.h mips/openbsd.h mips/sdb.h"
+	tm_defines="${tm_defines} OBSD_HAS_DECLARE_FUNCTION_NAME OBSD_HAS_DECLARE_OBJECT OBSD_HAS_CORRECT_SPECS MIPS_ISA_DEFAULT=3 MIPS_ABI_DEFAULT=ABI_64 PIE_DEFAULT=1"
+	tm_file="dbxelf.h elfos.h openbsd.h openbsd-stdint.h openbsd-libpthread.h mips/mips.h mips/openbsd64.h"
 	extra_options="${extra_options} openbsd.opt"
 	case ${target} in
 	mips*el-*-openbsd*)
-	    tm_defines="${tm_defines} TARGET_ENDIAN_DEFAULT=0";;
-	*)  tm_defines="${tm_defines} TARGET_ENDIAN_DEFAULT=MASK_BIG_ENDIAN";;
+	    tm_defines="${tm_defines} TARGET_ENDIAN_DEFAULT=0"
+	    target_cpu_default="MASK_ABICALLS";;
+	*)  tm_defines="${tm_defines} TARGET_ENDIAN_DEFAULT=MASK_BIG_ENDIAN"
+	    target_cpu_default="MASK_ABICALLS|MASK_FIX_R4000|MASK_FIX_R4400";;
         esac
 	;;
 mips*-sde-elf*)
@@ -2061,10 +2116,11 @@ picochip-*)
 	tmake_file="picochip/t-picochip t-pnt16-warn"
         ;;
 # port not yet contributed
-#powerpc-*-openbsd*)
-#	tmake_file="${tmake_file} rs6000/t-fprules rs6000/t-fprules-fpbit "
-#	extra_headers=
-#	;;
+powerpc-*-openbsd*)
+	tm_file="${tm_file} dbxelf.h elfos.h openbsd.h openbsd-libpthread.h freebsd-spec.h rs6000/sysv4.h rs6000/openbsd.h"
+	tmake_file="${tmake_file} rs6000/t-openbsd"
+	extra_options="${extra_options} rs6000/sysv4.opt"
+	;;
 powerpc-*-darwin*)
 	extra_options="${extra_options} rs6000/darwin.opt"
 	extra_parts="crt2.o"
@@ -2665,6 +2721,7 @@ sparc64-*-netbsd*)
 	tmake_file="${tmake_file} sparc/t-netbsd64"
 	;;
 sparc64-*-openbsd*)
+	tm_defines="${tm_defines} PIE_DEFAULT=2"
 	tm_file="sparc/openbsd1-64.h ${tm_file} dbxelf.h elfos.h sparc/sysv4.h sparc/sp64-elf.h"
 	tm_file="${tm_file} openbsd.h openbsd-stdint.h openbsd-libpthread.h sparc/openbsd64.h"
 	extra_options="${extra_options} openbsd.opt"
@@ -2830,6 +2887,12 @@ case ${target} in
     arch_without_sse2=yes
     arch_without_64bit=yes
     ;;
+  i386-*-openbsd*)
+    arch=i486
+    cpu=generic
+    arch_without_sse2=yes
+    arch_without_64bit=yes
+    ;;
   i386-*-*)
     arch=i386
     cpu=i386
