stdlib: qsort: Move some macros to inline function
[glibc.git] / scripts / check-installed-headers.sh
blobee9f534ab0fa9d8d10ab4647fcbabf71333e3610
1 #! /bin/sh
2 # Copyright (C) 2016-2023 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.
34 fortify_modes=""
36 if [ $# -lt 3 ]; then
37 echo "usage: $0 c|c++ maximum_fortify \"compile command\" header header header..." >&2
38 exit 2
40 case "$1" in
41 (c)
42 lang_modes="$c_modes"
43 cih_test_c=$(mktemp ${TMPDIR-/tmp}/cih_test_XXXXXX.c)
45 (c++)
46 lang_modes="$cxx_modes"
47 cih_test_c=$(mktemp ${TMPDIR-/tmp}/cih_test_XXXXXX.cc)
49 (*)
50 echo "usage: $0 c|c++ \"compile command\" header header header..." >&2
51 exit 2;;
52 esac
53 shift
54 fortify_modes=$(seq -s' ' 1 $1)
55 shift
56 cc_cmd="$1"
57 shift
58 trap "rm -f '$cih_test_c'" 0
60 failed=0
61 is_x86_64=unknown
62 for header in "$@"; do
63 # Skip various headers for which this test gets a false failure.
64 case "$header" in
65 # bits/* are not meant to be included directly and usually #error
66 # out if you try it.
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)
71 continue;;
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.
76 (sys/elf.h)
77 continue;;
79 # Skip Fortran headers.
80 (finclude/*)
81 continue;;
83 # sys/vm86.h is "unsupported on x86-64" and errors out on that target.
84 (sys/vm86.h)
85 case "$is_x86_64" in
86 (yes) continue;;
87 (no) ;;
88 (unknown)
89 cat >"$cih_test_c" <<EOF
90 #if defined __x86_64__ && __x86_64__
91 #error "is x86-64"
92 #endif
93 EOF
94 if $cc_cmd -fsyntax-only "$cih_test_c" > /dev/null 2>&1
95 then
96 is_x86_64=no
97 else
98 is_x86_64=yes
99 continue
102 esac
104 esac
106 echo :: "$header"
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 */'
112 else
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. */
123 #undef _LIBC
124 #undef _GNU_SOURCE
125 #undef _FORTIFY_SOURCE
126 $fortify_mode
127 /* The library mode is selected here rather than on the command line to
128 ensure that this selection wins. */
129 $expanded_lib_mode
130 #include <$header>
131 int avoid_empty_translation_unit;
133 if $cc_cmd -finput-charset=ascii -fsyntax-only $lang_mode \
134 "$cih_test_c" 2>&1
135 then :
136 else failed=1
138 done
139 done
140 done
141 done
142 exit $failed