On some systems, sqlite3 requires pthread libraries to be linked in. Add
the flag so that autoconf can successfully compile and look for
'sqlite3_open'.
The current macro does not seem to honor the CFLAGS and LDFLAGS
variables if '--with-sqlite3=yes' is used. Fix this and some of
the other cruft in the macro.