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 ( "stdlib", false );
313 const char* p
= att
->value
.c_str();
314 if ( !stricmp ( p
, "host" ) )
315 useHostStdlib
= true;
316 else if ( !stricmp ( p
, "default" ) )
317 useHostStdlib
= false;
320 throw InvalidAttributeValueException (
327 useHostStdlib
= false;
331 // Always define UNICODE and _UNICODE
332 Define
* pDefine
= new Define ( project
, this, "UNICODE" );
333 non_if_data
.defines
.push_back ( pDefine
);
335 pDefine
= new Define ( project
, this, "_UNICODE" );
336 non_if_data
.defines
.push_back ( pDefine
);
339 att
= moduleNode
.GetAttribute ( "entrypoint", false );
342 entrypoint
= att
->value
;
343 isDefaultEntryPoint
= false;
347 entrypoint
= GetDefaultModuleEntrypoint ();
348 isDefaultEntryPoint
= true;
351 att
= moduleNode
.GetAttribute ( "baseaddress", false );
353 baseaddress
= att
->value
;
355 baseaddress
= GetDefaultModuleBaseaddress ();
357 att
= moduleNode
.GetAttribute ( "mangledsymbols", false );
360 const char* p
= att
->value
.c_str();
361 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
362 mangledSymbols
= true;
363 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
364 mangledSymbols
= false;
367 throw InvalidAttributeValueException (
374 mangledSymbols
= false;
376 att
= moduleNode
.GetAttribute ( "host", false );
379 const char* p
= att
->value
.c_str();
380 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
382 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
386 throw InvalidAttributeValueException (
393 att
= moduleNode
.GetAttribute ( "isstartuplib", false );
396 const char* p
= att
->value
.c_str();
397 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
399 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
400 isStartupLib
= false;
403 throw InvalidAttributeValueException (
410 isStartupLib
= false;
412 att
= moduleNode
.GetAttribute ( "prefix", false );
416 att
= moduleNode
.GetAttribute ( "installbase", false );
418 installBase
= att
->value
;
422 att
= moduleNode
.GetAttribute ( "installname", false );
424 installName
= att
->value
;
428 att
= moduleNode
.GetAttribute ( "usewrc", false );
430 useWRC
= att
->value
== "true";
434 att
= moduleNode
.GetAttribute ( "allowwarnings", false );
437 att
= moduleNode
.GetAttribute ( "warnings", false );
440 printf ( "%s: WARNING: 'warnings' attribute of <module> is deprecated, use 'allowwarnings' instead\n",
441 moduleNode
.location
.c_str() );
445 allowWarnings
= att
->value
== "true";
447 allowWarnings
= false;
449 att
= moduleNode
.GetAttribute ( "aliasof", false );
450 if ( type
== Alias
&& att
!= NULL
)
451 aliasedModuleName
= att
->value
;
453 aliasedModuleName
= "";
455 if ( type
== BootProgram
)
457 att
= moduleNode
.GetAttribute ( "payload", true );
458 payload
= att
->value
;
465 for ( i
= 0; i
< invocations
.size(); i
++ )
466 delete invocations
[i
];
467 for ( i
= 0; i
< dependencies
.size(); i
++ )
468 delete dependencies
[i
];
469 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
470 delete compilerFlags
[i
];
471 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
472 delete linkerFlags
[i
];
473 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
474 delete stubbedComponents
[i
];
486 if ( aliasedModuleName
== name
)
488 throw XMLInvalidBuildFileException (
490 "module '%s' cannot link against itself",
493 const Module
* m
= project
.LocateModule ( aliasedModuleName
);
496 throw XMLInvalidBuildFileException (
498 "module '%s' trying to alias non-existant module '%s'",
500 aliasedModuleName
.c_str() );
505 for ( i
= 0; i
< node
.subElements
.size(); i
++ )
507 ParseContext parseContext
;
508 ProcessXMLSubElement ( *node
.subElements
[i
], path
, parseContext
);
510 for ( i
= 0; i
< invocations
.size(); i
++ )
511 invocations
[i
]->ProcessXML ();
512 for ( i
= 0; i
< dependencies
.size(); i
++ )
513 dependencies
[i
]->ProcessXML ();
514 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
515 compilerFlags
[i
]->ProcessXML();
516 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
517 linkerFlags
[i
]->ProcessXML();
518 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
519 stubbedComponents
[i
]->ProcessXML();
520 non_if_data
.ProcessXML();
522 linkerScript
->ProcessXML();
526 autoRegister
->ProcessXML();
530 Module::ProcessXMLSubElement ( const XMLElement
& e
,
532 ParseContext
& parseContext
)
534 If
* pOldIf
= parseContext
.ifData
;
535 CompilationUnit
* pOldCompilationUnit
= parseContext
.compilationUnit
;
536 bool subs_invalid
= false;
537 string
subpath ( path
);
538 if ( e
.name
== "file" && e
.value
.size () > 0 )
541 const XMLAttribute
* att
= e
.GetAttribute ( "first", false );
544 if ( !stricmp ( att
->value
.c_str(), "true" ) )
546 else if ( stricmp ( att
->value
.c_str(), "false" ) )
548 throw XMLInvalidBuildFileException (
550 "attribute 'first' of <file> element can only be 'true' or 'false'" );
553 string switches
= "";
554 att
= e
.GetAttribute ( "switches", false );
556 switches
= att
->value
;
559 // check for c++ file
560 string ext
= GetExtension ( e
.value
);
561 if ( !stricmp ( ext
.c_str(), ".cpp" ) )
563 else if ( !stricmp ( ext
.c_str(), ".cc" ) )
565 else if ( !stricmp ( ext
.c_str(), ".cxx" ) )
568 File
* pFile
= new File ( FixSeparator ( path
+ cSep
+ e
.value
),
572 if ( parseContext
.compilationUnit
)
573 parseContext
.compilationUnit
->files
.push_back ( pFile
);
576 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( pFile
);
577 if ( parseContext
.ifData
)
578 parseContext
.ifData
->data
.compilationUnits
.push_back ( pCompilationUnit
);
580 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
582 if ( parseContext
.ifData
)
583 parseContext
.ifData
->data
.files
.push_back ( pFile
);
585 non_if_data
.files
.push_back ( pFile
);
588 else if ( e
.name
== "library" && e
.value
.size () )
590 Library
* pLibrary
= new Library ( e
, *this, e
.value
);
591 if ( parseContext
.ifData
)
592 parseContext
.ifData
->data
.libraries
.push_back ( pLibrary
);
594 non_if_data
.libraries
.push_back ( pLibrary
);
597 else if ( e
.name
== "directory" )
599 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
601 subpath
= GetSubPath ( e
.location
, path
, att
->value
);
603 else if ( e
.name
== "include" )
605 Include
* include
= new Include ( project
, this, &e
);
606 if ( parseContext
.ifData
)
607 parseContext
.ifData
->data
.includes
.push_back ( include
);
609 non_if_data
.includes
.push_back ( include
);
612 else if ( e
.name
== "define" )
614 Define
* pDefine
= new Define ( project
, this, e
);
615 if ( parseContext
.ifData
)
616 parseContext
.ifData
->data
.defines
.push_back ( pDefine
);
618 non_if_data
.defines
.push_back ( pDefine
);
621 else if ( e
.name
== "invoke" )
623 if ( parseContext
.ifData
)
625 throw XMLInvalidBuildFileException (
627 "<invoke> is not a valid sub-element of <if>" );
629 invocations
.push_back ( new Invoke ( e
, *this ) );
630 subs_invalid
= false;
632 else if ( e
.name
== "dependency" )
634 if ( parseContext
.ifData
)
636 throw XMLInvalidBuildFileException (
638 "<dependency> is not a valid sub-element of <if>" );
640 dependencies
.push_back ( new Dependency ( e
, *this ) );
643 else if ( e
.name
== "importlibrary" )
645 if ( parseContext
.ifData
)
647 throw XMLInvalidBuildFileException (
649 "<importlibrary> is not a valid sub-element of <if>" );
653 throw XMLInvalidBuildFileException (
655 "Only one <importlibrary> is valid per module" );
657 importLibrary
= new ImportLibrary ( e
, *this );
660 else if ( e
.name
== "if" )
662 parseContext
.ifData
= new If ( e
, project
, this );
664 pOldIf
->data
.ifs
.push_back ( parseContext
.ifData
);
666 non_if_data
.ifs
.push_back ( parseContext
.ifData
);
667 subs_invalid
= false;
669 else if ( e
.name
== "ifnot" )
671 parseContext
.ifData
= new If ( e
, project
, this, true );
673 pOldIf
->data
.ifs
.push_back ( parseContext
.ifData
);
675 non_if_data
.ifs
.push_back ( parseContext
.ifData
);
676 subs_invalid
= false;
678 else if ( e
.name
== "compilerflag" )
680 CompilerFlag
* pCompilerFlag
= new CompilerFlag ( project
, this, e
);
681 if ( parseContext
.ifData
)
682 parseContext
.ifData
->data
.compilerFlags
.push_back ( pCompilerFlag
);
684 non_if_data
.compilerFlags
.push_back ( pCompilerFlag
);
687 else if ( e
.name
== "linkerflag" )
689 linkerFlags
.push_back ( new LinkerFlag ( project
, this, e
) );
692 else if ( e
.name
== "linkerscript" )
696 throw XMLInvalidBuildFileException (
698 "Only one <linkerscript> is valid per module" );
700 linkerScript
= new LinkerScript ( project
, this, e
);
703 else if ( e
.name
== "component" )
705 stubbedComponents
.push_back ( new StubbedComponent ( this, e
) );
706 subs_invalid
= false;
708 else if ( e
.name
== "property" )
710 throw XMLInvalidBuildFileException (
712 "<property> is not a valid sub-element of <module>" );
714 else if ( e
.name
== "bootstrap" )
716 bootstrap
= new Bootstrap ( project
, this, e
);
719 else if ( e
.name
== "pch" )
721 if ( parseContext
.ifData
)
723 throw XMLInvalidBuildFileException (
725 "<pch> is not a valid sub-element of <if>" );
729 throw XMLInvalidBuildFileException (
731 "Only one <pch> is valid per module" );
734 e
, *this, File ( FixSeparator ( path
+ cSep
+ e
.value
), false, "", true ) );
737 else if ( e
.name
== "compilationunit" )
739 if ( project
.configuration
.CompilationUnitsEnabled
)
741 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( &project
, this, &e
);
742 if ( parseContext
.ifData
)
743 parseContext
.ifData
->data
.compilationUnits
.push_back ( pCompilationUnit
);
745 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
746 parseContext
.compilationUnit
= pCompilationUnit
;
748 subs_invalid
= false;
750 else if ( e
.name
== "autoregister" )
752 if ( autoRegister
!= NULL
)
754 throw XMLInvalidBuildFileException (
756 "there can be only one <%s> element for a module",
759 autoRegister
= new AutoRegister ( project
, this, e
);
762 if ( subs_invalid
&& e
.subElements
.size() > 0 )
764 throw XMLInvalidBuildFileException (
766 "<%s> cannot have sub-elements",
769 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
770 ProcessXMLSubElement ( *e
.subElements
[i
], subpath
, parseContext
);
771 parseContext
.ifData
= pOldIf
;
772 parseContext
.compilationUnit
= pOldCompilationUnit
;
776 Module::GetModuleType ( const string
& location
, const XMLAttribute
& attribute
)
778 if ( attribute
.value
== "buildtool" )
780 if ( attribute
.value
== "staticlibrary" )
781 return StaticLibrary
;
782 if ( attribute
.value
== "objectlibrary" )
783 return ObjectLibrary
;
784 if ( attribute
.value
== "kernel" )
786 if ( attribute
.value
== "kernelmodedll" )
787 return KernelModeDLL
;
788 if ( attribute
.value
== "exportdriver" )
790 if ( attribute
.value
== "kernelmodedriver" )
791 return KernelModeDriver
;
792 if ( attribute
.value
== "nativedll" )
794 if ( attribute
.value
== "nativecui" )
796 if ( attribute
.value
== "win32dll" )
798 if ( attribute
.value
== "win32cui" )
800 if ( attribute
.value
== "win32gui" )
802 if ( attribute
.value
== "win32scr" )
804 if ( attribute
.value
== "bootloader" )
806 if ( attribute
.value
== "bootsector" )
808 if ( attribute
.value
== "bootprogram" )
810 if ( attribute
.value
== "iso" )
812 if ( attribute
.value
== "liveiso" )
814 if ( attribute
.value
== "isoregtest" )
816 if ( attribute
.value
== "liveisoregtest" )
817 return LiveIsoRegTest
;
818 if ( attribute
.value
== "test" )
820 if ( attribute
.value
== "rpcserver" )
822 if ( attribute
.value
== "rpcclient" )
824 if ( attribute
.value
== "alias" )
826 if ( attribute
.value
== "idlheader" )
828 throw InvalidAttributeValueException ( location
,
834 Module::GetDefaultModuleExtension () const
856 case KernelModeDriver
:
878 throw InvalidOperationException ( __FILE__
,
883 Module::GetDefaultModuleEntrypoint () const
888 return "NtProcessStartup";
890 case KernelModeDriver
:
892 return "DriverEntry@8";
894 return "DllMainCRTStartup@12";
896 return "NtProcessStartup@4";
902 return "wmainCRTStartup";
904 return "mainCRTStartup";
908 return "wWinMainCRTStartup";
910 return "WinMainCRTStartup";
927 throw InvalidOperationException ( __FILE__
,
932 Module::GetDefaultModuleBaseaddress () const
949 case KernelModeDriver
:
968 throw InvalidOperationException ( __FILE__
,
973 Module::HasImportLibrary () const
975 return importLibrary
!= NULL
&& type
!= StaticLibrary
;
979 Module::IsDLL () const
989 case KernelModeDriver
:
1004 case LiveIsoRegTest
:
1011 throw InvalidOperationException ( __FILE__
,
1016 Module::GenerateInOutputTree () const
1025 case KernelModeDriver
:
1038 case LiveIsoRegTest
:
1048 throw InvalidOperationException ( __FILE__
,
1053 Module::GetTargetName () const
1055 return name
+ extension
;
1059 Module::GetDependencyPath () const
1061 if ( HasImportLibrary () )
1062 return ReplaceExtension ( GetPathWithPrefix ( "lib" ), ".a" );
1068 Module::GetBasePath () const
1074 Module::GetPath () const
1076 if ( path
.length() > 0 )
1077 return path
+ cSep
+ GetTargetName ();
1079 return GetTargetName ();
1083 Module::GetPathWithPrefix ( const string
& prefix
) const
1085 return path
+ cSep
+ prefix
+ GetTargetName ();
1089 Module::GetPathToBaseDir () const
1091 string temp_path
= path
;
1092 string result
= "..\\";
1093 while(temp_path
.find ('\\') != string::npos
)
1095 temp_path
.erase (0, temp_path
.find('\\')+1);
1102 Module::GetInvocationTarget ( const int index
) const
1104 return ssprintf ( "%s_invoke_%d",
1110 Module::GetEntryPoint(bool leadingUnderscore
) const
1113 if (entrypoint
== "0" || entrypoint
== "0x0")
1115 if (leadingUnderscore
)
1118 result
+= entrypoint
;
1123 Module::HasFileWithExtension (
1124 const IfableData
& data
,
1125 const std::string
& extension
) const
1128 for ( i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1130 CompilationUnit
* compilationUnit
= data
.compilationUnits
[i
];
1131 if ( compilationUnit
->HasFileWithExtension ( extension
) )
1134 for ( i
= 0; i
< data
.ifs
.size (); i
++ )
1136 if ( HasFileWithExtension ( data
.ifs
[i
]->data
, extension
) )
1143 Module::InvokeModule () const
1145 for ( size_t i
= 0; i
< invocations
.size (); i
++ )
1147 Invoke
& invoke
= *invocations
[i
];
1148 string command
= FixSeparatorForSystemCommand(invoke
.invokeModule
->GetPath ()) + " " + invoke
.GetParameters ();
1149 printf ( "Executing '%s'\n\n", command
.c_str () );
1150 int exitcode
= system ( command
.c_str () );
1151 if ( exitcode
!= 0 )
1152 throw InvocationFailedException ( command
,
1158 File::File ( const string
& _name
, bool _first
,
1159 std::string _switches
,
1160 bool _isPreCompiledHeader
)
1163 switches(_switches
),
1164 isPreCompiledHeader(_isPreCompiledHeader
)
1174 Library::Library ( const XMLElement
& _node
,
1175 const Module
& _module
,
1176 const string
& _name
)
1180 importedModule(_module
.project
.LocateModule(_name
))
1182 if ( module
.name
== name
)
1184 throw XMLInvalidBuildFileException (
1186 "module '%s' cannot link against itself",
1189 if ( !importedModule
)
1191 throw XMLInvalidBuildFileException (
1193 "module '%s' trying to import non-existant module '%s'",
1194 module
.name
.c_str(),
1199 Library::Library ( const Module
& _module
,
1200 const string
& _name
)
1204 importedModule(_module
.project
.LocateModule(_name
))
1209 Library::ProcessXML()
1211 if ( node
&& !module
.project
.LocateModule ( name
) )
1213 throw XMLInvalidBuildFileException (
1215 "module '%s' is trying to link against non-existant module '%s'",
1216 module
.name
.c_str(),
1222 Invoke::Invoke ( const XMLElement
& _node
,
1223 const Module
& _module
)
1230 Invoke::ProcessXML()
1232 const XMLAttribute
* att
= node
.GetAttribute ( "module", false );
1234 invokeModule
= &module
;
1237 invokeModule
= module
.project
.LocateModule ( att
->value
);
1238 if ( invokeModule
== NULL
)
1240 throw XMLInvalidBuildFileException (
1242 "module '%s' is trying to invoke non-existant module '%s'",
1243 module
.name
.c_str(),
1244 att
->value
.c_str() );
1248 for ( size_t i
= 0; i
< node
.subElements
.size (); i
++ )
1249 ProcessXMLSubElement ( *node
.subElements
[i
] );
1253 Invoke::ProcessXMLSubElement ( const XMLElement
& e
)
1255 bool subs_invalid
= false;
1256 if ( e
.name
== "input" )
1258 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1259 ProcessXMLSubElementInput ( *e
.subElements
[i
] );
1261 else if ( e
.name
== "output" )
1263 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1264 ProcessXMLSubElementOutput ( *e
.subElements
[i
] );
1266 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1268 throw XMLInvalidBuildFileException (
1270 "<%s> cannot have sub-elements",
1276 Invoke::ProcessXMLSubElementInput ( const XMLElement
& e
)
1278 bool subs_invalid
= false;
1279 if ( e
.name
== "inputfile" && e
.value
.size () > 0 )
1281 input
.push_back ( new InvokeFile (
1282 e
, FixSeparator ( module
.path
+ cSep
+ e
.value
) ) );
1283 subs_invalid
= true;
1285 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1287 throw XMLInvalidBuildFileException (
1289 "<%s> cannot have sub-elements",
1295 Invoke::ProcessXMLSubElementOutput ( const XMLElement
& e
)
1297 bool subs_invalid
= false;
1298 if ( e
.name
== "outputfile" && e
.value
.size () > 0 )
1300 output
.push_back ( new InvokeFile (
1301 e
, FixSeparator ( module
.path
+ cSep
+ e
.value
) ) );
1302 subs_invalid
= true;
1304 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1306 throw XMLInvalidBuildFileException (
1308 "<%s> cannot have sub-elements",
1314 Invoke::GetTargets ( string_list
& targets
) const
1316 for ( size_t i
= 0; i
< output
.size (); i
++ )
1318 InvokeFile
& file
= *output
[i
];
1319 targets
.push_back ( NormalizeFilename ( file
.name
) );
1324 Invoke::GetParameters () const
1326 string
parameters ( "" );
1328 for ( i
= 0; i
< output
.size (); i
++ )
1330 if ( parameters
.length () > 0)
1332 InvokeFile
& invokeFile
= *output
[i
];
1333 if ( invokeFile
.switches
.length () > 0 )
1335 parameters
+= invokeFile
.switches
+ " ";
1337 parameters
+= invokeFile
.name
;
1340 for ( i
= 0; i
< input
.size (); i
++ )
1342 if ( parameters
.length () > 0 )
1344 InvokeFile
& invokeFile
= *input
[i
];
1345 if ( invokeFile
.switches
.length () > 0 )
1347 parameters
+= invokeFile
.switches
;
1350 parameters
+= invokeFile
.name
;
1357 InvokeFile::InvokeFile ( const XMLElement
& _node
,
1358 const string
& _name
)
1362 const XMLAttribute
* att
= _node
.GetAttribute ( "switches", false );
1364 switches
= att
->value
;
1370 InvokeFile::ProcessXML()
1375 Dependency::Dependency ( const XMLElement
& _node
,
1376 const Module
& _module
)
1379 dependencyModule (NULL
)
1384 Dependency::ProcessXML()
1386 dependencyModule
= module
.project
.LocateModule ( node
.value
);
1387 if ( dependencyModule
== NULL
)
1389 throw XMLInvalidBuildFileException (
1391 "module '%s' depend on non-existant module '%s'",
1392 module
.name
.c_str(),
1393 node
.value
.c_str() );
1398 ImportLibrary::ImportLibrary ( const XMLElement
& _node
,
1399 const Module
& _module
)
1403 const XMLAttribute
* att
= _node
.GetAttribute ( "basename", false );
1405 basename
= att
->value
;
1407 basename
= module
.name
;
1409 att
= _node
.GetAttribute ( "dllname", false );
1411 dllname
= att
->value
;
1414 if ( _module
.type
== StaticLibrary
)
1416 throw XMLInvalidBuildFileException (
1418 "<importlibrary> dllname attribute required." );
1424 att
= _node
.GetAttribute ( "definition", true );
1426 definition
= FixSeparator(att
->value
);
1430 If::If ( const XMLElement
& node_
,
1431 const Project
& project_
,
1432 const Module
* module_
,
1433 const bool negated_
)
1434 : node(node_
), project(project_
), module(module_
), negated(negated_
)
1436 const XMLAttribute
* att
;
1438 att
= node
.GetAttribute ( "property", true );
1440 property
= att
->value
;
1442 att
= node
.GetAttribute ( "value", true );
1458 Property::Property ( const XMLElement
& node_
,
1459 const Project
& project_
,
1460 const Module
* module_
)
1461 : node(node_
), project(project_
), module(module_
)
1463 const XMLAttribute
* att
;
1465 att
= node
.GetAttribute ( "name", true );
1469 att
= node
.GetAttribute ( "value", true );
1475 Property::ProcessXML()
1481 const XMLElement
& node_
,
1482 const Module
& module_
,
1484 : node(node_
), module(module_
), file(file_
)
1489 PchFile::ProcessXML()
1494 AutoRegister::AutoRegister ( const Project
& project_
,
1495 const Module
* module_
,
1496 const XMLElement
& node_
)
1497 : project(project_
),
1504 AutoRegister::~AutoRegister ()
1509 AutoRegister::IsSupportedModuleType ( ModuleType type
)
1523 case KernelModeDriver
:
1533 case LiveIsoRegTest
:
1541 throw InvalidOperationException ( __FILE__
,
1546 AutoRegister::GetAutoRegisterType( string type
)
1548 if ( type
== "DllRegisterServer" )
1549 return DllRegisterServer
;
1550 if ( type
== "DllInstall" )
1552 if ( type
== "Both" )
1554 throw XMLInvalidBuildFileException (
1556 "<autoregister> type attribute must be DllRegisterServer, DllInstall or Both." );
1560 AutoRegister::Initialize ()
1562 if ( !IsSupportedModuleType ( module
->type
) )
1564 throw XMLInvalidBuildFileException (
1566 "<autoregister> is not applicable for this module type." );
1569 const XMLAttribute
* att
= node
.GetAttribute ( "infsection", true );
1570 infSection
= att
->value
;
1572 att
= node
.GetAttribute ( "type", true );
1573 type
= GetAutoRegisterType ( att
->value
);
1577 AutoRegister::ProcessXML()