2 # Copyright (C) 2016-2024 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
5 # The GNU C Library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # The GNU C Library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with the GNU C Library; if not, see
17 # <https://www.gnu.org/licenses/>.
19 # For each installed header, confirm that it's possible to compile a
20 # file that includes that header and does nothing else, in several
21 # different compilation modes.
23 # These compilation switches assume GCC or compatible, which is probably
24 # fine since we also assume that when _building_ glibc.
25 c_modes
="-std=c89 -std=gnu89 -std=c11 -std=gnu11"
26 cxx_modes
="-std=c++98 -std=gnu++98 -std=c++11 -std=gnu++11"
28 # An exhaustive test of feature selection macros would take far too long.
29 # These are probably the most commonly used three.
30 lib_modes
="-D_DEFAULT_SOURCE=1 -D_GNU_SOURCE=1 -D_XOPEN_SOURCE=700"
32 # Also check for fortify modes, since it might be enabled as default. The
33 # maximum value to be checked is define by maximum_fortify argument.
37 echo "usage: $0 c|c++ maximum_fortify \"compile command\" header header header..." >&2
43 cih_test_c
=$
(mktemp
${TMPDIR-/tmp}/cih_test_XXXXXX.c
)
46 lang_modes
="$cxx_modes"
47 cih_test_c
=$
(mktemp
${TMPDIR-/tmp}/cih_test_XXXXXX.cc
)
50 echo "usage: $0 c|c++ \"compile command\" header header header..." >&2
54 fortify_modes
=$
(seq -s' ' 1 $1)
58 trap "rm -f '$cih_test_c'" 0
62 for header
in "$@"; do
63 # Skip various headers for which this test gets a false failure.
65 # bits/* are not meant to be included directly and usually #error
67 # regexp.h is a stub containing only an #error.
68 # Sun RPC's .x files are traditionally installed in
69 # $prefix/include/rpcsvc, but they are not C header files.
70 (bits
/* | regexp.h | rpcsvc
/*.x
)
73 # All extant versions of sys/elf.h contain nothing more than an
74 # exhortation (either a #warning or an #error) to use sys/procfs.h
75 # instead, plus an inclusion of that header.
79 # Skip Fortran headers.
83 # sys/vm86.h is "unsupported on x86-64" and errors out on that target.
89 cat >"$cih_test_c" <<EOF
90 #if defined __x86_64__ && __x86_64__
94 if $cc_cmd -fsyntax-only "$cih_test_c" > /dev
/null
2>&1
107 for lang_mode
in "" $lang_modes; do
108 for lib_mode
in "" $lib_modes; do
109 for fortify_mode
in "" $fortify_modes; do
110 if [ -z "$lib_mode" ]; then
111 expanded_lib_mode
='/* default library mode */'
113 expanded_lib_mode
=$
(echo : $lib_mode | \
114 sed 's/^: -D/#define /; s/=/ /')
116 if [ ! -z $fortify_mode ]; then
117 fortify_mode
="#define _FORTIFY_SOURCE $fortify_mode"
119 echo :::: $lang_mode $lib_mode $fortify_mode
120 cat >"$cih_test_c" <<EOF
121 /* These macros may have been defined on the command line. They are
122 inappropriate for this test. */
125 #undef _FORTIFY_SOURCE
127 /* The library mode is selected here rather than on the command line to
128 ensure that this selection wins. */
131 int avoid_empty_translation_unit;
133 if $cc_cmd -finput-charset=ascii
-fsyntax-only $lang_mode \