7 # Build the libafs_tree by reading component list files in the src dir, and copying the
8 # listed files from the src and obj dirs into the libafs_tree directory.
10 # Dependent components are listed in file named "libafsdep" in each dir with dependencies.
23 while ( $_ = shift @ARGV )
25 if (m/^-t/) { $treedir = testArg( shift @ARGV ); next; }
26 if (m/^-p/) { $projdir = testArg( shift @ARGV ); next; }
27 if (m/^-sn/) { $sysname = testArg( shift @ARGV ); next; }
29 if (m/^-os/) { $ostype = testArg( shift @ARGV ); next; }
30 elsif (m/^-o/) { $objdir = testArg( shift @ARGV ); next; }
32 if (m/^-q/) { $quiet = 1; next; }
33 if (m/^-n/) { $showonly = 1; next; }
36 if ( !$treedir || !$projdir || !$ostype || !$sysname)
46 $quiet || print "libafs_tree_dir = $treedir\n";
47 $quiet || print "top_proj_dir = $projdir\n";
48 $quiet || print "top_obj_dir = $objdir\n";
50 my $qprojdir = quotemeta($projdir);
53 # Start with an empty dir
55 if ( -e $treedir && ! -d $treedir )
57 die "Ick. Destination is not a directory and already exists!\n";
61 #$quiet || print "Cleaning up previous tree build:\n";
62 #rmtree([$treedir],!$quiet,0);
63 #$quiet || print "Done.\n\n";
67 # Find all the dep list files in the src dir
69 finddepth(\&find_libafsdep, $projdir);
74 ©it("$projdir/configure-libafs", "$treedir/configure");
75 ©it("$projdir/Makefile-libafs.in", "$treedir/Makefile.in");
76 ©it("$projdir/src/libafs/MakefileProto.$ostype.in",
77 "$treedir/src/libafs/MakefileProto.in");
79 $showonly || system("$projdir/build-tools/git-version $projdir > $treedir/.version");
81 # We need to regenerate this to support building amd64 kernels from a
82 # libafs_tree built on i386.
83 unlink("$treedir/include/afs/param.h");
93 if ( $fname eq "libafsdep" )
95 &process_libafsdep($File::Find::dir, $fname);
101 my ($dir, $depname) = @_;
105 $subdir =~ s|^$qprojdir||o;
106 $subdir =~ s|^/||gio;
107 $subdir =~ s|/$||gio;
109 print "# $dir/$depname\n";
110 open(COMPS, "$depname");
111 while ( defined($file = <COMPS>) )
113 my ($destdir, $proj_src,$obj_src);
119 # do some simple substitution in dep file
121 $file =~ s/MKAFS_OSTYPE/$ostype/ge;
123 next if ( $file eq "" );
125 $proj_src = "$projdir/$subdir/$file";
126 $obj_src = "$objdir/$subdir/$file";
127 $proj_src =~ s|//+|/|gio;
128 $obj_src =~ s|//+|/|gio;
130 if ( $file !~ /\*/ && $file !~ /\[/ ) # no globs in filename
133 $fname =~ s|.*/||gio;
137 $destdir = mkfullpath($projdir, $proj_src, $treedir);
138 copyit($proj_src, "$destdir/$fname");
141 if ( $obj_src ne $proj_src && -f $obj_src)
143 $destdir = mkfullpath($objdir, $obj_src, $treedir);
144 copyit($obj_src, "$destdir/$fname");
149 #print "Globbing ($proj_src)\n";
150 foreach my $src ( glob($proj_src) )
153 $fname =~ s|.*/||gio;
155 $destdir = mkfullpath($projdir, $src, $treedir);
156 copyit($src, "$destdir/$fname");
158 #print "Globbing ($obj_src)\n";
159 foreach my $src ( glob($obj_src) )
162 $fname =~ s|.*/||gio;
164 $destdir = mkfullpath($objdir, $src, $treedir);
165 copyit($src, "$destdir/$fname");
171 $quiet || print "\n";
176 print "usage: $0 -p top_proj_dir -os mkafs_ostype -sn sysname\n";
177 print "\t\t[-o top_obj_dir] [-t libafs_tree_dir] [-h] [-q] [-n]\n";
178 print "\ttop_proj_dir = /path/to/openafs - top level of openafs checkout/tarball\n";
179 print "\ttop_obj_dir = /path/to/objdir - top level of build directory, defaults to top_proj_dir\n";
180 print "\tlibafs_tree_dir = /path/to/libafs_tree - tree dir to create, defaults to top_obj_dir/libafs_tree\n";
181 print "\t-os = ostype value (i.e. LINUX)\n";
182 print "\t-sn = afs sysname (i.e. i386_linux24)\n";
183 print "\t-q = quiet build\n";
184 print "\t-n = just show what will be done\n";
185 print "\t-h = show this message\n";
193 return $arg if ( $arg && $arg ne "" );
199 my ($frombase, $fromfile, $destbase) = @_;
200 my $qfrombase = quotemeta $frombase;
202 my $subdir = $fromfile;
203 $subdir =~ s|^$qfrombase||;
204 $subdir =~ s|^(.*)/(.*?)$|$1|o;
205 $subdir =~ s|^/||gio;
206 $subdir =~ s|/$||gio;
207 $subdir =~ s|//+|/|gio;
209 my $destdir = "$destbase/$subdir";
210 $destdir =~ s|/$||gio;
211 $destdir =~ s|//+|/|gio;
213 $showonly || mkpath([$destdir], !$quiet, 0755);
220 my ( $from, $to ) = @_;
228 if ( ($#to < 0) || ($from[7] != $to[7]) || ($from[9] != $to[9]) )
230 $quiet || print "+ cp -p $from $to\n";
231 $showonly || system( "cp", "-p", $from, $to );