2 * Copyright (C) 2005 Casper S. Hornstrup
3 * Copyright (C) 2008 Hervé Poussineau
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 Right ( const string
& s
, size_t n
)
32 return string ( &s
[s
.size()-n
] );
36 Replace ( const string
& s
, const string
& find
, const string
& with
)
39 const char* p
= s
.c_str();
42 const char* p2
= strstr ( p
, find
.c_str() );
46 ret
+= string ( p
, p2
-p
);
56 ChangeSeparator ( const string
& s
,
57 const char fromSeparator
,
58 const char toSeparator
)
61 char* p
= strchr ( &s2
[0], fromSeparator
);
65 p
= strchr ( p
, fromSeparator
);
71 FixSeparator ( const string
& s
)
73 return ChangeSeparator ( s
, cBadSep
, cSep
);
77 FixSeparatorForSystemCommand ( const string
& s
)
80 char* p
= strchr ( &s2
[0], DEF_CBAD_SEP
);
84 p
= strchr ( p
, DEF_CBAD_SEP
);
90 DosSeparator ( const string
& s
)
93 char* p
= strchr ( &s2
[0], '/' );
97 p
= strchr ( p
, '/' );
104 const string
& filename
,
105 const string
& newExtension
)
107 size_t index
= filename
.find_last_of ( '/' );
108 if ( index
== string::npos
)
110 size_t index2
= filename
.find_last_of ( '\\' );
111 if ( index2
!= string::npos
&& index2
> index
)
113 string tmp
= filename
.substr( index
/*, filename.size() - index*/ );
114 size_t ext_index
= tmp
.find_last_of( '.' );
115 if ( ext_index
!= string::npos
)
116 return filename
.substr ( 0, index
+ ext_index
) + newExtension
;
117 return filename
+ newExtension
;
122 const Project
& project
,
123 const string
& location
,
125 const string
& att_value
)
127 if ( !att_value
.size() )
128 throw XMLInvalidBuildFileException (
130 "<directory> tag has empty 'name' attribute" );
131 if ( strpbrk ( att_value
.c_str (), "/\\?*:<>|" ) )
132 throw XMLInvalidBuildFileException (
134 "<directory> tag has invalid characters in 'name' attribute" );
138 return FixSeparator(path
+ cSep
+ att_value
);
142 GetExtension ( const string
& filename
)
144 size_t index
= filename
.find_last_of ( '/' );
145 if (index
== string::npos
) index
= 0;
146 string tmp
= filename
.substr( index
, filename
.size() - index
);
147 size_t ext_index
= tmp
.find_last_of( '.' );
148 if (ext_index
!= string::npos
)
149 return filename
.substr ( index
+ ext_index
, filename
.size() );
154 GetExtension ( const FileLocation
& file
)
156 return GetExtension ( file
.name
);
160 NormalizeFilename ( const string
& filename
)
162 if ( filename
== "" )
165 string normalizedPath
= path
.Fixup ( filename
, true );
166 string relativeNormalizedPath
= path
.RelativeFromWorkingDirectory ( normalizedPath
);
167 return FixSeparator ( relativeNormalizedPath
);
171 GetBooleanValue ( const string
& value
)
180 ToLower ( string filename
)
182 for ( size_t i
= 1; i
< filename
.length (); i
++ )
183 filename
[i
] = tolower ( filename
[i
] );
187 IfableData::IfableData( )
192 void IfableData::ExtractModules( std::map
<std::string
, Module
*> &modules
)
195 for ( i
= 0; i
< this->modules
.size (); i
++ )
196 modules
.insert(std::make_pair(this->modules
[i
]->name
, this->modules
[i
]));
199 IfableData::~IfableData()
202 for ( i
= 0; i
< includes
.size (); i
++ )
204 for ( i
= 0; i
< defines
.size (); i
++ )
206 for ( i
= 0; i
< libraries
.size (); i
++ )
208 for ( std::map
<std::string
, Property
*>::const_iterator p
= properties
.begin(); p
!= properties
.end(); ++ p
)
210 for ( i
= 0; i
< compilerFlags
.size (); i
++ )
211 delete compilerFlags
[i
];
212 for ( i
= 0; i
< modules
.size(); i
++ )
214 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
215 delete compilationUnits
[i
];
218 void IfableData::ProcessXML ()
221 for ( i
= 0; i
< includes
.size (); i
++ )
222 includes
[i
]->ProcessXML ();
223 for ( i
= 0; i
< defines
.size (); i
++ )
224 defines
[i
]->ProcessXML ();
225 for ( i
= 0; i
< libraries
.size (); i
++ )
226 libraries
[i
]->ProcessXML ();
227 for ( std::map
<std::string
, Property
*>::const_iterator p
= properties
.begin(); p
!= properties
.end(); ++ p
)
228 p
->second
->ProcessXML ();
229 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
230 compilerFlags
[i
]->ProcessXML ();
231 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
232 compilationUnits
[i
]->ProcessXML ();
235 Module::Module ( const Project
& project
,
236 const XMLElement
& moduleNode
,
237 const string
& modulePath
)
240 importLibrary (NULL
),
251 if ( node
.name
!= "module" )
252 throw InvalidOperationException ( __FILE__
,
254 "Module created with non-<module> node" );
256 xmlbuildFile
= FixSeparator ( Path::RelativeFromWorkingDirectory ( moduleNode
.xmlFile
->filename () ) );
258 const XMLAttribute
* att
= moduleNode
.GetAttribute ( "name", true );
264 att
= moduleNode
.GetAttribute ( "if", false );
266 enabled
= GetBooleanValue ( project
.ResolveProperties ( att
->value
) );
268 att
= moduleNode
.GetAttribute ( "ifnot", false );
270 enabled
= !GetBooleanValue ( project
.ResolveProperties ( att
->value
) );
272 if ( !enabled
&& project
.configuration
.Verbose
)
273 printf("Module '%s' has been disabled.\n", name
.c_str () );
275 att
= moduleNode
.GetAttribute ( "type", true );
277 type
= GetModuleType ( node
.location
, *att
);
279 att
= moduleNode
.GetAttribute ( "extension", false );
281 extension
= att
->value
;
283 extension
= GetDefaultModuleExtension ();
285 att
= moduleNode
.GetAttribute ( "unicode", false );
288 const char* p
= att
->value
.c_str();
289 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
291 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
295 throw InvalidAttributeValueException (
306 // Always define UNICODE and _UNICODE
307 Define
* pDefine
= new Define ( project
, this, "UNICODE" );
308 non_if_data
.defines
.push_back ( pDefine
);
310 pDefine
= new Define ( project
, this, "_UNICODE" );
311 non_if_data
.defines
.push_back ( pDefine
);
314 att
= moduleNode
.GetAttribute ( "entrypoint", false );
317 if ( att
->value
== "" )
319 throw InvalidAttributeValueException (
325 entrypoint
= att
->value
;
326 isDefaultEntryPoint
= false;
330 entrypoint
= GetDefaultModuleEntrypoint ();
331 isDefaultEntryPoint
= true;
334 att
= moduleNode
.GetAttribute ( "baseaddress", false );
336 baseaddress
= att
->value
;
338 baseaddress
= GetDefaultModuleBaseaddress ();
340 att
= moduleNode
.GetAttribute ( "mangledsymbols", false );
343 const char* p
= att
->value
.c_str();
344 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
345 mangledSymbols
= true;
346 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
347 mangledSymbols
= false;
350 throw InvalidAttributeValueException (
357 mangledSymbols
= false;
359 att
= moduleNode
.GetAttribute ( "underscoresymbols", false );
361 underscoreSymbols
= att
->value
== "true";
363 underscoreSymbols
= false;
365 att
= moduleNode
.GetAttribute ( "isstartuplib", false );
368 const char* p
= att
->value
.c_str();
369 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
371 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
372 isStartupLib
= false;
375 throw InvalidAttributeValueException (
382 isStartupLib
= false;
384 att
= moduleNode
.GetAttribute ( "prefix", false );
388 att
= moduleNode
.GetAttribute ( "installname", false );
391 const XMLAttribute
* installbase
= moduleNode
.GetAttribute ( "installbase", false );
392 install
= new FileLocation ( InstallDirectory
,
393 installbase
? installbase
->value
: "",
397 output
= new FileLocation ( GetTargetDirectoryTree (),
403 att
= moduleNode
.GetAttribute ( "output", false );
408 printf ( "%s: WARNING: 'installname' overrides 'output' also defined for this module.\n",
409 moduleNode
.location
.c_str() );
413 output
= new FileLocation ( GetTargetDirectoryTree (),
420 /* If no one has set the output file for this module set it automatically */
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 att
= moduleNode
.GetAttribute ( "description", false );
472 description
= project
.ResolveProperties(att
->value
);
477 att
= moduleNode
.GetAttribute ( "lcid", false );
478 if (type
== KeyboardLayout
&& att
!= NULL
)
483 att
= moduleNode
.GetAttribute ( "layoutid", false );
484 if (type
== KeyboardLayout
&& att
!= NULL
)
485 layoutId
= att
->value
;
489 att
= moduleNode
.GetAttribute ( "layoutnameresid", false );
490 if (type
== KeyboardLayout
&& att
!= NULL
)
491 layoutNameResId
= att
->value
;
493 layoutNameResId
= "";
495 SetImportLibrary ( NULL
);
501 for ( i
= 0; i
< invocations
.size(); i
++ )
502 delete invocations
[i
];
503 for ( i
= 0; i
< dependencies
.size(); i
++ )
504 delete dependencies
[i
];
505 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
506 delete compilerFlags
[i
];
507 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
508 delete linkerFlags
[i
];
509 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
510 delete stubbedComponents
[i
];
522 delete importLibrary
;
538 aliasedModuleName
= project
.ResolveProperties ( aliasedModuleName
);
539 if ( aliasedModuleName
== name
)
541 throw XMLInvalidBuildFileException (
543 "module '%s' cannot link against itself",
546 const Module
* m
= project
.LocateModule ( aliasedModuleName
);
549 throw XMLInvalidBuildFileException (
551 "module '%s' trying to alias non-existant module '%s'",
553 aliasedModuleName
.c_str() );
558 for ( i
= 0; i
< node
.subElements
.size(); i
++ )
560 ParseContext parseContext
;
561 ProcessXMLSubElement ( *node
.subElements
[i
], SourceDirectory
, output
->relative_path
, parseContext
);
563 for ( i
= 0; i
< invocations
.size(); i
++ )
564 invocations
[i
]->ProcessXML ();
565 for ( i
= 0; i
< dependencies
.size(); i
++ )
566 dependencies
[i
]->ProcessXML ();
567 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
568 compilerFlags
[i
]->ProcessXML();
569 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
570 linkerFlags
[i
]->ProcessXML();
571 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
572 stubbedComponents
[i
]->ProcessXML();
573 non_if_data
.ProcessXML();
575 linkerScript
->ProcessXML();
579 autoRegister
->ProcessXML();
583 Module::ProcessXMLSubElement ( const XMLElement
& e
,
584 DirectoryLocation directory
,
585 const string
& relative_path
,
586 ParseContext
& parseContext
)
588 CompilationUnit
* pOldCompilationUnit
= parseContext
.compilationUnit
;
589 bool subs_invalid
= false;
590 string
subpath ( relative_path
);
591 DirectoryLocation subdirectory
= SourceDirectory
;
592 if ( e
.name
== "file" && e
.value
.size () > 0 )
595 const XMLAttribute
* att
= e
.GetAttribute ( "first", false );
598 if ( !stricmp ( att
->value
.c_str(), "true" ) )
600 else if ( stricmp ( att
->value
.c_str(), "false" ) )
602 throw XMLInvalidBuildFileException (
604 "attribute 'first' of <file> element can only be 'true' or 'false'" );
607 string switches
= "";
608 att
= e
.GetAttribute ( "switches", false );
610 switches
= att
->value
;
613 // check for c++ file
614 string ext
= GetExtension ( e
.value
);
615 if ( !stricmp ( ext
.c_str(), ".cpp" ) )
617 else if ( !stricmp ( ext
.c_str(), ".cc" ) )
619 else if ( !stricmp ( ext
.c_str(), ".cxx" ) )
622 File
* pFile
= new File ( directory
,
628 if ( parseContext
.compilationUnit
)
629 parseContext
.compilationUnit
->AddFile ( pFile
);
632 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( pFile
);
633 string ext
= ToLower ( GetExtension ( e
.value
) );
636 // put .idl files at the start of the module
637 non_if_data
.compilationUnits
.insert (
638 non_if_data
.compilationUnits
.begin(),
641 else if ( ext
== ".asm" || ext
== ".s" )
643 // put .asm files at the end of the module
644 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
645 non_if_data
.asmFiles
++;
649 // put other files in the middle
650 non_if_data
.compilationUnits
.insert (
651 non_if_data
.compilationUnits
.end() - non_if_data
.asmFiles
,
655 non_if_data
.files
.push_back ( pFile
);
658 else if ( e
.name
== "library" && e
.value
.size () )
660 Library
* pLibrary
= new Library ( e
, *this, e
.value
);
661 non_if_data
.libraries
.push_back ( pLibrary
);
664 else if ( e
.name
== "directory" )
666 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
667 const XMLAttribute
* root
= e
.GetAttribute ( "root", false );
671 if ( root
->value
== "intermediate" )
672 subdirectory
= IntermediateDirectory
;
673 else if ( root
->value
== "output" )
674 subdirectory
= OutputDirectory
;
677 throw InvalidAttributeValueException (
683 subpath
= GetSubPath ( this->project
, e
.location
, relative_path
, att
->value
);
685 else if ( e
.name
== "include" )
687 Include
* include
= new Include ( project
, &e
, this );
688 non_if_data
.includes
.push_back ( include
);
691 else if ( e
.name
== "define" )
693 Define
* pDefine
= new Define ( project
, this, e
);
694 non_if_data
.defines
.push_back ( pDefine
);
697 else if ( e
.name
== "metadata" )
699 metadata
= new Metadata ( e
, *this );
700 subs_invalid
= false;
702 else if ( e
.name
== "invoke" )
704 invocations
.push_back ( new Invoke ( e
, *this ) );
705 subs_invalid
= false;
707 else if ( e
.name
== "dependency" )
709 dependencies
.push_back ( new Dependency ( e
, *this ) );
712 else if ( e
.name
== "bootsector" )
714 bootSector
= new Bootsector ( e
, this );
717 else if ( e
.name
== "importlibrary" )
721 throw XMLInvalidBuildFileException (
723 "Only one <importlibrary> is valid per module" );
725 SetImportLibrary ( new ImportLibrary ( project
, e
, this ) );
728 else if ( e
.name
== "if" || e
.name
== "ifnot" )
730 const XMLAttribute
* name
;
731 name
= e
.GetAttribute ( "property", true );
733 const Property
*property
= project
.LookupProperty( name
->value
);
736 // Property not found
737 throw InvalidOperationException ( __FILE__
,
739 "Test on unknown property '%s' at %s",
740 name
->value
.c_str (), e
.location
.c_str () );
743 const XMLAttribute
* value
;
744 value
= e
.GetAttribute ( "value", true );
747 bool negate
= ( e
.name
== "ifnot" );
748 bool equality
= ( property
->value
== value
->value
);
749 if ( equality
== negate
)
751 // Failed, skip this element
752 if ( project
.configuration
.Verbose
)
753 printf("Skipping 'If' at %s\n", e
.location
.c_str () );
756 subs_invalid
= false;
758 else if ( e
.name
== "compilerflag" )
760 CompilerFlag
* pCompilerFlag
= new CompilerFlag ( project
, this, e
);
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" )
773 throw XMLInvalidBuildFileException (
775 "Only one <linkerscript> is valid per module" );
777 size_t pos
= e
.value
.find_last_of ( "/\\" );
778 if ( pos
== string::npos
)
780 linkerScript
= new LinkerScript (
781 e
, *this, new FileLocation ( SourceDirectory
, relative_path
, e
.value
, &e
) );
785 string dir
= e
.value
.substr ( 0, pos
);
786 string name
= e
.value
.substr ( pos
+ 1);
787 linkerScript
= new LinkerScript (
788 e
, *this, new FileLocation ( SourceDirectory
, relative_path
+ sSep
+ dir
, name
, &e
) );
792 else if ( e
.name
== "component" )
794 stubbedComponents
.push_back ( new StubbedComponent ( this, e
) );
795 subs_invalid
= false;
797 else if ( e
.name
== "property" )
799 throw XMLInvalidBuildFileException (
801 "<property> is not a valid sub-element of <module>" );
803 else if ( e
.name
== "bootstrap" )
805 bootstrap
= new Bootstrap ( project
, this, e
);
808 else if ( e
.name
== "pch" )
812 throw XMLInvalidBuildFileException (
814 "Only one <pch> is valid per module" );
816 size_t pos
= e
.value
.find_last_of ( "/\\" );
817 if ( pos
== string::npos
)
820 e
, *this, new FileLocation ( SourceDirectory
, relative_path
, e
.value
, &e
) );
824 string dir
= e
.value
.substr ( 0, pos
);
825 string name
= e
.value
.substr ( pos
+ 1);
827 e
, *this, new FileLocation ( SourceDirectory
, relative_path
+ sSep
+ dir
, name
, &e
) );
831 else if ( e
.name
== "compilationunit" )
833 if ( project
.configuration
.CompilationUnitsEnabled
)
835 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( &project
, this, &e
);
836 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
837 parseContext
.compilationUnit
= pCompilationUnit
;
839 subs_invalid
= false;
841 else if ( e
.name
== "autoregister" )
843 if ( autoRegister
!= NULL
)
845 throw XMLInvalidBuildFileException (
847 "there can be only one <%s> element for a module",
850 autoRegister
= new AutoRegister ( project
, this, e
);
853 if ( subs_invalid
&& e
.subElements
.size() > 0 )
855 throw XMLInvalidBuildFileException (
857 "<%s> cannot have sub-elements",
860 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
861 ProcessXMLSubElement ( *e
.subElements
[i
], subdirectory
, subpath
, parseContext
);
862 parseContext
.compilationUnit
= pOldCompilationUnit
;
866 Module::GetModuleType ( const string
& location
, const XMLAttribute
& attribute
)
868 if ( attribute
.value
== "buildtool" )
870 if ( attribute
.value
== "staticlibrary" )
871 return StaticLibrary
;
872 if ( attribute
.value
== "hoststaticlibrary" )
873 return HostStaticLibrary
;
874 if ( attribute
.value
== "objectlibrary" )
875 return ObjectLibrary
;
876 if ( attribute
.value
== "kernel" )
878 if ( attribute
.value
== "kernelmodedll" )
879 return KernelModeDLL
;
880 if ( attribute
.value
== "kernelmodedriver" )
881 return KernelModeDriver
;
882 if ( attribute
.value
== "nativedll" )
884 if ( attribute
.value
== "nativecui" )
886 if ( attribute
.value
== "keyboardlayout" )
887 return KeyboardLayout
;
888 if ( attribute
.value
== "win32dll" )
890 if ( attribute
.value
== "win32ocx" )
892 if ( attribute
.value
== "win32cui" )
894 if ( attribute
.value
== "win32gui" )
896 if ( attribute
.value
== "win32scr" )
898 if ( attribute
.value
== "bootloader" )
900 if ( attribute
.value
== "bootsector" )
902 if ( attribute
.value
== "bootprogram" )
904 if ( attribute
.value
== "iso" )
906 if ( attribute
.value
== "liveiso" )
908 if ( attribute
.value
== "isoregtest" )
910 if ( attribute
.value
== "liveisoregtest" )
911 return LiveIsoRegTest
;
912 if ( attribute
.value
== "test" )
914 if ( attribute
.value
== "rpcserver" )
916 if ( attribute
.value
== "rpcclient" )
918 if ( attribute
.value
== "rpcproxy" )
920 if ( attribute
.value
== "alias" )
922 if ( attribute
.value
== "idlheader" )
924 if ( attribute
.value
== "embeddedtypelib" )
925 return EmbeddedTypeLib
;
926 if ( attribute
.value
== "elfexecutable" )
927 return ElfExecutable
;
928 if ( attribute
.value
== "cabinet" )
930 if ( attribute
.value
== "messageheader" )
931 return MessageHeader
;
932 throw InvalidAttributeValueException ( location
,
938 Module::GetTargetDirectoryTree () const
948 case KernelModeDriver
:
964 return OutputDirectory
;
965 case EmbeddedTypeLib
:
967 case HostStaticLibrary
:
975 return IntermediateDirectory
;
979 throw InvalidOperationException ( __FILE__
,
981 "Invalid module type %d.",
986 Module::GetDefaultModuleExtension () const
994 case HostStaticLibrary
:
1008 case KeyboardLayout
:
1013 case KernelModeDriver
:
1023 case LiveIsoRegTest
:
1036 case EmbeddedTypeLib
:
1041 throw InvalidOperationException ( __FILE__
,
1046 Module::GetDefaultModuleEntrypoint () const
1051 return "KiSystemStartup";
1052 case KeyboardLayout
:
1054 case KernelModeDriver
:
1055 if (Environment::GetArch() == "arm") return "DriverEntry";
1056 return "DriverEntry@8";
1058 if (Environment::GetArch() == "arm") return "DllMainCRTStartup";
1059 return "DllMainCRTStartup@12";
1061 if (Environment::GetArch() == "arm") return "NtProcessStartup";
1062 return "NtProcessStartup@4";
1065 if (Environment::GetArch() == "arm") return "DllMain";
1066 return "DllMain@12";
1070 return "wmainCRTStartup";
1072 return "mainCRTStartup";
1076 return "wWinMainCRTStartup";
1078 return "WinMainCRTStartup";
1081 case HostStaticLibrary
:
1088 case LiveIsoRegTest
:
1097 case EmbeddedTypeLib
:
1103 throw InvalidOperationException ( __FILE__
,
1108 Module::GetDefaultModuleBaseaddress () const
1113 return "0x80800000";
1116 return "0x10000000";
1121 return "0x00400000";
1124 return "0x00400000";
1125 case KeyboardLayout
:
1127 case KernelModeDriver
:
1128 return "0x00010000";
1133 case HostStaticLibrary
:
1140 case LiveIsoRegTest
:
1148 case EmbeddedTypeLib
:
1154 throw InvalidOperationException ( __FILE__
,
1159 Module::HasImportLibrary () const
1161 return importLibrary
!= NULL
&& type
!= StaticLibrary
&& type
!= HostStaticLibrary
;
1165 Module::IsDLL () const
1172 case KeyboardLayout
:
1175 case KernelModeDriver
:
1184 case HostStaticLibrary
:
1192 case LiveIsoRegTest
:
1199 case EmbeddedTypeLib
:
1206 throw InvalidOperationException ( __FILE__
,
1211 Module::GetPathWithPrefix ( const string
& prefix
) const
1213 return output
->relative_path
+ cSep
+ prefix
+ output
->name
;
1217 Module::GetPathToBaseDir () const
1219 string temp_path
= output
->relative_path
;
1220 string result
= "..\\";
1221 while(temp_path
.find ('\\') != string::npos
)
1223 temp_path
.erase (0, temp_path
.find('\\')+1);
1230 Module::GetInvocationTarget ( const int index
) const
1232 return ssprintf ( "%s_invoke_%d",
1238 Module::GetEntryPoint(bool leadingUnderscore
) const
1241 if (entrypoint
== "0" || entrypoint
== "0x0")
1243 if (leadingUnderscore
)
1246 result
+= entrypoint
;
1248 if (Environment::GetArch() == "amd64")
1250 size_t at_index
= result
.find_last_of( '@' );
1251 if ( at_index
!= result
.npos
)
1252 return result
.substr (0, at_index
);
1259 Module::HasFileWithExtension (
1260 const IfableData
& data
,
1261 const std::string
& extension
) const
1264 for ( i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1266 CompilationUnit
* compilationUnit
= data
.compilationUnits
[i
];
1267 if ( compilationUnit
->HasFileWithExtension ( extension
) )
1274 Module::InvokeModule () const
1276 for ( size_t i
= 0; i
< invocations
.size (); i
++ )
1278 Invoke
& invoke
= *invocations
[i
];
1279 string command
= FixSeparatorForSystemCommand(invoke
.invokeModule
->output
->relative_path
+ "/" + invoke
.invokeModule
->output
->name
) + " " + invoke
.GetParameters ();
1280 printf ( "Executing '%s'\n\n", command
.c_str () );
1281 int exitcode
= system ( command
.c_str () );
1282 if ( exitcode
!= 0 )
1283 throw InvocationFailedException ( command
,
1290 Module::SetImportLibrary ( ImportLibrary
* importLibrary
)
1292 this->importLibrary
= importLibrary
;
1293 dependency
= new FileLocation ( HasImportLibrary () ? IntermediateDirectory
: output
->directory
,
1294 output
->relative_path
,
1295 HasImportLibrary () ? "lib" + name
+ ".a" : output
->name
);
1299 File::File ( DirectoryLocation directory
,
1300 const string
& relative_path
,
1303 const string
& _switches
,
1304 bool _isPreCompiledHeader
)
1305 : file ( directory
, relative_path
, name
),
1307 switches(_switches
),
1308 isPreCompiledHeader(_isPreCompiledHeader
)
1319 std::string
File::GetFullPath () const
1321 string
directory ( "" );
1322 switch ( file
.directory
)
1324 case SourceDirectory
:
1326 case IntermediateDirectory
:
1327 directory
= Environment::GetIntermediatePath () + sSep
;
1330 throw InvalidOperationException ( __FILE__
,
1332 "Invalid directory %d.",
1336 if ( file
.relative_path
.length () > 0 )
1337 directory
+= file
.relative_path
+ sSep
;
1340 return directory
+ file
.name
;
1344 Library::Library ( const XMLElement
& _node
,
1345 const Module
& _module
,
1346 const string
& _name
)
1350 importedModule(_module
.project
.LocateModule(_name
))
1352 if ( module
.name
== name
)
1354 throw XMLInvalidBuildFileException (
1356 "module '%s' cannot link against itself",
1359 if ( !importedModule
)
1361 throw XMLInvalidBuildFileException (
1363 "module '%s' trying to import non-existant module '%s'",
1364 module
.name
.c_str(),
1369 Library::Library ( const Module
& _module
,
1370 const string
& _name
)
1374 importedModule(_module
.project
.LocateModule(_name
))
1379 Library::ProcessXML()
1381 if ( node
&& !module
.project
.LocateModule ( name
) )
1383 throw XMLInvalidBuildFileException (
1385 "module '%s' is trying to link against non-existant module '%s'",
1386 module
.name
.c_str(),
1392 Invoke::Invoke ( const XMLElement
& _node
,
1393 const Module
& _module
)
1400 Invoke::ProcessXML()
1402 const XMLAttribute
* att
= node
.GetAttribute ( "module", false );
1404 invokeModule
= &module
;
1407 invokeModule
= module
.project
.LocateModule ( att
->value
);
1408 if ( invokeModule
== NULL
)
1410 throw XMLInvalidBuildFileException (
1412 "module '%s' is trying to invoke non-existant module '%s'",
1413 module
.name
.c_str(),
1414 att
->value
.c_str() );
1418 for ( size_t i
= 0; i
< node
.subElements
.size (); i
++ )
1419 ProcessXMLSubElement ( *node
.subElements
[i
] );
1423 Invoke::ProcessXMLSubElement ( const XMLElement
& e
)
1425 bool subs_invalid
= false;
1426 if ( e
.name
== "input" )
1428 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1429 ProcessXMLSubElementInput ( *e
.subElements
[i
] );
1431 else if ( e
.name
== "output" )
1433 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1434 ProcessXMLSubElementOutput ( *e
.subElements
[i
] );
1436 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1438 throw XMLInvalidBuildFileException (
1440 "<%s> cannot have sub-elements",
1446 Invoke::ProcessXMLSubElementInput ( const XMLElement
& e
)
1448 bool subs_invalid
= false;
1449 if ( e
.name
== "inputfile" && e
.value
.size () > 0 )
1451 input
.push_back ( new InvokeFile (
1452 e
, FixSeparator ( module
.output
->relative_path
+ cSep
+ e
.value
) ) );
1453 subs_invalid
= true;
1455 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1457 throw XMLInvalidBuildFileException (
1459 "<%s> cannot have sub-elements",
1465 Invoke::ProcessXMLSubElementOutput ( const XMLElement
& e
)
1467 bool subs_invalid
= false;
1468 if ( e
.name
== "outputfile" && e
.value
.size () > 0 )
1470 output
.push_back ( new InvokeFile (
1471 e
, FixSeparator ( module
.output
->relative_path
+ cSep
+ e
.value
) ) );
1472 subs_invalid
= true;
1474 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1476 throw XMLInvalidBuildFileException (
1478 "<%s> cannot have sub-elements",
1484 Invoke::GetTargets ( string_list
& targets
) const
1486 for ( size_t i
= 0; i
< output
.size (); i
++ )
1488 InvokeFile
& file
= *output
[i
];
1489 targets
.push_back ( NormalizeFilename ( file
.name
) );
1494 Invoke::GetParameters () const
1496 string
parameters ( "" );
1498 for ( i
= 0; i
< output
.size (); i
++ )
1500 if ( parameters
.length () > 0)
1502 InvokeFile
& invokeFile
= *output
[i
];
1503 if ( invokeFile
.switches
.length () > 0 )
1505 parameters
+= invokeFile
.switches
+ " ";
1507 parameters
+= invokeFile
.name
;
1510 for ( i
= 0; i
< input
.size (); i
++ )
1512 if ( parameters
.length () > 0 )
1514 InvokeFile
& invokeFile
= *input
[i
];
1515 if ( invokeFile
.switches
.length () > 0 )
1517 parameters
+= invokeFile
.switches
;
1520 parameters
+= invokeFile
.name
;
1527 InvokeFile::InvokeFile ( const XMLElement
& _node
,
1528 const string
& _name
)
1532 const XMLAttribute
* att
= _node
.GetAttribute ( "switches", false );
1534 switches
= att
->value
;
1540 InvokeFile::ProcessXML()
1545 Dependency::Dependency ( const XMLElement
& _node
,
1546 const Module
& _module
)
1549 dependencyModule (NULL
)
1554 Dependency::ProcessXML()
1556 dependencyModule
= module
.project
.LocateModule ( node
.value
);
1557 if ( dependencyModule
== NULL
)
1559 throw XMLInvalidBuildFileException (
1561 "module '%s' depend on non-existant module '%s'",
1562 module
.name
.c_str(),
1563 node
.value
.c_str() );
1567 Bootsector::Bootsector ( const XMLElement
& _node
,
1568 const Module
* _module
)
1571 bootSectorModule (NULL
)
1573 if ( !IsSupportedModuleType ( module
->type
) )
1575 throw XMLInvalidBuildFileException (
1577 "<bootsector> is not applicable for this module type." );
1580 bootSectorModule
= module
->project
.LocateModule ( node
.value
);
1581 if ( bootSectorModule
== NULL
)
1583 throw XMLInvalidBuildFileException (
1585 "module '%s' depend on non-existant module '%s'",
1586 module
->name
.c_str(),
1587 node
.value
.c_str() );
1590 if (bootSectorModule
->type
!= BootSector
)
1592 throw XMLInvalidBuildFileException (
1594 "module '%s' is referencing non BootSector module '%s'",
1595 module
->name
.c_str(),
1596 node
.value
.c_str() );
1601 Bootsector::ProcessXML()
1606 Bootsector::IsSupportedModuleType ( ModuleType type
)
1610 type
== IsoRegTest
||
1611 type
== LiveIsoRegTest
)
1619 Metadata::Metadata ( const XMLElement
& _node
,
1620 const Module
& _module
)
1624 /* The module name */
1625 const XMLAttribute
* att
= _node
.GetAttribute ( "name", false );
1631 /* The module description */
1632 att
= _node
.GetAttribute ( "description", false );
1634 description
= att
->value
;
1638 /* The module version */
1639 att
= _node
.GetAttribute ( "version", false );
1641 version
= att
->value
;
1645 /* The module copyright */
1646 att
= _node
.GetAttribute ( "copyright", false );
1648 copyright
= att
->value
;
1652 att
= _node
.GetAttribute ( "url", false );
1658 /* When was this module updated */
1659 att
= _node
.GetAttribute ( "date", false );
1665 /* When was this module updated */
1666 att
= _node
.GetAttribute ( "owner", false );
1674 ImportLibrary::~ImportLibrary ()
1680 ImportLibrary::ImportLibrary ( const Project
& project
,
1681 const XMLElement
& node
,
1682 const Module
* module
)
1683 : XmlNode ( project
, node
),
1686 DirectoryLocation directory
= SourceDirectory
;
1687 const Module
* base
= module
;
1688 const XMLAttribute
* dllname
= node
.GetAttribute ( "dllname", false );
1689 const XMLAttribute
* definition
= node
.GetAttribute ( "definition", true );
1690 assert ( definition
);
1692 string relative_path
;
1693 const XMLAttribute
* att
= node
.GetAttribute ( "base", false );
1696 base
= project
.LocateModule ( att
->value
);
1698 throw XMLInvalidBuildFileException (
1700 "<importlibrary> attribute 'base' references non-existant module '%s'",
1701 att
->value
.c_str() );
1707 relative_path
= base
->output
->relative_path
;
1708 if ( node
.value
.length () > 0 && node
.value
!= "." )
1709 relative_path
+= sSep
+ node
.value
;
1712 relative_path
= node
.value
;
1714 att
= node
.GetAttribute ( "root", false );
1717 if ( att
->value
== "intermediate" )
1718 directory
= IntermediateDirectory
;
1720 throw InvalidAttributeValueException ( node
.location
,
1726 this->dllname
= dllname
->value
;
1727 else if ( module
->type
== StaticLibrary
|| module
->type
== HostStaticLibrary
)
1728 throw XMLInvalidBuildFileException (
1730 "<importlibrary> dllname attribute required." );
1732 size_t index
= definition
->value
.find_last_of ( "/\\" );
1733 if ( index
== string::npos
)
1735 source
= new FileLocation ( directory
,
1736 base
->output
->relative_path
,
1742 string dir
= definition
->value
.substr ( 0, index
);
1743 string name
= definition
->value
.substr ( index
+ 1);
1744 source
= new FileLocation ( directory
,
1745 NormalizeFilename ( base
->output
->relative_path
+ sSep
+ dir
),
1752 Property::Property ( const XMLElement
& node_
,
1753 const Project
& project_
,
1754 const Module
* module_
)
1755 : project(project_
), module(module_
)
1757 const XMLAttribute
* att
;
1759 att
= node_
.GetAttribute ( "name", true );
1761 name
= project
.ResolveProperties ( att
->value
);
1763 att
= node_
.GetAttribute ( "value", true );
1767 att
= node_
.GetAttribute ( "internal", false );
1770 const char* p
= att
->value
.c_str();
1771 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
1773 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
1777 throw InvalidAttributeValueException (
1787 Property::Property ( const Project
& project_
,
1788 const Module
* module_
,
1789 const std::string
& name_
,
1790 const std::string
& value_
)
1791 : project(project_
), module(module_
), name(name_
), value(value_
)
1796 Property::ProcessXML()
1802 const XMLElement
& node_
,
1803 const Module
& module_
,
1804 const FileLocation
*file_
)
1805 : node(node_
), module(module_
), file(file_
)
1815 PchFile::ProcessXML()