#! /bin/sh

# Windows can sort of run EPOC executables -- they just return 0.
# In consequence, "configure" doesn't know that we are cross-compiling.
# This program patches "configure" to cross-compile unconditionally.
#
# Replace
#
#   DIR/configure ARGS...
#
# with
#
#   emx-config-cross DIR ARGS...
#

usage()
{
  echo "Usage: emx-config-cross DIRECTORY [ARGUMENT]..."
  exit 2
}

test $# -ge 1 || usage
dir="$1"
shift
cat "$dir"/configure >/dev/null || exit 2
mv -f "$dir"/configure "$dir"/configure.orig || exit 2
sed 's/ac_cv_prog_cc_cross=no/ac_cv_prog_cc_cross=yes/' "$dir"/configure.orig >"$dir"/configure || exit 2
chmod 755 "$dir"/configure || exit 2
touch -r "$dir"/configure.orig "$dir"/configure || exit 2
"$dir"/configure "$@"
rc=$?
mv -f "$dir"/configure.orig "$dir"/configure || exit 2
exit $rc
