[PATCH 3/4] tests/cpu-policy: Rework Makefile

Andrew Cooper posted 4 patches 4 years, 7 months ago
[PATCH 3/4] tests/cpu-policy: Rework Makefile
Posted by Andrew Cooper 4 years, 7 months ago
In particular, fill in the install/uninstall rules so this test can be
packaged to be automated sensibly.

Rework TARGET-y to be TARGETS, drop redundant -f's for $(RM), drop the
unconditional -O3 and use the default instead, and drop CFLAGS from the link
line but honour APPEND_LDFLAGS.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Ian Jackson <iwj@xenproject.org>
CC: Wei Liu <wl@xen.org>
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Juergen Gross <jgross@suse.com>

v2:
 * Drop -f's
 * Use %.o rather than *.o for Make level wildcards
---
 tools/tests/cpu-policy/Makefile | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/tools/tests/cpu-policy/Makefile b/tools/tests/cpu-policy/Makefile
index 70ff154da6..161732ad16 100644
--- a/tools/tests/cpu-policy/Makefile
+++ b/tools/tests/cpu-policy/Makefile
@@ -1,21 +1,19 @@
 XEN_ROOT = $(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
-TARGET-y := test-cpu-policy
+TARGETS :=
 
 # For brevity, these tests make extensive use of designated initialisers in
 # anonymous unions, but GCCs older than 4.6 can't cope.  Ignore the test in
 # this case.
-ifneq ($(clang),y)
-TARGET-$(call cc-ver,$(CC),lt,0x040600) :=
-endif
-
-ifeq ($(TARGET-y),)
+ifneq ($(gcc)$(call cc-ver,$(CC),lt,0x040600),yy)
+TARGETS += test-cpu-policy
+else
 $(warning Test harness not built, use newer compiler than "$(CC)" (version $(shell $(CC) -dumpversion)))
 endif
 
 .PHONY: all
-all: $(TARGET-y)
+all: $(TARGETS)
 
 .PHONY: run
 run: $(TARGET-y)
@@ -23,23 +21,32 @@ run: $(TARGET-y)
 
 .PHONY: clean
 clean:
-	$(RM) -f -- *.o .*.d .*.d2 test-cpu-policy
+	$(RM) -- *.o $(TARGETS) $(DEPS_RM)
 
 .PHONY: distclean
 distclean: clean
-	$(RM) -f -- *~
+	$(RM) -- *~
 
 .PHONY: install
 install: all
+	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC_BIN)
+	$(if $(TARGETS),$(INSTALL_PROG) $(TARGETS) $(DESTDIR)$(LIBEXEC_BIN))
 
 .PHONY: uninstall
+uninstall:
+	$(RM) -- $(addprefix $(DESTDIR)$(LIBEXEC_BIN)/,$(TARGETS))
 
-CFLAGS += -Werror $(CFLAGS_xeninclude) -D__XEN_TOOLS__ -O3
+CFLAGS += -Werror -D__XEN_TOOLS__
+CFLAGS += $(CFLAGS_xeninclude)
 CFLAGS += $(APPEND_CFLAGS)
 
-vpath %.c ../../../xen/lib/x86
+LDFLAGS += $(APPEND_LDFLAGS)
+
+vpath %.c $(XEN_ROOT)/xen/lib/x86
+
+%.o: Makefile
 
 test-cpu-policy: test-cpu-policy.o msr.o cpuid.o policy.o
-	$(CC) $(CFLAGS) $^ -o $@
+	$(CC) $^ -o $@ $(LDFLAGS)
 
 -include $(DEPS_INCLUDE)
-- 
2.11.0


Re: [PATCH 3/4] tests/cpu-policy: Rework Makefile
Posted by Jan Beulich 4 years, 7 months ago
On 22.06.2021 20:21, Andrew Cooper wrote:
> @@ -23,23 +21,32 @@ run: $(TARGET-y)
>  
>  .PHONY: clean
>  clean:
> -	$(RM) -f -- *.o .*.d .*.d2 test-cpu-policy
> +	$(RM) -- *.o $(TARGETS) $(DEPS_RM)
>  
>  .PHONY: distclean
>  distclean: clean
> -	$(RM) -f -- *~
> +	$(RM) -- *~
>  
>  .PHONY: install
>  install: all
> +	$(INSTALL_DIR) $(DESTDIR)$(LIBEXEC_BIN)
> +	$(if $(TARGETS),$(INSTALL_PROG) $(TARGETS) $(DESTDIR)$(LIBEXEC_BIN))
>  
>  .PHONY: uninstall
> +uninstall:
> +	$(RM) -- $(addprefix $(DESTDIR)$(LIBEXEC_BIN)/,$(TARGETS))
>  
> -CFLAGS += -Werror $(CFLAGS_xeninclude) -D__XEN_TOOLS__ -O3
> +CFLAGS += -Werror -D__XEN_TOOLS__
> +CFLAGS += $(CFLAGS_xeninclude)
>  CFLAGS += $(APPEND_CFLAGS)
>  
> -vpath %.c ../../../xen/lib/x86
> +LDFLAGS += $(APPEND_LDFLAGS)
> +
> +vpath %.c $(XEN_ROOT)/xen/lib/x86

Is this a good move? In general I think relative references are better,
because it is then possible to move the tree as a whole (or access it
from multiple locations, where each one has it appearing in a different
place in the file system). I do realize though that we have many such
absolute references, so this one more isn't making things much worse.
Still
Reviewed-by: Jan Beulich <jbeulich@suse.com>
preferably with it left relative (or a strong reason for making it
absolute spelled out in the description).

Jan