辣子鸡属于什么菜系| 睡觉打呼噜什么原因| 平痛新又叫什么| 吃中药不可以吃什么水果| 草字头加弓念什么| 牙痛吃什么消炎药| 足外翻挂什么科| sla是什么意思| 干嘛是什么意思| 肛门松弛吃什么药| 罡什么意思| 眼睛有异物感是什么原因| 上午十点半是什么时辰| 什么血型的人最聪明| 看腋窝挂什么科| 左手大拇指麻木是什么原因| 扶正固本是什么意思| kg是什么单位| spao是什么牌子| 鳄鱼吃什么食物| 中国最早的文字是什么| 饮鸩止渴是什么意思| 皈依有什么好处| 被孤立的一般是什么人| hb是什么意思| 急性肠胃炎可以吃什么食物| 日本桑是什么意思| 甲状腺属于什么系统| d二聚体是检查什么的| 上四休二是什么意思| 雍正为什么不杀十阿哥| 调休是什么意思| 看肠胃挂什么科室| 滴度是什么意思| 二月初二是什么星座| 水煎是什么意思| 干咳有痰是什么原因| 海鲜中毒有什么反应| 卤蛋是什么意思| 初潮什么意思| 每天坚持跑步有什么好处| 梦见笑是什么意思| 自作多情是什么意思| 吃什么最容易减肥| 嘚儿是什么意思| 梦见烧火做饭是什么意思| 肉桂和桂皮有什么区别| 邮件号码是什么| 女生吃什么补气血| 吴刚和嫦娥什么关系| 专家是什么意思| 口炎是什么字| 孕中期头疼是什么原因| 闭关什么意思| 拔完牙吃什么消炎药| 胸有成竹是什么生肖| 鸭子烧什么好吃| 早晨醒来口苦是什么原因| 脑供血不足头晕吃什么药| 肺在什么位置图片| 微量元素是什么| 土黄色裤子配什么颜色上衣| 晚上七点到九点是什么时辰| 草口耳是什么字| 男蛇配什么属相最好| 伽马刀是什么意思| 两个人在一起的意义是什么| 什么门永远关不上| 牙疼吃什么药效果好| 养猫需要准备什么东西| 血沉高是什么意思| 风湿免疫科是看什么病的| 男生第一次什么感觉| 梦见摘桑葚是什么意思| 正月二十一是什么星座| 喝咖啡有什么好处和坏处| 干黄酱是什么酱| 什么水果通便效果最好| 容易出汗什么原因| 为什么单位不愿意申请工伤| 东北是什么气候| 脾虚挂什么科| 半岛铁盒是什么| 为什么会有狐臭| 孩子打呼噜是什么原因| 嘴里发咸是什么原因| 梦见拉屎是什么意思| 戾气重是什么意思| 今天什么日子老黄历| 卡替治疗是什么意思| 牛皮革是什么意思| 石钟乳是什么| 脑梗输液用什么药| 海鲜配啤酒有什么反应| 宣字五行属什么| 什么姿势最深| 什么病不能吃松花粉| 微信备注是什么意思| 上呼吸道感染吃什么消炎药| 周海媚什么病| 谛听是什么| 什么动物有四个胃| 女性尿臭味重是什么病| 4.29是什么星座| 什么啤酒度数高| 糜烂性胃炎吃什么药| 卵泡期是什么时候| 十二生肖它第一是什么生肖| 肚子疼吃什么消炎药| 安宫牛黄丸什么时候吃| 男外科都检查什么| 什么是呆账| 什么教无类| 呼吸困难是什么原因| 苹果什么时候成熟| 喝酒过敏是什么原因| 增加骨密度吃什么药| 凌乱是什么意思| 戒色是什么意思| 法香是什么菜| 怀孕初期应该注意什么| 长颈鹿吃什么树叶| 今年为什么闰六月| 眉毛下方有痣代表什么| o型血可以接受什么血型| 游戏bp是什么意思| 什么的流淌| 阿胶不能和什么一起吃| 草字头加西读什么| 吃什么排毒| 为什么头朝西睡觉不好| 明天代表什么生肖| 为什么老长口腔溃疡| 牙痛 吃什么药| 减肥不能吃什么东西| 心率低吃什么药好| 孩子脾胃虚弱吃什么药| 什么时间喝酸奶最好| 腋下副乳有什么危害吗| 拆台是什么意思| 尿路感染要吃什么药| 什么胆什么心| 什么是高嘌呤食物| 肺泡是什么| 天河水是什么意思| 佛跳墙是什么东西| 混合痔是什么意思| 端午节安康是什么意思| 生蛇是什么病| 番薯是什么| 甲减是什么意思| 阻力是什么意思| 冰冻三尺的下一句是什么| 坐月子什么意思| 嗣子是什么意思| 宫颈癌什么症状| 芥末黄是什么颜色| 什么是莱赛尔纤维| 突然恶心想吐是什么原因| 甲辰年五行属什么| 眼睛流泪用什么药| 左侧卵巢无回声是什么意思| 吃黄精有什么好处| 补肾固精吃什么药好| 胆气虚吃什么中成药| 什么是脑白质病变| 兔子吃什么食物| 梦见女儿结婚是什么意思| 羊水指数和羊水深度有什么区别| 蛇爱吃什么食物| 甲状腺结节不能吃什么| eso是什么意思| 痿是什么意思| 小粉是什么粉| 属龙什么命| 女人亏气亏血吃什么补的快| 日本投降是什么时候| 什么的点头| 人为什么有两个鼻孔| 九头身是什么意思| 等闲之辈是什么意思| 雄鱼是什么鱼| 吃什么补羊水最快| 海棠花什么时候开| 骨折和骨裂有什么区别| 蛤蚧是什么动物| 脑供血不足中医叫什么| 一吃就吐是什么病症| eus是什么检查| 房间隔缺损是什么意思| 黄豆煲汤搭配什么最好| 眼睛总跳是什么原因| 什么灯不会亮| 葛根粉吃了有什么作用| 鸡精和鸡粉有什么区别| 硬度单位是什么| 打嗝是什么引起的| 什么的马| 脚酸臭是什么原因| 四海是什么意思| 咖喱块什么牌子的好| loser什么意思| 牙松动了还疼用什么方法处理最好| 坐怀不乱柳下惠什么意思| 什么叫平仓| 受精卵着床的时候会有什么症状| 血管堵塞吃什么好疏通| 美人是什么生肖| 牙龈肿痛看什么科| 喉咙长期有痰是什么原因| 立春吃什么| 伯邑考为什么不姓姬| 梦见自己丢钱了什么征兆| 说梦话是什么原因| 补气血吃什么最好最快| 肚子胀疼是什么原因| 头发油的快是什么原因| gms是什么意思| 安全三原则是指什么| 黑桃a是什么酒| 右手中指痛什么预兆| 小孩咬人是什么原因| 肝多发小囊肿什么意思| 静脉是什么意思| 便秘挂什么科| 淋巴结炎吃什么药| 钢琴八级是什么水平| 猕猴桃什么时候上市| nas是什么| 食粉是什么粉| 什么情况下才做冠脉cta| 心慌胸闷是什么原因| 什么样的防晒霜比较好| 前列腺炎有些什么症状| 挺拔的意思是什么| 保险子是什么| 青枝骨折属于什么骨折| 吃什么解辣最快方法| 及是什么意思| 头孢过敏用什么药代替| 治疗胃反酸烧心用什么药最好| 什么叫免疫力| 精修是什么意思| 变色龙指什么人| 鼻窦炎挂什么科| 宫外孕有什么危害| 布五行属什么| 七月七日是什么日子| 提手旁的字与什么有关| 鸡是什么意思| 肥什么拱门成语| 三八妇女节送什么好| 乖戾是什么意思| 冠脉ct能检查出什么| 伊朗是什么派| 芪明颗粒主治什么病| 下身瘙痒是什么原因| 吃什么可以美白| 万艾可是什么药| 蛋白粉适合什么人群吃| dl是什么| 肾萎缩吃什么药好| 12306什么时候放票| 南通有什么大学| 百度
Jump to content

组图:影后是这么带娃的!波特曼胸前挎女儿边走边喂饭

From ArchWiki
(Redirected from Create a package)
Arch package guidelines
百度 谈及此次选曲,张韶涵直言在这首歌之前,自己从没想过有一天会跟青春告别,但歌曲中每一句歌词却都让她感同身受,仿佛看到曾经倔强坚持、偶尔犯傻的懵懂自我。

32-bitCLRCMakeCrossDKMSEclipseElectronFontFree PascalGNOMEGoHaskellJavaKDEKernel modulesLispMesonMinGWNode.jsNonfreeOCamlPerlPHPPythonRRubyRust - SecurityShellVCSWebWine

This article aims to assist users creating their own packages using the ports–like Arch build system, also for submission in Arch User Repository. It covers creation of a PKGBUILD(5) — a package build description file sourced by makepkg to create a binary package from source.

For instructions regarding existing rules and ways to improve package quality, see Arch packaging standards.

Overview

Packages in Arch Linux are built using the makepkg utility and the information stored in a PKGBUILD file. When makepkg runs, it searches for a PKGBUILD in the current directory and follows the instructions in it to acquire the required files and/or compile them to be packed within a package file pkgname.pkg.tar.zst. The resulting package contains binary files and installation instructions ready to be installed by pacman.

An Arch package is no more than a tar(1) archive, or a tarball, compressed using zstd(1), which contains the following files generated by makepkg:

  • The binary files to install.
  • .PKGINFO: contains all the metadata needed by pacman to deal with packages, dependencies, etc.
  • .BUILDINFO: contains information needed for reproducible builds, also see BUILDINFO(5).
  • .MTREE: contains hashes and timestamps of the files, which are included in the local database so that pacman can verify the integrity of the package.
  • .INSTALL: an optional file used to execute commands after the install/upgrade/remove stage (this file is present only if specified in the PKGBUILD).
  • .Changelog: an optional file kept by the package maintainer documenting the changes of the package.

Preparation

Prerequisite software

First, ensure that the necessary tools are installed: the meta package base-devel should be sufficient; it pulls in make(1) and additional tools needed for compiling from source.

The key tool for building packages is makepkg (provided by pacman). The tasks it performs can be found in Arch package guidelines#Makepkg duties.

Download and test the installation

Download the source tarball of the software you want to package, extract it, and follow the author's steps to install the program. Make a note of all commands and/or steps needed to compile and install it. You will be repeating those same commands in the PKGBUILD file.

Most software authors stick to the 3-step build cycle:

$ ./configure
$ make
# make install

This is a good time to make sure the program is working correctly.

Set up clean chroot

It is recommended to follow Building in a clean chroot to ensure that packages and configuration of your system do not lead to mistakes in the PKGBUILD. This is a more robust and correct way to build packages and will often catch missing dependencies that you did not realize were needed because they already existed in your system.

Creating a PKGBUILD

When makepkg is run, it looks for a PKGBUILD file in the current working directory. If it finds one, it downloads the software's source code and compiles it according to the instructions specified in the PKGBUILD file. The instructions must be fully interpretable by the Bash shell.

After successful completion, the resulting binaries and metadata of the package, i.e. package version and dependencies, are packed in a pkgname.pkg.tar.zst package file. The newly created package can be installed by simply using makepkg --install which will call pacman in the background, or by directly using pacman -U pkgname.pkg.tar.zst.

To start building a new package, first create a new directory for the package and change current directory into this one. Then, a PKGBUILD file needs to be created: a prototype PKGBUILD found in /usr/share/pacman/ can be used or you can start from a PKGBUILD from another package. The latter may be a good choice if a similar package already exists.

PKGBUILD variables

Note The main article is PKGBUILD, also see PKGBUILD(5) § OPTIONS AND DIRECTIVES.

makepkg predefines the following variables that should be used by packagers to refer to temporary locations during the build process:

srcdir
This points to the directory where makepkg extracts or symlinks all files in the source array.
pkgdir
This points to the directory where makepkg bundles the installed package, which becomes the root directory of your built package.

They contain absolute paths, which means you do not have to worry about your working directory if you use these variables properly.

Note makepkg, and thus the build() and package() functions, are intended to be non-interactive. Interactive utilities or scripts called in those functions may break makepkg, particularly if it is invoked with build-logging enabled (--log). See FS#13214 for details.

PKGBUILD functions

When building a package, makepkg will invoke the following five functions if they have been defined in the PKGBUILD. Function package() is required in every PKGBUILD and will always be invoked. If any of the other functions is not defined, makepkg will simply skip the invocation of that function.

During the build, the functions are invoked in the order in which they are listed here.

Also see PKGBUILD(5) § PACKAGING FUNCTIONS.

prepare()

With this function, commands that are used to prepare sources for building are run, such as patching. This function runs right after package extraction, before pkgver() and the build function. If extraction is skipped (makepkg --noextract), then prepare() is not run.

Note From PKGBUILD(5): The function is run in bash -e mode, meaning any command that exits with a non-zero status will cause the function to exit.

When it is not clear whether to put something in prepare() or build(), one rule of thumb is to put in prepare() the steps that should run exactly once after extracting the sources, and put in build() the steps which would make sense to re-run after any manual edits to the extracted files.

pkgver()

pkgver() runs after the sources are fetched, extracted and prepare() executed. So you can update the pkgver variable during a makepkg stage.

This is particularly useful if you are making git/svn/hg/etc. packages, where the build process may remain the same, but the source could be updated every day, even every hour. The old way of doing this was to put the date into the pkgver field which, if the software was not updated, makepkg would still rebuild it thinking the version had changed. Some useful commands for this are git describe, hg identify -ni, etc. Please test these before submitting a PKGBUILD, as a failure in the pkgver() function can stop a build in its tracks.

Note pkgver cannot contain spaces or hyphens (-). Using sed to correct this is common.

build()

Now, you need to implement the build() function in the PKGBUILD file. This function uses common shell commands in Bash syntax to automatically compile software and create a directory called pkg to install the software to. This allows makepkg to package files without having to sift through your file system.

The first step in the build() function is to change into the directory created by uncompressing the source tarball. makepkg will change the current directory to $srcdir before executing the build() function. Therefore, in most cases, like suggested in /usr/share/pacman/PKGBUILD.proto, the first command will look like this:

cd "$pkgname-$pkgver"

Now, you need to list the same commands you used when you manually compiled the software. The build() function in essence automates everything you did by hand and compiles the software in the fakeroot build environment. If the software you are packaging uses a configure script, it is good practice to use --prefix=/usr when building packages for pacman. A lot of software installs files relative to the /usr/local directory, which should only be done if you are manually building from source. All Arch Linux packages should use the /usr directory. As seen in the /usr/share/pacman/PKGBUILD.proto file, the next two lines often look like this:

./configure --prefix=/usr
make
Note If your software does not need to build anything, do not use the build() function. The build() function is not required, but the package() function is.

check()

Place for calls to make check and similar testing routines. It is highly recommended to have check() as it helps to make sure software has been built correctly and works fine with its dependencies.

Users who do not need it (and occasionally maintainers who can not fix a package for this to pass) can disable it by adding !check into the options array in PKGBUILD/makepkg.conf(5) or call makepkg with --nocheck flag.

If you are testing a GUI application, you can run it in a virtual xserver.

package()

The final step is to put the compiled files in a directory where makepkg can retrieve them to create a package. This by default is the pkg directory—a simple fakeroot environment. The pkg directory replicates the hierarchy of the root file system of the software's installation paths. If you have to manually place files under the root of your filesystem, you should install them in the pkg directory under the same directory structure. For example, if you want to install a file to /usr/bin, it should instead be placed under $pkgdir/usr/bin. Very few install procedures require the user to copy dozens of files manually. Instead, for most software, calling make install will do so. The final line should look like the following in order to correctly install the software in the pkg directory:

make DESTDIR="$pkgdir" install
Note It is sometimes the case where DESTDIR is not used in the Makefile; you may need to use prefix instead. If the package is built with autoconf / automake, use DESTDIR; this is what is documented in the manuals. If DESTDIR does not work, try building with make prefix="$pkgdir/usr" install. If that does not work, you will have to look further into the install commands that are executed by "make <...> install".

makepkg --repackage runs only the package() function, so it creates a package without building. This may save time e.g. if you have changed just the depends variable of the package.

Note Moving files (e.g. by using mv) produced by the build() function from $srcdir to $pkgdir breaks the --repackage option of makepkg.

Testing the PKGBUILD and package

As you are writing the build() function, you will want to test your changes frequently to ensure there are no bugs. You can do this using the makepkg command in the directory containing the PKGBUILD file. With a properly formatted PKGBUILD, makepkg will create a package; with a broken or unfinished PKGBUILD, it will raise an error.

If makepkg finishes successfully, it will place a file named pkgname-pkgver.pkg.tar.zst in your working directory. This package can be installed with the pacman -U command. However, just because a package file was built does not imply that it is fully functional. It might conceivably contain only the directory and no files whatsoever if, for example, a prefix was specified improperly. You can use pacman's query functions to display a list of files contained in the package with pacman -Qlp pkgname, and the dependencies it requires with pacman -Qip pkgname.

If the package looks sane, then you are done! However, if you plan on releasing the PKGBUILD file, it is imperative that you check and double-check the contents of the depends array.

Also ensure that the package binaries actually run flawlessly! It is annoying to release a package that contains all necessary files, but crashes because of some obscure configuration option that does not quite work well with the rest of the system. If you are only going to compile packages for your own system, though, you do not need to worry too much about this quality assurance step, as you are the only person suffering from mistakes, after all.

Checking package sanity

After testing package functionality, check it for errors using namcap:

$ namcap PKGBUILD
$ namcap pkgname.pkg.tar.zst

Namcap will:

  • check PKGBUILD contents for common errors and package file hierarchy for unnecessary/misplaced files,
  • scan all ELF files in the package using ldd(1), automatically reporting which packages with required shared libraries are missing from depends and which can be omitted as transitive dependencies,
  • heuristically search for missing and redundant dependencies,

and much more.

Get into the habit of checking your packages with namcap to avoid having to fix the simplest mistakes after package submission.

Using pkgctl to build in a clean chroot environment

This article or section is a candidate for merging with Arch build system#Build package.

Notes: This page is not about the build system. There is also #Set up clean chroot and DeveloperWiki:Building in a clean chroot. (Discuss in Talk:Creating packages)

You can use pkgctl from devtools to check if the package can be built where no other packages are already installed. While in the PKGBUILD directory:

$ pkgctl build

And check the output for potential errors or warnings. If the package depends on other AUR packages, those packages must be built and brought into chroot jail:

$ pkgctl build -I path/to/somepkg.tar.gz -I ...
Note If the package is installed using an AUR helper, there is a good chance its tarball can be found in its cache directory.

Refer to pkgctl-build(1) for more options.

Submitting packages to the AUR

Please read AUR submission guidelines for a detailed description of the submission process.

Summary

  1. Download the source tarball of the software to package.
  2. Try compiling the package and installing it into an arbitrary directory.
  3. Copy over the prototype /usr/share/pacman/PKGBUILD.proto and rename it to PKGBUILD in a temporary working directory.
  4. Edit the PKGBUILD according to the needs of your package.
  5. Run makepkg and check whether the package builds correctly.
  6. If not, repeat the previous two steps.

Warnings

  • Before you can automate the package building process, you should have done it manually at least once unless you know exactly what you are doing in advance, in which case you would not be reading this in the first place. Unfortunately, although a good bunch of program authors stick to the 3-step build cycle of "./configure; make; make install", this is not always the case, and things can get real ugly if you have to apply patches to make everything work at all. Rule of thumb: If you cannot get the program to compile from the source tarball, and make it install itself to a defined, temporary subdirectory, you do not even need to try packaging it. There is not any magic pixie dust in makepkg that makes source problems go away.
  • In a few cases, the packages are not even available as source and you have to use something like sh installer.run to get it to work. You will have to do quite a bit of research (read READMEs, INSTALL instructions, man pages, perhaps ebuilds from Gentoo or other package installers, possibly even the MAKEFILEs or source code) to get it working. In some really bad cases, you have to edit the source files to get it to work at all. However, makepkg needs to be completely autonomous, with no user input. Therefore if you need to edit the makefiles, you may have to bundle a custom patch with the PKGBUILD and install it from inside the prepare() function, or you might have to issue some sed commands from inside the prepare() function.

Automation

Checksums

The process of updating checksums for new software releases can be automated by the updpkgsums tool; see Makepkg#Generate new checksums for details.

PKGBUILD generators

PKGBUILDs for some packages can be generated automatically.

Note Users are still responsible for ensuring that the package meets the high quality standards before submitting the generated files to the AUR.

New upstream releases

pkgctl (from the devtools package) supports nvchecker integration in the form of a .nvchecker.toml configuration file (which should be placed in the same directory as the PKGBUILD). See the pacman package's .nvchecker.toml configuration file for an example.

Tip pkgctl version setup will attempt to create the .nvchecker.toml configuration file automatically by analyzing the source array specified in the PKGBUILD.

You can then use pkgctl version check to check if a new upstream version has been released (compared to the one specified as pkgver in the PKGBUILD) and pkgctl version upgrade to update the PKGBUILD accordingly. See pkgctl-version(1) for more details.

See also

72年属鼠是什么命 牙刷属于什么垃圾 炼乳是什么东西 月经期可以吃什么水果 孕妇吃什么坚果比较好
杀鸡给猴看什么意思 比劫是什么意思 乌龟用什么呼吸 滋阴降火吃什么药 临床医学专业学什么
秦始皇陵为什么不敢挖 望梅止渴是什么意思 六月初四是什么星座 发情什么意思 1994年属什么生肖
总感觉饿是什么原因 绿豆不能跟什么一起吃 下巴两边长痘痘是什么原因 疱疹什么症状 色令智昏是什么意思
眩晕症是什么引起的hcv9jop5ns6r.cn 肝多发囊肿是什么意思hcv8jop2ns2r.cn 脑梗灶是什么意思wuhaiwuya.com 检查视力挂什么科hcv9jop3ns3r.cn 网友见面叫什么hcv9jop7ns3r.cn
醒酒最快的方法是什么hcv8jop1ns4r.cn 登革热是什么症状hcv8jop5ns4r.cn 白炽灯属于什么光源hcv9jop7ns9r.cn 腊肉炒什么菜好吃hcv9jop4ns8r.cn 眼睛干涩吃什么食物好hcv9jop4ns7r.cn
等闲识得东风面什么意思hcv8jop3ns8r.cn 凉席什么材质好hcv9jop5ns1r.cn 1978年属什么的onlinewuye.com 什么样的花朵hcv9jop7ns3r.cn 直捣黄龙是什么意思hcv9jop5ns0r.cn
秦时明月什么时候更新hcv8jop6ns4r.cn m1是什么单位inbungee.com 什么的雪人hcv8jop0ns8r.cn 呼呼是什么意思hcv9jop0ns7r.cn 脓疱疮是什么原因引起的hcv9jop3ns7r.cn
百度