[4414] in java-interest

home help back first fref pref prev next nref lref last post

fix to UNIX make script

daemon@ATHENA.MIT.EDU (R.Volkmann)
Fri Dec 22 13:17:37 1995

Date: Fri, 22 Dec 1995 10:41:18 -0600
From: "R.Volkmann" <m224873@svxtrm17.mdc.com>
To: java-interest@java.sun.com
Reply-To: "R. Mark Volkmann"<m224873@svmstr01.mdc.com>

How embarassing!  I posted a script with a bug in it.
I was trying to set a variable in the -exec part of a find command
but you can't do that and see the result in subsequent commands.
Here's the fixed version.

#!/bin/sh
#-------------------------------------------------------------------------------
# Name:   make
# Author: Mark Volkmann
# EMail:  m224873@svmstr01.mdc.com
#
# This script compiles all Java programs in the current directory if needed.
# The CLASSES enviroment variable must be set to indicate where the .class
# files of packages should be placed.
#
# NOTE: Because no attempt is being made to track the dependencies between
#       source files, ordering of the compiles can affect their success.
#       If one file imports another that will be compiled after it then it
#       may be necessary to run this script again to get a successful compile.
#
# NOTE: In shell 0 is true and 1 is false.
#-------------------------------------------------------------------------------

options="" # Put options which should be used for all compiles here.

if [ "$CLASSES" = "" ]
then
    echo "The environment variable CLASSES must be set to the directory"
    echo "where the .class files of packages should be placed."
    exit 1
fi

# For each .java file in the current directory ...
for javaFile in *.java
do
    # Determine the name of the corresponding .class file.
    name=`echo $javaFile | cut -f1 -d.`
    classFile=$name.class

    # If the .java file contains a package statement ...
    package=`grep package $javaFile`
    if [ $? -eq 0 ]
    then
        # Strip off the word package and the semi-colon at the end, then
        # change the periods to slashes.
        subDir=`echo $package | cut -f2 -d" " | cut -f1 -d";" | \
               sed -e 's/\./\//g'`
        classFile="$CLASSES/$subDir/$classFile"
        opt="$options -d $CLASSES"
    else
        opt=$options
    fi

    # If the .class file exists ...
    if [ -s $classFile ]
    then
        # If the .java file is newer than the .class file then delete the
        # class file.
        find . -name $javaFile -newer $classFile -exec rm $classFile \;
    fi

    # If there is no .class file then compile the .java file.
    if [ ! -s $classFile ]
    then
        echo "---"
        echo "compiling $javaFile to produce $classFile"
        javac $opt $javaFile
    fi
done

|------------------------------------------------------------|
| R. Mark Volkmann - Principal Specialist Programmer/Analyst |
| McDonnell Douglas Aerospace, St. Louis, Missouri, USA      |
| email m224873@svmstr01.mdc.com, voice (314)232-0498        |
|------------------------------------------------------------|
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post