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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 isStartupLib
= GetBooleanAttribute ( moduleNode
, "isstartuplib" );
347 isCRT
= GetBooleanAttribute ( moduleNode
, "iscrt", GetDefaultModuleIsCRT () );
349 att
= moduleNode
.GetAttribute ( "crt", false );
354 if ( stricmp ( CRT
.c_str (), "auto" ) == 0 )
355 CRT
= GetDefaultModuleCRT ();
358 CRT
= GetDefaultModuleCRT ();
360 const char * crtAttr
= CRT
.c_str ();
361 if ( crtAttr
== NULL
|| stricmp ( crtAttr
, "none" ) == 0 )
363 else if ( stricmp ( crtAttr
, "libc" ) == 0 )
365 else if ( stricmp ( crtAttr
, "msvcrt" ) == 0 )
367 else if ( stricmp ( crtAttr
, "libcntpr" ) == 0 )
369 else if ( stricmp ( crtAttr
, "ntdll" ) == 0 )
371 else if ( stricmp ( crtAttr
, "static" ) == 0 )
373 else if ( stricmp ( crtAttr
, "dll" ) == 0 )
377 throw InvalidAttributeValueException (
380 std::string ( crtAttr
) );
383 if ( isCRT
&& dynamicCRT
)
385 throw XMLInvalidBuildFileException (
387 "C runtime module '%s' cannot be compiled for a dynamically-linked C runtime",
391 att
= moduleNode
.GetAttribute ( "prefix", false );
395 att
= moduleNode
.GetAttribute ( "installname", false );
398 const XMLAttribute
* installbase
= moduleNode
.GetAttribute ( "installbase", false );
401 this->installbase
= installbase
->value
;
403 this->installbase
= "";
405 install
= new FileLocation ( InstallDirectory
,
406 installbase
? installbase
->value
: "",
410 output
= new FileLocation ( GetTargetDirectoryTree (),
416 att
= moduleNode
.GetAttribute ( "output", false );
421 printf ( "%s: WARNING: 'installname' overrides 'output' also defined for this module.\n",
422 moduleNode
.location
.c_str() );
426 output
= new FileLocation ( GetTargetDirectoryTree (),
433 /* If no one has set the output file for this module set it automatically */
436 output
= new FileLocation ( GetTargetDirectoryTree (),
442 att
= moduleNode
.GetAttribute ( "allowwarnings", false );
445 att
= moduleNode
.GetAttribute ( "warnings", false );
448 printf ( "%s: WARNING: 'warnings' attribute of <module> is deprecated, use 'allowwarnings' instead\n",
449 moduleNode
.location
.c_str() );
453 allowWarnings
= att
->value
== "true";
454 else if ( project
.allowWarningsSet
)
455 allowWarnings
= project
.allowWarnings
;
457 allowWarnings
= false;
459 att
= moduleNode
.GetAttribute ( "aliasof", false );
460 if ( type
== Alias
&& att
!= NULL
)
461 aliasedModuleName
= att
->value
;
463 aliasedModuleName
= "";
465 if ( type
== BootProgram
)
467 att
= moduleNode
.GetAttribute ( "payload", true );
468 payload
= att
->value
;
471 if ( type
== BootProgram
|| type
== ElfExecutable
)
473 att
= moduleNode
.GetAttribute ( "buildtype", false );
476 buildtype
= att
->value
;
480 buildtype
= "BOOTPROG";
484 att
= moduleNode
.GetAttribute ( "description", false );
487 description
= project
.ResolveProperties(att
->value
);
492 att
= moduleNode
.GetAttribute ( "lcid", false );
493 if (type
== KeyboardLayout
&& att
!= NULL
)
498 att
= moduleNode
.GetAttribute ( "layoutid", false );
499 if (type
== KeyboardLayout
&& att
!= NULL
)
500 layoutId
= att
->value
;
504 att
= moduleNode
.GetAttribute ( "layoutnameresid", false );
505 if (type
== KeyboardLayout
&& att
!= NULL
)
506 layoutNameResId
= att
->value
;
508 layoutNameResId
= "";
510 SetImportLibrary ( NULL
);
516 for ( i
= 0; i
< invocations
.size(); i
++ )
517 delete invocations
[i
];
518 for ( i
= 0; i
< dependencies
.size(); i
++ )
519 delete dependencies
[i
];
520 for ( i
= 0; i
< compilerFlags
.size(); i
++ )
521 delete compilerFlags
[i
];
522 for ( i
= 0; i
< linkerFlags
.size(); i
++ )
523 delete linkerFlags
[i
];
524 for ( i
= 0; i
< stubbedComponents
.size(); i
++ )
525 delete stubbedComponents
[i
];
526 for ( i
= 0; i
< cdfiles
.size (); 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 else if ( e
.name
== "cdfile" )
922 CDFile
* cdfile
= new CDFile ( project
, e
, subpath
);
923 cdfiles
.push_back ( cdfile
);
926 if ( subs_invalid
&& e
.subElements
.size() > 0 )
928 throw XMLInvalidBuildFileException (
930 "<%s> cannot have sub-elements",
933 for ( size_t i
= 0; i
< cdfiles
.size (); i
++ )
934 cdfiles
[i
]->ProcessXML ();
935 for ( size_t i
= 0; i
< e
.subElements
.size (); i
++ )
936 ProcessXMLSubElement ( *e
.subElements
[i
], subdirectory
, subpath
, parseContext
);
937 parseContext
.compilationUnit
= pOldCompilationUnit
;
941 Module::GetModuleType ( const string
& location
, const XMLAttribute
& attribute
)
943 if ( attribute
.value
== "buildtool" )
945 if ( attribute
.value
== "staticlibrary" )
946 return StaticLibrary
;
947 if ( attribute
.value
== "hoststaticlibrary" )
948 return HostStaticLibrary
;
949 if ( attribute
.value
== "objectlibrary" )
950 return ObjectLibrary
;
951 if ( attribute
.value
== "kernel" )
953 if ( attribute
.value
== "kernelmodedll" )
954 return KernelModeDLL
;
955 if ( attribute
.value
== "kernelmodedriver" )
956 return KernelModeDriver
;
957 if ( attribute
.value
== "nativedll" )
959 if ( attribute
.value
== "nativecui" )
961 if ( attribute
.value
== "keyboardlayout" )
962 return KeyboardLayout
;
963 if ( attribute
.value
== "win32dll" )
965 if ( attribute
.value
== "win32ocx" )
967 if ( attribute
.value
== "win32cui" )
969 if ( attribute
.value
== "win32gui" )
971 if ( attribute
.value
== "win32scr" )
973 if ( attribute
.value
== "bootloader" )
975 if ( attribute
.value
== "bootsector" )
977 if ( attribute
.value
== "bootprogram" )
979 if ( attribute
.value
== "iso" )
981 if ( attribute
.value
== "liveiso" )
983 if ( attribute
.value
== "test" )
985 if ( attribute
.value
== "rpcserver" )
987 if ( attribute
.value
== "rpcclient" )
989 if ( attribute
.value
== "rpcproxy" )
991 if ( attribute
.value
== "alias" )
993 if ( attribute
.value
== "idlheader" )
995 if ( attribute
.value
== "idlinterface" )
997 if ( attribute
.value
== "embeddedtypelib" )
998 return EmbeddedTypeLib
;
999 if ( attribute
.value
== "elfexecutable" )
1000 return ElfExecutable
;
1001 if ( attribute
.value
== "cabinet" )
1003 if ( attribute
.value
== "messageheader" )
1004 return MessageHeader
;
1005 throw InvalidAttributeValueException ( location
,
1011 Module::GetTargetDirectoryTree () const
1017 case KeyboardLayout
:
1021 case KernelModeDriver
:
1035 return OutputDirectory
;
1036 case EmbeddedTypeLib
:
1038 case HostStaticLibrary
:
1047 return IntermediateDirectory
;
1051 throw InvalidOperationException ( __FILE__
,
1053 "Invalid module type %d.",
1058 Module::GetDefaultModuleExtension () const
1066 case HostStaticLibrary
:
1080 case KeyboardLayout
:
1085 case KernelModeDriver
:
1107 case EmbeddedTypeLib
:
1112 throw InvalidOperationException ( __FILE__
,
1117 Module::GetDefaultModuleEntrypoint () const
1122 if (Environment::GetArch() == "arm") return "KiSystemStartup";
1123 return "KiSystemStartup@4";
1124 case KeyboardLayout
:
1126 case KernelModeDriver
:
1127 if (Environment::GetArch() == "arm") return "DriverEntry";
1128 return "DriverEntry@8";
1130 if (Environment::GetArch() == "arm") return "DllMainCRTStartup";
1131 return "DllMainCRTStartup@12";
1133 if (Environment::GetArch() == "arm") return "NtProcessStartup";
1134 return "NtProcessStartup@4";
1137 if (Environment::GetArch() == "arm") return "DllMain";
1138 return "DllMain@12";
1141 return "mainCRTStartup";
1144 return "WinMainCRTStartup";
1147 case HostStaticLibrary
:
1162 case EmbeddedTypeLib
:
1168 throw InvalidOperationException ( __FILE__
,
1173 Module::GetDefaultModuleBaseaddress () const
1178 return "0x80800000";
1181 return "0x10000000";
1186 return "0x00400000";
1189 return "0x00400000";
1190 case KeyboardLayout
:
1192 case KernelModeDriver
:
1193 return "0x00010000";
1198 case HostStaticLibrary
:
1212 case EmbeddedTypeLib
:
1218 throw InvalidOperationException ( __FILE__
,
1223 Module::GetDefaultModuleCRT () const
1243 return "msvcrt"; // BUGBUG: not sure about this
1244 case KeyboardLayout
:
1247 case KernelModeDriver
:
1254 case HostStaticLibrary
:
1267 case EmbeddedTypeLib
:
1272 throw InvalidOperationException ( __FILE__
,
1277 Module::GetDefaultModuleIsCRT () const
1279 return type
== Kernel
;
1283 Module::HasImportLibrary () const
1285 return importLibrary
!= NULL
&& type
!= StaticLibrary
&& type
!= HostStaticLibrary
;
1289 Module::IsDLL () const
1296 case KeyboardLayout
:
1299 case KernelModeDriver
:
1308 case HostStaticLibrary
:
1322 case EmbeddedTypeLib
:
1329 throw InvalidOperationException ( __FILE__
,
1334 Module::GetPathWithPrefix ( const string
& prefix
) const
1336 return output
->relative_path
+ cSep
+ prefix
+ output
->name
;
1340 Module::GetPathToBaseDir () const
1342 string temp_path
= output
->relative_path
;
1343 string result
= "..\\";
1344 while(temp_path
.find ('\\') != string::npos
)
1346 temp_path
.erase (0, temp_path
.find('\\')+1);
1353 Module::GetInvocationTarget ( const int index
) const
1355 return ssprintf ( "%s_invoke_%d",
1361 Module::GetEntryPoint() const
1364 if (entrypoint
== "0" || entrypoint
== "0x0")
1367 if (Environment::GetArch() != "arm" && Environment::GetArch() != "amd64")
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
;
1878 size_t index
= definition
->value
.find_last_of ( "/\\" );
1879 if ( index
== string::npos
)
1881 source
= new FileLocation ( directory
,
1882 base
->output
->relative_path
,
1888 string dir
= definition
->value
.substr ( 0, index
);
1889 string name
= definition
->value
.substr ( index
+ 1);
1890 source
= new FileLocation ( directory
,
1891 NormalizeFilename ( base
->output
->relative_path
+ sSep
+ dir
),
1896 target
= new FileLocation ( IntermediateDirectory
,
1897 base
->output
->relative_path
,
1898 "lib" + module
->name
+ (delayimp
? ".delayimp.a" : ".a" ));
1903 Property::Property ( const XMLElement
& node_
,
1904 const Project
& project_
,
1905 const Module
* module_
)
1906 : project(project_
), module(module_
)
1908 const XMLAttribute
* att
;
1910 att
= node_
.GetAttribute ( "name", true );
1912 name
= project
.ResolveProperties ( att
->value
);
1914 att
= node_
.GetAttribute ( "value", true );
1918 att
= node_
.GetAttribute ( "internal", false );
1921 const char* p
= att
->value
.c_str();
1922 if ( !stricmp ( p
, "true" ) || !stricmp ( p
, "yes" ) )
1924 else if ( !stricmp ( p
, "false" ) || !stricmp ( p
, "no" ) )
1928 throw InvalidAttributeValueException (
1938 Property::Property ( const Project
& project_
,
1939 const Module
* module_
,
1940 const std::string
& name_
,
1941 const std::string
& value_
)
1942 : project(project_
), module(module_
), name(name_
), value(value_
)
1947 Property::ProcessXML()
1953 const XMLElement
& node_
,
1954 const Module
& module_
,
1955 const FileLocation
*file_
)
1956 : node(node_
), module(module_
), file(file_
)
1966 PchFile::ProcessXML()