.PHONY : clean

ifeq ($(origin DESTDIR), undefined)
DESTDIR=/
DESTCMU=/
DESTSRC=/
DESTCLM=/
else
DESTCMU=$(DESTDIR)cmucl/
DESTSRC=$(DESTDIR)cmucl-source/
DESTCLM=$(DESTDIR)cmucl-clm/
endif

all:
	rm -rf linux-1 linux-2 linux-3 linux-4 || true 
	bash bin/build.sh -o cmucl -v "Debian build"  -C "" 

doc:
	 (cd src/docs && make all)

install-dep:
	install -g root -o root -m 0755 linux-4/motif/server/motifd \
		$(DESTCLM)usr/lib/cmucl/

	install -g root -o root -m 0644 linux-4/interface/clm-library.sse2f \
		$(DESTCLM)usr/lib/cmucl/subsystems/
	install -g root -o root -m 0644 linux-4/clx/clx-library.sse2f \
		linux-4/hemlock/hemlock-library.sse2f \
		linux-4/pcl/gray-streams-library.sse2f \
		linux-4/pcl/simple-streams-library.sse2f \
		linux-4/pcl/iodefs-library.sse2f \
		linux-4/pcl/gray-compat-library.sse2f \
		$(DESTCMU)usr/lib/cmucl/subsystems/
	install -g root -o root -m 0644 linux-4/lisp/lisp-sse2.core $(DESTCMU)usr/lib/cmucl/lisp-sse2.core
	install -g root -o root -m 0444 src/contrib/asdf/asdf.lisp linux-4/contrib/asdf/asdf.sse2f $(DESTCMU)usr/lib/cmucl/contrib/asdf/

	install -g root -o root -m 0644 src/lisp/*.h linux-4/lisp/*.h linux-4/lisp/*.map linux-4/lisp/*.nm \
		$(DESTCMU)usr/lib/cmucl/include/
	install -g root -o root -m 0644 \
		debian/own-work/hemlock11.cursor debian/own-work/hemlock11.mask  \
			$(DESTCMU)usr/lib/cmucl/
	install -g root -o root -m 0644 \
			debian/own-work/site-init.lisp  \
			$(DESTCMU)etc/common-lisp/cmucl/
	install -g root -o root -m 644 debian/own-work/install-clc.lisp \
			$(DESTCMU)usr/lib/cmucl/
	ln -s /etc/common-lisp/cmucl/site-init.lisp $(DESTCMU)usr/lib/cmucl/

	install -g root -o root -m 0755 linux-4/lisp/lisp $(DESTCMU)usr/bin/cmucl
	install -g root -o root -m 0644 src/tools/config.lisp src/code/generic-site.lisp \
	   linux-4/lisp/lisp.nm linux-4/lisp/lisp.map linux-4/lisp/internals.h \
	   linux-4/lisp/internals.inc $(DESTCMU)usr/lib/cmucl/
	install -g root -o root -m 0755 debian/own-work/cmucl-run $(DESTCMU)usr/bin/cmucl-run
	install -g root -o root -m 0644 debian/own-work/binfmt $(DESTCMU)usr/share/binfmts/cmucl
	install -g root -o root -m 0444 src/general-info/cmucl.1 $(DESTCMU)usr/share/man/man1/cmucl-lisp.1
	install -g root -o root -m 0444 src/general-info/lisp.1 $(DESTCMU)usr/share/man/man1/cmucl.1
	install -g root -o root -m 0444 src/general-info/lisp.1 $(DESTCMU)usr/share/man/man1/lisp.1
	install -g root -o root -m 0444 debian/own-work/cmucl-run.1 \
	   $(DESTCMU)usr/share/man/man1/cmucl-run.1
	install -g root -o root -m 0444 src/pcl/simple-streams/external-formats/*.lisp \
              $(DESTCMU)usr/lib/cmucl/ext-formats/
	install -g root -o root -m 0444 ./src/i18n/unidata.bin \
              $(DESTCMU)usr/lib/cmucl/ext-formats/

install-indep:
	install -g root -o root -m 0644 debian/own-work/cmucl-graystream.asd \
	  $(DESTSRC)usr/share/common-lisp/source/cmucl-graystream/cmucl-graystream.asd
	install -g root -o root -m 0644 debian/own-work/cmucl-clx.asd \
	  $(DESTSRC)usr/share/common-lisp/source/cmucl-clx/cmucl-clx.asd
	(cd src ; find . \( -name "*.asd" -or -name "*.lisp" \) -and -type f | tar --create --file=-  --files-from=- ) | \
	  (cd $(DESTSRC)usr/share/common-lisp/source/cmucl/ ; tar --extract --file=- )
	chown root.root -R $(DESTSRC)usr/share/common-lisp/source/cmucl/
	find $(DESTSRC)usr/share/common-lisp/source/cmucl/ -type f -print0 | xargs -0 chmod 0644
	find $(DESTSRC)usr/share/common-lisp/source/cmucl/ -type d -print0 | xargs -0 chmod 0755

clean:
	find  . -name "*~" -or -name ".#*" | xargs rm ; true
	rm -rf linux-1 linux-2 linux-3 linux-4 || true
	# if the Makefile exists, use it, if not... do it by hand
	if [ -f src/docs/Makefile ] ; then \
	   (cd src/docs && make clean) \
	else \
	  rm src/docs/cmu-user/*.html \
	   src/docs/cmu-user/cmu-user.aux \
	   src/docs/cmu-user/cmu-user.cdx \
	   src/docs/cmu-user/cmu-user.cnd \
	   src/docs/cmu-user/cmu-user.css \
	   src/docs/cmu-user/cmu-user.fdx \
	   src/docs/cmu-user/cmu-user.fnd \
	   src/docs/cmu-user/cmu-user.haux \
	   src/docs/cmu-user/cmu-user.hcnd \
	   src/docs/cmu-user/cmu-user.hcnd.html \
	   src/docs/cmu-user/cmu-user.hfnd \
	   src/docs/cmu-user/cmu-user.hfnd.html \
	   src/docs/cmu-user/cmu-user.html \
	   src/docs/cmu-user/cmu-user.htnd \
	   src/docs/cmu-user/cmu-user.htnd.html \
	   src/docs/cmu-user/cmu-user.htoc \
	   src/docs/cmu-user/cmu-user.htoc.html \
	   src/docs/cmu-user/cmu-user.hvnd \
	   src/docs/cmu-user/cmu-user.hvnd.html \
	   src/docs/cmu-user/cmu-user.idx \
	   src/docs/cmu-user/cmu-user.ilg \
	   src/docs/cmu-user/cmu-user.info* \
	   src/docs/cmu-user/cmu-user.log \
	   src/docs/cmu-user/cmu-user.out \
	   src/docs/cmu-user/cmu-user.pdf \
	   src/docs/cmu-user/cmu-user.ps \
	   src/docs/cmu-user/cmu-user.tdx \
	   src/docs/cmu-user/cmu-user.tnd \
	   src/docs/cmu-user/cmu-user.toc \
	   src/docs/cmu-user/cmu-user.vdx \
	   src/docs/cmu-user/cmu-user.vnd \
	   src/docs/interface/internals.aux \
	   src/docs/interface/internals.dvi \
	   src/docs/interface/internals.log \
	   src/docs/interface/internals.ps \
	   src/docs/interface/toolkit.aux \
	   src/docs/interface/toolkit.dvi \
	   src/docs/interface/toolkit.log \
	   src/docs/interface/toolkit.ps \
	   src/docs/internals/architecture.aux \
	   src/docs/internals/compiler.aux \
	   src/docs/internals/design.aux \
	   src/docs/internals/design.log \
	   src/docs/internals/design.out \
	   src/docs/internals/design.pdf \
	   src/docs/internals/design.toc \
	   src/docs/internals/glossary.aux \
	   src/docs/internals/retargeting.aux \
	   src/docs/internals/run-time.aux  || true ; \
	fi

