# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Sören Tempel <soeren+alpine@soeren-tempel.net>
pkgname=stlink
pkgver=1.8.0
pkgrel=0
pkgdesc="STM32 discovery line linux programmer"
url="https://github.com/stlink-org/stlink"
arch="all"
license="MIT"
makedepends="cmake libusb-dev samurai"
options="!check" # upstream doesn't have automated tests
subpackages="$pkgname-doc $pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/stlink-org/stlink/archive/v$pkgver.tar.gz
	gcc14.patch
	"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SHARED_LIBS=True \
		-DSTLINK_LIBRARY_PATH=/usr/lib \
		-DCMAKE_C_FLAGS="$CFLAGS -Wno-error=cpp" \
		-DSTLINK_UDEV_RULES_DIR=/usr/lib/udev/rules.d \
		$CMAKE_CROSSOPTS
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	mkdir -p "$pkgdir"/usr/share/doc/$pkgname
	install -m644 README.md CHANGELOG.md doc/tutorial.md \
		"$pkgdir"/usr/share/doc/$pkgname/
}

sha512sums="
49245a4b0aeb926dd71ec4260b707d900318fe68e3a36e2e5543587fefb4886a9ff0ff42e0e12a8e727a5d4e9c7b4ce13989ca4d963842dbf960065e5fa0c968  stlink-1.8.0.tar.gz
f0374641756981c94d865d282cbe8009ccc9e9b41499501310f7442878e68b1984418428d13a7ea1f22312d5c928ec7bdb845d99a54a4264497a954859ad38cc  gcc14.patch
"
