makegalias.pl 1.92 KB
Newer Older
1 2
#!/usr/bin/perl -w

3 4 5 6 7 8 9
my $do_def = 0;

if (($#ARGV >= 0) && ($ARGV[0] eq "-def")) {
    shift;
    $do_def = 1;
}

10 11 12 13
print <<EOF;
/* Generated by makegalias.pl */

#ifndef DISABLE_VISIBILITY
14 15 16

#include "glibconfig.h"

17 18
#ifdef G_HAVE_GNUC_VISIBILITY

19
EOF
20

21 22 23 24
if ($do_def) {
    print <<EOF
#undef IN_FILE
#define IN_FILE defined
25

26 27
#undef IN_HEADER
#define IN_HEADER(x) 1
28

29 30 31 32 33 34
EOF
} 
else { 
    print <<EOF
#define IN_FILE(x) 1
#define IN_HEADER defined
35 36

EOF
37
}
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

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;
  }

76
  if ($_ =~ /^\#ifdef\s+(INCLUDE_VARIABLES|INCLUDE_INTERNAL_SYMBOLS|ALL_FILES)/)
77 78 79 80 81 82 83 84 85
  {
      $in_skipped_section = 1;
  }

  if ($in_skipped_section)
  {
      next;
  }

86
  if ($_ =~ /^\#ifn?def\s+(G|DISABLE_MEM_POOLS)/)
87 88 89 90 91
  {
      print $_;
      
      next;
  }
92

93
  if ($_ =~ /^\#if.*(G_STDIO_NO_WRAP_ON_UNIX|IN_FILE|IN_HEADER|IN_FILE)/)
94 95 96 97 98 99
  {
      print $_;
      
      next;
  }

100
  chop;
101
  my $str = $_;
102 103 104 105 106
  my @words;
  my $attributes = "";

  @words = split(/ /, $str);
  $str = shift(@words);
107 108 109
  chomp($str);
  my $alias = "IA__".$str;
  
110 111 112 113
  # Drop any Win32 specific .def file syntax,  but keep attributes
  foreach $word (@words) {
      $attributes = "$attributes $word" unless $word eq "PRIVATE";
  }
114 115 116

  if (!$do_def) {
    print <<EOF
117
extern __typeof ($str) $alias __attribute((visibility("hidden")))$attributes;
118 119 120
\#define $str $alias

EOF
121 122 123 124 125
  }
  else {
    print <<EOF
\#undef $str 
extern __typeof ($str) $str __attribute((alias("$alias"), visibility("default")));
126

127 128 129
EOF
  }
}
130

131
print <<EOF
132 133 134 135 136

#endif /* G_HAVE_GNUC_VISIBILITY */
#endif /* DISABLE_VISIBILITY */
EOF