# --- ROCK-COPYRIGHT-NOTE-BEGIN ---
# 
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
# Please add additional copyright information _after_ the line containing
# the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
# the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
# 
# ROCK Linux: rock-src/package/base/dietlibc/parse-config-9
# ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
# 
# 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; either version 2 of the License, or
# (at your option) any later version. A copy of the GNU General Public
# License can be found at Documentation/COPYING.
# 
# Many people helped and are helping developing ROCK Linux. Please
# have a look at http://www.rocklinux.org/ and the Documentation/TEAM
# file for details.
# 
# --- ROCK-COPYRIGHT-NOTE-END ---

if [ "$ROCKCFG_DIETLIBC_ALL" = 1 -o "$pkg" = "dietlibc" ]; then
	pkg_dietlibc_useit=1
else
	x="${pkg//-/_}" ; x="${x//+/_}"
	eval "pkg_dietlibc_useit=\$ROCKCFG_DIETLIBC_${x}"
fi
[ "$pkg_dietlibc_useit" != 1 ] && pkg_dietlibc_useit=0
[ "$stagelevel" -eq 0 ] && pkg_dietlibc_useit=0

if [ "$pkg_dietlibc_useit" = 1 ]; then

	# If we use something like 'i386-pc-linux-gnu' as architecture name,
	# some programs start using gnu extensions. So we use ..-gnulibc1
	# instead.
	#
	pkg_dietlibc_orig_target="$arch_target"
	arch_target="${arch_target}libc1"
	[ $ROCKCFG_CROSSBUILD = 0 ] && arch_build="${arch_target}"

	if [ -d $base/build/$ROCKCFG_ID/$toolsdir/diet-bin ] ; then
		PATH="$base/build/$ROCKCFG_ID/$toolsdir/diet-bin:$PATH"
	fi

	if [ "$ROCKCFG_DIETLIBC_DYN" = "1" ]
	then dietbin="diet-dyn" ; x="dynamically"
	else dietbin="diet" ; x="statically" ; fi

	echo_status "Building this package with dietlibc ($x)."

	if [ "$stagelevel" -gt 1 ]; then
		var_remove CC_WRAPPER_INSERT " " "-pipe" ;
		var_append CC_WRAPPER_REMOVE " " "-pipe" ;

		var_remove GCC_WRAPPER_INSERT " " "-pipe" ;
		var_append GCC_WRAPPER_REMOVE " " "-pipe" ;

#		patchopt="-bf -p1 -x 16 -z .orig" ;
#		var_append CC_WRAPPER_INSERT " " "-L/usr/i386-pc-linux-gnulibc1/lib"
	fi

	case "$pkg" in
		dietlibc|linux*)
			echo_status "Changing my mind and not building with dietlibc."
			;;

		util-linux|e2fsprogs|net-tools) # the packets that have BSD problems and/or GNU problems
			echo_status "setting dietlibc special GNU/BSD settings!"
			var_append CC_WRAPPER_INSERT " " "-nostdinc"
			var_append CC_WRAPPER_INSERT " " "-D_BSD_SOURCE"
			var_append CC_WRAPPER_INSERT " " "-D_GNU_SOURCE"
			var_insert CC_WRAPPER_FILTER "|" "sed -e 's,/usr/dietlibc/,$root&,'"
			var_append CC_WRAPPER_OTHERS ":" $dietbin
			;;

		sed)
			echo_status "setting dietlibc special lcompat settings!"
			var_append CC_WRAPPER_APPEND_PO " " "-lcompat"
			var_append CC_WRAPPER_INSERT " " "-nostdinc"
			var_insert CC_WRAPPER_FILTER "|" "sed -e 's,/usr/dietlibc/,$root&,'"
			var_append CC_WRAPPER_OTHERS ":" $dietbin
			;;

		coreutils)
			echo_status "setting dietlibc special lcompat+BSD settings!"
			var_append CC_WRAPPER_APPEND_PO " " "-lcompat"
			var_append CC_WRAPPER_INSERT " " "-nostdinc"
			var_append CC_WRAPPER_INSERT " " "-D_BSD_SOURCE"
			var_insert CC_WRAPPER_FILTER "|" "sed -e 's,/usr/dietlibc/,$root&,'"
			var_append CC_WRAPPER_OTHERS ":" $dietbin
		;;

		*)
			var_append CC_WRAPPER_INSERT " " "-nostdinc"
#			var_append CC_WRAPPER_INSERT " " "-I$root/usr/src/linux/include"    <<< that is not the right way !
			var_insert CC_WRAPPER_FILTER "|" "sed -e 's,/usr/dietlibc/,$root&,'"
			var_append CC_WRAPPER_OTHERS ":" $dietbin
			;;
	esac

	case "$pkg" in
		coreutils)
			var_remove patchfiles " " "*acl-xattr.patch"
		;;
	esac

	var_append patchfiles " " `ls $base/package/base/dietlibc/pkg_patch/pkg_$pkg.patch 2>/dev/null`
fi

