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
+ local defs="${0%/*}/../defs.h"
+ local prefix
+ if grep -x "extern const struct xlat ${name}\\[\\];" "${defs}" > /dev/null; then
+ prefix=
+ else
+ prefix='static '
+ fi
+
+ cat <<-EOF
+ /* Generated by $0 from $1; do not edit. */
+
+ ${prefix}const struct xlat ${name}[] = {
+ EOF
+ local unconditional= unterminated= line
+ while read line; do
+ LC_COLLATE=C
case ${line} in
- /*|\#*|'')
- echo "${line}"
+ '#unconditional')
+ unconditional=1
+ ;;
+ '#unterminated')
+ unterminated=1
;;
- *)
- echo "#ifdef ${line}"
+ [A-Z_]*) # symbolic constants
+ local m="${line%%|*}"
+ [ -n "${unconditional}" ] ||
+ echo "#if defined(${m}) || (defined(HAVE_DECL_${m}) && HAVE_DECL_${m})"
echo " XLAT(${line}),"
- echo "#endif"
+ [ -n "${unconditional}" ] ||
+ echo "#endif"
+ ;;
+ '1<<'[A-Z_]*) # symbolic constants with shift
+ local m="${line#1<<}"
+ [ -n "${unconditional}" ] ||
+ echo "#if defined(${m}) || (defined(HAVE_DECL_${m}) && HAVE_DECL_${m})"
+ echo " { ${line}, \"${m}\" },"
+ [ -n "${unconditional}" ] ||
+ echo "#endif"
+ ;;
+ [0-9]*) # numeric constants
+ echo " XLAT(${line}),"
+ ;;
+ *) # verbatim lines
+ echo "${line}"
;;
esac
done < "${input}"
- echo " XLAT_END"
+ if [ -n "${unterminated}" ]; then
+ echo " /* this array should remain not NULL-terminated */"
+ else
+ echo " XLAT_END"
+ fi
echo "};"
) >"${output}"
}
local name
if [ -d "${input}" ]; then
- local f name names
+ local f names=
for f in "${input}"/*.in; do
+ [ -f "${f}" ] || continue
name=${f##*/}
name=${name%.in}
gen_header "${f}" "${output}/${name}.h" "${name}" &