Merge pull request #228 from DOCGroup/jwillemsen-patch-1
[MPC.git] / modules / NMakeWorkspaceCreator.pm
blobaa30b965a1d73eb9049ffd995648f5ecd8fa8b64
1 package NMakeWorkspaceCreator;
3 # ************************************************************
4 # Description : A NMake Workspace (Makefile) creator
5 # Author : Chad Elliott
6 # Create Date : 6/10/2002
7 # ************************************************************
9 # ************************************************************
10 # Pragmas
11 # ************************************************************
13 use strict;
15 use NMakeProjectCreator;
16 use MakeWorkspaceBase;
17 use WinWorkspaceBase;
18 use WorkspaceCreator;
19 use VCPropertyBase;
21 use vars qw(@ISA);
22 @ISA = qw(MakeWorkspaceBase WinWorkspaceBase WorkspaceCreator VCPropertyBase);
24 # ************************************************************
25 # Data Section
26 # ************************************************************
28 my $targets = 'clean generated realclean $(CUSTOM_TARGETS)';
30 # ************************************************************
31 # Subroutine Section
32 # ************************************************************
34 sub workspace_file_extension {
35 #my $self = shift;
36 return '.mak';
40 sub pre_workspace {
41 my($self, $fh) = @_;
42 $self->workspace_preamble($fh, $self->crlf(), 'NMAKE Workspace',
43 '');
47 sub write_project_targets {
48 my($self, $fh, $crlf, $target, $list) = @_;
49 my $cwd = $self->getcwd();
51 ## Print out a make command for each project
52 foreach my $project (@$list) {
53 my $dir = $self->mpc_dirname($project);
54 my $chdir = ($dir ne '.');
56 print $fh ($chdir ? "\t\@cd $dir$crlf\t\@echo Directory: $dir$crlf" : ''),
57 "\t\@echo Project: ", $self->mpc_basename($project), $crlf,
58 "\t\$(MAKE) /\$(MAKEFLAGS) /f ", $self->mpc_basename($project),
59 " $target$crlf",
60 ($chdir ? "\t\@cd \$(MAKEDIR)$crlf" : '');
65 sub write_comps {
66 my($self, $fh, $gen) = @_;
67 my %targnum;
68 my $pjs = $self->get_project_info();
69 my @list = $self->number_target_deps($self->get_projects(), $pjs,
70 \%targnum, 0);
71 my $crlf = $self->crlf();
72 my $default = 'Win32 Debug';
74 ## Determine the default configuration. We want to get the Debug
75 ## configuration (if available). It just so happens that Debug comes
76 ## before Release so sorting the configurations works in our favor.
77 foreach my $project (keys %$pjs) {
78 my @cfgs = sort $gen->access_pi_values($pjs, $project,
79 ProjectCreator::CONFIGURATIONS);
80 if (defined $cfgs[0]) {
81 $default = $cfgs[0];
83 ## The configuration comes out in the form that is usable to Visual
84 ## Studio. We need it to be in the form that was chosen for the
85 ## nmake configuration. So, we just swap the parts and remove the
86 ## '|' character.
87 $default =~ s/(.*)\|(.*)/$2 $1/;
88 last;
92 ## Print out the content
93 print $fh '!IF "$(CFG)" == ""', $crlf,
94 'CFG=', $default, $crlf,
95 '!MESSAGE No configuration specified. ',
96 'Defaulting to ', $default, '.', $crlf,
97 '!ENDIF', $crlf, $crlf,
98 '!IF "$(CUSTOM_TARGETS)" == ""', $crlf,
99 'CUSTOM_TARGETS=_EMPTY_TARGET_', $crlf,
100 '!ENDIF', $crlf;
102 ## Send all the information to our base class method
103 $self->write_named_targets($fh, $crlf, \%targnum, \@list,
104 $targets, 'CFG="$(CFG)" ', '',
105 $self->project_target_translation());
109 sub get_properties {
110 my $self = shift;
112 ## Create the map of properties that we support.
113 my $props = {};
115 ## Merge in properties from all base projects
116 foreach my $base (@ISA) {
117 my $func = $base . '::get_properties';
118 my $p = $self->$func();
119 foreach my $key (keys %$p) {
120 $$props{$key} = $$p{$key};
124 return $props;