]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Update teaish to the latest upstream copy. Move some of its utility code into proj...
authorstephan <stephan@noemail.net>
Mon, 14 Apr 2025 23:52:11 +0000 (23:52 +0000)
committerstephan <stephan@noemail.net>
Mon, 14 Apr 2025 23:52:11 +0000 (23:52 +0000)
FossilOrigin-Name: 921c5ea76925be911222ac5f2887b8a967ff47b1aa43e196231e6168a3f9cb88

autoconf/tea/autosetup/core.tcl
autoconf/tea/autosetup/feature-tests.tcl
autoconf/tea/autosetup/tester.tcl
autoconf/tea/teaish.tcl
autosetup/proj.tcl
manifest
manifest.uuid

index 5cdfd6a14b6301dbeac22b310615afd0f6b72ab4..8b781793f24562073a1aa3d95237766f6eed0536 100644 (file)
@@ -29,12 +29,28 @@ if {"--help" ni $::argv} {
   proj-tweak-default-env-dirs
   msg-result "Source dir  = $::autosetup(srcdir)"
   msg-result "Build dir   = $::autosetup(builddir)"
-  msg-result "TEA-ish Version = [get-define TEAISH_VERSION]"
+  msg-result "TEA(ish) Version = [get-define TEAISH_VERSION]"
 }
 
-array set teaishConfig [proj-strip-hash-comments {
+#
+# API-internal settings and shared state.
+array set teaish__Config [proj-strip-hash-comments {
   # set to 1 to enable some internal debugging output
   debug-enabled 0
+  #
+  # 0    = default
+  # 0x01 = teaish__find-extension found input in TEAISH_DIR
+  # 0x02 = teaish__find-extension found input in srcdir
+  # 0x04 = teaish__find-extension found output file but no input
+  # 0x10 = teaish-pragma was called: use their pkgIndex.tcl
+  #
+  pkgindex-policy 0
+
+  #
+  # A list of lists of Autosetup [options]-format --flags definitions.
+  # Append to this using [teaish-append-options].
+  #
+  extra-options {}
 }]
 
 #
@@ -58,18 +74,20 @@ proc teaish-configure-core {} {
   #
   # "Declare" some defines for potential later use.
   #
-  foreach f {
-    TEAISH_MAKEFILE
-    TEAISH_MAKEFILE_IN
-    TEAISH_TCL
-    TEAISH_CFLAGS
-    TEAISH_LDFLAGS
-    TEAISH_SRC
-    TEAISH_DIST_FILES
-    TEAISH_PKGINIT_TCL
-    EXTRA_CFLAGS
+  foreach {f v} {
+    TEAISH_MAKEFILE ""
+    TEAISH_MAKEFILE_IN ""
+    TEAISH_TCL ""
+    TEAISH_CFLAGS ""
+    TEAISH_LDFLAGS ""
+    TEAISH_SRC ""
+    TEAISH_DIST_FILES ""
+    TEAISH_PKGINIT_TCL ""
+    TEAISH_PKGINDEX_TCL_IN ""
+    TEAISH_PKGINDEX_TCL ""
+    EXTRA_CFLAGS ""
   } {
-    define $f {}
+    define $f $v
   }
 
   set gotExt 0; # True if an extension config is found
@@ -78,18 +96,20 @@ proc teaish-configure-core {} {
   }
 
   if {$gotExt} {
-    proj-assert {[file exists [get-define TEAISH_TCL]]}
-    uplevel 1 {
-      source [get-define TEAISH_TCL]
-    }
-
+    set ttcl [get-define TEAISH_TCL]
+    proj-assert {[file exists $ttcl]} "Expecting to have found teaish.tcl by now"
+    uplevel 1 "source $ttcl"
     if {"" eq [get-define TEAISH_NAME ""]} {
-      proj-fatal "[get-define TEAISH_TCL] did not define TEAISH_NAME"
+      proj-fatal "$ttcl did not define TEAISH_NAME"
     } elseif {"" eq [get-define TEAISH_VERSION ""]} {
-      proj-fatal "[get-define TEAISH_TCL] did not define TEAISH_VERSION"
+      proj-fatal "$ttcl did not define TEAISH_VERSION"
     }
-  }
+    unset ttcl
+  }; # sourcing extension's teaish.tcl
 
+  #
+  # Set up the --flags...
+  #
   set opts [proj-strip-hash-comments {
     with-tcl:DIR
       => {Directory containing tclConfig.sh or a directory one level up from
@@ -116,7 +136,7 @@ proc teaish-configure-core {} {
     # As of this spontaneous moment, we'll formalize using using
     # --t-X-Y to abbreviate teaish flags when doing so is
     # unambiguous...
-    t-e-d:
+    ted: t-e-d:
     teaish-extension-dir:DIR
       => {Looks for an extension in the given directory instead of the current dir.}
 
@@ -136,13 +156,22 @@ proc teaish-configure-core {} {
     teaish-debug => {Enable teaish-specific debug output}
   }]; # $opts
 
+  #
+  # Create the full options list from:
+  # 1) $opts
+  # 2) [teaish-options], if defined
+  # 3) $::teaish__Config(exta-options)
+  #
+  set optLists [list $opts]
   if {[llength [info proc teaish-options]] > 0} {
-    # teaish-options is assumed to be imported via
-    # TEAISH_TCL
-    set opts [teaish-combine-option-lists $opts [teaish-options]]
+    # teaish-options is assumed to be imported via TEAISH_TCL.
+    lappend optLists [teaish-options]
   }
+  lappend optLists {*}$::teaish__Config(extra-options)
+  set opts [teaish-combine-option-lists {*}$optLists]
+  unset optLists
 
-  #lappend opts "soname:=duplicateEntry => {x}"; #just testing
+  #lappend opts teaish-debug => {x}; #testing dupe entry handling
   if {[catch {options $opts} msg xopts]} {
     # Workaround for <https://github.com/msteveb/autosetup/issues/73>
     # where [options] behaves oddly on _some_ TCL builds when it's
@@ -160,7 +189,7 @@ proc teaish-configure-core {} {
     t-f    => teaish-force
   }
 
-  set ::teaishConfig(debug-enabled) [opt-bool teaish-debug]
+  set ::teaish__Config(debug-enabled) [opt-bool teaish-debug]
 
   if {[proj-opt-was-provided teaish-create-extension]} {
     teaish__create-extension [opt-val teaish-create-extension]
@@ -176,7 +205,7 @@ proc teaish-configure-core {} {
 # Internal config-time debugging output routine. It is not legal to
 # call this from the global scope.
 proc teaish-debug {msg} {
-  if {$::teaishConfig(debug-enabled)} {
+  if {$::teaish__Config(debug-enabled)} {
     puts stderr [proj-bold "** DEBUG: \[[proj-current-scope 1]\]: $msg"]
   }
 }
@@ -242,11 +271,17 @@ proc teaish__configure-phase1 {} {
     define TEAISH_DLL9 [get-define TEAISH_DLL9_BASENAME]$ext
   }}
 
+#  foreach ft [glob -nocomplain [get-define TEAISH_AUTOSETUP_DIR]/featuretest-*.tcl] {
+#    puts "Loading external feature test: $ft"
+#    upscope 1 "source $ft"
+#  }
+
   if {[llength [info proc teaish-configure]] > 0} {
     # teaish-options is assumed to be imported via
     # TEAISH_TCL
     teaish-configure
   }
+
   if {[proj-looks-like-windows]} {
     # Without this, linking of an extension will not work on Cygwin or
     # Msys2.
@@ -254,17 +289,11 @@ proc teaish__configure-phase1 {} {
     teaish-add-cflags -DUSE_TCL_STUBS=1
   }
 
-  #
-  # Ensure we don't have a stale pkgIndex.tcl when rebuilding for different
-  # --with-tcl=... values.
-  #
-  file delete -force pkgIndex.tcl
-
   define TEAISH_TEST_TCL \
     [join [glob -nocomplain [get-define TEAISH_DIR]/teaish.test.tcl]]
 
   #define AS_LIBDIR $::autosetup(libdir)
-  define TEAISH_LIBDIR $::autosetup(libdir)/teaish
+  define TEAISH_CORE_DIR $::autosetup(libdir)/teaish
   define TEAISH_MODULE_TEST_TCL $::autosetup(libdir)/teaish/tester.tcl
   define TEAISH_TESTER_TCL $::autosetup(builddir)/teaish.tester.tcl
   teaish__configure-finalize
@@ -279,7 +308,6 @@ proc teaish__configure-finalize {} {
       TEAISH_TCL
       TEAISH_MAKEFILE_IN
       TEAISH_TEST_TCL
-      TEAISH_PKGINIT_TCL
     } {
       set x [get-define $d ""]
       if {"" ne $x} {
@@ -289,6 +317,46 @@ proc teaish__configure-finalize {} {
     teaish-add-dist {*}$df
   }}
 
+  #
+  # Ensure we have a pkgIndex.tcl and don't have a stale generated one
+  # when rebuilding for different --with-tcl=... values. Also take
+  # care not to nuke it if pkgindex-policy is 1.
+  #
+  apply {{} {
+    set policy $::teaish__Config(pkgindex-policy);
+    set src ""; # input source for pkgIndex.tcl
+    if {$policy & 0x10} {
+      # teaish-pragma --have-own-pkgIndex.tcl override. This means
+      # we have a static/non-generated pkgIndex.tcl.
+      define TEAISH_PKGINDEX_TCL_IN ""
+      set tpt [get-define TEAISH_PKGINDEX_TCL ""]
+      if {"" eq $tpt} {
+        set tpt [file join [get-define TEAISH_DIR] pkgIndex.tcl]
+        define TEAISH_PKGINDEX_TCL $tpt
+      }
+      set src $tpt
+    } elseif {$policy & 0x04} {
+      # Found output file in TEAISH_DIR but no input file, so
+      # assume it's a hand-written one.
+      set src [get-define TEAISH_PKGINDEX_TCL]
+    } elseif {$policy} {
+      # Found input pkgIndex.tcl.in TEAISH_DIR or srcdir
+      set src [get-define TEAISH_PKGINDEX_TCL_IN]
+    } else {
+      proj-fatal "Cannot determine the pkgIndex.tcl to use"
+    }
+    msg-result "Using pkgIndex from $src"
+  }}; # $::teaish__Config(pkgindex-policy)
+
+  proj-dot-ins-append $::autosetup(srcdir)/Makefile.in
+  proj-dot-ins-append $::autosetup(srcdir)/teaish.tester.tcl.in
+
+  if {[get-define TEAISH_OUT_OF_EXT_TREE]} {
+    define TEAISH_ENABLE_DIST 0
+  }
+
+  define TEAISH_AUTOSETUP_DIR $::autosetup(libdir)/teaish
+  proj-setup-autoreconfig TEAISH_AUTORECONFIG
   foreach f {
     TEAISH_CFLAGS
     TEAISH_LDFLAGS
@@ -297,26 +365,11 @@ proc teaish__configure-finalize {} {
   } {
     define $f [join [get-define $f]]
   }
-
-  if {[get-define TEAISH_OUT_OF_EXT_TREE]} {
-    define TEAISH_ENABLE_DIST 0
-  }
-
-  define TEAISH_AUTOSETUP_DIR $::autosetup(libdir)
-  proj-setup-autoreconfig TEAISH_AUTORECONFIG
-  proj-dot-ins-append $::autosetup(srcdir)/Makefile.in
-  proj-dot-ins-append $::autosetup(srcdir)/pkgIndex.tcl.in
-  proj-dot-ins-append $::autosetup(srcdir)/teaish.tester.tcl.in
-
-  set dotIns [proj-dot-ins-list]
-  #puts "*** dotIns = $dotIns"
-  proj-dot-ins-process; # do not [define] after this point
-  foreach e $dotIns {
-    proj-validate-no-unresolved-ats [lindex $e 1]
-  }
-
+  define TEAISH__DEFINES_MAP [teaish__dump_defs_to_list]
+  proj-dot-ins-process -validate; # do not [define] after this point
   proj-if-opt-truthy teaish-dump-defines {
     make-config-header config.defines.txt \
+      -none {TEAISH__*} \
       -str {BIN_* CC LD AR INSTALL LDFLAG*} \
       -bare {HAVE_*} \
       -str {TEAISH_DIST_FILES} \
@@ -546,9 +599,15 @@ proc teaish__check-tcl {} {
 
 #
 # Searches $::argv and/or the build dir and/or the source dir for
-# teaish.make and teaish.tcl. Fails if it cannot find one of
-# them. If it returns 0 then it did not find an extension but the
-# --help flag was seen, in which case that's not an error.
+# teaish.tcl and friends. Fails if it cannot find teaish.tcl or if
+# there are other irreconcilable problems. If it returns 0 then it did
+# not find an extension but the --help flag was seen, in which case
+# that's not an error.
+#
+# This does not _load_ the extension, it simply locates the files
+# which make up an extension.
+#
+# This sets up lots of defines, e.g. TEAISH_DIR.
 #
 proc teaish__find-extension {} {
 
@@ -625,9 +684,10 @@ proc teaish__find-extension {} {
     }
   }
   set ::argv $largv
-  set dbld $::autosetup(builddir)
-  set dsrc $::autosetup(srcdir)
-  set dext [get-define TEAISH_DIR $dbld]
+  set dbld $::autosetup(builddir); # dir we're configuring under
+  set dsrc $::autosetup(srcdir);   # where teaish's configure script lives
+  set dext [get-define TEAISH_DIR $dbld] ; # dir with the extension
+  set extEqSrc [expr {$dext eq $dsrc}]   ; # are we building in-tree vis-a-vis teaish core?
 
   #
   # teaish.tcl is a TCL script which implements various
@@ -637,7 +697,7 @@ proc teaish__find-extension {} {
   #
   if {"" eq $extT} {
     set flist [list $dext/teaish.tcl]
-    if {[lindex $flist 0] ne "$dsrc/teaish.tcl"} {
+    if {!$extEqSrc} {
       lappend flist $dsrc/teaish.tcl
     }
     if {![proj-first-file-found $flist extT]} {
@@ -654,13 +714,14 @@ use --teaish-extension-dir=/path/to/extension"
   if {![file readable $extT]} {
     proj-fatal "extension tcl file is not readable: $extT"
   }
-  msg-result "Extension config         = $extT"
+  msg-result "Extension config           = $extT"
   define TEAISH_TCL $extT
   if {"" eq [get-define TEAISH_DIR ""]} {
-    # If this wasn't set via --teaish.dir then derive it from
-    # --teaish.tcl.
-    #puts "extT=$extT"
-    define TEAISH_DIR [file dirname $extT]
+    # If this wasn't set via --teaish-extension-dir then derive it from
+    # $extT.
+    #puts "extT=$extT dext=$dext"
+    set dext [file dirname $extT]
+    define TEAISH_DIR $dext
   }
 
   #
@@ -672,7 +733,7 @@ use --teaish-extension-dir=/path/to/extension"
   #
   if {"" eq $extM} {
     set flist [list $dext/teaish.make.in]
-    if {[lindex $flist 0] ne "$dsrc/teaish.make.in"} {
+    if {!$extEqSrc} {
       lappend flist $dsrc/teaish.make.in
     }
     proj-first-file-found $flist extM
@@ -681,24 +742,60 @@ use --teaish-extension-dir=/path/to/extension"
     define TEAISH_MAKEFILE_IN $extM
     define TEAISH_MAKEFILE [file rootname [file tail $extM]]
     proj-dot-ins-append $extM [get-define TEAISH_MAKEFILE]
-    msg-result "Extension makefile       = $extM"
+    msg-result "Extension makefile         = $extM"
   } else {
     define TEAISH_MAKEFILE_IN ""
     define TEAISH_MAKEFILE ""
     #proj-warn "Did not find an teaish.make.in."
   }
 
-  set flist [list $dext/teaish.pkginit.tcl]
-  if {[lindex $flist 0] ne "$dsrc/teaish.pkginit.in"} {
-    lappend flist $dsrc/teaish.pkginit.in
-  }
+  # Look for teaish.pkginit.tcl
+  set flist [list $dext/teaish.pkginit.tcl.in $dext/teaish.pkginit.tcl]
   if {[proj-first-file-found $flist extI]} {
-    msg-result "Extension post-load init = $extI"
-    define TEAISH_PKGINIT_TCL $extI
-    define TEAISH_PKGINIT_TCL_TAIL [file tail $extI]; # for use in pkgIndex.tcl
-    #teaish-add-install $extI
+    if {[string match *.in $extI]} {
+      proj-dot-ins-append $extI
+      define TEAISH_PKGINIT_TCL_IN $extI
+      define TEAISH_PKGINIT_TCL [file tail [file rootname $extI]]
+    } else {
+      define TEAISH_PKGINIT_TCL_IN ""
+      define TEAISH_PKGINIT_TCL $extI
+    }
+    teaish-add-dist [file tail $extI]
+    msg-result "Extension post-load init   = $extI"
+    define TEAISH_PKGINIT_TCL_TAIL [file tail [get-define TEAISH_PKGINIT_TCL]]; # for use in pkgIndex.tcl
   }
 
+  # Look for pkgIndex.tcl[.in]...
+  set piPolicy 0
+  if {[proj-first-file-found $dext/pkgIndex.tcl.in extPI]} {
+    # If $dext/pkgIndex.tcl.in exists, generate ./pkgIndex.tcl from
+    # it.
+    define TEAISH_PKGINDEX_TCL_IN $extPI
+    define TEAISH_PKGINDEX_TCL [file rootname [file tail $extPI]]
+    proj-dot-ins-append $extPI
+    teaish-add-dist [file tail $extPI]
+    set piPolicy 0x01
+  } elseif {!$extEqSrc && [proj-first-file-found $dsrc/pkgIndex.tcl.in extPI]} {
+    # If $dsrc/pkgIndex.tcl.in exists, generate ./pkgIndex.tcl from
+    # it.
+    define TEAISH_PKGINDEX_TCL_IN $extPI
+    define TEAISH_PKGINDEX_TCL [file rootname [file tail $extPI]]
+    proj-dot-ins-append $extPI
+    set piPolicy 0x02
+  }
+  if {!$piPolicy } {
+    if {[proj-first-file-found $dext/pkgIndex.tcl extPI]} {
+      # if TEAISH_DIR/pkgIndex.tcl exists, assume it's a static file
+      # and use it.
+      define TEAISH_PKGINDEX_TCL_IN ""
+      define TEAISH_PKGINDEX_TCL $extPI
+      proj-dot-ins-append $extPI
+      set piPolicy 0x04
+    }
+  }
+
+  set ::teaish__Config(pkgindex-policy) $piPolicy
+
   #
   # Set some sane defaults...
   #
@@ -709,8 +806,9 @@ use --teaish-extension-dir=/path/to/extension"
 
   # TEAISH_OUT_OF_EXT_TREE = 1 if we're building from a dir other
   # than the extension's home dir.
+  set dteaish [file-normalize [get-define TEAISH_DIR]]
   define TEAISH_OUT_OF_EXT_TREE \
-    [expr {[file-normalize $::autosetup(builddir)] ne [file-normalize [get-define TEAISH_DIR]]}]
+    [expr {[file-normalize $::autosetup(builddir)] ne $dteaish}]
 
   #
   # Defines which extensions may optionally make but are not required
@@ -727,42 +825,16 @@ use --teaish-extension-dir=/path/to/extension"
   return 1
 }
 
-# Internal helper to append $args to [define-append] $def
-proc teaish__append_stuff {def args} {
-  foreach a $args {
-    if {"" ne $a} {
-      define-append $def {*}$a
-    }
-  }
-}
-
-# @teaish-add-cflags ?-define? cflags...
+# @teaish-add-cflags ?-p|prepend? ?-define? cflags...
 #
-# Appends all non-empty $args to TEAISH_CFLAGS
-#
-# If -define is used then each flag is assumed to be a [define]'d
-# symbol name and [get-define X ""] used to fetch it.
+# Equivalent to [proj-define-amend TEAISH_CFLAGS {*}$args].
 proc teaish-add-cflags {args} {
-  set isdefs 0
-  if {[lindex $args 0] in {-d -define}} {
-    set args [lassign $args -]
-    set xargs [list]
-    foreach arg $args {
-      lappend xargs [get-define $arg ""]
-    }
-    set args $xargs
-  }
-  teaish__append_stuff TEAISH_CFLAGS {*}$args
+  proj-define-amend TEAISH_CFLAGS {*}$args
 }
 
-# @teaish-add-cflags ?-p|-prepend? ?-define? ldflags...
-#
-# Appends all non-empty $args to TEAISH_LDFLAGS unless the first
-# argument is one of (-p | -prepend), in which case it prepends all
-# arguments, in their given order, to TEAISH_LDFLAGS.
+# @teaish-add-ldflags ?-p|-prepend? ?-define? ldflags...
 #
-# If -define is used then each argument is assumed to be a [define]'d
-# flag and [get-define X ""] is used to fetch it.
+# Equivalent to [proj-define-amend TEAISH_LDFLAGS {*}$args].
 #
 # Typically, -lXYZ flags need to be in "reverse" order, with each -lY
 # resolving symbols for -lX's to its left. This order is largely
@@ -771,34 +843,7 @@ proc teaish-add-cflags {args} {
 #
 # See: teaish-prepend-ldflags
 proc teaish-add-ldflags {args} {
-  set prepend 0
-  set isdefs 0
-  set xargs [list]
-  foreach arg $args {
-    switch -exact -- $arg {
-      -p - -prepend { set prepend 1 }
-      -d - -define {
-        set isdefs 1
-      }
-      default {
-        lappend xargs $arg
-      }
-    }
-  }
-  set args $xargs
-  if {$isdefs} {
-    set xargs [list]
-    foreach arg $args {
-      lappend xargs [get-define $arg ""]
-    }
-    set args $xargs
-  }
-  if {$prepend} {
-    lappend args {*}[get-define TEAISH_LDFLAGS ""]
-    define TEAISH_LDFLAGS [join $args]; # join to eliminate {} entries
-  } else {
-    teaish__append_stuff TEAISH_LDFLAGS {*}$args
-  }
+  proj-define-amend TEAISH_LDFLAGS {*}$args
 }
 
 # @teaish-prepend-ldflags args...
@@ -808,7 +853,7 @@ proc teaish-prepend-ldflags {args} {
   teaish-add-ldflags -p {*}$args
 }
 
-# @teaish-add-cflags ?-dist? ?-dir? src-files...
+# @teaish-add-src ?-dist? ?-dir? src-files...
 #
 # Appends all non-empty $args to TEAISH_SRC.
 #
@@ -835,7 +880,6 @@ proc teaish-add-src {args} {
         set args [lassign $args -]
       }
       default {
-        #lappend xargs $arg
         break;
       }
     }
@@ -847,23 +891,26 @@ proc teaish-add-src {args} {
     set xargs {}
     set d [get-define TEAISH_DIR]
     foreach arg $args {
-      lappend xargs $d/$arg
+      if {"" ne $arg} {
+        lappend xargs $d/$arg
+      }
     }
     set args $xargs
   }
-  teaish__append_stuff TEAISH_SRC {*}$args
+  proj-define-append TEAISH_SRC {*}$args
 }
 
 # @teaish-add-dist files-or-dirs...
-# Appends all non-empty $args to TEAISH_DIST_FILES
+#
+# Equivalent to [proj-define-apend TEAISH_DIST_FILES ...].
 proc teaish-add-dist {args} {
-  teaish__append_stuff TEAISH_DIST_FILES {*}$args
+  proj-define-amend TEAISH_DIST_FILES {*}$args
 }
 
 # teaish-add-install files...
-# Appends all non-empty $args to TEAISH_INSTALL_FILES
+# Equivalent to [proj-define-apend TEAISH_INSTALL_FILES ...].
 #proc teaish-add-install {args} {
-#  teaish__append_stuff TEAISH_INSTALL_FILES {*}$args
+#  proj-define-amend TEAISH_INSTALL_FILES {*}$args
 #}
 
 # @teash-append-make args...
@@ -922,8 +969,9 @@ array set teaish__fCache {}
 # Sets a feature-check cache entry with a key equal to
 # [proj-current-scope [expr {$depth+1}]] and the given value.
 proc teaish-feature-cache-set {{depth 0} val} {
-  array set ::teaish__fCache [list [proj-current-scope [expr {$depth + 1}]] $val]
-  return $val
+  set key [proj-current-scope [expr {$depth + 1}]]
+  #puts "** fcheck set key=$key = $val"
+  set ::teaish__fCache($key) $val
 }
 
 # @teaish-feature-cache-check ?$depth? tgtVarName
@@ -934,15 +982,32 @@ proc teaish-feature-cache-set {{depth 0} val} {
 #
 proc teaish-feature-cache-check {{depth 0} tgtVar} {
   upvar $tgtVar tgt
-  set scope [proj-current-scope [expr {$depth + 1}]]
-  if {[info exists ::teaish__fCache($scope)]} {
-    set tgt $::teaish__fCache($scope)
+  set key [proj-current-scope [expr {$depth + 1}]]
+  #puts "** fcheck get key=$key"
+  if {[info exists ::teaish__fCache($key)]} {
+    set tgt $::teaish__fCache($key)
     return 1
   }
   set tgtVar ""
   return 0
 }
 
+# @teach-append-options list
+#
+# Adds a list of options to the pending --flag processing.  It must be
+# in the format used by Autosetup's [options] function.
+#
+# This will have no effect if called from [teaish-configure],
+# as the flags processing is done by the time that is called.
+#
+# This may be used from the top scope of teaish.tcl or from
+# [teaish-options]. When used in conjunction with [teaish-options],
+# [teaish-options] will appear first in the --help list.
+#
+proc teaish-append-options {list} {
+  lappend ::teaish__Config(extra-options) $list
+}
+
 # @teash-combine-option-lists list1 ?...listN?
 #
 # Expects each argument to be a list of options compatible with
@@ -961,6 +1026,145 @@ proc teaish-combine-option-lists {args} {
   return $rv
 }
 
+########################################################################
+# Internal helper for teaish__defs-format_: returns a JSON-ish quoted
+# form of the given string-type values. It only performs the most
+# basic of escaping. The input must not contain any control
+# characters.
+proc teaish__quote-str {value} {
+  return \"[string map [list \\ \\\\ \" \\\"] $value]\"
+}
+
+########################################################################
+# Internal helper for teaish__dump-defs-json. Expects to be passed a
+# [define] name and the variadic $args which are passed to
+# teaish__dump-defs-json. If it finds a pattern match for the given
+# $name in the various $args, it returns the type flag for that $name,
+# e.g. "-str" or "-bare", else returns an empty string.
+proc teaish__defs-type {name spec} {
+  foreach {type patterns} $spec {
+    foreach pattern $patterns {
+      if {[string match $pattern $name]} {
+        return $type
+      }
+    }
+  }
+  return ""
+}
+
+########################################################################
+# An internal impl detail. Requires a data type specifier, as used by
+# make-config-header, and a value. Returns the formatted value or the
+# value $::teaish__Config(defs-skip) if the caller should skip
+# emitting that value.
+set teaish__Config(defs-skip) "-teaish__defs-format sentinel"
+proc teaish__defs-format {type value} {
+  switch -exact -- $type {
+    -bare {
+      # Just output the value unchanged
+    }
+    -none {
+      set value $::teaish__Config(defs-skip)
+    }
+    -str {
+      set value [teaish__quote-str_ $value]
+    }
+    -auto {
+      # Automatically determine the type
+      if {![string is integer -strict $value]} {
+        set value [teaish__quote-str $value]
+      }
+    }
+    -array {
+      set ar {}
+      foreach v $value {
+        set v [teaish__defs-format -auto $v]
+        if {$::teaish__Config(defs-skip) ne $v} {
+          lappend ar $v
+        }
+      }
+      set value "\[ [join $ar {, }] \]"
+    }
+    "" {
+      set value $::teaish__Config(defs-skip)
+    }
+    default {
+      proj-fatal "Unknown type in [proj-current-scope 1]: $type"
+    }
+  }
+  return $value
+}
+
+#
+# Returns Tcl code in the form of code which evaluates to a list of
+# configure-time DEFINEs in the form {key val key2 val...}. It will
+# misbehave for values which are not numeric or simple strings.
+#
+proc teaish__dump_defs_to_list {args} {
+  set lines {}
+  lappend lines "\{"
+  set skipper $::teaish__Config(defs-skip)
+  lappend args \
+    -none {
+      TEAISH__*
+      TEAISH_MAKEFILE_CODE
+      TEAISH_AUTORECONFIGURE
+      AM_* AS_*
+    } \
+    -bare {SIZEOF_* HAVE_DECL_*} \
+    -auto *
+  foreach n [lsort [dict keys [all-defines]]] {
+    set type [teaish__defs-type $n $args]
+    set value [teaish__defs-format $type [get-define $n]]
+    if {$skipper ne $value} {
+      lappend lines "$n $value"
+    }
+  }
+  lappend lines "\}"
+  return [join $lines "\n"]
+}
+
+# @teaish-pragma ...flags
+#
+# Offers a way to tweak how teaish's core behaves in some cases, in
+# particular those which require changing how the core looks for an
+# extension and its files.
+#
+# Accepts the following flags:
+#
+#   --have-own-pkgIndex.tcl: Tells teaish that ./pkgIndex.tcl is not a
+#    generated file, so it will not try to overwrite or delete it.
+#    May be used during initial loading of teaish.tcl.
+#
+#   --disable-dist: disables the "dist" parts of the filtered
+#     Makefile.  May be used during initial loading of teaish.tcl.
+#
+# Emits a warning message for unknown arguments.
+proc teaish-pragma {args} {
+  foreach arg $args {
+    switch -exact -- $arg {
+
+      --disable-dist {
+        define TEAISH_ENABLE_DIST 0
+      }
+
+      --have-own-pkgIndex.tcl {
+        set pi [file join [get-define TEAISH_DIR] pkgIndex.tcl]
+        if {![file exists $pi]} {
+          proj-fatal "teaish-pragmas $arg found no pkgIndex.tcl"
+        }
+        define TEAISH_PKGINDEX_TCL $pi
+        set ::teaish__Config(pkgindex-policy) 0x10
+      }
+
+      default {
+        proj-warn "Unknown [proj-current-scope] flag: $arg"
+      }
+    }
+  }
+}
+
+
 # @teaish-enable-dist ?yes?
 #
 # Explicitly enables or disables the "dist" rules in the default
@@ -973,6 +1177,7 @@ proc teaish-enable-dist {{yes 1}} {
   define TEAISH_ENABLE_DIST $yes
 }
 
+
 #
 # Handles --teaish-create-extension=TARGET-DIR
 #
index 1ecdc013a4075cea1a3f8d2a3c0c8852a52bc3d9..63da9cd4fa3db8d371e42fe617d4d34e7e20c83f 100644 (file)
@@ -9,7 +9,7 @@
 #  * May you share freely, never taking more than you give.
 #
 ########################################################################
-# ----- @module teaish-checks.tcl -----
+# ----- @module feature-tests.tcl -----
 # @section TEA-ish collection of feature tests.
 #
 # Functions in this file with a prefix of teaish__ are
 
 # @teaish-check-cached@ ?-flags? msg script
 #
-# Under construction.
+# A proxy for feature-test impls which handles caching of a feature
+# flag check on per-function basis, using the calling scope's name as
+# the cache key.
 #
-# A proxy for feature-test impls which handles chacheing of the
-# feature flag check on a per-caller basis, using the calling scope's
-# name as the cache key.
-#
-# The test is performed by $script. This function caches the result
-# and checks for a chache hit before running $script. The value stored
+# The test is performed by $script. This function checks for a chache
+# hit before running $script and caching the result. The value stored
 # in the cache is the final value of $script (and this routine will
 # intercept a 'return' from $script).
 #
 # Flags:
 #
 #   -nostatus = do not emit "ok" or "no" at the end. This presumes
-#    that the caller will emit a newline before turning.
+#    that the caller will emit at least one newline before turning.
 proc teaish-check-cached {args} {
   set quiet 0
   set xargs {}
@@ -58,6 +56,7 @@ proc teaish-check-cached {args} {
   } else {
     set code [catch {uplevel 1 $script} rc xopt]
     #puts "***** ::teaish__fCache ="; parray ::teaish__fCache
+    #puts "***** cached-check got code=$code rc=$rc"
     if {$code in {0 2}} {
       teaish-feature-cache-set 1 $rc
       if {!$quiet} {
@@ -71,7 +70,8 @@ proc teaish-check-cached {args} {
       #puts "**** code=$code rc=$rc xopt=$xopt"
       teaish-feature-cache-set 1 0
     }
-    return -options $xopt $rc
+    #puts "**** code=$code rc=$rc"
+    return {*}$xopt $rc
   }
 }
 
@@ -181,8 +181,11 @@ proc teaish-check-dlopen {} {
   }
 }
 
-########################################################################
-# Handles the --enable-math flag.
+#
+# @teaish-check-libmath
+#
+# Handles the --enable-math flag. Returns 1 if found, else 0.
+# If found, it prepends -lm (if needed) to the linker flags.
 proc teaish-check-libmath {} {
   teaish-check-cached "Checking for libc math library" {
     set lfl ""
@@ -199,282 +202,41 @@ proc teaish-check-libmath {} {
   }
 }
 
-# @teaish-check-pkg-config-openssl
+# @teaish-import-features ?-no-options? feature-names...
 #
-# Returns 1 if openssl is found via pkg-config, else 0.  If found,
-# passes its link flags to teaish-prepend-ldflags.
+# For each $name in feature-names... it invokes:
 #
-# It defines LDFLAGS_OPENSSL to the linker flags and CFLAGS_OPENSSL to
-# the CFLAGS, or "" if it's not found.
+#   use teaish/feature/$name
 #
-# Defines HAVE_OPENSSL to 0 or 1 (its return value).
+# to load $::autosetup(libdir)/teaish/feature/$name.tcl.
 #
-# If it returns true, the underlying pkg-config test will set several
-# defines named PKG_OPENSSL_... (see the docs for [pkg-config] for
-# details).
-proc teaish-check-pkg-config-openssl {} {
-  use pkg-config
-  teaish-check-cached -nostatus "Checking for openssl via pkg-config" {
-    set rc 0
-    if {[msg-quiet pkg-config-init 0] && [msg-quiet pkg-config openssl]} {
-      incr rc
-      set lfl [string trim "[get-define PKG_OPENSSL_LDFLAGS] [get-define PKG_OPENSSL_LIBS]"]
-      define CFLAGS_OPENSSL [get-define PKG_OPENSSL_CFLAGS]
-      define LDFLAGS_OPENSSL $lfl
-      teaish-prepend-ldflags $lfl
-      msg-result "ok ($lfl)"
-    } else {
-      define CFLAGS_OPENSSL ""
-      define LDFLAGS_OPENSSL ""
-      msg-result "no"
-    }
-    define HAVE_OPENSSL $rc
-    return [teaish-feature-cache-set $rc]
-  }
-}
-
-# Internal helper for OpenSSL checking using cc-with to check if the
-# given $cflags, $ldflags, and list of -l libs can link an
-# application.
-#
-# For a system-level check, use empty $cflags and $ldflags.
-#
-# On success, it defines CFLAGS_OPENSSL to $cflags and LDFLAGS_OPENSSL
-# to a combination of $ldflags and any required libs (which may be
-# amended beyond those provided in $libs). It then returns 1.
-#
-# On failure it defines the above-mentioned flags to ""
-# and returns 0.
-#
-# Defines HAVE_OPENSSL to its return value.
-#
-# Derived from https://fossil-scm.org/file/auto.def
-proc teaish__check-openssl {msg cflags ldflags {libs {-lssl -lcrypto -lpthread}}} {
-  msg-checking "$msg ... "
-  set rc 0
-  set isMinGw [teaish-is-mingw]
-  if {$isMinGw} {
-    lappend libs -lgdi32 -lwsock32 -lcrypt32
-  }
-  set prefix msg-quiet
-  #set prefix ""
-  set lz ""
-  if {[{*}$prefix teaish-check-libz]} {
-    set lz [get-define LDFLAGS_LIBZ]
-  }
-  set libs2 $libs
-  if {$lz ne ""} {
-    lappend libs2 $lz
-  }
-  {*}$prefix cc-with [list -link 1 -cflags "$cflags $ldflags" -libs $libs2] {
-    if {[cc-check-includes openssl/ssl.h] && \
-          [cc-check-functions SSL_new]} {
-      incr rc
-    }
-  }
-  if {!$rc && !$isMinGw} {
-    # On some systems, OpenSSL appears to require -ldl to link.
-    if {[{*}$prefix teaish-check-dlopen]} {
-      lappend libs2 [get-define LDFLAGS_DLOPEN ""]
-      {*}$prefix cc-with [list  -link 1 -cflags "$cflags $ldflags" -libs $libs2] {
-        if {[cc-check-includes openssl/ssl.h] && \
-              [cc-check-functions SSL_new]} {
-          incr rc
+# By default, if a proc named teaish-check-${name}-options is defined
+# after sourcing a file, it is called and its result is passed to
+# teaish-append-options. This can be suppressed with the -no-options
+# flag.
+proc teaish-import-features {args} {
+  set doOpt 1
+  if {1} {
+    set xopt [list]
+    foreach arg $args {
+      switch -exact -- $arg {
+        -no-options {
+          set doOpt 0
         }
-      }
-    }
-  }
-  #puts "*???? cflags=$cflags ldflags=$ldflags libs2=$libs2"
-  if {$rc} {
-    msg-result "ok"
-    define CFLAGS_OPENSSL "$cflags"
-    define LDFLAGS_OPENSSL "$ldflags $libs2"
-  } else {
-    define CFLAGS_OPENSSL ""
-    define LDFLAGS_OPENSSL ""
-    msg-result "no"
-  }
-  define HAVE_OPENSSL $rc
-  return $rc
-}
-
-# @teaish-check-openssl
-#
-# Jumps through some provierbial hoops to look for OpenSSL dev pieces.
-#
-# $where must be one of the following:
-#
-# - "pkg-config": check only pkg-config for it, but also verify that
-#   the results from pkg-config seem to work.
-#
-# - "system": look in standard(ish) system paths, starting with
-#   a lookup requiring no -L flag.
-#
-# - "auto" or "": try (pkg-config, system), in that order.
-#
-# - "none": do no lookup, define vars (see below), and return 0.
-#
-# - Any other value is assumed to be a directory name suitable for
-#   finding OpenSSL, but how this lookup is run is not currently
-#   well-defined.
-#
-# It defines LDFLAGS_OPENSSL and CFLAGS_OPENSSL to ldflags
-# resp. cflags needed for compiling and linking, and updates teaish's
-# internal ldflags/cflags lists. If OpenSSL is not found, they're
-# defined to "".
-#
-# It defines HAVE_OPENSSL to 0 or 1 (its return value).
-#
-# If $where is empty then it defaults to auto. If $where is not empty
-# _and_ OpenSSL is not found
-#
-# If the --with-openssl=... config flag is defined (see
-# teaish-check-openssl-options) then an empty $where value will use
-# the value of the --with-openssl flag, defaulting to "auto" if that
-# flag also has an empty value. If that flag is provided, and has a
-# value other than "none", then failure to find the library is
-# considered fatal.
-#
-# Derived from https://fossil-scm.org/file/auto.def
-proc teaish-check-openssl {{where ""}} {
-  teaish-check-cached -nostatus "Looking for openssl" {
-    if {$where eq ""} {
-      if {[proj-opt-exists with-openssl]} {
-        set where [join [opt-val with-openssl auto]]
-      }
-    }
-
-    set notfound {{checkWithFlag msg} {
-      if {$checkWithFlag && [proj-opt-was-provided with-openssl]} {
-        proj-fatal "--with-openssl " \
-          "found no working installation. Try --with-openssl=none"
-      }
-      define LDFLAGS_OPENSSL ""
-      define CFLAGS_OPENSSL ""
-      define HAVE_OPENSSL 0
-      msg-result $msg
-    }}
-
-    switch -exact -- $where {
-      none {
-        apply $notfound 0 none
-        return 0
-      }
-      "" {
-        set where auto
-      }
-    }
-    if {$where in {pkg-config auto}} {
-      # Check pkg-config
-      if {[teaish-check-pkg-config-openssl]} {
-        set cflags [get-define PKG_OPENSSL_CFLAGS ""]
-        set ldflags [get-define LDFLAGS_OPENSSL ""]
-        if {[teaish__check-openssl "Verifying openssl pkg-config values" \
-               "$cflags $ldflags"]} {
-          teaish-prepend-ldflags $ldflags
-          return 1
+        default {
+          lappend xopt $arg
         }
       }
-      if {$where eq "pkg-config"} {
-        apply $notfound 1 "not found"
-        return 0
-      }
-    }
-
-    # Determine which dirs to search...
-    set ssldirs {}
-    if {$where in {auto system}} {
-      set ssldirs {
-        {} /usr/sfw /usr/local/ssl /usr/lib/ssl /usr/ssl
-        /usr/pkg /usr/local /usr /usr/local/opt/openssl
-        /opt/homebrew/opt/openssl
-      }
-    } elseif {$where ne ""} {
-      lappend ssldirs $where
     }
-
-    foreach dir $ssldirs {
-      set msg "in $dir"
-      set cflags "-I$dir/include"
-      if {$dir eq ""} {
-        set msg "without -L/path"
-        set ldflags ""
-        set cflags ""
-      } elseif {![file isdir $dir]} {
-        continue
-      } elseif {[file readable $dir/libssl.a]} {
-        set ldflags -L$dir
-      } elseif {[file readable $dir/lib/libssl.a]} {
-        set ldflags -L$dir/lib
-      } elseif {[file isdir $dir/lib]} {
-        set ldflags [list -L$dir -L$dir/lib]
-      } else {
-        set ldflags -L$dir
-      }
-      if {[teaish__check-openssl $msg $cflags $ldflags]} {
-        teaish-add-cflags [get-define CFLAGS_OPENSSL]
-        teaish-prepend-ldflags [get-define LDFLAGS_OPENSSL]
-        return 1
-      }
-      if {$dir ne ""} {
-        # Look for a static build under $dir...
-        set ldflags ""
-        set libs [list $dir/libssl.a $dir/libcrypto.a]
-        set foundLibs 0
-        foreach x $libs {
-          if {![file readlable $x]} break;
-          incr foundLibs
-        }
-        if {$foundLibs != [llength $libs]} {
-          continue
-        }
-        set cflags "-I$dir/include"
-        lappend libs -lpthread
-        if {[teaish__check-openssl "Checking for static openssl build in $dir" \
-               $cflags $ldflags $libs]} {
-          teaish-add-cflags [get-define CFLAGS_OPENSSL]
-          teaish-prepend-ldflags [get-define LDFLAGS_OPENSSL]
-          return 1
-        }
+    set args $xopt
+  }
+  foreach arg $args {
+    uplevel "use teaish/feature/$arg"
+    if {$doOpt} {
+      set n "teaish-check-${arg}-options"
+      if {[llength [info proc $n]] > 0} {
+        teaish-append-options [$n]
       }
     }
-
-    apply $notfound 1 no
-    return 0
-  }
-}; # teaish-check-openssl
-
-# @teaish-check-openssl-options
-#
-# teaish.tcl files which use teaish-check-openssl should
-# include this function's result from their teaish-options
-# impl, so that configure --help can include the --with-openssl
-# flag that check exposes.
-#
-# Returns a list of options for the teaish-check-openssl feature test.
-#
-# Example usage:
-#
-# proc teaish-options {} {
-#  use teaish-feature-tests
-#  return [teaish-combine-option-lists \
-#            [teaish-check-openssl-options] \
-#            { hell-world => {just testing} } \
-#          ]
-# }
-proc teaish-check-openssl-options {} {
-  return {
-    with-openssl:see-the-help =>
-    {Checks for OpenSSL development libraries in a variety of ways.
-      "pkg-config" only checks the system's pkg-config.
-      "system" checks only for a system-level copy.
-      "auto" checks the prior options and a list of
-      likely candidate locations. "none" disables the check
-      altogether and causes the check to not fail if it's
-      not found. Any other value is a directory in which a
-      _static_ copy of libssl.a can be found, e.g. a locally-built
-      copy of the OpenSSL source tree. If this flag is explicitly provided,
-      and has a value other than "none", failure to find OpenSSL
-      is fatal.}
   }
 }
index f464c85a2d3a5dc20acdbbca96b1517ce01abddf..d0d8024474e065cac57c73c835321ea4cc6dae38 100644 (file)
@@ -42,18 +42,45 @@ proc test-current-scope {{lvl 0}} {
   }
 }
 
+# @test-msg
+#
+# Emits all arugments to stdout.
 proc test-msg {args} {
-  puts "{*}$args"
+  puts "$args"
+}
+
+# @test-warn
+#
+# Emits all arugments to stderr.
+proc test-warn {args} {
+  puts stderr "WARNING: $args"
 }
 
 ########################################################################
 # @test-error msg
 #
-# Emits an error message to stderr and exits with non-0.
+# Triggers a test-failed error with a string describing the calling
+# scope and the provided message.
 proc test-fail {msg} {
   #puts stderr "ERROR: \[[test-current-scope 1]]: $msg"
   #exit 1
-  error "ERROR: \[[test-current-scope 1]]: $msg"
+  error "FAIL: \[[test-current-scope 1]]: $msg"
+}
+
+# Internal impl for assert-likes. Should not be called directly by
+# client code.
+proc test__assert {lvl script {msg ""}} {
+  set src "expr \{ $script \}"
+  # puts "XXXX evalling $src";
+  if {![uplevel $lvl $src]} {
+    if {"" eq $msg} {
+      set msg $script
+    }
+    set caller1 [test-current-scope $lvl]
+    incr lvl
+    set caller2 [test-current-scope $lvl]
+    error "Assertion failed in: \[$caller2 -> $caller1]]: $msg"
+  }
 }
 
 ########################################################################
@@ -64,45 +91,85 @@ proc test-fail {msg} {
 # includes the body of the failed assertion, but if $msg is set then
 # that is used instead.
 proc assert {script {msg ""}} {
-  set x "expr \{ $script \}"
-  if {![uplevel 1 $x]} {
-    if {"" eq $msg} {
-      set msg $script
-    }
-    test-fail "Assertion failed in \[[test-current-scope 1]]: $msg"
-  }
+  test__assert 1 $script $msg
 }
 
 ########################################################################
-# @test-expect testId script result
+# @test-assert testId script ?msg?
 #
-# Runs $script in the calling scope and compares its result to
-# $result.  If they differ, it triggers an [assert].
-proc test-expect {testId script result} {
+# Works like [assert] but emits $testId to stdout first.
+proc test-assert {testId script {msg ""}} {
   puts "test $testId"
-  set x [uplevel 1 $script]
-  assert {$x eq $result} "\nEXPECTED: <<$result>>\nGOT:      <<$x>>"
+  test__assert 2 $script $msg
 }
 
 ########################################################################
-# @test-assert testId script ?msg?
+# @test-expect testId script result
 #
-# Works like [assert] but emits $testId to stdout first.
-proc test-assert {testId script {msg ""}} {
+# Runs $script in the calling scope and compares its result to
+# $result.  If they differ, it triggers an [assert].
+proc test-expect {testId script result} {
   puts "test $testId"
-  assert $script $msg
+  set x [uplevel 1 $script]
+  test__assert 1 {$x eq $result} "\nEXPECTED: <<$result>>\nGOT:      <<$x>>"
 }
 
 ########################################################################
 # @test-catch cmd ?...args?
 #
 # Runs [cmd ...args], repressing any exception except to possibly log
-# the failure.
+# the failure. Returns 1 if it caught anything, 0 if it didn't.
 proc test-catch {cmd args} {
   if {[catch {
     $cmd {*}$args
   } rc xopts]} {
     puts "[test-current-scope] ignoring failure of: $cmd [lindex $args 0]: $rc"
-    #how to extract just the message text from $xopts?
+    return 1
+  }
+  return 0
+}
+
+array set teaish__BuildFlags {}
+
+# @teaish-build-flag2 flag tgtVar ?dflt?
+#
+# Caveat #1: only valid when called in the context of teaish's default
+# "make test" recipe, e.g. from teaish.test.tcl. It is not valid from
+# a teaish.tcl configure script because (A) the state it relies on
+# doesn't fully exist at that point and (B) that level of the API has
+# more direct access to the build state. This function requires that
+# an external script have populated its internal state, which is
+# normally handled via teaish.tester.tcl.in.
+#
+# If the current build has the configure-time flag named $flag set
+# then tgtVar is assigned its value and 1 is returned, else tgtVal is
+# assigned $dflt and 0 is returned.
+#
+# Caveat #2: defines in the style of HAVE_FEATURENAME with a value of
+# 0 are, by long-standing configure script conventions, treated as
+# _undefined_ here.
+#
+proc teaish-build-flag2 {flag tgtVar {dflt ""}} {
+  upvar $tgtVar tgt
+  if {[info exists ::teaish__BuildFlags($flag)]} {
+    set tgt $::teaish__BuildFlags($flag)
+    return 1;
+  } elseif {0==[array size ::teaish__BuildFlags]} {
+    test-warn \
+      "\[[test-current-scope]] was called from " \
+      "[test-current-scope 1] without the build flags imported."
   }
+  set tgt $dflt
+  return 0
+}
+
+# @teaish-build-flag flag ?dflt?
+#
+# Convenience form of teaish-build-flag2 which returns the
+# configure-time-defined value of $flag or "" if it's not defined (or
+# if it's an empty string).
+proc teaish-build-flag {flag {dflt ""}} {
+  set tgt ""
+  teaish-build-flag2 $flag tgt $dflt
+  return $tgt
 }
index 39a51599dccd1cebe697eaa73cd3783a25c22801..30c8714ad4793e641007afb357ad706ea5573cac 100644 (file)
@@ -29,10 +29,9 @@ array set sqliteConfig [subst [proj-strip-hash-comments {
 proc teaish-options {} {
   return [proj-strip-hash-comments [subst -nocommands -nobackslashes {
     with-system-sqlite=0
-      => {Use the system-level sqlite instead of the copy in this tree.
-          WARNING: this extension's version is taken from the in-tree copy
-          and there is no reliable way to get the version of a system-level
-          copy.}
+      => {Use the system-level SQLite instead of the copy in this tree.
+          Also requires use of --override-sqlite-version so that the build
+          knows what version number to associate with the system-level SQLite.}
     override-sqlite-version:VERSION
       => {For use with --with-system-sqlite to set the version number.}
     threadsafe=1         => {Disable mutexing}
@@ -72,10 +71,14 @@ proc teaish-configure {} {
 
   set srcdir [get-define TEAISH_DIR]
   teaish-add-src -dist -dir generic/tclsqlite3.c
-  teaish-add-cflags -I${srcdir}/.. ; # for sqlite3.c
+  teaish-add-cflags -I${srcdir}/.. ; # for sqlite3.[ch]
   if {[proj-opt-was-provided override-sqlite-version]} {
     define TEAISH_VERSION [opt-val override-sqlite-version]
-    msg-result "NOTICE: overriding version number: [get-define TEAISH_VERSION]"
+    proj-warn "overriding sqlite version number: [get-define TEAISH_VERSION]"
+  } elseif {[proj-opt-was-provided with-system-sqlite]
+            && [opt-val with-system-sqlite] ne "0"} {
+    proj-fatal "when using --with-system-sqlite also use"\
+      "--override-sqlite-version to specify a library version number."
   }
 
   define CFLAGS [proj-get-env CFLAGS {-O2}]
index 80b0e95b8b9a3c4eb5b180d1342db5eb151355e8..296652279fe896c7c279811cbab55b5e133110aa 100644 (file)
@@ -73,7 +73,8 @@ set proj_(isatty) [isatty? stdout]
 ########################################################################
 # @proj-warn msg
 #
-# Emits a warning message to stderr.
+# Emits a warning message to stderr. All args are appended with a
+# space between each.
 proc proj-warn {args} {
   show-notices
   puts stderr [join [list "WARNING:" {*}$args] " "]
@@ -82,10 +83,11 @@ proc proj-warn {args} {
 ########################################################################
 # @proj-error msg
 #
-# Emits an error message to stderr and exits with non-0.
+# Emits an error message to stderr and exits with non-0. All args are
+# appended with a space between each.
 proc proj-fatal {args} {
   show-notices
-  puts stderr "ERROR: \[[proj-current-scope 1]]: $args"
+  puts stderr [join [list "ERROR: \[[proj-current-scope 1]]:" {*}$args] " "]
   exit 1
 }
 
@@ -1691,3 +1693,65 @@ proc proj-setup-autoreconfig {defName} {
     define-append $defName [apply $squote $arg]
   }
 }
+
+########################################################################
+# @prop-append-to defineName args...
+#
+# A proxy for Autosetup's [define-append]. Appends all non-empty $args
+# to [define-append $defineName].
+proc proj-define-append {defineName args} {
+  foreach a $args {
+    if {"" ne $a} {
+      define-append $defineName {*}$a
+    }
+  }
+}
+
+########################################################################
+# @prod-define-amend ?-p|-prepend? ?-define? FLAG args...
+#
+# A proxy for Autosetup's [define-append].
+#
+# Appends all non-empty $args to the define named by $FLAG unless.  If
+# one of (-p | -prepend) are used it instead prepends them, in their
+# given order, to $FLAG.
+#
+# If -define is used then each argument is assumed to be a [define]'d
+# flag and [get-define X ""] is used to fetch it.
+#
+# Typically, -lXYZ flags need to be in "reverse" order, with each -lY
+# resolving symbols for -lX's to its left. This order is largely
+# historical, and not relevant on all environments, but it is
+# technically correct and still relevant on some environments.
+#
+# See: proj-append-to
+proc proj-define-amend {defName args} {
+  set prepend 0
+  set isdefs 0
+  set xargs [list]
+  foreach arg $args {
+    switch -exact -- $arg {
+      -p - -prepend { set prepend 1 }
+      -d - -define {
+        set isdefs 1
+      }
+      default {
+        lappend xargs $arg
+      }
+    }
+  }
+  if {$isdefs} {
+    set args $xargs
+    set xargs [list]
+    foreach arg $args {
+      lappend xargs [get-define $arg ""]
+    }
+  }
+  set args $xargs
+  if {$prepend} {
+    lappend args {*}[get-define $defName ""]
+    define $defName [join $args]; # join to eliminate {} entries
+  } else {
+    proj-define-append $defName {*}$args
+  }
+}
index 8dba5dbc7596cf96433d9ed34957e2a8425c6914..b613f66bd22a4e204c2b3f1429a2e7688f459c97 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Improved\sestimate\son\sthe\snumber\sof\soutput\srows\sin\sa\srecursive\scommon\stable\sexpression\nthat\suses\sthe\sUNION\soperator.\s\sFollow-up\sto\s[f911f1c4977fbcae]\sand\sit's\soutput\srow\nestimate\schanges\sassociated\swith\sDISTINCT\squeries.
-D 2025-04-14T19:43:30.136
+C Update\steaish\sto\sthe\slatest\supstream\scopy.\sMove\ssome\sof\sits\sutility\scode\sinto\sproj.tcl\sfor\sreuse\sin\sthe\stop-level\sconfigure\sbits.
+D 2025-04-14T23:52:11.230
 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -26,14 +26,14 @@ F autoconf/tea/Makefile.in 2a90dfab1e95cb3ec610429c78d88d4a7d26beb080ad45ff6a059
 F autoconf/tea/README.txt 656d4686c509d375f5988ff3deda94f65fe6cd8358cd55d1f1dcc7b6e2ff73aa
 F autoconf/tea/auto.def 81e2617cfb90d53c19b53b3ec632cd2893bf32f2e5dd272b1116fadf2ea86c2d
 F autoconf/tea/autosetup/README.txt b40071e6f8506500a2f7f71d5fc69e0bf87b9d7678dd9da1e5b4d0acbf40b1ca
-F autoconf/tea/autosetup/core.tcl 85d6d484f75d9d2fa02517c20650cc7af50fe216f7848ebd6d0c59782f99ef01
-F autoconf/tea/autosetup/feature-tests.tcl 0e2893c787edb26d2d4302ea5178d4c0a6878f396905bf8fa485afb7a6fad5f0
-F autoconf/tea/autosetup/tester.tcl 91beb9e26916cdb54400446e2890105cdea4186789141d5748c72b2f73b26ed0
+F autoconf/tea/autosetup/core.tcl 2738997421c4fdcf52528af36db716993bb00425b10340a1e50143fe94048c46
+F autoconf/tea/autosetup/feature-tests.tcl 57bc056df24f7b5d54006598ee2cbdf234fea55e0d17f8c5f2b52a8d90095dbc
+F autoconf/tea/autosetup/tester.tcl d94aa9d51d2a22062e61db97310c2502ca0df50ca87108482c3bccf8f41db127
 F autoconf/tea/configure d0b12b984edca6030d1976375b80157ac78b5b90a5b4f0dcee39357f63f4a80b x
 F autoconf/tea/doc/sqlite3.n 9a97f4f717ceab73004ea412af7960625c1cb24b5c25e4ae4c8b5d8fa4300f4e
 F autoconf/tea/license.terms 13bd403c9610fd2b76ece0ab50c4c5eda933d523
 F autoconf/tea/pkgIndex.tcl.in 2c99a64a0eff5dc2ad8e9657bb564fae2dbdfdb6b77a4c49b4387bd5a25c42ef
-F autoconf/tea/teaish.tcl 9fc1fb838eabebcda65035178ade8d04daafa6bf07a7f7a01e3b1fbd3df08f6c
+F autoconf/tea/teaish.tcl 76bcea8d44543f085084b6662219f0534e7513374a82d6aaa6f9c7c7e1acca58
 F autoconf/tea/teaish.test.tcl cfe94e1fb79dd078f650295be59843d470125e0cc3a17a1414c1fb8d77f4aea6
 F autoconf/tea/teaish.tester.tcl.in 743fd0fe1e667f82fd8fc3ebe0a5c77763e4dbed7bbc8605a9d4b1d0663dac78
 F autosetup/LICENSE 41a26aebdd2cd185d1e2b210f71b7ce234496979f6b35aef2cbf6b80cbed4ce4
@@ -51,7 +51,7 @@ F autosetup/cc.tcl c0fcc50ca91deff8741e449ddad05bcd08268bc31177e613a6343bbd1fd3e
 F autosetup/find_tclconfig.tcl e64886ffe3b982d4df42cd28ed91fe0b5940c2c5785e126c1821baf61bc86a7e
 F autosetup/jimsh0.c a57c16e65dcffc9c76e496757cb3f7fb47e01ecbd1631a0a5e01751fc856f049
 F autosetup/pkg-config.tcl 4e635bf39022ff65e0d5434339dd41503ea48fc53822c9c5bde88b02d3d952ba
-F autosetup/proj.tcl a59eac46d92125905dd577699d4acc09adbbf377f4337cc43f61786091c8af6c
+F autosetup/proj.tcl 9de1b0fbc76dd22d447cd10c7a5f07c8aafef258a87c52c67687fb1e91fc3d58
 F autosetup/sqlite-config.tcl 3f771754b89ae10379bb5d9d48d80921568345618f8f37d4a62a8e1fd9cd916c
 F autosetup/system.tcl 51d4be76cd9a9074704b584e5c9cbba616202c8468cf9ba8a4f8294a7ab1dba9
 F configure 9a00b21dfd13757bbfb8d89b30660a89ec1f8f3a79402b8f9f9b6fc475c3303a x
@@ -2216,8 +2216,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
 F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
 F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 914d4c9d6c26536ca14be80eee6c54af4311eac6bf88b327738075275f4b77da
-R fee16bedc2936fcf762a590910cd0015
-U drh
-Z cac2b67ac54b69b59bd81ffa4eaf41eb
+P 92513f6bce7ecc778e78af3a77bc66ff65585fffa2e3138f8acb9e617121eeb0
+R 885261e686c805e49dc78c31644a054a
+U stephan
+Z 68c2318b2d8a42399b7b82112788ad28
 # Remove this line to create a well-formed Fossil manifest.
index d4ba1305b2ea1627ad459526629ec379f0275bb9..de64e8eecbc2419052be43079193318168ab2f6b 100644 (file)
@@ -1 +1 @@
-92513f6bce7ecc778e78af3a77bc66ff65585fffa2e3138f8acb9e617121eeb0
+921c5ea76925be911222ac5f2887b8a967ff47b1aa43e196231e6168a3f9cb88