Commit | Line | Data |
---|---|---|
8736538c AS |
1 | # |
2 | # Perl script being a wrapper around the gnu ld. When a dll is specified to | |
3 | # to be built, special processing is done, else the standard ld is called. | |
4 | # | |
5 | ||
b53432e4 | 6 | # these are pretty mandatory |
8736538c | 7 | my $CC = '@CC@'; |
8736538c | 8 | my $EXPORT_ALL = @EXPORT_ALL@; |
b53432e4 | 9 | |
8736538c AS |
10 | # if some of extensions are undefined, |
11 | # no corresponding output will be done. | |
12 | # most probably, you'd like to have an export library | |
b53432e4 | 13 | # my $DEF_EXT = '@DEF_EXT@'; |
8736538c AS |
14 | # my $EXP_EXT = '@EXP_EXT@'; |
15 | my $LIB_EXT = '@LIB_EXT@'; | |
16 | ||
17 | #my $DEBUG ="perlld.out"; | |
18 | my $DEBUG =undef; | |
19 | ||
20 | my $args = join(" ",@ARGV); # get args | |
21 | my $verbose =grep(/^\-(v|\-verbose)$/, @ARGV); | |
22 | ||
23 | sub shellexec; | |
24 | ||
25 | if ($DEBUG) { | |
26 | open DEBUGFILE, ">>$DEBUG"; | |
27 | print DEBUGFILE "\n--- " .localtime() ."\nargs:\n$args\n\nenvironment:\n"; | |
28 | foreach (keys(%ENV)) { print DEBUGFILE $_, "=", $ENV{$_}, "\n"; }; | |
29 | } | |
30 | ||
31 | if ($args !~ /\-o (\S+)/) { | |
32 | print DEBUGFILE "+ no dll output -- passing to gcc\n\n" if $DEBUG; | |
33 | shellexec("$CC $args\n"); | |
34 | } else { | |
35 | my ($path, $command, $dllname, $libname) =''; | |
36 | ||
37 | $dllname =$1; | |
38 | print DEBUGFILE "output file: $dllname\n" if $DEBUG; | |
39 | # remove -o from args | |
40 | $args =~ s/(^| )\-o \S+/$1/; | |
41 | ||
42 | # Check for path: | |
43 | if( $dllname =~ /.*[\/\\]/){ | |
44 | $dllname = $'; | |
45 | $path = $&; | |
46 | $path =~ s,[/\\](\.[/\\])*,/,g; | |
47 | } | |
48 | if ($dllname =~ /\./) { $libname =$`; } else { $libname =$dllname; }; | |
b53432e4 GH |
49 | my $v_e_r_s = '5_7_2'; |
50 | if ( $dllname =~ /.*perl.*/) { | |
51 | $dllname ="cygperl$v_e_r_s.dll"; | |
52 | } else { | |
8736538c | 53 | $dllname ="$libname.dll"; |
b53432e4 | 54 | } |
8736538c AS |
55 | $libname ="lib$libname" unless ($libname =~ /^lib/); |
56 | print DEBUGFILE "dll name: $dllname\nimport library: $libname\npath: $path\n" if $DEBUG; | |
57 | ||
b53432e4 GH |
58 | $command ="$CC -shared -o $dllname"; |
59 | # $command .=" --verbose" if $verbose; | |
8736538c | 60 | |
b53432e4 GH |
61 | $command .=" -Wl,--output-def=$libname$DEF_EXT" if $DEF_EXT; |
62 | $command .=" -Wl,--output-exp=$libname$EXP_EXT" if $EXP_EXT; | |
63 | $command .=" -Wl,--out-implib=$libname.dll$LIB_EXT" if $LIB_EXT; | |
64 | $command .=" -Wl,--export-all-symbols" if $EXPORT_ALL; | |
65 | $command .=" -Wl,--enable-auto-import -Wl,--stack,67108864"; # always | |
8736538c AS |
66 | |
67 | # other args are passed through | |
68 | shellexec("$command \\\n$args\n"); | |
69 | ||
70 | if ($path) { | |
71 | $command ="mv $dllname"; | |
b53432e4 | 72 | $command .=" $libname.dll$LIB_EXT" if $LIB_EXT; |
8736538c AS |
73 | shellexec("$command $path\n"); |
74 | }; | |
75 | }; | |
76 | close DEBUGFILE if $DEBUG; | |
77 | ||
78 | #--------------------------------------------------------------------------- | |
79 | sub shellexec{ | |
80 | my $command =shift; | |
81 | print $command; | |
82 | print DEBUGFILE $command if $DEBUG; | |
83 | system($command) == 0 | |
84 | or die "perlld: *** system() failed to execute\n$command\n"; | |
85 | }; | |
86 | ||
87 | 1; |