Fossil

Check-in [74d65bab]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Merge trunk with ben-testing
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | ben-testing
Files: files | file ages | folders
SHA1: 74d65bab28c8c27ba544df42a16c84342bc7b4d2
User & Date: ben 2011-07-20 08:29:21
Context
2011-07-20
08:37
Merge working directory relative file listings for changes and extras commands into ben-testing. check-in: 8320393b user: ben tags: ben-testing
08:29
Merge trunk with ben-testing check-in: 74d65bab user: ben tags: ben-testing
2011-07-19
23:29
Allow the root of a check-out to be in the root of the filesystem. Ticket [675f36eac4902cf] check-in: b317471d user: drh tags: trunk
2011-06-18
17:00
Merge latest changes from trunk check-in: 7bbeb882 user: ben tags: ben-testing
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to BUILD.txt.

     1         -All of the source code for fossil is contained in the src/ subdirectory.
     2         -But there is a lot of generated code, so you will probably want to
     3         -use the Makefile.  To do a complete build on unix, just type:
            1  +To do a complete build on most unix systems, just type:
     4      2   
     5      3      make
            4  +
            5  +If you have an unusual unix system for which the standard Makefile
            6  +will not work, or if you want to do some non-standard options, you can
            7  +also run:
            8  +
            9  +   ./configure; make
           10  +
           11  +The ./configure script builds GNUmakefile which will be used in place
           12  +of Makefile.  Run "./configure --help" for a listing of the available
           13  +options.
     6     14   
     7     15   On a windows box, use one of the Makefiles in the win/ subdirectory,
     8         -according to your compiler and environment.  For example:
           16  +according to your compiler and environment.  If you have GCC and MSYS
           17  +installed on your system, the consider:
     9     18   
    10         -   make -f win/Makefile.w32
           19  +   make -f win/Makefile.mingw
           20  +
           21  +If you have VC++ installed on your system, then consider:
           22  +
           23  +   cd win; nmake /f Makefile.msc
    11     24   
    12     25   If you have trouble, or you want to do something fancy, just look at
    13     26   top level makefile. There are 6 configuration options that are all well
    14     27   commented. Instead of editing the Makefile, consider copying the Makefile
    15     28   to an alternative name such as "GNUMakefile", "BSDMakefile", or "makefile"
    16     29   and editing the copy.
    17     30   

Added GNUmakefile.in.

            1  +#!/usr/bin/make
            2  +#
            3  +# This is the top-level makefile for Fossil when the build is occurring
            4  +# on a unix platform.  This works out-of-the-box on most unix platforms.
            5  +# But you are free to vary some of the definitions if desired.
            6  +#
            7  +#### The toplevel directory of the source tree.  Fossil can be built
            8  +#    in a directory that is separate from the source tree.  Just change
            9  +#    the following to point from the build directory to the src/ folder.
           10  +#
           11  +SRCDIR = @srcdir@/src
           12  +
           13  +#### The directory into which object code files should be written.
           14  +#
           15  +#
           16  +OBJDIR = ./bld
           17  +
           18  +#### C Compiler and options for use in building executables that
           19  +#    will run on the platform that is doing the build.  This is used
           20  +#    to compile code-generator programs as part of the build process.
           21  +#    See TCC below for the C compiler for building the finished binary.
           22  +#
           23  +BCC = @CC_FOR_BUILD@
           24  +
           25  +#### The suffix to add to final executable file.  When cross-compiling
           26  +#    to windows, make this ".exe".  Otherwise leave it blank.
           27  +#
           28  +E = @EXEEXT@
           29  +
           30  +TCC = @CC@
           31  +
           32  +#### Tcl shell for use in running the fossil testsuite.  If you do not
           33  +#    care about testing the end result, this can be blank.
           34  +#
           35  +TCLSH = tclsh
           36  +
           37  +LIB =	@LDFLAGS@ @EXTRA_LDFLAGS@ @LIBS@
           38  +TCC +=	@EXTRA_CFLAGS@ @CPPFLAGS@ @CFLAGS@ -DHAVE_AUTOCONFIG_H
           39  +INSTALLDIR = $(DESTDIR)@prefix@/bin
           40  +USE_SYSTEM_SQLITE = @USE_SYSTEM_SQLITE@
           41  +
           42  +include $(SRCDIR)/main.mk
           43  +
           44  +distclean: clean
           45  +	rm -f autoconfig.h config.log GNUmakefile

Changes to VERSION.

     1         -1.18
            1  +1.19

Added auto.def.

            1  +# System autoconfiguration. Try: ./configure --help
            2  +
            3  +use cc cc-lib
            4  +
            5  +options {
            6  +    with-openssl:path|auto|none
            7  +                         => {Look for openssl in the given path, or auto or none}
            8  +    with-zlib:path       => {Look for zlib in the given path}
            9  +    internal-sqlite=1    => {Don't use the internal sqlite, use the system one}
           10  +    static=0             => {Link a static executable}
           11  +    lineedit=1           => {Disable line editing}
           12  +    fossil-debug=0       => {Build with fossil debugging enabled}
           13  +}
           14  +
           15  +# sqlite wants these types if possible
           16  +cc-with {-includes {stdint.h inttypes.h}} {
           17  +    cc-check-types uint32_t uint16_t int16_t uint8_t
           18  +}
           19  +
           20  +# Use pread/pwrite system calls in place of seek + read/write if possible
           21  +define USE_PREAD [cc-check-functions pread]
           22  +
           23  +# Find tclsh for the test suite. Can't yet use jimsh for this.
           24  +cc-check-progs tclsh
           25  +
           26  +define EXTRA_CFLAGS ""
           27  +define EXTRA_LDFLAGS ""
           28  +define USE_SYSTEM_SQLITE ""
           29  +
           30  +if {![opt-bool internal-sqlite]} {
           31  +  proc find_internal_sqlite {} {
           32  +
           33  +    # On some systems (slackware), libsqlite3 requires -ldl to link. So
           34  +    # search for the system SQLite once with -ldl, and once without. If
           35  +    # the library can only be found with $extralibs set to -ldl, then 
           36  +    # the code below will append -ldl to LIBS.
           37  +    #
           38  +    foreach extralibs {{} {-ldl}} {
           39  +
           40  +      # Locate the system SQLite by searching for sqlite3_open(). Then check
           41  +      # if sqlite3_wal_checkpoint() can be found as well. If we can find
           42  +      # open() but not wal_checkpoint(), then the system SQLite is too old
           43  +      # to link against fossil.
           44  +      #
           45  +      if {[cc-check-function-in-lib sqlite3_open sqlite3 $extralibs]} {
           46  +        if {![cc-check-function-in-lib sqlite3_wal_checkpoint sqlite3 $extralibs]} {
           47  +          user-error "system sqlite3 too old (require >= 3.7.0)"
           48  +        }
           49  +
           50  +        # Success. Update symbols and return.
           51  +        #
           52  +        define USE_SYSTEM_SQLITE 1
           53  +        define-append LIBS $extralibs
           54  +        return
           55  +      }
           56  +    }
           57  +    user-error "system sqlite3 not found"
           58  +  }
           59  +
           60  +  find_internal_sqlite
           61  +}
           62  +
           63  +if {[opt-bool fossil-debug]} {
           64  +    define-append EXTRA_CFLAGS -DFOSSIL_DEBUG
           65  +}
           66  +
           67  +if {[opt-bool static]} {
           68  +    # XXX: This will not work on all systems.
           69  +    define-append EXTRA_LDFLAGS -static
           70  +}
           71  +
           72  +
           73  +# Check for zlib, using the given location if specified
           74  +set zlibpath [opt-val with-zlib]
           75  +if {$zlibpath ne ""} {
           76  +    cc-with [list -cflags "-I$zlibpath -L$zlibpath"]
           77  +    define-append EXTRA_CFLAGS -I$zlibpath
           78  +    define-append EXTRA_LDFLAGS -L$zlibpath
           79  +}
           80  +if {![cc-check-includes zlib.h] || ![cc-check-function-in-lib inflateEnd z]} {
           81  +    user-error "zlib not found please install it or specify the location with --with-zlib"
           82  +}
           83  +
           84  +# Helper for openssl checking
           85  +proc check-for-openssl {msg {cflags {}}} {
           86  +    msg-checking "Checking for $msg..."
           87  +    set rc 0
           88  +    msg-quiet cc-with [list -cflags $cflags -libs {-lssl -lcrypto}] {
           89  +        if {[cc-check-includes openssl/ssl.h] && [cc-check-functions SSL_new]} {
           90  +            incr rc
           91  +        }
           92  +    }
           93  +    if {$rc} {
           94  +        msg-result "ok"
           95  +        return 1
           96  +    } else {
           97  +        msg-result "no"
           98  +        return 0
           99  +    }
          100  +}
          101  +
          102  +set ssldirs [opt-val with-openssl]
          103  +if {$ssldirs ne "none"} {
          104  +    set found 0
          105  +    if {$ssldirs in {auto ""}} {
          106  +        catch {
          107  +            set cflags [exec pkg-config openssl --cflags-only-I]
          108  +            set ldflags [exec pkg-config openssl --libs-only-L]
          109  +
          110  +            set found [check-for-openssl "ssl via pkg-config" "$cflags $ldflags"]
          111  +        } msg
          112  +        if {!$found} {
          113  +            set ssldirs "{} /usr/sfw /usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr"
          114  +        }
          115  +    }
          116  +    if {!$found} {
          117  +        foreach dir $ssldirs {
          118  +            if {$dir eq ""} {
          119  +                set msg "system ssl"
          120  +                set cflags ""
          121  +                set ldflags ""
          122  +            } else {
          123  +                set msg "ssl in $dir"
          124  +                set cflags "-I$dir/include"
          125  +                set ldflags "-L$dir/include"
          126  +            }
          127  +            if {[check-for-openssl $msg "$cflags $ldflags"]} {
          128  +                incr found
          129  +                break
          130  +            }
          131  +        }
          132  +    }
          133  +    if {$found} {
          134  +        define FOSSIL_ENABLE_SSL
          135  +        define-append EXTRA_CFLAGS $cflags
          136  +        define-append EXTRA_LDFLAGS $ldflags
          137  +        define-append LIBS -lssl -lcrypto
          138  +        msg-result "HTTP support enabled"
          139  +    } else {
          140  +        user-error "OpenSSL not found. Consider --with-openssl=none to disable HTTPS support"
          141  +    }
          142  +}
          143  +
          144  +if {[opt-bool lineedit]} {
          145  +    # Need readline-compatible line editing
          146  +    cc-with {-includes stdio.h} {
          147  +        if {[cc-check-includes readline/readline.h] && [cc-check-function-in-lib readline readline]} {
          148  +            msg-result "Using readline for line editing"
          149  +        } elseif {[cc-check-includes editline/readline.h] && [cc-check-function-in-lib readline edit]} {
          150  +            define-feature editline
          151  +            msg-result "Using editline for line editing"
          152  +        }
          153  +    }
          154  +}
          155  +
          156  +# Network functions require libraries on some systems
          157  +cc-check-function-in-lib gethostbyname nsl
          158  +if {![cc-check-function-in-lib socket {socket network}]} {
          159  +    # Last resort, may be Windows
          160  +    if {[string match *mingw* [get-define host]]} {
          161  +        define-append LIBS -lwsock32
          162  +    }
          163  +}
          164  +
          165  +# Check for getpassphrase() for Solaris 10 where getpass() truncates to 10 chars
          166  +if {![cc-check-functions getpassphrase]} {
          167  +    # Haiku needs this
          168  +    cc-check-function-in-lib getpass bsd
          169  +}
          170  +
          171  +make-template GNUmakefile.in
          172  +make-config-header autoconfig.h -auto {USE_* FOSSIL_*}

Added autosetup/LICENSE.

            1  +Unless explicitly stated, all files which form part of autosetup
            2  +are released under the following license:
            3  +
            4  +---------------------------------------------------------------------
            5  +autosetup - A build environment "autoconfigurator"
            6  +
            7  +Copyright (c) 2010-2011, WorkWare Systems <http://workware.net.au/>
            8  +
            9  +Redistribution and use in source and binary forms, with or without
           10  +modification, are permitted provided that the following conditions
           11  +are met:
           12  +
           13  +1. Redistributions of source code must retain the above copyright
           14  +   notice, this list of conditions and the following disclaimer.
           15  +2. Redistributions in binary form must reproduce the above
           16  +   copyright notice, this list of conditions and the following
           17  +   disclaimer in the documentation and/or other materials
           18  +   provided with the distribution.
           19  +
           20  +THIS SOFTWARE IS PROVIDED BY THE WORKWARE SYSTEMS ``AS IS'' AND ANY
           21  +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
           22  +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
           23  +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WORKWARE
           24  +SYSTEMS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
           25  +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
           26  +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
           27  +OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
           28  +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
           29  +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
           30  +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
           31  +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
           32  +
           33  +The views and conclusions contained in the software and documentation
           34  +are those of the authors and should not be interpreted as representing
           35  +official policies, either expressed or implied, of WorkWare Systems.

Added autosetup/README.autosetup.

            1  +This is autosetup v0.6.2. See http://msteveb.github.com/autosetup/

Added autosetup/autosetup.

            1  +#!/bin/sh
            2  +# Copyright (c) 2006-2010 WorkWare Systems http://www.workware.net.au/
            3  +# All rights reserved
            4  +# vim:se syntax=tcl:
            5  +# \
            6  +dir=`dirname "$0"`; exec `"$dir/find-tclsh" || echo false` "$0" "$@"
            7  +
            8  +set autosetup(version) 0.6.2
            9  +
           10  +# Can be set to 1 to debug early-init problems
           11  +set autosetup(debug) 0
           12  +
           13  +##################################################################
           14  +#
           15  +# Main flow of control, option handling
           16  +#
           17  +proc main {argv} {
           18  +	global autosetup define
           19  +
           20  +	# There are 3 potential directories involved:
           21  +	# 1. The directory containing autosetup (this script)
           22  +	# 2. The directory containing auto.def
           23  +	# 3. The current directory
           24  +
           25  +	# From this we need to determine:
           26  +	# a. The path to this script (and related support files)
           27  +	# b. The path to auto.def
           28  +	# c. The build directory, where output files are created
           29  +
           30  +	# This is also complicated by the fact that autosetup may
           31  +	# have been run via the configure wrapper ([getenv WRAPPER] is set)
           32  +
           33  +	# Here are the rules.
           34  +	# a. This script is $::argv0
           35  +	#    => dir, prog, exe, libdir
           36  +	# b. auto.def is in the directory containing the configure wrapper,
           37  +	#    otherwise it is in the current directory.
           38  +	#    => srcdir, autodef
           39  +	# c. The build directory is the current directory
           40  +	#    => builddir, [pwd]
           41  +
           42  +	# 'misc' is needed before we can do anything, so set a temporary libdir
           43  +	# in case this is the development version
           44  +	set autosetup(libdir) [file dirname $::argv0]/lib
           45  +	use misc
           46  +
           47  +	# (a)
           48  +	set autosetup(dir) [realdir [file dirname [realpath $::argv0]]]
           49  +	set autosetup(prog) [file join $autosetup(dir) [file tail $::argv0]]
           50  +	set autosetup(exe) [getenv WRAPPER $autosetup(prog)]
           51  +	if {$autosetup(installed)} {
           52  +		set autosetup(libdir) $autosetup(dir)
           53  +	} else {
           54  +		set autosetup(libdir) [file join $autosetup(dir) lib]
           55  +	}
           56  +	autosetup_add_dep $autosetup(prog)
           57  +
           58  +	# (b)
           59  +	if {[getenv WRAPPER ""] eq ""} {
           60  +		# Invoked directly
           61  +		set autosetup(srcdir) [pwd]
           62  +	} else {
           63  +		# Invoked via the configure wrapper
           64  +		set autosetup(srcdir) [file dirname $autosetup(exe)]
           65  +	}
           66  +	set autosetup(autodef) [relative-path $autosetup(srcdir)/auto.def]
           67  +
           68  +	# (c)
           69  +	set autosetup(builddir) [pwd]
           70  +
           71  +	set autosetup(argv) $argv
           72  +	set autosetup(cmdline) {}
           73  +	set autosetup(options) {}
           74  +	set autosetup(optionhelp) {}
           75  +	set autosetup(showhelp) 0
           76  +
           77  +	# Parse options
           78  +	use getopt
           79  +
           80  +	array set ::useropts [getopt argv]
           81  +
           82  +	#"=Core Options:"
           83  +	options-add {
           84  +		help:=local  => "display help and options. Optionally specify a module name, such as --help=system"
           85  +		version      => "display the version of autosetup"
           86  +		ref:=text manual:=text
           87  +		reference:=text => "display the autosetup command reference. 'text', 'wiki', 'asciidoc' or 'markdown'"
           88  +		debug        => "display debugging output as autosetup runs"
           89  +		install      => "install autosetup to the current directory (in the 'autosetup/' subdirectory)"
           90  +		force init   => "create an initial 'configure' script if none exists"
           91  +		# Undocumented options
           92  +		option-checking=1
           93  +		nopager
           94  +		quiet
           95  +		timing
           96  +		conf:
           97  +	}
           98  +
           99  +	#parray ::useropts
          100  +	if {[opt-bool version]} {
          101  +		puts $autosetup(version)
          102  +		exit 0
          103  +	}
          104  +
          105  +	# autosetup --conf=alternate-auto.def
          106  +	if {[opt-val conf] ne ""} {
          107  +		set autosetup(autodef) [opt-val conf]
          108  +	}
          109  +
          110  +	# Debugging output (set this early)
          111  +	incr autosetup(debug) [opt-bool debug]
          112  +	incr autosetup(force) [opt-bool force]
          113  +	incr autosetup(msg-quiet) [opt-bool quiet]
          114  +	incr autosetup(msg-timing) [opt-bool timing]
          115  +
          116  +	# If the local module exists, source it now to allow for
          117  +	# project-local customisations
          118  +	if {[file exists $autosetup(libdir)/local.tcl]} {
          119  +		use local
          120  +	}
          121  +
          122  +	if {[opt-val help] ne ""} {
          123  +		incr autosetup(showhelp)
          124  +		use help
          125  +		autosetup_help [opt-val help]
          126  +	}
          127  +
          128  +	if {[opt-val {manual ref reference}] ne ""} {
          129  +		use help
          130  +		autosetup_reference [opt-val {manual ref reference}]
          131  +	}
          132  +
          133  +	if {[opt-bool init]} {
          134  +		use init
          135  +		autosetup_init
          136  +	}
          137  +
          138  +	if {[opt-bool install]} {
          139  +		use install
          140  +		autosetup_install
          141  +	}
          142  +
          143  +	if {![file exists $autosetup(autodef)]} {
          144  +		# Check for invalid option first
          145  +		options {}
          146  +		user-error "No auto.def found in $autosetup(srcdir)"
          147  +	}
          148  +
          149  +	# Parse extra arguments into autosetup(cmdline)
          150  +	foreach arg $argv {
          151  +		if {[regexp {([^=]*)=(.*)} $arg -> n v]} {
          152  +			dict set autosetup(cmdline) $n $v
          153  +			define $n $v
          154  +		} else {
          155  +			user-error "Unexpected parameter: $arg"
          156  +		}
          157  +	}
          158  +
          159  +	autosetup_add_dep $autosetup(autodef)
          160  +
          161  +	set cmd [file-normalize $autosetup(exe)]
          162  +	foreach arg $autosetup(argv) {
          163  +		append cmd " [quote-if-needed $arg]"
          164  +	}
          165  +	define AUTOREMAKE $cmd
          166  +
          167  +	# Log how we were invoked
          168  +	configlog "Invoked as: [getenv WRAPPER $::argv0] [quote-argv $autosetup(argv)]"
          169  +
          170  +	source $autosetup(autodef)
          171  +
          172  +	# Could warn here if options {} was not specified
          173  +
          174  +	show-notices
          175  +
          176  +	if {$autosetup(debug)} {
          177  +		parray define
          178  +	}
          179  +
          180  +	exit 0
          181  +}
          182  +
          183  +# @opt-bool option ...
          184  +#
          185  +# Check each of the named, boolean options and return 1 if any of them have
          186  +# been set by the user.
          187  +# 
          188  +proc opt-bool {args} {
          189  +	option-check-names {*}$args
          190  +	opt_bool ::useropts {*}$args
          191  +}
          192  +
          193  +# @opt-val option-list ?default=""?
          194  +#
          195  +# Returns a list containing all the values given for the non-boolean options in 'option-list'.
          196  +# There will be one entry in the list for each option given by the user, including if the
          197  +# same option was used multiple times.
          198  +# If only a single value is required, use something like:
          199  +#
          200  +## lindex [opt-val $names] end
          201  +#
          202  +# If no options were set, $default is returned (exactly, not as a list).
          203  +# 
          204  +proc opt-val {names {default ""}} {
          205  +	option-check-names {*}$names
          206  +	join [opt_val ::useropts $names $default]
          207  +}
          208  +
          209  +proc option-check-names {args} {
          210  +	foreach o $args {
          211  +		if {$o ni $::autosetup(options)} {
          212  +			autosetup-error "Request for undeclared option --$o"
          213  +		}
          214  +	}
          215  +}
          216  +
          217  +# Parse the option definition in $opts and update
          218  +# ::useropts() and ::autosetup(optionhelp) appropriately
          219  +#
          220  +proc options-add {opts {header ""}} {
          221  +	global useropts autosetup
          222  +
          223  +	# First weed out comment lines
          224  +	set realopts {}
          225  +	foreach line [split $opts \n] {
          226  +		if {![string match "#*" [string trimleft $line]]} {
          227  +			append realopts $line \n
          228  +		}
          229  +	}
          230  +	set opts $realopts
          231  +
          232  +	for {set i 0} {$i < [llength $opts]} {incr i} {
          233  +		set opt [lindex $opts $i]
          234  +		if {[string match =* $opt]} {
          235  +			# This is a special heading
          236  +			lappend autosetup(optionhelp) $opt ""
          237  +			set header {}
          238  +			continue
          239  +		}
          240  +
          241  +		#puts "i=$i, opt=$opt"
          242  +		regexp {^([^:=]*)(:)?(=)?(.*)$} $opt -> name colon equal value
          243  +		if {$name in $autosetup(options)} {
          244  +			autosetup-error "Option $name already specified"
          245  +		}
          246  +
          247  +		#puts "$opt => $name $colon $equal $value"
          248  +
          249  +		# Find the corresponding value in the user options
          250  +		# and set the default if necessary
          251  +		if {[string match "-*" $opt]} {
          252  +			# This is a documentation-only option, like "-C <dir>"
          253  +			set opthelp $opt
          254  +		} elseif {$colon eq ""} {
          255  +			# Boolean option
          256  +			lappend autosetup(options) $name
          257  +
          258  +			if {![info exists useropts($name)]} {
          259  +				set useropts($name) $value
          260  +			}
          261  +			if {$value eq "1"} {
          262  +				set opthelp "--disable-$name"
          263  +			} else {
          264  +				set opthelp "--$name"
          265  +			}
          266  +		} else {
          267  +			# String option.
          268  +			lappend autosetup(options) $name
          269  +
          270  +			if {$equal eq "="} {
          271  +				if {[info exists useropts($name)]} {
          272  +					# If the user specified the option with no value, the value will be "1"
          273  +					# Replace with the default
          274  +					if {$useropts($name) eq "1"} {
          275  +						set useropts($name) $value
          276  +					}
          277  +				}
          278  +				set opthelp "--$name?=$value?"
          279  +			} else {
          280  +				set opthelp "--$name=$value"
          281  +			}
          282  +		}
          283  +
          284  +		# Now create the help for this option if appropriate
          285  +		if {[lindex $opts $i+1] eq "=>"} {
          286  +			set desc [lindex $opts $i+2]
          287  +			#string match \n* $desc
          288  +			if {$header ne ""} {
          289  +				lappend autosetup(optionhelp) $header ""
          290  +				set header ""
          291  +			}
          292  +			# A multi-line description
          293  +			lappend autosetup(optionhelp) $opthelp $desc
          294  +			incr i 2
          295  +		}
          296  +	}
          297  +}
          298  +
          299  +# @module-options optionlist
          300  +#
          301  +# Like 'options', but used within a module.
          302  +proc module-options {opts} {
          303  +	set header ""
          304  +	if {$::autosetup(showhelp) > 1 && [llength $opts]} {
          305  +		set header "Module Options:"
          306  +	}
          307  +	options-add $opts $header
          308  +
          309  +	if {$::autosetup(showhelp)} {
          310  +		# Ensure that the module isn't executed on --help
          311  +		# We are running under eval or source, so use break
          312  +		# to prevent further execution
          313  +		#return -code break -level 2
          314  +		return -code break
          315  +	}
          316  +}
          317  +
          318  +proc max {a b} {
          319  +	expr {$a > $b ? $a : $b}
          320  +}
          321  +
          322  +proc options-wrap-desc {text length firstprefix nextprefix initial} {
          323  +	set len $initial
          324  +	set space $firstprefix
          325  +	foreach word [split $text] {
          326  +		set word [string trim $word]
          327  +		if {$word == ""} {
          328  +			continue
          329  +		}
          330  +		if {$len && [string length $space$word] + $len >= $length} {
          331  +			puts ""
          332  +			set len 0
          333  +			set space $nextprefix
          334  +		}
          335  +		incr len [string length $space$word]
          336  +		puts -nonewline $space$word
          337  +		set space " "
          338  +	}
          339  +	if {$len} {
          340  +		puts ""
          341  +	}
          342  +}
          343  +
          344  +proc options-show {} {
          345  +	# Determine the max option width
          346  +	set max 0
          347  +	foreach {opt desc} $::autosetup(optionhelp) {
          348  +		if {[string match =* $opt] || [string match \n* $desc]} {
          349  +			continue
          350  +		}
          351  +		set max [max $max [string length $opt]]
          352  +	}
          353  +	set indent [string repeat " " [expr $max+4]]
          354  +	set cols [getenv COLUMNS 80]
          355  +	catch {
          356  +		lassign [exec stty size] rows cols
          357  +	}
          358  +	incr cols -1
          359  +	# Now output
          360  +	foreach {opt desc} $::autosetup(optionhelp) {
          361  +		if {[string match =* $opt]} {
          362  +			puts [string range $opt 1 end]
          363  +			continue
          364  +		}
          365  +		puts -nonewline "  [format %-${max}s $opt]"
          366  +		if {[string match \n* $desc]} {
          367  +			puts $desc
          368  +		} else {
          369  +			options-wrap-desc [string trim $desc] $cols "  " $indent [expr $max + 2]
          370  +		}
          371  +	}
          372  +}
          373  +
          374  +# @options options-spec
          375  +#
          376  +# Specifies configuration-time options which may be selected by the user
          377  +# and checked with opt-val and opt-bool. The format of options-spec follows.
          378  +#
          379  +# A boolean option is of the form:
          380  +#
          381  +## name[=0|1]  => "Description of this boolean option"
          382  +#
          383  +# The default is name=0, meaning that the option is disabled by default.
          384  +# If name=1 is used to make the option enabled by default, the description should reflect
          385  +# that with text like "Disable support for ...".
          386  +#
          387  +# An argument option (one which takes a parameter) is of the form:
          388  +#
          389  +## name:[=]value  => "Description of this option"
          390  +#
          391  +# If the name:value form is used, the value must be provided with the option (as --name=myvalue).
          392  +# If the name:=value form is used, the value is optional and the given value is used as the default
          393  +# if is not provided.
          394  +#
          395  +# Undocumented options are also supported by omitting the "=> description.
          396  +# These options are not displayed with --help and can be useful for internal options or as aliases.
          397  +#
          398  +# For example, --disable-lfs is an alias for --disable=largefile:
          399  +#
          400  +## lfs=1 largefile=1 => "Disable large file support"
          401  +# 
          402  +proc options {optlist} {
          403  +	# Allow options as a list or args
          404  +	options-add $optlist "Local Options:"
          405  +
          406  +	if {$::autosetup(showhelp)} {
          407  +		options-show
          408  +		exit 0
          409  +	}
          410  +
          411  +	# Check for invalid options
          412  +	if {[opt-bool option-checking]} {
          413  +		foreach o [array names ::useropts] {
          414  +			if {$o ni $::autosetup(options)} {
          415  +				user-error "Unknown option --$o"
          416  +			}
          417  +		}
          418  +	}
          419  +}
          420  +
          421  +proc config_guess {} {
          422  +	if {[file-isexec $::autosetup(dir)/config.guess]} {
          423  +		exec-with-stderr sh $::autosetup(dir)/config.guess
          424  +	} else {
          425  +		configlog "No config.guess, so using uname"
          426  +		string tolower [exec uname -p]-unknown-[exec uname -s][exec uname -r]
          427  +	}
          428  +}
          429  +
          430  +proc config_sub {alias} {
          431  +	if {[file-isexec $::autosetup(dir)/config.sub]} {
          432  +		exec-with-stderr sh $::autosetup(dir)/config.sub $alias
          433  +	} else {
          434  +		return $alias
          435  +	}
          436  +}
          437  +
          438  +# @define name ?value=1?
          439  +# 
          440  +# Defines the named variable to the given value.
          441  +# These (name, value) pairs represent the results of the configuration check
          442  +# and are available to be checked, modified and substituted.
          443  +#
          444  +proc define {name {value 1}} {
          445  +	set ::define($name) $value
          446  +	#dputs "$name <= $value"
          447  +}
          448  +
          449  +# @define-append name value ...
          450  +#
          451  +# Appends the given value(s) to the given 'defined' variable.
          452  +# If the variable is not defined or empty, it is set to $value.
          453  +# Otherwise the value is appended, separated by a space.
          454  +# Any extra values are similarly appended.
          455  +# If any value is already contained in the variable (as a substring) it is omitted.
          456  +#
          457  +proc define-append {name args} {
          458  +	if {[get-define $name ""] ne ""} {
          459  +		# Make a token attempt to avoid duplicates
          460  +		foreach arg $args {
          461  +			if {[string first $arg $::define($name)] == -1} {
          462  +				append ::define($name) " " $arg
          463  +			}
          464  +		}
          465  +	} else {
          466  +		set ::define($name) [join $args]
          467  +	}
          468  +	#dputs "$name += [join $args] => $::define($name)"
          469  +}
          470  +
          471  +# @get-define name ?default=0?
          472  +#
          473  +# Returns the current value of the 'defined' variable, or $default
          474  +# if not set.
          475  +#
          476  +proc get-define {name {default 0}} {
          477  +	if {[info exists ::define($name)]} {
          478  +		#dputs "$name => $::define($name)"
          479  +		return $::define($name)
          480  +	}
          481  +	#dputs "$name => $default"
          482  +	return $default
          483  +}
          484  +
          485  +# @is-defined name
          486  +#
          487  +# Returns 1 if the given variable is defined.
          488  +#
          489  +proc is-defined {name} {
          490  +	info exists ::define($name)
          491  +}
          492  +
          493  +# @all-defines
          494  +#
          495  +# Returns a dictionary (name value list) of all defined variables.
          496  +#
          497  +# This is suitable for use with 'dict', 'array set' or 'foreach'
          498  +# and allows for arbitrary processing of the defined variables.
          499  +#
          500  +proc all-defines {} {
          501  +	array get ::define
          502  +}
          503  +
          504  +
          505  +# @get-env name default
          506  +#
          507  +# If $name was specified on the command line, return it.
          508  +# If $name was set in the environment, return it.
          509  +# Otherwise return $default.
          510  +#
          511  +proc get-env {name default} {
          512  +	if {[dict exists $::autosetup(cmdline) $name]} {
          513  +		return [dict get $::autosetup(cmdline) $name]
          514  +	}
          515  +	getenv $name $default
          516  +}
          517  +
          518  +# @env-is-set name
          519  +#
          520  +# Returns 1 if the $name was specified on the command line or in the environment.
          521  +#
          522  +proc env-is-set {name} {
          523  +	if {[dict exists $::autosetup(cmdline) $name]} {
          524  +		return 1
          525  +	}
          526  +	info exists ::env($name)
          527  +}
          528  +
          529  +# @readfile filename ?default=""?
          530  +#
          531  +# Return the contents of the file, without the trailing newline.
          532  +# If the doesn't exist or can't be read, returns $default.
          533  +#
          534  +proc readfile {filename {default_value ""}} {
          535  +	set result $default_value
          536  +	catch {
          537  +		set f [open $filename]
          538  +		set result [read -nonewline $f]
          539  +		close $f
          540  +	}
          541  +	return $result
          542  +}
          543  +
          544  +# @writefile filename value
          545  +#
          546  +# Creates the given file containing $value.
          547  +# Does not add an extra newline.
          548  +#
          549  +proc writefile {filename value} {
          550  +	set f [open $filename w]
          551  +	puts -nonewline $f $value
          552  +	close $f
          553  +}
          554  +
          555  +proc quote-if-needed {str} {
          556  +	if {[string match {*[\" ]*} $str]} {
          557  +		return \"[string map [list \" \\" \\ \\\\] $str]\"
          558  +	}
          559  +	return $str
          560  +}
          561  +
          562  +proc quote-argv {argv} {
          563  +	set args {}
          564  +	foreach arg $argv {
          565  +		lappend args [quote-if-needed $arg]
          566  +	}
          567  +	join $args
          568  +}
          569  +
          570  +# @find-executable name
          571  +#
          572  +# Searches the path for an executable with the given name.
          573  +# Note that the name may include some parameters, e.g. "cc -mbig-endian",
          574  +# in which case the parameters are ignored.
          575  +# Returns 1 if found, or 0 if not.
          576  +#
          577  +proc find-executable {name} {
          578  +	# Ignore any parameters
          579  +	set name [lindex $name 0]
          580  +	if {$name eq ""} {
          581  +		# The empty string is never a valid executable
          582  +		return 0
          583  +	}
          584  +	foreach p [split-path] {
          585  +		dputs "Looking for $name in $p"
          586  +		set exec [file join $p $name]
          587  +		if {[file-isexec $exec]} {
          588  +			dputs "Found $name -> $exec"
          589  +			return 1
          590  +		}
          591  +	}
          592  +	return 0
          593  +}
          594  +
          595  +# @find-an-executable ?-required? name ...
          596  +#
          597  +# Given a list of possible executable names,
          598  +# searches for one of these on the path.
          599  +#
          600  +# Returns the name found, or "" if none found.
          601  +# If the first parameter is '-required', an error is generated
          602  +# if no executable is found.
          603  +#
          604  +proc find-an-executable {args} {
          605  +	set required 0
          606  +	if {[lindex $args 0] eq "-required"} {
          607  +		set args [lrange $args 1 end]
          608  +		incr required
          609  +	}
          610  +	foreach name $args {
          611  +		if {[find-executable $name]} {
          612  +			return $name
          613  +		}
          614  +	}
          615  +	if {$required} {
          616  +		if {[llength $args] == 1} {
          617  +			user-error "failed to find: [join $args]"
          618  +		} else {
          619  +			user-error "failed to find one of: [join $args]"
          620  +		}
          621  +	}
          622  +	return ""
          623  +}
          624  +
          625  +# @configlog msg
          626  +#
          627  +# Writes the given message to the configuration log, config.log
          628  +#
          629  +proc configlog {msg} {
          630  +	if {![info exists ::autosetup(logfh)]} {
          631  +		set ::autosetup(logfh) [open config.log w]
          632  +	}
          633  +	puts $::autosetup(logfh) $msg
          634  +}
          635  +
          636  +# @msg-checking msg
          637  +#
          638  +# Writes the message with no newline to stdout.
          639  +#
          640  +proc msg-checking {msg} {
          641  +	if {$::autosetup(msg-quiet) == 0} {
          642  +		maybe-show-timestamp
          643  +		puts -nonewline $msg
          644  +		set ::autosetup(msg-checking) 1
          645  +	}
          646  +}
          647  +
          648  +# @msg-result msg
          649  +#
          650  +# Writes the message to stdout.
          651  +#
          652  +proc msg-result {msg} {
          653  +	if {$::autosetup(msg-quiet) == 0} {
          654  +		maybe-show-timestamp
          655  +		puts $msg
          656  +		set ::autosetup(msg-checking) 0
          657  +		show-notices
          658  +	}
          659  +}
          660  +
          661  +# @msg-quiet command ...
          662  +#
          663  +# msg-quiet evaluates it's arguments as a command with output
          664  +# from msg-checking and msg-result suppressed.
          665  +#
          666  +# This is useful if a check needs to run a subcheck which isn't
          667  +# of interest to the user.
          668  +proc msg-quiet {args} {
          669  +	incr ::autosetup(msg-quiet)
          670  +	set rc [uplevel 1 $args]
          671  +	incr ::autosetup(msg-quiet) -1
          672  +	return $rc
          673  +}
          674  +
          675  +# Will be overridden by 'use misc'
          676  +proc error-stacktrace {msg} {
          677  +	return $msg
          678  +}
          679  +
          680  +proc error-location {msg} {
          681  +	return $msg
          682  +}
          683  +
          684  +##################################################################
          685  +#
          686  +# Debugging output
          687  +#
          688  +proc dputs {msg} {
          689  +	if {$::autosetup(debug)} {
          690  +		puts $msg
          691  +	}
          692  +}
          693  +
          694  +##################################################################
          695  +#
          696  +# User and system warnings and errors
          697  +#
          698  +# Usage errors such as wrong command line options
          699  +
          700  +# @user-error msg
          701  +#
          702  +# Indicate incorrect usage to the user, including if required components
          703  +# or features are not found.
          704  +# autosetup exits with a non-zero return code.
          705  +#
          706  +proc user-error {msg} {
          707  +	show-notices
          708  +	puts stderr "Error: $msg"
          709  +	puts stderr "Try: '[file tail $::autosetup(exe)] --help' for options"
          710  +	exit 1
          711  +}
          712  +
          713  +# @user-notice msg
          714  +#
          715  +# Output the given message to stderr.
          716  +#
          717  +proc user-notice {msg} {
          718  +	lappend ::autosetup(notices) $msg
          719  +}
          720  +
          721  +# Incorrect usage in the auto.def file. Identify the location.
          722  +proc autosetup-error {msg} {
          723  +	show-notices
          724  +	puts stderr [error-location $msg]
          725  +	exit 1
          726  +}
          727  +
          728  +proc show-notices {} {
          729  +	if {$::autosetup(msg-checking)} {
          730  +		puts ""
          731  +		set ::autosetup(msg-checking) 0
          732  +	}
          733  +	flush stdout
          734  +	if {[info exists ::autosetup(notices)]} {
          735  +		puts stderr [join $::autosetup(notices) \n]
          736  +		unset ::autosetup(notices)
          737  +	}
          738  +}
          739  +
          740  +proc maybe-show-timestamp {} {
          741  +	if {$::autosetup(msg-timing) && $::autosetup(msg-checking) == 0} {
          742  +		puts -nonewline [format {[%6.2f] } [expr {([clock millis] - $::autosetup(start)) % 10000 / 1000.0}]]
          743  +	}
          744  +}
          745  +
          746  +proc autosetup_version {} {
          747  +	return "autosetup v$::autosetup(version)"
          748  +}
          749  +
          750  +##################################################################
          751  +#
          752  +# Directory/path handling
          753  +#
          754  +
          755  +proc realdir {dir} {
          756  +	set oldpwd [pwd]
          757  +	cd $dir
          758  +	set pwd [pwd]
          759  +	cd $oldpwd
          760  +	return $pwd
          761  +}
          762  +
          763  +# Follow symlinks until we get to something which is not a symlink
          764  +proc realpath {path} {
          765  +	while {1} {
          766  +		if {[catch {
          767  +			set path [file link $path]
          768  +		}]} {
          769  +			# Not a link
          770  +			break
          771  +		}
          772  +	}
          773  +	return $path
          774  +}
          775  +
          776  +# Convert absolute path, $path into a path relative
          777  +# to the given directory (or the current dir, if not given).
          778  +#
          779  +proc relative-path {path {pwd {}}} {
          780  +	set diff 0
          781  +	set same 0
          782  +	set newf {}
          783  +	set prefix {}
          784  +	set path [file-normalize $path]
          785  +	if {$pwd eq ""} {
          786  +		set pwd [pwd]
          787  +	} else {
          788  +		set pwd [file-normalize $pwd]
          789  +	}
          790  +
          791  +	if {$path eq $pwd} {
          792  +		return .
          793  +	}
          794  +
          795  +	# Try to make the filename relative to the current dir
          796  +	foreach p [split $pwd /] f [split $path /] {
          797  +		if {$p ne $f} {
          798  +			incr diff
          799  +		} elseif {!$diff} {
          800  +			incr same
          801  +		}
          802  +		if {$diff} {
          803  +			if {$p ne ""} {
          804  +				# Add .. for sibling or parent dir
          805  +				lappend prefix ..
          806  +			}
          807  +			if {$f ne ""} {
          808  +				lappend newf $f
          809  +			}
          810  +		}
          811  +	}
          812  +	if {$same == 1 || [llength $prefix] > 3} {
          813  +		return $path
          814  +	}
          815  +
          816  +	file join [join $prefix /] [join $newf /]
          817  +}
          818  +
          819  +# Add filename as a dependency to rerun autosetup
          820  +# The name will be normalised (converted to a full path)
          821  +#
          822  +proc autosetup_add_dep {filename} {
          823  +	lappend ::autosetup(deps) [file-normalize $filename]
          824  +}
          825  +
          826  +##################################################################
          827  +#
          828  +# Library module support
          829  +#
          830  +
          831  +# @use module ...
          832  +#
          833  +# Load the given library modules.
          834  +# e.g. use cc cc-shared
          835  +#
          836  +proc use {args} {
          837  +	foreach m $args {
          838  +		if {[info exists ::libmodule($m)]} {
          839  +			continue
          840  +		}
          841  +		set ::libmodule($m) 1
          842  +		if {[info exists ::modsource($m)]} {
          843  +			uplevel #0 eval $::modsource($m)
          844  +		} else {
          845  +			set source $::autosetup(libdir)/${m}.tcl
          846  +			if {[file exists $source]} {
          847  +				uplevel #0 [list source $source]
          848  +				autosetup_add_dep $source
          849  +			} else {
          850  +				puts "Looking for $source"
          851  +				autosetup-error "use: No such module: $m"
          852  +			}
          853  +		}
          854  +	}
          855  +}
          856  +
          857  +# Initial settings
          858  +set autosetup(exe) $::argv0
          859  +set autosetup(istcl) 1
          860  +set autosetup(start) [clock millis]
          861  +set autosetup(installed) 0
          862  +set autosetup(msg-checking) 0
          863  +set autosetup(msg-quiet) 0
          864  +
          865  +# Embedded modules are inserted below here
          866  +set autosetup(installed) 1
          867  +# ----- module asciidoc-formatting -----
          868  +
          869  +set modsource(asciidoc-formatting) {
          870  +# Copyright (c) 2010 WorkWare Systems http://www.workware.net.au/
          871  +# All rights reserved
          872  +
          873  +# Module which provides text formatting
          874  +# asciidoc format
          875  +
          876  +use formatting
          877  +
          878  +proc para {text} {
          879  +    regsub -all "\[ \t\n\]+" [string trim $text] " "
          880  +}
          881  +proc title {text} {
          882  +    underline [para $text] =
          883  +    nl
          884  +}
          885  +proc p {text} {
          886  +    puts [para $text]
          887  +    nl
          888  +}
          889  +proc code {text} {
          890  +    foreach line [parse_code_block $text] {
          891  +        puts "    $line"
          892  +    }
          893  +    nl
          894  +}
          895  +proc codelines {lines} {
          896  +    foreach line $lines {
          897  +        puts "    $line"
          898  +    }
          899  +    nl
          900  +}
          901  +proc nl {} {
          902  +    puts ""
          903  +}
          904  +proc underline {text char} {
          905  +    regexp "^(\[ \t\]*)(.*)" $text -> indent words
          906  +    puts $text
          907  +    puts $indent[string repeat $char [string length $words]]
          908  +}
          909  +proc section {text} {
          910  +    underline "[para $text]" -
          911  +    nl
          912  +}
          913  +proc subsection {text} {
          914  +    underline "$text" ~
          915  +    nl
          916  +}
          917  +proc bullet {text} {
          918  +    puts "* [para $text]"
          919  +}
          920  +proc indent {text} {
          921  +    puts " :: "
          922  +    puts [para $text]
          923  +}
          924  +proc defn {first args} {
          925  +    set sep ""
          926  +    if {$first ne ""} {
          927  +        puts "${first}::"
          928  +    } else {
          929  +        puts " :: "
          930  +    }
          931  +    set defn [string trim [join $args \n]]
          932  +    regsub -all "\n\n" $defn "\n ::\n" defn
          933  +    puts $defn
          934  +}
          935  +}
          936  +
          937  +# ----- module formatting -----
          938  +
          939  +set modsource(formatting) {
          940  +# Copyright (c) 2010 WorkWare Systems http://www.workware.net.au/
          941  +# All rights reserved
          942  +
          943  +# Module which provides common text formatting
          944  +
          945  +# This is designed for documenation which looks like:
          946  +# code {...}
          947  +# or
          948  +# code {
          949  +#    ...
          950  +#    ...
          951  +# }
          952  +# In the second case, we need to work out the indenting
          953  +# and strip it from all lines but preserve the remaining indenting.
          954  +# Note that all lines need to be indented with the same initial
          955  +# spaces/tabs.
          956  +#
          957  +# Returns a list of lines with the indenting removed.
          958  +#
          959  +proc parse_code_block {text} {
          960  +    # If the text begins with newline, take the following text,
          961  +    # otherwise just return the original
          962  +    if {![regexp "^\n(.*)" $text -> text]} {
          963  +        return [list [string trim $text]]
          964  +    }
          965  +
          966  +    # And trip spaces off the end
          967  +    set text [string trimright $text]
          968  +
          969  +    set min 100
          970  +    # Examine each line to determine the minimum indent
          971  +    foreach line [split $text \n] {
          972  +        if {$line eq ""} {
          973  +            # Ignore empty lines for the indent calculation
          974  +            continue
          975  +        }
          976  +        regexp "^(\[ \t\]*)" $line -> indent
          977  +        set len [string length $indent]
          978  +        if {$len < $min} {
          979  +            set min $len
          980  +        }
          981  +    }
          982  +
          983  +    # Now make a list of lines with this indent removed
          984  +    set lines {}
          985  +    foreach line [split $text \n] {
          986  +        lappend lines [string range $line $min end]
          987  +    }
          988  +
          989  +    # Return the result
          990  +    return $lines
          991  +}
          992  +}
          993  +
          994  +# ----- module getopt -----
          995  +
          996  +set modsource(getopt) {
          997  +# Copyright (c) 2006 WorkWare Systems http://www.workware.net.au/
          998  +# All rights reserved
          999  +
         1000  +# Simple getopt module
         1001  +
         1002  +# Parse everything out of the argv list which looks like an option
         1003  +# Knows about --enable-thing and --disable-thing as alternatives for --thing=0 or --thing=1
         1004  +proc getopt {argvname} {
         1005  +	upvar $argvname argv
         1006  +
         1007  +	for {set i 0} {$i < [llength $argv]} {incr i} {
         1008  +		set arg [lindex $argv $i]
         1009  +
         1010  +		#dputs arg=$arg
         1011  +
         1012  +		if {$arg eq "--"} {
         1013  +			# End of options
         1014  +			incr i
         1015  +			break
         1016  +		}
         1017  +
         1018  +		if {[regexp {^--([^=][^=]+)=(.*)$} $arg -> name value]} {
         1019  +			lappend opts($name) $value
         1020  +		} elseif {[regexp {^--(enable-|disable-)?([^=]*)$} $arg -> prefix name]} {
         1021  +			if {$prefix eq "disable-"} {
         1022  +				set value 0
         1023  +			} else {
         1024  +				set value 1
         1025  +			}
         1026  +			lappend opts($name) $value
         1027  +		} else {
         1028  +			break
         1029  +		}
         1030  +	}
         1031  +
         1032  +	#puts "getopt: argv=[join $argv] => [join [lrange $argv $i end]]"
         1033  +	#parray opts
         1034  +
         1035  +	set argv [lrange $argv $i end]
         1036  +
         1037  +	return [array get opts]
         1038  +}
         1039  +
         1040  +proc opt_val {optarrayname options {default {}}} {
         1041  +	upvar $optarrayname opts
         1042  +
         1043  +	set result {}
         1044  +
         1045  +	foreach o $options {
         1046  +		if {[info exists opts($o)]} {
         1047  +			lappend result {*}$opts($o)
         1048  +		}
         1049  +	}
         1050  +	if {[llength $result] == 0} {
         1051  +		return $default
         1052  +	}
         1053  +	return $result
         1054  +}
         1055  +
         1056  +proc opt_bool {optarrayname args} {
         1057  +	upvar $optarrayname opts
         1058  +
         1059  +	# Support the args being passed as a list
         1060  +	if {[llength $args] == 1} {
         1061  +		set args [lindex $args 0]
         1062  +	}
         1063  +
         1064  +	foreach o $args {
         1065  +		if {[info exists opts($o)]} {
         1066  +			if {"1" in $opts($o) || "yes" in $opts($o)} {
         1067  +				return 1
         1068  +			}
         1069  +		}
         1070  +	}
         1071  +	return 0
         1072  +}
         1073  +}
         1074  +
         1075  +# ----- module help -----
         1076  +
         1077  +set modsource(help) {
         1078  +# Copyright (c) 2010 WorkWare Systems http://workware.net.au/
         1079  +# All rights reserved
         1080  +
         1081  +# Module which provides usage, help and the command reference
         1082  +
         1083  +proc autosetup_help {what} {
         1084  +    use_pager
         1085  +
         1086  +    puts "Usage: [file tail $::autosetup(exe)] \[options\] \[settings\]\n"
         1087  +    puts "This is [autosetup_version], a build environment \"autoconfigurator\""
         1088  +    puts "See the documentation online at http://msteveb.github.com/autosetup/\n"
         1089  +
         1090  +    if {$what eq "local"} {
         1091  +        if {[file exists $::autosetup(autodef)]} {
         1092  +            # This relies on auto.def having a call to 'options'
         1093  +            # which will display options and quit
         1094  +            source $::autosetup(autodef)
         1095  +        } else {
         1096  +            options-show
         1097  +        }
         1098  +    } else {
         1099  +        incr ::autosetup(showhelp)
         1100  +        if {[catch {use $what}]} {
         1101  +            user-error "Unknown module: $what"
         1102  +        } else {
         1103  +            options-show
         1104  +        }
         1105  +    }
         1106  +    exit 0
         1107  +}
         1108  +
         1109  +# If not already paged and stdout is a tty, pipe the output through the pager
         1110  +# This is done by reinvoking autosetup with --nopager added
         1111  +proc use_pager {} {
         1112  +    if {![opt-bool nopager] && [getenv PAGER ""] ne "" && ![string match "not a tty" [exec tty]]} {
         1113  +        catch {
         1114  +            exec [info nameofexecutable] $::argv0 --nopager {*}$::argv | [getenv PAGER] >@stdout <@stdin 2>/dev/null
         1115  +        }
         1116  +        exit 0
         1117  +    }
         1118  +}
         1119  +
         1120  +# Outputs the autosetup references in one of several formats
         1121  +proc autosetup_reference {{type text}} {
         1122  +
         1123  +    use_pager
         1124  +
         1125  +    switch -glob -- $type {
         1126  +        wiki {use wiki-formatting}
         1127  +        ascii* {use asciidoc-formatting}
         1128  +        md - markdown {use markdown-formatting}
         1129  +        default {use text-formatting}
         1130  +    }
         1131  +
         1132  +    title "[autosetup_version] -- Command Reference"
         1133  +
         1134  +    section {Introduction}
         1135  +
         1136  +    p {
         1137  +        See http://msteveb.github.com/autosetup/ for the online documentation for 'autosetup'
         1138  +    }
         1139  +
         1140  +    p {
         1141  +        'autosetup' provides a number of built-in commands which
         1142  +        are documented below. These may be used from 'auto.def' to test
         1143  +        for features, define variables, create files from templates and
         1144  +        other similar actions.
         1145  +    }
         1146  +
         1147  +    automf_command_reference
         1148  +
         1149  +    exit 0
         1150  +}
         1151  +
         1152  +proc autosetup_output_block {type lines} {
         1153  +    if {[llength $lines]} {
         1154  +        switch $type {
         1155  +            code {
         1156  +                codelines $lines
         1157  +            }
         1158  +            p {
         1159  +                p [join $lines]
         1160  +            }
         1161  +            list {
         1162  +                foreach line $lines {
         1163  +                    bullet $line
         1164  +                }
         1165  +                nl
         1166  +            }
         1167  +        }
         1168  +    }
         1169  +}
         1170  +
         1171  +# Generate a command reference from inline documentation
         1172  +proc automf_command_reference {} {
         1173  +    lappend files $::autosetup(prog)
         1174  +    lappend files {*}[lsort [glob -nocomplain $::autosetup(libdir)/*.tcl]]
         1175  +
         1176  +    section "Core Commands"
         1177  +    set type p
         1178  +    set lines {}
         1179  +    set cmd {}
         1180  +
         1181  +    foreach file $files {
         1182  +        set f [open $file]
         1183  +        while {![eof $f]} {
         1184  +            set line [gets $f]
         1185  +
         1186  +            # Find lines starting with "# @*" and continuing through the remaining comment lines
         1187  +            if {![regexp {^# @(.*)} $line -> cmd]} {
         1188  +                continue
         1189  +            }
         1190  +
         1191  +            # Synopsis or command?
         1192  +            if {$cmd eq "synopsis:"} {
         1193  +                section "Module: [file rootname [file tail $file]]"
         1194  +            } else {
         1195  +                subsection $cmd
         1196  +            }
         1197  +
         1198  +            set lines {}
         1199  +            set type p
         1200  +
         1201  +            # Now the description
         1202  +            while {![eof $f]} {
         1203  +                set line [gets $f]
         1204  +
         1205  +                if {![regexp {^#(#)? ?(.*)} $line -> hash cmd]} {
         1206  +                    break
         1207  +                }
         1208  +                if {$hash eq "#"} {
         1209  +                    set t code
         1210  +                } elseif {[regexp {^- (.*)} $cmd -> cmd]} {
         1211  +                    set t list
         1212  +                } else {
         1213  +                    set t p
         1214  +                }
         1215  +
         1216  +                #puts "hash=$hash, oldhash=$oldhash, lines=[llength $lines], cmd=$cmd"
         1217  +
         1218  +                if {$t ne $type || $cmd eq ""} {
         1219  +                    # Finish the current block
         1220  +                    autosetup_output_block $type $lines
         1221  +                    set lines {}
         1222  +                    set type $t
         1223  +                }
         1224  +                if {$cmd ne ""} {
         1225  +                    lappend lines $cmd
         1226  +                }
         1227  +            }
         1228  +
         1229  +            autosetup_output_block $type $lines
         1230  +        }
         1231  +        close $f
         1232  +    }
         1233  +}
         1234  +}
         1235  +
         1236  +# ----- module init -----
         1237  +
         1238  +set modsource(init) {
         1239  +# Copyright (c) 2010 WorkWare Systems http://www.workware.net.au/
         1240  +# All rights reserved
         1241  +
         1242  +# Module to help create auto.def and configure
         1243  +
         1244  +proc autosetup_init {} {
         1245  +	set create_configure 1
         1246  +	if {[file exists configure]} {
         1247  +		if {!$::autosetup(force)} {
         1248  +			# Could this be an autosetup configure?
         1249  +			if {![string match "*\nWRAPPER=*" [readfile configure]]} {
         1250  +				puts "I see configure, but not created by autosetup, so I won't overwrite it."
         1251  +				puts "Use autosetup --init --force to overwrite."
         1252  +				set create_configure 0
         1253  +			}
         1254  +		} else {
         1255  +			puts "I will overwrite the existing configure because you used --force."
         1256  +		}
         1257  +	} else {
         1258  +		puts "I don't see configure, so I will create it."
         1259  +	}
         1260  +	if {$create_configure} {
         1261  +		if {!$::autosetup(installed)} {
         1262  +			user-notice "Warning: Initialising from the development version of autosetup"
         1263  +
         1264  +			writefile configure "#!/bin/sh\nWRAPPER=\"\$0\" exec $::autosetup(dir)/autosetup \"\$@\"\n"
         1265  +		} else {
         1266  +			writefile configure \
         1267  +{#!/bin/sh
         1268  +dir="`dirname "$0"`/autosetup"
         1269  +WRAPPER="$0" exec `"$dir/find-tclsh" || echo false` "$dir/autosetup" "$@"
         1270  +}
         1271  +		}
         1272  +		catch {exec chmod 755 configure}
         1273  +	}
         1274  +	if {![file exists auto.def]} {
         1275  +		puts "I don't see auto.def, so I will create a default one."
         1276  +		writefile auto.def {# Initial auto.def created by 'autosetup --init'
         1277  +
         1278  +use cc
         1279  +
         1280  +# Add any user options here
         1281  +options {
         1282  +}
         1283  +
         1284  +make-autoconf-h config.h
         1285  +make-template Makefile.in
         1286  +}
         1287  +	}
         1288  +	if {![file exists Makefile.in]} {
         1289  +		puts "Note: I don't see Makefile.in. You will probably need to create one."
         1290  +	}
         1291  +
         1292  +	exit 0
         1293  +}
         1294  +}
         1295  +
         1296  +# ----- module install -----
         1297  +
         1298  +set modsource(install) {
         1299  +# Copyright (c) 2006-2010 WorkWare Systems http://www.workware.net.au/
         1300  +# All rights reserved
         1301  +
         1302  +# Module which can install autosetup
         1303  +
         1304  +proc autosetup_install {} {
         1305  +	if {[catch {
         1306  +		file mkdir autosetup
         1307  +
         1308  +		set f [open autosetup/autosetup w]
         1309  +
         1310  +		set publicmodules {}
         1311  +
         1312  +		# First the main script, but only up until "CUT HERE"
         1313  +		set in [open $::autosetup(dir)/autosetup]
         1314  +		while {[gets $in buf] >= 0} {
         1315  +			if {$buf ne "##-- CUT HERE --##"} {
         1316  +				puts $f $buf
         1317  +				continue
         1318  +			}
         1319  +
         1320  +			# Insert the static modules here
         1321  +			# i.e. those which don't contain @synopsis:
         1322  +			puts $f "set autosetup(installed) 1"
         1323  +			foreach file [lsort [glob $::autosetup(libdir)/*.tcl]] {
         1324  +				set buf [readfile $file]
         1325  +				if {[string match "*\n# @synopsis:*" $buf]} {
         1326  +					lappend publicmodules $file
         1327  +					continue
         1328  +				}
         1329  +				set modname [file rootname [file tail $file]]
         1330  +				puts $f "# ----- module $modname -----"
         1331  +				puts $f "\nset modsource($modname) \{"
         1332  +				puts $f $buf
         1333  +				puts $f "\}\n"
         1334  +			}
         1335  +		}
         1336  +		close $in
         1337  +		close $f
         1338  +		exec chmod 755 autosetup/autosetup
         1339  +
         1340  +		# Install public modules
         1341  +		foreach file $publicmodules {
         1342  +			autosetup_install_file $file autosetup
         1343  +		}
         1344  +
         1345  +		# Install support files
         1346  +		foreach file {config.guess config.sub jimsh0.c find-tclsh test-tclsh LICENSE} {
         1347  +			autosetup_install_file $::autosetup(dir)/$file autosetup
         1348  +		}
         1349  +		exec chmod 755 autosetup/config.sub autosetup/config.guess autosetup/find-tclsh
         1350  +
         1351  +		writefile autosetup/README.autosetup \
         1352  +			"This is [autosetup_version]. See http://msteveb.github.com/autosetup/\n"
         1353  +
         1354  +	} error]} {
         1355  +		user-error "Failed to install autosetup: $error"
         1356  +	}
         1357  +	puts "Installed [autosetup_version] to autosetup/"
         1358  +	catch {exec [info nameofexecutable] autosetup/autosetup --init >@stdout 2>@stderr}
         1359  +
         1360  +	exit 0
         1361  +}
         1362  +
         1363  +# Append the contents of $file to filehandle $f
         1364  +proc autosetup_install_append {f file} {
         1365  +	set in [open $file]
         1366  +	puts $f [read $in]
         1367  +	close $in
         1368  +}
         1369  +
         1370  +proc autosetup_install_file {file dir} {
         1371  +	if {![file exists $file]} {
         1372  +		error "Missing installation file '$file'"
         1373  +	}
         1374  +	writefile [file join $dir [file tail $file]] [readfile $file]\n
         1375  +}
         1376  +
         1377  +if {$::autosetup(installed)} {
         1378  +	user-error "autosetup can only be installed from development source, not from installed copy"
         1379  +}
         1380  +}
         1381  +
         1382  +# ----- module markdown-formatting -----
         1383  +
         1384  +set modsource(markdown-formatting) {
         1385  +# Copyright (c) 2010 WorkWare Systems http://www.workware.net.au/
         1386  +# All rights reserved
         1387  +
         1388  +# Module which provides text formatting
         1389  +# markdown format (kramdown syntax)
         1390  +
         1391  +use formatting
         1392  +
         1393  +proc para {text} {
         1394  +    regsub -all "\[ \t\n\]+" [string trim $text] " " text
         1395  +    regsub -all {([^a-zA-Z])'([^']*)'} $text {\1**`\2`**} text
         1396  +    regsub -all {^'([^']*)'} $text {**`\1`**} text
         1397  +    regsub -all {(http[^ \t\n]*)} $text {[\1](\1)} text
         1398  +    return $text
         1399  +}
         1400  +proc title {text} {
         1401  +    underline [para $text] =
         1402  +    nl
         1403  +}
         1404  +proc p {text} {
         1405  +    puts [para $text]
         1406  +    nl
         1407  +}
         1408  +proc codelines {lines} {
         1409  +    puts "~~~~~~~~~~~~"
         1410  +    foreach line $lines {
         1411  +        puts $line
         1412  +    }
         1413  +    puts "~~~~~~~~~~~~"
         1414  +    nl
         1415  +}
         1416  +proc code {text} {
         1417  +    puts "~~~~~~~~~~~~"
         1418  +    foreach line [parse_code_block $text] {
         1419  +        puts $line
         1420  +    }
         1421  +    puts "~~~~~~~~~~~~"
         1422  +    nl
         1423  +}
         1424  +proc nl {} {
         1425  +    puts ""
         1426  +}
         1427  +proc underline {text char} {
         1428  +    regexp "^(\[ \t\]*)(.*)" $text -> indent words
         1429  +    puts $text
         1430  +    puts $indent[string repeat $char [string length $words]]
         1431  +}
         1432  +proc section {text} {
         1433  +    underline "[para $text]" -
         1434  +    nl
         1435  +}
         1436  +proc subsection {text} {
         1437  +    puts "### `$text`"
         1438  +    nl
         1439  +}
         1440  +proc bullet {text} {
         1441  +    puts "* [para $text]"
         1442  +}
         1443  +proc defn {first args} {
         1444  +    puts "^"
         1445  +    set defn [string trim [join $args \n]]
         1446  +    if {$first ne ""} {
         1447  +        puts "**${first}**"
         1448  +        puts -nonewline ": "
         1449  +        regsub -all "\n\n" $defn "\n: " defn
         1450  +    }
         1451  +    puts "$defn"
         1452  +}
         1453  +}
         1454  +
         1455  +# ----- module misc -----
         1456  +
         1457  +set modsource(misc) {
         1458  +# Copyright (c) 2007-2010 WorkWare Systems http://www.workware.net.au/
         1459  +# All rights reserved
         1460  +
         1461  +# Module containing misc procs useful to modules
         1462  +# Largely for platform compatibility
         1463  +
         1464  +set autosetup(istcl) [info exists ::tcl_library]
         1465  +set autosetup(iswin) [string equal windows $tcl_platform(platform)]
         1466  +
         1467  +if {$autosetup(iswin)} {
         1468  +	# mingw/windows separates $PATH with semicolons
         1469  +	# and doesn't have an executable bit
         1470  +	proc split-path {} {
         1471  +		split [getenv PATH .] {;}
         1472  +	}
         1473  +	proc file-isexec {exec} {
         1474  +		# Basic test for windows. We ignore .bat
         1475  +		if {[file isfile $exec] || [file isfile $exec.exe]} {
         1476  +			return 1
         1477  +		}
         1478  +		return 0
         1479  +	}
         1480  +} else {
         1481  +	# unix separates $PATH with colons and has and executable bit
         1482  +	proc split-path {} {
         1483  +		split [getenv PATH .] :
         1484  +	}
         1485  +	proc file-isexec {exec} {
         1486  +		file executable $exec
         1487  +	}
         1488  +}
         1489  +
         1490  +# Assume that exec can return stdout and stderr
         1491  +proc exec-with-stderr {args} {
         1492  +	exec {*}$args 2>@1
         1493  +}
         1494  +
         1495  +if {$autosetup(istcl)} {
         1496  +	# Tcl doesn't have the env command
         1497  +	proc getenv {name args} {
         1498  +		if {[info exists ::env($name)]} {
         1499  +			return $::env($name)
         1500  +		}
         1501  +		if {[llength $args]} {
         1502  +			return [lindex $args 0]
         1503  +		}
         1504  +		return -code error "environment variable \"$name\" does not exist"
         1505  +	}
         1506  +} elseif {$autosetup(iswin)} {
         1507  +	# On Windows, backslash convert all environment variables
         1508  +	# (Assume that Tcl does this for us)
         1509  +	proc getenv {name args} {
         1510  +		string map {\\ /} [env $name {*}$args]
         1511  +	}
         1512  +	# Jim uses system() for exec under mingw, so
         1513  +	# we need to fetch the output ourselves
         1514  +	proc exec-with-stderr {args} {
         1515  +			set tmpfile /tmp/autosetup.[format %05x [rand 10000]].tmp
         1516  +			set rc [catch [list exec {*}$args >$tmpfile 2>&1] result]
         1517  +			set result [readfile $tmpfile]
         1518  +			file delete $tmpfile
         1519  +			return -code $rc $result
         1520  +	}
         1521  +} else {
         1522  +	# Jim on unix is simple
         1523  +	alias getenv env
         1524  +}
         1525  +
         1526  +# In case 'file normalize' doesn't exist
         1527  +#
         1528  +proc file-normalize {path} {
         1529  +	if {[catch {file normalize $path} result]} {
         1530  +		if {$path eq ""} {
         1531  +			return ""
         1532  +		}
         1533  +		set oldpwd [pwd]
         1534  +		if {[file isdir $path]} {
         1535  +			cd $path
         1536  +			set result [pwd]
         1537  +		} else {
         1538  +			cd [file dirname $path]
         1539  +			set result [file join [pwd] [file tail $path]]
         1540  +		}
         1541  +		cd $oldpwd
         1542  +	}
         1543  +	return $result
         1544  +}
         1545  +
         1546  +# If everything is working properly, the only errors which occur
         1547  +# should be generated in user code (e.g. auto.def).
         1548  +# By default, we only want to show the error location in user code.
         1549  +# We use [info frame] to achieve this, but it works differently on Tcl and Jim.
         1550  +#
         1551  +# This is designed to be called for incorrect usage in auto.def, via autosetup-error
         1552  +#
         1553  +proc error-location {msg} {
         1554  +	if {$::autosetup(debug)} {
         1555  +		return -code error $msg
         1556  +	}
         1557  +	# Search back through the stack trace for the first error in a .def file
         1558  +	for {set i 1} {$i < [info level]} {incr i} {
         1559  +		if {$::autosetup(istcl)} {
         1560  +			array set info [info frame -$i]
         1561  +		} else {
         1562  +			lassign [info frame -$i] info(caller) info(file) info(line)
         1563  +		}
         1564  +		if {[string match *.def $info(file)]} {
         1565  +			return "[relative-path $info(file)]:$info(line): Error: $msg"
         1566  +		}
         1567  +		#puts "Skipping $info(file):$info(line)"
         1568  +	}
         1569  +	return $msg
         1570  +}
         1571  +
         1572  +# Similar to error-location, but called when user code generates an error
         1573  +# In this case we want to show the stack trace in user code, but not in autosetup code
         1574  +# (unless --debug is enabled)
         1575  +#
         1576  +proc error-stacktrace {msg} {
         1577  +	if {$::autosetup(istcl)} {
         1578  +		if {[regexp {file "([^ ]*)" line ([0-9]*)} $::errorInfo dummy file line]} {
         1579  +			return "[relative-path $file]:$line $msg\n$::errorInfo"
         1580  +		}
         1581  +		return $::errorInfo
         1582  +	} else {
         1583  +		# Prepend a live stacktrace to the error stacktrace, omitting the current level
         1584  +		set stacktrace [concat [info stacktrace] [lrange [stacktrace] 3 end]]
         1585  +
         1586  +		if {!$::autosetup(debug)} {
         1587  +			# Omit any levels from autosetup or with no file
         1588  +			set newstacktrace {}
         1589  +			foreach {p f l} $stacktrace {
         1590  +				if {[string match "*autosetup" $f] || $f eq ""} {
         1591  +					#puts "Skipping $p $f:$l"
         1592  +					continue
         1593  +				}
         1594  +				lappend newstacktrace $p $f $l
         1595  +			}
         1596  +			set stacktrace $newstacktrace
         1597  +		}
         1598  +
         1599  +		# Convert filenames to relative paths
         1600  +		set newstacktrace {}
         1601  +		foreach {p f l} $stacktrace {
         1602  +			lappend newstacktrace $p [relative-path $f] $l
         1603  +		}
         1604  +		lassign $newstacktrace p f l
         1605  +		if {$f ne ""} {
         1606  +			set prefix "$f:$l: "
         1607  +		} else {
         1608  +			set prefix ""
         1609  +		}
         1610  +
         1611  +		return "${prefix}Error: $msg\n[stackdump $newstacktrace]"
         1612  +	}
         1613  +}
         1614  +}
         1615  +
         1616  +# ----- module text-formatting -----
         1617  +
         1618  +set modsource(text-formatting) {
         1619  +# Copyright (c) 2010 WorkWare Systems http://www.workware.net.au/
         1620  +# All rights reserved
         1621  +
         1622  +# Module which provides text formatting
         1623  +
         1624  +use formatting
         1625  +
         1626  +proc wordwrap {text length {firstprefix ""} {nextprefix ""}} {
         1627  +    set len 0
         1628  +    set space $firstprefix
         1629  +    foreach word [split $text] {
         1630  +        set word [string trim $word]
         1631  +        if {$word == ""} {
         1632  +            continue
         1633  +        }
         1634  +        if {$len && [string length $space$word] + $len >= $length} {
         1635  +            puts ""
         1636  +            set len 0
         1637  +            set space $nextprefix
         1638  +        }
         1639  +        incr len [string length $space$word]
         1640  +
         1641  +        # Use man-page conventions for highlighting 'quoted' and *quoted*
         1642  +        # single words.
         1643  +        # Use x^Hx for *bold* and _^Hx for 'underline'.
         1644  +        #
         1645  +        # less and more will both understand this.
         1646  +        # Pipe through 'col -b' to remove them.
         1647  +        if {[regexp {^'(.*)'([^a-zA-Z0-9_]*)$} $word -> bareword dot]} {
         1648  +            regsub -all . $bareword "_\b&" word
         1649  +            append word $dot
         1650  +        } elseif {[regexp {^[*](.*)[*]([^a-zA-Z0-9_]*)$} $word -> bareword dot]} {
         1651  +            regsub -all . $bareword "&\b&" word
         1652  +            append word $dot
         1653  +        }
         1654  +        puts -nonewline $space$word
         1655  +        set space " "
         1656  +    }
         1657  +    if {$len} {
         1658  +        puts ""
         1659  +    }
         1660  +}
         1661  +proc title {text} {
         1662  +    underline [string trim $text] =
         1663  +    nl
         1664  +}
         1665  +proc p {text} {
         1666  +    wordwrap $text 80
         1667  +    nl
         1668  +}
         1669  +proc codelines {lines} {
         1670  +    foreach line $lines {
         1671  +        puts "    $line"
         1672  +    }
         1673  +    nl
         1674  +}
         1675  +proc nl {} {
         1676  +    puts ""
         1677  +}
         1678  +proc underline {text char} {
         1679  +    regexp "^(\[ \t\]*)(.*)" $text -> indent words
         1680  +    puts $text
         1681  +    puts $indent[string repeat $char [string length $words]]
         1682  +}
         1683  +proc section {text} {
         1684  +    underline "[string trim $text]" -
         1685  +    nl
         1686  +}
         1687  +proc subsection {text} {
         1688  +    underline "$text" ~
         1689  +    nl
         1690  +}
         1691  +proc bullet {text} {
         1692  +    wordwrap $text 76 "  * " "    "
         1693  +}
         1694  +proc indent {text} {
         1695  +    wordwrap $text 76 "    " "    "
         1696  +}
         1697  +proc defn {first args} {
         1698  +    if {$first ne ""} {
         1699  +        underline "    $first" ~
         1700  +    }
         1701  +    foreach p $args {
         1702  +        if {$p ne ""} {
         1703  +            indent $p
         1704  +        }
         1705  +    }
         1706  +}
         1707  +}
         1708  +
         1709  +# ----- module wiki-formatting -----
         1710  +
         1711  +set modsource(wiki-formatting) {
         1712  +# Copyright (c) 2010 WorkWare Systems http://www.workware.net.au/
         1713  +# All rights reserved
         1714  +
         1715  +# Module which provides text formatting
         1716  +# wiki.tcl.tk format output
         1717  +
         1718  +use formatting
         1719  +
         1720  +proc joinlines {text} {
         1721  +    set lines {}
         1722  +    foreach l [split [string trim $text] \n] {
         1723  +        lappend lines [string trim $l]
         1724  +    }
         1725  +    join $lines
         1726  +}
         1727  +proc p {text} {
         1728  +    puts [joinlines $text]
         1729  +    puts ""
         1730  +}
         1731  +proc title {text} {
         1732  +    puts "*** [joinlines $text] ***"
         1733  +    puts ""
         1734  +}
         1735  +proc codelines {lines} {
         1736  +    puts "======"
         1737  +    foreach line $lines {
         1738  +        puts "    $line"
         1739  +    }
         1740  +    puts "======"
         1741  +}
         1742  +proc code {text} {
         1743  +    puts "======"
         1744  +    foreach line [parse_code_block $text] {
         1745  +        puts "    $line"
         1746  +    }
         1747  +    puts "======"
         1748  +}
         1749  +proc nl {} {
         1750  +}
         1751  +proc section {text} {
         1752  +    puts "'''$text'''"
         1753  +    puts ""
         1754  +}
         1755  +proc subsection {text} {
         1756  +    puts "''$text''"
         1757  +    puts ""
         1758  +}
         1759  +proc bullet {text} {
         1760  +    puts "   * [joinlines $text]"
         1761  +}
         1762  +proc indent {text} {
         1763  +    puts "    :    [joinlines $text]"
         1764  +}
         1765  +proc defn {first args} {
         1766  +    if {$first ne ""} {
         1767  +        indent '''$first'''
         1768  +    }
         1769  +
         1770  +    foreach p $args {
         1771  +        p $p
         1772  +    }
         1773  +}
         1774  +}
         1775  +
         1776  +
         1777  +##################################################################
         1778  +#
         1779  +# Entry/Exit
         1780  +#
         1781  +if {$autosetup(debug)} {
         1782  +	main $argv
         1783  +}
         1784  +if {[catch {main $argv} msg] == 1} {
         1785  +	show-notices
         1786  +	puts stderr [error-stacktrace $msg]
         1787  +	if {!$autosetup(debug) && !$autosetup(istcl)} {
         1788  +		puts stderr "Try: '[file tail $autosetup(exe)] --debug' for a full stack trace"
         1789  +	}
         1790  +	exit 1
         1791  +}

Added autosetup/cc-lib.tcl.

            1  +# Copyright (c) 2011 WorkWare Systems http://www.workware.net.au/
            2  +# All rights reserved
            3  +
            4  +# @synopsis:
            5  +#
            6  +# Provides a library of common tests on top of the 'cc' module.
            7  +
            8  +use cc
            9  +
           10  +module-options {}
           11  +
           12  +# @cc-check-lfs
           13  +#
           14  +# The equivalent of the AC_SYS_LARGEFILE macro
           15  +# 
           16  +# defines 'HAVE_LFS' if LFS is available,
           17  +# and defines '_FILE_OFFSET_BITS=64' if necessary
           18  +#
           19  +# Returns 1 if 'LFS' is available or 0 otherwise
           20  +#
           21  +proc cc-check-lfs {} {
           22  +	cc-check-includes sys/types.h
           23  +	msg-checking "Checking if -D_FILE_OFFSET_BITS=64 is needed..."
           24  +	set lfs 1
           25  +	if {[msg-quiet cc-with {-includes sys/types.h} {cc-check-sizeof off_t}] == 8} {
           26  +		msg-result no
           27  +	} elseif {[msg-quiet cc-with {-includes sys/types.h -cflags -D_FILE_OFFSET_BITS=64} {cc-check-sizeof off_t}] == 8} {
           28  +		define _FILE_OFFSET_BITS 64
           29  +		msg-result yes
           30  +	} else {
           31  +		set lfs 0
           32  +		msg-result none
           33  +	}
           34  +	define-feature lfs $lfs
           35  +	return $lfs
           36  +}
           37  +
           38  +# @cc-check-endian
           39  +#
           40  +# The equivalent of the AC_C_BIGENDIAN macro
           41  +# 
           42  +# defines 'HAVE_BIG_ENDIAN' if endian is known to be big,
           43  +# or 'HAVE_LITTLE_ENDIAN' if endian is known to be little.
           44  +#
           45  +# Returns 1 if determined, or 0 if not.
           46  +#
           47  +proc cc-check-endian {} {
           48  +	cc-check-includes sys/types.h sys/param.h
           49  +	set rc 0
           50  +	msg-checking "Checking endian..."
           51  +	cc-with {-includes {sys/types.h sys/param.h}} {
           52  +		if {[cctest -code {
           53  +			#if! defined(BIG_ENDIAN) || !defined(BYTE_ORDER)
           54  +				#error unknown
           55  +			#elif BYTE_ORDER != BIG_ENDIAN
           56  +				#error little
           57  +			#endif
           58  +		}]} {
           59  +			define-feature big-endian
           60  +			msg-result "big"
           61  +			set rc 1
           62  +		} elseif {[cctest -code {
           63  +			#if! defined(LITTLE_ENDIAN) || !defined(BYTE_ORDER)
           64  +				#error unknown
           65  +			#elif BYTE_ORDER != LITTLE_ENDIAN
           66  +				#error big
           67  +			#endif
           68  +		}]} {
           69  +			define-feature little-endian
           70  +			msg-result "little"
           71  +			set rc 1
           72  +		} else {
           73  +			msg-result "unknown"
           74  +		}
           75  +	}
           76  +	return $rc
           77  +}

Added autosetup/cc-shared.tcl.

            1  +# Copyright (c) 2010 WorkWare Systems http://www.workware.net.au/
            2  +# All rights reserved
            3  +
            4  +# @synopsis:
            5  +#
            6  +# The 'cc-shared' module provides support for shared libraries and shared objects.
            7  +# It defines the following variables:
            8  +#
            9  +## SH_CFLAGS         Flags to use compiling sources destined for a shared library
           10  +## SH_LDFLAGS        Flags to use linking a shared library
           11  +## SHOBJ_CFLAGS      Flags to use compiling sources destined for a shared object
           12  +## SHOBJ_LDFLAGS     Flags to use linking a shared object
           13  +## SH_LINKFLAGS      Flags to use linking an executable which will load shared objects
           14  +## LD_LIBRARY_PATH   Environment variable which specifies path to shared libraries
           15  +
           16  +module-options {}
           17  +
           18  +foreach i {SH_LINKFLAGS SH_CFLAGS SH_LDFLAGS SHOBJ_CFLAGS SHOBJ_LDFLAGS} {
           19  +	define $i ""
           20  +}
           21  +
           22  +define LD_LIBRARY_PATH LD_LIBRARY_PATH
           23  +
           24  +switch -glob -- [get-define host] {
           25  +	*-*-darwin* {
           26  +		define SH_CFLAGS -dynamic
           27  +		define SH_LDFLAGS "-dynamiclib"
           28  +		define SHOBJ_CFLAGS "-dynamic -fno-common"
           29  +		define SHOBJ_LDFLAGS "-bundle -undefined dynamic_lookup"
           30  +		define LD_LIBRARY_PATH DYLD_LIBRARY_PATH
           31  +	}
           32  +	*-*-ming* {
           33  +		define SH_LDFLAGS -shared
           34  +		define SHOBJ_LDFLAGS -shared
           35  +	}
           36  +	*-*-cygwin {
           37  +		define SH_LDFLAGS -shared
           38  +		define SHOBJ_LDFLAGS -shared
           39  +	}
           40  +	* {
           41  +		# Generic Unix settings
           42  +		define SH_LINKFLAGS -rdynamic
           43  +		define SH_CFLAGS -fPIC
           44  +		define SH_LDFLAGS -shared
           45  +		define SHOBJ_CFLAGS -fPIC
           46  +		define SHOBJ_LDFLAGS "-shared -nostartfiles"
           47  +	}
           48  +}

Added autosetup/cc.tcl.

            1  +# Copyright (c) 2010 WorkWare Systems http://www.workware.net.au/
            2  +# All rights reserved
            3  +
            4  +# @synopsis:
            5  +#
            6  +# The 'cc' module supports checking various 'features' of the C or C++
            7  +# compiler/linker environment. Common commands are cc-check-includes,
            8  +# cc-check-types, cc-check-functions, cc-with, make-autoconf-h and make-template.
            9  +#
           10  +# The following environment variables are used if set:
           11  +#
           12  +## CC       - C compiler
           13  +## CXX      - C++ compiler
           14  +## CCACHE   - Set to "none" to disable automatic use of ccache
           15  +## CFLAGS   - Additional C compiler flags
           16  +## CXXFLAGS - Additional C++ compiler flags
           17  +## LDFLAGS  - Additional compiler flags during linking
           18  +## LIBS     - Additional libraries to use (for all tests)
           19  +## CROSS    - Tool prefix for cross compilation
           20  +#
           21  +# The following variables are defined from the corresponding
           22  +# environment variables if set.
           23  +#
           24  +## CPPFLAGS
           25  +## LINKFLAGS
           26  +## CC_FOR_BUILD
           27  +## LD
           28  +
           29  +use system
           30  +
           31  +module-options {}
           32  +
           33  +# Note that the return code is not meaningful
           34  +proc cc-check-something {name code} {
           35  +	uplevel 1 $code
           36  +}
           37  +
           38  +# Checks for the existence of the given function by linking
           39  +#
           40  +proc cctest_function {function} {
           41  +	cctest -link 1 -declare "extern void $function\(void);" -code "$function\();"
           42  +}
           43  +
           44  +# Checks for the existence of the given type by compiling
           45  +proc cctest_type {type} {
           46  +	cctest -code "$type _x;"
           47  +}
           48  +
           49  +# Checks for the existence of the given type/structure member.
           50  +# e.g. "struct stat.st_mtime"
           51  +proc cctest_member {struct_member} {
           52  +	lassign [split $struct_member .] struct member
           53  +	cctest -code "static $struct _s; return sizeof(_s.$member);"
           54  +}
           55  +
           56  +# Checks for the existence of the given define by compiling
           57  +#
           58  +proc cctest_define {name} {
           59  +	cctest -code "#ifndef $name\n#error not defined\n#endif"
           60  +}
           61  +
           62  +# Checks for the existence of the given name either as
           63  +# a macro (#define) or an rvalue (such as an enum)
           64  +#
           65  +proc cctest_decl {name} {
           66  +	cctest -code "#ifndef $name\n(void)$name;\n#endif"
           67  +}
           68  +
           69  +# @cc-check-sizeof type ...
           70  +#
           71  +# Checks the size of the given types (between 1 and 32, inclusive).
           72  +# Defines a variable with the size determined, or "unknown" otherwise.
           73  +# e.g. for type 'long long', defines SIZEOF_LONG_LONG.
           74  +# Returns the size of the last type.
           75  +#
           76  +proc cc-check-sizeof {args} {
           77  +	foreach type $args {
           78  +		msg-checking "Checking for sizeof $type..."
           79  +		set size unknown
           80  +		# Try the most common sizes first
           81  +		foreach i {4 8 1 2 16 32} {
           82  +			if {[cctest -code "static int _x\[sizeof($type) == $i ? 1 : -1\] = { 1 };"]} {
           83  +				set size $i
           84  +				break
           85  +			}
           86  +		}
           87  +		msg-result $size
           88  +		set define [feature-define-name $type SIZEOF_]
           89  +		define $define $size
           90  +	}
           91  +	# Return the last result
           92  +	get-define $define
           93  +}
           94  +
           95  +# Checks for each feature in $list by using the given script.
           96  +#
           97  +# When the script is evaluated, $each is set to the feature
           98  +# being checked, and $extra is set to any additional cctest args.
           99  +#
          100  +# Returns 1 if all features were found, or 0 otherwise.
          101  +proc cc-check-some-feature {list script} {
          102  +	set ret 1
          103  +	foreach each $list {
          104  +		if {![check-feature $each $script]} {
          105  +			set ret 0
          106  +		}
          107  +	}
          108  +	return $ret
          109  +}
          110  +
          111  +# @cc-check-includes includes ...
          112  +#
          113  +# Checks that the given include files can be used
          114  +proc cc-check-includes {args} {
          115  +	cc-check-some-feature $args {
          116  +		cctest -includes $each
          117  +	}
          118  +}
          119  +
          120  +# @cc-check-types type ...
          121  +#
          122  +# Checks that the types exist.
          123  +proc cc-check-types {args} {
          124  +	cc-check-some-feature $args {
          125  +		cctest_type $each
          126  +	}
          127  +}
          128  +
          129  +# @cc-check-defines define ...
          130  +#
          131  +# Checks that the given preprocessor symbol is defined
          132  +proc cc-check-defines {args} {
          133  +	cc-check-some-feature $args {
          134  +		cctest_define $each
          135  +	}
          136  +}
          137  +
          138  +# @cc-check-decls name ...
          139  +#
          140  +# Checks that each given name is either a preprocessor symbol or rvalue
          141  +# such as an enum. Note that the define used for a decl is HAVE_DECL_xxx
          142  +# rather than HAVE_xxx
          143  +proc cc-check-decls {args} {
          144  +	set ret 1
          145  +	foreach name $args {
          146  +		msg-checking "Checking for $name..."
          147  +		set r [cctest_decl $name]
          148  +		define-feature "decl $name" $r
          149  +		if {$r} {
          150  +			msg-result "ok"
          151  +		} else {
          152  +			msg-result "not found"
          153  +			set ret 0
          154  +		}
          155  +	}
          156  +	return $ret
          157  +}
          158  +
          159  +# @cc-check-functions function ...
          160  +#
          161  +# Checks that the given functions exist (can be linked)
          162  +proc cc-check-functions {args} {
          163  +	cc-check-some-feature $args {
          164  +		cctest_function $each
          165  +	}
          166  +}
          167  +
          168  +# @cc-check-members type.member ...
          169  +#
          170  +# Checks that the given type/structure members exist.
          171  +# A structure member is of the form "struct stat.st_mtime"
          172  +proc cc-check-members {args} {
          173  +	cc-check-some-feature $args {
          174  +		cctest_member $each
          175  +	}
          176  +}
          177  +
          178  +# @cc-check-function-in-lib function libs ?otherlibs?
          179  +#
          180  +# Checks that the given given function can be found in one of the libs.
          181  +#
          182  +# First checks for no library required, then checks each of the libraries
          183  +# in turn.
          184  +#
          185  +# If the function is found, the feature is defined and lib_$function is defined
          186  +# to -l$lib where the function was found, or "" if no library required.
          187  +# In addition, -l$lib is added to the LIBS define.
          188  +#
          189  +# If additional libraries may be needed for linking, they should be specified
          190  +# as $extralibs as "-lotherlib1 -lotherlib2".
          191  +# These libraries are not automatically added to LIBS.
          192  +#
          193  +# Returns 1 if found or 0 if not.
          194  +# 
          195  +proc cc-check-function-in-lib {function libs {otherlibs {}}} {
          196  +	msg-checking "Checking libs for $function..."
          197  +	set found 0
          198  +	cc-with [list -libs $otherlibs] {
          199  +		if {[cctest_function $function]} {
          200  +			msg-result "none needed"
          201  +			define lib_$function ""
          202  +			incr found
          203  +		} else {
          204  +			foreach lib $libs {
          205  +				cc-with [list -libs -l$lib] {
          206  +					if {[cctest_function $function]} {
          207  +						msg-result -l$lib
          208  +						define lib_$function -l$lib
          209  +						define-append LIBS -l$lib
          210  +						incr found
          211  +						break
          212  +					}
          213  +				}
          214  +			}
          215  +		}
          216  +	}
          217  +	if {$found} {
          218  +		define [feature-define-name $function]
          219  +	} else {
          220  +		msg-result "no"
          221  +	}
          222  +	return $found
          223  +}
          224  +
          225  +# @cc-check-tools tool ...
          226  +#
          227  +# Checks for existence of the given compiler tools, taking
          228  +# into account any cross compilation prefix.
          229  +#
          230  +# For example, when checking for "ar", first AR is checked on the command
          231  +# line and then in the environment. If not found, "${host}-ar" or
          232  +# simply "ar" is assumed depending upon whether cross compiling.
          233  +# The path is searched for this executable, and if found AR is defined
          234  +# to the executable name.
          235  +#
          236  +# It is an error if the executable is not found.
          237  +#
          238  +proc cc-check-tools {args} {
          239  +	foreach tool $args {
          240  +		set TOOL [string toupper $tool]
          241  +		set exe [get-env $TOOL [get-define cross]$tool]
          242  +		if {![find-executable $exe]} {
          243  +			user-error "Failed to find $exe"
          244  +		}
          245  +		define $TOOL $exe
          246  +	}
          247  +}
          248  +
          249  +# @cc-check-progs prog ...
          250  +#
          251  +# Checks for existence of the given executables on the path.
          252  +#
          253  +# For example, when checking for "grep", the path is searched for
          254  +# the executable, 'grep', and if found GREP is defined as "grep".
          255  +#
          256  +# It the executable is not found, the variable is defined as false.
          257  +# Returns 1 if all programs were found, or 0 otherwise.
          258  +#
          259  +proc cc-check-progs {args} {
          260  +	set failed 0
          261  +	foreach prog $args {
          262  +		set PROG [string toupper $prog]
          263  +		msg-checking "Checking for $prog..."
          264  +		if {![find-executable $prog]} {
          265  +			msg-result no
          266  +			define $PROG false
          267  +			incr failed
          268  +		} else {
          269  +			msg-result ok
          270  +			define $PROG $prog
          271  +		}
          272  +	}
          273  +	expr {!$failed}
          274  +}
          275  +
          276  +# Adds the given settings to $::autosetup(ccsettings) and
          277  +# returns the old settings.
          278  +#
          279  +proc cc-add-settings {settings} {
          280  +	if {[llength $settings] % 2} {
          281  +		autosetup-error "settings list is missing a value: $settings"
          282  +	}
          283  +
          284  +	set prev [cc-get-settings]
          285  +	# workaround a bug in some versions of jimsh by forcing
          286  +	# conversion of $prev to a list
          287  +	llength $prev
          288  +
          289  +	array set new $prev
          290  +
          291  +	foreach {name value} $settings {
          292  +		switch -exact -- $name {
          293  +			-cflags - -includes {
          294  +				# These are given as lists
          295  +				lappend new($name) {*}$value
          296  +			}
          297  +			-declare {
          298  +				lappend new($name) $value
          299  +			}
          300  +			-libs {
          301  +				# Note that new libraries are added before previous libraries
          302  +				set new($name) [list {*}$value {*}$new($name)]
          303  +			}
          304  +			-link - -lang {
          305  +				set new($name) $value
          306  +			}
          307  +			-source - -sourcefile - -code {
          308  +				# XXX: These probably are only valid directly from cctest
          309  +				set new($name) $value
          310  +			}
          311  +			default {
          312  +				autosetup-error "unknown cctest setting: $name"
          313  +			}
          314  +		}
          315  +	}
          316  +
          317  +	cc-store-settings [array get new]
          318  +
          319  +	return $prev
          320  +}
          321  +
          322  +proc cc-store-settings {new} {
          323  +	set ::autosetup(ccsettings) $new
          324  +}
          325  +
          326  +proc cc-get-settings {} {
          327  +	return $::autosetup(ccsettings)
          328  +}
          329  +
          330  +# Similar to cc-add-settings, but each given setting
          331  +# simply replaces the existing value.
          332  +#
          333  +# Returns the previous settings
          334  +proc cc-update-settings {args} {
          335  +	set prev [cc-get-settings]
          336  +	array set new $prev
          337  +
          338  +	foreach {name value} $args {
          339  +		set new($name) $value
          340  +	}
          341  +	cc-store-settings $new
          342  +
          343  +	return $prev
          344  +}
          345  +
          346  +# @cc-with settings ?{ script }?
          347  +#
          348  +# Sets the given 'cctest' settings and then runs the tests in 'script'.
          349  +# Note that settings such as -lang replace the current setting, while
          350  +# those such as -includes are appended to the existing setting.
          351  +#
          352  +# If no script is given, the settings become the default for the remainder
          353  +# of the auto.def file.
          354  +#
          355  +## cc-with {-lang c++} {
          356  +##   # This will check with the C++ compiler
          357  +##   cc-check-types bool
          358  +##   cc-with {-includes signal.h} {
          359  +##     # This will check with the C++ compiler, signal.h and any existing includes.
          360  +##     ...
          361  +##   }
          362  +##   # back to just the C++ compiler
          363  +## }
          364  +#
          365  +# The -libs setting is special in that newer values are added *before* earlier ones.
          366  +#
          367  +## cc-with {-libs {-lc -lm}} {
          368  +##   cc-with {-libs -ldl} {
          369  +##     cctest -libs -lsocket ...
          370  +##     # libs will be in this order: -lsocket -ldl -lc -lm
          371  +##   }
          372  +## }
          373  +proc cc-with {settings args} {
          374  +	if {[llength $args] == 0} {
          375  +		cc-add-settings $settings
          376  +	} elseif {[llength $args] > 1} {
          377  +		autosetup-error "usage: cc-with settings ?script?"
          378  +	} else {
          379  +		set save [cc-add-settings $settings]
          380  +		set rc [catch {uplevel 1 [lindex $args 0]} result info]
          381  +		cc-store-settings $save
          382  +		if {$rc != 0} {
          383  +			return $result -code [dict get $info -code]
          384  +		}
          385  +		return $result
          386  +	}
          387  +}
          388  +
          389  +# @cctest ?settings?
          390  +# 
          391  +# Low level C compiler checker. Compiles and or links a small C program
          392  +# according to the arguments and returns 1 if OK, or 0 if not.
          393  +#
          394  +# Supported settings are:
          395  +#
          396  +## -cflags cflags      A list of flags to pass to the compiler
          397  +## -includes list      A list of includes, e.g. {stdlib.h stdio.h}
          398  +## -declare code       Code to declare before main()
          399  +## -link 1             Don't just compile, link too
          400  +## -lang c|c++         Use the C (default) or C++ compiler
          401  +## -libs liblist       List of libraries to link, e.g. {-ldl -lm}
          402  +## -code code          Code to compile in the body of main()
          403  +## -source code        Compile a complete program. Ignore -includes, -declare and -code
          404  +## -sourcefile file    Shorthand for -source [readfile [get-define srcdir]/$file]
          405  +#
          406  +# Unless -source or -sourcefile is specified, the C program looks like:
          407  +#
          408  +## #include <firstinclude>   /* same for remaining includes in the list */
          409  +##
          410  +## declare-code              /* any code in -declare, verbatim */
          411  +##
          412  +## int main(void) {
          413  +##   code                    /* any code in -code, verbatim */
          414  +##   return 0;
          415  +## }
          416  +#
          417  +# Any failures are recorded in 'config.log'
          418  +#
          419  +proc cctest {args} {
          420  +	set src conftest__.c
          421  +	set tmp conftest__.o
          422  +
          423  +	# Easiest way to merge in the settings
          424  +	cc-with $args {
          425  +		array set opts [cc-get-settings]
          426  +	}
          427  +
          428  +	if {[info exists opts(-sourcefile)]} {
          429  +		set opts(-source) [readfile [get-define srcdir]/$opts(-sourcefile) "#error can't find $opts(-sourcefile)"]
          430  +	}
          431  +	if {[info exists opts(-source)]} {
          432  +		set lines $opts(-source)
          433  +	} else {
          434  +		foreach i $opts(-includes) {
          435  +			if {$opts(-code) ne "" && ![feature-checked $i]} {
          436  +				# Compiling real code with an unchecked header file
          437  +				# Quickly (and silently) check for it now
          438  +
          439  +				# Remove all -includes from settings before checking
          440  +				set saveopts [cc-update-settings -includes {}]
          441  +				msg-quiet cc-check-includes $i
          442  +				cc-store-settings $saveopts
          443  +			}
          444  +			if {$opts(-code) eq "" || [have-feature $i]} {
          445  +				lappend source "#include <$i>"
          446  +			}
          447  +		}
          448  +		lappend source {*}$opts(-declare)
          449  +		lappend source "int main(void) {"
          450  +		lappend source $opts(-code)
          451  +		lappend source "return 0;"
          452  +		lappend source "}"
          453  +
          454  +		set lines [join $source \n]
          455  +	}
          456  +
          457  +	# Build the command line
          458  +	set cmdline {}
          459  +	lappend cmdline {*}[get-define CCACHE]
          460  +	switch -exact -- $opts(-lang) {
          461  +		c++ {
          462  +			lappend cmdline {*}[get-define CXX] {*}[get-define CXXFLAGS]
          463  +		}
          464  +		c {
          465  +			lappend cmdline {*}[get-define CC] {*}[get-define CFLAGS]
          466  +		}
          467  +		default {
          468  +			autosetup-error "cctest called with unknown language: $opts(-lang)"
          469  +		}
          470  +	}
          471  +
          472  +	if {!$opts(-link)} {
          473  +		lappend cmdline -c
          474  +	}
          475  +	lappend cmdline {*}$opts(-cflags)
          476  +
          477  +	switch -glob -- [get-define host] {
          478  +		*-*-darwin* {
          479  +			# Don't generate .dSYM directories
          480  +			lappend cmdline -gstabs
          481  +		}
          482  +	}
          483  +	lappend cmdline $src -o $tmp {*}$opts(-libs)
          484  +
          485  +	# At this point we have the complete command line and the
          486  +	# complete source to be compiled. Get the result from cache if
          487  +	# we can
          488  +	if {[info exists ::cc_cache($cmdline,$lines)]} {
          489  +		msg-checking "(cached) "
          490  +		set ok $::cc_cache($cmdline,$lines)
          491  +		if {$::autosetup(debug)} {
          492  +			configlog "From cache (ok=$ok): [join $cmdline]"
          493  +			configlog "============"
          494  +			configlog $lines
          495  +			configlog "============"
          496  +		}
          497  +		return $ok
          498  +	}
          499  +
          500  +	writefile $src $lines\n
          501  +
          502  +	set ok 1
          503  +	if {[catch {exec-with-stderr {*}$cmdline} result errinfo]} {
          504  +		configlog "Failed: [join $cmdline]"
          505  +		configlog $result
          506  +		configlog "============"
          507  +		configlog "The failed code was:"
          508  +		configlog $lines
          509  +		configlog "============"
          510  +		set ok 0
          511  +	} elseif {$::autosetup(debug)} {
          512  +		configlog "Compiled OK: [join $cmdline]"
          513  +		configlog "============"
          514  +		configlog $lines
          515  +		configlog "============"
          516  +	}
          517  +	file delete $src
          518  +	file delete $tmp
          519  +
          520  +	# cache it
          521  +	set ::cc_cache($cmdline,$lines) $ok
          522  +
          523  +	return $ok
          524  +}
          525  +
          526  +# @make-autoconf-h outfile ?auto-patterns=HAVE_*? ?bare-patterns=SIZEOF_*?
          527  +#
          528  +# Deprecated - see make-config-header
          529  +proc make-autoconf-h {file {autopatterns {HAVE_*}} {barepatterns {SIZEOF_* HAVE_DECL_*}}} {
          530  +	user-notice "*** make-autoconf-h is deprecated -- use make-config-header instead"
          531  +	make-config-header $file -auto $autopatterns -bare $barepatterns
          532  +}
          533  +
          534  +# @make-config-header outfile ?-auto patternlist? ?-bare patternlist? ?-none patternlist? ?-str patternlist? ...
          535  +#
          536  +# Examines all defined variables which match the given patterns
          537  +# and writes an include file, $file, which defines each of these.
          538  +# Variables which match '-auto' are output as follows:
          539  +# - defines which have the value "0" are ignored.
          540  +# - defines which have integer values are defined as the integer value.
          541  +# - any other value is defined as a string, e.g. "value"
          542  +# Variables which match '-bare' are defined as-is.
          543  +# Variables which match '-str' are defined as a string, e.g. "value"
          544  +# Variables which match '-none' are omitted.
          545  +#
          546  +# Note that order is important. The first pattern which matches is selected
          547  +# Default behaviour is:
          548  +#
          549  +#  -bare {SIZEOF_* HAVE_DECL_*} -auto HAVE_* -none *
          550  +#
          551  +# If the file would be unchanged, it is not written.
          552  +proc make-config-header {file args} {
          553  +	set guard _[string toupper [regsub -all {[^a-zA-Z0-9]} [file tail $file] _]]
          554  +	file mkdir [file dirname $file]
          555  +	set lines {}
          556  +	lappend lines "#ifndef $guard"
          557  +	lappend lines "#define $guard"
          558  +
          559  +	# Add some defaults
          560  +	lappend args -bare {SIZEOF_* HAVE_DECL_*} -auto HAVE_*
          561  +
          562  +	foreach n [lsort [dict keys [all-defines]]] {
          563  +		set value [get-define $n]
          564  +		set type [calc-define-output-type $n $args]
          565  +		switch -exact -- $type {
          566  +			-bare {
          567  +				# Just output the value unchanged
          568  +			}
          569  +			-none {
          570  +				continue
          571  +			}
          572  +			-str {
          573  +				set value \"$value\"
          574  +			}
          575  +			-auto {
          576  +				# Automatically determine the type
          577  +				if {$value eq "0"} {
          578  +					lappend lines "/* #undef $n */"
          579  +					continue
          580  +				}
          581  +				if {![string is integer -strict $value]} {
          582  +					set value \"$value\"
          583  +				}
          584  +			}
          585  +			"" {
          586  +				continue
          587  +			}
          588  +			default {
          589  +				autosetup-error "Unknown type in make-config-header: $type"
          590  +			}
          591  +		}
          592  +		lappend lines "#define $n $value"
          593  +	}
          594  +	lappend lines "#endif"
          595  +	set buf [join $lines \n]
          596  +	write-if-changed $file $buf {
          597  +		msg-result "Created $file"
          598  +	}
          599  +}
          600  +
          601  +proc calc-define-output-type {name spec} {
          602  +	foreach {type patterns} $spec {
          603  +		foreach pattern $patterns {
          604  +			if {[string match $pattern $name]} {
          605  +				return $type
          606  +			}
          607  +		}
          608  +	}
          609  +	return ""
          610  +}
          611  +
          612  +# Initialise some values from the environment or commandline or default settings
          613  +foreach i {LDFLAGS LIBS CPPFLAGS LINKFLAGS {CFLAGS "-g -O2"}} {
          614  +	lassign $i var default
          615  +	define $var [get-env $var $default]
          616  +}
          617  +
          618  +if {[env-is-set CC]} {
          619  +	# Set by the user, so don't try anything else
          620  +	set try [list [get-env CC ""]]
          621  +} else {
          622  +	# Try some reasonable options
          623  +	set try [list [get-define cross]cc [get-define cross]gcc]
          624  +}
          625  +define CC [find-an-executable {*}$try]
          626  +if {[get-define CC] eq ""} {
          627  +	user-error "Could not find a C compiler. Tried: [join $try ", "]"
          628  +}
          629  +
          630  +define CPP [get-env CPP "[get-define CC] -E"]
          631  +
          632  +# XXX: Could avoid looking for a C++ compiler until requested
          633  +# Note that if CXX isn't found, we just set it to "false". It might not be needed.
          634  +if {[env-is-set CXX]} {
          635  +	define CXX [find-an-executable -required [get-env CXX ""]]
          636  +} else {
          637  +	define CXX [find-an-executable [get-define cross]c++ [get-define cross]g++ false]
          638  +}
          639  +
          640  +# CXXFLAGS default to CFLAGS if not specified
          641  +define CXXFLAGS [get-env CXXFLAGS [get-define CFLAGS]]
          642  +
          643  +cc-check-tools ld
          644  +
          645  +# May need a CC_FOR_BUILD, so look for one
          646  +define CC_FOR_BUILD [find-an-executable [get-env CC_FOR_BUILD ""] cc gcc false]
          647  +
          648  +if {[get-define CC] eq ""} {
          649  +	user-error "Could not find a C compiler. Tried: [join $try ", "]"
          650  +}
          651  +
          652  +define CCACHE [find-an-executable [get-env CCACHE ccache]]
          653  +
          654  +# Initial cctest settings
          655  +cc-store-settings {-cflags {} -includes {} -declare {} -link 0 -lang c -libs {} -code {}}
          656  +
          657  +msg-result "C compiler...[get-define CCACHE] [get-define CC] [get-define CFLAGS]"
          658  +if {[get-define CXX] ne "false"} {
          659  +	msg-result "C++ compiler...[get-define CCACHE] [get-define CXX] [get-define CXXFLAGS]"
          660  +}
          661  +msg-result "Build C compiler...[get-define CC_FOR_BUILD]"
          662  +
          663  +if {![cc-check-includes stdlib.h]} {
          664  +	user-error "Compiler does not work. See config.log"
          665  +}

Added autosetup/config.guess.

            1  +#! /bin/sh
            2  +# Attempt to guess a canonical system name.
            3  +#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
            4  +#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
            5  +#   Free Software Foundation, Inc.
            6  +
            7  +timestamp='2010-09-24'
            8  +
            9  +# This file is free software; you can redistribute it and/or modify it
           10  +# under the terms of the GNU General Public License as published by
           11  +# the Free Software Foundation; either version 2 of the License, or
           12  +# (at your option) any later version.
           13  +#
           14  +# This program is distributed in the hope that it will be useful, but
           15  +# WITHOUT ANY WARRANTY; without even the implied warranty of
           16  +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
           17  +# General Public License for more details.
           18  +#
           19  +# You should have received a copy of the GNU General Public License
           20  +# along with this program; if not, write to the Free Software
           21  +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
           22  +# 02110-1301, USA.
           23  +#
           24  +# As a special exception to the GNU General Public License, if you
           25  +# distribute this file as part of a program that contains a
           26  +# configuration script generated by Autoconf, you may include it under
           27  +# the same distribution terms that you use for the rest of that program.
           28  +
           29  +
           30  +# Originally written by Per Bothner.  Please send patches (context
           31  +# diff format) to <config-patches@gnu.org> and include a ChangeLog
           32  +# entry.
           33  +#
           34  +# This script attempts to guess a canonical system name similar to
           35  +# config.sub.  If it succeeds, it prints the system name on stdout, and
           36  +# exits with 0.  Otherwise, it exits with 1.
           37  +#
           38  +# You can get the latest version of this script from:
           39  +# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
           40  +
           41  +me=`echo "$0" | sed -e 's,.*/,,'`
           42  +
           43  +usage="\
           44  +Usage: $0 [OPTION]
           45  +
           46  +Output the configuration name of the system \`$me' is run on.
           47  +
           48  +Operation modes:
           49  +  -h, --help         print this help, then exit
           50  +  -t, --time-stamp   print date of last modification, then exit
           51  +  -v, --version      print version number, then exit
           52  +
           53  +Report bugs and patches to <config-patches@gnu.org>."
           54  +
           55  +version="\
           56  +GNU config.guess ($timestamp)
           57  +
           58  +Originally written by Per Bothner.
           59  +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
           60  +2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
           61  +Software Foundation, Inc.
           62  +
           63  +This is free software; see the source for copying conditions.  There is NO
           64  +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
           65  +
           66  +help="
           67  +Try \`$me --help' for more information."
           68  +
           69  +# Parse command line
           70  +while test $# -gt 0 ; do
           71  +  case $1 in
           72  +    --time-stamp | --time* | -t )
           73  +       echo "$timestamp" ; exit ;;
           74  +    --version | -v )
           75  +       echo "$version" ; exit ;;
           76  +    --help | --h* | -h )
           77  +       echo "$usage"; exit ;;
           78  +    -- )     # Stop option processing
           79  +       shift; break ;;
           80  +    - )	# Use stdin as input.
           81  +       break ;;
           82  +    -* )
           83  +       echo "$me: invalid option $1$help" >&2
           84  +       exit 1 ;;
           85  +    * )
           86  +       break ;;
           87  +  esac
           88  +done
           89  +
           90  +if test $# != 0; then
           91  +  echo "$me: too many arguments$help" >&2
           92  +  exit 1
           93  +fi
           94  +
           95  +trap 'exit 1' HUP INT TERM
           96  +
           97  +# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
           98  +# compiler to aid in system detection is discouraged as it requires
           99  +# temporary files to be created and, as you can see below, it is a
          100  +# headache to deal with in a portable fashion.
          101  +
          102  +# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
          103  +# use `HOST_CC' if defined, but it is deprecated.
          104  +
          105  +# Portable tmp directory creation inspired by the Autoconf team.
          106  +
          107  +set_cc_for_build='
          108  +trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
          109  +trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" HUP INT PIPE TERM ;
          110  +: ${TMPDIR=/tmp} ;
          111  + { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
          112  + { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
          113  + { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
          114  + { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
          115  +dummy=$tmp/dummy ;
          116  +tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
          117  +case $CC_FOR_BUILD,$HOST_CC,$CC in
          118  + ,,)    echo "int x;" > $dummy.c ;
          119  +	for c in cc gcc c89 c99 ; do
          120  +	  if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
          121  +	     CC_FOR_BUILD="$c"; break ;
          122  +	  fi ;
          123  +	done ;
          124  +	if test x"$CC_FOR_BUILD" = x ; then
          125  +	  CC_FOR_BUILD=no_compiler_found ;
          126  +	fi
          127  +	;;
          128  + ,,*)   CC_FOR_BUILD=$CC ;;
          129  + ,*,*)  CC_FOR_BUILD=$HOST_CC ;;
          130  +esac ; set_cc_for_build= ;'
          131  +
          132  +# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
          133  +# (ghazi@noc.rutgers.edu 1994-08-24)
          134  +if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
          135  +	PATH=$PATH:/.attbin ; export PATH
          136  +fi
          137  +
          138  +UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
          139  +UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
          140  +UNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown
          141  +UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
          142  +
          143  +# Note: order is significant - the case branches are not exclusive.
          144  +
          145  +case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
          146  +    *:NetBSD:*:*)
          147  +	# NetBSD (nbsd) targets should (where applicable) match one or
          148  +	# more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*,
          149  +	# *-*-netbsdecoff* and *-*-netbsd*.  For targets that recently
          150  +	# switched to ELF, *-*-netbsd* would select the old
          151  +	# object file format.  This provides both forward
          152  +	# compatibility and a consistent mechanism for selecting the
          153  +	# object file format.
          154  +	#
          155  +	# Note: NetBSD doesn't particularly care about the vendor
          156  +	# portion of the name.  We always set it to "unknown".
          157  +	sysctl="sysctl -n hw.machine_arch"
          158  +	UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \
          159  +	    /usr/sbin/$sysctl 2>/dev/null || echo unknown)`
          160  +	case "${UNAME_MACHINE_ARCH}" in
          161  +	    armeb) machine=armeb-unknown ;;
          162  +	    arm*) machine=arm-unknown ;;
          163  +	    sh3el) machine=shl-unknown ;;
          164  +	    sh3eb) machine=sh-unknown ;;
          165  +	    sh5el) machine=sh5le-unknown ;;
          166  +	    *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
          167  +	esac
          168  +	# The Operating System including object format, if it has switched
          169  +	# to ELF recently, or will in the future.
          170  +	case "${UNAME_MACHINE_ARCH}" in
          171  +	    arm*|i386|m68k|ns32k|sh3*|sparc|vax)
          172  +		eval $set_cc_for_build
          173  +		if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
          174  +			| grep -q __ELF__
          175  +		then
          176  +		    # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
          177  +		    # Return netbsd for either.  FIX?
          178  +		    os=netbsd
          179  +		else
          180  +		    os=netbsdelf
          181  +		fi
          182  +		;;
          183  +	    *)
          184  +	        os=netbsd
          185  +		;;
          186  +	esac
          187  +	# The OS release
          188  +	# Debian GNU/NetBSD machines have a different userland, and
          189  +	# thus, need a distinct triplet. However, they do not need
          190  +	# kernel version information, so it can be replaced with a
          191  +	# suitable tag, in the style of linux-gnu.
          192  +	case "${UNAME_VERSION}" in
          193  +	    Debian*)
          194  +		release='-gnu'
          195  +		;;
          196  +	    *)
          197  +		release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
          198  +		;;
          199  +	esac
          200  +	# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
          201  +	# contains redundant information, the shorter form:
          202  +	# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
          203  +	echo "${machine}-${os}${release}"
          204  +	exit ;;
          205  +    *:OpenBSD:*:*)
          206  +	UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
          207  +	echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
          208  +	exit ;;
          209  +    *:ekkoBSD:*:*)
          210  +	echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
          211  +	exit ;;
          212  +    *:SolidBSD:*:*)
          213  +	echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}
          214  +	exit ;;
          215  +    macppc:MirBSD:*:*)
          216  +	echo powerpc-unknown-mirbsd${UNAME_RELEASE}
          217  +	exit ;;
          218  +    *:MirBSD:*:*)
          219  +	echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
          220  +	exit ;;
          221  +    alpha:OSF1:*:*)
          222  +	case $UNAME_RELEASE in
          223  +	*4.0)
          224  +		UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
          225  +		;;
          226  +	*5.*)
          227  +	        UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
          228  +		;;
          229  +	esac
          230  +	# According to Compaq, /usr/sbin/psrinfo has been available on
          231  +	# OSF/1 and Tru64 systems produced since 1995.  I hope that
          232  +	# covers most systems running today.  This code pipes the CPU
          233  +	# types through head -n 1, so we only detect the type of CPU 0.
          234  +	ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^  The alpha \(.*\) processor.*$/\1/p' | head -n 1`
          235  +	case "$ALPHA_CPU_TYPE" in
          236  +	    "EV4 (21064)")
          237  +		UNAME_MACHINE="alpha" ;;
          238  +	    "EV4.5 (21064)")
          239  +		UNAME_MACHINE="alpha" ;;
          240  +	    "LCA4 (21066/21068)")
          241  +		UNAME_MACHINE="alpha" ;;
          242  +	    "EV5 (21164)")
          243  +		UNAME_MACHINE="alphaev5" ;;
          244  +	    "EV5.6 (21164A)")
          245  +		UNAME_MACHINE="alphaev56" ;;
          246  +	    "EV5.6 (21164PC)")
          247  +		UNAME_MACHINE="alphapca56" ;;
          248  +	    "EV5.7 (21164PC)")
          249  +		UNAME_MACHINE="alphapca57" ;;
          250  +	    "EV6 (21264)")
          251  +		UNAME_MACHINE="alphaev6" ;;
          252  +	    "EV6.7 (21264A)")
          253  +		UNAME_MACHINE="alphaev67" ;;
          254  +	    "EV6.8CB (21264C)")
          255  +		UNAME_MACHINE="alphaev68" ;;
          256  +	    "EV6.8AL (21264B)")
          257  +		UNAME_MACHINE="alphaev68" ;;
          258  +	    "EV6.8CX (21264D)")
          259  +		UNAME_MACHINE="alphaev68" ;;
          260  +	    "EV6.9A (21264/EV69A)")
          261  +		UNAME_MACHINE="alphaev69" ;;
          262  +	    "EV7 (21364)")
          263  +		UNAME_MACHINE="alphaev7" ;;
          264  +	    "EV7.9 (21364A)")
          265  +		UNAME_MACHINE="alphaev79" ;;
          266  +	esac
          267  +	# A Pn.n version is a patched version.
          268  +	# A Vn.n version is a released version.
          269  +	# A Tn.n version is a released field test version.
          270  +	# A Xn.n version is an unreleased experimental baselevel.
          271  +	# 1.2 uses "1.2" for uname -r.
          272  +	echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
          273  +	exit ;;
          274  +    Alpha\ *:Windows_NT*:*)
          275  +	# How do we know it's Interix rather than the generic POSIX subsystem?
          276  +	# Should we change UNAME_MACHINE based on the output of uname instead
          277  +	# of the specific Alpha model?
          278  +	echo alpha-pc-interix
          279  +	exit ;;
          280  +    21064:Windows_NT:50:3)
          281  +	echo alpha-dec-winnt3.5
          282  +	exit ;;
          283  +    Amiga*:UNIX_System_V:4.0:*)
          284  +	echo m68k-unknown-sysv4
          285  +	exit ;;
          286  +    *:[Aa]miga[Oo][Ss]:*:*)
          287  +	echo ${UNAME_MACHINE}-unknown-amigaos
          288  +	exit ;;
          289  +    *:[Mm]orph[Oo][Ss]:*:*)
          290  +	echo ${UNAME_MACHINE}-unknown-morphos
          291  +	exit ;;
          292  +    *:OS/390:*:*)
          293  +	echo i370-ibm-openedition
          294  +	exit ;;
          295  +    *:z/VM:*:*)
          296  +	echo s390-ibm-zvmoe
          297  +	exit ;;
          298  +    *:OS400:*:*)
          299  +        echo powerpc-ibm-os400
          300  +	exit ;;
          301  +    arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
          302  +	echo arm-acorn-riscix${UNAME_RELEASE}
          303  +	exit ;;
          304  +    arm:riscos:*:*|arm:RISCOS:*:*)
          305  +	echo arm-unknown-riscos
          306  +	exit ;;
          307  +    SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
          308  +	echo hppa1.1-hitachi-hiuxmpp
          309  +	exit ;;
          310  +    Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
          311  +	# akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
          312  +	if test "`(/bin/universe) 2>/dev/null`" = att ; then
          313  +		echo pyramid-pyramid-sysv3
          314  +	else
          315  +		echo pyramid-pyramid-bsd
          316  +	fi
          317  +	exit ;;
          318  +    NILE*:*:*:dcosx)
          319  +	echo pyramid-pyramid-svr4
          320  +	exit ;;
          321  +    DRS?6000:unix:4.0:6*)
          322  +	echo sparc-icl-nx6
          323  +	exit ;;
          324  +    DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
          325  +	case `/usr/bin/uname -p` in
          326  +	    sparc) echo sparc-icl-nx7; exit ;;
          327  +	esac ;;
          328  +    s390x:SunOS:*:*)
          329  +	echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
          330  +	exit ;;
          331  +    sun4H:SunOS:5.*:*)
          332  +	echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
          333  +	exit ;;
          334  +    sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
          335  +	echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
          336  +	exit ;;
          337  +    i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*)
          338  +	echo i386-pc-auroraux${UNAME_RELEASE}
          339  +	exit ;;
          340  +    i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
          341  +	eval $set_cc_for_build
          342  +	SUN_ARCH="i386"
          343  +	# If there is a compiler, see if it is configured for 64-bit objects.
          344  +	# Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
          345  +	# This test works for both compilers.
          346  +	if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
          347  +	    if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
          348  +		(CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
          349  +		grep IS_64BIT_ARCH >/dev/null
          350  +	    then
          351  +		SUN_ARCH="x86_64"
          352  +	    fi
          353  +	fi
          354  +	echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
          355  +	exit ;;
          356  +    sun4*:SunOS:6*:*)
          357  +	# According to config.sub, this is the proper way to canonicalize
          358  +	# SunOS6.  Hard to guess exactly what SunOS6 will be like, but
          359  +	# it's likely to be more like Solaris than SunOS4.
          360  +	echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
          361  +	exit ;;
          362  +    sun4*:SunOS:*:*)
          363  +	case "`/usr/bin/arch -k`" in
          364  +	    Series*|S4*)
          365  +		UNAME_RELEASE=`uname -v`
          366  +		;;
          367  +	esac
          368  +	# Japanese Language versions have a version number like `4.1.3-JL'.
          369  +	echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
          370  +	exit ;;
          371  +    sun3*:SunOS:*:*)
          372  +	echo m68k-sun-sunos${UNAME_RELEASE}
          373  +	exit ;;
          374  +    sun*:*:4.2BSD:*)
          375  +	UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
          376  +	test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
          377  +	case "`/bin/arch`" in
          378  +	    sun3)
          379  +		echo m68k-sun-sunos${UNAME_RELEASE}
          380  +		;;
          381  +	    sun4)
          382  +		echo sparc-sun-sunos${UNAME_RELEASE}
          383  +		;;
          384  +	esac
          385  +	exit ;;
          386  +    aushp:SunOS:*:*)
          387  +	echo sparc-auspex-sunos${UNAME_RELEASE}
          388  +	exit ;;
          389  +    # The situation for MiNT is a little confusing.  The machine name
          390  +    # can be virtually everything (everything which is not
          391  +    # "atarist" or "atariste" at least should have a processor
          392  +    # > m68000).  The system name ranges from "MiNT" over "FreeMiNT"
          393  +    # to the lowercase version "mint" (or "freemint").  Finally
          394  +    # the system name "TOS" denotes a system which is actually not
          395  +    # MiNT.  But MiNT is downward compatible to TOS, so this should
          396  +    # be no problem.
          397  +    atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
          398  +        echo m68k-atari-mint${UNAME_RELEASE}
          399  +	exit ;;
          400  +    atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
          401  +	echo m68k-atari-mint${UNAME_RELEASE}
          402  +        exit ;;
          403  +    *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
          404  +        echo m68k-atari-mint${UNAME_RELEASE}
          405  +	exit ;;
          406  +    milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
          407  +        echo m68k-milan-mint${UNAME_RELEASE}
          408  +        exit ;;
          409  +    hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
          410  +        echo m68k-hades-mint${UNAME_RELEASE}
          411  +        exit ;;
          412  +    *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
          413  +        echo m68k-unknown-mint${UNAME_RELEASE}
          414  +        exit ;;
          415  +    m68k:machten:*:*)
          416  +	echo m68k-apple-machten${UNAME_RELEASE}
          417  +	exit ;;
          418  +    powerpc:machten:*:*)
          419  +	echo powerpc-apple-machten${UNAME_RELEASE}
          420  +	exit ;;
          421  +    RISC*:Mach:*:*)
          422  +	echo mips-dec-mach_bsd4.3
          423  +	exit ;;
          424  +    RISC*:ULTRIX:*:*)
          425  +	echo mips-dec-ultrix${UNAME_RELEASE}
          426  +	exit ;;
          427  +    VAX*:ULTRIX*:*:*)
          428  +	echo vax-dec-ultrix${UNAME_RELEASE}
          429  +	exit ;;
          430  +    2020:CLIX:*:* | 2430:CLIX:*:*)
          431  +	echo clipper-intergraph-clix${UNAME_RELEASE}
          432  +	exit ;;
          433  +    mips:*:*:UMIPS | mips:*:*:RISCos)
          434  +	eval $set_cc_for_build
          435  +	sed 's/^	//' << EOF >$dummy.c
          436  +#ifdef __cplusplus
          437  +#include <stdio.h>  /* for printf() prototype */
          438  +	int main (int argc, char *argv[]) {
          439  +#else
          440  +	int main (argc, argv) int argc; char *argv[]; {
          441  +#endif
          442  +	#if defined (host_mips) && defined (MIPSEB)
          443  +	#if defined (SYSTYPE_SYSV)
          444  +	  printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
          445  +	#endif
          446  +	#if defined (SYSTYPE_SVR4)
          447  +	  printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
          448  +	#endif
          449  +	#if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
          450  +	  printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
          451  +	#endif
          452  +	#endif
          453  +	  exit (-1);
          454  +	}
          455  +EOF
          456  +	$CC_FOR_BUILD -o $dummy $dummy.c &&
          457  +	  dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` &&
          458  +	  SYSTEM_NAME=`$dummy $dummyarg` &&
          459  +	    { echo "$SYSTEM_NAME"; exit; }
          460  +	echo mips-mips-riscos${UNAME_RELEASE}
          461  +	exit ;;
          462  +    Motorola:PowerMAX_OS:*:*)
          463  +	echo powerpc-motorola-powermax
          464  +	exit ;;
          465  +    Motorola:*:4.3:PL8-*)
          466  +	echo powerpc-harris-powermax
          467  +	exit ;;
          468  +    Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
          469  +	echo powerpc-harris-powermax
          470  +	exit ;;
          471  +    Night_Hawk:Power_UNIX:*:*)
          472  +	echo powerpc-harris-powerunix
          473  +	exit ;;
          474  +    m88k:CX/UX:7*:*)
          475  +	echo m88k-harris-cxux7
          476  +	exit ;;
          477  +    m88k:*:4*:R4*)
          478  +	echo m88k-motorola-sysv4
          479  +	exit ;;
          480  +    m88k:*:3*:R3*)
          481  +	echo m88k-motorola-sysv3
          482  +	exit ;;
          483  +    AViiON:dgux:*:*)
          484  +        # DG/UX returns AViiON for all architectures
          485  +        UNAME_PROCESSOR=`/usr/bin/uname -p`
          486  +	if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
          487  +	then
          488  +	    if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
          489  +	       [ ${TARGET_BINARY_INTERFACE}x = x ]
          490  +	    then
          491  +		echo m88k-dg-dgux${UNAME_RELEASE}
          492  +	    else
          493  +		echo m88k-dg-dguxbcs${UNAME_RELEASE}
          494  +	    fi
          495  +	else
          496  +	    echo i586-dg-dgux${UNAME_RELEASE}
          497  +	fi
          498  + 	exit ;;
          499  +    M88*:DolphinOS:*:*)	# DolphinOS (SVR3)
          500  +	echo m88k-dolphin-sysv3
          501  +	exit ;;
          502  +    M88*:*:R3*:*)
          503  +	# Delta 88k system running SVR3
          504  +	echo m88k-motorola-sysv3
          505  +	exit ;;
          506  +    XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
          507  +	echo m88k-tektronix-sysv3
          508  +	exit ;;
          509  +    Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
          510  +	echo m68k-tektronix-bsd
          511  +	exit ;;
          512  +    *:IRIX*:*:*)
          513  +	echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
          514  +	exit ;;
          515  +    ????????:AIX?:[12].1:2)   # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
          516  +	echo romp-ibm-aix     # uname -m gives an 8 hex-code CPU id
          517  +	exit ;;               # Note that: echo "'`uname -s`'" gives 'AIX '
          518  +    i*86:AIX:*:*)
          519  +	echo i386-ibm-aix
          520  +	exit ;;
          521  +    ia64:AIX:*:*)
          522  +	if [ -x /usr/bin/oslevel ] ; then
          523  +		IBM_REV=`/usr/bin/oslevel`
          524  +	else
          525  +		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
          526  +	fi
          527  +	echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
          528  +	exit ;;
          529  +    *:AIX:2:3)
          530  +	if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
          531  +		eval $set_cc_for_build
          532  +		sed 's/^		//' << EOF >$dummy.c
          533  +		#include <sys/systemcfg.h>
          534  +
          535  +		main()
          536  +			{
          537  +			if (!__power_pc())
          538  +				exit(1);
          539  +			puts("powerpc-ibm-aix3.2.5");
          540  +			exit(0);
          541  +			}
          542  +EOF
          543  +		if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy`
          544  +		then
          545  +			echo "$SYSTEM_NAME"
          546  +		else
          547  +			echo rs6000-ibm-aix3.2.5
          548  +		fi
          549  +	elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
          550  +		echo rs6000-ibm-aix3.2.4
          551  +	else
          552  +		echo rs6000-ibm-aix3.2
          553  +	fi
          554  +	exit ;;
          555  +    *:AIX:*:[4567])
          556  +	IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
          557  +	if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
          558  +		IBM_ARCH=rs6000
          559  +	else
          560  +		IBM_ARCH=powerpc
          561  +	fi
          562  +	if [ -x /usr/bin/oslevel ] ; then
          563  +		IBM_REV=`/usr/bin/oslevel`
          564  +	else
          565  +		IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
          566  +	fi
          567  +	echo ${IBM_ARCH}-ibm-aix${IBM_REV}
          568  +	exit ;;
          569  +    *:AIX:*:*)
          570  +	echo rs6000-ibm-aix
          571  +	exit ;;
          572  +    ibmrt:4.4BSD:*|romp-ibm:BSD:*)
          573  +	echo romp-ibm-bsd4.4
          574  +	exit ;;
          575  +    ibmrt:*BSD:*|romp-ibm:BSD:*)            # covers RT/PC BSD and
          576  +	echo romp-ibm-bsd${UNAME_RELEASE}   # 4.3 with uname added to
          577  +	exit ;;                             # report: romp-ibm BSD 4.3
          578  +    *:BOSX:*:*)
          579  +	echo rs6000-bull-bosx
          580  +	exit ;;
          581  +    DPX/2?00:B.O.S.:*:*)
          582  +	echo m68k-bull-sysv3
          583  +	exit ;;
          584  +    9000/[34]??:4.3bsd:1.*:*)
          585  +	echo m68k-hp-bsd
          586  +	exit ;;
          587  +    hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
          588  +	echo m68k-hp-bsd4.4
          589  +	exit ;;
          590  +    9000/[34678]??:HP-UX:*:*)
          591  +	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
          592  +	case "${UNAME_MACHINE}" in
          593  +	    9000/31? )            HP_ARCH=m68000 ;;
          594  +	    9000/[34]?? )         HP_ARCH=m68k ;;
          595  +	    9000/[678][0-9][0-9])
          596  +		if [ -x /usr/bin/getconf ]; then
          597  +		    sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
          598  +                    sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
          599  +                    case "${sc_cpu_version}" in
          600  +                      523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
          601  +                      528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
          602  +                      532)                      # CPU_PA_RISC2_0
          603  +                        case "${sc_kernel_bits}" in
          604  +                          32) HP_ARCH="hppa2.0n" ;;
          605  +                          64) HP_ARCH="hppa2.0w" ;;
          606  +			  '') HP_ARCH="hppa2.0" ;;   # HP-UX 10.20
          607  +                        esac ;;
          608  +                    esac
          609  +		fi
          610  +		if [ "${HP_ARCH}" = "" ]; then
          611  +		    eval $set_cc_for_build
          612  +		    sed 's/^              //' << EOF >$dummy.c
          613  +
          614  +              #define _HPUX_SOURCE
          615  +              #include <stdlib.h>
          616  +              #include <unistd.h>
          617  +
          618  +              int main ()
          619  +              {
          620  +              #if defined(_SC_KERNEL_BITS)
          621  +                  long bits = sysconf(_SC_KERNEL_BITS);
          622  +              #endif
          623  +                  long cpu  = sysconf (_SC_CPU_VERSION);
          624  +
          625  +                  switch (cpu)
          626  +              	{
          627  +              	case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
          628  +              	case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
          629  +              	case CPU_PA_RISC2_0:
          630  +              #if defined(_SC_KERNEL_BITS)
          631  +              	    switch (bits)
          632  +              		{
          633  +              		case 64: puts ("hppa2.0w"); break;
          634  +              		case 32: puts ("hppa2.0n"); break;
          635  +              		default: puts ("hppa2.0"); break;
          636  +              		} break;
          637  +              #else  /* !defined(_SC_KERNEL_BITS) */
          638  +              	    puts ("hppa2.0"); break;
          639  +              #endif
          640  +              	default: puts ("hppa1.0"); break;
          641  +              	}
          642  +                  exit (0);
          643  +              }
          644  +EOF
          645  +		    (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
          646  +		    test -z "$HP_ARCH" && HP_ARCH=hppa
          647  +		fi ;;
          648  +	esac
          649  +	if [ ${HP_ARCH} = "hppa2.0w" ]
          650  +	then
          651  +	    eval $set_cc_for_build
          652  +
          653  +	    # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
          654  +	    # 32-bit code.  hppa64-hp-hpux* has the same kernel and a compiler
          655  +	    # generating 64-bit code.  GNU and HP use different nomenclature:
          656  +	    #
          657  +	    # $ CC_FOR_BUILD=cc ./config.guess
          658  +	    # => hppa2.0w-hp-hpux11.23
          659  +	    # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess
          660  +	    # => hppa64-hp-hpux11.23
          661  +
          662  +	    if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
          663  +		grep -q __LP64__
          664  +	    then
          665  +		HP_ARCH="hppa2.0w"
          666  +	    else
          667  +		HP_ARCH="hppa64"
          668  +	    fi
          669  +	fi
          670  +	echo ${HP_ARCH}-hp-hpux${HPUX_REV}
          671  +	exit ;;
          672  +    ia64:HP-UX:*:*)
          673  +	HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
          674  +	echo ia64-hp-hpux${HPUX_REV}
          675  +	exit ;;
          676  +    3050*:HI-UX:*:*)
          677  +	eval $set_cc_for_build
          678  +	sed 's/^	//' << EOF >$dummy.c
          679  +	#include <unistd.h>
          680  +	int
          681  +	main ()
          682  +	{
          683  +	  long cpu = sysconf (_SC_CPU_VERSION);
          684  +	  /* The order matters, because CPU_IS_HP_MC68K erroneously returns
          685  +	     true for CPU_PA_RISC1_0.  CPU_IS_PA_RISC returns correct
          686  +	     results, however.  */
          687  +	  if (CPU_IS_PA_RISC (cpu))
          688  +	    {
          689  +	      switch (cpu)
          690  +		{
          691  +		  case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
          692  +		  case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
          693  +		  case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
          694  +		  default: puts ("hppa-hitachi-hiuxwe2"); break;
          695  +		}
          696  +	    }
          697  +	  else if (CPU_IS_HP_MC68K (cpu))
          698  +	    puts ("m68k-hitachi-hiuxwe2");
          699  +	  else puts ("unknown-hitachi-hiuxwe2");
          700  +	  exit (0);
          701  +	}
          702  +EOF
          703  +	$CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` &&
          704  +		{ echo "$SYSTEM_NAME"; exit; }
          705  +	echo unknown-hitachi-hiuxwe2
          706  +	exit ;;
          707  +    9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
          708  +	echo hppa1.1-hp-bsd
          709  +	exit ;;
          710  +    9000/8??:4.3bsd:*:*)
          711  +	echo hppa1.0-hp-bsd
          712  +	exit ;;
          713  +    *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
          714  +	echo hppa1.0-hp-mpeix
          715  +	exit ;;
          716  +    hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
          717  +	echo hppa1.1-hp-osf
          718  +	exit ;;
          719  +    hp8??:OSF1:*:*)
          720  +	echo hppa1.0-hp-osf
          721  +	exit ;;
          722  +    i*86:OSF1:*:*)
          723  +	if [ -x /usr/sbin/sysversion ] ; then
          724  +	    echo ${UNAME_MACHINE}-unknown-osf1mk
          725  +	else
          726  +	    echo ${UNAME_MACHINE}-unknown-osf1
          727  +	fi
          728  +	exit ;;
          729  +    parisc*:Lites*:*:*)
          730  +	echo hppa1.1-hp-lites
          731  +	exit ;;
          732  +    C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
          733  +	echo c1-convex-bsd
          734  +        exit ;;
          735  +    C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
          736  +	if getsysinfo -f scalar_acc
          737  +	then echo c32-convex-bsd
          738  +	else echo c2-convex-bsd
          739  +	fi
          740  +        exit ;;
          741  +    C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
          742  +	echo c34-convex-bsd
          743  +        exit ;;
          744  +    C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
          745  +	echo c38-convex-bsd
          746  +        exit ;;
          747  +    C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
          748  +	echo c4-convex-bsd
          749  +        exit ;;
          750  +    CRAY*Y-MP:*:*:*)
          751  +	echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
          752  +	exit ;;
          753  +    CRAY*[A-Z]90:*:*:*)
          754  +	echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
          755  +	| sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
          756  +	      -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
          757  +	      -e 's/\.[^.]*$/.X/'
          758  +	exit ;;
          759  +    CRAY*TS:*:*:*)
          760  +	echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
          761  +	exit ;;
          762  +    CRAY*T3E:*:*:*)
          763  +	echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
          764  +	exit ;;
          765  +    CRAY*SV1:*:*:*)
          766  +	echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
          767  +	exit ;;
          768  +    *:UNICOS/mp:*:*)
          769  +	echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
          770  +	exit ;;
          771  +    F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
          772  +	FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
          773  +        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
          774  +        FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
          775  +        echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
          776  +        exit ;;
          777  +    5000:UNIX_System_V:4.*:*)
          778  +        FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
          779  +        FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
          780  +        echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
          781  +	exit ;;
          782  +    i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
          783  +	echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
          784  +	exit ;;
          785  +    sparc*:BSD/OS:*:*)
          786  +	echo sparc-unknown-bsdi${UNAME_RELEASE}
          787  +	exit ;;
          788  +    *:BSD/OS:*:*)
          789  +	echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
          790  +	exit ;;
          791  +    *:FreeBSD:*:*)
          792  +	case ${UNAME_MACHINE} in
          793  +	    pc98)
          794  +		echo i386-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
          795  +	    amd64)
          796  +		echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
          797  +	    *)
          798  +		echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
          799  +	esac
          800  +	exit ;;
          801  +    i*:CYGWIN*:*)
          802  +	echo ${UNAME_MACHINE}-pc-cygwin
          803  +	exit ;;
          804  +    *:MINGW*:*)
          805  +	echo ${UNAME_MACHINE}-pc-mingw32
          806  +	exit ;;
          807  +    i*:windows32*:*)
          808  +    	# uname -m includes "-pc" on this system.
          809  +    	echo ${UNAME_MACHINE}-mingw32
          810  +	exit ;;
          811  +    i*:PW*:*)
          812  +	echo ${UNAME_MACHINE}-pc-pw32
          813  +	exit ;;
          814  +    *:Interix*:*)
          815  +    	case ${UNAME_MACHINE} in
          816  +	    x86)
          817  +		echo i586-pc-interix${UNAME_RELEASE}
          818  +		exit ;;
          819  +	    authenticamd | genuineintel | EM64T)
          820  +		echo x86_64-unknown-interix${UNAME_RELEASE}
          821  +		exit ;;
          822  +	    IA64)
          823  +		echo ia64-unknown-interix${UNAME_RELEASE}
          824  +		exit ;;
          825  +	esac ;;
          826  +    [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
          827  +	echo i${UNAME_MACHINE}-pc-mks
          828  +	exit ;;
          829  +    8664:Windows_NT:*)
          830  +	echo x86_64-pc-mks
          831  +	exit ;;
          832  +    i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
          833  +	# How do we know it's Interix rather than the generic POSIX subsystem?
          834  +	# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
          835  +	# UNAME_MACHINE based on the output of uname instead of i386?
          836  +	echo i586-pc-interix
          837  +	exit ;;
          838  +    i*:UWIN*:*)
          839  +	echo ${UNAME_MACHINE}-pc-uwin
          840  +	exit ;;
          841  +    amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
          842  +	echo x86_64-unknown-cygwin
          843  +	exit ;;
          844  +    p*:CYGWIN*:*)
          845  +	echo powerpcle-unknown-cygwin
          846  +	exit ;;
          847  +    prep*:SunOS:5.*:*)
          848  +	echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
          849  +	exit ;;
          850  +    *:GNU:*:*)
          851  +	# the GNU system
          852  +	echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
          853  +	exit ;;
          854  +    *:GNU/*:*:*)
          855  +	# other systems with GNU libc and userland
          856  +	echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-gnu
          857  +	exit ;;
          858  +    i*86:Minix:*:*)
          859  +	echo ${UNAME_MACHINE}-pc-minix
          860  +	exit ;;
          861  +    alpha:Linux:*:*)
          862  +	case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
          863  +	  EV5)   UNAME_MACHINE=alphaev5 ;;
          864  +	  EV56)  UNAME_MACHINE=alphaev56 ;;
          865  +	  PCA56) UNAME_MACHINE=alphapca56 ;;
          866  +	  PCA57) UNAME_MACHINE=alphapca56 ;;
          867  +	  EV6)   UNAME_MACHINE=alphaev6 ;;
          868  +	  EV67)  UNAME_MACHINE=alphaev67 ;;
          869  +	  EV68*) UNAME_MACHINE=alphaev68 ;;
          870  +        esac
          871  +	objdump --private-headers /bin/sh | grep -q ld.so.1
          872  +	if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi
          873  +	echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC}
          874  +	exit ;;
          875  +    arm*:Linux:*:*)
          876  +	eval $set_cc_for_build
          877  +	if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
          878  +	    | grep -q __ARM_EABI__
          879  +	then
          880  +	    echo ${UNAME_MACHINE}-unknown-linux-gnu
          881  +	else
          882  +	    echo ${UNAME_MACHINE}-unknown-linux-gnueabi
          883  +	fi
          884  +	exit ;;
          885  +    avr32*:Linux:*:*)
          886  +	echo ${UNAME_MACHINE}-unknown-linux-gnu
          887  +	exit ;;
          888  +    cris:Linux:*:*)
          889  +	echo cris-axis-linux-gnu
          890  +	exit ;;
          891  +    crisv32:Linux:*:*)
          892  +	echo crisv32-axis-linux-gnu
          893  +	exit ;;
          894  +    frv:Linux:*:*)
          895  +    	echo frv-unknown-linux-gnu
          896  +	exit ;;
          897  +    i*86:Linux:*:*)
          898  +	LIBC=gnu
          899  +	eval $set_cc_for_build
          900  +	sed 's/^	//' << EOF >$dummy.c
          901  +	#ifdef __dietlibc__
          902  +	LIBC=dietlibc
          903  +	#endif
          904  +EOF
          905  +	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC'`
          906  +	echo "${UNAME_MACHINE}-pc-linux-${LIBC}"
          907  +	exit ;;
          908  +    ia64:Linux:*:*)
          909  +	echo ${UNAME_MACHINE}-unknown-linux-gnu
          910  +	exit ;;
          911  +    m32r*:Linux:*:*)
          912  +	echo ${UNAME_MACHINE}-unknown-linux-gnu
          913  +	exit ;;
          914  +    m68*:Linux:*:*)
          915  +	echo ${UNAME_MACHINE}-unknown-linux-gnu
          916  +	exit ;;
          917  +    mips:Linux:*:* | mips64:Linux:*:*)
          918  +	eval $set_cc_for_build
          919  +	sed 's/^	//' << EOF >$dummy.c
          920  +	#undef CPU
          921  +	#undef ${UNAME_MACHINE}
          922  +	#undef ${UNAME_MACHINE}el
          923  +	#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
          924  +	CPU=${UNAME_MACHINE}el
          925  +	#else
          926  +	#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
          927  +	CPU=${UNAME_MACHINE}
          928  +	#else
          929  +	CPU=
          930  +	#endif
          931  +	#endif
          932  +EOF
          933  +	eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`
          934  +	test x"${CPU}" != x && { echo "${CPU}-unknown-linux-gnu"; exit; }
          935  +	;;
          936  +    or32:Linux:*:*)
          937  +	echo or32-unknown-linux-gnu
          938  +	exit ;;
          939  +    padre:Linux:*:*)
          940  +	echo sparc-unknown-linux-gnu
          941  +	exit ;;
          942  +    parisc64:Linux:*:* | hppa64:Linux:*:*)
          943  +	echo hppa64-unknown-linux-gnu
          944  +	exit ;;
          945  +    parisc:Linux:*:* | hppa:Linux:*:*)
          946  +	# Look for CPU level
          947  +	case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
          948  +	  PA7*) echo hppa1.1-unknown-linux-gnu ;;
          949  +	  PA8*) echo hppa2.0-unknown-linux-gnu ;;
          950  +	  *)    echo hppa-unknown-linux-gnu ;;
          951  +	esac
          952  +	exit ;;
          953  +    ppc64:Linux:*:*)
          954  +	echo powerpc64-unknown-linux-gnu
          955  +	exit ;;
          956  +    ppc:Linux:*:*)
          957  +	echo powerpc-unknown-linux-gnu
          958  +	exit ;;
          959  +    s390:Linux:*:* | s390x:Linux:*:*)
          960  +	echo ${UNAME_MACHINE}-ibm-linux
          961  +	exit ;;
          962  +    sh64*:Linux:*:*)
          963  +    	echo ${UNAME_MACHINE}-unknown-linux-gnu
          964  +	exit ;;
          965  +    sh*:Linux:*:*)
          966  +	echo ${UNAME_MACHINE}-unknown-linux-gnu
          967  +	exit ;;
          968  +    sparc:Linux:*:* | sparc64:Linux:*:*)
          969  +	echo ${UNAME_MACHINE}-unknown-linux-gnu
          970  +	exit ;;
          971  +    tile*:Linux:*:*)
          972  +	echo ${UNAME_MACHINE}-tilera-linux-gnu
          973  +	exit ;;
          974  +    vax:Linux:*:*)
          975  +	echo ${UNAME_MACHINE}-dec-linux-gnu
          976  +	exit ;;
          977  +    x86_64:Linux:*:*)
          978  +	echo x86_64-unknown-linux-gnu
          979  +	exit ;;
          980  +    xtensa*:Linux:*:*)
          981  +    	echo ${UNAME_MACHINE}-unknown-linux-gnu
          982  +	exit ;;
          983  +    i*86:DYNIX/ptx:4*:*)
          984  +	# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
          985  +	# earlier versions are messed up and put the nodename in both
          986  +	# sysname and nodename.
          987  +	echo i386-sequent-sysv4
          988  +	exit ;;
          989  +    i*86:UNIX_SV:4.2MP:2.*)
          990  +        # Unixware is an offshoot of SVR4, but it has its own version
          991  +        # number series starting with 2...
          992  +        # I am not positive that other SVR4 systems won't match this,
          993  +	# I just have to hope.  -- rms.
          994  +        # Use sysv4.2uw... so that sysv4* matches it.
          995  +	echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
          996  +	exit ;;
          997  +    i*86:OS/2:*:*)
          998  +	# If we were able to find `uname', then EMX Unix compatibility
          999  +	# is probably installed.
         1000  +	echo ${UNAME_MACHINE}-pc-os2-emx
         1001  +	exit ;;
         1002  +    i*86:XTS-300:*:STOP)
         1003  +	echo ${UNAME_MACHINE}-unknown-stop
         1004  +	exit ;;
         1005  +    i*86:atheos:*:*)
         1006  +	echo ${UNAME_MACHINE}-unknown-atheos
         1007  +	exit ;;
         1008  +    i*86:syllable:*:*)
         1009  +	echo ${UNAME_MACHINE}-pc-syllable
         1010  +	exit ;;
         1011  +    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*)
         1012  +	echo i386-unknown-lynxos${UNAME_RELEASE}
         1013  +	exit ;;
         1014  +    i*86:*DOS:*:*)
         1015  +	echo ${UNAME_MACHINE}-pc-msdosdjgpp
         1016  +	exit ;;
         1017  +    i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
         1018  +	UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
         1019  +	if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
         1020  +		echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL}
         1021  +	else
         1022  +		echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
         1023  +	fi
         1024  +	exit ;;
         1025  +    i*86:*:5:[678]*)
         1026  +    	# UnixWare 7.x, OpenUNIX and OpenServer 6.
         1027  +	case `/bin/uname -X | grep "^Machine"` in
         1028  +	    *486*)	     UNAME_MACHINE=i486 ;;
         1029  +	    *Pentium)	     UNAME_MACHINE=i586 ;;
         1030  +	    *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
         1031  +	esac
         1032  +	echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
         1033  +	exit ;;
         1034  +    i*86:*:3.2:*)
         1035  +	if test -f /usr/options/cb.name; then
         1036  +		UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
         1037  +		echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
         1038  +	elif /bin/uname -X 2>/dev/null >/dev/null ; then
         1039  +		UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
         1040  +		(/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
         1041  +		(/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
         1042  +			&& UNAME_MACHINE=i586
         1043  +		(/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
         1044  +			&& UNAME_MACHINE=i686
         1045  +		(/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
         1046  +			&& UNAME_MACHINE=i686
         1047  +		echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
         1048  +	else
         1049  +		echo ${UNAME_MACHINE}-pc-sysv32
         1050  +	fi
         1051  +	exit ;;
         1052  +    pc:*:*:*)
         1053  +	# Left here for compatibility:
         1054  +        # uname -m prints for DJGPP always 'pc', but it prints nothing about
         1055  +        # the processor, so we play safe by assuming i586.
         1056  +	# Note: whatever this is, it MUST be the same as what config.sub
         1057  +	# prints for the "djgpp" host, or else GDB configury will decide that
         1058  +	# this is a cross-build.
         1059  +	echo i586-pc-msdosdjgpp
         1060  +        exit ;;
         1061  +    Intel:Mach:3*:*)
         1062  +	echo i386-pc-mach3
         1063  +	exit ;;
         1064  +    paragon:*:*:*)
         1065  +	echo i860-intel-osf1
         1066  +	exit ;;
         1067  +    i860:*:4.*:*) # i860-SVR4
         1068  +	if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
         1069  +	  echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
         1070  +	else # Add other i860-SVR4 vendors below as they are discovered.
         1071  +	  echo i860-unknown-sysv${UNAME_RELEASE}  # Unknown i860-SVR4
         1072  +	fi
         1073  +	exit ;;
         1074  +    mini*:CTIX:SYS*5:*)
         1075  +	# "miniframe"
         1076  +	echo m68010-convergent-sysv
         1077  +	exit ;;
         1078  +    mc68k:UNIX:SYSTEM5:3.51m)
         1079  +	echo m68k-convergent-sysv
         1080  +	exit ;;
         1081  +    M680?0:D-NIX:5.3:*)
         1082  +	echo m68k-diab-dnix
         1083  +	exit ;;
         1084  +    M68*:*:R3V[5678]*:*)
         1085  +	test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
         1086  +    3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
         1087  +	OS_REL=''
         1088  +	test -r /etc/.relid \
         1089  +	&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
         1090  +	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
         1091  +	  && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
         1092  +	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
         1093  +	  && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
         1094  +    3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
         1095  +        /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
         1096  +          && { echo i486-ncr-sysv4; exit; } ;;
         1097  +    NCR*:*:4.2:* | MPRAS*:*:4.2:*)
         1098  +	OS_REL='.3'
         1099  +	test -r /etc/.relid \
         1100  +	    && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
         1101  +	/bin/uname -p 2>/dev/null | grep 86 >/dev/null \
         1102  +	    && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
         1103  +	/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
         1104  +	    && { echo i586-ncr-sysv4.3${OS_REL}; exit; }
         1105  +	/bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \
         1106  +	    && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
         1107  +    m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
         1108  +	echo m68k-unknown-lynxos${UNAME_RELEASE}
         1109  +	exit ;;
         1110  +    mc68030:UNIX_System_V:4.*:*)
         1111  +	echo m68k-atari-sysv4
         1112  +	exit ;;
         1113  +    TSUNAMI:LynxOS:2.*:*)
         1114  +	echo sparc-unknown-lynxos${UNAME_RELEASE}
         1115  +	exit ;;
         1116  +    rs6000:LynxOS:2.*:*)
         1117  +	echo rs6000-unknown-lynxos${UNAME_RELEASE}
         1118  +	exit ;;
         1119  +    PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*)
         1120  +	echo powerpc-unknown-lynxos${UNAME_RELEASE}
         1121  +	exit ;;
         1122  +    SM[BE]S:UNIX_SV:*:*)
         1123  +	echo mips-dde-sysv${UNAME_RELEASE}
         1124  +	exit ;;
         1125  +    RM*:ReliantUNIX-*:*:*)
         1126  +	echo mips-sni-sysv4
         1127  +	exit ;;
         1128  +    RM*:SINIX-*:*:*)
         1129  +	echo mips-sni-sysv4
         1130  +	exit ;;
         1131  +    *:SINIX-*:*:*)
         1132  +	if uname -p 2>/dev/null >/dev/null ; then
         1133  +		UNAME_MACHINE=`(uname -p) 2>/dev/null`
         1134  +		echo ${UNAME_MACHINE}-sni-sysv4
         1135  +	else
         1136  +		echo ns32k-sni-sysv
         1137  +	fi
         1138  +	exit ;;
         1139  +    PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
         1140  +                      # says <Richard.M.Bartel@ccMail.Census.GOV>
         1141  +        echo i586-unisys-sysv4
         1142  +        exit ;;
         1143  +    *:UNIX_System_V:4*:FTX*)
         1144  +	# From Gerald Hewes <hewes@openmarket.com>.
         1145  +	# How about differentiating between stratus architectures? -djm
         1146  +	echo hppa1.1-stratus-sysv4
         1147  +	exit ;;
         1148  +    *:*:*:FTX*)
         1149  +	# From seanf@swdc.stratus.com.
         1150  +	echo i860-stratus-sysv4
         1151  +	exit ;;
         1152  +    i*86:VOS:*:*)
         1153  +	# From Paul.Green@stratus.com.
         1154  +	echo ${UNAME_MACHINE}-stratus-vos
         1155  +	exit ;;
         1156  +    *:VOS:*:*)
         1157  +	# From Paul.Green@stratus.com.
         1158  +	echo hppa1.1-stratus-vos
         1159  +	exit ;;
         1160  +    mc68*:A/UX:*:*)
         1161  +	echo m68k-apple-aux${UNAME_RELEASE}
         1162  +	exit ;;
         1163  +    news*:NEWS-OS:6*:*)
         1164  +	echo mips-sony-newsos6
         1165  +	exit ;;
         1166  +    R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
         1167  +	if [ -d /usr/nec ]; then
         1168  +	        echo mips-nec-sysv${UNAME_RELEASE}
         1169  +	else
         1170  +	        echo mips-unknown-sysv${UNAME_RELEASE}
         1171  +	fi
         1172  +        exit ;;
         1173  +    BeBox:BeOS:*:*)	# BeOS running on hardware made by Be, PPC only.
         1174  +	echo powerpc-be-beos
         1175  +	exit ;;
         1176  +    BeMac:BeOS:*:*)	# BeOS running on Mac or Mac clone, PPC only.
         1177  +	echo powerpc-apple-beos
         1178  +	exit ;;
         1179  +    BePC:BeOS:*:*)	# BeOS running on Intel PC compatible.
         1180  +	echo i586-pc-beos
         1181  +	exit ;;
         1182  +    BePC:Haiku:*:*)	# Haiku running on Intel PC compatible.
         1183  +	echo i586-pc-haiku
         1184  +	exit ;;
         1185  +    SX-4:SUPER-UX:*:*)
         1186  +	echo sx4-nec-superux${UNAME_RELEASE}
         1187  +	exit ;;
         1188  +    SX-5:SUPER-UX:*:*)
         1189  +	echo sx5-nec-superux${UNAME_RELEASE}
         1190  +	exit ;;
         1191  +    SX-6:SUPER-UX:*:*)
         1192  +	echo sx6-nec-superux${UNAME_RELEASE}
         1193  +	exit ;;
         1194  +    SX-7:SUPER-UX:*:*)
         1195  +	echo sx7-nec-superux${UNAME_RELEASE}
         1196  +	exit ;;
         1197  +    SX-8:SUPER-UX:*:*)
         1198  +	echo sx8-nec-superux${UNAME_RELEASE}
         1199  +	exit ;;
         1200  +    SX-8R:SUPER-UX:*:*)
         1201  +	echo sx8r-nec-superux${UNAME_RELEASE}
         1202  +	exit ;;
         1203  +    Power*:Rhapsody:*:*)
         1204  +	echo powerpc-apple-rhapsody${UNAME_RELEASE}
         1205  +	exit ;;
         1206  +    *:Rhapsody:*:*)
         1207  +	echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
         1208  +	exit ;;
         1209  +    *:Darwin:*:*)
         1210  +	UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
         1211  +	case $UNAME_PROCESSOR in
         1212  +	    i386)
         1213  +		eval $set_cc_for_build
         1214  +		if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
         1215  +		  if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
         1216  +		      (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
         1217  +		      grep IS_64BIT_ARCH >/dev/null
         1218  +		  then
         1219  +		      UNAME_PROCESSOR="x86_64"
         1220  +		  fi
         1221  +		fi ;;
         1222  +	    unknown) UNAME_PROCESSOR=powerpc ;;
         1223  +	esac
         1224  +	echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
         1225  +	exit ;;
         1226  +    *:procnto*:*:* | *:QNX:[0123456789]*:*)
         1227  +	UNAME_PROCESSOR=`uname -p`
         1228  +	if test "$UNAME_PROCESSOR" = "x86"; then
         1229  +		UNAME_PROCESSOR=i386
         1230  +		UNAME_MACHINE=pc
         1231  +	fi
         1232  +	echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
         1233  +	exit ;;
         1234  +    *:QNX:*:4*)
         1235  +	echo i386-pc-qnx
         1236  +	exit ;;
         1237  +    NEO-?:NONSTOP_KERNEL:*:*)
         1238  +	echo neo-tandem-nsk${UNAME_RELEASE}
         1239  +	exit ;;
         1240  +    NSE-?:NONSTOP_KERNEL:*:*)
         1241  +	echo nse-tandem-nsk${UNAME_RELEASE}
         1242  +	exit ;;
         1243  +    NSR-?:NONSTOP_KERNEL:*:*)
         1244  +	echo nsr-tandem-nsk${UNAME_RELEASE}
         1245  +	exit ;;
         1246  +    *:NonStop-UX:*:*)
         1247  +	echo mips-compaq-nonstopux
         1248  +	exit ;;
         1249  +    BS2000:POSIX*:*:*)
         1250  +	echo bs2000-siemens-sysv
         1251  +	exit ;;
         1252  +    DS/*:UNIX_System_V:*:*)
         1253  +	echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
         1254  +	exit ;;
         1255  +    *:Plan9:*:*)
         1256  +	# "uname -m" is not consistent, so use $cputype instead. 386
         1257  +	# is converted to i386 for consistency with other x86
         1258  +	# operating systems.
         1259  +	if test "$cputype" = "386"; then
         1260  +	    UNAME_MACHINE=i386
         1261  +	else
         1262  +	    UNAME_MACHINE="$cputype"
         1263  +	fi
         1264  +	echo ${UNAME_MACHINE}-unknown-plan9
         1265  +	exit ;;
         1266  +    *:TOPS-10:*:*)
         1267  +	echo pdp10-unknown-tops10
         1268  +	exit ;;
         1269  +    *:TENEX:*:*)
         1270  +	echo pdp10-unknown-tenex
         1271  +	exit ;;
         1272  +    KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
         1273  +	echo pdp10-dec-tops20
         1274  +	exit ;;
         1275  +    XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
         1276  +	echo pdp10-xkl-tops20
         1277  +	exit ;;
         1278  +    *:TOPS-20:*:*)
         1279  +	echo pdp10-unknown-tops20
         1280  +	exit ;;
         1281  +    *:ITS:*:*)
         1282  +	echo pdp10-unknown-its
         1283  +	exit ;;
         1284  +    SEI:*:*:SEIUX)
         1285  +        echo mips-sei-seiux${UNAME_RELEASE}
         1286  +	exit ;;
         1287  +    *:DragonFly:*:*)
         1288  +	echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
         1289  +	exit ;;
         1290  +    *:*VMS:*:*)
         1291  +    	UNAME_MACHINE=`(uname -p) 2>/dev/null`
         1292  +	case "${UNAME_MACHINE}" in
         1293  +	    A*) echo alpha-dec-vms ; exit ;;
         1294  +	    I*) echo ia64-dec-vms ; exit ;;
         1295  +	    V*) echo vax-dec-vms ; exit ;;
         1296  +	esac ;;
         1297  +    *:XENIX:*:SysV)
         1298  +	echo i386-pc-xenix
         1299  +	exit ;;
         1300  +    i*86:skyos:*:*)
         1301  +	echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'
         1302  +	exit ;;
         1303  +    i*86:rdos:*:*)
         1304  +	echo ${UNAME_MACHINE}-pc-rdos
         1305  +	exit ;;
         1306  +    i*86:AROS:*:*)
         1307  +	echo ${UNAME_MACHINE}-pc-aros
         1308  +	exit ;;
         1309  +esac
         1310  +
         1311  +#echo '(No uname command or uname output not recognized.)' 1>&2
         1312  +#echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2
         1313  +
         1314  +eval $set_cc_for_build
         1315  +cat >$dummy.c <<EOF
         1316  +#ifdef _SEQUENT_
         1317  +# include <sys/types.h>
         1318  +# include <sys/utsname.h>
         1319  +#endif
         1320  +main ()
         1321  +{
         1322  +#if defined (sony)
         1323  +#if defined (MIPSEB)
         1324  +  /* BFD wants "bsd" instead of "newsos".  Perhaps BFD should be changed,
         1325  +     I don't know....  */
         1326  +  printf ("mips-sony-bsd\n"); exit (0);
         1327  +#else
         1328  +#include <sys/param.h>
         1329  +  printf ("m68k-sony-newsos%s\n",
         1330  +#ifdef NEWSOS4
         1331  +          "4"
         1332  +#else
         1333  +	  ""
         1334  +#endif
         1335  +         ); exit (0);
         1336  +#endif
         1337  +#endif
         1338  +
         1339  +#if defined (__arm) && defined (__acorn) && defined (__unix)
         1340  +  printf ("arm-acorn-riscix\n"); exit (0);
         1341  +#endif
         1342  +
         1343  +#if defined (hp300) && !defined (hpux)
         1344  +  printf ("m68k-hp-bsd\n"); exit (0);
         1345  +#endif
         1346  +
         1347  +#if defined (NeXT)
         1348  +#if !defined (__ARCHITECTURE__)
         1349  +#define __ARCHITECTURE__ "m68k"
         1350  +#endif
         1351  +  int version;
         1352  +  version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`;
         1353  +  if (version < 4)
         1354  +    printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version);
         1355  +  else
         1356  +    printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version);
         1357  +  exit (0);
         1358  +#endif
         1359  +
         1360  +#if defined (MULTIMAX) || defined (n16)
         1361  +#if defined (UMAXV)
         1362  +  printf ("ns32k-encore-sysv\n"); exit (0);
         1363  +#else
         1364  +#if defined (CMU)
         1365  +  printf ("ns32k-encore-mach\n"); exit (0);
         1366  +#else
         1367  +  printf ("ns32k-encore-bsd\n"); exit (0);
         1368  +#endif
         1369  +#endif
         1370  +#endif
         1371  +
         1372  +#if defined (__386BSD__)
         1373  +  printf ("i386-pc-bsd\n"); exit (0);
         1374  +#endif
         1375  +
         1376  +#if defined (sequent)
         1377  +#if defined (i386)
         1378  +  printf ("i386-sequent-dynix\n"); exit (0);
         1379  +#endif
         1380  +#if defined (ns32000)
         1381  +  printf ("ns32k-sequent-dynix\n"); exit (0);
         1382  +#endif
         1383  +#endif
         1384  +
         1385  +#if defined (_SEQUENT_)
         1386  +    struct utsname un;
         1387  +
         1388  +    uname(&un);
         1389  +
         1390  +    if (strncmp(un.version, "V2", 2) == 0) {
         1391  +	printf ("i386-sequent-ptx2\n"); exit (0);
         1392  +    }
         1393  +    if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */
         1394  +	printf ("i386-sequent-ptx1\n"); exit (0);
         1395  +    }
         1396  +    printf ("i386-sequent-ptx\n"); exit (0);
         1397  +
         1398  +#endif
         1399  +
         1400  +#if defined (vax)
         1401  +# if !defined (ultrix)
         1402  +#  include <sys/param.h>
         1403  +#  if defined (BSD)
         1404  +#   if BSD == 43
         1405  +      printf ("vax-dec-bsd4.3\n"); exit (0);
         1406  +#   else
         1407  +#    if BSD == 199006
         1408  +      printf ("vax-dec-bsd4.3reno\n"); exit (0);
         1409  +#    else
         1410  +      printf ("vax-dec-bsd\n"); exit (0);
         1411  +#    endif
         1412  +#   endif
         1413  +#  else
         1414  +    printf ("vax-dec-bsd\n"); exit (0);
         1415  +#  endif
         1416  +# else
         1417  +    printf ("vax-dec-ultrix\n"); exit (0);
         1418  +# endif
         1419  +#endif
         1420  +
         1421  +#if defined (alliant) && defined (i860)
         1422  +  printf ("i860-alliant-bsd\n"); exit (0);
         1423  +#endif
         1424  +
         1425  +  exit (1);
         1426  +}
         1427  +EOF
         1428  +
         1429  +$CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && SYSTEM_NAME=`$dummy` &&
         1430  +	{ echo "$SYSTEM_NAME"; exit; }
         1431  +
         1432  +# Apollos put the system type in the environment.
         1433  +
         1434  +test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit; }
         1435  +
         1436  +# Convex versions that predate uname can use getsysinfo(1)
         1437  +
         1438  +if [ -x /usr/convex/getsysinfo ]
         1439  +then
         1440  +    case `getsysinfo -f cpu_type` in
         1441  +    c1*)
         1442  +	echo c1-convex-bsd
         1443  +	exit ;;
         1444  +    c2*)
         1445  +	if getsysinfo -f scalar_acc
         1446  +	then echo c32-convex-bsd
         1447  +	else echo c2-convex-bsd
         1448  +	fi
         1449  +	exit ;;
         1450  +    c34*)
         1451  +	echo c34-convex-bsd
         1452  +	exit ;;
         1453  +    c38*)
         1454  +	echo c38-convex-bsd
         1455  +	exit ;;
         1456  +    c4*)
         1457  +	echo c4-convex-bsd
         1458  +	exit ;;
         1459  +    esac
         1460  +fi
         1461  +
         1462  +cat >&2 <<EOF
         1463  +$0: unable to guess system type
         1464  +
         1465  +This script, last modified $timestamp, has failed to recognize
         1466  +the operating system you are using. It is advised that you
         1467  +download the most up to date version of the config scripts from
         1468  +
         1469  +  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
         1470  +and
         1471  +  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
         1472  +
         1473  +If the version you run ($0) is already up to date, please
         1474  +send the following data and any information you think might be
         1475  +pertinent to <config-patches@gnu.org> in order to provide the needed
         1476  +information to handle your system.
         1477  +
         1478  +config.guess timestamp = $timestamp
         1479  +
         1480  +uname -m = `(uname -m) 2>/dev/null || echo unknown`
         1481  +uname -r = `(uname -r) 2>/dev/null || echo unknown`
         1482  +uname -s = `(uname -s) 2>/dev/null || echo unknown`
         1483  +uname -v = `(uname -v) 2>/dev/null || echo unknown`
         1484  +
         1485  +/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null`
         1486  +/bin/uname -X     = `(/bin/uname -X) 2>/dev/null`
         1487  +
         1488  +hostinfo               = `(hostinfo) 2>/dev/null`
         1489  +/bin/universe          = `(/bin/universe) 2>/dev/null`
         1490  +/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null`
         1491  +/bin/arch              = `(/bin/arch) 2>/dev/null`
         1492  +/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null`
         1493  +/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null`
         1494  +
         1495  +UNAME_MACHINE = ${UNAME_MACHINE}
         1496  +UNAME_RELEASE = ${UNAME_RELEASE}
         1497  +UNAME_SYSTEM  = ${UNAME_SYSTEM}
         1498  +UNAME_VERSION = ${UNAME_VERSION}
         1499  +EOF
         1500  +
         1501  +exit 1
         1502  +
         1503  +# Local variables:
         1504  +# eval: (add-hook 'write-file-hooks 'time-stamp)
         1505  +# time-stamp-start: "timestamp='"
         1506  +# time-stamp-format: "%:y-%02m-%02d"
         1507  +# time-stamp-end: "'"
         1508  +# End:

Added autosetup/config.sub.

            1  +#! /bin/sh
            2  +# Configuration validation subroutine script.
            3  +#   Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
            4  +#   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
            5  +#   Free Software Foundation, Inc.
            6  +
            7  +timestamp='2010-09-11'
            8  +
            9  +# This file is (in principle) common to ALL GNU software.
           10  +# The presence of a machine in this file suggests that SOME GNU software
           11  +# can handle that machine.  It does not imply ALL GNU software can.
           12  +#
           13  +# This file is free software; you can redistribute it and/or modify
           14  +# it under the terms of the GNU General Public License as published by
           15  +# the Free Software Foundation; either version 2 of the License, or
           16  +# (at your option) any later version.
           17  +#
           18  +# This program is distributed in the hope that it will be useful,
           19  +# but WITHOUT ANY WARRANTY; without even the implied warranty of
           20  +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
           21  +# GNU General Public License for more details.
           22  +#
           23  +# You should have received a copy of the GNU General Public License
           24  +# along with this program; if not, write to the Free Software
           25  +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
           26  +# 02110-1301, USA.
           27  +#
           28  +# As a special exception to the GNU General Public License, if you
           29  +# distribute this file as part of a program that contains a
           30  +# configuration script generated by Autoconf, you may include it under
           31  +# the same distribution terms that you use for the rest of that program.
           32  +
           33  +
           34  +# Please send patches to <config-patches@gnu.org>.  Submit a context
           35  +# diff and a properly formatted GNU ChangeLog entry.
           36  +#
           37  +# Configuration subroutine to validate and canonicalize a configuration type.
           38  +# Supply the specified configuration type as an argument.
           39  +# If it is invalid, we print an error message on stderr and exit with code 1.
           40  +# Otherwise, we print the canonical config type on stdout and succeed.
           41  +
           42  +# You can get the latest version of this script from:
           43  +# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
           44  +
           45  +# This file is supposed to be the same for all GNU packages
           46  +# and recognize all the CPU types, system types and aliases
           47  +# that are meaningful with *any* GNU software.
           48  +# Each package is responsible for reporting which valid configurations
           49  +# it does not support.  The user should be able to distinguish
           50  +# a failure to support a valid configuration from a meaningless
           51  +# configuration.
           52  +
           53  +# The goal of this file is to map all the various variations of a given
           54  +# machine specification into a single specification in the form:
           55  +#	CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
           56  +# or in some cases, the newer four-part form:
           57  +#	CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
           58  +# It is wrong to echo any other type of specification.
           59  +
           60  +me=`echo "$0" | sed -e 's,.*/,,'`
           61  +
           62  +usage="\
           63  +Usage: $0 [OPTION] CPU-MFR-OPSYS
           64  +       $0 [OPTION] ALIAS
           65  +
           66  +Canonicalize a configuration name.
           67  +
           68  +Operation modes:
           69  +  -h, --help         print this help, then exit
           70  +  -t, --time-stamp   print date of last modification, then exit
           71  +  -v, --version      print version number, then exit
           72  +
           73  +Report bugs and patches to <config-patches@gnu.org>."
           74  +
           75  +version="\
           76  +GNU config.sub ($timestamp)
           77  +
           78  +Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
           79  +2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free
           80  +Software Foundation, Inc.
           81  +
           82  +This is free software; see the source for copying conditions.  There is NO
           83  +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
           84  +
           85  +help="
           86  +Try \`$me --help' for more information."
           87  +
           88  +# Parse command line
           89  +while test $# -gt 0 ; do
           90  +  case $1 in
           91  +    --time-stamp | --time* | -t )
           92  +       echo "$timestamp" ; exit ;;
           93  +    --version | -v )
           94  +       echo "$version" ; exit ;;
           95  +    --help | --h* | -h )
           96  +       echo "$usage"; exit ;;
           97  +    -- )     # Stop option processing
           98  +       shift; break ;;
           99  +    - )	# Use stdin as input.
          100  +       break ;;
          101  +    -* )
          102  +       echo "$me: invalid option $1$help"
          103  +       exit 1 ;;
          104  +
          105  +    *local*)
          106  +       # First pass through any local machine types.
          107  +       echo $1
          108  +       exit ;;
          109  +
          110  +    * )
          111  +       break ;;
          112  +  esac
          113  +done
          114  +
          115  +case $# in
          116  + 0) echo "$me: missing argument$help" >&2
          117  +    exit 1;;
          118  + 1) ;;
          119  + *) echo "$me: too many arguments$help" >&2
          120  +    exit 1;;
          121  +esac
          122  +
          123  +# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
          124  +# Here we must recognize all the valid KERNEL-OS combinations.
          125  +maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
          126  +case $maybe_os in
          127  +  nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
          128  +  linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
          129  +  knetbsd*-gnu* | netbsd*-gnu* | \
          130  +  kopensolaris*-gnu* | \
          131  +  storm-chaos* | os2-emx* | rtmk-nova*)
          132  +    os=-$maybe_os
          133  +    basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
          134  +    ;;
          135  +  *)
          136  +    basic_machine=`echo $1 | sed 's/-[^-]*$//'`
          137  +    if [ $basic_machine != $1 ]
          138  +    then os=`echo $1 | sed 's/.*-/-/'`
          139  +    else os=; fi
          140  +    ;;
          141  +esac
          142  +
          143  +### Let's recognize common machines as not being operating systems so
          144  +### that things like config.sub decstation-3100 work.  We also
          145  +### recognize some manufacturers as not being operating systems, so we
          146  +### can provide default operating systems below.
          147  +case $os in
          148  +	-sun*os*)
          149  +		# Prevent following clause from handling this invalid input.
          150  +		;;
          151  +	-dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
          152  +	-att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
          153  +	-unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
          154  +	-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
          155  +	-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
          156  +	-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
          157  +	-apple | -axis | -knuth | -cray | -microblaze)
          158  +		os=
          159  +		basic_machine=$1
          160  +		;;
          161  +        -bluegene*)
          162  +	        os=-cnk
          163  +		;;
          164  +	-sim | -cisco | -oki | -wec | -winbond)
          165  +		os=
          166  +		basic_machine=$1
          167  +		;;
          168  +	-scout)
          169  +		;;
          170  +	-wrs)
          171  +		os=-vxworks
          172  +		basic_machine=$1
          173  +		;;
          174  +	-chorusos*)
          175  +		os=-chorusos
          176  +		basic_machine=$1
          177  +		;;
          178  + 	-chorusrdb)
          179  + 		os=-chorusrdb
          180  +		basic_machine=$1
          181  + 		;;
          182  +	-hiux*)
          183  +		os=-hiuxwe2
          184  +		;;
          185  +	-sco6)
          186  +		os=-sco5v6
          187  +		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
          188  +		;;
          189  +	-sco5)
          190  +		os=-sco3.2v5
          191  +		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
          192  +		;;
          193  +	-sco4)
          194  +		os=-sco3.2v4
          195  +		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
          196  +		;;
          197  +	-sco3.2.[4-9]*)
          198  +		os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
          199  +		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
          200  +		;;
          201  +	-sco3.2v[4-9]*)
          202  +		# Don't forget version if it is 3.2v4 or newer.
          203  +		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
          204  +		;;
          205  +	-sco5v6*)
          206  +		# Don't forget version if it is 3.2v4 or newer.
          207  +		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
          208  +		;;
          209  +	-sco*)
          210  +		os=-sco3.2v2
          211  +		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
          212  +		;;
          213  +	-udk*)
          214  +		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
          215  +		;;
          216  +	-isc)
          217  +		os=-isc2.2
          218  +		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
          219  +		;;
          220  +	-clix*)
          221  +		basic_machine=clipper-intergraph
          222  +		;;
          223  +	-isc*)
          224  +		basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
          225  +		;;
          226  +	-lynx*)
          227  +		os=-lynxos
          228  +		;;
          229  +	-ptx*)
          230  +		basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
          231  +		;;
          232  +	-windowsnt*)
          233  +		os=`echo $os | sed -e 's/windowsnt/winnt/'`
          234  +		;;
          235  +	-psos*)
          236  +		os=-psos
          237  +		;;
          238  +	-mint | -mint[0-9]*)
          239  +		basic_machine=m68k-atari
          240  +		os=-mint
          241  +		;;
          242  +esac
          243  +
          244  +# Decode aliases for certain CPU-COMPANY combinations.
          245  +case $basic_machine in
          246  +	# Recognize the basic CPU types without company name.
          247  +	# Some are omitted here because they have special meanings below.
          248  +	1750a | 580 \
          249  +	| a29k \
          250  +	| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
          251  +	| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
          252  +	| am33_2.0 \
          253  +	| arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \
          254  +	| bfin \
          255  +	| c4x | clipper \
          256  +	| d10v | d30v | dlx | dsp16xx \
          257  +	| fido | fr30 | frv \
          258  +	| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
          259  +	| i370 | i860 | i960 | ia64 \
          260  +	| ip2k | iq2000 \
          261  +	| lm32 \
          262  +	| m32c | m32r | m32rle | m68000 | m68k | m88k \
          263  +	| maxq | mb | microblaze | mcore | mep | metag \
          264  +	| mips | mipsbe | mipseb | mipsel | mipsle \
          265  +	| mips16 \
          266  +	| mips64 | mips64el \
          267  +	| mips64octeon | mips64octeonel \
          268  +	| mips64orion | mips64orionel \
          269  +	| mips64r5900 | mips64r5900el \
          270  +	| mips64vr | mips64vrel \
          271  +	| mips64vr4100 | mips64vr4100el \
          272  +	| mips64vr4300 | mips64vr4300el \
          273  +	| mips64vr5000 | mips64vr5000el \
          274  +	| mips64vr5900 | mips64vr5900el \
          275  +	| mipsisa32 | mipsisa32el \
          276  +	| mipsisa32r2 | mipsisa32r2el \
          277  +	| mipsisa64 | mipsisa64el \
          278  +	| mipsisa64r2 | mipsisa64r2el \
          279  +	| mipsisa64sb1 | mipsisa64sb1el \
          280  +	| mipsisa64sr71k | mipsisa64sr71kel \
          281  +	| mipstx39 | mipstx39el \
          282  +	| mn10200 | mn10300 \
          283  +	| moxie \
          284  +	| mt \
          285  +	| msp430 \
          286  +	| nds32 | nds32le | nds32be \
          287  +	| nios | nios2 \
          288  +	| ns16k | ns32k \
          289  +	| or32 \
          290  +	| pdp10 | pdp11 | pj | pjl \
          291  +	| powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \
          292  +	| pyramid \
          293  +	| rx \
          294  +	| score \
          295  +	| sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
          296  +	| sh64 | sh64le \
          297  +	| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
          298  +	| sparcv8 | sparcv9 | sparcv9b | sparcv9v \
          299  +	| spu | strongarm \
          300  +	| tahoe | thumb | tic4x | tic54x | tic55x | tic6x | tic80 | tron \
          301  +	| ubicom32 \
          302  +	| v850 | v850e \
          303  +	| we32k \
          304  +	| x86 | xc16x | xscale | xscalee[bl] | xstormy16 | xtensa \
          305  +	| z8k | z80)
          306  +		basic_machine=$basic_machine-unknown
          307  +		;;
          308  +	c54x)
          309  +		basic_machine=tic54x-unknown
          310  +		;;
          311  +	c55x)
          312  +		basic_machine=tic55x-unknown
          313  +		;;
          314  +	c6x)
          315  +		basic_machine=tic6x-unknown
          316  +		;;
          317  +	m6811 | m68hc11 | m6812 | m68hc12 | picochip)
          318  +		# Motorola 68HC11/12.
          319  +		basic_machine=$basic_machine-unknown
          320  +		os=-none
          321  +		;;
          322  +	m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
          323  +		;;
          324  +	ms1)
          325  +		basic_machine=mt-unknown
          326  +		;;
          327  +
          328  +	# We use `pc' rather than `unknown'
          329  +	# because (1) that's what they normally are, and
          330  +	# (2) the word "unknown" tends to confuse beginning users.
          331  +	i*86 | x86_64)
          332  +	  basic_machine=$basic_machine-pc
          333  +	  ;;
          334  +	# Object if more than one company name word.
          335  +	*-*-*)
          336  +		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
          337  +		exit 1
          338  +		;;
          339  +	# Recognize the basic CPU types with company name.
          340  +	580-* \
          341  +	| a29k-* \
          342  +	| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
          343  +	| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
          344  +	| alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
          345  +	| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \
          346  +	| avr-* | avr32-* \
          347  +	| bfin-* | bs2000-* \
          348  +	| c[123]* | c30-* | [cjt]90-* | c4x-* \
          349  +	| clipper-* | craynv-* | cydra-* \
          350  +	| d10v-* | d30v-* | dlx-* \
          351  +	| elxsi-* \
          352  +	| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
          353  +	| h8300-* | h8500-* \
          354  +	| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
          355  +	| i*86-* | i860-* | i960-* | ia64-* \
          356  +	| ip2k-* | iq2000-* \
          357  +	| lm32-* \
          358  +	| m32c-* | m32r-* | m32rle-* \
          359  +	| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
          360  +	| m88110-* | m88k-* | maxq-* | mcore-* | metag-* | microblaze-* \
          361  +	| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
          362  +	| mips16-* \
          363  +	| mips64-* | mips64el-* \
          364  +	| mips64octeon-* | mips64octeonel-* \
          365  +	| mips64orion-* | mips64orionel-* \
          366  +	| mips64r5900-* | mips64r5900el-* \
          367  +	| mips64vr-* | mips64vrel-* \
          368  +	| mips64vr4100-* | mips64vr4100el-* \
          369  +	| mips64vr4300-* | mips64vr4300el-* \
          370  +	| mips64vr5000-* | mips64vr5000el-* \
          371  +	| mips64vr5900-* | mips64vr5900el-* \
          372  +	| mipsisa32-* | mipsisa32el-* \
          373  +	| mipsisa32r2-* | mipsisa32r2el-* \
          374  +	| mipsisa64-* | mipsisa64el-* \
          375  +	| mipsisa64r2-* | mipsisa64r2el-* \
          376  +	| mipsisa64sb1-* | mipsisa64sb1el-* \
          377  +	| mipsisa64sr71k-* | mipsisa64sr71kel-* \
          378  +	| mipstx39-* | mipstx39el-* \
          379  +	| mmix-* \
          380  +	| mt-* \
          381  +	| msp430-* \
          382  +	| nds32-* | nds32le-* | nds32be-* \
          383  +	| nios-* | nios2-* \
          384  +	| none-* | np1-* | ns16k-* | ns32k-* \
          385  +	| orion-* \
          386  +	| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
          387  +	| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \
          388  +	| pyramid-* \
          389  +	| romp-* | rs6000-* | rx-* \
          390  +	| sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
          391  +	| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
          392  +	| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
          393  +	| sparclite-* \
          394  +	| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | strongarm-* | sv1-* | sx?-* \
          395  +	| tahoe-* | thumb-* \
          396  +	| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
          397  +	| tile-* | tilegx-* \
          398  +	| tron-* \
          399  +	| ubicom32-* \
          400  +	| v850-* | v850e-* | vax-* \
          401  +	| we32k-* \
          402  +	| x86-* | x86_64-* | xc16x-* | xps100-* | xscale-* | xscalee[bl]-* \
          403  +	| xstormy16-* | xtensa*-* \
          404  +	| ymp-* \
          405  +	| z8k-* | z80-*)
          406  +		;;
          407  +	# Recognize the basic CPU types without company name, with glob match.
          408  +	xtensa*)
          409  +		basic_machine=$basic_machine-unknown
          410  +		;;
          411  +	# Recognize the various machine names and aliases which stand
          412  +	# for a CPU type and a company and sometimes even an OS.
          413  +	386bsd)
          414  +		basic_machine=i386-unknown
          415  +		os=-bsd
          416  +		;;
          417  +	3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
          418  +		basic_machine=m68000-att
          419  +		;;
          420  +	3b*)
          421  +		basic_machine=we32k-att
          422  +		;;
          423  +	a29khif)
          424  +		basic_machine=a29k-amd
          425  +		os=-udi
          426  +		;;
          427  +    	abacus)
          428  +		basic_machine=abacus-unknown
          429  +		;;
          430  +	adobe68k)
          431  +		basic_machine=m68010-adobe
          432  +		os=-scout
          433  +		;;
          434  +	alliant | fx80)
          435  +		basic_machine=fx80-alliant
          436  +		;;
          437  +	altos | altos3068)
          438  +		basic_machine=m68k-altos
          439  +		;;
          440  +	am29k)
          441  +		basic_machine=a29k-none
          442  +		os=-bsd
          443  +		;;
          444  +	amd64)
          445  +		basic_machine=x86_64-pc
          446  +		;;
          447  +	amd64-*)
          448  +		basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
          449  +		;;
          450  +	amdahl)
          451  +		basic_machine=580-amdahl
          452  +		os=-sysv
          453  +		;;
          454  +	amiga | amiga-*)
          455  +		basic_machine=m68k-unknown
          456  +		;;
          457  +	amigaos | amigados)
          458  +		basic_machine=m68k-unknown
          459  +		os=-amigaos
          460  +		;;
          461  +	amigaunix | amix)
          462  +		basic_machine=m68k-unknown
          463  +		os=-sysv4
          464  +		;;
          465  +	apollo68)
          466  +		basic_machine=m68k-apollo
          467  +		os=-sysv
          468  +		;;
          469  +	apollo68bsd)
          470  +		basic_machine=m68k-apollo
          471  +		os=-bsd
          472  +		;;
          473  +	aros)
          474  +		basic_machine=i386-pc
          475  +		os=-aros
          476  +		;;
          477  +	aux)
          478  +		basic_machine=m68k-apple
          479  +		os=-aux
          480  +		;;
          481  +	balance)
          482  +		basic_machine=ns32k-sequent
          483  +		os=-dynix
          484  +		;;
          485  +	blackfin)
          486  +		basic_machine=bfin-unknown
          487  +		os=-linux
          488  +		;;
          489  +	blackfin-*)
          490  +		basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'`
          491  +		os=-linux
          492  +		;;
          493  +	bluegene*)
          494  +		basic_machine=powerpc-ibm
          495  +		os=-cnk
          496  +		;;
          497  +	c54x-*)
          498  +		basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'`
          499  +		;;
          500  +	c55x-*)
          501  +		basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'`
          502  +		;;
          503  +	c6x-*)
          504  +		basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'`
          505  +		;;
          506  +	c90)
          507  +		basic_machine=c90-cray
          508  +		os=-unicos
          509  +		;;
          510  +        cegcc)
          511  +		basic_machine=arm-unknown
          512  +		os=-cegcc
          513  +		;;
          514  +	convex-c1)
          515  +		basic_machine=c1-convex
          516  +		os=-bsd
          517  +		;;
          518  +	convex-c2)
          519  +		basic_machine=c2-convex
          520  +		os=-bsd
          521  +		;;
          522  +	convex-c32)
          523  +		basic_machine=c32-convex
          524  +		os=-bsd
          525  +		;;
          526  +	convex-c34)
          527  +		basic_machine=c34-convex
          528  +		os=-bsd
          529  +		;;
          530  +	convex-c38)
          531  +		basic_machine=c38-convex
          532  +		os=-bsd
          533  +		;;
          534  +	cray | j90)
          535  +		basic_machine=j90-cray
          536  +		os=-unicos
          537  +		;;
          538  +	craynv)
          539  +		basic_machine=craynv-cray
          540  +		os=-unicosmp
          541  +		;;
          542  +	cr16)
          543  +		basic_machine=cr16-unknown
          544  +		os=-elf
          545  +		;;
          546  +	crds | unos)
          547  +		basic_machine=m68k-crds
          548  +		;;
          549  +	crisv32 | crisv32-* | etraxfs*)
          550  +		basic_machine=crisv32-axis
          551  +		;;
          552  +	cris | cris-* | etrax*)
          553  +		basic_machine=cris-axis
          554  +		;;
          555  +	crx)
          556  +		basic_machine=crx-unknown
          557  +		os=-elf
          558  +		;;
          559  +	da30 | da30-*)
          560  +		basic_machine=m68k-da30
          561  +		;;
          562  +	decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
          563  +		basic_machine=mips-dec
          564  +		;;
          565  +	decsystem10* | dec10*)
          566  +		basic_machine=pdp10-dec
          567  +		os=-tops10
          568  +		;;
          569  +	decsystem20* | dec20*)
          570  +		basic_machine=pdp10-dec
          571  +		os=-tops20
          572  +		;;
          573  +	delta | 3300 | motorola-3300 | motorola-delta \
          574  +	      | 3300-motorola | delta-motorola)
          575  +		basic_machine=m68k-motorola
          576  +		;;
          577  +	delta88)
          578  +		basic_machine=m88k-motorola
          579  +		os=-sysv3
          580  +		;;
          581  +	dicos)
          582  +		basic_machine=i686-pc
          583  +		os=-dicos
          584  +		;;
          585  +	djgpp)
          586  +		basic_machine=i586-pc
          587  +		os=-msdosdjgpp
          588  +		;;
          589  +	dpx20 | dpx20-*)
          590  +		basic_machine=rs6000-bull
          591  +		os=-bosx
          592  +		;;
          593  +	dpx2* | dpx2*-bull)
          594  +		basic_machine=m68k-bull
          595  +		os=-sysv3
          596  +		;;
          597  +	ebmon29k)
          598  +		basic_machine=a29k-amd
          599  +		os=-ebmon
          600  +		;;
          601  +	elxsi)
          602  +		basic_machine=elxsi-elxsi
          603  +		os=-bsd
          604  +		;;
          605  +	encore | umax | mmax)
          606  +		basic_machine=ns32k-encore
          607  +		;;
          608  +	es1800 | OSE68k | ose68k | ose | OSE)
          609  +		basic_machine=m68k-ericsson
          610  +		os=-ose
          611  +		;;
          612  +	fx2800)
          613  +		basic_machine=i860-alliant
          614  +		;;
          615  +	genix)
          616  +		basic_machine=ns32k-ns
          617  +		;;
          618  +	gmicro)
          619  +		basic_machine=tron-gmicro
          620  +		os=-sysv
          621  +		;;
          622  +	go32)
          623  +		basic_machine=i386-pc
          624  +		os=-go32
          625  +		;;
          626  +	h3050r* | hiux*)
          627  +		basic_machine=hppa1.1-hitachi
          628  +		os=-hiuxwe2
          629  +		;;
          630  +	h8300hms)
          631  +		basic_machine=h8300-hitachi
          632  +		os=-hms
          633  +		;;
          634  +	h8300xray)
          635  +		basic_machine=h8300-hitachi
          636  +		os=-xray
          637  +		;;
          638  +	h8500hms)
          639  +		basic_machine=h8500-hitachi
          640  +		os=-hms
          641  +		;;
          642  +	harris)
          643  +		basic_machine=m88k-harris
          644  +		os=-sysv3
          645  +		;;
          646  +	hp300-*)
          647  +		basic_machine=m68k-hp
          648  +		;;
          649  +	hp300bsd)
          650  +		basic_machine=m68k-hp
          651  +		os=-bsd
          652  +		;;
          653  +	hp300hpux)
          654  +		basic_machine=m68k-hp
          655  +		os=-hpux
          656  +		;;
          657  +	hp3k9[0-9][0-9] | hp9[0-9][0-9])
          658  +		basic_machine=hppa1.0-hp
          659  +		;;
          660  +	hp9k2[0-9][0-9] | hp9k31[0-9])
          661  +		basic_machine=m68000-hp
          662  +		;;
          663  +	hp9k3[2-9][0-9])
          664  +		basic_machine=m68k-hp
          665  +		;;
          666  +	hp9k6[0-9][0-9] | hp6[0-9][0-9])
          667  +		basic_machine=hppa1.0-hp
          668  +		;;
          669  +	hp9k7[0-79][0-9] | hp7[0-79][0-9])
          670  +		basic_machine=hppa1.1-hp
          671  +		;;
          672  +	hp9k78[0-9] | hp78[0-9])
          673  +		# FIXME: really hppa2.0-hp
          674  +		basic_machine=hppa1.1-hp
          675  +		;;
          676  +	hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
          677  +		# FIXME: really hppa2.0-hp
          678  +		basic_machine=hppa1.1-hp
          679  +		;;
          680  +	hp9k8[0-9][13679] | hp8[0-9][13679])
          681  +		basic_machine=hppa1.1-hp
          682  +		;;
          683  +	hp9k8[0-9][0-9] | hp8[0-9][0-9])
          684  +		basic_machine=hppa1.0-hp
          685  +		;;
          686  +	hppa-next)
          687  +		os=-nextstep3
          688  +		;;
          689  +	hppaosf)
          690  +		basic_machine=hppa1.1-hp
          691  +		os=-osf
          692  +		;;
          693  +	hppro)
          694  +		basic_machine=hppa1.1-hp
          695  +		os=-proelf
          696  +		;;
          697  +	i370-ibm* | ibm*)
          698  +		basic_machine=i370-ibm
          699  +		;;
          700  +# I'm not sure what "Sysv32" means.  Should this be sysv3.2?
          701  +	i*86v32)
          702  +		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
          703  +		os=-sysv32
          704  +		;;
          705  +	i*86v4*)
          706  +		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
          707  +		os=-sysv4
          708  +		;;
          709  +	i*86v)
          710  +		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
          711  +		os=-sysv
          712  +		;;
          713  +	i*86sol2)
          714  +		basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
          715  +		os=-solaris2
          716  +		;;
          717  +	i386mach)
          718  +		basic_machine=i386-mach
          719  +		os=-mach
          720  +		;;
          721  +	i386-vsta | vsta)
          722  +		basic_machine=i386-unknown
          723  +		os=-vsta
          724  +		;;
          725  +	iris | iris4d)
          726  +		basic_machine=mips-sgi
          727  +		case $os in
          728  +		    -irix*)
          729  +			;;
          730  +		    *)
          731  +			os=-irix4
          732  +			;;
          733  +		esac
          734  +		;;
          735  +	isi68 | isi)
          736  +		basic_machine=m68k-isi
          737  +		os=-sysv
          738  +		;;
          739  +	m68knommu)
          740  +		basic_machine=m68k-unknown
          741  +		os=-linux
          742  +		;;
          743  +	m68knommu-*)
          744  +		basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'`
          745  +		os=-linux
          746  +		;;
          747  +	m88k-omron*)
          748  +		basic_machine=m88k-omron
          749  +		;;
          750  +	magnum | m3230)
          751  +		basic_machine=mips-mips
          752  +		os=-sysv
          753  +		;;
          754  +	merlin)
          755  +		basic_machine=ns32k-utek
          756  +		os=-sysv
          757  +		;;
          758  +        microblaze)
          759  +		basic_machine=microblaze-xilinx
          760  +		;;
          761  +	mingw32)
          762  +		basic_machine=i386-pc
          763  +		os=-mingw32
          764  +		;;
          765  +	mingw32ce)
          766  +		basic_machine=arm-unknown
          767  +		os=-mingw32ce
          768  +		;;
          769  +	miniframe)
          770  +		basic_machine=m68000-convergent
          771  +		;;
          772  +	*mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
          773  +		basic_machine=m68k-atari
          774  +		os=-mint
          775  +		;;
          776  +	mips3*-*)
          777  +		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
          778  +		;;
          779  +	mips3*)
          780  +		basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
          781  +		;;
          782  +	monitor)
          783  +		basic_machine=m68k-rom68k
          784  +		os=-coff
          785  +		;;
          786  +	morphos)
          787  +		basic_machine=powerpc-unknown
          788  +		os=-morphos
          789  +		;;
          790  +	msdos)
          791  +		basic_machine=i386-pc
          792  +		os=-msdos
          793  +		;;
          794  +	ms1-*)
          795  +		basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
          796  +		;;
          797  +	mvs)
          798  +		basic_machine=i370-ibm
          799  +		os=-mvs
          800  +		;;
          801  +	ncr3000)
          802  +		basic_machine=i486-ncr
          803  +		os=-sysv4
          804  +		;;
          805  +	netbsd386)
          806  +		basic_machine=i386-unknown
          807  +		os=-netbsd
          808  +		;;
          809  +	netwinder)
          810  +		basic_machine=armv4l-rebel
          811  +		os=-linux
          812  +		;;
          813  +	news | news700 | news800 | news900)
          814  +		basic_machine=m68k-sony
          815  +		os=-newsos
          816  +		;;
          817  +	news1000)
          818  +		basic_machine=m68030-sony
          819  +		os=-newsos
          820  +		;;
          821  +	news-3600 | risc-news)
          822  +		basic_machine=mips-sony
          823  +		os=-newsos
          824  +		;;
          825  +	necv70)
          826  +		basic_machine=v70-nec
          827  +		os=-sysv
          828  +		;;
          829  +	next | m*-next )
          830  +		basic_machine=m68k-next
          831  +		case $os in
          832  +		    -nextstep* )
          833  +			;;
          834  +		    -ns2*)
          835  +		      os=-nextstep2
          836  +			;;
          837  +		    *)
          838  +		      os=-nextstep3
          839  +			;;
          840  +		esac
          841  +		;;
          842  +	nh3000)
          843  +		basic_machine=m68k-harris
          844  +		os=-cxux
          845  +		;;
          846  +	nh[45]000)
          847  +		basic_machine=m88k-harris
          848  +		os=-cxux
          849  +		;;
          850  +	nindy960)
          851  +		basic_machine=i960-intel
          852  +		os=-nindy
          853  +		;;
          854  +	mon960)
          855  +		basic_machine=i960-intel
          856  +		os=-mon960
          857  +		;;
          858  +	nonstopux)
          859  +		basic_machine=mips-compaq
          860  +		os=-nonstopux
          861  +		;;
          862  +	np1)
          863  +		basic_machine=np1-gould
          864  +		;;
          865  +        neo-tandem)
          866  +		basic_machine=neo-tandem
          867  +		;;
          868  +        nse-tandem)
          869  +		basic_machine=nse-tandem
          870  +		;;
          871  +	nsr-tandem)
          872  +		basic_machine=nsr-tandem
          873  +		;;
          874  +	op50n-* | op60c-*)
          875  +		basic_machine=hppa1.1-oki
          876  +		os=-proelf
          877  +		;;
          878  +	openrisc | openrisc-*)
          879  +		basic_machine=or32-unknown
          880  +		;;
          881  +	os400)
          882  +		basic_machine=powerpc-ibm
          883  +		os=-os400
          884  +		;;
          885  +	OSE68000 | ose68000)
          886  +		basic_machine=m68000-ericsson
          887  +		os=-ose
          888  +		;;
          889  +	os68k)
          890  +		basic_machine=m68k-none
          891  +		os=-os68k
          892  +		;;
          893  +	pa-hitachi)
          894  +		basic_machine=hppa1.1-hitachi
          895  +		os=-hiuxwe2
          896  +		;;
          897  +	paragon)
          898  +		basic_machine=i860-intel
          899  +		os=-osf
          900  +		;;
          901  +	parisc)
          902  +		basic_machine=hppa-unknown
          903  +		os=-linux
          904  +		;;
          905  +	parisc-*)
          906  +		basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'`
          907  +		os=-linux
          908  +		;;
          909  +	pbd)
          910  +		basic_machine=sparc-tti
          911  +		;;
          912  +	pbb)
          913  +		basic_machine=m68k-tti
          914  +		;;
          915  +	pc532 | pc532-*)
          916  +		basic_machine=ns32k-pc532
          917  +		;;
          918  +	pc98)
          919  +		basic_machine=i386-pc
          920  +		;;
          921  +	pc98-*)
          922  +		basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
          923  +		;;
          924  +	pentium | p5 | k5 | k6 | nexgen | viac3)
          925  +		basic_machine=i586-pc
          926  +		;;
          927  +	pentiumpro | p6 | 6x86 | athlon | athlon_*)
          928  +		basic_machine=i686-pc
          929  +		;;
          930  +	pentiumii | pentium2 | pentiumiii | pentium3)
          931  +		basic_machine=i686-pc
          932  +		;;
          933  +	pentium4)
          934  +		basic_machine=i786-pc
          935  +		;;
          936  +	pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
          937  +		basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
          938  +		;;
          939  +	pentiumpro-* | p6-* | 6x86-* | athlon-*)
          940  +		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
          941  +		;;
          942  +	pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
          943  +		basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
          944  +		;;
          945  +	pentium4-*)
          946  +		basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
          947  +		;;
          948  +	pn)
          949  +		basic_machine=pn-gould
          950  +		;;
          951  +	power)	basic_machine=power-ibm
          952  +		;;
          953  +	ppc)	basic_machine=powerpc-unknown
          954  +		;;
          955  +	ppc-*)	basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
          956  +		;;
          957  +	ppcle | powerpclittle | ppc-le | powerpc-little)
          958  +		basic_machine=powerpcle-unknown
          959  +		;;
          960  +	ppcle-* | powerpclittle-*)
          961  +		basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
          962  +		;;
          963  +	ppc64)	basic_machine=powerpc64-unknown
          964  +		;;
          965  +	ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
          966  +		;;
          967  +	ppc64le | powerpc64little | ppc64-le | powerpc64-little)
          968  +		basic_machine=powerpc64le-unknown
          969  +		;;
          970  +	ppc64le-* | powerpc64little-*)
          971  +		basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
          972  +		;;
          973  +	ps2)
          974  +		basic_machine=i386-ibm
          975  +		;;
          976  +	pw32)
          977  +		basic_machine=i586-unknown
          978  +		os=-pw32
          979  +		;;
          980  +	rdos)
          981  +		basic_machine=i386-pc
          982  +		os=-rdos
          983  +		;;
          984  +	rom68k)
          985  +		basic_machine=m68k-rom68k
          986  +		os=-coff
          987  +		;;
          988  +	rm[46]00)
          989  +		basic_machine=mips-siemens
          990  +		;;
          991  +	rtpc | rtpc-*)
          992  +		basic_machine=romp-ibm
          993  +		;;
          994  +	s390 | s390-*)
          995  +		basic_machine=s390-ibm
          996  +		;;
          997  +	s390x | s390x-*)
          998  +		basic_machine=s390x-ibm
          999  +		;;
         1000  +	sa29200)
         1001  +		basic_machine=a29k-amd
         1002  +		os=-udi
         1003  +		;;
         1004  +	sb1)
         1005  +		basic_machine=mipsisa64sb1-unknown
         1006  +		;;
         1007  +	sb1el)
         1008  +		basic_machine=mipsisa64sb1el-unknown
         1009  +		;;
         1010  +	sde)
         1011  +		basic_machine=mipsisa32-sde
         1012  +		os=-elf
         1013  +		;;
         1014  +	sei)
         1015  +		basic_machine=mips-sei
         1016  +		os=-seiux
         1017  +		;;
         1018  +	sequent)
         1019  +		basic_machine=i386-sequent
         1020  +		;;
         1021  +	sh)
         1022  +		basic_machine=sh-hitachi
         1023  +		os=-hms
         1024  +		;;
         1025  +	sh5el)
         1026  +		basic_machine=sh5le-unknown
         1027  +		;;
         1028  +	sh64)
         1029  +		basic_machine=sh64-unknown
         1030  +		;;
         1031  +	sparclite-wrs | simso-wrs)
         1032  +		basic_machine=sparclite-wrs
         1033  +		os=-vxworks
         1034  +		;;
         1035  +	sps7)
         1036  +		basic_machine=m68k-bull
         1037  +		os=-sysv2
         1038  +		;;
         1039  +	spur)
         1040  +		basic_machine=spur-unknown
         1041  +		;;
         1042  +	st2000)
         1043  +		basic_machine=m68k-tandem
         1044  +		;;
         1045  +	stratus)
         1046  +		basic_machine=i860-stratus
         1047  +		os=-sysv4
         1048  +		;;
         1049  +	sun2)
         1050  +		basic_machine=m68000-sun
         1051  +		;;
         1052  +	sun2os3)
         1053  +		basic_machine=m68000-sun
         1054  +		os=-sunos3
         1055  +		;;
         1056  +	sun2os4)
         1057  +		basic_machine=m68000-sun
         1058  +		os=-sunos4
         1059  +		;;
         1060  +	sun3os3)
         1061  +		basic_machine=m68k-sun
         1062  +		os=-sunos3
         1063  +		;;
         1064  +	sun3os4)
         1065  +		basic_machine=m68k-sun
         1066  +		os=-sunos4
         1067  +		;;
         1068  +	sun4os3)
         1069  +		basic_machine=sparc-sun
         1070  +		os=-sunos3
         1071  +		;;
         1072  +	sun4os4)
         1073  +		basic_machine=sparc-sun
         1074  +		os=-sunos4
         1075  +		;;
         1076  +	sun4sol2)
         1077  +		basic_machine=sparc-sun
         1078  +		os=-solaris2
         1079  +		;;
         1080  +	sun3 | sun3-*)
         1081  +		basic_machine=m68k-sun
         1082  +		;;
         1083  +	sun4)
         1084  +		basic_machine=sparc-sun
         1085  +		;;
         1086  +	sun386 | sun386i | roadrunner)
         1087  +		basic_machine=i386-sun
         1088  +		;;
         1089  +	sv1)
         1090  +		basic_machine=sv1-cray
         1091  +		os=-unicos
         1092  +		;;
         1093  +	symmetry)
         1094  +		basic_machine=i386-sequent
         1095  +		os=-dynix
         1096  +		;;
         1097  +	t3e)
         1098  +		basic_machine=alphaev5-cray
         1099  +		os=-unicos
         1100  +		;;
         1101  +	t90)
         1102  +		basic_machine=t90-cray
         1103  +		os=-unicos
         1104  +		;;
         1105  +        # This must be matched before tile*.
         1106  +        tilegx*)
         1107  +		basic_machine=tilegx-unknown
         1108  +		os=-linux-gnu
         1109  +		;;
         1110  +	tile*)
         1111  +		basic_machine=tile-unknown
         1112  +		os=-linux-gnu
         1113  +		;;
         1114  +	tx39)
         1115  +		basic_machine=mipstx39-unknown
         1116  +		;;
         1117  +	tx39el)
         1118  +		basic_machine=mipstx39el-unknown
         1119  +		;;
         1120  +	toad1)
         1121  +		basic_machine=pdp10-xkl
         1122  +		os=-tops20
         1123  +		;;
         1124  +	tower | tower-32)
         1125  +		basic_machine=m68k-ncr
         1126  +		;;
         1127  +	tpf)
         1128  +		basic_machine=s390x-ibm
         1129  +		os=-tpf
         1130  +		;;
         1131  +	udi29k)
         1132  +		basic_machine=a29k-amd
         1133  +		os=-udi
         1134  +		;;
         1135  +	ultra3)
         1136  +		basic_machine=a29k-nyu
         1137  +		os=-sym1
         1138  +		;;
         1139  +	v810 | necv810)
         1140  +		basic_machine=v810-nec
         1141  +		os=-none
         1142  +		;;
         1143  +	vaxv)
         1144  +		basic_machine=vax-dec
         1145  +		os=-sysv
         1146  +		;;
         1147  +	vms)
         1148  +		basic_machine=vax-dec
         1149  +		os=-vms
         1150  +		;;
         1151  +	vpp*|vx|vx-*)
         1152  +		basic_machine=f301-fujitsu
         1153  +		;;
         1154  +	vxworks960)
         1155  +		basic_machine=i960-wrs
         1156  +		os=-vxworks
         1157  +		;;
         1158  +	vxworks68)
         1159  +		basic_machine=m68k-wrs
         1160  +		os=-vxworks
         1161  +		;;
         1162  +	vxworks29k)
         1163  +		basic_machine=a29k-wrs
         1164  +		os=-vxworks
         1165  +		;;
         1166  +	w65*)
         1167  +		basic_machine=w65-wdc
         1168  +		os=-none
         1169  +		;;
         1170  +	w89k-*)
         1171  +		basic_machine=hppa1.1-winbond
         1172  +		os=-proelf
         1173  +		;;
         1174  +	xbox)
         1175  +		basic_machine=i686-pc
         1176  +		os=-mingw32
         1177  +		;;
         1178  +	xps | xps100)
         1179  +		basic_machine=xps100-honeywell
         1180  +		;;
         1181  +	ymp)
         1182  +		basic_machine=ymp-cray
         1183  +		os=-unicos
         1184  +		;;
         1185  +	z8k-*-coff)
         1186  +		basic_machine=z8k-unknown
         1187  +		os=-sim
         1188  +		;;
         1189  +	z80-*-coff)
         1190  +		basic_machine=z80-unknown
         1191  +		os=-sim
         1192  +		;;
         1193  +	none)
         1194  +		basic_machine=none-none
         1195  +		os=-none
         1196  +		;;
         1197  +
         1198  +# Here we handle the default manufacturer of certain CPU types.  It is in
         1199  +# some cases the only manufacturer, in others, it is the most popular.
         1200  +	w89k)
         1201  +		basic_machine=hppa1.1-winbond
         1202  +		;;
         1203  +	op50n)
         1204  +		basic_machine=hppa1.1-oki
         1205  +		;;
         1206  +	op60c)
         1207  +		basic_machine=hppa1.1-oki
         1208  +		;;
         1209  +	romp)
         1210  +		basic_machine=romp-ibm
         1211  +		;;
         1212  +	mmix)
         1213  +		basic_machine=mmix-knuth
         1214  +		;;
         1215  +	rs6000)
         1216  +		basic_machine=rs6000-ibm
         1217  +		;;
         1218  +	vax)
         1219  +		basic_machine=vax-dec
         1220  +		;;
         1221  +	pdp10)
         1222  +		# there are many clones, so DEC is not a safe bet
         1223  +		basic_machine=pdp10-unknown
         1224  +		;;
         1225  +	pdp11)
         1226  +		basic_machine=pdp11-dec
         1227  +		;;
         1228  +	we32k)
         1229  +		basic_machine=we32k-att
         1230  +		;;
         1231  +	sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)
         1232  +		basic_machine=sh-unknown
         1233  +		;;
         1234  +	sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
         1235  +		basic_machine=sparc-sun
         1236  +		;;
         1237  +	cydra)
         1238  +		basic_machine=cydra-cydrome
         1239  +		;;
         1240  +	orion)
         1241  +		basic_machine=orion-highlevel
         1242  +		;;
         1243  +	orion105)
         1244  +		basic_machine=clipper-highlevel
         1245  +		;;
         1246  +	mac | mpw | mac-mpw)
         1247  +		basic_machine=m68k-apple
         1248  +		;;
         1249  +	pmac | pmac-mpw)
         1250  +		basic_machine=powerpc-apple
         1251  +		;;
         1252  +	*-unknown)
         1253  +		# Make sure to match an already-canonicalized machine name.
         1254  +		;;
         1255  +	*)
         1256  +		echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
         1257  +		exit 1
         1258  +		;;
         1259  +esac
         1260  +
         1261  +# Here we canonicalize certain aliases for manufacturers.
         1262  +case $basic_machine in
         1263  +	*-digital*)
         1264  +		basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
         1265  +		;;
         1266  +	*-commodore*)
         1267  +		basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
         1268  +		;;
         1269  +	*)
         1270  +		;;
         1271  +esac
         1272  +
         1273  +# Decode manufacturer-specific aliases for certain operating systems.
         1274  +
         1275  +if [ x"$os" != x"" ]
         1276  +then
         1277  +case $os in
         1278  +        # First match some system type aliases
         1279  +        # that might get confused with valid system types.
         1280  +	# -solaris* is a basic system type, with this one exception.
         1281  +        -auroraux)
         1282  +	        os=-auroraux
         1283  +		;;
         1284  +	-solaris1 | -solaris1.*)
         1285  +		os=`echo $os | sed -e 's|solaris1|sunos4|'`
         1286  +		;;
         1287  +	-solaris)
         1288  +		os=-solaris2
         1289  +		;;
         1290  +	-svr4*)
         1291  +		os=-sysv4
         1292  +		;;
         1293  +	-unixware*)
         1294  +		os=-sysv4.2uw
         1295  +		;;
         1296  +	-gnu/linux*)
         1297  +		os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
         1298  +		;;
         1299  +	# First accept the basic system types.
         1300  +	# The portable systems comes first.
         1301  +	# Each alternative MUST END IN A *, to match a version number.
         1302  +	# -sysv* is not here because it comes later, after sysvr4.
         1303  +	-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
         1304  +	      | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
         1305  +	      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
         1306  +	      | -sym* | -kopensolaris* \
         1307  +	      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
         1308  +	      | -aos* | -aros* \
         1309  +	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
         1310  +	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
         1311  +	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
         1312  +	      | -openbsd* | -solidbsd* \
         1313  +	      | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
         1314  +	      | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
         1315  +	      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
         1316  +	      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
         1317  +	      | -chorusos* | -chorusrdb* | -cegcc* \
         1318  +	      | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
         1319  +	      | -mingw32* | -linux-gnu* | -linux-android* \
         1320  +	      | -linux-newlib* | -linux-uclibc* \
         1321  +	      | -uxpv* | -beos* | -mpeix* | -udk* \
         1322  +	      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
         1323  +	      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
         1324  +	      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
         1325  +	      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
         1326  +	      | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
         1327  +	      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
         1328  +	      | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es*)
         1329  +	# Remember, each alternative MUST END IN *, to match a version number.
         1330  +		;;
         1331  +	-qnx*)
         1332  +		case $basic_machine in
         1333  +		    x86-* | i*86-*)
         1334  +			;;
         1335  +		    *)
         1336  +			os=-nto$os
         1337  +			;;
         1338  +		esac
         1339  +		;;
         1340  +	-nto-qnx*)
         1341  +		;;
         1342  +	-nto*)
         1343  +		os=`echo $os | sed -e 's|nto|nto-qnx|'`
         1344  +		;;
         1345  +	-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
         1346  +	      | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
         1347  +	      | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
         1348  +		;;
         1349  +	-mac*)
         1350  +		os=`echo $os | sed -e 's|mac|macos|'`
         1351  +		;;
         1352  +	-linux-dietlibc)
         1353  +		os=-linux-dietlibc
         1354  +		;;
         1355  +	-linux*)
         1356  +		os=`echo $os | sed -e 's|linux|linux-gnu|'`
         1357  +		;;
         1358  +	-sunos5*)
         1359  +		os=`echo $os | sed -e 's|sunos5|solaris2|'`
         1360  +		;;
         1361  +	-sunos6*)
         1362  +		os=`echo $os | sed -e 's|sunos6|solaris3|'`
         1363  +		;;
         1364  +	-opened*)
         1365  +		os=-openedition
         1366  +		;;
         1367  +        -os400*)
         1368  +		os=-os400
         1369  +		;;
         1370  +	-wince*)
         1371  +		os=-wince
         1372  +		;;
         1373  +	-osfrose*)
         1374  +		os=-osfrose
         1375  +		;;
         1376  +	-osf*)
         1377  +		os=-osf
         1378  +		;;
         1379  +	-utek*)
         1380  +		os=-bsd
         1381  +		;;
         1382  +	-dynix*)
         1383  +		os=-bsd
         1384  +		;;
         1385  +	-acis*)
         1386  +		os=-aos
         1387  +		;;
         1388  +	-atheos*)
         1389  +		os=-atheos
         1390  +		;;
         1391  +	-syllable*)
         1392  +		os=-syllable
         1393  +		;;
         1394  +	-386bsd)
         1395  +		os=-bsd
         1396  +		;;
         1397  +	-ctix* | -uts*)
         1398  +		os=-sysv
         1399  +		;;
         1400  +	-nova*)
         1401  +		os=-rtmk-nova
         1402  +		;;
         1403  +	-ns2 )
         1404  +		os=-nextstep2
         1405  +		;;
         1406  +	-nsk*)
         1407  +		os=-nsk
         1408  +		;;
         1409  +	# Preserve the version number of sinix5.
         1410  +	-sinix5.*)
         1411  +		os=`echo $os | sed -e 's|sinix|sysv|'`
         1412  +		;;
         1413  +	-sinix*)
         1414  +		os=-sysv4
         1415  +		;;
         1416  +        -tpf*)
         1417  +		os=-tpf
         1418  +		;;
         1419  +	-triton*)
         1420  +		os=-sysv3
         1421  +		;;
         1422  +	-oss*)
         1423  +		os=-sysv3
         1424  +		;;
         1425  +	-svr4)
         1426  +		os=-sysv4
         1427  +		;;
         1428  +	-svr3)
         1429  +		os=-sysv3
         1430  +		;;
         1431  +	-sysvr4)
         1432  +		os=-sysv4
         1433  +		;;
         1434  +	# This must come after -sysvr4.
         1435  +	-sysv*)
         1436  +		;;
         1437  +	-ose*)
         1438  +		os=-ose
         1439  +		;;
         1440  +	-es1800*)
         1441  +		os=-ose
         1442  +		;;
         1443  +	-xenix)
         1444  +		os=-xenix
         1445  +		;;
         1446  +	-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
         1447  +		os=-mint
         1448  +		;;
         1449  +	-aros*)
         1450  +		os=-aros
         1451  +		;;
         1452  +	-kaos*)
         1453  +		os=-kaos
         1454  +		;;
         1455  +	-zvmoe)
         1456  +		os=-zvmoe
         1457  +		;;
         1458  +	-dicos*)
         1459  +		os=-dicos
         1460  +		;;
         1461  +        -nacl*)
         1462  +	        ;;
         1463  +	-none)
         1464  +		;;
         1465  +	*)
         1466  +		# Get rid of the `-' at the beginning of $os.
         1467  +		os=`echo $os | sed 's/[^-]*-//'`
         1468  +		echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
         1469  +		exit 1
         1470  +		;;
         1471  +esac
         1472  +else
         1473  +
         1474  +# Here we handle the default operating systems that come with various machines.
         1475  +# The value should be what the vendor currently ships out the door with their
         1476  +# machine or put another way, the most popular os provided with the machine.
         1477  +
         1478  +# Note that if you're going to try to match "-MANUFACTURER" here (say,
         1479  +# "-sun"), then you have to tell the case statement up towards the top
         1480  +# that MANUFACTURER isn't an operating system.  Otherwise, code above
         1481  +# will signal an error saying that MANUFACTURER isn't an operating
         1482  +# system, and we'll never get to this point.
         1483  +
         1484  +case $basic_machine in
         1485  +        score-*)
         1486  +		os=-elf
         1487  +		;;
         1488  +        spu-*)
         1489  +		os=-elf
         1490  +		;;
         1491  +	*-acorn)
         1492  +		os=-riscix1.2
         1493  +		;;
         1494  +	arm*-rebel)
         1495  +		os=-linux
         1496  +		;;
         1497  +	arm*-semi)
         1498  +		os=-aout
         1499  +		;;
         1500  +        c4x-* | tic4x-*)
         1501  +        	os=-coff
         1502  +		;;
         1503  +	tic54x-*)
         1504  +		os=-coff
         1505  +		;;
         1506  +	tic55x-*)
         1507  +		os=-coff
         1508  +		;;
         1509  +	tic6x-*)
         1510  +		os=-coff
         1511  +		;;
         1512  +	# This must come before the *-dec entry.
         1513  +	pdp10-*)
         1514  +		os=-tops20
         1515  +		;;
         1516  +	pdp11-*)
         1517  +		os=-none
         1518  +		;;
         1519  +	*-dec | vax-*)
         1520  +		os=-ultrix4.2
         1521  +		;;
         1522  +	m68*-apollo)
         1523  +		os=-domain
         1524  +		;;
         1525  +	i386-sun)
         1526  +		os=-sunos4.0.2
         1527  +		;;
         1528  +	m68000-sun)
         1529  +		os=-sunos3
         1530  +		# This also exists in the configure program, but was not the
         1531  +		# default.
         1532  +		# os=-sunos4
         1533  +		;;
         1534  +	m68*-cisco)
         1535  +		os=-aout
         1536  +		;;
         1537  +        mep-*)
         1538  +		os=-elf
         1539  +		;;
         1540  +	mips*-cisco)
         1541  +		os=-elf
         1542  +		;;
         1543  +	mips*-*)
         1544  +		os=-elf
         1545  +		;;
         1546  +	or32-*)
         1547  +		os=-coff
         1548  +		;;
         1549  +	*-tti)	# must be before sparc entry or we get the wrong os.
         1550  +		os=-sysv3
         1551  +		;;
         1552  +	sparc-* | *-sun)
         1553  +		os=-sunos4.1.1
         1554  +		;;
         1555  +	*-be)
         1556  +		os=-beos
         1557  +		;;
         1558  +	*-haiku)
         1559  +		os=-haiku
         1560  +		;;
         1561  +	*-ibm)
         1562  +		os=-aix
         1563  +		;;
         1564  +    	*-knuth)
         1565  +		os=-mmixware
         1566  +		;;
         1567  +	*-wec)
         1568  +		os=-proelf
         1569  +		;;
         1570  +	*-winbond)
         1571  +		os=-proelf
         1572  +		;;
         1573  +	*-oki)
         1574  +		os=-proelf
         1575  +		;;
         1576  +	*-hp)
         1577  +		os=-hpux
         1578  +		;;
         1579  +	*-hitachi)
         1580  +		os=-hiux
         1581  +		;;
         1582  +	i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
         1583  +		os=-sysv
         1584  +		;;
         1585  +	*-cbm)
         1586  +		os=-amigaos
         1587  +		;;
         1588  +	*-dg)
         1589  +		os=-dgux
         1590  +		;;
         1591  +	*-dolphin)
         1592  +		os=-sysv3
         1593  +		;;
         1594  +	m68k-ccur)
         1595  +		os=-rtu
         1596  +		;;
         1597  +	m88k-omron*)
         1598  +		os=-luna
         1599  +		;;
         1600  +	*-next )
         1601  +		os=-nextstep
         1602  +		;;
         1603  +	*-sequent)
         1604  +		os=-ptx
         1605  +		;;
         1606  +	*-crds)
         1607  +		os=-unos
         1608  +		;;
         1609  +	*-ns)
         1610  +		os=-genix
         1611  +		;;
         1612  +	i370-*)
         1613  +		os=-mvs
         1614  +		;;
         1615  +	*-next)
         1616  +		os=-nextstep3
         1617  +		;;
         1618  +	*-gould)
         1619  +		os=-sysv
         1620  +		;;
         1621  +	*-highlevel)
         1622  +		os=-bsd
         1623  +		;;
         1624  +	*-encore)
         1625  +		os=-bsd
         1626  +		;;
         1627  +	*-sgi)
         1628  +		os=-irix
         1629  +		;;
         1630  +	*-siemens)
         1631  +		os=-sysv4
         1632  +		;;
         1633  +	*-masscomp)
         1634  +		os=-rtu
         1635  +		;;
         1636  +	f30[01]-fujitsu | f700-fujitsu)
         1637  +		os=-uxpv
         1638  +		;;
         1639  +	*-rom68k)
         1640  +		os=-coff
         1641  +		;;
         1642  +	*-*bug)
         1643  +		os=-coff
         1644  +		;;
         1645  +	*-apple)
         1646  +		os=-macos
         1647  +		;;
         1648  +	*-atari*)
         1649  +		os=-mint
         1650  +		;;
         1651  +	*)
         1652  +		os=-none
         1653  +		;;
         1654  +esac
         1655  +fi
         1656  +
         1657  +# Here we handle the case where we know the os, and the CPU type, but not the
         1658  +# manufacturer.  We pick the logical manufacturer.
         1659  +vendor=unknown
         1660  +case $basic_machine in
         1661  +	*-unknown)
         1662  +		case $os in
         1663  +			-riscix*)
         1664  +				vendor=acorn
         1665  +				;;
         1666  +			-sunos*)
         1667  +				vendor=sun
         1668  +				;;
         1669  +			-cnk*|-aix*)
         1670  +				vendor=ibm
         1671  +				;;
         1672  +			-beos*)
         1673  +				vendor=be
         1674  +				;;
         1675  +			-hpux*)
         1676  +				vendor=hp
         1677  +				;;
         1678  +			-mpeix*)
         1679  +				vendor=hp
         1680  +				;;
         1681  +			-hiux*)
         1682  +				vendor=hitachi
         1683  +				;;
         1684  +			-unos*)
         1685  +				vendor=crds
         1686  +				;;
         1687  +			-dgux*)
         1688  +				vendor=dg
         1689  +				;;
         1690  +			-luna*)
         1691  +				vendor=omron
         1692  +				;;
         1693  +			-genix*)
         1694  +				vendor=ns
         1695  +				;;
         1696  +			-mvs* | -opened*)
         1697  +				vendor=ibm
         1698  +				;;
         1699  +			-os400*)
         1700  +				vendor=ibm
         1701  +				;;
         1702  +			-ptx*)
         1703  +				vendor=sequent
         1704  +				;;
         1705  +			-tpf*)
         1706  +				vendor=ibm
         1707  +				;;
         1708  +			-vxsim* | -vxworks* | -windiss*)
         1709  +				vendor=wrs
         1710  +				;;
         1711  +			-aux*)
         1712  +				vendor=apple
         1713  +				;;
         1714  +			-hms*)
         1715  +				vendor=hitachi
         1716  +				;;
         1717  +			-mpw* | -macos*)
         1718  +				vendor=apple
         1719  +				;;
         1720  +			-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
         1721  +				vendor=atari
         1722  +				;;
         1723  +			-vos*)
         1724  +				vendor=stratus
         1725  +				;;
         1726  +		esac
         1727  +		basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
         1728  +		;;
         1729  +esac
         1730  +
         1731  +echo $basic_machine$os
         1732  +exit
         1733  +
         1734  +# Local variables:
         1735  +# eval: (add-hook 'write-file-hooks 'time-stamp)
         1736  +# time-stamp-start: "timestamp='"
         1737  +# time-stamp-format: "%:y-%02m-%02d"
         1738  +# time-stamp-end: "'"
         1739  +# End:

Added autosetup/find-tclsh.

            1  +#!/bin/sh
            2  +# Looks for a suitable tclsh or jimsh in the PATH
            3  +# If not found, builds a bootstrap jimsh from source
            4  +d=`dirname "$0"`
            5  +PATH="$PATH:$d"
            6  +for tclsh in jimsh tclsh tclsh8.5 tclsh8.6 jimsh0; do
            7  +	{ $tclsh "$d/test-tclsh"; } 2>/dev/null && exit 0
            8  +done
            9  +echo 1>&2 "No installed jimsh or tclsh, building local bootstrap jimsh0"
           10  +for cc in ${CC_FOR_BUILD:-cc} gcc; do
           11  +	{ $cc -o "$d/jimsh0" "$d/jimsh0.c"; } 2>/dev/null || continue
           12  +	"$d/jimsh0" "$d/test-tclsh" && exit 0
           13  +done
           14  +echo 1>&2 "No working C compiler found. Tried ${CC_FOR_BUILD:-cc} and gcc."

Added autosetup/jimsh0.c.

more than 10,000 changes

Added autosetup/local.tcl.

            1  +# For this project, disable the pager for --help
            2  +set useropts(nopager) 1

Added autosetup/system.tcl.

            1  +# Copyright (c) 2010 WorkWare Systems http://www.workware.net.au/
            2  +# All rights reserved
            3  +
            4  +# @synopsis:
            5  +#
            6  +# This module supports common system interrogation and options
            7  +# such as --host, --build, --prefix, and setting srcdir, builddir, and EXEXT.
            8  +#
            9  +# It also support the 'feature' naming convention, where searching
           10  +# for a feature such as sys/type.h defines HAVE_SYS_TYPES_H
           11  +
           12  +# Note that the hidden options are supported for autoconf compatibility
           13  +
           14  +module-options {
           15  +	host:host-alias =>		{a complete or partial cpu-vendor-opsys for the system where
           16  +							the application will run (defaults to the same value as --build)}
           17  +	build:build-alias =>	{a complete or partial cpu-vendor-opsys for the system
           18  +							where the application will be built (defaults to the
           19  +							result of running config.guess)}
           20  +	prefix:dir =>			{the target directory for the build (defaults to /usr/local)}
           21  +
           22  +	includedir:
           23  +	mandir:
           24  +	infodir:
           25  +	libexecdir:
           26  +	sysconfdir:
           27  +	localstatedir:
           28  +
           29  +	maintainer-mode=0
           30  +	dependency-tracking=0
           31  +}
           32  +
           33  +# Returns 1 if exists, or 0 if  not
           34  +#
           35  +proc check-feature {name code} {
           36  +	msg-checking "Checking for $name..."
           37  +	set r [uplevel 1 $code]
           38  +	define-feature $name $r
           39  +	if {$r} {
           40  +		msg-result "ok"
           41  +	} else {
           42  +		msg-result "not found"
           43  +	}
           44  +	return $r
           45  +}
           46  +
           47  +# @have-feature name ?default=0?
           48  +#
           49  +# Returns the value of the feature if defined, or $default if not.
           50  +# See 'feature-define-name' for how the feature name
           51  +# is translated into the define name.
           52  +#
           53  +proc have-feature {name {default 0}} {
           54  +	get-define [feature-define-name $name] $default
           55  +}
           56  +
           57  +# @define-feature name ?value=1?
           58  +#
           59  +# Sets the feature 'define' to the given value.
           60  +# See 'feature-define-name' for how the feature name
           61  +# is translated into the define name.
           62  +#
           63  +proc define-feature {name {value 1}} {
           64  +	define [feature-define-name $name] $value
           65  +}
           66  +
           67  +# @feature-checked name
           68  +#
           69  +# Returns 1 if the feature has been checked, whether true or not
           70  +#
           71  +proc feature-checked {name} {
           72  +	is-defined [feature-define-name $name]
           73  +}
           74  +
           75  +# @feature-define-name name ?prefix=HAVE_?
           76  +#
           77  +# Converts a name to the corresponding define,
           78  +# e.g. sys/stat.h becomes HAVE_SYS_STAT_H.
           79  +#
           80  +# Converts * to P and all non-alphanumeric to underscore.
           81  +#
           82  +proc feature-define-name {name {prefix HAVE_}} {
           83  +	string toupper $prefix[regsub -all {[^a-zA-Z0-9]} [regsub -all {[*]} $name p] _]
           84  +}
           85  +
           86  +# If $file doesn't exist, or it's contents are different than $buf,
           87  +# the file is written and $script is executed.
           88  +# Otherwise a "file is unchanged" message is displayed.
           89  +proc write-if-changed {file buf {script {}}} {
           90  +	set old [readfile $file ""]
           91  +	if {$old eq $buf && [file exists $file]} {
           92  +		msg-result "$file is unchanged"
           93  +	} else {
           94  +		writefile $file $buf\n
           95  +		uplevel 1 $script
           96  +	}
           97  +}
           98  +
           99  +# @make-template template ?outfile?
          100  +#
          101  +# Reads the input file <srcdir>/$template and writes the output file $outfile.
          102  +# If $outfile is blank/omitted, $template should end with ".in" which
          103  +# is removed to create the output file name.
          104  +#
          105  +# Each pattern of the form @define@ is replaced the the corresponding
          106  +# define, if it exists, or left unchanged if not.
          107  +# 
          108  +# The special value @srcdir@ is subsituted with the relative
          109  +# path to the source directory from the directory where the output
          110  +# file is created. Use @top_srcdir@ for the absolute path.
          111  +#
          112  +proc make-template {template {out {}}} {
          113  +	set infile [file join $::autosetup(srcdir) $template]
          114  +
          115  +	if {![file exists $infile]} {
          116  +		user-error "Template $template is missing"
          117  +	}
          118  +
          119  +	# Define this as late as possible
          120  +	define AUTODEPS $::autosetup(deps)
          121  +
          122  +	if {$out eq ""} {
          123  +		if {[file ext $template] ne ".in"} {
          124  +			autosetup-error "make_template $template has no target file and can't guess"
          125  +		}
          126  +		set out [file rootname $template]
          127  +	}
          128  +
          129  +	set outdir [file dirname $out]
          130  +
          131  +	# Make sure the directory exists
          132  +	file mkdir $outdir
          133  +
          134  +	# Set up srcdir to be relative to the target dir
          135  +	define srcdir [relative-path [file join $::autosetup(srcdir) $outdir] $outdir]
          136  +
          137  +	set mapping {}
          138  +	foreach {n v} [array get ::define] {
          139  +		lappend mapping @$n@ $v
          140  +	}
          141  +	writefile $out [string map $mapping [readfile $infile]]\n
          142  +
          143  +	msg-result "Created [relative-path $out] from [relative-path $template]"
          144  +}
          145  +
          146  +# build/host tuples and cross-compilation prefix
          147  +set build [opt-val build]
          148  +define build_alias $build
          149  +if {$build eq ""} {
          150  +	define build [config_guess]
          151  +} else {
          152  +	define build [config_sub $build]
          153  +}
          154  +
          155  +set host [opt-val host]
          156  +define host_alias $host
          157  +if {$host eq ""} {
          158  +	define host [get-define build]
          159  +	set cross ""
          160  +} else {
          161  +	define host [config_sub $host]
          162  +	set cross $host-
          163  +}
          164  +define cross [get-env CROSS $cross]
          165  +
          166  +set prefix [opt-val prefix /usr/local]
          167  +
          168  +# These are for compatibility with autoconf
          169  +define target [get-define host]
          170  +define prefix $prefix
          171  +define builddir $autosetup(builddir)
          172  +define srcdir $autosetup(srcdir)
          173  +# Allow this to come from the environment
          174  +define top_srcdir [get-env top_srcdir [get-define srcdir]]
          175  +
          176  +# And less common ones too
          177  +define exec_prefix \${prefix}
          178  +define bindir \${exec_prefix}/bin
          179  +define sbindir \${exec_prefix}/sbin
          180  +define libexecdir [get-env libexecdir \${exec_prefix}/libexec]
          181  +define datadir \${prefix}/share
          182  +define sysconfdir [get-env sysconfdir \${prefix}/etc]
          183  +define sharedstatedir \${prefix}/com
          184  +define localstatedir [get-env localstatedir \${prefix}/var]
          185  +define libdir \${exec_prefix}/lib
          186  +define infodir [get-env infodir \${prefix}/share/info]
          187  +define mandir [get-env mandir \${prefix}/share/man]
          188  +define includedir [get-env includdir \${prefix}/include]
          189  +
          190  +define SHELL [get-env SHELL [find-an-executable sh bash ksh]]
          191  +
          192  +# Windows vs. non-Windows
          193  +switch -glob -- [get-define host] {
          194  +	*-*-ming* - *-*-cygwin {
          195  +		define-feature windows
          196  +		define EXEEXT .exe
          197  +	}
          198  +	default {
          199  +		define EXEEXT ""
          200  +	}
          201  +}
          202  +
          203  +# Display
          204  +msg-result "Host System...[get-define host]"
          205  +msg-result "Build System...[get-define build]"

Added autosetup/test-tclsh.

            1  +# A small Tcl script to verify that the chosen
            2  +# interpreter works. Sometimes we might e.g. pick up
            3  +# an interpreter for a different arch.
            4  +# Outputs the full path to the interpreter
            5  +
            6  +if {[catch {info version} version] == 0} {
            7  +	# This is Jim Tcl
            8  +	if {$version >= 0.70} {
            9  +		# Ensure that regexp works
           10  +		regexp (a.*?) a
           11  +
           12  +		# Older versions of jimsh may return a relative path for [info nameofexecutable]
           13  +		puts [file join [pwd] [info nameofexecutable]]
           14  +		exit 0
           15  +	}
           16  +} elseif {[catch {info tclversion} version] == 0} {
           17  +	if {$version >= 8.5 && ![string match 8.5a* [info patchlevel]]} {
           18  +		puts [info nameofexecutable]
           19  +		exit 0
           20  +	}
           21  +}
           22  +exit 1

Added configure.

            1  +#!/bin/sh
            2  +dir="`dirname "$0"`/autosetup"
            3  +WRAPPER="$0" exec `"$dir/find-tclsh" || echo false` "$dir/autosetup" "$@"

Changes to src/branch.c.

   174    174   
   175    175     /* Commit */
   176    176     db_end_transaction(0);
   177    177     
   178    178     /* Do an autosync push, if requested */
   179    179     autosync(AUTOSYNC_PUSH);
   180    180   }
          181  +
          182  +/*
          183  +** Prepare a query that will list all branches.
          184  +*/
          185  +static void prepareBranchQuery(Stmt *pQuery, int showAll, int showClosed){
          186  +  if( showClosed ){
          187  +    db_prepare(pQuery,
          188  +      "SELECT value FROM tagxref"
          189  +      " WHERE tagid=%d AND value NOT NULL "
          190  +      "EXCEPT "
          191  +      "SELECT value FROM tagxref"
          192  +      " WHERE tagid=%d"
          193  +      "   AND rid IN leaf"
          194  +      "   AND NOT %z"
          195  +      " ORDER BY value COLLATE nocase /*sort*/",
          196  +      TAG_BRANCH, TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
          197  +    );
          198  +  }else if( showAll ){
          199  +    db_prepare(pQuery,
          200  +      "SELECT DISTINCT value FROM tagxref"
          201  +      " WHERE tagid=%d AND value NOT NULL"
          202  +      "   AND rid IN leaf"
          203  +      " ORDER BY value COLLATE nocase /*sort*/",
          204  +      TAG_BRANCH
          205  +    );
          206  +  }else{
          207  +    db_prepare(pQuery,
          208  +      "SELECT DISTINCT value FROM tagxref"
          209  +      " WHERE tagid=%d AND value NOT NULL"
          210  +      "   AND rid IN leaf"
          211  +      "   AND NOT %z"
          212  +      " ORDER BY value COLLATE nocase /*sort*/",
          213  +      TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
          214  +    );
          215  +  }
          216  +}
          217  +
   181    218   
   182    219   /*
   183    220   ** COMMAND: branch
   184    221   **
   185    222   ** Usage: %fossil branch SUBCOMMAND ... ?-R|--repository FILE?
   186    223   **
   187    224   ** Run various subcommands to manage branches of the open repository or
................................................................................
   192    229   **        Create a new branch BRANCH-NAME off of check-in BASIS.
   193    230   **        You can optionally give the branch a default color.  The
   194    231   **        --private option makes the branch private.
   195    232   **
   196    233   **    %fossil branch list
   197    234   **    %fossil branch ls
   198    235   **
   199         -**        List all branches
          236  +**        List all branches.  Use --all or --closed to list all branches
          237  +**        or closed branches.  The default is to show only open branches.
   200    238   **
   201    239   */
   202    240   void branch_cmd(void){
   203    241     int n;
   204    242     const char *zCmd = "list";
   205    243     db_find_and_open_repository(0, 0);
   206    244     if( g.argc<2 ){
................................................................................
   210    248     n = strlen(zCmd);
   211    249     if( strncmp(zCmd,"new",n)==0 ){
   212    250       branch_new();
   213    251     }else if( (strncmp(zCmd,"list",n)==0)||(strncmp(zCmd, "ls", n)==0) ){
   214    252       Stmt q;
   215    253       int vid;
   216    254       char *zCurrent = 0;
          255  +    int showAll = find_option("all",0,0)!=0;
          256  +    int showClosed = find_option("closed",0,0)!=0;
   217    257   
   218    258       if( g.localOpen ){
   219    259         vid = db_lget_int("checkout", 0);
   220    260         zCurrent = db_text(0, "SELECT value FROM tagxref"
   221    261                               " WHERE rid=%d AND tagid=%d", vid, TAG_BRANCH);
   222    262       }
   223         -    db_prepare(&q,
   224         -      "SELECT DISTINCT value FROM tagxref"
   225         -      " WHERE tagid=%d AND value NOT NULL"
   226         -      "   AND rid IN leaf"
   227         -      "   AND NOT %z"
   228         -      " ORDER BY value /*sort*/",
   229         -      TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
   230         -    );
          263  +    prepareBranchQuery(&q, showAll, showClosed);
   231    264       while( db_step(&q)==SQLITE_ROW ){
   232    265         const char *zBr = db_column_text(&q, 0);
   233    266         int isCur = zCurrent!=0 && fossil_strcmp(zCurrent,zBr)==0;
   234    267         fossil_print("%s%s\n", (isCur ? "* " : "  "), zBr);
   235    268       }
   236    269       db_finalize(&q);
   237    270     }else{
................................................................................
   245    278   **
   246    279   ** Show a timeline of all branches
   247    280   */
   248    281   void brlist_page(void){
   249    282     Stmt q;
   250    283     int cnt;
   251    284     int showClosed = P("closed")!=0;
          285  +  int showAll = P("all")!=0;
   252    286   
   253    287     login_check_credentials();
   254    288     if( !g.okRead ){ login_needed(); return; }
   255    289   
   256         -  style_header(showClosed ? "Closed Branches" : "Open Branches");
          290  +  style_header(showClosed ? "Closed Branches" :
          291  +                  showAll ? "All Branches" : "Open Branches");
   257    292     style_submenu_element("Timeline", "Timeline", "brtimeline");
   258    293     if( showClosed ){
          294  +    style_submenu_element("All", "All", "brlist?all");
          295  +    style_submenu_element("Open","Open","brlist");
          296  +  }else if( showAll ){
          297  +    style_submenu_element("Closed", "Closed", "brlist?closed");
   259    298       style_submenu_element("Open","Open","brlist");
   260    299     }else{
          300  +    style_submenu_element("All", "All", "brlist?all");
   261    301       style_submenu_element("Closed","Closed","brlist?closed");
   262    302     }
   263    303     login_anonymous_available();
   264    304     style_sidebox_begin("Nomenclature:", "33%");
   265    305     @ <ol>
   266    306     @ <li> An <div class="sideboxDescribed"><a href="brlist">
   267    307     @ open branch</a></div> is a branch that has one or
................................................................................
   273    313     @ <div class="sideboxDescribed"><a href="leaves?closed">
   274    314     @ closed leaves</a></div>.
   275    315     @ Closed branches are fixed and do not change (unless they are first
   276    316     @ reopened)</li>
   277    317     @ </ol>
   278    318     style_sidebox_end();
   279    319   
          320  +  prepareBranchQuery(&q, showAll, showClosed);
   280    321     cnt = 0;
   281         -  if( showClosed ){
   282         -    db_prepare(&q,
   283         -      "SELECT value FROM tagxref"
   284         -      " WHERE tagid=%d AND value NOT NULL "
   285         -      "EXCEPT "
   286         -      "SELECT value FROM tagxref"
   287         -      " WHERE tagid=%d"
   288         -      "   AND rid IN leaf"
   289         -      "   AND NOT %z"
   290         -      " ORDER BY value /*sort*/",
   291         -      TAG_BRANCH, TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
   292         -    );
   293         -  }else{
   294         -    db_prepare(&q,
   295         -      "SELECT DISTINCT value FROM tagxref"
   296         -      " WHERE tagid=%d AND value NOT NULL"
   297         -      "   AND rid IN leaf"
   298         -      "   AND NOT %z"
   299         -      " ORDER BY value /*sort*/",
   300         -      TAG_BRANCH, leaf_is_closed_sql("tagxref.rid")
   301         -    );
   302         -  }
   303    322     while( db_step(&q)==SQLITE_ROW ){
   304    323       const char *zBr = db_column_text(&q, 0);
   305    324       if( cnt==0 ){
   306    325         if( showClosed ){
   307    326           @ <h2>Closed Branches:</h2>
   308    327         }else{
   309    328           @ <h2>Open Branches:</h2>

Changes to src/browse.c.

   265    265       i++;
   266    266       zFN = db_column_text(&q, 0);
   267    267       if( zFN[0]=='/' ){
   268    268         zFN++;
   269    269         @ <li><a href="%s(zSubdirLink)%T(zFN)">%h(zFN)/</a></li>
   270    270       }else if( zCI ){
   271    271         const char *zUuid = db_column_text(&q, 1);
   272         -      @ <li><a href="%s(g.zTop)/artifact?name=%s(zUuid)">%h(zFN)</a></li>
          272  +      @ <li><a href="%s(g.zTop)/artifact/%s(zUuid)">%h(zFN)</a></li>
   273    273       }else{
   274    274         @ <li><a href="%s(g.zTop)/finfo?name=%T(zPrefix)%T(zFN)">%h(zFN)
   275    275         @     </a></li>
   276    276       }
   277    277     }
   278    278     db_finalize(&q);
   279    279     manifest_destroy(pM);
   280    280     @ </ul></td></tr></table>
   281    281     style_footer();
   282    282   }

Changes to src/cgi.c.

   351    351       for(i=0; i<2; i++){
   352    352         size = blob_size(&cgiContent[i]);
   353    353         if( size>0 ){
   354    354           fwrite(blob_buffer(&cgiContent[i]), 1, size, g.httpOut);
   355    355         }
   356    356       }
   357    357     }
          358  +  fflush(g.httpOut);
   358    359     CGIDEBUG(("DONE\n"));
   359    360   }
   360    361   
   361    362   /*
   362    363   ** Do a redirect request to the URL given in the argument.
   363    364   **
   364    365   ** The URL must be relative to the base of the fossil server.
................................................................................
   885    886     va_end(ap);
   886    887     return 1;
   887    888   }
   888    889   
   889    890   /*
   890    891   ** Print all query parameters on standard output.  Format the
   891    892   ** parameters as HTML.  This is used for testing and debugging.
          893  +** Release builds omit the values of the cookies to avoid defeating
          894  +** the purpose of setting HttpOnly cookies.
   892    895   */
   893    896   void cgi_print_all(void){
   894    897     int i;
          898  +  int showAll = 0;
          899  +#ifdef FOSSIL_DEBUG
          900  +  /* Show the values of cookies in debug mode. */
          901  +  showAll = 1;
          902  +#endif
   895    903     cgi_parameter("","");  /* Force the parameters into sorted order */
   896    904     for(i=0; i<nUsedQP; i++){
   897         -    cgi_printf("%s = %s  <br />\n",
   898         -       htmlize(aParamQP[i].zName, -1), htmlize(aParamQP[i].zValue, -1));
          905  +    if( showAll || (fossil_stricmp("HTTP_COOKIE",aParamQP[i].zName)!=0 && fossil_strnicmp("fossil-",aParamQP[i].zName,7)!=0) ){
          906  +      cgi_printf("%s = %s  <br />\n",
          907  +         htmlize(aParamQP[i].zName, -1), htmlize(aParamQP[i].zValue, -1));
          908  +    }
   899    909     }
   900    910   }
   901    911   
   902    912   /*
   903    913   ** This routine works like "printf" except that it has the
   904    914   ** extra formatting capabilities such as %h and %t.
   905    915   */

Changes to src/clone.c.

    41     41   **    --private                   Also clone private branches 
    42     42   **    --ssl-identity=filename     Use the SSL identity if requested by the server
    43     43   **
    44     44   */
    45     45   void clone_cmd(void){
    46     46     char *zPassword;
    47     47     const char *zDefaultUser;   /* Optional name of the default user */
           48  +  const char *zPw;     /* The user clone password */
    48     49     int nErr = 0;
    49     50     int bPrivate;               /* Also clone private branches */
    50     51   
    51     52     bPrivate = find_option("private",0,0)!=0;
    52     53     url_proxy_options();
    53     54     if( g.argc < 4 ){
    54     55       usage("?OPTIONS? FILE-OR-URL NEW-REPOSITORY");
................................................................................
    75     76       );
    76     77       db_multi_exec(
    77     78          "DELETE FROM blob WHERE rid IN private;"
    78     79          "DELETE FROM delta wHERE rid IN private;"
    79     80          "DELETE FROM private;"
    80     81       );
    81     82       shun_artifacts();
    82         -    g.zLogin = db_text(0, "SELECT login FROM user WHERE cap LIKE '%%s%%'");
    83         -    if( g.zLogin==0 ){
    84         -      db_create_default_users(1,zDefaultUser);
           83  +    db_create_default_users(1, zDefaultUser);
           84  +    if( zDefaultUser ){
           85  +      g.zLogin = zDefaultUser;
           86  +    }else{
           87  +      g.zLogin = db_text(0, "SELECT login FROM user WHERE cap LIKE '%%s%%'");
    85     88       }
    86     89       fossil_print("Repository cloned into %s\n", g.argv[3]);
    87     90     }else{
    88     91       db_create_repository(g.argv[3]);
    89     92       db_open_repository(g.argv[3]);
    90     93       db_begin_transaction();
    91     94       db_record_repository_filename(g.argv[3]);
................................................................................
   123    126     db_begin_transaction();
   124    127     fossil_print("Rebuilding repository meta-data...\n");
   125    128     rebuild_db(0, 1, 0);
   126    129     fossil_print("project-id: %s\n", db_get("project-code", 0));
   127    130     fossil_print("server-id:  %s\n", db_get("server-code", 0));
   128    131     zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
   129    132     fossil_print("admin-user: %s (password is \"%s\")\n", g.zLogin, zPassword);
          133  +  zPw = g.urlPasswd;
          134  +  if( !g.dontKeepUrl && zPw) db_set("last-sync-pw", obscure(zPw), 0);
   130    135     db_end_transaction(0);
   131    136   }

Changes to src/config.h.

    22     22   ** some linux distributions, and possibly other unixes as well.
    23     23   */
    24     24   #define _LARGE_FILE       1
    25     25   #ifndef _FILE_OFFSET_BITS
    26     26   #  define _FILE_OFFSET_BITS 64
    27     27   #endif
    28     28   #define _LARGEFILE_SOURCE 1
           29  +
           30  +#ifdef HAVE_AUTOCONFIG_H
           31  +#include "autoconfig.h"
           32  +#endif
    29     33   
    30     34   #ifndef _RC_COMPILE_
    31     35   
    32     36   /*
    33     37   ** System header files used by all modules
    34     38   */
    35     39   #include <unistd.h>
................................................................................
    83     87   #ifndef _RC_COMPILE_
    84     88   
    85     89   #include "sqlite3.h"
    86     90   
    87     91   /*
    88     92   ** On Solaris, getpass() will only return up to 8 characters. getpassphrase() returns up to 257.
    89     93   */
    90         -#if defined(__sun__) || defined(sun)
           94  +#if HAVE_GETPASSPHRASE
    91     95     #define getpass getpassphrase
    92     96   #endif
    93     97   
    94     98   /*
    95     99   ** Typedef for a 64-bit integer
    96    100   */
    97    101   typedef sqlite3_int64 i64;

Changes to src/db.c.

   807    807     int i, n;
   808    808     char zPwd[2000];
   809    809     static const char *aDbName[] = { "/_FOSSIL_", "/.fos" };
   810    810     
   811    811     if( g.localOpen) return 1;
   812    812     file_getcwd(zPwd, sizeof(zPwd)-20);
   813    813     n = strlen(zPwd);
          814  +  if( n==1 && zPwd[0]=='/' ) zPwd[0] = '.';
   814    815     while( n>0 ){
   815    816       if( file_access(zPwd, W_OK) ) break;
   816    817       for(i=0; i<sizeof(aDbName)/sizeof(aDbName[0]); i++){
   817    818         sqlite3_snprintf(sizeof(zPwd)-n, &zPwd[n], "%s", aDbName[i]);
   818    819         if( isValidLocalDb(zPwd) ){
   819    820           /* Found a valid checkout database file */
   820    821           zPwd[n] = 0;
................................................................................
  1056   1057     db_delete_on_failure(zFilename);
  1057   1058   }
  1058   1059   
  1059   1060   /*
  1060   1061   ** Create the default user accounts in the USER table.
  1061   1062   */
  1062   1063   void db_create_default_users(int setupUserOnly, const char *zDefaultUser){
  1063         -  const char *zUser;
  1064         -  zUser = db_get("default-user", 0);
         1064  +  const char *zUser = zDefaultUser;
  1065   1065     if( zUser==0 ){
  1066         -    zUser = zDefaultUser;
         1066  +    zUser = db_get("default-user", 0);
  1067   1067     }
  1068   1068     if( zUser==0 ){
  1069   1069   #if defined(_WIN32)
  1070   1070       zUser = getenv("USERNAME");
  1071   1071   #else
  1072   1072       zUser = getenv("USER");
  1073   1073   #endif
  1074   1074     }
  1075   1075     if( zUser==0 ){
  1076   1076       zUser = "root";
  1077   1077     }
  1078   1078     db_multi_exec(
  1079         -     "INSERT INTO user(login, pw, cap, info)"
  1080         -     "VALUES(%Q,lower(hex(randomblob(3))),'s','')", zUser
         1079  +     "INSERT OR IGNORE INTO user(login, info) VALUES(%Q,'')", zUser
         1080  +  );
         1081  +  db_multi_exec(
         1082  +     "UPDATE user SET cap='s', pw=lower(hex(randomblob(3)))"
         1083  +     " WHERE login=%Q", zUser
  1081   1084     );
  1082   1085     if( !setupUserOnly ){
  1083   1086       db_multi_exec(
  1084   1087          "INSERT INTO user(login,pw,cap,info)"
  1085   1088          "   VALUES('anonymous',hex(randomblob(8)),'hmncz','Anon');"
  1086   1089          "INSERT INTO user(login,pw,cap,info)"
  1087   1090          "   VALUES('nobody','','gjor','Nobody');"
................................................................................
  1926   1929         db_unset(ctrlSettings[i].name, globalFlag);
  1927   1930       }else if( g.argc==4 ){
  1928   1931         db_set(ctrlSettings[i].name, g.argv[3], globalFlag);
  1929   1932       }else{
  1930   1933         isManifest = 0;
  1931   1934         print_setting(&ctrlSettings[i], db_open_local());
  1932   1935       }
  1933         -    if( isManifest ){
         1936  +    if( isManifest && g.localOpen ){
  1934   1937         manifest_to_disk(db_lget_int("checkout", 0));
  1935   1938       }
  1936   1939     }else{
  1937   1940       usage("?PROPERTY? ?VALUE?");
  1938   1941     }
  1939   1942   }
  1940   1943   

Changes to src/info.c.

  1211   1211       @ </script>
  1212   1212     }
  1213   1213   }
  1214   1214   
  1215   1215   
  1216   1216   /*
  1217   1217   ** WEBPAGE: artifact
  1218         -** URL: /artifact?name=ARTIFACTID
         1218  +** URL: /artifact/ARTIFACTID
  1219   1219   ** URL: /artifact?ci=CHECKIN&filename=PATH
         1220  +**
         1221  +** Additional query parameters:
         1222  +**
         1223  +**   ln              - show line numbers
         1224  +**   ln=N            - highlight line number N
         1225  +**   ln=M-N          - highlight lines M through N inclusive
  1220   1226   ** 
  1221   1227   ** Show the complete content of a file identified by ARTIFACTID
  1222   1228   ** as preformatted text.
  1223   1229   */
  1224   1230   void artifact_page(void){
  1225   1231     int rid = 0;
  1226   1232     Blob content;
................................................................................
  1258   1264     style_submenu_element("Download", "Download", 
  1259   1265             "%s/raw/%T?name=%s", g.zTop, blob_str(&downloadName), zUuid);
  1260   1266     zMime = mimetype_from_name(blob_str(&downloadName));
  1261   1267     if( zMime ){
  1262   1268       if( fossil_strcmp(zMime, "text/html")==0 ){
  1263   1269         if( P("txt") ){
  1264   1270           style_submenu_element("Html", "Html",
  1265         -                              "%s/artifact?name=%s", g.zTop, zUuid);
         1271  +                              "%s/artifact/%s", g.zTop, zUuid);
  1266   1272         }else{
  1267   1273           renderAsHtml = 1;
  1268   1274           style_submenu_element("Text", "Text",
  1269         -                              "%s/artifact?name=%s&amp;txt=1", g.zTop, zUuid);
         1275  +                              "%s/artifact/%s?txt=1", g.zTop, zUuid);
  1270   1276         }
  1271   1277       }else if( fossil_strcmp(zMime, "application/x-fossil-wiki")==0 ){
  1272   1278         if( P("txt") ){
  1273   1279           style_submenu_element("Wiki", "Wiki",
  1274         -                              "%s/artifact?name=%s", g.zTop, zUuid);
         1280  +                              "%s/artifact/%s", g.zTop, zUuid);
  1275   1281         }else{
  1276   1282           renderAsWiki = 1;
  1277   1283           style_submenu_element("Text", "Text",
  1278         -                              "%s/artifact?name=%s&amp;txt=1", g.zTop, zUuid);
         1284  +                              "%s/artifact/%s?txt=1", g.zTop, zUuid);
  1279   1285         }
  1280   1286       }
  1281   1287     }
  1282   1288     @ </p></blockquote>
  1283   1289     @ <hr />
  1284   1290     content_get(rid, &content);
  1285   1291     if( renderAsWiki ){

Changes to src/main.c.

  1102   1102         continue;
  1103   1103       }
  1104   1104       if( blob_eq(&key, "HOME:") && blob_token(&line, &value) ){
  1105   1105         cgi_setenv("HOME", blob_str(&value));
  1106   1106         blob_reset(&value);
  1107   1107         continue;
  1108   1108       }
  1109         -    if( blob_eq(&key, "repository:") && blob_token(&line, &value) ){
         1109  +    if( blob_eq(&key, "repository:") && blob_tail(&line, &value) ){
         1110  +      blob_trim(&value);
  1110   1111         db_open_repository(blob_str(&value));
  1111   1112         blob_reset(&value);
  1112   1113         continue;
  1113   1114       }
  1114   1115       if( blob_eq(&key, "directory:") && blob_token(&line, &value) ){
  1115   1116         db_close(1);
  1116   1117         g.zRepositoryName = mprintf("%s", blob_str(&value));
................................................................................
  1437   1438   #else
  1438   1439     /* Win32 implementation */
  1439   1440     if( isUiCmd ){
  1440   1441       zBrowser = db_get("web-browser", "start");
  1441   1442       zBrowserCmd = mprintf("%s http://127.0.0.1:%%d/", zBrowser);
  1442   1443     }
  1443   1444     db_close(1);
  1444         -  win32_http_server(iPort, mxPort, zBrowserCmd, zStopperFile, zNotFound, flags);
         1445  +  if( win32_http_service(iPort, zNotFound, flags) ){
         1446  +    win32_http_server(iPort, mxPort, zBrowserCmd,
         1447  +                      zStopperFile, zNotFound, flags);
         1448  +  }
  1445   1449   #endif
  1446   1450   }
  1447   1451   
  1448   1452   /*
  1449   1453   ** COMMAND:  test-echo
  1450   1454   **
  1451   1455   ** Echo all command-line arguments (enclosed in [...]) to the screen so that

Changes to src/main.mk.

   291    291   # the repository after running the tests.
   292    292   test:	$(APPNAME)
   293    293   	$(TCLSH) test/tester.tcl $(APPNAME)
   294    294   
   295    295   $(OBJDIR)/VERSION.h:	$(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion
   296    296   	$(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid  $(SRCDIR)/../manifest  $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
   297    297   
   298         -EXTRAOBJ =  $(OBJDIR)/sqlite3.o  $(OBJDIR)/shell.o  $(OBJDIR)/th.o  $(OBJDIR)/th_lang.o
          298  +# The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
          299  +# to 1. If it is set to 1, then there is no need to build or link
          300  +# the sqlite3.o object. Instead, the system sqlite will be linked
          301  +# using -lsqlite3.
          302  +SQLITE3_OBJ.1 = 
          303  +SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
          304  +SQLITE3_OBJ.  = $(SQLITE3_OBJ.0)
          305  +
          306  +EXTRAOBJ =  $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE))  $(OBJDIR)/shell.o  $(OBJDIR)/th.o  $(OBJDIR)/th_lang.o
   299    307   
   300    308   $(APPNAME):	$(OBJDIR)/headers $(OBJ) $(EXTRAOBJ)
   301    309   	$(TCC) -o $(APPNAME) $(OBJ) $(EXTRAOBJ) $(LIB)
   302    310   
   303    311   # This rule prevents make from using its default rules to try build
   304    312   # an executable named "manifest" out of the file named "manifest.c"
   305    313   #
................................................................................
   890    898   $(OBJDIR)/zip.o:	$(OBJDIR)/zip_.c $(OBJDIR)/zip.h  $(SRCDIR)/config.h
   891    899   	$(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
   892    900   
   893    901   $(OBJDIR)/zip.h:	$(OBJDIR)/headers
   894    902   $(OBJDIR)/sqlite3.o:	$(SRCDIR)/sqlite3.c
   895    903   	$(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT2 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
   896    904   
   897         -$(OBJDIR)/shell.o:	$(SRCDIR)/shell.c
          905  +$(OBJDIR)/shell.o:	$(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
   898    906   	$(XTCC) -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
   899    907   
   900    908   $(OBJDIR)/th.o:	$(SRCDIR)/th.c
   901    909   	$(XTCC) -I$(SRCDIR) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
   902    910   
   903    911   $(OBJDIR)/th_lang.o:	$(SRCDIR)/th_lang.c
   904    912   	$(XTCC) -I$(SRCDIR) -c $(SRCDIR)/th_lang.c -o $(OBJDIR)/th_lang.o
   905    913   

Changes to src/makemake.tcl.

   188    188   	$(TCLSH) test/tester.tcl $(APPNAME)
   189    189   
   190    190   $(OBJDIR)/VERSION.h:	$(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION $(OBJDIR)/mkversion
   191    191   	$(OBJDIR)/mkversion $(SRCDIR)/../manifest.uuid \
   192    192   		$(SRCDIR)/../manifest \
   193    193   		$(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
   194    194   
          195  +# The USE_SYSTEM_SQLITE variable may be undefined, set to 0, or set
          196  +# to 1. If it is set to 1, then there is no need to build or link
          197  +# the sqlite3.o object. Instead, the system sqlite will be linked
          198  +# using -lsqlite3.
          199  +SQLITE3_OBJ.1 = 
          200  +SQLITE3_OBJ.0 = $(OBJDIR)/sqlite3.o
          201  +SQLITE3_OBJ.  = $(SQLITE3_OBJ.0)
          202  +
   195    203   EXTRAOBJ = \
   196         -  $(OBJDIR)/sqlite3.o \
          204  +  $(SQLITE3_OBJ.$(USE_SYSTEM_SQLITE)) \
   197    205     $(OBJDIR)/shell.o \
   198    206     $(OBJDIR)/th.o \
   199    207     $(OBJDIR)/th_lang.o
   200    208   
   201    209   $(APPNAME):	$(OBJDIR)/headers $(OBJ) $(EXTRAOBJ)
   202    210   	$(TCC) -o $(APPNAME) $(OBJ) $(EXTRAOBJ) $(LIB)
   203    211   
................................................................................
   244    252   #append opt " -DSQLITE_ENABLE_FTS3=1"
   245    253   append opt " -DSQLITE_ENABLE_STAT2"
   246    254   append opt " -Dlocaltime=fossil_localtime"
   247    255   append opt " -DSQLITE_ENABLE_LOCKING_STYLE=0"
   248    256   set SQLITE_OPTIONS $opt
   249    257   writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/sqlite3.c -o \$(OBJDIR)/sqlite3.o\n"
   250    258   
   251         -writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c"
          259  +writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite3.h"
   252    260   set opt {-Dmain=sqlite3_shell}
   253    261   append opt " -DSQLITE_OMIT_LOAD_EXTENSION=1"
   254    262   writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/shell.c -o \$(OBJDIR)/shell.o\n"
   255    263   
   256    264   writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c"
   257    265   writeln "\t\$(XTCC) -I\$(SRCDIR) -c \$(SRCDIR)/th.c -o \$(OBJDIR)/th.o\n"
   258    266   
................................................................................
   396    404   # WARNING. DANGER. Running the testsuite modifies the repository the
   397    405   # build is done from, i.e. the checkout belongs to. Do not sync/push
   398    406   # the repository after running the tests.
   399    407   test:	$(APPNAME)
   400    408   	$(TCLSH) test/tester.tcl $(APPNAME)
   401    409   
   402    410   $(OBJDIR)/VERSION.h:	$(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(VERSION)
   403         -	$(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest >$(OBJDIR)/VERSION.h
          411  +	$(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
   404    412   
   405    413   EXTRAOBJ = \
   406    414     $(OBJDIR)/sqlite3.o \
   407    415     $(OBJDIR)/shell.o \
   408    416     $(OBJDIR)/th.o \
   409    417     $(OBJDIR)/th_lang.o
   410    418   
................................................................................
   456    464   }
   457    465   
   458    466   
   459    467   writeln "\$(OBJDIR)/sqlite3.o:\t\$(SRCDIR)/sqlite3.c"
   460    468   set opt $SQLITE_OPTIONS
   461    469   writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/sqlite3.c -o \$(OBJDIR)/sqlite3.o\n"
   462    470   
   463         -writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c"
          471  +writeln "\$(OBJDIR)/shell.o:\t\$(SRCDIR)/shell.c \$(SRCDIR)/sqlite3.h"
   464    472   set opt {-Dmain=sqlite3_shell}
   465    473   append opt " -DSQLITE_OMIT_LOAD_EXTENSION=1"
   466    474   writeln "\t\$(XTCC) $opt -c \$(SRCDIR)/shell.c -o \$(OBJDIR)/shell.o\n"
   467    475   
   468    476   writeln "\$(OBJDIR)/th.o:\t\$(SRCDIR)/th.c"
   469    477   writeln "\t\$(XTCC) -I\$(SRCDIR) -c \$(SRCDIR)/th.c -o \$(OBJDIR)/th.o\n"
   470    478   
................................................................................
   568    576   
   569    577   $(OBJDIR)\th$O : $(SRCDIR)\th.c
   570    578   	$(TCC) -o$@ -c $**
   571    579   
   572    580   $(OBJDIR)\th_lang$O : $(SRCDIR)\th_lang.c
   573    581   	$(TCC) -o$@ -c $**
   574    582   
   575         -VERSION.h : version$E $B\manifest.uuid $B\manifest
          583  +VERSION.h : version$E $B\manifest.uuid $B\manifest $B\VERSION
   576    584   	+$** > $@
   577    585   
   578    586   page_index.h: mkindex$E $(SRC) 
   579    587   	+$** > $@
   580    588   
   581    589   clean:
   582    590   	-del $(OBJDIR)\*.obj
................................................................................
   643    651   ZLIB    = zlib.lib
   644    652   
   645    653   INCL   = -I. -I$(SRCDIR) -I$B\win\include -I$(MSCDIR)\extra\include -I$(ZINCDIR)
   646    654   
   647    655   CFLAGS = -nologo -MT -O2
   648    656   BCC    = $(CC) $(CFLAGS)
   649    657   TCC    = $(CC) -c $(CFLAGS) $(MSCDEF) $(SSL) $(INCL)
   650         -LIBS   = $(ZLIB) ws2_32.lib $(SSLLIB)
          658  +LIBS   = $(ZLIB) ws2_32.lib advapi32.lib $(SSLLIB)
   651    659   LIBDIR = -LIBPATH:$(MSCDIR)\extra\lib -LIBPATH:$(ZLIBDIR)
   652    660   }
   653    661   regsub -all {[-]D} $SQLITE_OPTIONS {/D} MSC_SQLITE_OPTIONS
   654    662   writeln "SQLITE_OPTIONS = $MSC_SQLITE_OPTIONS\n"
   655    663   writeln -nonewline "SRC   = "
   656    664   foreach s [lsort $src] {
   657    665     writeln -nonewline "${s}_.c "
................................................................................
   690    698   
   691    699   makeheaders$E: $(SRCDIR)\makeheaders.c
   692    700   	$(BCC) $**
   693    701   
   694    702   mkindex$E: $(SRCDIR)\mkindex.c
   695    703   	$(BCC) $**
   696    704   
   697         -version$E: $B\src\mkversion.c
          705  +mkversion$E: $B\src\mkversion.c
   698    706   	$(BCC) $**
   699    707   
   700    708   $(OX)\shell$O : $(SRCDIR)\shell.c
   701    709   	$(TCC) /Fo$@ /Dmain=sqlite3_shell $(SQLITE_OPTIONS) -c $(SRCDIR)\shell.c
   702    710   
   703    711   $(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c
   704    712   	$(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $**
................................................................................
   705    713   
   706    714   $(OX)\th$O : $(SRCDIR)\th.c
   707    715   	$(TCC) /Fo$@ -c $**
   708    716   
   709    717   $(OX)\th_lang$O : $(SRCDIR)\th_lang.c
   710    718   	$(TCC) /Fo$@ -c $**
   711    719   
   712         -VERSION.h : version$E $B\manifest.uuid $B\manifest
          720  +VERSION.h : mkversion$E $B\manifest.uuid $B\manifest $B\VERSION
   713    721   	$** > $@
   714    722   
   715    723   page_index.h: mkindex$E $(SRC) 
   716    724   	$** > $@
   717    725   
   718    726   clean:
   719    727   	-del $(OX)\*.obj
................................................................................
   889    897   	translate.exe $< >$@
   890    898   
   891    899   # generate the index source, containing all web references,..
   892    900   page_index.h:	$(TRANSLATEDSRC) mkindex.exe
   893    901   	mkindex.exe $(TRANSLATEDSRC) >$@
   894    902   
   895    903   # extracting version info from manifest
   896         -VERSION.h:	version.exe ..\manifest.uuid ..\manifest
   897         -	version.exe ..\manifest.uuid ..\manifest  > $@
          904  +VERSION.h:	version.exe ..\manifest.uuid ..\manifest ..\VERSION
          905  +	version.exe ..\manifest.uuid ..\manifest ..\VERSION  > $@
   898    906   
   899    907   # generate the simplified headers
   900    908   headers: makeheaders.exe page_index.h VERSION.h ../src/sqlite3.h ../src/th.h VERSION.h
   901    909   	makeheaders.exe $(foreach ts,$(TRANSLATEDSRC),$(ts):$(ts:_.c=.h)) ../src/sqlite3.h ../src/th.h VERSION.h
   902    910   	echo Done >$@
   903    911   
   904    912   # compile C sources with relevant options

Changes to src/printf.c.

   857    857       return +1;
   858    858     }else{
   859    859       int a, b;
   860    860       do{ 
   861    861         a = *zA++;
   862    862         b = *zB++;
   863    863       }while( a==b && a!=0 );
   864         -    return a - b;
          864  +    return ((unsigned char)a) - (unsigned char)b;
   865    865     }
   866    866   }
   867    867   
   868    868   /*
   869    869   ** Case insensitive string comparison.
   870    870   */
   871    871   int fossil_strnicmp(const char *zA, const char *zB, int nByte){

Changes to src/rebuild.c.

   880    880     zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin);
   881    881     fossil_print("admin-user: %s (initial password is \"%s\")\n", g.zLogin, zPassword);
   882    882   }
   883    883   
   884    884   /*
   885    885   ** COMMAND: deconstruct
   886    886   **
   887         -** Usage %fossil deconstruct ?OPTIONS? DESTIONATION
          887  +** Usage %fossil deconstruct ?OPTIONS? DESTINATION
   888    888   **
   889    889   ** Options:
   890    890   **   -R|--repository REPOSITORY
   891    891   **   -L|--prefixlength N
   892    892   **
   893    893   ** This command exports all artifacts of a given repository and
   894    894   ** writes all artifacts to the file system. The DESTINATION directory

Changes to src/sqlite3.c.

   648    648   **
   649    649   ** See also: [sqlite3_libversion()],
   650    650   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   651    651   ** [sqlite_version()] and [sqlite_source_id()].
   652    652   */
   653    653   #define SQLITE_VERSION        "3.7.7"
   654    654   #define SQLITE_VERSION_NUMBER 3007007
   655         -#define SQLITE_SOURCE_ID      "2011-06-15 13:11:06 f9750870ee04935f338e4d808900fee5a8b2b389"
          655  +#define SQLITE_SOURCE_ID      "2011-06-24 11:29:51 9b191bb4c7c1e1b12b188c0b3eee1f8f587887c8"
   656    656   
   657    657   /*
   658    658   ** CAPI3REF: Run-Time Library Version Numbers
   659    659   ** KEYWORDS: sqlite3_version, sqlite3_sourceid
   660    660   **
   661    661   ** These interfaces provide the same information as the [SQLITE_VERSION],
   662    662   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
   849    849   **
   850    850   ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
   851    851   ** semicolon-separate SQL statements passed into its 2nd argument,
   852    852   ** in the context of the [database connection] passed in as its 1st
   853    853   ** argument.  ^If the callback function of the 3rd argument to
   854    854   ** sqlite3_exec() is not NULL, then it is invoked for each result row
   855    855   ** coming out of the evaluated SQL statements.  ^The 4th argument to
   856         -** to sqlite3_exec() is relayed through to the 1st argument of each
          856  +** sqlite3_exec() is relayed through to the 1st argument of each
   857    857   ** callback invocation.  ^If the callback pointer to sqlite3_exec()
   858    858   ** is NULL, then no callback is ever invoked and result rows are
   859    859   ** ignored.
   860    860   **
   861    861   ** ^If an error occurs while evaluating the SQL statements passed into
   862    862   ** sqlite3_exec(), then execution of the current statement stops and
   863    863   ** subsequent statements are skipped.  ^If the 5th parameter to sqlite3_exec()
................................................................................
  1441   1441   ** of good-quality randomness into zOut.  The return value is
  1442   1442   ** the actual number of bytes of randomness obtained.
  1443   1443   ** The xSleep() method causes the calling thread to sleep for at
  1444   1444   ** least the number of microseconds given.  ^The xCurrentTime()
  1445   1445   ** method returns a Julian Day Number for the current date and time as
  1446   1446   ** a floating point value.
  1447   1447   ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
  1448         -** Day Number multipled by 86400000 (the number of milliseconds in 
         1448  +** Day Number multiplied by 86400000 (the number of milliseconds in 
  1449   1449   ** a 24-hour day).  
  1450   1450   ** ^SQLite will use the xCurrentTimeInt64() method to get the current
  1451   1451   ** date and time if that method is available (if iVersion is 2 or 
  1452   1452   ** greater and the function pointer is not NULL) and will fall back
  1453   1453   ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
  1454   1454   **
  1455   1455   ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
................................................................................
  1879   1879   ** ^SQLite will never require a scratch buffer that is more than 6
  1880   1880   ** times the database page size. ^If SQLite needs needs additional
  1881   1881   ** scratch memory beyond what is provided by this configuration option, then 
  1882   1882   ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
  1883   1883   **
  1884   1884   ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
  1885   1885   ** <dd> ^This option specifies a static memory buffer that SQLite can use for
  1886         -** the database page cache with the default page cache implemenation.  
         1886  +** the database page cache with the default page cache implementation.  
  1887   1887   ** This configuration should not be used if an application-define page
  1888   1888   ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option.
  1889   1889   ** There are three arguments to this option: A pointer to 8-byte aligned
  1890   1890   ** memory, the size of each page buffer (sz), and the number of pages (N).
  1891   1891   ** The sz argument should be the size of the largest database page
  1892   1892   ** (a power of two between 512 and 32768) plus a little extra for each
  1893   1893   ** page header.  ^The page header size is 20 to 40 bytes depending on
................................................................................
  2977   2977   ** automatically deleted as soon as the database connection is closed.
  2978   2978   **
  2979   2979   ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
  2980   2980   **
  2981   2981   ** ^If [URI filename] interpretation is enabled, and the filename argument
  2982   2982   ** begins with "file:", then the filename is interpreted as a URI. ^URI
  2983   2983   ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
  2984         -** is set in the fourth argument to sqlite3_open_v2(), or if it has
         2984  +** set in the fourth argument to sqlite3_open_v2(), or if it has
  2985   2985   ** been enabled globally using the [SQLITE_CONFIG_URI] option with the
  2986   2986   ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
  2987   2987   ** As of SQLite version 3.7.7, URI filename interpretation is turned off
  2988   2988   ** by default, but future releases of SQLite might enable URI filename
  2989         -** intepretation by default.  See "[URI filenames]" for additional
         2989  +** interpretation by default.  See "[URI filenames]" for additional
  2990   2990   ** information.
  2991   2991   **
  2992   2992   ** URI filenames are parsed according to RFC 3986. ^If the URI contains an
  2993   2993   ** authority, then it must be either an empty string or the string 
  2994   2994   ** "localhost". ^If the authority is not an empty string or "localhost", an 
  2995   2995   ** error is returned to the caller. ^The fragment component of a URI, if 
  2996   2996   ** present, is ignored.
................................................................................
  3801   3801   ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
  3802   3802   ** ^With the "v2" interface, any of the other [result codes] or
  3803   3803   ** [extended result codes] might be returned as well.
  3804   3804   **
  3805   3805   ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the
  3806   3806   ** database locks it needs to do its job.  ^If the statement is a [COMMIT]
  3807   3807   ** or occurs outside of an explicit transaction, then you can retry the
  3808         -** statement.  If the statement is not a [COMMIT] and occurs within a
         3808  +** statement.  If the statement is not a [COMMIT] and occurs within an
  3809   3809   ** explicit transaction then you should rollback the transaction before
  3810   3810   ** continuing.
  3811   3811   **
  3812   3812   ** ^[SQLITE_DONE] means that the statement has finished executing
  3813   3813   ** successfully.  sqlite3_step() should not be called again on this virtual
  3814   3814   ** machine without first calling [sqlite3_reset()] to reset the virtual
  3815   3815   ** machine back to its initial state.
................................................................................
  4080   4080   SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);
  4081   4081   SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
  4082   4082   
  4083   4083   /*
  4084   4084   ** CAPI3REF: Destroy A Prepared Statement Object
  4085   4085   **
  4086   4086   ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
  4087         -** ^If the most recent evaluation of the statement encountered no errors or
         4087  +** ^If the most recent evaluation of the statement encountered no errors
  4088   4088   ** or if the statement is never been evaluated, then sqlite3_finalize() returns
  4089   4089   ** SQLITE_OK.  ^If the most recent evaluation of statement S failed, then
  4090   4090   ** sqlite3_finalize(S) returns the appropriate [error code] or
  4091   4091   ** [extended error code].
  4092   4092   **
  4093   4093   ** ^The sqlite3_finalize(S) routine can be called at any point during
  4094   4094   ** the life cycle of [prepared statement] S:
................................................................................
  5994   5994   ** ^The implementation is not required to provided versions of these
  5995   5995   ** routines that actually work. If the implementation does not provide working
  5996   5996   ** versions of these routines, it should at least provide stubs that always
  5997   5997   ** return true so that one does not get spurious assertion failures.
  5998   5998   **
  5999   5999   ** ^If the argument to sqlite3_mutex_held() is a NULL pointer then
  6000   6000   ** the routine should return 1.   This seems counter-intuitive since
  6001         -** clearly the mutex cannot be held if it does not exist.  But the
         6001  +** clearly the mutex cannot be held if it does not exist.  But
  6002   6002   ** the reason the mutex does not exist is because the build is not
  6003   6003   ** using mutexes.  And we do not want the assert() containing the
  6004   6004   ** call to sqlite3_mutex_held() to fail, so a non-zero return is
  6005   6005   ** the appropriate thing to do.  ^The sqlite3_mutex_notheld()
  6006   6006   ** interface should also return 1 when given a NULL pointer.
  6007   6007   */
  6008   6008   #ifndef NDEBUG
................................................................................
  6117   6117   #define SQLITE_TESTCTRL_ASSERT                  12
  6118   6118   #define SQLITE_TESTCTRL_ALWAYS                  13
  6119   6119   #define SQLITE_TESTCTRL_RESERVE                 14
  6120   6120   #define SQLITE_TESTCTRL_OPTIMIZATIONS           15
  6121   6121   #define SQLITE_TESTCTRL_ISKEYWORD               16
  6122   6122   #define SQLITE_TESTCTRL_PGHDRSZ                 17
  6123   6123   #define SQLITE_TESTCTRL_SCRATCHMALLOC           18
  6124         -#define SQLITE_TESTCTRL_LAST                    18
         6124  +#define SQLITE_TESTCTRL_LOCALTIME_FAULT         19
         6125  +#define SQLITE_TESTCTRL_LAST                    19
  6125   6126   
  6126   6127   /*
  6127   6128   ** CAPI3REF: SQLite Runtime Status
  6128   6129   **
  6129   6130   ** ^This interface is used to retrieve runtime status information
  6130   6131   ** about the performance of SQLite, and optionally to reset various
  6131   6132   ** highwater marks.  ^The first argument is an integer code for
................................................................................
  6503   6504   ** stored in the cache, both pinned and unpinned.
  6504   6505   ** 
  6505   6506   ** [[the xFetch() page cache methods]]
  6506   6507   ** The xFetch() method locates a page in the cache and returns a pointer to 
  6507   6508   ** the page, or a NULL pointer.
  6508   6509   ** A "page", in this context, means a buffer of szPage bytes aligned at an
  6509   6510   ** 8-byte boundary. The page to be fetched is determined by the key. ^The
  6510         -** mimimum key value is 1.  After it has been retrieved using xFetch, the page 
         6511  +** minimum key value is 1.  After it has been retrieved using xFetch, the page 
  6511   6512   ** is considered to be "pinned".
  6512   6513   **
  6513   6514   ** If the requested page is already in the page cache, then the page cache
  6514   6515   ** implementation must return a pointer to the page buffer with its content
  6515   6516   ** intact.  If the requested page is not already in the cache, then the
  6516   6517   ** cache implementation should use the value of the createFlag
  6517   6518   ** parameter to help it determined what action to take:
................................................................................
  9554   9555   #define SQLITE_QueryFlattener 0x01        /* Disable query flattening */
  9555   9556   #define SQLITE_ColumnCache    0x02        /* Disable the column cache */
  9556   9557   #define SQLITE_IndexSort      0x04        /* Disable indexes for sorting */
  9557   9558   #define SQLITE_IndexSearch    0x08        /* Disable indexes for searching */
  9558   9559   #define SQLITE_IndexCover     0x10        /* Disable index covering table */
  9559   9560   #define SQLITE_GroupByOrder   0x20        /* Disable GROUPBY cover of ORDERBY */
  9560   9561   #define SQLITE_FactorOutConst 0x40        /* Disable factoring out constants */
         9562  +#define SQLITE_IdxRealAsInt   0x80        /* Store REAL as INT in indices */
  9561   9563   #define SQLITE_OptMask        0xff        /* Mask of all disablable opts */
  9562   9564   
  9563   9565   /*
  9564   9566   ** Possible values for the sqlite.magic field.
  9565   9567   ** The numbers are obtained at random and have no special meaning, other
  9566   9568   ** than being distinct from one another.
  9567   9569   */
................................................................................
 11051  11053     int isMutexInit;                  /* True after mutexes are initialized */
 11052  11054     int isMallocInit;                 /* True after malloc is initialized */
 11053  11055     int isPCacheInit;                 /* True after malloc is initialized */
 11054  11056     sqlite3_mutex *pInitMutex;        /* Mutex used by sqlite3_initialize() */
 11055  11057     int nRefInitMutex;                /* Number of users of pInitMutex */
 11056  11058     void (*xLog)(void*,int,const char*); /* Function for logging */
 11057  11059     void *pLogArg;                       /* First argument to xLog() */
        11060  +  int bLocaltimeFault;              /* True to fail localtime() calls */
 11058  11061   };
 11059  11062   
 11060  11063   /*
 11061  11064   ** Context pointer passed down through the tree-walk.
 11062  11065   */
 11063  11066   struct Walker {
 11064  11067     int (*xExprCallback)(Walker*, Expr*);     /* Callback for expressions */
................................................................................
 12011  12014      0,                         /* isMutexInit */
 12012  12015      0,                         /* isMallocInit */
 12013  12016      0,                         /* isPCacheInit */
 12014  12017      0,                         /* pInitMutex */
 12015  12018      0,                         /* nRefInitMutex */
 12016  12019      0,                         /* xLog */
 12017  12020      0,                         /* pLogArg */
        12021  +   0,                         /* bLocaltimeFault */
 12018  12022   };
 12019  12023   
 12020  12024   
 12021  12025   /*
 12022  12026   ** Hash table for global functions - functions common to all
 12023  12027   ** database connections.  After initialization, this table is
 12024  12028   ** read-only.
................................................................................
 13161  13165   **      Willmann-Bell, Inc
 13162  13166   **      Richmond, Virginia (USA)
 13163  13167   */
 13164  13168   #include <time.h>
 13165  13169   
 13166  13170   #ifndef SQLITE_OMIT_DATETIME_FUNCS
 13167  13171   
 13168         -/*
 13169         -** On recent Windows platforms, the localtime_s() function is available
 13170         -** as part of the "Secure CRT". It is essentially equivalent to 
 13171         -** localtime_r() available under most POSIX platforms, except that the 
 13172         -** order of the parameters is reversed.
 13173         -**
 13174         -** See http://msdn.microsoft.com/en-us/library/a442x3ye(VS.80).aspx.
 13175         -**
 13176         -** If the user has not indicated to use localtime_r() or localtime_s()
 13177         -** already, check for an MSVC build environment that provides 
 13178         -** localtime_s().
 13179         -*/
 13180         -#if !defined(HAVE_LOCALTIME_R) && !defined(HAVE_LOCALTIME_S) && \
 13181         -     defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
 13182         -#define HAVE_LOCALTIME_S 1
 13183         -#endif
 13184  13172   
 13185  13173   /*
 13186  13174   ** A structure for holding a single date and time.
 13187  13175   */
 13188  13176   typedef struct DateTime DateTime;
 13189  13177   struct DateTime {
 13190  13178     sqlite3_int64 iJD; /* The julian day number times 86400000 */
................................................................................
 13521  13509   ** Clear the YMD and HMS and the TZ
 13522  13510   */
 13523  13511   static void clearYMD_HMS_TZ(DateTime *p){
 13524  13512     p->validYMD = 0;
 13525  13513     p->validHMS = 0;
 13526  13514     p->validTZ = 0;
 13527  13515   }
        13516  +
        13517  +/*
        13518  +** On recent Windows platforms, the localtime_s() function is available
        13519  +** as part of the "Secure CRT". It is essentially equivalent to 
        13520  +** localtime_r() available under most POSIX platforms, except that the 
        13521  +** order of the parameters is reversed.
        13522  +**
        13523  +** See http://msdn.microsoft.com/en-us/library/a442x3ye(VS.80).aspx.
        13524  +**
        13525  +** If the user has not indicated to use localtime_r() or localtime_s()
        13526  +** already, check for an MSVC build environment that provides 
        13527  +** localtime_s().
        13528  +*/
        13529  +#if !defined(HAVE_LOCALTIME_R) && !defined(HAVE_LOCALTIME_S) && \
        13530  +     defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE)
        13531  +#define HAVE_LOCALTIME_S 1
        13532  +#endif
        13533  +
        13534  +#ifndef SQLITE_OMIT_LOCALTIME
        13535  +/*
        13536  +** The following routine implements the rough equivalent of localtime_r()
        13537  +** using whatever operating-system specific localtime facility that
        13538  +** is available.  This routine returns 0 on success and
        13539  +** non-zero on any kind of error.
        13540  +**
        13541  +** If the sqlite3GlobalConfig.bLocaltimeFault variable is true then this
        13542  +** routine will always fail.
        13543  +*/
        13544  +static int osLocaltime(time_t *t, struct tm *pTm){
        13545  +  int rc;
        13546  +#if (!defined(HAVE_LOCALTIME_R) || !HAVE_LOCALTIME_R) \
        13547  +      && (!defined(HAVE_LOCALTIME_S) || !HAVE_LOCALTIME_S)
        13548  +  struct tm *pX;
        13549  +#if SQLITE_THREADSAFE>0
        13550  +  sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
        13551  +#endif
        13552  +  sqlite3_mutex_enter(mutex);
        13553  +  pX = localtime(t);
        13554  +#ifndef SQLITE_OMIT_BUILTIN_TEST
        13555  +  if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0;
        13556  +#endif
        13557  +  if( pX ) *pTm = *pX;
        13558  +  sqlite3_mutex_leave(mutex);
        13559  +  rc = pX==0;
        13560  +#else
        13561  +#ifndef SQLITE_OMIT_BUILTIN_TEST
        13562  +  if( sqlite3GlobalConfig.bLocaltimeFault ) return 1;
        13563  +#endif
        13564  +#if defined(HAVE_LOCALTIME_R) && HAVE_LOCALTIME_R
        13565  +  rc = localtime_r(t, pTm)==0;
        13566  +#else
        13567  +  rc = localtime_s(pTm, t);
        13568  +#endif /* HAVE_LOCALTIME_R */
        13569  +#endif /* HAVE_LOCALTIME_R || HAVE_LOCALTIME_S */
        13570  +  return rc;
        13571  +}
        13572  +#endif /* SQLITE_OMIT_LOCALTIME */
        13573  +
 13528  13574   
 13529  13575   #ifndef SQLITE_OMIT_LOCALTIME
 13530  13576   /*
 13531         -** Compute the difference (in milliseconds)
 13532         -** between localtime and UTC (a.k.a. GMT)
 13533         -** for the time value p where p is in UTC.
        13577  +** Compute the difference (in milliseconds) between localtime and UTC
        13578  +** (a.k.a. GMT) for the time value p where p is in UTC. If no error occurs,
        13579  +** return this value and set *pRc to SQLITE_OK. 
        13580  +**
        13581  +** Or, if an error does occur, set *pRc to SQLITE_ERROR. The returned value
        13582  +** is undefined in this case.
 13534  13583   */
 13535         -static sqlite3_int64 localtimeOffset(DateTime *p){
        13584  +static sqlite3_int64 localtimeOffset(
        13585  +  DateTime *p,                    /* Date at which to calculate offset */
        13586  +  sqlite3_context *pCtx,          /* Write error here if one occurs */
        13587  +  int *pRc                        /* OUT: Error code. SQLITE_OK or ERROR */
        13588  +){
 13536  13589     DateTime x, y;
 13537  13590     time_t t;
        13591  +  struct tm sLocal;
        13592  +
        13593  +  /* Initialize the contents of sLocal to avoid a compiler warning. */
        13594  +  memset(&sLocal, 0, sizeof(sLocal));
        13595  +
 13538  13596     x = *p;
 13539  13597     computeYMD_HMS(&x);
 13540  13598     if( x.Y<1971 || x.Y>=2038 ){
 13541  13599       x.Y = 2000;
 13542  13600       x.M = 1;
 13543  13601       x.D = 1;
 13544  13602       x.h = 0;
................................................................................
 13548  13606       int s = (int)(x.s + 0.5);
 13549  13607       x.s = s;
 13550  13608     }
 13551  13609     x.tz = 0;
 13552  13610     x.validJD = 0;
 13553  13611     computeJD(&x);
 13554  13612     t = (time_t)(x.iJD/1000 - 21086676*(i64)10000);
 13555         -#ifdef HAVE_LOCALTIME_R
 13556         -  {
 13557         -    struct tm sLocal;
 13558         -    localtime_r(&t, &sLocal);
 13559         -    y.Y = sLocal.tm_year + 1900;
 13560         -    y.M = sLocal.tm_mon + 1;
 13561         -    y.D = sLocal.tm_mday;
 13562         -    y.h = sLocal.tm_hour;
 13563         -    y.m = sLocal.tm_min;
 13564         -    y.s = sLocal.tm_sec;
        13613  +  if( osLocaltime(&t, &sLocal) ){
        13614  +    sqlite3_result_error(pCtx, "local time unavailable", -1);
        13615  +    *pRc = SQLITE_ERROR;
        13616  +    return 0;
 13565  13617     }
 13566         -#elif defined(HAVE_LOCALTIME_S) && HAVE_LOCALTIME_S
 13567         -  {
 13568         -    struct tm sLocal;
 13569         -    localtime_s(&sLocal, &t);
 13570         -    y.Y = sLocal.tm_year + 1900;
 13571         -    y.M = sLocal.tm_mon + 1;
 13572         -    y.D = sLocal.tm_mday;
 13573         -    y.h = sLocal.tm_hour;
 13574         -    y.m = sLocal.tm_min;
 13575         -    y.s = sLocal.tm_sec;
 13576         -  }
 13577         -#else
 13578         -  {
 13579         -    struct tm *pTm;
 13580         -    sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
 13581         -    pTm = localtime(&t);
 13582         -    y.Y = pTm->tm_year + 1900;
 13583         -    y.M = pTm->tm_mon + 1;
 13584         -    y.D = pTm->tm_mday;
 13585         -    y.h = pTm->tm_hour;
 13586         -    y.m = pTm->tm_min;
 13587         -    y.s = pTm->tm_sec;
 13588         -    sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER));
 13589         -  }
 13590         -#endif
        13618  +  y.Y = sLocal.tm_year + 1900;
        13619  +  y.M = sLocal.tm_mon + 1;
        13620  +  y.D = sLocal.tm_mday;
        13621  +  y.h = sLocal.tm_hour;
        13622  +  y.m = sLocal.tm_min;
        13623  +  y.s = sLocal.tm_sec;
 13591  13624     y.validYMD = 1;
 13592  13625     y.validHMS = 1;
 13593  13626     y.validJD = 0;
 13594  13627     y.validTZ = 0;
 13595  13628     computeJD(&y);
        13629  +  *pRc = SQLITE_OK;
 13596  13630     return y.iJD - x.iJD;
 13597  13631   }
 13598  13632   #endif /* SQLITE_OMIT_LOCALTIME */
 13599  13633   
 13600  13634   /*
 13601  13635   ** Process a modifier to a date-time stamp.  The modifiers are
 13602  13636   ** as follows:
................................................................................
 13612  13646   **     start of week
 13613  13647   **     start of day
 13614  13648   **     weekday N
 13615  13649   **     unixepoch
 13616  13650   **     localtime
 13617  13651   **     utc
 13618  13652   **
 13619         -** Return 0 on success and 1 if there is any kind of error.
        13653  +** Return 0 on success and 1 if there is any kind of error. If the error
        13654  +** is in a system call (i.e. localtime()), then an error message is written
        13655  +** to context pCtx. If the error is an unrecognized modifier, no error is
        13656  +** written to pCtx.
 13620  13657   */
 13621         -static int parseModifier(const char *zMod, DateTime *p){
        13658  +static int parseModifier(sqlite3_context *pCtx, const char *zMod, DateTime *p){
 13622  13659     int rc = 1;
 13623  13660     int n;
 13624  13661     double r;
 13625  13662     char *z, zBuf[30];
 13626  13663     z = zBuf;
 13627  13664     for(n=0; n<ArraySize(zBuf)-1 && zMod[n]; n++){
 13628  13665       z[n] = (char)sqlite3UpperToLower[(u8)zMod[n]];
................................................................................
 13634  13671         /*    localtime
 13635  13672         **
 13636  13673         ** Assuming the current time value is UTC (a.k.a. GMT), shift it to
 13637  13674         ** show local time.
 13638  13675         */
 13639  13676         if( strcmp(z, "localtime")==0 ){
 13640  13677           computeJD(p);
 13641         -        p->iJD += localtimeOffset(p);
        13678  +        p->iJD += localtimeOffset(p, pCtx, &rc);
 13642  13679           clearYMD_HMS_TZ(p);
 13643         -        rc = 0;
 13644  13680         }
 13645  13681         break;
 13646  13682       }
 13647  13683   #endif
 13648  13684       case 'u': {
 13649  13685         /*
 13650  13686         **    unixepoch
................................................................................
 13657  13693           clearYMD_HMS_TZ(p);
 13658  13694           rc = 0;
 13659  13695         }
 13660  13696   #ifndef SQLITE_OMIT_LOCALTIME
 13661  13697         else if( strcmp(z, "utc")==0 ){
 13662  13698           sqlite3_int64 c1;
 13663  13699           computeJD(p);
 13664         -        c1 = localtimeOffset(p);
 13665         -        p->iJD -= c1;
 13666         -        clearYMD_HMS_TZ(p);
 13667         -        p->iJD += c1 - localtimeOffset(p);
 13668         -        rc = 0;
        13700  +        c1 = localtimeOffset(p, pCtx, &rc);
        13701  +        if( rc==SQLITE_OK ){
        13702  +          p->iJD -= c1;
        13703  +          clearYMD_HMS_TZ(p);
        13704  +          p->iJD += c1 - localtimeOffset(p, pCtx, &rc);
        13705  +        }
 13669  13706         }
 13670  13707   #endif
 13671  13708         break;
 13672  13709       }
 13673  13710       case 'w': {
 13674  13711         /*
 13675  13712         **    weekday N
................................................................................
 13842  13879     }else{
 13843  13880       z = sqlite3_value_text(argv[0]);
 13844  13881       if( !z || parseDateOrTime(context, (char*)z, p) ){
 13845  13882         return 1;
 13846  13883       }
 13847  13884     }
 13848  13885     for(i=1; i<argc; i++){
 13849         -    if( (z = sqlite3_value_text(argv[i]))==0 || parseModifier((char*)z, p) ){
 13850         -      return 1;
 13851         -    }
        13886  +    z = sqlite3_value_text(argv[i]);
        13887  +    if( z==0 || parseModifier(context, (char*)z, p) ) return 1;
 13852  13888     }
 13853  13889     return 0;
 13854  13890   }
 13855  13891   
 13856  13892   
 13857  13893   /*
 13858  13894   ** The following routines implement the various date and time functions
................................................................................
 24362  24398   # endif
 24363  24399   #endif /* SQLITE_ENABLE_LOCKING_STYLE */
 24364  24400   
 24365  24401   #if defined(__APPLE__) || (SQLITE_ENABLE_LOCKING_STYLE && !OS_VXWORKS)
 24366  24402   # include <sys/mount.h>
 24367  24403   #endif
 24368  24404   
        24405  +#ifdef HAVE_UTIME
        24406  +# include <utime.h>
        24407  +#endif
        24408  +
 24369  24409   /*
 24370  24410   ** Allowed values of unixFile.fsFlags
 24371  24411   */
 24372  24412   #define SQLITE_FSFLAGS_IS_MSDOS     0x1
 24373  24413   
 24374  24414   /*
 24375  24415   ** If we are to be thread-safe, include the pthreads header and define
................................................................................
 26367  26407   
 26368  26408   
 26369  26409     /* If we have any lock, then the lock file already exists.  All we have
 26370  26410     ** to do is adjust our internal record of the lock level.
 26371  26411     */
 26372  26412     if( pFile->eFileLock > NO_LOCK ){
 26373  26413       pFile->eFileLock = eFileLock;
 26374         -#if !OS_VXWORKS
 26375  26414       /* Always update the timestamp on the old file */
        26415  +#ifdef HAVE_UTIME
        26416  +    utime(zLockFile, NULL);
        26417  +#else
 26376  26418       utimes(zLockFile, NULL);
 26377  26419   #endif
 26378  26420       return SQLITE_OK;
 26379  26421     }
 26380  26422     
 26381  26423     /* grab an exclusive lock */
 26382  26424     fd = robust_open(zLockFile,O_RDONLY|O_CREAT|O_EXCL,0600);
................................................................................
 28094  28136   */
 28095  28137   static void unixShmPurge(unixFile *pFd){
 28096  28138     unixShmNode *p = pFd->pInode->pShmNode;
 28097  28139     assert( unixMutexHeld() );
 28098  28140     if( p && p->nRef==0 ){
 28099  28141       int i;
 28100  28142       assert( p->pInode==pFd->pInode );
 28101         -    if( p->mutex ) sqlite3_mutex_free(p->mutex);
        28143  +    sqlite3_mutex_free(p->mutex);
 28102  28144       for(i=0; i<p->nRegion; i++){
 28103  28145         if( p->h>=0 ){
 28104  28146           munmap(p->apRegion[i], p->szRegion);
 28105  28147         }else{
 28106  28148           sqlite3_free(p->apRegion[i]);
 28107  28149         }
 28108  28150       }
................................................................................
 32252  32294       if( nRem>0 ){
 32253  32295         pFile->lastErrno = GetLastError();
 32254  32296         rc = 1;
 32255  32297       }
 32256  32298     }
 32257  32299   
 32258  32300     if( rc ){
 32259         -    if( pFile->lastErrno==ERROR_HANDLE_DISK_FULL ){
        32301  +    if(   ( pFile->lastErrno==ERROR_HANDLE_DISK_FULL )
        32302  +       || ( pFile->lastErrno==ERROR_DISK_FULL )){
 32260  32303         return SQLITE_FULL;
 32261  32304       }
 32262  32305       return winLogError(SQLITE_IOERR_WRITE, "winWrite", pFile->zPath);
 32263  32306     }
 32264  32307     return SQLITE_OK;
 32265  32308   }
 32266  32309   
................................................................................
 61203  61246       ** caller. Set the error code in the database handle to the same value.
 61204  61247       */ 
 61205  61248       rc = db->errCode = p->rc;
 61206  61249     }
 61207  61250     return (rc&db->errMask);
 61208  61251   }
 61209  61252   
        61253  +/*
        61254  +** The maximum number of times that a statement will try to reparse
        61255  +** itself before giving up and returning SQLITE_SCHEMA.
        61256  +*/
        61257  +#ifndef SQLITE_MAX_SCHEMA_RETRY
        61258  +# define SQLITE_MAX_SCHEMA_RETRY 5
        61259  +#endif
        61260  +
 61210  61261   /*
 61211  61262   ** This is the top-level implementation of sqlite3_step().  Call
 61212  61263   ** sqlite3Step() to do most of the work.  If a schema error occurs,
 61213  61264   ** call sqlite3Reprepare() and try again.
 61214  61265   */
 61215  61266   SQLITE_API int sqlite3_step(sqlite3_stmt *pStmt){
 61216  61267     int rc = SQLITE_OK;      /* Result from sqlite3Step() */
................................................................................
 61221  61272   
 61222  61273     if( vdbeSafetyNotNull(v) ){
 61223  61274       return SQLITE_MISUSE_BKPT;
 61224  61275     }
 61225  61276     db = v->db;
 61226  61277     sqlite3_mutex_enter(db->mutex);
 61227  61278     while( (rc = sqlite3Step(v))==SQLITE_SCHEMA
 61228         -         && cnt++ < 5
        61279  +         && cnt++ < SQLITE_MAX_SCHEMA_RETRY
 61229  61280            && (rc2 = rc = sqlite3Reprepare(v))==SQLITE_OK ){
 61230  61281       sqlite3_reset(pStmt);
 61231  61282       v->expired = 0;
 61232  61283     }
 61233  61284     if( rc2!=SQLITE_OK && ALWAYS(v->isPrepareV2) && ALWAYS(db->pErr) ){
 61234  61285       /* This case occurs after failing to recompile an sql statement. 
 61235  61286       ** The error message from the SQL compiler has already been loaded 
................................................................................
 63494  63545     REGISTER_TRACE(pOp->p1, pIn1);
 63495  63546     pc = u.aa.pcDest;
 63496  63547     break;
 63497  63548   }
 63498  63549   
 63499  63550   /* Opcode:  HaltIfNull  P1 P2 P3 P4 *
 63500  63551   **
 63501         -** Check the value in register P3.  If is is NULL then Halt using
        63552  +** Check the value in register P3.  If it is NULL then Halt using
 63502  63553   ** parameter P1, P2, and P4 as if this were a Halt instruction.  If the
 63503  63554   ** value in register P3 is not NULL, then this routine is a no-op.
 63504  63555   */
 63505  63556   case OP_HaltIfNull: {      /* in3 */
 63506  63557     pIn3 = &aMem[pOp->p3];
 63507  63558     if( (pIn3->flags & MEM_Null)==0 ) break;
 63508  63559     /* Fall through into OP_Halt */
................................................................................
 64431  64482   ** This works just like the Lt opcode except that the jump is taken if
 64432  64483   ** the operands in registers P1 and P3 are not equal.  See the Lt opcode for
 64433  64484   ** additional information.
 64434  64485   **
 64435  64486   ** If SQLITE_NULLEQ is set in P5 then the result of comparison is always either
 64436  64487   ** true or false and is never NULL.  If both operands are NULL then the result
 64437  64488   ** of comparison is false.  If either operand is NULL then the result is true.
 64438         -** If neither operand is NULL the the result is the same as it would be if
        64489  +** If neither operand is NULL the result is the same as it would be if
 64439  64490   ** the SQLITE_NULLEQ flag were omitted from P5.
 64440  64491   */
 64441  64492   /* Opcode: Eq P1 P2 P3 P4 P5
 64442  64493   **
 64443  64494   ** This works just like the Lt opcode except that the jump is taken if
 64444  64495   ** the operands in registers P1 and P3 are equal.
 64445  64496   ** See the Lt opcode for additional information.
 64446  64497   **
 64447  64498   ** If SQLITE_NULLEQ is set in P5 then the result of comparison is always either
 64448  64499   ** true or false and is never NULL.  If both operands are NULL then the result
 64449  64500   ** of comparison is true.  If either operand is NULL then the result is false.
 64450         -** If neither operand is NULL the the result is the same as it would be if
        64501  +** If neither operand is NULL the result is the same as it would be if
 64451  64502   ** the SQLITE_NULLEQ flag were omitted from P5.
 64452  64503   */
 64453  64504   /* Opcode: Le P1 P2 P3 P4 P5
 64454  64505   **
 64455  64506   ** This works just like the Lt opcode except that the jump is taken if
 64456  64507   ** the content of register P3 is less than or equal to the content of
 64457  64508   ** register P1.  See the Lt opcode for additional information.
................................................................................
 64728  64779       sqlite3VdbeMemSetInt64(pOut, ~sqlite3VdbeIntValue(pIn1));
 64729  64780     }
 64730  64781     break;
 64731  64782   }
 64732  64783   
 64733  64784   /* Opcode: If P1 P2 P3 * *
 64734  64785   **
 64735         -** Jump to P2 if the value in register P1 is true.  The value is
        64786  +** Jump to P2 if the value in register P1 is true.  The value
 64736  64787   ** is considered true if it is numeric and non-zero.  If the value
 64737  64788   ** in P1 is NULL then take the jump if P3 is true.
 64738  64789   */
 64739  64790   /* Opcode: IfNot P1 P2 P3 * *
 64740  64791   **
 64741         -** Jump to P2 if the value in register P1 is False.  The value is
        64792  +** Jump to P2 if the value in register P1 is False.  The value
 64742  64793   ** is considered true if it has a numeric value of zero.  If the value
 64743  64794   ** in P1 is NULL then take the jump if P3 is true.
 64744  64795   */
 64745  64796   case OP_If:                 /* jump, in1 */
 64746  64797   case OP_IfNot: {            /* jump, in1 */
 64747  64798   #if 0  /* local variables moved into u.al */
 64748  64799     int c;
................................................................................
 66388  66439       }
 66389  66440     }
 66390  66441     break;
 66391  66442   }
 66392  66443   
 66393  66444   /* Opcode: NotExists P1 P2 P3 * *
 66394  66445   **
 66395         -** Use the content of register P3 as a integer key.  If a record 
        66446  +** Use the content of register P3 as an integer key.  If a record 
 66396  66447   ** with that key does not exist in table of P1, then jump to P2. 
 66397  66448   ** If the record does exist, then fall through.  The cursor is left 
 66398  66449   ** pointing to the record if it exists.
 66399  66450   **
 66400  66451   ** The difference between this operation and NotFound is that this
 66401  66452   ** operation assumes the key is an integer and that P1 is a table whereas
 66402  66453   ** NotFound assumes key is a blob constructed from MakeRecord and
................................................................................
 66466  66517   ** The record number is not previously used as a key in the database
 66467  66518   ** table that cursor P1 points to.  The new record number is written
 66468  66519   ** written to register P2.
 66469  66520   **
 66470  66521   ** If P3>0 then P3 is a register in the root frame of this VDBE that holds 
 66471  66522   ** the largest previously generated record number. No new record numbers are
 66472  66523   ** allowed to be less than this value. When this value reaches its maximum, 
 66473         -** a SQLITE_FULL error is generated. The P3 register is updated with the '
        66524  +** an SQLITE_FULL error is generated. The P3 register is updated with the '
 66474  66525   ** generated record number. This P3 mechanism is used to help implement the
 66475  66526   ** AUTOINCREMENT feature.
 66476  66527   */
 66477  66528   case OP_NewRowid: {           /* out2-prerelease */
 66478  66529   #if 0  /* local variables moved into u.be */
 66479  66530     i64 v;                 /* The new rowid */
 66480  66531     VdbeCursor *pC;        /* Cursor of table to get the new rowid */
................................................................................
 67108  67159     }
 67109  67160     u.bm.pC->rowidIsValid = 0;
 67110  67161     break;
 67111  67162   }
 67112  67163   
 67113  67164   /* Opcode: IdxInsert P1 P2 P3 * P5
 67114  67165   **
 67115         -** Register P2 holds a SQL index key made using the
        67166  +** Register P2 holds an SQL index key made using the
 67116  67167   ** MakeRecord instructions.  This opcode writes that key
 67117  67168   ** into the index P1.  Data for the entry is nil.
 67118  67169   **
 67119  67170   ** P3 is a flag that provides a hint to the b-tree layer that this
 67120  67171   ** insert is likely to be an append.
 67121  67172   **
 67122  67173   ** This instruction only works for indices.  The equivalent instruction
................................................................................
 82133  82184         sqlite3VdbeAddOp2(v, OP_SCopy, regBase+nCol, regBase+j);
 82134  82185       }else{
 82135  82186         sqlite3VdbeAddOp3(v, OP_Column, iCur, idx, regBase+j);
 82136  82187         sqlite3ColumnDefault(v, pTab, idx, -1);
 82137  82188       }
 82138  82189     }
 82139  82190     if( doMakeRec ){
        82191  +    const char *zAff;
        82192  +    if( pTab->pSelect || (pParse->db->flags & SQLITE_IdxRealAsInt)!=0 ){
        82193  +      zAff = 0;
        82194  +    }else{
        82195  +      zAff = sqlite3IndexAffinityStr(v, pIdx);
        82196  +    }
 82140  82197       sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol+1, regOut);
 82141         -    sqlite3VdbeChangeP4(v, -1, sqlite3IndexAffinityStr(v, pIdx), P4_TRANSIENT);
        82198  +    sqlite3VdbeChangeP4(v, -1, zAff, P4_TRANSIENT);
 82142  82199     }
 82143  82200     sqlite3ReleaseTempRange(pParse, regBase, nCol+1);
 82144  82201     return regBase;
 82145  82202   }
 82146  82203   
 82147  82204   /************** End of delete.c **********************************************/
 82148  82205   /************** Begin file func.c ********************************************/
................................................................................
110761 110818         ppNew = va_arg(ap, void**);
110762 110819         pFree = va_arg(ap, void*);
110763 110820         if( sz ) *ppNew = sqlite3ScratchMalloc(sz);
110764 110821         sqlite3ScratchFree(pFree);
110765 110822         break;
110766 110823       }
110767 110824   
       110825  +    /*   sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, int onoff);
       110826  +    **
       110827  +    ** If parameter onoff is non-zero, configure the wrappers so that all
       110828  +    ** subsequent calls to localtime() and variants fail. If onoff is zero,
       110829  +    ** undo this setting.
       110830  +    */
       110831  +    case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
       110832  +      sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int);
       110833  +      break;
       110834  +    }
       110835  +
110768 110836     }
110769 110837     va_end(ap);
110770 110838   #endif /* SQLITE_OMIT_BUILTIN_TEST */
110771 110839     return rc;
110772 110840   }
110773 110841   
110774 110842   /*
................................................................................
111418 111486   ** older data.
111419 111487   **
111420 111488   ** TODO(shess) Provide a VACUUM type operation to clear out all
111421 111489   ** deletions and duplications.  This would basically be a forced merge
111422 111490   ** into a single segment.
111423 111491   */
111424 111492   
111425         -#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
111426         -
111427         -#if defined(SQLITE_ENABLE_FTS3) && !defined(SQLITE_CORE)
111428         -# define SQLITE_CORE 1
111429         -#endif
111430         -
111431 111493   /************** Include fts3Int.h in the middle of fts3.c ********************/
111432 111494   /************** Begin file fts3Int.h *****************************************/
111433 111495   /*
111434 111496   ** 2009 Nov 12
111435 111497   **
111436 111498   ** The author disclaims copyright to this source code.  In place of
111437 111499   ** a legal notice, here is a blessing:
................................................................................
111439 111501   **    May you do good and not evil.
111440 111502   **    May you find forgiveness for yourself and forgive others.
111441 111503   **    May you share freely, never taking more than you give.
111442 111504   **
111443 111505   ******************************************************************************
111444 111506   **
111445 111507   */
111446         -
111447 111508   #ifndef _FTSINT_H
111448 111509   #define _FTSINT_H
111449 111510   
111450 111511   #if !defined(NDEBUG) && !defined(SQLITE_DEBUG) 
111451 111512   # define NDEBUG 1
111452 111513   #endif
111453 111514   
       111515  +/*
       111516  +** FTS4 is really an extension for FTS3.  It is enabled using the
       111517  +** SQLITE_ENABLE_FTS3 macro.  But to avoid confusion we also all
       111518  +** the SQLITE_ENABLE_FTS4 macro to serve as an alisse for SQLITE_ENABLE_FTS3.
       111519  +*/
       111520  +#if defined(SQLITE_ENABLE_FTS4) && !defined(SQLITE_ENABLE_FTS3)
       111521  +# define SQLITE_ENABLE_FTS3
       111522  +#endif
       111523  +
       111524  +#ifdef SQLITE_ENABLE_FTS3
111454 111525   /************** Include fts3_tokenizer.h in the middle of fts3Int.h **********/
111455 111526   /************** Begin file fts3_tokenizer.h **********************************/
111456 111527   /*
111457 111528   ** 2006 July 10
111458 111529   **
111459 111530   ** The author disclaims copyright to this source code.
111460 111531   **
................................................................................
111938 112009     sqlite3_int64 iPrevId;          /* Previous id read from aDoclist */
111939 112010     char *pNextId;                  /* Pointer into the body of aDoclist */
111940 112011     char *aDoclist;                 /* List of docids for full-text queries */
111941 112012     int nDoclist;                   /* Size of buffer at aDoclist */
111942 112013     u8 bDesc;                       /* True to sort in descending order */
111943 112014     int eEvalmode;                  /* An FTS3_EVAL_XX constant */
111944 112015     int nRowAvg;                    /* Average size of database rows, in pages */
111945         -  int nDoc;                       /* Documents in table */
       112016  +  sqlite3_int64 nDoc;             /* Documents in table */
111946 112017   
111947 112018     int isMatchinfoNeeded;          /* True when aMatchinfo[] needs filling in */
111948 112019     u32 *aMatchinfo;                /* Information about most recent match */
111949 112020     int nMatchinfo;                 /* Number of elements in aMatchinfo[] */
111950 112021     char *zMatchinfo;               /* Matchinfo specification */
111951 112022   };
111952 112023   
................................................................................
111995 112066     char *z;                        /* Text of the token */
111996 112067     int n;                          /* Number of bytes in buffer z */
111997 112068     int isPrefix;                   /* True if token ends with a "*" character */
111998 112069   
111999 112070     /* Variables above this point are populated when the expression is
112000 112071     ** parsed (by code in fts3_expr.c). Below this point the variables are
112001 112072     ** used when evaluating the expression. */
112002         -  int bFulltext;                  /* True if full-text index was used */
112003 112073     Fts3DeferredToken *pDeferred;   /* Deferred token object for this token */
112004 112074     Fts3MultiSegReader *pSegcsr;    /* Segment-reader for this token */
112005 112075   };
112006 112076   
112007 112077   struct Fts3Phrase {
112008 112078     /* Cache of doclist for this phrase. */
112009 112079     Fts3Doclist doclist;
112010 112080     int bIncr;                 /* True if doclist is loaded incrementally */
       112081  +  int iDoclistToken;
112011 112082   
112012 112083     /* Variables below this point are populated by fts3_expr.c when parsing 
112013 112084     ** a MATCH expression. Everything above is part of the evaluation phase. 
112014 112085     */
112015 112086     int nToken;                /* Number of tokens in the phrase */
112016 112087     int iColumn;               /* Index of column this phrase must match */
112017 112088     Fts3PhraseToken aToken[1]; /* One entry for each token in the phrase */
................................................................................
112128 112199     int nSegment;                   /* Size of apSegment array */
112129 112200     int nAdvance;                   /* How many seg-readers to advance */
112130 112201     Fts3SegFilter *pFilter;         /* Pointer to filter object */
112131 112202     char *aBuffer;                  /* Buffer to merge doclists in */
112132 112203     int nBuffer;                    /* Allocated size of aBuffer[] in bytes */
112133 112204   
112134 112205     int iColFilter;                 /* If >=0, filter for this column */
       112206  +  int bRestart;
112135 112207   
112136 112208     /* Used by fts3.c only. */
112137 112209     int nCost;                      /* Cost of running iterator */
112138 112210     int bLookup;                    /* True if a lookup of a single entry. */
112139 112211   
112140 112212     /* Output values. Valid only after Fts3SegReaderStep() returns SQLITE_ROW. */
112141 112213     char *zTerm;                    /* Pointer to term buffer */
................................................................................
112197 112269   
112198 112270   SQLITE_PRIVATE int sqlite3Fts3MsrIncrStart(
112199 112271       Fts3Table*, Fts3MultiSegReader*, int, const char*, int);
112200 112272   SQLITE_PRIVATE int sqlite3Fts3MsrIncrNext(
112201 112273       Fts3Table *, Fts3MultiSegReader *, sqlite3_int64 *, char **, int *);
112202 112274   SQLITE_PRIVATE char *sqlite3Fts3EvalPhrasePoslist(Fts3Cursor *, Fts3Expr *, int iCol); 
112203 112275   SQLITE_PRIVATE int sqlite3Fts3MsrOvfl(Fts3Cursor *, Fts3MultiSegReader *, int *);
       112276  +SQLITE_PRIVATE int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr);
112204 112277   
112205 112278   SQLITE_PRIVATE int sqlite3Fts3DeferredTokenList(Fts3DeferredToken *, char **, int *);
112206 112279   
112207         -
       112280  +#endif /* SQLITE_ENABLE_FTS3 */
112208 112281   #endif /* _FTSINT_H */
112209 112282   
112210 112283   /************** End of fts3Int.h *********************************************/
112211 112284   /************** Continuing where we left off in fts3.c ***********************/
       112285  +#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
       112286  +
       112287  +#if defined(SQLITE_ENABLE_FTS3) && !defined(SQLITE_CORE)
       112288  +# define SQLITE_CORE 1
       112289  +#endif
112212 112290   
112213 112291   
112214 112292   #ifndef SQLITE_CORE 
112215 112293     SQLITE_EXTENSION_INIT1
112216 112294   #endif
112217 112295   
112218 112296   /* 
................................................................................
112543 112621         rc = SQLITE_NOMEM;
112544 112622       }else{
112545 112623         rc = sqlite3_prepare(p->db, zSql, -1, &pStmt, 0);
112546 112624         if( rc==SQLITE_OK ){
112547 112625           sqlite3_step(pStmt);
112548 112626           p->nPgsz = sqlite3_column_int(pStmt, 0);
112549 112627           rc = sqlite3_finalize(pStmt);
       112628  +      }else if( rc==SQLITE_AUTH ){
       112629  +        p->nPgsz = 1024;
       112630  +        rc = SQLITE_OK;
112550 112631         }
112551 112632       }
112552 112633       assert( p->nPgsz>0 || rc!=SQLITE_OK );
112553 112634       sqlite3_free(zSql);
112554 112635       *pRc = rc;
112555 112636     }
112556 112637   }
................................................................................
112993 113074     p->zDb = zCsr;
112994 113075     memcpy(zCsr, argv[1], nDb);
112995 113076     zCsr += nDb;
112996 113077   
112997 113078     /* Fill in the azColumn array */
112998 113079     for(iCol=0; iCol<nCol; iCol++){
112999 113080       char *z; 
113000         -    int n;
       113081  +    int n = 0;
113001 113082       z = (char *)sqlite3Fts3NextToken(aCol[iCol], &n);
113002 113083       memcpy(zCsr, z, n);
113003 113084       zCsr[n] = '\0';
113004 113085       sqlite3Fts3Dequote(zCsr);
113005 113086       p->azColumn[iCol] = zCsr;
113006 113087       zCsr += n+1;
113007 113088       assert( zCsr <= &((char *)p)[nByte] );
................................................................................
114579 114660     return rc;
114580 114661   }
114581 114662   
114582 114663   /*
114583 114664   ** Implementation of xBegin() method. This is a no-op.
114584 114665   */
114585 114666   static int fts3BeginMethod(sqlite3_vtab *pVtab){
114586         -  UNUSED_PARAMETER(pVtab);
114587 114667     TESTONLY( Fts3Table *p = (Fts3Table*)pVtab );
       114668  +  UNUSED_PARAMETER(pVtab);
114588 114669     assert( p->pSegments==0 );
114589 114670     assert( p->nPendingData==0 );
114590 114671     assert( p->inTransaction!=1 );
114591 114672     TESTONLY( p->inTransaction = 1 );
114592 114673     TESTONLY( p->mxSavepoint = -1; );
114593 114674     return SQLITE_OK;
114594 114675   }
................................................................................
114595 114676   
114596 114677   /*
114597 114678   ** Implementation of xCommit() method. This is a no-op. The contents of
114598 114679   ** the pending-terms hash-table have already been flushed into the database
114599 114680   ** by fts3SyncMethod().
114600 114681   */
114601 114682   static int fts3CommitMethod(sqlite3_vtab *pVtab){
114602         -  UNUSED_PARAMETER(pVtab);
114603 114683     TESTONLY( Fts3Table *p = (Fts3Table*)pVtab );
       114684  +  UNUSED_PARAMETER(pVtab);
114604 114685     assert( p->nPendingData==0 );
114605 114686     assert( p->inTransaction!=0 );
114606 114687     assert( p->pSegments==0 );
114607 114688     TESTONLY( p->inTransaction = 0 );
114608 114689     TESTONLY( p->mxSavepoint = -1; );
114609 114690     return SQLITE_OK;
114610 114691   }
................................................................................
115081 115162               pToken->z, pToken->n, pToken->isPrefix, &pToken->pSegcsr
115082 115163           );
115083 115164           if( rc!=SQLITE_OK ){
115084 115165             *pRc = rc;
115085 115166             return;
115086 115167           }
115087 115168         }
       115169  +      assert( pExpr->pPhrase->iDoclistToken==0 );
       115170  +      pExpr->pPhrase->iDoclistToken = -1;
115088 115171       }else{
115089 115172         *pnOr += (pExpr->eType==FTSQUERY_OR);
115090 115173         fts3EvalAllocateReaders(pCsr, pExpr->pLeft, pnToken, pnOr, pRc);
115091 115174         fts3EvalAllocateReaders(pCsr, pExpr->pRight, pnToken, pnOr, pRc);
115092 115175       }
115093 115176     }
115094 115177   }
       115178  +
       115179  +static void fts3EvalPhraseMergeToken(
       115180  +  Fts3Table *pTab,
       115181  +  Fts3Phrase *p,
       115182  +  int iToken,
       115183  +  char *pList,
       115184  +  int nList
       115185  +){
       115186  +  assert( iToken!=p->iDoclistToken );
       115187  +
       115188  +  if( pList==0 ){
       115189  +    sqlite3_free(p->doclist.aAll);
       115190  +    p->doclist.aAll = 0;
       115191  +    p->doclist.nAll = 0;
       115192  +  }
       115193  +
       115194  +  else if( p->iDoclistToken<0 ){
       115195  +    p->doclist.aAll = pList;
       115196  +    p->doclist.nAll = nList;
       115197  +  }
       115198  +
       115199  +  else if( p->doclist.aAll==0 ){
       115200  +    sqlite3_free(pList);
       115201  +  }
       115202  +
       115203  +  else {
       115204  +    char *pLeft;
       115205  +    char *pRight;
       115206  +    int nLeft;
       115207  +    int nRight;
       115208  +    int nDiff;
       115209  +
       115210  +    if( p->iDoclistToken<iToken ){
       115211  +      pLeft = p->doclist.aAll;
       115212  +      nLeft = p->doclist.nAll;
       115213  +      pRight = pList;
       115214  +      nRight = nList;
       115215  +      nDiff = iToken - p->iDoclistToken;
       115216  +    }else{
       115217  +      pRight = p->doclist.aAll;
       115218  +      nRight = p->doclist.nAll;
       115219  +      pLeft = pList;
       115220  +      nLeft = nList;
       115221  +      nDiff = p->iDoclistToken - iToken;
       115222  +    }
       115223  +
       115224  +    fts3DoclistPhraseMerge(pTab->bDescIdx, nDiff, pLeft, nLeft, pRight,&nRight);
       115225  +    sqlite3_free(pLeft);
       115226  +    p->doclist.aAll = pRight;
       115227  +    p->doclist.nAll = nRight;
       115228  +  }
       115229  +
       115230  +  if( iToken>p->iDoclistToken ) p->iDoclistToken = iToken;
       115231  +}
115095 115232   
115096 115233   static int fts3EvalPhraseLoad(
115097 115234     Fts3Cursor *pCsr, 
115098 115235     Fts3Phrase *p
115099 115236   ){
115100 115237     Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab;
115101 115238     int iToken;
115102 115239     int rc = SQLITE_OK;
115103 115240   
115104         -  char *aDoclist = 0;
115105         -  int nDoclist = 0;
115106         -  int iPrev = -1;
115107         -
115108 115241     for(iToken=0; rc==SQLITE_OK && iToken<p->nToken; iToken++){
115109 115242       Fts3PhraseToken *pToken = &p->aToken[iToken];
115110         -    assert( pToken->pSegcsr || pToken->pDeferred );
       115243  +    assert( pToken->pDeferred==0 || pToken->pSegcsr==0 );
115111 115244   
115112         -    if( pToken->pDeferred==0 ){
       115245  +    if( pToken->pSegcsr ){
115113 115246         int nThis = 0;
115114 115247         char *pThis = 0;
115115 115248         rc = fts3TermSelect(pTab, pToken, p->iColumn, 1, &nThis, &pThis);
115116 115249         if( rc==SQLITE_OK ){
115117         -        if( pThis==0 ){
115118         -          sqlite3_free(aDoclist);
115119         -          aDoclist = 0;
115120         -          nDoclist = 0;
115121         -          break;
115122         -        }else if( aDoclist==0 ){
115123         -          aDoclist = pThis;
115124         -          nDoclist = nThis;
115125         -        }else{
115126         -          assert( iPrev>=0 );
115127         -          fts3DoclistPhraseMerge(pTab->bDescIdx,
115128         -              iToken-iPrev, aDoclist, nDoclist, pThis, &nThis
115129         -          );
115130         -          sqlite3_free(aDoclist);
115131         -          aDoclist = pThis;
115132         -          nDoclist = nThis;
115133         -        }
115134         -        iPrev = iToken;
       115250  +        fts3EvalPhraseMergeToken(pTab, p, iToken, pThis, nThis);
115135 115251         }
115136 115252       }
       115253  +    assert( pToken->pSegcsr==0 );
115137 115254     }
115138 115255   
115139         -  if( rc==SQLITE_OK ){
115140         -    p->doclist.aAll = aDoclist;
115141         -    p->doclist.nAll = nDoclist;
115142         -  }else{
115143         -    sqlite3_free(aDoclist);
115144         -  }
115145 115256     return rc;
115146 115257   }
115147 115258   
115148 115259   static int fts3EvalDeferredPhrase(Fts3Cursor *pCsr, Fts3Phrase *pPhrase){
115149 115260     int iToken;
115150 115261     int rc = SQLITE_OK;
115151 115262   
115152         -  int nMaxUndeferred = -1;
       115263  +  int nMaxUndeferred = pPhrase->iDoclistToken;
115153 115264     char *aPoslist = 0;
115154 115265     int nPoslist = 0;
115155 115266     int iPrev = -1;
115156 115267   
115157 115268     assert( pPhrase->doclist.bFreeList==0 );
115158 115269   
115159 115270     for(iToken=0; rc==SQLITE_OK && iToken<pPhrase->nToken; iToken++){
................................................................................
115190 115301             sqlite3_free(aPoslist);
115191 115302             pPhrase->doclist.pList = 0;
115192 115303             pPhrase->doclist.nList = 0;
115193 115304             return SQLITE_OK;
115194 115305           }
115195 115306         }
115196 115307         iPrev = iToken;
115197         -    }else{
115198         -      nMaxUndeferred = iToken;
115199 115308       }
115200 115309     }
115201 115310   
115202 115311     if( iPrev>=0 ){
115203 115312       if( nMaxUndeferred<0 ){
115204 115313         pPhrase->doclist.pList = aPoslist;
115205 115314         pPhrase->doclist.nList = nPoslist;
................................................................................
115250 115359   ** used with fts3EvalPhraseNext() to iterate through the matching docids.
115251 115360   */
115252 115361   static int fts3EvalPhraseStart(Fts3Cursor *pCsr, int bOptOk, Fts3Phrase *p){
115253 115362     int rc;
115254 115363     Fts3PhraseToken *pFirst = &p->aToken[0];
115255 115364     Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab;
115256 115365   
115257         -  assert( p->doclist.aAll==0 );
115258         -  if( pCsr->bDesc==pTab->bDescIdx && bOptOk==1 && p->nToken==1 
115259         -   && pFirst->pSegcsr && pFirst->pSegcsr->bLookup 
       115366  +  if( pCsr->bDesc==pTab->bDescIdx 
       115367  +   && bOptOk==1 
       115368  +   && p->nToken==1 
       115369  +   && pFirst->pSegcsr 
       115370  +   && pFirst->pSegcsr->bLookup 
115260 115371     ){
115261 115372       /* Use the incremental approach. */
115262 115373       int iCol = (p->iColumn >= pTab->nColumn ? -1 : p->iColumn);
115263 115374       rc = sqlite3Fts3MsrIncrStart(
115264 115375           pTab, pFirst->pSegcsr, iCol, pFirst->z, pFirst->n);
115265 115376       p->bIncr = 1;
115266 115377   
................................................................................
115392 115503         ** edited in place by fts3EvalNearTrim2(), then pIter may not actually
115393 115504         ** point to the start of the next docid value. The following line deals
115394 115505         ** with this case by advancing pIter past the zero-padding added by
115395 115506         ** fts3EvalNearTrim2().  */
115396 115507         while( pIter<pEnd && *pIter==0 ) pIter++;
115397 115508   
115398 115509         pDL->pNextDocid = pIter;
115399         -      assert( *pIter || pIter>=&pDL->aAll[pDL->nAll] );
       115510  +      assert( pIter>=&pDL->aAll[pDL->nAll] || *pIter );
115400 115511         *pbEof = 0;
115401 115512       }
115402 115513     }
115403 115514   
115404 115515     return rc;
115405 115516   }
115406 115517   
................................................................................
115423 115534         fts3EvalStartReaders(pCsr, pExpr->pLeft, bOptOk, pRc);
115424 115535         fts3EvalStartReaders(pCsr, pExpr->pRight, bOptOk, pRc);
115425 115536         pExpr->bDeferred = (pExpr->pLeft->bDeferred && pExpr->pRight->bDeferred);
115426 115537       }
115427 115538     }
115428 115539   }
115429 115540   
115430         -
115431 115541   typedef struct Fts3TokenAndCost Fts3TokenAndCost;
115432 115542   struct Fts3TokenAndCost {
115433         -  Fts3PhraseToken *pToken;
115434         -  Fts3Expr *pRoot;
       115543  +  Fts3Phrase *pPhrase;            /* The phrase the token belongs to */
       115544  +  int iToken;                     /* Position of token in phrase */
       115545  +  Fts3PhraseToken *pToken;        /* The token itself */
       115546  +  Fts3Expr *pRoot; 
115435 115547     int nOvfl;
115436         -  int iCol;
       115548  +  int iCol;                       /* The column the token must match */
115437 115549   };
115438 115550   
115439 115551   static void fts3EvalTokenCosts(
115440 115552     Fts3Cursor *pCsr, 
115441 115553     Fts3Expr *pRoot, 
115442 115554     Fts3Expr *pExpr, 
115443 115555     Fts3TokenAndCost **ppTC,
................................................................................
115446 115558   ){
115447 115559     if( *pRc==SQLITE_OK && pExpr ){
115448 115560       if( pExpr->eType==FTSQUERY_PHRASE ){
115449 115561         Fts3Phrase *pPhrase = pExpr->pPhrase;
115450 115562         int i;
115451 115563         for(i=0; *pRc==SQLITE_OK && i<pPhrase->nToken; i++){
115452 115564           Fts3TokenAndCost *pTC = (*ppTC)++;
       115565  +        pTC->pPhrase = pPhrase;
       115566  +        pTC->iToken = i;
115453 115567           pTC->pRoot = pRoot;
115454 115568           pTC->pToken = &pPhrase->aToken[i];
115455 115569           pTC->iCol = pPhrase->iColumn;
115456 115570           *pRc = sqlite3Fts3MsrOvfl(pCsr, pTC->pToken->pSegcsr, &pTC->nOvfl);
115457 115571         }
115458 115572       }else if( pExpr->eType!=FTSQUERY_NOT ){
115459 115573         if( pExpr->eType==FTSQUERY_OR ){
................................................................................
115558 115672       assert( pTC );
115559 115673   
115560 115674       /* At this point pTC points to the cheapest remaining token. */
115561 115675       if( ii==0 ){
115562 115676         if( pTC->nOvfl ){
115563 115677           nDocEst = (pTC->nOvfl * pTab->nPgsz + pTab->nPgsz) / 10;
115564 115678         }else{
115565         -        /* TODO: Fix this so that the doclist need not be read twice. */
115566 115679           Fts3PhraseToken *pToken = pTC->pToken;
115567 115680           int nList = 0;
115568 115681           char *pList = 0;
115569 115682           rc = fts3TermSelect(pTab, pToken, pTC->iCol, 1, &nList, &pList);
       115683  +        assert( rc==SQLITE_OK || pList==0 );
       115684  +
115570 115685           if( rc==SQLITE_OK ){
115571 115686             nDocEst = fts3DoclistCountDocids(1, pList, nList);
115572         -        }
115573         -        sqlite3_free(pList);
115574         -        if( rc==SQLITE_OK ){
115575         -          rc = sqlite3Fts3TermSegReaderCursor(pCsr, 
115576         -              pToken->z, pToken->n, pToken->isPrefix, &pToken->pSegcsr
115577         -          );
       115687  +          fts3EvalPhraseMergeToken(pTab, pTC->pPhrase, pTC->iToken,pList,nList);
115578 115688           }
115579 115689         }
115580 115690       }else{
115581 115691         if( pTC->nOvfl>=(nDocEst*nDocSize) ){
115582 115692           Fts3PhraseToken *pToken = pTC->pToken;
115583 115693           rc = sqlite3Fts3DeferToken(pCsr, pToken, pTC->iCol);
115584 115694           fts3SegReaderCursorFree(pToken->pSegcsr);
................................................................................
116030 116140   ){
116031 116141     if( pExpr && *pRc==SQLITE_OK ){
116032 116142       Fts3Phrase *pPhrase = pExpr->pPhrase;
116033 116143   
116034 116144       if( pPhrase ){
116035 116145         fts3EvalZeroPoslist(pPhrase);
116036 116146         if( pPhrase->bIncr ){
116037         -        sqlite3Fts3EvalPhraseCleanup(pPhrase);
116038         -        memset(&pPhrase->doclist, 0, sizeof(Fts3Doclist));
116039         -        *pRc = sqlite3Fts3EvalStart(pCsr, pExpr, 0);
116040         -      }else{
116041         -        pPhrase->doclist.pNextDocid = 0;
116042         -        pPhrase->doclist.iDocid = 0;
       116147  +        assert( pPhrase->nToken==1 );
       116148  +        assert( pPhrase->aToken[0].pSegcsr );
       116149  +        sqlite3Fts3MsrIncrRestart(pPhrase->aToken[0].pSegcsr);
       116150  +        *pRc = fts3EvalPhraseStart(pCsr, 0, pPhrase);
116043 116151         }
       116152  +
       116153  +      pPhrase->doclist.pNextDocid = 0;
       116154  +      pPhrase->doclist.iDocid = 0;
116044 116155       }
116045 116156   
116046 116157       pExpr->iDocid = 0;
116047 116158       pExpr->bEof = 0;
116048 116159       pExpr->bStart = 0;
116049 116160   
116050 116161       fts3EvalRestart(pCsr, pExpr->pLeft, pRc);
................................................................................
116223 116334     Fts3Table *pTab = (Fts3Table *)pCsr->base.pVtab;
116224 116335     int rc = SQLITE_OK;
116225 116336     int iCol;
116226 116337   
116227 116338     if( pExpr->bDeferred && pExpr->pParent->eType!=FTSQUERY_NEAR ){
116228 116339       assert( pCsr->nDoc>0 );
116229 116340       for(iCol=0; iCol<pTab->nColumn; iCol++){
116230         -      aiOut[iCol*3 + 1] = pCsr->nDoc;
116231         -      aiOut[iCol*3 + 2] = pCsr->nDoc;
       116341  +      aiOut[iCol*3 + 1] = (u32)pCsr->nDoc;
       116342  +      aiOut[iCol*3 + 2] = (u32)pCsr->nDoc;
116232 116343       }
116233 116344     }else{
116234 116345       rc = fts3EvalGatherStats(pCsr, pExpr);
116235 116346       if( rc==SQLITE_OK ){
116236 116347         assert( pExpr->aMI );
116237 116348         for(iCol=0; iCol<pTab->nColumn; iCol++){
116238 116349           aiOut[iCol*3 + 1] = pExpr->aMI[iCol*3 + 1];
................................................................................
116332 116443   **    May you do good and not evil.
116333 116444   **    May you find forgiveness for yourself and forgive others.
116334 116445   **    May you share freely, never taking more than you give.
116335 116446   **
116336 116447   ******************************************************************************
116337 116448   **
116338 116449   */
116339         -
116340 116450   #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
116341 116451   
116342 116452   
116343 116453   typedef struct Fts3auxTable Fts3auxTable;
116344 116454   typedef struct Fts3auxCursor Fts3auxCursor;
116345 116455   
116346 116456   struct Fts3auxTable {
................................................................................
118166 118276   **     * The FTS3 module is being built into the core of
118167 118277   **       SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
118168 118278   */
118169 118279   #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
118170 118280   
118171 118281   
118172 118282   
118173         -
118174 118283   /*
118175 118284   ** Class derived from sqlite3_tokenizer
118176 118285   */
118177 118286   typedef struct porter_tokenizer {
118178 118287     sqlite3_tokenizer base;      /* Base class */
118179 118288   } porter_tokenizer;
118180 118289   
................................................................................
118806 118915   **
118807 118916   **     * The FTS3 module is being built as an extension
118808 118917   **       (in which case SQLITE_CORE is not defined), or
118809 118918   **
118810 118919   **     * The FTS3 module is being built into the core of
118811 118920   **       SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
118812 118921   */
118813         -#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
118814         -
118815 118922   #ifndef SQLITE_CORE
118816 118923     SQLITE_EXTENSION_INIT1
118817 118924   #endif
       118925  +
       118926  +#if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
118818 118927   
118819 118928   
118820 118929   /*
118821 118930   ** Implementation of the SQL scalar function for accessing the underlying 
118822 118931   ** hash table. This function may be called as follows:
118823 118932   **
118824 118933   **   SELECT <function-name>(<key-name>);
................................................................................
118935 119044     Fts3Hash *pHash,                /* Tokenizer hash table */
118936 119045     const char *zArg,               /* Tokenizer name */
118937 119046     sqlite3_tokenizer **ppTok,      /* OUT: Tokenizer (if applicable) */
118938 119047     char **pzErr                    /* OUT: Set to malloced error message */
118939 119048   ){
118940 119049     int rc;
118941 119050     char *z = (char *)zArg;
118942         -  int n;
       119051  +  int n = 0;
118943 119052     char *zCopy;
118944 119053     char *zEnd;                     /* Pointer to nul-term of zCopy */
118945 119054     sqlite3_tokenizer_module *m;
118946 119055   
118947 119056     zCopy = sqlite3_mprintf("%s", zArg);
118948 119057     if( !zCopy ) return SQLITE_NOMEM;
118949 119058     zEnd = &zCopy[strlen(zCopy)];
................................................................................
119297 119406   **     * The FTS3 module is being built as an extension
119298 119407   **       (in which case SQLITE_CORE is not defined), or
119299 119408   **
119300 119409   **     * The FTS3 module is being built into the core of
119301 119410   **       SQLite (in which case SQLITE_ENABLE_FTS3 is defined).
119302 119411   */
119303 119412   #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
119304         -
119305 119413   
119306 119414   
119307 119415   
119308 119416   typedef struct simple_tokenizer {
119309 119417     sqlite3_tokenizer base;
119310 119418     char delim[128];             /* flag ASCII delimiters */
119311 119419   } simple_tokenizer;
................................................................................
120748 120856       );
120749 120857       if( bEof ){
120750 120858         pReader->pOffsetList = 0;
120751 120859       }else{
120752 120860         pReader->pOffsetList = p;
120753 120861       }
120754 120862     }else{
       120863  +    char *pEnd = &pReader->aDoclist[pReader->nDoclist];
120755 120864   
120756 120865       /* Pointer p currently points at the first byte of an offset list. The
120757 120866       ** following block advances it to point one byte past the end of
120758 120867       ** the same offset list. */
120759 120868       while( 1 ){
120760 120869     
120761 120870         /* The following line of code (and the "p++" below the while() loop) is
................................................................................
120776 120885       /* If required, populate the output variables with a pointer to and the
120777 120886       ** size of the previous offset-list.
120778 120887       */
120779 120888       if( ppOffsetList ){
120780 120889         *ppOffsetList = pReader->pOffsetList;
120781 120890         *pnOffsetList = (int)(p - pReader->pOffsetList - 1);
120782 120891       }
       120892  +
       120893  +    while( p<pEnd && *p==0 ) p++;
120783 120894     
120784 120895       /* If there are no more entries in the doclist, set pOffsetList to
120785 120896       ** NULL. Otherwise, set Fts3SegReader.iDocid to the next docid and
120786 120897       ** Fts3SegReader.pOffsetList to point to the next offset list before
120787 120898       ** returning.
120788 120899       */
120789         -    if( p>=&pReader->aDoclist[pReader->nDoclist] ){
       120900  +    if( p>=pEnd ){
120790 120901         pReader->pOffsetList = 0;
120791 120902       }else{
120792 120903         rc = fts3SegReaderRequire(pReader, p, FTS3_VARINT_MAX);
120793 120904         if( rc==SQLITE_OK ){
120794 120905           sqlite3_int64 iDelta;
120795 120906           pReader->pOffsetList = p + sqlite3Fts3GetVarint(p, &iDelta);
120796 120907           if( pTab->bDescIdx ){
................................................................................
120821 120932     assert( pgsz>0 );
120822 120933   
120823 120934     for(ii=0; rc==SQLITE_OK && ii<pMsr->nSegment; ii++){
120824 120935       Fts3SegReader *pReader = pMsr->apSegment[ii];
120825 120936       if( !fts3SegReaderIsPending(pReader) 
120826 120937        && !fts3SegReaderIsRootOnly(pReader) 
120827 120938       ){
120828         -      int jj;
       120939  +      sqlite3_int64 jj;
120829 120940         for(jj=pReader->iStartBlock; jj<=pReader->iLeafEndBlock; jj++){
120830 120941           int nBlob;
120831 120942           rc = sqlite3Fts3ReadBlock(p, jj, 0, &nBlob, 0);
120832 120943           if( rc!=SQLITE_OK ) break;
120833 120944           if( (nBlob+35)>pgsz ){
120834 120945             nOvfl += (nBlob + 34)/pgsz;
120835 120946           }
................................................................................
121766 121877       p += sqlite3Fts3GetVarint32(p, &iCurrent);
121767 121878     }
121768 121879   
121769 121880     *ppList = pList;
121770 121881     *pnList = nList;
121771 121882   }
121772 121883   
121773         -SQLITE_PRIVATE int sqlite3Fts3MsrIncrStart(
121774         -  Fts3Table *p,                   /* Virtual table handle */
121775         -  Fts3MultiSegReader *pCsr,       /* Cursor object */
121776         -  int iCol,                       /* Column to match on. */
121777         -  const char *zTerm,              /* Term to iterate through a doclist for */
121778         -  int nTerm                       /* Number of bytes in zTerm */
121779         -){
121780         -  int i;
121781         -  int nSegment = pCsr->nSegment;
121782         -  int (*xCmp)(Fts3SegReader *, Fts3SegReader *) = (
121783         -    p->bDescIdx ? fts3SegReaderDoclistCmpRev : fts3SegReaderDoclistCmp
121784         -  );
121785         -
121786         -  assert( pCsr->pFilter==0 );
121787         -  assert( zTerm && nTerm>0 );
121788         -
121789         -  /* Advance each segment iterator until it points to the term zTerm/nTerm. */
121790         -  for(i=0; i<nSegment; i++){
121791         -    Fts3SegReader *pSeg = pCsr->apSegment[i];
121792         -    do {
121793         -      int rc = fts3SegReaderNext(p, pSeg, 1);
121794         -      if( rc!=SQLITE_OK ) return rc;
121795         -    }while( fts3SegReaderTermCmp(pSeg, zTerm, nTerm)<0 );
121796         -  }
121797         -  fts3SegReaderSort(pCsr->apSegment, nSegment, nSegment, fts3SegReaderCmp);
121798         -
121799         -  /* Determine how many of the segments actually point to zTerm/nTerm. */
121800         -  for(i=0; i<nSegment; i++){
121801         -    Fts3SegReader *pSeg = pCsr->apSegment[i];
121802         -    if( !pSeg->aNode || fts3SegReaderTermCmp(pSeg, zTerm, nTerm) ){
121803         -      break;
121804         -    }
121805         -  }
121806         -  pCsr->nAdvance = i;
121807         -
121808         -  /* Advance each of the segments to point to the first docid. */
121809         -  for(i=0; i<pCsr->nAdvance; i++){
121810         -    int rc = fts3SegReaderFirstDocid(p, pCsr->apSegment[i]);
121811         -    if( rc!=SQLITE_OK ) return rc;
121812         -  }
121813         -  fts3SegReaderSort(pCsr->apSegment, i, i, xCmp);
121814         -
121815         -  assert( iCol<0 || iCol<p->nColumn );
121816         -  pCsr->iColFilter = iCol;
121817         -
       121884  +/*
       121885  +** Cache data in the Fts3MultiSegReader.aBuffer[] buffer (overwriting any
       121886  +** existing data). Grow the buffer if required.
       121887  +**
       121888  +** If successful, return SQLITE_OK. Otherwise, if an OOM error is encountered
       121889  +** trying to resize the buffer, return SQLITE_NOMEM.
       121890  +*/
       121891  +static int fts3MsrBufferData(
       121892  +  Fts3MultiSegReader *pMsr,       /* Multi-segment-reader handle */
       121893  +  char *pList,
       121894  +  int nList
       121895  +){
       121896  +  if( nList>pMsr->nBuffer ){
       121897  +    char *pNew;
       121898  +    pMsr->nBuffer = nList*2;
       121899  +    pNew = (char *)sqlite3_realloc(pMsr->aBuffer, pMsr->nBuffer);
       121900  +    if( !pNew ) return SQLITE_NOMEM;
       121901  +    pMsr->aBuffer = pNew;
       121902  +  }
       121903  +
       121904  +  memcpy(pMsr->aBuffer, pList, nList);
121818 121905     return SQLITE_OK;
121819 121906   }
121820 121907   
121821 121908   SQLITE_PRIVATE int sqlite3Fts3MsrIncrNext(
121822 121909     Fts3Table *p,                   /* Virtual table handle */
121823 121910     Fts3MultiSegReader *pMsr,       /* Multi-segment-reader handle */
121824 121911     sqlite3_int64 *piDocid,         /* OUT: Docid value */
................................................................................
121864 121951         fts3SegReaderSort(pMsr->apSegment, nMerge, j, xCmp);
121865 121952   
121866 121953         if( pMsr->iColFilter>=0 ){
121867 121954           fts3ColumnFilter(pMsr->iColFilter, &pList, &nList);
121868 121955         }
121869 121956   
121870 121957         if( nList>0 ){
       121958  +        if( fts3SegReaderIsPending(apSegment[0]) ){
       121959  +          rc = fts3MsrBufferData(pMsr, pList, nList+1);
       121960  +          if( rc!=SQLITE_OK ) return rc;
       121961  +          *paPoslist = pMsr->aBuffer;
       121962  +          assert( (pMsr->aBuffer[nList] & 0xFE)==0x00 );
       121963  +        }else{
       121964  +          *paPoslist = pList;
       121965  +        }
121871 121966           *piDocid = iDocid;
121872         -        *paPoslist = pList;
121873 121967           *pnPoslist = nList;
121874 121968           break;
121875 121969         }
121876 121970       }
121877         -    
121878 121971     }
121879 121972   
       121973  +  return SQLITE_OK;
       121974  +}
       121975  +
       121976  +static int fts3SegReaderStart(
       121977  +  Fts3Table *p,                   /* Virtual table handle */
       121978  +  Fts3MultiSegReader *pCsr,       /* Cursor object */
       121979  +  const char *zTerm,              /* Term searched for (or NULL) */
       121980  +  int nTerm                       /* Length of zTerm in bytes */
       121981  +){
       121982  +  int i;
       121983  +  int nSeg = pCsr->nSegment;
       121984  +
       121985  +  /* If the Fts3SegFilter defines a specific term (or term prefix) to search 
       121986  +  ** for, then advance each segment iterator until it points to a term of
       121987  +  ** equal or greater value than the specified term. This prevents many
       121988  +  ** unnecessary merge/sort operations for the case where single segment
       121989  +  ** b-tree leaf nodes contain more than one term.
       121990  +  */
       121991  +  for(i=0; pCsr->bRestart==0 && i<pCsr->nSegment; i++){
       121992  +    Fts3SegReader *pSeg = pCsr->apSegment[i];
       121993  +    do {
       121994  +      int rc = fts3SegReaderNext(p, pSeg, 0);
       121995  +      if( rc!=SQLITE_OK ) return rc;
       121996  +    }while( zTerm && fts3SegReaderTermCmp(pSeg, zTerm, nTerm)<0 );
       121997  +  }
       121998  +  fts3SegReaderSort(pCsr->apSegment, nSeg, nSeg, fts3SegReaderCmp);
       121999  +
121880 122000     return SQLITE_OK;
121881 122001   }
121882 122002   
121883 122003   SQLITE_PRIVATE int sqlite3Fts3SegReaderStart(
121884 122004     Fts3Table *p,                   /* Virtual table handle */
121885 122005     Fts3MultiSegReader *pCsr,       /* Cursor object */
121886 122006     Fts3SegFilter *pFilter          /* Restrictions on range of iteration */
121887 122007   ){
121888         -  int i;
121889         -
121890         -  /* Initialize the cursor object */
121891 122008     pCsr->pFilter = pFilter;
       122009  +  return fts3SegReaderStart(p, pCsr, pFilter->zTerm, pFilter->nTerm);
       122010  +}
121892 122011   
121893         -  /* If the Fts3SegFilter defines a specific term (or term prefix) to search 
121894         -  ** for, then advance each segment iterator until it points to a term of
121895         -  ** equal or greater value than the specified term. This prevents many
121896         -  ** unnecessary merge/sort operations for the case where single segment
121897         -  ** b-tree leaf nodes contain more than one term.
121898         -  */
121899         -  for(i=0; i<pCsr->nSegment; i++){
121900         -    int nTerm = pFilter->nTerm;
121901         -    const char *zTerm = pFilter->zTerm;
       122012  +SQLITE_PRIVATE int sqlite3Fts3MsrIncrStart(
       122013  +  Fts3Table *p,                   /* Virtual table handle */
       122014  +  Fts3MultiSegReader *pCsr,       /* Cursor object */
       122015  +  int iCol,                       /* Column to match on. */
       122016  +  const char *zTerm,              /* Term to iterate through a doclist for */
       122017  +  int nTerm                       /* Number of bytes in zTerm */
       122018  +){
       122019  +  int i;
       122020  +  int rc;
       122021  +  int nSegment = pCsr->nSegment;
       122022  +  int (*xCmp)(Fts3SegReader *, Fts3SegReader *) = (
       122023  +    p->bDescIdx ? fts3SegReaderDoclistCmpRev : fts3SegReaderDoclistCmp
       122024  +  );
       122025  +
       122026  +  assert( pCsr->pFilter==0 );
       122027  +  assert( zTerm && nTerm>0 );
       122028  +
       122029  +  /* Advance each segment iterator until it points to the term zTerm/nTerm. */
       122030  +  rc = fts3SegReaderStart(p, pCsr, zTerm, nTerm);
       122031  +  if( rc!=SQLITE_OK ) return rc;
       122032  +
       122033  +  /* Determine how many of the segments actually point to zTerm/nTerm. */
       122034  +  for(i=0; i<nSegment; i++){
121902 122035       Fts3SegReader *pSeg = pCsr->apSegment[i];
121903         -    do {
121904         -      int rc = fts3SegReaderNext(p, pSeg, 0);
121905         -      if( rc!=SQLITE_OK ) return rc;
121906         -    }while( zTerm && fts3SegReaderTermCmp(pSeg, zTerm, nTerm)<0 );
121907         -  }
121908         -  fts3SegReaderSort(
121909         -      pCsr->apSegment, pCsr->nSegment, pCsr->nSegment, fts3SegReaderCmp);
121910         -
121911         -  return SQLITE_OK;
121912         -}
       122036  +    if( !pSeg->aNode || fts3SegReaderTermCmp(pSeg, zTerm, nTerm) ){
       122037  +      break;
       122038  +    }
       122039  +  }
       122040  +  pCsr->nAdvance = i;
       122041  +
       122042  +  /* Advance each of the segments to point to the first docid. */
       122043  +  for(i=0; i<pCsr->nAdvance; i++){
       122044  +    rc = fts3SegReaderFirstDocid(p, pCsr->apSegment[i]);
       122045  +    if( rc!=SQLITE_OK ) return rc;
       122046  +  }
       122047  +  fts3SegReaderSort(pCsr->apSegment, i, i, xCmp);
       122048  +
       122049  +  assert( iCol<0 || iCol<p->nColumn );
       122050  +  pCsr->iColFilter = iCol;
       122051  +
       122052  +  return SQLITE_OK;
       122053  +}
       122054  +
       122055  +/*
       122056  +** This function is called on a MultiSegReader that has been started using
       122057  +** sqlite3Fts3MsrIncrStart(). One or more calls to MsrIncrNext() may also
       122058  +** have been made. Calling this function puts the MultiSegReader in such
       122059  +** a state that if the next two calls are:
       122060  +**
       122061  +**   sqlite3Fts3SegReaderStart()
       122062  +**   sqlite3Fts3SegReaderStep()
       122063  +**
       122064  +** then the entire doclist for the term is available in 
       122065  +** MultiSegReader.aDoclist/nDoclist.
       122066  +*/
       122067  +SQLITE_PRIVATE int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr){
       122068  +  int i;                          /* Used to iterate through segment-readers */
       122069  +
       122070  +  assert( pCsr->zTerm==0 );
       122071  +  assert( pCsr->nTerm==0 );
       122072  +  assert( pCsr->aDoclist==0 );
       122073  +  assert( pCsr->nDoclist==0 );
       122074  +
       122075  +  pCsr->nAdvance = 0;
       122076  +  pCsr->bRestart = 1;
       122077  +  for(i=0; i<pCsr->nSegment; i++){
       122078  +    pCsr->apSegment[i]->pOffsetList = 0;
       122079  +    pCsr->apSegment[i]->nOffsetList = 0;
       122080  +    pCsr->apSegment[i]->iDocid = 0;
       122081  +  }
       122082  +
       122083  +  return SQLITE_OK;
       122084  +}
       122085  +
121913 122086   
121914 122087   SQLITE_PRIVATE int sqlite3Fts3SegReaderStep(
121915 122088     Fts3Table *p,                   /* Virtual table handle */
121916 122089     Fts3MultiSegReader *pCsr        /* Cursor object */
121917 122090   ){
121918 122091     int rc = SQLITE_OK;
121919 122092   
................................................................................
121979 122152       }
121980 122153   
121981 122154       assert( isIgnoreEmpty || (isRequirePos && !isColFilter) );
121982 122155       if( nMerge==1 
121983 122156        && !isIgnoreEmpty 
121984 122157        && (p->bDescIdx==0 || fts3SegReaderIsPending(apSegment[0])==0)
121985 122158       ){
121986         -      pCsr->aDoclist = apSegment[0]->aDoclist;
121987 122159         pCsr->nDoclist = apSegment[0]->nDoclist;
121988         -      rc = SQLITE_ROW;
       122160  +      if( fts3SegReaderIsPending(apSegment[0]) ){
       122161  +        rc = fts3MsrBufferData(pCsr, apSegment[0]->aDoclist, pCsr->nDoclist);
       122162  +        pCsr->aDoclist = pCsr->aBuffer;
       122163  +      }else{
       122164  +        pCsr->aDoclist = apSegment[0]->aDoclist;
       122165  +      }
       122166  +      if( rc==SQLITE_OK ) rc = SQLITE_ROW;
121989 122167       }else{
121990 122168         int nDoclist = 0;           /* Size of doclist */
121991 122169         sqlite3_int64 iPrev = 0;    /* Previous docid stored in doclist */
121992 122170   
121993 122171         /* The current term of the first nMerge entries in the array
121994 122172         ** of Fts3SegReader objects is the same. The doclists must be merged
121995 122173         ** and a single term returned with the merged doclist.
................................................................................
123723 123901   
123724 123902         case FTS3_MATCHINFO_NCOL:
123725 123903           if( bGlobal ) pInfo->aMatchinfo[0] = pInfo->nCol;
123726 123904           break;
123727 123905           
123728 123906         case FTS3_MATCHINFO_NDOC:
123729 123907           if( bGlobal ){
123730         -          sqlite3_int64 nDoc;
       123908  +          sqlite3_int64 nDoc = 0;
123731 123909             rc = fts3MatchinfoSelectDoctotal(pTab, &pSelect, &nDoc, 0);
123732 123910             pInfo->aMatchinfo[0] = (u32)nDoc;
123733 123911           }
123734 123912           break;
123735 123913   
123736 123914         case FTS3_MATCHINFO_AVGLENGTH: 
123737 123915           if( bGlobal ){
................................................................................
125618 125796   /*
125619 125797   ** Return the N-dimensional volumn of the cell stored in *p.
125620 125798   */
125621 125799   static float cellArea(Rtree *pRtree, RtreeCell *p){
125622 125800     float area = 1.0;
125623 125801     int ii;
125624 125802     for(ii=0; ii<(pRtree->nDim*2); ii+=2){
125625         -    area = area * (DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii]));
       125803  +    area = (float)(area * (DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii])));
125626 125804     }
125627 125805     return area;
125628 125806   }
125629 125807   
125630 125808   /*
125631 125809   ** Return the margin length of cell p. The margin length is the sum
125632 125810   ** of the objects size in each dimension.
125633 125811   */
125634 125812   static float cellMargin(Rtree *pRtree, RtreeCell *p){
125635 125813     float margin = 0.0;
125636 125814     int ii;
125637 125815     for(ii=0; ii<(pRtree->nDim*2); ii+=2){
125638         -    margin += (DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii]));
       125816  +    margin += (float)(DCOORD(p->aCoord[ii+1]) - DCOORD(p->aCoord[ii]));
125639 125817     }
125640 125818     return margin;
125641 125819   }
125642 125820   
125643 125821   /*
125644 125822   ** Store the union of cells p1 and p2 in p1.
125645 125823   */
................................................................................
125716 125894           x1 = MAX(DCOORD(p->aCoord[jj]), DCOORD(aCell[ii].aCoord[jj]));
125717 125895           x2 = MIN(DCOORD(p->aCoord[jj+1]), DCOORD(aCell[ii].aCoord[jj+1]));
125718 125896   
125719 125897           if( x2<x1 ){
125720 125898             o = 0.0;
125721 125899             break;
125722 125900           }else{
125723         -          o = o * (x2-x1);
       125901  +          o = o * (float)(x2-x1);
125724 125902           }
125725 125903         }
125726 125904         overlap += o;
125727 125905       }
125728 125906     }
125729 125907     return overlap;
125730 125908   }
................................................................................
125735 125913     Rtree *pRtree, 
125736 125914     RtreeCell *p, 
125737 125915     RtreeCell *pInsert, 
125738 125916     RtreeCell *aCell, 
125739 125917     int nCell, 
125740 125918     int iExclude
125741 125919   ){
125742         -  float before;
125743         -  float after;
       125920  +  double before;
       125921  +  double after;
125744 125922     before = cellOverlap(pRtree, p, aCell, nCell, iExclude);
125745 125923     cellUnion(pRtree, p, pInsert);
125746 125924     after = cellOverlap(pRtree, p, aCell, nCell, iExclude);
125747         -  return after-before;
       125925  +  return (float)(after-before);
125748 125926   }
125749 125927   #endif
125750 125928   
125751 125929   
125752 125930   /*
125753 125931   ** This function implements the ChooseLeaf algorithm from Gutman[84].
125754 125932   ** ChooseSubTree in r*tree terminology.
................................................................................
125762 125940     int rc;
125763 125941     int ii;
125764 125942     RtreeNode *pNode;
125765 125943     rc = nodeAcquire(pRtree, 1, 0, &pNode);
125766 125944   
125767 125945     for(ii=0; rc==SQLITE_OK && ii<(pRtree->iDepth-iHeight); ii++){
125768 125946       int iCell;
125769         -    sqlite3_int64 iBest;
       125947  +    sqlite3_int64 iBest = 0;
125770 125948   
125771         -    float fMinGrowth;
125772         -    float fMinArea;
125773         -    float fMinOverlap;
       125949  +    float fMinGrowth = 0.0;
       125950  +    float fMinArea = 0.0;
       125951  +    float fMinOverlap = 0.0;
125774 125952   
125775 125953       int nCell = NCELL(pNode);
125776 125954       RtreeCell cell;
125777 125955       RtreeNode *pChild;
125778 125956   
125779 125957       RtreeCell *aCell = 0;
125780 125958   
................................................................................
126196 126374     RtreeCell *pBboxLeft,
126197 126375     RtreeCell *pBboxRight
126198 126376   ){
126199 126377     int **aaSorted;
126200 126378     int *aSpare;
126201 126379     int ii;
126202 126380   
126203         -  int iBestDim;
126204         -  int iBestSplit;
126205         -  float fBestMargin;
       126381  +  int iBestDim = 0;
       126382  +  int iBestSplit = 0;
       126383  +  float fBestMargin = 0.0;
126206 126384   
126207 126385     int nByte = (pRtree->nDim+1)*(sizeof(int*)+nCell*sizeof(int));
126208 126386   
126209 126387     aaSorted = (int **)sqlite3_malloc(nByte);
126210 126388     if( !aaSorted ){
126211 126389       return SQLITE_NOMEM;
126212 126390     }
................................................................................
126220 126398         aaSorted[ii][jj] = jj;
126221 126399       }
126222 126400       SortByDimension(pRtree, aaSorted[ii], nCell, ii, aCell, aSpare);
126223 126401     }
126224 126402   
126225 126403     for(ii=0; ii<pRtree->nDim; ii++){
126226 126404       float margin = 0.0;
126227         -    float fBestOverlap;
126228         -    float fBestArea;
126229         -    int iBestLeft;
       126405  +    float fBestOverlap = 0.0;
       126406  +    float fBestArea = 0.0;
       126407  +    int iBestLeft = 0;
126230 126408       int nLeft;
126231 126409   
126232 126410       for(
126233 126411         nLeft=RTREE_MINCELLS(pRtree); 
126234 126412         nLeft<=(nCell-RTREE_MINCELLS(pRtree)); 
126235 126413         nLeft++
126236 126414       ){
................................................................................
126537 126715   }
126538 126716   
126539 126717   static int deleteCell(Rtree *, RtreeNode *, int, int);
126540 126718   
126541 126719   static int removeNode(Rtree *pRtree, RtreeNode *pNode, int iHeight){
126542 126720     int rc;
126543 126721     int rc2;
126544         -  RtreeNode *pParent;
       126722  +  RtreeNode *pParent = 0;
126545 126723     int iCell;
126546 126724   
126547 126725     assert( pNode->nRef==1 );
126548 126726   
126549 126727     /* Remove the entry in the parent cell. */
126550 126728     rc = nodeParentIndex(pRtree, pNode, &iCell);
126551 126729     if( rc==SQLITE_OK ){
................................................................................
126685 126863       if( ii==(nCell-1) ){
126686 126864         memcpy(&aCell[ii], pCell, sizeof(RtreeCell));
126687 126865       }else{
126688 126866         nodeGetCell(pRtree, pNode, ii, &aCell[ii]);
126689 126867       }
126690 126868       aOrder[ii] = ii;
126691 126869       for(iDim=0; iDim<pRtree->nDim; iDim++){
126692         -      aCenterCoord[iDim] += DCOORD(aCell[ii].aCoord[iDim*2]);
126693         -      aCenterCoord[iDim] += DCOORD(aCell[ii].aCoord[iDim*2+1]);
       126870  +      aCenterCoord[iDim] += (float)DCOORD(aCell[ii].aCoord[iDim*2]);
       126871  +      aCenterCoord[iDim] += (float)DCOORD(aCell[ii].aCoord[iDim*2+1]);
126694 126872       }
126695 126873     }
126696 126874     for(iDim=0; iDim<pRtree->nDim; iDim++){
126697         -    aCenterCoord[iDim] = aCenterCoord[iDim]/((float)nCell*2.0);
       126875  +    aCenterCoord[iDim] = (float)(aCenterCoord[iDim]/((float)nCell*2.0));
126698 126876     }
126699 126877   
126700 126878     for(ii=0; ii<nCell; ii++){
126701 126879       aDistance[ii] = 0.0;
126702 126880       for(iDim=0; iDim<pRtree->nDim; iDim++){
126703         -      float coord = DCOORD(aCell[ii].aCoord[iDim*2+1]) - 
126704         -          DCOORD(aCell[ii].aCoord[iDim*2]);
       126881  +      float coord = (float)(DCOORD(aCell[ii].aCoord[iDim*2+1]) - 
       126882  +          DCOORD(aCell[ii].aCoord[iDim*2]));
126705 126883         aDistance[ii] += (coord-aCenterCoord[iDim])*(coord-aCenterCoord[iDim]);
126706 126884       }
126707 126885     }
126708 126886   
126709 126887     SortByDistance(aOrder, nCell, aDistance, aSpare);
126710 126888     nodeZero(pRtree, pNode);
126711 126889   
................................................................................
126796 126974       RtreeNode *pInsert;
126797 126975       RtreeCell cell;
126798 126976       nodeGetCell(pRtree, pNode, ii, &cell);
126799 126977   
126800 126978       /* Find a node to store this cell in. pNode->iNode currently contains
126801 126979       ** the height of the sub-tree headed by the cell.
126802 126980       */
126803         -    rc = ChooseLeaf(pRtree, &cell, pNode->iNode, &pInsert);
       126981  +    rc = ChooseLeaf(pRtree, &cell, (int)pNode->iNode, &pInsert);
126804 126982       if( rc==SQLITE_OK ){
126805 126983         int rc2;
126806         -      rc = rtreeInsertCell(pRtree, pInsert, &cell, pNode->iNode);
       126984  +      rc = rtreeInsertCell(pRtree, pInsert, &cell, (int)pNode->iNode);
126807 126985         rc2 = nodeRelease(pRtree, pInsert);
126808 126986         if( rc==SQLITE_OK ){
126809 126987           rc = rc2;
126810 126988         }
126811 126989       }
126812 126990     }
126813 126991     return rc;
................................................................................
127188 127366     sqlite3 *db,                    /* Database handle */
127189 127367     Rtree *pRtree,                  /* Rtree handle */
127190 127368     int isCreate                    /* True for xCreate, false for xConnect */
127191 127369   ){
127192 127370     int rc;
127193 127371     char *zSql;
127194 127372     if( isCreate ){
127195         -    int iPageSize;
       127373  +    int iPageSize = 0;
127196 127374       zSql = sqlite3_mprintf("PRAGMA %Q.page_size", pRtree->zDb);
127197 127375       rc = getIntFromStmt(db, zSql, &iPageSize);
127198 127376       if( rc==SQLITE_OK ){
127199 127377         pRtree->iNodeSize = iPageSize-64;
127200 127378         if( (4+pRtree->nBytesPerCell*RTREE_MAXCELLS)<pRtree->iNodeSize ){
127201 127379           pRtree->iNodeSize = 4+pRtree->nBytesPerCell*RTREE_MAXCELLS;
127202 127380         }
................................................................................
127991 128169   **
127992 128170   **    May you do good and not evil.
127993 128171   **    May you find forgiveness for yourself and forgive others.
127994 128172   **    May you share freely, never taking more than you give.
127995 128173   **
127996 128174   *************************************************************************
127997 128175   ** This file implements a tokenizer for fts3 based on the ICU library.
127998         -** 
127999         -** $Id: fts3_icu.c,v 1.3 2008/09/01 18:34:20 danielk1977 Exp $
128000 128176   */
128001         -
128002 128177   #if !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3)
128003 128178   #ifdef SQLITE_ENABLE_ICU
128004 128179   
128005 128180   
128006 128181   #include <unicode/ubrk.h>
128007 128182   #include <unicode/utf16.h>
128008 128183   

Changes to src/sqlite3.h.

   105    105   **
   106    106   ** See also: [sqlite3_libversion()],
   107    107   ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
   108    108   ** [sqlite_version()] and [sqlite_source_id()].
   109    109   */
   110    110   #define SQLITE_VERSION        "3.7.7"
   111    111   #define SQLITE_VERSION_NUMBER 3007007
   112         -#define SQLITE_SOURCE_ID      "2011-06-15 13:11:06 f9750870ee04935f338e4d808900fee5a8b2b389"
          112  +#define SQLITE_SOURCE_ID      "2011-06-24 11:29:51 9b191bb4c7c1e1b12b188c0b3eee1f8f587887c8"
   113    113   
   114    114   /*
   115    115   ** CAPI3REF: Run-Time Library Version Numbers
   116    116   ** KEYWORDS: sqlite3_version, sqlite3_sourceid
   117    117   **
   118    118   ** These interfaces provide the same information as the [SQLITE_VERSION],
   119    119   ** [SQLITE_VERSION_NUMBER], and [SQLITE_SOURCE_ID] C preprocessor macros
................................................................................
   306    306   **
   307    307   ** ^The sqlite3_exec() interface runs zero or more UTF-8 encoded,
   308    308   ** semicolon-separate SQL statements passed into its 2nd argument,
   309    309   ** in the context of the [database connection] passed in as its 1st
   310    310   ** argument.  ^If the callback function of the 3rd argument to
   311    311   ** sqlite3_exec() is not NULL, then it is invoked for each result row
   312    312   ** coming out of the evaluated SQL statements.  ^The 4th argument to
   313         -** to sqlite3_exec() is relayed through to the 1st argument of each
          313  +** sqlite3_exec() is relayed through to the 1st argument of each
   314    314   ** callback invocation.  ^If the callback pointer to sqlite3_exec()
   315    315   ** is NULL, then no callback is ever invoked and result rows are
   316    316   ** ignored.
   317    317   **
   318    318   ** ^If an error occurs while evaluating the SQL statements passed into
   319    319   ** sqlite3_exec(), then execution of the current statement stops and
   320    320   ** subsequent statements are skipped.  ^If the 5th parameter to sqlite3_exec()
................................................................................
   898    898   ** of good-quality randomness into zOut.  The return value is
   899    899   ** the actual number of bytes of randomness obtained.
   900    900   ** The xSleep() method causes the calling thread to sleep for at
   901    901   ** least the number of microseconds given.  ^The xCurrentTime()
   902    902   ** method returns a Julian Day Number for the current date and time as
   903    903   ** a floating point value.
   904    904   ** ^The xCurrentTimeInt64() method returns, as an integer, the Julian
   905         -** Day Number multipled by 86400000 (the number of milliseconds in 
          905  +** Day Number multiplied by 86400000 (the number of milliseconds in 
   906    906   ** a 24-hour day).  
   907    907   ** ^SQLite will use the xCurrentTimeInt64() method to get the current
   908    908   ** date and time if that method is available (if iVersion is 2 or 
   909    909   ** greater and the function pointer is not NULL) and will fall back
   910    910   ** to xCurrentTime() if xCurrentTimeInt64() is unavailable.
   911    911   **
   912    912   ** ^The xSetSystemCall(), xGetSystemCall(), and xNestSystemCall() interfaces
................................................................................
  1336   1336   ** ^SQLite will never require a scratch buffer that is more than 6
  1337   1337   ** times the database page size. ^If SQLite needs needs additional
  1338   1338   ** scratch memory beyond what is provided by this configuration option, then 
  1339   1339   ** [sqlite3_malloc()] will be used to obtain the memory needed.</dd>
  1340   1340   **
  1341   1341   ** [[SQLITE_CONFIG_PAGECACHE]] <dt>SQLITE_CONFIG_PAGECACHE</dt>
  1342   1342   ** <dd> ^This option specifies a static memory buffer that SQLite can use for
  1343         -** the database page cache with the default page cache implemenation.  
         1343  +** the database page cache with the default page cache implementation.  
  1344   1344   ** This configuration should not be used if an application-define page
  1345   1345   ** cache implementation is loaded using the SQLITE_CONFIG_PCACHE option.
  1346   1346   ** There are three arguments to this option: A pointer to 8-byte aligned
  1347   1347   ** memory, the size of each page buffer (sz), and the number of pages (N).
  1348   1348   ** The sz argument should be the size of the largest database page
  1349   1349   ** (a power of two between 512 and 32768) plus a little extra for each
  1350   1350   ** page header.  ^The page header size is 20 to 40 bytes depending on
................................................................................
  2434   2434   ** automatically deleted as soon as the database connection is closed.
  2435   2435   **
  2436   2436   ** [[URI filenames in sqlite3_open()]] <h3>URI Filenames</h3>
  2437   2437   **
  2438   2438   ** ^If [URI filename] interpretation is enabled, and the filename argument
  2439   2439   ** begins with "file:", then the filename is interpreted as a URI. ^URI
  2440   2440   ** filename interpretation is enabled if the [SQLITE_OPEN_URI] flag is
  2441         -** is set in the fourth argument to sqlite3_open_v2(), or if it has
         2441  +** set in the fourth argument to sqlite3_open_v2(), or if it has
  2442   2442   ** been enabled globally using the [SQLITE_CONFIG_URI] option with the
  2443   2443   ** [sqlite3_config()] method or by the [SQLITE_USE_URI] compile-time option.
  2444   2444   ** As of SQLite version 3.7.7, URI filename interpretation is turned off
  2445   2445   ** by default, but future releases of SQLite might enable URI filename
  2446         -** intepretation by default.  See "[URI filenames]" for additional
         2446  +** interpretation by default.  See "[URI filenames]" for additional
  2447   2447   ** information.
  2448   2448   **
  2449   2449   ** URI filenames are parsed according to RFC 3986. ^If the URI contains an
  2450   2450   ** authority, then it must be either an empty string or the string 
  2451   2451   ** "localhost". ^If the authority is not an empty string or "localhost", an 
  2452   2452   ** error is returned to the caller. ^The fragment component of a URI, if 
  2453   2453   ** present, is ignored.
................................................................................
  3258   3258   ** [SQLITE_DONE], [SQLITE_ROW], [SQLITE_ERROR], or [SQLITE_MISUSE].
  3259   3259   ** ^With the "v2" interface, any of the other [result codes] or
  3260   3260   ** [extended result codes] might be returned as well.
  3261   3261   **
  3262   3262   ** ^[SQLITE_BUSY] means that the database engine was unable to acquire the
  3263   3263   ** database locks it needs to do its job.  ^If the statement is a [COMMIT]
  3264   3264   ** or occurs outside of an explicit transaction, then you can retry the
  3265         -** statement.  If the statement is not a [COMMIT] and occurs within a
         3265  +** statement.  If the statement is not a [COMMIT] and occurs within an
  3266   3266   ** explicit transaction then you should rollback the transaction before
  3267   3267   ** continuing.
  3268   3268   **
  3269   3269   ** ^[SQLITE_DONE] means that the statement has finished executing
  3270   3270   ** successfully.  sqlite3_step() should not be called again on this virtual
  3271   3271   ** machine without first calling [sqlite3_reset()] to reset the virtual
  3272   3272   ** machine back to its initial state.
................................................................................
  3537   3537   SQLITE_API int sqlite3_column_type(sqlite3_stmt*, int iCol);
  3538   3538   SQLITE_API sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol);
  3539   3539   
  3540   3540   /*
  3541   3541   ** CAPI3REF: Destroy A Prepared Statement Object
  3542   3542   **
  3543   3543   ** ^The sqlite3_finalize() function is called to delete a [prepared statement].
  3544         -** ^If the most recent evaluation of the statement encountered no errors or
         3544  +** ^If the most recent evaluation of the statement encountered no errors
  3545   3545   ** or if the statement is never been evaluated, then sqlite3_finalize() returns
  3546   3546   ** SQLITE_OK.  ^If the most recent evaluation of statement S failed, then
  3547   3547   ** sqlite3_finalize(S) returns the appropriate [error code] or
  3548   3548   ** [extended error code].
  3549   3549   **
  3550   3550   ** ^The sqlite3_finalize(S) routine can be called at any point during
  3551   3551   ** the life cycle of [prepared statement] S:
................................................................................
  5451   5451   ** ^The implementation is not required to provided versions of these
  5452   5452   ** routines that actually work. If the implementation does not provide working
  5453   5453   ** versions of these routines, it should at least provide stubs that always
  5454   5454   ** return true so that one does not get spurious assertion failures.
  5455   5455   **
  5456   5456   ** ^If the argument to sqlite3_mutex_held() is a NULL pointer then
  5457   5457   ** the routine should return 1.   This seems counter-intuitive since
  5458         -** clearly the mutex cannot be held if it does not exist.  But the
         5458  +** clearly the mutex cannot be held if it does not exist.  But
  5459   5459   ** the reason the mutex does not exist is because the build is not
  5460   5460   ** using mutexes.  And we do not want the assert() containing the
  5461   5461   ** call to sqlite3_mutex_held() to fail, so a non-zero return is
  5462   5462   ** the appropriate thing to do.  ^The sqlite3_mutex_notheld()
  5463   5463   ** interface should also return 1 when given a NULL pointer.
  5464   5464   */
  5465   5465   #ifndef NDEBUG
................................................................................
  5574   5574   #define SQLITE_TESTCTRL_ASSERT                  12
  5575   5575   #define SQLITE_TESTCTRL_ALWAYS                  13
  5576   5576   #define SQLITE_TESTCTRL_RESERVE                 14
  5577   5577   #define SQLITE_TESTCTRL_OPTIMIZATIONS           15
  5578   5578   #define SQLITE_TESTCTRL_ISKEYWORD               16
  5579   5579   #define SQLITE_TESTCTRL_PGHDRSZ                 17
  5580   5580   #define SQLITE_TESTCTRL_SCRATCHMALLOC           18
  5581         -#define SQLITE_TESTCTRL_LAST                    18
         5581  +#define SQLITE_TESTCTRL_LOCALTIME_FAULT         19
         5582  +#define SQLITE_TESTCTRL_LAST                    19
  5582   5583   
  5583   5584   /*
  5584   5585   ** CAPI3REF: SQLite Runtime Status
  5585   5586   **
  5586   5587   ** ^This interface is used to retrieve runtime status information
  5587   5588   ** about the performance of SQLite, and optionally to reset various
  5588   5589   ** highwater marks.  ^The first argument is an integer code for
................................................................................
  5960   5961   ** stored in the cache, both pinned and unpinned.
  5961   5962   ** 
  5962   5963   ** [[the xFetch() page cache methods]]
  5963   5964   ** The xFetch() method locates a page in the cache and returns a pointer to 
  5964   5965   ** the page, or a NULL pointer.
  5965   5966   ** A "page", in this context, means a buffer of szPage bytes aligned at an
  5966   5967   ** 8-byte boundary. The page to be fetched is determined by the key. ^The
  5967         -** mimimum key value is 1.  After it has been retrieved using xFetch, the page 
         5968  +** minimum key value is 1.  After it has been retrieved using xFetch, the page 
  5968   5969   ** is considered to be "pinned".
  5969   5970   **
  5970   5971   ** If the requested page is already in the page cache, then the page cache
  5971   5972   ** implementation must return a pointer to the page buffer with its content
  5972   5973   ** intact.  If the requested page is not already in the cache, then the
  5973   5974   ** cache implementation should use the value of the createFlag
  5974   5975   ** parameter to help it determined what action to take:

Changes to src/stash.c.

    98     98       db_bind_text(&ins, ":orig", zOrig);
    99     99       db_bind_text(&ins, ":new", zName);
   100    100       if( rid==0 ){
   101    101         /* A new file */
   102    102         blob_read_from_file(&content, zPath);
   103    103         db_bind_blob(&ins, ":content", &content);
   104    104       }else if( deleted ){
          105  +      blob_zero(&content);
   105    106         db_bind_null(&ins, ":content");
   106    107       }else{
   107    108         /* A modified file */
   108    109         Blob orig;
   109    110         Blob disk;
   110    111         blob_read_from_file(&disk, zPath);
   111    112         content_get(rid, &orig);

Changes to src/tkt.c.

   729    729     login_check_credentials();
   730    730     if( !g.okHistory || !g.okRdTkt ){ login_needed(); return; }
   731    731     zUuid = PD("name","");
   732    732     zTitle = mprintf("History Of Ticket %h", zUuid);
   733    733     style_submenu_element("Status", "Status",
   734    734       "%s/info/%s", g.zTop, zUuid);
   735    735     style_submenu_element("Check-ins", "Check-ins",
   736         -    "%s/tkttimeline?name=%s?y=ci", g.zTop, zUuid);
          736  +    "%s/tkttimeline?name=%s&amp;y=ci", g.zTop, zUuid);
   737    737     style_submenu_element("Timeline", "Timeline",
   738    738       "%s/tkttimeline?name=%s", g.zTop, zUuid);
   739    739     style_header(zTitle);
   740    740     free(zTitle);
   741    741   
   742    742     tagid = db_int(0, "SELECT tagid FROM tag WHERE tagname GLOB 'tkt-%q*'",zUuid);
   743    743     if( tagid==0 ){

Changes to src/wiki.c.

   180    180         "SELECT rid FROM tagxref"
   181    181         " WHERE tagid=(SELECT tagid FROM tag WHERE tagname=%Q)"
   182    182         " ORDER BY mtime DESC", zTag
   183    183       );
   184    184       free(zTag);
   185    185       pWiki = manifest_get(rid, CFTYPE_WIKI);
   186    186       if( pWiki ){
   187         -      while( fossil_isspace(pWiki->zWiki[0]) ) pWiki->zWiki++;
   188         -      if( pWiki->zWiki[0] ) zBody = pWiki->zWiki;
          187  +      zBody = pWiki->zWiki;
   189    188       }
   190    189     }
   191    190     if( !g.isHome ){
   192    191       if( (rid && g.okWrWiki) || (!rid && g.okNewWiki) ){
   193    192         style_submenu_element("Edit", "Edit Wiki Page", "%s/wikiedit?name=%T",
   194    193              g.zTop, zPageName);
   195    194       }
................................................................................
   889    888   
   890    889     if( strncmp(g.argv[2],"export",n)==0 ){
   891    890       char const *zPageName;        /* Name of the wiki page to export */
   892    891       char const *zFile;            /* Name of the output file (0=stdout) */
   893    892       int rid;                      /* Artifact ID of the wiki page */
   894    893       int i;                        /* Loop counter */
   895    894       char *zBody = 0;              /* Wiki page content */
          895  +    Blob body;                    /* Wiki page content */
   896    896       Manifest *pWiki = 0;          /* Parsed wiki page content */
   897    897   
   898    898       if( (g.argc!=4) && (g.argc!=5) ){
   899    899         usage("export PAGENAME ?FILE?");
   900    900       }
   901    901       zPageName = g.argv[3];
   902    902       rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
................................................................................
   907    907       if( (pWiki = manifest_get(rid, CFTYPE_WIKI))!=0 ){
   908    908         zBody = pWiki->zWiki;
   909    909       }
   910    910       if( zBody==0 ){
   911    911         fossil_fatal("wiki page [%s] not found",zPageName);
   912    912       }
   913    913       for(i=strlen(zBody); i>0 && fossil_isspace(zBody[i-1]); i--){}
   914         -    zFile  = (g.argc==4) ? 0 : g.argv[4];
   915         -    if( zFile ){
   916         -      FILE * zF;
   917         -      short doClose = 0;
   918         -      if( (1 == strlen(zFile)) && ('-'==zFile[0]) ){
   919         -        zF = stdout;
   920         -      }else{
   921         -        zF = fossil_fopen( zFile, "w" );
   922         -        doClose = zF ? 1 : 0;
   923         -      }
   924         -      if( ! zF ){
   925         -        fossil_fatal("wiki export could not open output file for writing.");
   926         -      }
   927         -      fprintf(zF,"%.*s\n", i, zBody);
   928         -      if( doClose ) fclose(zF);
   929         -    }else{
   930         -      fossil_print("%.*s\n", i, zBody);
   931         -    }
          914  +    zBody[i] = 0;
          915  +    zFile  = (g.argc==4) ? "-" : g.argv[4];
          916  +    blob_init(&body, zBody, -1);
          917  +    blob_append(&body, "\n", 1);
          918  +    blob_write_to_file(&body, zFile);
          919  +    blob_reset(&body);
   932    920       manifest_destroy(pWiki);
   933    921       return;
   934    922     }else
   935    923     if( strncmp(g.argv[2],"commit",n)==0
   936    924         || strncmp(g.argv[2],"create",n)==0 ){
   937    925       char *zPageName;
   938    926       Blob content;

Changes to src/winhttp.c.

    12     12   ** Author contact information:
    13     13   **   drh@hwaci.com
    14     14   **   http://www.hwaci.com/drh/
    15     15   **
    16     16   *******************************************************************************
    17     17   **
    18     18   ** This file implements a very simple (and low-performance) HTTP server
    19         -** for windows.
           19  +** for windows. It also implements a Windows Service which allows the HTTP
           20  +** server to be run without any user logged on.
    20     21   */
    21     22   #include "config.h"
    22     23   #ifdef _WIN32
    23     24   /* This code is for win32 only */
    24         -#include "winhttp.h"
    25     25   #include <windows.h>
           26  +#include "winhttp.h"
    26     27   
    27     28   /*
    28     29   ** The HttpRequest structure holds information about each incoming
    29     30   ** HTTP request.
    30     31   */
    31     32   typedef struct HttpRequest HttpRequest;
    32     33   struct HttpRequest {
................................................................................
    58     59     }
    59     60     return 0;
    60     61   }
    61     62   
    62     63   /*
    63     64   ** Process a single incoming HTTP request.
    64     65   */
    65         -void win32_process_one_http_request(void *pAppData){
           66  +static void win32_process_one_http_request(void *pAppData){
    66     67     HttpRequest *p = (HttpRequest*)pAppData;
    67     68     FILE *in = 0, *out = 0;
    68     69     int amt, got;
    69     70     int wanted = 0;
    70     71     char *z;
    71     72     char zRequestFName[100];
    72     73     char zReplyFName[100];
................................................................................
   143    144   ){
   144    145     WSADATA wd;
   145    146     SOCKET s = INVALID_SOCKET;
   146    147     SOCKADDR_IN addr;
   147    148     int idCnt = 0;
   148    149     int iPort = mnPort;
   149    150     Blob options;
          151  +  char zTmpPath[MAX_PATH];
   150    152   
   151    153     if( zStopper ) file_delete(zStopper);
   152    154     blob_zero(&options);
   153    155     if( zNotFound ){
   154    156       blob_appendf(&options, " --notfound %s", zNotFound);
   155    157     }
   156    158     if( g.useLocalauth ){
................................................................................
   187    189       if( mnPort==mxPort ){
   188    190         fossil_fatal("unable to open listening socket on ports %d", mnPort);
   189    191       }else{
   190    192         fossil_fatal("unable to open listening socket on any"
   191    193                      " port in the range %d..%d", mnPort, mxPort);
   192    194       }
   193    195     }
   194         -  zTempPrefix = mprintf("fossil_server_P%d_", iPort);
          196  +  if( !GetTempPath(sizeof(zTmpPath), zTmpPath) ){
          197  +    fossil_fatal("unable to get path to the temporary directory.");
          198  +  }
          199  +  zTempPrefix = mprintf("%sfossil_server_P%d_", zTmpPath, iPort);
   195    200     fossil_print("Listening for HTTP requests on TCP port %d\n", iPort);
   196    201     if( zBrowser ){
   197    202       zBrowser = mprintf(zBrowser, iPort);
   198    203       fossil_print("Launch webbrowser: %s\n", zBrowser);
   199    204       fossil_system(zBrowser);
   200    205     }
   201    206     fossil_print("Type Ctrl-C to stop the HTTP server\n");
          207  +  /* Set the service status to running and pass the listener socket to the
          208  +  ** service handling procedures. */
          209  +  win32_http_service_running(s);
   202    210     for(;;){
   203    211       SOCKET client;
   204    212       SOCKADDR_IN client_addr;
   205    213       HttpRequest *p;
   206    214       int len = sizeof(client_addr);
          215  +    int wsaError;
   207    216   
   208    217       client = accept(s, (struct sockaddr*)&client_addr, &len);
   209         -    if( zStopper && file_size(zStopper)>=0 ){
   210         -      break;
   211         -    }
   212    218       if( client==INVALID_SOCKET ){
   213         -      closesocket(s);
   214         -      fossil_fatal("error from accept()");
          219  +      /* If the service control handler has closed the listener socket, 
          220  +      ** cleanup and return, otherwise report a fatal error. */
          221  +      wsaError =  WSAGetLastError();
          222  +      if( (wsaError==WSAEINTR) || (wsaError==WSAENOTSOCK) ){
          223  +        WSACleanup();
          224  +        return;
          225  +      }else{
          226  +        closesocket(s);
          227  +        WSACleanup();
          228  +        fossil_fatal("error from accept()");
          229  +      }
          230  +    }else if( zStopper && file_size(zStopper)>=0 ){
          231  +      break;
   215    232       }
   216    233       p = fossil_malloc( sizeof(*p) );
   217    234       p->id = ++idCnt;
   218    235       p->s = client;
   219    236       p->addr = client_addr;
   220    237       p->zOptions = blob_str(&options);
   221    238       _beginthread(win32_process_one_http_request, 0, (void*)p);
   222    239     }
   223    240     closesocket(s);
   224    241     WSACleanup();
   225    242   }
          243  +
          244  +/*
          245  +** The HttpService structure is used to pass information to the service main
          246  +** function and to the service control handler function.
          247  +*/
          248  +typedef struct HttpService HttpService;
          249  +struct HttpService {
          250  +  int port;                 /* Port on which the http server should run */
          251  +  const char *zNotFound;    /* The --notfound option, or NULL */
          252  +  int flags;                /* One or more HTTP_SERVER_ flags */
          253  +  int isRunningAsService;   /* Are we running as a service ? */
          254  +  const char *zServiceName; /* Name of the service */
          255  +  SOCKET s;                 /* Socket on which the http server listens */
          256  +};
          257  +
          258  +/*
          259  +** Variables used for running as windows service.
          260  +*/
          261  +static HttpService hsData = {8080, NULL, 0, 0, NULL, INVALID_SOCKET};
          262  +static SERVICE_STATUS ssStatus;
          263  +static SERVICE_STATUS_HANDLE sshStatusHandle;
          264  +
          265  +/*
          266  +** Get message string of the last system error. Return a pointer to the
          267  +** message string. Call fossil_mbcs_free() to deallocate any memory used
          268  +** to store the message string when done.
          269  +*/
          270  +static char *win32_get_last_errmsg(void){
          271  +  DWORD nMsg;
          272  +  LPTSTR tmp = NULL;
          273  +  char *zMsg = NULL;
          274  +
          275  +  nMsg = FormatMessage(
          276  +           FORMAT_MESSAGE_ALLOCATE_BUFFER |
          277  +           FORMAT_MESSAGE_FROM_SYSTEM     |
          278  +           FORMAT_MESSAGE_IGNORE_INSERTS,
          279  +           NULL,
          280  +           GetLastError(),
          281  +           MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
          282  +           (LPTSTR) &tmp,
          283  +           0,
          284  +           NULL
          285  +         );
          286  +  if( nMsg ){
          287  +    zMsg = fossil_mbcs_to_utf8(tmp);
          288  +  }else{
          289  +    fossil_fatal("unable to get system error message.");
          290  +  }
          291  +  if( tmp ){
          292  +    LocalFree((HLOCAL) tmp);
          293  +  }
          294  +  return zMsg;
          295  +}
          296  +
          297  +/*
          298  +** Report the current status of the service to the service control manager.
          299  +** Make sure that during service startup no control codes are accepted.
          300  +*/
          301  +static void win32_report_service_status(
          302  +  DWORD dwCurrentState,     /* The current state of the service */
          303  +  DWORD dwWin32ExitCode,    /* The error code to report */
          304  +  DWORD dwWaitHint          /* The estimated time for a pending operation */
          305  +){
          306  +  if( dwCurrentState==SERVICE_START_PENDING) {
          307  +    ssStatus.dwControlsAccepted = 0;
          308  +  }else{
          309  +    ssStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
          310  +  }
          311  +  ssStatus.dwCurrentState = dwCurrentState;
          312  +  ssStatus.dwWin32ExitCode = dwWin32ExitCode;
          313  +  ssStatus.dwWaitHint = dwWaitHint;
          314  +
          315  +  if( (dwCurrentState==SERVICE_RUNNING) || 
          316  +      (dwCurrentState==SERVICE_STOPPED) ){
          317  +    ssStatus.dwCheckPoint = 0;
          318  +  }else{
          319  +    ssStatus.dwCheckPoint++;
          320  +  }
          321  +  SetServiceStatus(sshStatusHandle, &ssStatus);
          322  +  return ;
          323  +}
          324  +
          325  +/*
          326  +** Handle control codes sent from the service control manager.
          327  +** The control dispatcher in the main thread of the service process invokes
          328  +** this function whenever it receives a control request from the service
          329  +** control manager.
          330  +*/
          331  +static void WINAPI win32_http_service_ctrl(
          332  +  DWORD dwCtrlCode
          333  +){
          334  +  switch( dwCtrlCode ){
          335  +    case SERVICE_CONTROL_STOP: {
          336  +      win32_report_service_status(SERVICE_STOP_PENDING, NO_ERROR, 0);
          337  +      if( hsData.s != INVALID_SOCKET ){
          338  +        closesocket(hsData.s);
          339  +      }
          340  +      win32_report_service_status(ssStatus.dwCurrentState, NO_ERROR, 0);
          341  +      break;
          342  +    }
          343  +    default: {
          344  +      break;
          345  +    }
          346  +  }
          347  +  return;
          348  +}
          349  +
          350  +/*
          351  +** This is the main entry point for the service.
          352  +** When the service control manager receives a request to start the service,
          353  +** it starts the service process (if it is not already running). The main
          354  +** thread of the service process calls the StartServiceCtrlDispatcher
          355  +** function with a pointer to an array of SERVICE_TABLE_ENTRY structures.
          356  +** Then the service control manager sends a start request to the service
          357  +** control dispatcher for this service process. The service control dispatcher
          358  +** creates a new thread to execute the ServiceMain function (this function)
          359  +** of the service being started.
          360  +*/
          361  +static void WINAPI win32_http_service_main(
          362  +  DWORD argc,              /* Number of arguments in argv */
          363  +  LPTSTR *argv             /* Arguments passed */
          364  +){
          365  +
          366  +  /* Update the service information. */
          367  +  hsData.isRunningAsService = 1;
          368  +  if( argc>0 ){
          369  +    hsData.zServiceName = argv[0];
          370  +  }
          371  +
          372  +  /* Register the service control handler function */
          373  +  sshStatusHandle = RegisterServiceCtrlHandler("", win32_http_service_ctrl);
          374  +  if( !sshStatusHandle ){
          375  +    win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
          376  +    return;
          377  +  }
          378  +
          379  +  /* Set service specific data and report that the service is starting. */
          380  +  ssStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
          381  +  ssStatus.dwServiceSpecificExitCode = 0;
          382  +  win32_report_service_status(SERVICE_START_PENDING, NO_ERROR, 3000);
          383  +
          384  +   /* Execute the http server */
          385  +  win32_http_server(hsData.port, hsData.port,
          386  +                    NULL, NULL, hsData.zNotFound, hsData.flags);
          387  +
          388  +  /* Service has stopped now. */
          389  +  win32_report_service_status(SERVICE_STOPPED, NO_ERROR, 0);
          390  +  return;
          391  +}
          392  +
          393  +/*
          394  +** When running as service, update the HttpService structure with the
          395  +** listener socket and update the service status. This procedure must be
          396  +** called from the http server when he is ready to accept connections.
          397  +*/
          398  +LOCAL void win32_http_service_running(SOCKET s){
          399  +  if( hsData.isRunningAsService ){
          400  +    hsData.s = s;
          401  +    win32_report_service_status(SERVICE_RUNNING, NO_ERROR, 0);
          402  +  }
          403  +}
          404  +
          405  +/*
          406  +** Try to start the http server as a windows service. If we are running in
          407  +** a interactive console session, this routine fails and returns a non zero
          408  +** integer value. When running as service, this routine does not return until
          409  +** the service is stopped. In this case, the return value is zero.
          410  +*/
          411  +int win32_http_service(
          412  +  int nPort,                /* TCP port number */
          413  +  const char *zNotFound,    /* The --notfound option, or NULL */
          414  +  int flags                 /* One or more HTTP_SERVER_ flags */
          415  +){
          416  +  /* Define the service table. */
          417  +  SERVICE_TABLE_ENTRY ServiceTable[] =
          418  +    {{"", (LPSERVICE_MAIN_FUNCTION)win32_http_service_main}, {NULL, NULL}};
          419  +  
          420  +  /* Initialize the HttpService structure. */
          421  +  hsData.port = nPort;
          422  +  hsData.zNotFound = zNotFound;
          423  +  hsData.flags = flags;
          424  +
          425  +  /* Try to start the control dispatcher thread for the service. */
          426  +  if( !StartServiceCtrlDispatcher(ServiceTable) ){
          427  +    if( GetLastError()==ERROR_FAILED_SERVICE_CONTROLLER_CONNECT ){
          428  +      return 1;
          429  +    }else{
          430  +      fossil_fatal("error from StartServiceCtrlDispatcher()");
          431  +    }
          432  +  }
          433  +  return 0;
          434  +}
          435  +
          436  +/*
          437  +** COMMAND: winsrv
          438  +** Usage: fossil winsrv METHOD ?SERVICE-NAME? ?OPTIONS?
          439  +**
          440  +** Where METHOD is one of: create delete show start stop.
          441  +**
          442  +** The winsrv command manages Fossil as a Windows service.  This allows
          443  +** (for example) Fossil to be running in the background when no user
          444  +** is logged in.
          445  +**
          446  +** In the following description of the methods, "Fossil-DSCM" will be
          447  +** used as the default SERVICE-NAME:
          448  +** 
          449  +**    fossil service create ?SERVICE-NAME? ?OPTIONS?
          450  +**
          451  +**         Creates a service. Available options include:
          452  +**
          453  +**         -D|--display DISPLAY-NAME
          454  +**
          455  +**              Sets the display name of the service. This name is shown
          456  +**              by graphical interface programs. By default, the display name
          457  +**              equals to the service name.
          458  +**
          459  +**         -S|--start TYPE
          460  +**
          461  +**              Sets the start type of the service. TYPE can be "manual",
          462  +**              which means you need to start the service yourself with the
          463  +**              'fossil service start' command or with the "net start" command
          464  +**              from the operating system. If TYPE is set to "auto", the service
          465  +**              will be started automatically by the system during startup.
          466  +**
          467  +**         -U|--username USERNAME
          468  +**
          469  +**              Specifies the user account which will be used to run the
          470  +**              service. The account needs the "Logon as a service" right
          471  +**              enabled in its profile. Specify local accounts as follows:
          472  +**              ".\\USERNAME". By default, the "LocalSystem" account will be
          473  +**              used.
          474  +**
          475  +**         -W|--password PASSWORD
          476  +**
          477  +**              Password for the user account.
          478  +**
          479  +**         The following options are more or less the same as for the "server"
          480  +**         command and influence the behaviour of the http server:
          481  +**
          482  +**         -p|--port TCPPORT
          483  +**
          484  +**              Specifies the TCP port (default port is 8080) on which the
          485  +**              server should listen.
          486  +**
          487  +**         -R|--repository REPOSITORY
          488  +**
          489  +**              Specifies the name of the repository to be served.
          490  +**              The repository option may be omitted if the working directory
          491  +**              is within an open checkout.
          492  +**              The REPOSITORY can be a directory (aka folder) that contains
          493  +**              one or more respositories with names ending in ".fossil".
          494  +**              In that case, the first element of the URL is used to select
          495  +**              among the various repositories.
          496  +**
          497  +**         --notfound URL
          498  +**
          499  +**              If REPOSITORY is a directory that contains one or more
          500  +**              respositories with names of the form "*.fossil" then the
          501  +**              first element of the URL  pathname selects among the various
          502  +**              repositories. If the pathname does not select a valid
          503  +**              repository and the --notfound option is available,
          504  +**              then the server redirects (HTTP code 302) to the URL of
          505  +**              --notfound.
          506  +**
          507  +**         --localauth
          508  +**
          509  +**              Enables automatic login if the --localauth option is present
          510  +**              and the "localauth" setting is off and the connection is from
          511  +**              localhost.
          512  +**
          513  +**
          514  +**    fossil service delete ?SERVICE-NAME?
          515  +**
          516  +**         Deletes a service. If the service is currently running, it will be
          517  +**         stopped first and then deleted.
          518  +**
          519  +**
          520  +**    fossil service show ?SERVICE-NAME?
          521  +**
          522  +**         Shows how the service is configured and its current state.
          523  +**
          524  +**
          525  +**    fossil service start ?SERVICE-NAME?
          526  +**
          527  +**         Start the service.
          528  +**
          529  +**
          530  +**    fossil service stop ?SERVICE-NAME?
          531  +**
          532  +**         Stop the service.
          533  +**
          534  +**
          535  +** NOTE: This command is available on Windows operating systems only and
          536  +**       requires administrative rights on the machine executed.
          537  +**
          538  +*/
          539  +void cmd_win32_service(void){
          540  +  int n;
          541  +  const char *zMethod;
          542  +  const char *zSvcName = "Fossil-DSCM";    /* Default service name */
          543  +
          544  +  if( g.argc<3 ){
          545  +    usage("create|delete|show|start|stop ...");
          546  +  }
          547  +  zMethod = g.argv[2];
          548  +  n = strlen(zMethod);
          549  +  if( g.argc==4 ){
          550  +    zSvcName = g.argv[3];
          551  +  }
          552  +
          553  +  if( strncmp(zMethod, "create", n)==0 ){
          554  +    SC_HANDLE hScm;
          555  +    SC_HANDLE hSvc;
          556  +    SERVICE_DESCRIPTION
          557  +      svcDescr = {"Fossil - Distributed Software Configuration Management"};
          558  +    char *zErrFmt = "unable to create service '%s': %s";
          559  +    DWORD dwStartType = SERVICE_DEMAND_START;
          560  +    const char *zDisplay;
          561  +    const char *zStart;
          562  +    const char *zUsername;
          563  +    const char *zPassword;
          564  +    const char *zPort;
          565  +    const char *zNotFound;
          566  +    const char *zLocalAuth;
          567  +    const char *zRepository;
          568  +    Blob binPath;
          569  +
          570  +    /* Process service creation specific options. */
          571  +    zDisplay = find_option("display", "D", 1);
          572  +    if( !zDisplay ){
          573  +      zDisplay = zSvcName;
          574  +    }
          575  +    zStart = find_option("start", "S", 1);
          576  +    if( zStart ){
          577  +      if( strncmp(zStart, "auto", strlen(zStart))==0 ){
          578  +        dwStartType = SERVICE_AUTO_START;
          579  +      }else  if( strncmp(zStart, "manual", strlen(zStart))==0 ){
          580  +        dwStartType = SERVICE_DEMAND_START;
          581  +      }else{
          582  +        fossil_fatal(zErrFmt, zSvcName,
          583  +                     "specify 'auto' or 'manual' for the '-S|--start' option");
          584  +      }
          585  +    }
          586  +    zUsername = find_option("username", "U", 1);
          587  +    zPassword = find_option("password", "W", 1);
          588  +    /* Process options for Fossil running as server. */
          589  +    zPort = find_option("port", "P", 1);
          590  +    if( zPort && (atoi(zPort)<=0) ){
          591  +      fossil_fatal(zErrFmt, zSvcName,
          592  +                   "port number must be in the range 1 - 65535.");
          593  +    }
          594  +    zNotFound = find_option("notfound", 0, 1);
          595  +    zLocalAuth = find_option("localauth", 0, 0);
          596  +    zRepository = find_option("repository", "R", 1);
          597  +    if( !zRepository ){
          598  +      db_must_be_within_tree();
          599  +    }else if( file_isdir(zRepository)==1 ){
          600  +      g.zRepositoryName = mprintf("%s", zRepository);
          601  +      file_simplify_name(g.zRepositoryName, -1);
          602  +    }else{
          603  +      db_open_repository(zRepository);
          604  +    }
          605  +    db_close(0);
          606  +    verify_all_options();
          607  +    if( g.argc>4 ) fossil_fatal("to much arguments for create method.");
          608  +    /* Build the fully-qualified path to the service binary file. */
          609  +    blob_zero(&binPath);
          610  +    blob_appendf(&binPath, "\"%s\" server", fossil_nameofexe());
          611  +    if( zPort ) blob_appendf(&binPath, " --port %s", zPort);
          612  +    if( zNotFound ) blob_appendf(&binPath, " --notfound \"%s\"", zNotFound);
          613  +    if( zLocalAuth ) blob_append(&binPath, " --localauth", -1);
          614  +    blob_appendf(&binPath, " \"%s\"", g.zRepositoryName);
          615  +    /* Create the service. */
          616  +    hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
          617  +    if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          618  +    hSvc = CreateService(
          619  +             hScm,                                    /* Handle to the SCM */
          620  +             fossil_utf8_to_mbcs(zSvcName),           /* Name of the service */
          621  +             fossil_utf8_to_mbcs(zDisplay),           /* Display name */
          622  +             SERVICE_ALL_ACCESS,                      /* Desired access */
          623  +             SERVICE_WIN32_OWN_PROCESS,               /* Service type */
          624  +             dwStartType,                             /* Start type */
          625  +             SERVICE_ERROR_NORMAL,                    /* Error control */
          626  +             fossil_utf8_to_mbcs(blob_str(&binPath)), /* Binary path */
          627  +             NULL,                                    /* Load ordering group */
          628  +             NULL,                                    /* Tag value */
          629  +             NULL,                                    /* Service dependencies */
          630  +             fossil_utf8_to_mbcs(zUsername),          /* Service account */
          631  +             fossil_utf8_to_mbcs(zPassword)           /* Account password */
          632  +           );
          633  +    if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          634  +    /* Set the service description. */
          635  +    ChangeServiceConfig2(hSvc, SERVICE_CONFIG_DESCRIPTION, &svcDescr);
          636  +    fossil_print("Service '%s' successfully created.\n", zSvcName);
          637  +    CloseServiceHandle(hSvc);
          638  +    CloseServiceHandle(hScm);
          639  +  }else
          640  +  if( strncmp(zMethod, "delete", n)==0 ){
          641  +    SC_HANDLE hScm;
          642  +    SC_HANDLE hSvc;
          643  +    SERVICE_STATUS sstat;
          644  +    char *zErrFmt = "unable to delete service '%s': %s";
          645  +
          646  +    verify_all_options();
          647  +    if( g.argc>4 ) fossil_fatal("to much arguments for delete method.");
          648  +    hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
          649  +    if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          650  +    hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), SERVICE_ALL_ACCESS);
          651  +    if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          652  +    QueryServiceStatus(hSvc, &sstat);
          653  +    if( sstat.dwCurrentState!=SERVICE_STOPPED ){
          654  +      fossil_print("Stopping service '%s'", zSvcName);
          655  +      if( sstat.dwCurrentState!=SERVICE_STOP_PENDING ){
          656  +        if( !ControlService(hSvc, SERVICE_CONTROL_STOP, &sstat) ){
          657  +          fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          658  +        }
          659  +      }
          660  +      while( sstat.dwCurrentState!=SERVICE_STOPPED ){
          661  +        Sleep(100);
          662  +        fossil_print(".");
          663  +        QueryServiceStatus(hSvc, &sstat);
          664  +      }
          665  +      fossil_print("\nService '%s' stopped.\n", zSvcName);
          666  +    }
          667  +    if( !DeleteService(hSvc) ){
          668  +      if( GetLastError()==ERROR_SERVICE_MARKED_FOR_DELETE ){
          669  +        fossil_warning("Service '%s' already marked for delete.\n", zSvcName);
          670  +      }else{
          671  +        fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          672  +      }
          673  +    }else{
          674  +      fossil_print("Service '%s' successfully deleted.\n", zSvcName);
          675  +    }
          676  +    CloseServiceHandle(hSvc);
          677  +    CloseServiceHandle(hScm);
          678  +  }else
          679  +  if( strncmp(zMethod, "show", n)==0 ){
          680  +    SC_HANDLE hScm;
          681  +    SC_HANDLE hSvc;
          682  +    SERVICE_STATUS sstat;
          683  +    LPQUERY_SERVICE_CONFIG pSvcConfig;
          684  +    LPSERVICE_DESCRIPTION pSvcDescr;
          685  +    BOOL bStatus;
          686  +    DWORD nRequired;
          687  +    char *zErrFmt = "unable to show service '%s': %s";
          688  +    static const char *zSvcTypes[] = {
          689  +      "Driver service",
          690  +      "File system driver service",
          691  +      "Service runs in its own process",
          692  +      "Service shares a process with other services",
          693  +      "Service can interact with the desktop"
          694  +    };
          695  +    const char *zSvcType = "";
          696  +    static char *zSvcStartTypes[] = {
          697  +      "Started by the system loader",
          698  +      "Started by the IoInitSystem function",
          699  +      "Started automatically by the service control manager",
          700  +      "Started manually",
          701  +      "Service cannot be started"
          702  +    };
          703  +    const char *zSvcStartType = "";
          704  +    static const char *zSvcStates[] = {
          705  +      "Stopped", "Starting", "Stopping", "Running",
          706  +      "Continue pending", "Pause pending", "Paused"
          707  +    };
          708  +    const char *zSvcState = "";
          709  +
          710  +    verify_all_options();
          711  +    if( g.argc>4 ) fossil_fatal("to much arguments for show method.");
          712  +    hScm = OpenSCManager(NULL, NULL, GENERIC_READ);
          713  +    if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          714  +    hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), GENERIC_READ);
          715  +    if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          716  +    /* Get the service configuration */
          717  +    bStatus = QueryServiceConfig(hSvc, NULL, 0, &nRequired);
          718  +    if( !bStatus && GetLastError()!=ERROR_INSUFFICIENT_BUFFER ){
          719  +      fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          720  +    }
          721  +    pSvcConfig = fossil_malloc(nRequired);
          722  +    bStatus = QueryServiceConfig(hSvc, pSvcConfig, nRequired, &nRequired);
          723  +    if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          724  +    /* Translate the service type */
          725  +    switch( pSvcConfig->dwServiceType ){
          726  +      case SERVICE_KERNEL_DRIVER:       zSvcType = zSvcTypes[0]; break;
          727  +      case SERVICE_FILE_SYSTEM_DRIVER:  zSvcType = zSvcTypes[1]; break;
          728  +      case SERVICE_WIN32_OWN_PROCESS:   zSvcType = zSvcTypes[2]; break;
          729  +      case SERVICE_WIN32_SHARE_PROCESS: zSvcType = zSvcTypes[3]; break;
          730  +      case SERVICE_INTERACTIVE_PROCESS: zSvcType = zSvcTypes[4]; break;
          731  +    }
          732  +    /* Translate the service start type */
          733  +    switch( pSvcConfig->dwStartType ){
          734  +      case SERVICE_BOOT_START:    zSvcStartType = zSvcStartTypes[0]; break;
          735  +      case SERVICE_SYSTEM_START:  zSvcStartType = zSvcStartTypes[1]; break;
          736  +      case SERVICE_AUTO_START:    zSvcStartType = zSvcStartTypes[2]; break;
          737  +      case SERVICE_DEMAND_START:  zSvcStartType = zSvcStartTypes[3]; break;
          738  +      case SERVICE_DISABLED:      zSvcStartType = zSvcStartTypes[4]; break;
          739  +    }
          740  +    /* Get the service description. */
          741  +    bStatus = QueryServiceConfig2(hSvc, SERVICE_CONFIG_DESCRIPTION,
          742  +                                  NULL, 0, &nRequired);
          743  +    if( !bStatus && GetLastError()!=ERROR_INSUFFICIENT_BUFFER ){
          744  +      fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          745  +    }
          746  +    pSvcDescr = fossil_malloc(nRequired);
          747  +    bStatus = QueryServiceConfig2(hSvc, SERVICE_CONFIG_DESCRIPTION,
          748  +                                  (LPBYTE)pSvcDescr, nRequired, &nRequired);
          749  +    if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          750  +    /* Retrieves the current status of the specified service. */
          751  +    bStatus = QueryServiceStatus(hSvc, &sstat);
          752  +    if( !bStatus ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          753  +    /* Translate the current state. */
          754  +    switch( sstat.dwCurrentState ){
          755  +      case SERVICE_STOPPED:          zSvcState = zSvcStates[0]; break;
          756  +      case SERVICE_START_PENDING:    zSvcState = zSvcStates[1]; break;
          757  +      case SERVICE_STOP_PENDING:     zSvcState = zSvcStates[2]; break;
          758  +      case SERVICE_RUNNING:          zSvcState = zSvcStates[3]; break;
          759  +      case SERVICE_CONTINUE_PENDING: zSvcState = zSvcStates[4]; break;
          760  +      case SERVICE_PAUSE_PENDING:    zSvcState = zSvcStates[5]; break;
          761  +      case SERVICE_PAUSED:           zSvcState = zSvcStates[6]; break;
          762  +    }
          763  +    /* Print service information to terminal */
          764  +    fossil_print("Service name .......: %s\n", zSvcName);
          765  +    fossil_print("Display name .......: %s\n",
          766  +                 fossil_mbcs_to_utf8(pSvcConfig->lpDisplayName));
          767  +    fossil_print("Service description : %s\n",
          768  +                 fossil_mbcs_to_utf8(pSvcDescr->lpDescription));
          769  +    fossil_print("Service type .......: %s.\n", zSvcType);
          770  +    fossil_print("Service start type .: %s.\n", zSvcStartType);
          771  +    fossil_print("Binary path name ...: %s\n",
          772  +                 fossil_mbcs_to_utf8(pSvcConfig->lpBinaryPathName));
          773  +    fossil_print("Service username ...: %s\n",
          774  +                 fossil_mbcs_to_utf8(pSvcConfig->lpServiceStartName));
          775  +    fossil_print("Current state ......: %s.\n", zSvcState);
          776  +    /* Cleanup */
          777  +    fossil_free(pSvcConfig);
          778  +    fossil_free(pSvcDescr);
          779  +    CloseServiceHandle(hSvc);
          780  +    CloseServiceHandle(hScm);
          781  +  }else
          782  +  if( strncmp(zMethod, "start", n)==0 ){
          783  +    SC_HANDLE hScm;
          784  +    SC_HANDLE hSvc;
          785  +    SERVICE_STATUS sstat;
          786  +    char *zErrFmt = "unable to start service '%s': %s";
          787  +
          788  +    verify_all_options();
          789  +    if( g.argc>4 ) fossil_fatal("to much arguments for start method.");
          790  +    hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
          791  +    if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          792  +    hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), SERVICE_ALL_ACCESS);
          793  +    if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          794  +    QueryServiceStatus(hSvc, &sstat);
          795  +    if( sstat.dwCurrentState!=SERVICE_RUNNING ){
          796  +      fossil_print("Starting service '%s'", zSvcName);
          797  +      if( sstat.dwCurrentState!=SERVICE_START_PENDING ){
          798  +        if( !StartService(hSvc, 0, NULL) ){
          799  +          fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          800  +        }
          801  +      }
          802  +      while( sstat.dwCurrentState!=SERVICE_RUNNING ){
          803  +        Sleep(100);
          804  +        fossil_print(".");
          805  +        QueryServiceStatus(hSvc, &sstat);
          806  +      }
          807  +      fossil_print("\nService '%s' started.\n", zSvcName);
          808  +    }else{
          809  +      fossil_print("Service '%s' is already started.\n", zSvcName);
          810  +    }
          811  +    CloseServiceHandle(hSvc);
          812  +    CloseServiceHandle(hScm);
          813  +  }else
          814  +  if( strncmp(zMethod, "stop", n)==0 ){
          815  +    SC_HANDLE hScm;
          816  +    SC_HANDLE hSvc;
          817  +    SERVICE_STATUS sstat;
          818  +    char *zErrFmt = "unable to stop service '%s': %s";
          819  +
          820  +    verify_all_options();
          821  +    if( g.argc>4 ) fossil_fatal("to much arguments for stop method.");
          822  +    hScm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
          823  +    if( !hScm ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          824  +    hSvc = OpenService(hScm, fossil_utf8_to_mbcs(zSvcName), SERVICE_ALL_ACCESS);
          825  +    if( !hSvc ) fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          826  +    QueryServiceStatus(hSvc, &sstat);
          827  +    if( sstat.dwCurrentState!=SERVICE_STOPPED ){
          828  +      fossil_print("Stopping service '%s'", zSvcName);
          829  +      if( sstat.dwCurrentState!=SERVICE_STOP_PENDING ){
          830  +        if( !ControlService(hSvc, SERVICE_CONTROL_STOP, &sstat) ){
          831  +          fossil_fatal(zErrFmt, zSvcName, win32_get_last_errmsg());
          832  +        }
          833  +      }
          834  +      while( sstat.dwCurrentState!=SERVICE_STOPPED ){
          835  +        Sleep(100);
          836  +        fossil_print(".");
          837  +        QueryServiceStatus(hSvc, &sstat);
          838  +      }
          839  +      fossil_print("\nService '%s' stopped.\n", zSvcName);
          840  +    }else{
          841  +      fossil_print("Service '%s' is already stopped.\n", zSvcName);
          842  +    }
          843  +    CloseServiceHandle(hSvc);
          844  +    CloseServiceHandle(hScm);
          845  +  }else
          846  +  {
          847  +    fossil_fatal("METHOD should be one of:"
          848  +                 " create delete show start stop");
          849  +  }
          850  +  return;
          851  +}
          852  +
          853  +#else /* _WIN32  -- This code is for win32 only */
          854  +#include "winhttp.h"
          855  +
          856  +void cmd_win32_service(void){
          857  +  fossil_fatal("The service command is platform specific "
          858  +               "and not available on this platform."); 
          859  +  return;
          860  +}
   226    861   
   227    862   #endif /* _WIN32  -- This code is for win32 only */

Changes to test/release-checklist.wiki.

    19     19   Compile for all of the following platforms:
    20     20   <ol type="a">
    21     21   <li> Linux x86
    22     22   <li> Linux x86_64
    23     23   <li> Mac x86
    24     24   <li> Mac x86_64
    25     25   <li> Windows (mingw)
           26  +<li> Windows (vc++)
    26     27   <li> OpenBSD
    27     28   </ol>
    28     29   
    29     30   <li><p>
    30     31   Run at least one occurrence of the the following commands on every
    31     32   platform:
    32     33   <ol type="a">
................................................................................
    54     55   </ol>
    55     56   
    56     57   
    57     58   <li><p>
    58     59   Use the release candidate version of fossil in production on the
    59     60   [http://www.fossil-scm.org/] website for at least 48 hours (without
    60     61   incident) prior to making the release official.
           62  +
           63  +<li><p>
           64  +Verify that the [../www/changes.wiki | Change Log] is correct and
           65  +up-to-date.
    61     66   </ol>
    62     67   
    63     68   <hr>
    64     69   
    65     70   Upon successful completion of all tests above, tag the release candidate
    66         -with the "release" tag and set its background color to "#d0c0ff".
           71  +with the "release" tag and set its background color to "#d0c0ff".  Update
           72  +the www/changes.wiki file to show the date of the release.

Changes to win/Makefile.PellesCGMake.

   136    136   	translate.exe $< >$@
   137    137   
   138    138   # generate the index source, containing all web references,..
   139    139   page_index.h:	$(TRANSLATEDSRC) mkindex.exe
   140    140   	mkindex.exe $(TRANSLATEDSRC) >$@
   141    141   
   142    142   # extracting version info from manifest
   143         -VERSION.h:	version.exe ..\manifest.uuid ..\manifest
   144         -	version.exe ..\manifest.uuid ..\manifest  > $@
          143  +VERSION.h:	version.exe ..\manifest.uuid ..\manifest ..\VERSION
          144  +	version.exe ..\manifest.uuid ..\manifest ..\VERSION  > $@
   145    145   
   146    146   # generate the simplified headers
   147    147   headers: makeheaders.exe page_index.h VERSION.h ../src/sqlite3.h ../src/th.h VERSION.h
   148    148   	makeheaders.exe $(foreach ts,$(TRANSLATEDSRC),$(ts):$(ts:_.c=.h)) ../src/sqlite3.h ../src/th.h VERSION.h
   149    149   	echo Done >$@
   150    150   
   151    151   # compile C sources with relevant options

Changes to win/Makefile.dmc.

    71     71   
    72     72   $(OBJDIR)\th$O : $(SRCDIR)\th.c
    73     73   	$(TCC) -o$@ -c $**
    74     74   
    75     75   $(OBJDIR)\th_lang$O : $(SRCDIR)\th_lang.c
    76     76   	$(TCC) -o$@ -c $**
    77     77   
    78         -VERSION.h : version$E $B\manifest.uuid $B\manifest
           78  +VERSION.h : version$E $B\manifest.uuid $B\manifest $B\VERSION
    79     79   	+$** > $@
    80     80   
    81     81   page_index.h: mkindex$E $(SRC) 
    82     82   	+$** > $@
    83     83   
    84     84   clean:
    85     85   	-del $(OBJDIR)\*.obj

Changes to win/Makefile.mingw.

   359    359   # WARNING. DANGER. Running the testsuite modifies the repository the
   360    360   # build is done from, i.e. the checkout belongs to. Do not sync/push
   361    361   # the repository after running the tests.
   362    362   test:	$(APPNAME)
   363    363   	$(TCLSH) test/tester.tcl $(APPNAME)
   364    364   
   365    365   $(OBJDIR)/VERSION.h:	$(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(VERSION)
   366         -	$(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest >$(OBJDIR)/VERSION.h
          366  +	$(VERSION) $(SRCDIR)/../manifest.uuid $(SRCDIR)/../manifest $(SRCDIR)/../VERSION >$(OBJDIR)/VERSION.h
   367    367   
   368    368   EXTRAOBJ =  $(OBJDIR)/sqlite3.o  $(OBJDIR)/shell.o  $(OBJDIR)/th.o  $(OBJDIR)/th_lang.o
   369    369   
   370    370   $(APPNAME):	$(OBJDIR)/headers $(OBJ) $(EXTRAOBJ) $(OBJDIR)/icon.o
   371    371   	$(TCC) -o $(APPNAME) $(OBJ) $(EXTRAOBJ) $(LIB) $(OBJDIR)/icon.o
   372    372   
   373    373   # This rule prevents make from using its default rules to try build
................................................................................
   968    968   $(OBJDIR)/zip.o:	$(OBJDIR)/zip_.c $(OBJDIR)/zip.h  $(SRCDIR)/config.h
   969    969   	$(XTCC) -o $(OBJDIR)/zip.o -c $(OBJDIR)/zip_.c
   970    970   
   971    971   zip.h:	$(OBJDIR)/headers
   972    972   $(OBJDIR)/sqlite3.o:	$(SRCDIR)/sqlite3.c
   973    973   	$(XTCC) -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_THREADSAFE=0 -DSQLITE_DEFAULT_FILE_FORMAT=4 -DSQLITE_ENABLE_STAT2 -Dlocaltime=fossil_localtime -DSQLITE_ENABLE_LOCKING_STYLE=0 -c $(SRCDIR)/sqlite3.c -o $(OBJDIR)/sqlite3.o
   974    974   
   975         -$(OBJDIR)/shell.o:	$(SRCDIR)/shell.c
          975  +$(OBJDIR)/shell.o:	$(SRCDIR)/shell.c $(SRCDIR)/sqlite3.h
   976    976   	$(XTCC) -Dmain=sqlite3_shell -DSQLITE_OMIT_LOAD_EXTENSION=1 -c $(SRCDIR)/shell.c -o $(OBJDIR)/shell.o
   977    977   
   978    978   $(OBJDIR)/th.o:	$(SRCDIR)/th.c
   979    979   	$(XTCC) -I$(SRCDIR) -c $(SRCDIR)/th.c -o $(OBJDIR)/th.o
   980    980   
   981    981   $(OBJDIR)/th_lang.o:	$(SRCDIR)/th_lang.c
   982    982   	$(XTCC) -I$(SRCDIR) -c $(SRCDIR)/th_lang.c -o $(OBJDIR)/th_lang.o
   983    983   

Changes to win/Makefile.msc.

    29     29   ZLIB    = zlib.lib
    30     30   
    31     31   INCL   = -I. -I$(SRCDIR) -I$B\win\include -I$(MSCDIR)\extra\include -I$(ZINCDIR)
    32     32   
    33     33   CFLAGS = -nologo -MT -O2
    34     34   BCC    = $(CC) $(CFLAGS)
    35     35   TCC    = $(CC) -c $(CFLAGS) $(MSCDEF) $(SSL) $(INCL)
    36         -LIBS   = $(ZLIB) ws2_32.lib $(SSLLIB)
           36  +LIBS   = $(ZLIB) ws2_32.lib advapi32.lib $(SSLLIB)
    37     37   LIBDIR = -LIBPATH:$(MSCDIR)\extra\lib -LIBPATH:$(ZLIBDIR)
    38     38   
    39     39   SQLITE_OPTIONS = /DSQLITE_OMIT_LOAD_EXTENSION=1 /DSQLITE_THREADSAFE=0 /DSQLITE_DEFAULT_FILE_FORMAT=4 /DSQLITE_ENABLE_STAT2 /Dlocaltime=fossil_localtime /DSQLITE_ENABLE_LOCKING_STYLE=0
    40     40   
    41     41   SRC   = add_.c allrepo_.c attach_.c bag_.c bisect_.c blob_.c branch_.c browse_.c captcha_.c cgi_.c checkin_.c checkout_.c clearsign_.c clone_.c comformat_.c configure_.c content_.c db_.c delta_.c deltacmd_.c descendants_.c diff_.c diffcmd_.c doc_.c encode_.c event_.c export_.c file_.c finfo_.c glob_.c graph_.c gzip_.c http_.c http_socket_.c http_ssl_.c http_transport_.c import_.c info_.c leaf_.c login_.c main_.c manifest_.c md5_.c merge_.c merge3_.c name_.c path_.c pivot_.c popen_.c pqueue_.c printf_.c rebuild_.c report_.c rss_.c schema_.c search_.c setup_.c sha1_.c shun_.c skins_.c sqlcmd_.c stash_.c stat_.c style_.c sync_.c tag_.c tar_.c th_main_.c timeline_.c tkt_.c tktsetup_.c undo_.c update_.c url_.c user_.c verify_.c vfile_.c wiki_.c wikiformat_.c winhttp_.c xfer_.c zip_.c 
    42     42   
    43     43   OBJ   = $(OX)\add$O $(OX)\allrepo$O $(OX)\attach$O $(OX)\bag$O $(OX)\bisect$O $(OX)\blob$O $(OX)\branch$O $(OX)\browse$O $(OX)\captcha$O $(OX)\cgi$O $(OX)\checkin$O $(OX)\checkout$O $(OX)\clearsign$O $(OX)\clone$O $(OX)\comformat$O $(OX)\configure$O $(OX)\content$O $(OX)\db$O $(OX)\delta$O $(OX)\deltacmd$O $(OX)\descendants$O $(OX)\diff$O $(OX)\diffcmd$O $(OX)\doc$O $(OX)\encode$O $(OX)\event$O $(OX)\export$O $(OX)\file$O $(OX)\finfo$O $(OX)\glob$O $(OX)\graph$O $(OX)\gzip$O $(OX)\http$O $(OX)\http_socket$O $(OX)\http_ssl$O $(OX)\http_transport$O $(OX)\import$O $(OX)\info$O $(OX)\leaf$O $(OX)\login$O $(OX)\main$O $(OX)\manifest$O $(OX)\md5$O $(OX)\merge$O $(OX)\merge3$O $(OX)\name$O $(OX)\path$O $(OX)\pivot$O $(OX)\popen$O $(OX)\pqueue$O $(OX)\printf$O $(OX)\rebuild$O $(OX)\report$O $(OX)\rss$O $(OX)\schema$O $(OX)\search$O $(OX)\setup$O $(OX)\sha1$O $(OX)\shun$O $(OX)\skins$O $(OX)\sqlcmd$O $(OX)\stash$O $(OX)\stat$O $(OX)\style$O $(OX)\sync$O $(OX)\tag$O $(OX)\tar$O $(OX)\th_main$O $(OX)\timeline$O $(OX)\tkt$O $(OX)\tktsetup$O $(OX)\undo$O $(OX)\update$O $(OX)\url$O $(OX)\user$O $(OX)\verify$O $(OX)\vfile$O $(OX)\wiki$O $(OX)\wikiformat$O $(OX)\winhttp$O $(OX)\xfer$O $(OX)\zip$O $(OX)\shell$O $(OX)\sqlite3$O $(OX)\th$O $(OX)\th_lang$O 
................................................................................
   151    151   
   152    152   makeheaders$E: $(SRCDIR)\makeheaders.c
   153    153   	$(BCC) $**
   154    154   
   155    155   mkindex$E: $(SRCDIR)\mkindex.c
   156    156   	$(BCC) $**
   157    157   
   158         -version$E: $B\src\mkversion.c
          158  +mkversion$E: $B\src\mkversion.c
   159    159   	$(BCC) $**
   160    160   
   161    161   $(OX)\shell$O : $(SRCDIR)\shell.c
   162    162   	$(TCC) /Fo$@ /Dmain=sqlite3_shell $(SQLITE_OPTIONS) -c $(SRCDIR)\shell.c
   163    163   
   164    164   $(OX)\sqlite3$O : $(SRCDIR)\sqlite3.c
   165    165   	$(TCC) /Fo$@ -c $(SQLITE_OPTIONS) $**
................................................................................
   166    166   
   167    167   $(OX)\th$O : $(SRCDIR)\th.c
   168    168   	$(TCC) /Fo$@ -c $**
   169    169   
   170    170   $(OX)\th_lang$O : $(SRCDIR)\th_lang.c
   171    171   	$(TCC) /Fo$@ -c $**
   172    172   
   173         -VERSION.h : version$E $B\manifest.uuid $B\manifest
          173  +VERSION.h : mkversion$E $B\manifest.uuid $B\manifest $B\VERSION
   174    174   	$** > $@
   175    175   
   176    176   page_index.h: mkindex$E $(SRC) 
   177    177   	$** > $@
   178    178   
   179    179   clean:
   180    180   	-del $(OX)\*.obj

Changes to www/build.wiki.

    31     31   <a href="http://www.fossil-scm.org/fossil/leaves">Leaves</a> link at
    32     32   the top of the page.</p></li>
    33     33   
    34     34   <li><p>Select a version of of fossil you want to download.  Click on its
    35     35   link.  Note that you must successfully log in as "anonymous" in step 1
    36     36   above in order to see the link to the detailed version information.</p></li>
    37     37   
    38         -<li><p>Finally, click on the
    39         -"Zip Archive" link.  This link will build a ZIP archive of the 
           38  +<li><p>Finally, click on one of the
           39  +"Zip Archive" or "Tarball" links, according to your preference.
           40  +These link will build a ZIP archive or a gzip-compressed tarball of the 
    40     41   complete source code and download it to your browser.
    41     42   </ol>
    42     43   
    43     44   <h2>2.0 Compiling</h2>
    44     45   
    45         -<p>Follow these steps to compile on a unix platform
    46         -(Linux, *BSD, MacOS, etc):</p>
    47         -
    48     46   <ol>
    49     47   <li value="6">
    50         -<p>Create a directory to hold the source code.  Then unzip the
    51         -ZIP archive you downloaded into that directory.  You should be
           48  +<p>Create a directory to hold the source code.  Then unarchive the
           49  +ZIP or tarball you downloaded into that directory.  You should be
    52     50   in the top-level folder of that directory</p></li>
    53     51   
    54     52   <li><p><b>(Optional:)</b>
    55     53   Edit the Makefile to set it up like you want.  You probably do not
    56     54   need to do anything.  Do not be intimidated:  There are less than 10
    57     55   variables in the makefile that can be changed.  The whole Makefile
    58     56   is only a few dozen lines long and most of those lines are comments.</p>
    59     57   
    60         -<li><p>Type "<b>make</b>"
           58  +<li><p>Run make to build the "fossil" or "fossil.exe" executable.  The
           59  +details depend on your platform and compiler:
           60  +
           61  +<ol type="a">
           62  +<li><p><i>Unix</i> &rarr; the default Makefile works on most unix and
           63  +unix-like systems.  Simply type "<b>make</b>".
           64  +
           65  +<li><p><i>Msys/MinGW</i> &rarr; Use the
           66  +mingw makefile: "<b>make -f win/Makefile.mingw</b>"
           67  +
           68  +<li><p><i>VC++</i> &rarr; Use the msc makefile.  First
           69  +change to the "win/" subdirectory ("<b>cd win</b>") then run
           70  +"<b>nmake /f Makefile.msc</b>".
           71  +</ol>
    61     72   </ol>
    62     73   
    63         -<p>To build on windows, use an alternative makefile suitable for your
    64         -particular build environment.  The alternative windows makefiles are
    65         -all found in the win/ subdirectory of the source tree.  So, for example,
    66         -if you want build using the 
    67         -[http://www.mingw.org/ | mingw/msys compiler package] for windows, then
    68         -run "<b>make -f win/Makefile.mingw</b>" instead of just "<b>make</b>"
    69         -in step 8 above.</p>
           74  +<p>Note that Fossil requires the "zlib" compression library.  This library
           75  +is available by default on most unix systems, but it will typically have to
           76  +be installed separately on windows systems.  For windows builds, you may
           77  +need to edit the makefile to tell it exactly where zlib is located on your
           78  +system.</p>
    70     79   
    71     80   <h2>3.0 Installing</h2>
    72     81   
    73     82   <ol>
    74     83   <li value="9">
    75     84   <p>The finished binary is named "fossil" (or "fossil.exe" on windows).  
    76     85   Put this binary in a 

Added www/changes.wiki.

            1  +<title>Change Log</title>
            2  +
            3  +<h2>Changes For Version 1.19 (pending)</h2>
            4  +
            5  +  *  Added a ./configure script based on autosetup.
            6  +  *  Added the "[/help/winsrv | fossil winsrv]" command
            7  +     for creating a Fossil service on windows systems.
            8  +
            9  +<h2>Changes For Version 1.18 (2011-07-14)</h2>
           10  +
           11  +  *  Added this Change Log
           12  +  *  Added sequential version numbering
           13  +  *  Added a optional configure script - the Makefile still works for most
           14  +     systems.
           15  +  *  Improvements to the "annotate" algorithm: only search primary
           16  +     ancestors and ignore branches.
           17  +  *  Update the "scrub" command to remove traces of login-groups and
           18  +     subrepositories.
           19  +  *  Added the --type option to the "fossil tag find" command.
           20  +  *  In contexts where only a check-in makes sense, resolve branch and
           21  +     tag names to checkins only, never events or other artifacts.
           22  +  *  Improved display of file renames on a diff.  A rebuild is required
           23  +     to take full advantage of this change.
           24  +  *  Update the built-in SQLite to version 3.7.7.

Changes to www/checkin.wiki.

     1         -<title>Checkin Checklist</title>
            1  +<title>Check-in Checklist</title>
     2      2   
     3         -Before every checkins:
            3  +<h2><u>Always</u> run the following checklist prior to <u>every</u>
            4  +check-in or commit to the Fossil repository:</h2>
     4      5   
     5         -  1.   <b>fossil diff</b> &rarr; no stray changes
            6  +Before every check-in:
            7  +
            8  +  1.   <b>fossil diff</b> &rarr;
            9  +       <ol type="a">
           10  +       <li> No stray changes
           11  +       <li> All changes comply with the license
           12  +       <li> All inputs are scrubbed before use
           13  +       <li> No injection attacks via %s formats
           14  +       </ol>
     6     15   
     7     16     2.   <b>fossil extra</b> &rarr; no unmanaged files need to be added.
     8     17   
     9         -  3.   The checkin will go onto the desired branch.
           18  +  3.   The check-in will go onto the desired branch.
           19  +       &rarr;  Do <u>not</u> check into trunk without prior approval from
           20  +       the lead programmer (drh)!
           21  +
           22  +  4.   auto-sync is on, or the system clock is verified
           23  +
           24  +  5.   If sources files have been added or removed, ensure all makefiles
           25  +       and configure scripts have been updated accordingly.
           26  +
           27  +Before every check-in to <b>trunk</b>:
           28  +
           29  +  6.   No compiler warnings on the development machine.
           30  +
           31  +  7.   The fossil executable that results from a build actually works.
           32  +
           33  +
           34  +<hr>
           35  +<h2>Commentary</h2>
           36  +
           37  +Item 1 is the most important step.  Consider using <b>gdiff</b>
           38  +instead of <b>diff</b> if you have a graphical differ configured.  Or,
           39  +pipe the output of "<b>fossil diff</b>" into "<b>open -f</b>" (on a mac) to
           40  +get the diff output in a separate text window for easier viewing.
           41  +Look carefully at every changed line in item 1.
           42  +Make sure that you are not about to commit unrelated changes.
           43  +If there are two or more unrelated changes present, consider
           44  +breaking up the commit into two or more separate commits.
           45  +Always make 100% sure that all changes are compatible with the
           46  +BSD license, that you have the authority to commit the code in accordance
           47  +with the [/doc/trunk/www/copyright-release.html | CLA] that you have
           48  +signed and have on file, and that
           49  +no NDAs, copyrights, patents, or trademarks are infringed by the check-in.
           50  +Also check very carefully to make sure that
           51  +you are not introducing security vulnerabilities.  Pay particular attention
           52  +to the possibility of SQL or HTML injection attacks.
           53  +
           54  +Item 2 verifies that you have not added source files but failed to
           55  +do the necessary "<b>fossil add</b>" to manage them.  If you commit
           56  +without bringing the new file under source control, the check-in will
           57  +be broken.  That, in turn, can cause complications far in the future
           58  +when we are bisecting for a bug.
           59  +
           60  +For item 3, Run "<b>fossil status</b>" or the equivalent to
           61  +make sure your changes are going into the branch you think they are.
           62  +Also double-check the branch name when entering change comments.
           63  +Never check into trunk unless you are expressly authorized to do so.
    10     64   
    11         -  4.   "Autosync" is enabled &rarr;
    12         -       <ol>
    13         -       <li> The checkin will not cause a unintentional fork.
    14         -       <li> The local system clock is set correctly.
    15         -       </ol>
           65  +For Item 4, if you are on-network, make sure auto-sync is enabled.  This
           66  +will minimize the risk of an unintended fork.  It will also give you a
           67  +warning if you system clock is set incorrectly.  If you are off-network,
           68  +make sure that your system clock is correct or at least close to correct
           69  +so that your check-in does not appear out-of-sequence on timelines.
           70  +On-network commits are preferred, especially for trunk commits.
    16     71   
    17         -Before every checkin to <b>trunk</b>:
    18         -
    19         -  5.   No compiler warnings on the development machine.
    20         -
    21         -  6.   Changes will not cause problems on a future <b>bisect</b>.
           72  +Items 6 and 7 help to ensure that check-ins on the trunk always work.
           73  +Knowing that the trunk always works makes bisecting much easier.  Items
           74  +6 and 7 are recommended for all check-ins, even those that are on a branch.
           75  +But they are especially important for trunk check-ins.  We desire that
           76  +all trunk check-ins work at all times.  Any experimental, unstable, or
           77  +questionable changes should go on a branch and be merged into trunk after
           78  +further testing.

Added www/foss-cklist.wiki.

            1  +<title>Checklist For Successful Open-Source Projects</title>
            2  +<nowiki>
            3  +
            4  +<p>This checklist is loosely derived from Tom "Spot" Callaway's Fail Score
            5  +blog post <a href="http://spot.livejournal.com/308370.html">
            6  +http://spot.livejournal.com/308370.html</a> (see also
            7  +<a href="http://www.theopensourceway.org/book/The_Open_Source_Way-How_to_tell_if_a_FLOSS_project_is_doomed_to_FAIL.html">[1]</a> and
            8  +<a href="https://www.theopensourceway.org/wiki/How_to_tell_if_a_FLOSS_project_is_doomed_to_FAIL">[2]</a>).
            9  +Tom's original post assigned point scores to the various elements and
           10  +by adding together the individual points, the reader is suppose to be able
           11  +to judge the likelihood that the project will fail.
           12  +The point scores, and the items on the list, clearly reflect Tom's
           13  +biases and are not necessarily those of the larger open-source community.
           14  +Nevertheless, the policy of the Fossil shall be to strive for a perfect
           15  +score.</p>
           16  +
           17  +<p>This checklist is an inversion of Tom's original post in that it strives to
           18  +say what the project should do in order to succeed rather than what it
           19  +should not do to avoid failure.  The point values are omitted.</p>
           20  +
           21  +<p>See also:
           22  +<ul>
           23  +<li><a href="http://offog.org/articles/packaging/">
           24  +http://offog.org/articles/packaging/</a>
           25  +<li>
           26  +<a href="http://www.gnu.org/prep/standards/standards.html#Managing-Releases">
           27  +http://www.gnu.org/prep/standards/standards.html#Managing-Releases</a>
           28  +</ul>
           29  +
           30  +<hr>
           31  +
           32  +<ol>
           33  +<li><p>The source code size is less than 100 MB, uncompressed.
           34  +
           35  +<li><p>The project uses a Version Control System (VCS).
           36  +<ol type="a">
           37  +<li>The VCS has a working web interface.
           38  +<li>There is documentation on how to use the VCS.
           39  +<li>The VCS is general-purpose, not something hacked together for this
           40  +    one project.
           41  +</ol>
           42  +
           43  +<li><p>The project comes with documentation on how to build from source
           44  +and that documentation is lucid, correct, and up-to-date.
           45  +
           46  +<li><p>The project is configurable using an autoconf-generated configure
           47  +script, or the equivalent, and does not require:
           48  +<ol type="a">
           49  +<li>Manually editing flat files
           50  +<li>Editing code header files
           51  +</ol>
           52  +
           53  +<li><p>The project should be buildable using commonly available and
           54  +       standard tools like "make".
           55  +
           56  +<li><p>The project does not depend on 3rd-party proprietary build tools.
           57  +
           58  +<li><p>The project is able to dynamically link against standard libraries
           59  +      such as zlib and libjpeg.
           60  +<ol type="a">
           61  +<li>The project does not ship with the sources to standard libraries.
           62  +    <i>(On the Fossil project, we will allow the SQLite library sources
           63  +    to be included in the source tree as long as a system-installed
           64  +    SQLite library can be used in its stead.)</i>
           65  +<li>The project does not use slightly modified versions of standard
           66  +    libraries.  Any required bug fixes in standard libraries are pushed
           67  +    back upstream.
           68  +</ol>
           69  +
           70  +
           71  +<li><p>"make install" works and can be configured to target any
           72  +       directory of the installer's choosing.
           73  +<ol type="a">
           74  +<li>The project contains no unconfigurable hard-coded pathnames like
           75  +    "/opt" or "/usr/local".
           76  +<li>After installation, the source tree can be moved or deleted and
           77  +    the application will continue working.
           78  +</ol>
           79  +
           80  +
           81  +<li><p>The source code uses only \n for line endings, not \r\n.
           82  +
           83  +<li><p>The code does not depend on any special compiler features or bugs.
           84  +
           85  +<li><p>The project has a mailing list and announces releases on
           86  +       the mailing list.
           87  +
           88  +<li><p>The project has a bug tracker.
           89  +
           90  +<li><p>The project has a website.
           91  +
           92  +<li><p>Release version numbers are in the traditional X.Y or X.Y.Z format.
           93  +
           94  +<li><p>Releases can be downloaded as tarball using 
           95  +       gzip or bzip2 compression.
           96  +
           97  +<li><p>Releases unpack into a versioned top-level directory.
           98  +       (ex:  "projectname-1.2.3/").
           99  +
          100  +<li><p>A statement of license appears at the top of every source code file
          101  +       and the complete text of the license is included in the source code
          102  +       tarball.
          103  +
          104  +<li><p>There are no incompatible licenses in the code.
          105  +
          106  +<li><p>The project has not been blithely proclaimed "public domain" without
          107  +having gone through the tedious and exacting legal steps to actually put it 
          108  +in the public domain.
          109  +
          110  +<li><p>There is an accurate change log in the code and on the website.
          111  +
          112  +<li><p>There is documentation in the code and on the website.
          113  +</ol>

Changes to www/index.wiki.

    18     18   <ul>
    19     19   <li> [http://www.fossil-scm.org/download.html | Download]
    20     20   <li> [./quickstart.wiki | Quick Start]
    21     21   <li> [./build.wiki | Install]
    22     22   <li> [../COPYRIGHT-BSD2.txt | License]
    23     23   <li> [/timeline | Recent changes]
    24     24   <li> [./faq.wiki |