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
),
263 delayImportLibrary (NULL
),
274 if ( node
.name
!= "module" )
275 throw InvalidOperationException ( __FILE__
,
277 "Module created with non-<module> node" );
279 xmlbuildFile
= FixSeparator ( Path::RelativeFromWorkingDirectory ( moduleNode
.xmlFile
->filename () ) );
281 const XMLAttribute
* att
= moduleNode
.GetAttribute ( "name", true );
287 att
= moduleNode
.GetAttribute ( "if", false );
289 enabled
= GetBooleanValue ( project
.ResolveProperties ( att
->value
) );
291 att
= moduleNode
.GetAttribute ( "ifnot", false );
293 enabled
= !GetBooleanValue ( project
.ResolveProperties ( att
->value
) );
295 if ( !enabled
&& project
.configuration
.Verbose
)
296 printf("Module '%s' has been disabled.\n", name
.c_str () );
298 att
= moduleNode
.GetAttribute ( "type", true );
300 type
= GetModuleType ( node
.location
, *att
);
302 att
= moduleNode
.GetAttribute ( "extension", false );
304 extension
= att
->value
;
306 extension
= GetDefaultModuleExtension ();
308 isUnicode
= GetBooleanAttribute ( moduleNode
, "unicode" );
312 // Always define UNICODE and _UNICODE
313 Define
* pDefine
= new Define ( project
, this, "UNICODE" );
314 non_if_data
.defines
.push_back ( pDefine
);
316 pDefine
= new Define ( project
, this, "_UNICODE" );
317 non_if_data
.defines
.push_back ( pDefine
);
320 att
= moduleNode
.GetAttribute ( "entrypoint", false );
323 if ( att
->value
== "" )
325 throw InvalidAttributeValueException (
331 entrypoint
= att
->value
;
332 isDefaultEntryPoint
= false;
336 entrypoint
= GetDefaultModuleEntrypoint ();
337 isDefaultEntryPoint
= true;
340 att
= moduleNode
.GetAttribute ( "baseaddress", false );
342 baseaddress
= att
->value
;
344 baseaddress
= GetDefaultModuleBaseaddress ();
346 mangledSymbols
= GetBooleanAttribute ( moduleNode
, "mangledsymbols" );
348 att
= moduleNode
.GetAttribute ( "underscoresymbols", false );
350 underscoreSymbols
= att
->value
== "true";
352 underscoreSymbols
= false;
354 isStartupLib
= GetBooleanAttribute ( moduleNode
, "isstartuplib" );
355 isCRT
= GetBooleanAttribute ( moduleNode
, "iscrt", GetDefaultModuleIsCRT () );
357 att
= moduleNode
.GetAttribute ( "crt", false );
362 if ( stricmp ( CRT
.c_str (), "auto" ) == 0 )
363 CRT
= GetDefaultModuleCRT ();
366 CRT
= GetDefaultModuleCRT ();
368 const char * crtAttr
= CRT
.c_str ();
369 if ( crtAttr
== NULL
|| stricmp ( crtAttr
, "none" ) == 0 )
371 else if ( stricmp ( crtAttr
, "libc" ) == 0 )
373 else if ( stricmp ( crtAttr
, "msvcrt" ) == 0 )
375 else if ( stricmp ( crtAttr
, "libcntpr" ) == 0 )
377 else if ( stricmp ( crtAttr
, "ntdll" ) == 0 )
379 else if ( stricmp ( crtAttr
, "static" ) == 0 )
381 else if ( stricmp ( crtAttr
, "dll" ) == 0 )
385 throw InvalidAttributeValueException (
388 std::string ( crtAttr
) );
391 if ( isCRT
&& dynamicCRT
)
393 throw XMLInvalidBuildFileException (
395 "C runtime module '%s' cannot be compiled for a dynamically-linked C runtime",
399 att
= moduleNode
.GetAttribute ( "prefix", false );
403 att
= moduleNode
.GetAttribute ( "installname", false );
406 const XMLAttribute
* installbase
= moduleNode
.GetAttribute ( "installbase", false );
407 install
= new FileLocation ( InstallDirectory
,
408 installbase
? installbase
->value
: "",
412 output
= new FileLocation ( GetTargetDirectoryTree (),
418 att
= moduleNode
.GetAttribute ( "output", false );
423 printf ( "%s: WARNING: 'installname' overrides 'output' also defined for this module.\n",
424 moduleNode
.location
.c_str() );
428 output
= new FileLocation ( GetTargetDirectoryTree (),
435 /* If no one has set the output file for this module set it automatically */
438 output
= new FileLocation ( GetTargetDirectoryTree (),
444 att
= moduleNode
.GetAttribute ( "allowwarnings", false );
447 att
= moduleNode
.GetAttribute ( "warnings", false );
450 printf ( "%s: WARNING: 'warnings' attribute of <module> is deprecated, use 'allowwarnings' instead\n",
451 moduleNode
.location
.c_str() );
455 allowWarnings
= att
->value
== "true";
456 else if ( project
.allowWarningsSet
)
457 allowWarnings
= project
.allowWarnings
;
459 allowWarnings
= false;
461 att
= moduleNode
.GetAttribute ( "aliasof", false );
462 if ( type
== Alias
&& att
!= NULL
)
463 aliasedModuleName
= att
->value
;
465 aliasedModuleName
= "";
467 if ( type
== BootProgram
)
469 att
= moduleNode
.GetAttribute ( "payload", true );
470 payload
= att
->value
;
473 if ( type
== BootProgram
|| type
== ElfExecutable
)
475 att
= moduleNode
.GetAttribute ( "buildtype", false );
478 buildtype
= att
->value
;
482 buildtype
= "BOOTPROG";
486 att
= moduleNode
.GetAttribute ( "description", false );
489 description
= project
.ResolveProperties(att
->value
);
494 att
= moduleNode
.GetAttribute ( "lcid", false );
495 if (type
== KeyboardLayout
&& att
!= NULL
)
500 att
= moduleNode
.GetAttribute ( "layoutid", false );
501 if (type
== KeyboardLayout
&& att
!= NULL
)
502 layoutId
= att
->value
;
506 att
= moduleNode
.GetAttribute ( "layoutnameresid", false );
507 if (type
== KeyboardLayout
&& att
!= NULL
)
508 layoutNameResId
= att
->value
;
510 layoutNameResId
= "";
512 SetImportLibrary ( NULL
);
518 for ( i
= 0; i
< invocations
.size(); i
++ )
519 delete invocations
[i
];
520 for ( i
= 0; i
< dependencies
.size(); i
++ )
521 delete dependencies
[i
];
522 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
523 delete compilerFlags
[i
];
524 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
525 delete linkerFlags
[i
];
526 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
527 delete stubbedComponents
[i
];
539 delete importLibrary
;
555 aliasedModuleName
= project
.ResolveProperties ( aliasedModuleName
);
556 if ( aliasedModuleName
== name
)
558 throw XMLInvalidBuildFileException (
560 "module '%s' cannot link against itself",
563 const Module
* m
= project
.LocateModule ( aliasedModuleName
);
566 throw XMLInvalidBuildFileException (
568 "module '%s' trying to alias non-existant module '%s'",
570 aliasedModuleName
.c_str() );
575 for ( i
= 0; i
< node
.subElements
.size(); i
++ )
577 ParseContext parseContext
;
578 ProcessXMLSubElement ( *node
.subElements
[i
], SourceDirectory
, output
->relative_path
, parseContext
);
580 for ( i
= 0; i
< invocations
.size(); i
++ )
581 invocations
[i
]->ProcessXML ();
582 for ( i
= 0; i
< dependencies
.size(); i
++ )
583 dependencies
[i
]->ProcessXML ();
584 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
585 compilerFlags
[i
]->ProcessXML();
586 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
587 linkerFlags
[i
]->ProcessXML();
588 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
589 stubbedComponents
[i
]->ProcessXML();
590 non_if_data
.ProcessXML();
592 linkerScript
->ProcessXML();
596 autoRegister
->ProcessXML();
600 Module::ProcessXMLSubElement ( const XMLElement
& e
,
601 DirectoryLocation directory
,
602 const string
& relative_path
,
603 ParseContext
& parseContext
)
605 const XMLAttribute
* att
;
607 att
= e
.GetAttribute ( "compilerset", false );
611 CompilerSet compilerSet
;
613 if ( att
->value
== "msc" )
614 compilerSet
= MicrosoftC
;
615 else if ( att
->value
== "gcc" )
616 compilerSet
= GnuGcc
;
618 throw InvalidAttributeValueException (
623 if ( compilerSet
!= project
.configuration
.Compiler
)
627 att
= e
.GetAttribute ( "linkerset", false );
633 if ( att
->value
== "mslink" )
634 linkerSet
= MicrosoftLink
;
635 else if ( att
->value
== "ld" )
638 throw InvalidAttributeValueException (
643 if ( linkerSet
!= project
.configuration
.Linker
)
647 CompilationUnit
* pOldCompilationUnit
= parseContext
.compilationUnit
;
648 bool subs_invalid
= false;
649 string
subpath ( relative_path
);
650 DirectoryLocation subdirectory
= SourceDirectory
;
651 if ( e
.name
== "file" && e
.value
.size () > 0 )
654 const XMLAttribute
* att
= e
.GetAttribute ( "first", false );
657 if ( !stricmp ( att
->value
.c_str(), "true" ) )
659 else if ( stricmp ( att
->value
.c_str(), "false" ) )
661 throw XMLInvalidBuildFileException (
663 "attribute 'first' of <file> element can only be 'true' or 'false'" );
666 string switches
= "";
667 att
= e
.GetAttribute ( "switches", false );
669 switches
= att
->value
;
672 // check for c++ file
673 string ext
= GetExtension ( e
.value
);
674 if ( !stricmp ( ext
.c_str(), ".cpp" ) )
676 else if ( !stricmp ( ext
.c_str(), ".cc" ) )
678 else if ( !stricmp ( ext
.c_str(), ".cxx" ) )
681 File
* pFile
= new File ( directory
,
687 if ( parseContext
.compilationUnit
)
688 parseContext
.compilationUnit
->AddFile ( pFile
);
691 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( pFile
);
692 string ext
= ToLower ( GetExtension ( e
.value
) );
695 // put .idl files at the start of the module
696 non_if_data
.compilationUnits
.insert (
697 non_if_data
.compilationUnits
.begin(),
700 else if ( ext
== ".asm" || ext
== ".s" )
702 // put .asm files at the end of the module
703 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
704 non_if_data
.asmFiles
++;
708 // put other files in the middle
709 non_if_data
.compilationUnits
.insert (
710 non_if_data
.compilationUnits
.end() - non_if_data
.asmFiles
,
714 non_if_data
.files
.push_back ( pFile
);
717 else if ( e
.name
== "library" && e
.value
.size () )
719 const XMLAttribute
* att
= e
.GetAttribute ( "delayimport", false );
720 Library
* pLibrary
= new Library ( e
, *this, e
.value
);
721 if ( att
&& !stricmp ( att
->value
.c_str(), "true" ) )
722 pLibrary
->delayimp
= true;
723 non_if_data
.libraries
.push_back ( pLibrary
);
726 else if ( e
.name
== "directory" )
728 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
729 const XMLAttribute
* root
= e
.GetAttribute ( "root", false );
733 if ( root
->value
== "intermediate" )
734 subdirectory
= IntermediateDirectory
;
735 else if ( root
->value
== "output" )
736 subdirectory
= OutputDirectory
;
739 throw InvalidAttributeValueException (
745 subpath
= GetSubPath ( this->project
, e
.location
, relative_path
, att
->value
);
747 else if ( e
.name
== "include" )
749 Include
* include
= new Include ( project
, &e
, this );
750 non_if_data
.includes
.push_back ( include
);
753 else if ( e
.name
== "define" || e
.name
== "redefine" )
755 Define
* pDefine
= new Define ( project
, this, e
);
756 non_if_data
.defines
.push_back ( pDefine
);
759 else if ( e
.name
== "metadata" )
761 metadata
= new Metadata ( e
, *this );
762 subs_invalid
= false;
764 else if ( e
.name
== "invoke" )
766 invocations
.push_back ( new Invoke ( e
, *this ) );
767 subs_invalid
= false;
769 else if ( e
.name
== "dependency" )
771 dependencies
.push_back ( new Dependency ( e
, *this ) );
774 else if ( e
.name
== "bootsector" )
776 bootSector
= new Bootsector ( e
, this );
779 else if ( e
.name
== "importlibrary" )
783 throw XMLInvalidBuildFileException (
785 "Only one <importlibrary> is valid per module" );
787 SetImportLibrary ( new ImportLibrary ( project
, e
, this, false ) );
788 SetDelayImportLibrary ( new ImportLibrary ( project
, e
, this, true ) );
791 else if ( e
.name
== "if" || e
.name
== "ifnot" )
793 const XMLAttribute
* name
;
794 name
= e
.GetAttribute ( "property", true );
796 const Property
*property
= project
.LookupProperty( name
->value
);
797 const string
*PropertyValue
;
798 const string EmptyString
;
802 PropertyValue
= &property
->value
;
806 // Property does not exist, treat it as being empty
807 PropertyValue
= &EmptyString
;
810 const XMLAttribute
* value
;
811 value
= e
.GetAttribute ( "value", true );
814 bool negate
= ( e
.name
== "ifnot" );
815 bool equality
= ( *PropertyValue
== value
->value
);
816 if ( equality
== negate
)
818 // Failed, skip this element
819 if ( project
.configuration
.Verbose
)
820 printf("Skipping 'If' at %s\n", e
.location
.c_str () );
823 subs_invalid
= false;
825 else if ( e
.name
== "compilerflag" )
827 CompilerFlag
* pCompilerFlag
= new CompilerFlag ( project
, this, e
);
828 non_if_data
.compilerFlags
.push_back ( pCompilerFlag
);
831 else if ( e
.name
== "linkerflag" )
833 linkerFlags
.push_back ( new LinkerFlag ( project
, this, e
) );
836 else if ( e
.name
== "linkerscript" )
840 throw XMLInvalidBuildFileException (
842 "Only one <linkerscript> is valid per module" );
844 size_t pos
= e
.value
.find_last_of ( "/\\" );
845 if ( pos
== string::npos
)
847 linkerScript
= new LinkerScript (
848 e
, *this, new FileLocation ( SourceDirectory
, relative_path
, e
.value
, &e
) );
852 string dir
= e
.value
.substr ( 0, pos
);
853 string name
= e
.value
.substr ( pos
+ 1);
854 linkerScript
= new LinkerScript (
855 e
, *this, new FileLocation ( SourceDirectory
, relative_path
+ sSep
+ dir
, name
, &e
) );
859 else if ( e
.name
== "component" )
861 stubbedComponents
.push_back ( new StubbedComponent ( this, e
) );
862 subs_invalid
= false;
864 else if ( e
.name
== "property" )
866 throw XMLInvalidBuildFileException (
868 "<property> is not a valid sub-element of <module>" );
870 else if ( e
.name
== "bootstrap" )
872 bootstrap
= new Bootstrap ( project
, this, e
);
875 else if ( e
.name
== "pch" )
879 throw XMLInvalidBuildFileException (
881 "Only one <pch> is valid per module" );
883 size_t pos
= e
.value
.find_last_of ( "/\\" );
884 if ( pos
== string::npos
)
887 e
, *this, new FileLocation ( SourceDirectory
, relative_path
, e
.value
, &e
) );
891 string dir
= e
.value
.substr ( 0, pos
);
892 string name
= e
.value
.substr ( pos
+ 1);
894 e
, *this, new FileLocation ( SourceDirectory
, relative_path
+ sSep
+ dir
, name
, &e
) );
898 else if ( e
.name
== "compilationunit" )
900 if ( project
.configuration
.CompilationUnitsEnabled
)
902 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( &project
, this, &e
);
903 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
904 parseContext
.compilationUnit
= pCompilationUnit
;
906 subs_invalid
= false;
908 else if ( e
.name
== "autoregister" )
910 if ( autoRegister
!= NULL
)
912 throw XMLInvalidBuildFileException (
914 "there can be only one <%s> element for a module",
917 autoRegister
= new AutoRegister ( project
, this, e
);
920 if ( subs_invalid
&& e
.subElements
.size() > 0 )
922 throw XMLInvalidBuildFileException (
924 "<%s> cannot have sub-elements",
927 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
928 ProcessXMLSubElement ( *e
.subElements
[i
], subdirectory
, subpath
, parseContext
);
929 parseContext
.compilationUnit
= pOldCompilationUnit
;
933 Module::GetModuleType ( const string
& location
, const XMLAttribute
& attribute
)
935 if ( attribute
.value
== "buildtool" )
937 if ( attribute
.value
== "staticlibrary" )
938 return StaticLibrary
;
939 if ( attribute
.value
== "hoststaticlibrary" )
940 return HostStaticLibrary
;
941 if ( attribute
.value
== "objectlibrary" )
942 return ObjectLibrary
;
943 if ( attribute
.value
== "kernel" )
945 if ( attribute
.value
== "kernelmodedll" )
946 return KernelModeDLL
;
947 if ( attribute
.value
== "kernelmodedriver" )
948 return KernelModeDriver
;
949 if ( attribute
.value
== "nativedll" )
951 if ( attribute
.value
== "nativecui" )
953 if ( attribute
.value
== "keyboardlayout" )
954 return KeyboardLayout
;
955 if ( attribute
.value
== "win32dll" )
957 if ( attribute
.value
== "win32ocx" )
959 if ( attribute
.value
== "win32cui" )
961 if ( attribute
.value
== "win32gui" )
963 if ( attribute
.value
== "win32scr" )
965 if ( attribute
.value
== "bootloader" )
967 if ( attribute
.value
== "bootsector" )
969 if ( attribute
.value
== "bootprogram" )
971 if ( attribute
.value
== "iso" )
973 if ( attribute
.value
== "liveiso" )
975 if ( attribute
.value
== "isoregtest" )
977 if ( attribute
.value
== "liveisoregtest" )
978 return LiveIsoRegTest
;
979 if ( attribute
.value
== "test" )
981 if ( attribute
.value
== "rpcserver" )
983 if ( attribute
.value
== "rpcclient" )
985 if ( attribute
.value
== "rpcproxy" )
987 if ( attribute
.value
== "alias" )
989 if ( attribute
.value
== "idlheader" )
991 if ( attribute
.value
== "idlinterface" )
993 if ( attribute
.value
== "embeddedtypelib" )
994 return EmbeddedTypeLib
;
995 if ( attribute
.value
== "elfexecutable" )
996 return ElfExecutable
;
997 if ( attribute
.value
== "cabinet" )
999 if ( attribute
.value
== "messageheader" )
1000 return MessageHeader
;
1001 throw InvalidAttributeValueException ( location
,
1007 Module::GetTargetDirectoryTree () const
1013 case KeyboardLayout
:
1017 case KernelModeDriver
:
1030 case LiveIsoRegTest
:
1033 return OutputDirectory
;
1034 case EmbeddedTypeLib
:
1036 case HostStaticLibrary
:
1045 return IntermediateDirectory
;
1049 throw InvalidOperationException ( __FILE__
,
1051 "Invalid module type %d.",
1056 Module::GetDefaultModuleExtension () const
1064 case HostStaticLibrary
:
1078 case KeyboardLayout
:
1083 case KernelModeDriver
:
1093 case LiveIsoRegTest
:
1107 case EmbeddedTypeLib
:
1112 throw InvalidOperationException ( __FILE__
,
1117 Module::GetDefaultModuleEntrypoint () const
1122 return "KiSystemStartup";
1123 case KeyboardLayout
:
1125 case KernelModeDriver
:
1126 if (Environment::GetArch() == "arm") return "DriverEntry";
1127 return "DriverEntry@8";
1129 if (Environment::GetArch() == "arm") return "DllMainCRTStartup";
1130 return "DllMainCRTStartup@12";
1132 if (Environment::GetArch() == "arm") return "NtProcessStartup";
1133 return "NtProcessStartup@4";
1136 if (Environment::GetArch() == "arm") return "DllMain";
1137 return "DllMain@12";
1140 return "mainCRTStartup";
1143 return "WinMainCRTStartup";
1146 case HostStaticLibrary
:
1153 case LiveIsoRegTest
:
1163 case EmbeddedTypeLib
:
1169 throw InvalidOperationException ( __FILE__
,
1174 Module::GetDefaultModuleBaseaddress () const
1179 return "0x80800000";
1182 return "0x10000000";
1187 return "0x00400000";
1190 return "0x00400000";
1191 case KeyboardLayout
:
1193 case KernelModeDriver
:
1194 return "0x00010000";
1199 case HostStaticLibrary
:
1206 case LiveIsoRegTest
:
1215 case EmbeddedTypeLib
:
1221 throw InvalidOperationException ( __FILE__
,
1226 Module::GetDefaultModuleCRT () const
1246 return "msvcrt"; // BUGBUG: not sure about this
1247 case KeyboardLayout
:
1250 case KernelModeDriver
:
1257 case HostStaticLibrary
:
1263 case LiveIsoRegTest
:
1272 case EmbeddedTypeLib
:
1277 throw InvalidOperationException ( __FILE__
,
1282 Module::GetDefaultModuleIsCRT () const
1284 return type
== Kernel
;
1288 Module::HasImportLibrary () const
1290 return importLibrary
!= NULL
&& type
!= StaticLibrary
&& type
!= HostStaticLibrary
;
1294 Module::IsDLL () const
1301 case KeyboardLayout
:
1304 case KernelModeDriver
:
1313 case HostStaticLibrary
:
1321 case LiveIsoRegTest
:
1329 case EmbeddedTypeLib
:
1336 throw InvalidOperationException ( __FILE__
,
1341 Module::GetPathWithPrefix ( const string
& prefix
) const
1343 return output
->relative_path
+ cSep
+ prefix
+ output
->name
;
1347 Module::GetPathToBaseDir () const
1349 string temp_path
= output
->relative_path
;
1350 string result
= "..\\";
1351 while(temp_path
.find ('\\') != string::npos
)
1353 temp_path
.erase (0, temp_path
.find('\\')+1);
1360 Module::GetInvocationTarget ( const int index
) const
1362 return ssprintf ( "%s_invoke_%d",
1368 Module::GetEntryPoint(bool leadingUnderscore
) const
1371 if (entrypoint
== "0" || entrypoint
== "0x0")
1373 if (leadingUnderscore
)
1376 result
+= entrypoint
;
1378 if (Environment::GetArch() == "amd64")
1380 size_t at_index
= result
.find_last_of( '@' );
1381 if ( at_index
!= result
.npos
)
1382 return result
.substr (0, at_index
);
1389 Module::HasFileWithExtension (
1390 const IfableData
& data
,
1391 const std::string
& extension
) const
1394 for ( i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1396 CompilationUnit
* compilationUnit
= data
.compilationUnits
[i
];
1397 if ( compilationUnit
->HasFileWithExtension ( extension
) )
1404 Module::InvokeModule () const
1406 for ( size_t i
= 0; i
< invocations
.size (); i
++ )
1408 Invoke
& invoke
= *invocations
[i
];
1409 string command
= FixSeparatorForSystemCommand(invoke
.invokeModule
->output
->relative_path
+ "/" + invoke
.invokeModule
->output
->name
) + " " + invoke
.GetParameters ();
1410 printf ( "Executing '%s'\n\n", command
.c_str () );
1411 int exitcode
= system ( command
.c_str () );
1412 if ( exitcode
!= 0 )
1413 throw InvocationFailedException ( command
,
1420 Module::SetImportLibrary ( ImportLibrary
* importLibrary
)
1422 this->importLibrary
= importLibrary
;
1423 dependency
= new FileLocation ( HasImportLibrary () ? IntermediateDirectory
: output
->directory
,
1424 output
->relative_path
,
1425 HasImportLibrary () ? "lib" + name
+ ".a" : output
->name
);
1429 Module::SetDelayImportLibrary ( ImportLibrary
* importLibrary
)
1431 this->delayImportLibrary
= importLibrary
;
1435 Module::GetDllName () const
1437 if ( importLibrary
&& !importLibrary
->dllname
.empty() )
1438 return importLibrary
->dllname
;
1440 return output
->name
;
1442 throw new InvalidOperationException ( __FILE__
, __LINE__
, "Module %s has no dllname." );
1445 File::File ( DirectoryLocation directory
,
1446 const string
& relative_path
,
1449 const string
& _switches
,
1450 bool _isPreCompiledHeader
)
1451 : file ( directory
, relative_path
, name
),
1453 switches(_switches
),
1454 isPreCompiledHeader(_isPreCompiledHeader
)
1465 std::string
File::GetFullPath () const
1467 string
directory ( "" );
1468 switch ( file
.directory
)
1470 case SourceDirectory
:
1472 case IntermediateDirectory
:
1473 directory
= Environment::GetIntermediatePath () + sSep
;
1476 throw InvalidOperationException ( __FILE__
,
1478 "Invalid directory %d.",
1482 if ( file
.relative_path
.length () > 0 )
1483 directory
+= file
.relative_path
+ sSep
;
1486 return directory
+ file
.name
;
1490 Library::Library ( const XMLElement
& _node
,
1491 const Module
& _module
,
1492 const string
& _name
)
1496 importedModule(_module
.project
.LocateModule(_name
)),
1499 if ( module
.name
== name
)
1501 throw XMLInvalidBuildFileException (
1503 "module '%s' cannot link against itself",
1506 if ( !importedModule
)
1508 throw XMLInvalidBuildFileException (
1510 "module '%s' trying to import non-existant module '%s'",
1511 module
.name
.c_str(),
1516 Library::Library ( const Module
& _module
,
1517 const string
& _name
)
1521 importedModule(_module
.project
.LocateModule(_name
)),
1524 if ( !importedModule
)
1526 throw XMLInvalidBuildFileException (
1528 "module '%s' trying to import non-existant module '%s'",
1529 module
.name
.c_str(),
1535 Library::ProcessXML()
1537 if ( node
&& !module
.project
.LocateModule ( name
) )
1539 throw XMLInvalidBuildFileException (
1541 "module '%s' is trying to link against non-existant module '%s'",
1542 module
.name
.c_str(),
1548 Invoke::Invoke ( const XMLElement
& _node
,
1549 const Module
& _module
)
1556 Invoke::ProcessXML()
1558 const XMLAttribute
* att
= node
.GetAttribute ( "module", false );
1560 invokeModule
= &module
;
1563 invokeModule
= module
.project
.LocateModule ( att
->value
);
1564 if ( invokeModule
== NULL
)
1566 throw XMLInvalidBuildFileException (
1568 "module '%s' is trying to invoke non-existant module '%s'",
1569 module
.name
.c_str(),
1570 att
->value
.c_str() );
1574 for ( size_t i
= 0; i
< node
.subElements
.size (); i
++ )
1575 ProcessXMLSubElement ( *node
.subElements
[i
] );
1579 Invoke::ProcessXMLSubElement ( const XMLElement
& e
)
1581 bool subs_invalid
= false;
1582 if ( e
.name
== "input" )
1584 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1585 ProcessXMLSubElementInput ( *e
.subElements
[i
] );
1587 else if ( e
.name
== "output" )
1589 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1590 ProcessXMLSubElementOutput ( *e
.subElements
[i
] );
1592 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1594 throw XMLInvalidBuildFileException (
1596 "<%s> cannot have sub-elements",
1602 Invoke::ProcessXMLSubElementInput ( const XMLElement
& e
)
1604 bool subs_invalid
= false;
1605 if ( e
.name
== "inputfile" && e
.value
.size () > 0 )
1607 input
.push_back ( new InvokeFile (
1608 e
, FixSeparator ( module
.output
->relative_path
+ cSep
+ e
.value
) ) );
1609 subs_invalid
= true;
1611 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1613 throw XMLInvalidBuildFileException (
1615 "<%s> cannot have sub-elements",
1621 Invoke::ProcessXMLSubElementOutput ( const XMLElement
& e
)
1623 bool subs_invalid
= false;
1624 if ( e
.name
== "outputfile" && e
.value
.size () > 0 )
1626 output
.push_back ( new InvokeFile (
1627 e
, FixSeparator ( module
.output
->relative_path
+ cSep
+ e
.value
) ) );
1628 subs_invalid
= true;
1630 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1632 throw XMLInvalidBuildFileException (
1634 "<%s> cannot have sub-elements",
1640 Invoke::GetTargets ( string_list
& targets
) const
1642 for ( size_t i
= 0; i
< output
.size (); i
++ )
1644 InvokeFile
& file
= *output
[i
];
1645 targets
.push_back ( NormalizeFilename ( file
.name
) );
1650 Invoke::GetParameters () const
1652 string
parameters ( "" );
1654 for ( i
= 0; i
< output
.size (); i
++ )
1656 if ( parameters
.length () > 0)
1658 InvokeFile
& invokeFile
= *output
[i
];
1659 if ( invokeFile
.switches
.length () > 0 )
1661 parameters
+= invokeFile
.switches
+ " ";
1663 parameters
+= invokeFile
.name
;
1666 for ( i
= 0; i
< input
.size (); i
++ )
1668 if ( parameters
.length () > 0 )
1670 InvokeFile
& invokeFile
= *input
[i
];
1671 if ( invokeFile
.switches
.length () > 0 )
1673 parameters
+= invokeFile
.switches
;
1676 parameters
+= invokeFile
.name
;
1683 InvokeFile::InvokeFile ( const XMLElement
& _node
,
1684 const string
& _name
)
1688 const XMLAttribute
* att
= _node
.GetAttribute ( "switches", false );
1690 switches
= att
->value
;
1696 InvokeFile::ProcessXML()
1701 Dependency::Dependency ( const XMLElement
& _node
,
1702 const Module
& _module
)
1705 dependencyModule (NULL
)
1710 Dependency::ProcessXML()
1712 dependencyModule
= module
.project
.LocateModule ( node
.value
);
1713 if ( dependencyModule
== NULL
)
1715 throw XMLInvalidBuildFileException (
1717 "module '%s' depend on non-existant module '%s'",
1718 module
.name
.c_str(),
1719 node
.value
.c_str() );
1723 Bootsector::Bootsector ( const XMLElement
& _node
,
1724 const Module
* _module
)
1727 bootSectorModule (NULL
)
1729 if ( !IsSupportedModuleType ( module
->type
) )
1731 throw XMLInvalidBuildFileException (
1733 "<bootsector> is not applicable for this module type." );
1736 bootSectorModule
= module
->project
.LocateModule ( node
.value
);
1737 if ( bootSectorModule
== NULL
)
1739 throw XMLInvalidBuildFileException (
1741 "module '%s' depend on non-existant module '%s'",
1742 module
->name
.c_str(),
1743 node
.value
.c_str() );
1746 if (bootSectorModule
->type
!= BootSector
)
1748 throw XMLInvalidBuildFileException (
1750 "module '%s' is referencing non BootSector module '%s'",
1751 module
->name
.c_str(),
1752 node
.value
.c_str() );
1757 Bootsector::ProcessXML()
1762 Bootsector::IsSupportedModuleType ( ModuleType type
)
1766 type
== IsoRegTest
||
1767 type
== LiveIsoRegTest
)
1775 Metadata::Metadata ( const XMLElement
& _node
,
1776 const Module
& _module
)
1780 /* The module name */
1781 const XMLAttribute
* att
= _node
.GetAttribute ( "name", false );
1787 /* The module description */
1788 att
= _node
.GetAttribute ( "description", false );
1790 description
= att
->value
;
1794 /* The module version */
1795 att
= _node
.GetAttribute ( "version", false );
1797 version
= att
->value
;
1801 /* The module copyright */
1802 att
= _node
.GetAttribute ( "copyright", false );
1804 copyright
= att
->value
;
1808 att
= _node
.GetAttribute ( "url", false );
1814 /* When was this module updated */
1815 att
= _node
.GetAttribute ( "date", false );
1821 /* When was this module updated */
1822 att
= _node
.GetAttribute ( "owner", false );
1830 ImportLibrary::~ImportLibrary ()
1837 ImportLibrary::ImportLibrary ( const Project
& project
,
1838 const XMLElement
& node
,
1839 const Module
* module
,
1841 : XmlNode ( project
, node
),
1844 DirectoryLocation directory
= SourceDirectory
;
1845 const Module
* base
= module
;
1846 const XMLAttribute
* dllname
= node
.GetAttribute ( "dllname", false );
1847 const XMLAttribute
* definition
= node
.GetAttribute ( "definition", true );
1848 assert ( definition
);
1850 string relative_path
;
1851 const XMLAttribute
* att
= node
.GetAttribute ( "base", false );
1854 base
= project
.LocateModule ( att
->value
);
1856 throw XMLInvalidBuildFileException (
1858 "<importlibrary> attribute 'base' references non-existant module '%s'",
1859 att
->value
.c_str() );
1865 relative_path
= base
->output
->relative_path
;
1866 if ( node
.value
.length () > 0 && node
.value
!= "." )
1867 relative_path
+= sSep
+ node
.value
;
1870 relative_path
= node
.value
;
1872 att
= node
.GetAttribute ( "root", false );
1875 if ( att
->value
== "intermediate" )
1876 directory
= IntermediateDirectory
;
1878 throw InvalidAttributeValueException ( node
.location
,
1884 this->dllname
= dllname
->value
;
1885 else if ( module
->type
== StaticLibrary
|| module
->type
== HostStaticLibrary
)
1886 throw XMLInvalidBuildFileException (
1888 "<importlibrary> dllname attribute required." );
1890 size_t index
= definition
->value
.find_last_of ( "/\\" );
1891 if ( index
== string::npos
)
1893 source
= new FileLocation ( directory
,
1894 base
->output
->relative_path
,
1900 string dir
= definition
->value
.substr ( 0, index
);
1901 string name
= definition
->value
.substr ( index
+ 1);
1902 source
= new FileLocation ( directory
,
1903 NormalizeFilename ( base
->output
->relative_path
+ sSep
+ dir
),
1908 target
= new FileLocation ( IntermediateDirectory
,
1909 base
->output
->relative_path
,
1910 "lib" + module
->name
+ (delayimp
? ".delayimp.a" : ".a" ));
1915 Property::Property ( const XMLElement
& node_
,
1916 const Project
& project_
,
1917 const Module
* module_
)
1918 : project(project_
), module(module_
)
1920 const XMLAttribute
* att
;
1922 att
= node_
.GetAttribute ( "name", true );
1924 name
= project
.ResolveProperties ( att
->value
);
1926 att
= node_
.GetAttribute ( "value", true );
1930 att
= node_
.GetAttribute ( "internal", false );
1933 const char* p
= att
->value
.c_str();
1934 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
1936 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
1940 throw InvalidAttributeValueException (
1950 Property::Property ( const Project
& project_
,
1951 const Module
* module_
,
1952 const std::string
& name_
,
1953 const std::string
& value_
)
1954 : project(project_
), module(module_
), name(name_
), value(value_
)
1959 Property::ProcessXML()
1965 const XMLElement
& node_
,
1966 const Module
& module_
,
1967 const FileLocation
*file_
)
1968 : node(node_
), module(module_
), file(file_
)
1978 PchFile::ProcessXML()