|
1 # Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # |
|
15 |
|
16 |
|
17 package Cl_mingw; |
|
18 |
|
19 my $MinGWInstall='$(EPOCROOT)epoc32\\gcc_mingw\\bin'; |
|
20 my $MinGWPreInclude='$(EPOCINC)\\gcc_mingw\\gcc_mingw.h'; |
|
21 |
|
22 my $GccPrefix=''; |
|
23 my $ToolPrefix=''; |
|
24 my $HelperLib=''; |
|
25 my %PlatOpt=( |
|
26 'Dlltool'=>'', |
|
27 'Gcc'=>'', |
|
28 'Ld'=>'', |
|
29 # MinGW > 3.2.3 has been found to generate programs that crash (rombuild in particular) |
|
30 # and a workaround this appears to be to use specific optimisations rather than |
|
31 # specifying -O options |
|
32 'Optimize'=>'-fdefer-pop -fmerge-constants '. |
|
33 '-fthread-jumps -floop-optimize '. |
|
34 '-fif-conversion -fif-conversion2 '. |
|
35 '-fguess-branch-probability -fcprop-registers '. |
|
36 '-fforce-mem -foptimize-sibling-calls -fstrength-reduce '. |
|
37 '-fcse-follow-jumps -fcse-skip-blocks '. |
|
38 '-frerun-cse-after-loop -frerun-loop-opt '. |
|
39 '-fgcse -fgcse-lm -fgcse-sm -fgcse-las '. |
|
40 '-fdelete-null-pointer-checks '. |
|
41 '-fexpensive-optimizations '. |
|
42 '-fregmove '. |
|
43 '-fschedule-insns -fschedule-insns2 '. |
|
44 '-fsched-interblock -fsched-spec '. |
|
45 '-fcaller-saves '. |
|
46 '-fpeephole2 '. |
|
47 '-freorder-blocks -freorder-functions '. |
|
48 '-fstrict-aliasing '. |
|
49 '-funit-at-a-time '. |
|
50 '-falign-functions -falign-jumps '. |
|
51 '-falign-loops -falign-labels '. |
|
52 '-fcrossjumping' |
|
53 |
|
54 ); |
|
55 my $Dlltool; |
|
56 my $Archive; |
|
57 my $Link; |
|
58 my $Objcopy; |
|
59 |
|
60 my @Win32LibList=(); |
|
61 my $Win32StdHeaders; |
|
62 |
|
63 |
|
64 require Exporter; |
|
65 @ISA=qw(Exporter); |
|
66 |
|
67 @EXPORT=qw( |
|
68 PMHelp_Mmp |
|
69 PMCheckPlatformL |
|
70 PMPlatProcessMmp |
|
71 PMStartBldList |
|
72 PMBld |
|
73 PMStartSrcList |
|
74 PMStartSrc |
|
75 PMSrcDepend |
|
76 PMSrcBldDepend |
|
77 PMEndSrcBld |
|
78 PMEndSrc |
|
79 PMEndSrcList |
|
80 ); |
|
81 |
|
82 use strict; |
|
83 use cl_generic; |
|
84 use Genutl; |
|
85 use Winutl; |
|
86 |
|
87 sub PMHelp_Mmp { |
|
88 } |
|
89 |
|
90 sub PMCheckPlatformL { |
|
91 if ((&main::Plat eq 'TOOLS2') and (&main::BasicTrgType ne 'EXE') and (&main::BasicTrgType ne 'LIB')) |
|
92 { |
|
93 die "Can't specify anything but EXE or LIB TARGETTYPEs for this platform\n"; |
|
94 } |
|
95 } |
|
96 |
|
97 sub PMPlatProcessMmp (@) { |
|
98 &Winutl_DoMmp(\@_, "$ENV{EPOCROOT}epoc32\\gcc_mingw\\include"); |
|
99 @Win32LibList=&Winutl_Win32LibList; |
|
100 $Win32StdHeaders=&Winutl_Win32StdHeaders; |
|
101 } |
|
102 |
|
103 my $Makecmd; |
|
104 |
|
105 sub PMStartBldList($) { |
|
106 ($Makecmd) = @_; |
|
107 my $BaseTrg=&main::BaseTrg; |
|
108 my $BasicTrgType=&main::BasicTrgType; |
|
109 my @BldList=&main::BldList; |
|
110 my @SysIncPaths=&main::Path_Chop(&main::SysIncPaths); |
|
111 my @UserIncPaths=&main::Path_Chop(&main::UserIncPaths); |
|
112 |
|
113 my $EPOCPath=&main::EPOCPath; |
|
114 my $LibPath=&main::LibPath; |
|
115 |
|
116 my @MacroList=&main::MacroList(); |
|
117 |
|
118 my $VariantFile=&main::VariantFile(); |
|
119 my $Plat=&main::Plat; |
|
120 my $Trg=&main::Trg; |
|
121 my $TrgType=&main::TrgType; |
|
122 |
|
123 my $ExportLibrary=&main::ExportLibrary; |
|
124 my $NoExportLibrary=&main::NoExportLibrary; |
|
125 my $CompilerOption=&main::CompilerOption("GCC"); |
|
126 my $LinkerOption=&main::LinkerOption("GCC"); |
|
127 |
|
128 $Dlltool=$ToolPrefix.'$(DLLTOOL)'; |
|
129 $Archive=$ToolPrefix.'$(AR)'; |
|
130 $Link=$ToolPrefix.'$(GCC)'; |
|
131 $Objcopy=$ToolPrefix.'$(OBJCOPY)'; |
|
132 |
|
133 &Generic_Header(0, $Makecmd); # define standard things using absolute paths |
|
134 |
|
135 push @MacroList, "__TOOLS__"; |
|
136 push @MacroList, "__TOOLS2_WINDOWS__"; |
|
137 push @MacroList, "__SUPPORT_CPP_EXCEPTIONS__"; |
|
138 push @MacroList, "__PRODUCT_INCLUDE__=\\\"${VariantFile}\\\"" if ($VariantFile); |
|
139 |
|
140 # Remove __GCC32__ for TOOLS2 builds from the macro list. |
|
141 my $count = 0; |
|
142 foreach my $item (@MacroList) { |
|
143 if ($item =~ m/GCC32/i) { |
|
144 splice (@MacroList,$count,1) |
|
145 } |
|
146 $count++; |
|
147 } |
|
148 |
|
149 |
|
150 # GCC needs a fully-qualified path |
|
151 &main::Output( |
|
152 "\n", |
|
153 "# must set both PATH and Path to make it work correctly\n", |
|
154 "Path:=\$(Path)\n", |
|
155 "PATH:=\$(Path)\n", |
|
156 "\n" |
|
157 ); |
|
158 |
|
159 &main::Output( |
|
160 "INCDIR= -isystem \"$ENV{EPOCROOT}epoc32\\include\\tools\\stlport\" " |
|
161 ); |
|
162 |
|
163 foreach (@SysIncPaths) { |
|
164 &main::Output( |
|
165 " -isystem \"$_\"" |
|
166 ); |
|
167 } |
|
168 |
|
169 foreach (@UserIncPaths) { |
|
170 &main::Output( |
|
171 " -I \"$_\"" |
|
172 ); |
|
173 } |
|
174 |
|
175 if($VariantFile){ |
|
176 &main::Output("\\\n -include $MinGWPreInclude"); |
|
177 } |
|
178 |
|
179 |
|
180 |
|
181 &main::Output( |
|
182 "\n", |
|
183 "\n" |
|
184 ); |
|
185 |
|
186 &main::Output( |
|
187 "GCCFLAGS=$PlatOpt{Gcc} \\\n", |
|
188 "\t\t-pipe -c -Wall -W -Wno-ctor-dtor-privacy -Wno-unknown-pragmas", |
|
189 ); |
|
190 |
|
191 &main::Output( |
|
192 " $CompilerOption", # user-supplied compiler options |
|
193 "\n", |
|
194 "\n" |
|
195 ); |
|
196 |
|
197 &main::Output( |
|
198 "\n# ADDITIONAL LINKER OPTIONS", |
|
199 "\nUSERLDFLAGS = ", |
|
200 $LinkerOption, |
|
201 "\n\n" |
|
202 ); |
|
203 |
|
204 &main::Output( |
|
205 "GCCDEFS=" |
|
206 ); |
|
207 |
|
208 foreach(@MacroList) { |
|
209 &main::Output( |
|
210 " -D$_" |
|
211 ); |
|
212 } |
|
213 |
|
214 &main::Output( |
|
215 " \$(USERDEFS)\n", |
|
216 "\n" |
|
217 ); |
|
218 |
|
219 &main::Output( |
|
220 "MINGWPATH?=$MinGWInstall", "\n", |
|
221 "DLLTOOL:=\$(MINGWPATH)\\dlltool", "\n", |
|
222 "AR:=\$(MINGWPATH)\\ar", "\n", |
|
223 "OBJCOPY:=\$(MINGWPATH)\\objcopy", "\n", |
|
224 "GCC:=\$(MINGWPATH)\\g++", "\n" |
|
225 ); |
|
226 foreach (@BldList) { |
|
227 &main::Output( |
|
228 "GCC$_=\$(GCC)" |
|
229 ); |
|
230 if (/^REL$/o) { |
|
231 &main::Output(' -s ', $PlatOpt{Optimize}); |
|
232 } |
|
233 elsif (/^DEB$/o) { |
|
234 &main::Output(' -g'); |
|
235 unless (&main::SrcDbg) { |
|
236 &main::Output(' ', $PlatOpt{Optimize}); |
|
237 } |
|
238 } |
|
239 &main::Output(' $(GCCFLAGS)'); |
|
240 foreach (&main::MacroList($_)) { |
|
241 &main::Output(" -D$_"); |
|
242 } |
|
243 &main::Output(" \$(GCCDEFS)\n"); |
|
244 } |
|
245 |
|
246 &main::Output("\n","\n"); |
|
247 |
|
248 foreach (@BldList) { |
|
249 &main::Output("$_ :"); |
|
250 |
|
251 if ($BasicTrgType !~ /IMPLIB/io) { |
|
252 &main::Output (" \\\n\t",&Generic_Quote("\$(EPOCTRG$_)\\$Trg")); |
|
253 } |
|
254 &main::Output("\n","\n"); |
|
255 } |
|
256 |
|
257 # Resource building is done entirely via cl_generic.pm |
|
258 |
|
259 foreach (@BldList) { |
|
260 &main::Output("\n", "RESOURCE$_ : MAKEWORK$_"); |
|
261 } |
|
262 &main::Output("\n", "\n",); |
|
263 |
|
264 &main::Output("LIBRARY : MAKEWORKLIBRARY"); |
|
265 if ($BasicTrgType=~/^LIB$/o) { |
|
266 # code to ensure that the static libraries for all builds are built at the library stage |
|
267 foreach (@BldList) { |
|
268 &main::Output(" $_"); |
|
269 } |
|
270 } |
|
271 |
|
272 &main::Output( |
|
273 "\n", |
|
274 "CLEANLIBRARY :\n" |
|
275 ); |
|
276 |
|
277 &main::Output( |
|
278 "\n", |
|
279 "\n" |
|
280 ); |
|
281 |
|
282 &Generic_MakeWorkDir('MAKEWORKLIBRARY',"${LibPath}LIB"); |
|
283 |
|
284 &Generic_Releaseables; |
|
285 } |
|
286 |
|
287 |
|
288 sub PMBld { |
|
289 my @SrcList=&main::SrcList; |
|
290 my $BaseTrg=&main::BaseTrg; |
|
291 my $Bld=&main::Bld; |
|
292 my $ChopBldPath=&main::Path_Chop(&main::BldPath); |
|
293 my $EPOCIncPath=&main::EPOCIncPath; |
|
294 my $BasicTrgType=&main::BasicTrgType; |
|
295 my @LibList; |
|
296 my $LibPath=&main::LibPath; |
|
297 my $ChopRelPath=&main::Path_Chop(&main::RelPath); |
|
298 my $RelPath=&main::RelPath; |
|
299 my @StatLibList=&main::StatLibList; |
|
300 my $StatLinkPath=&main::StatLinkPath; |
|
301 my $Trg=&main::Trg; |
|
302 my $TrgType=&main::TrgType; |
|
303 my $ExportLibrary=&main::ExportLibrary; |
|
304 my $NoExportLibrary=&main::NoExportLibrary; |
|
305 |
|
306 if ($Bld =~ /DEB/) { |
|
307 @LibList = &main::DebugLibList; |
|
308 } else { |
|
309 @LibList = &main::LibList; |
|
310 } |
|
311 |
|
312 # REAL TARGETS |
|
313 #------------- |
|
314 &main::Output( |
|
315 "# REAL TARGET - BUILD VARIANT $Bld\n", |
|
316 "\n" |
|
317 ); |
|
318 |
|
319 # releasables |
|
320 my @releaseables; |
|
321 my $toolspath=&main::EPOCToolsPath(); |
|
322 |
|
323 if ($BasicTrgType!~/^LIB$/io) |
|
324 { |
|
325 push @releaseables, "$toolspath$Trg"; |
|
326 } |
|
327 else |
|
328 { |
|
329 push @releaseables, "$RelPath$Trg"; |
|
330 } |
|
331 |
|
332 if (!$NoExportLibrary && ($BasicTrgType!~/^(LIB|EXE)$/io)) { |
|
333 push @releaseables, "\$(EPOCLINK$Bld)\\lib$ExportLibrary.a"; |
|
334 } |
|
335 |
|
336 &main::Output( |
|
337 "WHAT$Bld : WHATGENERIC\n", |
|
338 "\n", |
|
339 "CLEAN$Bld : CLEANBUILD$Bld CLEANRELEASE$Bld\n", |
|
340 "\n", |
|
341 "CLEANBUILD$Bld : \n", |
|
342 "\t\@perl -w -S ermdir.pl \"\$(EPOCBLD$Bld)\"\n", |
|
343 "\n", |
|
344 "CLEANRELEASE$Bld : CLEANGENERIC\n", |
|
345 "\n" |
|
346 ); |
|
347 &Generic_WhatCleanTargets($Bld, "WHAT$Bld", "CLEANRELEASE$Bld", @releaseables); |
|
348 |
|
349 &Generic_MakeWorkDir("MAKEWORK$Bld",$ChopBldPath); |
|
350 &Generic_MakeWorkDir("MAKEWORK$Bld",$ChopRelPath); |
|
351 |
|
352 return if ($BasicTrgType=~/^IMPLIB$/io); |
|
353 |
|
354 &main::Output( |
|
355 "LISTING$Bld : MAKEWORK$Bld" |
|
356 ); |
|
357 foreach (@SrcList) { |
|
358 my $BaseSrc = &main::Path_Split('Base', $_); |
|
359 my $Ext = &main::Path_Split('Ext', $_); |
|
360 &main::Output( |
|
361 " \\\n\tLISTING$Bld$BaseSrc" |
|
362 ); |
|
363 } |
|
364 &main::Output( |
|
365 "\n", |
|
366 "\n" |
|
367 ); |
|
368 |
|
369 |
|
370 &main::Output( |
|
371 "OBJECTS$Bld=" |
|
372 ); |
|
373 foreach (@SrcList) { |
|
374 my $BaseSrc = &main::Path_Split('Base', $_); |
|
375 my $Ext = &main::Path_Split('Ext', $_); |
|
376 &main::Output( |
|
377 " \\\n\t", &Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.o") |
|
378 ); |
|
379 } |
|
380 &main::Output( |
|
381 "\n", |
|
382 "\n" |
|
383 ); |
|
384 |
|
385 &main::Output( |
|
386 &Generic_Quote("\$(EPOCTRG$Bld)\\$Trg"), " : ", |
|
387 &Generic_Quote("\$(OBJECTS$Bld)") |
|
388 ); |
|
389 &main::Output( |
|
390 " \$(LIBS$Bld)\n" |
|
391 ); |
|
392 # Link target |
|
393 if ($BasicTrgType=~/^EXE/o) { |
|
394 # call g++ to link the target |
|
395 &main::Output( |
|
396 "\t$Link $PlatOpt{Ld}" |
|
397 ); |
|
398 if ($Bld=~/^REL$/o) { |
|
399 &main::Output( |
|
400 " -s" |
|
401 ); |
|
402 } |
|
403 |
|
404 &main::Output( |
|
405 " -o \"\$(EPOCTRG$Bld)\\$Trg\" \\\n", |
|
406 "\t\t\$(OBJECTS$Bld) \\\n" |
|
407 ); |
|
408 &main::Output( |
|
409 "\t\t-L\$(EPOCTRG$Bld) \\\n" |
|
410 ); |
|
411 |
|
412 # Add dynamic libraries (dlls on Windows, .so on *nix systems) to linker options |
|
413 if (scalar @LibList) |
|
414 { |
|
415 &main::Output("\t\t-Wl,-Bdynamic "); |
|
416 } |
|
417 my $libs=""; |
|
418 foreach my $lib (@LibList) |
|
419 { |
|
420 $libs.="-l$lib "; |
|
421 } |
|
422 if ($libs ne "") |
|
423 { |
|
424 &main::Output( |
|
425 "$libs \\\n" |
|
426 ); |
|
427 } |
|
428 |
|
429 # Add static libraries (.a on both Windows and *nix) to linker options |
|
430 if (scalar @StatLibList) |
|
431 { |
|
432 &main::Output("\t\t-Wl,-Bstatic "); |
|
433 } |
|
434 my $statLibs="-lstlport.5.1 "; |
|
435 foreach my $lib (@StatLibList) |
|
436 { |
|
437 $statLibs.="-l$lib "; |
|
438 } |
|
439 if ($statLibs ne "") |
|
440 { |
|
441 $statLibs.="\\\n"; |
|
442 } |
|
443 &main::Output( |
|
444 "$statLibs" |
|
445 ); |
|
446 |
|
447 &main::Output( |
|
448 "\t\t \$(USERLDFLAGS)\n" |
|
449 ); |
|
450 &main::Output( |
|
451 "\tcopy \"\$(EPOCTRG$Bld)\\$Trg\" \"",&main::EPOCToolsPath,"$Trg\"\n" |
|
452 ); |
|
453 } |
|
454 elsif ($BasicTrgType=~/^LIB$/o) { |
|
455 &main::Output( |
|
456 "\tif exist \"\$\@\" del \"\$\@\"\n", |
|
457 "\t$Archive cr \$\@ \$^\n" |
|
458 ); |
|
459 } |
|
460 elsif ($BasicTrgType =~ /^DLL$/o) |
|
461 { |
|
462 &main::Output( |
|
463 "\t$Link -shared -o \$@ -Wl,--out-implib,\$(EPOCLINK$Bld)\\" . "lib" . "$ExportLibrary.a \$(OBJECTS$Bld)", |
|
464 "\n" |
|
465 ); |
|
466 &main::Output( |
|
467 "\tcopy \"\$@\" \"",&main::EPOCToolsPath,"$Trg\"\n" |
|
468 ); |
|
469 |
|
470 } |
|
471 |
|
472 |
|
473 &main::Output( |
|
474 "\n" |
|
475 ); |
|
476 |
|
477 |
|
478 } |
|
479 |
|
480 |
|
481 sub PMStartSrcList { |
|
482 |
|
483 &main::Output( |
|
484 "# SOURCES\n", |
|
485 "\n" |
|
486 ); |
|
487 } |
|
488 |
|
489 sub PMStartSrc { |
|
490 my $Src=&main::Src; |
|
491 |
|
492 &main::Output( |
|
493 "# Source $Src\n", |
|
494 "\n" |
|
495 ); |
|
496 } |
|
497 |
|
498 sub PMSrcDepend { |
|
499 my @BldList=&main::BldList; |
|
500 my @DepList=&main::DepList; |
|
501 my $BaseSrc=&main::BaseSrc; |
|
502 my $ExtSrc=&main::ExtSrc; |
|
503 |
|
504 return if (@DepList == 0); |
|
505 |
|
506 foreach (@BldList) { |
|
507 &main::Output( |
|
508 &Generic_Quote("\$(EPOCBLD$_)\\$BaseSrc.lis"), " ", |
|
509 &Generic_Quote("\$(EPOCBLD$_)\\$BaseSrc.o"), " \\\n", |
|
510 ); |
|
511 } |
|
512 &main::Output( |
|
513 ":" |
|
514 ); |
|
515 foreach (@DepList) { |
|
516 &main::Output( |
|
517 " \\\n\t", &Generic_Quote($_) |
|
518 ); |
|
519 } |
|
520 &main::Output( |
|
521 "\n", |
|
522 "\n" |
|
523 ); |
|
524 } |
|
525 |
|
526 sub PMSrcBldDepend { |
|
527 my $Bld=&main::Bld; |
|
528 my @DepList=&main::DepList; |
|
529 my $BaseSrc=&main::BaseSrc; |
|
530 my $ExtSrc=&main::ExtSrc; |
|
531 |
|
532 return if (@DepList == 0); |
|
533 |
|
534 &main::Output( |
|
535 &Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.lis"), " ", |
|
536 &Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.o"), " :", |
|
537 ); |
|
538 foreach (@DepList) { |
|
539 &main::Output( |
|
540 " \\\n\t", &Generic_Quote($_) |
|
541 ); |
|
542 } |
|
543 &main::Output( |
|
544 "\n", |
|
545 "\n" |
|
546 ); |
|
547 } |
|
548 |
|
549 sub PMEndSrcBld { |
|
550 my $BaseSrc=&main::BaseSrc; |
|
551 my $Bld=&main::Bld; |
|
552 my $Src=&main::Src; |
|
553 my $SrcPath=&main::Path_Chop(&main::SrcPath); |
|
554 my $Ext=&main::Path_Split('Ext', $Src); |
|
555 my $Plat=$main::Plat; |
|
556 |
|
557 # Use GCC trick to get assembler source files preprocessed with CPP |
|
558 $Src =~ s/\.s$/.S/i; |
|
559 &main::Output( |
|
560 &Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.o"), " : ", |
|
561 &Generic_Quote("$SrcPath\\$Src"), "\n", |
|
562 "\techo $Src\n", |
|
563 "\t\$(GCC$Bld) -I \"$SrcPath\" \$(INCDIR) -o \$\@ \"$SrcPath\\$Src\"\n", |
|
564 "\n", |
|
565 # generate an assembly listing target too |
|
566 "LISTING$Bld$BaseSrc : ", &Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.lis"), "\n", |
|
567 "\t", &Generic_CopyAction("$SrcPath\\$BaseSrc.tools2.lst"), |
|
568 "\n", |
|
569 &Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.lis"), " : ", |
|
570 &Generic_Quote("$SrcPath\\$Src"), "\n", |
|
571 "\t\$(GCC$Bld) -Wa,-adln -I \"$SrcPath\" \$(INCDIR) -o nul: \"$SrcPath\\$Src\" > \$\@\n", |
|
572 "\n" |
|
573 ); |
|
574 |
|
575 } |
|
576 |
|
577 sub PMEndSrc { |
|
578 |
|
579 &main::Output( |
|
580 "\n", |
|
581 "\n" |
|
582 ); |
|
583 } |
|
584 |
|
585 sub PMEndSrcList { |
|
586 |
|
587 # Deal with accumulated MAKEDIRS etc. |
|
588 |
|
589 &Generic_End; |
|
590 } |
|
591 |
|
592 1; |