sbsv1/abld/platform/cl_codewarrior.pm
changeset 40 68f68128601f
equal deleted inserted replaced
39:fa9d7d89d3d6 40:68f68128601f
       
     1 # Copyright (c) 2001-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_codewarrior;
       
    18 
       
    19 # declare variables global for module
       
    20 my @Win32LibList=();
       
    21 my $Win32StdHeaders;
       
    22 my $BaseAddressFlag;
       
    23 my $Win32Resrc;
       
    24 
       
    25 my $MWCC;
       
    26 my $MWLD;
       
    27 my $MWIncludePath;
       
    28 my $MWIncludeVar;
       
    29 my $CWVersion;
       
    30 my $CWVersionReadable;
       
    31 my $CWBuildNum;
       
    32 my $CWRuntimeLibs="";
       
    33 
       
    34 require Exporter;
       
    35 @ISA=qw(Exporter);
       
    36 @EXPORT=qw(
       
    37 	PMHelp_Mmp
       
    38 
       
    39 	PMCheckPlatformL
       
    40 
       
    41 	PMPlatProcessMmp
       
    42 
       
    43 	PMPlatCheckSource
       
    44 	
       
    45 	PMStartBldList
       
    46 		PMBld
       
    47 	PMStartSrcList
       
    48 		PMBitMapBld
       
    49 		PMResrcBld
       
    50 		PMAifBld
       
    51 		PMStartSrc
       
    52 		PMSrcDepend
       
    53 			PMSrcBldDepend
       
    54 			PMEndSrcBld
       
    55 		PMEndSrc
       
    56 	PMEndSrcList
       
    57 );
       
    58 
       
    59 use Winutl;
       
    60 use cl_generic;
       
    61 use E32Variant;
       
    62 
       
    63 my $NamedSymLkup = 0;
       
    64 
       
    65 my $stdcpp_tag_file = 'tag_coff';
       
    66 my $stdcpp_tag_path = '$(EPOCROOT)epoc32\tools\tag';
       
    67 
       
    68 sub RoundUp1k($) {
       
    69 	# Accept C hexadecimal number (0xNNN).  Convert argument to Kb
       
    70 	# rounded up to the next 1kb boundary.
       
    71 	use integer;
       
    72 	return (hex($_[0]) + 1023) / 1024;
       
    73 }
       
    74 
       
    75 
       
    76 sub PMHelp_Mmp {
       
    77 	&Winutl_Help_Mmp;
       
    78 }
       
    79 
       
    80 sub SysTrg () {
       
    81 	return 1 if &main::SystemTrg;
       
    82 	my $ExportLibrary=&main::ExportLibrary;
       
    83 	return 1 if ($ExportLibrary =~ /EKERN/i);
       
    84 	my $Trg=&main::Trg;
       
    85 	return 1 if ($Trg =~ /KSRT/i);
       
    86 	return 0;
       
    87 }
       
    88 
       
    89 sub PMCheckPlatformL {
       
    90 
       
    91 	my $IsProxyWrapperOption=&main::ProxyWrapperOption();
       
    92 
       
    93 	# check version of CodeWarrior for Symbian OS
       
    94 	
       
    95 	if (defined($ENV{MWCSym2Includes})) {
       
    96 		$MWCC = "mwccsym2.exe";
       
    97 		$MWLD = "mwldsym2.exe";
       
    98 	}
       
    99 	if (!defined($MWCC) && defined($ENV{MWSym2Libraries})) {
       
   100 		$MWCC = "mwccsym2.exe";
       
   101 		$MWLD = "mwldsym2.exe";
       
   102 	}
       
   103 	if (!defined($MWCC) && defined($ENV{CWFolder})) {
       
   104 		$MWCC = "mwcc.exe";
       
   105 		$MWLD = "mwld.exe";
       
   106 	}
       
   107 	if (!defined($MWCC)) {
       
   108 		die "ERROR: Unable to identify a valid CodeWarrior for Symbian OS installation\n";
       
   109 	}
       
   110 
       
   111 	# determine default include path
       
   112 	
       
   113 	$MWIncludeVar = 'MWCIncludes';	# default, even if it doesn't exist
       
   114 	$MWIncludePath = '';			# default is empty
       
   115 	
       
   116 	foreach my $var ('MWCSym2Includes','MWCWinx86Includes','MWCIncludes') {
       
   117 		if (defined($ENV{$var})) {
       
   118 			$MWIncludePath = $ENV{$var};
       
   119 			$MWIncludeVar = $var;
       
   120 			last;
       
   121 		}
       
   122 	}
       
   123 
       
   124 	open PIPE, "$MWCC |", or &main::FatalError( "Failed to find version information for $MWCC \n");
       
   125 	while (<PIPE>) {
       
   126 		if($_ =~ /Version\s+(\d+)\.(\d+)\.(\d+)\s+build\s+(\d+)/) {
       
   127 			my $MajorVer = $1;
       
   128 			my $MinorVer = $2;
       
   129 			my $PatchNum = $3;
       
   130 			
       
   131 			$CWBuildNum = $4;
       
   132 
       
   133             $CWVersionReadable = "$1.$2.$3 build $4";
       
   134 
       
   135 #			The CW compiler documentation says that the compiler version is a 2-byte value as
       
   136 #			0xMnpp (the corresponding CW's pre-defined macro is __MWERKS__), where,
       
   137 #				M is the major version number (which means it is accomodated in the first 4 bits, 
       
   138 #				n is the minor version number (which means it is accomodated in the next 4 bits, 
       
   139 #				pp is the patch number (which means it is accomodated in the next 8 bits.
       
   140 #			Here, an integer is formed from these 3 values to uniquely identify the compiler version.
       
   141 			$CWVersion = ($MajorVer << 12) + ($MinorVer << 8) + $PatchNum;
       
   142 			last;
       
   143 		}
       
   144 	}
       
   145 	close PIPE;
       
   146 	
       
   147 	if ($IsProxyWrapperOption){
       
   148 		$MWCC = "$ENV{ABLD_COMPWRAP} " . $MWCC;
       
   149 		$MWLD = "$ENV{ABLD_COMPWRAP} " . $MWLD;
       
   150 	}
       
   151 }
       
   152 
       
   153 sub PMPlatProcessMmp (@) {
       
   154 	&Winutl_DoMmp(\@_, $MWIncludePath);
       
   155 	$BaseAddressFlag=&Winutl_BaseAddress;
       
   156 	if ($BaseAddressFlag ne "") {
       
   157 		$BaseAddressFlag=" -imagebase \"$BaseAddressFlag\"";
       
   158 	}
       
   159 	@Win32LibList=&Winutl_Win32LibList;
       
   160 	$Win32Resrc=&Winutl_Win32Resrc;
       
   161 	$Win32StdHeaders=&Winutl_Win32StdHeaders;
       
   162 }
       
   163 
       
   164 sub PMPlatCheckSource () {
       
   165 	&Winutl_CheckSourceMMPMetaData ();
       
   166 }
       
   167 
       
   168 sub PMStartBldList($) {
       
   169 	my ($makecmd) = @_;
       
   170 	my $AifStructRef=&main::AifStructRef;
       
   171 	my $BaseTrg=&main::BaseTrg;
       
   172 	my $BitMapStructRef=&main::BitMapStructRef;
       
   173 	my @BldList=&main::BldList;
       
   174 	my @ChopSysIncPaths=&main::Path_Chop(&main::SysIncPaths);
       
   175 	my @ChopUserIncPaths=&main::Path_Chop(&main::UserIncPaths);
       
   176 	my $ExportLibrary=&main::ExportLibrary;
       
   177 	my $NoExportLibrary=&main::NoExportLibrary;
       
   178 	my $DefFile=&main::DefFile;
       
   179 	my $BasicTrgType=&main::BasicTrgType;
       
   180 	my $LibPath=&main::LibPath;
       
   181 	my @MacroList=&main::MacroList();
       
   182 	push @MacroList, "__SUPPORT_CPP_EXCEPTIONS__";
       
   183 
       
   184 	push @MacroList, "__SYMBIAN_STDCPP_SUPPORT__" if StdCppTarget();
       
   185 	
       
   186     my $VariantFile=&main::VariantFile();
       
   187 	my $ResourceStructRef=&main::ResourceStructRef;
       
   188 	my $Plat=&main::Plat;
       
   189 	my $Trg=&main::Trg;
       
   190 	my $TrgType=&main::TrgType;
       
   191 	my $WarningLevel=&main::CompilerOption("CW");
       
   192 	my $LinkAs=&main::LinkAs;
       
   193 
       
   194 	Generic_Header(0,$makecmd);	# define standard things using absolute paths
       
   195 
       
   196 	my $TrgDir="";
       
   197 	my $AifTrgDir="";
       
   198 	if (&Generic_Definition("TRGDIR") ne "") {
       
   199 		$TrgDir="\$(TRGDIR)\\";
       
   200 		$AifTrgDir=$TrgDir;
       
   201 	}
       
   202 
       
   203 # Handle migration of binaries to secure location
       
   204 
       
   205 	&Winutl_AdjustTargetPath(\$TrgDir);
       
   206 	
       
   207 # Change - mwwinrc.exe uses MWWinx86Includes or MWCIncludes, but some installations
       
   208 # fail to install either. Set MWCIncludes from the chosen variable as part
       
   209 # of the Makefile.
       
   210 	if (!defined($ENV{MWCIncludes}) && $MWIncludeVar ne 'MWCIncludes') {
       
   211 		&main::Output(
       
   212 			"\n",
       
   213 			"MWCIncludes:=\$($MWIncludeVar)\n",
       
   214 			"export MWCIncludes\n",
       
   215 			"\n"
       
   216 		);
       
   217 	}
       
   218 	if( ($CWVersion == 0x3205 && $CWBuildNum == 465)){
       
   219 		if($TrgType =~ /^(STDDLL|STDEXE|STDLIB)$/o) {
       
   220 		&main::Output(
       
   221 				"\n",
       
   222 				"MWSym2LibraryFiles:=msl_all_mse_symbian_d.lib;gdi32.lib;user32.lib;kernel32.lib;\n",
       
   223 				"export MWSym2LibraryFiles\n",
       
   224 				"\n"
       
   225 			);
       
   226 		}
       
   227 		else {
       
   228 			&main::Output(
       
   229 				"\n",
       
   230 				"MWSym2LibraryFiles:=msl_all_static_mse_symbian_d.lib;gdi32.lib;user32.lib;kernel32.lib;\n",
       
   231 				"export MWSym2LibraryFiles\n",
       
   232 				"\n"
       
   233 			);
       
   234 		}
       
   235 	}
       
   236 		
       
   237 	if($WarningLevel =~ /\-cwd\s\s*include/){	
       
   238 		&main::Output(
       
   239 			"# EPOC DEFINITIONS\n",
       
   240 			"\n",
       
   241 			"INCDIR  = -cwd include -i-"
       
   242 		);
       
   243 	}
       
   244 	else {
       
   245 		&main::Output(
       
   246 			"# EPOC DEFINITIONS\n",
       
   247 			"\n",
       
   248 			"INCDIR  = -cwd source -i-"
       
   249 		);
       
   250 	}
       
   251 	foreach (@ChopUserIncPaths,@ChopSysIncPaths) {
       
   252 		&main::Output(
       
   253 			" \\\n -i \"$_\""
       
   254 		);
       
   255 	}
       
   256 	use Pathutl;
       
   257 	if($VariantFile){
       
   258 	    my $variantFilePath = Path_Split('Path',$VariantFile);
       
   259 	    $VariantFile  = Path_Split('FILE',$VariantFile);
       
   260 	    # workaround for codewarrior defect:
       
   261 	    # codewarrior at the moment doesn't accept an absolute path with the
       
   262 	    # the -include option unless it contains a drive letter, this is solved
       
   263 	    # by including the directory and the file separately
       
   264 	    &main::Output("\\\n -i \"$variantFilePath \" -include \"$VariantFile\"");
       
   265 	}
       
   266 	&main::Output(
       
   267 		"\n",
       
   268 		"\n"
       
   269 	);
       
   270 
       
   271 	&main::Output(
       
   272 		"CWFLAGS ="		
       
   273 	);
       
   274 
       
   275 	# 'wchar_t' should be treated as default datatype for OE targets because when wchar_t option is turned off, 
       
   276 	# using 'wchar_t' defaults to the unsigned short int and wrong functionality. 
       
   277 	if ( $TrgType =~ /^(STDEXE|STDDLL|STDLIB)$/io || StdCppTarget() ) 
       
   278 	{
       
   279 		&main::Output(
       
   280 			" -wchar_t on"
       
   281 		);	
       
   282 	}
       
   283 	else 
       
   284 	{
       
   285 		&main::Output(
       
   286 			" -wchar_t off"
       
   287 		);
       
   288 	}
       
   289 
       
   290 	&main::Output(		
       
   291 		" -align 4",		# long alignment
       
   292 		" -warnings on",	# selection of warnings
       
   293 		" -w nohidevirtual",	# turn off "hides inherited virtual function" warning
       
   294 		   ",nounusedexpr",	# turn off "expression has no side effect" warning
       
   295 		" -msgstyle gcc",	# use GCC-style message format
       
   296 		# " -strict on",		# strict ANSI/ISO C++ checking
       
   297 		" -enum int",		# use int for enumeration types
       
   298 		" -str pool",		# pool strings into a single data object
       
   299 		" -exc ms",			# SEH C++ exception implementation
       
   300 		" -trigraphs on",		# Enable recognition of C-style trigraphs, e.g. '??/' -> '\'
       
   301 		" $WarningLevel"		
       
   302 	
       
   303 	);
       
   304 
       
   305 	if ($Win32StdHeaders or &main::Plat eq 'TOOLS') {
       
   306 		&main::Output(
       
   307 			" -stdinc"		# insist because mwccsym2 has -nostdinc as the default(?)
       
   308 		);
       
   309 	}
       
   310 	else {
       
   311 		&main::Output(
       
   312 			" -nostdinc"	# insist because mwcc has -stdinc as the default.
       
   313 		);
       
   314 	}
       
   315 	&main::Output(
       
   316 		"\n",
       
   317 		"\n"
       
   318 	);
       
   319 
       
   320 	&main::Output(
       
   321 		"CWDEFS  = "
       
   322 	);
       
   323 	foreach(@MacroList) {
       
   324 		&main::Output(
       
   325 			" -d \"$_\""
       
   326 		);
       
   327 	}
       
   328 	&main::Output(
       
   329 		" \$(USERDEFS)\n",
       
   330 		"\n"
       
   331 	);
       
   332 
       
   333 	foreach (@BldList) {
       
   334 		&main::Output(
       
   335 			"CW$_ = $MWCC"
       
   336 		);
       
   337 		if (/DEB$/o) {
       
   338 			&main::Output(
       
   339 				' -g -O0'   # debug information, no optimisation
       
   340 			);
       
   341 #			euser change to apply inlining on the _NAKED functions
       
   342 
       
   343 #			stdexe/stddll change so that the inline functions dont 
       
   344 #			get exported (in debug build) causing a different export list for debug and release builds
       
   345 			if ($BaseTrg!~/^EUSER$/oi && $TrgType !~ /^(STDEXE|STDDLL)$/io) {
       
   346 				&main::Output(
       
   347 					' -inline off'
       
   348 				);
       
   349 			}	
       
   350 		}
       
   351 		elsif (/REL$/o) {
       
   352 			&main::Output(
       
   353 				' -O4,s'	# highest level of optimisation, optimise for space
       
   354 			);
       
   355 		}
       
   356 
       
   357 		if( ($CWVersion == 0x3205 && $CWBuildNum >= 465) || $CWVersion > 0x3205){
       
   358 			if ($TrgType =~ /^(STDEXE|STDDLL|STDLIB)$/io) {
       
   359 				&main::Output(
       
   360 					' -runtime dllmulti'
       
   361 				);
       
   362 			}
       
   363 			else {
       
   364 				&main::Output(
       
   365 					' -runtime staticmulti'
       
   366 				);
       
   367 			}
       
   368 		}
       
   369 
       
   370 		&main::Output(
       
   371 			' $(CWFLAGS)'
       
   372 		);
       
   373 		foreach (&main::MacroList($_)) {
       
   374 			&main::Output(
       
   375 				" -d $_"
       
   376 			);
       
   377 		}
       
   378 		&main::Output(
       
   379 			" \$(CWDEFS) \$(INCDIR)\n"
       
   380 		);
       
   381 	}
       
   382 	&main::Output(
       
   383 		"\n",
       
   384 		"\n"
       
   385 	);
       
   386 	
       
   387 	foreach (@BldList) {
       
   388 		&main::Output(
       
   389 			"$_ :"
       
   390 		);
       
   391 
       
   392 		if ($BasicTrgType !~ /IMPLIB/io) {
       
   393 			&main::Output (
       
   394 				" \\\n",
       
   395 				"\t", &Generic_Quote("\$(EPOCTRG$_)\\$TrgDir$Trg")
       
   396 			);
       
   397 			if (&Winutl_CopyForStaticLinkage) {
       
   398 				&main::Output(
       
   399 					" \\\n",
       
   400 					"\t", &Generic_Quote("\$(EPOCTRG$_)\\$Trg")
       
   401 				);
       
   402 			}
       
   403 		}
       
   404 
       
   405 #		lib has to come after the main target so that a .DEF file will be generated if the project is not frozen
       
   406 		if ($DefFile and not &main::ExportUnfrozen) {
       
   407 			&main::Output(
       
   408 				" \\\n",
       
   409 				"\tLIBRARY\n"
       
   410 			);
       
   411 		}
       
   412 		&main::Output(
       
   413 			"\n",
       
   414 			"\n"
       
   415 		);
       
   416 	}
       
   417 
       
   418 	foreach (@BldList) {
       
   419 		my $makework="MAKEWORK$_";
       
   420 		&main::Output(
       
   421 			"\n",
       
   422 			"RESOURCE$_ : $makework"
       
   423 		);
       
   424 
       
   425 		my $BitMapRef;
       
   426 		foreach $BitMapRef (@$BitMapStructRef) {
       
   427 			my $file="\$(EPOCTRG$_)\\$$BitMapRef{TrgPath}$$BitMapRef{Trg}";
       
   428 			&Generic_MakeWorkFile($makework,$file);
       
   429 			&main::Output(
       
   430 				" \\\n",
       
   431 				"\t", &Generic_Quote($file)
       
   432 			);
       
   433 		}
       
   434 		undef $BitMapRef;
       
   435 
       
   436 		my $ResourceRef;
       
   437 		foreach $ResourceRef (@$ResourceStructRef) {
       
   438 			if(! defined $$ResourceRef{Hdronly}) {
       
   439 				my $file="\$(EPOCTRG$_)\\$$ResourceRef{Trg}";
       
   440 				&Generic_MakeWorkFile($makework,$file);
       
   441 				&main::Output(	# must come before main target because source for target will depend on the
       
   442 				" \\\n",		# *.rsg file in $EPOCIncPath
       
   443 				"\t", &Generic_Quote("$file")
       
   444 				);
       
   445 			}
       
   446 		}
       
   447 		undef $ResourceRef;
       
   448 
       
   449 		my $AifRef;
       
   450 		foreach $AifRef (@$AifStructRef) {
       
   451 			my $file="\$(EPOCTRG$_)\\$AifTrgDir$$AifRef{Trg}";
       
   452 			&Generic_MakeWorkFile($makework,$file);
       
   453 			&main::Output(
       
   454 				" \\\n",
       
   455 				"\t", &Generic_Quote($file)
       
   456 			);
       
   457 		}
       
   458 		undef $AifRef;
       
   459 
       
   460 		&main::Output(
       
   461 			"\n"
       
   462 		);
       
   463 	}
       
   464 	&main::Output(
       
   465 		"\n",
       
   466 		"\n",
       
   467 	);
       
   468 
       
   469 	&main::Output(
       
   470 		"\n",
       
   471 		"# REAL TARGET - LIBRARY\n",
       
   472 		"\n",
       
   473 		"LIBRARY : MAKEWORKLIBRARY"
       
   474 	);
       
   475 	if ($BasicTrgType=~/^LIB$/o) {
       
   476 #		code to ensure that the static libraries for all builds are built at the library stage
       
   477 		foreach (@BldList) {
       
   478 			&main::Output(
       
   479 				" $_"
       
   480 			);
       
   481 		}
       
   482 	}
       
   483 	elsif ($DefFile and !$NoExportLibrary) {
       
   484 		unless (&main::ExportUnfrozen) {
       
   485 			if (-e $DefFile) { # effectively "if project frozen ..."
       
   486 				my $LibLinkAs = ($BasicTrgType=~/^IMPLIB$/io) ? $LinkAs : $Trg;
       
   487 				&main::Output(
       
   488 					" ", &Generic_Quote("\$(EPOCLIB)\\UDEB\\$ExportLibrary.lib"), "\n",
       
   489 					"\n",
       
   490 					&Generic_Quote("\$(EPOCLIB)\\UDEB\\$ExportLibrary.lib"), " : ",
       
   491 					&Generic_Quote($DefFile), "\n",
       
   492 					"\tperl -S prepdef.pl ",&Generic_Quote($DefFile)," \"\$(EPOCBLD)\\$ExportLibrary.prep.def\"\n",
       
   493 					"\t$MWLD \"\$(EPOCBLD)\\$ExportLibrary.prep.def\" -importlib -o \$\@",
       
   494 					" -addcommand \"out:$LibLinkAs\" -warnings off",
       
   495 					"\n"
       
   496 				);
       
   497 			} else {
       
   498 				&main::Output(
       
   499 					"\n",
       
   500 					"\t\@echo WARNING: Not attempting to create \"\$(EPOCLIB)\\UDEB\\$ExportLibrary.lib\".\n",
       
   501 					"\t\@echo When exports are frozen in \"$DefFile\", regenerate Makefile.\n"
       
   502 				);
       
   503 			}
       
   504 		} else {
       
   505 			&main::Output(
       
   506 				"\n",
       
   507 				"\t\@echo Not attempting to create \"\$(EPOCLIB)\\UDEB\\$ExportLibrary.lib\"\n",
       
   508 				"\t\@echo from frozen .DEF file, since EXPORTUNFROZEN specified.\n"
       
   509 			);
       
   510 		}
       
   511 	}
       
   512 	&main::Output(
       
   513 		"\n",
       
   514 		"\n",
       
   515 		"FREEZE :\n"
       
   516 	);
       
   517 	if ($DefFile and $BasicTrgType!~/^IMPLIB$/io) {
       
   518 		&main::Output(
       
   519 #			call perl on the script here so nmake will die if there are errors - this doesn't happen if calling perl in a batch file
       
   520 			"\tperl -S efreeze.pl \$(EFREEZE_ALLOW_REMOVE) \"$DefFile\" \"\$(EPOCBLD)\\$ExportLibrary.def\" \n"
       
   521 		);
       
   522 	}
       
   523 	else {
       
   524 		&main::Output( "\tperl -e \"print \\\"warning: freeze could not be supported or \\
       
   525 		         you need to declare an explicitly specified def file using the keyword \\
       
   526 			 DEFFILE in the MMP file!\\n\\\"\""); 
       
   527 	}
       
   528 	&main::Output(
       
   529 		"\n",
       
   530 		"CLEANLIBRARY :\n"
       
   531 	);
       
   532 	if ($DefFile and !$NoExportLibrary) {
       
   533 		&main::Output(
       
   534 			"\t-\$(ERASE) \"\$(EPOCLIB)\\UDEB\\$ExportLibrary.lib\"\n"
       
   535 		);
       
   536 	}
       
   537 	&main::Output(
       
   538 		"\n"
       
   539 	);
       
   540 	&Generic_MakeWorkDir('MAKEWORKLIBRARY',"${LibPath}UDEB");
       
   541 
       
   542 	&Generic_Releaseables;
       
   543 }
       
   544 
       
   545 my $uidfile;
       
   546 sub PMBld {
       
   547 
       
   548 	my $AifStructRef=&main::AifStructRef;
       
   549 	my @SrcList=&main::SrcList;
       
   550 	my $BaseTrg=&main::BaseTrg;
       
   551 	my $BitMapStructRef=&main::BitMapStructRef;
       
   552 	my $Bld=&main::Bld;
       
   553 	my $ChopBldPath=&main::Path_Chop(&main::BldPath);
       
   554 	my $ExportLibrary=&main::ExportLibrary;
       
   555 	my $NoExportLibrary=&main::NoExportLibrary;
       
   556 	my $DefFile=&main::DefFile;
       
   557 	my $EPOCIncPath=&main::EPOCIncPath;
       
   558 	my $BasicTrgType=&main::BasicTrgType;
       
   559 	my @LibList;
       
   560 	my $RelPath=&main::RelPath;
       
   561 	my $ResourceStructRef=&main::ResourceStructRef;
       
   562 	my @StatLibList=&main::StatLibList;
       
   563 	my $Trg=&main::Trg;
       
   564 	my $TrgPath=&main::TrgPath;
       
   565 	my $TrgType=&main::TrgType;
       
   566 	# Get the information regarding supporting Compiler Wrapper Option
       
   567 	my $IsCompilerWrapperOption=&main::CompilerWrapperOption();
       
   568 
       
   569 	$NamedSymLkup = 1 if($TrgType =~ /^(STDDLL|STDEXE)$/o);
       
   570 
       
   571 	$uidfile = "$BaseTrg.UID";
       
   572 
       
   573 	if ($Bld =~ /DEB/) {
       
   574 		@LibList=&main::DebugLibList;
       
   575 	} else {
       
   576 		@LibList=&main::LibList;
       
   577 	}
       
   578 
       
   579 	# OE Glue Code
       
   580 	my @oe_exe_libs=("libcrt0.lib");
       
   581 	my @oe_exe_libs_wchar=("libwcrt0.lib");
       
   582 
       
   583 	# OE Import Libraries
       
   584 	my @oe_import_libs=("euser.lib"); 
       
   585  	if(not (grep /^libc.lib$/i, @LibList)){
       
   586  			push @oe_import_libs, "libc.lib";
       
   587  	}	   	
       
   588 	   	
       
   589    # Handle migration of binaries to secure location
       
   590 
       
   591 	my $BLDTRGPATH = "";
       
   592 	my $AIFBLDTRGPATH = "";
       
   593 	if ($TrgPath) {
       
   594 		$BLDTRGPATH = "\$(TRGDIR)\\";	    # handles TARGETPATH
       
   595 		$AIFBLDTRGPATH = $BLDTRGPATH;
       
   596 		&Winutl_AdjustTargetPath(\$BLDTRGPATH);
       
   597 	}
       
   598 	$BLDTRGPATH = "\$(EPOCTRG$Bld)\\".$BLDTRGPATH;
       
   599 	$AIFBLDTRGPATH = "\$(EPOCTRG$Bld)\\".$AIFBLDTRGPATH;
       
   600 
       
   601 	# REAL TARGETS
       
   602 	#-------------
       
   603 	&main::Output(
       
   604 		"# REAL TARGET - BUILD VARIANT $Bld\n",
       
   605 		"\n"
       
   606 	);
       
   607 
       
   608 #	releasables
       
   609 	my @releaseables;
       
   610 	
       
   611 	unless (&main::Plat() eq 'TOOLS') {
       
   612 		if ($TrgType !~ /^IMPLIB$/io) {
       
   613 			if ($TrgType !~ /^NONE/io) {
       
   614 				push @releaseables, "$BLDTRGPATH$Trg";
       
   615 				if ($Bld=~/REL$/o && $BasicTrgType!~/^LIB$/o) {
       
   616 					push @releaseables,"$BLDTRGPATH$Trg.map";
       
   617 				}
       
   618 				if (&Winutl_CopyForStaticLinkage) {
       
   619 					push @releaseables, "\$(EPOCTRG$Bld)\\$Trg";
       
   620 				}
       
   621 			}
       
   622 			my $BitMapRef;
       
   623 			foreach $BitMapRef (@$BitMapStructRef) {
       
   624 				push @releaseables, "\$(EPOCTRG$Bld)\\$$BitMapRef{TrgPath}$$BitMapRef{Trg}";
       
   625 			}
       
   626 			my $ResourceRef;
       
   627 			foreach $ResourceRef (@$ResourceStructRef) {
       
   628 				if(! defined $$ResourceRef{Hdronly}) {
       
   629 					push @releaseables,"\$(EPOCTRG$Bld)\\$$ResourceRef{Trg}";
       
   630 				}
       
   631 			}
       
   632 			my $AifRef;
       
   633 			foreach $AifRef (@$AifStructRef) {
       
   634 				push @releaseables, "$AIFBLDTRGPATH$$AifRef{Trg}";
       
   635 			}
       
   636 		}
       
   637 		if (-e $DefFile and !$NoExportLibrary) { # effectively "if project frozen ..."
       
   638 			push @releaseables, "\$(EPOCLIB$Bld)\\$ExportLibrary.lib";
       
   639 		}
       
   640 		if ($Bld=~/DEB$/o) {
       
   641 			# debugging support files?
       
   642 		}
       
   643 	}
       
   644 	else {
       
   645 		if ($BasicTrgType !~ /^IMPLIB$/io) {
       
   646 			my $toolspath=&main::EPOCToolsPath();
       
   647 			push @releaseables, "$toolspath$Trg";
       
   648 		}
       
   649 	}
       
   650 
       
   651 
       
   652 	my $firstlib = "";
       
   653 	my $newlib = "";
       
   654 
       
   655 	if ( $BasicTrgType =~ /^(EXE|DLL)$/o && main::Plat() ne 'TOOLS' ) {
       
   656 
       
   657 		$firstlib = main::FirstLib();
       
   658 
       
   659 		unless ( StdCppTarget() || ! main::StdCppSupport()) {
       
   660 
       
   661 			$newlib = main::NewLib(); # Check if has been set in the MMP file.
       
   662 
       
   663 			unless ($newlib) {
       
   664 				if ( main::SystemTrg() ) {
       
   665 
       
   666 					$newlib = 'scppnwdl_kern.lib';
       
   667 				}
       
   668 				else {
       
   669 					$newlib = 'scppnwdl.lib';
       
   670 				}
       
   671 			}
       
   672 		}
       
   673 	}
       
   674 
       
   675 
       
   676 	&main::Output(
       
   677 		"WHAT$Bld : WHATGENERIC\n",
       
   678 		"\n",
       
   679 		"CLEAN$Bld : CLEANBUILD$Bld CLEANRELEASE$Bld\n",
       
   680 		"\n",
       
   681 		"CLEANBUILD$Bld : \n",
       
   682 		"\t\@perl -S ermdir.pl \"\$(EPOCBLD$Bld)\"\n",
       
   683 		"\n",
       
   684 		"CLEANRELEASE$Bld : CLEANGENERIC\n",
       
   685 		"\n"
       
   686 	);
       
   687 	&Generic_WhatCleanTargets($Bld, "WHAT$Bld", "CLEANRELEASE$Bld", @releaseables);
       
   688 
       
   689 	my $adjustedTargetPath=$TrgPath;
       
   690 	&Winutl_AdjustTargetPath(\$adjustedTargetPath);
       
   691 	&Generic_MakeWorkDir("MAKEWORK$Bld", &main::BldPath);
       
   692 	&Generic_MakeWorkDir("MAKEWORK$Bld", "$RelPath$adjustedTargetPath");
       
   693 
       
   694 	&main::Output(
       
   695 		"\n",
       
   696 		"\n"
       
   697 	);
       
   698 
       
   699 	return if ($BasicTrgType=~/^IMPLIB$/io);
       
   700 
       
   701 	&main::Output(
       
   702 		"LISTING$Bld : MAKEWORK$Bld"
       
   703 	);
       
   704 	foreach (@SrcList) {
       
   705 		my $BaseSrc = &main::Path_Split('Base', $_);
       
   706 		my $Ext = &main::Path_Split('Ext', $_);
       
   707 		$BaseSrc.='_' if (lc($Ext) eq '.cia');
       
   708 		$BaseSrc =~ s/\.UID/_UID_/i if ($BaseSrc eq $uidfile);
       
   709 		
       
   710    		&main::Output(
       
   711 			" \\\n\tLISTING$Bld$BaseSrc"
       
   712    		);
       
   713    	}
       
   714 	&main::Output(
       
   715 		"\n",
       
   716 		"\n"
       
   717 	);
       
   718 	#Compiler wrapper support starts
       
   719 	if($IsCompilerWrapperOption)
       
   720 	{
       
   721 	 	my $Platcmpwrap=&main::Plat;
       
   722 	 	
       
   723 		&main::Output(
       
   724 			"COMPWRAP$Bld : OUTPUT_NAME = ",
       
   725 			"$Platcmpwrap\_$Bld",
       
   726 			"\n"
       
   727 		);
       
   728 	 	
       
   729 		&main::Output(
       
   730 			"COMPWRAP$Bld : MAKEWORK$Bld"
       
   731 		);
       
   732 
       
   733 		foreach (@SrcList) {
       
   734 			my $BaseSrc = &main::Path_Split('Base', $_);
       
   735 			my $Ext = &main::Path_Split('Ext', $_);
       
   736 			$BaseSrc.='_' if (lc($Ext) eq '.cia');
       
   737 			$BaseSrc =~ s/\.UID/_UID_/i if ($BaseSrc eq $uidfile);
       
   738 			
       
   739 			&main::Output(
       
   740 				" \\\n\tCOMPWRAP$Bld$BaseSrc"
       
   741 			);
       
   742 		}
       
   743 
       
   744 		&main::Output(
       
   745 			"\n",
       
   746 			"\n"
       
   747 		);
       
   748 	}
       
   749 	#--Compiler wrapper support ends
       
   750 
       
   751 	# Flag that tells whether to run checklib.exe on static libraries.
       
   752 	my $run_checklib = 0;
       
   753 
       
   754 	if (@StatLibList && $BasicTrgType =~ /^(EXE|DLL)$/o && !main::SystemTrg() && main::StdCppSupport()) {
       
   755 		# There are user-added static libraries. They should be checked for
       
   756 		# consistent use of operator new.
       
   757 		$run_checklib = 1;
       
   758 
       
   759 		#Create a make variable for the libraries.
       
   760 		main::Output("\nUSER_ADDED_ARCHIVES_$Bld=");
       
   761 		for (@StatLibList) {
       
   762 			&main::Output(
       
   763 				" \\\n\t", &Generic_Quote("\$(EPOCSTATLINK$Bld)\\$_")
       
   764 			);
       
   765 		}
       
   766 
       
   767 		main::Output("\n\n");
       
   768 	}
       
   769 
       
   770 	&main::Output(
       
   771 		"LIBS$Bld="
       
   772 	);
       
   773 	foreach (@StatLibList) {
       
   774 		&main::Output(
       
   775 			" \\\n\t", &Generic_Quote("\$(EPOCSTATLINK$Bld)\\$_")
       
   776 		);
       
   777 	}
       
   778 	
       
   779 	#OE Glue Code
       
   780 	if ($TrgType=~/^STDEXE$/o) {
       
   781 		if (&main::IsWideCharMain()) {
       
   782 			foreach (@oe_exe_libs_wchar) {
       
   783 				&main::Output(
       
   784 					" \\\n\t", &Generic_Quote("\$(EPOCSTATLINK$Bld)\\$_")
       
   785 				);
       
   786 			}
       
   787 		}
       
   788 		else {
       
   789 			foreach (@oe_exe_libs) {
       
   790 				&main::Output(
       
   791 					" \\\n\t", &Generic_Quote("\$(EPOCSTATLINK$Bld)\\$_")
       
   792 				);
       
   793 			}
       
   794 		}
       
   795 	}
       
   796 
       
   797 	foreach (@LibList) {
       
   798 		&main::Output(
       
   799 			" \\\n\t", &Generic_Quote("\$(EPOCLINK$Bld)\\$_")
       
   800 		);
       
   801 	}
       
   802 
       
   803 	#OE Import Libraries
       
   804 	if ($TrgType =~ /^STDEXE$/o || $TrgType =~ /^STDDLL$/o) {
       
   805 		foreach (@oe_import_libs) {
       
   806 		&main::Output(
       
   807 			" \\\n\t", &Generic_Quote("\$(EPOCLINK$Bld)\\$_")
       
   808 		);
       
   809 		}
       
   810 	}
       
   811 
       
   812 	&main::Output(
       
   813 		"\n",
       
   814 		"\n"
       
   815 	);
       
   816 
       
   817 	&main::Output(
       
   818 		"LINK_OBJS$Bld="
       
   819 	);
       
   820 	my $have_uidfile = 0;
       
   821 	foreach (@SrcList) {
       
   822 		my $BaseSrc = &main::Path_Split('Base', $_);
       
   823 		my $Ext = &main::Path_Split('Ext', $_);
       
   824 		if ($BaseSrc eq $uidfile) {
       
   825 			$have_uidfile = 1;
       
   826 			next;
       
   827 		}
       
   828 		$BaseSrc.='_' if (lc($Ext) eq '.cia');
       
   829    		&main::Output(
       
   830 			" \\\n",
       
   831 			"\t", &Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.o")
       
   832    		);
       
   833    	}
       
   834 
       
   835 	my $add_stdcpp_tag = 0;
       
   836 
       
   837 	if ($BasicTrgType=~/^LIB$/o && StdCppTarget() ) {
       
   838 		$add_stdcpp_tag = 1;
       
   839 	}
       
   840 
       
   841 	if ($add_stdcpp_tag) {
       
   842 		&main::Output(
       
   843 			" \\\n",
       
   844 			"\t", &Generic_Quote("$stdcpp_tag_path\\$stdcpp_tag_file")
       
   845 		);
       
   846 	}
       
   847 	if ($Win32Resrc) {
       
   848 		my $resbase=&main::Path_Split('Base',$Win32Resrc);
       
   849 		&main::Output(
       
   850 			" \\\n",
       
   851 			"\t", &Generic_Quote("\$(EPOCBLD$Bld)\\$resbase.res")
       
   852 		);
       
   853 	}
       
   854 	if ($have_uidfile) {
       
   855 		# ensure that the uid file is at the end of the list, as it's implicit in
       
   856 		# CodeWarrior IDE projects.
       
   857 		&main::Output(
       
   858 			" \\\n",
       
   859 			"\t", &Generic_Quote("\$(EPOCBLD$Bld)\\$BaseTrg"."_UID_.o")
       
   860 		);
       
   861 	}
       
   862 	&main::Output(
       
   863 		"\n",
       
   864 		"\n"
       
   865 	);
       
   866 
       
   867 	&main::OutFormat(
       
   868 		"COMMON_LINK_FLAGS$Bld=",
       
   869 		' -msgstyle gcc',
       
   870 		' -stdlib'		# use default runtime library for compiler help functions
       
   871 	);
       
   872 	if ($MWLD =~ /mwcc.exe/) {
       
   873 		&main::OutFormat(
       
   874 			' -warnings on'	# on by default in mwccsym2.exe
       
   875 		);
       
   876 	}
       
   877 
       
   878 	main::OutFormat(" \"\$(EPOCSTATLINK$Bld)\\$firstlib\" ") if $firstlib;
       
   879 	main::OutFormat(" \"\$(EPOCSTATLINK$Bld)\\$newlib\" ")   if $newlib;
       
   880 
       
   881 	foreach my $lib (@Win32LibList) {
       
   882 		 my $win32lib = $lib;    # take a copy, to avoid updating contents of Win32LibList!
       
   883 		$win32lib = "-l$win32lib" unless ($win32lib =~ /\\/);
       
   884 		&main::OutFormat(
       
   885 			" ",lc $win32lib
       
   886 		);
       
   887 	}
       
   888 	if ($BasicTrgType=~/^DLL$/o) {
       
   889 		&main::OutFormat(
       
   890 			"$BaseAddressFlag",
       
   891 			' -main __Win32DllMain@12',
       
   892 			' -shared'
       
   893 		);
       
   894 	}
       
   895 	elsif ($TrgType=~/^EXEXP$/o) {
       
   896 		&main::OutFormat(
       
   897 			"$BaseAddressFlag",
       
   898 			' -noentry',
       
   899 			' -shared'
       
   900 		);
       
   901 	}
       
   902 	elsif ($BasicTrgType=~/^EXE$/o) {
       
   903 		unless (&main::Plat eq 'TOOLS') {
       
   904 			&main::OutFormat(
       
   905 				' -m "?_E32Bootstrap@@YGXXZ"'
       
   906 			);
       
   907 		}
       
   908 	}
       
   909 	if (&main::Plat=~/^(WINC|TOOLS)$/o && $BasicTrgType=~/^EXE$/o) {
       
   910 		&main::OutFormat(
       
   911 			' -subsystem console'
       
   912 		);
       
   913 	}
       
   914 	else {
       
   915 		&main::OutFormat(
       
   916 			' -subsystem windows'
       
   917 		);
       
   918 	}
       
   919 	if (&main::HeapSize) {
       
   920 		my %HeapSize=&main::HeapSize;
       
   921 		&main::OutFormat(
       
   922 			' -heapreserve=',RoundUp1k($HeapSize{Max}),' -heapcommit=',RoundUp1k($HeapSize{Min})
       
   923 		);
       
   924 	}
       
   925 	if ($BasicTrgType=~/^(DLL|EXE)$/o) {
       
   926 		if ($Bld=~/DEB$/o) {
       
   927 			&main::OutFormat(
       
   928 				' -g'
       
   929 			);
       
   930 		}
       
   931 	}
       
   932 	&main::Output(
       
   933 		"\n",
       
   934 		"\n"
       
   935 	);
       
   936 
       
   937 	if($TrgType =~/^(STDEXE|STDDLL|STDLIB)$/o) {
       
   938 		if(! (( $CWVersion == 0x3205 && $CWBuildNum >= 465 ) || $CWVersion > 0x3205 ) ) {
       
   939 			&main::FatalError("TargetType $TrgType requires CodeWarrior version `3.2.5 build 465' or later but you have $CWVersionReadable.");
       
   940 		}
       
   941 	}
       
   942 
       
   943 	my $EntrySymbol='';
       
   944 	if ($BasicTrgType=~/^DLL$/o || $TrgType=~/^EXEXP$/o || $NamedSymLkup) {
       
   945 		my $Include="";
       
   946 		if ($BasicTrgType=~/^DLL$/o) {
       
   947 			$Include="-m __E32Dll";
       
   948 			$EntrySymbol='__E32Dll';
       
   949 		}
       
   950 		else {
       
   951 			$Include="-m __E32Startup";
       
   952 			$EntrySymbol='__E32Startup';
       
   953 		}
       
   954 		&main::Output(
       
   955 			"STAGE1_LINK_FLAGS$Bld= \$(COMMON_LINK_FLAGS$Bld) \$(LIBS$Bld) \\\n\t",
       
   956 			" -o \"\$(EPOCBLD$Bld)\\$Trg\"");
       
   957 		
       
   958 		if ($NamedSymLkup) {
       
   959 			&main::Output(
       
   960 			" -export all",
       
   961 			" -map \"\$(EPOCBLD$Bld)\\$Trg.map\""
       
   962 			);
       
   963 		}
       
   964 		else {
       
   965 			&main::Output(' -export dllexport');
       
   966 		}
       
   967 
       
   968 		if($CWRuntimeLibs ne "") {
       
   969 			&main::Output(
       
   970 				" -l$CWRuntimeLibs "
       
   971 			);
       
   972 		}
       
   973 		if($BasicTrgType=~/^DLL$/o || $TrgType=~/^EXEXP$/o) {
       
   974 			&main::Output(
       
   975 				" $Include",
       
   976 				' -nocompactimportlib', 
       
   977 				" -implib \"\$(EPOCBLD$Bld)\\$ExportLibrary.lib\"",
       
   978 				" -addcommand \"out:$Trg\" -warnings off",
       
   979 				"\n",
       
   980 			);
       
   981 		}
       
   982 		else{
       
   983 #		Dont generate import libs for an Exe
       
   984 			&main::Output(
       
   985 				" $Include",
       
   986 				" -addcommand \"out:$Trg\" -warnings off",
       
   987 				"\n",
       
   988 			);
       
   989 		}
       
   990 	}
       
   991 	my $AbsentSubst = '';
       
   992 	if ($EntrySymbol) {
       
   993 		$AbsentSubst = " -absent $EntrySymbol";
       
   994 	}
       
   995 
       
   996 	&main::Output(
       
   997 		"LINK_FLAGS$Bld= \$(COMMON_LINK_FLAGS$Bld) \$(LIBS$Bld) \\\n\t",
       
   998 		" -o \"$BLDTRGPATH$Trg\" ", &main::LinkerOption("CW") 
       
   999 	);
       
  1000 	if($CWRuntimeLibs ne "") {
       
  1001 			&main::Output(
       
  1002 				" -l$CWRuntimeLibs "
       
  1003 			);
       
  1004 	}
       
  1005 	if ($Bld=~/REL$/o && $BasicTrgType!~/^LIB$/o) {
       
  1006 		# Generate map file for release build executables
       
  1007 		&main::Output(
       
  1008 			" -map \"$BLDTRGPATH$Trg.map\"", 
       
  1009 		);
       
  1010 	}
       
  1011 	if ($BasicTrgType=~/^DLL$/o || $TrgType=~/^EXEXP$/o) {
       
  1012 		&main::Output(
       
  1013 			" -f \"\$(EPOCBLD)\\$ExportLibrary.def\"",	# use generated .DEF file
       
  1014 		);
       
  1015 		if (&main::ExportUnfrozen) {
       
  1016 			&main::Output(
       
  1017 				" -implib \"\$(EPOCLIB)\\UDEB\\$ExportLibrary.lib\"",
       
  1018 				" -addcommand \"out:$Trg\" -warnings off"
       
  1019 			);
       
  1020 		}
       
  1021 		else {
       
  1022 			&main::Output(
       
  1023 				' -noimplib'
       
  1024 			);
       
  1025 		}
       
  1026 	}
       
  1027 	else {
       
  1028 		&main::Output(
       
  1029 			' -noimplib'
       
  1030 		);
       
  1031 	}
       
  1032 	&main::Output(
       
  1033 		"\n",
       
  1034 		"\n"
       
  1035 	);
       
  1036 
       
  1037 	&main::Output(
       
  1038 		&Generic_Quote("$BLDTRGPATH$Trg"), " : \$(LINK_OBJS$Bld) "
       
  1039 	);
       
  1040 	if (-e $DefFile) { # effectively "if project frozen ..."
       
  1041 		&main::Output(
       
  1042 			&Generic_Quote($DefFile)
       
  1043 		);
       
  1044 	}
       
  1045 
       
  1046 	main::Output(" ", Generic_Quote("\$(EPOCSTATLINK$Bld)\\$firstlib") ) if $firstlib;
       
  1047 	main::Output(" ", Generic_Quote("\$(EPOCSTATLINK$Bld)\\$newlib") )   if $newlib;
       
  1048 
       
  1049 	&main::Output(
       
  1050 		" \$(LIBS$Bld)\n"
       
  1051 	);
       
  1052 
       
  1053 	my $checklib = "checklib";
       
  1054 
       
  1055 	if ( StdCppTarget() ) {
       
  1056 		$checklib .= " stdc++ --coff";
       
  1057 	}
       
  1058 	else {
       
  1059 		$checklib .= " symc++ --coff";
       
  1060 	}
       
  1061 
       
  1062 	&main::Output( "\t$checklib ","\$(USER_ADDED_ARCHIVES_$Bld)\n" ) if ($run_checklib);
       
  1063 #	Link by name first time round for dlls
       
  1064 	if ($BasicTrgType=~/^DLL$/o || $TrgType=~/^EXEXP$/o) {
       
  1065 		&main::Output(
       
  1066 			"\t$MWLD \$(STAGE1_LINK_FLAGS$Bld) -l \$(EPOCBLD$Bld) -search \$(notdir \$(LINK_OBJS$Bld))\n",
       
  1067 		);
       
  1068 		if(!$NamedSymLkup){
       
  1069 #		Dont delete the binary as we need to extract symbol/dependency info
       
  1070 			&main::Output(
       
  1071 			"\t\$(ERASE) \"\$(EPOCBLD$Bld)\\$Trg\"\n",
       
  1072 			);
       
  1073 		}
       
  1074 
       
  1075 #		Generate an export info file
       
  1076 		my $show_options = "names,verbose";
       
  1077 		$show_options = "names,unmangled,verbose" if ($MWLD =~ /mwldsym2.exe/);
       
  1078 		&main::Output(
       
  1079 			"\t$MWLD -S -show only,$show_options -o \"\$(EPOCBLD$Bld)\\$ExportLibrary.inf\" \"\$(EPOCBLD$Bld)\\$ExportLibrary.lib\"\n"
       
  1080 		);
       
  1081 
       
  1082 #		call makedef to reorder the export information
       
  1083 		&main::Output(
       
  1084 #			call perl on the script here so nmake will die if there are errors - this doesn't happen if calling perl in a batch file
       
  1085 			"\tperl -S makedef.pl $AbsentSubst -Inffile \"\$(EPOCBLD$Bld)\\$ExportLibrary.inf\""
       
  1086 		);
       
  1087 		if (SysTrg()) {
       
  1088     			&main::Output( "\t\t-SystemTargetType \\\n" );
       
  1089 	    	}		
       
  1090 		if (-e $DefFile) { # effectively "if project frozen ..."
       
  1091 			&main::Output(
       
  1092 				" -Frzfile \"$DefFile\""
       
  1093 			);
       
  1094 		}
       
  1095 		my $Export;
       
  1096 		my $Ordinal=1;
       
  1097 		foreach $Export (&main::Exports) {
       
  1098 #				replace "$" with "$$" so that NMAKE doesn't think there's a macro in the function name
       
  1099 			$Export=~s-\$-\$\$-go;
       
  1100 			&main::Output(
       
  1101 				" -$Ordinal $Export"
       
  1102 			);
       
  1103 			$Ordinal++;
       
  1104 		}
       
  1105 		&main::Output(" -sym_name_lkup") if($NamedSymLkup);
       
  1106 
       
  1107 		&main::Output(" -export_entrypoint_E32Dll") if ($TrgType =~ /^STDDLL$/i);  # Workaround: To export entry point _E32DLL for target type STDDLL
       
  1108 
       
  1109 		&main::Output(
       
  1110 			" \"\$(EPOCBLD)\\$ExportLibrary.def\" \n",
       
  1111 			"\t\$(ERASE) \"\$(EPOCBLD$Bld)\\$ExportLibrary.inf\"\n",
       
  1112 			"\t\$(ERASE) \"\$(EPOCBLD$Bld)\\$ExportLibrary.lib\"\n"
       
  1113 		);
       
  1114 	}
       
  1115 	elsif($NamedSymLkup) {
       
  1116 #	2-stage linking required for all those targets that enable symbol lookup
       
  1117 		&main::Output( "\t$checklib ","\$(USER_ADDED_ARCHIVES_$Bld)\n" ) if ($run_checklib);
       
  1118 		&main::Output(
       
  1119 			"\t$MWLD \$(STAGE1_LINK_FLAGS$Bld) -l \$(EPOCBLD$Bld) -search \$(notdir \$(LINK_OBJS$Bld))\n",
       
  1120 		);
       
  1121 	}
       
  1122 	my $gen_src_file = "";
       
  1123 	if($NamedSymLkup){
       
  1124 #		pick the symbols and the dependencies.
       
  1125 		&main::Output(
       
  1126 			"\t$MWLD -S -show only,names,verbose -o \"\$(EPOCBLD$Bld)\\$ExportLibrary.sym\" \"\$(EPOCBLD$Bld)\\$Trg\"\n",
       
  1127 		);
       
  1128 
       
  1129 #		Generate the source file with symbol and dependency information in the named data segment.
       
  1130 		$gen_src_file = "${BaseTrg}_SYM_";
       
  1131 		
       
  1132 		if($BasicTrgType=~/^EXE$/o){
       
  1133 #		For an EXE, generate the symbols as well as the dependencies
       
  1134 			&main::Output(
       
  1135 				"\tperl -S sym_lkup_util.pl -o \"\$(EPOCBLD$Bld)\\$gen_src_file.cpp\" -sym \"\$(EPOCBLD$Bld)\\$ExportLibrary.sym\" -map \"\$(EPOCBLD$Bld)\\$Trg.map\"\n"
       
  1136 			);
       
  1137 		}
       
  1138 		else {
       
  1139 #		For DLLs, generate only the dependencies.
       
  1140 			&main::Output(
       
  1141 				"\tperl -S sym_lkup_util.pl -o \"\$(EPOCBLD$Bld)\\$gen_src_file.cpp\" -sym \"\$(EPOCBLD$Bld)\\$ExportLibrary.sym\" --ignore_export_dir\n"
       
  1142 			);
       
  1143 		}
       
  1144 		main::Output(
       
  1145 			"\t\$(CW$Bld) -c \"\$(EPOCBLD$Bld)\\$gen_src_file.cpp\" -o \"\$(EPOCBLD$Bld)\\$gen_src_file.o\"\n",
       
  1146 		);
       
  1147 	}
       
  1148 
       
  1149 #	Perform the final link step
       
  1150 	&main::Output(
       
  1151 		"\t$MWLD "
       
  1152 	);
       
  1153 	if ($BasicTrgType=~/^LIB$/o) {
       
  1154 		&main::Output(
       
  1155 			"-library "
       
  1156 		);
       
  1157 
       
  1158 		&main::Output( "-l $stdcpp_tag_path ") if ($add_stdcpp_tag);
       
  1159 	}
       
  1160 	
       
  1161 	if($NamedSymLkup){
       
  1162 #	Final linking and cleanup
       
  1163 		main::Output(
       
  1164 		"\$(LINK_FLAGS$Bld) -l \$(EPOCBLD$Bld) -search \$(notdir \$(LINK_OBJS$Bld))",
       
  1165 		" \"\$(EPOCBLD$Bld)\\$gen_src_file.o\"\n",
       
  1166 		"\t\$(ERASE) \"\$(EPOCBLD$Bld)\\$gen_src_file.cpp\"\n",
       
  1167 		"\t\$(ERASE) \"\$(EPOCBLD$Bld)\\$gen_src_file.o\"\n",
       
  1168 		"\t\$(ERASE) \"\$(EPOCBLD$Bld)\\$ExportLibrary.sym\"\n",
       
  1169 		"\t\$(ERASE) \"\$(EPOCBLD$Bld)\\$Trg.map\"\n",
       
  1170 		"\t\$(ERASE) \"\$(EPOCBLD$Bld)\\$Trg\"\n",
       
  1171 		);
       
  1172 	}
       
  1173 	else {
       
  1174 		&main::Output(
       
  1175 			"\$(LINK_FLAGS$Bld) -l \$(EPOCBLD$Bld) -search \$(notdir \$(LINK_OBJS$Bld))\n",
       
  1176 		);
       
  1177 	}
       
  1178 	
       
  1179 	
       
  1180 	if (&main::Plat eq 'TOOLS') {
       
  1181 		&main::Output(
       
  1182 			"\tcopy \"BLDTRGPATH$Trg\" \"",&main::EPOCToolsPath,"$Trg\"\n"
       
  1183 		);
       
  1184 	}
       
  1185 	if (&Winutl_CopyForStaticLinkage) {
       
  1186 		&Generic_MakeWorkDir("MAKEWORK$Bld", "\$(EPOCTRG$Bld)");
       
  1187 		&main::Output(
       
  1188 			"\n",
       
  1189 			&Generic_Quote("\$(EPOCTRG$Bld)\\$Trg"), " : ", 
       
  1190 			&Generic_Quote("$BLDTRGPATH$Trg"), "\n",
       
  1191 			"\t", &Generic_CopyAction(),
       
  1192 		);
       
  1193 	}
       
  1194 
       
  1195 	&main::Output(
       
  1196 		"\n",
       
  1197 		"\n"
       
  1198 	);
       
  1199 }
       
  1200 
       
  1201 sub PMStartSrcList {
       
  1202 
       
  1203 	&main::Output(
       
  1204 		"# SOURCES\n",
       
  1205 		"\n"
       
  1206 	);
       
  1207 }
       
  1208 
       
  1209 sub PMBitMapBld {
       
  1210 
       
  1211 	&Generic_BitMapBld;
       
  1212 
       
  1213 	# Need to copy generic resource into emulated Z drive
       
  1214 
       
  1215 	my $BitMapRef=&main::BitMapRef;
       
  1216 
       
  1217 	my $ChopTrgPath="";
       
  1218 	if ($$BitMapRef{TrgPath}) {
       
  1219 		$ChopTrgPath.="\\$$BitMapRef{TrgPath}";
       
  1220 		chop $ChopTrgPath;
       
  1221 	}
       
  1222 
       
  1223 	my @BldList=&main::BldList;
       
  1224 	my $Bld;
       
  1225 	foreach $Bld (@BldList) {
       
  1226 		my $path="\$(EPOCTRG$Bld)$ChopTrgPath";
       
  1227 		&main::Output(
       
  1228 			&Generic_Quote("$path\\$$BitMapRef{Trg}"), " : ", 
       
  1229 			&Generic_Quote("$$BitMapRef{GenericTrg}"), "\n",
       
  1230 			"\t", &Generic_CopyAction(),
       
  1231 			"\n"
       
  1232 		);
       
  1233 	}
       
  1234 }
       
  1235 
       
  1236 sub PMResrcBld {
       
  1237 
       
  1238 	&Generic_ResrcBld;
       
  1239 
       
  1240 	# Need to copy generic resource into emulated Z drive
       
  1241 
       
  1242 	my $ResourceRef=&main::ResourceRef;
       
  1243 	my @BldList=&main::BldList;
       
  1244 
       
  1245 	foreach my $Bld (@BldList) 
       
  1246 	{
       
  1247 		if(! defined $$ResourceRef{Hdronly})
       
  1248 		{
       
  1249 			&main::Output(
       
  1250 				&Generic_Quote("\$(EPOCTRG$Bld)\\$$ResourceRef{Trg}"), " : ", 
       
  1251 				&Generic_Quote("$$ResourceRef{GenericTrg}"), "\n",
       
  1252 				"\t", &Generic_CopyAction(),
       
  1253 				"\n"
       
  1254 			);
       
  1255 		}
       
  1256 	}
       
  1257 }
       
  1258 
       
  1259 sub PMAifBld {
       
  1260 
       
  1261 	&Generic_AifBld;
       
  1262 
       
  1263 	# Need to copy generic resource into emulated Z drive
       
  1264 
       
  1265 	my $AifRef=&main::AifRef;
       
  1266 	my $TrgDir="";
       
  1267 	if (&Generic_Definition("TRGDIR") ne "") {
       
  1268 		$TrgDir="\\\$(TRGDIR)";
       
  1269 	}
       
  1270 
       
  1271 	my @BldList=&main::BldList;
       
  1272 	my $Bld;
       
  1273 	foreach $Bld (@BldList) {
       
  1274 		my $path="\$(EPOCTRG$Bld)$TrgDir";
       
  1275 		&main::Output(
       
  1276 			&Generic_Quote("$path\\$$AifRef{Trg}"), " : ",
       
  1277 			&Generic_Quote("$$AifRef{GenericTrg}"), "\n",
       
  1278 			"\t", &Generic_CopyAction(),
       
  1279 			"\n"
       
  1280 		);
       
  1281 	}
       
  1282 }
       
  1283 
       
  1284 
       
  1285 sub PMStartSrc {
       
  1286 	my $Src=&main::Src;
       
  1287 
       
  1288 	&main::Output(
       
  1289 		"# Source $Src\n",
       
  1290 		"\n"
       
  1291 	);
       
  1292 }
       
  1293 
       
  1294 sub PMSrcDepend {
       
  1295 	my @BldList=&main::BldList;	
       
  1296 	my @DepList=&main::DepList;
       
  1297 	my $BaseSrc=&main::BaseSrc;
       
  1298 	$BaseSrc =~ s/\.UID/_UID_/i if ($BaseSrc eq $uidfile);
       
  1299 
       
  1300 	return if (@DepList == 0);
       
  1301 
       
  1302 	foreach (@BldList) {
       
  1303 		&main::Output(
       
  1304 			&Generic_Quote("\$(EPOCBLD$_)\\$BaseSrc.o"), " \\\n",
       
  1305 		);
       
  1306 	}
       
  1307 	&main::Output(
       
  1308 		":"
       
  1309 	);
       
  1310 	foreach (@DepList) {
       
  1311 		&main::Output(
       
  1312 		" \\\n\t", &Generic_Quote($_)
       
  1313 		);
       
  1314 	}
       
  1315 	&main::Output(
       
  1316 		"\n",
       
  1317 		"\n"
       
  1318 	);
       
  1319 }
       
  1320 
       
  1321 sub PMSrcBldDepend {
       
  1322 	my $Bld=&main::Bld;
       
  1323 	my @DepList=&main::DepList;
       
  1324 	my $BaseSrc=&main::BaseSrc;
       
  1325 	$BaseSrc =~ s/\.UID/_UID_/i if ($BaseSrc eq $uidfile);
       
  1326 
       
  1327 	return if (@DepList == 0);
       
  1328 
       
  1329 	&main::Output(
       
  1330 		&Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.o"), " :",
       
  1331 	);
       
  1332 	foreach (@DepList) {
       
  1333 		&main::Output(
       
  1334 			" \\\n\t", &Generic_Quote($_)
       
  1335 		);
       
  1336 	}
       
  1337 	&main::Output(
       
  1338 		"\n",
       
  1339 		"\n"
       
  1340 	);
       
  1341 }
       
  1342 
       
  1343 sub PMEndSrcBld {
       
  1344 	my $BaseSrc=&main::BaseSrc;
       
  1345 	$BaseSrc =~ s/\.UID/_UID_/i if ($BaseSrc eq $uidfile);
       
  1346 	my $Bld=&main::Bld;
       
  1347 	my $Plat=&main::Plat;
       
  1348 	my $Src=&main::Src;
       
  1349 	my $SrcPath=&main::SrcPath;
       
  1350 	my $Ext=&main::ExtSrc;
       
  1351 	my $Cia = (lc($Ext) eq '.cia') ? 1 : 0;
       
  1352 	my $TrgType=&main::TrgType;
       
  1353 	# Get the information regarding supporting Compiler Wrapper Option
       
  1354 	my $IsCompilerWrapperOption=&main::CompilerWrapperOption();
       
  1355 
       
  1356 	if ($Cia) {
       
  1357 		&main::Output(
       
  1358 			&Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc\_.o"), " : ",
       
  1359 			&Generic_Quote("$SrcPath$Src"), "\n",
       
  1360 			"\techo $Src\n",
       
  1361 			"\t\$(CW$Bld) -lang c++ -o \"\$\@\" -c \"$SrcPath$Src\"\n",
       
  1362 			"\n",
       
  1363 #			assembler listing target - uses implicit rule to do disassembly
       
  1364 			"LISTING$Bld$BaseSrc\_ : ", &Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc\_.lis"), "\n",
       
  1365 			"\t", &Generic_CopyAction("$SrcPath$BaseSrc\_.$Plat.lst"),
       
  1366 			"\n"
       
  1367 		);
       
  1368 	} else {
       
  1369 		&main::Output(
       
  1370 			&Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.o"), " : ",
       
  1371 			&Generic_Quote("$SrcPath$Src"), "\n",
       
  1372 			"\techo $Src\n",
       
  1373 			"\t\$(CW$Bld) -o \"\$\@\" -c \"$SrcPath$Src\" "
       
  1374 		);
       
  1375 		# When building for OE target type and source file is of C++ type, 
       
  1376  		# then pass macro "__wchar_t_defined" to indicate that datatype "wchar_t" is enabled.
       
  1377  		if ( StdCppTarget() || $TrgType =~ /^(STDEXE|STDDLL|STDLIB)$/io ) 
       
  1378  		{			
       
  1379  			if (lc($Ext) =~ /^(.cpp|.cc|.cxx|.c\+\+)$/)
       
  1380  			{
       
  1381  				&main::Output(
       
  1382  					" -d \"__wchar_t_defined\" "					
       
  1383  				);			
       
  1384  			}
       
  1385  		}
       
  1386  		&main::Output(
       
  1387    			"\n",
       
  1388  			"\n"
       
  1389  		);
       
  1390 		&main::Output(
       
  1391 #			assembler listing target - uses implicit rule to do disassembly
       
  1392 			"LISTING$Bld$BaseSrc : ", &Generic_Quote("\$(EPOCBLD$Bld)\\$BaseSrc.lis"), "\n",
       
  1393 			"\t", &Generic_CopyAction("$SrcPath$BaseSrc.$Plat.lst"),
       
  1394 			"\n"
       
  1395 		);
       
  1396 
       
  1397 		# Output files if Compiler Wrapper Option is specified
       
  1398 		if($IsCompilerWrapperOption)
       
  1399 		{
       
  1400 			my $Platcmpwrap=&main::Plat;
       
  1401 			&main::Output(
       
  1402 				"COMPWRAP$Bld$BaseSrc : ",
       
  1403 				&Generic_Quote("$SrcPath$Src"), "\n",
       
  1404 				"\techo Analysing $Src\n",
       
  1405 				"\t\$(COMPWRAP) \$(CW$Bld) -o \"\$\@\" -c \"$SrcPath$Src\" ",
       
  1406 				"\n\n"
       
  1407 			);
       
  1408 
       
  1409 		}
       
  1410 	}
       
  1411 }
       
  1412 
       
  1413 sub PMEndSrc {
       
  1414 
       
  1415 	&main::Output(
       
  1416 		"\n",
       
  1417 		"\n"
       
  1418 	);
       
  1419 }
       
  1420 
       
  1421 sub PMEndSrcList {
       
  1422 
       
  1423 	my $show_options = "source";
       
  1424 	$show_options = "source,unmangled,comments" if ($MWLD =~ /mwldsym2.exe/);
       
  1425 	
       
  1426 	&main::Output(
       
  1427 		"\n",
       
  1428 		"# Implicit rule for generating .lis files\n",
       
  1429 		"\n",
       
  1430 		".SUFFIXES : .lis .o\n",
       
  1431 		"\n",
       
  1432 		".o.lis:\n",
       
  1433 		"\t$MWLD -S -show $show_options \$< -o \$\@\n",
       
  1434 		"\n",
       
  1435 		"\n"
       
  1436 	);
       
  1437 
       
  1438 	if ($Win32Resrc) {
       
  1439 		my @BldList=&main::BldList;
       
  1440 		my @DepList=&main::Deps_GenDependsL($Win32Resrc);
       
  1441 
       
  1442 		&main::Output(
       
  1443 			"# Win32 Resource $Win32Resrc\n",
       
  1444 			"\n",
       
  1445 			"DEPEND="
       
  1446 		);
       
  1447 		foreach (@DepList) {
       
  1448 			&main::Output(
       
  1449 				" \\\n\t", &Generic_Quote($_)
       
  1450 			);
       
  1451 		}
       
  1452 		&main::Output(
       
  1453 			"\n",
       
  1454 			"\n"
       
  1455 		);
       
  1456 	
       
  1457 		my $Bld;
       
  1458 		my $resbase=&main::Path_Split('Base',$Win32Resrc);
       
  1459 		my $respath=&main::Path_Chop(&main::Path_Split('Path',$Win32Resrc));
       
  1460 		foreach $Bld (@BldList) {
       
  1461 			&main::Output(
       
  1462 				&Generic_Quote("\$(EPOCBLD$Bld)\\$resbase.res"), " : ",
       
  1463 				&Generic_Quote($Win32Resrc), " \$(DEPEND)\n",
       
  1464 				"\tmwwinrc -o \$\@ \"$Win32Resrc\"\n",
       
  1465 				"\n"
       
  1466 			);
       
  1467 		}
       
  1468 		&main::Output(
       
  1469 			"\n",
       
  1470 			"\n"
       
  1471 		);
       
  1472 	}
       
  1473 
       
  1474 	# Deal with accumulated MAKEDIRS etc.
       
  1475 
       
  1476 	&Generic_End;
       
  1477 }
       
  1478 
       
  1479 sub StdCppTarget() {
       
  1480     
       
  1481     # STDCPP is supported
       
  1482     return 0 if (! main::StdCppSupport());
       
  1483     
       
  1484 	if ( main::NoStdCpp()) { # MMP keyword NOSTDCPP set
       
  1485 		return 0;
       
  1486 	}
       
  1487 	
       
  1488 	if ( main::StdCpp() ) { # MMP keyword STDCPP set.
       
  1489 		return 1;
       
  1490 	}
       
  1491 	else {
       
  1492 		return ( main::TrgType() =~ /^(STDEXE|STDDLL|STDLIB)$/io );
       
  1493 	}
       
  1494 }
       
  1495 
       
  1496 
       
  1497 1;