# 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    = "sudo"
version = "1.9.17_p2"
license = "ISC"

[source]
tarball = "https://www.sudo.ws/dist/sudo-1.9.17p2.tar.gz"
# FIXME sha256: el wrapper lo calcula (Alpine publica sha512). sha512 de Alpine:
# sha512 = "c8abd6ca56e54a081c9ef1e9f6579d1db5b93ff857e60d1f58d1f425d7dc23c31c58d40b7819780688f66dfdf87a1f3bbe0a78387b007e2beb1b0e546203ea93"
sha256  = "4a38a1ab3adb1199257edc2a7c4a2bd714665eb605b04368843b06dada2cfcfb"

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

[build.phases]
# fase configure EXPLÍCITA: si la receta no la define, hammer autogenera su propio
# `./configure --prefix=/usr` (sin nuestros --without-pam/--disable-nls) y aborta antes del compile.
# De-Alpinizado: sin PAM (musl trae crypt), sin NLS, sin SSSD; sin -flto; pie por defecto.
configure = '''
./configure \
	--build=$CBUILD \
	--host=$CHOST \
	--prefix=/usr \
	--libexecdir=/usr/lib \
	--mandir=/usr/share/man \
	--with-rundir=/run/sudo \
	--with-vardir=/var/lib/sudo \
	--with-tzdir=/usr/share/zoneinfo \
	--with-logdir=/var/log \
	--with-iologdir=/var/log/sudo-io \
	--with-logpath=/var/log/sudo.log \
	--with-relaydir=/var/log/sudo_logsrvd \
	--with-secure-path \
	--disable-shared \
	--enable-static-sudoers \
	--disable-log-server \
	--disable-log-client \
	--disable-nls \
	--with-env-editor \
	--with-mdoc \
	--without-pam \
	--without-skey \
	--without-sssd \
	--with-sendmail=/usr/sbin/sendmail \
	--with-passprompt="[sudo] password for %p: "
'''
# de build() de Alpine (traducido; el lab provee $CBUILD/$CHOST — Etapa G Fase 3):
compile = '''
make LDFLAGS="-all-static -no-pie"
'''
# de package() de Alpine (traducido $pkgdir→/out; el make install de sudo intenta chown/chmod
# setuid — el paquete lo re-aplica al hidratar; para el build alcanza con -o/-g neutralizados):
install = '''
# the sudo's mkinstalldir script miscreates the leading
# path components with bad permissions. fix this.
install -dm0755 "/out"/var "/out"/var/db
make -j1 DESTDIR="/out" INSTALL_OWNER= install LDFLAGS="-all-static -no-pie"

# Exactly the same as /etc/sudoers
rm -v "/out"/etc/sudoers.dist || true
'''

# Alpine build-deps de-Alpinizados: quitados linux-pam-dev, libxcrypt-dev (musl trae crypt).
# zlib del catálogo; runtime deps de Alpine no son build-deps.
[deps]
build = ["zlib", "linux-headers"]
