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"
85 class TestSupportCode
;
87 class AutomaticDependency
;
92 class StubbedComponent
;
94 class CompilationUnit
;
106 bool AutomaticDependencies
;
107 bool CheckDependenciesForModuleOnly
;
108 std::string CheckDependenciesForModuleOnlyModule
;
109 std::string VSProjectVersion
;
110 bool MakeHandlesInstallDirectories
;
111 bool GenerateProxyMakefilesInSourceTree
;
117 static std::string
GetVariable ( const std::string
& name
);
118 static std::string
GetIntermediatePath ();
119 static std::string
GetOutputPath ();
120 static std::string
GetInstallPath ();
121 static std::string
GetEnvironmentVariablePathOrDefault ( const std::string
& name
,
122 const std::string
& defaultValue
);
126 class FileSupportCode
129 static void WriteIfChanged ( char* outbuf
,
130 std::string filename
);
138 CompilationUnit
* compilationUnit
;
146 std::vector
<CompilationUnit
*> compilationUnits
;
147 std::vector
<File
*> files
;
148 std::vector
<Include
*> includes
;
149 std::vector
<Define
*> defines
;
150 std::vector
<Library
*> libraries
;
151 std::vector
<Property
*> properties
;
152 std::vector
<CompilerFlag
*> compilerFlags
;
153 std::vector
<If
*> ifs
;
162 XMLElement
*node
, *head
;
165 std::string makefile
;
166 XMLIncludes xmlbuildfiles
;
167 std::vector
<Module
*> modules
;
168 std::vector
<LinkerFlag
*> linkerFlags
;
169 std::vector
<CDFile
*> cdfiles
;
170 std::vector
<InstallFile
*> installfiles
;
171 IfableData non_if_data
;
173 Project ( const std::string
& filename
);
175 void WriteConfigurationFile ();
176 void ExecuteInvocations ();
177 void ProcessXML ( const std::string
& path
);
178 Module
* LocateModule ( const std::string
& name
);
179 const Module
* LocateModule ( const std::string
& name
) const;
180 std::string
GetProjectFilename () const;
181 std::string
ResolveProperties ( const std::string
& s
) const;
183 std::string
ResolveNextProperty ( std::string
& s
) const;
184 const Property
* LookupProperty ( const std::string
& name
) const;
185 void SetConfigurationOption ( char* s
,
187 std::string
* alternativeName
);
188 void SetConfigurationOption ( char* s
,
191 void ProcessXMLSubElement ( const XMLElement
& e
,
192 const std::string
& path
,
193 ParseContext
& parseContext
);
195 // disable copy semantics
196 Project ( const Project
& );
197 Project
& operator = ( const Project
& );
208 KernelModeDriver
= 5,
234 const Project
& project
;
235 const XMLElement
& node
;
236 std::string xmlbuildFile
;
239 std::string extension
;
240 std::string entrypoint
;
241 std::string baseaddress
;
244 ImportLibrary
* importLibrary
;
247 Bootstrap
* bootstrap
;
248 IfableData non_if_data
;
249 std::vector
<Invoke
*> invocations
;
250 std::vector
<Dependency
*> dependencies
;
251 std::vector
<CompilerFlag
*> compilerFlags
;
252 std::vector
<LinkerFlag
*> linkerFlags
;
253 std::vector
<StubbedComponent
*> stubbedComponents
;
254 LinkerScript
* linkerScript
;
259 std::string installBase
;
260 std::string installName
;
261 std::string aliasedModuleName
;
266 Module ( const Project
& project
,
267 const XMLElement
& moduleNode
,
268 const std::string
& modulePath
);
270 ModuleType
GetModuleType ( const std::string
& location
,
271 const XMLAttribute
& attribute
);
272 bool HasImportLibrary () const;
274 bool GenerateInOutputTree () const;
275 std::string
GetTargetName () const; // "foo.exe"
276 std::string
GetDependencyPath () const; // "path/foo.exe" or "path/libfoo.a"
277 std::string
GetBasePath () const; // "path"
278 std::string
GetPath () const; // "path/foo.exe"
279 std::string
GetPathWithPrefix ( const std::string
& prefix
) const; // "path/prefixfoo.exe"
280 void GetTargets ( string_list
& ) const;
281 std::string
GetInvocationTarget ( const int index
) const;
282 bool HasFileWithExtension ( const IfableData
&, const std::string
& extension
) const;
283 void InvokeModule () const;
285 void GetSourceFilenames ( string_list
& list
,
286 bool includeGeneratedFiles
) const;
288 std::string
GetDefaultModuleExtension () const;
289 std::string
GetDefaultModuleEntrypoint () const;
290 std::string
GetDefaultModuleBaseaddress () const;
291 void ProcessXMLSubElement ( const XMLElement
& e
,
292 const std::string
& path
,
293 ParseContext
& parseContext
);
300 const Project
& project
;
301 const Module
* module
;
302 const XMLElement
* node
;
303 const Module
* baseModule
;
304 std::string directory
;
305 std::string basePath
;
307 Include ( const Project
& project
,
308 const XMLElement
* includeNode
);
309 Include ( const Project
& project
,
310 const Module
* module
,
311 const XMLElement
* includeNode
);
312 Include ( const Project
& project
,
313 std::string directory
,
314 std::string basePath
);
324 const Project
& project
;
325 const Module
* module
;
326 const XMLElement
& node
;
330 Define ( const Project
& project
,
331 const XMLElement
& defineNode
);
332 Define ( const Project
& project
,
333 const Module
* module
,
334 const XMLElement
& defineNode
);
347 std::string switches
;
348 bool isPreCompiledHeader
;
350 File ( const std::string
& _name
,
352 std::string _switches
,
353 bool _isPreCompiledHeader
);
362 const XMLElement
& node
;
363 const Module
& module
;
365 const Module
* importedModule
;
367 Library ( const XMLElement
& _node
,
368 const Module
& _module
,
369 const std::string
& _name
);
378 const XMLElement
& node
;
379 const Module
& module
;
380 const Module
* invokeModule
;
381 std::vector
<InvokeFile
*> input
;
382 std::vector
<InvokeFile
*> output
;
384 Invoke ( const XMLElement
& _node
,
385 const Module
& _module
);
388 void GetTargets ( string_list
& targets
) const;
389 std::string
GetParameters () const;
391 void ProcessXMLSubElement ( const XMLElement
& e
);
392 void ProcessXMLSubElementInput ( const XMLElement
& e
);
393 void ProcessXMLSubElementOutput ( const XMLElement
& e
);
400 const XMLElement
& node
;
402 std::string switches
;
404 InvokeFile ( const XMLElement
& _node
,
405 const std::string
& _name
);
414 const XMLElement
& node
;
415 const Module
& module
;
416 const Module
* dependencyModule
;
418 Dependency ( const XMLElement
& _node
,
419 const Module
& _module
);
428 const XMLElement
& node
;
429 const Module
& module
;
430 std::string basename
;
431 std::string definition
;
433 ImportLibrary ( const XMLElement
& _node
,
434 const Module
& module
);
443 const XMLElement
& node
;
444 const Project
& project
;
445 const Module
* module
;
447 std::string property
, value
;
450 If ( const XMLElement
& node_
,
451 const Project
& project_
,
452 const Module
* module_
,
453 const bool negated_
= false );
463 const Project
& project
;
464 const Module
* module
;
465 const XMLElement
& node
;
468 CompilerFlag ( const Project
& project
,
469 const XMLElement
& compilerFlagNode
);
470 CompilerFlag ( const Project
& project
,
471 const Module
* module
,
472 const XMLElement
& compilerFlagNode
);
483 const Project
& project
;
484 const Module
* module
;
485 const XMLElement
& node
;
488 LinkerFlag ( const Project
& project
,
489 const XMLElement
& linkerFlagNode
);
490 LinkerFlag ( const Project
& project
,
491 const Module
* module
,
492 const XMLElement
& linkerFlagNode
);
503 const Project
& project
;
504 const Module
* module
;
505 const XMLElement
& node
;
506 const Module
* baseModule
;
507 std::string directory
;
508 std::string basePath
;
510 LinkerScript ( const Project
& project
,
511 const Module
* module
,
512 const XMLElement
& node
);
521 const XMLElement
& node
;
522 const Project
& project
;
523 const Module
* module
;
524 std::string name
, value
;
526 Property ( const XMLElement
& node_
,
527 const Project
& project_
,
528 const Module
* module_
);
534 class TestSupportCode
537 const Project
& project
;
539 TestSupportCode ( const Project
& project
);
541 void GenerateTestSupportCode ( bool verbose
);
543 bool IsTestModule ( const Module
& module
);
544 void GenerateTestSupportCodeForModule ( Module
& module
,
546 std::string
GetHooksFilename ( Module
& module
);
547 char* WriteStubbedSymbolToHooksFile ( char* buffer
,
548 const StubbedComponent
& component
,
549 const StubbedSymbol
& symbol
);
550 char* WriteStubbedComponentToHooksFile ( char* buffer
,
551 const StubbedComponent
& component
);
552 void WriteHooksFile ( Module
& module
);
553 std::string
GetStubsFilename ( Module
& module
);
554 char* WriteStubbedSymbolToStubsFile ( char* buffer
,
555 const StubbedComponent
& component
,
556 const StubbedSymbol
& symbol
,
558 char* WriteStubbedComponentToStubsFile ( char* buffer
,
559 const StubbedComponent
& component
,
561 void WriteStubsFile ( Module
& module
);
562 std::string
GetStartupFilename ( Module
& module
);
563 bool IsUnknownCharacter ( char ch
);
564 std::string
GetTestDispatcherName ( std::string filename
);
565 bool IsTestFile ( std::string
& filename
) const;
566 void GetSourceFilenames ( string_list
& list
,
567 Module
& module
) const;
568 char* WriteTestDispatcherPrototypesToStartupFile ( char* buffer
,
570 char* WriteRegisterTestsFunctionToStartupFile ( char* buffer
,
572 void WriteStartupFile ( Module
& module
);
579 const Project
& project
;
582 WineResource ( const Project
& project
,
583 std::string bin2res
);
585 void UnpackResources ( bool verbose
);
587 bool IsSpecFile ( const File
& file
);
588 bool IsWineModule ( const Module
& module
);
589 bool IsResourceFile ( const File
& file
);
590 std::string
GetResourceFilename ( const Module
& module
);
591 void UnpackResourcesInModule ( Module
& module
,
599 SourceFile ( AutomaticDependency
* automaticDependency
,
600 const Module
& module
,
601 const std::string
& filename
,
603 bool isNonAutomaticDependency
);
604 SourceFile
* ParseFile ( const std::string
& normalizedFilename
);
606 std::string
Location () const;
607 std::vector
<SourceFile
*> files
;
608 AutomaticDependency
* automaticDependency
;
609 const Module
& module
;
610 std::string filename
;
611 std::string filenamePart
;
612 std::string directoryPart
;
613 std::vector
<SourceFile
*> parents
; /* List of files, this file is included from */
614 bool isNonAutomaticDependency
;
615 std::string cachedDependencies
;
616 time_t lastWriteTime
;
617 time_t youngestLastWriteTime
; /* Youngest last write time of this file and all children */
618 SourceFile
* youngestFile
;
620 void GetDirectoryAndFilenameParts ();
623 void SkipWhitespace ();
624 bool ReadInclude ( std::string
& filename
,
625 bool& searchCurrentDirectory
,
627 bool IsIncludedFrom ( const std::string
& normalizedFilename
);
628 SourceFile
* GetParentSourceFile ();
629 bool CanProcessFile ( const std::string
& extension
);
630 bool IsParentOf ( const SourceFile
* parent
,
631 const SourceFile
* child
);
638 class AutomaticDependency
640 friend class SourceFileTest
;
642 const Project
& project
;
644 AutomaticDependency ( const Project
& project
);
645 ~AutomaticDependency ();
646 std::string
GetFilename ( const std::string
& filename
);
647 bool LocateIncludedFile ( const std::string
& directory
,
648 const std::string
& includedFilename
,
649 std::string
& resolvedFilename
);
650 bool LocateIncludedFile ( SourceFile
* sourceFile
,
651 const Module
& module
,
652 const std::string
& includedFilename
,
653 bool searchCurrentDirectory
,
655 std::string
& resolvedFilename
);
656 SourceFile
* RetrieveFromCacheOrParse ( const Module
& module
,
657 const std::string
& filename
,
658 SourceFile
* parentSourceFile
);
659 SourceFile
* RetrieveFromCache ( const std::string
& filename
);
660 void CheckAutomaticDependencies ( bool verbose
);
661 void CheckAutomaticDependenciesForModule ( Module
& module
,
664 void GetModulesToCheck ( Module
& module
, std::vector
<const Module
*>& modules
);
665 void CheckAutomaticDependencies ( const Module
& module
,
667 void CheckAutomaticDependenciesForFile ( SourceFile
* sourceFile
);
668 void GetIncludeDirectories ( std::vector
<Include
*>& includes
,
669 const Module
& module
,
670 Include
& currentDirectory
,
671 bool searchCurrentDirectory
);
672 void GetModuleFiles ( const Module
& module
,
673 std::vector
<File
*>& files
) const;
675 void ParseFiles ( const Module
& module
);
676 void ParseFile ( const Module
& module
,
678 std::map
<std::string
, SourceFile
*> sourcefile_map
;
685 const Project
& project
;
686 const Module
* module
;
687 const XMLElement
& node
;
689 std::string nameoncd
;
691 Bootstrap ( const Project
& project
,
692 const Module
* module
,
693 const XMLElement
& bootstrapNode
);
697 bool IsSupportedModuleType ( ModuleType type
);
705 const Project
& project
;
706 const XMLElement
& node
;
709 std::string nameoncd
;
712 CDFile ( const Project
& project
,
713 const XMLElement
& bootstrapNode
,
714 const std::string
& path
);
717 std::string
GetPath () const;
724 const Project
& project
;
725 const XMLElement
& node
;
731 InstallFile ( const Project
& project
,
732 const XMLElement
& bootstrapNode
,
733 const std::string
& path
);
736 std::string
GetPath () const;
743 const XMLElement
& node
;
744 const Module
& module
;
748 const XMLElement
& node
,
749 const Module
& module
,
755 class StubbedComponent
758 const Module
* module
;
759 const XMLElement
& node
;
761 std::vector
<StubbedSymbol
*> symbols
;
763 StubbedComponent ( const Module
* module_
,
764 const XMLElement
& stubbedComponentNode
);
765 ~StubbedComponent ();
767 void ProcessXMLSubElement ( const XMLElement
& e
);
774 const XMLElement
& node
;
777 std::string strippedName
;
779 StubbedSymbol ( const XMLElement
& stubbedSymbolNode
);
783 std::string
StripSymbol ( std::string symbol
);
787 class CompilationUnit
790 const Project
* project
;
791 const Module
* module
;
792 const XMLElement
* node
;
793 std::vector
<File
*> files
;
795 CompilationUnit ( File
* file
);
796 CompilationUnit ( const Project
* project
,
797 const Module
* module
,
798 const XMLElement
* node
);
801 bool IsGeneratedFile () const;
802 bool HasFileWithExtension ( const std::string
& extension
) const;
803 bool IsFirstFile () const;
804 std::string
GetFilename () const;
805 std::string
GetSwitches () const;
810 InitializeEnvironment ();
813 Right ( const std::string
& s
, size_t n
);
816 Replace ( const std::string
& s
, const std::string
& find
, const std::string
& with
);
819 FixSeparator ( const std::string
& s
);
822 FixSeparatorForSystemCommand ( const std::string
& s
);
825 DosSeparator ( const std::string
& s
);
829 const std::string
& filename
,
830 const std::string
& newExtension
);
834 const std::string
& location
,
835 const std::string
& path
,
836 const std::string
& att_value
);
839 GetExtension ( const std::string
& filename
);
842 GetDirectory ( const std::string
& filename
);
845 GetFilename ( const std::string
& filename
);
848 NormalizeFilename ( const std::string
& filename
);
850 #endif /* __RBUILD_H */