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