Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / bin / PerlACE / MSProject.pm
blob1797a609e81e40a9e80ff3dcbcc5e40d64fce4b1
1 #!/usr/bin/env perl
3 package PerlACE::MSProject;
5 use strict;
6 use FileHandle;
8 ###############################################################################
10 # Constructor
12 sub new
14 my $proto = shift;
15 my $class = ref ($proto) || $proto;
16 my $self = {};
18 $self->{FILENAME} = shift;
19 $self->{VERSION} = undef;
20 $self->{NAME} = undef;
21 %{$self->{CONFIGS}} = ();
23 bless ($self, $class);
24 return $self;
27 ###############################################################################
29 # Accessors
31 sub Filename
33 my $self = shift;
35 if (@_ != 0) {
36 $self->{FILENAME} = shift;
39 return $self->{FILENAME};
42 sub Version ()
44 my $self = shift;
45 return $self->{VERSION};
48 sub Name ()
50 my $self = shift;
51 return $self->{NAME};
54 sub Configs ()
56 my $self = shift;
57 return keys %{$self->{CONFIGS}};
60 sub DepOutputFile ($)
62 my $self = shift;
63 my $config = shift;
65 if (!defined $config) {
66 print STDERR "Error: No configuration specified\n";
67 return;
70 my $name = $self->OutputFile ($config);
72 if ($name =~ m/\.dll$/) {
73 $name = $self->LibraryFile ($config);
76 $name =~ s/.*\\//; # / <- For devenv
77 $name =~ s/.*\///;
79 return $name;
82 sub OutputFile ($)
84 my $self = shift;
85 my $config = shift;
87 if (!defined $config) {
88 print STDERR "Error: No configuration specified\n";
89 return;
92 if (%{$self->{CONFIGS}}->{$config}->{LINK} =~ m/out\:\"([^\"]*)\"/) {
93 return $1;
95 elsif (defined $self->Name ()) {
96 my $filename = $self->Filename;
97 my $ext = "";
99 if (%{$self->{CONFIGS}}->{$config}->{LINK} =~ m/\/dll/) {
100 $ext = ".dll";
102 elsif (%{$self->{CONFIGS}}->{$config}->{LINK} =~ m/\/subsystem\:/) {
103 $ext = ".exe";
105 else {
106 $ext = ".lib";
109 $filename =~ s/\.[^\.]*$/$ext/;
110 return $filename;
115 sub LibraryFile ($)
117 my $self = shift;
118 my $config = shift;
119 my $dll = undef;
121 if (!defined $config) {
122 print STDERR "Error: No configuration specified\n";
123 return;
126 if ($self->OutputFile ($config) =~ m/([^\/\\]*)\.dll$/i) {
127 $dll = $1;
130 if (defined $dll) {
131 if (%{$self->{CONFIGS}}->{$config}->{LINK} =~ m/implib\:\"([^\"]*)\"/i) {
132 return $1;
134 else {
135 $dll =~ s/.*\\//ig; # / <- Just here to fix color coding in devenv beta
136 return $self->OutputDir ($config). $dll . ".lib";
141 sub OutputDir ($)
143 my $self = shift;
144 my $config = shift;
146 if (!defined $config) {
147 print STDERR "Error: No configuration specified\n";
148 return;
151 return %{$self->{CONFIGS}}->{$config}->{OUTPUTDIR};
154 sub IntermidiateDir ($)
156 my $self = shift;
157 my $config = shift;
159 if (!defined $config) {
160 print STDERR "Error: No configuration specified\n";
161 return;
164 return %{$self->{CONFIGS}}->{$config}->{INTERMEDIATEDIR};
167 sub TargetDir ($)
169 my $self = shift;
170 my $config = shift;
172 if (!defined $config) {
173 print STDERR "Error: No configuration specified\n";
174 return;
177 return %{$self->{CONFIGS}}->{$config}->{TARGETDIR};
180 sub CPPOptions ($)
182 my $self = shift;
183 my $config = shift;
185 if (!defined $config) {
186 print STDERR "Error: No configuration specified\n";
187 return;
190 return %{$self->{CONFIGS}}->{$config}->{CPP};
193 sub LINKOptions ($)
195 my $self = shift;
196 my $config = shift;
198 if (!defined $config) {
199 print STDERR "Error: No configuration specified\n";
200 return;
203 return %{$self->{CONFIGS}}->{$config}->{LINK};
206 sub Libs($)
208 my $self = shift;
209 my $config = shift;
211 if (!defined $config) {
212 print STDERR "Error: No configuration specified\n";
213 return;
216 return %{$self->{CONFIGS}}->{$config}->{LIBS};
219 sub UsesTAOIDL ()
221 my $self = shift;
223 return $self->{TAOIDL};
226 sub Compiler ()
228 my $self = shift;
230 return $self->{COMPILER};
233 ###############################################################################
235 # Big methods
237 sub Load ()
239 my $self = shift;
240 my $config = "Unknown";
242 $self->{valid} = 0;
244 my $fh = new FileHandle;
246 unless ($fh->open ("<" . $self->{FILENAME})) {
247 print "Could not open file ", $self->{FILENAME}, ": ", $_;
248 return;
251 while (<$fh>) {
252 if (m/^\#.*Project File - Name=\"([^\"]*)\"/) {
253 $self->{NAME} = $1;
256 if (m/^\#.*Format Version (.*)/) {
257 $self->{VERSION} = $1;
260 # Check for configurations
262 if (m/^\!.*IF \"\$\(CFG\)\" == \".* - (.*)$\"/) {
263 $config = $1;
265 elsif (m/^\!ENDIF$/) {
266 $config = "";
269 # Check for directories
271 if (m/\# PROP Output_Dir \"(.*)\"/) {
272 %{$self->{CONFIGS}}->{$config}->{OUTPUTDIR} = $1;
274 elsif (m/\# PROP Intermediate_Dir \"(.*)\"/) {
275 %{$self->{CONFIGS}}->{$config}->{INTERMEDIATEDIR} = $1;
277 elsif (m/\# PROP Target_Dir \"(.*)\"/) {
278 %{$self->{CONFIGS}}->{$config}->{TARGETDIR} = $1;
281 # Look at CPP options
283 if (m/\# ADD BASE CPP(.*)$/ || m/\# ADD CPP(.*)$/) {
284 my @flags = split (/ \//, $1);
286 foreach my $flag (@flags) {
287 if ($flag && %{$self->{CONFIGS}}->{$config}->{CPP} !~ m/$flag/) {
288 %{$self->{CONFIGS}}->{$config}->{CPP} .= " /$flag";
292 elsif (m/\# SUBTRACT CPP(.*)$/ || m/\# SUBTRACT BASE CPP(.*)$/) {
293 my @flags = split (/ \//, $1);
295 foreach my $flag (@flags) {
296 if ($flag && %{$self->{CONFIGS}}->{$config}->{CPP} =~ m/$flag/) {
297 %{$self->{CONFIGS}}->{$config}->{CPP} =~ s/ \/$flag//g;
302 # Look at LINK32 options
304 if (m/\# ADD BASE LINK32(.*)$/ || m/\# ADD LINK32(.*)$/
305 || m/\# ADD BASE LIB32(.*)$/ || m/\# ADD LIB32(.*)$/) {
306 my @flags = split (/ \//, $1);
308 foreach my $flag (@flags) {
309 my $found = 0;
310 my @libs = split (/ /, $flag);
312 foreach my $lib (@libs) {
313 if ($lib =~ m/\.lib$/) {
314 if (%{$self->{CONFIGS}}->{$config}->{LIBS} !~ m/\Q$lib\E/) {
315 %{$self->{CONFIGS}}->{$config}->{LIBS} .= " $lib";
317 $found = 1;
321 if (!$found && $flag) {
322 my $shortflag = $flag;
323 if ($flag =~ m/^(.*)\:/) {
324 $shortflag = $1;
327 if (%{$self->{CONFIGS}}->{$config}->{LINK} !~ m/ \/$shortflag/) {
328 %{$self->{CONFIGS}}->{$config}->{LINK} .= " /$flag";
333 elsif (m/\# SUBTRACT BASE LINK32(.*)$/ || m/\# SUBTRACT LINK32(.*)$/
334 || m/\# SUBTRACT BASE LIB32(.*)$/ || m/\# SUBTRACT LIB32(.*)$/) {
335 my @flags = split (/ \//, $1);
337 foreach my $flag (@flags) {
338 my $shortflag = $flag;
339 if ($flag =~ m/^(.*)\:/) {
340 $shortflag = $1;
343 if ($flag && %{$self->{CONFIGS}}->{$config}->{LINK} =~ m/ (\/$shortflag\:[^ ]*)/) {
344 %{$self->{CONFIGS}}->{$config}->{LINK} =~ s/ \Q$1\E//ig;
349 if (m/^\# Name \".* - (.*)\"/ && defined %{$self->{CONFIGS}}->{"Unknown"}) {
350 %{$self->{CONFIGS}}->{$1} = %{$self->{CONFIGS}}->{"Unknown"};
351 delete %{$self->{CONFIGS}}->{"Unknown"};
354 if (m/tao\_idl/ && m/\$\(InputName\)\.idl/ || m/tao\_idl/ && m/\$\(InputPath\)/) {
355 $self->{TAOIDL} = 1;
358 $fh->close ();
359 $self->{valid} = 1;
362 ###############################################################################
364 # Build functions
366 sub Build ($)
368 my $self = shift;
369 my ($config) = @_;
371 my $command = $self->Compiler () . " " . $self->Filename ()
372 . " /USEENV"
373 . " /MAKE \"" . $self->Name ()
374 . " - " . $config . "\"";
376 system $command;
379 sub Clean ($)
381 my $self = shift;
382 my ($config) = @_;
384 my $command = $self->Compiler () . " " . $self->Filename ()
385 . " /USEENV"
386 . " /MAKE \"" . $self->Name ()
387 . " - " . $config . "\" /CLEAN";
389 system $command;