back to unicode
[MPC.git] / modules / MakeWorkspaceBase.pm
blob3709f53a84812e3ab5dd272e52b2e97d5d1a4d2e
1 package MakeWorkspaceBase;
3 # ************************************************************
4 # Description : A Make Workspace base module
5 # Author : Chad Elliott
6 # Create Date : 11/21/2006
7 # ************************************************************
9 # ************************************************************
10 # Pragmas
11 # ************************************************************
13 use strict;
14 use MakePropertyBase;
16 use vars qw(@ISA);
17 @ISA = qw(MakePropertyBase);
19 # ************************************************************
20 # Subroutine Section
21 # ************************************************************
23 sub targets {
24 return $_[0]->{'make_targets'};
27 sub workspace_file_prefix {
28 #my $self = shift;
29 return 'Makefile';
33 sub workspace_file_extension {
34 #my $self = shift;
35 return '';
39 sub supports_make_coexistence {
40 return ($_[0]->workspace_file_extension() ne '');
44 sub workspace_file_name {
45 my $self = shift;
46 return $self->get_modified_workspace_name(
47 $self->workspace_file_prefix(),
48 $self->make_coexistence() ?
49 $self->workspace_file_extension() : '');
53 sub workspace_per_project {
54 #my $self = shift;
55 return 1;
59 sub workspace_preamble {
60 my($self, $fh, $crlf, $name, $id) = @_;
62 ## Optionally print the workspace comment
63 $self->print_workspace_comment($fh,
64 '# -*-Makefile-*-', $crlf,
65 '#----------------------------------------------------------------------------', $crlf,
66 '# ', $name, $crlf,
67 '#', $crlf,
68 '# ', $id, $crlf,
69 '#', $crlf,
70 '# This file was generated by MPC. Any changes made directly to', $crlf,
71 '# this file will be lost the next time it is generated.', $crlf,
72 '#', $crlf,
73 '# MPC Command:', $crlf,
74 '# ', $self->create_command_line_string($0, @ARGV), $crlf,
75 '#', $crlf,
76 '#----------------------------------------------------------------------------', $crlf,
77 $crlf);
80 sub write_top_level_rule {
81 my($self, $fh, $crlf, $list, $remain, $trans, $maxline, $target, $suffix) = @_;
83 if (defined $maxline) {
84 my $line = $target . ':';
85 foreach my $project (@$list) {
86 $line .= " $$trans{$project}$suffix";
88 if (length($line) < $maxline) {
89 print $fh $crlf, $line;
91 elsif (length($suffix) > 0) {
92 $$remain .= ' ' . $target;
94 else {
95 $$remain = $target . ' ' . $$remain;
98 else {
99 print $fh $crlf . $target . ':';
100 foreach my $project (@$list) {
101 print $fh " $$trans{$project}$suffix";
106 sub write_named_targets {
107 my($self, $fh, $crlf, $targnum, $list, $remain, $targpre, $allpre, $trans, $phony, $andsym, $maxline) = @_;
109 ## Save the targets for later
110 $self->{'make_targets'} = $remain;
112 ## Print out the "all" target
113 $self->write_top_level_rule($fh, $crlf, $list, \$remain,
114 $trans, $maxline, 'all', '');
115 print $fh $crlf;
117 ## Print out the "depend" target
118 $self->write_top_level_rule($fh, $crlf, $list, \$remain,
119 $trans, $maxline, 'depend', '-depend');
121 ## Print out all other targets here
122 print $fh "$crlf$crlf$remain:$crlf";
123 $self->write_project_targets($fh, $crlf,
124 $targpre . '$(@)', $list, $andsym);
126 ## Print out each target separately
127 foreach my $project (@$list) {
128 print $fh ($phony ? "$crlf.PHONY: $$trans{$project}" : ''),
129 $crlf, $$trans{$project}, ':';
130 if (defined $$targnum{$project}) {
131 foreach my $number (@{$$targnum{$project}}) {
132 print $fh " $$trans{$$list[$number]}";
135 print $fh $crlf;
136 $self->write_project_targets($fh, $crlf,
137 $targpre . $allpre . 'all',
138 [ $project ], $andsym);
139 print $fh ($phony ? "$crlf.PHONY: $$trans{$project}-depend" : ''),
140 $crlf, $$trans{$project}, '-depend:', $crlf;
141 $self->write_project_targets($fh, $crlf,
142 $targpre . $allpre . 'depend',
143 [ $project ], $andsym);
146 ## Print out the project_name_list target
147 print $fh $crlf, "project_name_list:$crlf";
148 foreach my $project (sort @$list) {
149 print $fh "\t\@echo $$trans{$project}$crlf";
154 sub post_workspace {
155 my($self, $wsfh, $creator, $toplevel) = @_;
157 if ($toplevel && $self->{'for_eclipse'}) {
158 my $crlf = $self->crlf();
159 my $outdir = $self->get_outdir();
160 my $fh = new FileHandle();
161 my $outfile = "$outdir/.cdtproject";
162 my $pjt = $self->get_eclipse_cdtproject();
164 if (open($fh, ">$outfile")) {
165 ## We want to set the make command to nmake for the nmake project
166 ## type. As far as stopping on an error, I don't remember why this
167 ## is true only for Borland make.
168 my $cmd = ("$self" =~ /^nmake/i ? 'nmake' : 'make');
169 my $stop = ("$self" =~ /^bmake/i ? 'true' : 'false');
170 print $fh $$pjt[0];
171 foreach my $target ('all',
172 grep(/^[\w\-]+$/, split(/\s+/, $self->targets()))) {
173 print $fh ' <target name="', $target, '" path="" targetID="org.eclipse.cdt.make.MakeTargetBuilder">', $crlf,
174 ' <buildCommand>', $cmd, '</buildCommand>', $crlf,
175 ' <buildArguments></buildArguments>', $crlf,
176 ' <buildTarget>', $target, '</buildTarget> ', $crlf,
177 ' <stopOnError>', $stop, '</stopOnError>', $crlf,
178 ' <useDefaultCommand>false</useDefaultCommand>', $crlf,
179 ' </target>', $crlf;
181 print $fh $$pjt[1];
182 close($fh);
184 else {
185 $self->warning("Unable to create $outfile");
188 ## Create the eclipse project which is unchanging except for the name
189 ## of the starting makefile.
190 $pjt = $self->get_eclipse_project();
191 $outfile = "$outdir/.project";
192 if (open($fh, ">$outfile")) {
193 print $fh $$pjt[0], $self->get_workspace_name(), $$pjt[1];
194 close($fh);
196 else {
197 $self->warning("Unable to create $outfile");
203 sub get_eclipse_cdtproject {
204 my $self = shift;
205 if (!defined $self->{'eclipse_cdtproject'}) {
206 $self->{'eclipse_cdtproject'} = [
207 '<?xml version="1.0" encoding="UTF-8"?>
208 <?eclipse-cdt version="2.0"?>
209 <cdtproject id="org.eclipse.cdt.make.core.make">
210 <extension id="org.eclipse.cdt.core.ELF" point="org.eclipse.cdt.core.BinaryParser"/>
211 <extension id="org.eclipse.cdt.core.nullindexer" point="org.eclipse.cdt.core.CIndexer"/>
212 <data>
213 <item id="scannerConfiguration">
214 <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile"/>
215 <profile id="org.eclipse.cdt.make.core.GCCStandardMakePerProjectProfile">
216 <buildOutputProvider>
217 <openAction enabled="true" filePath=""/>
218 <parser enabled="true"/>
219 </buildOutputProvider>
220 </profile>
221 <profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfile">
222 <buildOutputProvider>
223 <openAction enabled="false" filePath=""/>
224 <parser enabled="false"/>
225 </buildOutputProvider>
226 <scannerInfoProvider id="specsFile">
227 <runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/>
228 <parser enabled="false"/>
229 </scannerInfoProvider>
230 </profile>
231 <profile id="org.eclipse.cdt.managedbuilder.core.GCCWinManagedMakePerProjectProfile">
232 <buildOutputProvider>
233 <openAction enabled="false" filePath=""/>
234 <parser enabled="false"/>
235 </buildOutputProvider>
236 <scannerInfoProvider id="specsFile">
237 <runAction arguments="-E -P -v -dD ${plugin_state_location}/${specs_file}" command="gcc" useDefault="true"/>
238 <parser enabled="false"/>
239 </scannerInfoProvider>
240 </profile>
241 <profile id="org.eclipse.cdt.make.core.GCCStandardMakePerFileProfile">
242 <buildOutputProvider>
243 <openAction enabled="false" filePath=""/>
244 <parser enabled="false"/>
245 </buildOutputProvider>
246 <scannerInfoProvider id="makefileGenerator">
247 <runAction arguments="-f ${project_name}_scd.mk" command="make" useDefault="true"/>
248 <parser enabled="false"/>
249 </scannerInfoProvider>
250 </profile>
251 </item>
252 <item id="org.eclipse.cdt.core.pathentry">
253 <pathentry kind="src" path=""/>
254 <pathentry kind="out" path=""/>
255 <pathentry kind="con" path="org.eclipse.cdt.make.core.DISCOVERED_SCANNER_INFO"/>
256 </item>
257 <item id="org.eclipse.cdt.make.core.buildtargets">
258 <buildTargets>
261 ' </buildTargets>
262 </item>
263 </data>
264 </cdtproject>
267 return $self->{'eclipse_cdtproject'};
271 sub get_eclipse_project {
272 my $self = shift;
273 if (!defined $self->{'eclipse_project'}) {
274 $self->{'eclipse_project'} = [
275 '<?xml version="1.0" encoding="UTF-8"?>
276 <projectDescription>
277 <name>',
278 '</name>
279 <comment></comment>
280 <projects>
281 </projects>
282 <buildSpec>
283 <buildCommand>
284 <name>org.eclipse.cdt.make.core.makeBuilder</name>
285 <triggers>clean,full,incremental,</triggers>
286 <arguments>
287 <dictionary>
288 <key>org.eclipse.cdt.make.core.build.arguments</key>
289 <value></value>
290 </dictionary>
291 <dictionary>
292 <key>org.eclipse.cdt.core.errorOutputParser</key>
293 <value>org.eclipse.cdt.core.MakeErrorParser;org.eclipse.cdt.core.GCCErrorParser;org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.VCErrorParser;</value>
294 </dictionary>
295 <dictionary>
296 <key>org.eclipse.cdt.make.core.enableAutoBuild</key>
297 <value>false</value>
298 </dictionary>
299 <dictionary>
300 <key>org.eclipse.cdt.make.core.environment</key>
301 <value></value>
302 </dictionary>
303 <dictionary>
304 <key>org.eclipse.cdt.make.core.enableFullBuild</key>
305 <value>true</value>
306 </dictionary>
307 <dictionary>
308 <key>org.eclipse.cdt.make.core.build.target.inc</key>
309 <value>all</value>
310 </dictionary>
311 <dictionary>
312 <key>org.eclipse.cdt.make.core.enabledIncrementalBuild</key>
313 <value>true</value>
314 </dictionary>
315 <dictionary>
316 <key>org.eclipse.cdt.make.core.build.target.clean</key>
317 <value>clean</value>
318 </dictionary>
319 <dictionary>
320 <key>org.eclipse.cdt.make.core.build.command</key>
321 <value>make</value>
322 </dictionary>
323 <dictionary>
324 <key>org.eclipse.cdt.make.core.enableCleanBuild</key>
325 <value>true</value>
326 </dictionary>
327 <dictionary>
328 <key>org.eclipse.cdt.make.core.append_environment</key>
329 <value>true</value>
330 </dictionary>
331 <dictionary>
332 <key>org.eclipse.cdt.make.core.build.target.full</key>
333 <value>clean all</value>
334 </dictionary>
335 <dictionary>
336 <key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
337 <value>true</value>
338 </dictionary>
339 <dictionary>
340 <key>org.eclipse.cdt.make.core.build.target.auto</key>
341 <value>all</value>
342 </dictionary>
343 <dictionary>
344 <key>org.eclipse.cdt.make.core.stopOnError</key>
345 <value>false</value>
346 </dictionary>
347 </arguments>
348 </buildCommand>
349 <buildCommand>
350 <name>org.eclipse.cdt.make.core.ScannerConfigBuilder</name>
351 <arguments>
352 </arguments>
353 </buildCommand>
354 </buildSpec>
355 <natures>
356 <nature>org.eclipse.cdt.core.cnature</nature>
357 <nature>org.eclipse.cdt.make.core.makeNature</nature>
358 <nature>org.eclipse.cdt.make.core.ScannerConfigNature</nature>
359 <nature>org.eclipse.cdt.core.ccnature</nature>
360 </natures>
361 </projectDescription>
364 return $self->{'eclipse_project'};