Clean-as-you-go mode to remove generated files as soon as possible to minimize disk...
[reactos.git] / reactos / tools / rbuild / rbuild.cpp
1 // rbuild.cpp
2
3 #include "pch.h"
4 #include <typeinfo>
5
6 #include <stdio.h>
7 #ifdef WIN32
8 #include <io.h>
9 #endif
10 #include <assert.h>
11
12 #include "rbuild.h"
13 #include "backend/backend.h"
14 #include "backend/mingw/mingw.h"
15
16 using std::string;
17 using std::vector;
18
19 static string BuildSystem;
20 static string RootXmlFile = "ReactOS.xml";
21 static bool Verbose = false;
22 static bool CleanAsYouGo = false;
23
24 bool
25 ParseSwitch ( int argc, char** argv, int index )
26 {
27 char switchChar = argv[index][1];
28 switch ( switchChar )
29 {
30 case 'v':
31 Verbose = true;
32 break;
33 case 'c':
34 CleanAsYouGo = true;
35 break;
36 case 'r':
37 RootXmlFile = string(&argv[index][2]);
38 break;
39 default:
40 printf ( "Unknown switch -%c",
41 switchChar );
42 return false;
43 }
44 return true;
45 }
46
47 bool
48 ParseArguments ( int argc, char** argv )
49 {
50 if ( argc < 2 )
51 return false;
52
53 for ( int i = 1; i < argc; i++ )
54 {
55 if ( argv[i][0] == '-' )
56 {
57 if ( !ParseSwitch ( argc, argv, i ) )
58 return false;
59 }
60 else
61 BuildSystem = argv[i];
62 }
63
64 return true;
65 }
66
67 int
68 main ( int argc, char** argv )
69 {
70 if ( !ParseArguments ( argc, argv ) )
71 {
72 printf ( "Generates project files for buildsystems\n\n" );
73 printf ( " rbuild [-v] [-rfile.xml] buildsystem\n\n" );
74 printf ( "Switches:\n" );
75 printf ( " -v Be verbose\n" );
76 printf ( " -c Clean as you go. Delete generated files as soon as they are not needed anymore\n" );
77 printf ( " -rfile.xml Name of the root xml file. Default is ReactOS.xml\n" );
78 printf ( "\n" );
79 printf ( " buildsystem Target build system. Can be one of:\n" );
80 printf ( " mingw MinGW\n" );
81 printf ( " devcpp DevC++\n" );
82 return 1;
83 }
84 try
85 {
86 string projectFilename ( RootXmlFile );
87 printf ( "Reading build files..." );
88 Project project ( projectFilename );
89 printf ( "done\n" );
90 project.WriteConfigurationFile ();
91 project.ExecuteInvocations ();
92 Backend* backend = Backend::Factory::Create ( BuildSystem,
93 project,
94 Verbose,
95 CleanAsYouGo );
96 backend->Process ();
97 delete backend;
98
99 return 0;
100 }
101 catch (Exception& ex)
102 {
103 printf ( "%s\n",
104 ex.Message.c_str () );
105 return 1;
106 }
107 }