auto.def 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440
  1. #/do/not/tclsh
  2. # ^^^ help out editors which guess this file's content type.
  3. #
  4. # This is the main autosetup-compatible configure script for the
  5. # SQLite project.
  6. #
  7. # This script should be kept compatible with JimTCL, a copy of which
  8. # is included in this source tree as ./autosetup/jimsh0.c. The number
  9. # of incompatibilities between canonical TCL and JimTCL is very low
  10. # and alternative formulations of incompatible constructs have, so
  11. # far, been easy to find.
  12. #
  13. # JimTCL: https://jim.tcl.tk
  14. #
  15. use cc cc-db cc-shared cc-lib proj pkg-config
  16. # $DUMP_DEFINES_TXT is the file emitted by --dump-defines, intended
  17. # only for build debugging and not part of the public build interface.
  18. set DUMP_DEFINES_TXT ./config.defines.txt
  19. # $DUMP_DEFINES_JSON is the autosetup counterpart of the historical
  20. # "DEFS" var which was generated by the autotools in the pre-processed
  21. # autotools builds (but not in the canonical tree). Generation of this
  22. # file is disabled (via an empty file name) until/unless someone
  23. # voices a specific interest in it. The original motivating use case
  24. # is handled fine by sqlite_cfg.h.
  25. set DUMP_DEFINES_JSON ""; #./config.defines.json
  26. ########################################################################
  27. # Regarding flag compatibility with the historical autotool configure
  28. # script:
  29. #
  30. # A very long story made short, autosetup's --flag handling has
  31. # some behaviors which make it impossible to implement 100% identical
  32. # flags compared to the historical autotools build. The differences
  33. # are documented here:
  34. #
  35. # 1) --debug is used by autosetup itself, so we have to rename it to
  36. # --with-debug. We cannot use --enable-debug because that is, for
  37. # autosetup, an alias for --debug=1. Alternately, we can patch
  38. # autosetup to use --autosetup-debug for its own purposes instead.
  39. #
  40. # 2) In autosetup, all flags starting with (--enable, --disable) are
  41. # forced to be booleans and receive special handling in how they're
  42. # resolved. Because of that we have to rename:
  43. #
  44. # 2.1) --enable-tempstore[=no] to --with-tempstore[=no], noting that
  45. # it has four legal values, not two.
  46. #
  47. ########################################################################
  48. # A gentle introduction to flags handling in autosetup
  49. #
  50. # Reference: https://msteveb.github.io/autosetup/developer/
  51. #
  52. # All configure flags must be described in an 'options' call, which
  53. # must appear very early on in this script. The general syntax is:
  54. #
  55. # FLAG => {Help text}
  56. #
  57. # Where FLAG can have any of the following formats:
  58. #
  59. # boolopt => "a boolean option which defaults to disabled"
  60. # boolopt2=1 => "a boolean option which defaults to enabled"
  61. # stringopt: => "an option which takes an argument, e.g. --stringopt=value"
  62. # stringopt2:=value => "an option where the argument is optional and defaults to 'value'"
  63. # optalias booltopt3 => "a boolean with a hidden alias. --optalias is not shown in --help"
  64. #
  65. # Autosetup does no small amount of specialized handling for flags,
  66. # especially booleans. Each bool-type --FLAG implicitly gets
  67. # --enable-FLAG and --disable-FLAG forms. e.g. we define a flag
  68. # "readline", which will be interpreted in one of two ways, depending
  69. # on how it's invoked and how its default is defined:
  70. #
  71. # --enable-readline ==> boolean true
  72. # --disable-readline ==> boolean false
  73. #
  74. # Passing --readline or --readline=1 is equivalent to passing
  75. # --enable-readline, and --readline=0 is equivalent to
  76. # --disable-readline.
  77. #
  78. # The behavior described above can lead lead to some confusion when
  79. # writing help text. For example:
  80. #
  81. # options { json=1 {Disable JSON functions} }
  82. #
  83. # The reason the help text says "disable" is because a boolean option
  84. # which defaults to true is, in the --help text, rendered as:
  85. #
  86. # --disable-json Disable JSON functions
  87. #
  88. # Whereas a bool flag which defaults to false will instead render as:
  89. #
  90. # --enable-FLAG
  91. #
  92. # Non-boolean flags, in contrast, use the names specifically given to
  93. # them in the [options] invocation. e.g. "with-tcl" is the --with-tcl
  94. # flag.
  95. #
  96. # Fetching values for flags:
  97. #
  98. # booleans: use one of:
  99. # - [opt-bool FLAG] is autosetup's built-in command for this, but we
  100. # have some convenience variants:
  101. # - [proj-opt-truthy FLAG]
  102. # - [proj-opt-if-truthy FLAG {THEN} {ELSE}]
  103. #
  104. # Non-boolean (i.e. string) flags:
  105. # - [opt-val FLAG ?default?]
  106. # - [opt-str ...] - see the docs in ./autosetup/autosetup
  107. #
  108. ########################################################################
  109. set flags {
  110. # When writing {help text blocks}, be aware that autosetup formats
  111. # them differently (left-aligned, directly under the --flag) if the
  112. # block starts with a newline. It does NOT expand vars and commands,
  113. # but we use a [subst] call below which will replace (only) var
  114. # refs.
  115. # <build-modes>
  116. shared=1 => {Disable build of shared libary}
  117. static=1 => {Disable build of static library (mostly)}
  118. amalgamation=1 => {Disable the amalgamation and instead build all files separately.}
  119. # </build-modes>
  120. # <lib-feature>
  121. threadsafe=1 => {Disable mutexing}
  122. with-tempstore:=no => {Use an in-RAM database for temporary tables: never,no,yes,always}
  123. largefile=1 => {Disable large file support}
  124. load-extension=1 => {Disable loading of external extensions}
  125. math=1 => {Disable math functions}
  126. json=1 => {Disable JSON functions}
  127. memsys5 => {Enable MEMSYS5}
  128. memsys3 => {Enable MEMSYS3}
  129. fts3 => {Enable the FTS3 extension}
  130. fts4 => {Enable the FTS4 extension}
  131. fts5 => {Enable the FTS5 extension}
  132. update-limit => {Enable the UPDATE/DELETE LIMIT clause}
  133. geopoly => {Enable the GEOPOLY extension}
  134. rtree => {Enable the RTREE extension}
  135. session => {Enable the SESSION extension}
  136. all => {Enable FTS4, FTS5, Geopoly, RTree, Sessions}
  137. # </lib-feature>
  138. # <tcl>
  139. with-tcl:DIR =>
  140. {Directory containing tclConfig.sh or a directory one level up from
  141. that, from which we can derive a directory containing tclConfig.sh.
  142. A dir name of "prefix" is equivalent to the directory specified by
  143. the --prefix flag.}
  144. with-tclsh:PATH =>
  145. {Full pathname of tclsh to use. It is used for (A) trying to find
  146. tclConfig.sh and (B) all TCL-based code generation. Warning: if
  147. its containing dir has multiple tclsh versions, it may select the
  148. wrong tclConfig.sh!}
  149. tcl=1 =>
  150. {Disable components which require TCL, including all tests.
  151. This tree requires TCL for code generation but can use the in-tree
  152. copy of autosetup/jimsh0.c for that. The SQLite TCL extension and the
  153. test code require a canonical tclsh.}
  154. # <tcl>
  155. # <line-editing>
  156. readline=1 => {Disable readline support}
  157. # --with-readline-lib is a backwards-compatible alias for
  158. # --with-readline-ldflags
  159. with-readline-lib:
  160. with-readline-ldflags:=auto
  161. => {Readline LDFLAGS, e.g. -lreadline -lncurses}
  162. # --with-readline-inc is a backwards-compatible alias for
  163. # --with-readline-cflags.
  164. with-readline-inc:
  165. with-readline-cflags:=auto
  166. => {Readline CFLAGS, e.g. -I/path/to/includes}
  167. with-readline-header:PATH
  168. => {Full path to readline.h, from which --with-readline-cflags will be derived}
  169. with-linenoise:DIR => {Source directory for linenoise.c and linenoise.h}
  170. editline=0 => {Enable BSD editline support}
  171. # </line-editing>
  172. # <icu>
  173. with-icu-ldflags:LDFLAGS
  174. => {Enable SQLITE_ENABLE_ICU and add the given linker flags for the ICU libraries}
  175. with-icu-cflags:CFLAGS
  176. => {Apply extra CFLAGS/CPPFLAGS necessary for building with ICU. e.g. -I/usr/local/include}
  177. with-icu-config:=auto => {Enable SQLITE_ENABLE_ICU. Value must be one of: auto, pkg-config, /path/to/icu-config}
  178. icu-collations=0 => {Enable SQLITE_ENABLE_ICU_COLLATIONS. Requires --with-icu-ldflags=... or --with-icu-config}
  179. # </icu>
  180. # <alternative-builds>
  181. with-wasi-sdk:=/opt/wasi-sdk
  182. => {Top-most dir of the wasi-sdk for a WASI build}
  183. with-emsdk:=auto => {Top-most dir of the Emscripten SDK installation. Default = EMSDK env var.}
  184. # </alternative-builds>
  185. # <developer>
  186. # Note that using the --debug/--enable-debug flag here requires patching
  187. # autosetup/autosetup to rename the --debug to --autosetup-debug.
  188. with-debug=0
  189. debug=0 =>
  190. {Enable debug build flags. This option will impact performance by
  191. as much as 4x, as it includes large numbers of assert()s in
  192. performance-critical loops. Never use --debug for production
  193. builds.}
  194. scanstatus => {Enable the SQLITE_ENABLE_STMT_SCANSTATUS feature flag}
  195. dev => {Enable dev-mode build: automatically enables certain other flags}
  196. test-status => {Enable status of tests}
  197. gcov=0 => {Enable coverage testing using gcov}
  198. linemacros => {Enable #line macros in the amalgamation}
  199. dump-defines=0 => {Dump autosetup defines to $DUMP_DEFINES_TXT (for build debugging)}
  200. dynlink-tools => {Dynamically link libsqlite3 to certain tools which normally statically embed it.}
  201. soname:=legacy =>
  202. {SONAME for libsqlite3.so. "none", or not using this flag, sets no
  203. soname. "legacy" sets it to its historical value of
  204. libsqlite3.so.0. A value matching the glob "libsqlite3.*" sets
  205. it to that literal value. Any other value is assumed to be a
  206. suffix which gets applied to "libsqlite3.so.",
  207. e.g. --soname=9.10 equates to "libsqlite3.so.9.10".
  208. }
  209. # --soname has a long story behind it: https://sqlite.org/src/forumpost/5a3b44f510df8ded
  210. # </developer>
  211. }
  212. if {"" ne $DUMP_DEFINES_JSON} {
  213. lappend flags \
  214. defines-json-include-lowercase=0 \
  215. => {Include lower-case defines (primarily system paths) in $DUMP_DEFINES_JSON}
  216. }
  217. options [subst -nobackslashes -nocommands $flags]
  218. unset flags
  219. #
  220. # Carry values from hidden --flag aliases over to their canonical flag
  221. # forms.
  222. #
  223. proj-xfer-options-aliases {
  224. with-readline-inc => with-readline-cflags
  225. with-readline-lib => with-readline-ldflags
  226. with-debug => debug
  227. }
  228. set srcdir $::autosetup(srcdir)
  229. set PACKAGE_VERSION [proj-file-content -trim $srcdir/VERSION]
  230. define PACKAGE_NAME "sqlite"
  231. define PACKAGE_URL {https://sqlite.org}
  232. define PACKAGE_VERSION $PACKAGE_VERSION
  233. define PACKAGE_STRING "[get-define PACKAGE_NAME] $PACKAGE_VERSION"
  234. define PACKAGE_BUGREPORT [get-define PACKAGE_URL]/forum
  235. msg-result "Source dir = $srcdir"
  236. msg-result "Build dir = $::autosetup(builddir)"
  237. msg-result "Configuring SQLite version $PACKAGE_VERSION"
  238. apply {{} {
  239. #
  240. # SQLITE_AUTORECONFIG contains make target rules for re-running the
  241. # configure script with the same arguments it was initially invoked
  242. # with. This can be used to automatically reconfigure
  243. #
  244. proc squote {arg} {
  245. # Wrap $arg in single-quotes if it looks like it might need that
  246. # to avoid mis-handling as a shell argument. We assume that $arg
  247. # will never contain any single-quote characters.
  248. if {[string match {*[ &;$*"]*} $arg]} { return '$arg' }
  249. return $arg
  250. }
  251. define-append SQLITE_AUTORECONFIG cd [squote $::autosetup(builddir)] && [squote $::srcdir/configure]
  252. #{*}$::autosetup(argv) breaks with --flag='val with spaces', so...
  253. foreach arg $::autosetup(argv) {
  254. define-append SQLITE_AUTORECONFIG [squote $arg]
  255. }
  256. rename squote ""
  257. }}
  258. # Are we cross-compiling?
  259. set isCrossCompiling [proj-is-cross-compiling]
  260. define OPT_FEATURE_FLAGS {} ; # -DSQLITE_OMIT/ENABLE flags.
  261. define OPT_SHELL {} ; # Feature-related CFLAGS for the sqlite3 CLI app
  262. ########################################################################
  263. # Adds $args, if not empty, to OPT_FEATURE_FLAGS. If the first arg is
  264. # -shell then it strips that arg and passes the remaining args the
  265. # sqlite-add-shell-opt in addition to adding them to
  266. # OPT_FEATURE_FLAGS.
  267. proc sqlite-add-feature-flag {args} {
  268. set shell ""
  269. if {"-shell" eq [lindex $args 0]} {
  270. set args [lassign $args shell]
  271. }
  272. if {"" ne $args} {
  273. if {"" ne $shell} {
  274. sqlite-add-shell-opt {*}$args
  275. }
  276. define-append OPT_FEATURE_FLAGS {*}$args
  277. }
  278. }
  279. # Appends $args, if not empty, to OPT_SHELL.
  280. proc sqlite-add-shell-opt {args} {
  281. if {"" ne $args} {
  282. define-append OPT_SHELL {*}$args
  283. }
  284. }
  285. # Pass msg-debug=1 to configure to enable obnoxiously loud output from
  286. # msg-debug.
  287. set msgDebugEnabled [proj-val-truthy [get-env msg-debug 0]]
  288. proc msg-debug {msg} {
  289. if {$::msgDebugEnabled} {
  290. puts stderr [proj-bold "** DEBUG: $msg"]
  291. }
  292. }
  293. proj-file-extensions
  294. if {".exe" eq [get-define TARGET_EXEEXT]} {
  295. define SQLITE_OS_UNIX 0
  296. define SQLITE_OS_WIN 1
  297. } else {
  298. define SQLITE_OS_UNIX 1
  299. define SQLITE_OS_WIN 0
  300. }
  301. #########
  302. # Programs needed
  303. cc-check-tools ld ar ; # must come before [sqlite-check-wasi-sdk]
  304. if {"" eq [proj-bin-define install]} {
  305. proj-warn "Cannot find install binary, so 'make install' will not work."
  306. define BIN_INSTALL false
  307. }
  308. ########################################################################
  309. # We differentiate between two C compilers: the one used for binaries
  310. # which are to run on the build system (in autosetup it's called
  311. # CC_FOR_BUILD and in Makefile.in it's $(B.cc)) and the one used for
  312. # compiling binaries for the target system (CC a.k.a. $(T.cc)).
  313. # Normally they're the same, but they will differ when
  314. # cross-compiling.
  315. define CFLAGS [proj-get-env CFLAGS {-g -O2}]
  316. define BUILD_CFLAGS [proj-get-env BUILD_CFLAGS {-g}]
  317. proj-if-opt-truthy dev {
  318. # --enable-dev needs to come early so that the downstream tests
  319. # which check for the following flags use their updated state.
  320. proj-opt-set all 1
  321. proj-opt-set debug 1
  322. proj-opt-set amalgamation 0
  323. define CFLAGS [get-env CFLAGS {-O0 -g}]
  324. }
  325. ########################################################################
  326. # Handle --with-wasi-sdk=DIR
  327. #
  328. # This must be run relatively early on because it may change the
  329. # toolchain and disable a number of config options.
  330. proc sqlite-check-wasi-sdk {} {
  331. set wasiSdkDir [opt-val with-wasi-sdk] ; # ??? [lindex [opt-val with-wasi-sdk] end]
  332. define HAVE_WASI_SDK 0
  333. if {$wasiSdkDir eq ""} {
  334. return 0
  335. } elseif {$::isCrossCompiling} {
  336. proj-fatal "Cannot combine --with-wasi-sdk with cross-compilation"
  337. }
  338. msg-result "Checking WASI SDK directory \[$wasiSdkDir]... "
  339. #puts "prefix = [prefix $wasiSdkDir/bin {clang ld}]"
  340. proj-affirm-files-exist -v {*}[prefix "$wasiSdkDir/bin/" {clang wasm-ld ar}]
  341. define HAVE_WASI_SDK 1
  342. define WASI_SDK_DIR $wasiSdkDir
  343. # Disable numerous options which we know either can't work or are
  344. # not useful in this build...
  345. msg-result "Using wasi-sdk clang. Disabling CLI shell modifying config flags:"
  346. # Boolean (--enable-/--disable-) flags which must be switched off:
  347. foreach opt {
  348. dynlink-tools
  349. editline
  350. gcov
  351. icu-collations
  352. load-extension
  353. readline
  354. shared
  355. tcl
  356. threadsafe
  357. } {
  358. if {[opt-bool $opt]} {
  359. msg-result " --disable-$opt"
  360. proj-opt-set $opt 0
  361. }
  362. }
  363. # Non-boolean flags which need to be cleared:
  364. foreach opt {
  365. with-emsdk
  366. with-icu-config
  367. with-icu-ldflags
  368. with-icu-cflags
  369. with-linenoise
  370. with-tcl
  371. } {
  372. if {[proj-opt-was-provided $opt]} {
  373. msg-result " removing --$opt"
  374. proj-opt-set $opt ""
  375. }
  376. }
  377. # Remember that we now have a discrepancy beteween
  378. # $::isCrossCompiling and [proj-is-cross-compiling].
  379. set ::isCrossCompiling 1
  380. #
  381. # Changing --host and --target have no effect here except to
  382. # possibly cause confusion. Autosetup has finished processing them
  383. # by this point.
  384. #
  385. # host_alias=wasm32-wasi
  386. # target=wasm32-wasi
  387. #
  388. # Merely changing CC, LD, and AR to the wasi-sdk's is enough to get
  389. # sqlite3.o building in WASM format.
  390. #
  391. define CC "${wasiSdkDir}/bin/clang"
  392. define LD "${wasiSdkDir}/bin/wasm-ld"
  393. define AR "${wasiSdkDir}/bin/ar"
  394. #define STRIP "${wasiSdkDir}/bin/strip"
  395. return 1
  396. }; # sqlite-check-wasi-sdk
  397. sqlite-check-wasi-sdk
  398. ########################################################################
  399. # --dynlink-tools tells the build to dynamically link certain binaries
  400. # to libsqlite3.so instead of embedding a copy of the amalgamation.
  401. define LINK_TOOLS_DYNAMICALLY [proj-opt-was-provided dynlink-tools]
  402. #
  403. # Enable large file support (if special flags are necessary)
  404. define HAVE_LFS 0
  405. if {[opt-bool largefile]} {
  406. cc-check-lfs
  407. }
  408. #
  409. # Check for needed/wanted data types
  410. cc-with {-includes stdint.h} \
  411. {cc-check-types int8_t int16_t int32_t int64_t intptr_t \
  412. uint8_t uint16_t uint32_t uint64_t uintptr_t}
  413. #
  414. # Check for needed/wanted functions
  415. cc-check-functions gmtime_r isnan localtime_r localtime_s \
  416. malloc_usable_size strchrnul usleep utime pread pread64 pwrite pwrite64
  417. proj-check-function-in-lib fdatasync rt
  418. define LDFLAGS_FDATASYNC [get-define lib_fdatasync]
  419. undefine lib_fdatasync
  420. #
  421. # Check for needed/wanted headers
  422. cc-check-includes \
  423. sys/types.h sys/stat.h dlfcn.h unistd.h \
  424. stdlib.h malloc.h memory.h \
  425. string.h strings.h \
  426. inttypes.h
  427. if {[cc-check-includes zlib.h] && [proj-check-function-in-lib deflate z]} {
  428. # TODO? port over the more sophisticated zlib search from the fossil auto.def
  429. define HAVE_ZLIB 1
  430. define LDFLAGS_ZLIB -lz
  431. sqlite-add-shell-opt -DSQLITE_HAVE_ZLIB=1
  432. } else {
  433. define HAVE_ZLIB 0
  434. define LDFLAGS_ZLIB ""
  435. }
  436. proj-check-rpath ; # Determine proper rpath-handling flag
  437. ########################################################################
  438. # "soname" for libsqlite3.so. See discussion at:
  439. # https://sqlite.org/src/forumpost/5a3b44f510df8ded
  440. apply {{} {
  441. define LDFLAGS_LIBSQLITE3_SONAME ""
  442. if {[proj-opt-was-provided soname]} {
  443. set soname [join [opt-val soname] ""]
  444. } else {
  445. # Enabling soname breaks linking for the --dynlink-tools feature,
  446. # and this project has no direct use for soname, so default to
  447. # none. Package maintainers, on the other hand, like to have an
  448. # soname.
  449. set soname none
  450. }
  451. switch -exact -- $soname {
  452. none - "" { return 0 }
  453. auto { set soname libsqlite3.so.3 }
  454. legacy { set soname libsqlite3.so.0 }
  455. default {
  456. if {[string match libsqlite3.* $soname]} {
  457. # use it as-is
  458. } else {
  459. # Assume it's a suffix
  460. set soname "libsqlite3.so.${soname}"
  461. }
  462. }
  463. }
  464. msg-debug "soname=$soname"
  465. if {[proj-check-soname $soname]} {
  466. define LDFLAGS_LIBSQLITE3_SONAME [get-define LDFLAGS_SONAME_PREFIX]$soname
  467. msg-result "Setting SONAME using: [get-define LDFLAGS_LIBSQLITE3_SONAME]"
  468. } elseif {[proj-opt-was-provided soname]} {
  469. # --soname was explicitly requested but not available, so fail fatally
  470. proj-fatal "This environment does not support SONAME."
  471. } else {
  472. # --soname was not explicitly requested but not available, so just warn
  473. msg-result "This environment does not support SONAME."
  474. }
  475. }}
  476. proj-define-for-opt shared ENABLE_SHARED "Build shared library?"
  477. if {![proj-define-for-opt static ENABLE_STATIC \
  478. "Build static library?"]} {
  479. proj-warn "Static lib build may be implicitly re-activated by other components, e.g. some test apps."
  480. }
  481. proj-define-for-opt amalgamation USE_AMALGAMATION "Use amalgamation for builds?"
  482. proj-define-for-opt gcov USE_GCOV "Use gcov?"
  483. proj-define-for-opt test-status TSTRNNR_OPTS \
  484. "test-runner flags:" {--status} {}
  485. proj-define-for-opt linemacros AMALGAMATION_LINE_MACROS \
  486. "Use #line macros in the amalgamation:"
  487. msg-checking "SQLITE_DEBUG build? "
  488. proj-if-opt-truthy debug {
  489. define SQLITE_DEBUG 1
  490. define TARGET_DEBUG {-g -DSQLITE_DEBUG=1 -DSQLITE_ENABLE_SELECTTRACE -DSQLITE_ENABLE_WHERETRACE -O0 -Wall}
  491. proj-opt-set memsys5
  492. msg-result yes
  493. } {
  494. define TARGET_DEBUG {-DNDEBUG}
  495. msg-result no
  496. }
  497. ########################################################################
  498. # TCL...
  499. #
  500. # sqlite-check-tcl performs most of the --with-tcl and --with-tclsh
  501. # handling. Some related bits and pieces are performed before and
  502. # after that function is called.
  503. #
  504. # Important [define]'d vars:
  505. #
  506. # - HAVE_TCL indicates whether we have a tclsh suitable for building
  507. # the TCL SQLite extension and, by extension, the testing
  508. # infrastructure. This must only be 1 for environments where
  509. # tclConfig.sh can be found.
  510. #
  511. # - TCLSH_CMD is the path to the canonical tclsh or "". It never
  512. # refers to jimtcl.
  513. #
  514. # - TCL_CONFIG_SH is the path to tclConfig.sh or "".
  515. #
  516. # - TCLLIBDIR is the dir to which libtclsqlite3 gets installed.
  517. #
  518. # - BTCLSH = the path to the tcl interpreter used for in-tree code
  519. # generation. It may be jimtcl or the canonical tclsh but may not
  520. # be empty - this tree requires TCL to generated numerous
  521. # components.
  522. #
  523. # If --tcl or --with-tcl are provided but no TCL is found, this
  524. # function fails fatally. If they are not explicitly provided then
  525. # failure to find TCL is not fatal but a loud warning will be emitted.
  526. #
  527. proc sqlite-check-tcl {} {
  528. rename sqlite-check-tcl ""
  529. define TCLSH_CMD false ; # Significant is that it exits with non-0
  530. define HAVE_TCL 0 ; # Will be enabled via --tcl or a successful search
  531. define TCLLIBDIR "" ; # Installation dir for TCL extension lib
  532. define TCL_CONFIG_SH ""; # full path to tclConfig.sh
  533. # Clear out all vars which would be set by tclConfigToAutoDef.sh, so
  534. # that the late-config validation of @VARS@ works even if
  535. # --disable-tcl is used.
  536. foreach k {TCL_INCLUDE_SPEC TCL_LIB_SPEC TCL_STUB_LIB_SPEC TCL_EXEC_PREFIX TCL_VERSION} {
  537. define $k ""
  538. }
  539. file delete -force ".tclenv.sh"; # ensure no stale state from previous configures.
  540. if {![opt-bool tcl]} {
  541. proj-indented-notice {
  542. NOTE: TCL is disabled via --disable-tcl. This means that none
  543. of the TCL-based components will be built, including tests
  544. and sqlite3_analyzer.
  545. }
  546. return
  547. }
  548. # TODO: document the steps this is taking.
  549. global srcdir
  550. msg-result "Checking for a suitable tcl... "
  551. proj-assert [proj-opt-truthy tcl]
  552. set use_tcl 1
  553. set with_tclsh [opt-val with-tclsh]
  554. set with_tcl [opt-val with-tcl]
  555. if {"prefix" eq $with_tcl} {
  556. set with_tcl [get-define prefix]
  557. }
  558. msg-debug "sqlite-check-tcl: use_tcl ${use_tcl}"
  559. msg-debug "sqlite-check-tcl: with_tclsh=${with_tclsh}"
  560. msg-debug "sqlite-check-tcl: with_tcl=$with_tcl"
  561. if {"" eq $with_tclsh && "" eq $with_tcl} {
  562. # If neither --with-tclsh nor --with-tcl are provided, try to find
  563. # a workable tclsh.
  564. set with_tclsh [proj-first-bin-of tclsh9.0 tclsh8.6 tclsh]
  565. msg-debug "sqlite-check-tcl: with_tclsh=${with_tclsh}"
  566. }
  567. set doConfigLookup 1 ; # set to 0 to test the tclConfig.sh-not-found cases
  568. if {"" ne $with_tclsh} {
  569. # --with-tclsh was provided or found above. Validate it and use it
  570. # to trump any value passed via --with-tcl=DIR.
  571. if {![file isfile $with_tclsh]} {
  572. proj-fatal "TCL shell $with_tclsh is not a file"
  573. } elseif {![file-isexec $with_tclsh]} {
  574. proj-fatal "TCL shell $with_tclsh is not executable"
  575. } else {
  576. define TCLSH_CMD $with_tclsh
  577. #msg-result "Using tclsh: $with_tclsh"
  578. }
  579. if {$doConfigLookup &&
  580. [catch {exec $with_tclsh $srcdir/tool/find_tclconfig.tcl} result] == 0} {
  581. set with_tcl $result
  582. }
  583. if {"" ne $with_tcl && [file isdir $with_tcl]} {
  584. msg-result "$with_tclsh recommends the tclConfig.sh from $with_tcl"
  585. } else {
  586. proj-warn "$with_tclsh is unable to recommend a tclConfig.sh"
  587. set use_tcl 0
  588. }
  589. }
  590. set cfg ""
  591. set tclSubdirs {tcl9.0 tcl8.6 lib}
  592. while {$use_tcl} {
  593. if {"" ne $with_tcl} {
  594. # Ensure that we can find tclConfig.sh under ${with_tcl}/...
  595. if {$doConfigLookup} {
  596. if {[file readable "${with_tcl}/tclConfig.sh"]} {
  597. set cfg "${with_tcl}/tclConfig.sh"
  598. } else {
  599. foreach i $tclSubdirs {
  600. if {[file readable "${with_tcl}/$i/tclConfig.sh"]} {
  601. set cfg "${with_tcl}/$i/tclConfig.sh"
  602. break
  603. }
  604. }
  605. }
  606. }
  607. if {"" eq $cfg} {
  608. proj-fatal "No tclConfig.sh found under ${with_tcl}"
  609. }
  610. } else {
  611. # If we have not yet found a tclConfig.sh file, look in
  612. # $libdir which is set automatically by autosetup or by the
  613. # --prefix command-line option. See
  614. # https://sqlite.org/forum/forumpost/e04e693439a22457
  615. set libdir [get-define libdir]
  616. if {[file readable "${libdir}/tclConfig.sh"]} {
  617. set cfg "${libdir}/tclConfig.sh"
  618. } else {
  619. foreach i $tclSubdirs {
  620. if {[file readable "${libdir}/$i/tclConfig.sh"]} {
  621. set cfg "${libdir}/$i/tclConfig.sh"
  622. break
  623. }
  624. }
  625. }
  626. if {![file readable $cfg]} {
  627. break
  628. }
  629. }
  630. msg-result "Using tclConfig.sh: $cfg"
  631. break
  632. }
  633. define TCL_CONFIG_SH $cfg
  634. # Export a subset of tclConfig.sh to the current TCL-space. If $cfg
  635. # is an empty string, this emits empty-string entries for the
  636. # various options we're interested in.
  637. eval [exec "${srcdir}/tool/tclConfigShToAutoDef.sh" "$cfg"]
  638. if {"" eq $with_tclsh && $cfg ne ""} {
  639. # We have tclConfig.sh but no tclsh. Attempt to locate a tclsh
  640. # based on info from tclConfig.sh.
  641. proj-assert {"" ne [get-define TCL_EXEC_PREFIX]}
  642. set with_tclsh [get-define TCL_EXEC_PREFIX]/bin/tclsh[get-define TCL_VERSION]
  643. if {![file-isexec $with_tclsh]} {
  644. set with_tclsh2 [get-define TCL_EXEC_PREFIX]/bin/tclsh
  645. if {![file-isexec $with_tclsh2]} {
  646. proj-warn "Cannot find a usable tclsh (tried: $with_tclsh $with_tclsh2)"
  647. } else {
  648. set with_tclsh $with_tclsh2
  649. }
  650. }
  651. }
  652. define TCLSH_CMD $with_tclsh
  653. if {$use_tcl} {
  654. # Set up the TCLLIBDIR
  655. #
  656. # 2024-10-28: calculation of TCLLIBDIR is now done via the shell
  657. # in main.mk (search it for T.tcl.env.sh) so that
  658. # static/hand-written makefiles which import main.mk do not have
  659. # to define that before importing main.mk. Even so, we export
  660. # TCLLIBDIR from here, which will cause the canonical makefile to
  661. # use this one rather than to re-calculate it at make-time.
  662. set tcllibdir [get-env TCLLIBDIR ""]
  663. if {"" eq $tcllibdir} {
  664. # Attempt to extract TCLLIBDIR from TCL's $auto_path
  665. if {"" ne $with_tclsh &&
  666. [catch {exec echo "puts stdout \$auto_path" | "$with_tclsh"} result] == 0} {
  667. foreach i $result {
  668. if {[file isdir $i]} {
  669. set tcllibdir $i/sqlite3
  670. break
  671. }
  672. }
  673. } else {
  674. proj-warn "Cannot determine TCLLIBDIR."
  675. # The makefile will fail fatally in this case if a target is
  676. # invoked which requires TCLLIBDIR.
  677. }
  678. }
  679. #if {"" ne $tcllibdir} { msg-result "TCLLIBDIR = ${tcllibdir}"; }
  680. define TCLLIBDIR $tcllibdir
  681. }; # find TCLLIBDIR
  682. if {[file-isexec $with_tclsh]} {
  683. msg-result "Using tclsh: $with_tclsh"
  684. if {$cfg ne ""} {
  685. define HAVE_TCL 1
  686. } else {
  687. proj-warn "Found tclsh but no tclConfig.sh."
  688. }
  689. }
  690. show-notices
  691. # If TCL is not found: if it was explicitly requested then fail
  692. # fatally, else just emit a warning. If we can find the APIs needed
  693. # to generate a working JimTCL then that will suffice for build-time
  694. # TCL purposes (see: proc sqlite-determine-codegen-tcl).
  695. if {![get-define HAVE_TCL] &&
  696. ([proj-opt-was-provided tcl] || [proj-opt-was-provided with-tcl])} {
  697. proj-fatal "TCL support was requested but no tclConfig.sh could be found."
  698. }
  699. if {"" eq $cfg} {
  700. proj-assert {0 == [get-define HAVE_TCL]}
  701. proj-indented-notice {
  702. WARNING: Cannot find a usable tclConfig.sh file. Use
  703. --with-tcl=DIR to specify a directory where tclConfig.sh can be
  704. found. SQLite does not use TCL internally, but some optional
  705. components require TCL, including tests and sqlite3_analyzer.
  706. }
  707. }
  708. }; # sqlite-check-tcl
  709. sqlite-check-tcl
  710. ########################################################################
  711. # sqlite-determine-codegen-tcl checks which TCL to use as a code
  712. # generator. By default, prefer jimsh simply because we have it
  713. # in-tree (it's part of autosetup) unless --with-tclsh=X is used, in
  714. # which case prefer X.
  715. #
  716. # Returns the human-readable name of the TCL it selects. Fails fatally
  717. # if it cannot detect a TCL appropriate for code generation.
  718. #
  719. # Defines:
  720. #
  721. # - BTCLSH = the TCL shell used for code generation. It may set this
  722. # to an unexpanded makefile var name.
  723. #
  724. # - CFLAGS_JIMSH = any flags needed for buildng a BTCLSH-compatible
  725. # jimsh. The defaults may be passed on to configure as
  726. # CFLAGS_JIMSH=...
  727. set useJimForCodeGen 0 ; # Set to 1 when using jimsh for code generation.
  728. # May affect later decisions.
  729. proc sqlite-determine-codegen-tcl {} {
  730. rename sqlite-determine-codegen-tcl ""
  731. msg-result "Checking for TCL to use for code generation... "
  732. define CFLAGS_JIMSH [proj-get-env CFLAGS_JIMSH {-O1}]
  733. set cgtcl [opt-val with-tclsh jimsh]
  734. if {"jimsh" ne $cgtcl} {
  735. # When --with-tclsh=X is used, use that for all TCL purposes,
  736. # including in-tree code generation, per developer request.
  737. define BTCLSH "\$(TCLSH_CMD)"
  738. return $cgtcl
  739. }
  740. set flagsToRestore {CC CFLAGS AS_CFLAGS CPPFLAGS AS_CPPFLAGS LDFLAGS LINKFLAGS LIBS CROSS}
  741. define-push $flagsToRestore {
  742. # We have to swap CC to CC_FOR_BUILD for purposes of the various
  743. # [cc-...] tests below. Recall that --with-wasi-sdk may have
  744. # swapped out CC with one which is not appropriate for this block.
  745. # Per consulation with autosetup's creator, doing this properly
  746. # requires us to [define-push] the whole $flagsToRestore list
  747. # (plus a few others which are not relevant in this tree).
  748. #
  749. # These will get set to their previous values at the end of this
  750. # block.
  751. foreach flag $flagsToRestore {define $flag ""}
  752. define CC [get-define CC_FOR_BUILD]
  753. # These headers are technically optional for JimTCL but necessary if
  754. # we want to use it for code generation:
  755. set sysh [cc-check-includes dirent.h sys/time.h]
  756. # jimsh0.c hard-codes #define's for HAVE_DIRENT_H and
  757. # HAVE_SYS_TIME_H on the platforms it supports, so we do not
  758. # need to add -D... flags for those. We check for them here only
  759. # so that we can avoid the situation that we later, at
  760. # make-time, try to compile jimsh but it then fails due to
  761. # missing headers (i.e. fail earlier rather than later).
  762. if {$sysh && [cc-check-functions realpath]} {
  763. define-append CFLAGS_JIMSH -DHAVE_REALPATH
  764. define BTCLSH "\$(JIMSH)"
  765. set ::useJimForCodeGen 1
  766. } elseif {$sysh && [cc-check-functions _fullpath]} {
  767. # _fullpath() is a Windows API. It's not entirely clear
  768. # whether we need to add {-DHAVE_SYS_TIME_H -DHAVE_DIRENT_H}
  769. # to CFLAGS_JIMSH in this case. On MinGW32 we definitely do
  770. # not want to because it already hard-codes them. On _MSC_VER
  771. # builds it does not.
  772. define-append CFLAGS_JIMSH -DHAVE__FULLPATH
  773. define BTCLSH "\$(JIMSH)"
  774. set ::useJimForCodeGen 1
  775. } elseif {[file-isexec [get-define TCLSH_CMD]]} {
  776. set cgtcl [get-define TCLSH_CMD]
  777. define BTCLSH "\$(TCLSH_CMD)"
  778. } else {
  779. # One last-ditch effort to find TCLSH_CMD: use info from
  780. # tclConfig.sh to try to find a tclsh
  781. if {"" eq [get-define TCLSH_CMD]} {
  782. set tpre [get-define TCL_EXEC_PREFIX]
  783. if {"" ne $tpre} {
  784. set tv [get-define TCL_VERSION]
  785. if {[file-isexec "${tpre}/bin/tclsh${tv}"]} {
  786. define TCLSH_CMD "${tpre}/bin/tclsh${tv}"
  787. } elseif {[file-isexec "${tpre}/bin/tclsh"]} {
  788. define TCLSH_CMD "${tpre}/bin/tclsh"
  789. }
  790. }
  791. }
  792. set cgtcl [get-define TCLSH_CMD]
  793. if {![file-isexec $cgtcl]} {
  794. proj-fatal "Cannot find a tclsh to use for code generation."
  795. }
  796. define BTCLSH "\$(TCLSH_CMD)"
  797. }
  798. }; # CC swap-out
  799. return $cgtcl
  800. }; # sqlite-determine-codegen-tcl
  801. msg-result "TCL for code generation: [sqlite-determine-codegen-tcl]"
  802. # /TCL
  803. ########################################################################
  804. ########################################################################
  805. # Thread safety?
  806. msg-checking "Support threadsafe operation? "
  807. proj-if-opt-truthy threadsafe {
  808. msg-result yes
  809. sqlite-add-feature-flag -DSQLITE_THREADSAFE=1
  810. if {![proj-check-function-in-lib pthread_create pthread]
  811. || ![proj-check-function-in-lib pthread_mutexattr_init pthread]} {
  812. user-error "Missing required pthread bits"
  813. }
  814. define LDFLAGS_PTHREAD [get-define lib_pthread_create]
  815. undefine lib_pthread_create
  816. # Recall that LDFLAGS_PTHREAD might be empty even if pthreads if
  817. # found because it's in -lc on some platforms.
  818. } {
  819. msg-result no
  820. sqlite-add-feature-flag -DSQLITE_THREADSAFE=0
  821. define LDFLAGS_PTHREAD ""
  822. }
  823. ########################################################################
  824. # Do we want temporary databases in memory?
  825. #
  826. # The test fixture likes to set SQLITE_TEMP_STORE on its own, so do
  827. # not set that feature flag unless it was explicitly provided to the
  828. # configure script.
  829. if {[proj-opt-was-provided with-tempstore]} {
  830. apply {{} {
  831. set ts [opt-val with-tempstore no]
  832. set tsn 1
  833. msg-checking "Use an in-RAM database for temporary tables? "
  834. switch -exact -- $ts {
  835. never { set tsn 0 }
  836. no { set tsn 1 }
  837. yes { set tsn 2 }
  838. always { set tsn 3 }
  839. default {
  840. user-error "Invalid --with-tempstore value '$ts'. Use one of: never, no, yes, always"
  841. }
  842. }
  843. msg-result $ts
  844. sqlite-add-feature-flag -DSQLITE_TEMP_STORE=$tsn
  845. }}
  846. }
  847. ########################################################################
  848. # sqlite-check-line-editing jumps through proverbial hoops to try to
  849. # find a working line-editing library, setting:
  850. #
  851. # - HAVE_READLINE to 0 or 1
  852. # - HAVE_LINENOISE to 0, 1, or 2
  853. # - HAVE_EDITLINE to 0 or 1
  854. #
  855. # Only one of ^^^ those will be set to non-0.
  856. #
  857. # - LDFLAGS_READLINE = linker flags or empty string
  858. #
  859. # - CFLAGS_READLINE = compilation flags for clients or empty string.
  860. #
  861. # Note that LDFLAGS_READLINE and CFLAGS_READLINE may refer to
  862. # linenoise or editline, not necessarily libreadline. In some cases
  863. # it will set HAVE_READLINE=1 when it's really using editline, for
  864. # reasons described in this function's comments.
  865. #
  866. # Returns a string describing which line-editing approach to use, or
  867. # "none" if no option is available.
  868. #
  869. # Order of checks:
  870. #
  871. # 1) --with-linenoise trumps all others and skips all of the
  872. # complexities involved with the remaining options.
  873. #
  874. # 2) --editline trumps --readline
  875. #
  876. # 3) --disable-readline trumps --readline
  877. #
  878. # 4) Default to automatic search for optional readline
  879. #
  880. # 5) Try to find readline or editline. If it's not found AND the
  881. # corresponding --FEATURE flag was explicitly given, fail fatally,
  882. # else fail silently.
  883. proc sqlite-check-line-editing {} {
  884. rename sqlite-check-line-editing ""
  885. msg-result "Checking for line-editing capability..."
  886. define HAVE_READLINE 0
  887. define HAVE_LINENOISE 0
  888. define HAVE_EDITLINE 0
  889. define LDFLAGS_READLINE ""
  890. define CFLAGS_READLINE ""
  891. set failIfNotFound 0 ; # Gets set to 1 for explicit --FEATURE requests
  892. # so that we know whether to fail fatally or not
  893. # if the library is not found.
  894. set libsForReadline {readline edit} ; # -l<LIB> names to check for readline().
  895. # The libedit check changes this.
  896. set editLibName "readline" ; # "readline" or "editline"
  897. set editLibDef "HAVE_READLINE" ; # "HAVE_READLINE" or "HAVE_EDITLINE"
  898. set dirLn [opt-val with-linenoise]
  899. if {"" ne $dirLn} {
  900. # Use linenoise from a copy of its sources (not a library)...
  901. if {![file isdir $dirLn]} {
  902. proj-fatal "--with-linenoise value is not a directory"
  903. }
  904. set lnH $dirLn/linenoise.h
  905. if {![file exists $lnH] } {
  906. proj-fatal "Cannot find linenoise.h in $dirLn"
  907. }
  908. set lnC ""
  909. set lnCOpts {linenoise-ship.c linenoise.c}
  910. foreach f $lnCOpts {
  911. if {[file exists $dirLn/$f]} {
  912. set lnC $dirLn/$f
  913. break;
  914. }
  915. }
  916. if {"" eq $lnC} {
  917. proj-fatal "Cannot find any of $lnCOpts in $dirLn"
  918. }
  919. set flavor ""
  920. set lnVal [proj-which-linenoise $lnH]
  921. switch -- $lnVal {
  922. 1 { set flavor "antirez" }
  923. 2 { set flavor "msteveb" }
  924. default {
  925. proj-fatal "Cannot determine the flavor of linenoise from $lnH"
  926. }
  927. }
  928. define CFLAGS_READLINE "-I$dirLn $lnC"
  929. define HAVE_LINENOISE $lnVal
  930. sqlite-add-shell-opt -DHAVE_LINENOISE=$lnVal
  931. if {$::useJimForCodeGen && 2 == $lnVal} {
  932. define-append CFLAGS_JIMSH -DUSE_LINENOISE [get-define CFLAGS_READLINE]
  933. user-notice "Adding linenoise support to jimsh."
  934. }
  935. return "linenoise ($flavor)"
  936. } elseif {[opt-bool editline]} {
  937. # libedit mimics libreadline and on some systems does not have its
  938. # own header installed (instead, that of libreadline is used).
  939. #
  940. # shell.c historically expects HAVE_EDITLINE to be set for
  941. # libedit, but it then expects to see <editline/readline.h>, which
  942. # some system's don't actually have despite having libedit. If we
  943. # end up finding <editline/readline.h> below, we will use
  944. # -DHAVE_EDITLINE=1, else we will use -DHAVE_READLINE=1. In either
  945. # case, we will link against libedit.
  946. set failIfNotFound 1
  947. set libsForReadline {edit}
  948. set editLibName editline
  949. } elseif {![opt-bool readline]} {
  950. msg-result "Readline support explicitly disabled with --disable-readline"
  951. return "none"
  952. } elseif {[proj-opt-was-provided readline]} {
  953. # If an explicit --[enable-]readline was used, fail if it's not
  954. # found, else treat the feature as optional.
  955. set failIfNotFound 1
  956. }
  957. # Transform with-readline-header=X to with-readline-cflags=-I...
  958. set v [opt-val with-readline-header]
  959. proj-opt-set with-readline-header ""
  960. if {"" ne $v} {
  961. if {"auto" eq $v} {
  962. proj-opt-set with-readline-cflags auto
  963. } else {
  964. set v [file dirname $v]
  965. if {[string match */readline $v]} {
  966. # Special case: if the path includes .../readline/readline.h,
  967. # set the -I to one dir up from that because our sources
  968. # #include <readline/readline.h> or <editline/readline.h>.
  969. set v [file dirname $v]
  970. }
  971. proj-opt-set with-readline-cflags "-I$v"
  972. }
  973. }
  974. # Look for readline.h
  975. set rlInc [opt-val with-readline-cflags auto]
  976. if {"auto" eq $rlInc} {
  977. set rlInc ""
  978. if {$::isCrossCompiling} {
  979. # ^^^ this check is derived from the legacy configure script.
  980. proj-warn "Skipping check for readline.h because we're cross-compiling."
  981. } else {
  982. set dirs "[get-define prefix] /usr /usr/local /usr/local/readline /usr/contrib /mingw"
  983. set subdirs "include/$editLibName"
  984. if {"editline" eq $editLibName} {
  985. lappend subdirs include/readline
  986. # ^^^ editline, on some systems, does not have its own header,
  987. # and uses libreadline's header.
  988. }
  989. lappend subdirs include
  990. # ^^^ The dirs and subdirs lists are, except for the inclusion
  991. # of $prefix and editline, from the legacy configure script
  992. set rlInc [proj-search-for-header-dir readline.h \
  993. -dirs $dirs -subdirs $subdirs]
  994. if {"" ne $rlInc} {
  995. if {[string match */readline $rlInc]} {
  996. set rlInc [file dirname $rlInc]; # shell #include's <readline/readline.h>
  997. } elseif {[string match */editline $rlInc]} {
  998. set editLibDef HAVE_EDITLINE
  999. set rlInc [file dirname $rlInc]; # shell #include's <editline/readline.h>
  1000. }
  1001. set rlInc "-I${rlInc}"
  1002. }
  1003. }
  1004. } elseif {"" ne $rlInc && ![string match *-I* $rlInc]} {
  1005. proj-fatal "Argument to --with-readline-cflags is intended to be CFLAGS and contain -I..."
  1006. }
  1007. # If readline.h was found/specified, look for lib(readline|edit)...
  1008. #
  1009. # This is not quite straightforward because both libreadline and
  1010. # libedit typically require some other library which (according to
  1011. # legacy autotools-generated tests) provides tgetent(3). On some
  1012. # systems that's built into libreadline/edit, on some (most?) its in
  1013. # lib[n]curses, and on some it's in libtermcap.
  1014. set rlLib ""
  1015. if {"" ne $rlInc} {
  1016. set rlLib [opt-val with-readline-ldflags]
  1017. if {"" eq $rlLib || "auto" eq $rlLib} {
  1018. set rlLib ""
  1019. set libTerm ""
  1020. if {[proj-check-function-in-lib tgetent "$editLibName ncurses curses termcap"]} {
  1021. # ^^^ that libs list comes from the legacy configure script ^^^
  1022. set libTerm [get-define lib_tgetent]
  1023. undefine lib_tgetent
  1024. }
  1025. if {$editLibName eq $libTerm} {
  1026. set rlLib $libTerm
  1027. } elseif {[proj-check-function-in-lib readline $libsForReadline $libTerm]} {
  1028. set rlLib [get-define lib_readline]
  1029. lappend rlLib $libTerm
  1030. undefine lib_readline
  1031. }
  1032. }
  1033. }
  1034. # If we found a library, configure the build to use it...
  1035. if {"" ne $rlLib} {
  1036. if {"editline" eq $editLibName && "HAVE_READLINE" eq $editLibDef} {
  1037. # Alert the user that, despite outward appearances, we won't be
  1038. # linking to the GPL'd libreadline. Presumably that distinction is
  1039. # significant for those using --editline.
  1040. proj-indented-notice {
  1041. NOTE: the local libedit but uses <readline/readline.h> so we
  1042. will compile with -DHAVE_READLINE=1 but will link with
  1043. libedit.
  1044. }
  1045. }
  1046. set rlLib [join $rlLib]
  1047. set rlInc [join $rlInc]
  1048. define LDFLAGS_READLINE $rlLib
  1049. define CFLAGS_READLINE $rlInc
  1050. proj-assert {$editLibDef in {HAVE_READLINE HAVE_EDITLINE}}
  1051. proj-assert {$editLibName in {readline editline}}
  1052. sqlite-add-shell-opt -D${editLibDef}=1
  1053. msg-result "Using $editLibName flags: $rlInc $rlLib"
  1054. # Check whether rl_completion_matches() has a signature we can use
  1055. # and disable that sub-feature if it doesn't.
  1056. if {![cctest \
  1057. -cflags "$rlInc -D${editLibDef}" -libs $rlLib -nooutput 1 -source {
  1058. #include <stdio.h>
  1059. #ifdef HAVE_EDITLINE
  1060. #include <editline/readline.h>
  1061. #else
  1062. #include <readline/readline.h>
  1063. #endif
  1064. static char * rcg(const char *z, int i){(void)z; (void)i; return 0;}
  1065. int main(void) {
  1066. char ** x = rl_completion_matches("one", rcg);
  1067. (void)x;
  1068. return 0;
  1069. }
  1070. }]} {
  1071. proj-warn "readline-style completion disabled due to rl_completion_matches() signature mismatch"
  1072. sqlite-add-shell-opt -DSQLITE_OMIT_READLINE_COMPLETION
  1073. }
  1074. return $editLibName
  1075. }
  1076. if {$failIfNotFound} {
  1077. proj-fatal "Explicit --$editLibName failed to find a matching library."
  1078. }
  1079. return "none"
  1080. }; # sqlite-check-line-editing
  1081. msg-result "Line-editing support for the sqlite3 shell: [sqlite-check-line-editing]"
  1082. proj-if-opt-truthy load-extension {
  1083. if {[proj-check-function-in-lib dlopen dl]} {
  1084. define LDFLAGS_DLOPEN [get-define lib_dlopen]
  1085. undefine lib_dlopen
  1086. } else {
  1087. user-error "dlopen() not found. Use --disable-load-extension to bypass this check."
  1088. }
  1089. } {
  1090. define LDFLAGS_DLOPEN ""
  1091. sqlite-add-feature-flag {-DSQLITE_OMIT_LOAD_EXTENSION=1}
  1092. msg-result "Disabling loadable extensions."
  1093. }
  1094. proj-if-opt-truthy math {
  1095. if {![proj-check-function-in-lib ceil m]} {
  1096. user-error "Cannot find libm functions. Use --disable-math to bypass this."
  1097. }
  1098. define LDFLAGS_MATH [get-define lib_ceil]
  1099. undefine lib_ceil
  1100. sqlite-add-feature-flag {-DSQLITE_ENABLE_MATH_FUNCTIONS}
  1101. msg-result "Enabling math SQL functions [get-define LDFLAGS_MATH]"
  1102. } {
  1103. define LDFLAGS_MATH ""
  1104. msg-result "Disabling math SQL functions"
  1105. }
  1106. ########################################################################
  1107. # ICU - International Components for Unicode
  1108. #
  1109. # Handles these flags:
  1110. #
  1111. # --with-icu-ldflags=LDFLAGS
  1112. # --with-icu-cflags=CFLAGS
  1113. # --with-icu-config[=auto | pkg-config | /path/to/icu-config]
  1114. # --enable-icu-collations
  1115. #
  1116. # --with-icu-config values:
  1117. #
  1118. # - auto: use the first one of (pkg-config, icu-config) found on the
  1119. # system.
  1120. # - pkg-config: use only pkg-config to determine flags
  1121. # - /path/to/icu-config: use that to determine flags
  1122. #
  1123. # If --with-icu-config is used as neither pkg-config nor icu-config
  1124. # are found, fail fatally.
  1125. #
  1126. # If both --with-icu-ldflags and --with-icu-config are provided, they
  1127. # are cumulative. If neither are provided, icu-collations is not
  1128. # honored and a warning is emitted if it is provided.
  1129. #
  1130. # Design note: though we could automatically enable ICU if the
  1131. # icu-config binary or (pkg-config icu-io) are found, we specifically
  1132. # do not. ICU is always an opt-in feature.
  1133. proc sqlite-check-icu {} {
  1134. rename sqlite-check-icu ""
  1135. define LDFLAGS_ICU [join [opt-val with-icu-ldflags ""]]
  1136. define CFLAGS_ICU [join [opt-val with-icu-cflags ""]]
  1137. if {[proj-opt-was-provided with-icu-config]} {
  1138. set icuConfigBin [opt-val with-icu-config]
  1139. set tryIcuConfigBin 1; # set to 0 if we end up using pkg-config
  1140. if {"auto" eq $icuConfigBin || "pkg-config" eq $icuConfigBin} {
  1141. if {[pkg-config-init 0] && [pkg-config icu-io]} {
  1142. # Maintenance reminder: historical docs say to use both of
  1143. # (icu-io, icu-uc). icu-uc lacks a required lib and icu-io has
  1144. # all of them on tested OSes.
  1145. set tryIcuConfigBin 0
  1146. define LDFLAGS_ICU [get-define PKG_ICU_IO_LDFLAGS]
  1147. define-append LDFLAGS_ICU [get-define PKG_ICU_IO_LIBS]
  1148. define CFLAGS_ICU [get-define PKG_ICU_IO_CFLAGS]
  1149. } elseif {"pkg-config" eq $icuConfigBin} {
  1150. proj-fatal "pkg-config cannot find package icu-io"
  1151. } else {
  1152. proj-assert {"auto" eq $icuConfigBin}
  1153. }
  1154. }
  1155. if {$tryIcuConfigBin} {
  1156. if {"auto" eq $icuConfigBin} {
  1157. set icuConfigBin [proj-first-bin-of \
  1158. /usr/local/bin/icu-config \
  1159. /usr/bin/icu-config]
  1160. if {"" eq $icuConfigBin} {
  1161. proj-fatal "--with-icu-config=auto cannot find (pkg-config icu-io) or icu-config binary"
  1162. }
  1163. }
  1164. if {[file-isexec $icuConfigBin]} {
  1165. set x [exec $icuConfigBin --ldflags]
  1166. if {"" eq $x} {
  1167. proj-fatal "$icuConfigBin --ldflags returned no data"
  1168. }
  1169. define-append LDFLAGS_ICU $x
  1170. set x [exec $icuConfigBin --cppflags]
  1171. define-append CFLAGS_ICU $x
  1172. } else {
  1173. proj-fatal "--with-icu-config=$bin does not refer to an executable"
  1174. }
  1175. }
  1176. }
  1177. set ldflags [define LDFLAGS_ICU [string trim [get-define LDFLAGS_ICU]]]
  1178. set cflags [define CFLAGS_ICU [string trim [get-define CFLAGS_ICU]]]
  1179. if {"" ne $ldflags} {
  1180. sqlite-add-feature-flag -shell -DSQLITE_ENABLE_ICU
  1181. msg-result "Enabling ICU support with flags: $ldflags $cflags"
  1182. if {[opt-bool icu-collations]} {
  1183. msg-result "Enabling ICU collations."
  1184. sqlite-add-feature-flag -shell -DSQLITE_ENABLE_ICU_COLLATIONS
  1185. # Recall that shell.c builds with sqlite3.c
  1186. }
  1187. } elseif {[opt-bool icu-collations]} {
  1188. proj-warn "ignoring --enable-icu-collations because neither --with-icu-ldflags nor --with-icu-config provided any linker flags"
  1189. } else {
  1190. msg-result "ICU support is disabled."
  1191. }
  1192. }; # sqlite-check-icu
  1193. sqlite-check-icu
  1194. ########################################################################
  1195. # Check for the Emscripten SDK for building the web-based wasm
  1196. # components. The core lib and tools do not require this but ext/wasm
  1197. # does.
  1198. apply {{} {
  1199. if {$::autosetup(srcdir) ne $::autosetup(builddir)} {
  1200. # The EMSDK pieces require writing to the original source tree
  1201. # even when doing an out-of-tree build. The ext/wasm pieces do not
  1202. # support an out-of-tree build so we catch that case and treat it
  1203. # as if EMSDK were not found.
  1204. msg-result "Out-of tree build: not checking for EMSDK."
  1205. define EMCC_WRAPPER ""
  1206. return
  1207. }
  1208. set emccsh $::srcdir/tool/emcc.sh
  1209. if {![get-define HAVE_WASI_SDK] && [proj-check-emsdk]} {
  1210. define EMCC_WRAPPER $emccsh
  1211. proj-make-from-dot-in $emccsh
  1212. catch {exec chmod u+x $emccsh}
  1213. } else {
  1214. define EMCC_WRAPPER ""
  1215. file delete -force $emccsh
  1216. }
  1217. }}
  1218. ########################################################################
  1219. # Check for log(3) in libm and die with an error if it is not
  1220. # found. $featureName should be the feature name which requires that
  1221. # function (it's used only in error messages). defines LDFLAGS_MATH to
  1222. # the required linker flags (which may be empty even if the math APIs
  1223. # are found, depending on the OS).
  1224. proc affirm-have-math {featureName} {
  1225. if {"" eq [get-define LDFLAGS_MATH ""]} {
  1226. if {![msg-quiet proj-check-function-in-lib log m]} {
  1227. user-error "Missing math APIs for $featureName"
  1228. }
  1229. define LDFLAGS_MATH [get-define lib_log ""]
  1230. undefine lib_log
  1231. }
  1232. }
  1233. ########################################################################
  1234. # Handle various SQLITE_ENABLE_... feature flags.
  1235. msg-result "Feature flags..."
  1236. foreach {boolFlag featureFlag ifSetEvalThis} {
  1237. all {} {
  1238. # The 'all' option must be first in this list.
  1239. proj-opt-set fts4
  1240. proj-opt-set fts5
  1241. proj-opt-set geopoly
  1242. proj-opt-set rtree
  1243. proj-opt-set session
  1244. }
  1245. fts4 -DSQLITE_ENABLE_FTS4 {affirm-have-math fts4}
  1246. fts5 -DSQLITE_ENABLE_FTS5 {affirm-have-math fts5}
  1247. geopoly -DSQLITE_ENABLE_GEOPOLY {proj-opt-set rtree}
  1248. rtree -DSQLITE_ENABLE_RTREE {}
  1249. session {-DSQLITE_ENABLE_SESSION -DSQLITE_ENABLE_PREUPDATE_HOOK} {}
  1250. update-limit -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT {}
  1251. memsys5 -DSQLITE_ENABLE_MEMSYS5 {}
  1252. memsys3 {} {
  1253. if {[opt-bool memsys5]} {
  1254. proj-warn "not enabling memsys3 because memsys5 is enabled."
  1255. expr 0
  1256. } else {
  1257. sqlite-add-feature-flag -DSQLITE_ENABLE_MEMSYS3
  1258. }
  1259. }
  1260. scanstatus -DSQLITE_ENABLE_STMT_SCANSTATUS {}
  1261. } {
  1262. proj-if-opt-truthy $boolFlag {
  1263. sqlite-add-feature-flag $featureFlag
  1264. if {0 != [eval $ifSetEvalThis] && "all" ne $boolFlag} {
  1265. msg-result " + $boolFlag"
  1266. }
  1267. } {
  1268. if {"all" ne $boolFlag} {
  1269. msg-result " - $boolFlag"
  1270. }
  1271. }
  1272. }
  1273. ########################################################################
  1274. # Invert the above loop's logic for some SQLITE_OMIT_... cases. If
  1275. # config option $boolFlag is false, [sqlite-add-feature-flag
  1276. # $featureFlag], where $featureFlag is intended to be
  1277. # -DSQLITE_OMIT_...
  1278. foreach {boolFlag featureFlag} {
  1279. json -DSQLITE_OMIT_JSON
  1280. } {
  1281. if {[proj-opt-truthy $boolFlag]} {
  1282. msg-result " + $boolFlag"
  1283. } else {
  1284. sqlite-add-feature-flag $featureFlag
  1285. msg-result " - $boolFlag"
  1286. }
  1287. }
  1288. #########################################################################
  1289. # Show the final feature flag sets:
  1290. apply {{} {
  1291. set oFF [get-define OPT_FEATURE_FLAGS]
  1292. if {"" ne $oFF} {
  1293. define OPT_FEATURE_FLAGS [lsort -unique $oFF]
  1294. msg-result "Library feature flags: [get-define OPT_FEATURE_FLAGS]"
  1295. }
  1296. set oFF [get-define OPT_SHELL]
  1297. if {"" ne $oFF} {
  1298. define OPT_SHELL [lsort -unique $oFF]
  1299. msg-result "Shell options: [get-define OPT_SHELL]"
  1300. }
  1301. unset oFF
  1302. }}
  1303. ########################################################################
  1304. # "Re-export" the autoconf-conventional --XYZdir flags into something
  1305. # which is more easily overridable from a make invocation. See the docs
  1306. # for [proj-remap-autoconf-dir-vars] for the explanation of why.
  1307. #
  1308. # We do this late in the config process, immediately before we export
  1309. # the Makefile and other generated files, so that configure tests
  1310. # which make make use of the autotools-conventional flags
  1311. # (e.g. [proj-check-rpath]) may do so before we "mangle" them here.
  1312. proj-remap-autoconf-dir-vars
  1313. ########################################################################
  1314. # Generate the output files.
  1315. #
  1316. # Potential TODO (unclear): in sqlite3.pc.in, do we need to include
  1317. # any CFLAGS_READLINE, CFLAGS_ZLIB, etc in its "Cflags:" section?
  1318. proj-make-from-dot-in -touch Makefile sqlite3.pc
  1319. make-config-header sqlite_cfg.h \
  1320. -bare {SIZEOF_* HAVE_DECL_*} \
  1321. -none {HAVE_CFLAG_* LDFLAGS_* SH_* SQLITE_AUTORECONFIG
  1322. TARGET_* USE_GCOV TCL_*} \
  1323. -auto {HAVE_* PACKAGE_*} \
  1324. -none *
  1325. proj-touch sqlite_cfg.h ; # help avoid frequent unnecessary @SQLITE_AUTORECONFIG@
  1326. ########################################################################
  1327. # Some build-dev/debug-only output
  1328. proj-if-opt-truthy dump-defines {
  1329. make-config-header $::DUMP_DEFINES_TXT \
  1330. -bare {SQLITE_OS* SQLITE_DEBUG USE_*} \
  1331. -str {BIN_* CC LD AR LDFLAG* OPT_*} \
  1332. -auto {*}
  1333. # achtung: ^^^^ whichever SQLITE_OS_foo flag which is set to 0 will
  1334. # get _undefined_ here unless it's part of the -bare set.
  1335. if {"" ne $DUMP_DEFINES_JSON} {
  1336. msg-result "--dump-defines is creating $::DUMP_DEFINES_JSON"
  1337. ########################################################################
  1338. # Dump config-defines.json...
  1339. # Demonstrate (mis?)handling of spaces in JSON-export array values:
  1340. # define-append OPT_FOO.list {"-DFOO=bar baz" -DBAR="baz barre"}
  1341. define OPT_FEATURE_FLAGS.list [get-define OPT_FEATURE_FLAGS]
  1342. define OPT_SHELL.list [get-define OPT_SHELL]
  1343. set dumpDefsOpt {
  1344. -bare {SIZEOF_* HAVE_DECL_*}
  1345. -none {HAVE_CFLAG_* LDFLAGS_* SH_* SQLITE_AUTORECONFIG TARGET_* USE_GCOV TCL_*}
  1346. -array {*.list}
  1347. -auto {OPT_* PACKAGE_* HAVE_*}
  1348. }
  1349. if {[opt-bool defines-json-include-lowercase]} {
  1350. lappend dumpDefsOpt -none {lib_*} ; # remnants from proj-check-function-in-lib and friends
  1351. lappend dumpDefsOpt -auto {[a-z]*}
  1352. }
  1353. lappend dumpDefsOpt -none *
  1354. proj-dump-defs-json $DUMP_DEFINES_JSON {*}$dumpDefsOpt
  1355. undefine OPT_FEATURE_FLAGS.list
  1356. undefine OPT_SHELL.list
  1357. }
  1358. }
  1359. ########################################################################
  1360. # Perform some high-level validation on the generated files...
  1361. #
  1362. # 1) Ensure that no unresolved @VAR@ placeholders are in files which
  1363. # use those.
  1364. #
  1365. # 2) TBD
  1366. apply {{} {
  1367. # Check #1: ensure that files which get filtered for @VAR@ do not
  1368. # contain any unresolved @VAR@ refs. That may indicate an
  1369. # unexported/unused var or a typo.
  1370. foreach f "Makefile sqlite3.pc $::srcdir/tool/emcc.sh" {
  1371. if {![file exists $f]} continue
  1372. set lnno 1
  1373. foreach line [proj-file-content-list $f] {
  1374. if {[regexp {(@[A-Za-z_]+@)} $line match]} {
  1375. error "Unresolved reference to $match at line $lnno of $f"
  1376. }
  1377. incr lnno
  1378. }
  1379. }
  1380. }}