# 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    = "vim"
version = "9.2.0747"
license = "Vim"

[source]
tarball = "https://github.com/vim/vim/archive/refs/tags/v9.2.0747/vim-9.2.0747.tar.gz"
# FIXME sha256: el wrapper lo calcula (Alpine publica sha512). sha512 de Alpine:
# sha512 = "9dba40e94e09879eed41555be1275b993cac9b85b1105635f3c1dd2f5c3171f41db09c18b75313d1c6e4c2e5562b8542c4c8861929128a541c77f7e351eb425c"
sha256  = "91535a380a445989b39dfd88c6afe8efa08668a17120ffbb33a237eab31952f3"

[build]
# gcc (gueto, como nano/htop): zig-cc miscompila estos C clásicos.
compiler = "zig-cc"
target   = "x86_64-linux-musl"
link     = "static"
flags    = []

# vim de CONSOLA (sin GUI, sin X, sin intérpretes). Fase `configure` EXPLÍCITA (gotcha: si el
# ./configure va dentro de `compile`, hammer sintetiza un configure por defecto y pisa las flags).
# vim_cv_* cacheados para musl/estático (evita runtime-tests que cuelgan). --with-tlib=ncursesw:
# la ncurses del corpus es widec-only (libncursesw.a; sin symlink libncurses.a).
[build.phases]
configure = '''
# La ncurses del corpus es static (no-PIE); vim usa la API termcap (tgetent→lib_termcap.o) cuyas
# reubicaciones R_X86_64_32 (_nc_globals) NO entran en un binario PIE. El lab linka static-PIE por
# defecto ⇒ apagamos PIE en compile y link.
export CFLAGS="${CFLAGS:-} -fno-pie -fno-PIE"
export LDFLAGS="${LDFLAGS:-} -no-pie"
export vim_cv_toupper_broken=no \
	vim_cv_terminfo=yes \
	vim_cv_tgetent=zero \
	vim_cv_getcwd_broken=no \
	vim_cv_stat_ignores_slash=no \
	vim_cv_memmove_handles_overlap=yes \
	vim_cv_bcopy_handles_overlap=yes \
	vim_cv_memcpy_handles_overlap=yes
./configure \
	--build=$CBUILD \
	--host=$CHOST \
	--prefix=/usr \
	--with-features=normal \
	--disable-gui \
	--without-x \
	--disable-netbeans \
	--enable-multibyte \
	--with-tlib=ncursesw \
	--disable-nls \
	--disable-luainterp \
	--disable-python3interp \
	--disable-perlinterp \
	--disable-rubyinterp \
	--disable-tclinterp \
	--with-compiledby="hammer"
'''
compile = 'make -j"$(nproc)"'
# de package() de Alpine (traducido $pkgdir→/out):
install = '''
make -j1 DESTDIR="/out" install

install -Dm644 runtime/doc/uganda.txt \
	"/out/usr/share/licenses/vim/LICENSE"

# only relevant to gvim (no existen sin GUI)
rm -rf "/out"/usr/share/icons/ || true
rm -rf "/out"/usr/share/applications/ || true
'''

[deps]
build = ["ncurses", "linux-headers", "pkgconf", "make"]
