Fix GCC detection in RBuild (first check TARGET_CC).
[reactos.git] / reactos / tools / rbuild / backend / mingw / mingw.cpp
index 0436347..4673d4d 100644 (file)
@@ -59,8 +59,6 @@ const struct ModuleHandlerInformations ModuleHandlerInformations[] = {
        { HostFalse, "", "", "" }, // Win32SCR
        { HostFalse, "", "", "" }, // IdlHeader
        { HostFalse, "", "", "" }, // IdlInterface
-       { HostFalse, "", "", "" }, // IsoRegTest
-       { HostFalse, "", "", "" }, // LiveIsoRegTest
        { HostFalse, "", "", "" }, // EmbeddedTypeLib
        { HostFalse, "", "", "" }, // ElfExecutable
        { HostFalse, "", "", "" }, // RpcProxy
@@ -70,6 +68,9 @@ const struct ModuleHandlerInformations ModuleHandlerInformations[] = {
        { HostFalse, "", "", "" }, // MessageHeader
 };
 
+static std::string mscPath;
+static std::string mslinkPath;
+
 string
 MingwBackend::GetFullPath ( const FileLocation& file ) const
 {
@@ -161,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 );
@@ -182,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];
@@ -426,6 +433,12 @@ MingwBackend::GenerateGlobalVariables () const
        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,
@@ -444,29 +457,27 @@ MingwBackend::GenerateGlobalVariables () const
 
        GenerateGlobalProperties ( "=", ProjectNode.non_if_data );
 
-       fprintf ( fMakefile, "PROJECT_CFLAGS += -Wall\n" );
-       fprintf ( fMakefile, "PROJECT_CXXFLAGS += -Wall\n" );
-       fprintf ( fMakefile, "ifneq ($(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" );
-
-       fprintf ( fMakefile, "PROJECT_CFLAGS += -g%s\n", Environment::GetArch() == "amd64" ? "dwarf-2" : "stabs+" );
-       fprintf ( fMakefile, "PROJECT_CXXFLAGS += -g%s\n", Environment::GetArch() == "amd64" ? "dwarf-2" : "stabs+" );
-       fprintf ( fMakefile, "PROJECT_ASFLAGS += -g%s\n", Environment::GetArch() == "amd64" ? "dwarf-2" : "stabs+" );
+       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" );
 
-       MingwModuleHandler::GenerateParameters ( "PROJECT", "+=", ProjectNode.non_if_data );
-       MingwModuleHandler::GenerateParameters ( "PROJECT_HOST", "+=", ProjectNode.host_non_if_data );
+               if ( usePipe )
+               {
+                       fprintf ( fMakefile, "PROJECT_CFLAGS += -pipe\n" );
+                       fprintf ( fMakefile, "PROJECT_CXXFLAGS += -pipe\n" );
+                       fprintf ( fMakefile, "PROJECT_ASFLAGS += -pipe\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
@@ -474,8 +485,8 @@ MingwBackend::GenerateGlobalVariables () const
        fputs ( "BUILTIN_HOST_CPPINCLUDES+= $(HOST_CFLAGS)\n", fMakefile );
        fputs ( "BUILTIN_HOST_CXXINCLUDES+= $(HOST_CPPFLAGS)\n", fMakefile );
 
-       // Would be nice to have our own C++ runtime
-       fputs ( "BUILTIN_CXXINCLUDES+= $(TARGET_CPPFLAGS)\n", fMakefile );
+       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 () );
@@ -493,7 +504,7 @@ MingwBackend::GenerateGlobalVariables () const
                {
                                fprintf ( fMakefile,
                                                  "MODULETYPE%d_%sFLAGS:=%s\n",
-                                                 i,
+                                                 (int)i,
                                                  "C",
                                                  ModuleHandlerInformations[i].cflags );
                }
@@ -502,7 +513,7 @@ MingwBackend::GenerateGlobalVariables () const
                {
                                fprintf ( fMakefile,
                                                  "MODULETYPE%d_%sFLAGS:=%s\n",
-                                                 i,
+                                                 (int)i,
                                                  "CXX",
                                                  ModuleHandlerInformations[i].cflags );
                }
@@ -511,7 +522,7 @@ MingwBackend::GenerateGlobalVariables () const
                {
                                fprintf ( fMakefile,
                                                  "MODULETYPE%d_%sFLAGS:=%s\n",
-                                                 i,
+                                                 (int)i,
                                                  "NASM",
                                                  ModuleHandlerInformations[i].nasmflags );
                }
@@ -531,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 )
@@ -733,13 +740,25 @@ MingwBackend::DetectCompiler ()
 
        if ( ProjectNode.configuration.Compiler == GnuGcc )
        {
+               const string& TARGET_CCValue = Environment::GetVariable ( "TARGET_CC" );
                const string& ROS_PREFIXValue = Environment::GetVariable ( "ROS_PREFIX" );
+
                if ( ROS_PREFIXValue.length () > 0 )
                {
-                       compilerPrefix = ROS_PREFIXValue;
-                       compilerCommand = compilerPrefix + "-gcc";
+                       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 )
                {
@@ -762,7 +781,8 @@ MingwBackend::DetectCompiler ()
        }
        else if ( ProjectNode.configuration.Compiler == MicrosoftC )
        {
-               detectedCompiler = DetectMicrosoftCompiler ( compilerVersion );
+               compilerCommand = "cl";
+               detectedCompiler = DetectMicrosoftCompiler ( compilerVersion, mscPath );
                supportedCompiler = true; // TODO
        }
 
@@ -1006,7 +1026,8 @@ MingwBackend::DetectBinutils ()
        }
        else if ( ProjectNode.configuration.Linker == MicrosoftLink )
        {
-               detectedBinutils = DetectMicrosoftLinker ( binutilsVersion );
+               compilerCommand = "link";
+               detectedBinutils = DetectMicrosoftLinker ( binutilsVersion, mslinkPath );
                supportedBinutils = true; // TODO
        }
 
@@ -1085,6 +1106,8 @@ MingwBackend::DetectPipeSupport ()
                else
                        printf ( "not detected\n" );
        }
+       else
+               usePipe = false;
 }
 
 void