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
++ )
27 for ( i
= 0; i
< installfiles
.size (); i
++ )
28 delete installfiles
[i
];
33 Project::LookupProperty ( const string
& name
) const
35 for ( size_t i
= 0; i
< non_if_data
.properties
.size (); i
++ )
37 const Property
* property
= non_if_data
.properties
[i
];
38 if ( property
->name
== name
)
45 Project::WriteIfChanged ( char* outbuf
,
53 out
= fopen ( filename
.c_str (), "rb" );
56 out
= fopen ( filename
.c_str (), "wb" );
58 throw AccessDeniedException ( filename
);
59 fputs ( outbuf
, out
);
64 fseek ( out
, 0, SEEK_END
);
66 cmpbuf
= (char*) malloc ( end
);
70 throw OutOfMemoryException ();
73 fseek ( out
, 0, SEEK_SET
);
74 stat
= fread ( cmpbuf
, 1, end
, out
);
79 throw AccessDeniedException ( filename
);
81 if ( end
== strlen ( outbuf
) && memcmp ( cmpbuf
, outbuf
, end
) == 0 )
90 out
= fopen ( filename
.c_str (), "wb" );
93 throw AccessDeniedException ( filename
);
96 stat
= fwrite ( outbuf
, 1, strlen ( outbuf
), out
);
97 if ( strlen ( outbuf
) != stat
)
100 throw AccessDeniedException ( filename
);
107 Project::SetConfigurationOption ( char* s
,
109 string
* alternativeName
)
111 const Property
* property
= LookupProperty ( name
);
112 if ( property
!= NULL
&& property
->value
.length () > 0 )
116 property
->name
.c_str (),
117 property
->value
.c_str () );
119 else if ( property
!= NULL
)
123 property
->name
.c_str () );
125 else if ( alternativeName
!= NULL
)
129 alternativeName
->c_str () );
134 Project::SetConfigurationOption ( char* s
,
137 SetConfigurationOption ( s
, name
, NULL
);
141 Project::WriteConfigurationFile ()
146 buf
= (char*) malloc ( 10*1024 );
148 throw OutOfMemoryException ();
151 s
= s
+ sprintf ( s
, "/* Automatically generated. " );
152 s
= s
+ sprintf ( s
, "Edit config.xml to change configuration */\n" );
153 s
= s
+ sprintf ( s
, "#ifndef __INCLUDE_CONFIG_H\n" );
154 s
= s
+ sprintf ( s
, "#define __INCLUDE_CONFIG_H\n" );
156 SetConfigurationOption ( s
, "ARCH" );
157 SetConfigurationOption ( s
, "OPTIMIZED" );
158 SetConfigurationOption ( s
, "MP", new string ( "UP" ) );
159 SetConfigurationOption ( s
, "ACPI" );
160 SetConfigurationOption ( s
, "_3GB" );
162 s
= s
+ sprintf ( s
, "#endif /* __INCLUDE_CONFIG_H */\n" );
164 WriteIfChanged ( buf
, "include" SSEP
"roscfg.h" );
170 Project::ExecuteInvocations ()
172 for ( size_t i
= 0; i
< modules
.size (); i
++ )
173 modules
[i
]->InvokeModule ();
180 head
= XMLLoadFile ( xmlfile
, path
, xmlbuildfiles
);
182 for ( size_t i
= 0; i
< head
->subElements
.size (); i
++ )
184 if ( head
->subElements
[i
]->name
== "project" )
186 node
= head
->subElements
[i
];
188 this->ProcessXML ( path
);
193 throw InvalidBuildFileException (
195 "Document contains no 'project' tag." );
199 Project::ProcessXML ( const string
& path
)
201 const XMLAttribute
*att
;
202 if ( node
->name
!= "project" )
203 throw Exception ( "internal tool error: Project::ProcessXML() called with non-<project> node" );
205 att
= node
->GetAttribute ( "name", false );
211 att
= node
->GetAttribute ( "makefile", true );
213 makefile
= att
->value
;
216 for ( i
= 0; i
< node
->subElements
.size (); i
++ )
217 ProcessXMLSubElement ( *node
->subElements
[i
], path
);
218 for ( i
= 0; i
< modules
.size (); i
++ )
219 modules
[i
]->ProcessXML ();
220 for ( i
= 0; i
< linkerFlags
.size (); i
++ )
221 linkerFlags
[i
]->ProcessXML ();
222 non_if_data
.ProcessXML ();
223 for ( i
= 0; i
< cdfiles
.size (); i
++ )
224 cdfiles
[i
]->ProcessXML ();
225 for ( i
= 0; i
< installfiles
.size (); i
++ )
226 installfiles
[i
]->ProcessXML ();
230 Project::ProcessXMLSubElement ( const XMLElement
& e
,
234 bool subs_invalid
= false;
235 string
subpath(path
);
236 if ( e
.name
== "module" )
239 throw InvalidBuildFileException (
241 "<module> is not a valid sub-element of <if>" );
242 Module
* module
= new Module ( *this, e
, path
);
243 if ( LocateModule ( module
->name
) )
244 throw InvalidBuildFileException (
246 "module name conflict: '%s' (originally defined at %s)",
247 module
->name
.c_str(),
248 module
->node
.location
.c_str() );
249 modules
.push_back ( module
);
250 return; // defer processing until later
252 else if ( e
.name
== "cdfile" )
254 CDFile
* cdfile
= new CDFile ( *this, e
, path
);
255 cdfiles
.push_back ( cdfile
);
258 else if ( e
.name
== "installfile" )
260 InstallFile
* installfile
= new InstallFile ( *this, e
, path
);
261 installfiles
.push_back ( installfile
);
264 else if ( e
.name
== "directory" )
266 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
268 subpath
= GetSubPath ( e
.location
, path
, att
->value
);
270 else if ( e
.name
== "include" )
272 Include
* include
= new Include ( *this, e
);
274 pIf
->data
.includes
.push_back ( include
);
276 non_if_data
.includes
.push_back ( include
);
279 else if ( e
.name
== "define" )
281 Define
* define
= new Define ( *this, e
);
283 pIf
->data
.defines
.push_back ( define
);
285 non_if_data
.defines
.push_back ( define
);
288 else if ( e
.name
== "linkerflag" )
290 linkerFlags
.push_back ( new LinkerFlag ( *this, e
) );
293 else if ( e
.name
== "if" )
296 pIf
= new If ( e
, *this, NULL
);
298 pOldIf
->data
.ifs
.push_back ( pIf
);
300 non_if_data
.ifs
.push_back ( pIf
);
301 subs_invalid
= false;
303 else if ( e
.name
== "property" )
305 Property
* property
= new Property ( e
, *this, NULL
);
307 pIf
->data
.properties
.push_back ( property
);
309 non_if_data
.properties
.push_back ( property
);
311 if ( subs_invalid
&& e
.subElements
.size() )
312 throw InvalidBuildFileException (
314 "<%s> cannot have sub-elements",
316 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
317 ProcessXMLSubElement ( *e
.subElements
[i
], subpath
, pIf
);
321 Project::LocateModule ( const string
& name
)
323 for ( size_t i
= 0; i
< modules
.size (); i
++ )
325 if (modules
[i
]->name
== name
)
333 Project::LocateModule ( const string
& name
) const
335 for ( size_t i
= 0; i
< modules
.size (); i
++ )
337 if ( modules
[i
]->name
== name
)
345 Project::GetProjectFilename () const