Blame view

scripts/Makefile.headersinst 4.27 KB
8d730cfb5   David Woodhouse   Basic implementat...
1
2
3
  # ==========================================================================
  # Installing headers
  #
7712401ae   Sam Ravnborg   kbuild: optimize ...
4
5
  # header-y  - list files to be installed. They are preprocessed
  #             to remove __KERNEL__ section of the file
40f1d4c20   David Howells   UAPI: Remove the ...
6
  # genhdr-y  - Same as header-y but in a generated/ directory
8d730cfb5   David Woodhouse   Basic implementat...
7
8
  #
  # ==========================================================================
cb97914b0   H. Peter Anvin   kbuild: Add suppo...
9
10
  # generated header directory
  gen := $(if $(gen),$(gen),$(subst include/,include/generated/,$(obj)))
283039fb7   Sam Ravnborg   kbuild: drop supp...
11
12
  kbuild-file := $(srctree)/$(obj)/Kbuild
  include $(kbuild-file)
8d730cfb5   David Woodhouse   Basic implementat...
13

9b58b9281   Jesper Nilsson   kbuild: Fix desti...
14
  # called may set destination dir (when installing to asm/)
c4619bc6f   Sam Ravnborg   kbuild: fix make ...
15
  _dst := $(if $(destination-y),$(destination-y),$(if $(dst),$(dst),$(obj)))
9b58b9281   Jesper Nilsson   kbuild: Fix desti...
16

10b63956f   David Howells   UAPI: Plumb the U...
17
18
19
20
  old-kbuild-file := $(srctree)/$(subst uapi/,,$(obj))/Kbuild
  ifneq ($(wildcard $(old-kbuild-file)),)
  include $(old-kbuild-file)
  endif
c7bb349e7   Sam Ravnborg   kbuild: introduce...
21

283039fb7   Sam Ravnborg   kbuild: drop supp...
22
  include scripts/Kbuild.include
de7891258   David Woodhouse   Use dependencies ...
23

10b63956f   David Howells   UAPI: Plumb the U...
24
  installdir    := $(INSTALL_HDR_PATH)/$(subst uapi/,,$(_dst))
8d730cfb5   David Woodhouse   Basic implementat...
25

7cfddeef3   Sam Ravnborg   kbuild: drop unif...
26
  header-y      := $(sort $(header-y))
7712401ae   Sam Ravnborg   kbuild: optimize ...
27
28
  subdirs       := $(patsubst %/,%,$(filter %/, $(header-y)))
  header-y      := $(filter-out %/, $(header-y))
de7891258   David Woodhouse   Use dependencies ...
29

7712401ae   Sam Ravnborg   kbuild: optimize ...
30
  # files used to track state of install/check
10b63956f   David Howells   UAPI: Plumb the U...
31
32
  install-file  := $(installdir)/.install
  check-file    := $(installdir)/.check
de7891258   David Woodhouse   Use dependencies ...
33

d8ecc5cd8   Sam Ravnborg   kbuild: asm-gener...
34
35
36
  # 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))
10b63956f   David Howells   UAPI: Plumb the U...
37
38
39
40
  srcdir        := $(srctree)/$(obj)
  gendir        := $(objtree)/$(gen)
  
  oldsrcdir     := $(srctree)/$(subst /uapi,,$(obj))
7712401ae   Sam Ravnborg   kbuild: optimize ...
41
  # all headers files for this dir
d8ecc5cd8   Sam Ravnborg   kbuild: asm-gener...
42
  header-y      := $(filter-out $(generic-y), $(header-y))
40f1d4c20   David Howells   UAPI: Remove the ...
43
  all-files     := $(header-y) $(genhdr-y) $(wrapper-files)
10b63956f   David Howells   UAPI: Plumb the U...
44
45
46
  output-files  := $(addprefix $(installdir)/, $(all-files))
  
  input-files   := $(foreach hdr, $(header-y), \
c4619bc6f   Sam Ravnborg   kbuild: fix make ...
47
  		   $(if $(wildcard $(srcdir)/$(hdr)), \
10b63956f   David Howells   UAPI: Plumb the U...
48
  			$(wildcard $(srcdir)/$(hdr)), \
c4619bc6f   Sam Ravnborg   kbuild: fix make ...
49
50
51
  			$(if $(wildcard $(oldsrcdir)/$(hdr)), \
  				$(wildcard $(oldsrcdir)/$(hdr)), \
  				$(error Missing UAPI file $(srcdir)/$(hdr))) \
10b63956f   David Howells   UAPI: Plumb the U...
52
53
  		   )) \
  		 $(foreach hdr, $(genhdr-y), \
c4619bc6f   Sam Ravnborg   kbuild: fix make ...
54
  		   $(if	$(wildcard $(gendir)/$(hdr)), \
10b63956f   David Howells   UAPI: Plumb the U...
55
56
57
  			$(wildcard $(gendir)/$(hdr)), \
  			$(error Missing generated UAPI file $(gendir)/$(hdr)) \
  		   ))
de7891258   David Woodhouse   Use dependencies ...
58

7712401ae   Sam Ravnborg   kbuild: optimize ...
59
  # Work out what needs to be removed
10b63956f   David Howells   UAPI: Plumb the U...
60
  oldheaders    := $(patsubst $(installdir)/%,%,$(wildcard $(installdir)/*.h))
7712401ae   Sam Ravnborg   kbuild: optimize ...
61
  unwanted      := $(filter-out $(all-files),$(oldheaders))
8d730cfb5   David Woodhouse   Basic implementat...
62

7712401ae   Sam Ravnborg   kbuild: optimize ...
63
  # Prefix unwanted with full paths to $(INSTALL_HDR_PATH)
10b63956f   David Howells   UAPI: Plumb the U...
64
  unwanted-file := $(addprefix $(installdir)/, $(unwanted))
de7891258   David Woodhouse   Use dependencies ...
65

7712401ae   Sam Ravnborg   kbuild: optimize ...
66
  printdir = $(patsubst $(INSTALL_HDR_PATH)/%/,%,$(dir $@))
684753599   David Woodhouse   Basic implementat...
67

7712401ae   Sam Ravnborg   kbuild: optimize ...
68
69
  quiet_cmd_install = INSTALL $(printdir) ($(words $(all-files))\
                              file$(if $(word 2, $(all-files)),s))
db1bec4f5   Sam Ravnborg   kbuild: install a...
70
        cmd_install = \
e0e2fa4b5   Rob Landley   headers_install.p...
71
          $(CONFIG_SHELL) $< $(installdir) $(input-files); \
d8ecc5cd8   Sam Ravnborg   kbuild: asm-gener...
72
          for F in $(wrapper-files); do                                   \
10b63956f   David Howells   UAPI: Plumb the U...
73
                  echo "\#include <asm-generic/$$F>" > $(installdir)/$$F;    \
d8ecc5cd8   Sam Ravnborg   kbuild: asm-gener...
74
          done;                                                           \
db1bec4f5   Sam Ravnborg   kbuild: install a...
75
          touch $@
8d730cfb5   David Woodhouse   Basic implementat...
76

7712401ae   Sam Ravnborg   kbuild: optimize ...
77
78
  quiet_cmd_remove = REMOVE  $(unwanted)
        cmd_remove = rm -f $(unwanted-file)
8d730cfb5   David Woodhouse   Basic implementat...
79

7712401ae   Sam Ravnborg   kbuild: optimize ...
80
  quiet_cmd_check = CHECK   $(printdir) ($(words $(all-files)) files)
7211b8b90   Sergei Poselenov   kbuild: fix "Argu...
81
82
83
  # Headers list can be pretty long, xargs helps to avoid
  # the "Argument list too long" error.
        cmd_check = for f in $(all-files); do                          \
10b63956f   David Howells   UAPI: Plumb the U...
84
                    echo "$(installdir)/$${f}"; done                      \
7211b8b90   Sergei Poselenov   kbuild: fix "Argu...
85
86
                    | xargs                                            \
                    $(PERL) $< $(INSTALL_HDR_PATH)/include $(SRCARCH); \
7712401ae   Sam Ravnborg   kbuild: optimize ...
87
  	          touch $@
de7891258   David Woodhouse   Use dependencies ...
88

7712401ae   Sam Ravnborg   kbuild: optimize ...
89
  PHONY += __headersinst __headerscheck
de7891258   David Woodhouse   Use dependencies ...
90

7712401ae   Sam Ravnborg   kbuild: optimize ...
91
92
93
94
  ifndef HDRCHECK
  # Rules for installing headers
  __headersinst: $(subdirs) $(install-file)
  	@:
de7891258   David Woodhouse   Use dependencies ...
95

7712401ae   Sam Ravnborg   kbuild: optimize ...
96
  targets += $(install-file)
e0e2fa4b5   Rob Landley   headers_install.p...
97
  $(install-file): scripts/headers_install.sh $(input-files) FORCE
7712401ae   Sam Ravnborg   kbuild: optimize ...
98
99
100
  	$(if $(unwanted),$(call cmd,remove),)
  	$(if $(wildcard $(dir $@)),,$(shell mkdir -p $(dir $@)))
  	$(call if_changed,install)
de7891258   David Woodhouse   Use dependencies ...
101

684753599   David Woodhouse   Basic implementat...
102
  else
7712401ae   Sam Ravnborg   kbuild: optimize ...
103
104
  __headerscheck: $(subdirs) $(check-file)
  	@:
8d730cfb5   David Woodhouse   Basic implementat...
105

7712401ae   Sam Ravnborg   kbuild: optimize ...
106
107
108
  targets += $(check-file)
  $(check-file): scripts/headers_check.pl $(output-files) FORCE
  	$(call if_changed,check)
8d730cfb5   David Woodhouse   Basic implementat...
109

7712401ae   Sam Ravnborg   kbuild: optimize ...
110
  endif
de7891258   David Woodhouse   Use dependencies ...
111

7712401ae   Sam Ravnborg   kbuild: optimize ...
112
113
114
115
116
  # Recursion
  hdr-inst := -rR -f $(srctree)/scripts/Makefile.headersinst obj
  .PHONY: $(subdirs)
  $(subdirs):
  	$(Q)$(MAKE) $(hdr-inst)=$(obj)/$@ dst=$(_dst)/$@
8d730cfb5   David Woodhouse   Basic implementat...
117

7712401ae   Sam Ravnborg   kbuild: optimize ...
118
119
120
  targets := $(wildcard $(sort $(targets)))
  cmd_files := $(wildcard \
               $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
4e420aa94   Sam Ravnborg   kbuild: always un...
121

7712401ae   Sam Ravnborg   kbuild: optimize ...
122
123
  ifneq ($(cmd_files),)
  	include $(cmd_files)
8d730cfb5   David Woodhouse   Basic implementat...
124
  endif
7712401ae   Sam Ravnborg   kbuild: optimize ...
125
126
127
  .PHONY: $(PHONY)
  PHONY += FORCE
  FORCE: ;