2010-06-27 18:54:05 +02:00
|
|
|
#!/bin/bash
|
2018-10-12 16:05:09 +02:00
|
|
|
#
|
|
|
|
# Small wrapper to deal with compilation of the compiler and the stdlib.
|
2010-06-27 18:54:05 +02:00
|
|
|
|
2011-11-20 20:03:57 +01:00
|
|
|
STATUS=0
|
|
|
|
|
2011-05-30 10:06:16 +02:00
|
|
|
RUN_DIR="`pwd`"
|
2010-06-27 18:54:05 +02:00
|
|
|
|
2018-10-12 16:05:09 +02:00
|
|
|
SCRIPT_DIR=`dirname $(realpath $0)`
|
2011-01-12 15:39:47 +01:00
|
|
|
|
2011-05-30 10:06:16 +02:00
|
|
|
COMPILER_DIR="$SCRIPT_DIR/compiler"
|
2011-12-06 13:50:01 +01:00
|
|
|
if [ -x $COMPILER_DIR/heptc.native ];
|
|
|
|
then
|
|
|
|
COMPILER=heptc.native
|
|
|
|
else
|
|
|
|
COMPILER=heptc.byte
|
|
|
|
fi
|
2011-03-21 14:30:19 +01:00
|
|
|
COMPILER_DEBUG=heptc.d.byte
|
2011-05-30 10:06:16 +02:00
|
|
|
LIB_DIR="$SCRIPT_DIR/lib"
|
2011-01-12 15:39:47 +01:00
|
|
|
|
2011-11-20 20:03:57 +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-11-20 20:03:57 +01:00
|
|
|
|
2011-01-12 15:39:47 +01:00
|
|
|
#the symlink
|
2011-05-30 10:06:16 +02:00
|
|
|
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
|
2011-11-20 20:03:57 +01:00
|
|
|
if [ -x "$HEPTC_DEBUG" ]
|
|
|
|
then
|
|
|
|
#use the debug
|
|
|
|
HEPTC=$HEPTC_DEBUG
|
|
|
|
else
|
|
|
|
pushd "$COMPILER_DIR" > /dev/null
|
2013-11-08 15:46:31 +01:00
|
|
|
ocamlbuild -use-ocamlfind -j 0 "$COMPILER"
|
2011-11-20 20:03:57 +01:00
|
|
|
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
|
2011-11-20 20:03:57 +01:00
|
|
|
pushd "$LIB_DIR" > /dev/null
|
2014-10-31 14:14:15 +01:00
|
|
|
echo "Recompile pervasives.epci" > /dev/stderr
|
2011-11-20 20:03:57 +01:00
|
|
|
"$HEPTC" -nopervasives pervasives.epi
|
|
|
|
popd > /dev/null
|
2010-06-27 18:54:05 +02:00
|
|
|
fi
|
|
|
|
|
2011-11-20 20:03:57 +01:00
|
|
|
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
|
2011-11-20 20:03:57 +01:00
|
|
|
#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
|
2011-11-20 20:03:57 +01:00
|
|
|
popd > /dev/null
|
|
|
|
fi
|
|
|
|
;;
|
2012-02-12 00:11:27 +01:00
|
|
|
c )
|
|
|
|
shift
|
|
|
|
set -e
|
|
|
|
compile -target c "$@"
|
|
|
|
base_f=`basename ${!#} .ept`
|
|
|
|
cd ${base_f}_c && cc -I`$HEPTC -where`/c *.c -o ../${base_f}
|
|
|
|
;;
|
2011-11-20 20:03:57 +01:00
|
|
|
-- | * )
|
|
|
|
compile "$@"
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit $STATUS
|