102 lines
1.8 KiB
Bash
Executable File
102 lines
1.8 KiB
Bash
Executable File
#!/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
|
|
|