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