自学内容网 自学内容网

linux 内核如何读取你配置好的.config文件

前言

众所周知,linux kernel可以根据使用者的需要灵活的配置架构、功能和模块。甚至在文件内部的同一个接口也会根据配置不同条件编译不同的实现,这些都是通过读取在内核的顶层目录通过make menuconfig后生成的.config文件实现的。
那么这个读取的过程是怎么实现的呢?

1.条件编译模块

在这里插入图片描述
顶层Makefile通过export将.config文件中保存的配置传递到下一级Makefile

2.文件内部的条件编译宏

在这里插入图片描述
linux kernel会在编译生成中间文件时加上-include autoconf.h,这个autoconf.h实际上就是内核在编译过程中读取.config文件自动生成的配置相关头文件。加上-include这个选项可以使得.c文件即使没有声明包含该头文件,也能包含到它。

autoconf.h文件的生成位置:
scripts/kconfig/confdata.c:conf_write_autoconf(void)

在这里插入图片描述
在这里插入图片描述
rename函数作用:

SYNOPSIS
       #include <stdio.h>
DESCRIPTION
rename() renames a file, moving it between directories if required.  Any other hard links to the file (as created using link(2)) are unaffected.  Open file descriptors for oldpath are also unaffected.
RETURN VALUE
       On success, zero is returned.  On error, -1 is returned, and errno is set appropriately.


原文地址:https://blog.csdn.net/weixin_45465612/article/details/142923639

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!