Artifact Content

Artifact 278643200522a7be44c1d4d1ae17587b8309f531:

# System autoconfiguration. Try: ./configure --help

use cc cc-lib

options {
                         => {Look for openssl in the given path, or auto or none}
    with-zlib:path       => {Look for zlib in the given path}
    with-tcl:path        => {Enable Tcl integration, with Tcl in the specified path}
    internal-sqlite=1    => {Don't use the internal sqlite, use the system one}
    static=0             => {Link a static executable}
    lineedit=1           => {Disable line editing}
    fossil-debug=0       => {Build with fossil debugging enabled}
    ipv6=1		 => {Disable IPv6 support}
    json=0        => {Build with fossil JSON API enabled}

# sqlite wants these types if possible
cc-with {-includes {stdint.h inttypes.h}} {
    cc-check-types uint32_t uint16_t int16_t uint8_t

# Use pread/pwrite system calls in place of seek + read/write if possible
define USE_PREAD [cc-check-functions pread]

# Find tclsh for the test suite. Can't yet use jimsh for this.
cc-check-progs tclsh

define EXTRA_CFLAGS ""

if {![opt-bool internal-sqlite]} {
  proc find_internal_sqlite {} {

    # On some systems (slackware), libsqlite3 requires -ldl to link. So
    # search for the system SQLite once with -ldl, and once without. If
    # the library can only be found with $extralibs set to -ldl, then 
    # the code below will append -ldl to LIBS.
    foreach extralibs {{} {-ldl}} {

      # Locate the system SQLite by searching for sqlite3_open(). Then check
      # if sqlite3_wal_checkpoint() can be found as well. If we can find
      # open() but not wal_checkpoint(), then the system SQLite is too old
      # to link against fossil.
      if {[cc-check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
        if {![cc-check-function-in-lib sqlite3_wal_checkpoint sqlite3 $extralibs]} {
          user-error "system sqlite3 too old (require >= 3.7.0)"

        # Success. Update symbols and return.
        define USE_SYSTEM_SQLITE 1
        define-append LIBS $extralibs
    user-error "system sqlite3 not found"


if {[opt-bool fossil-debug]} {

if {[opt-bool json]} {

if {[opt-bool static]} {
    # XXX: This will not work on all systems.
    define-append EXTRA_LDFLAGS -static

if {[opt-bool ipv6]} {
   define-append EXTRA_CFLAGS -DWITH_IPV6
   msg-result "IPv6 support enabled"
   if {[cc-check-functions getaddrinfo]} {
      msg-result "getaddrinfo() enabled"

# Check for zlib, using the given location if specified
set zlibpath [opt-val with-zlib]
if {$zlibpath ne ""} {
    cc-with [list -cflags "-I$zlibpath -L$zlibpath"]
    define-append EXTRA_CFLAGS -I$zlibpath
    define-append EXTRA_LDFLAGS -L$zlibpath
if {![cc-check-includes zlib.h] || ![cc-check-function-in-lib inflateEnd z]} {
    user-error "zlib not found please install it or specify the location with --with-zlib"

set tclpath [opt-val with-tcl]
if {$tclpath ne ""} {
	# Note parse-tclconfig-sh is in autosetup/local.tcl
    if {$tclpath eq "1"} {
        # Use the system Tcl. Look in some likely places.
        array set tclconfig [parse-tclconfig-sh /usr /usr/local /usr/share /opt/local]
		set msg "on your system"
	} else {
        array set tclconfig [parse-tclconfig-sh $tclpath]
		set msg "at $tclpath"
	if {![info exists tclconfig(TCL_INCLUDE_SPEC)]} {
		user-error "Cannot find Tcl $msg"
	set cflags $tclconfig(TCL_INCLUDE_SPEC)
	set libs "$tclconfig(TCL_LIB_SPEC) $tclconfig(TCL_LIBS)"
	cc-with [list -cflags $cflags -libs $libs] {
		if {![cc-check-functions Tcl_CreateInterp]} {
			user-error "Cannot find a usable Tcl $msg"
	set version $tclconfig(TCL_VERSION)$tclconfig(TCL_PATCH_LEVEL)
	msg-result "Found Tcl $version at $tclconfig(TCL_PREFIX)"
	define-append LIBS $libs
	define-append EXTRA_CFLAGS $cflags
	define-append EXTRA_LDFLAGS $tclconfig(TCL_LD_FLAGS)


# Helper for openssl checking
proc check-for-openssl {msg {cflags {}}} {
    msg-checking "Checking for $msg..."
    set rc 0
    msg-quiet cc-with [list -cflags $cflags -libs {-lssl -lcrypto}] {
        if {[cc-check-includes openssl/ssl.h] && [cc-check-functions SSL_new]} {
            incr rc
    if {$rc} {
        msg-result "ok"
        return 1
    } else {
        msg-result "no"
        return 0

set ssldirs [opt-val with-openssl]
if {$ssldirs ne "none"} {
    set found 0
    if {$ssldirs in {auto ""}} {
        catch {
            set cflags [exec pkg-config openssl --cflags-only-I]
            set ldflags [exec pkg-config openssl --libs-only-L]

            set found [check-for-openssl "ssl via pkg-config" "$cflags $ldflags"]
        } msg
        if {!$found} {
            set ssldirs "{} /usr/sfw /usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr"
    if {!$found} {
        foreach dir $ssldirs {
            if {$dir eq ""} {
                set msg "system ssl"
                set cflags ""
                set ldflags ""
            } else {
                set msg "ssl in $dir"
                set cflags "-I$dir/include"
                set ldflags "-L$dir/lib"
            if {[check-for-openssl $msg "$cflags $ldflags"]} {
                incr found
    if {$found} {
        define FOSSIL_ENABLE_SSL
        define-append EXTRA_CFLAGS $cflags
        define-append EXTRA_LDFLAGS $ldflags
        define-append LIBS -lssl -lcrypto
        msg-result "HTTP support enabled"

        # Silence OpenSSL deprecation warnings on Mac OS X 10.7.
        if {[string match *-darwin* [get-define host]]} {
            if {[cctest -cflags {-Wdeprecated-declarations}]} {
                define-append EXTRA_CFLAGS -Wdeprecated-declarations
    } else {
        user-error "OpenSSL not found. Consider --with-openssl=none to disable HTTPS support"

if {[opt-bool lineedit]} {
    # Need readline-compatible line editing
    cc-with {-includes stdio.h} {
        if {[cc-check-includes readline/readline.h] && [cc-check-function-in-lib readline readline]} {
            msg-result "Using readline for line editing"
        } elseif {[cc-check-includes editline/readline.h] && [cc-check-function-in-lib readline edit]} {
            define-feature editline
            msg-result "Using editline for line editing"

# Network functions require libraries on some systems
cc-check-function-in-lib gethostbyname nsl
if {![cc-check-function-in-lib socket {socket network}]} {
    # Last resort, may be Windows
    if {[string match *mingw* [get-define host]]} {
        define-append LIBS -lwsock32

# Check for getpassphrase() for Solaris 10 where getpass() truncates to 10 chars
if {![cc-check-functions getpassphrase]} {
    # Haiku needs this
    cc-check-function-in-lib getpass bsd

make-config-header autoconfig.h -auto {USE_* FOSSIL_*}