Blob Blame History Raw
From c652a62d1cce1b17b2d98d82a10da71dc8be9501 Mon Sep 17 00:00:00 2001
From: Matthew Fluet <matthew.fluet@gmail.com>
Date: Thu, 15 Feb 2018 14:54:25 -0500
Subject: [PATCH 5/5] Set `LIB_REL_BIN` in `mlton` script when installing

See a3cccd81e.

Some systems (e.g., x86_64 Fedora) will set `libdir` to `/usr/lib64`, so it is
necessary to compute and set the relative path from `TBIN` to `TLIB` when
installing `$(TBIN)/mlton`.

While GNU `realpath` would suffice, it does not exist on MacOS (and
other *BSD?).  A small, probably not entirely robust, shell command is
constructed to compute relative paths.
---
 Makefile.binary | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/Makefile.binary b/Makefile.binary
index 0f5e78522..bb65999a8 100644
--- a/Makefile.binary
+++ b/Makefile.binary
@@ -25,11 +25,15 @@ RM := rm -rf
 
 ######################################################################
 
+TGT_REL_SRC = ref="$(1)" pos="$(2)" down=; ref="$${ref%%/}" pos="$${pos%%/}"; while :; do test "$$pos" = '/' && break ; case "$$ref" in "$$pos"/*) break;; esac; down="../$$down"; pos="$${pos%/*}"; done; echo "$$down$${ref\#\#$$pos/}"
+
 SBIN := $(ROOT)/bin
 SLIB := $(ROOT)/lib/mlton
 SMAN := $(ROOT)/share/man/man1
 SDOC := $(ROOT)/share/doc/mlton
 
+SLIB_REL_SBIN := $(shell $(call TGT_REL_SRC,$(SLIB),$(SBIN)))
+
 prefix := $(PREFIX)
 exec_prefix := $(prefix)
 bindir := $(exec_prefix)/bin
@@ -45,10 +49,16 @@ TMAN := $(man1dir)
 TDOC := $(docdir)
 TEXM := $(TDOC)/examples
 
+TLIB_REL_TBIN := $(shell $(call TGT_REL_SRC,$(TLIB),$(TBIN)))
+
 .PHONY: install
 install:
 	$(MKDIR) "$(TBIN)" "$(TLIB)" "$(TMAN)" "$(TDOC)"
 	$(CP) "$(SBIN)/." "$(TBIN)/"
+	$(SED) \
+		-e "s;^LIB_REL_BIN=.*;LIB_REL_BIN=\"$(TLIB_REL_TBIN)\";" \
+		< "$(SBIN)/mlton" > "$(TBIN)/mlton"
+	chmod a+x "$(TBIN)/mlton"
 	$(CP) "$(SLIB)/." "$(TLIB)/"
 	$(CP) "$(SMAN)/." "$(TMAN)/"
 	if [ -d "$(SDOC)" ]; then $(CP) "$(SDOC)/." "$(TDOC)/"; fi
-- 
2.14.3