
MAIN_PKG = rhombus-main
PKGS =  \
  actor \
  actor-lib \
  box-extra \
  box-extra-lib \
  enforest \
  enforest-lib \
  ffi2 \
  ffi2-lib \
  gui-easy \
  gui-easy-lib \
  http-easy \
  http-easy-lib \
  pict-balloon2 \
  pretty-expressive \
  pretty-expressive-lib \
  rackcheck \
  rackcheck-lib \
  resource-pool \
  resource-pool-lib \
  rhombus \
  rhombus-csv \
  rhombus-csv-lib \
  rhombus-draw \
  rhombus-draw-lib \
  rhombus-exe \
  rhombus-ffi \
  rhombus-ffi-lib \
  rhombus-gui \
  rhombus-gui-lib \
  rhombus-html \
  rhombus-html-lib \
  rhombus-html-page \
  rhombus-html-page-lib \
  rhombus-http \
  rhombus-http-lib \
  rhombus-icons \
  rhombus-json \
  rhombus-json-lib \
  rhombus-lib \
  rhombus-logo \
  rhombus-logo-lib \
  rhombus-main \
  rhombus-main-distribution \
  rhombus-main-distribution-lib \
  rhombus-net-cookie \
  rhombus-net-cookie-lib \
  rhombus-parser \
  rhombus-parser-lib \
  rhombus-pict \
  rhombus-pict-lib \
  rhombus-prototype \
  rhombus-scribble \
  rhombus-scribble-lib \
  rhombus-slideshow \
  rhombus-slideshow-lib \
  rhombus-ssl \
  rhombus-ssl-lib \
  rhombus-url \
  rhombus-url-lib \
  rhombus-xml \
  rhombus-xml-lib \
  shrubbery \
  shrubbery-lib \
  shrubbery-render \
  shrubbery-render-lib \
  version-case \
  version-case-lib

RACKET = racket

DESTDIR =
DESTDIR_DOC =

FORCE =

DEST = build/rhombus-pkg-platform

platform:
	"$(RACKET)" -A build -l- raco pkg install -u --auto --catalog catalog/ --adjacent-deps $(MAIN_PKG)
	"$(RACKET)" -A build -l- raco pkg create --dest $(DEST)/pkgs --built --format dir --from-install --adjacent-deps $(MAIN_PKG)
	"$(RACKET)" -l- pkg/dirs-catalog -q $(DEST)/catalog $(DEST)/pkgs

# For a Racket that already has packages in `PKGS` installed
# --- not recommended, and there will be warnings to ignore
platform-force:
	"$(RACKET)" -A build -l- raco pkg install $(FORCE) -u --auto --catalog catalog/ $(PKGS)
	"$(RACKET)" -A build -l- raco pkg create --dest $(DEST)/pkgs --built --format dir --from-install $(PKGS)
	"$(RACKET)" -l- pkg/dirs-catalog -q $(DEST)/catalog $(DEST)/pkgs


install:
	if [ -z "$(DESTDIR)" ]; then $(MAKE) install-no-destdir; else $(MAKE) install-destdir; fi

install-no-destdir:
	"$(RACKET)" -l- raco pkg install -i --auto --catalog $(DEST)/catalog/ $(MAIN_PKG)

install-destdir:
	"$(RACKET)" -l- raco pkg install -i --auto --catalog $(DEST)/catalog --destdir "$(DESTDIR)" $(MAIN_PKG)
	if [ -n "$(DESTDIR_DOC)" ]; then $(MAKE) install-destdir-doc; fi

# Use with `platform-force`
install-destdir-force:
	"$(RACKET)" -l- raco pkg install -i --force --catalog $(DEST)/catalog --destdir "$(DESTDIR)" $(PKGS)
	if [ -n "$(DESTDIR_DOC)" ]; then $(MAKE) install-destdir-doc; fi

install-destdir-doc:
	"$(RACKET)" -l- setup/doc-to-destdir "$(DESTDIR_DOC)" "$(DESTDIR)"


# Not in this makefile: move `($DESTDIR)` and `$(DESTDIR_DOC)` contents into place


# This makefile isn't meant to be available in the final installation context,
# but here's the intended attach command
attach:
	"$(RACKET)" -l- raco pkg install -i --attach --deps search-auto --adjacent-deps $(MAIN_PKG)

# Like `attach` mode, the makefile isn't meant to be available,
# but here's the intended link command
LINK_DIR = $(DEST)/pkgs
link:
	cd $(LINK_DIR) && "$(RACKET)" -l- raco pkg install -i --link --deps search-auto --adjacent-deps $(MAIN_PKG)

pkg-list:
	@ echo $(PKGS)
