SQLite

Check-in [84e503dc1e]
Login

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

Overview
Comment:Move the linenoise flavor check from auto.def to proj.tcl for re-use in downstream projects.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 84e503dc1e3672fe7787fb747ed70ca14ad181a743925bd1658c40baaa8a27cd
User & Date: stephan 2024-10-30 22:49:40.804
Context
2024-10-30
23:10
Minor cleanups to the linenoise flavor detection test. (check-in: 3be32de162 user: stephan tags: trunk)
22:49
Move the linenoise flavor check from auto.def to proj.tcl for re-use in downstream projects. (check-in: 84e503dc1e user: stephan tags: trunk)
22:41
Expand [c0048e4482e9] to determine the linenoise API flavor via a compile test rather than guessing based on the filename. (check-in: dbf0079190 user: stephan tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to auto.def.
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
    }
  }
  msg-result $ts
  define TEMP_STORE $tsn
  unset ts tsn
}

########################################################################
# Attempts to determine whether the given linenoise header file is of
# the "antirez" or "msteveb" flavor. It returns 1 for antirez, 2 for
# msteveb, and 0 if it's neither.
proc sqlite-which-linenoise {dotH} {
  set sourceOrig {
    #include <stdio.h>
    #include <stdlib.h>
    #include <stddef.h>
    /* size_t has to be be in there _somewhere_ */
  }
  append sourceOrig [proj-file-content $dotH]
  set sourceTail {
    int main(void) {
      linenoiseSetCompletionCallback(0 $arg);
      return 0;
    }
  }
  set arg ""
  set source $sourceOrig
  append source [subst $sourceTail]
  if {[cctest -nooutput 1 -source $source]} {
    return 1
  }
  set arg ", 0"
  set source $sourceOrig
  append source [subst $sourceTail]
  if {[cctest -nooutput 1 -source $source]} {
    return 2
  }
  return 0
}

########################################################################
# sqlite-check-line-editing jumps through proverbial hoops to try to
# find a working line-editing library, setting:
#
#   - HAVE_READLINE to 0 or 1
#   - HAVE_LINENOISE to 0, 1, or 2
#   - HAVE_EDITLINE to 0 or 1







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







727
728
729
730
731
732
733

































734
735
736
737
738
739
740
    }
  }
  msg-result $ts
  define TEMP_STORE $tsn
  unset ts tsn
}


































########################################################################
# sqlite-check-line-editing jumps through proverbial hoops to try to
# find a working line-editing library, setting:
#
#   - HAVE_READLINE to 0 or 1
#   - HAVE_LINENOISE to 0, 1, or 2
#   - HAVE_EDITLINE to 0 or 1
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849








850

851
852
853
854
855
856
857
858
    if {![file isdir $dirLn]} {
      proj-fatal "--with-linenoise value is not a directory"
    }
    set lnH $dirLn/linenoise.h
    if {![file exists $lnH] } {
      proj-fatal "Cannot find linenoise.h in $dirLn"
    }
    set flavor ""
    switch -- [sqlite-which-linenoise $lnH] {
      1 {
        set flavor "antirez"
        define HAVE_LINENOISE 1
      }
      2 {
        set flavor "msteveb"
        define HAVE_LINENOISE 2
      }
      default {
        user-error "Cannot determine the flavor of linenoise from $lnH"
      }
    }
    set lnC ""
    set lnCOpts {linenoise-ship.c linenoise.c}
    foreach f $lnCOpts {
      if {[file exists $dirLn/$f]} {
        set lnC $dirLn/$f
        break;
      }
    }
    if {"" eq $lnC} {
      proj-fatal "Cannot find any of $lnCOpts in $dirLn"
    }
    msg-result "Using $flavor linenoise from $dirLn"








    define CFLAGS_READLINE "-I$dirLn $lnC"

    sqlite-add-shell-opt -DHAVE_LINENOISE=[get-define HAVE_LINENOISE]
    return "linenoise ($flavor)"
  } elseif {[opt-bool editline]} {
    # libedit mimics libreadline and on some systems does not have its
    # own header installed (instead, that of libreadline is used).
    #
    # shell.c historically expects HAVE_EDITLINE to be set for
    # libedit, but it then expects to see <editline/readline.h>, which







<
<
<
<
<
<
<
<
<
<
<
<
<
<











|
>
>
>
>
>
>
>
>

>
|







784
785
786
787
788
789
790














791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
    if {![file isdir $dirLn]} {
      proj-fatal "--with-linenoise value is not a directory"
    }
    set lnH $dirLn/linenoise.h
    if {![file exists $lnH] } {
      proj-fatal "Cannot find linenoise.h in $dirLn"
    }














    set lnC ""
    set lnCOpts {linenoise-ship.c linenoise.c}
    foreach f $lnCOpts {
      if {[file exists $dirLn/$f]} {
        set lnC $dirLn/$f
        break;
      }
    }
    if {"" eq $lnC} {
      proj-fatal "Cannot find any of $lnCOpts in $dirLn"
    }
    set flavor ""
    set lnVal [proj-which-linenoise $lnH]
    switch -- $lnVal {
      1 { set flavor "antirez" }
      2 { set flavor "msteveb" }
      default {
        proj-fatal "Cannot determine the flavor of linenoise from $lnH"
      }
    }
    define CFLAGS_READLINE "-I$dirLn $lnC"
    define HAVE_LINENOISE $lnVal
    sqlite-add-shell-opt -DHAVE_LINENOISE=$lnVal
    return "linenoise ($flavor)"
  } elseif {[opt-bool editline]} {
    # libedit mimics libreadline and on some systems does not have its
    # own header installed (instead, that of libreadline is used).
    #
    # shell.c historically expects HAVE_EDITLINE to be set for
    # libedit, but it then expects to see <editline/readline.h>, which
Changes to autosetup/proj.tcl.
985
986
987
988
989
990
991

































  if {![proj-is-cross-compiling]
     && "nope" eq [get-env CC_FOR_BUILD "nope"]
     && [get-define CC] ne [get-define CC_FOR_BUILD]} {
    user-notice "Re-defining CC_FOR_BUILD to CC=[get-define CC]. To avoid this, explicitly pass CC_FOR_BUILD=..."
    define CC_FOR_BUILD [get-define CC]
  }
}








































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
  if {![proj-is-cross-compiling]
     && "nope" eq [get-env CC_FOR_BUILD "nope"]
     && [get-define CC] ne [get-define CC_FOR_BUILD]} {
    user-notice "Re-defining CC_FOR_BUILD to CC=[get-define CC]. To avoid this, explicitly pass CC_FOR_BUILD=..."
    define CC_FOR_BUILD [get-define CC]
  }
}

########################################################################
# Attempts to determine whether the given linenoise header file is of
# the "antirez" or "msteveb" flavor. It returns 1 for antirez, 2 for
# msteveb, and 0 if it's neither.
proc proj-which-linenoise {dotH} {
  set sourceOrig {
    #include <stdio.h>
    #include <stdlib.h>
    #include <stddef.h>
    /* size_t has to be be in there _somewhere_ */
  }
  append sourceOrig [proj-file-content $dotH]
  set sourceTail {
    int main(void) {
      linenoiseSetCompletionCallback(0 $arg);
      return 0;
    }
  }
  set arg ""
  set source $sourceOrig
  append source [subst $sourceTail]
  if {[cctest -nooutput 1 -source $source]} {
    return 1
  }
  set arg ", 0"
  set source $sourceOrig
  append source [subst $sourceTail]
  if {[cctest -nooutput 1 -source $source]} {
    return 2
  }
  return 0
}