xref: /OK3568_Linux_fs/buildroot/docs/manual/writing-rules.txt (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun// -*- mode:doc; -*-
2*4882a593Smuzhiyun// vim: set syntax=asciidoc:
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun== Coding style
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunOverall, these coding style rules are here to help you to add new files in
7*4882a593SmuzhiyunBuildroot or refactor existing ones.
8*4882a593Smuzhiyun
9*4882a593SmuzhiyunIf you slightly modify some existing file, the important thing is
10*4882a593Smuzhiyunto keep the consistency of the whole file, so you can:
11*4882a593Smuzhiyun
12*4882a593Smuzhiyun* either follow the potentially deprecated coding style used in this
13*4882a593Smuzhiyunfile,
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun* or entirely rework it in order to make it comply with these rules.
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun[[writing-rules-config-in]]
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun=== +Config.in+ file
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun+Config.in+ files contain entries for almost anything configurable in
22*4882a593SmuzhiyunBuildroot.
23*4882a593Smuzhiyun
24*4882a593SmuzhiyunAn entry has the following pattern:
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun---------------------
27*4882a593Smuzhiyunconfig BR2_PACKAGE_LIBFOO
28*4882a593Smuzhiyun	bool "libfoo"
29*4882a593Smuzhiyun	depends on BR2_PACKAGE_LIBBAZ
30*4882a593Smuzhiyun	select BR2_PACKAGE_LIBBAR
31*4882a593Smuzhiyun	help
32*4882a593Smuzhiyun	  This is a comment that explains what libfoo is. The help text
33*4882a593Smuzhiyun	  should be wrapped.
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun	  http://foosoftware.org/libfoo/
36*4882a593Smuzhiyun---------------------
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun* The +bool+, +depends on+, +select+ and +help+ lines are indented
39*4882a593Smuzhiyun  with one tab.
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun* The help text itself should be indented with one tab and two
42*4882a593Smuzhiyun  spaces.
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun* The help text should be wrapped to fit 72 columns, where tab counts
45*4882a593Smuzhiyun  for 8, so 62 characters in the text itself.
46*4882a593Smuzhiyun
47*4882a593SmuzhiyunThe +Config.in+ files are the input for the configuration tool
48*4882a593Smuzhiyunused in Buildroot, which is the regular _Kconfig_. For further
49*4882a593Smuzhiyundetails about the _Kconfig_ language, refer to
50*4882a593Smuzhiyunhttp://kernel.org/doc/Documentation/kbuild/kconfig-language.txt[].
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun[[writing-rules-mk]]
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun=== The +.mk+ file
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun* Header: The file starts with a header. It contains the module name,
57*4882a593Smuzhiyunpreferably in lowercase, enclosed between separators made of 80 hashes. A
58*4882a593Smuzhiyunblank line is mandatory after the header:
59*4882a593Smuzhiyun+
60*4882a593Smuzhiyun---------------------
61*4882a593Smuzhiyun################################################################################
62*4882a593Smuzhiyun#
63*4882a593Smuzhiyun# libfoo
64*4882a593Smuzhiyun#
65*4882a593Smuzhiyun################################################################################
66*4882a593Smuzhiyun---------------------
67*4882a593Smuzhiyun+
68*4882a593Smuzhiyun* Assignment: use +=+ preceded and followed by one space:
69*4882a593Smuzhiyun+
70*4882a593Smuzhiyun---------------------
71*4882a593SmuzhiyunLIBFOO_VERSION = 1.0
72*4882a593SmuzhiyunLIBFOO_CONF_OPTS += --without-python-support
73*4882a593Smuzhiyun---------------------
74*4882a593Smuzhiyun+
75*4882a593SmuzhiyunDo not align the +=+ signs.
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun* Indentation: use tab only:
78*4882a593Smuzhiyun+
79*4882a593Smuzhiyun---------------------
80*4882a593Smuzhiyundefine LIBFOO_REMOVE_DOC
81*4882a593Smuzhiyun	$(RM) -fr $(TARGET_DIR)/usr/share/libfoo/doc \
82*4882a593Smuzhiyun		$(TARGET_DIR)/usr/share/man/man3/libfoo*
83*4882a593Smuzhiyunendef
84*4882a593Smuzhiyun---------------------
85*4882a593Smuzhiyun+
86*4882a593SmuzhiyunNote that commands inside a +define+ block should always start with a tab,
87*4882a593Smuzhiyunso _make_ recognizes them as commands.
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun* Optional dependency:
90*4882a593Smuzhiyun
91*4882a593Smuzhiyun** Prefer multi-line syntax.
92*4882a593Smuzhiyun+
93*4882a593SmuzhiyunYES:
94*4882a593Smuzhiyun+
95*4882a593Smuzhiyun---------------------
96*4882a593Smuzhiyunifeq ($(BR2_PACKAGE_PYTHON),y)
97*4882a593SmuzhiyunLIBFOO_CONF_OPTS += --with-python-support
98*4882a593SmuzhiyunLIBFOO_DEPENDENCIES += python
99*4882a593Smuzhiyunelse
100*4882a593SmuzhiyunLIBFOO_CONF_OPTS += --without-python-support
101*4882a593Smuzhiyunendif
102*4882a593Smuzhiyun---------------------
103*4882a593Smuzhiyun+
104*4882a593SmuzhiyunNO:
105*4882a593Smuzhiyun+
106*4882a593Smuzhiyun---------------------
107*4882a593SmuzhiyunLIBFOO_CONF_OPTS += --with$(if $(BR2_PACKAGE_PYTHON),,out)-python-support
108*4882a593SmuzhiyunLIBFOO_DEPENDENCIES += $(if $(BR2_PACKAGE_PYTHON),python,)
109*4882a593Smuzhiyun---------------------
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun** Keep configure options and dependencies close together.
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun* Optional hooks: keep hook definition and assignment together in one
114*4882a593Smuzhiyun  if block.
115*4882a593Smuzhiyun+
116*4882a593SmuzhiyunYES:
117*4882a593Smuzhiyun+
118*4882a593Smuzhiyun---------------------
119*4882a593Smuzhiyunifneq ($(BR2_LIBFOO_INSTALL_DATA),y)
120*4882a593Smuzhiyundefine LIBFOO_REMOVE_DATA
121*4882a593Smuzhiyun	$(RM) -fr $(TARGET_DIR)/usr/share/libfoo/data
122*4882a593Smuzhiyunendef
123*4882a593SmuzhiyunLIBFOO_POST_INSTALL_TARGET_HOOKS += LIBFOO_REMOVE_DATA
124*4882a593Smuzhiyunendif
125*4882a593Smuzhiyun---------------------
126*4882a593Smuzhiyun+
127*4882a593SmuzhiyunNO:
128*4882a593Smuzhiyun+
129*4882a593Smuzhiyun---------------------
130*4882a593Smuzhiyundefine LIBFOO_REMOVE_DATA
131*4882a593Smuzhiyun	$(RM) -fr $(TARGET_DIR)/usr/share/libfoo/data
132*4882a593Smuzhiyunendef
133*4882a593Smuzhiyun
134*4882a593Smuzhiyunifneq ($(BR2_LIBFOO_INSTALL_DATA),y)
135*4882a593SmuzhiyunLIBFOO_POST_INSTALL_TARGET_HOOKS += LIBFOO_REMOVE_DATA
136*4882a593Smuzhiyunendif
137*4882a593Smuzhiyun---------------------
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun[[writing-genimage-cfg]]
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun=== The +genimage.cfg+ file
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun+genimage.cfg+ files contain the output image layout that genimage utility
144*4882a593Smuzhiyunuses to create final .img file.
145*4882a593Smuzhiyun
146*4882a593SmuzhiyunAn example follows:
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun---------------------
149*4882a593Smuzhiyunimage efi-part.vfat {
150*4882a593Smuzhiyun	vfat {
151*4882a593Smuzhiyun		file EFI {
152*4882a593Smuzhiyun			image = "efi-part/EFI"
153*4882a593Smuzhiyun		}
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun		file Image {
156*4882a593Smuzhiyun			image = "Image"
157*4882a593Smuzhiyun		}
158*4882a593Smuzhiyun	}
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun	size = 32M
161*4882a593Smuzhiyun}
162*4882a593Smuzhiyun
163*4882a593Smuzhiyunimage sdimage.img {
164*4882a593Smuzhiyun	hdimage {
165*4882a593Smuzhiyun	}
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun	partition u-boot {
168*4882a593Smuzhiyun		image = "efi-part.vfat"
169*4882a593Smuzhiyun		offset = 8K
170*4882a593Smuzhiyun	}
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun	partition root {
173*4882a593Smuzhiyun		image = "rootfs.ext2"
174*4882a593Smuzhiyun		size = 512M
175*4882a593Smuzhiyun	}
176*4882a593Smuzhiyun}
177*4882a593Smuzhiyun---------------------
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun* Every +section+(i.e. hdimage, vfat etc.), +partition+ must be indented
180*4882a593Smuzhiyun  with one tab.
181*4882a593Smuzhiyun
182*4882a593Smuzhiyun* Every +file+ or other +subnode+ must be indented with two tabs.
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun* Every node(+section+, +partition+, +file+, +subnode+) must have an open
185*4882a593Smuzhiyun  curly bracket on the same line of the node's name, while the closing one
186*4882a593Smuzhiyun  must be on a newline and after it a newline must be added except for the
187*4882a593Smuzhiyun  last one node. Same goes for its option, for example option +size = +.
188*4882a593Smuzhiyun
189*4882a593Smuzhiyun* Every +option+(i.e. +image+, +offset+, +size+) must have the +=+
190*4882a593Smuzhiyun  assignment one space from it and one space from the value specified.
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun* Filename must at least begin with genimage prefix and have the .cfg
193*4882a593Smuzhiyun  extension to be easy to recognize.
194*4882a593Smuzhiyun
195*4882a593SmuzhiyunThe +genimage.cfg+ files are the input for the genimage tool used in
196*4882a593SmuzhiyunBuildroot to generate the final image file(i.e. sdcard.img). For further
197*4882a593Smuzhiyundetails about the _genimage_ language, refer to
198*4882a593Smuzhiyunhttps://github.com/pengutronix/genimage/blob/master/README.rst[].
199*4882a593Smuzhiyun
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun=== The documentation
202*4882a593Smuzhiyun
203*4882a593SmuzhiyunThe documentation uses the
204*4882a593Smuzhiyunhttp://www.methods.co.nz/asciidoc/[asciidoc] format.
205*4882a593Smuzhiyun
206*4882a593SmuzhiyunFor further details about the asciidoc syntax, refer to
207*4882a593Smuzhiyunhttp://www.methods.co.nz/asciidoc/userguide.html[].
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun=== Support scripts
210*4882a593Smuzhiyun
211*4882a593SmuzhiyunSome scripts in the +support/+ and +utils/+ directories are written in
212*4882a593SmuzhiyunPython and should follow the
213*4882a593Smuzhiyunhttps://www.python.org/dev/peps/pep-0008/[PEP8 Style Guide for Python Code].
214