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
 
15
use NMakeProjectCreator;
16
use WorkspaceCreator;
17
 
18
use vars qw(@ISA);
19
@ISA = qw(WorkspaceCreator);
20
 
21
# ************************************************************
22
# Data Section
23
# ************************************************************
24
 
25
my(@targets) = ('CLEAN', 'DEPEND', 'GENERATED', 'REALCLEAN',
26
                '$(CUSTOM_TARGETS)');
27
 
28
# ************************************************************
29
# Subroutine Section
30
# ************************************************************
31
 
32
sub supports_make_coexistence {
33
  #my($self) = shift;
34
  return 1;
35
}
36
 
37
 
38
sub crlf {
39
  my($self) = shift;
40
  return $self->windows_crlf();
41
}
42
 
43
 
44
sub workspace_per_project {
45
  #my($self) = shift;
46
  return 1;
47
}
48
 
49
 
50
sub workspace_file_name {
51
  my($self) = shift;
52
  if ($self->make_coexistence()) {
53
    return $self->get_modified_workspace_name($self->get_workspace_name(),
54
                                              '.nmake');
55
  }
56
  else {
57
    return $self->get_modified_workspace_name('Makefile', '');
58
  }
59
}
60
 
61
 
62
sub pre_workspace {
63
  my($self) = shift;
64
  my($fh)   = shift;
65
  my($crlf) = $self->crlf();
66
 
67
  print $fh '# Microsoft Developer Studio Generated NMAKE File', $crlf,
68
            '#', $crlf,
69
            '# $Id: NMakeWorkspaceCreator.pm 217 2006-05-05 09:35:48Z bj $', $crlf,
70
            '#', $crlf,
71
            '# This file was generated by MPC.  Any changes made directly to', $crlf,
72
            '# this file will be lost the next time it is generated.', $crlf,
73
            '#', $crlf,
74
            '# MPC Command:', $crlf,
75
            "# $0 @ARGV", $crlf,
76
            $crlf;
77
}
78
 
79
 
80
sub write_project_targets {
81
  my($self)     = shift;
82
  my($fh)       = shift;
83
  my($target)   = shift;
84
  my($list)     = shift;
85
  my($crlf)     = $self->crlf();
198 bj 86
  my($cwd)      = $self->getcwd();
107 bj 87
 
88
  foreach my $project (@$list) {
89
    my($dir)    = $self->mpc_dirname($project);
90
    my($chdir)  = 0;
91
    my($back)   = '';
92
 
93
    ## If the directory isn't '.' then we need
94
    ## to figure out how to get back to our starting point
95
    if ($dir ne '.') {
96
      $chdir = 1;
198 bj 97
      my($count) = ($dir =~ tr/\///) + 1;
217 bj 98
      if (index($dir, '../') == 0) {
198 bj 99
        ## Find out how many directories we went down
100
        my($rel) = $dir;
101
        while($rel =~ s/^\.\.\///) {
102
        }
103
        my($down) = ($rel =~ tr/\///) + 1;
104
 
105
        ## Get $count - $down parts of the base of the current directory
106
        $rel = $cwd;
107
        my($index) = length($rel);
108
        for(my $i = $down; $i < $count; $i++) {
109
          $index = rindex($rel, '/', $index - 1);
110
        }
111
        if ($index > -1) {
112
          $rel = substr($rel, $index + 1);
113
        }
114
        $back = ('../' x $down) . $rel;
107 bj 115
      }
116
      else {
198 bj 117
        $back = ('../' x $count);
107 bj 118
      }
119
    }
120
 
121
    print $fh ($chdir ? "\tcd $dir$crlf" : ''),
217 bj 122
              "\t\$(MAKE) /f ", $self->mpc_basename($project),
123
              " $target$crlf",
107 bj 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)  = ();
217 bj 136
  my(@list)     = $self->number_target_deps($projects, $pjs, \%targnum, 0);
107 bj 137
  my($crlf)     = $self->crlf();
138
  my($default)  = 'Win32 Debug';
139
 
140
  ## Determine the default configuration
141
  foreach my $project (keys %$pjs) {
217 bj 142
    my($name, $deps, $pguid, $lang, @cfgs) = @{$pjs->{$project}};
107 bj 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;