#!/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 [ x"$1" = x"-h" ] || [ x"$1" = x"--help" ]; then
  cat << EOF
Usage: `basename "$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 pascal.check-long rather than pascal.check
  -m          Make pascal.check-nomsg rather than pascal.check
EOF
  exit
fi

if [ x"$GPC_SRCDIR" = x ]; 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"

if [ x"$1" = x"-n" ]; then
  TARGET2="nop"
  shift
fi
if [ x"$1" = x"-c" ]; then
  TARGET1="nop"
  shift
fi
if [ x"$1" = x"-t" ]; then
  TARGET1="pascal.check-long"
  shift
fi
if [ x"$1" = x"-m" ]; then
  TARGET1="pascal.check-nomsg"
  shift
fi

if [ x"$TARGET1" != x"nop" ]; then
  if [ $# -ge 1 ]; then
    make -s -f "$TESTDIR/Makefile" srcdir="$TESTDIR" $TARGET1 "MASK=$*"
  else
    make -s -f "$TESTDIR/Makefile" srcdir="$TESTDIR" $TARGET1
  fi
fi

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