4 die "Usage: $0 script.ver dllname build.def import.def\n" if @ARGV != 4;
5 my ($verfile, $dllname, $builddef, $importdef) = @ARGV;
6 open my $verfh, '<', $verfile or die "Cannot open input file $verfile: $!\n";
7 my $input = join '', <$verfh>;
10 my (%cnt, %last, %ords);
11 $input =~ s/\/\*.*?\*\///sg; # Remove C comments
12 while ($input =~ m/(\S+)\s*\{((?:[^\{\}]|\{(?2)\})+)\}\s*;/sg) { # Split {...}
13 my ($ver, $block) = ($1, $2);
14 while ($block =~ s/(\S+)\s*:((?:[^\{\}:]|\{(?2)\})+)$//sg) { # Split section:
15 my ($section, $syms) = ($1, $2);
16 next if $section ne 'global';
18 foreach (split /;\s*/, $syms) { # Split symbols
21 push @syms, [$_, $ver];
25 open my $importfh, '>', $importdef or die "Cannot open output file $importdef: $!\n";
26 open my $buildfh, '>', $builddef or die "Cannot open output file $builddef: $!\n";
27 print $importfh "LIBRARY \"$dllname\"\n";
28 print $importfh "EXPORTS\n";
29 print $buildfh "EXPORTS\n";
32 my ($sym, $ver) = @{$_};
33 print $importfh "\"$sym\@$ver\" \@$ord\n";
34 if ($last{$sym} ne $ver) {
35 print $buildfh "\"$sym\@$ver\" \@$ord\n";
38 print $buildfh "\"$sym\@$ver\" = " . (($cnt{$sym} > 1) ? "\"$sym\@\@$ver\"" : $sym) . " \@$ord\n"
42 # GNU dlltool has broken calculation of ordinals for aliased symbols, so specify ordinals explicitly
43 # GNU LD prior 2.21 has broken handling of symbols with dot character
44 # Operator == for defining symbol alias is supported since GNU dlltool 2.21
45 print $importfh "$_ \@$ords{$_} == \"$_\@$last{$_}\"\n" foreach sort keys %last;