2 # Copyright (C) 2016 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 # <http://www.gnu.org/licenses/>.
19 # Check installed headers for cleanliness. For each header, confirm
20 # that it's possible to compile a file that includes that header and
21 # does nothing else, in several different compilation modes. Also,
22 # scan the header for a set of obsolete typedefs that should no longer
25 # These compilation switches assume GCC or compatible, which is probably
26 # fine since we also assume that when _building_ glibc.
27 c_modes
="-std=c89 -std=gnu89 -std=c11 -std=gnu11"
28 cxx_modes
="-std=c++98 -std=gnu++98 -std=c++11 -std=gnu++11"
30 # An exhaustive test of feature selection macros would take far too long.
31 # These are probably the most commonly used three.
32 lib_modes
="-D_DEFAULT_SOURCE=1 -D_GNU_SOURCE=1 -D_XOPEN_SOURCE=700"
34 # sys/types.h+bits/types.h have to define the obsolete types.
35 # rpc(svc)/* have the obsolete types too deeply embedded in their API
37 skip_obsolete_type_check
='*/sys/types.h|*/bits/types.h|*/rpc/*|*/rpcsvc/*'
39 '\<((__)?(quad_t|u(short|int|long|_(char|short|int([0-9]+_t)?|long|quad_t))))\>'
42 echo "usage: $0 c|c++ \"compile command\" header header header..." >&2
48 cih_test_c
=$
(mktemp
${TMPDIR-/tmp}/cih_test_XXXXXX.c
)
49 already
="$skip_obsolete_type_check"
52 lang_modes
="$cxx_modes"
53 cih_test_c
=$
(mktemp
${TMPDIR-/tmp}/cih_test_XXXXXX.cc
)
54 # The obsolete-type check can be skipped for C++; it is
55 # sufficient to do it for C.
59 echo "usage: $0 c|c++ \"compile command\" header header header..." >&2
65 trap "rm -f '$cih_test_c'" 0
69 for header
in "$@"; do
70 # Skip various headers for which this test gets a false failure.
72 # bits/* are not meant to be included directly and usually #error
74 # regexp.h is a stub containing only an #error.
75 # Sun RPC's .x files are traditionally installed in
76 # $prefix/include/rpcsvc, but they are not C header files.
77 (bits
/* | regexp.h | rpcsvc
/*.x
)
80 # All extant versions of sys/elf.h contain nothing more than an
81 # exhortation (either a #warning or an #error) to use sys/procfs.h
82 # instead, plus an inclusion of that header.
86 # sys/vm86.h is "unsupported on x86-64" and errors out on that target.
92 cat >"$cih_test_c" <<EOF
93 #if defined __x86_64__ && __x86_64__
97 if $cc_cmd -fsyntax-only "$cih_test_c" > /dev
/null
2>&1
109 for lang_mode
in "" $lang_modes; do
110 for lib_mode
in "" $lib_modes; do
111 echo :::: $lang_mode $lib_mode
112 if [ -z "$lib_mode" ]; then
113 expanded_lib_mode
='/* default library mode */'
115 expanded_lib_mode
=$
(echo : $lib_mode | \
116 sed 's/^: -D/#define /; s/=/ /')
118 cat >"$cih_test_c" <<EOF
119 /* These macros may have been defined on the command line. They are
120 inappropriate for this test. */
124 /* The library mode is selected here rather than on the command line to
125 ensure that this selection wins. */
128 int avoid_empty_translation_unit;
130 if $cc_cmd -fsyntax-only $lang_mode "$cih_test_c" 2>&1
132 includes
=$
($cc_cmd -fsyntax-only -H $lang_mode \
133 "$cih_test_c" 2>&1 |
sed -ne 's/^[.][.]* //p')
134 for h
in $includes; do
136 eval 'case "$h" in ('"$already"') continue;; esac'
138 if grep -qE "$obsolete_type_re" "$h"; then
139 echo "*** Obsolete types detected:"
140 grep -HE "$obsolete_type_re" "$h"
143 already
="$already|$h"