From a3cccd81e1f77bb5b3c45361681ec4b232596068 Mon Sep 17 00:00:00 2001
From: Matthew Fluet <matthew.fluet@gmail.com>
Date: Thu, 15 Feb 2018 14:34:49 -0500
Subject: [PATCH 3/5] Set `LIB_REL_BIN` in `mlton` script when installing
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`. (For robustness, also compute and set the relative
path from `BIN` to `LIB` when installing `$(BIN)/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 | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/Makefile b/Makefile
index a6d5474af..f3f12d46d 100644
--- a/Makefile
+++ b/Makefile
@@ -55,11 +55,14 @@ XARGS := xargs
######################################################################
######################################################################
+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/}"
+
SRC := $(shell pwd)
BUILD := $(SRC)/build
BIN := $(BUILD)/bin
LIB := $(BUILD)/lib/mlton
INC := $(LIB)/include
+LIB_REL_BIN := $(shell $(call TGT_REL_SRC,$(LIB),$(BIN)))
PATH := $(BIN):$(shell echo $$PATH)
@@ -306,6 +309,7 @@ runtime:
.PHONY: script
script:
$(SED) \
+ -e "s;^LIB_REL_BIN=.*;LIB_REL_BIN=\"$(LIB_REL_BIN)\";" \
-e "s;^EXE=.*;EXE=\"$(EXE)\";" \
-e "s;^CC=.*;CC=\"$(CC)\";" \
-e "s;^GMP_INC_DIR=.*;GMP_INC_DIR=\"$(WITH_GMP_INC_DIR)\";" \
@@ -419,6 +423,8 @@ TMAN := $(DESTDIR)$(man1dir)
TDOC := $(DESTDIR)$(docdir)
TEXM := $(TDOC)/examples
+TLIB_REL_TBIN := $(shell $(call TGT_REL_SRC,$(TLIB),$(TBIN)))
+
GZIP_MAN := true
ifeq ($(findstring $(TARGET_OS), openbsd solaris), $(TARGET_OS))
GZIP_MAN := false
@@ -438,6 +444,10 @@ MAN_PAGES := \
install-no-strip:
$(MKDIR) "$(TBIN)" "$(TLIB)" "$(TMAN)"
$(CP) "$(BIN)/." "$(TBIN)/"
+ $(SED) \
+ -e "s;^LIB_REL_BIN=.*;LIB_REL_BIN=\"$(TLIB_REL_TBIN)\";" \
+ < "$(BIN)/mlton" > "$(TBIN)/mlton"
+ chmod a+x "$(TBIN)/mlton"
$(CP) "$(LIB)/." "$(TLIB)/"
cd "$(SRC)/man" && $(CP) $(MAN_PAGES) "$(TMAN)/"
ifeq (true, $(GZIP_MAN))
--
2.14.3