That should fix building the python bindings if srcdir =! builddir.
[vlc.git] / vlc-api.pl
blobdc8056f0eb6a52044f4954cc84ebfd515a57b32a
1 #!/usr/bin/perl
2 #*****************************************************************************
3 #* vlc-api.pl: VLC API maintenance script
4 #*****************************************************************************
5 #* Copyright (C) 2005 the VideoLAN team
6 #* $Id$
7 #*
8 #* Authors: RĂ©mi Denis-Courmont <rem # videolan.org>
9 #*
10 #* This program is free software; you can redistribute it and/or modify
11 #* it under the terms of the GNU General Public License as published by
12 #* the Free Software Foundation; either version 2 of the License, or
13 #* (at your option) any later version.
15 #* This program is distributed in the hope that it will be useful,
16 #* but WITHOUT ANY WARRANTY; without even the implied warranty of
17 #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 #* GNU General Public License for more details.
20 #* You should have received a copy of the GNU General Public License
21 #* along with this program; if not, write to the Free Software
22 #* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 #*****************************************************************************/
25 use IO::Handle;
26 use strict;
28 my $srcdir = $ENV{'top_srcdir'};
31 # Reads to-be exported APIs
33 my %new_APIs;
34 my $new_sym = IO::Handle->new();
35 open $new_sym, '> libvlc.sym' or die "libvlc.sym: $!\n";
37 while (<STDIN>)
39 if (/VLC_EXPORT\(\s*(\w.*\S)\s*,\s*(\w*)\s*,\s*\(\s*(\w.*\S)\s*\)\s*\)[^)]*$/)
41 $new_APIs{$2} = [ ( $1, $3 ) ];
42 print { $new_sym } "$2\n";
46 close $new_sym;
49 # Write header's header
51 open $new_sym, '> vlc_symbols.h.new' or die "vlc_symbols.h.new: $!\n";
52 print { $new_sym }
53 "/*\n".
54 " * This file is automatically generated. DO NOT EDIT!\n".
55 " * You can force an update with \"make stamp-api\".\n".
56 " */\n".
57 "\n".
58 "#ifndef __VLC_SYMBOLS_H\n".
59 "# define __VLC_SYMBOLS_H\n".
60 "\n".
61 "# ifdef HAVE_SHARED_LIBVLC\n".
62 "# error You are not supposed to include this file!\n".
63 "# endif\n".
64 "/*\n".
65 " * This is the big VLC API structure for plugins :\n".
66 " * Changing its layout breaks plugin's binary compatibility,\n".
67 " * so DO NOT DO THAT.\n".
68 " * In case of conflict with SVN, add your uncommited APIs\n".
69 " * at the *end* of the structure so they don't mess the other's\n".
70 " * offset in the structure.\n".
71 " */\n".
72 "struct module_symbols_t\n".
73 "{\n";
75 my $changes = 0;
78 # Compares new APIs with currently exported APIs
80 my @API;
81 my @deprecated_API;
82 my $parse = 0;
84 my $oldfd = IO::Handle->new();
85 open $oldfd, "< $srcdir/include/vlc_symbols.h";
87 while (<$oldfd>)
89 if (/^struct module_symbols_t/)
91 $parse = 1;
93 elsif ($parse == 0)
96 elsif (/^ void \*(\w*)_deprecated;$/)
98 if (defined $new_APIs{$1})
100 print "[info] $1 was RESTORED!\n";
101 print { $new_sym }
102 " ".$new_APIs{$1}[0]." (*$1_inner) (".$new_APIs{$1}[1].");\n";
103 delete $new_APIs{$1};
104 push (@API, $1);
105 $changes++;
107 else
109 print { $new_sym } $_;
110 push (@deprecated_API, $1);
113 elsif (/^\s*(\w.*\S)\s*\(\*\s*(\w*)_inner\)\s*\(\s*(\w.*\S)\s*\)\s*;\s*$/)
115 if (!defined $new_APIs{$2})
117 print "[warn] $2 was REMOVED!\n";
118 print { $new_sym } " void *$2_deprecated;\n";
119 push (@deprecated_API, $2);
120 $changes++;
122 elsif (($new_APIs{$2}[0] ne $1)
123 || ($new_APIs{$2}[1] ne $3))
125 print
126 "[warn] $2 was CHANGED!\n".
127 " Old argument(s) : \"$3\"\n".
128 " New argument(s) : \"".$new_APIs{$2}[1]."\"\n".
129 " Old return type : \"$1\"\n".
130 " New return type : \"".$new_APIs{$2}[0]."\"\n";
132 print { $new_sym }
133 " ".$new_APIs{$2}[0]." (*$2_inner) (".$new_APIs{$2}[1].");\n";
134 delete $new_APIs{$2};
135 push (@API, $2);
136 $changes++;
138 else
140 print { $new_sym } " $1 (*$2_inner) ($3);\n";
141 push (@API, $2);
142 delete $new_APIs{$2};
146 close $oldfd;
149 # Adds brand-new APIs
151 foreach (keys %new_APIs)
153 print "[info] $_ was ADDED!\n";
154 print { $new_sym }
155 " ".$new_APIs{$_}[0]." (*${_}_inner) (".$new_APIs{$_}[1].");\n";
156 push (@API, $_);
157 $changes++;
161 # Writes #defines
163 print { $new_sym }
164 "};\n".
165 "# if defined (__PLUGIN__)\n";
167 foreach (@API)
169 print { $new_sym } "# define $_ (p_symbols)->${_}_inner\n";
172 print { $new_sym }
173 "# elif defined (HAVE_DYNAMIC_PLUGINS) && !defined (__BUILTIN__)\n".
174 "/******************************************************************\n".
175 " * STORE_SYMBOLS: store VLC APIs into p_symbols for plugin access.\n".
176 " ******************************************************************/\n".
177 "# define STORE_SYMBOLS( p_symbols ) \\\n";
179 foreach (@API)
181 print { $new_sym } " ((p_symbols)->${_}_inner) = $_; \\\n";
183 foreach (@deprecated_API)
185 print { $new_sym } " (p_symbols)->${_}_deprecated = NULL; \\\n";
188 print { $new_sym }
189 "\n".
190 "# endif /* __PLUGIN__ */\n".
191 "#endif /* __VLC_SYMBOLS_H */\n";
192 close $new_sym;
195 # Replace headers if needed
197 if ($changes != 0)
199 rename 'vlc_symbols.h.new', "$srcdir/include/vlc_symbols.h";
200 print "$changes API(s) changed.\n";
202 else
204 unlink 'vlc_symbols.h.new';