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 delete importLibrary
;
510 aliasedModuleName
= project
.ResolveProperties ( aliasedModuleName
);
511 if ( aliasedModuleName
== name
)
513 throw XMLInvalidBuildFileException (
515 "module '%s' cannot link against itself",
518 const Module
* m
= project
.LocateModule ( aliasedModuleName
);
521 throw XMLInvalidBuildFileException (
523 "module '%s' trying to alias non-existant module '%s'",
525 aliasedModuleName
.c_str() );
530 for ( i
= 0; i
< node
.subElements
.size(); i
++ )
532 ParseContext parseContext
;
533 ProcessXMLSubElement ( *node
.subElements
[i
], SourceDirectory
, output
->relative_path
, parseContext
);
535 for ( i
= 0; i
< invocations
.size(); i
++ )
536 invocations
[i
]->ProcessXML ();
537 for ( i
= 0; i
< dependencies
.size(); i
++ )
538 dependencies
[i
]->ProcessXML ();
539 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
540 compilerFlags
[i
]->ProcessXML();
541 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
542 linkerFlags
[i
]->ProcessXML();
543 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
544 stubbedComponents
[i
]->ProcessXML();
545 non_if_data
.ProcessXML();
547 linkerScript
->ProcessXML();
551 autoRegister
->ProcessXML();
555 Module::ProcessXMLSubElement ( const XMLElement
& e
,
556 DirectoryLocation directory
,
557 const string
& relative_path
,
558 ParseContext
& parseContext
)
560 If
* pOldIf
= parseContext
.ifData
;
561 CompilationUnit
* pOldCompilationUnit
= parseContext
.compilationUnit
;
562 bool subs_invalid
= false;
563 string
subpath ( relative_path
);
564 DirectoryLocation subdirectory
= SourceDirectory
;
565 if ( e
.name
== "file" && e
.value
.size () > 0 )
568 const XMLAttribute
* att
= e
.GetAttribute ( "first", false );
571 if ( !stricmp ( att
->value
.c_str(), "true" ) )
573 else if ( stricmp ( att
->value
.c_str(), "false" ) )
575 throw XMLInvalidBuildFileException (
577 "attribute 'first' of <file> element can only be 'true' or 'false'" );
580 string switches
= "";
581 att
= e
.GetAttribute ( "switches", false );
583 switches
= att
->value
;
586 // check for c++ file
587 string ext
= GetExtension ( e
.value
);
588 if ( !stricmp ( ext
.c_str(), ".cpp" ) )
590 else if ( !stricmp ( ext
.c_str(), ".cc" ) )
592 else if ( !stricmp ( ext
.c_str(), ".cxx" ) )
595 File
* pFile
= new File ( directory
,
601 if ( parseContext
.compilationUnit
)
602 parseContext
.compilationUnit
->AddFile ( pFile
);
605 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( pFile
);
606 if ( parseContext
.ifData
)
607 parseContext
.ifData
->data
.compilationUnits
.push_back ( pCompilationUnit
);
610 string ext
= ToLower ( GetExtension ( e
.value
) );
613 // put .idl files at the start of the module
614 non_if_data
.compilationUnits
.insert (
615 non_if_data
.compilationUnits
.begin(),
618 else if ( ext
== ".asm" || ext
== ".s" )
620 // put .asm files at the end of the module
621 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
622 non_if_data
.asmFiles
++;
626 // put other files in the middle
627 non_if_data
.compilationUnits
.insert (
628 non_if_data
.compilationUnits
.end() - non_if_data
.asmFiles
,
633 if ( parseContext
.ifData
)
634 parseContext
.ifData
->data
.files
.push_back ( pFile
);
636 non_if_data
.files
.push_back ( pFile
);
639 else if ( e
.name
== "library" && e
.value
.size () )
641 Library
* pLibrary
= new Library ( e
, *this, e
.value
);
642 if ( parseContext
.ifData
)
643 parseContext
.ifData
->data
.libraries
.push_back ( pLibrary
);
645 non_if_data
.libraries
.push_back ( pLibrary
);
648 else if ( e
.name
== "directory" )
650 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
651 const XMLAttribute
* root
= e
.GetAttribute ( "root", false );
655 if ( root
->value
== "intermediate" )
656 subdirectory
= IntermediateDirectory
;
657 else if ( root
->value
== "output" )
658 subdirectory
= OutputDirectory
;
661 throw InvalidAttributeValueException (
667 subpath
= GetSubPath ( this->project
, e
.location
, relative_path
, att
->value
);
669 else if ( e
.name
== "include" )
671 Include
* include
= new Include ( project
, &e
, this );
672 if ( parseContext
.ifData
)
673 parseContext
.ifData
->data
.includes
.push_back ( include
);
675 non_if_data
.includes
.push_back ( include
);
678 else if ( e
.name
== "define" )
680 Define
* pDefine
= new Define ( project
, this, e
);
681 if ( parseContext
.ifData
)
682 parseContext
.ifData
->data
.defines
.push_back ( pDefine
);
684 non_if_data
.defines
.push_back ( pDefine
);
687 else if ( e
.name
== "metadata" )
689 if ( parseContext
.ifData
)
691 throw XMLInvalidBuildFileException (
693 "<metadata> is not a valid sub-element of <if>" );
695 metadata
= new Metadata ( e
, *this );
696 subs_invalid
= false;
698 else if ( e
.name
== "invoke" )
700 if ( parseContext
.ifData
)
702 throw XMLInvalidBuildFileException (
704 "<invoke> is not a valid sub-element of <if>" );
706 invocations
.push_back ( new Invoke ( e
, *this ) );
707 subs_invalid
= false;
709 else if ( e
.name
== "dependency" )
711 if ( parseContext
.ifData
)
713 throw XMLInvalidBuildFileException (
715 "<dependency> is not a valid sub-element of <if>" );
717 dependencies
.push_back ( new Dependency ( e
, *this ) );
720 else if ( e
.name
== "importlibrary" )
722 if ( parseContext
.ifData
)
724 throw XMLInvalidBuildFileException (
726 "<importlibrary> is not a valid sub-element of <if>" );
730 throw XMLInvalidBuildFileException (
732 "Only one <importlibrary> is valid per module" );
734 SetImportLibrary ( new ImportLibrary ( project
, e
, *this ) );
737 else if ( e
.name
== "if" )
739 parseContext
.ifData
= new If ( e
, project
, this );
741 pOldIf
->data
.ifs
.push_back ( parseContext
.ifData
);
743 non_if_data
.ifs
.push_back ( parseContext
.ifData
);
744 subs_invalid
= false;
746 else if ( e
.name
== "ifnot" )
748 parseContext
.ifData
= new If ( e
, project
, this, true );
750 pOldIf
->data
.ifs
.push_back ( parseContext
.ifData
);
752 non_if_data
.ifs
.push_back ( parseContext
.ifData
);
753 subs_invalid
= false;
755 else if ( e
.name
== "compilerflag" )
757 CompilerFlag
* pCompilerFlag
= new CompilerFlag ( project
, this, e
);
758 if ( parseContext
.ifData
)
759 parseContext
.ifData
->data
.compilerFlags
.push_back ( pCompilerFlag
);
761 non_if_data
.compilerFlags
.push_back ( pCompilerFlag
);
764 else if ( e
.name
== "linkerflag" )
766 linkerFlags
.push_back ( new LinkerFlag ( project
, this, e
) );
769 else if ( e
.name
== "linkerscript" )
771 if ( parseContext
.ifData
)
773 throw XMLInvalidBuildFileException (
775 "<linkerscript> is not a valid sub-element of <if>" );
779 throw XMLInvalidBuildFileException (
781 "Only one <linkerscript> is valid per module" );
783 size_t pos
= e
.value
.find_last_of ( "/\\" );
784 if ( pos
== string::npos
)
786 linkerScript
= new LinkerScript (
787 e
, *this, new FileLocation ( SourceDirectory
, relative_path
, e
.value
, &e
) );
791 string dir
= e
.value
.substr ( 0, pos
);
792 string name
= e
.value
.substr ( pos
+ 1);
793 linkerScript
= new LinkerScript (
794 e
, *this, new FileLocation ( SourceDirectory
, relative_path
+ sSep
+ dir
, name
, &e
) );
798 else if ( e
.name
== "component" )
800 stubbedComponents
.push_back ( new StubbedComponent ( this, e
) );
801 subs_invalid
= false;
803 else if ( e
.name
== "property" )
805 throw XMLInvalidBuildFileException (
807 "<property> is not a valid sub-element of <module>" );
809 else if ( e
.name
== "bootstrap" )
811 bootstrap
= new Bootstrap ( project
, this, e
);
814 else if ( e
.name
== "pch" )
816 if ( parseContext
.ifData
)
818 throw XMLInvalidBuildFileException (
820 "<pch> is not a valid sub-element of <if>" );
824 throw XMLInvalidBuildFileException (
826 "Only one <pch> is valid per module" );
828 size_t pos
= e
.value
.find_last_of ( "/\\" );
829 if ( pos
== string::npos
)
832 e
, *this, new FileLocation ( SourceDirectory
, relative_path
, e
.value
, &e
) );
836 string dir
= e
.value
.substr ( 0, pos
);
837 string name
= e
.value
.substr ( pos
+ 1);
839 e
, *this, new FileLocation ( SourceDirectory
, relative_path
+ sSep
+ dir
, name
, &e
) );
843 else if ( e
.name
== "compilationunit" )
845 if ( project
.configuration
.CompilationUnitsEnabled
)
847 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( &project
, this, &e
);
848 if ( parseContext
.ifData
)
849 parseContext
.ifData
->data
.compilationUnits
.push_back ( pCompilationUnit
);
851 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
852 parseContext
.compilationUnit
= pCompilationUnit
;
854 subs_invalid
= false;
856 else if ( e
.name
== "autoregister" )
858 if ( autoRegister
!= NULL
)
860 throw XMLInvalidBuildFileException (
862 "there can be only one <%s> element for a module",
865 autoRegister
= new AutoRegister ( project
, this, e
);
868 if ( subs_invalid
&& e
.subElements
.size() > 0 )
870 throw XMLInvalidBuildFileException (
872 "<%s> cannot have sub-elements",
875 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
876 ProcessXMLSubElement ( *e
.subElements
[i
], subdirectory
, subpath
, parseContext
);
877 parseContext
.ifData
= pOldIf
;
878 parseContext
.compilationUnit
= pOldCompilationUnit
;
882 Module::GetModuleType ( const string
& location
, const XMLAttribute
& attribute
)
884 if ( attribute
.value
== "buildtool" )
886 if ( attribute
.value
== "staticlibrary" )
887 return StaticLibrary
;
888 if ( attribute
.value
== "hoststaticlibrary" )
889 return HostStaticLibrary
;
890 if ( attribute
.value
== "objectlibrary" )
891 return ObjectLibrary
;
892 if ( attribute
.value
== "kernel" )
894 if ( attribute
.value
== "kernelmodedll" )
895 return KernelModeDLL
;
896 if ( attribute
.value
== "kernelmodedriver" )
897 return KernelModeDriver
;
898 if ( attribute
.value
== "nativedll" )
900 if ( attribute
.value
== "nativecui" )
902 if ( attribute
.value
== "win32dll" )
904 if ( attribute
.value
== "win32ocx" )
906 if ( attribute
.value
== "win32cui" )
908 if ( attribute
.value
== "win32gui" )
910 if ( attribute
.value
== "win32scr" )
912 if ( attribute
.value
== "bootloader" )
914 if ( attribute
.value
== "bootsector" )
916 if ( attribute
.value
== "bootprogram" )
918 if ( attribute
.value
== "iso" )
920 if ( attribute
.value
== "liveiso" )
922 if ( attribute
.value
== "isoregtest" )
924 if ( attribute
.value
== "liveisoregtest" )
925 return LiveIsoRegTest
;
926 if ( attribute
.value
== "test" )
928 if ( attribute
.value
== "rpcserver" )
930 if ( attribute
.value
== "rpcclient" )
932 if ( attribute
.value
== "rpcproxy" )
934 if ( attribute
.value
== "alias" )
936 if ( attribute
.value
== "idlheader" )
938 if ( attribute
.value
== "embeddedtypelib" )
939 return EmbeddedTypeLib
;
940 if ( attribute
.value
== "elfexecutable" )
941 return ElfExecutable
;
942 throw InvalidAttributeValueException ( location
,
948 Module::GetTargetDirectoryTree () const
957 case KernelModeDriver
:
971 case EmbeddedTypeLib
:
973 return OutputDirectory
;
975 case HostStaticLibrary
:
982 return IntermediateDirectory
;
986 throw InvalidOperationException ( __FILE__
,
988 "Invalid module type %d.",
993 Module::GetDefaultModuleExtension () const
1001 case HostStaticLibrary
:
1019 case KernelModeDriver
:
1027 case LiveIsoRegTest
:
1039 case EmbeddedTypeLib
:
1044 throw InvalidOperationException ( __FILE__
,
1049 Module::GetDefaultModuleEntrypoint () const
1054 return "KiSystemStartup";
1056 case KernelModeDriver
:
1057 return "DriverEntry@8";
1059 return "DllMainCRTStartup@12";
1061 return "NtProcessStartup@4";
1064 return "DllMain@12";
1068 return "wmainCRTStartup";
1070 return "mainCRTStartup";
1074 return "wWinMainCRTStartup";
1076 return "WinMainCRTStartup";
1079 case HostStaticLibrary
:
1086 case LiveIsoRegTest
:
1094 case EmbeddedTypeLib
:
1099 throw InvalidOperationException ( __FILE__
,
1104 Module::GetDefaultModuleBaseaddress () const
1109 return "0x80800000";
1112 return "0x10000000";
1117 return "0x00400000";
1120 return "0x00400000";
1122 case KernelModeDriver
:
1123 return "0x00010000";
1128 case HostStaticLibrary
:
1135 case LiveIsoRegTest
:
1142 case EmbeddedTypeLib
:
1147 throw InvalidOperationException ( __FILE__
,
1152 Module::HasImportLibrary () const
1154 return importLibrary
!= NULL
&& type
!= StaticLibrary
&& type
!= HostStaticLibrary
;
1158 Module::IsDLL () const
1167 case KernelModeDriver
:
1176 case HostStaticLibrary
:
1184 case LiveIsoRegTest
:
1190 case EmbeddedTypeLib
:
1196 throw InvalidOperationException ( __FILE__
,
1201 Module::GetPathWithPrefix ( const string
& prefix
) const
1203 return output
->relative_path
+ cSep
+ prefix
+ output
->name
;
1207 Module::GetPathToBaseDir () const
1209 string temp_path
= output
->relative_path
;
1210 string result
= "..\\";
1211 while(temp_path
.find ('\\') != string::npos
)
1213 temp_path
.erase (0, temp_path
.find('\\')+1);
1220 Module::GetInvocationTarget ( const int index
) const
1222 return ssprintf ( "%s_invoke_%d",
1228 Module::GetEntryPoint(bool leadingUnderscore
) const
1231 if (entrypoint
== "0" || entrypoint
== "0x0")
1233 if (leadingUnderscore
)
1236 result
+= entrypoint
;
1241 Module::HasFileWithExtension (
1242 const IfableData
& data
,
1243 const std::string
& extension
) const
1246 for ( i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1248 CompilationUnit
* compilationUnit
= data
.compilationUnits
[i
];
1249 if ( compilationUnit
->HasFileWithExtension ( extension
) )
1252 for ( i
= 0; i
< data
.ifs
.size (); i
++ )
1254 if ( HasFileWithExtension ( data
.ifs
[i
]->data
, extension
) )
1261 Module::InvokeModule () const
1263 for ( size_t i
= 0; i
< invocations
.size (); i
++ )
1265 Invoke
& invoke
= *invocations
[i
];
1266 string command
= FixSeparatorForSystemCommand(invoke
.invokeModule
->output
->relative_path
+ "/" + invoke
.invokeModule
->output
->name
) + " " + invoke
.GetParameters ();
1267 printf ( "Executing '%s'\n\n", command
.c_str () );
1268 int exitcode
= system ( command
.c_str () );
1269 if ( exitcode
!= 0 )
1270 throw InvocationFailedException ( command
,
1277 Module::SetImportLibrary ( ImportLibrary
* importLibrary
)
1279 this->importLibrary
= importLibrary
;
1280 dependency
= new FileLocation ( HasImportLibrary () ? IntermediateDirectory
: output
->directory
,
1281 output
->relative_path
,
1282 HasImportLibrary () ? "lib" + name
+ ".a" : output
->name
);
1286 File::File ( DirectoryLocation directory
,
1287 const string
& relative_path
,
1290 const string
& _switches
,
1291 bool _isPreCompiledHeader
)
1292 : file ( directory
, relative_path
, name
),
1294 switches(_switches
),
1295 isPreCompiledHeader(_isPreCompiledHeader
)
1306 std::string
File::GetFullPath () const
1308 string
directory ( "" );
1309 switch ( file
.directory
)
1311 case SourceDirectory
:
1313 case IntermediateDirectory
:
1314 directory
= Environment::GetIntermediatePath () + sSep
;
1317 throw InvalidOperationException ( __FILE__
,
1319 "Invalid directory %d.",
1323 if ( file
.relative_path
.length () > 0 )
1324 directory
+= file
.relative_path
+ sSep
;
1327 return directory
+ file
.name
;
1331 Library::Library ( const XMLElement
& _node
,
1332 const Module
& _module
,
1333 const string
& _name
)
1337 importedModule(_module
.project
.LocateModule(_name
))
1339 if ( module
.name
== name
)
1341 throw XMLInvalidBuildFileException (
1343 "module '%s' cannot link against itself",
1346 if ( !importedModule
)
1348 throw XMLInvalidBuildFileException (
1350 "module '%s' trying to import non-existant module '%s'",
1351 module
.name
.c_str(),
1356 Library::Library ( const Module
& _module
,
1357 const string
& _name
)
1361 importedModule(_module
.project
.LocateModule(_name
))
1366 Library::ProcessXML()
1368 if ( node
&& !module
.project
.LocateModule ( name
) )
1370 throw XMLInvalidBuildFileException (
1372 "module '%s' is trying to link against non-existant module '%s'",
1373 module
.name
.c_str(),
1379 Invoke::Invoke ( const XMLElement
& _node
,
1380 const Module
& _module
)
1387 Invoke::ProcessXML()
1389 const XMLAttribute
* att
= node
.GetAttribute ( "module", false );
1391 invokeModule
= &module
;
1394 invokeModule
= module
.project
.LocateModule ( att
->value
);
1395 if ( invokeModule
== NULL
)
1397 throw XMLInvalidBuildFileException (
1399 "module '%s' is trying to invoke non-existant module '%s'",
1400 module
.name
.c_str(),
1401 att
->value
.c_str() );
1405 for ( size_t i
= 0; i
< node
.subElements
.size (); i
++ )
1406 ProcessXMLSubElement ( *node
.subElements
[i
] );
1410 Invoke::ProcessXMLSubElement ( const XMLElement
& e
)
1412 bool subs_invalid
= false;
1413 if ( e
.name
== "input" )
1415 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1416 ProcessXMLSubElementInput ( *e
.subElements
[i
] );
1418 else if ( e
.name
== "output" )
1420 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1421 ProcessXMLSubElementOutput ( *e
.subElements
[i
] );
1423 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1425 throw XMLInvalidBuildFileException (
1427 "<%s> cannot have sub-elements",
1433 Invoke::ProcessXMLSubElementInput ( const XMLElement
& e
)
1435 bool subs_invalid
= false;
1436 if ( e
.name
== "inputfile" && e
.value
.size () > 0 )
1438 input
.push_back ( new InvokeFile (
1439 e
, FixSeparator ( module
.output
->relative_path
+ cSep
+ e
.value
) ) );
1440 subs_invalid
= true;
1442 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1444 throw XMLInvalidBuildFileException (
1446 "<%s> cannot have sub-elements",
1452 Invoke::ProcessXMLSubElementOutput ( const XMLElement
& e
)
1454 bool subs_invalid
= false;
1455 if ( e
.name
== "outputfile" && e
.value
.size () > 0 )
1457 output
.push_back ( new InvokeFile (
1458 e
, FixSeparator ( module
.output
->relative_path
+ cSep
+ e
.value
) ) );
1459 subs_invalid
= true;
1461 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1463 throw XMLInvalidBuildFileException (
1465 "<%s> cannot have sub-elements",
1471 Invoke::GetTargets ( string_list
& targets
) const
1473 for ( size_t i
= 0; i
< output
.size (); i
++ )
1475 InvokeFile
& file
= *output
[i
];
1476 targets
.push_back ( NormalizeFilename ( file
.name
) );
1481 Invoke::GetParameters () const
1483 string
parameters ( "" );
1485 for ( i
= 0; i
< output
.size (); i
++ )
1487 if ( parameters
.length () > 0)
1489 InvokeFile
& invokeFile
= *output
[i
];
1490 if ( invokeFile
.switches
.length () > 0 )
1492 parameters
+= invokeFile
.switches
+ " ";
1494 parameters
+= invokeFile
.name
;
1497 for ( i
= 0; i
< input
.size (); i
++ )
1499 if ( parameters
.length () > 0 )
1501 InvokeFile
& invokeFile
= *input
[i
];
1502 if ( invokeFile
.switches
.length () > 0 )
1504 parameters
+= invokeFile
.switches
;
1507 parameters
+= invokeFile
.name
;
1514 InvokeFile::InvokeFile ( const XMLElement
& _node
,
1515 const string
& _name
)
1519 const XMLAttribute
* att
= _node
.GetAttribute ( "switches", false );
1521 switches
= att
->value
;
1527 InvokeFile::ProcessXML()
1532 Dependency::Dependency ( const XMLElement
& _node
,
1533 const Module
& _module
)
1536 dependencyModule (NULL
)
1541 Dependency::ProcessXML()
1543 dependencyModule
= module
.project
.LocateModule ( node
.value
);
1544 if ( dependencyModule
== NULL
)
1546 throw XMLInvalidBuildFileException (
1548 "module '%s' depend on non-existant module '%s'",
1549 module
.name
.c_str(),
1550 node
.value
.c_str() );
1555 Metadata::Metadata ( const XMLElement
& _node
,
1556 const Module
& _module
)
1560 /* The module name */
1561 const XMLAttribute
* att
= _node
.GetAttribute ( "name", false );
1567 /* The module description */
1568 att
= _node
.GetAttribute ( "description", false );
1570 description
= att
->value
;
1574 /* The module version */
1575 att
= _node
.GetAttribute ( "version", false );
1577 version
= att
->value
;
1581 /* The module copyright */
1582 att
= _node
.GetAttribute ( "copyright", false );
1584 copyright
= att
->value
;
1588 att
= _node
.GetAttribute ( "url", false );
1594 /* When was this module updated */
1595 att
= _node
.GetAttribute ( "date", false );
1601 /* When was this module updated */
1602 att
= _node
.GetAttribute ( "owner", false );
1610 ImportLibrary::~ImportLibrary ()
1616 ImportLibrary::ImportLibrary ( const Project
& project
,
1617 const XMLElement
& node
,
1618 const Module
& module
)
1619 : XmlNode ( project
, node
),
1622 const XMLAttribute
* dllname
= node
.GetAttribute ( "dllname", false );
1623 const XMLAttribute
* definition
= node
.GetAttribute ( "definition", true );
1624 assert ( definition
);
1627 this->dllname
= dllname
->value
;
1628 else if ( module
.type
== StaticLibrary
|| module
.type
== HostStaticLibrary
)
1629 throw XMLInvalidBuildFileException (
1631 "<importlibrary> dllname attribute required." );
1633 DirectoryLocation directory
= SourceDirectory
;
1634 size_t index
= definition
->value
.rfind ( ".spec.def" );
1635 if ( index
!= string::npos
)
1636 directory
= IntermediateDirectory
;
1638 index
= definition
->value
.find_last_of ( "/\\" );
1639 if ( index
== string::npos
)
1641 source
= new FileLocation ( directory
,
1642 module
.output
->relative_path
,
1648 string dir
= definition
->value
.substr ( 0, index
);
1649 string name
= definition
->value
.substr ( index
+ 1);
1650 source
= new FileLocation ( directory
,
1651 NormalizeFilename ( module
.output
->relative_path
+ sSep
+ dir
),
1658 If::If ( const XMLElement
& node_
,
1659 const Project
& project_
,
1660 const Module
* module_
,
1661 const bool negated_
)
1662 : node(node_
), project(project_
), module(module_
), negated(negated_
)
1664 const XMLAttribute
* att
;
1666 att
= node
.GetAttribute ( "property", true );
1668 property
= att
->value
;
1670 att
= node
.GetAttribute ( "value", true );
1686 Property::Property ( const XMLElement
& node_
,
1687 const Project
& project_
,
1688 const Module
* module_
)
1689 : project(project_
), module(module_
)
1691 const XMLAttribute
* att
;
1693 att
= node_
.GetAttribute ( "name", true );
1695 name
= project
.ResolveProperties ( att
->value
);
1697 att
= node_
.GetAttribute ( "value", true );
1702 Property::Property ( const Project
& project_
,
1703 const Module
* module_
,
1704 const std::string
& name_
,
1705 const std::string
& value_
)
1706 : project(project_
), module(module_
), name(name_
), value(value_
)
1711 Property::ProcessXML()
1717 const XMLElement
& node_
,
1718 const Module
& module_
,
1719 const FileLocation
*file_
)
1720 : node(node_
), module(module_
), file(file_
)
1730 PchFile::ProcessXML()