#! /bin/sh -e
# 10_newpatch.dpatch by  <schizo@debian.org>
# updated for 4.0, 4.1, 4.2 by Matthias Klose <doko@debian.org>
#
# DP: Enable biarch support for the 32bit sparc compiler

if [ $# -eq 3 ] && [ "$2" = '-d' ]; then
    pdir="-d $3"
    dir="$3/"
elif [ $# -ne 1 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch)
	patch $pdir -f --no-backup-if-mismatch -p0 < $0
        cd ${dir}libcpp && autoconf
	;;
    -unpatch)
	patch $pdir -f --no-backup-if-mismatch -R -p0 < $0
        cd ${dir}libcpp && autoconf
	;;
    *)
	echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
	exit 1;;
esac

exit 0

--- gcc/config/sparc/linux64.h.orig	2006-06-04 13:09:21.857528428 -0300
+++ gcc/config/sparc/linux64.h	2006-06-04 13:11:15.385012057 -0300
@@ -54,8 +54,8 @@
    + MASK_STACK_BIAS + MASK_APP_REGS + MASK_FPU + MASK_LONG_DOUBLE_128)
 #endif
 
-#undef ASM_CPU_DEFAULT_SPEC
-#define ASM_CPU_DEFAULT_SPEC "-Av9a"
+#undef ASM_CPU64_DEFAULT_SPEC
+#define ASM_CPU64_DEFAULT_SPEC "-Av9a"
 
 /* Provide a STARTFILE_SPEC appropriate for GNU/Linux.  Here we add
    the GNU/Linux magical crtbegin.o file (see crtstuff.c) which
--- gcc/config.gcc.orig	2006-06-04 13:09:21.882530957 -0300
+++ gcc/config.gcc	2006-06-04 13:14:13.577036688 -0300
@@ -315,6 +315,7 @@
 	;;
 sparc*-*-*)
 	cpu_type=sparc
+	need_64bit_hwint=yes
 	;;
 s390*-*-*)
 	cpu_type=s390
@@ -2105,9 +2106,16 @@
 	use_fixproto=yes
 	;;
 sparc-*-linux*)		# SPARC's running GNU/Linux, libc6
+	# If cpu is specified, assume we want a 32/64 compiler
+	if test x$with_cpu = x; then
 	tm_file="${tm_file} dbxelf.h elfos.h svr4.h sparc/sysv4.h sparc/linux.h"
 	extra_options="${extra_options} sparc/long-double-switch.opt"
 	tmake_file="${tmake_file} sparc/t-linux sparc/t-crtfm"
+	else
+	  tm_file="sparc/biarch64.h ${tm_file} dbxelf.h elfos.h svr4.h sparc/sysv4.h sparc/linux64.h"
+	  extra_options="${extra_options} sparc/long-double-switch.opt"
+	  tmake_file="${tmake_file} sparc/t-linux sparc/t-linux64 sparc/t-crtfm"
+	fi
 	;;
 sparc-*-rtems*)
 	tm_file="${tm_file} dbxelf.h elfos.h svr4.h sparc/sysv4.h sparc/sp-elf.h sparc/rtemself.h rtems.h"
--- libcpp/configure.ac~	2006-01-18 22:52:36.862072128 +0100
+++ libcpp/configure.ac	2006-08-15 14:48:00.484137064 +0200
@@ -124,7 +124,7 @@
 	powerpc*-*-* | \
 	rs6000*-*-* | \
 	s390*-*-* | \
-	sparc64*-*-* | ultrasparc-*-freebsd* | \
+	sparc*-*-* | ultrasparc-*-freebsd* | \
 	sparcv9-*-solaris2* | \
 	sparc-*-solaris2.[789] | sparc-*-solaris2.1[0-9]* | \
 	sh[123456789l]*-*-*)
