|
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 cl_generic; |
|
83 use Genutl; |
|
84 use Winutl; |
|
85 |
|
86 sub PMHelp_Mmp { |
|
87 } |
|
88 |
|
89 sub PMCheckPlatformL { |
|
90 if ((&main::Plat eq 'TOOLS2') and (&main::BasicTrgType ne 'EXE') and (&main::BasicTrgType ne 'LIB')) |
|
91 { |
|
92 die "Can't specify anything but EXE or LIB TARGETTYPEs for this platform\n"; |
|
93 } |
|
94 } |
|
95 |
|
96 sub PMPlatProcessMmp (@) { |
|
97 &Winutl_DoMmp(\@_, "$ENV{EPOCROOT}epoc32\\gcc_mingw\\include"); |
|
98 @Win32LibList=&Winutl_Win32LibList; |
|
99 $Win32StdHeaders=&Winutl_Win32StdHeaders; |
|
100 } |
|
101 |
|
102 my $Makecmd; |
|
103 |
|
104 sub PMStartBldList($) { |
|
105 ($Makecmd) = @_; |
|
106 my $BaseTrg=&main::BaseTrg; |
|
107 my $BasicTrgType=&main::BasicTrgType; |
|
108 my @BldList=&main::BldList; |
|
109 my @SysIncPaths=&main::Path_Chop(&main::SysIncPaths); |
|
110 my @UserIncPaths=&main::Path_Chop(&main::UserIncPaths); |
|
111 |
|
112 my $EPOCPath=&main::EPOCPath; |
|
113 my $LibPath=&main::LibPath; |
|
114 |
|
115 my @MacroList=&main::MacroList(); |
|
116 |
|
117 my $VariantFile=&main::VariantFile(); |
|
118 my $Plat=&main::Plat; |
|
119 my $Trg=&main::Trg; |
|
120 my $TrgType=&main::TrgType; |
|
121 |
|
122 my $ExportLibrary=&main::ExportLibrary; |
|
123 my $NoExportLibrary=&main::NoExportLibrary; |
|
124 my $CompilerOption=&main::CompilerOption("GCC"); |
|
125 my $LinkerOption=&main::LinkerOption("GCC"); |
|
126 |
|
127 $Dlltool=$ToolPrefix.'$(DLLTOOL)'; |
|
128 $Archive=$ToolPrefix.'$(AR)'; |
|
129 $Link=$ToolPrefix.'$(GCC)'; |
|
130 $Objcopy=$ToolPrefix.'$(OBJCOPY)'; |
|
131 |
|
132 &Generic_Header(0, $Makecmd); # define standard things using absolute paths |
|
133 |
|
134 push @MacroList, "__TOOLS__"; |
|
135 push @MacroList, "__TOOLS2_WINDOWS__"; |
|
136 push @MacroList, "__SUPPORT_CPP_EXCEPTIONS__"; |
|
137 push @MacroList, "__PRODUCT_INCLUDE__=\\\"${VariantFile}\\\"" if ($VariantFile); |
|
138 |
|
139 # Remove __GCC32__ for TOOLS2 builds from the macro list. |
|
140 my $count = 0; |
|
141 foreach my $item (@MacroList) { |
|
142 if ($item =~ m/GCC32/i) { |
|
143 splice (@MacroList,$count,1) |
|
144 } |
|
145 $count++; |
|
146 } |
|
147 |
|
148 |
|
149 # GCC needs a fully-qualified path |
|
150 &main::Output( |
|
151 "\n", |
|
152 "# must set both PATH and Path to make it work correctly\n", |
|
153 "Path:=\$(Path)\n", |
|
154 "PATH:=\$(Path)\n", |
|
155 "\n" |
|
156 ); |
|
157 |
|
158 &main::Output( |
|
159 "INCDIR= -isystem \"$ENV{EPOCROOT}epoc32\\include\\tools\\stlport\" " |
|
160 ); |
|
161 |
|
162 foreach (@SysIncPaths) { |
|
163 &main::Output( |
|
164 " -isystem \"$_\"" |
|
165 ); |
|
166 } |
|
167 |
|
168 foreach (@UserIncPaths) { |
|
169 &main::Output( |
|
170 " -I \"$_\"" |
|
171 ); |
|
172 } |
|
173 |
|
174 if($VariantFile){ |
|
175 &main::Output("\\\n -include $MinGWPreInclude"); |
|
176 } |
|
177 |
|
178 |
|
179 |
|
180 &main::Output( |
|
181 "\n", |
|
182 "\n" |
|
183 ); |
|
184 |
|
185 &main::Output( |
|
186 "GCCFLAGS=$PlatOpt{Gcc} \\\n", |
|
187 "\t\t-pipe -c -Wall -W -Wno-ctor-dtor-privacy -Wno-unknown-pragmas", |
|
188 ); |
|
189 |
|
190 &main::Output( |
|
191 " $CompilerOption", # user-supplied compiler options |
|
192 "\n", |
|
193 "\n" |
|
194 ); |
|
195 |
|
196 &main::Output( |
|
197 "\n# ADDITIONAL LINKER OPTIONS", |
|
198 "\nUSERLDFLAGS = ", |
|
199 $LinkerOption, |
|
200 "\n\n" |
|
201 ); |
|
202 |
|
203 &main::Output( |
|
204 "GCCDEFS=" |
|
205 ); |
|
206 |
|
207 foreach(@MacroList) { |
|
208 &main::Output( |
|
209 " -D$_" |
|
210 ); |
|
211 } |
|
212 |
|
213 &main::Output( |
|
214 " \$(USERDEFS)\n", |
|
215 "\n" |
|
216 ); |
|
217 |
|
218 &main::Output( |
|
219 "MINGWPATH?=$MinGWInstall", "\n", |
|
220 "DLLTOOL:=\$(MINGWPATH)\\dlltool", "\n", |
|
221 "AR:=\$(MINGWPATH)\\ar", "\n", |
|
222 "OBJCOPY:=\$(MINGWPATH)\\objcopy", "\n", |
|
223 "GCC:=\$(MINGWPATH)\\g++", "\n" |
|
224 ); |
|
225 foreach (@BldList) { |
|
226 &main::Output( |
|
227 "GCC$_=\$(GCC)" |
|
228 ); |
|
229 if (/^REL$/o) { |
|
230 &main::Output(' -s ', $PlatOpt{Optimize}); |
|
231 } |
|
232 elsif (/^DEB$/o) { |
|
233 &main::Output(' -g'); |
|
234 unless (&main::SrcDbg) { |
|
235 &main::Output(' ', $PlatOpt{Optimize}); |
|
236 } |
|
237 } |
|
238 &main::Output(' $(GCCFLAGS)'); |
|
239 foreach (&main::MacroList($_)) { |
|
240 &main::Output(" -D$_"); |
|
241 } |
|
242 &main::Output(" \$(GCCDEFS)\n"); |
|
243 } |
|
244 |
|
245 &main::Output("\n","\n"); |
|
246 |
|
247 foreach (@BldList) { |
|
248 &main::Output("$_ :"); |
|
249 |
|
250 if ($BasicTrgType !~ /IMPLIB/io) { |
|
251 &main::Output (" \\\n\t",&Generic_Quote("\$(EPOCTRG$_)\\$Trg")); |
|
252 } |
|
253 &main::Output("\n","\n"); |
|
254 } |
|
255 |
|
256 # Resource building is done entirely via cl_generic.pm |
|
257 |
|
258 foreach (@BldList) { |
|
259 &main::Output("\n", "RESOURCE$_ : MAKEWORK$_"); |
|
260 } |
|
261 &main::Output("\n", "\n",); |
|
262 |
|
263 &main::Output("LIBRARY : MAKEWORKLIBRARY"); |
|
264 if ($BasicTrgType=~/^LIB$/o) { |
|
265 # code to ensure that the static libraries for all builds are built at the library stage |
|
266 foreach (@BldList) { |
|
267 &main::Output(" $_"); |
|
268 } |
|
269 } |
|
270 |
|
271 &main::Output( |
|
272 "\n", |
|
273 "CLEANLIBRARY :\n" |
|
274 ); |
|
275 |
|
276 &main::Output( |
|
277 "\n", |
|
278 "\n" |
|
279 ); |
|
280 |
|
281 &Generic_MakeWorkDir('MAKEWORKLIBRARY',"${LibPath}LIB"); |
|
282 |
|
283 &Generic_Releaseables; |
|
284 } |
|
285 |
|
286 |
|
287 sub PMBld { |
|
288 my @SrcList=&main::SrcList; |
|
289 my $BaseTrg=&main::BaseTrg; |
|
290 my $Bld=&main::Bld; |
|
291 my $ChopBldPath=&main::Path_Chop(&main::BldPath); |
|
292 my $EPOCIncPath=&main::EPOCIncPath; |
|
293 my $BasicTrgType=&main::BasicTrgType; |
|
294 my @LibList; |
|
295 my $LibPath=&main::LibPath; |
|
296 my $ChopRelPath=&main::Path_Chop(&main::RelPath); |
|
297 my $RelPath=&main::RelPath; |
|
298 my @StatLibList=&main::StatLibList; |
|
299 my $StatLinkPath=&main::StatLinkPath; |
|
300 my $Trg=&main::Trg; |
|
301 my $TrgType=&main::TrgType; |
|
302 my $ExportLibrary=&main::ExportLibrary; |
|
303 my $NoExportLibrary=&main::NoExportLibrary; |
|
304 |
|
305 if ($Bld =~ /DEB/) { |
|
306 @LibList = &main::DebugLibList; |
|
307 } else { |
|
308 @LibList = &main::LibList; |
|
309 } |
|
310 |
|
311 # REAL TARGETS |
|
312 #------------- |
|
313 &main::Output( |
|
314 "# REAL TARGET - BUILD VARIANT $Bld\n", |
|
315 "\n" |
|
316 ); |
|
317 |
|
318 # releasables |
|
319 my @releaseables; |
|
320 my $toolspath=&main::EPOCToolsPath(); |
|
321 |
|
322 if ($BasicTrgType!~/^LIB$/io) |
|
323 { |
|
324 push @releaseables, "$toolspath$Trg"; |
|
325 } |
|
326 else |
|
327 { |
|
328 push @releaseables, "$RelPath$Trg"; |
|
329 } |
|
330 |
|
331 if (!$NoExportLibrary && ($BasicTrgType!~/^(LIB|EXE)$/io)) { |
|
332 push @releaseables, "\$(EPOCLINK$Bld)\\lib$ExportLibrary.a"; |
|
333 } |
|
334 |
|
335 &main::Output( |
|
336 "WHAT$Bld : WHATGENERIC\n", |
|
337 "\n", |
|
338 "CLEAN$Bld : CLEANBUILD$Bld CLEANRELEASE$Bld\n", |
|
339 "\n", |
|
340 "CLEANBUILD$Bld : \n", |
|
341 "\t\@perl -S ermdir.pl \"\$(EPOCBLD$Bld)\"\n", |
|
342 "\n", |
|
343 "CLEANRELEASE$Bld : CLEANGENERIC\n", |
|
344 "\n" |
|
345 ); |
|
346 &Generic_WhatCleanTargets($Bld, "WHAT$Bld", "CLEANRELEASE$Bld", @releaseables); |
|
347 |
|
348 &Generic_MakeWorkDir("MAKEWORK$Bld",$ChopBldPath); |
|
349 &Generic_MakeWorkDir("MAKEWORK$Bld",$ChopRelPath); |
|
350 |
|
351 return if ($BasicTrgType=~/^IMPLIB$/io); |
|
352 |
|
353 &main::Output( |
|
354 "LISTING$Bld : MAKEWORK$Bld" |
|
355 ); |
|
356 foreach (@SrcList) { |
|
357 my $BaseSrc = &main::Path_Split('Base', $_); |
|
358 my $Ext = &main::Path_Split('Ext', $_); |
|
359 &main::Output( |
|
360 " \\\n\tLISTING$Bld$BaseSrc" |
|
361 ); |
|
362 } |
|
363 &main::Output( |
|
364 "\n", |
|
365 "\n" |
|
366 ); |
|
367 |
|
368 |
|
369 &main::Output( |
|
370 "OBJECTS$Bld=" |
|
371 ); |
|
372 foreach (@SrcList) { |
|
373 my $BaseSrc = &main::Path_Split('Base', $_); |
|
374 my $Ext = &main::Path_Split('Ext', $_); |
|
375 &main::Output( |
|
376 " \\\n\t", &Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.o") |
|
377 ); |
|
378 } |
|
379 &main::Output( |
|
380 "\n", |
|
381 "\n" |
|
382 ); |
|
383 |
|
384 &main::Output( |
|
385 &Generic_Quote("\$(EPOCTRG$Bld)\\$Trg"), " : ", |
|
386 &Generic_Quote("\$(OBJECTS$Bld)") |
|
387 ); |
|
388 &main::Output( |
|
389 " \$(LIBS$Bld)\n" |
|
390 ); |
|
391 # Link target |
|
392 if ($BasicTrgType=~/^EXE/o) { |
|
393 # call g++ to link the target |
|
394 &main::Output( |
|
395 "\t$Link $PlatOpt{Ld}" |
|
396 ); |
|
397 if ($Bld=~/^REL$/o) { |
|
398 &main::Output( |
|
399 " -s" |
|
400 ); |
|
401 } |
|
402 |
|
403 &main::Output( |
|
404 " -o \"\$(EPOCTRG$Bld)\\$Trg\" \\\n", |
|
405 "\t\t\$(OBJECTS$Bld) \\\n" |
|
406 ); |
|
407 &main::Output( |
|
408 "\t\t-L\$(EPOCTRG$Bld) \\\n" |
|
409 ); |
|
410 |
|
411 # Add dynamic libraries (dlls on Windows, .so on *nix systems) to linker options |
|
412 if (scalar @LibList) |
|
413 { |
|
414 &main::Output("\t\t-Wl,-Bdynamic "); |
|
415 } |
|
416 my $libs=""; |
|
417 foreach my $lib (@LibList) |
|
418 { |
|
419 $libs.="-l$lib "; |
|
420 } |
|
421 if ($libs ne "") |
|
422 { |
|
423 &main::Output( |
|
424 "$libs \\\n" |
|
425 ); |
|
426 } |
|
427 |
|
428 # Add static libraries (.a on both Windows and *nix) to linker options |
|
429 if (scalar @StatLibList) |
|
430 { |
|
431 &main::Output("\t\t-Wl,-Bstatic "); |
|
432 } |
|
433 my $statLibs="-lstlport.5.1 "; |
|
434 foreach my $lib (@StatLibList) |
|
435 { |
|
436 $statLibs.="-l$lib "; |
|
437 } |
|
438 if ($statLibs ne "") |
|
439 { |
|
440 $statLibs.="\\\n"; |
|
441 } |
|
442 &main::Output( |
|
443 "$statLibs" |
|
444 ); |
|
445 |
|
446 &main::Output( |
|
447 "\t\t \$(USERLDFLAGS)\n" |
|
448 ); |
|
449 &main::Output( |
|
450 "\tcopy \"\$(EPOCTRG$Bld)\\$Trg\" \"",&main::EPOCToolsPath,"$Trg\"\n" |
|
451 ); |
|
452 } |
|
453 elsif ($BasicTrgType=~/^LIB$/o) { |
|
454 &main::Output( |
|
455 "\tif exist \"\$\@\" del \"\$\@\"\n", |
|
456 "\t$Archive cr \$\@ \$^\n" |
|
457 ); |
|
458 } |
|
459 elsif ($BasicTrgType =~ /^DLL$/o) |
|
460 { |
|
461 &main::Output( |
|
462 "\t$Link -shared -o \$@ -Wl,--out-implib,\$(EPOCLINK$Bld)\\" . "lib" . "$ExportLibrary.a \$(OBJECTS$Bld)", |
|
463 "\n" |
|
464 ); |
|
465 &main::Output( |
|
466 "\tcopy \"\$@\" \"",&main::EPOCToolsPath,"$Trg\"\n" |
|
467 ); |
|
468 |
|
469 } |
|
470 |
|
471 |
|
472 &main::Output( |
|
473 "\n" |
|
474 ); |
|
475 |
|
476 |
|
477 } |
|
478 |
|
479 |
|
480 sub PMStartSrcList { |
|
481 |
|
482 &main::Output( |
|
483 "# SOURCES\n", |
|
484 "\n" |
|
485 ); |
|
486 } |
|
487 |
|
488 sub PMStartSrc { |
|
489 my $Src=&main::Src; |
|
490 |
|
491 &main::Output( |
|
492 "# Source $Src\n", |
|
493 "\n" |
|
494 ); |
|
495 } |
|
496 |
|
497 sub PMSrcDepend { |
|
498 my @BldList=&main::BldList; |
|
499 my @DepList=&main::DepList; |
|
500 my $BaseSrc=&main::BaseSrc; |
|
501 my $ExtSrc=&main::ExtSrc; |
|
502 |
|
503 return if (@DepList == 0); |
|
504 |
|
505 foreach (@BldList) { |
|
506 &main::Output( |
|
507 &Generic_Quote("\$(EPOCBLD$_)\\$BaseSrc.lis"), " ", |
|
508 &Generic_Quote("\$(EPOCBLD$_)\\$BaseSrc.o"), " \\\n", |
|
509 ); |
|
510 } |
|
511 &main::Output( |
|
512 ":" |
|
513 ); |
|
514 foreach (@DepList) { |
|
515 &main::Output( |
|
516 " \\\n\t", &Generic_Quote($_) |
|
517 ); |
|
518 } |
|
519 &main::Output( |
|
520 "\n", |
|
521 "\n" |
|
522 ); |
|
523 } |
|
524 |
|
525 sub PMSrcBldDepend { |
|
526 my $Bld=&main::Bld; |
|
527 my @DepList=&main::DepList; |
|
528 my $BaseSrc=&main::BaseSrc; |
|
529 my $ExtSrc=&main::ExtSrc; |
|
530 |
|
531 return if (@DepList == 0); |
|
532 |
|
533 &main::Output( |
|
534 &Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.lis"), " ", |
|
535 &Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.o"), " :", |
|
536 ); |
|
537 foreach (@DepList) { |
|
538 &main::Output( |
|
539 " \\\n\t", &Generic_Quote($_) |
|
540 ); |
|
541 } |
|
542 &main::Output( |
|
543 "\n", |
|
544 "\n" |
|
545 ); |
|
546 } |
|
547 |
|
548 sub PMEndSrcBld { |
|
549 my $BaseSrc=&main::BaseSrc; |
|
550 my $Bld=&main::Bld; |
|
551 my $Src=&main::Src; |
|
552 my $SrcPath=&main::Path_Chop(&main::SrcPath); |
|
553 my $Ext=&main::Path_Split('Ext', $Src); |
|
554 my $Plat=$main::Plat; |
|
555 |
|
556 # Use GCC trick to get assembler source files preprocessed with CPP |
|
557 $Src =~ s/\.s$/.S/i; |
|
558 &main::Output( |
|
559 &Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.o"), " : ", |
|
560 &Generic_Quote("$SrcPath\\$Src"), "\n", |
|
561 "\techo $Src\n", |
|
562 "\t\$(GCC$Bld) -I \"$SrcPath\" \$(INCDIR) -o \$\@ \"$SrcPath\\$Src\"\n", |
|
563 "\n", |
|
564 # generate an assembly listing target too |
|
565 "LISTING$Bld$BaseSrc : ", &Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.lis"), "\n", |
|
566 "\t", &Generic_CopyAction("$SrcPath\\$BaseSrc.tools2.lst"), |
|
567 "\n", |
|
568 &Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.lis"), " : ", |
|
569 &Generic_Quote("$SrcPath\\$Src"), "\n", |
|
570 "\t\$(GCC$Bld) -Wa,-adln -I \"$SrcPath\" \$(INCDIR) -o nul: \"$SrcPath\\$Src\" > \$\@\n", |
|
571 "\n" |
|
572 ); |
|
573 |
|
574 } |
|
575 |
|
576 sub PMEndSrc { |
|
577 |
|
578 &main::Output( |
|
579 "\n", |
|
580 "\n" |
|
581 ); |
|
582 } |
|
583 |
|
584 sub PMEndSrcList { |
|
585 |
|
586 # Deal with accumulated MAKEDIRS etc. |
|
587 |
|
588 &Generic_End; |
|
589 } |
|
590 |
|
591 1; |