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
;
218 std::string extension
;
219 std::string entrypoint
;
220 std::string baseaddress
;
223 ImportLibrary
* importLibrary
;
225 Bootstrap
* bootstrap
;
226 IfableData non_if_data
;
227 std::vector
<Invoke
*> invocations
;
228 std::vector
<Dependency
*> dependencies
;
229 std::vector
<CompilerFlag
*> compilerFlags
;
230 std::vector
<LinkerFlag
*> linkerFlags
;
231 std::vector
<StubbedComponent
*> stubbedComponents
;
236 std::string installBase
;
237 std::string installName
;
238 std::string aliasedModuleName
;
243 Module ( const Project
& project
,
244 const XMLElement
& moduleNode
,
245 const std::string
& modulePath
);
247 ModuleType
GetModuleType ( const std::string
& location
,
248 const XMLAttribute
& attribute
);
249 bool HasImportLibrary () const;
251 bool GenerateInOutputTree () const;
252 std::string
GetTargetName () const; // "foo.exe"
253 std::string
GetDependencyPath () const; // "path/foo.exe" or "path/libfoo.a"
254 std::string
GetBasePath () const; // "path"
255 std::string
GetPath () const; // "path/foo.exe"
256 std::string
GetPathWithPrefix ( const std::string
& prefix
) const; // "path/prefixfoo.exe"
257 void GetTargets ( string_list
& ) const;
258 std::string
GetInvocationTarget ( const int index
) const;
259 bool HasFileWithExtension ( const IfableData
&, const std::string
& extension
) const;
260 void InvokeModule () const;
262 void GetSourceFilenames ( string_list
& list
,
263 bool includeGeneratedFiles
) const;
265 std::string
GetDefaultModuleExtension () const;
266 std::string
GetDefaultModuleEntrypoint () const;
267 std::string
GetDefaultModuleBaseaddress () const;
268 void ProcessXMLSubElement ( const XMLElement
& e
,
269 const std::string
& path
,
277 const Project
& project
;
278 const Module
* module
;
279 const XMLElement
* node
;
280 const Module
* baseModule
;
281 std::string directory
;
282 std::string basePath
;
284 Include ( const Project
& project
,
285 const XMLElement
* includeNode
);
286 Include ( const Project
& project
,
287 const Module
* module
,
288 const XMLElement
* includeNode
);
289 Include ( const Project
& project
,
290 std::string directory
,
291 std::string basePath
);
301 const Project
& project
;
302 const Module
* module
;
303 const XMLElement
& node
;
307 Define ( const Project
& project
,
308 const XMLElement
& defineNode
);
309 Define ( const Project
& project
,
310 const Module
* module
,
311 const XMLElement
& defineNode
);
324 std::string switches
;
325 bool isPreCompiledHeader
;
327 File ( const std::string
& _name
,
329 std::string _switches
,
330 bool _isPreCompiledHeader
);
333 bool IsGeneratedFile () const;
340 const XMLElement
& node
;
341 const Module
& module
;
343 const Module
* importedModule
;
345 Library ( const XMLElement
& _node
,
346 const Module
& _module
,
347 const std::string
& _name
);
356 const XMLElement
& node
;
357 const Module
& module
;
358 const Module
* invokeModule
;
359 std::vector
<InvokeFile
*> input
;
360 std::vector
<InvokeFile
*> output
;
362 Invoke ( const XMLElement
& _node
,
363 const Module
& _module
);
366 void GetTargets ( string_list
& targets
) const;
367 std::string
GetParameters () const;
369 void ProcessXMLSubElement ( const XMLElement
& e
);
370 void ProcessXMLSubElementInput ( const XMLElement
& e
);
371 void ProcessXMLSubElementOutput ( const XMLElement
& e
);
378 const XMLElement
& node
;
380 std::string switches
;
382 InvokeFile ( const XMLElement
& _node
,
383 const std::string
& _name
);
392 const XMLElement
& node
;
393 const Module
& module
;
394 const Module
* dependencyModule
;
396 Dependency ( const XMLElement
& _node
,
397 const Module
& _module
);
406 const XMLElement
& node
;
407 const Module
& module
;
408 std::string basename
;
409 std::string definition
;
411 ImportLibrary ( const XMLElement
& _node
,
412 const Module
& module
);
421 const XMLElement
& node
;
422 const Project
& project
;
423 const Module
* module
;
425 std::string property
, value
;
428 If ( const XMLElement
& node_
,
429 const Project
& project_
,
430 const Module
* module_
,
431 const bool negated_
= false );
441 const Project
& project
;
442 const Module
* module
;
443 const XMLElement
& node
;
446 CompilerFlag ( const Project
& project
,
447 const XMLElement
& compilerFlagNode
);
448 CompilerFlag ( const Project
& project
,
449 const Module
* module
,
450 const XMLElement
& compilerFlagNode
);
461 const Project
& project
;
462 const Module
* module
;
463 const XMLElement
& node
;
466 LinkerFlag ( const Project
& project
,
467 const XMLElement
& linkerFlagNode
);
468 LinkerFlag ( const Project
& project
,
469 const Module
* module
,
470 const XMLElement
& linkerFlagNode
);
481 const XMLElement
& node
;
482 const Project
& project
;
483 const Module
* module
;
484 std::string name
, value
;
486 Property ( const XMLElement
& node_
,
487 const Project
& project_
,
488 const Module
* module_
);
494 class TestSupportCode
497 const Project
& project
;
499 TestSupportCode ( const Project
& project
);
501 void GenerateTestSupportCode ( bool verbose
);
503 bool IsTestModule ( const Module
& module
);
504 void GenerateTestSupportCodeForModule ( Module
& module
,
506 std::string
GetHooksFilename ( Module
& module
);
507 char* WriteStubbedSymbolToHooksFile ( char* buffer
,
508 const StubbedComponent
& component
,
509 const StubbedSymbol
& symbol
);
510 char* WriteStubbedComponentToHooksFile ( char* buffer
,
511 const StubbedComponent
& component
);
512 void WriteHooksFile ( Module
& module
);
513 std::string
GetStubsFilename ( Module
& module
);
514 char* WriteStubbedSymbolToStubsFile ( char* buffer
,
515 const StubbedComponent
& component
,
516 const StubbedSymbol
& symbol
,
518 char* WriteStubbedComponentToStubsFile ( char* buffer
,
519 const StubbedComponent
& component
,
521 void WriteStubsFile ( Module
& module
);
522 std::string
GetStartupFilename ( Module
& module
);
523 bool IsUnknownCharacter ( char ch
);
524 std::string
GetTestDispatcherName ( std::string filename
);
525 bool IsTestFile ( std::string
& filename
) const;
526 void GetSourceFilenames ( string_list
& list
,
527 Module
& module
) const;
528 char* WriteTestDispatcherPrototypesToStartupFile ( char* buffer
,
530 char* WriteRegisterTestsFunctionToStartupFile ( char* buffer
,
532 void WriteStartupFile ( Module
& module
);
539 const Project
& project
;
542 WineResource ( const Project
& project
,
543 std::string bin2res
);
545 void UnpackResources ( bool verbose
);
547 bool IsSpecFile ( const File
& file
);
548 bool IsWineModule ( const Module
& module
);
549 bool IsResourceFile ( const File
& file
);
550 std::string
GetResourceFilename ( const Module
& module
);
551 void UnpackResourcesInModule ( Module
& module
,
559 SourceFile ( AutomaticDependency
* automaticDependency
,
560 const Module
& module
,
561 const std::string
& filename
,
563 bool isNonAutomaticDependency
);
564 SourceFile
* ParseFile ( const std::string
& normalizedFilename
);
566 std::string
Location () const;
567 std::vector
<SourceFile
*> files
;
568 AutomaticDependency
* automaticDependency
;
569 const Module
& module
;
570 std::string filename
;
571 std::string filenamePart
;
572 std::string directoryPart
;
573 std::vector
<SourceFile
*> parents
; /* List of files, this file is included from */
574 bool isNonAutomaticDependency
;
575 std::string cachedDependencies
;
576 time_t lastWriteTime
;
577 time_t youngestLastWriteTime
; /* Youngest last write time of this file and all children */
578 SourceFile
* youngestFile
;
580 void GetDirectoryAndFilenameParts ();
583 void SkipWhitespace ();
584 bool ReadInclude ( std::string
& filename
,
585 bool& searchCurrentDirectory
,
587 bool IsIncludedFrom ( const std::string
& normalizedFilename
);
588 SourceFile
* GetParentSourceFile ();
589 bool CanProcessFile ( const std::string
& extension
);
590 bool IsParentOf ( const SourceFile
* parent
,
591 const SourceFile
* child
);
598 class AutomaticDependency
600 friend class SourceFileTest
;
602 const Project
& project
;
604 AutomaticDependency ( const Project
& project
);
605 ~AutomaticDependency ();
606 std::string
GetFilename ( const std::string
& filename
);
607 bool LocateIncludedFile ( const std::string
& directory
,
608 const std::string
& includedFilename
,
609 std::string
& resolvedFilename
);
610 bool LocateIncludedFile ( SourceFile
* sourceFile
,
611 const Module
& module
,
612 const std::string
& includedFilename
,
613 bool searchCurrentDirectory
,
615 std::string
& resolvedFilename
);
616 SourceFile
* RetrieveFromCacheOrParse ( const Module
& module
,
617 const std::string
& filename
,
618 SourceFile
* parentSourceFile
);
619 SourceFile
* RetrieveFromCache ( const std::string
& filename
);
620 void CheckAutomaticDependencies ( bool verbose
);
621 void CheckAutomaticDependenciesForModule ( Module
& module
,
624 void GetModulesToCheck ( Module
& module
, std::vector
<const Module
*>& modules
);
625 void CheckAutomaticDependencies ( const Module
& module
,
627 void CheckAutomaticDependenciesForFile ( SourceFile
* sourceFile
);
628 void GetIncludeDirectories ( std::vector
<Include
*>& includes
,
629 const Module
& module
,
630 Include
& currentDirectory
,
631 bool searchCurrentDirectory
);
632 void GetModuleFiles ( const Module
& module
,
633 std::vector
<File
*>& files
) const;
635 void ParseFiles ( const Module
& module
);
636 void ParseFile ( const Module
& module
,
638 std::map
<std::string
, SourceFile
*> sourcefile_map
;
645 const Project
& project
;
646 const Module
* module
;
647 const XMLElement
& node
;
649 std::string nameoncd
;
651 Bootstrap ( const Project
& project
,
652 const Module
* module
,
653 const XMLElement
& bootstrapNode
);
657 bool IsSupportedModuleType ( ModuleType type
);
665 const Project
& project
;
666 const XMLElement
& node
;
669 std::string nameoncd
;
672 CDFile ( const Project
& project
,
673 const XMLElement
& bootstrapNode
,
674 const std::string
& path
);
677 std::string
GetPath () const;
684 const Project
& project
;
685 const XMLElement
& node
;
691 InstallFile ( const Project
& project
,
692 const XMLElement
& bootstrapNode
,
693 const std::string
& path
);
696 std::string
GetPath () const;
703 const XMLElement
& node
;
704 const Module
& module
;
708 const XMLElement
& node
,
709 const Module
& module
,
715 class StubbedComponent
718 const Module
* module
;
719 const XMLElement
& node
;
721 std::vector
<StubbedSymbol
*> symbols
;
723 StubbedComponent ( const Module
* module_
,
724 const XMLElement
& stubbedComponentNode
);
725 ~StubbedComponent ();
727 void ProcessXMLSubElement ( const XMLElement
& e
);
734 const XMLElement
& node
;
737 std::string strippedName
;
739 StubbedSymbol ( const XMLElement
& stubbedSymbolNode
);
743 std::string
StripSymbol ( std::string symbol
);
747 Right ( const std::string
& s
, size_t n
);
750 Replace ( const std::string
& s
, const std::string
& find
, const std::string
& with
);
753 FixSeparator ( const std::string
& s
);
756 DosSeparator ( const std::string
& s
);
760 const std::string
& filename
,
761 const std::string
& newExtension
);
765 const std::string
& location
,
766 const std::string
& path
,
767 const std::string
& att_value
);
770 GetExtension ( const std::string
& filename
);
773 GetDirectory ( const std::string
& filename
);
776 GetFilename ( const std::string
& filename
);
779 NormalizeFilename ( const std::string
& filename
);
781 #endif /* __RBUILD_H */