Add bootstrap tag to specify that files are to be copied to the CD
[reactos.git] / reactos / tools / rbuild / rbuild.h
1 #ifndef __RBUILD_H
2 #define __RBUILD_H
3
4 #include "pch.h"
5
6 #ifdef WIN32
7 #include <direct.h>
8 #include <io.h>
9 #endif
10 #include <sys/stat.h>
11 #include <time.h>
12 #ifdef _MSC_VER
13 #include <sys/utime.h>
14 #else
15 #include <utime.h>
16 #include <process.h>
17 #endif
18
19 #include "ssprintf.h"
20 #include "exception.h"
21 #include "XML.h"
22
23 #ifdef WIN32
24 #define EXEPREFIX ""
25 #define EXEPOSTFIX ".exe"
26 #define CSEP '\\'
27 #define CBAD_SEP '/'
28 #define SSEP "\\"
29 #define SBAD_SEP "/"
30 #else
31 #define EXEPREFIX "./"
32 #define EXEPOSTFIX ""
33 #define CSEP '/'
34 #define CBAD_SEP '\\'
35 #define SSEP "/"
36 #define SBAD_SEP "\\"
37 #endif
38
39 class Project;
40 class Module;
41 class Include;
42 class Define;
43 class File;
44 class Library;
45 class Invoke;
46 class InvokeFile;
47 class Dependency;
48 class ImportLibrary;
49 class If;
50 class CompilerFlag;
51 class LinkerFlag;
52 class Property;
53 class AutomaticDependency;
54 class Bootstrap;
55
56 class SourceFileTest;
57
58 class Project
59 {
60 std::string xmlfile;
61 XMLElement *node, *head;
62 public:
63 std::string name;
64 std::string makefile;
65 std::vector<Module*> modules;
66 std::vector<Include*> includes;
67 std::vector<Define*> defines;
68 std::vector<LinkerFlag*> linkerFlags;
69 std::vector<Property*> properties;
70 std::vector<If*> ifs;
71
72 Project ( const std::string& filename );
73 ~Project ();
74 void WriteConfigurationFile ();
75 void ExecuteInvocations ();
76 void ProcessXML ( const std::string& path );
77 Module* LocateModule ( const std::string& name );
78 const Module* LocateModule ( const std::string& name ) const;
79 private:
80 const Property* LookupProperty ( const std::string& name ) const;
81 void SetConfigurationOption ( char* s,
82 std::string name,
83 std::string* alternativeName );
84 void SetConfigurationOption ( char* s,
85 std::string name );
86 void WriteIfChanged ( char* outbuf,
87 std::string filename );
88 void ReadXml ();
89 void ProcessXMLSubElement ( const XMLElement& e,
90 const std::string& path,
91 If* pIf = NULL );
92
93 // disable copy semantics
94 Project ( const Project& );
95 Project& operator = ( const Project& );
96 };
97
98
99 enum ModuleType
100 {
101 BuildTool,
102 StaticLibrary,
103 ObjectLibrary,
104 Kernel,
105 KernelModeDLL,
106 KernelModeDriver,
107 NativeDLL,
108 NativeCUI,
109 Win32DLL,
110 Win32CUI,
111 Win32GUI,
112 BootLoader,
113 BootSector,
114 Iso
115 };
116
117
118 class Module
119 {
120 public:
121 const Project& project;
122 const XMLElement& node;
123 std::string name;
124 std::string extension;
125 std::string entrypoint;
126 std::string baseaddress;
127 std::string path;
128 ModuleType type;
129 ImportLibrary* importLibrary;
130 bool mangledSymbols;
131 Bootstrap* bootstrap;
132 std::vector<File*> files;
133 std::vector<Library*> libraries;
134 std::vector<Include*> includes;
135 std::vector<Define*> defines;
136 std::vector<Invoke*> invocations;
137 std::vector<Dependency*> dependencies;
138 std::vector<If*> ifs;
139 std::vector<CompilerFlag*> compilerFlags;
140 std::vector<LinkerFlag*> linkerFlags;
141
142 Module ( const Project& project,
143 const XMLElement& moduleNode,
144 const std::string& modulePath );
145 ~Module ();
146 ModuleType GetModuleType ( const std::string& location,
147 const XMLAttribute& attribute );
148 bool HasImportLibrary () const;
149 std::string GetTargetName () const;
150 std::string GetDependencyPath () const;
151 std::string GetBasePath () const;
152 std::string GetPath () const;
153 std::string GetPathWithPrefix ( const std::string& prefix ) const;
154 std::string GetTargets () const;
155 std::string GetInvocationTarget ( const int index ) const;
156 bool HasFileWithExtensions ( const std::string& extension1,
157 const std::string& extension2 ) const;
158 void InvokeModule () const;
159 void ProcessXML ();
160 private:
161 std::string GetDefaultModuleExtension () const;
162 std::string GetDefaultModuleEntrypoint () const;
163 std::string GetDefaultModuleBaseaddress () const;
164 void ProcessXMLSubElement ( const XMLElement& e,
165 const std::string& path,
166 If* pIf = NULL );
167 };
168
169
170 class Include
171 {
172 public:
173 const Project& project;
174 const Module* module;
175 const XMLElement& node;
176 std::string directory;
177 std::string basePath;
178
179 Include ( const Project& project,
180 const XMLElement& includeNode );
181 Include ( const Project& project,
182 const Module* module,
183 const XMLElement& includeNode );
184 ~Include ();
185 void ProcessXML();
186 private:
187 void Initialize();
188 };
189
190
191 class Define
192 {
193 public:
194 const Project& project;
195 const Module* module;
196 const XMLElement& node;
197 std::string name;
198 std::string value;
199
200 Define ( const Project& project,
201 const XMLElement& defineNode );
202 Define ( const Project& project,
203 const Module* module,
204 const XMLElement& defineNode );
205 ~Define();
206 void ProcessXML();
207 private:
208 void Initialize();
209 };
210
211
212 class File
213 {
214 public:
215 std::string name;
216 bool first;
217
218 File ( const std::string& _name, bool _first );
219
220 void ProcessXML();
221 };
222
223
224 class Library
225 {
226 public:
227 const XMLElement& node;
228 const Module& module;
229 std::string name;
230
231 Library ( const XMLElement& _node,
232 const Module& _module,
233 const std::string& _name );
234
235 void ProcessXML();
236 };
237
238
239 class Invoke
240 {
241 public:
242 const XMLElement& node;
243 const Module& module;
244 const Module* invokeModule;
245 std::vector<InvokeFile*> input;
246 std::vector<InvokeFile*> output;
247
248 Invoke ( const XMLElement& _node,
249 const Module& _module );
250
251 void ProcessXML();
252 std::string GetTargets () const;
253 std::string GetParameters () const;
254 private:
255 void ProcessXMLSubElement ( const XMLElement& e );
256 void ProcessXMLSubElementInput ( const XMLElement& e );
257 void ProcessXMLSubElementOutput ( const XMLElement& e );
258 };
259
260
261 class InvokeFile
262 {
263 public:
264 const XMLElement& node;
265 std::string name;
266 std::string switches;
267
268 InvokeFile ( const XMLElement& _node,
269 const std::string& _name );
270
271 void ProcessXML ();
272 };
273
274
275 class Dependency
276 {
277 public:
278 const XMLElement& node;
279 const Module& module;
280 const Module* dependencyModule;
281
282 Dependency ( const XMLElement& _node,
283 const Module& _module );
284
285 void ProcessXML();
286 };
287
288
289 class ImportLibrary
290 {
291 public:
292 const XMLElement& node;
293 const Module& module;
294 std::string basename;
295 std::string definition;
296
297 ImportLibrary ( const XMLElement& _node,
298 const Module& module );
299
300 void ProcessXML ();
301 };
302
303
304 class If
305 {
306 public:
307 const XMLElement& node;
308 const Project& project;
309 const Module* module;
310 std::string property, value;
311 std::vector<File*> files;
312 std::vector<Include*> includes;
313 std::vector<Define*> defines;
314 std::vector<Property*> properties;
315 std::vector<If*> ifs;
316
317 If ( const XMLElement& node_,
318 const Project& project_,
319 const Module* module_ );
320 ~If();
321
322 void ProcessXML();
323 };
324
325
326 class CompilerFlag
327 {
328 public:
329 const Project& project;
330 const Module* module;
331 const XMLElement& node;
332 std::string flag;
333
334 CompilerFlag ( const Project& project,
335 const XMLElement& compilerFlagNode );
336 CompilerFlag ( const Project& project,
337 const Module* module,
338 const XMLElement& compilerFlagNode );
339 ~CompilerFlag ();
340 void ProcessXML();
341 private:
342 void Initialize();
343 };
344
345
346 class LinkerFlag
347 {
348 public:
349 const Project& project;
350 const Module* module;
351 const XMLElement& node;
352 std::string flag;
353
354 LinkerFlag ( const Project& project,
355 const XMLElement& linkerFlagNode );
356 LinkerFlag ( const Project& project,
357 const Module* module,
358 const XMLElement& linkerFlagNode );
359 ~LinkerFlag ();
360 void ProcessXML();
361 private:
362 void Initialize();
363 };
364
365
366 class Property
367 {
368 public:
369 const XMLElement& node;
370 const Project& project;
371 const Module* module;
372 std::string name, value;
373
374 Property ( const XMLElement& node_,
375 const Project& project_,
376 const Module* module_ );
377
378 void ProcessXML();
379 };
380
381
382 class SourceFile
383 {
384 public:
385 SourceFile ( AutomaticDependency* automaticDependency,
386 Module& module,
387 const std::string& filename,
388 SourceFile* parent,
389 bool isNonAutomaticDependency );
390 SourceFile* ParseFile ( const std::string& normalizedFilename );
391 void Parse ();
392 std::string Location () const;
393 std::vector<SourceFile*> files;
394 AutomaticDependency* automaticDependency;
395 Module& module;
396 std::string filename;
397 std::string filenamePart;
398 std::string directoryPart;
399 std::vector<SourceFile*> parents; /* List of files, this file is included from */
400 bool isNonAutomaticDependency;
401 std::string cachedDependencies;
402 time_t lastWriteTime;
403 time_t youngestLastWriteTime; /* Youngest last write time of this file and all children */
404 SourceFile* youngestFile;
405 private:
406 void GetDirectoryAndFilenameParts ();
407 void Close ();
408 void Open ();
409 void SkipWhitespace ();
410 bool ReadInclude ( std::string& filename,
411 bool& includeNext );
412 bool IsIncludedFrom ( const std::string& normalizedFilename );
413 SourceFile* GetParentSourceFile ();
414 bool CanProcessFile ( const std::string& extension );
415 bool IsParentOf ( const SourceFile* parent,
416 const SourceFile* child );
417 std::string buf;
418 const char *p;
419 const char *end;
420 };
421
422
423 class AutomaticDependency
424 {
425 friend class SourceFileTest;
426 public:
427 const Project& project;
428
429 AutomaticDependency ( const Project& project );
430 ~AutomaticDependency ();
431 void Process ();
432 std::string GetFilename ( const std::string& filename );
433 bool LocateIncludedFile ( const std::string& directory,
434 const std::string& includedFilename,
435 std::string& resolvedFilename );
436 bool LocateIncludedFile ( SourceFile* sourceFile,
437 Module& module,
438 const std::string& includedFilename,
439 bool includeNext,
440 std::string& resolvedFilename );
441 SourceFile* RetrieveFromCacheOrParse ( Module& module,
442 const std::string& filename,
443 SourceFile* parentSourceFile );
444 SourceFile* RetrieveFromCache ( const std::string& filename );
445 void CheckAutomaticDependencies ();
446 void CheckAutomaticDependenciesForFile ( SourceFile* sourceFile );
447 private:
448 void ProcessModule ( Module& module );
449 void ProcessFile ( Module& module,
450 const File& file );
451 std::map<std::string, SourceFile*> sourcefile_map;
452 };
453
454
455 class Bootstrap
456 {
457 public:
458 const Project& project;
459 const Module* module;
460 const XMLElement& node;
461 std::string base;
462 std::string nameoncd;
463
464 Bootstrap ( const Project& project,
465 const Module* module,
466 const XMLElement& bootstrapNode );
467 ~Bootstrap ();
468 void ProcessXML();
469 private:
470 bool IsSupportedModuleType ( ModuleType type );
471 void Initialize();
472 };
473
474
475 extern std::string
476 FixSeparator ( const std::string& s );
477
478 extern std::string
479 GetExtension ( const std::string& filename );
480
481 extern std::string
482 GetDirectory ( const std::string& filename );
483
484 extern std::string
485 NormalizeFilename ( const std::string& filename );
486
487 #endif /* __RBUILD_H */