xref: /openbmc/linux/scripts/Makefile.asm-generic (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
2d8ecc5cdSSam Ravnborg# include/asm-generic contains a lot of files that are used
3d8ecc5cdSSam Ravnborg# verbatim by several architectures.
4d8ecc5cdSSam Ravnborg#
57d0e5c20SMasahiro Yamada# This Makefile reads the file arch/$(SRCARCH)/include/(uapi/)/asm/Kbuild
6d8ecc5cdSSam Ravnborg# and for each file listed in this file with generic-y creates
77d0e5c20SMasahiro Yamada# a small wrapper file in arch/$(SRCARCH)/include/generated/(uapi/)/asm.
8d8ecc5cdSSam Ravnborg
9a7d34df3SMasahiro YamadaPHONY := all
10a7d34df3SMasahiro Yamadaall:
11a7d34df3SMasahiro Yamada
127d0e5c20SMasahiro Yamadasrc := $(subst /generated,,$(obj))
13*a2430b25SMasahiro Yamada
14*a2430b25SMasahiro Yamadainclude $(srctree)/scripts/Kbuild.include
15*a2430b25SMasahiro Yamada-include $(kbuild-file)
16d8ecc5cdSSam Ravnborg
17037fc336SMasahiro Yamada# $(generic)/Kbuild lists mandatory-y. Exclude um since it is a special case.
18037fc336SMasahiro Yamadaifneq ($(SRCARCH),um)
193204a7fbSMasahiro Yamadainclude $(srctree)/$(generic)/Kbuild
20037fc336SMasahiro Yamadaendif
21037fc336SMasahiro Yamada
227cbbbb8bSMasahiro Yamadaredundant := $(filter $(mandatory-y) $(generated-y), $(generic-y))
237cbbbb8bSMasahiro Yamadaredundant += $(foreach f, $(generic-y), $(if $(wildcard $(srctree)/$(src)/$(f)),$(f)))
247cbbbb8bSMasahiro Yamadaredundant := $(sort $(redundant))
257cbbbb8bSMasahiro Yamada$(if $(redundant),\
267cbbbb8bSMasahiro Yamada	$(warning redundant generic-y found in $(src)/Kbuild: $(redundant)))
277cbbbb8bSMasahiro Yamada
2891998731SMasahiro Yamada# If arch does not implement mandatory headers, fallback to asm-generic ones.
2991998731SMasahiro Yamadamandatory-y := $(filter-out $(generated-y), $(mandatory-y))
3091998731SMasahiro Yamadageneric-y   += $(foreach f, $(mandatory-y), $(if $(wildcard $(srctree)/$(src)/$(f)),,$(f)))
3191998731SMasahiro Yamada
327d0e5c20SMasahiro Yamadageneric-y   := $(addprefix $(obj)/, $(generic-y))
337d0e5c20SMasahiro Yamadagenerated-y := $(addprefix $(obj)/, $(generated-y))
34d8ecc5cdSSam Ravnborg
357d0e5c20SMasahiro Yamada# Remove stale wrappers when the corresponding files are removed from generic-y
36cda2c65fSJames Hoganold-headers := $(wildcard $(obj)/*.h)
377d0e5c20SMasahiro Yamadaunwanted    := $(filter-out $(generic-y) $(generated-y),$(old-headers))
38cda2c65fSJames Hogan
39d8ecc5cdSSam Ravnborgquiet_cmd_wrap = WRAP    $@
40d8ecc5cdSSam Ravnborg      cmd_wrap = echo "\#include <asm-generic/$*.h>" > $@
41d8ecc5cdSSam Ravnborg
42cda2c65fSJames Hoganquiet_cmd_remove = REMOVE  $(unwanted)
43cda2c65fSJames Hogan      cmd_remove = rm -f $(unwanted)
44cda2c65fSJames Hogan
457d0e5c20SMasahiro Yamadaall: $(generic-y)
467d0e5c20SMasahiro Yamada	$(if $(unwanted),$(call cmd,remove))
47181e9763SPeter Foley	@:
48d8ecc5cdSSam Ravnborg
49d8ecc5cdSSam Ravnborg$(obj)/%.h:
50d8ecc5cdSSam Ravnborg	$(call cmd,wrap)
51cda2c65fSJames Hogan
527d0e5c20SMasahiro Yamada# Create output directory. Skip it if at least one old header exists
537d0e5c20SMasahiro Yamada# since we know the output directory already exists.
547d0e5c20SMasahiro Yamadaifeq ($(old-headers),)
557d0e5c20SMasahiro Yamada$(shell mkdir -p $(obj))
567d0e5c20SMasahiro Yamadaendif
577d0e5c20SMasahiro Yamada
58cda2c65fSJames Hogan.PHONY: $(PHONY)
59