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
];
528 for ( i
= 0; i
< cdfiles
.size (); i
++ )
541 delete importLibrary
;
557 aliasedModuleName
= project
.ResolveProperties ( aliasedModuleName
);
558 if ( aliasedModuleName
== name
)
560 throw XMLInvalidBuildFileException (
562 "module '%s' cannot link against itself",
565 const Module
* m
= project
.LocateModule ( aliasedModuleName
);
568 throw XMLInvalidBuildFileException (
570 "module '%s' trying to alias non-existant module '%s'",
572 aliasedModuleName
.c_str() );
577 for ( i
= 0; i
< node
.subElements
.size(); i
++ )
579 ParseContext parseContext
;
580 ProcessXMLSubElement ( *node
.subElements
[i
], SourceDirectory
, output
->relative_path
, parseContext
);
582 for ( i
= 0; i
< invocations
.size(); i
++ )
583 invocations
[i
]->ProcessXML ();
584 for ( i
= 0; i
< dependencies
.size(); i
++ )
585 dependencies
[i
]->ProcessXML ();
586 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
587 compilerFlags
[i
]->ProcessXML();
588 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
589 linkerFlags
[i
]->ProcessXML();
590 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
591 stubbedComponents
[i
]->ProcessXML();
592 non_if_data
.ProcessXML();
594 linkerScript
->ProcessXML();
598 autoRegister
->ProcessXML();
602 Module::ProcessXMLSubElement ( const XMLElement
& e
,
603 DirectoryLocation directory
,
604 const string
& relative_path
,
605 ParseContext
& parseContext
)
607 const XMLAttribute
* att
;
609 att
= e
.GetAttribute ( "compilerset", false );
613 CompilerSet compilerSet
;
615 if ( att
->value
== "msc" )
616 compilerSet
= MicrosoftC
;
617 else if ( att
->value
== "gcc" )
618 compilerSet
= GnuGcc
;
620 throw InvalidAttributeValueException (
625 if ( compilerSet
!= project
.configuration
.Compiler
)
629 att
= e
.GetAttribute ( "linkerset", false );
635 if ( att
->value
== "mslink" )
636 linkerSet
= MicrosoftLink
;
637 else if ( att
->value
== "ld" )
640 throw InvalidAttributeValueException (
645 if ( linkerSet
!= project
.configuration
.Linker
)
649 CompilationUnit
* pOldCompilationUnit
= parseContext
.compilationUnit
;
650 bool subs_invalid
= false;
651 string
subpath ( relative_path
);
652 DirectoryLocation subdirectory
= SourceDirectory
;
653 if ( e
.name
== "file" && e
.value
.size () > 0 )
656 const XMLAttribute
* att
= e
.GetAttribute ( "first", false );
659 if ( !stricmp ( att
->value
.c_str(), "true" ) )
661 else if ( stricmp ( att
->value
.c_str(), "false" ) )
663 throw XMLInvalidBuildFileException (
665 "attribute 'first' of <file> element can only be 'true' or 'false'" );
668 string switches
= "";
669 att
= e
.GetAttribute ( "switches", false );
671 switches
= att
->value
;
674 // check for c++ file
675 string ext
= GetExtension ( e
.value
);
676 if ( !stricmp ( ext
.c_str(), ".cpp" ) )
678 else if ( !stricmp ( ext
.c_str(), ".cc" ) )
680 else if ( !stricmp ( ext
.c_str(), ".cxx" ) )
683 File
* pFile
= new File ( directory
,
689 if ( parseContext
.compilationUnit
)
690 parseContext
.compilationUnit
->AddFile ( pFile
);
693 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( pFile
);
694 string ext
= ToLower ( GetExtension ( e
.value
) );
697 // put .idl files at the start of the module
698 non_if_data
.compilationUnits
.insert (
699 non_if_data
.compilationUnits
.begin(),
702 else if ( ext
== ".asm" || ext
== ".s" )
704 // put .asm files at the end of the module
705 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
706 non_if_data
.asmFiles
++;
710 // put other files in the middle
711 non_if_data
.compilationUnits
.insert (
712 non_if_data
.compilationUnits
.end() - non_if_data
.asmFiles
,
716 non_if_data
.files
.push_back ( pFile
);
719 else if ( e
.name
== "library" && e
.value
.size () )
721 const XMLAttribute
* att
= e
.GetAttribute ( "delayimport", false );
722 Library
* pLibrary
= new Library ( e
, *this, e
.value
);
723 if ( att
&& !stricmp ( att
->value
.c_str(), "true" ) )
724 pLibrary
->delayimp
= true;
725 non_if_data
.libraries
.push_back ( pLibrary
);
728 else if ( e
.name
== "directory" )
730 const XMLAttribute
* att
= e
.GetAttribute ( "name", true );
731 const XMLAttribute
* root
= e
.GetAttribute ( "root", false );
735 if ( root
->value
== "intermediate" )
736 subdirectory
= IntermediateDirectory
;
737 else if ( root
->value
== "output" )
738 subdirectory
= OutputDirectory
;
741 throw InvalidAttributeValueException (
747 subpath
= GetSubPath ( this->project
, e
.location
, relative_path
, att
->value
);
749 else if ( e
.name
== "include" )
751 Include
* include
= new Include ( project
, &e
, this );
752 non_if_data
.includes
.push_back ( include
);
755 else if ( e
.name
== "define" || e
.name
== "redefine" )
757 Define
* pDefine
= new Define ( project
, this, e
);
758 non_if_data
.defines
.push_back ( pDefine
);
761 else if ( e
.name
== "metadata" )
763 metadata
= new Metadata ( e
, *this );
764 subs_invalid
= false;
766 else if ( e
.name
== "invoke" )
768 invocations
.push_back ( new Invoke ( e
, *this ) );
769 subs_invalid
= false;
771 else if ( e
.name
== "dependency" )
773 dependencies
.push_back ( new Dependency ( e
, *this ) );
776 else if ( e
.name
== "bootsector" )
778 bootSector
= new Bootsector ( e
, this );
781 else if ( e
.name
== "importlibrary" )
785 throw XMLInvalidBuildFileException (
787 "Only one <importlibrary> is valid per module" );
789 SetImportLibrary ( new ImportLibrary ( project
, e
, this, false ) );
790 SetDelayImportLibrary ( new ImportLibrary ( project
, e
, this, true ) );
793 else if ( e
.name
== "if" || e
.name
== "ifnot" )
795 const XMLAttribute
* name
;
796 name
= e
.GetAttribute ( "property", true );
798 const Property
*property
= project
.LookupProperty( name
->value
);
799 const string
*PropertyValue
;
800 const string EmptyString
;
804 PropertyValue
= &property
->value
;
808 // Property does not exist, treat it as being empty
809 PropertyValue
= &EmptyString
;
812 const XMLAttribute
* value
;
813 value
= e
.GetAttribute ( "value", true );
816 bool negate
= ( e
.name
== "ifnot" );
817 bool equality
= ( *PropertyValue
== value
->value
);
818 if ( equality
== negate
)
820 // Failed, skip this element
821 if ( project
.configuration
.Verbose
)
822 printf("Skipping 'If' at %s\n", e
.location
.c_str () );
825 subs_invalid
= false;
827 else if ( e
.name
== "compilerflag" )
829 CompilerFlag
* pCompilerFlag
= new CompilerFlag ( project
, this, e
);
830 non_if_data
.compilerFlags
.push_back ( pCompilerFlag
);
833 else if ( e
.name
== "linkerflag" )
835 linkerFlags
.push_back ( new LinkerFlag ( project
, this, e
) );
838 else if ( e
.name
== "linkerscript" )
842 throw XMLInvalidBuildFileException (
844 "Only one <linkerscript> is valid per module" );
846 size_t pos
= e
.value
.find_last_of ( "/\\" );
847 if ( pos
== string::npos
)
849 linkerScript
= new LinkerScript (
850 e
, *this, new FileLocation ( SourceDirectory
, relative_path
, e
.value
, &e
) );
854 string dir
= e
.value
.substr ( 0, pos
);
855 string name
= e
.value
.substr ( pos
+ 1);
856 linkerScript
= new LinkerScript (
857 e
, *this, new FileLocation ( SourceDirectory
, relative_path
+ sSep
+ dir
, name
, &e
) );
861 else if ( e
.name
== "component" )
863 stubbedComponents
.push_back ( new StubbedComponent ( this, e
) );
864 subs_invalid
= false;
866 else if ( e
.name
== "property" )
868 throw XMLInvalidBuildFileException (
870 "<property> is not a valid sub-element of <module>" );
872 else if ( e
.name
== "bootstrap" )
874 bootstrap
= new Bootstrap ( project
, this, e
);
877 else if ( e
.name
== "pch" )
881 throw XMLInvalidBuildFileException (
883 "Only one <pch> is valid per module" );
885 size_t pos
= e
.value
.find_last_of ( "/\\" );
886 if ( pos
== string::npos
)
889 e
, *this, new FileLocation ( SourceDirectory
, relative_path
, e
.value
, &e
) );
893 string dir
= e
.value
.substr ( 0, pos
);
894 string name
= e
.value
.substr ( pos
+ 1);
896 e
, *this, new FileLocation ( SourceDirectory
, relative_path
+ sSep
+ dir
, name
, &e
) );
900 else if ( e
.name
== "compilationunit" )
902 if ( project
.configuration
.CompilationUnitsEnabled
)
904 CompilationUnit
* pCompilationUnit
= new CompilationUnit ( &project
, this, &e
);
905 non_if_data
.compilationUnits
.push_back ( pCompilationUnit
);
906 parseContext
.compilationUnit
= pCompilationUnit
;
908 subs_invalid
= false;
910 else if ( e
.name
== "autoregister" )
912 if ( autoRegister
!= NULL
)
914 throw XMLInvalidBuildFileException (
916 "there can be only one <%s> element for a module",
919 autoRegister
= new AutoRegister ( project
, this, e
);
922 else if ( e
.name
== "cdfile" )
924 CDFile
* cdfile
= new CDFile ( project
, e
, subpath
);
925 cdfiles
.push_back ( cdfile
);
928 if ( subs_invalid
&& e
.subElements
.size() > 0 )
930 throw XMLInvalidBuildFileException (
932 "<%s> cannot have sub-elements",
935 for ( size_t i
= 0; i
< cdfiles
.size (); i
++ )
936 cdfiles
[i
]->ProcessXML ();
937 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
938 ProcessXMLSubElement ( *e
.subElements
[i
], subdirectory
, subpath
, parseContext
);
939 parseContext
.compilationUnit
= pOldCompilationUnit
;
943 Module::GetModuleType ( const string
& location
, const XMLAttribute
& attribute
)
945 if ( attribute
.value
== "buildtool" )
947 if ( attribute
.value
== "staticlibrary" )
948 return StaticLibrary
;
949 if ( attribute
.value
== "hoststaticlibrary" )
950 return HostStaticLibrary
;
951 if ( attribute
.value
== "objectlibrary" )
952 return ObjectLibrary
;
953 if ( attribute
.value
== "kernel" )
955 if ( attribute
.value
== "kernelmodedll" )
956 return KernelModeDLL
;
957 if ( attribute
.value
== "kernelmodedriver" )
958 return KernelModeDriver
;
959 if ( attribute
.value
== "nativedll" )
961 if ( attribute
.value
== "nativecui" )
963 if ( attribute
.value
== "keyboardlayout" )
964 return KeyboardLayout
;
965 if ( attribute
.value
== "win32dll" )
967 if ( attribute
.value
== "win32ocx" )
969 if ( attribute
.value
== "win32cui" )
971 if ( attribute
.value
== "win32gui" )
973 if ( attribute
.value
== "win32scr" )
975 if ( attribute
.value
== "bootloader" )
977 if ( attribute
.value
== "bootsector" )
979 if ( attribute
.value
== "bootprogram" )
981 if ( attribute
.value
== "iso" )
983 if ( attribute
.value
== "liveiso" )
985 if ( attribute
.value
== "test" )
987 if ( attribute
.value
== "rpcserver" )
989 if ( attribute
.value
== "rpcclient" )
991 if ( attribute
.value
== "rpcproxy" )
993 if ( attribute
.value
== "alias" )
995 if ( attribute
.value
== "idlheader" )
997 if ( attribute
.value
== "idlinterface" )
999 if ( attribute
.value
== "embeddedtypelib" )
1000 return EmbeddedTypeLib
;
1001 if ( attribute
.value
== "elfexecutable" )
1002 return ElfExecutable
;
1003 if ( attribute
.value
== "cabinet" )
1005 if ( attribute
.value
== "messageheader" )
1006 return MessageHeader
;
1007 throw InvalidAttributeValueException ( location
,
1013 Module::GetTargetDirectoryTree () const
1019 case KeyboardLayout
:
1023 case KernelModeDriver
:
1037 return OutputDirectory
;
1038 case EmbeddedTypeLib
:
1040 case HostStaticLibrary
:
1049 return IntermediateDirectory
;
1053 throw InvalidOperationException ( __FILE__
,
1055 "Invalid module type %d.",
1060 Module::GetDefaultModuleExtension () const
1068 case HostStaticLibrary
:
1082 case KeyboardLayout
:
1087 case KernelModeDriver
:
1109 case EmbeddedTypeLib
:
1114 throw InvalidOperationException ( __FILE__
,
1119 Module::GetDefaultModuleEntrypoint () const
1124 return "KiSystemStartup";
1125 case KeyboardLayout
:
1127 case KernelModeDriver
:
1128 if (Environment::GetArch() == "arm") return "DriverEntry";
1129 return "DriverEntry@8";
1131 if (Environment::GetArch() == "arm") return "DllMainCRTStartup";
1132 return "DllMainCRTStartup@12";
1134 if (Environment::GetArch() == "arm") return "NtProcessStartup";
1135 return "NtProcessStartup@4";
1138 if (Environment::GetArch() == "arm") return "DllMain";
1139 return "DllMain@12";
1142 return "mainCRTStartup";
1145 return "WinMainCRTStartup";
1148 case HostStaticLibrary
:
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
:
1213 case EmbeddedTypeLib
:
1219 throw InvalidOperationException ( __FILE__
,
1224 Module::GetDefaultModuleCRT () const
1244 return "msvcrt"; // BUGBUG: not sure about this
1245 case KeyboardLayout
:
1248 case KernelModeDriver
:
1255 case HostStaticLibrary
:
1268 case EmbeddedTypeLib
:
1273 throw InvalidOperationException ( __FILE__
,
1278 Module::GetDefaultModuleIsCRT () const
1280 return type
== Kernel
;
1284 Module::HasImportLibrary () const
1286 return importLibrary
!= NULL
&& type
!= StaticLibrary
&& type
!= HostStaticLibrary
;
1290 Module::IsDLL () const
1297 case KeyboardLayout
:
1300 case KernelModeDriver
:
1309 case HostStaticLibrary
:
1323 case EmbeddedTypeLib
:
1330 throw InvalidOperationException ( __FILE__
,
1335 Module::GetPathWithPrefix ( const string
& prefix
) const
1337 return output
->relative_path
+ cSep
+ prefix
+ output
->name
;
1341 Module::GetPathToBaseDir () const
1343 string temp_path
= output
->relative_path
;
1344 string result
= "..\\";
1345 while(temp_path
.find ('\\') != string::npos
)
1347 temp_path
.erase (0, temp_path
.find('\\')+1);
1354 Module::GetInvocationTarget ( const int index
) const
1356 return ssprintf ( "%s_invoke_%d",
1362 Module::GetEntryPoint(bool leadingUnderscore
) const
1365 if (entrypoint
== "0" || entrypoint
== "0x0")
1367 if (leadingUnderscore
)
1370 result
+= entrypoint
;
1372 if (Environment::GetArch() == "amd64")
1374 size_t at_index
= result
.find_last_of( '@' );
1375 if ( at_index
!= result
.npos
)
1376 return result
.substr (0, at_index
);
1383 Module::HasFileWithExtension (
1384 const IfableData
& data
,
1385 const std::string
& extension
) const
1388 for ( i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1390 CompilationUnit
* compilationUnit
= data
.compilationUnits
[i
];
1391 if ( compilationUnit
->HasFileWithExtension ( extension
) )
1398 Module::InvokeModule () const
1400 for ( size_t i
= 0; i
< invocations
.size (); i
++ )
1402 Invoke
& invoke
= *invocations
[i
];
1403 string command
= FixSeparatorForSystemCommand(invoke
.invokeModule
->output
->relative_path
+ "/" + invoke
.invokeModule
->output
->name
) + " " + invoke
.GetParameters ();
1404 printf ( "Executing '%s'\n\n", command
.c_str () );
1405 int exitcode
= system ( command
.c_str () );
1406 if ( exitcode
!= 0 )
1407 throw InvocationFailedException ( command
,
1414 Module::SetImportLibrary ( ImportLibrary
* importLibrary
)
1416 this->importLibrary
= importLibrary
;
1417 dependency
= new FileLocation ( HasImportLibrary () ? IntermediateDirectory
: output
->directory
,
1418 output
->relative_path
,
1419 HasImportLibrary () ? "lib" + name
+ ".a" : output
->name
);
1423 Module::SetDelayImportLibrary ( ImportLibrary
* importLibrary
)
1425 this->delayImportLibrary
= importLibrary
;
1429 Module::GetDllName () const
1431 if ( importLibrary
&& !importLibrary
->dllname
.empty() )
1432 return importLibrary
->dllname
;
1434 return output
->name
;
1436 throw new InvalidOperationException ( __FILE__
, __LINE__
, "Module %s has no dllname." );
1439 File::File ( DirectoryLocation directory
,
1440 const string
& relative_path
,
1443 const string
& _switches
,
1444 bool _isPreCompiledHeader
)
1445 : file ( directory
, relative_path
, name
),
1447 switches(_switches
),
1448 isPreCompiledHeader(_isPreCompiledHeader
)
1459 std::string
File::GetFullPath () const
1461 string
directory ( "" );
1462 switch ( file
.directory
)
1464 case SourceDirectory
:
1466 case IntermediateDirectory
:
1467 directory
= Environment::GetIntermediatePath () + sSep
;
1470 throw InvalidOperationException ( __FILE__
,
1472 "Invalid directory %d.",
1476 if ( file
.relative_path
.length () > 0 )
1477 directory
+= file
.relative_path
+ sSep
;
1480 return directory
+ file
.name
;
1484 Library::Library ( const XMLElement
& _node
,
1485 const Module
& _module
,
1486 const string
& _name
)
1490 importedModule(_module
.project
.LocateModule(_name
)),
1493 if ( module
.name
== name
)
1495 throw XMLInvalidBuildFileException (
1497 "module '%s' cannot link against itself",
1500 if ( !importedModule
)
1502 throw XMLInvalidBuildFileException (
1504 "module '%s' trying to import non-existant module '%s'",
1505 module
.name
.c_str(),
1510 Library::Library ( const Module
& _module
,
1511 const string
& _name
)
1515 importedModule(_module
.project
.LocateModule(_name
)),
1518 if ( !importedModule
)
1520 throw XMLInvalidBuildFileException (
1522 "module '%s' trying to import non-existant module '%s'",
1523 module
.name
.c_str(),
1529 Library::ProcessXML()
1531 if ( node
&& !module
.project
.LocateModule ( name
) )
1533 throw XMLInvalidBuildFileException (
1535 "module '%s' is trying to link against non-existant module '%s'",
1536 module
.name
.c_str(),
1542 Invoke::Invoke ( const XMLElement
& _node
,
1543 const Module
& _module
)
1550 Invoke::ProcessXML()
1552 const XMLAttribute
* att
= node
.GetAttribute ( "module", false );
1554 invokeModule
= &module
;
1557 invokeModule
= module
.project
.LocateModule ( att
->value
);
1558 if ( invokeModule
== NULL
)
1560 throw XMLInvalidBuildFileException (
1562 "module '%s' is trying to invoke non-existant module '%s'",
1563 module
.name
.c_str(),
1564 att
->value
.c_str() );
1568 for ( size_t i
= 0; i
< node
.subElements
.size (); i
++ )
1569 ProcessXMLSubElement ( *node
.subElements
[i
] );
1573 Invoke::ProcessXMLSubElement ( const XMLElement
& e
)
1575 bool subs_invalid
= false;
1576 if ( e
.name
== "input" )
1578 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1579 ProcessXMLSubElementInput ( *e
.subElements
[i
] );
1581 else if ( e
.name
== "output" )
1583 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
1584 ProcessXMLSubElementOutput ( *e
.subElements
[i
] );
1586 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1588 throw XMLInvalidBuildFileException (
1590 "<%s> cannot have sub-elements",
1596 Invoke::ProcessXMLSubElementInput ( const XMLElement
& e
)
1598 bool subs_invalid
= false;
1599 if ( e
.name
== "inputfile" && e
.value
.size () > 0 )
1601 input
.push_back ( new InvokeFile (
1602 e
, FixSeparator ( module
.output
->relative_path
+ cSep
+ e
.value
) ) );
1603 subs_invalid
= true;
1605 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1607 throw XMLInvalidBuildFileException (
1609 "<%s> cannot have sub-elements",
1615 Invoke::ProcessXMLSubElementOutput ( const XMLElement
& e
)
1617 bool subs_invalid
= false;
1618 if ( e
.name
== "outputfile" && e
.value
.size () > 0 )
1620 output
.push_back ( new InvokeFile (
1621 e
, FixSeparator ( module
.output
->relative_path
+ cSep
+ e
.value
) ) );
1622 subs_invalid
= true;
1624 if ( subs_invalid
&& e
.subElements
.size() > 0 )
1626 throw XMLInvalidBuildFileException (
1628 "<%s> cannot have sub-elements",
1634 Invoke::GetTargets ( string_list
& targets
) const
1636 for ( size_t i
= 0; i
< output
.size (); i
++ )
1638 InvokeFile
& file
= *output
[i
];
1639 targets
.push_back ( NormalizeFilename ( file
.name
) );
1644 Invoke::GetParameters () const
1646 string
parameters ( "" );
1648 for ( i
= 0; i
< output
.size (); i
++ )
1650 if ( parameters
.length () > 0)
1652 InvokeFile
& invokeFile
= *output
[i
];
1653 if ( invokeFile
.switches
.length () > 0 )
1655 parameters
+= invokeFile
.switches
+ " ";
1657 parameters
+= invokeFile
.name
;
1660 for ( i
= 0; i
< input
.size (); i
++ )
1662 if ( parameters
.length () > 0 )
1664 InvokeFile
& invokeFile
= *input
[i
];
1665 if ( invokeFile
.switches
.length () > 0 )
1667 parameters
+= invokeFile
.switches
;
1670 parameters
+= invokeFile
.name
;
1677 InvokeFile::InvokeFile ( const XMLElement
& _node
,
1678 const string
& _name
)
1682 const XMLAttribute
* att
= _node
.GetAttribute ( "switches", false );
1684 switches
= att
->value
;
1690 InvokeFile::ProcessXML()
1695 Dependency::Dependency ( const XMLElement
& _node
,
1696 const Module
& _module
)
1699 dependencyModule (NULL
)
1704 Dependency::ProcessXML()
1706 dependencyModule
= module
.project
.LocateModule ( node
.value
);
1707 if ( dependencyModule
== NULL
)
1709 throw XMLInvalidBuildFileException (
1711 "module '%s' depend on non-existant module '%s'",
1712 module
.name
.c_str(),
1713 node
.value
.c_str() );
1717 Bootsector::Bootsector ( const XMLElement
& _node
,
1718 const Module
* _module
)
1721 bootSectorModule (NULL
)
1723 if ( !IsSupportedModuleType ( module
->type
) )
1725 throw XMLInvalidBuildFileException (
1727 "<bootsector> is not applicable for this module type." );
1730 bootSectorModule
= module
->project
.LocateModule ( node
.value
);
1731 if ( bootSectorModule
== NULL
)
1733 throw XMLInvalidBuildFileException (
1735 "module '%s' depend on non-existant module '%s'",
1736 module
->name
.c_str(),
1737 node
.value
.c_str() );
1740 if (bootSectorModule
->type
!= BootSector
)
1742 throw XMLInvalidBuildFileException (
1744 "module '%s' is referencing non BootSector module '%s'",
1745 module
->name
.c_str(),
1746 node
.value
.c_str() );
1751 Bootsector::ProcessXML()
1756 Bootsector::IsSupportedModuleType ( ModuleType type
)
1767 Metadata::Metadata ( const XMLElement
& _node
,
1768 const Module
& _module
)
1772 /* The module name */
1773 const XMLAttribute
* att
= _node
.GetAttribute ( "name", false );
1779 /* The module description */
1780 att
= _node
.GetAttribute ( "description", false );
1782 description
= att
->value
;
1786 /* The module version */
1787 att
= _node
.GetAttribute ( "version", false );
1789 version
= att
->value
;
1793 /* The module copyright */
1794 att
= _node
.GetAttribute ( "copyright", false );
1796 copyright
= att
->value
;
1800 att
= _node
.GetAttribute ( "url", false );
1806 /* When was this module updated */
1807 att
= _node
.GetAttribute ( "date", false );
1813 /* When was this module updated */
1814 att
= _node
.GetAttribute ( "owner", false );
1822 ImportLibrary::~ImportLibrary ()
1829 ImportLibrary::ImportLibrary ( const Project
& project
,
1830 const XMLElement
& node
,
1831 const Module
* module
,
1833 : XmlNode ( project
, node
),
1836 DirectoryLocation directory
= SourceDirectory
;
1837 const Module
* base
= module
;
1838 const XMLAttribute
* dllname
= node
.GetAttribute ( "dllname", false );
1839 const XMLAttribute
* definition
= node
.GetAttribute ( "definition", true );
1840 assert ( definition
);
1842 string relative_path
;
1843 const XMLAttribute
* att
= node
.GetAttribute ( "base", false );
1846 base
= project
.LocateModule ( att
->value
);
1848 throw XMLInvalidBuildFileException (
1850 "<importlibrary> attribute 'base' references non-existant module '%s'",
1851 att
->value
.c_str() );
1857 relative_path
= base
->output
->relative_path
;
1858 if ( node
.value
.length () > 0 && node
.value
!= "." )
1859 relative_path
+= sSep
+ node
.value
;
1862 relative_path
= node
.value
;
1864 att
= node
.GetAttribute ( "root", false );
1867 if ( att
->value
== "intermediate" )
1868 directory
= IntermediateDirectory
;
1870 throw InvalidAttributeValueException ( node
.location
,
1876 this->dllname
= dllname
->value
;
1877 else if ( module
->type
== StaticLibrary
|| module
->type
== HostStaticLibrary
)
1878 throw XMLInvalidBuildFileException (
1880 "<importlibrary> dllname attribute required." );
1882 size_t index
= definition
->value
.find_last_of ( "/\\" );
1883 if ( index
== string::npos
)
1885 source
= new FileLocation ( directory
,
1886 base
->output
->relative_path
,
1892 string dir
= definition
->value
.substr ( 0, index
);
1893 string name
= definition
->value
.substr ( index
+ 1);
1894 source
= new FileLocation ( directory
,
1895 NormalizeFilename ( base
->output
->relative_path
+ sSep
+ dir
),
1900 target
= new FileLocation ( IntermediateDirectory
,
1901 base
->output
->relative_path
,
1902 "lib" + module
->name
+ (delayimp
? ".delayimp.a" : ".a" ));
1907 Property::Property ( const XMLElement
& node_
,
1908 const Project
& project_
,
1909 const Module
* module_
)
1910 : project(project_
), module(module_
)
1912 const XMLAttribute
* att
;
1914 att
= node_
.GetAttribute ( "name", true );
1916 name
= project
.ResolveProperties ( att
->value
);
1918 att
= node_
.GetAttribute ( "value", true );
1922 att
= node_
.GetAttribute ( "internal", false );
1925 const char* p
= att
->value
.c_str();
1926 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
1928 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
1932 throw InvalidAttributeValueException (
1942 Property::Property ( const Project
& project_
,
1943 const Module
* module_
,
1944 const std::string
& name_
,
1945 const std::string
& value_
)
1946 : project(project_
), module(module_
), name(name_
), value(value_
)
1951 Property::ProcessXML()
1957 const XMLElement
& node_
,
1958 const Module
& module_
,
1959 const FileLocation
*file_
)
1960 : node(node_
), module(module_
), file(file_
)
1970 PchFile::ProcessXML()