#define XLAT_END { 0, NULL }
extern const struct xlat addrfams[];
-extern const struct xlat adjtimex_modes[];
-extern const struct xlat adjtimex_status[];
extern const struct xlat at_flags[];
extern const struct xlat dirent_types[];
extern const struct xlat open_access_modes[];
extern const struct xlat open_mode_flags[];
extern const struct xlat resource_flags[];
-extern const struct xlat sigev_value[];
extern const struct xlat whence_codes[];
/* Format of syscall return values */
#!/bin/sh -e
-exec > mpers.am
+list="$(sed -n '/^strace_SOURCES[[:space:]]*=/,/^[[:space:]]*# end of strace_SOURCES/ s/^[[:space:]]*\([[:alnum:]][^.]*\.c\)[[:space:]]*\\$/\1/p' Makefile.am |
+ xargs -r grep -lx '#[[:space:]]*include[[:space:]]\+MPERS_DEFS' |
+ tr '\n' ' ')"
-echo "# Generated by $0; do not edit."
-printf 'mpers_source_files = '
+cat > mpers.am <<EOF
+# Generated by $0; do not edit.
+mpers_source_files = $list
+EOF
-sed -n '/^strace_SOURCES[[:space:]]*=/,/^[[:space:]]*# end of strace_SOURCES/ s/^[[:space:]]*\([[:alnum:]][^.]*\.c\)[[:space:]]*\\$/\1/p' Makefile.am |
- xargs -r grep -lx '#[[:space:]]*include[[:space:]]\+MPERS_DEFS' |
- tr '\n' ' '
-echo
+sed -n 's/^#[[:space:]]*include[[:space:]]*"xlat\/\([^."]\+\)\.h".*/extern const struct xlat \1[];/p' \
+ $list > mpers_xlat.h
exit 1
}
+cond_def()
+{
+ local line
+ line="$1"; shift
+
+ local val
+ val="$(printf %s "$line" |
+ sed -n 's/^\([^[:space:]]\+\).*$/\1/p')"
+
+ local def
+ def="$(printf %s "${line}" |
+ sed -n 's/^[^[:space:]]\+[[:space:]]\+\([^[:space:]].*\)$/\1/p')"
+
+ if [ -n "$def" ]; then
+ cat <<-EOF
+ #if !(defined($val) || (defined(HAVE_DECL_$val) && HAVE_DECL_$val))
+ # define $val $def
+ #endif
+ EOF
+ fi
+}
+
cond_xlat()
{
local line val m def xlat
sed -n 's/^[^[:space:]]\+[[:space:]]\+\([^[:space:]].*\)$/\1/p')"
if [ "${m}" = "${m#1<<}" ]; then
- xlat="XLAT(${val}),"
+ xlat=" XLAT(${val}),"
else
m="${m#1<<}"
xlat=" { ${val}, \"${m}\" },"
#endif
EOF
else
- cat <<-EOF
- #if !(defined(${m}) || (defined(HAVE_DECL_${m}) && HAVE_DECL_${m}))
- # define ${m} ${def}
- #endif
- ${xlat}
- EOF
+ echo "$xlat"
fi
}
echo "generating ${output}"
(
local defs="${0%/*}/../defs.h"
- local prefix
- if grep -x "extern const struct xlat ${name}\\[\\];" "${defs}" > /dev/null; then
- prefix=
- else
- prefix='static '
+ local mpers="${0%/*}/../mpers_xlat.h"
+ local decl="extern const struct xlat ${name}[];"
+ local in_defs= in_mpers=
+
+ if grep -F -x "$decl" "$defs" > /dev/null; then
+ in_defs=1
+ elif grep -F -x "$decl" "$mpers" > /dev/null; then
+ in_mpers=1
fi
- cat <<-EOF
- /* Generated by $0 from $1; do not edit. */
+ echo "/* Generated by $0 from $1; do not edit. */"
- ${prefix}const struct xlat ${name}[] = {
- EOF
local unconditional= unterminated= line
+ # 1st pass: output directives.
while read line; do
LC_COLLATE=C
- case ${line} in
+ case $line in
'#unconditional')
unconditional=1
;;
'#unterminated')
unterminated=1
;;
+ '#'*)
+ echo "${line}"
+ ;;
+ [A-Z_]*)
+ [ -n "$unconditional" ] ||
+ cond_def "$line"
+ ;;
+ esac
+ done < "$input"
+
+ echo
+ if [ -n "$in_defs" ]; then
+ cat <<-EOF
+ #ifndef IN_MPERS
+
+ EOF
+ elif [ -n "$in_mpers" ]; then
+ cat <<-EOF
+ #ifdef IN_MPERS
+
+ ${decl}
+
+ #else
+
+ # if !(defined HAVE_M32_MPERS || defined HAVE_MX32_MPERS)
+ static
+ # endif
+ EOF
+ else
+ cat <<-EOF
+ #ifdef IN_MPERS
+
+ # error static const struct xlat ${name} in mpers mode
+
+ #else
+
+ static
+ EOF
+ fi
+ echo "const struct xlat ${name}[] = {"
+
+ unconditional=
+ # 2nd pass: output everything.
+ while read line; do
+ LC_COLLATE=C
+ case ${line} in
+ '#unconditional')
+ unconditional=1
+ ;;
+ '#unterminated')
+ # processed during 1st pass
+ ;;
[A-Z_]*) # symbolic constants
if [ -n "${unconditional}" ]; then
echo " XLAT(${line}),"
fi
;;
'1<<'[A-Z_]*) # symbolic constants with shift
- m="${line%% *}"
if [ -n "${unconditional}" ]; then
echo " { ${line}, \"${line#1<<}\" },"
else
else
echo " XLAT_END"
fi
- echo "};"
+
+ cat <<-EOF
+ };
+
+ #endif /* !IN_MPERS */
+ EOF
) >"${output}"
}