adding-packages-gentargets.txt 13 KB

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