. ../../config/system
. ../../config/site

echo Building Makefile.local...
cat <<EOT >Makefile.local
# Makefile for zelk extensions
# This Makefile was produced by running ./build in this directory!
# EDIT BUILD, not this file.
# modified
# 22sep92

# the top level directory of the elk source
ELKTOP=	$elktop

# where is the top level directory of the elk source relative to a 
# subdirectory of the current directory.  If ELKTOP is absolute,
# this is ELKTOP, otherwise this is ../$(ELKTOP)
# TOP_SUBDIR=	../../..
# TOP_SUBDIR=	$(ELKTOP)

SHELL=		/bin/sh
TSCM=		$(ELKTOP)/scm
LIBSCM=		$scheme_dir

# put target elk before zelk
all:		TOPLEVEL SCM ELK ZELK ZLIB

# install modified scheme toplevel
# copy toplevel to $elktop/scm; the top-level/scm install copies it
# from there into $scheme_dir 
# copy basics directly to $scheme_dir because the top level scm install
# does not know about this file.
TOPLEVEL:
		if [ -f \$(TSCM)/toplevel -a ! -f \$(TSCM)/toplevel.orig ];\\
		then cp \$(TSCM)/toplevel \$(TSCM)/toplevel.orig ; fi
		cp scm/toplevel \$(TSCM)
		cp scm/basics \$(LIBSCM)
		#cp scm/.elkrc \$(HOME)

# install SCM library files
SCM:
		echo installing scm library files
		cd scm; set -x; \\
		for i in * ;\\
		do # use diff to check that files are not already copied\\
		  ( diff \$\$i \$(LIBSCM)/\$\$i > /dev/null \\
		  ||  cp \$\$i \$(LIBSCM)/\$\$i );\\
		done


# install modified elk source files
ELK:
		cd src-elk; set -x; \\
		for i in *.c ;\\
		do # use diff to check that files are not already copied\\
		  ( diff \$\$i \$(ELKTOP)/src/\$\$i > /dev/null \\
		  || (cp \$(ELKTOP)/src/\$\$i\\
			\$(ELKTOP)/src/\$\$i.orig;\\
		     cp \$\$i \$(ELKTOP)/src/\$\$i ));\\
		done ;\\
		for i in *.h ;\\
		do # use diff to check that files are not already copied\\
		  ( diff \$\$i \$(ELKTOP)/include/\$\$i > /dev/null \\
		  || (cp \$(ELKTOP)/include/\$\$i\\
			\$(ELKTOP)/include/\$\$i.orig;\\
		     cp \$\$i \$(ELKTOP)/include/\$\$i ));\\
		done

# compile foreign function,vector extensions
ZELK:		Makefile.local
		echo Compiling elk extensions source
		cd src-zelk;make
		echo done compiling elk extensions source

# compile library routines used by extensions
ZLIB:
		cd src-zlib;make "ECFLAGS=$cflags" CC=${cc-cc}

install:
# null target

distclean:
		make -f Makefile.local clean
		
clean:
		-rm -f src-zelk/*.o src-zelk/Makefile.local
		-rm -f src-zlib/*.o 
		-rm -f Zelk.o
		-rm -f libZ.a
		-rm -f Makefile.local

EOT
