10 Project::Project ( const string
& filename
)
21 for ( i
= 0; i
< modules
.size (); i
++ )
23 for ( i
= 0; i
< linkerFlags
.size (); i
++ )
24 delete linkerFlags
[i
];
25 for ( i
= 0; i
< cdfiles
.size (); i
++ )
31 Project::LookupProperty ( const string
& name
) const
33 for ( size_t i
= 0; i
< non_if_data
.properties
.size (); i
++ )
35 const Property
* property
= non_if_data
.properties
[i
];
36 if ( property
->name
== name
)
43 Project::WriteIfChanged ( char* outbuf
,
51 out
= fopen ( filename
.c_str (), "rb" );
54 out
= fopen ( filename
.c_str (), "wb" );
56 throw AccessDeniedException ( filename
);
57 fputs ( outbuf
, out
);
62 fseek ( out
, 0, SEEK_END
);
64 cmpbuf
= (char*) malloc ( end
);
68 throw OutOfMemoryException ();
71 fseek ( out
, 0, SEEK_SET
);
72 stat
= fread ( cmpbuf
, 1, end
, out
);
77 throw AccessDeniedException ( filename
);
79 if ( end
== strlen ( outbuf
) && memcmp ( cmpbuf
, outbuf
, end
) == 0 )
88 out
= fopen ( filename
.c_str (), "wb" );
91 throw AccessDeniedException ( filename
);
94 stat
= fwrite ( outbuf
, 1, strlen ( outbuf
), out
);
95 if ( strlen ( outbuf
) != stat
)
98 throw AccessDeniedException ( filename
);
105 Project::SetConfigurationOption ( char* s
,
107 string
* alternativeName
)
109 const Property
* property
= LookupProperty ( name
);
110 if ( property
!= NULL
&& property
->value
.length () > 0 )
114 property
->name
.c_str (),
115 property
->value
.c_str () );
117 else if ( property
!= NULL
)
121 property
->name
.c_str () );
123 else if ( alternativeName
!= NULL
)
127 alternativeName
->c_str () );
132 Project::SetConfigurationOption ( char* s
,
135 SetConfigurationOption ( s
, name
, NULL
);
139 Project::WriteConfigurationFile ()
144 buf
= (char*) malloc ( 10*1024 );
146 throw OutOfMemoryException ();
149 s
= s
+ sprintf ( s
, "/* Automatically generated. " );
150 s
= s
+ sprintf ( s
, "Edit config.xml to change configuration */\n" );
151 s
= s
+ sprintf ( s
, "#ifndef __INCLUDE_CONFIG_H\n" );
152 s
= s
+ sprintf ( s
, "#define __INCLUDE_CONFIG_H\n" );
154 SetConfigurationOption ( s
, "ARCH" );
155 SetConfigurationOption ( s
, "OPTIMIZED" );
156 SetConfigurationOption ( s
, "MP", new string ( "UP" ) );
157 SetConfigurationOption ( s
, "ACPI" );
158 SetConfigurationOption ( s
, "_3GB" );
160 s
= s
+ sprintf ( s
, "#endif /* __INCLUDE_CONFIG_H */\n" );
162 WriteIfChanged ( buf
, "include" SSEP
"roscfg.h" );
168 Project::ExecuteInvocations ()
170 for ( size_t i
= 0; i
< modules
.size (); i
++ )
171 modules
[i
]->InvokeModule ();
178 head
= XMLLoadFile ( xmlfile
, path
, xmlbuildfiles
);
180 for ( size_t i
= 0; i
< head
->subElements
.size (); i
++ )
182 if ( head
->subElements
[i
]->name
== "project" )
184 node
= head
->subElements
[i
];
186 this->ProcessXML ( path
);
191 throw InvalidBuildFileException (
193 "Document contains no 'project' tag." );
197 Project::ProcessXML ( const string
& path
)
199 const XMLAttribute
*att
;
200 if ( node
->name
!= "project" )
201 throw Exception ( "internal tool error: Project::ProcessXML() called with non-<project> node" );
203 att
= node
->GetAttribute ( "name", false );
209 att
= node
->GetAttribute ( "makefile", true );
211 makefile
= att
->value
;
214 for ( i
= 0; i
< node
->subElements
.size (); i
++ )
215 ProcessXMLSubElement ( *node
->subElements
[i
], path
);
216 for ( i
= 0; i
< modules
.size (); i
++ )
217 modules
[i
]->ProcessXML ();
218 for ( i
= 0; i
< linkerFlags
.size (); i
++ )
219 linkerFlags
[i
]->ProcessXML ();
220 non_if_data
.ProcessXML ();
221 for ( i
= 0; i
< cdfiles
.size (); i
++ )
222 cdfiles
[i
]->ProcessXML ();
226 Project::ProcessXMLSubElement ( const XMLElement
& e
,
230 bool subs_invalid
= false;
231 string
subpath(path
);
232 if ( e
.name
== "module" )
235 throw InvalidBuildFileException (
237 "<module> is not a valid sub-element of <if>" );
238 Module
* module
= new Module ( *this, e
, path
);
239 if ( LocateModule ( module
->name
) )
240 throw InvalidBuildFileException (
242 "module name conflict: '%s' (originally defined at %s)",
243 module
->name
.c_str(),
244 module
->node
.location
.c_str() );
245 modules
.push_back ( module
);
246 return; // defer processing until later
248 else if ( e
.name
== "cdfile" )
250 CDFile
* cdfile
= new CDFile ( *this, e
, path
);
251 cdfiles
.push_back ( cdfile
);
254 else if ( e
.name
== "directory" )
256 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
258 subpath
= GetSubPath ( e
.location
, path
, att
->value
);
260 else if ( e
.name
== "include" )
262 Include
* include
= new Include ( *this, e
);
264 pIf
->data
.includes
.push_back ( include
);
266 non_if_data
.includes
.push_back ( include
);
269 else if ( e
.name
== "define" )
271 Define
* define
= new Define ( *this, e
);
273 pIf
->data
.defines
.push_back ( define
);
275 non_if_data
.defines
.push_back ( define
);
278 else if ( e
.name
== "linkerflag" )
280 linkerFlags
.push_back ( new LinkerFlag ( *this, e
) );
283 else if ( e
.name
== "if" )
286 pIf
= new If ( e
, *this, NULL
);
288 pOldIf
->data
.ifs
.push_back ( pIf
);
290 non_if_data
.ifs
.push_back ( pIf
);
291 subs_invalid
= false;
293 else if ( e
.name
== "property" )
295 Property
* property
= new Property ( e
, *this, NULL
);
297 pIf
->data
.properties
.push_back ( property
);
299 non_if_data
.properties
.push_back ( property
);
301 if ( subs_invalid
&& e
.subElements
.size() )
302 throw InvalidBuildFileException (
304 "<%s> cannot have sub-elements",
306 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
307 ProcessXMLSubElement ( *e
.subElements
[i
], subpath
, pIf
);
311 Project::LocateModule ( const string
& name
)
313 for ( size_t i
= 0; i
< modules
.size (); i
++ )
315 if (modules
[i
]->name
== name
)
323 Project::LocateModule ( const string
& name
) const
325 for ( size_t i
= 0; i
< modules
.size (); i
++ )
327 if ( modules
[i
]->name
== name
)
335 Project::GetProjectFilename () const