Subversion Repositories gelsvn

Rev

Rev 217 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
107 bj 1
package BMakeWorkspaceCreator;
2
 
3
# ************************************************************
4
# Description   : A Borland Make Workspace (Makefile) creator
5
# Author        : Chad Elliott
6
# Create Date   : 2/03/2004
7
# ************************************************************
8
 
9
# ************************************************************
10
# Pragmas
11
# ************************************************************
12
 
13
use strict;
14
 
15
use BMakeProjectCreator;
16
use WorkspaceCreator;
17
 
18
use vars qw(@ISA);
19
@ISA = qw(WorkspaceCreator);
20
 
21
# ************************************************************
22
# Data Section
23
# ************************************************************
24
 
25
my($max_line_length) = 32767; ## Borland Make's maximum line length
26
my(@targets) = ('clean', 'generated', 'realclean', '$(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_file_name {
45
  my($self) = shift;
46
  if ($self->make_coexistence()) {
47
    return $self->get_modified_workspace_name($self->get_workspace_name(),
48
                                              '.bmake');
49
  }
50
  else {
51
    return $self->get_modified_workspace_name('Makefile', '');
52
  }
53
}
54
 
55
 
56
sub workspace_per_project {
57
  #my($self) = shift;
58
  return 1;
59
}
60
 
61
 
62
sub pre_workspace {
63
  my($self) = shift;
64
  my($fh)   = shift;
65
  my($crlf) = $self->crlf();
66
 
67
  print $fh '#----------------------------------------------------------------------------', $crlf,
68
            '#       Borland Workspace Makefile', $crlf,
69
            '#', $crlf,
70
            '# $Id: BMakeWorkspaceCreator.pm 217 2006-05-05 09:35:48Z 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
            '#----------------------------------------------------------------------------', $crlf,
79
            $crlf;
80
}
81
 
82
 
83
sub write_project_targets {
84
  my($self)     = shift;
85
  my($fh)       = shift;
86
  my($target)   = shift;
87
  my($list)     = shift;
88
  my($crlf)     = $self->crlf();
198 bj 89
  my($cwd)      = $self->getcwd();
107 bj 90
 
91
  foreach my $project (@$list) {
92
    my($dir)   = $self->mpc_dirname($project);
93
    my($chdir) = 0;
94
    my($back)  = '';
95
 
96
    ## If the directory isn't '.' then we need
97
    ## to figure out how to get back to our starting point
98
    if ($dir ne '.') {
99
      $chdir = 1;
198 bj 100
      my($count) = ($dir =~ tr/\///) + 1;
217 bj 101
      if (index($dir, '../') == 0) {
198 bj 102
        ## Find out how many directories we went down
103
        my($rel) = $dir;
104
        while($rel =~ s/^\.\.\///) {
105
        }
106
        my($down) = ($rel =~ tr/\///) + 1;
107
 
108
        ## Get $count - $down parts of the base of the current directory
109
        $rel = $cwd;
110
        my($index) = length($rel);
111
        for(my $i = $down; $i < $count; $i++) {
112
          $index = rindex($rel, '/', $index - 1);
113
        }
114
        if ($index > -1) {
115
          $rel = substr($rel, $index + 1);
116
        }
117
        $back = ('../' x $down) . $rel;
107 bj 118
      }
119
      else {
198 bj 120
        $back = ('../' x $count);
107 bj 121
      }
122
    }
123
 
124
    print $fh ($chdir ? "\t\@cd $dir$crlf" : ''),
217 bj 125
              "\t\$(MAKE) -\$(MAKEFLAGS) -f ",
126
              $self->mpc_basename($project), " $target$crlf",
107 bj 127
              ($chdir ? "\t\@cd $back$crlf" : '');
128
  }
129
}
130
 
131
 
132
sub write_comps {
133
  my($self)     = shift;
134
  my($fh)       = shift;
135
  my($projects) = $self->get_projects();
136
  my($pjs)      = $self->get_project_info();
137
  my(%targnum)  = ();
217 bj 138
  my(@list)     = $self->number_target_deps($projects, $pjs, \%targnum, 0);
107 bj 139
  my($crlf)     = $self->crlf();
140
  my(@ltargets) = @targets;
141
 
142
  ## Set up the custom targets
143
  print $fh '!ifndef CUSTOM_TARGETS', $crlf,
144
            'CUSTOM_TARGETS=_EMPTY_TARGET_', $crlf,
145
            '!endif', $crlf;
146
 
147
  ## Construct the "all" target
148
  my($all) = 'all:';
149
  foreach my $project (@list) {
150
    $all .= " $$pjs{$project}->[0]";
151
  }
152
  if (length($all) < $max_line_length) {
153
    print $fh $crlf, $all, $crlf;
154
  }
155
  else {
156
    unshift(@ltargets, 'all');
157
  }
158
 
159
  ## Print out all other targets here
160
  foreach my $target (@ltargets) {
161
    print $fh $crlf, $target, ':', $crlf;
162
    $self->write_project_targets($fh, $target, \@list);
163
  }
164
 
165
  ## Print out each target separately
166
  foreach my $project (@list) {
167
    print $fh $crlf, $$pjs{$project}->[0], ':';
168
    if (defined $targnum{$project}) {
169
      foreach my $number (@{$targnum{$project}}) {
170
        print $fh " $$pjs{$list[$number]}->[0]";
171
      }
172
    }
173
 
174
    print $fh $crlf;
175
    $self->write_project_targets($fh, 'all', [ $project ]);
176
  }
177
 
178
  ## Print out the project_name_list target
179
  print $fh $crlf, 'project_name_list:', $crlf;
180
  foreach my $project (sort @list) {
181
    print $fh "\t\@echo $$pjs{$project}->[0]$crlf";
182
  }
183
}
184
 
185
 
186
 
187
1;