File 0004-arch-lkl-use-archprepare-rule-to-generate-config.h.patch of Package lkl

From 6cbfab8b29c4599a35bd3e26ccbbb853e5fdff8c Mon Sep 17 00:00:00 2001
From: David Disseldorp <ddiss@suse.de>
Date: Thu, 29 May 2025 19:28:02 +1000
Subject: [PATCH 4/4] arch/lkl: use archprepare rule to generate config.h

arch/lkl/include/generated/uapi/asm/config.h is generated at build time
with any of:
  #define LKL_CONFIG_64BIT 1
  #define LKL_CONFIG_CPU_BIG_ENDIAN 1
based on the build environment.
Generation is handled by Makefiles under tools/lkl, where it is then
copied to arch/lkl/include/generated/uapi/asm/config.h prior to kernel
compilation.
This change simplifies header generation by doing it directly in the
arch/lkl parent Makefile. It also improves rebuild times by only
rewriting config.h if its contents would change.

Signed-off-by: David Disseldorp <ddiss@suse.de>
---
 arch/lkl/Makefile           | 14 ++++++++++++++
 arch/lkl/include/asm/Kbuild |  2 ++
 tools/lkl/.gitignore        |  1 -
 tools/lkl/Makefile          | 12 ++----------
 tools/lkl/Makefile.autoconf |  8 --------
 5 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/arch/lkl/Makefile b/arch/lkl/Makefile
index 752a717e9e3c..5437b8df5918 100644
--- a/arch/lkl/Makefile
+++ b/arch/lkl/Makefile
@@ -65,6 +65,20 @@ core-y += arch/lkl/lib/
 core-y += arch/lkl/mm/
 core-y += arch/lkl/drivers/
 
+configh-y = "/* this header is autogenerated */\n"
+configh-$(CONFIG_64BIT) +='\#define LKL_CONFIG_64BIT 1\n'
+configh-$(CONFIG_CPU_BIG_ENDIAN) +='\#define LKL_CONFIG_CPU_BIG_ENDIAN 1\n'
+
+quiet_cmd_gen_configh = GEN     $@
+      cmd_gen_configh = mkdir -p $(dir $@); echo -en $(configh-y) > $@
+
+targets += arch/lkl/include/generated/uapi/asm/config.h
+
+arch/lkl/include/generated/uapi/asm/config.h: FORCE
+	$(call if_changed,gen_configh)
+
+archprepare: arch/lkl/include/generated/uapi/asm/config.h
+
 all: lkl.o arch/lkl/include/generated/uapi/asm/syscall_defs.h
 
 lkl.o: vmlinux
diff --git a/arch/lkl/include/asm/Kbuild b/arch/lkl/include/asm/Kbuild
index 89662979ae26..299644e097ca 100644
--- a/arch/lkl/include/asm/Kbuild
+++ b/arch/lkl/include/asm/Kbuild
@@ -32,3 +32,5 @@ generic-y += termbits.h
 generic-y += termios.h
 generic-y += time.h
 generic-y += user.h
+
+generated-y += config.h
diff --git a/tools/lkl/.gitignore b/tools/lkl/.gitignore
index 2a5f4273b0b0..d1b3c635d18c 100644
--- a/tools/lkl/.gitignore
+++ b/tools/lkl/.gitignore
@@ -13,7 +13,6 @@ tests/config
 tests/test-dlmopen
 Makefile.conf
 include/lkl_autoconf.h
-include/kernel_config.h
 tests/autoconf.sh
 *.pyc
 bin/stat
diff --git a/tools/lkl/Makefile b/tools/lkl/Makefile
index dac9fd5e79dd..918649938993 100644
--- a/tools/lkl/Makefile
+++ b/tools/lkl/Makefile
@@ -41,7 +41,7 @@ all:
 
 conf: $(OUTPUT)Makefile.conf
 
-$(OUTPUT)Makefile.conf $(OUTPUT)include/kernel_config.h $(OUTPUT)/kernel.config: Makefile.autoconf
+$(OUTPUT)Makefile.conf $(OUTPUT)/kernel.config: Makefile.autoconf
 	$(call QUIET_AUTOCONF, headers)$(MAKE) -f Makefile.autoconf -s
 
 include $(OUTPUT)Makefile.conf
@@ -72,8 +72,6 @@ else
 	$(Q)touch bin/stat
 endif
 
-ASM_UAPI_GENERATED:=$(OUTPUT)../../arch/lkl/include/generated/uapi/asm
-ASM_CONFIG:=$(ASM_UAPI_GENERATED)/config.h
 DOT_CONFIG:=$(OUTPUT)../../.config
 
 $(DOT_CONFIG): $(OUTPUT)/kernel.config
@@ -82,13 +80,8 @@ $(DOT_CONFIG): $(OUTPUT)/kernel.config
 	$(Q)$(MAKE) -C ../.. ARCH=lkl $(KOPT) olddefconfig
 	$(Q)$(MAKE) -C ../.. ARCH=lkl $(KOPT) syncconfig
 
-
-$(ASM_CONFIG): $(OUTPUT)include/kernel_config.h
-	$(Q)mkdir -p $$(dirname $@)
-	$(call QUIET_INSTALL, kernel_config.h)cp $<  $@
-
 # rule to build lkl.o
-$(OUTPUT)lib/lkl.o: bin/stat $(ASM_CONFIG) $(DOT_CONFIG)
+$(OUTPUT)lib/lkl.o: bin/stat $(DOT_CONFIG)
 # this workaround is for arm32 linker (ld.gold)
 	$(Q)export PATH=$(srctree)/tools/lkl/bin/:${PATH} ;\
 	$(MAKE) -C ../.. ARCH=lkl $(KOPT)
@@ -126,7 +119,6 @@ clean:
 
 clean-conf: clean
 	$(call QUIET_CLEAN, Makefile.conf)$(RM) $(OUTPUT)/Makefile.conf
-	$(call QUIET_CLEAN, kernel_config.h)$(RM) $(OUTPUT)/include/kernel_config.h
 	$(call QUIET_CLEAN, kernel.config)$(RM) $(OUTPUT)/kernel.config
 
 headers_install: $(TARGETS)
diff --git a/tools/lkl/Makefile.autoconf b/tools/lkl/Makefile.autoconf
index 3e443241d024..90a55a52eb70 100644
--- a/tools/lkl/Makefile.autoconf
+++ b/tools/lkl/Makefile.autoconf
@@ -9,11 +9,6 @@ define set_autoconf_var
   export LKL_HOST_CONFIG_$(1)=$(2)
 endef
 
-define set_kernel_config_h
-$(shell echo "#define $(1) $(2)" \
-	  >> $(OUTPUT)/include/kernel_config.h)
-endef
-
 define set_kernel_config
 $(shell echo "CONFIG_$(1)=$(2)" >> $(OUTPUT)/kernel.config)
 endef
@@ -119,12 +114,10 @@ define nt_host
 endef
 
 define s390_host
-  $(call set_kernel_config_h,LKL_CONFIG_CPU_BIG_ENDIAN,1)
   $(call set_kernel_config,CPU_BIG_ENDIAN,y)
 endef
 
 define 64bit_host
-  $(call set_kernel_config_h,LKL_CONFIG_64BIT,1)
   $(call set_kernel_config,64BIT,y)
 endef
 
@@ -209,7 +202,6 @@ $(OUTPUT)Makefile.conf: Makefile.autoconf
 	$(shell mkdir -p $(OUTPUT)/include)
 	$(shell mkdir -p $(OUTPUT)/tests)
 	$(shell echo -n "" > $(OUTPUT)/include/lkl_autoconf.h)
-	$(shell echo -n "" > $(OUTPUT)/include/kernel_config.h)
 	$(shell echo -n "" > $(OUTPUT)/kernel.config)
 	$(shell echo -n "" > $(OUTPUT)/tests/autoconf.sh)
 	@echo "$$do_autoconf" > $(OUTPUT)/Makefile.conf
-- 
2.43.0

openSUSE Build Service is sponsored by