2011-05-03 12:02:25 +02:00
#!/usr/bin/perl -w
#
# Update spec files across dlls that share an implementation
#
# Copyright 2011 Alexandre Julliard
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#
use strict;
my %funcs;
my $group_head;
my @dll_groups =
(
[
"msvcrt",
2012-12-06 13:23:23 +01:00
"msvcirt",
2011-05-03 12:02:25 +02:00
"msvcrt40",
"msvcrt20",
],
[
"msvcrt",
"msvcp90",
"msvcp100",
2013-03-30 13:48:49 +01:00
"msvcp110",
2014-11-11 18:35:39 +01:00
"msvcp120",
2015-11-03 22:54:34 +01:00
"msvcp140",
2011-05-03 12:02:25 +02:00
"msvcp71",
2013-01-16 14:36:40 +01:00
"msvcp80",
2011-05-03 12:02:25 +02:00
"msvcp70",
"msvcp60",
],
2014-12-10 09:44:44 +01:00
[
"msvcr120",
"msvcr120_app",
2016-08-04 01:57:08 +02:00
"concrt140",
2014-12-10 09:44:44 +01:00
],
2015-08-26 08:44:42 +02:00
[
"ucrtbase",
2015-10-29 13:30:08 +01:00
"vcruntime140",
2015-08-26 08:44:42 +02:00
],
2014-12-10 14:44:04 +01:00
[
"msvcp120",
"msvcp120_app",
],
2021-11-19 19:47:18 +01:00
[
"msvcp140",
"msvcp_win",
],
2018-02-27 05:21:25 +01:00
[
"d3d10",
"d3d10_1",
],
2011-05-03 11:13:08 +02:00
[
"d3dx10_43",
"d3dx10_42",
"d3dx10_41",
"d3dx10_40",
"d3dx10_39",
"d3dx10_38",
"d3dx10_37",
"d3dx10_36",
"d3dx10_35",
"d3dx10_34",
"d3dx10_33",
],
[
"xinput1_3",
2013-09-03 21:07:29 +02:00
"xinput1_4",
2011-05-03 11:13:08 +02:00
"xinput1_2",
"xinput1_1",
"xinput9_1_0",
],
2012-03-18 19:30:10 +01:00
[
"vcomp",
2016-08-09 04:56:29 +02:00
"vcomp140",
2015-04-28 20:08:47 +02:00
"vcomp120",
2015-07-31 19:00:00 +02:00
"vcomp110",
2012-03-18 19:30:10 +01:00
"vcomp100",
2012-09-16 17:10:20 +02:00
"vcomp90",
2012-03-18 19:30:10 +01:00
],
2012-12-17 11:37:45 +01:00
[
"advapi32",
2022-02-15 15:55:46 +01:00
"sechost",
2018-03-13 14:44:31 +01:00
],
2016-11-19 11:56:38 +01:00
[
"netapi32",
2020-11-02 19:19:27 +01:00
"srvcli",
2016-11-19 11:56:38 +01:00
],
2012-12-20 08:50:01 +01:00
[
"ole32",
2016-09-19 21:16:26 +02:00
"iprop",
2012-12-20 08:50:01 +01:00
],
2018-04-25 03:44:02 +02:00
[
"secur32",
2022-02-16 16:07:33 +01:00
"security",
2018-04-25 03:44:02 +02:00
"sspicli",
],
2014-02-04 14:55:23 +01:00
[
"gdi32",
2020-11-09 11:04:04 +01:00
"usp10"
2014-02-04 14:55:23 +01:00
],
2016-01-22 07:51:00 +01:00
[
"bthprops.cpl",
"irprops.cpl",
],
2016-04-02 01:36:45 +02:00
[
"sfc_os",
"sfc",
],
2016-05-26 07:21:09 +02:00
[
"bcrypt",
"ncrypt",
2021-10-22 12:40:08 +02:00
"cng.sys",
2016-05-26 07:21:09 +02:00
],
2017-03-07 16:01:20 +01:00
[
"ntoskrnl.exe",
"hal",
],
2019-07-11 21:23:43 +02:00
[
"mscoree",
"mscorwks",
],
2021-06-02 21:40:16 +02:00
[
"sppc",
"slc",
],
2011-05-03 12:02:25 +02:00
);
my $update_flags = 0;
my $show_duplicates = 0;
foreach my $arg (@ARGV)
{
if ($arg eq "-f") { $update_flags = 1; }
elsif ($arg eq "-d") { $show_duplicates = 1; }
}
2016-07-06 08:32:16 +02:00
# update a file if changed
sub update_file($$)
2011-05-03 12:02:25 +02:00
{
my $file = shift;
2016-07-06 08:32:16 +02:00
my $new = shift;
open FILE, ">$file.new" or die "cannot create $file.new";
print FILE $new;
close FILE;
rename "$file.new", "$file";
print "$file updated\n";
2011-05-03 12:02:25 +02:00
}
# parse a spec file line
sub parse_line($$$)
{
2014-02-06 11:19:16 +01:00
my ($name, $line, $str) = @_;
2011-05-03 12:02:25 +02:00
2014-02-06 11:19:16 +01:00
if ($str =~ /^\s*(\@|\d+)\s+(stdcall|cdecl|varargs|thiscall|stub|extern)\s+((?:-\S+\s+)*)([A-Za-z0-9_\@\$?]+)(?:\s*(\([^)]*\)))?(?:\s+([A-Za-z0-9_\@\$?.]+))?(\s*\#.*)?/)
2011-05-03 12:02:25 +02:00
{
return ( "ordinal" => $1, "callconv" => $2, "flags" => $3, "name" => $4, "args" => $5 || "",
"target" => $6 || $4, "comment" => $7, "spec" => $name );
}
2014-02-06 11:19:16 +01:00
return () if $str =~ /^\s*$/;
return () if $str =~ /^\s*\#/;
2011-05-03 12:02:25 +02:00
printf STDERR "$name.spec:$line: error: Unrecognized line $_\n";
}
sub read_spec_file($)
{
my $name = shift;
my $file = "dlls/$name/$name.spec";
my %stubs;
open SPEC, "<$file" or die "cannot open $file";
while (<SPEC>)
{
chomp;
my %descr = parse_line( $name, $., $_ );
next unless %descr;
my $func = $descr{name};
2021-11-28 16:19:34 +01:00
if (defined $funcs{$func})
{
my %update = %{$funcs{$func}};
next if $update{ordinal} ne $descr{ordinal} or $update{callconv} ne $descr{callconv} or $update{args} ne $descr{args};
my $arch = $1 if $update{flags} =~ /-arch=(\S+)/;
my $new_arch = $1 if $descr{flags} =~ /-arch=(\S+)/;
next if !defined $arch or !defined $new_arch;
if (($arch eq "win32" and $new_arch eq "win64") or ($arch eq "win64" and $new_arch eq "win32"))
{
$funcs{$func}{flags} =~ s/-arch=\S+\s+//;
next;
}
$funcs{$func}{flags} =~ s/-arch=$arch/-arch=$arch,$new_arch/;
next;
}
2017-03-24 04:11:50 +01:00
next if $func eq "@";
2011-05-03 12:02:25 +02:00
$funcs{$func} = \%descr;
}
close SPEC;
}
sub update_spec_file($)
{
my $name = shift;
my $file = "dlls/$name/$name.spec";
my %stubs;
2016-07-06 08:32:16 +02:00
my ($old, $new);
2011-05-03 12:02:25 +02:00
open SPEC, "<$file" or die "cannot open $file";
while (<SPEC>)
{
2016-07-06 08:32:16 +02:00
$old .= $_;
2011-05-03 12:02:25 +02:00
chomp;
my $commented_out = 0;
my %descr = parse_line( $name, $., $_ );
if (!%descr)
{
# check for commented out exports
if (/^\s*\#\s*((?:\@|\d+)\s+)?((?:extern|stub|stdcall|cdecl|varargs|thiscall)\s+.*)/)
{
$commented_out = 1;
%descr = parse_line( $name, $., ($1 || "\@ ") . $2 );
}
}
goto done unless %descr;
my $func = $descr{name};
if (!defined $funcs{$func})
{
2019-09-26 19:39:08 +02:00
$funcs{$func} = \%descr unless $commented_out || $name =~ /-/;
2011-05-03 12:02:25 +02:00
goto done;
}
my %parent = %{$funcs{$func}};
goto done if $parent{spec} eq $descr{spec}; # the definition is in this spec file
2011-09-14 16:29:35 +02:00
goto done if $descr{comment} && $descr{comment} =~ /don't forward/;
2011-05-04 13:45:36 +02:00
if ($descr{callconv} ne "stub" && $descr{target} !~ /\./ && !$commented_out)
2011-05-03 12:02:25 +02:00
{
printf "%s:%u: note: %s already defined in %s\n", $file, $., $func, $parent{spec} if $show_duplicates;
goto done;
}
2012-12-19 14:36:24 +01:00
my $flags = $descr{flags};
if ($parent{callconv} ne "stub" || $update_flags)
{
$flags = $parent{flags};
$flags =~ s/-ordinal\s*// if $descr{ordinal} eq "@";
2014-02-06 11:19:16 +01:00
$flags =~ s/-noname\s*// if $descr{ordinal} eq "@";
2019-06-21 12:08:44 +02:00
$flags =~ s/-import\s*//;
2013-03-14 13:57:33 +01:00
if ($descr{flags} =~ /-private/) # preserve -private flag
{
$flags = "-private " . $flags unless $flags =~ /-private/;
}
2012-12-19 14:36:24 +01:00
}
2011-05-03 12:02:25 +02:00
2011-05-03 13:13:15 +02:00
if ($parent{callconv} ne "stub" || $parent{args})
2011-05-03 12:02:25 +02:00
{
my $callconv = $parent{callconv} ne "stub" ? $parent{callconv} :
2015-08-26 08:44:41 +02:00
$parent{spec} =~ /(msvc|ucrtbase)/ ? "cdecl" : "stdcall"; # hack
2011-06-23 00:02:30 +02:00
$_ = sprintf "$descr{ordinal} %s %s%s", $callconv, $flags, $func;
2011-05-03 12:02:25 +02:00
if ($parent{target} =~ /$group_head\./) # use the same forward as parent if possible
{
$_ .= sprintf "%s %s", $parent{args}, $parent{target};
}
else
{
$_ .= sprintf "%s %s.%s", $parent{args}, $parent{spec}, $func;
}
}
else
{
2011-06-23 00:02:30 +02:00
$_ = sprintf "$descr{ordinal} stub %s%s", $flags, $func;
2011-05-03 12:02:25 +02:00
}
$_ .= $descr{comment} || "";
done:
2016-07-06 08:32:16 +02:00
$new .= "$_\n";
2011-05-03 12:02:25 +02:00
}
close SPEC;
2016-07-06 08:32:16 +02:00
update_file( $file, $new ) if $old ne $new;
2011-05-03 12:02:25 +02:00
}
sub sync_spec_files(@)
{
%funcs = ();
$group_head = shift;
read_spec_file( $group_head );
foreach my $spec (@_) { update_spec_file($spec); }
}
foreach my $group (@dll_groups)
{
sync_spec_files( @{$group} );
}