adding-packages-gentargets.txt 12 KB

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