This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Resync with mainline
[perl5.git] / cygwin / perlld.in
CommitLineData
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
6# theese are pretty mandatory
7my $CC = '@CC@';
8my $DLLWRAP = '@DLLWRAP@';
9
10# following are optional.
11my $WRAPDRIVER = '@WRAPDRIVER@';
12my $AS = '@AS@';
13my $DLLTOOL = '@DLLTOOL@';
14my $EXPORT_ALL = @EXPORT_ALL@;
15# if some of extensions are undefined,
16# no corresponding output will be done.
17# most probably, you'd like to have an export library
18my $DEF_EXT = '@DEF_EXT@';
19# my $EXP_EXT = '@EXP_EXT@';
20my $LIB_EXT = '@LIB_EXT@';
21
22#my $DEBUG ="perlld.out";
23my $DEBUG =undef;
24
25my $args = join(" ",@ARGV); # get args
26my $verbose =grep(/^\-(v|\-verbose)$/, @ARGV);
27
28sub shellexec;
29
30if ($DEBUG) {
31 open DEBUGFILE, ">>$DEBUG";
32 print DEBUGFILE "\n--- " .localtime() ."\nargs:\n$args\n\nenvironment:\n";
33 foreach (keys(%ENV)) { print DEBUGFILE $_, "=", $ENV{$_}, "\n"; };
34}
35
36if ($args !~ /\-o (\S+)/) {
37 print DEBUGFILE "+ no dll output -- passing to gcc\n\n" if $DEBUG;
38 shellexec("$CC $args\n");
39} else {
40 my ($path, $command, $dllname, $libname) ='';
41
42 $dllname =$1;
43 print DEBUGFILE "output file: $dllname\n" if $DEBUG;
44 # remove -o from args
45 $args =~ s/(^| )\-o \S+/$1/;
46
47 # Check for path:
48 if( $dllname =~ /.*[\/\\]/){
49 $dllname = $';
50 $path = $&;
51 $path =~ s,[/\\](\.[/\\])*,/,g;
52 }
53 if ($dllname =~ /\./) { $libname =$`; } else { $libname =$dllname; };
54 $dllname ="$libname.dll";
55 $libname ="lib$libname" unless ($libname =~ /^lib/);
56 print DEBUGFILE "dll name: $dllname\nimport library: $libname\npath: $path\n" if $DEBUG;
57
f89d6eaa 58 $command ="$DLLWRAP --dllname $dllname";
8736538c
AS
59 $command .=" --driver-name $WRAPDRIVER" if $WRAPDRIVER;
60 $command .=" --dlltool $DLLTOOL" if $DLLTOOL;
61 $command .=" --export-all-symbols" if $EXPORT_ALL;
62 $command .=" --as $AS" if $AS;
63 $command .=" --verbose" if $verbose;
64
65 $command .=" --output-def $libname$DEF_EXT" if $DEF_EXT;
66 $command .=" --output-exp $libname$EXP_EXT" if $EXP_EXT;
67 $command .=" --output-lib $libname$LIB_EXT" if $LIB_EXT;
68
69 # other args are passed through
70 shellexec("$command \\\n$args\n");
71
72 if ($path) {
73 $command ="mv $dllname";
74 $command .=" $libname$LIB_EXT" if $LIB_EXT;
75 shellexec("$command $path\n");
76 };
77};
78close DEBUGFILE if $DEBUG;
79
80#---------------------------------------------------------------------------
81sub shellexec{
82 my $command =shift;
83 print $command;
84 print DEBUGFILE $command if $DEBUG;
85 system($command) == 0
86 or die "perlld: *** system() failed to execute\n$command\n";
87};
88
891;