heptagon/heptc

73 lines
1.4 KiB
Text
Raw Normal View History

2010-06-27 18:54:05 +02:00
#!/bin/bash
#Small wrapper to deal with compilation of the compiler and the stdlib.
STATUS=0
RUN_DIR="`pwd`"
2010-06-27 18:54:05 +02:00
SCRIPT_DIR=`dirname $(python -c "import os, sys; print os.path.realpath(\"$0\")")`
2011-01-12 15:39:47 +01:00
COMPILER_DIR="$SCRIPT_DIR/compiler"
2011-01-12 15:39:47 +01:00
COMPILER=heptc.byte
2011-03-21 14:30:19 +01:00
COMPILER_DEBUG=heptc.d.byte
LIB_DIR="$SCRIPT_DIR/lib"
2011-01-12 15:39:47 +01:00
JAVA_LIB_DIR="$LIB_DIR/java"
2011-11-22 11:27:58 +01:00
JAVAC="javac -Xlint:unchecked -cp $JAVA_LIB_DIR"
2011-01-12 15:39:47 +01:00
#the symlink
HEPTC="$COMPILER_DIR/$COMPILER"
HEPTC_DEBUG="$COMPILER_DIR/$COMPILER_DEBUG"
2011-01-12 15:39:47 +01:00
#compile the compiler
2011-05-30 10:23:03 +02:00
if [ ! -x "$HEPTC" ]
2010-06-27 18:54:05 +02:00
then
if [ -x "$HEPTC_DEBUG" ]
then
#use the debug
HEPTC=$HEPTC_DEBUG
else
pushd "$COMPILER_DIR" > /dev/null
ocamlbuild -j 0 "$COMPILER"
popd > /dev/null
fi
2010-06-27 18:54:05 +02:00
fi
2011-01-12 15:39:47 +01:00
#compile the stdlib
2011-05-30 10:23:03 +02:00
if [ ! -e "$LIB_DIR/pervasives.epci" ] || [ "$HEPTC" -nt "$LIB_DIR/pervasives.epci" ]
2010-06-27 18:54:05 +02:00
then
pushd "$LIB_DIR" > /dev/null
echo "Recompile pervasives.epci"
"$HEPTC" -nopervasives pervasives.epi
popd > /dev/null
2010-06-27 18:54:05 +02:00
fi
function compile
{
#call the compiler with the passed arguments.
pushd "$RUN_DIR" > /dev/null
"$HEPTC" -stdlib "$LIB_DIR" "$@"
STATUS=$?
popd > /dev/null
}
case $1 in
java )
shift
compile -target java "$@"
if [[ $STATUS = 0 ]]
2011-11-21 09:10:27 +01:00
then
#call javac to compile the file given as last argument
last_arg=$#
base_f=`basename ${!last_arg} .ept`
pushd "java/$(echo ${base_f} | sed 's/^./\u&/')" > /dev/null
2011-11-22 11:27:58 +01:00
${JAVAC}:.. *.java
popd > /dev/null
fi
;;
-- | * )
compile "$@"
esac
exit $STATUS