Merge pull request #2240 from DOCGroup/revert-2239-jwi-pi23
[ACE_TAO.git] / ACE / bin / pippen.pl
blobde06a32be69a0d740b0bb805740134e9b7fefca4
2 BEGIN {
3 use Cwd;
4 if (!$ENV{ACE_ROOT}) {
5 $ACE_ROOT = getcwd ()."\\";
6 print STDERR "Error: ACE_ROOT not defined\n";
7 exit 1;
9 else {
10 $ACE_ROOT = $ENV{ACE_ROOT};
13 use lib "$ACE_ROOT/bin";
14 use PerlACE::MSProject::DSP;
15 use PerlACE::MSProject::VCP;
16 use File::DosGlob 'glob';
17 use DirHandle;
18 use strict;
20 ################################################################################
22 my $extension;
23 my $recurse = 0;
24 my $list = 0;
25 my $verbose = 0;
26 my @arguments;
27 my @configs;
28 my @roots;
29 my $auto_compile = 0;
30 my $clean = 0;
31 my $debug = 0;
33 my $aceroot = 0;
35 ################################################################################
37 # Parse command line arguments
39 while ( $#ARGV >= 0)
41 if ($ARGV[0] =~ m/^-list/i) {
42 $list = 1;
44 elsif ($ARGV[0] =~ m/^-evc3/i) {
45 $extension = "vcp";
47 elsif ($ARGV[0] =~ m/^-msvc7/i) {
48 $extension = "vcproj";
50 elsif ($ARGV[0] =~ m/^-config/i) {
51 push @configs, $ARGV[1];
52 shift;
54 elsif ($ARGV[0] =~ m/^-r/i) {
55 $recurse = 1;
57 elsif ($ARGV[0] =~ m/^-v/i) {
58 $verbose = 1;
60 elsif ($ARGV[0] =~ m/^-auto_compile/i) {
61 $auto_compile = 1;
63 elsif ($ARGV[0] =~ m/^-clean/i) {
64 $clean = 1;
66 elsif ($ARGV[0] =~ m/^-useroot/i) {
67 push @roots, $ARGV[1];
68 shift;
70 elsif ($ARGV[0] =~ m/^-aceroot/i) {
71 $aceroot = 1;
73 elsif ($ARGV[0] =~ m/^-(\?|h)/i) { # Help information
74 print "Options\n";
75 print "-list - Prints out the list of project files\n";
76 print "-config <c> - Use <c> as a configuration\n";
77 print "-evc3 - Looks for eMbedded Visual C++ 3.0 projects\n";
78 print "-msvc7 - Looks for Visual C++ 7.0 projects\n";
79 print "-clean - Clean instead of building\n";
80 print "-recurse - Recurse into directories\n";
81 print "-verbose - Make some noise\n";
82 print "-auto_compile - Print out auto_compile info during build\n";
83 print "-useroot <dir> - Use <dir> as a root to look for dependencies\n";
84 print "-aceroot - Use %ACE_ROOT% as a dependency root\n";
85 exit;
87 elsif ($ARGV[0] =~ m/^-/) {
88 warn "$0: unknown option $ARGV[0]\n";
89 exit 1;
91 else {
92 push @arguments, $ARGV[0];
94 shift;
97 if ($#configs < 0) {
98 if (defined $ENV{WINMAKE_CONFIGS}) {
99 @configs = split /:/, $ENV{WINMAKE_CONFIGS};
101 elsif (defined $ENV{PIPPEN_CONFIGS}) {
102 @configs = split /:/, $ENV{PIPPEN_CONFIGS};
104 else {
105 print STDERR "Error: No config specified\n";
106 exit 1;
110 if (!defined $extension) {
111 my $compiler = '';
112 if (defined $ENV{WINMAKE_COMPILER}) {
113 $compiler = $ENV{WINMAKE_COMPILER};
115 elsif (defined $ENV{PIPPEN_COMPILER}) {
116 $compiler = $ENV{PIPPEN_COMPILER};
118 else {
119 print STDERR "Error: No compiler specified\n";
120 exit 1;
123 if ($compiler eq "evc3") {
124 $extension = "vcp";
126 elsif ($compiler eq "msvc7") {
127 $extension = "vcproj";
131 ################################################################################
133 # I like these variables
135 # %projects->{$file}->{BUILD} <- Are we supposed to build this file?
136 # ->{PROJ} <- MSProject object
137 # ->{CONFIGS}->{$config}->{DEPS} <- List of dependencies
138 # ->{DONE} <- Have we compiled it yet?
140 my %projects;
142 # %names->{$output} <- points to the $file used in the above %projects
144 my %names;
146 ################################################################################
148 # Expand all the files/directories passed in on the command line
150 sub ProjectSearch ($@)
152 my $build = shift;
153 my @targets = @_;
155 while ($#targets >= 0) {
156 my $target = $targets[0];
157 if (-d $target) {
158 print " Reading Directory $target\n" if ($verbose);
159 if ($recurse) {
160 my $dh = new DirHandle ($target);
162 if (defined $dh) {
163 foreach my $entry ($dh->read ()) {
164 if (-d "$target/$entry" && $entry ne "." && $entry ne "..") {
165 $entry =~ s/^.\\//; # / <- fix for color coding in devenv
166 push @targets, ($target . "\\". $entry);
170 else {
171 print STDERR "Error: Cannot read $target: $!\n";
175 foreach my $t (glob ($target . "\\*." . $extension)) {
176 print " Adding project $t\n" if ($verbose);
177 %projects->{$t}->{BUILD} = $build;
180 else {
181 foreach my $t (glob ($target)) {
182 print " Adding project $t\n" if ($verbose);
183 %projects->{$t}->{BUILD} = $build;
186 shift @targets;
190 print "=== Expanding Command line Arguments\n" if ($verbose);
192 if ($#arguments < 0) {
193 print " No files specified, defaulting to \".\"\n" if ($verbose);
194 push @arguments, (".");
197 ProjectSearch (1, @arguments);
199 print "=== Expanding Root Arguments\n" if ($verbose);
201 ProjectSearch (0, @roots);
203 if ($aceroot == 1) {
204 my $oldrecurse = $recurse;
205 $recurse = 1;
206 my @aceroots = ($ENV{ACE_ROOT}."\\ace",
207 $ENV{ACE_ROOT}."\\apps\\gperf\\src",
208 $ENV{ACE_ROOT}."\\TAO\\TAO_IDL",
209 $ENV{ACE_ROOT}."\\TAO\\tao",
210 $ENV{ACE_ROOT}."\\TAO\\orbsvcs\\orbsvcs");
211 ProjectSearch (0, @aceroots);
212 $recurse = $oldrecurse;
215 ################################################################################
217 # Read each project file to gather dependency and output information
219 print "=== Reading Project Files\n" if ($verbose);
221 foreach my $project (keys %projects) {
222 my $proj;
224 if ($project =~ m/\.dsp$/i) {
225 $proj = new PerlACE::MSProject::DSP ($project);
227 elsif ($project =~ m/\.vcp$/i) {
228 $proj = new PerlACE::MSProject::VCP ($project);
230 elsif ($project =~ m/\.vcproj$/i) {
231 print STDERR "Error: MSVC7 not supported yet\n";
233 else {
234 print STDERR "Error: Unrecognized file: $project\n";
237 print " Loading $project:" if ($verbose);
239 $proj->Load ();
241 foreach my $config (@configs) {
242 foreach my $proj_config ($proj->Configs ()) {
243 if ($proj_config =~ m/\Q$config\E/i) {
244 print " \"$proj_config\"" if ($verbose);
245 my $name = $proj->DepOutputFile ($proj_config);
247 %names->{lc $name} = $project;
248 my @deps = split / /, $proj->Libs ($proj_config);
250 foreach my $dep (@deps) {
251 # $dep =~ s/.*[\/\\]//g;
252 push (@{%projects->{$project}->{CONFIGS}->{$proj_config}->{DEPS}}, $dep);
254 if ($proj->UsesTAOIDL () == 1) {
255 push @{%projects->{$project}->{CONFIGS}->{$proj_config}->{DEPS}}, ("gperf.exe", "tao_idl.exe");
261 print "\n" if ($verbose);
263 %projects->{$project}->{PROJ} = $proj;
266 ################################################################################
268 # Clean out the dependency lists, we only keep the libraries which we know
269 # how to generate
271 print "=== Cleaning out Dependency Lists\n" if ($verbose);
273 foreach my $project (keys %projects) {
274 foreach my $config (keys %{%projects->{$project}->{CONFIGS}}) {
275 print " Cleaning Dependencies: $project ($config)\n" if ($verbose);
276 print " Before:", join (" ", @{%projects->{$project}->{CONFIGS}->{$config}->{DEPS}}), "\n" if ($verbose);
277 my @newdeps;
278 foreach my $dep (@{%projects->{$project}->{CONFIGS}->{$config}->{DEPS}}) {
279 $dep =~ s/.*[\/\\]//g;
281 if (defined %names->{lc $dep}) {
282 push @newdeps, $dep;
285 print " After:", join (" ", @newdeps), "\n" if ($verbose);
286 @{%projects->{$project}->{CONFIGS}->{$config}->{DEPS}} = @newdeps;
290 ################################################################################
292 # Make sure to build any dependencies found
294 print "=== Walking Dependency Lists\n" if ($verbose);
296 my $finished = 0;
298 do {
299 $finished = 1;
300 foreach my $project (keys %projects) {
301 foreach my $config (keys %{%projects->{$project}->{CONFIGS}}) {
302 if (%projects->{$project}->{BUILD} == 1) {
303 foreach my $dep (@{%projects->{$project}->{CONFIGS}->{$config}->{DEPS}}) {
304 if (%projects->{%names->{lc $dep}}->{BUILD} != 1) {
305 %projects->{%names->{lc $dep}}->{BUILD} = 1;
306 $finished = 0;
313 } while (!$finished);
316 ################################################################################
318 # Output a list, if requested
320 if ($debug) {
321 print "List of Dependencies\n";
322 print "--------------------\n";
323 foreach my $project (keys %projects) {
324 print "=== $project\n";
325 foreach my $config (keys %{%projects->{$project}->{CONFIGS}}) {
326 print " Config: $config\n";
327 print " Depends: ", join (" ", @{%projects->{$project}->{CONFIGS}->{$config}->{DEPS}}), "\n";
331 print "\n";
332 print "List of Outputs\n";
333 print "---------------\n";
335 foreach my $name (keys %names) {
336 print "$name\n";
340 ################################################################################
342 # Loop through and
344 print "=== Compiling\n" if ($verbose);
346 my $compilations; # Keep track of the number of compiles done during a pass
347 my $unfinished;
348 my $loop = 1;
350 do {
351 $compilations = 0;
352 $unfinished = 0;
354 foreach my $project (keys %projects) {
355 if (%projects->{$project}->{BUILD} == 1) {
356 foreach my $config (keys %{%projects->{$project}->{CONFIGS}}) {
357 if (%projects->{$project}->{CONFIGS}->{$config}->{DONE} != 1) {
358 my $depsleft = 0;
359 foreach my $dep (@{%projects->{$project}->{CONFIGS}->{$config}->{DEPS}}) {
360 if (%projects->{%names->{lc $dep}}->{CONFIGS}->{$config}->{DONE} != 1) {
361 ++$depsleft;
365 if ($depsleft == 0) {
366 ++$compilations;
367 print "Auto_compiling $project : $config\n" if ($auto_compile);
369 if ($list == 1) {
370 if ($clean == 1) {
371 print "Cleaning ";
373 else {
374 print "Compiling ";
377 print "$project : $config\n";
379 elsif ($clean == 1) {
380 %projects->{$project}->{PROJ}->Clean ($config);
382 else {
383 %projects->{$project}->{PROJ}->Build ($config);
386 %projects->{$project}->{CONFIGS}->{$config}->{DONE} = 1;
388 else {
389 ++$unfinished;
396 print " === Loop $loop: $compilations compiles, $unfinished left\n" if ($verbose);
397 ++$loop;
398 } while ($compilations != 0);
400 # Loop through and see if anything wasn't compiled. If so, this means either there is
401 # an error in the script or that there are circular dependencies
403 foreach my $project (keys %projects) {
404 if (%projects->{$project}->{BUILD} == 1) {
405 foreach my $config (keys %{%projects->{$project}->{CONFIGS}}) {
406 if (%projects->{$project}->{CONFIGS}->{$config}->{DONE} != 1) {
407 print STDERR "Error: Project not compiled: $project - $config\n",