Files
mercury/scripts/msc.in
Fergus Henderson 0856a71ed1 Fix a syntax error in my last change.
Estimated hours taken: .1

scripts/msc.in:
	Fix a syntax error in my last change.
1998-03-29 13:51:34 +00:00

131 lines
2.9 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#! /bin/sh
# @configure_input@
#---------------------------------------------------------------------------#
# Copyright (C) 1995-1998 The University of Melbourne.
# This file may only be copied under the terms of the GNU General
# Public License - see the file COPYING in the Mercury distribution.
#---------------------------------------------------------------------------#
# MSC - Mercury SICStus Compiler.
#
# Compiles Mercury programs to SICStus Prolog object code (*.ql).
#
# Use `msc -h' for help.
sicstus_compile=\
${MERCURY_SICSTUS_COMPILER=@LIBDIR@/sicstus/@FULLARCH@/sicstus_compile}
help=false
compile_mode=compactcode
target=
use_subdirs=${MMAKE_USE_SUBDIRS=yes}
while true; do
case "$1" in
-h|--help)
help=true
break
;;
--use-subdirs)
use_subdirs=yes
shift
;;
--no-use-subdirs)
use_subdirs=no
shift
;;
-o|--output)
target="$2"
shift; shift
;;
-m|--mode)
compile_mode="$2"
shift; shift
;;
--)
shift
break
;;
-*)
echo "$0: unrecognized option \`$1'" 1>&2
exit 1
;;
*)
break
;;
esac
done
if [ $# -lt 1 ] || $help; then
# IMPORTANT: the manpage is produced automatically from this help
# message, so if you change the help message, don't forget to check
# that the manpage still looks OK.
cat << 'EOF'
Name: msc - Mercury SICStus Compiler.
Compiles Mercury programs to SICStus Prolog object code (*.ql).
Usage: msc [<options>] file(s)
Options:
-h, --help
Print this help message
--use-subdirs
Generate output files in subdirectories.
-o <target>, --output <target>
Name the output file <target>.
-m <compile-mode>, --mode <compile-mode>
Use the specified mode of compilation.
<compile-mode> should be either compactcode, fastcode,
or profiledcode.
Environment variables: MERCURY_SICSTUS_COMPILER
EOF
exit 0
fi
case "$use_subdirs" in
yes)
[ -d Mercury/qls ] || mkdir -p Mercury/qls
;;
esac
for file in "$@"; do
echo "msc: compiling \`$file'"
dir="`dirname $file`"
case $file in
*.m) base="`basename $file .m`" ;;
*.nl) base="`basename $file .nl`" ;;
*) base="`basename $file`" ;;
esac
tmp=/tmp/msc$$
trap 'rm -f $tmp.pl $tmp.ql; exit 1' 1 2 3 13 15
# This sed script is used to convert from Mercury/NU-Prolog to Sicstus Prolog
# It does three things: delete the `:- module' line,
# expand backslash escapes, and replace the use
# of `^' for xor in calls to is/2 with `#'.
# It also removes '%' comments, to avoid problems with quotes in them.
# Obviously this is not the most robust method of translation imaginable!
sed '
/ is /s/\^/#/g
/^:- *module/d
/^[ ]*%/s/.*//
/\\\\/s//\\/g
/\\a/s///g
/\\b/s///g
/\\r/s//
/g
/\\f/s// /g
/\\t/s// /g
/\\n/s//\
/g
/\\v/s// /g
' $file > $tmp.pl
$sicstus_compile $compile_mode $tmp.pl
rm $tmp.pl
case "$target" in
"") case "$use_subdirs" in
no) mv $tmp.ql "$dir/$base.ql" ;;
yes) mv $tmp.ql "$dir/Mercury/qls/$base.ql" ;;
esac ;;
*) mv $tmp.ql "$target" ;;
esac
done