Fossil SCM

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

Keyboard Shortcuts

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