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 Project
& project
,
122 const string
& location
,
124 const string
& att_value
)
126 if ( !att_value
.size() )
127 throw XMLInvalidBuildFileException (
129 "<directory> tag has empty 'name' attribute" );
130 if ( strpbrk ( att_value
.c_str (), "/\\?*:<>|" ) )
131 throw XMLInvalidBuildFileException (
133 "<directory> tag has invalid characters in 'name' attribute" );
137 return FixSeparator(path
+ cSep
+ att_value
);
141 GetExtension ( const string
& filename
)
143 size_t index
= filename
.find_last_of ( '/' );
144 if (index
== string::npos
) index
= 0;
145 string tmp
= filename
.substr( index
, filename
.size() - index
);
146 size_t ext_index
= tmp
.find_last_of( '.' );
147 if (ext_index
!= string::npos
)
148 return filename
.substr ( index
+ ext_index
, filename
.size() );
153 GetDirectory ( const string
& filename
)
155 size_t index
= filename
.find_last_of ( cSep
);
156 if ( index
== string::npos
)
159 return filename
.substr ( 0, index
);
163 GetFilename ( const string
& filename
)
165 size_t index
= filename
.find_last_of ( cSep
);
166 if ( index
== string::npos
)
169 return filename
.substr ( index
+ 1, filename
.length () - index
);
173 NormalizeFilename ( const string
& filename
)
175 if ( filename
== "" )
178 string normalizedPath
= path
.Fixup ( filename
, true );
179 string relativeNormalizedPath
= path
.RelativeFromWorkingDirectory ( normalizedPath
);
180 return FixSeparator ( relativeNormalizedPath
);
184 GetBooleanValue ( const string
& value
)
193 ToLower ( string filename
)
195 for ( size_t i
= 1; i
< filename
.length (); i
++ )
196 filename
[i
] = tolower ( filename
[i
] );
200 void IfableData::ExtractModules( std::vector
<Module
*> &modules
)
203 for ( i
= 0; i
< this->modules
.size (); i
++ )
204 modules
.push_back(this->modules
[i
]);
207 IfableData::~IfableData()
210 for ( i
= 0; i
< includes
.size (); i
++ )
212 for ( i
= 0; i
< defines
.size (); i
++ )
214 for ( i
= 0; i
< libraries
.size (); i
++ )
216 for ( i
= 0; i
< properties
.size (); i
++ )
217 delete properties
[i
];
218 for ( i
= 0; i
< compilerFlags
.size (); i
++ )
219 delete compilerFlags
[i
];
220 for ( i
= 0; i
< modules
.size(); i
++ )
222 for ( i
= 0; i
< ifs
.size (); i
++ )
224 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
225 delete compilationUnits
[i
];
228 void IfableData::ProcessXML ()
231 for ( i
= 0; i
< includes
.size (); i
++ )
232 includes
[i
]->ProcessXML ();
233 for ( i
= 0; i
< defines
.size (); i
++ )
234 defines
[i
]->ProcessXML ();
235 for ( i
= 0; i
< libraries
.size (); i
++ )
236 libraries
[i
]->ProcessXML ();
237 for ( i
= 0; i
< properties
.size(); i
++ )
238 properties
[i
]->ProcessXML ();
239 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
240 compilerFlags
[i
]->ProcessXML ();
241 for ( i
= 0; i
< ifs
.size (); i
++ )
242 ifs
[i
]->ProcessXML ();
243 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
244 compilationUnits
[i
]->ProcessXML ();
247 Module::Module ( const Project
& project
,
248 const XMLElement
& moduleNode
,
249 const string
& modulePath
)
252 importLibrary (NULL
),
261 if ( node
.name
!= "module" )
262 throw InvalidOperationException ( __FILE__
,
264 "Module created with non-<module> node" );
266 xmlbuildFile
= Path::RelativeFromWorkingDirectory ( moduleNode
.xmlFile
->filename () );
268 path
= FixSeparator ( modulePath
);
272 const XMLAttribute
* att
= moduleNode
.GetAttribute ( "if", false );
274 enabled
= GetBooleanValue ( project
.ResolveProperties ( att
->value
) );
276 att
= moduleNode
.GetAttribute ( "ifnot", false );
278 enabled
= !GetBooleanValue ( project
.ResolveProperties ( att
->value
) );
280 att
= moduleNode
.GetAttribute ( "name", true );
284 att
= moduleNode
.GetAttribute ( "type", true );
286 type
= GetModuleType ( node
.location
, *att
);
288 att
= moduleNode
.GetAttribute ( "extension", false );
290 extension
= att
->value
;
292 extension
= GetDefaultModuleExtension ();
294 att
= moduleNode
.GetAttribute ( "unicode", false );
297 const char* p
= att
->value
.c_str();
298 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
300 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
304 throw InvalidAttributeValueException (
313 att
= moduleNode
.GetAttribute ( "stdlib", false );
316 const char* p
= att
->value
.c_str();
317 if ( !stricmp ( p
, "host" ) )
318 useHostStdlib
= true;
319 else if ( !stricmp ( p
, "default" ) )
320 useHostStdlib
= false;
323 throw InvalidAttributeValueException (
330 useHostStdlib
= false;
334 // Always define UNICODE and _UNICODE
335 Define
* pDefine
= new Define ( project
, this, "UNICODE" );
336 non_if_data
.defines
.push_back ( pDefine
);
338 pDefine
= new Define ( project
, this, "_UNICODE" );
339 non_if_data
.defines
.push_back ( pDefine
);
342 att
= moduleNode
.GetAttribute ( "entrypoint", false );
345 if ( att
->value
== "" )
347 throw InvalidAttributeValueException (
353 entrypoint
= att
->value
;
354 isDefaultEntryPoint
= false;
358 entrypoint
= GetDefaultModuleEntrypoint ();
359 isDefaultEntryPoint
= true;
362 att
= moduleNode
.GetAttribute ( "baseaddress", false );
364 baseaddress
= att
->value
;
366 baseaddress
= GetDefaultModuleBaseaddress ();
368 att
= moduleNode
.GetAttribute ( "mangledsymbols", false );
371 const char* p
= att
->value
.c_str();
372 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
373 mangledSymbols
= true;
374 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
375 mangledSymbols
= false;
378 throw InvalidAttributeValueException (
385 mangledSymbols
= false;
387 att
= moduleNode
.GetAttribute ( "underscoresymbols", false );
389 underscoreSymbols
= att
->value
== "true";
391 underscoreSymbols
= false;
393 att
= moduleNode
.GetAttribute ( "host", 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" ) )
403 throw InvalidAttributeValueException (
410 att
= moduleNode
.GetAttribute ( "isstartuplib", false );
413 const char* p
= att
->value
.c_str();
414 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
416 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
417 isStartupLib
= false;
420 throw InvalidAttributeValueException (
427 isStartupLib
= false;
429 att
= moduleNode
.GetAttribute ( "prefix", false );
433 att
= moduleNode
.GetAttribute ( "installbase", false );
435 installBase
= att
->value
;
439 att
= moduleNode
.GetAttribute ( "installname", false );
441 installName
= att
->value
;
445 att
= moduleNode
.GetAttribute ( "usewrc", false );
447 useWRC
= att
->value
== "true";
451 att
= moduleNode
.GetAttribute ( "allowwarnings", false );
454 att
= moduleNode
.GetAttribute ( "warnings", false );
457 printf ( "%s: WARNING: 'warnings' attribute of <module> is deprecated, use 'allowwarnings' instead\n",
458 moduleNode
.location
.c_str() );
462 allowWarnings
= att
->value
== "true";
464 allowWarnings
= false;
466 att
= moduleNode
.GetAttribute ( "aliasof", false );
467 if ( type
== Alias
&& att
!= NULL
)
468 aliasedModuleName
= att
->value
;
470 aliasedModuleName
= "";
472 if ( type
== BootProgram
)
474 att
= moduleNode
.GetAttribute ( "payload", true );
475 payload
= att
->value
;
478 if ( type
== BootProgram
|| type
== ElfExecutable
)
480 att
= moduleNode
.GetAttribute ( "buildtype", false );
483 buildtype
= att
->value
;
487 buildtype
= "BOOTPROG";
495 for ( i
= 0; i
< invocations
.size(); i
++ )
496 delete invocations
[i
];
497 for ( i
= 0; i
< dependencies
.size(); i
++ )
498 delete dependencies
[i
];
499 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
500 delete compilerFlags
[i
];
501 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
502 delete linkerFlags
[i
];
503 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
504 delete stubbedComponents
[i
];
516 if ( aliasedModuleName
== name
)
518 throw XMLInvalidBuildFileException (
520 "module '%s' cannot link against itself",
523 const Module
* m
= project
.LocateModule ( aliasedModuleName
);
526 throw XMLInvalidBuildFileException (
528 "module '%s' trying to alias non-existant module '%s'",
530 aliasedModuleName
.c_str() );
535 for ( i
= 0; i
< node
.subElements
.size(); i
++ )
537 ParseContext parseContext
;
538 ProcessXMLSubElement ( *node
.subElements
[i
], path
, "", parseContext
);
540 for ( i
= 0; i
< invocations
.size(); i
++ )
541 invocations
[i
]->ProcessXML ();
542 for ( i
= 0; i
< dependencies
.size(); i
++ )
543 dependencies
[i
]->ProcessXML ();
544 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
545 compilerFlags
[i
]->ProcessXML();
546 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
547 linkerFlags
[i
]->ProcessXML();
548 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
549 stubbedComponents
[i
]->ProcessXML();
550 non_if_data
.ProcessXML();
552 linkerScript
->ProcessXML();
556 autoRegister
->ProcessXML();
560 Module::ProcessXMLSubElement ( const XMLElement
& e
,
562 const string
& path_prefix
,
563 ParseContext
& parseContext
)
565 If
* pOldIf
= parseContext
.ifData
;
566 CompilationUnit
* pOldCompilationUnit
= parseContext
.compilationUnit
;
567 bool subs_invalid
= false;
568 string
subpath ( path
);
569 string
subpath_prefix ( "" );
570 if ( e
.name
== "file" && e
.value
.size () > 0 )
573 const XMLAttribute
* att
= e
.GetAttribute ( "first", false );
576 if ( !stricmp ( att
->value
.c_str(), "true" ) )
578 else if ( stricmp ( att
->value
.c_str(), "false" ) )
580 throw XMLInvalidBuildFileException (
582 "attribute 'first' of <file> element can only be 'true' or 'false'" );
585 string switches
= "";
586 att
= e
.GetAttribute ( "switches", false );
588 switches
= att
->value
;
591 // check for c++ file
592 string ext
= GetExtension ( e
.value
);
593 if ( !stricmp ( ext
.c_str(), ".cpp" ) )
595 else if ( !stricmp ( ext
.c_str(), ".cc" ) )
597 else if ( !stricmp ( ext
.c_str(), ".cxx" ) )
600 File
* pFile
= new File ( FixSeparator ( path
+ cSep
+ e
.value
),
605 if ( parseContext
.compilationUnit
)
606 parseContext
.compilationUnit
->files
.push_back ( pFile
);
609 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( pFile
);
610 if ( parseContext
.ifData
)
611 parseContext
.ifData
->data
.compilationUnits
.push_back ( pCompilationUnit
);
614 string ext
= GetExtension ( e
.value
);
615 if ( !stricmp ( ext
.c_str(), ".idl" ) )
616 non_if_data
.compilationUnits
.insert ( non_if_data
.compilationUnits
.begin(), pCompilationUnit
);
618 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
621 if ( parseContext
.ifData
)
622 parseContext
.ifData
->data
.files
.push_back ( pFile
);
624 non_if_data
.files
.push_back ( pFile
);
627 else if ( e
.name
== "library" && e
.value
.size () )
629 Library
* pLibrary
= new Library ( e
, *this, e
.value
);
630 if ( parseContext
.ifData
)
631 parseContext
.ifData
->data
.libraries
.push_back ( pLibrary
);
633 non_if_data
.libraries
.push_back ( pLibrary
);
636 else if ( e
.name
== "directory" )
638 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
639 const XMLAttribute
* root
= e
.GetAttribute ( "root", false );
643 if ( root
->value
== "intermediate" )
644 subpath_prefix
= "$(INTERMEDIATE)";
645 else if ( root
->value
== "output" )
646 subpath_prefix
= "$(OUTPUT)";
649 throw InvalidAttributeValueException (
655 subpath
= GetSubPath ( this->project
, e
.location
, path
, att
->value
);
657 else if ( e
.name
== "include" )
659 Include
* include
= new Include ( project
, this, &e
);
660 if ( parseContext
.ifData
)
661 parseContext
.ifData
->data
.includes
.push_back ( include
);
663 non_if_data
.includes
.push_back ( include
);
666 else if ( e
.name
== "define" )
668 Define
* pDefine
= new Define ( project
, this, e
);
669 if ( parseContext
.ifData
)
670 parseContext
.ifData
->data
.defines
.push_back ( pDefine
);
672 non_if_data
.defines
.push_back ( pDefine
);
675 else if ( e
.name
== "metadata" )
677 if ( parseContext
.ifData
)
679 throw XMLInvalidBuildFileException (
681 "<metadata> is not a valid sub-element of <if>" );
683 metadata
= new Metadata ( e
, *this );
684 subs_invalid
= false;
686 else if ( e
.name
== "invoke" )
688 if ( parseContext
.ifData
)
690 throw XMLInvalidBuildFileException (
692 "<invoke> is not a valid sub-element of <if>" );
694 invocations
.push_back ( new Invoke ( e
, *this ) );
695 subs_invalid
= false;
697 else if ( e
.name
== "dependency" )
699 if ( parseContext
.ifData
)
701 throw XMLInvalidBuildFileException (
703 "<dependency> is not a valid sub-element of <if>" );
705 dependencies
.push_back ( new Dependency ( e
, *this ) );
708 else if ( e
.name
== "importlibrary" )
710 if ( parseContext
.ifData
)
712 throw XMLInvalidBuildFileException (
714 "<importlibrary> is not a valid sub-element of <if>" );
718 throw XMLInvalidBuildFileException (
720 "Only one <importlibrary> is valid per module" );
722 importLibrary
= new ImportLibrary ( e
, *this );
725 else if ( e
.name
== "if" )
727 parseContext
.ifData
= new If ( e
, project
, this );
729 pOldIf
->data
.ifs
.push_back ( parseContext
.ifData
);
731 non_if_data
.ifs
.push_back ( parseContext
.ifData
);
732 subs_invalid
= false;
734 else if ( e
.name
== "ifnot" )
736 parseContext
.ifData
= new If ( e
, project
, this, true );
738 pOldIf
->data
.ifs
.push_back ( parseContext
.ifData
);
740 non_if_data
.ifs
.push_back ( parseContext
.ifData
);
741 subs_invalid
= false;
743 else if ( e
.name
== "compilerflag" )
745 CompilerFlag
* pCompilerFlag
= new CompilerFlag ( project
, this, e
);
746 if ( parseContext
.ifData
)
747 parseContext
.ifData
->data
.compilerFlags
.push_back ( pCompilerFlag
);
749 non_if_data
.compilerFlags
.push_back ( pCompilerFlag
);
752 else if ( e
.name
== "linkerflag" )
754 linkerFlags
.push_back ( new LinkerFlag ( project
, this, e
) );
757 else if ( e
.name
== "linkerscript" )
761 throw XMLInvalidBuildFileException (
763 "Only one <linkerscript> is valid per module" );
765 linkerScript
= new LinkerScript ( project
, this, e
);
768 else if ( e
.name
== "component" )
770 stubbedComponents
.push_back ( new StubbedComponent ( this, e
) );
771 subs_invalid
= false;
773 else if ( e
.name
== "property" )
775 throw XMLInvalidBuildFileException (
777 "<property> is not a valid sub-element of <module>" );
779 else if ( e
.name
== "bootstrap" )
781 bootstrap
= new Bootstrap ( project
, this, e
);
784 else if ( e
.name
== "pch" )
786 if ( parseContext
.ifData
)
788 throw XMLInvalidBuildFileException (
790 "<pch> is not a valid sub-element of <if>" );
794 throw XMLInvalidBuildFileException (
796 "Only one <pch> is valid per module" );
799 e
, *this, File ( FixSeparator ( path
+ cSep
+ e
.value
), false, "", true ) );
802 else if ( e
.name
== "compilationunit" )
804 if ( project
.configuration
.CompilationUnitsEnabled
)
806 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( &project
, this, &e
);
807 if ( parseContext
.ifData
)
808 parseContext
.ifData
->data
.compilationUnits
.push_back ( pCompilationUnit
);
810 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
811 parseContext
.compilationUnit
= pCompilationUnit
;
813 subs_invalid
= false;
815 else if ( e
.name
== "autoregister" )
817 if ( autoRegister
!= NULL
)
819 throw XMLInvalidBuildFileException (
821 "there can be only one <%s> element for a module",
824 autoRegister
= new AutoRegister ( project
, this, e
);
827 if ( subs_invalid
&& e
.subElements
.size() > 0 )
829 throw XMLInvalidBuildFileException (
831 "<%s> cannot have sub-elements",
834 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
835 ProcessXMLSubElement ( *e
.subElements
[i
], subpath
, subpath_prefix
, parseContext
);
836 parseContext
.ifData
= pOldIf
;
837 parseContext
.compilationUnit
= pOldCompilationUnit
;
841 Module::GetModuleType ( const string
& location
, const XMLAttribute
& attribute
)
843 if ( attribute
.value
== "buildtool" )
845 if ( attribute
.value
== "staticlibrary" )
846 return StaticLibrary
;
847 if ( attribute
.value
== "objectlibrary" )
848 return ObjectLibrary
;
849 if ( attribute
.value
== "kernel" )
851 if ( attribute
.value
== "kernelmodedll" )
852 return KernelModeDLL
;
853 if ( attribute
.value
== "kernelmodedriver" )
854 return KernelModeDriver
;
855 if ( attribute
.value
== "nativedll" )
857 if ( attribute
.value
== "nativecui" )
859 if ( attribute
.value
== "win32dll" )
861 if ( attribute
.value
== "win32ocx" )
863 if ( attribute
.value
== "win32cui" )
865 if ( attribute
.value
== "win32gui" )
867 if ( attribute
.value
== "win32scr" )
869 if ( attribute
.value
== "bootloader" )
871 if ( attribute
.value
== "bootsector" )
873 if ( attribute
.value
== "bootprogram" )
875 if ( attribute
.value
== "iso" )
877 if ( attribute
.value
== "liveiso" )
879 if ( attribute
.value
== "isoregtest" )
881 if ( attribute
.value
== "liveisoregtest" )
882 return LiveIsoRegTest
;
883 if ( attribute
.value
== "test" )
885 if ( attribute
.value
== "rpcserver" )
887 if ( attribute
.value
== "rpcclient" )
889 if ( attribute
.value
== "alias" )
891 if ( attribute
.value
== "idlheader" )
893 if ( attribute
.value
== "embeddedtypelib" )
894 return EmbeddedTypeLib
;
895 if ( attribute
.value
== "elfexecutable" )
896 return ElfExecutable
;
897 throw InvalidAttributeValueException ( location
,
903 Module::GetDefaultModuleExtension () const
928 case KernelModeDriver
:
948 case EmbeddedTypeLib
:
951 throw InvalidOperationException ( __FILE__
,
956 Module::GetDefaultModuleEntrypoint () const
961 return "NtProcessStartup";
963 case KernelModeDriver
:
964 return "DriverEntry@8";
966 return "DllMainCRTStartup@12";
968 return "NtProcessStartup@4";
975 return "wmainCRTStartup";
977 return "mainCRTStartup";
981 return "wWinMainCRTStartup";
983 return "WinMainCRTStartup";
999 case EmbeddedTypeLib
:
1002 throw InvalidOperationException ( __FILE__
,
1007 Module::GetDefaultModuleBaseaddress () const
1012 return "0x80800000";
1015 return "0x10000000";
1020 return "0x00400000";
1023 return "0x00400000";
1025 case KernelModeDriver
:
1026 return "0x00010000";
1037 case LiveIsoRegTest
:
1043 case EmbeddedTypeLib
:
1046 throw InvalidOperationException ( __FILE__
,
1051 Module::HasImportLibrary () const
1053 return importLibrary
!= NULL
&& type
!= StaticLibrary
;
1057 Module::IsDLL () const
1066 case KernelModeDriver
:
1082 case LiveIsoRegTest
:
1087 case EmbeddedTypeLib
:
1091 throw InvalidOperationException ( __FILE__
,
1096 Module::GenerateInOutputTree () const
1105 case KernelModeDriver
:
1117 case LiveIsoRegTest
:
1118 case EmbeddedTypeLib
:
1130 throw InvalidOperationException ( __FILE__
,
1135 Module::GetTargetName () const
1137 return name
+ extension
;
1141 Module::GetDependencyPath () const
1143 if ( HasImportLibrary () )
1144 return ReplaceExtension ( GetPathWithPrefix ( "lib" ), ".a" );
1150 Module::GetBasePath () const
1156 Module::GetPath () const
1158 if ( path
.length() > 0 )
1159 return path
+ cSep
+ GetTargetName ();
1161 return GetTargetName ();
1165 Module::GetPathWithPrefix ( const string
& prefix
) const
1167 return path
+ cSep
+ prefix
+ GetTargetName ();
1171 Module::GetPathToBaseDir () const
1173 string temp_path
= path
;
1174 string result
= "..\\";
1175 while(temp_path
.find ('\\') != string::npos
)
1177 temp_path
.erase (0, temp_path
.find('\\')+1);
1184 Module::GetInvocationTarget ( const int index
) const
1186 return ssprintf ( "%s_invoke_%d",
1192 Module::GetEntryPoint(bool leadingUnderscore
) const
1195 if (entrypoint
== "0" || entrypoint
== "0x0")
1197 if (leadingUnderscore
)
1200 result
+= entrypoint
;
1205 Module::HasFileWithExtension (
1206 const IfableData
& data
,
1207 const std::string
& extension
) const
1210 for ( i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1212 CompilationUnit
* compilationUnit
= data
.compilationUnits
[i
];
1213 if ( compilationUnit
->HasFileWithExtension ( extension
) )
1216 for ( i
= 0; i
< data
.ifs
.size (); i
++ )
1218 if ( HasFileWithExtension ( data
.ifs
[i
]->data
, extension
) )
1225 Module::InvokeModule () const
1227 for ( size_t i
= 0; i
< invocations
.size (); i
++ )
1229 Invoke
& invoke
= *invocations
[i
];
1230 string command
= FixSeparatorForSystemCommand(invoke
.invokeModule
->GetPath ()) + " " + invoke
.GetParameters ();
1231 printf ( "Executing '%s'\n\n", command
.c_str () );
1232 int exitcode
= system ( command
.c_str () );
1233 if ( exitcode
!= 0 )
1234 throw InvocationFailedException ( command
,
1240 File::File ( const string
& _name
,
1242 std::string _switches
,
1243 bool _isPreCompiledHeader
)
1247 switches(_switches
),
1248 isPreCompiledHeader(_isPreCompiledHeader
)
1253 File::File ( const string
& _name
,
1254 const string
& _path_prefix
,
1256 std::string _switches
,
1257 bool _isPreCompiledHeader
)
1259 path_prefix(_path_prefix
),
1261 switches(_switches
),
1262 isPreCompiledHeader(_isPreCompiledHeader
)
1272 std::string
File::GetFullPath () const
1274 if ( path_prefix
.length () > 0 )
1275 return path_prefix
+ sSep
+ name
;
1281 Library::Library ( const XMLElement
& _node
,
1282 const Module
& _module
,
1283 const string
& _name
)
1287 importedModule(_module
.project
.LocateModule(_name
))
1289 if ( module
.name
== name
)
1291 throw XMLInvalidBuildFileException (
1293 "module '%s' cannot link against itself",
1296 if ( !importedModule
)
1298 throw XMLInvalidBuildFileException (
1300 "module '%s' trying to import non-existant module '%s'",
1301 module
.name
.c_str(),
1306 Library::Library ( const Module
& _module
,
1307 const string
& _name
)
1311 importedModule(_module
.project
.LocateModule(_name
))
1316 Library::ProcessXML()
1318 if ( node
&& !module
.project
.LocateModule ( name
) )
1320 throw XMLInvalidBuildFileException (
1322 "module '%s' is trying to link against non-existant module '%s'",
1323 module
.name
.c_str(),
1329 Invoke::Invoke ( const XMLElement
& _node
,
1330 const Module
& _module
)
1337 Invoke::ProcessXML()
1339 const XMLAttribute
* att
= node
.GetAttribute ( "module", false );
1341 invokeModule
= &module
;
1344 invokeModule
= module
.project
.LocateModule ( att
->value
);
1345 if ( invokeModule
== NULL
)
1347 throw XMLInvalidBuildFileException (
1349 "module '%s' is trying to invoke non-existant module '%s'",
1350 module
.name
.c_str(),
1351 att
->value
.c_str() );
1355 for ( size_t i
= 0; i
< node
.subElements
.size (); i
++ )
1356 ProcessXMLSubElement ( *node
.subElements
[i
] );
1360 Invoke::ProcessXMLSubElement ( const XMLElement
& e
)
1362 bool subs_invalid
= false;
1363 if ( e
.name
== "input" )
1365 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1366 ProcessXMLSubElementInput ( *e
.subElements
[i
] );
1368 else if ( e
.name
== "output" )
1370 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1371 ProcessXMLSubElementOutput ( *e
.subElements
[i
] );
1373 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1375 throw XMLInvalidBuildFileException (
1377 "<%s> cannot have sub-elements",
1383 Invoke::ProcessXMLSubElementInput ( const XMLElement
& e
)
1385 bool subs_invalid
= false;
1386 if ( e
.name
== "inputfile" && e
.value
.size () > 0 )
1388 input
.push_back ( new InvokeFile (
1389 e
, FixSeparator ( module
.path
+ cSep
+ e
.value
) ) );
1390 subs_invalid
= true;
1392 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1394 throw XMLInvalidBuildFileException (
1396 "<%s> cannot have sub-elements",
1402 Invoke::ProcessXMLSubElementOutput ( const XMLElement
& e
)
1404 bool subs_invalid
= false;
1405 if ( e
.name
== "outputfile" && e
.value
.size () > 0 )
1407 output
.push_back ( new InvokeFile (
1408 e
, FixSeparator ( module
.path
+ cSep
+ e
.value
) ) );
1409 subs_invalid
= true;
1411 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1413 throw XMLInvalidBuildFileException (
1415 "<%s> cannot have sub-elements",
1421 Invoke::GetTargets ( string_list
& targets
) const
1423 for ( size_t i
= 0; i
< output
.size (); i
++ )
1425 InvokeFile
& file
= *output
[i
];
1426 targets
.push_back ( NormalizeFilename ( file
.name
) );
1431 Invoke::GetParameters () const
1433 string
parameters ( "" );
1435 for ( i
= 0; i
< output
.size (); i
++ )
1437 if ( parameters
.length () > 0)
1439 InvokeFile
& invokeFile
= *output
[i
];
1440 if ( invokeFile
.switches
.length () > 0 )
1442 parameters
+= invokeFile
.switches
+ " ";
1444 parameters
+= invokeFile
.name
;
1447 for ( i
= 0; i
< input
.size (); i
++ )
1449 if ( parameters
.length () > 0 )
1451 InvokeFile
& invokeFile
= *input
[i
];
1452 if ( invokeFile
.switches
.length () > 0 )
1454 parameters
+= invokeFile
.switches
;
1457 parameters
+= invokeFile
.name
;
1464 InvokeFile::InvokeFile ( const XMLElement
& _node
,
1465 const string
& _name
)
1469 const XMLAttribute
* att
= _node
.GetAttribute ( "switches", false );
1471 switches
= att
->value
;
1477 InvokeFile::ProcessXML()
1482 Dependency::Dependency ( const XMLElement
& _node
,
1483 const Module
& _module
)
1486 dependencyModule (NULL
)
1491 Dependency::ProcessXML()
1493 dependencyModule
= module
.project
.LocateModule ( node
.value
);
1494 if ( dependencyModule
== NULL
)
1496 throw XMLInvalidBuildFileException (
1498 "module '%s' depend on non-existant module '%s'",
1499 module
.name
.c_str(),
1500 node
.value
.c_str() );
1505 Metadata::Metadata ( const XMLElement
& _node
,
1506 const Module
& _module
)
1510 /* The module name */
1511 const XMLAttribute
* att
= _node
.GetAttribute ( "name", false );
1517 /* The module description */
1518 att
= _node
.GetAttribute ( "description", false );
1520 description
= att
->value
;
1524 /* The module version */
1525 att
= _node
.GetAttribute ( "version", false );
1527 version
= att
->value
;
1531 /* The module copyright */
1532 att
= _node
.GetAttribute ( "copyright", false );
1534 copyright
= att
->value
;
1538 att
= _node
.GetAttribute ( "url", false );
1544 /* When was this module updated */
1545 att
= _node
.GetAttribute ( "date", false );
1551 /* When was this module updated */
1552 att
= _node
.GetAttribute ( "owner", false );
1560 ImportLibrary::ImportLibrary ( const XMLElement
& _node
,
1561 const Module
& _module
)
1565 const XMLAttribute
* att
= _node
.GetAttribute ( "basename", false );
1567 basename
= att
->value
;
1569 basename
= module
.name
;
1571 att
= _node
.GetAttribute ( "dllname", false );
1573 dllname
= att
->value
;
1576 if ( _module
.type
== StaticLibrary
)
1578 throw XMLInvalidBuildFileException (
1580 "<importlibrary> dllname attribute required." );
1586 att
= _node
.GetAttribute ( "definition", true );
1588 definition
= FixSeparator(att
->value
);
1592 If::If ( const XMLElement
& node_
,
1593 const Project
& project_
,
1594 const Module
* module_
,
1595 const bool negated_
)
1596 : node(node_
), project(project_
), module(module_
), negated(negated_
)
1598 const XMLAttribute
* att
;
1600 att
= node
.GetAttribute ( "property", true );
1602 property
= att
->value
;
1604 att
= node
.GetAttribute ( "value", true );
1620 Property::Property ( const XMLElement
& node_
,
1621 const Project
& project_
,
1622 const Module
* module_
)
1623 : project(project_
), module(module_
)
1625 const XMLAttribute
* att
;
1627 att
= node_
.GetAttribute ( "name", true );
1631 att
= node_
.GetAttribute ( "value", true );
1636 Property::Property ( const Project
& project_
,
1637 const Module
* module_
,
1638 const std::string
& name_
,
1639 const std::string
& value_
)
1640 : project(project_
), module(module_
), name(name_
), value(value_
)
1645 Property::ProcessXML()
1651 const XMLElement
& node_
,
1652 const Module
& module_
,
1654 : node(node_
), module(module_
), file(file_
)
1659 PchFile::ProcessXML()
1664 AutoRegister::AutoRegister ( const Project
& project_
,
1665 const Module
* module_
,
1666 const XMLElement
& node_
)
1667 : project(project_
),
1674 AutoRegister::~AutoRegister ()
1679 AutoRegister::IsSupportedModuleType ( ModuleType type
)
1693 case KernelModeDriver
:
1703 case LiveIsoRegTest
:
1709 case EmbeddedTypeLib
:
1713 throw InvalidOperationException ( __FILE__
,
1718 AutoRegister::GetAutoRegisterType( string type
)
1720 if ( type
== "DllRegisterServer" )
1721 return DllRegisterServer
;
1722 if ( type
== "DllInstall" )
1724 if ( type
== "Both" )
1726 throw XMLInvalidBuildFileException (
1728 "<autoregister> type attribute must be DllRegisterServer, DllInstall or Both." );
1732 AutoRegister::Initialize ()
1734 if ( !IsSupportedModuleType ( module
->type
) )
1736 throw XMLInvalidBuildFileException (
1738 "<autoregister> is not applicable for this module type." );
1741 const XMLAttribute
* att
= node
.GetAttribute ( "infsection", true );
1742 infSection
= att
->value
;
1744 att
= node
.GetAttribute ( "type", true );
1745 type
= GetAutoRegisterType ( att
->value
);
1749 AutoRegister::ProcessXML()