11 Environment::GetVariable ( const string
& name
)
13 char* value
= getenv ( name
.c_str () );
14 if ( value
!= NULL
&& strlen ( value
) > 0 )
15 return ssprintf ( "%s",
22 Environment::GetEnvironmentVariablePathOrDefault ( const string
& name
,
23 const string
& defaultValue
)
25 const string
& environmentVariableValue
= Environment::GetVariable ( name
);
26 if ( environmentVariableValue
.length () > 0 )
27 return NormalizeFilename ( environmentVariableValue
);
33 Environment::GetIntermediatePath ()
35 return GetEnvironmentVariablePathOrDefault ( "ROS_INTERMEDIATE",
40 Environment::GetOutputPath ()
42 return GetEnvironmentVariablePathOrDefault ( "ROS_OUTPUT",
47 Environment::GetInstallPath ()
49 return GetEnvironmentVariablePathOrDefault ( "ROS_INSTALL",
54 Project::Project ( const string
& filename
)
65 for ( i
= 0; i
< modules
.size (); i
++ )
67 for ( i
= 0; i
< linkerFlags
.size (); i
++ )
68 delete linkerFlags
[i
];
69 for ( i
= 0; i
< cdfiles
.size (); i
++ )
71 for ( i
= 0; i
< installfiles
.size (); i
++ )
72 delete installfiles
[i
];
77 Project::LookupProperty ( const string
& name
) const
79 for ( size_t i
= 0; i
< non_if_data
.properties
.size (); i
++ )
81 const Property
* property
= non_if_data
.properties
[i
];
82 if ( property
->name
== name
)
89 Project::SetConfigurationOption ( char* s
,
91 string
* alternativeName
)
93 const Property
* property
= LookupProperty ( name
);
94 if ( property
!= NULL
&& property
->value
.length () > 0 )
98 property
->name
.c_str (),
99 property
->value
.c_str () );
101 else if ( property
!= NULL
)
105 property
->name
.c_str () );
107 else if ( alternativeName
!= NULL
)
111 alternativeName
->c_str () );
116 Project::SetConfigurationOption ( char* s
,
119 SetConfigurationOption ( s
, name
, NULL
);
123 Project::WriteConfigurationFile ()
128 buf
= (char*) malloc ( 10*1024 );
130 throw OutOfMemoryException ();
133 s
= s
+ sprintf ( s
, "/* Automatically generated. " );
134 s
= s
+ sprintf ( s
, "Edit config.xml to change configuration */\n" );
135 s
= s
+ sprintf ( s
, "#ifndef __INCLUDE_CONFIG_H\n" );
136 s
= s
+ sprintf ( s
, "#define __INCLUDE_CONFIG_H\n" );
138 SetConfigurationOption ( s
, "ARCH" );
139 SetConfigurationOption ( s
, "OPTIMIZED" );
140 SetConfigurationOption ( s
, "MP", new string ( "UP" ) );
141 SetConfigurationOption ( s
, "ACPI" );
142 SetConfigurationOption ( s
, "_3GB" );
144 s
= s
+ sprintf ( s
, "#endif /* __INCLUDE_CONFIG_H */\n" );
146 FileSupportCode::WriteIfChanged ( buf
, "include" SSEP
"roscfg.h" );
152 Project::ExecuteInvocations ()
154 for ( size_t i
= 0; i
< modules
.size (); i
++ )
155 modules
[i
]->InvokeModule ();
162 head
= XMLLoadFile ( xmlfile
, path
, xmlbuildfiles
);
164 for ( size_t i
= 0; i
< head
->subElements
.size (); i
++ )
166 if ( head
->subElements
[i
]->name
== "project" )
168 node
= head
->subElements
[i
];
170 this->ProcessXML ( path
);
175 throw InvalidBuildFileException (
177 "Document contains no 'project' tag." );
181 Project::ProcessXML ( const string
& path
)
183 const XMLAttribute
*att
;
184 if ( node
->name
!= "project" )
185 throw Exception ( "internal tool error: Project::ProcessXML() called with non-<project> node" );
187 att
= node
->GetAttribute ( "name", false );
193 att
= node
->GetAttribute ( "makefile", true );
195 makefile
= att
->value
;
198 for ( i
= 0; i
< node
->subElements
.size (); i
++ )
199 ProcessXMLSubElement ( *node
->subElements
[i
], path
);
200 for ( i
= 0; i
< modules
.size (); i
++ )
201 modules
[i
]->ProcessXML ();
202 for ( i
= 0; i
< linkerFlags
.size (); i
++ )
203 linkerFlags
[i
]->ProcessXML ();
204 non_if_data
.ProcessXML ();
205 for ( i
= 0; i
< cdfiles
.size (); i
++ )
206 cdfiles
[i
]->ProcessXML ();
207 for ( i
= 0; i
< installfiles
.size (); i
++ )
208 installfiles
[i
]->ProcessXML ();
212 Project::ProcessXMLSubElement ( const XMLElement
& e
,
216 bool subs_invalid
= false;
217 string
subpath(path
);
218 if ( e
.name
== "module" )
221 throw InvalidBuildFileException (
223 "<module> is not a valid sub-element of <if>" );
224 Module
* module
= new Module ( *this, e
, path
);
225 if ( LocateModule ( module
->name
) )
226 throw InvalidBuildFileException (
228 "module name conflict: '%s' (originally defined at %s)",
229 module
->name
.c_str(),
230 module
->node
.location
.c_str() );
231 modules
.push_back ( module
);
232 return; // defer processing until later
234 else if ( e
.name
== "cdfile" )
236 CDFile
* cdfile
= new CDFile ( *this, e
, path
);
237 cdfiles
.push_back ( cdfile
);
240 else if ( e
.name
== "installfile" )
242 InstallFile
* installfile
= new InstallFile ( *this, e
, path
);
243 installfiles
.push_back ( installfile
);
246 else if ( e
.name
== "directory" )
248 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
250 subpath
= GetSubPath ( e
.location
, path
, att
->value
);
252 else if ( e
.name
== "include" )
254 Include
* include
= new Include ( *this, e
);
256 pIf
->data
.includes
.push_back ( include
);
258 non_if_data
.includes
.push_back ( include
);
261 else if ( e
.name
== "define" )
263 Define
* define
= new Define ( *this, e
);
265 pIf
->data
.defines
.push_back ( define
);
267 non_if_data
.defines
.push_back ( define
);
270 else if ( e
.name
== "compilerflag" )
272 CompilerFlag
* pCompilerFlag
= new CompilerFlag ( *this, e
);
274 pIf
->data
.compilerFlags
.push_back ( pCompilerFlag
);
276 non_if_data
.compilerFlags
.push_back ( pCompilerFlag
);
279 else if ( e
.name
== "linkerflag" )
281 linkerFlags
.push_back ( new LinkerFlag ( *this, e
) );
284 else if ( e
.name
== "if" )
287 pIf
= new If ( e
, *this, NULL
);
289 pOldIf
->data
.ifs
.push_back ( pIf
);
291 non_if_data
.ifs
.push_back ( pIf
);
292 subs_invalid
= false;
294 else if ( e
.name
== "property" )
296 Property
* property
= new Property ( e
, *this, NULL
);
298 pIf
->data
.properties
.push_back ( property
);
300 non_if_data
.properties
.push_back ( property
);
302 if ( subs_invalid
&& e
.subElements
.size() )
303 throw InvalidBuildFileException (
305 "<%s> cannot have sub-elements",
307 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
308 ProcessXMLSubElement ( *e
.subElements
[i
], subpath
, pIf
);
312 Project::LocateModule ( const string
& name
)
314 for ( size_t i
= 0; i
< modules
.size (); i
++ )
316 if (modules
[i
]->name
== name
)
324 Project::LocateModule ( const string
& name
) const
326 for ( size_t i
= 0; i
< modules
.size (); i
++ )
328 if ( modules
[i
]->name
== name
)
336 Project::GetProjectFilename () const