From b9bffbca54d23bcf5a6c98f4d83a857e88326d42 Mon Sep 17 00:00:00 2001 From: Royce Mitchell III Date: Wed, 5 Jan 2005 19:02:00 +0000 Subject: [PATCH] beginnings of makefile output svn path=/branches/xmlbuildsystem/; revision=12826 --- reactos/tools/rbuild/project.cpp | 87 ++++++++++++++++++++++++++------ reactos/tools/rbuild/rbuild.cpp | 19 +++---- reactos/tools/rbuild/rbuild.h | 2 + 3 files changed, 83 insertions(+), 25 deletions(-) diff --git a/reactos/tools/rbuild/project.cpp b/reactos/tools/rbuild/project.cpp index dfa1a29908f..8cd9db207e1 100644 --- a/reactos/tools/rbuild/project.cpp +++ b/reactos/tools/rbuild/project.cpp @@ -6,6 +6,36 @@ using std::string; using std::vector; +#ifdef WIN32 +#define EXEPOSTFIX ".exe" +#define SEP "\\" +string FixSep ( const string& s ) +{ + string s2(s); + char* p = strchr ( &s2[0], '/' ); + while ( p ) + { + *p++ = '\\'; + p = strchr ( p, '/' ); + } + return s2; +} +#else +#define EXEPOSTFIX +#define SEP "/" +string FixSep ( const string& s ) +{ + string s2(s); + char* p = strchr ( &s2[0], '\\' ); + while ( p ) + { + *p++ = '/'; + p = strchr ( p, '\\' ); + } + return s2; +} +#endif + Project::Project() { } @@ -21,28 +51,24 @@ Project::~Project() { for ( size_t i = 0; i < modules.size(); i++ ) delete modules[i]; + delete head; } void Project::ReadXml() { Path path; - bool projectFound = false; - do + + head = XMLParse ( xmlfile, path ); + if ( !head ) + throw InvalidBuildFileException ( "Document contains no 'project' tag." ); + + if ( head->name != "project" ) { - XMLElement* head = XMLParse ( xmlfile, path ); - if ( !head ) - throw InvalidBuildFileException ( "Document contains no 'project' tag." ); - - if ( head->name != "project" ) - { - throw InvalidBuildFileException ( "Expected 'project', got '%s'.", - head->name.c_str()); - } - - this->ProcessXML ( *head, "." ); - delete head; - projectFound = true; - } while (!projectFound); + throw InvalidBuildFileException ( "Expected 'project', got '%s'.", + head->name.c_str()); + } + + this->ProcessXML ( *head, "." ); } void @@ -79,3 +105,32 @@ Project::ProcessXML ( const XMLElement& e, const string& path ) for ( size_t i = 0; i < e.subElements.size(); i++ ) ProcessXML ( *e.subElements[i], subpath ); } + +bool +Project::GenerateOutput() +{ + const XMLAttribute* att; + size_t i; + + att = head->GetAttribute ( "makefile", true ); + if ( !att ) + return false; + FILE* f = fopen ( att->value.c_str(), "w" ); + if ( !f ) + { + throw Exception ( "Unable to open '%s' for output", att->value.c_str() ); + return false; + } + fprintf ( f, "# THIS FILE IS AUTOMATICALLY GENERATED, EDIT 'ReactOS.xml' INSTEAD\n\n" ); + + // generate module list: + fprintf ( f, "all: " ); + for ( i = 0; i < modules.size(); i++ ) + { + Module& m = *modules[i]; + fprintf ( f, " %s" SEP "%s" EXEPOSTFIX, FixSep(m.path).c_str(), m.name.c_str() ); + } + fprintf ( f, "\n\n" ); + + return true; +} diff --git a/reactos/tools/rbuild/rbuild.cpp b/reactos/tools/rbuild/rbuild.cpp index f8604984bdd..b13b1fccc65 100644 --- a/reactos/tools/rbuild/rbuild.cpp +++ b/reactos/tools/rbuild/rbuild.cpp @@ -1,6 +1,7 @@ // rbuild.cpp #include "pch.h" +#include #include #include @@ -17,14 +18,15 @@ main ( int argc, char** argv ) try { string projectFilename ( "ReactOS.xml" ); - Project* project = new Project( projectFilename ); + Project project ( projectFilename ); + project.GenerateOutput(); - Path path; // REM TODO FIXME actually do something with Project object... - printf ( "Found %d modules:\n", project->modules.size() ); - for ( size_t i = 0; i < project->modules.size(); i++ ) +#if 0 + printf ( "Found %d modules:\n", project.modules.size() ); + for ( size_t i = 0; i < project.modules.size(); i++ ) { - Module& m = *project->modules[i]; + Module& m = *project.modules[i]; printf ( "\t%s in folder: %s\n", m.name.c_str(), m.path.c_str() ); @@ -49,15 +51,14 @@ main ( int argc, char** argv ) printf ( "\t\t%s\n", m.files[j]->name.c_str() ); } } - - delete project; +#endif return 0; } catch (Exception& ex) { - printf ( "%s\n", - ex.Message.c_str() ); + printf ( "%s: %s\n", + typeid(ex).name(), ex.Message.c_str() ); return 1; } } diff --git a/reactos/tools/rbuild/rbuild.h b/reactos/tools/rbuild/rbuild.h index af0314a69cc..6fa5ab88784 100644 --- a/reactos/tools/rbuild/rbuild.h +++ b/reactos/tools/rbuild/rbuild.h @@ -21,9 +21,11 @@ public: Project ( const std::string& filename ); ~Project (); void ProcessXML ( const XMLElement& e, const std::string& path ); + bool GenerateOutput(); private: void ReadXml (); XMLFile xmlfile; + XMLElement* head; }; class Module -- 2.17.1