| 392 |
dpurdie |
1 |
#! perl
|
|
|
2 |
########################################################################
|
| 7300 |
dpurdie |
3 |
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
|
| 392 |
dpurdie |
4 |
#
|
|
|
5 |
# Module name : jats.sh
|
|
|
6 |
# Module type : Makefile system
|
|
|
7 |
# Compiler(s) : n/a
|
|
|
8 |
# Environment(s): jats
|
|
|
9 |
#
|
|
|
10 |
# Description : This file contains a single function
|
|
|
11 |
# A play thing at the moment.
|
|
|
12 |
#
|
|
|
13 |
# The use of this function does require that the "Common.pl"
|
|
|
14 |
# has been initialised.
|
|
|
15 |
#
|
|
|
16 |
# Include in a makefile.pl with
|
|
|
17 |
# require "$::GBE_TOOLS/LocateFiles.pl";
|
|
|
18 |
#
|
|
|
19 |
# Usage:
|
|
|
20 |
#
|
|
|
21 |
# Version Who Date Description
|
|
|
22 |
#
|
|
|
23 |
#......................................................................#
|
|
|
24 |
|
|
|
25 |
#
|
|
|
26 |
# Globals used
|
|
|
27 |
#
|
|
|
28 |
# $::ScmRoot - Project Root
|
|
|
29 |
# $::ScmInterface - Path to the interface directory
|
|
|
30 |
# $::ScmLocal - Path to build (local)
|
|
|
31 |
# $::ScmDebug - Debug control
|
|
|
32 |
# $::exe - Allow search for exe files
|
|
|
33 |
# $::a
|
|
|
34 |
# $::so
|
|
|
35 |
# $::ScmBuildPkgRules - Allow searching in packages
|
|
|
36 |
# $::ScmPlatform - Allow searching in packages
|
|
|
37 |
#
|
|
|
38 |
# @::SRCDIRS - Allow searching for SOURCE files
|
|
|
39 |
# $::SRCS - Allow Src lookup
|
|
|
40 |
# ::Src() - Extend Src
|
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
require 5.006_001;
|
|
|
45 |
use strict;
|
|
|
46 |
use warnings;
|
|
|
47 |
|
|
|
48 |
unless ( defined $::ScmWho )
|
|
|
49 |
{
|
|
|
50 |
die "ERROR common.pl has not been initialised\n",
|
|
|
51 |
"This is required in order to include many of the structures needed\n",
|
|
|
52 |
"";
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
#-------------------------------------------------------------------------------
|
|
|
56 |
# Function : LocateFiles
|
|
|
57 |
#
|
|
|
58 |
# Description : Locate one or more files within the dependancy lists
|
|
|
59 |
# of the current package.
|
|
|
60 |
#
|
|
|
61 |
# Inputs : PlatformSelector arguments+
|
|
|
62 |
# Arguments are
|
|
|
63 |
# One or more files to locate, with embedded options
|
|
|
64 |
# Files may contain leading directories ( etc/file.ini )
|
|
|
65 |
# Options:
|
|
|
66 |
# --Dir=xxxx[,yyyy] Limit search to xxxx type directories
|
|
|
67 |
# --Lib Limit search for lib directories
|
|
|
68 |
# Shorthand for --Dir=lib
|
|
|
69 |
# --Include Limit search to include directories
|
|
|
70 |
# Shorthand for --Dir=include,inc
|
|
|
71 |
# --Bin Limit search to bin directories
|
|
|
72 |
# Shorthand for --Dir=bin
|
|
|
73 |
# --Local Search the "local" directory tree only
|
|
|
74 |
# --Interface Search the "interface" directory only
|
|
|
75 |
# --Src Search within the AddDir paths
|
|
|
76 |
# This will not locate files within packages
|
|
|
77 |
# only files within the build sandbox
|
|
|
78 |
# --Type=nnn Where nnn is one of:
|
|
|
79 |
# prog -> Implies --Bin
|
|
|
80 |
# lib -> Implies --Lib
|
|
|
81 |
# shared -> Implies --Lib
|
|
|
82 |
# This option will modify the named
|
|
|
83 |
# file by appending the target specific
|
|
|
84 |
# file suffix and prefix to the files.
|
|
|
85 |
# --Verbose User level debug of the scanning process
|
|
|
86 |
# --Production Do not search debug directories
|
|
|
87 |
# --Debug Do not search production directories
|
|
|
88 |
# --AddToSrc Add files to JATS Src
|
|
|
89 |
#
|
|
|
90 |
# When the search is limited to a directory(s) the function
|
|
|
91 |
# will try various compatibility version of the directory. ie:
|
|
|
92 |
# dir.machine[D|P|'']
|
|
|
93 |
# dir/machine[D|P|'']
|
|
|
94 |
# dir/dir.machine[D|P|'']
|
|
|
95 |
# dir[D|P|'']
|
|
|
96 |
#
|
|
|
97 |
# This function will locate files that are in packages
|
|
|
98 |
# specified with either the LinkPkgArchive or BuildPkgArchive
|
|
|
99 |
# directive.
|
|
|
100 |
#
|
|
|
101 |
# Notes : A limitation of this function is that it only looks in "known"
|
|
|
102 |
# locations for files. It does not allow for random package construction
|
|
|
103 |
# although it does attempt to handle some of the older and uglier
|
|
|
104 |
# packages
|
|
|
105 |
#
|
|
|
106 |
# Returns : An array of resolved pathnames - if user wants an array
|
|
|
107 |
# A scalar pathname of one file - if the user does not want an array
|
|
|
108 |
#
|
|
|
109 |
# An error will be issued if a file cannot be resolved and the
|
|
|
110 |
# function will not return.
|
|
|
111 |
#
|
|
|
112 |
# Examples : LocateFiles ( *, --Type=shared, myDll, myDll2 );
|
|
|
113 |
# LocateFiles ( *, etc/config.ini );
|
|
|
114 |
#
|
|
|
115 |
#
|
|
|
116 |
our %_DirSeen; # Internal Cache of directories that don't exist
|
|
|
117 |
# Use "_" Prefix to prevent retention in makefile.cfg
|
|
|
118 |
sub LocateFiles
|
|
|
119 |
{
|
|
|
120 |
my( $platforms, @elements ) = @_;
|
|
|
121 |
|
|
|
122 |
Debug2( "LocateFiles($platforms, @elements)" );
|
|
|
123 |
return if ( ! ActivePlatform($platforms) );
|
|
|
124 |
|
|
|
125 |
#---------------------------------------------------------------------------
|
|
|
126 |
# Scan the user arguments and determine options and files
|
|
|
127 |
#
|
|
|
128 |
my @rfiles; # Fully located files
|
|
|
129 |
my @sfiles; # Files to locate
|
|
|
130 |
my @dirs; # Subdir roots to scan
|
|
|
131 |
my $scan_local = 0; # Look in "local" only
|
|
|
132 |
my $scan_interface = 0; # Look in "interface" only
|
|
|
133 |
my $scan_src = 0; # Look in users Src dirs only
|
|
|
134 |
my $add_type; # Process file names
|
|
|
135 |
my $verbose = 0; # User level debug
|
|
|
136 |
my $saved_verbose = $::ScmDebug; # Saved debug level
|
|
|
137 |
my $no_debug; # Don't scan debug dirs
|
|
|
138 |
my $no_prod; # Don't scan prod dirs
|
|
|
139 |
my $source_for_usr; # Do a Src too
|
|
|
140 |
|
|
|
141 |
foreach ( @elements )
|
|
|
142 |
{
|
|
|
143 |
next unless ( defined $_ ); # Skip empty elements
|
|
|
144 |
push (@sfiles, $_) && next unless ( m/^-/ ); # Extract files
|
|
|
145 |
|
|
|
146 |
if ( m/^--Dir=(.+)/ ) {
|
|
|
147 |
UniquePush( \@dirs, $1 );
|
|
|
148 |
|
|
|
149 |
} elsif ( m/^--Lib$/ ) {
|
|
|
150 |
UniquePush( \@dirs, "lib" );
|
|
|
151 |
|
|
|
152 |
} elsif ( m/^--Bin$/ ) {
|
|
|
153 |
UniquePush( \@dirs, "bin" );
|
|
|
154 |
|
|
|
155 |
} elsif ( m/^--Include$/ ) {
|
|
|
156 |
UniquePush( \@dirs, "include", "inc" );
|
|
|
157 |
$no_debug = 1;
|
|
|
158 |
$no_prod = 1;
|
|
|
159 |
|
|
|
160 |
} elsif ( m/^--Local$/ ) {
|
|
|
161 |
$scan_local = 1;
|
|
|
162 |
Error ("LocateFiles: --Local not valid. No local directory defined") unless ( $::ScmLocal );
|
|
|
163 |
|
|
|
164 |
} elsif ( m/^--Interface$/ ) {
|
|
|
165 |
$scan_interface = 1;
|
|
|
166 |
|
|
|
167 |
} elsif ( m/^--Src$/ ) {
|
|
|
168 |
$scan_src = 1;
|
|
|
169 |
|
|
|
170 |
} elsif ( m/^--Type=(.+)/ ) {
|
|
|
171 |
Error ("LocateFiles: Multiple --Type=xxx not allowed") if ( $add_type );
|
|
|
172 |
$add_type = $1;
|
|
|
173 |
|
|
|
174 |
} elsif ( m/^--Verbose$/ ) {
|
|
|
175 |
$verbose++;
|
|
|
176 |
|
|
|
177 |
} elsif ( m/^--Verbose=(\d*)/ ) {
|
|
|
178 |
$verbose = $1;
|
|
|
179 |
|
|
|
180 |
} elsif ( m/^--Debug/ ) {
|
|
|
181 |
$no_prod = 1;
|
|
|
182 |
|
|
|
183 |
} elsif ( m/^--Prod/ ) {
|
|
|
184 |
$no_debug = 1;
|
|
|
185 |
|
|
|
186 |
} elsif ( m/^--AddToSrc/ ) {
|
|
|
187 |
$source_for_usr = 1;
|
|
|
188 |
|
|
|
189 |
} else
|
|
|
190 |
{
|
|
|
191 |
Warning ("LocateFiles: Unknown option ignored: $_");
|
|
|
192 |
}
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
#
|
|
|
196 |
# Sanity Testing
|
|
|
197 |
#
|
|
|
198 |
Error ("LocateFiles: Conflicting options: --Src, --Local and --Interface are mutually exclusive")
|
|
|
199 |
if ( $scan_src + $scan_local + $scan_interface > 1 );
|
|
|
200 |
|
|
|
201 |
#
|
|
|
202 |
# Enable user level debugging for this function only
|
|
|
203 |
# System level debugging will override
|
|
|
204 |
#
|
|
|
205 |
$::ScmDebug = $verbose unless ( $::ScmDebug );
|
|
|
206 |
Debug( "LocateFiles: ScanFor: @sfiles" );
|
|
|
207 |
|
|
|
208 |
#---------------------------------------------------------------------------
|
|
|
209 |
# Add target specific prefix and suffix to filenames
|
|
|
210 |
#
|
|
|
211 |
if ( $add_type )
|
|
|
212 |
{
|
|
|
213 |
Debug( "LocateFiles: Adding file types: $add_type" );
|
|
|
214 |
my $prefix = '';
|
|
|
215 |
my $suffix = '';
|
|
|
216 |
my $dolib = 1;
|
|
|
217 |
if ( $add_type =~ /prog/ )
|
|
|
218 |
{
|
|
|
219 |
$suffix = $::exe;
|
|
|
220 |
$dolib = 0;
|
|
|
221 |
UniquePush( \@dirs, "bin" );
|
|
|
222 |
|
|
|
223 |
} elsif ( $add_type =~ /lib/ )
|
|
|
224 |
{
|
|
|
225 |
$suffix = '.' . $::a;
|
|
|
226 |
UniquePush( \@dirs, "lib" );
|
|
|
227 |
|
|
|
228 |
} elsif ( $add_type =~ /shared/ )
|
|
|
229 |
{
|
|
|
230 |
$suffix = '.' . $::so;
|
|
|
231 |
UniquePush( \@dirs, "lib" );
|
|
|
232 |
|
|
|
233 |
} else
|
|
|
234 |
{
|
|
|
235 |
Error ("LocateFiles: Unknown type: --Type=$add_type");
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
#
|
|
|
239 |
# On a unix system libraries have a "lib" prepended to each library.
|
|
|
240 |
#
|
|
|
241 |
$prefix= "lib" if ( $dolib && $::ScmTargetHost eq "Unix" );
|
|
|
242 |
|
|
|
243 |
#
|
|
|
244 |
# Add prefix and suffix to all the files in the list
|
|
|
245 |
#
|
|
|
246 |
@sfiles = map $prefix . $_ . $suffix, @sfiles;
|
|
|
247 |
|
|
|
248 |
Debug( "LocateFiles: Adding file types: Prefix:'$prefix', Suffix:'$suffix'" );
|
|
|
249 |
Debug2( "LocateFiles: Processed file list: @sfiles" );
|
|
|
250 |
}
|
|
|
251 |
|
|
|
252 |
#---------------------------------------------------------------------------
|
|
|
253 |
# Determine the list of directories to search
|
|
|
254 |
# Will search within:
|
|
|
255 |
# - User AddDir paths
|
|
|
256 |
# - Local Directory ( Not useful )
|
|
|
257 |
# - Interface Directory (BuildPkgArchive)
|
|
|
258 |
# - Interface Directory + Package directories ( Build + Link PkgArchive)
|
|
|
259 |
# This is the default
|
|
|
260 |
#
|
|
|
261 |
my @basedirs;
|
|
|
262 |
my $simple_scan;
|
|
|
263 |
if ( $scan_src )
|
|
|
264 |
{
|
|
|
265 |
push @basedirs, @::SRCDIRS;
|
|
|
266 |
$simple_scan = 1;
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
if ( $scan_local )
|
|
|
270 |
{
|
|
|
271 |
push @basedirs, "$::ScmRoot/$::ScmLocal";
|
|
|
272 |
$simple_scan = 1;
|
|
|
273 |
}
|
|
|
274 |
|
|
|
275 |
if ( $scan_interface )
|
|
|
276 |
{
|
|
|
277 |
push @basedirs, "$::ScmRoot/$::ScmInterface";
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
unless ( @basedirs )
|
|
|
281 |
{
|
|
|
282 |
push @basedirs, "$::ScmRoot/$::ScmInterface";
|
|
|
283 |
for (@{$::ScmBuildPkgRules{$::ScmPlatform} })
|
|
|
284 |
{
|
|
|
285 |
push @basedirs, $_->{'ROOT'} if ($_->{'TYPE'} eq 'link');
|
|
|
286 |
}
|
|
|
287 |
}
|
|
|
288 |
Debug( "LocateFiles: Scan: @basedirs" );
|
|
|
289 |
|
|
|
290 |
#---------------------------------------------------------------------------
|
|
|
291 |
# If we are scanning package directories then we need to maintain
|
|
|
292 |
# backward compatability with some badly constructed directories
|
|
|
293 |
# There is also a kludge for the SOLARIS target
|
|
|
294 |
#
|
|
|
295 |
# Create an extended list of directories to scan
|
|
|
296 |
#
|
|
|
297 |
unless ( $simple_scan )
|
|
|
298 |
{
|
|
|
299 |
Debug2( "LocateFiles: Platform: $::ScmPlatform" );
|
|
|
300 |
Debug2( "LocateFiles: Parts : @{$::BUILDPLATFORM_PARTS{$::ScmPlatform}}" );
|
|
|
301 |
|
|
|
302 |
my @more_dirs;
|
|
|
303 |
foreach my $dir ( @dirs )
|
|
|
304 |
{
|
|
|
305 |
my @parts = @{$::BUILDPLATFORM_PARTS{$::ScmPlatform}};
|
|
|
306 |
push @parts, 'sparc', 'SOLARIS_sparc' if ( $::ScmPlatform eq 'SOLARIS' );
|
|
|
307 |
push @parts, 'win32' if ( $::ScmPlatform eq 'WIN32' );
|
|
|
308 |
|
|
|
309 |
foreach my $type ( 'P', 'D', '' )
|
|
|
310 |
{
|
|
|
311 |
next if ( $type eq 'P' && $no_prod);
|
|
|
312 |
next if ( $type eq 'D' && $no_debug);
|
|
|
313 |
foreach my $part ( @parts )
|
|
|
314 |
{
|
|
|
315 |
UniquePush (\@more_dirs, "$dir.$part$type");
|
|
|
316 |
UniquePush (\@more_dirs, "$dir/$part$type");
|
|
|
317 |
UniquePush (\@more_dirs, "$dir/$dir.$part$type");
|
|
|
318 |
}
|
|
|
319 |
UniquePush (\@more_dirs, $dir . $type);
|
|
|
320 |
}
|
|
|
321 |
}
|
|
|
322 |
Debug2( "LocateFiles: Complex: @more_dirs" );
|
|
|
323 |
@dirs = @more_dirs;
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
#---------------------------------------------------------------------------
|
|
|
327 |
# Locate all the required files
|
|
|
328 |
#
|
|
|
329 |
my $tfile;
|
|
|
330 |
DIR:
|
|
|
331 |
foreach my $file ( @sfiles)
|
|
|
332 |
{
|
|
|
333 |
#
|
|
|
334 |
# Look in the list of known source files
|
|
|
335 |
# We can only handle a single instance of any given filename in the
|
|
|
336 |
# system so we should strip of any possible directory
|
|
|
337 |
#
|
|
|
338 |
(my $raw_file = $file) =~ s~.*/~~;
|
|
|
339 |
if ( $tfile = $::SRCS{$raw_file} )
|
|
|
340 |
{
|
|
|
341 |
#
|
|
|
342 |
# Base file found in the source database
|
|
|
343 |
# Ensure that this is the one that the user wants
|
|
|
344 |
#
|
|
|
345 |
Error ("LocateFiles: File already known, but the specified directories don't match",
|
|
|
346 |
"Specified file: $file",
|
|
|
347 |
"Known file : $tfile" ) unless ( $tfile eq $file || $tfile =~ m~/$file$~ );
|
|
|
348 |
next DIR;
|
|
|
349 |
}
|
|
|
350 |
|
|
|
351 |
#
|
|
|
352 |
# Scan the complete directory list for the specified file
|
|
|
353 |
#
|
|
|
354 |
foreach my $root ( @basedirs )
|
|
|
355 |
{
|
|
|
356 |
foreach my $sdir ( @dirs, '' )
|
|
|
357 |
{
|
|
|
358 |
#
|
|
|
359 |
# Maintain a list of directories that we know
|
|
|
360 |
# that we have and those that we know that we do not have.
|
|
|
361 |
# This (should) speed up access
|
|
|
362 |
# undef - not tested
|
|
|
363 |
# 1 - Know we have the directory
|
|
|
364 |
# 2 - Know that we don;t have the directory
|
|
|
365 |
#
|
|
|
366 |
#
|
|
|
367 |
my $dir = "$root/$sdir";
|
|
|
368 |
$dir =~ s~//~/~g;
|
|
|
369 |
$dir =~ s~/$~~;
|
|
|
370 |
my $dirseen = $_DirSeen{$dir} || 0;
|
|
|
371 |
Debug2( "LocateFiles: Look for($dirseen): $dir/$file" );
|
|
|
372 |
$_DirSeen{$dir} = $dirseen = -d $dir ? 1 : 2
|
|
|
373 |
unless ( $dirseen );
|
|
|
374 |
next if ( $dirseen > 1 );
|
|
|
375 |
|
|
|
376 |
Debug( "LocateFiles: Examine: $dir/$file" );
|
|
|
377 |
$tfile = "$dir/$file";
|
|
|
378 |
next DIR if ( -f $tfile );
|
|
|
379 |
}
|
|
|
380 |
}
|
|
|
381 |
|
|
|
382 |
#
|
|
|
383 |
# Not found
|
|
|
384 |
#
|
|
|
385 |
$tfile = ();
|
|
|
386 |
}
|
|
|
387 |
continue
|
|
|
388 |
{
|
|
|
389 |
#
|
|
|
390 |
# This block is executed for all iterations of the associated loop
|
|
|
391 |
# It is used for common error detection and reporting of the found
|
|
|
392 |
# file
|
|
|
393 |
#
|
|
|
394 |
Error ("LocateFiles: File not located: $file") unless ( $tfile );
|
|
|
395 |
|
|
|
396 |
push @rfiles, $tfile;
|
|
|
397 |
Debug( "LocateFiles: Result: $file ->$tfile" );
|
|
|
398 |
}
|
|
|
399 |
|
|
|
400 |
#
|
|
|
401 |
# Restore system debug mode
|
|
|
402 |
#
|
|
|
403 |
$::ScmDebug = $saved_verbose;
|
|
|
404 |
|
|
|
405 |
#
|
|
|
406 |
# Add the files to the Src mechanism if required
|
|
|
407 |
# This will allow random files to be built directly from a package
|
|
|
408 |
#
|
|
|
409 |
Src( '*', @rfiles ) if ( $source_for_usr );
|
|
|
410 |
|
|
|
411 |
#
|
|
|
412 |
# Return to the user what they want an array or a list
|
|
|
413 |
#
|
|
|
414 |
return wantarray ? @rfiles : "@rfiles";
|
|
|
415 |
|
|
|
416 |
}
|
|
|
417 |
|
|
|
418 |
1;
|