#!/bin/sh

exit_with_usage ()
{
    echo "Usage: $0 --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--help"
    exit 1
}

prefix="/tmp/necessitas/ndk-build/build/host-python/install/prebuilt/darwin-x86"
exec_prefix="${prefix}"
includedir="${prefix}/include"
VERSION="2.7"
#libdir="${exec_prefix}/lib"
libdir=$prefix/lib/python$VERSION/config
LIBM=""
LIBC=""
SYSLIBS="$LIBM $LIBC"
LIBS="-ldl  -lpthread -framework CoreFoundation $SYSLIBS -lpython$VERSION"
ABIFLAGS="@ABIFLAGS@"
BASECFLAGS=" -fno-strict-aliasing"
CFLAGS="-O2 -Os -fomit-frame-pointer -s"
LDLIBRARY="libpython${VERSION}.a"
LINKFORSHARED="-u _PyMac_Error"
OPT="-DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes"

for ARG in $*
do
    case $ARG in
        --prefix)
            echo $prefix
            exit 0
        ;;
        --exec-prefix)
            echo $exec_prefix
            exit 0
        ;;
        --includes)
            echo -I$includedir/python$VERSION
            exit 0
        ;;
        --libs)
            echo $LIBS
            exit 0
        ;;
        --cflags)
            echo -I$includedir/python$VERSION $BASECFLAGS $CFLAGS $OPT
            exit 0
        ;;
        --ldflags)
        # I'm not handling the case of not Py_ENABLE_SHARED here.
        # As there's no AC_SUBST for Py_ENABLE_SHARED (though I should just
        # add that to be honest with you!)
        # From python-config there's:
        # if not getvar('Py_ENABLE_SHARED'):
        #     libs.insert(0, '-L' + getvar('LIBPL'))
        #     libs.extend(getvar('LINKFORSHARED').split())
            echo -L$libdir $LIBS $LINKFORSHARED
            exit 0
        ;;
        *.py)
        # configuring GDB uses:
        # ${python_prog} ${srcdir}/python/python-config.py --includes
        # so skip any .py files passed as arguments.
        ;;
        *)
            exit_with_usage
        ;;
esac
done
