Fix GCC detection in RBuild (first check TARGET_CC).
[reactos.git] / reactos / tools / rbuild / backend / mingw / mingw.cpp
index 7a66bc7..4673d4d 100644 (file)
@@ -58,8 +58,7 @@ const struct ModuleHandlerInformations ModuleHandlerInformations[] = {
        { HostFalse, "", "", "-nostartfiles -nostdlib" }, // BootProgram
        { HostFalse, "", "", "" }, // Win32SCR
        { HostFalse, "", "", "" }, // IdlHeader
-       { HostFalse, "", "", "" }, // IsoRegTest
-       { HostFalse, "", "", "" }, // LiveIsoRegTest
+       { HostFalse, "", "", "" }, // IdlInterface
        { HostFalse, "", "", "" }, // EmbeddedTypeLib
        { HostFalse, "", "", "" }, // ElfExecutable
        { HostFalse, "", "", "" }, // RpcProxy
@@ -69,6 +68,9 @@ const struct ModuleHandlerInformations ModuleHandlerInformations[] = {
        { HostFalse, "", "", "" }, // MessageHeader
 };
 
+static std::string mscPath;
+static std::string mslinkPath;
+
 string
 MingwBackend::GetFullPath ( const FileLocation& file ) const
 {
@@ -160,7 +162,10 @@ v2s ( const Backend* backend, const vector<FileLocation>& files, int wrap_at )
        {
                const FileLocation& file = files[i];
                if ( wrap_at > 0 && wrap_count++ == wrap_at )
+               {
                        s += " \\\n\t\t";
+                       wrap_count = 1;
+               }
                else if ( s.size() )
                        s += " ";
                s += backend->GetFullName ( file );
@@ -181,7 +186,10 @@ v2s ( const string_list& v, int wrap_at )
                if ( !v[i].size() )
                        continue;
                if ( wrap_at > 0 && wrap_count++ == wrap_at )
+               {
                        s += " \\\n\t\t";
+                       wrap_count = 1;
+               }
                else if ( s.size() )
                        s += " ";
                s += v[i];
@@ -255,9 +263,12 @@ MingwBackend::ProcessModules ()
        vector<MingwModuleHandler*> v;
        size_t i;
 
-       for ( i = 0; i < ProjectNode.modules.size (); i++ )
+       for ( std::map<std::string, Module*>::iterator p = ProjectNode.modules.begin (); p != ProjectNode.modules.end (); ++ p )
+               fprintf ( fMakefile, "%s_TYPE:=%u\n", p->second->name.c_str(), p->second->type );
+
+       for ( std::map<std::string, Module*>::iterator p = ProjectNode.modules.begin (); p != ProjectNode.modules.end (); ++ p )
        {
-               Module& module = *ProjectNode.modules[i];
+               Module& module = *p->second;
                if ( !module.enabled )
                        continue;
                MingwModuleHandler* h = MingwModuleHandler::InstanciateHandler (
@@ -313,7 +324,7 @@ MingwBackend::Process ()
 void
 MingwBackend::CheckAutomaticDependenciesForModuleOnly ()
 {
-       if ( configuration.AutomaticDependencies )
+       if ( configuration.Dependencies == AutomaticDependencies )
        {
                Module* module = ProjectNode.LocateModule ( configuration.CheckDependenciesForModuleOnlyModule );
                if ( module == NULL )
@@ -384,36 +395,13 @@ MingwBackend::GenerateHeader () const
 }
 
 void
-MingwBackend::GenerateProjectCFlagsMacro ( const char* assignmentOperation,
-                                           const IfableData& data ) const
-{
-       set<string> used_defs;
-
-       if ( data.includes.size () > 0 )
-               fprintf (
-                       fMakefile,
-                       "PROJECT_CFLAGS %s %s\n",
-                       assignmentOperation,
-                       MingwModuleHandler::GenerateGccIncludeParametersFromVector ( data.includes ).c_str ());
-
-       if ( data.defines.size () > 0 )
-               fprintf (
-                       fMakefile,
-                       "PROJECT_CDEFINES %s %s\n",
-                       assignmentOperation,
-                       MingwModuleHandler::GenerateGccDefineParametersFromVector ( data.defines, used_defs ).c_str ());
-}
-
-void
-MingwBackend::GenerateGlobalCFlagsAndProperties (
+MingwBackend::GenerateGlobalProperties (
        const char* assignmentOperation,
        const IfableData& data ) const
 {
-       size_t i;
-
-       for ( i = 0; i < data.properties.size(); i++ )
+       for ( std::map<std::string, Property*>::const_iterator p = data.properties.begin(); p != data.properties.end(); ++ p )
        {
-               Property& prop = *data.properties[i];
+               Property& prop = *p->second;
 
                if (!prop.isInternal)
                {
@@ -422,49 +410,6 @@ MingwBackend::GenerateGlobalCFlagsAndProperties (
                                prop.value.c_str() );
                }
        }
-
-       if ( data.includes.size() || data.defines.size() )
-       {
-               GenerateProjectCFlagsMacro ( assignmentOperation,
-                                            data );
-       }
-}
-
-void
-MingwBackend::GenerateProjectGccOptionsMacro ( const char* assignmentOperation,
-                                               IfableData& data ) const
-{
-       size_t i;
-
-       fprintf (
-               fMakefile,
-               "PROJECT_GCCOPTIONS %s",
-               assignmentOperation );
-
-       for ( i = 0; i < data.compilerFlags.size(); i++ )
-       {
-               if ( data.compilerFlags[i]->compiler == CompilerTypeDontCare )
-               {
-                       fprintf (
-                               fMakefile,
-                               " %s",
-                               data.compilerFlags[i]->flag.c_str() );
-               }
-       }
-
-       fprintf ( fMakefile, "\n" );
-}
-
-void
-MingwBackend::GenerateProjectGccOptions (
-       const char* assignmentOperation,
-       IfableData& data ) const
-{
-       if ( data.compilerFlags.size() )
-       {
-               GenerateProjectGccOptionsMacro ( assignmentOperation,
-                                                data );
-       }
 }
 
 string
@@ -484,25 +429,105 @@ MingwBackend::GenerateProjectLFLAGS () const
 void
 MingwBackend::GenerateGlobalVariables () const
 {
+       fputs ( "include tools$(SEP)rbuild$(SEP)backend$(SEP)mingw$(SEP)rules.mak\n", fMakefile );
+       fprintf ( fMakefile, "include tools$(SEP)rbuild$(SEP)backend$(SEP)mingw$(SEP)linkers$(SEP)%s.mak\n", ProjectNode.GetLinkerSet ().c_str () );
+       fprintf ( fMakefile, "include tools$(SEP)rbuild$(SEP)backend$(SEP)mingw$(SEP)compilers$(SEP)%s.mak\n", ProjectNode.GetCompilerSet ().c_str () );
+
+       if ( mscPath.length() )
+               fprintf ( fMakefile, "export RBUILD_CL_PATH=%s\n", mscPath.c_str () );
+
+       if ( mslinkPath.length() )
+               fprintf ( fMakefile, "export RBUILD_LINK_PATH=%s\n", mslinkPath.c_str () );
+
+       if ( configuration.Dependencies == FullDependencies )
+       {
+               fprintf ( fMakefile,
+                                 "ifeq ($(ROS_BUILDDEPS),)\n"
+                                 "ROS_BUILDDEPS:=%s\n"
+                                 "endif\n",
+                                 "full" );
+       }
+
        fprintf ( fMakefile,
                  "PREFIX := %s\n",
                  compilerPrefix.c_str () );
        fprintf ( fMakefile,
-                 "nasm := %s\n",
+                 "nasm := $(Q)%s\n",
                  nasmCommand.c_str () );
 
-       GenerateGlobalCFlagsAndProperties ( "=", ProjectNode.non_if_data );
-       GenerateProjectGccOptions ( "=", ProjectNode.non_if_data );
+       GenerateGlobalProperties ( "=", ProjectNode.non_if_data );
+
+       if ( ProjectNode.configuration.Compiler == GnuGcc )
+       {
+               fprintf ( fMakefile, "ifneq ($(OARCH),)\n" );
+               fprintf ( fMakefile, "PROJECT_ASFLAGS += -march=$(OARCH)\n" );
+               fprintf ( fMakefile, "PROJECT_CFLAGS += -march=$(OARCH)\n" );
+               fprintf ( fMakefile, "PROJECT_CXXFLAGS += -march=$(OARCH)\n" );
+               fprintf ( fMakefile, "endif\n" );
+               fprintf ( fMakefile, "ifneq ($(TUNE),)\n" );
+               fprintf ( fMakefile, "PROJECT_CFLAGS += -mtune=$(TUNE)\n" );
+               fprintf ( fMakefile, "PROJECT_CXXFLAGS += -mtune=$(TUNE)\n" );
+               fprintf ( fMakefile, "endif\n" );
+
+               if ( usePipe )
+               {
+                       fprintf ( fMakefile, "PROJECT_CFLAGS += -pipe\n" );
+                       fprintf ( fMakefile, "PROJECT_CXXFLAGS += -pipe\n" );
+                       fprintf ( fMakefile, "PROJECT_ASFLAGS += -pipe\n" );
+               }
+
+               // Would be nice to have our own C++ runtime
+               fputs ( "BUILTIN_CXXINCLUDES+= $(TARGET_CPPFLAGS)\n", fMakefile );
+       }
+
+       // Because RosBE gcc is built to suck
+       fputs ( "BUILTIN_HOST_CINCLUDES+= $(HOST_CFLAGS)\n", fMakefile );
+       fputs ( "BUILTIN_HOST_CPPINCLUDES+= $(HOST_CFLAGS)\n", fMakefile );
+       fputs ( "BUILTIN_HOST_CXXINCLUDES+= $(HOST_CPPFLAGS)\n", fMakefile );
 
-       fprintf ( fMakefile, "PROJECT_RCFLAGS := $(PROJECT_CFLAGS) $(PROJECT_CDEFINES)\n" );
-       fprintf ( fMakefile, "PROJECT_WIDLFLAGS := $(PROJECT_CFLAGS) $(PROJECT_CDEFINES)\n" );
+       MingwModuleHandler::GenerateParameters ( "PROJECT", "+=", ProjectNode.non_if_data );
+       MingwModuleHandler::GenerateParameters ( "PROJECT_HOST", "+=", ProjectNode.host_non_if_data );
+
+       // TODO: linker flags
        fprintf ( fMakefile, "PROJECT_LFLAGS := '$(shell ${TARGET_CC} -print-libgcc-file-name)' %s\n", GenerateProjectLFLAGS ().c_str () );
-       fprintf ( fMakefile, "PROJECT_LPPFLAGS := '$(shell ${TARGET_CPP} -print-file-name=libstdc++.a)' '$(shell ${TARGET_CPP} -print-file-name=libgcc.a)' '$(shell ${TARGET_CPP} -print-file-name=libmingw32.a)' '$(shell ${TARGET_CPP} -print-file-name=libmingwex.a)'\n" );
-       fprintf ( fMakefile, "PROJECT_CFLAGS += -Wall\n" );
-       fprintf ( fMakefile, "ifneq ($(OARCH),)\n" );
-       fprintf ( fMakefile, "PROJECT_CFLAGS += -march=$(OARCH)\n" );
-       fprintf ( fMakefile, "endif\n" );
-       fprintf ( fMakefile, "PROJECT_CFLAGS += $(PROJECT_GCCOPTIONS)\n" );
+       fprintf ( fMakefile, "PROJECT_LPPFLAGS := '$(shell ${TARGET_CPP} -print-file-name=libstdc++.a)' '$(shell ${TARGET_CPP} -print-file-name=libgcc.a)' '$(shell ${TARGET_CPP} -print-file-name=libmingw32.a)' '$(shell ${TARGET_CPP} -print-file-name=libmingwex.a)' '$(shell ${TARGET_CPP} -print-file-name=libcoldname.a)'\n" );
+       /* hack to get libgcc_eh.a, should check mingw version or something */
+       if (Environment::GetArch() == "amd64")
+       {
+           fprintf ( fMakefile, "PROJECT_LPPFLAGS += '$(shell ${TARGET_CPP} -print-file-name=libgcc_eh.a)'\n" );
+       }
+
+       // TODO: use symbolic names for module types
+       for ( size_t i = 0; i < sizeof(ModuleHandlerInformations) / sizeof(ModuleHandlerInformations[0]); ++ i )
+       {
+               if ( ModuleHandlerInformations[i].cflags && ModuleHandlerInformations[i].cflags[0] )
+               {
+                               fprintf ( fMakefile,
+                                                 "MODULETYPE%d_%sFLAGS:=%s\n",
+                                                 (int)i,
+                                                 "C",
+                                                 ModuleHandlerInformations[i].cflags );
+               }
+
+               if ( ModuleHandlerInformations[i].cflags && ModuleHandlerInformations[i].cflags[0] )
+               {
+                               fprintf ( fMakefile,
+                                                 "MODULETYPE%d_%sFLAGS:=%s\n",
+                                                 (int)i,
+                                                 "CXX",
+                                                 ModuleHandlerInformations[i].cflags );
+               }
+
+               if ( ModuleHandlerInformations[i].nasmflags && ModuleHandlerInformations[i].nasmflags[0] )
+               {
+                               fprintf ( fMakefile,
+                                                 "MODULETYPE%d_%sFLAGS:=%s\n",
+                                                 (int)i,
+                                                 "NASM",
+                                                 ModuleHandlerInformations[i].nasmflags );
+               }
+       }
+
        fprintf ( fMakefile, "\n" );
 }
 
@@ -517,10 +542,6 @@ MingwBackend::IncludeInAllTarget ( const Module& module ) const
                return false;
        if ( module.type == LiveIso )
                return false;
-       if ( module.type == IsoRegTest )
-               return false;
-       if ( module.type == LiveIsoRegTest )
-               return false;
        if ( module.type == Test )
                return false;
        if ( module.type == Alias )
@@ -676,7 +697,7 @@ MingwBackend::GenerateProxyMakefiles ()
 void
 MingwBackend::CheckAutomaticDependencies ()
 {
-       if ( configuration.AutomaticDependencies )
+       if ( configuration.Dependencies == AutomaticDependencies )
        {
                printf ( "Checking automatic dependencies..." );
                AutomaticDependency automaticDependency ( ProjectNode );
@@ -714,32 +735,60 @@ MingwBackend::DetectCompiler ()
        printf ( "Detecting compiler..." );
 
        bool detectedCompiler = false;
-       const string& ROS_PREFIXValue = Environment::GetVariable ( "ROS_PREFIX" );
-       if ( ROS_PREFIXValue.length () > 0 )
+       bool supportedCompiler = false;
+       string compilerVersion;
+
+       if ( ProjectNode.configuration.Compiler == GnuGcc )
        {
-               compilerPrefix = ROS_PREFIXValue;
-               compilerCommand = compilerPrefix + "-gcc";
-               detectedCompiler = TryToDetectThisCompiler ( compilerCommand );
-       }
+               const string& TARGET_CCValue = Environment::GetVariable ( "TARGET_CC" );
+               const string& ROS_PREFIXValue = Environment::GetVariable ( "ROS_PREFIX" );
+
+               if ( ROS_PREFIXValue.length () > 0 )
+               {
+                       compilerPrefix = "";
+                       compilerCommand = TARGET_CCValue;
+                       detectedCompiler = TryToDetectThisCompiler ( compilerCommand );
+               }
+
+               if ( !detectedCompiler )
+               {
+                       if ( ROS_PREFIXValue.length () > 0 )
+                       {
+                               compilerPrefix = ROS_PREFIXValue;
+                               compilerCommand = compilerPrefix + "-gcc";
+                               detectedCompiler = TryToDetectThisCompiler ( compilerCommand );
+                       }
+               }
 #if defined(WIN32)
-       if ( !detectedCompiler )
-       {
-               compilerPrefix = "";
-               compilerCommand = "gcc";
-               detectedCompiler = TryToDetectThisCompiler ( compilerCommand );
-       }
+               if ( !detectedCompiler )
+               {
+                       compilerPrefix = "";
+                       compilerCommand = "gcc";
+                       detectedCompiler = TryToDetectThisCompiler ( compilerCommand );
+               }
 #endif
-       if ( !detectedCompiler )
+               if ( !detectedCompiler )
+               {
+                       compilerPrefix = "mingw32";
+                       compilerCommand = compilerPrefix + "-gcc";
+                       detectedCompiler = TryToDetectThisCompiler ( compilerCommand );
+               }
+
+               if ( detectedCompiler )
+                       compilerVersion = GetCompilerVersion ( compilerCommand );
+
+               supportedCompiler = IsSupportedCompilerVersion ( compilerVersion );
+       }
+       else if ( ProjectNode.configuration.Compiler == MicrosoftC )
        {
-               compilerPrefix = "mingw32";
-               compilerCommand = compilerPrefix + "-gcc";
-               detectedCompiler = TryToDetectThisCompiler ( compilerCommand );
+               compilerCommand = "cl";
+               detectedCompiler = DetectMicrosoftCompiler ( compilerVersion, mscPath );
+               supportedCompiler = true; // TODO
        }
 
        if ( detectedCompiler )
        {
-               string compilerVersion = GetCompilerVersion ( compilerCommand );
-               if ( IsSupportedCompilerVersion ( compilerVersion ) )
+               if ( supportedCompiler )
                        printf ( "detected (%s %s)\n", compilerCommand.c_str (), compilerVersion.c_str() );
                else
                {
@@ -786,7 +835,7 @@ MingwBackend::GetVersionString ( const string& versionCommand )
        buffer[i] = '\0';
        pclose ( fp );
 
-       char separators[] = " ";
+       char separators[] = " ()";
        char *token;
        char *prevtoken = NULL;
 
@@ -941,34 +990,51 @@ MingwBackend::DetectBinutils ()
        printf ( "Detecting binutils..." );
 
        bool detectedBinutils = false;
-       const string& ROS_PREFIXValue = Environment::GetVariable ( "ROS_PREFIX" );
+       bool supportedBinutils = false;
+       string binutilsVersion;
 
-       if ( ROS_PREFIXValue.length () > 0 )
+       if ( ProjectNode.configuration.Linker == GnuLd )
        {
-               binutilsPrefix = ROS_PREFIXValue;
-               binutilsCommand = binutilsPrefix + "-ld";
-               manualBinutilsSetting = true;
-               detectedBinutils = true;
-       }
+               const string& ROS_PREFIXValue = Environment::GetVariable ( "ROS_PREFIX" );
+
+               if ( ROS_PREFIXValue.length () > 0 )
+               {
+                       binutilsPrefix = ROS_PREFIXValue;
+                       binutilsCommand = binutilsPrefix + "-ld";
+                       manualBinutilsSetting = true;
+                       detectedBinutils = true;
+               }
 #if defined(WIN32)
-       if ( !detectedBinutils )
-       {
-               binutilsPrefix = "";
-               binutilsCommand = "ld";
-               detectedBinutils = TryToDetectThisBinutils ( binutilsCommand );
-       }
+               if ( !detectedBinutils )
+               {
+                       binutilsPrefix = "";
+                       binutilsCommand = "ld";
+                       detectedBinutils = TryToDetectThisBinutils ( binutilsCommand );
+               }
 #endif
-       if ( !detectedBinutils )
+               if ( !detectedBinutils )
+               {
+                       binutilsPrefix = "mingw32";
+                       binutilsCommand = binutilsPrefix + "-ld";
+                       detectedBinutils = TryToDetectThisBinutils ( binutilsCommand );
+               }
+               if ( detectedBinutils )
+               {
+                       binutilsVersion = GetBinutilsVersionDate ( binutilsCommand );
+                       supportedBinutils = IsSupportedBinutilsVersion ( binutilsVersion );
+               }
+       }
+       else if ( ProjectNode.configuration.Linker == MicrosoftLink )
        {
-               binutilsPrefix = "mingw32";
-               binutilsCommand = binutilsPrefix + "-ld";
-               detectedBinutils = TryToDetectThisBinutils ( binutilsCommand );
+               compilerCommand = "link";
+               detectedBinutils = DetectMicrosoftLinker ( binutilsVersion, mslinkPath );
+               supportedBinutils = true; // TODO
        }
+
        if ( detectedBinutils )
        {
-               string binutilsVersion = GetBinutilsVersionDate ( binutilsCommand );
-               if ( IsSupportedBinutilsVersion ( binutilsVersion ) )
-                       printf ( "detected (%s %s)\n", binutilsCommand.c_str (), GetBinutilsVersion( binutilsCommand ).c_str() );
+               if ( supportedBinutils )
+                       printf ( "detected (%s %s)\n", binutilsCommand.c_str (), binutilsVersion.c_str() );
                else
                {
                        printf ( "detected (%s), but with unsupported version (%s)\n",
@@ -1010,33 +1076,38 @@ MingwBackend::DetectNetwideAssembler ()
 void
 MingwBackend::DetectPipeSupport ()
 {
-       printf ( "Detecting compiler -pipe support..." );
-
-       string pipe_detection = "tools" + sSep + "rbuild" + sSep + "backend" + sSep + "mingw" + sSep + "pipe_detection.c";
-       string pipe_detectionObjectFilename = ReplaceExtension ( pipe_detection,
-                                                                ".o" );
-       string command = ssprintf (
-               "%s -pipe -c %s -o %s 1>%s 2>%s",
-               FixSeparatorForSystemCommand(compilerCommand).c_str (),
-               pipe_detection.c_str (),
-               pipe_detectionObjectFilename.c_str (),
-               NUL,
-               NUL );
-       int exitcode = system ( command.c_str () );
-       FILE* f = fopen ( pipe_detectionObjectFilename.c_str (), "rb" );
-       if ( f )
+       if ( ProjectNode.configuration.Compiler == GnuGcc )
        {
-               usePipe = (exitcode == 0);
-               fclose ( f );
-               unlink ( pipe_detectionObjectFilename.c_str () );
+               printf ( "Detecting compiler -pipe support..." );
+
+               string pipe_detection = "tools" + sSep + "rbuild" + sSep + "backend" + sSep + "mingw" + sSep + "pipe_detection.c";
+               string pipe_detectionObjectFilename = ReplaceExtension ( pipe_detection,
+                                                                                                                                ".o" );
+               string command = ssprintf (
+                       "%s -pipe -c %s -o %s 1>%s 2>%s",
+                       FixSeparatorForSystemCommand(compilerCommand).c_str (),
+                       pipe_detection.c_str (),
+                       pipe_detectionObjectFilename.c_str (),
+                       NUL,
+                       NUL );
+               int exitcode = system ( command.c_str () );
+               FILE* f = fopen ( pipe_detectionObjectFilename.c_str (), "rb" );
+               if ( f )
+               {
+                       usePipe = (exitcode == 0);
+                       fclose ( f );
+                       unlink ( pipe_detectionObjectFilename.c_str () );
+               }
+               else
+                       usePipe = false;
+
+               if ( usePipe )
+                       printf ( "detected\n" );
+               else
+                       printf ( "not detected\n" );
        }
        else
                usePipe = false;
-
-       if ( usePipe )
-               printf ( "detected\n" );
-       else
-               printf ( "not detected\n" );
 }
 
 void
@@ -1044,7 +1115,7 @@ MingwBackend::DetectPCHSupport ()
 {
        printf ( "Detecting compiler pre-compiled header support..." );
 
-       if ( configuration.PrecompiledHeadersEnabled )
+       if ( configuration.PrecompiledHeadersEnabled && ProjectNode.configuration.Compiler == GnuGcc )
        {
                string path = "tools" + sSep + "rbuild" + sSep + "backend" + sSep + "mingw" + sSep + "pch_detection.h";
                string cmd = ssprintf (
@@ -1055,7 +1126,7 @@ MingwBackend::DetectPCHSupport ()
                        NUL );
                system ( cmd.c_str () );
                path += ".gch";
-       
+
                FILE* f = fopen ( path.c_str (), "rb" );
                if ( f )
                {
@@ -1093,9 +1164,9 @@ void
 MingwBackend::GetModuleInstallTargetFiles (
        vector<FileLocation>& out ) const
 {
-       for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
+       for ( std::map<std::string, Module*>::const_iterator p = ProjectNode.modules.begin (); p != ProjectNode.modules.end (); ++ p )
        {
-               const Module& module = *ProjectNode.modules[i];
+               const Module& module = *p->second;
                if ( !module.enabled )
                        continue;
                if ( module.install )
@@ -1154,9 +1225,9 @@ MingwBackend::GetAliasedModuleOrModule ( const Module& module ) const
 void
 MingwBackend::OutputModuleInstallTargets ()
 {
-       for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
+       for ( std::map<std::string, Module*>::const_iterator p = ProjectNode.modules.begin (); p != ProjectNode.modules.end (); ++ p )
        {
-               const Module& module = *ProjectNode.modules[i];
+               const Module& module = *p->second;
                if ( !module.enabled )
                        continue;
                if ( module.install )
@@ -1241,9 +1312,9 @@ void
 MingwBackend::GetModuleTestTargets (
        vector<string>& out ) const
 {
-       for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
+       for ( std::map<std::string, Module*>::const_iterator p = ProjectNode.modules.begin (); p != ProjectNode.modules.end (); ++ p )
        {
-               const Module& module = *ProjectNode.modules[i];
+               const Module& module = *p->second;
                if ( !module.enabled )
                        continue;
                if ( module.type == Test )