From 280812bec8d2885ef259aa7a9130393a7281f55e Mon Sep 17 00:00:00 2001 From: Elliot Berman Date: Fri, 24 Jul 2020 18:12:48 -0700 Subject: [PATCH] ANDROID: kbuild: Add support for installing out-of-tree kernel headers Add support for installing out-of-tree kernel headers. The "headers_install" target was copied to the external module compilation section (lines 1245:1270), and the src/obj variables were tweaked to include $(KBUILD_EXTMODULE). Bug: 162332589 Change-Id: I2e2c7598612bea94267e6a9bc6d0793da53915ac Signed-off-by: Elliot Berman --- Documentation/kbuild/modules.rst | 16 ++++++++ Makefile | 64 ++++++++++++++++++-------------- 2 files changed, 53 insertions(+), 27 deletions(-) diff --git a/Documentation/kbuild/modules.rst b/Documentation/kbuild/modules.rst index 85ccc878895e..d4b3e0c1d9fb 100644 --- a/Documentation/kbuild/modules.rst +++ b/Documentation/kbuild/modules.rst @@ -21,6 +21,7 @@ This document describes how to build an out-of-tree kernel module. --- 4.1 Kernel Includes --- 4.2 Single Subdirectory --- 4.3 Several Subdirectories + --- 4.4 UAPI Headers Installation === 5. Module Installation --- 5.1 INSTALL_MOD_PATH --- 5.2 INSTALL_MOD_DIR @@ -131,6 +132,10 @@ executed to make module versioning work. /lib/modules//extra/, but a prefix may be added with INSTALL_MOD_PATH (discussed in section 5). + headers_install + Export headers in a format suitable for userspace. The default + location is $PWD/usr. INSTALL_HDR_PATH can change this path. + clean Remove all generated files in the module directory only. @@ -406,6 +411,17 @@ according to the following rule: pointing to the directory where the currently executing kbuild file is located. +4.4 UAPI Headers Installation +----------------------------- + + External modules may export headers to userspace in a similar + fashion to the in-tree counterpart drivers. kbuild supports + running headers_install target in an out-of-tree. The location + where kbuild searches for headers is $(M)/include/uapi and + $(M)/arch/$(SRCARCH)/include/uapi. + + See also Documentation/kbuild/headers_install.rst. + 5. Module Installation ====================== diff --git a/Makefile b/Makefile index 8e13dda19c87..effb910aa8ef 100644 --- a/Makefile +++ b/Makefile @@ -1073,6 +1073,41 @@ PHONY += prepare0 export MODORDER := $(extmod-prefix)modules.order export MODULES_NSDEPS := $(extmod-prefix)modules.nsdeps +# --------------------------------------------------------------------------- +# Kernel headers + +PHONY += headers + +#Default location for installed headers +ifeq ($(KBUILD_EXTMOD),) +PHONY += archheaders archscripts +hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj +headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts +else +hdr-prefix = $(KBUILD_EXTMOD)/ +hdr-inst := -f $(srctree)/scripts/Makefile.headersinst dst=$(KBUILD_EXTMOD)/usr/include objtree=$(objtree)/$(KBUILD_EXTMOD) obj +endif + +export INSTALL_HDR_PATH = $(objtree)/$(hdr-prefix)usr + +quiet_cmd_headers_install = INSTALL $(INSTALL_HDR_PATH)/include + cmd_headers_install = \ + mkdir -p $(INSTALL_HDR_PATH); \ + rsync -mrl --include='*/' --include='*\.h' --exclude='*' \ + usr/include $(INSTALL_HDR_PATH) + +PHONY += headers_install +headers_install: headers + $(call cmd,headers_install) + +headers: +ifeq ($(KBUILD_EXTMOD),) + $(if $(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/Kbuild),, \ + $(error Headers not exportable for the $(SRCARCH) architecture)) +endif + $(Q)$(MAKE) $(hdr-inst)=$(hdr-prefix)include/uapi + $(Q)$(MAKE) $(hdr-inst)=$(hdr-prefix)arch/$(SRCARCH)/include/uapi + ifeq ($(KBUILD_EXTMOD),) core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ @@ -1242,33 +1277,6 @@ headerdep: $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \ $(srctree)/scripts/headerdep.pl -I$(srctree)/include -# --------------------------------------------------------------------------- -# Kernel headers - -#Default location for installed headers -export INSTALL_HDR_PATH = $(objtree)/usr - -quiet_cmd_headers_install = INSTALL $(INSTALL_HDR_PATH)/include - cmd_headers_install = \ - mkdir -p $(INSTALL_HDR_PATH); \ - rsync -mrl --include='*/' --include='*\.h' --exclude='*' \ - usr/include $(INSTALL_HDR_PATH) - -PHONY += headers_install -headers_install: headers - $(call cmd,headers_install) - -PHONY += archheaders archscripts - -hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj - -PHONY += headers -headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts - $(if $(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/Kbuild),, \ - $(error Headers not exportable for the $(SRCARCH) architecture)) - $(Q)$(MAKE) $(hdr-inst)=include/uapi - $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi - # Deprecated. It is no-op now. PHONY += headers_check headers_check: @@ -1701,6 +1709,8 @@ help: @echo '' @echo ' modules - default target, build the module(s)' @echo ' modules_install - install the module' + @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH' + @echo ' (default: $(abspath $(INSTALL_HDR_PATH)))' @echo ' clean - remove generated files in module directory only' @echo ''