blob: 1a0ad5140c018b24406c0dcfd14f1101ca418857 (
plain)
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
|
#!/bin/sh
set -e
set -u
# Default output file name:
outputfile="a.wrap.o"
# --32 or --64. Empty by default. To pass to GNU as.
bitness=""
# Print assembler source code to stdout
# instead of compiling to ELF object
show_source="no"
fatal () {
echo "$0: $@" >&2
echo "$0: Type \`$0 -h' to get help" >&2
exit 2
}
usage () {
echo "$0 [ -64 | -32 ] [ -o outputfile ] [ -s ] files ..."
exit 1
}
files=""
collect() {
files="$files$1|"
}
processing_options="yes"
while [ $# != 0 ]; do
opt="$1"
shift
if [ "$processing_options" = yes ]; then
case "$opt" in
--)
processing_options="no"
;;
-s)
show_source="yes"
;;
-h|--help)
usage
;;
-32|--32)
bitness="--32"
;;
-64|--64)
bitness="--64"
;;
-o)
[ $# != 0 ] || fatal "Option -o requires an argument"
outputfile="$1"
shift
;;
-*)
fatal "Invalid option: $opt"
;;
*)
collect "$opt"
;;
esac
else
collect "$opt"
fi
done
if [ -z "$files" ]; then
fatal "No files given."
fi
(
IFS='|'
set -- $files
for f in "$@"; do
base=`basename -- "$f" | sed -e 's,[^0-9a-zA-Z_],_,g' -e 's,^\([0-9]\),_\1,'`
echo ".section .${base}, \"a\", @progbits"
echo ".global ${base}_start"
echo ".global ${base}_end"
echo ".type ${base}_start, @object"
echo ".type ${base}_end, @object"
echo "${base}_start:"
echo ".incbin \"$f\""
echo "${base}_end:"
echo
done
) | (
if [ "$show_source" = yes ]; then
cat
else
as $bitness -o "$outputfile" --
fi
)
exit 0
|