
# Builds MzScheme and MrEd

srcdir = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
libdir = @libdir@
includepltdir = @includepltdir@
libpltdir = @libpltdir@
collectsdir = @collectsdir@
mandir = @mandir@
docdir = @docdir@
builddir = @builddir@

ALLDIRINFO = "$(DESTDIR)$(bindir)" \
             "$(DESTDIR)$(collectsdir)" \
             "$(DESTDIR)$(docdir)" \
             "$(DESTDIR)$(libdir)" \
             "$(DESTDIR)$(includepltdir)" \
             "$(DESTDIR)$(libpltdir)" \
             "$(DESTDIR)$(mandir)"

all:
	$(MAKE) mz
	$(MAKE) mred-stub

mred-stub: @MAKE_MRED@


3m:
	$(MAKE) mz3m
	$(MAKE) mred3m-stub

mred3m-stub: @MAKE_MRED3M@

SETUP_ARGS = -mvqX "$(DESTDIR)$(collectsdir)" -M setup

install:
	$(MAKE) plain-install
	"$(DESTDIR)$(bindir)/mzscheme" $(SETUP_ARGS)
	$(MAKE) fix-paths

plain-install:
	$(MAKE) install-normal

install-normal:
	mkdir -p $(ALLDIRINFO)
	$(MAKE) mzinstall
	$(MAKE) copytree-stub
	$(MAKE) mredinstall-stub
	$(MAKE) lib-finish

mredinstall-stub: @MAKE_MREDINSTALL@

plain-install-3m:
	$(MAKE) install-normal
	$(MAKE) mzinstall3m
	$(MAKE) mredinstall3m-stub

install-3m:
	$(MAKE) plain-install-3m
	"$(DESTDIR)$(bindir)/mzscheme3m" $(SETUP_ARGS)
	$(MAKE) fix-paths

mredinstall3m-stub: @MAKE_MREDINSTALL3M@


clean:
	cd mzscheme; $(MAKE) clean
	if [ -d mred ]; then cd mred; $(MAKE) clean; fi


mz:
	cd mzscheme; $(MAKE)

mz3m:
	cd mzscheme; $(MAKE) 3m

mr:
	cd mred; $(MAKE)

mr3m:
	cd mred; $(MAKE) 3m


mzinstall:
	cd mzscheme; $(MAKE) install

mzinstall3m:
	cd mzscheme; $(MAKE) install-3m

mrinstall:
	cd mred; $(MAKE) install

mrinstall3m:
	cd mred; $(MAKE) install-3m


lib-finish:
	@LIBFINISH@ "$(libdir)"

copytree-stub: @MAKE_COPYTREE@

copytree:
	mzscheme/mzscheme -mvxqu \
          "$(srcdir)/../collects/setup/unixstyle-install.ss" \
          make-install-copytree "$(srcdir)/.." \
          $(ALLDIRINFO) "@INSTALL_ORIG_TREE@"

fix-paths:
	if [ "$(DESTDIR)" != "" ]; then \
          mzscheme/mzscheme -mvxqu \
            "$(srcdir)/../collects/setup/unixstyle-install.ss" \
            make-install-destdir-fix "$(srcdir)/.." \
            $(ALLDIRINFO) "@INSTALL_ORIG_TREE@"; \
        fi
