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
);
356 bool IsGeneratedFile () const;
363 const XMLElement
& node
;
364 const Module
& module
;
366 const Module
* importedModule
;
368 Library ( const XMLElement
& _node
,
369 const Module
& _module
,
370 const std::string
& _name
);
379 const XMLElement
& node
;
380 const Module
& module
;
381 const Module
* invokeModule
;
382 std::vector
<InvokeFile
*> input
;
383 std::vector
<InvokeFile
*> output
;
385 Invoke ( const XMLElement
& _node
,
386 const Module
& _module
);
389 void GetTargets ( string_list
& targets
) const;
390 std::string
GetParameters () const;
392 void ProcessXMLSubElement ( const XMLElement
& e
);
393 void ProcessXMLSubElementInput ( const XMLElement
& e
);
394 void ProcessXMLSubElementOutput ( const XMLElement
& e
);
401 const XMLElement
& node
;
403 std::string switches
;
405 InvokeFile ( const XMLElement
& _node
,
406 const std::string
& _name
);
415 const XMLElement
& node
;
416 const Module
& module
;
417 const Module
* dependencyModule
;
419 Dependency ( const XMLElement
& _node
,
420 const Module
& _module
);
429 const XMLElement
& node
;
430 const Module
& module
;
431 std::string basename
;
432 std::string definition
;
434 ImportLibrary ( const XMLElement
& _node
,
435 const Module
& module
);
444 const XMLElement
& node
;
445 const Project
& project
;
446 const Module
* module
;
448 std::string property
, value
;
451 If ( const XMLElement
& node_
,
452 const Project
& project_
,
453 const Module
* module_
,
454 const bool negated_
= false );
464 const Project
& project
;
465 const Module
* module
;
466 const XMLElement
& node
;
469 CompilerFlag ( const Project
& project
,
470 const XMLElement
& compilerFlagNode
);
471 CompilerFlag ( const Project
& project
,
472 const Module
* module
,
473 const XMLElement
& compilerFlagNode
);
484 const Project
& project
;
485 const Module
* module
;
486 const XMLElement
& node
;
489 LinkerFlag ( const Project
& project
,
490 const XMLElement
& linkerFlagNode
);
491 LinkerFlag ( const Project
& project
,
492 const Module
* module
,
493 const XMLElement
& linkerFlagNode
);
504 const Project
& project
;
505 const Module
* module
;
506 const XMLElement
& node
;
507 const Module
* baseModule
;
508 std::string directory
;
509 std::string basePath
;
511 LinkerScript ( const Project
& project
,
512 const Module
* module
,
513 const XMLElement
& node
);
522 const XMLElement
& node
;
523 const Project
& project
;
524 const Module
* module
;
525 std::string name
, value
;
527 Property ( const XMLElement
& node_
,
528 const Project
& project_
,
529 const Module
* module_
);
535 class TestSupportCode
538 const Project
& project
;
540 TestSupportCode ( const Project
& project
);
542 void GenerateTestSupportCode ( bool verbose
);
544 bool IsTestModule ( const Module
& module
);
545 void GenerateTestSupportCodeForModule ( Module
& module
,
547 std::string
GetHooksFilename ( Module
& module
);
548 char* WriteStubbedSymbolToHooksFile ( char* buffer
,
549 const StubbedComponent
& component
,
550 const StubbedSymbol
& symbol
);
551 char* WriteStubbedComponentToHooksFile ( char* buffer
,
552 const StubbedComponent
& component
);
553 void WriteHooksFile ( Module
& module
);
554 std::string
GetStubsFilename ( Module
& module
);
555 char* WriteStubbedSymbolToStubsFile ( char* buffer
,
556 const StubbedComponent
& component
,
557 const StubbedSymbol
& symbol
,
559 char* WriteStubbedComponentToStubsFile ( char* buffer
,
560 const StubbedComponent
& component
,
562 void WriteStubsFile ( Module
& module
);
563 std::string
GetStartupFilename ( Module
& module
);
564 bool IsUnknownCharacter ( char ch
);
565 std::string
GetTestDispatcherName ( std::string filename
);
566 bool IsTestFile ( std::string
& filename
) const;
567 void GetSourceFilenames ( string_list
& list
,
568 Module
& module
) const;
569 char* WriteTestDispatcherPrototypesToStartupFile ( char* buffer
,
571 char* WriteRegisterTestsFunctionToStartupFile ( char* buffer
,
573 void WriteStartupFile ( Module
& module
);
580 const Project
& project
;
583 WineResource ( const Project
& project
,
584 std::string bin2res
);
586 void UnpackResources ( bool verbose
);
588 bool IsSpecFile ( const File
& file
);
589 bool IsWineModule ( const Module
& module
);
590 bool IsResourceFile ( const File
& file
);
591 std::string
GetResourceFilename ( const Module
& module
);
592 void UnpackResourcesInModule ( Module
& module
,
600 SourceFile ( AutomaticDependency
* automaticDependency
,
601 const Module
& module
,
602 const std::string
& filename
,
604 bool isNonAutomaticDependency
);
605 SourceFile
* ParseFile ( const std::string
& normalizedFilename
);
607 std::string
Location () const;
608 std::vector
<SourceFile
*> files
;
609 AutomaticDependency
* automaticDependency
;
610 const Module
& module
;
611 std::string filename
;
612 std::string filenamePart
;
613 std::string directoryPart
;
614 std::vector
<SourceFile
*> parents
; /* List of files, this file is included from */
615 bool isNonAutomaticDependency
;
616 std::string cachedDependencies
;
617 time_t lastWriteTime
;
618 time_t youngestLastWriteTime
; /* Youngest last write time of this file and all children */
619 SourceFile
* youngestFile
;
621 void GetDirectoryAndFilenameParts ();
624 void SkipWhitespace ();
625 bool ReadInclude ( std::string
& filename
,
626 bool& searchCurrentDirectory
,
628 bool IsIncludedFrom ( const std::string
& normalizedFilename
);
629 SourceFile
* GetParentSourceFile ();
630 bool CanProcessFile ( const std::string
& extension
);
631 bool IsParentOf ( const SourceFile
* parent
,
632 const SourceFile
* child
);
639 class AutomaticDependency
641 friend class SourceFileTest
;
643 const Project
& project
;
645 AutomaticDependency ( const Project
& project
);
646 ~AutomaticDependency ();
647 std::string
GetFilename ( const std::string
& filename
);
648 bool LocateIncludedFile ( const std::string
& directory
,
649 const std::string
& includedFilename
,
650 std::string
& resolvedFilename
);
651 bool LocateIncludedFile ( SourceFile
* sourceFile
,
652 const Module
& module
,
653 const std::string
& includedFilename
,
654 bool searchCurrentDirectory
,
656 std::string
& resolvedFilename
);
657 SourceFile
* RetrieveFromCacheOrParse ( const Module
& module
,
658 const std::string
& filename
,
659 SourceFile
* parentSourceFile
);
660 SourceFile
* RetrieveFromCache ( const std::string
& filename
);
661 void CheckAutomaticDependencies ( bool verbose
);
662 void CheckAutomaticDependenciesForModule ( Module
& module
,
665 void GetModulesToCheck ( Module
& module
, std::vector
<const Module
*>& modules
);
666 void CheckAutomaticDependencies ( const Module
& module
,
668 void CheckAutomaticDependenciesForFile ( SourceFile
* sourceFile
);
669 void GetIncludeDirectories ( std::vector
<Include
*>& includes
,
670 const Module
& module
,
671 Include
& currentDirectory
,
672 bool searchCurrentDirectory
);
673 void GetModuleFiles ( const Module
& module
,
674 std::vector
<File
*>& files
) const;
676 void ParseFiles ( const Module
& module
);
677 void ParseFile ( const Module
& module
,
679 std::map
<std::string
, SourceFile
*> sourcefile_map
;
686 const Project
& project
;
687 const Module
* module
;
688 const XMLElement
& node
;
690 std::string nameoncd
;
692 Bootstrap ( const Project
& project
,
693 const Module
* module
,
694 const XMLElement
& bootstrapNode
);
698 bool IsSupportedModuleType ( ModuleType type
);
706 const Project
& project
;
707 const XMLElement
& node
;
710 std::string nameoncd
;
713 CDFile ( const Project
& project
,
714 const XMLElement
& bootstrapNode
,
715 const std::string
& path
);
718 std::string
GetPath () const;
725 const Project
& project
;
726 const XMLElement
& node
;
732 InstallFile ( const Project
& project
,
733 const XMLElement
& bootstrapNode
,
734 const std::string
& path
);
737 std::string
GetPath () const;
744 const XMLElement
& node
;
745 const Module
& module
;
749 const XMLElement
& node
,
750 const Module
& module
,
756 class StubbedComponent
759 const Module
* module
;
760 const XMLElement
& node
;
762 std::vector
<StubbedSymbol
*> symbols
;
764 StubbedComponent ( const Module
* module_
,
765 const XMLElement
& stubbedComponentNode
);
766 ~StubbedComponent ();
768 void ProcessXMLSubElement ( const XMLElement
& e
);
775 const XMLElement
& node
;
778 std::string strippedName
;
780 StubbedSymbol ( const XMLElement
& stubbedSymbolNode
);
784 std::string
StripSymbol ( std::string symbol
);
788 class CompilationUnit
791 const Project
& project
;
792 const Module
* module
;
793 const XMLElement
& node
;
794 std::vector
<File
*> files
;
796 CompilationUnit ( const Project
& project
,
797 const Module
* module
,
798 const XMLElement
& node
);
805 InitializeEnvironment ();
808 Right ( const std::string
& s
, size_t n
);
811 Replace ( const std::string
& s
, const std::string
& find
, const std::string
& with
);
814 FixSeparator ( const std::string
& s
);
817 FixSeparatorForSystemCommand ( const std::string
& s
);
820 DosSeparator ( const std::string
& s
);
824 const std::string
& filename
,
825 const std::string
& newExtension
);
829 const std::string
& location
,
830 const std::string
& path
,
831 const std::string
& att_value
);
834 GetExtension ( const std::string
& filename
);
837 GetDirectory ( const std::string
& filename
);
840 GetFilename ( const std::string
& filename
);
843 NormalizeFilename ( const std::string
& filename
);
845 #endif /* __RBUILD_H */