kbuild: asm symlink support for arch/$ARCH/include

Adjust the asm symlink support so we do not create the
symlink unless really needed.
We check the precense of include/asm-$ARCH by checking
for the system.h file. We may end up with a stale directory
so it is not enough to check if the directory is present.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>

+29 -16
+1 -2
Kbuild
··· 43 # 2) Generate asm-offsets.h 44 # 45 46 - offsets-file := include/asm-$(SRCARCH)/asm-offsets.h 47 48 always += $(offsets-file) 49 targets += $(offsets-file) ··· 81 $(call if_changed_dep,cc_s_c) 82 83 $(obj)/$(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s Kbuild 84 - $(Q)mkdir -p $(dir $@) 85 $(call cmd,offsets) 86 87 #####
··· 43 # 2) Generate asm-offsets.h 44 # 45 46 + offsets-file := include/asm/asm-offsets.h 47 48 always += $(offsets-file) 49 targets += $(offsets-file) ··· 81 $(call if_changed_dep,cc_s_c) 82 83 $(obj)/$(offsets-file): arch/$(SRCARCH)/kernel/asm-offsets.s Kbuild 84 $(call cmd,offsets) 85 86 #####
+28 -14
Makefile
··· 925 /bin/false; \ 926 fi; 927 $(Q)if [ ! -d include2 ]; then mkdir -p include2; fi; 928 - $(Q)ln -fsn $(srctree)/include/asm-$(SRCARCH) include2/asm 929 endif 930 931 # prepare2 creates a makefile if using a separate output directory ··· 953 954 # The asm symlink changes when $(ARCH) changes. 955 # Detect this and ask user to run make mrproper 956 - 957 - include/asm: FORCE 958 - $(Q)set -e; asmlink=`readlink include/asm | cut -d '-' -f 2`; \ 959 - if [ -L include/asm ]; then \ 960 - if [ "$$asmlink" != "$(SRCARCH)" ]; then \ 961 echo "ERROR: the symlink $@ points to asm-$$asmlink but asm-$(SRCARCH) was expected"; \ 962 echo " set ARCH or save .config and run 'make mrproper' to fix it"; \ 963 - exit 1; \ 964 - fi; \ 965 - else \ 966 - echo ' SYMLINK $@ -> include/asm-$(SRCARCH)'; \ 967 - if [ ! -d include ]; then \ 968 - mkdir -p include; \ 969 - fi; \ 970 - ln -fsn asm-$(SRCARCH) $@; \ 971 fi 972 973 # Generate some files 974 # ---------------------------------------------------------------------------
··· 925 /bin/false; \ 926 fi; 927 $(Q)if [ ! -d include2 ]; then mkdir -p include2; fi; 928 + $(Q)if [ -e $(srctree)/include/asm-$(SRCARCH)/system.h ]; then \ 929 + ln -fsn $(srctree)/include/asm-$(SRCARCH) include2/asm; \ 930 + fi 931 endif 932 933 # prepare2 creates a makefile if using a separate output directory ··· 951 952 # The asm symlink changes when $(ARCH) changes. 953 # Detect this and ask user to run make mrproper 954 + define check-symlink 955 + set -e; \ 956 + if [ -L include/asm ]; then \ 957 + asmlink=`readlink include/asm | cut -d '-' -f 2`; \ 958 + if [ "$$asmlink" != "$(SRCARCH)" ]; then \ 959 echo "ERROR: the symlink $@ points to asm-$$asmlink but asm-$(SRCARCH) was expected"; \ 960 echo " set ARCH or save .config and run 'make mrproper' to fix it"; \ 961 + exit 1; \ 962 + fi; \ 963 fi 964 + endef 965 + 966 + # We create the target directory of the symlink if it does 967 + # not exist so the test in chack-symlink works and we have a 968 + # directory for generated filesas used by some architectures. 969 + define create-symlink 970 + if [ ! -L include/asm ]; then \ 971 + echo ' SYMLINK $@ -> include/asm-$(SRCARCH)'; \ 972 + if [ ! -d include/asm-$(SRCARCH) ]; then \ 973 + mkdir -p include/asm-$(SRCARCH); \ 974 + fi; \ 975 + ln -fsn asm-$(SRCARCH) $@; \ 976 + fi 977 + endef 978 + 979 + include/asm: FORCE 980 + $(Q)$(check-symlink) 981 + $(Q)$(create-symlink) 982 983 # Generate some files 984 # ---------------------------------------------------------------------------