started working on cross-compile support
[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 Property;
36
37 class Project
38 {
39 std::string xmlfile;
40 XMLElement *node, *head;
41 public:
42 std::string name;
43 std::string makefile;
44 std::vector<Module*> modules;
45 std::vector<Include*> includes;
46 std::vector<Define*> defines;
47 std::vector<Property*> properties;
48 std::vector<If*> ifs;
49
50 //Project ();
51 Project ( const std::string& filename );
52 ~Project ();
53 void ProcessXML ( const std::string& path );
54 Module* LocateModule ( const std::string& name );
55 const Module* LocateModule ( const std::string& name ) const;
56 private:
57 void ReadXml ();
58 void ProcessXMLSubElement ( const XMLElement& e,
59 const std::string& path,
60 If* pIf = NULL );
61
62 // disable copy semantics
63 Project ( const Project& );
64 Project& operator = ( const Project& );
65 };
66
67
68 enum ModuleType
69 {
70 BuildTool,
71 StaticLibrary,
72 Kernel,
73 KernelModeDLL,
74 NativeDLL,
75 Win32DLL
76 };
77
78
79 class Module
80 {
81 public:
82 const Project& project;
83 const XMLElement& node;
84 std::string name;
85 std::string extension;
86 std::string path;
87 ModuleType type;
88 ImportLibrary* importLibrary;
89 std::vector<File*> files;
90 std::vector<Library*> libraries;
91 std::vector<Include*> includes;
92 std::vector<Define*> defines;
93 std::vector<Invoke*> invocations;
94 std::vector<Dependency*> dependencies;
95 std::vector<If*> ifs;
96
97 Module ( const Project& project,
98 const XMLElement& moduleNode,
99 const std::string& modulePath );
100 ~Module ();
101 ModuleType GetModuleType ( const std::string& location,
102 const XMLAttribute& attribute );
103 bool HasImportLibrary () const;
104 std::string GetTargetName () const;
105 std::string GetDependencyPath () const;
106 std::string GetBasePath() const;
107 std::string GetPath () const;
108 std::string GetPathWithPrefix ( const std::string& prefix ) const;
109 std::string GetTargets () const;
110 std::string GetInvocationTarget ( const int index ) const;
111 void ProcessXML();
112 private:
113 std::string GetDefaultModuleExtension () const;
114 void ProcessXMLSubElement ( const XMLElement& e,
115 const std::string& path,
116 If* pIf = NULL );
117 };
118
119
120 class Include
121 {
122 public:
123 const Project& project;
124 const Module* module;
125 const XMLElement& node;
126 std::string directory;
127 const Module* base;
128
129 Include ( const Project& project,
130 const XMLElement& includeNode );
131 Include ( const Project& project,
132 const Module* module,
133 const XMLElement& includeNode );
134 ~Include ();
135 void ProcessXML();
136 private:
137 void Initialize();
138 };
139
140
141 class Define
142 {
143 public:
144 const Project& project;
145 const Module* module;
146 const XMLElement& node;
147 std::string name;
148 std::string value;
149
150 Define ( const Project& project,
151 const XMLElement& defineNode );
152 Define ( const Project& project,
153 const Module* module,
154 const XMLElement& defineNode );
155 ~Define();
156 void ProcessXML();
157 private:
158 void Initialize();
159 };
160
161
162 class File
163 {
164 public:
165 std::string name;
166
167 File ( const std::string& _name );
168
169 void ProcessXML();
170 };
171
172
173 class Library
174 {
175 public:
176 const XMLElement& node;
177 const Module& module;
178 std::string name;
179
180 Library ( const XMLElement& _node,
181 const Module& _module,
182 const std::string& _name );
183
184 void ProcessXML();
185 };
186
187
188 class Invoke
189 {
190 public:
191 const XMLElement& node;
192 const Module& module;
193 const Module* invokeModule;
194 std::vector<InvokeFile*> input;
195 std::vector<InvokeFile*> output;
196
197 Invoke ( const XMLElement& _node,
198 const Module& _module );
199
200 void ProcessXML();
201 std::string GetTargets () const;
202 private:
203 void ProcessXMLSubElement ( const XMLElement& e );
204 void ProcessXMLSubElementInput ( const XMLElement& e );
205 void ProcessXMLSubElementOutput ( const XMLElement& e );
206 };
207
208
209 class InvokeFile
210 {
211 public:
212 const XMLElement& node;
213 std::string name;
214 std::string switches;
215
216 InvokeFile ( const XMLElement& _node,
217 const std::string& _name );
218
219 void ProcessXML ();
220 };
221
222
223 class Dependency
224 {
225 public:
226 const XMLElement& node;
227 const Module& module;
228 const Module* dependencyModule;
229
230 Dependency ( const XMLElement& _node,
231 const Module& _module );
232
233 void ProcessXML();
234 };
235
236
237 class ImportLibrary
238 {
239 public:
240 const XMLElement& node;
241 const Module& module;
242 std::string basename;
243 std::string definition;
244
245 ImportLibrary ( const XMLElement& _node,
246 const Module& module );
247
248 void ProcessXML ();
249 };
250
251 class If
252 {
253 public:
254 const XMLElement& node;
255 const Project& project;
256 const Module* module;
257 std::string property, value;
258 std::vector<File*> files;
259 std::vector<Include*> includes;
260 std::vector<Define*> defines;
261 std::vector<Property*> properties;
262 std::vector<If*> ifs;
263
264 If ( const XMLElement& node_,
265 const Project& project_,
266 const Module* module_ );
267 ~If();
268
269 void ProcessXML();
270 };
271
272 class Property
273 {
274 public:
275 const XMLElement& node;
276 const Project& project;
277 const Module* module;
278 std::string name, value;
279
280 Property ( const XMLElement& node_,
281 const Project& project_,
282 const Module* module_ );
283
284 void ProcessXML();
285 };
286
287 extern std::string
288 FixSeparator ( const std::string& s );
289
290 #endif /* __RBUILD_H */