William A. Kennington III | ac69b48 | 2021-06-02 12:28:27 -0700 | [diff] [blame] | 1 | From 9ab56f841b1986cd5cdff66cb5ef222794b9ed39 Mon Sep 17 00:00:00 2001 |
| 2 | From: Dmitry Kalinkin <dmitry.kalinkin@gmail.com> |
| 3 | Date: Mon, 22 Feb 2021 14:07:58 -0500 |
| 4 | Subject: [PATCH] Makefile: escape special regex characters in paths |
| 5 | |
| 6 | Fixes a problem with certain valid install paths: |
| 7 | |
| 8 | make prefix=/tmp/a+b/ |
| 9 | Makefile:434: *** configured libdir (/tmp/a+b//lib) is outside of exec_prefix (/tmp/a+b/), can't generate pkg-config file. Stop. |
| 10 | |
| 11 | Upstream-Status: Backport [f79cd22a806993b4a62d8a4f1ba529a29a9d9ff5] |
| 12 | |
| 13 | Signed-off-by: Chen Qi <Qi.Chen@windriver.com> |
| 14 | --- |
| 15 | Makefile | 12 ++++++++---- |
| 16 | 1 file changed, 8 insertions(+), 4 deletions(-) |
| 17 | |
| 18 | diff --git a/Makefile b/Makefile |
| 19 | index ef24e94..baa1533 100644 |
| 20 | --- a/Makefile |
| 21 | +++ b/Makefile |
| 22 | @@ -411,14 +411,18 @@ INSTALL_PROGRAM ?= $(INSTALL) |
| 23 | INSTALL_DATA ?= $(INSTALL) -m 644 |
| 24 | |
| 25 | |
| 26 | -PCLIBDIR ?= $(shell echo "$(LIBDIR)" | $(SED) -n $(SED_ERE_OPT) -e "s@^$(EXEC_PREFIX)(/|$$)@@p") |
| 27 | -PCINCDIR ?= $(shell echo "$(INCLUDEDIR)" | $(SED) -n $(SED_ERE_OPT) -e "s@^$(PREFIX)(/|$$)@@p") |
| 28 | +# Escape special symbols by putting each character into its separate class |
| 29 | +EXEC_PREFIX_REGEX ?= $(shell echo "$(EXEC_PREFIX)" | $(SED) $(SED_ERE_OPT) -e "s/([^^])/[\1]/g" -e "s/\\^/\\\\^/g") |
| 30 | +PREFIX_REGEX ?= $(shell echo "$(PREFIX)" | $(SED) $(SED_ERE_OPT) -e "s/([^^])/[\1]/g" -e "s/\\^/\\\\^/g") |
| 31 | + |
| 32 | +PCLIBDIR ?= $(shell echo "$(LIBDIR)" | $(SED) -n $(SED_ERE_OPT) -e "s@^$(EXEC_PREFIX_REGEX)(/|$$)@@p") |
| 33 | +PCINCDIR ?= $(shell echo "$(INCLUDEDIR)" | $(SED) -n $(SED_ERE_OPT) -e "s@^$(PREFIX_REGEX)(/|$$)@@p") |
| 34 | PCEXECDIR?= $(if $(filter $(PREFIX),$(EXEC_PREFIX)),$$\{prefix\},$(EXEC_PREFIX)) |
| 35 | |
| 36 | ifeq (,$(PCLIBDIR)) |
| 37 | # Additional prefix check is required, since the empty string is technically a |
| 38 | # valid PCLIBDIR |
| 39 | -ifeq (,$(shell echo "$(LIBDIR)" | $(SED) -n $(SED_ERE_OPT) -e "\\@^$(EXEC_PREFIX)(/|$$)@ p")) |
| 40 | +ifeq (,$(shell echo "$(LIBDIR)" | $(SED) -n $(SED_ERE_OPT) -e "\\@^$(EXEC_PREFIX_REGEX)(/|$$)@ p")) |
| 41 | $(error configured libdir ($(LIBDIR)) is outside of exec_prefix ($(EXEC_PREFIX)), can't generate pkg-config file) |
| 42 | endif |
| 43 | endif |
| 44 | @@ -426,7 +430,7 @@ endif |
| 45 | ifeq (,$(PCINCDIR)) |
| 46 | # Additional prefix check is required, since the empty string is technically a |
| 47 | # valid PCINCDIR |
| 48 | -ifeq (,$(shell echo "$(INCLUDEDIR)" | $(SED) -n $(SED_ERE_OPT) -e "\\@^$(PREFIX)(/|$$)@ p")) |
| 49 | +ifeq (,$(shell echo "$(INCLUDEDIR)" | $(SED) -n $(SED_ERE_OPT) -e "\\@^$(PREFIX_REGEX)(/|$$)@ p")) |
| 50 | $(error configured includedir ($(INCLUDEDIR)) is outside of prefix ($(PREFIX)), can't generate pkg-config file) |
| 51 | endif |
| 52 | endif |
| 53 | -- |
| 54 | 2.17.1 |
| 55 | |