X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/aa6893958c2bfb6fa4ab923c8466c188c65748fd..1b92e6949b737e92f61827f9c92afce9218e30ba:/os2/perl2cmd.pl diff --git a/os2/perl2cmd.pl b/os2/perl2cmd.pl index e774f77..07529ad 100644 --- a/os2/perl2cmd.pl +++ b/os2/perl2cmd.pl @@ -2,6 +2,7 @@ # Note that we cannot put hashbang to be extproc to make Configure work. use Config; +use File::Compare; $dir = shift; $dir =~ s|/|\\|g ; @@ -16,14 +17,38 @@ EOU $idir = $Config{installbin}; $indir =~ s|\\|/|g ; +my %seen; + foreach $file (<$idir/*>) { - next if $file =~ /\.exe/i; + next if $file =~ /\.(exe|bak)/i; $base = $file; $base =~ s/\.$//; # just in case... $base =~ s|.*/||; - $file =~ s|/|\\|g ; - print "Processing $file => $dir\\$base.cmd\n"; - system 'cmd.exe', '/c', "echo extproc perl -S >$dir\\$base.cmd"; - system 'cmd.exe', '/c', "type $file >> $dir\\$base.cmd"; + $base =~ s|\.pl$||; + #$file =~ s|/|\\|g ; + warn "Clashing output name for $file, skipping" if $seen{$base}++; + my $new = (-f "$dir/$base.cmd" ? '' : ' (new file)'); + print "Processing $file => $dir/$base.cmd$new\n"; + my $ext = ($new ? '.cmd' : '.tcm'); + open IN, '<', $file or warn, next; + open OUT, '>', "$dir/$base$ext" or warn, next; + my $firstline = ; + my $flags = ''; + $flags = $2 if $firstline =~ /^#!\s*(\S+)\s+-([^#]+?)\s*(#|$)/; + print OUT "extproc perl -S$flags\n$firstline"; + print OUT $_ while ; + close IN or warn, next; + close OUT or warn, next; + chmod 0444, "$dir/$base$ext"; + next if $new; + if (compare "$dir/$base$ext", "$dir/$base.cmd") { # different + chmod 0666, "$dir/$base.cmd"; + unlink "$dir/$base.cmd"; + rename "$dir/$base$ext", "$dir/$base.cmd"; + } else { + chmod 0666, "$dir/$base$ext"; + unlink "$dir/$base$ext"; + print "...unchanged...\n"; + } }