#! /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 [] file(s) Options: -h, --help Print this help message --use-subdirs Generate output files in subdirectories. -o , --output Name the output file . -m , --mode Use the specified mode of compilation. 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