Updates
[glib.git] / glib / makegalias.pl
blobf7ee76965b15bf28fe9aa854862e0e5c6efee9c8
1 #!/usr/bin/perl -w
3 my $do_def = 0;
5 if (($#ARGV >= 0) && ($ARGV[0] eq "-def")) {
6 shift;
7 $do_def = 1;
10 print <<EOF;
11 /* Generated by makegalias.pl */
13 #ifndef DISABLE_VISIBILITY
15 #include "glibconfig.h"
17 #ifdef G_HAVE_GNUC_VISIBILITY
19 EOF
21 if ($do_def) {
22 print <<EOF
23 #undef IN_FILE
24 #define IN_FILE defined
26 #undef IN_HEADER
27 #define IN_HEADER(x) 1
29 EOF
31 else {
32 print <<EOF
33 #define IN_FILE(x) 1
34 #define IN_HEADER defined
36 EOF
39 my $in_comment = 0;
40 my $in_skipped_section = 0;
42 while (<>) {
44 # ignore empty lines
45 next if /^\s*$/;
47 # skip comments
48 if ($_ =~ /^\s*\/\*/)
50 $in_comment = 1;
53 if ($in_comment)
55 if ($_ =~ /\*\/\s$/)
57 $in_comment = 0;
60 next;
63 # handle ifdefs
64 if ($_ =~ /^\#endif/)
66 if (!$in_skipped_section)
68 print $_;
71 $in_skipped_section = 0;
73 next;
76 if ($_ =~ /^\#ifdef\s+(INCLUDE_VARIABLES|INCLUDE_INTERNAL_SYMBOLS|ALL_FILES)/)
78 $in_skipped_section = 1;
81 if ($in_skipped_section)
83 next;
86 if ($_ =~ /^\#ifn?def\s+(G|DISABLE_MEM_POOLS)/)
88 print $_;
90 next;
93 if ($_ =~ /^\#if.*(G_STDIO_NO_WRAP_ON_UNIX|IN_FILE|IN_HEADER|IN_FILE)/)
95 print $_;
97 next;
100 chop;
101 my $str = $_;
102 my @words;
103 my $attributes = "";
105 @words = split(/ /, $str);
106 $str = shift(@words);
107 chomp($str);
108 my $alias = "IA__".$str;
110 # Drop any Win32 specific .def file syntax, but keep attributes
111 foreach $word (@words) {
112 $attributes = "$attributes $word" unless $word eq "PRIVATE";
115 if (!$do_def) {
116 print <<EOF
117 extern __typeof ($str) $alias __attribute((visibility("hidden")))$attributes;
118 \#define $str $alias
122 else {
123 print <<EOF
124 \#undef $str
125 extern __typeof ($str) $str __attribute((alias("$alias"), visibility("default")));
131 print <<EOF
133 #endif /* G_HAVE_GNUC_VISIBILITY */
134 #endif /* DISABLE_VISIBILITY */