# Importada de Alpine aports por `hammer import-alpine` (Etapa G). PUNTO DE PARTIDA — pero
# YA trae los parches de musl de Alpine (lo que un import de nix pierde). Pendiente: el
# sha256 del tarball (el wrapper lo calcula), y adaptar build/install del shell de abuild.
name    = "libwebp"
version = "1.6.0"
license = "BSD-3-Clause"

[source]
tarball = "https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.6.0.tar.gz"
# FIXME sha256: el wrapper lo calcula (Alpine publica sha512). sha512 de Alpine:
# sha512 = "5c159d9760efcb92749092536daada22c0a73c20926c76097a5f0448ddbf874cf761324ca97925ca5f578b30477564b2b072b47667e504673797128b31cafcbf"
sha256  = "e4ab7009bf0629fd11982d4c2aa83964cf244cffba7347ecd39019a9e38c4564"

[build]
compiler = "zig-cc"
target   = "x86_64-linux-musl"
link     = "static"
flags    = []

[build.phases]
# de build() de Alpine (traducido; el lab provee $CBUILD/$CHOST — Etapa G Fase 3; revisá --shared para estático):
compile = '''
_abuild_phase() {
CFLAGS="$CFLAGS -O2 -flto=auto -ffat-lto-objects" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--enable-libwebpmux \
		--enable-libwebpdemux \
		--enable-libwebpdecoder \
		--disable-tiff # dependency-loop
	make LDFLAGS="-all-static -no-pie"
}
_abuild_phase
'''
# de package() de Alpine (traducido $pkgdir→/out):
install = '''
_abuild_phase() {
make DESTDIR="/out" install LDFLAGS="-all-static -no-pie"
	mkdir -p "/out"/usr/share/doc/libwebp
	install -Dm644 PATENTS README.md "/out"/usr/share/doc/libwebp
}
_abuild_phase
'''

[deps]
build = ["giflib", "libjpeg-turbo", "libpng", "make"]
