
########################################################
# You shouldn't need to change anything below this line

include configure

help:
	@echo "Pick one of the following targets:"
	@echo "    make bin-install      - install binaries and man pages"
	@echo "    make all              - recompile from sources (if you have them)"
	@echo "    make install          - install from sources (if you have them)"
	@echo "    make clean            - clean sources (if you have them)"

man-pages:
	$(MKDIRHIER) $(MANDIR)
	$(INSTALL) -m 644 man/$(OCCHECK).1 $(MANDIR)
	$(INSTALL) -m 644 man/$(TL2STRL).1 $(MANDIR)

new-$(OCCHECK):
	@echo 's|sml_run_time_prototype|$(SML_RT_DIR)/run.'$(ARCH)'|' > sed-tmp
	@echo 's|occheck_heap_prototype|$(HEAPDIR)/$(OCCHECK).heap.$(ARCH)|' >> sed-tmp
	@echo '#!'`which perl` >  bin/$(OCCHECK)
	@sed -f sed-tmp < bin/occheck-prototype >> bin/$(OCCHECK)
	@rm -f sed-tmp

runtime:
	@if ( [ ! -r $(SML_RT_DIR)/run.$(ARCH) ] ) ; then \
	-$(INSTALL) -m 755 bin/run.$(ARCH) $(SML_RT_DIR); \
	fi

new-$(TL2STRL):
	@echo '#!/bin/sh' > bin/$(TL2STRL)
	@echo '$(SML_RT_DIR)/run.'$(ARCH)' @SMLdebug=/dev/null @SMLquiet @SMLload=$(HEAPDIR)/$(TL2STRL).heap.$(ARCH) $$@' >> bin/$(TL2STRL)

bin-install: man-pages
	$(MAKE) new-$(OCCHECK) new-$(TL2STRL) "ARCH=`bin/arch-n-opsys`"
	$(MKDIRHIER) $(BINDIR)
	$(MKDIRHIER) $(HEAPDIR)
	$(MAKE) runtime "ARCH=`bin/arch-n-opsys`"
	$(INSTALL) -m 644 bin/$(OCCHECK).heap.$(ARCH) $(HEAPDIR)
	$(INSTALL) -m 644 bin/$(TL2STRL).heap.$(ARCH) $(HEAPDIR)
	$(INSTALL) -m 755 bin/$(OCCHECK) $(BINDIR)
	$(INSTALL) -m 755 bin/$(TL2STRL) $(BINDIR)

all:
	cd src; $(MAKE) all "ARCH=`../bin/arch-n-opsys`"

install:
	cd src; $(MAKE) install "ARCH=`../bin/arch-n-opsys`"

clean:
	cd src; $(MAKE) clean "ARCH=`../bin/arch-n-opsys`"
