预处理 Linux 源代码并保存到另一个目录

Preprocess the Linux source code and save to another directory

假设我在 /tmp/linux-src 中有完整的 Linux 源代码。在 menuconfig 之后,我想做 "some kind of gcc -E",其中除 #include 之外的所有预处理器宏都被扩展,因此 实际配置的预处理 源代码(用于编译)将保存在 /tmp/linux-src-to-compile - 不是在单个文件中,而是保留整个树结构,排除不需要的文件。这种骗局可能吗?准备交叉编译时也可以吗?

谢谢

简短回答:不。一般情况下是做不到的。

长答案: 大多数预处理是通过#include 文件进行的。保留 #include(不扩展它们)将阻止大多数 #define、#ifdef、... 工作。

考虑 SEEK_END

的简单情况
file.c
#include <stdlib.h>
#include <stdio.h>
...
    fseek(fp, 0, SEEK_END) ;

将 SEEK_END 翻译成“2”将需要阅读、分析和扩展 stdio.h、跟随许多 #if 等。此外,它还需要扩展任何以前 #included 的文件,在这种情况下,它可能定义会影响 stdio.h - stdlib.h 的符号。