Ubuntu 16.04 下编译dpkg和rpm

有些情况下需要使用最新的dpkg或rpm。官方源里提供的基本都是距离现在一到三年的稳定版本,想用最新的必须下载源码编译。

公共环境

安装自动化编译工具

sudo apt-get install autoconf autopoint automake libtool

dpkg

下载dpkg源码

git clone https://git.dpkg.org/git/dpkg/dpkg.git
cd dpkg

安装依赖库sudo apt-get install libncurses5-dev
直接执行./autogen

如果报错:autopoint:*** gettext version 0.19.8 or newer is required
解决方案如下:

这个报错是版本校验有问题,但是Ubuntu源里最新的就是0.19.7了,所以我这里修改如果失败的话,不打印报错,而是和校验成功执行相同的代码,亲测无伤大雅。

直接打开/usr/bin/autopoint,修改代码。这是一个脚本,在大约340行左右,找到代码:

if test -n "$xreq"; then
  if func_version_prereq "$xreq" "$archive_version"; then
    ver="$archive_version"
  else  
    ver="$archive_version" # 复制if下的这一行到else这里
    # 把下面这一行直接注释掉!!!!!!!
    # func_fatal_error "gettext version $xreq or newer is required"  
  fi    
else  
  if test -z "$xver" && test -f intl/VERSION; then
    xver=`cat intl/VERSION | LC_ALL=C sed -n -e 's/^.*gettext-\([-+_.0-9A-Za-z]*\).*$/\1/p'`
  fi

成功后生成configure文件,直接./configure
可能会报错perl必须 >= 5.24.1 源内最新版本是5.22,可以从官网下最新的版本然后编译安装。

wget https://www.cpan.org/src/5.0/perl-5.30.1.tar.gz
tar zxvf perl-5.30.1.tar.gz
cd perl-5.30.1/
./Configure 
# 过程中出现问询直接一路回车到底
# 遇到prefix输入/usr回车。 默认会安装到/usr/local。 
# 那样的话在make install之后还要手动创建软连接直到新版本
# 才能让dpkg的configure通过。
make 
sudo make install 

成功后生成Makefile,执行make
如果需要安装到系统目录中,执行sudo make install

rpm

下载rpm源码

git clone https://github.com/rpm-software-management/rpm.git
cd rpm

下载安装依赖库:

扫描二维码关注公众号,回复: 11156646 查看本文章
sudo apt-get install libnss3-dev  libnspr4-dev  zlib1g-dev libgcrypt20-dev libgcrypt20  libmagic-dev  libdb-dev  libpopt-dev  libarchive-dev  lua5.2  liblua5.2-dev liblzma-dev

修改配置脚本vi autogen.sh为:

#!/bin/sh

export CPPFLAGS
export CFLAGS="-I/usr/include/lua5.2 -I/usr/include/nspr -I/usr/include/nss"
export LDFLAGS="-llua5.2"
export LUA_LIBS="-I/usr/lib64" 
export LUA_CFLAGS="-I/usr/bin"


autoreconf -i

sed -i "s/sysconfdir='\${prefix}\/etc'/sysconfdir='\/etc'/g" ./configure  # 自动生成的configure文件中,sysconfdir的路径指定的是{$prefix}/etc,打包的时候会有问题,应该改为/etc

case "$1" in
  "--noconfigure")
    exit 0;
    ;;  
  "--rpmconfigure")
    shift
    eval "`rpm --eval %configure`" "$@"
    ;;  
  *)  
    ./configure "$@" --prefix="/usr"  # /usr 是安装的路径,不改的话默认为/usr/local
    ;;  
esac

执行./autogen.sh
完后别着急编译,打开生成的configure文件1073行:
sysconfdir={prefix}/etc改成/etc
然后再次执行./autogen.sh
成功后生成Makefile
编译安装

make 
sudo make install 

安装旧版的rpm(4.12)会出现问题db的问题的处理:

下载旧版的rpm

wget https://github.com/rpm-software-management/rpm/archive/rpm-4.12.0.1-release.tar.gz
tar zxvf rpm-4.12.0.1-release.tar.gz
cd rpm-4.12.0.1-release/

修改autogen.sh,内容和上面一样。然后执行./autogen.sh
然而报错:

configure: error: internal Berkeley DB directory not present, see INSTALL

报错已经提到了see INSTALL,查看INSTALL文件之内的内容,给出了两个解决方案。按照给出的方案即可解决编译。

修改autogen.sh为:

#!/bin/sh

export CPPFLAGS="-I/usr/include/db45"
export CFLAGS="-I/usr/include/lua5.2 -I/usr/include/nspr -I/usr/include/nss"
export LDFLAGS="-llua5.2"
export LUA_LIBS="-I/usr/lib64" 
export LUA_CFLAGS="-I/usr/bin"


autoreconf -i

case "$1" in
  "--noconfigure")
    exit 0;
    ;;  
  "--rpmconfigure")
    shift
    eval "`rpm --eval %configure`" "$@"
    ;;  
  *)  
    ./configure "$@" --prefix="/usr" --with-external-db
    ;;  
esac
原创文章 39 获赞 33 访问量 2万+

猜你喜欢

转载自blog.csdn.net/Three_dog/article/details/103418141