IN_FILE and IN_HEADER were defined as "defined", which is undefined behaviour; clang warned about it some thousand times per build. The generated files now test defined() directly, with the same result.
137 lines
2.2 KiB
Perl
Executable file
137 lines
2.2 KiB
Perl
Executable file
#!/usr/bin/perl -w
|
|
|
|
my $do_def = 0;
|
|
|
|
if (($#ARGV >= 0) && ($ARGV[0] eq "-def")) {
|
|
shift;
|
|
$do_def = 1;
|
|
}
|
|
|
|
print <<EOF;
|
|
/* Generated by makegdkalias.pl */
|
|
|
|
#ifndef DISABLE_VISIBILITY
|
|
|
|
#include <glib.h>
|
|
|
|
#if defined(G_HAVE_GNUC_VISIBILITY) && !defined(__APPLE__) && !defined(G_OS_WIN32)
|
|
|
|
EOF
|
|
|
|
# The sections of the .symbols file become plain tests here: a macro
|
|
# that expands to "defined" is undefined behaviour, which clang warns of.
|
|
# Aliases (the -def file) are made for the file being compiled, the
|
|
# renaming (the header) for the headers it included.
|
|
sub section_test {
|
|
my ($line) = @_;
|
|
|
|
if ($do_def) {
|
|
$line =~ s/IN_FILE\(([^)]*)\)/defined($1)/g;
|
|
$line =~ s/IN_HEADER\([^)]*\)/1/g;
|
|
}
|
|
else {
|
|
$line =~ s/IN_FILE\([^)]*\)/1/g;
|
|
$line =~ s/IN_HEADER\(([^)]*)\)/defined($1)/g;
|
|
}
|
|
|
|
return $line;
|
|
}
|
|
|
|
my $in_comment = 0;
|
|
my $in_skipped_section = 0;
|
|
|
|
while (<>) {
|
|
|
|
# ignore empty lines
|
|
next if /^\s*$/;
|
|
|
|
# skip comments
|
|
if ($_ =~ /^\s*\/\*/)
|
|
{
|
|
$in_comment = 1;
|
|
}
|
|
|
|
if ($in_comment)
|
|
{
|
|
if ($_ =~ /\*\/\s$/)
|
|
{
|
|
$in_comment = 0;
|
|
}
|
|
|
|
next;
|
|
}
|
|
|
|
# handle ifdefs
|
|
if ($_ =~ /^\#endif/)
|
|
{
|
|
if (!$in_skipped_section)
|
|
{
|
|
print $_;
|
|
}
|
|
|
|
$in_skipped_section = 0;
|
|
|
|
next;
|
|
}
|
|
|
|
if ($_ =~ /^\#ifdef\s+(INCLUDE_VARIABLES|INCLUDE_INTERNAL_SYMBOLS|ALL_FILES)/)
|
|
{
|
|
$in_skipped_section = 1;
|
|
}
|
|
|
|
if ($in_skipped_section)
|
|
{
|
|
next;
|
|
}
|
|
|
|
if ($_ =~ /^\#ifn?def\s+G/)
|
|
{
|
|
print $_;
|
|
|
|
next;
|
|
}
|
|
|
|
if ($_ =~ /^\#if.*(IN_FILE|IN_HEADER)/)
|
|
{
|
|
print section_test ($_);
|
|
|
|
next;
|
|
}
|
|
|
|
chop;
|
|
my $str = $_;
|
|
my @words;
|
|
my $attributes = "";
|
|
|
|
@words = split(/ /, $str);
|
|
$str = shift(@words);
|
|
chomp($str);
|
|
my $alias = "IA__".$str;
|
|
|
|
# Drop any Win32 specific .def file syntax, but keep attributes
|
|
foreach $word (@words) {
|
|
$attributes = "$attributes $word" unless $word eq "PRIVATE";
|
|
}
|
|
|
|
if (!$do_def) {
|
|
print <<EOF
|
|
extern __typeof ($str) $alias __attribute((visibility("hidden")))$attributes;
|
|
\#define $str $alias
|
|
|
|
EOF
|
|
}
|
|
else {
|
|
print <<EOF
|
|
#undef $str
|
|
extern __typeof ($str) $str __attribute((alias("$alias"), visibility("default")))$attributes;
|
|
|
|
EOF
|
|
}
|
|
}
|
|
|
|
print <<EOF;
|
|
|
|
#endif /* G_HAVE_GNUC_VISIBILITY */
|
|
#endif /* DISABLE_VISIBILITY */
|
|
EOF
|
|
|