SQLite

Check-in [501ff84e12]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Refactor proj-make-from-dot-in and friends to be more useful and remove some annoying limitations.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 501ff84e1263e2b026b0ca5f043bcc912ea935229b625b113b7402955df20dd3
User & Date: stephan 2025-04-05 02:59:37.477
Context
2025-04-05
07:12
Move the automatic reconfigure tcl code from sqlite-config.tcl to proj.tcl so that the TEA bits can reuse it. (check-in: 52839db2fc user: stephan tags: trunk)
02:59
Refactor proj-make-from-dot-in and friends to be more useful and remove some annoying limitations. (check-in: 501ff84e12 user: stephan tags: trunk)
2025-04-04
23:12
Rename makefile var libtclsqlite3.SO to libtclsqlite3.DLL for consistency. (check-in: 6fb364c853 user: stephan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to autosetup/proj.tcl.
50
51
52
53
54
55
56










57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# ----- @module proj.tcl -----
# @section Project Helper APIs

########################################################################
# $proj_ is an internal-use-only array for storing whatever generic
# internal stuff we need stored.
array set proj_ {}










set proj_(isatty) [isatty? stdout]

########################################################################
# @proj-warn msg
#
# Emits a warning message to stderr.
proc proj-warn {msg} {
  show-notices
  puts stderr "WARNING: $msg"
}

########################################################################
# @proj-error msg
#
# Emits an error message to stderr and exits with non-0.
proc proj-fatal {msg} {
  show-notices
  puts stderr "ERROR: $msg"
  exit 1
}

########################################################################
# @proj-assert script ?message?
#
# Kind of like a C assert: if uplevel (eval) of [expr {$script}] is







>
>
>
>
>
>
>
>
>
>

















|







50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# ----- @module proj.tcl -----
# @section Project Helper APIs

########################################################################
# $proj_ is an internal-use-only array for storing whatever generic
# internal stuff we need stored.
array set proj_ {}
#
# List of dot-in files to filter in the final stages of
# configuration. Some configuration steps may append to this.  Each
# one in this list which exists will trigger the generation of a
# file with that same name, minus the ".in", in the build directory
# (which differ from the source dir in out-of-tree builds).
#
# See: proj-dot-ins-append and proj-dot-ins-process
#
set proj_(dot-in-files) {}
set proj_(isatty) [isatty? stdout]

########################################################################
# @proj-warn msg
#
# Emits a warning message to stderr.
proc proj-warn {msg} {
  show-notices
  puts stderr "WARNING: $msg"
}

########################################################################
# @proj-error msg
#
# Emits an error message to stderr and exits with non-0.
proc proj-fatal {msg} {
  show-notices
  puts stderr "ERROR: \[[proj-current-proc-name 1]]: $msg"
  exit 1
}

########################################################################
# @proj-assert script ?message?
#
# Kind of like a C assert: if uplevel (eval) of [expr {$script}] is
666
667
668
669
670
671
672
673
674
675
676
677







678
679
680
681
682
683
684
685
686
687

688
689
690


691
692



693
694



695
696
697

698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
# Runs the 'touch' external command on one or more files, ignoring any
# errors.
proc proj-touch {filename} {
  catch { exec touch {*}$filename }
}

########################################################################
# @proj-make-from-dot-in ?-touch? filename...
#
# Uses [make-template] to create makefile(-like) file(s) $filename
# from $filename.in but explicitly makes the output read-only, to
# avoid inadvertent editing (who, me?).







#
# If the first argument is -touch then the generated file is touched
# to update its timestamp. This can be used as a workaround for
# cases where (A) autosetup does not update the file because it was
# not really modified and (B) the file *really* needs to be updated to
# please the build process.
#
# Failures when running chmod or touch are silently ignored.
proc proj-make-from-dot-in {args} {
  set filename $args

  set touch 0
  if {[lindex $args 0] eq "-touch"} {
    set touch 1


    set filename [lrange $args 1 end]
  }



  foreach f $filename {
    set f [string trim $f]



    if {[file exists $f]} {
      catch { exec chmod u+w $f }
    }

    make-template $f.in $f
    if {$touch} {
      proj-touch $f
    }
    catch {
      exec chmod -w $f
      #file attributes -w $f; #jimtcl has no 'attributes'
    }
  }
}

########################################################################
# @proj-check-profile-flag ?flagname?
#
# Checks for the boolean configure option named by $flagname. If set,







|

|
|
|
>
>
>
>
>
>
>









|
>



>
>
|

>
>
>
|
|
>
>
>
|
|
|
>
|
|
|
|
|
|
|
<







676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731

732
733
734
735
736
737
738
# Runs the 'touch' external command on one or more files, ignoring any
# errors.
proc proj-touch {filename} {
  catch { exec touch {*}$filename }
}

########################################################################
# @proj-make-from-dot-in ?-touch? infile ?outfile?
#
# Uses [make-template] to create makefile(-like) file(s) $outfile from
# $infile but explicitly makes the output read-only, to avoid
# inadvertent editing (who, me?).
#
# If $outfile is empty then:
#
# - If $infile is a 2-element list, it is assumed to be an in/out pair,
#   and $outfile is set from the 2nd entry in that list. Else...
#
# - $outfile is set to $infile stripped of its extension.
#
# If the first argument is -touch then the generated file is touched
# to update its timestamp. This can be used as a workaround for
# cases where (A) autosetup does not update the file because it was
# not really modified and (B) the file *really* needs to be updated to
# please the build process.
#
# Failures when running chmod or touch are silently ignored.
proc proj-make-from-dot-in {args} {
  set fIn ""
  set fOut ""
  set touch 0
  if {[lindex $args 0] eq "-touch"} {
    set touch 1
    lassign $args - fIn fOut
  } else {
    lassign $args fIn fOut
  }
  if {"" eq $fOut} {
    if {2==[llength $fIn]} {
      lassign $fIn fIn fOut
    } else {
      set fOut [file rootname $fIn]
    }
  }
  #puts "filenames=$filename"
  if {[file exists $fOut]} {
    catch { exec chmod u+w $fOut }
  }
  #puts "making template: $fIn ==> $fOut"
  make-template $fIn $fOut
  if {$touch} {
    proj-touch $fOut
  }
  catch {
    exec chmod -w $fOut
    #file attributes -w $f; #jimtcl has no 'attributes'

  }
}

########################################################################
# @proj-check-profile-flag ?flagname?
#
# Checks for the boolean configure option named by $flagname. If set,
1472
1473
1474
1475
1476
1477
1478











































































        define prefix $hpre
        return 1
      }
    }
  }
  return 0
}


















































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
        define prefix $hpre
        return 1
      }
    }
  }
  return 0
}

########################################################################
# @proj-dot-ins-append {file ?fileOut?}...
#
# Queues up an autosetup [make-template]-style file to be processed
# at a later time using [proj-dot-ins-process].
#
# $file is the input file. If $fileOut is empty then this function
# derives $fileOut from $file, stripping both its directory and
# extension parts.
#
# See [proj-dot-ins-process]
proc proj-dot-ins-append {args} {
  set srcdir $::autosetup(srcdir)
  foreach f ${args} {
    if {1==[llength $f]} {
      lappend f [file rootname [file tail $f]]
    }
    #puts "******* [proj-current-proc-name]: adding $f"
    lappend ::proj_(dot-in-files) $f
  }
}

########################################################################
# @proj-dot-ins-list
#
# Returns the current list of [proj-dot-ins-append]'d files, noting
# that each entry is a 2-element list.
proc proj-dot-ins-list {} {
  return $::proj_(dot-in-files)
}

########################################################################
# @proj-dot-ins-process ?-touch?
#
# Each file which has previously been passed to [proj-dot-ins-append]
# is processed, with its passing its in-file out-file names to
# [proj-make-from-dot-in].
#
# The optional argument may be the -touch flag, which is passed on to
# that [proj-make-from-dot-in].
#
# The intent is that a project accumulate any number of files to
# filter and delay their actual filtering until the last stage of the
# configure script, calling this function at that time.
proc proj-dot-ins-process {args} {
  set flags ""
  if {"-touch" eq $args} {
    set flags "-touch"
  }
  foreach f $::proj_(dot-in-files) {
    proj-assert {2==[llength $f]}
    lassign $f fIn fOut
    #puts "DOING $fIn  ==> $fOut"
    proj-make-from-dot-in {*}$flags $fIn $fOut
  }
}

########################################################################
# @proj-validate-no-unresolved-ats filenames...
#
# For each filename given to it, it validates that the file has no
# unresolved @VAR@ references. If it finds any, it produces an error
# with location information.
proc proj-validate-no-unresolved-ats {args} {
  foreach f $args {
    set lnno 1
    foreach line [proj-file-content-list $f] {
      if {[regexp {(@[A-Za-z0-9_]+@)} $line match]} {
        error "Unresolved reference to $match at line $lnno of $f"
      }
      incr lnno
    }
  }
}
Changes to autosetup/sqlite-config.tcl.
486
487
488
489
490
491
492






493
494
495
496
497
498
499
    # library.  Perhaps it did back in the early 2000's. The
    # --enable/disable-largefile flag is retained because it's
    # harmless, but it doesn't do anything useful. It does have
    # visible side-effects, though: the generated sqlite_cfg.h may (or
    # may not) define HAVE_LFS.
    cc-check-lfs
  }






}; # sqlite-configure-phase1

########################################################################
# Performs late-stage config steps common to all supported
# $::sqliteConfig(build-mode) values.
proc sqlite-configure-finalize {} {
  sqlite-handle-rpath







>
>
>
>
>
>







486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
    # library.  Perhaps it did back in the early 2000's. The
    # --enable/disable-largefile flag is retained because it's
    # harmless, but it doesn't do anything useful. It does have
    # visible side-effects, though: the generated sqlite_cfg.h may (or
    # may not) define HAVE_LFS.
    cc-check-lfs
  }

  set srcdir $::autosetup(srcdir)
  proj-dot-ins-append $srcdir/Makefile.in
  if {[file exists $srcdir/sqlite3.pc.in]} {
    proj-dot-ins-append $srcdir/sqlite3.pc.in
  }
}; # sqlite-configure-phase1

########################################################################
# Performs late-stage config steps common to all supported
# $::sqliteConfig(build-mode) values.
proc sqlite-configure-finalize {} {
  sqlite-handle-rpath
1001
1002
1003
1004
1005
1006
1007







1008

1009

1010
1011
1012
1013
1014
1015
1016
    proj-bin-define bash; # ext/wasm/GNUmakefile requires bash
    if {[file-isexec $emsdkHome/upstream/bin/wasm-opt]} {
      define BIN_WASM_OPT $emsdkHome/upstream/bin/wasm-opt
    } else {
      # Maybe there's a copy in the path?
      proj-bin-define wasm-opt BIN_WASM_OPT
    }







    proj-make-from-dot-in $emccSh $extWasmConfig

    catch {exec chmod u+x $emccSh}

  } else {
    define EMCC_WRAPPER ""
    file delete -force -- $emccSh $extWasmConfig
  }
}

########################################################################







>
>
>
>
>
>
>
|
>

>







1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
    proj-bin-define bash; # ext/wasm/GNUmakefile requires bash
    if {[file-isexec $emsdkHome/upstream/bin/wasm-opt]} {
      define BIN_WASM_OPT $emsdkHome/upstream/bin/wasm-opt
    } else {
      # Maybe there's a copy in the path?
      proj-bin-define wasm-opt BIN_WASM_OPT
    }
    #
    # We would prefer to pass these to proj-dot-ins-append but that
    # family of APIs cannot handle the output being in a dir other
    # than the current one. Also, we need to chmod +x $emccSh, and we
    # don't have a hook to do that with if we defer dot-in-processing
    # it.
    #
    proj-make-from-dot-in $emccSh.in
    proj-make-from-dot-in $extWasmConfig.in
    catch {exec chmod u+x $emccSh}
    proj-validate-no-unresolved-ats $emccSh $extWasmConfig
  } else {
    define EMCC_WRAPPER ""
    file delete -force -- $emccSh $extWasmConfig
  }
}

########################################################################
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
  #
  # We do this late in the config process, immediately before we export
  # the Makefile and other generated files, so that configure tests
  # which make make use of the autotools-conventional flags
  # (e.g. [proj-check-rpath]) may do so before we "mangle" them here.
  proj-remap-autoconf-dir-vars

  set srcdir $::autosetup(srcdir)/
  foreach f {Makefile sqlite3.pc} {
    if {[file exists $srcdir/$f.in]} {
      # ^^^ we do this only so that this block can be made to work for
      # multiple builds. e.g. the tea build (under construction) does
      # not hae sqlite3.pc.in.
      proj-make-from-dot-in -touch $f
    }
  }
  make-config-header sqlite_cfg.h \
    -bare {SIZEOF_* HAVE_DECL_*} \
    -none {HAVE_CFLAG_* LDFLAGS_* SH_* SQLITE_AUTORECONFIG
      TARGET_* USE_GCOV TCL_*} \
    -auto {HAVE_* PACKAGE_*} \
    -none *
  proj-touch sqlite_cfg.h ; # help avoid frequent unnecessary @SQLITE_AUTORECONFIG@







<
<
<
<
<
<
|
<
<







1736
1737
1738
1739
1740
1741
1742






1743


1744
1745
1746
1747
1748
1749
1750
  #
  # We do this late in the config process, immediately before we export
  # the Makefile and other generated files, so that configure tests
  # which make make use of the autotools-conventional flags
  # (e.g. [proj-check-rpath]) may do so before we "mangle" them here.
  proj-remap-autoconf-dir-vars







  proj-dot-ins-process


  make-config-header sqlite_cfg.h \
    -bare {SIZEOF_* HAVE_DECL_*} \
    -none {HAVE_CFLAG_* LDFLAGS_* SH_* SQLITE_AUTORECONFIG
      TARGET_* USE_GCOV TCL_*} \
    -auto {HAVE_* PACKAGE_*} \
    -none *
  proj-touch sqlite_cfg.h ; # help avoid frequent unnecessary @SQLITE_AUTORECONFIG@
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
#
# 2) TBD
proc sqlite-post-config-validation {} {
  # Check #1: ensure that files which get filtered for @VAR@ do not
  # contain any unresolved @VAR@ refs. That may indicate an
  # unexported/unused var or a typo.
  set srcdir $::autosetup(srcdir)
  foreach f [list Makefile sqlite3.pc \
             $srcdir/tool/emcc.sh \
             $srcdir/ext/wasm/config.make] {
    if {![file exists $f]} continue
    set lnno 1
    foreach line [proj-file-content-list $f] {
      if {[regexp {(@[A-Za-z0-9_]+@)} $line match]} {
        error "Unresolved reference to $match at line $lnno of $f"
      }
      incr lnno
    }
  }
}

########################################################################
# Handle --with-wasi-sdk[=DIR]
#
# This must be run relatively early on because it may change the







|
<
<
<
<
|
<
|
<
<
<







1758
1759
1760
1761
1762
1763
1764
1765




1766

1767



1768
1769
1770
1771
1772
1773
1774
#
# 2) TBD
proc sqlite-post-config-validation {} {
  # Check #1: ensure that files which get filtered for @VAR@ do not
  # contain any unresolved @VAR@ refs. That may indicate an
  # unexported/unused var or a typo.
  set srcdir $::autosetup(srcdir)
  foreach f [proj-dot-ins-list] {




    proj-assert {2==[llength $f]}

    proj-validate-no-unresolved-ats [lindex $f 1]



  }
}

########################################################################
# Handle --with-wasi-sdk[=DIR]
#
# This must be run relatively early on because it may change the