adding-packages-generic.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. Infrastructure for packages with specific build systems
  2. -------------------------------------------------------
  3. By 'packages with specific build systems' we mean all the packages
  4. whose build system is not one of the standard ones, such as
  5. 'autotools' or 'CMake'. This typically includes packages whose build
  6. system is based on hand-written Makefiles or shell scripts.
  7. [[generic-package-tutorial]]
  8. +generic-package+ Tutorial
  9. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  10. ------------------------------
  11. 01: #############################################################
  12. 02: #
  13. 03: # libfoo
  14. 04: #
  15. 05: #############################################################
  16. 06: LIBFOO_VERSION = 1.0
  17. 07: LIBFOO_SOURCE = libfoo-$(LIBFOO_VERSION).tar.gz
  18. 08: LIBFOO_SITE = http://www.foosoftware.org/download
  19. 09: LIBFOO_INSTALL_STAGING = YES
  20. 10: LIBFOO_DEPENDENCIES = host-libaaa libbbb
  21. 11:
  22. 12: define LIBFOO_BUILD_CMDS
  23. 13: $(MAKE) CC="$(TARGET_CC)" LD="$(TARGET_LD)" -C $(@D) all
  24. 14: endef
  25. 15:
  26. 16: define LIBFOO_INSTALL_STAGING_CMDS
  27. 17: $(INSTALL) -D -m 0755 $(@D)/libfoo.a $(STAGING_DIR)/usr/lib/libfoo.a
  28. 18: $(INSTALL) -D -m 0644 $(@D)/foo.h $(STAGING_DIR)/usr/include/foo.h
  29. 19: $(INSTALL) -D -m 0755 $(@D)/libfoo.so* $(STAGING_DIR)/usr/lib
  30. 20: endef
  31. 21:
  32. 22: define LIBFOO_INSTALL_TARGET_CMDS
  33. 23: $(INSTALL) -D -m 0755 $(@D)/libfoo.so* $(TARGET_DIR)/usr/lib
  34. 24: $(INSTALL) -d -m 0755 $(TARGET_DIR)/etc/foo.d
  35. 25: endef
  36. 26:
  37. 27: define LIBFOO_DEVICES
  38. 28: /dev/foo c 666 0 0 42 0 - - -
  39. 29: endef
  40. 30:
  41. 31: define LIBFOO_PERMISSIONS
  42. 32: /bin/foo f 4755 0 0 - - - - -
  43. 33: endef
  44. 34:
  45. 35: $(eval $(generic-package))
  46. --------------------------------
  47. The Makefile begins on line 6 to 8 with metadata information: the
  48. version of the package (+LIBFOO_VERSION+), the name of the
  49. tarball containing the package (+LIBFOO_SOURCE+) and the
  50. Internet location at which the tarball can be downloaded
  51. (+LIBFOO_SITE+). All variables must start with the same prefix,
  52. +LIBFOO_+ in this case. This prefix is always the uppercased
  53. version of the package name (see below to understand where the package
  54. name is defined).
  55. On line 9, we specify that this package wants to install something to
  56. the staging space. This is often needed for libraries, since they must
  57. install header files and other development files in the staging space.
  58. This will ensure that the commands listed in the
  59. +LIBFOO_INSTALL_STAGING_CMDS+ variable will be executed.
  60. On line 10, we specify the list of dependencies this package relies
  61. on. These dependencies are listed in terms of lower-case package names,
  62. which can be packages for the target (without the +host-+
  63. prefix) or packages for the host (with the +host-+) prefix).
  64. Buildroot will ensure that all these packages are built and installed
  65. 'before' the current package starts its configuration.
  66. The rest of the Makefile defines what should be done at the different
  67. steps of the package configuration, compilation and installation.
  68. +LIBFOO_BUILD_CMDS+ tells what steps should be performed to
  69. build the package. +LIBFOO_INSTALL_STAGING_CMDS+ tells what
  70. steps should be performed to install the package in the staging space.
  71. +LIBFOO_INSTALL_TARGET_CMDS+ tells what steps should be
  72. performed to install the package in the target space.
  73. All these steps rely on the +$(@D)+ variable, which
  74. contains the directory where the source code of the package has been
  75. extracted.
  76. Finally, on line 35, we call the +generic-package+ which
  77. generates, according to the variables defined previously, all the
  78. Makefile code necessary to make your package working.
  79. [[generic-package-reference]]
  80. +generic-package+ Reference
  81. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  82. There are two variants of the generic target. The +generic-package+ macro is
  83. used for packages to be cross-compiled for the target. The
  84. +host-generic-package+ macro is used for host packages, natively compiled
  85. for the host. It is possible to call both of them in a single +.mk+
  86. file: once to create the rules to generate a target
  87. package and once to create the rules to generate a host package:
  88. ----------------------
  89. $(eval $(generic-package))
  90. $(eval $(host-generic-package))
  91. ----------------------
  92. This might be useful if the compilation of the target package requires
  93. some tools to be installed on the host. If the package name is
  94. +libfoo+, then the name of the package for the target is also
  95. +libfoo+, while the name of the package for the host is
  96. +host-libfoo+. These names should be used in the DEPENDENCIES
  97. variables of other packages, if they depend on +libfoo+ or
  98. +host-libfoo+.
  99. The call to the +generic-package+ and/or +host-generic-package+ macro *must* be
  100. at the end of the +.mk+ file, after all variable definitions.
  101. For the target package, the +generic-package+ uses the variables defined by
  102. the .mk file and prefixed by the uppercased package name:
  103. +LIBFOO_*+. +host-generic-package+ uses the +HOST_LIBFOO_*+ variables. For
  104. 'some' variables, if the +HOST_LIBFOO_+ prefixed variable doesn't
  105. exist, the package infrastructure uses the corresponding variable
  106. prefixed by +LIBFOO_+. This is done for variables that are likely to
  107. have the same value for both the target and host packages. See below
  108. for details.
  109. The list of variables that can be set in a +.mk+ file to give metadata
  110. information is (assuming the package name is +libfoo+) :
  111. * +LIBFOO_VERSION+, mandatory, must contain the version of the
  112. package. Note that if +HOST_LIBFOO_VERSION+ doesn't exist, it is
  113. assumed to be the same as +LIBFOO_VERSION+. It can also be a
  114. revision number, branch or tag for packages that are fetched
  115. directly from their revision control system. +
  116. Examples: +
  117. +LIBFOO_VERSION = 0.1.2+ +
  118. +LIBFOO_VERSION = cb9d6aa9429e838f0e54faa3d455bcbab5eef057+ +
  119. +LIBFOO_VERSION = stable+
  120. * +LIBFOO_SOURCE+ may contain the name of the tarball of
  121. the package. If +HOST_LIBFOO_SOURCE+ is not specified, it
  122. defaults to +LIBFOO_SOURCE+. If none are specified, then
  123. the value is assumed to be
  124. +packagename-$(LIBFOO_VERSION).tar.gz+. +
  125. Example: +LIBFOO_SOURCE = foobar-$(LIBFOO_VERSION).tar.bz2+
  126. * +LIBFOO_PATCH+ may contain the name of a patch, that will be
  127. downloaded from the same location as the tarball indicated in
  128. +LIBFOO_SOURCE+. If +HOST_LIBFOO_PATCH+ is not specified, it
  129. defaults to +LIBFOO_PATCH+. Also note that another mechanism is
  130. available to patch a package: all files of the form
  131. +packagename-packageversion-description.patch+ present in the
  132. package directory inside Buildroot will be applied to the package
  133. after extraction.
  134. * +LIBFOO_SITE+ provides the location of the package, which can be a
  135. URL or a local filesystem path. HTTP, FTP and SCP are supported URL
  136. types for retrieving package tarballs. Git, Subversion, Mercurial,
  137. and Bazaar are supported URL types for retrieving packages directly
  138. from source code management systems. A filesystem path may be used
  139. to specify either a tarball or a directory containing the package
  140. source code. See +LIBFOO_SITE_METHOD+ below for more details on how
  141. retrieval works. +
  142. Note that SCP URLs should be of the form
  143. +scp://[user@]host:filepath+, and that filepath is relative to the
  144. user's home directory, so you may want to prepend the path with a
  145. slash for absolute paths:
  146. +scp://[user@]host:/absolutepath+. +
  147. If +HOST_LIBFOO_SITE+ is not specified, it defaults to
  148. +LIBFOO_SITE+. If none are specified, then the location is assumed
  149. to be
  150. +http://$$(BR2_SOURCEFORGE_MIRROR).dl.sourceforge.net/sourceforge/packagename+. +
  151. Examples: +
  152. +LIBFOO_SITE=http://www.libfoosoftware.org/libfoo+ +
  153. +LIBFOO_SITE=http://svn.xiph.org/trunk/Tremor/+ +
  154. +LIBFOO_SITE=git://github.com/kergoth/tslib.git+
  155. +LIBFOO_SITE=/opt/software/libfoo.tar.gz+
  156. +LIBFOO_SITE=$(TOPDIR)/../src/libfoo/+
  157. * +LIBFOO_SITE_METHOD+ determines the method used to fetch or copy the
  158. package source code. In many cases, Buildroot guesses the method
  159. from the contents of +LIBFOO_SITE+ and setting +LIBFOO_SITE_METHOD+
  160. is unnecessary. When +HOST_LIBFOO_SITE_METHOD+ is not specified, it
  161. defaults to the value of +LIBFOO_SITE_METHOD+. +
  162. The possible values of +LIBFOO_SITE_METHOD+ are:
  163. ** +wget+ for normal FTP/HTTP downloads of tarballs. Used by
  164. default when +LIBFOO_SITE+ begins with +http://+, +https://+ or
  165. +ftp://+.
  166. ** +scp+ for downloads of tarballs over SSH with scp. Used by
  167. default when +LIBFOO_SITE+ begins with +scp://+.
  168. ** +svn+ for retrieving source code from a Subversion repository.
  169. Used by default when +LIBFOO_SITE+ begins with +svn://+. When a
  170. +http://+ Subversion repository URL is specified in
  171. +LIBFOO_SITE+, one 'must' specify +LIBFOO_SITE_METHOD=svn+.
  172. Buildroot performs a checkout which is preserved as a tarball in
  173. the download cache; subsequent builds use the tarball instead of
  174. performing another checkout.
  175. ** +git+ for retrieving source code from a Git repository. Used by
  176. default when +LIBFOO_SITE+ begins with +git://+. The downloaded
  177. source code is cached as with the +svn+
  178. method.
  179. ** +hg+ for retrieving source code from a Mercurial repository. One
  180. 'must' specify +LIBFOO_SITE_METHOD=hg+ when +LIBFOO_SITE+
  181. contains a Mercurial repository URL. The downloaded source code
  182. is cached as with the +svn+ method.
  183. ** +bzr+ for retrieving source code from a Bazaar repository. Used
  184. by default when +LIBFOO_SITE+ begins with +bzr://+. The
  185. downloaded source code is cached as with the +svn+ method.
  186. ** +file+ for a local tarball. One should use this when
  187. +LIBFOO_SITE+ specifies a package tarball as a local filename.
  188. Useful for software that isn't available publicly or in version
  189. control.
  190. ** +local+ for a local source code directory. One should use this
  191. when +LIBFOO_SITE+ specifies a local directory path containing
  192. the package source code. Buildroot copies the contents of the
  193. source directory into the package's build directory.
  194. * +LIBFOO_DEPENDENCIES+ lists the dependencies (in terms of package
  195. name) that are required for the current target package to
  196. compile. These dependencies are guaranteed to be compiled and
  197. installed before the configuration of the current package starts. In
  198. a similar way, +HOST_LIBFOO_DEPENDENCIES+ lists the dependency for
  199. the current host package.
  200. * +LIBFOO_INSTALL_STAGING+ can be set to +YES+ or +NO+ (default). If
  201. set to +YES+, then the commands in the +LIBFOO_INSTALL_STAGING_CMDS+
  202. variables are executed to install the package into the staging
  203. directory.
  204. * +LIBFOO_INSTALL_TARGET+ can be set to +YES+ (default) or +NO+. If
  205. set to +YES+, then the commands in the +LIBFOO_INSTALL_TARGET_CMDS+
  206. variables are executed to install the package into the target
  207. directory.
  208. * +LIBFOO_DEVICES+ lists the device files to be created by Buildroot
  209. when using the static device table. The syntax to use is the
  210. makedevs one. You can find some documentation for this syntax in the
  211. xref:makedev-syntax[]. This variable is optional.
  212. * +LIBFOO_PERMISSIONS+ lists the changes of permissions to be done at
  213. the end of the build process. The syntax is once again the makedevs one.
  214. You can find some documentation for this syntax in the xref:makedev-syntax[].
  215. This variable is optional.
  216. * +LIBFOO_LICENSE+ defines the license (or licenses) under which the package
  217. is released.
  218. This name will appear in the manifest file produced by +make legal-info+.
  219. If the license is one of those listed in xref:legal-info[],
  220. use the same string to make the manifest file uniform.
  221. Otherwise, describe the license in a precise and concise way, avoiding
  222. ambiguous names such as +BSD+ which actually name a family of licenses.
  223. If the root filesystem you generate contains non-opensource packages, you
  224. can define their license as +PROPRIETARY+: Buildroot will not save any
  225. licensing info or source code for this package.
  226. This variable is optional. If it is not defined, +unknown+ will appear in
  227. the +license+ field of the manifest file for this package.
  228. * +LIBFOO_LICENSE_FILES+ is a space-separated list of files in the package
  229. tarball that contain the license(s) under which the package is released.
  230. +make legal-info+ copies all of these files in the +legal-info+ directory.
  231. See xref:legal-info[] for more information.
  232. This variable is optional. If it is not defined, a warning will be produced
  233. to let you know, and +not saved+ will appear in the +license files+ field
  234. of the manifest file for this package.
  235. The recommended way to define these variables is to use the following
  236. syntax:
  237. ----------------------
  238. LIBFOO_VERSION = 2.32
  239. ----------------------
  240. Now, the variables that define what should be performed at the
  241. different steps of the build process.
  242. * +LIBFOO_CONFIGURE_CMDS+, used to list the actions to be performed to
  243. configure the package before its compilation
  244. * +LIBFOO_BUILD_CMDS+, used to list the actions to be performed to
  245. compile the package
  246. * +HOST_LIBFOO_INSTALL_CMDS+, used to list the actions to be performed
  247. to install the package, when the package is a host package. The
  248. package must install its files to the directory given by
  249. +$(HOST_DIR)+. All files, including development files such as
  250. headers should be installed, since other packages might be compiled
  251. on top of this package.
  252. * +LIBFOO_INSTALL_TARGET_CMDS+, used to list the actions to be
  253. performed to install the package to the target directory, when the
  254. package is a target package. The package must install its files to
  255. the directory given by +$(TARGET_DIR)+. Only the files required for
  256. 'documentation' and 'execution' of the package should be
  257. installed. Header files should not be installed, they will be copied
  258. to the target, if the +development files in target filesystem+
  259. option is selected.
  260. * +LIBFOO_INSTALL_STAGING_CMDS+, used to list the actions to be
  261. performed to install the package to the staging directory, when the
  262. package is a target package. The package must install its files to
  263. the directory given by +$(STAGING_DIR)+. All development files
  264. should be installed, since they might be needed to compile other
  265. packages.
  266. * +LIBFOO_CLEAN_CMDS+, used to list the actions to perform to clean up
  267. the build directory of the package.
  268. * +LIBFOO_UNINSTALL_TARGET_CMDS+, used to list the actions to
  269. uninstall the package from the target directory +$(TARGET_DIR)+
  270. * +LIBFOO_UNINSTALL_STAGING_CMDS+, used to list the actions to
  271. uninstall the package from the staging directory +$(STAGING_DIR)+.
  272. * +LIBFOO_INSTALL_INIT_SYSV+ and +LIBFOO_INSTALL_INIT_SYSTEMD+, used
  273. to install init scripts either for the systemV-like init systems
  274. (busybox, sysvinit, etc.) or for the systemd units. These commands
  275. will be run only when the relevant init system is installed (i.e. if
  276. systemd is selected as the init system in the configuration, only
  277. +LIBFOO_INSTALL_INIT_SYSTEMD+ will be run).
  278. The preferred way to define these variables is:
  279. ----------------------
  280. define LIBFOO_CONFIGURE_CMDS
  281. action 1
  282. action 2
  283. action 3
  284. endef
  285. ----------------------
  286. In the action definitions, you can use the following variables:
  287. * +$(@D)+, which contains the directory in which the package source
  288. code has been uncompressed.
  289. * +$(TARGET_CC)+, +$(TARGET_LD)+, etc. to get the target
  290. cross-compilation utilities
  291. * +$(TARGET_CROSS)+ to get the cross-compilation toolchain prefix
  292. * Of course the +$(HOST_DIR)+, +$(STAGING_DIR)+ and +$(TARGET_DIR)+
  293. variables to install the packages properly.
  294. The last feature of the generic infrastructure is the ability to add
  295. hooks. These define further actions to perform after existing steps.
  296. Most hooks aren't really useful for generic packages, since the +.mk+
  297. file already has full control over the actions performed in each step
  298. of the package construction. The hooks are more useful for packages
  299. using the autotools infrastructure described below. However, since
  300. they are provided by the generic infrastructure, they are documented
  301. here. The exception is +LIBFOO_POST_PATCH_HOOKS+. Patching the
  302. package and producing legal info are not user definable, so
  303. +LIBFOO_POST_PATCH_HOOKS+ and +LIBFOO_POST_LEGAL_INFO_HOOKS+ will be
  304. userful for generic packages.
  305. The following hook points are available:
  306. * +LIBFOO_POST_PATCH_HOOKS+
  307. * +LIBFOO_PRE_CONFIGURE_HOOKS+
  308. * +LIBFOO_POST_CONFIGURE_HOOKS+
  309. * +LIBFOO_POST_BUILD_HOOKS+
  310. * +LIBFOO_POST_INSTALL_HOOKS+ (for host packages only)
  311. * +LIBFOO_POST_INSTALL_STAGING_HOOKS+ (for target packages only)
  312. * +LIBFOO_POST_INSTALL_TARGET_HOOKS+ (for target packages only)
  313. * +LIBFOO_POST_LEGAL_INFO_HOOKS+
  314. These variables are 'lists' of variable names containing actions to be
  315. performed at this hook point. This allows several hooks to be
  316. registered at a given hook point. Here is an example:
  317. ----------------------
  318. define LIBFOO_POST_PATCH_FIXUP
  319. action1
  320. action2
  321. endef
  322. LIBFOO_POST_PATCH_HOOKS += LIBFOO_POST_PATCH_FIXUP
  323. ----------------------