summaryrefslogtreecommitdiff
path: root/gobject/makegobjectalias.pl
blob: 31983c19d03e327e8400220c797b0b00c757ce4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/perl -w

exit 0;

my $do_def = 0;

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

print <<EOF;
/* Generated by makegobjectalias.pl */

#ifndef DISABLE_VISIBILITY

#include "glibconfig.h"

#ifdef G_HAVE_GNUC_VISIBILITY

EOF

if ($do_def) {
    print <<EOF
#undef IN_FILE
#define IN_FILE defined

#undef IN_HEADER
#define IN_HEADER(x) 1

EOF
} 
else { 
    print <<EOF
#define IN_FILE(x) 1
#define IN_HEADER defined

EOF
}

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 $_;
      
      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")));

EOF
  }
}

print <<EOF;

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