patch-policy.txt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. It is downloaded from the same site
  16. as the package itself. It can be a single patch, or a tarball containing a
  17. patch series.
  18. This method is typically used for packages from Debian.
  19. ==== Within Buildroot
  20. Most patches are provided within Buildroot, in the package
  21. directory; these typically aim to fix cross-compilation, libc support,
  22. or other such issues.
  23. These patch files should be named +<packagename>-<number>-<description>.patch+.
  24. A +series+ file, as used by +quilt+, may also be added in the
  25. package directory. In that case, the +series+ file defines the patch
  26. application order.
  27. .Notes
  28. - The patch files coming with Buildroot should not contain any package version
  29. reference in their filename.
  30. - The field +<number>+ in the patch file name refers to the 'apply order'.
  31. ==== Global patch directory
  32. The +BR2_GLOBAL_PATCH_DIR+ configuration file option can be
  33. used to specify a space separated list of one or more directories
  34. containing global package patches. See xref:customize-patches[] for
  35. details.
  36. [[patch-apply-order]]
  37. === How patches are applied
  38. . Run the +<packagename>_PRE_PATCH_HOOKS+ commands if defined;
  39. . Cleanup the build directory, removing any existing +*.rej+ files;
  40. . If +<packagename>_PATCH+ is defined, then patches from these
  41. tarballs are applied;
  42. . If there are some +*.patch+ files in the package's Buildroot
  43. directory or in a package subdirectory named +<packageversion>+,
  44. then:
  45. +
  46. * If a +series+ file exists in the package directory, then patches are
  47. applied according to the +series+ file;
  48. +
  49. * Otherwise, patch files matching +<packagename>-*.patch+
  50. are applied in alphabetical order.
  51. So, to ensure they are applied in the right order, it is highly
  52. recommended to name the patch files like this:
  53. +<packagename>-<number>-<description>.patch+, where +<number>+
  54. refers to the 'apply order'.
  55. . If +BR2_GLOBAL_PATCH_DIR+ is defined, the directories will be
  56. enumerated in the order they are specified. The patches are applied
  57. as described in the previous step.
  58. . Run the +<packagename>_POST_PATCH_HOOKS+ commands if defined.
  59. If something goes wrong in the steps _3_ or _4_, then the build fails.
  60. === Format and licensing of the package patches
  61. Patches are released under the same license as the software that is
  62. modified.
  63. A message explaining what the patch does, and why it is needed, should
  64. be added in the header commentary of the patch.
  65. You should add a +Signed-off-by+ statement in the header of the each
  66. patch to help with keeping track of the changes and to certify that the
  67. patch is released under the same license as the software that is modified.
  68. If the software is under version control, it is recommended to use the
  69. upstream SCM software to generate the patch set.
  70. Otherwise, concatenate the header with the output of the
  71. +diff -purN package-version.orig/ package-version/+ command.
  72. At the end, the patch should look like:
  73. ---------------
  74. configure.ac: add C++ support test
  75. Signed-off-by: John Doe <john.doe@noname.org>
  76. --- configure.ac.orig
  77. +++ configure.ac
  78. @@ -40,2 +40,12 @@
  79. AC_PROG_MAKE_SET
  80. +
  81. +AC_CACHE_CHECK([whether the C++ compiler works],
  82. + [rw_cv_prog_cxx_works],
  83. + [AC_LANG_PUSH([C++])
  84. + AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
  85. + [rw_cv_prog_cxx_works=yes],
  86. + [rw_cv_prog_cxx_works=no])
  87. + AC_LANG_POP([C++])])
  88. +
  89. +AM_CONDITIONAL([CXX_WORKS], [test "x$rw_cv_prog_cxx_works" = "xyes"])
  90. ---------------
  91. === Integrating patches found on the Web
  92. When integrating a patch of which you are not the author, you have to
  93. add a few things in the header of the patch itself.
  94. Depending on whether the patch has been obtained from the project
  95. repository itself, or from somewhere on the web, add one of the
  96. following tags:
  97. ---------------
  98. Backported from: <some commit id>
  99. ---------------
  100. or
  101. ---------------
  102. Fetch from: <some url>
  103. ---------------
  104. It is also sensible to add a few words about any changes to the patch
  105. that may have been necessary.