aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--autoconfig.cpp87
-rw-r--r--default.bld23
-rw-r--r--src/config.h8
-rw-r--r--src/utfstring.cpp4
4 files changed, 86 insertions, 36 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}
diff --git a/default.bld b/default.bld
index 1aca56a..9391c68 100644
--- a/default.bld
+++ b/default.bld
@@ -34,28 +34,20 @@ action "unit"
34{ 34{
35 build: targets("unit tests"); 35 build: targets("unit tests");
36} 36}
37/* 37
38target "src/autoconfig.h" 38target ["src/autoconfig.h", "src/version.h"]
39{ 39{
40 input "autoconfig"; 40 input "autoconfig";
41 display "autoconfig"; 41 display "autoconfig";
42 profile "build" 42 profile "build"
43 { 43 {
44 execute("./autoconfig 2>src/autoconfig.h"); 44 execute("./autoconfig ${OUTPUT}");
45 } 45 }
46} 46}
47 47
48target "bu/autoconfig.h" 48target "src/version.h"
49{ 49{
50 tag "header-links"; 50 input ".svn";
51 display "symlink";
52 input "src/autoconfig.h";
53 profile "build"
54 {
55 execute("echo ${INPUT}");
56 execute("echo ${OUTPUT}");
57 execute("mkdir -p $(dirname ${OUTPUT}); ln -s ../${INPUT} ${OUTPUT}");
58 }
59} 51}
60 52
61target "autoconfig" 53target "autoconfig"
@@ -63,9 +55,9 @@ target "autoconfig"
63 rule "exe"; 55 rule "exe";
64 input "autoconfig.cpp"; 56 input "autoconfig.cpp";
65} 57}
66*/
67 58
68target files("src/*.h").replace("src/", "bu/") 59target [files("src/*.h").replace("src/", "bu/"), "bu/autoconfig.h",
60 "bu/version.h"]
69{ 61{
70 tag "header-links"; 62 tag "header-links";
71 display "symlink"; 63 display "symlink";
@@ -75,6 +67,7 @@ target files("src/*.h").replace("src/", "bu/")
75 execute("mkdir -p $(dirname ${OUTPUT}); ln -s ../${INPUT} ${OUTPUT}"); 67 execute("mkdir -p $(dirname ${OUTPUT}); ln -s ../${INPUT} ${OUTPUT}");
76 } 68 }
77} 69}
70
78target files("src/compat/*.h").replace("src/", "bu/") 71target files("src/compat/*.h").replace("src/", "bu/")
79{ 72{
80 tag "header-links"; 73 tag "header-links";
diff --git a/src/config.h b/src/config.h
index ce954de..260d406 100644
--- a/src/config.h
+++ b/src/config.h
@@ -17,7 +17,11 @@
17 17
18#include "bu/extratypes.h" 18#include "bu/extratypes.h"
19 19
20// Later if we need autoconfig stuff, here's where it'll go. 20#ifndef WIN32
21// #include "bu/autoconfig.h" 21#include "bu/autoconfig.h"
22#else
23#warning Cannot generate an autoinclude file for windows yet
24#endif
25
22 26
23#endif 27#endif
diff --git a/src/utfstring.cpp b/src/utfstring.cpp
index 7c4ba19..c9da52f 100644
--- a/src/utfstring.cpp
+++ b/src/utfstring.cpp
@@ -9,9 +9,7 @@
9 9
10#include "bu/string.h" 10#include "bu/string.h"
11#include "bu/stream.h" 11#include "bu/stream.h"
12 12#include "bu/config.h"
13#include <endian.h>
14
15#include "bu/sio.h" 13#include "bu/sio.h"
16using Bu::sio; 14using Bu::sio;
17 15