auto.def 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  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. apply {{} {
  827. set ts [opt-val with-tempstore no]
  828. set tsn 1
  829. msg-checking "Use an in-RAM database for temporary tables? "
  830. switch -exact -- $ts {
  831. never { set tsn 0 }
  832. no { set tsn 1 }
  833. yes { set tsn 2 }
  834. always { set tsn 3 }
  835. default {
  836. user-error "Invalid --with-tempstore value '$ts'. Use one of: never, no, yes, always"
  837. }
  838. }
  839. msg-result $ts
  840. sqlite-add-feature-flag -DSQLITE_TEMP_STORE=$tsn
  841. }}
  842. ########################################################################
  843. # sqlite-check-line-editing jumps through proverbial hoops to try to
  844. # find a working line-editing library, setting:
  845. #
  846. # - HAVE_READLINE to 0 or 1
  847. # - HAVE_LINENOISE to 0, 1, or 2
  848. # - HAVE_EDITLINE to 0 or 1
  849. #
  850. # Only one of ^^^ those will be set to non-0.
  851. #
  852. # - LDFLAGS_READLINE = linker flags or empty string
  853. #
  854. # - CFLAGS_READLINE = compilation flags for clients or empty string.
  855. #
  856. # Note that LDFLAGS_READLINE and CFLAGS_READLINE may refer to
  857. # linenoise or editline, not necessarily libreadline. In some cases
  858. # it will set HAVE_READLINE=1 when it's really using editline, for
  859. # reasons described in this function's comments.
  860. #
  861. # Returns a string describing which line-editing approach to use, or
  862. # "none" if no option is available.
  863. #
  864. # Order of checks:
  865. #
  866. # 1) --with-linenoise trumps all others and skips all of the
  867. # complexities involved with the remaining options.
  868. #
  869. # 2) --editline trumps --readline
  870. #
  871. # 3) --disable-readline trumps --readline
  872. #
  873. # 4) Default to automatic search for optional readline
  874. #
  875. # 5) Try to find readline or editline. If it's not found AND the
  876. # corresponding --FEATURE flag was explicitly given, fail fatally,
  877. # else fail silently.
  878. proc sqlite-check-line-editing {} {
  879. rename sqlite-check-line-editing ""
  880. msg-result "Checking for line-editing capability..."
  881. define HAVE_READLINE 0
  882. define HAVE_LINENOISE 0
  883. define HAVE_EDITLINE 0
  884. define LDFLAGS_READLINE ""
  885. define CFLAGS_READLINE ""
  886. set failIfNotFound 0 ; # Gets set to 1 for explicit --FEATURE requests
  887. # so that we know whether to fail fatally or not
  888. # if the library is not found.
  889. set libsForReadline {readline edit} ; # -l<LIB> names to check for readline().
  890. # The libedit check changes this.
  891. set editLibName "readline" ; # "readline" or "editline"
  892. set editLibDef "HAVE_READLINE" ; # "HAVE_READLINE" or "HAVE_EDITLINE"
  893. set dirLn [opt-val with-linenoise]
  894. if {"" ne $dirLn} {
  895. # Use linenoise from a copy of its sources (not a library)...
  896. if {![file isdir $dirLn]} {
  897. proj-fatal "--with-linenoise value is not a directory"
  898. }
  899. set lnH $dirLn/linenoise.h
  900. if {![file exists $lnH] } {
  901. proj-fatal "Cannot find linenoise.h in $dirLn"
  902. }
  903. set lnC ""
  904. set lnCOpts {linenoise-ship.c linenoise.c}
  905. foreach f $lnCOpts {
  906. if {[file exists $dirLn/$f]} {
  907. set lnC $dirLn/$f
  908. break;
  909. }
  910. }
  911. if {"" eq $lnC} {
  912. proj-fatal "Cannot find any of $lnCOpts in $dirLn"
  913. }
  914. set flavor ""
  915. set lnVal [proj-which-linenoise $lnH]
  916. switch -- $lnVal {
  917. 1 { set flavor "antirez" }
  918. 2 { set flavor "msteveb" }
  919. default {
  920. proj-fatal "Cannot determine the flavor of linenoise from $lnH"
  921. }
  922. }
  923. define CFLAGS_READLINE "-I$dirLn $lnC"
  924. define HAVE_LINENOISE $lnVal
  925. sqlite-add-shell-opt -DHAVE_LINENOISE=$lnVal
  926. if {$::useJimForCodeGen && 2 == $lnVal} {
  927. define-append CFLAGS_JIMSH -DUSE_LINENOISE [get-define CFLAGS_READLINE]
  928. user-notice "Adding linenoise support to jimsh."
  929. }
  930. return "linenoise ($flavor)"
  931. } elseif {[opt-bool editline]} {
  932. # libedit mimics libreadline and on some systems does not have its
  933. # own header installed (instead, that of libreadline is used).
  934. #
  935. # shell.c historically expects HAVE_EDITLINE to be set for
  936. # libedit, but it then expects to see <editline/readline.h>, which
  937. # some system's don't actually have despite having libedit. If we
  938. # end up finding <editline/readline.h> below, we will use
  939. # -DHAVE_EDITLINE=1, else we will use -DHAVE_READLINE=1. In either
  940. # case, we will link against libedit.
  941. set failIfNotFound 1
  942. set libsForReadline {edit}
  943. set editLibName editline
  944. } elseif {![opt-bool readline]} {
  945. msg-result "Readline support explicitly disabled with --disable-readline"
  946. return "none"
  947. } elseif {[proj-opt-was-provided readline]} {
  948. # If an explicit --[enable-]readline was used, fail if it's not
  949. # found, else treat the feature as optional.
  950. set failIfNotFound 1
  951. }
  952. # Transform with-readline-header=X to with-readline-cflags=-I...
  953. set v [opt-val with-readline-header]
  954. proj-opt-set with-readline-header ""
  955. if {"" ne $v} {
  956. if {"auto" eq $v} {
  957. proj-opt-set with-readline-cflags auto
  958. } else {
  959. set v [file dirname $v]
  960. if {[string match */readline $v]} {
  961. # Special case: if the path includes .../readline/readline.h,
  962. # set the -I to one dir up from that because our sources
  963. # #include <readline/readline.h> or <editline/readline.h>.
  964. set v [file dirname $v]
  965. }
  966. proj-opt-set with-readline-cflags "-I$v"
  967. }
  968. }
  969. # Look for readline.h
  970. set rlInc [opt-val with-readline-cflags auto]
  971. if {"auto" eq $rlInc} {
  972. set rlInc ""
  973. if {$::isCrossCompiling} {
  974. # ^^^ this check is derived from the legacy configure script.
  975. proj-warn "Skipping check for readline.h because we're cross-compiling."
  976. } else {
  977. set dirs "[get-define prefix] /usr /usr/local /usr/local/readline /usr/contrib /mingw"
  978. set subdirs "include/$editLibName"
  979. if {"editline" eq $editLibName} {
  980. lappend subdirs include/readline
  981. # ^^^ editline, on some systems, does not have its own header,
  982. # and uses libreadline's header.
  983. }
  984. lappend subdirs include
  985. # ^^^ The dirs and subdirs lists are, except for the inclusion
  986. # of $prefix and editline, from the legacy configure script
  987. set rlInc [proj-search-for-header-dir readline.h \
  988. -dirs $dirs -subdirs $subdirs]
  989. if {"" ne $rlInc} {
  990. if {[string match */readline $rlInc]} {
  991. set rlInc [file dirname $rlInc]; # shell #include's <readline/readline.h>
  992. } elseif {[string match */editline $rlInc]} {
  993. set editLibDef HAVE_EDITLINE
  994. set rlInc [file dirname $rlInc]; # shell #include's <editline/readline.h>
  995. }
  996. set rlInc "-I${rlInc}"
  997. }
  998. }
  999. } elseif {"" ne $rlInc && ![string match *-I* $rlInc]} {
  1000. proj-fatal "Argument to --with-readline-cflags is intended to be CFLAGS and contain -I..."
  1001. }
  1002. # If readline.h was found/specified, look for lib(readline|edit)...
  1003. #
  1004. # This is not quite straightforward because both libreadline and
  1005. # libedit typically require some other library which (according to
  1006. # legacy autotools-generated tests) provides tgetent(3). On some
  1007. # systems that's built into libreadline/edit, on some (most?) its in
  1008. # lib[n]curses, and on some it's in libtermcap.
  1009. set rlLib ""
  1010. if {"" ne $rlInc} {
  1011. set rlLib [opt-val with-readline-ldflags]
  1012. if {"" eq $rlLib || "auto" eq $rlLib} {
  1013. set rlLib ""
  1014. set libTerm ""
  1015. if {[proj-check-function-in-lib tgetent "$editLibName ncurses curses termcap"]} {
  1016. # ^^^ that libs list comes from the legacy configure script ^^^
  1017. set libTerm [get-define lib_tgetent]
  1018. undefine lib_tgetent
  1019. }
  1020. if {$editLibName eq $libTerm} {
  1021. set rlLib $libTerm
  1022. } elseif {[proj-check-function-in-lib readline $libsForReadline $libTerm]} {
  1023. set rlLib [get-define lib_readline]
  1024. lappend rlLib $libTerm
  1025. undefine lib_readline
  1026. }
  1027. }
  1028. }
  1029. # If we found a library, configure the build to use it...
  1030. if {"" ne $rlLib} {
  1031. if {"editline" eq $editLibName && "HAVE_READLINE" eq $editLibDef} {
  1032. # Alert the user that, despite outward appearances, we won't be
  1033. # linking to the GPL'd libreadline. Presumably that distinction is
  1034. # significant for those using --editline.
  1035. proj-indented-notice {
  1036. NOTE: the local libedit but uses <readline/readline.h> so we
  1037. will compile with -DHAVE_READLINE=1 but will link with
  1038. libedit.
  1039. }
  1040. }
  1041. set rlLib [join $rlLib]
  1042. set rlInc [join $rlInc]
  1043. define LDFLAGS_READLINE $rlLib
  1044. define CFLAGS_READLINE $rlInc
  1045. proj-assert {$editLibDef in {HAVE_READLINE HAVE_EDITLINE}}
  1046. proj-assert {$editLibName in {readline editline}}
  1047. sqlite-add-shell-opt -D${editLibDef}=1
  1048. msg-result "Using $editLibName flags: $rlInc $rlLib"
  1049. # Check whether rl_completion_matches() has a signature we can use
  1050. # and disable that sub-feature if it doesn't.
  1051. if {![cctest \
  1052. -cflags "$rlInc -D${editLibDef}" -libs $rlLib -nooutput 1 -source {
  1053. #include <stdio.h>
  1054. #ifdef HAVE_EDITLINE
  1055. #include <editline/readline.h>
  1056. #else
  1057. #include <readline/readline.h>
  1058. #endif
  1059. static char * rcg(const char *z, int i){(void)z; (void)i; return 0;}
  1060. int main(void) {
  1061. char ** x = rl_completion_matches("one", rcg);
  1062. (void)x;
  1063. return 0;
  1064. }
  1065. }]} {
  1066. proj-warn "readline-style completion disabled due to rl_completion_matches() signature mismatch"
  1067. sqlite-add-shell-opt -DSQLITE_OMIT_READLINE_COMPLETION
  1068. }
  1069. return $editLibName
  1070. }
  1071. if {$failIfNotFound} {
  1072. proj-fatal "Explicit --$editLibName failed to find a matching library."
  1073. }
  1074. return "none"
  1075. }; # sqlite-check-line-editing
  1076. msg-result "Line-editing support for the sqlite3 shell: [sqlite-check-line-editing]"
  1077. proj-if-opt-truthy load-extension {
  1078. if {[proj-check-function-in-lib dlopen dl]} {
  1079. define LDFLAGS_DLOPEN [get-define lib_dlopen]
  1080. undefine lib_dlopen
  1081. } else {
  1082. user-error "dlopen() not found. Use --disable-load-extension to bypass this check."
  1083. }
  1084. } {
  1085. define LDFLAGS_DLOPEN ""
  1086. sqlite-add-feature-flag {-DSQLITE_OMIT_LOAD_EXTENSION=1}
  1087. msg-result "Disabling loadable extensions."
  1088. }
  1089. proj-if-opt-truthy math {
  1090. if {![proj-check-function-in-lib ceil m]} {
  1091. user-error "Cannot find libm functions. Use --disable-math to bypass this."
  1092. }
  1093. define LDFLAGS_MATH [get-define lib_ceil]
  1094. undefine lib_ceil
  1095. sqlite-add-feature-flag {-DSQLITE_ENABLE_MATH_FUNCTIONS}
  1096. msg-result "Enabling math SQL functions [get-define LDFLAGS_MATH]"
  1097. } {
  1098. define LDFLAGS_MATH ""
  1099. msg-result "Disabling math SQL functions"
  1100. }
  1101. ########################################################################
  1102. # ICU - International Components for Unicode
  1103. #
  1104. # Handles these flags:
  1105. #
  1106. # --with-icu-ldflags=LDFLAGS
  1107. # --with-icu-cflags=CFLAGS
  1108. # --with-icu-config[=auto | pkg-config | /path/to/icu-config]
  1109. # --enable-icu-collations
  1110. #
  1111. # --with-icu-config values:
  1112. #
  1113. # - auto: use the first one of (pkg-config, icu-config) found on the
  1114. # system.
  1115. # - pkg-config: use only pkg-config to determine flags
  1116. # - /path/to/icu-config: use that to determine flags
  1117. #
  1118. # If --with-icu-config is used as neither pkg-config nor icu-config
  1119. # are found, fail fatally.
  1120. #
  1121. # If both --with-icu-ldflags and --with-icu-config are provided, they
  1122. # are cumulative. If neither are provided, icu-collations is not
  1123. # honored and a warning is emitted if it is provided.
  1124. #
  1125. # Design note: though we could automatically enable ICU if the
  1126. # icu-config binary or (pkg-config icu-io) are found, we specifically
  1127. # do not. ICU is always an opt-in feature.
  1128. proc sqlite-check-icu {} {
  1129. rename sqlite-check-icu ""
  1130. define LDFLAGS_ICU [join [opt-val with-icu-ldflags ""]]
  1131. define CFLAGS_ICU [join [opt-val with-icu-cflags ""]]
  1132. if {[proj-opt-was-provided with-icu-config]} {
  1133. set icuConfigBin [opt-val with-icu-config]
  1134. set tryIcuConfigBin 1; # set to 0 if we end up using pkg-config
  1135. if {"auto" eq $icuConfigBin || "pkg-config" eq $icuConfigBin} {
  1136. if {[pkg-config-init 0] && [pkg-config icu-io]} {
  1137. # Maintenance reminder: historical docs say to use both of
  1138. # (icu-io, icu-uc). icu-uc lacks a required lib and icu-io has
  1139. # all of them on tested OSes.
  1140. set tryIcuConfigBin 0
  1141. define LDFLAGS_ICU [get-define PKG_ICU_IO_LDFLAGS]
  1142. define-append LDFLAGS_ICU [get-define PKG_ICU_IO_LIBS]
  1143. define CFLAGS_ICU [get-define PKG_ICU_IO_CFLAGS]
  1144. } elseif {"pkg-config" eq $icuConfigBin} {
  1145. proj-fatal "pkg-config cannot find package icu-io"
  1146. } else {
  1147. proj-assert {"auto" eq $icuConfigBin}
  1148. }
  1149. }
  1150. if {$tryIcuConfigBin} {
  1151. if {"auto" eq $icuConfigBin} {
  1152. set icuConfigBin [proj-first-bin-of \
  1153. /usr/local/bin/icu-config \
  1154. /usr/bin/icu-config]
  1155. if {"" eq $icuConfigBin} {
  1156. proj-fatal "--with-icu-config=auto cannot find (pkg-config icu-io) or icu-config binary"
  1157. }
  1158. }
  1159. if {[file-isexec $icuConfigBin]} {
  1160. set x [exec $icuConfigBin --ldflags]
  1161. if {"" eq $x} {
  1162. proj-fatal "$icuConfigBin --ldflags returned no data"
  1163. }
  1164. define-append LDFLAGS_ICU $x
  1165. set x [exec $icuConfigBin --cppflags]
  1166. define-append CFLAGS_ICU $x
  1167. } else {
  1168. proj-fatal "--with-icu-config=$bin does not refer to an executable"
  1169. }
  1170. }
  1171. }
  1172. set ldflags [define LDFLAGS_ICU [string trim [get-define LDFLAGS_ICU]]]
  1173. set cflags [define CFLAGS_ICU [string trim [get-define CFLAGS_ICU]]]
  1174. if {"" ne $ldflags} {
  1175. sqlite-add-feature-flag -shell -DSQLITE_ENABLE_ICU
  1176. msg-result "Enabling ICU support with flags: $ldflags $cflags"
  1177. if {[opt-bool icu-collations]} {
  1178. msg-result "Enabling ICU collations."
  1179. sqlite-add-feature-flag -shell -DSQLITE_ENABLE_ICU_COLLATIONS
  1180. # Recall that shell.c builds with sqlite3.c
  1181. }
  1182. } elseif {[opt-bool icu-collations]} {
  1183. proj-warn "ignoring --enable-icu-collations because neither --with-icu-ldflags nor --with-icu-config provided any linker flags"
  1184. } else {
  1185. msg-result "ICU support is disabled."
  1186. }
  1187. }; # sqlite-check-icu
  1188. sqlite-check-icu
  1189. ########################################################################
  1190. # Check for the Emscripten SDK for building the web-based wasm
  1191. # components. The core lib and tools do not require this but ext/wasm
  1192. # does.
  1193. apply {{} {
  1194. if {$::autosetup(srcdir) ne $::autosetup(builddir)} {
  1195. # The EMSDK pieces require writing to the original source tree
  1196. # even when doing an out-of-tree build. The ext/wasm pieces do not
  1197. # support an out-of-tree build so we catch that case and treat it
  1198. # as if EMSDK were not found.
  1199. msg-result "Out-of tree build: not checking for EMSDK."
  1200. define EMCC_WRAPPER ""
  1201. return
  1202. }
  1203. set emccsh $::srcdir/tool/emcc.sh
  1204. if {![get-define HAVE_WASI_SDK] && [proj-check-emsdk]} {
  1205. define EMCC_WRAPPER $emccsh
  1206. proj-make-from-dot-in $emccsh
  1207. catch {exec chmod u+x $emccsh}
  1208. } else {
  1209. define EMCC_WRAPPER ""
  1210. file delete -force $emccsh
  1211. }
  1212. }}
  1213. ########################################################################
  1214. # Check for log(3) in libm and die with an error if it is not
  1215. # found. $featureName should be the feature name which requires that
  1216. # function (it's used only in error messages). defines LDFLAGS_MATH to
  1217. # the required linker flags (which may be empty even if the math APIs
  1218. # are found, depending on the OS).
  1219. proc affirm-have-math {featureName} {
  1220. if {"" eq [get-define LDFLAGS_MATH ""]} {
  1221. if {![msg-quiet proj-check-function-in-lib log m]} {
  1222. user-error "Missing math APIs for $featureName"
  1223. }
  1224. define LDFLAGS_MATH [get-define lib_log ""]
  1225. undefine lib_log
  1226. }
  1227. }
  1228. ########################################################################
  1229. # Handle various SQLITE_ENABLE_... feature flags.
  1230. msg-result "Feature flags..."
  1231. foreach {boolFlag featureFlag ifSetEvalThis} {
  1232. all {} {
  1233. # The 'all' option must be first in this list.
  1234. proj-opt-set fts4
  1235. proj-opt-set fts5
  1236. proj-opt-set geopoly
  1237. proj-opt-set rtree
  1238. proj-opt-set session
  1239. }
  1240. fts4 -DSQLITE_ENABLE_FTS4 {affirm-have-math fts4}
  1241. fts5 -DSQLITE_ENABLE_FTS5 {affirm-have-math fts5}
  1242. geopoly -DSQLITE_ENABLE_GEOPOLY {proj-opt-set rtree}
  1243. rtree -DSQLITE_ENABLE_RTREE {}
  1244. session {-DSQLITE_ENABLE_SESSION -DSQLITE_ENABLE_PREUPDATE_HOOK} {}
  1245. update-limit -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT {}
  1246. memsys5 -DSQLITE_ENABLE_MEMSYS5 {}
  1247. memsys3 {} {
  1248. if {[opt-bool memsys5]} {
  1249. proj-warn "not enabling memsys3 because memsys5 is enabled."
  1250. expr 0
  1251. } else {
  1252. sqlite-add-feature-flag -DSQLITE_ENABLE_MEMSYS3
  1253. }
  1254. }
  1255. scanstatus -DSQLITE_ENABLE_STMT_SCANSTATUS {}
  1256. } {
  1257. proj-if-opt-truthy $boolFlag {
  1258. sqlite-add-feature-flag $featureFlag
  1259. if {0 != [eval $ifSetEvalThis] && "all" ne $boolFlag} {
  1260. msg-result " + $boolFlag"
  1261. }
  1262. } {
  1263. if {"all" ne $boolFlag} {
  1264. msg-result " - $boolFlag"
  1265. }
  1266. }
  1267. }
  1268. ########################################################################
  1269. # Invert the above loop's logic for some SQLITE_OMIT_... cases. If
  1270. # config option $boolFlag is false, [sqlite-add-feature-flag
  1271. # $featureFlag], where $featureFlag is intended to be
  1272. # -DSQLITE_OMIT_...
  1273. foreach {boolFlag featureFlag} {
  1274. json -DSQLITE_OMIT_JSON
  1275. } {
  1276. if {[proj-opt-truthy $boolFlag]} {
  1277. msg-result " + $boolFlag"
  1278. } else {
  1279. sqlite-add-feature-flag $featureFlag
  1280. msg-result " - $boolFlag"
  1281. }
  1282. }
  1283. #########################################################################
  1284. # Show the final feature flag sets:
  1285. apply {{} {
  1286. set oFF [get-define OPT_FEATURE_FLAGS]
  1287. if {"" ne $oFF} {
  1288. define OPT_FEATURE_FLAGS [lsort -unique $oFF]
  1289. msg-result "Library feature flags: [get-define OPT_FEATURE_FLAGS]"
  1290. }
  1291. set oFF [get-define OPT_SHELL]
  1292. if {"" ne $oFF} {
  1293. define OPT_SHELL [lsort -unique $oFF]
  1294. msg-result "Shell options: [get-define OPT_SHELL]"
  1295. }
  1296. unset oFF
  1297. }}
  1298. ########################################################################
  1299. # "Re-export" the autoconf-conventional --XYZdir flags into something
  1300. # which is more easily overridable from a make invocation. See the docs
  1301. # for [proj-remap-autoconf-dir-vars] for the explanation of why.
  1302. #
  1303. # We do this late in the config process, immediately before we export
  1304. # the Makefile and other generated files, so that configure tests
  1305. # which make make use of the autotools-conventional flags
  1306. # (e.g. [proj-check-rpath]) may do so before we "mangle" them here.
  1307. proj-remap-autoconf-dir-vars
  1308. ########################################################################
  1309. # Generate the output files.
  1310. #
  1311. # Potential TODO (unclear): in sqlite3.pc.in, do we need to include
  1312. # any CFLAGS_READLINE, CFLAGS_ZLIB, etc in its "Cflags:" section?
  1313. proj-make-from-dot-in -touch Makefile sqlite3.pc
  1314. make-config-header sqlite_cfg.h \
  1315. -bare {SIZEOF_* HAVE_DECL_*} \
  1316. -none {HAVE_CFLAG_* LDFLAGS_* SH_* SQLITE_AUTORECONFIG
  1317. TARGET_* USE_GCOV TCL_*} \
  1318. -auto {HAVE_* PACKAGE_*} \
  1319. -none *
  1320. proj-touch sqlite_cfg.h ; # help avoid frequent unnecessary @SQLITE_AUTORECONFIG@
  1321. ########################################################################
  1322. # Some build-dev/debug-only output
  1323. proj-if-opt-truthy dump-defines {
  1324. make-config-header $::DUMP_DEFINES_TXT \
  1325. -bare {SQLITE_OS* SQLITE_DEBUG USE_*} \
  1326. -str {BIN_* CC LD AR LDFLAG* OPT_*} \
  1327. -auto {*}
  1328. # achtung: ^^^^ whichever SQLITE_OS_foo flag which is set to 0 will
  1329. # get _undefined_ here unless it's part of the -bare set.
  1330. if {"" ne $DUMP_DEFINES_JSON} {
  1331. msg-result "--dump-defines is creating $::DUMP_DEFINES_JSON"
  1332. ########################################################################
  1333. # Dump config-defines.json...
  1334. # Demonstrate (mis?)handling of spaces in JSON-export array values:
  1335. # define-append OPT_FOO.list {"-DFOO=bar baz" -DBAR="baz barre"}
  1336. define OPT_FEATURE_FLAGS.list [get-define OPT_FEATURE_FLAGS]
  1337. define OPT_SHELL.list [get-define OPT_SHELL]
  1338. set dumpDefsOpt {
  1339. -bare {SIZEOF_* HAVE_DECL_*}
  1340. -none {HAVE_CFLAG_* LDFLAGS_* SH_* SQLITE_AUTORECONFIG TARGET_* USE_GCOV TCL_*}
  1341. -array {*.list}
  1342. -auto {OPT_* PACKAGE_* HAVE_*}
  1343. }
  1344. if {[opt-bool defines-json-include-lowercase]} {
  1345. lappend dumpDefsOpt -none {lib_*} ; # remnants from proj-check-function-in-lib and friends
  1346. lappend dumpDefsOpt -auto {[a-z]*}
  1347. }
  1348. lappend dumpDefsOpt -none *
  1349. proj-dump-defs-json $DUMP_DEFINES_JSON {*}$dumpDefsOpt
  1350. undefine OPT_FEATURE_FLAGS.list
  1351. undefine OPT_SHELL.list
  1352. }
  1353. }
  1354. ########################################################################
  1355. # Perform some high-level validation on the generated files...
  1356. #
  1357. # 1) Ensure that no unresolved @VAR@ placeholders are in files which
  1358. # use those.
  1359. #
  1360. # 2) TBD
  1361. apply {{} {
  1362. # Check #1: ensure that files which get filtered for @VAR@ do not
  1363. # contain any unresolved @VAR@ refs. That may indicate an
  1364. # unexported/unused var or a typo.
  1365. foreach f "Makefile sqlite3.pc $::srcdir/tool/emcc.sh" {
  1366. if {![file exists $f]} continue
  1367. set lnno 1
  1368. foreach line [proj-file-content-list $f] {
  1369. if {[regexp {(@[A-Za-z_]+@)} $line match]} {
  1370. error "Unresolved reference to $match at line $lnno of $f"
  1371. }
  1372. incr lnno
  1373. }
  1374. }
  1375. }}