aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--autoconfig.cpp32
-rw-r--r--src/tools/bin2cpp.cpp53
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 )
13 return pclose(pop) == 0; 13 return pclose(pop) == 0;
14} 14}
15 15
16bool testLib( const char *lib, const char *symname, const char *humname )
17{
18 printf("Detecting library %s (-l%s)...", humname, lib );
19 fflush( stdout );
20 static const char *prog = "int main () { return 0; }";
21 char *cmdline = (char *)malloc( 29+strlen(lib) );
22 strcpy( cmdline, "g++ -x c++ -l");
23 strcat( cmdline, lib );
24 strcat( cmdline, " - -o /dev/null");
25
26 FILE *pop = popen( cmdline, "w");
27 fwrite( prog, 1, strlen( prog ), pop );
28 free( cmdline );
29 if( pclose(pop) == 0 )
30 {
31 printf("found.\n");
32 fprintf( fOut, "#define BU_FEATURE_%s 1\n", symname );
33 fprintf( fOut, "#define BU_HAS_%s\n", symname );
34 return false;
35 }
36 else
37 {
38 printf("missing.\n");
39 fprintf( fOut, "#define BU_FEATURE_%s 0\n", symname );
40 fprintf( fOut, "#define BU_MISSING_%s\n", symname );
41 return true;
42 }
43}
44
16void detectEndianness() 45void detectEndianness()
17{ 46{
18 printf("Detecting endian support..."); 47 printf("Detecting endian support...");
@@ -59,6 +88,9 @@ int main( int argc, char *argv[] )
59 ); 88 );
60 89
61 detectEndianness(); 90 detectEndianness();
91 testLib("z", "DEFLATE", "Deflate");
92 testLib("bz2", "BZIP2", "BZip2");
93 testLib("lzma", "LZMA", "Lzma");
62 94
63 fprintf( fOut, "#endif\n"); 95 fprintf( fOut, "#endif\n");
64 } 96 }
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 @@
5#include <bu/strfilter.h> 5#include <bu/strfilter.h>
6#include <bu/taf.h> 6#include <bu/taf.h>
7 7
8#ifdef BU_HAS_DEFLATE
8#include <bu/deflate.h> 9#include <bu/deflate.h>
10#endif
11#ifdef BU_HAS_BZIP2
9#include <bu/bzip2.h> 12#include <bu/bzip2.h>
13#endif
14#ifdef BU_HAS_LZMA
10#include <bu/lzma.h> 15#include <bu/lzma.h>
16#endif
17
11#include <bu/base64.h> 18#include <bu/base64.h>
12#include <bu/hex.h> 19#include <bu/hex.h>
13 20
@@ -26,7 +33,17 @@ public:
26 addOption( sClass, 'c', "Class name [default=\"Datafiles\"]"); 33 addOption( sClass, 'c', "Class name [default=\"Datafiles\"]");
27 addOption( sOutBase, 'o', "Output base filename [defaults to classname]"); 34 addOption( sOutBase, 'o', "Output base filename [defaults to classname]");
28 addOption( sOutDir, 'd', "Output directory [defaults to current dir]"); 35 addOption( sOutDir, 'd', "Output directory [defaults to current dir]");
29 addOption( slot(this, &Options::addFilter), 'f', "Add filter: deflate, bzip2, lzma, base64, hex"); 36 addOption( slot(this, &Options::addFilter), 'f', "Add filter: "
37#ifdef BU_HAS_DEFLATE
38 "deflate, "
39#endif
40#ifdef BU_HAS_BZIP2
41 "bzip2, "
42#endif
43#ifdef BU_HAS_LZMA
44 "lzma, "
45#endif
46 "base64, hex");
30 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."); 47 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.");
31 setNonOption( slot(this, &Options::addInput) ); 48 setNonOption( slot(this, &Options::addInput) );
32 addHelpOption(); 49 addHelpOption();
@@ -115,15 +132,22 @@ int main( int argc, char *argv[] )
115 << "};" << fHdr.nl << fHdr.nl; 132 << "};" << fHdr.nl << fHdr.nl;
116 fHdr << "#endif"; 133 fHdr << "#endif";
117 134
118 fSrc << "#include \"" << opt.sOutBase << ".h\"" << fSrc.nl 135 fSrc << "#include \"" << opt.sOutBase << ".h\"" << fSrc.nl;
119 << "#include <bu/deflate.h>" << fSrc.nl 136#ifdef BU_HAS_DEFLATE
120 << "#include <bu/bzip2.h>" << fSrc.nl 137 fSrc << "#include <bu/deflate.h>" << fSrc.nl;
121 << "#include <bu/base64.h>" << fSrc.nl 138#endif
122 << "#include <bu/lzma.h>" << fSrc.nl 139#ifdef BU_HAS_BZIP2
123 << "#include <bu/hex.h>" << fSrc.nl 140 fSrc << "#include <bu/bzip2.h>" << fSrc.nl;
124 << "#include <bu/strfilter.h>" << fSrc.nl 141#endif
125 << "#include <bu/staticmembuf.h>" << fSrc.nl << fSrc.nl 142#ifdef BU_HAS_LZMA
126 << "const " << opt.sClass << "::File " << opt.sClass << "::aFile[] = {" << fSrc.nl; 143 fSrc << "#include <bu/lzma.h>" << fSrc.nl;
144#endif
145 fSrc << "#include <bu/base64.h>" << fSrc.nl;
146 fSrc << "#include <bu/hex.h>" << fSrc.nl;
147 fSrc << "#include <bu/strfilter.h>" << fSrc.nl;
148 fSrc << "#include <bu/staticmembuf.h>" << fSrc.nl;
149 fSrc << fSrc.nl;
150 fSrc << "const " << opt.sClass << "::File " << opt.sClass << "::aFile[] = {" << fSrc.nl;
127 151
128 for( Bu::StringList::iterator i = opt.slInput.begin(); i; i++ ) 152 for( Bu::StringList::iterator i = opt.slInput.begin(); i; i++ )
129 { 153 {
@@ -138,24 +162,31 @@ int main( int argc, char *argv[] )
138 Bu::String sFltDesc; 162 Bu::String sFltDesc;
139 for( Bu::StringList::iterator f = opt.slFilter.begin(); f; f++ ) 163 for( Bu::StringList::iterator f = opt.slFilter.begin(); f; f++ )
140 { 164 {
141 if( *f == "deflate" ) 165 if( false ) { } // should optomize out
166#ifdef BU_HAS_DEFLATE
167 else if( *f == "deflate" )
142 { 168 {
143 sDat = encodeStr<Deflate>( sDat ); 169 sDat = encodeStr<Deflate>( sDat );
144 sFltDesc.prepend("d"); 170 sFltDesc.prepend("d");
145 hFilters.insert('d', true ); 171 hFilters.insert('d', true );
146 } 172 }
173#endif
174#ifdef BU_HAS_BZIP2
147 else if( *f == "bzip2" ) 175 else if( *f == "bzip2" )
148 { 176 {
149 sDat = encodeStr<BZip2>( sDat ); 177 sDat = encodeStr<BZip2>( sDat );
150 sFltDesc.prepend("b"); 178 sFltDesc.prepend("b");
151 hFilters.insert('b', true ); 179 hFilters.insert('b', true );
152 } 180 }
181#endif
182#ifdef BU_HAS_LZMA
153 else if( *f == "lzma" ) 183 else if( *f == "lzma" )
154 { 184 {
155 sDat = encodeStr<Lzma>( sDat ); 185 sDat = encodeStr<Lzma>( sDat );
156 sFltDesc.prepend("l"); 186 sFltDesc.prepend("l");
157 hFilters.insert('l', true ); 187 hFilters.insert('l', true );
158 } 188 }
189#endif
159 else if( *f == "base64" ) 190 else if( *f == "base64" )
160 { 191 {
161 sDat = encodeStr<Base64>( sDat ); 192 sDat = encodeStr<Base64>( sDat );