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 ( "underscoresymbols", false );
378 underscoreSymbols
= att
->value
== "true";
380 underscoreSymbols
= false;
382 att
= moduleNode
.GetAttribute ( "host", false );
385 const char* p
= att
->value
.c_str();
386 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
388 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
392 throw InvalidAttributeValueException (
399 att
= moduleNode
.GetAttribute ( "isstartuplib", false );
402 const char* p
= att
->value
.c_str();
403 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
405 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
406 isStartupLib
= false;
409 throw InvalidAttributeValueException (
416 isStartupLib
= false;
418 att
= moduleNode
.GetAttribute ( "prefix", false );
422 att
= moduleNode
.GetAttribute ( "installbase", false );
424 installBase
= att
->value
;
428 att
= moduleNode
.GetAttribute ( "installname", false );
430 installName
= att
->value
;
434 att
= moduleNode
.GetAttribute ( "usewrc", false );
436 useWRC
= att
->value
== "true";
440 att
= moduleNode
.GetAttribute ( "allowwarnings", false );
443 att
= moduleNode
.GetAttribute ( "warnings", false );
446 printf ( "%s: WARNING: 'warnings' attribute of <module> is deprecated, use 'allowwarnings' instead\n",
447 moduleNode
.location
.c_str() );
451 allowWarnings
= att
->value
== "true";
453 allowWarnings
= false;
455 att
= moduleNode
.GetAttribute ( "aliasof", false );
456 if ( type
== Alias
&& att
!= NULL
)
457 aliasedModuleName
= att
->value
;
459 aliasedModuleName
= "";
461 if ( type
== BootProgram
)
463 att
= moduleNode
.GetAttribute ( "payload", true );
464 payload
= att
->value
;
471 for ( i
= 0; i
< invocations
.size(); i
++ )
472 delete invocations
[i
];
473 for ( i
= 0; i
< dependencies
.size(); i
++ )
474 delete dependencies
[i
];
475 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
476 delete compilerFlags
[i
];
477 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
478 delete linkerFlags
[i
];
479 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
480 delete stubbedComponents
[i
];
492 if ( aliasedModuleName
== name
)
494 throw XMLInvalidBuildFileException (
496 "module '%s' cannot link against itself",
499 const Module
* m
= project
.LocateModule ( aliasedModuleName
);
502 throw XMLInvalidBuildFileException (
504 "module '%s' trying to alias non-existant module '%s'",
506 aliasedModuleName
.c_str() );
511 for ( i
= 0; i
< node
.subElements
.size(); i
++ )
513 ParseContext parseContext
;
514 ProcessXMLSubElement ( *node
.subElements
[i
], path
, parseContext
);
516 for ( i
= 0; i
< invocations
.size(); i
++ )
517 invocations
[i
]->ProcessXML ();
518 for ( i
= 0; i
< dependencies
.size(); i
++ )
519 dependencies
[i
]->ProcessXML ();
520 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
521 compilerFlags
[i
]->ProcessXML();
522 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
523 linkerFlags
[i
]->ProcessXML();
524 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
525 stubbedComponents
[i
]->ProcessXML();
526 non_if_data
.ProcessXML();
528 linkerScript
->ProcessXML();
532 autoRegister
->ProcessXML();
536 Module::ProcessXMLSubElement ( const XMLElement
& e
,
538 ParseContext
& parseContext
)
540 If
* pOldIf
= parseContext
.ifData
;
541 CompilationUnit
* pOldCompilationUnit
= parseContext
.compilationUnit
;
542 bool subs_invalid
= false;
543 string
subpath ( path
);
544 if ( e
.name
== "file" && e
.value
.size () > 0 )
547 const XMLAttribute
* att
= e
.GetAttribute ( "first", false );
550 if ( !stricmp ( att
->value
.c_str(), "true" ) )
552 else if ( stricmp ( att
->value
.c_str(), "false" ) )
554 throw XMLInvalidBuildFileException (
556 "attribute 'first' of <file> element can only be 'true' or 'false'" );
559 string switches
= "";
560 att
= e
.GetAttribute ( "switches", false );
562 switches
= att
->value
;
565 // check for c++ file
566 string ext
= GetExtension ( e
.value
);
567 if ( !stricmp ( ext
.c_str(), ".cpp" ) )
569 else if ( !stricmp ( ext
.c_str(), ".cc" ) )
571 else if ( !stricmp ( ext
.c_str(), ".cxx" ) )
574 File
* pFile
= new File ( FixSeparator ( path
+ cSep
+ e
.value
),
578 if ( parseContext
.compilationUnit
)
579 parseContext
.compilationUnit
->files
.push_back ( pFile
);
582 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( pFile
);
583 if ( parseContext
.ifData
)
584 parseContext
.ifData
->data
.compilationUnits
.push_back ( pCompilationUnit
);
587 string ext
= GetExtension ( e
.value
);
588 if ( !stricmp ( ext
.c_str(), ".idl" ) )
589 non_if_data
.compilationUnits
.insert ( non_if_data
.compilationUnits
.begin(), pCompilationUnit
);
591 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
594 if ( parseContext
.ifData
)
595 parseContext
.ifData
->data
.files
.push_back ( pFile
);
597 non_if_data
.files
.push_back ( pFile
);
600 else if ( e
.name
== "library" && e
.value
.size () )
602 Library
* pLibrary
= new Library ( e
, *this, e
.value
);
603 if ( parseContext
.ifData
)
604 parseContext
.ifData
->data
.libraries
.push_back ( pLibrary
);
606 non_if_data
.libraries
.push_back ( pLibrary
);
609 else if ( e
.name
== "directory" )
611 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
613 subpath
= GetSubPath ( e
.location
, path
, att
->value
);
615 else if ( e
.name
== "include" )
617 Include
* include
= new Include ( project
, this, &e
);
618 if ( parseContext
.ifData
)
619 parseContext
.ifData
->data
.includes
.push_back ( include
);
621 non_if_data
.includes
.push_back ( include
);
624 else if ( e
.name
== "define" )
626 Define
* pDefine
= new Define ( project
, this, e
);
627 if ( parseContext
.ifData
)
628 parseContext
.ifData
->data
.defines
.push_back ( pDefine
);
630 non_if_data
.defines
.push_back ( pDefine
);
633 else if ( e
.name
== "invoke" )
635 if ( parseContext
.ifData
)
637 throw XMLInvalidBuildFileException (
639 "<invoke> is not a valid sub-element of <if>" );
641 invocations
.push_back ( new Invoke ( e
, *this ) );
642 subs_invalid
= false;
644 else if ( e
.name
== "dependency" )
646 if ( parseContext
.ifData
)
648 throw XMLInvalidBuildFileException (
650 "<dependency> is not a valid sub-element of <if>" );
652 dependencies
.push_back ( new Dependency ( e
, *this ) );
655 else if ( e
.name
== "importlibrary" )
657 if ( parseContext
.ifData
)
659 throw XMLInvalidBuildFileException (
661 "<importlibrary> is not a valid sub-element of <if>" );
665 throw XMLInvalidBuildFileException (
667 "Only one <importlibrary> is valid per module" );
669 importLibrary
= new ImportLibrary ( e
, *this );
672 else if ( e
.name
== "if" )
674 parseContext
.ifData
= new If ( e
, project
, this );
676 pOldIf
->data
.ifs
.push_back ( parseContext
.ifData
);
678 non_if_data
.ifs
.push_back ( parseContext
.ifData
);
679 subs_invalid
= false;
681 else if ( e
.name
== "ifnot" )
683 parseContext
.ifData
= new If ( e
, project
, this, true );
685 pOldIf
->data
.ifs
.push_back ( parseContext
.ifData
);
687 non_if_data
.ifs
.push_back ( parseContext
.ifData
);
688 subs_invalid
= false;
690 else if ( e
.name
== "compilerflag" )
692 CompilerFlag
* pCompilerFlag
= new CompilerFlag ( project
, this, e
);
693 if ( parseContext
.ifData
)
694 parseContext
.ifData
->data
.compilerFlags
.push_back ( pCompilerFlag
);
696 non_if_data
.compilerFlags
.push_back ( pCompilerFlag
);
699 else if ( e
.name
== "linkerflag" )
701 linkerFlags
.push_back ( new LinkerFlag ( project
, this, e
) );
704 else if ( e
.name
== "linkerscript" )
708 throw XMLInvalidBuildFileException (
710 "Only one <linkerscript> is valid per module" );
712 linkerScript
= new LinkerScript ( project
, this, e
);
715 else if ( e
.name
== "component" )
717 stubbedComponents
.push_back ( new StubbedComponent ( this, e
) );
718 subs_invalid
= false;
720 else if ( e
.name
== "property" )
722 throw XMLInvalidBuildFileException (
724 "<property> is not a valid sub-element of <module>" );
726 else if ( e
.name
== "bootstrap" )
728 bootstrap
= new Bootstrap ( project
, this, e
);
731 else if ( e
.name
== "pch" )
733 if ( parseContext
.ifData
)
735 throw XMLInvalidBuildFileException (
737 "<pch> is not a valid sub-element of <if>" );
741 throw XMLInvalidBuildFileException (
743 "Only one <pch> is valid per module" );
746 e
, *this, File ( FixSeparator ( path
+ cSep
+ e
.value
), false, "", true ) );
749 else if ( e
.name
== "compilationunit" )
751 if ( project
.configuration
.CompilationUnitsEnabled
)
753 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( &project
, this, &e
);
754 if ( parseContext
.ifData
)
755 parseContext
.ifData
->data
.compilationUnits
.push_back ( pCompilationUnit
);
757 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
758 parseContext
.compilationUnit
= pCompilationUnit
;
760 subs_invalid
= false;
762 else if ( e
.name
== "autoregister" )
764 if ( autoRegister
!= NULL
)
766 throw XMLInvalidBuildFileException (
768 "there can be only one <%s> element for a module",
771 autoRegister
= new AutoRegister ( project
, this, e
);
774 if ( subs_invalid
&& e
.subElements
.size() > 0 )
776 throw XMLInvalidBuildFileException (
778 "<%s> cannot have sub-elements",
781 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
782 ProcessXMLSubElement ( *e
.subElements
[i
], subpath
, parseContext
);
783 parseContext
.ifData
= pOldIf
;
784 parseContext
.compilationUnit
= pOldCompilationUnit
;
788 Module::GetModuleType ( const string
& location
, const XMLAttribute
& attribute
)
790 if ( attribute
.value
== "buildtool" )
792 if ( attribute
.value
== "staticlibrary" )
793 return StaticLibrary
;
794 if ( attribute
.value
== "objectlibrary" )
795 return ObjectLibrary
;
796 if ( attribute
.value
== "kernel" )
798 if ( attribute
.value
== "kernelmodedll" )
799 return KernelModeDLL
;
800 if ( attribute
.value
== "exportdriver" )
802 if ( attribute
.value
== "kernelmodedriver" )
803 return KernelModeDriver
;
804 if ( attribute
.value
== "nativedll" )
806 if ( attribute
.value
== "nativecui" )
808 if ( attribute
.value
== "win32dll" )
810 if ( attribute
.value
== "win32cui" )
812 if ( attribute
.value
== "win32gui" )
814 if ( attribute
.value
== "win32scr" )
816 if ( attribute
.value
== "bootloader" )
818 if ( attribute
.value
== "bootsector" )
820 if ( attribute
.value
== "bootprogram" )
822 if ( attribute
.value
== "iso" )
824 if ( attribute
.value
== "liveiso" )
826 if ( attribute
.value
== "isoregtest" )
828 if ( attribute
.value
== "liveisoregtest" )
829 return LiveIsoRegTest
;
830 if ( attribute
.value
== "test" )
832 if ( attribute
.value
== "rpcserver" )
834 if ( attribute
.value
== "rpcclient" )
836 if ( attribute
.value
== "alias" )
838 if ( attribute
.value
== "idlheader" )
840 throw InvalidAttributeValueException ( location
,
846 Module::GetDefaultModuleExtension () const
868 case KernelModeDriver
:
890 throw InvalidOperationException ( __FILE__
,
895 Module::GetDefaultModuleEntrypoint () const
900 return "NtProcessStartup";
902 case KernelModeDriver
:
904 return "DriverEntry@8";
906 return "DllMainCRTStartup@12";
908 return "NtProcessStartup@4";
914 return "wmainCRTStartup";
916 return "mainCRTStartup";
920 return "wWinMainCRTStartup";
922 return "WinMainCRTStartup";
939 throw InvalidOperationException ( __FILE__
,
944 Module::GetDefaultModuleBaseaddress () const
961 case KernelModeDriver
:
980 throw InvalidOperationException ( __FILE__
,
985 Module::HasImportLibrary () const
987 return importLibrary
!= NULL
&& type
!= StaticLibrary
;
991 Module::IsDLL () const
1001 case KernelModeDriver
:
1016 case LiveIsoRegTest
:
1023 throw InvalidOperationException ( __FILE__
,
1028 Module::GenerateInOutputTree () const
1037 case KernelModeDriver
:
1050 case LiveIsoRegTest
:
1060 throw InvalidOperationException ( __FILE__
,
1065 Module::GetTargetName () const
1067 return name
+ extension
;
1071 Module::GetDependencyPath () const
1073 if ( HasImportLibrary () )
1074 return ReplaceExtension ( GetPathWithPrefix ( "lib" ), ".a" );
1080 Module::GetBasePath () const
1086 Module::GetPath () const
1088 if ( path
.length() > 0 )
1089 return path
+ cSep
+ GetTargetName ();
1091 return GetTargetName ();
1095 Module::GetPathWithPrefix ( const string
& prefix
) const
1097 return path
+ cSep
+ prefix
+ GetTargetName ();
1101 Module::GetPathToBaseDir () const
1103 string temp_path
= path
;
1104 string result
= "..\\";
1105 while(temp_path
.find ('\\') != string::npos
)
1107 temp_path
.erase (0, temp_path
.find('\\')+1);
1114 Module::GetInvocationTarget ( const int index
) const
1116 return ssprintf ( "%s_invoke_%d",
1122 Module::GetEntryPoint(bool leadingUnderscore
) const
1125 if (entrypoint
== "0" || entrypoint
== "0x0")
1127 if (leadingUnderscore
)
1130 result
+= entrypoint
;
1135 Module::HasFileWithExtension (
1136 const IfableData
& data
,
1137 const std::string
& extension
) const
1140 for ( i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1142 CompilationUnit
* compilationUnit
= data
.compilationUnits
[i
];
1143 if ( compilationUnit
->HasFileWithExtension ( extension
) )
1146 for ( i
= 0; i
< data
.ifs
.size (); i
++ )
1148 if ( HasFileWithExtension ( data
.ifs
[i
]->data
, extension
) )
1155 Module::InvokeModule () const
1157 for ( size_t i
= 0; i
< invocations
.size (); i
++ )
1159 Invoke
& invoke
= *invocations
[i
];
1160 string command
= FixSeparatorForSystemCommand(invoke
.invokeModule
->GetPath ()) + " " + invoke
.GetParameters ();
1161 printf ( "Executing '%s'\n\n", command
.c_str () );
1162 int exitcode
= system ( command
.c_str () );
1163 if ( exitcode
!= 0 )
1164 throw InvocationFailedException ( command
,
1170 File::File ( const string
& _name
, bool _first
,
1171 std::string _switches
,
1172 bool _isPreCompiledHeader
)
1175 switches(_switches
),
1176 isPreCompiledHeader(_isPreCompiledHeader
)
1186 Library::Library ( const XMLElement
& _node
,
1187 const Module
& _module
,
1188 const string
& _name
)
1192 importedModule(_module
.project
.LocateModule(_name
))
1194 if ( module
.name
== name
)
1196 throw XMLInvalidBuildFileException (
1198 "module '%s' cannot link against itself",
1201 if ( !importedModule
)
1203 throw XMLInvalidBuildFileException (
1205 "module '%s' trying to import non-existant module '%s'",
1206 module
.name
.c_str(),
1211 Library::Library ( const Module
& _module
,
1212 const string
& _name
)
1216 importedModule(_module
.project
.LocateModule(_name
))
1221 Library::ProcessXML()
1223 if ( node
&& !module
.project
.LocateModule ( name
) )
1225 throw XMLInvalidBuildFileException (
1227 "module '%s' is trying to link against non-existant module '%s'",
1228 module
.name
.c_str(),
1234 Invoke::Invoke ( const XMLElement
& _node
,
1235 const Module
& _module
)
1242 Invoke::ProcessXML()
1244 const XMLAttribute
* att
= node
.GetAttribute ( "module", false );
1246 invokeModule
= &module
;
1249 invokeModule
= module
.project
.LocateModule ( att
->value
);
1250 if ( invokeModule
== NULL
)
1252 throw XMLInvalidBuildFileException (
1254 "module '%s' is trying to invoke non-existant module '%s'",
1255 module
.name
.c_str(),
1256 att
->value
.c_str() );
1260 for ( size_t i
= 0; i
< node
.subElements
.size (); i
++ )
1261 ProcessXMLSubElement ( *node
.subElements
[i
] );
1265 Invoke::ProcessXMLSubElement ( const XMLElement
& e
)
1267 bool subs_invalid
= false;
1268 if ( e
.name
== "input" )
1270 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1271 ProcessXMLSubElementInput ( *e
.subElements
[i
] );
1273 else if ( e
.name
== "output" )
1275 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1276 ProcessXMLSubElementOutput ( *e
.subElements
[i
] );
1278 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1280 throw XMLInvalidBuildFileException (
1282 "<%s> cannot have sub-elements",
1288 Invoke::ProcessXMLSubElementInput ( const XMLElement
& e
)
1290 bool subs_invalid
= false;
1291 if ( e
.name
== "inputfile" && e
.value
.size () > 0 )
1293 input
.push_back ( new InvokeFile (
1294 e
, FixSeparator ( module
.path
+ cSep
+ e
.value
) ) );
1295 subs_invalid
= true;
1297 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1299 throw XMLInvalidBuildFileException (
1301 "<%s> cannot have sub-elements",
1307 Invoke::ProcessXMLSubElementOutput ( const XMLElement
& e
)
1309 bool subs_invalid
= false;
1310 if ( e
.name
== "outputfile" && e
.value
.size () > 0 )
1312 output
.push_back ( new InvokeFile (
1313 e
, FixSeparator ( module
.path
+ cSep
+ e
.value
) ) );
1314 subs_invalid
= true;
1316 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1318 throw XMLInvalidBuildFileException (
1320 "<%s> cannot have sub-elements",
1326 Invoke::GetTargets ( string_list
& targets
) const
1328 for ( size_t i
= 0; i
< output
.size (); i
++ )
1330 InvokeFile
& file
= *output
[i
];
1331 targets
.push_back ( NormalizeFilename ( file
.name
) );
1336 Invoke::GetParameters () const
1338 string
parameters ( "" );
1340 for ( i
= 0; i
< output
.size (); i
++ )
1342 if ( parameters
.length () > 0)
1344 InvokeFile
& invokeFile
= *output
[i
];
1345 if ( invokeFile
.switches
.length () > 0 )
1347 parameters
+= invokeFile
.switches
+ " ";
1349 parameters
+= invokeFile
.name
;
1352 for ( i
= 0; i
< input
.size (); i
++ )
1354 if ( parameters
.length () > 0 )
1356 InvokeFile
& invokeFile
= *input
[i
];
1357 if ( invokeFile
.switches
.length () > 0 )
1359 parameters
+= invokeFile
.switches
;
1362 parameters
+= invokeFile
.name
;
1369 InvokeFile::InvokeFile ( const XMLElement
& _node
,
1370 const string
& _name
)
1374 const XMLAttribute
* att
= _node
.GetAttribute ( "switches", false );
1376 switches
= att
->value
;
1382 InvokeFile::ProcessXML()
1387 Dependency::Dependency ( const XMLElement
& _node
,
1388 const Module
& _module
)
1391 dependencyModule (NULL
)
1396 Dependency::ProcessXML()
1398 dependencyModule
= module
.project
.LocateModule ( node
.value
);
1399 if ( dependencyModule
== NULL
)
1401 throw XMLInvalidBuildFileException (
1403 "module '%s' depend on non-existant module '%s'",
1404 module
.name
.c_str(),
1405 node
.value
.c_str() );
1410 ImportLibrary::ImportLibrary ( const XMLElement
& _node
,
1411 const Module
& _module
)
1415 const XMLAttribute
* att
= _node
.GetAttribute ( "basename", false );
1417 basename
= att
->value
;
1419 basename
= module
.name
;
1421 att
= _node
.GetAttribute ( "dllname", false );
1423 dllname
= att
->value
;
1426 if ( _module
.type
== StaticLibrary
)
1428 throw XMLInvalidBuildFileException (
1430 "<importlibrary> dllname attribute required." );
1436 att
= _node
.GetAttribute ( "definition", true );
1438 definition
= FixSeparator(att
->value
);
1442 If::If ( const XMLElement
& node_
,
1443 const Project
& project_
,
1444 const Module
* module_
,
1445 const bool negated_
)
1446 : node(node_
), project(project_
), module(module_
), negated(negated_
)
1448 const XMLAttribute
* att
;
1450 att
= node
.GetAttribute ( "property", true );
1452 property
= att
->value
;
1454 att
= node
.GetAttribute ( "value", true );
1470 Property::Property ( const XMLElement
& node_
,
1471 const Project
& project_
,
1472 const Module
* module_
)
1473 : node(node_
), project(project_
), module(module_
)
1475 const XMLAttribute
* att
;
1477 att
= node
.GetAttribute ( "name", true );
1481 att
= node
.GetAttribute ( "value", true );
1487 Property::ProcessXML()
1493 const XMLElement
& node_
,
1494 const Module
& module_
,
1496 : node(node_
), module(module_
), file(file_
)
1501 PchFile::ProcessXML()
1506 AutoRegister::AutoRegister ( const Project
& project_
,
1507 const Module
* module_
,
1508 const XMLElement
& node_
)
1509 : project(project_
),
1516 AutoRegister::~AutoRegister ()
1521 AutoRegister::IsSupportedModuleType ( ModuleType type
)
1535 case KernelModeDriver
:
1545 case LiveIsoRegTest
:
1553 throw InvalidOperationException ( __FILE__
,
1558 AutoRegister::GetAutoRegisterType( string type
)
1560 if ( type
== "DllRegisterServer" )
1561 return DllRegisterServer
;
1562 if ( type
== "DllInstall" )
1564 if ( type
== "Both" )
1566 throw XMLInvalidBuildFileException (
1568 "<autoregister> type attribute must be DllRegisterServer, DllInstall or Both." );
1572 AutoRegister::Initialize ()
1574 if ( !IsSupportedModuleType ( module
->type
) )
1576 throw XMLInvalidBuildFileException (
1578 "<autoregister> is not applicable for this module type." );
1581 const XMLAttribute
* att
= node
.GetAttribute ( "infsection", true );
1582 infSection
= att
->value
;
1584 att
= node
.GetAttribute ( "type", true );
1585 type
= GetAutoRegisterType ( att
->value
);
1589 AutoRegister::ProcessXML()