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 ("$(INTERMEDIATE)" ) ),
176 outputDirectory ( new Directory ( "$(OUTPUT)" ) ),
177 installDirectory ( new Directory ( "$(INSTALL)" ) )
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
.files
.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
.files
.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
]->GenerateObjectMacro();
265 fprintf ( fMakefile
, "\n" );
266 for ( i
= 0; i
< iend
; i
++ )
267 v
[i
]->GenerateTargetMacro();
268 fprintf ( fMakefile
, "\n" );
270 GenerateAllTarget ( v
);
271 GenerateInitTarget ();
272 GenerateRegTestsRunTarget ();
274 for ( i
= 0; i
< iend
; i
++ )
275 v
[i
]->GenerateOtherMacros();
277 for ( i
= 0; i
< iend
; i
++ )
279 MingwModuleHandler
& h
= *v
[i
];
280 h
.GeneratePreconditionDependencies ();
282 h
.GenerateInvocations ();
283 h
.GenerateCleanTarget ();
284 h
.GenerateInstallTarget ();
285 h
.GenerateDependsTarget ();
293 MingwBackend::Process ()
295 if ( configuration
.CheckDependenciesForModuleOnly
)
296 CheckAutomaticDependenciesForModuleOnly ();
302 MingwBackend::CheckAutomaticDependenciesForModuleOnly ()
304 if ( configuration
.AutomaticDependencies
)
306 Module
* module
= ProjectNode
.LocateModule ( configuration
.CheckDependenciesForModuleOnlyModule
);
307 if ( module
== NULL
)
309 printf ( "Module '%s' does not exist\n",
310 configuration
.CheckDependenciesForModuleOnlyModule
.c_str () );
314 printf ( "Checking automatic dependencies for module '%s'...",
315 module
->name
.c_str () );
316 AutomaticDependency
automaticDependency ( ProjectNode
);
317 automaticDependency
.CheckAutomaticDependenciesForModule ( *module
,
318 configuration
.Verbose
);
324 MingwBackend::ProcessNormal ()
328 DetectNetwideAssembler ();
329 DetectPipeSupport ();
333 GenerateGlobalVariables ();
334 GenerateXmlBuildFilesMacro ();
335 UnpackWineResources ();
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::GenerateIncludesAndDefines ( IfableData
& data
) const
376 string includeParameters
= MingwModuleHandler::GenerateGccIncludeParametersFromVector ( data
.includes
);
377 string defineParameters
= MingwModuleHandler::GenerateGccDefineParametersFromVector ( data
.defines
);
378 return includeParameters
+ " " + defineParameters
;
382 MingwBackend::GenerateProjectCFlagsMacro ( const char* assignmentOperation
,
383 IfableData
& data
) const
388 assignmentOperation
);
392 GenerateIncludesAndDefines ( data
).c_str() );
394 fprintf ( fMakefile
, "\n" );
398 MingwBackend::GenerateGlobalCFlagsAndProperties (
399 const char* assignmentOperation
,
400 IfableData
& data
) const
404 for ( i
= 0; i
< data
.properties
.size(); i
++ )
406 Property
& prop
= *data
.properties
[i
];
407 fprintf ( fMakefile
, "%s := %s\n",
409 prop
.value
.c_str() );
412 if ( data
.includes
.size() || data
.defines
.size() )
414 GenerateProjectCFlagsMacro ( assignmentOperation
,
418 for ( i
= 0; i
< data
.ifs
.size(); i
++ )
420 If
& rIf
= *data
.ifs
[i
];
421 if ( rIf
.data
.defines
.size()
422 || rIf
.data
.includes
.size()
423 || rIf
.data
.ifs
.size() )
427 "ifeq (\"$(%s)\",\"%s\")\n",
428 rIf
.property
.c_str(),
430 GenerateGlobalCFlagsAndProperties (
441 MingwBackend::GenerateProjectGccOptionsMacro ( const char* assignmentOperation
,
442 IfableData
& data
) const
448 "PROJECT_GCCOPTIONS %s",
449 assignmentOperation
);
451 for ( i
= 0; i
< data
.compilerFlags
.size(); i
++ )
456 data
.compilerFlags
[i
]->flag
.c_str() );
459 fprintf ( fMakefile
, "\n" );
463 MingwBackend::GenerateProjectGccOptions (
464 const char* assignmentOperation
,
465 IfableData
& data
) const
469 if ( data
.compilerFlags
.size() )
471 GenerateProjectGccOptionsMacro ( assignmentOperation
,
475 for ( i
= 0; i
< data
.ifs
.size(); i
++ )
477 If
& rIf
= *data
.ifs
[i
];
478 if ( rIf
.data
.compilerFlags
.size()
479 || rIf
.data
.ifs
.size() )
483 "ifeq (\"$(%s)\",\"%s\")\n",
484 rIf
.property
.c_str(),
486 GenerateProjectGccOptions (
497 MingwBackend::GenerateProjectLFLAGS () const
500 for ( size_t i
= 0; i
< ProjectNode
.linkerFlags
.size (); i
++ )
502 LinkerFlag
& linkerFlag
= *ProjectNode
.linkerFlags
[i
];
503 if ( lflags
.length () > 0 )
505 lflags
+= linkerFlag
.flag
;
511 MingwBackend::GenerateGlobalVariables () const
515 compilerPrefix
.c_str () );
518 nasmCommand
.c_str () );
520 GenerateGlobalCFlagsAndProperties ( "=", ProjectNode
.non_if_data
);
521 GenerateProjectGccOptions ( "=", ProjectNode
.non_if_data
);
523 fprintf ( fMakefile
, "PROJECT_RCFLAGS := $(PROJECT_CFLAGS)\n" );
524 fprintf ( fMakefile
, "PROJECT_WIDLFLAGS := $(PROJECT_CFLAGS)\n" );
525 fprintf ( fMakefile
, "PROJECT_LFLAGS := %s\n",
526 GenerateProjectLFLAGS ().c_str () );
527 fprintf ( fMakefile
, "PROJECT_CFLAGS += -Wall\n" );
528 fprintf ( fMakefile
, "ifneq ($(OARCH),)\n" );
529 fprintf ( fMakefile
, "PROJECT_CFLAGS += -march=$(OARCH)\n" );
530 fprintf ( fMakefile
, "endif\n" );
531 fprintf ( fMakefile
, "PROJECT_CFLAGS += $(PROJECT_GCCOPTIONS)\n" );
532 fprintf ( fMakefile
, "\n" );
536 MingwBackend::IncludeInAllTarget ( const Module
& module
) const
538 if ( MingwModuleHandler::ReferenceObjects ( module
) )
540 if ( module
.type
== BootSector
)
542 if ( module
.type
== Iso
)
544 if ( module
.type
== LiveIso
)
546 if ( module
.type
== IsoRegTest
)
548 if ( module
.type
== LiveIsoRegTest
)
550 if ( module
.type
== Test
)
552 if ( module
.type
== Alias
)
558 MingwBackend::GenerateAllTarget ( const vector
<MingwModuleHandler
*>& handlers
) const
560 fprintf ( fMakefile
, "all:" );
562 size_t iend
= handlers
.size ();
563 for ( size_t i
= 0; i
< iend
; i
++ )
565 const Module
& module
= handlers
[i
]->module
;
566 if ( IncludeInAllTarget ( module
) )
568 if ( wrap_count
++ == 5 )
569 fprintf ( fMakefile
, " \\\n\t\t" ), wrap_count
= 0;
572 GetTargetMacro(module
).c_str () );
575 fprintf ( fMakefile
, "\n\t\n\n" );
579 MingwBackend::GetBuildToolDependencies () const
582 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
584 Module
& module
= *ProjectNode
.modules
[i
];
585 if ( !module
.enabled
)
587 if ( module
.type
== BuildTool
)
589 if ( dependencies
.length () > 0 )
591 dependencies
+= GetFullName ( *module
.dependency
);
598 MingwBackend::GenerateInitTarget () const
602 GetBuildToolDependencies ().c_str () );
603 fprintf ( fMakefile
, "\n" );
607 MingwBackend::GenerateRegTestsRunTarget () const
610 "REGTESTS_RUN_TARGET = regtests.dll\n" );
612 "$(REGTESTS_RUN_TARGET): $(REGTESTS_TARGET)\n" );
614 "\t$(cp) $(REGTESTS_TARGET) $(REGTESTS_RUN_TARGET)\n" );
615 fprintf ( fMakefile
, "\n" );
619 MingwBackend::GenerateXmlBuildFilesMacro() const
622 "XMLBUILDFILES = %s \\\n",
623 ProjectNode
.GetProjectFilename ().c_str () );
624 string xmlbuildFilenames
;
625 int numberOfExistingFiles
= 0;
627 time_t SystemTime
, lastWriteTime
;
629 for ( size_t i
= 0; i
< ProjectNode
.xmlbuildfiles
.size (); i
++ )
631 XMLInclude
& xmlbuildfile
= *ProjectNode
.xmlbuildfiles
[i
];
632 if ( !xmlbuildfile
.fileExists
)
634 numberOfExistingFiles
++;
635 if ( xmlbuildFilenames
.length () > 0 )
636 xmlbuildFilenames
+= " ";
638 FILE* f
= fopen ( xmlbuildfile
.topIncludeFilename
.c_str (), "rb" );
640 throw FileNotFoundException ( NormalizeFilename ( xmlbuildfile
.topIncludeFilename
) );
642 if ( fstat ( fileno ( f
), &statbuf
) != 0 )
645 throw AccessDeniedException ( NormalizeFilename ( xmlbuildfile
.topIncludeFilename
) );
648 lastWriteTime
= statbuf
.st_mtime
;
649 SystemTime
= time(NULL
);
651 if (SystemTime
!= -1)
653 if (difftime (lastWriteTime
, SystemTime
) > 0)
654 throw InvalidDateException ( NormalizeFilename ( xmlbuildfile
.topIncludeFilename
) );
659 xmlbuildFilenames
+= NormalizeFilename ( xmlbuildfile
.topIncludeFilename
);
660 if ( numberOfExistingFiles
% 5 == 4 || i
== ProjectNode
.xmlbuildfiles
.size () - 1 )
664 xmlbuildFilenames
.c_str ());
665 if ( i
== ProjectNode
.xmlbuildfiles
.size () - 1 )
667 fprintf ( fMakefile
, "\n" );
674 xmlbuildFilenames
.resize ( 0 );
676 numberOfExistingFiles
++;
678 fprintf ( fMakefile
, "\n" );
682 MingwBackend::GetBin2ResExecutable ()
684 return NormalizeFilename ( Environment::GetOutputPath () + sSep
+ "tools/bin2res/bin2res" + ExePostfix
);
688 MingwBackend::UnpackWineResources ()
690 printf ( "Unpacking WINE resources..." );
691 WineResource
wineResource ( ProjectNode
,
692 GetBin2ResExecutable () );
693 wineResource
.UnpackResources ( configuration
.Verbose
);
698 MingwBackend::GenerateTestSupportCode ()
700 printf ( "Generating test support code..." );
701 TestSupportCode
testSupportCode ( ProjectNode
);
702 testSupportCode
.GenerateTestSupportCode ( configuration
.Verbose
);
707 MingwBackend::GenerateCompilationUnitSupportCode ()
709 if ( configuration
.CompilationUnitsEnabled
)
711 printf ( "Generating compilation unit support code..." );
712 CompilationUnitSupportCode
compilationUnitSupportCode ( ProjectNode
);
713 compilationUnitSupportCode
.Generate ( configuration
.Verbose
);
719 MingwBackend::GenerateSysSetup ()
721 printf ( "Generating syssetup.inf..." );
722 SysSetupGenerator
sysSetupGenerator ( ProjectNode
);
723 sysSetupGenerator
.Generate ();
728 MingwBackend::GetProxyMakefileTree () const
730 if ( configuration
.GenerateProxyMakefilesInSourceTree
)
733 return Environment::GetOutputPath ();
737 MingwBackend::GenerateProxyMakefiles ()
739 printf ( "Generating proxy makefiles..." );
740 ProxyMakefile
proxyMakefile ( ProjectNode
);
741 proxyMakefile
.GenerateProxyMakefiles ( configuration
.Verbose
,
742 GetProxyMakefileTree () );
747 MingwBackend::CheckAutomaticDependencies ()
749 if ( configuration
.AutomaticDependencies
)
751 printf ( "Checking automatic dependencies..." );
752 AutomaticDependency
automaticDependency ( ProjectNode
);
753 automaticDependency
.CheckAutomaticDependencies ( configuration
.Verbose
);
759 MingwBackend::IncludeDirectoryTarget ( const string
& directory
) const
761 if ( directory
== "$(INTERMEDIATE)" + sSep
+ "tools")
768 MingwBackend::GenerateDirectories ()
770 printf ( "Creating directories..." );
771 intermediateDirectory
->GenerateTree ( "", configuration
.Verbose
);
772 outputDirectory
->GenerateTree ( "", configuration
.Verbose
);
773 if ( !configuration
.MakeHandlesInstallDirectories
)
774 installDirectory
->GenerateTree ( "", configuration
.Verbose
);
779 MingwBackend::TryToDetectThisCompiler ( const string
& compiler
)
781 string command
= ssprintf (
783 FixSeparatorForSystemCommand(compiler
).c_str (),
786 int exitcode
= system ( command
.c_str () );
787 return (bool) (exitcode
== 0);
791 MingwBackend::DetectCompiler ()
793 printf ( "Detecting compiler..." );
795 bool detectedCompiler
= false;
796 const string
& ROS_PREFIXValue
= Environment::GetVariable ( "ROS_PREFIX" );
797 if ( ROS_PREFIXValue
.length () > 0 )
799 compilerPrefix
= ROS_PREFIXValue
;
800 compilerCommand
= compilerPrefix
+ "-gcc";
801 detectedCompiler
= TryToDetectThisCompiler ( compilerCommand
);
804 if ( !detectedCompiler
)
807 compilerCommand
= "gcc";
808 detectedCompiler
= TryToDetectThisCompiler ( compilerCommand
);
811 if ( !detectedCompiler
)
813 compilerPrefix
= "mingw32";
814 compilerCommand
= compilerPrefix
+ "-gcc";
815 detectedCompiler
= TryToDetectThisCompiler ( compilerCommand
);
818 if ( detectedCompiler
)
820 string compilerVersion
= GetCompilerVersion ( compilerCommand
);
821 if ( IsSupportedCompilerVersion ( compilerVersion
) )
822 printf ( "detected (%s %s)\n", compilerCommand
.c_str (), compilerVersion
.c_str() );
825 printf ( "detected (%s), but with unsupported version (%s)\n",
826 compilerCommand
.c_str (),
827 compilerVersion
.c_str () );
828 throw UnsupportedBuildToolException ( compilerCommand
, compilerVersion
);
832 printf ( "not detected\n" );
837 MingwBackend::TryToDetectThisNetwideAssembler ( const string
& assembler
)
839 string command
= ssprintf (
841 FixSeparatorForSystemCommand(assembler
).c_str (),
844 int exitcode
= system ( command
.c_str () );
845 return (bool) (exitcode
== 0);
849 MingwBackend::GetVersionString ( const string
& versionCommand
)
855 fp
= popen ( versionCommand
.c_str () , "r" );
858 ( feof ( fp
) == 0 &&
859 ( ( ch
= fgetc( fp
) ) != -1 ) );
862 buffer
[i
] = (char) ch
;
867 char separators
[] = " ";
869 char *prevtoken
= NULL
;
873 token
= strtok ( buffer
, separators
);
874 while ( token
!= NULL
)
877 version
= string( prevtoken
);
878 if ( version
.find('.') != std::string::npos
)
880 token
= strtok ( NULL
, separators
);
886 MingwBackend::GetNetwideAssemblerVersion ( const string
& nasmCommand
)
888 string versionCommand
;
889 if ( nasmCommand
.find("yasm") != std::string::npos
)
891 versionCommand
= ssprintf ( "%s --version",
892 nasmCommand
.c_str (),
898 versionCommand
= ssprintf ( "%s -v",
899 nasmCommand
.c_str (),
903 return GetVersionString( versionCommand
);
907 MingwBackend::GetCompilerVersion ( const string
& compilerCommand
)
909 string versionCommand
= ssprintf ( "%s --version gcc",
910 compilerCommand
.c_str (),
913 return GetVersionString( versionCommand
);
917 MingwBackend::GetBinutilsVersion ( const string
& binutilsCommand
)
919 string versionCommand
= ssprintf ( "%s -v",
920 binutilsCommand
.c_str (),
923 return GetVersionString( versionCommand
);
927 MingwBackend::IsSupportedCompilerVersion ( const string
& compilerVersion
)
929 if ( strcmp ( compilerVersion
.c_str (), "3.4.2") < 0 )
936 MingwBackend::TryToDetectThisBinutils ( const string
& binutils
)
938 string command
= ssprintf (
940 FixSeparatorForSystemCommand(binutils
).c_str (),
943 int exitcode
= system ( command
.c_str () );
944 return (exitcode
== 0);
948 MingwBackend::GetBinutilsVersionDate ( const string
& binutilsCommand
)
954 string versionCommand
= ssprintf ( "%s -v",
955 binutilsCommand
.c_str (),
958 fp
= popen ( versionCommand
.c_str () , "r" );
961 ( feof ( fp
) == 0 &&
962 ( ( ch
= fgetc( fp
) ) != -1 ) );
965 buffer
[i
] = (char) ch
;
970 char separators
[] = " ";
972 char *prevtoken
= NULL
;
974 token
= strtok ( buffer
, separators
);
975 while ( token
!= NULL
)
978 token
= strtok ( NULL
, separators
);
980 string version
= string ( prevtoken
);
981 int lastDigit
= version
.find_last_not_of ( "\t\r\n" );
982 if ( lastDigit
!= -1 )
983 return string ( version
, 0, lastDigit
+1 );
989 MingwBackend::IsSupportedBinutilsVersion ( const string
& binutilsVersion
)
991 if ( manualBinutilsSetting
) return true;
994 if ( binutilsVersion
.find('.') != std::string::npos
)
996 /* TODO: blacklist versions on version number instead of date */
1001 * - Binutils older than 2003/10/01 have broken windres which can't handle
1002 * icons with alpha channel.
1003 * - Binutils between 2004/09/02 and 2004/10/08 have broken handling of
1004 * forward exports in dlltool.
1006 if ( ( ( strcmp ( binutilsVersion
.c_str (), "20040902") >= 0 ) &&
1007 ( strcmp ( binutilsVersion
.c_str (), "20041008") <= 0 ) ) ||
1008 ( strcmp ( binutilsVersion
.c_str (), "20031001") < 0 ) )
1015 MingwBackend::DetectBinutils ()
1017 printf ( "Detecting binutils..." );
1019 bool detectedBinutils
= false;
1020 const string
& ROS_PREFIXValue
= Environment::GetVariable ( "ROS_PREFIX" );
1022 if ( ROS_PREFIXValue
.length () > 0 )
1024 binutilsPrefix
= ROS_PREFIXValue
;
1025 binutilsCommand
= binutilsPrefix
+ "-ld";
1026 manualBinutilsSetting
= true;
1027 detectedBinutils
= true;
1030 if ( !detectedBinutils
)
1032 binutilsPrefix
= "";
1033 binutilsCommand
= "ld";
1034 detectedBinutils
= TryToDetectThisBinutils ( binutilsCommand
);
1037 if ( !detectedBinutils
)
1039 binutilsPrefix
= "mingw32";
1040 binutilsCommand
= binutilsPrefix
+ "-ld";
1041 detectedBinutils
= TryToDetectThisBinutils ( binutilsCommand
);
1043 if ( detectedBinutils
)
1045 string binutilsVersion
= GetBinutilsVersionDate ( binutilsCommand
);
1046 if ( IsSupportedBinutilsVersion ( binutilsVersion
) )
1047 printf ( "detected (%s %s)\n", binutilsCommand
.c_str (), GetBinutilsVersion( binutilsCommand
).c_str() );
1050 printf ( "detected (%s), but with unsupported version (%s)\n",
1051 binutilsCommand
.c_str (),
1052 binutilsVersion
.c_str () );
1053 throw UnsupportedBuildToolException ( binutilsCommand
, binutilsVersion
);
1057 printf ( "not detected\n" );
1062 MingwBackend::DetectNetwideAssembler ()
1064 printf ( "Detecting netwide assembler..." );
1066 nasmCommand
= "nasm";
1067 bool detectedNasm
= TryToDetectThisNetwideAssembler ( nasmCommand
);
1069 if ( !detectedNasm
)
1071 nasmCommand
= "nasmw";
1072 detectedNasm
= TryToDetectThisNetwideAssembler ( nasmCommand
);
1075 if ( !detectedNasm
)
1077 nasmCommand
= "yasm";
1078 detectedNasm
= TryToDetectThisNetwideAssembler ( nasmCommand
);
1081 printf ( "detected (%s %s)\n", nasmCommand
.c_str (), GetNetwideAssemblerVersion( nasmCommand
).c_str() );
1083 printf ( "not detected\n" );
1087 MingwBackend::DetectPipeSupport ()
1089 printf ( "Detecting compiler -pipe support..." );
1091 string pipe_detection
= "tools" + sSep
+ "rbuild" + sSep
+ "backend" + sSep
+ "mingw" + sSep
+ "pipe_detection.c";
1092 string pipe_detectionObjectFilename
= ReplaceExtension ( pipe_detection
,
1094 string command
= ssprintf (
1095 "%s -pipe -c %s -o %s 1>%s 2>%s",
1096 FixSeparatorForSystemCommand(compilerCommand
).c_str (),
1097 pipe_detection
.c_str (),
1098 pipe_detectionObjectFilename
.c_str (),
1101 int exitcode
= system ( command
.c_str () );
1102 FILE* f
= fopen ( pipe_detectionObjectFilename
.c_str (), "rb" );
1105 usePipe
= (exitcode
== 0);
1107 unlink ( pipe_detectionObjectFilename
.c_str () );
1113 printf ( "detected\n" );
1115 printf ( "not detected\n" );
1119 MingwBackend::DetectPCHSupport ()
1121 printf ( "Detecting compiler pre-compiled header support..." );
1123 string path
= "tools" + sSep
+ "rbuild" + sSep
+ "backend" + sSep
+ "mingw" + sSep
+ "pch_detection.h";
1124 string cmd
= ssprintf (
1125 "%s -c %s 1>%s 2>%s",
1126 FixSeparatorForSystemCommand(compilerCommand
).c_str (),
1130 system ( cmd
.c_str () );
1133 FILE* f
= fopen ( path
.c_str (), "rb" );
1138 unlink ( path
.c_str () );
1144 printf ( "detected\n" );
1146 printf ( "not detected\n" );
1150 MingwBackend::GetNonModuleInstallTargetFiles (
1151 vector
<FileLocation
>& out
) const
1153 for ( size_t i
= 0; i
< ProjectNode
.installfiles
.size (); i
++ )
1155 const InstallFile
& installfile
= *ProjectNode
.installfiles
[i
];
1156 out
.push_back ( *installfile
.target
);
1161 MingwBackend::GetModuleInstallTargetFiles (
1162 vector
<FileLocation
>& out
) const
1164 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
1166 const Module
& module
= *ProjectNode
.modules
[i
];
1167 if ( !module
.enabled
)
1169 if ( module
.install
)
1170 out
.push_back ( *module
.install
);
1175 MingwBackend::GetInstallTargetFiles (
1176 vector
<FileLocation
>& out
) const
1178 GetNonModuleInstallTargetFiles ( out
);
1179 GetModuleInstallTargetFiles ( out
);
1183 MingwBackend::OutputInstallTarget ( const FileLocation
& source
,
1184 const FileLocation
& target
)
1186 fprintf ( fMakefile
,
1188 GetFullName ( target
).c_str (),
1189 GetFullName ( source
).c_str (),
1190 GetFullPath ( target
).c_str () );
1191 fprintf ( fMakefile
,
1193 fprintf ( fMakefile
,
1194 "\t${cp} %s %s 1>$(NUL)\n",
1195 GetFullName ( source
).c_str (),
1196 GetFullName ( target
).c_str () );
1200 MingwBackend::OutputNonModuleInstallTargets ()
1202 for ( size_t i
= 0; i
< ProjectNode
.installfiles
.size (); i
++ )
1204 const InstallFile
& installfile
= *ProjectNode
.installfiles
[i
];
1205 OutputInstallTarget ( *installfile
.source
, *installfile
.target
);
1210 MingwBackend::GetAliasedModuleOrModule ( const Module
& module
) const
1212 if ( module
.aliasedModuleName
.size () > 0 )
1214 const Module
* aliasedModule
= ProjectNode
.LocateModule ( module
.aliasedModuleName
);
1215 assert ( aliasedModule
);
1216 return *aliasedModule
;
1223 MingwBackend::OutputModuleInstallTargets ()
1225 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
1227 const Module
& module
= *ProjectNode
.modules
[i
];
1228 if ( !module
.enabled
)
1230 if ( module
.install
)
1232 const Module
& aliasedModule
= GetAliasedModuleOrModule ( module
);
1233 OutputInstallTarget ( *aliasedModule
.output
, *module
.install
);
1239 MingwBackend::GetRegistrySourceFiles ()
1241 return "boot" + sSep
+ "bootdata" + sSep
+ "hivecls.inf "
1242 "boot" + sSep
+ "bootdata" + sSep
+ "hivedef.inf "
1243 "boot" + sSep
+ "bootdata" + sSep
+ "hiveinst.inf "
1244 "boot" + sSep
+ "bootdata" + sSep
+ "hivesft.inf "
1245 "boot" + sSep
+ "bootdata" + sSep
+ "hivesys.inf";
1249 MingwBackend::GetRegistryTargetFiles ()
1251 string system32ConfigDirectory
= "system32" + sSep
+ "config";
1252 FileLocation
system32 ( InstallDirectory
, system32ConfigDirectory
, "" );
1254 vector
<FileLocation
> registry_files
;
1255 registry_files
.push_back ( FileLocation ( InstallDirectory
, system32ConfigDirectory
, "default" ) );
1256 registry_files
.push_back ( FileLocation ( InstallDirectory
, system32ConfigDirectory
, "sam" ) );
1257 registry_files
.push_back ( FileLocation ( InstallDirectory
, system32ConfigDirectory
, "security" ) );
1258 registry_files
.push_back ( FileLocation ( InstallDirectory
, system32ConfigDirectory
, "software" ) );
1259 registry_files
.push_back ( FileLocation ( InstallDirectory
, system32ConfigDirectory
, "system" ) );
1261 return v2s( this, registry_files
, 6 );
1265 MingwBackend::OutputRegistryInstallTarget ()
1267 FileLocation
system32 ( InstallDirectory
, "system32" + sSep
+ "config", "" );
1269 string registrySourceFiles
= GetRegistrySourceFiles ();
1270 string registryTargetFiles
= GetRegistryTargetFiles ();
1271 fprintf ( fMakefile
,
1272 "install_registry: %s\n",
1273 registryTargetFiles
.c_str () );
1274 fprintf ( fMakefile
,
1275 "%s: %s %s $(MKHIVE_TARGET)\n",
1276 registryTargetFiles
.c_str (),
1277 registrySourceFiles
.c_str (),
1278 GetFullPath ( system32
).c_str () );
1279 fprintf ( fMakefile
,
1280 "\t$(ECHO_MKHIVE)\n" );
1281 fprintf ( fMakefile
,
1282 "\t$(MKHIVE_TARGET) boot%cbootdata %s boot%cbootdata%chiveinst.inf\n",
1283 cSep
, GetFullPath ( system32
).c_str (),
1285 fprintf ( fMakefile
,
1290 MingwBackend::GenerateInstallTarget ()
1292 vector
<FileLocation
> vInstallTargetFiles
;
1293 GetInstallTargetFiles ( vInstallTargetFiles
);
1294 string installTargetFiles
= v2s ( this, vInstallTargetFiles
, 5 );
1295 string registryTargetFiles
= GetRegistryTargetFiles ();
1297 fprintf ( fMakefile
,
1299 installTargetFiles
.c_str (),
1300 registryTargetFiles
.c_str () );
1301 OutputNonModuleInstallTargets ();
1302 OutputModuleInstallTargets ();
1303 OutputRegistryInstallTarget ();
1304 fprintf ( fMakefile
,
1309 MingwBackend::GetModuleTestTargets (
1310 vector
<string
>& out
) const
1312 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
1314 const Module
& module
= *ProjectNode
.modules
[i
];
1315 if ( !module
.enabled
)
1317 if ( module
.type
== Test
)
1318 out
.push_back ( module
.name
);
1323 MingwBackend::GenerateTestTarget ()
1325 vector
<string
> vTestTargets
;
1326 GetModuleTestTargets ( vTestTargets
);
1327 string testTargets
= v2s ( vTestTargets
, 5 );
1329 fprintf ( fMakefile
,
1331 testTargets
.c_str () );
1332 fprintf ( fMakefile
,
1337 MingwBackend::GenerateDirectoryTargets ()
1339 intermediateDirectory
->CreateRule ( fMakefile
, "" );
1340 outputDirectory
->CreateRule ( fMakefile
, "" );
1341 installDirectory
->CreateRule ( fMakefile
, "" );