10 #define EXEPOSTFIX ".exe"
12 string
FixSep ( const string
& s
)
15 char* p
= strchr ( &s2
[0], '/' );
19 p
= strchr ( p
, '/' );
26 string
FixSep ( const string
& s
)
29 char* p
= strchr ( &s2
[0], '\\' );
33 p
= strchr ( p
, '\\' );
43 Project::Project(const string
& filename
)
45 if ( !xmlfile
.open ( filename
) )
46 throw FileNotFoundException ( filename
);
52 for ( size_t i
= 0; i
< modules
.size(); i
++ )
57 void Project::ReadXml()
61 head
= XMLParse ( xmlfile
, path
);
63 throw InvalidBuildFileException ( "Document contains no 'project' tag." );
65 if ( head
->name
!= "project" )
67 throw InvalidBuildFileException ( "Expected 'project', got '%s'.",
71 this->ProcessXML ( *head
, "." );
75 Project::ProcessXML ( const XMLElement
& e
, const string
& path
)
77 const XMLAttribute
*att
;
79 if ( e
.name
== "project" )
81 att
= e
.GetAttribute ( "name", false );
87 else if ( e
.name
== "module" )
89 att
= e
.GetAttribute ( "name", true );
92 Module
* module
= new Module ( e
, att
->value
, path
);
93 modules
.push_back ( module
);
94 module
->ProcessXML ( e
, path
);
97 else if ( e
.name
== "directory" )
99 // this code is duplicated between Project::ProcessXML() and Module::ProcessXML() :(
100 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
103 subpath
= path
+ "/" + att
->value
;
105 for ( size_t i
= 0; i
< e
.subElements
.size(); i
++ )
106 ProcessXML ( *e
.subElements
[i
], subpath
);
110 Project::GenerateOutput()
112 const XMLAttribute
* att
;
115 att
= head
->GetAttribute ( "makefile", true );
118 FILE* f
= fopen ( att
->value
.c_str(), "w" );
121 throw Exception ( "Unable to open '%s' for output", att
->value
.c_str() );
124 fprintf ( f
, "# THIS FILE IS AUTOMATICALLY GENERATED, EDIT 'ReactOS.xml' INSTEAD\n\n" );
126 // generate module list:
127 fprintf ( f
, "all: " );
128 for ( i
= 0; i
< modules
.size(); i
++ )
130 Module
& m
= *modules
[i
];
131 fprintf ( f
, " %s" SEP
"%s" EXEPOSTFIX
, FixSep(m
.path
).c_str(), m
.name
.c_str() );
133 fprintf ( f
, "\n\n" );