1 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
2 & eval 'exec perl -S $0 $argv:q'
5 # Creates an ACE build tree in directory "build/<build name>" below the current
6 # directory, which must be an ACE "top level" directory (such as
7 # $ACE_ROOT). The build tree directory structure mirrors that of the ACE
8 # top level directory structure, except that instead of containing any plain
9 # files, it contains only symlinks to the files in the ACE top level structure.
11 # This program has a similar purpose to "clone", but in addition to
12 # only creating symlinks (clone creates hard links, by default), this
14 # 1) uses relative rather than absolute symlinks,
15 # 2) tries not to put junk files into the build tree,
16 # 3) only creates a new tree in a build/ directory below the current,
17 # top level ACE directory (it's a feature :-), but it does enforce
20 # This program can be re-run on a build tree at any time in order to
21 # update it. It will add symlinks for newly added files, and remove
22 # any that are no longer valid.
24 # If the <build name> starts with "build/", that part will be removed
27 # The first three lines above let this script run without specifying the
28 # full path to perl, as long as it is in the user's PATH.
29 # Taken from perlrun man page.
35 print "You should consider using clone_build_tree.pl found with MPC\n";
37 $usage = "usage: $0 -? | [-a] [-d <directory mode>] [-v] <build name>\n";
38 $directory_mode = 0777; #### Will be modified by umask, also.
44 $perl_version = $] + 0;
45 if ($perl_version >= 5) {
46 #### Use an eval so that this script will compile with perl4.
62 my($starting_dir) = cwd ();
64 my($build_re) = undef;
69 my($uif) = ($^O eq 'MSWin32' ? 'link' : 'symlink');
71 print "$uif $real $fake\n" if $verbose;
74 if ($^O eq 'MSWin32') {
76 $fixed =~ s/$build_re//;
77 push(@nlinks, $fixed);
79 chdir(dirname($fake));
80 $status = link ($real, basename($fake));
84 $status = symlink ($real, $fake);
87 warn "$0: $uif to $fake failed\n";
92 #### Process command line args.
94 while ($#ARGV >= 0 && $ARGV[0] =~ /^-/) {
95 if ($ARGV[0] eq '-v') {
97 } elsif ($ARGV[0] eq '-d') {
98 if ($ARGV[1] =~ /^\d+$/) {
99 $directory_mode = eval ($ARGV[1]); shift;
101 warn "$0: must provide argument for -d option\n";
104 } elsif ($ARGV[0] eq '-a') {
107 } elsif ($ARGV[0] eq '-?') {
111 warn "$0: unknown option $ARGV[0]\n";
117 die $usage unless $#ARGV == 0;
119 $build =~ s%^build[/\\]%%; #### remove leading "build/", if any
120 $build = "build/$build";
122 ## Set up the build regular expression use under MSWin32
123 if ($^O eq 'MSWin32') {
124 ## Get the original build name
127 ## Remove any trailing slashes
128 $build_re =~ s/[\\\/]+$//;
130 ## Add a single trailing slash
133 ## Escape any special characters
134 $build_re =~ s/([\\\$\[\]\(\)\.])/\\$1/g;
138 #### Check that we're in an ACE "top level" directory.
140 (-d 'ace' && -d 'include') ||
141 die "$0: must be in an ACE top level (ACE_ROOT) directory!\n";
144 #### Create build directories, if needed.
146 -d 'build' || mkdir ('build', $directory_mode);
147 -d "$build" || mkdir ("$build", $directory_mode);
150 #### Get all ACE plain file and directory names.
155 my ($dev,$ino,$mode,$nlink,$uid,$gid);
158 ($File::Find::prune = 1)
161 ($File::Find::prune = 1)
164 ($File::Find::prune = 1)
166 /^Templates\.DB\z/s &&
167 ($File::Find::prune = 1)
170 ($File::Find::prune = 1)
173 ($File::Find::prune = 1)
175 /^Static_Debug\z/s &&
176 ($File::Find::prune = 1)
178 /^Static_Release\z/s &&
179 ($File::Find::prune = 1)
182 ($nlink || (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_))) &&
196 push(@files, $File::Find::name);
199 File::Find::find({wanted => \&wanted}, '.');
202 #### Create directories and symlinks to files.
204 foreach $file (@files) {
205 $file =~ s%^./%%g; #### excise leading ./ directory component
208 unless (-d "$build/$file") {
209 print "mkdir $build/$file, $directory_mode\n" if $verbose;
210 mkdir ("$build/$file", $directory_mode);
213 unless (-e "$build/$file") {
216 while ($file =~ m%/%g) {
220 cab_link("$up/$file", "$build/$file");
222 $path = $source . '/' . $file;
223 cab_link("$path", "$build/$file");
230 #### Find all the symlinks in the build directory, and remove ones
231 #### that are no longer actually linked to a file.
234 if ($^O eq 'MSWin32') {
235 my($lfh) = new FileHandle();
236 my($txt) = "$build/create_ace_build.links";
237 if (open($lfh, "$txt")) {
242 push(@nlinks, $line);
245 print "Removing $build/$line \n" if $verbose;
246 unlink("$build/$line") || warn "$0: unlink of $build/$line failed\n";
252 ## Rewrite the link file.
254 if (open($lfh, ">$txt")) {
255 foreach my $file (@nlinks) {
256 print $lfh "$file\n";
265 ## There's no way to know if we have hard linked back to a now
266 ## non-existent file. So, just do the normal -l on the file
267 ## which will cause no files to be pushed on Windows.
269 push(@lfiles, $File::Find::name);
273 File::Find::find({wanted => \&lcheck}, $build);
278 print "Removing $_ \n" if $verbose;
279 unlink $_ || warn "$0: unlink of $_ failed\n";
285 #### Done: print message.
287 print "\nCompleted creation of $build/.\n";
289 if (! -e "$build/ace/config.h") {
290 $msg .= "$build/ace/config.h";
293 if ($^O ne 'MSWin32' &&
294 ! -e "$build/include/makeinclude/platform_macros.GNU") {
298 $msg .= "$build/include/makeinclude/platform_macros.GNU";
302 print "Be sure to setup $msg.\n";