SUMMARY="STM32 discovery line programmer"
DESCRIPTION="stlink is a cheap adapter used to program and debug STM32 \
microcontrollers. This tool allows interfacing the stlink with GDB for easy \
programming and debugging of these chips."
HOMEPAGE="https://github.com/texane/stlink"
COPYRIGHT="2011-2020 The Capt'ns Missing Link Authors"
LICENSE="BSD (3-clause)"
REVISION="2"
SOURCE_URI="https://github.com/texane/stlink/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="ca9a640f84c3e2c9873bd51759594bc05c00cdf6e1f21b434ae2c0e7985433d8"
PATCHES="stlink-$portVersion.patchset"

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

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

PROVIDES="
	stlink$secondaryArchSuffix = $portVersion
	cmd:st_flash$commandSuffix = $portVersion
	cmd:st_info$commandSuffix = $portVersion
	cmd:st_util$commandSuffix = $portVersion
	lib:libstlink$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libusb_1.0$secondaryArchSuffix
	"

BUILD_REQUIRES="
	devel:libusb_1.0$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	mkdir -p build
	cd build

	cmake .. -DCMAKE_BUILD_TYPE=Release
	make $jobArgs
}

INSTALL()
{
	mkdir -p $commandBinDir $libDir
	cp build/bin/{st-flash,st-info,st-util} $commandBinDir
	cp build/lib/*.so* $libDir
}
