From d8ef3caf2d9be17c3fe54a51b65d321fcd768d30 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 28 Nov 2014 17:49:37 +0000 Subject: Heh, autoconfig didn't work on systems without /dev/null (*caugh* windows *caugh*) --- autoconfig.cpp | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/autoconfig.cpp b/autoconfig.cpp index 9d09412..0df3dbd 100644 --- a/autoconfig.cpp +++ b/autoconfig.cpp @@ -5,12 +5,18 @@ #include FILE *fOut = NULL; +bool bHasDevNull; bool testCpp( const char *prog ) { - FILE *pop = popen("g++ -x c++ - -o /dev/null", "w"); + FILE *pop = popen( + bHasDevNull?"g++ -x c++ - -o /dev/null":"g++ -x c++ - -o trash.del", + "w"); fwrite( prog, 1, strlen( prog ), pop ); - return pclose(pop) == 0; + bool bFound = (pclose(pop) == 0); + if( !bHasDevNull ) + unlink("trash.del"); + return bFound; } bool testLib( const char *lib, const char *symname, const char *humname ) @@ -21,25 +27,31 @@ bool testLib( const char *lib, const char *symname, const char *humname ) char *cmdline = (char *)malloc( 29+strlen(lib) ); strcpy( cmdline, "g++ -x c++ -l"); strcat( cmdline, lib ); - strcat( cmdline, " - -o /dev/null"); + if( bHasDevNull ) + strcat( cmdline, " - -o /dev/null"); + else + strcat( cmdline, " - -o trash.del"); FILE *pop = popen( cmdline, "w"); fwrite( prog, 1, strlen( prog ), pop ); free( cmdline ); - if( pclose(pop) == 0 ) + bool bFound = (pclose(pop) == 0); + if( bFound ) { printf("found.\n"); fprintf( fOut, "#define BU_FEATURE_%s 1\n", symname ); fprintf( fOut, "#define BU_HAS_%s\n", symname ); - return false; } else { printf("missing.\n"); fprintf( fOut, "#define BU_FEATURE_%s 0\n", symname ); fprintf( fOut, "#define BU_MISSING_%s\n", symname ); - return true; } + + if( !bHasDevNull ) + unlink("trash.del"); + return bFound; } void detectEndianness() @@ -67,6 +79,15 @@ void detectEndianness() } } +bool fileExists( const char *filename ) +{ + FILE *fTmp = fopen(filename, "rw"); + if( fTmp == NULL ) + return false; + fclose( fTmp ); + return true; +} + int main( int argc, char *argv[] ) { if( argc == 1 ) @@ -79,6 +100,7 @@ int main( int argc, char *argv[] ) ); return 127; } + bHasDevNull = fileExists("/dev/null"); if( strcmp( argv[1], "src/autoconfig.h" ) == 0 ) { fOut = fopen( argv[1], "w" ); -- cgit v1.2.3