makeJava again

Pavel Roskin pavel_roskin at geocities.com
Fri Nov 13 12:39:31 PST 1998


Hello!

I have corrected makeJava script in such way that it doesn't use "test"
command for timestamp comparision.
Now even /usr/old/bin/sh on HP-UX can run it.
Maybe some other changes will be needed, for example setting of default
srcdir (however it may be convenient to call makeJava from make and set
srcdir through the command line).
Of course, this script doesn't ensure that everything is rebuilt 
correctly, but I don't want to rebuild everything after I change two lines
in AppletViewer.

Pavel Roskin
-------------- next part --------------
#! /bin/sh
#
# Simple little script which builds the .class files which are older
# than the .java files.
#
# Exit codes: 0 - Ok, 1 - bad options, 2 - compile errors, 3 - fatal errors
#
# Copyright (c) 1997, 1998
#      Transvirtual Technologies, Inc.  All rights reserved.
#
# See the file "license.terms" for information on usage and redistribution
# of this file.
#

remap()
{
#	This is needed because java/awt/widgets/* goes to lib/java/awt/*
	echo $1 | sed 's/java\/awt\/widgets\//java\/awt\//'
}

get_args()
{
	arg_1=$1
	arg_2=$2
}

srcdir=.
dstdir=lib
alltopdirs="java kaffe"
batch=0
force=0
unsafe=0
otherargs=""
errorlist=""
batchlist=""

while test x$1 != x; do

case $1 in
-srcdir)
	if test x$2 = x; then
		echo argument to $1 missing
		exit 1
	fi
	srcdir=$2; shift; shift;;
-dstdir)
	if test x$2 = x; then
		echo argument to $1 missing
		exit 1
	fi
	dstdir=$2; shift; shift;;
-batch)
	batch=1; shift;;
-force)
	force=1; shift;;
-unsafe)
	unsafe=1; shift;;
-*)
	echo "usage: makeJava options {java files or directories}"
	echo "-srcdir path   where sources are placed (default is '.')"
	echo "-dstdir path   where compiled classes will be placed (default is 'lib')"
	echo "-force         don't check whether classes are newer than sources"
	echo "-unsafe        don't check whether classes are created"
	echo "-batch         compile newer sources alltogether (implies -unsafe)"
	echo "By default ./java/ and ./kaffe/ directories are used"
	exit 1;;
*)
	otherargs="$otherargs $1"
	shift;;
esac

done

get_args $otherargs
if test x"$arg_1" = x; then
	otherargs=$alltopdirs
fi

files=""
for file in $otherargs; do
	if test -f $srcdir/$file; then
		files="$files $file"
	elif test -f $srcdir/${file}.java; then
		files="$files ${file}.java"
	elif test -d $srcdir/$file; then
		files="$files `cd $srcdir; find $file -type f -name \*.java -print`"
	else
		echo File or directory $srcdir/$file not found
		exit 1
	fi
done

get_args $files
if test x"$arg_1" = x; then
	echo No files found
	exit 1
fi

if test "$JAVA" = "" ; then
	JAVA="kaffe -ms 8M -mx 64M"
fi

if test "$JAVAC" = "" ; then
	JAVAC="$JAVA pizza.compiler.Main"
fi

if test "$JAVAC_CP" = "" ; then
	JAVAC_CP="$dstdir:$srcdir/Klasses.jar"
fi

if test "$JFLAGS" = "" ; then
	JFLAGS="-verbose"
fi

if test "$JAVAC_CP" != "none" ; then
	JFLAGS="-classpath $JAVAC_CP $JFLAGS"
fi

for file in $files
do
	jf=$srcdir/$file
	cf=$dstdir/`echo $file | sed s/\\.java$//`.class
	cf=`remap $cf`
	docompile=0
	if test ! -f $cf ; then
		docompile=1
	else
		get_args `ls -t $cf $jf`
		if test $force = 1 || test x"$arg_1" = x"$jf" ; then
			docompile=1
		fi
	fi
	if test "$docompile" = "1" ; then
		outdir=`dirname $cf`
		if test ! -d $outdir; then
			echo Creating directory $outdir
			mkdir -p $outdir
		fi
		if test $batch = 1; then
			batchlist="$batchlist $jf"
		else
			echo "Compiling $jf"
			$JAVAC $JFLAGS -d $dstdir $jf
			if test $? = 0; then
				if test -f $cf; then
					echo "done"
				elif test $unsafe = 0; then
					echo Fatal error while processing $jf
					echo belonging to `grep ^package $jf`
					exit 3
				fi
			else
				if test x"$errorlist" = x; then
					errorlist="$jf"
				else
					errorlist="$errorlist $jf"
				fi
				echo "not done"
			fi
		fi
	fi
done

if test $batch = 1; then
	get_args $batchlist
	if test x"$arg_1" = x; then
		echo "Everything seems to be up-to-date"
		exit 0
	else
		echo "Compiling $batchlist"
		$JAVAC $JFLAGS -d $dstdir $batchlist
		if test $? = 0; then
			echo "done"
		else
			echo "not done"
		fi
	fi
elif test x"$errorlist" != x; then
	echo There were errors while compiling:
	echo $errorlist
	exit 2
else
	echo No errors encountered
fi


More information about the kaffe mailing list