1#!/usr/bin/env perl -w
2#
3# Copyright (c) 2004      The GLib Development Team.
4# Copyright (c) 2005-2006 Benedikt Meurer <benny@xfce.org>.
5#
6# This library is free software; you can redistribute it and/or
7# modify it under the terms of the GNU Library General Public
8# License as published by the Free Software Foundation; either
9# version 2 of the License, or (at your option) any later version.
10#
11# This library is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14# Library General Public License for more details.
15#
16# You should have received a copy of the GNU Lesser General Public
17# License along with this library; if not, write to the Free
18# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19# Boston, MA 02110-1301 USA
20#
21
22my $option_def = 0;
23
24if (($#ARGV >= 0) && ($ARGV[0] eq "-def"))
25  {
26    shift;
27    $option_def = 1;
28  }
29
30print <<EOF;
31/* Generated by make-libxfce4util-alias.pl. Do not edit this file. */
32
33#ifdef HAVE_GNUC_VISIBILITY
34
35#include <glib.h>
36
37EOF
38
39my $in_comment = 0;
40my $in_skipped_section = 0;
41
42while (<>)
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        next;
60      }
61
62    # handle ifdefs
63    if ($_ =~ /^\#endif/)
64      {
65        if (!$in_skipped_section)
66          {
67            print $_;
68          }
69
70        $in_skipped_section = 0;
71        next;
72      }
73
74    if ($_ =~ /^\#ifdef\s+(INCLUDE_VARIABLES|INCLUDE_INTERNAL_SYMBOLS|ALL_FILES)/)
75      {
76        $in_skipped_section = 1;
77      }
78
79    if ($in_skipped_section)
80      {
81        next;
82      }
83
84    if ($_ =~ /^\#ifn?def\s+G/)
85      {
86        print $_;
87        next;
88      }
89
90    if ($_ =~ /^\#if.*IN_SOURCE\((.*)\)/)
91      {
92        if ($option_def)
93          {
94            print "#ifdef $1\n";
95          }
96        else
97          {
98            print "#if 1\n";
99          }
100        next;
101      }
102
103    if ($_ =~ /^\#if.*IN_HEADER\((.*)\)/)
104      {
105        if ($option_def)
106          {
107            print "#if 1\n";
108          }
109        else
110          {
111            print "#ifdef $1\n";
112          }
113        next;
114      }
115
116    chop;
117    my $line = $_;
118    my @words;
119    my $attributes = "";
120
121    @words = split (/ /, $line);
122    my $symbol = shift (@words);
123    chomp ($symbol);
124    my $alias = "IA__".$symbol;
125
126    # Drop any Win32 specific .def file syntax,  but keep attributes
127    foreach $word (@words)
128      {
129        $attributes = "$attributes $word" unless $word eq "PRIVATE";
130      }
131
132    if (!$option_def)
133      {
134        print <<EOF
135extern __typeof ($symbol) $alias __attribute((visibility("hidden")))$attributes;
136\#define $symbol $alias
137
138EOF
139      }
140    else
141      {
142        print <<EOF
143\#undef $symbol
144extern __typeof ($symbol) $symbol __attribute((alias("$alias"), visibility("default")));
145
146EOF
147      }
148  }
149
150print <<EOF;
151
152#endif /* HAVE_GNUC_VISIBILITY */
153EOF
154
155
156