]>
Commit | Line | Data |
---|---|---|
47755784 | 1 | #! /bin/sh |
d614a753 | 2 | # Copyright (C) 2016-2020 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. | |
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 | ||
47755784 ZW |
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) | |
47755784 ZW |
40 | ;; |
41 | (c++) | |
42 | lang_modes="$cxx_modes" | |
43 | cih_test_c=$(mktemp ${TMPDIR-/tmp}/cih_test_XXXXXX.cc) | |
47755784 ZW |
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 | for header in "$@"; do | |
57 | # Skip various headers for which this test gets a false failure. | |
58 | case "$header" in | |
59 | # bits/* are not meant to be included directly and usually #error | |
60 | # out if you try it. | |
61 | # regexp.h is a stub containing only an #error. | |
62 | # Sun RPC's .x files are traditionally installed in | |
63 | # $prefix/include/rpcsvc, but they are not C header files. | |
64 | (bits/* | regexp.h | rpcsvc/*.x) | |
65 | continue;; | |
66 | ||
8d3bd947 ZW |
67 | # All extant versions of sys/elf.h contain nothing more than an |
68 | # exhortation (either a #warning or an #error) to use sys/procfs.h | |
69 | # instead, plus an inclusion of that header. | |
70 | (sys/elf.h) | |
71 | continue;; | |
72 | ||
ae514971 | 73 | # Skip Fortran headers. |
74 | (finclude/*) | |
75 | continue;; | |
76 | ||
744e8296 FW |
77 | # sys/sysctl.h produces a deprecation warning and therefore |
78 | # fails compilation with -Werror. | |
06b9e94f | 79 | (sys/sysctl.h) |
744e8296 | 80 | continue;; |
06b9e94f | 81 | |
8d3bd947 ZW |
82 | # sys/vm86.h is "unsupported on x86-64" and errors out on that target. |
83 | (sys/vm86.h) | |
47755784 ZW |
84 | case "$is_x86_64" in |
85 | (yes) continue;; | |
86 | (no) ;; | |
87 | (unknown) | |
88 | cat >"$cih_test_c" <<EOF | |
89 | #if defined __x86_64__ && __x86_64__ | |
90 | #error "is x86-64" | |
91 | #endif | |
92 | EOF | |
93 | if $cc_cmd -fsyntax-only "$cih_test_c" > /dev/null 2>&1 | |
94 | then | |
95 | is_x86_64=no | |
96 | else | |
97 | is_x86_64=yes | |
98 | continue | |
99 | fi | |
100 | ;; | |
101 | esac | |
a726c87a | 102 | ;; |
47755784 ZW |
103 | esac |
104 | ||
105 | echo :: "$header" | |
106 | for lang_mode in "" $lang_modes; do | |
107 | for lib_mode in "" $lib_modes; do | |
108 | echo :::: $lang_mode $lib_mode | |
109 | if [ -z "$lib_mode" ]; then | |
110 | expanded_lib_mode='/* default library mode */' | |
111 | else | |
112 | expanded_lib_mode=$(echo : $lib_mode | \ | |
113 | sed 's/^: -D/#define /; s/=/ /') | |
114 | fi | |
115 | cat >"$cih_test_c" <<EOF | |
116 | /* These macros may have been defined on the command line. They are | |
117 | inappropriate for this test. */ | |
118 | #undef _LIBC | |
119 | #undef _GNU_SOURCE | |
47755784 ZW |
120 | /* The library mode is selected here rather than on the command line to |
121 | ensure that this selection wins. */ | |
122 | $expanded_lib_mode | |
123 | #include <$header> | |
124 | int avoid_empty_translation_unit; | |
125 | EOF | |
126 | if $cc_cmd -fsyntax-only $lang_mode "$cih_test_c" 2>&1 | |
711a322a ZW |
127 | then : |
128 | else failed=1 | |
47755784 ZW |
129 | fi |
130 | done | |
131 | done | |
132 | done | |
133 | exit $failed |