patch-policy.txt 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. // -*- mode:doc; -*-
  2. // vim: set syntax=asciidoc:
  3. [[patch-policy]]
  4. == Patching a package
  5. While integrating a new package or updating an existing one, it may be
  6. necessary to patch the source of the software to get it cross-built within
  7. Buildroot.
  8. Buildroot offers an infrastructure to automatically handle this during
  9. the builds. It supports three ways of applying patch sets: downloaded patches,
  10. patches supplied within buildroot and patches located in a user-defined
  11. global patch directory.
  12. === Providing patches
  13. ==== Downloaded
  14. If it is necessary to apply a patch that is available for download, then add it
  15. to the +<packagename>_PATCH+ variable. If an entry contains +://+,
  16. then Buildroot will assume it is a full URL and download the patch
  17. from this location. Otherwise, Buildroot will assume that the patch should be
  18. downloaded from +<packagename>_SITE+. It can be a single patch,
  19. or a tarball containing a patch series.
  20. Like for all downloads, a hash should be added to the +<packagename>.hash+
  21. file.
  22. This method is typically used for packages from Debian.
  23. ==== Within Buildroot
  24. Most patches are provided within Buildroot, in the package
  25. directory; these typically aim to fix cross-compilation, libc support,
  26. or other such issues.
  27. These patch files should be named +<number>-<description>.patch+.
  28. .Notes
  29. - The patch files coming with Buildroot should not contain any package version
  30. reference in their filename.
  31. - The field +<number>+ in the patch file name refers to the 'apply order',
  32. and shall start at 1; It is preferred to pad the number with zeros up to 4
  33. digits, like 'git-format-patch' does. E.g.: +0001-foobar-the-buz.patch+
  34. - The patch email subject prefix shall not be numbered. Patches shall
  35. be generated with the +git format-patch -N+ command, since this
  36. numbering is automatically added for series. For example, the patch
  37. subject line should look like +Subject: [PATCH] foobar the buz+ rather
  38. than +Subject: [PATCH n/m] foobar the buz+.
  39. - Previously, it was mandatory for patches to be prefixed with the name of
  40. the package, like +<package>-<number>-<description>.patch+, but that is
  41. no longer the case. Existing packages will be fixed as time passes. 'Do
  42. not prefix patches with the package name.'
  43. - Previously, a +series+ file, as used by +quilt+, could also be added in
  44. the package directory. In that case, the +series+ file defines the patch
  45. application order. This is deprecated, and will be removed in the future.
  46. 'Do not use a series file.'
  47. ==== Global patch directory
  48. The +BR2_GLOBAL_PATCH_DIR+ configuration file option can be
  49. used to specify a space separated list of one or more directories
  50. containing global package patches. See xref:customize-patches[] for
  51. details.
  52. [[patch-apply-order]]
  53. === How patches are applied
  54. . Run the +<packagename>_PRE_PATCH_HOOKS+ commands if defined;
  55. . Cleanup the build directory, removing any existing +*.rej+ files;
  56. . If +<packagename>_PATCH+ is defined, then patches from these
  57. tarballs are applied;
  58. . If there are some +*.patch+ files in the package's Buildroot
  59. directory or in a package subdirectory named +<packageversion>+,
  60. then:
  61. +
  62. * If a +series+ file exists in the package directory, then patches are
  63. applied according to the +series+ file;
  64. +
  65. * Otherwise, patch files matching +*.patch+ are applied in alphabetical
  66. order.
  67. So, to ensure they are applied in the right order, it is highly
  68. recommended to name the patch files like this:
  69. +<number>-<description>.patch+, where +<number>+ refers to the
  70. 'apply order'.
  71. . If +BR2_GLOBAL_PATCH_DIR+ is defined, the directories will be
  72. enumerated in the order they are specified. The patches are applied
  73. as described in the previous step.
  74. . Run the +<packagename>_POST_PATCH_HOOKS+ commands if defined.
  75. If something goes wrong in the steps _3_ or _4_, then the build fails.
  76. === Format and licensing of the package patches
  77. Patches are released under the same license as the software they apply
  78. to (see xref:legal-info-buildroot[]).
  79. A message explaining what the patch does, and why it is needed, should
  80. be added in the header commentary of the patch.
  81. You should add a +Signed-off-by+ statement in the header of the each
  82. patch to help with keeping track of the changes and to certify that the
  83. patch is released under the same license as the software that is modified.
  84. If the software is under version control, it is recommended to use the
  85. upstream SCM software to generate the patch set.
  86. Otherwise, concatenate the header with the output of the
  87. +diff -purN package-version.orig/ package-version/+ command.
  88. If you update an existing patch (e.g. when bumping the package version),
  89. make sure the existing From header and Signed-off-by tags are not
  90. removed, but do update the rest of the patch comment when appropriate.
  91. At the end, the patch should look like:
  92. ---------------
  93. configure.ac: add C++ support test
  94. Signed-off-by: John Doe <john.doe@noname.org>
  95. --- configure.ac.orig
  96. +++ configure.ac
  97. @@ -40,2 +40,12 @@
  98. AC_PROG_MAKE_SET
  99. +
  100. +AC_CACHE_CHECK([whether the C++ compiler works],
  101. + [rw_cv_prog_cxx_works],
  102. + [AC_LANG_PUSH([C++])
  103. + AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
  104. + [rw_cv_prog_cxx_works=yes],
  105. + [rw_cv_prog_cxx_works=no])
  106. + AC_LANG_POP([C++])])
  107. +
  108. +AM_CONDITIONAL([CXX_WORKS], [test "x$rw_cv_prog_cxx_works" = "xyes"])
  109. ---------------
  110. === Integrating patches found on the Web
  111. When integrating a patch of which you are not the author, you have to
  112. add a few things in the header of the patch itself.
  113. Depending on whether the patch has been obtained from the project
  114. repository itself, or from somewhere on the web, add one of the
  115. following tags:
  116. ---------------
  117. Backported from: <some commit id>
  118. ---------------
  119. or
  120. ---------------
  121. Fetch from: <some url>
  122. ---------------
  123. It is also sensible to add a few words about any changes to the patch
  124. that may have been necessary.