#!/bin/sh

. config/options

CWD=`pwd`

setup_toolchain host

cd $PKG_BUILD/ncurses-host
./configure

make -C include
make -C progs tic

cp -PR progs/tic $ROOT/$TOOLCHAIN/bin

cd "$CWD"

setup_toolchain target

$SCRIPTS/build toolchain

cd $PKG_BUILD
./configure --host=$TARGET_NAME \
            --build=$HOST_NAME \
            --prefix=/usr \
            --sysconfdir=/etc \
            --with-build-cc=$HOST_CC \
            --with-build-cppflags="$HOST_CPPFLAGS -I../include" \
            --with-build-cflags="$HOST_CFLAGS" \
            --with-build-ldflags="$HOST_LDFLAGS" \
            --without-cxx \
            --without-cxx-binding \
            --without-ada \
            --without-progs \
            --with-shared \
            --without-normal \
            --without-debug \
            --without-profile \
            --with-termlib \
            --without-dbmalloc \
            --without-dmalloc \
            --without-gpm \
            --disable-rpath \
            --disable-overwrite \
            --enable-database \
            --disable-big-core \
            --enable-termcap \
            --enable-getcap \
            --disable-getcap-cache \
            --disable-bsdpad \
            --without-rcs-ids \
            --enable-ext-funcs \
            --disable-const \
            --enable-no-padding \
            --disable-sigwinch \
            --disable-tcap-names \
            --without-develop \
            --disable-hard-tabs \
            --disable-xmc-glitch \
            --disable-hashmap \
            --enable-safe-sprintf \
            --disable-scroll-hints \
            --disable-widec \
            --disable-echo \
            --disable-warnings \
            --disable-assertions

make -C include
make -C ncurses
make -C panel
make -C menu
make -C form

$AR cru lib/libncurses.a obj_s/*.o

$MAKEINSTALL -C include
$MAKEINSTALL -C ncurses
$MAKEINSTALL -C panel
$MAKEINSTALL -C menu
$MAKEINSTALL -C form

cp $SYSROOT_PREFIX/usr/include/ncurses/curses.h \
   $SYSROOT_PREFIX/usr/include/ncurses/term.h \
   $SYSROOT_PREFIX/usr/include/
