linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] kbuild: add phony targets to ./Kbuild
@ 2022-08-20  9:15 Masahiro Yamada
  2022-08-20  9:15 ` [PATCH 2/4] kbuild: check sha1sum just once for each atomic header Masahiro Yamada
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Masahiro Yamada @ 2022-08-20  9:15 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Masahiro Yamada, Michal Marek, Nick Desaulniers, linux-kernel

missing-syscalls and old-atomics are meant to be phony targets.
Adding them to always-y is odd. (always-y should generate something).

Add a new phony target 'prepare', which depends on all the other.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 Kbuild   | 26 +++++++++++++-------------
 Makefile |  2 +-
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/Kbuild b/Kbuild
index fa441b98c9f6..e122d93cee32 100644
--- a/Kbuild
+++ b/Kbuild
@@ -2,18 +2,18 @@
 #
 # Kbuild for top-level directory of the kernel
 
-#####
+# Prepare global headers and check sanity before descending into sub-directories
+# ---------------------------------------------------------------------------
+
 # Generate bounds.h
 
 bounds-file := include/generated/bounds.h
 
-always-y := $(bounds-file)
 targets := kernel/bounds.s
 
 $(bounds-file): kernel/bounds.s FORCE
 	$(call filechk,offsets,__LINUX_BOUNDS_H__)
 
-#####
 # Generate timeconst.h
 
 timeconst-file := include/generated/timeconst.h
@@ -23,12 +23,10 @@ filechk_gentimeconst = echo $(CONFIG_HZ) | bc -q $<
 $(timeconst-file): kernel/time/timeconst.bc FORCE
 	$(call filechk,gentimeconst)
 
-#####
 # Generate asm-offsets.h
 
 offsets-file := include/generated/asm-offsets.h
 
-always-y += $(offsets-file)
 targets += arch/$(SRCARCH)/kernel/asm-offsets.s
 
 arch/$(SRCARCH)/kernel/asm-offsets.s: $(timeconst-file) $(bounds-file)
@@ -36,24 +34,26 @@ arch/$(SRCARCH)/kernel/asm-offsets.s: $(timeconst-file) $(bounds-file)
 $(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s FORCE
 	$(call filechk,offsets,__ASM_OFFSETS_H__)
 
-#####
 # Check for missing system calls
 
-always-y += missing-syscalls
-
 quiet_cmd_syscalls = CALL    $<
       cmd_syscalls = $(CONFIG_SHELL) $< $(CC) $(c_flags) $(missing_syscalls_flags)
 
-missing-syscalls: scripts/checksyscalls.sh $(offsets-file) FORCE
+PHONY += missing-syscalls
+missing-syscalls: scripts/checksyscalls.sh $(offsets-file)
 	$(call cmd,syscalls)
 
-#####
 # Check atomic headers are up-to-date
 
-always-y += old-atomics
-
 quiet_cmd_atomics = CALL    $<
       cmd_atomics = $(CONFIG_SHELL) $<
 
-old-atomics: scripts/atomic/check-atomics.sh FORCE
+PHONY += old-atomics
+old-atomics: scripts/atomic/check-atomics.sh
 	$(call cmd,atomics)
+
+# A phony target that depends on all the preparation targets
+
+PHONY += prepare
+prepare: $(offsets-file) missing-syscalls old-atomics
+	@:
diff --git a/Makefile b/Makefile
index 697ab397fe31..4fcced0d3907 100644
--- a/Makefile
+++ b/Makefile
@@ -1202,7 +1202,7 @@ archprepare: outputmakefile archheaders archscripts scripts include/config/kerne
 
 prepare0: archprepare
 	$(Q)$(MAKE) $(build)=scripts/mod
-	$(Q)$(MAKE) $(build)=.
+	$(Q)$(MAKE) $(build)=. prepare
 
 # All the preparing..
 prepare: prepare0
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/4] kbuild: check sha1sum just once for each atomic header
  2022-08-20  9:15 [PATCH 1/4] kbuild: add phony targets to ./Kbuild Masahiro Yamada
@ 2022-08-20  9:15 ` Masahiro Yamada
  2022-08-20  9:15 ` [PATCH 3/4] kbuild: do not deduplicate modules.order Masahiro Yamada
  2022-08-20  9:15 ` [PATCH 4/4] nios2: move core-y in arch/nios2/Makefile to arch/nios2/Kbuild Masahiro Yamada
  2 siblings, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2022-08-20  9:15 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Masahiro Yamada, Boqun Feng, Mark Rutland, Michal Marek,
	Nick Desaulniers, Peter Zijlstra, Will Deacon, linux-kernel

It is unneeded to check the sha1sum every time.

Create the timestamp files to manage it.

Add '.' to vmlinux-alldirs because 'make clean' must visit ./Kbuild
to clean up the timestamp files.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 Kbuild                          | 33 ++++++++++++++++++++++++---------
 Makefile                        |  2 +-
 scripts/atomic/check-atomics.sh | 33 ---------------------------------
 3 files changed, 25 insertions(+), 43 deletions(-)
 delete mode 100755 scripts/atomic/check-atomics.sh

diff --git a/Kbuild b/Kbuild
index e122d93cee32..0b9e8a16a621 100644
--- a/Kbuild
+++ b/Kbuild
@@ -43,17 +43,32 @@ PHONY += missing-syscalls
 missing-syscalls: scripts/checksyscalls.sh $(offsets-file)
 	$(call cmd,syscalls)
 
-# Check atomic headers are up-to-date
-
-quiet_cmd_atomics = CALL    $<
-      cmd_atomics = $(CONFIG_SHELL) $<
-
-PHONY += old-atomics
-old-atomics: scripts/atomic/check-atomics.sh
-	$(call cmd,atomics)
+# Check the manual modification of atomic headers
+
+quiet_cmd_check_sha1 = CHKSHA1 $<
+      cmd_check_sha1 = \
+	if ! command -v sha1sum >/dev/null; then \
+		echo "warning: cannot check the header due to sha1sum missing"; \
+		exit 0; \
+	fi; \
+	if [ "$$(sed -n '$$s:// ::p' $<)" != \
+	     "$$(sed '$$d' $< | sha1sum | sed 's/ .*//')" ]; then \
+		echo "error: $< has been modified." >&2; \
+		exit 1; \
+	fi; \
+	touch $@
+
+atomic-checks += $(addprefix $(obj)/.checked-, \
+	  atomic-arch-fallback.h \
+	  atomic-instrumented.h \
+	  atomic-long.h)
+
+targets += $(atomic-checks)
+$(atomic-checks): $(obj)/.checked-%: include/linux/atomic/%  FORCE
+	$(call if_changed,check_sha1)
 
 # A phony target that depends on all the preparation targets
 
 PHONY += prepare
-prepare: $(offsets-file) missing-syscalls old-atomics
+prepare: $(offsets-file) missing-syscalls $(atomic-checks)
 	@:
diff --git a/Makefile b/Makefile
index 4fcced0d3907..d8ca0738b9e1 100644
--- a/Makefile
+++ b/Makefile
@@ -1109,7 +1109,7 @@ vmlinux-dirs	:= $(patsubst %/,%,$(filter %/, \
 		     $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
 		     $(libs-y) $(libs-m)))
 
-vmlinux-alldirs	:= $(sort $(vmlinux-dirs) Documentation \
+vmlinux-alldirs	:= $(sort $(vmlinux-dirs) Documentation . \
 		     $(patsubst %/,%,$(filter %/, $(core-) \
 			$(drivers-) $(libs-))))
 
diff --git a/scripts/atomic/check-atomics.sh b/scripts/atomic/check-atomics.sh
deleted file mode 100755
index 0e7bab3eb0d1..000000000000
--- a/scripts/atomic/check-atomics.sh
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0
-#
-# Check if atomic headers are up-to-date
-
-ATOMICDIR=$(dirname $0)
-ATOMICTBL=${ATOMICDIR}/atomics.tbl
-LINUXDIR=${ATOMICDIR}/../..
-
-echo '' | sha1sum - > /dev/null 2>&1
-if [ $? -ne 0 ]; then
-	printf "sha1sum not available, skipping atomic header checks.\n"
-	exit 0
-fi
-
-cat <<EOF |
-linux/atomic/atomic-instrumented.h
-linux/atomic/atomic-long.h
-linux/atomic/atomic-arch-fallback.h
-EOF
-while read header; do
-	OLDSUM="$(tail -n 1 ${LINUXDIR}/include/${header})"
-	OLDSUM="${OLDSUM#// }"
-
-	NEWSUM="$(sed '$d' ${LINUXDIR}/include/${header} | sha1sum)"
-	NEWSUM="${NEWSUM%% *}"
-
-	if [ "${OLDSUM}" != "${NEWSUM}" ]; then
-		printf "warning: generated include/${header} has been modified.\n"
-	fi
-done
-
-exit 0
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/4] kbuild: do not deduplicate modules.order
  2022-08-20  9:15 [PATCH 1/4] kbuild: add phony targets to ./Kbuild Masahiro Yamada
  2022-08-20  9:15 ` [PATCH 2/4] kbuild: check sha1sum just once for each atomic header Masahiro Yamada
@ 2022-08-20  9:15 ` Masahiro Yamada
  2022-08-20  9:15 ` [PATCH 4/4] nios2: move core-y in arch/nios2/Makefile to arch/nios2/Kbuild Masahiro Yamada
  2 siblings, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2022-08-20  9:15 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Masahiro Yamada, Michal Marek, Nick Desaulniers, linux-kernel

The AWK code was added to deduplicate modules.order in case $(obj-m)
contains the same module multiple times, but it is actually unneeded
since commit b2c885549122 ("kbuild: update modules.order only when
contained modules are updated").

The list is already deduplicated before being processed by AWK because
$^ is the deduplicated list of prerequisites.
(Please note the real-prereqs macro uses $^)

Yet, modules.order will contain duplication if two different Makefiles
build the same module:

  foo/Makefile:

      obj-m += bar/baz.o

  foo/bar/Makefile:

      obj-m += baz.o

However, the parallel builds cannot properly handle this case in the
first place. So, it is better to let it fail (as already done by
scripts/modules-check.sh).

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 Makefile               | 5 +----
 scripts/Makefile.build | 2 +-
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index d8ca0738b9e1..8add796953ad 100644
--- a/Makefile
+++ b/Makefile
@@ -1435,14 +1435,11 @@ endif
 
 # Build modules
 #
-# A module can be listed more than once in obj-m resulting in
-# duplicate lines in modules.order files.  Those are removed
-# using awk while concatenating to the final file.
 
 PHONY += modules
 modules: $(if $(KBUILD_BUILTIN),vmlinux) modules_check modules_prepare
 
-cmd_modules_order = $(AWK) '!x[$$0]++' $(real-prereqs) > $@
+cmd_modules_order = cat $(real-prereqs) > $@
 
 modules.order: $(subdir-modorder) FORCE
 	$(call if_changed,modules_order)
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 784f46d41959..0df488d0bbb0 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -374,7 +374,7 @@ $(obj)/built-in.a: $(real-obj-y) FORCE
 
 cmd_modules_order = { $(foreach m, $(real-prereqs), \
 	$(if $(filter %/modules.order, $m), cat $m, echo $(patsubst %.o,%.ko,$m));) :; } \
-	| $(AWK) '!x[$$0]++' - > $@
+	> $@
 
 $(obj)/modules.order: $(obj-m) FORCE
 	$(call if_changed,modules_order)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 4/4] nios2: move core-y in arch/nios2/Makefile to arch/nios2/Kbuild
  2022-08-20  9:15 [PATCH 1/4] kbuild: add phony targets to ./Kbuild Masahiro Yamada
  2022-08-20  9:15 ` [PATCH 2/4] kbuild: check sha1sum just once for each atomic header Masahiro Yamada
  2022-08-20  9:15 ` [PATCH 3/4] kbuild: do not deduplicate modules.order Masahiro Yamada
@ 2022-08-20  9:15 ` Masahiro Yamada
  2 siblings, 0 replies; 4+ messages in thread
From: Masahiro Yamada @ 2022-08-20  9:15 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Masahiro Yamada, Dinh Nguyen, linux-kernel

Use obj-y to clean up Makefile.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 arch/nios2/Kbuild   | 2 ++
 arch/nios2/Makefile | 4 ----
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/arch/nios2/Kbuild b/arch/nios2/Kbuild
index 4e39f7abdeb6..fc2952edd2de 100644
--- a/arch/nios2/Kbuild
+++ b/arch/nios2/Kbuild
@@ -1,4 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 
+obj-y += kernel/ mm/ platform/ boot/dts/
+
 # for cleaning
 subdir- += boot
diff --git a/arch/nios2/Makefile b/arch/nios2/Makefile
index d6a7499b814c..3f34e6831863 100644
--- a/arch/nios2/Makefile
+++ b/arch/nios2/Makefile
@@ -39,8 +39,6 @@ KBUILD_CFLAGS += -G 0
 
 head-y		:= arch/nios2/kernel/head.o
 libs-y		+= arch/nios2/lib/ $(LIBGCC)
-core-y		+= arch/nios2/kernel/ arch/nios2/mm/
-core-y		+= arch/nios2/platform/
 
 INSTALL_PATH ?= /tftpboot
 nios2-boot := arch/$(ARCH)/boot
@@ -48,8 +46,6 @@ BOOT_TARGETS = vmImage zImage
 PHONY += $(BOOT_TARGETS) install
 KBUILD_IMAGE := $(nios2-boot)/vmImage
 
-core-y	+= $(nios2-boot)/dts/
-
 all: vmImage
 
 $(BOOT_TARGETS): vmlinux
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-08-20  9:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-20  9:15 [PATCH 1/4] kbuild: add phony targets to ./Kbuild Masahiro Yamada
2022-08-20  9:15 ` [PATCH 2/4] kbuild: check sha1sum just once for each atomic header Masahiro Yamada
2022-08-20  9:15 ` [PATCH 3/4] kbuild: do not deduplicate modules.order Masahiro Yamada
2022-08-20  9:15 ` [PATCH 4/4] nios2: move core-y in arch/nios2/Makefile to arch/nios2/Kbuild Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).