# Makefile for SCM (Scheme implementation intended for JACAL).
# Copyright (C) 1990, 1991, 1992, 1993 Aubrey Jaffer.
# See the file "COPYING" for terms applying to this program

# directory where COPYING and Init.scm reside.
#IMPLPATH=/usr/src/local/scm/
#this one is good while debugging
IMPLPATH=`pwd`/

# Pathname where Init.scm resides.  This directory must also contain COPYING.
IMPLINIT=$(IMPLPATH)Init.scm
# If pathname where Init.scm resides is not known in advance then
# SCM_INIT_PATH is the environment variable whose value is the
# pathname where Init.scm resides.
# IMPLINIT=

# directory where `make install' will put executable.
DEST=/usr/local/bin/
# directory where `make install' will put manual page.
MANDEST=/usr/man/scm/

#CC = your compiler
# -DRTL if this is a run-time library only (no interactive top level)
# -Dunix is required for SCO
# -DRECKLESS if you want most scm error checking disabled.
# -O if you want the optimizing C compiler to be used.
CC=/bin/cc
CFLAGS=-O -VNDP

#FFLAGS are flags for inexact numbers (floating point)
# -DFLOATS turns on support for inexact numbers.
# -DENGNOT for engineering notation instead of scientific notation.

FFLAGS=-DFLOATS -DENGNOT

# append any names of user extension files
# -lm for -DFLOATS
#ELIBS=../regex-0.11/regex.o
LIBS=$(ELIBS) -L/lib/ndp -L/usr/lib/ndp -lm

RGXFLAGS=-I../regex-0.11/

# INITS= the initialization calls for user extension files.
# FINALS= the finalialization calls for user extension files.
#File:	INITS line:		functions defined:
#sc2.c	init_sc2\(\);	substring-move-left!, substring-move-right!,
#			substring-fill!, append!, and last-pair
#rgx.c	init_rgx\(\);	regcomp and regexec.
INITS=-DINITS=init_sc2\(\)\;
FINALS=-DFINALS=\;

#seds to help find names not unique in first 8 characters (name8s)
# for BSD nm format
SED_TO_STRIP_NM=sed -e '/.*\.o$$/d' -e 's/.* _//' -e 's/.* T //'
#old, bad for T [^_] on suns: SED_TO_STRIP_NM=sed -e '/.*\.o$$/d' -e 's/.* _//'
# For a System V nm where plain C identifiers have _ prepended:
#SED_TO_STRIP_NM=sed -e '/^_[A-Za-z][A-za-z0-9_]*[ 	|].*|extern|!d' -e 's/|/ /g' -e 's/^_//'
# For a System V nm where plain C identifiers have nothing prepended:
#SED_TO_STRIP_NM=sed -e '/^[A-Za-z][A-za-z0-9_]*[ 	|].*|extern|!d' -e 's/|/ /g'

#you should not need to change below this line.

SHELL = /bin/sh
DFLAG = -DIMPLINIT=\"$(IMPLINIT)\"
ffiles = time.o repl.o fscl.o sys.o feval.o subr.o sc2.o funif.o #rgx.o
efiles = time.o repl.o escl.o sys.o eeval.o subr.o sc2.o eunif.o #rgx.o
cfiles = scm.c time.c repl.c scl.c sys.c eval.c subr.c sc2.c unif.c rgx.c
hfiles = scm.h config.h setjump.h patchlvl.h proto.h
ifiles = Init.scm Transcen.scm
tfiles = test.scm example.scm pi.scm pi.c
dfiles = README COPYING scm.1 scm.doc MANUAL ChangeLog code.doc ANNOUNCE
mfiles = makefile.unix makefile.msc makefile.bor makefile.tur\
	makefile.djg makefile.qc compile.amiga link.amiga makefile.aztec\
	makefile.ast makefile.prj
vfiles = setjump.mar VMSBUILD.COM VMSGCC.COM
afiles = $(dfiles) $(cfiles) $(hfiles) $(ifiles) $(tfiles) $(mfiles) $(vfiles)

all:	scm
scheme:	scm

# -DINITS= the initialization calls for user extension files.
# -DFINALS= the finalialization calls for user extension files.
dbscm:	$(efiles) ../db/db.a scm.c scm.h config.h patchlvl.h makefile.unix \
	rgx.o
	$(CC) -o dbscm $(efiles) $(ELIBS) ../regex-0.11/regex.o rgx.o \
	$(CFLAGS) $(INITS)init_db\(\)\;init_rgx\(\) $(FINALS)final_db\(\) \
	-DRTL scm.c ../db/db.a

scm:	$(ffiles) fscm.o
	$(CC) -o scm $(ffiles) fscm.o $(LIBS)
fscm.o:	scm.c scm.h config.h patchlvl.h
	$(CC) $(CFLAGS) -c $(FFLAGS) $(INITS) $(FINALS) scm.c
	mv scm.o fscm.o
fscl.o:	scl.c scm.h config.h
	$(CC) $(CFLAGS) -c $(FFLAGS) scl.c
	mv scl.o fscl.o
feval.o:	eval.c scm.h config.h
	$(CC) $(CFLAGS) -c $(FFLAGS) eval.c
	mv eval.o feval.o
funif.o:	unif.c scm.h
	$(CC) $(CFLAGS) -c $(FFLAGS) unif.c
	mv unif.o funif.o

escm:	$(efiles) escm.o
	$(CC) -o escm $(efiles) $(ELIBS) escm.o
escm.o:	scm.c scm.h config.h patchlvl.h
	$(CC) $(CFLAGS) -c $(INITS) $(FINALS) scm.c
	mv scm.o escm.o
escl.o:	scl.c scm.h config.h
	$(CC) $(CFLAGS) -c scl.c
	mv scl.o escl.o
eeval.o:	eval.c scm.h config.h
	$(CC) $(CFLAGS) -c eval.c
	mv eval.o eeval.o
eunif.o:	unif.c scm.h
	$(CC) $(CFLAGS) -c unif.c
	mv unif.o eunif.o

repl.o:	repl.c scm.h config.h setjump.h
	$(CC) $(CFLAGS) -c $(DFLAG) repl.c
sys.o:	sys.c scm.h config.h setjump.h
	$(CC) $(CFLAGS) -c sys.c
time.o:	time.c scm.h config.h
	$(CC) $(CFLAGS) -c time.c
subr.o:	subr.c scm.h config.h
	$(CC) $(CFLAGS) -c subr.c
sc2.o:	sc2.c scm.h
	$(CC) $(CFLAGS) -c sc2.c
rgx.o:	rgx.c scm.h makefile.unix
	$(CC) $(CFLAGS) $(RGXFLAGS) -c rgx.c

both:	scm escm

proto.h:	$(cfiles)
	rm -f proto.h
	mkproto $(cfiles) > proto.h

libscm.a:	rtlscm.o $(ffiles)
	rm -f libscm.a
	ar rc libscm.a rtlscm.o $(ffiles)
	ranlib libscm.a

rtlscm.o:	scm.c scm.h config.h patchlvl.h
	$(CC) $(CFLAGS) -c $(FFLAGS) -DRTL $(INITS)init_user_scm\(\) \
	$(FINALS) scm.c
	mv scm.o rtlscm.o

scm.doc:	scm.1
	nroff -man scm.1 >scm.doc

install:	scm scm.1
	cp scm $(DEST)
	strip $(DEST)scm
	-cp scm.1 $(MANDEST)
	-cp Init.scm $(IMPLPATH)
	-cp Transcen.scm $(IMPLPATH)
	-cp COPYING $(IMPLPATH)

tar:	scm.tar
scm.tar:	temp/scm
	cd temp; tar chf ../scm.tar scm
shar:	scm.shar
scm.shar:	temp/scm
	cd temp; shar scm >../scm.shar
dclshar:	scm.com
com:	scm.com
scm.com:	temp/scm
	cd temp; dclshar scm >../scm.com
zip:	scm.zip
scm.zip:	temp/scm
	cd temp; zip -ru ../scm.zip scm

temp/scm:	$(afiles)
	-rm -rf temp
	mkdir temp
	mkdir temp/scm
	ln  $(afiles) temp/scm

dist:	tar.Z
tar.Z:	scm.tar.Z
scm.tar.Z:	scm.tar
	-rm -f scm.tar.Z
	compress scm.tar
shar.Z:	scm.shar.Z
scm.shar.Z:	scm.shar
	-rm -f scm.shar.Z
	compress scm.shar

diffs:	temp/scm
	mv temp/scm temp/nscm
	cd temp;zcat ../scm.tar.Z | tar xf -
	-rm -f scm.pat
	-diff -c temp/scm temp/nscm > scm.pat
	-rm -rf temp
	ls -l scm.pat

checks: check echeck
check:	scm test.scm
	echo '(test-sc4)(test-cont)(test-inexact)(gc)(exit (length errs))' \
	| scm test.scm
echeck:	escm test.scm
	echo '(test-sc4)(test-cont)(gc)(exit (length errs))' \
	| escm test.scm

lint:	lints
lints:	$(cfiles) $(hfiles)
	lint $(CFLAGS) $(FFLAGS) $(cfiles) | tee lints
#	lint $(CFLAGS) $(cfiles) | tee lintes
name8:	name8s
name8s:	scm
	nm scm |\
	$(SED_TO_STRIP_NM) |\
	sort -u|\
	awk '{	if (substr(l,1,8)==substr($$1,1,8)) {\
			if (p) print l;\
			print $$1;p=0;stat=1\
		}else p=1;\
		l=$$1\
	     }END{exit stat}' -
ctags:	$(hfiles) $(cfiles) code.doc
	etags $(hfiles) $(cfiles) code.doc
TAGS:
tags:	$(hfiles) $(cfiles) $(ifiles) $(mfiles) $(vfiles) \
	MANUAL code.doc README
	etags $(hfiles) $(cfiles) $(ifiles) $(mfiles) $(vfiles) \
	MANUAL code.doc README
mostlyclean:
clean:
	-rm -f *~ \#* *\# *.orig *.rej a.out core lints tmp*
	-rm -rf temp
distclean:
	-rm -f *~ \#* *.o *\# *.orig *.rej a.out core lints tmp*
	-rm -rf temp
realclean:
	-rm -f *~ \#* *.o *\# *.orig *.rej a.out core TAGS lints tmp* scm.doc
	-rm -rf temp
