adding-packages-gentargets.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. [[gentargets-tutorial]]
  8. +GENTARGETS+ 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 $(call GENTARGETS))
  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 +GENTARGETS+ which
  77. generates, according to the variables defined previously, all the
  78. Makefile code necessary to make your package working.
  79. [[gentargets-reference]]
  80. +GENTARGETS+ Reference
  81. ~~~~~~~~~~~~~~~~~~~~~~
  82. The +GENTARGETS+ macro takes one optional argument. This argument can
  83. be used to tell if the package is a target package (cross-compiled for
  84. the target) or a host package (natively compiled for the host). If
  85. unspecified, it is assumed that it is a target package. See below for
  86. details.
  87. For a given package, in a single +.mk+ file, it is possible to call
  88. GENTARGETS twice, once to create the rules to generate a target
  89. package and once to create the rules to generate a host package:
  90. ----------------------
  91. $(eval $(call GENTARGETS))
  92. $(eval $(call GENTARGETS,host))
  93. ----------------------
  94. This might be useful if the compilation of the target package requires
  95. some tools to be installed on the host. If the package name is
  96. +libfoo+, then the name of the package for the target is also
  97. +libfoo+, while the name of the package for the host is
  98. +host-libfoo+. These names should be used in the DEPENDENCIES
  99. variables of other packages, if they depend on +libfoo+ or
  100. +host-libfoo+.
  101. The call to the +GENTARGETS+ macro *must* be at the end of the +.mk+
  102. file, after all variable definitions.
  103. For the target package, the +GENTARGETS+ uses the variables defined by
  104. the .mk file and prefixed by the uppercased package name:
  105. +LIBFOO_*+. For the host package, it uses the +HOST_LIBFOO_*+. For
  106. 'some' variables, if the +HOST_LIBFOO_+ prefixed variable doesn't
  107. exist, the package infrastructure uses the corresponding variable
  108. prefixed by +LIBFOO_+. This is done for variables that are likely to
  109. have the same value for both the target and host packages. See below
  110. for details.
  111. The list of variables that can be set in a +.mk+ file to give metadata
  112. information is (assuming the package name is +libfoo+) :
  113. * +LIBFOO_VERSION+, mandatory, must contain the version of the
  114. package. Note that if +HOST_LIBFOO_VERSION+ doesn't exist, it is
  115. assumed to be the same as +LIBFOO_VERSION+. It can also be a
  116. revision number, branch or tag for packages that are fetched
  117. directly from their revision control system. +
  118. Examples: +
  119. +LIBFOO_VERSION = 0.1.2+ +
  120. +LIBFOO_VERSION = cb9d6aa9429e838f0e54faa3d455bcbab5eef057+ +
  121. +LIBFOO_VERSION = stable+
  122. * +LIBFOO_SOURCE+ may contain the name of the tarball of
  123. the package. If +HOST_LIBFOO_SOURCE+ is not specified, it
  124. defaults to +LIBFOO_SOURCE+. If none are specified, then
  125. the value is assumed to be
  126. +packagename-$(LIBFOO_VERSION).tar.gz+. +
  127. Example: +LIBFOO_SOURCE = foobar-$(LIBFOO_VERSION).tar.bz2+
  128. * +LIBFOO_PATCH+ may contain the name of a patch, that will be
  129. downloaded from the same location as the tarball indicated in
  130. +LIBFOO_SOURCE+. If +HOST_LIBFOO_PATCH+ is not specified, it
  131. defaults to +LIBFOO_PATCH+. Also note that another mechanism is
  132. available to patch a package: all files of the form
  133. +packagename-packageversion-description.patch+ present in the
  134. package directory inside Buildroot will be applied to the package
  135. after extraction.
  136. * +LIBFOO_SITE+ may contain the Internet location of the package. It
  137. can either be the HTTP, FTP or SCP location of a tarball, or the URL
  138. of a Git, Subversion, Mercurial or Bazaar repository (see
  139. +LIBFOO_SITE_METHOD+ below). +
  140. SCP URLs should be of the form +scp://[user@]host:filepath+. Note
  141. that filepath is relative to the user's home directory, so you may want
  142. to prepend the path with a slash for absolute paths:
  143. +scp://[user@]host:/absolutepath+. +
  144. If +HOST_LIBFOO_SITE+ is not specified, it defaults to
  145. +LIBFOO_SITE+. If none are specified, then the location is assumed
  146. to be
  147. +http://$$(BR2_SOURCEFORGE_MIRROR).dl.sourceforge.net/sourceforge/packagename+. +
  148. Examples: +
  149. +LIBFOO_SITE=http://www.libfoosoftware.org/libfoo+ +
  150. +LIBFOO_SITE=http://svn.xiph.org/trunk/Tremor/+ +
  151. +LIBFOO_SITE=git://github.com/kergoth/tslib.git+
  152. * +LIBFOO_SITE_METHOD+ may contain the method to fetch the package
  153. source code. It can either be +wget+ (for normal FTP/HTTP downloads
  154. of tarballs), +scp+ (for downloads over SSH with scp), +svn+, +git+,
  155. +hg+ or +bzr+. When not specified, it is guessed from the URL given
  156. in +LIBFOO_SITE+: +scp://+, +svn://+, +git://+ and
  157. +bzr://+ URLs will use the +scp+, +svn+, +git+ and +bzr+ methods
  158. respectively. All other URL-types will use the +wget+ method. So for
  159. example, in the case of a package whose source code is available
  160. through a Subversion repository on HTTP, one 'must' specifiy
  161. +LIBFOO_SITE_METHOD=svn+. Similarly, for Mercurial repositories, one
  162. 'must' specify +LIBFOO_SITE_METHOD=hg+. For +svn+, +git+, +hg+ and
  163. +bzr+ methods, what Buildroot does is a checkout/clone of the repository
  164. which is then tarballed and stored into the download cache. Next
  165. builds will not checkout/clone again, but will use the tarball directly.
  166. When +HOST_LIBFOO_SITE_METHOD+ is not specified, it defaults to the value
  167. of +LIBFOO_SITE_METHOD+. See +package/multimedia/tremor/+ for an
  168. example.
  169. * +LIBFOO_DEPENDENCIES+ lists the dependencies (in terms of package
  170. name) that are required for the current target package to
  171. compile. These dependencies are guaranteed to be compiled and
  172. installed before the configuration of the current package starts. In
  173. a similar way, +HOST_LIBFOO_DEPENDENCIES+ lists the dependency for
  174. the current host package.
  175. * +LIBFOO_INSTALL_STAGING+ can be set to +YES+ or +NO+ (default). If
  176. set to +YES+, then the commands in the +LIBFOO_INSTALL_STAGING_CMDS+
  177. variables are executed to install the package into the staging
  178. directory.
  179. * +LIBFOO_INSTALL_TARGET+ can be set to +YES+ (default) or +NO+. If
  180. set to +YES+, then the commands in the +LIBFOO_INSTALL_TARGET_CMDS+
  181. variables are executed to install the package into the target
  182. directory.
  183. * +LIBFOO_DEVICES+ lists the device files to be created by Buildroot
  184. when using the static device table. The syntax to use is the
  185. makedevs one. You can find some documentation for this syntax in the
  186. xref:makedev-syntax[]. This variable is optional.
  187. * +LIBFOO_PERMISSIONS+ lists the changes of permissions to be done at
  188. the end of the build process. The syntax is once again the makedevs one.
  189. You can find some documentation for this syntax in the xref:makedev-syntax[].
  190. This variable is optional.
  191. The recommended way to define these variables is to use the following
  192. syntax:
  193. ----------------------
  194. LIBFOO_VERSION = 2.32
  195. ----------------------
  196. Now, the variables that define what should be performed at the
  197. different steps of the build process.
  198. * +LIBFOO_CONFIGURE_CMDS+, used to list the actions to be performed to
  199. configure the package before its compilation
  200. * +LIBFOO_BUILD_CMDS+, used to list the actions to be performed to
  201. compile the package
  202. * +HOST_LIBFOO_INSTALL_CMDS+, used to list the actions to be performed
  203. to install the package, when the package is a host package. The
  204. package must install its files to the directory given by
  205. +$(HOST_DIR)+. All files, including development files such as
  206. headers should be installed, since other packages might be compiled
  207. on top of this package.
  208. * +LIBFOO_INSTALL_TARGET_CMDS+, used to list the actions to be
  209. performed to install the package to the target directory, when the
  210. package is a target package. The package must install its files to
  211. the directory given by +$(TARGET_DIR)+. Only the files required for
  212. 'documentation' and 'execution' of the package should be
  213. installed. Header files should not be installed, they will be copied
  214. to the target, if the +development files in target filesystem+
  215. option is selected.
  216. * +LIBFOO_INSTALL_STAGING_CMDS+, used to list the actions to be
  217. performed to install the package to the staging directory, when the
  218. package is a target package. The package must install its files to
  219. the directory given by +$(STAGING_DIR)+. All development files
  220. should be installed, since they might be needed to compile other
  221. packages.
  222. * +LIBFOO_CLEAN_CMDS+, used to list the actions to perform to clean up
  223. the build directory of the package.
  224. * +LIBFOO_UNINSTALL_TARGET_CMDS+, used to list the actions to
  225. uninstall the package from the target directory +$(TARGET_DIR)+
  226. * +LIBFOO_UNINSTALL_STAGING_CMDS+, used to list the actions to
  227. uninstall the package from the staging directory +$(STAGING_DIR)+.
  228. The preferred way to define these variables is:
  229. ----------------------
  230. define LIBFOO_CONFIGURE_CMDS
  231. action 1
  232. action 2
  233. action 3
  234. endef
  235. ----------------------
  236. In the action definitions, you can use the following variables:
  237. * +$(@D)+, which contains the directory in which the package source
  238. code has been uncompressed.
  239. * +$(TARGET_CC)+, +$(TARGET_LD)+, etc. to get the target
  240. cross-compilation utilities
  241. * +$(TARGET_CROSS)+ to get the cross-compilation toolchain prefix
  242. * Of course the +$(HOST_DIR)+, +$(STAGING_DIR)+ and +$(TARGET_DIR)+
  243. variables to install the packages properly.
  244. The last feature of the generic infrastructure is the ability to add
  245. hooks. These define further actions to perform after existing steps.
  246. Most hooks aren't really useful for generic packages, since the +.mk+
  247. file already has full control over the actions performed in each step
  248. of the package construction. The hooks are more useful for packages
  249. using the autotools infrastructure described below. However, since
  250. they are provided by the generic infrastructure, they are documented
  251. here. The exception is +LIBFOO_POST_PATCH_HOOKS+. Patching the
  252. package is not user definable, so +LIBFOO_POST_PATCH_HOOKS+ will be
  253. userful for generic packages.
  254. The following hook points are available:
  255. * +LIBFOO_POST_PATCH_HOOKS+
  256. * +LIBFOO_PRE_CONFIGURE_HOOKS+
  257. * +LIBFOO_POST_CONFIGURE_HOOKS+
  258. * +LIBFOO_POST_BUILD_HOOKS+
  259. * +LIBFOO_POST_INSTALL_HOOKS+ (for host packages only)
  260. * +LIBFOO_POST_INSTALL_STAGING_HOOKS+ (for target packages only)
  261. * +LIBFOO_POST_INSTALL_TARGET_HOOKS+ (for target packages only)
  262. These variables are 'lists' of variable names containing actions to be
  263. performed at this hook point. This allows several hooks to be
  264. registered at a given hook point. Here is an example:
  265. ----------------------
  266. define LIBFOO_POST_PATCH_FIXUP
  267. action1
  268. action2
  269. endef
  270. LIBFOO_POST_PATCH_HOOKS += LIBFOO_POST_PATCH_FIXUP
  271. ----------------------