2 * Copyright (C) 2005 Casper S. Hornstrup
3 * 2006 Christoph von Wittich
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.
19 #include "../../pch.h"
23 #include "modulehandler.h"
27 #define pclose _pclose
35 typedef set
<string
> set_string
;
38 MingwBackend::GetFullPath ( const FileLocation
& file
) const
40 MingwModuleHandler::PassThruCacheDirectory ( &file
);
43 switch ( file
.directory
)
48 case IntermediateDirectory
:
49 directory
= "$(INTERMEDIATE)";
52 directory
= "$(OUTPUT)";
54 case InstallDirectory
:
55 directory
= "$(INSTALL)";
57 case TemporaryDirectory
:
58 directory
= "$(TEMPORARY)";
61 throw InvalidOperationException ( __FILE__
,
63 "Invalid directory %d.",
67 if ( file
.relative_path
.length () > 0 )
69 if ( directory
.length () > 0 )
71 directory
+= file
.relative_path
;
77 MingwBackend::GetFullName ( const FileLocation
& file
) const
80 switch ( file
.directory
)
85 case IntermediateDirectory
:
86 directory
= "$(INTERMEDIATE)";
89 directory
= "$(OUTPUT)";
91 case InstallDirectory
:
92 directory
= "$(INSTALL)";
94 case TemporaryDirectory
:
95 directory
= "$(TEMPORARY)";
98 throw InvalidOperationException ( __FILE__
,
100 "Invalid directory %d.",
104 if ( file
.relative_path
.length () > 0 )
106 if ( directory
.length () > 0 )
108 directory
+= file
.relative_path
;
111 if ( directory
.length () > 0 )
114 return directory
+ file
.name
;
118 v2s ( const Backend
* backend
, const vector
<FileLocation
>& files
, int wrap_at
)
124 for ( size_t i
= 0; i
< files
.size(); i
++ )
126 const FileLocation
& file
= files
[i
];
127 if ( wrap_at
> 0 && wrap_count
++ == wrap_at
)
131 s
+= backend
->GetFullName ( file
);
138 v2s ( const string_list
& v
, int wrap_at
)
144 for ( size_t i
= 0; i
< v
.size(); i
++ )
148 if ( wrap_at
> 0 && wrap_count
++ == wrap_at
)
158 static class MingwFactory
: public Backend::Factory
161 MingwFactory() : Factory ( "mingw", "Minimalist GNU Win32" ) {}
162 Backend
* operator() ( Project
& project
,
163 Configuration
& configuration
)
165 return new MingwBackend ( project
,
171 MingwBackend::MingwBackend ( Project
& project
,
172 Configuration
& configuration
)
173 : Backend ( project
, configuration
),
174 manualBinutilsSetting( false ),
175 intermediateDirectory ( new Directory ( "" ) ),
176 outputDirectory ( new Directory ( "" ) ),
177 installDirectory ( new Directory ( "" ) )
182 MingwBackend::~MingwBackend()
184 delete intermediateDirectory
;
185 delete outputDirectory
;
186 delete installDirectory
;
190 MingwBackend::AddDirectoryTarget ( const string
& directory
,
191 Directory
* directoryTree
)
193 if ( directory
.length () > 0)
194 directoryTree
->Add ( directory
.c_str() );
195 return directoryTree
->name
;
199 MingwBackend::CanEnablePreCompiledHeaderSupportForModule ( const Module
& module
)
201 if ( !configuration
.CompilationUnitsEnabled
)
204 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
206 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
208 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
209 if ( compilationUnit
.GetFiles ().size () != 1 )
212 // intentionally make a copy so that we can append more work in
213 // the middle of processing without having to go recursive
214 vector
<If
*> v
= module
.non_if_data
.ifs
;
215 for ( i
= 0; i
< v
.size (); i
++ )
219 // check for sub-ifs to add to list
220 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
221 for ( j
= 0; j
< ifs
.size (); j
++ )
222 v
.push_back ( ifs
[j
] );
223 const vector
<CompilationUnit
*>& compilationUnits
= rIf
.data
.compilationUnits
;
224 for ( j
= 0; j
< compilationUnits
.size (); j
++ )
226 CompilationUnit
& compilationUnit
= *compilationUnits
[j
];
227 if ( compilationUnit
.GetFiles ().size () != 1 )
235 MingwBackend::ProcessModules ()
237 printf ( "Processing modules..." );
239 vector
<MingwModuleHandler
*> v
;
242 for ( i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
244 Module
& module
= *ProjectNode
.modules
[i
];
245 if ( !module
.enabled
)
247 MingwModuleHandler
* h
= MingwModuleHandler::InstanciateHandler (
250 h
->AddImplicitLibraries ( module
);
251 if ( use_pch
&& CanEnablePreCompiledHeaderSupportForModule ( module
) )
252 h
->EnablePreCompiledHeaderSupport ();
253 if ( module
.host
== HostDefault
)
255 module
.host
= h
->DefaultHost();
256 assert ( module
.host
!= HostDefault
);
261 size_t iend
= v
.size ();
263 for ( i
= 0; i
< iend
; i
++ )
264 v
[i
]->GenerateSourceMacro();
265 for ( i
= 0; i
< iend
; i
++ )
266 v
[i
]->GenerateObjectMacro();
267 fprintf ( fMakefile
, "\n" );
268 for ( i
= 0; i
< iend
; i
++ )
269 v
[i
]->GenerateTargetMacro();
270 fprintf ( fMakefile
, "\n" );
272 GenerateAllTarget ( v
);
273 GenerateRegTestsRunTarget ();
275 for ( i
= 0; i
< iend
; i
++ )
276 v
[i
]->GenerateOtherMacros();
278 for ( i
= 0; i
< iend
; i
++ )
280 MingwModuleHandler
& h
= *v
[i
];
281 h
.GeneratePreconditionDependencies ();
283 h
.GenerateInvocations ();
284 h
.GenerateCleanTarget ();
285 h
.GenerateInstallTarget ();
286 h
.GenerateDependsTarget ();
294 MingwBackend::Process ()
296 if ( configuration
.CheckDependenciesForModuleOnly
)
297 CheckAutomaticDependenciesForModuleOnly ();
303 MingwBackend::CheckAutomaticDependenciesForModuleOnly ()
305 if ( configuration
.AutomaticDependencies
)
307 Module
* module
= ProjectNode
.LocateModule ( configuration
.CheckDependenciesForModuleOnlyModule
);
308 if ( module
== NULL
)
310 printf ( "Module '%s' does not exist\n",
311 configuration
.CheckDependenciesForModuleOnlyModule
.c_str () );
315 printf ( "Checking automatic dependencies for module '%s'...",
316 module
->name
.c_str () );
317 AutomaticDependency
automaticDependency ( ProjectNode
);
318 automaticDependency
.CheckAutomaticDependenciesForModule ( *module
,
319 configuration
.Verbose
);
325 MingwBackend::ProcessNormal ()
329 DetectNetwideAssembler ();
330 DetectPipeSupport ();
334 GenerateGlobalVariables ();
335 GenerateXmlBuildFilesMacro ();
337 GenerateInstallTarget ();
338 GenerateTestTarget ();
339 GenerateDirectoryTargets ();
340 GenerateDirectories ();
341 GenerateTestSupportCode ();
342 GenerateCompilationUnitSupportCode ();
344 GenerateProxyMakefiles ();
345 CheckAutomaticDependencies ();
350 MingwBackend::CreateMakefile ()
352 fMakefile
= fopen ( ProjectNode
.makefile
.c_str (), "w" );
354 throw AccessDeniedException ( ProjectNode
.makefile
);
355 MingwModuleHandler::SetBackend ( this );
356 MingwModuleHandler::SetMakefile ( fMakefile
);
360 MingwBackend::CloseMakefile () const
363 fclose ( fMakefile
);
367 MingwBackend::GenerateHeader () const
369 fprintf ( fMakefile
, "# THIS FILE IS AUTOMATICALLY GENERATED, EDIT '%s' INSTEAD\n\n",
370 ProjectNode
.GetProjectFilename ().c_str () );
374 MingwBackend::GenerateProjectCFlagsMacro ( const char* assignmentOperation
,
375 const IfableData
& data
) const
377 set
<string
> used_defs
;
379 if ( data
.includes
.size () > 0 )
382 "PROJECT_CFLAGS %s %s\n",
384 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( data
.includes
).c_str ());
386 if ( data
.defines
.size () > 0 )
389 "PROJECT_CDEFINES %s %s\n",
391 MingwModuleHandler::GenerateGccDefineParametersFromVector ( data
.defines
, used_defs
).c_str ());
395 MingwBackend::GenerateGlobalCFlagsAndProperties (
396 const char* assignmentOperation
,
397 const IfableData
& data
) const
401 for ( i
= 0; i
< data
.properties
.size(); i
++ )
403 Property
& prop
= *data
.properties
[i
];
405 if (!prop
.isInternal
)
407 fprintf ( fMakefile
, "%s := %s\n",
409 prop
.value
.c_str() );
413 if ( data
.includes
.size() || data
.defines
.size() )
415 GenerateProjectCFlagsMacro ( assignmentOperation
,
419 for ( i
= 0; i
< data
.ifs
.size(); i
++ )
421 const If
& rIf
= *data
.ifs
[i
];
422 if ( rIf
.data
.defines
.size()
423 || rIf
.data
.includes
.size()
424 || rIf
.data
.ifs
.size() )
428 "ifeq (\"$(%s)\",\"%s\")\n",
429 rIf
.property
.c_str(),
431 GenerateGlobalCFlagsAndProperties (
442 MingwBackend::GenerateProjectGccOptionsMacro ( const char* assignmentOperation
,
443 IfableData
& data
) const
449 "PROJECT_GCCOPTIONS %s",
450 assignmentOperation
);
452 for ( i
= 0; i
< data
.compilerFlags
.size(); i
++ )
454 if ( data
.compilerFlags
[i
]->compiler
== CompilerTypeDontCare
)
459 data
.compilerFlags
[i
]->flag
.c_str() );
463 fprintf ( fMakefile
, "\n" );
467 MingwBackend::GenerateProjectGccOptions (
468 const char* assignmentOperation
,
469 IfableData
& data
) const
473 if ( data
.compilerFlags
.size() )
475 GenerateProjectGccOptionsMacro ( assignmentOperation
,
479 for ( i
= 0; i
< data
.ifs
.size(); i
++ )
481 If
& rIf
= *data
.ifs
[i
];
482 if ( rIf
.data
.compilerFlags
.size()
483 || rIf
.data
.ifs
.size() )
487 "ifeq (\"$(%s)\",\"%s\")\n",
488 rIf
.property
.c_str(),
490 GenerateProjectGccOptions (
501 MingwBackend::GenerateProjectLFLAGS () const
504 for ( size_t i
= 0; i
< ProjectNode
.linkerFlags
.size (); i
++ )
506 LinkerFlag
& linkerFlag
= *ProjectNode
.linkerFlags
[i
];
507 if ( lflags
.length () > 0 )
509 lflags
+= linkerFlag
.flag
;
515 MingwBackend::GenerateGlobalVariables () const
519 compilerPrefix
.c_str () );
522 nasmCommand
.c_str () );
524 GenerateGlobalCFlagsAndProperties ( "=", ProjectNode
.non_if_data
);
525 GenerateProjectGccOptions ( "=", ProjectNode
.non_if_data
);
527 fprintf ( fMakefile
, "PROJECT_RCFLAGS := $(PROJECT_CFLAGS) $(PROJECT_CDEFINES)\n" );
528 fprintf ( fMakefile
, "PROJECT_WIDLFLAGS := $(PROJECT_CFLAGS) $(PROJECT_CDEFINES)\n" );
529 fprintf ( fMakefile
, "PROJECT_LFLAGS := %s\n",
530 GenerateProjectLFLAGS ().c_str () );
531 fprintf ( fMakefile
, "PROJECT_CFLAGS += -Wall\n" );
532 fprintf ( fMakefile
, "ifneq ($(OARCH),)\n" );
533 fprintf ( fMakefile
, "PROJECT_CFLAGS += -march=$(OARCH)\n" );
534 fprintf ( fMakefile
, "endif\n" );
535 fprintf ( fMakefile
, "PROJECT_CFLAGS += $(PROJECT_GCCOPTIONS)\n" );
536 fprintf ( fMakefile
, "\n" );
540 MingwBackend::IncludeInAllTarget ( const Module
& module
) const
542 if ( MingwModuleHandler::ReferenceObjects ( module
) )
544 if ( module
.type
== BootSector
)
546 if ( module
.type
== Iso
)
548 if ( module
.type
== LiveIso
)
550 if ( module
.type
== IsoRegTest
)
552 if ( module
.type
== LiveIsoRegTest
)
554 if ( module
.type
== Test
)
556 if ( module
.type
== Alias
)
562 MingwBackend::GenerateAllTarget ( const vector
<MingwModuleHandler
*>& handlers
) const
564 fprintf ( fMakefile
, "all:" );
566 size_t iend
= handlers
.size ();
567 for ( size_t i
= 0; i
< iend
; i
++ )
569 const Module
& module
= handlers
[i
]->module
;
570 if ( IncludeInAllTarget ( module
) )
572 if ( wrap_count
++ == 5 )
573 fprintf ( fMakefile
, " \\\n\t\t" ), wrap_count
= 0;
576 GetTargetMacro(module
).c_str () );
579 fprintf ( fMakefile
, "\n\t\n\n" );
583 MingwBackend::GenerateRegTestsRunTarget () const
586 "REGTESTS_RUN_TARGET = regtests.dll\n" );
588 "$(REGTESTS_RUN_TARGET): $(REGTESTS_TARGET)\n" );
590 "\t$(cp) $(REGTESTS_TARGET) $(REGTESTS_RUN_TARGET)\n" );
591 fprintf ( fMakefile
, "\n" );
595 MingwBackend::GenerateXmlBuildFilesMacro() const
598 "XMLBUILDFILES = %s \\\n",
599 ProjectNode
.GetProjectFilename ().c_str () );
600 string xmlbuildFilenames
;
601 int numberOfExistingFiles
= 0;
603 time_t SystemTime
, lastWriteTime
;
605 for ( size_t i
= 0; i
< ProjectNode
.xmlbuildfiles
.size (); i
++ )
607 XMLInclude
& xmlbuildfile
= *ProjectNode
.xmlbuildfiles
[i
];
608 if ( !xmlbuildfile
.fileExists
)
610 numberOfExistingFiles
++;
611 if ( xmlbuildFilenames
.length () > 0 )
612 xmlbuildFilenames
+= " ";
614 FILE* f
= fopen ( xmlbuildfile
.topIncludeFilename
.c_str (), "rb" );
616 throw FileNotFoundException ( NormalizeFilename ( xmlbuildfile
.topIncludeFilename
) );
618 if ( fstat ( fileno ( f
), &statbuf
) != 0 )
621 throw AccessDeniedException ( NormalizeFilename ( xmlbuildfile
.topIncludeFilename
) );
624 lastWriteTime
= statbuf
.st_mtime
;
625 SystemTime
= time(NULL
);
627 if (SystemTime
!= -1)
629 if (difftime (lastWriteTime
, SystemTime
) > 0)
630 throw InvalidDateException ( NormalizeFilename ( xmlbuildfile
.topIncludeFilename
) );
635 xmlbuildFilenames
+= NormalizeFilename ( xmlbuildfile
.topIncludeFilename
);
636 if ( numberOfExistingFiles
% 5 == 4 || i
== ProjectNode
.xmlbuildfiles
.size () - 1 )
640 xmlbuildFilenames
.c_str ());
641 if ( i
== ProjectNode
.xmlbuildfiles
.size () - 1 )
643 fprintf ( fMakefile
, "\n" );
650 xmlbuildFilenames
.resize ( 0 );
652 numberOfExistingFiles
++;
654 fprintf ( fMakefile
, "\n" );
658 MingwBackend::GenerateTestSupportCode ()
660 printf ( "Generating test support code..." );
661 TestSupportCode
testSupportCode ( ProjectNode
);
662 testSupportCode
.GenerateTestSupportCode ( configuration
.Verbose
);
667 MingwBackend::GenerateCompilationUnitSupportCode ()
669 if ( configuration
.CompilationUnitsEnabled
)
671 printf ( "Generating compilation unit support code..." );
672 CompilationUnitSupportCode
compilationUnitSupportCode ( ProjectNode
);
673 compilationUnitSupportCode
.Generate ( configuration
.Verbose
);
679 MingwBackend::GenerateSysSetup ()
681 printf ( "Generating syssetup.inf..." );
682 SysSetupGenerator
sysSetupGenerator ( ProjectNode
);
683 sysSetupGenerator
.Generate ();
688 MingwBackend::GetProxyMakefileTree () const
690 if ( configuration
.GenerateProxyMakefilesInSourceTree
)
693 return Environment::GetOutputPath ();
697 MingwBackend::GenerateProxyMakefiles ()
699 printf ( "Generating proxy makefiles..." );
700 ProxyMakefile
proxyMakefile ( ProjectNode
);
701 proxyMakefile
.GenerateProxyMakefiles ( configuration
.Verbose
,
702 GetProxyMakefileTree () );
707 MingwBackend::CheckAutomaticDependencies ()
709 if ( configuration
.AutomaticDependencies
)
711 printf ( "Checking automatic dependencies..." );
712 AutomaticDependency
automaticDependency ( ProjectNode
);
713 automaticDependency
.CheckAutomaticDependencies ( configuration
.Verbose
);
719 MingwBackend::GenerateDirectories ()
721 printf ( "Creating directories..." );
722 intermediateDirectory
->GenerateTree ( IntermediateDirectory
, configuration
.Verbose
);
723 outputDirectory
->GenerateTree ( OutputDirectory
, configuration
.Verbose
);
724 if ( !configuration
.MakeHandlesInstallDirectories
)
725 installDirectory
->GenerateTree ( InstallDirectory
, configuration
.Verbose
);
730 MingwBackend::TryToDetectThisCompiler ( const string
& compiler
)
732 string command
= ssprintf (
734 FixSeparatorForSystemCommand(compiler
).c_str (),
737 int exitcode
= system ( command
.c_str () );
738 return (bool) (exitcode
== 0);
742 MingwBackend::DetectCompiler ()
744 printf ( "Detecting compiler..." );
746 bool detectedCompiler
= false;
747 const string
& ROS_PREFIXValue
= Environment::GetVariable ( "ROS_PREFIX" );
748 if ( ROS_PREFIXValue
.length () > 0 )
750 compilerPrefix
= ROS_PREFIXValue
;
751 compilerCommand
= compilerPrefix
+ "-gcc";
752 detectedCompiler
= TryToDetectThisCompiler ( compilerCommand
);
755 if ( !detectedCompiler
)
758 compilerCommand
= "gcc";
759 detectedCompiler
= TryToDetectThisCompiler ( compilerCommand
);
762 if ( !detectedCompiler
)
764 compilerPrefix
= "mingw32";
765 compilerCommand
= compilerPrefix
+ "-gcc";
766 detectedCompiler
= TryToDetectThisCompiler ( compilerCommand
);
769 if ( detectedCompiler
)
771 string compilerVersion
= GetCompilerVersion ( compilerCommand
);
772 if ( IsSupportedCompilerVersion ( compilerVersion
) )
773 printf ( "detected (%s %s)\n", compilerCommand
.c_str (), compilerVersion
.c_str() );
776 printf ( "detected (%s), but with unsupported version (%s)\n",
777 compilerCommand
.c_str (),
778 compilerVersion
.c_str () );
779 throw UnsupportedBuildToolException ( compilerCommand
, compilerVersion
);
783 printf ( "not detected\n" );
788 MingwBackend::TryToDetectThisNetwideAssembler ( const string
& assembler
)
790 string command
= ssprintf (
792 FixSeparatorForSystemCommand(assembler
).c_str (),
795 int exitcode
= system ( command
.c_str () );
796 return (bool) (exitcode
== 0);
800 MingwBackend::GetVersionString ( const string
& versionCommand
)
807 fp
= popen ( versionCommand
.c_str () , "r" );
810 ( feof ( fp
) == 0 &&
811 ( ( ch
= fgetc( fp
) ) != -1 ) );
814 buffer
[i
] = (char) ch
;
819 char separators
[] = " ";
821 char *prevtoken
= NULL
;
825 token
= strtok ( buffer
, separators
);
826 while ( token
!= NULL
)
829 version
= string( prevtoken
);
830 if ( (newline
= version
.find('\n')) != std::string::npos
)
831 version
.erase(newline
, 1);
832 if ( version
.find('.') != std::string::npos
)
834 token
= strtok ( NULL
, separators
);
840 MingwBackend::GetNetwideAssemblerVersion ( const string
& nasmCommand
)
842 string versionCommand
;
843 if ( nasmCommand
.find("yasm") != std::string::npos
)
845 versionCommand
= ssprintf ( "%s --version",
846 nasmCommand
.c_str (),
852 versionCommand
= ssprintf ( "%s -v",
853 nasmCommand
.c_str (),
857 return GetVersionString( versionCommand
);
861 MingwBackend::GetCompilerVersion ( const string
& compilerCommand
)
863 string versionCommand
= ssprintf ( "%s --version gcc",
864 compilerCommand
.c_str (),
867 return GetVersionString( versionCommand
);
871 MingwBackend::GetBinutilsVersion ( const string
& binutilsCommand
)
873 string versionCommand
= ssprintf ( "%s -v",
874 binutilsCommand
.c_str (),
877 return GetVersionString( versionCommand
);
881 MingwBackend::IsSupportedCompilerVersion ( const string
& compilerVersion
)
883 if ( strcmp ( compilerVersion
.c_str (), "3.4.2") < 0 )
890 MingwBackend::TryToDetectThisBinutils ( const string
& binutils
)
892 string command
= ssprintf (
894 FixSeparatorForSystemCommand(binutils
).c_str (),
897 int exitcode
= system ( command
.c_str () );
898 return (exitcode
== 0);
902 MingwBackend::GetBinutilsVersionDate ( const string
& binutilsCommand
)
908 string versionCommand
= ssprintf ( "%s -v",
909 binutilsCommand
.c_str (),
912 fp
= popen ( versionCommand
.c_str () , "r" );
915 ( feof ( fp
) == 0 &&
916 ( ( ch
= fgetc( fp
) ) != -1 ) );
919 buffer
[i
] = (char) ch
;
924 char separators
[] = " ";
926 char *prevtoken
= NULL
;
928 token
= strtok ( buffer
, separators
);
929 while ( token
!= NULL
)
932 token
= strtok ( NULL
, separators
);
934 string version
= string ( prevtoken
);
935 int lastDigit
= version
.find_last_not_of ( "\t\r\n" );
936 if ( lastDigit
!= -1 )
937 return string ( version
, 0, lastDigit
+1 );
943 MingwBackend::IsSupportedBinutilsVersion ( const string
& binutilsVersion
)
945 if ( manualBinutilsSetting
) return true;
948 if ( binutilsVersion
.find('.') != std::string::npos
)
950 /* TODO: blacklist versions on version number instead of date */
955 * - Binutils older than 2003/10/01 have broken windres which can't handle
956 * icons with alpha channel.
957 * - Binutils between 2004/09/02 and 2004/10/08 have broken handling of
958 * forward exports in dlltool.
960 if ( ( ( strcmp ( binutilsVersion
.c_str (), "20040902") >= 0 ) &&
961 ( strcmp ( binutilsVersion
.c_str (), "20041008") <= 0 ) ) ||
962 ( strcmp ( binutilsVersion
.c_str (), "20031001") < 0 ) )
969 MingwBackend::DetectBinutils ()
971 printf ( "Detecting binutils..." );
973 bool detectedBinutils
= false;
974 const string
& ROS_PREFIXValue
= Environment::GetVariable ( "ROS_PREFIX" );
976 if ( ROS_PREFIXValue
.length () > 0 )
978 binutilsPrefix
= ROS_PREFIXValue
;
979 binutilsCommand
= binutilsPrefix
+ "-ld";
980 manualBinutilsSetting
= true;
981 detectedBinutils
= true;
984 if ( !detectedBinutils
)
987 binutilsCommand
= "ld";
988 detectedBinutils
= TryToDetectThisBinutils ( binutilsCommand
);
991 if ( !detectedBinutils
)
993 binutilsPrefix
= "mingw32";
994 binutilsCommand
= binutilsPrefix
+ "-ld";
995 detectedBinutils
= TryToDetectThisBinutils ( binutilsCommand
);
997 if ( detectedBinutils
)
999 string binutilsVersion
= GetBinutilsVersionDate ( binutilsCommand
);
1000 if ( IsSupportedBinutilsVersion ( binutilsVersion
) )
1001 printf ( "detected (%s %s)\n", binutilsCommand
.c_str (), GetBinutilsVersion( binutilsCommand
).c_str() );
1004 printf ( "detected (%s), but with unsupported version (%s)\n",
1005 binutilsCommand
.c_str (),
1006 binutilsVersion
.c_str () );
1007 throw UnsupportedBuildToolException ( binutilsCommand
, binutilsVersion
);
1011 printf ( "not detected\n" );
1016 MingwBackend::DetectNetwideAssembler ()
1018 printf ( "Detecting netwide assembler..." );
1020 nasmCommand
= "nasm";
1021 bool detectedNasm
= TryToDetectThisNetwideAssembler ( nasmCommand
);
1023 if ( !detectedNasm
)
1025 nasmCommand
= "nasmw";
1026 detectedNasm
= TryToDetectThisNetwideAssembler ( nasmCommand
);
1029 if ( !detectedNasm
)
1031 nasmCommand
= "yasm";
1032 detectedNasm
= TryToDetectThisNetwideAssembler ( nasmCommand
);
1035 printf ( "detected (%s %s)\n", nasmCommand
.c_str (), GetNetwideAssemblerVersion( nasmCommand
).c_str() );
1037 printf ( "not detected\n" );
1041 MingwBackend::DetectPipeSupport ()
1043 printf ( "Detecting compiler -pipe support..." );
1045 string pipe_detection
= "tools" + sSep
+ "rbuild" + sSep
+ "backend" + sSep
+ "mingw" + sSep
+ "pipe_detection.c";
1046 string pipe_detectionObjectFilename
= ReplaceExtension ( pipe_detection
,
1048 string command
= ssprintf (
1049 "%s -pipe -c %s -o %s 1>%s 2>%s",
1050 FixSeparatorForSystemCommand(compilerCommand
).c_str (),
1051 pipe_detection
.c_str (),
1052 pipe_detectionObjectFilename
.c_str (),
1055 int exitcode
= system ( command
.c_str () );
1056 FILE* f
= fopen ( pipe_detectionObjectFilename
.c_str (), "rb" );
1059 usePipe
= (exitcode
== 0);
1061 unlink ( pipe_detectionObjectFilename
.c_str () );
1067 printf ( "detected\n" );
1069 printf ( "not detected\n" );
1073 MingwBackend::DetectPCHSupport ()
1075 printf ( "Detecting compiler pre-compiled header support..." );
1077 string path
= "tools" + sSep
+ "rbuild" + sSep
+ "backend" + sSep
+ "mingw" + sSep
+ "pch_detection.h";
1078 string cmd
= ssprintf (
1079 "%s -c %s 1>%s 2>%s",
1080 FixSeparatorForSystemCommand(compilerCommand
).c_str (),
1084 system ( cmd
.c_str () );
1087 FILE* f
= fopen ( path
.c_str (), "rb" );
1092 unlink ( path
.c_str () );
1098 printf ( "detected\n" );
1100 printf ( "not detected\n" );
1104 MingwBackend::GetNonModuleInstallTargetFiles (
1105 vector
<FileLocation
>& out
) const
1107 for ( size_t i
= 0; i
< ProjectNode
.installfiles
.size (); i
++ )
1109 const InstallFile
& installfile
= *ProjectNode
.installfiles
[i
];
1110 out
.push_back ( *installfile
.target
);
1115 MingwBackend::GetModuleInstallTargetFiles (
1116 vector
<FileLocation
>& out
) const
1118 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
1120 const Module
& module
= *ProjectNode
.modules
[i
];
1121 if ( !module
.enabled
)
1123 if ( module
.install
)
1124 out
.push_back ( *module
.install
);
1129 MingwBackend::GetInstallTargetFiles (
1130 vector
<FileLocation
>& out
) const
1132 GetNonModuleInstallTargetFiles ( out
);
1133 GetModuleInstallTargetFiles ( out
);
1137 MingwBackend::OutputInstallTarget ( const FileLocation
& source
,
1138 const FileLocation
& target
)
1140 fprintf ( fMakefile
,
1142 GetFullName ( target
).c_str (),
1143 GetFullName ( source
).c_str (),
1144 GetFullPath ( target
).c_str () );
1145 fprintf ( fMakefile
,
1147 fprintf ( fMakefile
,
1148 "\t${cp} %s %s 1>$(NUL)\n",
1149 GetFullName ( source
).c_str (),
1150 GetFullName ( target
).c_str () );
1154 MingwBackend::OutputNonModuleInstallTargets ()
1156 for ( size_t i
= 0; i
< ProjectNode
.installfiles
.size (); i
++ )
1158 const InstallFile
& installfile
= *ProjectNode
.installfiles
[i
];
1159 OutputInstallTarget ( *installfile
.source
, *installfile
.target
);
1164 MingwBackend::GetAliasedModuleOrModule ( const Module
& module
) const
1166 if ( module
.aliasedModuleName
.size () > 0 )
1168 const Module
* aliasedModule
= ProjectNode
.LocateModule ( module
.aliasedModuleName
);
1169 assert ( aliasedModule
);
1170 return *aliasedModule
;
1177 MingwBackend::OutputModuleInstallTargets ()
1179 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
1181 const Module
& module
= *ProjectNode
.modules
[i
];
1182 if ( !module
.enabled
)
1184 if ( module
.install
)
1186 const Module
& aliasedModule
= GetAliasedModuleOrModule ( module
);
1187 OutputInstallTarget ( *aliasedModule
.output
, *module
.install
);
1193 MingwBackend::GetRegistrySourceFiles ()
1195 return "boot" + sSep
+ "bootdata" + sSep
+ "hivecls.inf "
1196 "boot" + sSep
+ "bootdata" + sSep
+ "hivedef.inf "
1197 "boot" + sSep
+ "bootdata" + sSep
+ "hiveinst.inf "
1198 "boot" + sSep
+ "bootdata" + sSep
+ "hivesft.inf "
1199 "boot" + sSep
+ "bootdata" + sSep
+ "hivesys.inf";
1203 MingwBackend::GetRegistryTargetFiles ()
1205 string system32ConfigDirectory
= "system32" + sSep
+ "config";
1206 FileLocation
system32 ( InstallDirectory
, system32ConfigDirectory
, "" );
1208 vector
<FileLocation
> registry_files
;
1209 registry_files
.push_back ( FileLocation ( InstallDirectory
, system32ConfigDirectory
, "default" ) );
1210 registry_files
.push_back ( FileLocation ( InstallDirectory
, system32ConfigDirectory
, "sam" ) );
1211 registry_files
.push_back ( FileLocation ( InstallDirectory
, system32ConfigDirectory
, "security" ) );
1212 registry_files
.push_back ( FileLocation ( InstallDirectory
, system32ConfigDirectory
, "software" ) );
1213 registry_files
.push_back ( FileLocation ( InstallDirectory
, system32ConfigDirectory
, "system" ) );
1215 return v2s( this, registry_files
, 6 );
1219 MingwBackend::OutputRegistryInstallTarget ()
1221 FileLocation
system32 ( InstallDirectory
, "system32" + sSep
+ "config", "" );
1223 string registrySourceFiles
= GetRegistrySourceFiles ();
1224 string registryTargetFiles
= GetRegistryTargetFiles ();
1225 fprintf ( fMakefile
,
1226 "install_registry: %s\n",
1227 registryTargetFiles
.c_str () );
1228 fprintf ( fMakefile
,
1229 "%s: %s %s $(MKHIVE_TARGET)\n",
1230 registryTargetFiles
.c_str (),
1231 registrySourceFiles
.c_str (),
1232 GetFullPath ( system32
).c_str () );
1233 fprintf ( fMakefile
,
1234 "\t$(ECHO_MKHIVE)\n" );
1235 fprintf ( fMakefile
,
1236 "\t$(MKHIVE_TARGET) boot%cbootdata %s boot%cbootdata%chiveinst.inf\n",
1237 cSep
, GetFullPath ( system32
).c_str (),
1239 fprintf ( fMakefile
,
1244 MingwBackend::GenerateInstallTarget ()
1246 vector
<FileLocation
> vInstallTargetFiles
;
1247 GetInstallTargetFiles ( vInstallTargetFiles
);
1248 string installTargetFiles
= v2s ( this, vInstallTargetFiles
, 5 );
1249 string registryTargetFiles
= GetRegistryTargetFiles ();
1251 fprintf ( fMakefile
,
1253 installTargetFiles
.c_str (),
1254 registryTargetFiles
.c_str () );
1255 OutputNonModuleInstallTargets ();
1256 OutputModuleInstallTargets ();
1257 OutputRegistryInstallTarget ();
1258 fprintf ( fMakefile
,
1263 MingwBackend::GetModuleTestTargets (
1264 vector
<string
>& out
) const
1266 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
1268 const Module
& module
= *ProjectNode
.modules
[i
];
1269 if ( !module
.enabled
)
1271 if ( module
.type
== Test
)
1272 out
.push_back ( module
.name
);
1277 MingwBackend::GenerateTestTarget ()
1279 vector
<string
> vTestTargets
;
1280 GetModuleTestTargets ( vTestTargets
);
1281 string testTargets
= v2s ( vTestTargets
, 5 );
1283 fprintf ( fMakefile
,
1285 testTargets
.c_str () );
1286 fprintf ( fMakefile
,
1291 MingwBackend::GenerateDirectoryTargets ()
1293 intermediateDirectory
->CreateRule ( fMakefile
, "$(INTERMEDIATE)" );
1294 outputDirectory
->CreateRule ( fMakefile
, "$(OUTPUT)" );
1295 installDirectory
->CreateRule ( fMakefile
, "$(INSTALL)" );