Skip to content

Stop using gcc's "-include" flag #7216

Closed
@SebastianBoe

Description

@SebastianBoe

Both the linux kernel and Zephyr uses gcc's "-include" feature to insert Kconfig defines into the top of every source file that is built.

The main advantage of using "-include" is that it is impossible for a C source file to accidentally forget to include the Kconfig header file[0].

But protecting the user from this user-error has several disadvantages.

IDE support

IDE's and other C tooling that rely on best-effort parsing of C source code will struggle to resolve where the CONFIG_ defines come from because there is no #include that points to where the CONFIG_ defines come from.

E.g. opening a hello world Zephyr application with Eclipse presents the user with a compilation error because CONFIG_ARCH is not being resolved.

Even CLion, which is supposed to have CMake-integration had for many years an open bug about "-include" not being parsed correctly.

Human readability

Not only tools, but also humans are more confused by "-include" than "#include". If a firmware developer
wants to get familiar with Zephyr and find out where the CONFIG_ macros come from he will be able to follow "#include's" without assistance or reading documentation. But self-discovering that the build system is using the niche "-include" flag is not as easy.

It is not clear-cut, but I believe that out-of-the-box IDE support and a simplified build system will outweigh the confusion from accidentally omitting #include "conf.h". The best resolution to this issue however would be some mechanism that could verify that all C sources include directly or indirectly autoconf.h, then we would have all of the advantages, but none of the disadvantages of -include.

EDIT: After thinking more about this, testing for this would be very difficult, because not only would you need to prove that #include "conf.h" occurs, but also that it occurs before any CONFIG_ define is used ...

[0] TODO: Is there any way to automatically enforce/test that all C source files either directly or indirectly #include autoconf.h ?

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions