File: _heap2exec

package info (click to toggle)
smlnj 110.79-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 82,564 kB
  • sloc: ansic: 32,532; asm: 6,314; sh: 2,296; makefile: 1,821; perl: 1,170; pascal: 295; yacc: 190; cs: 78; python: 77; lisp: 19
file content (154 lines) | stat: -rw-r--r-- 2,785 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!@SHELL@

CMD=`basename "$0"`

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

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

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

ARCH_N_OPSYS=`"$BIN_DIR/.arch-n-opsys"`
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} "$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