Compiling Vassal from the Command Line on MacOS

I wanted to share the following script/Makefile that compiles VASSAL from the command-line on MacOS. It uses basic Unix utilities to parse through the directories in the distribution recursively, and finds all of the necessary .java files and bundles them into a lengthy command-line file that compiles the software from scratch without the need for an IDE. A second file is also created that can be used to run the software.

Sharing in case it will be of use to those familiar with command-line editing but not Java experts. The script requires that people already have java/javac installed on their machines, but doesn’t need any messing around with Netbeans, etc.

#
# Clean up any legacy files from the last 
# time we ran this script if necessary
#
if [ -e mac.make.temp1 ]
then
  rm mac.make.temp1
fi
if [ -e mac.make.temp2 ]
then
  rm mac.make.temp2
fi
if [ -e mac.make.temp3 ]
then
  rm mac.make.temp3
fi
if [ -e mac.make.java_files ]
then
  rm mac.make.java_files
fi
if [ -e mac.make.class_files ]
then
  rm mac.make.class_files
fi
if [ -e mac.make.compile ]
then
  rm mac.make.compile
fi
if [ -e src/mac.make.run ]
then
  rm src/mac.make.run
fi




#
# Print Reassuring Message
#
echo '
Generating Makefile....'



#
# Create file containing all sub-directories
# found within this folder
#
ls -R -1 ./* > mac.make.temp1



#
# Parse that file for only the directory
# entries. We will subsequently search 
# directory by directory for files in 
# these folders
#
grep ":" mac.make.temp1 > mac.make.temp2



#
# Loop through folders and rename them to
# absolute file paths, so that we can search
# them for ava files
#
# Generate a file containing nothing but
# the directories in which we want to 
# find our *.class and *.java files.
while read p; do
  len=${#p}
  echo $PWD${p:1:len-2} >> mac.make.temp3
done < mac.make.temp2



#
# generate separate files containing only
# our java files
#
while read p; do
  ls ${p}/*.java 2>/dev/null >> mac.make.java_files
done < mac.make.temp3



#
# create the javac command 
#
echo 'javac -classpath "lib/*:lib-eth/*:lib-nondist/*" @mac.make.java_files ' >> mac.make.compile



#
# Print Reassuring Message
#
echo '
Compiling VASSAL from the command-line means going through
all of the directories included in this software package
to find all of the .java files that need to be compiled. 
We have just done this and generated a script that will 
automate the compilation process using the default Java
compiler on your system:

  ./mac.make.compile

The default VASSAL code triggers a few error messages, but
nothing critical. If you need to recompile the software you
can simply re-execute this script from this directory.

Compiling....

';



#
# compile
#
chmod +x mac.make.compile
./mac.make.compile


#
# generate separate files containing only
# our class files
#
while read p; do
  ls ${p}/*.class 2>/dev/null >> mac.make.class_files
done < mac.make.temp3



#
# create the java runtime 
#
echo -n 'java -classpath "../lib/*:../lib-nondist/*:' >> src/mac.make.run
while read p; do
  echo -n ${p} >> src/mac.make.run
  echo -n ":" >> src/mac.make.run
done < mac.make.class_files
echo '" VASSAL/launch/EthereumModuleManager' >> src/mac.make.run
chmod +x src/mac.make.run



#
# Print Reassuring Message
#
echo '


Now that the software has compiled we have created
another command-line file you can use to start running
it. Enter the /src directory and run:

 ./mac.make.run

Remember that if you need to make any changes to the 
code base you will need to recompile from scratch.

';

Thus spake trevelyan:

I wanted to share the following script/Makefile that compiles VASSAL
from the command-line on MacOS. It uses basic Unix utilities to parse
through the directories in the distribution recursively, and finds all
of the necessary .java files and bundles them into a lengthy
command-line file that compiles the software from scratch without the
need for an IDE. A second file is also created that can be used to run
the software.

Sharing in case it will be of use to those familiar with command-line
editing but not Java experts. The script requires that people already
have java/javac installed on their machines, but doesn’t need any
messing around with Netbeans, etc.

Did you not notice that we already have a Makefile?


J.

The Makefile provided uses some options that aren’t supported by the MacOS versions of certain tools, for example find’s -printf, or not supplying an extension to sed’s -i. It might work better using alternate versions of those tools through fink or macports or something, but I haven’t tried.

Thus spake Malnorma:

The Makefile provided uses some options that aren’t supported by the
MacOS versions of certain tools, for example find’s -printf, or not
supplying an extension to sed’s -i. It might work better using
alternate versions of those tools through fink or macports or something,
but I haven’t tried.

In future, I expect we’ll use autotools for generating the Makefile,
which papers over those differences.

J.