Makefile.headersinst 4.4 KB
Newer Older
1 2 3
# ==========================================================================
# Installing headers
#
4 5 6 7
# All headers under include/uapi, include/generated/uapi,
# arch/<arch>/include/uapi/asm and arch/<arch>/include/generated/uapi/asm are
# exported.
# They are preprocessed to remove __KERNEL__ section of the file.
8 9 10
#
# ==========================================================================

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

14
# Kbuild file is optional
15
kbuild-file := $(srctree)/$(obj)/Kbuild
16
-include $(kbuild-file)
17

18
# called may set destination dir (when installing to asm/)
19
_dst := $(if $(dst),$(dst),$(obj))
20

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

26
include scripts/Kbuild.include
27

28
installdir    := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst))
29

30 31 32 33 34 35 36 37 38
srcdir        := $(srctree)/$(obj)
gendir        := $(objtree)/$(gen)
subdirs       := $(patsubst $(srcdir)/%/.,%,$(wildcard $(srcdir)/*/.))
subdirs       += $(subdir-y)
header-files  := $(notdir $(wildcard $(srcdir)/*.h))
header-files  += $(notdir $(wildcard $(srcdir)/*.agh))
header-files  := $(filter-out $(no-export-headers), $(header-files))
genhdr-files  := $(notdir $(wildcard $(gendir)/*.h))
genhdr-files  := $(filter-out $(header-files), $(genhdr-files))
39

40
# files used to track state of install/check
41 42
install-file  := $(installdir)/.install
check-file    := $(installdir)/.check
43

S
Sam Ravnborg 已提交
44 45
# generic-y list all files an architecture uses from asm-generic
# Use this to build a list of headers which require a wrapper
46 47 48
generic-files := $(notdir $(wildcard $(srctree)/include/uapi/asm-generic/*.h))
wrapper-files := $(filter $(generic-files), $(generic-y))
wrapper-files := $(filter-out $(header-files), $(wrapper-files))
49

50
# all headers files for this dir
51
all-files     := $(header-files) $(genhdr-files) $(wrapper-files)
52 53
output-files  := $(addprefix $(installdir)/, $(all-files))

54 55 56 57 58 59
ifneq ($(mandatory-y),)
missing       := $(filter-out $(all-files),$(mandatory-y))
ifneq ($(missing),)
$(error Some mandatory headers ($(missing)) are missing in $(obj))
endif
endif
60

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

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

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

70 71
quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
                            file$(if $(word 2, $(all-files)),s))
72
      cmd_install = \
73 74
        $(CONFIG_SHELL) $< $(installdir) $(srcdir) $(header-files); \
        $(CONFIG_SHELL) $< $(installdir) $(gendir) $(genhdr-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
targets += $(install-file)
100
$(install-file): scripts/headers_install.sh \
101 102
		 $(addprefix $(srcdir)/,$(header-files)) \
		 $(addprefix $(gendir)/,$(genhdr-files)) FORCE
103 104 105
	$(if $(unwanted),$(call cmd,remove),)
	$(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
	$(call if_changed,install)
106

107
else
108 109
__headerscheck: $(subdirs) $(check-file)
	@:
110

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

115
endif
116

117 118 119 120
# Recursion
.PHONY: $(subdirs)
$(subdirs):
	$(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
121

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

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

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