Skip to content

Commit

Permalink
Fixing github tests on macos.
Browse files Browse the repository at this point in the history
Added pure shell function to get relative path between two dirs.
  • Loading branch information
spog committed Dec 1, 2024
1 parent b932992 commit 1fa2c26
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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),)
Expand All @@ -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
Expand Down
25 changes: 25 additions & 0 deletions share/pnrelpath.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1fa2c26

Please sign in to comment.