2014-02-16 10:59:20 +04:00
#!/bin/sh
2015-12-17 20:56:48 +03:00
#
# Copyright (c) 2014-2015 Mike Frysinger <vapier@gentoo.org>
# Copyright (c) 2014-2015 Dmitry V. Levin <ldv@altlinux.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2014-02-16 10:59:20 +04:00
2015-02-18 06:47:17 +03:00
usage( )
{
2014-02-16 10:59:20 +04:00
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
}
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.
2015-11-20 04:43:12 +03:00
cond_def( )
{
local line
line = " $1 " ; shift
local val
val = " $( printf %s " $line " |
Consistently use extended regular expressions where appropriate
When grep or sed is used with basic regular expressions containing
'(', ')', '{', '}', '|', '?', and '+' special characters, convert them
to extended regular expressions for better portability and readability.
* generate_mpers_am.sh: Convert grep and sed BREs to EREs.
* Makefile.am (ioctl_redefs%.h, m%_type_defs.h, m%_funcs.h,
mpers_printer_decl_pattern, printers.h, %_printer_decls.h,
%_printer_defs.h): Convert sed BREs to EREs.
* generate_sen.sh: Likewise.
* linux/mips/genstub.sh: Likewise.
* make-dsc: Likewise.
* mpers.sh: Likewise.
* xlat/gen.sh: Likewise.
* tests/Makefile.am (ksysent.h): Likewise.
* tests/ksysent.sed: Likewise.
* tests/pc.test: Likewise.
* tests/strace-S.test: Likewise.
* tests/strace-V.test: Likewise.
* tests/strace-k.test: Likewise.
2016-07-28 19:51:58 +03:00
sed -r -n 's/^([^[:space:]]+).*$/\1/p' ) "
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.
2015-11-20 04:43:12 +03:00
local def
def = " $( printf %s " ${ line } " |
Consistently use extended regular expressions where appropriate
When grep or sed is used with basic regular expressions containing
'(', ')', '{', '}', '|', '?', and '+' special characters, convert them
to extended regular expressions for better portability and readability.
* generate_mpers_am.sh: Convert grep and sed BREs to EREs.
* Makefile.am (ioctl_redefs%.h, m%_type_defs.h, m%_funcs.h,
mpers_printer_decl_pattern, printers.h, %_printer_decls.h,
%_printer_defs.h): Convert sed BREs to EREs.
* generate_sen.sh: Likewise.
* linux/mips/genstub.sh: Likewise.
* make-dsc: Likewise.
* mpers.sh: Likewise.
* xlat/gen.sh: Likewise.
* tests/Makefile.am (ksysent.h): Likewise.
* tests/ksysent.sed: Likewise.
* tests/pc.test: Likewise.
* tests/strace-S.test: Likewise.
* tests/strace-V.test: Likewise.
* tests/strace-k.test: Likewise.
2016-07-28 19:51:58 +03:00
sed -r -n 's/^[^[:space:]]+[[:space:]]+([^[:space:]].*)$/\1/p' ) "
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.
2015-11-20 04:43:12 +03:00
if [ -n " $def " ] ; then
cat <<-EOF
#if !(defined($val) || (defined(HAVE_DECL_$val) && HAVE_DECL_$val))
# define $val $def
#endif
EOF
fi
}
2016-04-29 04:02:13 +03:00
print_xlat( )
{
local val
val = " $1 " ; shift
2016-04-29 04:02:13 +03:00
if [ -z " ${ val_type - } " ] ; then
echo " XLAT( ${ val } ), "
else
echo " XLAT_TYPE( ${ val_type } , ${ val } ), "
fi
2016-04-29 04:02:13 +03:00
}
print_xlat_pair( )
{
local val str
val = " $1 " ; shift
str = " $1 " ; shift
2016-04-29 04:02:13 +03:00
if [ -z " ${ val_type - } " ] ; then
echo " XLAT_PAIR( ${ val } , \" ${ str } \"), "
else
echo " XLAT_TYPE_PAIR( ${ val_type } , ${ val } , \" ${ str } \"), "
fi
2016-04-29 04:02:13 +03:00
}
2015-02-18 06:47:17 +03:00
cond_xlat( )
{
2016-05-06 00:50:23 +03:00
local line val m def xlat
2015-02-18 06:47:17 +03:00
line = " $1 " ; shift
Consistently use extended regular expressions where appropriate
When grep or sed is used with basic regular expressions containing
'(', ')', '{', '}', '|', '?', and '+' special characters, convert them
to extended regular expressions for better portability and readability.
* generate_mpers_am.sh: Convert grep and sed BREs to EREs.
* Makefile.am (ioctl_redefs%.h, m%_type_defs.h, m%_funcs.h,
mpers_printer_decl_pattern, printers.h, %_printer_decls.h,
%_printer_defs.h): Convert sed BREs to EREs.
* generate_sen.sh: Likewise.
* linux/mips/genstub.sh: Likewise.
* make-dsc: Likewise.
* mpers.sh: Likewise.
* xlat/gen.sh: Likewise.
* tests/Makefile.am (ksysent.h): Likewise.
* tests/ksysent.sed: Likewise.
* tests/pc.test: Likewise.
* tests/strace-S.test: Likewise.
* tests/strace-V.test: Likewise.
* tests/strace-k.test: Likewise.
2016-07-28 19:51:58 +03:00
val = " $( printf %s " ${ line } " | sed -r -n 's/^([^[:space:]]+).*$/\1/p' ) "
2015-02-18 06:47:17 +03:00
m = " ${ val %%|* } "
def = " $( printf %s " ${ line } " |
Consistently use extended regular expressions where appropriate
When grep or sed is used with basic regular expressions containing
'(', ')', '{', '}', '|', '?', and '+' special characters, convert them
to extended regular expressions for better portability and readability.
* generate_mpers_am.sh: Convert grep and sed BREs to EREs.
* Makefile.am (ioctl_redefs%.h, m%_type_defs.h, m%_funcs.h,
mpers_printer_decl_pattern, printers.h, %_printer_decls.h,
%_printer_defs.h): Convert sed BREs to EREs.
* generate_sen.sh: Likewise.
* linux/mips/genstub.sh: Likewise.
* make-dsc: Likewise.
* mpers.sh: Likewise.
* xlat/gen.sh: Likewise.
* tests/Makefile.am (ksysent.h): Likewise.
* tests/ksysent.sed: Likewise.
* tests/pc.test: Likewise.
* tests/strace-S.test: Likewise.
* tests/strace-V.test: Likewise.
* tests/strace-k.test: Likewise.
2016-07-28 19:51:58 +03:00
sed -r -n 's/^[^[:space:]]+[[:space:]]+([^[:space:]].*)$/\1/p' ) "
2015-02-18 06:47:17 +03:00
2016-05-06 00:50:23 +03:00
if [ " ${ m } " = " ${ m #1<< } " ] ; then
2016-04-29 04:02:13 +03:00
xlat = " $( print_xlat " ${ val } " ) "
2015-02-18 06:47:17 +03:00
else
2016-05-06 00:50:23 +03:00
xlat = " $( print_xlat_pair " 1ULL<< ${ val #1<< } " " ${ val } " ) "
2015-02-18 06:47:17 +03:00
m = " ${ m #1<< } "
fi
if [ -z " ${ def } " ] ; then
cat <<-EOF
#if defined(${m}) || (defined(HAVE_DECL_${m}) && HAVE_DECL_${m})
${ xlat }
#endif
EOF
else
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.
2015-11-20 04:43:12 +03:00
echo " $xlat "
2015-02-18 06:47:17 +03:00
fi
}
gen_header( )
{
2014-02-16 10:59:20 +04:00
local input = " $1 " output = " $2 " name = " $3 "
echo " generating ${ output } "
(
2014-04-26 03:04:13 +04:00
local defs = " ${ 0 %/* } /../defs.h "
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.
2015-11-20 04:43:12 +03:00
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
2014-04-26 03:04:13 +04:00
fi
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.
2015-11-20 04:43:12 +03:00
echo " /* Generated by $0 from $1 ; do not edit. */ "
2014-04-26 03:04:13 +04:00
local unconditional = unterminated = line
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.
2015-11-20 04:43:12 +03:00
# 1st pass: output directives.
2014-04-26 03:04:13 +04:00
while read line; do
LC_COLLATE = C
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.
2015-11-20 04:43:12 +03:00
case $line in
2016-06-06 18:08:45 +03:00
'#conditional' )
unconditional =
; ;
2014-04-26 03:04:13 +04:00
'#unconditional' )
unconditional = 1
; ;
'#unterminated' )
unterminated = 1
2014-02-16 10:59:20 +04:00
; ;
2016-04-29 04:02:13 +03:00
'#val_type ' *)
# to be processed during 2nd pass
; ;
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.
2015-11-20 04:43:12 +03:00
'#' *)
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 } [] = { "
2016-04-29 04:02:13 +03:00
unconditional = val_type =
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.
2015-11-20 04:43:12 +03:00
# 2nd pass: output everything.
while read line; do
LC_COLLATE = C
case ${ line } in
2016-06-06 18:08:45 +03:00
'#conditional' )
unconditional =
; ;
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.
2015-11-20 04:43:12 +03:00
'#unconditional' )
unconditional = 1
; ;
'#unterminated' )
# processed during 1st pass
; ;
2016-04-29 04:02:13 +03:00
'#val_type ' *)
val_type = " ${ line # \# val_type } "
; ;
2014-04-26 03:04:13 +04:00
[ A-Z_] *) # symbolic constants
2015-02-18 06:47:17 +03:00
if [ -n " ${ unconditional } " ] ; then
2016-04-29 04:02:13 +03:00
print_xlat " ${ line } "
2015-02-18 06:47:17 +03:00
else
2016-05-06 00:50:23 +03:00
cond_xlat " ${ line } "
2015-02-18 06:47:17 +03:00
fi
2014-04-26 03:04:13 +04:00
; ;
'1<<' [ A-Z_] *) # symbolic constants with shift
2015-02-18 06:47:17 +03:00
if [ -n " ${ unconditional } " ] ; then
2016-05-06 00:50:23 +03:00
print_xlat_pair " 1ULL<< ${ line #1<< } " " ${ line } "
2015-02-18 06:47:17 +03:00
else
2016-05-06 00:50:23 +03:00
cond_xlat " ${ line } "
2015-02-18 06:47:17 +03:00
fi
2014-04-26 03:04:13 +04:00
; ;
[ 0-9] *) # numeric constants
2016-04-29 04:02:13 +03:00
print_xlat " ${ line } "
2014-04-26 03:04:13 +04:00
; ;
*) # verbatim lines
echo " ${ line } "
2014-02-16 10:59:20 +04:00
; ;
esac
done < " ${ input } "
2014-04-26 03:04:13 +04:00
if [ -n " ${ unterminated } " ] ; then
2015-02-18 06:47:17 +03:00
echo " /* this array should remain not NULL-terminated */"
2014-04-26 03:04:13 +04:00
else
2015-02-18 06:47:17 +03:00
echo " XLAT_END"
2014-04-26 03:04:13 +04:00
fi
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.
2015-11-20 04:43:12 +03:00
cat <<-EOF
} ;
#endif /* !IN_MPERS */
EOF
2014-02-16 10:59:20 +04:00
) >" ${ output } "
}
2015-02-18 06:47:17 +03:00
gen_make( )
{
2014-02-16 10:59:20 +04:00
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 } "
}
2015-02-18 06:47:17 +03:00
gen_git( )
{
2014-02-16 10:59:20 +04:00
local output = " $1 "
shift
echo " generating ${ output } "
(
printf '/%s\n' .gitignore Makemodule.am
printf '/%s.h\n' " $@ "
) >" ${ output } "
}
2015-02-18 06:47:17 +03:00
main( )
{
2014-02-16 10:59:20 +04:00
case $# in
0) set -- " ${ 0 %/* } " " ${ 0 %/* } " ; ;
2) ; ;
*) usage ; ;
esac
local input = " $1 "
local output = " $2 "
local name
2015-02-27 02:06:16 +03:00
local jobs = 0
local ncpus = " $( getconf _NPROCESSORS_ONLN) "
[ " ${ ncpus } " -ge 1 ] ||
ncpus = 1
2014-02-16 10:59:20 +04:00
if [ -d " ${ input } " ] ; then
2014-04-26 03:04:13 +04:00
local f names =
2014-02-16 10:59:20 +04:00
for f in " ${ input } " /*.in; do
2014-04-26 03:04:13 +04:00
[ -f " ${ f } " ] || continue
2014-02-16 10:59:20 +04:00
name = ${ f ##*/ }
name = ${ name %.in }
gen_header " ${ f } " " ${ output } / ${ name } .h " " ${ name } " &
names = " ${ names } ${ name } "
2015-02-27 02:06:16 +03:00
: $(( jobs + = 1 ))
if [ ${ jobs } -ge ${ ncpus } ] ; then
jobs = 0
wait
fi
2014-02-16 10:59:20 +04:00
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 " $@ "