介绍一下编译makefile和config的知识。
当执行#make menuconfig时会出现内核的配置界面,所有配置工具都是通过读取"arch/$(ARCH)Kconfig"文件来生成配置界面,这个文件就是所有配置的总入口,它会包含其他目录的Kconfig
Kconfig的作用:Kconfig用来配置内核,它就是各种配置界面的源文件,内核的配置工具读取各个Kconfig文件,生成配置界面供开发人员配置内核,最后生成配置文件.config
Kconfig的语法可以参考“Documentation/kbuild/kconfig-language.txt”
Kconfig文件的基本要素:
1.config条目(entry)
config SENSORS_DEBUG
tristate"Generic sensors debug config" if EXPERT
default n
help
Say Y here if you want to debug the sensors
Say N here if you do not want to debug thesensors
If unsure, say Y.
解释:
1:config 是关键字,表示一个配置选项的开始。SENSORS_DEBUG是配置选项的名称,在一个项目中一般都有专门的config配置文件,用来打开或关闭该config,以此来控制要不要编译该文件进内核。config文件路径:kernel/arch/arm64/mach/...../xx_config
2:tristate 表示变量类型,就是SENSORS_DEBUG的类型,总共有5种类型:bool、tristate、string、hex和int,其中tristate和string是基本的类型。
bool变量的值: y和n
tristate变量的值:y、n和m
string变量的值: 字符串
字符串“Genericsensors debug config”是提示信息,在配置界面中上下移动光标选中它时,就可以通过按空格或回车键来设置
3:default n 表变量的默认值的n 即SENSORS_DEBUG变量的类型是tristate,默认值是n 即默认SENSORS_DEBUG=n
4: depends on TMPFS
dependson:表示依赖于XXX,“depends on TMPFS”表示只有当TMPFS配置选项被选中时,当前配置选项的提示信息才会出现,才能设置当前配置选项
source条目
source条目用于读取另一个Kconfig文件,如:
source"net/Kconifg"
makefile:
obj-$(CONFIG_SENSORS_PARAMS) += sensparams/
解释:如果CONFIG_SENSORS_PARAMS=y,sensparams则编译并链接进内核
如果CONFIG_SENSORS_PARAMS=n,sensparams则忽略,不编译
如果CONFIG_SENSORS_PARAMS=m,sensparams则作为模块编译
ifeq ($(TARGET_SENSORS_NOCOMPASS), true)
include $(call all-named-subdir-makefiles, libsensors2)
解释:$ 表引入,如果TARGET_SENSORS_NOCOMPASS为true,则includelibsensor2所有子目录下的makefiles
// ccflags-y += -I$ ----引入该路径下的头文件
ccflags-y += -I$(srctree)/drivers/misc/mediatek/accelerometer/inc
ccflags-y +=-I$(srctree)/drivers/misc/mediatek/hwmon/include
obj-y := xxxx.o
srctree:kbuild所在路径:/kernel-3.18
那么在xxxx.c中就可以直接包含上面路径inc 和include文件中的投文件
如
#include <cust_acc.h>
#include <hwmsensor.h>
#include <hwmsen_dev.h>
#include <sensors_io.h>