#### -*- mode:makefile-gmake;coding:utf-8 -*-
####****************************************************************************
####FILE:               Makefile
####LANGUAGE:           makefile-gmake
####SYSTEM:             POSIX
####USER-INTERFACE:     NONE
####DESCRIPTION
####
####    Makefile for LISP 1.5.
####
####AUTHORS
####    <PJB> Pascal J. Bourguignon <pjb@informatimago.com>
####MODIFICATIONS
####    2012-12-15 <PJB> Added this header.
####BUGS
####LEGAL
####    AGPL3
####
####    Copyright Pascal J. Bourguignon 2012 - 2012
####
####    This program is free software: you can redistribute it and/or modify
####    it under the terms of the GNU Affero General Public License as published by
####    the Free Software Foundation, either version 3 of the License, or
####    (at your option) any later version.
####
####    This program is distributed in the hope that it will be useful,
####    but WITHOUT ANY WARRANTY; without even the implied warranty of
####    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
####    GNU Affero General Public License for more details.
####
####    You should have received a copy of the GNU Affero General Public License
####    along with this program.  If not, see <http://www.gnu.org/licenses/>.
####****************************************************************************

EMULATORS=/data/src/emulators
ASM7090=$(EMULATORS)/7090/asm7090-2.2.2/asm7090
LNK7090=$(EMULATORS)/7090/lnk7090-2.1.3/lnk7090
UTILDIR=$(EMULATORS)/7090/utils-1.0.5
BCD2TXT=$(EMULATORS)/7090/s709/bcd2txt
S709=$(EMULATORS)/7090/s709/s709


INSTALL_DIR="$(HOME)/public_html/sites/com.informatimago.www/develop/lisp"
PJB_EMACS="$(HOME)/src/public/emacs"
URL_BASE=develop/lisp


all: lisp15.out
	@echo 'make run # to run it'


help:
	echo '# Please, edit variables inside the Makefile.'
	echo ''
	echo 'make all      # compiles LISP15 into "lisp15.out" tape.'
	echo 'make run      # runs the compiled LISP15.'
	echo 'make clean    # remove files generated by compilation and run.'
	echo 'make archive  # prepare a distribution tarball.'
	echo ''

# We need to complete the lines to 80 characters,
# for asm7090 doesn't detect space opcode as PZE.
lisp15.src:Makefile lisp15.asm  head.card
	cat head.card lisp15.asm \
	| sed \
		-e '{:loop' \
		-e 's/$$/              /' \
		-e 't next' \
		-e ':next' \
		-e 's/^\(.\{80\}\).*/\1/' \
		-e 't' \
		-e 'b loop}' \
	| sed \
		-e 's/PCC   /PCC ON/' \
		-e '/PAGE 121/s/SPACE   5/SPACE   4/' \
		-e '/PAGE 122/s/^       SPACE/*      SPACE/' \
		-e 's/^\([^ ]\+\) \+\<HED\>/       HEAD \1/' \
		-e 's/^\(.\{80\}\).*/\1/' \
	> lisp15.src

#
#		-e 's/^       TITLE/***    TITLE/' \
#		-e '/\* Local Variables:/a\* eval: (progn (widen)(put-computer-paper-overlay 2 2))' \
#
lisp15.out lisp15.lis lisp15.lst:Makefile lisp15.src
	$(ASM7090) \
		-c 7090 \
		-a -f -p -w -x \
		-d LISP15 \
		-t 'BONNIE-S BIRTHDAY ASSEMBLY' \
		-l lisp15.lst \
		-o lisp15.out \
		lisp15.src || (	ls -l lisp15.*[a-z] ; exit 1)

TAP=io/lisp15.tape
TMP=io/core-dump.tape
PIT=io/punched-card-input.tape
POT=io/printed-output.tape
PPT=io/punched-card-output.tape
PUN=io/punch
PRI=io/print

io:
	- mkdir io 2>/dev/null

run:io lisp15.out
	$(UTILDIR)/obj2bin lisp15.out $(TAP)
	if [ -n $$DISPLAY ] ; then \
		xterm  -e \
        $(S709) -m7090 p=$(PRI).bcd u=$(PUN).bcd \
                       b7=$(TAP) b3=$(TMP) a2=$(PIT) a3=$(POT) a4=$(PPT) ;\
    else \
        $(S709) -m7090 p=$(PRI).bcd u=$(PUN).bcd \
                       b7=$(TAP) b3=$(TMP) a2=$(PIT) a3=$(POT) a4=$(PPT) ;\
	fi
	-$(BCD2TXT)    $(PUN).bcd $(PUN).txt 80
	-$(BCD2TXT) -p $(PRI).bcd $(PRI).txt 132
	@echo '------------------------(punched cards)----------------------'
	-@cat $(PUN).txt
	@echo '-----------------------(printed listing)---------------------'
	-@cat $(PRI).txt
	@echo '-------------------------------------------------------------'

clean:
	-rm -f lisp15.out lisp15.lis lisp15.src
	-rm -rf io
	-rm -f printlog.lst


archive $(INSTALL_DIR)/lisp15-$$VERSION.tar.gz:Makefile
	VERSION=$$(cat VERSION) ;\
	rm -rf lisp15-$$VERSION  ;\
	mkdir  lisp15-$$VERSION   ;\
	cp  README   \
		VERSION   \
		Makefile   \
		head.card   \
		lisp15.asm   \
		lisp15.lst    \
		lisp15.lisp    \
		asm7090.patch   \
        *.job            \
		$(PJB_EMACS)/pjb-page.el   \
		$(PJB_EMACS)/pjb-asm7090.el \
			lisp15-$$VERSION                           ;\
	chmod a+r lisp15-$$VERSION/*                        ;\
	tar zcf lisp15-$$VERSION.tar.gz lisp15-$$VERSION     ;\
	install -m 644 lisp15-$$VERSION.tar.gz $(INSTALL_DIR) ;\
	echo file:/$(INSTALL_DIR)/lisp15-$$VERSION.tar.gz      ;\
	echo http://www.informatimago.com/$(URL_BASE)/lisp15-$$VERSION.tar.gz

#### THE END ####
ViewGit