This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate mainline
[perl5.git] / cygwin / perlld.in
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
7 my $CC = '@CC@';
8 my $DLLWRAP = '@DLLWRAP@';
9
10 # following are optional.
11 my $WRAPDRIVER = '@WRAPDRIVER@';
12 my $AS = '@AS@';
13 my $DLLTOOL = '@DLLTOOL@';
14 my $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
18 my $DEF_EXT = '@DEF_EXT@';
19 # my $EXP_EXT = '@EXP_EXT@';
20 my $LIB_EXT = '@LIB_EXT@';
21
22 #my $DEBUG ="perlld.out";
23 my $DEBUG =undef;
24
25 my $args = join(" ",@ARGV); # get args
26 my $verbose =grep(/^\-(v|\-verbose)$/, @ARGV);
27
28 sub shellexec;
29
30 if ($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
36 if ($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
58   $command ="$DLLWRAP --dllname $dllname";
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 };
78 close DEBUGFILE if $DEBUG;
79
80 #---------------------------------------------------------------------------
81 sub 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
89 1;