#!/usr/bin/perl $OCCDir="$ARGV[0]/ros"; $OCCSrcDir="$OCCDir/src"; $OCCIncDir="$OCCDir/inc"; $OCCAdmDir="$OCCDir/adm"; $OCCPlatform="Linux"; $OCCLnkDir="$OCCAdmDir/$OCCPlatform"; $OCCBinDir="$OCCDir/$OCCPlatform/bin"; $OCCLibDir="$OCCDir/$OCCPlatform/lib"; shift; # Get source directories from .lnk file sub GetLnkSourceDirs { my $line, $file = $_[0]; my %resulthash; open (FILE, "< $file") or die "Cannot open file: $file"; while (defined($line = )) { if ($line =~ m|/Linux/obj/([^/]*)/[^/]*\.o|) { $resulthash{$1} = 1; } } close (FILE); return sort(keys(%resulthash)); } # Get source dir for each executable my %exesrc, $exe; opendir (DIR, $OCCBinDir) or die "Cannot open directory: $OCCBinDir"; while (defined($exe = readdir(DIR))) { next unless ( -f "$OCCBinDir/$exe" ); my $file = "$OCCLnkDir/$exe.lnk"; my @srclist = GetLnkSourceDirs($file); my $size = $#srclist + 1; die "Got $size source directories for executable: $exe" unless ($size eq 1); $exesrc{$exe} = $srclist[0]; } closedir(DIR); # Get source dir for each header my %hdrsrc, %hdrsrctmp, $hdr; # First scan all source directories for headers opendir (DIR, "$OCCSrcDir") or die "Cannot open directory: $OCCSrcDir"; while (defined($dir = readdir(DIR))) { next if ($dir =~ /^\./); my $subdir = "$OCCSrcDir/$dir"; next unless (-d $subdir); opendir (SUBDIR, $subdir) or die "Cannot open directory: $subdir"; while (defined($file = readdir(SUBDIR))) { next unless ($file =~ /^(.*)\.([^.]+)$/); my $base = $1, $ext = $2; if (($ext eq "h") || ($ext eq "hxx") || ($ext eq "lxx") || ($ext eq "gxx")) { $hdrsrctmp{$file} = $dir; } elsif ($ext eq "lex") { $hdrsrctmp{"${base}.tab.h"} = $dir; } } closedir(SUBDIR); } closedir(DIR); # Now scan the include directory opendir (IDIR, "$OCCIncDir") or die "Cannot open directory: $OCCIncDir"; while (defined($hdr = readdir(IDIR))) { next unless (-f "$OCCIncDir/$hdr"); if ( exists( $hdrsrctmp{$hdr} ) ) { $hdrsrc{$hdr} = $hdrsrctmp{$hdr}; } elsif (($hdr =~ /^Handle_([^._]+).*\.[hgl]xx/) and (-d "$OCCSrcDir/$1")) { $hdrsrc{$hdr} = $1; } elsif (($hdr =~ /^([^._]+).*\.[hgl]xx/) and (-d "$OCCSrcDir/$1")) { $hdrsrc{$hdr} = $1; } else { die "Can't find source for: $OCCIncDir/$hdr"; } } closedir(IDIR); # Get source dir for each library my %libsrc, $lib; opendir (DIR, $OCCLibDir) or die "Cannot open directory: $OCCLibDir"; while (defined($lib = readdir(DIR))) { next unless ($lib =~ /^lib([^.]+)\.so(\.[0-9]+(\.[0-9]+)?)?/); my $name = $1; if (-d "$OCCSrcDir/$name") { $libsrc{$lib} = $name; } elsif (-f "$OCCLnkDir/$name.lnk") { my @list = GetLnkSourceDirs( "$OCCLnkDir/$name.lnk" ); my $size = $#list + 1; die "Got $size source directories for lib: $lib" unless ($size eq 1); $libsrc{$lib} = $list[0]; } else { die "Can't find source for: $OCCLibDir/$lib"; } } closedir(DIR); # Given a reference to a hash and a list of values, # do reverse lookup of values in hash (return keys) sub ReverseHash { my $hashref = $_[0]; shift; my $key; my $val; my %hash = (); my @results = (); foreach $val (@_) { $hash{$val} = 1; } foreach $key (keys %$hashref) { $val = $$hashref{$key}; push (@results, $key) if (exists $hash{$val}); } return @results; } # Get headers from a list of source directories sub GetHeaders { return ReverseHash( \%hdrsrc, @_ ); } # Get executables from a list of source directories sub GetExecutables { return ReverseHash( \%exesrc, @_ ); } # Get libraries from a list of source directories sub GetLibs { return ReverseHash( \%libsrc, @_ ); } # Get source directories for a target sub GetSourceDirs { my $item = $_[0]; die "Directory doesn't exist: $OCCSrcDir/$item" unless (-d "$OCCSrcDir/$item"); my %resulthash = ($item, 1); # If target has a PACKAGES file (it's a toolkit) # then read it. my $line, $file = "$OCCSrcDir/$item/PACKAGES"; if (open (FILE, "< $file" )) { while (defined($line = )) { $resulthash{$1} = 1 if ($line =~ /^\s*([^\s]+)\s*$/ ); } close (FILE); } # If target has link instructions, get source # directories for object files. $file = "$OCCLnkDir/$item.lnk"; if (open (FILE, "< $file" )) { while (defined($line = )) { $resulthash{$1} = 1 if ($line =~ m|/$OCCPlatform/obj/([^/]*)/.*\.o|); } close (FILE); } return sort(keys(%resulthash)); } # Dump all data # print "++++++++++++++++++++++ Headers ++++++++++++++++++++++\n"; # foreach $hdr (keys %hdrsrc) { # print "$hdr <= $hdrsrc{$hdr}\n"; # } # print "++++++++++++++++++++++ Executables ++++++++++++++++++++++\n"; # foreach $exe (keys %exesrc) { # print "$exe <= $exesrc{$exe}\n"; # } # print "++++++++++++++++++++++ Libs ++++++++++++++++++++++\n"; # foreach $lib (keys %libsrc) { # print "$lib <= $libsrc{$lib}\n"; # } # Consturct big list of source directories from input list my @dirlist = (); foreach $item (@ARGV) { my @tmplist = GetSourceDirs( $item ); push (@dirlist, @tmplist); } # Get installed files my @headers = GetHeaders( @dirlist ); my @execs = GetExecutables( @dirlist ); my @libs = GetLibs( @dirlist ); print "headers: @headers\n"; print "execs: @execs\n"; print "libs: @libs\n";