]>
Commit | Line | Data |
---|---|---|
47755784 | 1 | #! /bin/sh |
bfff8b1b | 2 | # Copyright (C) 2016-2017 Free Software Foundation, Inc. |
47755784 ZW |
3 | # This file is part of the GNU C Library. |
4 | # | |
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. | |
9 | # | |
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. | |
14 | # | |
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/>. | |
18 | ||
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 | |
23 | # appear. | |
24 | ||
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" | |
29 | ||
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" | |
33 | ||
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 | |
36 | # to remove. | |
37 | skip_obsolete_type_check='*/sys/types.h|*/bits/types.h|*/rpc/*|*/rpcsvc/*' | |
38 | obsolete_type_re=\ | |
39 | '\<((__)?(quad_t|u(short|int|long|_(char|short|int([0-9]+_t)?|long|quad_t))))\>' | |
40 | ||
41 | if [ $# -lt 3 ]; then | |
42 | echo "usage: $0 c|c++ \"compile command\" header header header..." >&2 | |
43 | exit 2 | |
44 | fi | |
45 | case "$1" in | |
46 | (c) | |
47 | lang_modes="$c_modes" | |
48 | cih_test_c=$(mktemp ${TMPDIR-/tmp}/cih_test_XXXXXX.c) | |
49 | already="$skip_obsolete_type_check" | |
50 | ;; | |
51 | (c++) | |
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. | |
56 | already="*" | |
57 | ;; | |
58 | (*) | |
59 | echo "usage: $0 c|c++ \"compile command\" header header header..." >&2 | |
60 | exit 2;; | |
61 | esac | |
62 | shift | |
63 | cc_cmd="$1" | |
64 | shift | |
65 | trap "rm -f '$cih_test_c'" 0 | |
66 | ||
67 | failed=0 | |
68 | is_x86_64=unknown | |
06b9e94f | 69 | is_x32=unknown |
47755784 ZW |
70 | for header in "$@"; do |
71 | # Skip various headers for which this test gets a false failure. | |
72 | case "$header" in | |
73 | # bits/* are not meant to be included directly and usually #error | |
74 | # out if you try it. | |
75 | # regexp.h is a stub containing only an #error. | |
76 | # Sun RPC's .x files are traditionally installed in | |
77 | # $prefix/include/rpcsvc, but they are not C header files. | |
78 | (bits/* | regexp.h | rpcsvc/*.x) | |
79 | continue;; | |
80 | ||
8d3bd947 ZW |
81 | # All extant versions of sys/elf.h contain nothing more than an |
82 | # exhortation (either a #warning or an #error) to use sys/procfs.h | |
83 | # instead, plus an inclusion of that header. | |
84 | (sys/elf.h) | |
85 | continue;; | |
86 | ||
06b9e94f JM |
87 | # sys/sysctl.h is unsupported for x32. |
88 | (sys/sysctl.h) | |
89 | case "$is_x32" in | |
90 | (yes) continue;; | |
91 | (no) ;; | |
92 | (unknown) | |
93 | cat >"$cih_test_c" <<EOF | |
94 | #if defined __x86_64__ && defined __ILP32__ | |
95 | # error "is x32" | |
96 | #endif | |
97 | EOF | |
98 | if $cc_cmd -fsyntax-only "$cih_test_c" > /dev/null 2>&1 | |
99 | then | |
100 | is_x32=no | |
101 | else | |
102 | is_x32=yes | |
103 | continue | |
104 | fi | |
105 | ;; | |
106 | esac | |
107 | ;; | |
108 | ||
8d3bd947 ZW |
109 | # sys/vm86.h is "unsupported on x86-64" and errors out on that target. |
110 | (sys/vm86.h) | |
47755784 ZW |
111 | case "$is_x86_64" in |
112 | (yes) continue;; | |
113 | (no) ;; | |
114 | (unknown) | |
115 | cat >"$cih_test_c" <<EOF | |
116 | #if defined __x86_64__ && __x86_64__ | |
117 | #error "is x86-64" | |
118 | #endif | |
119 | EOF | |
120 | if $cc_cmd -fsyntax-only "$cih_test_c" > /dev/null 2>&1 | |
121 | then | |
122 | is_x86_64=no | |
123 | else | |
124 | is_x86_64=yes | |
125 | continue | |
126 | fi | |
127 | ;; | |
128 | esac | |
129 | esac | |
130 | ||
131 | echo :: "$header" | |
132 | for lang_mode in "" $lang_modes; do | |
133 | for lib_mode in "" $lib_modes; do | |
134 | echo :::: $lang_mode $lib_mode | |
135 | if [ -z "$lib_mode" ]; then | |
136 | expanded_lib_mode='/* default library mode */' | |
137 | else | |
138 | expanded_lib_mode=$(echo : $lib_mode | \ | |
139 | sed 's/^: -D/#define /; s/=/ /') | |
140 | fi | |
141 | cat >"$cih_test_c" <<EOF | |
142 | /* These macros may have been defined on the command line. They are | |
143 | inappropriate for this test. */ | |
144 | #undef _LIBC | |
145 | #undef _GNU_SOURCE | |
47755784 ZW |
146 | /* The library mode is selected here rather than on the command line to |
147 | ensure that this selection wins. */ | |
148 | $expanded_lib_mode | |
149 | #include <$header> | |
150 | int avoid_empty_translation_unit; | |
151 | EOF | |
152 | if $cc_cmd -fsyntax-only $lang_mode "$cih_test_c" 2>&1 | |
153 | then | |
154 | includes=$($cc_cmd -fsyntax-only -H $lang_mode \ | |
155 | "$cih_test_c" 2>&1 | sed -ne 's/^[.][.]* //p') | |
156 | for h in $includes; do | |
157 | # Don't repeat work. | |
158 | eval 'case "$h" in ('"$already"') continue;; esac' | |
159 | ||
160 | if grep -qE "$obsolete_type_re" "$h"; then | |
161 | echo "*** Obsolete types detected:" | |
162 | grep -HE "$obsolete_type_re" "$h" | |
163 | failed=1 | |
164 | fi | |
165 | already="$already|$h" | |
166 | done | |
167 | else | |
168 | failed=1 | |
169 | fi | |
170 | done | |
171 | done | |
172 | done | |
173 | exit $failed |