Makefile.headersinst 4.1 KB
Newer Older
1 2 3
# ==========================================================================
# Installing headers
#
4 5
# header-y  - list files to be installed. They are preprocessed
#             to remove __KERNEL__ section of the file
6
# genhdr-y  - Same as header-y but in a generated/ directory
7 8 9
#
# ==========================================================================

10
# called may set destination dir (when installing to asm/)
11
_dst := $(or $(destination-y),$(dst),$(obj))
12

13 14 15
# generated header directory
gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj)))

16 17
kbuild-file := $(srctree)/$(obj)/Kbuild
include $(kbuild-file)
18

19 20 21 22
old-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild
ifneq ($(wildcard $(old-kbuild-file)),)
include $(old-kbuild-file)
endif
23

24
include scripts/Kbuild.include
25

26
installdir    := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst))
27

S
Sam Ravnborg 已提交
28
header-y      := $(sort $(header-y))
29 30
subdirs       := $(patsubst %/,%,$(filter %/, $(header-y)))
header-y      := $(filter-out %/, $(header-y))
31

32
# files used to track state of install/check
33 34
install-file  := $(installdir)/.install
check-file    := $(installdir)/.check
35

S
Sam Ravnborg 已提交
36 37 38 39
# generic-y list all files an architecture uses from asm-generic
# Use this to build a list of headers which require a wrapper
wrapper-files := $(filter $(header-y), $(generic-y))

40 41 42 43 44
srcdir        := $(srctree)/$(obj)
gendir        := $(objtree)/$(gen)

oldsrcdir     := $(srctree)/$(subst /uapi,,$(obj))

45
# all headers files for this dir
S
Sam Ravnborg 已提交
46
header-y      := $(filter-out $(generic-y), $(header-y))
47
all-files     := $(header-y) $(genhdr-y) $(wrapper-files)
48 49 50 51 52 53 54 55 56 57 58 59 60
output-files  := $(addprefix $(installdir)/, $(all-files))

input-files   := $(foreach hdr, $(header-y), \
		   $(or \
			$(wildcard $(srcdir)/$(hdr)), \
			$(wildcard $(oldsrcdir)/$(hdr)), \
			$(error Missing UAPI file $(srcdir)/$(hdr)) \
		   )) \
		 $(foreach hdr, $(genhdr-y), \
		   $(or \
			$(wildcard $(gendir)/$(hdr)), \
			$(error Missing generated UAPI file $(gendir)/$(hdr)) \
		   ))
61

62
# Work out what needs to be removed
63
oldheaders    := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
64
unwanted      := $(filter-out $(all-files),$(oldheaders))
65

66
# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
67
unwanted-file := $(addprefix $(installdir)/, $(unwanted))
68

69
printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
70

71 72
quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
                            file$(if $(word 2, $(all-files)),s))
73
      cmd_install = \
74
        $(PERL) $< $(installdir) $(SRCARCH) $(input-files); \
S
Sam Ravnborg 已提交
75
        for F in $(wrapper-files); do                                   \
76
                echo "\#include <asm-generic/$$F>" > $(installdir)/$$F;    \
S
Sam Ravnborg 已提交
77
        done;                                                           \
78
        touch $@
79

80 81
quiet_cmd_remove = REMOVE  $(unwanted)
      cmd_remove = rm -f $(unwanted-file)
82

83
quiet_cmd_check = CHECK   $(printdir) ($(words $(all-files)) files)
84 85 86
# Headers list can be pretty long, xargs helps to avoid
# the "Argument list too long" error.
      cmd_check = for f in $(all-files); do                          \
87
                  echo "$(installdir)/$${f}"; done                      \
88 89
                  | xargs                                            \
                  $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
90
	          touch $@
91

92
PHONY += __headersinst __headerscheck
93

94 95 96 97
ifndef HDRCHECK
# Rules for installing headers
__headersinst: $(subdirs) $(install-file)
	@:
98

99 100 101 102 103
targets += $(install-file)
$(install-file): scripts/headers_install.pl $(input-files) FORCE
	$(if $(unwanted),$(call cmd,remove),)
	$(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
	$(call if_changed,install)
104

105
else
106 107
__headerscheck: $(subdirs) $(check-file)
	@:
108

109 110 111
targets += $(check-file)
$(check-file): scripts/headers_check.pl $(output-files) FORCE
	$(call if_changed,check)
112

113
endif
114

115 116 117 118 119
# Recursion
hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
.PHONY: $(subdirs)
$(subdirs):
	$(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
120

121 122 123
targets := $(wildcard $(sort $(targets)))
cmd_files := $(wildcard \
             $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
124

125 126
ifneq ($(cmd_files),)
	include $(cmd_files)
127 128
endif

129 130 131
.PHONY: $(PHONY)
PHONY += FORCE
FORCE: ;