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
;
46 #define EXEPOSTFIX ".exe"
52 #define EXEPREFIX "./"
60 #define MS_VS_DEF_VERSION "7.10"
78 class TestSupportCode
;
80 class AutomaticDependency
;
85 class StubbedComponent
;
98 bool AutomaticDependencies
;
99 bool CheckDependenciesForModuleOnly
;
100 std::string CheckDependenciesForModuleOnlyModule
;
101 std::string VSProjectVersion
;
102 bool MakeHandlesInstallDirectories
;
103 bool GenerateProxyMakefilesInSourceTree
;
109 static std::string
GetVariable ( const std::string
& name
);
110 static std::string
GetIntermediatePath ();
111 static std::string
GetOutputPath ();
112 static std::string
GetInstallPath ();
113 static std::string
GetEnvironmentVariablePathOrDefault ( const std::string
& name
,
114 const std::string
& defaultValue
);
117 class FileSupportCode
120 static void WriteIfChanged ( char* outbuf
,
121 std::string filename
);
127 std::vector
<File
*> files
;
128 std::vector
<Include
*> includes
;
129 std::vector
<Define
*> defines
;
130 std::vector
<Library
*> libraries
;
131 std::vector
<Property
*> properties
;
132 std::vector
<CompilerFlag
*> compilerFlags
;
133 std::vector
<If
*> ifs
;
142 XMLElement
*node
, *head
;
145 std::string makefile
;
146 XMLIncludes xmlbuildfiles
;
147 std::vector
<Module
*> modules
;
148 std::vector
<LinkerFlag
*> linkerFlags
;
149 std::vector
<CDFile
*> cdfiles
;
150 std::vector
<InstallFile
*> installfiles
;
151 IfableData non_if_data
;
153 Project ( const std::string
& filename
);
155 void WriteConfigurationFile ();
156 void ExecuteInvocations ();
157 void ProcessXML ( const std::string
& path
);
158 Module
* LocateModule ( const std::string
& name
);
159 const Module
* LocateModule ( const std::string
& name
) const;
160 std::string
GetProjectFilename () const;
161 std::string
ResolveProperties ( const std::string
& s
) const;
163 std::string
ResolveNextProperty ( std::string
& s
) const;
164 const Property
* LookupProperty ( const std::string
& name
) const;
165 void SetConfigurationOption ( char* s
,
167 std::string
* alternativeName
);
168 void SetConfigurationOption ( char* s
,
171 void ProcessXMLSubElement ( const XMLElement
& e
,
172 const std::string
& path
,
175 // disable copy semantics
176 Project ( const Project
& );
177 Project
& operator = ( const Project
& );
188 KernelModeDriver
= 5,
214 const Project
& project
;
215 const XMLElement
& node
;
216 std::string xmlbuildFile
;
219 std::string extension
;
220 std::string entrypoint
;
221 std::string baseaddress
;
224 ImportLibrary
* importLibrary
;
227 Bootstrap
* bootstrap
;
228 IfableData non_if_data
;
229 std::vector
<Invoke
*> invocations
;
230 std::vector
<Dependency
*> dependencies
;
231 std::vector
<CompilerFlag
*> compilerFlags
;
232 std::vector
<LinkerFlag
*> linkerFlags
;
233 std::vector
<StubbedComponent
*> stubbedComponents
;
234 LinkerScript
* linkerScript
;
239 std::string installBase
;
240 std::string installName
;
241 std::string aliasedModuleName
;
246 Module ( const Project
& project
,
247 const XMLElement
& moduleNode
,
248 const std::string
& modulePath
);
250 ModuleType
GetModuleType ( const std::string
& location
,
251 const XMLAttribute
& attribute
);
252 bool HasImportLibrary () const;
254 bool GenerateInOutputTree () const;
255 std::string
GetTargetName () const; // "foo.exe"
256 std::string
GetDependencyPath () const; // "path/foo.exe" or "path/libfoo.a"
257 std::string
GetBasePath () const; // "path"
258 std::string
GetPath () const; // "path/foo.exe"
259 std::string
GetPathWithPrefix ( const std::string
& prefix
) const; // "path/prefixfoo.exe"
260 void GetTargets ( string_list
& ) const;
261 std::string
GetInvocationTarget ( const int index
) const;
262 bool HasFileWithExtension ( const IfableData
&, const std::string
& extension
) const;
263 void InvokeModule () const;
265 void GetSourceFilenames ( string_list
& list
,
266 bool includeGeneratedFiles
) const;
268 std::string
GetDefaultModuleExtension () const;
269 std::string
GetDefaultModuleEntrypoint () const;
270 std::string
GetDefaultModuleBaseaddress () const;
271 void ProcessXMLSubElement ( const XMLElement
& e
,
272 const std::string
& path
,
280 const Project
& project
;
281 const Module
* module
;
282 const XMLElement
* node
;
283 const Module
* baseModule
;
284 std::string directory
;
285 std::string basePath
;
287 Include ( const Project
& project
,
288 const XMLElement
* includeNode
);
289 Include ( const Project
& project
,
290 const Module
* module
,
291 const XMLElement
* includeNode
);
292 Include ( const Project
& project
,
293 std::string directory
,
294 std::string basePath
);
304 const Project
& project
;
305 const Module
* module
;
306 const XMLElement
& node
;
310 Define ( const Project
& project
,
311 const XMLElement
& defineNode
);
312 Define ( const Project
& project
,
313 const Module
* module
,
314 const XMLElement
& defineNode
);
327 std::string switches
;
328 bool isPreCompiledHeader
;
330 File ( const std::string
& _name
,
332 std::string _switches
,
333 bool _isPreCompiledHeader
);
336 bool IsGeneratedFile () const;
343 const XMLElement
& node
;
344 const Module
& module
;
346 const Module
* importedModule
;
348 Library ( const XMLElement
& _node
,
349 const Module
& _module
,
350 const std::string
& _name
);
359 const XMLElement
& node
;
360 const Module
& module
;
361 const Module
* invokeModule
;
362 std::vector
<InvokeFile
*> input
;
363 std::vector
<InvokeFile
*> output
;
365 Invoke ( const XMLElement
& _node
,
366 const Module
& _module
);
369 void GetTargets ( string_list
& targets
) const;
370 std::string
GetParameters () const;
372 void ProcessXMLSubElement ( const XMLElement
& e
);
373 void ProcessXMLSubElementInput ( const XMLElement
& e
);
374 void ProcessXMLSubElementOutput ( const XMLElement
& e
);
381 const XMLElement
& node
;
383 std::string switches
;
385 InvokeFile ( const XMLElement
& _node
,
386 const std::string
& _name
);
395 const XMLElement
& node
;
396 const Module
& module
;
397 const Module
* dependencyModule
;
399 Dependency ( const XMLElement
& _node
,
400 const Module
& _module
);
409 const XMLElement
& node
;
410 const Module
& module
;
411 std::string basename
;
412 std::string definition
;
414 ImportLibrary ( const XMLElement
& _node
,
415 const Module
& module
);
424 const XMLElement
& node
;
425 const Project
& project
;
426 const Module
* module
;
428 std::string property
, value
;
431 If ( const XMLElement
& node_
,
432 const Project
& project_
,
433 const Module
* module_
,
434 const bool negated_
= false );
444 const Project
& project
;
445 const Module
* module
;
446 const XMLElement
& node
;
449 CompilerFlag ( const Project
& project
,
450 const XMLElement
& compilerFlagNode
);
451 CompilerFlag ( const Project
& project
,
452 const Module
* module
,
453 const XMLElement
& compilerFlagNode
);
464 const Project
& project
;
465 const Module
* module
;
466 const XMLElement
& node
;
469 LinkerFlag ( const Project
& project
,
470 const XMLElement
& linkerFlagNode
);
471 LinkerFlag ( const Project
& project
,
472 const Module
* module
,
473 const XMLElement
& linkerFlagNode
);
484 const Project
& project
;
485 const Module
* module
;
486 const XMLElement
& node
;
487 const Module
* baseModule
;
488 std::string directory
;
489 std::string basePath
;
491 LinkerScript ( const Project
& project
,
492 const Module
* module
,
493 const XMLElement
& node
);
502 const XMLElement
& node
;
503 const Project
& project
;
504 const Module
* module
;
505 std::string name
, value
;
507 Property ( const XMLElement
& node_
,
508 const Project
& project_
,
509 const Module
* module_
);
515 class TestSupportCode
518 const Project
& project
;
520 TestSupportCode ( const Project
& project
);
522 void GenerateTestSupportCode ( bool verbose
);
524 bool IsTestModule ( const Module
& module
);
525 void GenerateTestSupportCodeForModule ( Module
& module
,
527 std::string
GetHooksFilename ( Module
& module
);
528 char* WriteStubbedSymbolToHooksFile ( char* buffer
,
529 const StubbedComponent
& component
,
530 const StubbedSymbol
& symbol
);
531 char* WriteStubbedComponentToHooksFile ( char* buffer
,
532 const StubbedComponent
& component
);
533 void WriteHooksFile ( Module
& module
);
534 std::string
GetStubsFilename ( Module
& module
);
535 char* WriteStubbedSymbolToStubsFile ( char* buffer
,
536 const StubbedComponent
& component
,
537 const StubbedSymbol
& symbol
,
539 char* WriteStubbedComponentToStubsFile ( char* buffer
,
540 const StubbedComponent
& component
,
542 void WriteStubsFile ( Module
& module
);
543 std::string
GetStartupFilename ( Module
& module
);
544 bool IsUnknownCharacter ( char ch
);
545 std::string
GetTestDispatcherName ( std::string filename
);
546 bool IsTestFile ( std::string
& filename
) const;
547 void GetSourceFilenames ( string_list
& list
,
548 Module
& module
) const;
549 char* WriteTestDispatcherPrototypesToStartupFile ( char* buffer
,
551 char* WriteRegisterTestsFunctionToStartupFile ( char* buffer
,
553 void WriteStartupFile ( Module
& module
);
560 const Project
& project
;
563 WineResource ( const Project
& project
,
564 std::string bin2res
);
566 void UnpackResources ( bool verbose
);
568 bool IsSpecFile ( const File
& file
);
569 bool IsWineModule ( const Module
& module
);
570 bool IsResourceFile ( const File
& file
);
571 std::string
GetResourceFilename ( const Module
& module
);
572 void UnpackResourcesInModule ( Module
& module
,
580 SourceFile ( AutomaticDependency
* automaticDependency
,
581 const Module
& module
,
582 const std::string
& filename
,
584 bool isNonAutomaticDependency
);
585 SourceFile
* ParseFile ( const std::string
& normalizedFilename
);
587 std::string
Location () const;
588 std::vector
<SourceFile
*> files
;
589 AutomaticDependency
* automaticDependency
;
590 const Module
& module
;
591 std::string filename
;
592 std::string filenamePart
;
593 std::string directoryPart
;
594 std::vector
<SourceFile
*> parents
; /* List of files, this file is included from */
595 bool isNonAutomaticDependency
;
596 std::string cachedDependencies
;
597 time_t lastWriteTime
;
598 time_t youngestLastWriteTime
; /* Youngest last write time of this file and all children */
599 SourceFile
* youngestFile
;
601 void GetDirectoryAndFilenameParts ();
604 void SkipWhitespace ();
605 bool ReadInclude ( std::string
& filename
,
606 bool& searchCurrentDirectory
,
608 bool IsIncludedFrom ( const std::string
& normalizedFilename
);
609 SourceFile
* GetParentSourceFile ();
610 bool CanProcessFile ( const std::string
& extension
);
611 bool IsParentOf ( const SourceFile
* parent
,
612 const SourceFile
* child
);
619 class AutomaticDependency
621 friend class SourceFileTest
;
623 const Project
& project
;
625 AutomaticDependency ( const Project
& project
);
626 ~AutomaticDependency ();
627 std::string
GetFilename ( const std::string
& filename
);
628 bool LocateIncludedFile ( const std::string
& directory
,
629 const std::string
& includedFilename
,
630 std::string
& resolvedFilename
);
631 bool LocateIncludedFile ( SourceFile
* sourceFile
,
632 const Module
& module
,
633 const std::string
& includedFilename
,
634 bool searchCurrentDirectory
,
636 std::string
& resolvedFilename
);
637 SourceFile
* RetrieveFromCacheOrParse ( const Module
& module
,
638 const std::string
& filename
,
639 SourceFile
* parentSourceFile
);
640 SourceFile
* RetrieveFromCache ( const std::string
& filename
);
641 void CheckAutomaticDependencies ( bool verbose
);
642 void CheckAutomaticDependenciesForModule ( Module
& module
,
645 void GetModulesToCheck ( Module
& module
, std::vector
<const Module
*>& modules
);
646 void CheckAutomaticDependencies ( const Module
& module
,
648 void CheckAutomaticDependenciesForFile ( SourceFile
* sourceFile
);
649 void GetIncludeDirectories ( std::vector
<Include
*>& includes
,
650 const Module
& module
,
651 Include
& currentDirectory
,
652 bool searchCurrentDirectory
);
653 void GetModuleFiles ( const Module
& module
,
654 std::vector
<File
*>& files
) const;
656 void ParseFiles ( const Module
& module
);
657 void ParseFile ( const Module
& module
,
659 std::map
<std::string
, SourceFile
*> sourcefile_map
;
666 const Project
& project
;
667 const Module
* module
;
668 const XMLElement
& node
;
670 std::string nameoncd
;
672 Bootstrap ( const Project
& project
,
673 const Module
* module
,
674 const XMLElement
& bootstrapNode
);
678 bool IsSupportedModuleType ( ModuleType type
);
686 const Project
& project
;
687 const XMLElement
& node
;
690 std::string nameoncd
;
693 CDFile ( const Project
& project
,
694 const XMLElement
& bootstrapNode
,
695 const std::string
& path
);
698 std::string
GetPath () const;
705 const Project
& project
;
706 const XMLElement
& node
;
712 InstallFile ( const Project
& project
,
713 const XMLElement
& bootstrapNode
,
714 const std::string
& path
);
717 std::string
GetPath () const;
724 const XMLElement
& node
;
725 const Module
& module
;
729 const XMLElement
& node
,
730 const Module
& module
,
736 class StubbedComponent
739 const Module
* module
;
740 const XMLElement
& node
;
742 std::vector
<StubbedSymbol
*> symbols
;
744 StubbedComponent ( const Module
* module_
,
745 const XMLElement
& stubbedComponentNode
);
746 ~StubbedComponent ();
748 void ProcessXMLSubElement ( const XMLElement
& e
);
755 const XMLElement
& node
;
758 std::string strippedName
;
760 StubbedSymbol ( const XMLElement
& stubbedSymbolNode
);
764 std::string
StripSymbol ( std::string symbol
);
768 Right ( const std::string
& s
, size_t n
);
771 Replace ( const std::string
& s
, const std::string
& find
, const std::string
& with
);
774 FixSeparator ( const std::string
& s
);
777 DosSeparator ( const std::string
& s
);
781 const std::string
& filename
,
782 const std::string
& newExtension
);
786 const std::string
& location
,
787 const std::string
& path
,
788 const std::string
& att_value
);
791 GetExtension ( const std::string
& filename
);
794 GetDirectory ( const std::string
& filename
);
797 GetFilename ( const std::string
& filename
);
800 NormalizeFilename ( const std::string
& filename
);
802 #endif /* __RBUILD_H */