Use fork if available.
[p5sagit/p5-mst-13.2.git] / installman
old mode 100644 (file)
new mode 100755 (executable)
index f184fd5..6c99682
@@ -27,6 +27,7 @@ $usage =
 
 GetOptions( qw( man1dir=s man1ext=s man3dir=s man3ext=s notify help)) 
        || die $usage;
+die $usage if $opt_help;
 
 # These are written funny to avoid -w typo warnings.
 $man1dir = defined($opt_man1dir) ? $opt_man1dir : $Config{'installman1dir'};
@@ -64,8 +65,16 @@ sub runpod2man {
 
     # We insist on using the current version of pod2man in case there
     # are enhancements or changes from previous installed versions.
-    $pod2man = "../pod/pod2man";
-    -x  $pod2man       || die "Executable $pod2man not found.\n";
+    # The error message doesn't include the '..' because the user
+    # won't be aware that we've chdir to $poddir.
+    -x  "../pod/pod2man" || die "Executable pod/pod2man not found.\n";
+
+    # We want to be sure to use the current perl.  We can't rely on
+    # the installed perl because it might not be actually installed
+    # yet. (The user may have set the $install* Configure variables 
+    # to point to some temporary home, from which the executable gets
+    # installed by occult means.)
+    $pod2man = "../perl -I ../lib ../pod/pod2man --section=$manext --official";
 
     &makedir($mandir);
     # Make a list of all the .pm and .pod files in the directory.  We will
@@ -80,8 +89,13 @@ sub runpod2man {
        $manpage =~ s#\.p(m|od)$##;
        $manpage =~ s#/#::#g;
        $manpage = "${mandir}/${manpage}.${manext}";
-       # Print $release $patchlevel stuff?  or should pod2man do that?
        &cmd("$pod2man $mod > $manpage");
+       if (-z $manpage) {
+           print STDERR "unlink $manpage\n";
+           unless ($notify) {
+               unlink($manpage) || warn "cannot unlink $manpage: $!";
+           } 
+       } 
     }
     chdir "$builddir" || die "Unable to cd back to $builddir directory!\n$!\n";
 }
@@ -107,9 +121,15 @@ sub cmd {
     local($cmd) = @_;
     print STDERR "  $cmd\n";
     unless ($notify) {
-       system $cmd;
-       warn "Command failed!!!\n" if $?;
+       if ($Config{d_fork}) {
+           fork ? wait : exec $cmd;  # Allow user to ^C out of command.
+       }
+       else {
+           system $cmd;
+       }
+       warn "Command failed!!\n" if $?;
     }
+    return $? != 0;
 }
 
 sub link {