[RFT] kbuild: check asm symlink when building a kernel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We often hit the situation where the asm symlink
in include/ points to the wrong architecture.
In 9 out of 10 cases thats because we forgot to set
ARCH but sometimes we just reused the same tree
for another ARCH. For the merged x86 tree we need
to create a new symlink but this is not obvious.
So with the following patch we check if the symlink
points to the correct architecture and error
out if this is not the case.

For x86 a "rm include/asm" is enough but we
recommend make mrproper for the general case.

The patch survives my testing but before pushing
it to -mm or -linus I would like a few more to
test it in their environment.
I am a bit unsafe with the use of readlink and cut since
they are not widely used by the kernel
build today.

Any feedback good/bad appreciated!

PS - I know that the lines are too long in the patch but
     breaking them would hurt readability.

	Sam

diff --git a/Makefile b/Makefile
index ed65de7..136d7c2 100644
--- a/Makefile
+++ b/Makefile
@@ -903,14 +903,24 @@ prepare: prepare0
 
 export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH)
 
-# FIXME: The asm symlink changes when $(ARCH) changes. That's
-# hard to detect, but I suppose "make mrproper" is a good idea
-# before switching between archs anyway.
-
-include/asm:
-	@echo '  SYMLINK $@ -> include/asm-$(SRCARCH)'
-	$(Q)if [ ! -d include ]; then mkdir -p include; fi;
-	@ln -fsn asm-$(SRCARCH) $@
+# The asm symlink changes when $(ARCH) changes.
+# Detect this and ask user to run make mrproper
+
+include/asm: FORCE
+	$(Q)set -e; asmlink=`readlink include/asm | cut -d '-' -f 2`;   \
+	if [ -L include/asm ]; then                                     \
+		if [ "$$asmlink" != "$(SRCARCH)" ]; then                \
+			echo "ERROR: the symlink $@ points to asm-$$asmlink but asm-$(SRCARCH) was expected"; \
+			echo "       save .config and run 'make mrproper' to fix it";                         \
+			exit 1;                                         \
+		fi;                                                     \
+	else                                                            \
+		echo '  SYMLINK $@ -> include/asm-$(SRCARCH)';          \
+		if [ ! -d include ]; then                               \
+			mkdir -p include;                               \
+		fi;                                                     \
+		ln -fsn asm-$(SRCARCH) $@;                              \
+	fi
 
 # Generate some files
 # ---------------------------------------------------------------------------
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux