Merge tag 'amd-drm-next-5.14-2021-05-19' of https://gitlab.freedesktop.org/agd5f...
[platform/kernel/linux-starfive.git] / scripts / Makefile.asm-generic
1 # SPDX-License-Identifier: GPL-2.0
2 # include/asm-generic contains a lot of files that are used
3 # verbatim by several architectures.
4 #
5 # This Makefile reads the file arch/$(SRCARCH)/include/(uapi/)/asm/Kbuild
6 # and for each file listed in this file with generic-y creates
7 # a small wrapper file in arch/$(SRCARCH)/include/generated/(uapi/)/asm.
8
9 PHONY := all
10 all:
11
12 src := $(subst /generated,,$(obj))
13 -include $(src)/Kbuild
14
15 # $(generic)/Kbuild lists mandatory-y. Exclude um since it is a special case.
16 ifneq ($(SRCARCH),um)
17 include $(srctree)/$(generic)/Kbuild
18 endif
19
20 include $(srctree)/scripts/Kbuild.include
21
22 redundant := $(filter $(mandatory-y) $(generated-y), $(generic-y))
23 redundant += $(foreach f, $(generic-y), $(if $(wildcard $(srctree)/$(src)/$(f)),$(f)))
24 redundant := $(sort $(redundant))
25 $(if $(redundant),\
26         $(warning redundant generic-y found in $(src)/Kbuild: $(redundant)))
27
28 # If arch does not implement mandatory headers, fallback to asm-generic ones.
29 mandatory-y := $(filter-out $(generated-y), $(mandatory-y))
30 generic-y   += $(foreach f, $(mandatory-y), $(if $(wildcard $(srctree)/$(src)/$(f)),,$(f)))
31
32 generic-y   := $(addprefix $(obj)/, $(generic-y))
33 generated-y := $(addprefix $(obj)/, $(generated-y))
34
35 # Remove stale wrappers when the corresponding files are removed from generic-y
36 old-headers := $(wildcard $(obj)/*.h)
37 unwanted    := $(filter-out $(generic-y) $(generated-y),$(old-headers))
38
39 quiet_cmd_wrap = WRAP    $@
40       cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
41
42 quiet_cmd_remove = REMOVE  $(unwanted)
43       cmd_remove = rm -f $(unwanted)
44
45 all: $(generic-y)
46         $(if $(unwanted),$(call cmd,remove))
47         @:
48
49 $(obj)/%.h:
50         $(call cmd,wrap)
51
52 # Create output directory. Skip it if at least one old header exists
53 # since we know the output directory already exists.
54 ifeq ($(old-headers),)
55 $(shell mkdir -p $(obj))
56 endif
57
58 .PHONY: $(PHONY)