SUMMARY="Identify a file's format by scanning binary data for patterns"
DESCRIPTION="This is Release 5.x of Ian Darwin's (copyright but distributable) \
file(1) command, an implementation of the Unix File(1) command. It knows the \
'magic number' of several thousands of file types. This version is the \
standard 'file' command for Linux, *BSD, and other systems. (See \
'patchlevel.h' for the exact release number)."
HOMEPAGE="https://www.darwinsys.com/file/"
COPYRIGHT="1986-1999 Ian F. Darwin
	1994-2018 Christos Zoulas"
LICENSE="BSD (2-clause)"
REVISION="1"
SOURCE_URI="ftp://ftp.astron.com/pub/file/file-$portVersion.tar.gz"
CHECKSUM_SHA256="13e532c7b364f7d57e23dfeea3147103150cb90593a57af86c10e4f6e411603f"
PATCHES="file-$portVersion.patchset"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86_gcc2 x86"

libVersion="1.0.0"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"
portVersionCompat="$portVersion compat >= 5"

PROVIDES="
	file$secondaryArchSuffix = $portVersion
	cmd:file$secondaryArchSuffix = $portVersionCompat
	lib:libmagic$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	file_data == $portVersion
	lib:libz$secondaryArchSuffix
	"

if [ -z "$secondaryArchSuffix" ]; then
	SUMMARY_data="Magic file for the file(1) command"
	ARCHITECTURES_data="any"
	PROVIDES_data="
		file_data = $portVersion
		"
	REQUIRES_data=""
fi

PROVIDES_devel="
	file${secondaryArchSuffix}_devel = $portVersion
	devel:libmagic$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	file$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libz$secondaryArchSuffix
	"
if [ -n "$secondaryArchSuffix" ]; then
	BUILD_REQUIRES="$BUILD_REQUIRES
		file_data == $portVersion
		"
fi

BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:automake
	cmd:autoreconf
	cmd:gcc$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:sed
	"

defineDebugInfoPackage file$secondaryArchSuffix \
	"$binDir"/file \
	"$libDir"/libmagic.so.$libVersion

BUILD()
{
	autoreconf
	runConfigure ./configure
	make
}

INSTALL()
{
	make install

	# remove libtool file
	rm -f $libDir/libmagic.la

	prepareInstalledDevelLib libmagic
	fixPkgconfig

	if [ -z "$secondaryArchSuffix" ]; then
		packageEntries data \
			$dataDir
		maybe_manDir_man3=$manDir/man3
		rmdir $manDir/man5
		sed -i -e "s,$dataDir/,/system/$relativeDataDir/,g" \
			$manDir/man1/file.1 \
			$manDir/man3/libmagic.3 \
			$manDir/man4/magic.4
	else
		maybe_manDir_man3=
		rm -rf $dataDir $manDir
	fi

	packageEntries devel \
		$developDir \
		$maybe_manDir_man3
}

TEST()
{
	make check
}
