updated on Thu Jan 26 00:18:00 UTC 2012
[aur-mirror.git] / alloy / alloy
blob1a16fd900315ac644c054438cdb2748688a5765f
1 #!/bin/sh
3 # A launcher script for Alloy programs, with liberal borrowings from
4 # the Clojure launcher script `clj'.
6 # The following environment variables can be used to configure the
7 # script:
9 # ALLOY_HOME
10 # The root directory where Alloy is installed.
11 # ALLOY_JAVA
12 # The name of the java executable used to run Alloy.
13 # ALLOY_JAVA_OPTS
14 # Additional options to be passed to the java executable.
15 # ALLOY_CLASSPATH
16 # A path to be added to Alloy's classpath.
17 # ALLOY_LIBRARY_PATH
18 # A path to be searched for native code such as DLL's or JNI
19 # libraries. This gets added to the Java options as
20 # "-Djava.library.path=$ALLOY_LIBRARY_PATH".
21 # ALLOY_LIB
22 # This directory, and any jars inside it, will be automatically
23 # added to Alloy's classpath.
25 usage="\
26 usage: alloy [options] [file1 [file2] ...]
28 Options:
29 --help, -h show this message
30 --java-cmd, -J the Java executable to use
31 --java-opts, -j options to be passed to the JVM
32 --classpath, -cp add to Alloy's classpath
33 --verbose, -v print initialization information
36 ## read ~/.alloyrc for home configuration
37 [ -e ~/.alloyrc ] && . ~/.alloyrc
39 ## read ./.alloyrc for project specific configuration
40 [ -e ./.alloyrc ] && . ./.alloyrc
42 if [ ! "$ALLOY_HOME" ]; then
43 # Find the real path to Alloy's home directory if $0 is a symlink
44 program="$0"
45 while [ -h "$program" ]; do
46 ls=`ls -ld "$program"`
47 link=`expr "$ls" : '.*-> \(.*\)$'`
48 if expr "$link" : '.*/.*' >/dev/null; then
49 program="$link"
50 else
51 program="`dirname $program`/$link"
53 done
54 script_dir=`dirname "$program"`
55 relative_alloy_home=`dirname "$script_dir"`
56 ALLOY_HOME=`cd "$relative_alloy_home" && pwd`
59 if [ ! "$ALLOY_JAVA" ]; then
60 ALLOY_JAVA="java";
63 if [ ! "$ALLOY_CLASSPATH" ]; then
64 ALLOY_CLASSPATH="."
67 ## Add Alloy home jars.
68 for jar in "$ALLOY_HOME"/*.jar; do
69 ALLOY_CLASSPATH="$ALLOY_CLASSPATH:$jar"
70 done
72 if [ -d "$ALLOY_LIB" ]; then
73 ALLOY_CLASSPATH="$ALLOY_CLASSPATH:$ALLOY_LIB"
74 for jar in "$ALLOY_LIB"/*.jar; do
75 ALLOY_CLASSPATH="$ALLOY_CLASSPATH:$jar"
76 done
79 verbose=0
80 main="edu.mit.csail.sdg.alloy4whole.SimpleGUI"
81 for arg in "$@"; do
82 case $arg in
83 -h|--help)
84 echo "$usage"; exit 1;;
85 -J|--java-cmd)
86 ALLOY_JAVA="$2"; shift; shift;;
87 -j|--java-opts)
88 ALLOY_JAVA_OPTS="$ALLOY_JAVA_OPTS $2"; shift; shift;;
89 -cp|--classpath)
90 ALLOY_CLASSPATH="$ALLOY_CLASSPATH:$2"; shift; shift;;
91 -L|--library-path)
92 if [ "$ALLOY_LIBRARY_PATH" ]; then
93 ALLOY_LIBRARY_PATH="$ALLOY_LIBRARY_PATH:$2";
94 else
95 ALLOY_LIBRARY_PATH="$2";
97 shift; shift;;
98 -v|--verbose)
99 verbose=1; shift;;
100 *) break;;
101 esac
102 done
104 [ $verbose -eq 1 ] && echo "$ALLOY_CLASSPATH"
106 ## Add ALLOY_LIBRARY_PATH to the Java options if necessary
107 if [ -n "$ALLOY_LIBRARY_PATH" ]; then
108 ALLOY_JAVA_OPTS="$ALLOY_JAVA_OPTS -Djava.library.path=$ALLOY_LIBRARY_PATH"
111 cmd=`echo "$ALLOY_JAVA" "$ALLOY_JAVA_OPTS" -cp "$ALLOY_CLASSPATH" $main "$@"`
112 [ $verbose -eq 1 ] && echo "$cmd"
113 exec `echo $cmd`