Blame view

scripts/Makefile.headersinst 2.87 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  # SPDX-License-Identifier: GPL-2.0
8d730cfb5   David Woodhouse   Basic implementat...
2
3
4
  # ==========================================================================
  # Installing headers
  #
fcc8487d4   Nicolas Dichtel   uapi: export all ...
5
  # All headers under include/uapi, include/generated/uapi,
61562f981   Nicolas Dichtel   uapi: export all ...
6
  # arch/<arch>/include/uapi and arch/<arch>/include/generated/uapi are
fcc8487d4   Nicolas Dichtel   uapi: export all ...
7
8
  # exported.
  # They are preprocessed to remove __KERNEL__ section of the file.
8d730cfb5   David Woodhouse   Basic implementat...
9
10
  #
  # ==========================================================================
05d8cba4a   Masahiro Yamada   kbuild: skip inst...
11
12
13
14
  PHONY := __headers
  __headers:
  
  include scripts/Kbuild.include
d5470d144   Masahiro Yamada   kbuild: re-implem...
15
16
17
  src := $(srctree)/$(obj)
  gen := $(objtree)/$(subst include/,include/generated/,$(obj))
  dst := usr/include
2f263d145   Richard Genoud   kbuild: fix heade...
18

d5470d144   Masahiro Yamada   kbuild: re-implem...
19
  -include $(src)/Kbuild
2f263d145   Richard Genoud   kbuild: fix heade...
20

7ff4f0805   Masahiro Yamada   kbuild: fix 'No s...
21
22
23
24
  # $(filter %/, ...) is a workaround for GNU Make <= 4.2.1, where
  # $(wildcard $(src)/*/) contains not only directories but also regular files.
  src-subdirs := $(patsubst $(src)/%/,%,$(filter %/, $(wildcard $(src)/*/)))
  gen-subdirs := $(patsubst $(gen)/%/,%,$(filter %/, $(wildcard $(gen)/*/)))
d5470d144   Masahiro Yamada   kbuild: re-implem...
25
  all-subdirs := $(sort $(src-subdirs) $(gen-subdirs))
05d8cba4a   Masahiro Yamada   kbuild: skip inst...
26

d5470d144   Masahiro Yamada   kbuild: re-implem...
27
28
29
30
  src-headers := $(if $(src-subdirs), $(shell cd $(src) && find $(src-subdirs) -name '*.h'))
  src-headers := $(filter-out $(no-export-headers), $(src-headers))
  gen-headers := $(if $(gen-subdirs), $(shell cd $(gen) && find $(gen-subdirs) -name '*.h'))
  gen-headers := $(filter-out $(no-export-headers), $(gen-headers))
05d8cba4a   Masahiro Yamada   kbuild: skip inst...
31

d5470d144   Masahiro Yamada   kbuild: re-implem...
32
33
34
35
  # If the same header is exported from source and generated directories,
  # the former takes precedence, but this should be warned.
  duplicated := $(filter $(gen-headers), $(src-headers))
  $(if $(duplicated), $(warning duplicated header export: $(duplicated)))
05d8cba4a   Masahiro Yamada   kbuild: skip inst...
36

d5470d144   Masahiro Yamada   kbuild: re-implem...
37
  gen-headers := $(filter-out $(duplicated), $(gen-headers))
05d8cba4a   Masahiro Yamada   kbuild: skip inst...
38

d5470d144   Masahiro Yamada   kbuild: re-implem...
39
40
41
42
43
  # Add dst path prefix
  all-subdirs := $(addprefix $(dst)/, $(all-subdirs))
  src-headers := $(addprefix $(dst)/, $(src-headers))
  gen-headers := $(addprefix $(dst)/, $(gen-headers))
  all-headers := $(src-headers) $(gen-headers)
8d730cfb5   David Woodhouse   Basic implementat...
44

d5470d144   Masahiro Yamada   kbuild: re-implem...
45
46
47
48
  # Work out what needs to be removed
  old-subdirs := $(wildcard $(all-subdirs))
  old-headers := $(if $(old-subdirs),$(shell find $(old-subdirs) -name '*.h'))
  unwanted    := $(filter-out $(all-headers), $(old-headers))
de7891258   David Woodhouse   Use dependencies ...
49

d5470d144   Masahiro Yamada   kbuild: re-implem...
50
51
52
53
54
  # Create directories
  existing-dirs := $(sort $(dir $(old-headers)))
  wanted-dirs   := $(sort $(dir $(all-headers)))
  new-dirs      := $(filter-out $(existing-dirs), $(wanted-dirs))
  $(if $(new-dirs), $(shell mkdir -p $(new-dirs)))
de7891258   David Woodhouse   Use dependencies ...
55

d5470d144   Masahiro Yamada   kbuild: re-implem...
56
  # Rules
d5470d144   Masahiro Yamada   kbuild: re-implem...
57
  quiet_cmd_install = HDRINST $@
555187a87   Masahiro Yamada   kbuild: simplify ...
58
        cmd_install = $(CONFIG_SHELL) $(srctree)/scripts/headers_install.sh $< $@
de7891258   David Woodhouse   Use dependencies ...
59

d5470d144   Masahiro Yamada   kbuild: re-implem...
60
61
  $(src-headers): $(dst)/%.h: $(src)/%.h $(srctree)/scripts/headers_install.sh FORCE
  	$(call if_changed,install)
684753599   David Woodhouse   Basic implementat...
62

d5470d144   Masahiro Yamada   kbuild: re-implem...
63
64
  $(gen-headers): $(dst)/%.h: $(gen)/%.h $(srctree)/scripts/headers_install.sh FORCE
  	$(call if_changed,install)
8d730cfb5   David Woodhouse   Basic implementat...
65

7712401ae   Sam Ravnborg   kbuild: optimize ...
66
  quiet_cmd_remove = REMOVE  $(unwanted)
d5470d144   Masahiro Yamada   kbuild: re-implem...
67
        cmd_remove = rm -f $(unwanted)
de7891258   David Woodhouse   Use dependencies ...
68

d5470d144   Masahiro Yamada   kbuild: re-implem...
69
70
71
72
  __headers: $(all-headers)
  ifneq ($(unwanted),)
  	$(call cmd,remove)
  endif
7712401ae   Sam Ravnborg   kbuild: optimize ...
73
  	@:
de7891258   David Woodhouse   Use dependencies ...
74

d5470d144   Masahiro Yamada   kbuild: re-implem...
75
76
77
  existing-headers := $(filter $(old-headers), $(all-headers))
  
  -include $(foreach f,$(existing-headers),$(dir $(f)).$(notdir $(f)).cmd)
de7891258   David Woodhouse   Use dependencies ...
78

7712401ae   Sam Ravnborg   kbuild: optimize ...
79
  PHONY += FORCE
d5470d144   Masahiro Yamada   kbuild: re-implem...
80
  FORCE:
e474ed457   Masahiro Yamada   kbuild: specify F...
81
82
  
  .PHONY: $(PHONY)