Revert r34346, it didn't work the way I thought because of different CRT's on every...
[reactos.git] / reactos / tools / rbuild / backend / mingw / modulehandler.cpp
index 5637022..2a06f29 100644 (file)
@@ -30,6 +30,7 @@ using std::string;
 using std::vector;
 
 #define CLEAN_FILE(f) clean_files.push_back ( (f).name.length () > 0 ? backend->GetFullName ( f ) : backend->GetFullPath ( f ) );
+#define IsStaticLibrary( module ) ( ( module.type == StaticLibrary ) || ( module.type == HostStaticLibrary ) )
 
 MingwBackend*
 MingwModuleHandler::backend = NULL;
@@ -170,6 +171,9 @@ MingwModuleHandler::InstanciateHandler (
                case StaticLibrary:
                        handler = new MingwStaticLibraryModuleHandler ( module );
                        break;
+               case HostStaticLibrary:
+                       handler = new MingwHostStaticLibraryModuleHandler ( module );
+                       break;
                case ObjectLibrary:
                        handler = new MingwObjectLibraryModuleHandler ( module );
                        break;
@@ -186,6 +190,7 @@ MingwModuleHandler::InstanciateHandler (
                case Win32GUI:
                        handler = new MingwWin32GUIModuleHandler ( module );
                        break;
+               case KeyboardLayout:
                case KernelModeDLL:
                        handler = new MingwKernelModeDLLModuleHandler ( module );
                        break;
@@ -237,9 +242,15 @@ MingwModuleHandler::InstanciateHandler (
                case Alias:
                        handler = new MingwAliasModuleHandler ( module );
                        break;
+               case MessageHeader:
+                       handler = new MingwMessageHeaderModuleHandler (module);
+                       break;
                case IdlHeader:
                        handler = new MingwIdlHeaderModuleHandler ( module );
                        break;
+               case Cabinet:
+                       handler = new MingwCabinetModuleHandler ( module );
+                       break;
                case EmbeddedTypeLib:
                        handler = new MingwEmbeddedTypeLibModuleHandler ( module );
                        break;
@@ -270,49 +281,6 @@ MingwModuleHandler::GetBasename ( const string& filename ) const
        return "";
 }
 
-/* caller needs to delete the returned object */
-const FileLocation*
-MingwModuleHandler::GetActualSourceFilename (
-       const FileLocation* file ) const
-{
-       string filename = file->name;
-
-       string extension = GetExtension ( *file );
-       if ( extension == ".spec" || extension == ".SPEC" )
-       {
-               const FileLocation *objectFile = GetObjectFilename ( file, module );
-               FileLocation *sourceFile = new FileLocation (
-                       objectFile->directory,
-                       objectFile->relative_path,
-                       ReplaceExtension ( objectFile->name, ".c" ) );
-               delete objectFile;
-               return sourceFile;
-       }
-       else if ( ( extension == ".idl" || extension == ".IDL" ) &&
-                 ( module.type == RpcServer || module.type == RpcClient || module.type == RpcProxy ) )
-       {
-               const FileLocation *objectFile = GetObjectFilename ( file, module );
-               FileLocation *sourceFile = new FileLocation (
-                       objectFile->directory,
-                       objectFile->relative_path,
-                       ReplaceExtension ( objectFile->name, ".c" ) );
-               delete objectFile;
-               return sourceFile;
-       }
-       else if ( extension == ".mc" || extension == ".MC" )
-       {
-               const FileLocation *objectFile = GetObjectFilename ( file, module );
-               FileLocation *sourceFile = new FileLocation (
-                       objectFile->directory,
-                       objectFile->relative_path,
-                       ReplaceExtension ( objectFile->name, ".rc" ) );
-               delete objectFile;
-               return sourceFile;
-       }
-       else
-               return new FileLocation ( *file );
-}
-
 string
 MingwModuleHandler::GetExtraDependencies (
        const FileLocation *file ) const
@@ -359,7 +327,7 @@ MingwModuleHandler::GetCompilationUnitDependencies (
 const FileLocation*
 MingwModuleHandler::GetModuleArchiveFilename () const
 {
-       if ( module.type == StaticLibrary )
+       if ( IsStaticLibrary ( module ) )
                return GetTargetFilename ( module, NULL );
        return new FileLocation ( IntermediateDirectory,
                                  module.output->relative_path,
@@ -387,6 +355,8 @@ MingwModuleHandler::ReferenceObjects (
                return true;
        if ( module.type == IdlHeader )
                return true;
+       if ( module.type == MessageHeader)
+               return true;
        return false;
 }
 
@@ -475,56 +445,6 @@ MingwModuleHandler::GetModuleDependencies (
        }
 }
 
-void
-MingwModuleHandler::GetSourceFilenames ( vector<FileLocation>& list,
-                                         bool includeGeneratedFiles ) const
-{
-       size_t i;
-
-       const vector<CompilationUnit*>& compilationUnits = module.non_if_data.compilationUnits;
-       for ( i = 0; i < compilationUnits.size (); i++ )
-       {
-               if ( includeGeneratedFiles || !compilationUnits[i]->IsGeneratedFile () )
-               {
-                       const FileLocation& compilationName = compilationUnits[i]->GetFilename ();
-                       const FileLocation* sourceFileLocation = GetActualSourceFilename ( &compilationName );
-                       list.push_back ( *sourceFileLocation );
-                       delete sourceFileLocation;
-               }
-       }
-       // intentionally make a copy so that we can append more work in
-       // the middle of processing without having to go recursive
-       vector<If*> v = module.non_if_data.ifs;
-       for ( i = 0; i < v.size (); i++ )
-       {
-               size_t j;
-               If& rIf = *v[i];
-               // check for sub-ifs to add to list
-               const vector<If*>& ifs = rIf.data.ifs;
-               for ( j = 0; j < ifs.size (); j++ )
-                       v.push_back ( ifs[j] );
-               const vector<CompilationUnit*>& compilationUnits = rIf.data.compilationUnits;
-               for ( j = 0; j < compilationUnits.size (); j++ )
-               {
-                       CompilationUnit& compilationUnit = *compilationUnits[j];
-                       if ( includeGeneratedFiles || !compilationUnit.IsGeneratedFile () )
-                       {
-                               const FileLocation& compilationName = compilationUnit.GetFilename ();
-                               const FileLocation* sourceFileLocation = GetActualSourceFilename ( &compilationName );
-                               list.push_back ( *sourceFileLocation );
-                               delete sourceFileLocation;
-                       }
-               }
-       }
-}
-
-void
-MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
-       vector<FileLocation>& list ) const
-{
-       GetSourceFilenames ( list, false );
-}
-
 /* caller needs to delete the returned object */
 const FileLocation*
 MingwModuleHandler::GetObjectFilename (
@@ -823,10 +743,9 @@ MingwModuleHandler::GenerateMacro (
        size_t i;
        bool generateAssignment;
 
+       generateAssignment = (use_pch && module.pch != NULL ) || data.includes.size () > 0 || data.defines.size () > 0;
        if ( generatingCompilerMacro )
-               generateAssignment = (use_pch && module.pch != NULL ) || data.includes.size () > 0 || data.defines.size () > 0 || data.compilerFlags.size () > 0;
-       else
-               generateAssignment = (use_pch && module.pch != NULL ) || data.includes.size () > 0 || data.defines.size () > 0;
+               generateAssignment |= data.compilerFlags.size () > 0;
        if ( generateAssignment )
        {
                fprintf ( fMakefile,
@@ -1236,8 +1155,8 @@ MingwModuleHandler::GetPrecompiledHeaderFilename () const
        if ( !module.pch || !use_pch )
                return NULL;
        return new FileLocation ( IntermediateDirectory,
-                                 module.pch->file.relative_path,
-                                 ReplaceExtension ( module.pch->file.name, "_" + module.name + ".gch" ) );
+                                 module.pch->file->relative_path,
+                                 module.pch->file->name + ".gch" );
 }
 
 Rule arRule1 ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).a: $($(module_name)_OBJS) | $(INTERMEDIATE)$(SEP)$(source_dir)\n",
@@ -1246,21 +1165,28 @@ Rule arRule1 ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).a:
 Rule arRule2 ( "\t$(ECHO_AR)\n"
               "\t${ar} -rc $@ $($(module_name)_OBJS)\n",
               NULL );
-Rule gasRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o: $(source)$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
+Rule arHostRule2 ( "\t$(ECHO_AR)\n"
+                   "\t${host_ar} -rc $@ $($(module_name)_OBJS)\n",
+                   NULL );
+Rule gasRule ( "$(source): ${$(module_name)_precondition}\n"
+               "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o: $(source)$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
                "\t$(ECHO_GAS)\n"
-               "\t${gcc} -x assembler-with-cpp -c $< -o $@ -D__ASM__ $($(module_name)_CFLAGS)\n",
+               "\t${gcc} -x assembler-with-cpp -o $@ -D__ASM__ $($(module_name)_CFLAGS) -c $<\n",
                "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o",
                "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL );
-Rule bootRule ( "$(module_output): $(source)$(dependencies) | $(OUTPUT)$(SEP)$(source_dir)\n"
+Rule bootRule ( "$(source): ${$(module_name)_precondition}\n"
+                "$(module_output): $(source)$(dependencies) | $(OUTPUT)$(SEP)$(source_dir)\n"
                 "\t$(ECHO_NASM)\n"
                 "\t$(Q)${nasm} -f win32 $< -o $@ $($(module_name)_NASMFLAGS)\n",
                 "$(OUTPUT)$(SEP)$(source_dir)$(SEP)", NULL );
-Rule nasmRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o: $(source)$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
+Rule nasmRule ( "$(source): ${$(module_name)_precondition}\n"
+                "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o: $(source)$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
                 "\t$(ECHO_NASM)\n"
                 "\t$(Q)${nasm} -f win32 $< -o $@ $($(module_name)_NASMFLAGS)\n",
                 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o",
                 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL );
-Rule windresRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).coff: $(source)$(dependencies) $(WRC_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir) $(TEMPORARY)\n"
+Rule windresRule ( "$(source): ${$(module_name)_precondition}\n"
+                   "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).coff: $(source)$(dependencies) $(WRC_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir) $(TEMPORARY)\n"
                    "\t$(ECHO_WRC)\n"
                    "\t${gcc} -xc -E -DRC_INVOKED ${$(module_name)_RCFLAGS} $(source) > $(TEMPORARY)$(SEP)$(module_name).$(source_name_noext).rci.tmp\n"
                    "\t$(Q)$(WRC_TARGET) ${$(module_name)_RCFLAGS} $(TEMPORARY)$(SEP)$(module_name).$(source_name_noext).rci.tmp $(TEMPORARY)$(SEP)$(module_name).$(source_name_noext).res.tmp\n"
@@ -1269,78 +1195,90 @@ Rule windresRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)
                    "\t-@${rm} $(TEMPORARY)$(SEP)$(module_name).$(source_name_noext).res.tmp 2>$(NUL)\n",
                    "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).coff",
                    "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL );
-Rule wmcRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).rc $(INTERMEDIATE)$(SEP)include$(SEP)reactos$(SEP)$(source_name_noext).h: $(WMC_TARGET) $(source)\n"
+Rule wmcRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).rc $(INTERMEDIATE)$(SEP)include$(SEP)reactos$(SEP)$(source_name_noext).h: $(WMC_TARGET) $(source) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
                "\t$(ECHO_WMC)\n"
                "\t$(Q)$(WMC_TARGET) -i -H $(INTERMEDIATE)$(SEP)include$(SEP)reactos$(SEP)$(source_name_noext).h -o $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).rc $(source)\n",
-               "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).rc", "$(INTERMEDIATE)$(SEP)include$(SEP)reactos$(SEP)$(source_name_noext).h", NULL );
+               "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).rc",
+               "$(INTERMEDIATE)$(SEP)include$(SEP)reactos$(SEP)$(source_name_noext).h",
+               "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL );
 Rule winebuildRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).spec.def: $(source)$(dependencies) $(WINEBUILD_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
                      "\t$(ECHO_WINEBLD)\n"
-                     "\t$(Q)$(WINEBUILD_TARGET) $(WINEBUILD_FLAGS) -o $(INTERMEDIATE)$(SEP)$(source_path)$(SEP)$(source_name_noext).spec.def --def -E $(source_path)$(SEP)$(source_name_noext).spec\n"
+                     "\t$(Q)$(WINEBUILD_TARGET) $(WINEBUILD_FLAGS) -o $(INTERMEDIATE)$(SEP)$(source_path)$(SEP)$(source_name_noext).spec.def --def -E $(source)\n"
                      "$(INTERMEDIATE)$(SEP)$(source_path)$(SEP)$(source_name_noext).stubs.c: $(source_path)$(SEP)$(source_name_noext).spec $(WINEBUILD_TARGET)\n"
                      "\t$(ECHO_WINEBLD)\n"
                      "\t$(Q)$(WINEBUILD_TARGET) $(WINEBUILD_FLAGS) -o $(INTERMEDIATE)$(SEP)$(source_path)$(SEP)$(source_name_noext).stubs.c --pedll $(source_path)$(SEP)$(source_name_noext).spec\n"
                      "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).stubs.o: $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).stubs.c$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
                      "\t$(ECHO_CC)\n"
-                     "\t${gcc} -c $< -o $@ $($(module_name)_CFLAGS)$(compiler_flags)\n",
+                     "\t${gcc} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -c $<\n",
                      "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).spec.def",
                      "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).stubs.c",
                      "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).stubs.o",
                      "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL );
-Rule widlHeaderRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).h: $(source)$(dependencies) $(WIDL_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
+Rule widlHeaderRule ( "$(source): ${$(module_name)_precondition}\n"
+                      "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).h: $(source)$(dependencies) $(WIDL_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
                       "\t$(ECHO_WIDL)\n"
                       "\t$(Q)$(WIDL_TARGET) $($(module_name)_WIDLFLAGS) -h -H $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).h $(source)\n",
                       "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).h",
                       "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL );
-Rule widlServerRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.c $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.h: $(source)$(dependencies) $(WIDL_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
+Rule widlServerRule ( "$(source): ${$(module_name)_precondition}\n"
+                      "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.c $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.h: $(source)$(dependencies) $(WIDL_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
                       "\t$(ECHO_WIDL)\n"
                       "\t$(Q)$(WIDL_TARGET) $($(module_name)_WIDLFLAGS) -h -H $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.h -s -S $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.c $(source)\n"
                       "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.o: $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.c $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.h$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
                       "\t$(ECHO_CC)\n"
-                      "\t${gcc} -c $< -o $@ $($(module_name)_CFLAGS)$(compiler_flags)\n",
+                      "\t${gcc} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -c $<\n",
                       "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.h",
                       "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.c",
                       "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.o",
                       "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL );
-Rule widlClientRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.c $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.h: $(source)$(dependencies) $(WIDL_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
+Rule widlClientRule ( "$(source): ${$(module_name)_precondition}\n"
+                      "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.c $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.h: $(source)$(dependencies) $(WIDL_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
                       "\t$(ECHO_WIDL)\n"
                       "\t$(Q)$(WIDL_TARGET) $($(module_name)_WIDLFLAGS) -h -H $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.h -c -C $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.c $(source)\n"
                       "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.o: $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.c $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.h$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
                       "\t$(ECHO_CC)\n"
-                      "\t${gcc} -c $< -o $@ $($(module_name)_CFLAGS)$(compiler_flags)\n",
+                      "\t${gcc} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -c $<\n",
                       "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.h",
                       "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.c",
                       "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.o",
                       "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL );
-Rule widlProxyRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.c $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.h: $(source)$(dependencies) $(WIDL_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
+Rule widlProxyRule ( "$(source): ${$(module_name)_precondition}\n"
+                     "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.c $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.h: $(source)$(dependencies) $(WIDL_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
                      "\t$(ECHO_WIDL)\n"
                      "\t$(Q)$(WIDL_TARGET) $($(module_name)_WIDLFLAGS) -h -H $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.h -p -P $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.c $(source)\n"
                      "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.o: $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.c $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.h$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
                       "\t$(ECHO_CC)\n"
-                      "\t${gcc} -c $< -o $@ $($(module_name)_CFLAGS)$(compiler_flags)\n",
+                      "\t${gcc} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -c $<\n",
                      "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.h",
                      "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.c",
                      "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.o",
                      "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL );
-Rule widlTlbRule ( "$(OUTPUT)$(SEP)$(source_dir)$(SEP)$(module_name).tlb: $(source)$(dependencies) $(WIDL_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
+Rule widlTlbRule ( "$(source): ${$(module_name)_precondition}\n"
+                   "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(module_name).tlb: $(source)$(dependencies) $(WIDL_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
                    "\t$(ECHO_WIDL)\n"
                    "\t$(Q)$(WIDL_TARGET) $($(module_name)_WIDLFLAGS) -t -T $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).tlb $(source)\n",
                    "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL );
-Rule gccRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o: $(source)$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
+Rule gccRule ( "$(source): ${$(module_name)_precondition}\n"
+               "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o: $(source)$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
                "\t$(ECHO_CC)\n"
-               "\t${gcc} -c $< -o $@ $($(module_name)_CFLAGS)$(compiler_flags)\n",
+               "\t${gcc} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -c $<\n",
                "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o", NULL );
-Rule gccHostRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o: $(source)$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
+Rule gccHostRule ( "$(source): ${$(module_name)_precondition}\n"
+                   "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o: $(source)$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
                    "\t$(ECHO_CC)\n"
-                   "\t${host_gcc} -c $< -o $@ $($(module_name)_CFLAGS)$(compiler_flags)\n",
+                   "\t${host_gcc} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -c $<\n",
                    "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o", NULL );
-Rule gppRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o: $(source)$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
+Rule gppRule ( "$(source): ${$(module_name)_precondition}\n"
+               "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o: $(source)$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
                "\t$(ECHO_CC)\n"
-               "\t${gpp} -c $< -o $@ $($(module_name)_CFLAGS)$(compiler_flags)\n",
+               "\t${gpp} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -c $<\n",
                "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o", NULL );
-Rule gppHostRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o: $(source)$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
+Rule gppHostRule ( "$(source): ${$(module_name)_precondition}\n"
+                   "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o: $(source)$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
                    "\t$(ECHO_CC)\n"
-                   "\t${host_gpp} -c $< -o $@ $($(module_name)_CFLAGS)$(compiler_flags)\n",
+                   "\t${host_gpp} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -c $<\n",
                    "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o", NULL );
+Rule emptyRule ( "", NULL );
 
 void
 MingwModuleHandler::GenerateGccCommand (
@@ -1348,7 +1286,6 @@ MingwModuleHandler::GenerateGccCommand (
        const Rule *rule,
        const string& extraDependencies )
 {
-       const FileLocation *generatedSourceFileName = GetActualSourceFilename ( sourceFile );
        const FileLocation *pchFilename = GetPrecompiledHeaderFilename ();
        string dependencies = extraDependencies;
 
@@ -1371,9 +1308,7 @@ MingwModuleHandler::GenerateGccCommand (
        if ( rpcDependencies.size () > 0 )
                dependencies += " " + v2s ( backend, rpcDependencies, 5 );
 
-       rule->Execute ( fMakefile, backend, module, generatedSourceFileName, clean_files, dependencies, flags );
-
-       delete generatedSourceFileName;
+       rule->Execute ( fMakefile, backend, module, sourceFile, clean_files, dependencies, flags );
 }
 
 string
@@ -1463,6 +1398,7 @@ MingwModuleHandler::GenerateCommands (
                { HostFalse, TypeDontCare, ".cc", &gppRule },
                { HostFalse, TypeDontCare, ".cpp", &gppRule },
                { HostFalse, TypeDontCare, ".cxx", &gppRule },
+               { HostFalse, Cabinet, ".*", &emptyRule }
        };
        size_t i;
        Rule *customRule = NULL;
@@ -1473,7 +1409,7 @@ MingwModuleHandler::GenerateCommands (
                        continue;
                if ( rules[i].type != TypeDontCare && rules[i].type != module.type )
                        continue;
-               if ( rules[i].extension != extension )
+               if ( rules[i].extension != extension && rules[i].extension != ".*")
                        continue;
                customRule = rules[i].rule;
                break;
@@ -1613,10 +1549,14 @@ MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const
 void
 MingwModuleHandler::GenerateRunRsymCode () const
 {
+       fprintf ( fMakefile,
+             "ifneq ($(ROS_GENERATE_RSYM),no)\n" );
        fprintf ( fMakefile,
                  "\t$(ECHO_RSYM)\n" );
        fprintf ( fMakefile,
                  "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
+       fprintf ( fMakefile,
+             "endif\n" );
 }
 
 void
@@ -1640,7 +1580,7 @@ MingwModuleHandler::GenerateLinkerCommand (
 {
        const FileLocation *target_file = GetTargetFilename ( module, NULL );
        const FileLocation *definitionFilename = GetDefinitionFilename ();
-       string linker = module.cplusplus ? "${gpp}" : "${gcc}";
+       string linker = "${ld}";
        string objectsMacro = GetObjectsMacro ( module );
        string libsMacro = GetLibsMacro ();
 
@@ -1649,32 +1589,37 @@ MingwModuleHandler::GenerateLinkerCommand (
 
        string linkerScriptArgument;
        if ( module.linkerScript != NULL )
-               linkerScriptArgument = ssprintf ( " -Wl,-T,%s", backend->GetFullName ( module.linkerScript->file ).c_str () );
+               linkerScriptArgument = ssprintf ( " -T %s", backend->GetFullName ( *module.linkerScript->file ).c_str () );
        else
                linkerScriptArgument = "";
 
        fprintf ( fMakefile,
                "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n",
                target_macro.c_str (),
-               backend->GetFullName ( *definitionFilename ).c_str (),
+               definitionFilename ? backend->GetFullName ( *definitionFilename ).c_str () : "",
                dependencies.c_str (),
                target_folder.c_str () );
        fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
        string targetName ( module.output->name );
 
-       if ( !module.IsDLL () )
+       /* HACK: if we have C++ in kernel, link it with some user mode dlls (kernel32 + msvcrt) ... */
+       static const string libsCppKernel = " '$(shell ${TARGET_CC} -print-file-name=libkernel32.a)' '$(shell ${TARGET_CC} -print-file-name=libmsvcrt.a)'";
+
+       if ( !module.HasImportLibrary() )
        {
                fprintf ( fMakefile,
-                         "\t%s %s%s -o %s %s %s %s\n",
+                         "\t%s %s%s %s %s%s %s %s -o %s\n",
                          linker.c_str (),
                          linkerParameters.c_str (),
                          linkerScriptArgument.c_str (),
-                         target_macro.c_str (),
                          objectsMacro.c_str (),
+                         module.cplusplus ? "$(PROJECT_LPPFLAGS) " : "",
+                         module.cplusplus && (module.type == KernelModeDLL || module.type == KernelModeDriver) ? libsCppKernel.c_str () : "",
                          libsMacro.c_str (),
-                         GetLinkerMacro ().c_str () );
+                         GetLinkerMacro ().c_str (),
+                         target_macro.c_str () );
        }
-       else if ( module.HasImportLibrary () )
+       else
        {
                FileLocation temp_exp ( TemporaryDirectory,
                                        "",
@@ -1684,21 +1629,23 @@ MingwModuleHandler::GenerateLinkerCommand (
                fprintf ( fMakefile,
                          "\t${dlltool} --dllname %s --def %s --output-exp %s%s%s\n",
                          targetName.c_str (),
-                         backend->GetFullName ( *definitionFilename ).c_str (),
+                         definitionFilename ? backend->GetFullName ( *definitionFilename ).c_str () : "",
                          backend->GetFullName ( temp_exp ).c_str (),
                          module.mangledSymbols ? "" : " --kill-at",
                          module.underscoreSymbols ? " --add-underscore" : "" );
 
                fprintf ( fMakefile,
-                         "\t%s %s%s %s -o %s %s %s %s\n",
+                         "\t%s %s%s %s %s %s%s %s %s -o %s\n",
                          linker.c_str (),
                          linkerParameters.c_str (),
                          linkerScriptArgument.c_str (),
                          backend->GetFullName ( temp_exp ).c_str (),
-                         target_macro.c_str (),
                          objectsMacro.c_str (),
+                         module.cplusplus ? "$(PROJECT_LPPFLAGS) " : "",
+                         module.cplusplus && (module.type == KernelModeDLL || module.type == KernelModeDriver) ? libsCppKernel.c_str () : "",
                          libsMacro.c_str (),
-                         GetLinkerMacro ().c_str () );
+                         GetLinkerMacro ().c_str (),
+                         target_macro.c_str () );
 
                fprintf ( fMakefile,
                          "\t$(Q)$(PEFIXUP_TARGET) %s -exports%s\n",
@@ -1709,24 +1656,6 @@ MingwModuleHandler::GenerateLinkerCommand (
                          "\t-@${rm} %s 2>$(NUL)\n",
                          backend->GetFullName ( temp_exp ).c_str () );
        }
-       else
-       {
-               /* XXX: need to workaround binutils bug, which exports
-                * all functions in a dll if no .def file or an empty
-                * one has been provided... */
-               /* See bug 1244 */
-               //printf ( "%s will have all its functions exported\n",
-               //         module.target->name.c_str () );
-               fprintf ( fMakefile,
-                         "\t%s %s%s -o %s %s %s %s\n",
-                         linker.c_str (),
-                         linkerParameters.c_str (),
-                         linkerScriptArgument.c_str (),
-                         target_macro.c_str (),
-                         objectsMacro.c_str (),
-                         libsMacro.c_str (),
-                         GetLinkerMacro ().c_str () );
-       }
 
        GenerateBuildMapCode ();
        GenerateBuildNonSymbolStrippedCode ();
@@ -1734,7 +1663,8 @@ MingwModuleHandler::GenerateLinkerCommand (
        GenerateRunStripCode ();
        GenerateCleanObjectsAsYouGoCode ();
 
-       delete definitionFilename;
+       if ( definitionFilename )
+               delete definitionFilename;
        delete target_file;
 }
 
@@ -1807,7 +1737,7 @@ MingwModuleHandler::GenerateObjectFileTargets ()
                string cc = ( module.host == HostTrue ? "${host_gcc}" : "${gcc}" );
                string cppc = ( module.host == HostTrue ? "${host_gpp}" : "${gpp}" );
 
-               const FileLocation& baseHeaderFile = module.pch->file;
+               const FileLocation& baseHeaderFile = *module.pch->file;
                CLEAN_FILE ( *pchFilename );
                string dependencies = backend->GetFullName ( baseHeaderFile );
                /* WIDL generated headers may be used */
@@ -1839,24 +1769,27 @@ const FileLocation*
 MingwModuleHandler::GenerateArchiveTarget ()
 {
        const FileLocation *archiveFilename = GetModuleArchiveFilename ();
+       const FileLocation *definitionFilename = GetDefinitionFilename ();
 
        arRule1.Execute ( fMakefile, backend, module, archiveFilename, clean_files );
 
-       if ( module.type == StaticLibrary && module.importLibrary )
+       if ( IsStaticLibrary ( module ) && definitionFilename )
        {
-               const FileLocation *definitionFilename = GetDefinitionFilename ();
-
                fprintf ( fMakefile,
                          "\t${dlltool} --dllname %s --def %s --output-lib $@%s%s\n",
                          module.importLibrary->dllname.c_str (),
                          backend->GetFullName ( *definitionFilename ).c_str (),
                          module.mangledSymbols ? "" : " --kill-at",
                          module.underscoreSymbols ? " --add-underscore" : "" );
+       }
 
+       if ( definitionFilename )
                delete definitionFilename;
-       }
 
-       arRule2.Execute ( fMakefile, backend, module, archiveFilename, clean_files );
+       if(module.type == HostStaticLibrary)
+               arHostRule2.Execute ( fMakefile, backend, module, archiveFilename, clean_files );
+       else
+               arRule2.Execute ( fMakefile, backend, module, archiveFilename, clean_files );
 
        GenerateCleanObjectsAsYouGoCode ();
 
@@ -2016,11 +1949,14 @@ MingwModuleHandler::GenerateOtherMacros ()
                &module.linkerFlags,
                used_defs );
 
-       GenerateMacros (
-               "+=",
-               module.project.non_if_data,
-               NULL,
-               used_defs );
+       if ( module.host == HostFalse )
+       {
+               GenerateMacros (
+                       "+=",
+                       module.project.non_if_data,
+                       NULL,
+                       used_defs );
+       }
 
        vector<FileLocation> s;
        if ( module.importLibrary )
@@ -2048,7 +1984,12 @@ MingwModuleHandler::GenerateOtherMacros ()
                fprintf ( fMakefile, "\n" );
        }
 
-       string globalCflags = "-g";
+       string globalCflags = "";
+       if ( module.host == HostFalse )
+               globalCflags += " $(PROJECT_CFLAGS)";
+       else
+               globalCflags += " -Wall -Wpointer-arith -D__REACTOS__";
+       globalCflags += " -g";
        if ( backend->usePipe )
                globalCflags += " -pipe";
        if ( !module.allowWarnings )
@@ -2058,7 +1999,7 @@ MingwModuleHandler::GenerateOtherMacros ()
                if ( module.cplusplus )
                        globalCflags += " $(HOST_CPPFLAGS)";
                else
-                       globalCflags += " $(HOST_CFLAGS)";
+                       globalCflags += " -Wno-strict-aliasing $(HOST_CFLAGS)";
        }
        else
        {
@@ -2077,25 +2018,35 @@ MingwModuleHandler::GenerateOtherMacros ()
 
        fprintf (
                fMakefile,
-               "%s += $(PROJECT_CFLAGS) %s\n",
+               "%s +=%s\n",
                cflagsMacro.c_str (),
                globalCflags.c_str () );
 
-       fprintf (
-               fMakefile,
-               "%s += $(PROJECT_RCFLAGS)\n",
-               windresflagsMacro.c_str () );
+       if ( module.host == HostFalse )
+       {
+               fprintf (
+                       fMakefile,
+                       "%s += $(PROJECT_RCFLAGS)\n",
+                       windresflagsMacro.c_str () );
 
-       fprintf (
-               fMakefile,
-               "%s += $(PROJECT_WIDLFLAGS) -I%s\n",
-               widlflagsMacro.c_str (),
-               module.output->relative_path.c_str () );
+               fprintf (
+                       fMakefile,
+                       "%s += $(PROJECT_WIDLFLAGS) -I%s\n",
+                       widlflagsMacro.c_str (),
+                       module.output->relative_path.c_str () );
 
-       fprintf (
-               fMakefile,
-               "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
-               module.name.c_str () );
+               fprintf (
+                       fMakefile,
+                       "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
+                       module.name.c_str () );
+       }
+       else
+       {
+               fprintf (
+                       fMakefile,
+                       "%s_LFLAGS += $(HOST_LFLAGS)\n",
+                       module.name.c_str () );
+       }
 
        fprintf (
                fMakefile,
@@ -2130,7 +2081,7 @@ MingwModuleHandler::GenerateOtherMacros ()
                          linkerflags.c_str () );
        }
 
-       if ( module.type == StaticLibrary && module.isStartupLib )
+       if ( IsStaticLibrary ( module ) && module.isStartupLib )
        {
                fprintf ( fMakefile,
                          "%s += -Wno-main\n\n",
@@ -2254,41 +2205,47 @@ MingwModuleHandler::GetDefaultDependencies (
        string_list& dependencies ) const
 {
        /* Avoid circular dependency */
-       if ( module.type != BuildTool
-               && module.name != "zlib"
-               && module.name != "hostzlib" )
-
-               dependencies.push_back ( "$(INIT)" );
-
-       if ( module.type != BuildTool
-               && module.name != "psdk" )
+       if ( module.host == HostTrue )
+               return;
 
-       dependencies.push_back ( "$(PSDK_TARGET) $(psdk_HEADERS)" );
+       if (module.name != "psdk" && 
+               module.name != "dxsdk")
+       {
+               dependencies.push_back ( "$(PSDK_TARGET) $(psdk_HEADERS)" );
+               dependencies.push_back ( "$(DXSDK_TARGET) $(dxsdk_HEADERS)" );
+       }
 
-       /* Check if any dependent library relays on the generated headers */
-       for ( size_t i = 0; i < module.project.modules.size (); i++ )
+       if (module.name != "errcodes" && 
+               module.name != "bugcodes" &&
+               module.name != "ntstatus")
        {
-               const Module& m = *module.project.modules[i];
-               for ( size_t j = 0; j < m.non_if_data.compilationUnits.size (); j++ )
-               {
-                       CompilationUnit& compilationUnit = *m.non_if_data.compilationUnits[j];
-                       const FileLocation& sourceFile = compilationUnit.GetFilename ();
-                       string extension = GetExtension ( sourceFile );
-                       if (extension == ".mc" || extension == ".MC" )
-                       {
-                               string dependency = ssprintf ( "$(%s_MCHEADERS)", m.name.c_str () );
-                               dependencies.push_back ( dependency );
-                       }
-               }
+               dependencies.push_back ( "$(ERRCODES_TARGET) $(ERRCODES_MCHEADERS)" );
+               dependencies.push_back ( "$(BUGCODES_TARGET) $(BUGCODES_MCHEADERS)" );
+               dependencies.push_back ( "$(NTSTATUS_TARGET) $(NTSTATUS_MCHEADERS)" );
        }
+
+       ///* Check if any dependent library relies on the generated headers */
+       //for ( size_t i = 0; i < module.project.modules.size (); i++ )
+       //{
+       //      const Module& m = *module.project.modules[i];
+       //      for ( size_t j = 0; j < m.non_if_data.compilationUnits.size (); j++ )
+       //      {
+       //              CompilationUnit& compilationUnit = *m.non_if_data.compilationUnits[j];
+       //              const FileLocation& sourceFile = compilationUnit.GetFilename ();
+       //              string extension = GetExtension ( sourceFile );
+       //              if (extension == ".mc" || extension == ".MC" )
+       //              {
+       //                      string dependency = ssprintf ( "$(%s_MCHEADERS)", m.name.c_str () );
+       //                      dependencies.push_back ( dependency );
+       //              }
+       //      }
+       //}
 }
 
 void
 MingwModuleHandler::GeneratePreconditionDependencies ()
 {
        string preconditionDependenciesName = GetPreconditionDependenciesName ();
-       vector<FileLocation> sourceFilenames;
-       GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames );
        string_list dependencies;
        GetDefaultDependencies ( dependencies );
        GetModuleDependencies ( dependencies );
@@ -2307,13 +2264,6 @@ MingwModuleHandler::GeneratePreconditionDependencies ()
                fprintf ( fMakefile, "\n\n" );
        }
 
-       for ( size_t i = 0; i < sourceFilenames.size(); i++ )
-       {
-               fprintf ( fMakefile,
-                         "%s: ${%s}\n",
-                         backend->GetFullName ( sourceFilenames[i] ).c_str (),
-                         preconditionDependenciesName.c_str ());
-       }
        fprintf ( fMakefile, "\n" );
 }
 
@@ -2331,20 +2281,18 @@ MingwModuleHandler::IsWineModule () const
 const FileLocation*
 MingwModuleHandler::GetDefinitionFilename () const
 {
-       if ( module.importLibrary != NULL )
-       {
-               DirectoryLocation directory;
-               if ( IsWineModule () )
-                       directory = IntermediateDirectory;
-               else
-                       directory = SourceDirectory;
+       if ( module.importLibrary == NULL )
+               return NULL;
 
-               return new FileLocation ( directory,
-                                         module.importLibrary->source->relative_path,
-                                         module.importLibrary->source->name );
-       }
+       DirectoryLocation directory;
+       if ( IsWineModule () )
+               directory = IntermediateDirectory;
        else
-               return new FileLocation ( SourceDirectory, "tools" + sSep + "rbuild", "empty.def" );
+               directory = SourceDirectory;
+
+       return new FileLocation ( directory,
+                                 module.importLibrary->source->relative_path,
+                                 module.importLibrary->source->name );
 }
 
 void
@@ -2354,15 +2302,21 @@ MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
        {
                const FileLocation *library_target = GetImportLibraryFilename ( module, &clean_files );
                const FileLocation *defFilename = GetDefinitionFilename ();
+               string empty = "tools" + sSep + "rbuild" + sSep + "empty.def";
 
                vector<FileLocation> deps;
                GetDefinitionDependencies ( deps );
 
                fprintf ( fMakefile, "# IMPORT LIBRARY RULE:\n" );
 
-               fprintf ( fMakefile, "%s: %s",
-                         backend->GetFullName ( *library_target ).c_str (),
-                         backend->GetFullName ( *defFilename ).c_str () );
+               fprintf ( fMakefile, "%s:",
+                         backend->GetFullName ( *library_target ).c_str () );
+
+               if ( defFilename )
+               {
+                       fprintf ( fMakefile, " %s",
+                                 backend->GetFullName ( *defFilename ).c_str () );
+               }
 
                size_t i, iend = deps.size();
                for ( i = 0; i < iend; i++ )
@@ -2377,12 +2331,14 @@ MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
                fprintf ( fMakefile,
                          "\t${dlltool} --dllname %s --def %s --output-lib %s%s%s\n\n",
                          module.output->name.c_str (),
-                         backend->GetFullName ( *defFilename ).c_str (),
+                         defFilename ? backend->GetFullName ( *defFilename ).c_str ()
+                                     : empty.c_str (),
                          backend->GetFullName ( *library_target ).c_str (),
                          module.mangledSymbols ? "" : " --kill-at",
                          module.underscoreSymbols ? " --add-underscore" : "" );
 
-               delete defFilename;
+               if ( defFilename )
+                       delete defFilename;
                delete library_target;
        }
 }
@@ -2561,7 +2517,7 @@ MingwKernelModuleHandler::GenerateKernelModuleTarget ()
 
                string dependencies = linkDepsMacro + " " + objectsMacro;
 
-               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s",
+               string linkerParameters = ssprintf ( "-subsystem=native -entry=%s -image-base=%s",
                                                     module.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (),
                                                     module.baseaddress.c_str () );
 
@@ -2596,6 +2552,26 @@ MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
 }
 
 
+MingwHostStaticLibraryModuleHandler::MingwHostStaticLibraryModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwHostStaticLibraryModuleHandler::Process ()
+{
+       GenerateHostStaticLibraryModuleTarget ();
+}
+
+void
+MingwHostStaticLibraryModuleHandler::GenerateHostStaticLibraryModuleTarget ()
+{
+       GenerateRules ();
+}
+
+
 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
        const Module& module_ )
 
@@ -2664,7 +2640,7 @@ MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
 
                string dependencies = linkDepsMacro + " " + objectsMacro;
 
-               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
+               string linkerParameters = ssprintf ( "-subsystem=native -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000 -shared",
                                                     module.GetEntryPoint(true).c_str (),
                                                     module.baseaddress.c_str () );
                GenerateLinkerCommand ( dependencies,
@@ -2713,7 +2689,7 @@ MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
 
                string dependencies = linkDepsMacro + " " + objectsMacro;
 
-               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
+               string linkerParameters = ssprintf ( "-subsystem=native -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000 -shared",
                                                     module.GetEntryPoint(true).c_str (),
                                                     module.baseaddress.c_str () );
                GenerateLinkerCommand ( dependencies,
@@ -2761,7 +2737,7 @@ MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
 
                string dependencies = linkDepsMacro + " " + objectsMacro;
 
-               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -shared",
+               string linkerParameters = ssprintf ( "-subsystem=native -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000 -shared",
                                                     module.GetEntryPoint(true).c_str (),
                                                     module.baseaddress.c_str () );
                GenerateLinkerCommand ( dependencies,
@@ -2809,7 +2785,7 @@ MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
 
                string dependencies = linkDepsMacro + " " + objectsMacro;
 
-               string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
+               string linkerParameters = ssprintf ( "-subsystem=native -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000",
                                                     module.GetEntryPoint(true).c_str (),
                                                     module.baseaddress.c_str () );
                GenerateLinkerCommand ( dependencies,
@@ -2859,7 +2835,7 @@ MingwAddImplicitLibraries( Module &module )
          && module.type != Win32OCX
          && module.type != Win32CUI
          && module.type != Win32GUI
-         && module.type != Win32SCR )
+         && module.type != Win32SCR)
        {
                // no implicit libraries
                return;
@@ -2934,7 +2910,7 @@ MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
 
                string dependencies = linkDepsMacro + " " + objectsMacro;
 
-               string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
+               string linkerParameters = ssprintf ( "-subsystem=console -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000 -shared",
                                                     module.GetEntryPoint(true).c_str (),
                                                     module.baseaddress.c_str () );
                GenerateLinkerCommand ( dependencies,
@@ -2976,7 +2952,7 @@ MingwWin32OCXModuleHandler::GenerateWin32OCXModuleTarget ()
 
                string dependencies = linkDepsMacro + " " + objectsMacro;
 
-               string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
+               string linkerParameters = ssprintf ( "-subsystem=console -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000 -shared",
                                                     module.GetEntryPoint(true).c_str (),
                                                     module.baseaddress.c_str () );
                GenerateLinkerCommand ( dependencies,
@@ -3025,7 +3001,7 @@ MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
 
                string dependencies = linkDepsMacro + " " + objectsMacro;
 
-               string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
+               string linkerParameters = ssprintf ( "-subsystem=console -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000",
                                                     module.GetEntryPoint(true).c_str (),
                                                     module.baseaddress.c_str () );
                GenerateLinkerCommand ( dependencies,
@@ -3074,7 +3050,7 @@ MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
 
                string dependencies = linkDepsMacro + " " + objectsMacro;
 
-               string linkerParameters = ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
+               string linkerParameters = ssprintf ( "-subsystem=windows -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000",
                                                     module.GetEntryPoint(true).c_str (),
                                                     module.baseaddress.c_str () );
                GenerateLinkerCommand ( dependencies,
@@ -3417,10 +3393,16 @@ MingwIsoModuleHandler::GenerateIsoModuleTarget ()
                vSourceFiles.push_back ( srcunattend );
 
        // bootsector
-       const Module* bootModule;
-       bootModule = module.project.LocateModule ( module.type == IsoRegTest
-                                                      ? "isobtrt"
-                                                      : "isoboot" );
+       const Module* bootModule = module.bootSector->bootSectorModule;
+
+       if (!bootModule)
+       {
+               throw InvalidOperationException ( module.node.location.c_str(),
+                                                                                 0,
+                                                                                 "Invalid bootsector. module '%s' requires <bootsector>",
+                                                                                 module.name.c_str ());
+       }
+
        const FileLocation *isoboot = bootModule->output;
        vSourceFiles.push_back ( *isoboot );
 
@@ -3431,22 +3413,14 @@ MingwIsoModuleHandler::GenerateIsoModuleTarget ()
        FileLocation reactosInf ( bootcdReactos.directory,
                                  bootcdReactos.relative_path,
                                  "reactos.inf" );
-       FileLocation vgafontsCab( bootcdReactos.directory,
-                             bootcdReactos.relative_path,
-                             "vgafonts.cab");
-       FileLocation vgafontsDir( SourceDirectory,
-                             "media" + sSep + "vgafonts",
-                             "" );
 
        vSourceFiles.push_back ( reactosDff );
 
-       string IsoName;
-
-       if (module.type == IsoRegTest)
-               IsoName = "ReactOS-RegTest.iso";
-       else
-               IsoName = "ReactOS.iso";
-
+       /* 
+               We use only the name and not full FileLocation(ouput) because Iso/LiveIso are an exception to the general rule.
+               Iso/LiveIso outputs are generated in code base root 
+       */
+       string IsoName = module.output->name;
 
        string sourceFiles = v2s ( backend, vSourceFiles, 5 );
 
@@ -3465,11 +3439,6 @@ MingwIsoModuleHandler::GenerateIsoModuleTarget ()
                  sourceFiles.c_str (),
                  cdFiles.c_str (),
                  cdDirectories.c_str () );
-       fprintf ( fMakefile, "\t$(ECHO_CABMAN)\n" );
-       fprintf ( fMakefile,
-                 "\t$(Q)$(CABMAN_TARGET) -M raw -S %s %s\\*.bin\n",      // Escape the asterisk for Make
-                 backend->GetFullName ( vgafontsCab ).c_str (),
-                 backend->GetFullName ( vgafontsDir ).c_str ());
        fprintf ( fMakefile,
                  "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
                  backend->GetFullName ( reactosDff ).c_str (),
@@ -3615,15 +3584,24 @@ MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
 
        string IsoName;
 
-       const Module* bootModule;
-       bootModule = module.project.LocateModule ( module.name == "livecdregtest"
-                                                      ? "isobtrt"
-                                                      : "isoboot" );
+       // bootsector
+       const Module* bootModule = module.bootSector->bootSectorModule;
+
+       if (!bootModule)
+       {
+               throw InvalidOperationException ( module.node.location.c_str(),
+                                                                                 0,
+                                                                                 "Invalid bootsector. module '%s' requires <bootsector>",
+                                                                                 module.name.c_str ());
+       }
+
        const FileLocation *isoboot = bootModule->output;
-       if (module.name == "livecdregtest")
-               IsoName = "ReactOS-LiveCD-RegTest.iso";
-       else
-               IsoName = "ReactOS-LiveCD.iso";
+
+       /* 
+               We use only the name and not full FileLocation(ouput) because Iso/LiveIso are an exception to the general rule.
+               Iso/LiveIso outputs are generated in code base root 
+       */
+       IsoName = module.output->name;
 
        string reactosDirectory = "reactos";
        string livecdReactosNoFixup = livecdDirectory + sSep + reactosDirectory;
@@ -3694,7 +3672,7 @@ MingwTestModuleHandler::GenerateTestModuleTarget ()
 
                string dependencies = linkDepsMacro + " " + objectsMacro;
 
-               string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
+               string linkerParameters = ssprintf ( "-subsystem=console -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000",
                                                     module.GetEntryPoint(true).c_str (),
                                                     module.baseaddress.c_str () );
                GenerateLinkerCommand ( dependencies,
@@ -3762,6 +3740,19 @@ MingwAliasModuleHandler::Process ()
 {
 }
 
+MingwMessageHeaderModuleHandler::MingwMessageHeaderModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwMessageHeaderModuleHandler::Process ()
+{
+       GenerateRules ();
+}
+
 MingwIdlHeaderModuleHandler::MingwIdlHeaderModuleHandler (
        const Module& module_ )
 
@@ -3775,6 +3766,32 @@ MingwIdlHeaderModuleHandler::Process ()
        GenerateRules ();
 }
 
+MingwCabinetModuleHandler::MingwCabinetModuleHandler (
+       const Module& module_ )
+
+       : MingwModuleHandler ( module_ )
+{
+}
+
+void
+MingwCabinetModuleHandler::Process ()
+{
+       string targetMacro ( GetTargetMacro (module) );
+
+       GenerateRules ();
+       
+       const FileLocation *target_file = GetTargetFilename ( module, NULL );
+       fprintf ( fMakefile, "%s: $(CABMAN_TARGET) | %s\n",
+                 targetMacro.c_str (),
+                 backend->GetFullPath ( *target_file ).c_str () );
+
+       fprintf ( fMakefile, "\t$(ECHO_CABMAN)\n" );
+       fprintf ( fMakefile,
+                 "\t$(Q)$(CABMAN_TARGET) -M raw -S %s $(%s_SOURCES)\n",      // Escape the asterisk for Make
+                 targetMacro.c_str (),
+                         module.name.c_str());
+}
+
 MingwElfExecutableModuleHandler::MingwElfExecutableModuleHandler (
        const Module& module_ )