博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于内核中 #ifdef CONFIG_**的问题
阅读量:2152 次
发布时间:2019-04-30

本文共 2130 字,大约阅读时间需要 7 分钟。

经常在内核中看到这样的宏判断:
#ifdef CONFIG_**
....
#endif
比如,init/main.c中有这样的代码:
#ifdef CONFIG_PROC_FS
        proc_root_init();
#endif
这里的意思我知道,就是根据CONFIG_PROC_FS是否定义来选择proc文件系统。
如果选择proc文件系统,在.config中就会有如下内容:
CONFIG_PROC_FS=y

我不明白的是,如果要将上面的proc_root_init编译进内核,必须有#define CONFIG_PROC_FS或者编译时使用-DCONFIG_PROC_FS,但这两种方法我在代码中都找不到,难道是CONFIG_PROC_FS=y起作用了?如果是的话,它是怎么起作用的?
请指教,谢谢。

=================================================================================================================================

我是这样理解的:
#define CONFIG_PROC_FS 1 是在 include/linux/autoconf.h 中定义的 (autoconf.h 又是通过make menuconfig生成的)
在 顶层的Makefile中 定义了 LINUXINCLUDE.
LINUXINCLUDE    := -Iinclude \
                   $(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) \
           -include include/linux/autoconf.h
在编译 init/main.c时gcc会处理 -include include/linux/autoconf.h,相当于源文件中有 #include "linux/autoconfi.h"语句,此时 init/main.c就可以使用autoconf.h中的个个宏了。

cmd_init/main.o := gcc -m32 -Wp,-MD,init/.main.o.d  -nostdinc -isystem /usr/lib/gcc/i386-redhat-linux/4.1.2/include -D__KERNEL__ -Iinclude -Iinclude2 -I/root/fs_all/kernel/linux-2.6.24/include -include include/linux/autoconf.h -I/root/fs_all/kernel/linux-2.6.24/init -Iinit -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Os -pipe -msoft-float -mregparm=3 -freg-struct-return -mpreferred-stack-boundary=2 -march=i686 -mtune=generic -ffreestanding -maccumulate-outgoing-args -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -I/root/fs_all/kernel/linux-2.6.24/include/asm-x86/mach-generic -Iinclude/asm-x86/mach-generic -I/root/fs_all/kernel/linux-2.6.24/include/asm-x86/mach-default -Iinclude/asm-x86/mach-default -fno-omit-frame-pointer -fno-optimize-sibling-calls -g -fno-stack-protector -Wdeclaration-after-statement -Wno-pointer-sign  -D"KBUILD_STR(s)=\#s" -D"KBUILD_BASENAME=KBUILD_STR(main)"  -D"KBUILD_MODNAME=KBUILD_STR(main)" -c -o init/.tmp_main.o /root/   fs_all/kernel/linux-2.6.24/init/main.c

==================================================================================================================================

在嵌入式linux中:Linux-2.6.35.7/include/generated/autoconfig.h

转载地址:http://sdiwb.baihongyu.com/

你可能感兴趣的文章
A星算法详解(个人认为最详细,最通俗易懂的一个版本)
查看>>
利用栈实现DFS
查看>>
逆序对的数量(递归+归并思想)
查看>>
数的范围(二分查找上下界)
查看>>
算法导论阅读顺序
查看>>
Windows程序设计:直线绘制
查看>>
linux之CentOS下文件解压方式
查看>>
Django字段的创建并连接MYSQL
查看>>
div标签布局的使用
查看>>
HTML中表格的使用
查看>>
(模板 重要)Tarjan算法解决LCA问题(PAT 1151 LCA in a Binary Tree)
查看>>
(PAT 1154) Vertex Coloring (图的广度优先遍历)
查看>>
(PAT 1115) Counting Nodes in a BST (二叉查找树-统计指定层元素个数)
查看>>
(PAT 1143) Lowest Common Ancestor (二叉查找树的LCA)
查看>>
(PAT 1061) Dating (字符串处理)
查看>>
(PAT 1118) Birds in Forest (并查集)
查看>>
数据结构 拓扑排序
查看>>
(PAT 1040) Longest Symmetric String (DP-最长回文子串)
查看>>
(PAT 1145) Hashing - Average Search Time (哈希表冲突处理)
查看>>
(1129) Recommendation System 排序
查看>>