From 3fd44ec840459ed1c53eab1a206090cdc0983e2b Mon Sep 17 00:00:00 2001
From: Maxim Cournoyer <maxim.cournoyer@savoirfairelinux.com>
Date: Tue, 16 Feb 2021 15:41:36 -0500
Subject: [PATCH] contrib: Relax the file name requirements for the contrib
 scripts.

It should only worry about its parent directory, not its grandparent.
This makes it possible to bind mount just daemon/contrib in a
container, to run 'make fetch' for example.

* contrib/bootstrap: Adjust relative paths.
* contrib/src/main.mak: Express using the CURDIR variable.
(PATH): Express using the TOPSRC variable.
(pkg_static): Express using the SRC environment variable.

Change-Id: I02cba2249e4971d76ef0af0fa00f4b1af61c5aff
---
 contrib/bootstrap    |  6 +++---
 contrib/src/main.mak | 10 ++++++----
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/contrib/bootstrap b/contrib/bootstrap
index a9346cd2e6..c51a5fd45f 100755
--- a/contrib/bootstrap
+++ b/contrib/bootstrap
@@ -39,7 +39,7 @@ PKGS_ENABLE=
 PKGS_DISABLE=
 CONF_TARBALLS=
 
-if test ! -f "../../contrib/src/main.mak"
+if test ! -f "../src/main.mak"
 then
 	echo "$0 must be run from a subdirectory"
 	exit 1
@@ -270,7 +270,7 @@ esac
 # Results output
 #
 test -e Makefile && unlink Makefile
-ln -sf ../../contrib/src/main.mak Makefile || exit $?
+ln -sf ../src/main.mak Makefile || exit $?
 cat << EOF
 Bootstrap completed.
 
@@ -289,4 +289,4 @@ Other targets:
  * make package       prepare prebuilt packages
 EOF
 
-mkdir -p ../../contrib/tarballs || exit $?
+mkdir -p ../tarballs || exit $?
diff --git a/contrib/src/main.mak b/contrib/src/main.mak
index 101a302fc0..b131b40451 100644
--- a/contrib/src/main.mak
+++ b/contrib/src/main.mak
@@ -23,8 +23,10 @@ all: install
 # bootstrap configuration
 include config.mak
 
-TOPSRC ?= $(abspath ../../contrib)
-TOPDST ?= $(abspath ..)
+# The bootstrap script is enforced to run from a child directory of
+# daemon/contrib; TOPSRC corresponds to this contrib/ directory.
+TOPSRC ?= $(abspath $(CURDIR)/..)
+TOPDST ?= $(abspath $(CURDIR)/..)
 SRC := $(TOPSRC)/src
 
 # Resolves TARBALLS using the following precedence rules:
@@ -33,7 +35,7 @@ SRC := $(TOPSRC)/src
 # 3. Default value
 TARBALLS := $(or $(TARBALLS),$(CONF_TARBALLS),$(TOPSRC)/tarballs)
 
-PATH :=$(abspath ../../extras/tools/build/bin):$(PATH)
+PATH :=$(abspath $(TOPSRC)/../extras/tools/build/bin):$(PATH)
 export PATH
 
 PKGS_ALL := $(patsubst $(SRC)/%/rules.mak,%,$(wildcard $(SRC)/*/rules.mak))
@@ -367,7 +369,7 @@ UNPACK = $(RM) -R $@ \
 UNPACK_DIR = $(basename $(basename $(notdir $<)))
 APPLY = (cd $(UNPACK_DIR) && patch -flp1) <
 APPLY_BIN = (cd $(UNPACK_DIR) && patch --binary -flp1) <
-pkg_static = (cd $(UNPACK_DIR) && ../../../contrib/src/pkg-static.sh $(1))
+pkg_static = (cd $(UNPACK_DIR) && $(SRC)/pkg-static.sh $(1))
 MOVE = mv $(UNPACK_DIR) $@ && touch $@
 
 AUTOMAKE_DATA_DIRS=$(foreach n,$(foreach n,$(subst :, ,$(shell echo $$PATH)),$(abspath $(n)/../share)),$(wildcard $(n)/automake*))
-- 
GitLab