Alpine 包维护


# 准备
mkdir buiild && cd build
git clone --depth 50
# 启动环境
# 配置缓存
docker run --rm -it \
-v $PWD:/build \
-v $PWD/distfiles:/var/cache/distfiles \
-v $PWD/cache:/etc/apk/cache \
--name builder wener/base:builder
# 更新仓库
sudo apk update
# git 用户配置
git config --global "Your Full Name"
git config --global "[email protected]"
# 个人信息
[ -e ~/.abuild/abuild.conf ] || { mkdir -p ~/.abuild; echo "PACKAGER=\"$(git config --global <$(git config --global>\"" > ~/.abuild/abuild.conf; }
# 生成密钥
grep PACKAGER_PRIVKEY ~/.abuild/abuild.conf || abuild-keygen -ani
# 打包
# community/grpc
cd aports/community/grpc
# 编译构建到 ~/packages
# -K 保留 src 和 pkg - 用于开发调试
# -r 安装依赖
abuild -Kr
# /var/cache/distfiles
abuild checksum
abuild -r
# 位于 $HOME/packages/main/x86_64
abuild -Kf
# 针对单个包操作
abuild package dev
# 移除所有构建时安装的依赖
# 直接编辑 /etc/apk/world 然后 apk fix 也可以
apk del '.makedepends-*'
rsync -avz --no-perms --no-owner --no-group --exclude='src,pkg' mnt/wener abuild/


# 默认环境


export CFLAGS="-Os -fomit-frame-pointer"
export LDFLAGS="-Wl,--as-needed"
export GOFLAGS="-buildmode=pie"
# Do note that these should work with at least GDC and LDC
export DFLAGS="-Os"
export JOBS=2
# remove line below to disable colors
# uncomment line below to enable ccache support.
# uncomment line below to store built packages in other location
# The package will be stored as $REPODEST/$repo/$pkgname-$pkgver-r$pkgrel.apk
# where $repo is the name of the parent directory of $startdir.
# PACKAGER and MAINTAINER are used by newapkbuild when creating new aports for
# the APKBUILD's "Contributor:" and "Maintainer:" comments, respectively.
#PACKAGER="Your Name <[email protected]>"
# what to clean up after a successful build
CLEANUP="srcdir bldroot pkgdir deps"
# what to cleanup after a failed build
ERROR_CLEANUP="bldroot deps"

生成和使用 Patch

cd src/dahdi-linux-3.1.0/
cp include/kernel.h include/
nano include/
diff -u include/kernel.h include/ > ../../kernel-compact-5.4.patch
# 添加 patch
abuild checksum
# 验证 patch 正确性
rm -rf src; abuild prepare && abuild prepare
# 构建
abuild -r


$ abuild -h
usage: abuild [options] [-P REPODEST] [-s SRCDEST] [-D DESCRIPTION] [cmd] ...
abuild [-c] -n PKGNAME[-PKGVER]
-A Print CARCH and exit
-c Enable colored output
-d Disable dependency checking
-D Set APKINDEX description (default: $repo $(git describe))
-f Force specified cmd (skip checks: apk up to date, arch, libc)
-F Force run as root
-h Show this help
-k Keep built packages, even if APKBUILD or sources are newer
-K Keep buildtime temp dirs and files (srcdir/pkgdir/deps)
-m Disable colors (monochrome)
-P Set REPODEST as the repository location for created packages
-q Quiet
-r Install missing dependencies from system repository (using sudo)
-s Set source package destination directory
-v Verbose: show every command as it is run (very noisy)
build Compile and install package into $pkgdir
check Run any defined tests concerning the package
checksum Generate checksum to be included in APKBUILD
clean Remove temp build and install dirs
cleancache Remove downloaded files from $SRCDEST
cleanoldpkg Remove binary packages except current version
cleanpkg Remove already built binary and source package
deps Install packages listed in makedepends and depends
fetch Fetch sources to $SRCDEST (consider: 'abuild fetch verify')
index Regenerate indexes in $REPODEST
listpkg List target packages
package Install project into
prepare Apply patches
rootbld Build package in clean chroot
rootpkg Run 'package', the split functions and create apks as fakeroot
sanitycheck Basic sanity check of APKBUILD
snapshot Create a $giturl or $svnurl snapshot and upload to $disturl
sourcecheck Check if remote source package exists upstream
srcpkg Make a source package
undeps Uninstall packages listed in makedepends and depends
unpack Unpack sources to $srcdir
up2date Compare target and sources dates
verify Verify checksums
To activate cross compilation specify in environment:
CHOST Arch or hostspec of machine to generate packages for
CTARGET Arch or hostspec of machine to generate compiler for


Invalid configuration x86_64-alpine-linux-musl: machine x86_64-alpine-linux not recognized

  • 可以将 --build--host 设置为 x86_64-alpine-linux
  • 因为部分项目构建是无法将 musl 识别为 gnu