memana/analyzetoolclient/commandlineengine/internal/src/CATProject.cpp
changeset 2 6a82cd05fb1e
parent 1 3ff3fecb12fe
equal deleted inserted replaced
1:3ff3fecb12fe 2:6a82cd05fb1e
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Class representing a project.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "../inc/CATProject.h"
       
    20 #include "../inc/CATModule2.h"
       
    21 #include "../inc/CATParseTraceFile.h"
       
    22 #include "../inc/CATDatParser.h"
       
    23 
       
    24 // ----------------------------------------------------------------------------
       
    25 // CATProject::CATProject()
       
    26 // ----------------------------------------------------------------------------
       
    27 CATProject::CATProject()
       
    28 {
       
    29 	LOG_FUNC_ENTRY("CATProject::CATProject");
       
    30 
       
    31 	m_bUninstrumented = true;
       
    32 
       
    33 	// Use windows api to acquire current directory info.
       
    34 	GetCurrentDirectory( MAX_LINE_LENGTH, m_cCurrentDir );
       
    35 
       
    36 	m_eBuildSystem = SBS_V1;
       
    37 	m_eBuildType = UDEB;
       
    38 	m_eLoggingMode = XTI;
       
    39 	m_eMode = NOT_DEFINED;
       
    40 	
       
    41 	m_iLoggingLevel = 3;
       
    42 	
       
    43 	m_pAnalyzer = 0;
       
    44 
       
    45 	m_sBinaryTarget = "";
       
    46 	m_sBuildCommand = "";
       
    47 	m_sDataFile = "";
       
    48 	m_sDataFileOutput = "";
       
    49 	m_sDataFileTemp = "";
       
    50 	m_sEpocRoot = "\\";
       
    51 	m_sMakeFile = "";
       
    52 	m_sPlatform = "";
       
    53 	m_sS60FileName = "";
       
    54 	m_sTargetModule = "";
       
    55 	m_sVariant = "";
       
    56 
       
    57 	m_vRomSymbolFiles.clear();
       
    58 	m_vModules.clear();
       
    59 	m_vStaticLibraries.clear();
       
    60 	m_vTargetModules.clear();
       
    61 	m_vUnsupportedModules.clear();
       
    62 }
       
    63 
       
    64 // ----------------------------------------------------------------------------
       
    65 // CATProject::~CATProject()
       
    66 // ----------------------------------------------------------------------------
       
    67 CATProject::~CATProject()
       
    68 {
       
    69 	LOG_FUNC_ENTRY("CATProject::~CATProject");
       
    70 
       
    71 	CleanModuleVectors();
       
    72 
       
    73 	// Delete analyzer
       
    74 	if ( m_pAnalyzer )
       
    75 		delete m_pAnalyzer;
       
    76 
       
    77 	// Temporary datafile
       
    78 	if ( !m_sDataFileTemp.empty() )
       
    79 	{
       
    80 		if ( FileExists( m_sDataFileTemp.c_str() ) )
       
    81 			FileDelete( m_sDataFileTemp, false );
       
    82 	}
       
    83 }
       
    84 
       
    85 bool CATProject::SetArguments( ARGUMENTS& arguments )
       
    86 {
       
    87 	LOG_FUNC_ENTRY("CATProject::SetArguments");
       
    88 	bool bRet = true;
       
    89 
       
    90 	//Project mode.
       
    91 	if( arguments.eHookSwitch == HOOK_INTERNAL )
       
    92 	{
       
    93 		SetMode( CATProject::COMPILE );
       
    94 		SetLoggingMode( CATProject::S60 );
       
    95 	}
       
    96 	else if ( arguments.eHookSwitch == HOOK_EXTERNAL )
       
    97 	{
       
    98 		SetMode( CATProject::COMPILE );
       
    99 		SetLoggingMode( CATProject::XTI );
       
   100 	}
       
   101 	else if ( arguments.eHookSwitch == HOOK_EXTERNAL_FAST )
       
   102 	{
       
   103 		SetMode( CATProject::COMPILE );
       
   104 		SetLoggingMode( CATProject::XTI_FAST );
       
   105 	}
       
   106 	/* Extension*/
       
   107 	else if ( arguments.eHookSwitch == HOOK_EXTENSION_INTERNAL )
       
   108 	{
       
   109 		SetMode( CATProject::INSTRUMENT );
       
   110 		SetLoggingMode( CATProject::S60 );
       
   111 	}
       
   112 	else if ( arguments.eHookSwitch == HOOK_EXTENSION_EXTERNAL )
       
   113 	{
       
   114 		SetMode( CATProject::INSTRUMENT );
       
   115 		SetLoggingMode( CATProject::XTI );
       
   116 	}
       
   117 	else if ( arguments.eHookSwitch == HOOK_EXTENSION_EXTERNAL_FAST )
       
   118 	{
       
   119 		SetMode( CATProject::INSTRUMENT );
       
   120 		SetLoggingMode( CATProject::XTI_FAST );
       
   121 	}
       
   122 	else if ( arguments.eHookSwitch == HOOK_EXTENSION_UNINSTRUMENT )
       
   123 	{
       
   124 		SetMode( CATProject::UNINSTRUMENT );
       
   125 	}
       
   126 	else if ( arguments.eHookSwitch == HOOK_EXTENSION_FAILED )
       
   127 	{
       
   128 		SetMode( CATProject::UNINSTRUMENT_FAILED );
       
   129 	}
       
   130 	//Return if uninstrumenting because no other arguments are set.
       
   131     if ( GetMode() == CATProject::UNINSTRUMENT
       
   132 		|| GetMode() == CATProject::UNINSTRUMENT_FAILED )
       
   133 	{
       
   134 		return bRet;
       
   135 	}
       
   136 
       
   137 	// No build / instrument.
       
   138 	if ( arguments.HOOK.bNoBuild )
       
   139 		SetMode( CATProject::INSTRUMENT_CONSOLE );
       
   140 
       
   141 	// Call stack sizes
       
   142 	SetAllocCallStackSize( arguments.HOOK.iAllocCallStackSize );
       
   143 	SetFreeCallStackSize( arguments.HOOK.iFreeCallStackSize );
       
   144 
       
   145 	//Build system.
       
   146 	if ( arguments.HOOK.iBuildSystem == 1 )
       
   147 		SetBuildSystem( CATProject::SBS_V1 );
       
   148 	else if ( arguments.HOOK.iBuildSystem == 2 )
       
   149 		SetBuildSystem( CATProject::SBS_V2 );
       
   150 
       
   151 	//Platform.
       
   152 	if ( !_stricmp( arguments.HOOK.sPlatform.c_str(), "armv5" ) )
       
   153 		SetPlatform( arguments.HOOK.sPlatform );
       
   154 	else if ( !_stricmp( arguments.HOOK.sPlatform.c_str(), "gcce" ) )
       
   155 		SetPlatform( arguments.HOOK.sPlatform );
       
   156 	else if ( !_stricmp( arguments.HOOK.sPlatform.c_str(), "winscw" ) )
       
   157 		SetPlatform( arguments.HOOK.sPlatform );
       
   158 	else
       
   159 	{
       
   160 		LOG_STRING( "Error, no supported platform specified (armv5/gcce/winscw).");
       
   161 		bRet = false;
       
   162 	}
       
   163 
       
   164 	//BuildType.
       
   165 	if ( !_stricmp( arguments.HOOK.sBuildType.c_str(), "urel" ) )
       
   166 		SetBuildType( CATProject::UREL );
       
   167 	else if ( !_stricmp( arguments.HOOK.sBuildType.c_str(), "udeb" ) )
       
   168 		SetBuildType( CATProject::UDEB );
       
   169 	else
       
   170 	{
       
   171 		LOG_STRING( "Error, no build type specified.");
       
   172 		bRet = false;
       
   173 	}
       
   174 
       
   175 	//Internal data file.
       
   176 	if ( arguments.HOOK.bDataFileName )
       
   177 		SetS60FileName( arguments.HOOK.sDataFileName );
       
   178 
       
   179 	//Build command.
       
   180 	if ( arguments.HOOK.sBuildCmd.empty() && ( 
       
   181 		GetMode() == CATProject::COMPILE ||
       
   182 		GetMode() == CATProject::INSTRUMENT ||
       
   183 		GetMode() == CATProject::INSTRUMENT_CONSOLE
       
   184 		))
       
   185 	{
       
   186 		cout << AT_MSG << "Error, no build command specified." << endl;
       
   187 		bRet = false;
       
   188 	}
       
   189 
       
   190 	SetBuildCommand( arguments.HOOK.sBuildCmd );
       
   191 
       
   192 	//Variant.
       
   193 	SetVariant( arguments.HOOK.sFeatureVariant );
       
   194 
       
   195 	//Target programs.
       
   196 	SetTargetModules( arguments.HOOK.vTargetPrograms );
       
   197 
       
   198 	return bRet;
       
   199 }
       
   200 
       
   201 void CATProject::CleanModuleVectors()
       
   202 {
       
   203 	LOG_FUNC_ENTRY("CATProject::CleanModuleVectors");
       
   204 	// delete modules from vector.
       
   205 	for( size_t i = 0; i < m_vModules.size()  ; i++ )
       
   206 		delete m_vModules[i];
       
   207 	m_vModules.clear();
       
   208 	
       
   209 	// Delete modules from vector (unsupported).
       
   210 	for( size_t i = 0; i < m_vUnsupportedModules.size()  ; i++ )
       
   211 		delete m_vUnsupportedModules[i];
       
   212 	m_vUnsupportedModules.clear();
       
   213 
       
   214 	// Delete modules from static library vector.
       
   215 	for( size_t i = 0; i < m_vStaticLibraries.size() ; i++ )
       
   216 		delete m_vStaticLibraries[i];
       
   217 	m_vStaticLibraries.clear();
       
   218 }
       
   219 // ----------------------------------------------------------------------------
       
   220 // CATProject::Run
       
   221 // ----------------------------------------------------------------------------
       
   222 int CATProject::Run()
       
   223 {
       
   224 	LOG_FUNC_ENTRY("CATProject::Run");
       
   225 	int iReturnCode = 0;
       
   226 	switch( m_eMode )
       
   227 	{
       
   228 	case COMPILE:
       
   229 		// Run compile
       
   230 		iReturnCode = RunCompile();
       
   231 		if ( iReturnCode == AT_RETURN_CODE::READ_MAKEFILE_ERROR
       
   232 			|| iReturnCode == AT_RETURN_CODE::KERNEL_SIDE_MODULE_ERROR
       
   233 			|| iReturnCode == AT_RETURN_CODE::INVALID_MMP_DEFINED )
       
   234 		{
       
   235 			DeleteTemporaryDirs();
       
   236 			DirDelete( AT_TEMP_DIR, true );
       
   237 		}
       
   238 		else
       
   239 		{
       
   240 			DisplayCompileSummary();
       
   241 			DisplayBuildSummary();
       
   242 		}
       
   243 		break;
       
   244 	case CLEAN:
       
   245 		iReturnCode = RunClean();
       
   246 		break;
       
   247 	case ANALYZE:
       
   248 		iReturnCode = RunAnalyze();
       
   249 		break;
       
   250 	case INSTRUMENT:
       
   251 		iReturnCode = RunInstrument();
       
   252 		break;
       
   253 	case INSTRUMENT_CONSOLE:
       
   254 		iReturnCode = RunInstrumentConsole();
       
   255 		if ( iReturnCode == AT_RETURN_CODE::READ_MAKEFILE_ERROR
       
   256 			|| iReturnCode == AT_RETURN_CODE::KERNEL_SIDE_MODULE_ERROR )
       
   257 		{
       
   258 			DeleteTemporaryDirs();
       
   259 			DirDelete( AT_TEMP_DIR, true );
       
   260 		}
       
   261 		else
       
   262 		{
       
   263 			DisplayBuildSummary();
       
   264 		}
       
   265 		break;
       
   266 	case UNINSTRUMENT:
       
   267 		iReturnCode = RunUninstrument();
       
   268 		// Show summary
       
   269 		DisplayCompileSummary();
       
   270 		DisplayBuildSummary();
       
   271 		break;
       
   272 	case UNINSTRUMENT_CONSOLE:
       
   273 		iReturnCode = RunUninstrumentConsole();
       
   274 		// Show summary
       
   275 		DisplayCompileSummary();
       
   276 		DisplayBuildSummary();
       
   277 		break;
       
   278 	case UNINSTRUMENT_FAILED:
       
   279 		iReturnCode = RunUninstrumentFailed();
       
   280 		// Display message
       
   281 		cout << AT_MSG << "Build aborted, because project contains compile error(s)."
       
   282 			<< endl;
       
   283 		break;
       
   284 	default:
       
   285 		cout << AT_MSG << "Error, mode not supported / implemented." << endl;
       
   286 		break;
       
   287 	}
       
   288 	// Error messages
       
   289 	switch( iReturnCode )
       
   290 	{
       
   291 		case AT_RETURN_CODE::MAKEFILE_ERROR:
       
   292 			cout << AT_MSG << "Error, creating/reading makefiles." << endl;
       
   293 			break;
       
   294 		case AT_RETURN_CODE::COMPILE_ERROR:
       
   295 			cout << AT_MSG << "Error, compiling project." << endl;
       
   296 			break;
       
   297 		case AT_RETURN_CODE::UNKNOWN:
       
   298 			cout << AT_MSG << "Error, unknown." << endl;
       
   299 			break;
       
   300 		case AT_RETURN_CODE::WRONG_DATA_FILE_VERSION:
       
   301 			cout << AT_MSG << "unable to analyze the data file.\n";
       
   302 			cout << AT_MSG << "wrong data file version.\n";
       
   303 			break;
       
   304 		case AT_RETURN_CODE::INVALID_DATA_FILE:
       
   305 			cout << AT_MSG << "Error, invalid datafile." << endl;
       
   306 			break;
       
   307 		case AT_RETURN_CODE::RELEASABLES_ERROR:
       
   308 			cout << AT_MSG << "Error, copying releasable(s)." << endl;
       
   309 			break;
       
   310 		case AT_RETURN_CODE::RESTORE_MODULES_ERROR:
       
   311 			cout << AT_MSG << "Error, restoring mmp file(s)." << endl;
       
   312 			break;
       
   313 		case AT_RETURN_CODE::CREATING_TEMP_CPP_ERROR:
       
   314 			cout << AT_MSG << "Error, creating temporary cpp file(s)." << endl;
       
   315 			break;
       
   316 		case AT_RETURN_CODE::CLEANING_TEMP_ERROR:
       
   317 			cout << AT_MSG << "Error, cleaning temporary dir(s)." << endl;
       
   318 			break;
       
   319 		case AT_RETURN_CODE::READ_MAKEFILE_ERROR:
       
   320 			cout << AT_MSG << "Error, reading makefile." << endl;
       
   321 			break;
       
   322 		case AT_RETURN_CODE::MODIFY_MODULES_ERROR:
       
   323 			cout << AT_MSG << "Error, modifying mmp file(s)." << endl;
       
   324 			break;
       
   325 		case AT_RETURN_CODE::INVALID_MMP_DEFINED:
       
   326 			break;
       
   327 		case AT_RETURN_CODE::WRITE_ATTRIBUTES_ERROR:
       
   328 			cout << AT_MSG << "Error, writing attributes." << endl;
       
   329 			break;
       
   330 		case AT_RETURN_CODE::READ_ATTRIBUTES_ERROR:
       
   331 			cout << AT_MSG << "Error, reading project configuration. Instrument project again." << endl;
       
   332 			break;
       
   333 		case AT_RETURN_CODE::EMPTY_DATA_FILE:
       
   334 			cout << AT_MSG << "Error, no data to be analyzed." << endl;
       
   335 			break;
       
   336 		case AT_RETURN_CODE::NO_SUPPORTED_MODULES_ERROR:
       
   337 			cout << AT_MSG << "Error, no modules found with supported target type." << endl;
       
   338 			break;
       
   339 		case AT_RETURN_CODE::KERNEL_SIDE_MODULE_ERROR:
       
   340 			cout << AT_MSG << "Error, kernel side component found component. Build/instrument aborted." << endl;
       
   341 			break;
       
   342 	}	
       
   343 	return iReturnCode;
       
   344 }
       
   345 // ----------------------------------------------------------------------------
       
   346 // CATProject::RunRecoveryAndExit()
       
   347 // Restore modules quick and exit. Used when user wants to kill/end process.
       
   348 // ----------------------------------------------------------------------------
       
   349 int CATProject::RunRecoveryAndExit()
       
   350 {
       
   351 	LOG_FUNC_ENTRY("CATProject::RunRecoveryAndExit");
       
   352 	cout << AT_MSG << "Error, user requested exit." << endl;
       
   353 	VerifyAndRecoverModules();
       
   354 	DeleteTemporaryDirs();
       
   355 	DirDelete( AT_TEMP_DIR, true );
       
   356 	cout << AT_MSG << "Exit." << endl;
       
   357 	return AT_RETURN_CODE::USER_ISSUED_EXIT;
       
   358 }
       
   359 
       
   360 // ----------------------------------------------------------------------------
       
   361 // CATProject::IsUninstrumented()
       
   362 // Reads projects configuration file if it exists. 
       
   363 // Return false in case the data contains information that project is
       
   364 // uninstrumented. Otherwise returns always true.
       
   365 // ----------------------------------------------------------------------------
       
   366 bool CATProject::IsUninstrumented()
       
   367 {
       
   368 	LOG_FUNC_ENTRY("CATProject::IsUninstrumented");
       
   369 	string sCfgFile( AT_TEMP_DIR );
       
   370 	sCfgFile.append( "\\" );
       
   371 	sCfgFile.append( AT_PROJECT_ATTRIBUTES_FILE_NAME );
       
   372 	if ( ! FileExists( sCfgFile.c_str() ) )
       
   373 		return true;
       
   374 	if( !ReadAttributes() )
       
   375 	{
       
   376 		LOG_STRING( "Error, reading project.cfg file." );
       
   377 		return false;
       
   378 	}
       
   379 	return m_bUninstrumented;
       
   380 }
       
   381 
       
   382 // ----------------------------------------------------------------------------
       
   383 // CATProject::RunCompile()
       
   384 // Helper functions to run different modes.
       
   385 // ----------------------------------------------------------------------------
       
   386 int CATProject::RunCompile()
       
   387 {
       
   388 	LOG_FUNC_ENTRY("CATProject::RunCompile");
       
   389 	// Store attributes
       
   390 	if( ! MakeTempDirIfNotExist() )
       
   391 		return AT_RETURN_CODE::WRITE_ATTRIBUTES_ERROR;
       
   392 	if ( ! WriteAttributes() )
       
   393 		return AT_RETURN_CODE::WRITE_ATTRIBUTES_ERROR;
       
   394 	// Create makefile
       
   395 	if ( ! CreateMakeFile() )
       
   396 		return AT_RETURN_CODE::MAKEFILE_ERROR;
       
   397 	// Read makefile to get project attributes
       
   398 	if ( ! ReadMakeFile() )
       
   399 		return AT_RETURN_CODE::READ_MAKEFILE_ERROR;
       
   400 	// Filter unsupported
       
   401 	FilterModules();
       
   402 	// Check that we have some "valid" modules to hook
       
   403 	if ( m_vModules.size() == 0 &&(  m_vUnsupportedModules.size() > 0 || m_vStaticLibraries.size() > 0 ) )
       
   404 		return AT_RETURN_CODE::NO_SUPPORTED_MODULES_ERROR;
       
   405 	// Check is possible target module defined in project
       
   406 	if ( ! IsTargetModuleInProject() )
       
   407 		return AT_RETURN_CODE::INVALID_MMP_DEFINED;
       
   408 	// Clean temporary dirs of modules
       
   409 	if ( ! CleanTemporaryDirs() )
       
   410 		return AT_RETURN_CODE::CLEANING_TEMP_ERROR;
       
   411 	// Create temporary cpps for modulse
       
   412 	if (! CreateTemporaryCpps() )
       
   413 		return AT_RETURN_CODE::CREATING_TEMP_CPP_ERROR;
       
   414 	// Hook modules
       
   415 	if (! ModifyModules() )
       
   416 		return AT_RETURN_CODE::MODIFY_MODULES_ERROR;
       
   417 	// Compile all
       
   418 	// Return code
       
   419 	int iRetCode = AT_RETURN_CODE::OK;
       
   420 	// Compile
       
   421 	if ( ! Compile() )
       
   422 		iRetCode = AT_RETURN_CODE::COMPILE_ERROR;
       
   423 	// Listings
       
   424 	if (! CreateListings() )
       
   425 		iRetCode = AT_RETURN_CODE::COMPILE_ERROR;
       
   426 	// Releasables
       
   427 	if (! CopyReleasables() )
       
   428 		iRetCode = AT_RETURN_CODE::RELEASABLES_ERROR;
       
   429 	// Restore "unhook" modules
       
   430 	if (! RestoreModules() )
       
   431 		iRetCode = AT_RETURN_CODE::RESTORE_MODULES_ERROR;
       
   432 	// Return error code OK
       
   433 	return iRetCode;
       
   434 }
       
   435 
       
   436 int CATProject::RunClean()
       
   437 {
       
   438 	LOG_FUNC_ENTRY("CATProject::RunClean");
       
   439 	int iRetCode = AT_RETURN_CODE::OK;
       
   440 	bool bNothingFound = true;
       
   441 	// Read attributes.
       
   442 	if (  ReadAttributes() )
       
   443 	{
       
   444 		bNothingFound = false;
       
   445 		if ( m_eBuildSystem == SBS_V1 )
       
   446 			InitSbs1MakeFileWithPathToTemp();
       
   447 		// Read makefile to get project attributes
       
   448 		if( ReadMakeFile() )
       
   449 		{
       
   450 			// Filter unsupported
       
   451 			FilterModules();
       
   452 			// Restore modules to make sure no changes left
       
   453 			if( VerifyAndRecoverModules() )
       
   454 			{
       
   455 				// Run reallyclean
       
   456 				switch ( m_eBuildSystem )
       
   457 				{
       
   458 				case SBS_V1:
       
   459 					RunReallyCleanSbs1();
       
   460 					break;
       
   461 				case SBS_V2:
       
   462 					RunReallyCleanSbs2();
       
   463 					break;
       
   464 				default:
       
   465 					break;
       
   466 				}
       
   467 				// Delete temporary dirs of modules
       
   468 				if(! DeleteTemporaryDirs() )
       
   469 				{
       
   470 					
       
   471 				}
       
   472 			}
       
   473 			else
       
   474 			{
       
   475 				
       
   476 			}
       
   477 		}
       
   478 	}
       
   479 	// Projects
       
   480 	if ( ! DirDelete( AT_TEMP_DIR, true ) )
       
   481 	{
       
   482 
       
   483 	}
       
   484 	else
       
   485 		bNothingFound = false;
       
   486 
       
   487 	if ( bNothingFound )
       
   488 		cout << AT_MSG << "Nothing found to clean." << endl;
       
   489 	else
       
   490 		cout << AT_MSG << "Cleaning done." << endl;
       
   491 	return iRetCode;
       
   492 }
       
   493 
       
   494 int CATProject::RunAnalyze()
       
   495 {
       
   496 	LOG_FUNC_ENTRY("CATProject::RunAnalyze");
       
   497 
       
   498 	// Parse data file if it is trace.
       
   499 	if ( !IsDataFile( m_sDataFile ) )
       
   500 	{
       
   501 		m_sDataFileTemp.clear();
       
   502 		m_sDataFileTemp.append( m_sDataFile );
       
   503 		m_sDataFileTemp.append( ".atool" );
       
   504 		cout << AT_MSG << "Parsing trace file..." << endl;
       
   505 		CATParseTraceFile Parser;
       
   506 		if ( ! Parser.StartParse( m_sDataFile.c_str(), m_sDataFileTemp.c_str() ) )
       
   507 		{
       
   508 			return AT_RETURN_CODE::EMPTY_DATA_FILE;
       
   509 		}
       
   510 		m_sDataFile = m_sDataFileTemp;
       
   511 	}
       
   512 
       
   513 	// Init makefile member for this run mode.
       
   514 	if ( m_eBuildSystem == SBS_V1 )
       
   515 		InitSbs1MakeFileWithPathToTemp();
       
   516 	// Read makefile to get project attributes
       
   517     if( ! ReadMakeFile() )
       
   518 	{
       
   519 		cout << AT_MSG << "Error, cannot find project build with AnalyzeTool." << endl;
       
   520 	}
       
   521 	else
       
   522 		FilterModules();
       
   523 
       
   524 	#ifndef ADDR2LINE
       
   525 	// Initialize modules locating code lines.
       
   526 	for( size_t i = 0 ; i < m_vModules.size() ; i++ )
       
   527 	{
       
   528 		m_vModules.at(i)->InitializeAddressToLine();
       
   529 	}
       
   530 	#endif
       
   531 
       
   532 	// Create analyzer
       
   533 	m_pAnalyzer = new CATDatParser( &m_vModules );
       
   534 
       
   535 	// Pass some info from project if it "exists" to analyzer.
       
   536 	if ( m_vModules.size() > 0 )
       
   537 	{
       
   538 		// Pass platform.
       
   539 		m_pAnalyzer->SetProjectPlatform( m_sPlatform );
       
   540 		// Pass build type.
       
   541 		m_pAnalyzer->SetProjectBuildType( m_eBuildType );
       
   542 	}
       
   543 	
       
   544 	// Set file.
       
   545 	m_pAnalyzer->SetInputFile( m_sDataFile );
       
   546 
       
   547 	// Set rom symbol file.
       
   548 	m_pAnalyzer->SetRomSymbolFiles( m_vRomSymbolFiles );
       
   549 
       
   550 	// Set output file if specified
       
   551 	if ( ! m_sDataFileOutput.empty() )
       
   552 	{
       
   553 		m_pAnalyzer->SetOutputFile( m_sDataFileOutput );
       
   554 	}
       
   555 	// Set log level
       
   556 	m_pAnalyzer->SetLogLevel( m_iLoggingLevel );
       
   557 
       
   558 	// Analyze
       
   559 	return m_pAnalyzer->Analyze();
       
   560 }
       
   561 
       
   562 int CATProject::RunInstrument()
       
   563 {
       
   564 	LOG_FUNC_ENTRY("CATProject::RunInstrument");
       
   565 	// Store attributes
       
   566 	if( ! MakeTempDirIfNotExist() )
       
   567 		return AT_RETURN_CODE::WRITE_ATTRIBUTES_ERROR;
       
   568 	if ( ! WriteAttributes() )
       
   569 		return AT_RETURN_CODE::WRITE_ATTRIBUTES_ERROR;
       
   570 	if ( m_eBuildSystem == SBS_V1 )
       
   571 	{
       
   572 		// Initialize level 1 make file member.
       
   573 		if ( ! InitSbs1MakeFileWithPath() )
       
   574 			return AT_RETURN_CODE::MAKEFILE_ERROR;
       
   575 		// Copy it to temporary folder.
       
   576 		CopyMakeFileSbs1ToTemporaryFolder();
       
   577 		// Run export.
       
   578 		if( ! RunExportSbs1() )
       
   579 			return AT_RETURN_CODE::MAKEFILE_ERROR;
       
   580 		// Create level 2 makefiles.
       
   581 		if ( ! CreateMakeFileSbs1Level2() )
       
   582 			return AT_RETURN_CODE::MAKEFILE_ERROR;
       
   583 	}
       
   584 	else if ( m_eBuildSystem == SBS_V2 )
       
   585 	{
       
   586 		// Create makefile only when using SBS v.2
       
   587 		if ( ! CreateMakeFile() )
       
   588 			return AT_RETURN_CODE::MAKEFILE_ERROR;
       
   589 	}
       
   590 	else
       
   591 	{
       
   592 		return AT_RETURN_CODE::UNKNOWN;
       
   593 	}
       
   594 	// Read makefile to get project attributes
       
   595 	if ( ! ReadMakeFile() )
       
   596 		return AT_RETURN_CODE::READ_MAKEFILE_ERROR;
       
   597 	// Filter unsupported
       
   598 	FilterModules();
       
   599 	// Check that we have some "valid" modules to hook
       
   600 	if ( m_vModules.size() == 0 &&(  m_vUnsupportedModules.size() > 0 || m_vStaticLibraries.size() > 0 ) )
       
   601 		return AT_RETURN_CODE::NO_SUPPORTED_MODULES_ERROR;
       
   602 
       
   603 	// Clean temporary dirs of modules
       
   604 	if ( ! CleanTemporaryDirs() )
       
   605 		return AT_RETURN_CODE::CLEANING_TEMP_ERROR;
       
   606 	// Create temporary cpps for modulse
       
   607 	if (! CreateTemporaryCpps() )
       
   608 		return AT_RETURN_CODE::CREATING_TEMP_CPP_ERROR;
       
   609 	// Hook modules
       
   610 	if (! ModifyModules() )
       
   611 		return AT_RETURN_CODE::MODIFY_MODULES_ERROR;
       
   612 	return AT_RETURN_CODE::OK;
       
   613 }
       
   614 
       
   615 int CATProject::RunInstrumentConsole()
       
   616 {
       
   617 	LOG_FUNC_ENTRY("CATProject::RunInstrumentConsole");
       
   618 	if( ! MakeTempDirIfNotExist() )
       
   619 		return AT_RETURN_CODE::UNKNOWN;
       
   620 	// Store attributes
       
   621 	m_bUninstrumented = false;
       
   622 	if ( ! WriteAttributes() )
       
   623 		return AT_RETURN_CODE::WRITE_ATTRIBUTES_ERROR;
       
   624 	// Create makefile
       
   625 	if ( ! CreateMakeFile() )
       
   626 		return AT_RETURN_CODE::MAKEFILE_ERROR;
       
   627 	// Read makefile to get project attributes
       
   628 	if ( ! ReadMakeFile() )
       
   629 		return AT_RETURN_CODE::READ_MAKEFILE_ERROR;
       
   630 	// Filter unsupported
       
   631 	FilterModules();
       
   632 	// Check that we have some "valid" modules to hook
       
   633 	if ( m_vModules.size() == 0 &&(  m_vUnsupportedModules.size() > 0 || m_vStaticLibraries.size() > 0 ) )
       
   634 		return AT_RETURN_CODE::NO_SUPPORTED_MODULES_ERROR;
       
   635 
       
   636 	// Clean temporary dirs of modules
       
   637 	if ( ! CleanTemporaryDirs() )
       
   638 		return AT_RETURN_CODE::CLEANING_TEMP_ERROR;
       
   639 	// Create temporary cpps for modulse
       
   640 	if (! CreateTemporaryCpps() )
       
   641 		return AT_RETURN_CODE::CREATING_TEMP_CPP_ERROR;
       
   642 	// Hook modules
       
   643 	if (! ModifyModules() )
       
   644 		return AT_RETURN_CODE::MODIFY_MODULES_ERROR;	
       
   645 	return AT_RETURN_CODE::OK;
       
   646 }
       
   647 
       
   648 int CATProject::RunUninstrument()
       
   649 {
       
   650 	LOG_FUNC_ENTRY("CATProject::RunUninstrument");
       
   651 	// Read attributes.
       
   652 	if ( ! ReadAttributes() )
       
   653 		return AT_RETURN_CODE::READ_ATTRIBUTES_ERROR;
       
   654 	// Init makefile member for this run mode.
       
   655 	if ( m_eBuildSystem == SBS_V1 )
       
   656 		InitSbs1MakeFileWithPathToTemp();
       
   657 	// Read makefile to get project attributes
       
   658 	if ( ! ReadMakeFile() )
       
   659 		return AT_RETURN_CODE::READ_MAKEFILE_ERROR;
       
   660 	// Filter unsupported
       
   661 	FilterModules();
       
   662 	// Check that we have some "valid" modules to hook
       
   663 	if ( m_vModules.size() == 0 &&(  m_vUnsupportedModules.size() > 0 || m_vStaticLibraries.size() > 0 ) )
       
   664 		return AT_RETURN_CODE::NO_SUPPORTED_MODULES_ERROR;
       
   665 	// Create lst files
       
   666     if (! CreateListings() )
       
   667 		return AT_RETURN_CODE::COMPILE_ERROR;
       
   668 	// Copy releasables of modules
       
   669 	if (! CopyReleasables() )
       
   670 		return AT_RETURN_CODE::RELEASABLES_ERROR;
       
   671 	// Restore "unhook" modules
       
   672 	if (! RestoreModules() )
       
   673 		return AT_RETURN_CODE::RESTORE_MODULES_ERROR;
       
   674 	// Return error code OK
       
   675 	return AT_RETURN_CODE::OK;
       
   676 }
       
   677 
       
   678 int CATProject::RunUninstrumentConsole()
       
   679 {
       
   680 	LOG_FUNC_ENTRY("CATProject::RunUninstrumentConsole");
       
   681 	int iErrorCode = AT_RETURN_CODE::OK;
       
   682 	// Read attributes
       
   683 	if ( ReadAttributes() )
       
   684 	{
       
   685 		// Init makefile member for this run mode.
       
   686 		if ( m_eBuildSystem == SBS_V1 )
       
   687 			InitSbs1MakeFileWithPathToTemp();
       
   688 		// Read makefile to get project attributes
       
   689 		if( ReadMakeFile() )
       
   690 		{
       
   691 			// Filter unsupported
       
   692 			FilterModules();
       
   693 			// Create lst files
       
   694 			CreateListings();
       
   695 			if (! CopyReleasables() )
       
   696 				iErrorCode = AT_RETURN_CODE::RELEASABLES_ERROR;
       
   697 		}
       
   698 		else
       
   699 			iErrorCode = AT_RETURN_CODE::READ_MAKEFILE_ERROR;
       
   700 		// Change state to uninstrumented and write status
       
   701 		m_bUninstrumented = true;
       
   702 		if ( ! WriteAttributes() )
       
   703 			iErrorCode = AT_RETURN_CODE::WRITE_ATTRIBUTES_ERROR;
       
   704 	}
       
   705 	else
       
   706 	{
       
   707 		iErrorCode = AT_RETURN_CODE::READ_ATTRIBUTES_ERROR;
       
   708 	}
       
   709 	return iErrorCode;
       
   710 }
       
   711 
       
   712 int CATProject::RunUninstrumentFailed()
       
   713 {
       
   714 	LOG_FUNC_ENTRY("CATProject::RunUninstrumentFailed");
       
   715 	// Read attributes.
       
   716 	if ( ! ReadAttributes() )
       
   717 		return AT_RETURN_CODE::READ_ATTRIBUTES_ERROR;
       
   718 	// Init makefile member for this run mode.
       
   719 	if ( m_eBuildSystem == SBS_V1 )
       
   720 		InitSbs1MakeFileWithPathToTemp();
       
   721 	// Read makefile to get project attributes
       
   722 	if( ReadMakeFile() )
       
   723 	{
       
   724 		// Filter modules
       
   725 		FilterModules();
       
   726 		// Restore modules to make sure no changes left
       
   727 		if( RestoreModules() )
       
   728 		{
       
   729 			// Delete temporary dirs of modules
       
   730 			if(! DeleteTemporaryDirs() )
       
   731 			{
       
   732 
       
   733 			}
       
   734 
       
   735 		}
       
   736 		else
       
   737 		{
       
   738 
       
   739 		}
       
   740 	}
       
   741 	else
       
   742 	{
       
   743 
       
   744 	}
       
   745 	// Projects
       
   746 	if ( ! DirDelete( AT_TEMP_DIR, true ) )
       
   747 	{
       
   748 
       
   749 	}
       
   750 	return AT_RETURN_CODE::OK;
       
   751 }
       
   752 
       
   753 // ----------------------------------------------------------------------------
       
   754 // Main Functions
       
   755 // ----------------------------------------------------------------------------
       
   756 void CATProject::DisplayCompileSummary()
       
   757 {
       
   758 	LOG_FUNC_ENTRY("CATProject::DisplayCompileSummary");
       
   759 	cout << AT_BUILD_SUMMARY_HEADER;
       
   760 	// Supported modules
       
   761 	for( size_t i = 0; i < m_vModules.size(); i++ )
       
   762 	{
       
   763 		// Successful
       
   764 		if ( m_vModules.at(i)->GetErrors().empty() )
       
   765 		{
       
   766 			// Create build complete file for Carbide xtension
       
   767 			m_vModules.at(i)->CreateBuildCompleteFile();
       
   768 			cout << AT_BUILD_SUMMARY_INSTRUMENTED_BUILD_COMPLETE
       
   769 				<< GetPathOrFileName( true, m_vModules.at(i)->GetMmpFile() )
       
   770 				<< endl
       
   771 				<< AT_BUILD_SUMMARY_TARGET
       
   772 				<< m_vModules.at(i)->GetBinaryName()
       
   773 				<< endl;
       
   774 			// Datafiles
       
   775 			// Use module data file name if project's data file not defined.
       
   776 			if ( m_eLoggingMode == CATProject::S60 
       
   777 				&& m_vModules.at(i)->GetTargetType().compare("exe") == 0 )
       
   778 			{
       
   779 				if ( m_sS60FileName.empty() )
       
   780 					cout << AT_BUILD_SUMMARY_DATA_FILE_NAME
       
   781 						<< m_vModules.at(i)->GetS60FileName()
       
   782 						<< endl;
       
   783 				else
       
   784 					cout << AT_BUILD_SUMMARY_DATA_FILE_NAME
       
   785 					<< m_sS60FileName
       
   786 					<< endl;
       
   787 			}
       
   788 		}
       
   789 		else
       
   790 		{
       
   791 			// Failed
       
   792 			cout << AT_BUILD_SUMMARY_FAILED
       
   793 				<< GetPathOrFileName( true, m_vModules.at(i)->GetMmpFile() )
       
   794 				<< endl
       
   795 				<< AT_BUILD_SUMMARY_TARGET
       
   796 				<< m_vModules.at(i)->GetBinaryName()
       
   797 				<< endl;
       
   798 			// Print errors.
       
   799 			cout << AT_BUILD_SUMMARY_ERRORS
       
   800 				<< m_vModules.at(i)->GetErrors()
       
   801 				<< endl;
       
   802 		}
       
   803 	}
       
   804 
       
   805 	// Static libraries
       
   806 	for( size_t i = 0; i < m_vStaticLibraries.size(); i++ )
       
   807 	{
       
   808 		if ( m_vStaticLibraries.at(i)->GetErrors().empty() )
       
   809 		{
       
   810 			cout << AT_BUILD_SUMMARY_NORMAL_BUILD_COMPLETE
       
   811 				<< GetPathOrFileName( true, m_vStaticLibraries.at(i)->GetMmpFile())
       
   812 				<< endl
       
   813 				<< AT_BUILD_SUMMARY_TARGET
       
   814 				<< m_vStaticLibraries.at(i)->GetBinaryName()
       
   815 				<< endl
       
   816 				<< AT_BUILD_SUMMARY_STATIC_LIBRARY
       
   817 				<< endl;
       
   818 				
       
   819 		}
       
   820 		else
       
   821 		{
       
   822 			// Failed
       
   823 			cout << AT_BUILD_SUMMARY_FAILED
       
   824 				<< GetPathOrFileName( true, m_vStaticLibraries.at(i)->GetMmpFile() )
       
   825 				<< endl
       
   826 				<< AT_BUILD_SUMMARY_TARGET
       
   827 				<< m_vStaticLibraries.at(i)->GetBinaryName()
       
   828 				<< endl;
       
   829 			// Print errors.
       
   830 			cout << AT_BUILD_SUMMARY_ERRORS
       
   831 				<< m_vStaticLibraries.at(i)->GetErrors()
       
   832 				<< endl;
       
   833 		}
       
   834 	}
       
   835 
       
   836 	// Unsupported modules
       
   837 	for( size_t i = 0; i < m_vUnsupportedModules.size(); i++ )
       
   838 	{
       
   839 		cout << AT_BUILD_SUMMARY_NORMAL_BUILD_COMPLETE
       
   840 			<< GetPathOrFileName( true, m_vUnsupportedModules.at(i)->GetMmpFile() )
       
   841 			<< endl
       
   842 			<< AT_BUILD_SUMMARY_TARGET
       
   843 			<< m_vUnsupportedModules.at(i)->GetBinaryName()
       
   844 			<< endl;
       
   845 		cout << m_vUnsupportedModules.at(i)->GetCompileInfoText() << endl;
       
   846 	}
       
   847 }
       
   848 
       
   849 void CATProject::DisplayBuildSummary( void )
       
   850 {
       
   851 	LOG_FUNC_ENTRY("CATProject::DisplayBuildSummary");
       
   852 	cout << endl;
       
   853 	// Build information
       
   854 	cout << AT_BUILD_SUMMARY_BUILD_TYPE << GetBuildTypeString() << endl;
       
   855 	// Platform
       
   856 	cout << AT_BUILD_SUMMARY_BUILD_PLATFORM << m_sPlatform << endl;
       
   857 	// Possible variant
       
   858 	if ( ! m_sVariant.empty() )
       
   859 		cout << AT_BUILD_SUMMARY_BUILD_VARIANT << m_sVariant << endl;
       
   860 	// Logging mode
       
   861 	cout << AT_BUILD_SUMMARY_LOGGING_MODE;
       
   862 	if ( m_eLoggingMode == S60 )
       
   863 		cout  << AT_BUILD_SUMMARY_S60;
       
   864 	else if ( m_eLoggingMode == XTI )
       
   865 		cout << AT_BUILD_SUMMARY_XTI;
       
   866 	else if ( m_eLoggingMode == XTI_FAST )
       
   867 		cout << AT_BUILD_SUMMARY_XTI_FAST;
       
   868 	cout << endl;
       
   869 	// Call stack sizes
       
   870 	cout << AT_BUILD_SUMMARY_ALLOC_CALL_STACK_SIZE
       
   871 		<< m_iAllocCallStackSize
       
   872 		<< endl;
       
   873 	cout << AT_BUILD_SUMMARY_FREE_CALL_STACK_SIZE
       
   874 		<< m_iFreeCallStackSize
       
   875 		<< endl;
       
   876 }
       
   877 
       
   878 bool CATProject::CreateMakeFile()
       
   879 {
       
   880 	switch ( m_eBuildSystem )
       
   881 	{
       
   882 	case SBS_V1:
       
   883 		if( ! CreateMakeFileSbs1() )
       
   884 			return false;
       
   885 		// Copy main make file.
       
   886 		if( ! CopyMakeFileSbs1ToTemporaryFolder() )
       
   887 			return false;
       
   888 		// Run Reallyclean.
       
   889 		if( ! RunReallyCleanSbs1() )
       
   890 			return false;
       
   891 		// Run export.
       
   892 		if( ! RunExportSbs1() )
       
   893 			return false;
       
   894 		// Create level 2 makefiles.
       
   895 		if( ! CreateMakeFileSbs1Level2() )
       
   896 			return false;
       
   897 		return true;
       
   898 	case SBS_V2:
       
   899 		return CreateMakeFileSbs2();
       
   900 	default:
       
   901 		return false;
       
   902 	}
       
   903 }
       
   904 
       
   905 bool CATProject::CreateMakeFileSbs1()
       
   906 {
       
   907 	LOG_FUNC_ENTRY("CATProject::CreateMakeFileSbs1");
       
   908 
       
   909 	// If variant defined check does it exist.
       
   910 	if( ! m_sVariant.empty() )
       
   911 	{
       
   912 		if ( ! CheckVariant( m_sEpocRoot, m_sVariant ) )
       
   913 		{
       
   914 			cout << INVALID_VARIANT_ERROR;
       
   915 			if ( IsDefaultVariant( m_sEpocRoot ) )
       
   916 			{
       
   917 				m_sVariant = "default";
       
   918 				cout << USING_DEFAULT_VARIANT_MESSAGE;
       
   919 				if ( ! WriteAttributes() )
       
   920 					return false;
       
   921 			}
       
   922 			else
       
   923 			{
       
   924 				cout << NO_DEFAULT_VARIANT_ERROR;
       
   925 				return false;
       
   926 			}
       
   927 		}
       
   928 	}
       
   929 
       
   930 	// Create level 1 make file.
       
   931 	string sCmd( "bldmake bldfiles " );
       
   932 	sCmd.append( m_sPlatform );
       
   933 	cout << AT_MSG_SYSTEM_CALL << sCmd << endl;
       
   934 	(void)system( sCmd.c_str() );
       
   935 	return InitSbs1MakeFileWithPath();
       
   936 }
       
   937 
       
   938 bool CATProject::CopyMakeFileSbs1ToTemporaryFolder()
       
   939 {
       
   940 	LOG_FUNC_ENTRY("CATProject::CopyMakeFileSbs1ToTemporaryFolder");
       
   941 	// Check that temporary dir exists if not create it.
       
   942 	if ( ! MakeTempDirIfNotExist() )
       
   943 		return false;
       
   944 	// Copy makefile to temporary directory
       
   945 	string sMakeFileInTemp( AT_TEMP_DIR );
       
   946 	sMakeFileInTemp.append( "\\" );
       
   947 	sMakeFileInTemp.append( AT_LEVEL_1_MAKEFILE_NAME );
       
   948 	if ( ! FileCopyToPath( m_sMakeFile, sMakeFileInTemp ) )
       
   949 		return false;
       
   950 	return true;
       
   951 
       
   952 }
       
   953 
       
   954 bool CATProject::RunReallyCleanSbs1()
       
   955 {
       
   956 	LOG_FUNC_ENTRY("CATProject::RunReallyCleanSbs1");
       
   957 	// Check that abld.bat has been made.
       
   958 	if ( ! FileExists( "abld.bat" ) )
       
   959 		return false;
       
   960 	// Run reallyclean.
       
   961 	string sCmd( "abld reallyclean ");
       
   962 	sCmd.append( m_sPlatform );
       
   963 	if ( ! m_sVariant.empty() )
       
   964 	{
       
   965 		sCmd.append( "." );
       
   966 		sCmd.append( m_sVariant );
       
   967 	}
       
   968 	sCmd.append( " " );
       
   969 	sCmd.append( GetBuildTypeString() );
       
   970 	if ( m_vTargetModules.size() > 1 )
       
   971 	{
       
   972 		RunAbldCommandToAllTargets( sCmd );
       
   973 	}
       
   974 	else
       
   975 	{
       
   976 		AddTargetModuleIfDefined( sCmd );
       
   977 		cout << AT_MSG_SYSTEM_CALL << sCmd << endl;
       
   978 		(void) system( sCmd.c_str() );
       
   979 	}
       
   980 	return true;
       
   981 }
       
   982 
       
   983 bool CATProject::RunReallyCleanSbs2()
       
   984 {
       
   985 	LOG_FUNC_ENTRY("CATProject::RunReallyCleanSbs2");
       
   986 	string sCmd("");
       
   987 	if ( m_sBuildCommand.empty() )
       
   988 	{
       
   989 		// If no build command defined (not found in project.cfg).
       
   990 		sCmd.append( RAPTOR_CMD_BASE );;
       
   991 		sCmd.append( m_sPlatform );
       
   992 		sCmd.append( "_" );
       
   993 		sCmd.append( GetBuildTypeString() );
       
   994 		if ( ! m_sVariant.empty() )
       
   995 		{
       
   996 			sCmd.append( "." );
       
   997 			sCmd.append( m_sVariant );
       
   998 		}
       
   999 		sCmd.append( RAPTOR_REALLYCLEAN_LOG );
       
  1000 		AddTargetModuleIfDefined( sCmd );
       
  1001 		sCmd.append( " REALLYCLEAN" );
       
  1002 	}
       
  1003 	else
       
  1004 	{
       
  1005 		// When build command set use it.
       
  1006 		sCmd.append( m_sBuildCommand );
       
  1007 		sCmd.append( RAPTOR_REALLYCLEAN_LOG );
       
  1008 		sCmd.append( " REALLYCLEAN" );
       
  1009 	}
       
  1010 	cout << AT_MSG_SYSTEM_CALL << sCmd << endl;
       
  1011 	int iRet = (int)system( sCmd.c_str() );
       
  1012 	if ( iRet == 0 )
       
  1013 		return true;
       
  1014 	return false;
       
  1015 }
       
  1016 
       
  1017 bool CATProject::RunExportSbs1()
       
  1018 {
       
  1019 	LOG_FUNC_ENTRY("CATProject::RunExportSbs1");
       
  1020 	// Run export.
       
  1021 	cout << AT_MSG_SYSTEM_CALL << "abld export" << endl;
       
  1022 	(void) system( "abld export" );
       
  1023 	return true;
       
  1024 }
       
  1025 
       
  1026 bool CATProject::CreateMakeFileSbs1Level2()
       
  1027 {
       
  1028 	LOG_FUNC_ENTRY("CATProject::CreateMakeFileSbs1Level2");
       
  1029 	// Create level 2 makefiles.
       
  1030 	string sCmd( "abld makefile ");
       
  1031 	sCmd.append( m_sPlatform );
       
  1032 	if ( ! m_sVariant.empty() )
       
  1033 	{
       
  1034 		sCmd.append( "." );
       
  1035 		sCmd.append( m_sVariant );
       
  1036 	}
       
  1037 		// Check if multiple targets defined and sbs 1.
       
  1038 	if ( m_vTargetModules.size() > 1 )
       
  1039 	{
       
  1040 		RunAbldCommandToAllTargets( sCmd );
       
  1041 	}
       
  1042 	else
       
  1043 	{
       
  1044 		AddTargetModuleIfDefined( sCmd );
       
  1045 		cout << AT_MSG_SYSTEM_CALL << sCmd << endl;
       
  1046 		(void) system( sCmd.c_str() );
       
  1047 	}
       
  1048 	return true;
       
  1049 }
       
  1050 
       
  1051 bool CATProject::CreateMakeFileSbs2()
       
  1052 {
       
  1053 	LOG_FUNC_ENTRY("CATProject::CreateMakeFileSbs2");
       
  1054 	// Delete build directory if it exists before creating new makefiles.
       
  1055 	if ( DirectoryExists( "atool_temp\\build" ) )
       
  1056 		DirDelete( "atool_temp\\build", true );
       
  1057 	// Create command to create makefiles.
       
  1058 	string sCmd( m_sBuildCommand );
       
  1059 	sCmd.append( " " );
       
  1060 	sCmd.append( RAPTOR_MAKEFILE_SWITCH );
       
  1061 	sCmd.append( " " );
       
  1062 	sCmd.append( RAPTOR_NOBUILD_SWITCH );
       
  1063 	cout << AT_MSG_SYSTEM_CALL << sCmd << endl;
       
  1064 	int iRet = (int)system( sCmd.c_str() );
       
  1065 	if ( iRet == 0 )
       
  1066 		return true;
       
  1067 	return false;
       
  1068 }
       
  1069 
       
  1070 bool CATProject::ReadMakeFile()
       
  1071 {
       
  1072 	// Clean modules before reading.
       
  1073 	CleanModuleVectors();
       
  1074 	if ( m_eBuildSystem == SBS_V1 )
       
  1075 	{
       
  1076 		// Read level 1 makefile which contains module name and makefiles.
       
  1077 		if( ! ReadMakeFileSbs1Level1() )
       
  1078 			return false;
       
  1079 		// Read level 2 makefiles.
       
  1080 		vector<CATModule2*>::iterator it;
       
  1081 		// If we are compiling or etc... we need to create temporary directories.
       
  1082 		if ( m_eMode == COMPILE || m_eMode == INSTRUMENT || m_eMode == INSTRUMENT_CONSOLE )
       
  1083 		{
       
  1084 			// Read make makefiles from /epoc32/build... and create temporary directory.
       
  1085 			bool bLevel2 = true;
       
  1086 			for( it = m_vModules.begin(); it != m_vModules.end() ; it ++ )
       
  1087 			{
       
  1088 				if( ! (*it)->CreateTemporaryDirectory() )
       
  1089 					return false;
       
  1090 				if( ! (*it)->ReadMakeFile() )
       
  1091 				{
       
  1092 					bLevel2 = false;
       
  1093 					break;
       
  1094 				}
       
  1095 			}
       
  1096 			// If failed reading modules from level 2 makefiles.
       
  1097 			if ( ! bLevel2 )
       
  1098 			{
       
  1099 				// Clean modules.
       
  1100 				CleanModuleVectors();
       
  1101 				// Try use default variant if it exists.
       
  1102 				if ( CheckVariant( m_sEpocRoot, "default" ) )
       
  1103 				{
       
  1104 					m_sVariant = "default";
       
  1105 					cout << USING_DEFAULT_VARIANT_MESSAGE;
       
  1106 					if ( ! WriteAttributes() )
       
  1107 						return false;
       
  1108 					if ( ! InitSbs1MakeFileWithPath() )
       
  1109 						return false;
       
  1110 					if ( ! ReadMakeFileSbs1Level1() )
       
  1111 						return false;
       
  1112 					for( it = m_vModules.begin(); it != m_vModules.end() ; it ++ )
       
  1113 					{
       
  1114 						if( ! (*it)->CreateTemporaryDirectory() )
       
  1115 							return false;
       
  1116 						if( ! (*it)->ReadMakeFile() )
       
  1117 							return false;
       
  1118 					}
       
  1119 
       
  1120 				}
       
  1121 			}
       
  1122 		}
       
  1123 		else
       
  1124 		{
       
  1125 			// Read make files from temporary directories.
       
  1126 			for( it = m_vModules.begin(); it != m_vModules.end() ; it ++ )
       
  1127 			{
       
  1128 				if ( ! (*it)->ReadMakeFileFromTemp() )
       
  1129 					return false;
       
  1130 			}
       
  1131 		}
       
  1132 		return true;
       
  1133 	}
       
  1134 	else if ( m_eBuildSystem == SBS_V2 )
       
  1135 	{
       
  1136 		// Read make file.
       
  1137 		if( ! ReadMakeFileSbs2() )
       
  1138 			return false;
       
  1139 		// Create module temporary directories if we are compiling or etc...
       
  1140 		if ( m_eMode == COMPILE || m_eMode == INSTRUMENT || m_eMode == INSTRUMENT_CONSOLE )
       
  1141 			{
       
  1142 			for( vector<CATModule2*>::iterator it = m_vModules.begin(); it < m_vModules.end(); it++ )
       
  1143 				(*it)->CreateTemporaryDirectory();
       
  1144 			for( vector<CATModule2*>::iterator it = m_vStaticLibraries.begin(); it < m_vStaticLibraries.end(); it++ )
       
  1145 				(*it)->CreateTemporaryDirectory();
       
  1146 			}
       
  1147 	}
       
  1148 	return true;
       
  1149 }
       
  1150 
       
  1151 bool CATProject::ReadMakeFileSbs1Level1()
       
  1152 {
       
  1153 	LOG_FUNC_ENTRY("CATProject::ReadMakeFileSbs1Level1");
       
  1154 
       
  1155 	bool bRet = false;
       
  1156 
       
  1157 	//Try to open makefile
       
  1158 	ifstream in;
       
  1159 	in.open( m_sMakeFile.c_str() );
       
  1160 
       
  1161 	//File open ok?
       
  1162 	if( !in.good() )
       
  1163 	{
       
  1164 		printf( "Can not open file: %s\n", m_sMakeFile.c_str() );
       
  1165 		in.close();
       
  1166 		return bRet;
       
  1167 	}
       
  1168 
       
  1169 	// Add also these so "compatible with sbs2".
       
  1170 	// Releasables path (binaries).
       
  1171 	string sReleasePath( m_sEpocRoot );
       
  1172 	// add trailing '\' if root path is missing it
       
  1173 	if ( sReleasePath.size() < 1 )
       
  1174 		sReleasePath.append( "\\" );
       
  1175 	else if ( sReleasePath.at( sReleasePath.length() -1 ) != '\\' )
       
  1176 		sReleasePath.append( "\\" );
       
  1177 	sReleasePath.append( "epoc32\\release" );
       
  1178 	string sFullVariantPath( m_sPlatform );
       
  1179 	sFullVariantPath.append( "\\" );
       
  1180 	sFullVariantPath.append( GetBuildTypeString() );
       
  1181 
       
  1182 	char cTemp[MAX_LINE_LENGTH];
       
  1183 	bool bContinueSearch = true;
       
  1184 	bool bMmpInfoFound = false;
       
  1185 	CATModule2* pModule = 0;
       
  1186 	string sTempLineFromFile;
       
  1187 	do
       
  1188 	{
       
  1189 		// get line from file
       
  1190 		in.getline( cTemp, MAX_LINE_LENGTH );
       
  1191 		sTempLineFromFile.clear();
       
  1192 		sTempLineFromFile.append( cTemp );
       
  1193 
       
  1194 		//Search makefile string
       
  1195 		if( sTempLineFromFile.find( MAKEFILE_SEARCH_STRING ) != string::npos )
       
  1196 		{
       
  1197 			bMmpInfoFound = true;
       
  1198 			if( sTempLineFromFile.find( MMPFILE_SEARCH_STRING ) != string::npos )
       
  1199 			{
       
  1200 				bRet = true;
       
  1201 				//Parse mmp path + mmp filename
       
  1202 				sTempLineFromFile.erase( 0, sTempLineFromFile.find_first_of("\"") );
       
  1203 				sTempLineFromFile.erase( 0, 1 );
       
  1204 
       
  1205 				string sPath = sTempLineFromFile.substr(0, sTempLineFromFile.find_first_of("\"") );
       
  1206 
       
  1207 				sPath = ChangeSlashToBackSlash( sPath );
       
  1208 				//Remove text "bld.inf"
       
  1209 				sPath.erase( (sPath.find_last_of( "\\" ) + 1) , string::npos );
       
  1210 
       
  1211 				string sFileName = sTempLineFromFile.substr( (sTempLineFromFile.find( MMPFILE_SEARCH_STRING ) + strlen(MMPFILE_SEARCH_STRING) + 3), string::npos );
       
  1212 				sFileName = ChangeSlashToBackSlash( sFileName );
       
  1213 				sFileName = sFileName.substr( 0, sFileName.find_first_of("\"") );
       
  1214 
       
  1215 				// Append .mmp to filename if it does not exist
       
  1216 				if ( sFileName.find(".mmp") == string::npos )
       
  1217 					sFileName.append(".mmp");
       
  1218 
       
  1219 				//Insert drive letter
       
  1220 				sPath.insert(0, string( m_cCurrentDir).substr(0,2) );
       
  1221 		
       
  1222 				//Insert mmp file to the end
       
  1223 				sPath.append( sFileName );
       
  1224 
       
  1225 				ChangeToLower( sPath );
       
  1226 				
       
  1227 				// If target programs defined find from those or do not
       
  1228 				// add module to vector.
       
  1229 				bool bAddToVector = true;
       
  1230 				if ( m_vTargetModules.size() > 0 )
       
  1231 				{
       
  1232 					bAddToVector = false;
       
  1233 					vector<string>::iterator it;
       
  1234 					for( it = m_vTargetModules.begin() ; it != m_vTargetModules.end() ; it++ )
       
  1235 					{
       
  1236 						string sFind( *it );
       
  1237 						sFind.insert( 0, "\\" );
       
  1238 						if ( sPath.find( sFind ) != string::npos )
       
  1239 						{
       
  1240 							bAddToVector = true;
       
  1241 							break;
       
  1242 						}
       
  1243 					}	
       
  1244 				}
       
  1245 
       
  1246 				if ( bAddToVector )
       
  1247 				{
       
  1248 					pModule = new CATModule2();
       
  1249 					pModule->SetMmpFile( sPath );
       
  1250 					pModule->SetVariantType( GetBuildTypeString() );
       
  1251 					pModule->SetVariantPlatform( m_sPlatform );
       
  1252 					pModule->SetReleasePath( sReleasePath );
       
  1253 					pModule->SetFullVariantPath( sFullVariantPath );
       
  1254 					pModule->SetBuildSystem( SBS_V1 );
       
  1255 					m_vModules.push_back( pModule );
       
  1256 				}
       
  1257 			}
       
  1258 		}
       
  1259 		else if( bMmpInfoFound )
       
  1260 			//Do not continue search if mmp info lines are all handled
       
  1261 			bContinueSearch = false;
       
  1262 		if( !in.good() )
       
  1263 			bContinueSearch = false;
       
  1264 	}
       
  1265 	while( bContinueSearch );
       
  1266 
       
  1267 	bContinueSearch = true;
       
  1268 
       
  1269 	//Search MAKEFILES for invidual modules
       
  1270 	do
       
  1271 	{
       
  1272 		in.getline( cTemp, MAX_LINE_LENGTH );
       
  1273 		sTempLineFromFile.clear();
       
  1274 		sTempLineFromFile.append( cTemp );
       
  1275 		// find the lines 'MAKEFILE[modulename]_FILES'
       
  1276 		if( (sTempLineFromFile.find( "MAKEFILE" ) == 0) && (sTempLineFromFile.find( "_FILES" ) != string::npos) )
       
  1277 		{
       
  1278 			//Math the makefile line with one of our modules
       
  1279 			for( size_t i = 0 ; i < m_vModules.size() ; i++ )
       
  1280 			{
       
  1281 				//Create name
       
  1282 				string sMakeFile( "MAKEFILE" );
       
  1283 				string sTempMmpFile( RemovePathAndExt( m_vModules.at(i)->GetMmpFile(), true ) );
       
  1284 				ChangeToUpper( sTempMmpFile );
       
  1285 				sMakeFile.append( sTempMmpFile );
       
  1286 				sMakeFile.append( "_FILES" );
       
  1287 				// matched
       
  1288 				if( sTempLineFromFile.find( sMakeFile ) != string::npos )
       
  1289 				{
       
  1290 					//parse the makefile name from line
       
  1291 					in.getline( cTemp, MAX_LINE_LENGTH );
       
  1292 					sTempLineFromFile.clear();
       
  1293 					sTempLineFromFile.append( cTemp );
       
  1294 					//Remove character "\""
       
  1295 					sTempLineFromFile.erase( 0, ( sTempLineFromFile.find_first_of("\"") + 1 ) );
       
  1296 					// in winscw last part is '" \' and on armd '"' so remove all after last '"'
       
  1297 					sTempLineFromFile.erase( sTempLineFromFile.find_last_of("\""), sTempLineFromFile.size() );
       
  1298 					// Set correct makefile for module
       
  1299 					m_vModules.at( i )->SetMakeFile( sTempLineFromFile );
       
  1300 					// break 
       
  1301 					break;
       
  1302 				} // If mathed to mmp
       
  1303 			} // End of mmp file loop
       
  1304 		} // found lines 'MAKEFILE[modulename]_FILES'
       
  1305 		if( !in.good() )
       
  1306 			bContinueSearch = false;
       
  1307 	}
       
  1308 	while( bContinueSearch );
       
  1309 	in.close();
       
  1310 	return bRet;
       
  1311 }
       
  1312 
       
  1313 bool CATProject::ReadMakeFileSbs2( void )
       
  1314 {
       
  1315 	LOG_FUNC_ENTRY("CATProject::ReadMakeFileSbs2(void)");
       
  1316 	// File is by default named make_build.default but when building specific layer
       
  1317 	// make_build_LAYERNAME.default is produced by Raptor.
       
  1318 	// So find makefile(s) and read them.
       
  1319 	vector<string> vMakeFiles = DirList( "atool_temp\\build\\", false, true );
       
  1320 	bool bRet = true;
       
  1321 	for( vector<string>::iterator it = vMakeFiles.begin(); it != vMakeFiles.end() ; it++ )
       
  1322 	{
       
  1323 		// Recognize multiple makefiles.
       
  1324 		if ( it->find("make_build_") != string::npos && it->find(".default") != string::npos )
       
  1325 		{
       
  1326 			if ( ! ReadMakeFileSbs2( *it ) )
       
  1327 				bRet = false;
       
  1328 		}
       
  1329 		// Single makefile.
       
  1330 		else if ( it->find( "make_build.default" ) != string::npos )
       
  1331 		{
       
  1332 			if ( ! ReadMakeFileSbs2( *it ) )
       
  1333 				bRet = false;
       
  1334 		}
       
  1335 	}
       
  1336 	// We got some modules?
       
  1337 	if ( m_vModules.size() == 0 )
       
  1338 		bRet = false;
       
  1339 	return bRet;
       
  1340 }
       
  1341 
       
  1342 bool CATProject::ReadMakeFileSbs2( string& sMakeFile )
       
  1343 {
       
  1344 	LOG_FUNC_ENTRY("CATProject::ReadMakeFileSbs2(string)");
       
  1345 	try {
       
  1346 		// Open file
       
  1347 		ifstream in;
       
  1348 		in.open( sMakeFile.c_str() , ios_base::in );
       
  1349 		// Check that open ok
       
  1350 		if ( ! in.good() )
       
  1351 		{
       
  1352 			cout << AT_MSG << "Error, opening file "
       
  1353 				<< RAPTOR_MAKEFILE << endl;
       
  1354 			in.close();
       
  1355 			return false;
       
  1356 		}
       
  1357 		// Source line from file
       
  1358 		string sSourceLine;
       
  1359 		// Module pointer
       
  1360 		CATModule2* pModule = 0;
       
  1361 		// Line from file
       
  1362 		char cLine[MAX_LINE_LENGTH];
       
  1363 		// Are we looking for module attributes
       
  1364 		bool bFindAttributes = false;
       
  1365 		// Until end of file
       
  1366 		while( in.good() )
       
  1367 		{
       
  1368 			// Get new line from file
       
  1369 			in.getline( cLine, MAX_LINE_LENGTH );
       
  1370 			string sLine(cLine);
       
  1371 			// New module
       
  1372 			if ( sLine.find( RAPTOR_PROJECT_META ) == 0 )
       
  1373 			{
       
  1374 				// Remove project_meta from line
       
  1375 				sLine.erase(0, strlen( RAPTOR_PROJECT_META ) );
       
  1376 				LOG_STRING("Found module: " << sLine );
       
  1377 				// Check is name empty
       
  1378 				// This seems to happen when sbs2 "wraps" i.e. mifconv to a module type item
       
  1379 				if ( sLine.empty() )
       
  1380 				{
       
  1381 					LOG_STRING("skipping empty module");
       
  1382 					// Skip it
       
  1383 					continue;
       
  1384 				}
       
  1385 				// If module add it to vector
       
  1386 				if ( pModule )
       
  1387 				{
       
  1388 					// Add sources,
       
  1389 					pModule->AddSources( sSourceLine );
       
  1390 					// Build system.
       
  1391 					pModule->SetBuildSystem( SBS_V1 );
       
  1392 					// Push to vector.
       
  1393 					m_vModules.push_back( pModule );
       
  1394 				}
       
  1395 				// New module
       
  1396 				pModule = new CATModule2();
       
  1397 				// Clear sourceline
       
  1398 				sSourceLine.clear();
       
  1399 				// Set modules mmp with path
       
  1400 
       
  1401 				if ( ! pModule->SetMmpFile( sLine ) )
       
  1402 				{
       
  1403 					// Fatal error setting mmp file
       
  1404 					in.close();
       
  1405 					return false;
       
  1406 				}
       
  1407 				// Find attributes on
       
  1408 				bFindAttributes = true;
       
  1409 				// Get new line from file
       
  1410 				in.getline( cLine, MAX_LINE_LENGTH );
       
  1411 			}
       
  1412 			// If attribute finding on
       
  1413 			if ( bFindAttributes )
       
  1414 			{
       
  1415 				// Pickup modules attributes
       
  1416 				if ( sLine.find ( RAPTOR_SOURCE ) == 0 )
       
  1417 				{
       
  1418 					sLine.erase(0, strlen( RAPTOR_SOURCE ) );
       
  1419 					sSourceLine = sLine;
       
  1420 				}
       
  1421 				else if ( sLine.find ( RAPTOR_TARGET ) == 0 )
       
  1422 				{
       
  1423 					sLine.erase(0, strlen( RAPTOR_TARGET ) );
       
  1424 					pModule->SetTarget( sLine );
       
  1425 				}
       
  1426 				else if ( sLine.find ( RAPTOR_TARGETYPE ) == 0 )
       
  1427 				{
       
  1428 					sLine.erase(0, strlen( RAPTOR_TARGETYPE ));
       
  1429 					pModule->SetTargetType( sLine );
       
  1430 				}
       
  1431 				else if ( sLine.find( RAPTOR_REQUESTEDTARGETEXT ) == 0 )
       
  1432 				{
       
  1433 					sLine.erase(0, strlen( RAPTOR_REQUESTEDTARGETEXT ) );
       
  1434 					pModule->SetRequestedTargetExt( sLine );
       
  1435 				}
       
  1436 				else if ( sLine.find ( RAPTOR_VARIANTPLATFORM ) == 0 )
       
  1437 				{
       
  1438 					sLine.erase(0, strlen( RAPTOR_VARIANTPLATFORM ));
       
  1439 					pModule->SetVariantPlatform( sLine );
       
  1440 				}
       
  1441 				else if ( sLine.find ( RAPTOR_VARIANTTYPE ) == 0 )
       
  1442 				{
       
  1443 					sLine.erase(0, strlen( RAPTOR_VARIANTTYPE ));
       
  1444 					pModule->SetVariantType( sLine );
       
  1445 				}
       
  1446 				else if ( sLine.find ( RAPTOR_FEATUREVARIANT ) == 0 )
       
  1447 				{
       
  1448 					sLine.erase(0, strlen( RAPTOR_FEATUREVARIANT ));
       
  1449 					pModule->SetFeatureVariant( sLine );
       
  1450 				}
       
  1451 				else if ( sLine.find ( RAPTOR_FEATUREVARIANTNAME ) == 0 )
       
  1452 				{
       
  1453 					sLine.erase(0, strlen( RAPTOR_FEATUREVARIANTNAME ));
       
  1454 					pModule->SetFeatureVariantName( sLine );
       
  1455 				}
       
  1456 				else if ( sLine.find ( RAPTOR_RELEASEPATH ) == 0 )
       
  1457 				{
       
  1458 					sLine.erase(0, strlen( RAPTOR_RELEASEPATH ));
       
  1459 					pModule->SetReleasePath( sLine );
       
  1460 				}
       
  1461 				else if ( sLine.find ( RAPTOR_FULLVARIANTPATH ) == 0 )
       
  1462 				{
       
  1463 					sLine.erase(0, strlen( RAPTOR_FULLVARIANTPATH ));
       
  1464 					pModule->SetFullVariantPath( sLine );
       
  1465 				}
       
  1466 				else if ( sLine.find ( RAPTOR_COMPILE_DEFINITIONS ) == 0 )
       
  1467 				{
       
  1468 					sLine.erase(0, strlen( RAPTOR_COMPILE_DEFINITIONS ) );
       
  1469 					pModule->SetCompileDefinitions( sLine );
       
  1470 				}
       
  1471 			}
       
  1472 		} // while in.good()
       
  1473 		// Add last module if n number of modules found
       
  1474 		if ( pModule )
       
  1475 		{
       
  1476 			if ( ! pModule->GetTarget().empty() )
       
  1477 			{
       
  1478 				// Add sources
       
  1479 				pModule->AddSources( sSourceLine );
       
  1480 				// Build system.
       
  1481 				pModule->SetBuildSystem( SBS_V1 );
       
  1482 				// Push back to vector
       
  1483 				m_vModules.push_back( pModule );
       
  1484 			}
       
  1485 		}
       
  1486 		// Close file
       
  1487 		in.close();
       
  1488 		return true;
       
  1489 	} // try.
       
  1490 	catch(...)
       
  1491 	{
       
  1492 		LOG_STRING("Unexpected exception reading sbs 2 makefile");
       
  1493 		return false;
       
  1494 	}
       
  1495 }
       
  1496 bool CATProject::CreateTemporaryDirectories()
       
  1497 {
       
  1498 	LOG_FUNC_ENTRY("CATProject::CreateTemporaryDirectories");
       
  1499 	bool bRet = true;
       
  1500 	for( size_t i = 0 ; i < m_vModules.size(); i++)
       
  1501 	{
       
  1502 		if( ! m_vModules.at(i)->CreateTemporaryDirectory() )
       
  1503 			bRet = false;
       
  1504 	}
       
  1505 	for( size_t i = 0 ; i < m_vStaticLibraries.size(); i++)
       
  1506 	{
       
  1507 		if( ! m_vStaticLibraries.at(i)->CreateTemporaryDirectory() )
       
  1508 			bRet = false;
       
  1509 	}
       
  1510 	return bRet;
       
  1511 
       
  1512 }
       
  1513 
       
  1514 bool CATProject::CreateTemporaryCpps()
       
  1515 {
       
  1516 	LOG_FUNC_ENTRY("CATProject::CreateTemporaryCpps");
       
  1517 	bool bRet = true;
       
  1518 	for( size_t i = 0 ; i < m_vModules.size(); i++)
       
  1519 	{
       
  1520 		if( ! m_vModules.at(i)->CreateTempCpp(
       
  1521 			m_sS60FileName, m_eLoggingMode, m_eBuildType, m_iAllocCallStackSize, m_iFreeCallStackSize ) )
       
  1522 			bRet = false;
       
  1523 	}
       
  1524 	return bRet;
       
  1525 }
       
  1526 
       
  1527 bool CATProject::FilterModules()
       
  1528 {
       
  1529 	LOG_FUNC_ENTRY("CATProject::FilterModules");
       
  1530 	vector<CATModule2*>::iterator it;
       
  1531 	// Loop thru modules.
       
  1532 	it = m_vModules.begin();
       
  1533 	while( it != m_vModules.end() )
       
  1534 	{
       
  1535 		// Get target type of module to separate string (will be modified).
       
  1536 		string sTargetType = (*it)->GetTargetType();
       
  1537 		// Modules compile definitions.
       
  1538 		string sCompileDefinition = (*it)->GetCompileDefinitions();
       
  1539 		// Check is it supported.
       
  1540 		if ( !IsTargetTypeSupported( sTargetType) )
       
  1541 		{
       
  1542 			(*it)->SetCompileInfoText( AT_UNSUPPORTED_TARGET_TYPE );
       
  1543 			// Not supported add to not supported vector.
       
  1544 			m_vUnsupportedModules.push_back( *it );
       
  1545 			// Erase cell.
       
  1546 			it = m_vModules.erase( it );
       
  1547 		}
       
  1548 		// Check if its static library
       
  1549 		else if ( _stricmp( sTargetType.c_str(), "lib" ) == 0 )
       
  1550 		{
       
  1551 			// Static librarie move to their vector.
       
  1552 			m_vStaticLibraries.push_back( *it );
       
  1553 			// Erase cell.
       
  1554 			it = m_vModules.erase( it );
       
  1555 		
       
  1556 		}
       
  1557 		else if ( sCompileDefinition.find( KERNEL_MODE_COMPILE_DEFINITION ) != string::npos )
       
  1558 		{
       
  1559 			(*it)->SetCompileInfoText( AT_UNSUPPORTED_COMPILE_DEFINITION );
       
  1560 			// Not supported add to not supported vector.
       
  1561 			m_vUnsupportedModules.push_back( *it );
       
  1562 			// Erase cell.
       
  1563 			it = m_vModules.erase( it );
       
  1564 		}
       
  1565 		else
       
  1566 			it++;
       
  1567 	}
       
  1568 	return true;
       
  1569 }
       
  1570 
       
  1571 bool CATProject::ModifyModules()
       
  1572 {
       
  1573 	LOG_FUNC_ENTRY("CATProject::ModifyModules");
       
  1574 	bool bRet = true;
       
  1575 	for( size_t i = 0; i < m_vModules.size(); i++ )
       
  1576 	{
       
  1577 		if (! m_vModules.at(i)->ModifyMmp() )
       
  1578 			bRet = false;
       
  1579 	}
       
  1580 	for( size_t i = 0; i < m_vStaticLibraries.size(); i++ )
       
  1581 	{
       
  1582 		if (! m_vStaticLibraries.at(i)->ModifyMmp() )
       
  1583 			bRet = false;
       
  1584 	}
       
  1585 	return bRet;
       
  1586 }
       
  1587 
       
  1588 bool CATProject::RestoreModules()
       
  1589 {
       
  1590 	LOG_FUNC_ENTRY("CATProject::RestoreModules");
       
  1591 	bool bRet = true;
       
  1592 	for( size_t i = 0; i < m_vModules.size(); i++ )
       
  1593 	{
       
  1594 		if (! m_vModules.at(i)->RestoreMmp() )
       
  1595 			bRet = false;
       
  1596 	}
       
  1597 	for( size_t i = 0; i < m_vStaticLibraries.size(); i++ )
       
  1598 	{
       
  1599 		if (! m_vStaticLibraries.at(i)->RestoreMmp() )
       
  1600 			bRet = false;
       
  1601 	}
       
  1602 	return bRet;
       
  1603 }
       
  1604 
       
  1605 bool CATProject::VerifyAndRecoverModules()
       
  1606 {
       
  1607 	LOG_FUNC_ENTRY("CATProject::VerifyAndRecoverModules");
       
  1608 	bool bRet = true;
       
  1609 	for( size_t i = 0; i < m_vModules.size(); i++ )
       
  1610 	{
       
  1611 		if (! m_vModules.at(i)->VerifyAndRecoverMmp() )
       
  1612 			bRet = false;
       
  1613 	}
       
  1614 	for( size_t i = 0; i < m_vStaticLibraries.size(); i++ )
       
  1615 	{
       
  1616 		if (! m_vStaticLibraries.at(i)->VerifyAndRecoverMmp() )
       
  1617 			bRet = false;
       
  1618 	}
       
  1619 	return bRet;
       
  1620 }
       
  1621 bool CATProject::Compile()
       
  1622 {
       
  1623 	switch ( m_eBuildSystem )
       
  1624 	{
       
  1625 	case SBS_V1:
       
  1626 		return CompileSbs1();
       
  1627 	case SBS_V2:
       
  1628 		return CompileSbs2();
       
  1629 	default:
       
  1630 		return false;
       
  1631 	}
       
  1632 }
       
  1633 
       
  1634 bool CATProject::CompileSbs1()
       
  1635 {
       
  1636 	LOG_FUNC_ENTRY("CATProject::CompileSbs1");
       
  1637 	string sCommand("");
       
  1638 	if ( m_sBuildCommand.empty() )
       
  1639 	{
       
  1640 		sCommand = "abld build";
       
  1641 		// -debug if urel
       
  1642 		if ( m_eBuildType == UREL )
       
  1643 			sCommand.append( " -debug" );
       
  1644 
       
  1645 		// No variant
       
  1646 		if ( m_sVariant.empty() )
       
  1647 		{
       
  1648 			sCommand.append( " " );
       
  1649 			sCommand.append( m_sPlatform );
       
  1650 		}
       
  1651 		else
       
  1652 		{
       
  1653 			// Add variant
       
  1654 			sCommand.append( " " );
       
  1655 			sCommand.append( m_sPlatform );
       
  1656 			sCommand.append( "." );
       
  1657 			sCommand.append( m_sVariant );
       
  1658 		}
       
  1659 
       
  1660 		// urel vs udeb
       
  1661 		sCommand.append( " " );
       
  1662 		sCommand.append( GetBuildTypeString() );
       
  1663 
       
  1664 		// Possible target module
       
  1665 		AddTargetModuleIfDefined( sCommand );
       
  1666 	}
       
  1667 	// Check that build command contains -debug switch if sbs v.1 used
       
  1668 	else if ( ! m_sBuildCommand.empty() 
       
  1669 		&& m_eBuildType == UREL 
       
  1670 		&& m_eBuildSystem == SBS_V1 
       
  1671 		&& m_sBuildCommand.find( "-debug" ) == string::npos )
       
  1672 	{
       
  1673 		// Find correct index to insert -debug switch
       
  1674 		size_t iPos = m_sBuildCommand.find( "build" );
       
  1675 		if ( iPos != string::npos )
       
  1676 		{
       
  1677 			sCommand = m_sBuildCommand;
       
  1678 			sCommand.insert( iPos+5, " -debug" );
       
  1679 		}
       
  1680 		else
       
  1681 		{
       
  1682 			LOG_STRING("Overwriting given build command to add -debug switch. Original command is: " << m_sBuildCommand );
       
  1683 			sCommand = "abld build -debug ";
       
  1684 			// No variant
       
  1685 			if ( m_sVariant.empty() )
       
  1686 			{
       
  1687 				sCommand.append( m_sPlatform );
       
  1688 			}
       
  1689 			else
       
  1690 			{
       
  1691 				// Add variant
       
  1692 				sCommand.append( m_sPlatform );
       
  1693 				sCommand.append( "." );
       
  1694 				sCommand.append( m_sVariant );
       
  1695 			}
       
  1696 
       
  1697 			// urel vs udeb
       
  1698 			sCommand.append( " " );
       
  1699 			sCommand.append( GetBuildTypeString() );
       
  1700 			// Possible target module
       
  1701 			AddTargetModuleIfDefined( sCommand );
       
  1702 		}
       
  1703 	}
       
  1704 	else
       
  1705 		sCommand = m_sBuildCommand;
       
  1706 	// Run command
       
  1707 	cout << AT_MSG_SYSTEM_CALL << sCommand << endl;
       
  1708 	(void)system( sCommand.c_str() );
       
  1709 	return true;
       
  1710 }
       
  1711 
       
  1712 bool CATProject::CompileSbs2()
       
  1713 {
       
  1714 	LOG_FUNC_ENTRY("CATProject::CompileSbs2");
       
  1715 	// Create command to compile with raptor
       
  1716 	string sCmd( m_sBuildCommand );
       
  1717 	sCmd.append( RAPTOR_BUILD_LOG );
       
  1718 	cout << AT_MSG_SYSTEM_CALL << sCmd << endl;
       
  1719 	int iRet = (int)system( sCmd.c_str() );
       
  1720 	if ( iRet == 0 )
       
  1721 		return true;
       
  1722 	return false;
       
  1723 }
       
  1724 
       
  1725 bool CATProject::CreateListings()
       
  1726 {
       
  1727 	// Create listings if no addr2line defined
       
  1728 	#ifndef ADDR2LINE
       
  1729 	if ( _stricmp( m_sPlatform.c_str(), "armv5" ) == 0 )
       
  1730 	{
       
  1731 		switch ( m_eBuildSystem )
       
  1732 		{
       
  1733 		case SBS_V1:
       
  1734 			return CreateListingsSbs1();
       
  1735 		case SBS_V2:
       
  1736 			return CreateListingsSbs2();
       
  1737 		default:
       
  1738 			return false;
       
  1739 		}
       
  1740 	}
       
  1741 	#endif
       
  1742 	return true;
       
  1743 }
       
  1744 
       
  1745 bool CATProject::CreateListingsSbs1()
       
  1746 {
       
  1747 	LOG_FUNC_ENTRY("CATProject::CreateListingsSbs1");
       
  1748 	string sCommand( "abld listing " );
       
  1749 
       
  1750 	// Listing
       
  1751 	if ( m_sVariant.empty() )
       
  1752 	{
       
  1753 		// No variant
       
  1754 		sCommand.append( m_sPlatform );
       
  1755 	}
       
  1756 	else
       
  1757 	{
       
  1758 		// Use specified variant
       
  1759 		sCommand.append( m_sPlatform );
       
  1760 		sCommand.append( "." );
       
  1761 		sCommand.append( m_sVariant );
       
  1762 	}
       
  1763 	// udeb vs urel
       
  1764 	sCommand.append( " " );
       
  1765 	sCommand.append( GetBuildTypeString() );
       
  1766 
       
  1767 	if ( m_vTargetModules.size() > 1 )
       
  1768 	{
       
  1769 		RunAbldCommandToAllTargets( sCommand );
       
  1770 	}
       
  1771 	else
       
  1772 	{
       
  1773 		AddTargetModuleIfDefined( sCommand ); 
       
  1774 		cout << AT_MSG_SYSTEM_CALL << sCommand << endl;
       
  1775 		(void)system( sCommand.c_str() );
       
  1776 	}
       
  1777 	return true;
       
  1778 }
       
  1779 
       
  1780 bool CATProject::CreateListingsSbs2()
       
  1781 {
       
  1782 	LOG_FUNC_ENTRY("CATProject::CreateListingsSbs2");
       
  1783 	string sCmd( m_sBuildCommand );
       
  1784 	sCmd.append( RAPTOR_LISTING_LOG );
       
  1785 	sCmd.append( " LISTING");
       
  1786 	cout << AT_MSG_SYSTEM_CALL << sCmd << endl;
       
  1787 	int iRet = (int)system( sCmd.c_str() );
       
  1788 	if ( iRet == 0 )
       
  1789 		return true;
       
  1790 	return false;
       
  1791 }
       
  1792 
       
  1793 bool CATProject::CopyReleasables()
       
  1794 {
       
  1795 	bool bRet = true;
       
  1796 	LOG_FUNC_ENTRY("CATProject::CopyReleasables");
       
  1797 	// Only copy releasables on armv5 platform and no addr2line defined.
       
  1798 	#ifndef ADDR2LINE
       
  1799 	if ( _stricmp( m_sPlatform.c_str(), "armv5" ) == 0 ) 
       
  1800 	{
       
  1801 		for( size_t i = 0; i < m_vModules.size(); i++ )
       
  1802 		{
       
  1803 			if ( ! m_vModules.at(i)->CopyReleasables() )
       
  1804 				bRet = false;
       
  1805 		}
       
  1806 		// Static libraries lst files.
       
  1807 		// First create directory for them (delete old one if exists).
       
  1808 		if ( ! DirectoryExists( AT_TEMP_LST_DIR ) )
       
  1809 		{
       
  1810 			DirCreate( AT_TEMP_LST_DIR, true );
       
  1811 		}
       
  1812 		else
       
  1813 		{
       
  1814 			DirDelete( AT_TEMP_LST_DIR, true );
       
  1815 			DirCreate( AT_TEMP_LST_DIR, true );
       
  1816 		}
       
  1817 		for ( size_t i = 0 ; i < m_vStaticLibraries.size(); i ++ )
       
  1818 		{
       
  1819 			if( ! m_vStaticLibraries.at(i)->CopyLstFilesToDir( AT_TEMP_LST_DIR ) )
       
  1820 				bRet = false;
       
  1821 		}
       
  1822 
       
  1823 		// Delete lst files from all type of modules in project.
       
  1824 		// Ignoring errors because different modules might use same source/lst files.
       
  1825 		for( size_t i = 0; i < m_vModules.size(); i++ )
       
  1826 			m_vModules.at(i)->DeleteLstFilesFromSrc();
       
  1827 		for ( size_t i = 0 ; i < m_vUnsupportedModules.size(); i ++ )
       
  1828 			m_vUnsupportedModules.at(i)->DeleteLstFilesFromSrc();
       
  1829 		for ( size_t i = 0 ; i < m_vStaticLibraries.size(); i ++ )
       
  1830 			m_vStaticLibraries.at(i)->DeleteLstFilesFromSrc();
       
  1831 		
       
  1832 		return bRet;
       
  1833 	}
       
  1834 	#endif
       
  1835 	// When addr2line defined and used we use symbol and map file(s).
       
  1836 	#ifdef ADDR2LINE
       
  1837 	if ( _stricmp( m_sPlatform.c_str(), "armv5" ) == 0 )
       
  1838 	{
       
  1839 		// Verify that module(s) symbol file(s) exist
       
  1840 		for( size_t i = 0; i < m_vModules.size(); i++ )
       
  1841 		{
       
  1842 			// Check symbol file.
       
  1843 			if ( ! m_vModules.at(i)->SymbolFileExist() )
       
  1844 				bRet = false;
       
  1845 			// Check map  file.
       
  1846 			if ( ! m_vModules.at(i)->MapFileExist() )
       
  1847 				bRet = false;
       
  1848 		}
       
  1849 	}
       
  1850 	#endif
       
  1851 	// Platform winscw.
       
  1852 	else if ( _stricmp( m_sPlatform.c_str(), "winscw" ) == 0 )
       
  1853 	{
       
  1854 		// Verify that module(s) binaries exist
       
  1855 		for( size_t i = 0; i < m_vModules.size(); i++ )
       
  1856 		{
       
  1857 			if ( ! m_vModules.at(i)->BinaryFileExist() )
       
  1858 				bRet = false;
       
  1859 		}
       
  1860 		// For static libraries binary/target is same as their library.
       
  1861 		for ( size_t i = 0 ; i < m_vStaticLibraries.size(); i ++ )
       
  1862 			if ( ! m_vStaticLibraries.at(i)->BinaryFileExist() )
       
  1863 				bRet = false;
       
  1864 	}
       
  1865 	// Platform gcce.
       
  1866 	else if ( _stricmp( m_sPlatform.c_str(), "gcce" ) == 0 )
       
  1867 	{
       
  1868 		// Verify that module(s) symbol file(s) exist
       
  1869 		for( size_t i = 0; i < m_vModules.size(); i++ )
       
  1870 		{
       
  1871 			// Check symbol file.
       
  1872 			if ( ! m_vModules.at(i)->SymbolFileExist() )
       
  1873 				bRet = false;
       
  1874 		}
       
  1875 	}
       
  1876 	return bRet;
       
  1877 }
       
  1878 
       
  1879 // ----------------------------------------------------------------------------
       
  1880 // Write project's (user) attributes to a file under temp folder
       
  1881 // ----------------------------------------------------------------------------
       
  1882 bool CATProject::WriteAttributes() const
       
  1883 {
       
  1884 	LOG_FUNC_ENTRY("CATProject::WriteAttributes");
       
  1885 	// File to write to
       
  1886 	string sOutFile( AT_TEMP_DIR );
       
  1887 	sOutFile.append( "\\" );
       
  1888 	sOutFile.append( AT_PROJECT_ATTRIBUTES_FILE_NAME );
       
  1889 	// Open file truncate if exists
       
  1890 	ofstream out( sOutFile.c_str(), ios_base::trunc );
       
  1891 	// Check file opened successfully
       
  1892 	if ( ! out.good() )
       
  1893 		return false;
       
  1894 	// Write attributes line by line
       
  1895 	out << m_bUninstrumented << endl; // Is project instrumented
       
  1896 	// Sbs version
       
  1897 	if ( m_eBuildSystem == CATProject::SBS_V2 )
       
  1898 		out << "SBS_2" << endl; 
       
  1899 	else
       
  1900 		out << "SBS_1" << endl;
       
  1901 	out << endl; // Reserved for possible binary data
       
  1902 	out << m_sPlatform << endl;
       
  1903 	out << m_sVariant << endl;
       
  1904 	out << m_eLoggingMode << endl;
       
  1905 	out << m_eBuildType << endl;
       
  1906 	out << m_sS60FileName << endl;
       
  1907 	out << m_iAllocCallStackSize << endl;
       
  1908 	out << m_iFreeCallStackSize << endl;
       
  1909 	for ( size_t i = 0 ; i < m_vTargetModules.size() ; i++ )
       
  1910 		out << m_vTargetModules.at(i) << AT_PROJECT_ATTRIBUTES_SEPARATOR;
       
  1911 	out << endl;
       
  1912 	out << m_sBuildCommand << endl;
       
  1913 	out.close();
       
  1914 	return true;
       
  1915 }
       
  1916 // ----------------------------------------------------------------------------
       
  1917 // Reads project's (user) attributes to a file under temp folder
       
  1918 // ----------------------------------------------------------------------------
       
  1919 bool CATProject::ReadAttributes()
       
  1920 {
       
  1921 	LOG_FUNC_ENTRY("CATProject::ReadAttributes");
       
  1922 	// File to read on
       
  1923 	string sInFile( AT_TEMP_DIR );
       
  1924 	sInFile.append( "\\" );
       
  1925 	sInFile.append( AT_PROJECT_ATTRIBUTES_FILE_NAME );
       
  1926 	// Open file
       
  1927 	ifstream in( sInFile.c_str() );
       
  1928 	// Check file opened successfully
       
  1929 	if ( ! in.good() )
       
  1930 		return false;
       
  1931 	// Read attributes
       
  1932 	char cLine[ MAX_LINE_LENGTH ];
       
  1933 	string sLine;
       
  1934 	in.getline( cLine, MAX_LINE_LENGTH );
       
  1935 	int iValue = atoi( cLine );
       
  1936 	if ( iValue == 1 )
       
  1937 		m_bUninstrumented = true;
       
  1938 	else
       
  1939 		m_bUninstrumented = false;
       
  1940 	// Sbs version
       
  1941 	in.getline( cLine, MAX_LINE_LENGTH ); string sBuildSystem = string( cLine );
       
  1942 	if ( sBuildSystem.compare( "SBS_1" ) == 0 )
       
  1943 		m_eBuildSystem = CATProject::SBS_V1;
       
  1944 	else if ( sBuildSystem.compare( "SBS_2" ) == 0 )
       
  1945 		m_eBuildSystem = CATProject::SBS_V2;
       
  1946 	else {
       
  1947 		LOG_STRING("Error invalid build system defined in project.cfg");
       
  1948 		m_eBuildSystem = CATProject::SBS_V1;
       
  1949 	}
       
  1950 	in.getline( cLine, MAX_LINE_LENGTH ); // reserverd for possible binary timestamp or similar
       
  1951 	in.getline( cLine, MAX_LINE_LENGTH ); m_sPlatform = string( cLine );
       
  1952 	in.getline( cLine, MAX_LINE_LENGTH ); m_sVariant = string( cLine );
       
  1953 	in.getline( cLine, MAX_LINE_LENGTH ); m_eLoggingMode = atoi( cLine );
       
  1954 	in.getline( cLine, MAX_LINE_LENGTH ); m_eBuildType = atoi( cLine );
       
  1955 	in.getline( cLine, MAX_LINE_LENGTH ); m_sS60FileName = string( cLine );
       
  1956 	in.getline( cLine, MAX_LINE_LENGTH ); m_iAllocCallStackSize = atoi( cLine );
       
  1957 	in.getline( cLine, MAX_LINE_LENGTH ); m_iFreeCallStackSize = atoi( cLine );
       
  1958 	in.getline( cLine, MAX_LINE_LENGTH ); sLine = cLine;
       
  1959 	size_t iSpot = sLine.find( AT_PROJECT_ATTRIBUTES_SEPARATOR );
       
  1960 	while ( iSpot != string::npos )
       
  1961 	{
       
  1962 		string sTarget = sLine.substr(0, iSpot );
       
  1963 		m_vTargetModules.push_back( sTarget );
       
  1964 		sLine.erase(0, iSpot + AT_PROJECT_ATTRIBUTES_SEPARATOR.size() );
       
  1965 		iSpot = sLine.find( AT_PROJECT_ATTRIBUTES_SEPARATOR );
       
  1966 	}
       
  1967 	in.getline( cLine, MAX_LINE_LENGTH ); m_sBuildCommand = cLine;
       
  1968 	in.close();
       
  1969 	return true;
       
  1970 }
       
  1971 
       
  1972 // ----------------------------------------------------------------------------
       
  1973 // Creates atool_temp directory to current folder if does not exist
       
  1974 // ----------------------------------------------------------------------------
       
  1975 bool CATProject::MakeTempDirIfNotExist()
       
  1976 {
       
  1977 	LOG_FUNC_ENTRY("CATProject::MakeTempDirIfNotExist");
       
  1978 	if ( ! DirectoryExists( AT_TEMP_DIR ) )
       
  1979 	{
       
  1980 		if( !CreateDirectory( AT_TEMP_DIR , NULL ) )
       
  1981 		{
       
  1982 			return false;
       
  1983 		}
       
  1984 	}
       
  1985 	return true;
       
  1986 }
       
  1987 // ----------------------------------------------------------------------------
       
  1988 // Utilities
       
  1989 // ----------------------------------------------------------------------------
       
  1990 
       
  1991 bool CATProject::RunAbldCommandToAllTargets( const string& sCommand )
       
  1992 {
       
  1993 	LOG_FUNC_ENTRY("CATProject::RunAbldCommandToAllTargets");
       
  1994 
       
  1995 	// Check for space at the commands end.
       
  1996 	string sSystemCall( sCommand );
       
  1997 	if ( *(sSystemCall.rbegin()) != ' ' )
       
  1998 		sSystemCall.append( " " );
       
  1999 
       
  2000 	// Loop calls.
       
  2001 	bool bRet = true;
       
  2002 	for ( vector<string>::iterator it = m_vTargetModules.begin(); it < m_vTargetModules.end(); it++ )
       
  2003 	{
       
  2004 		string sCall( sSystemCall );
       
  2005 		sCall.append( RemovePathAndExt( *it, true ) );
       
  2006 		cout << AT_MSG_SYSTEM_CALL << sCall << endl;
       
  2007 		if ( (int) system( sCall.c_str() ) != 0 )
       
  2008 			bRet = false;
       
  2009 	}
       
  2010 	return bRet;
       
  2011 }
       
  2012 
       
  2013 void CATProject::AddTargetModuleIfDefined( string& sCmd )
       
  2014 {
       
  2015 	LOG_FUNC_ENTRY("CATProject::AddTargetModuleIfDefined");
       
  2016 	// Do we have target modules defined
       
  2017 	if ( m_vTargetModules.size() > 0 )
       
  2018 	{
       
  2019 		switch( m_eBuildSystem )
       
  2020 		{
       
  2021 		case SBS_V1:
       
  2022 			// Add first target modules name without extension to build cmd.
       
  2023 			sCmd.append( " " );
       
  2024 			sCmd.append( RemovePathAndExt( m_vTargetModules.at( 0 ), true ) );
       
  2025 			break;
       
  2026 		case SBS_V2:
       
  2027 			// Add all target modules to build command using raptor switch '-p'.
       
  2028 			for( size_t i = 0 ; i < m_vTargetModules.size() ; i++ )
       
  2029 			{
       
  2030 				LOG_STRING("Adding :" << m_vTargetModules.at( i ) );
       
  2031 				sCmd.append( " -p " );
       
  2032 				sCmd.append( m_vTargetModules.at( i ) );
       
  2033 			}
       
  2034 			break;
       
  2035 		}
       
  2036 	}
       
  2037 }
       
  2038 
       
  2039 bool CATProject::IsTargetModuleInProject() const
       
  2040 {
       
  2041 	LOG_FUNC_ENTRY("CATProject::IsTargetModuleInProject");
       
  2042 	vector<CATModule2*>::const_iterator modules;
       
  2043 	vector<CATModule2*>::const_iterator staticModules;
       
  2044 	vector<string>::const_iterator targets;
       
  2045 	bool bRet = true;
       
  2046 	// Do we have target modules defined
       
  2047 	if ( m_vTargetModules.size() > 0 )
       
  2048 	{
       
  2049 		// Sbs version 1 support only single target module.
       
  2050 		if ( m_eBuildSystem == SBS_V1 )
       
  2051 		{
       
  2052 			// Try to find module from project.
       
  2053 			bRet = false;
       
  2054 			string sTarget = m_vTargetModules.at(0);
       
  2055 			for( modules = m_vModules.begin() ; modules != m_vModules.end() ; modules++ )
       
  2056 			{
       
  2057 				if( (*modules)->GetMmpFile().find( sTarget ) != string::npos )
       
  2058 				{
       
  2059 					// Found it return true.
       
  2060 					bRet = true;
       
  2061 					break;
       
  2062 				}
       
  2063 			}
       
  2064 			for( staticModules = m_vStaticLibraries.begin(); staticModules != m_vStaticLibraries.end(); staticModules++ )
       
  2065 			{
       
  2066 				if( (*staticModules)->GetMmpFile().find( sTarget ) != string::npos )
       
  2067 				{
       
  2068 					bRet = true;
       
  2069 					break;
       
  2070 				}
       
  2071 			}
       
  2072 			if ( ! bRet )
       
  2073 			{
       
  2074 				// Not found display error message.
       
  2075 				cout << AT_MSG << "Error, " << sTarget << " not defined in project." << endl;
       
  2076 			}
       
  2077 		}
       
  2078 		// Sbs version 2 supports multiple target modules.
       
  2079 		else if ( m_eBuildSystem == SBS_V2 )
       
  2080 		{
       
  2081 			// Check that all targets are defined in project.
       
  2082 			for( targets = m_vTargetModules.begin(); targets != m_vTargetModules.end() ; targets++ )
       
  2083 			{
       
  2084 				// Found iterated target?
       
  2085 				bool bFound = false;
       
  2086 				for ( modules = m_vModules.begin() ; modules != m_vModules.end() ; modules++ )
       
  2087 				{
       
  2088 					if( (*modules)->GetMmpFile().find( *targets ) != string::npos )
       
  2089 					{
       
  2090 						// yes.
       
  2091 						bFound = true;
       
  2092 						break;
       
  2093 					}
       
  2094 				}
       
  2095 				for( staticModules = m_vStaticLibraries.begin(); staticModules != m_vStaticLibraries.end(); staticModules++ )
       
  2096 				{
       
  2097 					if( (*staticModules)->GetMmpFile().find( *targets ) != string::npos )
       
  2098 					{
       
  2099 						bFound = true;
       
  2100 						break;
       
  2101 					}
       
  2102 				}
       
  2103 				if ( ! bFound )
       
  2104 				{
       
  2105 					// Display error when not found and set return value false.
       
  2106 					bRet = false;
       
  2107 					cout << AT_MSG << "Error, " << targets->c_str() << " not defined in project." << endl;
       
  2108 				}
       
  2109 			}
       
  2110 		}
       
  2111 	}
       
  2112 	return bRet;
       
  2113 }
       
  2114 
       
  2115 string CATProject::GetBuildTypeString()
       
  2116 {
       
  2117 	LOG_LOW_FUNC_ENTRY("CATProject::GetBuildTypeString");
       
  2118 	// Return build type as lowercase string
       
  2119 	switch( m_eBuildType )
       
  2120 	{
       
  2121 	case BUILD_TYPE::UDEB:
       
  2122 		return string("udeb");
       
  2123 	case BUILD_TYPE::UREL:
       
  2124 		return string("urel");
       
  2125 	default:
       
  2126 		return "";
       
  2127 	}
       
  2128 }
       
  2129 
       
  2130 string CATProject::GetBuildTypeString( int eType )
       
  2131 {
       
  2132 	LOG_LOW_FUNC_ENTRY("CATProject::GetBuildTypeString( int eType )");
       
  2133 	// Return build type as lowercase string
       
  2134 	switch( eType )
       
  2135 	{
       
  2136 	case BUILD_TYPE::UDEB:
       
  2137 		return string("udeb");
       
  2138 	case BUILD_TYPE::UREL:
       
  2139 		return string("urel");
       
  2140 	default:
       
  2141 		return string("unknown");
       
  2142 	}
       
  2143 }
       
  2144 
       
  2145 bool CATProject::CleanTemporaryDirs()
       
  2146 {
       
  2147 	LOG_FUNC_ENTRY("CATProject::CleanTemporaryDirs");
       
  2148 	bool bRet = true;
       
  2149 	// Modules
       
  2150 	for( size_t i = 0; i < m_vModules.size(); i++ )
       
  2151 	{
       
  2152 		if ( ! m_vModules.at(i)->CleanTemporaryDir() )
       
  2153 			bRet = false;
       
  2154 	}
       
  2155 	for( size_t i = 0; i < m_vStaticLibraries.size(); i++ )
       
  2156 	{
       
  2157 		if ( ! m_vStaticLibraries.at(i)->CleanTemporaryDir() )
       
  2158 			bRet = false;
       
  2159 	}
       
  2160 	// Projects
       
  2161 	vector<string> vFileList = DirList( AT_TEMP_DIR, false , true );
       
  2162 	vector<string>::iterator it2 = vFileList.begin();
       
  2163 	// Size of constant table
       
  2164 	int iCount = sizeof( TEMP_EXTENSION_NO_DELETE ) / sizeof( string );
       
  2165 	while ( it2 != vFileList.end() )
       
  2166 	{
       
  2167 		// Get extension and compare it to list
       
  2168 		bool bDelete = true;
       
  2169 		string sExtension = GetExtension( *it2 );
       
  2170 		ChangeToLower( sExtension );
       
  2171 		for ( int i = 0 ; i < iCount ; i++ )
       
  2172 		{
       
  2173 			if( sExtension.compare( TEMP_EXTENSION_NO_DELETE[i] ) == 0 )
       
  2174 			{
       
  2175 				bDelete = false;
       
  2176 				break;
       
  2177 			}
       
  2178 		}
       
  2179 		if ( bDelete )
       
  2180 		{
       
  2181 			// Delete file
       
  2182 			if ( ! FileDelete( *it2, true ) )
       
  2183 				bRet = false;
       
  2184 		}
       
  2185 		// Increment
       
  2186 		it2++;
       
  2187 	}
       
  2188 	return bRet;
       
  2189 }
       
  2190 
       
  2191 bool CATProject::DeleteTemporaryDirs()
       
  2192 {
       
  2193 	LOG_FUNC_ENTRY("CATProject::DeleteTemporaryDirs");
       
  2194 	bool bRet = true;
       
  2195 	// Modules
       
  2196 	for( size_t i = 0; i < m_vModules.size(); i++ )
       
  2197 	{
       
  2198 		if (! m_vModules.at(i)->DeleteTemporaryDir() )
       
  2199 			bRet = false;
       
  2200 	}
       
  2201 	for( size_t i = 0; i < m_vStaticLibraries.size(); i++ )
       
  2202 	{
       
  2203 		if (! m_vStaticLibraries.at(i)->DeleteTemporaryDir() )
       
  2204 			bRet = false;
       
  2205 	}
       
  2206 	return bRet;
       
  2207 }
       
  2208 
       
  2209 bool CATProject::InitSbs1MakeFileWithPathToTemp()
       
  2210 {
       
  2211 	LOG_FUNC_ENTRY("CATProject::InitSbs1MakeFileWithPathToTemp");
       
  2212 	// Use temporary folder
       
  2213 	m_sMakeFile.clear();
       
  2214 	m_sMakeFile.append( AT_TEMP_DIR );
       
  2215 	m_sMakeFile.append( "\\" );
       
  2216 	m_sMakeFile.append( AT_LEVEL_1_MAKEFILE_NAME );
       
  2217 	// At end check does it exist, return the result.
       
  2218 	return FileExists( m_sMakeFile.c_str() );
       
  2219 }
       
  2220 
       
  2221 bool CATProject::InitSbs1MakeFileWithPath()
       
  2222 {
       
  2223 	LOG_FUNC_ENTRY("CATProject::InitMakeFileWithPath");
       
  2224 	if ( m_sEpocRoot.empty() )
       
  2225 	{
       
  2226 		LOG_STRING("Error, epocroot is not set.");
       
  2227 		return false;
       
  2228 	}
       
  2229 	m_sMakeFile.clear();
       
  2230 	m_sMakeFile.append( m_sEpocRoot );
       
  2231 	if( *m_sMakeFile.rbegin() != '\\' )
       
  2232 		m_sMakeFile.append( "\\" );
       
  2233 	m_sMakeFile.append( "epoc32\\build\\" );
       
  2234 	// Add current directory to path (first remove driveletter).
       
  2235 	string sCurrentDir( m_cCurrentDir );
       
  2236 	if ( sCurrentDir.length() < 3 )
       
  2237 	{
       
  2238 		LOG_STRING("Error, current dir invalid.");
       
  2239 		return false;
       
  2240 	}
       
  2241 	sCurrentDir.erase(0,3);
       
  2242 	m_sMakeFile.append( sCurrentDir );
       
  2243 	m_sMakeFile.append( "\\" );
       
  2244 	// Platform
       
  2245 	string sPlatInUpper( m_sPlatform);
       
  2246 	ChangeToUpper( sPlatInUpper );
       
  2247 	m_sMakeFile.append( sPlatInUpper );
       
  2248 	// Possible variant
       
  2249 	m_sMakeFile.append( "." );
       
  2250 	if ( m_sVariant.empty() )
       
  2251 	{
       
  2252 		m_sMakeFile.append( "MAKE" );
       
  2253 	}
       
  2254 	else
       
  2255 	{
       
  2256 		m_sMakeFile.append( m_sVariant );
       
  2257 		m_sMakeFile.append( ".MAKE" );
       
  2258 	}
       
  2259 	// At end check does it exist, return the result.
       
  2260 	return FileExists( m_sMakeFile.c_str() );
       
  2261 }
       
  2262 
       
  2263 // ----------------------------------------------------------------------------
       
  2264 // Get & Sets
       
  2265 // ----------------------------------------------------------------------------
       
  2266 void CATProject::SetBuildSystem( BUILD_SYSTEM eSystem )
       
  2267 {
       
  2268 	LOG_FUNC_ENTRY("CATProject::SetBuildSystem");
       
  2269 	m_eBuildSystem = eSystem;
       
  2270 }
       
  2271 void CATProject::SetMode( PROJECT_MODE eMode )
       
  2272 {
       
  2273 	LOG_FUNC_ENTRY("CATProject::SetMode");
       
  2274 	m_eMode = eMode;
       
  2275 }
       
  2276 int CATProject::GetMode() const
       
  2277 {
       
  2278 	LOG_LOW_FUNC_ENTRY("CATProject::GetMode");
       
  2279 	return m_eMode;
       
  2280 }
       
  2281 void CATProject::SetEpocRoot( const string& sEpocRoot )
       
  2282 {
       
  2283 	LOG_FUNC_ENTRY("CATProject::SetEpocRoot");
       
  2284 	m_sEpocRoot = sEpocRoot;
       
  2285 }
       
  2286 void CATProject::SetPlatform( const string& sPlatform )
       
  2287 {
       
  2288 	LOG_FUNC_ENTRY("CATProject::SetPlatform");
       
  2289 	m_sPlatform = sPlatform;
       
  2290 }
       
  2291 void CATProject::SetVariant( const string& sVariant )
       
  2292 {
       
  2293 	LOG_FUNC_ENTRY("CATProject::SetVariant");
       
  2294 	m_sVariant = sVariant;
       
  2295 }
       
  2296 void CATProject::SetLoggingMode( LOGGING_MODE eLoggingMode)
       
  2297 {
       
  2298 	LOG_FUNC_ENTRY("CATProject::SetLoggingMode");
       
  2299 	m_eLoggingMode = eLoggingMode;
       
  2300 }
       
  2301 void CATProject::SetAllocCallStackSize( int iAllocCallStackSize )
       
  2302 {
       
  2303 	m_iAllocCallStackSize = iAllocCallStackSize;
       
  2304 }
       
  2305 void CATProject::SetFreeCallStackSize( int iFreeCallStackSize )
       
  2306 {
       
  2307 	m_iFreeCallStackSize = iFreeCallStackSize;
       
  2308 }
       
  2309 void CATProject::SetBuildType( BUILD_TYPE eType )
       
  2310 {
       
  2311 	LOG_FUNC_ENTRY("CATProject::SetBuildType");
       
  2312 	m_eBuildType = eType;
       
  2313 }
       
  2314 void CATProject::SetS60FileName( const string& sFileName)
       
  2315 {
       
  2316 	LOG_FUNC_ENTRY("CATProject::SetS60FileName");
       
  2317 	m_sS60FileName = sFileName;
       
  2318 }
       
  2319 void CATProject::SetRomSymbolFiles(const vector<string>& vRomSymbolFiles)
       
  2320 {
       
  2321 	LOG_FUNC_ENTRY("CATProject::SetRomSymbolFiles");
       
  2322 	m_vRomSymbolFiles = vRomSymbolFiles;
       
  2323 }
       
  2324 void CATProject::SetTargetModule(const string& sTargetModule)
       
  2325 {
       
  2326 	LOG_FUNC_ENTRY("CATProject::SetTargetModule");
       
  2327 	m_sTargetModule = sTargetModule;
       
  2328 	ChangeToLower( m_sTargetModule);
       
  2329 }
       
  2330 void CATProject::SetBinaryTarget(const string& sBinaryTarget)
       
  2331 {
       
  2332 	LOG_FUNC_ENTRY("CATProject::SetBinaryTarget");
       
  2333 	m_sBinaryTarget = sBinaryTarget;
       
  2334 	ChangeToLower( m_sBinaryTarget );
       
  2335 }
       
  2336 void CATProject::SetDataFile( const string& sDataFile )
       
  2337 {
       
  2338 	LOG_FUNC_ENTRY("CATProject::SetDataFile");
       
  2339 	m_sDataFile = sDataFile;
       
  2340 }
       
  2341 void CATProject::SetLogLevel( int iLogLevel )
       
  2342 {
       
  2343 	LOG_FUNC_ENTRY("CATProject::SetLogLevel");
       
  2344 	m_iLoggingLevel = iLogLevel;
       
  2345 }
       
  2346 void CATProject::SetDataFileOutput( const string& sDataFileOutput )
       
  2347 {
       
  2348 	LOG_FUNC_ENTRY("CATProject::SetDataFileOutput");
       
  2349 	m_sDataFileOutput = sDataFileOutput;
       
  2350 }
       
  2351 void CATProject::SetTargetModules( const vector<string>& vTargetModules )
       
  2352 {
       
  2353 	LOG_FUNC_ENTRY("CATProject::SetTargetModules");
       
  2354 	m_vTargetModules = vTargetModules;
       
  2355 }
       
  2356 void CATProject::SetBuildCommand( const string& sBuildCommand )
       
  2357 {
       
  2358 	LOG_FUNC_ENTRY("CATProject::SetBuildCommand");
       
  2359 	m_sBuildCommand = sBuildCommand;
       
  2360 }
       
  2361 // End of file