]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add basic libreadline detection and build CLI shell.
authorstephan <stephan@noemail.net>
Fri, 27 Sep 2024 13:29:50 +0000 (13:29 +0000)
committerstephan <stephan@noemail.net>
Fri, 27 Sep 2024 13:29:50 +0000 (13:29 +0000)
FossilOrigin-Name: 2ba7ab562580667bc9249f2d1f2402c605553d5583eec497398abe6d196c83d4

Makefile.in
auto.def
autosetup/hwaci-common.tcl
manifest
manifest.uuid

index 77f96a948ced24557deb11b4ffa7e47039209854..1e60d411b80e789394445c79fbc71081230ddee7 100644 (file)
@@ -62,9 +62,9 @@ TCC += @TARGET_DEBUG@
 #XX##
 #XX#LIBTCL = @TCL_LIB_SPEC@
 #XX#
-#XX## Compiler options needed for programs that use the readline() library.
-#XX##
-#XX#READLINE_FLAGS = -DHAVE_READLINE=@TARGET_HAVE_READLINE@ @TARGET_READLINE_INC@
+# Compiler options needed for programs that use the readline() library.
+#
+READLINE_FLAGS = -DHAVE_READLINE=@HAVE_READLINE@ @CFLAGS_READLINE@
 #XX#READLINE_FLAGS += -DHAVE_EDITLINE=@TARGET_HAVE_EDITLINE@
 #XX#READLINE_FLAGS += -DHAVE_LINENOISE=@TARGET_HAVE_LINENOISE@
 #XX#
@@ -76,9 +76,9 @@ TCC += @TARGET_DEBUG@
 #XX##
 #XX#TCC += -DSQLITE_THREADSAFE=@SQLITE_THREADSAFE@
 #XX#
-#XX## Any target libraries which libsqlite must be linked against
-#XX##
-#XX#TLIBS = @LIBS@ $(LIBS)
+# Any target libraries which libsqlite must be linked against
+#
+TLIBS = @LIBS@ $(LIBS)
 #XX#
 # Flags controlling use of the in memory btree implementation
 #
@@ -617,6 +617,7 @@ TESTOPTS = --verbose=file --output=test-out.txt
 
 # Extra compiler options for various shell tools
 #
+SHELL_OPT = @OPT_SHELL@
 SHELL_OPT += -DSQLITE_DQS=0
 SHELL_OPT += -DSQLITE_ENABLE_FTS4
 #SHELL_OPT += -DSQLITE_ENABLE_FTS5
@@ -675,12 +676,13 @@ DBFUZZ_OPT =
 ST_OPT = -DSQLITE_OS_KV_OPTIONAL
 
 
-# In wasi-sdk builds, disable the CLI shell build in the "all" target.
-SQLITE3_SHELL_TARGET_  = sqlite3$(TEXE)
-SQLITE3_SHELL_TARGET_1 =
-SQLITE3_SHELL_TARGET   = $(SQLITE3_SHELL_TARGET_@HAVE_WASI_SDK@)
-
-SQLITE3_O = $(TOP)/sqlite3.o
+# In wasi-sdk builds, disable the CLI shell build.
+@if HAVE_WASI_SDK
+  SQLITE3_SHELL_TARGET =
+@else
+  SQLITE3_SHELL_TARGET = sqlite3$(TEXE)
+@endif
+#XXX#??? SQLITE3_O = $(TOP)/sqlite3.o
 
 # Use $(libtclsqlite3.la_$(HAVE_TCL)) to resolve to either
 # libtclsqlite3.la or an empty value.
@@ -691,8 +693,8 @@ libtclsqlite3.la_1 = libtclsqlite3.la
 # are what get build when you type just "make" with no arguments.
 #
 
-all:   sqlite3.h sqlite3.c shell.c
-#all:  libsqlite3.la $(SQLITE3_SHELL_TARGET) \
+all:   sqlite3.h sqlite3.c shell.c $(SQLITE3_SHELL_TARGET)
+#all:  libsqlite3.la  \
 #XX#  $(libtclsqlite3.la_$(HAVE_TCL))
 
 # Re-run $(TOP)/configure with the same args invoked to produce this
@@ -723,10 +725,10 @@ sqlite_cfg.h: $(TOP)/sqlite_cfg.h.in $(AS_AUTO_DEF)
 #XX#           -version-info "8:6:8" \
 #XX#           -avoid-version
 #XX#
-#XX#sqlite3$(TEXE):    shell.c sqlite3.c
-#XX#   $(LTLINK) $(READLINE_FLAGS) $(SHELL_OPT) -o $@ \
-#XX#           shell.c sqlite3.c \
-#XX#           $(LIBREADLINE) $(TLIBS) -rpath "$(libdir)"
+sqlite3$(TEXE):        shell.c sqlite3.c
+       $(TCC) $(READLINE_FLAGS) $(SHELL_OPT) -o $@ \
+               shell.c sqlite3.c \
+               @LDFLAGS_RPATH@ @LDFLAGS_READLINE@ $(TLIBS)
 #XX#
 #XX#sqldiff$(TEXE):    $(TOP)/tool/sqldiff.c sqlite3.lo sqlite3.h
 #XX#   $(LTLINK) -o $@ $(TOP)/tool/sqldiff.c sqlite3.lo $(TLIBS)
index 10009d060ee4510b03ca6dd47bc41d2648d260c6..c5c972d4506b89ae7a79a7ed2fd32b53bc252ef6 100644 (file)
--- a/auto.def
+++ b/auto.def
@@ -38,7 +38,7 @@ options {
   releasemode          => {libtool link to release mode}
   with-tempstore:=no => {Use an in-ram database for temporary tables: never,no,yes,always.}
   editline=0           => {BSD editline support}
-  readline=0           => {readline support}
+  readline=1           => {Disable readline support}
   largefile=1          => {Disable large file support}
   with-readline-lib    => {readline library}
   with-readline-inc    => {readline include paths}
@@ -150,13 +150,19 @@ cc-check-tools ld ar
 ########################################################################
 # OPT_FEATURE_FLAGS = -DSQLITE_OMIT/ENABLE flags.
 define OPT_FEATURE_FLAGS {}
+define OPT_SHELL {}; # CFLAGS for the sqlite3 CLI app
 # Adds $flag, if not empty, to OPT_FEATURE_FLAGS.
-proc add-feature-flag {flag} {
-  if {"" ne $flag} {
-    define-append OPT_FEATURE_FLAGS $flag
+proc add-feature-flag {args} {
+  if {"" ne $args} {
+    define-append OPT_FEATURE_FLAGS {*}$args
   }
 }
 # add-feature-flag -DSQLITE_JUST_TESTING=3
+proc add-shell-opt {args} {
+  if {"" ne $args} {
+    define-append OPT_SHELL {*}$args
+  }
+}
 
 hwaci-check-exeext
 if {".exe" eq [get-define TARGET_EXEEXT]} {
@@ -206,10 +212,7 @@ define BUILD_CFLAGS [get-env CFLAGS {-g}]
 if {1} {
   set wasiSdkDir [opt-val with-wasi-sdk] ; # ??? [lindex [opt-val with-wasi-sdk] end]
   #puts "x wasiSdkDir=$wasiSdkDir foo=[lindex [opt-val with-wasi-sdk] end]"
-  if {$wasiSdkDir eq ""} {
-    define HAVE_WASI_SDK 0
-    define WASI_SDK_DIR ""
-  } else {
+  if {$wasiSdkDir ne ""} {
     msg-checking "Checking WASI SDK directory \[$wasiSdkDir]... "
     puts "prefix = [prefix $wasiSdkDir/bin {clang ld}]"
     hwaci-affirm-files-exist -v {*}[prefix "$wasiSdkDir/bin/" {clang wasm-ld}]
@@ -267,6 +270,8 @@ cc-check-lfs
 cc-check-types int8_t int16_t int32_t int64_t intptr_t \
   uint8_t uint16_t uint32_t uint64_t uintptr_t
 
+########################################################################
+# Check for needed/wanted functions
 cc-check-functions gmtime_r isnan localtime_r localtime_s \
   malloc_usable_size strchrnul usleep utime pread pread64 pwrite pwrite64
 
@@ -296,12 +301,17 @@ if {[cc-check-includes zlib.h] && [cc-check-function-in-lib deflate z]} {
 
 hwaci-define-if-opt-truthy amalgamation USE_AMALGAMATION \
   "Use amalgamation for builds?"
+
 hwaci-define-if-opt-truthy gcov USE_GCOV "Use gcov?"
+
 hwaci-define-if-opt-truthy test-status TSTRNNR_OPTS \
   "test-runner flags:" {--status} {}
+
 hwaci-define-if-opt-truthy linemacros AMALGAMATION_LINE_MACROS \
   "Use #line macros in the amalgamation:" {--linemacros=1} {--linemacros=0}
+
 msg-checking "Debug build? "
+
 hwaci-if-opt-truthy with-debug {
   define SQLITE_DEBUG 1
   define TARGET_DEBUG {-DSQLITE_DEBUG=1 -DSQLITE_ENABLE_SELECTTRACE -DSQLITE_ENABLE_WHERETRACE -O0 -Wall}
@@ -311,6 +321,8 @@ hwaci-if-opt-truthy with-debug {
   msg-result no
 }
 
+hwaci-check-rpath
+
 ########################################################################
 # TCL...
 define HAVE_TCL 0
@@ -530,10 +542,13 @@ if {1} {
   unset ts tsn
 }
 
-if {0} {
+if {1} {
   ##########
   # Figure out what C libraries are required to compile programs
   # that use "readline()" library.
+  hwaci-check-readline
+} else {
+  # Older impl solely for reference while porting...
   #
   # XXX TARGET_READLINE_LIBS=""
   # XXX TARGET_READLINE_INC=""
@@ -840,6 +855,10 @@ if {"" ne $oFF} {
   define OPT_FEATURE_FLAGS [lsort -unique $oFF]
   msg-result "Final feature flags: [get-define OPT_FEATURE_FLAGS]"
 }
+set oFF [get-define SHELL_OPT]
+if {"" ne $oFF} {
+  msg-result "Final shell opts: [get-define OPT_SHELL]"
+}
 unset oFF
 
 hwaci-if-opt-truthy dump-defines {
index 72219f385116d64aee1bfde04d5d27a554923a60..3da0961c54d6342ce9bc4d0a06b9ac71ee367ae0 100644 (file)
@@ -61,7 +61,7 @@ proc hwaci-lshift- {listVar {count 1}} {
 # routine makes to the LIBS define. Returns the result of
 # cc-check-function-in-lib.
 proc hwaci-check-function-in-lib {function libs {otherlibs {}}} {
-  set found ""
+  set found 0
   define-push {LIBS} {
     set found [cc-check-function-in-lib $function $libs $otherlibs]
   }
@@ -425,9 +425,11 @@ proc hwaci-check-profile-flag {{flagname profile}} {
 # Returns 1 if this appears to be a Windows environment (MinGw,
 # Cygwin, MSys), else returns 0. The optional argument is the name of
 # an autosetup define which contains platform name info, defaulting to
-# "host". The other legal value is "build" (the build machine). If
-# $key == "build" then some additional checks may be performed which
-# are not applicable when $key == "host".
+# "host" (meaning, somewhat counterintuitively, the target system, not
+# the current host). The other legal value is "build" (the build
+# machine, i.e. the local host). If $key == "build" then some
+# additional checks may be performed which are not applicable when
+# $key == "host".
 proc hwaci-looks-like-windows {{key host}} {
   global autosetup
   switch -glob -- [get-define $key] {
@@ -447,14 +449,14 @@ proc hwaci-looks-like-windows {{key host}} {
 }
 
 ########################################################################
-# Checks autosetup's "host" and "target" defines to see if the build
+# Checks autosetup's "host" and "build" defines to see if the build
 # host and target are Windows-esque (Cygwin, MinGW, MSys). If the
-# build host is then BUILD_EXEEXT is [define]'d to ".exe", else "". If
-# the build target is then TARGET_EXEEXT is [define]'d to ".exe", else
-# "".
+# build environment is then BUILD_EXEEXT is [define]'d to ".exe", else
+# "". If the target, a.k.a. "host", is then TARGET_EXEEXT is
+# [define]'d to ".exe", else "".
 proc hwaci-check-exeext {} {
   msg-checking "Build host is Windows-esque? "
-  if {[hwaci-looks-like-windows host]} {
+  if {[hwaci-looks-like-windows build]} {
     define BUILD_EXEEXT ".exe"
     msg-result yes
   } else {
@@ -463,7 +465,7 @@ proc hwaci-check-exeext {} {
   }
 
   msg-checking "Build target is Windows-esque? "
-  if {[hwaci-looks-like-windows target]} {
+  if {[hwaci-looks-like-windows host]} {
     define TARGET_EXEEXT ".exe"
     msg-result yes
   } else {
@@ -549,3 +551,54 @@ proc hwaci-check-emsdk {} {
   define HAVE_EMSDK $rc
   return $rc
 }
+
+########################################################################
+# Tries various approaches to handling the -rpath link-time
+# flag. Defines LDFLAGS_RPATH to that/those flag(s) or an empty
+# string. Returns 1 if it finds an option, else 0.
+proc hwaci-check-rpath {} {
+  if {[cc-check-flags -Wl,-R/tmp]} {
+    define LDFLAGS_RPATH "-Wl,-R[get-define libdir]"
+    return 1
+  } elseif {[cc-check-flags -Wl,-rpath -Wl,/tmp]} {
+    define LDFLAGS_RPATH "-Wl,-rpath -Wl,[get-define libdir]"
+    return 1
+  } else {
+    define LDFLAGS_RPATH ""
+    return 0
+  }
+}
+
+########################################################################
+# Under construction - check for libreadline functionality
+proc hwaci-check-readline {} {
+  define HAVE_READLINE 0
+  define LDFLAGS_READLINE ""
+  define CFLAGS_READLINE ""
+  define READLINE_H ""
+  if {![opt-bool readline]} {
+    msg-result "libreadline disabled via --disable-readline."
+    return 0
+  }
+  set h "readline/readline.h"
+  if {[cc-check-includes $h]} {
+    define READLINE_H $h
+    if {[hwaci-check-function-in-lib readline readline]} {
+      msg-result "Enabling libreadline."
+      define HAVE_READLINE 1
+      define LDFLAGS_READLINE [get-define lib_readline]
+      undefine lib_readline
+      return 1
+    }
+    # else TODO: look in various places and [define CFLAGS_READLINE
+    # -I...]
+  }
+  # Numerous TODOs:
+  # - Requires linking with ncurses or similar on some platforms.
+  # - Headers are in a weird place on some BSD systems.
+  # - Add --with-readline=DIR
+  # - Add --with-readline-lib=lib file
+  # - Add --with-readline-inc=dir -Idir
+  msg-result "libreadline not found."
+  return 0
+}
index ee7e3844a2e169bdffb3d2a564c654d8a98c92b7..bf80bfb4cb3b94358a81ee413f9d702a2f401897 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,9 +1,9 @@
-C General\stinkering\sand\scleanups\sin\sthe\sautosetup\sbits.
-D 2024-09-27T12:15:14.956
+C Add\sbasic\slibreadline\sdetection\sand\sbuild\sCLI\sshell.
+D 2024-09-27T13:29:50.775
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
-F Makefile.in 5ac6defaba5f19e487a02c920bdffd42033e2be31172fefaff40cbf997d42947
+F Makefile.in 5253a425c9167286a21b2393d4293c197914c135e35ef3fdea7b1334df98c9cc
 F Makefile.linux-gcc f3842a0b1efbfbb74ac0ef60e56b301836d05b4d867d014f714fa750048f1ab6
 F Makefile.msc e3c4723c27464acc31da4420b808c8d2690180ba2b915897bece0a9d5d2cecf6
 F README.md c3c0f19532ce28f6297a71870f3c7b424729f0e6d9ab889616d3587dd2332159
@@ -14,7 +14,7 @@ F art/icon-80x90.gif 65509ce3e5f86a9cd64fe7fca2d23954199f31fe44c1e09e208c80fb83d
 F art/sqlite370.eps aa97a671332b432a54e1d74ff5e8775be34200c2
 F art/sqlite370.ico af56c1d00fee7cd4753e8631ed60703ed0fc6e90
 F art/sqlite370.jpg d512473dae7e378a67e28ff96a34da7cb331def2
-F auto.def 63a9d902a3326370aed3698c961161b6f1d975c047fa110e7ea9bcb83c8cd006
+F auto.def 6e46e578f319e20c2469c90c0e54f4c08c246d136b2b20962ba8281c715c3b4b
 F autoconf/INSTALL 83e4a25da9fd053c7b3665eaaaf7919707915903
 F autoconf/Makefile.am adedc1324b6a87fdd1265ddd336d2fb7d4f36a0e77b86ea553ae7cc4ea239347
 F autoconf/Makefile.fallback 22fe523eb36dfce31e0f6349f782eb084e86a5620b2b0b4f84a2d6133f53f5ac
@@ -46,7 +46,7 @@ F autosetup/cc-lib.tcl 493c5935b5dd3bf9bd4eca89b07c8b1b1a9356d61783035144e21795f
 F autosetup/cc-shared.tcl 4f024e94a47f427ba61de1739f6381ef0080210f9fae89112d5c1de1e5460d78
 F autosetup/cc.tcl 1b52de228642c1db5a714d54ca974d723ec8b4092e8c3765d348b625850f7311
 F autosetup/default.auto 5cdf016de2140e50f1db190a02039dc42fb390af1dda4cc4853e3042a9ef0e82
-F autosetup/hwaci-common.tcl c6638a9ffb180ed2b240357c443ca60cc16d48d15c6e492b2965d2197ef0fb37
+F autosetup/hwaci-common.tcl bd3321e80b92eb0644be4f05df44d5c98ab415b2c7dc10866303dfe5ba77592a
 F autosetup/jimsh0.c 1b5fe91fffcddbc29f2b16acb80f1650632ea2edbe8336b8155ef7b4c66f6d8d
 F autosetup/pkg-config.tcl 4e635bf39022ff65e0d5434339dd41503ea48fc53822c9c5bde88b02d3d952ba
 F autosetup/system.tcl 3a39d6e0b3bfba526fd39afe07c1d0d325e5a31925013a1ba7c671e1128e31bb
@@ -2233,8 +2233,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P a7ff8f3c2c86f435a08d568a07f019a59dcca8f66a719d242289fa0c7097c2af
-R 35d30a680586fc0d89ef4699e74bef45
+P a290e3b15de75f6a0a4975b5747449525fb2b58b3947b8ca0ab64a4d3cca228e
+R 00136067f886dfec24f53eea1a13e92a
 U stephan
-Z b93d9def15ae319c294048d66bd247b2
+Z 89712eb4fe24753b96ac2cf6bb7cec31
 # Remove this line to create a well-formed Fossil manifest.
index dbf92f2b43edb6f2a49b4a439b57098e41483bf6..a944e85909d16796693943fd6e277fa9265eb066 100644 (file)
@@ -1 +1 @@
-a290e3b15de75f6a0a4975b5747449525fb2b58b3947b8ca0ab64a4d3cca228e
+2ba7ab562580667bc9249f2d1f2402c605553d5583eec497398abe6d196c83d4