From 1fa2c26c0053a0cb5c6afa4584a87fa155bade96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samo=20Poga=C4=8Dnik?= Date: Sun, 1 Dec 2024 12:18:09 +0100 Subject: [PATCH] Fixing github tests on macos. Added pure shell function to get relative path between two dirs. --- Makefile | 5 ++--- share/pnrelpath.sh | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 share/pnrelpath.sh diff --git a/Makefile b/Makefile index e2be1575..5a4b4e8c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ SHELL := bash INSTALL ?= install -UNAME := $(shell uname); -REALPATH := $(shell if [ "$(UNAME)" == "Darwin" ]; then echo grealpath; else echo realpath; fi) +UNAME := $(shell uname) # Make sure we have git: ifeq ($(shell which git),) @@ -24,7 +23,7 @@ INSTALL_BIN ?= $(PREFIX)/bin INSTALL_LIB ?= $(PREFIX)/share/$(NAME) INSTALL_EXT ?= $(INSTALL_LIB)/$(NAME).d INSTALL_MAN1 ?= $(PREFIX)/share/man/man1 -LINK_REL_DIR := $(shell $(REALPATH) --relative-to=$(INSTALL_BIN) $(INSTALL_LIB)) +LINK_REL_DIR := $(shell bash share/pnrelpath.sh $(INSTALL_BIN) $(INSTALL_LIB)) # Docker variables: DOCKER_TAG ?= 0.0.6 diff --git a/share/pnrelpath.sh b/share/pnrelpath.sh new file mode 100644 index 00000000..800e822e --- /dev/null +++ b/share/pnrelpath.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# +# from: https://unix.stackexchange.com/questions/573047/how-to-get-the-relative-path-between-two-directories +# +# Expects two parameters, source-dir and target-dir, both absolute canonicalized +# non-empty pathnames, either may be /-ended, neither need exist. +# Returns result in shell variable $REPLY as a relative path from source-dir +# to target-dir without trailing /, . if void. +# +# Algorithm is from a 2005 comp.unix.shell posting which has now ascended to +# archive.org. + +pnrelpath() { + set -- "${1%/}/" "${2%/}/" '' ## '/'-end to avoid mismatch + while [ "$1" ] && [ "$2" = "${2#"$1"}" ] ## reduce $1 to shared path + do set -- "${1%/?*/}/" "$2" "../$3" ## source/.. target ../relpath + done + REPLY="${3}${2#"$1"}" ## build result + # unless root chomp trailing '/', replace '' with '.' + [ "${REPLY#/}" ] && REPLY="${REPLY%/}" || REPLY="${REPLY:-.}" +} + +pnrelpath "$1" "$2" + +echo $REPLY