diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
commit | ec05778d5718a7912e506764d443a78d6a6179e3 (patch) | |
tree | 78a9a01532180030c095acefc45763f07c14edb8 /autoconfig.cpp | |
parent | b20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff) | |
download | libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2 libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip |
Converted tabs to spaces with tabconv.
Diffstat (limited to 'autoconfig.cpp')
-rw-r--r-- | autoconfig.cpp | 128 |
1 files changed, 64 insertions, 64 deletions
diff --git a/autoconfig.cpp b/autoconfig.cpp index c2649ad..28362ec 100644 --- a/autoconfig.cpp +++ b/autoconfig.cpp | |||
@@ -8,87 +8,87 @@ FILE *fOut = NULL; | |||
8 | 8 | ||
9 | bool testCpp( const char *prog ) | 9 | bool testCpp( const char *prog ) |
10 | { | 10 | { |
11 | FILE *pop = popen("g++ -x c++ - -o /dev/null", "w"); | 11 | FILE *pop = popen("g++ -x c++ - -o /dev/null", "w"); |
12 | fwrite( prog, 1, strlen( prog ), pop ); | 12 | fwrite( prog, 1, strlen( prog ), pop ); |
13 | return pclose(pop) == 0; | 13 | return pclose(pop) == 0; |
14 | } | 14 | } |
15 | 15 | ||
16 | void detectEndianness() | 16 | void detectEndianness() |
17 | { | 17 | { |
18 | printf("Detecting endian support..."); | 18 | printf("Detecting endian support..."); |
19 | fflush( stdout ); | 19 | fflush( stdout ); |
20 | if( testCpp("#include <endian.h>\n\nint main() { return BYTE_ORDER; }\n") ) | 20 | if( testCpp("#include <endian.h>\n\nint main() { return BYTE_ORDER; }\n") ) |
21 | { | 21 | { |
22 | fprintf( fOut, "#include <endian.h>\n\n"); | 22 | fprintf( fOut, "#include <endian.h>\n\n"); |
23 | printf("header file endian.h found, using that.\n"); | 23 | printf("header file endian.h found, using that.\n"); |
24 | } | 24 | } |
25 | else | 25 | else |
26 | { | 26 | { |
27 | uint16_t x=0x0100; | 27 | uint16_t x=0x0100; |
28 | fprintf( fOut, | 28 | fprintf( fOut, |
29 | "#define LITTLE_ENDIAN 0\n" | 29 | "#define LITTLE_ENDIAN 0\n" |
30 | "#define BIG_ENDIAN 1\n" | 30 | "#define BIG_ENDIAN 1\n" |
31 | "#define BYTE_ORDER %d\n\n", | 31 | "#define BYTE_ORDER %d\n\n", |
32 | ((uint8_t *)&x)[0] | 32 | ((uint8_t *)&x)[0] |
33 | ); | 33 | ); |
34 | printf("no header file found, faking it...\n" | 34 | printf("no header file found, faking it...\n" |
35 | "\tArchetecture is: %s Endian\n", | 35 | "\tArchetecture is: %s Endian\n", |
36 | ((uint8_t *)&x)[0]?"Big":"Little" | 36 | ((uint8_t *)&x)[0]?"Big":"Little" |
37 | ); | 37 | ); |
38 | } | 38 | } |
39 | } | 39 | } |
40 | 40 | ||
41 | int main( int argc, char *argv[] ) | 41 | int main( int argc, char *argv[] ) |
42 | { | 42 | { |
43 | if( argc == 1 ) | 43 | if( argc == 1 ) |
44 | { | 44 | { |
45 | fprintf( stderr, | 45 | fprintf( stderr, |
46 | "Invalid usage: specify a file to generate:\n" | 46 | "Invalid usage: specify a file to generate:\n" |
47 | " src/autoconfig.h\n" | 47 | " src/autoconfig.h\n" |
48 | " src/version.h\n" | 48 | " src/version.h\n" |
49 | "\n" | 49 | "\n" |
50 | ); | 50 | ); |
51 | return 127; | 51 | return 127; |
52 | } | 52 | } |
53 | if( strcmp( argv[1], "src/autoconfig.h" ) == 0 ) | 53 | if( strcmp( argv[1], "src/autoconfig.h" ) == 0 ) |
54 | { | 54 | { |
55 | fOut = fopen( argv[1], "w" ); | 55 | fOut = fopen( argv[1], "w" ); |
56 | fprintf( fOut, | 56 | fprintf( fOut, |
57 | "#ifndef BU_AUTO_CONFIG_H\n" | 57 | "#ifndef BU_AUTO_CONFIG_H\n" |
58 | "#define BU_AUTO_CONFIG_H\n\n" | 58 | "#define BU_AUTO_CONFIG_H\n\n" |
59 | ); | 59 | ); |
60 | 60 | ||
61 | detectEndianness(); | 61 | detectEndianness(); |
62 | 62 | ||
63 | fprintf( fOut, "#endif\n"); | 63 | fprintf( fOut, "#endif\n"); |
64 | } | 64 | } |
65 | else if( strcmp( argv[1], "src/version.h" ) == 0 ) | 65 | else if( strcmp( argv[1], "src/version.h" ) == 0 ) |
66 | { | 66 | { |
67 | FILE *fVer = fopen("version", "rt"); | 67 | FILE *fVer = fopen("version", "rt"); |
68 | char buf[1024]; | 68 | char buf[1024]; |
69 | buf[fread( buf, 1, 1024, fVer )] = '\0'; | 69 | buf[fread( buf, 1, 1024, fVer )] = '\0'; |
70 | for( int j = 0; buf[j]; j++ ) | 70 | for( int j = 0; buf[j]; j++ ) |
71 | if( buf[j] == '\n' ) | 71 | if( buf[j] == '\n' ) |
72 | buf[j] = '\0'; | 72 | buf[j] = '\0'; |
73 | fclose( fVer ); | 73 | fclose( fVer ); |
74 | 74 | ||
75 | fOut = fopen( argv[1], "w" ); | 75 | fOut = fopen( argv[1], "w" ); |
76 | fprintf( fOut, | 76 | fprintf( fOut, |
77 | "#ifndef BU_VERSION_H\n" | 77 | "#ifndef BU_VERSION_H\n" |
78 | "#define BU_VERSION_H\n\n" | 78 | "#define BU_VERSION_H\n\n" |
79 | "#define LIBBU_VERSION 0\n" | 79 | "#define LIBBU_VERSION 0\n" |
80 | "#define LIBBU_REVISION 1\n" | 80 | "#define LIBBU_REVISION 1\n" |
81 | "#define LIBBU_VERSION_STR \"%s\"\n" | 81 | "#define LIBBU_VERSION_STR \"%s\"\n" |
82 | "#define LIBBU_API 0\n" | 82 | "#define LIBBU_API 0\n" |
83 | "#define LIBBU_VC_ID \"", | 83 | "#define LIBBU_VC_ID \"", |
84 | buf | 84 | buf |
85 | ); | 85 | ); |
86 | FILE *psub = popen("svnversion -n", "r"); | 86 | FILE *psub = popen("svnversion -n", "r"); |
87 | fwrite( buf, fread( buf, 1, 1024, psub ), 1, fOut ); | 87 | fwrite( buf, fread( buf, 1, 1024, psub ), 1, fOut ); |
88 | pclose( psub ); | 88 | pclose( psub ); |
89 | fprintf( fOut, "\"\n\n#endif\n"); | 89 | fprintf( fOut, "\"\n\n#endif\n"); |
90 | } | 90 | } |
91 | 91 | ||
92 | return 0; | 92 | return 0; |
93 | } | 93 | } |
94 | 94 | ||