sbsv1_os/e32toolp/platform/cl_tools.pm
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 # Copyright (c) 2003-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 package Cl_tools;
       
    17 
       
    18 # declare variables global for module
       
    19 my @Win32LibList=();
       
    20 my $BaseAddressFlag;
       
    21 my $Win32Resrc;
       
    22 
       
    23 my $MWCC;
       
    24 my $MWLD;
       
    25 
       
    26 require Exporter;
       
    27 @ISA=qw(Exporter);
       
    28 @EXPORT=qw(
       
    29 	PMHelp_Mmp
       
    30 	PMCheckPlatformL
       
    31 	PMPlatProcessMmp
       
    32 	PMStartBldList
       
    33 	PMBld
       
    34 	PMStartSrcList
       
    35 	PMStartSrc
       
    36 	PMSrcDepend
       
    37 	PMSrcBldDepend
       
    38 	PMEndSrcBld
       
    39 	PMEndSrc
       
    40 	PMEndSrcList
       
    41 );
       
    42 
       
    43 use strict;
       
    44 use Winutl;
       
    45 use cl_generic;
       
    46 
       
    47 sub PMHelp_Mmp {
       
    48 	&Winutl_Help_Mmp;
       
    49 }
       
    50 
       
    51 sub PMCheckPlatformL {
       
    52 	if ((&main::Plat eq 'TOOLS') and (&main::BasicTrgType ne 'EXE') and (&main::BasicTrgType ne 'LIB')) {
       
    53 		die "Can't specify anything but EXE or LIB targettypes for this platform\n";
       
    54 	}
       
    55 }
       
    56 
       
    57 sub PMPlatProcessMmp (@) {
       
    58 	&Winutl_DoMmp(\@_, $ENV{MWCSym2Includes});
       
    59 	$BaseAddressFlag=&Winutl_BaseAddress;
       
    60 	if ($BaseAddressFlag ne "") {
       
    61 		$BaseAddressFlag=" -imagebase \"$BaseAddressFlag\"";
       
    62 	}
       
    63 	@Win32LibList=&Winutl_Win32LibList;
       
    64 	$Win32Resrc=&Winutl_Win32Resrc;
       
    65 }
       
    66 
       
    67 sub PMStartBldList($) {
       
    68 	my ($makecmd) = @_;
       
    69 	my $BaseTrg=&main::BaseTrg;
       
    70 	my @BldList=&main::BldList;
       
    71 	my @ChopSysIncPaths=&main::Path_Chop(&main::SysIncPaths);
       
    72 	my @ChopUserIncPaths=&main::Path_Chop(&main::UserIncPaths);
       
    73 	my $DefFile=&main::DefFile;
       
    74 	my $BasicTrgType=&main::BasicTrgType;
       
    75 	my $LibPath=&main::LibPath;
       
    76 	my @MacroList=&main::MacroList();
       
    77 	my $VariantFile=&main::VariantFile();
       
    78 	my $Plat=&main::Plat;
       
    79 	my $Trg=&main::Trg;
       
    80 	my $TrgType=&main::TrgType;
       
    81 	my $WarningLevel=&main::CompilerOption("CW");
       
    82 
       
    83 	# check version of CodeWarrior for Symbian OS
       
    84 	if (defined($ENV{MWSym2Libraries})) {
       
    85 		my $allthere=1;
       
    86 		foreach (split/;/,$ENV{MWSym2Libraries}) {
       
    87 			s/^\+//;	# remove leading "+", if any
       
    88 			if (!-d $_) {
       
    89 				$allthere=0;
       
    90 				last;
       
    91 			}
       
    92 		}
       
    93 		if ($allthere) {
       
    94 			$MWCC = "mwccsym2.exe";
       
    95 			$MWLD = "mwldsym2.exe";
       
    96 			print "Detected CodeWarrior for Symbian OS, version 2.0\n";
       
    97 		}
       
    98 	}
       
    99 	if (!defined($MWCC)) {
       
   100 		if (defined($ENV{CWFolder}) && -d $ENV{CWFolder}) {
       
   101 			$MWCC = "mwcc.exe";
       
   102 			$MWLD = "mwld.exe";
       
   103 			print "Detected CodeWarrior for Symbian OS, version 1.0\n";
       
   104 			die "ERROR: This version of CodeWarrior is not suitable for Symbian OS version 8\n";
       
   105 		}
       
   106 		else {
       
   107 			die "ERROR: Unable to identify a valid CodeWarrior for Symbian OS installation\n";
       
   108 		}
       
   109 	}
       
   110 	
       
   111 	Generic_Header(0,$makecmd);	# define standard things using absolute paths
       
   112 
       
   113 	my $TrgDir="";
       
   114 	if (&Generic_Definition("TRGDIR") ne "") {
       
   115 		$TrgDir="\$(TRGDIR)\\";
       
   116 	}
       
   117 
       
   118 # Change - winutl.pm checks MWCWinx86Includes, but mwccsym2.exe seems to use MWCIncludes
       
   119 	if ($MWCC eq "mwccsym2.exe" && !defined($ENV{MWCIncludes})) {
       
   120 		&main::Output(
       
   121 			"\n",
       
   122 			"MWCIncludes:=\$(MWCSym2Includes)\n",
       
   123 			"export MWCIncludes\n",
       
   124 			"\n"
       
   125 		);
       
   126 	}
       
   127 		
       
   128 	&main::Output(
       
   129 		"# EPOC DEFINITIONS\n",
       
   130 		"\n",
       
   131 		"INCDIR  = -cwd source -i-"
       
   132 	);
       
   133 	foreach (@ChopUserIncPaths,@ChopSysIncPaths) {
       
   134 		&main::Output(
       
   135 			" \\\n -i \"$_\""
       
   136 		);
       
   137 	}
       
   138 	use Pathutl;
       
   139 	if($VariantFile){
       
   140 	    my $variantFilePath = Path_Split('Path',$VariantFile);
       
   141 	    $VariantFile  = Path_Split('FILE',$VariantFile);
       
   142 	    # workaround for codewarrior defect:
       
   143 	    # codewarrior at the moment doesn't accept an absolute path with the
       
   144 	    # the -include option unless it contains a drive letter, this is solved
       
   145 	    # by including the directory and the file separately
       
   146 	    &main::Output("\\\n -i \"$variantFilePath\" -include \"$VariantFile\"");
       
   147 	}
       
   148 	&main::Output(
       
   149 		"\n",
       
   150 		"\n"
       
   151 	);
       
   152 
       
   153 	&main::Output(
       
   154 		"CWFLAGS =",
       
   155 		" -wchar_t off",	# do not treat wchar_t as a predefined type
       
   156 		" -align 4",		# long alignment
       
   157 		" -warnings on",	# selection of warnings
       
   158 		" -w nohidevirtual",	# turn off "hides inherited virtual function" warning
       
   159 		   ",nounusedexpr",	# turn off "expression has no side effect" warning
       
   160 		" -msgstyle gcc",	# use GCC-style message format
       
   161 		# " -strict on",		# strict ANSI/ISO C++ checking
       
   162 		" -enum int",		# use int for enumeration types
       
   163 		" -str pool",		# pool strings into a single data object
       
   164 		" $WarningLevel"		
       
   165 	
       
   166 	);
       
   167 
       
   168 	&main::Output(
       
   169 		" -stdinc"		# insist because mwccsym2 has -nostdinc as the default(?)
       
   170 	);
       
   171 
       
   172 	&main::Output(
       
   173 		"\n",
       
   174 		"\n"
       
   175 	);
       
   176 
       
   177 	&main::Output(
       
   178 		"CWDEFS  = "
       
   179 	);
       
   180 	foreach(@MacroList) {
       
   181 		&main::Output(
       
   182 			" -d \"$_\""
       
   183 		);
       
   184 	}
       
   185 	&main::Output(
       
   186 		" \$(USERDEFS)\n",
       
   187 		"\n"
       
   188 	);
       
   189 
       
   190 	foreach (@BldList) {
       
   191 		&main::Output(
       
   192 			"CW$_ = $MWCC"
       
   193 		);
       
   194 		if (/DEB$/o) {
       
   195 			&main::Output(
       
   196 				' -g -O0'   # debug information, no optimisation
       
   197 			);
       
   198 		}
       
   199 		elsif (/REL$/o) {
       
   200 			&main::Output(
       
   201 				' -O4,s'    # highest level of optimisation, optimise for space
       
   202 			);
       
   203 		}
       
   204 		&main::Output(
       
   205 			' $(CWFLAGS)'
       
   206 		);
       
   207 		foreach (&main::MacroList($_)) {
       
   208 			&main::Output(
       
   209 				" -d $_"
       
   210 			);
       
   211 		}
       
   212 		&main::Output(
       
   213 			" \$(CWDEFS) \$(INCDIR)\n"
       
   214 		);
       
   215 	}
       
   216 	&main::Output(
       
   217 		"\n",
       
   218 		"\n"
       
   219 	);
       
   220 	
       
   221 	foreach (@BldList) {
       
   222 		&main::Output(
       
   223 			"$_ :"
       
   224 		);
       
   225 
       
   226 		&main::Output (
       
   227 			" \\\n",
       
   228 			"\t", &Generic_Quote("\$(EPOCTRG$_)\\$TrgDir$Trg")
       
   229 		);
       
   230 		
       
   231 
       
   232 #		lib has to come after the main target so that a .DEF file will be generated if the project is not frozen
       
   233 		if ($DefFile and not &main::ExportUnfrozen) {
       
   234 			&main::Output(
       
   235 				" \\\n",
       
   236 				"\tLIBRARY\n"
       
   237 			);
       
   238 		}
       
   239 		&main::Output(
       
   240 			"\n",
       
   241 			"\n"
       
   242 		);
       
   243 	}
       
   244 
       
   245 	&main::Output(
       
   246 		"LIBRARY : MAKEWORKLIBRARY",
       
   247 		"\n"
       
   248 	);
       
   249 	&main::Output(
       
   250 		"\n",
       
   251 		"FREEZE :\n"
       
   252 	);
       
   253 	&main::Output(
       
   254 		"\n",
       
   255 		"CLEANLIBRARY :\n"
       
   256 	);
       
   257 	&Generic_MakeWorkDir('MAKEWORKLIBRARY',"${LibPath}UDEB");
       
   258 
       
   259 	&Generic_Releaseables;
       
   260 }
       
   261 
       
   262 my $uidfile;
       
   263 sub PMBld {
       
   264 
       
   265 	my @SrcList=&main::SrcList;
       
   266 	my $BaseTrg=&main::BaseTrg;
       
   267 	my $Bld=&main::Bld;
       
   268 	my $ChopBldPath=&main::Path_Chop(&main::BldPath);
       
   269 	my $DefFile=&main::DefFile;
       
   270 	my $EPOCIncPath=&main::EPOCIncPath;
       
   271 	my $FirstLib=&main::FirstLib;
       
   272 	my $BasicTrgType=&main::BasicTrgType;
       
   273 	my @LibList;
       
   274 	my $RelPath=&main::RelPath;
       
   275 	my $Trg=&main::Trg;
       
   276 	my $TrgPath=&main::TrgPath;
       
   277 	my $TrgType=&main::TrgType;
       
   278 
       
   279 	$uidfile = "$BaseTrg.UID";
       
   280 
       
   281 	if ($Bld =~ /DEB/) {
       
   282 		@LibList=&main::DebugLibList;
       
   283 	} else {
       
   284 		@LibList=&main::LibList;
       
   285 	}
       
   286 
       
   287 	my $BLDTRGPATH = "\$(EPOCTRG$Bld)\\";
       
   288 	if ($TrgPath) {
       
   289 		$BLDTRGPATH .= "\$(TRGDIR)\\";	    # handles TARGETPATH
       
   290 	}
       
   291 
       
   292 
       
   293 #	releasables
       
   294 	my @releaseables;
       
   295 	
       
   296 	my $toolspath=&main::EPOCToolsPath();
       
   297 	push @releaseables, "$toolspath$Trg";
       
   298 
       
   299 	&main::Output(
       
   300 		"WHAT$Bld : WHATGENERIC\n",
       
   301 		"\n",
       
   302 		"CLEAN$Bld : CLEANBUILD$Bld CLEANRELEASE$Bld\n",
       
   303 		"\n",
       
   304 		"CLEANBUILD$Bld : \n",
       
   305 		"\t\@perl -w -S ermdir.pl \"\$(EPOCBLD$Bld)\"\n",
       
   306 		"\n",
       
   307 		"CLEANRELEASE$Bld : CLEANGENERIC\n",
       
   308 		"\n"
       
   309 	);
       
   310 	
       
   311 	&Generic_WhatCleanTargets($Bld, "WHAT$Bld", "CLEANRELEASE$Bld", @releaseables);
       
   312 	&Generic_MakeWorkDir("MAKEWORK$Bld", &main::BldPath);
       
   313 	&Generic_MakeWorkDir("MAKEWORK$Bld", "$RelPath$TrgPath");
       
   314 
       
   315 	&main::Output(
       
   316 		"\n",
       
   317 		"\n"
       
   318 	);
       
   319 
       
   320 	&main::Output(
       
   321 		"LISTING$Bld : MAKEWORK$Bld"
       
   322 	);
       
   323 	foreach (@SrcList) {
       
   324 		my $BaseSrc = &main::Path_Split('Base', $_);
       
   325 		my $Ext = &main::Path_Split('Ext', $_);
       
   326 		$BaseSrc = "uid" if ($BaseSrc eq $uidfile);
       
   327 		
       
   328    		&main::Output(
       
   329 			" \\\n\tLISTING$Bld$BaseSrc"
       
   330    		);
       
   331    	}
       
   332 	&main::Output(
       
   333 		"\n",
       
   334 		"\n"
       
   335 	);
       
   336 
       
   337 	&main::Output(
       
   338 		"LIBS$Bld="
       
   339 	);
       
   340 	
       
   341 	foreach (@LibList) {
       
   342 		&main::Output(
       
   343 			" \\\n\t", &Generic_Quote("\$(EPOCLINK$Bld)\\$_")
       
   344 		);
       
   345 	}
       
   346 	&main::Output(
       
   347 		"\n",
       
   348 		"\n"
       
   349 	);
       
   350 
       
   351 	&main::Output(
       
   352 		"LINK_OBJS$Bld="
       
   353 	);
       
   354 	my $have_uidfile = 0;
       
   355 	foreach (@SrcList) {
       
   356 		my $BaseSrc = &main::Path_Split('Base', $_);
       
   357 		my $Ext = &main::Path_Split('Ext', $_);
       
   358 		if ($BaseSrc eq $uidfile) {
       
   359 			$have_uidfile = 1;
       
   360 			next;
       
   361 		}
       
   362    		&main::Output(
       
   363 			" \\\n",
       
   364 			"\t", &Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.o")
       
   365    		);
       
   366    	}
       
   367 	
       
   368 	if ($have_uidfile) {
       
   369 		# ensure that the uid file is at the end of the list, as it's implicit in
       
   370 		# CodeWarrior IDE projects.
       
   371 		&main::Output(
       
   372 			" \\\n",
       
   373 			"\t", &Generic_Quote("\$(EPOCBLD$Bld)\\uid.o")
       
   374 		);
       
   375 	}
       
   376 	&main::Output(
       
   377 		"\n",
       
   378 		"\n"
       
   379 	);
       
   380 
       
   381 	&main::OutFormat(
       
   382 		"COMMON_LINK_FLAGS$Bld=",
       
   383 		' -msgstyle gcc',
       
   384 		' -stdlib'		# use default runtime library for compiler help functions
       
   385 	);
       
   386 	if ($MWLD eq "mwcc.exe") {
       
   387 		&main::OutFormat(
       
   388 			' -warnings on'	# on by default in mwccsym2.exe
       
   389 		);
       
   390 	}
       
   391 
       
   392 	&main::OutFormat(
       
   393 		' -subsystem console'
       
   394 	);
       
   395 		
       
   396 	if ($Bld=~/DEB$/o) {
       
   397 		&main::OutFormat(
       
   398 				' -g'
       
   399 			);
       
   400 		}
       
   401 	
       
   402 	&main::Output(
       
   403 		"\n",
       
   404 		"\n"
       
   405 	);
       
   406 
       
   407 	&main::Output(
       
   408 		"LINK_FLAGS$Bld= \$(COMMON_LINK_FLAGS$Bld) \$(LIBS$Bld) \\\n\t",
       
   409 		" -o \"$BLDTRGPATH$Trg\"" 
       
   410 	);
       
   411 	
       
   412 	&main::Output(
       
   413 		' -noimplib'
       
   414 	);
       
   415 
       
   416 	&main::Output(
       
   417 		"\n",
       
   418 		"\n"
       
   419 	);
       
   420 
       
   421 	&main::Output(
       
   422 		&Generic_Quote("$BLDTRGPATH$Trg"), " : \$(LINK_OBJS$Bld) "
       
   423 	);
       
   424 	if (-e $DefFile) { # effectively "if project frozen ..."
       
   425 		&main::Output(
       
   426 			&Generic_Quote($DefFile)
       
   427 		);
       
   428 	}
       
   429 
       
   430 	&main::Output(
       
   431 		" \$(LIBS$Bld)\n"
       
   432 	);
       
   433 
       
   434 #	Perform the final link step
       
   435 	&main::Output(
       
   436 		"\t$MWLD "
       
   437 	);
       
   438 	
       
   439 	&main::Output(
       
   440 		"\$(LINK_FLAGS$Bld) \$(LINK_OBJS$Bld)\n",
       
   441 	);
       
   442 
       
   443 	&main::Output(
       
   444 		"\tcopy \"$BLDTRGPATH$Trg\" \"",&main::EPOCToolsPath,"$Trg\"\n"
       
   445 	);
       
   446 
       
   447 	&main::Output(
       
   448 		"\n",
       
   449 		"\n"
       
   450 	);
       
   451 }
       
   452 
       
   453 sub PMStartSrcList {
       
   454 
       
   455 	&main::Output(
       
   456 		"# SOURCES\n",
       
   457 		"\n"
       
   458 	);
       
   459 }
       
   460 
       
   461 
       
   462 sub PMStartSrc {
       
   463 	my $Src=&main::Src;
       
   464 
       
   465 	&main::Output(
       
   466 		"# Source $Src\n",
       
   467 		"\n"
       
   468 	);
       
   469 }
       
   470 
       
   471 sub PMSrcDepend {
       
   472 	my @BldList=&main::BldList;	
       
   473 	my @DepList=&main::DepList;
       
   474 	my $BaseSrc=&main::BaseSrc;
       
   475 	$BaseSrc = "uid" if ($BaseSrc eq $uidfile);
       
   476 
       
   477 	return if (@DepList == 0);
       
   478 
       
   479 	foreach (@BldList) {
       
   480 		&main::Output(
       
   481 			&Generic_Quote("\$(EPOCBLD$_)\\$BaseSrc.o"), " \\\n",
       
   482 		);
       
   483 	}
       
   484 	&main::Output(
       
   485 		":"
       
   486 	);
       
   487 	foreach (@DepList) {
       
   488 		&main::Output(
       
   489 		" \\\n\t", &Generic_Quote($_)
       
   490 		);
       
   491 	}
       
   492 	&main::Output(
       
   493 		"\n",
       
   494 		"\n"
       
   495 	);
       
   496 }
       
   497 
       
   498 sub PMSrcBldDepend {
       
   499 	my $Bld=&main::Bld;
       
   500 	my @DepList=&main::DepList;
       
   501 	my $BaseSrc=&main::BaseSrc;
       
   502 	$BaseSrc = "uid" if ($BaseSrc eq $uidfile);
       
   503 
       
   504 	return if (@DepList == 0);
       
   505 
       
   506 	&main::Output(
       
   507 		&Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.o"), " :",
       
   508 	);
       
   509 	foreach (@DepList) {
       
   510 		&main::Output(
       
   511 			" \\\n\t", &Generic_Quote($_)
       
   512 		);
       
   513 	}
       
   514 	&main::Output(
       
   515 		"\n",
       
   516 		"\n"
       
   517 	);
       
   518 }
       
   519 
       
   520 sub PMEndSrcBld {
       
   521 	my $BaseSrc=&main::BaseSrc;
       
   522 	$BaseSrc = "uid" if ($BaseSrc eq $uidfile);
       
   523 	my $Bld=&main::Bld;
       
   524 	my $Plat=&main::Plat;
       
   525 	my $Src=&main::Src;
       
   526 	my $SrcPath=&main::SrcPath;
       
   527 
       
   528 	&main::Output(
       
   529 		&Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.o"), " : ",
       
   530 		&Generic_Quote("$SrcPath$Src"), "\n",
       
   531 		"\t\$(CW$Bld) -o \"\$\@\" -c \"$SrcPath$Src\"\n",
       
   532 		"\n",
       
   533 #		assembler listing target - uses implicit rule to do disassembly
       
   534 		"LISTING$Bld$BaseSrc : ", &Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.lis"), "\n",
       
   535 		"\t", &Generic_CopyAction("$SrcPath$BaseSrc.$Plat.lst"),
       
   536 		"\n"
       
   537 	);
       
   538 }
       
   539 
       
   540 sub PMEndSrc {
       
   541 
       
   542 	&main::Output(
       
   543 		"\n",
       
   544 		"\n"
       
   545 	);
       
   546 }
       
   547 
       
   548 sub PMEndSrcList {
       
   549 
       
   550 	my $show_options = "source";
       
   551 	$show_options = "source,unmangled,comments" if ($MWLD eq "mwldsym2.exe");
       
   552 	
       
   553 	&main::Output(
       
   554 		"\n",
       
   555 		"# Implicit rule for generating .lis files\n",
       
   556 		"\n",
       
   557 		".SUFFIXES : .lis .o\n",
       
   558 		"\n",
       
   559 		".o.lis:\n",
       
   560 		"\t$MWLD -S -show $show_options \$< -o \$\@\n",
       
   561 		"\n",
       
   562 		"\n"
       
   563 	);
       
   564 
       
   565 	# Deal with accumulated MAKEDIRS etc.
       
   566 
       
   567 	&Generic_End;
       
   568 }
       
   569 
       
   570 1;