summaryrefslogtreecommitdiffstats
path: root/docs/manual/writing-rules.txt
blob: c9816a44021671d89be62d56c526e72a2699d826 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// -*- mode:doc; -*-
// vim: set syntax=asciidoc:

Coding style
------------

Overall, these coding style rules are here to help you to add new files in
Buildroot or refactor existing ones.

If you slightly modify some existing file, the important thing is
to keep the consistency of the whole file, so you can:

* either follow the potentially deprecated coding style used in this
file,

* or entirely rework it in order to make it comply with these rules.

[[writing-rules-config-in]]

+Config.in+ file
~~~~~~~~~~~~~~~~

+Config.in+ files contain entries for almost anything configurable in
Buildroot.

An entry has the following pattern:

---------------------
config BR2_PACKAGE_LIBFOO
	bool "libfoo"
	depends on BR2_PACKAGE_LIBBAZ
	select BR2_PACKAGE_LIBBAR
	help
	  This is a comment that explains what libfoo is.

	  http://foosoftware.org/libfoo/
---------------------

* The +bool+, +depends on+, +select+ and +help+ lines are indented
  with one tab.

* The help text itself should be indented with one tab and two
  spaces.

The +Config.in+ files are the input for the configuration tool
used in Buildroot, which is the regular _Kconfig_. For further
details about the _Kconfig_ language, refer to
http://kernel.org/doc/Documentation/kbuild/kconfig-language.txt[].

[[writing-rules-mk]]

The +.mk+ file
~~~~~~~~~~~~~~

* Assignment: use +=+ preceded and followed by one space:
+
---------------------
LIBFOO_VERSION = 1.0
LIBFOO_CONF_OPT += --without-python-support
---------------------
+
It is also possible to align the +=+ signs:
+
---------------------
LIBFOO_VERSION   = 1.0
LIBFOO_SOURCE    = foo-$(LIBFOO_VERSION).tar.gz
LIBFOO_CONF_OPT += --without-python-support
---------------------

* Indentation: use tab only:
+
---------------------
define LIBFOO_REMOVE_DOC
	$(RM) -fr $(TARGET_DIR)/usr/share/libfoo/doc \
		$(TARGET_DIR)/usr/share/man/man3/libfoo*
endef
---------------------
+
Note that commands inside a +define+ block should always start with a tab,
so _make_ recognizes them as commands.

* Optional dependency:

** Prefer multi-line syntax.
+
YES:
+
---------------------
ifeq ($(BR2_PACKAGE_PYTHON),y)
LIBFOO_CONF_OPT += --with-python-support
LIBFOO_DEPENDENCIES += python
else
LIBFOO_CONF_OPT += --without-python-support
endif
---------------------
+
NO:
+
---------------------
LIBFOO_CONF_OPT += --with$(if $(BR2_PACKAGE_PYTHON),,out)-python-support
LIBFOO_DEPENDENCIES += $(if $(BR2_PACKAGE_PYTHON),python,)
---------------------

** Keep configure options and dependencies close together.

* Optional hooks: keep hook definition and assignment together in one
  if block.
+
YES:
+
---------------------
ifneq ($(BR2_LIBFOO_INSTALL_DATA),y)
define LIBFOO_REMOVE_DATA
	$(RM) -fr $(TARGET_DIR)/usr/share/libfoo/data
endef
LIBFOO_POST_INSTALL_TARGET_HOOKS += LIBFOO_REMOVE_DATA
endif
---------------------
+
NO:
+
---------------------
define LIBFOO_REMOVE_DATA
	$(RM) -fr $(TARGET_DIR)/usr/share/libfoo/data
endef

ifneq ($(BR2_LIBFOO_INSTALL_DATA),y)
LIBFOO_POST_INSTALL_TARGET_HOOKS += LIBFOO_REMOVE_DATA
endif
---------------------

The documentation
~~~~~~~~~~~~~~~~~

The documentation uses the
http://www.methods.co.nz/asciidoc/[asciidoc] format.

For further details about the http://www.methods.co.nz/asciidoc/[asciidoc]
syntax, refer to http://www.methods.co.nz/asciidoc/userguide.html[].