# $Id: Imakefile,v 1.9 1993/09/07 07:53:49 queinnec Exp $
# The Imakefile of LiSP2TeX (can also serve as a direct Makefile)

# By default, regenerate everything in the o/HOSTTYPE directory 
# and install the result in the usual directories  (see below).
MAKEOPTIONS	= 	"SCM=${SCM}" "HOSTTYPE=${HOSTTYPE}"
work : 
	@if [ X${SCM} = X ] ; then \
		echo "	Read the Imakefile and choose SCM please. "	;\
		exit 1 ; else : ; fi
	@if [ X${HOSTTYPE} = X ] ; then make work ${MAKEOPTIONS} ; else : ; fi
	@echo "	Binary files will go in o/${HOSTTYPE}/"
	@echo "	and I will use ${SCM} as Scheme compiler."
	@echo
	make mkdir ${MAKEOPTIONS}
	make o/${HOSTTYPE}/${SCM}.LiSP2TeX ${MAKEOPTIONS}
	@echo
	@echo "	Testing the new o/${HOSTTYPE}/${SCM}.LiSP2TeX..."
	make test ${MAKEOPTIONS}
	@echo
	@echo -n " Do you want to install LiSP2TeX (yes,no)[n]? "
	@read ans ; case X$$ans in X[yY]*) 		\
		echo "	Installing LiSP2TeX..."		;\
		make install ${MAKEOPTIONS}		;;\
	    *) echo "	Binary left in o/${HOSTTYPE}/${SCM}.LiSP2TeX" ;; esac
	@echo "	Everything seems OK! Happy LiSP2TeX'ing..."

##############################################################################
# An useful default rule to convert a bk file into a TeX file. 
# Insert it in your own makefiles (or Imakefiles).

LiSP2TeX	= ${BINDIR}/LiSP2TeX
LiSP2TeXFLAGS	= -v -I${DOCDIR} 

.SUFFIXES: .tex .bk
.bk.tex : ;	${LiSP2TeX} ${LiSP2TeXFLAGS} -- $*.bk > $*.tex

############### Public Install procedure ######################################
### You must probably be root to make the final installation.
MANEXTENSION	= 1
MANDIR		= /usr/man/man${MANEXTENSION}
BINDIR		= /usr/local/bin
DOCDIR		= /usr/local/lib/LiSP2TeX
STYDIR		= /usr/local/lib/tex/inputs
INSTALL		= install -c

# Choose your Scheme compiler among {s2c,bigloo}
#SCM		= s2c
#SCM		= bigloo

install : o/${HOSTTYPE}/${SCM}.LiSP2TeX
	@echo
	@echo '	This may fail if you are not root !'
	@echo
	${INSTALL} -s o/${HOSTTYPE}/${SCM}.LiSP2TeX ${BINDIR}/LiSP2TeX
	${INSTALL} LiSP2TeX.1   ${MANDIR}/LiSP2TeX.${MANEXTENSION}
	${INSTALL} LiSP2TeX.sty ${STYDIR}
	-mkdir ${DOCDIR}
	${INSTALL} LiSP2TeX.bk  ${DOCDIR}
	${INSTALL} LiSP2TeX.dvi ${DOCDIR}
	${INSTALL} README       ${DOCDIR}
	for f in *.mkgreek ; do ${INSTALL} $$f ${DOCDIR} ; done

################ End of public entries ########################################

### PORT Note: If you have Scheme->C just use this
#FINDER		= find-string.scm
### Otherwise use the already expanded version of the previous file:
### This is provided since macros are not standard enough.
#FINDER 	= look.scm
### But if you have Bigloo, use this one:
#FINDER		= find-string.bgl

### PORT Note: Dependencies are gathered in files: port-${SCM}.scm
### SCM can be {s2c,bigloo}.
PORT 	= port-${SCM}.scm

### The sources: Before them must be loaded the PORT prologue and after them
### must be loaded the FINDER file.
LiSPsources =  	util.scm		\
		read-objects.scm	\
		read.scm		\
	    	scan-objects.scm	\
		scan-file.scm		\
		emit.scm		\
		pp.scm			\
	  	commands.scm		\
		version.scm

### The documentation:
LiSPdocs    = 	LiSP2TeX.sty		\
		LiSP2TeX.bk		\
	    	LiSP2TeX.tex		\
		LiSP2TeX.bbl		\
		LiSP2TeX.dvi		\
		LiSP2TeX.ps		\
	   	LiSP2TeX.1		\
		reading.test		\
		README

### Some customization files for example
LiSPcustom  =	default.mkgreek		\
		number.mkgreek		\
		pp.mkgreek		\
		qnc.mkgreek

### The files to include in the distribution:
LiSPallFiles =  Imakefile		\
		Makefile		\
		port-s2c.scm		\
		port-bigloo.scm		\
		${LiSPsources}		\
		find-string.scm		\
		find-string.bgl		\
		look.scm		\
		${LiSPdocs}		\
		${LiSPcustom}
#add other ports, contrib ?????????????????????

############### Generate directories for binaries
# create subdirectories to store binaries
mkdir :
	-mkdir o
	-mkdir o/${HOSTTYPE}

# these files must be present for the installation.
install : 	LiSP2TeX.1 LiSP2TeX.sty README		\
		LiSP2TeX.bk LiSP2TeX.tex LiSP2TeX.dvi	\
		default.mkgreek number.mkgreek

################################################################################
############### This generation is adapted to Scheme->C
### The distributed version uses Scheme->C from Joel Bartlett.
### Adjust these paths if your Scheme->C is not there:
SCC  		= /usr/local/bin/scc -schf 14
SCI  		= /usr/local/bin/sci
S2CDIR 		= /usr/local/schemetoc

s2c_sources	= port-s2c.scm ${LiSPsources} find-string.scm

# Gather all files in a single module to simplify linking (if not 
# compilation time :).
o/${HOSTTYPE}/LiSP2TeX.sc : ${s2c_sources}
	( echo "(module lisp2tex (main unix-main))"	;\
	  for f in ${s2c_sources}			;\
	  do echo "(include \"$$f\")" 			;\
	  done ) 				> o/${HOSTTYPE}/LiSP2TeX.sc

# Takes 200 seconds on a Sony News3200 (20MHz r3000 MIPS)
o/${HOSTTYPE}/look.scm \
o/${HOSTTYPE}/s2c.LiSP2TeX : ${s2c_sources} o/${HOSTTYPE}/LiSP2TeX.sc 
	cd o/${HOSTTYPE} ; ${SCC} -O -o s2c.LiSP2TeX -I ../.. LiSP2TeX.sc
	if cmp look.scm o/${HOSTTYPE}/look.scm ; then : ;\
	else mv o/${HOSTTYPE}/look.scm . ; fi

#################################################################################
############### This generation is adapted to Bigloo
# Gather all files in a single module to simplify linking (if not 
# compilation time :).  The produced executable is named bigloo.LiSP2TeX.
CFLAGS		= -O
CC		= gcc
BIGLOO		= bigloo
BIGLOODIR	= /usr/local/lib/bigloo/1.4
BIGLOOFLAGS	= -O2
bigloo_sources	= port-bigloo.scm ${LiSPsources} find-string.bgl

o/${HOSTTYPE}/bigloo.LiSP2TeX.bgl : ${bigloo_sources}
	( echo "(module lisp2tex (export (unix-main args))"	;\
	  for f in ${bigloo_sources}				;\
	  do echo "(include \"../../$$f\")"			;\
	  done ; echo ")" )		> o/${HOSTTYPE}/bigloo.LiSP2TeX.bgl

o/${HOSTTYPE}/bigloo.LiSP2TeX.c : ${bigloo_sources} 
o/${HOSTTYPE}/bigloo.LiSP2TeX.c : o/${HOSTTYPE}/bigloo.LiSP2TeX.bgl
	cd o/${HOSTTYPE} ; \
		${BIGLOO} ${BIGLOOFLAGS} -C+ \
		-o bigloo.LiSP2TeX.c bigloo.LiSP2TeX.bgl
o/${HOSTTYPE}/bigloo.LiSP2TeX.o : o/${HOSTTYPE}/bigloo.LiSP2TeX.c 
	cd o/${HOSTTYPE} ; \
	  	${CC} ${CFLAGS} -c -o bigloo.LiSP2TeX.o -I${BIGLOODIR} \
		bigloo.LiSP2TeX.c 
o/${HOSTTYPE}/main.bgl : 
	@echo "(module main (main start)			\
(import (unix-main lisp2tex \"bigloo.LiSP2TeX.bgl\"))	\
(with lisp2tex) )					\
(define (start args) (unix-main args))"  > o/${HOSTTYPE}/main.bgl
o/${HOSTTYPE}/bigloo.LiSP2TeX : o/${HOSTTYPE}/main.bgl
o/${HOSTTYPE}/bigloo.LiSP2TeX : o/${HOSTTYPE}/bigloo.LiSP2TeX.o
	cd o/${HOSTTYPE} ; \
		${BIGLOO} ${BIGLOOFLAGS} -o bigloo.LiSP2TeX main.bgl 
# Cut the compilation into two parts to avoid virtual memory exhaustion on
# my Sony portable. 

############### Obtaining the documentation
# These entries use the installed LiSP2TeX
LiSP2TeX.tex : LiSP2TeX.bk version.scm
	${LiSP2TeX} ${LiSP2TeXFLAGS} -- LiSP2TeX.bk > LiSP2TeX.tex
LiSP2TeX.dvi : LiSP2TeX.tex LiSP2TeX.sty 
	latex  LiSP2TeX.tex
	bibtex LiSP2TeX
	latex  LiSP2TeX.tex
	latex  LiSP2TeX.tex
LiSP2TeX.ps : LiSP2TeX.dvi
	dvips LiSP2TeX.dvi -o LiSP2TeX.ps
LiSP2TeX.spell : LiSP2TeX.tex
	delatex LiSP2TeX.tex | ispell -l | sort -u > LiSP2TeX.spell

############### Print the readable files
PRINT 		= print
PRDVI 		= prdvi
print : print.sources print.man print.dvi
print.sources : 
	${PRINT} ${LiSPsources}
print.dvi : LiSP2TeX.dvi
	${PRDVI} LiSP2TeX.dvi
print.man :
	man LiSP2TeX | colcrt - | ${PRINT}

############### Tags
TAGS-MAKER      = etags -t
tags : ;	${TAGS-MAKER} *.scm

################################################################################
############### Test compiled LiSP2TeX
# Test the fresh LiSP2TeX.
test : 
	@echo "	Regenerate documentation ..."
	time o/${HOSTTYPE}/${SCM}.LiSP2TeX ${LiSP2TeXFLAGS} -- LiSP2TeX.bk \
		> o/${HOSTTYPE}/LiSP2TeX.tex
	@echo "	Compare with reference ..."
	if [ -r LiSP2TeX.tex ]  				;\
	then diff o/${HOSTTYPE}/LiSP2TeX.tex LiSP2TeX.tex 	;\
	fi

################################################################################
############### Test with interpreter Scheme->C
test.read.sci : 
	@( for f in ${s2c_sources}			;\
	   do echo "(load \"$$f\")" 			;\
	      done					;\
	   echo "(test-read \"reading.test\")"		) | ${SCI}

interp.sci : 
	@( for f in ${s2c_sources}			;\
	   do echo "(load \"$$f\")" 			;\
	      done					;\
	   echo "(unix-main '(sci))" 	; tee ) | ${SCI}

TEST_OPTIONS	= 	\"-v\" \"--\" \"LiSP2TeX.bk\"
test.interp.sci : 
	@( for f in ${s2c_sources}					;\
	   do echo "(load \"$$f\")" 					;\
	      done							;\
	   echo "(LiSP2TeX '(${TEST_OPTIONS}))"	 			;\
	   tee ) | ${SCI}

################################################################################
############### Test with interpreter Bigloo
test.read.bgl : 
	@( for f in ${bigloo_sources}			;\
	   do echo "(load \"$$f\")" 			;\
	      done					;\
	   echo "(test-read \"reading.test\")"		) | ${BIGLOO}

interp.bgl : 
	@( for f in ${bigloo_sources}			;\
	   do echo "(load \"$$f\")" 			;\
	      done					;\
	   echo "(unix-main '(bgl))" 	; tee ) | ${BIGLOO}

tmp.interp.bgl : 
	@( for f in ${bigloo_sources}			;\
	   do echo "(load \"$$f\")" 			;\
	      done					;\
	   echo "(unix-main '(bgl))" )
	${BIGLOO}

test.interp.bgl : 
	@( for f in ${bigloo_sources}					;\
	   do echo "(load \"$$f\")" 					;\
	      done							;\
	   echo "(LiSP2TeX '(${TEST_OPTIONS}))"	 			;\
	   tee ) | ${BIGLOO}

################################################################################
############### Making Distribution
DIST_DIR	= LiSP2TeX
LiSP2TeX.tar : ${LiSPallFiles}
	-mkdir ${DIST_DIR}
	cp -p ${LiSPallFiles} ${DIST_DIR}
	chmod ug=rw,o=r ${DIST_DIR}/?*
	tar -cvf LiSP2TeX.tar ${DIST_DIR}
	rm -rf ${DIST_DIR}
LiSP2TeX.tar.Z : LiSP2TeX.tar
	compress -f LiSP2TeX.tar

distribution : 
	@echo Check that all files are checked-in wrt CVS
	make notci
	@echo -n "m ckpt (yes,no)[n]? " 
	@read ans ; case X$$ans in X[yY]*) m ckpt ;; *) : ;; esac
	-rm -f version.scm
	make version.scm
	make LiSP2TeX.dvi
	cvs tag `date +LiSP2TeX%y%h%d`
	make LiSP2TeX.tar.Z
	mv LiSP2TeX.tar.Z `date +LiSP2TeX%y%h%d.tar.Z`

version.scm :
	echo ";;; Automatically generated, do not touch!!!"	> version.scm
	date "+(define version \"%y%h%d\")"			>> version.scm
	chmod a=r version.scm

############### Clean 
clean :: cleanMakefile cleantex
	-rm TAGS 
	-rm o/${HOSTTYPE}/SC-TO-C* 
	-rm -rf LiSP2TeX*.tar* LiSP2TeX
clean.all : clean
	-rm -rf o/$HOSTTYPE} LiSP2TeX.dvi LiSP2TeX*.tar.Z LiSP2TeX.tex 
	-rm look.scm version.scm

# end of Imakefile
