summaryrefslogblamecommitdiff
path: root/scripts/Makefile.headersinst
blob: 599503f0e5f2a80fd2ec28c038ced4b0b676d74a (plain) (tree)
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
#
# ==========================================================================

UNIFDEF := scripts/unifdef -U__KERNEL__

# Eliminate the contents of (and inclusions of) compiler.h
HDRSED  := sed	-e "s/ inline / __inline__ /g" \
		-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" \
		-e "s/[[:space:]]__attribute_const__$$//" \
		-e "/^\#include <linux\/compiler.h>/d"

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

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

include scripts/Kbuild.include

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

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

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

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

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

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

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

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

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

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

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

.PHONY: __headersinst __headerscheck

ifdef HDRCHECK
__headerscheck: $(subdir-y) $(check-y)
	@true

$(check-y) : $(install)/.check.%.h : $(install)/%.h
	$(call cmd,check)

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

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

else
# Rules for installing headers
__headersinst: $(subdir-y) $(header-y) $(objhdr-y)
	@true

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

$(install):
	$(call cmd,mkdir)

# Rules for removing unwanted header files
.PHONY: $(unwanted)
$(unwanted):
	$(call cmd,remove)

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

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

endif

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

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