#!/bin/sh

rm -f a.out

TMPFILE=/tmp/COMPILE.$$
OUTPUT=/tmp/MODULE.gpslib.$$

mv config.h config.h.orig
cat > config.h <<EOF
#define EARTHMATE_ENABLE 1
#define EVERMORE_ENABLE 1
#define FV18_ENABLE 1
#define GARMIN_ENABLE 1
#define HAVE_ALLOCA 1
#define HAVE_ALLOCA_H 1
#define HAVE_DAYLIGHT 1
#define HAVE_DLFCN_H 1
#define HAVE_GETOPT_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_MEMORY_H 1
#define HAVE_ROUND 1
#define HAVE_STDINT_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRINGS_H 1
#define HAVE_STRING_H 1
#define HAVE_STRUCT_TM_TM_ZONE 1
#define HAVE_SYS_IPC_H 1
#define HAVE_SYS_SELECT_H 1
#define HAVE_SYS_SHM_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_SYS_TERMIOS_H 1
#define HAVE_SYS_TIME_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_TERMIOS_H 1
#define HAVE_TIMEZONE 
#define HAVE_TM_ZONE 1
#define HAVE_UNISTD_H 1
#define HAVE_X11_XPM_H 1
#define HAVE_XPM 1
#define ITALK_ENABLE 1
#define ITRAX_ENABLE 1
#define NMEA_ENABLE 1
#define NTPSHM_ENABLE 1
#define PACKAGE "gpsd"
#define PACKAGE_BUGREPORT ""
#define PACKAGE_NAME ""
#define PACKAGE_STRING ""
#define PACKAGE_TARNAME ""
#define PACKAGE_VERSION ""
#define PPS_ENABLE 1
#define SIRFII_ENABLE 1
#define STDC_HEADERS 1
#define TIME_WITH_SYS_TIME 1
#define TRIPMATE_ENABLE 1
#define TSIP_ENABLE 1
#define VERSION "2.32"
#define X_DISPLAY_MISSING 1
#  define UNUSED __attribute__((unused)) /* Flag variable as unused */
EOF
grep 'CC:' gpsd.c > $TMPFILE
cat $TMPFILE
chmod +x $TMPFILE
$TMPFILE
mv config.h.orig config.h
rm -f $TMPFILE
if [ ! -x a.out ]; then
    echo ERROR
    echo "Test failed."
    exit 1
fi

export WORKING_DIR=`pwd`

$TRACE $WORKING_DIR/a.out
if [ $? != "0" ]; then
  echo ERROR
  exit 1
fi

echo "Test OK"
rm -f a.out
rm -f $OUTPUT
exit 0
