updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / clojure-git / clj
blobb22c8e158e63c1d9ad356e1c977c91b10df4d3d8
1 #!/bin/sh
3 # A launcher script for Clojure programs. These environment variables can be
4 # used to configure the script:
6 # CLOJURE_HOME
7 # The root directory where Clojure is installed.
8 # CLOJURE_JAVA
9 # The name of the java executable used to run Clojure.
10 # CLOJURE_JAVA_OPTS
11 # Additional options to be passed to the java executable.
12 # CLOJURE_CLASSPATH
13 # A path to be added to Clojure's classpath.
14 # CLOJURE_LIBRARY_PATH
15 # A path to be searched for native code such as DLL's or JNI
16 # libraries. This gets added to the Java options as
17 # "-Djava.library.path=$CLOJURE_LIBRARY_PATH".
18 # CLOJURE_LIB
19 # This directory, and any jars inside it, will be automatically
20 # added to Clojure's classpath.
22 # CLOJURE_JLINE
23 # This should be the path to Jline jar.
24 # TODO:
25 # make CLOJURE_LIB a path instead of a single directory
26 # allow for adding to CLOJURE_LIB from the command line
28 usage="\
29 usage: clojure [options] [file1 [file2] ...]
31 Options:
32 --help, -h show this message
33 --java-cmd, -J the Java executable to use
34 --java-opts, -j add options to be passed on to the JVM
35 --classpath, -cp add to Clojure's classpath
36 --library-path, -L add to the path to search for native libraries
37 --verbose, -v print initialization information
39 ## read ~/.clojurerc for home configuration
40 [ -e ~/.clojurerc ] && . ~/.clojurerc
42 ## read ./.clojurerc for project specific configuration
43 [ -e ./.clojurerc ] && . ./.clojurerc
45 if [ ! "$CLOJURE_HOME" ]; then
46 # Find the real path to Clojure's home directory if $0 is a symlink
47 program="$0"
48 while [ -h "$program" ]; do
49 ls=`ls -ld "$program"`
50 link=`expr "$ls" : '.*-> \(.*\)$'`
51 if expr "$link" : '.*/.*' >/dev/null; then
52 program="$link"
53 else
54 program="`dirname $program`/$link"
56 done
57 script_dir=`dirname "$program"`
58 relative_clojure_home=`dirname "$script_dir"`
59 CLOJURE_HOME=`cd "$relative_clojure_home" && pwd`
62 if [ ! "$CLOJURE_JAVA" ]; then
63 CLOJURE_JAVA="java";
66 if [ ! "$CLOJURE_JAVA_OPTS" ]; then
67 CLOJURE_JAVA_OPTS="-Dpid=$$"; # set the pid for SLIME
70 if [ ! "$CLOJURE_CLASSPATH" ]; then
71 CLOJURE_CLASSPATH="."
74 ## Add Clojure home jars.
75 for jar in "$CLOJURE_HOME"/*.jar; do
76 CLOJURE_CLASSPATH="$CLOJURE_CLASSPATH:$jar"
77 done
79 if [ -d "$CLOJURE_LIB" ]; then
80 CLOJURE_CLASSPATH="$CLOJURE_CLASSPATH:$CLOJURE_LIB"
81 for jar in "$CLOJURE_LIB"/*.jar; do
82 CLOJURE_CLASSPATH="$CLOJURE_CLASSPATH:$jar"
83 done
86 # this is now the same for both the repl and for scripts
87 main="clojure.main"
88 repl=0
89 verbose=0
91 for arg in "$@"; do
92 case $arg in
93 -h|--help)
94 echo "$usage"; exit 1;;
95 -J|--java-cmd)
96 CLOJURE_JAVA="$2"; shift; shift;;
97 -j|--java-opts)
98 CLOJURE_JAVA_OPTS="$CLOJURE_JAVA_OPTS $2"; shift; shift;;
99 -cp|--classpath)
100 CLOJURE_CLASSPATH="$CLOJURE_CLASSPATH:$2"; shift; shift;;
101 -L|--library-path)
102 if [ "$CLOJURE_LIBRARY_PATH" ]; then
103 CLOJURE_LIBRARY_PATH="$CLOJURE_LIBRARY_PATH:$2";
104 else
105 CLOJURE_LIBRARY_PATH="$2";
107 shift; shift;;
108 -v|--verbose)
109 verbose=1; shift;;
110 *) break;;
111 esac
112 done
114 [ $verbose -eq 1 ] && echo "$CLOJURE_CLASSPATH"
116 # If we didn't get any files to load on the commandline, we want to run the
117 # repl, with command line editing if available.
118 [ $# -eq 0 ] && repl=1
120 # If the classpath contains the JLine jar, use the JLine console runner
121 if expr "$CLOJURE_CLASSPATH" : ".*jline.*\.jar" >/dev/null; then
122 [ $repl -eq 1 ] && jline="jline.ConsoleRunner"
125 # Enable rlwrap if present
126 if [ $repl -eq 1 ] && [ -z $jline ]; then
127 rlwrap=`type -p rlwrap`
130 ## Add CLOJURE_LIBRARY_PATH to the Java options if necessary
131 if [ -n "$CLOJURE_LIBRARY_PATH" ]; then
132 CLOJURE_JAVA_OPTS="$CLOJURE_JAVA_OPTS -Djava.library.path=$CLOJURE_LIBRARY_PATH"
135 cmd=`echo $rlwrap "$CLOJURE_JAVA" "$CLOJURE_JAVA_OPTS" -cp "$CLOJURE_CLASSPATH" $jline $main "$@"`
136 [ $verbose -eq 1 ] && echo "$cmd"
137 exec `echo $cmd`