Files
mercury/scripts/ml.in
Fergus Henderson 08d0172754 For efficiency, use shell builtins rather than calling /bin/true:
scripts/mgnuc.in:
	For efficiency, use shell builtins rather than calling /bin/true:
	use `:' rather than `true' and use `case' rather than `if'.

scripts/ml.in:
	By default, strip the executable.
	(This speeds up linking considerably on systems without
	shared libraries, and most of the time debugging information
	is not used, since gdb doesn't support Mercury yet anyway.)
	Add -g / --no-strip option to suppress stripping.
	Use `case' rather than `if', for efficiency.
1995-09-09 11:30:26 +00:00

145 lines
3.3 KiB
Bash

#! /bin/sh
# @configure_input@
#---------------------------------------------------------------------------#
# 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 [<ml options>] [<gcc options] files...
# Options:
# -v, --verbose
# Echo gcc command line before executing it
# -g, --no-strip
# Do not strip debugging information
# -s <grade>, --grade <grade>
# Specify which grade of the Mercury library to link with.
# (The default grade is determined by `configure'.)
#
# Environment variables: MERCURY_C_LIB_DIR, MERCURY_DEFAULT_GRADE
LIBDIR=${MERCURY_C_LIB_DIR=@LIBDIR@/lib}
DEFAULT_GRADE=${MERCURY_DEFAULT_GRADE=@DEFAULT_GRADE@}
# DEMANGLER=${MERCURY_DEMANGLER=@LIBDIR@/bin/@FULLARCH@/mdemangle}
DEMANGLER=${MERCURY_DEMANGLER=mdemangle}
CC=${MERCURY_C_COMPILER=@CC@}
verbose=false
strip=true
GRADE=$DEFAULT_GRADE
while true; do
case "$1" in
-v|--verbose)
verbose=true
shift ;;
-s|--grade)
shift
GRADE="$1"
shift ;;
--strip)
strip=true
shift ;;
-g|--no-strip)
strip=false
shift ;;
--no-libs)
MERCURY_LIBS=
shift ;;
--)
shift
break ;;
-static|-shared)
break ;;
-s*)
GRADE="` expr $1 : '-s\(.*\)' `"
shift ;;
*)
break ;;
esac
done
case "$GRADE" in
*.gc.prof)
LIBGC="-lgc.prof"
;;
*.gc)
LIBGC="-lgc"
;;
*)
LIBGC=
;;
esac
case $strip in
true) STRIP_OPTS="-s" ;;
false) STRIP_OPTS="" ;;
esac
LIBS=${MERCURY_LIBS="-lmer -lmercury -lmer $LIBGC -lm"}
case @FULLARCH@ in
*-solaris*)
LIBDIR_OPTS="
-R@LIBDIR@/lib/@FULLARCH@ -L$LIBDIR/@FULLARCH@
-R@LIBDIR@/lib/$GRADE/@FULLARCH@ -L$LIBDIR/$GRADE/@FULLARCH@
"
;;
alpha-dec-osf*)
LIBDIR_OPTS="
-Wl,-rpath,@LIBDIR@/lib/@FULLARCH@:@LIBDIR@/lib/$GRADE/@FULLARCH@
-L$LIBDIR/@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@
"
case "$GRADE" in
*fast*|*jump*)
ARCH_OPTS=-non_shared
LIBRARY_PATH="/usr/contrib/lib/nonshared:/usr/lib/nonshared:$LIBRARY_PATH"
export LIBRARY_PATH
;;
esac
;;
*)
LIBDIR_OPTS="
-L$LIBDIR/@FULLARCH@
-L$LIBDIR/$GRADE/@FULLARCH@
"
;;
esac
case $verbose in
true) echo $CC $STRIP_OPTS $ARCH_OPTS "$@" $LIBDIR_OPTS $LIBS "|"
echo "$DEMANGLER"
;;
false) ;;
esac
# we would like to just run $CC and pipe the result into $DEMANGLER,
# but `$CC | $DEMANGLER' would return the wrong exit status, so
# we need to use a named pipe
# create the pipe, making sure we remove it if interrupted
PIPE=/tmp/ml.$$
trap 'rm -f $PIPE' 0 1 2 3 13 15
mkfifo $PIPE
# execute the demangler in the background,
# with stdin coming from the pipe and with stdout redirected to stderr
exec $DEMANGLER 1>&2 < $PIPE &
# redirect our stdout and stderr into the pipe
exec >$PIPE 2>&1
# now we can remove the pipe; since is an open file, it will stay
# around until $CC and $DEMANGLER exit
rm -f $PIPE
# finally execute $CC;
# stdout & stderr will go via the pipe to $DEMANGLER and then to stderr
exec $CC $STRIP_OPTS $ARCH_OPTS "$@" $LIBDIR_OPTS $LIBS