Copy riched20
[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 bool Verbose = false;
21
22 bool
23 ParseSwitch ( int argc, char** argv, int index )
24 {
25 char switchChar = argv[index][1];
26 switch ( switchChar )
27 {
28 case 'v':
29 Verbose = true;
30 break;
31 default:
32 printf ( "Unknown switch -%c",
33 switchChar );
34 return false;
35 }
36 return true;
37 }
38
39 bool
40 ParseArguments ( int argc, char** argv )
41 {
42 if ( argc < 2 )
43 return false;
44
45 for ( int i = 1; i < argc; i++ )
46 {
47 if ( argv[i][0] == '-' )
48 {
49 if ( !ParseSwitch ( argc, argv, i ) )
50 return false;
51 }
52 else
53 BuildSystem = argv[i];
54 }
55
56 return true;
57 }
58
59 int
60 main ( int argc, char** argv )
61 {
62 if ( !ParseArguments ( argc, argv ) )
63 {
64 printf ( "Generates project files for buildsystems\n\n" );
65 printf ( " rbuild [-v] buildsystem\n\n" );
66 printf ( "Switches:\n" );
67 printf ( " -v Be verbose\n" );
68 printf ( "\n" );
69 printf ( " buildsystem Target build system. Can be one of:\n" );
70 printf ( " mingw MinGW\n" );
71 printf ( " devcpp DevC++\n" );
72 return 1;
73 }
74 try
75 {
76 string projectFilename ( "ReactOS.xml" );
77 printf ( "Reading build files..." );
78 Project project ( projectFilename );
79 printf ( "done\n" );
80 project.WriteConfigurationFile ();
81 project.ExecuteInvocations ();
82 Backend* backend = Backend::Factory::Create ( BuildSystem,
83 project,
84 Verbose );
85 backend->Process ();
86 delete backend;
87
88 return 0;
89 }
90 catch (Exception& ex)
91 {
92 printf ( "%s\n",
93 ex.Message.c_str () );
94 return 1;
95 }
96 }