srcanamdw/appdep/src/appdep_otherfunc.cpp
changeset 0 509e4801c378
equal deleted inserted replaced
-1:000000000000 0:509e4801c378
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Other non-categorized AppDep functionality 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "appdep.hpp"
       
    20 
       
    21 // ----------------------------------------------------------------------------------------------------------
       
    22 
       
    23 void ParseCommandLineParameters(int argc, char* argv[])
       
    24 {   
       
    25 	// loop through the command line parameters and check their usage
       
    26 	int i=1;
       
    27 	while (i<argc)
       
    28 	{
       
    29 		if (StringICmp("-?", argv[i])==0 ||
       
    30 		    StringICmp("-h", argv[i])==0 ||
       
    31 		    StringICmp("--help", argv[i])==0)
       
    32 		{
       
    33 			ShowCommandLineOptionsAndExit();
       
    34 		}
       
    35 		
       
    36 		else if (StringICmp("GCC", argv[i])==0)
       
    37 		{
       
    38 			_cl_use_gcc = true;
       
    39 		}
       
    40 		
       
    41 		else if (StringICmp("GCCE", argv[i])==0)
       
    42 		{
       
    43 			_cl_use_gcce = true;
       
    44 		}
       
    45 		
       
    46 		else if (StringICmp("RVCT", argv[i])==0)
       
    47 		{
       
    48 			_cl_use_rvct = true;
       
    49 		}
       
    50 	
       
    51 		else if (StringICmp("--refresh", argv[i])==0)
       
    52 		{
       
    53 			_cl_update_cache = true;
       
    54 		}
       
    55 
       
    56 		else if (StringICmp("--clean", argv[i])==0)
       
    57 		{
       
    58 			_cl_generate_clean_cache = true;
       
    59 		}
       
    60         		
       
    61 		else if (StringICmp("--uselibs", argv[i])==0)
       
    62 		{
       
    63 			_cl_use_libs = true;
       
    64 		}
       
    65 
       
    66 		else if (StringICmp("--showordinals", argv[i])==0)
       
    67 		{
       
    68 			_cl_show_ordinals = true;
       
    69 		}
       
    70 
       
    71 		else if (StringICmp("--useudeb", argv[i])==0)
       
    72 		{
       
    73 			_cl_use_udeb = true;
       
    74 		}
       
    75 
       
    76 		else if (StringICmp("--debug", argv[i])==0)
       
    77 		{
       
    78 			_cl_print_debug = true;
       
    79 		}
       
    80         		
       
    81 		else if (StringICmp("-tools", argv[i])==0)
       
    82 		{
       
    83 			if (i+1<argc) { _cl_toolsdir = argv[i+1]; i++; }
       
    84 		}
       
    85 
       
    86 		else if (StringICmp("-cache", argv[i])==0)
       
    87 		{
       
    88 			if (i+1<argc) { _cl_cachedir = argv[i+1]; i++; }
       
    89 		}
       
    90 
       
    91 		else if (StringICmp("-release", argv[i])==0)
       
    92 		{
       
    93 			if (i+1<argc) { _cl_releasedir = argv[i+1]; i++; }
       
    94 		}
       
    95 
       
    96 		else if (StringICmp("-targets", argv[i])==0)
       
    97 		{
       
    98 			if (i+1<argc) { _cl_targets = argv[i+1]; i++; }
       
    99 		}
       
   100 		
       
   101 		else if (StringICmp("-cfilt", argv[i])==0)
       
   102 		{
       
   103 			if (i+1<argc) { _cl_cfiltloc = argv[i+1]; i++; }
       
   104 		}
       
   105 
       
   106 		else if (StringICmp("-out", argv[i])==0)
       
   107 		{
       
   108 			if (i+1<argc) { _cl_outputfile = argv[i+1]; i++; }
       
   109 		}		
       
   110 
       
   111 		else if (StringICmp("-config", argv[i])==0)
       
   112 		{
       
   113 			if (i+1<argc) { _cl_configfile = argv[i+1]; i++; }
       
   114 		}		
       
   115 
       
   116 		else if (StringICmp("-sisfiles", argv[i])==0)
       
   117 		{
       
   118 			if (i+1<argc) { _cl_sisfiles = argv[i+1]; i++; }
       
   119 		}
       
   120 		
       
   121 		else if (StringICmp("-usestaticdepstxt", argv[i])==0)
       
   122 		{
       
   123 			if (i+1<argc) { _cl_usestaticdepstxt = argv[i+1]; i++; }
       
   124 		}
       
   125 		
       
   126 		else if (StringICmp("-properties", argv[i])==0)
       
   127 		{
       
   128 			if (i+1<argc) { _cl_properties = argv[i+1]; i++; }
       
   129 		}
       
   130 		
       
   131 		else if (StringICmp("-staticdeps", argv[i])==0)
       
   132 		{
       
   133 			if (i+1<argc) { _cl_staticdeps = argv[i+1]; i++; }
       
   134 		}
       
   135 
       
   136 		else if (StringICmp("-dependson", argv[i])==0)
       
   137 		{
       
   138 			if (i+1<argc) { _cl_dependson = argv[i+1]; i++; }
       
   139 		}        		
       
   140 
       
   141 		else if (StringICmp("-showfunctions", argv[i])==0)
       
   142 		{
       
   143 			if (i+1<argc) { _cl_showfunctions = argv[i+1]; i++; }
       
   144 		} 		
       
   145 
       
   146 		else if (StringICmp("-usesfunction", argv[i])==0)
       
   147 		{
       
   148 			if (i+1<argc) { _cl_usesfunction = argv[i+1]; i++; }
       
   149 		} 
       
   150 		
       
   151 		// check if the parameter is illegal
       
   152         else
       
   153         {
       
   154             string param = argv[i];
       
   155             
       
   156             if (!param.empty() && param.at(0) == '-')
       
   157             {
       
   158         		cerr << "ERROR: Illegal argument: " << param << endl;
       
   159         		cerr << "Type appdep -? for help" << endl;
       
   160                 exit(EXIT_INVALID_ARGUMENT);            
       
   161             }   
       
   162         }
       
   163 
       
   164 		i++;
       
   165 	}    
       
   166 }
       
   167 
       
   168 // ----------------------------------------------------------------------------------------------------------
       
   169 
       
   170 void ShowCommandLineOptionsAndExit()
       
   171 {
       
   172     cout << "AppDep v" << APPDEP_VERSION << " - " << APPDEP_DATE << "\n"
       
   173             "Copyright (c) " << APPDEP_COPYRIGHT_YEARS << " Nokia Corporation and/or its subsidiary(-ies). All rights reserved.\n"            
       
   174             "\n"
       
   175             "Usage: appdep GCC|GCCE|RVCT [parameters] [options] [commands]\n"
       
   176             "\n"
       
   177             "Where:\n"
       
   178             "  GCC                      Use Symbian GCC tool chain\n"
       
   179             "  GCCE                     Use CSL ARM tool chain\n"
       
   180             "  RVCT                     Use RVCT tool chain\n"
       
   181             "\n"
       
   182             "Parameters:\n"
       
   183             "  -targets A+B+C+...       Target types from release, one or more separated with + without spaces\n"
       
   184             "\n"
       
   185             "Required parameters when RVCT tool chain is used:\n"
       
   186             "  -cfilt FILE              Location FILE of cfilt/c++filt\n"
       
   187             "\n"
       
   188             "Options:\n"
       
   189             "  -tools DIRECTORY         DIRECTORY where the used compiler tool chain is installed\n"
       
   190             "  -release DIRECTORY       DIRECTORY where release has been installed\n"
       
   191             "  -cache DIRECTORY         DIRECTORY to store cache files\n"
       
   192             "  -out FILE                Prints results to FILE\n"
       
   193             "  --refresh                Updates the cache, use always after making changes to the release\n"
       
   194             "  --clean                  Always creates a clean cache\n"
       
   195             "  --uselibs                Always use LIBs instead of DSOs (not valid with GCC)\n"
       
   196             "  --showordinals           Show ordinals numbers in output when appropriate\n"
       
   197             "  --useudeb                Scan udeb folder for binaries instead of urel\n"
       
   198             "  -sisfiles FILE;FILE;...  Includes binaries from sis FILE under analysis\n"
       
   199             //"  -usestaticdepstxt FILE   Use platform generated StaticDependencies.txt instead of cache\n"
       
   200             //"  --debug                  Print debug messages where available\n"
       
   201             "\n"
       
   202             "Commands:\n"
       
   203             "  -properties FILE         Show properties of binary FILE\n"
       
   204             "  -staticdeps FILE         Print all static dependencies of component FILE\n"
       
   205             "  -dependson FILE          Print all components that depends on component FILE\n"
       
   206             "  -showfunctions FILE      Print all functions used by compoment FILE\n"
       
   207             "  -usesfunction NAME       Print all components that are using function NAME (NAME can be full\n"
       
   208             "                             function name or in format DLLNAME@ORDINALNUMBER)\n"
       
   209             "\n";
       
   210 
       
   211 	exit(EXIT_NORMAL);
       
   212 }
       
   213 
       
   214 // ----------------------------------------------------------------------------------------------------------
       
   215 
       
   216 void DoInitialChecksAndPreparations()
       
   217 {
       
   218     // make sure the directory names have trailing directory markers
       
   219     MakeSureTrailingDirectoryMarkerExists(_cl_toolsdir);
       
   220     MakeSureTrailingDirectoryMarkerExists(_cl_cachedir);
       
   221     MakeSureTrailingDirectoryMarkerExists(_cl_releasedir);    
       
   222 
       
   223     // check that both --refresh and --clean are not defined
       
   224     if (_cl_update_cache && _cl_generate_clean_cache)
       
   225         {
       
   226     	cerr << "Do not specify both --refresh and --clean at the same time!" << endl;
       
   227     	cerr << "Type appdep -? for help" << endl;
       
   228     	exit(EXIT_WRONG_USAGE);
       
   229         }            
       
   230 
       
   231     // check if targets parameter has been given
       
   232     if (_cl_targets.empty())
       
   233     {
       
   234     	cerr << "-targets parameter not specified!" << endl;
       
   235     	cerr << "Type appdep -? for help" << endl;
       
   236     	exit(EXIT_NO_TARGETS);
       
   237     }
       
   238         
       
   239     // if releasedir param is not specified, assign it be the root of current drive
       
   240     if (_cl_releasedir.empty())
       
   241     {
       
   242         _cl_releasedir = DIR_SEPARATOR;
       
   243     }
       
   244    
       
   245     // append default cache location if otherwise the cache parameter is empty
       
   246     if (_cl_cachedir.empty())
       
   247     {
       
   248         _cl_cachedir = _cl_releasedir + DEFAULT_CACHE_DIR;
       
   249     }
       
   250 
       
   251 	// check output file can be created
       
   252     if (!_cl_outputfile.empty())
       
   253     {
       
   254         _outputf.open(_cl_outputfile.c_str(), ios::trunc);
       
   255         if (!_outputf.is_open())
       
   256         {
       
   257             _outputf.close();
       
   258     		cerr << "ERROR: Cannot open " << _cl_outputfile << " for writing!" << endl;
       
   259     		cerr << "Please check that the directory exists and there are no write permission problems" << endl;
       
   260     		exit(EXIT_CANNOT_CREATE_OUTPUT_FILE);
       
   261         }            
       
   262     }    
       
   263 
       
   264     // set target mode
       
   265     if (_cl_use_udeb)
       
   266         _target_mode = "udeb";
       
   267     else
       
   268         _target_mode = "urel";
       
   269 
       
   270 }
       
   271 
       
   272 // ----------------------------------------------------------------------------------------------------------
       
   273 
       
   274 void ParseTargets()
       
   275 {
       
   276     // parse A+B+C+... to a vector
       
   277     int last_found_plus_pos = -1;
       
   278     for (unsigned int i=0; i<_cl_targets.length(); i++)
       
   279     {   
       
   280         // try to find '+' characters 
       
   281         string::size_type plus_pos = _cl_targets.find("+", i);
       
   282         
       
   283         target new_target;
       
   284         
       
   285         if (plus_pos == string::npos)
       
   286         {
       
   287             // could not find the plus character, append last part of the list
       
   288             string tmp = _cl_targets.substr(last_found_plus_pos+1, _cl_targets.length()-last_found_plus_pos-1);
       
   289             new_target.name = LowerCase(tmp);   
       
   290             _targets.push_back(new_target);
       
   291             break;
       
   292         }
       
   293         else
       
   294         {
       
   295             // found a plus character, append to the list, but needs to check if there are more
       
   296             string tmp = _cl_targets.substr(last_found_plus_pos+1, plus_pos-last_found_plus_pos-1);
       
   297             new_target.name = LowerCase(tmp);
       
   298             
       
   299             if (new_target.name.length() > 0)
       
   300                 _targets.push_back(new_target);
       
   301             
       
   302             last_found_plus_pos = plus_pos;
       
   303             i = last_found_plus_pos;
       
   304         }    
       
   305     }        
       
   306     
       
   307     // set more values of targets vector
       
   308     for (unsigned int i=0; i<_targets.size(); i++)
       
   309     {  
       
   310         // set path where release the release can be found, eg z:\epoc32\release\armv5\ .
       
   311         _targets.at(i).release_dir = _cl_releasedir + EPOC32_RELEASE + _targets.at(i).name + DIR_SEPARATOR;
       
   312 
       
   313         // set path where the import libraries of the release can be found, eg z:\epoc32\release\armv5\lib\ .
       
   314         string lib_dir;
       
   315         if (_cl_use_gcce || _cl_use_rvct)
       
   316             lib_dir = "lib"; // lib dir used in Symbian OS 9.x    
       
   317         else
       
   318             lib_dir = _target_mode;
       
   319         
       
   320         _targets.at(i).release_lib_dir = _targets.at(i).release_dir + lib_dir + DIR_SEPARATOR;
       
   321 
       
   322         // set path where the binaries of the release can be found, eg z:\epoc32\release\armv5\urel\ .
       
   323         _targets.at(i).release_bin_dir = _targets.at(i).release_dir + _target_mode + DIR_SEPARATOR;
       
   324         
       
   325         // set location of the cache files of this target, eg z:\caches\armv5\urel\xxx.txt 
       
   326         _targets.at(i).cache_dir =  _cl_cachedir + _targets.at(i).name + DIR_SEPARATOR + _target_mode + DIR_SEPARATOR;      
       
   327         _targets.at(i).st_cache_path = _targets.at(i).cache_dir + CACHE_ST_FILENAME;
       
   328         _targets.at(i).dep_cache_path = _targets.at(i).cache_dir + CACHE_DEP_FILENAME;
       
   329      
       
   330         // check if those cache files exists
       
   331         _targets.at(i).cache_files_valid = FileExists(_targets.at(i).st_cache_path) && FileExists(_targets.at(i).dep_cache_path);
       
   332     }            
       
   333 }
       
   334 
       
   335 // ----------------------------------------------------------------------------------------------------------
       
   336 
       
   337 void DoCacheGenerationChecksAndPreparations()
       
   338 {
       
   339 	if (!_cl_use_gcc && !_cl_use_gcce && !_cl_use_rvct)     
       
   340 	{	
       
   341 		cerr << "ERROR: No tool chain defined!" << endl;
       
   342 		cerr << "Type appdep -? for help" << endl;
       
   343         exit(EXIT_WRONG_USAGE);
       
   344 	}        
       
   345 
       
   346 	if (_cl_use_rvct && _cl_cfiltloc.empty())     
       
   347 	{	
       
   348 		cerr << "ERROR: Specify -cfilt when RVCT is defined!" << endl;
       
   349 		cerr << "Type appdep -? for help" << endl;
       
   350         exit(EXIT_WRONG_USAGE);
       
   351 	}  
       
   352 
       
   353 	if ( (_cl_use_gcc && (_cl_use_gcce || _cl_use_rvct)) || (_cl_use_gcce && (_cl_use_gcc || _cl_use_rvct)) ||
       
   354          (_cl_use_rvct && (_cl_use_gcc || _cl_use_gcce)) )   
       
   355 	{	
       
   356 		cerr << "ERROR: Specify only one tool chain!" << endl;
       
   357 		cerr << "Type appdep -? for help" << endl;
       
   358         exit(EXIT_WRONG_USAGE);
       
   359 	}     	    
       
   360 
       
   361 	// make sure the vectors are empty when generating clean cache
       
   362 	if (_cl_generate_clean_cache)
       
   363     {
       
   364         for (unsigned int i=0; i<_targets.size(); i++) // loop each target
       
   365         {
       
   366             _targets.at(i).import_libraries.clear();
       
   367             _targets.at(i).binaries.clear();    
       
   368         }
       
   369     }
       
   370 
       
   371     // if tools parameter is empty, try get it from path, otherwise check given parameter
       
   372     if (_cl_toolsdir.empty())
       
   373     {
       
   374         GetToolsPathFromEnvironmentVariable();
       
   375     }
       
   376     else
       
   377     {
       
   378         // check the given tools directory parameter is valid
       
   379         if (_cl_use_gcc)
       
   380         {
       
   381             _gcc_nm_location = _cl_toolsdir + GCC_NM_EXE;
       
   382     
       
   383         	if (!FileExists(_gcc_nm_location))
       
   384         	{
       
   385         		cerr << "ERROR: Unable to find " + _gcc_nm_location << ", check -tools parameter" << endl;
       
   386         		cerr << "Tip: GCC is typically installed to \\epoc32\\gcc\\bin directory" << endl;
       
   387         		exit(EXIT_TOOLCHAIN_NOT_FOUND);
       
   388         	}        
       
   389     
       
   390             // extra quotes needed to prevent white space problems while executing the tool
       
   391             InsertQuotesToFilePath(_gcc_nm_location);
       
   392         }
       
   393     
       
   394         else if (_cl_use_gcce)
       
   395         {
       
   396             _gcce_nm_location = _cl_toolsdir + GCCE_NM_EXE;
       
   397             _gcce_readelf_location = _cl_toolsdir + GCCE_READELF_EXE;
       
   398             _gcce_cfilt_location = _cl_toolsdir + GCCE_CFILT_EXE;
       
   399     
       
   400         	if (!FileExists(_gcce_nm_location))
       
   401         	{
       
   402         		cerr << "ERROR: Unable to find " + _gcce_nm_location << ", check -tools param" << endl;
       
   403         		cerr << "Tip: GCCE is typically installed to C:\\Program Files\\CSL Arm Toolchain\\bin" << endl;
       
   404         		exit(EXIT_TOOLCHAIN_NOT_FOUND);
       
   405         	} 
       
   406     
       
   407         	if (!FileExists(_gcce_readelf_location))
       
   408         	{
       
   409         		cerr << "ERROR: Unable to find " + _gcce_readelf_location << ", check -tools param" << endl;
       
   410         		cerr << "Tip: GCCE is typically installed to C:\\Program Files\\CSL Arm Toolchain\\bin" << endl;
       
   411         		exit(EXIT_TOOLCHAIN_NOT_FOUND);
       
   412         	} 
       
   413     
       
   414         	if (!FileExists(_gcce_cfilt_location))
       
   415         	{
       
   416         		cerr << "ERROR: Unable to find " + _gcce_cfilt_location << ", check -tools param" << endl;
       
   417         		cerr << "Tip: GCCE is typically installed to C:\\Program Files\\CSL Arm Toolchain\\bin" << endl;
       
   418         		exit(EXIT_TOOLCHAIN_NOT_FOUND);
       
   419         	} 
       
   420     
       
   421             // extra quotes needed to prevent white space problems while executing the tool
       
   422             InsertQuotesToFilePath(_gcce_nm_location);
       
   423             InsertQuotesToFilePath(_gcce_readelf_location);
       
   424             InsertQuotesToFilePath(_gcce_cfilt_location);
       
   425             
       
   426         }
       
   427     
       
   428         else if (_cl_use_rvct)
       
   429         {
       
   430             _rvct_armar_location = _cl_toolsdir + RVCT_ARMAR_EXE;
       
   431             _rvct_fromelf_location = _cl_toolsdir + RVCT_FROMELF_EXE;
       
   432     
       
   433         	if (!FileExists(_rvct_armar_location))
       
   434         	{
       
   435         		cerr << "ERROR: Unable to find " + _rvct_armar_location << ", check -tools param" << endl;
       
   436         		cerr << "Tip: Check your environment variables to see the directory where RVCT has been installed" << endl;
       
   437         		exit(EXIT_TOOLCHAIN_NOT_FOUND);
       
   438         	} 
       
   439     
       
   440         	if (!FileExists(_rvct_fromelf_location))
       
   441         	{
       
   442         		cerr << "ERROR: Unable to find " + _rvct_fromelf_location << ", check -tools param" << endl;
       
   443         		cerr << "Tip: Check your environment variables to see the directory where RVCT has been installed" << endl;
       
   444         		exit(EXIT_TOOLCHAIN_NOT_FOUND);
       
   445         	} 
       
   446                     
       
   447             // extra quotes needed to prevent white space problems while executing the tool
       
   448             InsertQuotesToFilePath(_rvct_armar_location);
       
   449             InsertQuotesToFilePath(_rvct_fromelf_location);
       
   450         }            
       
   451     } // else of if (!cl_toolsdir)
       
   452 
       
   453         
       
   454     // check path of RVCT's cfilt is correct
       
   455     if (_cl_use_rvct)
       
   456     {
       
   457         _rvct_cfilt_location = _cl_cfiltloc;
       
   458         
       
   459     	if (!FileExists(_rvct_cfilt_location))
       
   460     	{
       
   461     		cerr << "ERROR: Unable to find " + _rvct_cfilt_location << ", check -cfilt param" << endl;
       
   462     		cerr << "Tip: Working cfilt.exe can be found from the same directory where appdep has been installed" << endl;
       
   463     		exit(EXIT_CFILT_NOT_FOUND);
       
   464     	}    
       
   465         
       
   466         // extra quotes needed to prevent white space problems while executing the tool
       
   467         InsertQuotesToFilePath(_rvct_cfilt_location);
       
   468     }
       
   469 
       
   470 
       
   471     // check Petran can be found
       
   472     SetAndCheckPetranPath();
       
   473 
       
   474     // loop all targets
       
   475     for (unsigned int i=0; i<_targets.size(); i++)
       
   476     {
       
   477         // check directories for given targets are valid
       
   478         if (!DirectoryExists(_targets.at(i).release_dir))
       
   479         {
       
   480     		cerr << "ERROR: Directory " << _targets.at(i).release_dir << " not found!" << endl;
       
   481     		cerr << "Please check that -targets parameter is valid and you have a full release environment" << endl;
       
   482     		exit(EXIT_TARGETDIR_NOT_FOUND);            
       
   483         }
       
   484         else
       
   485         {
       
   486             //cerr <<  "NOTE: " << targets.at(i) << " is a valid target in your release" << endl;  
       
   487         }
       
   488 
       
   489         // make sure that the cache directory exists
       
   490         MkDirAll(_targets.at(i).cache_dir);    
       
   491     }
       
   492 
       
   493 	// check that it is possible to create the temporary file under the cache directory
       
   494     _tempfile_location = _cl_cachedir + TEMP_FILENAME;
       
   495     ofstream tempf(_tempfile_location.c_str(), ios::trunc);
       
   496     if (!tempf.is_open())
       
   497     {
       
   498         tempf.close();
       
   499 		cerr << "ERROR: Cannot open " << _tempfile_location << " for writing!" << endl;
       
   500 		cerr << "Please check that the directory exists and there are no write permission problems" << endl;
       
   501 		exit(EXIT_CANNOT_WRITE_TO_TEMP_FILE);
       
   502     }
       
   503     else
       
   504         tempf.close(); 
       
   505         
       
   506 }
       
   507 
       
   508 // ----------------------------------------------------------------------------------------------------------
       
   509 
       
   510 void GetToolsPathFromEnvironmentVariable()
       
   511 {
       
   512    #ifdef WIN32
       
   513     // get path environment variable
       
   514     const char* env_path = getenv("PATH");
       
   515     
       
   516     if (env_path != NULL)
       
   517     {
       
   518         string env_path_str = env_path;
       
   519         
       
   520         string::size_type previous_delimpos = 0;
       
   521         bool match_found(false);
       
   522         string test_path;
       
   523 
       
   524         for (unsigned int i=0; i<env_path_str.length(); i++)
       
   525         {
       
   526             // directories in %PATH% are separated with ';'-char
       
   527             string::size_type delimpos = env_path_str.find(";", i);
       
   528             
       
   529             if (delimpos != string::npos)
       
   530             {
       
   531                 // get path
       
   532                 test_path = env_path_str.substr(previous_delimpos, delimpos-previous_delimpos);
       
   533                
       
   534                 MakeSureTrailingDirectoryMarkerExists(test_path);
       
   535                 
       
   536                 // remember found position
       
   537                 previous_delimpos = delimpos + 1;
       
   538                 i = delimpos;
       
   539 
       
   540                 // do check if path is correct
       
   541                 if (_cl_use_gcc)
       
   542                 {
       
   543                     _gcc_nm_location = test_path + GCC_NM_EXE;
       
   544            
       
   545                 	if (FileExists(_gcc_nm_location))
       
   546                 	{
       
   547                 		match_found = true;
       
   548 
       
   549                         // extra quotes needed to prevent white space problems while executing the tool
       
   550                         InsertQuotesToFilePath(_gcc_nm_location);
       
   551                 	}        
       
   552                 }
       
   553             
       
   554                 else if (_cl_use_gcce)
       
   555                 {
       
   556                     _gcce_nm_location = test_path + GCCE_NM_EXE;
       
   557                     _gcce_readelf_location = test_path + GCCE_READELF_EXE;
       
   558                     _gcce_cfilt_location = test_path + GCCE_CFILT_EXE;
       
   559             
       
   560                 	if (FileExists(_gcce_nm_location) && FileExists(_gcce_readelf_location) && FileExists(_gcce_cfilt_location))
       
   561                 	{
       
   562                 		match_found = true;
       
   563 
       
   564                         // extra quotes needed to prevent white space problems while executing the tool
       
   565                         InsertQuotesToFilePath(_gcce_nm_location);
       
   566                         InsertQuotesToFilePath(_gcce_readelf_location);
       
   567                         InsertQuotesToFilePath(_gcce_cfilt_location);
       
   568                 	} 
       
   569                 }
       
   570             
       
   571                 else if (_cl_use_rvct)
       
   572                 {
       
   573                     _rvct_armar_location = test_path + RVCT_ARMAR_EXE;
       
   574                     _rvct_fromelf_location = test_path + RVCT_FROMELF_EXE;
       
   575             
       
   576                 	if (FileExists(_rvct_armar_location) && FileExists(_rvct_fromelf_location))
       
   577                 	{
       
   578                 		match_found = true;
       
   579 
       
   580                         // extra quotes needed to prevent white space problems while executing the tool
       
   581                         InsertQuotesToFilePath(_rvct_armar_location);
       
   582                         InsertQuotesToFilePath(_rvct_fromelf_location);
       
   583                 	} 
       
   584                 }   
       
   585 
       
   586             }          
       
   587 
       
   588             // first matching directory found, no need to loop anymore
       
   589             if (match_found)
       
   590             {
       
   591                 _cl_toolsdir = test_path;
       
   592                 cerr << "Tool chain found from %PATH% at " << test_path << endl;
       
   593                 break;
       
   594             }                           
       
   595             
       
   596             if (i>5000)
       
   597                 break;  // something went wrong..
       
   598         }
       
   599 
       
   600         if (!match_found)
       
   601         {
       
   602             cerr << "ERROR: Cannot find specified compiler toolset from PATH environment" << endl;
       
   603             cerr << "Fix PATH environment variable or specify -tools parameter" << endl;
       
   604         	exit(EXIT_TOOLCHAIN_NOT_FOUND_FROM_PATH);                      
       
   605         }
       
   606 
       
   607     }
       
   608     else
       
   609     {
       
   610         cerr << "ERROR: PATH environment variable not available, please specify -tools parameter" << endl;
       
   611     	exit(EXIT_PATH_VARIABLE_NOT_FOUND);                
       
   612     }
       
   613   
       
   614    #else
       
   615 
       
   616     cerr << "ERROR: Optional -tools parameter is only supported in Windows environment " << endl;
       
   617 	exit(EXIT_ONLY_SUPPORTED_IN_WIN32);                
       
   618 
       
   619    #endif
       
   620 
       
   621 }
       
   622 
       
   623 // ----------------------------------------------------------------------------------------------------------
       
   624 
       
   625 void FindImportLibrariesAndBinariesFromReleases()
       
   626 {
       
   627     // check if analysing .dso or .lib files
       
   628     string lib_filter;
       
   629     if (_cl_use_gcc || _cl_use_libs)  // for GCC use always .lib files
       
   630         lib_filter = "*.lib";
       
   631     else
       
   632         lib_filter = "*.dso";
       
   633             
       
   634     for (unsigned int i=0; i<_targets.size(); i++) // loop each target
       
   635     {
       
   636         // get import libraries
       
   637         GetFileNamesFromDirectory(_targets.at(i).release_lib_dir, lib_filter, _targets.at(i).lib_files);
       
   638         _max_progress += _targets.at(i).lib_files.size();
       
   639 
       
   640         // get binaries
       
   641         GetFileNamesFromDirectory(_targets.at(i).release_bin_dir, "*.app", _targets.at(i).bin_files);
       
   642         GetFileNamesFromDirectory(_targets.at(i).release_bin_dir, "*.exe", _targets.at(i).bin_files);
       
   643         GetFileNamesFromDirectory(_targets.at(i).release_bin_dir, "*.dll", _targets.at(i).bin_files);
       
   644         GetFileNamesFromDirectory(_targets.at(i).release_bin_dir, "*.prt", _targets.at(i).bin_files);
       
   645         GetFileNamesFromDirectory(_targets.at(i).release_bin_dir, "*.?sy", _targets.at(i).bin_files);
       
   646         GetFileNamesFromDirectory(_targets.at(i).release_bin_dir, "*.fep", _targets.at(i).bin_files);
       
   647         GetFileNamesFromDirectory(_targets.at(i).release_bin_dir, "*.agt", _targets.at(i).bin_files);
       
   648         GetFileNamesFromDirectory(_targets.at(i).release_bin_dir, "*.fxt", _targets.at(i).bin_files);
       
   649 
       
   650         // increase the value of total number of files
       
   651         _max_progress += _targets.at(i).bin_files.size();
       
   652     }
       
   653 }
       
   654 
       
   655 // ----------------------------------------------------------------------------------------------------------
       
   656 
       
   657 void GetFileNamesFromDirectory(const string& directory, const string& filter, vector<string>& resultset)
       
   658 {  
       
   659     // get list of files from the directory by executing OS specific dir/ls command
       
   660     string dir_command = DIR_COMMAND;
       
   661     string cmd = dir_command + " \"" + directory + "\"" + filter + " " + CERR_TO_NULL;
       
   662         
       
   663     vector<string> tempVector;
       
   664     ExecuteCommand(cmd, tempVector);
       
   665     
       
   666     // loop through all returned files
       
   667     for (unsigned int i=0; i<tempVector.size(); i++)
       
   668     {
       
   669         // remove any leading and trailing white spaces
       
   670         string file_entry = tempVector.at(i);
       
   671         TrimAll(file_entry);
       
   672         
       
   673         // filter out any unwanted files and append the file to the vector
       
   674         if (!file_entry.empty() && file_entry.find("{000a0000}")==string::npos && file_entry.find(".dll55l")==string::npos)
       
   675         {
       
   676             // strip out any possible directory paths
       
   677             string::size_type sep_pos = file_entry.find_last_of(DIR_SEPARATOR);
       
   678             if (sep_pos != string::npos)
       
   679                 file_entry = file_entry.substr(sep_pos+1, file_entry.length()-sep_pos-1); 
       
   680                         
       
   681             // append entry
       
   682             resultset.push_back(file_entry);
       
   683         }
       
   684     }
       
   685 }
       
   686 
       
   687 // ----------------------------------------------------------------------------------------------------------
       
   688 
       
   689 void SetAndCheckPetranPath()
       
   690 {
       
   691 	if(_cl_use_gcc)
       
   692 	{
       
   693     	_petran_location = _cl_releasedir + PETRAN_LOCATION;
       
   694 	}
       
   695 	else
       
   696 	{
       
   697     	_petran_location = _cl_releasedir + ELFTRAN_LOCATION;
       
   698 	}
       
   699 
       
   700  	if (!FileExists(_petran_location))
       
   701 	{
       
   702 		cerr << "ERROR: Unable to find " + _petran_location << ", check -release param" << endl;
       
   703 		cerr << "Make sure you have a working development environment" << endl;
       
   704 		exit(EXIT_PETRAN_NOT_FOUND);
       
   705 	}
       
   706 }
       
   707 
       
   708 // ----------------------------------------------------------------------------------------------------------