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 "./"
75 class TestSupportCode
;
77 class AutomaticDependency
;
82 class StubbedComponent
;
95 bool AutomaticDependencies
;
96 bool CheckDependenciesForModuleOnly
;
97 std::string CheckDependenciesForModuleOnlyModule
;
98 bool MakeHandlesInstallDirectories
;
99 bool GenerateProxyMakefilesInSourceTree
;
105 static std::string
GetVariable ( const std::string
& name
);
106 static std::string
GetIntermediatePath ();
107 static std::string
GetOutputPath ();
108 static std::string
GetInstallPath ();
109 static std::string
GetEnvironmentVariablePathOrDefault ( const std::string
& name
,
110 const std::string
& defaultValue
);
113 class FileSupportCode
116 static void WriteIfChanged ( char* outbuf
,
117 std::string filename
);
123 std::vector
<File
*> files
;
124 std::vector
<Include
*> includes
;
125 std::vector
<Define
*> defines
;
126 std::vector
<Library
*> libraries
;
127 std::vector
<Property
*> properties
;
128 std::vector
<CompilerFlag
*> compilerFlags
;
129 std::vector
<If
*> ifs
;
138 XMLElement
*node
, *head
;
141 std::string makefile
;
142 XMLIncludes xmlbuildfiles
;
143 std::vector
<Module
*> modules
;
144 std::vector
<LinkerFlag
*> linkerFlags
;
145 std::vector
<CDFile
*> cdfiles
;
146 std::vector
<InstallFile
*> installfiles
;
147 IfableData non_if_data
;
149 Project ( const std::string
& filename
);
151 void WriteConfigurationFile ();
152 void ExecuteInvocations ();
153 void ProcessXML ( const std::string
& path
);
154 Module
* LocateModule ( const std::string
& name
);
155 const Module
* LocateModule ( const std::string
& name
) const;
156 std::string
GetProjectFilename () const;
157 std::string
ResolveProperties ( const std::string
& s
) const;
159 std::string
ResolveNextProperty ( std::string
& s
) const;
160 const Property
* LookupProperty ( const std::string
& name
) const;
161 void SetConfigurationOption ( char* s
,
163 std::string
* alternativeName
);
164 void SetConfigurationOption ( char* s
,
167 void ProcessXMLSubElement ( const XMLElement
& e
,
168 const std::string
& path
,
171 // disable copy semantics
172 Project ( const Project
& );
173 Project
& operator = ( const Project
& );
184 KernelModeDriver
= 5,
210 const Project
& project
;
211 const XMLElement
& node
;
212 std::string xmlbuildFile
;
214 std::string extension
;
215 std::string entrypoint
;
216 std::string baseaddress
;
219 ImportLibrary
* importLibrary
;
221 Bootstrap
* bootstrap
;
222 IfableData non_if_data
;
223 std::vector
<Invoke
*> invocations
;
224 std::vector
<Dependency
*> dependencies
;
225 std::vector
<CompilerFlag
*> compilerFlags
;
226 std::vector
<LinkerFlag
*> linkerFlags
;
227 std::vector
<StubbedComponent
*> stubbedComponents
;
232 std::string installBase
;
233 std::string installName
;
234 std::string aliasedModuleName
;
239 Module ( const Project
& project
,
240 const XMLElement
& moduleNode
,
241 const std::string
& modulePath
);
243 ModuleType
GetModuleType ( const std::string
& location
,
244 const XMLAttribute
& attribute
);
245 bool HasImportLibrary () const;
247 bool GenerateInOutputTree () const;
248 std::string
GetTargetName () const;
249 std::string
GetDependencyPath () const;
250 std::string
GetBasePath () const;
251 std::string
GetPath () const;
252 std::string
GetPathWithPrefix ( const std::string
& prefix
) const;
253 void GetTargets ( string_list
& ) const;
254 std::string
GetInvocationTarget ( const int index
) const;
255 bool HasFileWithExtension ( const IfableData
&, const std::string
& extension
) const;
256 void InvokeModule () const;
258 void GetSourceFilenames ( string_list
& list
,
259 bool includeGeneratedFiles
) const;
261 std::string
GetDefaultModuleExtension () const;
262 std::string
GetDefaultModuleEntrypoint () const;
263 std::string
GetDefaultModuleBaseaddress () const;
264 void ProcessXMLSubElement ( const XMLElement
& e
,
265 const std::string
& path
,
273 const Project
& project
;
274 const Module
* module
;
275 const XMLElement
* node
;
276 const Module
* baseModule
;
277 std::string directory
;
278 std::string basePath
;
280 Include ( const Project
& project
,
281 const XMLElement
* includeNode
);
282 Include ( const Project
& project
,
283 const Module
* module
,
284 const XMLElement
* includeNode
);
285 Include ( const Project
& project
,
286 std::string directory
,
287 std::string basePath
);
297 const Project
& project
;
298 const Module
* module
;
299 const XMLElement
& node
;
303 Define ( const Project
& project
,
304 const XMLElement
& defineNode
);
305 Define ( const Project
& project
,
306 const Module
* module
,
307 const XMLElement
& defineNode
);
320 std::string switches
;
321 bool isPreCompiledHeader
;
323 File ( const std::string
& _name
,
325 std::string _switches
,
326 bool _isPreCompiledHeader
);
329 bool IsGeneratedFile () const;
336 const XMLElement
& node
;
337 const Module
& module
;
339 const Module
* importedModule
;
341 Library ( const XMLElement
& _node
,
342 const Module
& _module
,
343 const std::string
& _name
);
352 const XMLElement
& node
;
353 const Module
& module
;
354 const Module
* invokeModule
;
355 std::vector
<InvokeFile
*> input
;
356 std::vector
<InvokeFile
*> output
;
358 Invoke ( const XMLElement
& _node
,
359 const Module
& _module
);
362 void GetTargets ( string_list
& targets
) const;
363 std::string
GetParameters () const;
365 void ProcessXMLSubElement ( const XMLElement
& e
);
366 void ProcessXMLSubElementInput ( const XMLElement
& e
);
367 void ProcessXMLSubElementOutput ( const XMLElement
& e
);
374 const XMLElement
& node
;
376 std::string switches
;
378 InvokeFile ( const XMLElement
& _node
,
379 const std::string
& _name
);
388 const XMLElement
& node
;
389 const Module
& module
;
390 const Module
* dependencyModule
;
392 Dependency ( const XMLElement
& _node
,
393 const Module
& _module
);
402 const XMLElement
& node
;
403 const Module
& module
;
404 std::string basename
;
405 std::string definition
;
407 ImportLibrary ( const XMLElement
& _node
,
408 const Module
& module
);
417 const XMLElement
& node
;
418 const Project
& project
;
419 const Module
* module
;
421 std::string property
, value
;
424 If ( const XMLElement
& node_
,
425 const Project
& project_
,
426 const Module
* module_
,
427 const bool negated_
= false );
437 const Project
& project
;
438 const Module
* module
;
439 const XMLElement
& node
;
442 CompilerFlag ( const Project
& project
,
443 const XMLElement
& compilerFlagNode
);
444 CompilerFlag ( const Project
& project
,
445 const Module
* module
,
446 const XMLElement
& compilerFlagNode
);
457 const Project
& project
;
458 const Module
* module
;
459 const XMLElement
& node
;
462 LinkerFlag ( const Project
& project
,
463 const XMLElement
& linkerFlagNode
);
464 LinkerFlag ( const Project
& project
,
465 const Module
* module
,
466 const XMLElement
& linkerFlagNode
);
477 const XMLElement
& node
;
478 const Project
& project
;
479 const Module
* module
;
480 std::string name
, value
;
482 Property ( const XMLElement
& node_
,
483 const Project
& project_
,
484 const Module
* module_
);
490 class TestSupportCode
493 const Project
& project
;
495 TestSupportCode ( const Project
& project
);
497 void GenerateTestSupportCode ( bool verbose
);
499 bool IsTestModule ( const Module
& module
);
500 void GenerateTestSupportCodeForModule ( Module
& module
,
502 std::string
GetHooksFilename ( Module
& module
);
503 char* WriteStubbedSymbolToHooksFile ( char* buffer
,
504 const StubbedComponent
& component
,
505 const StubbedSymbol
& symbol
);
506 char* WriteStubbedComponentToHooksFile ( char* buffer
,
507 const StubbedComponent
& component
);
508 void WriteHooksFile ( Module
& module
);
509 std::string
GetStubsFilename ( Module
& module
);
510 char* WriteStubbedSymbolToStubsFile ( char* buffer
,
511 const StubbedComponent
& component
,
512 const StubbedSymbol
& symbol
,
514 char* WriteStubbedComponentToStubsFile ( char* buffer
,
515 const StubbedComponent
& component
,
517 void WriteStubsFile ( Module
& module
);
518 std::string
GetStartupFilename ( Module
& module
);
519 bool IsUnknownCharacter ( char ch
);
520 std::string
GetTestDispatcherName ( std::string filename
);
521 bool IsTestFile ( std::string
& filename
) const;
522 void GetSourceFilenames ( string_list
& list
,
523 Module
& module
) const;
524 char* WriteTestDispatcherPrototypesToStartupFile ( char* buffer
,
526 char* WriteRegisterTestsFunctionToStartupFile ( char* buffer
,
528 void WriteStartupFile ( Module
& module
);
535 const Project
& project
;
538 WineResource ( const Project
& project
,
539 std::string bin2res
);
541 void UnpackResources ( bool verbose
);
543 bool IsSpecFile ( const File
& file
);
544 bool IsWineModule ( const Module
& module
);
545 bool IsResourceFile ( const File
& file
);
546 std::string
GetResourceFilename ( const Module
& module
);
547 void UnpackResourcesInModule ( Module
& module
,
555 SourceFile ( AutomaticDependency
* automaticDependency
,
556 const Module
& module
,
557 const std::string
& filename
,
559 bool isNonAutomaticDependency
);
560 SourceFile
* ParseFile ( const std::string
& normalizedFilename
);
562 std::string
Location () const;
563 std::vector
<SourceFile
*> files
;
564 AutomaticDependency
* automaticDependency
;
565 const Module
& module
;
566 std::string filename
;
567 std::string filenamePart
;
568 std::string directoryPart
;
569 std::vector
<SourceFile
*> parents
; /* List of files, this file is included from */
570 bool isNonAutomaticDependency
;
571 std::string cachedDependencies
;
572 time_t lastWriteTime
;
573 time_t youngestLastWriteTime
; /* Youngest last write time of this file and all children */
574 SourceFile
* youngestFile
;
576 void GetDirectoryAndFilenameParts ();
579 void SkipWhitespace ();
580 bool ReadInclude ( std::string
& filename
,
581 bool& searchCurrentDirectory
,
583 bool IsIncludedFrom ( const std::string
& normalizedFilename
);
584 SourceFile
* GetParentSourceFile ();
585 bool CanProcessFile ( const std::string
& extension
);
586 bool IsParentOf ( const SourceFile
* parent
,
587 const SourceFile
* child
);
594 class AutomaticDependency
596 friend class SourceFileTest
;
598 const Project
& project
;
600 AutomaticDependency ( const Project
& project
);
601 ~AutomaticDependency ();
602 std::string
GetFilename ( const std::string
& filename
);
603 bool LocateIncludedFile ( const std::string
& directory
,
604 const std::string
& includedFilename
,
605 std::string
& resolvedFilename
);
606 bool LocateIncludedFile ( SourceFile
* sourceFile
,
607 const Module
& module
,
608 const std::string
& includedFilename
,
609 bool searchCurrentDirectory
,
611 std::string
& resolvedFilename
);
612 SourceFile
* RetrieveFromCacheOrParse ( const Module
& module
,
613 const std::string
& filename
,
614 SourceFile
* parentSourceFile
);
615 SourceFile
* RetrieveFromCache ( const std::string
& filename
);
616 void CheckAutomaticDependencies ( bool verbose
);
617 void CheckAutomaticDependenciesForModule ( Module
& module
,
620 void GetModulesToCheck ( Module
& module
, std::vector
<const Module
*>& modules
);
621 void CheckAutomaticDependencies ( const Module
& module
,
623 void CheckAutomaticDependenciesForFile ( SourceFile
* sourceFile
);
624 void GetIncludeDirectories ( std::vector
<Include
*>& includes
,
625 const Module
& module
,
626 Include
& currentDirectory
,
627 bool searchCurrentDirectory
);
628 void GetModuleFiles ( const Module
& module
,
629 std::vector
<File
*>& files
) const;
631 void ParseFiles ( const Module
& module
);
632 void ParseFile ( const Module
& module
,
634 std::map
<std::string
, SourceFile
*> sourcefile_map
;
641 const Project
& project
;
642 const Module
* module
;
643 const XMLElement
& node
;
645 std::string nameoncd
;
647 Bootstrap ( const Project
& project
,
648 const Module
* module
,
649 const XMLElement
& bootstrapNode
);
653 bool IsSupportedModuleType ( ModuleType type
);
661 const Project
& project
;
662 const XMLElement
& node
;
665 std::string nameoncd
;
668 CDFile ( const Project
& project
,
669 const XMLElement
& bootstrapNode
,
670 const std::string
& path
);
673 std::string
GetPath () const;
680 const Project
& project
;
681 const XMLElement
& node
;
687 InstallFile ( const Project
& project
,
688 const XMLElement
& bootstrapNode
,
689 const std::string
& path
);
692 std::string
GetPath () const;
699 const XMLElement
& node
;
700 const Module
& module
;
704 const XMLElement
& node
,
705 const Module
& module
,
711 class StubbedComponent
714 const Module
* module
;
715 const XMLElement
& node
;
717 std::vector
<StubbedSymbol
*> symbols
;
719 StubbedComponent ( const Module
* module_
,
720 const XMLElement
& stubbedComponentNode
);
721 ~StubbedComponent ();
723 void ProcessXMLSubElement ( const XMLElement
& e
);
730 const XMLElement
& node
;
733 std::string strippedName
;
735 StubbedSymbol ( const XMLElement
& stubbedSymbolNode
);
739 std::string
StripSymbol ( std::string symbol
);
744 FixSeparator ( const std::string
& s
);
748 const std::string
& filename
,
749 const std::string
& newExtension
);
753 const std::string
& location
,
754 const std::string
& path
,
755 const std::string
& att_value
);
758 GetExtension ( const std::string
& filename
);
761 GetDirectory ( const std::string
& filename
);
764 GetFilename ( const std::string
& filename
);
767 NormalizeFilename ( const std::string
& filename
);
769 #endif /* __RBUILD_H */