xref: /OK3568_Linux_fs/buildroot/docs/manual/adding-packages-directory.txt (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun// -*- mode:doc; -*-
2*4882a593Smuzhiyun// vim: set syntax=asciidoc:
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun=== Package directory
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunFirst of all, create a directory under the +package+ directory for
7*4882a593Smuzhiyunyour software, for example +libfoo+.
8*4882a593Smuzhiyun
9*4882a593SmuzhiyunSome packages have been grouped by topic in a sub-directory:
10*4882a593Smuzhiyun+x11r7+, +qt5+ and +gstreamer+. If your package fits in
11*4882a593Smuzhiyunone of these categories, then create your package directory in these.
12*4882a593SmuzhiyunNew subdirectories are discouraged, however.
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun=== Config files
15*4882a593Smuzhiyun
16*4882a593SmuzhiyunFor the package to be displayed in the configuration tool, you need to
17*4882a593Smuzhiyuncreate a Config file in your package directory. There are two types:
18*4882a593Smuzhiyun+Config.in+ and +Config.in.host+.
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun==== +Config.in+ file
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunFor packages used on the target, create a file named +Config.in+. This
23*4882a593Smuzhiyunfile will contain the option descriptions related to our +libfoo+ software
24*4882a593Smuzhiyunthat will be used and displayed in the configuration tool. It should basically
25*4882a593Smuzhiyuncontain:
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun---------------------------
28*4882a593Smuzhiyunconfig BR2_PACKAGE_LIBFOO
29*4882a593Smuzhiyun	bool "libfoo"
30*4882a593Smuzhiyun	help
31*4882a593Smuzhiyun	  This is a comment that explains what libfoo is. The help text
32*4882a593Smuzhiyun	  should be wrapped.
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun	  http://foosoftware.org/libfoo/
35*4882a593Smuzhiyun---------------------------
36*4882a593Smuzhiyun
37*4882a593SmuzhiyunThe +bool+ line, +help+ line and other metadata information about the
38*4882a593Smuzhiyunconfiguration option must be indented with one tab. The help text
39*4882a593Smuzhiyunitself should be indented with one tab and two spaces, lines should
40*4882a593Smuzhiyunbe wrapped to fit 72 columns, where tab counts for 8, so 62 characters
41*4882a593Smuzhiyunin the text itself. The help text must mention the upstream URL of the
42*4882a593Smuzhiyunproject after an empty line.
43*4882a593Smuzhiyun
44*4882a593SmuzhiyunAs a convention specific to Buildroot, the ordering of the attributes
45*4882a593Smuzhiyunis as follows:
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun1. The type of option: +bool+, +string+... with the prompt
48*4882a593Smuzhiyun2. If needed, the +default+ value(s)
49*4882a593Smuzhiyun3. Any dependencies on the target in +depends on+ form
50*4882a593Smuzhiyun4. Any dependencies on the toolchain in +depends on+ form
51*4882a593Smuzhiyun5. Any dependencies on other packages in +depends on+ form
52*4882a593Smuzhiyun6. Any dependency of the +select+ form
53*4882a593Smuzhiyun7. The help keyword and help text.
54*4882a593Smuzhiyun
55*4882a593SmuzhiyunYou can add other sub-options into a +if BR2_PACKAGE_LIBFOO...endif+
56*4882a593Smuzhiyunstatement to configure particular things in your software. You can look at
57*4882a593Smuzhiyunexamples in other packages. The syntax of the +Config.in+ file is the same
58*4882a593Smuzhiyunas the one for the kernel Kconfig file. The documentation for this syntax is
59*4882a593Smuzhiyunavailable at http://kernel.org/doc/Documentation/kbuild/kconfig-language.txt[]
60*4882a593Smuzhiyun
61*4882a593SmuzhiyunFinally you have to add your new +libfoo/Config.in+ to
62*4882a593Smuzhiyun+package/Config.in+ (or in a category subdirectory if you decided to
63*4882a593Smuzhiyunput your package in one of the existing categories). The files
64*4882a593Smuzhiyunincluded there are 'sorted alphabetically' per category and are 'NOT'
65*4882a593Smuzhiyunsupposed to contain anything but the 'bare' name of the package.
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun--------------------------
68*4882a593Smuzhiyunsource "package/libfoo/Config.in"
69*4882a593Smuzhiyun--------------------------
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun==== +Config.in.host+ file
73*4882a593Smuzhiyun
74*4882a593SmuzhiyunSome packages also need to be built for the host system. There are two
75*4882a593Smuzhiyunoptions here:
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun* The host package is only required to satisfy build-time
78*4882a593Smuzhiyun  dependencies of one or more target packages. In this case, add
79*4882a593Smuzhiyun  +host-foo+ to the target package's +BAR_DEPENDENCIES+ variable. No
80*4882a593Smuzhiyun  +Config.in.host+ file should be created.
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun* The host package should be explicitly selectable by the user from
83*4882a593Smuzhiyun  the configuration menu. In this case, create a +Config.in.host+ file
84*4882a593Smuzhiyun  for that host package:
85*4882a593Smuzhiyun+
86*4882a593Smuzhiyun---------------------------
87*4882a593Smuzhiyunconfig BR2_PACKAGE_HOST_FOO
88*4882a593Smuzhiyun	bool "host foo"
89*4882a593Smuzhiyun	help
90*4882a593Smuzhiyun	  This is a comment that explains what foo for the host is.
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun	  http://foosoftware.org/foo/
93*4882a593Smuzhiyun---------------------------
94*4882a593Smuzhiyun+
95*4882a593SmuzhiyunThe same coding style and options as for the +Config.in+ file are valid.
96*4882a593Smuzhiyun+
97*4882a593SmuzhiyunFinally you have to add your new +libfoo/Config.in.host+ to
98*4882a593Smuzhiyun+package/Config.in.host+. The files included there are 'sorted alphabetically'
99*4882a593Smuzhiyunand are 'NOT' supposed to contain anything but the 'bare' name of the package.
100*4882a593Smuzhiyun+
101*4882a593Smuzhiyun--------------------------
102*4882a593Smuzhiyunsource "package/foo/Config.in.host"
103*4882a593Smuzhiyun--------------------------
104*4882a593Smuzhiyun+
105*4882a593SmuzhiyunThe host package will then be available from the +Host utilities+ menu.
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun[[depends-on-vs-select]]
108*4882a593Smuzhiyun==== Choosing +depends on+ or +select+
109*4882a593Smuzhiyun
110*4882a593SmuzhiyunThe +Config.in+ file of your package must also ensure that
111*4882a593Smuzhiyundependencies are enabled. Typically, Buildroot uses the following
112*4882a593Smuzhiyunrules:
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun* Use a +select+ type of dependency for dependencies on
115*4882a593Smuzhiyun  libraries. These dependencies are generally not obvious and it
116*4882a593Smuzhiyun  therefore make sense to have the kconfig system ensure that the
117*4882a593Smuzhiyun  dependencies are selected. For example, the _libgtk2_ package uses
118*4882a593Smuzhiyun  +select BR2_PACKAGE_LIBGLIB2+ to make sure this library is also
119*4882a593Smuzhiyun  enabled.
120*4882a593Smuzhiyun  The +select+ keyword expresses the dependency with a backward
121*4882a593Smuzhiyun  semantic.
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun* Use a +depends on+ type of dependency when the user really needs to
124*4882a593Smuzhiyun  be aware of the dependency. Typically, Buildroot uses this type of
125*4882a593Smuzhiyun  dependency for dependencies on target architecture, MMU support and
126*4882a593Smuzhiyun  toolchain options (see xref:dependencies-target-toolchain-options[]),
127*4882a593Smuzhiyun  or for dependencies on "big" things, such as the X.org system.
128*4882a593Smuzhiyun  The +depends on+ keyword expresses the dependency with a forward
129*4882a593Smuzhiyun  semantic.
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun.Note
132*4882a593SmuzhiyunThe current problem with the _kconfig_ language is that these two
133*4882a593Smuzhiyundependency semantics are not internally linked. Therefore, it may be
134*4882a593Smuzhiyunpossible to select a package, whom one of its dependencies/requirement
135*4882a593Smuzhiyunis not met.
136*4882a593Smuzhiyun
137*4882a593SmuzhiyunAn example illustrates both the usage of +select+ and +depends on+.
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun--------------------------
140*4882a593Smuzhiyunconfig BR2_PACKAGE_RRDTOOL
141*4882a593Smuzhiyun	bool "rrdtool"
142*4882a593Smuzhiyun	depends on BR2_USE_WCHAR
143*4882a593Smuzhiyun	select BR2_PACKAGE_FREETYPE
144*4882a593Smuzhiyun	select BR2_PACKAGE_LIBART
145*4882a593Smuzhiyun	select BR2_PACKAGE_LIBPNG
146*4882a593Smuzhiyun	select BR2_PACKAGE_ZLIB
147*4882a593Smuzhiyun        help
148*4882a593Smuzhiyun	  RRDtool is the OpenSource industry standard, high performance
149*4882a593Smuzhiyun	  data logging and graphing system for time series data.
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun	  http://oss.oetiker.ch/rrdtool/
152*4882a593Smuzhiyun
153*4882a593Smuzhiyuncomment "rrdtool needs a toolchain w/ wchar"
154*4882a593Smuzhiyun	depends on !BR2_USE_WCHAR
155*4882a593Smuzhiyun--------------------------
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun
158*4882a593SmuzhiyunNote that these two dependency types are only transitive with the
159*4882a593Smuzhiyundependencies of the same kind.
160*4882a593Smuzhiyun
161*4882a593SmuzhiyunThis means, in the following example:
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun--------------------------
164*4882a593Smuzhiyunconfig BR2_PACKAGE_A
165*4882a593Smuzhiyun        bool "Package A"
166*4882a593Smuzhiyun
167*4882a593Smuzhiyunconfig BR2_PACKAGE_B
168*4882a593Smuzhiyun        bool "Package B"
169*4882a593Smuzhiyun        depends on BR2_PACKAGE_A
170*4882a593Smuzhiyun
171*4882a593Smuzhiyunconfig BR2_PACKAGE_C
172*4882a593Smuzhiyun        bool "Package C"
173*4882a593Smuzhiyun        depends on BR2_PACKAGE_B
174*4882a593Smuzhiyun
175*4882a593Smuzhiyunconfig BR2_PACKAGE_D
176*4882a593Smuzhiyun        bool "Package D"
177*4882a593Smuzhiyun        select BR2_PACKAGE_B
178*4882a593Smuzhiyun
179*4882a593Smuzhiyunconfig BR2_PACKAGE_E
180*4882a593Smuzhiyun        bool "Package E"
181*4882a593Smuzhiyun        select BR2_PACKAGE_D
182*4882a593Smuzhiyun--------------------------
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun* Selecting +Package C+ will be visible if +Package B+ has been
185*4882a593Smuzhiyun  selected, which in turn is only visible if +Package A+ has been
186*4882a593Smuzhiyun  selected.
187*4882a593Smuzhiyun
188*4882a593Smuzhiyun* Selecting +Package E+ will select +Package D+, which will select
189*4882a593Smuzhiyun  +Package B+, it will not check for the dependencies of +Package B+,
190*4882a593Smuzhiyun  so it will not select +Package A+.
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun* Since +Package B+ is selected but +Package A+ is not, this violates
193*4882a593Smuzhiyun  the dependency of +Package B+ on +Package A+. Therefore, in such a
194*4882a593Smuzhiyun  situation, the transitive dependency has to be added explicitly:
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun--------------------------
197*4882a593Smuzhiyunconfig BR2_PACKAGE_D
198*4882a593Smuzhiyun	bool "Package D"
199*4882a593Smuzhiyun	select BR2_PACKAGE_B
200*4882a593Smuzhiyun	depends on BR2_PACKAGE_A
201*4882a593Smuzhiyun
202*4882a593Smuzhiyunconfig BR2_PACKAGE_E
203*4882a593Smuzhiyun	bool "Package E"
204*4882a593Smuzhiyun	select BR2_PACKAGE_D
205*4882a593Smuzhiyun	depends on BR2_PACKAGE_A
206*4882a593Smuzhiyun--------------------------
207*4882a593Smuzhiyun
208*4882a593SmuzhiyunOverall, for package library dependencies, +select+ should be
209*4882a593Smuzhiyunpreferred.
210*4882a593Smuzhiyun
211*4882a593SmuzhiyunNote that such dependencies will ensure that the dependency option
212*4882a593Smuzhiyunis also enabled, but not necessarily built before your package. To do
213*4882a593Smuzhiyunso, the dependency also needs to be expressed in the +.mk+ file of the
214*4882a593Smuzhiyunpackage.
215*4882a593Smuzhiyun
216*4882a593SmuzhiyunFurther formatting details: see xref:writing-rules-config-in[the
217*4882a593Smuzhiyuncoding style].
218*4882a593Smuzhiyun
219*4882a593Smuzhiyun[[dependencies-target-toolchain-options]]
220*4882a593Smuzhiyun==== Dependencies on target and toolchain options
221*4882a593Smuzhiyun
222*4882a593SmuzhiyunMany packages depend on certain options of the toolchain: the choice of
223*4882a593SmuzhiyunC library, C++ support, thread support, RPC support, wchar support,
224*4882a593Smuzhiyunor dynamic library support. Some packages can only be built on certain
225*4882a593Smuzhiyuntarget architectures, or if an MMU is available in the processor.
226*4882a593Smuzhiyun
227*4882a593SmuzhiyunThese dependencies have to be expressed with the appropriate 'depends
228*4882a593Smuzhiyunon' statements in the Config.in file. Additionally, for dependencies on
229*4882a593Smuzhiyuntoolchain options, a +comment+ should be displayed when the option is
230*4882a593Smuzhiyunnot enabled, so that the user knows why the package is not available.
231*4882a593SmuzhiyunDependencies on target architecture or MMU support should not be
232*4882a593Smuzhiyunmade visible in a comment: since it is unlikely that the user can
233*4882a593Smuzhiyunfreely choose another target, it makes little sense to show these
234*4882a593Smuzhiyundependencies explicitly.
235*4882a593Smuzhiyun
236*4882a593SmuzhiyunThe +comment+ should only be visible if the +config+ option itself would
237*4882a593Smuzhiyunbe visible when the toolchain option dependencies are met. This means
238*4882a593Smuzhiyunthat all other dependencies of the package (including dependencies on
239*4882a593Smuzhiyuntarget architecture and MMU support) have to be repeated on the
240*4882a593Smuzhiyun+comment+ definition. To keep it clear, the +depends on+ statement for
241*4882a593Smuzhiyunthese non-toolchain option should be kept separate from the +depends on+
242*4882a593Smuzhiyunstatement for the toolchain options.
243*4882a593SmuzhiyunIf there is a dependency on a config option in that same file (typically
244*4882a593Smuzhiyunthe main package) it is preferable to have a global +if ... endif+
245*4882a593Smuzhiyunconstruct rather than repeating the +depends on+ statement on the
246*4882a593Smuzhiyuncomment and other config options.
247*4882a593Smuzhiyun
248*4882a593SmuzhiyunThe general format of a dependency +comment+ for package foo is:
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun--------------------------
251*4882a593Smuzhiyunfoo needs a toolchain w/ featA, featB, featC
252*4882a593Smuzhiyun--------------------------
253*4882a593Smuzhiyun
254*4882a593Smuzhiyunfor example:
255*4882a593Smuzhiyun
256*4882a593Smuzhiyun--------------------------
257*4882a593Smuzhiyunmpd needs a toolchain w/ C++, threads, wchar
258*4882a593Smuzhiyun--------------------------
259*4882a593Smuzhiyun
260*4882a593Smuzhiyunor
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun--------------------------
263*4882a593Smuzhiyuncrda needs a toolchain w/ threads
264*4882a593Smuzhiyun--------------------------
265*4882a593Smuzhiyun
266*4882a593SmuzhiyunNote that this text is kept brief on purpose, so that it will fit on a
267*4882a593Smuzhiyun80-character terminal.
268*4882a593Smuzhiyun
269*4882a593SmuzhiyunThe rest of this section enumerates the different target and toolchain
270*4882a593Smuzhiyunoptions, the corresponding config symbols to depend on, and the text to
271*4882a593Smuzhiyunuse in the comment.
272*4882a593Smuzhiyun
273*4882a593Smuzhiyun* Target architecture
274*4882a593Smuzhiyun** Dependency symbol: +BR2_powerpc+, +BR2_mips+, ... (see +arch/Config.in+)
275*4882a593Smuzhiyun** Comment string: no comment to be added
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun* MMU support
278*4882a593Smuzhiyun** Dependency symbol: +BR2_USE_MMU+
279*4882a593Smuzhiyun** Comment string: no comment to be added
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun* Gcc +__sync_*+ built-ins used for atomic operations. They are
282*4882a593Smuzhiyun  available in variants operating on 1 byte, 2 bytes, 4 bytes and 8
283*4882a593Smuzhiyun  bytes. Since different architectures support atomic operations on
284*4882a593Smuzhiyun  different sizes, one dependency symbol is available for each size:
285*4882a593Smuzhiyun** Dependency symbol: +BR2_TOOLCHAIN_HAS_SYNC_1+ for 1 byte,
286*4882a593Smuzhiyun   +BR2_TOOLCHAIN_HAS_SYNC_2+ for 2 bytes,
287*4882a593Smuzhiyun   +BR2_TOOLCHAIN_HAS_SYNC_4+ for 4 bytes, +BR2_TOOLCHAIN_HAS_SYNC_8+
288*4882a593Smuzhiyun   for 8 bytes.
289*4882a593Smuzhiyun** Comment string: no comment to be added
290*4882a593Smuzhiyun
291*4882a593Smuzhiyun* Gcc +__atomic_*+ built-ins used for atomic operations.
292*4882a593Smuzhiyun** Dependency symbol: +BR2_TOOLCHAIN_HAS_ATOMIC+.
293*4882a593Smuzhiyun** Comment string: no comment to be added
294*4882a593Smuzhiyun
295*4882a593Smuzhiyun* Kernel headers
296*4882a593Smuzhiyun** Dependency symbol: +BR2_TOOLCHAIN_HEADERS_AT_LEAST_X_Y+, (replace
297*4882a593Smuzhiyun   +X_Y+ with the proper version, see +toolchain/Config.in+)
298*4882a593Smuzhiyun** Comment string: +headers >= X.Y+ and/or `headers <= X.Y` (replace
299*4882a593Smuzhiyun   +X.Y+ with the proper version)
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun* GCC version
302*4882a593Smuzhiyun** Dependency symbol: +BR2_TOOLCHAIN_GCC_AT_LEAST_X_Y+, (replace
303*4882a593Smuzhiyun   +X_Y+ with the proper version, see +toolchain/Config.in+)
304*4882a593Smuzhiyun** Comment string: +gcc >= X.Y+ and/or `gcc <= X.Y` (replace
305*4882a593Smuzhiyun   +X.Y+ with the proper version)
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun* Host GCC version
308*4882a593Smuzhiyun** Dependency symbol: +BR2_HOST_GCC_AT_LEAST_X_Y+, (replace
309*4882a593Smuzhiyun   +X_Y+ with the proper version, see +Config.in+)
310*4882a593Smuzhiyun** Comment string: no comment to be added
311*4882a593Smuzhiyun** Note that it is usually not the package itself that has a minimum
312*4882a593Smuzhiyun   host GCC version, but rather a host-package on which it depends.
313*4882a593Smuzhiyun
314*4882a593Smuzhiyun* C library
315*4882a593Smuzhiyun** Dependency symbol: +BR2_TOOLCHAIN_USES_GLIBC+,
316*4882a593Smuzhiyun   +BR2_TOOLCHAIN_USES_MUSL+, +BR2_TOOLCHAIN_USES_UCLIBC+
317*4882a593Smuzhiyun** Comment string: for the C library, a slightly different comment text
318*4882a593Smuzhiyun   is used: +foo needs a glibc toolchain+, or `foo needs a glibc
319*4882a593Smuzhiyun   toolchain w/ C++`
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun* C++ support
322*4882a593Smuzhiyun** Dependency symbol: +BR2_INSTALL_LIBSTDCPP+
323*4882a593Smuzhiyun** Comment string: `C++`
324*4882a593Smuzhiyun
325*4882a593Smuzhiyun* D support
326*4882a593Smuzhiyun** Dependency symbol: +BR2_TOOLCHAIN_HAS_DLANG+
327*4882a593Smuzhiyun** Comment string: `Dlang`
328*4882a593Smuzhiyun
329*4882a593Smuzhiyun* Fortran support
330*4882a593Smuzhiyun** Dependency symbol: +BR2_TOOLCHAIN_HAS_FORTRAN+
331*4882a593Smuzhiyun** Comment string: `fortran`
332*4882a593Smuzhiyun
333*4882a593Smuzhiyun* thread support
334*4882a593Smuzhiyun** Dependency symbol: +BR2_TOOLCHAIN_HAS_THREADS+
335*4882a593Smuzhiyun** Comment string: +threads+ (unless +BR2_TOOLCHAIN_HAS_THREADS_NPTL+
336*4882a593Smuzhiyun   is also needed, in which case, specifying only +NPTL+ is sufficient)
337*4882a593Smuzhiyun
338*4882a593Smuzhiyun* NPTL thread support
339*4882a593Smuzhiyun** Dependency symbol: +BR2_TOOLCHAIN_HAS_THREADS_NPTL+
340*4882a593Smuzhiyun** Comment string: +NPTL+
341*4882a593Smuzhiyun
342*4882a593Smuzhiyun* RPC support
343*4882a593Smuzhiyun** Dependency symbol: +BR2_TOOLCHAIN_HAS_NATIVE_RPC+
344*4882a593Smuzhiyun** Comment string: +RPC+
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun* wchar support
347*4882a593Smuzhiyun** Dependency symbol: +BR2_USE_WCHAR+
348*4882a593Smuzhiyun** Comment string: +wchar+
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun* dynamic library
351*4882a593Smuzhiyun** Dependency symbol: +!BR2_STATIC_LIBS+
352*4882a593Smuzhiyun** Comment string: +dynamic library+
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun==== Dependencies on a Linux kernel built by buildroot
355*4882a593Smuzhiyun
356*4882a593SmuzhiyunSome packages need a Linux kernel to be built by buildroot. These are
357*4882a593Smuzhiyuntypically kernel modules or firmware. A comment should be added in the
358*4882a593SmuzhiyunConfig.in file to express this dependency, similar to dependencies on
359*4882a593Smuzhiyuntoolchain options. The general format is:
360*4882a593Smuzhiyun
361*4882a593Smuzhiyun--------------------------
362*4882a593Smuzhiyunfoo needs a Linux kernel to be built
363*4882a593Smuzhiyun--------------------------
364*4882a593Smuzhiyun
365*4882a593SmuzhiyunIf there is a dependency on both toolchain options and the Linux
366*4882a593Smuzhiyunkernel, use this format:
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun--------------------------
369*4882a593Smuzhiyunfoo needs a toolchain w/ featA, featB, featC and a Linux kernel to be built
370*4882a593Smuzhiyun--------------------------
371*4882a593Smuzhiyun
372*4882a593Smuzhiyun==== Dependencies on udev /dev management
373*4882a593Smuzhiyun
374*4882a593SmuzhiyunIf a package needs udev /dev management, it should depend on symbol
375*4882a593Smuzhiyun+BR2_PACKAGE_HAS_UDEV+, and the following comment should be added:
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun--------------------------
378*4882a593Smuzhiyunfoo needs udev /dev management
379*4882a593Smuzhiyun--------------------------
380*4882a593Smuzhiyun
381*4882a593SmuzhiyunIf there is a dependency on both toolchain options and udev /dev
382*4882a593Smuzhiyunmanagement, use this format:
383*4882a593Smuzhiyun
384*4882a593Smuzhiyun--------------------------
385*4882a593Smuzhiyunfoo needs udev /dev management and a toolchain w/ featA, featB, featC
386*4882a593Smuzhiyun--------------------------
387*4882a593Smuzhiyun
388*4882a593Smuzhiyun==== Dependencies on features provided by virtual packages
389*4882a593Smuzhiyun
390*4882a593SmuzhiyunSome features can be provided by more than one package, such as the
391*4882a593SmuzhiyunopenGL libraries.
392*4882a593Smuzhiyun
393*4882a593SmuzhiyunSee xref:virtual-package-tutorial[] for more on the virtual packages.
394*4882a593Smuzhiyun
395*4882a593Smuzhiyun=== The +.mk+ file
396*4882a593Smuzhiyun
397*4882a593Smuzhiyun[[adding-packages-mk]]
398*4882a593Smuzhiyun
399*4882a593SmuzhiyunFinally, here's the hardest part. Create a file named +libfoo.mk+. It
400*4882a593Smuzhiyundescribes how the package should be downloaded, configured, built,
401*4882a593Smuzhiyuninstalled, etc.
402*4882a593Smuzhiyun
403*4882a593SmuzhiyunDepending on the package type, the +.mk+ file must be written in a
404*4882a593Smuzhiyundifferent way, using different infrastructures:
405*4882a593Smuzhiyun
406*4882a593Smuzhiyun* *Makefiles for generic packages* (not using autotools or CMake):
407*4882a593Smuzhiyun  These are based on an infrastructure similar to the one used for
408*4882a593Smuzhiyun  autotools-based packages, but require a little more work from the
409*4882a593Smuzhiyun  developer. They specify what should be done for the configuration,
410*4882a593Smuzhiyun  compilation and installation of the package. This
411*4882a593Smuzhiyun  infrastructure must be used for all packages that do not use the
412*4882a593Smuzhiyun  autotools as their build system. In the future, other specialized
413*4882a593Smuzhiyun  infrastructures might be written for other build systems. We cover
414*4882a593Smuzhiyun  them through in a xref:generic-package-tutorial[tutorial] and a
415*4882a593Smuzhiyun  xref:generic-package-reference[reference].
416*4882a593Smuzhiyun
417*4882a593Smuzhiyun* *Makefiles for autotools-based software* (autoconf, automake, etc.):
418*4882a593Smuzhiyun  We provide a dedicated infrastructure for such packages, since
419*4882a593Smuzhiyun  autotools is a very common build system. This infrastructure 'must'
420*4882a593Smuzhiyun  be used for new packages that rely on the autotools as their build
421*4882a593Smuzhiyun  system. We cover them through a xref:autotools-package-tutorial[tutorial]
422*4882a593Smuzhiyun  and xref:autotools-package-reference[reference].
423*4882a593Smuzhiyun
424*4882a593Smuzhiyun* *Makefiles for cmake-based software*: We provide a dedicated
425*4882a593Smuzhiyun   infrastructure for such packages, as CMake is a more and more
426*4882a593Smuzhiyun   commonly used build system and has a standardized behaviour. This
427*4882a593Smuzhiyun   infrastructure 'must' be used for new packages that rely on
428*4882a593Smuzhiyun   CMake. We cover them through a xref:cmake-package-tutorial[tutorial]
429*4882a593Smuzhiyun   and xref:cmake-package-reference[reference].
430*4882a593Smuzhiyun
431*4882a593Smuzhiyun* *Makefiles for Python modules*: We have a dedicated infrastructure
432*4882a593Smuzhiyun   for Python modules that use either the +distutils+ or the
433*4882a593Smuzhiyun   +setuptools+ mechanism. We cover them through a
434*4882a593Smuzhiyun   xref:python-package-tutorial[tutorial] and a
435*4882a593Smuzhiyun   xref:python-package-reference[reference].
436*4882a593Smuzhiyun
437*4882a593Smuzhiyun* *Makefiles for Lua modules*: We have a dedicated infrastructure for
438*4882a593Smuzhiyun   Lua modules available through the LuaRocks web site. We cover them
439*4882a593Smuzhiyun   through a xref:luarocks-package-tutorial[tutorial] and a
440*4882a593Smuzhiyun   xref:luarocks-package-reference[reference].
441*4882a593Smuzhiyun
442*4882a593SmuzhiyunFurther formatting details: see xref:writing-rules-mk[the writing
443*4882a593Smuzhiyunrules].
444*4882a593Smuzhiyun
445*4882a593Smuzhiyun[[adding-packages-hash]]
446*4882a593Smuzhiyun=== The +.hash+ file
447*4882a593Smuzhiyun
448*4882a593SmuzhiyunWhen possible, you must add a third file, named +libfoo.hash+, that
449*4882a593Smuzhiyuncontains the hashes of the downloaded files for the +libfoo+
450*4882a593Smuzhiyunpackage. The only reason for not adding a +.hash+ file is when hash
451*4882a593Smuzhiyunchecking is not possible due to how the package is downloaded.
452*4882a593Smuzhiyun
453*4882a593SmuzhiyunWhen a package has a version selection choice, then the hash file may be
454*4882a593Smuzhiyunstored in a subdirectory named after the version, e.g.
455*4882a593Smuzhiyun+package/libfoo/1.2.3/libfoo.hash+. This is especially important if the
456*4882a593Smuzhiyundifferent versions have different licensing terms, but they are stored
457*4882a593Smuzhiyunin the same file. Otherwise, the hash file should stay in the package's
458*4882a593Smuzhiyundirectory.
459*4882a593Smuzhiyun
460*4882a593SmuzhiyunThe hashes stored in that file are used to validate the integrity of the
461*4882a593Smuzhiyundownloaded files and of the license files.
462*4882a593Smuzhiyun
463*4882a593SmuzhiyunThe format of this file is one line for each file for which to check the
464*4882a593Smuzhiyunhash, each line with the following three fields separated by two spaces:
465*4882a593Smuzhiyun
466*4882a593Smuzhiyun* the type of hash, one of:
467*4882a593Smuzhiyun** +md5+, +sha1+, +sha224+, +sha256+, +sha384+, +sha512+, +none+
468*4882a593Smuzhiyun* the hash of the file:
469*4882a593Smuzhiyun** for +none+, one or more non-space chars, usually just the string +xxx+
470*4882a593Smuzhiyun** for +md5+, 32 hexadecimal characters
471*4882a593Smuzhiyun** for +sha1+, 40 hexadecimal characters
472*4882a593Smuzhiyun** for +sha224+, 56 hexadecimal characters
473*4882a593Smuzhiyun** for +sha256+, 64 hexadecimal characters
474*4882a593Smuzhiyun** for +sha384+, 96 hexadecimal characters
475*4882a593Smuzhiyun** for +sha512+, 128 hexadecimal characters
476*4882a593Smuzhiyun* the name of the file:
477*4882a593Smuzhiyun** for a source archive: the basename of the file, without any directory
478*4882a593Smuzhiyun   component,
479*4882a593Smuzhiyun** for a license file: the path as it appears in +FOO_LICENSE_FILES+.
480*4882a593Smuzhiyun
481*4882a593SmuzhiyunLines starting with a +#+ sign are considered comments, and ignored. Empty
482*4882a593Smuzhiyunlines are ignored.
483*4882a593Smuzhiyun
484*4882a593SmuzhiyunThere can be more than one hash for a single file, each on its own line. In
485*4882a593Smuzhiyunthis case, all hashes must match.
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun.Note
488*4882a593SmuzhiyunIdeally, the hashes stored in this file should match the hashes published by
489*4882a593Smuzhiyunupstream, e.g. on their website, in the e-mail announcement... If upstream
490*4882a593Smuzhiyunprovides more than one type of hash (e.g. +sha1+ and +sha512+), then it is
491*4882a593Smuzhiyunbest to add all those hashes in the +.hash+ file. If upstream does not
492*4882a593Smuzhiyunprovide any hash, or only provides an +md5+ hash, then compute at least one
493*4882a593Smuzhiyunstrong hash yourself (preferably +sha256+, but not +md5+), and mention
494*4882a593Smuzhiyunthis in a comment line above the hashes.
495*4882a593Smuzhiyun
496*4882a593Smuzhiyun.Note
497*4882a593SmuzhiyunThe hashes for license files are used to detect a license change when a
498*4882a593Smuzhiyunpackage version is bumped. The hashes are checked during the make legal-info
499*4882a593Smuzhiyuntarget run. For a package with multiple versions (like Qt5),
500*4882a593Smuzhiyuncreate the hash file in a subdirectory +<packageversion>+ of that package
501*4882a593Smuzhiyun(see also xref:patch-apply-order[]).
502*4882a593Smuzhiyun
503*4882a593SmuzhiyunThe +none+ hash type is reserved to those archives downloaded from a
504*4882a593Smuzhiyunrepository, like a 'git clone', a 'subversion checkout'...
505*4882a593Smuzhiyun
506*4882a593SmuzhiyunThe example below defines a +sha1+ and a +sha256+ published by upstream for
507*4882a593Smuzhiyunthe main +libfoo-1.2.3.tar.bz2+ tarball, an +md5+ from upstream and a
508*4882a593Smuzhiyunlocally-computed +sha256+ hashes for a binary blob, a +sha256+ for a
509*4882a593Smuzhiyundownloaded patch, and an archive with no hash:
510*4882a593Smuzhiyun
511*4882a593Smuzhiyun----
512*4882a593Smuzhiyun# Hashes from: http://www.foosoftware.org/download/libfoo-1.2.3.tar.bz2.{sha1,sha256}:
513*4882a593Smuzhiyunsha1  486fb55c3efa71148fe07895fd713ea3a5ae343a  libfoo-1.2.3.tar.bz2
514*4882a593Smuzhiyunsha256  efc8103cc3bcb06bda6a781532d12701eb081ad83e8f90004b39ab81b65d4369  libfoo-1.2.3.tar.bz2
515*4882a593Smuzhiyun
516*4882a593Smuzhiyun# md5 from: http://www.foosoftware.org/download/libfoo-1.2.3.tar.bz2.md5, sha256 locally computed:
517*4882a593Smuzhiyunmd5  2d608f3c318c6b7557d551a5a09314f03452f1a1  libfoo-data.bin
518*4882a593Smuzhiyunsha256  01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b  libfoo-data.bin
519*4882a593Smuzhiyun
520*4882a593Smuzhiyun# Locally computed:
521*4882a593Smuzhiyunsha256  ff52101fb90bbfc3fe9475e425688c660f46216d7e751c4bbdb1dc85cdccacb9  libfoo-fix-blabla.patch
522*4882a593Smuzhiyun
523*4882a593Smuzhiyun# No hash for 1234:
524*4882a593Smuzhiyunnone  xxx  libfoo-1234.tar.gz
525*4882a593Smuzhiyun
526*4882a593Smuzhiyun# Hash for license files:
527*4882a593Smuzhiyunsha256  a45a845012742796534f7e91fe623262ccfb99460a2bd04015bd28d66fba95b8  COPYING
528*4882a593Smuzhiyunsha256  01b1f9f2c8ee648a7a596a1abe8aa4ed7899b1c9e5551bda06da6e422b04aa55  doc/COPYING.LGPL
529*4882a593Smuzhiyun----
530*4882a593Smuzhiyun
531*4882a593SmuzhiyunIf the +.hash+ file is present, and it contains one or more hashes for a
532*4882a593Smuzhiyundownloaded file, the hash(es) computed by Buildroot (after download) must
533*4882a593Smuzhiyunmatch the hash(es) stored in the +.hash+ file. If one or more hashes do
534*4882a593Smuzhiyunnot match, Buildroot considers this an error, deletes the downloaded file,
535*4882a593Smuzhiyunand aborts.
536*4882a593Smuzhiyun
537*4882a593SmuzhiyunIf the +.hash+ file is present, but it does not contain a hash for a
538*4882a593Smuzhiyundownloaded file, Buildroot considers this an error and aborts. However,
539*4882a593Smuzhiyunthe downloaded file is left in the download directory since this
540*4882a593Smuzhiyuntypically indicates that the +.hash+ file is wrong but the downloaded
541*4882a593Smuzhiyunfile is probably OK.
542*4882a593Smuzhiyun
543*4882a593SmuzhiyunHashes are currently checked for files fetched from http/ftp servers,
544*4882a593SmuzhiyunGit repositories, files copied using scp and local files. Hashes are
545*4882a593Smuzhiyunnot checked for other version control systems (such as Subversion,
546*4882a593SmuzhiyunCVS, etc.) because Buildroot currently does not generate reproducible
547*4882a593Smuzhiyuntarballs when source code is fetched from such version control
548*4882a593Smuzhiyunsystems.
549*4882a593Smuzhiyun
550*4882a593SmuzhiyunHashes should only be added in +.hash+ files for files that are
551*4882a593Smuzhiyunguaranteed to be stable. For example, patches auto-generated by Github
552*4882a593Smuzhiyunare not guaranteed to be stable, and therefore their hashes can change
553*4882a593Smuzhiyunover time. Such patches should not be downloaded, and instead be added
554*4882a593Smuzhiyunlocally to the package folder.
555*4882a593Smuzhiyun
556*4882a593SmuzhiyunIf the +.hash+ file is missing, then no check is done at all.
557