diff options
Diffstat (limited to 'autoconfig.cpp')
-rw-r--r-- | autoconfig.cpp | 87 |
1 files changed, 71 insertions, 16 deletions
diff --git a/autoconfig.cpp b/autoconfig.cpp index aa8b6a4..1402704 100644 --- a/autoconfig.cpp +++ b/autoconfig.cpp | |||
@@ -1,29 +1,84 @@ | |||
1 | #include <stdint.h> | 1 | #include <stdint.h> |
2 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | #include <unistd.h> | ||
4 | #include <stdlib.h> | ||
5 | #include <string.h> | ||
6 | |||
7 | FILE *fOut = NULL; | ||
8 | |||
9 | bool testCpp( const char *prog ) | ||
10 | { | ||
11 | FILE *pop = popen("g++ -x c++ - -o /dev/null", "w"); | ||
12 | fwrite( prog, 1, strlen( prog ), pop ); | ||
13 | return pclose(pop) == 0; | ||
14 | } | ||
3 | 15 | ||
4 | void detectEndianness() | 16 | void detectEndianness() |
5 | { | 17 | { |
6 | uint16_t x=0x0100; | 18 | printf("Detecting endian support..."); |
7 | fprintf( stderr, | 19 | fflush( stdout ); |
8 | "#define LITTLE_ENDIAN 0\n" | 20 | if( testCpp("#include <endian.h>\n\nint main() { return BYTE_ORDER; }\n") ) |
9 | "#define BIG_ENDIAN 1\n" | 21 | { |
10 | "#define ENDIANNESS %d\n\n", | 22 | fprintf( fOut, "#include <endian.h>\n\n"); |
11 | ((uint8_t *)&x)[0] | 23 | printf("header file endian.h found, using that.\n"); |
12 | ); | 24 | } |
13 | printf("Archetecture is: %s Endian\n", ((uint8_t *)&x)[0]?"Big":"Little" ); | 25 | else |
26 | { | ||
27 | uint16_t x=0x0100; | ||
28 | fprintf( fOut, | ||
29 | "#define LITTLE_ENDIAN 0\n" | ||
30 | "#define BIG_ENDIAN 1\n" | ||
31 | "#define BYTE_ORDER %d\n\n", | ||
32 | ((uint8_t *)&x)[0] | ||
33 | ); | ||
34 | printf("no header file found, faking it...\n" | ||
35 | "\tArchetecture is: %s Endian\n", | ||
36 | ((uint8_t *)&x)[0]?"Big":"Little" | ||
37 | ); | ||
38 | } | ||
14 | } | 39 | } |
15 | 40 | ||
16 | int main() | 41 | int main( int argc, char *argv[] ) |
17 | { | 42 | { |
18 | fprintf( stderr, | 43 | if( argc == 1 ) |
19 | "#ifndef BU_AUTO_CONFIG_H\n" | 44 | { |
20 | "#define BU_AUTO_CONFIG_H\n\n" | 45 | fprintf( stderr, |
21 | ); | 46 | "Invalid usage: specify a file to generate:\n" |
47 | " src/autoconfig.h\n" | ||
48 | " src/version.h\n" | ||
49 | "\n" | ||
50 | ); | ||
51 | return 127; | ||
52 | } | ||
53 | if( strcmp( argv[1], "src/autoconfig.h" ) == 0 ) | ||
54 | { | ||
55 | fOut = fopen( argv[1], "w" ); | ||
56 | fprintf( fOut, | ||
57 | "#ifndef BU_AUTO_CONFIG_H\n" | ||
58 | "#define BU_AUTO_CONFIG_H\n\n" | ||
59 | ); | ||
22 | 60 | ||
23 | // huh, turns out #include <endian.h> covers this... | 61 | detectEndianness(); |
24 | // detectEndianness(); | ||
25 | 62 | ||
26 | fprintf( stderr, "#endif\n"); | 63 | fprintf( fOut, "#endif\n"); |
64 | } | ||
65 | else if( strcmp( argv[1], "src/version.h" ) == 0 ) | ||
66 | { | ||
67 | fOut = fopen( argv[1], "w" ); | ||
68 | fprintf( fOut, | ||
69 | "#ifndef BU_VERSION_H\n" | ||
70 | "#define BU_VERSION_H\n\n" | ||
71 | "#define LIBBU_VERSION 0\n" | ||
72 | "#define LIBBU_REVISION 1\n" | ||
73 | "#define LIBBU_VERSION_STR \"0.1\"\n" | ||
74 | "#define LIBBU_API 0\n" | ||
75 | "#define LIBBU_VC_ID \""); | ||
76 | FILE *psub = popen("svnversion -n", "r"); | ||
77 | char buf[1024]; | ||
78 | fwrite( buf, fread( buf, 1, 1024, psub ), 1, fOut ); | ||
79 | pclose( psub ); | ||
80 | fprintf( fOut, "\"\n\n#endif\n"); | ||
81 | } | ||
27 | 82 | ||
28 | return 0; | 83 | return 0; |
29 | } | 84 | } |