Skip to contentSkip to conversation

Makefile: expand ~ in DESTDIR

PATCH In review Masatake YAMATO 3 participants 5 messages May 31, 2023 – Jun 8, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Makefile: expand ~ in DESTDIR

Though instructed as

DESTDIR=~/obj ./scripts/env_use_destdir make test

in README.md, compiling policy_define.c was failed with following errors:

    make[1]: Entering directory '/home/yamato/var/selinux/checkpolicy'
    cc -O2 -Werror -Wall -Wextra -Wfloat-equal -Wformat=2 -Winit-self \
       -Wmissing-format-attribute -Wmissing-noreturn -Wmissing-prototypes \
       -Wnull-dereference -Wpointer-arith -Wshadow -Wstrict-prototypes \
       -Wundef -Wunused -Wwrite-strings -fno-common -I~/obj/usr/include \
       -o policy_define.o -c policy_define.c
    policy_define.c: In function ‘define_te_avtab_xperms_helper’:
    policy_define.c:2083:61: error: ‘RULE_NOTSELF’ undeclared (first use in this function); did you mean ‘RULE_SELF’?
     2083 |                         avrule->flags |= (add ? RULE_SELF : RULE_NOTSELF);
	  |                                                             ^~~~~~~~~~~~
	  |                                                             RULE_SELF

because cc cannot find the directory ~/obj/usr/include passed via -I option.

cc doesn't expand "~".

---
 Makefile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Makefile +3 -3
index 2ffba8e9..053c6d3d 100644
@@ -26,11 +26,11 @@ else
 endif
 
 ifneq ($(DESTDIR),)
-	LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
+	LIBDIR ?= $(wildcard $(DESTDIR))$(PREFIX)/lib
 	LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 
-	CFLAGS += -I$(DESTDIR)$(PREFIX)/include
-	LDFLAGS += -L$(DESTDIR)$(PREFIX)/lib -L$(LIBDIR)
+	CFLAGS += -I$(wildcard $(DESTDIR))$(PREFIX)/include
+	LDFLAGS += -L$(wildcard $(DESTDIR))$(PREFIX)/lib -L$(LIBDIR)
 	export CFLAGS
 	export LDFLAGS
 	export LIBSEPOLA
Signature · 1 line
2.40.1
#1 lore raw
Quoted 18 lines · Masatake YAMATO

Though instructed as

DESTDIR=~/obj ./scripts/env_use_destdir make test

in README.md, compiling policy_define.c was failed with following errors:

    make[1]: Entering directory '/home/yamato/var/selinux/checkpolicy'
    cc -O2 -Werror -Wall -Wextra -Wfloat-equal -Wformat=2 -Winit-self \
       -Wmissing-format-attribute -Wmissing-noreturn -Wmissing-prototypes \
       -Wnull-dereference -Wpointer-arith -Wshadow -Wstrict-prototypes \
       -Wundef -Wunused -Wwrite-strings -fno-common -I~/obj/usr/include \
       -o policy_define.o -c policy_define.c
    policy_define.c: In function ‘define_te_avtab_xperms_helper’:
    policy_define.c:2083:61: error: ‘RULE_NOTSELF’ undeclared (first use in this function); did you mean ‘RULE_SELF’?
     2083 |                         avrule->flags |= (add ? RULE_SELF : RULE_NOTSELF);
	  |                                                             ^~~~~~~~~~~~
	  |                                                             RULE_SELF
Quoted 5 lines

because cc cannot find the directory ~/obj/usr/include passed via -I option.

cc doesn't expand "~".

It doesn't work when DESTDIR does not exist - If no existing file name matches a pattern, then that pattern is omitted from the output of the wildcard function, see
https://www.gnu.org/software/make/manual/html_node/Wildcard-Function.html

Petr

Quoted 25 lines
---
 Makefile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Makefile +3 -3
index 2ffba8e9..053c6d3d 100644
@@ -26,11 +26,11 @@ else
 endif
 
 ifneq ($(DESTDIR),)
-	LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
+	LIBDIR ?= $(wildcard $(DESTDIR))$(PREFIX)/lib
 	LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 
-	CFLAGS += -I$(DESTDIR)$(PREFIX)/include
-	LDFLAGS += -L$(DESTDIR)$(PREFIX)/lib -L$(LIBDIR)
+	CFLAGS += -I$(wildcard $(DESTDIR))$(PREFIX)/include
+	LDFLAGS += -L$(wildcard $(DESTDIR))$(PREFIX)/lib -L$(LIBDIR)
 	export CFLAGS
 	export LDFLAGS
 	export LIBSEPOLA
Signature · 1 line
2.40.1
#2 lore raw
Quoted 6 lines · Petr Lautrbach
Quoted 3 lines · Masatake YAMATO

Though instructed as

DESTDIR=~/obj ./scripts/env_use_destdir make test

Is that a valid use case of the script env_use_destdir? I thought the script is just for executing binaries depending on the shared libraries in DESTDIR (e.g. DESTDIR=~/obj ./scripts/env_use_destdir seinfo), not for make invocations.

Quoted 55 lines
Quoted 15 lines

in README.md, compiling policy_define.c was failed with following errors:

    make[1]: Entering directory '/home/yamato/var/selinux/checkpolicy'
    cc -O2 -Werror -Wall -Wextra -Wfloat-equal -Wformat=2 -Winit-self \
       -Wmissing-format-attribute -Wmissing-noreturn -Wmissing-prototypes \
       -Wnull-dereference -Wpointer-arith -Wshadow -Wstrict-prototypes \
       -Wundef -Wunused -Wwrite-strings -fno-common -I~/obj/usr/include \
       -o policy_define.o -c policy_define.c
    policy_define.c: In function ‘define_te_avtab_xperms_helper’:
    policy_define.c:2083:61: error: ‘RULE_NOTSELF’ undeclared (first use in this function); did you mean ‘RULE_SELF’?
     2083 |                         avrule->flags |= (add ? RULE_SELF : RULE_NOTSELF);
        |                                                             ^~~~~~~~~~~~
        |                                                             RULE_SELF
Quoted 5 lines

because cc cannot find the directory ~/obj/usr/include passed via -I option.

cc doesn't expand "~".

It doesn't work when DESTDIR does not exist - If no existing file name matches a pattern, then that pattern is omitted from the output of the wildcard function, see
https://www.gnu.org/software/make/manual/html_node/Wildcard-Function.html

Petr

Quoted 25 lines
---
 Makefile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Makefile +3 -4
index 2ffba8e9..053c6d3d 100644
@@ -26,11 +26,11 @@ else
 endif
 
 ifneq ($(DESTDIR),)
-     LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
+     LIBDIR ?= $(wildcard $(DESTDIR))$(PREFIX)/lib
      LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 
-     CFLAGS += -I$(DESTDIR)$(PREFIX)/include
-     LDFLAGS += -L$(DESTDIR)$(PREFIX)/lib -L$(LIBDIR)
+     CFLAGS += -I$(wildcard $(DESTDIR))$(PREFIX)/include
+     LDFLAGS += -L$(wildcard $(DESTDIR))$(PREFIX)/lib -L$(LIBDIR)
      export CFLAGS
      export LDFLAGS
      export LIBSEPOLA
--

2.40.1

#3 lore raw
Quoted 4 lines · Christian Göttsche
Quoted 3 lines · Petr Lautrbach

Masatake YAMATO <[email protected]> writes:

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

Though instructed as

DESTDIR=~/obj ./scripts/env_use_destdir make test

Is that a valid use case of the script env_use_destdir? I thought the script is just for executing binaries depending on the shared libraries in DESTDIR (e.g. DESTDIR=~/obj ./scripts/env_use_destdir seinfo), not for make invocations.

make is just another binary to run in pre-set environment. Especially for make test it is important to use PATH and LD_LIBRARY_PATH pointing to the new built binaries.

I personally use source ./scripts/env_use_destdir also for manual testing.

Petr

Quoted 55 lines
Quoted 55 lines
Quoted 15 lines

in README.md, compiling policy_define.c was failed with following errors:

    make[1]: Entering directory '/home/yamato/var/selinux/checkpolicy'
    cc -O2 -Werror -Wall -Wextra -Wfloat-equal -Wformat=2 -Winit-self \
       -Wmissing-format-attribute -Wmissing-noreturn -Wmissing-prototypes \
       -Wnull-dereference -Wpointer-arith -Wshadow -Wstrict-prototypes \
       -Wundef -Wunused -Wwrite-strings -fno-common -I~/obj/usr/include \
       -o policy_define.o -c policy_define.c
    policy_define.c: In function ‘define_te_avtab_xperms_helper’:
    policy_define.c:2083:61: error: ‘RULE_NOTSELF’ undeclared (first use in this function); did you mean ‘RULE_SELF’?
     2083 |                         avrule->flags |= (add ? RULE_SELF : RULE_NOTSELF);
        |                                                             ^~~~~~~~~~~~
        |                                                             RULE_SELF
Quoted 5 lines

because cc cannot find the directory ~/obj/usr/include passed via -I option.

cc doesn't expand "~".

It doesn't work when DESTDIR does not exist - If no existing file name matches a pattern, then that pattern is omitted from the output of the wildcard function, see
https://www.gnu.org/software/make/manual/html_node/Wildcard-Function.html

Petr

Quoted 25 lines
---
 Makefile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Makefile +3 -4
index 2ffba8e9..053c6d3d 100644
@@ -26,11 +26,11 @@ else
 endif
 
 ifneq ($(DESTDIR),)
-     LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
+     LIBDIR ?= $(wildcard $(DESTDIR))$(PREFIX)/lib
      LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 
-     CFLAGS += -I$(DESTDIR)$(PREFIX)/include
-     LDFLAGS += -L$(DESTDIR)$(PREFIX)/lib -L$(LIBDIR)
+     CFLAGS += -I$(wildcard $(DESTDIR))$(PREFIX)/include
+     LDFLAGS += -L$(wildcard $(DESTDIR))$(PREFIX)/lib -L$(LIBDIR)
      export CFLAGS
      export LDFLAGS
      export LIBSEPOLA
--

2.40.1

#4 lore raw
In reply to Masatake YAMATO

I would like to withdraw my patch.
It seems that I skipped install target before running the test target. So I got the error.

Sorry for making noise.

Masatake YAMATO

Quoted 49 lines

Though instructed as

DESTDIR=~/obj ./scripts/env_use_destdir make test

in README.md, compiling policy_define.c was failed with following errors:

    make[1]: Entering directory '/home/yamato/var/selinux/checkpolicy'
    cc -O2 -Werror -Wall -Wextra -Wfloat-equal -Wformat=2 -Winit-self \
       -Wmissing-format-attribute -Wmissing-noreturn -Wmissing-prototypes \
       -Wnull-dereference -Wpointer-arith -Wshadow -Wstrict-prototypes \
       -Wundef -Wunused -Wwrite-strings -fno-common -I~/obj/usr/include \
       -o policy_define.o -c policy_define.c
    policy_define.c: In function ‘define_te_avtab_xperms_helper’:
    policy_define.c:2083:61: error: ‘RULE_NOTSELF’ undeclared (first use in this function); did you mean ‘RULE_SELF’?
     2083 |                         avrule->flags |= (add ? RULE_SELF : RULE_NOTSELF);
	  |                                                             ^~~~~~~~~~~~
	  |                                                             RULE_SELF

because cc cannot find the directory ~/obj/usr/include passed via -I option.

cc doesn't expand "~".

---
 Makefile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Makefile +3 -3
index 2ffba8e9..053c6d3d 100644
@@ -26,11 +26,11 @@ else
 endif
 
 ifneq ($(DESTDIR),)
-	LIBDIR ?= $(DESTDIR)$(PREFIX)/lib
+	LIBDIR ?= $(wildcard $(DESTDIR))$(PREFIX)/lib
 	LIBSEPOLA ?= $(LIBDIR)/libsepol.a
 
-	CFLAGS += -I$(DESTDIR)$(PREFIX)/include
-	LDFLAGS += -L$(DESTDIR)$(PREFIX)/lib -L$(LIBDIR)
+	CFLAGS += -I$(wildcard $(DESTDIR))$(PREFIX)/include
+	LDFLAGS += -L$(wildcard $(DESTDIR))$(PREFIX)/lib -L$(LIBDIR)
 	export CFLAGS
 	export LDFLAGS
 	export LIBSEPOLA
Signature · 1 line
2.40.1