2 * Copyright (C) 2005 Casper S. Hornstrup
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.
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.
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.
30 #include <sys/utime.h>
39 #include "exception.h"
42 typedef std::vector
<std::string
> string_list
;
44 extern std::string ExePrefix
;
45 extern std::string ExePostfix
;
46 extern std::string sSep
;
47 extern std::string sBadSep
;
52 #define DEF_EXEPREFIX ""
53 #define DEF_EXEPOSTFIX ".exe"
55 #define DEF_CBAD_SEP '/'
57 #define DEF_SBAD_SEP "/"
59 #define DEF_EXEPREFIX "./"
60 #define DEF_EXEPOSTFIX ""
62 #define DEF_CBAD_SEP '\\'
64 #define DEF_SBAD_SEP "\\"
67 #define MS_VS_DEF_VERSION "7.10"
86 class TestSupportCode
;
88 class AutomaticDependency
;
93 class StubbedComponent
;
95 class CompilationUnit
;
101 typedef std::map
<std::string
,Directory
*> directory_map
;
107 directory_map subdirs
;
108 Directory ( const std::string
& name
);
109 void Add ( const char* subdir
);
110 void GenerateTree ( const std::string
& parent
,
112 std::string
EscapeSpaces ( std::string path
);
113 void CreateRule ( FILE* f
,
114 const std::string
& parent
);
116 bool mkdir_p ( const char* path
);
117 std::string
ReplaceVariable ( std::string name
,
120 std::string
GetEnvironmentVariable ( const std::string
& name
);
121 void ResolveVariablesInPath ( char* buf
,
123 bool CreateDirectory ( std::string path
);
134 bool AutomaticDependencies
;
135 bool CheckDependenciesForModuleOnly
;
136 bool CompilationUnitsEnabled
;
137 std::string CheckDependenciesForModuleOnlyModule
;
138 std::string VSProjectVersion
;
139 bool MakeHandlesInstallDirectories
;
140 bool GenerateProxyMakefilesInSourceTree
;
146 static std::string
GetVariable ( const std::string
& name
);
147 static std::string
GetIntermediatePath ();
148 static std::string
GetOutputPath ();
149 static std::string
GetInstallPath ();
150 static std::string
GetEnvironmentVariablePathOrDefault ( const std::string
& name
,
151 const std::string
& defaultValue
);
155 class FileSupportCode
158 static void WriteIfChanged ( char* outbuf
,
159 std::string filename
);
167 CompilationUnit
* compilationUnit
;
175 std::vector
<CompilationUnit
*> compilationUnits
;
176 std::vector
<File
*> files
;
177 std::vector
<Include
*> includes
;
178 std::vector
<Define
*> defines
;
179 std::vector
<Library
*> libraries
;
180 std::vector
<Property
*> properties
;
181 std::vector
<CompilerFlag
*> compilerFlags
;
182 std::vector
<If
*> ifs
;
191 XMLElement
*node
, *head
;
193 const Configuration
& configuration
;
195 std::string makefile
;
196 XMLIncludes xmlbuildfiles
;
197 std::vector
<Module
*> modules
;
198 std::vector
<LinkerFlag
*> linkerFlags
;
199 std::vector
<CDFile
*> cdfiles
;
200 std::vector
<InstallFile
*> installfiles
;
201 IfableData non_if_data
;
203 Project ( const Configuration
& configuration
,
204 const std::string
& filename
);
206 void WriteConfigurationFile ();
207 void ExecuteInvocations ();
208 void ProcessXML ( const std::string
& path
);
209 Module
* LocateModule ( const std::string
& name
);
210 const Module
* LocateModule ( const std::string
& name
) const;
211 std::string
GetProjectFilename () const;
212 std::string
ResolveProperties ( const std::string
& s
) const;
214 std::string
ResolveNextProperty ( std::string
& s
) const;
215 const Property
* LookupProperty ( const std::string
& name
) const;
216 void SetConfigurationOption ( char* s
,
218 std::string
* alternativeName
);
219 void SetConfigurationOption ( char* s
,
222 void ProcessXMLSubElement ( const XMLElement
& e
,
223 const std::string
& path
,
224 ParseContext
& parseContext
);
226 // disable copy semantics
227 Project ( const Project
& );
228 Project
& operator = ( const Project
& );
239 KernelModeDriver
= 5,
265 const Project
& project
;
266 const XMLElement
& node
;
267 std::string xmlbuildFile
;
270 std::string extension
;
271 std::string entrypoint
;
272 std::string baseaddress
;
275 ImportLibrary
* importLibrary
;
278 Bootstrap
* bootstrap
;
279 IfableData non_if_data
;
280 std::vector
<Invoke
*> invocations
;
281 std::vector
<Dependency
*> dependencies
;
282 std::vector
<CompilerFlag
*> compilerFlags
;
283 std::vector
<LinkerFlag
*> linkerFlags
;
284 std::vector
<StubbedComponent
*> stubbedComponents
;
285 LinkerScript
* linkerScript
;
290 std::string installBase
;
291 std::string installName
;
292 std::string aliasedModuleName
;
297 Module ( const Project
& project
,
298 const XMLElement
& moduleNode
,
299 const std::string
& modulePath
);
301 ModuleType
GetModuleType ( const std::string
& location
,
302 const XMLAttribute
& attribute
);
303 bool HasImportLibrary () const;
305 bool GenerateInOutputTree () const;
306 std::string
GetTargetName () const; // "foo.exe"
307 std::string
GetDependencyPath () const; // "path/foo.exe" or "path/libfoo.a"
308 std::string
GetBasePath () const; // "path"
309 std::string
GetPath () const; // "path/foo.exe"
310 std::string
GetPathWithPrefix ( const std::string
& prefix
) const; // "path/prefixfoo.exe"
311 void GetTargets ( string_list
& ) const;
312 std::string
GetInvocationTarget ( const int index
) const;
313 bool HasFileWithExtension ( const IfableData
&, const std::string
& extension
) const;
314 void InvokeModule () const;
316 void GetSourceFilenames ( string_list
& list
,
317 bool includeGeneratedFiles
) const;
319 std::string
GetDefaultModuleExtension () const;
320 std::string
GetDefaultModuleEntrypoint () const;
321 std::string
GetDefaultModuleBaseaddress () const;
322 void ProcessXMLSubElement ( const XMLElement
& e
,
323 const std::string
& path
,
324 ParseContext
& parseContext
);
331 const Project
& project
;
332 const Module
* module
;
333 const XMLElement
* node
;
334 const Module
* baseModule
;
335 std::string directory
;
336 std::string basePath
;
338 Include ( const Project
& project
,
339 const XMLElement
* includeNode
);
340 Include ( const Project
& project
,
341 const Module
* module
,
342 const XMLElement
* includeNode
);
343 Include ( const Project
& project
,
344 std::string directory
,
345 std::string basePath
);
355 const Project
& project
;
356 const Module
* module
;
357 const XMLElement
& node
;
361 Define ( const Project
& project
,
362 const XMLElement
& defineNode
);
363 Define ( const Project
& project
,
364 const Module
* module
,
365 const XMLElement
& defineNode
);
378 std::string switches
;
379 bool isPreCompiledHeader
;
381 File ( const std::string
& _name
,
383 std::string _switches
,
384 bool _isPreCompiledHeader
);
393 const XMLElement
& node
;
394 const Module
& module
;
396 const Module
* importedModule
;
398 Library ( const XMLElement
& _node
,
399 const Module
& _module
,
400 const std::string
& _name
);
409 const XMLElement
& node
;
410 const Module
& module
;
411 const Module
* invokeModule
;
412 std::vector
<InvokeFile
*> input
;
413 std::vector
<InvokeFile
*> output
;
415 Invoke ( const XMLElement
& _node
,
416 const Module
& _module
);
419 void GetTargets ( string_list
& targets
) const;
420 std::string
GetParameters () const;
422 void ProcessXMLSubElement ( const XMLElement
& e
);
423 void ProcessXMLSubElementInput ( const XMLElement
& e
);
424 void ProcessXMLSubElementOutput ( const XMLElement
& e
);
431 const XMLElement
& node
;
433 std::string switches
;
435 InvokeFile ( const XMLElement
& _node
,
436 const std::string
& _name
);
445 const XMLElement
& node
;
446 const Module
& module
;
447 const Module
* dependencyModule
;
449 Dependency ( const XMLElement
& _node
,
450 const Module
& _module
);
459 const XMLElement
& node
;
460 const Module
& module
;
461 std::string basename
;
462 std::string definition
;
464 ImportLibrary ( const XMLElement
& _node
,
465 const Module
& module
);
474 const XMLElement
& node
;
475 const Project
& project
;
476 const Module
* module
;
478 std::string property
, value
;
481 If ( const XMLElement
& node_
,
482 const Project
& project_
,
483 const Module
* module_
,
484 const bool negated_
= false );
494 const Project
& project
;
495 const Module
* module
;
496 const XMLElement
& node
;
499 CompilerFlag ( const Project
& project
,
500 const XMLElement
& compilerFlagNode
);
501 CompilerFlag ( const Project
& project
,
502 const Module
* module
,
503 const XMLElement
& compilerFlagNode
);
514 const Project
& project
;
515 const Module
* module
;
516 const XMLElement
& node
;
519 LinkerFlag ( const Project
& project
,
520 const XMLElement
& linkerFlagNode
);
521 LinkerFlag ( const Project
& project
,
522 const Module
* module
,
523 const XMLElement
& linkerFlagNode
);
534 const Project
& project
;
535 const Module
* module
;
536 const XMLElement
& node
;
537 const Module
* baseModule
;
538 std::string directory
;
539 std::string basePath
;
541 LinkerScript ( const Project
& project
,
542 const Module
* module
,
543 const XMLElement
& node
);
552 const XMLElement
& node
;
553 const Project
& project
;
554 const Module
* module
;
555 std::string name
, value
;
557 Property ( const XMLElement
& node_
,
558 const Project
& project_
,
559 const Module
* module_
);
565 class TestSupportCode
568 const Project
& project
;
570 TestSupportCode ( const Project
& project
);
572 void GenerateTestSupportCode ( bool verbose
);
574 bool IsTestModule ( const Module
& module
);
575 void GenerateTestSupportCodeForModule ( Module
& module
,
577 std::string
GetHooksFilename ( Module
& module
);
578 char* WriteStubbedSymbolToHooksFile ( char* buffer
,
579 const StubbedComponent
& component
,
580 const StubbedSymbol
& symbol
);
581 char* WriteStubbedComponentToHooksFile ( char* buffer
,
582 const StubbedComponent
& component
);
583 void WriteHooksFile ( Module
& module
);
584 std::string
GetStubsFilename ( Module
& module
);
585 char* WriteStubbedSymbolToStubsFile ( char* buffer
,
586 const StubbedComponent
& component
,
587 const StubbedSymbol
& symbol
,
589 char* WriteStubbedComponentToStubsFile ( char* buffer
,
590 const StubbedComponent
& component
,
592 void WriteStubsFile ( Module
& module
);
593 std::string
GetStartupFilename ( Module
& module
);
594 bool IsUnknownCharacter ( char ch
);
595 std::string
GetTestDispatcherName ( std::string filename
);
596 bool IsTestFile ( std::string
& filename
) const;
597 void GetSourceFilenames ( string_list
& list
,
598 Module
& module
) const;
599 char* WriteTestDispatcherPrototypesToStartupFile ( char* buffer
,
601 char* WriteRegisterTestsFunctionToStartupFile ( char* buffer
,
603 void WriteStartupFile ( Module
& module
);
610 const Project
& project
;
613 WineResource ( const Project
& project
,
614 std::string bin2res
);
616 void UnpackResources ( bool verbose
);
618 bool IsSpecFile ( const File
& file
);
619 bool IsWineModule ( const Module
& module
);
620 bool IsResourceFile ( const File
& file
);
621 std::string
GetResourceFilename ( const Module
& module
);
622 void UnpackResourcesInModule ( Module
& module
,
630 SourceFile ( AutomaticDependency
* automaticDependency
,
631 const Module
& module
,
632 const std::string
& filename
,
634 bool isNonAutomaticDependency
);
635 SourceFile
* ParseFile ( const std::string
& normalizedFilename
);
637 std::string
Location () const;
638 std::vector
<SourceFile
*> files
;
639 AutomaticDependency
* automaticDependency
;
640 const Module
& module
;
641 std::string filename
;
642 std::string filenamePart
;
643 std::string directoryPart
;
644 std::vector
<SourceFile
*> parents
; /* List of files, this file is included from */
645 bool isNonAutomaticDependency
;
646 std::string cachedDependencies
;
647 time_t lastWriteTime
;
648 time_t youngestLastWriteTime
; /* Youngest last write time of this file and all children */
649 SourceFile
* youngestFile
;
651 void GetDirectoryAndFilenameParts ();
654 void SkipWhitespace ();
655 bool ReadInclude ( std::string
& filename
,
656 bool& searchCurrentDirectory
,
658 bool IsIncludedFrom ( const std::string
& normalizedFilename
);
659 SourceFile
* GetParentSourceFile ();
660 bool CanProcessFile ( const std::string
& extension
);
661 bool IsParentOf ( const SourceFile
* parent
,
662 const SourceFile
* child
);
669 class AutomaticDependency
671 friend class SourceFileTest
;
673 const Project
& project
;
675 AutomaticDependency ( const Project
& project
);
676 ~AutomaticDependency ();
677 std::string
GetFilename ( const std::string
& filename
);
678 bool LocateIncludedFile ( const std::string
& directory
,
679 const std::string
& includedFilename
,
680 std::string
& resolvedFilename
);
681 bool LocateIncludedFile ( SourceFile
* sourceFile
,
682 const Module
& module
,
683 const std::string
& includedFilename
,
684 bool searchCurrentDirectory
,
686 std::string
& resolvedFilename
);
687 SourceFile
* RetrieveFromCacheOrParse ( const Module
& module
,
688 const std::string
& filename
,
689 SourceFile
* parentSourceFile
);
690 SourceFile
* RetrieveFromCache ( const std::string
& filename
);
691 void CheckAutomaticDependencies ( bool verbose
);
692 void CheckAutomaticDependenciesForModule ( Module
& module
,
695 void GetModulesToCheck ( Module
& module
, std::vector
<const Module
*>& modules
);
696 void CheckAutomaticDependencies ( const Module
& module
,
698 void CheckAutomaticDependenciesForFile ( SourceFile
* sourceFile
);
699 void GetIncludeDirectories ( std::vector
<Include
*>& includes
,
700 const Module
& module
,
701 Include
& currentDirectory
,
702 bool searchCurrentDirectory
);
703 void GetModuleFiles ( const Module
& module
,
704 std::vector
<File
*>& files
) const;
706 void ParseFiles ( const Module
& module
);
707 void ParseFile ( const Module
& module
,
709 std::map
<std::string
, SourceFile
*> sourcefile_map
;
716 const Project
& project
;
717 const Module
* module
;
718 const XMLElement
& node
;
720 std::string nameoncd
;
722 Bootstrap ( const Project
& project
,
723 const Module
* module
,
724 const XMLElement
& bootstrapNode
);
728 bool IsSupportedModuleType ( ModuleType type
);
736 const Project
& project
;
737 const XMLElement
& node
;
740 std::string nameoncd
;
743 CDFile ( const Project
& project
,
744 const XMLElement
& bootstrapNode
,
745 const std::string
& path
);
748 std::string
GetPath () const;
755 const Project
& project
;
756 const XMLElement
& node
;
762 InstallFile ( const Project
& project
,
763 const XMLElement
& bootstrapNode
,
764 const std::string
& path
);
767 std::string
GetPath () const;
774 const XMLElement
& node
;
775 const Module
& module
;
779 const XMLElement
& node
,
780 const Module
& module
,
786 class StubbedComponent
789 const Module
* module
;
790 const XMLElement
& node
;
792 std::vector
<StubbedSymbol
*> symbols
;
794 StubbedComponent ( const Module
* module_
,
795 const XMLElement
& stubbedComponentNode
);
796 ~StubbedComponent ();
798 void ProcessXMLSubElement ( const XMLElement
& e
);
805 const XMLElement
& node
;
808 std::string strippedName
;
810 StubbedSymbol ( const XMLElement
& stubbedSymbolNode
);
814 std::string
StripSymbol ( std::string symbol
);
818 class CompilationUnit
821 const Project
* project
;
822 const Module
* module
;
823 const XMLElement
* node
;
825 std::vector
<File
*> files
;
827 CompilationUnit ( File
* file
);
828 CompilationUnit ( const Project
* project
,
829 const Module
* module
,
830 const XMLElement
* node
);
833 bool IsGeneratedFile () const;
834 bool HasFileWithExtension ( const std::string
& extension
) const;
835 bool IsFirstFile () const;
836 FileLocation
* GetFilename ( Directory
* intermediateDirectory
) const;
837 std::string
GetSwitches () const;
841 class CompilationUnitSupportCode
844 const Project
& project
;
846 CompilationUnitSupportCode ( const Project
& project
);
847 ~CompilationUnitSupportCode ();
848 void Generate ( bool verbose
);
850 void GenerateForModule ( Module
& module
,
852 std::string
GetCompilationUnitFilename ( Module
& module
,
853 CompilationUnit
& compilationUnit
);
854 void WriteCompilationUnitFile ( Module
& module
,
855 CompilationUnit
& compilationUnit
);
862 Directory
* directory
;
863 std::string filename
;
864 FileLocation ( Directory
* directory
,
865 std::string filename
);
870 InitializeEnvironment ();
873 Right ( const std::string
& s
, size_t n
);
876 Replace ( const std::string
& s
, const std::string
& find
, const std::string
& with
);
879 ChangeSeparator ( const std::string
& s
,
880 const char fromSeparator
,
881 const char toSeparator
);
884 FixSeparator ( const std::string
& s
);
887 FixSeparatorForSystemCommand ( const std::string
& s
);
890 DosSeparator ( const std::string
& s
);
894 const std::string
& filename
,
895 const std::string
& newExtension
);
899 const std::string
& location
,
900 const std::string
& path
,
901 const std::string
& att_value
);
904 GetExtension ( const std::string
& filename
);
907 GetDirectory ( const std::string
& filename
);
910 GetFilename ( const std::string
& filename
);
913 NormalizeFilename ( const std::string
& filename
);
915 #endif /* __RBUILD_H */