#! /bin/sh

# by Alexandre Oliva <oliva@dcc.unicamp.br>
# updated by Edouard G. Parmelan <egp@free.fr>

# This script can be used to update the list of class files to
# compiled into rt.jar and included in the Kaffe distribution.
# Whenever you add or remove a file, run this script from within
# kaffe-src/libraries/javalib

# set LC_ALL to C to get the same sort order on all systems
export LC_ALL=C

if test -f Makefile.am.in &&
   SRCDIRS=`sed -n '/^SRCDIRS *= */ s///p' < Makefile.am.in` > /dev/null; then :
else
    echo update-class-list must be run from within a javalib directory >&2
    exit 1
fi

trap 'rm -f classlist pkglist macrodef; exit 1' 1 2 15

find $SRCDIRS -name \*.java -print | sort > classlist


sed 's,/[^/]*$,,' < classlist | sort | uniq > pkglist

{
  sed 's,^,	$(,;s,$,_SRCS) \\,;$s, \\$,,;s,[-/],_,g' < pkglist

  while read pkg; do
    echo "${pkg}_SRCS = \\" | sed 's,[-/],_,g'
    grep "^${pkg}/[^/]*$" < classlist | sed 's/^/	/;s/$/ \\/;$s/ \\$//'
  done < pkglist
} > macrodef


rm -f classlist pkglist

sed '
/^'"Klasses_jar_SRCS"'/ {
    p
    r macrodef
}
/^'"Klasses_jar_SRCS"'/,/^$/ d
' < Makefile.am.in > Makefile.am

rm -f macrodef

exit 0
