Makefile.headersinst 3.6 KB
Newer Older
1 2 3 4 5 6 7 8 9
# ==========================================================================
# Installing headers
#
# header-y files will be installed verbatim
# unifdef-y are the files where unifdef will be run before installing files
# objhdr-y are generated files that will be installed verbatim
#
# ==========================================================================

S
Sam Ravnborg 已提交
10
UNIFDEF := scripts/unifdef -U__KERNEL__
11 12

# Eliminate the contents of (and inclusions of) compiler.h
13
HDRSED  := sed	-e "s/ inline / __inline__ /g" \
14 15 16 17 18 19 20
		-e "s/[[:space:]]__user[[:space:]]\{1,\}/ /g" \
		-e "s/(__user[[:space:]]\{1,\}/ (/g" \
		-e "s/[[:space:]]__force[[:space:]]\{1,\}/ /g" \
		-e "s/(__force[[:space:]]\{1,\}/ (/g" \
		-e "s/[[:space:]]__iomem[[:space:]]\{1,\}/ /g" \
		-e "s/(__iomem[[:space:]]\{1,\}/ (/g" \
		-e "s/[[:space:]]__attribute_const__[[:space:]]\{1,\}/\ /g" \
21 22 23 24 25
		-e "s/[[:space:]]__attribute_const__$$//" \
		-e "/^\#include <linux\/compiler.h>/d"

_dst := $(if $(dst),$(dst),$(obj))

26 27
kbuild-file := $(srctree)/$(obj)/Kbuild
include $(kbuild-file)
28

29
include scripts/Kbuild.include
30

31 32
install := $(INSTALL_HDR_PATH)/$(_dst)

33
header-y	:= $(sort $(header-y) $(unifdef-y))
34 35 36
subdir-y	:= $(patsubst %/,%,$(filter %/, $(header-y)))
header-y	:= $(filter-out %/, $(header-y))

37
# stamp files for header checks
38
check-y		:= $(patsubst %,.check.%,$(header-y) $(objhdr-y))
39 40

# Work out what needs to be removed
41 42
oldheaders      := $(patsubst $(install)/%,%,$(wildcard $(install)/*.h))
unwanted        := $(filter-out $(header-y) $(objhdr-y),$(oldheaders))
43

44 45
oldcheckstamps  := $(patsubst $(install)/%,%,$(wildcard $(install)/.check.*.h))
unwanted        += $(filter-out $(check-y),$(oldcheckstamps))
46 47

# Prefix them all with full paths to $(INSTALL_HDR_PATH)
48 49 50
header-y        := $(patsubst %,$(install)/%,$(header-y))
objhdr-y        := $(patsubst %,$(install)/%,$(objhdr-y))
check-y         := $(patsubst %,$(install)/%,$(check-y))
51

52 53 54
quiet_cmd_o_hdr_install = INSTALL $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
      cmd_o_hdr_install = cp $(patsubst $(install)/%,$(objtree)/$(obj)/%,$@) \
                             $(install)
55

56 57 58
quiet_cmd_unifdef = UNIFDEF $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
      cmd_unifdef = $(UNIFDEF) $(patsubst $(install)/%,$(srctree)/$(obj)/%,$@)\
                               | $(HDRSED) > $@ || :
59

60 61 62
quiet_cmd_check = CHECK   $(patsubst $(install)/.check.%,$(_dst)/%,$@)
      cmd_check = $(CONFIG_SHELL) $(srctree)/scripts/hdrcheck.sh \
                  $(INSTALL_HDR_PATH)/include $(subst /.check.,/,$@) $@
63

64 65
quiet_cmd_remove = REMOVE  $(_dst)/$@
      cmd_remove = rm -f $(install)/$@
66

67 68
quiet_cmd_mkdir  = MKDIR   $(patsubst $(INSTALL_HDR_PATH)/%,%,$@)
      cmd_mkdir  = mkdir -p $@
69

70
.PHONY: __headersinst __headerscheck
71

72
ifdef HDRCHECK
73 74 75
__headerscheck: $(subdir-y) $(check-y)
	@true

76
$(check-y) : $(install)/.check.%.h : $(install)/%.h
77
	$(call cmd,check)
78 79

# Other dependencies for $(check-y)
80
include /dev/null $(wildcard $(check-y))
81

82 83
# but leave $(check-y) as .PHONY for now until those
# deps are actually correct.
84 85
.PHONY: $(check-y)

86
else
87
# Rules for installing headers
88
__headersinst: $(subdir-y) $(header-y) $(objhdr-y)
89
	@true
90

91
$(objhdr-y) $(subdir-y) $(header-y): | $(install) $(unwanted)
92

93
$(install):
94 95
	$(call cmd,mkdir)

96
# Rules for removing unwanted header files
97 98 99 100
.PHONY: $(unwanted)
$(unwanted):
	$(call cmd,remove)

101 102
# Install generated files
$(objhdr-y): $(install)/%.h: $(objtree)/$(obj)/%.h $(kbuild-file)
103 104
	$(call cmd,o_hdr_install)

105 106
# Unifdef header files and install them
$(header-y): $(install)/%.h: $(srctree)/$(obj)/%.h $(kbuild-file)
107
	$(call cmd,unifdef)
108

109 110
endif

111
hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
112 113

# Recursion
114
.PHONY: $(subdir-y)
115
$(subdir-y):
116
	$(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@