- Various resource fixes (unclosed files, unchecked memory allocations, missing destr...
[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 EmbeddedTypeLib,
319 ElfExecutable,
320 RpcProxy,
321 HostStaticLibrary,
322 Cabinet,
323 KeyboardLayout,
324 MessageHeader,
325 TypeDontCare, // always at the end
326 };
327
328 enum HostType
329 {
330 HostFalse,
331 HostDefault,
332 HostTrue,
333 HostDontCare,
334 };
335
336 enum CompilerType
337 {
338 CompilerTypeCC,
339 CompilerTypeCXX,
340 CompilerTypeCPP,
341 CompilerTypeAS,
342 CompilerTypeMIDL,
343 CompilerTypeRC,
344 CompilerTypeNASM,
345
346 CompilerTypesCount
347 };
348
349 class FileLocation
350 {
351 public:
352 DirectoryLocation directory;
353 std::string relative_path;
354 std::string name;
355
356 FileLocation ( const DirectoryLocation directory,
357 const std::string& relative_path,
358 const std::string& name,
359 const XMLElement *node = NULL );
360
361 FileLocation ( const FileLocation& other );
362 };
363
364 class Module
365 {
366 public:
367 const Project& project;
368 const XMLElement& node;
369 std::string xmlbuildFile;
370 std::string name;
371 std::string guid;
372 std::string extension;
373 std::string baseaddress;
374 std::string payload;
375 std::string buildtype;
376 ModuleType type;
377 ImportLibrary* importLibrary;
378 ImportLibrary* delayImportLibrary;
379 Metadata* metadata;
380 Bootsector* bootSector;
381 bool mangledSymbols;
382 bool underscoreSymbols;
383 bool isUnicode;
384 bool isDefaultEntryPoint;
385 Bootstrap* bootstrap;
386 AutoRegister* autoRegister; // <autoregister> node
387 IfableData non_if_data;
388 std::vector<Invoke*> invocations;
389 std::vector<Dependency*> dependencies;
390 std::vector<CompilerFlag*> compilerFlags;
391 std::vector<LinkerFlag*> linkerFlags;
392 std::vector<StubbedComponent*> stubbedComponents;
393 std::vector<CDFile*> cdfiles;
394 LinkerScript* linkerScript;
395 PchFile* pch;
396 bool cplusplus;
397 std::string prefix;
398 std::string aliasedModuleName;
399 bool allowWarnings;
400 bool enabled;
401 bool isStartupLib;
402 bool isCRT;
403 std::string CRT;
404 bool dynamicCRT;
405 FileLocation *output; // "path/foo.exe"
406 FileLocation *dependency; // "path/foo.exe" or "path/libfoo.a"
407 FileLocation *install;
408 std::string description;
409 std::string lcid;
410 std::string layoutId;
411 std::string layoutNameResId;
412
413 Module ( const Project& project,
414 const XMLElement& moduleNode,
415 const std::string& modulePath );
416 ~Module ();
417 ModuleType GetModuleType ( const std::string& location,
418 const XMLAttribute& attribute );
419 bool HasImportLibrary () const;
420 bool IsDLL () const;
421 std::string GetPathWithPrefix ( const std::string& prefix ) const; // "path/prefixfoo.exe"
422 std::string GetPathToBaseDir() const; // "../" offset to rootdirectory
423 std::string GetEntryPoint(bool leadingUnderscore) const;
424 void GetTargets ( string_list& ) const;
425 std::string GetInvocationTarget ( const int index ) const;
426 bool HasFileWithExtension ( const IfableData&, const std::string& extension ) const;
427 void InvokeModule () const;
428 void ProcessXML ();
429 std::string GetDllName() const;
430 private:
431 void SetImportLibrary ( ImportLibrary* importLibrary );
432 void SetDelayImportLibrary ( ImportLibrary* importLibrary );
433 DirectoryLocation GetTargetDirectoryTree () const;
434 std::string GetDefaultModuleExtension () const;
435 std::string GetDefaultModuleEntrypoint () const;
436 std::string GetDefaultModuleBaseaddress () const;
437 std::string GetDefaultModuleCRT () const;
438 bool GetDefaultModuleIsCRT () const;
439 std::string entrypoint;
440 void ProcessXMLSubElement ( const XMLElement& e,
441 DirectoryLocation directory,
442 const std::string& relative_path,
443 ParseContext& parseContext );
444 bool GetBooleanAttribute ( const XMLElement& moduleNode,
445 const char * name,
446 bool default_value = false );
447 };
448
449 class ToolsetDirective
450 {
451 private:
452 bool enabled;
453
454 protected:
455 void ParseToolsets ( const Project& project, const XMLElement& node );
456
457 public:
458 virtual ~ToolsetDirective() { }
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 virtual ~CompilerDirective() { }
474 void SetCompiler ( CompilerType compiler );
475 void UnsetCompiler ( CompilerType compiler );
476 void SetAllCompilers ();
477 void UnsetAllCompilers ();
478 bool IsCompilerSet ( CompilerType compiler ) const;
479 };
480
481 class Include: public CompilerDirective, public ToolsetDirective
482 {
483 public:
484 FileLocation *directory;
485
486 Include ( const Project& project,
487 const XMLElement* includeNode );
488 Include ( const Project& project,
489 const XMLElement* includeNode,
490 const Module* module );
491 Include ( const Project& project,
492 DirectoryLocation directory,
493 const std::string& relative_path );
494 ~Include ();
495 void ProcessXML ();
496 private:
497 const Project& project;
498 const XMLElement* node;
499 const Module* module;
500 DirectoryLocation GetDefaultDirectoryTree ( const Module* module ) const;
501 void Initialize ();
502 };
503
504
505 class Define: public CompilerDirective, public ToolsetDirective
506 {
507 public:
508 const Project& project;
509 const Module* module;
510 const XMLElement* node;
511 std::string name;
512 std::string arguments;
513 std::string value;
514 std::string backend;
515 bool redefine;
516
517 Define ( const Project& project,
518 const XMLElement& defineNode );
519 Define ( const Project& project,
520 const Module* module,
521 const XMLElement& defineNode );
522 Define ( const Project& project,
523 const Module* module,
524 const std::string& name_,
525 const std::string& backend_ = "",
526 bool redefine_ = false );
527 ~Define();
528 void ProcessXML();
529 private:
530 void Initialize();
531 };
532
533
534 class File
535 {
536 public:
537 FileLocation file;
538 bool first;
539 std::string switches;
540 bool isPreCompiledHeader;
541
542 File ( DirectoryLocation directory,
543 const std::string& relative_path,
544 const std::string& name,
545 bool _first,
546 const std::string& _switches,
547 bool _isPreCompiledHeader );
548
549 void ProcessXML();
550 std::string GetFullPath () const;
551 };
552
553
554 class Library
555 {
556 const XMLElement *node;
557 public:
558 const Module& module;
559 std::string name;
560 const Module* importedModule;
561 bool delayimp;
562
563 Library ( const XMLElement& _node,
564 const Module& _module,
565 const std::string& _name );
566 Library ( const Module& _module,
567 const std::string& _name );
568
569 void ProcessXML();
570 };
571
572
573 class Invoke
574 {
575 public:
576 const XMLElement& node;
577 const Module& module;
578 const Module* invokeModule;
579 std::vector<InvokeFile*> input;
580 std::vector<InvokeFile*> output;
581
582 Invoke ( const XMLElement& _node,
583 const Module& _module );
584
585 void ProcessXML();
586 void GetTargets ( string_list& targets ) const;
587 std::string GetParameters () const;
588 private:
589 void ProcessXMLSubElement ( const XMLElement& e );
590 void ProcessXMLSubElementInput ( const XMLElement& e );
591 void ProcessXMLSubElementOutput ( const XMLElement& e );
592 };
593
594
595 class InvokeFile
596 {
597 public:
598 const XMLElement& node;
599 std::string name;
600 std::string switches;
601
602 InvokeFile ( const XMLElement& _node,
603 const std::string& _name );
604
605 void ProcessXML ();
606 };
607
608
609 class Dependency
610 {
611 public:
612 const XMLElement& node;
613 const Module& module;
614 const Module* dependencyModule;
615
616 Dependency ( const XMLElement& _node,
617 const Module& _module );
618
619 void ProcessXML();
620 };
621
622 class Bootsector
623 {
624 public:
625 const XMLElement& node;
626 const Module* module;
627 const Module* bootSectorModule;
628
629 Bootsector ( const XMLElement& _node,
630 const Module* _module );
631
632 void ProcessXML();
633 private:
634 bool IsSupportedModuleType ( ModuleType type );
635 };
636
637 class Metadata
638 {
639 public:
640 const XMLElement& node;
641 const Module& module;
642 std::string name;
643 std::string description;
644 std::string version;
645 std::string copyright;
646 std::string url;
647 std::string date;
648 std::string owner;
649
650 Metadata ( const XMLElement& _node,
651 const Module& _module );
652
653 void ProcessXML();
654 };
655
656 class ImportLibrary : public XmlNode
657 {
658 public:
659 const Module* module;
660 std::string dllname;
661 FileLocation *source;
662 FileLocation *target;
663
664 ImportLibrary ( const Project& project,
665 const XMLElement& node,
666 const Module* module,
667 bool delayimp );
668 ~ImportLibrary ();
669 };
670
671
672 class CompilerFlag: public CompilerDirective, public ToolsetDirective
673 {
674 public:
675 const Project& project;
676 const Module* module;
677 const XMLElement& node;
678 std::string flag;
679
680 CompilerFlag ( const Project& project,
681 const XMLElement& compilerFlagNode );
682 CompilerFlag ( const Project& project,
683 const Module* module,
684 const XMLElement& compilerFlagNode );
685 ~CompilerFlag ();
686 void ProcessXML();
687 private:
688 void Initialize();
689 };
690
691
692 class LinkerFlag: public ToolsetDirective
693 {
694 public:
695 const Project& project;
696 const Module* module;
697 const XMLElement& node;
698 std::string flag;
699
700 LinkerFlag ( const Project& project,
701 const XMLElement& linkerFlagNode );
702 LinkerFlag ( const Project& project,
703 const Module* module,
704 const XMLElement& linkerFlagNode );
705 ~LinkerFlag ();
706 void ProcessXML();
707 private:
708 void Initialize();
709 };
710
711
712 class LinkerScript
713 {
714 public:
715 const XMLElement& node;
716 const Module& module;
717 const FileLocation *file;
718
719 LinkerScript ( const XMLElement& node,
720 const Module& module,
721 const FileLocation *file );
722 ~LinkerScript ();
723 void ProcessXML();
724 };
725
726
727 class Property
728 {
729 public:
730 const Project& project;
731 const Module* module;
732 std::string name, value;
733 bool isInternal;
734
735 Property ( const XMLElement& node_,
736 const Project& project_,
737 const Module* module_ );
738
739 Property ( const Project& project_,
740 const Module* module_,
741 const std::string& name_,
742 const std::string& value_ );
743
744 void ProcessXML();
745 };
746
747
748 class TestSupportCode
749 {
750 public:
751 const Project& project;
752
753 TestSupportCode ( const Project& project );
754 ~TestSupportCode ();
755 void GenerateTestSupportCode ( bool verbose );
756 private:
757 bool IsTestModule ( const Module& module );
758 void GenerateTestSupportCodeForModule ( Module& module,
759 bool verbose );
760 std::string GetHooksFilename ( Module& module );
761 char* WriteStubbedSymbolToHooksFile ( char* buffer,
762 const StubbedComponent& component,
763 const StubbedSymbol& symbol );
764 char* WriteStubbedComponentToHooksFile ( char* buffer,
765 const StubbedComponent& component );
766 void WriteHooksFile ( Module& module );
767 std::string GetStubsFilename ( Module& module );
768 char* WriteStubbedSymbolToStubsFile ( char* buffer,
769 const StubbedComponent& component,
770 const StubbedSymbol& symbol,
771 int stubIndex );
772 char* WriteStubbedComponentToStubsFile ( char* buffer,
773 const StubbedComponent& component,
774 int* stubIndex );
775 void WriteStubsFile ( Module& module );
776 std::string GetStartupFilename ( Module& module );
777 bool IsUnknownCharacter ( char ch );
778 std::string GetTestDispatcherName ( std::string filename );
779 bool IsTestFile ( std::string& filename ) const;
780 void GetSourceFilenames ( string_list& list,
781 Module& module ) const;
782 char* WriteTestDispatcherPrototypesToStartupFile ( char* buffer,
783 Module& module );
784 char* WriteRegisterTestsFunctionToStartupFile ( char* buffer,
785 Module& module );
786 void WriteStartupFile ( Module& module );
787 };
788
789
790 class SourceFile
791 {
792 public:
793 SourceFile ( AutomaticDependency* automaticDependency,
794 const Module& module,
795 const File& file,
796 SourceFile* parent );
797 void Parse ();
798 std::vector<SourceFile*> files; /* List of files included in this file */
799 const File& file;
800 AutomaticDependency* automaticDependency;
801 const Module& module;
802 std::vector<SourceFile*> parents; /* List of files, this file is included from */
803 time_t lastWriteTime;
804 time_t youngestLastWriteTime; /* Youngest last write time of this file and all children */
805 SourceFile* youngestFile;
806 private:
807 void Close ();
808 void Open ();
809 void SkipWhitespace ();
810 bool ReadInclude ( std::string& filename,
811 bool& searchCurrentDirectory,
812 bool& includeNext );
813 bool IsIncludedFrom ( const File& file );
814 SourceFile* ParseFile(const File& file);
815 bool CanProcessFile ( const File& file );
816 bool IsParentOf ( const SourceFile* parent,
817 const SourceFile* child );
818 std::string buf;
819 const char *p;
820 const char *end;
821 };
822
823
824 class AutomaticDependency
825 {
826 friend class SourceFileTest;
827 public:
828 const Project& project;
829
830 AutomaticDependency ( const Project& project );
831 ~AutomaticDependency ();
832 bool LocateIncludedFile ( const FileLocation& directory,
833 const std::string& includedFilename );
834 bool LocateIncludedFile ( SourceFile* sourceFile,
835 const Module& module,
836 const std::string& includedFilename,
837 bool searchCurrentDirectory,
838 bool includeNext,
839 File& resolvedFile );
840 SourceFile* RetrieveFromCacheOrParse ( const Module& module,
841 const File& file,
842 SourceFile* parentSourceFile );
843 SourceFile* RetrieveFromCache ( const File& file );
844 void CheckAutomaticDependencies ( bool verbose );
845 void CheckAutomaticDependenciesForModule ( Module& module,
846 bool verbose );
847 private:
848 void GetModulesToCheck ( Module& module, std::vector<const Module*>& modules );
849 void CheckAutomaticDependencies ( const Module& module,
850 bool verbose );
851 void CheckAutomaticDependenciesForFile ( SourceFile* sourceFile );
852 void GetIncludeDirectories ( std::vector<Include*>& includes,
853 const Module& module );
854 void GetModuleFiles ( const Module& module,
855 std::vector<File*>& files ) const;
856 void ParseFiles ();
857 void ParseFiles ( const Module& module );
858 void ParseFile ( const Module& module,
859 const File& file );
860 std::map<std::string, SourceFile*> sourcefile_map;
861 };
862
863
864 class Bootstrap
865 {
866 public:
867 const Project& project;
868 const Module* module;
869 const XMLElement& node;
870 std::string base;
871 std::string nameoncd;
872
873 Bootstrap ( const Project& project,
874 const Module* module,
875 const XMLElement& bootstrapNode );
876 ~Bootstrap ();
877 void ProcessXML();
878 private:
879 bool IsSupportedModuleType ( ModuleType type );
880 void Initialize();
881 static std::string ReplaceVariable ( const std::string& name,
882 const std::string& value,
883 std::string path );
884 };
885
886
887 class CDFile : public XmlNode
888 {
889 public:
890 FileLocation *source;
891 FileLocation *target;
892
893 CDFile ( const Project& project,
894 const XMLElement& bootstrapNode,
895 const std::string& path );
896 ~CDFile ();
897 private:
898 static std::string ReplaceVariable ( const std::string& name,
899 const std::string& value,
900 std::string path );
901 };
902
903
904 class InstallFile : public XmlNode
905 {
906 public:
907 FileLocation *source;
908 FileLocation *target;
909
910 InstallFile ( const Project& project,
911 const XMLElement& bootstrapNode,
912 const std::string& path );
913 ~InstallFile ();
914 };
915
916
917 class PchFile
918 {
919 public:
920 const XMLElement& node;
921 const Module& module;
922 const FileLocation *file;
923
924 PchFile (
925 const XMLElement& node,
926 const Module& module,
927 const FileLocation *file );
928 ~PchFile();
929 void ProcessXML();
930 };
931
932
933 class StubbedComponent
934 {
935 public:
936 const Module* module;
937 const XMLElement& node;
938 std::string name;
939 std::vector<StubbedSymbol*> symbols;
940
941 StubbedComponent ( const Module* module_,
942 const XMLElement& stubbedComponentNode );
943 ~StubbedComponent ();
944 void ProcessXML ();
945 void ProcessXMLSubElement ( const XMLElement& e );
946 };
947
948
949 class StubbedSymbol
950 {
951 public:
952 const XMLElement& node;
953 std::string symbol;
954 std::string newname;
955 std::string strippedName;
956
957 StubbedSymbol ( const XMLElement& stubbedSymbolNode );
958 ~StubbedSymbol ();
959 void ProcessXML();
960 private:
961 std::string StripSymbol ( std::string symbol );
962 };
963
964
965 class CompilationUnit
966 {
967 public:
968 std::string name;
969
970 CompilationUnit ( const File* file );
971 CompilationUnit ( const Project* project,
972 const Module* module,
973 const XMLElement* node );
974 ~CompilationUnit ();
975 void ProcessXML();
976 bool IsGeneratedFile () const;
977 bool HasFileWithExtension ( const std::string& extension ) const;
978 bool IsFirstFile () const;
979 const FileLocation& GetFilename () const;
980 const std::string& GetSwitches () const;
981 void AddFile ( const File * file );
982 const std::vector<const File*> GetFiles () const;
983 private:
984 const Project* project;
985 const Module* module;
986 const XMLElement* node;
987 std::vector<const File*> files;
988 FileLocation *default_name;
989 };
990
991
992 class CompilationUnitSupportCode
993 {
994 public:
995 const Project& project;
996
997 CompilationUnitSupportCode ( const Project& project );
998 ~CompilationUnitSupportCode ();
999 void Generate ( bool verbose );
1000 private:
1001 void GenerateForModule ( Module& module,
1002 bool verbose );
1003 std::string GetCompilationUnitFilename ( Module& module,
1004 CompilationUnit& compilationUnit );
1005 void WriteCompilationUnitFile ( Module& module,
1006 CompilationUnit& compilationUnit );
1007 };
1008
1009
1010 enum AutoRegisterType
1011 {
1012 DllRegisterServer,
1013 DllInstall,
1014 Both
1015 };
1016
1017 class AutoRegister : public XmlNode
1018 {
1019 public:
1020 const Module* module;
1021 std::string infSection;
1022 AutoRegisterType type;
1023 AutoRegister ( const Project& project_,
1024 const Module* module_,
1025 const XMLElement& node_ );
1026 private:
1027 bool IsSupportedModuleType ( ModuleType type );
1028 AutoRegisterType GetAutoRegisterType( const std::string& type );
1029 void Initialize ();
1030 };
1031
1032
1033 class SysSetupGenerator
1034 {
1035 public:
1036 const Project& project;
1037 SysSetupGenerator ( const Project& project );
1038 ~SysSetupGenerator ();
1039 void Generate ();
1040 private:
1041 std::string GetDirectoryId ( const Module& module );
1042 std::string GetFlags ( const Module& module );
1043 void Generate ( HINF inf,
1044 const Module& module );
1045 };
1046
1047
1048 extern void
1049 InitializeEnvironment ();
1050
1051 extern std::string
1052 Right ( const std::string& s, size_t n );
1053
1054 extern std::string
1055 Replace ( const std::string& s, const std::string& find, const std::string& with );
1056
1057 extern std::string
1058 ChangeSeparator ( const std::string& s,
1059 const char fromSeparator,
1060 const char toSeparator );
1061
1062 extern std::string
1063 FixSeparator ( const std::string& s );
1064
1065 extern std::string
1066 FixSeparatorForSystemCommand ( const std::string& s );
1067
1068 extern std::string
1069 DosSeparator ( const std::string& s );
1070
1071 extern std::string
1072 ReplaceExtension (
1073 const std::string& filename,
1074 const std::string& newExtension );
1075
1076 extern std::string
1077 GetSubPath (
1078 const Project& project,
1079 const std::string& location,
1080 const std::string& path,
1081 const std::string& att_value );
1082
1083 extern std::string
1084 GetExtension ( const FileLocation& file );
1085
1086 extern std::string
1087 NormalizeFilename ( const std::string& filename );
1088
1089 extern std::string
1090 ToLower ( std::string filename );
1091
1092 #endif /* __RBUILD_H */