1*4882a593Smuzhiyun// -*- mode:doc; -*- 2*4882a593Smuzhiyun// vim: set syntax=asciidoc: 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun=== Tips and tricks 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun[[package-name-variable-relation]] 7*4882a593Smuzhiyun==== Package name, config entry name and makefile variable relationship 8*4882a593Smuzhiyun 9*4882a593SmuzhiyunIn Buildroot, there is some relationship between: 10*4882a593Smuzhiyun 11*4882a593Smuzhiyun* the _package name_, which is the package directory name (and the 12*4882a593Smuzhiyun name of the +*.mk+ file); 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun* the config entry name that is declared in the +Config.in+ file; 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun* the makefile variable prefix. 17*4882a593Smuzhiyun 18*4882a593SmuzhiyunIt is mandatory to maintain consistency between these elements, 19*4882a593Smuzhiyunusing the following rules: 20*4882a593Smuzhiyun 21*4882a593Smuzhiyun* the package directory and the +*.mk+ name are the _package name_ 22*4882a593Smuzhiyun itself (e.g.: +package/foo-bar_boo/foo-bar_boo.mk+); 23*4882a593Smuzhiyun 24*4882a593Smuzhiyun* the _make_ target name is the _package name_ itself (e.g.: 25*4882a593Smuzhiyun +foo-bar_boo+); 26*4882a593Smuzhiyun 27*4882a593Smuzhiyun* the config entry is the upper case _package name_ with `.` and `-` 28*4882a593Smuzhiyun characters substituted with `_`, prefixed with +BR2_PACKAGE_+ (e.g.: 29*4882a593Smuzhiyun +BR2_PACKAGE_FOO_BAR_BOO+); 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun* the +*.mk+ file variable prefix is the upper case _package name_ 32*4882a593Smuzhiyun with `.` and `-` characters substituted with `_` (e.g.: 33*4882a593Smuzhiyun +FOO_BAR_BOO_VERSION+). 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun[[check-package]] 36*4882a593Smuzhiyun==== How to check the coding style 37*4882a593Smuzhiyun 38*4882a593SmuzhiyunBuildroot provides a script in +utils/check-package+ that checks new or 39*4882a593Smuzhiyunchanged files for coding style. It is not a complete language validator, 40*4882a593Smuzhiyunbut it catches many common mistakes. It is meant to run in the actual 41*4882a593Smuzhiyunfiles you created or modified, before creating the patch for submission. 42*4882a593Smuzhiyun 43*4882a593SmuzhiyunThis script can be used for packages, filesystem makefiles, Config.in 44*4882a593Smuzhiyunfiles, etc. It does not check the files defining the package 45*4882a593Smuzhiyuninfrastructures and some other files containing similar common code. 46*4882a593Smuzhiyun 47*4882a593SmuzhiyunTo use it, run the +check-package+ script, by telling which files you 48*4882a593Smuzhiyuncreated or changed: 49*4882a593Smuzhiyun 50*4882a593Smuzhiyun---- 51*4882a593Smuzhiyun$ ./utils/check-package package/new-package/* 52*4882a593Smuzhiyun---- 53*4882a593Smuzhiyun 54*4882a593SmuzhiyunIf you have the +utils+ directory in your path you can also run: 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun---- 57*4882a593Smuzhiyun$ cd package/new-package/ 58*4882a593Smuzhiyun$ check-package * 59*4882a593Smuzhiyun---- 60*4882a593Smuzhiyun 61*4882a593SmuzhiyunThe tool can also be used for packages in a br2-external: 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun---- 64*4882a593Smuzhiyun$ check-package -b /path/to/br2-ext-tree/package/my-package/* 65*4882a593Smuzhiyun---- 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun[[testing-package]] 68*4882a593Smuzhiyun==== How to test your package 69*4882a593Smuzhiyun 70*4882a593SmuzhiyunOnce you have added your new package, it is important that you test it 71*4882a593Smuzhiyununder various conditions: does it build for all architectures? Does it 72*4882a593Smuzhiyunbuild with the different C libraries? Does it need threads, NPTL? And 73*4882a593Smuzhiyunso on... 74*4882a593Smuzhiyun 75*4882a593SmuzhiyunBuildroot runs http://autobuild.buildroot.org/[autobuilders] which 76*4882a593Smuzhiyuncontinuously test random configurations. However, these only build the 77*4882a593Smuzhiyun`master` branch of the git tree, and your new fancy package is not yet 78*4882a593Smuzhiyunthere. 79*4882a593Smuzhiyun 80*4882a593SmuzhiyunBuildroot provides a script in +utils/test-pkg+ that uses the same base 81*4882a593Smuzhiyunconfigurations as used by the autobuilders so you can test your package 82*4882a593Smuzhiyunin the same conditions. 83*4882a593Smuzhiyun 84*4882a593SmuzhiyunFirst, create a config snippet that contains all the necessary options 85*4882a593Smuzhiyunneeded to enable your package, but without any architecture or toolchain 86*4882a593Smuzhiyunoption. For example, let's create a config snippet that just enables 87*4882a593Smuzhiyun+libcurl+, without any TLS backend: 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun---- 90*4882a593Smuzhiyun$ cat libcurl.config 91*4882a593SmuzhiyunBR2_PACKAGE_LIBCURL=y 92*4882a593Smuzhiyun---- 93*4882a593Smuzhiyun 94*4882a593SmuzhiyunIf your package needs more configuration options, you can add them to the 95*4882a593Smuzhiyunconfig snippet. For example, here's how you would test +libcurl+ with 96*4882a593Smuzhiyun+openssl+ as a TLS backend and the +curl+ program: 97*4882a593Smuzhiyun 98*4882a593Smuzhiyun---- 99*4882a593Smuzhiyun$ cat libcurl.config 100*4882a593SmuzhiyunBR2_PACKAGE_LIBCURL=y 101*4882a593SmuzhiyunBR2_PACKAGE_LIBCURL_CURL=y 102*4882a593SmuzhiyunBR2_PACKAGE_OPENSSL=y 103*4882a593Smuzhiyun---- 104*4882a593Smuzhiyun 105*4882a593SmuzhiyunThen run the +test-pkg+ script, by telling it what config snippet to use 106*4882a593Smuzhiyunand what package to test: 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun---- 109*4882a593Smuzhiyun$ ./utils/test-pkg -c libcurl.config -p libcurl 110*4882a593Smuzhiyun---- 111*4882a593Smuzhiyun 112*4882a593SmuzhiyunBy default, +test-pkg+ will build your package against a subset of the 113*4882a593Smuzhiyuntoolchains used by the autobuilders, which has been selected by the 114*4882a593SmuzhiyunBuildroot developers as being the most useful and representative 115*4882a593Smuzhiyunsubset. If you want to test all toolchains, pass the +-a+ option. Note 116*4882a593Smuzhiyunthat in any case, internal toolchains are excluded as they take too 117*4882a593Smuzhiyunlong to build. 118*4882a593Smuzhiyun 119*4882a593SmuzhiyunThe output lists all toolchains that are tested and the corresponding 120*4882a593Smuzhiyunresult (excerpt, results are fake): 121*4882a593Smuzhiyun 122*4882a593Smuzhiyun---- 123*4882a593Smuzhiyun$ ./utils/test-pkg -c libcurl.config -p libcurl 124*4882a593Smuzhiyun armv5-ctng-linux-gnueabi [ 1/11]: OK 125*4882a593Smuzhiyun armv7-ctng-linux-gnueabihf [ 2/11]: OK 126*4882a593Smuzhiyun br-aarch64-glibc [ 3/11]: SKIPPED 127*4882a593Smuzhiyun br-arcle-hs38 [ 4/11]: SKIPPED 128*4882a593Smuzhiyun br-arm-basic [ 5/11]: FAILED 129*4882a593Smuzhiyun br-arm-cortex-a9-glibc [ 6/11]: OK 130*4882a593Smuzhiyun br-arm-cortex-a9-musl [ 7/11]: FAILED 131*4882a593Smuzhiyun br-arm-cortex-m4-full [ 8/11]: OK 132*4882a593Smuzhiyun br-arm-full [ 9/11]: OK 133*4882a593Smuzhiyun br-arm-full-nothread [10/11]: FAILED 134*4882a593Smuzhiyun br-arm-full-static [11/11]: OK 135*4882a593Smuzhiyun11 builds, 2 skipped, 2 build failed, 1 legal-info failed 136*4882a593Smuzhiyun---- 137*4882a593Smuzhiyun 138*4882a593SmuzhiyunThe results mean: 139*4882a593Smuzhiyun 140*4882a593Smuzhiyun* `OK`: the build was successful. 141*4882a593Smuzhiyun* `SKIPPED`: one or more configuration options listed in the config 142*4882a593Smuzhiyun snippet were not present in the final configuration. This is due to 143*4882a593Smuzhiyun options having dependencies not satisfied by the toolchain, such as 144*4882a593Smuzhiyun for example a package that +depends on BR2_USE_MMU+ with a noMMU 145*4882a593Smuzhiyun toolchain. The missing options are reported in +missing.config+ in 146*4882a593Smuzhiyun the output build directory (+~/br-test-pkg/TOOLCHAIN_NAME/+ by 147*4882a593Smuzhiyun default). 148*4882a593Smuzhiyun* `FAILED`: the build failed. Inspect the +logfile+ file in the output 149*4882a593Smuzhiyun build directory to see what went wrong: 150*4882a593Smuzhiyun** the actual build failed, 151*4882a593Smuzhiyun** the legal-info failed, 152*4882a593Smuzhiyun** one of the preliminary steps (downloading the config file, applying 153*4882a593Smuzhiyun the configuration, running `dirclean` for the package) failed. 154*4882a593Smuzhiyun 155*4882a593SmuzhiyunWhen there are failures, you can just re-run the script with the same 156*4882a593Smuzhiyunoptions (after you fixed your package); the script will attempt to 157*4882a593Smuzhiyunre-build the package specified with +-p+ for all toolchains, without 158*4882a593Smuzhiyunthe need to re-build all the dependencies of that package. 159*4882a593Smuzhiyun 160*4882a593SmuzhiyunThe +test-pkg+ script accepts a few options, for which you can get some 161*4882a593Smuzhiyunhelp by running: 162*4882a593Smuzhiyun 163*4882a593Smuzhiyun---- 164*4882a593Smuzhiyun$ ./utils/test-pkg -h 165*4882a593Smuzhiyun---- 166*4882a593Smuzhiyun 167*4882a593Smuzhiyun[[github-download-url]] 168*4882a593Smuzhiyun==== How to add a package from GitHub 169*4882a593Smuzhiyun 170*4882a593SmuzhiyunPackages on GitHub often don't have a download area with release tarballs. 171*4882a593SmuzhiyunHowever, it is possible to download tarballs directly from the repository 172*4882a593Smuzhiyunon GitHub. As GitHub is known to have changed download mechanisms in the 173*4882a593Smuzhiyunpast, the 'github' helper function should be used as shown below. 174*4882a593Smuzhiyun 175*4882a593Smuzhiyun------------------------ 176*4882a593Smuzhiyun# Use a tag or a full commit ID 177*4882a593SmuzhiyunFOO_VERSION = 1.0 178*4882a593SmuzhiyunFOO_SITE = $(call github,<user>,<package>,v$(FOO_VERSION)) 179*4882a593Smuzhiyun------------------------ 180*4882a593Smuzhiyun 181*4882a593Smuzhiyun.Notes 182*4882a593Smuzhiyun- The FOO_VERSION can either be a tag or a commit ID. 183*4882a593Smuzhiyun- The tarball name generated by github matches the default one from 184*4882a593Smuzhiyun Buildroot (e.g.: +foo-f6fb6654af62045239caed5950bc6c7971965e60.tar.gz+), 185*4882a593Smuzhiyun so it is not necessary to specify it in the +.mk+ file. 186*4882a593Smuzhiyun- When using a commit ID as version, you should use the full 40 hex characters. 187*4882a593Smuzhiyun- When the tag contains a prefix such as +v+ in +v1.0+, then the 188*4882a593Smuzhiyun +VERSION+ variable should contain just +1.0+, and the +v+ should be 189*4882a593Smuzhiyun added directly in the +SITE+ variable, as illustrated above. This 190*4882a593Smuzhiyun ensures that the +VERSION+ variable value can be used to match 191*4882a593Smuzhiyun against http://www.release-monitoring.org/[release-monitoring.org] 192*4882a593Smuzhiyun results. 193*4882a593Smuzhiyun 194*4882a593SmuzhiyunIf the package you wish to add does have a release section on GitHub, the 195*4882a593Smuzhiyunmaintainer may have uploaded a release tarball, or the release may just point 196*4882a593Smuzhiyunto the automatically generated tarball from the git tag. If there is a 197*4882a593Smuzhiyunrelease tarball uploaded by the maintainer, we prefer to use that since it 198*4882a593Smuzhiyunmay be slightly different (e.g. it contains a configure script so we don't 199*4882a593Smuzhiyunneed to do AUTORECONF). 200*4882a593Smuzhiyun 201*4882a593SmuzhiyunYou can see on the release page if it's an uploaded tarball or a git tag: 202*4882a593Smuzhiyun 203*4882a593Smuzhiyunimage::github_hash_mongrel2.png[] 204*4882a593Smuzhiyun 205*4882a593Smuzhiyun- If it looks like the image above then it was uploaded by the 206*4882a593Smuzhiyun maintainer and you should use that link (in that example: 207*4882a593Smuzhiyun 'mongrel2-v1.9.2.tar.bz2') to specify +FOO_SITE+, and not use the 208*4882a593Smuzhiyun 'github' helper. 209*4882a593Smuzhiyun 210*4882a593Smuzhiyun- On the other hand, if there's is *only* the "Source code" link, then 211*4882a593Smuzhiyun it's an automatically generated tarball and you should use the 212*4882a593Smuzhiyun 'github' helper function. 213*4882a593Smuzhiyun 214*4882a593Smuzhiyun[[gitlab-download-url]] 215*4882a593Smuzhiyun==== How to add a package from Gitlab 216*4882a593Smuzhiyun 217*4882a593SmuzhiyunIn a similar way to the +github+ macro described in 218*4882a593Smuzhiyunxref:github-download-url[], Buildroot also provides the +gitlab+ macro 219*4882a593Smuzhiyunto download from Gitlab repositories. It can be used to download 220*4882a593Smuzhiyunauto-generated tarballs produced by Gitlab, either for specific tags 221*4882a593Smuzhiyunor commits: 222*4882a593Smuzhiyun 223*4882a593Smuzhiyun------------------------ 224*4882a593Smuzhiyun# Use a tag or a full commit ID 225*4882a593SmuzhiyunFOO_VERSION = 1.0 226*4882a593SmuzhiyunFOO_SITE = $(call gitlab,<user>,<package>,v$(FOO_VERSION)) 227*4882a593Smuzhiyun------------------------ 228*4882a593Smuzhiyun 229*4882a593SmuzhiyunBy default, it will use a +.tar.gz+ tarball, but Gitlab also provides 230*4882a593Smuzhiyun+.tar.bz2+ tarballs, so by adding a +<pkg>_SOURCE+ variable, this 231*4882a593Smuzhiyun+.tar.bz2+ tarball can be used: 232*4882a593Smuzhiyun 233*4882a593Smuzhiyun------------------------ 234*4882a593Smuzhiyun# Use a tag or a full commit ID 235*4882a593SmuzhiyunFOO_VERSION = 1.0 236*4882a593SmuzhiyunFOO_SITE = $(call gitlab,<user>,<package>,v$(FOO_VERSION)) 237*4882a593SmuzhiyunFOO_SOURCE = foo-$(FOO_VERSION).tar.bz2 238*4882a593Smuzhiyun------------------------ 239*4882a593Smuzhiyun 240*4882a593SmuzhiyunIf there is a specific tarball uploaded by the upstream developers in 241*4882a593Smuzhiyun+https://gitlab.com/<project>/releases/+, do not use this macro, but 242*4882a593Smuzhiyunrather use directly the link to the tarball. 243