#!/bin/sh
# usage: binfile [-i] [-a <align>] <target-src.S> <binary-file> <varname>
# -a <align>  align data at 2^<align> boundary (default: byte alignment)
# -i          add to .init.rodata (default: .rodata) section

section=""
align=0

OPTIND=1
while getopts "ia:" opt; do
    case "$opt" in
    i)
        section=".init"
        ;;
    a)
        align=$OPTARG
        ;;
    esac
done
SHIFT=$((OPTIND-1))
shift $SHIFT

target=$1
binsource=$2
varname=$3

cat <<EOF >$target
#include <xen/linkage.h>

        .section $section.rodata, "a", %progbits

DATA($varname, 1 << $align)
        .incbin "$binsource"
.Lend:
END($varname)

        ASM_INT(${varname}_size, .Lend - $varname)
EOF
