# -*- coding: utf-8; mode: shell-script -*-
# Creation of the Makefile used for compiling CLISP
# Bruno Haible 1991-2003
# Sam Steingold 1999-2003

# Simple usage:
#        ./makemake [--with-PACKAGE] [debug] > Makefile

HSDEFAULT="http://www.lisp.org/HyperSpec/";
hyperspec=${CLHSROOT:-${HSDEFAULT}}

info_help () {
cat << EOP
Usage: ./makemake [options] [debug] > Makefile
options:
    The following general options are recognized:
       --help                  print this message and exit
       --version               print the CLISP version and exit
       --verbose               print some config information to the stderr
    The following options set installation parameters:
       --srcdir=SRCDIR         sets the source directory to SRCDIR
       --prefix=PREFIX         sets the installation directory prefix to PREFIX
       --exec-prefix=EXECPREFIX  sets the architecture dependent installation
                                  directory prefix to EXECPREFIX
       --fsstnd=std            installation according to FileSystem Standards:
                               suse - SuSE-Linux conventions
                               redhat - RedHat
                               debian - Debian, Slackware
                               *bsd - NetBSD, OpenBSD, FreeBSD
       --hyperspec=URL         the path to the Common Lisp HyperSpec
           (the default is ${HSDEFAULT}
            or the value of the environment variable CLHSROOT, if set).
    The following options add support for specific separate packages. See the
    main INSTALL file for how to get them.
       --with-noreadline       do not use readline library (even when present)
       --with-gettext          internationalization, needs GNU gettext
       --with-nogettext        static internationalization (en only)
       --without-unicode       no Unicode character set, only 8-bit characters
       --with-dynamic-ffi      a foreign language interface
       --with-dynamic-modules  dynamic loading of foreign language modules
       --with-threads=FLAVOR   MT [_experimental_!]
                               FLAVOR: POSIX_THREADS POSIXOLD_THREADS
                                       SOLARIS_THREADS C_THREADS WIN32_THREADS
       --with-module=bindings/amigaos
       --with-module=bindings/glibc
       --with-module=dirkey
       --with-module=postgresql
       --with-module=regexp
       --with-module=syscalls
       --with-module=wildcard
debug: Specify this if you expect that you will need to debug the sources.
Example:
       ./makemake --with-dynamic-ffi > Makefile
EOP
}

# Advanced usage:
#        ./makemake [--with-PACKAGE] TARGET COMPILER [debug] > Makefile
#  where PACKAGE is one of
#        noreadline       no readline library
#        gettext          internationalization, needs GNU gettext
#        nogettext        static internationalization (en only)
#        unicode          Unicode character set
#        dynamic-ffi      a dynamic foreign language interface
#        dynamic-modules  dynamic loading of foreign language modules
#        module=MODULE    an add-on module
#  where TARGET is one of
#        sun3
#        sun4
#        i386      (any other 386 machine, e.g. Linux boxes or Sun386i)
#        i486      (any other 486 machine)
#        mips
#        amiga     (Amiga 500/1000/2000 microcomputers)
#        acorn     (Acorn Archimedes running RiscOS)
#        os2       (PC or compatible running OS/2 2.0)
#  and COMPILER is one of
#        gcc       (GNU C under the name gcc)
#        cc        (any other ANSI C compliant cc)

# Examples:
#   makemake > Makefile
#   makemake debug > Makefile
#   makemake --with-noreadline debug > Makefile
#   makemake i386 gcc > make.gcc/makefile
#   makemake i486 gcc > make.gcc/makefile
#   makemake sun4 gcc > make.gcc/makefile
#   makemake amiga gcc > make.amiga/makefile
#   makemake acorn cc > make.acorn.cc/makefile
#   makemake acorn gcc > make.acorn.gcc/makefile
#   makemake os2 gcc > make.os2/makefile
#   makemake win32gcc gcc > make.win32gcc/makefile
#   makemake --with-dynamic-ffi win32msvc msvc4 > make.win32msvc/makefile.msvc4
#   makemake --with-dynamic-ffi win32msvc msvc5 > make.win32msvc/makefile.msvc5
#   makemake win32bc bcc32i > make.win32bc/makefile


# Fix the "echo" command. The SysV /bin/sh (and also ksh, and also bash if
# built with --enable-usg-echo-default, and also GNU sh-utils-1.16) are broken:
# They have an echo command which interprets backslashes in the string to be
# output. We cannot fix this by defining a function called "echo", because the
# HP/UX, OSF/1, AIX /bin/sh would nevertheless call the builtin, broken "echo".
# `echol' stands for "echo line".
if echo 'rs\tuv' | grep t > /dev/null 2> /dev/null; then
  # Uff. Found a BSD or POSIX compliant "echo" command.
  echol () {
    echo "$*"
  }
else
  if type printf >/dev/null 2>/dev/null; then
    # The "Single Unix Specification" (which also adheres to this broken
    # "echo") recommends the following workaround.
    echol () {
      printf '%s\n' "$*"
    }
  else
    # This one looks harmless, but in Solaris /bin/sh, when called inside
    # shell backquote `...`, it prefixes every character with a backslash!
    # Therefore we use this only as a last resort, if `printf' is missing
    # (for example, on OpenStep V4.2).
echol () {
cat <<ECHOVAL_END
$*
ECHOVAL_END
}
  fi
fi

link_dep() {
  echol "$1 : $2";
  echotab "-\$(LN_S) $2 $1";
  echol
}

# Handle --help and --version arguments.
for arg do
  case "$arg" in
    --help | --hel | --he | --h)
      info_help
      exit 0 ;;
    --version | --versio | --versi | --vers | --ver | --ve | --v)
      version="CLISP version "`cat ../src/VERSION`
      echol $version
      exit 0 ;;
  esac
done

# Save the argument list for reference.
makemake_args=''
for arg do
  # Approximate a shell-quote.
  case "$arg" in
    *" "* | *"	"* | *[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]* ) makemake_args="$makemake_args '$arg'" ;;
    * ) makemake_args="$makemake_args $arg" ;;
  esac
done
hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`

srcdir=''
prefix=''
exec_prefix=''
fsstnd=gnu_ext # supported styles: gnu, gnu_ext, suse, redhat, debian, *bsd
MODULES=''
CP='cp -p'
LN_S='ln -s'
HLN='ln'

# NLS nuisances.
# Needed e.g. for some versions of `tr' so that character classes in `[]' work.
if test "${LC_ALL+set}" = 'set'; then LC_ALL=C ; export LC_ALL ; fi
if test "${LANG+set}"   = 'set'; then LANG=C   ; export LANG   ; fi
if [ `echo ABC | tr '[A-Z]' '[a-z]'` = "abc" ] ; then
  tolower="tr '[A-Z]' '[a-z]'"
else
  tolower="tr A-Z a-z"
fi
my_eval(){
  eval "$*";
  if [ "${verbose}" = true -o "${verbose}" = yes ]; then echo "$*" >&2; fi
}

verbose=${CLISP_MAKEMAKE_VERBOSE:-false};
# Handle --with-... arguments
while test -z "$endofargs"; do
  case "$1" in
    -verb* | --verb* )
      verbose=`echol "$1"|sed 's/-*v[^=]*=*//'`;
      test -n "${verbose}" || verbose=true;
      shift
      ;;
    -with-module=* | --with-module=*)
      MODULES="$MODULES "`echol "$1"|sed 's/-*with-module=//'`
      shift
      ;;
    -without-* | --without-* | -with-no* | --with-no*)
      package=`echol "$1"|sed 's/-*with\(out-\|-no-*\)//'`
      # Delete all the valid chars; see if any are left.
      if test -n "`echol $package|sed 's/[-a-zA-Z0-9_]*//g'`"; then
        echol "makemake: $package: invalid package name" >&2; exit 1
      fi
      my_eval "with_`echol $package|sed s/-/_/g`=0"
      shift
      ;;
    -with-* | --with-*)
      package=`echol "$1"|sed 's/-*with-//'`
      packopt=`echol "${package}" | sed -e 's/^.*=\(.*\)$/\1/'`
      if test -z "${packopt}"; then packopt=1;
      elif [ "${packopt}" = "on" ];  then packopt=1;
      elif [ "${packopt}" = "off" ]; then packopt=0;
      elif [ "${packopt}" = "yes" ]; then packopt=1;
      elif [ "${packopt}" = "no" ];  then packopt=0;
      fi
      package=`echol "${package}" | sed -e 's/=.*//'`
      # Delete all the valid chars; see if any are left.
      if test -n "`echol $package|sed 's/[-a-zA-Z0-9_]*//g'`"; then
        echol "makemake: $package: invalid package name" >&2; exit 1
      fi
      my_eval "with_`echol $package|sed s/-/_/g`=${packopt}"
      shift
      ;;
    -srcdir* | --srcdir*)
      srcdir=`echol "$1" | sed 's/-*srcdir=*//'`
      shift
      if test -z "$srcdir" ; then
        srcdir=$1
        shift
      fi
      ;;
    -prefix* | --prefix*)
      prefix=`echol "$1" | sed 's/-*prefix=*//'`
      shift
      if test -z "$prefix" ; then
        prefix=$1
        shift
      fi
      ;;
    -exec-prefix* | --exec-prefix*)
      exec_prefix=`echol "$1" | sed 's/-*exec-prefix=*//'`
      shift
      if test -z "$exec_prefix" ; then
        exec_prefix=$1
        shift
      fi
      ;;
    --fsstnd=*)
      fsstnd=`echol "$1" | sed 's/-*fsstnd=//'`
      shift
      ;;
    --win32gcc) HSYS="win32gcc"; shift; ;;
    --hyperspec=*)
      arg=`echol "$1" | sed 's/-*hyperspec=//'`
      case "$arg" in
        */FrontMatter/index.html ) arg=`echo "$arg" | sed -e 's,/FrontMatter/index.html$,,'` ;;
        */FrontMatter/ )           arg=`echo "$arg" | sed -e 's,/FrontMatter/$,,'` ;;
        */FrontMatter )            arg=`echo "$arg" | sed -e 's,/FrontMatter$,,'` ;;
        */ )                       arg=`echo "$arg" | sed -e 's,/$,,'` ;;
        * ) ;;
      esac
      case "$arg" in
        *://*) hyperspec="$arg" ;;
        /*) if test -d "$arg" -a -d "$arg/FrontMatter" ; then
              hyperspec="file:${arg}"
            else
              echo "makemake: --hyperspec=${arg} argument ignored, does not point to the Common Lisp HyperSpec" 1>&2
            fi
            ;;
        *)  case "$arg" in
              file:*) arg=`echo "$arg" | sed -e 's,^file:,,'` ;;
            esac
            if test -d "$arg" -a -d "$arg/FrontMatter" ; then
              hyperspec="file:"`cd "$arg" > /dev/null && pwd`
            else
              echo "makemake: --hyperspec=${arg} argument ignored, does not point to the Common Lisp HyperSpec" 1>&2
            fi
            ;;
      esac
      shift
      ;;
    *) endofargs=1 ;;
  esac
done

if test -z "$srcdir" ; then
  # srcdir defaults to the value given at `makemake' construction time.
  if echol '@srcdir@' | grep '^@' > /dev/null ; then
    srcdir=.
  else
    srcdir='@srcdir@'
  fi
fi

# Remove trailing slash from hyperspec URL.
case "$hyperspec" in
  */) hyperspec=`echo "$hyperspec" | sed -e 's,/$,,'` ;;
esac

# HSYS, HSYSOS = host system
# HOS  = host operating system
# TSYS, TSYSOS = target system
# TOS  = target operating system
# CC, CFLAGS, CLFLAGS, CPP = compiler on host, for host
# XCC, XCFLAGS, XCLFLAGS, XCPP = cross-compiler on host, for target

case $# in
  0 | 1)
     # Assume we are on Unix (or win32gcc); target=host (not cross-compiling).
     CROSS=false
     if [ -z "$HSYS" ]; then # not win32gcc
       # some shells (A/UX and OSF/1) need the parentheses around "arch" below.
       HSYS=`((arch) 2>/dev/null || uname -m 2>/dev/null) | $tolower` # system name in lowercase
       HSYSOS=`((uname) 2>/dev/null || arch 2>/dev/null) | $tolower` # OS name in lowercase
       if [ "$HSYS" = 386bsd -o "$HSYS" = sun386 -o "$HSYS" = "386/at" -o "$HSYS" = i86pc ] ; then
         HSYS='i386'
       fi
       if [ "$HSYS" = sun4m ] ; then
         HSYS='sun4'
       fi
       case "$HSYSOS" in
         # Canonicalize cygwin32/nt and cygwin32/95 to plain cygwin32.
         cygwin*) HSYSOS=cygwin32 ;;
       esac
       HOS='unix'
       COMPILER=??
     else                       # win32gcc
       HSYSOS=$HSYS
       HOS=win32
       COMPILER=gcc
     fi
     TSYS="$HSYS"
     TSYSOS="$HSYSOS"
     TOS="$HOS"
     # These variables are set by configure:
     # srcdir='@srcdir@'                 # either '.' or '../src', see above
     CP='@CP@'                           # either 'cp -p' or 'cp'
     LN_S='@LN_S@'                       # either 'ln -s' or 'ln'
     HLN='@HLN@'                         # either 'ln' or 'hln'
     CC="@CC@"                           # either 'gcc -O' or 'cc'
     CPP="@CPP@"                         # either $CC' -E' or '/lib/cpp'
     CPPFLAGS='@CPPFLAGS@'               # additional options for $CC and $CPP
     CC_GCC='@CC_GCC@'                   # either true or false
     CC_NEED_CCPAUX='@CC_NEED_CCPAUX@'   # either true or false
     CC_NEED_DEEMA='@CC_NEED_DEEMA@'     # either true or false
     AS_UNDERSCORE='@AS_UNDERSCORE@'     # either true or false
     RANLIB='@RANLIB@'                   # either 'ranlib' or 'true'
     INSTALL='@INSTALL@'                 # either 'install -c' or 'cp'
     INSTALL_PROGRAM='@INSTALL_PROGRAM@' # either 'install -c' or 'cp'
     INSTALL_DATA='@INSTALL_DATA@'       # either 'install -c -m 644' or 'cp'
     GROFF='@GROFF@'                     # either 'groff' or ''
     GMALLOC='@GMALLOC@'                 # either 'gmalloc' or ''
     LIBS='@LIBS@'                       # list of system libraries
     LIBTERMCAP='@LIBTERMCAP@'           # either '-ltermcap' or '-lncurses'
     LIBICONV='@LIBICONV@'               # either '-liconv' or ''
     LIBSIGSEGV='@LTLIBSIGSEGV@'         # '-lsigsegv -L/usr/local/lib' or ''
     X_INCLUDES='@X_INCLUDES@'           # either '-I/usr/somewhere/include' or ''
     X_LIBS='@X_LIBS@'                   # either '-L/usr/somewhere/lib -lX11' or ''
     host='@host@'                       # something like 'sparc-sun-sunos4'
     host_cpu='@host_cpu@'               # something like 'sparc'
     host_vendor='@host_vendor@'         # something like 'sun'
     host_os='@host_os@'                 # something like 'sunos4'
     # Important: Don't rely on this host classification.
     # 1. GNU's database config.guess is not always up to date.
     # 2. New operating systems are emerging at every corner.
     # 3. People tend to change their systems locally.
     # Use this classification ONLY if we know no better way to check for a
     # feature or bug than to look at various `uname ...` results and list
     # the buggy systems explicitly. ONLY in this case!
     ;;
  *) if [ "$1" = cross ] ; then
       CROSS=true
       shift
       srcdir='../src'
     else
       CROSS=false
     fi
     TSYS=$1
     COMPILER=$2
     # TSYS should be (master|sun3|sun4|i[3456]86|mips|vax|amiga|acorn|os2|win32(msvc|bc)).
     # COMPILER should be gcc or cc
     if [ $TSYS = amiga -o $TSYS = acorn -o $TSYS = os2 ] ; then
       TOS=$TSYS
     else
       if [ $TSYS = win32msvc -o $TSYS = win32bc ] ; then
         TOS='win32'
       else
         TOS='unix'
       fi
     fi
     TSYSOS=$TSYS
     if [ $CROSS = true ] ; then
       HOS='unix'
       HSYS=irrelevant
       HSYSOS=irrelevant
     else
       HOS="$TOS"
       HSYS="$TSYS"
       HSYSOS="$TSYSOS"
     fi
     if [ $TSYS = win32msvc -o $TSYS = win32bc ] ; then
       if [ $TSYS = win32msvc ] ; then
         CC='cl'
         CC_GCC=false
         CFLAGS='$(MFLAGS)'
         CLFLAGS=''
         CC_NEED_CCPAUX=false
         AS_UNDERSCORE=false
         CC_NEED_DEEMA=false
       fi
       if [ $TSYS = win32bc ] ; then
         CC=$COMPILER # should be bcc32 or bcc32i
         CC_GCC=false
         # "-Od -v -R" means to compile for debugging.
         # "-O2" means to optimize.
         # "-g0" means not to treat 100 warnings as an error.
         CFLAGS='-O2 -g0 -w-rch'
         CLFLAGS=''
         CPP='cpp32 -P-' # buggy!
         CC_NEED_CCPAUX=false
         AS_UNDERSCORE=true
         CC_NEED_DEEMA=false
       fi
     else
       if [ $COMPILER = gcc ] ; then
         CC=gcc
         CC_GCC=true
       else
         CC=cc
         CC_GCC=false
       fi
       CFLAGS='-O'
       CLFLAGS=''
       CPP="${CC} -E"
       CPPFLAGS=''
       CC_NEED_CCPAUX=false
       if [ $COMPILER = gcc ] ; then
         # guess that if cross-compiling using gcc, then as preprends underscore
         AS_UNDERSCORE=true
       else
         AS_UNDERSCORE=false
       fi
       CC_NEED_DEEMA=false
     fi
     GROFF='groff'
     GMALLOC=''
     LIBS=''
     LIBICONV=''
     LIBSIGSEGV=''
     X_INCLUDES=''
     X_LIBS=''
     shift 2
     ;;
esac

if [ $CROSS = true ] ; then
  # We can cross-compile only with GCC 2
  XCC="gcc-${TSYS}"
  XCPP="${XCC} -E"
  XCPPFLAGS=''
  XCC_GCC=true
  XCC_NEED_CCPAUX=false
  XCC_NEED_DEEMA=false
else
  TSYS="$HSYS"
  TOS="$HOS"
  XCC="${CC}"
  XCPP="${CPP}"
  XCPPFLAGS="${CPPFLAGS}"
  XCC_GCC="${CC_GCC}"
  XCC_NEED_CCPAUX="${CC_NEED_CCPAUX}"
  XCC_NEED_DEEMA="${CC_NEED_DEEMA}"
fi
XCC_UNUSABLE_CPP=false

# DEBUGGING should be debug or nothing
DEBUGGING=$1

# now set appropriate MSVC cflags
if [ $TSYS = win32msvc ] ; then
  # -G5 means to optimize for i586.
  # "-Od -Z7" means to compile for debugging.
  # "-O1" means to optimize on msvc4,
  # "-Os -Oy -Ob1 -Gs -Gf -Gy" means to optimize on msvc5
  # ("-O1" and "-O2" are buggy in msvc5 ... msvc7).
  # -Zi - include debug info (-ZI for debug-and-continue)
  # -GZ - runtime debug checks
  case $COMPILER in
    msvc4) CFLAGS=${CFLAGS}" -G5 -O1"
      ;;
    msvc5 | msvc7)
      if [ "$DEBUGGING" != debug ] ; then
        CFLAGS=${CFLAGS}" -G5 -Os -Oy -Ob1 -Gs -Gf -Gy"
      else
        CFLAGS=${CFLAGS}" -Zi -Od -GZ"
      fi
      ;;
    *) echol "makemake: unknown compiler [${COMPILER}]" >&2; exit 1
      ;;
  esac
fi

if [ "$srcdir" = . ] ; then
  SRCDIR=''
else
  SRCDIR="${srcdir}/"
fi

# SRCTOPDIR is the parent directory of $srcdir, ending in a slash.
case "$srcdir" in
  *"/src" ) SRCTOPDIR=`echol "$srcdir" | sed -e 's,src$,,'` ;;
  "." )     SRCTOPDIR="../" ;;
  * )       SRCTOPDIR="$srcdir/../" ;;
esac
case "$SRCTOPDIR" in
  /*) PARENT_SRCTOPDIR="${SRCTOPDIR}" ;;
  *)  PARENT_SRCTOPDIR="../${SRCTOPDIR}" ;;
esac

TESTDIR=stage
TESTSDIR=suite
BENCHDIR=benchmarks

# Main host OS dependencies:

# DOS-style filenames and file utilities
H_DOS="false";
if [ $HOS = os2 ]; then H_DOS="true"; fi
if [ $HOS = win32 -a $HSYS != win32gcc ]; then H_DOS="true"; fi

# HEXE = extension for executable files on host
if [ $HOS = os2 -o $HOS = win32 ] ; then
  HEXE='.exe'
else
  HEXE=''
fi

# HERE = prefix to ensure that executables are looked up in current directory
if [ $HOS = unix ] ; then
  HERE='./'
else
  if [ $HOS = acorn ] ; then
    HERE='/@.'
  else
    HERE=''
  fi
fi

# PREFIX = prefix for installation directories
# (This should not end in a backslash. Add a space to avoid this.)
if [ $HOS = unix ] ; then
  if [ -n "$prefix" ] ; then
    PREFIX="${prefix}"
  else
    PREFIX='/usr/local'
  fi
else
  PREFIX=''
fi

# EXEC_PREFIX = prefix for architecture dependent installation directories
if [ -n "$exec_prefix" ] ; then
  EXEC_PREFIX="${exec_prefix}"
else
  EXEC_PREFIX='$(prefix)'
fi

# PARENT = piece of path for parent directory
# NEXT = piece of path for next subdirectory
# PARENT, NEXT: For interpretation by CLISP.
# PARENT_, NEXT_: For interpretation by the system's shell (called by make).
# PARENT_M, NEXT_M: For interpretation by the make program.
if [ $HOS = amiga ] ; then
  PARENT='/'
else
  if [ $HOS = acorn ] ; then
    PARENT='^.'
  else
    PARENT='../'
  fi
fi
if [ $HOS = acorn ] ; then
  NEXT='.'
else
  NEXT='/'
fi
if [ $H_DOS = "true" ] ; then
  # Replace '/' with '\':
  PARENT_=`echol $PARENT | sed -e 's,/,\\\\,g'`
  NEXT_=`echol $NEXT | sed -e 's,/,\\\\,g'`
else
  PARENT_=$PARENT
  NEXT_=$NEXT
fi
# Replace '\' with '\\':
#PARENT_2=`echol $PARENT_ | sed -e 's,\\\\,\\\\\\\\,g'`
if [ $HSYS = win32gcc ] ; then
  PARENT_M="$PARENT"
  NEXT_M="$NEXT"
else
  PARENT_M="$PARENT_"
  NEXT_M="$NEXT_"
fi
# maybe convert the cygwin cygdrive pathnames
if [ ${HSYS} != win32gcc ]; then PWDCMD='`pwd`';
else DEVPREFIX=`(cd c:; pwd | sed 's,^/\([a-z]*\)/.*,\1,')`;
  PWDCMD='`pwd|sed '"'s,^/${DEVPREFIX}/\\(.\\),\1:,'"'`';
fi
HERE_='`pwd`'"${NEXT_}"

if [ $H_DOS = "true" ] ; then
  # Replace '/' with '\':
  SRCTOPDIR_=`echol ${SRCTOPDIR} | sed -e 's,/,\\\\,g'`
  PARENT_SRCTOPDIR_=`echol ${PARENT_SRCTOPDIR} | sed -e 's,/,\\\\,g'`
else
  SRCTOPDIR_=$SRCTOPDIR
  PARENT_SRCTOPDIR_=${PARENT_SRCTOPDIR}
fi
if [ $HSYS = win32gcc ] ; then
  SRCTOPDIR_M="$SRCTOPDIR"
  PARENT_SRCTOPDIR_M="${PARENT_SRCTOPDIR}"
else
  SRCTOPDIR_M="$SRCTOPDIR_"
  PARENT_SRCTOPDIR_M="${PARENT_SRCTOPDIR_}"
fi
UTILDIR="${SRCTOPDIR}utils${NEXT}"
UTILDIR_="${SRCTOPDIR_}utils${NEXT_}"
UTILDIR_M="${SRCTOPDIR_M}utils${NEXT_M}"
DOCDIR="${SRCTOPDIR}doc${NEXT}"
DOCDIR_="${SRCTOPDIR_}doc${NEXT_}"
DOCDIR_M="${SRCTOPDIR_M}doc${NEXT_M}"
MODULESDIR="${SRCTOPDIR}modules${NEXT}"
MODULESDIR_="${SRCTOPDIR_}modules${NEXT_}"
MODULESDIR_M="${SRCTOPDIR_M}modules${NEXT_M}"

if [ $CROSS = false ] && [ $HSYS = win32msvc -o $HSYS = win32bc ] ; then
  NEXT_CC="$NEXT_"
  UTILDIR_CC="$UTILDIR_"
else
  NEXT_CC="$NEXT"
  UTILDIR_CC="$UTILDIR"
fi

# Some operating systems cripple filenames.
if [ $HOS = acorn ] ; then
  interpreted=interpre
  halfcompiled=halfcomp
  txt=text
else
  interpreted=interpreted
  halfcompiled=halfcompiled
  txt=txt
fi

# RM = command for deleting files; RMRF - recursively
if [ $H_DOS = "true" ] ; then
  RM='del /q'
  RMRF='del /q /s'
else
  if [ $HOS = acorn ] ; then
    RM='remove'
    RMRF='remove' # FIXME
  else
    RM='rm -f'
    RMRF='rm -rf'
  fi
fi

# CP = command for copying files
if [ $H_DOS = "true" ] ; then
  CP='copy'
else
  if [ $HOS = acorn ] ; then
    CP='cp ~A~CNF'
# else see above
  fi
fi

# LN_S = command for copying read-only files
if [ $H_DOS = "true" ] ; then
  LN_S='copy'
else
  if [ $HOS = acorn ] ; then
    LN_S='cp ~A~CNF'
# else see above
  fi
fi

# LN = command for making hard links ($HOS = unix only)
if [ "$HLN" = hln ] ; then
  HLN="${HERE}hln"
fi

# MV = command for renaming files
if [ $H_DOS = "true" ] ; then
  MV='ren'
else
  if [ $HOS = acorn ] ; then
    MV='cp ~A~CDF' # not 'rename' because rename does not overwrite
  else
    MV='mv'
  fi
fi

# CAT = command for typing files to stdout
if [ $H_DOS = "true" ] ; then
  CAT='type'
else
  CAT='cat'
fi

# TOUCH = command for pretending files are new
TOUCH='touch'

# GREP = command for filtering text according to regular expressions
if [ $HOS = acorn ] ; then
  GREP='egrep'
else
  GREP='grep'
fi

# RANLIB = command for finishing libraries
if [ -z "$RANLIB" ] ; then
  RANLIB='ranlib'
fi

# INSTALL = command for installing binaries/data
if [ -z "$INSTALL" ] ; then
  INSTALL=$CP
  INSTALL_PROGRAM='$(INSTALL)'
  INSTALL_DATA='$(INSTALL)'
fi

# Main target OS dependencies:

OS_INCLUDES=''
if [ $TSYS = master -o $TOS = unix ] ; then
  OS_INCLUDES=$OS_INCLUDES' unix'
  LIBS=$LIBS' '$LIBICONV' '$LIBSIGSEGV
fi
if [ $TSYS = master -o $TOS = amiga ] ; then
  OS_INCLUDES=$OS_INCLUDES' amiga'
fi
if [ $TSYS = master -o $TOS = acorn ] ; then
  OS_INCLUDES=$OS_INCLUDES' acorn'
fi
if [ $TSYS = master -o $TOS = os2 ] ; then
  OS_INCLUDES=$OS_INCLUDES' msdos'
  if [ $TSYS = os2 ] ; then
    LIBS=$LIBS' -ltermcap'
  fi
fi
SYSLIBS=''
if [ $TSYS = master -o $TOS = win32 ] ; then
  OS_INCLUDES=$OS_INCLUDES' win32'
  if [ $TSYS = win32gcc ] ; then
    # I don't know why advapi32 is not needed here.
    LIBS=$LIBS' -luser32 -lws2_32 -lole32 -luuid '$LIBSIGSEGV
  else
    if [ $TSYS = win32msvc ] ; then
      LIBS=$LIBS' user32.lib ws2_32.lib advapi32.lib'
    fi
    LIBS=$LIBS' ole32.lib shell32.lib'
    # With Borland C++, we must generate stub libraries for system DLLs
    # ourselves.
    if [ $TSYS = win32bc ] ; then
      SYSLIBS=' ole32.lib'
    fi
  fi
fi
if [ $TSYS = master -o $TOS = unix -o $TOS = win32 ] ; then
  OS_INCLUDES=$OS_INCLUDES' xthread'
fi

if [ $CROSS = true ] ; then
  if [ $TOS = os2 ] ; then
    # CHSCONVERT='$(HOME)/cc/convert-to-ibmpc'
    # CHSCONVERT='/usr/local/utils/cv-to-ibmpc'
    # CHSCONVERT='recode latin1:ibmpc | crlf-to-nl'
    CHSCONVERT='./cv_lt_pc'
  fi
fi

# TEXE = extension for executable files on target
# LEXE = extension for executable file LISP on target
if [ ${TOS} = os2 -o ${TOS} = win32 -o ${HSYSOS} = cygwin32 ] ; then
  TEXE='.exe'
  LEXE='.exe'
elif [ $TOS = acorn ] ; then
  TEXE=''
  LEXE=''
else
  TEXE=''
  LEXE='.run'
fi

# TOBJ = extension for compiled modules on target
if [ $TSYS = win32msvc -o $TSYS = win32bc ] ; then
  TOBJ='.obj'
else
  TOBJ='.o'
fi

# Main cpu dependencies:

cpu=''
if [ "$host_cpu" = m68k -o $TSYS = sun3 -o $TSYS = m68k -o $TSYS = mc68040 -o $TSYS = amiga ] ; then
# was: if [ "$host_cpu" = m68k -o $TSYS = sun3 -o $TSYS = hp300 -o $TSYS = m68k -o $TSYS = mc68040 -o $TSYS = amiga ] ; then
  cpu=m68k
fi
if [ "$host_cpu" = sparc -o $TSYS = sun4 ] ; then
  cpu=sparc
fi
if [ "$host_cpu" = sparc64 ] ; then
  cpu=sparc64
fi
case $TSYS in mips | r4000)
# was: case $TSYS in mips | ip* | sgi | risc | r4000)
  cpu=mips ;;
esac
if [ "$host_cpu" = mips ] ; then
  cpu=mips
fi
if [ "$host_cpu" = mips64 ] ; then
  cpu=mips64
fi
if [ "$host_cpu" = i386 -o "$host_cpu" = i486 -o "$host_cpu" = i586 -o "$host_cpu" = i686 -o $TSYS = i386 -o $TSYS = i486 -o $TSYS = i586 -o $TSYS = i686 -o $TSYS = os2 -o $TOS = win32 ] ; then
  cpu=i386
fi
case "$host_cpu" in
  hppa*) cpu=hppa ;;
  arm*)  cpu=arm  ;;
esac
# Probably obsolete.
# case $TSYS in 9000/7* | 9000/8* | hp7*)
#   # HP 9000 Series 700, 800
#   cpu=hppa ;;
# esac
if [ "$TSYS" = acorn ] ; then
  cpu=arm
fi

if [ "${verbose}" = true -o "${verbose}" = yes ]; then
  cat <<EOF >&2
# host system:
 hostname = "${hostname}"
     HSYS = "${HSYS}"
   HSYSOS = "${HSYSOS}"
      HOS = "${HOS}"
 host_cpu = "${host_cpu}"
      cpu = "${cpu}"
# target system:
     TSYS = "${TSYS}"
   TSYSOS = "${TSYSOS}"
      TOS = "${TOS}"
EOF
fi

# Main compiler dependencies:

if [ $XCC_GCC = true ] ; then
  XCC_GCC_VERSION=`$XCC -v 2>&1 | grep version | tail -1 | sed -e 's/.*version //g' -e 's/gcc //'`
  XCFLAGS='-W -Wswitch -Wcomment -Wpointer-arith -Wimplicit -Wreturn-type '
  if [ $HOS = os2 ] ; then
    # DOS has a very limited command line length
    XCFLAGS=''
  fi
  XCFLAGS="$XCPPFLAGS $XCFLAGS"
  if [ "$DEBUGGING" != debug ] ; then
    # We do not need a frame-pointer. Where we need it (in eval.d:
    # interpret_bytecode_()), we enforce it by using alloca().
    # On Windows, -fomit-frame-pointer may not be used in general (because
    # otherwise gcc might store data-pointers in %ebp, which is not admissible
    # because of incompatible segment registers). Fortunately, this is no
    # problem with rsxw32, because %cs = 0x185F,
    # %ds = %es = %fs = %gs = %ss = 0x1867, in particular %ds = %ss.
    XCFLAGS=$XCFLAGS' -fomit-frame-pointer'
  fi
  if [ $TSYS = amiga ] ; then
    # register A4 contains the stack.
    # The GCC-Strength-Reduction is not unproblematic on 68000.
    XCFLAGS=$XCFLAGS' -ffixed-a4 -fno-strength-reduce'
  fi
  if [ $TSYS = acorn ] ; then
    # Acorn/RISCOS specific gcc option??
    XCFLAGS=$XCFLAGS' -mthrowback'
  fi
  if [ $CROSS = false ] ; then
    case "$XCC_GCC_VERSION" in
      # gcc 2.7 introduced an annoying warning, but gcc 2.8 has a workaround:
      2.[8-9]* | 3.* | egcs-2.*)
        XCFLAGS=$XCFLAGS' -Wno-sign-compare'
        ;;
      * ) ;;
    esac
  fi
  if [ "${DEBUGGING}" != debug ] ; then # no optimizations
    if [ "$cpu" = i386 ] ; then
      # gcc <= 2.3.2 may crash when compiling lisparit with -O2
      # gcc 2.3.3 may produce incorrect code when compiling spvw(SPVW_PURE)
      # with -O -fomit-frame-pointer
      if [ $CROSS = false ] ; then
        case "$XCC_GCC_VERSION" in
          2.7.[0-2] )
            # gcc-2.7.2 has a strength-reduction bug (fixed in gcc-2.7.2.1,
            # also fixed through the specs file of some Linux distributions).
            XCFLAGS=$XCFLAGS' -O2 -fexpensive-optimizations -fno-strength-reduce' ;;
          2.3.[3-9]* | 2.[4-9]* | 3.* | egcs-2.*)
            # XCFLAGS=$XCFLAGS' -O2 -fno-omit-frame-pointer' ;;
            # Let's try it nevertheless!
            XCFLAGS=$XCFLAGS' -O2 -fexpensive-optimizations' ;;
          * )
            XCFLAGS=$XCFLAGS' -O' ;;
        esac
      else
        XCFLAGS=$XCFLAGS' -O'
      fi
    elif [ "$cpu" = hppa ] ; then
      # gcc-2.7.2 produces incorrect code when compiling spvw
      # (loadmem routine).
      XCFLAGS=$XCFLAGS' -O2 -fno-strength-reduce'
    elif [ "$cpu" = sparc ] ; then
      if [ $CROSS = false ] ; then
        case "$XCC_GCC_VERSION" in
          egcs-2.*)
            # egcs-1.0.3 and egcs-1.1.1 produce incorrect code when compiling
            # lisparit (function UDS_divide_).
            XCFLAGS=$XCFLAGS' -O2 -fno-schedule-insns' ;;
          2.9* | 3.*)
            # gcc-2.95 produces incorrect code when compiling predtype
            # (function C_coerce).
            XCFLAGS=$XCFLAGS' -O2 -fno-schedule-insns -fno-gcse' ;;
          * )
            XCFLAGS=$XCFLAGS' -O2' ;;
        esac
      else
        XCFLAGS=$XCFLAGS' -O2'
      fi
    else
      XCFLAGS=$XCFLAGS' -O2'
    fi
    # For platforms that use global register variables...
    case "$cpu" in
      m68k | i386 | sparc | sparc64 | hppa | m88k | arm | alpha* | convex | s390*)
        if [ $CROSS = false ] ; then
          case "$XCC_GCC_VERSION" in
            3.1*)
              # gcc-3.1 produces incorrect code when compiling record
              # (function C_make_instance).
              XCFLAGS=$XCFLAGS' -fno-gcse' ;;
          esac
        fi
        ;;
    esac
  else
    case "$XCC_GCC_VERSION" in
      3*) # on linux: C_CODE_ALIGNMENT is wrong. &EVAL-WHEN = 0x806D512
        XCFLAGS=$XCFLAGS' -falign-functions=4'
    esac
  fi # DEBUGGING
  if [ $TSYS = win32gcc ] ; then
    XCFLAGS=$XCFLAGS' -D_WIN32';
  fi
  if [ $TSYS = sun4 -o $TSYS = acorn ] ; then
    XCLFLAGS='-static'
  else
    XCLFLAGS=''
  fi
  # Override any "-x c++" options which may be present in $XCC or $XCFLAGS.
  XCLFLAGS=$XCLFLAGS' -x none'
  XCC_NOOPTFLAGS=' -O0'

  if [ "${with_threads}" = "POSIX_THREADS" ]; then
    XCFLAGS=${XCFLAGS}" -pthread";
  fi

else

  if [ "$TSYSOS" = aix -o "$TSYSOS" = ultrix -o $TSYS = win32msvc -o $TSYS = win32bc ] ; then
    # If one cannot use the default cc preprocessor: Use GNU cpp instead.
    # The Coherent386 cc preprocessor is not usable
    # 1. because of "macro expansion buffer overflow", 2. because it is an
    # ANSI like preprocessor (## and the like) in front of a K&R C compiler.
    # The AIX 4.2 xlc preprocessor is not usable because when avl.c is included
    # twice from spvw.d, the second inclusion produces no expansion at all.
    # The Ultrix cc preprocessor is not usable because it does not
    # expand the `alloc_FNDS_nocopy' macro in lisparit.
    # The MSVC4 preprocessor is not usable because of its treatment of empty
    # macro arguments.
    # The BC5 preprocessor is not usable because of a macro argument expansion
    # bug.
    XCC_UNUSABLE_CPP=true
    XCPP="${UTILDIR_}gcc-cccp${NEXT_}cccp -U__GNUC__"
    XCC_NEED_CCPAUX=false
    XCC_NEED_DEEMA=false
    XCPP_POSTPROCESS=""
    if [ "$TSYSOS" = aix ] ; then
      XCPP="$XCPP -D_AIX -D_IBMR2"
      # AIX 4.2 xlc doesn't like "#nnn" line number notes. Must filter them out.
      XCPP_POSTPROCESS=" | sed -e '/^#/d'"
    fi
    if [ "$TSYSOS" = ultrix ] ; then
      # Add some flags for the Ultrix include files.
      XCPP="$XCPP -traditional -P -Dunix -Dmips -Dultrix -D__mips -D__MIPSEB -D__LANGUAGE_C -D_CFE"
    fi
    if [ $TSYS = win32msvc ] ; then
      # -+ means to accept C++ comments in MSVC's include files.
      # _MSC_VER=1000 _M_IX86=500 means to simulate msvc4 on i586.
      # _MSC_VER=1100 _M_IX86=500 means to simulate msvc5 on i586.
      # _MSC_VER=1300 _M_IX86=500 means to simulate msvc7 (.NET) on i586.
      XCPP="$XCPP -+ -D_M_IX86=500 -D_WIN32 -I\$(MSVCDIR)/include"
      case ${COMPILER} in
        msvc4) XCPP="$XCPP -D_MSC_VER=1000"
          ;;
        msvc5) XCPP="$XCPP -D_MSC_VER=1100 -D_INTEGRAL_MAX_BITS=64"
          ;;
        msvc7) XCPP="$XCPP -D_MSC_VER=1300 -D_INTEGRAL_MAX_BITS=64 -I\$(MSVCDIR)/PlatformSDK/include"
          ;;
        *) echol "makemake: unknown compiler [${COMPILER}]" >&2; exit 1
          ;;
      esac
    fi
    if [ $TSYS = win32bc ] ; then
      # -+ means to accept C++ comments in BC's include files.
      # -D__BORLANDC__=0x460 -D__TURBOC__=0x460 -D_M_IX86=300 -D__WIN32__ -D__FLAT__ means to simulate BC5 on i386.
      XCPP="$XCPP -+ -D__BORLANDC__=0x460 -D__TURBOC__=0x460 -D_M_IX86=300 -D__WIN32__ -D__FLAT__ -I\$(BCDIR)/include"
    fi
  fi
  if [ $TSYS = sun4 -a $CROSS = false ] ; then
    # Detect SUNWspro C compiler.
    if $CC -flags 2> /dev/null | grep SunSoft > /dev/null ; then
      # SUNWspro cc, defines __SUNPRO_C
      XCC_SUNPRO=true
    fi
  fi
  if [ $TSYS = win32msvc -o $TSYS = win32bc ] ; then
    XCFLAGS="$CFLAGS"
  else
    if [ $TSYS = sun4 -a -n "$XCC_SUNPRO" ] ; then
      # SUNWspro cc flags:
      XCFLAGS='-xO3 -xstrconst'
    else
      if [ "$HSYSOS" = hp-ux -o $TSYS = sun4 -o $TSYS = acorn ] ; then
        # HP's HPPA compilers crash when optimizing.
        # SUN's cc is buggy when optimizing spvw.d, even with only -O1.
        # No -O for Acorn/Norcroft cc.
        XCFLAGS=''
      else
        XCFLAGS='-O'
      fi
    fi
  fi
  if [ "$TSYSOS" = ultrix ] ; then
    # Ultrix cc needs this for compiling spvw.d.
    XCFLAGS="$XCFLAGS -Olimit 1000"
  fi
  if [ $XCC_UNUSABLE_CPP = true ] ; then
    # GNU cpp has restricted command line flags. Pass them only to XCC.
    XCC="$XCC $XCFLAGS"
    XCFLAGS=''
  fi
  XCLFLAGS=''
  case $TSYS in mips | ip*)
    # IRIX 4 "cc -ansi" sometimes barfs when a string constant contains one
    # or more quotes('). They must be written as \047.
    ANSIDECLFLAGS="${ANSIDECLFLAGS} -DQUOTE_QUOTES"
    TXT2CFLAGS="${TXT2CFLAGS} -DQUOTE_QUOTES"
  esac
  if [ $TSYS = sun4 ] ; then
    XCFLAGS=$XCFLAGS' -dalign -fsingle'
    XCLFLAGS=$XCLFLAGS' -Bstatic'
  fi
  if [ $TSYS = acorn ] ; then
    XCFLAGS=$XCFLAGS' -D__arm -D__riscos -wanp -throwback -JUnix: -IUnix:'
  fi
  XCC_NOOPTFLAGS=''

fi

if test -n "$with_dynamic_modules"; then
  # Support for dynamic loading. Taken from libtool's ltconfig.in.
  if [ $XCC_GCC = true ] ; then
    XCC_LINKER_FLAG_PREFIX='-Wl,'
    case "$host_os" in
      irix5* | irix6*)
        # PIC is the default for these OSes.
        XCC_PICFLAG=''
        ;;
      *)
        XCC_PICFLAG='-fPIC'
        ;;
    esac
  else
    case "$host_os" in
      hpux9* | hpux10* | irix5* | irix6* | osf3* | osf4* | solaris2*)
        XCC_LINKER_FLAG_PREFIX='-Wl,'
        ;;
      sunos4*)
        XCC_LINKER_FLAG_PREFIX='-Qoption ld '
        ;;
      *)
        XCC_LINKER_FLAG_PREFIX=''
        ;;
    esac
    case "$host_os" in
      sco3.2v5*)
        XCC_PICFLAG='-Kpic'
        ;;
      solaris2*)
        XCC_PICFLAG='-KPIC'
        ;;
      sunos4*)
        XCC_PICFLAG='-PIC'
        ;;
    esac
  fi
  case "$cpu" in
    alpha | rs6000)
      # All code for these CPUs is position-independent.
      XCC_PICFLAG=''
      ;;
  esac
  # Support for creating a shared library. Taken from libtool's ltconfig.in,
  # much simplified: no support for weird systems like AIX, no support for
  # GNU ld on non-GNU systems, don't care about where we find ld.
  if ld -v 2>&1 < /dev/null | egrep '(GNU|with BFD)' > /dev/null ; then
    XCC_DLOPENABLE_EXE_FLAG="${XCC_LINKER_FLAG_PREFIX}-export-dynamic"
  else
    XCC_DLOPENABLE_EXE_FLAG=""
  fi
  XCC_CREATESHARED='create-shared-lib -o $lib $libs' # dummy command
  case "$host_os" in
    freebsd2.2*)
      XCC_CREATESHARED='ld -Bshareable -o $lib $libs /usr/lib/c++rt0.o'
      ;;
    freebsd2* | netbsd* | openbsd*)
      XCC_CREATESHARED='ld -Bshareable -o $lib $libs'
      ;;
    freebsd3* | gnu* | linux*)
      XCC_CREATESHARED='$CC $CFLAGS $CLFLAGS -shared -o $lib $libs'
      ;;
    hpux9* | hpux10*)
      XCC_CREATESHARED='ld -b +s -o $lib $libs'
      ;;
    irix5* | irix6*)
      case " $CC $CFLAGS " in
        *" -32 "*)  XCC_CREATESHARED='ld -32 -shared -o $lib $libs' ;;
        *" -n32 "*) XCC_CREATESHARED='ld -n32 -shared -o $lib $libs' ;;
        *" -64 "*)  XCC_CREATESHARED='ld -64 -shared -o $lib $libs' ;;
        *)          XCC_CREATESHARED='ld -shared -o $lib $libs' ;;
      esac
      ;;
    osf3* | osf4*)
      XCC_CREATESHARED='ld -shared -expect_unresolved -o $lib $libs -lc'
      ;;
    sco3.2v5*)
      XCC_CREATESHARED='ld -G -o $lib $libs'
      ;;
    solaris2*)
      XCC_CREATESHARED='ld -G -z text -o $lib $libs'
      ;;
    sunos4*)
      XCC_CREATESHARED='ld -assert pure-text -Bstatic -o $lib $libs'
      ;;
  esac
fi

if [ "$DEBUGGING" = debug ] ; then
  if [ $TSYS = sun4 -a $XCC_GCC = true ] ; then
    XCFLAGS=$XCFLAGS' -gstabs'
  elif [ ${HSYS} != "win32msvc" ]; then
    XCFLAGS=$XCFLAGS' -g'
  fi
  XCFLAGS=$XCFLAGS' -DDEBUG_OS_ERROR -DDEBUG_SPVW -DSAFETY=3';
  case "$CC" in
    *"g++"* ) XCFLAGS=$XCFLAGS' -DDEBUG_GCSAFETY -DNO_TYPECODES'; ;;
  esac
fi

if [ ${HSYSOS} = win32gcc -o ${HSYSOS} = cygwin32 ]; then
  # this is necessary for g++ to handle w32shell
  # <http://article.gmane.org/gmane.comp.gnu.mingw.user/8213>
  case "$CC" in *"g++"* ) XCFLAGS=$XCFLAGS' -DCINTERFACE'; ;; esac
fi

if [ $HSYS = acorn ] ; then
  CLFLAGS=$CLFLAGS' -LUnix:o.Unixlib'
fi
if [ $TSYS = acorn ] ; then
  XCLFLAGS=$XCLFLAGS' -LUnix:o.Unixlib'
fi

if [ "$cpu" = i386 -a "$TSYSOS" = "sinix-z" ] ; then # SINIX-Z V5.41
  XCFLAGS=$XCFLAGS' -DSNI -DSVR4' # maybe add -DUSL
fi
if [ "$cpu" = mips -a "$TSYSOS" = "sysv4" ] ; then # mips-sni-sysv4
  XCFLAGS=$XCFLAGS'' # maybe add -DUSL
fi
if [ "$cpu" = i386 -a "$TSYSOS" = "unix_sv" ] ; then # Onsite SVR4.2
  XCFLAGS=$XCFLAGS'' # maybe add -DUSL
fi
if [ "$cpu" = i386 -a "$TSYSOS" = "sunos" ] ; then # Solaris 2
  XCFLAGS=$XCFLAGS'' # maybe add -DUSL
fi
if [ "$cpu" = i386 -a "$TSYSOS" = linux -a $CROSS = false ] ; then # Linux
  # Generational GC requires Linux 1.1.52 or newer
  UNAME_R=`uname -r | $tolower`
  case "$UNAME_R" in
    0.* | 1.0.* | 1.1.[0-9] | 1.1.[1-4][0-9] | 1.1.5[0-1] )
      XCFLAGS=$XCFLAGS' -DNO_GENERATIONAL_GC' ;;
    *) ;;
  esac
fi

if [ $TSYS = sun4 -a $CROSS = false ] ; then
  ARCH_K=`(arch -k) 2>/dev/null || uname -m 2>/dev/null` # kernel architecture, see arch(1)
  if [ "$ARCH_K" = sun4 -o "$ARCH_K" = sun4c -o "$ARCH_K" = sun4e ] ; then
    # sun4, sun4c, sun4e support only 29 bit addresses,
    # sun4m supports 32 bit addresses.
    XCFLAGS=$XCFLAGS' -DSUN4_29'
  fi
fi
if [ "$cpu" = i386 -o $TSYS = sun4 ] && [ $CROSS = false ] ; then
  # Distinguish good SunOS 4 from the SunOS 5 garbage called "Solaris 2":
  case "$host_os" in
    solaris*)
      # We need a lot of libraries. To check which libraries are necessary, do
      #   % cd /usr/lib
      #   % foreach f (lib*.a)
      #   % echo $f ; nm $f | grep gethostbyname
      #   % end
      # We conclude that
      # - for gethostname() we need libnsl.a,
      # - for connect() and socket() we need libsocket.a,
      # - for these we need libdl_stubs.a and everything required by this one,
      # - a second pass through the libraries is needed to satisfy circular
      #   dependencies.
      if test -f /usr/lib/libdl_stubs.a; then
        LIBS=$LIBS' -lnsl -lsocket -ldl_stubs -lnswfiles -lnswnis -lnswnisplus -ltcpip -lswitch -lnswcompat -lstraddr -lintl'
        LIBS=$LIBS' -lnsl -lsocket -ldl_stubs -lnswfiles -lnswnis -lnswnisplus -ltcpip -lswitch -lnswcompat -lstraddr -lintl'
      else
        # Newer versions of Solaris (Solaris 2.2 and newer) don't have
        # libdl_stubs.a any more. This means that you cannot link -static !
        XCLFLAGS=`echol "$XCLFLAGS" | sed -e 's/-B*static//g'`
        SOLARIS_LINKING=1 # Even more hacks needed??
      fi
      BINARY_DISTRIB=1
    ;;
    hpux*)
      # Newer versions of HP-UX (HP-UX 10.20 and HP-UX 11) ship with no ANSI C
      # compiler, only with K&R "cc" whose only use may be to bootstrap gcc.
      BINARY_DISTRIB=1
    ;;
  esac
fi
if test -n "$BINARY_DISTRIB"; then
  XCFLAGS=$XCFLAGS' -DUNIX_BINARY_DISTRIB'
fi


# Other dependencies:

FILES=''

if [ "${with_unicode}" != "0" ]; then
  XCFLAGS="$XCFLAGS -DUNICODE"
fi
if [ -n "${with_threads}" -a "${with_threads}" != "0" ]; then
  XCFLAGS="$XCFLAGS -DMULTITHREAD -D${with_threads}"
fi

if [ "${with_termcap_ncurses}" = "0" -o "${LIBTERMCAP}" = "broken" ] ; then
  XCFLAGS=$XCFLAGS' -DNO_TERMCAP_NCURSES'
  LIBTERMCAP="";
fi

# the type of library naming
if [ ${HOS} = "win32" -a ${HSYS} != "win32gcc" ]; then
  LIB_TYPE="win32";             # foo.lib
else
  LIB_TYPE="unix";              # libfoo.a
fi

if test -n "$with_dynamic_ffi"; then
  XCFLAGS="$XCFLAGS -DDYNAMIC_FFI"
  if [ ${LIB_TYPE} = "win32" ] ; then
    XCL_FFILIBS='avcall.lib callback.lib'
  else
    XCL_FFILIBS='libavcall.a libcallback.a'
  fi
  LIBS=$XCL_FFILIBS' '$LIBS
  FILES=$XCL_FFILIBS' '$FILES
else
  XCL_FFILIBS=''
fi

if test -n "$with_dynamic_modules"; then
  XCFLAGS="$XCFLAGS -DDYNAMIC_MODULES"
fi

USE_LIBCHARSET=''
if [ $HOS = unix -o $HOS = win32 ] ; then
  USE_LIBCHARSET=yes
  if [ ${LIB_TYPE} = "unix" ] ; then
    # use symbolic link
    XCL_CHARSETLIB='libcharset.a'
    FILES='libcharset.a '$FILES
  fi
  if [ ${LIB_TYPE} = "win32" ] ; then
    XCL_CHARSETLIB='charset.lib'
  fi
  LIBS=$XCL_CHARSETLIB' '$LIBS
fi

if [ $TOS = unix -o $TOS = os2 ] ; then
  if [ "${with_readline}" = "0" ]; then
    XCFLAGS=$XCFLAGS' -DNO_READLINE'
  else
    FILES='libnoreadline.a '$FILES
    if [ "${with_readline}" != "" ]; then
      # --with-readline was supplied ==> barf when readline is missing
      if grep "#undef HAVE_READLINE" unixconf.h 2>&1 >/dev/null; then
        echol "makemake: configure failed to detect readline" >&2;
        exit 1;
      fi
    fi
  fi
fi

USE_GETTEXT=''
XCL_GETTEXTLIB=''
if [ $TOS = unix -o $TOS = os2 ] ; then
  if [ "${with_gettext}" = "0" ]; then
    XCFLAGS=$XCFLAGS' -DNO_GETTEXT'
  else
    if [ @USE_NLS@ = yes ] ; then
      USE_GETTEXT=yes
      LIBS='@LIBINTL@ '$LIBS
      XCL_GETTEXTLIB=$XCL_GETTEXTLIB' locale'
    else
      XCFLAGS=$XCFLAGS' -DNO_GETTEXT'
    fi
  fi
fi
if [ $TOS = win32 ] ; then
  XCFLAGS=$XCFLAGS' -DNO_GETTEXT'
fi

if test -z "$LIBSIGSEGV"; then
  XCFLAGS=$XCFLAGS' -DNO_SIGSEGV'
fi

FILES='lisp.a '$FILES

CPARTS='        spvw spvwtabf spvwtabs spvwtabo'
CPARTS=$CPARTS' eval control'
CPARTS=$CPARTS' encoding pathname stream'
if [ $TSYS = master -o $TOS = unix -o $TOS = win32 ] ; then
  CPARTS=$CPARTS' socket'
fi
CPARTS=$CPARTS' io'
CPARTS=$CPARTS' array hashtabl list package record sequence'
CPARTS=$CPARTS' charstrg debug error misc time predtype symbol lisparit i18n'
if [ $TSYS = master -o $TSYS = amiga ] ; then
  CPARTS=$CPARTS' rexx'
fi
if [ $TSYS = master -o -n "$with_dynamic_ffi" ] ; then
  CPARTS=$CPARTS' foreign'
fi
if [ $TSYS = master -o $TOS = unix -o $TSYS = os2 -o $TSYS = acorn ] ; then
  CPARTS=$CPARTS' unixaux'
fi
if [ $TSYS = master -o $TOS = win32 ] ; then
  CPARTS=$CPARTS' win32aux'
fi
if [ $TSYS = master -o $TOS = acorn ] ; then
  CPARTS=$CPARTS' acornaux acornsig'
fi
if [ -n "${with_threads}" -a "${with_threads}" != "0" ]; then
  CPARTS=$CPARTS' zthread';
fi

EVERY_INCLUDES='lispbibl fsubr subr pseudofun constsym constobj '$OS_INCLUDES

EVERY_INCLUDES_C=''
for f in $EVERY_INCLUDES ; do
  EVERY_INCLUDES_C=$EVERY_INCLUDES_C' '$f'.c'
done

EVERY_INCLUDES_H=''
if [ $TOS = unix ] ; then
  if [ -n '@STDBOOL_H@' -o -n '@STDINT_H@' ]; then
    EVERY_INCLUDES_H=${EVERY_INCLUDES_H}' @STDBOOL_H@ @STDINT_H@';
    XCFLAGS=${XCFLAGS}' -I.';
  fi
else
  EVERY_INCLUDES_H=$EVERY_INCLUDES_H' stdbool.h stdint.h'
  XCFLAGS=${XCFLAGS}' -I.';
fi
if [ -n "$USE_LIBCHARSET" ] ; then
  EVERY_INCLUDES_H=$EVERY_INCLUDES_H' libcharset.h'
fi

OTHER_INCLUDES=' constpack avl sort subrkw bytecode'
if [ $TSYS = master -o $TSYS = amiga ] ; then
  OTHER_INCLUDES=$OTHER_INCLUDES' amiga2'
fi

SPVW_INCLUDES=' spvw_module spvw_debug spvw_alloca spvw_mmap spvw_multimap spvw_singlemap spvw_page spvw_heap spvw_global spvw_gcstat spvw_space spvw_mark spvw_objsize spvw_update spvw_fault spvw_sigsegv spvw_sigcld spvw_sigpipe spvw_sigint spvw_sigwinch spvw_garcol spvw_genera1 spvw_genera2 spvw_genera3 spvw_allocate spvw_typealloc spvw_circ spvw_walk spvw_ctype spvw_language spvw_memfile'

UNICODE_INCLUDES=''
UNICODE_EXTRA='';
if [ "${with_unicode}" != "0" ] ; then
  UNICODE_INCLUDES=$UNICODE_INCLUDES' uni_upcase uni_downcase uni_attribute uniname'
  UNICODE_EXTRA=${UNICODE_EXTRA}' streq.h cjk.h uniwidth.h width.c unitypes.h uniname.h uninames.h';
fi

NLS_INCLUDES=''
if [ "${with_unicode}" != "0" ] ; then
  NLS_INCLUDES=$NLS_INCLUDES' nls_ascii'
  NLS_INCLUDES=$NLS_INCLUDES' nls_iso8859_1 nls_iso8859_2 nls_iso8859_3'
  NLS_INCLUDES=$NLS_INCLUDES' nls_iso8859_4 nls_iso8859_5 nls_iso8859_6'
  NLS_INCLUDES=$NLS_INCLUDES' nls_iso8859_7 nls_iso8859_8 nls_iso8859_9'
  NLS_INCLUDES=$NLS_INCLUDES' nls_iso8859_10 nls_iso8859_13 nls_iso8859_14'
  NLS_INCLUDES=$NLS_INCLUDES' nls_iso8859_15 nls_iso8859_16'
  NLS_INCLUDES=$NLS_INCLUDES' nls_koi8_r nls_koi8_u'
  NLS_INCLUDES=$NLS_INCLUDES' nls_mac_arabic nls_mac_centraleurope'
  NLS_INCLUDES=$NLS_INCLUDES' nls_mac_croatian nls_mac_cyrillic nls_mac_dingbat'
  NLS_INCLUDES=$NLS_INCLUDES' nls_mac_greek nls_mac_hebrew nls_mac_iceland'
  NLS_INCLUDES=$NLS_INCLUDES' nls_mac_roman nls_mac_romania nls_mac_symbol'
  NLS_INCLUDES=$NLS_INCLUDES' nls_mac_thai nls_mac_turkish nls_mac_ukraine'
  NLS_INCLUDES=$NLS_INCLUDES' nls_cp437_ms nls_cp437_ibm nls_cp737 nls_cp775'
  NLS_INCLUDES=$NLS_INCLUDES' nls_cp850 nls_cp852_ms nls_cp852_ibm nls_cp855'
  NLS_INCLUDES=$NLS_INCLUDES' nls_cp857 nls_cp860_ms nls_cp860_ibm nls_cp861_ms'
  NLS_INCLUDES=$NLS_INCLUDES' nls_cp861_ibm nls_cp862_ms nls_cp862_ibm'
  NLS_INCLUDES=$NLS_INCLUDES' nls_cp863_ms nls_cp863_ibm nls_cp864_ms'
  NLS_INCLUDES=$NLS_INCLUDES' nls_cp864_ibm nls_cp865_ms nls_cp865_ibm'
  NLS_INCLUDES=$NLS_INCLUDES' nls_cp866 nls_cp869_ms nls_cp869_ibm nls_cp874_ms'
  NLS_INCLUDES=$NLS_INCLUDES' nls_cp874_ibm'
  NLS_INCLUDES=$NLS_INCLUDES' nls_cp1250 nls_cp1251 nls_cp1252 nls_cp1253'
  NLS_INCLUDES=$NLS_INCLUDES' nls_cp1254 nls_cp1256 nls_cp1257'
  NLS_INCLUDES=$NLS_INCLUDES' nls_hp_roman8'
  NLS_INCLUDES=$NLS_INCLUDES' nls_nextstep'
  NLS_INCLUDES=$NLS_INCLUDES' nls_jisx0201'
fi

ERROR_INCLUDES=''
if [ $TSYS = master -o $TSYS = amiga ] ; then
  ERROR_INCLUDES=$ERROR_INCLUDES' erramiga'
fi
if [ $TSYS = master -o $TOS = unix -o $TSYS = os2 -o $TOS = acorn ] ; then
  ERROR_INCLUDES=$ERROR_INCLUDES' errunix'
fi
if [ $TSYS = master -o $TOS = win32 ] ; then
  ERROR_INCLUDES=$ERROR_INCLUDES' errwin32'
fi

LISPARIT_SUBFILES=' aridecl arilev0 arilev1 intelem intlog intplus intcomp intbyte intmal intdiv intgcd int2adic intsqrt intprint intread rational'
LISPARIT_SUBFILES=$LISPARIT_SUBFILES' sfloat ffloat dfloat lfloat flo_konv flo_rest realelem realrand realtran compelem comptran'
LISPARIT_INCLUDES=$LISPARIT_SUBFILES' arilev1c arilev1e arilev1i'

EXTRA_CPARTS='noreadline'

DFILES="$CPARTS $EVERY_INCLUDES $OTHER_INCLUDES $SPVW_INCLUDES $ERROR_INCLUDES $LISPARIT_INCLUDES genclisph modules $EXTRA_CPARTS"

ARI_ASMD=''
ARI_ASMC=''
ARI_ASMS=''
if [ "$cpu" = m68k ] ; then
  ARI_ASMD=$ARI_ASMD' ari68000 ari68020'
  if [ $TSYS = sun3 -o $TSYS = hp300 -o $TSYS = m68k -o $TSYS = mc68040 -o $TSYS = amiga -a "$TSYSOS" = netbsd ] ; then
    ARI_ASMS=$ARI_ASMS' ari68020'
  else
    ARI_ASMS=$ARI_ASMS' ari68000'
  fi
  ARI_ASMC=$ARI_ASMS
fi
if [ "$cpu" = sparc ] ; then
  ARI_ASMD=$ARI_ASMD' arisparc'
  ARI_ASMS=$ARI_ASMS' arisparc'
fi
if [ "$cpu" = sparc64 ] ; then
  ARI_ASMD=$ARI_ASMD' arisparc64'
  ARI_ASMS=$ARI_ASMS' arisparc64'
fi
if [ "$cpu" = mips ] ; then
  ARI_ASMD=$ARI_ASMD' arimips'
  ARI_ASMS=$ARI_ASMS' arimips'
fi
if [ "$cpu" = mips64 ] ; then
  ARI_ASMD=$ARI_ASMD' arimips64'
  ARI_ASMS=$ARI_ASMS' arimips64'
fi
if [ "$cpu" = i386 ] ; then
  if [ $TSYS != win32bc ] ; then
    ARI_ASMD=$ARI_ASMD' ari80386'
    ARI_ASMS=$ARI_ASMS' ari80386'
  fi
fi
if [ "$cpu" = hppa ] ; then
  ARI_ASMD=$ARI_ASMD' arihppa'
  ARI_ASMS=$ARI_ASMS' arihppa'
fi
if [ "$cpu" = arm ] ; then
  ARI_ASMD=$ARI_ASMD' ariarm'
  ARI_ASMS=$ARI_ASMS' ariarm'
fi

SP_ASMD=''
SP_ASMS=''
if [ $XCC_GCC = false ] ; then
  if [ "$cpu" = m68k ] ; then
    SP_ASMD=$SP_ASMD' sp68000'
    SP_ASMS=$SP_ASMS' sp68000'
  fi
  if [ "$cpu" = sparc -o "$cpu" = sparc64 ] ; then
    SP_ASMD=$SP_ASMD" sp${cpu}"
    SP_ASMS=$SP_ASMS" sp${cpu}"
  fi
  if [ "$cpu" = mips -o "$cpu" = mips64 ] ; then
    SP_ASMD=$SP_ASMD' spmips'
    SP_ASMS=$SP_ASMS' spmips'
  fi
  if [ "$cpu" = i386 ] ; then
    if [ $TSYS != win32bc ] ; then
      SP_ASMD=$SP_ASMD' sp80386'
      SP_ASMS=$SP_ASMS' sp80386'
    fi
  fi
fi

COMMENTS=''

LPARTS='        init defseq backquote defmacro macros1 macros2 defs1'
LPARTS=$LPARTS' timezone places floatprint type defstruct format international'
LPARTS=$LPARTS' savemem trace cmacros compiler defs2 loop clos'
LPARTS=$LPARTS' disassem condition loadform gstream xcharin keyboard'
LPARTS=$LPARTS' screen beossock runprog query reploop dribble complete'
LPARTS=$LPARTS' pprint describe room edit macros3 clhs inspect gray'
if [ -n "${with_threads}" -a "${with_threads}" != "0" ]; then
  LPARTS=$LPARTS' threads';
fi
if [ $TSYS = master -o -n "$with_dynamic_ffi" ] ; then
  LPARTS=$LPARTS' foreign1'
fi
LPARTS=$LPARTS' german'
if [ "$with_unicode" != "0" ] ; then
  LPARTS=$LPARTS' french spanish russian'
fi
LPARTS=$LPARTS' dutch deprecated config'

DOC='LISP-tutorial CLOS-guide editors'

TXT_FILES='README README.de README.es clisp.1 clisp.html clisp.c'
if [ $CROSS = false -a $HOS = unix ] ; then
  TXT_FILES=$TXT_FILES' distmakefile'
fi

OBSOLETE=''

# Output the makefile:

# echotab line
# outputs a line, preceding it with a tab. cat is needed to output tabs.
if [ $HSYS != win32msvc ] ; then
echotab () {
cat <<!!
	$1
!!
}
else
# Win32 "nmake" stupidly passes the command lines through `printf', thus
# interpreting % characters.
echotab () {
cmd=`echol "$1" | sed -e 's,%,%%,g'`
cat <<!!
	$cmd
!!
}
fi

# echotabpipe line
# outputs a line, split along pipe symbols, preceding with tabs.
if [ $HSYS != acorn -a $HSYS != win32bc ] ; then
echotabpipe() {
echotab "$1"
}
else
echotabpipe() {
line="$1"
junk=''
i=1
while
  linefirst=`echol "$line" | sed -e 's/|.*$//'`
  test "$linefirst" != "$line"
do
  linefirst=`echol "$linefirst" | sed -e 's/[ 	]*$//'`
  linerest=`echol "$line" | sed -e 's/^[^|]*|//' | sed -e 's/^[ 	]*//'`
  tempfile='TMPPIPE'"$i"
  echotab "$linefirst"" > $tempfile"
  if test -n "$junk"; then
    echotab "\$(RM) $junk"
  fi
  junk="$tempfile"
  i=`expr "$i" + 1`
  line=`echol "$linerest" | sed -e 's/[<>|].*$//' | sed -e 's/[ 	]*$//'`" < $tempfile "`echol "$linerest" | sed -e 's/^[^<>|]*//'`
done
echotab "$line"
if test -n "$junk"; then
  echotab "\$(RM) $junk"
fi
}
fi

# echolist prefix list suffix prefix
# outputs a list of items, prefixed by backslashes and newlines to break long
# lines.
echolist () {
line="$1"
suffix="$3"
prefix="$4"
for f in $2 ; do
  echol $line" \\"
  line="${prefix}${f}${suffix}"
done
echol $line
}

# echodummyrule target
# outputs a dummy rule for the given target.
if [ $HSYS != acorn ] ; then
case "$host_os" in
  aix*) # GNU make on AIX starts an interactive shell for every empty rule
echodummyrule () {
echotab "true"
}
  ;;
  *)
echodummyrule () {
:
}
  ;;
esac
else
echodummyrule () {
echotab "\$(TOUCH) $1"
}
fi

# echotab_mkdir_maybe dir
# make the directory if it is not there
echotab_mkdir_maybe () { echotab "test -d $1 || mkdir -p $1"; }

echol "# -*- Makefile -*- for the CLISP binaries"
echol "# DO NOT EDIT! GENERATED AUTOMATICALLY!"
echol "# This file was created on host $hostname as the output of the command:"
echol "# $0$makemake_args"
echol
echol '# -------------- Start of configurable section --------------------'
echol
if [ $TSYS = win32msvc ] ; then
  echol "# Flags that can be set on the nmake command line:"
  echol "#   MFLAGS={-ML|-MT|-MD} for defining the compilation model"
  echol "#     MFLAGS=-ML (the default)  Single-threaded, statically linked - libc.lib"
  echol "#     MFLAGS=-MT                Multi-threaded, statically linked  - libcmt.lib"
  echol "#     MFLAGS=-MD                Multi-threaded, dynamically linked - msvcrt.lib"
  echol '!if !defined(MFLAGS)'
  echol 'MFLAGS='
  echol '!endif'
  echol
fi
if [ ${TSYS} = win32gcc ]; then
  echol "PATH=/bin:."
  echol
fi
echol '# Directories used by "make install":'
echol "prefix = ${PREFIX}"
echol "exec_prefix = ${EXEC_PREFIX}"
echol "bindir  = \$(exec_prefix)${NEXT_}bin"
echol "shared  = \$(prefix)${NEXT_}share"
echol "mandir  = \$(prefix)${NEXT_}share${NEXT_}man"
echol "docdir  = \$(prefix)${NEXT_}share${NEXT_}doc"
case "$fsstnd" in
  suse)
    echol "lispdocdir = \$(docdir)${NEXT_}packages${NEXT_}clisp"
    ;;
  redhat)
    echol "lispdocdir = \$(docdir)${NEXT_}clisp-`cat ${SRCDIR}VERSION`"
    ;;
  debian | gnu_ext | *bsd)
    echol "lispdocdir = \$(docdir)${NEXT_}clisp"
    ;;
esac
echol "htmldir = \$(lispdocdir)"
echol "dvidir  = \$(lispdocdir)"
echol "psdir   = \$(lispdocdir)"
echol "libdir = \$(exec_prefix)${NEXT_}lib"
echol "lisplibdir = \$(libdir)${NEXT_}clisp"
if [ -n "$USE_GETTEXT" ] ; then
  echol "datadir = \$(prefix)/share"
  echol "localedir = \$(datadir)/locale"
fi
echol "# The value of following variable is prepended to all the paths for"
echol "# installation. This is useful when preparing a binary distribution."
echol "DESTDIR ="
echol
echol     "# List of add-on modules:"
echol     "# queens               the queens function as a separate module"
echol     "# dirkey               the directory access (LDAP, win32 registry)"
echol     "# syscalls             export some POSIX (and other) system calls"
if test -n "$with_dynamic_ffi"; then
  echol   "# wildcard             wildcard matching"
  echol   "# regexp               Unix-style regular expression matching and searching"
  echol   "# postgresql           interface to PostgreSQL ODBMS"
  if [ "$cpu" = i386 -a "$TSYSOS" = linux ] ; then
    echol "# bindings/glibc       Linux glibc bindings (GNU libc version 2)"
  fi
fi
if [ $TOS = unix -o $TOS = win32 ] ; then
  echol   "# clx/mit-clx          classical X11 interface"
fi
if [ $TOS = unix ] ; then
  echol   "# clx/new-clx          faster X11 interface (replaces clx/mit-clx)"
fi
echol '# If you change this after doing "make", you have to "rm -r full; make".'
echol "MODULES = ${MODULES} "`set | grep '^with_module_' | sed -e 's,^with_module_,,' -e 's,=.*$,,'`
echol
echol '# Programs used by "make":'
if [ $CROSS = true ] ; then
  echol "CC = ${CC}"
  echol "CFLAGS = ${CFLAGS}"
  echol "CLFLAGS = ${CLFLAGS}"
  echol "CPP = ${CPP}"
  echol "XCC = ${XCC}"
  echol "XCFLAGS = ${XCFLAGS}"
  echol "XCPP = ${XCPP}"
  echol "XCLFLAGS = ${XCLFLAGS}"
  echol "XLIBS = ${LIBS}"
  XCC="\$(XCC)"
  XCFLAGS="\$(XCFLAGS)"
  XCPP="\$(XCPP)"
  XCLFLAGS="\$(XCLFLAGS)"
  LIBS="\$(XLIBS)"
else
  echol "CC = ${XCC}"
  echol "CFLAGS = ${XCFLAGS}"
  echol "CPP = ${XCPP}"
  echol "CLFLAGS = ${XCLFLAGS}"
  echol "LIBS = ${LIBS}"
  XCC="\$(CC)"
  XCFLAGS="\$(CFLAGS)"
  XCPP="\$(CPP)"
  XCLFLAGS="\$(CLFLAGS)"
  LIBS="\$(LIBS)"
fi
echol "X_LIBS = ${X_LIBS}"
X_LIBS="\$(X_LIBS)"
if test -n "$with_dynamic_modules"; then
  echol 'MODULE_CFLAGS = $(CFLAGS) '"${XCC_PICFLAG}"
  echol 'MODULE_CLFLAGS = $(CLFLAGS) '"${XCC_DLOPENABLE_EXE_FLAG}"
  MODULE_CFLAGS_VAR='MODULE_CFLAGS'
  MODULE_CLFLAGS_VAR='MODULE_CLFLAGS'
  XCLFLAGS="\$(MODULE_CLFLAGS)"
else
  MODULE_CFLAGS_VAR='CFLAGS'
  MODULE_CLFLAGS_VAR='CLFLAGS'
fi
# if [ $TSYS = sun4 -a "$CC" = cc ] ; then
#   echol "INLINE = /usr/lib/inline"
# fi
if [ $HSYS = os2 ] ; then
  echol "LD = ld"
fi
if [ $HSYS = os2 ] ; then
  # Putting emx.exe allows one to get away with less installation problems.
  # Putting emxl.exe causes rsx.exe to be used if running under Windows.
  echol 'EMX = c:\emx\bin\emxl.exe'
fi
if [ $HSYS = win32msvc ] ; then
  if [ $COMPILER = msvc4 ] ; then
    echol "MSVCDIR = d:/msdev"
  fi
  if [ $COMPILER = msvc5 ] ; then
    echol "#MSVCDIR = d:/devstudio/vc"
    echol "#MSVCDIR = c:/msvs/vc98"
    echol "#MSVCDIR = \"C:/Program Files/Microsoft Visual Studio/VC98\""
  fi
fi
if [ $HSYS = win32bc ] ; then
  echol "BCDIR = d:/bc5"
  echol "WIN32DIR = c:\\winnt35\\system32"
fi
# echotab_to_HEXE command source target
# outputs a `make' statement that executes "command source" and creates
# target${HEXE}.
if [ $HSYS != win32msvc -a $HSYS != win32bc ] ; then
  echotab_to_HEXE () {
  echotab "$1 $2 -o $3${HEXE}"
  }
else
  if [ $HSYS = win32msvc ] ; then
    echotab_to_HEXE () {
    echotab "$1 $2 /Fe$3${HEXE}"
    }
  fi
  if [ $HSYS = win32bc ] ; then
    echotab_to_HEXE () {
    echotab "$1 -e$3${HEXE} $2"
    }
  fi
fi
if [ -n "$CHSCONVERT" ] ; then
  echol "CHARSETCONVERT = ${CHSCONVERT}"
  CHSCONVERT_FILTER=" | \$(CHARSETCONVERT)"
else
  CHSCONVERT_FILTER=''
fi
echol
if [ $HOS = win32 -a $HSYS != win32gcc ] ; then
  if [ $HSYS = win32msvc ] ; then
    echol "MAKE = nmake"
  else
    echol "MAKE = amake"
  fi
  echol "RM = -${RM}"
  echol "RMRF = -${RMRF}"
  echol "TOUCH = -${TOUCH}"
else
  echol "MAKE = ${MAKE:-make}"
  echol "RM = ${RM}"
  echol "RMRF = ${RMRF}"
  echol "TOUCH = ${TOUCH}"
fi
echol "CP = ${CP}"
echol "LN_S = ${LN_S}"
echol "MV = ${MV}"
echol "CAT = ${CAT}"
echol "GREP = ${GREP}"
if [ $HOS = acorn ] ; then
  echol "SED = sed"
fi
echol "AR = ar"
echol "RANLIB = ${RANLIB}"
echol
echol '# Programs used by "make install":'
echol "INSTALL = ${INSTALL}"
echol "INSTALL_PROGRAM = ${INSTALL_PROGRAM}"
echol "INSTALL_DATA = ${INSTALL_DATA}"
echol
echol '# Programs used by "make distrib":'
echol
# Auxiliary routines for linking lisp.a:
if [ $HOS = unix -a $XCC_GCC = true ] ; then
  # We need the full libgcc.a in general. But we don't know its location.
  LIBGCC='`'"${XCC} -print-libgcc-file-name"'` # something like /usr/somewhere/libgcc.a'
  if [ $CROSS = false ] ; then
    if [ "$HSYSOS" = linux -o "$HSYSOS" = beos -o "$HSYSOS" = cygwin32 ] ; then
      # gcc2 is cc on Linux, BeOS and Cygwin32. Don't need libgcc.a
      LIBGCC=''
    fi
  fi
else
  LIBGCC=''
fi
if test -n "$LIBGCC"; then
  echol "LIBGCC = ${LIBGCC}"
fi
if test -n "$GROFF"; then
  ROFF_MAN="$GROFF -Tascii -mandoc"
  ROFF_DVI="$GROFF -Tdvi -mandoc"
  ROFF_PS="$GROFF -Tps -mandoc"
else
  if [ $HSYS = acorn ] ; then
    ROFF_MAN="xfmt -m"
  else
    ROFF_MAN="nroff -man"
    if [ $HSYS = sun4 -a $CROSS = false ] ; then
      if [ "$UNAME_S" = sunos ] ; then
        case "$UNAME_R" in 4*)
          # SunOS 4
          ROFF_MAN="nroff -a -man" ;;
        esac
      fi
    fi
  fi
fi
echol '# formatter for manual page'
echol "ROFF_MAN = ${ROFF_MAN}"' # try "groff -Tascii -mandoc" or "nroff -man"'
if test -n "$GROFF"; then
  echol "ROFF_DVI = ${ROFF_DVI}"' # try "groff -Tdvi -mandoc"'
  echol "ROFF_PS  = ${ROFF_PS}"' # try "groff -Tps -mandoc"'
fi
echol
echol '# -------------- End of configurable section --------------------'
echol
cat <<\!!
#
#                       Requirements for add-on modules
#                       -------------------------------
#
# The general layout of add-on modules is described in ../doc/module.txt.
# The requirements made there (i.e. the existence of a "link.sh" file
# which defines certain variables) make sure that such an add-on module
# can be distributed with CLISP.
#
# If you want an add-on module to be _built_ automatically with CLISP,
# the following additional requirements have to be obeyed.
#
#   1. The module must be located in a subdirectory of clisp's source
#      directory.
#      Examples: clisp/src/ wildcard/
#                clisp/src/ bindings/glibc/
#
#   2. If the module contains a file called "configure", it is assumed
#      to be a GNU autoconf generated configuration file, and is called
#      with a "--cache-file=..." argument. It should generate platform
#      dependent header files, Makefiles and the like.
#
#   3. The module should contain a Makefile (maybe generated by requirement 2),
#      which defines the following targets:
#
#        clisp-module
#
#           This target builds the file mentioned by the link.sh file.
#           The following makefile variables can be used:
#             CC                 the C compiler used to compile the CLISP source
#             CFLAGS             the C compiler flags
#             INCLUDES           a directory containing CLISP header files
#             LISPBIBL_INCLUDES  if you #include "lispbibl.c", put this onto
#                                the dependency line
#             CLFLAGS            the C compiler flags when linking an executable
#             LIBS               the libraries used when linking an executable
#             RANLIB             the name of the "ranlib" command
#             CLISP              a command which calls the already built
#                                "base" clisp.
#           Typically, you will have rules like this in your Makefile:
#               foo.o : foo.c
#                       $(CC) $(CFLAGS) -I$(INCLUDES) -c foo.c
#               foo.fas : foo.lisp
#                       $(CLISP) -c foo.lisp
#
#        clisp-module-distrib
#
#           This target copies the module into a temporary distribution
#           directory, on the same disk.
#           The following makefile variables can be used:
#             distribdir       the name of temporary distribution directory
#             LN               command to make hard links (works also for
#                              symbolic links)
#           Typically, this target will look like this:
#
#               DISTRIBFILES = <the NEW_FILES mentioned in link.sh> <doc files>
#               clisp-module-distrib : clisp-module force
#                       $(LN) $(DISTRIBFILES) $(distribdir)
#
# If these requirements are obeyed, this Makefile will automatically build
# the add-on module and make it part of the "full" distribution -- all you
# need to do is to add its name to the MODULES definition line above.
#
!!
echol
if [ $HOS = unix ] ; then
  # On some systems (IRIX SVR3 and others) the default shell is csh.
  echol "SHELL = /bin/sh"
  echol
fi
echol "COMMENT5 = ${HERE}comment5"

if [ -n "$XCC_SUNPRO" ] ; then
  XASM_NEED_CCPAUX=true
else
  XASM_NEED_CCPAUX=$XCC_NEED_CCPAUX
fi

if [ $CC_NEED_CCPAUX = true -o $XCC_NEED_CCPAUX = true -o $XASM_NEED_CCPAUX = true ] ; then
  NEED_CCPAUX=true
else
  NEED_CCPAUX=false
fi
XDECL_FILTER="| \$(ANSIDECL) | \$(VARBRACE)"
XDECL_DEPENDENCIES=" ansidecl${HEXE} varbrace${HEXE}"

echol "ANSIDECL = ${HERE}ansidecl"
echol "VARBRACE = ${HERE}varbrace"
if [ $CC_NEED_CCPAUX = true ] ; then
  CCPAUX='ccpaux'$HEXE
  CCPAUX_FILTER=' | '$HERE'ccpaux'
else
  CCPAUX=''
  CCPAUX_FILTER=''
fi
if [ $XCC_NEED_CCPAUX = true ] ; then
  XCCPAUX='ccpaux'$HEXE
  XCCPAUX_FILTER=' | '$HERE'ccpaux'
else
  XCCPAUX=''
  XCCPAUX_FILTER=''
fi
if [ $XASM_NEED_CCPAUX = true ] ; then
  XASMCCPAUX='ccpaux'$HEXE
  XASMCCPAUX_FILTER=' | '$HERE'ccpaux'
else
  XASMCCPAUX=''
  XASMCCPAUX_FILTER=''
fi
if [ $XCC_NEED_DEEMA = true ] ; then
  if [ $HOS = unix ] ; then
    echol "DEEMA = sed -e 's/,)/,_EMA_)/g' -e 's/,,/,_EMA_,/g'"
  else
    echol "DEEMA = deema"
    XDECL_DEPENDENCIES="${XDECL_DEPENDENCIES} deema${HEXE}"
  fi
  XDECL_FILTER="${XDECL_FILTER} | \$(DEEMA)"
fi

if [ $TOS = unix ] ; then
  TXT2CINCL="-I'${SRCTOPDIR}'"
else
  TXT2CINCL="-I${SRCTOPDIR}"
fi
echol "TXT2C = ${HERE}txt2c ${TXT2CINCL}"
if [ $CROSS = true ] ; then
  TXT2CFLAGS="${TXT2CFLAGS} -DCROSS"
  TXT_INCLUDES=' lispbibl.h'
else
  TXT2CFLAGS="${TXT2CFLAGS}"
  TXT_INCLUDES="${EVERY_INCLUDES_C}${EVERY_INCLUDES_H}"
fi

echol

echolist "DFILES =" "$DFILES $ARI_ASMD $SP_ASMD" ".d"
echol

echolist "CFILES =" "$DFILES $ARI_ASMD $ARI_ASMC $SP_ASMD" ".c"
echol

echolist "OBJECTS =" "$CPARTS $ARI_ASMS $SP_ASMS $GMALLOC" "${TOBJ}"
echol

echolist "LISPFILES =" "$LPARTS" ".lisp"
echol

echolist "FASFILES =" "$LPARTS" ".fas"
echol

echolist "TXTFILES =" "$DOC" ".txt"
echol

echolist "TESTLISPFILES =" "$LPARTS" ".lisp" "${TESTDIR}${NEXT_M}"
echol
echolist "TESTFASFILES =" "$LPARTS" ".fas" "${TESTDIR}${NEXT_M}"
echol

echol

if [ $HOS = acorn ] ; then
  echol "# The Acorn Make Utility has problems with $halfcompiled.mem."
  echol "# If you have this problem, either swap $halfcompiled.mem and lispinit.mem in the next line, or use GNU make."
fi
needs="init allc allo lisp${LEXE} $interpreted.mem $halfcompiled.mem lispinit.mem manual"
if [ \( $HOS = unix -o ${HSYS} = win32gcc \) -a $CROSS = false ] ; then
  needs=".gdbinit "$needs' modular $(MODULES) base clisp full'
fi
echol "all : $needs"
echodummyrule all
echol

# development targets
echol "makemake : makemake.in config.status"
echotab "./config.status --file=makemake"
echol
echol "unixconf.h : unixconf.h.in config.status"
echotab "sh config.status --header=unixconf.h"
echol
echol "Makefile : makemake"
echotab "$0$makemake_args > Makefile.tmp"
echotab "\$(MV) Makefile Makefile~"
echotab "\$(MV) Makefile.tmp Makefile"
echol
echol "config.status : configure"
echotab "sh config.status --recheck"
echol
echol "${SRCDIR}VERSION : ${SRCDIR}version.h"
echotab "cd ${SRCTOPDIR_} && \$(MAKE) -f Makefile.devel src${NEXT_}VERSION"
echol
echol "${SRCDIR}configure : ${SRCDIR}configure.in"
echotab "cd ${SRCTOPDIR_} && \$(MAKE) -f Makefile.devel src${NEXT_}configure"
echol
if [ -n "${SRCDIR}" ] ; then
  for f in makemake.in unixconf.h.in configure VERSION; do
    echol "${f} : ${SRCDIR}${f}"
    echotab "-\$(RM) ${f}"
    echotab "-\$(LN_S) ${SRCDIR}${f} ${f}"
    echol
  done
fi


UTILS=''
if [ $NEED_CCPAUX = true ] ; then
  UTILS=$UTILS' ccpaux'
fi
UTILS=$UTILS' comment5'
UTILS=$UTILS' ansidecl'
UTILS=$UTILS' varbrace'
if [ $XCC_NEED_DEEMA = true -a $HOS != unix ] ; then
  UTILS=$UTILS' deema'
fi
UTILS=$UTILS' txt2c'
UTILS=$UTILS' ccmp2c' # needed by clx module
if [ "$CHSCONVERT" = "./cv_lt_at" ] ; then
  UTILS=$UTILS' cv_lt_at'
fi
if [ "$CHSCONVERT" = "./cv_lt_pc" ] ; then
  UTILS=$UTILS' cv_lt_pc'
fi
LUTILS=''
LUTILS=$LUTILS' modprep'

PARAMS="intparam floatparam";
PARAMS_H="";
line="init :"
for parf in ${PARAMS}; do
  if [ ${TOS} != win32 ] ; then
    line=$line" "${parf}.h;
  fi
  PARAMS_H=${PARAMS_H}" "${parf}.h;
done
if [ $XCC_UNUSABLE_CPP = true ] ; then
  line=$line" ${SRCTOPDIR}utils/gcc-cccp/cccp${HEXE}"
fi
if [ $CROSS = true ] ; then
  line=$line" unixconf.h"
fi
for util in ${UTILS} ;  do line=$line" ${util}${HEXE}"; done
for util in ${LUTILS} ; do line=$line" ${util}.fas"; done
line=$line" \$(DFILES) modules.h"
if [ -n "${SRCDIR}" ] ; then
  for f in $UNICODE_INCLUDES $NLS_INCLUDES ; do
    line=$line" ${f}.c"
  done
  line=$line${UNICODE_EXTRA}
fi
echol $line
if [ $HOS = unix -a $CROSS = false ] ; then
  echotab_mkdir_maybe "bindings"
else
  echodummyrule init
fi
echol
for parf in ${PARAMS}; do
  echol "${parf}.h : ${SRCDIR}${parf}.c unixconf.h"
  echotab "echo '#include \"unixconf.h\"' > tmp.c"
  echotab "cat '${SRCDIR}${parf}.c' >> tmp.c"
  echotab_to_HEXE "\$(CC)" "tmp.c" "${parf}"
  echotab "${HERE}${parf}${HEXE} > ${parf}.h"
  echotab "\$(RM) ${parf}${HEXE} tmp.c"
  echol
done
if [ $XCC_UNUSABLE_CPP = true ] ; then
  echol "${SRCTOPDIR}utils/gcc-cccp/cccp${HEXE} :"
  if [ $HOS = unix ] ; then
    if [ "$TSYSOS" = aix ] ; then
      echotab "cd ${SRCTOPDIR}utils/gcc-cccp && \$(MAKE) ALLOCA=alloca.o"
    else
      echotab "cd ${SRCTOPDIR}utils/gcc-cccp && \$(MAKE)"
    fi
  fi
  echol
fi
if [ $CROSS = true ] ; then
  echol "unixconf.h :"
  echotab "if [ ! -f unixconf.h ] ; then \$(TOUCH) unixconf.h ; fi"
  echol
fi
for util in ${UTILS} ; do
  case ${util} in
    ccpaux | deema | txt2c | ccmp2c )
      flags=''
      if [ $util = ccmp2c ] ; then flags=' -I.'; fi
      echol "${util}${HEXE} : ${UTILDIR_M}${util}.c"
      echotab_to_HEXE "\$(CC) \$(CFLAGS) \$(CLFLAGS) ${flags}" "${UTILDIR_CC}${util}.c" "${util}"
      echol ;;
    cv_lt_pc )  # Only used when $CROSS = true
      echol "${util}${HEXE} : ${SRCTOPDIR}os2/${util}.c"
      echotab_to_HEXE "\$(CC) \$(CFLAGS) \$(CLFLAGS)" "${SRCTOPDIR}os2/${util}.c" "${util}"
      echol ;;
    comment5 )
      if [ $CC_NEED_CCPAUX = true ] ; then
        echol "${util}${HEXE} : ${UTILDIR_M}${util}.c ${CCPAUX}"
        echotab "${HERE}ccpaux${HEXE} < ${UTILDIR_}${util}.c > ${util}.c"
        echotab_to_HEXE "\$(CC) \$(CFLAGS) \$(CLFLAGS)" "${util}.c" "${util}"
        echotab "\$(RM) ${util}.c"
        echol
        OBSOLETE=$OBSOLETE" ${util}.c"
      else
        echol "${util}${HEXE} : ${UTILDIR_M}${util}.c"
        if [ ${HSYS} = "win32gcc" ]; then
          # **HACK**: avoid -mno-cygwin so that comment5.exe
          #           understands symbolic links
          echotab_to_HEXE "gcc \$(CFLAGS) \$(CLFLAGS)" "${UTILDIR_CC}${util}.c" "${util}"
        else
          echotab_to_HEXE "\$(CC) \$(CFLAGS) \$(CLFLAGS)" "${UTILDIR_CC}${util}.c" "${util}"
        fi
        echol
      fi
      ;;
    ansidecl )
      flags="${ANSIDECLFLAGS}"
      echol "${util}${HEXE} : ${UTILDIR_M}${util}.d comment5${HEXE}"
      echotab "\$(LN_S) ${UTILDIR_}${util}.d ${util}.d"
      echotab "\$(COMMENT5) ${util}.d ${util}.c"
      echotab "\$(RM) ${util}.d"
      echotab_to_HEXE "\$(CC) \$(CFLAGS) \$(CLFLAGS)${flags}" "${util}.c" "${util}"
      echotab "\$(RM) ${util}.c"
      echol
      OBSOLETE=$OBSOLETE" ${util}.c" ;;
    varbrace )
      echol "${util}${HEXE} : ${UTILDIR_M}${util}.d comment5${HEXE} ansidecl${HEXE}"
      echotabpipe "\$(COMMENT5) ${UTILDIR_CC}${util}.d | \$(ANSIDECL) > ${util}.c"
      echotab_to_HEXE "\$(CC) \$(CFLAGS) \$(CLFLAGS)" "${util}.c" "${util}"
      echotab "\$(RM) ${util}.c"
      echol
      OBSOLETE=$OBSOLETE" ${util}.c" ;;
  esac
done

echol

echol "stdbool.h : ${SRCDIR}stdbool.h.in"
if [ $TOS = unix ] ; then
  echotab "sed -e 's/@''HAVE__BOOL''@/@HAVE__BOOL@/g' < ${SRCDIR}stdbool.h.in > stdbool.h"
else
  if [ $TSYS = win32msvc ] ; then
    echotab "sed -e \"s/@HAVE__BOOL@/0/g\" < ${SRCDIR}stdbool.h.in > stdbool.h"
  else
    echotab "sed -e 's/@''HAVE__BOOL''@/0/g' < ${SRCDIR}stdbool.h.in > stdbool.h"
  fi
fi
echol

echol "stdint.h : ${SRCDIR}stdint.h.in"
if [ $TOS = unix ] ; then
  echotab "sed -e 's/@''HAVE_LONG_64BIT''@/@HAVE_LONG_64BIT@/g' -e 's/@''HAVE_LONGLONG_64BIT''@/@HAVE_LONGLONG_64BIT@/g' < ${SRCDIR}stdint.h.in > stdint.h"
else
  if [ $TSYS = win32msvc ] ; then
    echotab "sed -e \"s/@HAVE_LONG_64BIT@/0/g\" -e \"s/@HAVE_LONGLONG_64BIT@/0/g\" < ${SRCDIR}stdint.h.in > stdint.h"
  else
    echotab "sed -e 's/@''HAVE_LONG_64BIT''@/0/g' -e 's/@''HAVE_LONGLONG_64BIT''@/0/g' < ${SRCDIR}stdint.h.in > stdint.h"
  fi
fi
echol

if [ -n "${SRCDIR}" ] ; then
  if [ ${HOS} = unix -o ${HSYS} = win32gcc ] ; then
    for f in $DFILES $ARI_ASMD $SP_ASMD ; do
      link_dep "${f}.d" "${SRCDIR}${f}.d"
    done
    for f in $UNICODE_INCLUDES $NLS_INCLUDES w32shell; do
      link_dep "${f}.c" "${SRCDIR}${f}.c"
    done
    for f in ${UNICODE_EXTRA} version.h modules.h ; do
      link_dep "${f}" "${SRCDIR}${f}"
    done
    echol
  fi
fi

echol "allc : init \$(CFILES)"
echodummyrule allc
echol

for f in $DFILES ; do
  echol "${f}.c : ${f}.d comment5${HEXE}${XDECL_DEPENDENCIES}"
  echotabpipe "\$(COMMENT5) ${f}.d${CHSCONVERT_FILTER} ${XDECL_FILTER} > ${f}.c"
  echol
done

for f in $ARI_ASMD $SP_ASMD ; do
  echol "${f}.c : ${f}.d comment5${HEXE} ${XCCPAUX}"
  echotabpipe "\$(COMMENT5) ${f}.d${XASMCCPAUX_FILTER} > ${f}.c"
  echol
done

if [ $TSYS != win32msvc ] ; then
  if [ $AS_UNDERSCORE = true ] ; then
    ASMFLAGS=' -DASM_UNDERSCORE'
  else
    ASMFLAGS=''
  fi
  if [ -n "$XCC_SUNPRO" ] ; then
    # SUNPRO cc preprocessor does too much checking in ANSI C mode, choose K&R mode
    ASMFLAGS="$ASMFLAGS"' -Xs'
  fi
  if [ $XCC_GCC = false -a $HOS != acorn ] ; then
    # Remove the line number information etc. and convert "% ecx" back to "%ecx"
    # and ". align" to ".align" and ". Lxxx" to ".Lxxx":
    ASM_FILTER=" | \$(GREP) -v '^#' | \$(GREP) -v '^ *#line' | sed -e 's,% ,%,g' -e 's,\\. ,.,g'"
  else
    if [ $HOS = acorn ] ; then
      ASM_FILTER=" | \$(SED) -f ${PARENT}acorn${NEXT}asmfilter.sed"
    else
      if [ $AS_UNDERSCORE = false ] ; then
        # These are the less modern assemblers or SYSV assemblers.
        # Remove the line number information etc.
        ASM_FILTER=" | \$(GREP) -v '^#'"
      else
        ASM_FILTER=''
      fi
      if [ "$cpu" = m68k ] ; then
        # SunOS 4.0 "as" doesn't understand ! comments.
        ASM_FILTER="$ASM_FILTER | sed -e 's,!.*\$\$,,'"
      fi
    fi
  fi
  for f in $ARI_ASMS $SP_ASMS ; do
    # The preprocessor barfs on arihppa: "unterminated character constant".
    # We ignore this:
    case $f in
      *hppa) g='-' ;;
      *)     g='' ;;
    esac
    # In ari68020.d the dollars must be replaced, and \# replaced with # :
    case $f in
      ari68020*)
        if [ $AS_UNDERSCORE = false ] ; then
          h=' | sed -e '"'"'s/\\#/#/g'"'"' -e '"'"'s/\$$/%/g'"'"
        else
          h=' | sed -e '"'"'s/\\#/#/g'"'"' -e '"'"'s/\$$//g'"'"
        fi
        ;;
      *) h='' ;;
    esac
    echol "${f}.s : ${f}.c"
    echotabpipe "${g}${XCPP}${ASMFLAGS} ${f}.c${h}${ASM_FILTER} > ${f}.s"
    echol
  done
fi

if [ -n "$with_dynamic_ffi" -a $HOS = unix ] ; then
  echol "trampoline${NEXT}trampoline.h :"
  echotab "cd trampoline && \$(MAKE) && \$(MAKE) check"
  echol
fi

line="allo : allc"
for f in $CPARTS ; do
  line=$line" ${f}${TOBJ}"
done
echol $line
echodummyrule allo
echol

line="alls : allc"
for f in $CPARTS ; do
  line=$line" ${f}.s"
done
echol $line
echodummyrule alls
echol

echol "# Normally not used (just for debugging)."
line="alli : allc"
for f in $CPARTS ; do
  line=$line" ${f}.i"
done
echol $line
echodummyrule alli
echol

for f in $CPARTS genclisph modules $EXTRA_CPARTS ; do
  depends=$EVERY_INCLUDES
  dependsc=''
  if [ $f = spvw -o $f = package ] ; then
    depends=$depends' constpack'
  fi
  if [ $f = spvw -o $f = predtype ] ; then
    depends=$depends' avl'
  fi
  if [ $f = spvw ] ; then
    depends=$depends''$SPVW_INCLUDES' sort subrkw'
  fi
  if [ $f = eval ] ; then
    depends=$depends' bytecode'
  fi
  if [ $f = array -o $f = hashtabl -o $f = io -o $f = time -o $f = package -o $f = spvw -o $f = stream -o $f = foreign ] ; then
    depends=$depends' arilev0'
  fi
  if [ $f = spvw -o $f = hashtabl ] ; then
    depends=$depends' aridecl'
  fi
  if [ $f = charstrg -a "${with_unicode}" != "0" ] ; then
    depends=$depends${UNICODE_INCLUDES}
    dependsc=${dependsc}${UNICODE_EXTRA};
  fi
  if [ $f = encoding ] ; then
    depends=$depends''$NLS_INCLUDES
  fi
  if [ $f = error ] ; then
    depends=$depends''$ERROR_INCLUDES
  fi
  if [ $f = lisparit ] ; then
    depends=$depends''$LISPARIT_INCLUDES''$ARI_ASMS
  fi
  if [ $f = rexx ] ; then
    depends=$depends' amiga2'
  fi
  for g in $depends ; do
    dependsc=$dependsc' '$g'.c'
  done
  dependsc=$dependsc''$EVERY_INCLUDES_H
  if [ $f = spvw ] ; then
    dependsc=$dependsc' version.h'
  fi
  if [ $f = encoding ] ; then
    dependsc=$dependsc' libcharset.h'
  fi
  if [ $f = foreign ] ; then
    dependsc=$dependsc' avcall.h callback.h'
  fi
  if [ $f = pathname -a ${TOS} = win32 ]; then
    dependsc=$dependsc' w32shell.c'
  fi
  flags=$XCFLAGS
  if [ $f = foreign ] ; then
    if [ $HOS = win32 ] ; then
      flags=$flags" -I${SRCTOPDIR}ffcall"
    fi
  fi
  if [ $f = modules ] ; then
    if [ $HOS = unix -a $CROSS = true ] ; then
      dependsc=$dependsc' clisp.h'
    else
      flags=$flags' -DNO_CLISP_H'
    fi
    dependsc=$dependsc' modules.h'
  fi
  flags2=$flags
  if [ $f = genclisph -a $XCC_GCC = true ] ; then
    flags2=$flags2' -O0' # no need to optimize this
  fi
  echol "${f}.i : ${f}.c${dependsc}"
  echotab "${XCPP} ${flags} ${f}.c > ${f}.i"
  echol
  if [ $XCC_UNUSABLE_CPP = true ] ; then
    if [ $HSYS = win32msvc -o $HSYS = win32bc ] ; then
      echol "${f}.s : ${f}.c${dependsc}"
      echotab "${XCPP} ${flags} ${f}.c > ${f}.i.c"
      echotab "${XCC} ${flags2} -c ${f}.i.c /FAs /Fa${f}.s"
      echotab "\$(RM) ${f}.i${TOBJ}"
      echotab "\$(RM) ${f}.i.c"
      echol
      echol "${f}${TOBJ} : ${f}.c${dependsc}"
      echotab "${XCPP} ${flags} ${f}.c > ${f}.i.c"
      echotab "${XCC} ${flags2} -c ${f}.i.c"
      echotab "\$(RM) ${f}${TOBJ}"
      echotab "\$(MV) ${f}.i${TOBJ} ${f}${TOBJ}"
      echotab "\$(RM) ${f}.i.c"
      echol
    else
      echol "${f}.s : ${f}.c${dependsc}"
      echotab "${XCPP} ${flags} ${f}.c${XCPP_POSTPROCESS} > ${f}.i.c"
      echotab "${XCC} ${flags2} -S ${f}.i.c"
      echotab "\$(MV) ${f}.i.s ${f}.s"
      echotab "\$(RM) ${f}.i.c"
      echol
      echol "${f}${TOBJ} : ${f}.c${dependsc}"
      echotab "${XCPP} ${flags} ${f}.c${XCPP_POSTPROCESS} > ${f}.i.c"
      echotab "${XCC} ${flags2} -c ${f}.i.c"
      echotab "\$(MV) ${f}.i${TOBJ} ${f}${TOBJ}"
      echotab "\$(RM) ${f}.i.c"
      echol
    fi
  else
    echol "${f}.s : ${f}.c${dependsc}"
    echotab "${XCC} ${flags2} -S ${f}.c"
    echol
    echol "${f}${TOBJ} : ${f}.c${dependsc}"
    echotab "${XCC} ${flags2} -c ${f}.c"
    echol
  fi
done

if test -n "$GMALLOC"; then
  for f in $GMALLOC ; do
    echol "${f}${TOBJ} : ${SRCDIR}malloc${NEXT_M}${f}.c"
    # gmalloc.c needs -DUSG on Solaris and then needs -DMEMMOVE_MISSING for SunOS 4.
    echotab "${XCC} ${XCFLAGS} -DUSG -DMEMMOVE_MISSING -c ${SRCDIR}malloc${NEXT_}${f}.c -o ${f}${TOBJ}"
    echol
  done
fi

for f in $ARI_ASMS $SP_ASMS ; do
  if [ $TSYS = win32msvc ] ; then
    echol "${f}.i : ${f}.msvc.c"
    echotab "${XCPP} ${XCFLAGS} ${f}.msvc.c > ${f}.i"
    echol
    echol "${f}.s : ${f}.msvc.c"
    echotab "${XCPP} ${XCFLAGS} ${f}.msvc.c > ${f}.i.c"
    echotab "${XCC} ${XCFLAGS} -c ${f}.i.c /FAs /Fa${f}.s"
    echotab "\$(RM) ${f}.i${TOBJ}"
    echotab "\$(RM) ${f}.i.c"
    echol
    echol "${f}${TOBJ} : ${f}.msvc.c"
    echotab "${XCPP} ${XCFLAGS} ${f}.msvc.c > ${f}.i.c"
    echotab "${XCC} ${XCFLAGS} -c ${f}.i.c"
    echotab "\$(RM) ${f}${TOBJ}"
    echotab "\$(MV) ${f}.i${TOBJ} ${f}${TOBJ}"
    echotab "\$(RM) ${f}.i.c"
    echol
  else
    echol "${f}${TOBJ} : ${f}.s"
    # Call the assembler, preferrably through the C compiler:
    if [ $TSYS = acorn ] ; then
      echotab "objasm -Stamp -Quit -CloseExec -from ${f}.s -o ${f}${TOBJ}"
    else
      if [ $f = arihppa ] ; then
        # Only the native as groks the .SHORTDATA statements in arihppa.d
        echotab "${XCC} ${XCFLAGS} -c ${f}.s || /usr/ccs/bin/as ${f}.s -o ${f}${TOBJ} || /bin/as ${f}.s -o ${f}${TOBJ}"
      else
        if [ $f = arimips ] ; then
          # Avoid problem during incremental linking of lisp.o.
          echotab "/bin/as -KPIC ${f}.s -o ${f}${TOBJ} || /usr/ccs/bin/as -KPIC ${f}.s -o ${f}${TOBJ}"
        else
          if [ $XCC_GCC = true ] ; then
            echotab "${XCC} ${XCFLAGS} -x assembler -c ${f}.s"
          else
            echotab "${XCC} ${XCFLAGS} -c ${f}.s"
          fi
        fi
      fi
    fi
    echol
  fi
done

if [ $HOS = unix -o $HSYS = win32gcc ] ; then
  # on w32 -g, using lisp.o leads to a crash on the first statement in main()
  test $HSYSOS = win32gcc -o $HSYSOS = cygwin32; no_lisp_o=$?;
  echol "lisp.a : \$(OBJECTS)"
  if [ $no_lisp_o = 1 ]; then
    echotab "ld -r -o lisp.o \$(OBJECTS)"
    echotab "chmod a-x lisp.o"
  fi
  if test -z "$LIBGCC"; then
    if [ $no_lisp_o = 1 ]; then
      echotab "\$(AR) rcv lisp.a lisp.o"
    else echotab "\$(AR) rcv lisp.a \$(OBJECTS)"
    fi
  else
    # Test for libgcc.a because NeXT cc does not have it.
    echotab "if test -f \$(LIBGCC) ; then mkdir libgcc ; (cd libgcc ; \$(AR) xv \$(LIBGCC)) ; \$(AR) rcv lisp.a lisp.o libgcc/*.o* ; \$(RM) -r libgcc ; else \$(AR) rcv lisp.a lisp.o ; fi"
  fi
  if [ $no_lisp_o = 1 ]; then echotab "\$(RM) lisp.o"; fi
  echotab "\$(RANLIB) lisp.a"
  echol
  echol "libnoreadline.a : noreadline.o"
  echotab "\$(AR) rcv libnoreadline.a noreadline.o"
  echotab "\$(RANLIB) libnoreadline.a"
  echol
fi

if [ -n "$with_dynamic_ffi" ] ; then
  for f in avcall callback; do
    if [ ${LIB_TYPE} = "unix" ] ; then
      echol "$f.h lib$f.a :"
      echotab "builddir=\"\`pwd\`\"; cd $f && \$(MAKE) && \$(MAKE) check && \$(MAKE) install-lib libdir=\"\$\$builddir\" includedir=\"\$\$builddir\""
      echol
    fi
    if [ ${LIB_TYPE} = "win32" ] ; then
      echol "$f.h : ${SRCTOPDIR_M}ffcall${NEXT_M}$f${NEXT_M}$f.h"
      echotab "-\$(LN_S) ${SRCTOPDIR_}ffcall${NEXT_}$f${NEXT_}$f.h $f.h"
      if [ $f = callback ] ; then
        for g in vacall_r trampoline_r; do
          echotab "-\$(LN_S) ${SRCTOPDIR_}ffcall${NEXT_}$f${NEXT_}$g.h $g.h"
        done
      fi
      echol
      echol "$f.lib : ${SRCTOPDIR_M}ffcall${NEXT_M}$f${NEXT_M}$f.lib"
      echotab "-\$(LN_S) ${SRCTOPDIR_}ffcall${NEXT_}$f${NEXT_}$f.lib $f.lib"
      echol
    fi
  done
fi

if [ -n "$USE_GETTEXT" ] ; then

  echol "locale :"
  if [ $HOS = unix ] ; then
    echotab "if test -d locale; then rm -rf locale; fi"
    echotab "mkdir locale"
    echotab "(cd po && \$(MAKE) && \$(MAKE) install datadir=.. localedir='\$\$(datadir)/locale' INSTALL_DATA=ln) || (rm -rf locale ; exit 1)"
  else
    echotab "mkdir locale"
    my_eval `grep ALL_LINGUAS= src/configure.in`
    for lang in ${ALL_LINGUAS:-"en de fr"}; do
      echotab "mkdir locale${NEXT_}${lang}"
      echotab "mkdir locale${NEXT_}${lang}${NEXT_}LC_MESSAGES"
      echotab "\$(LN_S) po${NEXT_}${lang}.gmo locale${NEXT_}${lang}${NEXT_}LC_MESSAGES${NEXT_}clisp.mo"
    done
  fi
  echol

  echol

fi

for f in libcharset; do
  if [ ${LIB_TYPE} = "unix" ] ; then
    echol "libcharset.h libcharset.a :"
    echotab "builddir=\"\`pwd\`\"; cd $f && \$(MAKE) && \$(MAKE) install-lib libdir=\"\$\$builddir\" includedir=\"\$\$builddir\""
    echol
  fi
  if [ ${LIB_TYPE} = "win32" ] ; then
    echol "libcharset.h : ${SRCTOPDIR_M}$f${NEXT_M}include${NEXT_M}libcharset.h"
    echotab "-\$(LN_S) ${SRCTOPDIR_}$f${NEXT_}include${NEXT_}libcharset.h libcharset.h"
    echol
    echol "charset.lib : ${SRCTOPDIR_M}$f${NEXT_M}lib${NEXT_M}charset.lib"
    echotab "-\$(LN_S) ${SRCTOPDIR_}$f${NEXT_}lib${NEXT_}charset.lib charset.lib"
    echol
  fi
done

if [ $TOS = win32 ] ; then
  for f in $SYSLIBS ; do
    echol "$f :"
    echotab "implib $f \$(WIN32DIR)\\"`basename $f .lib`".dll"
    echol
  done
fi

DATA_FILES="UnicodeDataFull.txt clhs.txt"
DATA_FILES_TOP_PATH="utils${NEXT_}unicode${NEXT_}UnicodeDataFull.txt src${NEXT_}clhs.txt"
data_target="data :"
for f in ${DATA_FILES_TOP_PATH}; do
  data_target="${data_target} ${SRCTOPDIR_}${f}"
done
echol "${data_target}"
echotab "\$(RMRF) data"
echotab "mkdir data"
for f in ${DATA_FILES_TOP_PATH}; do
  echotab "cd data && \$(LN_S) ${PARENT_SRCTOPDIR_}${f} ."
done
echol

echol "lisp${LEXE} : \$(OBJECTS) modules${TOBJ} ${XCL_FFILIBS} ${XCL_GETTEXTLIB} ${XCL_CHARSETLIB} ${SYSLIBS} data"
if [ $HOS != os2 -a $HOS != win32 ] ; then
  if [ $XCC_GCC = true -a -n "$SOLARIS_LINKING" ] ; then
    # Dynamically linking on Solaris 2.[23] is a pain.
    LIBGCC_DIR='`'"${XCC} -print-libgcc-file-name"' | sed -e '"'"'s,[^/]*$$,,'"'"'`'
    echotab "${XCC} ${XCFLAGS} ${XCLFLAGS} \$(OBJECTS) modules${TOBJ} ${LIBS} -o lisp${LEXE} || /usr/ccs/bin/ld -V -dy -Bdynamic -Y P,/usr/ccs/lib:/usr/lib -Qy -o lisp${LEXE} ${LIBGCC_DIR}crt1.o ${LIBGCC_DIR}crti.o /usr/ccs/lib/values-Xa.o ${LIBGCC_DIR}crtbegin.o \$(OBJECTS) modules${TOBJ} -L${LIBGCC_DIR} -L/usr/ccs/bin ${LIBS} -lgcc -lc ${LIBGCC_DIR}crtend.o ${LIBGCC_DIR}crtn.o -lgcc"
  else
    echotab "${XCC} ${XCFLAGS} ${XCLFLAGS} \$(OBJECTS) modules${TOBJ} ${LIBS} -o lisp${LEXE}"
  fi
  if [ $HOS = unix ] ; then
    echotab "-sync"
  fi
  echol
else
  if [ $HSYS = win32gcc -o $HSYS = win32msvc -o $HSYS = win32bc ] ; then
    if [ $HSYS = win32gcc ] ; then
      echotab "${XCC} ${XCFLAGS} ${XCLFLAGS} \$(OBJECTS) modules${TOBJ} ${LIBS} -o lisp${LEXE}"
    fi
    if [ $HSYS = win32msvc ] ; then
      # MSVC's incremental linking is buggy, avoid it.
      echotab "\$(RM) lisp.ilk"
      echotab "${XCC} ${XCFLAGS} ${XCLFLAGS} \$(OBJECTS) modules${TOBJ} ${LIBS} /link /out:lisp${LEXE}"
      # With msvc4/5, need at least 1200 KB stack for creating the first
      # interpreted.mem, but the default stack size is only 1 MB.
      # With msvc6, need more than 2 MB for compiling compiler.lisp.
      if [ ${COMPILER} != msvc7 ]; then
        # Jay Kint <jkint@icosahedron.org> says that msvc7(.NET)
        # does not need this
        echotab "editbin /stack:3145728 lisp${LEXE}"
      fi
    fi
    if [ $HSYS = win32bc ] ; then
      echotab "${XCC} ${XCFLAGS} ${XCLFLAGS} -elisp${LEXE} \$(OBJECTS) modules${TOBJ} ${LIBS}"
    fi
  else
    # DOS has a very limited command line length
    # XCLFLAGS=$XCLFLAGS' -s' # strip, does not work anymore on emx0.8f
    echotab "\$(RM) lisp"
    echotab "\$(RM) lisp${LEXE}"
    echotab "${XCC} ${XCFLAGS} -o lisp @gcclink.in ${XCLFLAGS} ${LIBS}"
    echotab "emxbind -q \$(EMX) lisp lisp${LEXE} -p"
    # strip may be done only afterwards because of -lvideo
    echotab "emxbind -s lisp${LEXE}"
  fi
  echol
fi

echol

echol "alllisp : \$(LISPFILES)"
echodummyrule alllisp
echol

if [ $TOS = amiga ] ; then
  CONFIG=cfgamiga
fi
if [ $TOS = acorn ] ; then
  CONFIG=cfgacorn
fi
if [ $TOS = os2 ] ; then
  CONFIG=cfgdos
fi
if [ $TOS = win32 ] ; then
  CONFIG=cfgwin32
fi
if [ $TOS = unix ] ; then
  if [ $CROSS = false -a "$HSYSOS" = sunos ] ; then
    CONFIG=cfgsunux
  fi
  if test -z "$CONFIG"; then
    CONFIG=cfgunix
  fi
fi
for f in $LPARTS ; do
  if [ $f = config ] ; then
    echol "${f}.lisp : ${SRCDIR}${CONFIG}.lisp"
    echotab "\$(CP) ${SRCDIR}${CONFIG}.lisp ${f}.lisp"
    if [ $TOS = unix ] ; then
      echotab "chmod +w ${f}.lisp"
      echotab "echo '(setq *clhs-root-default* \"${hyperspec}/\")' >> ${f}.lisp"
      if [ ${TSYSOS} = cygwin32 ]; then
        echotab "echo '(setq *device-prefix* \"${DEVPREFIX}\")' >> ${f}.lisp"
      fi
    fi
    echol
  else
    if [ -n "${SRCDIR}" ] ; then
      link_dep "${f}.lisp" "${SRCDIR}${f}.lisp"
    fi
  fi
done

if [ -n "$USE_GETTEXT" ] ; then
  localeflags='-B . -N locale'
else
  localeflags='-B .'
fi
encflags='-Efile UTF-8 -Eterminal UTF-8'
echol "RUN= ${HERE}lisp${LEXE} ${localeflags} ${encflags} -norc";
echol;

for f in ${LUTILS} ; do
  echol "${f}.fas : ${UTILDIR_M}${f}.lisp lisp${LEXE} lispinit.mem"
  echotab "\$(RUN) -M lispinit.mem -q -c ${UTILDIR}${f}.lisp -o ${f}.fas"
  echol
done

if [ $CROSS = false ] ; then

  echol "$interpreted.mem : lisp${LEXE} \$(LISPFILES)"
  if [ $HOS != unix ] ; then
    echotab "-\$(RM) $interpreted.mem"
  fi
  if [ $HSYSOS = beos ] ; then
    # Workaround BeOS 5 kernel bug which causes subsequent invocations
    # of lisp${LEXE} to be incorrectly relocated. On BeOS, executables and
    # shared libraries are relocated page-by-page by a kernel routine.
    echotab "cp -p lisp${LEXE} lisp.tmp"
    echotab "mv lisp.tmp lisp${LEXE}"
  fi
  if [ $HOS != os2 ] ; then
    echotab '$(RUN) -m 750KW -x "(and (load \"init.lisp\") (sys::%saveinitmem) (ext::exit))"'
  else
    echotab '$(RUN) -m 750KW < interpreted.in'
  fi
  echotab "\$(MV) lispimag.mem $interpreted.mem"
  echol

fi

if [ $CROSS = false ] ; then

  for f in $LPARTS ; do
    if [ $f = "compiler" ]; then image=${interpreted}.mem;
    else image=${halfcompiled}.mem; fi
    echol "${f}.fas : ${f}.lisp lisp${LEXE} $image"
    # The strict minimum needed for compiling compiler.lisp is between 750KW
    # and 800KW. To reduce GCs, we spend 20% more than this.
    echotab "\$(RUN) -m 1000KW -M ${image} -q -c ${f}.lisp"
    echol
  done

else

  for f in $LPARTS ; do
    echol "${f}.fas : ${f}.lisp"
    echotab 'clisp -M cross.mem ${localeflags} ${encflags} -norc -q -x "(cross:compile-file \"'"${f}.lisp"'\")"'
    echol
  done

fi

if [ $CROSS = false ] ; then

  echol "${halfcompiled}.mem : lisp${LEXE} \$(LISPFILES) compiler.fas"
  if [ $HOS != unix ] ; then
    echotab "-\$(RM) ${halfcompiled}.mem"
  fi
  if [ $HSYSOS = beos ] ; then
    # Workaround BeOS 5 kernel bug, see explanation above.
    echotab "cp -p lisp${LEXE} lisp.tmp"
    echotab "mv lisp.tmp lisp${LEXE}"
  fi
  if [ $HOS != os2 ] ; then
    echotab '$(RUN) -m 750KW -x "(and (load \"init.lisp\") (sys::%saveinitmem) (ext::exit))"'
  else
    echotab '$(RUN) -m 750KW < interpreted.in'
  fi
  echotab "\$(MV) lispimag.mem $halfcompiled.mem"
  echol

  echol "lispinit.mem : lisp${LEXE} \$(FASFILES)"
  if [ $HOS != unix ] ; then
    echotab "-\$(RM) lispinit.mem"
  fi
  if [ $HSYSOS = beos ] ; then
    # Workaround BeOS 5 kernel bug, see explanation above.
    echotab "cp -p lisp${LEXE} lisp.tmp"
    echotab "mv lisp.tmp lisp${LEXE}"
  fi
  if [ $HOS != os2 ] ; then
    echotab '$(RUN) -x "(and (load \"init.fas\") (ext::saveinitmem) (ext::exit))"'
  else
    echotab '$(RUN) < lispinit.in'
  fi
  echol

fi

echol

if [ -n "$USE_GETTEXT" ] ; then
  localeflags='-B `pwd` -N '"${HERE_}locale"
else
  localeflags='-B `pwd`'
fi
CLISP_="${HERE_}lisp${LEXE} -M ${HERE_}lispinit.mem ${localeflags} ${encflags} -norc"

if [ $CROSS = false ] ; then

  echol "# Perform self-tests."
  echol "check : test testsuite"
  echodummyrule check
  echol

  echol "# check the sources:"
  echol "# 1. subr.d, fsubr.d, subrkw.d and all the LISPFUNs must add up"
  echol "# 2. no variables of type gcv_object_t - only pointers to it"
  echol "check-sources : # lisp${LEXE} lispinit.mem"
  echotab "\$(RUN) -M lispinit.mem -C -i ${SRCDIR}check-lispfun.lisp -x '(check-lisp-defs \"${SRCDIR}\")'"
  echotab "if egrep ' var gcv_object_t *[^* ]' *.d; then false; else true; fi"
  echol

  echol "# Test: recompile \$(LISPFILES) and compare their contents."

  echol "test : lispinit.mem ${TESTDIR} \$(TESTLISPFILES) \$(TESTFASFILES)"
  if [ $HOS = unix -o $HSYS = win32gcc ] ; then
    # replace GENSYMs with a string
    SEDRE='s/\(#Y([-a-zA-Z:]\{1,\}\)[0-9]\{2,\}\(-*[0-9]*\)/\1<GENSYM>\2/g';
    FAIL=' || (echo "Test failed." ; exit 1)';
    for f in $LPARTS ; do
      # add the lisp files with GENSYMS in FLET here
      if [ ${f} = "threads" ]; then
        echotab "sed '${SEDRE}' ${f}.fas > ${f}.fas1";
        echotab "sed '${SEDRE}' ${TESTDIR}/${f}.fas > ${TESTDIR}/${f}.fas1";
        echotab "cmp -s ${f}.fas1 ${TESTDIR}/${f}.fas1 ${FAIL}";
        echotab "${RM} ${f}.fas1 ${TESTDIR}/${f}.fas1";
      else echotab "cmp -s ${f}.fas ${TESTDIR}/${f}.fas ${FAIL}";
      fi
    done
    echotab 'echo "Test passed."'
    echol
  else
    if [ $HOS = os2 -o $HSYS = win32msvc -o $HSYS = win32bc ] ; then
      echotab "comp *.fas ${TESTDIR}"
      echotab "echo The test passed if only GENSYM differences were found."
      echol
    else
      echotab 'echo "Compare the .fas files by hand."'
      echol
    fi
  fi

  echol "${TESTDIR} :"
  echotab "-mkdir ${TESTDIR}"
  echol

  for f in $LPARTS ; do
    echol "${TESTDIR}${NEXT_M}${f}.lisp : ${f}.lisp"
    if [ $H_DOS != "true" -a $HOS != acorn ] ; then
      echotab "cd ${TESTDIR} && \$(LN_S) ${PARENT_}${f}.lisp ${f}.lisp"
    else
      echotab "\$(LN_S) ${f}.lisp ${TESTDIR}"
    fi
    echol
  done

  # have to reset *GENSYM-COUNTER* in the test image since the compiled
  # files can (and some actually do, like threads.lisp) contain GENSYMed
  # FLET locals, whose names are written to the FAS files
  TESTIMAGE="${TESTDIR}${NEXT_M}testinit.mem";
  echol "${TESTIMAGE}: lispinit.mem";
  # this does not help, unfortunately, since the number of GENSYM calls
  # depends on which files went into halfcompiled.mem as FAS files
  #  echotab "\$(RUN) -M lispinit.mem -x \"(setq *gensym-counter* (- \`\$(RUN) -q -M ${halfcompiled}.mem -x '*gensym-counter*'\` 16)) (sys::%saveinitmem) (exit)\"";
  #  echotab "\$(MV) lispimag.mem ${TESTIMAGE}";
  echotab "\$(CP) lispinit.mem ${TESTIMAGE}";
  echol;

  for f in $LPARTS ; do
    echol "${TESTDIR}${NEXT_M}${f}.fas : ${TESTDIR}${NEXT_M}${f}.lisp lisp${LEXE} ${TESTIMAGE}"
    echotab "\$(RUN) -M ${TESTIMAGE} -q -d -c ${TESTDIR}${NEXT_}${f}.lisp"
    echol
  done

  echol "lispinit2.mem : lisp${LEXE} \$(TESTFASFILES)"
  if [ $HSYSOS = beos ] ; then
    # Workaround BeOS 5 kernel bug, see explanation above.
    echotab "cp -p lisp${LEXE} lisp.tmp"
    echotab "mv lisp.tmp lisp${LEXE}"
  fi
  echotab '$(RUN) -x "(and (cd \"'"${TESTDIR}${NEXT}"'\") (load \"init.fas\") (cd \"'"${PARENT}"'\") (sys::%saveinitmem) (ext::exit))"'
  echotab "-\$(RM) lispinit2.mem"
  echotab "\$(MV) lispimag.mem lispinit2.mem"
  echol

  echol

  echol "testsuite : ${TESTSDIR} lisp${LEXE} lispinit.mem"
  echotab "cd ${TESTSDIR} && \$(MAKE) LEXE=${LEXE}"
  echol
  echol "${TESTSDIR} :"
  echotab "-mkdir ${TESTSDIR}"
  # on win32, LN_S=copy and it accepts exactly 2 arguments
  for f in Makefile '*.lisp' '*.tst'; do
    echotab "cd ${TESTSDIR} && \$(LN_S) ${PARENT_SRCTOPDIR_}tests${NEXT_}${f} ."
  done
  echol

  # benchmarks are for developers only, and the developers work from the CVS
  if test -d ${SRCTOPDIR}CVS; then
    echol "bench : ${BENCHDIR}"
    echotab "CLISP=\"${CLISP_}\"; export CLISP; cd ${BENCHDIR}; \$(MAKE) CLISP=\"\$\$CLISP\" clisp"
    echol
    echol "${BENCHDIR} :"
    echotab "-mkdir ${BENCHDIR}"
    for f in Makefile '*.lisp'; do
      echotab "cd ${BENCHDIR} && \$(LN_S) ${PARENT_SRCTOPDIR_}benchmarks${NEXT_}${f} ."
    done
    echol
  fi
  echol
fi

if [ $XCC_GCC = true ] ; then
  echol "lispbibl.h :${EVERY_INCLUDES_C}${EVERY_INCLUDES_H}"
  echotab "((${XCPP} ${XCFLAGS} -P lispbibl.c | \$(GREP) -v \"^ *\$\$\") ; (${XCPP} ${XCFLAGS} -P -dM lispbibl.c | sort) ) > lispbibl.h"
  echol
  echol "gc : lispbibl.h # show GC-related definitions"
  echotab "egrep '[^[:alpha:]](MEMORY|SPVW|GC|SIGSEGV|SAFETY|ASM|FAST|DEBUG)[^[:alpha:]]' lispbibl.h | grep -v 'define _' | egrep '^#define'"
  echol
  echol
fi


echol "clisp.h : genclisph.o unixconf.h ${PARAMS_H}"
echotab_to_HEXE "\$(CC) \$(CFLAGS) \$(CLFLAGS)" "genclisph.o" "genclisph"
echotab "(echo '#ifndef _CLISP_H' ; echo '#define _CLISP_H' ; echo; echo '/* unixconf */' ; grep '^#' unixconf.h ) > clisp.h"
for parf in ${PARAMS_H}; do
  echotab "(echo; echo '/* '${parf}' */' ; grep '^#' ${parf} ) >> clisp.h"
done
echotab "(echo; echo '/* genclisph */' ; ${HERE}genclisph ; echo ; echo '#endif /* _CLISP_H */') >> clisp.h"
echotab "\$(RM) genclisph${HEXE}"
echol
echol "linkkit : modules.d modules.c clisp.h"
echotab "-\$(RMRF) linkkit"
echotab "mkdir linkkit"
echotab "cd linkkit && \$(LN_S) ${PARENT_}modules.d modules.d"
echotab "cd linkkit && \$(LN_S) ${PARENT_}modules.c modules.c"
echotab "cd linkkit && \$(LN_S) ${PARENT_}clisp.h clisp.h"
echol
echol "exporting.fas : ${MODULESDIR_M}exporting.lisp lisp${LEXE} lispinit.mem"
echotab "\$(RUN) -M lispinit.mem -q -c ${MODULESDIR}exporting.lisp -o exporting.fas"
echol
echol "modular : ${FILES} clisp-link linkkit modules.h modules.o makevars"
echodummyrule modular
echol
echol "makevars :"
echotab "(echo 'CC='\"'\"'\$(CC)'\"'\" ; echo 'CFLAGS='\"'\"'\$(${MODULE_CFLAGS_VAR})'\"'\" ; echo 'CLFLAGS='\"'\"'\$(${MODULE_CLFLAGS_VAR})'\"'\" ; echo 'LIBS='\"'\"'lisp.a \$(LIBS)'\"'\" ; echo 'X_LIBS='\"'\"'\$(X_LIBS)'\"'\" ; echo 'RANLIB='\"'\"'\$(RANLIB)'\"'\" ; echo 'FILES='\"'\"'${FILES}'\"'\") > makevars"
echol
for f in clisp-link ; do
  echol "${f} : ${SRCDIR}${f}.in"
  XCC_CREATESHARED_=`echo "$XCC_CREATESHARED" | sed -e 's,\\$,$$,g'`
  echotab "sed -e 's%@with_dynamic_modules@%$with_dynamic_modules%' -e 's%@createsharedlib@%$XCC_CREATESHARED_%' -e 's%@LEXE@%${LEXE}%' < ${SRCDIR}${f}.in > ${f}"
  echotab "chmod a+x ${f}"
  echol
done
echol "base : modular lispinit.mem"
echotab "test -d base || (mkdir base && cd base && for f in ${FILES} modules.h modules.o makevars lisp${LEXE} lispinit.mem; do \$(LN_S) ${PARENT_}\$\$f \$\$f; done) || (\$(RMRF) base ; exit 1)"
echol
# Some "make"s don't support empty target lists. Hence the "anymodule".
echol "anymodule \$(MODULES) : lisp${LEXE} lispinit.mem force modprep.fas exporting.fas clisp.h"
echotab "test -d \$@ || ${SRCDIR:-${HERE}}lndir ${SRCTOPDIR_}modules/\$@ \$@"
echotab "if test -f \$@/configure -a '!' -f \$@/config.status ; then cd \$@ ; ./configure --cache-file="'`'"echo \$@/ | sed -e 's,[^/][^/]*//*,../,g'"'`'"config.cache ; fi"
EVERY_INCLUDES_DOTS_C=''
for f in $EVERY_INCLUDES_C $EVERY_INCLUDES_H ; do
  EVERY_INCLUDES_DOTS_C=$EVERY_INCLUDES_DOTS_C' $${dots}'$f
done
echotab "CLISP=\"${CLISP_}\" ; cd \$@ ; dots="'`'"echo \$@/ | sed -e 's,[^/][^/]*//*,../,g'"'`'" ; \$(MAKE) clisp-module CC=\"\$(CC)\" CFLAGS=\"\$(${MODULE_CFLAGS_VAR})\" INCLUDES=\"\$\$dots\" LISPBIBL_INCLUDES=\"$EVERY_INCLUDES_DOTS_C\" CLFLAGS=\"\$(${MODULE_CLFLAGS_VAR})\" LIBS=\"\$(LIBS)\" RANLIB=\"\$(RANLIB)\" CLISP=\"\$\$CLISP -q\""
echol
echol "full : modular base \$(MODULES)"
echotab "\$(RMRF) full"
echotab "CLISP_LINKKIT=. ${HERE}clisp-link add-module-sets base full \$(MODULES) || (\$(RMRF) full ; exit 1)"
echol
OBSOLETE=$OBSOLETE" genclisph${HEXE}"

if test -n "$GROFF"; then
  manual_dvi='clisp.dvi clisp.ps'
else
  manual_dvi=''
fi
echol "READMES = ANNOUNCE COPYRIGHT GNU-GPL SUMMARY NEWS README README.de README.es"`if [ $TOS = unix ] ; then echol ' MAGIC.add' ; fi`
IMPNOTES_FILES="impnotes.html impnotes.css clisp.png";
if [ ${HOS} = win32 ]; then
  IMPNOTES_FILES=${IMPNOTES_FILES}" clisp.ico";
fi
echol "IMPNOTES = ${IMPNOTES_FILES}"
echol "MANUALS = clisp.1 clisp.html \$(TXTFILES) \$(IMPNOTES)"
echol
for f in ${IMPNOTES_FILES} ; do
  echol "${f} : ${DOCDIR_M}${f}"
  echotab "\$(LN_S) ${DOCDIR_M}${f} ${f}"
  echol
done
EMACS_FILES="clisp-coding.el clisp-indent.el clisp-indent.lisp";

# On Unix, clisp.dvi & clisp.ps must be built by "make all", because
# "make install" needs it and "make install" must not create files in
# the current directory, for compliance with the GNU standards.
# On other OSes, clisp.dvi & clisp.ps must be built manually on another
# machine, so don't make it part of "make all".
if [ $HOS = unix ] ; then
  echol "manual : \$(READMES) \$(MANUALS) ${manual_dvi}"
  echodummyrule manual
  echol
  echol "manualx : manual clisp.man"
  echodummyrule manualx
  echol
else
  echol "manual : \$(READMES) \$(MANUALS)"
  echodummyrule manual
  echol
  echol "manualx : manual clisp.man ${manual_dvi}"
  echodummyrule manualx
  echol
fi

for f in ANNOUNCE COPYRIGHT GNU-GPL SUMMARY ; do
  echol "${f} : ${SRCTOPDIR_M}${f}"
  echotab "-\$(LN_S) ${SRCTOPDIR_}${f} ${f}"
  echol
done

for f in NEWS .gdbinit ; do
  if [ -n "${SRCDIR}" ] ; then
    echol "${f} : ${SRCDIR}${f}"
    if [ $f = .gdbinit -a $LEXE != ".run" ]; then
      echotab "sed 's/lisp.run/lisp$LEXE/g' ${SRCDIR}${f} > ${f}"
    else echotab "-\$(LN_S) ${SRCDIR}${f} ${f}"
    fi
    echol
  fi
done

if [ $TOS = unix ] ; then
  for f in MAGIC.add ; do
    link_dep "${f}" "${SRCTOPDIR}unix${NEXT}${f}"
  done
fi

for f in $TXT_FILES ; do
  depends=''
  flags=''
  if [ $f = README ] ; then
    depends=$depends" ${SRCDIR}_${f}.de ${SRCDIR}_${f}.en"
  fi
  if [ $f = clisp.html ] ; then depends=$depends" VERSION"; fi
  echol "${f} : ${SRCDIR}_${f}${TXT_INCLUDES}${depends} txt2c${HEXE}"
  echotab "\$(TXT2C) < ${SRCDIR}_${f} > $txt.c"
  if [ $CROSS = false -a $XCC_UNUSABLE_CPP = true ] ; then
    echotab "${XCPP} ${XCFLAGS}${flags} $txt.c${XCPP_POSTPROCESS} > $txt.i.c"
    echotab_to_HEXE "${XCC} ${XCFLAGS} ${XCLFLAGS}${XCC_NOOPTFLAGS}" "$txt.i.c" "$txt"
    echotab "\$(RM) $txt.i.c"
    if [ $HSYS = win32msvc ] ; then
      echotab "\$(RM) $txt.i${TOBJ}"
    fi
  else
    echotab_to_HEXE "\$(CC) \$(CFLAGS)${flags} \$(CLFLAGS)${XCC_NOOPTFLAGS}" "$txt.c" "$txt"
  fi
  line="${HERE}$txt"
  if [ $f = clisp.1 ] ; then
    if [ $HOS != os2 -a $HOS != win32 -a $HOS != acorn ] ; then
      line=$line" | \$(GREP) -v '^ *\$\$'"
    else
      if [ $HOS = os2 ] ; then
        # DOS command line args may not contain spaces. grep.in contains "^ *$"
        line=$line" | \$(GREP) -v -f grep.in"
      fi
      if [ $HOS = acorn ] ; then
        line=$line" | \$(GREP) -v -f ${PARENT}acorn${NEXT}grep.in"
      fi
      # On Win32, no grep installed. The blank lines don't hurt.
    fi
  fi
  if [ $f = clisp.html -a $HOS != win32 ] ; then
    line=$line" | sed -e 's,=\"CLHSROOT/,=\"${hyperspec}/,' -e \"s,VERSION,\`cat VERSION\`,\""
  fi
  if [ $f = distmakefile ] ; then
    line=$line" | (libs=''; for f in modules.o lisp.a \$(LIBS); do case \$\$f in -*) libs=\"\$\$libs \$\$f\";; *) libs=\"\$\$libs\"' base/'\"\$\$f\";; esac; done; files=''; for f in modules.o ${FILES}; do files=\"\$\$files\"' base/'\"\$\$f\"; done; sed -e \"s,@@LEXE@@,${LEXE},g\" -e \"s,@@BASE_LIBS@@,\$\$libs,g\" -e \"s,@@BASE_FILES@@,\$\$files,g\")"
  fi
  echotabpipe "${line} > ${f}"
  echotab "\$(RM) $txt.c"
  echotab "\$(RM) $txt${HEXE}"
  echol
done
OBSOLETE=$OBSOLETE" $txt.c $txt${HEXE}"
if [ $CROSS = false -a $XCC_UNUSABLE_CPP = true ] ; then
  OBSOLETE=$OBSOLETE" $txt.i.c"
fi

if test -n "$GROFF"; then
  echol "clisp.dvi : clisp.1"
  echotab "\$(ROFF_DVI) clisp.1 > clisp.dvi"
  echol
  echol "clisp.ps : clisp.1"
  echotab "\$(ROFF_PS) clisp.1 > clisp.ps"
  echol
fi

echol "clisp.man : clisp.1"
echotab "\$(ROFF_MAN) clisp.1 > clisp.man"
echol

for f in $DOC ; do
  echol "${f}.txt : ${DOCDIR_M}${f}.txt"
  echotab "-\$(LN_S) ${DOCDIR_}${f}.txt ${f}.txt"
  echol
done

echol

if [ $CROSS = false ] ; then
  DRIVER_DEP=''; DRIVER_RES='';
  if [ $HOS = win32 ]; then
    DRIVER_RES=' clispres.o';
    DRIVER_DEP=${DRIVER_RES}' w32shell.c';
    echol "clispres.o : clisp.rc"
    echotab "windres -i clisp.rc -o clispres.o"
    echol
    echol "clisp.rc :"
    echotab 'echo "MAINICON ICON \"clisp.ico\"" > clisp.rc'
    echol
  fi
  echol "clisp : clisp.c${DRIVER_DEP}"
  echotab "builddir=\"${PWDCMD}\"; \$(CC) \$(CFLAGS) \$(CLFLAGS) -DLISPLIBDIR='\"'"\$\$builddir"'\"' -DLOCALEDIR='\"'"\$\$builddir/locale"'\"' clisp.c${DRIVER_RES} ${LIBS} -o clisp"
  echol
  if [ $HOS = unix ] ; then
    echol "install : install-bin install-man install-doc"
    echodummyrule install
    echol
    echol "installdirs : force"
    echotab_mkdir_maybe "\$(DESTDIR)\$(prefix)"
    echotab_mkdir_maybe "\$(DESTDIR)\$(exec_prefix)"
    echotab_mkdir_maybe "\$(DESTDIR)\$(libdir)"
    echotab_mkdir_maybe "\$(DESTDIR)\$(lisplibdir)"
    echotab_mkdir_maybe "\$(DESTDIR)\$(lisplibdir)/data"
    echotab_mkdir_maybe "\$(DESTDIR)\$(lisplibdir)/linkkit"
    echotab_mkdir_maybe "\$(DESTDIR)\$(lisplibdir)/base"
    echotab_mkdir_maybe "\$(DESTDIR)\$(lisplibdir)/full"
    echotab_mkdir_maybe "\$(DESTDIR)\$(bindir)"
    if [ -n "$USE_GETTEXT" ] ; then
      echotab "cd po && \$(MAKE) installdirs prefix='\$(DESTDIR)\$(prefix)' exec_prefix='\$(DESTDIR)\$(exec_prefix)'"
    fi
    echotab_mkdir_maybe "\$(DESTDIR)\$(shared)"
    echotab_mkdir_maybe "\$(DESTDIR)\$(mandir)"
    echotab_mkdir_maybe "\$(DESTDIR)\$(mandir)/man1"
    case "$fsstnd" in
      gnu_ext)
        echotab_mkdir_maybe "\$(DESTDIR)\$(htmldir)"
        echotab_mkdir_maybe "\$(DESTDIR)\$(dvidir)"
        echotab_mkdir_maybe "\$(DESTDIR)\$(psdir)"
        ;;
      *bsd)
        echotab_mkdir_maybe "\$(DESTDIR)\$(lispdocdir)"
        ;;
    esac
    echotab_mkdir_maybe "\$(DESTDIR)\$(docdir)"
    echotab_mkdir_maybe "\$(DESTDIR)\$(lispdocdir)"
    case "$fsstnd" in
      *bsd)
        ;;
      *)
        echotab_mkdir_maybe "\$(DESTDIR)\$(lispdocdir)/doc"
        ;;
    esac
    echol
    echol "install-bin : lisp${LEXE} lispinit.mem clisp.c force"
    echotab_mkdir_maybe "\$(DESTDIR)\$(prefix)"
    echotab_mkdir_maybe "\$(DESTDIR)\$(exec_prefix)"
    echotab_mkdir_maybe "\$(DESTDIR)\$(libdir)"
    echotab_mkdir_maybe "\$(DESTDIR)\$(lisplibdir)"
    echotab_mkdir_maybe "\$(DESTDIR)\$(lisplibdir)/data"
    for f in ${DATA_FILES}; do
      echotab "\$(INSTALL_DATA) data/${f} \$(DESTDIR)\$(lisplibdir)/data/${f}"
    done
    echotab_mkdir_maybe "\$(DESTDIR)\$(lisplibdir)/linkkit"
    echotab "(cd \$(DESTDIR)\$(lisplibdir) && \$(RMRF) base full)"
    echotab "mkdir \$(DESTDIR)\$(lisplibdir)/base"
    echotab "mkdir \$(DESTDIR)\$(lisplibdir)/full"
    echotab "for f in clisp-link linkkit/modules.d linkkit/modules.c linkkit/clisp.h base/* full/*; do \\"
    echotab "  case \$\$f in \\"
    echotab "    */lisp${LEXE}) \$(INSTALL_PROGRAM) \$\$f \$(DESTDIR)\$(lisplibdir)/\$\$f;; \\"
    echotab "    *) \$(INSTALL_DATA) \$\$f \$(DESTDIR)\$(lisplibdir)/\$\$f;; \\"
    echotab "  esac; \\"
    echotab "done"
    # Don't strip the executables, otherwise (disassemble #'cons) won't work.
    # echotab "strip \$(DESTDIR)\$(lisplibdir)/base/lisp${LEXE}"
    if [ -n "$USE_GETTEXT" ] ; then
      echotab "cd po && \$(MAKE) install prefix='\$(DESTDIR)\$(prefix)' exec_prefix='\$(DESTDIR)\$(exec_prefix)'"
    fi
    echotab_mkdir_maybe "\$(DESTDIR)\$(bindir)"
    echotab "\$(CC) \$(CFLAGS) \$(CLFLAGS) -DLISPLIBDIR='\"\$(lisplibdir)\"' -DLOCALEDIR='\"\$(localedir)\"' clisp.c -o \$(DESTDIR)\$(bindir)/clisp"
    echol
    echol "install-man : clisp.1 ${manual_dvi} clisp.html force"
    echotab_mkdir_maybe "\$(DESTDIR)\$(prefix)"
    echotab_mkdir_maybe "\$(DESTDIR)\$(exec_prefix)"
    echotab_mkdir_maybe "\$(DESTDIR)\$(shared)"
    echotab_mkdir_maybe "\$(DESTDIR)\$(mandir)"
    echotab_mkdir_maybe "\$(DESTDIR)\$(mandir)/man1"
    echotab "\$(INSTALL_DATA) clisp.1 \$(DESTDIR)\$(mandir)/man1/clisp.1"
    case "$fsstnd" in
      gnu_ext)
        echotab_mkdir_maybe "\$(DESTDIR)\$(htmldir)"
        echotab "\$(INSTALL_DATA) clisp.html \$(DESTDIR)\$(htmldir)/clisp.html"
        echotab_mkdir_maybe "\$(DESTDIR)\$(dvidir)"
        echotab_mkdir_maybe "\$(DESTDIR)\$(psdir)"
        if test -n "$GROFF"; then
          echotab "\$(INSTALL_DATA) clisp.dvi \$(DESTDIR)\$(dvidir)/clisp.dvi"
          echotab "\$(INSTALL_DATA) clisp.ps  \$(DESTDIR)\$(psdir)/clisp.ps"
        fi
        ;;
      *bsd)
        echotab_mkdir_maybe "\$(DESTDIR)\$(lispdocdir)"
        echotab "\$(INSTALL_DATA) clisp.html \$(DESTDIR)\$(lispdocdir)/clisp.html"
        ;;
    esac
    echol
    echol "install-doc : \$(READMES) \$(MANUALS) ${manual_dvi} force"
    echotab_mkdir_maybe "\$(DESTDIR)\$(prefix)"
    echotab_mkdir_maybe "\$(DESTDIR)\$(exec_prefix)"
    echotab_mkdir_maybe "\$(DESTDIR)\$(docdir)"
    echotab_mkdir_maybe "\$(DESTDIR)\$(lispdocdir)"
    echotab "\$(INSTALL_DATA) \$(READMES) \$(DESTDIR)\$(lispdocdir)/"
    case "$fsstnd" in
      *bsd)
        echotab "\$(INSTALL_DATA) \$(MANUALS) ${manual_dvi} \$(DESTDIR)\$(lispdocdir)/"
        ;;
      *)
        echotab_mkdir_maybe "\$(DESTDIR)\$(lispdocdir)/doc"
        echotab "\$(INSTALL_DATA) \$(MANUALS) ${manual_dvi} \$(DESTDIR)\$(lispdocdir)/doc/"
        ;;
    esac
    echol
    echol
    echol "installcheck : ${TESTSDIR} force"
    echotab "cd ${TESTSDIR} && \$(MAKE) LISP=\"\$(bindir)/clisp\""
    echol
    echol
    echol "uninstall : uninstall-bin uninstall-man"
    echodummyrule uninstall
    echol
    echol "uninstall-bin : force"
    echotab "\$(RM) \$(DESTDIR)\$(lisplibdir)/base/lisp${LEXE}"
    echotab "\$(RM) \$(DESTDIR)\$(lisplibdir)/base/lispinit.mem"
    echotab "\$(RM) \$(DESTDIR)\$(lisplibdir)/full/lisp${LEXE}"
    echotab "\$(RM) \$(DESTDIR)\$(lisplibdir)/full/lispinit.mem"
    echotab "\$(RM) \$(DESTDIR)\$(bindir)/clisp"
    if [ -n "$USE_GETTEXT" ] ; then
      echotab "cd po && \$(MAKE) uninstall prefix='\$(DESTDIR)\$(prefix)' exec_prefix='\$(DESTDIR)\$(exec_prefix)'"
    fi
    echol
    echol "uninstall-man : force"
    echotab "\$(RM) \$(DESTDIR)\$(mandir)/man1/clisp.1"
    case "$fsstnd" in
      gnu_ext)
        echotab "\$(RM) \$(DESTDIR)\$(htmldir)/clisp.html"
        echotab "\$(RM) \$(DESTDIR)\$(dvidir)/clisp.dvi"
        echotab "\$(RM) \$(DESTDIR)\$(psdir)/clisp.ps"
        ;;
      *bsd)
        echotab "\$(RM) \$(DESTDIR)\$(lispdocdir)/clisp.html"
        ;;
    esac
    echotab "for f in \$(READMES); do \$(RM) \$(DESTDIR)\$(lispdocdir)/\$\$f; done"
    case "$fsstnd" in
      *bsd)
        echotab "for f in \$(MANUALS) ${manual_dvi}; do \$(RM) \$(DESTDIR)\$(lispdocdir)/\$\$f; done"
        ;;
      *)
        echotab "for f in \$(MANUALS) ${manual_dvi}; do \$(RM) \$(DESTDIR)\$(lispdocdir)/doc/\$\$f; done"
        ;;
    esac
    echol
    echol
  fi
  if [ $HOS = os2 ] ; then
    echol "install : install-bin"
    echodummyrule install
    echol
    echol "installdirs : force"
    echotab "-mkdir \$(DESTDIR)\$(libdir)"
    echotab "-mkdir \$(DESTDIR)\$(lisplibdir)"
    echotab "-mkdir \$(DESTDIR)\$(bindir)"
    echol
    echol "install-bin : lisp${LEXE} lispinit.mem force"
    echotab "-mkdir \$(DESTDIR)\$(libdir)"
    echotab "-mkdir \$(DESTDIR)\$(lisplibdir)"
    echotab "-mkdir \$(DESTDIR)\$(lisplibdir)data"
    for f in ${DATA_FILES}; do
      echotab "\$(INSTALL_DATA) data/${f} \$(DESTDIR)\$(lisplibdir)data/${f}"
    done
    echotab "\$(INSTALL_PROGRAM) lisp${LEXE} \$(DESTDIR)\$(lisplibdir)lisp${LEXE}"
    echotab "\$(INSTALL_DATA) lispinit.mem \$(DESTDIR)\$(lisplibdir)lispinit.mem"
    echotab "-mkdir \$(DESTDIR)\$(bindir)"
    echotab "echo \$(lisplibdir)\lisp${LEXE} -M \$(lisplibdir)lispinit.mem %1 %2 %3 %4 %5 %6 %7 %8 %9 > \$(DESTDIR)\$(bindir)clisp.cmd"
    echol
    echol "uninstall : uninstall-bin"
    echodummyrule uninstall
    echol
    echol "uninstall-bin : force"
    for f in ${DATA_FILES}; do
      echotab "\$(RM) \$(DESTDIR)\$(lisplibdir)/data/${f}"
    done
    echotab "\$(RM) \$(DESTDIR)\$(lisplibdir)/lisp${LEXE}"
    echotab "\$(RM) \$(DESTDIR)\$(lisplibdir)/lispinit.mem"
    echotab "\$(RM) \$(DESTDIR)\$(bindir)/clisp.cmd"
    echol
  fi
fi

if [ $HOS = unix ] ; then
cat <<!!
# Choose one of the packers:

# Standard Unix packer. Compress afterwards.
#PACK = tar
#PACKOPT = -cvf
#PACKEXT = .tar

# GNU tar together with compress.
#PACK = tar
#PACKOPT = cvfhz
#PACKEXT = .tar.Z

# GNU tar together with GNU gzip. Excellent performance.
PACK = tar
PACKOPT = cvfhz
PACKEXT = .tar.gz

# Popular Amiga packer. Good performance.
#PACK = lha
#PACKOPT = a
#PACKEXT = .lzh

# Popular DOS packer.
#PACK = zip
#PACKOPT = -r
#PACKEXT = .zip

# Popular Atari packer.
#PACK = zoo
#PACKOPT = -add
#PACKEXT = .zoo

# Temporary directory for packing
PACKDIR = .

!!
echol "# The distribution's top directory"
if test -f "${SRCDIR}VERSION"; then
  echol "TOPDIR=clisp-`cat ${SRCDIR}VERSION`"
else
  if test -f "src/VERSION"; then
    echol "TOPDIR=clisp-`cat src/VERSION`"
  else
    echol "TOPDIR=clisp"
  fi
fi
echol
echol "# Distribution file"
PROC=`((uname -p) 2>/dev/null || mach 2>/dev/null) | $tolower`;
echol "DISTFILE=\$(PACKDIR)/\$(TOPDIR)-${HSYS:-unknown}-${PROC:-unknown}-${HSYSOS:-unknown}-`uname -r|sed 's/(.*)//g'`\$(PACKEXT)"
echol
needs='all'
if test "$HLN" != ln; then
  needs=$needs' hln'
  echol "hln :"
  echotab "mkdir -p buildhln"
  echotab "cd buildhln && ${PARENT_SRCTOPDIR}utils/hln/configure --srcdir=${PARENT_SRCTOPDIR}utils/hln && \$(MAKE)"
  echotab "ln buildhln/hln${TEXE} hln${TEXE}"
  echol
fi
echol "distrib : force $needs modular manualx clisp.c distmakefile"
echotab "\$(RMRF) \$(TOPDIR) \$(DISTFILE) clisp\$(PACKEXT)"
echotab "mkdir \$(TOPDIR)"
# General documentation files.
echotab "${HLN} ANNOUNCE COPYRIGHT GNU-GPL SUMMARY NEWS README README.de README.es MAGIC.add \$(TOPDIR)"
# The linking sets: base and full.
echotab "mkdir \$(TOPDIR)/base"
echotab "${HLN} ${FILES} modules.h modules.o makevars lispinit.mem \$(TOPDIR)/base"
if test -n "$BINARY_DISTRIB"; then
  echotab "cp lisp${LEXE} \$(TOPDIR)/base/lisp${LEXE}"
  # Don't strip the executable, otherwise (disassemble #'cons) won't work.
  # echotab "strip \$(TOPDIR)/base/lisp${LEXE}"
  echotab "chmod a+x \$(TOPDIR)/base/lisp${LEXE}"
fi
echotab "mkdir \$(TOPDIR)/full"
echotab "${HLN} "'`'". full/makevars ; for f in \$\$FILES modules.h modules.o makevars lispinit.mem ; do echo full/\$\$f ; done"'`'" \$(TOPDIR)/full"
if test -n "$BINARY_DISTRIB"; then
  echotab "cp full/lisp${LEXE} \$(TOPDIR)/full/lisp${LEXE}"
  # Don't strip the executable, otherwise (disassemble #'cons) won't work.
  # echotab "strip \$(TOPDIR)/full/lisp${LEXE}"
  echotab "chmod a+x \$(TOPDIR)/full/lisp${LEXE}"
fi
# The Makefile, generated from distmakefile.
if test -z "$BINARY_DISTRIB"; then
  echotab ". full/makevars ; full_files='' ; for f in modules.o \$\$FILES ; do full_files=\"\$\$full_files\"' full/'\"\$\$f\" ; done ; full_libs='' ; for f in modules.o \$\$LIBS ; do case \$\$f in -*) full_libs=\"\$\$full_libs \$\$f\";; *) full_libs=\"\$\$full_libs\"' full/'\"\$\$f\";; esac ; done ; sed -e \"s,@@FULL_FILES@@,\$\$full_files,\" -e \"s,@@FULL_LIBS@@,\$\$full_libs,\" < distmakefile > \$(TOPDIR)/Makefile"
else
  echotab "${HLN} distmakefile \$(TOPDIR)/Makefile"
fi
# Architecture independent data files.
if [ -n "$USE_GETTEXT" ] ; then
  echotab "for f in \`find locale -type d -print\`; do mkdir \$(TOPDIR)/\$\$f; done"
  echotab "for f in \`find locale -type f -print\`; do ${HLN} \$\$f \$(TOPDIR)/\$\$f; done"
fi
echotab "mkdir \$(TOPDIR)/data"
echotab "${HLN} data/* \$(TOPDIR)/data"
echotab "mkdir \$(TOPDIR)/doc"
echotab "${HLN} clisp.1 clisp.man ${manual_dvi} clisp.html \$(TXTFILES) \$(IMPNOTES) \$(TOPDIR)/doc"
echotab "mkdir \$(TOPDIR)/emacs"
for f in ${EMACS_FILES}; do
  echotab "${HLN} ${SRCTOPDIR}/emacs/${f} \$(TOPDIR)/emacs/${f}"
done
echotab "mkdir \$(TOPDIR)/src"
echotab "${HLN} \$(LISPFILES) \$(FASFILES) \$(TOPDIR)/src"
echotab "${HLN} clisp-link \$(TOPDIR)"
echotab "mkdir \$(TOPDIR)/linkkit"
echotab "${HLN} modules.d modules.c clisp.h \$(TOPDIR)/linkkit"
echotab "for module in '' \$(MODULES); do if test -n \"\$\$module\"; then \\"
echotab "  (dir=\$(TOPDIR)/ ; for subdir in "'`'"echo \$\$module/ | sed -e 's,/, ,g'"'`'" ; do dir=\$\${dir}\$\${subdir} ; test -d \$\${dir} || mkdir \$\${dir} ; dir=\$\${dir}/ ; done ; cd \$\$module ; dots="'`'"echo \$\$module/ | sed -e 's,[^/][^/]*//*,../,g'"'`'" ; \$(MAKE) clisp-module-distrib distribdir=\$\${dots}\$(TOPDIR)/\$\$module LN="`if test "$HLN" = ln; then echo 'ln'; else echo '$${dots}hln'; fi`") \\"
echotab "fi; done"
# For building the `clisp' executable.
if test -z "$BINARY_DISTRIB"; then
  echotab "${HLN} clisp.c \$(TOPDIR)/src"
else
  echotab_to_HEXE "\$(CC) \$(CFLAGS) \$(CLFLAGS) -DLISPLIBDIR='\"\$(lisplibdir)\"' -DLOCALEDIR='\"\$(localedir)\"'" clisp.c "\$(TOPDIR)/clisp"
  echotab_to_HEXE "\$(CC) \$(CFLAGS) \$(CLFLAGS)" "${UTILDIR_CC}hardcode.c" "\$(TOPDIR)/hardcode"
fi
# Final packing.
echotab "chmod a+r \$(TOPDIR) \$(TOPDIR)/* \$(TOPDIR)/*/*"
echotab "chmod a+x \$(TOPDIR)/. \$(TOPDIR)/*/."
echotab "\$(PACK) \$(PACKOPT) \$(DISTFILE) \$(TOPDIR)"
echotab "${HLN} \$(DISTFILE) clisp\$(PACKEXT)"
echotab "\$(RMRF) \$(TOPDIR)"
echol
echol
fi
if [ $HSYS = acorn ] ; then
  echol "distrib : force all manualx"
  echotab "-cdir ^.!Clisp"
  echotab "\$(CP) lisp ^.!Clisp.lisp"
  echotab "squeeze ^.!Clisp.lisp"
  echotab "-cdir ^.!Clisp.mem"
  echotab "\$(CP) mem.lispinit ^.!Clisp.mem.lispinit"
  for f in ANNOUNCE COPYRIGHT GNU-GPL SUMMARY NEWS README README.de README.es; do
    echotab "\$(CP) $f ^.!Clisp.$f"
  done
  echotab "-cdir ^.!Clisp.1"
  echotab "\$(CP) 1.clisp ^.!Clisp.1.clisp"
  echotab "-cdir ^.!Clisp.man"
  echotab "\$(CP) man.clisp ^.!Clisp.man.clisp"
  echotab "-cdir ^.!Clisp.html"
  echotab "\$(CP) html.clisp ^.!Clisp.html.clisp"
  echotab "\$(CP) html.impnotes ^.!Clisp.html.impnotes"
  echotab "\$(CP) css.impnotes ^.!Clisp.css.impnotes"
  echotab "\$(CP) png.clisp ^.!Clisp.png.clisp"
  echotab "\$(CP) el.clisp-coding ^.!Clisp.el.clisp-coding"
  echotab "\$(CP) el.clisp-indent ^.!Clisp.el.clisp-indent"
  echotab "\$(CP) lisp.clisp-indent ^.!Clisp.lisp.clisp-indent"
  echotab "\$(CP) txt.clhs ^.!Clisp.txt.clhs"
  echotab "\$(CP) txt.UnicodeDataFull ^.!Clisp.txt.UnicodeDataFull"
  echotab "settype ^.!Clisp.html.clisp FAF"
  echotab "-cdir ^.!Clisp.txt"
  for f in $DOC; do
    f=`echol $f | cut -c 1-10`
    echotab "\$(CP) txt.$f ^.!Clisp.txt.$f"
  done
  echotab "-cdir ^.!Clisp.lisp"
  for f in config timezone; do
    echotab "\$(CP) lisp.$f ^.!Clisp.lisp.$f"
  done
  echotab "\$(CP) ^.acorn.!Run ^.!Clisp.!Run"
  echotab "settype ^.!Clisp.!Run Obey"
  echotab "\$(CP) ^.acorn.!Sprites ^.!Clisp.!Sprites"
  echotab "settype ^.!Clisp.!Sprites Sprite"
  echol
fi
if [ $HOS = win32 ] ; then
  echol "# Distribution, to be executed on a Unix host or using Cygwin."
  echol "distrib : force"
  echotab "nroff -man clisp.1 > clisp.man"
  if [ $HOS = win32 ] ; then
    for f in clisp.html ; do
      echotab "sed -e 's,=\"CLHSROOT/,=\"${hyperspec}/,' -e \"s,VERSION,\`cat VERSION\`,\" < $f > $f.new"
      echotab "mv $f.new $f"
    done
  fi
  echotab "version=\`cat VERSION\` ; \\"
  echotab "distdir=clisp-\$\$version ; \\"
  echotab "distfile=clisp-\$\$version-win32.zip ; \\"
  echotab "mkdir \$\$distdir ; \\"
  echotab "for f in ANNOUNCE COPYRIGHT GNU-GPL SUMMARY NEWS README README.de README.es ; do \\"
  echotab "  if test -f \$\$f ; then cp -p \$\$f \$\$distdir/\$\$f ; else cp -p \`echo \$\$f | tr '[A-Z]' '[a-z]'\` \$\$distdir/\$\$f ; fi ; \\"
  echotab "done ; \\"
  echotab "for f in lisp.exe lispinit.mem install.bat ; do \\"
  echotab "  cp -p \$\$f \$\$distdir/\$\$f ; \\"
  echotab "done ; \\"
  echotab "mkdir \$\$distdir/data ; \\"
  for f in ${DATA_FILES}; do
    echotab "cp -p data/${f} \$\$distdir/data/${f} ; \\"
  done
  echotab "mkdir \$\$distdir/doc ; \\"
  echotab "for f in clisp.1 clisp.man clisp.html \$(TXTFILES) \$(IMPNOTES) ; do \\"
  echotab "  if test -f \$\$f ; then cp -p \$\$f \$\$distdir/doc/\$\$f ; else cp -p \`echo \$\$f | tr '[A-Z]' '[a-z]'\` \$\$distdir/doc/\$\$f ; fi ; \\"
  echotab "done ; \\"
  echotab "mkdir \$\$distdir/emacs; \\"
  for f in ${EMACS_FILES}; do
    echotab "cp -p ${SRCTOPDIR}emacs/${f} \$\$distdir/emacs/${f} ; \\"
  done
  echotab "mkdir \$\$distdir/src ; \\"
  echotab "cp -p \$(LISPFILES) install.lisp \$\$distdir/src/ ; \\"
  echotab "chmod 755 \$\$distdir/. \$\$distdir/*/. ; \\"
  echotab "chmod 644 \`find \$\$distdir -type f -print\` ; \\"
  echotab "rm -f \$\$distfile ; \\"
  echotab "(echo \"CLISP version \$\$version for Win32.\"; echo \".\") | zip -r -9 -z \$\$distfile \$\$distdir ; \\"
  echotab "\$(RMRF) \$\$distdir"
  echol
fi

cat <<!!
# clean0 is harmless: removes only superfluous things: temporary files.
clean0 : force
	-\$(RM) core${OBSOLETE}
	-\$(RMRF) linkkit

# clean1 removes everything that becomes obsolete once lisp${LEXE} is recompiled
# without changing the bytecode format and the tables in
# constobj.d, constpack.d, constsym.d, subr.d, fsubr.d, pseudofun.d.
clean1 : clean0
	-\$(RM) lispbibl.h clisp.h *.i *.s *${TOBJ} *.a lisp${LEXE} clisp-link makevars ${TESTDIR}${NEXT_}* ${TESTSDIR}${NEXT_}*
	-\$(RMRF) base full
!!
if [ ${LIB_TYPE} = "win32" ] ; then
cat <<!!
	-\$(RM) charset.lib avcall.lib callback.lib
!!
else
cat <<!!
	-\$(RM) libcharset.* libavcall.* libcallback.*
!!
fi
cat <<!!
	-rmdir ${TESTDIR}
	-rmdir ${TESTSDIR}
	-\$(RM) README README.de README.es clisp.1 clisp.man clisp.dvi clisp.ps clisp.html \$(IMPNOTES) clisp.c distmakefile \$(TXTFILES)

# clean2 removes everything that becomes obsolete once lisp${LEXE}
# is recompiled without changing the bytecode format.
clean2 : clean1
	-\$(RM) $interpreted.mem $halfcompiled.mem lispinit.mem lispinit2.mem

# clean3 removes everything that becomes obsolete once lisp${LEXE}
# is recompiled. It leaves everything generated by "make allc".
clean3 : clean2
	-\$(RM) \$(FASFILES) *.lib

# clean4 removes everything that becomes obsolete
# when switching to a new version of the C compiler.
# It leaves everything generated by "make init".
clean4 : clean3
	-\$(RM) \$(CFILES)
!!
if [ -n "$with_dynamic_ffi" ] ; then
cat <<!!
	-\$(RM) avcall.h
	-\$(RM) callback.h vacall_r.h trampoline_r.h
!!
fi
if [ -n "$USE_GETTEXT" ] ; then
cat <<!!
	cd po && \$(MAKE) clean
	-\$(RMRF) locale
!!
fi
if [ -n "$USE_LIBCHARSET" ] ; then
cat <<!!
	-\$(RM) libcharset.h
	-\$(RM) charset.alias
!!
fi
cat <<!!
	-\$(RM) stdbool.h
	-\$(RM) stdint.h

# clean5 even undoes "make init".
!!
echol "clean5 : clean4"
echotab "-\$(RM) ANNOUNCE COPYRIGHT GNU-GPL SUMMARY"
if [ -n "${SRCDIR}" ] ; then
  line="-\$(RM)"
  line="$line \$(DFILES)"
  for f in $UNICODE_INCLUDES $NLS_INCLUDES ; do
    line="$line ${f}.c"
  done
  line="$line version.h modules.h"${UNICODE_EXTRA}
  line="$line \$(LISPFILES) NEWS clisp.png"
  if [ ${HOS} = win32 ]; then
    line="$line clisp.ico";
  fi
  echotab "$line"
  if [ $HOS = unix -a $CROSS = false ] ; then
    echotab "-\$(RM) .gdbinit"
  fi
else
  echotab "-\$(RM) config.lisp"
fi
if [ $TOS = unix ] ; then
  echotab "-\$(RM) MAGIC.add"
fi
echotab "-\$(RMRF) data"
line="clisp${HEXE} clisp.rc"
for f in ${UTILS}; do line=$line" ${f}${HEXE}"; done
for f in ${LUTILS}; do line=$line" ${f}.fas ${f}.lib"; done
echotab "-\$(RM) ${line}"
echol
cat <<!!
# clean6 lets us go back to "makemake > Makefile".
clean6 : clean5
	-\$(RM) Makefile

# clean7 lets us go back to the main "configure".
clean7 : clean6
	-\$(RM) config.status config.log config.cache ${PARAMS_H} unixconf.h makemake
!!
if [ -n "$USE_GETTEXT" ] ; then
cat <<!!
	cd po && \$(MAKE) distclean
	-\$(RMRF) locale
!!
fi
if [ $HOS = unix -a $CROSS = false ] ; then
cat <<!!
	-\$(RMRF) \`ls -d ${SRCTOPDIR}modules/*/. | sed -e 's,/\.\$\$,,' -e 's,^.*/,,' | grep -v '^CVS\$\$'\`
!!
fi
cat <<!!
	-\$(RMRF) avcall
	-\$(RMRF) callback
	-\$(RMRF) libcharset
!!
if [ -n "${SRCDIR}" ] ; then
cat <<!!
	-\$(RMRF) po
	-\$(RM) configure unixconf.h.in makemake.in VERSION
!!
fi
cat <<!!

# clean8 moreover cleans up the SRCDIR.
clean8 : clean7

# The normal "start over" command:
mostlyclean : clean4

# Clear all files that are built by "make ...":
clean : clean5

# Make "clear for distribution":
distclean : clean7

# Remove everything that can be generated otherwise:
maintainer-clean : clean8

!!

echol

# Without this NeXT's make program tries to compile via c -> s -> o
echol ".SUFFIXES:"
echodummyrule .SUFFIXES
echol

echol "force:"
echodummyrule force

echol

