ntalkc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. # Get JTalk root directory
  3. JTALK=`dirname ${0}`/..
  4. USAGE="Usage: $0 [-r] file1 file2 ... file3 Program
  5. Will compile a JTalk Program.js file by concatenating listed files:
  6. *.js files are concatenated as is. If not found we look in $JTALK/js
  7. *.st files are compiled into .js files. If not found we look in $JTALK/st.
  8. Each file is considered to be a single class category of the same name.
  9. NOTE: boot.js and Kernel.js is always first and init.js
  10. is always added just before the last file. Finally main.js is added if found.
  11. "
  12. if [ "$#" == "0" ]; then
  13. echo "$USAGE"
  14. exit 1
  15. fi
  16. if [ $1 == "-r" ]; then
  17. RUN=true
  18. shift
  19. fi
  20. # Get a unique tempdir and make sure it gets nuked later
  21. TMPDIR=`mktemp -d`
  22. trap "rm -rf $TMPDIR" EXIT
  23. # Collect libraries and Smalltalk files
  24. until [ "$*" = "" ]
  25. do
  26. case $1 in
  27. *.st)
  28. CATEGORY=`basename $1 .st`
  29. if [ -f "$1" ]; then
  30. COMPILE="$COMPILE $1 $CATEGORY"
  31. COMPILED="$COMPILED $CATEGORY.js"
  32. else
  33. if [ -f $JTALK/st/$1 ]; then
  34. COMPILE="$COMPILE $JTALK/st/$1 $CATEGORY"
  35. COMPILED="$COMPILED $CATEGORY.js"
  36. else
  37. echo "JTalk file not found: $1"
  38. fi
  39. fi
  40. shift
  41. ;;
  42. *.js)
  43. if [ -f "$1" ]; then
  44. LIBS="$LIBS $1"
  45. else
  46. if [ -f $JTALK/js/$1 ]; then
  47. LIBS="$LIBS $JTALK/js/$1"
  48. else
  49. echo "Javascript file not found: $1"
  50. fi
  51. fi
  52. ;;
  53. esac
  54. # Will end up being the last argument
  55. PROGRAM=$1
  56. shift
  57. done
  58. # Create compiler
  59. cat $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
  60. # Compile all collected .st files to .js
  61. node $TMPDIR/compiler-all.js $COMPILE
  62. # Compose the complete libs.js file
  63. if [ -n "$LIBS" ]; then
  64. echo "LIBS $LIBS"
  65. cat $LIBS > $TMPDIR/libs.js
  66. LIBS=$TMPDIR/libs.js
  67. fi
  68. # Check for main.js
  69. if [ -f "main.js" ]; then
  70. MAIN="main.js"
  71. fi
  72. # And finally concatenate Program.js
  73. cat $JTALK/js/boot.js $JTALK/js/Kernel.js $LIBS $COMPILED $JTALK/js/init.js $MAIN > $PROGRAM.js
  74. # Optionally run Program and give all args left to it
  75. if [ -n "$RUN" ]; then
  76. echo "Running program"
  77. echo "---------------"
  78. node $PROGRAM.js $@
  79. fi