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
;
505 aliasedModuleName
= project
.ResolveProperties ( aliasedModuleName
);
506 if ( aliasedModuleName
== name
)
508 throw XMLInvalidBuildFileException (
510 "module '%s' cannot link against itself",
513 const Module
* m
= project
.LocateModule ( aliasedModuleName
);
516 throw XMLInvalidBuildFileException (
518 "module '%s' trying to alias non-existant module '%s'",
520 aliasedModuleName
.c_str() );
525 for ( i
= 0; i
< node
.subElements
.size(); i
++ )
527 ParseContext parseContext
;
528 ProcessXMLSubElement ( *node
.subElements
[i
], SourceDirectory
, output
->relative_path
, parseContext
);
530 for ( i
= 0; i
< invocations
.size(); i
++ )
531 invocations
[i
]->ProcessXML ();
532 for ( i
= 0; i
< dependencies
.size(); i
++ )
533 dependencies
[i
]->ProcessXML ();
534 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
535 compilerFlags
[i
]->ProcessXML();
536 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
537 linkerFlags
[i
]->ProcessXML();
538 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
539 stubbedComponents
[i
]->ProcessXML();
540 non_if_data
.ProcessXML();
542 linkerScript
->ProcessXML();
546 autoRegister
->ProcessXML();
550 Module::ProcessXMLSubElement ( const XMLElement
& e
,
551 DirectoryLocation directory
,
552 const string
& relative_path
,
553 ParseContext
& parseContext
)
555 If
* pOldIf
= parseContext
.ifData
;
556 CompilationUnit
* pOldCompilationUnit
= parseContext
.compilationUnit
;
557 bool subs_invalid
= false;
558 string
subpath ( relative_path
);
559 DirectoryLocation subdirectory
= SourceDirectory
;
560 if ( e
.name
== "file" && e
.value
.size () > 0 )
563 const XMLAttribute
* att
= e
.GetAttribute ( "first", false );
566 if ( !stricmp ( att
->value
.c_str(), "true" ) )
568 else if ( stricmp ( att
->value
.c_str(), "false" ) )
570 throw XMLInvalidBuildFileException (
572 "attribute 'first' of <file> element can only be 'true' or 'false'" );
575 string switches
= "";
576 att
= e
.GetAttribute ( "switches", false );
578 switches
= att
->value
;
581 // check for c++ file
582 string ext
= GetExtension ( e
.value
);
583 if ( !stricmp ( ext
.c_str(), ".cpp" ) )
585 else if ( !stricmp ( ext
.c_str(), ".cc" ) )
587 else if ( !stricmp ( ext
.c_str(), ".cxx" ) )
590 File
* pFile
= new File ( directory
,
596 if ( parseContext
.compilationUnit
)
597 parseContext
.compilationUnit
->AddFile ( pFile
);
600 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( pFile
);
601 if ( parseContext
.ifData
)
602 parseContext
.ifData
->data
.compilationUnits
.push_back ( pCompilationUnit
);
605 string ext
= ToLower ( GetExtension ( e
.value
) );
608 // put .idl files at the start of the module
609 non_if_data
.compilationUnits
.insert (
610 non_if_data
.compilationUnits
.begin(),
613 else if ( ext
== ".asm" || ext
== ".s" )
615 // put .asm files at the end of the module
616 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
617 non_if_data
.asmFiles
++;
621 // put other files in the middle
622 non_if_data
.compilationUnits
.insert (
623 non_if_data
.compilationUnits
.end() - non_if_data
.asmFiles
,
628 if ( parseContext
.ifData
)
629 parseContext
.ifData
->data
.files
.push_back ( pFile
);
631 non_if_data
.files
.push_back ( pFile
);
634 else if ( e
.name
== "library" && e
.value
.size () )
636 Library
* pLibrary
= new Library ( e
, *this, e
.value
);
637 if ( parseContext
.ifData
)
638 parseContext
.ifData
->data
.libraries
.push_back ( pLibrary
);
640 non_if_data
.libraries
.push_back ( pLibrary
);
643 else if ( e
.name
== "directory" )
645 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
646 const XMLAttribute
* root
= e
.GetAttribute ( "root", false );
650 if ( root
->value
== "intermediate" )
651 subdirectory
= IntermediateDirectory
;
652 else if ( root
->value
== "output" )
653 subdirectory
= OutputDirectory
;
656 throw InvalidAttributeValueException (
662 subpath
= GetSubPath ( this->project
, e
.location
, relative_path
, att
->value
);
664 else if ( e
.name
== "include" )
666 Include
* include
= new Include ( project
, &e
, this );
667 if ( parseContext
.ifData
)
668 parseContext
.ifData
->data
.includes
.push_back ( include
);
670 non_if_data
.includes
.push_back ( include
);
673 else if ( e
.name
== "define" )
675 Define
* pDefine
= new Define ( project
, this, e
);
676 if ( parseContext
.ifData
)
677 parseContext
.ifData
->data
.defines
.push_back ( pDefine
);
679 non_if_data
.defines
.push_back ( pDefine
);
682 else if ( e
.name
== "metadata" )
684 if ( parseContext
.ifData
)
686 throw XMLInvalidBuildFileException (
688 "<metadata> is not a valid sub-element of <if>" );
690 metadata
= new Metadata ( e
, *this );
691 subs_invalid
= false;
693 else if ( e
.name
== "invoke" )
695 if ( parseContext
.ifData
)
697 throw XMLInvalidBuildFileException (
699 "<invoke> is not a valid sub-element of <if>" );
701 invocations
.push_back ( new Invoke ( e
, *this ) );
702 subs_invalid
= false;
704 else if ( e
.name
== "dependency" )
706 if ( parseContext
.ifData
)
708 throw XMLInvalidBuildFileException (
710 "<dependency> is not a valid sub-element of <if>" );
712 dependencies
.push_back ( new Dependency ( e
, *this ) );
715 else if ( e
.name
== "importlibrary" )
717 if ( parseContext
.ifData
)
719 throw XMLInvalidBuildFileException (
721 "<importlibrary> is not a valid sub-element of <if>" );
725 throw XMLInvalidBuildFileException (
727 "Only one <importlibrary> is valid per module" );
729 SetImportLibrary ( new ImportLibrary ( project
, e
, *this ) );
732 else if ( e
.name
== "if" )
734 parseContext
.ifData
= new If ( e
, project
, this );
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
== "ifnot" )
743 parseContext
.ifData
= new If ( e
, project
, this, true );
745 pOldIf
->data
.ifs
.push_back ( parseContext
.ifData
);
747 non_if_data
.ifs
.push_back ( parseContext
.ifData
);
748 subs_invalid
= false;
750 else if ( e
.name
== "compilerflag" )
752 CompilerFlag
* pCompilerFlag
= new CompilerFlag ( project
, this, e
);
753 if ( parseContext
.ifData
)
754 parseContext
.ifData
->data
.compilerFlags
.push_back ( pCompilerFlag
);
756 non_if_data
.compilerFlags
.push_back ( pCompilerFlag
);
759 else if ( e
.name
== "linkerflag" )
761 linkerFlags
.push_back ( new LinkerFlag ( project
, this, e
) );
764 else if ( e
.name
== "linkerscript" )
766 if ( parseContext
.ifData
)
768 throw XMLInvalidBuildFileException (
770 "<linkerscript> is not a valid sub-element of <if>" );
774 throw XMLInvalidBuildFileException (
776 "Only one <linkerscript> is valid per module" );
778 size_t pos
= e
.value
.find_last_of ( "/\\" );
779 if ( pos
== string::npos
)
781 linkerScript
= new LinkerScript (
782 e
, *this, new FileLocation ( SourceDirectory
, relative_path
, e
.value
, &e
) );
786 string dir
= e
.value
.substr ( 0, pos
);
787 string name
= e
.value
.substr ( pos
+ 1);
788 linkerScript
= new LinkerScript (
789 e
, *this, new FileLocation ( SourceDirectory
, relative_path
+ sSep
+ dir
, name
, &e
) );
793 else if ( e
.name
== "component" )
795 stubbedComponents
.push_back ( new StubbedComponent ( this, e
) );
796 subs_invalid
= false;
798 else if ( e
.name
== "property" )
800 throw XMLInvalidBuildFileException (
802 "<property> is not a valid sub-element of <module>" );
804 else if ( e
.name
== "bootstrap" )
806 bootstrap
= new Bootstrap ( project
, this, e
);
809 else if ( e
.name
== "pch" )
811 if ( parseContext
.ifData
)
813 throw XMLInvalidBuildFileException (
815 "<pch> is not a valid sub-element of <if>" );
819 throw XMLInvalidBuildFileException (
821 "Only one <pch> is valid per module" );
823 size_t pos
= e
.value
.find_last_of ( "/\\" );
824 if ( pos
== string::npos
)
827 e
, *this, new FileLocation ( SourceDirectory
, relative_path
, e
.value
, &e
) );
831 string dir
= e
.value
.substr ( 0, pos
);
832 string name
= e
.value
.substr ( pos
+ 1);
834 e
, *this, new FileLocation ( SourceDirectory
, relative_path
+ sSep
+ dir
, name
, &e
) );
838 else if ( e
.name
== "compilationunit" )
840 if ( project
.configuration
.CompilationUnitsEnabled
)
842 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( &project
, this, &e
);
843 if ( parseContext
.ifData
)
844 parseContext
.ifData
->data
.compilationUnits
.push_back ( pCompilationUnit
);
846 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
847 parseContext
.compilationUnit
= pCompilationUnit
;
849 subs_invalid
= false;
851 else if ( e
.name
== "autoregister" )
853 if ( autoRegister
!= NULL
)
855 throw XMLInvalidBuildFileException (
857 "there can be only one <%s> element for a module",
860 autoRegister
= new AutoRegister ( project
, this, e
);
863 if ( subs_invalid
&& e
.subElements
.size() > 0 )
865 throw XMLInvalidBuildFileException (
867 "<%s> cannot have sub-elements",
870 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
871 ProcessXMLSubElement ( *e
.subElements
[i
], subdirectory
, subpath
, parseContext
);
872 parseContext
.ifData
= pOldIf
;
873 parseContext
.compilationUnit
= pOldCompilationUnit
;
877 Module::GetModuleType ( const string
& location
, const XMLAttribute
& attribute
)
879 if ( attribute
.value
== "buildtool" )
881 if ( attribute
.value
== "staticlibrary" )
882 return StaticLibrary
;
883 if ( attribute
.value
== "hoststaticlibrary" )
884 return HostStaticLibrary
;
885 if ( attribute
.value
== "objectlibrary" )
886 return ObjectLibrary
;
887 if ( attribute
.value
== "kernel" )
889 if ( attribute
.value
== "kernelmodedll" )
890 return KernelModeDLL
;
891 if ( attribute
.value
== "kernelmodedriver" )
892 return KernelModeDriver
;
893 if ( attribute
.value
== "nativedll" )
895 if ( attribute
.value
== "nativecui" )
897 if ( attribute
.value
== "win32dll" )
899 if ( attribute
.value
== "win32ocx" )
901 if ( attribute
.value
== "win32cui" )
903 if ( attribute
.value
== "win32gui" )
905 if ( attribute
.value
== "win32scr" )
907 if ( attribute
.value
== "bootloader" )
909 if ( attribute
.value
== "bootsector" )
911 if ( attribute
.value
== "bootprogram" )
913 if ( attribute
.value
== "iso" )
915 if ( attribute
.value
== "liveiso" )
917 if ( attribute
.value
== "isoregtest" )
919 if ( attribute
.value
== "liveisoregtest" )
920 return LiveIsoRegTest
;
921 if ( attribute
.value
== "test" )
923 if ( attribute
.value
== "rpcserver" )
925 if ( attribute
.value
== "rpcclient" )
927 if ( attribute
.value
== "rpcproxy" )
929 if ( attribute
.value
== "alias" )
931 if ( attribute
.value
== "idlheader" )
933 if ( attribute
.value
== "embeddedtypelib" )
934 return EmbeddedTypeLib
;
935 if ( attribute
.value
== "elfexecutable" )
936 return ElfExecutable
;
937 throw InvalidAttributeValueException ( location
,
943 Module::GetTargetDirectoryTree () const
952 case KernelModeDriver
:
966 case EmbeddedTypeLib
:
968 return OutputDirectory
;
970 case HostStaticLibrary
:
977 return IntermediateDirectory
;
981 throw InvalidOperationException ( __FILE__
,
983 "Invalid module type %d.",
988 Module::GetDefaultModuleExtension () const
996 case HostStaticLibrary
:
1014 case KernelModeDriver
:
1022 case LiveIsoRegTest
:
1034 case EmbeddedTypeLib
:
1039 throw InvalidOperationException ( __FILE__
,
1044 Module::GetDefaultModuleEntrypoint () const
1049 return "KiSystemStartup";
1051 case KernelModeDriver
:
1052 return "DriverEntry@8";
1054 return "DllMainCRTStartup@12";
1056 return "NtProcessStartup@4";
1059 return "DllMain@12";
1063 return "wmainCRTStartup";
1065 return "mainCRTStartup";
1069 return "wWinMainCRTStartup";
1071 return "WinMainCRTStartup";
1074 case HostStaticLibrary
:
1081 case LiveIsoRegTest
:
1089 case EmbeddedTypeLib
:
1094 throw InvalidOperationException ( __FILE__
,
1099 Module::GetDefaultModuleBaseaddress () const
1104 return "0x80800000";
1107 return "0x10000000";
1112 return "0x00400000";
1115 return "0x00400000";
1117 case KernelModeDriver
:
1118 return "0x00010000";
1123 case HostStaticLibrary
:
1130 case LiveIsoRegTest
:
1137 case EmbeddedTypeLib
:
1142 throw InvalidOperationException ( __FILE__
,
1147 Module::HasImportLibrary () const
1149 return importLibrary
!= NULL
&& type
!= StaticLibrary
&& type
!= HostStaticLibrary
;
1153 Module::IsDLL () const
1162 case KernelModeDriver
:
1171 case HostStaticLibrary
:
1179 case LiveIsoRegTest
:
1185 case EmbeddedTypeLib
:
1191 throw InvalidOperationException ( __FILE__
,
1196 Module::GetPathWithPrefix ( const string
& prefix
) const
1198 return output
->relative_path
+ cSep
+ prefix
+ output
->name
;
1202 Module::GetPathToBaseDir () const
1204 string temp_path
= output
->relative_path
;
1205 string result
= "..\\";
1206 while(temp_path
.find ('\\') != string::npos
)
1208 temp_path
.erase (0, temp_path
.find('\\')+1);
1215 Module::GetInvocationTarget ( const int index
) const
1217 return ssprintf ( "%s_invoke_%d",
1223 Module::GetEntryPoint(bool leadingUnderscore
) const
1226 if (entrypoint
== "0" || entrypoint
== "0x0")
1228 if (leadingUnderscore
)
1231 result
+= entrypoint
;
1236 Module::HasFileWithExtension (
1237 const IfableData
& data
,
1238 const std::string
& extension
) const
1241 for ( i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1243 CompilationUnit
* compilationUnit
= data
.compilationUnits
[i
];
1244 if ( compilationUnit
->HasFileWithExtension ( extension
) )
1247 for ( i
= 0; i
< data
.ifs
.size (); i
++ )
1249 if ( HasFileWithExtension ( data
.ifs
[i
]->data
, extension
) )
1256 Module::InvokeModule () const
1258 for ( size_t i
= 0; i
< invocations
.size (); i
++ )
1260 Invoke
& invoke
= *invocations
[i
];
1261 string command
= FixSeparatorForSystemCommand(invoke
.invokeModule
->output
->relative_path
+ "/" + invoke
.invokeModule
->output
->name
) + " " + invoke
.GetParameters ();
1262 printf ( "Executing '%s'\n\n", command
.c_str () );
1263 int exitcode
= system ( command
.c_str () );
1264 if ( exitcode
!= 0 )
1265 throw InvocationFailedException ( command
,
1272 Module::SetImportLibrary ( ImportLibrary
* importLibrary
)
1274 this->importLibrary
= importLibrary
;
1275 dependency
= new FileLocation ( HasImportLibrary () ? IntermediateDirectory
: output
->directory
,
1276 output
->relative_path
,
1277 HasImportLibrary () ? "lib" + name
+ ".a" : output
->name
);
1281 File::File ( DirectoryLocation directory
,
1282 const string
& relative_path
,
1285 const string
& _switches
,
1286 bool _isPreCompiledHeader
)
1287 : file ( directory
, relative_path
, name
),
1289 switches(_switches
),
1290 isPreCompiledHeader(_isPreCompiledHeader
)
1301 std::string
File::GetFullPath () const
1303 string
directory ( "" );
1304 switch ( file
.directory
)
1306 case SourceDirectory
:
1308 case IntermediateDirectory
:
1309 directory
= Environment::GetIntermediatePath () + sSep
;
1312 throw InvalidOperationException ( __FILE__
,
1314 "Invalid directory %d.",
1318 if ( file
.relative_path
.length () > 0 )
1319 directory
+= file
.relative_path
+ sSep
;
1322 return directory
+ file
.name
;
1326 Library::Library ( const XMLElement
& _node
,
1327 const Module
& _module
,
1328 const string
& _name
)
1332 importedModule(_module
.project
.LocateModule(_name
))
1334 if ( module
.name
== name
)
1336 throw XMLInvalidBuildFileException (
1338 "module '%s' cannot link against itself",
1341 if ( !importedModule
)
1343 throw XMLInvalidBuildFileException (
1345 "module '%s' trying to import non-existant module '%s'",
1346 module
.name
.c_str(),
1351 Library::Library ( const Module
& _module
,
1352 const string
& _name
)
1356 importedModule(_module
.project
.LocateModule(_name
))
1361 Library::ProcessXML()
1363 if ( node
&& !module
.project
.LocateModule ( name
) )
1365 throw XMLInvalidBuildFileException (
1367 "module '%s' is trying to link against non-existant module '%s'",
1368 module
.name
.c_str(),
1374 Invoke::Invoke ( const XMLElement
& _node
,
1375 const Module
& _module
)
1382 Invoke::ProcessXML()
1384 const XMLAttribute
* att
= node
.GetAttribute ( "module", false );
1386 invokeModule
= &module
;
1389 invokeModule
= module
.project
.LocateModule ( att
->value
);
1390 if ( invokeModule
== NULL
)
1392 throw XMLInvalidBuildFileException (
1394 "module '%s' is trying to invoke non-existant module '%s'",
1395 module
.name
.c_str(),
1396 att
->value
.c_str() );
1400 for ( size_t i
= 0; i
< node
.subElements
.size (); i
++ )
1401 ProcessXMLSubElement ( *node
.subElements
[i
] );
1405 Invoke::ProcessXMLSubElement ( const XMLElement
& e
)
1407 bool subs_invalid
= false;
1408 if ( e
.name
== "input" )
1410 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1411 ProcessXMLSubElementInput ( *e
.subElements
[i
] );
1413 else if ( e
.name
== "output" )
1415 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1416 ProcessXMLSubElementOutput ( *e
.subElements
[i
] );
1418 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1420 throw XMLInvalidBuildFileException (
1422 "<%s> cannot have sub-elements",
1428 Invoke::ProcessXMLSubElementInput ( const XMLElement
& e
)
1430 bool subs_invalid
= false;
1431 if ( e
.name
== "inputfile" && e
.value
.size () > 0 )
1433 input
.push_back ( new InvokeFile (
1434 e
, FixSeparator ( module
.output
->relative_path
+ cSep
+ e
.value
) ) );
1435 subs_invalid
= true;
1437 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1439 throw XMLInvalidBuildFileException (
1441 "<%s> cannot have sub-elements",
1447 Invoke::ProcessXMLSubElementOutput ( const XMLElement
& e
)
1449 bool subs_invalid
= false;
1450 if ( e
.name
== "outputfile" && e
.value
.size () > 0 )
1452 output
.push_back ( new InvokeFile (
1453 e
, FixSeparator ( module
.output
->relative_path
+ cSep
+ e
.value
) ) );
1454 subs_invalid
= true;
1456 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1458 throw XMLInvalidBuildFileException (
1460 "<%s> cannot have sub-elements",
1466 Invoke::GetTargets ( string_list
& targets
) const
1468 for ( size_t i
= 0; i
< output
.size (); i
++ )
1470 InvokeFile
& file
= *output
[i
];
1471 targets
.push_back ( NormalizeFilename ( file
.name
) );
1476 Invoke::GetParameters () const
1478 string
parameters ( "" );
1480 for ( i
= 0; i
< output
.size (); i
++ )
1482 if ( parameters
.length () > 0)
1484 InvokeFile
& invokeFile
= *output
[i
];
1485 if ( invokeFile
.switches
.length () > 0 )
1487 parameters
+= invokeFile
.switches
+ " ";
1489 parameters
+= invokeFile
.name
;
1492 for ( i
= 0; i
< input
.size (); i
++ )
1494 if ( parameters
.length () > 0 )
1496 InvokeFile
& invokeFile
= *input
[i
];
1497 if ( invokeFile
.switches
.length () > 0 )
1499 parameters
+= invokeFile
.switches
;
1502 parameters
+= invokeFile
.name
;
1509 InvokeFile::InvokeFile ( const XMLElement
& _node
,
1510 const string
& _name
)
1514 const XMLAttribute
* att
= _node
.GetAttribute ( "switches", false );
1516 switches
= att
->value
;
1522 InvokeFile::ProcessXML()
1527 Dependency::Dependency ( const XMLElement
& _node
,
1528 const Module
& _module
)
1531 dependencyModule (NULL
)
1536 Dependency::ProcessXML()
1538 dependencyModule
= module
.project
.LocateModule ( node
.value
);
1539 if ( dependencyModule
== NULL
)
1541 throw XMLInvalidBuildFileException (
1543 "module '%s' depend on non-existant module '%s'",
1544 module
.name
.c_str(),
1545 node
.value
.c_str() );
1550 Metadata::Metadata ( const XMLElement
& _node
,
1551 const Module
& _module
)
1555 /* The module name */
1556 const XMLAttribute
* att
= _node
.GetAttribute ( "name", false );
1562 /* The module description */
1563 att
= _node
.GetAttribute ( "description", false );
1565 description
= att
->value
;
1569 /* The module version */
1570 att
= _node
.GetAttribute ( "version", false );
1572 version
= att
->value
;
1576 /* The module copyright */
1577 att
= _node
.GetAttribute ( "copyright", false );
1579 copyright
= att
->value
;
1583 att
= _node
.GetAttribute ( "url", false );
1589 /* When was this module updated */
1590 att
= _node
.GetAttribute ( "date", false );
1596 /* When was this module updated */
1597 att
= _node
.GetAttribute ( "owner", false );
1605 ImportLibrary::~ImportLibrary ()
1611 ImportLibrary::ImportLibrary ( const Project
& project
,
1612 const XMLElement
& node
,
1613 const Module
& module
)
1614 : XmlNode ( project
, node
),
1617 const XMLAttribute
* dllname
= node
.GetAttribute ( "dllname", false );
1618 const XMLAttribute
* definition
= node
.GetAttribute ( "definition", true );
1619 assert ( definition
);
1622 this->dllname
= dllname
->value
;
1623 else if ( module
.type
== StaticLibrary
|| module
.type
== HostStaticLibrary
)
1624 throw XMLInvalidBuildFileException (
1626 "<importlibrary> dllname attribute required." );
1628 DirectoryLocation directory
= SourceDirectory
;
1629 size_t index
= definition
->value
.rfind ( ".spec.def" );
1630 if ( index
!= string::npos
)
1631 directory
= IntermediateDirectory
;
1633 index
= definition
->value
.find_last_of ( "/\\" );
1634 if ( index
== string::npos
)
1636 source
= new FileLocation ( directory
,
1637 module
.output
->relative_path
,
1643 string dir
= definition
->value
.substr ( 0, index
);
1644 string name
= definition
->value
.substr ( index
+ 1);
1645 source
= new FileLocation ( directory
,
1646 NormalizeFilename ( module
.output
->relative_path
+ sSep
+ dir
),
1653 If::If ( const XMLElement
& node_
,
1654 const Project
& project_
,
1655 const Module
* module_
,
1656 const bool negated_
)
1657 : node(node_
), project(project_
), module(module_
), negated(negated_
)
1659 const XMLAttribute
* att
;
1661 att
= node
.GetAttribute ( "property", true );
1663 property
= att
->value
;
1665 att
= node
.GetAttribute ( "value", true );
1681 Property::Property ( const XMLElement
& node_
,
1682 const Project
& project_
,
1683 const Module
* module_
)
1684 : project(project_
), module(module_
)
1686 const XMLAttribute
* att
;
1688 att
= node_
.GetAttribute ( "name", true );
1690 name
= project
.ResolveProperties ( att
->value
);
1692 att
= node_
.GetAttribute ( "value", true );
1697 Property::Property ( const Project
& project_
,
1698 const Module
* module_
,
1699 const std::string
& name_
,
1700 const std::string
& value_
)
1701 : project(project_
), module(module_
), name(name_
), value(value_
)
1706 Property::ProcessXML()
1712 const XMLElement
& node_
,
1713 const Module
& module_
,
1714 const FileLocation
*file_
)
1715 : node(node_
), module(module_
), file(file_
)
1725 PchFile::ProcessXML()