3 # Extract #define symbol information from C header files.
5 # Copyright 2002 Alexandre Julliard
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 # list of symbols (regexps) to skip for each header
25 "winnt.h" => [ "APIENTRY", "APIPRIVATE", "CALLBACK", "CONST", "EXTERN_C", "PASCAL",
26 "VOID", "DUMMY(STRUCT|UNION)NAME.*", "STDAPI.*", "STDMETHOD.*", "WINAPI.*",
27 "WINE_.*", "_*(cdecl|CDECL|pascal|export|fastcall|stdcall)",
28 "MEM_SYSTEM", "_GET_CONTEXT", "_QUAD_.*",
29 "CONTEXT_(ALPHA|R4000|SPARC|X86|i386|i486)" ],
30 "winbase.h" => [ "(Fill|Move|Zero|Copy)Memory" ],
31 "wingdi.h" => [ "PROFILE_LINKED", "PROFILE_EMBEDDED", "GetCharWidth[AW]" ],
32 "winuser.h" => [ "OemToAnsi[AW]", "OemToAnsiBuff[AW]", "AnsiToOem[AW]", "AnsiToOemBuff[AW]",
33 "Ansi(Next|Prev|Lower|Upper|LowerBuff|UpperBuff)[AW]", "GetNextWindow" ],
34 "winsock2.h" => [ "WSAEVENT", "LPWSAEVENT", "WSAOVERLAPPED", "WS_.*" ]
53 $include_dir = "../../include";
55 @list = ($#ARGV >= 0) ? @ARGV : @header_list;
57 foreach $basename (@list)
59 my $skip = $skip_list{$basename};
60 my $result = "include/" . $basename;
61 $result =~ s!\.h$!.pm!;
63 my $package = $basename;
66 open INPUT, "$include_dir/$basename" or die "Cannot open $include_dir/$basename";
67 open OUTPUT, ">sym.c" or die "Cannot create sym.c";
68 print "Building $result\n";
75 foreach $inc (@header_list) { print OUTPUT "#include <$inc>\n"; }
80 printf( "# Automatically generated by make_symbols; DO NOT EDIT!! \\n" );
82 printf( "# Perl definitions for header file $basename\\n" );
85 printf( "package $package;\\n" );
87 printf( "use strict;\\n" );
89 printf( "use vars qw(\$VERSION \@ISA \@EXPORT \@EXPORT_OK);\\n" );
91 printf( "require Exporter;\\n" );
93 printf( "\@ISA = qw(Exporter);\\n" );
94 printf( "\@EXPORT = qw(\\n" );
100 # extract all #defines
101 next unless (/^\s*\#\s*define\s+([A-Za-z0-9_]+)\s+(.*)$/);
102 my ($name,$value) = ($1,$2);
104 next if ($value eq "");
105 # skip the WINELIB defines
106 next if ($value =~ /WINELIB_NAME_AW/);
107 # skip macros containing multiple values
108 next if ($value =~ /{.*}/);
109 # check against regexps to skip
110 next if (grep { $name =~ /^$_$/ } @$skip);
111 $symbols{$name} = $value;
113 foreach $sym (sort keys %symbols)
115 printf OUTPUT " printf(\" $sym\\n\");\n";
117 printf OUTPUT " printf(\");\\n\");\n";
118 printf OUTPUT " printf(\"\@EXPORT_OK = qw();\\n\");\n";
119 printf OUTPUT " printf(\"\\n\");\n";
121 foreach $sym (sort keys %symbols)
123 printf OUTPUT " printf(\"use constant $sym => %%d;\\n\", (int)($sym));\n";
125 printf OUTPUT " printf(\"\\n\");\n";
126 printf OUTPUT " printf(\"1;\\n\");\n";
127 print OUTPUT " exit(0);\n}\n";
129 #print "cc -I../../include -o sym sym.c\n";
130 if (system( "cc -I../../include -o sym sym.c" )) { die "Could not compile sym.c"; }
131 #print "./sym >$result\n";
132 if (system( "./sym >$result" )) { die "Could not run ./sym\n"; }
133 unlink "sym","sym.c";