From 9f440fb38b36f2d602710695dd53ad9c80e84c2c Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 6 Apr 2011 14:14:01 +0000 Subject: 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. --- autoconfig.cpp | 87 +++++++++++++++++++++++++++++++++++++++++++++---------- default.bld | 23 +++++---------- src/config.h | 8 +++-- src/utfstring.cpp | 4 +-- 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 @@ #include #include +#include +#include +#include + +FILE *fOut = NULL; + +bool testCpp( const char *prog ) +{ + FILE *pop = popen("g++ -x c++ - -o /dev/null", "w"); + fwrite( prog, 1, strlen( prog ), pop ); + return pclose(pop) == 0; +} void detectEndianness() { - uint16_t x=0x0100; - fprintf( stderr, - "#define LITTLE_ENDIAN 0\n" - "#define BIG_ENDIAN 1\n" - "#define ENDIANNESS %d\n\n", - ((uint8_t *)&x)[0] - ); - printf("Archetecture is: %s Endian\n", ((uint8_t *)&x)[0]?"Big":"Little" ); + printf("Detecting endian support..."); + fflush( stdout ); + if( testCpp("#include \n\nint main() { return BYTE_ORDER; }\n") ) + { + fprintf( fOut, "#include \n\n"); + printf("header file endian.h found, using that.\n"); + } + else + { + uint16_t x=0x0100; + fprintf( fOut, + "#define LITTLE_ENDIAN 0\n" + "#define BIG_ENDIAN 1\n" + "#define BYTE_ORDER %d\n\n", + ((uint8_t *)&x)[0] + ); + printf("no header file found, faking it...\n" + "\tArchetecture is: %s Endian\n", + ((uint8_t *)&x)[0]?"Big":"Little" + ); + } } -int main() +int main( int argc, char *argv[] ) { - fprintf( stderr, - "#ifndef BU_AUTO_CONFIG_H\n" - "#define BU_AUTO_CONFIG_H\n\n" - ); + if( argc == 1 ) + { + fprintf( stderr, + "Invalid usage: specify a file to generate:\n" + " src/autoconfig.h\n" + " src/version.h\n" + "\n" + ); + return 127; + } + if( strcmp( argv[1], "src/autoconfig.h" ) == 0 ) + { + fOut = fopen( argv[1], "w" ); + fprintf( fOut, + "#ifndef BU_AUTO_CONFIG_H\n" + "#define BU_AUTO_CONFIG_H\n\n" + ); - // huh, turns out #include covers this... -// detectEndianness(); + detectEndianness(); - fprintf( stderr, "#endif\n"); + fprintf( fOut, "#endif\n"); + } + else if( strcmp( argv[1], "src/version.h" ) == 0 ) + { + fOut = fopen( argv[1], "w" ); + fprintf( fOut, + "#ifndef BU_VERSION_H\n" + "#define BU_VERSION_H\n\n" + "#define LIBBU_VERSION 0\n" + "#define LIBBU_REVISION 1\n" + "#define LIBBU_VERSION_STR \"0.1\"\n" + "#define LIBBU_API 0\n" + "#define LIBBU_VC_ID \""); + FILE *psub = popen("svnversion -n", "r"); + char buf[1024]; + fwrite( buf, fread( buf, 1, 1024, psub ), 1, fOut ); + pclose( psub ); + fprintf( fOut, "\"\n\n#endif\n"); + } return 0; } diff --git a/default.bld b/default.bld index 1aca56a..9391c68 100644 --- a/default.bld +++ b/default.bld @@ -34,28 +34,20 @@ action "unit" { build: targets("unit tests"); } -/* -target "src/autoconfig.h" + +target ["src/autoconfig.h", "src/version.h"] { input "autoconfig"; display "autoconfig"; profile "build" { - execute("./autoconfig 2>src/autoconfig.h"); + execute("./autoconfig ${OUTPUT}"); } } -target "bu/autoconfig.h" +target "src/version.h" { - tag "header-links"; - display "symlink"; - input "src/autoconfig.h"; - profile "build" - { - execute("echo ${INPUT}"); - execute("echo ${OUTPUT}"); - execute("mkdir -p $(dirname ${OUTPUT}); ln -s ../${INPUT} ${OUTPUT}"); - } + input ".svn"; } target "autoconfig" @@ -63,9 +55,9 @@ target "autoconfig" rule "exe"; input "autoconfig.cpp"; } -*/ -target files("src/*.h").replace("src/", "bu/") +target [files("src/*.h").replace("src/", "bu/"), "bu/autoconfig.h", + "bu/version.h"] { tag "header-links"; display "symlink"; @@ -75,6 +67,7 @@ target files("src/*.h").replace("src/", "bu/") execute("mkdir -p $(dirname ${OUTPUT}); ln -s ../${INPUT} ${OUTPUT}"); } } + target files("src/compat/*.h").replace("src/", "bu/") { 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 @@ #include "bu/extratypes.h" -// Later if we need autoconfig stuff, here's where it'll go. -// #include "bu/autoconfig.h" +#ifndef WIN32 +#include "bu/autoconfig.h" +#else +#warning Cannot generate an autoinclude file for windows yet +#endif + #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 @@ #include "bu/string.h" #include "bu/stream.h" - -#include - +#include "bu/config.h" #include "bu/sio.h" using Bu::sio; -- cgit v1.2.3