sbsv1/abld/bldmake/linkdeps.pl
changeset 629 541af5ee3ed9
parent 599 fa7a3cc6effd
equal deleted inserted replaced
628:7c4a911dc066 629:541af5ee3ed9
       
     1 # Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # Generate a link-dependency graph
       
    15 # Given a baseline list of components, look through the BLDMAKE
       
    16 # generated files to find the individual DLL and EXE makefiles.
       
    17 # Scan those makefile to find out which .LIB files are generated,
       
    18 # and which .LIB files are required, thereby deducing the 
       
    19 # component dependency graph.
       
    20 # 
       
    21 #
       
    22 
       
    23 my @components;
       
    24 my %component_releases;
       
    25 my %components_by_lib;
       
    26 my %libs_needed;
       
    27 my %component_deps;
       
    28 my $errors = 0;
       
    29 my @platforms = ("WINS", "ARMI", "MAWD");
       
    30 my $makefile_count=0;
       
    31 
       
    32 while (<>)
       
    33 	{
       
    34 	s/\s*#.*$//;
       
    35 	if ($_ =~ /^$/)
       
    36 		{
       
    37 		next;
       
    38 		}
       
    39 
       
    40 	if ($_ =~ /<option (\w+)(.*)>/)
       
    41 		{
       
    42 		# placeholder
       
    43 		next;	
       
    44 		}
       
    45 
       
    46 	push @components, lc $_;
       
    47 	}
       
    48 
       
    49 scan_bldmakes();
       
    50 
       
    51 if ($makefile_count==0)
       
    52 	{
       
    53 	error("No makefiles scanned!??");
       
    54 	}
       
    55 
       
    56 if (%libs_needed==0)
       
    57 	{
       
    58 	error("No libraries needed!??");
       
    59 	}
       
    60 
       
    61 foreach $lib (sort keys %libs_needed)
       
    62 	{
       
    63 	if ($components_by_lib{$lib} eq "")
       
    64 		{
       
    65 		error("library $lib is not produced by any component!");
       
    66 		$components_by_lib{$lib} = "($lib)";
       
    67 		}
       
    68 	}
       
    69 
       
    70 if ($errors > 0)
       
    71 	{
       
    72 	print "\n";
       
    73 	}
       
    74 
       
    75 foreach $component (sort keys %component_deps)
       
    76 	{
       
    77 	my %dependencies;
       
    78 
       
    79 	foreach $lib (split /\s+/, $component_deps{$component})
       
    80 		{
       
    81 		next if ($lib eq "");
       
    82 		my $dependent = $components_by_lib{$lib};
       
    83 		$dependencies{$dependent} = 1;
       
    84 		}
       
    85 
       
    86 	print "$component $component_releases{$component}:";
       
    87 	foreach $dependent (sort keys %dependencies)
       
    88 		{
       
    89 		next if ($dependent eq $component);
       
    90 		print " $dependent";
       
    91 		}
       
    92 	print "\n";
       
    93 	}
       
    94 
       
    95 sub scan_bldmakes
       
    96 	{
       
    97 	foreach $line (@components)
       
    98 		{
       
    99 		next if ($line =~ /<special (\w+)(.*)>/);
       
   100 		my ($name, $groupdir, $subdir, $release) = split /\s+/,$line;
       
   101 		$component_releases{$name} = $release;
       
   102 		my $bldmake = "\\epoc32\\build\\$groupdir";
       
   103 		if (! -d $bldmake)
       
   104 			{
       
   105 			error("bldmake failed for $name $release");
       
   106 			next;
       
   107 			}
       
   108 		foreach $platform (@platforms)
       
   109 			{
       
   110 			scan_bldmake_makefile($name,"$bldmake\\$platform.make");
       
   111 			}
       
   112 		}
       
   113 	}
       
   114 
       
   115 exit ($errors > 0);
       
   116 
       
   117 sub error
       
   118 	{
       
   119 	my ($text) = @_;
       
   120 	print "# ERROR: $text\n";
       
   121 	$errors+=1;
       
   122 	}
       
   123 
       
   124 # In \epoc32\build\<place>\wins.make
       
   125 #
       
   126 # SAVESPACEAPPARC :
       
   127 #	nmake -nologo $(VERBOSE) -f "\EPOC32\BUILD\APPARC\GROUP\WINS\APPARC.WINS" $(CFG) CLEANBUILD$(CFG)
       
   128 #
       
   129 # repeated N times
       
   130 
       
   131 sub scan_bldmake_makefile
       
   132 	{
       
   133 	my ($component, $makefile) = @_;
       
   134 	if (! -e $makefile) 
       
   135 		{
       
   136 		return;
       
   137 		}
       
   138 	open FILE, "<$makefile" or error("Can't open $makefile") and return;
       
   139 	while ($line = <FILE>)
       
   140 		{
       
   141 		if ($line =~ /^SAVESPACE/)
       
   142 			{
       
   143 			$line = <FILE>;
       
   144 			if ($line =~ /-f "(\S+)"\s/i)
       
   145 				{
       
   146 				scan_mmp_makefile($component,$1);
       
   147 				}
       
   148 			}
       
   149 		}
       
   150 	close FILE;
       
   151 	}
       
   152 
       
   153 # In \EPOC32\MAKE\LEXICON\WINS\INSO.WINS
       
   154 #
       
   155 # # MMPFile \LEXICON\GROUP\INSO.MMP
       
   156 # # Target INSO.LIB
       
   157 # # TargetType LIB
       
   158 # # GeneralTargetType LIB
       
   159 #
       
   160 
       
   161 # In \EPOC32\BUILD\APPARC\GROUP\WINS\APPARC.WINS
       
   162 #
       
   163 # LIBRARY : "$(EPOCLIB)UDEB\APPARC.LIB"
       
   164 #
       
   165 # LIBS= \
       
   166 #	"$(EPOCLINKDEB)\EUSER.LIB" \
       
   167 #	"$(EPOCLINKDEB)\EFSRV.LIB" \
       
   168 #	"$(EPOCLINKDEB)\GDI.LIB" \
       
   169 #	"$(EPOCLINKDEB)\ESTOR.LIB"
       
   170 #
       
   171 sub scan_mmp_makefile
       
   172 	{
       
   173 	my ($component, $makefile) = @_;
       
   174 	open SUBFILE, "<$makefile" or error("Can't open mmp $makefile for $component") and return;
       
   175 	$makefile_count++;
       
   176 	while ($line = <SUBFILE>)
       
   177 		{
       
   178 		if ($line =~ /^LIBRARY : .*\\(\S+)"/ || 
       
   179 			$line =~ /^# Target (\S+\.LIB)/)
       
   180 			{
       
   181 			my $built_lib = $1;
       
   182 			my $previous = $components_by_lib{$built_lib};
       
   183 			if ($previous && $previous ne $component)
       
   184 				{
       
   185 				error("$built_lib is generated by $component and $previous");
       
   186 				next;
       
   187 				}
       
   188 			$components_by_lib{$built_lib} = $component;
       
   189 			next
       
   190 			}
       
   191 		if ($line =~ /^LIBS= \\/)
       
   192 			{
       
   193 			while ($line = <SUBFILE>)
       
   194 				{
       
   195 				if ($line =~ /\\(\S+)"/)
       
   196 					{
       
   197 					$component_deps{$component} .= " $1";
       
   198 					$libs_needed{$1} = 1;
       
   199 					}
       
   200 				if ($line !~ /\\$/)
       
   201 					{
       
   202 					last;
       
   203 					}
       
   204 				}
       
   205 			}
       
   206 		}
       
   207 	close SUBFILE;
       
   208 	}
       
   209 
       
   210