add a 'unicode' property to modules (not yet supported by mingw, need to add a librar...
[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
65 bool
66 ParseVCProjectSwitch ( char switchChar2,
67 char* switchStart )
68 {
69 switch ( switchChar2 )
70 {
71 case 's':
72 if ( strlen ( switchStart ) <= 3 )
73 {
74 printf ( "Switch -dm requires a module name\n" );
75 return false;
76 }
77 configuration.VSProjectVersion = string(&switchStart[3]);
78
79 if (configuration.VSProjectVersion.at(0) == '{') {
80 printf ( "Error: invalid char {\n" );
81 return false;
82 }
83
84 if (configuration.VSProjectVersion.length() == 1) //7,8
85 configuration.VSProjectVersion.append(".00");
86
87 if (configuration.VSProjectVersion.length() == 3) //7.1
88 configuration.VSProjectVersion.append("0");
89
90 break;
91 default:
92 printf ( "Unknown switch -d%c\n",
93 switchChar2 );
94 return false;
95 }
96 return true;
97 }
98
99 bool
100 ParseMakeSwitch ( char switchChar2 )
101 {
102 switch ( switchChar2 )
103 {
104 case 'i':
105 configuration.MakeHandlesInstallDirectories = true;
106 break;
107 default:
108 printf ( "Unknown switch -m%c\n",
109 switchChar2 );
110 return false;
111 }
112 return true;
113 }
114
115 bool
116 ParseProxyMakefileSwitch ( char switchChar2 )
117 {
118 switch ( switchChar2 )
119 {
120 case 's':
121 configuration.GenerateProxyMakefilesInSourceTree = true;
122 break;
123 default:
124 printf ( "Unknown switch -p%c\n",
125 switchChar2 );
126 return false;
127 }
128 return true;
129 }
130
131 bool
132 ParseSwitch ( int argc, char** argv, int index )
133 {
134 char switchChar = strlen ( argv[index] ) > 1 ? argv[index][1] : ' ';
135 char switchChar2 = strlen ( argv[index] ) > 2 ? argv[index][2] : ' ';
136 switch ( switchChar )
137 {
138 case 'v':
139 if (switchChar2 == 's')
140 return ParseVCProjectSwitch ( switchChar2,
141 argv[index] );
142 else
143 configuration.Verbose = true;
144 break;
145 case 'c':
146 configuration.CleanAsYouGo = true;
147 break;
148 case 'd':
149 return ParseAutomaticDependencySwitch ( switchChar2,
150 argv[index] );
151 case 'r':
152 RootXmlFile = string(&argv[index][2]);
153 break;
154 case 'm':
155 return ParseMakeSwitch ( switchChar2 );
156 case 'p':
157 return ParseProxyMakefileSwitch ( switchChar2 );
158 default:
159 printf ( "Unknown switch -%c\n",
160 switchChar );
161 return false;
162 }
163 return true;
164 }
165
166 bool
167 ParseArguments ( int argc, char** argv )
168 {
169 if ( argc < 2 )
170 return false;
171
172 for ( int i = 1; i < argc; i++ )
173 {
174 if ( argv[i][0] == '-' )
175 {
176 if ( !ParseSwitch ( argc, argv, i ) )
177 return false;
178 }
179 else
180 BuildSystem = argv[i];
181 }
182
183 return true;
184 }
185
186 int
187 main ( int argc, char** argv )
188 {
189 if ( !ParseArguments ( argc, argv ) )
190 {
191 printf ( "Generates project files for buildsystems\n\n" );
192 printf ( " rbuild [switches] buildsystem\n\n" );
193 printf ( "Switches:\n" );
194 printf ( " -v Be verbose.\n" );
195 printf ( " -c Clean as you go. Delete generated files as soon as they are not\n" );
196 printf ( " needed anymore.\n" );
197 printf ( " -dd Disable automatic dependencies.\n" );
198 printf ( " -dm{module} Check only automatic dependencies for this module.\n" );
199 printf ( " -r{file.xml} Name of the root xml file. Default is ReactOS.xml.\n" );
200 printf ( " -mi Let make handle creation of install directories. Rbuild will\n" );
201 printf ( " not generate the directories.\n" );
202 printf ( " -ps Generate proxy makefiles in source tree instead of the output.\n" );
203 printf ( " tree.\n" );
204 printf ( " -vs{version} Version of MS VS project files. Default is %s.\n", MS_VS_DEF_VERSION );
205 printf ( "\n" );
206 printf ( " buildsystem Target build system. Can be one of:\n" );
207 printf ( " mingw MinGW\n" );
208 printf ( " devcpp DevC++\n" );
209 printf ( " msvc MS Visual Studio\n" );
210 return 1;
211 }
212 try
213 {
214 string projectFilename ( RootXmlFile );
215 printf ( "Reading build files..." );
216 Project project ( projectFilename );
217 printf ( "done\n" );
218 project.WriteConfigurationFile ();
219 project.ExecuteInvocations ();
220 Backend* backend = Backend::Factory::Create ( BuildSystem,
221 project,
222 configuration );
223 backend->Process ();
224 delete backend;
225
226 return 0;
227 }
228 catch (Exception& ex)
229 {
230 printf ( "%s\n",
231 ex.Message.c_str () );
232 return 1;
233 }
234 }