RELEASE="release x86-linux 2.4.19 `date  "+%e %B %Y"` build `cat build`"
.PHONY : build clean proper 

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

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

build:
	expr  1 + `cat build` > build

make-new: build 
	$(LISP) $(LAZY) -batch -core $(IMAGE) -load do-build
	echo -e \
	'(in-package :common-lisp-user)(load "finish")\n'$(RELEASE)'\n' | \
		./x86/lisp/lisp -core x86/lisp/kernel.core
new-utils:
	./bin/lisp -core bin/lisp-safe.core -load do-clx-clm-hem.lisp
	(cd x86/motif/server && make )
	cp  x86/contrib/defsystem/defsystem.x86f \
             x86/clx/clx-library.x86f \
             x86/hemlock/hemlock-library.x86f \
             x86/interface/clm-library.x86f  \
             x86/motif/server/motifd \
             bin/

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

select-fast:
	ln -sf setenv-optimized.lisp setenv.lisp

quick:
	make proper
	make select-small
	./bin/lisp -batch -core ./bin/lisp-small.core -load do-build

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

install:
	echo installing
	install -g root -o root -m 0644 debian/changelog \
	$(DESTDIR)cmucl-clx/usr/share/doc/cmucl-clx/ 
	install -g root -o root -m 0644 debian/changelog \
	$(DESTDIR)cmucl-hemlock/usr/share/doc/cmucl-hemlock/
	install -g root -o root -m 0644 debian/changelog \
	$(DESTDIR)cmucl-defsystem/usr/share/doc/cmucl-defsystem/
	install -g root -o root -m 0644 debian/changelog \
	$(DESTDIR)cmucl-clm/usr/share/doc/cmucl-clm/
	install -g root -o root -m 0644 x86/contrib/defsystem/defsystem.x86f \
	$(DESTDIR)cmucl-defsystem/usr/lib/cmucl/subsystems/defsystem-library.x86f
	install -g root -o root -m 0644 own-work/copyright-defsystem \
	$(DESTDIR)cmucl-defsystem/usr/share/doc/cmucl-defsystem/copyright
	install -g root -o root -m 0644 src/contrib/defsystem/defsystem.ps \
	$(DESTDIR)cmucl-defsystem/usr/share/doc/cmucl/defsystem/
	install -g root -o root -m 0644 own-work/copyright-clx \
	$(DESTDIR)cmucl-clx/usr/share/doc/cmucl-clx/copyright
	install -g root -o root -m 0644 own-work/copyright-clm \
	$(DESTDIR)cmucl-clm/usr/share/doc/cmucl-clm/copyright
	install -g root -o root -m 0644 own-work/copyright-hemlock \
	$(DESTDIR)cmucl-hemlock/usr/share/doc/cmucl-hemlock/copyright
	install -g root -o root -m 0755 -d $(DESTDIR)usr/share/doc/cmucl/
	install -g root -o root -m 0755 -d own-work/clm
	install -g root -o root -m 0644 src/docs/interface/internals.dvi \
	src/docs/interface/internals.ps src/docs/interface/toolkit.dvi \
	src/docs/interface/toolkit.ps own-work/clm/
	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 x86/lisp/lisp.nm x86/lisp/lisp.map \
	$(DESTDIR)tmp/usr/share/doc/cmucl/bin/
	install -g root -o root -m 0644 x86/clx/clx-library.x86f \
	$(DESTDIR)cmucl-clx/usr/lib/cmucl/subsystems/
	install -g root -o root -m 0644 \
	 x86/hemlock/hemlock-library.x86f \
	$(DESTDIR)cmucl-hemlock/usr/lib/cmucl/subsystems/
	install -g root -o root -m 0644 \
	x86/interface/clm-library.x86f  \
	$(DESTDIR)cmucl-clm/usr/lib/cmucl/subsystems/
	install -g root -o root -m 0755 x86/motif/server/motifd \
	$(DESTDIR)cmucl-clm/usr/lib/cmucl/
	install -g root -o root -m 0644 \
 	src/docs/interface/internals.dvi  src/docs/interface/internals.ps \
	src/docs/interface/toolkit.dvi  src/docs/interface/toolkit.ps \
	$(DESTDIR)cmucl-clm/usr/share/doc/cmucl-clm/
	install -g root -o root -m 0644 \
	own-work/hemlock11.cursor own-work/hemlock11.mask  \
	$(DESTDIR)cmucl-hemlock/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
	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/
	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 

