Detect compiler -pipe support

svn path=/branches/xmlbuildsystem/; revision=14468
This commit is contained in:
Casper Hornstrup
2005-04-03 10:46:08 +00:00
parent 1cb006090f
commit 2c65178fde
3 changed files with 71 additions and 22 deletions

View File

@@ -206,7 +206,8 @@ MingwBackend::Process ()
{
size_t i;
DetectPCHSupport();
DetectPipeSupport ();
DetectPCHSupport ();
CreateMakefile ();
GenerateHeader ();
@@ -515,30 +516,65 @@ FixupTargetFilename ( const string& targetFilename )
}
void
MingwBackend::DetectPCHSupport()
MingwBackend::DetectPipeSupport ()
{
#ifdef WIN32
string sNUL = "NUL";
#else
string sNUL = "/dev/null";
#endif
string path = "tools" SSEP "rbuild" SSEP "backend" SSEP "mingw" SSEP "pch_detection.h";
string cmd = ssprintf(
"gcc -c %s 2>%s",
path.c_str (),
sNUL.c_str () );
system ( cmd.c_str() );
path += ".gch";
printf ( "Detecting compiler -pipe support..." );
FILE* f = fopen ( path.c_str(), "rb" );
string pipe_detection = "tools" SSEP "rbuild" SSEP "backend" SSEP "mingw" SSEP "pipe_detection.c";
string pipe_detectionObjectFilename = ReplaceExtension ( pipe_detection,
".o" );
string command = ssprintf (
"gcc -pipe -c %s -o %s 2>%s",
pipe_detection.c_str (),
pipe_detectionObjectFilename.c_str (),
NUL );
int exitcode = system ( command.c_str () );
FILE* f = fopen ( pipe_detectionObjectFilename.c_str (), "rb" );
if ( f )
{
use_pch = true;
fclose(f);
unlink ( path.c_str() );
usePipe = (exitcode == 0);
fclose ( f );
unlink ( pipe_detectionObjectFilename.c_str () );
}
else
use_pch = false;
usePipe = false;
if ( usePipe )
printf ( "detected\n" );
else
printf ( "not detected\n" );
// TODO FIXME - eventually check for ROS_USE_PCH env var and
// allow that to override use_pch if true
}
void
MingwBackend::DetectPCHSupport ()
{
printf ( "Detecting compiler pre-compiled header support..." );
string path = "tools" SSEP "rbuild" SSEP "backend" SSEP "mingw" SSEP "pch_detection.h";
string cmd = ssprintf (
"gcc -c %s 2>%s",
path.c_str (),
NUL );
system ( cmd.c_str () );
path += ".gch";
FILE* f = fopen ( path.c_str (), "rb" );
if ( f )
{
use_pch = true;
fclose ( f );
unlink ( path.c_str () );
}
else
use_pch = false;
if ( use_pch )
printf ( "detected\n" );
else
printf ( "not detected\n" );
// TODO FIXME - eventually check for ROS_USE_PCH env var and
// allow that to override use_pch if true

View File

@@ -3,6 +3,12 @@
#include "../backend.h"
#ifdef WIN32
#define NUL "NUL"
#else
#define NUL "/dev/null"
#endif
class Directory;
class MingwModuleHandler;
@@ -13,6 +19,7 @@ public:
virtual ~MingwBackend ();
virtual void Process ();
std::string AddDirectoryTarget ( const std::string& directory, bool out );
bool usePipe;
private:
void CreateMakefile ();
void CloseMakefile () const;
@@ -31,7 +38,8 @@ private:
void GenerateXmlBuildFilesMacro() const;
void CheckAutomaticDependencies ();
bool IncludeDirectoryTarget ( const std::string& directory ) const;
void DetectPCHSupport();
void DetectPipeSupport ();
void DetectPCHSupport ();
FILE* fMakefile;
bool use_pch;
Directory *int_directories, *out_directories;

View File

@@ -1278,10 +1278,15 @@ MingwModuleHandler::GenerateOtherMacros ()
}
}
string globalCflags = "-g";
if ( backend->usePipe )
globalCflags += " -pipe";
fprintf (
fMakefile,
"%s += $(PROJECT_CFLAGS) -g\n",
cflagsMacro.c_str () );
"%s += $(PROJECT_CFLAGS) %s\n",
cflagsMacro.c_str (),
globalCflags.c_str () );
fprintf (
fMakefile,