#!/bin/sh

# Copyright (C) 2000 Free Software Foundation, Inc.
#
# Authors: Peter Gerwinski <peter@gerwinski.de>
#          Frank Heckenbach <frank@pascal.gnu.de>
#
# This file is part of GNU Pascal.
#
# GNU Pascal is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# GNU Pascal is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Pascal; see the file COPYING.  If not, write to
# the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
  cat << EOF
Usage: $0 [options] [file...]
Options (must be given in this order!):
  -h, --help  Display this help and exit
  -n          Don't make extraclean after testing
  -c          Don't test, just make extraclean
  -t          Make check-gpc-long rather than summary
EOF
  exit
fi

if [ -z "$GPC_SRCDIR" ]; then
  echo "GPC_SRCDIR must be set" >&2
  exit 1
fi

if [ -e $GPC_SRCDIR/gcc/p/gpc.c ]; then
  TESTDIR=$GPC_SRCDIR/gcc/p/test
elif [ -e $GPC_SRCDIR/p/gpc.c ]; then
  TESTDIR=$GPC_SRCDIR/p/test
else
  echo "Invalid GPC_SRCDIR" >&2
  exit 1
fi

export DJGPP_NO_OUT=

TARGET1=""
TARGET2="extraclean"
MASK="DUMMY=OPTION"

if [ "$1" = "-n" ]; then
  TARGET2="nop"
  shift
fi
if [ "$1" = "-c" ]; then
  TARGET1="nop"
  shift
fi
if [ "$1" = "-t" ]; then
  TARGET1=check-gpc-long
  shift
fi
if [ "$*" ]; then
  MASK="MASK=$*"
fi

if [ "$TARGET1" != "nop" ]; then make -s -f $TESTDIR/Makefile srcdir=$TESTDIR $TARGET1 "$MASK"; fi
if [ "$TARGET2" != "nop" ]; then make -s -f $TESTDIR/Makefile srcdir=$TESTDIR $TARGET2; fi
