Kernel fixes
关于在Android10上如何修改kernel的Makefile,可参考Sony Kernel: Update makefiles for Android Q and clang
Android 10 build相关改动
主要的变更点如下:
- 对$PATH变量的限制
- 弃用GCC4.9
- 移除ccache
- PHONY 目标规则强制
更多信息可以参考, AOSP: Build System Changes for Android.mk Writers
PHONY targets
更多信息参考 .PHONY rule enforcement
真实的输出文件不能被定义为PHONY目标,否则会给出编译警告,如下
warning: PHONY target "out/.../foo" looks like a real file (contains a "/")
如果输出文件不是真正的PHONY目标,请移除相关属性定义,如下
-.PHONY: $(PRODUCT_OUT)/kernel
-$(PRODUCT_OUT)/kernel: $(KERNEL_BIN) | $(ACP)
- cp $(KERNEL_BIN) $(PRODUCT_OUT)/kernel
+$(PRODUCT_OUT)/kernel: $(KERNEL_BIN)
+ $(ACP) $(KERNEL_BIN) $(PRODUCT_OUT)/kernel
当然,如果您的最终目标不是PHONY,中间就不可以依赖PHONY target,这是make的标准配置
Output directory restrictions
如果你依赖具有绝对文件名的构建目标,这回给你带来麻烦。
例如:
KERNEL_OUT: $(PWD)/$(OUT)/obj/KERNEL_OBJ
$(KERNEL_OUT)/drivers:
make -C $(KERNEL_SRC) -O $(KERNEL_OUT) drivers
抛出如下警告warning: writing to readonly directory: "/home/[...]/out/[...]/KERNEL_OBJ/drivers"
这是因为,编译输出目录$(KERNEL_OUT)/drivers不是从out/target/...开始,而是一个绝对路径;编译系统无法确定这个路径是否应该被允许。
使用一个相对路径KERNEL\_OUT作为make的目标,在make命令中使用真正的绝对路径KERNEL\_OUT\_ABS:
KERNEL_OUT: $(OUT)/obj/KERNEL_OBJ
KERNEL_OUT_ABS: $(PWD)/$(OUT)/obj/KERNEL_OBJ
$(KERNEL_OUT)/drivers:
make -C $(KERNEL_SRC) -O $(KERNEL_OUT_ABS) drivers
GCC is broken for host compilation
Even with correct PATH supplied for cc1, the prebuilt GCC 4.9 still fails at compiling the host scripts:
HOSTCC scripts/basic/fixdep
[...]/kernel/scripts/basic/fixdep.c:105:23:
fatal error: sys/types.h: No such file or directory
#include <sys/types.h>
It’s better to use clang for HOSTCC:
# Android.mk
CLANG_HOST_TOOLCHAIN := $(PWD)/prebuilts/clang/host/linux-x86/clang-r365631/bin
CLANG_HOSTCC := $(CLANG_HOST_TOOLCHAIN)/clang
[...]
KERNEL_CROSS_COMPILE += HOSTCC="$(CLANG_HOSTCC)"
[...]
my-target:
make $(MAKE_FLAGS) -C $(KERNEL_SRC_ABS) O=$(KERNEL_OUT_ABS) \
ARCH=$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE)
Makefile:
-HOSTCC = gcc
-HOSTCXX = g++
+HOSTCC = $(HOSTCC)
+HOSTCXX = $(HOSTCXX)
Absolute paths for invoking build tools
调用构建工具的绝对路径
CLANG_HOST_TOOLCHAIN := $(PWD)/prebuilts/clang/host/linux-x86/clang-r365631/bin
KERNEL_HOSTCC := $(CLANG_HOST_TOOLCHAIN)/clang
KERNEL_TOOLCHAIN := $(PWD)/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin
KERNEL_TOOLCHAIN_PREFIX := aarch64-linux-android-
KERNEL_TOOLCHAIN_PATH := $(KERNEL_TOOLCHAIN)/$(KERNEL_TOOLCHAIN_PREFIX)
KERNEL_CROSS_COMPILE :=
KERNEL_CROSS_COMPILE += CC="$(CLANG_CC)"
KERNEL_CROSS_COMPILE += CLANG_TRIPLE="aarch64-linux-gnu"
KERNEL_CROSS_COMPILE += HOSTCC="$(KERNEL_HOSTCC)"
KERNEL_CROSS_COMPILE += CROSS_COMPILE="$(KERNEL_TOOLCHAIN_PATH)"
KERNEL_CROSS_COMPILE += CROSS_COMPILE_ARM32="$(KERNEL_TOOLCHAIN_32BITS_PATH)"
No relying on tools being in PATH
不要依赖PATH变量中的的工具
不可以使用$PATH中的make,perl,gcc等工具。更多信息可以参考Android Q Changes: PATH restrictions.
Perl is no longer allowed as a PATH tool:
# Android.mk
KERNEL_PERL := /usr/bin/perl
[...]
KERNEL_CROSS_COMPILE += PERL=$(KERNEL_PERL)
Makefile:
-PERL= perl
+PERL= $(PERL)
lib/Makefile:
- cmd_build_OID_registry = perl $(srctree)/$(src)/build_OID_registry $< $@
+ cmd_build_OID_registry = $(PERL) $(srctree)/$(src)/build_OID_registry $< $@
make is no longer an allowed PATH tool, and you need to supply an extra PATH for host binutils:
GCC_PREBUILTS := $(PWD)/prebuilts/gcc/linux-x86/host
KERNEL_HOST_TOOLCHAIN := \
$(GCC_PREBUILTS)/x86_64-linux-glibc2.17-4.8/x86_64-linux/bin
KERNEL_HOST_TOOLCHAIN_LIBEXEC := \
$(GCC_PREBUILTS)/libexec/gcc/x86_64-linux/4.8.3
KERNEL_PREBUILT_MAKE := $(PWD)/prebuilts/build-tools/linux-x86/bin/make
# clang/GCC (glibc) host toolchain needs to be prepended to $PATH for certain
# host bootstrap tools to be built. Also, binutils such as `ld` and `ar` are
# needed for now.
KERNEL_MAKE_EXTRA_PATH := $(KERNEL_HOST_TOOLCHAIN)
ifneq ($(TARGET_KERNEL_USE_CLANG),true)
KERNEL_MAKE_EXTRA_PATH := \
"$(KERNEL_HOST_TOOLCHAIN):$(KERNEL_HOST_TOOLCHAIN_LIBEXEC)"
endif
KERNEL_MAKE := \
PATH="$(KERNEL_MAKE_EXTRA_PATH):$$PATH" \
$(KERNEL_PREBUILT_MAKE)
评论 (0)