4 use File::Basename qw(&basename &dirname);
6 # List explicitly here the variables you want Configure to
7 # generate. Metaconfig only looks for shell variables, so you
8 # have to mention them as if they were shell variables, not
9 # %Config entries. Thus you write
11 # to ensure Configure will look for $Config{startperl}.
13 # This forces PL files to create target in same directory as PL file.
14 # This is so that make depend always knows where to find PL derivatives.
16 ($file = basename($0)) =~ s/\.PL$//;
18 if ($Config{'osname'} eq 'VMS' or
19 $Config{'osname'} eq 'OS2'); # "case-forgiving"
21 open OUT,">$file" or die "Can't create $file: $!";
23 print "Extracting $file (with variable substitutions)\n";
25 # In this section, perl variables will be expanded during extraction.
26 # You can use $Config{...} to use Configure variables.
28 print OUT <<"!GROK!THIS!";
30 eval 'exec perl -S \$0 "\$@"'
32 \$startperl = $Config{startperl};
35 # In the following, perl variables are not expanded during extraction.
37 print OUT <<'!NO!SUBS!';
39 # Modified September 26, 1993 to provide proper handling of years after 1999
40 # Tom Link <tml+@pitt.edu>
41 # University of Pittsburgh
43 while ($ARGV[0] =~ /^[^-!(]/) {
46 @roots = ('.') unless @roots;
47 for (@roots) { $_ = "e($_); }
48 $roots = join(',', @roots);
54 s/^-// || /^[()!]/ || die "Unrecognized switch: $_\n";
68 elsif ($_ eq 'name') {
70 $pat = &fileglob_to_re(shift);
71 $out .= '/' . $pat . "/";
73 elsif ($_ eq 'perm') {
75 die "Malformed -perm argument: $onum\n" unless $onum =~ /^-?[0-7]+$/;
76 if ($onum =~ s/^-//) {
77 $onum = '0' . sprintf("%o", oct($onum) & 017777); # s/b 07777 ?
78 $out .= &tab . "((\$mode & $onum) == $onum)";
81 $onum = '0' . $onum unless $onum =~ /^0/;
82 $out .= &tab . "((\$mode & 0777) == $onum)";
85 elsif ($_ eq 'type') {
86 ($filetest = shift) =~ tr/s/S/;
87 $out .= &tab . "-$filetest _";
89 elsif ($_ eq 'print') {
90 $out .= &tab . 'print("$name\n")';
92 elsif ($_ eq 'print0') {
93 $out .= &tab . 'print("$name\0")';
95 elsif ($_ eq 'fstype') {
99 { $out .= '($dev < 0)'; }
101 { $out .= '($dev >= 0)'; }
103 elsif ($_ eq 'user') {
105 $out .= &tab . "(\$uid == \$uid{'$uname'})";
108 elsif ($_ eq 'group') {
110 $out .= &tab . "(\$gid == \$gid{'$gname'})";
113 elsif ($_ eq 'nouser') {
114 $out .= &tab . '!defined $uid{$uid}';
117 elsif ($_ eq 'nogroup') {
118 $out .= &tab . '!defined $gid{$gid}';
121 elsif ($_ eq 'links') {
122 $out .= &tab . '($nlink ' . &n(shift);
124 elsif ($_ eq 'inum') {
125 $out .= &tab . '($ino ' . &n(shift);
127 elsif ($_ eq 'size') {
128 $out .= &tab . '(int(((-s _) + 511) / 512) ' . &n(shift);
130 elsif ($_ eq 'atime') {
131 $out .= &tab . '(int(-A _) ' . &n(shift);
133 elsif ($_ eq 'mtime') {
134 $out .= &tab . '(int(-M _) ' . &n(shift);
136 elsif ($_ eq 'ctime') {
137 $out .= &tab . '(int(-C _) ' . &n(shift);
139 elsif ($_ eq 'exec') {
140 for (@cmd = (); @ARGV && $ARGV[0] ne ';'; push(@cmd,shift)) { }
143 if (m#^(/bin/)?rm -f {}$#) {
145 $out .= &tab . 'unlink($_)';
148 $out .= &tab . '(unlink($_) || 1)';
151 elsif (m#^(/bin/)?rm {}$#) {
152 $out .= &tab . '(unlink($_) || warn "$name: $!\n")';
155 for (@cmd) { s/'/\\'/g; }
157 $out .= &tab . "&exec(0, '@cmd')";
163 for (@cmd = (); @ARGV && $ARGV[0] ne ';'; push(@cmd,shift)) { }
165 for (@cmd) { s/'/\\'/g; }
167 $out .= &tab . "&exec(1, '@cmd')";
171 elsif ($_ eq 'prune') {
172 $out .= &tab . '($prune = 1)';
174 elsif ($_ eq 'xdev') {
175 $out .= &tab . '!($prune |= ($dev != $topdev))';
177 elsif ($_ eq 'newer') {
180 $newername = 'AGE_OF' . $file;
181 $newername =~ s/[^\w]/_/g;
182 $newername = '$' . $newername;
183 $out .= "(-M _ < $newername)";
184 $initnewer .= "$newername = -M " . "e($file) . ";\n";
186 elsif ($_ eq 'eval') {
187 $prog = "e(shift);
188 $out .= &tab . "eval $prog";
190 elsif ($_ eq 'depth') {
195 $out .= &tab . "&ls";
198 elsif ($_ eq 'tar') {
200 die "-tar must have a filename argument\n" unless @ARGV;
206 $initfile .= "open($fh, " . "e($file) .
207 qq{) || die "Can't open $fh: \$!\\n";\n};
209 $flushall = "\n&tflushall;\n";
214 die "-$_ must have a filename argument\n" unless @ARGV;
218 $out .= "&cpio('" . substr($_,0,1) . "', $fh)";
220 $initfile .= "open($fh, " . "e($file) .
221 qq{) || die "Can't open $fh: \$!\\n";\n};
223 $flushall = "\n&flushall;\n";
226 die "Unrecognized switch: -$_\n";
229 if ($ARGV[0] eq '-o') {
230 { local($statdone) = 1; $out .= "\n" . &tab . "||\n"; }
231 $statdone = 0 if $indent == 1 && $delayedstat;
236 $out .= " &&" unless $ARGV[0] eq ')';
238 shift if $ARGV[0] eq '-a';
246 eval 'exec perl -S \$0 \${1+"\$@"}'
247 if \$running_under_some_shell;
253 @rwx = ('---','--x','-w-','-wx','r--','r-x','rw-','rwx');
254 @moname = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
259 if ($inituser || $initls) {
260 print 'while (($name, $pw, $uid) = getpwent) {', "\n";
261 print ' $uid{$name} = $uid{$uid} = $uid;', "\n" if $inituser;
262 print ' $user{$uid} = $name unless $user{$uid};', "\n" if $initls;
266 if ($initgroup || $initls) {
267 print 'while (($name, $pw, $gid) = getgrent) {', "\n";
268 print ' $gid{$name} = $gid{$gid} = $gid;', "\n" if $initgroup;
269 print ' $group{$gid} = $name unless $group{$gid};', "\n" if $initls;
273 print $initnewer, "\n" if $initnewer;
275 print $initfile, "\n" if $initfile;
277 $find = $depth ? "finddepth" : "find";
281 # Traverse desired filesystems
296 local($ok, @cmd) = @_;
297 foreach $word (@cmd) {
298 $word =~ s#{}#$name#g;
301 local($old) = select(STDOUT);
305 return 0 unless <STDIN> =~ /^y/;
319 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$sizemm,
320 $atime,$mtime,$ctime,$blksize,$blocks) = lstat(_);
324 if (defined $blocks) {
325 $blocks = int(($blocks + 1) / 2);
328 $blocks = int(($size + 1023) / 1024);
331 if (-f _) { $perms = '-'; }
332 elsif (-d _) { $perms = 'd'; }
333 elsif (-c _) { $perms = 'c'; $sizemm = &sizemm; }
334 elsif (-b _) { $perms = 'b'; $sizemm = &sizemm; }
335 elsif (-p _) { $perms = 'p'; }
336 elsif (-S _) { $perms = 's'; }
337 else { $perms = 'l'; $pname .= ' -> ' . readlink($_); }
340 $tmp = $rwx[$tmpmode & 7];
342 $tmp = $rwx[$tmpmode & 7] . $tmp;
344 $tmp = $rwx[$tmpmode & 7] . $tmp;
345 substr($tmp,2,1) =~ tr/-x/Ss/ if -u _;
346 substr($tmp,5,1) =~ tr/-x/Ss/ if -g _;
347 substr($tmp,8,1) =~ tr/-x/Tt/ if -k _;
350 $user = $user{$uid} || $uid;
351 $group = $group{$gid} || $gid;
353 ($sec,$min,$hour,$mday,$mon,$year) = localtime($mtime);
354 $moname = $moname[$mon];
355 if (-M _ > 365.25 / 2) {
356 $timeyear = $year + 1900;
359 $timeyear = sprintf("%02d:%02d", $hour, $min);
362 printf "%5lu %4ld %-10s %2d %-8s %-8s %8s %s %2d %5s %s\n",
378 sprintf("%3d, %3d", ($rdev >> 8) & 255, $rdev & 255);
390 if ($name eq 'TRAILER!!!') {
395 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
396 $atime,$mtime,$ctime,$blksize,$blocks) = lstat(_);
398 open(IN, "./$_\0") || do {
399 warn "Couldn't open $name: $!\n";
404 $text = readlink($_);
405 $size = 0 unless defined $text;
409 ($nm = $name) =~ s#^\./##;
413 sprintf("%06o%06o%06o%06o%06o%06o%06o%06o%011lo%06o%011lo%s\0",
428 $cpout{$fh} .= "\0" if length($cpout{$fh}) & 1;
429 $cpout{$fh} .= pack("SSSSSSSSLSLa*",
430 070707, $dev, $ino, $mode, $uid, $gid, $nlink, $rdev, $mtime,
431 length($nm)+1, $size, $nm . (length($nm) & 1 ? "\0" : "\0\0"));
434 $cpout{$fh} .= $text;
437 &flush($fh) while ($l = length($cpout{$fh})) >= 5120;
438 while (sysread(IN, $cpout{$fh}, 5120 - $l, $l)) {
440 $l = length($cpout{$fh});
449 while (length($cpout{$fh}) >= 5120) {
450 syswrite($fh,$cpout{$fh},5120);
452 substr($cpout{$fh}, 0, 5120) = '';
457 $name = 'TRAILER!!!';
458 foreach $fh (keys %cpout) {
460 $cpout{$fh} .= "0" x (5120 - length($cpout{$fh}));
462 print $blocks{$fh} * 10, " blocks\n";
473 local($linkname,$header,$l,$slop);
474 local($linkflag) = "\0";
476 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
477 $atime,$mtime,$ctime,$blksize,$blocks) = lstat(_);
480 if ($linkname = $linkseen{$fh,$dev,$ino}) {
484 $linkseen{$fh,$dev,$ino} = $nm;
488 open(IN, "./$_\0") || do {
489 warn "Couldn't open $name: $!\n";
492 $size = 0 if $linkflag ne "\0";
495 $linkname = readlink($_);
496 $linkflag = 2 if defined $linkname;
501 $header = pack("a100a8a8a8a12a12a8a1a100",
503 sprintf("%6o ", $mode & 0777),
504 sprintf("%6o ", $uid & 0777777),
505 sprintf("%6o ", $gid & 0777777),
506 sprintf("%11o ", $size),
507 sprintf("%11o ", $mtime),
511 $l = length($header) % 512;
512 substr($header, 148, 6) = sprintf("%6o", unpack("%16C*", $header));
513 substr($header, 154, 1) = "\0"; # blech
514 $tarout{$fh} .= $header;
515 $tarout{$fh} .= "\0" x (512 - $l) if $l;
517 &tflush($fh) while ($l = length($tarout{$fh})) >= 10240;
518 while (sysread(IN, $tarout{$fh}, 10240 - $l, $l)) {
519 $slop = length($tarout{$fh}) % 512;
520 $tarout{$fh} .= "\0" x (512 - $slop) if $slop;
522 $l = length($tarout{$fh});
531 while (length($tarout{$fh}) >= 10240) {
532 syswrite($fh,$tarout{$fh},10240);
534 substr($tarout{$fh}, 0, 10240) = '';
541 foreach $fh (keys %tarout) {
542 $len = 10240 - length($tarout{$fh});
543 $len += 10240 if $len < 1024;
544 $tarout{$fh} .= "\0" x $len;
554 ############################################################################
559 $tabstring = "\t" x ($indent / 2) . ' ' x ($indent % 2 * 4);
561 if ($_ =~ /^(name|print|prune|exec|ok|\(|\))/) {
566 $tabstring .= <<'ENDOFSTAT' . $tabstring;
567 ($nlink || (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_))) &&
571 $tabstring .= <<'ENDOFSTAT' . $tabstring;
572 (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
578 $tabstring =~ s/^\s+/ / if $out =~ /!$/;
585 $tmp =~ s#([./^\$()])#\\$1#g;
586 $tmp =~ s/([?*])/.$1/g;
593 $n =~ s/^-/< / || $n =~ s/^\+/> / || $n =~ s/^/== /;
594 $n =~ s/ 0*(\d)/ $1/;
605 close OUT or die "Can't close $file: $!";
606 chmod 0755, $file or die "Can't reset permissions for $file: $!\n";
607 exec("$Config{'eunicefix'} $file") if $Config{'eunicefix'} ne ':';