mpers: skip xlat struct definitions in mpers mode
Avoid duplicate definitions of xlat structures in files
compiled in mpers mode.
Each xlat file defines the corresponding xlat struct with
either global or local visibility using the following rules:
- if xlat struct declaration is available in defs.h,
a global definition is provided in regular mode,
and nothing is provided in mpers mode;
- otherwise, if xlat file is included by a mpers source file,
a global definition is provided in regular mode
(unless no mpers mode is supported on this architecture,
in that case, a local definition is provided instead),
and a declaration is provided in mpers mode;
- otherwise, a local definition is provided in regular mode,
and an error message is printed in mpers mode.
Fallback definitions of constants provided by xlat files
remain available in all modes.
* bootstrap: Invoke generate_mpers_am.sh before xlat/gen.sh.
* defs.h (adjtimex_modes, adjtimex_status, sigev_value): Remove.
* generate_mpers_am.sh: Generate mpers_xlat.h.
* Makefile.am (EXTRA_DIST): Add mpers_xlat.h.
* print_sigevent.c: Include "xlat/sigev_value.h" unconditionally.
* print_timex.c: Include "xlat/adjtimex_modes.h" and
"xlat/adjtimex_status.h" unconditionally.
* xlat/gen.sh (cond_xlat): Move printing of fallback definitions ...
(cond_def): ... here.
(gen_header): Check also mpers_xlat.h for global declarations
of xlat structures.
Process input file twice, first time print directives
only, second time print everything.
Wrap struct xlat into #ifdef IN_MPERS ... #else ... #endif.
* xlat/getrandom_flags.in: Cleanup.
diff --git a/generate_mpers_am.sh b/generate_mpers_am.sh
index 5469c94..1ee4791 100755
--- a/generate_mpers_am.sh
+++ b/generate_mpers_am.sh
@@ -1,11 +1,13 @@
#!/bin/sh -e
-exec > mpers.am
-
-echo "# Generated by $0; do not edit."
-printf 'mpers_source_files = '
-
-sed -n '/^strace_SOURCES[[:space:]]*=/,/^[[:space:]]*# end of strace_SOURCES/ s/^[[:space:]]*\([[:alnum:]][^.]*\.c\)[[:space:]]*\\$/\1/p' Makefile.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
+ tr '\n' ' ')"
+
+cat > mpers.am <<EOF
+# Generated by $0; do not edit.
+mpers_source_files = $list
+EOF
+
+sed -n 's/^#[[:space:]]*include[[:space:]]*"xlat\/\([^."]\+\)\.h".*/extern const struct xlat \1[];/p' \
+ $list > mpers_xlat.h