# Makefile to distribute, compile and install SNePS on various hosts
#
# hc, May 4, 91
#
# RCS: $Id: Makefile,v 1.2 1993/07/08 10:07:18 snwiz Exp $
#
# This Makefile provides support for distribution, compilation and
# installation of SNePS on various hosts. It assumes the following
# setup: 
# 
#    A Master directory as the unique SNePS source, from which
#    distribution copies on remote hosts can be made via rdist.
# 
#    On each remote host there has to be a directory that contains the
#    following link setup:
#    /...directory on remote host...:
#       lrwxrwxrwx  1 snwiz           9 May  8 18:55 Dist -> Sneps-B
#       drwxr-xr-x  2 snwiz         512 May  8 15:26 Sneps-A
#       drwxr-xr-x 13 snwiz        1024 May  8 18:53 Sneps-B
#       lrwxrwxrwx  1 snwiz           9 May  8 18:55 Temp -> Sneps-A
#    Then names of the actual sub-directories are arbitrary, the names
#    of the links Dist and Temp are hardcoded in the Makefile and tools.
# 
# Distribution to a remote host:
# ==============================
# The basic idea is that each remote host that supports SNePS
# contains a distribution copy that people are currently using, and which
# is loaded via a load file that uses /...../Dist as the *sneps-directory*
# load pathname. When an updated copy should get installed on the remote
# host, the working version that people currently use should not get
# affected until the installation of the new version is successfully
# completed. Hence we use the directory pointed to by the Temp link for
# the installation of the updated SNePS system. Here are the steps: 
#    - rdist from the Master directory to the remote Temp directory with
#      help of the Distfile contained in this directory
#    - Compile SNePS on the remote host. For this step it is
#      important that we use the actual pathname to which Temp points in
#      all the compile-file calls, because this pathname gets hardcoded
#      into the object files, where it is used for edit-definition
#      support (i.e., automatic location of source code for SNePS
#      functions/variables/etc.). 
#    - Swap the links Dist and Temp on the remote host. Now the load
#      file will automatically load the new version (pointed to by
#      Dist), and edit-definition will still be able to find source code
#      because the actual directory name has not changed (just swapping
#      the names of Sneps-A and Sneps-B would have screwed this up,
#      hence we have to use links).
#
# The make targets ...-dist, ...-compile and ...-install refer to
# these 3 steps, e.g., `make ucs-dist' will distribute SNePS to the
# UCS file system, `make ucs-dist ucs-compile ucs-install' will
# perform the complete installation.
# 
#
# How to distribute a new SNePS release from the Master directory:
# ================================================================
# - cd to ~snwiz/src/Sneps21/All-Lisps/Master/Tools
# - make dist-compile-all
# - Once the source has been completely distributed to ${CS_HOST} one can
#   start the compilation on the Lisp machines by loading sneps-compile.lisp
#   and executing (compile-sneps "Sneps-B") (assuming Temp points to the
#   Sneps-B directory)
# - Check whether all compilations completed successfully by checking the 
#   ...-compilation.log files in the Temp/Logs/ directories on the various 
#   machines.
# - Now do make install-all (mail will be sent after successful installation)
#
#
# Variable Naming Conventions:
# ===========================
# All .._DIR variables refer to parent directories which can be used to
# create actual SNePS directory names by appending Dist, Temp or
# Master. 


.IGNORE:         # Most remote commands return nonzero status -> ignore

SHELL = /bin/csh

SNEPS_SOURCE = /u6/rstaff/snerg/src/Sneps21/All-Lisps/Master

# Mirrors the corresponding Distfile variable in shell syntax, it is
# used to delete all object files (i.e., .sbin .fasl .xld .bin)
SNEPS_EXCEPT_PAT = *.[sfxb][balip][aisdn]* 

# CS-Department machine parameters:
CS_DIR = /u6/rstaff/snerg/src/Sneps21/All-Lisps
CS_CLISP1 = scl-clos
CS_CLISP2 = acl
CS_HOST = pegasus
CS_INSTALLER = snwiz
CS_X_SERVER = weisse.cs.buffalo.edu

# Tape directory from which distribution tapes can be written:
CS_TAPE_DIR = /u6/rstaff/snerg/src/Sneps21/All-Lisps/tape

# USPS machine parameters:
USPS_DIR = /DIUG/snerg/src/Sun4
USPS_CLISP = /DIUG/snerg/cl4/acl
USPS_HOST = pleiades
USPS_INSTALLER = hans

# UCS machine parameters:
UCS_DIR = /home/staff/cs/snwiz/src/Sneps21
UCS_CS_DIR = /net/hadar.cs/u6/rstaff/snerg/src/Sneps21/All-Lisps
UCS_CLISP = acl
UCS_HOST = vodalus.acsu
UCS_CS_HOST = lictor.acsu            # UCS host that mounts CS partitions
UCS_INSTALLER = snwiz

# These parameters are used for recursive calls to make that call
# generic targets such as compile or dist-compile:
LISP_DIR = ${CS_DIR}        # The parent directory of the actual SNePS tree
SNEPS_NAME = Temp           # the name of the actual SNePS tree
CLISP = ${CS_CLISP1}        # the name of the common lisp program to use
LISP_HOST = ${CS_HOST}      # the name of the host to run the compilation on
X_SERVER = ${CS_X_SERVER}   # name of a running X server
INSTALLER = ${CS_INSTALLER} # login on machine on which SNePS gets installed


cs-dist:
	rdist -d SNEPS_HOST=${CS_HOST} \
              -d SNEPS_INSTALLER=${CS_INSTALLER} \
              -d SNEPS_SOURCE=${SNEPS_SOURCE} \
              -d SNEPS_TARGET=${CS_DIR}/Temp sneps-dist
cs-compile:
	make LISP_HOST=${CS_HOST} LISP_DIR=${CS_DIR} \
             CLISP=${CS_CLISP1} INSTALLER=${CS_INSTALLER} \
             ${MFLAGS} dist-compile &; \
	make LISP_HOST=${CS_HOST} LISP_DIR=${CS_DIR} \
             CLISP=${CS_CLISP2} INSTALLER=${CS_INSTALLER} \
             ${MFLAGS} dist-compile
cs-install:
	make LISP_HOST=${CS_HOST} LISP_DIR=${CS_DIR} \
             CLISP=${CS_CLISP1} INSTALLER=${CS_INSTALLER} \
             ${MFLAGS} dist-install

tape-dist:
	rdist -d SNEPS_HOST=${CS_HOST} \
              -d SNEPS_INSTALLER=${CS_INSTALLER} \
              -d SNEPS_SOURCE=${CS_DIR}/Dist \
              -d SNEPS_TARGET=${CS_TAPE_DIR} sneps-dist

usps-dist:
	rdist -d SNEPS_HOST=${USPS_HOST} \
              -d SNEPS_INSTALLER=${USPS_INSTALLER} \
              -d SNEPS_SOURCE=${SNEPS_SOURCE} \
              -d SNEPS_TARGET=${USPS_DIR}/Temp sneps-dist
usps-compile:
	make LISP_HOST=${USPS_HOST} LISP_DIR=${USPS_DIR} \
             CLISP=${USPS_CLISP} INSTALLER=${USPS_INSTALLER} \
             ${MFLAGS} dist-compile
usps-install:
	make LISP_HOST=${USPS_HOST} LISP_DIR=${USPS_DIR} \
             CLISP=${USPS_CLISP} INSTALLER=${USPS_INSTALLER} \
             ${MFLAGS} dist-install

ucs-dist: 
	rdist -d SNEPS_HOST=${UCS_HOST} \
              -d SNEPS_INSTALLER=${UCS_INSTALLER} \
              -d SNEPS_SOURCE=${SNEPS_SOURCE} \
              -d SNEPS_TARGET=${UCS_DIR}/Temp sneps-small-dist
ucs-compile:
	make LISP_HOST=${UCS_HOST} LISP_DIR=${UCS_DIR} \
             CLISP=${UCS_CLISP} INSTALLER=${UCS_INSTALLER} \
             ${MFLAGS} dist-compile
ucs-install: 
	make LISP_HOST=${UCS_HOST} LISP_DIR=${UCS_DIR} \
             CLISP=${UCS_CLISP} INSTALLER=${UCS_INSTALLER} \
             ${MFLAGS} dist-install

# Do installation in an extra step, because on the CS machine
# we have to do Explorer and Symbolics compilation `by hand' first.
# Once these compilations have completed we can call it a release
# and do `make install-all'
dist-compile-all:
	make cs-dist cs-compile ${MFLAGS} &; \
        make usps-dist usps-compile ${MFLAGS} &; \
        make ucs-dist ucs-compile ${MFLAGS}; \
        wait

install-all:
	make cs-install ${MFLAGS} &; \
	make usps-install ${MFLAGS} &; \
	make ucs-install ${MFLAGS}; \
        wait


dist-compile:
	setenv TEMP_ACTUAL \
               `rsh ${LISP_HOST} -l ${INSTALLER} "cd ${LISP_DIR}/Temp/Tools;                       dereflink ${LISP_DIR} Temp"` ; \
        rsh ${LISP_HOST} -l ${INSTALLER} \
            "cd ${LISP_DIR}/Temp/Tools; \
             make LISP_DIR=${LISP_DIR} SNEPS_NAME=$$TEMP_ACTUAL                                    CLISP=${CLISP} INSTALLER=${INSTALLER} ${MFLAGS}                                binclean compile"

dist-install:
	rsh ${LISP_HOST} -l ${INSTALLER} \
            "cd ${LISP_DIR}/Temp/Tools; \
             install-sneps ${LISP_DIR} ${CLISP} ${INSTALLER}"

# This removes all binary files
binclean-old:
	find ${LISP_DIR}/${SNEPS_NAME}/ \
             -name '${SNEPS_EXCEPT_PAT}'  -exec "rm" {} \; 
binclean:
	find ${LISP_DIR}/${SNEPS_NAME}/ \
             \( -name '*.sbin' -o -name '*.fasl' -o -name '*.xld' -o \
                -name '*.sparcf' -o -name '*.bin' \) \
             -exec "rm" {} \; 

compile:
	setenv DISPLAY ${X_SERVER}:0 ; \
	echo \(load \"compile-sneps.lisp\"\) \
             \(compile-sneps \"${SNEPS_NAME}\" \
                      :parent \"${LISP_DIR}\" \
                      :dribble-on nil \) | \
	${CLISP} >& \
             ${LISP_DIR}/${SNEPS_NAME}/Logs/`basename ${CLISP}`-compilation.log


# Some special targets to compile the Master directory:
master-compile-scl: 
	make LISP_DIR=${CS_DIR} SNEPS_NAME=Master \
             CLISP=${CS_CLISP1} INSTALLER=${CS_INSTALLER} ${MFLAGS} compile

master-compile-allegro:
	rsh ${UCS_CS_HOST} -l ${UCS_INSTALLER} \
            "cd ${UCS_CS_DIR}/Master/Tools; \
             make LISP_DIR=${UCS_CS_DIR} SNEPS_NAME=Master                                         CLISP=${UCS_CLISP1} INSTALLER=${UCS_INSTALLER}                                  ${MFLAGS} compile"

master-compile-all: 
	make ${MFLAGS} master-compile-scl &; \
        make ${MFLAGS} master-compile-allegro; \
        wait
	chmod -R ugo+rX ${CS_DIR}/Master/*
	chmod -R go-w   ${CS_DIR}/Master/*

# For expansion of symbolic links:
slinkdir: slinkdir.c
	cc -o slinkdir slinkdir.c

