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
= 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 output
= new FileLocation ( GetTargetDirectoryTree (),
291 att
= moduleNode
.GetAttribute ( "unicode", false );
294 const char* p
= att
->value
.c_str();
295 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
297 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
301 throw InvalidAttributeValueException (
312 // Always define UNICODE and _UNICODE
313 Define
* pDefine
= new Define ( project
, this, "UNICODE" );
314 non_if_data
.defines
.push_back ( pDefine
);
316 pDefine
= new Define ( project
, this, "_UNICODE" );
317 non_if_data
.defines
.push_back ( pDefine
);
320 att
= moduleNode
.GetAttribute ( "entrypoint", false );
323 if ( att
->value
== "" )
325 throw InvalidAttributeValueException (
331 entrypoint
= att
->value
;
332 isDefaultEntryPoint
= false;
336 entrypoint
= GetDefaultModuleEntrypoint ();
337 isDefaultEntryPoint
= true;
340 att
= moduleNode
.GetAttribute ( "baseaddress", false );
342 baseaddress
= att
->value
;
344 baseaddress
= GetDefaultModuleBaseaddress ();
346 att
= moduleNode
.GetAttribute ( "mangledsymbols", false );
349 const char* p
= att
->value
.c_str();
350 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
351 mangledSymbols
= true;
352 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
353 mangledSymbols
= false;
356 throw InvalidAttributeValueException (
363 mangledSymbols
= false;
365 att
= moduleNode
.GetAttribute ( "underscoresymbols", false );
367 underscoreSymbols
= att
->value
== "true";
369 underscoreSymbols
= false;
371 att
= moduleNode
.GetAttribute ( "host", false );
374 const char* p
= att
->value
.c_str();
375 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
377 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
381 throw InvalidAttributeValueException (
388 att
= moduleNode
.GetAttribute ( "isstartuplib", false );
391 const char* p
= att
->value
.c_str();
392 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
394 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
395 isStartupLib
= false;
398 throw InvalidAttributeValueException (
405 isStartupLib
= false;
407 att
= moduleNode
.GetAttribute ( "prefix", false );
411 att
= moduleNode
.GetAttribute ( "installname", false );
414 const XMLAttribute
* installbase
= moduleNode
.GetAttribute ( "installbase", false );
415 install
= new FileLocation ( InstallDirectory
,
416 installbase
? installbase
->value
: "",
423 att
= moduleNode
.GetAttribute ( "allowwarnings", false );
426 att
= moduleNode
.GetAttribute ( "warnings", false );
429 printf ( "%s: WARNING: 'warnings' attribute of <module> is deprecated, use 'allowwarnings' instead\n",
430 moduleNode
.location
.c_str() );
434 allowWarnings
= att
->value
== "true";
436 allowWarnings
= false;
438 att
= moduleNode
.GetAttribute ( "aliasof", false );
439 if ( type
== Alias
&& att
!= NULL
)
440 aliasedModuleName
= att
->value
;
442 aliasedModuleName
= "";
444 if ( type
== BootProgram
)
446 att
= moduleNode
.GetAttribute ( "payload", true );
447 payload
= att
->value
;
450 if ( type
== BootProgram
|| type
== ElfExecutable
)
452 att
= moduleNode
.GetAttribute ( "buildtype", false );
455 buildtype
= att
->value
;
459 buildtype
= "BOOTPROG";
463 SetImportLibrary ( NULL
);
469 for ( i
= 0; i
< invocations
.size(); i
++ )
470 delete invocations
[i
];
471 for ( i
= 0; i
< dependencies
.size(); i
++ )
472 delete dependencies
[i
];
473 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
474 delete compilerFlags
[i
];
475 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
476 delete linkerFlags
[i
];
477 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
478 delete stubbedComponents
[i
];
490 aliasedModuleName
= project
.ResolveProperties ( aliasedModuleName
);
491 if ( aliasedModuleName
== name
)
493 throw XMLInvalidBuildFileException (
495 "module '%s' cannot link against itself",
498 const Module
* m
= project
.LocateModule ( aliasedModuleName
);
501 throw XMLInvalidBuildFileException (
503 "module '%s' trying to alias non-existant module '%s'",
505 aliasedModuleName
.c_str() );
510 for ( i
= 0; i
< node
.subElements
.size(); i
++ )
512 ParseContext parseContext
;
513 ProcessXMLSubElement ( *node
.subElements
[i
], SourceDirectory
, output
->relative_path
, parseContext
);
515 for ( i
= 0; i
< invocations
.size(); i
++ )
516 invocations
[i
]->ProcessXML ();
517 for ( i
= 0; i
< dependencies
.size(); i
++ )
518 dependencies
[i
]->ProcessXML ();
519 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
520 compilerFlags
[i
]->ProcessXML();
521 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
522 linkerFlags
[i
]->ProcessXML();
523 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
524 stubbedComponents
[i
]->ProcessXML();
525 non_if_data
.ProcessXML();
527 linkerScript
->ProcessXML();
531 autoRegister
->ProcessXML();
535 Module::ProcessXMLSubElement ( const XMLElement
& e
,
536 DirectoryLocation directory
,
537 const string
& relative_path
,
538 ParseContext
& parseContext
)
540 If
* pOldIf
= parseContext
.ifData
;
541 CompilationUnit
* pOldCompilationUnit
= parseContext
.compilationUnit
;
542 bool subs_invalid
= false;
543 string
subpath ( relative_path
);
544 DirectoryLocation subdirectory
= SourceDirectory
;
545 if ( e
.name
== "file" && e
.value
.size () > 0 )
548 const XMLAttribute
* att
= e
.GetAttribute ( "first", false );
551 if ( !stricmp ( att
->value
.c_str(), "true" ) )
553 else if ( stricmp ( att
->value
.c_str(), "false" ) )
555 throw XMLInvalidBuildFileException (
557 "attribute 'first' of <file> element can only be 'true' or 'false'" );
560 string switches
= "";
561 att
= e
.GetAttribute ( "switches", false );
563 switches
= att
->value
;
566 // check for c++ file
567 string ext
= GetExtension ( e
.value
);
568 if ( !stricmp ( ext
.c_str(), ".cpp" ) )
570 else if ( !stricmp ( ext
.c_str(), ".cc" ) )
572 else if ( !stricmp ( ext
.c_str(), ".cxx" ) )
575 File
* pFile
= new File ( directory
,
581 if ( parseContext
.compilationUnit
)
582 parseContext
.compilationUnit
->files
.push_back ( pFile
);
585 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( pFile
);
586 if ( parseContext
.ifData
)
587 parseContext
.ifData
->data
.compilationUnits
.push_back ( pCompilationUnit
);
590 string ext
= ToLower ( GetExtension ( e
.value
) );
593 // put .idl files at the start of the module
594 non_if_data
.compilationUnits
.insert (
595 non_if_data
.compilationUnits
.begin(),
598 else if ( ext
== ".asm" || ext
== ".s" )
600 // put .asm files at the end of the module
601 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
602 non_if_data
.asmFiles
++;
606 // put other files in the middle
607 non_if_data
.compilationUnits
.insert (
608 non_if_data
.compilationUnits
.end() - non_if_data
.asmFiles
,
613 if ( parseContext
.ifData
)
614 parseContext
.ifData
->data
.files
.push_back ( pFile
);
616 non_if_data
.files
.push_back ( pFile
);
619 else if ( e
.name
== "library" && e
.value
.size () )
621 Library
* pLibrary
= new Library ( e
, *this, e
.value
);
622 if ( parseContext
.ifData
)
623 parseContext
.ifData
->data
.libraries
.push_back ( pLibrary
);
625 non_if_data
.libraries
.push_back ( pLibrary
);
628 else if ( e
.name
== "directory" )
630 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
631 const XMLAttribute
* root
= e
.GetAttribute ( "root", false );
635 if ( root
->value
== "intermediate" )
636 subdirectory
= IntermediateDirectory
;
637 else if ( root
->value
== "output" )
638 subdirectory
= OutputDirectory
;
641 throw InvalidAttributeValueException (
647 subpath
= GetSubPath ( this->project
, e
.location
, relative_path
, att
->value
);
649 else if ( e
.name
== "include" )
651 Include
* include
= new Include ( project
, &e
, this );
652 if ( parseContext
.ifData
)
653 parseContext
.ifData
->data
.includes
.push_back ( include
);
655 non_if_data
.includes
.push_back ( include
);
658 else if ( e
.name
== "define" )
660 Define
* pDefine
= new Define ( project
, this, e
);
661 if ( parseContext
.ifData
)
662 parseContext
.ifData
->data
.defines
.push_back ( pDefine
);
664 non_if_data
.defines
.push_back ( pDefine
);
667 else if ( e
.name
== "metadata" )
669 if ( parseContext
.ifData
)
671 throw XMLInvalidBuildFileException (
673 "<metadata> is not a valid sub-element of <if>" );
675 metadata
= new Metadata ( e
, *this );
676 subs_invalid
= false;
678 else if ( e
.name
== "invoke" )
680 if ( parseContext
.ifData
)
682 throw XMLInvalidBuildFileException (
684 "<invoke> is not a valid sub-element of <if>" );
686 invocations
.push_back ( new Invoke ( e
, *this ) );
687 subs_invalid
= false;
689 else if ( e
.name
== "dependency" )
691 if ( parseContext
.ifData
)
693 throw XMLInvalidBuildFileException (
695 "<dependency> is not a valid sub-element of <if>" );
697 dependencies
.push_back ( new Dependency ( e
, *this ) );
700 else if ( e
.name
== "importlibrary" )
702 if ( parseContext
.ifData
)
704 throw XMLInvalidBuildFileException (
706 "<importlibrary> is not a valid sub-element of <if>" );
710 throw XMLInvalidBuildFileException (
712 "Only one <importlibrary> is valid per module" );
714 SetImportLibrary ( new ImportLibrary ( project
, e
, *this ) );
717 else if ( e
.name
== "if" )
719 parseContext
.ifData
= new If ( e
, project
, this );
721 pOldIf
->data
.ifs
.push_back ( parseContext
.ifData
);
723 non_if_data
.ifs
.push_back ( parseContext
.ifData
);
724 subs_invalid
= false;
726 else if ( e
.name
== "ifnot" )
728 parseContext
.ifData
= new If ( e
, project
, this, true );
730 pOldIf
->data
.ifs
.push_back ( parseContext
.ifData
);
732 non_if_data
.ifs
.push_back ( parseContext
.ifData
);
733 subs_invalid
= false;
735 else if ( e
.name
== "compilerflag" )
737 CompilerFlag
* pCompilerFlag
= new CompilerFlag ( project
, this, e
);
738 if ( parseContext
.ifData
)
739 parseContext
.ifData
->data
.compilerFlags
.push_back ( pCompilerFlag
);
741 non_if_data
.compilerFlags
.push_back ( pCompilerFlag
);
744 else if ( e
.name
== "linkerflag" )
746 linkerFlags
.push_back ( new LinkerFlag ( project
, this, e
) );
749 else if ( e
.name
== "linkerscript" )
751 if ( parseContext
.ifData
)
753 throw XMLInvalidBuildFileException (
755 "<linkerscript> is not a valid sub-element of <if>" );
759 throw XMLInvalidBuildFileException (
761 "Only one <linkerscript> is valid per module" );
763 size_t pos
= e
.value
.find_last_of ( "/\\" );
764 if ( pos
== string::npos
)
766 linkerScript
= new LinkerScript (
767 e
, *this, FileLocation ( SourceDirectory
, relative_path
, e
.value
, &e
) );
771 string dir
= e
.value
.substr ( 0, pos
);
772 string name
= e
.value
.substr ( pos
+ 1);
773 linkerScript
= new LinkerScript (
774 e
, *this, FileLocation ( SourceDirectory
, relative_path
+ sSep
+ dir
, name
, &e
) );
778 else if ( e
.name
== "component" )
780 stubbedComponents
.push_back ( new StubbedComponent ( this, e
) );
781 subs_invalid
= false;
783 else if ( e
.name
== "property" )
785 throw XMLInvalidBuildFileException (
787 "<property> is not a valid sub-element of <module>" );
789 else if ( e
.name
== "bootstrap" )
791 bootstrap
= new Bootstrap ( project
, this, e
);
794 else if ( e
.name
== "pch" )
796 if ( parseContext
.ifData
)
798 throw XMLInvalidBuildFileException (
800 "<pch> is not a valid sub-element of <if>" );
804 throw XMLInvalidBuildFileException (
806 "Only one <pch> is valid per module" );
808 size_t pos
= e
.value
.find_last_of ( "/\\" );
809 if ( pos
== string::npos
)
812 e
, *this, FileLocation ( SourceDirectory
, relative_path
, e
.value
, &e
) );
816 string dir
= e
.value
.substr ( 0, pos
);
817 string name
= e
.value
.substr ( pos
+ 1);
819 e
, *this, FileLocation ( SourceDirectory
, relative_path
+ sSep
+ dir
, name
, &e
) );
823 else if ( e
.name
== "compilationunit" )
825 if ( project
.configuration
.CompilationUnitsEnabled
)
827 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( &project
, this, &e
);
828 if ( parseContext
.ifData
)
829 parseContext
.ifData
->data
.compilationUnits
.push_back ( pCompilationUnit
);
831 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
832 parseContext
.compilationUnit
= pCompilationUnit
;
834 subs_invalid
= false;
836 else if ( e
.name
== "autoregister" )
838 if ( autoRegister
!= NULL
)
840 throw XMLInvalidBuildFileException (
842 "there can be only one <%s> element for a module",
845 autoRegister
= new AutoRegister ( project
, this, e
);
848 if ( subs_invalid
&& e
.subElements
.size() > 0 )
850 throw XMLInvalidBuildFileException (
852 "<%s> cannot have sub-elements",
855 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
856 ProcessXMLSubElement ( *e
.subElements
[i
], subdirectory
, subpath
, parseContext
);
857 parseContext
.ifData
= pOldIf
;
858 parseContext
.compilationUnit
= pOldCompilationUnit
;
862 Module::GetModuleType ( const string
& location
, const XMLAttribute
& attribute
)
864 if ( attribute
.value
== "buildtool" )
866 if ( attribute
.value
== "staticlibrary" )
867 return StaticLibrary
;
868 if ( attribute
.value
== "objectlibrary" )
869 return ObjectLibrary
;
870 if ( attribute
.value
== "kernel" )
872 if ( attribute
.value
== "kernelmodedll" )
873 return KernelModeDLL
;
874 if ( attribute
.value
== "kernelmodedriver" )
875 return KernelModeDriver
;
876 if ( attribute
.value
== "nativedll" )
878 if ( attribute
.value
== "nativecui" )
880 if ( attribute
.value
== "win32dll" )
882 if ( attribute
.value
== "win32ocx" )
884 if ( attribute
.value
== "win32cui" )
886 if ( attribute
.value
== "win32gui" )
888 if ( attribute
.value
== "win32scr" )
890 if ( attribute
.value
== "bootloader" )
892 if ( attribute
.value
== "bootsector" )
894 if ( attribute
.value
== "bootprogram" )
896 if ( attribute
.value
== "iso" )
898 if ( attribute
.value
== "liveiso" )
900 if ( attribute
.value
== "isoregtest" )
902 if ( attribute
.value
== "liveisoregtest" )
903 return LiveIsoRegTest
;
904 if ( attribute
.value
== "test" )
906 if ( attribute
.value
== "rpcserver" )
908 if ( attribute
.value
== "rpcclient" )
910 if ( attribute
.value
== "alias" )
912 if ( attribute
.value
== "idlheader" )
914 if ( attribute
.value
== "embeddedtypelib" )
915 return EmbeddedTypeLib
;
916 if ( attribute
.value
== "elfexecutable" )
917 return ElfExecutable
;
918 throw InvalidAttributeValueException ( location
,
924 Module::GetTargetDirectoryTree () const
933 case KernelModeDriver
:
947 case EmbeddedTypeLib
:
949 return OutputDirectory
;
956 return IntermediateDirectory
;
958 throw InvalidOperationException ( __FILE__
,
960 "Invalid module type %d.",
965 Module::GetDefaultModuleExtension () const
990 case KernelModeDriver
:
994 return "_" + this->name
+ ".o";
1010 case EmbeddedTypeLib
:
1013 throw InvalidOperationException ( __FILE__
,
1018 Module::GetDefaultModuleEntrypoint () const
1023 return "NtProcessStartup";
1025 case KernelModeDriver
:
1026 return "DriverEntry@8";
1028 return "DllMainCRTStartup@12";
1030 return "NtProcessStartup@4";
1033 return "DllMain@12";
1037 return "wmainCRTStartup";
1039 return "mainCRTStartup";
1043 return "wWinMainCRTStartup";
1045 return "WinMainCRTStartup";
1054 case LiveIsoRegTest
:
1061 case EmbeddedTypeLib
:
1064 throw InvalidOperationException ( __FILE__
,
1069 Module::GetDefaultModuleBaseaddress () const
1074 return "0x80800000";
1077 return "0x10000000";
1082 return "0x00400000";
1085 return "0x00400000";
1087 case KernelModeDriver
:
1088 return "0x00010000";
1099 case LiveIsoRegTest
:
1105 case EmbeddedTypeLib
:
1108 throw InvalidOperationException ( __FILE__
,
1113 Module::HasImportLibrary () const
1115 return importLibrary
!= NULL
&& type
!= StaticLibrary
;
1119 Module::IsDLL () const
1128 case KernelModeDriver
:
1144 case LiveIsoRegTest
:
1149 case EmbeddedTypeLib
:
1153 throw InvalidOperationException ( __FILE__
,
1158 Module::GetPathWithPrefix ( const string
& prefix
) const
1160 return output
->relative_path
+ cSep
+ prefix
+ output
->name
;
1164 Module::GetPathToBaseDir () const
1166 string temp_path
= output
->relative_path
;
1167 string result
= "..\\";
1168 while(temp_path
.find ('\\') != string::npos
)
1170 temp_path
.erase (0, temp_path
.find('\\')+1);
1177 Module::GetInvocationTarget ( const int index
) const
1179 return ssprintf ( "%s_invoke_%d",
1185 Module::GetEntryPoint(bool leadingUnderscore
) const
1188 if (entrypoint
== "0" || entrypoint
== "0x0")
1190 if (leadingUnderscore
)
1193 result
+= entrypoint
;
1198 Module::HasFileWithExtension (
1199 const IfableData
& data
,
1200 const std::string
& extension
) const
1203 for ( i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1205 CompilationUnit
* compilationUnit
= data
.compilationUnits
[i
];
1206 if ( compilationUnit
->HasFileWithExtension ( extension
) )
1209 for ( i
= 0; i
< data
.ifs
.size (); i
++ )
1211 if ( HasFileWithExtension ( data
.ifs
[i
]->data
, extension
) )
1218 Module::InvokeModule () const
1220 for ( size_t i
= 0; i
< invocations
.size (); i
++ )
1222 Invoke
& invoke
= *invocations
[i
];
1223 string command
= FixSeparatorForSystemCommand(invoke
.invokeModule
->output
->relative_path
+ "/" + invoke
.invokeModule
->output
->name
) + " " + invoke
.GetParameters ();
1224 printf ( "Executing '%s'\n\n", command
.c_str () );
1225 int exitcode
= system ( command
.c_str () );
1226 if ( exitcode
!= 0 )
1227 throw InvocationFailedException ( command
,
1234 Module::SetImportLibrary ( ImportLibrary
* importLibrary
)
1236 this->importLibrary
= importLibrary
;
1237 dependency
= new FileLocation ( HasImportLibrary () ? IntermediateDirectory
: output
->directory
,
1238 output
->relative_path
,
1239 HasImportLibrary () ? "lib" + name
+ ".a" : output
->name
);
1243 File::File ( DirectoryLocation directory
,
1244 const string
& relative_path
,
1247 const string
& _switches
,
1248 bool _isPreCompiledHeader
)
1249 : file ( directory
, relative_path
, name
),
1251 switches(_switches
),
1252 isPreCompiledHeader(_isPreCompiledHeader
)
1263 std::string
File::GetFullPath () const
1265 string
directory ( "" );
1266 switch ( file
.directory
)
1268 case SourceDirectory
:
1270 case IntermediateDirectory
:
1271 directory
= Environment::GetIntermediatePath () + sSep
;
1274 throw InvalidOperationException ( __FILE__
,
1276 "Invalid directory %d.",
1280 if ( file
.relative_path
.length () > 0 )
1281 directory
+= file
.relative_path
+ sSep
;
1284 return directory
+ file
.name
;
1288 Library::Library ( const XMLElement
& _node
,
1289 const Module
& _module
,
1290 const string
& _name
)
1294 importedModule(_module
.project
.LocateModule(_name
))
1296 if ( module
.name
== name
)
1298 throw XMLInvalidBuildFileException (
1300 "module '%s' cannot link against itself",
1303 if ( !importedModule
)
1305 throw XMLInvalidBuildFileException (
1307 "module '%s' trying to import non-existant module '%s'",
1308 module
.name
.c_str(),
1313 Library::Library ( const Module
& _module
,
1314 const string
& _name
)
1318 importedModule(_module
.project
.LocateModule(_name
))
1323 Library::ProcessXML()
1325 if ( node
&& !module
.project
.LocateModule ( name
) )
1327 throw XMLInvalidBuildFileException (
1329 "module '%s' is trying to link against non-existant module '%s'",
1330 module
.name
.c_str(),
1336 Invoke::Invoke ( const XMLElement
& _node
,
1337 const Module
& _module
)
1344 Invoke::ProcessXML()
1346 const XMLAttribute
* att
= node
.GetAttribute ( "module", false );
1348 invokeModule
= &module
;
1351 invokeModule
= module
.project
.LocateModule ( att
->value
);
1352 if ( invokeModule
== NULL
)
1354 throw XMLInvalidBuildFileException (
1356 "module '%s' is trying to invoke non-existant module '%s'",
1357 module
.name
.c_str(),
1358 att
->value
.c_str() );
1362 for ( size_t i
= 0; i
< node
.subElements
.size (); i
++ )
1363 ProcessXMLSubElement ( *node
.subElements
[i
] );
1367 Invoke::ProcessXMLSubElement ( const XMLElement
& e
)
1369 bool subs_invalid
= false;
1370 if ( e
.name
== "input" )
1372 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1373 ProcessXMLSubElementInput ( *e
.subElements
[i
] );
1375 else if ( e
.name
== "output" )
1377 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1378 ProcessXMLSubElementOutput ( *e
.subElements
[i
] );
1380 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1382 throw XMLInvalidBuildFileException (
1384 "<%s> cannot have sub-elements",
1390 Invoke::ProcessXMLSubElementInput ( const XMLElement
& e
)
1392 bool subs_invalid
= false;
1393 if ( e
.name
== "inputfile" && e
.value
.size () > 0 )
1395 input
.push_back ( new InvokeFile (
1396 e
, FixSeparator ( module
.output
->relative_path
+ cSep
+ e
.value
) ) );
1397 subs_invalid
= true;
1399 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1401 throw XMLInvalidBuildFileException (
1403 "<%s> cannot have sub-elements",
1409 Invoke::ProcessXMLSubElementOutput ( const XMLElement
& e
)
1411 bool subs_invalid
= false;
1412 if ( e
.name
== "outputfile" && e
.value
.size () > 0 )
1414 output
.push_back ( new InvokeFile (
1415 e
, FixSeparator ( module
.output
->relative_path
+ cSep
+ e
.value
) ) );
1416 subs_invalid
= true;
1418 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1420 throw XMLInvalidBuildFileException (
1422 "<%s> cannot have sub-elements",
1428 Invoke::GetTargets ( string_list
& targets
) const
1430 for ( size_t i
= 0; i
< output
.size (); i
++ )
1432 InvokeFile
& file
= *output
[i
];
1433 targets
.push_back ( NormalizeFilename ( file
.name
) );
1438 Invoke::GetParameters () const
1440 string
parameters ( "" );
1442 for ( i
= 0; i
< output
.size (); i
++ )
1444 if ( parameters
.length () > 0)
1446 InvokeFile
& invokeFile
= *output
[i
];
1447 if ( invokeFile
.switches
.length () > 0 )
1449 parameters
+= invokeFile
.switches
+ " ";
1451 parameters
+= invokeFile
.name
;
1454 for ( i
= 0; i
< input
.size (); i
++ )
1456 if ( parameters
.length () > 0 )
1458 InvokeFile
& invokeFile
= *input
[i
];
1459 if ( invokeFile
.switches
.length () > 0 )
1461 parameters
+= invokeFile
.switches
;
1464 parameters
+= invokeFile
.name
;
1471 InvokeFile::InvokeFile ( const XMLElement
& _node
,
1472 const string
& _name
)
1476 const XMLAttribute
* att
= _node
.GetAttribute ( "switches", false );
1478 switches
= att
->value
;
1484 InvokeFile::ProcessXML()
1489 Dependency::Dependency ( const XMLElement
& _node
,
1490 const Module
& _module
)
1493 dependencyModule (NULL
)
1498 Dependency::ProcessXML()
1500 dependencyModule
= module
.project
.LocateModule ( node
.value
);
1501 if ( dependencyModule
== NULL
)
1503 throw XMLInvalidBuildFileException (
1505 "module '%s' depend on non-existant module '%s'",
1506 module
.name
.c_str(),
1507 node
.value
.c_str() );
1512 Metadata::Metadata ( const XMLElement
& _node
,
1513 const Module
& _module
)
1517 /* The module name */
1518 const XMLAttribute
* att
= _node
.GetAttribute ( "name", false );
1524 /* The module description */
1525 att
= _node
.GetAttribute ( "description", false );
1527 description
= att
->value
;
1531 /* The module version */
1532 att
= _node
.GetAttribute ( "version", false );
1534 version
= att
->value
;
1538 /* The module copyright */
1539 att
= _node
.GetAttribute ( "copyright", false );
1541 copyright
= att
->value
;
1545 att
= _node
.GetAttribute ( "url", false );
1551 /* When was this module updated */
1552 att
= _node
.GetAttribute ( "date", false );
1558 /* When was this module updated */
1559 att
= _node
.GetAttribute ( "owner", false );
1567 ImportLibrary::ImportLibrary ( const Project
& project
,
1568 const XMLElement
& node
,
1569 const Module
& module
)
1570 : XmlNode ( project
, node
),
1573 const XMLAttribute
* dllname
= node
.GetAttribute ( "dllname", false );
1574 const XMLAttribute
* definition
= node
.GetAttribute ( "definition", true );
1575 assert ( definition
);
1578 this->dllname
= dllname
->value
;
1579 else if ( module
.type
== StaticLibrary
)
1580 throw XMLInvalidBuildFileException (
1582 "<importlibrary> dllname attribute required." );
1584 DirectoryLocation directory
= SourceDirectory
;
1585 size_t index
= definition
->value
.rfind ( ".spec.def" );
1586 if ( index
!= string::npos
)
1587 directory
= IntermediateDirectory
;
1589 index
= definition
->value
.find_last_of ( "/\\" );
1590 if ( index
== string::npos
)
1592 source
= new FileLocation ( directory
,
1593 module
.output
->relative_path
,
1599 string dir
= definition
->value
.substr ( 0, index
);
1600 string name
= definition
->value
.substr ( index
+ 1);
1601 source
= new FileLocation ( directory
,
1602 NormalizeFilename ( module
.output
->relative_path
+ sSep
+ dir
),
1609 If::If ( const XMLElement
& node_
,
1610 const Project
& project_
,
1611 const Module
* module_
,
1612 const bool negated_
)
1613 : node(node_
), project(project_
), module(module_
), negated(negated_
)
1615 const XMLAttribute
* att
;
1617 att
= node
.GetAttribute ( "property", true );
1619 property
= att
->value
;
1621 att
= node
.GetAttribute ( "value", true );
1637 Property::Property ( const XMLElement
& node_
,
1638 const Project
& project_
,
1639 const Module
* module_
)
1640 : project(project_
), module(module_
)
1642 const XMLAttribute
* att
;
1644 att
= node_
.GetAttribute ( "name", true );
1646 name
= project
.ResolveProperties ( att
->value
);
1648 att
= node_
.GetAttribute ( "value", true );
1653 Property::Property ( const Project
& project_
,
1654 const Module
* module_
,
1655 const std::string
& name_
,
1656 const std::string
& value_
)
1657 : project(project_
), module(module_
), name(name_
), value(value_
)
1662 Property::ProcessXML()
1668 const XMLElement
& node_
,
1669 const Module
& module_
,
1670 const FileLocation
& file_
)
1671 : node(node_
), module(module_
), file(file_
)
1676 PchFile::ProcessXML()