Building Chez Scheme Version 9.5
Copyright 1984-2017 Cisco Systems, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

----------------------------------------------------------------------------

This directory contains the sources for Chez Scheme, plus boot and header
files for various supported machine types.

BASICS

Building and installing Chez Scheme on a recent version of Linux or OS X
is typically as simple as installing the prerequisites listed below and
running (Windows build instructions appear under the heading WINDOWS
later in this file):

./configure
sudo make install

This should not take more than a minute or so, after which the commands
'scheme' and 'petite' can be used to run Chez Scheme and Petite Chez
Scheme, while 'man scheme' and 'man petite' can be used to view the
manual pages.  Chez Scheme and Petite Chez Scheme are terminal-based
programs, not GUIs.  They both incorporate sophisticated command-line
editing reminiscent of tcsh but with support for expressions that span
multiple lines.

Prerequisites:

* GNU Make
* gcc
* Header files and libraries for ncurses
* Header files and libraries for X windows

DETAILS

The sources for Chez Scheme come in two parts:

* A set of Scheme source files found in the subdirectory s.  Compiling
  these produces the boot files petite.boot and scheme.boot, along with
  two header files, equates.h and scheme.h.

* A set of C source files found in the subdirectory c.  Compiling and
  linking these files produces the executable scheme (scheme.exe under
  Windows).  Compiling the C sources requires the two header files
  produced by compiling the Scheme sources.

Since the Scheme sources can be compiled only by a working version of
Chez Scheme, it's not actually possible to build Chez Scheme from source.
That's why the boot and header files are packaged with the sources.

'./configure' attempts to determine what type of machine it's on and,
if successful, creates several files and directories:

* The directory nanopass containing the Nanopass Infrastructure,
  retrieved from github.

* A make file, Makefile, in the root (top level) directory.

* A "workarea", or subdirectory named for the machine type (e.g.,
  a6le for nonthreaded 64-bit linux).  The workarea is a mirror of
  the root directory, with subdirectories named c, s, and so on.
  Compilation takes place in the workarea.

* Within the workarea, the files Makefile, Mf-install, and Mf-boot.

'./configure' supports various options, among which is --help, which
can be used to list the supported options.

The make file supports several targets:

'make' or 'make build'
  compiles and links the C sources to produce the executable, then
  bootstraps the Scheme sources.  Bootstrapping involves using the
  freshly built scheme executable along with the distributed boot files
  to compile the Scheme sources.  If the new boot files are equivalent
  to the old boot files, the system is bootstrapped.  Otherwise, the new
  boot files are used to create a newer set, and those are compared.
  If this succeeds, the system is bootstrapped.  Otherwise, the make
  fails.  This should not fail unless the distributed boot files are
  out of sync with the sources.

  To run Chez Scheme without installing, you need to tell the executable
  where to find the boot files.  This can be done via command-line
  arguments, e.g.:

    $W/bin/$M/scheme -b $W/boot/$M/petite.boot -b $W/boot/$M/scheme.boot

  or by setting the SCHEMEHEAPDIRS variable to point to the directory
  containing the boot files.  For example, in bash:

    SCHEMEHEAPDIRS=$W/boot/$M $W/bin/$M/scheme

  and in tcsh:

    setenv SCHEMEHEAPDIRS "$W/boot/$M"
    $W/bin/$M/scheme

  In all cases, $W should be replaced with the name of the workarea,
  and $M should be replaced with the machine type.  (Unless the default
  is overridden via an argument to ./configure, $W is the same as $M.)

'sudo make install'
  runs the build plus installs the resulting executable, boot files,
  example files, and manual pages.

'make test'
  runs the build plus runs a set of test programs in various different
  ways, e.g., with different compiler options.  It can take 30 minutes
  or more, depending on the speed of the machine.  It produces voluminous
  output, so it's best to redirect its stdout and stderr to a file.

  NB: A complete run does not imply no errors occurred.  To check for
  errors, look at the file $W/mats/summary, where $W is the name of the
  workarea created by ./configure.  $W/mats/summary should contain one
  line per test run, something like this:

  -------- o=0 --------
  -------- o=3 --------
  -------- o=0 cp0=t --------
  -------- o=3 cp0=t --------
  -------- o=0 spi=t p=t --------
  -------- o=3 spi=t p=t --------
  -------- o=0 eval=interpret --------
  -------- o=3 eval=interpret --------
  -------- o=0 cp0=t eval=interpret --------
  -------- o=3 cp0=t eval=interpret --------
  -------- o=0 ehc=t eoc=f --------
  -------- o=3 ehc=t eval=interpret --------

  If there is anything else in $W/mats/summary, something unexpected
  occurred.

'make bootfiles'
  runs the build plus uses the locally built system to recreate the
  distributed boot and header files for each supported machine type.
  It should be run whenever modifications made to the Scheme sources
  are to be committed to the source-code repository so that up-to-date
  boot and header files can be committed as well.  'make bootfiles'
  can take 5 minutes or more.

  'make bootfiles' builds boot files for each machine type for which
  a subdirectory exists in the top-level boot directory.  to build
  for a supported machine type that isn't built by default, simply
  add the appropriate subdirectory, i.e., 'mkdir boot/$M', where M
  is the machine type, before running 'make bootfiles'.  You can
  also run '(cd $W ; make -f Mf-boot $M.boot)', where W is the name
  of a built work area for the host machine type, to build just the
  boot files for machine-type M.

'make clean'
  removes binaries from the workarea.

'make distclean'
  removes nanopass, Makefile, and all workareas.

WINDOWS

Building Chez Scheme under 64-bit Windows with Cygwin or Bash/WSL
follows the instructions above, except that 'make install' is not
supported, and the 'OS' environment variable must be set to
'Windows_NT' on Bash/WSL (to indicate a build for Windows, as opposed
to a build for Linux on Windows):

env OS=Windows_NT ./configure
env OS=Windows_NT make

Prerequisites:

* Cygwin or Bash/WSL with bash, grep, make, sed, etc.
* Microsoft Visual Studio 2017 or 2015
* WiX Toolset (for making an install)

To run Chez Scheme or Petite Chez Scheme from a Windows command prompt,
set PATH:

set PATH=$W\bin\$M;%PATH%

again with $W and $M replaced with the workarea name and machine
type, and start Chez Scheme with the command "scheme" or Petite
Chez with the command "petite".

The executables are dynamically linked against the Microsoft Visual
C++ run-time library vcruntime140.dll. If you distribute the
executables to a different system, be sure to include the
redistributable run-time library.

Making an Install for Windows

cd wininstall
make workareas
make

This will create workareas and compile binaries for the a6nt, i3nt,
ta6nt, and ti3nt configurations and then include them in a single
Windows installer package Chez Scheme.msi. The package also includes
example files and the redistributable Microsoft Visual C++ run-time
libraries.

Testing under Windows

The iconv tests in mats/io.ms require that a 32-bit or 64-bit (as
appropriate) iconv.dll, libiconv.dll, or libiconv-2.dll implementing
GNU libiconv be located in $W\bin\$M or the path.  Windows sources for
libiconv can be found at:

http://gnuwin32.sourceforge.net/packages/libiconv.htm

An alternative that uses the Windows API can be found at:

https://github.com/win-iconv/win-iconv

If the DLL is not present, the iconv tests will fail.  No other tests
should be affected.

Unset the TZ environment variable before running the tests, because
the Cygwin values are incompatible with the Microsoft C Runtime
Library.

Use 'make test' described above to run the tests.
