\r
#include "pch.h"\r
\r
+#ifdef WIN32\r
+#include <direct.h>\r
+#include <io.h>\r
+#endif\r
+#include <sys/stat.h>\r
+#include <time.h>\r
+#ifdef _MSC_VER\r
+#include <sys/utime.h>\r
+#else\r
+#include <utime.h>\r
+#include <process.h>\r
+#endif\r
+\r
#include "ssprintf.h"\r
#include "exception.h"\r
#include "XML.h"\r
\r
+#ifdef WIN32\r
+#define EXEPREFIX ""\r
+#define EXEPOSTFIX ".exe"\r
+#define CSEP '\\'\r
+#define CBAD_SEP '/'\r
+#define SSEP "\\"\r
+#define SBAD_SEP "/"\r
+#else\r
+#define EXEPREFIX "./"\r
+#define EXEPOSTFIX ""\r
+#define CSEP '/'\r
+#define CBAD_SEP '\\'\r
+#define SSEP "/"\r
+#define SBAD_SEP "\\"\r
+#endif\r
+\r
class Project;\r
class Module;\r
+class Include;\r
+class Define;\r
class File;\r
+class Library;\r
+class Invoke;\r
+class InvokeFile;\r
+class Dependency;\r
+class ImportLibrary;\r
+class If;\r
+class CompilerFlag;\r
+class LinkerFlag;\r
+class Property;\r
+class AutomaticDependency;\r
+\r
+class SourceFileTest;\r
\r
class Project\r
{\r
+ std::string xmlfile;\r
+ XMLElement *node, *head;\r
public:\r
std::string name;\r
+ std::string makefile;\r
std::vector<Module*> modules;\r
+ std::vector<Include*> includes;\r
+ std::vector<Define*> defines;\r
+ std::vector<LinkerFlag*> linkerFlags;\r
+ std::vector<Property*> properties;\r
+ std::vector<If*> ifs;\r
\r
- Project ();\r
Project ( const std::string& filename );\r
~Project ();\r
- void ProcessXML ( const XMLElement& e, const std::string& path );\r
- bool GenerateOutput();\r
+ void WriteConfigurationFile ();\r
+ void ExecuteInvocations ();\r
+ void ProcessXML ( const std::string& path );\r
+ Module* LocateModule ( const std::string& name );\r
+ const Module* LocateModule ( const std::string& name ) const;\r
private:\r
+ const Property* LookupProperty ( const std::string& name ) const;\r
+ void SetConfigurationOption ( char* s,\r
+ std::string name,\r
+ std::string* alternativeName );\r
+ void SetConfigurationOption ( char* s,\r
+ std::string name );\r
+ void WriteIfChanged ( char* outbuf,\r
+ std::string filename );\r
void ReadXml ();\r
- XMLFile xmlfile;\r
- XMLElement* head;\r
+ void ProcessXMLSubElement ( const XMLElement& e,\r
+ const std::string& path,\r
+ If* pIf = NULL );\r
+\r
+ // disable copy semantics\r
+ Project ( const Project& );\r
+ Project& operator = ( const Project& );\r
+};\r
+\r
+\r
+enum ModuleType\r
+{\r
+ BuildTool,\r
+ StaticLibrary,\r
+ ObjectLibrary,\r
+ Kernel,\r
+ KernelModeDLL,\r
+ KernelModeDriver,\r
+ NativeDLL,\r
+ NativeCUI,\r
+ Win32DLL,\r
+ Win32CUI,\r
+ Win32GUI,\r
+ BootLoader,\r
+ BootSector,\r
+ Iso\r
};\r
\r
+\r
class Module\r
{\r
public:\r
+ const Project& project;\r
const XMLElement& node;\r
std::string name;\r
+ std::string extension;\r
+ std::string entrypoint;\r
+ std::string baseaddress;\r
std::string path;\r
+ ModuleType type;\r
+ ImportLibrary* importLibrary;\r
+ bool mangledSymbols;\r
std::vector<File*> files;\r
+ std::vector<Library*> libraries;\r
+ std::vector<Include*> includes;\r
+ std::vector<Define*> defines;\r
+ std::vector<Invoke*> invocations;\r
+ std::vector<Dependency*> dependencies;\r
+ std::vector<If*> ifs;\r
+ std::vector<CompilerFlag*> compilerFlags;\r
+ std::vector<LinkerFlag*> linkerFlags;\r
\r
- Module ( const XMLElement& moduleNode,\r
- const std::string& moduleName,\r
+ Module ( const Project& project,\r
+ const XMLElement& moduleNode,\r
const std::string& modulePath );\r
+ ~Module ();\r
+ ModuleType GetModuleType ( const std::string& location,\r
+ const XMLAttribute& attribute );\r
+ bool HasImportLibrary () const;\r
+ std::string GetTargetName () const;\r
+ std::string GetDependencyPath () const;\r
+ std::string GetBasePath () const;\r
+ std::string GetPath () const;\r
+ std::string GetPathWithPrefix ( const std::string& prefix ) const;\r
+ std::string GetTargets () const;\r
+ std::string GetInvocationTarget ( const int index ) const;\r
+ bool HasFileWithExtensions ( const std::string& extension1,\r
+ const std::string& extension2 ) const;\r
+ void InvokeModule () const;\r
+ void ProcessXML ();\r
+private:\r
+ std::string GetDefaultModuleExtension () const;\r
+ std::string GetDefaultModuleEntrypoint () const;\r
+ std::string GetDefaultModuleBaseaddress () const;\r
+ void ProcessXMLSubElement ( const XMLElement& e,\r
+ const std::string& path,\r
+ If* pIf = NULL );\r
+};\r
+\r
\r
- ~Module();\r
+class Include\r
+{\r
+public:\r
+ const Project& project;\r
+ const Module* module;\r
+ const XMLElement& node;\r
+ std::string directory;\r
+ std::string basePath;\r
\r
- void ProcessXML ( const XMLElement& e, const std::string& path );\r
+ Include ( const Project& project,\r
+ const XMLElement& includeNode );\r
+ Include ( const Project& project,\r
+ const Module* module,\r
+ const XMLElement& includeNode );\r
+ ~Include ();\r
+ void ProcessXML();\r
+private:\r
+ void Initialize();\r
};\r
\r
+\r
+class Define\r
+{\r
+public:\r
+ const Project& project;\r
+ const Module* module;\r
+ const XMLElement& node;\r
+ std::string name;\r
+ std::string value;\r
+\r
+ Define ( const Project& project,\r
+ const XMLElement& defineNode );\r
+ Define ( const Project& project,\r
+ const Module* module,\r
+ const XMLElement& defineNode );\r
+ ~Define();\r
+ void ProcessXML();\r
+private:\r
+ void Initialize();\r
+};\r
+\r
+\r
class File\r
{\r
public:\r
std::string name;\r
+ bool first;\r
\r
- File ( const std::string& _name );\r
+ File ( const std::string& _name, bool _first );\r
+\r
+ void ProcessXML();\r
};\r
\r
+\r
+class Library\r
+{\r
+public:\r
+ const XMLElement& node;\r
+ const Module& module;\r
+ std::string name;\r
+\r
+ Library ( const XMLElement& _node,\r
+ const Module& _module,\r
+ const std::string& _name );\r
+\r
+ void ProcessXML();\r
+};\r
+\r
+\r
+class Invoke\r
+{\r
+public:\r
+ const XMLElement& node;\r
+ const Module& module;\r
+ const Module* invokeModule;\r
+ std::vector<InvokeFile*> input;\r
+ std::vector<InvokeFile*> output;\r
+\r
+ Invoke ( const XMLElement& _node,\r
+ const Module& _module );\r
+\r
+ void ProcessXML();\r
+ std::string GetTargets () const;\r
+ std::string GetParameters () const;\r
+private:\r
+ void ProcessXMLSubElement ( const XMLElement& e );\r
+ void ProcessXMLSubElementInput ( const XMLElement& e );\r
+ void ProcessXMLSubElementOutput ( const XMLElement& e );\r
+};\r
+\r
+\r
+class InvokeFile\r
+{\r
+public:\r
+ const XMLElement& node;\r
+ std::string name;\r
+ std::string switches;\r
+\r
+ InvokeFile ( const XMLElement& _node,\r
+ const std::string& _name );\r
+\r
+ void ProcessXML ();\r
+};\r
+\r
+\r
+class Dependency\r
+{\r
+public:\r
+ const XMLElement& node;\r
+ const Module& module;\r
+ const Module* dependencyModule;\r
+\r
+ Dependency ( const XMLElement& _node,\r
+ const Module& _module );\r
+\r
+ void ProcessXML();\r
+};\r
+\r
+\r
+class ImportLibrary\r
+{\r
+public:\r
+ const XMLElement& node;\r
+ const Module& module;\r
+ std::string basename;\r
+ std::string definition;\r
+\r
+ ImportLibrary ( const XMLElement& _node,\r
+ const Module& module );\r
+\r
+ void ProcessXML ();\r
+};\r
+\r
+\r
+class If\r
+{\r
+public:\r
+ const XMLElement& node;\r
+ const Project& project;\r
+ const Module* module;\r
+ std::string property, value;\r
+ std::vector<File*> files;\r
+ std::vector<Include*> includes;\r
+ std::vector<Define*> defines;\r
+ std::vector<Property*> properties;\r
+ std::vector<If*> ifs;\r
+\r
+ If ( const XMLElement& node_,\r
+ const Project& project_,\r
+ const Module* module_ );\r
+ ~If();\r
+\r
+ void ProcessXML();\r
+};\r
+\r
+\r
+class CompilerFlag\r
+{\r
+public:\r
+ const Project& project;\r
+ const Module* module;\r
+ const XMLElement& node;\r
+ std::string flag;\r
+\r
+ CompilerFlag ( const Project& project,\r
+ const XMLElement& compilerFlagNode );\r
+ CompilerFlag ( const Project& project,\r
+ const Module* module,\r
+ const XMLElement& compilerFlagNode );\r
+ ~CompilerFlag ();\r
+ void ProcessXML();\r
+private:\r
+ void Initialize();\r
+};\r
+\r
+\r
+class LinkerFlag\r
+{\r
+public:\r
+ const Project& project;\r
+ const Module* module;\r
+ const XMLElement& node;\r
+ std::string flag;\r
+\r
+ LinkerFlag ( const Project& project,\r
+ const XMLElement& linkerFlagNode );\r
+ LinkerFlag ( const Project& project,\r
+ const Module* module,\r
+ const XMLElement& linkerFlagNode );\r
+ ~LinkerFlag ();\r
+ void ProcessXML();\r
+private:\r
+ void Initialize();\r
+};\r
+\r
+\r
+class Property\r
+{\r
+public:\r
+ const XMLElement& node;\r
+ const Project& project;\r
+ const Module* module;\r
+ std::string name, value;\r
+\r
+ Property ( const XMLElement& node_,\r
+ const Project& project_,\r
+ const Module* module_ );\r
+\r
+ void ProcessXML();\r
+};\r
+\r
+\r
+class SourceFile\r
+{\r
+public:\r
+ SourceFile ( AutomaticDependency* automaticDependency,\r
+ Module& module,\r
+ const std::string& filename,\r
+ SourceFile* parent,\r
+ bool isNonAutomaticDependency );\r
+ SourceFile* ParseFile ( const std::string& normalizedFilename );\r
+ void Parse ();\r
+ std::string Location () const;\r
+ std::vector<SourceFile*> files;\r
+ AutomaticDependency* automaticDependency;\r
+ Module& module;\r
+ std::string filename;\r
+ std::string filenamePart;\r
+ std::string directoryPart;\r
+ std::vector<SourceFile*> parents; /* List of files, this file is included from */\r
+ bool isNonAutomaticDependency;\r
+ std::string cachedDependencies;\r
+ time_t lastWriteTime;\r
+ time_t youngestLastWriteTime; /* Youngest last write time of this file and all children */\r
+ SourceFile* youngestFile;\r
+private:\r
+ void GetDirectoryAndFilenameParts ();\r
+ void Close ();\r
+ void Open ();\r
+ void SkipWhitespace ();\r
+ bool ReadInclude ( std::string& filename,\r
+ bool& includeNext );\r
+ bool IsIncludedFrom ( const std::string& normalizedFilename );\r
+ SourceFile* GetParentSourceFile ();\r
+ bool CanProcessFile ( const std::string& extension );\r
+ bool IsParentOf ( const SourceFile* parent,\r
+ const SourceFile* child );\r
+ std::string buf;\r
+ const char *p;\r
+ const char *end;\r
+};\r
+\r
+\r
+class AutomaticDependency\r
+{\r
+ friend class SourceFileTest;\r
+public:\r
+ const Project& project;\r
+\r
+ AutomaticDependency ( const Project& project );\r
+ ~AutomaticDependency ();\r
+ void Process ();\r
+ std::string GetFilename ( const std::string& filename );\r
+ bool LocateIncludedFile ( const std::string& directory,\r
+ const std::string& includedFilename,\r
+ std::string& resolvedFilename );\r
+ bool LocateIncludedFile ( SourceFile* sourceFile,\r
+ Module& module,\r
+ const std::string& includedFilename,\r
+ bool includeNext,\r
+ std::string& resolvedFilename );\r
+ SourceFile* RetrieveFromCacheOrParse ( Module& module,\r
+ const std::string& filename,\r
+ SourceFile* parentSourceFile );\r
+ SourceFile* RetrieveFromCache ( const std::string& filename );\r
+ void CheckAutomaticDependencies ();\r
+ void CheckAutomaticDependenciesForFile ( SourceFile* sourceFile );\r
+private:\r
+ void ProcessModule ( Module& module );\r
+ void ProcessFile ( Module& module,\r
+ const File& file );\r
+ std::map<std::string, SourceFile*> sourcefile_map;\r
+};\r
+\r
+\r
+extern std::string\r
+FixSeparator ( const std::string& s );\r
+\r
+extern std::string\r
+GetExtension ( const std::string& filename );\r
+\r
+extern std::string\r
+GetDirectory ( const std::string& filename );\r
+\r
+extern std::string\r
+NormalizeFilename ( const std::string& filename );\r
+\r
#endif /* __RBUILD_H */\r