Show execution time of tests
[reactos.git] / reactos / tools / rbuild / backend / mingw / mingw.cpp
index 4c709bb..aeeadd9 100644 (file)
@@ -227,6 +227,7 @@ MingwBackend::MingwBackend ( Project& project,
          outputDirectory ( new Directory ( "$(OUTPUT)" ) ),
          installDirectory ( new Directory ( "$(INSTALL)" ) )
 {
+       compilerPrefix = "";
 }
 
 MingwBackend::~MingwBackend()
@@ -255,6 +256,8 @@ MingwBackend::ProcessModules ()
        for ( i = 0; i < ProjectNode.modules.size (); i++ )
        {
                Module& module = *ProjectNode.modules[i];
+               if ( !module.enabled )
+                       continue;
                MingwModuleHandler* h = MingwModuleHandler::InstanciateHandler (
                        module,
                        this );
@@ -290,16 +293,49 @@ MingwBackend::ProcessModules ()
                h.GenerateInvocations ();
                h.GenerateCleanTarget ();
                h.GenerateInstallTarget ();
+               h.GenerateDependsTarget ();
                delete v[i];
        }
 
        printf ( "done\n" );
 }
-       
+
 void
 MingwBackend::Process ()
+{
+       if ( configuration.CheckDependenciesForModuleOnly )
+               CheckAutomaticDependenciesForModuleOnly ();
+       else
+               ProcessNormal ();
+}
+
+void
+MingwBackend::CheckAutomaticDependenciesForModuleOnly ()
+{
+       if ( configuration.AutomaticDependencies )
+       {
+               Module* module = ProjectNode.LocateModule ( configuration.CheckDependenciesForModuleOnlyModule );
+               if ( module == NULL )
+               {
+                       printf ( "Module '%s' does not exist\n",
+                               configuration.CheckDependenciesForModuleOnlyModule.c_str () );
+                       return;
+               }
+               
+               printf ( "Checking automatic dependencies for module '%s'...",
+                        module->name.c_str () );
+               AutomaticDependency automaticDependency ( ProjectNode );
+               automaticDependency.CheckAutomaticDependencies ( *module,
+                                                                configuration.Verbose );
+               printf ( "done\n" );
+       }
+}
+
+void
+MingwBackend::ProcessNormal ()
 {
        DetectCompiler ();
+       DetectNetwideAssembler ();
        DetectPipeSupport ();
        DetectPCHSupport ();
        CreateMakefile ();
@@ -482,6 +518,13 @@ MingwBackend::GenerateProjectLFLAGS () const
 void
 MingwBackend::GenerateGlobalVariables () const
 {
+       fprintf ( fMakefile,
+                 "PREFIX := %s\n",
+                 compilerPrefix.c_str () );
+       fprintf ( fMakefile,
+                 "nasm := %s\n",
+                 nasmCommand.c_str () );
+
        GenerateGlobalCFlagsAndProperties ( "=", ProjectNode.non_if_data );
        GenerateProjectGccOptions ( "=", ProjectNode.non_if_data );
 
@@ -538,6 +581,8 @@ MingwBackend::GetBuildToolDependencies () const
        for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
        {
                Module& module = *ProjectNode.modules[i];
+               if ( !module.enabled )
+                       continue;
                if ( module.type == BuildTool )
                {
                        if ( dependencies.length () > 0 )
@@ -563,7 +608,7 @@ MingwBackend::GenerateRegTestsRunTarget () const
        fprintf ( fMakefile,
                  "REGTESTS_RUN_TARGET = regtests.dll\n" );
        fprintf ( fMakefile,
-                 "$(REGTESTS_RUN_TARGET):\n" );
+                 "$(REGTESTS_RUN_TARGET): $(REGTESTS_TARGET)\n" );
        fprintf ( fMakefile,
                  "\t$(cp) $(REGTESTS_TARGET) $(REGTESTS_RUN_TARGET)\n" );
        fprintf ( fMakefile, "\n" );
@@ -598,8 +643,7 @@ MingwBackend::GenerateXmlBuildFilesMacro() const
                        else
                        {
                                fprintf ( fMakefile,
-                                         " \\\n",
-                                         xmlbuildFilenames.c_str () );
+                                         " \\\n" );
                        }
                        xmlbuildFilenames.resize ( 0 );
                }
@@ -633,12 +677,22 @@ MingwBackend::GenerateTestSupportCode ()
        printf ( "done\n" );
 }
 
+string
+MingwBackend::GetProxyMakefileTree () const
+{
+       if ( configuration.GenerateProxyMakefilesInSourceTree )
+               return "";
+       else
+               return Environment::GetOutputPath ();
+}
+
 void
 MingwBackend::GenerateProxyMakefiles ()
 {
        printf ( "Generating proxy makefiles..." );
        ProxyMakefile proxyMakefile ( ProjectNode );
-       proxyMakefile.GenerateProxyMakefiles ( configuration.Verbose );
+       proxyMakefile.GenerateProxyMakefiles ( configuration.Verbose,
+                                              GetProxyMakefileTree () );
        printf ( "done\n" );
 }
 
@@ -649,7 +703,6 @@ MingwBackend::CheckAutomaticDependencies ()
        {
                printf ( "Checking automatic dependencies..." );
                AutomaticDependency automaticDependency ( ProjectNode );
-               automaticDependency.Process ();
                automaticDependency.CheckAutomaticDependencies ( configuration.Verbose );
                printf ( "done\n" );
        }
@@ -679,8 +732,9 @@ bool
 MingwBackend::TryToDetectThisCompiler ( const string& compiler )
 {
        string command = ssprintf (
-               "%s -v 2>%s",
+               "%s -v 1>%s 2>%s",
                compiler.c_str (),
+               NUL,
                NUL );
        int exitcode = system ( command.c_str () );
        return (exitcode == 0);
@@ -695,19 +749,22 @@ MingwBackend::DetectCompiler ()
        const string& ROS_PREFIXValue = Environment::GetVariable ( "ROS_PREFIX" );
        if ( ROS_PREFIXValue.length () > 0 )
        {
-               compilerCommand = ROS_PREFIXValue + "-gcc";
+               compilerPrefix = ROS_PREFIXValue;
+               compilerCommand = compilerPrefix + "-gcc";
                detectedCompiler = TryToDetectThisCompiler ( compilerCommand );
        }
 #if defined(WIN32)
        if ( !detectedCompiler )
        {
+               compilerPrefix = "";
                compilerCommand = "gcc";
                detectedCompiler = TryToDetectThisCompiler ( compilerCommand );
        }
 #endif
        if ( !detectedCompiler )
        {
-               compilerCommand = "mingw32-gcc";
+               compilerPrefix = "mingw32";
+               compilerCommand = compilerPrefix + "-gcc";
                detectedCompiler = TryToDetectThisCompiler ( compilerCommand );
        }
        if ( detectedCompiler )
@@ -716,6 +773,38 @@ MingwBackend::DetectCompiler ()
                printf ( "not detected\n" );
 }
 
+bool
+MingwBackend::TryToDetectThisNetwideAssembler ( const string& assembler )
+{
+       string command = ssprintf (
+               "%s -h 1>%s 2>%s",
+               assembler.c_str (),
+               NUL,
+               NUL );
+       int exitcode = system ( command.c_str () );
+       return (exitcode == 0);
+}
+
+void
+MingwBackend::DetectNetwideAssembler ()
+{
+       printf ( "Detecting netwide assembler..." );
+
+       nasmCommand = "nasm";
+       bool detectedNasm = TryToDetectThisNetwideAssembler ( nasmCommand );
+#if defined(WIN32)
+       if ( !detectedNasm )
+       {
+               nasmCommand = "nasmw";
+               detectedNasm = TryToDetectThisNetwideAssembler ( nasmCommand );
+       }
+#endif
+       if ( detectedNasm )
+               printf ( "detected (%s)\n", nasmCommand.c_str () );
+       else
+               printf ( "not detected\n" );
+}
+
 void
 MingwBackend::DetectPipeSupport ()
 {
@@ -725,10 +814,11 @@ MingwBackend::DetectPipeSupport ()
        string pipe_detectionObjectFilename = ReplaceExtension ( pipe_detection,
                                                                 ".o" );
        string command = ssprintf (
-               "%s -pipe -c %s -o %s 2>%s",
+               "%s -pipe -c %s -o %s 1>%s 2>%s",
                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" );
@@ -754,9 +844,10 @@ MingwBackend::DetectPCHSupport ()
 
        string path = "tools" SSEP "rbuild" SSEP "backend" SSEP "mingw" SSEP "pch_detection.h";
        string cmd = ssprintf (
-               "%s -c %s 2>%s",
+               "%s -c %s 1>%s 2>%s",
                compilerCommand.c_str (),
                path.c_str (),
+               NUL,
                NUL );
        system ( cmd.c_str () );
        path += ".gch";
@@ -799,6 +890,8 @@ MingwBackend::GetModuleInstallTargetFiles (
        for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
        {
                const Module& module = *ProjectNode.modules[i];
+               if ( !module.enabled )
+                       continue;
                if ( module.installName.length () > 0 )
                {
                        string targetFilenameNoFixup;
@@ -869,14 +962,16 @@ MingwBackend::OutputModuleInstallTargets ()
        for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
        {
                const Module& module = *ProjectNode.modules[i];
+               if ( !module.enabled )
+                       continue;
                if ( module.installName.length () > 0 )
                {
                        string sourceFilename = MingwModuleHandler::PassThruCacheDirectory (
                                NormalizeFilename ( module.GetPath () ),
                                outputDirectory );
                        OutputInstallTarget ( sourceFilename,
-                                         module.installName,
-                                         module.installBase );
+                                             module.installName,
+                                             module.installBase );
                }
        }
 }
@@ -958,6 +1053,8 @@ MingwBackend::GetModuleTestTargets (
        for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
        {
                const Module& module = *ProjectNode.modules[i];
+               if ( !module.enabled )
+                       continue;
                if ( module.type == Test )
                        out.push_back ( module.name );
        }