# SPDX-License-Identifier: CC0-1.0
#
# SPDX-FileContributor: Adrian "asie" Siekierka, 2023

pkgname=toolchain-gcc-sh-elf-picolibc-generic
_pkgver=1.8.2
pkgver=1.8.2.r23434.a1a130c4f
pkgrel=2
epoch=
pkgdesc="picolibc-based C library for Wonderful toolchain"
arch=(any)
url="https://github.com/WonderfulToolchain/wf-picolibc"
license=("BSD-3-Clause")
source=(
	"wf-picolibc::git+https://github.com/WonderfulToolchain/wf-picolibc#branch=wonderful"
	"cross.txt"
)
depends=(toolchain-gcc-sh-elf-binutils toolchain-gcc-sh-elf-gcc)
groups=(toolchain-gcc-sh-elf)
sha256sums=(
	'SKIP'
	'SKIP'
)
options=(!strip)

. "/wf/config/runtime-env-vars.sh"

prepare() {
	mkdir -p picolibc-build
}

GIT_REPO_DIR=wf-picolibc
. "../templates/git-pkgver.PKGBUILD"

build() {
	cd picolibc-build
	export PATH=$WF_PATH/toolchain/gcc-sh-elf/bin:$PATH

	meson setup \
		--cross-file=../cross.txt \
		-Dmultilib=false \
		-Dpicocrt=false \
		-Dpicolib=false \
		-Dsemihost=false \
		-Dspecsdir=none \
		-Dtests=false \
		\
		-Dio-long-long=true \
		-Dio-pos-args=true \
		\
		-Dposix-console=true \
		-Dformat-default=double \
		\
		-Dnewlib-nano-malloc=true \
		\
		-Dprefix="$WF_PATH"/toolchain/gcc-sh-elf \
		-Dlibdir=sh-elf/lib \
		-Dincludedir=sh-elf/include \
		../wf-picolibc

	ninja
}

package() {
	cd picolibc-build
	DESTDIR="$pkgdir" ninja install

	cd "$pkgdir"
	wf_relocate_path_to_destdir
}
