-
Notifications
You must be signed in to change notification settings - Fork 2
/
bcl
executable file
·81 lines (72 loc) · 1.61 KB
/
bcl
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
#!/usr/bin/env bash
bcl="$(basename "$0")"
if [ "${bcl}" != "bcl" ]; then
target="$(basename "$0" bcl)"
else
target=""
fi
# TODO: change gcc to ld
BCC="${target}bcc"
LD="${target}gcc"
args=$(getopt -o "gsVcAiSEwhCe:I:D:U:O:d:l:L:o:" -- "$@") || exit 1
eval set -- "${args}"
unset args
output_file=""
bcc_options="-c -nostdlib"
ld_options=""
linking=yes
while true; do
case "$1" in
-c|-A|-i|-S|-E)
linking=no
bcc_options="${bcc_options} $1"
shift
;;
-w|-C)
bcc_options="${bcc_options} $1"
shift
;;
-o)
output_file="$2"
shift 2
;;
-e|-I|-D|-U|-O|-d)
bcc_options="${bcc_options} $1$2"
shift 2
;;
-l|-L)
ld_options="${ld_options} $1$2"
shift 2
;;
-s|-g)
ld_options="${ld_options} $1"
shift
;;
-h|-V)
"${target}bcc" -h
exit
;;
--)
shift
break
;;
*)
printf "bcl: invalid option '%s'\n" "$1" >&2
exit 1
esac
done
echo "The use of this tool is deprecated!" >&2
echo "It will be removed at some point since linking should hopefully work now." >&2
echo "If not, please file a bug report." >&2
[ -z "$1" ] && echo "Usage: ${target}bcl [options] file" >&2 && exit 1
file="$1"
if [ "${linking}" = "yes" ]; then
[ -z "${output_file}" ] && output_file="a.out"
"${BCC}" ${bcc_options} -o tmp.o "${file}" || exit 1
"${LD}" -o "${output_file}" tmp.o ${ld_options}
[ $? -ne 0 ] && rm -f tmp.o && exit 1
rm -f tmp.o
else
[ -n "${output_file}" ] && bcc_options="${bcc_options} -o ${output_file}"
"${BCC}" ${bcc_options} "${file}" || exit 1
fi