RELEASE="release x86-linux 3.0.8 18c+ `LC_ALL=C date  "+%e %B %Y"` build `cat build`"
.PHONY : build clean proper 

IMAGE=./bin/lisp.core
LISP=lisp
LAZY=-nolazy
#LAZY=-lazy

all:	build  clean
	(cd x86/lisp &&  make depend &&  make )
	make proper && \
	make select-safe && \
	make IMAGE=/usr/lib/cmucl/lisp-safe-old.core make-new \
		&& mv lisp.core lisp-safe.core
	make proper && \
	make select-normal && \
	make IMAGE=/usr/lib/cmucl/lisp-normal-old.core make-new \
		&& mv lisp.core lisp-normal.core
	make proper && \
	make select-small && \
	make IMAGE=/usr/lib/cmucl/lisp-small-old.core make-new \
		&& mv lisp.core lisp-small.core
	make proper
	x86/lisp/lisp $(LAZY) -nositeinit -noinit -core lisp-safe.core -load do-clm.lisp
	(cd x86/motif/server && make )
	(cd src/docs/ && make all)

build:
	expr  1 + `cat build` > build

#-quiet -batch 

make-new: 
	$(LISP) $(LAZY) -nositeinit -noinit \
	-core $(IMAGE) -load do-build
	echo -e \
	'(in-package :common-lisp-user)(load "finish")\n'$(RELEASE)'\n' | \
		./x86/lisp/lisp $(LAZY) -nositeinit -noinit -core x86/lisp/kernel.core

select-small:
	ln -sf setenv-small.lisp setenv.lisp

select-safe:
	ln -sf setenv-safe.lisp setenv.lisp

select-normal:
	ln -sf setenv-normal.lisp setenv.lisp

new-gen: build 
	make proper
	make select-safe && \
	make IMAGE=./bin/lisp-safe.core LISP=./bin/lisp make-new && \
	mv lisp.core lisp-safe.core
	make proper
	make select-normal && \
	make IMAGE=./bin/lisp-normal.core LISP=./bin/lisp make-new && \
	mv lisp.core lisp-normal.core
	make select-small && \
	make IMAGE=./bin/lisp-small.core LISP=./bin/lisp make-new && \
	mv lisp.core lisp-small.core
	make proper
	mv lisp-*.core bin/
	cp x86/lisp/lisp bin/

install:
	echo installing
	install -g root -o root -m 0644 own-work/linitian-override  \
	  	$(DESTDIR)cmucl-source/usr/share/lintian/overrides/cmucl-source
	install -g root -o root -m 0755 x86/motif/server/motifd \
		$(DESTDIR)cmucl-clm/usr/lib/cmucl/
	install -g root -o root -m 0644 x86/interface/clm-library.x86f \
		$(DESTDIR)cmucl-clm/usr/lib/cmucl/subsystems/clm-library.x86f 
	install -g root -o root -m 0644 own-work/config.lisp \
		$(DESTDIR)tmp/usr/lib/cmucl/
	install -g root -o root -m 0755 own-work/cmuclconfig $(DESTDIR)tmp/usr/sbin/
	install -g root -o root -m 0644 own-work/*.system \
		$(DESTDIR)cmucl-source/usr/share/common-lisp/systems
	install -g root -o root -m 0644 src/lisp/*.h x86/lisp/*.h x86/lisp/*.map *86/lisp/*.nm \
		$(DESTDIR)tmp/usr/lib/cmucl/include/
	install -g root -o root -m 0644 \
		own-work/hemlock11.cursor own-work/hemlock11.mask  \
			$(DESTDIR)tmp/usr/lib/cmucl/
	install -g root -o root -m 0644 \
			own-work/site-init.lisp  \
			$(DESTDIR)tmp/var/lib/cmucl/
	install -g root -o root -m 0644 own-work/lisp-config.lisp \
			$(DESTDIR)tmp/etc
	install -g root -o root -m 644 own-work/install-defsystem.lisp \
			$(DESTDIR)tmp/usr/lib/cmucl/
	ln -s /var/lib/cmucl/site-init.lisp $(DESTDIR)tmp/usr/lib/cmucl/
	install -g root -o root -m 0644 lisp-small.core $(DESTDIR)cmucl-small/usr/lib/cmucl
	install -g root -o root -m 0644 lisp-safe.core $(DESTDIR)cmucl-safe/usr/lib/cmucl
	install -g root -o root -m 0644 lisp-normal.core $(DESTDIR)cmucl-normal/usr/lib/cmucl
	install -g root -o root -m 0755 x86/lisp/lisp $(DESTDIR)tmp/usr/bin/
	install -g root -o root -m 0755 own-work/cmucl-script.sh $(DESTDIR)cmucl-small/usr/lib/common-lisp/bin/cmucl-small.sh
	install -g root -o root -m 0755 own-work/cmucl-script.sh $(DESTDIR)cmucl-safe/usr/lib/common-lisp/bin/cmucl-safe.sh
	install -g root -o root -m 0755 own-work/cmucl-script.sh $(DESTDIR)cmucl-normal/usr/lib/common-lisp/bin/cmucl-normal.sh
	cp -R build Makefile README.CVS *.lisp diffs-with-cvs reference src TODO own-work README  \
			$(DESTDIR)cmucl-source/usr/share/common-lisp/repositories/cmucl/
	mkdir $(DESTDIR)cmucl-source/usr/share/common-lisp/repositories/cmucl/debian
	cp -R debian/*dirs* debian/*docs* debian/*examples* debian/*files* debian/*copyright* \
			debian/*menu* debian/*post* debian/*pre* debian/rules debian/conffiles \
			debian/control debian/README* debian/changelog  \
			$(DESTDIR)cmucl-source/usr/share/common-lisp/repositories/cmucl/debian/
	echo done installing

clean: proper
	rm lisp*.core ; true
	(cd src/docs/ && make clean )
	(cd x86/lisp && make clean)
	(cd x86/motif/server && make clean )

proper:
	find x86* -name "*.x86f" -or -name "*.lbytef" -or -name "*.assem" -or \
		-name "*.core" | xargs rm ; true
	rm -rf own-work/clm ; true
	find  . -name "*~" -or -name ".#*" | xargs rm ; true
	rm x86*/compile-*.log x86*/hemlock/spell-dictionary.bin ; true 

