From 8bbf908ab1afd341e361dd5ad0c37f3c1b9a6635 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 28 Nov 2014 17:38:56 +0000 Subject: Autoconfig now detects libraries that libbu++ can use and generates the appropriate headers. bin2cpp now uses those headers to compile correctly despite having missing filters. --- autoconfig.cpp | 32 +++++++++++++++++++++++++++++++ src/tools/bin2cpp.cpp | 53 ++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 74 insertions(+), 11 deletions(-) diff --git a/autoconfig.cpp b/autoconfig.cpp index 28362ec..9d09412 100644 --- a/autoconfig.cpp +++ b/autoconfig.cpp @@ -13,6 +13,35 @@ bool testCpp( const char *prog ) return pclose(pop) == 0; } +bool testLib( const char *lib, const char *symname, const char *humname ) +{ + printf("Detecting library %s (-l%s)...", humname, lib ); + fflush( stdout ); + static const char *prog = "int main () { return 0; }"; + char *cmdline = (char *)malloc( 29+strlen(lib) ); + strcpy( cmdline, "g++ -x c++ -l"); + strcat( cmdline, lib ); + strcat( cmdline, " - -o /dev/null"); + + FILE *pop = popen( cmdline, "w"); + fwrite( prog, 1, strlen( prog ), pop ); + free( cmdline ); + if( pclose(pop) == 0 ) + { + printf("found.\n"); + fprintf( fOut, "#define BU_FEATURE_%s 1\n", symname ); + fprintf( fOut, "#define BU_HAS_%s\n", symname ); + return false; + } + else + { + printf("missing.\n"); + fprintf( fOut, "#define BU_FEATURE_%s 0\n", symname ); + fprintf( fOut, "#define BU_MISSING_%s\n", symname ); + return true; + } +} + void detectEndianness() { printf("Detecting endian support..."); @@ -59,6 +88,9 @@ int main( int argc, char *argv[] ) ); detectEndianness(); + testLib("z", "DEFLATE", "Deflate"); + testLib("bz2", "BZIP2", "BZip2"); + testLib("lzma", "LZMA", "Lzma"); fprintf( fOut, "#endif\n"); } diff --git a/src/tools/bin2cpp.cpp b/src/tools/bin2cpp.cpp index cd57086..e0eab28 100644 --- a/src/tools/bin2cpp.cpp +++ b/src/tools/bin2cpp.cpp @@ -5,9 +5,16 @@ #include #include +#ifdef BU_HAS_DEFLATE #include +#endif +#ifdef BU_HAS_BZIP2 #include +#endif +#ifdef BU_HAS_LZMA #include +#endif + #include #include @@ -26,7 +33,17 @@ public: addOption( sClass, 'c', "Class name [default=\"Datafiles\"]"); addOption( sOutBase, 'o', "Output base filename [defaults to classname]"); addOption( sOutDir, 'd', "Output directory [defaults to current dir]"); - addOption( slot(this, &Options::addFilter), 'f', "Add filter: deflate, bzip2, lzma, base64, hex"); + addOption( slot(this, &Options::addFilter), 'f', "Add filter: " +#ifdef BU_HAS_DEFLATE + "deflate, " +#endif +#ifdef BU_HAS_BZIP2 + "bzip2, " +#endif +#ifdef BU_HAS_LZMA + "lzma, " +#endif + "base64, hex"); addOption( sSpecFile, 's', "Use the specified spec file instead of providing options on the command line. If you use this option all others are ignored."); setNonOption( slot(this, &Options::addInput) ); addHelpOption(); @@ -115,15 +132,22 @@ int main( int argc, char *argv[] ) << "};" << fHdr.nl << fHdr.nl; fHdr << "#endif"; - fSrc << "#include \"" << opt.sOutBase << ".h\"" << fSrc.nl - << "#include " << fSrc.nl - << "#include " << fSrc.nl - << "#include " << fSrc.nl - << "#include " << fSrc.nl - << "#include " << fSrc.nl - << "#include " << fSrc.nl - << "#include " << fSrc.nl << fSrc.nl - << "const " << opt.sClass << "::File " << opt.sClass << "::aFile[] = {" << fSrc.nl; + fSrc << "#include \"" << opt.sOutBase << ".h\"" << fSrc.nl; +#ifdef BU_HAS_DEFLATE + fSrc << "#include " << fSrc.nl; +#endif +#ifdef BU_HAS_BZIP2 + fSrc << "#include " << fSrc.nl; +#endif +#ifdef BU_HAS_LZMA + fSrc << "#include " << fSrc.nl; +#endif + fSrc << "#include " << fSrc.nl; + fSrc << "#include " << fSrc.nl; + fSrc << "#include " << fSrc.nl; + fSrc << "#include " << fSrc.nl; + fSrc << fSrc.nl; + fSrc << "const " << opt.sClass << "::File " << opt.sClass << "::aFile[] = {" << fSrc.nl; for( Bu::StringList::iterator i = opt.slInput.begin(); i; i++ ) { @@ -138,24 +162,31 @@ int main( int argc, char *argv[] ) Bu::String sFltDesc; for( Bu::StringList::iterator f = opt.slFilter.begin(); f; f++ ) { - if( *f == "deflate" ) + if( false ) { } // should optomize out +#ifdef BU_HAS_DEFLATE + else if( *f == "deflate" ) { sDat = encodeStr( sDat ); sFltDesc.prepend("d"); hFilters.insert('d', true ); } +#endif +#ifdef BU_HAS_BZIP2 else if( *f == "bzip2" ) { sDat = encodeStr( sDat ); sFltDesc.prepend("b"); hFilters.insert('b', true ); } +#endif +#ifdef BU_HAS_LZMA else if( *f == "lzma" ) { sDat = encodeStr( sDat ); sFltDesc.prepend("l"); hFilters.insert('l', true ); } +#endif else if( *f == "base64" ) { sDat = encodeStr( sDat ); -- cgit v1.2.3