SUMMARY="Standard GNU core utilities"
DESCRIPTION="Most of these programs have significant advantages over their \
Unix counterparts, such as greater speed, additional options, and fewer \
arbitrary limits.

The programs that can be built with this package are:

  [ arch base64 basename cat chcon chgrp chmod chown chroot cksum comm cp \
csplit cut date dd df dir dircolors dirname du echo env expand expr \
factor false fmt fold groups head hostid hostname id install join kill \
link ln logname ls md5sum mkdir mkfifo mknod mktemp mv nice nl nohup \
nproc numfmt od paste pathchk pinky pr printenv printf ptx pwd readlink \
realpath rm rmdir runcon seq sha1sum sha224sum sha256sum sha384sum sha512sum \
shred shuf sleep sort split stat stdbuf stty sum sync tac tail tee test \
timeout touch tr true truncate tsort tty uname unexpand uniq unlink \
uptime users vdir wc who whoami yes"
HOMEPAGE="https://www.gnu.org/software/coreutils/"
COPYRIGHT="1994-2017 Free Software Foundation, Inc."
LICENSE="GNU GPL v3"
REVISION="6"
SOURCE_URI="https://ftpmirror.gnu.org/coreutils/coreutils-$portVersion.tar.xz
	https://ftp.gnu.org/gnu/coreutils/coreutils-$portVersion.tar.xz"
CHECKSUM_SHA256="ce30acdf4a41bc5bb30dd955e9eaa75fa216b4e3deb08889ed32433c7b3b97ce"
PATCHES="coreutils-$portVersion.patchset"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

binVersionCompat="$portVersion compat >= 8"
PROVIDES="
	coreutils$secondaryArchSuffix = $binVersionCompat
	cmd:[$commandSuffix = $binVersionCompat
	cmd:b2sum$commandSuffix = $binVersionCompat
	cmd:base32$commandSuffix = $binVersionCompat
	cmd:base64$commandSuffix = $binVersionCompat
	cmd:basename$commandSuffix = $binVersionCompat
	cmd:basenc$commandSuffix = $binVersionCompat
	cmd:cat$commandSuffix = $binVersionCompat
	cmd:chcon$commandSuffix = $binVersionCompat
	cmd:chgrp$commandSuffix = $binVersionCompat
	cmd:chmod$commandSuffix = $binVersionCompat
	cmd:chown$commandSuffix = $binVersionCompat
	cmd:chroot$commandSuffix = $binVersionCompat
	cmd:cksum$commandSuffix = $binVersionCompat
	cmd:comm$commandSuffix = $binVersionCompat
	cmd:cp$commandSuffix = $binVersionCompat
	cmd:csplit$commandSuffix = $binVersionCompat
	cmd:cut$commandSuffix = $binVersionCompat
	cmd:date$commandSuffix = $binVersionCompat
	cmd:dd$commandSuffix = $binVersionCompat
	cmd:dir$commandSuffix = $binVersionCompat
	cmd:dircolors$commandSuffix = $binVersionCompat
	cmd:dirname$commandSuffix = $binVersionCompat
	cmd:du$commandSuffix = $binVersionCompat
	cmd:echo$commandSuffix = $binVersionCompat
	cmd:env$commandSuffix = $binVersionCompat
	cmd:expand$commandSuffix = $binVersionCompat
	cmd:expr$commandSuffix = $binVersionCompat
	cmd:factor$commandSuffix = $binVersionCompat
	cmd:false$commandSuffix = $binVersionCompat
	cmd:fmt$commandSuffix = $binVersionCompat
	cmd:fold$commandSuffix = $binVersionCompat
	cmd:groups$commandSuffix = $binVersionCompat
	cmd:head$commandSuffix = $binVersionCompat
	cmd:hostname$commandSuffix = $binVersionCompat
	cmd:id$commandSuffix = $binVersionCompat
	cmd:install$commandSuffix = $binVersionCompat
	cmd:join$commandSuffix = $binVersionCompat
	cmd:kill$commandSuffix = $binVersionCompat
	cmd:link$commandSuffix = $binVersionCompat
	cmd:ln$commandSuffix = $binVersionCompat
	cmd:logname$commandSuffix = $binVersionCompat
	cmd:ls$commandSuffix = $binVersionCompat
	cmd:md5sum$commandSuffix = $binVersionCompat
	cmd:mkdir$commandSuffix = $binVersionCompat
	cmd:mkfifo$commandSuffix = $binVersionCompat
	cmd:mknod$commandSuffix = $binVersionCompat
	cmd:mktemp$commandSuffix = $binVersionCompat
	cmd:mv$commandSuffix = $binVersionCompat
	cmd:nice$commandSuffix = $binVersionCompat
	cmd:nl$commandSuffix = $binVersionCompat
	cmd:nohup$commandSuffix = $binVersionCompat
	cmd:nproc$commandSuffix = $binVersionCompat
	cmd:numfmt$commandSuffix = $binVersionCompat
	cmd:od$commandSuffix = $binVersionCompat
	cmd:paste$commandSuffix = $binVersionCompat
	cmd:pathchk$commandSuffix = $binVersionCompat
	cmd:pr$commandSuffix = $binVersionCompat
	cmd:printenv$commandSuffix = $binVersionCompat
	cmd:printf$commandSuffix = $binVersionCompat
	cmd:ptx$commandSuffix = $binVersionCompat
	cmd:pwd$commandSuffix = $binVersionCompat
	cmd:readlink$commandSuffix = $binVersionCompat
	cmd:realpath$commandSuffix = $binVersionCompat
	cmd:rm$commandSuffix = $binVersionCompat
	cmd:rmdir$commandSuffix = $binVersionCompat
	cmd:runcon$commandSuffix = $binVersionCompat
	cmd:seq$commandSuffix = $binVersionCompat
	cmd:sha1sum$commandSuffix = $binVersionCompat
	cmd:sha224sum$commandSuffix = $binVersionCompat
	cmd:sha256sum$commandSuffix = $binVersionCompat
	cmd:sha384sum$commandSuffix = $binVersionCompat
	cmd:sha512sum$commandSuffix = $binVersionCompat
	cmd:shred$commandSuffix = $binVersionCompat
	cmd:shuf$commandSuffix = $binVersionCompat
	cmd:sleep$commandSuffix = $binVersionCompat
	cmd:sort$commandSuffix = $binVersionCompat
	cmd:split$commandSuffix = $binVersionCompat
	cmd:stat$commandSuffix = $binVersionCompat
	cmd:stdbuf$commandSuffix = $binVersionCompat
	cmd:stty$commandSuffix = $binVersionCompat
	cmd:sum$commandSuffix = $binVersionCompat
	cmd:sync$commandSuffix = $binVersionCompat
	cmd:tac$commandSuffix = $binVersionCompat
	cmd:tail$commandSuffix = $binVersionCompat
	cmd:tee$commandSuffix = $binVersionCompat
	cmd:test$commandSuffix = $binVersionCompat
	cmd:timeout$commandSuffix = $binVersionCompat
	cmd:touch$commandSuffix = $binVersionCompat
	cmd:tr$commandSuffix = $binVersionCompat
	cmd:true$commandSuffix = $binVersionCompat
	cmd:truncate$commandSuffix = $binVersionCompat
	cmd:tsort$commandSuffix = $binVersionCompat
	cmd:tty$commandSuffix = $binVersionCompat
	cmd:uname$commandSuffix = $binVersionCompat
	cmd:unexpand$commandSuffix = $binVersionCompat
	cmd:uniq$commandSuffix = $binVersionCompat
	cmd:unlink$commandSuffix = $binVersionCompat
	cmd:uptime$commandSuffix = $binVersionCompat
	cmd:vdir$commandSuffix = $binVersionCompat
	cmd:wc$commandSuffix = $binVersionCompat
	cmd:whoami$commandSuffix = $binVersionCompat
	cmd:yes$commandSuffix = $binVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"
if [ "$targetArchitecture" = x86_gcc2 ]; then
	PROVIDES+="
		coreutils = $binVersionCompat
		"
	REPLACES="
		coreutils
		"
fi

BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel
	cmd:awk
	cmd:cmp
	cmd:gcc$secondaryArchSuffix
	cmd:grep
	cmd:help2man
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:makeinfo
	cmd:sed
	"

defineDebugInfoPackage coreutils$secondaryArchSuffix \
	$commandBinDir/[ \
	$commandBinDir/b2sum \
	$commandBinDir/base32 \
	$commandBinDir/base64 \
	$commandBinDir/basename \
	$commandBinDir/basenc \
	$commandBinDir/cat \
	$commandBinDir/chcon \
	$commandBinDir/chgrp \
	$commandBinDir/chmod \
	$commandBinDir/chown \
	$commandBinDir/chroot \
	$commandBinDir/cksum \
	$commandBinDir/comm \
	$commandBinDir/cp \
	$commandBinDir/csplit \
	$commandBinDir/cut \
	$commandBinDir/date \
	$commandBinDir/dd \
	$commandBinDir/dir \
	$commandBinDir/dircolors \
	$commandBinDir/dirname \
	$commandBinDir/du \
	$commandBinDir/echo \
	$commandBinDir/env \
	$commandBinDir/expand \
	$commandBinDir/expr \
	$commandBinDir/factor \
	$commandBinDir/false \
	$commandBinDir/fmt \
	$commandBinDir/fold \
	$commandBinDir/groups \
	$commandBinDir/head \
	$commandBinDir/hostname \
	$commandBinDir/id \
	$commandBinDir/install \
	$commandBinDir/join \
	$commandBinDir/kill \
	$commandBinDir/link \
	$commandBinDir/ln \
	$commandBinDir/logname \
	$commandBinDir/ls \
	$commandBinDir/md5sum \
	$commandBinDir/mkdir \
	$commandBinDir/mkfifo \
	$commandBinDir/mknod \
	$commandBinDir/mktemp \
	$commandBinDir/mv \
	$commandBinDir/nice \
	$commandBinDir/nl \
	$commandBinDir/nohup \
	$commandBinDir/nproc \
	$commandBinDir/numfmt \
	$commandBinDir/od \
	$commandBinDir/paste \
	$commandBinDir/pathchk \
	$commandBinDir/pr \
	$commandBinDir/printenv \
	$commandBinDir/printf \
	$commandBinDir/ptx \
	$commandBinDir/pwd \
	$commandBinDir/readlink \
	$commandBinDir/realpath \
	$commandBinDir/rm \
	$commandBinDir/rmdir \
	$commandBinDir/runcon \
	$commandBinDir/seq \
	$commandBinDir/sha1sum \
	$commandBinDir/sha224sum \
	$commandBinDir/sha256sum \
	$commandBinDir/sha384sum \
	$commandBinDir/sha512sum \
	$commandBinDir/shred \
	$commandBinDir/shuf \
	$commandBinDir/sleep \
	$commandBinDir/sort \
	$commandBinDir/split \
	$commandBinDir/stat \
	$commandBinDir/stdbuf \
	$commandBinDir/stty \
	$commandBinDir/sum \
	$commandBinDir/sync \
	$commandBinDir/tac \
	$commandBinDir/tail \
	$commandBinDir/tee \
	$commandBinDir/test \
	$commandBinDir/timeout \
	$commandBinDir/touch \
	$commandBinDir/tr \
	$commandBinDir/true \
	$commandBinDir/truncate \
	$commandBinDir/tsort \
	$commandBinDir/tty \
	$commandBinDir/uname \
	$commandBinDir/unexpand \
	$commandBinDir/uniq \
	$commandBinDir/unlink \
	$commandBinDir/uptime \
	$commandBinDir/vdir \
	$commandBinDir/wc \
	$commandBinDir/whoami \
	$commandBinDir/yes

PATCH()
{
	sed -i -e 's|O_NOCACHE|DD_NOCACHE|g' src/dd.c
}

BUILD()
{
	export CPPFLAGS=-Dst_birthtim=st_crtim
	FORCE_UNSAFE_CONFIGURE=1 runConfigure --omit-dirs binDir ./configure \
		 --bindir=$commandBinDir \
		--without-included-regex \
		--disable-rpath --with-gnu-ld \
		--enable-no-install-program=df,pinky,users,who \
		--enable-install-program=hostname
	touch doc/*.info
	make $jobArgs
}

INSTALL()
{
	make install
}

TEST()
{
	make check
}
