auto.def 52 KB

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