Arch下所有软件的安装都是通过pacman来管理的,不过pacman只会根据/etc/pacman.d/mirrorlist中提供的镜像来下载最新版的软件。
如果你需要一些老版的软件,例如gcc 4.1.2这种“比较老”的编译器,用pacman是搞不定的,这时候需要用到另外一套系统pkgbuild。
以安装gcc 4.1.2为例子。
首先到AUR上找到gcc 4.1.2的PKGBUILD文件:https://aur.archlinux.org/packages/gcc41/
raywill@localhost /home/raywill/tools $ cat PKGBUILD
# Contributor: Claudio Pisa <clauz@ninux.org>
# based con gcc43 PKGBUILD
pkgname=gcc41
_ver=4.1
pkgver=4.1.2
pkgrel=1
pkgdesc="The GNU Compiler Collection"
arch=('i686' 'x86_64')
license=('GPL' 'LGPL')
url="http://gcc.gnu.org"
depends=('glibc' 'binutils' 'gmp' 'mpfr' 'ppl')
makedepends=('flex' 'bison')
options=('!libtool')
source=(ftp://gcc.gnu.org/pub/gcc/releases/gcc-${pkgver}/gcc-{core,g++}-${pkgver}.tar.bz2)
md5sums=('2af3fb599635219171c6ae1f3034888a'
'75c6d5fa3415d614314caf0f509e8933'
'39621038e425c73f955db8c8db411c34'
'abda05c0ab99059e8f9e7a625361fd87')
build() {
if ! locale -a | grep ^de_DE; then
echo "You need the de_DE locale to build gcc."
return 1
fi
cd ${srcdir}/gcc-${pkgver}
# Don't install libiberty
sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in
echo ${pkgver} > gcc/BASE-VER
# Don't run fixincludes
sed -i -e 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
mkdir build
cd build
../configure --prefix=/usr --enable-shared \
--enable-languages=c,c++ \
--enable-threads=posix --mandir=/usr/share/man --infodir=/usr/share/info \
--enable-__cxa_atexit --disable-multilib --libdir=/usr/lib \
--libexecdir=/usr/lib --enable-clocale=gnu --disable-libstdcxx-pch \
--with-tune=i686 \
--disable-werror --enable-checking=release \
--program-suffix=-${_ver} --enable-version-specific-runtime-libs
make || return 1
make DESTDIR=${pkgdir} install || return 1
# Lazy way of dealing with conflicting man and info pages...
rm -rf ${pkgdir}/usr/share
}
将PKGBUILD文件下载到本地,然后执行makepkg,它会自动分析PKGBUILD描述的任务,下载依赖包、gcc安装包等,下载完毕后会自动编译。可能的输出:
raywill@localhost /home/raywill/tools $ makepkg
==> Making package: gcc41 4.1.2-1 (Sun Aug 25 22:58:42 UTC 2013)
==> WARNING: Using a PKGBUILD without a package() function is deprecated.
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
-> Downloading gcc-core-4.1.2.tar.bz2...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 16.6M 100 16.6M 0 0 19652 0 0:14:49 0:14:49 --:--:-- 42037
-> Downloading gcc-g++-4.1.2.tar.bz2...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
61 3719k 61 2288k 0 0 15009 0 0:04:13 0:02:36 0:01:37 19470
下载过程走的是代理服务器。对应pacman,需要设置/etc/pacman.conf中的XferCommand = /usr/bin/curl --socks4a 192.168.17.2:1080 -C - -f %u > %o 。
--socks4a 192.168.17.2:1080表示走socks代理,并指定了代理ip和端口。
对于makepkg,也需要设置代理,设置文件/etc/makepkg.conf,如下,里面ip端口跟上面一致。
DLAGENTS=('ftp::/usr/bin/curl --socks4a 192.168.17.2:1080 -fC - --ftp-pasv --retry 3 --retry-delay 3 -o %o %u'
'http::/usr/bin/curl --socks4a 192.168.17.2:1080 -fLC - --retry 3 --retry-delay 3 -o %o %u'
'https::/usr/bin/curl --socks4a 192.168.17.2:1080 -fLC - --retry 3 --retry-delay 3 -o %o %u'
'rsync::/usr/bin/rsync --no-motd -z %u %o'
'scp::/usr/bin/scp -C %u %o')
为了找到makepkg配置文件的位置,我用到了strace,通过跟踪makepkg用到的open调用才知道makepkg.conf的绝对位置。这是个小技巧,大家可以学习下。
strace makepkg 1 > log.txt 2 > log.txt
然后在log.txt中搜conf关键字即可找到。
总结一下:
pacman,负责安装最新的应用。
makepkg,负责安装一些老版本的应用。这些老应用在Mirror Site上不存在,但在AUR上可以下载到。
raywill@localhost /home/raywill/tools $ cat PKGBUILD
# Contributor: Claudio Pisa <clauz@ninux.org>
# based con gcc43 PKGBUILD
pkgname=gcc41
_ver=4.1
pkgver=4.1.2
pkgrel=1
pkgdesc="The GNU Compiler Collection"
arch=('i686' 'x86_64')
license=('GPL' 'LGPL')
url="http://gcc.gnu.org"
depends=('glibc' 'binutils' 'gmp' 'mpfr' 'ppl')
makedepends=('flex' 'bison')
options=('!libtool')
source=(ftp://gcc.gnu.org/pub/gcc/releases/gcc-${pkgver}/gcc-{core,g++}-${pkgver}.tar.bz2)
md5sums=('2af3fb599635219171c6ae1f3034888a'
'75c6d5fa3415d614314caf0f509e8933'
'39621038e425c73f955db8c8db411c34'
'abda05c0ab99059e8f9e7a625361fd87')
build() {
if ! locale -a | grep ^de_DE; then
echo "You need the de_DE locale to build gcc."
return 1
fi
cd ${srcdir}/gcc-${pkgver}
# Don't install libiberty
sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in
echo ${pkgver} > gcc/BASE-VER
# Don't run fixincludes
sed -i -e 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
mkdir build
cd build
../configure --prefix=/usr --enable-shared \
--enable-languages=c,c++ \
--enable-threads=posix --mandir=/usr/share/man --infodir=/usr/share/info \
--enable-__cxa_atexit --disable-multilib --libdir=/usr/lib \
--libexecdir=/usr/lib --enable-clocale=gnu --disable-libstdcxx-pch \
--with-tune=i686 \
--disable-werror --enable-checking=release \
--program-suffix=-${_ver} --enable-version-specific-runtime-libs
make || return 1
make DESTDIR=${pkgdir} install || return 1
# Lazy way of dealing with conflicting man and info pages...
rm -rf ${pkgdir}/usr/share
}