Files
mercury/scripts/mod2init.sh
Fergus Henderson f79d5f9632 Due to a bug in the Solaris linker, we need to call the GC_INIT()
scripts/mod2init.sh, runtime/{wrapper.mod,init.h}:
        Due to a bug in the Solaris linker, we need to call the GC_INIT()
        macro from some statically linked part of the code.
        So I've modified mod2init to add an init_gc() function to the init
        file, and I've modified wrapper.mod to call it.
1995-03-18 07:51:34 +00:00

69 lines
1.7 KiB
Bash

#!/bin/sh
# MOD2INIT - Convert *.mod (or *.c) to *_init.c
#
# This script outputs an appropriate init.c, given the .mod (or .c) files.
#
# Usage: mod2init [-w<entry_point>] 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/*}
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 <stddef.h>';
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 "";
echo "void init_modules(void)";
echo "{";
for mod in $modules; do
echo " $mod();";
done
echo "";
echo " default_entry = ENTRY($defentry);";
echo "}";