Add ROS_ARCH environment variable
[reactos.git] / reactos / tools / rbuild / rbuild.cpp
index d7edd13..abe255f 100644 (file)
@@ -17,6 +17,7 @@
  */
 #include "pch.h"
 #include <typeinfo>
+#include <algorithm>
 
 #include <stdio.h>
 #ifdef WIN32
@@ -32,19 +33,13 @@ using std::string;
 using std::vector;
 
 static string BuildSystem;
-static string RootXmlFile = "ReactOS.xml";
+static string RootXmlFile;
 static Configuration configuration;
 
-string ExePrefix;
-string ExePostfix;
-string sSep;
-string sBadSep;
-char cSep;
-char cBadSep;
-
 bool
-ParseAutomaticDependencySwitch ( char switchChar2,
-                                    char* switchStart )
+ParseAutomaticDependencySwitch (
+       char switchChar2,
+       char* switchStart )
 {
        switch ( switchChar2 )
        {
@@ -68,11 +63,31 @@ ParseAutomaticDependencySwitch ( char switchChar2,
        return true;
 }
 
+bool
+ParseCompilationUnitSwitch (
+       char switchChar2,
+       char* switchStart )
+{
+       switch ( switchChar2 )
+       {
+               case 'd':
+                       configuration.CompilationUnitsEnabled = false;
+                       break;
+               default:
+                       printf ( "Unknown switch -u%c\n",
+                                switchChar2 );
+                       return false;
+       }
+       return true;
+}
 
 bool
-ParseVCProjectSwitch ( char switchChar2,
-                      char* switchStart )
+ParseVCProjectSwitch (
+       char switchChar2,
+       char* switchStart )
 {
+       string temp;
+
        switch ( switchChar2 )
        {
                case 's':
@@ -95,6 +110,23 @@ ParseVCProjectSwitch ( char switchChar2,
                                configuration.VSProjectVersion.append("0");
 
                        break;
+               case 'c':
+                       configuration.VSConfigurationType = string (&switchStart[3]);
+                       configuration.InstallFiles = true;
+                       break;
+               case 'o':
+                       if ( strlen ( switchStart ) <= 3 )
+                       {
+                               printf ( "Invalid switch\n" );
+                               return false;
+                       }
+                       temp = string (&switchStart[3]);
+                       if ( temp.find ("configuration") != string::npos )
+                               configuration.UseConfigurationInPath = true;
+                       
+                       if ( temp.find ("version") != string::npos )
+                               configuration.UseVSVersionInPath = true;
+                       break;
                default:
                        printf ( "Unknown switch -d%c\n",
                                 switchChar2 );
@@ -143,9 +175,12 @@ ParseSwitch ( int argc, char** argv, int index )
        switch ( switchChar )
        {
                case 'v':
-                       if (switchChar2 == 's')
-                               return ParseVCProjectSwitch ( switchChar2,
-                                                             argv[index] );
+                       if (switchChar2 == 's' || switchChar2 == 'c' || switchChar2 == 'o')
+                       {
+                               return ParseVCProjectSwitch (
+                                       switchChar2,
+                                       argv[index] );
+                       }
                        else
                                configuration.Verbose = true;
                        break;
@@ -153,8 +188,13 @@ ParseSwitch ( int argc, char** argv, int index )
                        configuration.CleanAsYouGo = true;
                        break;
                case 'd':
-                       return ParseAutomaticDependencySwitch ( switchChar2,
-                                                               argv[index] );
+                       return ParseAutomaticDependencySwitch (
+                               switchChar2,
+                               argv[index] );
+               case 'u':
+                       return ParseCompilationUnitSwitch (
+                               switchChar2,
+                               argv[index] );
                case 'r':
                        RootXmlFile = string(&argv[index][2]);
                        break;
@@ -163,8 +203,9 @@ ParseSwitch ( int argc, char** argv, int index )
                case 'p':
                        return ParseProxyMakefileSwitch ( switchChar2 );
                default:
-                       printf ( "Unknown switch -%c\n",
-                                switchChar );
+                       printf (
+                               "Unknown switch -%c\n",
+                               switchChar );
                        return false;
        }
        return true;
@@ -193,86 +234,66 @@ ParseArguments ( int argc, char** argv )
 int
 main ( int argc, char** argv )
 {
-        char *SepValue, *ExePostfixValue, *ExePrefixValue;;
-
-        SepValue = getenv("SEP");
-        if (SepValue && (0 == strcmp(SepValue, DEF_SSEP) || 0 == strcmp(SepValue, DEF_SBAD_SEP)))
-        {
-            cSep = SepValue[0];
-            sSep = SepValue;
-        }
-        else
-        {
-            cSep = DEF_CSEP;
-            sSep = DEF_SSEP;
-        }
-        if (cSep == DEF_CSEP)
-        {
-            cBadSep = DEF_CBAD_SEP;
-            sBadSep = DEF_SBAD_SEP;
-        }
-        else
-        {
-            cBadSep = DEF_CSEP;
-            sBadSep = DEF_SSEP;
-        }
-        ExePostfixValue = getenv("EXEPOSTFIX");
-        ExePrefixValue = getenv("EXEPREFIX");
-        if ((ExePostfixValue == NULL || 0 == strlen(ExePostfixValue)) &&
-            (ExePrefixValue == NULL || 0 == strlen(ExePrefixValue)))
-        {
-            ExePostfix = DEF_EXEPOSTFIX;
-            ExePrefix = DEF_EXEPREFIX;
-        }
-        else
-        {
-            ExePostfix = ExePostfixValue ? ExePostfixValue : "";
-            ExePrefix = ExePrefixValue ? ExePrefixValue : "";
-        }
+       InitializeEnvironment ();
 
        if ( !ParseArguments ( argc, argv ) )
        {
                printf ( "Generates project files for buildsystems\n\n" );
-               printf ( "  rbuild [switches] buildsystem\n\n" );
+               printf ( "  rbuild [switches] -r{rootfile.rbuild} buildsystem\n\n" );
                printf ( "Switches:\n" );
                printf ( "  -v            Be verbose.\n" );
                printf ( "  -c            Clean as you go. Delete generated files as soon as they are not\n" );
                printf ( "                needed anymore.\n" );
                printf ( "  -dd           Disable automatic dependencies.\n" );
                printf ( "  -dm{module}   Check only automatic dependencies for this module.\n" );
-               printf ( "  -r{file.xml}  Name of the root xml file. Default is ReactOS.xml.\n" );
+               printf ( "  -ud           Disable multiple source files per compilation unit.\n" );
                printf ( "  -mi           Let make handle creation of install directories. Rbuild will\n" );
                printf ( "                not generate the directories.\n" );
                printf ( "  -ps           Generate proxy makefiles in source tree instead of the output.\n" );
                printf ( "                tree.\n" );
                printf ( "  -vs{version}  Version of MS VS project files. Default is %s.\n", MS_VS_DEF_VERSION );
+               printf ( "  -vo{version|configuration} Adds subdirectory path to the default Intermediate-Outputdirectory.\n" );
                printf ( "\n" );
                printf ( "  buildsystem   Target build system. Can be one of:\n" );
-               printf ( "                 mingw   MinGW\n" );
-               printf ( "                 devcpp  DevC++\n" );
-               printf ( "                 msvc    MS Visual Studio\n" );
+
+               std::map<std::string,Backend::Factory*>::iterator iter;
+               for (iter = Backend::Factory::map_begin(); iter != Backend::Factory::map_end(); iter++)
+               {
+                       Backend::Factory *factory = iter->second;
+                       printf ( "                %-10s %s\n", factory->Name(), factory->Description());
+               }
                return 1;
        }
        try
        {
+               if ( RootXmlFile.length () == 0 )
+                       throw MissingArgumentException ( "-r" );
+
                string projectFilename ( RootXmlFile );
+
                printf ( "Reading build files..." );
-               Project project ( projectFilename );
+               Project project ( configuration, projectFilename );
                printf ( "done\n" );
+
+               project.SetBackend ( Backend::Factory::Create (
+                       BuildSystem,
+                       project,
+                       configuration ) );
+
                project.WriteConfigurationFile ();
                project.ExecuteInvocations ();
-               Backend* backend = Backend::Factory::Create ( BuildSystem,
-                                                             project,
-                                                             configuration );
-               backend->Process ();
-               delete backend;
+               project.GetBackend().Process();
 
                return 0;
        }
-       catch (Exception& ex)
+       catch ( Exception& ex )
+       {
+               printf ( "%s\n", (*ex).c_str () );
+               return 1;
+       }
+       catch ( XMLException& ex )
        {
-               printf ( "%s\n",
-                        ex.Message.c_str () );
+               printf ( "%s\n", (*ex).c_str () );
                return 1;
        }
 }