sync with trunk head (34904)
[reactos.git] / reactos / tools / rbuild / module.cpp
index 8445778..688a934 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2005 Casper S. Hornstrup
+ * Copyright (C) 2008 HervĂ© Poussineau
  *
  * 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
@@ -118,6 +119,7 @@ ReplaceExtension (
 
 string
 GetSubPath (
+       const Project& project,
        const string& location,
        const string& path,
        const string& att_value )
@@ -132,39 +134,26 @@ GetSubPath (
                        "<directory> tag has invalid characters in 'name' attribute" );
        if ( !path.size() )
                return att_value;
+
        return FixSeparator(path + cSep + att_value);
 }
 
-string
+static string
 GetExtension ( const string& filename )
 {
        size_t index = filename.find_last_of ( '/' );
        if (index == string::npos) index = 0;
        string tmp = filename.substr( index, filename.size() - index );
        size_t ext_index = tmp.find_last_of( '.' );
-       if (ext_index != string::npos) 
+       if (ext_index != string::npos)
                return filename.substr ( index + ext_index, filename.size() );
        return "";
 }
 
 string
-GetDirectory ( const string& filename )
-{
-       size_t index = filename.find_last_of ( cSep );
-       if ( index == string::npos )
-               return "";
-       else
-               return filename.substr ( 0, index );
-}
-
-string
-GetFilename ( const string& filename )
+GetExtension ( const FileLocation& file )
 {
-       size_t index = filename.find_last_of ( cSep );
-       if ( index == string::npos )
-               return filename;
-       else
-               return filename.substr ( index + 1, filename.length () - index );
+       return GetExtension ( file.name );
 }
 
 string
@@ -195,6 +184,11 @@ ToLower ( string filename )
        return filename;
 }
 
+IfableData::IfableData( )
+       : asmFiles ( 0 )
+{
+}
+
 void IfableData::ExtractModules( std::vector<Module*> &modules )
 {
        size_t i;
@@ -217,8 +211,6 @@ IfableData::~IfableData()
                delete compilerFlags[i];
        for ( i = 0; i < modules.size(); i++ )
                delete modules[i];
-       for ( i = 0; i < ifs.size (); i++ )
-               delete ifs[i];
        for ( i = 0; i < compilationUnits.size (); i++ )
                delete compilationUnits[i];
 }
@@ -236,8 +228,6 @@ void IfableData::ProcessXML ()
                properties[i]->ProcessXML ();
        for ( i = 0; i < compilerFlags.size(); i++ )
                compilerFlags[i]->ProcessXML ();
-       for ( i = 0; i < ifs.size (); i++ )
-               ifs[i]->ProcessXML ();
        for ( i = 0; i < compilationUnits.size (); i++ )
                compilationUnits[i]->ProcessXML ();
 }
@@ -248,25 +238,31 @@ Module::Module ( const Project& project,
        : project (project),
          node (moduleNode),
          importLibrary (NULL),
+         metadata (NULL),
+         bootSector (NULL),
          bootstrap (NULL),
          autoRegister(NULL),
          linkerScript (NULL),
          pch (NULL),
          cplusplus (false),
-         host (HostDefault)
+         host (HostDefault),
+         output (NULL),
+         install (NULL)
 {
        if ( node.name != "module" )
                throw InvalidOperationException ( __FILE__,
                                                  __LINE__,
                                                  "Module created with non-<module> node" );
 
-       xmlbuildFile = Path::RelativeFromWorkingDirectory ( moduleNode.xmlFile->filename () );
+       xmlbuildFile = FixSeparator ( Path::RelativeFromWorkingDirectory ( moduleNode.xmlFile->filename () ) );
 
-       path = FixSeparator ( modulePath );
+       const XMLAttribute* att = moduleNode.GetAttribute ( "name", true );
+       assert(att);
+       name = att->value;
 
        enabled = true;
 
-       const XMLAttribute* att = moduleNode.GetAttribute ( "if", false );
+       att = moduleNode.GetAttribute ( "if", false );
        if ( att != NULL )
                enabled = GetBooleanValue ( project.ResolveProperties ( att->value ) );
 
@@ -274,9 +270,8 @@ Module::Module ( const Project& project,
        if ( att != NULL )
                enabled = !GetBooleanValue ( project.ResolveProperties ( att->value ) );
 
-       att = moduleNode.GetAttribute ( "name", true );
-       assert(att);
-       name = att->value;
+       if ( !enabled && project.configuration.Verbose )
+               printf("Module '%s' has been disabled.\n", name.c_str () );
 
        att = moduleNode.GetAttribute ( "type", true );
        assert(att);
@@ -307,11 +302,35 @@ Module::Module ( const Project& project,
        else
                isUnicode = false;
 
+       if (isUnicode)
+       {
+               // Always define UNICODE and _UNICODE
+               Define* pDefine = new Define ( project, this, "UNICODE" );
+               non_if_data.defines.push_back ( pDefine );
+
+               pDefine = new Define ( project, this, "_UNICODE" );
+               non_if_data.defines.push_back ( pDefine );
+       }
+
        att = moduleNode.GetAttribute ( "entrypoint", false );
        if ( att != NULL )
+       {
+               if ( att->value == "" )
+               {
+                       throw InvalidAttributeValueException (
+                               moduleNode.location,
+                               "entrypoint",
+                               att->value );
+               }
+
                entrypoint = att->value;
+               isDefaultEntryPoint = false;
+       }
        else
+       {
                entrypoint = GetDefaultModuleEntrypoint ();
+               isDefaultEntryPoint = true;
+       }
 
        att = moduleNode.GetAttribute ( "baseaddress", false );
        if ( att != NULL )
@@ -338,6 +357,12 @@ Module::Module ( const Project& project,
        else
                mangledSymbols = false;
 
+       att = moduleNode.GetAttribute ( "underscoresymbols", false );
+       if ( att != NULL )
+               underscoreSymbols = att->value == "true";
+       else
+               underscoreSymbols = false;
+
        att = moduleNode.GetAttribute ( "host", false );
        if ( att != NULL )
        {
@@ -355,27 +380,69 @@ Module::Module ( const Project& project,
                }
        }
 
-       att = moduleNode.GetAttribute ( "prefix", false );
+       att = moduleNode.GetAttribute ( "isstartuplib", false );
        if ( att != NULL )
-               prefix = att->value;
+       {
+               const char* p = att->value.c_str();
+               if ( !stricmp ( p, "true" ) || !stricmp ( p, "yes" ) )
+                       isStartupLib = true;
+               else if ( !stricmp ( p, "false" ) || !stricmp ( p, "no" ) )
+                       isStartupLib = false;
+               else
+               {
+                       throw InvalidAttributeValueException (
+                               moduleNode.location,
+                               "host",
+                               att->value );
+               }
+       }
+       else
+               isStartupLib = false;
 
-       att = moduleNode.GetAttribute ( "installbase", false );
+       att = moduleNode.GetAttribute ( "prefix", false );
        if ( att != NULL )
-               installBase = att->value;
-       else
-               installBase = "";
+               prefix = att->value;
 
        att = moduleNode.GetAttribute ( "installname", false );
        if ( att != NULL )
-               installName = att->value;
-       else
-               installName = "";
-       
-       att = moduleNode.GetAttribute ( "usewrc", false );
+       {
+               const XMLAttribute* installbase = moduleNode.GetAttribute ( "installbase", false );
+               install = new FileLocation ( InstallDirectory,
+                                            installbase ? installbase->value : "",
+                                            att->value,
+                                            &moduleNode );
+
+               output = new FileLocation ( GetTargetDirectoryTree (),
+                                           modulePath,
+                                           att->value,
+                                           &moduleNode );
+       }
+
+       att = moduleNode.GetAttribute ( "output", false );
        if ( att != NULL )
-               useWRC = att->value == "true";
-       else
-               useWRC = true;
+       {
+               if (output != NULL)
+               {
+                       printf ( "%s: WARNING: 'installname' overrides 'output' also defined for this module.\n",
+                               moduleNode.location.c_str() );
+               }
+               else
+               {
+                       output = new FileLocation ( GetTargetDirectoryTree (),
+                                                                               modulePath,
+                                                                               att->value,
+                                                                               &moduleNode );
+               }
+       }
+
+       /* If no one has set the output file for this module set it automatically */
+       if (output == NULL)
+       {
+               output = new FileLocation ( GetTargetDirectoryTree (),
+                                                                       modulePath,
+                                                                       name + extension,
+                                                                       &moduleNode );
+       }
 
        att = moduleNode.GetAttribute ( "allowwarnings", false );
        if ( att == NULL )
@@ -403,6 +470,47 @@ Module::Module ( const Project& project,
                att = moduleNode.GetAttribute ( "payload", true );
                payload = att->value;
        }
+
+       if ( type == BootProgram || type == ElfExecutable )
+       {
+               att = moduleNode.GetAttribute ( "buildtype", false );
+               if ( att != NULL )
+               {
+                       buildtype = att->value;
+               }
+               else
+               {
+                       buildtype = "BOOTPROG";
+               }
+       }
+
+       att = moduleNode.GetAttribute ( "description", false );
+       if (att != NULL )
+       {
+               description = project.ResolveProperties(att->value);
+       }
+       else
+               description = "";
+
+       att = moduleNode.GetAttribute ( "lcid", false );
+       if (type == KeyboardLayout && att != NULL )
+               lcid = att->value;
+       else
+               lcid = "";
+
+       att = moduleNode.GetAttribute ( "layoutid", false );
+       if (type == KeyboardLayout && att != NULL )
+               layoutId = att->value;
+       else
+               layoutId = "";
+
+       att = moduleNode.GetAttribute ( "layoutnameresid", false );
+       if (type == KeyboardLayout && att != NULL )
+               layoutNameResId = att->value;
+       else
+               layoutNameResId = "";
+
+       SetImportLibrary ( NULL );
 }
 
 Module::~Module ()
@@ -422,6 +530,22 @@ Module::~Module ()
                delete linkerScript;
        if ( pch )
                delete pch;
+       if ( install )
+               delete install;
+       if ( metadata )
+               delete metadata;
+       if ( bootstrap )
+               delete bootstrap;
+       if ( importLibrary )
+               delete importLibrary;
+       if ( bootSector )
+               delete  bootSector;
+       if ( dependency )
+               delete  dependency;
+       if ( autoRegister )
+               delete autoRegister;
+       if ( output )
+               delete output;          
 }
 
 void
@@ -429,6 +553,7 @@ Module::ProcessXML()
 {
        if ( type == Alias )
        {
+               aliasedModuleName = project.ResolveProperties ( aliasedModuleName );
                if ( aliasedModuleName == name )
                {
                        throw XMLInvalidBuildFileException (
@@ -437,7 +562,7 @@ Module::ProcessXML()
                                name.c_str() );
                }
                const Module* m = project.LocateModule ( aliasedModuleName );
-               if ( !m )
+               if ( !m && enabled )
                {
                        throw XMLInvalidBuildFileException (
                                node.location,
@@ -451,7 +576,7 @@ Module::ProcessXML()
        for ( i = 0; i < node.subElements.size(); i++ )
        {
                ParseContext parseContext;
-               ProcessXMLSubElement ( *node.subElements[i], path, parseContext );
+               ProcessXMLSubElement ( *node.subElements[i], SourceDirectory, output->relative_path, parseContext );
        }
        for ( i = 0; i < invocations.size(); i++ )
                invocations[i]->ProcessXML ();
@@ -474,13 +599,14 @@ Module::ProcessXML()
 
 void
 Module::ProcessXMLSubElement ( const XMLElement& e,
-                               const string& path,
+                               DirectoryLocation directory,
+                                  const string& relative_path,
                                ParseContext& parseContext )
 {
-       If* pOldIf = parseContext.ifData;
        CompilationUnit* pOldCompilationUnit = parseContext.compilationUnit;
        bool subs_invalid = false;
-       string subpath ( path );
+       string subpath ( relative_path );
+       DirectoryLocation subdirectory = SourceDirectory;
        if ( e.name == "file" && e.value.size () > 0 )
        {
                bool first = false;
@@ -511,123 +637,146 @@ Module::ProcessXMLSubElement ( const XMLElement& e,
                        else if ( !stricmp ( ext.c_str(), ".cxx" ) )
                                cplusplus = true;
                }
-               File* pFile = new File ( FixSeparator ( path + cSep + e.value ),
+               File* pFile = new File ( directory,
+                                        relative_path,
+                                        e.value,
                                         first,
                                         switches,
                                         false );
                if ( parseContext.compilationUnit )
-                       parseContext.compilationUnit->files.push_back ( pFile );
+                       parseContext.compilationUnit->AddFile ( pFile );
                else
                {
                        CompilationUnit* pCompilationUnit = new CompilationUnit ( pFile );
-                       if ( parseContext.ifData )
-                               parseContext.ifData->data.compilationUnits.push_back ( pCompilationUnit );
-                       else
+                       string ext = ToLower ( GetExtension ( e.value ) );
+                       if ( ext == ".idl" )
+                       {
+                               // put .idl files at the start of the module
+                               non_if_data.compilationUnits.insert (
+                                       non_if_data.compilationUnits.begin(),
+                                       pCompilationUnit );
+                       }
+                       else if ( ext == ".asm" || ext == ".s" )
+                       {
+                               // put .asm files at the end of the module
                                non_if_data.compilationUnits.push_back ( pCompilationUnit );
+                               non_if_data.asmFiles++;
+                       }
+                       else
+                       {
+                               // put other files in the middle
+                               non_if_data.compilationUnits.insert (
+                                       non_if_data.compilationUnits.end() - non_if_data.asmFiles,
+                                       pCompilationUnit );
+                       }
                }
-               if ( parseContext.ifData )
-                       parseContext.ifData->data.files.push_back ( pFile );
-               else
-                       non_if_data.files.push_back ( pFile );
+               non_if_data.files.push_back ( pFile );
                subs_invalid = true;
        }
        else if ( e.name == "library" && e.value.size () )
        {
                Library* pLibrary = new Library ( e, *this, e.value );
-               if ( parseContext.ifData )
-                       parseContext.ifData->data.libraries.push_back ( pLibrary );
-               else
-                       non_if_data.libraries.push_back ( pLibrary );
+               non_if_data.libraries.push_back ( pLibrary );
                subs_invalid = true;
        }
        else if ( e.name == "directory" )
        {
                const XMLAttribute* att = e.GetAttribute ( "name", true );
+               const XMLAttribute* root = e.GetAttribute ( "root", false );
                assert(att);
-               subpath = GetSubPath ( e.location, path, att->value );
+               if ( root )
+               {
+                       if ( root->value == "intermediate" )
+                               subdirectory = IntermediateDirectory;
+                       else if ( root->value == "output" )
+                               subdirectory = OutputDirectory;
+                       else
+                       {
+                               throw InvalidAttributeValueException (
+                                       e.location,
+                                       "root",
+                                       root->value );
+                       }
+               }
+               subpath = GetSubPath ( this->project, e.location, relative_path, att->value );
        }
        else if ( e.name == "include" )
        {
-               Include* include = new Include ( project, this, &e );
-               if ( parseContext.ifData )
-                       parseContext.ifData->data.includes.push_back ( include );
-               else
-                       non_if_data.includes.push_back ( include );
+               Include* include = new Include ( project, &e, this );
+               non_if_data.includes.push_back ( include );
                subs_invalid = true;
        }
        else if ( e.name == "define" )
        {
                Define* pDefine = new Define ( project, this, e );
-               if ( parseContext.ifData )
-                       parseContext.ifData->data.defines.push_back ( pDefine );
-               else
-                       non_if_data.defines.push_back ( pDefine );
+               non_if_data.defines.push_back ( pDefine );
                subs_invalid = true;
        }
+       else if ( e.name == "metadata" )
+       {
+               metadata = new Metadata ( e, *this );
+               subs_invalid = false;
+       }
        else if ( e.name == "invoke" )
        {
-               if ( parseContext.ifData )
-               {
-                       throw XMLInvalidBuildFileException (
-                               e.location,
-                               "<invoke> is not a valid sub-element of <if>" );
-               }
                invocations.push_back ( new Invoke ( e, *this ) );
                subs_invalid = false;
        }
        else if ( e.name == "dependency" )
        {
-               if ( parseContext.ifData )
-               {
-                       throw XMLInvalidBuildFileException (
-                               e.location,
-                               "<dependency> is not a valid sub-element of <if>" );
-               }
                dependencies.push_back ( new Dependency ( e, *this ) );
                subs_invalid = true;
        }
+       else if ( e.name == "bootsector" )
+       {
+               bootSector = new Bootsector ( e, this );
+               subs_invalid = true;
+       }
        else if ( e.name == "importlibrary" )
        {
-               if ( parseContext.ifData )
-               {
-                       throw XMLInvalidBuildFileException (
-                               e.location,
-                               "<importlibrary> is not a valid sub-element of <if>" );
-               }
                if ( importLibrary )
                {
                        throw XMLInvalidBuildFileException (
                                e.location,
                                "Only one <importlibrary> is valid per module" );
                }
-               importLibrary = new ImportLibrary ( e, *this );
+               SetImportLibrary ( new ImportLibrary ( project, e, this ) );
                subs_invalid = true;
        }
-       else if ( e.name == "if" )
+       else if ( e.name == "if" || e.name == "ifnot" )
        {
-               parseContext.ifData = new If ( e, project, this );
-               if ( pOldIf )
-                       pOldIf->data.ifs.push_back ( parseContext.ifData );
-               else
-                       non_if_data.ifs.push_back ( parseContext.ifData );
-               subs_invalid = false;
-       }
-       else if ( e.name == "ifnot" )
-       {
-               parseContext.ifData = new If ( e, project, this, true );
-               if ( pOldIf )
-                       pOldIf->data.ifs.push_back ( parseContext.ifData );
-               else
-                       non_if_data.ifs.push_back ( parseContext.ifData );
+               const XMLAttribute* name;
+               name = e.GetAttribute ( "property", true );
+               assert( name );
+               const Property *property = project.LookupProperty( name->value );
+               if ( !property )
+               {
+                       // Property not found
+                       throw InvalidOperationException ( __FILE__,
+                                                         __LINE__,
+                                                         "Test on unknown property '%s' at %s",
+                                                         name->value.c_str (), e.location.c_str () );
+               }
+
+               const XMLAttribute* value;
+               value = e.GetAttribute ( "value", true );
+               assert( value );
+
+               bool negate = ( e.name == "ifnot" );
+               bool equality = ( property->value == value->value );
+               if ( equality == negate )
+               {
+                       // Failed, skip this element
+                       if ( project.configuration.Verbose )
+                               printf("Skipping 'If' at %s\n", e.location.c_str () );
+                       return;
+               }
                subs_invalid = false;
        }
        else if ( e.name == "compilerflag" )
        {
                CompilerFlag* pCompilerFlag = new CompilerFlag ( project, this, e );
-               if ( parseContext.ifData )
-                       parseContext.ifData->data.compilerFlags.push_back ( pCompilerFlag );
-               else
-                       non_if_data.compilerFlags.push_back ( pCompilerFlag );
+               non_if_data.compilerFlags.push_back ( pCompilerFlag );
                subs_invalid = true;
        }
        else if ( e.name == "linkerflag" )
@@ -643,7 +792,19 @@ Module::ProcessXMLSubElement ( const XMLElement& e,
                                e.location,
                                "Only one <linkerscript> is valid per module" );
                }
-               linkerScript = new LinkerScript ( project, this, e );
+               size_t pos = e.value.find_last_of ( "/\\" );
+               if ( pos == string::npos )
+               {
+                       linkerScript = new LinkerScript (
+                               e, *this, new FileLocation ( SourceDirectory, relative_path, e.value, &e ) );
+               }
+               else
+               {
+                       string dir = e.value.substr ( 0, pos );
+                       string name = e.value.substr ( pos + 1);
+                       linkerScript = new LinkerScript (
+                               e, *this, new FileLocation ( SourceDirectory, relative_path + sSep + dir, name, &e ) );
+               }
                subs_invalid = true;
        }
        else if ( e.name == "component" )
@@ -664,20 +825,25 @@ Module::ProcessXMLSubElement ( const XMLElement& e,
        }
        else if ( e.name == "pch" )
        {
-               if ( parseContext.ifData )
-               {
-                       throw XMLInvalidBuildFileException (
-                               e.location,
-                               "<pch> is not a valid sub-element of <if>" );
-               }
                if ( pch )
                {
                        throw XMLInvalidBuildFileException (
                                e.location,
                                "Only one <pch> is valid per module" );
                }
-               pch = new PchFile (
-                       e, *this, File ( FixSeparator ( path + cSep + e.value ), false, "", true ) );
+               size_t pos = e.value.find_last_of ( "/\\" );
+               if ( pos == string::npos )
+               {
+                       pch = new PchFile (
+                               e, *this, new FileLocation ( SourceDirectory, relative_path, e.value, &e ) );
+               }
+               else
+               {
+                       string dir = e.value.substr ( 0, pos );
+                       string name = e.value.substr ( pos + 1);
+                       pch = new PchFile (
+                               e, *this, new FileLocation ( SourceDirectory, relative_path + sSep + dir, name, &e ) );
+               }
                subs_invalid = true;
        }
        else if ( e.name == "compilationunit" )
@@ -685,10 +851,7 @@ Module::ProcessXMLSubElement ( const XMLElement& e,
                if ( project.configuration.CompilationUnitsEnabled )
                {
                        CompilationUnit* pCompilationUnit = new CompilationUnit ( &project, this, &e );
-                       if ( parseContext.ifData )
-                               parseContext.ifData->data.compilationUnits.push_back ( pCompilationUnit );
-                       else
-                               non_if_data.compilationUnits.push_back ( pCompilationUnit );
+                       non_if_data.compilationUnits.push_back ( pCompilationUnit );
                        parseContext.compilationUnit = pCompilationUnit;
                }
                subs_invalid = false;
@@ -713,8 +876,7 @@ Module::ProcessXMLSubElement ( const XMLElement& e,
                        e.name.c_str() );
        }
        for ( size_t i = 0; i < e.subElements.size (); i++ )
-               ProcessXMLSubElement ( *e.subElements[i], subpath, parseContext );
-       parseContext.ifData = pOldIf;
+               ProcessXMLSubElement ( *e.subElements[i], subdirectory, subpath, parseContext );
        parseContext.compilationUnit = pOldCompilationUnit;
 }
 
@@ -725,22 +887,26 @@ Module::GetModuleType ( const string& location, const XMLAttribute& attribute )
                return BuildTool;
        if ( attribute.value == "staticlibrary" )
                return StaticLibrary;
+       if ( attribute.value == "hoststaticlibrary" )
+               return HostStaticLibrary;
        if ( attribute.value == "objectlibrary" )
                return ObjectLibrary;
        if ( attribute.value == "kernel" )
                return Kernel;
        if ( attribute.value == "kernelmodedll" )
                return KernelModeDLL;
-    if ( attribute.value == "exportdriver" )
-        return ExportDriver;
        if ( attribute.value == "kernelmodedriver" )
                return KernelModeDriver;
        if ( attribute.value == "nativedll" )
                return NativeDLL;
        if ( attribute.value == "nativecui" )
                return NativeCUI;
+       if ( attribute.value == "keyboardlayout" )
+               return KeyboardLayout;
        if ( attribute.value == "win32dll" )
                return Win32DLL;
+       if ( attribute.value == "win32ocx" )
+               return Win32OCX;
        if ( attribute.value == "win32cui" )
                return Win32CUI;
        if ( attribute.value == "win32gui" )
@@ -767,15 +933,73 @@ Module::GetModuleType ( const string& location, const XMLAttribute& attribute )
                return RpcServer;
        if ( attribute.value == "rpcclient" )
                return RpcClient;
+       if ( attribute.value == "rpcproxy" )
+               return RpcProxy;
        if ( attribute.value == "alias" )
                return Alias;
        if ( attribute.value == "idlheader" )
                return IdlHeader;
+       if ( attribute.value == "embeddedtypelib" )
+               return EmbeddedTypeLib;
+       if ( attribute.value == "elfexecutable" )
+               return ElfExecutable;
+       if ( attribute.value == "cabinet" )
+               return Cabinet;
+       if ( attribute.value == "messageheader" )
+               return MessageHeader;
        throw InvalidAttributeValueException ( location,
                                               attribute.name,
                                               attribute.value );
 }
 
+DirectoryLocation
+Module::GetTargetDirectoryTree () const
+{
+       switch ( type )
+       {
+               case Kernel:
+               case KernelModeDLL:
+               case KeyboardLayout:
+               case NativeDLL:
+               case Win32DLL:
+               case Win32OCX:
+               case KernelModeDriver:
+               case NativeCUI:
+               case Win32CUI:
+               case Test:
+               case Win32SCR:
+               case Win32GUI:
+               case BuildTool:
+               case BootLoader:
+               case BootSector:
+               case BootProgram:
+               case Iso:
+               case LiveIso:
+               case IsoRegTest:
+               case LiveIsoRegTest:
+               case ElfExecutable:
+               case Cabinet:
+                       return OutputDirectory;
+               case EmbeddedTypeLib:
+               case StaticLibrary:
+               case HostStaticLibrary:
+               case ObjectLibrary:
+               case RpcServer:
+               case RpcClient:
+               case RpcProxy:
+               case Alias:
+               case IdlHeader:
+               case MessageHeader:
+                       return IntermediateDirectory;
+               case TypeDontCare:
+                       break;
+       }
+       throw InvalidOperationException ( __FILE__,
+                                         __LINE__,
+                                         "Invalid module type %d.",
+                                         type );
+}
+
 string
 Module::GetDefaultModuleExtension () const
 {
@@ -783,7 +1007,9 @@ Module::GetDefaultModuleExtension () const
        {
                case BuildTool:
                        return ExePostfix;
+               case BootProgram:
                case StaticLibrary:
+               case HostStaticLibrary:
                        return ".a";
                case ObjectLibrary:
                        return ".o";
@@ -797,12 +1023,16 @@ Module::GetDefaultModuleExtension () const
 
                case KernelModeDLL:
                case NativeDLL:
+               case KeyboardLayout:
                case Win32DLL:
                        return ".dll";
+               case Win32OCX:
+                       return ".ocx";
                case KernelModeDriver:
                case BootLoader:
-        case ExportDriver:
                        return ".sys";
+               case Cabinet:
+                       return ".cab";
                case BootSector:
                        return ".o";
                case Iso:
@@ -813,13 +1043,18 @@ Module::GetDefaultModuleExtension () const
                case Test:
                        return ".exe";
                case RpcServer:
-                       return ".o";
                case RpcClient:
+               case RpcProxy:
                        return ".o";
                case Alias:
-               case BootProgram:
+               case ElfExecutable:
                case IdlHeader:
+               case MessageHeader:
                        return "";
+               case EmbeddedTypeLib:
+                       return ".tlb";
+               case TypeDontCare:
+                       break;
        }
        throw InvalidOperationException ( __FILE__,
                                          __LINE__ );
@@ -831,16 +1066,21 @@ Module::GetDefaultModuleEntrypoint () const
        switch ( type )
        {
                case Kernel:
-                       return "NtProcessStartup";
+                       return "KiSystemStartup";
+               case KeyboardLayout:
                case KernelModeDLL:
-        case KernelModeDriver:
-        case ExportDriver:
+               case KernelModeDriver:
+            if (Environment::GetArch() == "arm") return "DriverEntry";
                        return "DriverEntry@8";
                case NativeDLL:
-                       return "DllMainCRTStartup@12";
+            if (Environment::GetArch() == "arm") return "DllMainCRTStartup";
+            return "DllMainCRTStartup@12";
                case NativeCUI:
-                       return "NtProcessStartup@4";
+            if (Environment::GetArch() == "arm") return "NtProcessStartup";
+            return "NtProcessStartup@4";            
                case Win32DLL:
+               case Win32OCX:
+            if (Environment::GetArch() == "arm") return "DllMain";
                        return "DllMain@12";
                case Win32CUI:
                case Test:
@@ -856,6 +1096,7 @@ Module::GetDefaultModuleEntrypoint () const
                                return "WinMainCRTStartup";
                case BuildTool:
                case StaticLibrary:
+               case HostStaticLibrary:
                case ObjectLibrary:
                case BootLoader:
                case BootSector:
@@ -865,10 +1106,17 @@ Module::GetDefaultModuleEntrypoint () const
                case LiveIsoRegTest:
                case RpcServer:
                case RpcClient:
+               case RpcProxy:
                case Alias:
                case BootProgram:
                case IdlHeader:
+               case MessageHeader:
+               case ElfExecutable:
+               case EmbeddedTypeLib:
+               case Cabinet:
                        return "";
+               case TypeDontCare:
+                       break;
        }
        throw InvalidOperationException ( __FILE__,
                                          __LINE__ );
@@ -880,8 +1128,9 @@ Module::GetDefaultModuleBaseaddress () const
        switch ( type )
        {
                case Kernel:
-                       return "0x80000000";
+                       return "0x80800000";
                case Win32DLL:
+               case Win32OCX:
                        return "0x10000000";
                case NativeDLL:
                case NativeCUI:
@@ -891,12 +1140,15 @@ Module::GetDefaultModuleBaseaddress () const
                case Win32SCR:
                case Win32GUI:
                        return "0x00400000";
+               case KeyboardLayout:
                case KernelModeDLL:
                case KernelModeDriver:
-        case ExportDriver:
                        return "0x00010000";
+               case ElfExecutable:
+                       return "0xe00000";
                case BuildTool:
                case StaticLibrary:
+               case HostStaticLibrary:
                case ObjectLibrary:
                case BootLoader:
                case BootSector:
@@ -906,10 +1158,16 @@ Module::GetDefaultModuleBaseaddress () const
                case LiveIsoRegTest:
                case RpcServer:
                case RpcClient:
+               case RpcProxy:
                case Alias:
                case BootProgram:
                case IdlHeader:
+               case MessageHeader:
+               case EmbeddedTypeLib:
+               case Cabinet:
                        return "";
+               case TypeDontCare:
+                       break;
        }
        throw InvalidOperationException ( __FILE__,
                                          __LINE__ );
@@ -918,7 +1176,7 @@ Module::GetDefaultModuleBaseaddress () const
 bool
 Module::HasImportLibrary () const
 {
-       return importLibrary != NULL;
+       return importLibrary != NULL && type != StaticLibrary && type != HostStaticLibrary;
 }
 
 bool
@@ -928,11 +1186,12 @@ Module::IsDLL () const
        {
                case Kernel:
                case KernelModeDLL:
-        case ExportDriver:
                case NativeDLL:
+               case KeyboardLayout:
                case Win32DLL:
-            return true;
+               case Win32OCX:
                case KernelModeDriver:
+                       return true;
                case NativeCUI:
                case Win32CUI:
                case Test:
@@ -940,6 +1199,7 @@ Module::IsDLL () const
                case Win32GUI:
                case BuildTool:
                case StaticLibrary:
+               case HostStaticLibrary:
                case ObjectLibrary:
                case BootLoader:
                case BootSector:
@@ -950,91 +1210,31 @@ Module::IsDLL () const
                case LiveIsoRegTest:
                case RpcServer:
                case RpcClient:
+               case RpcProxy:
                case Alias:
                case IdlHeader:
+               case MessageHeader:
+               case EmbeddedTypeLib:
+               case ElfExecutable:
+               case Cabinet:
                        return false;
+               case TypeDontCare:
+                       break;
        }
        throw InvalidOperationException ( __FILE__,
                                          __LINE__ );
 }
 
-bool
-Module::GenerateInOutputTree () const
-{
-       switch ( type )
-       {
-               case Kernel:
-               case KernelModeDLL:
-        case ExportDriver:
-               case NativeDLL:
-               case Win32DLL:
-               case KernelModeDriver:
-               case NativeCUI:
-               case Win32CUI:
-               case Test:
-               case Win32SCR:
-               case Win32GUI:
-               case BuildTool:
-               case BootLoader:
-               case BootSector:
-               case BootProgram:
-               case Iso:
-               case LiveIso:
-               case IsoRegTest:
-               case LiveIsoRegTest:
-                       return true;
-               case StaticLibrary:
-               case ObjectLibrary:
-               case RpcServer:
-               case RpcClient:
-               case Alias:
-               case IdlHeader:
-                       return false;
-       }
-       throw InvalidOperationException ( __FILE__,
-                                         __LINE__ );
-}
-
-string
-Module::GetTargetName () const
-{
-       return name + extension;
-}
-
-string
-Module::GetDependencyPath () const
-{
-       if ( HasImportLibrary () )
-               return ReplaceExtension ( GetPathWithPrefix ( "lib" ), ".a" );
-       else
-               return GetPath();
-}
-
-string
-Module::GetBasePath () const
-{
-       return path;
-}
-
-string
-Module::GetPath () const
-{
-       if ( path.length() > 0 )
-               return path + cSep + GetTargetName ();
-       else
-               return GetTargetName ();
-}
-
 string
 Module::GetPathWithPrefix ( const string& prefix ) const
 {
-       return path + cSep + prefix + GetTargetName ();
+       return output->relative_path + cSep + prefix + output->name;
 }
 
 string
 Module::GetPathToBaseDir () const
 {
-       string temp_path = path;
+       string temp_path = output->relative_path;
        string result = "..\\";
        while(temp_path.find ('\\') != string::npos)
        {
@@ -1056,10 +1256,20 @@ string
 Module::GetEntryPoint(bool leadingUnderscore) const
 {
        string result = "";
+       if (entrypoint == "0" || entrypoint == "0x0")
+               return "0";
        if (leadingUnderscore)
                result = "_";
 
        result += entrypoint;
+
+       if (Environment::GetArch() == "amd64")
+       {
+               size_t at_index = result.find_last_of( '@' );
+               if ( at_index != result.npos )
+                       return result.substr (0, at_index );
+       }
+
        return result;
 }
 
@@ -1075,11 +1285,6 @@ Module::HasFileWithExtension (
                if ( compilationUnit->HasFileWithExtension ( extension ) )
                        return true;
        }
-       for ( i = 0; i < data.ifs.size (); i++ )
-       {
-               if ( HasFileWithExtension ( data.ifs[i]->data, extension ) )
-                       return true;
-       }
        return false;
 }
 
@@ -1089,7 +1294,7 @@ Module::InvokeModule () const
        for ( size_t i = 0; i < invocations.size (); i++ )
        {
                Invoke& invoke = *invocations[i];
-               string command = FixSeparatorForSystemCommand(invoke.invokeModule->GetPath ()) + " " + invoke.GetParameters ();
+               string command = FixSeparatorForSystemCommand(invoke.invokeModule->output->relative_path + "/" + invoke.invokeModule->output->name ) + " " + invoke.GetParameters ();
                printf ( "Executing '%s'\n\n", command.c_str () );
                int exitcode = system ( command.c_str () );
                if ( exitcode != 0 )
@@ -1099,26 +1304,65 @@ Module::InvokeModule () const
 }
 
 
-File::File ( const string& _name, bool _first,
-             std::string _switches,
+void
+Module::SetImportLibrary ( ImportLibrary* importLibrary )
+{
+       this->importLibrary = importLibrary;
+       dependency = new FileLocation ( HasImportLibrary () ? IntermediateDirectory : output->directory,
+                                       output->relative_path,
+                                       HasImportLibrary () ? "lib" + name + ".a" : output->name );
+}
+
+
+File::File ( DirectoryLocation directory,
+             const string& relative_path,
+             const string& name,
+             bool _first,
+             const string& _switches,
              bool _isPreCompiledHeader )
-       : name(_name),
+       : file ( directory, relative_path, name ),
          first(_first),
          switches(_switches),
          isPreCompiledHeader(_isPreCompiledHeader)
 {
 }
 
+
 void
 File::ProcessXML()
 {
 }
 
 
+std::string File::GetFullPath () const
+{
+       string directory ( "" );
+       switch ( file.directory )
+       {
+               case SourceDirectory:
+                       break;
+               case IntermediateDirectory:
+                       directory = Environment::GetIntermediatePath () + sSep;
+                       break;
+               default:
+                       throw InvalidOperationException ( __FILE__,
+                                                         __LINE__,
+                                                         "Invalid directory %d.",
+                                                         file.directory );
+       }
+
+       if ( file.relative_path.length () > 0 )
+               directory += file.relative_path + sSep;
+
+
+       return directory + file.name;
+}
+
+
 Library::Library ( const XMLElement& _node,
                    const Module& _module,
                    const string& _name )
-       : node(_node),
+       : node(&_node),
          module(_module),
          name(_name),
          importedModule(_module.project.LocateModule(_name))
@@ -1126,27 +1370,36 @@ Library::Library ( const XMLElement& _node,
        if ( module.name == name )
        {
                throw XMLInvalidBuildFileException (
-                       node.location,
+                       node->location,
                        "module '%s' cannot link against itself",
                        name.c_str() );
        }
        if ( !importedModule )
        {
                throw XMLInvalidBuildFileException (
-                       node.location,
+                       node->location,
                        "module '%s' trying to import non-existant module '%s'",
                        module.name.c_str(),
                        name.c_str() );
        }
 }
 
+Library::Library ( const Module& _module,
+                   const string& _name )
+       : node(NULL),
+         module(_module),
+         name(_name),
+         importedModule(_module.project.LocateModule(_name))
+{
+}
+
 void
 Library::ProcessXML()
 {
-       if ( !module.project.LocateModule ( name ) )
+       if ( node && !module.project.LocateModule ( name ) )
        {
                throw XMLInvalidBuildFileException (
-                       node.location,
+                       node->location,
                        "module '%s' is trying to link against non-existant module '%s'",
                        module.name.c_str(),
                        name.c_str() );
@@ -1214,7 +1467,7 @@ Invoke::ProcessXMLSubElementInput ( const XMLElement& e )
        if ( e.name == "inputfile" && e.value.size () > 0 )
        {
                input.push_back ( new InvokeFile (
-                       e, FixSeparator ( module.path + cSep + e.value ) ) );
+                       e, FixSeparator ( module.output->relative_path + cSep + e.value ) ) );
                subs_invalid = true;
        }
        if ( subs_invalid && e.subElements.size() > 0 )
@@ -1233,7 +1486,7 @@ Invoke::ProcessXMLSubElementOutput ( const XMLElement& e )
        if ( e.name == "outputfile" && e.value.size () > 0 )
        {
                output.push_back ( new InvokeFile (
-                       e, FixSeparator ( module.path + cSep + e.value ) ) );
+                       e, FixSeparator ( module.output->relative_path + cSep + e.value ) ) );
                subs_invalid = true;
        }
        if ( subs_invalid && e.subElements.size() > 0 )
@@ -1329,66 +1582,238 @@ Dependency::ProcessXML()
        }
 }
 
+Bootsector::Bootsector ( const XMLElement& _node,
+                         const Module* _module )
+       : node (_node),
+         module (_module),
+         bootSectorModule (NULL)
+{
+       if ( !IsSupportedModuleType ( module->type ) )
+       {
+               throw XMLInvalidBuildFileException (
+                       node.location,
+                       "<bootsector> is not applicable for this module type." );
+       }
+
+       bootSectorModule = module->project.LocateModule ( node.value );
+       if ( bootSectorModule == NULL )
+       {
+               throw XMLInvalidBuildFileException (
+                       node.location,
+                       "module '%s' depend on non-existant module '%s'",
+                       module->name.c_str(),
+                       node.value.c_str() );
+       }
 
-ImportLibrary::ImportLibrary ( const XMLElement& _node,
-                               const Module& _module )
+       if (bootSectorModule->type != BootSector)
+       {
+               throw XMLInvalidBuildFileException (
+                       node.location,
+                       "module '%s' is referencing non BootSector module '%s'",
+                       module->name.c_str(),
+                       node.value.c_str() );
+       }
+}
+
+void
+Bootsector::ProcessXML()
+{
+}
+
+bool
+Bootsector::IsSupportedModuleType ( ModuleType type )
+{
+       if ( type == Iso ||
+            type == LiveIso ||
+            type == IsoRegTest ||
+                type == LiveIsoRegTest )
+       {
+               return true;
+       }
+
+       return false;
+}
+
+Metadata::Metadata ( const XMLElement& _node,
+                     const Module& _module )
        : node (_node),
          module (_module)
 {
-       const XMLAttribute* att = _node.GetAttribute ( "basename", false );
+       /* The module name */
+       const XMLAttribute* att = _node.GetAttribute ( "name", false );
        if (att != NULL)
-               basename = att->value;
+               name = att->value;
        else
-               basename = module.name;
+               name = module.name;
 
-       att = _node.GetAttribute ( "definition", true );
-       assert (att);
-       definition = FixSeparator(att->value);
-}
+       /* The module description */
+       att = _node.GetAttribute ( "description", false );
+       if (att != NULL)
+               description = att->value;
+       else
+               description = "";
 
+       /* The module version */
+       att = _node.GetAttribute ( "version", false );
+       if (att != NULL)
+               version = att->value;
+       else
+               version = "";
 
-If::If ( const XMLElement& node_,
-         const Project& project_,
-         const Module* module_,
-         const bool negated_ )
-       : node(node_), project(project_), module(module_), negated(negated_)
-{
-       const XMLAttribute* att;
+       /* The module copyright */
+       att = _node.GetAttribute ( "copyright", false );
+       if (att != NULL)
+               copyright = att->value;
+       else
+               copyright = "";
 
-       att = node.GetAttribute ( "property", true );
-       assert(att);
-       property = att->value;
+       att = _node.GetAttribute ( "url", false );
+       if (att != NULL)
+               url = att->value;
+       else
+               url = "";
 
-       att = node.GetAttribute ( "value", true );
-       assert(att);
-       value = att->value;
+       /* When was this module updated */
+       att = _node.GetAttribute ( "date", false );
+       if (att != NULL)
+               date = att->value;
+       else
+               date = "?";
+
+       /* When was this module updated */
+       att = _node.GetAttribute ( "owner", false );
+       if (att != NULL)
+               owner = att->value;
+       else
+               owner = "ReactOS";
 }
 
-If::~If ()
+
+ImportLibrary::~ImportLibrary ()
 {
+       delete source;
 }
 
-void
-If::ProcessXML()
+
+ImportLibrary::ImportLibrary ( const Project& project,
+                               const XMLElement& node,
+                               const Module* module )
+       : XmlNode ( project, node ),
+         module (module)
 {
-       
+       DirectoryLocation directory = SourceDirectory;
+       const Module* base = module;
+       const XMLAttribute* dllname = node.GetAttribute ( "dllname", false );
+       const XMLAttribute* definition = node.GetAttribute ( "definition", true );
+       assert ( definition );
+
+       string relative_path;
+       const XMLAttribute* att = node.GetAttribute ( "base", false );
+       if ( att )
+       {
+                       base = project.LocateModule ( att->value );
+                       if ( !base )
+                               throw XMLInvalidBuildFileException (
+                                       node.location,
+                                       "<importlibrary> attribute 'base' references non-existant module '%s'",
+                                       att->value.c_str() );
+
+       }
+
+       if ( base )
+       {
+               relative_path = base->output->relative_path;
+               if ( node.value.length () > 0 && node.value != "." )
+                       relative_path += sSep + node.value;
+       }
+       else
+               relative_path = node.value;
+
+       att = node.GetAttribute ( "root", false );
+       if ( att )
+       {
+               if ( att->value == "intermediate" )
+                       directory = IntermediateDirectory;
+               else
+                       throw InvalidAttributeValueException ( node.location,
+                                                              "root",
+                                                              att->value );
+       }
+       else
+       {
+               size_t index = definition->value.rfind ( ".spec.def" );
+               if ( index != string::npos )
+                       directory = IntermediateDirectory;
+       }
+
+       if ( dllname )
+               this->dllname = dllname->value;
+       else if ( module->type == StaticLibrary || module->type == HostStaticLibrary )
+               throw XMLInvalidBuildFileException (
+                   node.location,
+                   "<importlibrary> dllname attribute required." );
+
+       size_t index = definition->value.find_last_of ( "/\\" );
+       if ( index == string::npos )
+       {
+               source = new FileLocation ( directory,
+                                           base->output->relative_path,
+                                           definition->value,
+                                           &node );
+       }
+       else
+       {
+               string dir = definition->value.substr ( 0, index );
+               string name = definition->value.substr ( index + 1);
+               source = new FileLocation ( directory,
+                                           NormalizeFilename ( base->output->relative_path + sSep + dir ),
+                                           name,
+                                           &node );
+       }
 }
 
 
 Property::Property ( const XMLElement& node_,
                      const Project& project_,
                      const Module* module_ )
-       : node(node_), project(project_), module(module_)
+       : project(project_), module(module_)
 {
        const XMLAttribute* att;
 
-       att = node.GetAttribute ( "name", true );
+       att = node_.GetAttribute ( "name", true );
        assert(att);
-       name = att->value;
+       name = project.ResolveProperties ( att->value );
 
-       att = node.GetAttribute ( "value", true );
+       att = node_.GetAttribute ( "value", true );
        assert(att);
        value = att->value;
+
+       att = node_.GetAttribute ( "internal", false );
+       if ( att != NULL )
+       {
+               const char* p = att->value.c_str();
+               if ( !stricmp ( p, "true" ) || !stricmp ( p, "yes" ) )
+                       isInternal = true;
+               else if ( !stricmp ( p, "false" ) || !stricmp ( p, "no" ) )
+                       isInternal = false;
+               else
+               {
+                       throw InvalidAttributeValueException (
+                               node_.location,
+                               "internal",
+                               att->value );
+               }
+       }
+       else
+               isInternal = false;
+}
+
+Property::Property ( const Project& project_,
+                     const Module* module_,
+                     const std::string& name_,
+                     const std::string& value_ )
+       : project(project_), module(module_), name(name_), value(value_)
+{
 }
 
 void
@@ -1400,100 +1825,17 @@ Property::ProcessXML()
 PchFile::PchFile (
        const XMLElement& node_,
        const Module& module_,
-       const File file_ )
+       const FileLocation *file_ )
        : node(node_), module(module_), file(file_)
 {
 }
 
-void
-PchFile::ProcessXML()
-{
-}
-
-
-AutoRegister::AutoRegister ( const Project& project_,
-                             const Module* module_,
-                             const XMLElement& node_ )
-       : project(project_),
-         module(module_),
-         node(node_)
+PchFile::~PchFile()
 {
-       Initialize();
-}
-
-AutoRegister::~AutoRegister ()
-{
-}
-
-bool
-AutoRegister::IsSupportedModuleType ( ModuleType type )
-{
-       switch ( type )
-       {
-               case Win32DLL:
-                       return true;
-               case Kernel:
-               case KernelModeDLL:
-        case ExportDriver:
-               case NativeDLL:
-               case NativeCUI:
-               case Win32CUI:
-               case Win32GUI:
-               case Win32SCR:
-               case KernelModeDriver:
-               case BootSector:
-               case BootLoader:
-               case BootProgram:
-               case BuildTool:
-               case StaticLibrary:
-               case ObjectLibrary:
-               case Iso:
-               case LiveIso:
-               case IsoRegTest:
-               case LiveIsoRegTest:
-               case Test:
-               case RpcServer:
-               case RpcClient:
-               case Alias:
-               case IdlHeader:
-                       return false;
-       }
-       throw InvalidOperationException ( __FILE__,
-                                         __LINE__ );
-}
-
-AutoRegisterType
-AutoRegister::GetAutoRegisterType( string type )
-{
-       if ( type == "DllRegisterServer" )
-               return DllRegisterServer;
-       if ( type == "DllInstall" )
-               return DllInstall;
-       if ( type == "Both" )
-               return Both;
-       throw XMLInvalidBuildFileException (
-               node.location,
-               "<autoregister> type attribute must be DllRegisterServer, DllInstall or Both." );
+       delete file;
 }
 
 void
-AutoRegister::Initialize ()
-{
-       if ( !IsSupportedModuleType ( module->type ) )
-       {
-               throw XMLInvalidBuildFileException (
-                       node.location,
-                       "<autoregister> is not applicable for this module type." );
-       }
-
-       const XMLAttribute* att = node.GetAttribute ( "infsection", true );
-       infSection = att->value;
-
-       att = node.GetAttribute ( "type", true );
-       type = GetAutoRegisterType ( att->value );
-}
-
-void
-AutoRegister::ProcessXML()
+PchFile::ProcessXML()
 {
 }