# Maintainer: Marian Buschsieweke <marian.buschsieweke@posteo.net>
# Contributor: Marian Buschsieweke <marian.buschsieweke@posteo.net>
pkgname=kicad-library
pkgver=9.0.2
pkgrel=0
pkgdesc="KiCad component and footprint libraries"
url="https://kicad.github.io/"
# limited by kicad
arch="noarch !armv7 !armhf !riscv64 !s390x"
license="GPL-3.0-or-later"
makedepends="cmake samurai"
depends="kicad"
subpackages="$pkgname-3d:three_d"
source="
	https://gitlab.com/kicad/libraries/kicad-symbols/-/archive/$pkgver/kicad-symbols-$pkgver.tar.gz
	https://gitlab.com/kicad/libraries/kicad-footprints/-/archive/$pkgver/kicad-footprints-$pkgver.tar.gz
	https://gitlab.com/kicad/libraries/kicad-packages3D/-/archive/$pkgver/kicad-packages3D-$pkgver.tar.gz
	"
options="!check" # package only provides data files, so not tests possible

build() {
	cd "$srcdir"/kicad-symbols-$pkgver
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr
	cmake --build build

	cd "$srcdir"/kicad-footprints-$pkgver
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr
	cmake --build build

	cd "$srcdir"/kicad-packages3D-$pkgver
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install "$srcdir"/kicad-symbols-$pkgver/build
	DESTDIR="$pkgdir" cmake --install "$srcdir"/kicad-footprints-$pkgver/build
}

three_d() {
	pkgdesc="3D models for KiCad component and footprint libraries"
	depends="$pkgname"
	DESTDIR="$subpkgdir" cmake --install "$srcdir"/kicad-packages3D-$pkgver/build

	# Remove .step version of 3D models; only .wrl versions are needed
	find "$subpkgdir" -name '*.step' -exec rm {} \;
}

sha512sums="
30c14f70083401fad8ae936dc89555c0fe575bf94a65cd7b74df4ef8d68ac26e83f2a4fe85321a336aa1bb4a2f1886bff75db252132f7cc67d45308f2021425d  kicad-symbols-9.0.2.tar.gz
c1b6fe855d5dc44a38464d5fac40716b55fcc54df5d18ee385edb1a3c29aaa0d81bd1260393d5578794026c544e8710268f670eb00f4577405da35f00e65ea0e  kicad-footprints-9.0.2.tar.gz
24cb6322809e4958c07df2263b8838b319fa1afe514f4a2d259b0a121696433bfc27e05228cf91b3a475592af8ad85fefb4675e87281f5928edd68ea528bba8f  kicad-packages3D-9.0.2.tar.gz
"
