e929c0cfe87b594710a3b586d7346195d9b0f3ae
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
];
185 this->ProcessXML ( "." );
190 throw InvalidBuildFileException (
192 "Document contains no 'project' tag." );
196 Project::ProcessXML ( const string
& path
)
198 const XMLAttribute
*att
;
199 if ( node
->name
!= "project" )
200 throw Exception ( "internal tool error: Project::ProcessXML() called with non-<project> node" );
202 att
= node
->GetAttribute ( "name", false );
208 att
= node
->GetAttribute ( "makefile", true );
210 makefile
= att
->value
;
213 for ( i
= 0; i
< node
->subElements
.size (); i
++ )
214 ProcessXMLSubElement ( *node
->subElements
[i
], path
);
215 for ( i
= 0; i
< modules
.size (); i
++ )
216 modules
[i
]->ProcessXML ();
217 for ( i
= 0; i
< linkerFlags
.size (); i
++ )
218 linkerFlags
[i
]->ProcessXML ();
219 non_if_data
.ProcessXML ();
220 for ( i
= 0; i
< cdfiles
.size (); i
++ )
221 cdfiles
[i
]->ProcessXML ();
225 Project::ProcessXMLSubElement ( const XMLElement
& e
,
229 bool subs_invalid
= false;
230 string
subpath(path
);
231 if ( e
.name
== "module" )
234 throw InvalidBuildFileException (
236 "<module> is not a valid sub-element of <if>" );
237 Module
* module
= new Module ( *this, e
, path
);
238 if ( LocateModule ( module
->name
) )
239 throw InvalidBuildFileException (
241 "module name conflict: '%s' (originally defined at %s)",
242 module
->name
.c_str(),
243 module
->node
.location
.c_str() );
244 modules
.push_back ( module
);
245 return; // defer processing until later
247 else if ( e
.name
== "cdfile" )
249 CDFile
* cdfile
= new CDFile ( *this, e
, path
);
250 cdfiles
.push_back ( cdfile
);
253 else if ( e
.name
== "directory" )
255 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
257 subpath
= path
+ CSEP
+ att
->value
;
259 else if ( e
.name
== "include" )
261 Include
* include
= new Include ( *this, e
);
263 pIf
->data
.includes
.push_back ( include
);
265 non_if_data
.includes
.push_back ( include
);
268 else if ( e
.name
== "define" )
270 Define
* define
= new Define ( *this, e
);
272 pIf
->data
.defines
.push_back ( define
);
274 non_if_data
.defines
.push_back ( define
);
277 else if ( e
.name
== "linkerflag" )
279 linkerFlags
.push_back ( new LinkerFlag ( *this, e
) );
282 else if ( e
.name
== "if" )
285 pIf
= new If ( e
, *this, NULL
);
287 pOldIf
->data
.ifs
.push_back ( pIf
);
289 non_if_data
.ifs
.push_back ( pIf
);
290 subs_invalid
= false;
292 else if ( e
.name
== "property" )
294 Property
* property
= new Property ( e
, *this, NULL
);
296 pIf
->data
.properties
.push_back ( property
);
298 non_if_data
.properties
.push_back ( property
);
300 if ( subs_invalid
&& e
.subElements
.size() )
301 throw InvalidBuildFileException (
303 "<%s> cannot have sub-elements",
305 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
306 ProcessXMLSubElement ( *e
.subElements
[i
], subpath
, pIf
);
310 Project::LocateModule ( const string
& name
)
312 for ( size_t i
= 0; i
< modules
.size (); i
++ )
314 if (modules
[i
]->name
== name
)
322 Project::LocateModule ( const string
& name
) const
324 for ( size_t i
= 0; i
< modules
.size (); i
++ )
326 if ( modules
[i
]->name
== name
)
334 Project::GetProjectFilename () const