#!/bin/sh

source ../Config.sh

pp_clean_local () {
    pp_clean_default
    rm -f "${FW_TOPDIR}/bin/flex"
    rm -rf build-cross
    rm -rf build-native
}

pp_build_local () {
    # force configure
    if [ ! -f configure -o "$PP_FORCE_FULL_BUILD" = "1" ]; then
	echo "Running autoreconf ..."
	libtoolize --copy --force
	autoreconf -f -i
	#rm -f build-cross/Makefile
	rm -f build-native/Makefile
    fi

    # cross: configure
    # currently disabled - keep if needed sometime in the future
    #if [ ! -f build-cross/Makefile ]; then
	#echo "Running configure (cross) ..."
	#mkdir -p build-cross
	#cd build-cross
	#../configure \
	#	--host="${HOST_SYSTEM}" \
	#	--prefix=/
	#cd "$OLDPWD"
    #fi

    # cross: make /install
    # currently disabled - keep if needed sometime in the future
    #echo "Running make (cross) ..."
    #make -C build-cross install

    # native: configure
    unset CC LD CROSS CONFIG_SITE
    if [ ! -f build-native/Makefile ]; then
	echo "Running configure (native) ..."
	mkdir -p build-native
	cd build-native
	../configure
	cd "$OLDPWD"
    fi

    # native: make
    echo "Running make (native) ..."
    make -C build-native
    mkdir -p "${FW_TOPDIR}/bin"
    rm -f "${FW_TOPDIR}/bin/flex"
    ln -s ../flex/build-native/flex "${FW_TOPDIR}/bin/flex"
}

pp_do "$@"
