]> git.ipfire.org Git - thirdparty/glibc.git/blame - scripts/check-installed-headers.sh
Use --enable-obsolete in build-many-glibcs.py for nios2-linux-gnu
[thirdparty/glibc.git] / scripts / check-installed-headers.sh
CommitLineData
47755784 1#! /bin/sh
dff8da6b 2# Copyright (C) 2016-2024 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
5a82c748 17# <https://www.gnu.org/licenses/>.
47755784 18
711a322a
ZW
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.
47755784
ZW
22
23# These compilation switches assume GCC or compatible, which is probably
24# fine since we also assume that when _building_ glibc.
25c_modes="-std=c89 -std=gnu89 -std=c11 -std=gnu11"
26cxx_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.
30lib_modes="-D_DEFAULT_SOURCE=1 -D_GNU_SOURCE=1 -D_XOPEN_SOURCE=700"
31
a3090c2c
AZ
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.
34fortify_modes=""
30379efa 35
47755784 36if [ $# -lt 3 ]; then
a3090c2c 37 echo "usage: $0 c|c++ maximum_fortify \"compile command\" header header header..." >&2
47755784
ZW
38 exit 2
39fi
40case "$1" in
41 (c)
42 lang_modes="$c_modes"
43 cih_test_c=$(mktemp ${TMPDIR-/tmp}/cih_test_XXXXXX.c)
47755784
ZW
44 ;;
45 (c++)
46 lang_modes="$cxx_modes"
47 cih_test_c=$(mktemp ${TMPDIR-/tmp}/cih_test_XXXXXX.cc)
47755784
ZW
48 ;;
49 (*)
50 echo "usage: $0 c|c++ \"compile command\" header header header..." >&2
51 exit 2;;
52esac
53shift
a3090c2c
AZ
54fortify_modes=$(seq -s' ' 1 $1)
55shift
47755784
ZW
56cc_cmd="$1"
57shift
58trap "rm -f '$cih_test_c'" 0
59
60failed=0
61is_x86_64=unknown
62for 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;;
72
8d3bd947
ZW
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;;
78
ae514971 79 # Skip Fortran headers.
80 (finclude/*)
81 continue;;
82
8d3bd947
ZW
83 # sys/vm86.h is "unsupported on x86-64" and errors out on that target.
84 (sys/vm86.h)
47755784
ZW
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
93EOF
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
100 fi
101 ;;
102 esac
a726c87a 103 ;;
47755784
ZW
104 esac
105
106 echo :: "$header"
107 for lang_mode in "" $lang_modes; do
108 for lib_mode in "" $lib_modes; do
30379efa 109 for fortify_mode in "" $fortify_modes; do
30379efa
AZ
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/=/ /')
115 fi
116 if [ ! -z $fortify_mode ]; then
117 fortify_mode="#define _FORTIFY_SOURCE $fortify_mode"
118 fi
a3090c2c 119 echo :::: $lang_mode $lib_mode $fortify_mode
30379efa 120 cat >"$cih_test_c" <<EOF
47755784
ZW
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
30379efa
AZ
125#undef _FORTIFY_SOURCE
126$fortify_mode
47755784
ZW
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>
131int avoid_empty_translation_unit;
132EOF
30379efa
AZ
133 if $cc_cmd -finput-charset=ascii -fsyntax-only $lang_mode \
134 "$cih_test_c" 2>&1
135 then :
136 else failed=1
137 fi
138 done
47755784
ZW
139 done
140 done
141done
142exit $failed