Enhance xlat generator

* xlat/gen.sh: Define all xlat structs not declared in defs.h as static.
Some symbolic constants are not macros, extend #ifdef check to cover
symbolic constants checked by AC_CHECK_DECLS.
Handle complex symbolic constants in SYMBOL|... form.
Handle symbolic constants in 1<<SYMBOL form.
Handle numeric constants.
Implement #unconditional directive that turns off preprocessor checks.
Implement #unterminated directive that turns off adding XLAT_END.
diff --git a/xlat/gen.sh b/xlat/gen.sh
index 23d5b8d..f217840 100755
--- a/xlat/gen.sh
+++ b/xlat/gen.sh
@@ -12,24 +12,60 @@
 
 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
 			;;
-		*)
-			echo "#ifdef ${line}"
+		'#unterminated')
+			unterminated=1
+			;;
+		[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}"
 }
@@ -76,8 +112,9 @@
 	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}" &