# --- T2-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# 
# T2 SDE: architecture/sparc64/parse-config
# Copyright (C) 2004 - 2006 The T2 SDE Project
# 
# More information can be found in the files COPYING and README.
# 
# This program 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; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- T2-COPYRIGHT-NOTE-END ---

# Note: There is a copy in powerpc64/parse-config

alter_arch()
{
	case "$SDECFG_SPARC64_OPT" in
		generic) x=v9 ;;
		*) x=v9b ;;
	esac

	echo_status "Altering arch_{machine,target} to sparc$x ..."
	# tweak target and other defines
	arch_machine=${arch_machine/64/$x}
	arch_target=${arch_target/64/$x}
	atstage native && arch_build=${arch_build/64/$x}

	# let the libdir and configure options regenerate
	set_confopt
}

sparc64_build_32()
{
	# wipe the former build
	make distclean
	var_remove GCC_WRAPPER_INSERT ' ' '-m64'
	alter_arch
	build_package ncurses ncurses.conf
}

if [ "$SDECFG_SPARC64_32BIT" = 1 ]; then
  # TODO: make dietlibc parse-config -7 (or so) and this one -9 (or so) ,-)
  x="${pkg//-/_}" ; x="${x//+/_}"
  eval x=\$SDECFG_DIETLIBC_$x
  if [ "$x" = 1 ]; then
	echo_status "Building package for 64bit ..."
	var_append GCC_WRAPPER_INSERT ' ' '-m64'
  else
  	case $pkg in
	gcc|binutils)
		echo_status "Patching package to default to 32bit ..."
		var_append patchfiles ' ' \
		           "$base/architecture/$arch/pkg_$pkg.diff"
		;;
	glibc|module-init-tools|modutils|iptables|strace|gdb)
		echo_status "Building for 64bit ..."
		var_append GCC_WRAPPER_INSERT ' ' '-m64'
		;;
	linux2*)
		;;
	ncurses)
		var_append GCC_WRAPPER_INSERT ' ' '-m64'
		hook_add postmake 9 "sparc64_build_32"
		;;
	*) # including glibc32
		alter_arch
		;;
	esac
  fi
fi

