diff options
Diffstat (limited to '')
-rw-r--r-- | autoconfig.cpp | 34 |
1 files 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 @@ | |||
5 | #include <string.h> | 5 | #include <string.h> |
6 | 6 | ||
7 | FILE *fOut = NULL; | 7 | FILE *fOut = NULL; |
8 | bool bHasDevNull; | ||
8 | 9 | ||
9 | bool testCpp( const char *prog ) | 10 | bool testCpp( const char *prog ) |
10 | { | 11 | { |
11 | FILE *pop = popen("g++ -x c++ - -o /dev/null", "w"); | 12 | FILE *pop = popen( |
13 | bHasDevNull?"g++ -x c++ - -o /dev/null":"g++ -x c++ - -o trash.del", | ||
14 | "w"); | ||
12 | fwrite( prog, 1, strlen( prog ), pop ); | 15 | fwrite( prog, 1, strlen( prog ), pop ); |
13 | return pclose(pop) == 0; | 16 | bool bFound = (pclose(pop) == 0); |
17 | if( !bHasDevNull ) | ||
18 | unlink("trash.del"); | ||
19 | return bFound; | ||
14 | } | 20 | } |
15 | 21 | ||
16 | bool testLib( const char *lib, const char *symname, const char *humname ) | 22 | 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 ) | |||
21 | char *cmdline = (char *)malloc( 29+strlen(lib) ); | 27 | char *cmdline = (char *)malloc( 29+strlen(lib) ); |
22 | strcpy( cmdline, "g++ -x c++ -l"); | 28 | strcpy( cmdline, "g++ -x c++ -l"); |
23 | strcat( cmdline, lib ); | 29 | strcat( cmdline, lib ); |
24 | strcat( cmdline, " - -o /dev/null"); | 30 | if( bHasDevNull ) |
31 | strcat( cmdline, " - -o /dev/null"); | ||
32 | else | ||
33 | strcat( cmdline, " - -o trash.del"); | ||
25 | 34 | ||
26 | FILE *pop = popen( cmdline, "w"); | 35 | FILE *pop = popen( cmdline, "w"); |
27 | fwrite( prog, 1, strlen( prog ), pop ); | 36 | fwrite( prog, 1, strlen( prog ), pop ); |
28 | free( cmdline ); | 37 | free( cmdline ); |
29 | if( pclose(pop) == 0 ) | 38 | bool bFound = (pclose(pop) == 0); |
39 | if( bFound ) | ||
30 | { | 40 | { |
31 | printf("found.\n"); | 41 | printf("found.\n"); |
32 | fprintf( fOut, "#define BU_FEATURE_%s 1\n", symname ); | 42 | fprintf( fOut, "#define BU_FEATURE_%s 1\n", symname ); |
33 | fprintf( fOut, "#define BU_HAS_%s\n", symname ); | 43 | fprintf( fOut, "#define BU_HAS_%s\n", symname ); |
34 | return false; | ||
35 | } | 44 | } |
36 | else | 45 | else |
37 | { | 46 | { |
38 | printf("missing.\n"); | 47 | printf("missing.\n"); |
39 | fprintf( fOut, "#define BU_FEATURE_%s 0\n", symname ); | 48 | fprintf( fOut, "#define BU_FEATURE_%s 0\n", symname ); |
40 | fprintf( fOut, "#define BU_MISSING_%s\n", symname ); | 49 | fprintf( fOut, "#define BU_MISSING_%s\n", symname ); |
41 | return true; | ||
42 | } | 50 | } |
51 | |||
52 | if( !bHasDevNull ) | ||
53 | unlink("trash.del"); | ||
54 | return bFound; | ||
43 | } | 55 | } |
44 | 56 | ||
45 | void detectEndianness() | 57 | void detectEndianness() |
@@ -67,6 +79,15 @@ void detectEndianness() | |||
67 | } | 79 | } |
68 | } | 80 | } |
69 | 81 | ||
82 | bool fileExists( const char *filename ) | ||
83 | { | ||
84 | FILE *fTmp = fopen(filename, "rw"); | ||
85 | if( fTmp == NULL ) | ||
86 | return false; | ||
87 | fclose( fTmp ); | ||
88 | return true; | ||
89 | } | ||
90 | |||
70 | int main( int argc, char *argv[] ) | 91 | int main( int argc, char *argv[] ) |
71 | { | 92 | { |
72 | if( argc == 1 ) | 93 | if( argc == 1 ) |
@@ -79,6 +100,7 @@ int main( int argc, char *argv[] ) | |||
79 | ); | 100 | ); |
80 | return 127; | 101 | return 127; |
81 | } | 102 | } |
103 | bHasDevNull = fileExists("/dev/null"); | ||
82 | if( strcmp( argv[1], "src/autoconfig.h" ) == 0 ) | 104 | if( strcmp( argv[1], "src/autoconfig.h" ) == 0 ) |
83 | { | 105 | { |
84 | fOut = fopen( argv[1], "w" ); | 106 | fOut = fopen( argv[1], "w" ); |