SUMMARY="Standard EXT2/EXT3/EXT4 filesystem utilities"
DESCRIPTION="Various tools to manage EXT2,3,4 filesystems (resize, etc)"
HOMEPAGE="http://e2fsprogs.sourceforge.net/"
COPYRIGHT="2004-2018 Theodore Ts'o"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://downloads.sourceforge.net/e2fsprogs/e2fsprogs-$portVersion.tar.gz
	https://sourceforge.mirrorservice.org/e/e2/e2fsprogs/e2fsprogs/v$portVersion/e2fsprogs-$portVersion.tar.gz
	https://fossies.org/linux/misc/e2fsprogs-$portVersion.tar.gz"
CHECKSUM_SHA256="5f64ac50a2b60b8e67c5b382bb137dec39344017103caffc3a61554424f2d693"
PATCHES="e2fsprogs-$portVersion.patchset"

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

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

GLOBAL_WRITABLE_FILES="
	settings/mke2fs.conf keep-old
	"

PROVIDES="
	e2fsprogs$secondaryArchSuffix = $portVersion
	cmd:badblocks$commandSuffix
	cmd:chattr$commandSuffix
	cmd:compile_et$commandSuffix
	cmd:dumpe2fs$commandSuffix
	cmd:e2freefrag$commandSuffix
	cmd:e2fsck$commandSuffix
	cmd:e2image$commandSuffix
	cmd:e2label$commandSuffix
	cmd:e2mmpstatus$commandSuffix
	cmd:e2undo$commandSuffix
	cmd:filefrag$commandSuffix
	cmd:fsck.ext2$commandSuffix
	cmd:fsck.ext3$commandSuffix
	cmd:fsck.ext4$commandSuffix
	cmd:logsave$commandSuffix
	cmd:lsattr$commandSuffix
	cmd:mk_cmds$commandSuffix
	cmd:mke2fs$commandSuffix
	cmd:mkfs.ext2$commandSuffix
	cmd:mkfs.ext3$commandSuffix
	cmd:mkfs.ext4$commandSuffix
	cmd:mklost+found$commandSuffix
	cmd:resize2fs$commandSuffix
	cmd:tune2fs$commandSuffix
	lib:libcom_err$secondaryArchSuffix = 2.1 compat >= 2
	lib:libe2p$secondaryArchSuffix = 2.3 compat >= 2
	lib:libext2fs$secondaryArchSuffix = 2.4 compat >= 2
	lib:libss$secondaryArchSuffix = 2.0 compat >= 2
	devel:libcom_err$secondaryArchSuffix = 2.1 compat >= 2
	devel:libe2p$secondaryArchSuffix = 2.3 compat >= 2
	devel:libext2fs$secondaryArchSuffix = 2.4 compat >= 2
	devel:libss$secondaryArchSuffix = 2.0 compat >= 2
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libblkid$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libuuid$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libblkid$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libuuid$secondaryArchSuffix >= 1.3
	"
BUILD_PREREQUIRES="
	cmd:autoconf
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

PATCH()
{
	cat <<EOF >gnuc_prereq.h
#ifndef __GNUC_PREREQ
# if defined(__GNUC__) && defined(__GNUC_MINOR__)
#  define __GNUC_PREREQ(ma, mi) \\
    (__GNUC__ > (ma) || __GNUC__ == (ma) && __GNUC_MINOR__ >= (mi))
# else
#  define __GNUC_PREREQ(ma, mi) 0
# endif
#endif
EOF
	sed -i -e '$a #include "../gnuc_prereq.h"' lib/config.h.in
	sed -i -e '1i #include "../../gnuc_prereq.h"' lib/ext2fs/hashmap.h
}

BUILD()
{
	autoconf
	libdir=`finddir B_COMMON_LIB_DIRECTORY`
	CPPFLAGS="-include gnuc_prereq.h" \
	runConfigure --omit-dirs "binDir sbinDir" ./configure \
		--bindir="$commandBinDir" \
		--sbindir="$commandBinDir" \
		USE=-loop-aes --disable-tls \
		--disable-libblkid --disable-libuuid \
		--disable-fsck --disable-debugfs \
		--enable-elf-shlibs --enable-symlink-build --enable-symlink-install
	sed -i \
		-e "s| 'CPPFLAGS=-include gnuc_prereq\.h'||g" \
		-e 's|"-include gnuc_prereq.h"|""|' \
		-e 's| -include gnuc_prereq.h||g' \
		config.status
	make $jobArgs
}

INSTALL()
{
	make install

	rm -f $libDir/*.a
	prepareInstalledDevelLibs libcom_err libe2p libext2fs libss
	fixPkgconfig

}

TEST()
{
	LIBRARY_PATH="$sourceDir/lib${LIBRARY_PATH:+:$LIBRARY_PATH}" \
	make check
}
