* Name compilation unit

* Generate compilation unit support code


svn path=/trunk/; revision=19470
This commit is contained in:
Casper Hornstrup 2005-11-22 22:16:14 +00:00
parent dc1f52977d
commit b102fa96a8
12 changed files with 276 additions and 74 deletions

View file

@ -129,11 +129,11 @@ void DevCppBackend::ProcessModules()
{ {
Module &module = *ProjectNode.modules[i]; Module &module = *ProjectNode.modules[i];
for(size_t k = 0; k < module.non_if_data.compilationUnits.size(); k++) for(size_t k = 0; k < module.non_if_data.files.size(); k++)
{ {
CompilationUnit &compilationUnit = *module.non_if_data.compilationUnits[k]; File &file = *module.non_if_data.files[k];
string filename = compilationUnit.GetFilename();
ProcessFile(filename); ProcessFile(file.name);
} }
} }
} }

View file

@ -193,6 +193,7 @@ MingwBackend::ProcessNormal ()
GenerateDirectories (); GenerateDirectories ();
UnpackWineResources (); UnpackWineResources ();
GenerateTestSupportCode (); GenerateTestSupportCode ();
GenerateCompilationUnitSupportCode ();
GenerateProxyMakefiles (); GenerateProxyMakefiles ();
CheckAutomaticDependencies (); CheckAutomaticDependencies ();
CloseMakefile (); CloseMakefile ();
@ -523,6 +524,15 @@ MingwBackend::GenerateTestSupportCode ()
printf ( "done\n" ); printf ( "done\n" );
} }
void
MingwBackend::GenerateCompilationUnitSupportCode ()
{
printf ( "Generating compilation unit support code..." );
CompilationUnitSupportCode compilationUnitSupportCode ( ProjectNode );
compilationUnitSupportCode.Generate ( configuration.Verbose );
printf ( "done\n" );
}
string string
MingwBackend::GetProxyMakefileTree () const MingwBackend::GetProxyMakefileTree () const
{ {

View file

@ -77,6 +77,7 @@ private:
std::string GetBin2ResExecutable (); std::string GetBin2ResExecutable ();
void UnpackWineResources (); void UnpackWineResources ();
void GenerateTestSupportCode (); void GenerateTestSupportCode ();
void GenerateCompilationUnitSupportCode ();
std::string GetProxyMakefileTree () const; std::string GetProxyMakefileTree () const;
void GenerateProxyMakefiles (); void GenerateProxyMakefiles ();
void CheckAutomaticDependencies (); void CheckAutomaticDependencies ();

View file

@ -121,6 +121,8 @@ MingwModuleHandler::PassThruCacheDirectory (
Directory* directoryTree ) Directory* directoryTree )
{ {
string directory ( GetDirectory ( RemoveVariables ( file ) ) ); string directory ( GetDirectory ( RemoveVariables ( file ) ) );
if ( directoryTree == NULL )
return file;
string generatedFilesDirectory = backend->AddDirectoryTarget ( directory, string generatedFilesDirectory = backend->AddDirectoryTarget ( directory,
directoryTree ); directoryTree );
if ( directory.find ( generatedFilesDirectory ) != string::npos ) if ( directory.find ( generatedFilesDirectory ) != string::npos )
@ -134,6 +136,13 @@ MingwModuleHandler::PassThruCacheDirectory (
} }
} }
/*static*/ string
MingwModuleHandler::PassThruCacheDirectory (const FileLocation* fileLocation )
{
return PassThruCacheDirectory ( fileLocation->filename,
fileLocation->directory );
}
/*static*/ Directory* /*static*/ Directory*
MingwModuleHandler::GetTargetDirectoryTree ( MingwModuleHandler::GetTargetDirectoryTree (
const Module& module ) const Module& module )
@ -264,16 +273,18 @@ MingwModuleHandler::GetBasename ( const string& filename ) const
return ""; return "";
} }
string FileLocation*
MingwModuleHandler::GetActualSourceFilename ( MingwModuleHandler::GetActualSourceFilename (
const string& filename ) const const FileLocation* fileLocation ) const
{ {
string filename = fileLocation->filename;
string extension = GetExtension ( filename ); string extension = GetExtension ( filename );
if ( extension == ".spec" || extension == ".SPEC" ) if ( extension == ".spec" || extension == ".SPEC" )
{ {
string basename = GetBasename ( filename ); string basename = GetBasename ( filename );
return PassThruCacheDirectory ( NormalizeFilename ( basename + ".stubs.c" ), PassThruCacheDirectory ( NormalizeFilename ( basename + ".stubs.c" ),
backend->intermediateDirectory ); backend->intermediateDirectory );
return new FileLocation ( backend->intermediateDirectory, NormalizeFilename ( basename + ".stubs.c" ) );
} }
else if ( extension == ".idl" || extension == ".IDL" ) else if ( extension == ".idl" || extension == ".IDL" )
{ {
@ -283,11 +294,12 @@ MingwModuleHandler::GetActualSourceFilename (
newname = basename + "_s.c"; newname = basename + "_s.c";
else else
newname = basename + "_c.c"; newname = basename + "_c.c";
return PassThruCacheDirectory ( NormalizeFilename ( newname ), PassThruCacheDirectory ( NormalizeFilename ( newname ),
backend->intermediateDirectory ); backend->intermediateDirectory );
return new FileLocation ( backend->intermediateDirectory, NormalizeFilename ( newname ) );
} }
else else
return filename; return new FileLocation ( fileLocation->directory, filename );
} }
string string
@ -304,6 +316,21 @@ MingwModuleHandler::GetExtraDependencies (
return ""; return "";
} }
string
MingwModuleHandler::GetCompilationUnitDependencies (
const CompilationUnit& compilationUnit ) const
{
if ( compilationUnit.files.size () <= 1 )
return "";
vector<string> sourceFiles;
for ( size_t i = 0; i < compilationUnit.files.size (); i++ )
{
File& file = *compilationUnit.files[i];
sourceFiles.push_back ( NormalizeFilename ( file.name ) );
}
return v2s ( sourceFiles, 10 );
}
string string
MingwModuleHandler::GetModuleArchiveFilename () const MingwModuleHandler::GetModuleArchiveFilename () const
{ {
@ -393,7 +420,10 @@ MingwModuleHandler::GetSourceFilenames ( string_list& list,
{ {
if ( includeGeneratedFiles || !compilationUnits[i]->IsGeneratedFile () ) if ( includeGeneratedFiles || !compilationUnits[i]->IsGeneratedFile () )
{ {
list.push_back ( GetActualSourceFilename ( compilationUnits[i]->GetFilename () ) ); FileLocation* sourceFileLocation = GetActualSourceFilename (
compilationUnits[i]->GetFilename ( backend->intermediateDirectory ) );
list.push_back ( PassThruCacheDirectory ( sourceFileLocation->filename,
sourceFileLocation->directory ) );
} }
} }
// intentionally make a copy so that we can append more work in // intentionally make a copy so that we can append more work in
@ -412,7 +442,12 @@ MingwModuleHandler::GetSourceFilenames ( string_list& list,
{ {
CompilationUnit& compilationUnit = *compilationUnits[j]; CompilationUnit& compilationUnit = *compilationUnits[j];
if ( includeGeneratedFiles || !compilationUnit.IsGeneratedFile () ) if ( includeGeneratedFiles || !compilationUnit.IsGeneratedFile () )
list.push_back ( GetActualSourceFilename ( compilationUnit.GetFilename () ) ); {
FileLocation* sourceFileLocation = GetActualSourceFilename (
compilationUnit.GetFilename ( backend->intermediateDirectory ) );
list.push_back ( PassThruCacheDirectory ( sourceFileLocation->filename,
sourceFileLocation->directory ) );
}
} }
} }
} }
@ -426,11 +461,11 @@ MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
string string
MingwModuleHandler::GetObjectFilename ( MingwModuleHandler::GetObjectFilename (
const string& sourceFilename, const FileLocation* sourceFileLocation,
string_list* pclean_files ) const string_list* pclean_files ) const
{ {
string sourceFilename = sourceFileLocation->filename;
Directory* directoryTree; Directory* directoryTree;
string newExtension; string newExtension;
string extension = GetExtension ( sourceFilename ); string extension = GetExtension ( sourceFilename );
if ( extension == ".rc" || extension == ".RC" ) if ( extension == ".rc" || extension == ".RC" )
@ -550,7 +585,7 @@ MingwModuleHandler::GetObjectFilenames ()
{ {
if ( objectFilenames.size () > 0 ) if ( objectFilenames.size () > 0 )
objectFilenames += " "; objectFilenames += " ";
objectFilenames += GetObjectFilename ( compilationUnits[i]->GetFilename (), NULL ); objectFilenames += GetObjectFilename ( compilationUnits[i]->GetFilename ( backend->intermediateDirectory ), NULL );
} }
return objectFilenames; return objectFilenames;
} }
@ -851,7 +886,7 @@ MingwModuleHandler::GenerateObjectMacros (
fprintf ( fMakefile, fprintf ( fMakefile,
"%s := %s $(%s)\n", "%s := %s $(%s)\n",
objectsMacro.c_str(), objectsMacro.c_str(),
GetObjectFilename ( compilationUnit.GetFilename (), NULL ).c_str (), GetObjectFilename ( compilationUnit.GetFilename ( backend->intermediateDirectory ), NULL ).c_str (),
objectsMacro.c_str() ); objectsMacro.c_str() );
} }
} }
@ -869,7 +904,7 @@ MingwModuleHandler::GenerateObjectMacros (
fMakefile, fMakefile,
"%s%s", "%s%s",
( i%10 == 9 ? " \\\n\t" : " " ), ( i%10 == 9 ? " \\\n\t" : " " ),
GetObjectFilename ( compilationUnit.GetFilename (), NULL ).c_str () ); GetObjectFilename ( compilationUnit.GetFilename ( backend->intermediateDirectory ), NULL ).c_str () );
} }
} }
fprintf ( fMakefile, "\n" ); fprintf ( fMakefile, "\n" );
@ -910,7 +945,7 @@ MingwModuleHandler::GenerateObjectMacros (
fMakefile, fMakefile,
"%s += %s\n", "%s += %s\n",
objectsMacro.c_str(), objectsMacro.c_str(),
GetObjectFilename ( sourceCompilationUnits[i]->GetFilename (), NULL ).c_str () ); GetObjectFilename ( sourceCompilationUnits[i]->GetFilename ( backend->intermediateDirectory ), NULL ).c_str () );
} }
CleanupCompilationUnitVector ( sourceCompilationUnits ); CleanupCompilationUnitVector ( sourceCompilationUnits );
} }
@ -925,11 +960,12 @@ MingwModuleHandler::GetPrecompiledHeaderFilename () const
void void
MingwModuleHandler::GenerateGccCommand ( MingwModuleHandler::GenerateGccCommand (
const string& sourceFilename, const FileLocation* sourceFileLocation,
const string& extraDependencies, const string& extraDependencies,
const string& cc, const string& cc,
const string& cflagsMacro ) const string& cflagsMacro )
{ {
string sourceFilename = PassThruCacheDirectory ( sourceFileLocation );
string dependencies = sourceFilename; string dependencies = sourceFilename;
if ( extraDependencies != "" ) if ( extraDependencies != "" )
dependencies += " " + extraDependencies; dependencies += " " + extraDependencies;
@ -943,7 +979,7 @@ MingwModuleHandler::GenerateGccCommand (
dependencies += " " + NormalizeFilename ( module.xmlbuildFile ); dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
string objectFilename = GetObjectFilename ( string objectFilename = GetObjectFilename (
sourceFilename, &clean_files ); sourceFileLocation, &clean_files );
fprintf ( fMakefile, fprintf ( fMakefile,
"%s: %s | %s\n", "%s: %s | %s\n",
objectFilename.c_str (), objectFilename.c_str (),
@ -958,14 +994,15 @@ MingwModuleHandler::GenerateGccCommand (
void void
MingwModuleHandler::GenerateGccAssemblerCommand ( MingwModuleHandler::GenerateGccAssemblerCommand (
const string& sourceFilename, const FileLocation* sourceFileLocation,
const string& cc, const string& cc,
const string& cflagsMacro ) const string& cflagsMacro )
{ {
string sourceFilename = PassThruCacheDirectory ( sourceFileLocation );
string dependencies = sourceFilename; string dependencies = sourceFilename;
dependencies += " " + NormalizeFilename ( module.xmlbuildFile ); dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
string objectFilename = GetObjectFilename ( string objectFilename = GetObjectFilename (
sourceFilename, &clean_files ); sourceFileLocation, &clean_files );
fprintf ( fMakefile, fprintf ( fMakefile,
"%s: %s | %s\n", "%s: %s | %s\n",
objectFilename.c_str (), objectFilename.c_str (),
@ -980,13 +1017,14 @@ MingwModuleHandler::GenerateGccAssemblerCommand (
void void
MingwModuleHandler::GenerateNasmCommand ( MingwModuleHandler::GenerateNasmCommand (
const string& sourceFilename, const FileLocation* sourceFileLocation,
const string& nasmflagsMacro ) const string& nasmflagsMacro )
{ {
string sourceFilename = PassThruCacheDirectory ( sourceFileLocation );
string dependencies = sourceFilename; string dependencies = sourceFilename;
dependencies += " " + NormalizeFilename ( module.xmlbuildFile ); dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
string objectFilename = GetObjectFilename ( string objectFilename = GetObjectFilename (
sourceFilename, &clean_files ); sourceFileLocation, &clean_files );
fprintf ( fMakefile, fprintf ( fMakefile,
"%s: %s | %s\n", "%s: %s | %s\n",
objectFilename.c_str (), objectFilename.c_str (),
@ -1001,13 +1039,13 @@ MingwModuleHandler::GenerateNasmCommand (
void void
MingwModuleHandler::GenerateWindresCommand ( MingwModuleHandler::GenerateWindresCommand (
const string& sourceFilename, const FileLocation* sourceFileLocation,
const string& windresflagsMacro ) const string& windresflagsMacro )
{ {
string sourceFilename = PassThruCacheDirectory ( sourceFileLocation );
string dependencies = sourceFilename; string dependencies = sourceFilename;
dependencies += " " + NormalizeFilename ( module.xmlbuildFile ); dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
string objectFilename = string objectFilename = GetObjectFilename ( sourceFileLocation, &clean_files );
GetObjectFilename ( sourceFilename, &clean_files );
string sourceFilenamePart = ReplaceExtension ( GetFilename ( sourceFilename ), "" ); string sourceFilenamePart = ReplaceExtension ( GetFilename ( sourceFilename ), "" );
string rciFilename = ros_temp + module.name + "." + sourceFilenamePart + ".rci.tmp"; string rciFilename = ros_temp + module.name + "." + sourceFilenamePart + ".rci.tmp";
string resFilename = ros_temp + module.name + "." + sourceFilenamePart + ".res.tmp"; string resFilename = ros_temp + module.name + "." + sourceFilenamePart + ".res.tmp";
@ -1056,8 +1094,9 @@ MingwModuleHandler::GenerateWindresCommand (
void void
MingwModuleHandler::GenerateWinebuildCommands ( MingwModuleHandler::GenerateWinebuildCommands (
const string& sourceFilename ) const FileLocation* sourceFileLocation )
{ {
string sourceFilename = PassThruCacheDirectory ( sourceFileLocation );
string dependencies = sourceFilename; string dependencies = sourceFilename;
dependencies += " " + NormalizeFilename ( module.xmlbuildFile ); dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
@ -1113,7 +1152,8 @@ MingwModuleHandler::GenerateWidlCommandsServer (
const CompilationUnit& compilationUnit, const CompilationUnit& compilationUnit,
const string& widlflagsMacro ) const string& widlflagsMacro )
{ {
string filename = compilationUnit.GetFilename (); FileLocation* sourceFileLocation = compilationUnit.GetFilename ( backend->intermediateDirectory );
string filename = sourceFileLocation->filename;
string dependencies = filename; string dependencies = filename;
dependencies += " " + NormalizeFilename ( module.xmlbuildFile ); dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
@ -1156,7 +1196,8 @@ MingwModuleHandler::GenerateWidlCommandsClient (
const CompilationUnit& compilationUnit, const CompilationUnit& compilationUnit,
const string& widlflagsMacro ) const string& widlflagsMacro )
{ {
string filename = compilationUnit.GetFilename (); FileLocation* sourceFileLocation = compilationUnit.GetFilename ( backend->intermediateDirectory );
string filename = sourceFileLocation->filename;
string dependencies = filename; string dependencies = filename;
dependencies += " " + NormalizeFilename ( module.xmlbuildFile ); dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
@ -1210,12 +1251,13 @@ MingwModuleHandler::GenerateCommands (
const string& windresflagsMacro, const string& windresflagsMacro,
const string& widlflagsMacro ) const string& widlflagsMacro )
{ {
string filename = compilationUnit.GetFilename (); FileLocation* sourceFileLocation = compilationUnit.GetFilename ( backend->intermediateDirectory );
string filename = sourceFileLocation->filename;
string extension = GetExtension ( filename ); string extension = GetExtension ( filename );
if ( extension == ".c" || extension == ".C" ) if ( extension == ".c" || extension == ".C" )
{ {
GenerateGccCommand ( filename, GenerateGccCommand ( sourceFileLocation,
"", GetCompilationUnitDependencies ( compilationUnit ),
cc, cc,
cflagsMacro ); cflagsMacro );
return; return;
@ -1224,35 +1266,35 @@ MingwModuleHandler::GenerateCommands (
extension == ".cpp" || extension == ".CPP" || extension == ".cpp" || extension == ".CPP" ||
extension == ".cxx" || extension == ".CXX" ) extension == ".cxx" || extension == ".CXX" )
{ {
GenerateGccCommand ( filename, GenerateGccCommand ( sourceFileLocation,
"", GetCompilationUnitDependencies ( compilationUnit ),
cppc, cppc,
cflagsMacro ); cflagsMacro );
return; return;
} }
else if ( extension == ".s" || extension == ".S" ) else if ( extension == ".s" || extension == ".S" )
{ {
GenerateGccAssemblerCommand ( filename, GenerateGccAssemblerCommand ( sourceFileLocation,
cc, cc,
cflagsMacro ); cflagsMacro );
return; return;
} }
else if ( extension == ".asm" || extension == ".ASM" ) else if ( extension == ".asm" || extension == ".ASM" )
{ {
GenerateNasmCommand ( filename, GenerateNasmCommand ( sourceFileLocation,
nasmflagsMacro ); nasmflagsMacro );
return; return;
} }
else if ( extension == ".rc" || extension == ".RC" ) else if ( extension == ".rc" || extension == ".RC" )
{ {
GenerateWindresCommand ( filename, GenerateWindresCommand ( sourceFileLocation,
windresflagsMacro ); windresflagsMacro );
return; return;
} }
else if ( extension == ".spec" || extension == ".SPEC" ) else if ( extension == ".spec" || extension == ".SPEC" )
{ {
GenerateWinebuildCommands ( filename ); GenerateWinebuildCommands ( sourceFileLocation );
GenerateGccCommand ( GetActualSourceFilename ( filename ), GenerateGccCommand ( GetActualSourceFilename ( sourceFileLocation ),
"", "",
cc, cc,
cflagsMacro ); cflagsMacro );
@ -1262,7 +1304,7 @@ MingwModuleHandler::GenerateCommands (
{ {
GenerateWidlCommands ( compilationUnit, GenerateWidlCommands ( compilationUnit,
widlflagsMacro ); widlflagsMacro );
GenerateGccCommand ( GetActualSourceFilename ( filename ), GenerateGccCommand ( GetActualSourceFilename ( sourceFileLocation ),
GetExtraDependencies ( filename ), GetExtraDependencies ( filename ),
cc, cc,
cflagsMacro ); cflagsMacro );
@ -1369,7 +1411,7 @@ MingwModuleHandler::GetObjectsVector ( const IfableData& data,
for ( size_t i = 0; i < data.compilationUnits.size (); i++ ) for ( size_t i = 0; i < data.compilationUnits.size (); i++ )
{ {
CompilationUnit& compilationUnit = *data.compilationUnits[i]; CompilationUnit& compilationUnit = *data.compilationUnits[i];
objectFiles.push_back ( GetObjectFilename ( compilationUnit.GetFilename (), NULL ) ); objectFiles.push_back ( GetObjectFilename ( compilationUnit.GetFilename ( backend->intermediateDirectory ), NULL ) );
} }
} }
@ -1701,11 +1743,11 @@ MingwModuleHandler::GetRpcHeaderDependencies (
for ( size_t j = 0; j < library.importedModule->non_if_data.compilationUnits.size (); j++ ) for ( size_t j = 0; j < library.importedModule->non_if_data.compilationUnits.size (); j++ )
{ {
CompilationUnit& compilationUnit = *library.importedModule->non_if_data.compilationUnits[j]; CompilationUnit& compilationUnit = *library.importedModule->non_if_data.compilationUnits[j];
string filename = compilationUnit.GetFilename (); FileLocation* sourceFileLocation = compilationUnit.GetFilename ( backend->intermediateDirectory );
string extension = GetExtension ( filename ); string extension = GetExtension ( sourceFileLocation->filename );
if ( extension == ".idl" || extension == ".IDL" ) if ( extension == ".idl" || extension == ".IDL" )
{ {
string basename = GetBasename ( filename ); string basename = GetBasename ( sourceFileLocation->filename );
if ( library.importedModule->type == RpcServer ) if ( library.importedModule->type == RpcServer )
dependencies.push_back ( GetRpcServerHeaderFilename ( basename ) ); dependencies.push_back ( GetRpcServerHeaderFilename ( basename ) );
if ( library.importedModule->type == RpcClient ) if ( library.importedModule->type == RpcClient )
@ -1739,10 +1781,10 @@ MingwModuleHandler::GenerateOtherMacros ()
for ( size_t i = 0; i < compilationUnits.size (); i++ ) for ( size_t i = 0; i < compilationUnits.size (); i++ )
{ {
CompilationUnit& compilationUnit = *compilationUnits[i]; CompilationUnit& compilationUnit = *compilationUnits[i];
string filename = compilationUnit.GetFilename (); FileLocation* sourceFileLocation = compilationUnit.GetFilename ( backend->intermediateDirectory );
string extension = GetExtension ( filename ); string extension = GetExtension ( sourceFileLocation->filename );
if ( extension == ".spec" || extension == ".SPEC" ) if ( extension == ".spec" || extension == ".SPEC" )
GetSpecObjectDependencies ( s, filename ); GetSpecObjectDependencies ( s, sourceFileLocation->filename );
} }
} }
if ( s.size () > 0 ) if ( s.size () > 0 )
@ -2094,12 +2136,12 @@ MingwModuleHandler::GetDefinitionDependencies (
for ( size_t i = 0; i < compilationUnits.size (); i++ ) for ( size_t i = 0; i < compilationUnits.size (); i++ )
{ {
CompilationUnit& compilationUnit = *compilationUnits[i]; CompilationUnit& compilationUnit = *compilationUnits[i];
string filename = compilationUnit.GetFilename (); FileLocation* sourceFileLocation = compilationUnit.GetFilename ( backend->intermediateDirectory );
string extension = GetExtension ( filename ); string extension = GetExtension ( sourceFileLocation->filename );
if ( extension == ".spec" || extension == ".SPEC" ) if ( extension == ".spec" || extension == ".SPEC" )
GetSpecObjectDependencies ( dependencies, filename ); GetSpecObjectDependencies ( dependencies, sourceFileLocation->filename );
if ( extension == ".idl" || extension == ".IDL" ) if ( extension == ".idl" || extension == ".IDL" )
GetWidlObjectDependencies ( dependencies, filename ); GetWidlObjectDependencies ( dependencies, sourceFileLocation->filename );
} }
} }

View file

@ -45,6 +45,8 @@ public:
const std::string &f, const std::string &f,
Directory* directoryTree ); Directory* directoryTree );
static std::string PassThruCacheDirectory (const FileLocation* fileLocation );
static Directory* GetTargetDirectoryTree ( static Directory* GetTargetDirectoryTree (
const Module& module ); const Module& module );
@ -84,8 +86,9 @@ protected:
virtual void GetModuleSpecificCompilationUnits ( std::vector<CompilationUnit*>& compilationUnits ); virtual void GetModuleSpecificCompilationUnits ( std::vector<CompilationUnit*>& compilationUnits );
std::string GetWorkingDirectory () const; std::string GetWorkingDirectory () const;
std::string GetBasename ( const std::string& filename ) const; std::string GetBasename ( const std::string& filename ) const;
std::string GetActualSourceFilename ( const std::string& filename ) const; FileLocation* GetActualSourceFilename ( const FileLocation* fileLocation ) const;
std::string GetExtraDependencies ( const std::string& filename ) const; std::string GetExtraDependencies ( const std::string& filename ) const;
std::string MingwModuleHandler::GetCompilationUnitDependencies ( const CompilationUnit& compilationUnit ) const;
std::string GetModuleArchiveFilename () const; std::string GetModuleArchiveFilename () const;
bool IsGeneratedFile ( const File& file ) const; bool IsGeneratedFile ( const File& file ) const;
std::string GetImportLibraryDependency ( const Module& importedModule ); std::string GetImportLibraryDependency ( const Module& importedModule );
@ -96,7 +99,7 @@ protected:
void GetSourceFilenames ( string_list& list, void GetSourceFilenames ( string_list& list,
bool includeGeneratedFiles ) const; bool includeGeneratedFiles ) const;
void GetSourceFilenamesWithoutGeneratedFiles ( string_list& list ) const; void GetSourceFilenamesWithoutGeneratedFiles ( string_list& list ) const;
std::string GetObjectFilename ( const std::string& sourceFilename, std::string GetObjectFilename ( const FileLocation* sourceFileLocation,
string_list* pclean_files ) const; string_list* pclean_files ) const;
std::string GetObjectFilenames (); std::string GetObjectFilenames ();
@ -144,18 +147,18 @@ private:
std::string GenerateGccParameters () const; std::string GenerateGccParameters () const;
std::string GenerateNasmParameters () const; std::string GenerateNasmParameters () const;
std::string MingwModuleHandler::GetPrecompiledHeaderFilename () const; std::string MingwModuleHandler::GetPrecompiledHeaderFilename () const;
void GenerateGccCommand ( const std::string& sourceFilename, void GenerateGccCommand ( const FileLocation* sourceFileLocation,
const std::string& extraDependencies, const std::string& extraDependencies,
const std::string& cc, const std::string& cc,
const std::string& cflagsMacro ); const std::string& cflagsMacro );
void GenerateGccAssemblerCommand ( const std::string& sourceFilename, void GenerateGccAssemblerCommand ( const FileLocation* sourceFileLocation,
const std::string& cc, const std::string& cc,
const std::string& cflagsMacro ); const std::string& cflagsMacro );
void GenerateNasmCommand ( const std::string& sourceFilename, void GenerateNasmCommand ( const FileLocation* sourceFileLocation,
const std::string& nasmflagsMacro ); const std::string& nasmflagsMacro );
void GenerateWindresCommand ( const std::string& sourceFilename, void GenerateWindresCommand ( const FileLocation* sourceFileLocation,
const std::string& windresflagsMacro ); const std::string& windresflagsMacro );
void GenerateWinebuildCommands ( const std::string& sourceFilename ); void GenerateWinebuildCommands ( const FileLocation* sourceFileLocation );
std::string GetWidlFlags ( const CompilationUnit& compilationUnit ); std::string GetWidlFlags ( const CompilationUnit& compilationUnit );
void GenerateWidlCommandsServer ( void GenerateWidlCommandsServer (
const CompilationUnit& compilationUnit, const CompilationUnit& compilationUnit,

View file

@ -28,6 +28,7 @@ CompilationUnit::CompilationUnit ( File* file )
module(NULL), module(NULL),
node(NULL) node(NULL)
{ {
name = file->name;
files.push_back ( file ); files.push_back ( file );
} }
@ -38,6 +39,9 @@ CompilationUnit::CompilationUnit ( const Project* project,
module(module), module(module),
node(node) node(node)
{ {
const XMLAttribute* att = node->GetAttribute ( "name", true );
assert(att);
name = module->GetBasePath () + cSep + att->value;
} }
CompilationUnit::~CompilationUnit () CompilationUnit::~CompilationUnit ()
@ -83,28 +87,25 @@ bool
CompilationUnit::IsFirstFile () const CompilationUnit::IsFirstFile () const
{ {
if ( files.size () == 0 || files.size () > 1 ) if ( files.size () == 0 || files.size () > 1 )
{ return false;
printf("fs:'%d'\n", files.size ());
throw InvalidOperationException ( __FILE__, __LINE__ );
}
File* file = files[0]; File* file = files[0];
return file->first; return file->first;
} }
std::string FileLocation*
CompilationUnit::GetFilename () const CompilationUnit::GetFilename ( Directory* intermediateDirectory ) const
{ {
if ( files.size () == 0 || files.size () > 1 ) if ( files.size () == 0 || files.size () > 1 )
throw InvalidOperationException ( __FILE__, __LINE__ ); return new FileLocation ( intermediateDirectory, name );
File* file = files[0]; File* file = files[0];
return file->name; return new FileLocation ( NULL, file->name );
} }
std::string std::string
CompilationUnit::GetSwitches () const CompilationUnit::GetSwitches () const
{ {
if ( files.size () == 0 || files.size () > 1 ) if ( files.size () == 0 || files.size () > 1 )
throw InvalidOperationException ( __FILE__, __LINE__ ); return "";
File* file = files[0]; File* file = files[0];
return file->switches; return file->switches;
} }

View file

@ -0,0 +1,99 @@
/*
* Copyright (C) 2005 Casper S. Hornstrup
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "pch.h"
#include <assert.h>
#include "rbuild.h"
using std::string;
using std::vector;
CompilationUnitSupportCode::CompilationUnitSupportCode ( const Project& project )
: project ( project )
{
}
CompilationUnitSupportCode::~CompilationUnitSupportCode ()
{
}
void
CompilationUnitSupportCode::Generate ( bool verbose )
{
for ( size_t i = 0; i < project.modules.size (); i++ )
{
GenerateForModule ( *project.modules[i],
verbose );
}
}
void
CompilationUnitSupportCode::GenerateForModule ( Module& module,
bool verbose )
{
if ( verbose )
{
printf ( "\nGenerating compilation unit support code for %s",
module.name.c_str () );
}
for ( size_t i = 0; i < module.non_if_data.compilationUnits.size () ; i++ )
{
CompilationUnit& compilationUnit = *module.non_if_data.compilationUnits[i];
if ( compilationUnit.files.size () <= 1 )
continue;
WriteCompilationUnitFile ( module, compilationUnit );
}
}
string
CompilationUnitSupportCode::GetCompilationUnitFilename ( Module& module,
CompilationUnit& compilationUnit )
{
return NormalizeFilename ( Environment::GetIntermediatePath () + sSep + compilationUnit.name );
}
void
CompilationUnitSupportCode::WriteCompilationUnitFile ( Module& module,
CompilationUnit& compilationUnit )
{
char* buf;
char* s;
buf = (char*) malloc ( 512*1024 );
if ( buf == NULL )
throw OutOfMemoryException ();
s = buf;
s = s + sprintf ( s, "/* This file is automatically generated. */\n" );
s = s + sprintf ( s, "#define ONE_COMPILATION_UNIT\n" );
if ( module.pch )
s = s + sprintf ( s, "#include <%s>\n", NormalizeFilename ( module.pch->file.name ).c_str () );
for ( size_t i = 0; i < compilationUnit.files.size () ; i++ )
{
File& file = *compilationUnit.files[i];
s = s + sprintf ( s, "#include \"%s\"\n", file.name.c_str () );
}
s = s + sprintf ( s, "\n" );
FileSupportCode::WriteIfChanged ( buf, GetCompilationUnitFilename ( module, compilationUnit ) );
free ( buf );
}

View file

@ -195,12 +195,12 @@ CompilationUnit element
A compilationunit element specifies that one or more source code files are to be compiled as a single compilation unit. A compilationunit element specifies that one or more source code files are to be compiled as a single compilation unit.
Syntax: Syntax:
<compilationunit> <compilationunit name="kernel32.c">
... ...
</compilationunit> </compilationunit>
Attributes: Attributes:
None. name - Name of generated source code file.
Value: Value:
None. None.

View file

@ -72,6 +72,15 @@ ParseContext::ParseContext ()
{ {
} }
FileLocation::FileLocation ( Directory* directory,
std::string filename )
: directory (directory),
filename (filename)
{
}
Project::Project ( const string& filename ) Project::Project ( const string& filename )
: xmlfile (filename), : xmlfile (filename),
node (NULL), node (NULL),

View file

@ -93,6 +93,7 @@ class PchFile;
class StubbedComponent; class StubbedComponent;
class StubbedSymbol; class StubbedSymbol;
class CompilationUnit; class CompilationUnit;
class FileLocation;
class SourceFileTest; class SourceFileTest;
@ -817,6 +818,7 @@ public:
const Project* project; const Project* project;
const Module* module; const Module* module;
const XMLElement* node; const XMLElement* node;
std::string name;
std::vector<File*> files; std::vector<File*> files;
CompilationUnit ( File* file ); CompilationUnit ( File* file );
@ -828,11 +830,39 @@ public:
bool IsGeneratedFile () const; bool IsGeneratedFile () const;
bool HasFileWithExtension ( const std::string& extension ) const; bool HasFileWithExtension ( const std::string& extension ) const;
bool IsFirstFile () const; bool IsFirstFile () const;
std::string GetFilename () const; FileLocation* GetFilename ( Directory* intermediateDirectory ) const;
std::string GetSwitches () const; std::string GetSwitches () const;
}; };
class CompilationUnitSupportCode
{
public:
const Project& project;
CompilationUnitSupportCode ( const Project& project );
~CompilationUnitSupportCode ();
void Generate ( bool verbose );
private:
void GenerateForModule ( Module& module,
bool verbose );
std::string GetCompilationUnitFilename ( Module& module,
CompilationUnit& compilationUnit );
void WriteCompilationUnitFile ( Module& module,
CompilationUnit& compilationUnit );
};
class FileLocation
{
public:
Directory* directory;
std::string filename;
FileLocation ( Directory* directory,
std::string filename );
};
extern void extern void
InitializeEnvironment (); InitializeEnvironment ();

View file

@ -157,6 +157,7 @@ RBUILD_COMMON_SOURCES = \
bootstrap.cpp \ bootstrap.cpp \
cdfile.cpp \ cdfile.cpp \
compilationunit.cpp \ compilationunit.cpp \
compilationunitsupportcode.cpp \
compilerflag.cpp \ compilerflag.cpp \
configuration.cpp \ configuration.cpp \
define.cpp \ define.cpp \
@ -280,6 +281,10 @@ $(RBUILD_INT_)compilationunit.o: $(RBUILD_BASE_)compilationunit.cpp $(RBUILD_HEA
$(ECHO_CC) $(ECHO_CC)
${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@ ${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@
$(RBUILD_INT_)compilationunitsupportcode.o: $(RBUILD_BASE_)compilationunitsupportcode.cpp $(RBUILD_HEADERS) | $(RBUILD_INT)
$(ECHO_CC)
${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@
$(RBUILD_INT_)compilerflag.o: $(RBUILD_BASE_)compilerflag.cpp $(RBUILD_HEADERS) | $(RBUILD_INT) $(RBUILD_INT_)compilerflag.o: $(RBUILD_BASE_)compilerflag.cpp $(RBUILD_HEADERS) | $(RBUILD_INT)
$(ECHO_CC) $(ECHO_CC)
${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@ ${host_gpp} $(RBUILD_HOST_CXXFLAGS) -c $< -o $@

View file

@ -297,7 +297,8 @@ TestSupportCode::GetSourceFilenames ( string_list& list,
const vector<CompilationUnit*>& compilationUnits = module.non_if_data.compilationUnits; const vector<CompilationUnit*>& compilationUnits = module.non_if_data.compilationUnits;
for ( i = 0; i < compilationUnits.size (); i++ ) for ( i = 0; i < compilationUnits.size (); i++ )
{ {
string filename = compilationUnits[i]->GetFilename(); FileLocation* sourceFileLocation = compilationUnits[i]->GetFilename ( NULL );
string filename = sourceFileLocation->filename;
if ( !compilationUnits[i]->IsGeneratedFile () && IsTestFile ( filename ) ) if ( !compilationUnits[i]->IsGeneratedFile () && IsTestFile ( filename ) )
list.push_back ( filename ); list.push_back ( filename );
} }
@ -316,7 +317,8 @@ TestSupportCode::GetSourceFilenames ( string_list& list,
for ( j = 0; j < compilationUnits.size (); j++ ) for ( j = 0; j < compilationUnits.size (); j++ )
{ {
CompilationUnit& compilationUnit = *compilationUnits[j]; CompilationUnit& compilationUnit = *compilationUnits[j];
string filename = compilationUnits[j]->GetFilename(); FileLocation* sourceFileLocation = compilationUnits[j]->GetFilename ( NULL );
string filename = sourceFileLocation->filename;
if ( !compilationUnit.IsGeneratedFile () && IsTestFile ( filename ) ) if ( !compilationUnit.IsGeneratedFile () && IsTestFile ( filename ) )
list.push_back ( filename ); list.push_back ( filename );
} }