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"
77 class TestSupportCode
;
79 class AutomaticDependency
;
84 class StubbedComponent
;
97 bool AutomaticDependencies
;
98 bool CheckDependenciesForModuleOnly
;
99 std::string CheckDependenciesForModuleOnlyModule
;
100 std::string VSProjectVersion
;
101 bool MakeHandlesInstallDirectories
;
102 bool GenerateProxyMakefilesInSourceTree
;
108 static std::string
GetVariable ( const std::string
& name
);
109 static std::string
GetIntermediatePath ();
110 static std::string
GetOutputPath ();
111 static std::string
GetInstallPath ();
112 static std::string
GetEnvironmentVariablePathOrDefault ( const std::string
& name
,
113 const std::string
& defaultValue
);
116 class FileSupportCode
119 static void WriteIfChanged ( char* outbuf
,
120 std::string filename
);
126 std::vector
<File
*> files
;
127 std::vector
<Include
*> includes
;
128 std::vector
<Define
*> defines
;
129 std::vector
<Library
*> libraries
;
130 std::vector
<Property
*> properties
;
131 std::vector
<CompilerFlag
*> compilerFlags
;
132 std::vector
<If
*> ifs
;
141 XMLElement
*node
, *head
;
144 std::string makefile
;
145 XMLIncludes xmlbuildfiles
;
146 std::vector
<Module
*> modules
;
147 std::vector
<LinkerFlag
*> linkerFlags
;
148 std::vector
<CDFile
*> cdfiles
;
149 std::vector
<InstallFile
*> installfiles
;
150 IfableData non_if_data
;
152 Project ( const std::string
& filename
);
154 void WriteConfigurationFile ();
155 void ExecuteInvocations ();
156 void ProcessXML ( const std::string
& path
);
157 Module
* LocateModule ( const std::string
& name
);
158 const Module
* LocateModule ( const std::string
& name
) const;
159 std::string
GetProjectFilename () const;
160 std::string
ResolveProperties ( const std::string
& s
) const;
162 std::string
ResolveNextProperty ( std::string
& s
) const;
163 const Property
* LookupProperty ( const std::string
& name
) const;
164 void SetConfigurationOption ( char* s
,
166 std::string
* alternativeName
);
167 void SetConfigurationOption ( char* s
,
170 void ProcessXMLSubElement ( const XMLElement
& e
,
171 const std::string
& path
,
174 // disable copy semantics
175 Project ( const Project
& );
176 Project
& operator = ( const Project
& );
187 KernelModeDriver
= 5,
213 const Project
& project
;
214 const XMLElement
& node
;
215 std::string xmlbuildFile
;
217 std::string extension
;
218 std::string entrypoint
;
219 std::string baseaddress
;
222 ImportLibrary
* importLibrary
;
224 Bootstrap
* bootstrap
;
225 IfableData non_if_data
;
226 std::vector
<Invoke
*> invocations
;
227 std::vector
<Dependency
*> dependencies
;
228 std::vector
<CompilerFlag
*> compilerFlags
;
229 std::vector
<LinkerFlag
*> linkerFlags
;
230 std::vector
<StubbedComponent
*> stubbedComponents
;
235 std::string installBase
;
236 std::string installName
;
237 std::string aliasedModuleName
;
242 Module ( const Project
& project
,
243 const XMLElement
& moduleNode
,
244 const std::string
& modulePath
);
246 ModuleType
GetModuleType ( const std::string
& location
,
247 const XMLAttribute
& attribute
);
248 bool HasImportLibrary () const;
250 bool GenerateInOutputTree () const;
251 std::string
GetTargetName () const; // "foo.exe"
252 std::string
GetDependencyPath () const; // "path/foo.exe" or "path/libfoo.a"
253 std::string
GetBasePath () const; // "path"
254 std::string
GetPath () const; // "path/foo.exe"
255 std::string
GetPathWithPrefix ( const std::string
& prefix
) const; // "path/prefixfoo.exe"
256 void GetTargets ( string_list
& ) const;
257 std::string
GetInvocationTarget ( const int index
) const;
258 bool HasFileWithExtension ( const IfableData
&, const std::string
& extension
) const;
259 void InvokeModule () const;
261 void GetSourceFilenames ( string_list
& list
,
262 bool includeGeneratedFiles
) const;
264 std::string
GetDefaultModuleExtension () const;
265 std::string
GetDefaultModuleEntrypoint () const;
266 std::string
GetDefaultModuleBaseaddress () const;
267 void ProcessXMLSubElement ( const XMLElement
& e
,
268 const std::string
& path
,
276 const Project
& project
;
277 const Module
* module
;
278 const XMLElement
* node
;
279 const Module
* baseModule
;
280 std::string directory
;
281 std::string basePath
;
283 Include ( const Project
& project
,
284 const XMLElement
* includeNode
);
285 Include ( const Project
& project
,
286 const Module
* module
,
287 const XMLElement
* includeNode
);
288 Include ( const Project
& project
,
289 std::string directory
,
290 std::string basePath
);
300 const Project
& project
;
301 const Module
* module
;
302 const XMLElement
& node
;
306 Define ( const Project
& project
,
307 const XMLElement
& defineNode
);
308 Define ( const Project
& project
,
309 const Module
* module
,
310 const XMLElement
& defineNode
);
323 std::string switches
;
324 bool isPreCompiledHeader
;
326 File ( const std::string
& _name
,
328 std::string _switches
,
329 bool _isPreCompiledHeader
);
332 bool IsGeneratedFile () const;
339 const XMLElement
& node
;
340 const Module
& module
;
342 const Module
* importedModule
;
344 Library ( const XMLElement
& _node
,
345 const Module
& _module
,
346 const std::string
& _name
);
355 const XMLElement
& node
;
356 const Module
& module
;
357 const Module
* invokeModule
;
358 std::vector
<InvokeFile
*> input
;
359 std::vector
<InvokeFile
*> output
;
361 Invoke ( const XMLElement
& _node
,
362 const Module
& _module
);
365 void GetTargets ( string_list
& targets
) const;
366 std::string
GetParameters () const;
368 void ProcessXMLSubElement ( const XMLElement
& e
);
369 void ProcessXMLSubElementInput ( const XMLElement
& e
);
370 void ProcessXMLSubElementOutput ( const XMLElement
& e
);
377 const XMLElement
& node
;
379 std::string switches
;
381 InvokeFile ( const XMLElement
& _node
,
382 const std::string
& _name
);
391 const XMLElement
& node
;
392 const Module
& module
;
393 const Module
* dependencyModule
;
395 Dependency ( const XMLElement
& _node
,
396 const Module
& _module
);
405 const XMLElement
& node
;
406 const Module
& module
;
407 std::string basename
;
408 std::string definition
;
410 ImportLibrary ( const XMLElement
& _node
,
411 const Module
& module
);
420 const XMLElement
& node
;
421 const Project
& project
;
422 const Module
* module
;
424 std::string property
, value
;
427 If ( const XMLElement
& node_
,
428 const Project
& project_
,
429 const Module
* module_
,
430 const bool negated_
= false );
440 const Project
& project
;
441 const Module
* module
;
442 const XMLElement
& node
;
445 CompilerFlag ( const Project
& project
,
446 const XMLElement
& compilerFlagNode
);
447 CompilerFlag ( const Project
& project
,
448 const Module
* module
,
449 const XMLElement
& compilerFlagNode
);
460 const Project
& project
;
461 const Module
* module
;
462 const XMLElement
& node
;
465 LinkerFlag ( const Project
& project
,
466 const XMLElement
& linkerFlagNode
);
467 LinkerFlag ( const Project
& project
,
468 const Module
* module
,
469 const XMLElement
& linkerFlagNode
);
480 const XMLElement
& node
;
481 const Project
& project
;
482 const Module
* module
;
483 std::string name
, value
;
485 Property ( const XMLElement
& node_
,
486 const Project
& project_
,
487 const Module
* module_
);
493 class TestSupportCode
496 const Project
& project
;
498 TestSupportCode ( const Project
& project
);
500 void GenerateTestSupportCode ( bool verbose
);
502 bool IsTestModule ( const Module
& module
);
503 void GenerateTestSupportCodeForModule ( Module
& module
,
505 std::string
GetHooksFilename ( Module
& module
);
506 char* WriteStubbedSymbolToHooksFile ( char* buffer
,
507 const StubbedComponent
& component
,
508 const StubbedSymbol
& symbol
);
509 char* WriteStubbedComponentToHooksFile ( char* buffer
,
510 const StubbedComponent
& component
);
511 void WriteHooksFile ( Module
& module
);
512 std::string
GetStubsFilename ( Module
& module
);
513 char* WriteStubbedSymbolToStubsFile ( char* buffer
,
514 const StubbedComponent
& component
,
515 const StubbedSymbol
& symbol
,
517 char* WriteStubbedComponentToStubsFile ( char* buffer
,
518 const StubbedComponent
& component
,
520 void WriteStubsFile ( Module
& module
);
521 std::string
GetStartupFilename ( Module
& module
);
522 bool IsUnknownCharacter ( char ch
);
523 std::string
GetTestDispatcherName ( std::string filename
);
524 bool IsTestFile ( std::string
& filename
) const;
525 void GetSourceFilenames ( string_list
& list
,
526 Module
& module
) const;
527 char* WriteTestDispatcherPrototypesToStartupFile ( char* buffer
,
529 char* WriteRegisterTestsFunctionToStartupFile ( char* buffer
,
531 void WriteStartupFile ( Module
& module
);
538 const Project
& project
;
541 WineResource ( const Project
& project
,
542 std::string bin2res
);
544 void UnpackResources ( bool verbose
);
546 bool IsSpecFile ( const File
& file
);
547 bool IsWineModule ( const Module
& module
);
548 bool IsResourceFile ( const File
& file
);
549 std::string
GetResourceFilename ( const Module
& module
);
550 void UnpackResourcesInModule ( Module
& module
,
558 SourceFile ( AutomaticDependency
* automaticDependency
,
559 const Module
& module
,
560 const std::string
& filename
,
562 bool isNonAutomaticDependency
);
563 SourceFile
* ParseFile ( const std::string
& normalizedFilename
);
565 std::string
Location () const;
566 std::vector
<SourceFile
*> files
;
567 AutomaticDependency
* automaticDependency
;
568 const Module
& module
;
569 std::string filename
;
570 std::string filenamePart
;
571 std::string directoryPart
;
572 std::vector
<SourceFile
*> parents
; /* List of files, this file is included from */
573 bool isNonAutomaticDependency
;
574 std::string cachedDependencies
;
575 time_t lastWriteTime
;
576 time_t youngestLastWriteTime
; /* Youngest last write time of this file and all children */
577 SourceFile
* youngestFile
;
579 void GetDirectoryAndFilenameParts ();
582 void SkipWhitespace ();
583 bool ReadInclude ( std::string
& filename
,
584 bool& searchCurrentDirectory
,
586 bool IsIncludedFrom ( const std::string
& normalizedFilename
);
587 SourceFile
* GetParentSourceFile ();
588 bool CanProcessFile ( const std::string
& extension
);
589 bool IsParentOf ( const SourceFile
* parent
,
590 const SourceFile
* child
);
597 class AutomaticDependency
599 friend class SourceFileTest
;
601 const Project
& project
;
603 AutomaticDependency ( const Project
& project
);
604 ~AutomaticDependency ();
605 std::string
GetFilename ( const std::string
& filename
);
606 bool LocateIncludedFile ( const std::string
& directory
,
607 const std::string
& includedFilename
,
608 std::string
& resolvedFilename
);
609 bool LocateIncludedFile ( SourceFile
* sourceFile
,
610 const Module
& module
,
611 const std::string
& includedFilename
,
612 bool searchCurrentDirectory
,
614 std::string
& resolvedFilename
);
615 SourceFile
* RetrieveFromCacheOrParse ( const Module
& module
,
616 const std::string
& filename
,
617 SourceFile
* parentSourceFile
);
618 SourceFile
* RetrieveFromCache ( const std::string
& filename
);
619 void CheckAutomaticDependencies ( bool verbose
);
620 void CheckAutomaticDependenciesForModule ( Module
& module
,
623 void GetModulesToCheck ( Module
& module
, std::vector
<const Module
*>& modules
);
624 void CheckAutomaticDependencies ( const Module
& module
,
626 void CheckAutomaticDependenciesForFile ( SourceFile
* sourceFile
);
627 void GetIncludeDirectories ( std::vector
<Include
*>& includes
,
628 const Module
& module
,
629 Include
& currentDirectory
,
630 bool searchCurrentDirectory
);
631 void GetModuleFiles ( const Module
& module
,
632 std::vector
<File
*>& files
) const;
634 void ParseFiles ( const Module
& module
);
635 void ParseFile ( const Module
& module
,
637 std::map
<std::string
, SourceFile
*> sourcefile_map
;
644 const Project
& project
;
645 const Module
* module
;
646 const XMLElement
& node
;
648 std::string nameoncd
;
650 Bootstrap ( const Project
& project
,
651 const Module
* module
,
652 const XMLElement
& bootstrapNode
);
656 bool IsSupportedModuleType ( ModuleType type
);
664 const Project
& project
;
665 const XMLElement
& node
;
668 std::string nameoncd
;
671 CDFile ( const Project
& project
,
672 const XMLElement
& bootstrapNode
,
673 const std::string
& path
);
676 std::string
GetPath () const;
683 const Project
& project
;
684 const XMLElement
& node
;
690 InstallFile ( const Project
& project
,
691 const XMLElement
& bootstrapNode
,
692 const std::string
& path
);
695 std::string
GetPath () const;
702 const XMLElement
& node
;
703 const Module
& module
;
707 const XMLElement
& node
,
708 const Module
& module
,
714 class StubbedComponent
717 const Module
* module
;
718 const XMLElement
& node
;
720 std::vector
<StubbedSymbol
*> symbols
;
722 StubbedComponent ( const Module
* module_
,
723 const XMLElement
& stubbedComponentNode
);
724 ~StubbedComponent ();
726 void ProcessXMLSubElement ( const XMLElement
& e
);
733 const XMLElement
& node
;
736 std::string strippedName
;
738 StubbedSymbol ( const XMLElement
& stubbedSymbolNode
);
742 std::string
StripSymbol ( std::string symbol
);
746 Right ( const std::string
& s
, size_t n
);
749 Replace ( const std::string
& s
, const std::string
& find
, const std::string
& with
);
752 FixSeparator ( const std::string
& s
);
755 DosSeparator ( const std::string
& s
);
759 const std::string
& filename
,
760 const std::string
& newExtension
);
764 const std::string
& location
,
765 const std::string
& path
,
766 const std::string
& att_value
);
769 GetExtension ( const std::string
& filename
);
772 GetDirectory ( const std::string
& filename
);
775 GetFilename ( const std::string
& filename
);
778 NormalizeFilename ( const std::string
& filename
);
780 #endif /* __RBUILD_H */