Subversion Repositories gelsvn

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
107 bj 1
package NMakeWorkspaceCreator;
2
 
3
# ************************************************************
4
# Description   : A NMake Workspace (Makefile) creator
5
# Author        : Chad Elliott
6
# Create Date   : 6/10/2002
7
# ************************************************************
8
 
9
# ************************************************************
10
# Pragmas
11
# ************************************************************
12
 
13
use strict;
14
use File::Basename;
15
 
16
use NMakeProjectCreator;
17
use WorkspaceCreator;
18
 
19
use vars qw(@ISA);
20
@ISA = qw(WorkspaceCreator);
21
 
22
# ************************************************************
23
# Data Section
24
# ************************************************************
25
 
26
my(@targets) = ('CLEAN', 'DEPEND', 'GENERATED', 'REALCLEAN',
27
                '$(CUSTOM_TARGETS)');
28
 
29
# ************************************************************
30
# Subroutine Section
31
# ************************************************************
32
 
33
sub supports_make_coexistence {
34
  #my($self) = shift;
35
  return 1;
36
}
37
 
38
 
39
sub crlf {
40
  my($self) = shift;
41
  return $self->windows_crlf();
42
}
43
 
44
 
45
sub workspace_per_project {
46
  #my($self) = shift;
47
  return 1;
48
}
49
 
50
 
51
sub workspace_file_name {
52
  my($self) = shift;
53
  if ($self->make_coexistence()) {
54
    return $self->get_modified_workspace_name($self->get_workspace_name(),
55
                                              '.nmake');
56
  }
57
  else {
58
    return $self->get_modified_workspace_name('Makefile', '');
59
  }
60
}
61
 
62
 
63
sub pre_workspace {
64
  my($self) = shift;
65
  my($fh)   = shift;
66
  my($crlf) = $self->crlf();
67
 
68
  print $fh '# Microsoft Developer Studio Generated NMAKE File', $crlf,
69
            '#', $crlf,
70
            '# $Id: NMakeWorkspaceCreator.pm 198 2005-12-15 11:30:53Z bj $', $crlf,
71
            '#', $crlf,
72
            '# This file was generated by MPC.  Any changes made directly to', $crlf,
73
            '# this file will be lost the next time it is generated.', $crlf,
74
            '#', $crlf,
75
            '# MPC Command:', $crlf,
76
            "# $0 @ARGV", $crlf,
77
            $crlf;
78
}
79
 
80
 
81
sub write_project_targets {
82
  my($self)     = shift;
83
  my($fh)       = shift;
84
  my($target)   = shift;
85
  my($list)     = shift;
86
  my($crlf)     = $self->crlf();
198 bj 87
  my($cwd)      = $self->getcwd();
107 bj 88
 
89
  foreach my $project (@$list) {
90
    my($dir)    = $self->mpc_dirname($project);
91
    my($chdir)  = 0;
92
    my($back)   = '';
93
 
94
    ## If the directory isn't '.' then we need
95
    ## to figure out how to get back to our starting point
96
    if ($dir ne '.') {
97
      $chdir = 1;
198 bj 98
      my($count) = ($dir =~ tr/\///) + 1;
107 bj 99
      if ($dir =~ /^\.\.\//) {
198 bj 100
        ## Find out how many directories we went down
101
        my($rel) = $dir;
102
        while($rel =~ s/^\.\.\///) {
103
        }
104
        my($down) = ($rel =~ tr/\///) + 1;
105
 
106
        ## Get $count - $down parts of the base of the current directory
107
        $rel = $cwd;
108
        my($index) = length($rel);
109
        for(my $i = $down; $i < $count; $i++) {
110
          $index = rindex($rel, '/', $index - 1);
111
        }
112
        if ($index > -1) {
113
          $rel = substr($rel, $index + 1);
114
        }
115
        $back = ('../' x $down) . $rel;
107 bj 116
      }
117
      else {
198 bj 118
        $back = ('../' x $count);
107 bj 119
      }
120
    }
121
 
122
    print $fh ($chdir ? "\tcd $dir$crlf" : ''),
123
              "\t\$(MAKE) /f ", basename($project), " $target$crlf",
124
              ($chdir ? "\tcd $back$crlf" : '');
125
  }
126
}
127
 
128
 
129
sub write_comps {
130
  my($self)     = shift;
131
  my($fh)       = shift;
132
  my($projects) = $self->get_projects();
133
  my($pjs)      = $self->get_project_info();
134
  my($trans)    = $self->project_target_translation();
135
  my(%targnum)  = ();
136
  my(@list)     = $self->number_target_deps($projects, $pjs, \%targnum);
137
  my($crlf)     = $self->crlf();
138
  my($default)  = 'Win32 Debug';
139
 
140
  ## Determine the default configuration
141
  foreach my $project (keys %$pjs) {
142
    my($name, $deps, $pguid, @cfgs) = @{$pjs->{$project}};
143
    @cfgs = sort @cfgs;
144
    if (defined $cfgs[0]) {
145
      $default = $cfgs[0];
146
      $default =~ s/(.*)\|(.*)/$2 $1/;
147
      last;
148
    }
149
  }
150
 
151
  ## Print out the content
152
  print $fh '!IF "$(CFG)" == ""', $crlf,
153
            'CFG=', $default, $crlf,
154
            '!MESSAGE No configuration specified. ',
155
            'Defaulting to ', $default, '.', $crlf,
156
            '!ENDIF', $crlf, $crlf,
157
            '!IF "$(CUSTOM_TARGETS)" == ""', $crlf,
158
            'CUSTOM_TARGETS=_EMPTY_TARGET_', $crlf,
159
            '!ENDIF', $crlf;
160
 
161
  ## Print out the "all" target
162
  print $fh $crlf, 'ALL:';
163
  foreach my $project (@list) {
164
    print $fh " $$trans{$project}";
165
  }
166
  print $fh $crlf;
167
 
168
  ## Print out all other targets here
169
  foreach my $target (@targets) {
170
    print $fh $crlf,
171
              $target, ':', $crlf;
172
    $self->write_project_targets($fh, 'CFG="$(CFG)" ' . $target, \@list);
173
  }
174
 
175
  ## Print out each target separately
176
  foreach my $project (@list) {
177
    print $fh $crlf, $$trans{$project}, ':';
178
    if (defined $targnum{$project}) {
179
      foreach my $number (@{$targnum{$project}}) {
180
        print $fh " $$trans{$list[$number]}";
181
      }
182
    }
183
 
184
    print $fh $crlf;
185
    $self->write_project_targets($fh, 'CFG="$(CFG)" ' . 'ALL', [ $project ]);
186
  }
187
 
188
  ## Print out the project_name_list target
189
  print $fh $crlf, "project_name_list:$crlf";
190
  foreach my $project (sort @list) {
191
    print $fh "\t\@echo $$trans{$project}$crlf";
192
  }
193
}
194
 
195
 
196
 
197
1;