charj: don't try to move compiler output when we're just translating
[charm.git] / src / langs / charj / bin / charjc
1 #!/bin/bash
2
3 cd ${0%${0##*/}}
4 CHARJCHOME=`pwd`                    # location of charjc
5 cd - >& /dev/null
6 ANTLRHOME=$CHARJCHOME/../lib        # location of antlr jars
7 ANTLR_VERSION="3.2"
8
9 ANTLR_JAR=$ANTLRHOME/antlr-3.2.jar
10 JSAP_JAR=$CHARJCHOME/../lib/JSAP-2.1.jar
11 CHARJ_JAR=$CHARJCHOME/../build/lib/charj.jar
12 CHARJ_JFLAGS="-classpath $CLASSPATH:$ANTLR_JAR:$JSAP_JAR:$CHARJ_JAR"
13
14 # flag processing
15 # We need to aggregate all charmc options into one quoted string, while leaving
16 # the charjc options alone.
17 VERBOSE=false
18 NOCOMPILE=false
19 CHARMC=$CHARJCHOME/../../../../bin/charmc
20 STDLIB=$CHARJCHOME/../src
21 CHARMC_ARGS=
22 CJFILES=
23 ARGS=
24 processArgs() {
25     while [ ! $# -eq 0 ]
26     do
27         arg="$1"
28         shift
29
30         case "$arg" in
31         "-v"|"-V"|"--verbose")
32             VERBOSE=true
33             ARGS="$ARGS $arg"
34             ;;
35         "--AST"|"--ast")
36             ARGS="$ARGS $arg"
37             ;;
38         "--debug")
39             ARGS="$ARGS $arg"
40             ;;
41         "--stdout")
42             ARGS="$ARGS $arg"
43             ;;
44         "--stdlib")
45             STDLIB="$1"
46             shift
47             ;;
48         "--lib")
49             ARGS="$ARGS $arg $1"
50             shift
51             ;;
52         "--translate-only")
53             NOCOMPILE=true
54             ARGS="$ARGS $arg"
55             ;;
56         "--count-tokens")
57             ARGS="$ARGS $arg"
58             ;;
59         "--charmc")
60             CHARMC="$1"
61             shift
62             ;;
63         *.cj)
64             CJFILES="$CJFILES $arg"
65             ;;
66         --*|-*)
67             # unrecognized options are passed through to charmc
68             CHARMC_ARGS="$CHARMC_ARGS $arg"
69             ;;
70         *)
71             echo "discarding unrecognized argument: $arg"
72             ;;
73         esac
74     done
75     CHARMC="$CHARMC $CHARMC_ARGS"
76 }
77
78 processArgs "$@"
79 for file in $CJFILES; do
80     tmpdir=`dirname $file`/`basename $file`.gen
81     mkdir -p $tmpdir
82     if $VERBOSE; then
83         #echo "cpp $ARGS $file $tmpdir/$file"
84         echo "cp $file $tmpdir/$file"
85         echo "cd $tmpdir"
86     fi
87     #cpp $CHARMC_ARGS $file $tmpdir/$file
88     cp $file $tmpdir/$file
89     cd $tmpdir
90     if $VERBOSE; then
91         echo "java $CHARJ_JFLAGS charj.Main --charmc \"$CHARMC\" \
92         --stdlib $STDLIB $ARGS $file"
93     fi
94     java $CHARJ_JFLAGS charj.Main --charmc "$CHARMC" --stdlib $STDLIB \
95         $ARGS $file
96     if ! $NOCOMPILE; then
97         cp *.o *.decl.h ..
98     fi
99 done
100