diff mbox series

[kvm-unit-tests] (arm|powerpc|s390x): Makefile: add `%.aux.o` target

Message ID 20240125151127.94798-1-mhartmay@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series [kvm-unit-tests] (arm|powerpc|s390x): Makefile: add `%.aux.o` target | expand

Commit Message

Marc Hartmayer Jan. 25, 2024, 3:11 p.m. UTC
It's unusual to create multiple files in one target rule, therefore create an
extra target for `%.aux.o` and list it as prerequisite. As a side effect, this
change fixes the dependency tracking of the prerequisites of
`.aux.o` (`lib/auxinfo.c` was missing).

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
---
 arm/Makefile.common     | 23 ++++++++++++-----------
 powerpc/Makefile.common | 10 +++++-----
 s390x/Makefile          |  9 +++++----
 3 files changed, 22 insertions(+), 20 deletions(-)

Comments

Marc Hartmayer Jan. 25, 2024, 3:30 p.m. UTC | #1
On Thu, Jan 25, 2024 at 04:11 PM +0100, Marc Hartmayer <mhartmay@linux.ibm.com> wrote:
> It's unusual to create multiple files in one target rule, therefore create an
> extra target for `%.aux.o` and list it as prerequisite. As a side effect, this
> change fixes the dependency tracking of the prerequisites of
> `.aux.o` (`lib/auxinfo.c` was missing).
>
> Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
> ---

Note: I have only tested it for s390x, so please take a close look!
Thomas Huth Feb. 1, 2024, 12:09 p.m. UTC | #2
On 25/01/2024 16.11, Marc Hartmayer wrote:
> It's unusual to create multiple files in one target rule, therefore create an
> extra target for `%.aux.o` and list it as prerequisite. As a side effect, this
> change fixes the dependency tracking of the prerequisites of
> `.aux.o` (`lib/auxinfo.c` was missing).
> 
> Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
> ---
>   arm/Makefile.common     | 23 ++++++++++++-----------
>   powerpc/Makefile.common | 10 +++++-----
>   s390x/Makefile          |  9 +++++----
>   3 files changed, 22 insertions(+), 20 deletions(-)

Patch looks sane to me, so I went ahead and pushed it to the git repo. Thanks!

By the way, unrelated to your modifications, but while testing it, I noticed 
that "make distclean" leaves some files behind for the s390x build:

  ./configure --arch=s390x --cross-prefix=s390x-linux-gnu-
  make -j$(nproc)
  make distclean
  git status --ignored

On branch master
Your branch is up to date with 'origin/master'.

Ignored files:
   (use "git add -f <file>..." to include in what will be committed)
	.mvpg-snippet.d
	.sie-dat.d
	.spec_ex.d
	lib/auxinfo.o
	s390x/snippets/c/.cstart.d
	s390x/snippets/c/.flat.d

... in case someone wants to have a look ...

  Thomas
Andrew Jones Feb. 1, 2024, 1:55 p.m. UTC | #3
On Thu, Feb 01, 2024 at 01:09:10PM +0100, Thomas Huth wrote:
> On 25/01/2024 16.11, Marc Hartmayer wrote:
> > It's unusual to create multiple files in one target rule, therefore create an
> > extra target for `%.aux.o` and list it as prerequisite. As a side effect, this
> > change fixes the dependency tracking of the prerequisites of
> > `.aux.o` (`lib/auxinfo.c` was missing).
> > 
> > Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
> > ---
> >   arm/Makefile.common     | 23 ++++++++++++-----------
> >   powerpc/Makefile.common | 10 +++++-----
> >   s390x/Makefile          |  9 +++++----
> >   3 files changed, 22 insertions(+), 20 deletions(-)
> 
> Patch looks sane to me, so I went ahead and pushed it to the git repo. Thanks!

I'll update the riscv port to make the same changes before merging it.

Thanks,
drew

> 
> By the way, unrelated to your modifications, but while testing it, I noticed
> that "make distclean" leaves some files behind for the s390x build:
> 
>  ./configure --arch=s390x --cross-prefix=s390x-linux-gnu-
>  make -j$(nproc)
>  make distclean
>  git status --ignored
> 
> On branch master
> Your branch is up to date with 'origin/master'.
> 
> Ignored files:
>   (use "git add -f <file>..." to include in what will be committed)
> 	.mvpg-snippet.d
> 	.sie-dat.d
> 	.spec_ex.d
> 	lib/auxinfo.o
> 	s390x/snippets/c/.cstart.d
> 	s390x/snippets/c/.flat.d
> 
> ... in case someone wants to have a look ...
> 
>  Thomas
>
Marc Hartmayer Feb. 1, 2024, 2:16 p.m. UTC | #4
On Thu, Feb 01, 2024 at 01:09 PM +0100, Thomas Huth <thuth@redhat.com> wrote:
> On 25/01/2024 16.11, Marc Hartmayer wrote:
>> It's unusual to create multiple files in one target rule, therefore create an
>> extra target for `%.aux.o` and list it as prerequisite. As a side effect, this
>> change fixes the dependency tracking of the prerequisites of
>> `.aux.o` (`lib/auxinfo.c` was missing).
>> 
>> Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
>> ---
>>   arm/Makefile.common     | 23 ++++++++++++-----------
>>   powerpc/Makefile.common | 10 +++++-----
>>   s390x/Makefile          |  9 +++++----
>>   3 files changed, 22 insertions(+), 20 deletions(-)
>
> Patch looks sane to me, so I went ahead and pushed it to the git repo.
> Thanks!

Thanks.

>
> By the way, unrelated to your modifications, but while testing it, I noticed 
> that "make distclean" leaves some files behind for the s390x build:
>
>   ./configure --arch=s390x --cross-prefix=s390x-linux-gnu-
>   make -j$(nproc)
>   make distclean
>   git status --ignored
>
> On branch master
> Your branch is up to date with 'origin/master'.
>
> Ignored files:
>    (use "git add -f <file>..." to include in what will be committed)
> 	.mvpg-snippet.d
> 	.sie-dat.d
> 	.spec_ex.d

> 	lib/auxinfo.o

At least, this file is related to this patch. Before it was always
deleted, now it’s only removed if the “Makefile semantics” enforce it.

[…snip]
diff mbox series

Patch

diff --git a/arm/Makefile.common b/arm/Makefile.common
index 5214c8acdab3..54cb4a63ab64 100644
--- a/arm/Makefile.common
+++ b/arm/Makefile.common
@@ -70,14 +70,14 @@  eabiobjs = lib/arm/eabi_compat.o
 FLATLIBS = $(libcflat) $(LIBFDT_archive) $(libeabi)
 
 ifeq ($(CONFIG_EFI),y)
+%.aux.o: $(SRCDIR)/lib/auxinfo.c
+	$(CC) $(CFLAGS) -c -o $@ $^ \
+		-DPROGNAME=\"$(@:.aux.o=.efi)\" -DAUXFLAGS=$(AUXFLAGS)
+
 %.so: EFI_LDFLAGS += -defsym=EFI_SUBSYSTEM=0xa --no-undefined
-%.so: %.o $(FLATLIBS) $(SRCDIR)/arm/efi/elf_aarch64_efi.lds $(cstart.o)
-	$(CC) $(CFLAGS) -c -o $(@:.so=.aux.o) $(SRCDIR)/lib/auxinfo.c \
-		-DPROGNAME=\"$(@:.so=.efi)\" -DAUXFLAGS=$(AUXFLAGS)
+%.so: %.o $(FLATLIBS) $(SRCDIR)/arm/efi/elf_aarch64_efi.lds $(cstart.o) %.aux.o
 	$(LD) $(EFI_LDFLAGS) -o $@ -T $(SRCDIR)/arm/efi/elf_aarch64_efi.lds \
-		$(filter %.o, $^) $(FLATLIBS) $(@:.so=.aux.o) \
-		$(EFI_LIBS)
-	$(RM) $(@:.so=.aux.o)
+		$(filter %.o, $^) $(FLATLIBS) $(EFI_LIBS)
 
 %.efi: %.so
 	$(call arch_elf_check, $^)
@@ -90,13 +90,14 @@  ifeq ($(CONFIG_EFI),y)
 		-j .reloc \
 		-O binary $^ $@
 else
+%.aux.o: $(SRCDIR)/lib/auxinfo.c
+	$(CC) $(CFLAGS) -c -o $@ $^ \
+		-DPROGNAME=\"$(@:.aux.o=.flat)\" -DAUXFLAGS=$(AUXFLAGS)
+
 %.elf: LDFLAGS += $(arch_LDFLAGS)
-%.elf: %.o $(FLATLIBS) $(SRCDIR)/arm/flat.lds $(cstart.o)
-	$(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) $(SRCDIR)/lib/auxinfo.c \
-		-DPROGNAME=\"$(@:.elf=.flat)\" -DAUXFLAGS=$(AUXFLAGS)
+%.elf: %.o $(FLATLIBS) $(SRCDIR)/arm/flat.lds $(cstart.o) %.aux.o
 	$(LD) $(LDFLAGS) -o $@ -T $(SRCDIR)/arm/flat.lds \
-		$(filter %.o, $^) $(FLATLIBS) $(@:.elf=.aux.o)
-	$(RM) $(@:.elf=.aux.o)
+		$(filter %.o, $^) $(FLATLIBS)
 	@chmod a-x $@
 
 %.flat: %.elf
diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common
index f8f474908b06..483ff64829a7 100644
--- a/powerpc/Makefile.common
+++ b/powerpc/Makefile.common
@@ -47,16 +47,16 @@  cflatobjs += lib/powerpc/smp.o
 
 OBJDIRS += lib/powerpc
 
+%.aux.o: $(SRCDIR)/lib/auxinfo.c
+	$(CC) $(CFLAGS) -c -o $@ $^ -DPROGNAME=\"$(@:.aux.o=.elf)\"
+
 FLATLIBS = $(libcflat) $(LIBFDT_archive)
 %.elf: CFLAGS += $(arch_CFLAGS)
 %.elf: LDFLAGS += $(arch_LDFLAGS) -pie -n
-%.elf: %.o $(FLATLIBS) $(SRCDIR)/powerpc/flat.lds $(cstart.o) $(reloc.o)
-	$(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) $(SRCDIR)/lib/auxinfo.c \
-		-DPROGNAME=\"$@\"
+%.elf: %.o $(FLATLIBS) $(SRCDIR)/powerpc/flat.lds $(cstart.o) $(reloc.o) %.aux.o
 	$(LD) $(LDFLAGS) -o $@ \
 		-T $(SRCDIR)/powerpc/flat.lds --build-id=none \
-		$(filter %.o, $^) $(FLATLIBS) $(@:.elf=.aux.o)
-	$(RM) $(@:.elf=.aux.o)
+		$(filter %.o, $^) $(FLATLIBS)
 	@chmod a-x $@
 	@echo -n Checking $@ for unsupported reloc types...
 	@if $(OBJDUMP) -R $@ | grep R_ | grep -v R_PPC64_RELATIVE; then	\
diff --git a/s390x/Makefile b/s390x/Makefile
index f79fd0098312..e64521e002ce 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -176,13 +176,14 @@  lds-autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d -MT $@
 %.lds: %.lds.S $(asm-offsets)
 	$(CPP) $(lds-autodepend-flags) $(CPPFLAGS) -P -C -o $@ $<
 
+%.aux.o: $(SRCDIR)/lib/auxinfo.c
+	$(CC) $(CFLAGS) -c -o $@ $^ -DPROGNAME=\"$(@:.aux.o=.elf)\"
+
 .SECONDEXPANSION:
-%.elf: $(FLATLIBS) $(asmlib) $(SRCDIR)/s390x/flat.lds $$(snippets-obj) $$(snippet-hdr-obj) %.o
-	$(CC) $(CFLAGS) -c -o $(@:.elf=.aux.o) $(SRCDIR)/lib/auxinfo.c -DPROGNAME=\"$@\"
+%.elf: $(FLATLIBS) $(asmlib) $(SRCDIR)/s390x/flat.lds $$(snippets-obj) $$(snippet-hdr-obj) %.o %.aux.o
 	@$(CC) $(LDFLAGS) -o $@ -T $(SRCDIR)/s390x/flat.lds \
-		$(filter %.o, $^) $(FLATLIBS) $(snippets-obj) $(snippet-hdr-obj) $(@:.elf=.aux.o) || \
+		$(filter %.o, $^) $(FLATLIBS) $(snippets-obj) $(snippet-hdr-obj) || \
 		{ echo "Failure probably caused by missing definition of gen-se-header executable"; exit 1; }
-	$(RM) $(@:.elf=.aux.o)
 	@chmod a-x $@
 
 # Secure Execution Customer Communication Key file