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 throw InvalidAttributeValueException ( location
,
161 Module::GetDefaultModuleExtension () const
174 throw InvalidOperationException (__FILE__
,
179 Module::GetTargetName () const
181 return name
+ extension
;
185 Module::GetDependencyPath () const
187 if ( type
== KernelModeDLL
)
188 return ssprintf ( "dk%snkm%slib%slib%s.a",
198 Module::GetBasePath () const
204 Module::GetPath () const
206 return path
+ CSEP
+ GetTargetName ();
210 Module::GetPathWithPrefix ( const string
& prefix
) const
212 return path
+ CSEP
+ prefix
+ GetTargetName ();
216 Module::GetTargets () const
218 if ( invocations
.size () > 0 )
220 string
targets ( "" );
221 for ( size_t i
= 0; i
< invocations
.size (); i
++ )
223 Invoke
& invoke
= *invocations
[i
];
224 if ( targets
.length () > 0 )
226 targets
+= invoke
.GetTargets ();
235 Module::GetInvocationTarget ( const int index
) const
237 return ssprintf ( "%s_invoke_%d",
243 File::File ( const string
& _name
)
254 Library::Library ( const XMLElement
& _node
,
255 const Module
& _module
,
256 const string
& _name
)
261 if ( module
.name
== name
)
262 throw InvalidBuildFileException (
264 "module '%s' cannot link against itself",
269 Library::ProcessXML()
271 if ( !module
.project
.LocateModule ( name
) )
272 throw InvalidBuildFileException (
274 "module '%s' is trying to link against non-existant module '%s'",
280 Invoke::Invoke ( const XMLElement
& _node
,
281 const Module
& _module
)
290 const XMLAttribute
* att
= node
.GetAttribute ( "module", false );
292 invokeModule
= &module
;
295 invokeModule
= module
.project
.LocateModule ( att
->value
);
296 if ( invokeModule
== NULL
)
297 throw InvalidBuildFileException (
299 "module '%s' is trying to invoke non-existant module '%s'",
301 att
->value
.c_str() );
304 for ( size_t i
= 0; i
< node
.subElements
.size (); i
++ )
305 ProcessXMLSubElement ( *node
.subElements
[i
] );
309 Invoke::ProcessXMLSubElement ( const XMLElement
& e
)
311 bool subs_invalid
= false;
312 if ( e
.name
== "input" )
314 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
315 ProcessXMLSubElementInput ( *e
.subElements
[i
] );
317 else if ( e
.name
== "output" )
319 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
320 ProcessXMLSubElementOutput ( *e
.subElements
[i
] );
322 if ( subs_invalid
&& e
.subElements
.size() > 0 )
323 throw InvalidBuildFileException ( e
.location
,
324 "<%s> cannot have sub-elements",
329 Invoke::ProcessXMLSubElementInput ( const XMLElement
& e
)
331 bool subs_invalid
= false;
332 if ( e
.name
== "inputfile" && e
.value
.size () > 0 )
334 input
.push_back ( new InvokeFile ( e
, FixSeparator ( module
.path
+ CSEP
+ e
.value
) ) );
337 if ( subs_invalid
&& e
.subElements
.size() > 0 )
338 throw InvalidBuildFileException ( e
.location
,
339 "<%s> cannot have sub-elements",
344 Invoke::ProcessXMLSubElementOutput ( const XMLElement
& e
)
346 bool subs_invalid
= false;
347 if ( e
.name
== "outputfile" && e
.value
.size () > 0 )
349 output
.push_back ( new InvokeFile ( e
, FixSeparator ( module
.path
+ CSEP
+ e
.value
) ) );
352 if ( subs_invalid
&& e
.subElements
.size() > 0 )
353 throw InvalidBuildFileException ( e
.location
,
354 "<%s> cannot have sub-elements",
359 Invoke::GetTargets () const
361 string
targets ( "" );
362 for ( size_t i
= 0; i
< output
.size (); i
++ )
364 InvokeFile
& file
= *output
[i
];
365 if ( targets
.length () > 0 )
367 targets
+= file
.name
;
373 InvokeFile::InvokeFile ( const XMLElement
& _node
,
374 const string
& _name
)
378 const XMLAttribute
* att
= _node
.GetAttribute ( "switches", false );
380 switches
= att
->value
;
386 InvokeFile::ProcessXML()
391 Dependency::Dependency ( const XMLElement
& _node
,
392 const Module
& _module
)
395 dependencyModule (NULL
)
400 Dependency::ProcessXML()
402 dependencyModule
= module
.project
.LocateModule ( node
.value
);
403 if ( dependencyModule
== NULL
)
404 throw InvalidBuildFileException ( node
.location
,
405 "module '%s' depend on non-existant module '%s'",
407 node
.value
.c_str() );
411 ImportLibrary::ImportLibrary ( const XMLElement
& _node
,
412 const Module
& _module
)
416 const XMLAttribute
* att
= _node
.GetAttribute ( "basename", false );
418 basename
= att
->value
;
420 basename
= module
.name
;
422 att
= _node
.GetAttribute ( "definition", true );
424 definition
= att
->value
;