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 bool Module::GetBooleanAttribute ( const XMLElement
& moduleNode
, const char * name
, bool default_value
)
237 const XMLAttribute
* att
= moduleNode
.GetAttribute ( name
, false );
240 const char* p
= att
->value
.c_str();
241 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
243 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
247 throw InvalidAttributeValueException (
254 return default_value
;
257 Module::Module ( const Project
& project
,
258 const XMLElement
& moduleNode
,
259 const string
& modulePath
)
262 importLibrary (NULL
),
273 if ( node
.name
!= "module" )
274 throw InvalidOperationException ( __FILE__
,
276 "Module created with non-<module> node" );
278 xmlbuildFile
= FixSeparator ( Path::RelativeFromWorkingDirectory ( moduleNode
.xmlFile
->filename () ) );
280 const XMLAttribute
* att
= moduleNode
.GetAttribute ( "name", true );
286 att
= moduleNode
.GetAttribute ( "if", false );
288 enabled
= GetBooleanValue ( project
.ResolveProperties ( att
->value
) );
290 att
= moduleNode
.GetAttribute ( "ifnot", false );
292 enabled
= !GetBooleanValue ( project
.ResolveProperties ( att
->value
) );
294 if ( !enabled
&& project
.configuration
.Verbose
)
295 printf("Module '%s' has been disabled.\n", name
.c_str () );
297 att
= moduleNode
.GetAttribute ( "type", true );
299 type
= GetModuleType ( node
.location
, *att
);
301 att
= moduleNode
.GetAttribute ( "extension", false );
303 extension
= att
->value
;
305 extension
= GetDefaultModuleExtension ();
307 isUnicode
= GetBooleanAttribute ( moduleNode
, "unicode" );
311 // Always define UNICODE and _UNICODE
312 Define
* pDefine
= new Define ( project
, this, "UNICODE" );
313 non_if_data
.defines
.push_back ( pDefine
);
315 pDefine
= new Define ( project
, this, "_UNICODE" );
316 non_if_data
.defines
.push_back ( pDefine
);
319 att
= moduleNode
.GetAttribute ( "entrypoint", false );
322 if ( att
->value
== "" )
324 throw InvalidAttributeValueException (
330 entrypoint
= att
->value
;
331 isDefaultEntryPoint
= false;
335 entrypoint
= GetDefaultModuleEntrypoint ();
336 isDefaultEntryPoint
= true;
339 att
= moduleNode
.GetAttribute ( "baseaddress", false );
341 baseaddress
= att
->value
;
343 baseaddress
= GetDefaultModuleBaseaddress ();
345 mangledSymbols
= GetBooleanAttribute ( moduleNode
, "mangledsymbols" );
347 att
= moduleNode
.GetAttribute ( "underscoresymbols", false );
349 underscoreSymbols
= att
->value
== "true";
351 underscoreSymbols
= false;
353 isStartupLib
= GetBooleanAttribute ( moduleNode
, "isstartuplib" );
354 isCRT
= GetBooleanAttribute ( moduleNode
, "iscrt", GetDefaultModuleIsCRT () );
356 att
= moduleNode
.GetAttribute ( "crt", false );
361 if ( stricmp ( CRT
.c_str (), "auto" ) == 0 )
362 CRT
= GetDefaultModuleCRT ();
365 CRT
= GetDefaultModuleCRT ();
367 const char * crtAttr
= CRT
.c_str ();
368 if ( crtAttr
== NULL
|| stricmp ( crtAttr
, "none" ) == 0 )
370 else if ( stricmp ( crtAttr
, "libc" ) == 0 )
372 else if ( stricmp ( crtAttr
, "msvcrt" ) == 0 )
374 else if ( stricmp ( crtAttr
, "libcntpr" ) == 0 )
376 else if ( stricmp ( crtAttr
, "ntdll" ) == 0 )
378 else if ( stricmp ( crtAttr
, "static" ) == 0 )
380 else if ( stricmp ( crtAttr
, "dll" ) == 0 )
384 throw InvalidAttributeValueException (
387 std::string ( crtAttr
) );
390 if ( isCRT
&& dynamicCRT
)
392 throw XMLInvalidBuildFileException (
394 "C runtime module '%s' cannot be compiled for a dynamically-linked C runtime",
398 att
= moduleNode
.GetAttribute ( "prefix", false );
402 att
= moduleNode
.GetAttribute ( "installname", false );
405 const XMLAttribute
* installbase
= moduleNode
.GetAttribute ( "installbase", false );
406 install
= new FileLocation ( InstallDirectory
,
407 installbase
? installbase
->value
: "",
411 output
= new FileLocation ( GetTargetDirectoryTree (),
417 att
= moduleNode
.GetAttribute ( "output", false );
422 printf ( "%s: WARNING: 'installname' overrides 'output' also defined for this module.\n",
423 moduleNode
.location
.c_str() );
427 output
= new FileLocation ( GetTargetDirectoryTree (),
434 /* If no one has set the output file for this module set it automatically */
437 output
= new FileLocation ( GetTargetDirectoryTree (),
443 att
= moduleNode
.GetAttribute ( "allowwarnings", false );
446 att
= moduleNode
.GetAttribute ( "warnings", false );
449 printf ( "%s: WARNING: 'warnings' attribute of <module> is deprecated, use 'allowwarnings' instead\n",
450 moduleNode
.location
.c_str() );
454 allowWarnings
= att
->value
== "true";
455 else if ( project
.allowWarningsSet
)
456 allowWarnings
= project
.allowWarnings
;
458 allowWarnings
= false;
460 att
= moduleNode
.GetAttribute ( "aliasof", false );
461 if ( type
== Alias
&& att
!= NULL
)
462 aliasedModuleName
= att
->value
;
464 aliasedModuleName
= "";
466 if ( type
== BootProgram
)
468 att
= moduleNode
.GetAttribute ( "payload", true );
469 payload
= att
->value
;
472 if ( type
== BootProgram
|| type
== ElfExecutable
)
474 att
= moduleNode
.GetAttribute ( "buildtype", false );
477 buildtype
= att
->value
;
481 buildtype
= "BOOTPROG";
485 att
= moduleNode
.GetAttribute ( "description", false );
488 description
= project
.ResolveProperties(att
->value
);
493 att
= moduleNode
.GetAttribute ( "lcid", false );
494 if (type
== KeyboardLayout
&& att
!= NULL
)
499 att
= moduleNode
.GetAttribute ( "layoutid", false );
500 if (type
== KeyboardLayout
&& att
!= NULL
)
501 layoutId
= att
->value
;
505 att
= moduleNode
.GetAttribute ( "layoutnameresid", false );
506 if (type
== KeyboardLayout
&& att
!= NULL
)
507 layoutNameResId
= att
->value
;
509 layoutNameResId
= "";
511 SetImportLibrary ( NULL
);
517 for ( i
= 0; i
< invocations
.size(); i
++ )
518 delete invocations
[i
];
519 for ( i
= 0; i
< dependencies
.size(); i
++ )
520 delete dependencies
[i
];
521 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
522 delete compilerFlags
[i
];
523 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
524 delete linkerFlags
[i
];
525 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
526 delete stubbedComponents
[i
];
538 delete importLibrary
;
554 aliasedModuleName
= project
.ResolveProperties ( aliasedModuleName
);
555 if ( aliasedModuleName
== name
)
557 throw XMLInvalidBuildFileException (
559 "module '%s' cannot link against itself",
562 const Module
* m
= project
.LocateModule ( aliasedModuleName
);
565 throw XMLInvalidBuildFileException (
567 "module '%s' trying to alias non-existant module '%s'",
569 aliasedModuleName
.c_str() );
574 for ( i
= 0; i
< node
.subElements
.size(); i
++ )
576 ParseContext parseContext
;
577 ProcessXMLSubElement ( *node
.subElements
[i
], SourceDirectory
, output
->relative_path
, parseContext
);
579 for ( i
= 0; i
< invocations
.size(); i
++ )
580 invocations
[i
]->ProcessXML ();
581 for ( i
= 0; i
< dependencies
.size(); i
++ )
582 dependencies
[i
]->ProcessXML ();
583 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
584 compilerFlags
[i
]->ProcessXML();
585 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
586 linkerFlags
[i
]->ProcessXML();
587 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
588 stubbedComponents
[i
]->ProcessXML();
589 non_if_data
.ProcessXML();
591 linkerScript
->ProcessXML();
595 autoRegister
->ProcessXML();
599 Module::ProcessXMLSubElement ( const XMLElement
& e
,
600 DirectoryLocation directory
,
601 const string
& relative_path
,
602 ParseContext
& parseContext
)
604 CompilationUnit
* pOldCompilationUnit
= parseContext
.compilationUnit
;
605 bool subs_invalid
= false;
606 string
subpath ( relative_path
);
607 DirectoryLocation subdirectory
= SourceDirectory
;
608 if ( e
.name
== "file" && e
.value
.size () > 0 )
611 const XMLAttribute
* att
= e
.GetAttribute ( "first", false );
614 if ( !stricmp ( att
->value
.c_str(), "true" ) )
616 else if ( stricmp ( att
->value
.c_str(), "false" ) )
618 throw XMLInvalidBuildFileException (
620 "attribute 'first' of <file> element can only be 'true' or 'false'" );
623 string switches
= "";
624 att
= e
.GetAttribute ( "switches", false );
626 switches
= att
->value
;
629 // check for c++ file
630 string ext
= GetExtension ( e
.value
);
631 if ( !stricmp ( ext
.c_str(), ".cpp" ) )
633 else if ( !stricmp ( ext
.c_str(), ".cc" ) )
635 else if ( !stricmp ( ext
.c_str(), ".cxx" ) )
638 File
* pFile
= new File ( directory
,
644 if ( parseContext
.compilationUnit
)
645 parseContext
.compilationUnit
->AddFile ( pFile
);
648 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( pFile
);
649 string ext
= ToLower ( GetExtension ( e
.value
) );
652 // put .idl files at the start of the module
653 non_if_data
.compilationUnits
.insert (
654 non_if_data
.compilationUnits
.begin(),
657 else if ( ext
== ".asm" || ext
== ".s" )
659 // put .asm files at the end of the module
660 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
661 non_if_data
.asmFiles
++;
665 // put other files in the middle
666 non_if_data
.compilationUnits
.insert (
667 non_if_data
.compilationUnits
.end() - non_if_data
.asmFiles
,
671 non_if_data
.files
.push_back ( pFile
);
674 else if ( e
.name
== "library" && e
.value
.size () )
676 Library
* pLibrary
= new Library ( e
, *this, e
.value
);
677 non_if_data
.libraries
.push_back ( pLibrary
);
680 else if ( e
.name
== "directory" )
682 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
683 const XMLAttribute
* root
= e
.GetAttribute ( "root", false );
687 if ( root
->value
== "intermediate" )
688 subdirectory
= IntermediateDirectory
;
689 else if ( root
->value
== "output" )
690 subdirectory
= OutputDirectory
;
693 throw InvalidAttributeValueException (
699 subpath
= GetSubPath ( this->project
, e
.location
, relative_path
, att
->value
);
701 else if ( e
.name
== "include" )
703 Include
* include
= new Include ( project
, &e
, this );
704 non_if_data
.includes
.push_back ( include
);
707 else if ( e
.name
== "define" )
709 Define
* pDefine
= new Define ( project
, this, e
);
710 non_if_data
.defines
.push_back ( pDefine
);
713 else if ( e
.name
== "metadata" )
715 metadata
= new Metadata ( e
, *this );
716 subs_invalid
= false;
718 else if ( e
.name
== "invoke" )
720 invocations
.push_back ( new Invoke ( e
, *this ) );
721 subs_invalid
= false;
723 else if ( e
.name
== "dependency" )
725 dependencies
.push_back ( new Dependency ( e
, *this ) );
728 else if ( e
.name
== "bootsector" )
730 bootSector
= new Bootsector ( e
, this );
733 else if ( e
.name
== "importlibrary" )
737 throw XMLInvalidBuildFileException (
739 "Only one <importlibrary> is valid per module" );
741 SetImportLibrary ( new ImportLibrary ( project
, e
, this ) );
744 else if ( e
.name
== "if" || e
.name
== "ifnot" )
746 const XMLAttribute
* name
;
747 name
= e
.GetAttribute ( "property", true );
749 const Property
*property
= project
.LookupProperty( name
->value
);
750 const string
*PropertyValue
;
751 const string EmptyString
;
755 PropertyValue
= &property
->value
;
759 // Property does not exist, treat it as being empty
760 PropertyValue
= &EmptyString
;
763 const XMLAttribute
* value
;
764 value
= e
.GetAttribute ( "value", true );
767 bool negate
= ( e
.name
== "ifnot" );
768 bool equality
= ( *PropertyValue
== value
->value
);
769 if ( equality
== negate
)
771 // Failed, skip this element
772 if ( project
.configuration
.Verbose
)
773 printf("Skipping 'If' at %s\n", e
.location
.c_str () );
776 subs_invalid
= false;
778 else if ( e
.name
== "compilerflag" )
780 CompilerFlag
* pCompilerFlag
= new CompilerFlag ( project
, this, e
);
781 non_if_data
.compilerFlags
.push_back ( pCompilerFlag
);
784 else if ( e
.name
== "linkerflag" )
786 linkerFlags
.push_back ( new LinkerFlag ( project
, this, e
) );
789 else if ( e
.name
== "linkerscript" )
793 throw XMLInvalidBuildFileException (
795 "Only one <linkerscript> is valid per module" );
797 size_t pos
= e
.value
.find_last_of ( "/\\" );
798 if ( pos
== string::npos
)
800 linkerScript
= new LinkerScript (
801 e
, *this, new FileLocation ( SourceDirectory
, relative_path
, e
.value
, &e
) );
805 string dir
= e
.value
.substr ( 0, pos
);
806 string name
= e
.value
.substr ( pos
+ 1);
807 linkerScript
= new LinkerScript (
808 e
, *this, new FileLocation ( SourceDirectory
, relative_path
+ sSep
+ dir
, name
, &e
) );
812 else if ( e
.name
== "component" )
814 stubbedComponents
.push_back ( new StubbedComponent ( this, e
) );
815 subs_invalid
= false;
817 else if ( e
.name
== "property" )
819 throw XMLInvalidBuildFileException (
821 "<property> is not a valid sub-element of <module>" );
823 else if ( e
.name
== "bootstrap" )
825 bootstrap
= new Bootstrap ( project
, this, e
);
828 else if ( e
.name
== "pch" )
832 throw XMLInvalidBuildFileException (
834 "Only one <pch> is valid per module" );
836 size_t pos
= e
.value
.find_last_of ( "/\\" );
837 if ( pos
== string::npos
)
840 e
, *this, new FileLocation ( SourceDirectory
, relative_path
, e
.value
, &e
) );
844 string dir
= e
.value
.substr ( 0, pos
);
845 string name
= e
.value
.substr ( pos
+ 1);
847 e
, *this, new FileLocation ( SourceDirectory
, relative_path
+ sSep
+ dir
, name
, &e
) );
851 else if ( e
.name
== "compilationunit" )
853 if ( project
.configuration
.CompilationUnitsEnabled
)
855 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( &project
, this, &e
);
856 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
857 parseContext
.compilationUnit
= pCompilationUnit
;
859 subs_invalid
= false;
861 else if ( e
.name
== "autoregister" )
863 if ( autoRegister
!= NULL
)
865 throw XMLInvalidBuildFileException (
867 "there can be only one <%s> element for a module",
870 autoRegister
= new AutoRegister ( project
, this, e
);
873 if ( subs_invalid
&& e
.subElements
.size() > 0 )
875 throw XMLInvalidBuildFileException (
877 "<%s> cannot have sub-elements",
880 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
881 ProcessXMLSubElement ( *e
.subElements
[i
], subdirectory
, subpath
, parseContext
);
882 parseContext
.compilationUnit
= pOldCompilationUnit
;
886 Module::GetModuleType ( const string
& location
, const XMLAttribute
& attribute
)
888 if ( attribute
.value
== "buildtool" )
890 if ( attribute
.value
== "staticlibrary" )
891 return StaticLibrary
;
892 if ( attribute
.value
== "hoststaticlibrary" )
893 return HostStaticLibrary
;
894 if ( attribute
.value
== "objectlibrary" )
895 return ObjectLibrary
;
896 if ( attribute
.value
== "kernel" )
898 if ( attribute
.value
== "kernelmodedll" )
899 return KernelModeDLL
;
900 if ( attribute
.value
== "kernelmodedriver" )
901 return KernelModeDriver
;
902 if ( attribute
.value
== "nativedll" )
904 if ( attribute
.value
== "nativecui" )
906 if ( attribute
.value
== "keyboardlayout" )
907 return KeyboardLayout
;
908 if ( attribute
.value
== "win32dll" )
910 if ( attribute
.value
== "win32ocx" )
912 if ( attribute
.value
== "win32cui" )
914 if ( attribute
.value
== "win32gui" )
916 if ( attribute
.value
== "win32scr" )
918 if ( attribute
.value
== "bootloader" )
920 if ( attribute
.value
== "bootsector" )
922 if ( attribute
.value
== "bootprogram" )
924 if ( attribute
.value
== "iso" )
926 if ( attribute
.value
== "liveiso" )
928 if ( attribute
.value
== "isoregtest" )
930 if ( attribute
.value
== "liveisoregtest" )
931 return LiveIsoRegTest
;
932 if ( attribute
.value
== "test" )
934 if ( attribute
.value
== "rpcserver" )
936 if ( attribute
.value
== "rpcclient" )
938 if ( attribute
.value
== "rpcproxy" )
940 if ( attribute
.value
== "alias" )
942 if ( attribute
.value
== "idlheader" )
944 if ( attribute
.value
== "embeddedtypelib" )
945 return EmbeddedTypeLib
;
946 if ( attribute
.value
== "elfexecutable" )
947 return ElfExecutable
;
948 if ( attribute
.value
== "cabinet" )
950 if ( attribute
.value
== "messageheader" )
951 return MessageHeader
;
952 throw InvalidAttributeValueException ( location
,
958 Module::GetTargetDirectoryTree () const
968 case KernelModeDriver
:
984 return OutputDirectory
;
985 case EmbeddedTypeLib
:
987 case HostStaticLibrary
:
995 return IntermediateDirectory
;
999 throw InvalidOperationException ( __FILE__
,
1001 "Invalid module type %d.",
1006 Module::GetDefaultModuleExtension () const
1014 case HostStaticLibrary
:
1028 case KeyboardLayout
:
1033 case KernelModeDriver
:
1043 case LiveIsoRegTest
:
1056 case EmbeddedTypeLib
:
1061 throw InvalidOperationException ( __FILE__
,
1066 Module::GetDefaultModuleEntrypoint () const
1071 return "KiSystemStartup";
1072 case KeyboardLayout
:
1074 case KernelModeDriver
:
1075 if (Environment::GetArch() == "arm") return "DriverEntry";
1076 return "DriverEntry@8";
1078 if (Environment::GetArch() == "arm") return "DllMainCRTStartup";
1079 return "DllMainCRTStartup@12";
1081 if (Environment::GetArch() == "arm") return "NtProcessStartup";
1082 return "NtProcessStartup@4";
1085 if (Environment::GetArch() == "arm") return "DllMain";
1086 return "DllMain@12";
1090 return "wmainCRTStartup";
1092 return "mainCRTStartup";
1096 return "wWinMainCRTStartup";
1098 return "WinMainCRTStartup";
1101 case HostStaticLibrary
:
1108 case LiveIsoRegTest
:
1117 case EmbeddedTypeLib
:
1123 throw InvalidOperationException ( __FILE__
,
1128 Module::GetDefaultModuleBaseaddress () const
1133 return "0x80800000";
1136 return "0x10000000";
1141 return "0x00400000";
1144 return "0x00400000";
1145 case KeyboardLayout
:
1147 case KernelModeDriver
:
1148 return "0x00010000";
1153 case HostStaticLibrary
:
1160 case LiveIsoRegTest
:
1168 case EmbeddedTypeLib
:
1174 throw InvalidOperationException ( __FILE__
,
1179 Module::GetDefaultModuleCRT () const
1199 return "msvcrt"; // BUGBUG: not sure about this
1200 case KeyboardLayout
:
1203 case KernelModeDriver
:
1210 case HostStaticLibrary
:
1216 case LiveIsoRegTest
:
1224 case EmbeddedTypeLib
:
1229 throw InvalidOperationException ( __FILE__
,
1234 Module::GetDefaultModuleIsCRT () const
1236 return type
== Kernel
;
1240 Module::HasImportLibrary () const
1242 return importLibrary
!= NULL
&& type
!= StaticLibrary
&& type
!= HostStaticLibrary
;
1246 Module::IsDLL () const
1253 case KeyboardLayout
:
1256 case KernelModeDriver
:
1265 case HostStaticLibrary
:
1273 case LiveIsoRegTest
:
1280 case EmbeddedTypeLib
:
1287 throw InvalidOperationException ( __FILE__
,
1292 Module::GetPathWithPrefix ( const string
& prefix
) const
1294 return output
->relative_path
+ cSep
+ prefix
+ output
->name
;
1298 Module::GetPathToBaseDir () const
1300 string temp_path
= output
->relative_path
;
1301 string result
= "..\\";
1302 while(temp_path
.find ('\\') != string::npos
)
1304 temp_path
.erase (0, temp_path
.find('\\')+1);
1311 Module::GetInvocationTarget ( const int index
) const
1313 return ssprintf ( "%s_invoke_%d",
1319 Module::GetEntryPoint(bool leadingUnderscore
) const
1322 if (entrypoint
== "0" || entrypoint
== "0x0")
1324 if (leadingUnderscore
)
1327 result
+= entrypoint
;
1329 if (Environment::GetArch() == "amd64")
1331 size_t at_index
= result
.find_last_of( '@' );
1332 if ( at_index
!= result
.npos
)
1333 return result
.substr (0, at_index
);
1340 Module::HasFileWithExtension (
1341 const IfableData
& data
,
1342 const std::string
& extension
) const
1345 for ( i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1347 CompilationUnit
* compilationUnit
= data
.compilationUnits
[i
];
1348 if ( compilationUnit
->HasFileWithExtension ( extension
) )
1355 Module::InvokeModule () const
1357 for ( size_t i
= 0; i
< invocations
.size (); i
++ )
1359 Invoke
& invoke
= *invocations
[i
];
1360 string command
= FixSeparatorForSystemCommand(invoke
.invokeModule
->output
->relative_path
+ "/" + invoke
.invokeModule
->output
->name
) + " " + invoke
.GetParameters ();
1361 printf ( "Executing '%s'\n\n", command
.c_str () );
1362 int exitcode
= system ( command
.c_str () );
1363 if ( exitcode
!= 0 )
1364 throw InvocationFailedException ( command
,
1371 Module::SetImportLibrary ( ImportLibrary
* importLibrary
)
1373 this->importLibrary
= importLibrary
;
1374 dependency
= new FileLocation ( HasImportLibrary () ? IntermediateDirectory
: output
->directory
,
1375 output
->relative_path
,
1376 HasImportLibrary () ? "lib" + name
+ ".a" : output
->name
);
1380 Module::GetDllName () const
1382 if ( importLibrary
&& !importLibrary
->dllname
.empty() )
1383 return importLibrary
->dllname
;
1385 return output
->name
;
1387 throw new InvalidOperationException ( __FILE__
, __LINE__
, "Module %s has no dllname." );
1390 File::File ( DirectoryLocation directory
,
1391 const string
& relative_path
,
1394 const string
& _switches
,
1395 bool _isPreCompiledHeader
)
1396 : file ( directory
, relative_path
, name
),
1398 switches(_switches
),
1399 isPreCompiledHeader(_isPreCompiledHeader
)
1410 std::string
File::GetFullPath () const
1412 string
directory ( "" );
1413 switch ( file
.directory
)
1415 case SourceDirectory
:
1417 case IntermediateDirectory
:
1418 directory
= Environment::GetIntermediatePath () + sSep
;
1421 throw InvalidOperationException ( __FILE__
,
1423 "Invalid directory %d.",
1427 if ( file
.relative_path
.length () > 0 )
1428 directory
+= file
.relative_path
+ sSep
;
1431 return directory
+ file
.name
;
1435 Library::Library ( const XMLElement
& _node
,
1436 const Module
& _module
,
1437 const string
& _name
)
1441 importedModule(_module
.project
.LocateModule(_name
))
1443 if ( module
.name
== name
)
1445 throw XMLInvalidBuildFileException (
1447 "module '%s' cannot link against itself",
1450 if ( !importedModule
)
1452 throw XMLInvalidBuildFileException (
1454 "module '%s' trying to import non-existant module '%s'",
1455 module
.name
.c_str(),
1460 Library::Library ( const Module
& _module
,
1461 const string
& _name
)
1465 importedModule(_module
.project
.LocateModule(_name
))
1467 if ( !importedModule
)
1469 throw XMLInvalidBuildFileException (
1471 "module '%s' trying to import non-existant module '%s'",
1472 module
.name
.c_str(),
1478 Library::ProcessXML()
1480 if ( node
&& !module
.project
.LocateModule ( name
) )
1482 throw XMLInvalidBuildFileException (
1484 "module '%s' is trying to link against non-existant module '%s'",
1485 module
.name
.c_str(),
1491 Invoke::Invoke ( const XMLElement
& _node
,
1492 const Module
& _module
)
1499 Invoke::ProcessXML()
1501 const XMLAttribute
* att
= node
.GetAttribute ( "module", false );
1503 invokeModule
= &module
;
1506 invokeModule
= module
.project
.LocateModule ( att
->value
);
1507 if ( invokeModule
== NULL
)
1509 throw XMLInvalidBuildFileException (
1511 "module '%s' is trying to invoke non-existant module '%s'",
1512 module
.name
.c_str(),
1513 att
->value
.c_str() );
1517 for ( size_t i
= 0; i
< node
.subElements
.size (); i
++ )
1518 ProcessXMLSubElement ( *node
.subElements
[i
] );
1522 Invoke::ProcessXMLSubElement ( const XMLElement
& e
)
1524 bool subs_invalid
= false;
1525 if ( e
.name
== "input" )
1527 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1528 ProcessXMLSubElementInput ( *e
.subElements
[i
] );
1530 else if ( e
.name
== "output" )
1532 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1533 ProcessXMLSubElementOutput ( *e
.subElements
[i
] );
1535 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1537 throw XMLInvalidBuildFileException (
1539 "<%s> cannot have sub-elements",
1545 Invoke::ProcessXMLSubElementInput ( const XMLElement
& e
)
1547 bool subs_invalid
= false;
1548 if ( e
.name
== "inputfile" && e
.value
.size () > 0 )
1550 input
.push_back ( new InvokeFile (
1551 e
, FixSeparator ( module
.output
->relative_path
+ cSep
+ e
.value
) ) );
1552 subs_invalid
= true;
1554 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1556 throw XMLInvalidBuildFileException (
1558 "<%s> cannot have sub-elements",
1564 Invoke::ProcessXMLSubElementOutput ( const XMLElement
& e
)
1566 bool subs_invalid
= false;
1567 if ( e
.name
== "outputfile" && e
.value
.size () > 0 )
1569 output
.push_back ( new InvokeFile (
1570 e
, FixSeparator ( module
.output
->relative_path
+ cSep
+ e
.value
) ) );
1571 subs_invalid
= true;
1573 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1575 throw XMLInvalidBuildFileException (
1577 "<%s> cannot have sub-elements",
1583 Invoke::GetTargets ( string_list
& targets
) const
1585 for ( size_t i
= 0; i
< output
.size (); i
++ )
1587 InvokeFile
& file
= *output
[i
];
1588 targets
.push_back ( NormalizeFilename ( file
.name
) );
1593 Invoke::GetParameters () const
1595 string
parameters ( "" );
1597 for ( i
= 0; i
< output
.size (); i
++ )
1599 if ( parameters
.length () > 0)
1601 InvokeFile
& invokeFile
= *output
[i
];
1602 if ( invokeFile
.switches
.length () > 0 )
1604 parameters
+= invokeFile
.switches
+ " ";
1606 parameters
+= invokeFile
.name
;
1609 for ( i
= 0; i
< input
.size (); i
++ )
1611 if ( parameters
.length () > 0 )
1613 InvokeFile
& invokeFile
= *input
[i
];
1614 if ( invokeFile
.switches
.length () > 0 )
1616 parameters
+= invokeFile
.switches
;
1619 parameters
+= invokeFile
.name
;
1626 InvokeFile::InvokeFile ( const XMLElement
& _node
,
1627 const string
& _name
)
1631 const XMLAttribute
* att
= _node
.GetAttribute ( "switches", false );
1633 switches
= att
->value
;
1639 InvokeFile::ProcessXML()
1644 Dependency::Dependency ( const XMLElement
& _node
,
1645 const Module
& _module
)
1648 dependencyModule (NULL
)
1653 Dependency::ProcessXML()
1655 dependencyModule
= module
.project
.LocateModule ( node
.value
);
1656 if ( dependencyModule
== NULL
)
1658 throw XMLInvalidBuildFileException (
1660 "module '%s' depend on non-existant module '%s'",
1661 module
.name
.c_str(),
1662 node
.value
.c_str() );
1666 Bootsector::Bootsector ( const XMLElement
& _node
,
1667 const Module
* _module
)
1670 bootSectorModule (NULL
)
1672 if ( !IsSupportedModuleType ( module
->type
) )
1674 throw XMLInvalidBuildFileException (
1676 "<bootsector> is not applicable for this module type." );
1679 bootSectorModule
= module
->project
.LocateModule ( node
.value
);
1680 if ( bootSectorModule
== NULL
)
1682 throw XMLInvalidBuildFileException (
1684 "module '%s' depend on non-existant module '%s'",
1685 module
->name
.c_str(),
1686 node
.value
.c_str() );
1689 if (bootSectorModule
->type
!= BootSector
)
1691 throw XMLInvalidBuildFileException (
1693 "module '%s' is referencing non BootSector module '%s'",
1694 module
->name
.c_str(),
1695 node
.value
.c_str() );
1700 Bootsector::ProcessXML()
1705 Bootsector::IsSupportedModuleType ( ModuleType type
)
1709 type
== IsoRegTest
||
1710 type
== LiveIsoRegTest
)
1718 Metadata::Metadata ( const XMLElement
& _node
,
1719 const Module
& _module
)
1723 /* The module name */
1724 const XMLAttribute
* att
= _node
.GetAttribute ( "name", false );
1730 /* The module description */
1731 att
= _node
.GetAttribute ( "description", false );
1733 description
= att
->value
;
1737 /* The module version */
1738 att
= _node
.GetAttribute ( "version", false );
1740 version
= att
->value
;
1744 /* The module copyright */
1745 att
= _node
.GetAttribute ( "copyright", false );
1747 copyright
= att
->value
;
1751 att
= _node
.GetAttribute ( "url", false );
1757 /* When was this module updated */
1758 att
= _node
.GetAttribute ( "date", false );
1764 /* When was this module updated */
1765 att
= _node
.GetAttribute ( "owner", false );
1773 ImportLibrary::~ImportLibrary ()
1779 ImportLibrary::ImportLibrary ( const Project
& project
,
1780 const XMLElement
& node
,
1781 const Module
* module
)
1782 : XmlNode ( project
, node
),
1785 DirectoryLocation directory
= SourceDirectory
;
1786 const Module
* base
= module
;
1787 const XMLAttribute
* dllname
= node
.GetAttribute ( "dllname", false );
1788 const XMLAttribute
* definition
= node
.GetAttribute ( "definition", true );
1789 assert ( definition
);
1791 string relative_path
;
1792 const XMLAttribute
* att
= node
.GetAttribute ( "base", false );
1795 base
= project
.LocateModule ( att
->value
);
1797 throw XMLInvalidBuildFileException (
1799 "<importlibrary> attribute 'base' references non-existant module '%s'",
1800 att
->value
.c_str() );
1806 relative_path
= base
->output
->relative_path
;
1807 if ( node
.value
.length () > 0 && node
.value
!= "." )
1808 relative_path
+= sSep
+ node
.value
;
1811 relative_path
= node
.value
;
1813 att
= node
.GetAttribute ( "root", false );
1816 if ( att
->value
== "intermediate" )
1817 directory
= IntermediateDirectory
;
1819 throw InvalidAttributeValueException ( node
.location
,
1825 this->dllname
= dllname
->value
;
1826 else if ( module
->type
== StaticLibrary
|| module
->type
== HostStaticLibrary
)
1827 throw XMLInvalidBuildFileException (
1829 "<importlibrary> dllname attribute required." );
1831 size_t index
= definition
->value
.find_last_of ( "/\\" );
1832 if ( index
== string::npos
)
1834 source
= new FileLocation ( directory
,
1835 base
->output
->relative_path
,
1841 string dir
= definition
->value
.substr ( 0, index
);
1842 string name
= definition
->value
.substr ( index
+ 1);
1843 source
= new FileLocation ( directory
,
1844 NormalizeFilename ( base
->output
->relative_path
+ sSep
+ dir
),
1851 Property::Property ( const XMLElement
& node_
,
1852 const Project
& project_
,
1853 const Module
* module_
)
1854 : project(project_
), module(module_
)
1856 const XMLAttribute
* att
;
1858 att
= node_
.GetAttribute ( "name", true );
1860 name
= project
.ResolveProperties ( att
->value
);
1862 att
= node_
.GetAttribute ( "value", true );
1866 att
= node_
.GetAttribute ( "internal", false );
1869 const char* p
= att
->value
.c_str();
1870 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
1872 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
1876 throw InvalidAttributeValueException (
1886 Property::Property ( const Project
& project_
,
1887 const Module
* module_
,
1888 const std::string
& name_
,
1889 const std::string
& value_
)
1890 : project(project_
), module(module_
), name(name_
), value(value_
)
1895 Property::ProcessXML()
1901 const XMLElement
& node_
,
1902 const Module
& module_
,
1903 const FileLocation
*file_
)
1904 : node(node_
), module(module_
), file(file_
)
1914 PchFile::ProcessXML()