mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 15:43:00 +00:00
Christoph_vW <Christoph@ApiViewer.de>:
Binutils detection Modified to support cross-compilation Resolves #707 svn path=/trunk/; revision=17744
This commit is contained in:
parent
b4f5c9b4b5
commit
21501cda53
4 changed files with 133 additions and 0 deletions
|
@ -361,6 +361,7 @@ void
|
||||||
MingwBackend::ProcessNormal ()
|
MingwBackend::ProcessNormal ()
|
||||||
{
|
{
|
||||||
DetectCompiler ();
|
DetectCompiler ();
|
||||||
|
DetectBinutils ();
|
||||||
DetectNetwideAssembler ();
|
DetectNetwideAssembler ();
|
||||||
DetectPipeSupport ();
|
DetectPipeSupport ();
|
||||||
DetectPCHSupport ();
|
DetectPCHSupport ();
|
||||||
|
@ -813,6 +814,111 @@ MingwBackend::TryToDetectThisNetwideAssembler ( const string& assembler )
|
||||||
return (exitcode == 0);
|
return (exitcode == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
MingwBackend::TryToDetectThisBinutils ( const string& binutils )
|
||||||
|
{
|
||||||
|
string command = ssprintf (
|
||||||
|
"%s -v 1>%s",
|
||||||
|
binutils.c_str (),
|
||||||
|
NUL,
|
||||||
|
NUL );
|
||||||
|
int exitcode = system ( command.c_str () );
|
||||||
|
return (exitcode == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
string
|
||||||
|
MingwBackend::GetBinutilsVersion ( const string& binutilsCommand )
|
||||||
|
{
|
||||||
|
FILE *fp;
|
||||||
|
int ch, i;
|
||||||
|
char buffer[81];
|
||||||
|
|
||||||
|
string versionCommand = ssprintf ( "%s -v",
|
||||||
|
binutilsCommand.c_str (),
|
||||||
|
NUL,
|
||||||
|
NUL );
|
||||||
|
fp = popen ( versionCommand.c_str () , "r" );
|
||||||
|
for( i = 0; ( i < 80 ) && ( feof ( fp ) == 0 ); i++ )
|
||||||
|
{
|
||||||
|
buffer[i] = (char) ch;
|
||||||
|
ch = fgetc( fp );
|
||||||
|
}
|
||||||
|
buffer[i] = '\0';
|
||||||
|
pclose ( fp );
|
||||||
|
|
||||||
|
char separators[] = " ";
|
||||||
|
char *token;
|
||||||
|
char *prevtoken;
|
||||||
|
|
||||||
|
token = strtok ( buffer, separators );
|
||||||
|
while ( token != NULL )
|
||||||
|
{
|
||||||
|
prevtoken = token;
|
||||||
|
token = strtok ( NULL, separators );
|
||||||
|
}
|
||||||
|
string version = string ( prevtoken );
|
||||||
|
int firstSpace = version.find_last_not_of ( " \t" );
|
||||||
|
if ( firstSpace != -1 )
|
||||||
|
return string ( version, 0, firstSpace - 1);
|
||||||
|
else
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
MingwBackend::IsSupportedBinutilsVersion ( const string& binutilsVersion )
|
||||||
|
{
|
||||||
|
if ( ( ( strcmp ( binutilsVersion.c_str (), "20040902") >= 0 ) &&
|
||||||
|
( strcmp ( binutilsVersion.c_str (), "20041008") <= 0 ) ) ||
|
||||||
|
( strcmp ( binutilsVersion.c_str (), "20031001") < 0 ) )
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MingwBackend::DetectBinutils ()
|
||||||
|
{
|
||||||
|
printf ( "Detecting binutils..." );
|
||||||
|
|
||||||
|
bool detectedBinutils = false;
|
||||||
|
const string& ROS_PREFIXValue = Environment::GetVariable ( "ROS_PREFIX" );
|
||||||
|
if ( ROS_PREFIXValue.length () > 0 )
|
||||||
|
{
|
||||||
|
binutilsPrefix = ROS_PREFIXValue;
|
||||||
|
binutilsCommand = binutilsPrefix + "-ld";
|
||||||
|
detectedBinutils = TryToDetectThisBinutils ( binutilsCommand );
|
||||||
|
}
|
||||||
|
#if defined(WIN32)
|
||||||
|
if ( !detectedBinutils )
|
||||||
|
{
|
||||||
|
binutilsPrefix = "";
|
||||||
|
binutilsCommand = "ld";
|
||||||
|
detectedBinutils = TryToDetectThisBinutils ( binutilsCommand );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if ( !detectedBinutils )
|
||||||
|
{
|
||||||
|
binutilsPrefix = "mingw32";
|
||||||
|
binutilsCommand = binutilsPrefix + "-ld";
|
||||||
|
detectedBinutils = TryToDetectThisBinutils ( binutilsCommand );
|
||||||
|
}
|
||||||
|
if ( detectedBinutils )
|
||||||
|
{
|
||||||
|
const string& binutilsVersion = GetBinutilsVersion ( binutilsCommand );
|
||||||
|
if ( IsSupportedBinutilsVersion ( binutilsVersion ) )
|
||||||
|
printf ( "detected (%s)\n", binutilsCommand.c_str () );
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf ( "detected (%s), but with unsupported version (%s)\n",
|
||||||
|
binutilsCommand.c_str (),
|
||||||
|
binutilsVersion.c_str () );
|
||||||
|
throw UnsupportedBuildToolException ( binutilsCommand, binutilsVersion );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
printf ( "not detected\n" );
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MingwBackend::DetectNetwideAssembler ()
|
MingwBackend::DetectNetwideAssembler ()
|
||||||
{
|
{
|
||||||
|
|
|
@ -72,6 +72,8 @@ public:
|
||||||
std::string compilerPrefix;
|
std::string compilerPrefix;
|
||||||
std::string compilerCommand;
|
std::string compilerCommand;
|
||||||
std::string nasmCommand;
|
std::string nasmCommand;
|
||||||
|
std::string binutilsPrefix;
|
||||||
|
std::string binutilsCommand;
|
||||||
bool usePipe;
|
bool usePipe;
|
||||||
Directory* intermediateDirectory;
|
Directory* intermediateDirectory;
|
||||||
Directory* outputDirectory;
|
Directory* outputDirectory;
|
||||||
|
@ -108,6 +110,10 @@ private:
|
||||||
bool TryToDetectThisCompiler ( const std::string& compiler );
|
bool TryToDetectThisCompiler ( const std::string& compiler );
|
||||||
void DetectCompiler ();
|
void DetectCompiler ();
|
||||||
bool TryToDetectThisNetwideAssembler ( const std::string& assembler );
|
bool TryToDetectThisNetwideAssembler ( const std::string& assembler );
|
||||||
|
bool TryToDetectThisBinutils ( const std::string& binutils );
|
||||||
|
std::string GetBinutilsVersion ( const std::string& binutilsCommand );
|
||||||
|
bool IsSupportedBinutilsVersion ( const std::string& binutilsVersion );
|
||||||
|
void DetectBinutils ();
|
||||||
void DetectNetwideAssembler ();
|
void DetectNetwideAssembler ();
|
||||||
void DetectPipeSupport ();
|
void DetectPipeSupport ();
|
||||||
void DetectPCHSupport ();
|
void DetectPCHSupport ();
|
||||||
|
|
|
@ -187,3 +187,14 @@ InvocationFailedException::InvocationFailedException ( const std::string& comman
|
||||||
Command = command;
|
Command = command;
|
||||||
ExitCode = exitcode;
|
ExitCode = exitcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
UnsupportedBuildToolException::UnsupportedBuildToolException ( const std::string& buildTool,
|
||||||
|
const std::string& version )
|
||||||
|
: Exception ( "Build tool '%s' with version '%s' is unsupported. Please upgrade your build tool.",
|
||||||
|
buildTool.c_str (),
|
||||||
|
version.c_str () )
|
||||||
|
{
|
||||||
|
BuildTool = buildTool;
|
||||||
|
Version = version;
|
||||||
|
}
|
||||||
|
|
|
@ -139,4 +139,14 @@ public:
|
||||||
int ExitCode;
|
int ExitCode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class UnsupportedBuildToolException : public Exception
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UnsupportedBuildToolException ( const std::string& buildtool,
|
||||||
|
const std::string& version );
|
||||||
|
std::string BuildTool;
|
||||||
|
std::string Version;
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* __EXCEPTION_H */
|
#endif /* __EXCEPTION_H */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue