diff options
author | Rich Hickey <richhickey@gmail.com> | 2008-11-26 23:57:25 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2008-11-26 23:57:25 +0000 |
commit | 2adf03dc22be0cf9caf93b4999528b3a06eb9002 (patch) | |
tree | ca05486e75cb376c1c946d062740119063a8b92b /src/jvm | |
parent | 4d944fea131f35d4bb88822127274d25bfcef100 (diff) |
added clojure.main, patch from Stephen C. Gilardi
Diffstat (limited to 'src/jvm')
-rw-r--r-- | src/jvm/clojure/lang/Compile.java | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/jvm/clojure/lang/Compile.java b/src/jvm/clojure/lang/Compile.java new file mode 100644 index 00000000..d31b3569 --- /dev/null +++ b/src/jvm/clojure/lang/Compile.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) Rich Hickey. All rights reserved. + * The use and distribution terms for this software are covered by the + * Common Public License 1.0 (http://opensource.org/licenses/cpl.php) + * which can be found in the file CPL.TXT at the root of this distribution. + * By using this software in any fashion, you are agreeing to be bound by + * the terms of this license. + * You must not remove this notice, or any other, from this software. + **/ + + +package clojure.lang; + +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.io.IOException; + +// Compiles libs and generates class files stored within the directory +// named by the Java System property "clojure.compile.path". Arguments are +// strings naming the libs to be compiled. The libs and compile-path must +// all be within CLASSPATH. + +public class Compile{ + +private static final String PATH_PROP = "clojure.compile.path"; +private static final Var compile_path = RT.var("clojure.core", "*compile-path*"); +private static final Var compile = RT.var("clojure.core", "compile"); + +public static void main(String[] args) throws Exception{ + + OutputStreamWriter out = (OutputStreamWriter) RT.OUT.get(); + PrintWriter err = (PrintWriter) RT.ERR.get(); + String path = System.getProperty(PATH_PROP); + int count = args.length; + + if(path == null) + { + err.println("ERROR: Must set system property " + PATH_PROP + + "\nto the location for compiled .class files." + + "\nThis directory must also be on your CLASSPATH."); + System.exit(1); + } + + try + { + Var.pushThreadBindings(RT.map(compile_path, path)); + + out.write("Compiling " + count + " " + + ((count == 1) ? "lib" : "libs") + + " to " + path); + out.flush(); + + for(String lib : args) + compile.invoke(Symbol.intern(lib)); + + Var.popThreadBindings(); + } + finally + { + try + { + out.flush(); + out.close(); + } + catch(IOException e) + { + e.printStackTrace(err); + } + } +} +} |