Installer: Early check whether the installation directory is writable
[msysgit.git] / bin / perlld
blob2074c53afc7c68afc371a161df7b70f4f6f660c4
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 # these are pretty mandatory
7 my $CC = 'gcc';
8 my $EXPORT_ALL = 1;
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
13 # my $DEF_EXT = '.def';
14 # my $EXP_EXT = '.exp';
15 my $LIB_EXT = '.a';
17 #my $DEBUG ="perlld.out";
18 my $DEBUG =undef;
20 my $args = join(" ",@ARGV); # get args
21 my $verbose =grep(/^\-(v|\-verbose)$/, @ARGV);
23 sub shellexec;
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"; };
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) ='';
37   $dllname =$1;
38   print DEBUGFILE "output file: $dllname\n" if $DEBUG;
39   # remove -o from args
40   $args =~ s/(^| )\-o \S+/$1/;
42   # Check for path:
43   if( $dllname =~ /.*[\/\\]/){
44     $dllname = $';
45     $path = $&;
46     $path =~ s,[/\\](\.[/\\])*,/,g;
47   }
48   if ($dllname =~ /\./) { $libname =$`; } else { $libname =$dllname; };
49   my $v_e_r_s = substr("5.6.1",0,-2);
50   $v_e_r_s =~ tr/./_/;
51   if ( $dllname =~ /libperl.*/) {
52     $dllname ="msys-perl$v_e_r_s.dll";
53   } else {
54     $dllname ="$libname.dll";
55   }
56   $libname ="lib$libname" unless ($libname =~ /^lib/);
57   print DEBUGFILE "dll name: $dllname\nimport library: $libname\npath: $path\n" if $DEBUG;
59   $command ="$CC -shared -o $dllname";
60 #  $command .=" --verbose" if $verbose;
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,8388608"; # always
66   $command .=" -Wl,--enable-auto-image-base"; # always
68   # other args are passed through
69   shellexec("$command \\\n$args\n");
71   if ($path) {
72     $command ="mv $dllname";
73     $command .=" $libname.dll$LIB_EXT" if $LIB_EXT;
74     shellexec("$command $path\n");
75   };
77 close DEBUGFILE if $DEBUG;
79 #---------------------------------------------------------------------------
80 sub shellexec {
81   my $command = shift;
82   print STDERR $command;
83   print DEBUGFILE $command if $DEBUG;
84   system($command) == 0
85     or die "perlld: *** system() failed to execute\n$command\n";