| 1 |
|
| 2 |
# Copyright (c) 2024-2025, PostgreSQL Global Development Group |
| 3 |
|
| 4 |
use strict; |
| 5 |
use warnings FATAL => 'all'; |
| 6 |
use Getopt::Long; |
| 7 |
|
| 8 |
my $format; |
| 9 |
my $libname; |
| 10 |
my $input; |
| 11 |
my $output; |
| 12 |
|
| 13 |
GetOptions( |
| 14 |
'format:s' => \$format, |
| 15 |
'libname:s' => \$libname, |
| 16 |
'input:s' => \$input, |
| 17 |
'output:s' => \$output) or die "wrong arguments"; |
| 18 |
|
| 19 |
if (not( $format eq 'darwin' |
| 20 |
or $format eq 'gnu' |
| 21 |
or $format eq 'win')) |
| 22 |
{ |
| 23 |
die "$0: $format is not yet handled (only darwin, gnu, win are)\n"; |
| 24 |
} |
| 25 |
|
| 26 |
open(my $input_handle, '<', $input) |
| 27 |
or die "$0: could not open input file '$input': $!\n"; |
| 28 |
|
| 29 |
open(my $output_handle, '>', $output) |
| 30 |
or die "$0: could not open output file '$output': $!\n"; |
| 31 |
|
| 32 |
|
| 33 |
if ($format eq 'gnu') |
| 34 |
{ |
| 35 |
print $output_handle "{ |
| 36 |
global: |
| 37 |
"; |
| 38 |
} |
| 39 |
elsif ($format eq 'win') |
| 40 |
{ |
| 41 |
# XXX: Looks like specifying LIBRARY $libname is optional, which makes it |
| 42 |
# easier to build a generic command for generating export files... |
| 43 |
if ($libname) |
| 44 |
{ |
| 45 |
print $output_handle "LIBRARY $libname\n"; |
| 46 |
} |
| 47 |
print $output_handle "EXPORTS\n"; |
| 48 |
} |
| 49 |
|
| 50 |
while (<$input_handle>) |
| 51 |
{ |
| 52 |
if (/^#/) |
| 53 |
{ |
| 54 |
# don't do anything with a comment |
| 55 |
} |
| 56 |
elsif (/^(\S+)\s+(\S+)/) |
| 57 |
{ |
| 58 |
if ($format eq 'darwin') |
| 59 |
{ |
| 60 |
print $output_handle "_$1\n"; |
| 61 |
} |
| 62 |
elsif ($format eq 'gnu') |
| 63 |
{ |
| 64 |
print $output_handle " $1;\n"; |
| 65 |
} |
| 66 |
elsif ($format eq 'win') |
| 67 |
{ |
| 68 |
print $output_handle "$1 @ $2\n"; |
| 69 |
} |
| 70 |
} |
| 71 |
else |
| 72 |
{ |
| 73 |
die "$0: unexpected line $_\n"; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
if ($format eq 'gnu') |
| 78 |
{ |
| 79 |
print $output_handle " local: *; |
| 80 |
}; |
| 81 |
"; |
| 82 |
} |