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
;
105 bool AutomaticDependencies
;
106 bool CheckDependenciesForModuleOnly
;
107 std::string CheckDependenciesForModuleOnlyModule
;
108 std::string VSProjectVersion
;
109 bool MakeHandlesInstallDirectories
;
110 bool GenerateProxyMakefilesInSourceTree
;
116 static std::string
GetVariable ( const std::string
& name
);
117 static std::string
GetIntermediatePath ();
118 static std::string
GetOutputPath ();
119 static std::string
GetInstallPath ();
120 static std::string
GetEnvironmentVariablePathOrDefault ( const std::string
& name
,
121 const std::string
& defaultValue
);
124 class FileSupportCode
127 static void WriteIfChanged ( char* outbuf
,
128 std::string filename
);
134 std::vector
<File
*> files
;
135 std::vector
<Include
*> includes
;
136 std::vector
<Define
*> defines
;
137 std::vector
<Library
*> libraries
;
138 std::vector
<Property
*> properties
;
139 std::vector
<CompilerFlag
*> compilerFlags
;
140 std::vector
<If
*> ifs
;
149 XMLElement
*node
, *head
;
152 std::string makefile
;
153 XMLIncludes xmlbuildfiles
;
154 std::vector
<Module
*> modules
;
155 std::vector
<LinkerFlag
*> linkerFlags
;
156 std::vector
<CDFile
*> cdfiles
;
157 std::vector
<InstallFile
*> installfiles
;
158 IfableData non_if_data
;
160 Project ( const std::string
& filename
);
162 void WriteConfigurationFile ();
163 void ExecuteInvocations ();
164 void ProcessXML ( const std::string
& path
);
165 Module
* LocateModule ( const std::string
& name
);
166 const Module
* LocateModule ( const std::string
& name
) const;
167 std::string
GetProjectFilename () const;
168 std::string
ResolveProperties ( const std::string
& s
) const;
170 std::string
ResolveNextProperty ( std::string
& s
) const;
171 const Property
* LookupProperty ( const std::string
& name
) const;
172 void SetConfigurationOption ( char* s
,
174 std::string
* alternativeName
);
175 void SetConfigurationOption ( char* s
,
178 void ProcessXMLSubElement ( const XMLElement
& e
,
179 const std::string
& path
,
182 // disable copy semantics
183 Project ( const Project
& );
184 Project
& operator = ( const Project
& );
195 KernelModeDriver
= 5,
221 const Project
& project
;
222 const XMLElement
& node
;
223 std::string xmlbuildFile
;
226 std::string extension
;
227 std::string entrypoint
;
228 std::string baseaddress
;
231 ImportLibrary
* importLibrary
;
234 Bootstrap
* bootstrap
;
235 IfableData non_if_data
;
236 std::vector
<Invoke
*> invocations
;
237 std::vector
<Dependency
*> dependencies
;
238 std::vector
<CompilerFlag
*> compilerFlags
;
239 std::vector
<LinkerFlag
*> linkerFlags
;
240 std::vector
<StubbedComponent
*> stubbedComponents
;
241 LinkerScript
* linkerScript
;
246 std::string installBase
;
247 std::string installName
;
248 std::string aliasedModuleName
;
253 Module ( const Project
& project
,
254 const XMLElement
& moduleNode
,
255 const std::string
& modulePath
);
257 ModuleType
GetModuleType ( const std::string
& location
,
258 const XMLAttribute
& attribute
);
259 bool HasImportLibrary () const;
261 bool GenerateInOutputTree () const;
262 std::string
GetTargetName () const; // "foo.exe"
263 std::string
GetDependencyPath () const; // "path/foo.exe" or "path/libfoo.a"
264 std::string
GetBasePath () const; // "path"
265 std::string
GetPath () const; // "path/foo.exe"
266 std::string
GetPathWithPrefix ( const std::string
& prefix
) const; // "path/prefixfoo.exe"
267 void GetTargets ( string_list
& ) const;
268 std::string
GetInvocationTarget ( const int index
) const;
269 bool HasFileWithExtension ( const IfableData
&, const std::string
& extension
) const;
270 void InvokeModule () const;
272 void GetSourceFilenames ( string_list
& list
,
273 bool includeGeneratedFiles
) const;
275 std::string
GetDefaultModuleExtension () const;
276 std::string
GetDefaultModuleEntrypoint () const;
277 std::string
GetDefaultModuleBaseaddress () const;
278 void ProcessXMLSubElement ( const XMLElement
& e
,
279 const std::string
& path
,
287 const Project
& project
;
288 const Module
* module
;
289 const XMLElement
* node
;
290 const Module
* baseModule
;
291 std::string directory
;
292 std::string basePath
;
294 Include ( const Project
& project
,
295 const XMLElement
* includeNode
);
296 Include ( const Project
& project
,
297 const Module
* module
,
298 const XMLElement
* includeNode
);
299 Include ( const Project
& project
,
300 std::string directory
,
301 std::string basePath
);
311 const Project
& project
;
312 const Module
* module
;
313 const XMLElement
& node
;
317 Define ( const Project
& project
,
318 const XMLElement
& defineNode
);
319 Define ( const Project
& project
,
320 const Module
* module
,
321 const XMLElement
& defineNode
);
334 std::string switches
;
335 bool isPreCompiledHeader
;
337 File ( const std::string
& _name
,
339 std::string _switches
,
340 bool _isPreCompiledHeader
);
343 bool IsGeneratedFile () const;
350 const XMLElement
& node
;
351 const Module
& module
;
353 const Module
* importedModule
;
355 Library ( const XMLElement
& _node
,
356 const Module
& _module
,
357 const std::string
& _name
);
366 const XMLElement
& node
;
367 const Module
& module
;
368 const Module
* invokeModule
;
369 std::vector
<InvokeFile
*> input
;
370 std::vector
<InvokeFile
*> output
;
372 Invoke ( const XMLElement
& _node
,
373 const Module
& _module
);
376 void GetTargets ( string_list
& targets
) const;
377 std::string
GetParameters () const;
379 void ProcessXMLSubElement ( const XMLElement
& e
);
380 void ProcessXMLSubElementInput ( const XMLElement
& e
);
381 void ProcessXMLSubElementOutput ( const XMLElement
& e
);
388 const XMLElement
& node
;
390 std::string switches
;
392 InvokeFile ( const XMLElement
& _node
,
393 const std::string
& _name
);
402 const XMLElement
& node
;
403 const Module
& module
;
404 const Module
* dependencyModule
;
406 Dependency ( const XMLElement
& _node
,
407 const Module
& _module
);
416 const XMLElement
& node
;
417 const Module
& module
;
418 std::string basename
;
419 std::string definition
;
421 ImportLibrary ( const XMLElement
& _node
,
422 const Module
& module
);
431 const XMLElement
& node
;
432 const Project
& project
;
433 const Module
* module
;
435 std::string property
, value
;
438 If ( const XMLElement
& node_
,
439 const Project
& project_
,
440 const Module
* module_
,
441 const bool negated_
= false );
451 const Project
& project
;
452 const Module
* module
;
453 const XMLElement
& node
;
456 CompilerFlag ( const Project
& project
,
457 const XMLElement
& compilerFlagNode
);
458 CompilerFlag ( const Project
& project
,
459 const Module
* module
,
460 const XMLElement
& compilerFlagNode
);
471 const Project
& project
;
472 const Module
* module
;
473 const XMLElement
& node
;
476 LinkerFlag ( const Project
& project
,
477 const XMLElement
& linkerFlagNode
);
478 LinkerFlag ( const Project
& project
,
479 const Module
* module
,
480 const XMLElement
& linkerFlagNode
);
491 const Project
& project
;
492 const Module
* module
;
493 const XMLElement
& node
;
494 const Module
* baseModule
;
495 std::string directory
;
496 std::string basePath
;
498 LinkerScript ( const Project
& project
,
499 const Module
* module
,
500 const XMLElement
& node
);
509 const XMLElement
& node
;
510 const Project
& project
;
511 const Module
* module
;
512 std::string name
, value
;
514 Property ( const XMLElement
& node_
,
515 const Project
& project_
,
516 const Module
* module_
);
522 class TestSupportCode
525 const Project
& project
;
527 TestSupportCode ( const Project
& project
);
529 void GenerateTestSupportCode ( bool verbose
);
531 bool IsTestModule ( const Module
& module
);
532 void GenerateTestSupportCodeForModule ( Module
& module
,
534 std::string
GetHooksFilename ( Module
& module
);
535 char* WriteStubbedSymbolToHooksFile ( char* buffer
,
536 const StubbedComponent
& component
,
537 const StubbedSymbol
& symbol
);
538 char* WriteStubbedComponentToHooksFile ( char* buffer
,
539 const StubbedComponent
& component
);
540 void WriteHooksFile ( Module
& module
);
541 std::string
GetStubsFilename ( Module
& module
);
542 char* WriteStubbedSymbolToStubsFile ( char* buffer
,
543 const StubbedComponent
& component
,
544 const StubbedSymbol
& symbol
,
546 char* WriteStubbedComponentToStubsFile ( char* buffer
,
547 const StubbedComponent
& component
,
549 void WriteStubsFile ( Module
& module
);
550 std::string
GetStartupFilename ( Module
& module
);
551 bool IsUnknownCharacter ( char ch
);
552 std::string
GetTestDispatcherName ( std::string filename
);
553 bool IsTestFile ( std::string
& filename
) const;
554 void GetSourceFilenames ( string_list
& list
,
555 Module
& module
) const;
556 char* WriteTestDispatcherPrototypesToStartupFile ( char* buffer
,
558 char* WriteRegisterTestsFunctionToStartupFile ( char* buffer
,
560 void WriteStartupFile ( Module
& module
);
567 const Project
& project
;
570 WineResource ( const Project
& project
,
571 std::string bin2res
);
573 void UnpackResources ( bool verbose
);
575 bool IsSpecFile ( const File
& file
);
576 bool IsWineModule ( const Module
& module
);
577 bool IsResourceFile ( const File
& file
);
578 std::string
GetResourceFilename ( const Module
& module
);
579 void UnpackResourcesInModule ( Module
& module
,
587 SourceFile ( AutomaticDependency
* automaticDependency
,
588 const Module
& module
,
589 const std::string
& filename
,
591 bool isNonAutomaticDependency
);
592 SourceFile
* ParseFile ( const std::string
& normalizedFilename
);
594 std::string
Location () const;
595 std::vector
<SourceFile
*> files
;
596 AutomaticDependency
* automaticDependency
;
597 const Module
& module
;
598 std::string filename
;
599 std::string filenamePart
;
600 std::string directoryPart
;
601 std::vector
<SourceFile
*> parents
; /* List of files, this file is included from */
602 bool isNonAutomaticDependency
;
603 std::string cachedDependencies
;
604 time_t lastWriteTime
;
605 time_t youngestLastWriteTime
; /* Youngest last write time of this file and all children */
606 SourceFile
* youngestFile
;
608 void GetDirectoryAndFilenameParts ();
611 void SkipWhitespace ();
612 bool ReadInclude ( std::string
& filename
,
613 bool& searchCurrentDirectory
,
615 bool IsIncludedFrom ( const std::string
& normalizedFilename
);
616 SourceFile
* GetParentSourceFile ();
617 bool CanProcessFile ( const std::string
& extension
);
618 bool IsParentOf ( const SourceFile
* parent
,
619 const SourceFile
* child
);
626 class AutomaticDependency
628 friend class SourceFileTest
;
630 const Project
& project
;
632 AutomaticDependency ( const Project
& project
);
633 ~AutomaticDependency ();
634 std::string
GetFilename ( const std::string
& filename
);
635 bool LocateIncludedFile ( const std::string
& directory
,
636 const std::string
& includedFilename
,
637 std::string
& resolvedFilename
);
638 bool LocateIncludedFile ( SourceFile
* sourceFile
,
639 const Module
& module
,
640 const std::string
& includedFilename
,
641 bool searchCurrentDirectory
,
643 std::string
& resolvedFilename
);
644 SourceFile
* RetrieveFromCacheOrParse ( const Module
& module
,
645 const std::string
& filename
,
646 SourceFile
* parentSourceFile
);
647 SourceFile
* RetrieveFromCache ( const std::string
& filename
);
648 void CheckAutomaticDependencies ( bool verbose
);
649 void CheckAutomaticDependenciesForModule ( Module
& module
,
652 void GetModulesToCheck ( Module
& module
, std::vector
<const Module
*>& modules
);
653 void CheckAutomaticDependencies ( const Module
& module
,
655 void CheckAutomaticDependenciesForFile ( SourceFile
* sourceFile
);
656 void GetIncludeDirectories ( std::vector
<Include
*>& includes
,
657 const Module
& module
,
658 Include
& currentDirectory
,
659 bool searchCurrentDirectory
);
660 void GetModuleFiles ( const Module
& module
,
661 std::vector
<File
*>& files
) const;
663 void ParseFiles ( const Module
& module
);
664 void ParseFile ( const Module
& module
,
666 std::map
<std::string
, SourceFile
*> sourcefile_map
;
673 const Project
& project
;
674 const Module
* module
;
675 const XMLElement
& node
;
677 std::string nameoncd
;
679 Bootstrap ( const Project
& project
,
680 const Module
* module
,
681 const XMLElement
& bootstrapNode
);
685 bool IsSupportedModuleType ( ModuleType type
);
693 const Project
& project
;
694 const XMLElement
& node
;
697 std::string nameoncd
;
700 CDFile ( const Project
& project
,
701 const XMLElement
& bootstrapNode
,
702 const std::string
& path
);
705 std::string
GetPath () const;
712 const Project
& project
;
713 const XMLElement
& node
;
719 InstallFile ( const Project
& project
,
720 const XMLElement
& bootstrapNode
,
721 const std::string
& path
);
724 std::string
GetPath () const;
731 const XMLElement
& node
;
732 const Module
& module
;
736 const XMLElement
& node
,
737 const Module
& module
,
743 class StubbedComponent
746 const Module
* module
;
747 const XMLElement
& node
;
749 std::vector
<StubbedSymbol
*> symbols
;
751 StubbedComponent ( const Module
* module_
,
752 const XMLElement
& stubbedComponentNode
);
753 ~StubbedComponent ();
755 void ProcessXMLSubElement ( const XMLElement
& e
);
762 const XMLElement
& node
;
765 std::string strippedName
;
767 StubbedSymbol ( const XMLElement
& stubbedSymbolNode
);
771 std::string
StripSymbol ( std::string symbol
);
775 Right ( const std::string
& s
, size_t n
);
778 Replace ( const std::string
& s
, const std::string
& find
, const std::string
& with
);
781 FixSeparator ( const std::string
& s
);
784 FixSeparatorForSystemCommand ( const std::string
& s
);
787 DosSeparator ( const std::string
& s
);
791 const std::string
& filename
,
792 const std::string
& newExtension
);
796 const std::string
& location
,
797 const std::string
& path
,
798 const std::string
& att_value
);
801 GetExtension ( const std::string
& filename
);
804 GetDirectory ( const std::string
& filename
);
807 GetFilename ( const std::string
& filename
);
810 NormalizeFilename ( const std::string
& filename
);
812 #endif /* __RBUILD_H */