#!/bin/sh
# This is a script used for cross-compiling.  It sets up the preprocessor
# environment for the desired architecture, after unsetting the one for
# the existing one, before calling the real cpp.
#
# The first argument is the name of the compiling architecture.
# The second argument is the name of the target architecture.
# Both must be have been installed by ../configure.
#
# Note: We are assuming (as is ../configure) that no architecture ends in .undef

# Figure out CC (taken from realconfigure)
ARCH=`../../config/config.guess`
TYPE=`echo ${ARCH} | awk -F'-' '{ print $2 }'`
if [ "$TYPE" = "apple" ]; then
  CC="cc -no-cpp-precomp"
else
  for comp in gcc cc; do
    CC=`which $comp 2> /dev/null`
    if [ -n "$CC" -a -x "$CC" ]; then
      CC=$comp
      break
    fi
  done
fi

CPP="$CC -w -x c -E -U__GNUC__ -nostdinc"

if [ $# -lt 3 ]; then
  echo usage: $0 this_architecture target_architecture
  exit 1
else

SOURCE=$1
TARGET=$2
shift
shift

ARCHDIR=$CYCDIR/config/arch

$CPP -include $SOURCE.undef -include $TARGET $*
fi

