SUMMARY="The GNU partition editor"
DESCRIPTION="GNU Parted manipulates partition tables. This is useful for \
creating space for new operating systems, reorganizing disk usage, copying \
data on hard disks and disk imaging."
HOMEPAGE="https://www.gnu.org/software/parted/"
COPYRIGHT="1999-2014 Free Software Foundation Inc."
LICENSE="GNU GPL v3"
REVISION="6"
SOURCE_URI="https://ftpmirror.gnu.org/parted/parted-$portVersion.tar.xz
	https://ftp.gnu.org/gnu/parted/parted-$portVersion.tar.xz"
CHECKSUM_SHA256="858b589c22297cacdf437f3baff6f04b333087521ab274f7ab677cb8c6bb78e4"
PATCHES="parted-$portVersion.patchset"

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

# On x86_gcc2 we don't want to install the commands in bin/<arch>/, but in bin/.
commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

libVersion="2.0.1"
libFsResizeVersion="0.0.1"

libMajorVersion="${libVersion%%.*}"
libFsResizeMajorVersion="${libFsResizeVersion%%.*}"

libVersionCompat="$libVersion compat >= $libMajorVersion"
libFsResizeVersionCompat="$libFsResizeVersion compat >= $libFsResizeMajorVersion"

PROVIDES="
	parted$secondaryArchSuffix = $portVersion
	cmd:parted$commandSuffix = $portVersion
	cmd:partprobe$commandSuffix = $portVersion
	lib:libparted$secondaryArchSuffix = $libVersionCompat
	lib:libparted_fs_resize$secondaryArchSuffix = $libFsResizeVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libblkid$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libncurses$secondaryArchSuffix
	lib:libreadline$secondaryArchSuffix
	lib:libuuid$secondaryArchSuffix >= 1.3
	"

PROVIDES_devel="
	parted${secondaryArchSuffix}_devel = $portVersion
	devel:libparted$secondaryArchSuffix = $libVersionCompat
	devel:libparted_fs_resize$secondaryArchSuffix = $libFsResizeVersionCompat
	"
REQUIRES_devel="
	parted$secondaryArchSuffix == $portVersion base
	devel:libblkid$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libncurses$secondaryArchSuffix
	devel:libreadline$secondaryArchSuffix
	devel:libuuid$secondaryArchSuffix >= 1.3
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libblkid$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libncurses$secondaryArchSuffix
	devel:libreadline$secondaryArchSuffix
	devel:libuuid$secondaryArchSuffix >= 1.3
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:autom4te
	cmd:automake
	cmd:autoreconf
	cmd:awk
	cmd:gcc$secondaryArchSuffix
	cmd:gettext$secondaryArchSuffix
	cmd:gperf
	cmd:grep
	cmd:iconv
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:sed
	"

TEST_REQUIRES="
	cmd:dd
	"

defineDebugInfoPackage parted$secondaryArchSuffix \
	"$libDir"/libparted.so.$libVersion \
	"$libDir"/libparted-fs-resize.so.$libFsResizeVersion

BUILD()
{
	autoreconf
	CPPFLAGS="-Wimplicit-fallthrough=0" \
	MAKEINFO=true \
	runConfigure --omit-dirs sbinDir ./configure --sbindir=$commandBinDir \
		--disable-device-mapper
	make $jobArgs
}

INSTALL()
{
	make install

	rm -f "$libDir"/libparted*.la

	prepareInstalledDevelLibs \
		libparted \
		libparted-fs-resize

	fixPkgconfig

	# devel package
	packageEntries devel \
		$developDir
}

TEST()
{
	make check
}
