Fossil SCM

fossil-scm / auto.def
Source Blame History 1004 lines
f476744… drh 1 # System autoconfiguration. Try: ./configure --help
f476744… drh 2
65c7196… wyoung 3 # This must be above "options" below because it implicitly brings in the
65c7196… wyoung 4 # default Autosetup options, things like --prefix.
f99e07d… stephan 5 use cc cc-lib local
65c7196… wyoung 6
f476744… drh 7 options {
a0061bb… mistachkin 8 with-openssl:path|auto|tree|none
a0061bb… mistachkin 9 => {Look for OpenSSL in the given path, automatically, in the source tree, or none}
8435adc… mistachkin 10 with-zlib:path|auto|tree
a0061bb… mistachkin 11 => {Look for zlib in the given path, automatically, or in the source tree}
dfa758b… stephan 12 with-sqlite:path|auto|tree
31d431e… stephan 13 => {Look for sqlite in the given path, automatically, or in the source tree.}
825d78b… mistachkin 14 with-exec-rel-paths=0
825d78b… mistachkin 15 => {Enable relative paths for external diff/gdiff}
231d693… drh 16 with-sanitizer: => {Build with C compiler's -fsanitize=LIST; e.g. address,enum,null,undefined}
c91bafc… mistachkin 17 with-th1-docs=0 => {Enable TH1 for embedded documentation pages}
1c528d3… mistachkin 18 with-th1-hooks=0 => {Enable TH1 hooks for commands and web pages}
23c8937… drh 19 with-tcl:path => {Enable Tcl integration, with Tcl in the specified path}
955886f… mistachkin 20 with-tcl-stubs=0 => {Enable Tcl integration via stubs library mechanism}
955886f… mistachkin 21 with-tcl-private-stubs=0
955886f… mistachkin 22 => {Enable Tcl integration via private stubs mechanism}
d5ca538… mistachkin 23 with-mman=0 => {Enable use of POSIX memory APIs from "sys/mman.h"}
ed871fb… drh 24 with-see=0 => {Enable the SQLite Encryption Extension (SEE)}
b9a6e1a… danshearer 25 print-minimum-sqlite-version=0
b9a6e1a… danshearer 26 => {print the minimum SQLite version number required, and exit}
fea0402… jan.nijtmans 27 internal-sqlite=1 => {Don't use the internal SQLite, use the system one}
f476744… drh 28 static=0 => {Link a static executable}
4bf670e… drh 29 fusefs=1 => {Disable the Fuse Filesystem}
f476744… drh 30 fossil-debug=0 => {Build with fossil debugging enabled}
189adb9… drh 31 no-opt=0 => {Build without optimization}
3154536… stephan 32 json=0 => {Build with fossil JSON API enabled}
7fcb462… stephan 33 with-emsdk:path => {Directory containing the Emscripten SDK}
5cf0da6… stephan 34 compile-commands=0 =>
5cf0da6… stephan 35 "Check for compile_commands.json support."
b9a6e1a… danshearer 36 }
b9a6e1a… danshearer 37
7018d7c… drh 38 # Update the minimum required SQLite version number here, and also
7018d7c… drh 39 # in src/main.c near the sqlite3_libversion_number() call. Take care
7018d7c… drh 40 # that both places agree!
a13a024… drh 41 define MINIMUM_SQLITE_VERSION "3.54.0"
b9a6e1a… danshearer 42
834f651… danshearer 43 # This is useful for people wanting Fossil to use an external SQLite library
834f651… danshearer 44 # to compare the one they have against the minimum required
b9a6e1a… danshearer 45 if {[opt-bool print-minimum-sqlite-version]} {
a76b48c… stephan 46 puts [get-define MINIMUM_SQLITE_VERSION]
a76b48c… stephan 47 exit 0
b9f57f5… drh 48 }
b9f57f5… drh 49
b9f57f5… drh 50 # Space characters have never been allowed in either the source
b9f57f5… drh 51 # tree nor the build directory. But the resulting error messages
b9f57f5… drh 52 # could be confusing. The following checks make the reason for the
b9f57f5… drh 53 # failure clear.
b9f57f5… drh 54 #
f99e07d… stephan 55 set ::dirSrc $::autosetup(srcdir)
f99e07d… stephan 56 if {[string first " " $$::dirSrc] != -1} {
b9f57f5… drh 57 user-error "The pathname of the source tree\
b9f57f5… drh 58 may not contain space characters"
b9f57f5… drh 59 }
b9f57f5… drh 60 if {[string first " " $autosetup(builddir)] != -1} {
b9f57f5… drh 61 user-error "The pathname of the build directory\
b9f57f5… drh 62 may not contain space characters"
35f3e5b… stephan 63 }
35f3e5b… stephan 64
35f3e5b… stephan 65 set outOfTreeBuild 0
35f3e5b… stephan 66 if {![file exists fossil.1]} {
35f3e5b… stephan 67 puts "This appears to be an out-of-tree build."
35f3e5b… stephan 68 set outOfTreeBuild 1
65c7196… wyoung 69 }
f476744… drh 70
f476744… drh 71 # sqlite wants these types if possible
f476744… drh 72 cc-with {-includes {stdint.h inttypes.h}} {
a76b48c… stephan 73 cc-check-types uint32_t uint16_t int16_t uint8_t
f476744… drh 74 }
f476744… drh 75
f476744… drh 76 # Use pread/pwrite system calls in place of seek + read/write if possible
f476744… drh 77 define USE_PREAD [cc-check-functions pread]
ebb67be… wyoung 78
ebb67be… wyoung 79 # If we have cscope here, we'll use it in the "tags" target
4211165… wyoung 80 if {[cc-check-progs cscope]} {
e31cb3a… brickviking 81 define COLLECT_CSCOPE_DATA "cscope -bR $::dirSrc/src/*.\[ch\]"
4211165… wyoung 82 } else {
a76b48c… stephan 83 define COLLECT_CSCOPE_DATA ""
4211165… wyoung 84 }
ee2ffe3… wyoung 85
ee2ffe3… wyoung 86 # Find tclsh for the test suite.
ee2ffe3… wyoung 87 #
ee2ffe3… wyoung 88 # We can't use jimsh for this: the test suite uses features of Tcl that
ee2ffe3… wyoung 89 # Jim doesn't support, either statically or due to the way it's built by
ee2ffe3… wyoung 90 # autosetup. For example, Jim supports `file normalize`, but only if
ee2ffe3… wyoung 91 # you build it with HAVE_REALPATH, which won't ever be defined in this
ee2ffe3… wyoung 92 # context because autosetup doesn't try to discover platform-specific
ee2ffe3… wyoung 93 # details like that before it decides to build jimsh0. Besides which,
ee2ffe3… wyoung 94 # autosetup won't build jimsh0 at all if it can find tclsh itself.
ee2ffe3… wyoung 95 # Ironically, this means we may right now be running under either jimsh0
ee2ffe3… wyoung 96 # or a version of tclsh that we find unsuitable below!
f476744… drh 97 cc-check-progs tclsh
ee2ffe3… wyoung 98 set hbtd /usr/local/Cellar/tcl-tk
ee2ffe3… wyoung 99 if {[string equal false [get-define TCLSH]]} {
a76b48c… stephan 100 msg-result "WARNING: 'make test' will not run here."
7a43dcb… jan.nijtmans 101 set v 8.6
a76b48c… stephan 102 } else {
a76b48c… stephan 103 set v [exec sh -c "echo 'puts \$tcl_version' | tclsh"]
7a43dcb… jan.nijtmans 104 if {$v >= 8.6} {
a76b48c… stephan 105 msg-result "Found Tclsh version $v in the PATH."
a76b48c… stephan 106 define TCLSH tclsh
a76b48c… stephan 107 } elseif {[file isdirectory $hbtd]} {
a76b48c… stephan 108 # This is a macOS system with the Homebrew version of Tcl/Tk
a76b48c… stephan 109 # installed. Select the newest version. It won't normally be
a76b48c… stephan 110 # in the PATH to avoid shadowing /usr/bin/tclsh, and even if it
a76b48c… stephan 111 # were in the PATH, it's bad practice to put /usr/local/bin (the
a76b48c… stephan 112 # Homebrew default) ahead of /usr/bin, especially given that
a76b48c… stephan 113 # it's user-writeable by default with Homebrew. Thus, we can be
a76b48c… stephan 114 # pretty sure the only way to call it is with an absolute path.
a76b48c… stephan 115 set v [exec ls -tr $hbtd | tail -1]
a76b48c… stephan 116 set path "$hbtd/$v/bin/tclsh"
a76b48c… stephan 117 define TCLSH $path
a76b48c… stephan 118 msg-result "Using Homebrew Tcl/Tk version $path."
a76b48c… stephan 119 } else {
a76b48c… stephan 120 msg-result "WARNING: tclsh $v found; need >= 8.6 for 'make test'."
a76b48c… stephan 121 define TCLSH false ;# force "make test" failure via /usr/bin/false
a76b48c… stephan 122 }
57da8e2… drh 123 }
57da8e2… drh 124
57da8e2… drh 125 define CFLAGS [get-env CFLAGS "-g -Os"]
3f2cde2… drh 126 define EXTRA_CFLAGS "-Wall"
f476744… drh 127 define EXTRA_LDFLAGS ""
a13c373… jan.nijtmans 128 define USE_SYSTEM_SQLITE 0
a0061bb… mistachkin 129 define USE_LINENOISE 0
d5ca538… mistachkin 130 define USE_MMAN_H 0
ed871fb… drh 131 define USE_SEE 0
31d431e… stephan 132 define SQLITE3_ORIGIN 0
31d431e… stephan 133 # SQLITE3_ORIGIN 0 = src/sqlite3, 1=src/sqlite3-see.c, 2=client-provided
ac3e326… stephan 134 define SQLITE_OPTIONS_EXT ""
ac3e326… stephan 135 # SQLITE_OPTIONS_EXT => build-dependent CFLAGS for sqlite3.c and shell.c
da9f362… ashepilko 136
da9f362… ashepilko 137 # Maintain the C89/C90-style order of variable declarations before statements.
da9f362… ashepilko 138 # Check if the compiler supports the respective warning flag.
da9f362… ashepilko 139 if {[cctest -cflags -Wdeclaration-after-statement]} {
a76b48c… stephan 140 define-append EXTRA_CFLAGS -Wdeclaration-after-statement
da9f362… ashepilko 141 }
da9f362… ashepilko 142
b41f428… mistachkin 143
b41f428… mistachkin 144 # This procedure is a customized version of "cc-check-function-in-lib",
b41f428… mistachkin 145 # that does not modify the LIBS variable. Its use prevents prematurely
b41f428… mistachkin 146 # pulling in libraries that will be added later anyhow (e.g. "-ldl").
b41f428… mistachkin 147 proc check-function-in-lib {function libs {otherlibs {}}} {
a76b48c… stephan 148 if {[string length $otherlibs]} {
a76b48c… stephan 149 msg-checking "Checking for $function in $libs with $otherlibs..."
a76b48c… stephan 150 } else {
a76b48c… stephan 151 msg-checking "Checking for $function in $libs..."
a76b48c… stephan 152 }
a76b48c… stephan 153 set found 0
a76b48c… stephan 154 cc-with [list -libs $otherlibs] {
a76b48c… stephan 155 if {[cctest_function $function]} {
a76b48c… stephan 156 msg-result "none needed"
a76b48c… stephan 157 define lib_$function ""
a76b48c… stephan 158 incr found
a76b48c… stephan 159 } else {
a76b48c… stephan 160 foreach lib $libs {
a76b48c… stephan 161 cc-with [list -libs -l$lib] {
a76b48c… stephan 162 if {[cctest_function $function]} {
a76b48c… stephan 163 msg-result -l$lib
a76b48c… stephan 164 define lib_$function -l$lib
a76b48c… stephan 165 incr found
a76b48c… stephan 166 break
a76b48c… stephan 167 }
a76b48c… stephan 168 }
a76b48c… stephan 169 }
a76b48c… stephan 170 }
a76b48c… stephan 171 }
a76b48c… stephan 172 if {$found} {
a76b48c… stephan 173 define [feature-define-name $function]
a76b48c… stephan 174 } else {
a76b48c… stephan 175 msg-result "no"
a76b48c… stephan 176 }
a76b48c… stephan 177 return $found
b41f428… mistachkin 178 }
f476744… drh 179
f476744… drh 180 if {![opt-bool internal-sqlite]} {
350c627… drh 181 proc find_system_sqlite {} {
5fe55cb… dan 182
5fe55cb… dan 183 # On some systems (slackware), libsqlite3 requires -ldl to link. So
5fe55cb… dan 184 # search for the system SQLite once with -ldl, and once without. If
25f7fa1… drh 185 # the library can only be found with $extralibs set to -ldl, then
5fe55cb… dan 186 # the code below will append -ldl to LIBS.
5fe55cb… dan 187 #
5fe55cb… dan 188 foreach extralibs {{} {-ldl}} {
5fe55cb… dan 189
5fe55cb… dan 190 # Locate the system SQLite by searching for sqlite3_open(). Then check
e3258f1… jan.nijtmans 191 # if sqlite3_stmt_isexplain can be found as well. If we can find open() but
e3258f1… jan.nijtmans 192 # not stmt_isexplain(), then the system SQLite is too old to link against
7829abd… jan.nijtmans 193 # fossil.
7829abd… jan.nijtmans 194 #
b41f428… mistachkin 195 if {[check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
5fe55cb… dan 196 # Success. Update symbols and return.
5fe55cb… dan 197 #
5fe55cb… dan 198 define USE_SYSTEM_SQLITE 1
b41f428… mistachkin 199 define-append LIBS -lsqlite3
5fe55cb… dan 200 define-append LIBS $extralibs
5fe55cb… dan 201 return
5fe55cb… dan 202 }
5fe55cb… dan 203 }
5fe55cb… dan 204 user-error "system sqlite3 not found"
5fe55cb… dan 205 }
5fe55cb… dan 206
350c627… drh 207 find_system_sqlite
350c627… drh 208
350c627… drh 209 proc test_system_sqlite {} {
cbd27f2… stephan 210 # Check compatibility of the system SQLite library by running the
cbd27f2… stephan 211 # sqlcompttest.c program in the source tree passes
cbd27f2… stephan 212 # MINIMUM_SQLITE_VERSION set at the top of this file to
cbd27f2… stephan 213 # sqlcompttest.c
350c627… drh 214 #
350c627… drh 215 set cmdline {}
350c627… drh 216 lappend cmdline {*}[get-define CCACHE]
350c627… drh 217 lappend cmdline {*}[get-define CC] {*}[get-define CFLAGS]
f99e07d… stephan 218 lappend cmdline $::dirSrc/tools/sqlcompattest.c
f99e07d… stephan 219 lappend cmdline -o conftest__
4a15ccd… drh 220 lappend cmdline {*}[get-define LDFLAGS]
350c627… drh 221 lappend cmdline {*}[get-define LIBS]
834f651… danshearer 222 set sqlite-version [string cat "-D MINIMUM_SQLITE_VERSION=" [get-define MINIMUM_SQLITE_VERSION]]
834f651… danshearer 223 lappend cmdline {*}[set sqlite-version]
350c627… drh 224 set ok 1
350c627… drh 225 set err [catch {exec-with-stderr {*}$cmdline} result errinfo]
350c627… drh 226 if {$err} {
a76b48c… stephan 227 configlog "Failed: [join $cmdline]"
a76b48c… stephan 228 if {[string length $result]>0} {configlog $result}
a76b48c… stephan 229 configlog "============"
a76b48c… stephan 230 set ok 0
350c627… drh 231 } elseif {$::autosetup(debug)} {
a76b48c… stephan 232 configlog "Compiled OK: [join $cmdline]"
a76b48c… stephan 233 configlog "============"
350c627… drh 234 }
350c627… drh 235 if {!$ok} {
350c627… drh 236 user-error "unable to compile SQLite compatibility test program"
350c627… drh 237 }
350c627… drh 238 set err [catch {exec-with-stderr ./conftest__} result errinfo]
e6de5ec… drh 239 if {[get-define build] eq [get-define host]} {
e6de5ec… drh 240 set err [catch {exec-with-stderr ./conftest__} result errinfo]
e6de5ec… drh 241 if {$err} {
e6de5ec… drh 242 user-error $result
e6de5ec… drh 243 }
350c627… drh 244 }
350c627… drh 245 file delete ./conftest__
350c627… drh 246 }
350c627… drh 247 test_system_sqlite
918bcfc… jan.nijtmans 248
a0061bb… mistachkin 249 }
a0061bb… mistachkin 250
a0061bb… mistachkin 251 proc is_mingw {} {
5c6dee5… wyoung 252 return [expr {
ddba8ea… wyoung 253 [string match *mingw* [get-define host]]
5c6dee5… wyoung 254 }]
5c6dee5… wyoung 255 }
5c6dee5… wyoung 256
5c6dee5… wyoung 257 if {[is_mingw]} {
a76b48c… stephan 258 define-append EXTRA_CFLAGS -DBROKEN_MINGW_CMDLINE
a76b48c… stephan 259 define-append LIBS -lkernel32 -lws2_32
a76b48c… stephan 260 } else {
a76b48c… stephan 261 #
a76b48c… stephan 262 # NOTE: All platforms except MinGW should use the linenoise
a76b48c… stephan 263 # package. It is currently unsupported on Win32.
a76b48c… stephan 264 #
a76b48c… stephan 265 define USE_LINENOISE 1
a76b48c… stephan 266 }
a76b48c… stephan 267
a76b48c… stephan 268 if {[string match *-solaris* [get-define host]]} {
a76b48c… stephan 269 define-append EXTRA_CFLAGS {-D__EXTENSIONS__}
a76b48c… stephan 270 }
a76b48c… stephan 271
a76b48c… stephan 272 if {[opt-bool fossil-debug]} {
a76b48c… stephan 273 define CFLAGS {-g -O0 -Wall}
a76b48c… stephan 274 define-append CFLAGS -DFOSSIL_DEBUG
a76b48c… stephan 275 msg-result "Debugging support enabled"
a76b48c… stephan 276 }
a76b48c… stephan 277
a76b48c… stephan 278 if {[opt-bool no-opt]} {
a76b48c… stephan 279 define CFLAGS {-g -O0 -Wall}
a76b48c… stephan 280 msg-result "Builting without compiler optimization"
a76b48c… stephan 281 if {[opt-bool fossil-debug]} {
a76b48c… stephan 282 define-append CFLAGS -DFOSSIL_DEBUG
a76b48c… stephan 283 }
a76b48c… stephan 284 }
a76b48c… stephan 285
a76b48c… stephan 286 if {[opt-bool with-mman]} {
a76b48c… stephan 287 define-append EXTRA_CFLAGS -DUSE_MMAN_H
a76b48c… stephan 288 define USE_MMAN_H 1
a76b48c… stephan 289 msg-result "Enabling \"sys/mman.h\" support"
ed871fb… drh 290 }
ed871fb… drh 291
ed871fb… drh 292 if {[opt-bool with-see]} {
a76b48c… stephan 293 define-append EXTRA_CFLAGS -DUSE_SEE
a76b48c… stephan 294 define USE_SEE 1
a76b48c… stephan 295 define SQLITE3_ORIGIN 1
a76b48c… stephan 296 msg-result "Enabling encryption support"
796dcfe… drh 297 }
796dcfe… drh 298
796dcfe… drh 299 if {[opt-bool json]} {
a76b48c… stephan 300 # Reminder/FIXME (stephan): FOSSIL_ENABLE_JSON
a76b48c… stephan 301 # is required in the CFLAGS because json*.c
a76b48c… stephan 302 # have #ifdef guards around the whole file without
a76b48c… stephan 303 # reading config.h first.
a76b48c… stephan 304 define-append EXTRA_CFLAGS -DFOSSIL_ENABLE_JSON
a76b48c… stephan 305 define FOSSIL_ENABLE_JSON
a76b48c… stephan 306 msg-result "JSON support enabled"
3c941dd… drh 307 }
3c941dd… drh 308
825d78b… mistachkin 309 if {[opt-bool with-exec-rel-paths]} {
a76b48c… stephan 310 define-append EXTRA_CFLAGS -DFOSSIL_ENABLE_EXEC_REL_PATHS
a76b48c… stephan 311 define FOSSIL_ENABLE_EXEC_REL_PATHS
a76b48c… stephan 312 msg-result "Relative paths in external diff/gdiff enabled"
c91bafc… mistachkin 313 }
c91bafc… mistachkin 314
c91bafc… mistachkin 315 if {[opt-bool with-th1-docs]} {
a76b48c… stephan 316 define-append EXTRA_CFLAGS -DFOSSIL_ENABLE_TH1_DOCS
a76b48c… stephan 317 define FOSSIL_ENABLE_TH1_DOCS
a76b48c… stephan 318 msg-result "TH1 embedded documentation support enabled"
1c528d3… mistachkin 319 }
1c528d3… mistachkin 320
1c528d3… mistachkin 321 if {[opt-bool with-th1-hooks]} {
a76b48c… stephan 322 define-append EXTRA_CFLAGS -DFOSSIL_ENABLE_TH1_HOOKS
a76b48c… stephan 323 define FOSSIL_ENABLE_TH1_HOOKS
a76b48c… stephan 324 msg-result "TH1 hooks support enabled"
f476744… drh 325 }
61079c3… mistachkin 326
ce93b46… drh 327 #if {[opt-bool markdown]} {
ce93b46… drh 328 # # no-op. Markdown is now enabled by default.
166fa7e… mistachkin 329 # msg-result "Markdown support enabled"
ce93b46… drh 330 #}
f476744… drh 331
f476744… drh 332 if {[opt-bool static]} {
a76b48c… stephan 333 # XXX: This will not work on all systems.
a76b48c… stephan 334 define-append EXTRA_LDFLAGS -static
a76b48c… stephan 335 msg-result "Trying to link statically"
b41f428… mistachkin 336 } else {
a76b48c… stephan 337 define-append EXTRA_CFLAGS -DFOSSIL_DYNAMIC_BUILD=1
a76b48c… stephan 338 define FOSSIL_DYNAMIC_BUILD
b41f428… mistachkin 339 }
e6f64f5… wyoung 340
e6f64f5… wyoung 341 # Check for libraries that need to be sorted out early
e6f64f5… wyoung 342 cc-check-function-in-lib iconv iconv
e6f64f5… wyoung 343
374e73c… stephan 344 cc-check-function-in-lib sin m
374e73c… stephan 345 cc-check-function-in-lib dlopen dl
04e2f64… stephan 346
19f11a8… drh 347 # Helper for OpenSSL checking
19f11a8… drh 348 proc check-for-openssl {msg {cflags {}} {libs {-lssl -lcrypto -lpthread}}} {
a76b48c… stephan 349 msg-checking "Checking for $msg..."
a76b48c… stephan 350 set rc 0
a76b48c… stephan 351 if {[is_mingw]} {
a76b48c… stephan 352 lappend libs -lgdi32 -lwsock32 -lcrypt32
a76b48c… stephan 353 }
a76b48c… stephan 354 if {[info exists ::zlib_lib]} {
a76b48c… stephan 355 lappend libs $::zlib_lib
a76b48c… stephan 356 }
a76b48c… stephan 357 msg-quiet cc-with [list -cflags $cflags -libs $libs] {
a76b48c… stephan 358 if {[cc-check-includes openssl/ssl.h] && \
a76b48c… stephan 359 [cc-check-functions SSL_new]} {
a76b48c… stephan 360 incr rc
a76b48c… stephan 361 }
a76b48c… stephan 362 }
a76b48c… stephan 363 if {!$rc && ![is_mingw]} {
a76b48c… stephan 364 # On some systems, OpenSSL appears to require -ldl to link.
a76b48c… stephan 365 lappend libs -ldl
a76b48c… stephan 366 msg-quiet cc-with [list -cflags $cflags -libs $libs] {
a76b48c… stephan 367 if {[cc-check-includes openssl/ssl.h] && \
a76b48c… stephan 368 [cc-check-functions SSL_new]} {
a76b48c… stephan 369 incr rc
a76b48c… stephan 370 }
a76b48c… stephan 371 }
a76b48c… stephan 372 }
a76b48c… stephan 373 if {$rc} {
a76b48c… stephan 374 msg-result "ok"
a76b48c… stephan 375 return 1
a76b48c… stephan 376 } else {
a76b48c… stephan 377 msg-result "no"
a76b48c… stephan 378 return 0
a76b48c… stephan 379 }
a76b48c… stephan 380 }
a76b48c… stephan 381
d84494f… stephan 382 #
af7475c… stephan 383 # Check for zlib, using the given location if specified
d84494f… stephan 384 #
d84494f… stephan 385 proc handle-zlib {} {
d84494f… stephan 386 set ::zlibpath [opt-val with-zlib]; # used by downstream tcl tests
d84494f… stephan 387 if {$::zlibpath eq "tree"} {
d84494f… stephan 388 set ::zlibdir [file dirname $::autosetup(dir)]/compat/zlib
d84494f… stephan 389 if {![file isdirectory $::zlibdir]} {
d84494f… stephan 390 user-error "The zlib in source tree directory does not exist"
d84494f… stephan 391 } elseif { ([llength [glob -nocomplain -directory $::zlibdir libz*]] == 0) } {
d84494f… stephan 392 user-error "With --with-zlib=tree, $::zlibdir must be configured and built first."
d84494f… stephan 393 }
d84494f… stephan 394 cc-with [list -cflags "-I$::zlibdir -L$::zlibdir"]
d84494f… stephan 395 define-append EXTRA_CFLAGS -I$::zlibdir
d84494f… stephan 396 define-append LIBS $::zlibdir/libz.a
d84494f… stephan 397 set ::zlib_lib $::zlibdir/libz.a
d84494f… stephan 398 msg-result "Using zlib in source tree"
d84494f… stephan 399 } else {
d84494f… stephan 400 set cftry {""}
d84494f… stephan 401 set ldtry {""}
d84494f… stephan 402 if {$::zlibpath ni {auto ""}} {
d84494f… stephan 403 lappend cftry "-I$::zlibpath"
d84494f… stephan 404 lappend cftry "-I$::zlibpath/include"
d84494f… stephan 405 lappend ldtry "-L$::zlibpath"
d84494f… stephan 406 lappend ldtry "-L$::zlibpath/lib"
d84494f… stephan 407 }
d84494f… stephan 408
d84494f… stephan 409 # Reverse the list of tests so we check most-specific to least, else
d84494f… stephan 410 # platform devel files will shadow local --with-zlib overrides.
d84494f… stephan 411 foreach c [lreverse $cftry] {
d84494f… stephan 412 if {[cc-with [list -cflags $c] {cc-check-includes zlib.h}]} {
d84494f… stephan 413 if {$c eq ""} {
d84494f… stephan 414 msg-result "Found zlib.h in default include path"
d84494f… stephan 415 } else {
d84494f… stephan 416 define-append EXTRA_CFLAGS "$c"
d84494f… stephan 417 msg-result "Found zlib.h via $c"
d84494f… stephan 418 }
d84494f… stephan 419 set cfound $c
d84494f… stephan 420 break
d84494f… stephan 421 }
d84494f… stephan 422 }
d84494f… stephan 423 if {![info exists cfound]} {
d84494f… stephan 424 user-error "zlib.h not found; either install it or specify its location via --with-zlib"
d84494f… stephan 425 }
d84494f… stephan 426 foreach lcheck [lreverse $ldtry] {
d84494f… stephan 427 if {[cc-with [list -cflags "$cfound $lcheck"] {check-function-in-lib inflateEnd z}]} {
d84494f… stephan 428 if {$lcheck eq ""} {
d84494f… stephan 429 msg-result "Linked to zlib via default library path"
d84494f… stephan 430 } else {
d84494f… stephan 431 define-append EXTRA_LDFLAGS "$lcheck"
d84494f… stephan 432 msg-result "Linked to zlib via $lcheck"
d84494f… stephan 433 }
d84494f… stephan 434 if {![check-function-in-lib compressBound z]} {
d84494f… stephan 435 puts "Notice: disabling zlib compression in the SQL shell"
d84494f… stephan 436 define-append SQLITE_OPTIONS_EXT {-USQLITE_HAVE_ZLIB}
d84494f… stephan 437 }
d84494f… stephan 438 break
d84494f… stephan 439 }
d84494f… stephan 440 }
d84494f… stephan 441 set ::zlib_lib -lz
d84494f… stephan 442 }
d84494f… stephan 443 }; # handle-zlib
d84494f… stephan 444 handle-zlib
af7475c… stephan 445
af7475c… stephan 446 #
af7475c… stephan 447 # Handle the --with-openssl flag and, incidentally, update @LIBS@ for
af7475c… stephan 448 # zlib if openssl is _not_ used (if it is, we get zlib via libssl).
af7475c… stephan 449 #
af7475c… stephan 450 # This function should be called as late as possible in the configure
af7475c… stephan 451 # script to avoid that its updates to @LIBS@ break tests which follow
af7475c… stephan 452 # it when a custom local build of openssl is used, as discussed in
af7475c… stephan 453 # <https://fossil-scm.org/forum/forumpost/15e3d9cdc137030c>.
af7475c… stephan 454 #
af7475c… stephan 455 proc handle-with-openssl {} {
af7475c… stephan 456 set ssldirs [opt-val with-openssl]
af7475c… stephan 457 if {$ssldirs ne "none"} {
af7475c… stephan 458 set found 0
af7475c… stephan 459 if {$ssldirs eq "tree"} {
d84494f… stephan 460 set ssldir [file dirname $::autosetup(dir)]/compat/openssl
af7475c… stephan 461 if {![file isdirectory $ssldir]} {
af7475c… stephan 462 user-error "The OpenSSL in source tree directory does not exist"
af7475c… stephan 463 }
af7475c… stephan 464 set msg "openssl in $ssldir"
af7475c… stephan 465 set cflags "-I$ssldir/include"
af7475c… stephan 466 set ldflags "-L$ssldir"
af7475c… stephan 467 set ssllibs "$ssldir/libssl.a $ssldir/libcrypto.a -lpthread"
af7475c… stephan 468 set found [check-for-openssl "openssl in source tree" "$cflags $ldflags" $ssllibs]
af7475c… stephan 469 } else {
af7475c… stephan 470 if {$ssldirs in {auto ""}} {
af7475c… stephan 471 catch {
d84494f… stephan 472 # TODO?: use autosetup's pkg-config support
af7475c… stephan 473 set cflags [exec pkg-config openssl --cflags-only-I]
af7475c… stephan 474 set ldflags [exec pkg-config openssl --libs-only-L]
af7475c… stephan 475 set found [check-for-openssl "ssl via pkg-config" "$cflags $ldflags"]
af7475c… stephan 476 } msg
af7475c… stephan 477 if {!$found} {
af7475c… stephan 478 set ssldirs "{} /usr/sfw /usr/local/ssl /usr/lib/ssl /usr/ssl \
af7475c… stephan 479 /usr/pkg /usr/local /usr /usr/local/opt/openssl \
af7475c… stephan 480 /opt/homebrew/opt/openssl"
af7475c… stephan 481 }
af7475c… stephan 482 }
af7475c… stephan 483 if {!$found} {
af7475c… stephan 484 foreach dir $ssldirs {
af7475c… stephan 485 if {$dir eq ""} {
af7475c… stephan 486 set msg "system openssl"
af7475c… stephan 487 set cflags ""
af7475c… stephan 488 set ldflags ""
af7475c… stephan 489 } else {
af7475c… stephan 490 set msg "openssl in $dir"
af7475c… stephan 491 set cflags "-I$dir/include"
af7475c… stephan 492 if {[file readable $dir/libssl.a]} {
af7475c… stephan 493 set ldflags -L$dir
af7475c… stephan 494 } elseif {[file readable $dir/lib/libssl.a]} {
af7475c… stephan 495 set ldflags -L$dir/lib
af7475c… stephan 496 } elseif {[file isdir $dir/lib]} {
af7475c… stephan 497 set ldflags "-L$dir -L$dir/lib"
af7475c… stephan 498 } else {
af7475c… stephan 499 set ldflags -L$dir
af7475c… stephan 500 }
af7475c… stephan 501 }
af7475c… stephan 502 if {[check-for-openssl $msg "$cflags $ldflags"]} {
af7475c… stephan 503 incr found
af7475c… stephan 504 break
af7475c… stephan 505 }
af7475c… stephan 506 if {$dir ne ""} {
af7475c… stephan 507 set ldflags ""
af7475c… stephan 508 set msg "static build of openssl in $dir"
af7475c… stephan 509 set ssllibs "$dir/libssl.a $dir/libcrypto.a -lpthread"
af7475c… stephan 510 if {[check-for-openssl $msg "$cflags $ldflags" $ssllibs]} {
af7475c… stephan 511 incr found
af7475c… stephan 512 break
af7475c… stephan 513 }
8d3b9bf… drh 514 # This test should arguably fail here if --with-openssl=X
8d3b9bf… drh 515 # points to an invalid X.
af7475c… stephan 516 }
af7475c… stephan 517 }
af7475c… stephan 518 }
af7475c… stephan 519 }
af7475c… stephan 520 if {$found} {
af7475c… stephan 521 define FOSSIL_ENABLE_SSL
af7475c… stephan 522 define-append EXTRA_CFLAGS $cflags
af7475c… stephan 523 define-append EXTRA_LDFLAGS $ldflags
af7475c… stephan 524 if {[info exists ssllibs]} {
af7475c… stephan 525 define-append LIBS $ssllibs
af7475c… stephan 526 } else {
af7475c… stephan 527 define-append LIBS -lssl -lcrypto
af7475c… stephan 528 }
af7475c… stephan 529 if {[info exists ::zlib_lib]} {
af7475c… stephan 530 define-append LIBS $::zlib_lib
af7475c… stephan 531 }
af7475c… stephan 532 if {[is_mingw]} {
af7475c… stephan 533 define-append LIBS -lgdi32 -lwsock32 -lcrypt32
af7475c… stephan 534 }
af7475c… stephan 535 msg-result "HTTPS support enabled"
af7475c… stephan 536
af7475c… stephan 537 # Silence OpenSSL deprecation warnings on Mac OS X 10.7.
af7475c… stephan 538 if {[string match *-darwin* [get-define host]]} {
af7475c… stephan 539 if {[cctest -cflags {-Wdeprecated-declarations}]} {
af7475c… stephan 540 define-append EXTRA_CFLAGS -Wdeprecated-declarations
af7475c… stephan 541 }
af7475c… stephan 542 }
af7475c… stephan 543 } else {
af7475c… stephan 544 user-error "OpenSSL not found. Consider --with-openssl=none to disable HTTPS support"
af7475c… stephan 545 }
af7475c… stephan 546 } else {
af7475c… stephan 547 if {[info exists ::zlib_lib]} {
af7475c… stephan 548 define-append LIBS $::zlib_lib
af7475c… stephan 549 }
af7475c… stephan 550 }
af7475c… stephan 551 }; # handle-with-openssl
af7475c… stephan 552
d84494f… stephan 553 #
d84494f… stephan 554 # CFLAGS_INCLUDE is ONLY for -I... flags and their order is
d84494f… stephan 555 # significant so that --with-sqlite=PATH's header can shadow our
d84494f… stephan 556 # own. <s>One caveat with this is that we cannot point
d84494f… stephan 557 # --with-sqlite=PATH to the root of sqlite3's own build tree because
d84494f… stephan 558 # that dir has a config.h which ends up shadowing src/config.h,
d84494f… stephan 559 # breaking our build.</s> (That is no longer true: that that config.h
d84494f… stephan 560 # was renamed to sqlite_cfg.h at some point.)
d84494f… stephan 561 #
d84494f… stephan 562 define CFLAGS_INCLUDE {}
d84494f… stephan 563
31d431e… stephan 564 ########################################################################
31d431e… stephan 565 # --with-sqlite=PATH checks for the first it finds of the following...
31d431e… stephan 566 # - PATH/sqlite3.c and PATH/sqlite3.h
31d431e… stephan 567 # - PATH/sqlite3.o (and assumes sqlite3.h is with it)
31d431e… stephan 568 # - PATH/lib/libsqlite3* and PATH/include/sqlite3.h
d84494f… stephan 569 proc handle-with-sqlite {} {
d84494f… stephan 570 set sq3path [opt-val with-sqlite]
d84494f… stephan 571 define SQLITE3_SRC.2 {}
d84494f… stephan 572 define SQLITE3_OBJ.2 {}
d84494f… stephan 573 define SQLITE3_SHELL_SRC.2 {$(SQLITE3_SHELL_SRC.0)}
d84494f… stephan 574 if {$sq3path in {tree ""}} {
d84494f… stephan 575 msg-result "Using sqlite3.c from this source tree."
d84494f… stephan 576 } else {
d84494f… stephan 577 # SQLITE3_ORIGIN:
d84494f… stephan 578 # 0 = local source tree
d84494f… stephan 579 # 1 = use external lib or sqlite3.o
d84494f… stephan 580 # 2 = use external sqlite3.c and (if found) shell.c
d84494f… stephan 581 define USE_SYSTEM_SQLITE 1
d84494f… stephan 582 define SQLITE3_ORIGIN 2
d84494f… stephan 583 if {$sq3path != "auto"} {
d84494f… stephan 584 if {([file exists $sq3path/sqlite3.c]) &&
d84494f… stephan 585 ([file exists $sq3path/sqlite3.h]) } {
d84494f… stephan 586 # Prefer sqlite3.[ch] if found.
d84494f… stephan 587 define SQLITE3_SRC.2 $sq3path/sqlite3.c
d84494f… stephan 588 define SQLITE3_OBJ.2 {$(SQLITE3_OBJ.0)}
d84494f… stephan 589 define USE_SYSTEM_SQLITE 2
d84494f… stephan 590 define SQLITE3_ORIGIN 2
d84494f… stephan 591 if {[file exists $sq3path/shell.c]} {
d84494f… stephan 592 define SQLITE3_SHELL_SRC.2 $sq3path/shell.c
d84494f… stephan 593 }
d84494f… stephan 594 define-append CFLAGS_INCLUDE -I$sq3path
d84494f… stephan 595 define-append EXTRA_LDFLAGS -lpthread
d84494f… stephan 596 # ^^^ additional -lXXX flags are conservative estimates
d84494f… stephan 597 msg-result "Using sqlite3.c and sqlite3.h from $sq3path"
d84494f… stephan 598 } elseif {[file exists $sq3path/sqlite3.o]} {
d84494f… stephan 599 # Use sqlite3.o if found.
d84494f… stephan 600 define SQLITE3_OBJ.2 $sq3path/sqlite3.o
d84494f… stephan 601 define-append CFLAGS_INCLUDE -I$sq3path
d84494f… stephan 602 define-append EXTRA_LDFLAGS $sq3path/sqlite3.o -lpthread
d84494f… stephan 603 # ^^^ additional -lXXX flags are conservative estimates
d84494f… stephan 604 msg-result "Using sqlite3.o from $sq3path"
d84494f… stephan 605 } elseif { ([llength [glob -nocomplain -directory $sq3path/lib libsqlite3*]] != 0) \
d84494f… stephan 606 && ([file exists $sq3path/include/sqlite3.h]) } {
d84494f… stephan 607 # e.g. --with-sqlite=/usr/local. Try $sq3path/lib/libsqlite3*
d84494f… stephan 608 # and $sq3path/include/sqlite3.h
d84494f… stephan 609 define-append CFLAGS_INCLUDE -I$sq3path/include
d84494f… stephan 610 define-append EXTRA_LDFLAGS -L$sq3path/lib -lsqlite3 -lpthread
d84494f… stephan 611 # ^^^ additional -lXXX flags are conservative estimates
d84494f… stephan 612 msg-result "Using -lsqlite3 from $sq3path"
d84494f… stephan 613 } else {
d84494f… stephan 614 # Assume $sq3path holds both the lib and header
d84494f… stephan 615 cc-with [list -cflags "-I$sq3path -L$sq3path"]
d84494f… stephan 616 define-append CFLAGS_INCLUDE -I$sq3path
d84494f… stephan 617 define-append EXTRA_LDFLAGS -L$sq3path -lsqlite3 -lpthread
d84494f… stephan 618 # ^^^ additional -lXXX flags are conservative estimates
d84494f… stephan 619 msg-result "Using -lsqlite3 from $sq3path"
d84494f… stephan 620 }
d84494f… stephan 621 } elseif {![cc-check-includes sqlite3.h] || ![check-function-in-lib sqlite3_open_v2 sqlite3]} {
d84494f… stephan 622 user-error "libsqlite3 not found please install it or specify the location with --with-sqlite"
d84494f… stephan 623 }
d84494f… stephan 624 }
d84494f… stephan 625 }; # handle-with-sqlite
d84494f… stephan 626 handle-with-sqlite
d84494f… stephan 627 define-append CFLAGS_INCLUDE {-I. -I$(SRCDIR) -I$(SRCDIR_extsrc)}; # must be after handle-with-sqlite
d84494f… stephan 628
d84494f… stephan 629 #
d84494f… stephan 630 # Handle the --with-tcl flag.
d84494f… stephan 631 #
d84494f… stephan 632 proc handle-with-tcl {} {
7a43dcb… jan.nijtmans 633 global v
d84494f… stephan 634 set tclpath [opt-val with-tcl]
d84494f… stephan 635 if {$tclpath eq ""} {
d84494f… stephan 636 return
d84494f… stephan 637 }
a76b48c… stephan 638 set tclprivatestubs [opt-bool with-tcl-private-stubs]
a76b48c… stephan 639 # Note parse-tclconfig-sh is in autosetup/local.tcl
a76b48c… stephan 640 if {$tclpath eq "1"} {
7a43dcb… jan.nijtmans 641 if {$v >= 9.0} {
7a43dcb… jan.nijtmans 642 set tcldir [file dirname $::autosetup(dir)]/compat/tcl-9.0
7a43dcb… jan.nijtmans 643 } else {
7a43dcb… jan.nijtmans 644 set tcldir [file dirname $::autosetup(dir)]/compat/tcl-8.6
7a43dcb… jan.nijtmans 645 }
a76b48c… stephan 646 if {$tclprivatestubs} {
a76b48c… stephan 647 set tclconfig(TCL_INCLUDE_SPEC) -I$tcldir/generic
a76b48c… stephan 648 set tclconfig(TCL_VERSION) {Private Stubs}
a76b48c… stephan 649 set tclconfig(TCL_PATCH_LEVEL) {}
a76b48c… stephan 650 set tclconfig(TCL_PREFIX) $tcldir
a76b48c… stephan 651 set tclconfig(TCL_LD_FLAGS) { }
a76b48c… stephan 652 } else {
a76b48c… stephan 653 # Use the system Tcl. Look in some likely places.
a76b48c… stephan 654 array set tclconfig [parse-tclconfig-sh \
d84494f… stephan 655 $tcldir/unix $tcldir/win \
d84494f… stephan 656 /usr /usr/local /usr/share /opt/local]
a76b48c… stephan 657 set msg "on your system"
a76b48c… stephan 658 }
a76b48c… stephan 659 } else {
a76b48c… stephan 660 array set tclconfig [parse-tclconfig-sh $tclpath]
a76b48c… stephan 661 set msg "at $tclpath"
a76b48c… stephan 662 }
a76b48c… stephan 663 if {[opt-bool static]} {
a76b48c… stephan 664 set tclconfig(TCL_LD_FLAGS) { }
a76b48c… stephan 665 }
a76b48c… stephan 666 if {![info exists tclconfig(TCL_INCLUDE_SPEC)]} {
a76b48c… stephan 667 user-error "Cannot find Tcl $msg"
a76b48c… stephan 668 }
a76b48c… stephan 669 set tclstubs [opt-bool with-tcl-stubs]
a76b48c… stephan 670 if {$tclprivatestubs} {
a76b48c… stephan 671 define FOSSIL_ENABLE_TCL_PRIVATE_STUBS
a76b48c… stephan 672 define USE_TCL_STUBS
a76b48c… stephan 673 } elseif {$tclstubs && $tclconfig(TCL_SUPPORTS_STUBS)} {
a76b48c… stephan 674 set libs "$tclconfig(TCL_STUB_LIB_SPEC)"
a76b48c… stephan 675 define FOSSIL_ENABLE_TCL_STUBS
a76b48c… stephan 676 define USE_TCL_STUBS
a76b48c… stephan 677 } else {
a76b48c… stephan 678 set libs "$tclconfig(TCL_LIB_SPEC) $tclconfig(TCL_LIBS)"
a76b48c… stephan 679 }
a76b48c… stephan 680 set cflags $tclconfig(TCL_INCLUDE_SPEC)
a76b48c… stephan 681 if {!$tclprivatestubs} {
a76b48c… stephan 682 set foundtcl 0; # Did we find a working Tcl library?
a76b48c… stephan 683 cc-with [list -cflags $cflags -libs $libs] {
a76b48c… stephan 684 if {$tclstubs} {
a76b48c… stephan 685 if {[cc-check-functions Tcl_InitStubs]} {
a76b48c… stephan 686 set foundtcl 1
a76b48c… stephan 687 }
a76b48c… stephan 688 } else {
a76b48c… stephan 689 if {[cc-check-functions Tcl_CreateInterp]} {
a76b48c… stephan 690 set foundtcl 1
a76b48c… stephan 691 }
a76b48c… stephan 692 }
a76b48c… stephan 693 }
a76b48c… stephan 694 if {!$foundtcl && [string match *-lieee* $libs]} {
a76b48c… stephan 695 # On some systems, using "-lieee" from TCL_LIB_SPEC appears
a76b48c… stephan 696 # to cause issues.
a76b48c… stephan 697 msg-result "Removing \"-lieee\" and retrying for Tcl..."
a76b48c… stephan 698 set libs [string map [list -lieee ""] $libs]
a76b48c… stephan 699 cc-with [list -cflags $cflags -libs $libs] {
a76b48c… stephan 700 if {$tclstubs} {
a76b48c… stephan 701 if {[cc-check-functions Tcl_InitStubs]} {
a76b48c… stephan 702 set foundtcl 1
a76b48c… stephan 703 }
a76b48c… stephan 704 } else {
a76b48c… stephan 705 if {[cc-check-functions Tcl_CreateInterp]} {
a76b48c… stephan 706 set foundtcl 1
a76b48c… stephan 707 }
a76b48c… stephan 708 }
a76b48c… stephan 709 }
a76b48c… stephan 710 }
a76b48c… stephan 711 if {!$foundtcl && ![string match *-lpthread* $libs]} {
a76b48c… stephan 712 # On some systems, TCL_LIB_SPEC appears to be missing
a76b48c… stephan 713 # "-lpthread". Try adding it.
a76b48c… stephan 714 msg-result "Adding \"-lpthread\" and retrying for Tcl..."
a76b48c… stephan 715 set libs "$libs -lpthread"
a76b48c… stephan 716 cc-with [list -cflags $cflags -libs $libs] {
a76b48c… stephan 717 if {$tclstubs} {
a76b48c… stephan 718 if {[cc-check-functions Tcl_InitStubs]} {
a76b48c… stephan 719 set foundtcl 1
a76b48c… stephan 720 }
a76b48c… stephan 721 } else {
a76b48c… stephan 722 if {[cc-check-functions Tcl_CreateInterp]} {
a76b48c… stephan 723 set foundtcl 1
a76b48c… stephan 724 }
a76b48c… stephan 725 }
a76b48c… stephan 726 }
a76b48c… stephan 727 }
a76b48c… stephan 728 if {!$foundtcl} {
a76b48c… stephan 729 if {$tclstubs} {
a76b48c… stephan 730 user-error "Cannot find a usable Tcl stubs library $msg"
a76b48c… stephan 731 } else {
a76b48c… stephan 732 user-error "Cannot find a usable Tcl library $msg"
a76b48c… stephan 733 }
a76b48c… stephan 734 }
a76b48c… stephan 735 }
a76b48c… stephan 736 set version $tclconfig(TCL_VERSION)$tclconfig(TCL_PATCH_LEVEL)
a76b48c… stephan 737 msg-result "Found Tcl $version at $tclconfig(TCL_PREFIX)"
a76b48c… stephan 738 if {!$tclprivatestubs} {
a76b48c… stephan 739 define-append LIBS $libs
a76b48c… stephan 740 }
a76b48c… stephan 741 define-append EXTRA_CFLAGS $cflags
a76b48c… stephan 742 define-append CFLAGS $cflags
d84494f… stephan 743 if {[info exists ::zlibpath] && $::zlibpath eq "tree"} {
a76b48c… stephan 744 #
a76b48c… stephan 745 # NOTE: When using zlib in the source tree, prevent Tcl from
a76b48c… stephan 746 # pulling in the system one.
a76b48c… stephan 747 #
a76b48c… stephan 748 set tclconfig(TCL_LD_FLAGS) [string map [list -lz ""] \
d84494f… stephan 749 $tclconfig(TCL_LD_FLAGS)]
a76b48c… stephan 750 }
a76b48c… stephan 751 #
a76b48c… stephan 752 # NOTE: Remove "-ldl" from the TCL_LD_FLAGS because it will be
a76b48c… stephan 753 # be checked for near the bottom of this file.
a76b48c… stephan 754 #
a76b48c… stephan 755 set tclconfig(TCL_LD_FLAGS) [string map [list -ldl ""] \
d84494f… stephan 756 $tclconfig(TCL_LD_FLAGS)]
a76b48c… stephan 757 define-append EXTRA_LDFLAGS $tclconfig(TCL_LD_FLAGS)
a76b48c… stephan 758 define FOSSIL_ENABLE_TCL
d84494f… stephan 759 }; # handle-with-tcl
d84494f… stephan 760 handle-with-tcl
f476744… drh 761
f476744… drh 762 # Network functions require libraries on some systems
f476744… drh 763 cc-check-function-in-lib gethostbyname nsl
f476744… drh 764 if {![cc-check-function-in-lib socket {socket network}]} {
a76b48c… stephan 765 # Last resort, may be Windows
a76b48c… stephan 766 if {[is_mingw]} {
a76b48c… stephan 767 define-append LIBS -lwsock32
a76b48c… stephan 768 }
71c298f… wyoung 769 }
3bff7b9… drh 770
3bff7b9… drh 771 # Some systems (ex: SunOS) require -lrt in order to use nanosleep
3bff7b9… drh 772 cc-check-function-in-lib nanosleep rt
71c298f… wyoung 773
71c298f… wyoung 774 # The SMTP module requires special libraries and headers for MX DNS
71c298f… wyoung 775 # record lookups and such.
71c298f… wyoung 776 cc-check-includes arpa/nameser.h
71c298f… wyoung 777 cc-include-needs bind/resolv.h netinet/in.h
71c298f… wyoung 778 cc-check-includes bind/resolv.h
71c298f… wyoung 779 cc-check-includes resolv.h
71c298f… wyoung 780 if { !(([cc-check-function-in-lib dn_expand resolv] ||
71c298f… wyoung 781 [cc-check-function-in-lib ns_name_uncompress {bind resolv}] ||
71c298f… wyoung 782 [cc-check-function-in-lib __ns_name_uncompress {bind resolv}]) &&
71c298f… wyoung 783 ([cc-check-function-in-lib ns_parserr {bind resolv}] ||
71c298f… wyoung 784 [cc-check-function-in-lib __ns_parserr {bind resolv}]) &&
71c298f… wyoung 785 ([cc-check-function-in-lib res_query {bind resolv}] ||
71c298f… wyoung 786 [cc-check-function-in-lib __res_query {bind resolv}]))} {
a76b48c… stephan 787 msg-result "WARNING: SMTP feature will not be able to look up local MX."
7023de9… jan.nijtmans 788 }
71c298f… wyoung 789 cc-check-function-in-lib res_9_ns_initparse resolv
71c298f… wyoung 790
71c298f… wyoung 791 # Other nonstandard function checks
16f1076… jan.nijtmans 792 cc-check-functions utime
16f1076… jan.nijtmans 793 cc-check-functions usleep
9a9ef1d… jan.nijtmans 794 cc-check-functions strchrnul
64def88… drh 795 cc-check-functions pledge
a8d220b… drh 796 cc-check-functions backtrace
a8d220b… drh 797
f2aa77c… danield 798 # Termux on Android adds "getpass(char *)" to unistd.h, so check this so we
a3843d4… stephan 799 # guard against including it again; use cctest as cc-check-functions and
f2aa77c… danield 800 # cctest_function check for "getpass()" with no args and fail
f2aa77c… danield 801 if {[cctest -link 1 -includes {unistd.h} -code "getpass(0);"]} {
a76b48c… stephan 802 define FOSSIL_HAVE_GETPASS 1
a76b48c… stephan 803 msg-result "Found getpass() with unistd.h"
f2aa77c… danield 804 }
f2aa77c… danield 805
7023de9… jan.nijtmans 806 # Check for getloadavg(), and if it doesn't exist, define FOSSIL_OMIT_LOAD_AVERAGE
50ba8d8… danield 807 if {![cc-check-functions getloadavg] ||
50ba8d8… danield 808 ![cctest -link 1 -includes {unistd.h} -code "double a\[3\]; getloadavg(a,3);"]} {
7023de9… jan.nijtmans 809 define FOSSIL_OMIT_LOAD_AVERAGE 1
166fa7e… mistachkin 810 msg-result "Load average support unavailable"
7023de9… jan.nijtmans 811 }
f476744… drh 812
f476744… drh 813 # Check for getpassphrase() for Solaris 10 where getpass() truncates to 10 chars
f476744… drh 814 if {![cc-check-functions getpassphrase]} {
a76b48c… stephan 815 # Haiku needs this
a76b48c… stephan 816 cc-check-function-in-lib getpass bsd
4bf670e… drh 817 }
4bf670e… drh 818
4bf670e… drh 819 # Check for the FuseFS library
4bf670e… drh 820 if {[opt-bool fusefs]} {
6f9d265… drh 821 if {[opt-bool static]} {
a76b48c… stephan 822 msg-result "FuseFS support disabled due to -static"
6f9d265… drh 823 } elseif {[cc-check-function-in-lib fuse_mount fuse]} {
a76b48c… stephan 824 define-append EXTRA_CFLAGS -DFOSSIL_HAVE_FUSEFS
a76b48c… stephan 825 define FOSSIL_HAVE_FUSEFS 1
a76b48c… stephan 826 msg-result "FuseFS support enabled"
91f0f00… mark 827 }
91f0f00… mark 828 }
91f0f00… mark 829
91f0f00… mark 830 ########################################################################
bb66461… stephan 831 # Checks the compiler for compile_commands.json support.
91f0f00… mark 832 #
91f0f00… mark 833 # Returns 1 if supported, else 0. Defines MAKE_COMPILATION_DB to "yes"
91f0f00… mark 834 # if supported, "no" if not.
5cf0da6… stephan 835 proc check-compile-commands {} {
a76b48c… stephan 836 msg-checking "compile_commands.json support... "
a76b48c… stephan 837 if {[cctest -lang c -cflags {/dev/null -MJ} -source {}]} {
a76b48c… stephan 838 # This test reportedly incorrectly succeeds on one of
a76b48c… stephan 839 # Martin G.'s older systems.
a76b48c… stephan 840 msg-result "compiler supports compile_commands.json"
a76b48c… stephan 841 define MAKE_COMPILATION_DB yes
a76b48c… stephan 842 return 1
a76b48c… stephan 843 } else {
a76b48c… stephan 844 msg-result "compiler does not support compile_commands.json"
a76b48c… stephan 845 define MAKE_COMPILATION_DB no
a76b48c… stephan 846 return 0
a76b48c… stephan 847 }
5cf0da6… stephan 848 }
5cf0da6… stephan 849
5cf0da6… stephan 850 define MAKE_COMPILATION_DB no
35f3e5b… stephan 851 if {!$outOfTreeBuild} {
5cf0da6… stephan 852 if {[opt-bool compile-commands]} {
5cf0da6… stephan 853 check-compile-commands
5cf0da6… stephan 854 } else {
5cf0da6… stephan 855 puts "Use --compile-commands to enable check for compile-commands-capable compiler."
5cf0da6… stephan 856 }
35f3e5b… stephan 857 } else {
35f3e5b… stephan 858 puts "Disabling compile_commands.json check for out-of-tree build."
35f3e5b… stephan 859 # This is an attempt to resolve the problem reported at
35f3e5b… stephan 860 # https://fossil-scm.org/forum/forumpost/d19061d09a8179d0
35f3e5b… stephan 861 }
231d693… drh 862
231d693… drh 863 # Add -fsanitize compile and link options late: we don't want the C
231d693… drh 864 # checks above to run with those sanitizers enabled. It can not only
231d693… drh 865 # be pointless, it can actually break correct tests.
231d693… drh 866 set fsan [opt-val with-sanitizer]
231d693… drh 867 if {[string length $fsan]} {
a76b48c… stephan 868 define-append EXTRA_CFLAGS -fsanitize=$fsan
a76b48c… stephan 869 define-append EXTRA_LDFLAGS -fsanitize=$fsan
a76b48c… stephan 870 if {[string first "undefined" $fsan] != -1} {
a76b48c… stephan 871 # We need to link with libubsan if we're compiling under
a76b48c… stephan 872 # GCC with -fsanitize=undefined.
a76b48c… stephan 873 cc-check-function-in-lib __ubsan_handle_add_overflow ubsan
a76b48c… stephan 874 }
a76b48c… stephan 875 }
a3843d4… stephan 876
a3843d4… stephan 877 ########################################################################
a3843d4… stephan 878 # @proj-check-emsdk
a3843d4… stephan 879 #
a3843d4… stephan 880 # Emscripten is used for doing in-tree builds of web-based WASM stuff,
a3843d4… stephan 881 # as opposed to WASI-based WASM or WASM binaries we import from other
a3843d4… stephan 882 # places. This is only set up for Unix-style OSes and is untested
a3843d4… stephan 883 # anywhere but Linux. Requires that the --with-emsdk flag be
a3843d4… stephan 884 # registered with autosetup.
a3843d4… stephan 885 #
a3843d4… stephan 886 # It looks for the SDK in the location specified by --with-emsdk.
a3843d4… stephan 887 # Values of "" or "auto" mean to check for the environment var EMSDK
a3843d4… stephan 888 # (which gets set by the emsdk_env.sh script from the SDK) or that
a3843d4… stephan 889 # same var passed to configure.
a3843d4… stephan 890 #
a3843d4… stephan 891 # If the given directory is found, it expects to find emsdk_env.sh in
a3843d4… stephan 892 # that directory, as well as the emcc compiler somewhere under there.
a3843d4… stephan 893 #
a3843d4… stephan 894 # If the --with-emsdk flag is explicitly provided and the SDK is not
a3843d4… stephan 895 # found then a fatal error is generated, otherwise failure to find the
a3843d4… stephan 896 # SDK is not fatal.
a3843d4… stephan 897 #
a3843d4… stephan 898 # Defines the following:
a3843d4… stephan 899 #
a3843d4… stephan 900 # - EMSDK_HOME = top dir of the emsdk or "".
a3843d4… stephan 901 # - EMSDK_ENV_SH = path to EMSDK_HOME/emsdk_env.sh or ""
a3843d4… stephan 902 # - BIN_EMCC = $EMSDK_HOME/upstream/emscripten/emcc or ""
a3843d4… stephan 903 # - HAVE_EMSDK = 0 or 1 (this function's return value)
a3843d4… stephan 904 #
a3843d4… stephan 905 # Returns 1 if EMSDK_ENV_SH is found, else 0. If EMSDK_HOME is not empty
a3843d4… stephan 906 # but BIN_EMCC is then emcc was not found in the EMSDK_HOME, in which
a3843d4… stephan 907 # case we have to rely on the fact that sourcing $EMSDK_ENV_SH from a
a3843d4… stephan 908 # shell will add emcc to the $PATH.
a3843d4… stephan 909 proc proj-check-emsdk {} {
a3843d4… stephan 910 set emsdkHome [opt-val with-emsdk]
a3843d4… stephan 911 define EMSDK_HOME ""
a3843d4… stephan 912 define EMSDK_ENV_SH ""
a3843d4… stephan 913 define BIN_EMCC ""
a3843d4… stephan 914 set hadValue [llength $emsdkHome]
a3843d4… stephan 915 msg-checking "Emscripten SDK? "
a3843d4… stephan 916 if {$emsdkHome in {"" "auto"}} {
a3843d4… stephan 917 # Check the environment. $EMSDK gets set by sourcing emsdk_env.sh.
a3843d4… stephan 918 set emsdkHome [get-env EMSDK ""]
a3843d4… stephan 919 }
a3843d4… stephan 920 set rc 0
a3843d4… stephan 921 if {$emsdkHome ne ""} {
a3843d4… stephan 922 define EMSDK_HOME $emsdkHome
a3843d4… stephan 923 set emsdkEnv "$emsdkHome/emsdk_env.sh"
a3843d4… stephan 924 if {[file exists $emsdkEnv]} {
a3843d4… stephan 925 msg-result "$emsdkHome"
a3843d4… stephan 926 define EMSDK_ENV_SH $emsdkEnv
a3843d4… stephan 927 set rc 1
a3843d4… stephan 928 set emcc "$emsdkHome/upstream/emscripten/emcc"
a3843d4… stephan 929 if {[file exists $emcc]} {
a3843d4… stephan 930 define BIN_EMCC $emcc
a3843d4… stephan 931 }
a3843d4… stephan 932 } else {
a3843d4… stephan 933 msg-result "emsdk_env.sh not found in $emsdkHome"
a3843d4… stephan 934 }
a3843d4… stephan 935 } else {
a3843d4… stephan 936 msg-result "not found"
a3843d4… stephan 937 }
a3843d4… stephan 938 if {$hadValue && 0 == $rc} {
a3843d4… stephan 939 # Fail if it was explicitly requested but not found
a3843d4… stephan 940 proj-fatal "Cannot find the Emscripten SDK"
a3843d4… stephan 941 }
a3843d4… stephan 942 define HAVE_EMSDK $rc
a3843d4… stephan 943 return $rc
a3843d4… stephan 944 }
a3843d4… stephan 945
f99e07d… stephan 946 if {!$outOfTreeBuild && [proj-check-emsdk]} {
f99e07d… stephan 947 # Maintenance note: the WASM-related pieces are only for in-tree
f99e07d… stephan 948 # maintenance, not out-of-tree builds.
f99e07d… stephan 949 define EMCC_WRAPPER $::dirSrc/tools/emcc.sh
a3843d4… stephan 950 define EMCC_OPT [get-env EMCC_OPT "-Oz"]; # optional flags to pass to emcc
a3843d4… stephan 951 make-template tools/emcc.sh.in
f99e07d… stephan 952 catch {exec chmod u+x [get-define EMCC_WRAPPER]}
a3843d4… stephan 953 } else {
a3843d4… stephan 954 define EMCC_WRAPPER ""
a3843d4… stephan 955 define EMCC_OPT ""
af7475c… stephan 956 }
af7475c… stephan 957
af7475c… stephan 958 handle-with-openssl
ea2fbaf… stephan 959
ea2fbaf… stephan 960 # Finally, append libraries that must be last. This matters more on some
ea2fbaf… stephan 961 # OSes than others, but is most broadly required for static linking.
ea2fbaf… stephan 962 if {[opt-bool static]} {
ea2fbaf… stephan 963 # Linux can only infer the dependency on pthread from OpenSSL when
ea2fbaf… stephan 964 # doing dynamic linkage.
ea2fbaf… stephan 965 define-append LIBS -lpthread
ea2fbaf… stephan 966 }
8d3b9bf… drh 967
8d3b9bf… drh 968 apply {{} {
374e73c… stephan 969 # This started out as a workaround for getting the ordering of -ldl
374e73c… stephan 970 # correct in conjunction with openssl in some environments. Then it
374e73c… stephan 971 # evolved into a more generic preemptive portability workaround to
374e73c… stephan 972 # ensure that certain libraries are always appended to the global
374e73c… stephan 973 # LIBS list if they exist on the system. Based on a /chat discussion
374e73c… stephan 974 # on 2025-02-27 in the context of check-in [8d3b9bf4d4].
374e73c… stephan 975 #
374e73c… stephan 976 # Note that [move-lib-to-end] and [lib-actually-exists] are in
374e73c… stephan 977 # autosetup/local.tcl.
8d3b9bf… drh 978 set libs [get-define LIBS]
374e73c… stephan 979 #puts "**** 1 LIBS: $libs"
374e73c… stephan 980 foreach ll {-ldl -lpthread -lm} {
374e73c… stephan 981 if {![move-lib-to-end $ll $libs libs]} {
374e73c… stephan 982 # $ll was not in the list
374e73c… stephan 983 if {[lib-actually-exists $ll]} {
374e73c… stephan 984 # Add it to the list "just in case." This will be a no-op on
374e73c… stephan 985 # systems where the lib is not actually used.
374e73c… stephan 986 lappend libs $ll
374e73c… stephan 987 }
374e73c… stephan 988 }
374e73c… stephan 989 }
374e73c… stephan 990 #puts "**** 2 LIBS: $libs"
374e73c… stephan 991 define LIBS [join $libs " "]
8d3b9bf… drh 992 }}
b0c9c26… wyoung 993
b0c9c26… wyoung 994 # Tag container builds with a prefix of the checkin ID of the version
b0c9c26… wyoung 995 # of Fossil each one contains. This not only allows multiple images
b0c9c26… wyoung 996 # to coexist and multiple containers to be created unamgiguosly from
b0c9c26… wyoung 997 # them, it also changes the URL we fetch the source tarball from, so
b0c9c26… wyoung 998 # repeated builds of a given version generate and fetch the source
b0c9c26… wyoung 999 # tarball once only, keeping it in the local Docker/Podman cache.
7b9402f… stephan 1000 set ci [readfile "$::dirSrc/manifest.uuid"]
b0c9c26… wyoung 1001 define FOSSIL_CI_PFX [string range $ci 0 11]
75f0294… drh 1002
75f0294… drh 1003 make-template Makefile.in
f476744… drh 1004 make-config-header autoconfig.h -auto {USE_* FOSSIL_*}

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button