xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame^] | 1 | #!/usr/bin/perl |
| 2 | |
| 3 | # Shared code for glibc conformance tests. |
| 4 | |
| 5 | # Copyright (C) 2014-2016 Free Software Foundation, Inc. |
| 6 | # This file is part of the GNU C Library. |
| 7 | |
| 8 | # The GNU C Library is free software; you can redistribute it and/or |
| 9 | # modify it under the terms of the GNU Lesser General Public |
| 10 | # License as published by the Free Software Foundation; either |
| 11 | # version 2.1 of the License, or (at your option) any later version. |
| 12 | |
| 13 | # The GNU C Library is distributed in the hope that it will be useful, |
| 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | # Lesser General Public License for more details. |
| 17 | |
| 18 | # You should have received a copy of the GNU Lesser General Public |
| 19 | # License along with the GNU C Library; if not, see |
| 20 | # <http://www.gnu.org/licenses/>. |
| 21 | |
| 22 | package GlibcConform; |
| 23 | require Exporter; |
| 24 | @ISA = qw(Exporter); |
| 25 | @EXPORT = qw(%CFLAGS list_exported_functions); |
| 26 | |
| 27 | # Compiler options for each standard. |
| 28 | $CFLAGS{"ISO"} = "-ansi"; |
| 29 | $CFLAGS{"ISO99"} = "-std=c99"; |
| 30 | $CFLAGS{"ISO11"} = "-std=c11"; |
| 31 | $CFLAGS{"POSIX"} = "-D_POSIX_C_SOURCE=199506L -ansi"; |
| 32 | $CFLAGS{"XPG3"} = "-ansi -D_XOPEN_SOURCE"; |
| 33 | $CFLAGS{"XPG4"} = "-ansi -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED"; |
| 34 | $CFLAGS{"UNIX98"} = "-ansi -D_XOPEN_SOURCE=500"; |
| 35 | $CFLAGS{"XOPEN2K"} = "-std=c99 -D_XOPEN_SOURCE=600"; |
| 36 | $CFLAGS{"XOPEN2K8"} = "-std=c99 -D_XOPEN_SOURCE=700"; |
| 37 | $CFLAGS{"POSIX2008"} = "-std=c99 -D_POSIX_C_SOURCE=200809L"; |
| 38 | |
| 39 | # Return a list of functions exported by a header, empty if an include |
| 40 | # of the header does not compile. |
| 41 | sub list_exported_functions { |
| 42 | my ($cc, $standard, $header, $tmpdir) = @_; |
| 43 | my ($cc_all) = "$cc -D_ISOMAC $CFLAGS{$standard}"; |
| 44 | my ($tmpfile) = "$tmpdir/list-$$.c"; |
| 45 | my ($auxfile) = "$tmpdir/list-$$.c.aux"; |
| 46 | my ($ret); |
| 47 | my (%res) = (); |
| 48 | open (TMPFILE, ">$tmpfile") || die ("open $tmpfile: $!\n"); |
| 49 | print TMPFILE "#include <$header>\n"; |
| 50 | close (TMPFILE) || die ("close $tmpfile: $!\n"); |
| 51 | $ret = system "$cc_all -c $tmpfile -o /dev/null -aux-info $auxfile > /dev/null"; |
| 52 | unlink ($tmpfile) || die ("unlink $tmpfile: $!\n"); |
| 53 | if ($ret != 0) { |
| 54 | return; |
| 55 | } |
| 56 | open (AUXFILE, "<$auxfile") || die ("open $auxfile: $!\n"); |
| 57 | while (<AUXFILE>) { |
| 58 | s|/\*.*?\*/||g; |
| 59 | if (/^\s*$/) { |
| 60 | next; |
| 61 | } |
| 62 | # The word before a '(' that isn't '(*' is the function name |
| 63 | # before the argument list (not fully general, but sufficient for |
| 64 | # -aux-info output on standard headers). |
| 65 | if (/(\w+)\s*\([^*]/) { |
| 66 | $res{$1} = 1; |
| 67 | } else { |
| 68 | die ("couldn't parse -aux-info output: $_\n"); |
| 69 | } |
| 70 | } |
| 71 | close (AUXFILE) || die ("close $auxfile: $!\n"); |
| 72 | unlink ($auxfile) || die ("unlink $auxfile: $!\n"); |
| 73 | return sort keys %res; |
| 74 | } |