
# Builds MzScheme and MrEd (if enabled), and
#  drives the main install

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) @MAIN_VARIANT@

3m:
	cd mzscheme; $(MAKE) 3m
	$(MAKE) @MAKE_MRED@-3m

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

no-3m:
	cd .

cgc:
	cd mzscheme; $(MAKE) cgc
	$(MAKE) @MAKE_MRED@-cgc

mred-cgc:
	cd mred; $(MAKE) cgc

no-cgc:
	cd .

both:
	$(MAKE) cgc
	$(MAKE) 3m

# Install (common) ----------------------------------------

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

install:
	$(MAKE) install-@MAIN_VARIANT@

install-common-first:
	mkdir -p $(ALLDIRINFO)

install-common-middle:
	$(MAKE) @MAKE_COPYTREE@-run
	$(MAKE) install-@MAKE_MRED@-post-collects
	$(MAKE) lib-finish

install-common-last:
	$(MAKE) fix-paths

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

no-run:
	cd .

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

install-mred-post-collects:
	cd mred; $(MAKE) install-post-collects

install-no-post-collects:
	cd .

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

# 3m install ----------------------------------------

install-3m:
	$(MAKE) install-common-first
	cd mzscheme; $(MAKE) install-3m
	$(MAKE) install-@MAKE_MRED@-3m
	$(MAKE) install-common-middle
	mzscheme/mzscheme@MMM@ $(SETUP_ARGS)
	$(MAKE) install-common-last

install-no-3m:
	cd .

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

# CGC install ----------------------------------------

install-cgc:
	$(MAKE) install-common-first
	cd mzscheme; $(MAKE) install-cgc
	$(MAKE) install-@MAKE_MRED@-cgc
	$(MAKE) install-common-middle
	mzscheme/mzscheme@CGC@ $(SETUP_ARGS)
	$(MAKE) install-common-last

install-no-cgc:
	cd .

install-mred-cgc:
	cd mred; $(MAKE) install-cgc

# Both install ----------------------------------------

install-both:
	$(MAKE) install-common-first
	cd mzscheme; $(MAKE) install-both
	$(MAKE) install-@MAKE_MRED@-both
	$(MAKE) install-common-middle
	mzscheme/mzscheme@MAIN_VARIANT@ $(SETUP_ARGS)
	$(MAKE) install-common-last

install-no-both:
	cd .

install-mred-both:
	cd mred; $(MAKE) install-both

# Clean ----------------------------------------

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