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
;
226 Bootstrap
* bootstrap
;
227 IfableData non_if_data
;
228 std::vector
<Invoke
*> invocations
;
229 std::vector
<Dependency
*> dependencies
;
230 std::vector
<CompilerFlag
*> compilerFlags
;
231 std::vector
<LinkerFlag
*> linkerFlags
;
232 std::vector
<StubbedComponent
*> stubbedComponents
;
237 std::string installBase
;
238 std::string installName
;
239 std::string aliasedModuleName
;
244 Module ( const Project
& project
,
245 const XMLElement
& moduleNode
,
246 const std::string
& modulePath
);
248 ModuleType
GetModuleType ( const std::string
& location
,
249 const XMLAttribute
& attribute
);
250 bool HasImportLibrary () const;
252 bool GenerateInOutputTree () const;
253 std::string
GetTargetName () const; // "foo.exe"
254 std::string
GetDependencyPath () const; // "path/foo.exe" or "path/libfoo.a"
255 std::string
GetBasePath () const; // "path"
256 std::string
GetPath () const; // "path/foo.exe"
257 std::string
GetPathWithPrefix ( const std::string
& prefix
) const; // "path/prefixfoo.exe"
258 void GetTargets ( string_list
& ) const;
259 std::string
GetInvocationTarget ( const int index
) const;
260 bool HasFileWithExtension ( const IfableData
&, const std::string
& extension
) const;
261 void InvokeModule () const;
263 void GetSourceFilenames ( string_list
& list
,
264 bool includeGeneratedFiles
) const;
266 std::string
GetDefaultModuleExtension () const;
267 std::string
GetDefaultModuleEntrypoint () const;
268 std::string
GetDefaultModuleBaseaddress () const;
269 void ProcessXMLSubElement ( const XMLElement
& e
,
270 const std::string
& path
,
278 const Project
& project
;
279 const Module
* module
;
280 const XMLElement
* node
;
281 const Module
* baseModule
;
282 std::string directory
;
283 std::string basePath
;
285 Include ( const Project
& project
,
286 const XMLElement
* includeNode
);
287 Include ( const Project
& project
,
288 const Module
* module
,
289 const XMLElement
* includeNode
);
290 Include ( const Project
& project
,
291 std::string directory
,
292 std::string basePath
);
302 const Project
& project
;
303 const Module
* module
;
304 const XMLElement
& node
;
308 Define ( const Project
& project
,
309 const XMLElement
& defineNode
);
310 Define ( const Project
& project
,
311 const Module
* module
,
312 const XMLElement
& defineNode
);
325 std::string switches
;
326 bool isPreCompiledHeader
;
328 File ( const std::string
& _name
,
330 std::string _switches
,
331 bool _isPreCompiledHeader
);
334 bool IsGeneratedFile () const;
341 const XMLElement
& node
;
342 const Module
& module
;
344 const Module
* importedModule
;
346 Library ( const XMLElement
& _node
,
347 const Module
& _module
,
348 const std::string
& _name
);
357 const XMLElement
& node
;
358 const Module
& module
;
359 const Module
* invokeModule
;
360 std::vector
<InvokeFile
*> input
;
361 std::vector
<InvokeFile
*> output
;
363 Invoke ( const XMLElement
& _node
,
364 const Module
& _module
);
367 void GetTargets ( string_list
& targets
) const;
368 std::string
GetParameters () const;
370 void ProcessXMLSubElement ( const XMLElement
& e
);
371 void ProcessXMLSubElementInput ( const XMLElement
& e
);
372 void ProcessXMLSubElementOutput ( const XMLElement
& e
);
379 const XMLElement
& node
;
381 std::string switches
;
383 InvokeFile ( const XMLElement
& _node
,
384 const std::string
& _name
);
393 const XMLElement
& node
;
394 const Module
& module
;
395 const Module
* dependencyModule
;
397 Dependency ( const XMLElement
& _node
,
398 const Module
& _module
);
407 const XMLElement
& node
;
408 const Module
& module
;
409 std::string basename
;
410 std::string definition
;
412 ImportLibrary ( const XMLElement
& _node
,
413 const Module
& module
);
422 const XMLElement
& node
;
423 const Project
& project
;
424 const Module
* module
;
426 std::string property
, value
;
429 If ( const XMLElement
& node_
,
430 const Project
& project_
,
431 const Module
* module_
,
432 const bool negated_
= false );
442 const Project
& project
;
443 const Module
* module
;
444 const XMLElement
& node
;
447 CompilerFlag ( const Project
& project
,
448 const XMLElement
& compilerFlagNode
);
449 CompilerFlag ( const Project
& project
,
450 const Module
* module
,
451 const XMLElement
& compilerFlagNode
);
462 const Project
& project
;
463 const Module
* module
;
464 const XMLElement
& node
;
467 LinkerFlag ( const Project
& project
,
468 const XMLElement
& linkerFlagNode
);
469 LinkerFlag ( const Project
& project
,
470 const Module
* module
,
471 const XMLElement
& linkerFlagNode
);
482 const XMLElement
& node
;
483 const Project
& project
;
484 const Module
* module
;
485 std::string name
, value
;
487 Property ( const XMLElement
& node_
,
488 const Project
& project_
,
489 const Module
* module_
);
495 class TestSupportCode
498 const Project
& project
;
500 TestSupportCode ( const Project
& project
);
502 void GenerateTestSupportCode ( bool verbose
);
504 bool IsTestModule ( const Module
& module
);
505 void GenerateTestSupportCodeForModule ( Module
& module
,
507 std::string
GetHooksFilename ( Module
& module
);
508 char* WriteStubbedSymbolToHooksFile ( char* buffer
,
509 const StubbedComponent
& component
,
510 const StubbedSymbol
& symbol
);
511 char* WriteStubbedComponentToHooksFile ( char* buffer
,
512 const StubbedComponent
& component
);
513 void WriteHooksFile ( Module
& module
);
514 std::string
GetStubsFilename ( Module
& module
);
515 char* WriteStubbedSymbolToStubsFile ( char* buffer
,
516 const StubbedComponent
& component
,
517 const StubbedSymbol
& symbol
,
519 char* WriteStubbedComponentToStubsFile ( char* buffer
,
520 const StubbedComponent
& component
,
522 void WriteStubsFile ( Module
& module
);
523 std::string
GetStartupFilename ( Module
& module
);
524 bool IsUnknownCharacter ( char ch
);
525 std::string
GetTestDispatcherName ( std::string filename
);
526 bool IsTestFile ( std::string
& filename
) const;
527 void GetSourceFilenames ( string_list
& list
,
528 Module
& module
) const;
529 char* WriteTestDispatcherPrototypesToStartupFile ( char* buffer
,
531 char* WriteRegisterTestsFunctionToStartupFile ( char* buffer
,
533 void WriteStartupFile ( Module
& module
);
540 const Project
& project
;
543 WineResource ( const Project
& project
,
544 std::string bin2res
);
546 void UnpackResources ( bool verbose
);
548 bool IsSpecFile ( const File
& file
);
549 bool IsWineModule ( const Module
& module
);
550 bool IsResourceFile ( const File
& file
);
551 std::string
GetResourceFilename ( const Module
& module
);
552 void UnpackResourcesInModule ( Module
& module
,
560 SourceFile ( AutomaticDependency
* automaticDependency
,
561 const Module
& module
,
562 const std::string
& filename
,
564 bool isNonAutomaticDependency
);
565 SourceFile
* ParseFile ( const std::string
& normalizedFilename
);
567 std::string
Location () const;
568 std::vector
<SourceFile
*> files
;
569 AutomaticDependency
* automaticDependency
;
570 const Module
& module
;
571 std::string filename
;
572 std::string filenamePart
;
573 std::string directoryPart
;
574 std::vector
<SourceFile
*> parents
; /* List of files, this file is included from */
575 bool isNonAutomaticDependency
;
576 std::string cachedDependencies
;
577 time_t lastWriteTime
;
578 time_t youngestLastWriteTime
; /* Youngest last write time of this file and all children */
579 SourceFile
* youngestFile
;
581 void GetDirectoryAndFilenameParts ();
584 void SkipWhitespace ();
585 bool ReadInclude ( std::string
& filename
,
586 bool& searchCurrentDirectory
,
588 bool IsIncludedFrom ( const std::string
& normalizedFilename
);
589 SourceFile
* GetParentSourceFile ();
590 bool CanProcessFile ( const std::string
& extension
);
591 bool IsParentOf ( const SourceFile
* parent
,
592 const SourceFile
* child
);
599 class AutomaticDependency
601 friend class SourceFileTest
;
603 const Project
& project
;
605 AutomaticDependency ( const Project
& project
);
606 ~AutomaticDependency ();
607 std::string
GetFilename ( const std::string
& filename
);
608 bool LocateIncludedFile ( const std::string
& directory
,
609 const std::string
& includedFilename
,
610 std::string
& resolvedFilename
);
611 bool LocateIncludedFile ( SourceFile
* sourceFile
,
612 const Module
& module
,
613 const std::string
& includedFilename
,
614 bool searchCurrentDirectory
,
616 std::string
& resolvedFilename
);
617 SourceFile
* RetrieveFromCacheOrParse ( const Module
& module
,
618 const std::string
& filename
,
619 SourceFile
* parentSourceFile
);
620 SourceFile
* RetrieveFromCache ( const std::string
& filename
);
621 void CheckAutomaticDependencies ( bool verbose
);
622 void CheckAutomaticDependenciesForModule ( Module
& module
,
625 void GetModulesToCheck ( Module
& module
, std::vector
<const Module
*>& modules
);
626 void CheckAutomaticDependencies ( const Module
& module
,
628 void CheckAutomaticDependenciesForFile ( SourceFile
* sourceFile
);
629 void GetIncludeDirectories ( std::vector
<Include
*>& includes
,
630 const Module
& module
,
631 Include
& currentDirectory
,
632 bool searchCurrentDirectory
);
633 void GetModuleFiles ( const Module
& module
,
634 std::vector
<File
*>& files
) const;
636 void ParseFiles ( const Module
& module
);
637 void ParseFile ( const Module
& module
,
639 std::map
<std::string
, SourceFile
*> sourcefile_map
;
646 const Project
& project
;
647 const Module
* module
;
648 const XMLElement
& node
;
650 std::string nameoncd
;
652 Bootstrap ( const Project
& project
,
653 const Module
* module
,
654 const XMLElement
& bootstrapNode
);
658 bool IsSupportedModuleType ( ModuleType type
);
666 const Project
& project
;
667 const XMLElement
& node
;
670 std::string nameoncd
;
673 CDFile ( const Project
& project
,
674 const XMLElement
& bootstrapNode
,
675 const std::string
& path
);
678 std::string
GetPath () const;
685 const Project
& project
;
686 const XMLElement
& node
;
692 InstallFile ( const Project
& project
,
693 const XMLElement
& bootstrapNode
,
694 const std::string
& path
);
697 std::string
GetPath () const;
704 const XMLElement
& node
;
705 const Module
& module
;
709 const XMLElement
& node
,
710 const Module
& module
,
716 class StubbedComponent
719 const Module
* module
;
720 const XMLElement
& node
;
722 std::vector
<StubbedSymbol
*> symbols
;
724 StubbedComponent ( const Module
* module_
,
725 const XMLElement
& stubbedComponentNode
);
726 ~StubbedComponent ();
728 void ProcessXMLSubElement ( const XMLElement
& e
);
735 const XMLElement
& node
;
738 std::string strippedName
;
740 StubbedSymbol ( const XMLElement
& stubbedSymbolNode
);
744 std::string
StripSymbol ( std::string symbol
);
748 Right ( const std::string
& s
, size_t n
);
751 Replace ( const std::string
& s
, const std::string
& find
, const std::string
& with
);
754 FixSeparator ( const std::string
& s
);
757 DosSeparator ( const std::string
& s
);
761 const std::string
& filename
,
762 const std::string
& newExtension
);
766 const std::string
& location
,
767 const std::string
& path
,
768 const std::string
& att_value
);
771 GetExtension ( const std::string
& filename
);
774 GetDirectory ( const std::string
& filename
);
777 GetFilename ( const std::string
& filename
);
780 NormalizeFilename ( const std::string
& filename
);
782 #endif /* __RBUILD_H */