Move some code to libsqlite3.so to avoid duplication.
Link executables against libsqlite3.so.
Increase timeout for fuzzcheck.
Update list of optionally available functions.
Fix building with dlopen() not available.

SQLite revision: 10e20c0b43500cfb9bbc0eaa061c57514f715d87238f4d835880cd846b9ebd1f

--- /Makefile.in
+++ /Makefile.in
@@ -313,6 +313,9 @@
 # Source code for extensions
 #
 SRC += \
+  $(TOP)/ext/expert/sqlite3expert.c \
+  $(TOP)/ext/expert/sqlite3expert.h
+SRC += \
   $(TOP)/ext/fts1/fts1.c \
   $(TOP)/ext/fts1/fts1.h \
   $(TOP)/ext/fts1/fts1_hash.c \
@@ -365,8 +368,29 @@
   $(TOP)/ext/rbu/sqlite3rbu.h \
   $(TOP)/ext/rbu/sqlite3rbu.c
 SRC += \
+  $(TOP)/ext/misc/amatch.c \
+  $(TOP)/ext/misc/appendvfs.c \
+  $(TOP)/ext/misc/carray.c \
+  $(TOP)/ext/misc/completion.c \
+  $(TOP)/ext/misc/csv.c \
+  $(TOP)/ext/misc/dbdata.c \
+  $(TOP)/ext/misc/decimal.c \
+  $(TOP)/ext/misc/eval.c \
+  $(TOP)/ext/misc/fileio.c \
+  $(TOP)/ext/misc/ieee754.c \
   $(TOP)/ext/misc/json1.c \
-  $(TOP)/ext/misc/stmt.c
+  $(TOP)/ext/misc/nextchar.c \
+  $(TOP)/ext/misc/percentile.c \
+  $(TOP)/ext/misc/regexp.c \
+  $(TOP)/ext/misc/series.c \
+  $(TOP)/ext/misc/sha1.c \
+  $(TOP)/ext/misc/shathree.c \
+  $(TOP)/ext/misc/sqlar.c \
+  $(TOP)/ext/misc/stmt.c \
+  $(TOP)/ext/misc/totype.c \
+  $(TOP)/ext/misc/uint.c \
+  $(TOP)/ext/misc/uuid.c \
+  $(TOP)/ext/misc/zipfile.c
 
 # Generated source code files
 #
@@ -437,35 +461,21 @@
 # Statically linked extensions
 #
 TESTSRC += \
-  $(TOP)/ext/expert/sqlite3expert.c \
   $(TOP)/ext/expert/test_expert.c \
-  $(TOP)/ext/misc/amatch.c \
-  $(TOP)/ext/misc/carray.c \
   $(TOP)/ext/misc/cksumvfs.c \
   $(TOP)/ext/misc/closure.c \
-  $(TOP)/ext/misc/csv.c \
-  $(TOP)/ext/misc/decimal.c \
-  $(TOP)/ext/misc/eval.c \
   $(TOP)/ext/misc/explain.c \
-  $(TOP)/ext/misc/fileio.c \
   $(TOP)/ext/misc/fuzzer.c \
   $(TOP)/ext/fts5/fts5_tcl.c \
   $(TOP)/ext/fts5/fts5_test_mi.c \
   $(TOP)/ext/fts5/fts5_test_tok.c \
-  $(TOP)/ext/misc/ieee754.c \
   $(TOP)/ext/misc/mmapwarm.c \
-  $(TOP)/ext/misc/nextchar.c \
   $(TOP)/ext/misc/normalize.c \
-  $(TOP)/ext/misc/percentile.c \
   $(TOP)/ext/misc/prefixes.c \
-  $(TOP)/ext/misc/regexp.c \
   $(TOP)/ext/misc/remember.c \
-  $(TOP)/ext/misc/series.c \
   $(TOP)/ext/misc/spellfix.c \
-  $(TOP)/ext/misc/totype.c \
   $(TOP)/ext/misc/unionvtab.c \
   $(TOP)/ext/misc/wholenumber.c \
-  $(TOP)/ext/misc/zipfile.c \
   $(TOP)/ext/userauth/userauth.c
 
 # Source code to the library files needed by the test fixture
@@ -647,25 +657,25 @@
 
 libtclsqlite3.la:	tclsqlite.lo libsqlite3.la
 	$(LTLINK) -no-undefined -o $@ tclsqlite.lo \
-		libsqlite3.la @TCL_STUB_LIB_SPEC@ $(TLIBS) \
+		libsqlite3.la @TCL_STUB_LIB_SPEC@ \
 		-rpath "$(TCLLIBDIR)" \
 		-version-info "8:6:8" \
 		-avoid-version
 
-sqlite3$(TEXE):	shell.c sqlite3.c
-	$(LTLINK) $(READLINE_FLAGS) $(SHELL_OPT) -o $@ \
-		shell.c sqlite3.c \
-		$(LIBREADLINE) $(TLIBS) -rpath "$(libdir)"
+sqlite3$(TEXE):	shell.c libsqlite3.la
+	$(LTLINK) $(READLINE_FLAGS) -o $@ \
+		shell.c libsqlite3.la \
+		$(LIBREADLINE)
 
-sqldiff$(TEXE):	$(TOP)/tool/sqldiff.c sqlite3.lo sqlite3.h
-	$(LTLINK) -o $@ $(TOP)/tool/sqldiff.c sqlite3.lo $(TLIBS)
+sqldiff$(TEXE):	$(TOP)/tool/sqldiff.c libsqlite3.la
+	$(LTLINK) -o $@ $(TOP)/tool/sqldiff.c libsqlite3.la
 
-dbhash$(TEXE):	$(TOP)/tool/dbhash.c sqlite3.lo sqlite3.h
-	$(LTLINK) -o $@ $(TOP)/tool/dbhash.c sqlite3.lo $(TLIBS)
+dbhash$(TEXE):	$(TOP)/tool/dbhash.c libsqlite3.la
+	$(LTLINK) -o $@ $(TOP)/tool/dbhash.c libsqlite3.la
 
-scrub$(TEXE):	$(TOP)/ext/misc/scrub.c sqlite3.lo
+scrub$(TEXE):	$(TOP)/ext/misc/scrub.c libsqlite3.la
 	$(LTLINK) -o $@ -I. -DSCRUB_STANDALONE \
-		$(TOP)/ext/misc/scrub.c sqlite3.lo $(TLIBS)
+		$(TOP)/ext/misc/scrub.c libsqlite3.la
 
 srcck1$(BEXE):	$(TOP)/tool/srcck1.c
 	$(BCC) -o srcck1$(BEXE) $(TOP)/tool/srcck1.c
@@ -776,7 +786,7 @@
 # Rule to build the amalgamation
 #
 sqlite3.lo:	sqlite3.c
-	$(LTCOMPILE) $(TEMP_STORE) -c sqlite3.c
+	$(LTCOMPILE) $(SHELL_OPT) $(TEMP_STORE) -c sqlite3.c
 
 # Rules to build the LEMON compiler generator
 #
@@ -1082,18 +1092,6 @@
 # Source files that go into making shell.c
 SHELL_SRC = \
 	$(TOP)/src/shell.c.in \
-        $(TOP)/ext/misc/appendvfs.c \
-	$(TOP)/ext/misc/completion.c \
-        $(TOP)/ext/misc/decimal.c \
-	$(TOP)/ext/misc/fileio.c \
-        $(TOP)/ext/misc/ieee754.c \
-        $(TOP)/ext/misc/series.c \
-	$(TOP)/ext/misc/shathree.c \
-	$(TOP)/ext/misc/sqlar.c \
-        $(TOP)/ext/misc/uint.c \
-	$(TOP)/ext/expert/sqlite3expert.c \
-	$(TOP)/ext/expert/sqlite3expert.h \
-	$(TOP)/ext/misc/zipfile.c \
 	$(TOP)/ext/misc/memtrace.c \
         $(TOP)/src/test_windirent.c
 
@@ -1263,11 +1261,11 @@
 
 # Fuzz testing
 fuzztest:	fuzzcheck$(TEXE) $(FUZZDATA) sessionfuzz$(TEXE) $(TOP)/test/sessionfuzz-data1.db
-	./fuzzcheck$(TEXE) $(FUZZDATA)
+	./fuzzcheck$(TEXE) --timeout 3600 $(FUZZDATA)
 	./sessionfuzz$(TEXE) run $(TOP)/test/sessionfuzz-data1.db
 
 valgrindfuzz:	fuzzcheck$(TEXT) $(FUZZDATA) sessionfuzz$(TEXE) $(TOP)/test/sessionfuzz-data1.db
-	valgrind ./fuzzcheck$(TEXE) --cell-size-check --limit-mem 10M --timeout 600 $(FUZZDATA)
+	valgrind ./fuzzcheck$(TEXE) --cell-size-check --limit-mem 10M --timeout 3600 $(FUZZDATA)
 	valgrind ./sessionfuzz$(TEXE) run $(TOP)/test/sessionfuzz-data1.db
 
 # The veryquick.test TCL tests.
@@ -1301,24 +1299,23 @@
 shelltest: $(TESTPROGS)
 	./testfixture$(TEXT) $(TOP)/test/permutations.test shell
 
-sqlite3_analyzer.c: sqlite3.c $(TOP)/src/tclsqlite.c $(TOP)/tool/spaceanal.tcl $(TOP)/tool/mkccode.tcl $(TOP)/tool/sqlite3_analyzer.c.in
+sqlite3_analyzer.c:	$(TOP)/src/tclsqlite.c $(TOP)/tool/spaceanal.tcl $(TOP)/tool/mkccode.tcl $(TOP)/tool/sqlite3_analyzer.c.in
 	$(TCLSH_CMD) $(TOP)/tool/mkccode.tcl $(TOP)/tool/sqlite3_analyzer.c.in >sqlite3_analyzer.c
 
-sqlite3_analyzer$(TEXE): sqlite3_analyzer.c
-	$(LTLINK) sqlite3_analyzer.c -o $@ $(LIBTCL) $(TLIBS)
+sqlite3_analyzer$(TEXE):	sqlite3_analyzer.c libsqlite3.la
+	$(LTLINK) sqlite3_analyzer.c -o $@ libsqlite3.la $(LIBTCL)
 
-sqltclsh.c: sqlite3.c $(TOP)/src/tclsqlite.c $(TOP)/tool/sqltclsh.tcl $(TOP)/ext/misc/appendvfs.c $(TOP)/tool/mkccode.tcl $(TOP)/tool/sqltclsh.c.in
+sqltclsh.c:	$(TOP)/src/tclsqlite.c $(TOP)/tool/sqltclsh.tcl $(TOP)/tool/mkccode.tcl $(TOP)/tool/sqltclsh.c.in
 	$(TCLSH_CMD) $(TOP)/tool/mkccode.tcl $(TOP)/tool/sqltclsh.c.in >sqltclsh.c
 
-sqltclsh$(TEXE): sqltclsh.c
-	$(LTLINK) sqltclsh.c -o $@ $(LIBTCL) $(TLIBS)
+sqltclsh$(TEXE):	sqltclsh.c libsqlite3.la
+	$(LTLINK) sqltclsh.c -o $@ libsqlite3.la $(LIBTCL)
 
-sqlite3_expert$(TEXE): $(TOP)/ext/expert/sqlite3expert.h $(TOP)/ext/expert/sqlite3expert.c $(TOP)/ext/expert/expert.c sqlite3.c
-	$(LTLINK)	$(TOP)/ext/expert/sqlite3expert.h $(TOP)/ext/expert/sqlite3expert.c $(TOP)/ext/expert/expert.c sqlite3.c -o sqlite3_expert $(TLIBS)
+sqlite3_expert$(TEXE):	$(TOP)/ext/expert/sqlite3expert.h $(TOP)/ext/expert/expert.c libsqlite3.la
+	$(LTLINK) $(TOP)/ext/expert/expert.c -o sqlite3_expert libsqlite3.la
 
 CHECKER_DEPS =\
   $(TOP)/tool/mkccode.tcl \
-  sqlite3.c \
   $(TOP)/src/tclsqlite.c \
   $(TOP)/ext/repair/sqlite3_checker.tcl \
   $(TOP)/ext/repair/checkindex.c \
@@ -1329,36 +1326,36 @@
 sqlite3_checker.c:	$(CHECKER_DEPS)
 	$(TCLSH_CMD) $(TOP)/tool/mkccode.tcl $(TOP)/ext/repair/sqlite3_checker.c.in >$@
 
-sqlite3_checker$(TEXE):	sqlite3_checker.c
-	$(LTLINK) sqlite3_checker.c -o $@ $(LIBTCL) $(TLIBS)
+sqlite3_checker$(TEXE):	sqlite3_checker.c libsqlite3.la
+	$(LTLINK) sqlite3_checker.c -o $@ libsqlite3.la $(LIBTCL)
 
-dbdump$(TEXE): $(TOP)/ext/misc/dbdump.c sqlite3.lo
+dbdump$(TEXE):	$(TOP)/ext/misc/dbdump.c libsqlite3.la
 	$(LTLINK) -DDBDUMP_STANDALONE -o $@ \
-           $(TOP)/ext/misc/dbdump.c sqlite3.lo $(TLIBS)
+           $(TOP)/ext/misc/dbdump.c libsqlite3.la
 
-dbtotxt$(TEXE): $(TOP)/tool/dbtotxt.c
-	$(LTLINK)-o $@ $(TOP)/tool/dbtotxt.c
+dbtotxt$(TEXE):	$(TOP)/tool/dbtotxt.c
+	$(LTLINK) -o $@ $(TOP)/tool/dbtotxt.c
 
-showdb$(TEXE):	$(TOP)/tool/showdb.c sqlite3.lo
-	$(LTLINK) -o $@ $(TOP)/tool/showdb.c sqlite3.lo $(TLIBS)
+showdb$(TEXE):	$(TOP)/tool/showdb.c libsqlite3.la
+	$(LTLINK) -o $@ $(TOP)/tool/showdb.c libsqlite3.la
 
-showstat4$(TEXE):	$(TOP)/tool/showstat4.c sqlite3.lo
-	$(LTLINK) -o $@ $(TOP)/tool/showstat4.c sqlite3.lo $(TLIBS)
+showstat4$(TEXE):	$(TOP)/tool/showstat4.c libsqlite3.la
+	$(LTLINK) -o $@ $(TOP)/tool/showstat4.c libsqlite3.la
 
-showjournal$(TEXE):	$(TOP)/tool/showjournal.c sqlite3.lo
-	$(LTLINK) -o $@ $(TOP)/tool/showjournal.c sqlite3.lo $(TLIBS)
+showjournal$(TEXE):	$(TOP)/tool/showjournal.c
+	$(LTLINK) -o $@ $(TOP)/tool/showjournal.c
 
-showwal$(TEXE):	$(TOP)/tool/showwal.c sqlite3.lo
-	$(LTLINK) -o $@ $(TOP)/tool/showwal.c sqlite3.lo $(TLIBS)
+showwal$(TEXE):	$(TOP)/tool/showwal.c
+	$(LTLINK) -o $@ $(TOP)/tool/showwal.c
 
 showshm$(TEXE):	$(TOP)/tool/showshm.c
 	$(LTLINK) -o $@ $(TOP)/tool/showshm.c
 
-index_usage$(TEXE): $(TOP)/tool/index_usage.c sqlite3.lo
-	$(LTLINK) $(SHELL_OPT) -o $@ $(TOP)/tool/index_usage.c sqlite3.lo $(TLIBS)
+index_usage$(TEXE):	$(TOP)/tool/index_usage.c libsqlite3.la
+	$(LTLINK) -o $@ $(TOP)/tool/index_usage.c libsqlite3.la
 
-changeset$(TEXE):	$(TOP)/ext/session/changeset.c sqlite3.lo
-	$(LTLINK) -o $@ $(TOP)/ext/session/changeset.c sqlite3.lo $(TLIBS)
+changeset$(TEXE):	$(TOP)/ext/session/changeset.c libsqlite3.la
+	$(LTLINK) -o $@ $(TOP)/ext/session/changeset.c libsqlite3.la
 
 changesetfuzz$(TEXE):	$(TOP)/ext/session/changesetfuzz.c sqlite3.lo
 	$(LTLINK) -o $@ $(TOP)/ext/session/changesetfuzz.c sqlite3.lo $(TLIBS)
@@ -1383,11 +1380,11 @@
 kvtest$(TEXE):	$(TOP)/test/kvtest.c sqlite3.c
 	$(LTLINK) $(KV_OPT) -o $@ $(TOP)/test/kvtest.c sqlite3.c $(TLIBS)
 
-rbu$(EXE): $(TOP)/ext/rbu/rbu.c $(TOP)/ext/rbu/sqlite3rbu.c sqlite3.lo
-	$(LTLINK) -I. -o $@ $(TOP)/ext/rbu/rbu.c sqlite3.lo $(TLIBS)
+rbu$(EXE):	$(TOP)/ext/rbu/rbu.c libsqlite3.la
+	$(LTLINK) -I. -o $@ $(TOP)/ext/rbu/rbu.c libsqlite3.la
 
-loadfts$(EXE): $(TOP)/tool/loadfts.c libsqlite3.la
-	$(LTLINK) $(TOP)/tool/loadfts.c libsqlite3.la -o $@ $(TLIBS)
+loadfts$(EXE):	$(TOP)/tool/loadfts.c libsqlite3.la
+	$(LTLINK) $(TOP)/tool/loadfts.c libsqlite3.la -o $@
 
 # This target will fail if the SQLite amalgamation contains any exported
 # symbols that do not begin with "sqlite3_". It is run as part of the
--- /configure.ac
+++ /configure.ac
@@ -108,7 +108,7 @@
 #########
 # Figure out whether or not we have these functions
 #
-AC_CHECK_FUNCS([fdatasync gmtime_r isnan localtime_r localtime_s malloc_usable_size strchrnul usleep utime pread pread64 pwrite pwrite64])
+AC_CHECK_FUNCS([fdatasync fullfsync gmtime_r isnan localtime_r localtime_s malloc_usable_size posix_fallocate pread pread64 pwrite pwrite64 strchrnul usleep utime])
 
 #########
 # By default, we use the amalgamation (this may be changed below...)
@@ -582,6 +582,9 @@
 if test "${enable_load_extension}" = "yes" ; then
   OPT_FEATURE_FLAGS=""
   AC_SEARCH_LIBS(dlopen, dl)
+  if test "${ac_cv_search_dlopen}" = "no" ; then
+    OPT_FEATURE_FLAGS="-DSQLITE_OMIT_LOAD_EXTENSION=1"
+  fi
 else
   OPT_FEATURE_FLAGS="-DSQLITE_OMIT_LOAD_EXTENSION=1"
 fi
