diff --git a/scripts/Mmake b/scripts/Mmake index 32d9e0c22..cd17cee81 100644 --- a/scripts/Mmake +++ b/scripts/Mmake @@ -19,15 +19,6 @@ SCRIPTS = mmake mc mcn mcs mod2c mod2init mgnuc ml mint mnc mnl mnp msc msl \ #-----------------------------------------------------------------------------# -.SUFFIXES: .sh -.sh: - sed -e "s^@LIBDIR@^$(INSTALL_LIBDIR)^g" \ - -e "s^@FULLARCH@^$(FULLARCH)^g" \ - $< > $@ - chmod +x $@ - -#-----------------------------------------------------------------------------# - .PHONY: all all: $(SCRIPTS) @@ -52,6 +43,6 @@ clean_progs: clean_scripts .PHONY: clean_scripts clean_scripts: - for file in *.sh; do rm -f `basename $$file .sh`; done + for file in *.in; do rm -f `basename $$file .in`; done #-----------------------------------------------------------------------------# diff --git a/scripts/mc.in b/scripts/mc.in new file mode 100644 index 000000000..b56846977 --- /dev/null +++ b/scripts/mc.in @@ -0,0 +1,20 @@ +#!/bin/sh +#---------------------------------------------------------------------------# +# Copyright (C) 1995 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. +#---------------------------------------------------------------------------# +# +# MC - Mercury Compiler. +# +# Use `mc -h' for help. +# +# Environment variables: MERCURY_INT_DIR, MERCURY_DEP_DIR, MERCURY_C_INCL_DIR, +# MERCURY_COMPILER. + +INTDIR=${MERCURY_INT_DIR=@LIBDIR@/ints} +DEPDIR=${MERCURY_DEP_DIR=@LIBDIR@/deps} +C_INCL=${MERCURY_C_INCL_DIR=@LIBDIR@/inc} +MC=${MERCURY_COMPILER="@LIBDIR@/bin/@FULLARCH@/mercury_compile"} + +exec $MC -- -I "$INTDIR" -I "$DEPDIR" --c-include-directory "$C_INCL" "$@" diff --git a/scripts/mcn.in b/scripts/mcn.in new file mode 100644 index 000000000..69a340b1a --- /dev/null +++ b/scripts/mcn.in @@ -0,0 +1,20 @@ +#!/bin/sh +#---------------------------------------------------------------------------# +# Copyright (C) 1995 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. +#---------------------------------------------------------------------------# +# +# MCN - Mercury Compiler (compiled with NU-Prolog). +# +# Use `mcn -h' for help. +# +# Environment variables: MERCURY_INT_DIR, MERCURY_DEP_DIR, MERCURY_C_INCL_DIR, +# MERCURY_COMPILER. + +INTDIR=${MERCURY_INT_DIR=@LIBDIR@/ints} +DEPDIR=${MERCURY_DEP_DIR=@LIBDIR@/deps} +C_INCL=${MERCURY_C_INCL_DIR=@LIBDIR@/inc} +MC=${MERCURY_COMPILER=@LIBDIR@/nuprolog/@FULLARCH@/mercury_compile.nu} + +exec $MC -I "$INTDIR" -I "$DEPDIR" --c-include-directory "$C_INCL" "$@" diff --git a/scripts/mcs.in b/scripts/mcs.in new file mode 100644 index 000000000..823964395 --- /dev/null +++ b/scripts/mcs.in @@ -0,0 +1,20 @@ +#!/bin/sh +#---------------------------------------------------------------------------# +# Copyright (C) 1995 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. +#---------------------------------------------------------------------------# +# +# MCS - Mercury Compiler, compiled with Sicstus +# +# Use `mcs -h' for help. +# +# Environment variables: MERCURY_INT_DIR, MERCURY_DEP_DIR, MERCURY_C_INCL_DIR, +# MERCURY_COMPILER_SICSTUS. + +INTDIR=${MERCURY_INT_DIR=@LIBDIR@/ints} +DEPDIR=${MERCURY_DEP_DIR=@LIBDIR@/deps} +C_INCL=${MERCURY_C_INCL_DIR=@LIBDIR@/inc} +MCS=${MERCURY_COMPILER_SICSTUS=@LIBDIR@/sicstus/@FULLARCH@/mercury_compile.sicstus} + +exec $MCS -I "$INTDIR" -I "$DEPDIR" --c-include-directory "$C_INCL" "$@" diff --git a/scripts/mercury_update_interface.in b/scripts/mercury_update_interface.in new file mode 100644 index 000000000..a1d376d01 --- /dev/null +++ b/scripts/mercury_update_interface.in @@ -0,0 +1,49 @@ +#!/bin/sh +#---------------------------------------------------------------------------# +# Copyright (C) 1995 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. +#---------------------------------------------------------------------------# +# +# MERCURY_UPDATE_INTERFACE +# +# usage: +# mercury_update_interface [-v] filename +# +# Moves `filename.tmp' to `filename', but only if necessary: +# if they are identical, then `filename.tmp' is simply removed, +# and the time-stamp is left unaltered. +# +# If the `-v' (verbose) option is specified, then appropriate progress messages +# will be printed. +# +# Enviroment variables: none. + +PATH=/bin:/usr/bin + +verbose=true + +if [ $# -ge 1 ] && [ "$1" = "-v" ]; then + verbose=true + shift +fi + +if [ $# -ne 1 ]; then + echo "Usage: `basename $0` filename" 1>&2 + exit 1 +fi + +filename="$1" + +if [ ! -f "$filename" ] +then + $verbose && echo "creating \`$filename'." 1>&2 + mv -f "$filename.tmp" "$filename" +elif cmp -s "$filename.tmp" "$filename" +then + $verbose && echo "\`$filename' has not changed." 1>&2 + rm -f "$filename.tmp" +else + $verbose && echo "\`$filename' has changed." 1>&2 + mv -f "$filename.tmp" "$filename" +fi diff --git a/scripts/mgnuc.in b/scripts/mgnuc.in new file mode 100644 index 000000000..c20297e5b --- /dev/null +++ b/scripts/mgnuc.in @@ -0,0 +1,150 @@ +#!/bin/sh +#---------------------------------------------------------------------------# +# Copyright (C) 1995 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. +#---------------------------------------------------------------------------# + +# MGNUC - Mercury GNU C +# +# Usage: mgnuc [-v|--verbose] [-s] -- [] files... +# +# -v, --verbose +# Echo gcc command before executing it. +# -s +# Select optimization/debug/gc options according to , which +# must be one of debug, none, jump, asm_jump, reg, fast, or asm_fast, +# or one of those with .gc appended. +# +# This runs gcc with all warnings enabled, except for the following +# exceptions: +# +# -Wredundant-decls causes too many complaints in system header files +# -Wconversion really only intended to help people using `unprotoize' +# -Waggregate-return not useful, IMHO +# +# -Wcast-align causes redundant warnings in memory.c +# -pedantic causes unsuppressable warnings about LVALUE_CAST() +# -Wnested-externs causes unsuppressable warnings about callentry() +# -Wid-clash-31 causes warnings about entry_mercury__xxx ... +# -Wenum-clash is for C++ only +# -Wunused causes various spurious warnings + +C_INCL_DIR=${MERCURY_C_INCL_DIR=@LIBDIR@/inc} + +CHECK_OPTS="-ansi + -Wall -Wwrite-strings -Wpointer-arith -Wcast-qual -Wtraditional -Wshadow + -Wstrict-prototypes -Wmissing-prototypes -Wno-unused" +OPT_OPTS="-O2 -fomit-frame-pointer -DSPEED" +OPT_OPTS="-O2 -g -DSPEED" +DEBUG_OPTS="-g" + +grade=asm_fast.gc +verbose=false + +while true; do + case "$1" in + -v|--verbose) + verbose=true + shift + ;; + -s) + shift + grade="$1"; + shift + ;; + -s*) + grade="` expr $1 : '-s\(.*\)' `" + shift + ;; + --) + shift + break + ;; + *) + break + ;; + esac +done + +case "$grade" in + *.gc) GC_OPTS="-DCONSERVATIVE_GC -DTAGBITS=0" + grade="` expr $grade : '\(.*\).gc' `" + ;; + *) + GC_OPTS="" + ;; +esac + +case "$grade" in + asm_fast) + GRADE_OPTS="$OPT_OPTS -DUSE_GCC_GLOBAL_REGISTERS + -DUSE_ASM_LABELS -DUSE_GCC_NONLOCAL_GOTOS" + ;; + fast) + GRADE_OPTS="$OPT_OPTS + -DUSE_GCC_GLOBAL_REGISTERS -DUSE_GCC_NONLOCAL_GOTOS" + ;; + reg) + GRADE_OPTS="$OPT_OPTS + -DUSE_GCC_GLOBAL_REGISTERS" + ;; + asm_jump) + GRADE_OPTS="$OPT_OPTS + -DUSE_ASM_LABELS -DUSE_GCC_NONLOCAL_GOTOS" + ;; + jump) + GRADE_OPTS="$OPT_OPTS + -DUSE_GCC_NONLOCAL_GOTOS" + ;; + none) + GRADE_OPTS="$OPT_OPTS" + ;; + init) + echo "$0: the \`-s init' option is no longer supported" 1>&2 + exit 1 + ;; + debug) + GRADE_OPTS="$DEBUG_OPTS" + ;; + *) + echo "$0: invalid grade \`$grade'" 1>&2; + exit 1 +esac + +ARCH_OPTS="" +case @FULLARCH@ in + mips-sgi-irix5*) + # nonlocal gotos don't work with PIC, which is the + # default for Irix 5, so if nonlocal gotos are enabled + # we need to disable PIC with -non_shared. + case $GRADE_OPTS in + *-DUSE_GCC_NONLOCAL_GOTOS*) + ARCH_OPTS=-non_shared + ;; + esac + ;; +esac + +HOST_OPTS="" +case "`hostname`" in + cadillac.*) + GCC=/usr/local/bin/gcc ;; + kryten.*) + GCC=/usr/local/contrib/bin/gcc + HOST_OPTS="-msupersparc" ;; + *) + GCC=gcc +esac + +if [ "`uname -r -s`" = "SunOS 4.1.2" ]; then + # the header files on cadillac are stuffed, so don't + # enable any warnings + CHECK_OPTS= +fi +if $verbose; then + echo $GCC -I $C_INCL_DIR $ARCH_OPTS $HOST_OPTS $CHECK_OPTS \ + $GRADE_OPTS $GC_OPTS "$@" +fi +exec $GCC -I $C_INCL_DIR $ARCH_OPTS $HOST_OPTS $CHECK_OPTS \ + $GRADE_OPTS $GC_OPTS "$@" diff --git a/scripts/mint.in b/scripts/mint.in new file mode 100644 index 000000000..387477218 --- /dev/null +++ b/scripts/mint.in @@ -0,0 +1,32 @@ +#!/bin/sh +#---------------------------------------------------------------------------# +# Copyright (C) 1995 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. +#---------------------------------------------------------------------------# +# +# mint - Mercury interface browser. +# +# Usage: mint module-name ... + +INTDIR=${MERCURY_INT_DIR=@LIBDIR@/ints} + +exit_status=0 + +if [ $# -lt 1 ] +then + echo "usage: `basename $0` module-name ..." 1>&2 + exit 1 +fi + +for arg in "$@"; do + module="`basename $arg .nl`" + file="$INTDIR/$module.int" + if [ -r "$file" ]; then + ${PAGER=more} "$file" + else + echo "`basename $0`: no interface file for \`$module'." 1>&2 + exit_status=1 + fi +done +exit $exit_status diff --git a/scripts/ml.in b/scripts/ml.in new file mode 100644 index 000000000..c71dd3f75 --- /dev/null +++ b/scripts/ml.in @@ -0,0 +1,90 @@ +#!/bin/sh +#---------------------------------------------------------------------------# +# Copyright (C) 1995 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. +#---------------------------------------------------------------------------# +# +# ML - Mercury Linker. +# +# Invokes GCC with the appropriate options to link in the Mercury library. +# +# Usage: ml [] [ +# Specify which grade of the Mercury library to link with. +# Defaults to `asm_fast.gc'. +# +# Environment variables: MERCURY_C_LIB_DIR + +LIBDIR=${MERCURY_C_LIB_DIR=@LIBDIR@/lib} +verbose=false +GRADE=asm_fast.gc + +while true; do + case "$1" in + -v|--verbose) + verbose=true + shift ;; + -s) + shift + GRADE="$1" + shift ;; + --) + shift + break ;; + -static) + break ;; + -s*) + GRADE="` expr $1 : '-s\(.*\)' `" + shift ;; + *) + break ;; + esac +done + +case "$GRADE" in + *.gc) + LIBGC="-lgc" + ;; + *) + LIBGC= + ;; +esac + +case @FULLARCH@ in + *-solaris*) + LIBDIR_OPTS=" + -R@LIBDIR@/lib/@FULLARCH@ -L$LIBDIR/@FULLARCH@ + -R@LIBDIR@/lib/$GRADE/@FULLARCH@ -L$LIBDIR/$GRADE/@FULLARCH@ + " + ;; + *-sgi-irix5*) + LIBDIR_OPTS=" + -Wl,-rpath,@LIBDIR@/lib/@FULLARCH@:@LIBDIR@/lib/$GRADE/@FULLARCH@ + -L$LIBDIR/@FULLARCH@ -L$LIBDIR/$GRADE/@FULLARCH@ + " + ;; + *) + LIBDIR_OPTS=" + -L$LIBDIR/@FULLARCH@ + -L$LIBDIR/$GRADE/@FULLARCH@ + " + ;; +esac + +case "`hostname`" in + cadillac.dd.citri.edu.au) + GCC=/usr/local/bin/gcc ;; + kryten.cs.mu.OZ.AU) + GCC=/usr/local/bin/gcc ;; + *) + GCC=${GCC=gcc} +esac + +if $verbose; then + echo $GCC "$@" $LIBDIR_OPTS -lmer -lmercury -lmer $LIBGC +fi +exec $GCC "$@" $LIBDIR_OPTS -lmer -lmercury -lmer $LIBGC diff --git a/scripts/mmake.in b/scripts/mmake.in new file mode 100644 index 000000000..556fa98e2 --- /dev/null +++ b/scripts/mmake.in @@ -0,0 +1,110 @@ +#!/bin/sh +#---------------------------------------------------------------------------# +# Copyright (C) 1995 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. +#---------------------------------------------------------------------------# +# +# mmake - Mercury Make. +# +# Type mmake -h for help. +# +#-----------------------------------------------------------------------------# + +MAKE=${MMAKE_MAKE=make} +MMAKE_VARS=${MMAKE_VARS=@LIBDIR@/mmake/Mmake.vars} +MMAKE_RULES=${MMAKE_RULES=@LIBDIR@/mmake/Mmake.rules} +MERCURY_INT_DIR=${MERCURY_INT_DIR=@LIBDIR@/ints} + +MMAKE=$0 +verbose=false +save_makefile=false + +while [ $# -gt 0 ]; do + case $1 in + -h|--help) +#-----------------------------------------------------------------------------# + cat << 'EOF' +Usage: mmake [] [-- ] ... +Options: + -s, --save-makefile: + Save the generated makefile to `Mmake.makefile'. + -v, --verbose: + Print verbose progress messages. + -h, --help: + Print this usage message. +Targets: + .depend: + Make the file `.dep'. This step is required + in preparation for the targets below. + : + Compile and link a Mercury program with main module + `.nl' to produce an executable. + .nu: + Compile and link a Mercury program with NU-Prolog + rather than with the Mercury compiler. + clean: + Remove intermediate files. + realclean: + Remove all automatically-generated files: intermediate files, + dependency files, and executables. +EOF +#-----------------------------------------------------------------------------# + exit + ;; + -s|--save-makefile) + save_makefile=true + MMAKE="$MMAKE $1" + shift + ;; + -v|--verbose) + verbose=true + MMAKE="$MMAKE $1" + shift + ;; + --) + MMAKE="$MMAKE $1" + shift + break + ;; + *) + break + ;; + esac +done + +if [ -f Mmake ]; then + mmake="Mmake" +else + mmake="" +fi +if [ "`echo *.dep`" = "*.dep" ]; then + deps="" +else + deps="*.dep" +fi +if [ "`echo *.d`" = "*.d" ]; then + ds="" +else + ds="*.d" +fi + +if $save_makefile; then + tmp=Mmake.makefile +else + tmp=/tmp/mmake.$$ + trap 'status=$?; rm -f $tmp; exit $status' 0 1 2 3 13 15 +fi + +if $verbose; then + echo MMAKE=$MMAKE + echo export MMAKE + echo MERCURY_INT_DIR=$MERCURY_INT_DIR + echo export MERCURY_INT_DIR + echo cat ${MMAKE_VARS} $deps $ds $mmake ${MMAKE_RULES} ">" $tmp + echo ${MAKE} -f $tmp "$@" +fi +export MMAKE +export MERCURY_INT_DIR +cat ${MMAKE_VARS} $deps $ds $mmake ${MMAKE_RULES} > $tmp +${MAKE} -f $tmp -r "$@" diff --git a/scripts/mnc.in b/scripts/mnc.in new file mode 100644 index 000000000..f6e58b592 --- /dev/null +++ b/scripts/mnc.in @@ -0,0 +1,62 @@ +#!/bin/sh +#---------------------------------------------------------------------------# +# Copyright (C) 1995 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. +#---------------------------------------------------------------------------# + +# MNC - Mercury NU-Prolog Compiler. +# +# Compiles Mercury programs to NU-Prolog object code (*.no). +# +# Usage: same as for `nc'. +# +# Environment variables: MERCURY_NC_BUILTIN + +nc_builtin_nl=${MERCURY_NC_BUILTIN=@LIBDIR@/nuprolog/nc_builtin.nl} + +options= + +unset target + +while true; do + case "$1" in + -F) options="$options $1 $2" + shift 2 + ;; + -o) target="$2" + shift 2 + ;; + -*) options="$options $1" + shift + ;; + *) break 2 + ;; + esac +done + +for file in "$@"; do + dir="`dirname $file`" + case $file in + *.m) base="`basename $file .m`" ;; + *.nl) base="`basename $file .nl`" ;; + *) base="`basename $file`" ;; + esac + rootname="$dir/$base" + tmp=/tmp/mnc$$ + trap 'rm -f $tmp.nl $tmp.ns $tmp.no; exit 1' 1 2 3 13 15 + cat $nc_builtin_nl > $tmp.nl + # as a special-case hack, if there is a .pp file we use it instead, + # after preprocessing away any #if NU_PROLOG commands in it + if [ -f "$rootname.pp" ]; then + echo "mnc: compiling \`$rootname.pp'" + sed -e '/^#if *NU_PROLOG/s/.*//' -e '/^#endif/s/.*//' \ + "$rootname.pp" >> $tmp.nl + else + echo "mnc: compiling \`$file'" + cat $file >> $tmp.nl + fi + nc -c $options $tmp.nl + rm $tmp.nl $tmp.ns + mv $tmp.no ${target="$rootname.no"} +done diff --git a/scripts/mnl.in b/scripts/mnl.in new file mode 100644 index 000000000..c529060e5 --- /dev/null +++ b/scripts/mnl.in @@ -0,0 +1,61 @@ +#!/bin/sh +#---------------------------------------------------------------------------# +# Copyright (C) 1995 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. +#---------------------------------------------------------------------------# + +# mnl - Mercury NU-Prolog Linker. +# +# Links NU-Prolog object files together with the Mercury library +# to produce an executable binary. +# +# Usage: mnl [-v|--verbose] [] files... +# +# Environment variables: MERCURY_LIB_DIR, MERCURY_LIB_OBJS + +NULIBDIR=${MERCURY_LIB_DIR=@LIBDIR@/nuprolog/@FULLARCH@} +LIBRARY_OBJS=${MERCURY_LIB_OBJS=`cd $NULIBDIR; echo *.no`} + +options= +verbose=false +debug=false + +while true; do + case "$1" in + -v|--verbose) + verbose=true + shift + ;; + -d|--debug) + debug=true + shift + ;; + -e|-u|-o|-F) + options="$options $1 $2" + shift 2 + ;; + -*) options="$options $1" + shift + ;; + *) break 2 + ;; + esac +done +if $debug; then + LIBRARY_OBJS="$LIBRARY_OBJS debug.no portray.no" +fi + +objlist= +for obj in $LIBRARY_OBJS; do + if echo "" "$@" "" | grep " $obj " > /dev/null; then + true + else + objlist="$objlist $NULIBDIR/$obj" + fi +done + +if $verbose; then + echo nc $options $objlist "$@" +fi +exec nc $options $objlist "$@" diff --git a/scripts/mnp.in b/scripts/mnp.in new file mode 100644 index 000000000..484a211d1 --- /dev/null +++ b/scripts/mnp.in @@ -0,0 +1,18 @@ +#!/bin/sh +#---------------------------------------------------------------------------# +# Copyright (C) 1995 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. +#---------------------------------------------------------------------------# + +# mnp - Mercury NU-Prolog Interpreter +# +# A version of `np' with `np_builtin' and the Mercury library already loaded. +# +# Usage: mnp [] +# +# Environment variables: MERCURY_INTERPRETER + +INTERPRETER=${MERCURY_INTERPRETER=@LIBDIR@/nuprolog/@FULLARCH@/library.nu} + +exec $INTERPRETER "$@" diff --git a/scripts/mod2init.in b/scripts/mod2init.in new file mode 100644 index 000000000..8805da4c6 --- /dev/null +++ b/scripts/mod2init.in @@ -0,0 +1,94 @@ +#!/bin/sh +#---------------------------------------------------------------------------# +# Copyright (C) 1995 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. +#---------------------------------------------------------------------------# + +# MOD2INIT - Convert *.mod (or *.c) to *_init.c +# +# This script outputs an appropriate init.c, given the .mod (or .c) files. +# +# Usage: mod2init [-w] modules... +# +# Environment variables: MERCURY_MOD_LIB_DIR, MERCURY_MOD_LIB_MODS. + +MERCURY_MOD_LIB_DIR=${MERCURY_MOD_LIB_DIR=@LIBDIR@/modules} +MERCURY_MOD_LIB_MODS=${MERCURY_MOD_LIB_MODS=@LIBDIR@/modules/*} + +# maximum number of calls to put in a single function +calls_per_func=50 + +defentry=mercury__io__run_0_0 +while getopts w: c +do + case $c in + w) defentry="$OPTARG";; + \?) echo "Usage: mod2init -[wentry] modules ..." + exit 1;; + esac + shift `expr $OPTIND - 1` +done + +files="$* $MERCURY_MOD_LIB_MODS" +modules="`sed -n '/^BEGIN_MODULE(\(.*\)).*$/s//\1/p' $files`" +echo "/*"; +echo "** This code was automatically generated by mod2init."; +echo "** Do not edit."; +echo "**" +echo "** Input files:" +for file in $files; do + echo "** $file" +done +echo "*/"; +echo ""; +echo '#include '; +echo '#include "init.h"'; +echo ""; +echo "Declare_entry($defentry);"; +echo "#if defined(USE_GCC_NONLOCAL_GOTOS) && !defined(USE_ASM_LABELS)"; +echo "Code *default_entry;"; +echo "#else"; +echo "Code *default_entry = ENTRY($defentry);"; +echo "#endif"; +echo ""; +for mod in $modules; do + echo "extern void $mod(void);"; +done +echo ""; +echo "#ifdef CONSERVATIVE_GC"; +echo "/* This works around a bug in the Solaris 2.X (X <= 4) linker. */"; +echo "/* The reason it is here is that it needs to be in statically linked */"; +echo "/* code, it won't work if it is in the dynamically linked library. */"; +echo "void init_gc(void)"; +echo "{"; +echo " GC_INIT();"; +echo "}"; +echo "#endif"; +echo ""; + +init_funcs= +num_funcs=0 +set - $modules +while [ $# -gt 0 ]; do + num_funcs=`expr $num_funcs + 1` + init_funcs="$init_funcs init_modules_$num_funcs" + echo "static void init_modules_$num_funcs(void) {" + num_calls=0 + while [ $# -gt 0 ] && [ $num_calls -lt $calls_per_func ]; do + num_calls=`expr $num_calls + 1` + echo " $1();" + shift + done + echo "}" + echo "" +done + +echo "void init_modules(void)"; +echo "{"; +for init in $init_funcs; do + echo " $init();"; +done +echo ""; +echo " default_entry = ENTRY($defentry);"; +echo "}"; diff --git a/scripts/msc.in b/scripts/msc.in new file mode 100644 index 000000000..eb43b5c54 --- /dev/null +++ b/scripts/msc.in @@ -0,0 +1,105 @@ +#!/bin/sh +#---------------------------------------------------------------------------# +# Copyright (C) 1995 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. + +sp_builtin_pl=${MERCURY_SP_BUILTIN=@LIBDIR@/sicstus/sp_builtin.pl} +sicstus_compile=\ +${MERCURY_SICSTUS_COMPILER=@LIBDIR@/sicstus/@FULLARCH@/sicstus_compile} + +help=false +compile_mode=fastcode +unset target + +while true; do + case $1 in + -h|--help) + help=true + break + ;; + -o|--output) + target=$2 + shift 2 + ;; + -m|--mode) + compile_mode=$2 + shift 2 + ;; + --) + shift + break + ;; + -*) + echo "$0: unrecognized option \`$1'" 1>&2 + exit 1 + ;; + *) + break + ;; + esac +done + +if [ $# -lt 1 ] || $help; then + cat << 'EOF' +MSC - Mercury SICStus Compiler. +Compiles Mercury programs to SICStus Prolog object code (*.ql). +Usage: msc [] file(s) +Options: + -h, --help + Print this help message + -o , --output + Name the output file . + -m , --mode + Use the specified mode of compilation. + should be either compactcode, fastcode, + or profiledcode. +Environment variables: MERCURY_SP_BUILTIN, MERCURY_SICSTUS_COMPILER +EOF + exit 0 +fi + +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 + rootname="$dir/$base" + 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 + mv $tmp.ql ${target="$rootname.ql"} +done diff --git a/scripts/msl.in b/scripts/msl.in new file mode 100644 index 000000000..937c21ff7 --- /dev/null +++ b/scripts/msl.in @@ -0,0 +1,110 @@ +#!/bin/sh +#---------------------------------------------------------------------------# +# Copyright (C) 1995 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. +#---------------------------------------------------------------------------# + +# msl - Mercury SICStus Prolog Linker. +# +# Loads SICStus object files (*.ql) together with the Mercury library +# into the SICStus interpreter, and then saves the state to produce an +# executable binary. +# +# Usage: msl [] files... +# Options: +# -v, --verbose +# -d, --debug +# -o, --output +# Environment variables: MERCURY_SP_LIB_DIR, MERCURY_SP_LIB_OBJS + +SP=${MERCURY_SICSTUS_PROLOG=@LIBDIR@/sicstus/@FULLARCH@/library.sicstus.debug} +SPLIBDIR=${MERCURY_SP_LIB_DIR=@LIBDIR@/sicstus/@FULLARCH@} +LIBRARY_OBJS=${MERCURY_SP_LIB_OBJS=`cd $SPLIBDIR; echo *.ql`} + +verbose=false +debug=false +save_temp=false +target=a.out + +while true; do + case "$1" in + -v|--verbose) + verbose=true + shift + ;; + -d|--debug) + debug=true + shift + ;; + -o|--output) + target=$2 + shift 2 + ;; + -s|--save-temp) + save_temp=true + shift + ;; + -*) + echo "$0: invalid option \`$1'" 1>&2 + exit 1 + ;; + *) break 2 + ;; + esac +done + +objlist= +for obj in $LIBRARY_OBJS; do + if [ "$obj" = "sp_lib.ql" ]; then + sp_lib=$SPLIBDIR/$obj + elif echo "" "$objlist" "$@" "" | grep " $obj " > /dev/null; then + true + else + objlist="$objlist $SPLIBDIR/$obj" + fi +done + +if $verbose; then + echo Linking $objlist "$@" $sp_lib +fi +if $save_temp; then + tmp=msl.tmp +else + tmp=/tmp/msl$$ + trap 'rm -f $tmp; exit 1' 1 2 3 13 15 + trap 'rm -f $tmp; exit 0' 0 +fi +if $debug; then + cat > $tmp << EOF + assert((mercury_do_save :- + on_exception(Error, ( + prolog_flag(compiling, _, fastcode), + unix(argv(Files)), load(Files), + abolish(mercury_do_save), + save('$target', _), + version + ), (print_message(error, Error), halt)))). + + mercury_do_save. + +EOF + $SP $objlist "$@" $sp_lib < $tmp 2>&1 +else + cat > $tmp << EOF + on_exception(Error, ( + prolog_flag(compiling, _, fastcode), + unix(argv(Files)), load(Files), + garbage_collect, + save('$target', 1), + unix(argv(Args)), run([mc|Args]) + ), print_message(error, Error)), halt ; halt. + e + e + e + e +EOF + $SP $objlist "$@" $sp_lib < $tmp 2>&1 +fi # grep -v 'DOMAIN ERROR.*when_condition' +# We pipe the output through grep -v to suppress some spurious warnings +# caused by the NU-Prolog when declarations not matching Sicstus syntax. diff --git a/scripts/msp.in b/scripts/msp.in new file mode 100644 index 000000000..398379734 --- /dev/null +++ b/scripts/msp.in @@ -0,0 +1,19 @@ +#!/bin/sh +#---------------------------------------------------------------------------# +# Copyright (C) 1995 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. +#---------------------------------------------------------------------------# + +# msp - Mercury SICStus Prolog Interpreter +# +# A version of `sp' with `sp_builtin' and the Mercury library already loaded. +# +# Usage: msp [] +# +# Environment variables: MERCURY_SICSTUS_INTERPRETER + +INTERPRETER=\ +${MERCURY_SICSTUS_INTERPRETER=@LIBDIR@/sicstus/@FULLARCH@/library.sicstus} + +exec $INTERPRETER "$@" diff --git a/scripts/sicstus_conv.in b/scripts/sicstus_conv.in new file mode 100644 index 000000000..74d6dc78d --- /dev/null +++ b/scripts/sicstus_conv.in @@ -0,0 +1,33 @@ +#!/bin/sh +#---------------------------------------------------------------------------# +# Copyright (C) 1995 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. +#---------------------------------------------------------------------------# +# +# This sed script is used to convert from Mercury 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 `#'. + +for file in "$@"; do + case $file in + *.m) base=`basename $file .m` ;; + *.nl) base=`basename $file .nl` ;; + *) base=`basename $file` ;; + esac + sed -e ' + / 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 > $base.pl +done