176d0d1350c82fbb584d77551cca2508081bf6d9
[reactos.git] / reactos / tools / rbuild / rbuild.h
1 #ifndef __RBUILD_H
2 #define __RBUILD_H
3
4 #include "pch.h"
5
6 #include "ssprintf.h"
7 #include "exception.h"
8 #include "XML.h"
9
10 #ifdef WIN32
11 #define EXEPOSTFIX ".exe"
12 #define CSEP '\\'
13 #define CBAD_SEP '/'
14 #define SSEP "\\"
15 #define SBAD_SEP "/"
16 #else
17 #define EXEPOSTFIX ""
18 #define CSEP '/'
19 #define CBAD_SEP '\\'
20 #define SSEP "/"
21 #define SBAD_SEP "\\"
22 #endif
23
24 class Project;
25 class Module;
26 class Include;
27 class Define;
28 class File;
29 class Library;
30 class Invoke;
31 class InvokeFile;
32 class Dependency;
33 class ImportLibrary;
34 class If;
35 class LinkerFlag;
36 class Property;
37
38 class Project
39 {
40 std::string xmlfile;
41 XMLElement *node, *head;
42 public:
43 std::string name;
44 std::string makefile;
45 std::vector<Module*> modules;
46 std::vector<Include*> includes;
47 std::vector<Define*> defines;
48 std::vector<LinkerFlag*> linkerFlags;
49 std::vector<Property*> properties;
50 std::vector<If*> ifs;
51
52 //Project ();
53 Project ( const std::string& filename );
54 ~Project ();
55 void ProcessXML ( const std::string& path );
56 Module* LocateModule ( const std::string& name );
57 const Module* LocateModule ( const std::string& name ) const;
58 private:
59 void ReadXml ();
60 void ProcessXMLSubElement ( const XMLElement& e,
61 const std::string& path,
62 If* pIf = NULL );
63
64 // disable copy semantics
65 Project ( const Project& );
66 Project& operator = ( const Project& );
67 };
68
69
70 enum ModuleType
71 {
72 BuildTool,
73 StaticLibrary,
74 Kernel,
75 KernelModeDLL,
76 KernelModeDriver,
77 NativeDLL,
78 Win32DLL,
79 Win32GUI
80 };
81
82
83 class Module
84 {
85 public:
86 const Project& project;
87 const XMLElement& node;
88 std::string name;
89 std::string extension;
90 std::string path;
91 ModuleType type;
92 ImportLibrary* importLibrary;
93 std::vector<File*> files;
94 std::vector<Library*> libraries;
95 std::vector<Include*> includes;
96 std::vector<Define*> defines;
97 std::vector<Invoke*> invocations;
98 std::vector<Dependency*> dependencies;
99 std::vector<If*> ifs;
100 std::vector<LinkerFlag*> linkerFlags;
101
102 Module ( const Project& project,
103 const XMLElement& moduleNode,
104 const std::string& modulePath );
105 ~Module ();
106 ModuleType GetModuleType ( const std::string& location,
107 const XMLAttribute& attribute );
108 bool HasImportLibrary () const;
109 std::string GetTargetName () const;
110 std::string GetDependencyPath () const;
111 std::string GetBasePath () const;
112 std::string GetPath () const;
113 std::string GetPathWithPrefix ( const std::string& prefix ) const;
114 std::string GetTargets () const;
115 std::string GetInvocationTarget ( const int index ) const;
116 void ProcessXML();
117 private:
118 std::string GetDefaultModuleExtension () const;
119 void ProcessXMLSubElement ( const XMLElement& e,
120 const std::string& path,
121 If* pIf = NULL );
122 };
123
124
125 class Include
126 {
127 public:
128 const Project& project;
129 const Module* module;
130 const XMLElement& node;
131 std::string directory;
132 std::string basePath;
133
134 Include ( const Project& project,
135 const XMLElement& includeNode );
136 Include ( const Project& project,
137 const Module* module,
138 const XMLElement& includeNode );
139 ~Include ();
140 void ProcessXML();
141 private:
142 void Initialize();
143 };
144
145
146 class Define
147 {
148 public:
149 const Project& project;
150 const Module* module;
151 const XMLElement& node;
152 std::string name;
153 std::string value;
154
155 Define ( const Project& project,
156 const XMLElement& defineNode );
157 Define ( const Project& project,
158 const Module* module,
159 const XMLElement& defineNode );
160 ~Define();
161 void ProcessXML();
162 private:
163 void Initialize();
164 };
165
166
167 class File
168 {
169 public:
170 std::string name;
171 bool first;
172
173 File ( const std::string& _name, bool _first );
174
175 void ProcessXML();
176 };
177
178
179 class Library
180 {
181 public:
182 const XMLElement& node;
183 const Module& module;
184 std::string name;
185
186 Library ( const XMLElement& _node,
187 const Module& _module,
188 const std::string& _name );
189
190 void ProcessXML();
191 };
192
193
194 class Invoke
195 {
196 public:
197 const XMLElement& node;
198 const Module& module;
199 const Module* invokeModule;
200 std::vector<InvokeFile*> input;
201 std::vector<InvokeFile*> output;
202
203 Invoke ( const XMLElement& _node,
204 const Module& _module );
205
206 void ProcessXML();
207 std::string GetTargets () const;
208 private:
209 void ProcessXMLSubElement ( const XMLElement& e );
210 void ProcessXMLSubElementInput ( const XMLElement& e );
211 void ProcessXMLSubElementOutput ( const XMLElement& e );
212 };
213
214
215 class InvokeFile
216 {
217 public:
218 const XMLElement& node;
219 std::string name;
220 std::string switches;
221
222 InvokeFile ( const XMLElement& _node,
223 const std::string& _name );
224
225 void ProcessXML ();
226 };
227
228
229 class Dependency
230 {
231 public:
232 const XMLElement& node;
233 const Module& module;
234 const Module* dependencyModule;
235
236 Dependency ( const XMLElement& _node,
237 const Module& _module );
238
239 void ProcessXML();
240 };
241
242
243 class ImportLibrary
244 {
245 public:
246 const XMLElement& node;
247 const Module& module;
248 std::string basename;
249 std::string definition;
250
251 ImportLibrary ( const XMLElement& _node,
252 const Module& module );
253
254 void ProcessXML ();
255 };
256
257
258 class If
259 {
260 public:
261 const XMLElement& node;
262 const Project& project;
263 const Module* module;
264 std::string property, value;
265 std::vector<File*> files;
266 std::vector<Include*> includes;
267 std::vector<Define*> defines;
268 std::vector<Property*> properties;
269 std::vector<If*> ifs;
270
271 If ( const XMLElement& node_,
272 const Project& project_,
273 const Module* module_ );
274 ~If();
275
276 void ProcessXML();
277 };
278
279
280 class LinkerFlag
281 {
282 public:
283 const Project& project;
284 const Module* module;
285 const XMLElement& node;
286 std::string flag;
287
288 LinkerFlag ( const Project& project,
289 const XMLElement& linkerFlagNode );
290 LinkerFlag ( const Project& project,
291 const Module* module,
292 const XMLElement& linkerFlagNode );
293 ~LinkerFlag ();
294 void ProcessXML();
295 private:
296 void Initialize();
297 };
298
299
300 class Property
301 {
302 public:
303 const XMLElement& node;
304 const Project& project;
305 const Module* module;
306 std::string name, value;
307
308 Property ( const XMLElement& node_,
309 const Project& project_,
310 const Module* module_ );
311
312 void ProcessXML();
313 };
314
315 extern std::string
316 FixSeparator ( const std::string& s );
317
318 extern std::string
319 NormalizeFilename ( const std::string& filename );
320
321 #endif /* __RBUILD_H */