changed windres back to rc
[reactos.git] / reactos / tools / rbuild / rbuild.cpp
1 /*
2 * Copyright (C) 2005 Casper S. Hornstrup
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18 #include "pch.h"
19 #include <typeinfo>
20
21 #include <stdio.h>
22 #ifdef WIN32
23 #include <io.h>
24 #endif
25 #include <assert.h>
26
27 #include "rbuild.h"
28 #include "backend/backend.h"
29 #include "backend/mingw/mingw.h"
30
31 using std::string;
32 using std::vector;
33
34 static string BuildSystem;
35 static string RootXmlFile = "ReactOS.xml";
36 static Configuration configuration;
37
38 bool
39 ParseAutomaticDependencySwitch ( char switchChar2,
40 char* switchStart )
41 {
42 switch ( switchChar2 )
43 {
44 case 'd':
45 configuration.AutomaticDependencies = false;
46 break;
47 case 'm':
48 if ( strlen ( switchStart ) <= 3 )
49 {
50 printf ( "Switch -dm requires a module name\n" );
51 return false;
52 }
53 configuration.CheckDependenciesForModuleOnly = true;
54 configuration.CheckDependenciesForModuleOnlyModule = string(&switchStart[3]);
55 break;
56 default:
57 printf ( "Unknown switch -d%c\n",
58 switchChar2 );
59 return false;
60 }
61 return true;
62 }
63
64 bool
65 ParseMakeSwitch ( char switchChar2 )
66 {
67 switch ( switchChar2 )
68 {
69 case 'i':
70 configuration.MakeHandlesInstallDirectories = true;
71 break;
72 default:
73 printf ( "Unknown switch -m%c\n",
74 switchChar2 );
75 return false;
76 }
77 return true;
78 }
79
80 bool
81 ParseProxyMakefileSwitch ( char switchChar2 )
82 {
83 switch ( switchChar2 )
84 {
85 case 's':
86 configuration.GenerateProxyMakefilesInSourceTree = true;
87 break;
88 default:
89 printf ( "Unknown switch -p%c\n",
90 switchChar2 );
91 return false;
92 }
93 return true;
94 }
95
96 bool
97 ParseSwitch ( int argc, char** argv, int index )
98 {
99 char switchChar = strlen ( argv[index] ) > 1 ? argv[index][1] : ' ';
100 char switchChar2 = strlen ( argv[index] ) > 2 ? argv[index][2] : ' ';
101 switch ( switchChar )
102 {
103 case 'v':
104 configuration.Verbose = true;
105 break;
106 case 'c':
107 configuration.CleanAsYouGo = true;
108 break;
109 case 'd':
110 return ParseAutomaticDependencySwitch ( switchChar2,
111 argv[index] );
112 case 'r':
113 RootXmlFile = string(&argv[index][2]);
114 break;
115 case 'm':
116 return ParseMakeSwitch ( switchChar2 );
117 case 'p':
118 return ParseProxyMakefileSwitch ( switchChar2 );
119 default:
120 printf ( "Unknown switch -%c\n",
121 switchChar );
122 return false;
123 }
124 return true;
125 }
126
127 bool
128 ParseArguments ( int argc, char** argv )
129 {
130 if ( argc < 2 )
131 return false;
132
133 for ( int i = 1; i < argc; i++ )
134 {
135 if ( argv[i][0] == '-' )
136 {
137 if ( !ParseSwitch ( argc, argv, i ) )
138 return false;
139 }
140 else
141 BuildSystem = argv[i];
142 }
143
144 return true;
145 }
146
147 int
148 main ( int argc, char** argv )
149 {
150 if ( !ParseArguments ( argc, argv ) )
151 {
152 printf ( "Generates project files for buildsystems\n\n" );
153 printf ( " rbuild [switches] buildsystem\n" );
154 printf ( " rbuild msvc\n" );
155 printf ( "Switches:\n" );
156 printf ( " -v Be verbose.\n" );
157 printf ( " -c Clean as you go. Delete generated files as soon as they are not\n" );
158 printf ( " needed anymore.\n" );
159 printf ( " -dd Disable automatic dependencies.\n" );
160 printf ( " -dm{module} Check only automatic dependencies for this module.\n" );
161 printf ( " -r{file.xml} Name of the root xml file. Default is ReactOS.xml.\n" );
162 printf ( " -mi Let make handle creation of install directories. Rbuild will\n" );
163 printf ( " not generate the directories.\n" );
164 printf ( " -ps Generate proxy makefiles in source tree instead of the output.\n" );
165 printf ( " tree.\n" );
166 printf ( "\n" );
167 printf ( " buildsystem Target build system. Can be one of:\n" );
168 printf ( " mingw MinGW\n" );
169 printf ( " devcpp DevC++\n\n" );
170 printf ( " msvc Generates dsp files for MSVC" );
171 return 1;
172 }
173 try
174 {
175 string projectFilename ( RootXmlFile );
176 printf ( "Reading build files..." );
177 Project project ( projectFilename );
178 printf ( "done\n" );
179 project.WriteConfigurationFile ();
180 project.ExecuteInvocations ();
181 Backend* backend = Backend::Factory::Create ( BuildSystem,
182 project,
183 configuration );
184 backend->Process ();
185 delete backend;
186
187 return 0;
188 }
189 catch (Exception& ex)
190 {
191 printf ( "%s\n",
192 ex.Message.c_str () );
193 return 1;
194 }
195 }