# 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    = "rsync"
version = "3.4.4"

[source]
tarball = "https://download.samba.org/pub/rsync/rsync-3.4.4.tar.gz"
# FIXME sha256: el wrapper lo calcula (Alpine publica sha512). sha512 de Alpine:
# sha512 = "cf9a838b1f019b70fd67fa2c293f267be3f24e579c2ea33177ec7afc502c97ce0b613ff0854088c0eb28acd14ee0a75706ae8445115cef4669bd586c505d8453"
sha256  = "bd88cf82fa653da32314fb229136407c5c90f80d1758d8f4b091767877d8fa96"
patches = ["dont-use-nobody.patch"]

[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() {
cp  rrsync.1 support/rrsync.1
	CFLAGS="$CFLAGS -flto=auto" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--enable-acl-support \
		--enable-xattr-support \
		--enable-xxhash \
		--with-rrsync \
		--without-included-popt \
		--without-included-zlib \
		--disable-md2man \
		--disable-openssl
		# openssl is disabled since xxh checksums are faster anyway
	make
}
_abuild_phase
'''
# de package() de Alpine (traducido $pkgdir→/out):
install = '''
_abuild_phase() {
make DESTDIR="/out" install

	install -Dm755 "$srcdir"/rsyncd.initd "/out"/etc/init.d/rsyncd
	install -Dm644 "$srcdir"/rsyncd.conf "/out"/etc/rsyncd.conf
	install -Dm644 "$srcdir"/rsyncd.confd "/out"/etc/conf.d/rsyncd
	install -Dm644 "$srcdir"/rsyncd.logrotate "/out"/etc/logrotate.d/rsyncd
}
_abuild_phase
'''

# depends de runtime de Alpine (NO build-deps): python3

[deps]
build = ["acl", "attr", "linux-headers", "lz4", "perl", "popt", "xxhash", "zlib", "zstd"]
