Makefile.headersinst 4.7 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 11 12
# generated header directory
gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj)))

13 14
kbuild-file := $(srctree)/$(obj)/Kbuild
include $(kbuild-file)
15

16
# called may set destination dir (when installing to asm/)
17
_dst := $(if $(destination-y),$(destination-y),$(if $(dst),$(dst),$(obj)))
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
output-files  := $(addprefix $(installdir)/, $(all-files))

50
input-files1  := $(foreach hdr, $(header-y), \
51
		   $(if $(wildcard $(srcdir)/$(hdr)), \
52 53 54 55 56
			$(wildcard $(srcdir)/$(hdr))) \
		   )
input-files1-name := $(notdir $(input-files1))
input-files2  := $(foreach hdr, $(header-y), \
		   $(if  $(wildcard $(srcdir)/$(hdr)),, \
57 58 59
			$(if $(wildcard $(oldsrcdir)/$(hdr)), \
				$(wildcard $(oldsrcdir)/$(hdr)), \
				$(error Missing UAPI file $(srcdir)/$(hdr))) \
60 61 62
		   ))
input-files2-name := $(notdir $(input-files2))
input-files3  := $(foreach hdr, $(genhdr-y), \
63
		   $(if	$(wildcard $(gendir)/$(hdr)), \
64 65 66
			$(wildcard $(gendir)/$(hdr)), \
			$(error Missing generated UAPI file $(gendir)/$(hdr)) \
		   ))
67
input-files3-name := $(notdir $(input-files3))
68

69
# Work out what needs to be removed
70
oldheaders    := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
71
unwanted      := $(filter-out $(all-files),$(oldheaders))
72

73
# Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
74
unwanted-file := $(addprefix $(installdir)/, $(unwanted))
75

76
printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
77

78 79
quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
                            file$(if $(word 2, $(all-files)),s))
80
      cmd_install = \
81 82 83
        $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(input-files1-name); \
        $(CONFIG_SHELL) $< $(installdir) $(oldsrcdir) $(input-files2-name); \
        $(CONFIG_SHELL) $< $(installdir) $(gendir) $(input-files3-name); \
S
Sam Ravnborg 已提交
84
        for F in $(wrapper-files); do                                   \
85
                echo "\#include <asm-generic/$$F>" > $(installdir)/$$F;    \
S
Sam Ravnborg 已提交
86
        done;                                                           \
87
        touch $@
88

89 90
quiet_cmd_remove = REMOVE  $(unwanted)
      cmd_remove = rm -f $(unwanted-file)
91

92
quiet_cmd_check = CHECK   $(printdir) ($(words $(all-files)) files)
93 94 95
# Headers list can be pretty long, xargs helps to avoid
# the "Argument list too long" error.
      cmd_check = for f in $(all-files); do                          \
96
                  echo "$(installdir)/$${f}"; done                      \
97 98
                  | xargs                                            \
                  $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
99
	          touch $@
100

101
PHONY += __headersinst __headerscheck
102

103 104 105 106
ifndef HDRCHECK
# Rules for installing headers
__headersinst: $(subdirs) $(install-file)
	@:
107

108
targets += $(install-file)
109
$(install-file): scripts/headers_install.sh $(input-files1) $(input-files2) $(input-files3) FORCE
110 111 112
	$(if $(unwanted),$(call cmd,remove),)
	$(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
	$(call if_changed,install)
113

114
else
115 116
__headerscheck: $(subdirs) $(check-file)
	@:
117

118 119 120
targets += $(check-file)
$(check-file): scripts/headers_check.pl $(output-files) FORCE
	$(call if_changed,check)
121

122
endif
123

124 125 126 127
# Recursion
.PHONY: $(subdirs)
$(subdirs):
	$(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
128

129 130 131
targets := $(wildcard $(sort $(targets)))
cmd_files := $(wildcard \
             $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
132

133 134
ifneq ($(cmd_files),)
	include $(cmd_files)
135 136
endif

137 138 139
.PHONY: $(PHONY)
PHONY += FORCE
FORCE: ;