.SUFFIXES: .c .V

# Fix up local paths, machine, etc in file h/`machine`.defs
# which will be inserted just below this point in several makefiles.

CC=cc
# begin makedefs
AKCLDIR=/usr/public/akcl
SHELL=/bin/sh
MACHINE=hp300-bsd

# Machine dependent makefile definitions for hp300 running 4.3bsd(mt xinu)

LBINDIR=/usr/local/bin

OFLAG	=  -O 
LIBS	= -lm -lg 
ODIR_DEBUG= -g

# This CC string will be used for compilation of the system,
# and also in the compiler::*cc* variable for later compilation of
# lisp files.

CC = gcc -fwritable-strings -msoft-float -DVOL=volatile -I$(AKCLDIR)/o 
MAINDIR = /public/kcl

# Enable the fastloading mechanism which does not use ld -A
# requires c/rel_.. machine dependent code.

RSYM	= rsym
SFASL	= $(ODIR)/sfasl.o

#  Use the mp.s file on 68k machine 

MPFILES= $(MPDIR)/mpi-bsd68k.o   $(MPDIR)/libmport.a


# When using SFASL it is good to have (si::build-symbol-table)
INITFORM=(si::build-symbol-table)

# Use symbolic links
SYMB=-s

LIBFILES=bsearch.o

# the  make to use for saved_kcp the profiler.
KCP=kcp-bsd
# end makedefs

HDIR = h
CHANGED=nevernever.c
BOTH=nevernever
MERGE=./merge

all: h/config.h V/cmpnew/cmpvar.lsp
# If the links have not yet been made do it:
# set SYMB=-s in relink-script if you want symbolic links
	xbin/if-exists xbin/${MACHINE}-fixes "sh xbin/${MACHINE}-fixes"
	xbin/relink-files $(MAINDIR) $(SYMB)
	make -f Smakefile merge
	make -f Smakefile sources
	@ rm -f   c/include.h
	make -f Smakefile cmpinclude  
	make -f  makefile  all  "CC=$(CC)" "SU=$(SU)"
# 	second pass may recompile some cmpnew and lsp files.
	make -f makefile all "CC=$(CC)" "SU=$(SU)"
# 	After making successfully send in a notification to
#	akcl@nicolas.ma.utexas.edu.   This is extremely helpful in
#	tracking on which machines and OS versions there are problems.
#	This will be done automatically by the  xbin/notify line.
	@- if  fgrep ASSIGN-DOWN cmpnew/cmpvar.c > /dev/null ; \
	then echo "Make of AKCL `cat minvers` completed." ; \
	xbin/notify "CC=${CC}" ; \
	else echo "The second pass of make failed to compile the new compiler" ;fi

h/config.h:
	@ echo You should read the README file first:  You forgot to do
	echo "% add-defs machine-name"
	exit 1
	
V/cmpnew/cmpvar.lsp: ${MAINDIR}/cmpnew/cmpvar.lsp
	@ echo You MUST restore the kcl.tar.Z and akcl.tar.Z with original write dates
	@ echo No file in 'V/*/*' should be older than any file in ${MAINDIR}.
	@ echo extract the files again or maybe touch 'V/*' 'V/*/*' 'V/*/*/*'
	exit 1

Vmakefile:  V makedefs
	xbin/make-Vmake > Vmakefile

sources: $(MERGE) Vmakefile
	make -f Vmakefile
	rm -f c/num_include.h c/include.h


merge:  merge.c
	${CC} -O merge.c -o $(MERGE)

remove-linked-changes:
	echo rm -f bin/dpp c/include.h V/* */V/* | sed s:V/::g | sh

chown:
	echo su and make -f Smakefile chown1
chown1:
	chown $(LOGNAME) o cmpnew lsp unixport c h doc xbin . \
	Smakefile   V/*  */V/* 

clean-V:
	for v in */V/* ; do \
		echo mv $$v $$v.old | sed s:V/::g | sh  ;  \
		echo ln -s ../standard-kcl/$$v $$v | sed s:V/::g | sh ;  \
	done
	for v in V/*; do \
		echo mv $$v $$v.old | sed s:V/::g | sh  ;  \
		echo ln -s standard-kcl/$$v $$v | sed s:V/::g | sh ;  \
	done

setup:
	make -f Smakefile remove-linked-changes
	make -f Smakefile chown1
	echo "xbin/relink-script $(MAINDIR) `pwd`"  | sh
	



cmpinclude:
	for v in c lsp o cmpnew unixport; do \
		rm -f $$v/cmpinclude.h ; \
		ln  h/cmpinclude.h  $$v/cmpinclude.h ; \
	done

tar:
	tar cf ../xkcl.tar .
	
clean:	
	rm -f *~ #* */*~ */#* merge
	for v in o unixport cmpnew lsp ; do  (cd $$v ; make clean ); done

sunview:
	$(MERGE) standard-kcl/unixport/makefile sunv/chang sunv/makefile
	make -f Smakefile "PORTDIR=sunv"


# remove the c files from the changed version, and relink them to 
# the MAINDIR.
redolsp: 
	for v in `echo lsp/V/*.lsp cmpnew/V/*.lsp | sed -e "s:\.lsp::g" -e "s:V/::g"` ;
	do rm -f $$v.lsp $$v.c $$v.data $$v.o ;
	ln $(MAINDIR)/$$v.lsp $$v.lsp ;
	ln $(MAINDIR)/$$v.c $$v.c ;
	ln $(MAINDIR)/$$v.data $$v.data ;
	ln $(MAINDIR)/$$v.h $$v.h ;
	rm unixport/saved_kcl;
	make ;
	make;


doc:
	(cd doc ; make install "LBINDIR=$(LBINDIR)")

xbin/print_doc: xbin/print_doc.c
	$(CC) xbin/print_doc.c -o xbin/print_doc
	

lsp/DOC:  
	echo '(load "lsp/setdoc.lsp")(load "lsp/doc-file.lsp")(doc-file "lsp/DOC" (quote(lisp si)))' | xbin/kcl 


kcp:
	(cd go ; make  "CFLAGS = -I../h -pg  -c -g ")
	(cd unixport ; make kcp)

	
	
	