#!/bin/sh

source ../Config.sh

PP_PUBLIC_INCLUDES="gettext-runtime/intl/libintl.h"

pp_clean_local () {
    cd gettext-runtime
    pp_clean_default
    # force autoreconf
    rm -f configure
    cd "$OLDPWD"
}

pp_build_local () {

    # we only need the runtime stuff
    cd gettext-runtime

    # force configure
    if [ ! -f configure -o "$PP_FORCE_FULL_BUILD" = "1" ]; then
	echo "Running autoreconf ..."
	libtoolize --copy --force
	autoreconf -f -i
	rm -f Makefile
    fi

    # configure
    if [ ! -f Makefile ]; then
	echo "Running configure ..."
	if [ "${PP_FEAT_STANDALONE_VIEWER}" = "1" ]; then
	    STATIC_SWITCH=--enable-static
	    SHARED_SWITCH=--disable-shared
	else
	    STATIC_SWITCH=--disable-static
	    SHARED_SWITCH=--enable-shared
	fi
	./configure \
		--host="$HOST_SYSTEM" \
		--prefix=/ \
		--disable-rpath \
		--with-included-gettext \
		${STATIC_SWITCH} \
		${SHARED_SWITCH}
	sed -i -e "s,^\(sys_lib_search_path_spec=\).*,\1\"$DESTDIR/lib $DESTDIR/usr/lib\"," libtool
    fi

    # make / install
    echo "Running make ..."
    make config.h
    if grep -q "^#define HAVE_SETLOCALE" config.h; then
	sed -i -e 's,^#define HAVE_SETLOCALE.*,#undef HAVE_SETLOCALE,' config.h
    fi
    make install

    # delete installed libtool files
    for f in `find . -name \*.la`; do
	rm -f $DESTDIR/lib/`basename $f`
    done

    # back to component root
    cd "$OLDPWD"
}

pp_do "$@"
