| 1 | #!/usr/bin/perl | ||||||||||||||
| 2 | |||||||||||||||
| 3 | =head1 Progcopy.PL | ||||||||||||||
| 4 | |||||||||||||||
| 5 | I like to keep my perl programs in files named C<*.pl> since this | ||||||||||||||
| 6 | makes it easy to find and work with them. However it is better to | ||||||||||||||
| 7 | install them as normal programs. This does that. | ||||||||||||||
| 8 | |||||||||||||||
| 9 | The other key thing this does is sets up the scripts to call the perl | ||||||||||||||
| 10 | interpreter correctly. I really needed this since I was working with | ||||||||||||||
| 11 | self compiled versions of perl in my home directory and not wanting to | ||||||||||||||
| 12 | disturb the main installation | ||||||||||||||
| 13 | |||||||||||||||
| 14 | This ought to be possible through standard Makefile.PL, but I don't | ||||||||||||||
| 15 | know how. | ||||||||||||||
| 16 | |||||||||||||||
| 17 | I also set this up to install the documentation appropriately. | ||||||||||||||
| 18 | |||||||||||||||
| 19 | =cut | ||||||||||||||
| 20 | |||||||||||||||
| 21 | 1 | ▶ | use File::Find; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 22 | 1 | ▶ | use Config; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 23 | 1 | ▶ | use Cwd; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 24 | |||||||||||||||
| 25 | 1 | $File::Find::dont_use_nlink=1; # I had problems | |||||||||||||
| 26 | |||||||||||||||
| 27 | 1 | my $perlint=$Config{"startperl"}; | |||||||||||||
| 28 | 1 | ▶ | die "can't find out how to start interpreter" unless $perlint; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 29 | |||||||||||||||
| 30 | 1 | my $target_dir = "blib/script"; | |||||||||||||
| 31 | 1 | my $man_dir = "blib/man1"; | |||||||||||||
| 32 | 1 | ▶ | die "no blib to install into" unless -d "blib"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 33 | 1 | ▶ | mkdir $target_dir, 0750 unless -e $target_dir; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 34 | 1 | ▶ | die "$target_dir is not a directory" unless -d $target_dir; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 35 | 1 | $target_dir = cwd() . '/' . $target_dir . '/'; #so we can find it later | |||||||||||||
| 36 | 1 | ▶ | mkdir $man_dir, 0750 unless -e $man_dir; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | 1 | ▶ | die "$man_dir is not a directory" unless -d $man_dir; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 38 | 1 | $man_dir = cwd() . '/' . $man_dir . '/'; #so we can find it later | |||||||||||||
| 39 | |||||||||||||||
| 40 | 171 | ▶ | sub work { | ||||||||||||
|
Subroutine
work: called CC=11 SCAR=33.0
| |||||||||||||||
| 41 | 171 | ▶ | -d && do { m/^((docs)|(blib)|(old)|(t))$/ and $File::Find::prune = 1; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 42 | 43 | return; }; | |||||||||||||
| 43 | 128 | ▶ | return unless m/^[^.].*.pl$/; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 44 | 15 | ▶ | return if m/test-tmp/; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 45 | 15 | my $save=$_; | |||||||||||||
| 46 | 15 | ($name=$_) =~ s/.pl$//; | |||||||||||||
| 47 | 15 | my $target=$target_dir . $name; | |||||||||||||
| 48 | |||||||||||||||
| 49 | 15 | ▶ | if (-e $target) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 50 | 15 | my @origstat=stat $_; | |||||||||||||
| 51 | 15 | my @targetstat=stat $target; | |||||||||||||
| 52 | 15 | ▶ | if ($targetstat[9] > $origstat[9]) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | 15 | print STDERR "$target up to date.. ignoring\n"; | |||||||||||||
| 54 | 15 | return; | |||||||||||||
| 55 | } | ||||||||||||||
| 56 | } | ||||||||||||||
| 57 | |||||||||||||||
| 58 | 0 | print STDERR ( "copying " . cwd() . '/' . $_ | |||||||||||||
| 59 | . " to " . $target . "\n"); | ||||||||||||||
| 60 | 0 | ▶ | open (INFILE, "<" . $_) or die "failed to open to read $_"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 61 | 0 | ▶ | open (OUTFILE, ">" . $target) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | or die "failed to open $target_dir$name to write"; | ||||||||||||||
| 63 | 0 | $_ = <INFILE>; | |||||||||||||
| 64 | 0 | ▶ | s/#!\S*perl/$perlint/ or print OUTFILE $perlint, "\n"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 65 | |||||||||||||||
| 66 | 0 | print OUTFILE $_; | |||||||||||||
| 67 | 0 | ▶ | while (<INFILE>) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 68 | 0 | print OUTFILE $_; | |||||||||||||
| 69 | } | ||||||||||||||
| 70 | 0 | close INFILE; | |||||||||||||
| 71 | 0 | close OUTFILE; | |||||||||||||
| 72 | 0 | chmod 0755, $target; #FIXME... what if they don't want | |||||||||||||
| 73 | 0 | system "pod2man $name.pl > $man_dir$name.1"; | |||||||||||||
| 74 | 0 | $_=$save; | |||||||||||||
| 75 | } | ||||||||||||||
| 76 | |||||||||||||||
| 77 | 1 | find(\&work, '.' ); | |||||||||||||
| 78 | |||||||||||||||
| 79 | |||||||||||||||