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 GetExtension ( const FileLocation
& file
)
155 return GetExtension ( file
.name
);
159 NormalizeFilename ( const string
& filename
)
161 if ( filename
== "" )
164 string normalizedPath
= path
.Fixup ( filename
, true );
165 string relativeNormalizedPath
= path
.RelativeFromWorkingDirectory ( normalizedPath
);
166 return FixSeparator ( relativeNormalizedPath
);
170 GetBooleanValue ( const string
& value
)
179 ToLower ( string filename
)
181 for ( size_t i
= 1; i
< filename
.length (); i
++ )
182 filename
[i
] = tolower ( filename
[i
] );
186 IfableData::IfableData( )
191 void IfableData::ExtractModules( std::vector
<Module
*> &modules
)
194 for ( i
= 0; i
< this->modules
.size (); i
++ )
195 modules
.push_back(this->modules
[i
]);
198 IfableData::~IfableData()
201 for ( i
= 0; i
< includes
.size (); i
++ )
203 for ( i
= 0; i
< defines
.size (); i
++ )
205 for ( i
= 0; i
< libraries
.size (); i
++ )
207 for ( i
= 0; i
< properties
.size (); i
++ )
208 delete properties
[i
];
209 for ( i
= 0; i
< compilerFlags
.size (); i
++ )
210 delete compilerFlags
[i
];
211 for ( i
= 0; i
< modules
.size(); i
++ )
213 for ( i
= 0; i
< ifs
.size (); i
++ )
215 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
216 delete compilationUnits
[i
];
219 void IfableData::ProcessXML ()
222 for ( i
= 0; i
< includes
.size (); i
++ )
223 includes
[i
]->ProcessXML ();
224 for ( i
= 0; i
< defines
.size (); i
++ )
225 defines
[i
]->ProcessXML ();
226 for ( i
= 0; i
< libraries
.size (); i
++ )
227 libraries
[i
]->ProcessXML ();
228 for ( i
= 0; i
< properties
.size(); i
++ )
229 properties
[i
]->ProcessXML ();
230 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
231 compilerFlags
[i
]->ProcessXML ();
232 for ( i
= 0; i
< ifs
.size (); i
++ )
233 ifs
[i
]->ProcessXML ();
234 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
235 compilationUnits
[i
]->ProcessXML ();
238 Module::Module ( const Project
& project
,
239 const XMLElement
& moduleNode
,
240 const string
& modulePath
)
243 importLibrary (NULL
),
252 if ( node
.name
!= "module" )
253 throw InvalidOperationException ( __FILE__
,
255 "Module created with non-<module> node" );
257 xmlbuildFile
= FixSeparator ( Path::RelativeFromWorkingDirectory ( moduleNode
.xmlFile
->filename () ) );
259 const XMLAttribute
* att
= moduleNode
.GetAttribute ( "name", true );
265 att
= moduleNode
.GetAttribute ( "if", false );
267 enabled
= GetBooleanValue ( project
.ResolveProperties ( att
->value
) );
269 att
= moduleNode
.GetAttribute ( "ifnot", false );
271 enabled
= !GetBooleanValue ( project
.ResolveProperties ( att
->value
) );
273 if ( !enabled
&& project
.configuration
.Verbose
)
274 printf("Module '%s' has been disabled.\n", name
.c_str () );
276 att
= moduleNode
.GetAttribute ( "type", true );
278 type
= GetModuleType ( node
.location
, *att
);
280 att
= moduleNode
.GetAttribute ( "extension", false );
282 extension
= att
->value
;
284 extension
= GetDefaultModuleExtension ();
286 att
= moduleNode
.GetAttribute ( "unicode", false );
289 const char* p
= att
->value
.c_str();
290 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
292 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
296 throw InvalidAttributeValueException (
307 // Always define UNICODE and _UNICODE
308 Define
* pDefine
= new Define ( project
, this, "UNICODE" );
309 non_if_data
.defines
.push_back ( pDefine
);
311 pDefine
= new Define ( project
, this, "_UNICODE" );
312 non_if_data
.defines
.push_back ( pDefine
);
315 att
= moduleNode
.GetAttribute ( "entrypoint", false );
318 if ( att
->value
== "" )
320 throw InvalidAttributeValueException (
326 entrypoint
= att
->value
;
327 isDefaultEntryPoint
= false;
331 entrypoint
= GetDefaultModuleEntrypoint ();
332 isDefaultEntryPoint
= true;
335 att
= moduleNode
.GetAttribute ( "baseaddress", false );
337 baseaddress
= att
->value
;
339 baseaddress
= GetDefaultModuleBaseaddress ();
341 att
= moduleNode
.GetAttribute ( "mangledsymbols", false );
344 const char* p
= att
->value
.c_str();
345 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
346 mangledSymbols
= true;
347 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
348 mangledSymbols
= false;
351 throw InvalidAttributeValueException (
358 mangledSymbols
= false;
360 att
= moduleNode
.GetAttribute ( "underscoresymbols", false );
362 underscoreSymbols
= att
->value
== "true";
364 underscoreSymbols
= false;
366 att
= moduleNode
.GetAttribute ( "host", false );
369 const char* p
= att
->value
.c_str();
370 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
372 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
376 throw InvalidAttributeValueException (
383 att
= moduleNode
.GetAttribute ( "isstartuplib", false );
386 const char* p
= att
->value
.c_str();
387 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
389 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
390 isStartupLib
= false;
393 throw InvalidAttributeValueException (
400 isStartupLib
= false;
402 att
= moduleNode
.GetAttribute ( "prefix", false );
406 att
= moduleNode
.GetAttribute ( "installname", false );
409 const XMLAttribute
* installbase
= moduleNode
.GetAttribute ( "installbase", false );
410 install
= new FileLocation ( InstallDirectory
,
411 installbase
? installbase
->value
: "",
415 output
= new FileLocation ( GetTargetDirectoryTree (),
423 output
= new FileLocation ( GetTargetDirectoryTree (),
429 att
= moduleNode
.GetAttribute ( "allowwarnings", false );
432 att
= moduleNode
.GetAttribute ( "warnings", false );
435 printf ( "%s: WARNING: 'warnings' attribute of <module> is deprecated, use 'allowwarnings' instead\n",
436 moduleNode
.location
.c_str() );
440 allowWarnings
= att
->value
== "true";
442 allowWarnings
= false;
444 att
= moduleNode
.GetAttribute ( "aliasof", false );
445 if ( type
== Alias
&& att
!= NULL
)
446 aliasedModuleName
= att
->value
;
448 aliasedModuleName
= "";
450 if ( type
== BootProgram
)
452 att
= moduleNode
.GetAttribute ( "payload", true );
453 payload
= att
->value
;
456 if ( type
== BootProgram
|| type
== ElfExecutable
)
458 att
= moduleNode
.GetAttribute ( "buildtype", false );
461 buildtype
= att
->value
;
465 buildtype
= "BOOTPROG";
469 SetImportLibrary ( NULL
);
475 for ( i
= 0; i
< invocations
.size(); i
++ )
476 delete invocations
[i
];
477 for ( i
= 0; i
< dependencies
.size(); i
++ )
478 delete dependencies
[i
];
479 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
480 delete compilerFlags
[i
];
481 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
482 delete linkerFlags
[i
];
483 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
484 delete stubbedComponents
[i
];
496 aliasedModuleName
= project
.ResolveProperties ( aliasedModuleName
);
497 if ( aliasedModuleName
== name
)
499 throw XMLInvalidBuildFileException (
501 "module '%s' cannot link against itself",
504 const Module
* m
= project
.LocateModule ( aliasedModuleName
);
507 throw XMLInvalidBuildFileException (
509 "module '%s' trying to alias non-existant module '%s'",
511 aliasedModuleName
.c_str() );
516 for ( i
= 0; i
< node
.subElements
.size(); i
++ )
518 ParseContext parseContext
;
519 ProcessXMLSubElement ( *node
.subElements
[i
], SourceDirectory
, output
->relative_path
, parseContext
);
521 for ( i
= 0; i
< invocations
.size(); i
++ )
522 invocations
[i
]->ProcessXML ();
523 for ( i
= 0; i
< dependencies
.size(); i
++ )
524 dependencies
[i
]->ProcessXML ();
525 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
526 compilerFlags
[i
]->ProcessXML();
527 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
528 linkerFlags
[i
]->ProcessXML();
529 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
530 stubbedComponents
[i
]->ProcessXML();
531 non_if_data
.ProcessXML();
533 linkerScript
->ProcessXML();
537 autoRegister
->ProcessXML();
541 Module::ProcessXMLSubElement ( const XMLElement
& e
,
542 DirectoryLocation directory
,
543 const string
& relative_path
,
544 ParseContext
& parseContext
)
546 If
* pOldIf
= parseContext
.ifData
;
547 CompilationUnit
* pOldCompilationUnit
= parseContext
.compilationUnit
;
548 bool subs_invalid
= false;
549 string
subpath ( relative_path
);
550 DirectoryLocation subdirectory
= SourceDirectory
;
551 if ( e
.name
== "file" && e
.value
.size () > 0 )
554 const XMLAttribute
* att
= e
.GetAttribute ( "first", false );
557 if ( !stricmp ( att
->value
.c_str(), "true" ) )
559 else if ( stricmp ( att
->value
.c_str(), "false" ) )
561 throw XMLInvalidBuildFileException (
563 "attribute 'first' of <file> element can only be 'true' or 'false'" );
566 string switches
= "";
567 att
= e
.GetAttribute ( "switches", false );
569 switches
= att
->value
;
572 // check for c++ file
573 string ext
= GetExtension ( e
.value
);
574 if ( !stricmp ( ext
.c_str(), ".cpp" ) )
576 else if ( !stricmp ( ext
.c_str(), ".cc" ) )
578 else if ( !stricmp ( ext
.c_str(), ".cxx" ) )
581 File
* pFile
= new File ( directory
,
587 if ( parseContext
.compilationUnit
)
588 parseContext
.compilationUnit
->AddFile ( pFile
);
591 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( pFile
);
592 if ( parseContext
.ifData
)
593 parseContext
.ifData
->data
.compilationUnits
.push_back ( pCompilationUnit
);
596 string ext
= ToLower ( GetExtension ( e
.value
) );
599 // put .idl files at the start of the module
600 non_if_data
.compilationUnits
.insert (
601 non_if_data
.compilationUnits
.begin(),
604 else if ( ext
== ".asm" || ext
== ".s" )
606 // put .asm files at the end of the module
607 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
608 non_if_data
.asmFiles
++;
612 // put other files in the middle
613 non_if_data
.compilationUnits
.insert (
614 non_if_data
.compilationUnits
.end() - non_if_data
.asmFiles
,
619 if ( parseContext
.ifData
)
620 parseContext
.ifData
->data
.files
.push_back ( pFile
);
622 non_if_data
.files
.push_back ( pFile
);
625 else if ( e
.name
== "library" && e
.value
.size () )
627 Library
* pLibrary
= new Library ( e
, *this, e
.value
);
628 if ( parseContext
.ifData
)
629 parseContext
.ifData
->data
.libraries
.push_back ( pLibrary
);
631 non_if_data
.libraries
.push_back ( pLibrary
);
634 else if ( e
.name
== "directory" )
636 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
637 const XMLAttribute
* root
= e
.GetAttribute ( "root", false );
641 if ( root
->value
== "intermediate" )
642 subdirectory
= IntermediateDirectory
;
643 else if ( root
->value
== "output" )
644 subdirectory
= OutputDirectory
;
647 throw InvalidAttributeValueException (
653 subpath
= GetSubPath ( this->project
, e
.location
, relative_path
, att
->value
);
655 else if ( e
.name
== "include" )
657 Include
* include
= new Include ( project
, &e
, this );
658 if ( parseContext
.ifData
)
659 parseContext
.ifData
->data
.includes
.push_back ( include
);
661 non_if_data
.includes
.push_back ( include
);
664 else if ( e
.name
== "define" )
666 Define
* pDefine
= new Define ( project
, this, e
);
667 if ( parseContext
.ifData
)
668 parseContext
.ifData
->data
.defines
.push_back ( pDefine
);
670 non_if_data
.defines
.push_back ( pDefine
);
673 else if ( e
.name
== "metadata" )
675 if ( parseContext
.ifData
)
677 throw XMLInvalidBuildFileException (
679 "<metadata> is not a valid sub-element of <if>" );
681 metadata
= new Metadata ( e
, *this );
682 subs_invalid
= false;
684 else if ( e
.name
== "invoke" )
686 if ( parseContext
.ifData
)
688 throw XMLInvalidBuildFileException (
690 "<invoke> is not a valid sub-element of <if>" );
692 invocations
.push_back ( new Invoke ( e
, *this ) );
693 subs_invalid
= false;
695 else if ( e
.name
== "dependency" )
697 if ( parseContext
.ifData
)
699 throw XMLInvalidBuildFileException (
701 "<dependency> is not a valid sub-element of <if>" );
703 dependencies
.push_back ( new Dependency ( e
, *this ) );
706 else if ( e
.name
== "importlibrary" )
708 if ( parseContext
.ifData
)
710 throw XMLInvalidBuildFileException (
712 "<importlibrary> is not a valid sub-element of <if>" );
716 throw XMLInvalidBuildFileException (
718 "Only one <importlibrary> is valid per module" );
720 SetImportLibrary ( new ImportLibrary ( project
, e
, *this ) );
723 else if ( e
.name
== "if" )
725 parseContext
.ifData
= new If ( e
, project
, this );
727 pOldIf
->data
.ifs
.push_back ( parseContext
.ifData
);
729 non_if_data
.ifs
.push_back ( parseContext
.ifData
);
730 subs_invalid
= false;
732 else if ( e
.name
== "ifnot" )
734 parseContext
.ifData
= new If ( e
, project
, this, true );
736 pOldIf
->data
.ifs
.push_back ( parseContext
.ifData
);
738 non_if_data
.ifs
.push_back ( parseContext
.ifData
);
739 subs_invalid
= false;
741 else if ( e
.name
== "compilerflag" )
743 CompilerFlag
* pCompilerFlag
= new CompilerFlag ( project
, this, e
);
744 if ( parseContext
.ifData
)
745 parseContext
.ifData
->data
.compilerFlags
.push_back ( pCompilerFlag
);
747 non_if_data
.compilerFlags
.push_back ( pCompilerFlag
);
750 else if ( e
.name
== "linkerflag" )
752 linkerFlags
.push_back ( new LinkerFlag ( project
, this, e
) );
755 else if ( e
.name
== "linkerscript" )
757 if ( parseContext
.ifData
)
759 throw XMLInvalidBuildFileException (
761 "<linkerscript> is not a valid sub-element of <if>" );
765 throw XMLInvalidBuildFileException (
767 "Only one <linkerscript> is valid per module" );
769 size_t pos
= e
.value
.find_last_of ( "/\\" );
770 if ( pos
== string::npos
)
772 linkerScript
= new LinkerScript (
773 e
, *this, FileLocation ( SourceDirectory
, relative_path
, e
.value
, &e
) );
777 string dir
= e
.value
.substr ( 0, pos
);
778 string name
= e
.value
.substr ( pos
+ 1);
779 linkerScript
= new LinkerScript (
780 e
, *this, FileLocation ( SourceDirectory
, relative_path
+ sSep
+ dir
, name
, &e
) );
784 else if ( e
.name
== "component" )
786 stubbedComponents
.push_back ( new StubbedComponent ( this, e
) );
787 subs_invalid
= false;
789 else if ( e
.name
== "property" )
791 throw XMLInvalidBuildFileException (
793 "<property> is not a valid sub-element of <module>" );
795 else if ( e
.name
== "bootstrap" )
797 bootstrap
= new Bootstrap ( project
, this, e
);
800 else if ( e
.name
== "pch" )
802 if ( parseContext
.ifData
)
804 throw XMLInvalidBuildFileException (
806 "<pch> is not a valid sub-element of <if>" );
810 throw XMLInvalidBuildFileException (
812 "Only one <pch> is valid per module" );
814 size_t pos
= e
.value
.find_last_of ( "/\\" );
815 if ( pos
== string::npos
)
818 e
, *this, FileLocation ( SourceDirectory
, relative_path
, e
.value
, &e
) );
822 string dir
= e
.value
.substr ( 0, pos
);
823 string name
= e
.value
.substr ( pos
+ 1);
825 e
, *this, FileLocation ( SourceDirectory
, relative_path
+ sSep
+ dir
, name
, &e
) );
829 else if ( e
.name
== "compilationunit" )
831 if ( project
.configuration
.CompilationUnitsEnabled
)
833 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( &project
, this, &e
);
834 if ( parseContext
.ifData
)
835 parseContext
.ifData
->data
.compilationUnits
.push_back ( pCompilationUnit
);
837 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
838 parseContext
.compilationUnit
= pCompilationUnit
;
840 subs_invalid
= false;
842 else if ( e
.name
== "autoregister" )
844 if ( autoRegister
!= NULL
)
846 throw XMLInvalidBuildFileException (
848 "there can be only one <%s> element for a module",
851 autoRegister
= new AutoRegister ( project
, this, e
);
854 if ( subs_invalid
&& e
.subElements
.size() > 0 )
856 throw XMLInvalidBuildFileException (
858 "<%s> cannot have sub-elements",
861 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
862 ProcessXMLSubElement ( *e
.subElements
[i
], subdirectory
, subpath
, parseContext
);
863 parseContext
.ifData
= pOldIf
;
864 parseContext
.compilationUnit
= pOldCompilationUnit
;
868 Module::GetModuleType ( const string
& location
, const XMLAttribute
& attribute
)
870 if ( attribute
.value
== "buildtool" )
872 if ( attribute
.value
== "staticlibrary" )
873 return StaticLibrary
;
874 if ( attribute
.value
== "objectlibrary" )
875 return ObjectLibrary
;
876 if ( attribute
.value
== "kernel" )
878 if ( attribute
.value
== "kernelmodedll" )
879 return KernelModeDLL
;
880 if ( attribute
.value
== "kernelmodedriver" )
881 return KernelModeDriver
;
882 if ( attribute
.value
== "nativedll" )
884 if ( attribute
.value
== "nativecui" )
886 if ( attribute
.value
== "win32dll" )
888 if ( attribute
.value
== "win32ocx" )
890 if ( attribute
.value
== "win32cui" )
892 if ( attribute
.value
== "win32gui" )
894 if ( attribute
.value
== "win32scr" )
896 if ( attribute
.value
== "bootloader" )
898 if ( attribute
.value
== "bootsector" )
900 if ( attribute
.value
== "bootprogram" )
902 if ( attribute
.value
== "iso" )
904 if ( attribute
.value
== "liveiso" )
906 if ( attribute
.value
== "isoregtest" )
908 if ( attribute
.value
== "liveisoregtest" )
909 return LiveIsoRegTest
;
910 if ( attribute
.value
== "test" )
912 if ( attribute
.value
== "rpcserver" )
914 if ( attribute
.value
== "rpcclient" )
916 if ( attribute
.value
== "rpcproxy" )
918 if ( attribute
.value
== "alias" )
920 if ( attribute
.value
== "idlheader" )
922 if ( attribute
.value
== "embeddedtypelib" )
923 return EmbeddedTypeLib
;
924 if ( attribute
.value
== "elfexecutable" )
925 return ElfExecutable
;
926 throw InvalidAttributeValueException ( location
,
932 Module::GetTargetDirectoryTree () const
941 case KernelModeDriver
:
955 case EmbeddedTypeLib
:
957 return OutputDirectory
;
965 return IntermediateDirectory
;
969 throw InvalidOperationException ( __FILE__
,
971 "Invalid module type %d.",
976 Module::GetDefaultModuleExtension () const
1001 case KernelModeDriver
:
1009 case LiveIsoRegTest
:
1021 case EmbeddedTypeLib
:
1026 throw InvalidOperationException ( __FILE__
,
1031 Module::GetDefaultModuleEntrypoint () const
1036 return "KiSystemStartup";
1038 case KernelModeDriver
:
1039 return "DriverEntry@8";
1041 return "DllMainCRTStartup@12";
1043 return "NtProcessStartup@4";
1046 return "DllMain@12";
1050 return "wmainCRTStartup";
1052 return "mainCRTStartup";
1056 return "wWinMainCRTStartup";
1058 return "WinMainCRTStartup";
1067 case LiveIsoRegTest
:
1075 case EmbeddedTypeLib
:
1080 throw InvalidOperationException ( __FILE__
,
1085 Module::GetDefaultModuleBaseaddress () const
1090 return "0x80800000";
1093 return "0x10000000";
1098 return "0x00400000";
1101 return "0x00400000";
1103 case KernelModeDriver
:
1104 return "0x00010000";
1115 case LiveIsoRegTest
:
1122 case EmbeddedTypeLib
:
1127 throw InvalidOperationException ( __FILE__
,
1132 Module::HasImportLibrary () const
1134 return importLibrary
!= NULL
&& type
!= StaticLibrary
;
1138 Module::IsDLL () const
1147 case KernelModeDriver
:
1163 case LiveIsoRegTest
:
1169 case EmbeddedTypeLib
:
1175 throw InvalidOperationException ( __FILE__
,
1180 Module::GetPathWithPrefix ( const string
& prefix
) const
1182 return output
->relative_path
+ cSep
+ prefix
+ output
->name
;
1186 Module::GetPathToBaseDir () const
1188 string temp_path
= output
->relative_path
;
1189 string result
= "..\\";
1190 while(temp_path
.find ('\\') != string::npos
)
1192 temp_path
.erase (0, temp_path
.find('\\')+1);
1199 Module::GetInvocationTarget ( const int index
) const
1201 return ssprintf ( "%s_invoke_%d",
1207 Module::GetEntryPoint(bool leadingUnderscore
) const
1210 if (entrypoint
== "0" || entrypoint
== "0x0")
1212 if (leadingUnderscore
)
1215 result
+= entrypoint
;
1220 Module::HasFileWithExtension (
1221 const IfableData
& data
,
1222 const std::string
& extension
) const
1225 for ( i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1227 CompilationUnit
* compilationUnit
= data
.compilationUnits
[i
];
1228 if ( compilationUnit
->HasFileWithExtension ( extension
) )
1231 for ( i
= 0; i
< data
.ifs
.size (); i
++ )
1233 if ( HasFileWithExtension ( data
.ifs
[i
]->data
, extension
) )
1240 Module::InvokeModule () const
1242 for ( size_t i
= 0; i
< invocations
.size (); i
++ )
1244 Invoke
& invoke
= *invocations
[i
];
1245 string command
= FixSeparatorForSystemCommand(invoke
.invokeModule
->output
->relative_path
+ "/" + invoke
.invokeModule
->output
->name
) + " " + invoke
.GetParameters ();
1246 printf ( "Executing '%s'\n\n", command
.c_str () );
1247 int exitcode
= system ( command
.c_str () );
1248 if ( exitcode
!= 0 )
1249 throw InvocationFailedException ( command
,
1256 Module::SetImportLibrary ( ImportLibrary
* importLibrary
)
1258 this->importLibrary
= importLibrary
;
1259 dependency
= new FileLocation ( HasImportLibrary () ? IntermediateDirectory
: output
->directory
,
1260 output
->relative_path
,
1261 HasImportLibrary () ? "lib" + name
+ ".a" : output
->name
);
1265 File::File ( DirectoryLocation directory
,
1266 const string
& relative_path
,
1269 const string
& _switches
,
1270 bool _isPreCompiledHeader
)
1271 : file ( directory
, relative_path
, name
),
1273 switches(_switches
),
1274 isPreCompiledHeader(_isPreCompiledHeader
)
1285 std::string
File::GetFullPath () const
1287 string
directory ( "" );
1288 switch ( file
.directory
)
1290 case SourceDirectory
:
1292 case IntermediateDirectory
:
1293 directory
= Environment::GetIntermediatePath () + sSep
;
1296 throw InvalidOperationException ( __FILE__
,
1298 "Invalid directory %d.",
1302 if ( file
.relative_path
.length () > 0 )
1303 directory
+= file
.relative_path
+ sSep
;
1306 return directory
+ file
.name
;
1310 Library::Library ( const XMLElement
& _node
,
1311 const Module
& _module
,
1312 const string
& _name
)
1316 importedModule(_module
.project
.LocateModule(_name
))
1318 if ( module
.name
== name
)
1320 throw XMLInvalidBuildFileException (
1322 "module '%s' cannot link against itself",
1325 if ( !importedModule
)
1327 throw XMLInvalidBuildFileException (
1329 "module '%s' trying to import non-existant module '%s'",
1330 module
.name
.c_str(),
1335 Library::Library ( const Module
& _module
,
1336 const string
& _name
)
1340 importedModule(_module
.project
.LocateModule(_name
))
1345 Library::ProcessXML()
1347 if ( node
&& !module
.project
.LocateModule ( name
) )
1349 throw XMLInvalidBuildFileException (
1351 "module '%s' is trying to link against non-existant module '%s'",
1352 module
.name
.c_str(),
1358 Invoke::Invoke ( const XMLElement
& _node
,
1359 const Module
& _module
)
1366 Invoke::ProcessXML()
1368 const XMLAttribute
* att
= node
.GetAttribute ( "module", false );
1370 invokeModule
= &module
;
1373 invokeModule
= module
.project
.LocateModule ( att
->value
);
1374 if ( invokeModule
== NULL
)
1376 throw XMLInvalidBuildFileException (
1378 "module '%s' is trying to invoke non-existant module '%s'",
1379 module
.name
.c_str(),
1380 att
->value
.c_str() );
1384 for ( size_t i
= 0; i
< node
.subElements
.size (); i
++ )
1385 ProcessXMLSubElement ( *node
.subElements
[i
] );
1389 Invoke::ProcessXMLSubElement ( const XMLElement
& e
)
1391 bool subs_invalid
= false;
1392 if ( e
.name
== "input" )
1394 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1395 ProcessXMLSubElementInput ( *e
.subElements
[i
] );
1397 else if ( e
.name
== "output" )
1399 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1400 ProcessXMLSubElementOutput ( *e
.subElements
[i
] );
1402 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1404 throw XMLInvalidBuildFileException (
1406 "<%s> cannot have sub-elements",
1412 Invoke::ProcessXMLSubElementInput ( const XMLElement
& e
)
1414 bool subs_invalid
= false;
1415 if ( e
.name
== "inputfile" && e
.value
.size () > 0 )
1417 input
.push_back ( new InvokeFile (
1418 e
, FixSeparator ( module
.output
->relative_path
+ cSep
+ e
.value
) ) );
1419 subs_invalid
= true;
1421 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1423 throw XMLInvalidBuildFileException (
1425 "<%s> cannot have sub-elements",
1431 Invoke::ProcessXMLSubElementOutput ( const XMLElement
& e
)
1433 bool subs_invalid
= false;
1434 if ( e
.name
== "outputfile" && e
.value
.size () > 0 )
1436 output
.push_back ( new InvokeFile (
1437 e
, FixSeparator ( module
.output
->relative_path
+ cSep
+ e
.value
) ) );
1438 subs_invalid
= true;
1440 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1442 throw XMLInvalidBuildFileException (
1444 "<%s> cannot have sub-elements",
1450 Invoke::GetTargets ( string_list
& targets
) const
1452 for ( size_t i
= 0; i
< output
.size (); i
++ )
1454 InvokeFile
& file
= *output
[i
];
1455 targets
.push_back ( NormalizeFilename ( file
.name
) );
1460 Invoke::GetParameters () const
1462 string
parameters ( "" );
1464 for ( i
= 0; i
< output
.size (); i
++ )
1466 if ( parameters
.length () > 0)
1468 InvokeFile
& invokeFile
= *output
[i
];
1469 if ( invokeFile
.switches
.length () > 0 )
1471 parameters
+= invokeFile
.switches
+ " ";
1473 parameters
+= invokeFile
.name
;
1476 for ( i
= 0; i
< input
.size (); i
++ )
1478 if ( parameters
.length () > 0 )
1480 InvokeFile
& invokeFile
= *input
[i
];
1481 if ( invokeFile
.switches
.length () > 0 )
1483 parameters
+= invokeFile
.switches
;
1486 parameters
+= invokeFile
.name
;
1493 InvokeFile::InvokeFile ( const XMLElement
& _node
,
1494 const string
& _name
)
1498 const XMLAttribute
* att
= _node
.GetAttribute ( "switches", false );
1500 switches
= att
->value
;
1506 InvokeFile::ProcessXML()
1511 Dependency::Dependency ( const XMLElement
& _node
,
1512 const Module
& _module
)
1515 dependencyModule (NULL
)
1520 Dependency::ProcessXML()
1522 dependencyModule
= module
.project
.LocateModule ( node
.value
);
1523 if ( dependencyModule
== NULL
)
1525 throw XMLInvalidBuildFileException (
1527 "module '%s' depend on non-existant module '%s'",
1528 module
.name
.c_str(),
1529 node
.value
.c_str() );
1534 Metadata::Metadata ( const XMLElement
& _node
,
1535 const Module
& _module
)
1539 /* The module name */
1540 const XMLAttribute
* att
= _node
.GetAttribute ( "name", false );
1546 /* The module description */
1547 att
= _node
.GetAttribute ( "description", false );
1549 description
= att
->value
;
1553 /* The module version */
1554 att
= _node
.GetAttribute ( "version", false );
1556 version
= att
->value
;
1560 /* The module copyright */
1561 att
= _node
.GetAttribute ( "copyright", false );
1563 copyright
= att
->value
;
1567 att
= _node
.GetAttribute ( "url", false );
1573 /* When was this module updated */
1574 att
= _node
.GetAttribute ( "date", false );
1580 /* When was this module updated */
1581 att
= _node
.GetAttribute ( "owner", false );
1589 ImportLibrary::ImportLibrary ( const Project
& project
,
1590 const XMLElement
& node
,
1591 const Module
& module
)
1592 : XmlNode ( project
, node
),
1595 const XMLAttribute
* dllname
= node
.GetAttribute ( "dllname", false );
1596 const XMLAttribute
* definition
= node
.GetAttribute ( "definition", true );
1597 assert ( definition
);
1600 this->dllname
= dllname
->value
;
1601 else if ( module
.type
== StaticLibrary
)
1602 throw XMLInvalidBuildFileException (
1604 "<importlibrary> dllname attribute required." );
1606 DirectoryLocation directory
= SourceDirectory
;
1607 size_t index
= definition
->value
.rfind ( ".spec.def" );
1608 if ( index
!= string::npos
)
1609 directory
= IntermediateDirectory
;
1611 index
= definition
->value
.find_last_of ( "/\\" );
1612 if ( index
== string::npos
)
1614 source
= new FileLocation ( directory
,
1615 module
.output
->relative_path
,
1621 string dir
= definition
->value
.substr ( 0, index
);
1622 string name
= definition
->value
.substr ( index
+ 1);
1623 source
= new FileLocation ( directory
,
1624 NormalizeFilename ( module
.output
->relative_path
+ sSep
+ dir
),
1631 If::If ( const XMLElement
& node_
,
1632 const Project
& project_
,
1633 const Module
* module_
,
1634 const bool negated_
)
1635 : node(node_
), project(project_
), module(module_
), negated(negated_
)
1637 const XMLAttribute
* att
;
1639 att
= node
.GetAttribute ( "property", true );
1641 property
= att
->value
;
1643 att
= node
.GetAttribute ( "value", true );
1659 Property::Property ( const XMLElement
& node_
,
1660 const Project
& project_
,
1661 const Module
* module_
)
1662 : project(project_
), module(module_
)
1664 const XMLAttribute
* att
;
1666 att
= node_
.GetAttribute ( "name", true );
1668 name
= project
.ResolveProperties ( att
->value
);
1670 att
= node_
.GetAttribute ( "value", true );
1675 Property::Property ( const Project
& project_
,
1676 const Module
* module_
,
1677 const std::string
& name_
,
1678 const std::string
& value_
)
1679 : project(project_
), module(module_
), name(name_
), value(value_
)
1684 Property::ProcessXML()
1690 const XMLElement
& node_
,
1691 const Module
& module_
,
1692 const FileLocation
& file_
)
1693 : node(node_
), module(module_
), file(file_
)
1698 PchFile::ProcessXML()