blob: 23d5b8d8f0c6d9d80e1831f2238838f475da3639 [file] [log] [blame]
#!/bin/sh
usage() {
cat <<EOF
Usage: $0 <input> <output>
Generate xlat header files from <input> (a file or dir of files) and write
the generated headers to <output>.
EOF
exit 1
}
gen_header() {
local input="$1" output="$2" name="$3"
local line
echo "generating ${output}"
(
echo "/* Generated by $0 from $1; do not edit. */"
echo "const struct xlat ${name}[] = {"
while read line ; do
case ${line} in
/*|\#*|'')
echo "${line}"
;;
*)
echo "#ifdef ${line}"
echo " XLAT(${line}),"
echo "#endif"
;;
esac
done < "${input}"
echo " XLAT_END"
echo "};"
) >"${output}"
}
gen_make() {
local output="$1"
local name
shift
echo "generating ${output}"
(
printf "XLAT_INPUT_FILES = "
printf 'xlat/%s.in ' "$@"
echo
printf "XLAT_HEADER_FILES = "
printf 'xlat/%s.h ' "$@"
echo
for name; do
printf '$(top_srcdir)/xlat/%s.h: $(top_srcdir)/xlat/%s.in $(top_srcdir)/xlat/gen.sh\n' \
"${name}" "${name}"
echo ' $(AM_V_GEN)$(top_srcdir)/xlat/gen.sh $< $@'
done
) >"${output}"
}
gen_git() {
local output="$1"
shift
echo "generating ${output}"
(
printf '/%s\n' .gitignore Makemodule.am
printf '/%s.h\n' "$@"
) >"${output}"
}
main() {
case $# in
0) set -- "${0%/*}" "${0%/*}" ;;
2) ;;
*) usage ;;
esac
local input="$1"
local output="$2"
local name
if [ -d "${input}" ]; then
local f name names
for f in "${input}"/*.in; do
name=${f##*/}
name=${name%.in}
gen_header "${f}" "${output}/${name}.h" "${name}" &
names="${names} ${name}"
done
gen_git "${output}/.gitignore" ${names}
gen_make "${output}/Makemodule.am" ${names}
wait
else
name=${input##*/}
name=${name%.in}
gen_header "${input}" "${output}" "${name}"
fi
}
main "$@"