13baa2ef651b84b1d4adcd73ccae021447381475
[reactos.git] / reactos / tools / rbuild / rbuild.h
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 #ifndef __RBUILD_H
19 #define __RBUILD_H
20
21 #include "pch.h"
22
23 #ifdef WIN32
24 #include <direct.h>
25 #include <io.h>
26 #endif/*WIN32*/
27 #include <sys/stat.h>
28 #include <time.h>
29 #ifdef _MSC_VER
30 #include <sys/utime.h>
31 #else/*_MSC_VER*/
32 #include <utime.h>
33 #ifdef WIN32
34 #include <process.h>
35 #endif/*WIN32*/
36 #endif/*_MSC_VER*/
37
38 #include <infhost.h>
39
40 #include "ssprintf.h"
41 #include "exception.h"
42 #include "xml.h"
43
44 class Backend; // forward declaration
45
46 typedef std::vector<std::string> string_list;
47
48 extern std::string ExePrefix;
49 extern std::string ExePostfix;
50 extern std::string sSep;
51 extern std::string sBadSep;
52 extern char cSep;
53 extern char cBadSep;
54
55 #ifdef WIN32
56 #define DEF_EXEPREFIX ""
57 #define DEF_EXEPOSTFIX ".exe"
58 #define DEF_CSEP '\\'
59 #define DEF_CBAD_SEP '/'
60 #define DEF_SSEP "\\"
61 #define DEF_SBAD_SEP "/"
62 #else
63 #define DEF_EXEPREFIX "./"
64 #define DEF_EXEPOSTFIX ""
65 #define DEF_CSEP '/'
66 #define DEF_CBAD_SEP '\\'
67 #define DEF_SSEP "/"
68 #define DEF_SBAD_SEP "\\"
69 #endif
70
71 #define MS_VS_DEF_VERSION "7.10"
72
73 class XmlNode;
74 class Directory;
75 class Project;
76 class IfableData;
77 class Module;
78 class Include;
79 class Define;
80 class File;
81 class Library;
82 class Invoke;
83 class InvokeFile;
84 class Dependency;
85 class ImportLibrary;
86 class CompilerFlag;
87 class LinkerFlag;
88 class LinkerScript;
89 class Property;
90 class TestSupportCode;
91 class AutomaticDependency;
92 class Bootstrap;
93 class CDFile;
94 class InstallFile;
95 class PchFile;
96 class StubbedComponent;
97 class StubbedSymbol;
98 class CompilationUnit;
99 class FileLocation;
100 class AutoRegister;
101
102 class SourceFileTest;
103 class Metadata;
104 class Bootsector;
105
106 typedef std::map<std::string,Directory*> directory_map;
107
108 class XmlNode
109 {
110 protected:
111 const Project& project;
112 const XMLElement& node;
113
114 XmlNode ( const Project& project_,
115 const XMLElement& node_ );
116 virtual ~XmlNode();
117
118 public:
119 virtual void ProcessXML();
120 };
121
122 enum DirectoryLocation
123 {
124 SourceDirectory,
125 IntermediateDirectory,
126 OutputDirectory,
127 InstallDirectory,
128 TemporaryDirectory,
129 };
130
131 class Directory
132 {
133 public:
134 std::string name;
135 directory_map subdirs;
136 Directory ( const std::string& name );
137 ~Directory();
138 void Add ( const char* subdir );
139 void GenerateTree ( DirectoryLocation root,
140 bool verbose );
141 void CreateRule ( FILE* f,
142 const std::string& parent );
143 private:
144 bool mkdir_p ( const char* path );
145 bool CreateDirectory ( const std::string& path );
146 std::string EscapeSpaces ( const std::string& path );
147 void GenerateTree ( const std::string& parent,
148 bool verbose );
149 };
150
151 enum DependenciesType
152 {
153 NoDependencies,
154 AutomaticDependencies,
155 FullDependencies
156 };
157
158 enum CompilerSet
159 {
160 GnuGcc,
161 MicrosoftC
162 };
163
164 enum LinkerSet
165 {
166 GnuLd,
167 MicrosoftLink
168 };
169
170 class Configuration
171 {
172 public:
173 Configuration ();
174 ~Configuration ();
175 bool Verbose;
176 bool CleanAsYouGo;
177 DependenciesType Dependencies;
178 bool CheckDependenciesForModuleOnly;
179 bool CompilationUnitsEnabled;
180 bool PrecompiledHeadersEnabled;
181 std::string CheckDependenciesForModuleOnlyModule;
182 std::string VSProjectVersion;
183 std::string VSConfigurationType;
184 bool UseVSVersionInPath;
185 bool UseConfigurationInPath;
186 bool MakeHandlesInstallDirectories;
187 bool GenerateProxyMakefilesInSourceTree;
188 bool InstallFiles;
189 CompilerSet Compiler;
190 LinkerSet Linker;
191 };
192
193 class Environment
194 {
195 public:
196 static std::string GetVariable ( const std::string& name );
197 static std::string GetArch ();
198 static std::string GetIntermediatePath ();
199 static std::string GetOutputPath ();
200 static std::string GetCdOutputPath ();
201 static std::string GetInstallPath ();
202 static std::string GetAutomakeFile ( const std::string& defaultFile );
203 static std::string GetEnvironmentVariablePathOrDefault ( const std::string& name,
204 const std::string& defaultValue );
205 };
206
207
208 class FileSupportCode
209 {
210 public:
211 static void WriteIfChanged ( char* outbuf,
212 const std::string& filename,
213 bool ignoreError = false );
214 };
215
216
217 class ParseContext
218 {
219 public:
220 CompilationUnit* compilationUnit;
221 ParseContext ();
222 };
223
224
225 class IfableData
226 {
227 public:
228 std::vector<CompilationUnit*> compilationUnits;
229 std::vector<File*> files;
230 std::vector<Include*> includes;
231 std::vector<Define*> defines;
232 std::vector<Library*> libraries;
233 std::map<std::string, Property*> properties;
234 std::vector<Module*> modules;
235 std::vector<CompilerFlag*> compilerFlags;
236 int asmFiles; // number of .asm files in compilationUnits
237
238 IfableData();
239 ~IfableData();
240 void ProcessXML();
241 void ExtractModules( std::map<std::string, Module*> &modules );
242 };
243
244 class Project
245 {
246 std::string xmlfile;
247 XMLElement *node, *head;
248 Backend* _backend;
249 public:
250 const Configuration& configuration;
251 std::string name;
252 std::string makefile;
253 XMLIncludes xmlbuildfiles;
254 std::vector<LinkerFlag*> linkerFlags;
255 std::vector<CDFile*> cdfiles;
256 std::vector<InstallFile*> installfiles;
257 std::map<std::string, Module*> modules;
258 IfableData non_if_data;
259 IfableData host_non_if_data;
260 bool allowWarnings;
261 bool allowWarningsSet;
262
263 Project ( const Configuration& configuration,
264 const std::string& filename,
265 const std::map<std::string, std::string>* properties = NULL );
266 ~Project ();
267 void SetBackend ( Backend* backend ) { _backend = backend; }
268 Backend& GetBackend() { return *_backend; }
269 void ExecuteInvocations ();
270
271 void ProcessXML ( const std::string& path );
272 Module* LocateModule ( const std::string& name );
273 const Module* LocateModule ( const std::string& name ) const;
274 const std::string& GetProjectFilename () const;
275 std::string ResolveProperties ( const std::string& s ) const;
276 const Property* LookupProperty ( const std::string& name ) const;
277 std::string GetCompilerSet () const;
278 std::string GetLinkerSet () const;
279 private:
280 std::string ResolveNextProperty ( const std::string& s ) const;
281 void ReadXml ();
282 void ProcessXMLSubElement ( const XMLElement& e,
283 const std::string& path,
284 ParseContext& parseContext );
285
286 // disable copy semantics
287 Project ( const Project& );
288 Project& operator = ( const Project& );
289 };
290
291
292 enum ModuleType
293 {
294 BuildTool,
295 StaticLibrary,
296 ObjectLibrary,
297 Kernel,
298 KernelModeDLL,
299 KernelModeDriver,
300 NativeDLL,
301 NativeCUI,
302 Win32DLL,
303 Win32OCX,
304 Win32CUI,
305 Win32GUI,
306 BootLoader,
307 BootSector,
308 Iso,
309 LiveIso,
310 Test,
311 RpcServer,
312 RpcClient,
313 Alias,
314 BootProgram,
315 Win32SCR,
316 IdlHeader,
317 IdlInterface,
318 IsoRegTest,
319 LiveIsoRegTest,
320 EmbeddedTypeLib,
321 ElfExecutable,
322 RpcProxy,
323 HostStaticLibrary,
324 Cabinet,
325 KeyboardLayout,
326 MessageHeader,
327 TypeDontCare, // always at the end
328 };
329
330 enum HostType
331 {
332 HostFalse,
333 HostDefault,
334 HostTrue,
335 HostDontCare,
336 };
337
338 enum CompilerType
339 {
340 CompilerTypeCC,
341 CompilerTypeCXX,
342 CompilerTypeCPP,
343 CompilerTypeAS,
344 CompilerTypeMIDL,
345 CompilerTypeRC,
346 CompilerTypeNASM,
347
348 CompilerTypesCount
349 };
350
351 class FileLocation
352 {
353 public:
354 DirectoryLocation directory;
355 std::string relative_path;
356 std::string name;
357
358 FileLocation ( const DirectoryLocation directory,
359 const std::string& relative_path,
360 const std::string& name,
361 const XMLElement *node = NULL );
362
363 FileLocation ( const FileLocation& other );
364 };
365
366 class Module
367 {
368 public:
369 const Project& project;
370 const XMLElement& node;
371 std::string xmlbuildFile;
372 std::string name;
373 std::string guid;
374 std::string extension;
375 std::string baseaddress;
376 std::string payload;
377 std::string buildtype;
378 ModuleType type;
379 ImportLibrary* importLibrary;
380 ImportLibrary* delayImportLibrary;
381 Metadata* metadata;
382 Bootsector* bootSector;
383 bool mangledSymbols;
384 bool underscoreSymbols;
385 bool isUnicode;
386 bool isDefaultEntryPoint;
387 Bootstrap* bootstrap;
388 AutoRegister* autoRegister; // <autoregister> node
389 IfableData non_if_data;
390 std::vector<Invoke*> invocations;
391 std::vector<Dependency*> dependencies;
392 std::vector<CompilerFlag*> compilerFlags;
393 std::vector<LinkerFlag*> linkerFlags;
394 std::vector<StubbedComponent*> stubbedComponents;
395 LinkerScript* linkerScript;
396 PchFile* pch;
397 bool cplusplus;
398 std::string prefix;
399 std::string aliasedModuleName;
400 bool allowWarnings;
401 bool enabled;
402 bool isStartupLib;
403 bool isCRT;
404 std::string CRT;
405 bool dynamicCRT;
406 FileLocation *output; // "path/foo.exe"
407 FileLocation *dependency; // "path/foo.exe" or "path/libfoo.a"
408 FileLocation *install;
409 std::string description;
410 std::string lcid;
411 std::string layoutId;
412 std::string layoutNameResId;
413
414 Module ( const Project& project,
415 const XMLElement& moduleNode,
416 const std::string& modulePath );
417 ~Module ();
418 ModuleType GetModuleType ( const std::string& location,
419 const XMLAttribute& attribute );
420 bool HasImportLibrary () const;
421 bool IsDLL () const;
422 std::string GetPathWithPrefix ( const std::string& prefix ) const; // "path/prefixfoo.exe"
423 std::string GetPathToBaseDir() const; // "../" offset to rootdirectory
424 std::string GetEntryPoint(bool leadingUnderscore) const;
425 void GetTargets ( string_list& ) const;
426 std::string GetInvocationTarget ( const int index ) const;
427 bool HasFileWithExtension ( const IfableData&, const std::string& extension ) const;
428 void InvokeModule () const;
429 void ProcessXML ();
430 std::string GetDllName() const;
431 private:
432 void SetImportLibrary ( ImportLibrary* importLibrary );
433 void SetDelayImportLibrary ( ImportLibrary* importLibrary );
434 DirectoryLocation GetTargetDirectoryTree () const;
435 std::string GetDefaultModuleExtension () const;
436 std::string GetDefaultModuleEntrypoint () const;
437 std::string GetDefaultModuleBaseaddress () const;
438 std::string GetDefaultModuleCRT () const;
439 bool GetDefaultModuleIsCRT () const;
440 std::string entrypoint;
441 void ProcessXMLSubElement ( const XMLElement& e,
442 DirectoryLocation directory,
443 const std::string& relative_path,
444 ParseContext& parseContext );
445 bool GetBooleanAttribute ( const XMLElement& moduleNode,
446 const char * name,
447 bool default_value = false );
448 };
449
450 class ToolsetDirective
451 {
452 private:
453 bool enabled;
454
455 protected:
456 void ParseToolsets ( const Project& project, const XMLElement& node );
457
458 public:
459 bool IsEnabled () const;
460 };
461
462 class CompilerDirective
463 {
464 private:
465 std::bitset<CompilerTypesCount> compilersSet;
466 bool enabled;
467
468 protected:
469 void ParseCompilers ( const XMLElement& node, const std::string& defaultValue );
470
471 public:
472 CompilerDirective (): enabled ( true ) { }
473 void SetCompiler ( CompilerType compiler );
474 void UnsetCompiler ( CompilerType compiler );
475 void SetAllCompilers ();
476 void UnsetAllCompilers ();
477 bool IsCompilerSet ( CompilerType compiler ) const;
478 };
479
480 class Include: public CompilerDirective, public ToolsetDirective
481 {
482 public:
483 FileLocation *directory;
484
485 Include ( const Project& project,
486 const XMLElement* includeNode );
487 Include ( const Project& project,
488 const XMLElement* includeNode,
489 const Module* module );
490 Include ( const Project& project,
491 DirectoryLocation directory,
492 const std::string& relative_path );
493 ~Include ();
494 void ProcessXML ();
495 private:
496 const Project& project;
497 const XMLElement* node;
498 const Module* module;
499 DirectoryLocation GetDefaultDirectoryTree ( const Module* module ) const;
500 void Initialize ();
501 };
502
503
504 class Define: public CompilerDirective, public ToolsetDirective
505 {
506 public:
507 const Project& project;
508 const Module* module;
509 const XMLElement* node;
510 std::string name;
511 std::string arguments;
512 std::string value;
513 std::string backend;
514 bool redefine;
515
516 Define ( const Project& project,
517 const XMLElement& defineNode );
518 Define ( const Project& project,
519 const Module* module,
520 const XMLElement& defineNode );
521 Define ( const Project& project,
522 const Module* module,
523 const std::string& name_,
524 const std::string& backend_ = "",
525 bool redefine_ = false );
526 ~Define();
527 void ProcessXML();
528 private:
529 void Initialize();
530 };
531
532
533 class File
534 {
535 public:
536 FileLocation file;
537 bool first;
538 std::string switches;
539 bool isPreCompiledHeader;
540
541 File ( DirectoryLocation directory,
542 const std::string& relative_path,
543 const std::string& name,
544 bool _first,
545 const std::string& _switches,
546 bool _isPreCompiledHeader );
547
548 void ProcessXML();
549 std::string GetFullPath () const;
550 };
551
552
553 class Library
554 {
555 const XMLElement *node;
556 public:
557 const Module& module;
558 std::string name;
559 const Module* importedModule;
560 bool delayimp;
561
562 Library ( const XMLElement& _node,
563 const Module& _module,
564 const std::string& _name );
565 Library ( const Module& _module,
566 const std::string& _name );
567
568 void ProcessXML();
569 };
570
571
572 class Invoke
573 {
574 public:
575 const XMLElement& node;
576 const Module& module;
577 const Module* invokeModule;
578 std::vector<InvokeFile*> input;
579 std::vector<InvokeFile*> output;
580
581 Invoke ( const XMLElement& _node,
582 const Module& _module );
583
584 void ProcessXML();
585 void GetTargets ( string_list& targets ) const;
586 std::string GetParameters () const;
587 private:
588 void ProcessXMLSubElement ( const XMLElement& e );
589 void ProcessXMLSubElementInput ( const XMLElement& e );
590 void ProcessXMLSubElementOutput ( const XMLElement& e );
591 };
592
593
594 class InvokeFile
595 {
596 public:
597 const XMLElement& node;
598 std::string name;
599 std::string switches;
600
601 InvokeFile ( const XMLElement& _node,
602 const std::string& _name );
603
604 void ProcessXML ();
605 };
606
607
608 class Dependency
609 {
610 public:
611 const XMLElement& node;
612 const Module& module;
613 const Module* dependencyModule;
614
615 Dependency ( const XMLElement& _node,
616 const Module& _module );
617
618 void ProcessXML();
619 };
620
621 class Bootsector
622 {
623 public:
624 const XMLElement& node;
625 const Module* module;
626 const Module* bootSectorModule;
627
628 Bootsector ( const XMLElement& _node,
629 const Module* _module );
630
631 void ProcessXML();
632 private:
633 bool IsSupportedModuleType ( ModuleType type );
634 };
635
636 class Metadata
637 {
638 public:
639 const XMLElement& node;
640 const Module& module;
641 std::string name;
642 std::string description;
643 std::string version;
644 std::string copyright;
645 std::string url;
646 std::string date;
647 std::string owner;
648
649 Metadata ( const XMLElement& _node,
650 const Module& _module );
651
652 void ProcessXML();
653 };
654
655 class ImportLibrary : public XmlNode
656 {
657 public:
658 const Module* module;
659 std::string dllname;
660 FileLocation *source;
661 FileLocation *target;
662
663 ImportLibrary ( const Project& project,
664 const XMLElement& node,
665 const Module* module,
666 bool delayimp );
667 ~ImportLibrary ();
668 };
669
670
671 class CompilerFlag: public CompilerDirective, public ToolsetDirective
672 {
673 public:
674 const Project& project;
675 const Module* module;
676 const XMLElement& node;
677 std::string flag;
678
679 CompilerFlag ( const Project& project,
680 const XMLElement& compilerFlagNode );
681 CompilerFlag ( const Project& project,
682 const Module* module,
683 const XMLElement& compilerFlagNode );
684 ~CompilerFlag ();
685 void ProcessXML();
686 private:
687 void Initialize();
688 };
689
690
691 class LinkerFlag: public ToolsetDirective
692 {
693 public:
694 const Project& project;
695 const Module* module;
696 const XMLElement& node;
697 std::string flag;
698
699 LinkerFlag ( const Project& project,
700 const XMLElement& linkerFlagNode );
701 LinkerFlag ( const Project& project,
702 const Module* module,
703 const XMLElement& linkerFlagNode );
704 ~LinkerFlag ();
705 void ProcessXML();
706 private:
707 void Initialize();
708 };
709
710
711 class LinkerScript
712 {
713 public:
714 const XMLElement& node;
715 const Module& module;
716 const FileLocation *file;
717
718 LinkerScript ( const XMLElement& node,
719 const Module& module,
720 const FileLocation *file );
721 ~LinkerScript ();
722 void ProcessXML();
723 };
724
725
726 class Property
727 {
728 public:
729 const Project& project;
730 const Module* module;
731 std::string name, value;
732 bool isInternal;
733
734 Property ( const XMLElement& node_,
735 const Project& project_,
736 const Module* module_ );
737
738 Property ( const Project& project_,
739 const Module* module_,
740 const std::string& name_,
741 const std::string& value_ );
742
743 void ProcessXML();
744 };
745
746
747 class TestSupportCode
748 {
749 public:
750 const Project& project;
751
752 TestSupportCode ( const Project& project );
753 ~TestSupportCode ();
754 void GenerateTestSupportCode ( bool verbose );
755 private:
756 bool IsTestModule ( const Module& module );
757 void GenerateTestSupportCodeForModule ( Module& module,
758 bool verbose );
759 std::string GetHooksFilename ( Module& module );
760 char* WriteStubbedSymbolToHooksFile ( char* buffer,
761 const StubbedComponent& component,
762 const StubbedSymbol& symbol );
763 char* WriteStubbedComponentToHooksFile ( char* buffer,
764 const StubbedComponent& component );
765 void WriteHooksFile ( Module& module );
766 std::string GetStubsFilename ( Module& module );
767 char* WriteStubbedSymbolToStubsFile ( char* buffer,
768 const StubbedComponent& component,
769 const StubbedSymbol& symbol,
770 int stubIndex );
771 char* WriteStubbedComponentToStubsFile ( char* buffer,
772 const StubbedComponent& component,
773 int* stubIndex );
774 void WriteStubsFile ( Module& module );
775 std::string GetStartupFilename ( Module& module );
776 bool IsUnknownCharacter ( char ch );
777 std::string GetTestDispatcherName ( std::string filename );
778 bool IsTestFile ( std::string& filename ) const;
779 void GetSourceFilenames ( string_list& list,
780 Module& module ) const;
781 char* WriteTestDispatcherPrototypesToStartupFile ( char* buffer,
782 Module& module );
783 char* WriteRegisterTestsFunctionToStartupFile ( char* buffer,
784 Module& module );
785 void WriteStartupFile ( Module& module );
786 };
787
788
789 class SourceFile
790 {
791 public:
792 SourceFile ( AutomaticDependency* automaticDependency,
793 const Module& module,
794 const File& file,
795 SourceFile* parent );
796 void Parse ();
797 std::vector<SourceFile*> files; /* List of files included in this file */
798 const File& file;
799 AutomaticDependency* automaticDependency;
800 const Module& module;
801 std::vector<SourceFile*> parents; /* List of files, this file is included from */
802 time_t lastWriteTime;
803 time_t youngestLastWriteTime; /* Youngest last write time of this file and all children */
804 SourceFile* youngestFile;
805 private:
806 void Close ();
807 void Open ();
808 void SkipWhitespace ();
809 bool ReadInclude ( std::string& filename,
810 bool& searchCurrentDirectory,
811 bool& includeNext );
812 bool IsIncludedFrom ( const File& file );
813 SourceFile* ParseFile(const File& file);
814 bool CanProcessFile ( const File& file );
815 bool IsParentOf ( const SourceFile* parent,
816 const SourceFile* child );
817 std::string buf;
818 const char *p;
819 const char *end;
820 };
821
822
823 class AutomaticDependency
824 {
825 friend class SourceFileTest;
826 public:
827 const Project& project;
828
829 AutomaticDependency ( const Project& project );
830 ~AutomaticDependency ();
831 bool LocateIncludedFile ( const FileLocation& directory,
832 const std::string& includedFilename );
833 bool LocateIncludedFile ( SourceFile* sourceFile,
834 const Module& module,
835 const std::string& includedFilename,
836 bool searchCurrentDirectory,
837 bool includeNext,
838 File& resolvedFile );
839 SourceFile* RetrieveFromCacheOrParse ( const Module& module,
840 const File& file,
841 SourceFile* parentSourceFile );
842 SourceFile* RetrieveFromCache ( const File& file );
843 void CheckAutomaticDependencies ( bool verbose );
844 void CheckAutomaticDependenciesForModule ( Module& module,
845 bool verbose );
846 private:
847 void GetModulesToCheck ( Module& module, std::vector<const Module*>& modules );
848 void CheckAutomaticDependencies ( const Module& module,
849 bool verbose );
850 void CheckAutomaticDependenciesForFile ( SourceFile* sourceFile );
851 void GetIncludeDirectories ( std::vector<Include*>& includes,
852 const Module& module );
853 void GetModuleFiles ( const Module& module,
854 std::vector<File*>& files ) const;
855 void ParseFiles ();
856 void ParseFiles ( const Module& module );
857 void ParseFile ( const Module& module,
858 const File& file );
859 std::map<std::string, SourceFile*> sourcefile_map;
860 };
861
862
863 class Bootstrap
864 {
865 public:
866 const Project& project;
867 const Module* module;
868 const XMLElement& node;
869 std::string base;
870 std::string nameoncd;
871
872 Bootstrap ( const Project& project,
873 const Module* module,
874 const XMLElement& bootstrapNode );
875 ~Bootstrap ();
876 void ProcessXML();
877 private:
878 bool IsSupportedModuleType ( ModuleType type );
879 void Initialize();
880 static std::string ReplaceVariable ( const std::string& name,
881 const std::string& value,
882 std::string path );
883 };
884
885
886 class CDFile : public XmlNode
887 {
888 public:
889 FileLocation *source;
890 FileLocation *target;
891
892 CDFile ( const Project& project,
893 const XMLElement& bootstrapNode,
894 const std::string& path );
895 ~CDFile ();
896 private:
897 static std::string ReplaceVariable ( const std::string& name,
898 const std::string& value,
899 std::string path );
900 };
901
902
903 class InstallFile : public XmlNode
904 {
905 public:
906 FileLocation *source;
907 FileLocation *target;
908
909 InstallFile ( const Project& project,
910 const XMLElement& bootstrapNode,
911 const std::string& path );
912 ~InstallFile ();
913 };
914
915
916 class PchFile
917 {
918 public:
919 const XMLElement& node;
920 const Module& module;
921 const FileLocation *file;
922
923 PchFile (
924 const XMLElement& node,
925 const Module& module,
926 const FileLocation *file );
927 ~PchFile();
928 void ProcessXML();
929 };
930
931
932 class StubbedComponent
933 {
934 public:
935 const Module* module;
936 const XMLElement& node;
937 std::string name;
938 std::vector<StubbedSymbol*> symbols;
939
940 StubbedComponent ( const Module* module_,
941 const XMLElement& stubbedComponentNode );
942 ~StubbedComponent ();
943 void ProcessXML ();
944 void ProcessXMLSubElement ( const XMLElement& e );
945 };
946
947
948 class StubbedSymbol
949 {
950 public:
951 const XMLElement& node;
952 std::string symbol;
953 std::string newname;
954 std::string strippedName;
955
956 StubbedSymbol ( const XMLElement& stubbedSymbolNode );
957 ~StubbedSymbol ();
958 void ProcessXML();
959 private:
960 std::string StripSymbol ( std::string symbol );
961 };
962
963
964 class CompilationUnit
965 {
966 public:
967 std::string name;
968
969 CompilationUnit ( const File* file );
970 CompilationUnit ( const Project* project,
971 const Module* module,
972 const XMLElement* node );
973 ~CompilationUnit ();
974 void ProcessXML();
975 bool IsGeneratedFile () const;
976 bool HasFileWithExtension ( const std::string& extension ) const;
977 bool IsFirstFile () const;
978 const FileLocation& GetFilename () const;
979 const std::string& GetSwitches () const;
980 void AddFile ( const File * file );
981 const std::vector<const File*> GetFiles () const;
982 private:
983 const Project* project;
984 const Module* module;
985 const XMLElement* node;
986 std::vector<const File*> files;
987 FileLocation *default_name;
988 };
989
990
991 class CompilationUnitSupportCode
992 {
993 public:
994 const Project& project;
995
996 CompilationUnitSupportCode ( const Project& project );
997 ~CompilationUnitSupportCode ();
998 void Generate ( bool verbose );
999 private:
1000 void GenerateForModule ( Module& module,
1001 bool verbose );
1002 std::string GetCompilationUnitFilename ( Module& module,
1003 CompilationUnit& compilationUnit );
1004 void WriteCompilationUnitFile ( Module& module,
1005 CompilationUnit& compilationUnit );
1006 };
1007
1008
1009 enum AutoRegisterType
1010 {
1011 DllRegisterServer,
1012 DllInstall,
1013 Both
1014 };
1015
1016 class AutoRegister : public XmlNode
1017 {
1018 public:
1019 const Module* module;
1020 std::string infSection;
1021 AutoRegisterType type;
1022 AutoRegister ( const Project& project_,
1023 const Module* module_,
1024 const XMLElement& node_ );
1025 private:
1026 bool IsSupportedModuleType ( ModuleType type );
1027 AutoRegisterType GetAutoRegisterType( const std::string& type );
1028 void Initialize ();
1029 };
1030
1031
1032 class SysSetupGenerator
1033 {
1034 public:
1035 const Project& project;
1036 SysSetupGenerator ( const Project& project );
1037 ~SysSetupGenerator ();
1038 void Generate ();
1039 private:
1040 std::string GetDirectoryId ( const Module& module );
1041 std::string GetFlags ( const Module& module );
1042 void Generate ( HINF inf,
1043 const Module& module );
1044 };
1045
1046
1047 extern void
1048 InitializeEnvironment ();
1049
1050 extern std::string
1051 Right ( const std::string& s, size_t n );
1052
1053 extern std::string
1054 Replace ( const std::string& s, const std::string& find, const std::string& with );
1055
1056 extern std::string
1057 ChangeSeparator ( const std::string& s,
1058 const char fromSeparator,
1059 const char toSeparator );
1060
1061 extern std::string
1062 FixSeparator ( const std::string& s );
1063
1064 extern std::string
1065 FixSeparatorForSystemCommand ( const std::string& s );
1066
1067 extern std::string
1068 DosSeparator ( const std::string& s );
1069
1070 extern std::string
1071 ReplaceExtension (
1072 const std::string& filename,
1073 const std::string& newExtension );
1074
1075 extern std::string
1076 GetSubPath (
1077 const Project& project,
1078 const std::string& location,
1079 const std::string& path,
1080 const std::string& att_value );
1081
1082 extern std::string
1083 GetExtension ( const FileLocation& file );
1084
1085 extern std::string
1086 NormalizeFilename ( const std::string& filename );
1087
1088 extern std::string
1089 ToLower ( std::string filename );
1090
1091 #endif /* __RBUILD_H */