2 * Copyright (C) 2005 Casper S. Hornstrup
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 Right ( const string
& s
, size_t n
)
31 return string ( &s
[s
.size()-n
] );
35 Replace ( const string
& s
, const string
& find
, const string
& with
)
38 const char* p
= s
.c_str();
41 const char* p2
= strstr ( p
, find
.c_str() );
45 ret
+= string ( p
, p2
-p
);
55 ChangeSeparator ( const string
& s
,
56 const char fromSeparator
,
57 const char toSeparator
)
60 char* p
= strchr ( &s2
[0], fromSeparator
);
64 p
= strchr ( p
, fromSeparator
);
70 FixSeparator ( const string
& s
)
72 return ChangeSeparator ( s
, cBadSep
, cSep
);
76 FixSeparatorForSystemCommand ( const string
& s
)
79 char* p
= strchr ( &s2
[0], DEF_CBAD_SEP
);
83 p
= strchr ( p
, DEF_CBAD_SEP
);
89 DosSeparator ( const string
& s
)
92 char* p
= strchr ( &s2
[0], '/' );
96 p
= strchr ( p
, '/' );
103 const string
& filename
,
104 const string
& newExtension
)
106 size_t index
= filename
.find_last_of ( '/' );
107 if ( index
== string::npos
)
109 size_t index2
= filename
.find_last_of ( '\\' );
110 if ( index2
!= string::npos
&& index2
> index
)
112 string tmp
= filename
.substr( index
/*, filename.size() - index*/ );
113 size_t ext_index
= tmp
.find_last_of( '.' );
114 if ( ext_index
!= string::npos
)
115 return filename
.substr ( 0, index
+ ext_index
) + newExtension
;
116 return filename
+ newExtension
;
121 const string
& location
,
123 const string
& att_value
)
125 if ( !att_value
.size() )
126 throw XMLInvalidBuildFileException (
128 "<directory> tag has empty 'name' attribute" );
129 if ( strpbrk ( att_value
.c_str (), "/\\?*:<>|" ) )
130 throw XMLInvalidBuildFileException (
132 "<directory> tag has invalid characters in 'name' attribute" );
135 return FixSeparator(path
+ cSep
+ att_value
);
139 GetExtension ( const string
& filename
)
141 size_t index
= filename
.find_last_of ( '/' );
142 if (index
== string::npos
) index
= 0;
143 string tmp
= filename
.substr( index
, filename
.size() - index
);
144 size_t ext_index
= tmp
.find_last_of( '.' );
145 if (ext_index
!= string::npos
)
146 return filename
.substr ( index
+ ext_index
, filename
.size() );
151 GetDirectory ( const string
& filename
)
153 size_t index
= filename
.find_last_of ( cSep
);
154 if ( index
== string::npos
)
157 return filename
.substr ( 0, index
);
161 GetFilename ( const string
& filename
)
163 size_t index
= filename
.find_last_of ( cSep
);
164 if ( index
== string::npos
)
167 return filename
.substr ( index
+ 1, filename
.length () - index
);
171 NormalizeFilename ( const string
& filename
)
173 if ( filename
== "" )
176 string normalizedPath
= path
.Fixup ( filename
, true );
177 string relativeNormalizedPath
= path
.RelativeFromWorkingDirectory ( normalizedPath
);
178 return FixSeparator ( relativeNormalizedPath
);
182 GetBooleanValue ( const string
& value
)
191 ToLower ( string filename
)
193 for ( size_t i
= 1; i
< filename
.length (); i
++ )
194 filename
[i
] = tolower ( filename
[i
] );
198 void IfableData::ExtractModules( std::vector
<Module
*> &modules
)
201 for ( i
= 0; i
< this->modules
.size (); i
++ )
202 modules
.push_back(this->modules
[i
]);
205 IfableData::~IfableData()
208 for ( i
= 0; i
< includes
.size (); i
++ )
210 for ( i
= 0; i
< defines
.size (); i
++ )
212 for ( i
= 0; i
< libraries
.size (); i
++ )
214 for ( i
= 0; i
< properties
.size (); i
++ )
215 delete properties
[i
];
216 for ( i
= 0; i
< compilerFlags
.size (); i
++ )
217 delete compilerFlags
[i
];
218 for ( i
= 0; i
< modules
.size(); i
++ )
220 for ( i
= 0; i
< ifs
.size (); i
++ )
222 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
223 delete compilationUnits
[i
];
226 void IfableData::ProcessXML ()
229 for ( i
= 0; i
< includes
.size (); i
++ )
230 includes
[i
]->ProcessXML ();
231 for ( i
= 0; i
< defines
.size (); i
++ )
232 defines
[i
]->ProcessXML ();
233 for ( i
= 0; i
< libraries
.size (); i
++ )
234 libraries
[i
]->ProcessXML ();
235 for ( i
= 0; i
< properties
.size(); i
++ )
236 properties
[i
]->ProcessXML ();
237 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
238 compilerFlags
[i
]->ProcessXML ();
239 for ( i
= 0; i
< ifs
.size (); i
++ )
240 ifs
[i
]->ProcessXML ();
241 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
242 compilationUnits
[i
]->ProcessXML ();
245 Module::Module ( const Project
& project
,
246 const XMLElement
& moduleNode
,
247 const string
& modulePath
)
250 importLibrary (NULL
),
258 if ( node
.name
!= "module" )
259 throw InvalidOperationException ( __FILE__
,
261 "Module created with non-<module> node" );
263 xmlbuildFile
= Path::RelativeFromWorkingDirectory ( moduleNode
.xmlFile
->filename () );
265 path
= FixSeparator ( modulePath
);
269 const XMLAttribute
* att
= moduleNode
.GetAttribute ( "if", false );
271 enabled
= GetBooleanValue ( project
.ResolveProperties ( att
->value
) );
273 att
= moduleNode
.GetAttribute ( "ifnot", false );
275 enabled
= !GetBooleanValue ( project
.ResolveProperties ( att
->value
) );
277 att
= moduleNode
.GetAttribute ( "name", true );
281 att
= moduleNode
.GetAttribute ( "type", true );
283 type
= GetModuleType ( node
.location
, *att
);
285 att
= moduleNode
.GetAttribute ( "extension", false );
287 extension
= att
->value
;
289 extension
= GetDefaultModuleExtension ();
291 att
= moduleNode
.GetAttribute ( "unicode", false );
294 const char* p
= att
->value
.c_str();
295 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
297 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
301 throw InvalidAttributeValueException (
310 att
= moduleNode
.GetAttribute ( "entrypoint", false );
312 entrypoint
= att
->value
;
314 entrypoint
= GetDefaultModuleEntrypoint ();
316 att
= moduleNode
.GetAttribute ( "baseaddress", false );
318 baseaddress
= att
->value
;
320 baseaddress
= GetDefaultModuleBaseaddress ();
322 att
= moduleNode
.GetAttribute ( "mangledsymbols", false );
325 const char* p
= att
->value
.c_str();
326 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
327 mangledSymbols
= true;
328 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
329 mangledSymbols
= false;
332 throw InvalidAttributeValueException (
339 mangledSymbols
= false;
341 att
= moduleNode
.GetAttribute ( "host", false );
344 const char* p
= att
->value
.c_str();
345 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
347 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
351 throw InvalidAttributeValueException (
358 att
= moduleNode
.GetAttribute ( "prefix", false );
362 att
= moduleNode
.GetAttribute ( "installbase", false );
364 installBase
= att
->value
;
368 att
= moduleNode
.GetAttribute ( "installname", false );
370 installName
= att
->value
;
374 att
= moduleNode
.GetAttribute ( "usewrc", false );
376 useWRC
= att
->value
== "true";
380 att
= moduleNode
.GetAttribute ( "allowwarnings", false );
383 att
= moduleNode
.GetAttribute ( "warnings", false );
386 printf ( "%s: WARNING: 'warnings' attribute of <module> is deprecated, use 'allowwarnings' instead\n",
387 moduleNode
.location
.c_str() );
391 allowWarnings
= att
->value
== "true";
393 allowWarnings
= false;
395 att
= moduleNode
.GetAttribute ( "aliasof", false );
396 if ( type
== Alias
&& att
!= NULL
)
397 aliasedModuleName
= att
->value
;
399 aliasedModuleName
= "";
401 if ( type
== BootProgram
)
403 att
= moduleNode
.GetAttribute ( "payload", true );
404 payload
= att
->value
;
411 for ( i
= 0; i
< invocations
.size(); i
++ )
412 delete invocations
[i
];
413 for ( i
= 0; i
< dependencies
.size(); i
++ )
414 delete dependencies
[i
];
415 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
416 delete compilerFlags
[i
];
417 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
418 delete linkerFlags
[i
];
419 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
420 delete stubbedComponents
[i
];
432 if ( aliasedModuleName
== name
)
434 throw XMLInvalidBuildFileException (
436 "module '%s' cannot link against itself",
439 const Module
* m
= project
.LocateModule ( aliasedModuleName
);
442 throw XMLInvalidBuildFileException (
444 "module '%s' trying to alias non-existant module '%s'",
446 aliasedModuleName
.c_str() );
451 for ( i
= 0; i
< node
.subElements
.size(); i
++ )
453 ParseContext parseContext
;
454 ProcessXMLSubElement ( *node
.subElements
[i
], path
, parseContext
);
456 for ( i
= 0; i
< invocations
.size(); i
++ )
457 invocations
[i
]->ProcessXML ();
458 for ( i
= 0; i
< dependencies
.size(); i
++ )
459 dependencies
[i
]->ProcessXML ();
460 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
461 compilerFlags
[i
]->ProcessXML();
462 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
463 linkerFlags
[i
]->ProcessXML();
464 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
465 stubbedComponents
[i
]->ProcessXML();
466 non_if_data
.ProcessXML();
468 linkerScript
->ProcessXML();
472 autoRegister
->ProcessXML();
476 Module::ProcessXMLSubElement ( const XMLElement
& e
,
478 ParseContext
& parseContext
)
480 If
* pOldIf
= parseContext
.ifData
;
481 CompilationUnit
* pOldCompilationUnit
= parseContext
.compilationUnit
;
482 bool subs_invalid
= false;
483 string
subpath ( path
);
484 if ( e
.name
== "file" && e
.value
.size () > 0 )
487 const XMLAttribute
* att
= e
.GetAttribute ( "first", false );
490 if ( !stricmp ( att
->value
.c_str(), "true" ) )
492 else if ( stricmp ( att
->value
.c_str(), "false" ) )
494 throw XMLInvalidBuildFileException (
496 "attribute 'first' of <file> element can only be 'true' or 'false'" );
499 string switches
= "";
500 att
= e
.GetAttribute ( "switches", false );
502 switches
= att
->value
;
505 // check for c++ file
506 string ext
= GetExtension ( e
.value
);
507 if ( !stricmp ( ext
.c_str(), ".cpp" ) )
509 else if ( !stricmp ( ext
.c_str(), ".cc" ) )
511 else if ( !stricmp ( ext
.c_str(), ".cxx" ) )
514 File
* pFile
= new File ( FixSeparator ( path
+ cSep
+ e
.value
),
518 if ( parseContext
.compilationUnit
)
519 parseContext
.compilationUnit
->files
.push_back ( pFile
);
522 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( pFile
);
523 if ( parseContext
.ifData
)
524 parseContext
.ifData
->data
.compilationUnits
.push_back ( pCompilationUnit
);
526 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
528 if ( parseContext
.ifData
)
529 parseContext
.ifData
->data
.files
.push_back ( pFile
);
531 non_if_data
.files
.push_back ( pFile
);
534 else if ( e
.name
== "library" && e
.value
.size () )
536 Library
* pLibrary
= new Library ( e
, *this, e
.value
);
537 if ( parseContext
.ifData
)
538 parseContext
.ifData
->data
.libraries
.push_back ( pLibrary
);
540 non_if_data
.libraries
.push_back ( pLibrary
);
543 else if ( e
.name
== "directory" )
545 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
547 subpath
= GetSubPath ( e
.location
, path
, att
->value
);
549 else if ( e
.name
== "include" )
551 Include
* include
= new Include ( project
, this, &e
);
552 if ( parseContext
.ifData
)
553 parseContext
.ifData
->data
.includes
.push_back ( include
);
555 non_if_data
.includes
.push_back ( include
);
558 else if ( e
.name
== "define" )
560 Define
* pDefine
= new Define ( project
, this, e
);
561 if ( parseContext
.ifData
)
562 parseContext
.ifData
->data
.defines
.push_back ( pDefine
);
564 non_if_data
.defines
.push_back ( pDefine
);
567 else if ( e
.name
== "invoke" )
569 if ( parseContext
.ifData
)
571 throw XMLInvalidBuildFileException (
573 "<invoke> is not a valid sub-element of <if>" );
575 invocations
.push_back ( new Invoke ( e
, *this ) );
576 subs_invalid
= false;
578 else if ( e
.name
== "dependency" )
580 if ( parseContext
.ifData
)
582 throw XMLInvalidBuildFileException (
584 "<dependency> is not a valid sub-element of <if>" );
586 dependencies
.push_back ( new Dependency ( e
, *this ) );
589 else if ( e
.name
== "importlibrary" )
591 if ( parseContext
.ifData
)
593 throw XMLInvalidBuildFileException (
595 "<importlibrary> is not a valid sub-element of <if>" );
599 throw XMLInvalidBuildFileException (
601 "Only one <importlibrary> is valid per module" );
603 importLibrary
= new ImportLibrary ( e
, *this );
606 else if ( e
.name
== "if" )
608 parseContext
.ifData
= new If ( e
, project
, this );
610 pOldIf
->data
.ifs
.push_back ( parseContext
.ifData
);
612 non_if_data
.ifs
.push_back ( parseContext
.ifData
);
613 subs_invalid
= false;
615 else if ( e
.name
== "ifnot" )
617 parseContext
.ifData
= new If ( e
, project
, this, true );
619 pOldIf
->data
.ifs
.push_back ( parseContext
.ifData
);
621 non_if_data
.ifs
.push_back ( parseContext
.ifData
);
622 subs_invalid
= false;
624 else if ( e
.name
== "compilerflag" )
626 CompilerFlag
* pCompilerFlag
= new CompilerFlag ( project
, this, e
);
627 if ( parseContext
.ifData
)
628 parseContext
.ifData
->data
.compilerFlags
.push_back ( pCompilerFlag
);
630 non_if_data
.compilerFlags
.push_back ( pCompilerFlag
);
633 else if ( e
.name
== "linkerflag" )
635 linkerFlags
.push_back ( new LinkerFlag ( project
, this, e
) );
638 else if ( e
.name
== "linkerscript" )
642 throw XMLInvalidBuildFileException (
644 "Only one <linkerscript> is valid per module" );
646 linkerScript
= new LinkerScript ( project
, this, e
);
649 else if ( e
.name
== "component" )
651 stubbedComponents
.push_back ( new StubbedComponent ( this, e
) );
652 subs_invalid
= false;
654 else if ( e
.name
== "property" )
656 throw XMLInvalidBuildFileException (
658 "<property> is not a valid sub-element of <module>" );
660 else if ( e
.name
== "bootstrap" )
662 bootstrap
= new Bootstrap ( project
, this, e
);
665 else if ( e
.name
== "pch" )
667 if ( parseContext
.ifData
)
669 throw XMLInvalidBuildFileException (
671 "<pch> is not a valid sub-element of <if>" );
675 throw XMLInvalidBuildFileException (
677 "Only one <pch> is valid per module" );
680 e
, *this, File ( FixSeparator ( path
+ cSep
+ e
.value
), false, "", true ) );
683 else if ( e
.name
== "compilationunit" )
685 if ( project
.configuration
.CompilationUnitsEnabled
)
687 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( &project
, this, &e
);
688 if ( parseContext
.ifData
)
689 parseContext
.ifData
->data
.compilationUnits
.push_back ( pCompilationUnit
);
691 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
692 parseContext
.compilationUnit
= pCompilationUnit
;
694 subs_invalid
= false;
696 else if ( e
.name
== "autoregister" )
698 if ( autoRegister
!= NULL
)
700 throw XMLInvalidBuildFileException (
702 "there can be only one <%s> element for a module",
705 autoRegister
= new AutoRegister ( project
, this, e
);
708 if ( subs_invalid
&& e
.subElements
.size() > 0 )
710 throw XMLInvalidBuildFileException (
712 "<%s> cannot have sub-elements",
715 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
716 ProcessXMLSubElement ( *e
.subElements
[i
], subpath
, parseContext
);
717 parseContext
.ifData
= pOldIf
;
718 parseContext
.compilationUnit
= pOldCompilationUnit
;
722 Module::GetModuleType ( const string
& location
, const XMLAttribute
& attribute
)
724 if ( attribute
.value
== "buildtool" )
726 if ( attribute
.value
== "staticlibrary" )
727 return StaticLibrary
;
728 if ( attribute
.value
== "objectlibrary" )
729 return ObjectLibrary
;
730 if ( attribute
.value
== "kernel" )
732 if ( attribute
.value
== "kernelmodedll" )
733 return KernelModeDLL
;
734 if ( attribute
.value
== "kernelmodedriver" )
735 return KernelModeDriver
;
736 if ( attribute
.value
== "nativedll" )
738 if ( attribute
.value
== "nativecui" )
740 if ( attribute
.value
== "win32dll" )
742 if ( attribute
.value
== "win32cui" )
744 if ( attribute
.value
== "win32gui" )
746 if ( attribute
.value
== "win32scr" )
748 if ( attribute
.value
== "bootloader" )
750 if ( attribute
.value
== "bootsector" )
752 if ( attribute
.value
== "bootprogram" )
754 if ( attribute
.value
== "iso" )
756 if ( attribute
.value
== "liveiso" )
758 if ( attribute
.value
== "test" )
760 if ( attribute
.value
== "rpcserver" )
762 if ( attribute
.value
== "rpcclient" )
764 if ( attribute
.value
== "alias" )
766 throw InvalidAttributeValueException ( location
,
772 Module::GetDefaultModuleExtension () const
794 case KernelModeDriver
:
813 throw InvalidOperationException ( __FILE__
,
818 Module::GetDefaultModuleEntrypoint () const
823 return "_NtProcessStartup";
825 return "_DriverEntry@8";
827 return "_DllMainCRTStartup@12";
829 return "_NtProcessStartup@4";
831 return "_DllMain@12";
835 return "_wmainCRTStartup";
837 return "_mainCRTStartup";
841 return "_wWinMainCRTStartup";
843 return "_WinMainCRTStartup";
844 case KernelModeDriver
:
845 return "_DriverEntry@8";
859 throw InvalidOperationException ( __FILE__
,
864 Module::GetDefaultModuleBaseaddress () const
881 case KernelModeDriver
:
896 throw InvalidOperationException ( __FILE__
,
901 Module::HasImportLibrary () const
903 return importLibrary
!= NULL
;
907 Module::IsDLL () const
915 case KernelModeDriver
:
935 throw InvalidOperationException ( __FILE__
,
940 Module::GenerateInOutputTree () const
948 case KernelModeDriver
:
968 throw InvalidOperationException ( __FILE__
,
973 Module::GetTargetName () const
975 return name
+ extension
;
979 Module::GetDependencyPath () const
981 if ( HasImportLibrary () )
982 return ReplaceExtension ( GetPathWithPrefix ( "lib" ), ".a" );
988 Module::GetBasePath () const
994 Module::GetPath () const
996 if ( path
.length() > 0 )
997 return path
+ cSep
+ GetTargetName ();
999 return GetTargetName ();
1003 Module::GetPathWithPrefix ( const string
& prefix
) const
1005 return path
+ cSep
+ prefix
+ GetTargetName ();
1009 Module::GetPathToBaseDir () const
1011 string temp_path
= path
;
1012 string result
= "..\\";
1013 while(temp_path
.find ('\\') != string::npos
)
1015 temp_path
.erase (0, temp_path
.find('\\')+1);
1022 Module::GetInvocationTarget ( const int index
) const
1024 return ssprintf ( "%s_invoke_%d",
1030 Module::HasFileWithExtension (
1031 const IfableData
& data
,
1032 const std::string
& extension
) const
1035 for ( i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1037 CompilationUnit
* compilationUnit
= data
.compilationUnits
[i
];
1038 if ( compilationUnit
->HasFileWithExtension ( extension
) )
1041 for ( i
= 0; i
< data
.ifs
.size (); i
++ )
1043 if ( HasFileWithExtension ( data
.ifs
[i
]->data
, extension
) )
1050 Module::InvokeModule () const
1052 for ( size_t i
= 0; i
< invocations
.size (); i
++ )
1054 Invoke
& invoke
= *invocations
[i
];
1055 string command
= FixSeparatorForSystemCommand(invoke
.invokeModule
->GetPath ()) + " " + invoke
.GetParameters ();
1056 printf ( "Executing '%s'\n\n", command
.c_str () );
1057 int exitcode
= system ( command
.c_str () );
1058 if ( exitcode
!= 0 )
1059 throw InvocationFailedException ( command
,
1065 File::File ( const string
& _name
, bool _first
,
1066 std::string _switches
,
1067 bool _isPreCompiledHeader
)
1070 switches(_switches
),
1071 isPreCompiledHeader(_isPreCompiledHeader
)
1081 Library::Library ( const XMLElement
& _node
,
1082 const Module
& _module
,
1083 const string
& _name
)
1087 importedModule(_module
.project
.LocateModule(_name
))
1089 if ( module
.name
== name
)
1091 throw XMLInvalidBuildFileException (
1093 "module '%s' cannot link against itself",
1096 if ( !importedModule
)
1098 throw XMLInvalidBuildFileException (
1100 "module '%s' trying to import non-existant module '%s'",
1101 module
.name
.c_str(),
1107 Library::ProcessXML()
1109 if ( !module
.project
.LocateModule ( name
) )
1111 throw XMLInvalidBuildFileException (
1113 "module '%s' is trying to link against non-existant module '%s'",
1114 module
.name
.c_str(),
1120 Invoke::Invoke ( const XMLElement
& _node
,
1121 const Module
& _module
)
1128 Invoke::ProcessXML()
1130 const XMLAttribute
* att
= node
.GetAttribute ( "module", false );
1132 invokeModule
= &module
;
1135 invokeModule
= module
.project
.LocateModule ( att
->value
);
1136 if ( invokeModule
== NULL
)
1138 throw XMLInvalidBuildFileException (
1140 "module '%s' is trying to invoke non-existant module '%s'",
1141 module
.name
.c_str(),
1142 att
->value
.c_str() );
1146 for ( size_t i
= 0; i
< node
.subElements
.size (); i
++ )
1147 ProcessXMLSubElement ( *node
.subElements
[i
] );
1151 Invoke::ProcessXMLSubElement ( const XMLElement
& e
)
1153 bool subs_invalid
= false;
1154 if ( e
.name
== "input" )
1156 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1157 ProcessXMLSubElementInput ( *e
.subElements
[i
] );
1159 else if ( e
.name
== "output" )
1161 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1162 ProcessXMLSubElementOutput ( *e
.subElements
[i
] );
1164 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1166 throw XMLInvalidBuildFileException (
1168 "<%s> cannot have sub-elements",
1174 Invoke::ProcessXMLSubElementInput ( const XMLElement
& e
)
1176 bool subs_invalid
= false;
1177 if ( e
.name
== "inputfile" && e
.value
.size () > 0 )
1179 input
.push_back ( new InvokeFile (
1180 e
, FixSeparator ( module
.path
+ cSep
+ e
.value
) ) );
1181 subs_invalid
= true;
1183 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1185 throw XMLInvalidBuildFileException (
1187 "<%s> cannot have sub-elements",
1193 Invoke::ProcessXMLSubElementOutput ( const XMLElement
& e
)
1195 bool subs_invalid
= false;
1196 if ( e
.name
== "outputfile" && e
.value
.size () > 0 )
1198 output
.push_back ( new InvokeFile (
1199 e
, FixSeparator ( module
.path
+ cSep
+ e
.value
) ) );
1200 subs_invalid
= true;
1202 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1204 throw XMLInvalidBuildFileException (
1206 "<%s> cannot have sub-elements",
1212 Invoke::GetTargets ( string_list
& targets
) const
1214 for ( size_t i
= 0; i
< output
.size (); i
++ )
1216 InvokeFile
& file
= *output
[i
];
1217 targets
.push_back ( NormalizeFilename ( file
.name
) );
1222 Invoke::GetParameters () const
1224 string
parameters ( "" );
1226 for ( i
= 0; i
< output
.size (); i
++ )
1228 if ( parameters
.length () > 0)
1230 InvokeFile
& invokeFile
= *output
[i
];
1231 if ( invokeFile
.switches
.length () > 0 )
1233 parameters
+= invokeFile
.switches
+ " ";
1235 parameters
+= invokeFile
.name
;
1238 for ( i
= 0; i
< input
.size (); i
++ )
1240 if ( parameters
.length () > 0 )
1242 InvokeFile
& invokeFile
= *input
[i
];
1243 if ( invokeFile
.switches
.length () > 0 )
1245 parameters
+= invokeFile
.switches
;
1248 parameters
+= invokeFile
.name
;
1255 InvokeFile::InvokeFile ( const XMLElement
& _node
,
1256 const string
& _name
)
1260 const XMLAttribute
* att
= _node
.GetAttribute ( "switches", false );
1262 switches
= att
->value
;
1268 InvokeFile::ProcessXML()
1273 Dependency::Dependency ( const XMLElement
& _node
,
1274 const Module
& _module
)
1277 dependencyModule (NULL
)
1282 Dependency::ProcessXML()
1284 dependencyModule
= module
.project
.LocateModule ( node
.value
);
1285 if ( dependencyModule
== NULL
)
1287 throw XMLInvalidBuildFileException (
1289 "module '%s' depend on non-existant module '%s'",
1290 module
.name
.c_str(),
1291 node
.value
.c_str() );
1296 ImportLibrary::ImportLibrary ( const XMLElement
& _node
,
1297 const Module
& _module
)
1301 const XMLAttribute
* att
= _node
.GetAttribute ( "basename", false );
1303 basename
= att
->value
;
1305 basename
= module
.name
;
1307 att
= _node
.GetAttribute ( "definition", true );
1309 definition
= FixSeparator(att
->value
);
1313 If::If ( const XMLElement
& node_
,
1314 const Project
& project_
,
1315 const Module
* module_
,
1316 const bool negated_
)
1317 : node(node_
), project(project_
), module(module_
), negated(negated_
)
1319 const XMLAttribute
* att
;
1321 att
= node
.GetAttribute ( "property", true );
1323 property
= att
->value
;
1325 att
= node
.GetAttribute ( "value", true );
1341 Property::Property ( const XMLElement
& node_
,
1342 const Project
& project_
,
1343 const Module
* module_
)
1344 : node(node_
), project(project_
), module(module_
)
1346 const XMLAttribute
* att
;
1348 att
= node
.GetAttribute ( "name", true );
1352 att
= node
.GetAttribute ( "value", true );
1358 Property::ProcessXML()
1364 const XMLElement
& node_
,
1365 const Module
& module_
,
1367 : node(node_
), module(module_
), file(file_
)
1372 PchFile::ProcessXML()
1377 AutoRegister::AutoRegister ( const Project
& project_
,
1378 const Module
* module_
,
1379 const XMLElement
& node_
)
1380 : project(project_
),
1387 AutoRegister::~AutoRegister ()
1392 AutoRegister::IsSupportedModuleType ( ModuleType type
)
1405 case KernelModeDriver
:
1420 throw InvalidOperationException ( __FILE__
,
1425 AutoRegister::GetAutoRegisterType( string type
)
1427 if ( type
== "DllRegisterServer" )
1428 return DllRegisterServer
;
1429 if ( type
== "DllInstall" )
1431 if ( type
== "Both" )
1433 throw XMLInvalidBuildFileException (
1435 "<autoregister> type attribute must be DllRegisterServer, DllInstall or Both." );
1439 AutoRegister::Initialize ()
1441 if ( !IsSupportedModuleType ( module
->type
) )
1443 throw XMLInvalidBuildFileException (
1445 "<autoregister> is not applicable for this module type." );
1448 const XMLAttribute
* att
= node
.GetAttribute ( "infsection", true );
1449 infSection
= att
->value
;
1451 att
= node
.GetAttribute ( "type", true );
1452 type
= GetAutoRegisterType ( att
->value
);
1456 AutoRegister::ProcessXML()