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
.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
]->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 GenerateInitTarget ();
274 GenerateRegTestsRunTarget ();
276 for ( i
= 0; i
< iend
; i
++ )
277 v
[i
]->GenerateOtherMacros();
279 for ( i
= 0; i
< iend
; i
++ )
281 MingwModuleHandler
& h
= *v
[i
];
282 h
.GeneratePreconditionDependencies ();
284 h
.GenerateInvocations ();
285 h
.GenerateCleanTarget ();
286 h
.GenerateInstallTarget ();
287 h
.GenerateDependsTarget ();
295 MingwBackend::Process ()
297 if ( configuration
.CheckDependenciesForModuleOnly
)
298 CheckAutomaticDependenciesForModuleOnly ();
304 MingwBackend::CheckAutomaticDependenciesForModuleOnly ()
306 if ( configuration
.AutomaticDependencies
)
308 Module
* module
= ProjectNode
.LocateModule ( configuration
.CheckDependenciesForModuleOnlyModule
);
309 if ( module
== NULL
)
311 printf ( "Module '%s' does not exist\n",
312 configuration
.CheckDependenciesForModuleOnlyModule
.c_str () );
316 printf ( "Checking automatic dependencies for module '%s'...",
317 module
->name
.c_str () );
318 AutomaticDependency
automaticDependency ( ProjectNode
);
319 automaticDependency
.CheckAutomaticDependenciesForModule ( *module
,
320 configuration
.Verbose
);
326 MingwBackend::ProcessNormal ()
330 DetectNetwideAssembler ();
331 DetectPipeSupport ();
335 GenerateGlobalVariables ();
336 GenerateXmlBuildFilesMacro ();
337 UnpackWineResources ();
339 GenerateInstallTarget ();
340 GenerateTestTarget ();
341 GenerateDirectoryTargets ();
342 GenerateDirectories ();
343 GenerateTestSupportCode ();
344 GenerateCompilationUnitSupportCode ();
346 GenerateProxyMakefiles ();
347 CheckAutomaticDependencies ();
352 MingwBackend::CreateMakefile ()
354 fMakefile
= fopen ( ProjectNode
.makefile
.c_str (), "w" );
356 throw AccessDeniedException ( ProjectNode
.makefile
);
357 MingwModuleHandler::SetBackend ( this );
358 MingwModuleHandler::SetMakefile ( fMakefile
);
362 MingwBackend::CloseMakefile () const
365 fclose ( fMakefile
);
369 MingwBackend::GenerateHeader () const
371 fprintf ( fMakefile
, "# THIS FILE IS AUTOMATICALLY GENERATED, EDIT '%s' INSTEAD\n\n",
372 ProjectNode
.GetProjectFilename ().c_str () );
376 MingwBackend::GenerateProjectCFlagsMacro ( const char* assignmentOperation
,
377 const IfableData
& data
) const
379 set
<string
> used_defs
;
381 if ( data
.includes
.size () > 0 )
384 "PROJECT_CFLAGS %s %s\n",
386 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( data
.includes
).c_str ());
388 if ( data
.defines
.size () > 0 )
391 "PROJECT_CDEFINES %s %s\n",
393 MingwModuleHandler::GenerateGccDefineParametersFromVector ( data
.defines
, used_defs
).c_str ());
397 MingwBackend::GenerateGlobalCFlagsAndProperties (
398 const char* assignmentOperation
,
399 const IfableData
& data
) const
403 for ( i
= 0; i
< data
.properties
.size(); i
++ )
405 Property
& prop
= *data
.properties
[i
];
406 fprintf ( fMakefile
, "%s := %s\n",
408 prop
.value
.c_str() );
411 if ( data
.includes
.size() || data
.defines
.size() )
413 GenerateProjectCFlagsMacro ( assignmentOperation
,
417 for ( i
= 0; i
< data
.ifs
.size(); i
++ )
419 const If
& rIf
= *data
.ifs
[i
];
420 if ( rIf
.data
.defines
.size()
421 || rIf
.data
.includes
.size()
422 || rIf
.data
.ifs
.size() )
426 "ifeq (\"$(%s)\",\"%s\")\n",
427 rIf
.property
.c_str(),
429 GenerateGlobalCFlagsAndProperties (
440 MingwBackend::GenerateProjectGccOptionsMacro ( const char* assignmentOperation
,
441 IfableData
& data
) const
447 "PROJECT_GCCOPTIONS %s",
448 assignmentOperation
);
450 for ( i
= 0; i
< data
.compilerFlags
.size(); i
++ )
455 data
.compilerFlags
[i
]->flag
.c_str() );
458 fprintf ( fMakefile
, "\n" );
462 MingwBackend::GenerateProjectGccOptions (
463 const char* assignmentOperation
,
464 IfableData
& data
) const
468 if ( data
.compilerFlags
.size() )
470 GenerateProjectGccOptionsMacro ( assignmentOperation
,
474 for ( i
= 0; i
< data
.ifs
.size(); i
++ )
476 If
& rIf
= *data
.ifs
[i
];
477 if ( rIf
.data
.compilerFlags
.size()
478 || rIf
.data
.ifs
.size() )
482 "ifeq (\"$(%s)\",\"%s\")\n",
483 rIf
.property
.c_str(),
485 GenerateProjectGccOptions (
496 MingwBackend::GenerateProjectLFLAGS () const
499 for ( size_t i
= 0; i
< ProjectNode
.linkerFlags
.size (); i
++ )
501 LinkerFlag
& linkerFlag
= *ProjectNode
.linkerFlags
[i
];
502 if ( lflags
.length () > 0 )
504 lflags
+= linkerFlag
.flag
;
510 MingwBackend::GenerateGlobalVariables () const
514 compilerPrefix
.c_str () );
517 nasmCommand
.c_str () );
519 GenerateGlobalCFlagsAndProperties ( "=", ProjectNode
.non_if_data
);
520 GenerateProjectGccOptions ( "=", ProjectNode
.non_if_data
);
522 fprintf ( fMakefile
, "PROJECT_RCFLAGS := $(PROJECT_CFLAGS) $(PROJECT_CDEFINES)\n" );
523 fprintf ( fMakefile
, "PROJECT_WIDLFLAGS := $(PROJECT_CFLAGS) $(PROJECT_CDEFINES)\n" );
524 fprintf ( fMakefile
, "PROJECT_LFLAGS := %s\n",
525 GenerateProjectLFLAGS ().c_str () );
526 fprintf ( fMakefile
, "PROJECT_CFLAGS += -Wall\n" );
527 fprintf ( fMakefile
, "ifneq ($(OARCH),)\n" );
528 fprintf ( fMakefile
, "PROJECT_CFLAGS += -march=$(OARCH)\n" );
529 fprintf ( fMakefile
, "endif\n" );
530 fprintf ( fMakefile
, "PROJECT_CFLAGS += $(PROJECT_GCCOPTIONS)\n" );
531 fprintf ( fMakefile
, "\n" );
535 MingwBackend::IncludeInAllTarget ( const Module
& module
) const
537 if ( MingwModuleHandler::ReferenceObjects ( module
) )
539 if ( module
.type
== BootSector
)
541 if ( module
.type
== Iso
)
543 if ( module
.type
== LiveIso
)
545 if ( module
.type
== IsoRegTest
)
547 if ( module
.type
== LiveIsoRegTest
)
549 if ( module
.type
== Test
)
551 if ( module
.type
== Alias
)
557 MingwBackend::GenerateAllTarget ( const vector
<MingwModuleHandler
*>& handlers
) const
559 fprintf ( fMakefile
, "all:" );
561 size_t iend
= handlers
.size ();
562 for ( size_t i
= 0; i
< iend
; i
++ )
564 const Module
& module
= handlers
[i
]->module
;
565 if ( IncludeInAllTarget ( module
) )
567 if ( wrap_count
++ == 5 )
568 fprintf ( fMakefile
, " \\\n\t\t" ), wrap_count
= 0;
571 GetTargetMacro(module
).c_str () );
574 fprintf ( fMakefile
, "\n\t\n\n" );
578 MingwBackend::GetBuildToolDependencies () const
581 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
583 Module
& module
= *ProjectNode
.modules
[i
];
584 if ( !module
.enabled
)
586 if ( module
.type
== BuildTool
)
588 if ( dependencies
.length () > 0 )
590 dependencies
+= GetFullName ( *module
.dependency
);
597 MingwBackend::GenerateInitTarget () const
601 GetBuildToolDependencies ().c_str () );
602 fprintf ( fMakefile
, "\n" );
606 MingwBackend::GenerateRegTestsRunTarget () const
609 "REGTESTS_RUN_TARGET = regtests.dll\n" );
611 "$(REGTESTS_RUN_TARGET): $(REGTESTS_TARGET)\n" );
613 "\t$(cp) $(REGTESTS_TARGET) $(REGTESTS_RUN_TARGET)\n" );
614 fprintf ( fMakefile
, "\n" );
618 MingwBackend::GenerateXmlBuildFilesMacro() const
621 "XMLBUILDFILES = %s \\\n",
622 ProjectNode
.GetProjectFilename ().c_str () );
623 string xmlbuildFilenames
;
624 int numberOfExistingFiles
= 0;
626 time_t SystemTime
, lastWriteTime
;
628 for ( size_t i
= 0; i
< ProjectNode
.xmlbuildfiles
.size (); i
++ )
630 XMLInclude
& xmlbuildfile
= *ProjectNode
.xmlbuildfiles
[i
];
631 if ( !xmlbuildfile
.fileExists
)
633 numberOfExistingFiles
++;
634 if ( xmlbuildFilenames
.length () > 0 )
635 xmlbuildFilenames
+= " ";
637 FILE* f
= fopen ( xmlbuildfile
.topIncludeFilename
.c_str (), "rb" );
639 throw FileNotFoundException ( NormalizeFilename ( xmlbuildfile
.topIncludeFilename
) );
641 if ( fstat ( fileno ( f
), &statbuf
) != 0 )
644 throw AccessDeniedException ( NormalizeFilename ( xmlbuildfile
.topIncludeFilename
) );
647 lastWriteTime
= statbuf
.st_mtime
;
648 SystemTime
= time(NULL
);
650 if (SystemTime
!= -1)
652 if (difftime (lastWriteTime
, SystemTime
) > 0)
653 throw InvalidDateException ( NormalizeFilename ( xmlbuildfile
.topIncludeFilename
) );
658 xmlbuildFilenames
+= NormalizeFilename ( xmlbuildfile
.topIncludeFilename
);
659 if ( numberOfExistingFiles
% 5 == 4 || i
== ProjectNode
.xmlbuildfiles
.size () - 1 )
663 xmlbuildFilenames
.c_str ());
664 if ( i
== ProjectNode
.xmlbuildfiles
.size () - 1 )
666 fprintf ( fMakefile
, "\n" );
673 xmlbuildFilenames
.resize ( 0 );
675 numberOfExistingFiles
++;
677 fprintf ( fMakefile
, "\n" );
681 MingwBackend::GetBin2ResExecutable ()
683 return NormalizeFilename ( Environment::GetOutputPath () + sSep
+ "tools/bin2res/bin2res" + ExePostfix
);
687 MingwBackend::UnpackWineResources ()
689 printf ( "Unpacking WINE resources..." );
690 WineResource
wineResource ( ProjectNode
,
691 GetBin2ResExecutable () );
692 wineResource
.UnpackResources ( configuration
.Verbose
);
697 MingwBackend::GenerateTestSupportCode ()
699 printf ( "Generating test support code..." );
700 TestSupportCode
testSupportCode ( ProjectNode
);
701 testSupportCode
.GenerateTestSupportCode ( configuration
.Verbose
);
706 MingwBackend::GenerateCompilationUnitSupportCode ()
708 if ( configuration
.CompilationUnitsEnabled
)
710 printf ( "Generating compilation unit support code..." );
711 CompilationUnitSupportCode
compilationUnitSupportCode ( ProjectNode
);
712 compilationUnitSupportCode
.Generate ( configuration
.Verbose
);
718 MingwBackend::GenerateSysSetup ()
720 printf ( "Generating syssetup.inf..." );
721 SysSetupGenerator
sysSetupGenerator ( ProjectNode
);
722 sysSetupGenerator
.Generate ();
727 MingwBackend::GetProxyMakefileTree () const
729 if ( configuration
.GenerateProxyMakefilesInSourceTree
)
732 return Environment::GetOutputPath ();
736 MingwBackend::GenerateProxyMakefiles ()
738 printf ( "Generating proxy makefiles..." );
739 ProxyMakefile
proxyMakefile ( ProjectNode
);
740 proxyMakefile
.GenerateProxyMakefiles ( configuration
.Verbose
,
741 GetProxyMakefileTree () );
746 MingwBackend::CheckAutomaticDependencies ()
748 if ( configuration
.AutomaticDependencies
)
750 printf ( "Checking automatic dependencies..." );
751 AutomaticDependency
automaticDependency ( ProjectNode
);
752 automaticDependency
.CheckAutomaticDependencies ( configuration
.Verbose
);
758 MingwBackend::GenerateDirectories ()
760 printf ( "Creating directories..." );
761 intermediateDirectory
->GenerateTree ( IntermediateDirectory
, configuration
.Verbose
);
762 outputDirectory
->GenerateTree ( OutputDirectory
, configuration
.Verbose
);
763 if ( !configuration
.MakeHandlesInstallDirectories
)
764 installDirectory
->GenerateTree ( InstallDirectory
, configuration
.Verbose
);
769 MingwBackend::TryToDetectThisCompiler ( const string
& compiler
)
771 string command
= ssprintf (
773 FixSeparatorForSystemCommand(compiler
).c_str (),
776 int exitcode
= system ( command
.c_str () );
777 return (bool) (exitcode
== 0);
781 MingwBackend::DetectCompiler ()
783 printf ( "Detecting compiler..." );
785 bool detectedCompiler
= false;
786 const string
& ROS_PREFIXValue
= Environment::GetVariable ( "ROS_PREFIX" );
787 if ( ROS_PREFIXValue
.length () > 0 )
789 compilerPrefix
= ROS_PREFIXValue
;
790 compilerCommand
= compilerPrefix
+ "-gcc";
791 detectedCompiler
= TryToDetectThisCompiler ( compilerCommand
);
794 if ( !detectedCompiler
)
797 compilerCommand
= "gcc";
798 detectedCompiler
= TryToDetectThisCompiler ( compilerCommand
);
801 if ( !detectedCompiler
)
803 compilerPrefix
= "mingw32";
804 compilerCommand
= compilerPrefix
+ "-gcc";
805 detectedCompiler
= TryToDetectThisCompiler ( compilerCommand
);
808 if ( detectedCompiler
)
810 string compilerVersion
= GetCompilerVersion ( compilerCommand
);
811 if ( IsSupportedCompilerVersion ( compilerVersion
) )
812 printf ( "detected (%s %s)\n", compilerCommand
.c_str (), compilerVersion
.c_str() );
815 printf ( "detected (%s), but with unsupported version (%s)\n",
816 compilerCommand
.c_str (),
817 compilerVersion
.c_str () );
818 throw UnsupportedBuildToolException ( compilerCommand
, compilerVersion
);
822 printf ( "not detected\n" );
827 MingwBackend::TryToDetectThisNetwideAssembler ( const string
& assembler
)
829 string command
= ssprintf (
831 FixSeparatorForSystemCommand(assembler
).c_str (),
834 int exitcode
= system ( command
.c_str () );
835 return (bool) (exitcode
== 0);
839 MingwBackend::GetVersionString ( const string
& versionCommand
)
845 fp
= popen ( versionCommand
.c_str () , "r" );
848 ( feof ( fp
) == 0 &&
849 ( ( ch
= fgetc( fp
) ) != -1 ) );
852 buffer
[i
] = (char) ch
;
857 char separators
[] = " ";
859 char *prevtoken
= NULL
;
863 token
= strtok ( buffer
, separators
);
864 while ( token
!= NULL
)
867 version
= string( prevtoken
);
868 if ( version
.find('.') != std::string::npos
)
870 token
= strtok ( NULL
, separators
);
876 MingwBackend::GetNetwideAssemblerVersion ( const string
& nasmCommand
)
878 string versionCommand
;
879 if ( nasmCommand
.find("yasm") != std::string::npos
)
881 versionCommand
= ssprintf ( "%s --version",
882 nasmCommand
.c_str (),
888 versionCommand
= ssprintf ( "%s -v",
889 nasmCommand
.c_str (),
893 return GetVersionString( versionCommand
);
897 MingwBackend::GetCompilerVersion ( const string
& compilerCommand
)
899 string versionCommand
= ssprintf ( "%s --version gcc",
900 compilerCommand
.c_str (),
903 return GetVersionString( versionCommand
);
907 MingwBackend::GetBinutilsVersion ( const string
& binutilsCommand
)
909 string versionCommand
= ssprintf ( "%s -v",
910 binutilsCommand
.c_str (),
913 return GetVersionString( versionCommand
);
917 MingwBackend::IsSupportedCompilerVersion ( const string
& compilerVersion
)
919 if ( strcmp ( compilerVersion
.c_str (), "3.4.2") < 0 )
926 MingwBackend::TryToDetectThisBinutils ( const string
& binutils
)
928 string command
= ssprintf (
930 FixSeparatorForSystemCommand(binutils
).c_str (),
933 int exitcode
= system ( command
.c_str () );
934 return (exitcode
== 0);
938 MingwBackend::GetBinutilsVersionDate ( const string
& binutilsCommand
)
944 string versionCommand
= ssprintf ( "%s -v",
945 binutilsCommand
.c_str (),
948 fp
= popen ( versionCommand
.c_str () , "r" );
951 ( feof ( fp
) == 0 &&
952 ( ( ch
= fgetc( fp
) ) != -1 ) );
955 buffer
[i
] = (char) ch
;
960 char separators
[] = " ";
962 char *prevtoken
= NULL
;
964 token
= strtok ( buffer
, separators
);
965 while ( token
!= NULL
)
968 token
= strtok ( NULL
, separators
);
970 string version
= string ( prevtoken
);
971 int lastDigit
= version
.find_last_not_of ( "\t\r\n" );
972 if ( lastDigit
!= -1 )
973 return string ( version
, 0, lastDigit
+1 );
979 MingwBackend::IsSupportedBinutilsVersion ( const string
& binutilsVersion
)
981 if ( manualBinutilsSetting
) return true;
984 if ( binutilsVersion
.find('.') != std::string::npos
)
986 /* TODO: blacklist versions on version number instead of date */
991 * - Binutils older than 2003/10/01 have broken windres which can't handle
992 * icons with alpha channel.
993 * - Binutils between 2004/09/02 and 2004/10/08 have broken handling of
994 * forward exports in dlltool.
996 if ( ( ( strcmp ( binutilsVersion
.c_str (), "20040902") >= 0 ) &&
997 ( strcmp ( binutilsVersion
.c_str (), "20041008") <= 0 ) ) ||
998 ( strcmp ( binutilsVersion
.c_str (), "20031001") < 0 ) )
1005 MingwBackend::DetectBinutils ()
1007 printf ( "Detecting binutils..." );
1009 bool detectedBinutils
= false;
1010 const string
& ROS_PREFIXValue
= Environment::GetVariable ( "ROS_PREFIX" );
1012 if ( ROS_PREFIXValue
.length () > 0 )
1014 binutilsPrefix
= ROS_PREFIXValue
;
1015 binutilsCommand
= binutilsPrefix
+ "-ld";
1016 manualBinutilsSetting
= true;
1017 detectedBinutils
= true;
1020 if ( !detectedBinutils
)
1022 binutilsPrefix
= "";
1023 binutilsCommand
= "ld";
1024 detectedBinutils
= TryToDetectThisBinutils ( binutilsCommand
);
1027 if ( !detectedBinutils
)
1029 binutilsPrefix
= "mingw32";
1030 binutilsCommand
= binutilsPrefix
+ "-ld";
1031 detectedBinutils
= TryToDetectThisBinutils ( binutilsCommand
);
1033 if ( detectedBinutils
)
1035 string binutilsVersion
= GetBinutilsVersionDate ( binutilsCommand
);
1036 if ( IsSupportedBinutilsVersion ( binutilsVersion
) )
1037 printf ( "detected (%s %s)\n", binutilsCommand
.c_str (), GetBinutilsVersion( binutilsCommand
).c_str() );
1040 printf ( "detected (%s), but with unsupported version (%s)\n",
1041 binutilsCommand
.c_str (),
1042 binutilsVersion
.c_str () );
1043 throw UnsupportedBuildToolException ( binutilsCommand
, binutilsVersion
);
1047 printf ( "not detected\n" );
1052 MingwBackend::DetectNetwideAssembler ()
1054 printf ( "Detecting netwide assembler..." );
1056 nasmCommand
= "nasm";
1057 bool detectedNasm
= TryToDetectThisNetwideAssembler ( nasmCommand
);
1059 if ( !detectedNasm
)
1061 nasmCommand
= "nasmw";
1062 detectedNasm
= TryToDetectThisNetwideAssembler ( nasmCommand
);
1065 if ( !detectedNasm
)
1067 nasmCommand
= "yasm";
1068 detectedNasm
= TryToDetectThisNetwideAssembler ( nasmCommand
);
1071 printf ( "detected (%s %s)\n", nasmCommand
.c_str (), GetNetwideAssemblerVersion( nasmCommand
).c_str() );
1073 printf ( "not detected\n" );
1077 MingwBackend::DetectPipeSupport ()
1079 printf ( "Detecting compiler -pipe support..." );
1081 string pipe_detection
= "tools" + sSep
+ "rbuild" + sSep
+ "backend" + sSep
+ "mingw" + sSep
+ "pipe_detection.c";
1082 string pipe_detectionObjectFilename
= ReplaceExtension ( pipe_detection
,
1084 string command
= ssprintf (
1085 "%s -pipe -c %s -o %s 1>%s 2>%s",
1086 FixSeparatorForSystemCommand(compilerCommand
).c_str (),
1087 pipe_detection
.c_str (),
1088 pipe_detectionObjectFilename
.c_str (),
1091 int exitcode
= system ( command
.c_str () );
1092 FILE* f
= fopen ( pipe_detectionObjectFilename
.c_str (), "rb" );
1095 usePipe
= (exitcode
== 0);
1097 unlink ( pipe_detectionObjectFilename
.c_str () );
1103 printf ( "detected\n" );
1105 printf ( "not detected\n" );
1109 MingwBackend::DetectPCHSupport ()
1111 printf ( "Detecting compiler pre-compiled header support..." );
1113 string path
= "tools" + sSep
+ "rbuild" + sSep
+ "backend" + sSep
+ "mingw" + sSep
+ "pch_detection.h";
1114 string cmd
= ssprintf (
1115 "%s -c %s 1>%s 2>%s",
1116 FixSeparatorForSystemCommand(compilerCommand
).c_str (),
1120 system ( cmd
.c_str () );
1123 FILE* f
= fopen ( path
.c_str (), "rb" );
1128 unlink ( path
.c_str () );
1134 printf ( "detected\n" );
1136 printf ( "not detected\n" );
1140 MingwBackend::GetNonModuleInstallTargetFiles (
1141 vector
<FileLocation
>& out
) const
1143 for ( size_t i
= 0; i
< ProjectNode
.installfiles
.size (); i
++ )
1145 const InstallFile
& installfile
= *ProjectNode
.installfiles
[i
];
1146 out
.push_back ( *installfile
.target
);
1151 MingwBackend::GetModuleInstallTargetFiles (
1152 vector
<FileLocation
>& out
) const
1154 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
1156 const Module
& module
= *ProjectNode
.modules
[i
];
1157 if ( !module
.enabled
)
1159 if ( module
.install
)
1160 out
.push_back ( *module
.install
);
1165 MingwBackend::GetInstallTargetFiles (
1166 vector
<FileLocation
>& out
) const
1168 GetNonModuleInstallTargetFiles ( out
);
1169 GetModuleInstallTargetFiles ( out
);
1173 MingwBackend::OutputInstallTarget ( const FileLocation
& source
,
1174 const FileLocation
& target
)
1176 fprintf ( fMakefile
,
1178 GetFullName ( target
).c_str (),
1179 GetFullName ( source
).c_str (),
1180 GetFullPath ( target
).c_str () );
1181 fprintf ( fMakefile
,
1183 fprintf ( fMakefile
,
1184 "\t${cp} %s %s 1>$(NUL)\n",
1185 GetFullName ( source
).c_str (),
1186 GetFullName ( target
).c_str () );
1190 MingwBackend::OutputNonModuleInstallTargets ()
1192 for ( size_t i
= 0; i
< ProjectNode
.installfiles
.size (); i
++ )
1194 const InstallFile
& installfile
= *ProjectNode
.installfiles
[i
];
1195 OutputInstallTarget ( *installfile
.source
, *installfile
.target
);
1200 MingwBackend::GetAliasedModuleOrModule ( const Module
& module
) const
1202 if ( module
.aliasedModuleName
.size () > 0 )
1204 const Module
* aliasedModule
= ProjectNode
.LocateModule ( module
.aliasedModuleName
);
1205 assert ( aliasedModule
);
1206 return *aliasedModule
;
1213 MingwBackend::OutputModuleInstallTargets ()
1215 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
1217 const Module
& module
= *ProjectNode
.modules
[i
];
1218 if ( !module
.enabled
)
1220 if ( module
.install
)
1222 const Module
& aliasedModule
= GetAliasedModuleOrModule ( module
);
1223 OutputInstallTarget ( *aliasedModule
.output
, *module
.install
);
1229 MingwBackend::GetRegistrySourceFiles ()
1231 return "boot" + sSep
+ "bootdata" + sSep
+ "hivecls.inf "
1232 "boot" + sSep
+ "bootdata" + sSep
+ "hivedef.inf "
1233 "boot" + sSep
+ "bootdata" + sSep
+ "hiveinst.inf "
1234 "boot" + sSep
+ "bootdata" + sSep
+ "hivesft.inf "
1235 "boot" + sSep
+ "bootdata" + sSep
+ "hivesys.inf";
1239 MingwBackend::GetRegistryTargetFiles ()
1241 string system32ConfigDirectory
= "system32" + sSep
+ "config";
1242 FileLocation
system32 ( InstallDirectory
, system32ConfigDirectory
, "" );
1244 vector
<FileLocation
> registry_files
;
1245 registry_files
.push_back ( FileLocation ( InstallDirectory
, system32ConfigDirectory
, "default" ) );
1246 registry_files
.push_back ( FileLocation ( InstallDirectory
, system32ConfigDirectory
, "sam" ) );
1247 registry_files
.push_back ( FileLocation ( InstallDirectory
, system32ConfigDirectory
, "security" ) );
1248 registry_files
.push_back ( FileLocation ( InstallDirectory
, system32ConfigDirectory
, "software" ) );
1249 registry_files
.push_back ( FileLocation ( InstallDirectory
, system32ConfigDirectory
, "system" ) );
1251 return v2s( this, registry_files
, 6 );
1255 MingwBackend::OutputRegistryInstallTarget ()
1257 FileLocation
system32 ( InstallDirectory
, "system32" + sSep
+ "config", "" );
1259 string registrySourceFiles
= GetRegistrySourceFiles ();
1260 string registryTargetFiles
= GetRegistryTargetFiles ();
1261 fprintf ( fMakefile
,
1262 "install_registry: %s\n",
1263 registryTargetFiles
.c_str () );
1264 fprintf ( fMakefile
,
1265 "%s: %s %s $(MKHIVE_TARGET)\n",
1266 registryTargetFiles
.c_str (),
1267 registrySourceFiles
.c_str (),
1268 GetFullPath ( system32
).c_str () );
1269 fprintf ( fMakefile
,
1270 "\t$(ECHO_MKHIVE)\n" );
1271 fprintf ( fMakefile
,
1272 "\t$(MKHIVE_TARGET) boot%cbootdata %s boot%cbootdata%chiveinst.inf\n",
1273 cSep
, GetFullPath ( system32
).c_str (),
1275 fprintf ( fMakefile
,
1280 MingwBackend::GenerateInstallTarget ()
1282 vector
<FileLocation
> vInstallTargetFiles
;
1283 GetInstallTargetFiles ( vInstallTargetFiles
);
1284 string installTargetFiles
= v2s ( this, vInstallTargetFiles
, 5 );
1285 string registryTargetFiles
= GetRegistryTargetFiles ();
1287 fprintf ( fMakefile
,
1289 installTargetFiles
.c_str (),
1290 registryTargetFiles
.c_str () );
1291 OutputNonModuleInstallTargets ();
1292 OutputModuleInstallTargets ();
1293 OutputRegistryInstallTarget ();
1294 fprintf ( fMakefile
,
1299 MingwBackend::GetModuleTestTargets (
1300 vector
<string
>& out
) const
1302 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
1304 const Module
& module
= *ProjectNode
.modules
[i
];
1305 if ( !module
.enabled
)
1307 if ( module
.type
== Test
)
1308 out
.push_back ( module
.name
);
1313 MingwBackend::GenerateTestTarget ()
1315 vector
<string
> vTestTargets
;
1316 GetModuleTestTargets ( vTestTargets
);
1317 string testTargets
= v2s ( vTestTargets
, 5 );
1319 fprintf ( fMakefile
,
1321 testTargets
.c_str () );
1322 fprintf ( fMakefile
,
1327 MingwBackend::GenerateDirectoryTargets ()
1329 intermediateDirectory
->CreateRule ( fMakefile
, "$(INTERMEDIATE)" );
1330 outputDirectory
->CreateRule ( fMakefile
, "$(OUTPUT)" );
1331 installDirectory
->CreateRule ( fMakefile
, "$(INSTALL)" );