fba4022ad922fa4b4dcd6e75725c779a973a915d
12 FixSeparator ( const string
& s
)
15 char* p
= strchr ( &s2
[0], CBAD_SEP
);
19 p
= strchr ( p
, CBAD_SEP
);
24 Module::Module ( const Project
& project
,
25 const XMLElement
& moduleNode
,
26 const string
& modulePath
)
31 if ( node
.name
!= "module" )
32 throw Exception ( "internal tool error: Module created with non-<module> node" );
34 path
= FixSeparator ( modulePath
);
36 const XMLAttribute
* att
= moduleNode
.GetAttribute ( "name", true );
40 att
= moduleNode
.GetAttribute ( "type", true );
42 type
= GetModuleType ( node
.location
, *att
);
44 att
= moduleNode
.GetAttribute ( "extension", false );
46 extension
= att
->value
;
48 extension
= GetDefaultModuleExtension ();
54 for ( i
= 0; i
< files
.size(); i
++ )
56 for ( i
= 0; i
< libraries
.size(); i
++ )
58 for ( i
= 0; i
< includes
.size(); i
++ )
60 for ( i
= 0; i
< defines
.size(); i
++ )
62 for ( i
= 0; i
< invocations
.size(); i
++ )
63 delete invocations
[i
];
64 for ( i
= 0; i
< dependencies
.size(); i
++ )
65 delete dependencies
[i
];
72 for ( i
= 0; i
< node
.subElements
.size(); i
++ )
73 ProcessXMLSubElement ( *node
.subElements
[i
], path
);
74 for ( i
= 0; i
< files
.size (); i
++ )
75 files
[i
]->ProcessXML ();
76 for ( i
= 0; i
< libraries
.size(); i
++ )
77 libraries
[i
]->ProcessXML ();
78 for ( i
= 0; i
< includes
.size(); i
++ )
79 includes
[i
]->ProcessXML ();
80 for ( i
= 0; i
< defines
.size(); i
++ )
81 defines
[i
]->ProcessXML ();
82 for ( i
= 0; i
< invocations
.size(); i
++ )
83 invocations
[i
]->ProcessXML ();
84 for ( i
= 0; i
< dependencies
.size(); i
++ )
85 dependencies
[i
]->ProcessXML ();
89 Module::ProcessXMLSubElement ( const XMLElement
& e
,
92 bool subs_invalid
= false;
93 string
subpath ( path
);
94 if ( e
.name
== "file" && e
.value
.size () > 0 )
96 files
.push_back ( new File ( FixSeparator ( path
+ CSEP
+ e
.value
) ) );
99 else if ( e
.name
== "library" && e
.value
.size () )
101 libraries
.push_back ( new Library ( e
, *this, e
.value
) );
104 else if ( e
.name
== "directory" )
106 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
108 subpath
= FixSeparator ( path
+ CSEP
+ att
->value
);
110 else if ( e
.name
== "include" )
112 includes
.push_back ( new Include ( project
, this, e
) );
115 else if ( e
.name
== "define" )
117 defines
.push_back ( new Define ( project
, this, e
) );
120 else if ( e
.name
== "invoke" )
122 invocations
.push_back ( new Invoke ( e
, *this ) );
123 subs_invalid
= false;
125 else if ( e
.name
== "dependency" )
127 dependencies
.push_back ( new Dependency ( e
, *this ) );
130 else if ( e
.name
== "importlibrary" )
132 importLibrary
= new ImportLibrary ( e
, *this );
135 if ( subs_invalid
&& e
.subElements
.size() > 0 )
136 throw InvalidBuildFileException (
138 "<%s> cannot have sub-elements",
140 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
141 ProcessXMLSubElement ( *e
.subElements
[i
], subpath
);
145 Module::GetModuleType ( const string
& location
, const XMLAttribute
& attribute
)
147 if ( attribute
.value
== "buildtool" )
149 if ( attribute
.value
== "staticlibrary" )
150 return StaticLibrary
;
151 if ( attribute
.value
== "kernel" )
153 if ( attribute
.value
== "kernelmodedll" )
154 return KernelModeDLL
;
155 if ( attribute
.value
== "nativedll" )
157 throw InvalidAttributeValueException ( location
,
163 Module::GetDefaultModuleExtension () const
178 throw InvalidOperationException (__FILE__
,
183 Module::GetTargetName () const
185 return name
+ extension
;
189 Module::GetDependencyPath () const
191 if ( type
== KernelModeDLL
)
192 return ssprintf ( "dk%snkm%slib%slib%s.a",
202 Module::GetBasePath () const
208 Module::GetPath () const
210 return path
+ CSEP
+ GetTargetName ();
214 Module::GetPathWithPrefix ( const string
& prefix
) const
216 return path
+ CSEP
+ prefix
+ GetTargetName ();
220 Module::GetTargets () const
222 if ( invocations
.size () > 0 )
224 string
targets ( "" );
225 for ( size_t i
= 0; i
< invocations
.size (); i
++ )
227 Invoke
& invoke
= *invocations
[i
];
228 if ( targets
.length () > 0 )
230 targets
+= invoke
.GetTargets ();
239 Module::GetInvocationTarget ( const int index
) const
241 return ssprintf ( "%s_invoke_%d",
247 File::File ( const string
& _name
)
258 Library::Library ( const XMLElement
& _node
,
259 const Module
& _module
,
260 const string
& _name
)
265 if ( module
.name
== name
)
266 throw InvalidBuildFileException (
268 "module '%s' cannot link against itself",
273 Library::ProcessXML()
275 if ( !module
.project
.LocateModule ( name
) )
276 throw InvalidBuildFileException (
278 "module '%s' is trying to link against non-existant module '%s'",
284 Invoke::Invoke ( const XMLElement
& _node
,
285 const Module
& _module
)
294 const XMLAttribute
* att
= node
.GetAttribute ( "module", false );
296 invokeModule
= &module
;
299 invokeModule
= module
.project
.LocateModule ( att
->value
);
300 if ( invokeModule
== NULL
)
301 throw InvalidBuildFileException (
303 "module '%s' is trying to invoke non-existant module '%s'",
305 att
->value
.c_str() );
308 for ( size_t i
= 0; i
< node
.subElements
.size (); i
++ )
309 ProcessXMLSubElement ( *node
.subElements
[i
] );
313 Invoke::ProcessXMLSubElement ( const XMLElement
& e
)
315 bool subs_invalid
= false;
316 if ( e
.name
== "input" )
318 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
319 ProcessXMLSubElementInput ( *e
.subElements
[i
] );
321 else if ( e
.name
== "output" )
323 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
324 ProcessXMLSubElementOutput ( *e
.subElements
[i
] );
326 if ( subs_invalid
&& e
.subElements
.size() > 0 )
327 throw InvalidBuildFileException ( e
.location
,
328 "<%s> cannot have sub-elements",
333 Invoke::ProcessXMLSubElementInput ( const XMLElement
& e
)
335 bool subs_invalid
= false;
336 if ( e
.name
== "inputfile" && e
.value
.size () > 0 )
338 input
.push_back ( new InvokeFile ( e
, FixSeparator ( module
.path
+ CSEP
+ e
.value
) ) );
341 if ( subs_invalid
&& e
.subElements
.size() > 0 )
342 throw InvalidBuildFileException ( e
.location
,
343 "<%s> cannot have sub-elements",
348 Invoke::ProcessXMLSubElementOutput ( const XMLElement
& e
)
350 bool subs_invalid
= false;
351 if ( e
.name
== "outputfile" && e
.value
.size () > 0 )
353 output
.push_back ( new InvokeFile ( e
, FixSeparator ( module
.path
+ CSEP
+ e
.value
) ) );
356 if ( subs_invalid
&& e
.subElements
.size() > 0 )
357 throw InvalidBuildFileException ( e
.location
,
358 "<%s> cannot have sub-elements",
363 Invoke::GetTargets () const
365 string
targets ( "" );
366 for ( size_t i
= 0; i
< output
.size (); i
++ )
368 InvokeFile
& file
= *output
[i
];
369 if ( targets
.length () > 0 )
371 targets
+= file
.name
;
377 InvokeFile::InvokeFile ( const XMLElement
& _node
,
378 const string
& _name
)
382 const XMLAttribute
* att
= _node
.GetAttribute ( "switches", false );
384 switches
= att
->value
;
390 InvokeFile::ProcessXML()
395 Dependency::Dependency ( const XMLElement
& _node
,
396 const Module
& _module
)
399 dependencyModule (NULL
)
404 Dependency::ProcessXML()
406 dependencyModule
= module
.project
.LocateModule ( node
.value
);
407 if ( dependencyModule
== NULL
)
408 throw InvalidBuildFileException ( node
.location
,
409 "module '%s' depend on non-existant module '%s'",
411 node
.value
.c_str() );
415 ImportLibrary::ImportLibrary ( const XMLElement
& _node
,
416 const Module
& _module
)
420 const XMLAttribute
* att
= _node
.GetAttribute ( "basename", false );
422 basename
= att
->value
;
424 basename
= module
.name
;
426 att
= _node
.GetAttribute ( "definition", true );
428 definition
= att
->value
;