# 
#  Copyright (c) 1989 Regents of the University of California
#  
#  Permission to use, copy, modify, and distribute this software and its
#  documentation for any purpose and without fee is hereby granted,
#  provided that the above copyright notice appear in all copies and
#  that both that copyright notice and this permission notice appear in
#  supporting documentation, and that the name of the University of
#  California not be used in advertising or publicity pertaining to
#  distribution of the software without specific, written prior
#  permission.  The University of California makes no representations
#  about the suitability of this software for any purpose.  It is
#  provided "as is" without express or implied warranty.
#  

# ==================================================================
#
# Edit the following lines:
#
# Home directory:  the location of ~picasso
HOME = /pic1/picasso

# Location of lisp library (must be writable by picasso)
LISPLIB = /usr/local/lib/cl/code

SUB-DIRS   = clx pcl pds libpq

# Name of common lisp
CL = /usr/local/cl

# C compiler 
CC	= /bin/cc

# ==================================================================
# Command to return type of machine
GET-MACHTYPE = $(HOME)/bin/machtype

# Command to get level from current directory
GET-LEVEL = $(HOME)/bin/srclevel2

# Command to get appropriate cc flags
GET-CFLAGS = $(HOME)/bin/cflags

# Type of lisp
LISPTYPE = allegro

# source tree
SRC-DIR    = $(HOME)/$(LEVEL)/src/sys
BIN-DIR    = $(HOME)/$(LEVEL)/build/$(LISPTYPE)/$(MACHTYPE)/sys

# Name of dump to create
DUMP = $(HOME)/$(LEVEL)/dumps/$(MACHTYPE)/pcl-clx

# Lisp optimizations
SPEED	= 1
SAFETY	= 1

# Lisp extensions
LISP	= cl
FASL	= fasl

CFILES= 
OFILES= 
#
# Make transformation rules
#

default		: usage

usage		:
		@echo "Possible usages:"
		@echo "	% make pcl-clx: make pcl-clx for this architecture."
		@echo "	% make compile-pcl: recompile pcl for this arch."
		@echo "	% make compile-clx: recompile clx for this arch."
		@echo "	% make compile-pds: recompile pds for this arch."
		@echo "	% make compile-libpq: recompile libpq for this arch."
		@echo "	% make compile-cling: recompile cling for this arch."
		@echo "	% make compile-sling: recompile sling for this arch."
		@echo "	% make compile: Compile pcl-clx."
		@echo " % make load: Make pcl-clx dump without recompiling. "
		@echo "	% make tidy: Remove backup files."
		@echo "	% make clean: Remove object/backup/fasl files."

compile         :
		make do-compile MACHTYPE=`$(GET-MACHTYPE)` \
		CFLAGS=`$(GET-CFLAGS) $(MACHTYPE)` \
		LEVEL=`$(GET-LEVEL) \`pwd\``

load         	:
	        make do-load MACHTYPE=`$(GET-MACHTYPE)` \
	        CFLAGS=`$(GET-CFLAGS) $(MACHTYPE)` \
	        LEVEL=`$(GET-LEVEL) \`pwd\``

pcl-clx         :
	        make do-pcl-clx MACHTYPE=`$(GET-MACHTYPE)` \
	        CFLAGS=`$(GET-CFLAGS) $(MACHTYPE)` \
	        LEVEL=`$(GET-LEVEL) \`pwd\``

compile-pcl		:
		make do-compile MACHTYPE=`$(GET-MACHTYPE)` \
		CFLAGS=`$(GET-CFLAGS) $(MACHTYPE)` \
		LEVEL=`$(GET-LEVEL) \`pwd\``
		SUB-DIRS=pcl

compile-clx		:
		make do-compile MACHTYPE=`$(GET-MACHTYPE)` \
		CFLAGS=`$(GET-CFLAGS) $(MACHTYPE)` \
		LEVEL=`$(GET-LEVEL) \`pwd\`` \
		SUB-DIRS=clx

compile-cling		:
		make do-compile MACHTYPE=`$(GET-MACHTYPE)` \
		CFLAGS=`$(GET-CFLAGS) $(MACHTYPE)` \
		LEVEL=`$(GET-LEVEL) \`pwd\`` \
		SUB-DIRS=cling

compile-sling		:
		make do-compile MACHTYPE=`$(GET-MACHTYPE)` \
		CFLAGS=`$(GET-CFLAGS) $(MACHTYPE)` \
		LEVEL=`$(GET-LEVEL) \`pwd\`` \
		SUB-DIRS=sling

compile-pds		:
		make do-compile MACHTYPE=`$(GET-MACHTYPE)` \
		CFLAGS=`$(GET-CFLAGS) $(MACHTYPE)` \
		LEVEL=`$(GET-LEVEL) \`pwd\`` \
		SUB-DIRS=pds

compile-libpq		:
		make do-compile MACHTYPE=`$(GET-MACHTYPE)` \
		CFLAGS=`$(GET-CFLAGS) $(MACHTYPE)` \
		LEVEL=`$(GET-LEVEL) \`pwd\`` \
		SUB-DIRS=libpq

clean           :
	        make do-clean MACHTYPE=`$(GET-MACHTYPE)` \
	        CFLAGS=`$(GET-CFLAGS) $(MACHTYPE)` \
	        LEVEL=`$(GET-LEVEL) \`pwd\``

tidy            :
	        make do-tidy MACHTYPE=`$(GET-MACHTYPE)` \
	        CFLAGS=`$(GET-CFLAGS) $(MACHTYPE)` \
	        LEVEL=`$(GET-LEVEL) \`pwd\``

do-compile	: 
		( \
		for p in $(SUB-DIRS); do \
		   case $$p in \
	            clx)  ( cd clx ; make LIBDIR=$(BIN-DIR)/clx \
					  CFLAGS=$(CFLAGS) \
	                                  CL=$(CL) ) ; \
	                  /bin/cp $(BIN-DIR)/clx/clx.fasl \
	                          $(LISPLIB)/pic-clx.fasl ; \
			  /bin/cp $(BIN-DIR)/clx/*.o $(LISPLIB) ;; \
		    pcl)  echo "(proclaim '(optimize (speed $(SPEED))))" \
	                       "(proclaim '(optimize (safety $(SAFETY))))" \
			       '#+allegro' \
			       "(tpl:setq-default *redefinition-warnings* nil)"\
			       '(load "pcl/defsys") '\
			       '(pcl::compile-pcl) '\
			       '(excl:exit)' | $(CL) -qq ;; \
		    pds)  (cd pds ; make LIBDIR=$(BIN-DIR)/pds \
	                                 CL=$(CL) ) ; \
	                  /bin/cp $(BIN-DIR)/pds/pds.fasl $(LISPLIB) ;; \
		    libpq)  (cd libpq ; make LIBDIR=$(BIN-DIR)/libpq \
					     CFLAGS=$(CFLAGS) \
	                                     CL=$(CL) ) ; \
	                    /bin/cp $(BIN-DIR)/libpq/libpq.fasl \
				    $(BIN-DIR)/libpq/*.o \
				    $(LISPLIB) ;; \
		    cling)  (cd cling ; make LIBDIR=$(BIN-DIR)/cling \
					     CFLAGS=$(CFLAGS) \
	                                     CL=$(CL) ) ; \
	                    /bin/cp $(BIN-DIR)/cling/cling.fasl \
				    $(BIN-DIR)/cling/*.o \
				    $(LISPLIB) ;; \
		    sling)  (cd sling ; make LIBDIR=$(BIN-DIR)/sling \
					     CFLAGS=$(CFLAGS) \
	                                     CL=$(CL) ) ; \
	                    /bin/cp $(BIN-DIR)/sling/sling.fasl \
				    $(BIN-DIR)/sling/*.o \
				    $(LISPLIB) ;; \
		    *)	echo "Unknown subsystem for pcl-clx:  ignored" ;; \
	           esac ; done  \
		)

do-pcl-clx:	$(CL) do-compile dump

do-load:	dump

dump:	
	( \
	 cd $(BIN-DIR) ;\
	 echo '#+allegro' \
	    "(tpl:setq-default *redefinition-warnings* nil)" \
	    "(setf (system:gsgc-parameter :generation-spread) 1)" \
	    "(setq pcl-clx-pkgs '($(SUB-DIRS)))" \
	    "(chdir \"clx\") " \
	    "(when (member 'clx pcl-clx-pkgs) (load \"clx.fasl\"))" \
	    "(chdir \"$(SRC-DIR)\")" \
	    "(when (member 'pcl pcl-clx-pkgs)" \
	          "(load (concatenate 'string \"$(SRC-DIR)\"" \
	                                      "\"/pcl/defsys\")))" \
	    "(when (member 'pcl pcl-clx-pkgs)" \
	          "(pcl::load-pcl))" \
	    "(chdir \"$(BIN-DIR)\")" \
	    "(chdir \"pds\" )" \
	    "(when (member 'pds pcl-clx-pkgs) (load \"pds.fasl\"))" \
	    "(chdir \"../libpq\" )" \
	    "(when (member 'libpq pcl-clx-pkgs) (load \"libpq.fasl\"))" \
	    "(chdir \"../cling\" ) " \
	    "(when (member 'cling pcl-clx-pkgs) (load \"cling.fasl\"))" \
	    "(chdir \"../sling\" ) " \
	    "(when (member 'sling pcl-clx-pkgs) (load \"sling.fasl\"))" \
	    "(excl:gc :tenure)" \
	    "(excl:gc :tenure)" \
	    "(excl:gc t)" \
	    "(setf (system:gsgc-parameter :generation-spread) 4)" \
	    "(excl:dumplisp :name \"$(DUMP)\")" \
	    "(excl:exit)" | $(CL) -qq > $(SRC-DIR)/make.$(MACHTYPE).out ; \
	)

do-clean	: do-tidy
		for i in $(SUB-DIRS); do \
			(old=`pwd`; cd $(BIN-DIR)/$$i; \
			 rm -f tags TAGS *.o *.$(FASL); \
			 cd $$old); \
		done

do-tidy		:
		for i in $(SUB-DIRS); do \
			(old=`pwd`; cd $(SRC-DIR)/$$i; \
			 rm -f *.out core *~ \#* *.o ; \
			 cd $$old); \
		done

.PRECIOUS:	$(DUMP)
