android 如何添加第3方lib库到kernel中

注意:只能将lib库放在kernel编译到的地方,如下:
alps/kernel/
alps/mediatek/custom/common/kernel/
alps/mediatek/custom/$platform/kernel/
alps/mediatek/custom/$proj/kernel/
alps/mediatek/kernel/
alps/mediatek/platform/$platform/kernel/core/
alps/mediatek/platform/$platform/kernel/drivers/
假设第3方库名称为test.a
(1). 如果存放的目录存在Makefile,那么只需在该Makefile最后添加:
obj-y += test.a
然后将test.a文件复制到该目录下,
重新命名为test.a_shipped,目的是防止clean kernel阶段把该库给清除掉!
重新编译kernel即可。
(2). 如果存放的目录不存在Makefile,比如在alps/mediatek/custom/目录下的kernel目录都没有Makefile,这时需要自行添加一个Makefile,内容和第1种方法差不多:
obj-y := xxx.o yyy.o test.a
以上表示将xxx.c/yyy.c和test.a编译到kernel
然后将test.a文件复制到该目录下并重新命名为test.a_shipped
重新编译kernel即可。
注意:alps/mediatek/custom/common/kernel/touchpanel/xxx目录下的文件会和alps/mediatek/custom/common/kernel/touchpanel/src目录合并,obj-y要将两个目录下的obj全部加入才行,否则编译失败。也可以用以下Makefile,自动将所有obj加入obj-y,省却麻烦。其他目录如有类似的情形一样处理。
添加的Makefile(将所有*.c变为*.o并加入obj-y):
include $(MTK_PATH_BUILD)/common.mk
path := $(if $(filter yes,$(KBUILD_OUTPUT_SUPPORT)),$(srctree)/$(obj),$(obj))
obj-y := $(patsubst %.c,%.o,$(subst $(path)/,,$(call wildcard2,$(path)/*.c)))
obj-y += test.a

说明:对于kernel的Makefile编写规则说明,可以到网络搜索相关材料参考,比如obj-y表示要编译到kernel,而obj-m表示要编译成module,obj-n或obj-表示不编译
原文地址:https://www.cnblogs.com/LoongEmbedded/p/5298364.html