aboutsummaryrefslogtreecommitdiff
path: root/autoconfig.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-04-06 14:14:01 +0000
committerMike Buland <eichlan@xagasoft.com>2011-04-06 14:14:01 +0000
commit9f440fb38b36f2d602710695dd53ad9c80e84c2c (patch)
treeb5b1fb4dec3fd4433c564f8b69bc155782e2b00b /autoconfig.cpp
parent5fdf49f609a658161f482b406590531d4941ac46 (diff)
downloadlibbu++-9f440fb38b36f2d602710695dd53ad9c80e84c2c.tar.gz
libbu++-9f440fb38b36f2d602710695dd53ad9c80e84c2c.tar.bz2
libbu++-9f440fb38b36f2d602710695dd53ad9c80e84c2c.tar.xz
libbu++-9f440fb38b36f2d602710695dd53ad9c80e84c2c.zip
Libbu++ generates it's own system specific config file as well as a fancy
version header file all programs can now use to determine which version, api version, and svn revision of libbu++ they're linking against. It doesn't quite work for windows yet, but it will, eventually.
Diffstat (limited to 'autoconfig.cpp')
-rw-r--r--autoconfig.cpp87
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
7FILE *fOut = NULL;
8
9bool 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
4void detectEndianness() 16void 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
16int main() 41int 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}