]> git.ipfire.org Git - thirdparty/glibc.git/blob - scripts/check-installed-headers.sh
e4f37d33f89a95c6e6c45afb15e27c446c3c0c1b
[thirdparty/glibc.git] / scripts / check-installed-headers.sh
1 #! /bin/sh
2 # Copyright (C) 2016-2019 Free Software Foundation, Inc.
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 # 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.
22
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"
27
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"
31
32 if [ $# -lt 3 ]; then
33 echo "usage: $0 c|c++ \"compile command\" header header header..." >&2
34 exit 2
35 fi
36 case "$1" in
37 (c)
38 lang_modes="$c_modes"
39 cih_test_c=$(mktemp ${TMPDIR-/tmp}/cih_test_XXXXXX.c)
40 ;;
41 (c++)
42 lang_modes="$cxx_modes"
43 cih_test_c=$(mktemp ${TMPDIR-/tmp}/cih_test_XXXXXX.cc)
44 ;;
45 (*)
46 echo "usage: $0 c|c++ \"compile command\" header header header..." >&2
47 exit 2;;
48 esac
49 shift
50 cc_cmd="$1"
51 shift
52 trap "rm -f '$cih_test_c'" 0
53
54 failed=0
55 is_x86_64=unknown
56 is_x32=unknown
57 for header in "$@"; do
58 # Skip various headers for which this test gets a false failure.
59 case "$header" in
60 # bits/* are not meant to be included directly and usually #error
61 # out if you try it.
62 # regexp.h is a stub containing only an #error.
63 # Sun RPC's .x files are traditionally installed in
64 # $prefix/include/rpcsvc, but they are not C header files.
65 (bits/* | regexp.h | rpcsvc/*.x)
66 continue;;
67
68 # All extant versions of sys/elf.h contain nothing more than an
69 # exhortation (either a #warning or an #error) to use sys/procfs.h
70 # instead, plus an inclusion of that header.
71 (sys/elf.h)
72 continue;;
73
74 # Skip Fortran headers.
75 (finclude/*)
76 continue;;
77
78 # sys/sysctl.h is unsupported for x32.
79 (sys/sysctl.h)
80 case "$is_x32" in
81 (yes) continue;;
82 (no) ;;
83 (unknown)
84 cat >"$cih_test_c" <<EOF
85 #if defined __x86_64__ && defined __ILP32__
86 # error "is x32"
87 #endif
88 EOF
89 if $cc_cmd -fsyntax-only "$cih_test_c" > /dev/null 2>&1
90 then
91 is_x32=no
92 else
93 is_x32=yes
94 continue
95 fi
96 ;;
97 esac
98 ;;
99
100 # sys/vm86.h is "unsupported on x86-64" and errors out on that target.
101 (sys/vm86.h)
102 case "$is_x86_64" in
103 (yes) continue;;
104 (no) ;;
105 (unknown)
106 cat >"$cih_test_c" <<EOF
107 #if defined __x86_64__ && __x86_64__
108 #error "is x86-64"
109 #endif
110 EOF
111 if $cc_cmd -fsyntax-only "$cih_test_c" > /dev/null 2>&1
112 then
113 is_x86_64=no
114 else
115 is_x86_64=yes
116 continue
117 fi
118 ;;
119 esac
120 ;;
121 esac
122
123 echo :: "$header"
124 for lang_mode in "" $lang_modes; do
125 for lib_mode in "" $lib_modes; do
126 echo :::: $lang_mode $lib_mode
127 if [ -z "$lib_mode" ]; then
128 expanded_lib_mode='/* default library mode */'
129 else
130 expanded_lib_mode=$(echo : $lib_mode | \
131 sed 's/^: -D/#define /; s/=/ /')
132 fi
133 cat >"$cih_test_c" <<EOF
134 /* These macros may have been defined on the command line. They are
135 inappropriate for this test. */
136 #undef _LIBC
137 #undef _GNU_SOURCE
138 /* The library mode is selected here rather than on the command line to
139 ensure that this selection wins. */
140 $expanded_lib_mode
141 #include <$header>
142 int avoid_empty_translation_unit;
143 EOF
144 if $cc_cmd -fsyntax-only $lang_mode "$cih_test_c" 2>&1
145 then :
146 else failed=1
147 fi
148 done
149 done
150 done
151 exit $failed