#!/bin/sh -ue
NAME=netbsd-curses
VERSION=git
RELEASE=1
SOURCE="https://github.com/sabotage-linux/netbsd-curses.git"

build() {
	msg "building netbsd-curses..."
	gmake -j"$NPROC" \
		PREFIX="$PREFIX" \
		CC="cc -static" \
		HOSTCC="cc -static" \
		CFLAGS="${CFLAGS:--O2 -pipe}" \
		all-static || die "gmake all-static failed"

	msg "installing netbsd-curses..."
	gmake -j"$NPROC" \
		PREFIX="$PREFIX" \
		CC="cc -static" \
		CFLAGS="${CFLAGS:--O2 -pipe}" \
		LDFLAGS="${LDFLAGS:--static}" \
		DESTDIR="$PKG" \
		install-static || die "gmake install-static failed"

	msg "creating compatibility symlinks..."
	mkdir -p "$PKG/$PREFIX/lib" "$PKG/$PREFIX/include"
	[ -f "$PKG/$PREFIX/lib/libcurses.a" ] && ln -sf libcurses.a "$PKG/$PREFIX/lib/libncurses.a"
	[ -f "$PKG/$PREFIX/lib/libcurses.a" ] && ln -sf libcurses.a "$PKG/$PREFIX/lib/libncursesw.a"
	[ -f "$PKG/$PREFIX/lib/libterminfo.a" ] && ln -sf libterminfo.a "$PKG/$PREFIX/lib/libtinfo.a"
	[ -f "$PKG/$PREFIX/include/curses.h" ] && ln -sf curses.h "$PKG/$PREFIX/include/ncurses.h"
	mkdir -p "$PKG/$PREFIX/include/ncurses" "$PKG/$PREFIX/include/ncursesw"
	[ -e "$PKG/$PREFIX/include/ncurses/curses.h" ] || ln -sf ../curses.h "$PKG/$PREFIX/include/ncurses/curses.h"
	[ -e "$PKG/$PREFIX/include/ncursesw/curses.h" ] || ln -sf ../curses.h "$PKG/$PREFIX/include/ncursesw/curses.h"
}

. ${0%/*}/../../libsh/libdmake.sh
