| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 | #!/bin/bash## This is a trivial "compiler" for JTalk code. Run without arguments for help.# Get JTalk root directory from the location of this script.JTALK=`dirname ${0}`/..USAGE="Usage: $0 [-r] file1 file2 ... file3 Program   Will compile a JTalk program into a single javascript file called   <Program>.js by concatenating listed files using these rules:     *.js files are concatenated as is. If not found we look in $JTALK/js     *.st files are compiled into .js files. If not found we look in $JTALK/st.     Each file is currently considered to be a fileout of a single class     category of the same name as the file.     NOTE: boot.js and Kernel.js is always added first and init.js     is always added last. Finally main.js is added if found.     If -r is used we also run node with the resulting Program.js.     Example invocations:     Compile Hello.st to Hello.js and create     complete program called Program.js:        ntalkc Hello.st Program     Compile two different class categories into corresponding .js files,     link with two existing javascript libraries and create complete     program called Program.js:        ntalkc lib1.js lib2.js CategoryOne.st CategoryTwo.st Program"if [ "$#" == "0" ]; then	echo "$USAGE"	exit 1fiif [ $1 == "-r" ]; then  RUN=true  shiftfi# Get a unique tempdir and make sure it gets nuked laterTMPDIR=`mktemp -d`trap "rm -rf $TMPDIR" EXIT# Collect libraries and Smalltalk filesuntil [ "$*" = "" ]do  case $1 in     *.st)        CATEGORY=`basename $1 .st`        if [ -f "$1" ]; then           COMPILE="$COMPILE $1 $CATEGORY"           COMPILED="$COMPILED $CATEGORY.js"        else           if [ -f $JTALK/st/$1 ]; then             COMPILE="$COMPILE $JTALK/st/$1 $CATEGORY"             COMPILED="$COMPILED $CATEGORY.js"           else             echo "JTalk file not found: $1"           fi        fi        shift        ;;     *.js)        if [ -f "$1" ]; then           LIBS="$LIBS $1"         else           if [ -f $JTALK/js/$1 ]; then             LIBS="$LIBS $JTALK/js/$1"           else             echo "Javascript file not found: $1"           fi        fi        ;;  esac  # Will end up being the last argument  PROGRAM=$1  shiftdone# Create compiler dynamicallycat $JTALK/js/boot.js $JTALK/js/Kernel.js $JTALK/js/Parser.js $JTALK/js/Compiler.js $JTALK/js/init.js $JTALK/nodejs/nodecompile.js > $TMPDIR/compiler-all.js# Compile all collected .st files to .jsecho "Compiling$COMPILED ..."node $TMPDIR/compiler-all.js $COMPILE# Verify all .js files corresponding .st files were created, otherwise exitIFS=" "for FILE in $COMPILEDdo  if [ ! -f "$FILE" ]; then    echo "Failed compilation of $FILE, exiting."    exit 1  fi done# We must have these first...echo "Adding boot.js and Kernel.js ..."BOOT="$JTALK/js/boot.js $JTALK/js/Kernel.js"# Compose the complete libs.js file from collected .js filenames.if [ -n "$LIBS" ]; then  echo "Adding libraries $LIBS ..."  cat $LIBS > $TMPDIR/libs.js  LIBS=$TMPDIR/libs.jsfi# Check for init.jsif [ -f "init.js" ]; then  echo "Adding init.js ..."  INIT="init.js"else  echo "Adding $JTALK/js/init.js ..."  INIT=$JTALK/js/init.jsfi# Check for main.jsif [ -f "main.js" ]; then  echo "Adding main.js ..."  MAIN="main.js"fi# And finally concatenate Program.jsecho "Writing $PROGRAM.js ..."cat $BOOT $LIBS $COMPILED $INIT $MAIN > $PROGRAM.jsecho "Done."# Optionally run Program and give all args left to itif [ -n "$RUN" ]; then  echo "Running program"  echo "---------------"  node $PROGRAM.js $@fi
 |