1*4882a593Smuzhiyun// -*- mode:doc; -*- 2*4882a593Smuzhiyun// vim: set syntax=asciidoc: 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun[[patch-policy]] 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun== Patching a package 7*4882a593Smuzhiyun 8*4882a593SmuzhiyunWhile integrating a new package or updating an existing one, it may be 9*4882a593Smuzhiyunnecessary to patch the source of the software to get it cross-built within 10*4882a593SmuzhiyunBuildroot. 11*4882a593Smuzhiyun 12*4882a593SmuzhiyunBuildroot offers an infrastructure to automatically handle this during 13*4882a593Smuzhiyunthe builds. It supports three ways of applying patch sets: downloaded patches, 14*4882a593Smuzhiyunpatches supplied within buildroot and patches located in a user-defined 15*4882a593Smuzhiyunglobal patch directory. 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun=== Providing patches 18*4882a593Smuzhiyun 19*4882a593Smuzhiyun==== Downloaded 20*4882a593Smuzhiyun 21*4882a593SmuzhiyunIf it is necessary to apply a patch that is available for download, then add it 22*4882a593Smuzhiyunto the +<packagename>_PATCH+ variable. If an entry contains +://+, 23*4882a593Smuzhiyunthen Buildroot will assume it is a full URL and download the patch 24*4882a593Smuzhiyunfrom this location. Otherwise, Buildroot will assume that the patch should be 25*4882a593Smuzhiyundownloaded from +<packagename>_SITE+. It can be a single patch, 26*4882a593Smuzhiyunor a tarball containing a patch series. 27*4882a593Smuzhiyun 28*4882a593SmuzhiyunLike for all downloads, a hash should be added to the +<packagename>.hash+ 29*4882a593Smuzhiyunfile. 30*4882a593Smuzhiyun 31*4882a593SmuzhiyunThis method is typically used for packages from Debian. 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun==== Within Buildroot 34*4882a593Smuzhiyun 35*4882a593SmuzhiyunMost patches are provided within Buildroot, in the package 36*4882a593Smuzhiyundirectory; these typically aim to fix cross-compilation, libc support, 37*4882a593Smuzhiyunor other such issues. 38*4882a593Smuzhiyun 39*4882a593SmuzhiyunThese patch files should be named +<number>-<description>.patch+. 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun.Notes 42*4882a593Smuzhiyun- The patch files coming with Buildroot should not contain any package version 43*4882a593Smuzhiyun reference in their filename. 44*4882a593Smuzhiyun- The field +<number>+ in the patch file name refers to the 'apply order', 45*4882a593Smuzhiyun and shall start at 1; It is preferred to pad the number with zeros up to 4 46*4882a593Smuzhiyun digits, like 'git-format-patch' does. E.g.: +0001-foobar-the-buz.patch+ 47*4882a593Smuzhiyun- Previously, it was mandatory for patches to be prefixed with the name of 48*4882a593Smuzhiyun the package, like +<package>-<number>-<description>.patch+, but that is 49*4882a593Smuzhiyun no longer the case. Existing packages will be fixed as time passes. 'Do 50*4882a593Smuzhiyun not prefix patches with the package name.' 51*4882a593Smuzhiyun- Previously, a +series+ file, as used by +quilt+, could also be added in 52*4882a593Smuzhiyun the package directory. In that case, the +series+ file defines the patch 53*4882a593Smuzhiyun application order. This is deprecated, and will be removed in the future. 54*4882a593Smuzhiyun 'Do not use a series file.' 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun 57*4882a593Smuzhiyun==== Global patch directory 58*4882a593Smuzhiyun 59*4882a593SmuzhiyunThe +BR2_GLOBAL_PATCH_DIR+ configuration file option can be 60*4882a593Smuzhiyunused to specify a space separated list of one or more directories 61*4882a593Smuzhiyuncontaining global package patches. See xref:customize-patches[] for 62*4882a593Smuzhiyundetails. 63*4882a593Smuzhiyun 64*4882a593Smuzhiyun[[patch-apply-order]] 65*4882a593Smuzhiyun=== How patches are applied 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun. Run the +<packagename>_PRE_PATCH_HOOKS+ commands if defined; 68*4882a593Smuzhiyun 69*4882a593Smuzhiyun. Cleanup the build directory, removing any existing +*.rej+ files; 70*4882a593Smuzhiyun 71*4882a593Smuzhiyun. If +<packagename>_PATCH+ is defined, then patches from these 72*4882a593Smuzhiyun tarballs are applied; 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun. If there are some +*.patch+ files in the package's Buildroot 75*4882a593Smuzhiyun directory or in a package subdirectory named +<packageversion>+, 76*4882a593Smuzhiyun then: 77*4882a593Smuzhiyun+ 78*4882a593Smuzhiyun* If a +series+ file exists in the package directory, then patches are 79*4882a593Smuzhiyun applied according to the +series+ file; 80*4882a593Smuzhiyun+ 81*4882a593Smuzhiyun* Otherwise, patch files matching +*.patch+ are applied in alphabetical 82*4882a593Smuzhiyun order. 83*4882a593Smuzhiyun So, to ensure they are applied in the right order, it is highly 84*4882a593Smuzhiyun recommended to name the patch files like this: 85*4882a593Smuzhiyun +<number>-<description>.patch+, where +<number>+ refers to the 86*4882a593Smuzhiyun 'apply order'. 87*4882a593Smuzhiyun 88*4882a593Smuzhiyun. If +BR2_GLOBAL_PATCH_DIR+ is defined, the directories will be 89*4882a593Smuzhiyun enumerated in the order they are specified. The patches are applied 90*4882a593Smuzhiyun as described in the previous step. 91*4882a593Smuzhiyun 92*4882a593Smuzhiyun. Run the +<packagename>_POST_PATCH_HOOKS+ commands if defined. 93*4882a593Smuzhiyun 94*4882a593SmuzhiyunIf something goes wrong in the steps _3_ or _4_, then the build fails. 95*4882a593Smuzhiyun 96*4882a593Smuzhiyun=== Format and licensing of the package patches 97*4882a593Smuzhiyun 98*4882a593SmuzhiyunPatches are released under the same license as the software they apply 99*4882a593Smuzhiyunto (see xref:legal-info-buildroot[]). 100*4882a593Smuzhiyun 101*4882a593SmuzhiyunA message explaining what the patch does, and why it is needed, should 102*4882a593Smuzhiyunbe added in the header commentary of the patch. 103*4882a593Smuzhiyun 104*4882a593SmuzhiyunYou should add a +Signed-off-by+ statement in the header of the each 105*4882a593Smuzhiyunpatch to help with keeping track of the changes and to certify that the 106*4882a593Smuzhiyunpatch is released under the same license as the software that is modified. 107*4882a593Smuzhiyun 108*4882a593SmuzhiyunIf the software is under version control, it is recommended to use the 109*4882a593Smuzhiyunupstream SCM software to generate the patch set. 110*4882a593Smuzhiyun 111*4882a593SmuzhiyunOtherwise, concatenate the header with the output of the 112*4882a593Smuzhiyun+diff -purN package-version.orig/ package-version/+ command. 113*4882a593Smuzhiyun 114*4882a593SmuzhiyunIf you update an existing patch (e.g. when bumping the package version), 115*4882a593Smuzhiyunmake sure the existing From header and Signed-off-by tags are not 116*4882a593Smuzhiyunremoved, but do update the rest of the patch comment when appropriate. 117*4882a593Smuzhiyun 118*4882a593SmuzhiyunAt the end, the patch should look like: 119*4882a593Smuzhiyun 120*4882a593Smuzhiyun--------------- 121*4882a593Smuzhiyunconfigure.ac: add C++ support test 122*4882a593Smuzhiyun 123*4882a593SmuzhiyunSigned-off-by: John Doe <john.doe@noname.org> 124*4882a593Smuzhiyun 125*4882a593Smuzhiyun--- configure.ac.orig 126*4882a593Smuzhiyun+++ configure.ac 127*4882a593Smuzhiyun@@ -40,2 +40,12 @@ 128*4882a593Smuzhiyun 129*4882a593SmuzhiyunAC_PROG_MAKE_SET 130*4882a593Smuzhiyun+ 131*4882a593Smuzhiyun+AC_CACHE_CHECK([whether the C++ compiler works], 132*4882a593Smuzhiyun+ [rw_cv_prog_cxx_works], 133*4882a593Smuzhiyun+ [AC_LANG_PUSH([C++]) 134*4882a593Smuzhiyun+ AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], 135*4882a593Smuzhiyun+ [rw_cv_prog_cxx_works=yes], 136*4882a593Smuzhiyun+ [rw_cv_prog_cxx_works=no]) 137*4882a593Smuzhiyun+ AC_LANG_POP([C++])]) 138*4882a593Smuzhiyun+ 139*4882a593Smuzhiyun+AM_CONDITIONAL([CXX_WORKS], [test "x$rw_cv_prog_cxx_works" = "xyes"]) 140*4882a593Smuzhiyun--------------- 141*4882a593Smuzhiyun 142*4882a593Smuzhiyun=== Integrating patches found on the Web 143*4882a593Smuzhiyun 144*4882a593SmuzhiyunWhen integrating a patch of which you are not the author, you have to 145*4882a593Smuzhiyunadd a few things in the header of the patch itself. 146*4882a593Smuzhiyun 147*4882a593SmuzhiyunDepending on whether the patch has been obtained from the project 148*4882a593Smuzhiyunrepository itself, or from somewhere on the web, add one of the 149*4882a593Smuzhiyunfollowing tags: 150*4882a593Smuzhiyun 151*4882a593Smuzhiyun--------------- 152*4882a593SmuzhiyunBackported from: <some commit id> 153*4882a593Smuzhiyun--------------- 154*4882a593Smuzhiyun 155*4882a593Smuzhiyunor 156*4882a593Smuzhiyun 157*4882a593Smuzhiyun--------------- 158*4882a593SmuzhiyunFetch from: <some url> 159*4882a593Smuzhiyun--------------- 160*4882a593Smuzhiyun 161*4882a593SmuzhiyunIt is also sensible to add a few words about any changes to the patch 162*4882a593Smuzhiyunthat may have been necessary. 163