2 eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
3 & eval 'exec perl -w -S $0 $argv:q'
6 # ******************************************************************
8 # Create Date: 3/09/2004
10 # ******************************************************************
12 # ******************************************************************
14 # ******************************************************************
22 # ******************************************************************
24 # ******************************************************************
28 my %defaults = ('header_files' => 1,
32 'template_files' => 1,
36 my %special = ('exe_output' => 1,
45 eval 'symlink("", "");';
46 my $hasSymlink = ($@
eq '');
48 # ******************************************************************
50 # ******************************************************************
54 my @parts = split(/[\/\\]/, $path);
56 ## Split the path into parts and check for '..'. If we find one
57 ## and the previous entry wasn't one, then we can remove them both.
58 for(my $i = 0; $i <= $#parts; $i++) {
59 if ($i > 0 && $parts[$i] eq '..' && $parts[$i - 1] ne '..') {
60 splice(@parts, $i - 1, 2);
64 return join('/', @parts);
68 my($files, $insdir, $symlink, $verbose) = @_;
69 my $type = ($symlink ?
'link' : 'copy');
72 foreach my $file (@
$files) {
73 my $dest = rm_updirs
($insdir . '/' .
74 (defined $actual{$file} ?
76 basename
($file) : $file));
77 my $fulldir = dirname
($dest);
80 foreach my $part (split(/[\/\\]/, $fulldir)) {
86 if (! -e
$dest || (-M
$file) < (-M
$dest)) {
88 print '', ($symlink ?
'Linking' : 'Copying'), " to $dest\n";
93 $status = symlink("$cwd/$file", $dest);
96 $status = copy
($file, $dest);
97 chmod(0755, $dest) if ($status && -x
$file);
100 print STDERR
"ERROR: Unable to $type $file to $dest\n";
107 print "Skipping $file\n" if ($verbose);
114 sub determineSpecialName
{
115 my($tag, $dir, $info) = @_;
117 my($insdir, $name) = split(/\s+/, $info);
126 my $odir = ($dir eq '' ?
'.' : $dir) . '/' . $insdir;
127 if ($tag eq 'exe_output') {
129 my $fh = new FileHandle
();
130 if (opendir($fh, $odir)) {
131 foreach my $file (grep(!/^\.\.?$/, readdir($fh))) {
132 if ($file =~ /^$name$/ ||
133 $file =~ /^$name.*\.exe$/i) {
134 push(@exes, "$dir$insdir$file");
141 elsif ($tag eq 'lib_output') {
143 my $fh = new FileHandle
();
144 if (opendir($fh, $odir)) {
145 foreach my $file (grep(!/^\.\.?$/, readdir($fh))) {
146 if ($file =~ /^lib$name\.(a|so|sl)/ ||
147 $file =~ /^(lib)?$name.*\.(dll|lib)$/i) {
148 push(@libs, "$dir$insdir$file");
160 sub replaceVariables
{
162 while($line =~ /(\$\(([^)]+)\))/) {
165 my $val = (defined $ENV{$name} ?
$ENV{$name} : '');
166 $line =~ s/\$\([^)]+\)/$val/;
173 my($files, $tags, $verbose) = @_;
174 my $fh = new FileHandle
();
177 foreach my $file (@
$files) {
178 if (open($fh, $file)) {
180 print "Loading $file\n";
182 my $base = dirname
($file);
187 $base =~ s/^\.[\/\\]+//;
198 if ($line =~ /^(\w+):$/) {
199 if (defined $$tags{$1}) {
206 elsif (defined $current) {
207 $line = replaceVariables
($line);
208 my $start = $#copy + 1;
209 if (defined $special{$current}) {
210 push(@copy, determineSpecialName
($current, $base, $line));
213 push(@copy, "$base$line");
215 if (defined $override{$current}) {
216 for(my $i = $start; $i <= $#copy; ++$i) {
217 $actual{$copy[$i]} = $override{$current};
220 elsif (defined $base{$current}) {
221 for(my $i = $start; $i <= $#copy; ++$i) {
222 $actual{$copy[$i]} = $base{$current} . '/' .
232 print STDERR
"Unable to open $file\n";
246 my $fh = new FileHandle
();
247 if (opendir($fh, $file)) {
248 foreach my $f (grep(!/^\.\.?$/, readdir($fh))) {
249 push(@files, getInsFiles
("$file/$f"));
254 elsif ($file =~ /\.$insext$/) {
264 print STDERR
"$msg\n" if (defined $msg);
266 my $base = basename
($0);
267 my $spc = ' ' x
(length($base) + 8);
268 print STDERR
"$base v$version\n",
269 "Usage: $base [-a tag1[,tagN]] [-b tag=dir] ",
270 ($hasSymlink ?
'[-l] ' : ''), "[-o tag=dir]\n",
271 $spc, "[-s tag1[,tagN]] [-v] [-k] [install directory]\n",
272 $spc, "[$insext files or directories]\n\n",
273 "Install files matching the tag specifications found ",
274 "in $insext files.\n\n",
275 "-a Adds to the default set of tags that get copied.\n",
276 "-b Install tag into dir underneath the install directory.\n",
277 "-k Keep going if a file to be copied is missing.\n",
278 ($hasSymlink ?
"-l Use symbolic links instead of copying.\n" : ''),
279 "-o Install tag into dir.\n",
280 "-s Sets the tags that get copied.\n",
281 "-v Enables verbose mode.\n",
283 "The default set of tags are:\n";
285 foreach my $key (sort keys %defaults) {
286 print STDERR
'', ($first ?
'' : ', '), $key;
294 # ******************************************************************
296 # ******************************************************************
303 my %tags = %defaults;
305 for(my $i = 0; $i <= $#ARGV; ++$i) {
310 if (defined $ARGV[$i]) {
311 foreach my $tag (split(',', $ARGV[$i])) {
316 usageAndExit
('-a requires a parameter.');
319 elsif ($arg eq '-b') {
321 if (defined $ARGV[$i]) {
322 if ($ARGV[$i] =~ /([^=]+)=(.*)/) {
326 usageAndExit
("Invalid parameter to -b: $ARGV[$i]");
330 usageAndExit
('-b requires a parameter.');
333 elsif ($arg eq '-k') {
336 elsif ($arg eq '-l') {
337 $symlink = $hasSymlink;
339 elsif ($arg eq '-o') {
341 if (defined $ARGV[$i]) {
342 if ($ARGV[$i] =~ /([^=]+)=(.*)/) {
346 usageAndExit
("Invalid parameter to -o: $ARGV[$i]");
350 usageAndExit
('-o requires a parameter.');
353 elsif ($arg eq '-s') {
355 if (defined $ARGV[$i]) {
357 foreach my $tag (split(',', $ARGV[$i])) {
362 usageAndExit
('-s requires a parameter.');
365 elsif ($arg eq '-v') {
369 usageAndExit
('Unkown option: ' . $arg);
372 elsif (!defined $insdir) {
380 print "Collecting $insext files...\n";
384 push(@insfiles, getInsFiles
($arg));
388 if (!defined $insdir) {
391 elsif (!defined $insfiles[0]) {
392 print "No $insext files were found.\n";
397 my @files = loadInsFiles
(\
@insfiles, \
%tags, $verbose);
398 if (defined $files[0]) {
399 $status = (copyFiles
(\
@files, $insdir, $symlink, $verbose) ?
0 : 1);