Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] View of /config/trunk/_heap2exec
ViewVC logotype

View of /config/trunk/_heap2exec

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6027 - (download) (annotate)
Sun Dec 1 14:39:11 2019 UTC (7 weeks, 5 days ago) by jhr
File size: 3190 byte(s)
  fix for bug #237
#!@SHELL@
#
# COPYRIGHT (c) 2019 The Fellowship of SML/NJ (http://www.smlnj.org)
# All rights reserved.
#
# usage: heap2exec [--linkwith-<format>] heapfile execfile
#

CMD=`basename "$0"`

usage() {
	echo "usage: $CMD [--linkwith-<format>] <heapfile> <execfile>"
	echo "       <format> = exec | so | a"
	exit 1
}

die () {
	echo "${CMD}: $1"
	exit 1
}

# the default size; this is set by the config/install.sh script
#
SIZE=@SIZE@
if [ x"$1" = x-32 ] ; then
  SIZE=32 ; shift
elif [ x"$1" = x-64 ] ; then
  SIZE=64 ; shift
fi
SIZE_OPT="-"$SIZE

if [ x${SMLNJ_HOME} = x ] ; then
    BIN_DIR="@BINDIR@"
else
    BIN_DIR=${SMLNJ_HOME}/bin
fi

ARCH_N_OPSYS=`"$BIN_DIR/.arch-n-opsys" $SIZE_OPT`
if [ "$?" != "0" ]; then
	die "unable to determine architecture/operating system"
fi
eval $ARCH_N_OPSYS

RUNX=${BIN_DIR}/.run/runx.${ARCH}-${OPSYS}
RUN_SO=${BIN_DIR}/.run/run.${ARCH}-${OPSYS}.so
RUN_A=${BIN_DIR}/.run/run.${ARCH}-${OPSYS}.a
H2A=${BIN_DIR}/heap2asm

FORMAT=
if [ $# != 2 ] ; then
    if [ $# = 3 ] ; then
	case $1 in
	    --linkwith-exec)
		FORMAT=exec
		;;
	    --linkwith-so)
		FORMAT=so
		;;
	    --linkwith-a)
		FORMAT=a
		;;
	    *)
		usage
		;;
	esac
	shift
    else
	usage
    fi
else
    case ${OPSYS} in
	darwin)
	    FORMAT=exec
	    ;;
	freebsd|linux)
	    FORMAT=a
	    ;;
	*)
	    die "no default runtime link format known for ${OPSYS}"
	    ;;
	esac
fi
if [ -z "$FORMAT" ] ; then
    die "no runtime object format specified"
fi

heapfile=$1
execfile=$2

CC=cc
LD=ld

EXEC_PROG=
EXEC_FLAGS=
EXEC_LIBS=
SO_PROG=
SO_FLAGS=
SO_LIBS=
A_PROG=
A_FLAGS=
A_LIBS=

case ${OPSYS} in
    darwin)
	EXEC_PROG=${LD}
	EXEC_LIBS=-lc
	;;
    freebsd)
	SO_PROG=${CC}
	SO_FLAGS=-Wl,--export-dynamic
	SO_LIBS=-lm
	A_PROG=${CC}
	A_FLAGS=-Wl,--export-dynamic
	A_LIBS=-lm
	;;
    linux)
	SO_PROG=${CC}
	SO_FLAGS=-Wl,--export-dynamic
	A_PROG=${CC}
	A_FLAGS=-Wl,--export-dynamic
	A_LIBS="-lm -ldl"
	;;
    *)
	;;
esac

if [ ! -f $H2A ]; then
    echo "${CMD}: heap2asm is not installed"
    exit 2
fi

RESULT=0
if ${H2A} $SIZE_OPT "$heapfile" "$execfile".s ; then
    if [ -f "$execfile".s ] ; then
	if ${CC} -c -o "$execfile".o "$execfile".s ; then
	    rm "$execfile".s
	else
	    rm "$execfile".s
	    die "${execfile}.o creation failed"
	fi
    else
	die "${execfile}.s creation failed"
    fi
    if [ "$FORMAT" = exec -a -f "${RUNX}" ] ; then
	[ -z "${EXEC_PROG}" ] && die "no linker specified for runtime format $FORMAT"
	${EXEC_PROG} ${EXEC_FLAGS} -o "$execfile" ${RUNX} "$execfile".o ${EXEC_LIBS}
	RESULT=$?
    elif [ "$FORMAT" = so -a -f "${RUN_SO}" ] ; then
	[ -z "${SO_PROG}" ] && die "no linker specified for runtime format $FORMAT"
	${SO_PROG} ${SO_FLAGS} -o "$execfile" ${RUN_SO} "$execfile".o ${SO_LIBS}
	RESULT=$?
    elif [ "$FORMAT" = a -a -f "${RUN_A}" ] ; then
	[ -z "${A_PROG}" ] && die "no linker specified for runtime format $FORMAT"
	${A_PROG} ${A_FLAGS} -o "$execfile" ${RUN_A} "$execfile".o ${A_LIBS}
	RESULT=$?
    else
	echo "${CMD}: linkable runtime system object ($FORMAT) not available"
	rm "$execfile".o
	exit 2
    fi
    rm "$execfile".o
else
    die "heap2asm failed"
fi

if [ $RESULT != 0 ] ; then
    die "linking failed with return code $RESULT"
fi

exit 0

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0