Browse Source

Merge pull request #10 from gokr/master

Makefile and jtalkc that works
Nicolas Petton 13 years ago
parent
commit
b26ed9b7b4
4 changed files with 171 additions and 26 deletions
  1. 2 2
      LICENSE
  2. 55 20
      bin/jtalkc
  3. 19 4
      nodejs/nodecompile.js
  4. 95 0
      st/Makefile

+ 2 - 2
LICENSE

@@ -3,9 +3,9 @@ Copyright (C) 2011 Jtalk contributors
 
 Contributors
 David Graham <dgraham@iphouse.com>
-Göran Krampe <goran.krampe@gmail.com>
+Göran Krampe <goran@krampe.se>
 
-Parts of Jtalk take ideas from Clamato (http://clamato.net), written by Avi Byrant.
+Parts of Jtalk take ideas from Clamato (http://clamato.net), written by Avi Bryant.
 The PetitParser library is written by Lukas Renggli (http://lukas-renggli.ch) and released under the MIT license.
 
 Permission is hereby granted, free of charge, to any person obtaining a copy

+ 55 - 20
bin/jtalkc

@@ -7,11 +7,12 @@ JTALK=$(readlink -f `dirname ${0}`/..)
 
 function usage {
 	cat <<ENDOFHELP
-Usage: $0 [-N|D|E] [-K|C] [-o] [-O] [-m class] [-M file]
-          [-i] [-I file] file1 [file2 ...] [Program]
+Usage: $0 [-N|D|E] [-K|C|J] [-o] [-O] [-g] [-p prefix] [-m class] [-M file]
+          [-i] [-I file] [file1 [file2 ...]] [Program]
 
    Will compile Jtalk files - either separately or into a runnable complete
-   program. Files listed will be handled using these rules:
+   program. If no files are listed only a linking stage is performed.
+   Files listed will be handled using these rules:
 
    *.js
      Files are concatenated in listed order.
@@ -34,10 +35,13 @@ Usage: $0 [-N|D|E] [-K|C] [-o] [-O] [-m class] [-M file]
      is added last.
 
   -K
-     Add libraries to get minimal JTalk Kernel running.
+     Add libraries to get minimal Jtalk Kernel running.
 
   -C
-     Add libraries to get minimal JTalk Compiler running.
+     Add libraries to get minimal Jtalk Compiler running.
+
+  -J
+     Add libraries to get minimal Jtalk IDE running.
 
   -o
      Optimize each js file using the Google closure compiler.
@@ -47,6 +51,13 @@ Usage: $0 [-N|D|E] [-K|C] [-o] [-O] [-m class] [-M file]
      Optimize final <Program>.js using the Google closure compiler.
      Using Closure at ~/compiler.jar    
 
+  -g
+     Compile Jtalk code in debug mode - include source and references etc.
+
+  -p prefix
+     Add <prefix> to compiled js files so that File.st is compiled into
+     <prefix>File.st.
+
   -l library1,library2
      Load listed libraries (no spaces) into Compiler before compiling.
 
@@ -95,10 +106,11 @@ if [ -z $1 ] ; then
 fi
 
 # Define our predefined library combinations
-BOOT="$JTALK/js/boot.js"
-KERNEL="$BOOT $JTALK/js/Kernel.js"
-COMPILER="$KERNEL $JTALK/js/Parser.js $JTALK/js/Compiler.js"
-KITCHENSINK="$COMPILER $JTALK/js/Canvas.js"
+BOOT="boot.js"
+KERNEL="$BOOT Kernel.js"
+COMPILER="$KERNEL Parser.js Compiler.js"
+CANVAS="$COMPILER Canvas.js"
+IDE="$CANVAS JQuery.js IDE.js SUnit.js Examples.js"
 
 # Predefined initializer
 INITIALIZER="$JTALK/js/init.js"
@@ -108,12 +120,17 @@ ENV=
 INIT=
 MAIN=
 MAINFILE=
-BASE=$KERNEL
+BASE=
 LOAD=
 LOADANDADD=
+# Ok, bad coding practice but hey, who would use such a prefix?
+PREFIX=no-silly-prefix
+PREFIXUSED=
+DEBUG=false
+NODECOMPILE=nodecompile.js
 
 # Read options and shift them away
-while getopts "NDEKCoOl:L:i:IM:m:h?" o; do
+while getopts "NDEKCJoOgp:l:L:i:IM:m:h?" o; do
 case "$o" in
    N) ENV=NODE
       BASE=$KERNEL
@@ -121,15 +138,19 @@ case "$o" in
    D) ENV=D8
       BASE=$KERNEL
       INIT=$INITIALIZER;;
-   D) ENV=ENYO
+   E) ENV=ENYO
       BASE=$KERNEL
       INIT=$INITIALIZER;;
    K) BASE=$KERNEL;;
    C) BASE=$COMPILER;;
+   J) BASE=$IDE;;
    o) CLOSURE=true
       CLOSUREPARTS=true;;
    O) CLOSURE=true
       CLOSUREFULL=true;;
+   g) DEBUG=true;;
+   p) PREFIX=$OPTARG
+      PREFIXUSED=$PREFIX;;
    l) LOAD=$OPTARG;;
    L) LOADANDADD=$OPTARG;;
    I) INIT=$INITIALIZER;;
@@ -170,6 +191,13 @@ function resolvejs {
   fi
 }
 
+# Resolve listed libraries in $BASE separated by spaces
+for FILE in $BASE
+do
+   resolvejs $FILE
+   TOBASE="$TOBASE $RESOLVED"
+done
+
 # Resolve listed libraries in $LOAD separated by spaces
 LOAD=${LOAD//,/\ }
 for FILE in $LOAD
@@ -188,10 +216,17 @@ do
 done
 
 # Define our Compiler loading supplied libraries
-OURCOMPILER="$KITCHENSINK $TOLOAD $JTALK/js/init.js $JTALK/nodejs/nodecompile.js"
+OURCOMPILER="$COMPILER $TOLOAD init.js $JTALK/nodejs/$NODECOMPILE"
+
+# Resolve OURCOMPILER
+for FILE in $OURCOMPILER
+do
+   resolvejs $FILE
+   TOOURCOMPILER="$TOOURCOMPILER $RESOLVED"
+done
 
 # Add supplied libraries
-LIBS="$BASE $TOADD"
+LIBS="$TOBASE $TOADD"
 
 # Get a unique tempdir and make it get auto removed on exit
 TMPDIR=`mktemp -d`
@@ -210,11 +245,11 @@ do
         CATEGORY=`basename $1 .st`
         if [ -f "$1" ]; then
            COMPILE="$COMPILE $1 $CATEGORY"
-           COMPILED="$COMPILED $CATEGORY.js"
+           COMPILED="$COMPILED $PREFIXUSED$CATEGORY.js"
         else
            if [ -f $JTALK/st/$1 ]; then
              COMPILE="$COMPILE $JTALK/st/$1 $CATEGORY"
-             COMPILED="$COMPILED $CATEGORY.js"
+             COMPILED="$COMPILED $PREFIXUSED$CATEGORY.js"
            else
              echo "JTalk file not found: $1"
              exit 1
@@ -239,11 +274,11 @@ done
 # --------------------------------------------------
 
 # Create compiler dynamically
-cat $OURCOMPILER > $TMPDIR/compiler.js
-
+cat $TOOURCOMPILER > $TMPDIR/compiler.js
+ 
 # Compile all collected .st files to .js
-echo "Loading libraries $KITCHENSINK $TOLOAD and compiling ..."
-node $TMPDIR/compiler.js $COMPILE
+echo "Loading libraries $TOOURCOMPILER and compiling ..."
+node $TMPDIR/compiler.js $DEBUG $PREFIX $COMPILE
 
 # Verify all .js files corresponding to .st files were created, otherwise exit
 IFS=" "

+ 19 - 4
nodejs/nodecompile.js

@@ -4,8 +4,23 @@
 // as aCategoryName.js.
 var sys = require('sys'), fs = require('fs');
 
-// Only care about our arguments, strip away node and all.js
-var arguments = process.argv.splice(2);
+// Only care about our arguments, strip away node, all.js and debug flag.
+var arguments = process.argv.splice(4);
+
+// First argument is debugMode: "true" or "false"
+if (process.argv[2] == "true") {
+  smalltalk.debugMode = true;
+} else {
+  smalltalk.debugMode = false;
+}
+
+// Second argument is prefix: "no-silly-prefix" means none
+prefix = process.argv[3];
+if (prefix == "no-silly-prefix") {
+  prefix = "";
+}
+
+console.log("Compiling in debugMode: " + smalltalk.debugMode);
 
 // If it ends with .st, import it, otherwise export category as .js
 arguments.forEach(function(val, index, array) {
@@ -14,7 +29,7 @@ arguments.forEach(function(val, index, array) {
     code = fs.readFileSync(val, "utf8");
     smalltalk.Importer._new()._import_(code._stream());
   } else {
-    sys.puts("Exporting category " + val);
-    fs.writeFileSync(val + ".js", smalltalk.Exporter._new()._exportCategory_(val));
+    sys.puts("Exporting category " + val + " as " + prefix + val + ".js");
+    fs.writeFileSync(prefix + val + ".js", smalltalk.Exporter._new()._exportCategory_(val));
   }
 });

+ 95 - 0
st/Makefile

@@ -0,0 +1,95 @@
+#
+# This Makefile takes .st files in the jtalk/st directory and produces compiled
+# javascript files from them. It also produces one or more concatenated jtalk.js files
+# for development and deployment.
+#
+# Where we find the current runnable code and where we put our js files when we are done
+JS	:= ../js/
+
+# The compiler script
+JTALKC	:= ../bin/jtalkc
+
+# Generic flags to JTALKC
+FLAGS   := -g
+
+# All corresponding js filenames for every st file available
+# In other words, if we have Kernel.st and Parser.st, then OBJECTS will be "Kernel.js Parser.js"
+OBJECTS := $(patsubst %.st,%.js,$(wildcard *.st))
+
+# Default make target since it is the first target in this Makefile
+all: jtalk.deploy.js jtalk.js
+
+# Step by step
+#
+# First we copy the core javascript files from current working files
+# into this directory. These files are hand written. $@ is the target name.
+boot.js init.js:
+	cp ../js/$@ .
+
+# Then we compile Kernel.st using boot.js, Kernel.js, init.js
+# $< means the first dependency - in other words Kernel.st
+Kernel.js: Kernel.st boot.js init.js
+	$(JTALKC) $(FLAGS) $<
+
+# And one for deployment, no flags.
+deploy-Kernel.js: Kernel.st boot.js init.js
+	$(JTALKC) -p deploy- $<
+
+# ...then Parser, but using the new Kernel from step above.
+# We only need to depend on Kernel.js since it in turn depends on boot.js and init.js.
+Parser.js: Parser.st Kernel.js
+	$(JTALKC) $(FLAGS) $<
+
+# ...and Compiler, but using the new Parser and Kernel from above.
+# We only need to depend on Parser.js since it in turn depends on Kernel.js, boot.js etc
+Compiler.js: Compiler.st Parser.js
+	$(JTALKC) $(FLAGS) $<
+
+# ...now that we have a new Kernel/Parser/Compiler we use them
+# to compile the rest of st files that only depend on Compiler, like
+# for example Canvas.js, Benchfib.js etc
+%.js: %.st Compiler.js 
+	$(JTALKC) $(FLAGS) $<
+
+# But for some libraries there are dependencies to care for. Then
+# we need to use -l so that the compiler first loads that library
+# before compiling the .st file. Otherwise bindings will fail.
+#
+# JQuery uses Canvas
+JQuery.js: JQuery.st Canvas.js
+	$(JTALKC) $(FLAGS) -l Canvas.js $<
+
+# IDE uses JQuery
+IDE.js: IDE.st JQuery.js
+	$(JTALKC) $(FLAGS) -l Canvas.js,JQuery.js $<
+
+# The SUnit TestRunner uses UI stuff from IDE.
+SUnit.js: SUnit.st IDE.js
+	$(JTALKC) $(FLAGS) -l Canvas.js,JQuery.js,IDE.js $<
+
+# Some Examples use SUnit
+Examples.js: Examples.st SUnit.js
+	$(JTALKC) $(FLAGS) -l Canvas.js,JQuery.js,IDE.js,SUnit.js $<;
+
+# This is the deployment target with only the Jtalk Kernel compiled without -g.
+# Then we push it all through Closure (-O) and add init.js at end (-I).
+jtalk.deploy.js: boot.js init.js deploy-Kernel.js
+	$(JTALKC) -O -I boot.js deploy-Kernel.js jtalk.deploy;
+
+# Full IDE compiled with -g. We do not clean away objects at end.
+# Here we give -J (will include all  libs for Jtalk IDE),
+# push it all through Closure (-O) and add init.js at end (-I).
+jtalk.js: boot.js init.js $(OBJECTS)
+	$(JTALKC) -J -O -I jtalk;
+
+
+# Installing is simply copying all js files to js directory.
+install: all
+	cp *.js $(JS)
+
+# And cleaning is trivial
+clean:
+	rm -f *.js; 
+
+# These three are phony
+.PHONY: all install clean