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" || e
.name
== "redefine" )
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
== "idlinterface" )
946 if ( attribute
.value
== "embeddedtypelib" )
947 return EmbeddedTypeLib
;
948 if ( attribute
.value
== "elfexecutable" )
949 return ElfExecutable
;
950 if ( attribute
.value
== "cabinet" )
952 if ( attribute
.value
== "messageheader" )
953 return MessageHeader
;
954 throw InvalidAttributeValueException ( location
,
960 Module::GetTargetDirectoryTree () const
970 case KernelModeDriver
:
986 return OutputDirectory
;
987 case EmbeddedTypeLib
:
989 case HostStaticLibrary
:
998 return IntermediateDirectory
;
1002 throw InvalidOperationException ( __FILE__
,
1004 "Invalid module type %d.",
1009 Module::GetDefaultModuleExtension () const
1017 case HostStaticLibrary
:
1031 case KeyboardLayout
:
1036 case KernelModeDriver
:
1046 case LiveIsoRegTest
:
1060 case EmbeddedTypeLib
:
1065 throw InvalidOperationException ( __FILE__
,
1070 Module::GetDefaultModuleEntrypoint () const
1075 return "KiSystemStartup";
1076 case KeyboardLayout
:
1078 case KernelModeDriver
:
1079 if (Environment::GetArch() == "arm") return "DriverEntry";
1080 return "DriverEntry@8";
1082 if (Environment::GetArch() == "arm") return "DllMainCRTStartup";
1083 return "DllMainCRTStartup@12";
1085 if (Environment::GetArch() == "arm") return "NtProcessStartup";
1086 return "NtProcessStartup@4";
1089 if (Environment::GetArch() == "arm") return "DllMain";
1090 return "DllMain@12";
1093 return "mainCRTStartup";
1096 return "WinMainCRTStartup";
1099 case HostStaticLibrary
:
1106 case LiveIsoRegTest
:
1116 case EmbeddedTypeLib
:
1122 throw InvalidOperationException ( __FILE__
,
1127 Module::GetDefaultModuleBaseaddress () const
1132 return "0x80800000";
1135 return "0x10000000";
1140 return "0x00400000";
1143 return "0x00400000";
1144 case KeyboardLayout
:
1146 case KernelModeDriver
:
1147 return "0x00010000";
1152 case HostStaticLibrary
:
1159 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
:
1225 case EmbeddedTypeLib
:
1230 throw InvalidOperationException ( __FILE__
,
1235 Module::GetDefaultModuleIsCRT () const
1237 return type
== Kernel
;
1241 Module::HasImportLibrary () const
1243 return importLibrary
!= NULL
&& type
!= StaticLibrary
&& type
!= HostStaticLibrary
;
1247 Module::IsDLL () const
1254 case KeyboardLayout
:
1257 case KernelModeDriver
:
1266 case HostStaticLibrary
:
1274 case LiveIsoRegTest
:
1282 case EmbeddedTypeLib
:
1289 throw InvalidOperationException ( __FILE__
,
1294 Module::GetPathWithPrefix ( const string
& prefix
) const
1296 return output
->relative_path
+ cSep
+ prefix
+ output
->name
;
1300 Module::GetPathToBaseDir () const
1302 string temp_path
= output
->relative_path
;
1303 string result
= "..\\";
1304 while(temp_path
.find ('\\') != string::npos
)
1306 temp_path
.erase (0, temp_path
.find('\\')+1);
1313 Module::GetInvocationTarget ( const int index
) const
1315 return ssprintf ( "%s_invoke_%d",
1321 Module::GetEntryPoint(bool leadingUnderscore
) const
1324 if (entrypoint
== "0" || entrypoint
== "0x0")
1326 if (leadingUnderscore
)
1329 result
+= entrypoint
;
1331 if (Environment::GetArch() == "amd64")
1333 size_t at_index
= result
.find_last_of( '@' );
1334 if ( at_index
!= result
.npos
)
1335 return result
.substr (0, at_index
);
1342 Module::HasFileWithExtension (
1343 const IfableData
& data
,
1344 const std::string
& extension
) const
1347 for ( i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1349 CompilationUnit
* compilationUnit
= data
.compilationUnits
[i
];
1350 if ( compilationUnit
->HasFileWithExtension ( extension
) )
1357 Module::InvokeModule () const
1359 for ( size_t i
= 0; i
< invocations
.size (); i
++ )
1361 Invoke
& invoke
= *invocations
[i
];
1362 string command
= FixSeparatorForSystemCommand(invoke
.invokeModule
->output
->relative_path
+ "/" + invoke
.invokeModule
->output
->name
) + " " + invoke
.GetParameters ();
1363 printf ( "Executing '%s'\n\n", command
.c_str () );
1364 int exitcode
= system ( command
.c_str () );
1365 if ( exitcode
!= 0 )
1366 throw InvocationFailedException ( command
,
1373 Module::SetImportLibrary ( ImportLibrary
* importLibrary
)
1375 this->importLibrary
= importLibrary
;
1376 dependency
= new FileLocation ( HasImportLibrary () ? IntermediateDirectory
: output
->directory
,
1377 output
->relative_path
,
1378 HasImportLibrary () ? "lib" + name
+ ".a" : output
->name
);
1382 Module::GetDllName () const
1384 if ( importLibrary
&& !importLibrary
->dllname
.empty() )
1385 return importLibrary
->dllname
;
1387 return output
->name
;
1389 throw new InvalidOperationException ( __FILE__
, __LINE__
, "Module %s has no dllname." );
1392 File::File ( DirectoryLocation directory
,
1393 const string
& relative_path
,
1396 const string
& _switches
,
1397 bool _isPreCompiledHeader
)
1398 : file ( directory
, relative_path
, name
),
1400 switches(_switches
),
1401 isPreCompiledHeader(_isPreCompiledHeader
)
1412 std::string
File::GetFullPath () const
1414 string
directory ( "" );
1415 switch ( file
.directory
)
1417 case SourceDirectory
:
1419 case IntermediateDirectory
:
1420 directory
= Environment::GetIntermediatePath () + sSep
;
1423 throw InvalidOperationException ( __FILE__
,
1425 "Invalid directory %d.",
1429 if ( file
.relative_path
.length () > 0 )
1430 directory
+= file
.relative_path
+ sSep
;
1433 return directory
+ file
.name
;
1437 Library::Library ( const XMLElement
& _node
,
1438 const Module
& _module
,
1439 const string
& _name
)
1443 importedModule(_module
.project
.LocateModule(_name
))
1445 if ( module
.name
== name
)
1447 throw XMLInvalidBuildFileException (
1449 "module '%s' cannot link against itself",
1452 if ( !importedModule
)
1454 throw XMLInvalidBuildFileException (
1456 "module '%s' trying to import non-existant module '%s'",
1457 module
.name
.c_str(),
1462 Library::Library ( const Module
& _module
,
1463 const string
& _name
)
1467 importedModule(_module
.project
.LocateModule(_name
))
1469 if ( !importedModule
)
1471 throw XMLInvalidBuildFileException (
1473 "module '%s' trying to import non-existant module '%s'",
1474 module
.name
.c_str(),
1480 Library::ProcessXML()
1482 if ( node
&& !module
.project
.LocateModule ( name
) )
1484 throw XMLInvalidBuildFileException (
1486 "module '%s' is trying to link against non-existant module '%s'",
1487 module
.name
.c_str(),
1493 Invoke::Invoke ( const XMLElement
& _node
,
1494 const Module
& _module
)
1501 Invoke::ProcessXML()
1503 const XMLAttribute
* att
= node
.GetAttribute ( "module", false );
1505 invokeModule
= &module
;
1508 invokeModule
= module
.project
.LocateModule ( att
->value
);
1509 if ( invokeModule
== NULL
)
1511 throw XMLInvalidBuildFileException (
1513 "module '%s' is trying to invoke non-existant module '%s'",
1514 module
.name
.c_str(),
1515 att
->value
.c_str() );
1519 for ( size_t i
= 0; i
< node
.subElements
.size (); i
++ )
1520 ProcessXMLSubElement ( *node
.subElements
[i
] );
1524 Invoke::ProcessXMLSubElement ( const XMLElement
& e
)
1526 bool subs_invalid
= false;
1527 if ( e
.name
== "input" )
1529 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1530 ProcessXMLSubElementInput ( *e
.subElements
[i
] );
1532 else if ( e
.name
== "output" )
1534 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1535 ProcessXMLSubElementOutput ( *e
.subElements
[i
] );
1537 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1539 throw XMLInvalidBuildFileException (
1541 "<%s> cannot have sub-elements",
1547 Invoke::ProcessXMLSubElementInput ( const XMLElement
& e
)
1549 bool subs_invalid
= false;
1550 if ( e
.name
== "inputfile" && e
.value
.size () > 0 )
1552 input
.push_back ( new InvokeFile (
1553 e
, FixSeparator ( module
.output
->relative_path
+ cSep
+ e
.value
) ) );
1554 subs_invalid
= true;
1556 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1558 throw XMLInvalidBuildFileException (
1560 "<%s> cannot have sub-elements",
1566 Invoke::ProcessXMLSubElementOutput ( const XMLElement
& e
)
1568 bool subs_invalid
= false;
1569 if ( e
.name
== "outputfile" && e
.value
.size () > 0 )
1571 output
.push_back ( new InvokeFile (
1572 e
, FixSeparator ( module
.output
->relative_path
+ cSep
+ e
.value
) ) );
1573 subs_invalid
= true;
1575 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1577 throw XMLInvalidBuildFileException (
1579 "<%s> cannot have sub-elements",
1585 Invoke::GetTargets ( string_list
& targets
) const
1587 for ( size_t i
= 0; i
< output
.size (); i
++ )
1589 InvokeFile
& file
= *output
[i
];
1590 targets
.push_back ( NormalizeFilename ( file
.name
) );
1595 Invoke::GetParameters () const
1597 string
parameters ( "" );
1599 for ( i
= 0; i
< output
.size (); i
++ )
1601 if ( parameters
.length () > 0)
1603 InvokeFile
& invokeFile
= *output
[i
];
1604 if ( invokeFile
.switches
.length () > 0 )
1606 parameters
+= invokeFile
.switches
+ " ";
1608 parameters
+= invokeFile
.name
;
1611 for ( i
= 0; i
< input
.size (); i
++ )
1613 if ( parameters
.length () > 0 )
1615 InvokeFile
& invokeFile
= *input
[i
];
1616 if ( invokeFile
.switches
.length () > 0 )
1618 parameters
+= invokeFile
.switches
;
1621 parameters
+= invokeFile
.name
;
1628 InvokeFile::InvokeFile ( const XMLElement
& _node
,
1629 const string
& _name
)
1633 const XMLAttribute
* att
= _node
.GetAttribute ( "switches", false );
1635 switches
= att
->value
;
1641 InvokeFile::ProcessXML()
1646 Dependency::Dependency ( const XMLElement
& _node
,
1647 const Module
& _module
)
1650 dependencyModule (NULL
)
1655 Dependency::ProcessXML()
1657 dependencyModule
= module
.project
.LocateModule ( node
.value
);
1658 if ( dependencyModule
== NULL
)
1660 throw XMLInvalidBuildFileException (
1662 "module '%s' depend on non-existant module '%s'",
1663 module
.name
.c_str(),
1664 node
.value
.c_str() );
1668 Bootsector::Bootsector ( const XMLElement
& _node
,
1669 const Module
* _module
)
1672 bootSectorModule (NULL
)
1674 if ( !IsSupportedModuleType ( module
->type
) )
1676 throw XMLInvalidBuildFileException (
1678 "<bootsector> is not applicable for this module type." );
1681 bootSectorModule
= module
->project
.LocateModule ( node
.value
);
1682 if ( bootSectorModule
== NULL
)
1684 throw XMLInvalidBuildFileException (
1686 "module '%s' depend on non-existant module '%s'",
1687 module
->name
.c_str(),
1688 node
.value
.c_str() );
1691 if (bootSectorModule
->type
!= BootSector
)
1693 throw XMLInvalidBuildFileException (
1695 "module '%s' is referencing non BootSector module '%s'",
1696 module
->name
.c_str(),
1697 node
.value
.c_str() );
1702 Bootsector::ProcessXML()
1707 Bootsector::IsSupportedModuleType ( ModuleType type
)
1711 type
== IsoRegTest
||
1712 type
== LiveIsoRegTest
)
1720 Metadata::Metadata ( const XMLElement
& _node
,
1721 const Module
& _module
)
1725 /* The module name */
1726 const XMLAttribute
* att
= _node
.GetAttribute ( "name", false );
1732 /* The module description */
1733 att
= _node
.GetAttribute ( "description", false );
1735 description
= att
->value
;
1739 /* The module version */
1740 att
= _node
.GetAttribute ( "version", false );
1742 version
= att
->value
;
1746 /* The module copyright */
1747 att
= _node
.GetAttribute ( "copyright", false );
1749 copyright
= att
->value
;
1753 att
= _node
.GetAttribute ( "url", false );
1759 /* When was this module updated */
1760 att
= _node
.GetAttribute ( "date", false );
1766 /* When was this module updated */
1767 att
= _node
.GetAttribute ( "owner", false );
1775 ImportLibrary::~ImportLibrary ()
1781 ImportLibrary::ImportLibrary ( const Project
& project
,
1782 const XMLElement
& node
,
1783 const Module
* module
)
1784 : XmlNode ( project
, node
),
1787 DirectoryLocation directory
= SourceDirectory
;
1788 const Module
* base
= module
;
1789 const XMLAttribute
* dllname
= node
.GetAttribute ( "dllname", false );
1790 const XMLAttribute
* definition
= node
.GetAttribute ( "definition", true );
1791 assert ( definition
);
1793 string relative_path
;
1794 const XMLAttribute
* att
= node
.GetAttribute ( "base", false );
1797 base
= project
.LocateModule ( att
->value
);
1799 throw XMLInvalidBuildFileException (
1801 "<importlibrary> attribute 'base' references non-existant module '%s'",
1802 att
->value
.c_str() );
1808 relative_path
= base
->output
->relative_path
;
1809 if ( node
.value
.length () > 0 && node
.value
!= "." )
1810 relative_path
+= sSep
+ node
.value
;
1813 relative_path
= node
.value
;
1815 att
= node
.GetAttribute ( "root", false );
1818 if ( att
->value
== "intermediate" )
1819 directory
= IntermediateDirectory
;
1821 throw InvalidAttributeValueException ( node
.location
,
1827 this->dllname
= dllname
->value
;
1828 else if ( module
->type
== StaticLibrary
|| module
->type
== HostStaticLibrary
)
1829 throw XMLInvalidBuildFileException (
1831 "<importlibrary> dllname attribute required." );
1833 size_t index
= definition
->value
.find_last_of ( "/\\" );
1834 if ( index
== string::npos
)
1836 source
= new FileLocation ( directory
,
1837 base
->output
->relative_path
,
1843 string dir
= definition
->value
.substr ( 0, index
);
1844 string name
= definition
->value
.substr ( index
+ 1);
1845 source
= new FileLocation ( directory
,
1846 NormalizeFilename ( base
->output
->relative_path
+ sSep
+ dir
),
1853 Property::Property ( const XMLElement
& node_
,
1854 const Project
& project_
,
1855 const Module
* module_
)
1856 : project(project_
), module(module_
)
1858 const XMLAttribute
* att
;
1860 att
= node_
.GetAttribute ( "name", true );
1862 name
= project
.ResolveProperties ( att
->value
);
1864 att
= node_
.GetAttribute ( "value", true );
1868 att
= node_
.GetAttribute ( "internal", false );
1871 const char* p
= att
->value
.c_str();
1872 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
1874 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
1878 throw InvalidAttributeValueException (
1888 Property::Property ( const Project
& project_
,
1889 const Module
* module_
,
1890 const std::string
& name_
,
1891 const std::string
& value_
)
1892 : project(project_
), module(module_
), name(name_
), value(value_
)
1897 Property::ProcessXML()
1903 const XMLElement
& node_
,
1904 const Module
& module_
,
1905 const FileLocation
*file_
)
1906 : node(node_
), module(module_
), file(file_
)
1916 PchFile::ProcessXML()