summaryrefslogtreecommitdiff
path: root/ACE/bin/create_ace_build
blob: 273342bbd50caad27cabec326aecd101463892d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
    & eval 'exec perl -S $0 $argv:q'
    if 0;

# $Id$
#
# Creates an ACE build tree in directory "build/<build name>" below the current
# directory, which must be an ACE "top level" directory (such as
# $ACE_ROOT).  The build tree directory structure mirrors that of the ACE
# top level directory structure, except that instead of containing any plain
# files, it contains only symlinks to the files in the ACE top level structure.
#
# This program has a similar purpose to "clone", but in addition to
# only creating symlinks (clone creates hard links, by default), this
# script:
# 1) uses relative rather than absolute symlinks,
# 2) tries not to put junk files into the build tree,
# 3) only creates a new tree in a build/ directory below the current,
#    top level ACE directory (it's a feature :-), but it does enforce
#    consistency).
#
# This program can be re-run on a build tree at any time in order to
# update it.  It will add symlinks for newly added files, and remove
# any that are no longer valid.
#
# If the <build name> starts with "build/", that part will be removed
# from it.
#
# The first three lines above let this script run without specifying the
# full path to perl, as long as it is in the user's PATH.
# Taken from perlrun man page.

use File::Find ();
use File::Basename;
use FileHandle;

print "You should consider using clone_build_tree.pl found with MPC\n";

$usage = "usage: $0 -? | [-a] [-d <directory mode>] [-v] <build name>\n";
$directory_mode = 0777;   #### Will be modified by umask, also.
$verbose = 0;

$source='.';
$absolute= 0;

$perl_version = $] + 0;
if ($perl_version >= 5) {
  #### Use an eval so that this script will compile with perl4.
  eval <<'PERL5_CWD'
  require Cwd;
  sub cwd {
    Cwd::getcwd ();
  }
PERL5_CWD
} else {
  sub cwd {
    local ($pwd);

    chop ($pwd = `pwd`);
    $pwd;
  }
}

my($starting_dir) = cwd ();
my(@nlinks)       = ();
my($build_re)     = undef;

sub cab_link {
  my($real) = shift;
  my($fake) = shift;
  my($uif)  = ($^O eq 'MSWin32' ? 'link' : 'symlink');

  print "$uif $real $fake\n" if $verbose;

  my($status) = 0;
  if ($^O eq 'MSWin32') {
    my($fixed) = $fake;
    $fixed =~ s/$build_re//;
    push(@nlinks, $fixed);

    chdir(dirname($fake));
    $status = link ($real, basename($fake));
    chdir($starting_dir);
  }
  else {
    $status = symlink ($real, $fake);
  }
  if (!$status) {
    warn "$0: $uif to $fake failed\n";
  }
}

####
#### Process command line args.
####
while ($#ARGV >= 0  &&  $ARGV[0] =~ /^-/) {
  if ($ARGV[0] eq '-v') {
    $verbose = 1;
  } elsif ($ARGV[0] eq '-d') {
    if ($ARGV[1] =~ /^\d+$/) {
      $directory_mode = eval ($ARGV[1]); shift;
    } else {
      warn "$0:  must provide argument for -d option\n";
      die $usage;
    }
  } elsif ($ARGV[0] eq '-a') {
    $source = &cwd ();
    $absolute = 1;
  } elsif ($ARGV[0] eq '-?') {
    print "$usage";
    exit;
  } else {
    warn "$0:  unknown option $ARGV[0]\n";
    die $usage;
  }
  shift;
}

die $usage unless $#ARGV == 0;
$build = $ARGV[0];
$build =~ s%^build[/\\]%%;        #### remove leading "build/", if any
$build = "build/$build";

## Set up the build regular expression use under MSWin32
if ($^O eq 'MSWin32') {
  ## Get the original build name
  $build_re = $build;

  ## Remove any trailing slashes
  $build_re =~ s/[\\\/]+$//;

  ## Add a single trailing slash
  $build_re .= '/';

  ## Escape any special characters
  $build_re =~ s/([\\\$\[\]\(\)\.])/\\$1/g;
}

####
#### Check that we're in an ACE "top level" directory.
####
(-d 'ace' && -d 'include')  ||
  die "$0:  must be in an ACE top level (ACE_ROOT) directory!\n";

####
#### Create build directories, if needed.
####
-d 'build'  ||  mkdir ('build', $directory_mode);
-d "$build"  ||  mkdir ("$build", $directory_mode);

####
#### Get all ACE plain file and directory names.
####
@files = ();

sub wanted {
    my ($dev,$ino,$mode,$nlink,$uid,$gid);

    /^CVS\z/s &&
    ($File::Find::prune = 1)
    ||
    /^build\z/s &&
    ($File::Find::prune = 1)
    ||
    /^\..*obj\z/s &&
    ($File::Find::prune = 1)
    ||
    /^Templates\.DB\z/s &&
    ($File::Find::prune = 1)
    ||
    /^Debug\z/s &&
    ($File::Find::prune = 1)
    ||
    /^Release\z/s &&
    ($File::Find::prune = 1)
    ||
    /^Static_Debug\z/s &&
    ($File::Find::prune = 1)
    ||
    /^Static_Release\z/s &&
    ($File::Find::prune = 1)
    ||
    ( 
        ($nlink || (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_))) &&
        ! -l $_ &&
        ! /^core\z/s &&
        ! /^.*\.state\z/s &&
        ! /^.*\.so\z/s &&   
        ! /^.*\.[oa]\z/s && 
        ! /^.*\.dll\z/s &&   
        ! /^.*\.lib\z/s && 
        ! /^.*\.obj\z/s && 
        ! /^.*~\z/s &&
        ! /^\.\z/s && 
        ! /^\.#.*\z/s &&
        ! /^.*\.log\z/s 
    ) &&
    push(@files, $File::Find::name);
}

File::Find::find({wanted => \&wanted}, '.');

####
#### Create directories and symlinks to files.
####
foreach $file (@files) {
  $file =~ s%^./%%g;  #### excise leading ./ directory component

  if (-d $file) {
     unless (-d "$build/$file") {
       print "mkdir $build/$file, $directory_mode\n" if $verbose;
       mkdir ("$build/$file", $directory_mode);
     }
  } else {
    unless (-e "$build/$file") {
      if (!$absolute) {
        $up = '../..';
        while ($file =~ m%/%g) {
          $up .= '/..';
        }

        cab_link("$up/$file", "$build/$file");
      } else {
        $path = $source . '/' . $file;
        cab_link("$path", "$build/$file");
      }
    }
  }
}

####
#### Find all the symlinks in the build directory, and remove ones
#### that are no longer actually linked to a file.
####

if ($^O eq 'MSWin32') {
  my($lfh) = new FileHandle();
  my($txt) = "$build/create_ace_build.links";
  if (open($lfh, "$txt")) {
    while(<$lfh>) {
      my($line) = $_;
      $line =~ s/\s+$//;
      if (-e $line) {
        push(@nlinks, $line);
      }
      else {
        print "Removing $build/$line \n" if $verbose;
        unlink("$build/$line") || warn "$0: unlink of $build/$line failed\n";
      }
    }
    close($lfh);
  }

  ## Rewrite the link file.
  unlink($txt);
  if (open($lfh, ">$txt")) {
    foreach my $file (@nlinks) {
      print $lfh "$file\n";
    }
    close($lfh);
  }
}
else {
  @lfiles = ();

  sub lcheck {
    ## There's no way to know if we have hard linked back to a now
    ## non-existent file.  So, just do the normal -l on the file
    ## which will cause no files to be pushed on Windows.
    if (-l $_) {
      push(@lfiles, $File::Find::name);
    }
  }

  File::Find::find({wanted => \&lcheck}, $build);

  foreach (@lfiles) {
    local @s = stat $_;
    if ($#s == -1) {
      print "Removing $_ \n" if $verbose;
      unlink $_  ||  warn "$0: unlink of $_ failed\n";
    }
  }
}

####
#### Done: print message.
####
print "\nCompleted creation of $build/.\n";
my($msg) = '';
if (! -e "$build/ace/config.h") {
  $msg .= "$build/ace/config.h";
}

if ($^O ne 'MSWin32' &&
    ! -e "$build/include/makeinclude/platform_macros.GNU") {
  if ($msg ne '') {
    $msg .= " and\n";
  }
  $msg .= "$build/include/makeinclude/platform_macros.GNU";
}

if ($msg ne '') {
  print "Be sure to setup $msg.\n";
}

#### EOF