mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-08 19:11:53 +00:00
doc/develop/codingstyle.rst: Clarify include section
Rework the section about includes slightly. We should not be using common.h anywhere, so remove that from examples and ask people to send patches removing it when found. Doing this also means we need to reword other parts of this section. Be clearer about using alphabetical ordering. Signed-off-by: Tom Rini <trini@konsulko.com> Reviewed-by: Igor Opaniuk <igor.opaniuk@gmail.com>
This commit is contained in:
parent
1a72acba38
commit
2eb39c9ada
1 changed files with 11 additions and 12 deletions
|
@ -108,30 +108,29 @@ expected size, or that particular members appear at the right offset.
|
||||||
Include files
|
Include files
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
You should follow this ordering in U-Boot. The common.h header (which is going
|
You should follow this ordering in U-Boot. In all cases, they should be listed
|
||||||
away at some point) should always be first, followed by other headers in order,
|
in alphabetical order. First comes headers which are located directly in our
|
||||||
then headers with directories, then local files:
|
top-level include diretory. This excludes the common.h header file which is to
|
||||||
|
be removed. Second are headers within subdirectories, Finally directory-local
|
||||||
|
includes should be listed. See this example:
|
||||||
|
|
||||||
.. code-block:: C
|
.. code-block:: C
|
||||||
|
|
||||||
#include <common.h>
|
|
||||||
#include <bootstage.h>
|
#include <bootstage.h>
|
||||||
#include <dm.h>
|
#include <dm.h>
|
||||||
#include <others.h>
|
#include <others.h>
|
||||||
#include <asm/...>
|
#include <asm/...>
|
||||||
#include <arm/arch/...>
|
#include <asm/arch/...>
|
||||||
#include <dm/device_compat.h>
|
#include <dm/device_compat.h>
|
||||||
#include <linux/...>
|
#include <linux/...>
|
||||||
#include "local.h"
|
#include "local.h"
|
||||||
|
|
||||||
Within that order, sort your includes.
|
|
||||||
|
|
||||||
It is important to include common.h first since it provides basic features used
|
|
||||||
by most files, e.g. CONFIG options.
|
|
||||||
|
|
||||||
For files that need to be compiled for the host (e.g. tools), you need to use
|
For files that need to be compiled for the host (e.g. tools), you need to use
|
||||||
``#ifndef USE_HOSTCC`` to avoid including common.h since it includes a lot of
|
``#ifndef USE_HOSTCC`` to avoid including U-Boot specific include files. See
|
||||||
internal U-Boot things. See common/image.c for an example.
|
common/image.c for an example.
|
||||||
|
|
||||||
|
If you encounter code which still uses <common.h> a patch to remove that and
|
||||||
|
replace it with any required include files directly is much appreciated.
|
||||||
|
|
||||||
If your file uses driver model, include <dm.h> in the C file. Do not include
|
If your file uses driver model, include <dm.h> in the C file. Do not include
|
||||||
dm.h in a header file. Try to use forward declarations (e.g. ``struct
|
dm.h in a header file. Try to use forward declarations (e.g. ``struct
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue