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