Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / bin / libsize.pl
blobba906127048509f9790aae0ddea2e79af8c8a4f5
1 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
2 & eval 'exec perl -S $0 $argv:q'
3 if 0;
6 # Provides size breakdown of ACE, TAO, or orbsvcs libs.
8 # Assumes (or builds) the lib with debug=0. Allows other make args,
9 # such as -j 4, to be passed on the command line.
11 $usage =
12 "$0 [-h, for html output] [-s, for shared libs] [-v] [make arguments]\n";
14 ####
15 #### Configuration parameters.
16 ####
17 $build_args =
18 'debug=0 optimize=1 static_libs_only=1';
19 $ACE_COMPONENTS =
20 'OS Utils Logging Threads Demux Connection Sockets IPC Svcconf ' .
21 'Streams Memory Token Other';
22 $TAO_COMPONENTS =
23 'POA Pluggable_Protocols Default_Resources Interpretive_Marshaling ' .
24 'IDL_Compiler ORB_Core Dynamic_Any';
25 $ORBSVCS_COMPONENTS =
26 'Naming ImplRepo Time Concurrency Property Trader LifeCycle Sched ' .
27 'Event CosEvent Event2 AV';
30 #### The following are only used for VxWorks libraries, and
31 #### only if the corresponding environment variable isn't set.
32 $default_toolenv = '386';
33 $default_wind_base = '/project/doc/pkg/wind';
34 $default_host_type = 'sun4-solaris2';
36 #### Use gmake if it's on the user's PATH, otherwise use make. Use
37 #### sh -c to avoid warning if gmake isn't found.
38 $make =
39 system ("sh -c \"gmake --version\" > /dev/null 2>&1") ? 'make' : 'gmake';
41 $ACE_ROOT = $ENV{'ACE_ROOT'} ||
42 die "$0: ACE_ROOT was not set!\n";
45 $html = $verbose = 0;
46 $lib_extension = 'a';
48 ####
49 #### Process command line args.
50 ####
51 while ($#ARGV >= $[ && $ARGV[0] =~ /^-/) {
52 if ($ARGV[0] eq '-h') {
53 $html = 1;
54 chop ($sysname = `uname -s`);
55 chop ($sysrev = `uname -r`);
56 shift;
57 } elsif ($ARGV[0] eq '-s') {
58 $lib_extension = 'so';
59 $build_args =~ s/ static_libs_only=1//;
60 shift;
61 } elsif ($ARGV[0] eq '-v') {
62 $verbose = 1;
63 shift;
64 } elsif ($ARGV[0] eq '-?') {
65 print "$usage";
66 exit;
67 } else {
68 #### Pass remaining args to make.
72 $make_args = join (' ', @ARGV) . $build_args;
74 chop ($pwd = `pwd`);
76 if ($pwd =~ m%/ace$%) {
77 #### libACE
78 $COMPONENTS = "$ACE_COMPONENTS";
79 $LIB_COMPONENTS = 'ACE_COMPONENTS';
80 $libname = 'ACE';
81 } elsif ($pwd =~ m%/tao$%) {
82 $COMPONENTS = "$TAO_COMPONENTS";
83 $LIB_COMPONENTS = 'TAO_COMPONENTS';
84 $libname = 'TAO';
85 } elsif ($pwd =~ m%/orbsvcs/orbsvcs$%) {
86 $COMPONENTS = "$ORBSVCS_COMPONENTS";
87 $LIB_COMPONENTS = 'TAO_ORBSVCS';
88 $libname = 'orbsvcs';
89 } else {
90 die "$0: unsupported directory; $pwd\n";
93 $lib = "lib${libname}.$lib_extension";
96 ####
97 #### Select the size command based on ACE_ROOT setting.
98 ####
99 if ($ACE_ROOT =~ /vxworks/) {
100 $TOOLENV = $ENV{'TOOLENV'} || $default_toolenv;
101 $WIND_BASE = $ENV{'WIND_BASE'} || $default_wind_base;
102 $WIND_HOST_TYPE = $ENV{'WIND_HOST_TYPE'} || $default_host_type;
103 $size = "$WIND_BASE/host/$WIND_HOST_TYPE/bin/size$TOOLENV";
104 } elsif ($ACE_ROOT =~ /lynx-ppc/) {
105 $size = '/usr/lynx/3.0.0/ppc/cdk/sunos-xcoff-ppc/bin/size';
106 } elsif ($ACE_ROOT =~ /lynx/) {
107 $size = '/usr/lynx/3.0.0/x86/cdk/sunos-coff-x86/bin/size';
108 } else {
109 $size = 'size';
113 ####
114 #### Measure the size of the entire library.
115 ####
116 $sizeTotal = build_lib ("$LIB_COMPONENTS=\"$COMPONENTS\"");
117 $components = " <th>Platform\n <th>Component\n <th>Total";
118 $componentSize = " <th>Size, bytes\n <td align=center>$sizeTotal";
119 $componentPercentage =
120 " <th>Percentage of<br>total size\n <td align=center>100";
121 print "Total $sizeTotal (100)\n" unless $html;
124 ####
125 #### Measure the size of each library component.
126 ####
127 foreach my $i (split (' ', $COMPONENTS)) {
128 $sizeLib = build_lib ("$LIB_COMPONENTS=\"$i\"");
129 $components .= "\n <th>$i";
130 $componentSize .= "\n <td align=center>$sizeLib";
131 $thisPercentage = percentage ($sizeLib, $sizeTotal);
132 $componentPercentage .= "\n <td align=center>$thisPercentage";
133 print "$i $sizeLib ($thisPercentage)\n" unless $html;
136 ####
137 #### Produce HTML output, if requested.
138 ####
139 if ($html) {
140 print '<center><table cellpadding=4 border=4>' . "\n";
141 print ' <tr>' . "\n";
142 print "$echoArgs $components\n";
143 print ' <tr>' . "\n";
144 print " <th rowspan=2>$sysname $sysrev $ACE_ROOT\n";
145 print "$echoArgs $componentSize\n";
146 print ' <tr>' . "\n";
147 print "$echoArgs $componentPercentage\n";
148 print '</table></center><p>' . "\n";
152 ####
153 #### Build library with components specified in argument.
154 ####
155 sub build_lib ()
157 my ($lib_components) = @_;
159 unlink "$lib";
161 print "$make $make_args $lib_components\n" if $verbose;
163 system ("$make $make_args $lib_components >> make.log 2>&1") &&
164 die "$0: command failed; $make $make_args $lib_components\n";
166 my $libSize = 0;
168 open (SIZE, "$size $lib |") ||
169 die "$0: unable to open $size\n";
170 while (<SIZE>) {
171 my (@field) = split;
172 $libSize += $field[3] if $field[3] =~ /\d/; #### Skip size header line.
174 close (SIZE);
176 $libSize;
180 ####
181 #### Return percentage of first argument as fraction of second.
182 #### Returns a string with two-decimal place precision.
183 ####
184 sub percentage ()
186 my ($size, $total) = @_;
188 sprintf ("%.2f", $size * 100 / $total);