|
Packit |
6c4009 |
#!/usr/bin/perl
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# Shared code for glibc conformance tests.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# Copyright (C) 2014-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
# This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
# modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
# License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
# version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
# Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
# License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
# <http://www.gnu.org/licenses/>.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
package GlibcConform;
|
|
Packit |
6c4009 |
require Exporter;
|
|
Packit |
6c4009 |
@ISA = qw(Exporter);
|
|
Packit |
6c4009 |
@EXPORT = qw(%CFLAGS list_exported_functions);
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# Compiler options for each standard.
|
|
Packit |
6c4009 |
$CFLAGS{"ISO"} = "-ansi";
|
|
Packit |
6c4009 |
$CFLAGS{"ISO99"} = "-std=c99";
|
|
Packit |
6c4009 |
$CFLAGS{"ISO11"} = "-std=c11";
|
|
Packit |
6c4009 |
$CFLAGS{"POSIX"} = "-D_POSIX_C_SOURCE=199506L -ansi";
|
|
Packit |
6c4009 |
$CFLAGS{"XPG4"} = "-ansi -D_XOPEN_SOURCE";
|
|
Packit |
6c4009 |
$CFLAGS{"XPG42"} = "-ansi -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED";
|
|
Packit |
6c4009 |
$CFLAGS{"UNIX98"} = "-ansi -D_XOPEN_SOURCE=500";
|
|
Packit |
6c4009 |
$CFLAGS{"XOPEN2K"} = "-std=c99 -D_XOPEN_SOURCE=600";
|
|
Packit |
6c4009 |
$CFLAGS{"XOPEN2K8"} = "-std=c99 -D_XOPEN_SOURCE=700";
|
|
Packit |
6c4009 |
$CFLAGS{"POSIX2008"} = "-std=c99 -D_POSIX_C_SOURCE=200809L";
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
# Return a list of functions exported by a header, empty if an include
|
|
Packit |
6c4009 |
# of the header does not compile.
|
|
Packit |
6c4009 |
sub list_exported_functions {
|
|
Packit |
6c4009 |
my ($cc, $standard, $header, $tmpdir) = @_;
|
|
Packit |
6c4009 |
my ($cc_all) = "$cc -D_ISOMAC $CFLAGS{$standard}";
|
|
Packit |
6c4009 |
my ($tmpfile) = "$tmpdir/list-$$.c";
|
|
Packit |
6c4009 |
my ($auxfile) = "$tmpdir/list-$$.c.aux";
|
|
Packit |
6c4009 |
my ($ret);
|
|
Packit |
6c4009 |
my (%res) = ();
|
|
Packit |
6c4009 |
open (TMPFILE, ">$tmpfile") || die ("open $tmpfile: $!\n");
|
|
Packit |
6c4009 |
print TMPFILE "#include <$header>\n";
|
|
Packit |
6c4009 |
close (TMPFILE) || die ("close $tmpfile: $!\n");
|
|
Packit |
6c4009 |
$ret = system "$cc_all -c $tmpfile -o /dev/null -aux-info $auxfile > /dev/null";
|
|
Packit |
6c4009 |
unlink ($tmpfile) || die ("unlink $tmpfile: $!\n");
|
|
Packit |
6c4009 |
if ($ret != 0) {
|
|
Packit |
6c4009 |
return;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
open (AUXFILE, "<$auxfile") || die ("open $auxfile: $!\n");
|
|
Packit |
6c4009 |
while (<AUXFILE>) {
|
|
Packit |
6c4009 |
s|/\*.*?\*/||g;
|
|
Packit |
6c4009 |
if (/^\s*$/) {
|
|
Packit |
6c4009 |
next;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
# The word before a '(' that isn't '(*' is the function name
|
|
Packit |
6c4009 |
# before the argument list (not fully general, but sufficient for
|
|
Packit |
6c4009 |
# -aux-info output on standard headers).
|
|
Packit |
6c4009 |
if (/(\w+)\s*\([^*]/) {
|
|
Packit |
6c4009 |
$res{$1} = 1;
|
|
Packit |
6c4009 |
} else {
|
|
Packit |
6c4009 |
die ("couldn't parse -aux-info output: $_\n");
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
close (AUXFILE) || die ("close $auxfile: $!\n");
|
|
Packit |
6c4009 |
unlink ($auxfile) || die ("unlink $auxfile: $!\n");
|
|
Packit |
6c4009 |
return sort keys %res;
|
|
Packit |
6c4009 |
}
|