构建环境
https://wiki.alpinelinux.org/wiki/Creating_an_Alpine_package
alpine-sdk
元包,包括以下三个包(安装 meta 包后,依赖会自动安装)
- abuild
- build-base
- git
build-base
也是元包,一部分是 abuild 需要的运行时依赖:
- binutils 构建相关,链接小工具
- file 检测文件类型
- patch 打 patch 用,musl 发行版需要很多 patch,还有上游的更新补丁
另一部分是大部分构建都需要的工具链:
- gcc、g++
- make
- libc-dev 约等于 musl-dev
- fortify-headers 缓冲区检查宏
所以 APKBUILD 中 makedepends 不需要再把 gcc make 写进来啦!每台打包机都默认安装了这些包
abuild
bin/abuild
根据 APKBUILD 拉取源码并更新配置文件中的校验值(构建需要)
$ abuild checksum
自动安装依赖并在构建完成后卸载依赖,自动完成整个构建过程
$ abuild -r
启动沙盒环境进行纯净构建,等同于手动创建 chroot 环境(需要安装 abuild-rootbld 包)
$ abuild rootbld
bin/newapkbuild
newapkbuild 使用模板新建(会自动创建文件夹)
$ newapkbuild -h
newapkbuild 3.12.0-r0 - generate a new APKBUILD
Usage: newapkbuild [-n PKGNAME] [-d PKGDESC] [-l LICENSE] [-u URL]
[-a | -C | -m | -p | -y | -r] [-s] [-c] [-f] [-h]
PKGNAME[-PKGVER] | SRCURL
Options:
-n Set package name to PKGNAME (only use with SRCURL)
-d Set package description to PKGDESC
-l Set package license to LICENSE, use identifiers from:
<https://spdx.org/licenses/>
-u Set package URL
-a Create autotools package (use ./configure ...)
-C Create CMake package (Assume cmake/ is there)
-m Create meson package (Assume meson.build is there)
-p Create perl package (Assume Makefile.PL is there)
-y Create python setuptools package (Assume setup.py is there)
-e Create python gpep517 package (Assume pyproject.toml is there)
-r Create rust package (Assume Cargo.toml is there)
-s Use sourceforge source URL
-c Copy a sample init.d, conf.d, and install script
-f Force even if directory already exists
-h Show this help
abuild-rootbld
$ apk add abuild-rootbld
注意事项:https://wiki.alpinelinux.org/wiki/Include:AbuildRootBld
- options 添加 net
- 上级目录下添加
.rootbld-repositories文件指定仓库或镜像(官方的 aports 自带) - 保持文件结构像
~/aports或设置环境变量APORTSDIR=$(PWD)
由于每次都是重新下载安装环境,因此可以开启安装包缓存
$ setup-apkcache
以及指定镜像源来减少等待时间。
$ mirror=http://mirrors.tuna.tsinghua.edu.cn/alpine abuild rootbld
这里的环境变量 mirror 生效是因为官方 aports 的 .rootbld-repositories 中有预留变量
lab ~/aports/community
$ bat .rootbld-repositories -p
$mirror/$version/main
$mirror/$version/community