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.
6 # theese are pretty mandatory
8 my $DLLWRAP = 'dllwrap';
10 # following are optional.
11 my $WRAPDRIVER = 'gcc';
13 my $DLLTOOL = 'dlltool';
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
19 # my $EXP_EXT = '.exp';
22 #my $DEBUG ="perlld.out";
25 my $args = join(" ",@ARGV); # get args
26 my $verbose =grep(/^\-(v|\-verbose)$/, @ARGV);
31 open DEBUGFILE, ">>$DEBUG";
32 print DEBUGFILE "\n--- " .localtime() ."\nargs:\n$args\n\nenvironment:\n";
33 foreach (keys(%ENV)) { print DEBUGFILE $_, "=", $ENV{$_}, "\n"; };
36 if ($args !~ /\-o (\S+)/) {
37 print DEBUGFILE "+ no dll output -- passing to gcc\n\n" if $DEBUG;
38 shellexec("$CC $args\n");
40 my ($path, $command, $dllname, $libname) ='';
43 print DEBUGFILE "output file: $dllname\n" if $DEBUG;
45 $args =~ s/(^| )\-o \S+/$1/;
48 if( $dllname =~ /.*[\/\\]/){
51 $path =~ s,[/\\](\.[/\\])*,/,g;
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;
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;
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;
69 # other args are passed through
70 shellexec("$command \\\n$args\n");
73 $command ="mv $dllname";
74 $command .=" $libname$LIB_EXT" if $LIB_EXT;
75 shellexec("$command $path\n");
78 close DEBUGFILE if $DEBUG;
80 #---------------------------------------------------------------------------
84 print DEBUGFILE $command if $DEBUG;
86 or die "perlld: *** system() failed to execute\n$command\n";