#! /bin/sh
# Utility script to generate basic description files for all ports.
# The main purpose of this script is to have a script that will
# exercise loading of all the ports.
#
#   Copyright 2012 Free Software Foundation
#
# This file 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 3 of the License, or
# (at your option) any later version.
# 
# This program 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 this program; see the file COPYING3.  If not see
# <http://www.gnu.org/licenses/>.
#

# Run this script in the src/cgen directory.

# Exit on any error.
set -e

# For debugging.
set -x

# List of top-level .cpu files of all ports.
# ??? Some are missing: ia32, ia64
# Need to add them after some research.
# NOTE: Some of these ports are incomplete.

archs="
cpu/fr30.cpu
cpu/arm.cpu
../cpu/cris.cpu
../cpu/frv.cpu
cpu/i960.cpu
cpu/ip2k.cpu
../cpu/iq2000.cpu
../cpu/lm32.cpu
../cpu/m32c.cpu
../cpu/m32r.cpu
cpu/m68k.cpu
cpu/mep.cpu
../cpu/mt.cpu
cpu/openrisc.cpu
cpu/powerpc.cpu
cpu/sh.cpu
cpu/sparc.cpu
../cpu/xc16x.cpu
cpu/xstormy16.cpu
"

if [ ! -f opcodes.scm ]
then
    echo "Not in the src/cgen directory." >& 2
    exit 1
fi

export builddir=tmp-desc

rm -rf $builddir
mkdir $builddir

export cgendir=`pwd`

(
  set -e
  set -x
  cd $builddir
  $cgendir/configure --prefix /tmp/junk --target m32r-elf

  for a in $archs
  do
    archfile=../$a
    arch=$(basename $archfile .cpu)

    # FIXME: Seems like this shouldn't be needed.  Could be wrong though.
    ISAS="all"
    MACHS="all"
    case $arch in
    arm) ISAS="arm" ;;
    sh) ISAS="media" ;;
    sparc) MACHS="sparc-v9" ;; # FIXME: ugh, would rather select on isa
    esac

    if make desc ARCH=$arch ARCHFILE=$archfile ISAS="$ISAS" MACHS="$MACHS" \
        CGENFLAGS='-b -v'
    then
        echo "File generation for $arch succeeded."
    else
        echo "ERROR: File generation for $arch failed."
    fi
  done
)
