10 Project::Project ( const string
& filename
)
21 for ( i
= 0; i
< modules
.size (); i
++ )
23 for ( i
= 0; i
< includes
.size (); i
++ )
25 for ( i
= 0; i
< defines
.size (); i
++ )
27 for ( i
= 0; i
< linkerFlags
.size (); i
++ )
28 delete linkerFlags
[i
];
29 for ( i
= 0; i
< properties
.size (); i
++ )
31 for ( i
= 0; i
< ifs
.size (); i
++ )
33 for ( i
= 0; i
< cdfiles
.size (); i
++ )
39 Project::LookupProperty ( const string
& name
) const
41 for ( size_t i
= 0; i
< properties
.size (); i
++ )
43 const Property
* property
= properties
[i
];
44 if ( property
->name
== name
)
51 Project::WriteIfChanged ( char* outbuf
,
59 out
= fopen ( filename
.c_str (), "rb" );
62 out
= fopen ( filename
.c_str (), "wb" );
64 throw AccessDeniedException ( filename
);
65 fputs ( outbuf
, out
);
70 fseek ( out
, 0, SEEK_END
);
72 cmpbuf
= (char*) malloc ( end
);
76 throw OutOfMemoryException ();
79 fseek ( out
, 0, SEEK_SET
);
80 stat
= fread ( cmpbuf
, 1, end
, out
);
85 throw AccessDeniedException ( filename
);
87 if ( end
== strlen ( outbuf
) && memcmp ( cmpbuf
, outbuf
, end
) == 0 )
96 out
= fopen ( filename
.c_str (), "wb" );
99 throw AccessDeniedException ( filename
);
102 stat
= fwrite ( outbuf
, 1, strlen ( outbuf
), out
);
103 if ( strlen ( outbuf
) != stat
)
106 throw AccessDeniedException ( filename
);
113 Project::SetConfigurationOption ( char* s
,
115 string
* alternativeName
)
117 const Property
* property
= LookupProperty ( name
);
118 if ( property
!= NULL
&& property
->value
.length () > 0 )
122 property
->name
.c_str (),
123 property
->value
.c_str () );
125 else if ( property
!= NULL
)
129 property
->name
.c_str () );
131 else if ( alternativeName
!= NULL
)
135 alternativeName
->c_str () );
140 Project::SetConfigurationOption ( char* s
,
143 SetConfigurationOption ( s
, name
, NULL
);
147 Project::WriteConfigurationFile ()
152 buf
= (char*) malloc ( 10*1024 );
154 throw OutOfMemoryException ();
157 s
= s
+ sprintf ( s
, "/* Automatically generated. " );
158 s
= s
+ sprintf ( s
, "Edit config.xml to change configuration */\n" );
159 s
= s
+ sprintf ( s
, "#ifndef __INCLUDE_CONFIG_H\n" );
160 s
= s
+ sprintf ( s
, "#define __INCLUDE_CONFIG_H\n" );
162 SetConfigurationOption ( s
, "ARCH" );
163 SetConfigurationOption ( s
, "OPTIMIZED" );
164 SetConfigurationOption ( s
, "MP", new string ( "UP" ) );
165 SetConfigurationOption ( s
, "ACPI" );
166 SetConfigurationOption ( s
, "_3GB" );
168 s
= s
+ sprintf ( s
, "#endif /* __INCLUDE_CONFIG_H */\n" );
170 WriteIfChanged ( buf
, "include" SSEP
"roscfg.h" );
176 Project::ExecuteInvocations ()
178 for ( size_t i
= 0; i
< modules
.size (); i
++ )
179 modules
[i
]->InvokeModule ();
186 head
= XMLLoadFile ( xmlfile
, path
);
188 for ( size_t i
= 0; i
< head
->subElements
.size (); i
++ )
190 if ( head
->subElements
[i
]->name
== "project" )
192 node
= head
->subElements
[i
];
193 this->ProcessXML ( "." );
198 throw InvalidBuildFileException (
200 "Document contains no 'project' tag." );
204 Project::ProcessXML ( const string
& path
)
206 const XMLAttribute
*att
;
207 if ( node
->name
!= "project" )
208 throw Exception ( "internal tool error: Project::ProcessXML() called with non-<project> node" );
210 att
= node
->GetAttribute ( "name", false );
216 att
= node
->GetAttribute ( "makefile", true );
218 makefile
= att
->value
;
221 for ( i
= 0; i
< node
->subElements
.size (); i
++ )
222 ProcessXMLSubElement ( *node
->subElements
[i
], path
);
223 for ( i
= 0; i
< modules
.size (); i
++ )
224 modules
[i
]->ProcessXML ();
225 for ( i
= 0; i
< includes
.size (); i
++ )
226 includes
[i
]->ProcessXML ();
227 for ( i
= 0; i
< defines
.size (); i
++ )
228 defines
[i
]->ProcessXML ();
229 for ( i
= 0; i
< linkerFlags
.size (); i
++ )
230 linkerFlags
[i
]->ProcessXML ();
231 for ( i
= 0; i
< properties
.size(); i
++ )
232 properties
[i
]->ProcessXML ();
233 for ( i
= 0; i
< ifs
.size (); i
++ )
234 ifs
[i
]->ProcessXML ();
235 for ( i
= 0; i
< cdfiles
.size (); i
++ )
236 ifs
[i
]->ProcessXML ();
240 Project::ProcessXMLSubElement ( const XMLElement
& e
,
244 bool subs_invalid
= false;
245 string
subpath(path
);
246 if ( e
.name
== "module" )
249 throw InvalidBuildFileException (
251 "<module> is not a valid sub-element of <if>" );
252 Module
* module
= new Module ( *this, e
, path
);
253 if ( LocateModule ( module
->name
) )
254 throw InvalidBuildFileException (
256 "module name conflict: '%s' (originally defined at %s)",
257 module
->name
.c_str(),
258 module
->node
.location
.c_str() );
259 modules
.push_back ( module
);
260 return; // defer processing until later
262 else if ( e
.name
== "cdfile" )
264 CDFile
* cdfile
= new CDFile ( *this, e
, path
);
265 cdfiles
.push_back ( cdfile
);
268 else if ( e
.name
== "directory" )
270 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
272 subpath
= path
+ CSEP
+ att
->value
;
274 else if ( e
.name
== "include" )
276 Include
* include
= new Include ( *this, e
);
278 pIf
->includes
.push_back ( include
);
280 includes
.push_back ( include
);
283 else if ( e
.name
== "define" )
285 Define
* define
= new Define ( *this, e
);
287 pIf
->defines
.push_back ( define
);
289 defines
.push_back ( define
);
292 else if ( e
.name
== "linkerflag" )
294 linkerFlags
.push_back ( new LinkerFlag ( *this, e
) );
297 else if ( e
.name
== "if" )
300 pIf
= new If ( e
, *this, NULL
);
302 pOldIf
->ifs
.push_back ( pIf
);
304 ifs
.push_back ( pIf
);
305 subs_invalid
= false;
307 else if ( e
.name
== "property" )
309 Property
* property
= new Property ( e
, *this, NULL
);
311 pIf
->properties
.push_back ( property
);
313 properties
.push_back ( property
);
315 if ( subs_invalid
&& e
.subElements
.size() )
316 throw InvalidBuildFileException (
318 "<%s> cannot have sub-elements",
320 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
321 ProcessXMLSubElement ( *e
.subElements
[i
], subpath
, pIf
);
325 Project::LocateModule ( const string
& name
)
327 for ( size_t i
= 0; i
< modules
.size (); i
++ )
329 if (modules
[i
]->name
== name
)
337 Project::LocateModule ( const string
& name
) const
339 for ( size_t i
= 0; i
< modules
.size (); i
++ )
341 if ( modules
[i
]->name
== name
)