14a4f25f9Sdownsj# This will put installed perl files into some other location 24a4f25f9Sdownsj# Note that we cannot put hashbang to be extproc to make Configure work. 34a4f25f9Sdownsj 44a4f25f9Sdownsjuse Config; 5*09e75b67Smillertuse File::Compare; 64a4f25f9Sdownsj 74a4f25f9Sdownsj$dir = shift; 84a4f25f9Sdownsj$dir =~ s|/|\\|g ; 94a4f25f9Sdownsj$nowarn = 1, $dir = shift if $dir eq '-n'; 104a4f25f9Sdownsj 114a4f25f9Sdownsjdie <<EOU unless defined $dir and -d $dir; 124a4f25f9Sdownsjusage: $^X $0 [-n] directory-to-install 134a4f25f9Sdownsj -n do not check whether the directory is not on path 144a4f25f9SdownsjEOU 154a4f25f9Sdownsj 164a4f25f9Sdownsj@path = split /;/, $ENV{PATH}; 174a4f25f9Sdownsj$idir = $Config{installbin}; 184a4f25f9Sdownsj$indir =~ s|\\|/|g ; 194a4f25f9Sdownsj 20f64b279aSmillertmy %seen; 21f64b279aSmillert 22ba47ec9dSmillertforeach $file (<$idir/*>) { 23f64b279aSmillert next if $file =~ /\.(exe|bak)/i; 244a4f25f9Sdownsj $base = $file; 254a4f25f9Sdownsj $base =~ s/\.$//; # just in case... 264a4f25f9Sdownsj $base =~ s|.*/||; 27f64b279aSmillert $base =~ s|\.pl$||; 28f64b279aSmillert #$file =~ s|/|\\|g ; 29f64b279aSmillert warn "Clashing output name for $file, skipping" if $seen{$base}++; 30*09e75b67Smillert my $new = (-f "$dir/$base.cmd" ? '' : ' (new file)'); 31*09e75b67Smillert print "Processing $file => $dir/$base.cmd$new\n"; 32*09e75b67Smillert my $ext = ($new ? '.cmd' : '.tcm'); 33f64b279aSmillert open IN, '<', $file or warn, next; 34*09e75b67Smillert open OUT, '>', "$dir/$base$ext" or warn, next; 35f64b279aSmillert my $firstline = <IN>; 36f64b279aSmillert my $flags = ''; 37f64b279aSmillert $flags = $2 if $firstline =~ /^#!\s*(\S+)\s+-([^#]+?)\s*(#|$)/; 38f64b279aSmillert print OUT "extproc perl -S$flags\n$firstline"; 39f64b279aSmillert print OUT $_ while <IN>; 40f64b279aSmillert close IN or warn, next; 41f64b279aSmillert close OUT or warn, next; 42*09e75b67Smillert chmod 0444, "$dir/$base$ext"; 43*09e75b67Smillert next if $new; 44*09e75b67Smillert if (compare "$dir/$base$ext", "$dir/$base.cmd") { # different 45*09e75b67Smillert chmod 0666, "$dir/$base.cmd"; 46*09e75b67Smillert unlink "$dir/$base.cmd"; 47*09e75b67Smillert rename "$dir/$base$ext", "$dir/$base.cmd"; 48*09e75b67Smillert } else { 49*09e75b67Smillert chmod 0666, "$dir/$base$ext"; 50*09e75b67Smillert unlink "$dir/$base$ext"; 51*09e75b67Smillert print "...unchanged...\n"; 52*09e75b67Smillert } 534a4f25f9Sdownsj} 544a4f25f9Sdownsj 55