Home | History | Annotate | Download | only in gobject
      1 #!/usr/bin/perl -w
      2 
      3 my $do_def = 0;
      4 
      5 if (($#ARGV >= 0) && ($ARGV[0] eq "-def")) {
      6     shift;
      7     $do_def = 1;
      8 }
      9 
     10 print <<EOF;
     11 /* Generated by makegobjectalias.pl */
     12 
     13 #ifndef DISABLE_VISIBILITY
     14 
     15 #include "glibconfig.h"
     16 
     17 #ifdef G_HAVE_GNUC_VISIBILITY
     18 
     19 EOF
     20 
     21 if ($do_def) {
     22     print <<EOF
     23 #undef IN_FILE
     24 #define IN_FILE defined
     25 
     26 #undef IN_HEADER
     27 #define IN_HEADER(x) 1
     28 
     29 EOF
     30 } 
     31 else { 
     32     print <<EOF
     33 #define IN_FILE(x) 1
     34 #define IN_HEADER defined
     35 
     36 EOF
     37 }
     38 
     39 my $in_comment = 0;
     40 my $in_skipped_section = 0;
     41 
     42 while (<>) {
     43 
     44   # ignore empty lines
     45   next if /^\s*$/;
     46 
     47   # skip comments
     48   if ($_ =~ /^\s*\/\*/)
     49   {
     50       $in_comment = 1;
     51   }
     52   
     53   if ($in_comment)
     54   {
     55       if ($_ =~  /\*\/\s$/)
     56       {
     57 	  $in_comment = 0;
     58       }
     59       
     60       next;
     61   }
     62 
     63   # handle ifdefs
     64   if ($_ =~ /^\#endif/)
     65   {
     66       if (!$in_skipped_section)
     67       {
     68 	  print $_;
     69       }
     70 
     71       $in_skipped_section = 0;
     72 
     73       next;
     74   }
     75 
     76   if ($_ =~ /^\#ifdef\s+(INCLUDE_VARIABLES|INCLUDE_INTERNAL_SYMBOLS|ALL_FILES)/)
     77   {
     78       $in_skipped_section = 1;
     79   }
     80 
     81   if ($in_skipped_section)
     82   {
     83       next;
     84   }
     85 
     86   if ($_ =~ /^\#ifn?def\s+G/)
     87   {
     88       print $_;
     89       
     90       next;
     91   }
     92  
     93   if ($_ =~ /^\#if.*(IN_FILE|IN_HEADER)/)
     94   {
     95       print $_;
     96       
     97       next;
     98   }
     99 
    100   chop;
    101   my $str = $_;
    102   my @words;
    103   my $attributes = "";
    104 
    105   @words = split(/ /, $str);
    106   $str = shift(@words);
    107   chomp($str);
    108   my $alias = "IA__".$str;
    109   
    110   # Drop any Win32 specific .def file syntax,  but keep attributes
    111   foreach $word (@words) {
    112       $attributes = "$attributes $word" unless $word eq "PRIVATE";
    113   }
    114   
    115   if (!$do_def) {
    116     print <<EOF
    117 extern __typeof ($str) $alias __attribute((visibility("hidden")))$attributes;
    118 \#define $str $alias
    119 
    120 EOF
    121   }
    122   else {
    123     print <<EOF
    124 \#undef $str 
    125 extern __typeof ($str) $str __attribute((alias("$alias"), visibility("default")));
    126 
    127 EOF
    128   }
    129 }
    130 
    131 print <<EOF;
    132 
    133 #endif /* G_HAVE_GNUC_VISIBILITY */
    134 #endif /* DISABLE_VISIBILITY */
    135 EOF
    136 
    137 
    138