[antlr-interest] Cygwin build env/ files - was Re: Problem to run Beta 4

Zenaan Harkness zen at freedbms.net
Tue Sep 19 16:03:20 PDT 2006


I prefer being in cygwin when I have to be on windows (mutt, grep,
find etc etc), but Java 1.5/5 broke my old build scripts.

Here are the files I have built up over quite some time, for those
who might find them useful.

I also recommend GNU Screen. If anyone needs a Cygwin ready
.screen conf, just ask. For cygwin, I set up XFree and use XTerms
rather than Bash console for Windows, since I can arbitrarily
resize the xterms with mouse.

Cheers
Zenaan


--- ~/bin/go.sh (this makes it easy to get into my working directory):
$ cat /home/zen/bin/go.sh 
#!/bin/sh
# run with ". ~/bin/go.sh"
BASED="/home/zen/my/working/dir"
cd $BASED
. $BASED/conf/env


--- Then, inside ~/my/working/dir, I have the following:
bin/[build,clean,run,etc]
conf/[env,env.path,etc]
doc/
lib/[antlr.jar,st.jar,log4j.jar,yaml.jar,etc]
out/[output of build files]
src/[all inputs to build process - my java packages, conf/, data/ etc]


--- conf/env.path:
$ cat conf/env.path
#!/bin/bash
# to use this file, source it, eg. ". conf/env.sh

JDKBASE="/cygdrive/c/Program Files/Java/jdk1.5.0_08"

PATH=./bin:$JDKBASE/bin:$PATH

export PATH
export BUILDPATH_DEFINED="true"


--- conf/env (aliases j and jc to run java & javac manually,
--- instead of via bin/build and bin/run, which is useful):
--- Note: even though I use these files by sourcing them instead
--- of running them, having the first line makes for nice
--- highlighting when editing.
$ cat conf/env
#!/bin/bash
# to use this file, source it, eg. ". conf/env.sh". For debugging,
# use first line "#!/bin/bash -x"

if [ ! $BUILDPATH_DEFINED ]; then
   . conf/env.path
fi

# Project directories:
CONF=conf
DOC=doc
BIN=bin
LIB=lib
SRC=src
OUT=out
TEMP=$OUT/tmp

BASED=`pwd`

# There are two $CONF directories, src/$CONF and simply $CONF;
# src/$CONF contains release files:
CONFD=$BASED/$SRC/$CONF
TEMPD=$BASED/$TEMP
DOCD=$BASED/$DOC
BIND=$BASED/$BIN
LIBD=$BASED/$LIB
SRCD=$BASED/$SRC
OUTD=$BASED/$OUT

# This should be relative, but at least with SUN's javac from JDK
# 1.5.0_08 on cygwin, paths must be absolute:
CLASSPATH=$LIBD/yaml.jar:$LIBD/st.jar:$LIBD/antlr.jar:$LIBD/foj.jar:$LIBD/log4j.jar
CLASSPATH_LOCAL="`cygpath -wp \"$CLASSPATH:$OUTD\"`"

# Because javac 1.5.0_08 is so flaky with respect to CLASSPATH (at
# least on cygwin/msw),
# we must have separate commends, slightly different, for JAVAC
# and for alias jc:
   JAVAC="javac -d $OUT -sourcepath $SRC -cp $CLASSPATH_LOCAL"
alias jc="javac -d $OUT -sourcepath \"$SRC\" -cp \"$CLASSPATH_LOCAL\""

   JAVA="java -cp $CLASSPATH_LOCAL"
alias j="java -cp \"$CLASSPATH_LOCAL\""

export CONF TEMP DOC BIN LIB SRC OUT BASED CONFD TEMPD DOCD
export BIND LIBD SRCD OUTD CLASSPATH CLASSPATH_LOCAL

# Signal that environment is now configured:
export CONFENV="true"


--- bin/clean, to clean up my build output dir:
$ cat bin/clean
#!/bin/bash
. conf/env
if [ ! -d $OUT ]; then
   exit 0
fi
cd $OUT
# You may prefer to delete everything in out, in which case just rm -rf it.
TODELETE="conf log4j.properties test tmp dir1 package2 etc"
for i in $TODELETE; do
   if [ -d $i ]; then
      rm -r $i
   fi
   if [ -a $i ]; then
      rm $i
   fi
   # Cygwin has a bug where it returns false for existence check (generic)
   # against symlinked file:
   if [ -h $i ]; then
      rm $i
   fi
done


--- bin/build - this is the guts of the funkiness for cygwin, besides conf/env:
$ cat bin/build 
#!/bin/bash
#!/bin/bash -x

bin/clean

. conf/env

# Auto in-code output build-versioning feature:
# File containing template string, located in $SRC subdirectory:
SED_FILE="package/InterfaceContainingVersionString.java"
# Template string - use this in the SED_FILE file(s):
TEMPLATE_STRING="SED_version"
# Replacement version string:
VERSION_STRING=`date +%Y%m%d-%H.%M`
# Text file to create containing just the version string:
VERSION_FILENAME="build-version"

# Files to be compiled by javac:
JAVA_FILES="test/TestYaml.java"

# HTML files to be processed during build, to create output (todo):
#HTML_FILES="index.html"

if [ ! -d $SRC ]; then
   echo "There is no $SRC/ directory - cannot compile anything. Are you in a
working tree?"
   exit 1
fi 
echo "Building ..."

# prepare new version/date string:
SRC_SED_FILE=$SRCD/$SED_FILE
DST_SED_FILE=$TEMPD/$SED_FILE

echo "Munging version strings: $SED_FILE"
SED_DIR=`dirname $DST_SED_FILE`
if [ ! -d $SED_DIR ]; then
   mkdir -p $SED_DIR
fi
sed -e "s#$TEMPLATE_STRING#$VERSION_STRING#g;" $SRC_SED_FILE > $DST_SED_FILE

# Create text file which contains the version string:
VERSION_FILE=$DSTD/$VERSION_FILENAME
if [ -e $VERSION_FILE ]; then
   rm $VERSION_FILE
fi 
echo "$VERSION_STRING" > $VERSION_FILE

# conf/ Log4j configuration:
cd $OUTD
if [ ! -d $CONF ]; then
   echo "Copying: cp $SRC/$CONF $OUT/$CONF/"
   cp --recursive --dereference $CONFD .
   # log4j.properties (WARNING, on cygwin, DO NOT SYMLINK! file cannot be
   # read by log4j in such case!):
   cp $CONF/logger log4j.properties
fi

# compile java files
echo
cd $BASED
ALL_FILES=$TEMP/$SED_FILE
for i in $JAVA_FILES; do
   ALL_FILES="$ALL_FILES $SRC/$i"
done
echo "Compiling: $ALL_FILES"
$JAVAC $ALL_FILES

echo "... done."


--- bin/run - final convenience:
$ cat bin/run 
#!/bin/bash
. conf/env
#cd $OUT
RUNCLASS=test.TestYaml
#echo $JAVA $RUNCLASS
$JAVA $RUNCLASS \
   $*


Of course, you must also have src/conf/logger for the log4j bit to
work.

Hope that's useful - took me a while to get these scripts to this
point, so perhaps this will save someone else the little
frustrations along the way.

Regards
Zen


-- 
Free Australia - www.UPMART.org
Please respect the confidentiality of this email as sensibly warranted.


More information about the antlr-interest mailing list