SUMMARY="Utilities for interacting with the sg SCSI interface"
DESCRIPTION="The sg3_utils package contains utilities that send SCSI commands \
to devices. As well as devices on transports traditionally associated with \
SCSI (e.g. Fibre Channel (FCP), Serial Attached SCSI (SAS) and the SCSI \
Parallel Interface(SPI)) many other devices use SCSI command sets. \
ATAPI CD/DVD drives and SATA disks that connect via a translation layer or \
a bridge device are examples of devices that use SCSI command sets."
HOMEPAGE="http://sg.danny.cz/sg/sg3_utils.html"
COPYRIGHT="2016 Douglas Gilbert
	2016 sg3_utils Contributors"
LICENSE="GNU GPL v2
	BSD (3-clause)"
REVISION="1"
SOURCE_URI="http://sg.danny.cz/sg/p/sg3_utils-$portVersion.tar.xz"
CHECKSUM_SHA256="97aeed65894feb2add896b4adfa4cf343966c8a61c7d206795ed0507640ee7b9"
PATCHES="sg3_utils-$portVersion.patchset"

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

libVersion="2.0.0"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"
libName="libsgutils${libVersionCompat##* }"

PROVIDES="
	sg3_utils$secondaryArchSuffix = $portVersion
	lib:$libName$secondaryArchSuffix = $libVersionCompat
	"

sgBins=(compare_and_write decode_sense format get_config get_lba_status
	ident inq logs luns modes opcodes persist prevent raw rdac read_attr
	read_block_limits read_buffer read_long readcap reassign referrals
	rep_zones requests reset_wp rmsn rtpg safte sanitize sat_identify
	sat_phy_event sat_read_gplog sat_set_features senddiag ses ses_microcode
	start stpg sync timestamp turs unmap verify vpd wr_mode
	write_buffer write_long write_same write_verify zone)
# helper scripts
scsiBins=(mandat readcap ready satl start stop temperature)

for i in "${sgBins[@]}"
do
	PROVIDES+="
		cmd:sg_$i = $portVersion
		"
done
for i in "${scsiBins[@]}"
do
	PROVIDES+="
		cmd:scsi_$i = $portVersion
		"
done

REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_devel="
	sg3_utils${secondaryArchSuffix}_devel = $portVersion
	devel:$libName$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	sg3_utils$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:autoheader
	cmd:awk
	cmd:cmp
	cmd:gcc$secondaryArchSuffix
	cmd:grep
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:sed
	"

defineDebugInfoPackage sg3_utils$secondaryArchSuffix \
	"${sgBins[@]/#/$prefix\/bin/sg_}" \
	"$libDir/$libName.so.$libVersion"

BUILD()
{
	./autogen.sh
	runConfigure --omit-dirs binDir ./configure --bindir="$prefix/bin"
	make $jobArgs
}

INSTALL()
{
	make install
	install -d -m 755 "$docDir"
	install -t "$docDir" AUTHORS CREDITS

	# This script is Linux-only
	rm "$prefix"/bin/scsi_logging_level

	rm -f "$libDir"/*.la

	prepareInstalledDevelLib $libName
	packageEntries devel "$developDir"
}

# While this port ships a folder called testing, it was mainly for testing
# Linux APIs. The only tool we've got is a small utility that test various utils
# functions. As it doesn't indicate failure, I would say this more or less
# only serves as an example for those functions.
#TEST()
#{
#	cd testing
#	make tst_sg_lib
#	./tst_sg_lib -dpsu
#}
