mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-21 20:33:55 +00:00
Estimated hours taken: 1
Some work towards making it easier to use shared libraries on Linux.
scripts/ml.in:
Add a `--mercury-libs {shared, static, none}' option
(`--mercury-libs none' replaces the old `--no-libs' option).
Add `--shared' and `--static' options.
Add a `--help' option.
275 lines
6.3 KiB
Bash
275 lines
6.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: see below.
|
|
#
|
|
# Environment variables: MERCURY_C_LIB_DIR, MERCURY_DEFAULT_GRADE, ...
|
|
|
|
Help="\
|
|
Name: ml - Mercury Linker
|
|
Usage: ml [<ml options>] [<gcc options] files...
|
|
Options:
|
|
-h, --help
|
|
Print this help message.
|
|
-v, --verbose
|
|
Echo the gcc command line before executing it.
|
|
--mercury-libs {shared, static, none}
|
|
Specify which version of the standard Mercury libraries to
|
|
link with:
|
|
--mercury-libs shared
|
|
Link with the shared Mercury libraries (*.so),
|
|
if possible, otherwise with the static ones.
|
|
--mercury-libs static
|
|
Link with the static Mercury libraries (*.a).
|
|
--mercury-libs none
|
|
Don't link in the Mercury libraries.
|
|
-shared, --shared
|
|
Similar to \`--mercury-libs shared', but applies to all
|
|
libraries, not just the standard Mercury libraries.
|
|
-static, --static
|
|
Similar to \`--mercury-libs static', but applies to all
|
|
libraries, not just the standard Mercury libraries.
|
|
--no-demangle
|
|
Don't pipe the output of the linker through the Mercury
|
|
demangler.
|
|
-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'.)"
|
|
|
|
FULLARCH=@FULLARCH@
|
|
NONSHARED_LIB_DIR=${MERCURY_NONSHARED_LIB_DIR=@NONSHARED_LIB_DIR@}
|
|
DEFAULT_LIBDIR=@LIBDIR@/lib
|
|
LIBDIR=${MERCURY_C_LIB_DIR=$DEFAULT_LIBDIR}
|
|
DEFAULT_GRADE=${MERCURY_DEFAULT_GRADE=@DEFAULT_GRADE@}
|
|
# DEMANGLER=${MERCURY_DEMANGLER=@LIBDIR@/bin/@FULLARCH@/mdemangle}
|
|
DEMANGLER=${MERCURY_DEMANGLER=mdemangle}
|
|
CC=${MERCURY_C_COMPILER="@CC@"}
|
|
MKFIFO=${MERCURY_MKFIFO="@MKFIFO@"}
|
|
|
|
verbose=false
|
|
case $FULLARCH in
|
|
*-win95|*-winnt|*-win32)
|
|
# `gcc -s' is broken in gnu-win32
|
|
strip=false
|
|
;;
|
|
*)
|
|
strip=true
|
|
;;
|
|
esac
|
|
case $FULLARCH in
|
|
i?86-*-linux*)
|
|
# shared libraries are not the default on Linux
|
|
# -- see README.Linux
|
|
mercury_libs=static
|
|
;;
|
|
*)
|
|
mercury_libs=shared
|
|
;;
|
|
esac
|
|
demangle=true
|
|
GRADE=$DEFAULT_GRADE
|
|
SHARED_OR_STATIC_OPT=""
|
|
|
|
while true; do
|
|
case "$1" in
|
|
-h|--help|"-?")
|
|
echo "$Help"
|
|
exit 0
|
|
;;
|
|
-v|--verbose)
|
|
verbose=true
|
|
shift ;;
|
|
--demangle)
|
|
demangle=true
|
|
shift ;;
|
|
--no-demangle)
|
|
demangle=false
|
|
shift ;;
|
|
-s|--grade)
|
|
shift
|
|
GRADE="$1"
|
|
shift ;;
|
|
--strip)
|
|
strip=true
|
|
shift ;;
|
|
-g|--no-strip)
|
|
strip=false
|
|
shift ;;
|
|
--no-libs)
|
|
progname=`basename $0`
|
|
cat 1>&2 << EOF
|
|
$progname: Warning: option \`--no-libs' is deprecated --
|
|
$progname: please use the new option \`--mercury-libs none' instead.
|
|
$progname: Support for \`--no-libs' may be removed in a future release.
|
|
EOF
|
|
mercury_libs=none
|
|
shift ;;
|
|
--mercury-libs)
|
|
case "$2" in
|
|
shared|static|none)
|
|
mercury_libs="$2"
|
|
shift; shift ;;
|
|
*)
|
|
progname=`basename $0`
|
|
cat 1>&2 << EOF
|
|
$progname: Error: parameter to \`--mercury-libs' option should be
|
|
$progname: either \`shared', \`static', or \`none', not \`$2'.
|
|
$progname: Try `$0 --help' for help.
|
|
EOF
|
|
exit 1
|
|
;;
|
|
esac
|
|
;;
|
|
-shared|--shared)
|
|
STATIC_OR_SHARED_OPT=-shared
|
|
case $mercury_libs in static)
|
|
mercury_libs=shared ;;
|
|
esac
|
|
;;
|
|
-static|--static)
|
|
STATIC_OR_SHARED_OPT=-static
|
|
case $mercury_libs in shared)
|
|
mercury_libs=static ;;
|
|
esac
|
|
;;
|
|
--)
|
|
shift
|
|
break ;;
|
|
-s*)
|
|
GRADE="` expr $1 : '-s\(.*\)' `"
|
|
shift ;;
|
|
*)
|
|
break ;;
|
|
esac
|
|
done
|
|
|
|
case "$GRADE" in
|
|
*.gc.prof*)
|
|
LIBGC="-lgc_prof"
|
|
LIBGC_STATIC="$LIBDIR/$FULLARCH/libgc_prof.a"
|
|
;;
|
|
*.gc*)
|
|
LIBGC="-lgc"
|
|
LIBGC_STATIC="$LIBDIR/$FULLARCH/libgc.a"
|
|
;;
|
|
*)
|
|
LIBGC=
|
|
LIBGC_STATIC=
|
|
;;
|
|
esac
|
|
|
|
case $strip in
|
|
true) STRIP_OPTS="-s" ;;
|
|
false) STRIP_OPTS="" ;;
|
|
esac
|
|
|
|
case $mercury_libs in
|
|
shared) LIBS=${MERCURY_LIBS="-lmercury -lmer $LIBGC -lm"}
|
|
;;
|
|
static) LIBS=${MERCURY_LIBS="\
|
|
$LIBDIR/$GRADE/$FULLARCH/libmercury.a \
|
|
$LIBDIR/$GRADE/$FULLARCH/libmer.a \
|
|
$LIBGC_STATIC \
|
|
-lm"}
|
|
;;
|
|
none) LIBS=""
|
|
;;
|
|
esac
|
|
|
|
case $FULLARCH in
|
|
i?86-*-linux*)
|
|
LIBDIR_OPTS="
|
|
-Wl,-rpath,$DEFAULT_LIBDIR/$FULLARCH -L$LIBDIR/$FULLARCH
|
|
-Wl,-rpath,$DEFAULT_LIBDIR/$GRADE/$FULLARCH -L$LIBDIR/$GRADE/$FULLARCH
|
|
"
|
|
;;
|
|
*-solaris*)
|
|
LIBDIR_OPTS="
|
|
-R$DEFAULT_LIBDIR/$FULLARCH -L$LIBDIR/$FULLARCH
|
|
-R$DEFAULT_LIBDIR/$GRADE/$FULLARCH -L$LIBDIR/$GRADE/$FULLARCH
|
|
"
|
|
;;
|
|
alpha-dec-osf*)
|
|
LIBDIR_OPTS="
|
|
-Wl,-rpath,$DEFAULT_LIBDIR/$FULLARCH:$DEFAULT_LIBDIR/$GRADE/$FULLARCH
|
|
-L$LIBDIR/$FULLARCH -L$LIBDIR/$GRADE/$FULLARCH
|
|
"
|
|
;;
|
|
*-sgi-irix5*)
|
|
LIBDIR_OPTS="
|
|
-Wl,-rpath,$DEFAULT_LIBDIR/$FULLARCH:$DEFAULT_LIBDIR/$GRADE/$FULLARCH
|
|
-L$LIBDIR/$FULLARCH -L$LIBDIR/$GRADE/$FULLARCH
|
|
"
|
|
case "$GRADE" in
|
|
*fast*|*jump*)
|
|
ARCH_OPTS=-non_shared
|
|
LIBRARY_PATH="$NONSHARED_LIB_DIR:/usr/lib/nonshared:$LIBRARY_PATH"
|
|
export LIBRARY_PATH
|
|
;;
|
|
esac
|
|
;;
|
|
*)
|
|
LIBDIR_OPTS="
|
|
-L$LIBDIR/$FULLARCH
|
|
-L$LIBDIR/$GRADE/$FULLARCH
|
|
"
|
|
;;
|
|
esac
|
|
|
|
case "$MKFIFO" in
|
|
none) demangle=false ;;
|
|
esac
|
|
|
|
case $verbose in
|
|
true)
|
|
case $demangle in
|
|
false)
|
|
echo $CC $STRIP_OPTS $ARCH_OPTS "$@" $LIBDIR_OPTS $LIBS
|
|
;;
|
|
true)
|
|
echo $CC $STRIP_OPTS $ARCH_OPTS "$@" $LIBDIR_OPTS $LIBS "|"
|
|
echo "$DEMANGLER"
|
|
;;
|
|
esac
|
|
;;
|
|
esac
|
|
|
|
case $demangle in
|
|
true)
|
|
# 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; if the system doesn't have named
|
|
# pipes, then we don't use the demangler
|
|
|
|
# create the pipe, making sure we remove it if interrupted
|
|
PIPE=/tmp/ml.$$
|
|
trap 'rm -f $PIPE; exit 1' 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
|
|
;;
|
|
esac
|
|
case $# in
|
|
0) exec $CC $STRIP_OPTS $ARCH_OPTS $LIBDIR_OPTS $LIBS ;;
|
|
*) exec $CC $STRIP_OPTS $ARCH_OPTS "$@" $LIBDIR_OPTS $LIBS ;;
|
|
esac
|