deepin-riscv修包经验总结--以netkit-telnet为例

一、相关概念

软件打包:

​ 软件打包就是将上游源代码进行构建,生成二进制包,通常格式为*.deb。

常规打包流程(from github deepin-community):

​ 从github clone软件包源代码-->检查debian目录文件是否完备-->使用quilt打上历史补丁-->使用dpkg-buildpackage -b -us -uc命令完整重构建-->测试deb包是否能正常安装和卸载。

quilt:

​ quilt是debian打包过程中的补丁管理工具。以下是常用命令:

quilt new *.patch //创建补丁,会在series中自动添加记录
quilt add *       //将*文件添加到quilt中管理
quilt refresh     //文件修改后更新patch
quilt header -e   //对patch添加描述,会自动进入编辑器
quilt push -a     //对当前软件包打上所有patch
quilt pop  -a     //对当前软件包卸载所有patch

quilt配置,用以下配置方便使用[ref:Debian 新维护者手册]

quilt 程序是 Debian 打包过程中采用的补丁管理工具。我们只需要在默认配置的基础上,加以少许修改即可。首先我们来创建一个别名 dquilt,以方便打包之需: 添加以下几行内容到 ~/.bashrc 文件中。其中第二行可以给 dquilt 命令提供与 quilt 命令相同的 shell 补全:

alias dquilt="quilt --quiltrc=${HOME}/.quiltrc-dpkg"
. /usr/share/bash-completion/completions/quilt
complete -F _quilt_completion -o filenames dquilt

现在我们来创建 ~/.quiltrc-dpkg 文件:

d=. ; while [ ! -d $d/debian -a $(readlink -e $d) != / ]; do d=$d/..; done
if [ -d $d/debian ] && [ -z $QUILT_PATCHES ]; then
    # if in Debian packaging tree with unset $QUILT_PATCHES
    QUILT_PATCHES="debian/patches"
    QUILT_PATCH_OPTS="--reject-format=unified"
    QUILT_DIFF_ARGS="-p ab --no-timestamps --no-index --color=auto"
    QUILT_REFRESH_ARGS="-p ab --no-timestamps --no-index"
    QUILT_COLORS="diff_hdr=1;32:diff_add=1;34:diff_rem=1;31:diff_hunk=1;33:diff_ctx=35:diff_cctx=33"
    if ! [ -d $d/debian/patches ]; then mkdir $d/debian/patches; fi
fi

二、修包过程

注意:以下操作在qemu的deepin-riscv64环境下进行

1、在github上fork netkit-telnet软件包

2、git clone

3、打上所有历史补丁dquilt push -a

4、尝试构建软件包dpkg-buildpackage -b -us -uc

5、编译失败,出现报错信息

...
cd /root/git_fix/netkit-telnet/obj-riscv64-linux-gnu/telnetd && /usr/bin/cmake -E cmake_link_script CMakeFiles/in.telnetd.dir/link.txt --verbose=1
/usr/bin/cc          -D_GNU_SOURCE     -Ddebian     -DACCEPT_USERVAR     -Wall     -Wno-trigraphs      -DISSUE_FILE='"/etc/issue.net"'     -DPARANOID_TTYS     -DNO_REVOKE     -DKLUDGELINEMODE     -DDIAGNOSTICS     -DLOGIN_WRAPPER='"/usr/lib/telnetlogin"'  CMakeFiles/in.telnetd.dir/global.c.o CMakeFiles/in.telnetd.dir/setproctitle.c.o CMakeFiles/in.telnetd.dir/slc.c.o CMakeFiles/in.telnetd.dir/state.c.o CMakeFiles/in.telnetd.dir/sys_term.c.o CMakeFiles/in.telnetd.dir/telnetd.c.o CMakeFiles/in.telnetd.dir/termstat.c.o CMakeFiles/in.telnetd.dir/utility.c.o -o in.telnetd  -lncurses -lutil 
/usr/bin/ld: CMakeFiles/telnet.netkit.dir/telnet.cc.o: in function `.L0 ':
telnet.cc:(.text+0xfb6): undefined reference to `tgetent'
collect2: error: ld returned 1 exit status
make[3]: *** [telnet/CMakeFiles/telnet.netkit.dir/build.make:276: telnet/telnet.netkit] Error 1
make[3]: Leaving directory '/root/git_fix/netkit-telnet/obj-riscv64-linux-gnu'
make[2]: *** [CMakeFiles/Makefile2:137: telnet/CMakeFiles/telnet.netkit.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....
make[3]: Leaving directory '/root/git_fix/netkit-telnet/obj-riscv64-linux-gnu'
[100%] Built target in.telnetd
make[2]: Leaving directory '/root/git_fix/netkit-telnet/obj-riscv64-linux-gnu'
make[1]: *** [Makefile:139: all] Error 2
make[1]: Leaving directory '/root/git_fix/netkit-telnet/obj-riscv64-linux-gnu'
dh_auto_build: error: cd obj-riscv64-linux-gnu && make -j8 VERBOSE=1 returned exit code 2
make: *** [debian/rules:4: build] Error 2
dpkg-buildpackage: error: debian/rules build subprocess returned exit status 2

注意到error出现的信息telnet.cc:(.text+0xfb6): undefined reference to 'tgetent'

通过google查询得知此问题出现的原因是ncurses is not linked with telnet by default,所以需要将telnet精确链接到ncurses。

因此在CMakelists.txt文件中添加target_link_libraries(telnet.netkit ${CURSES_LIBRARIES})使得telnet.netkit软件包编译过程中能链接到ncurses。

6、添加patch

新建patch

dquilt new add-missing-lib.patch

将CMakelists.txt添加到quilt管理

dquilt add /debian/CMakelists.txt

修改CMakelists.txt文件

refresh patch,自动生成补丁

dquilt refresh

编写补丁描述

dquilt header -e

最终的patch如下:

Description: Link with the missing ncurses library
Author: Authorname <username@email.com>
--- a/telnet/CMakeLists.txt
+++ b/telnet/CMakeLists.txt
@@ -1,4 +1,5 @@
-
+find_package(Curses REQUIRED)
+include_directories(${CURSES_INCLUDE_DIR})
 set(
     CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
     -DUSE_TERMIO \
@@ -20,6 +21,7 @@
     tn3270.cc
     utilities.cc
 )
+target_link_libraries(telnet.netkit ${CURSES_LIBRARIES})
 install(
     TARGETS telnet.netkit
     DESTINATION ${BIN_DIR}

再次尝试dpkg-buildpackage -b -rfakeroot -us -uc,构建成功,在上级目录找到*.deb文件,使用dpkg命令测试安装和卸载,未出现报错信息,至此,修包完成。
使用dch -i来编辑changelog。changelog中版本号规则可查看:https://wiki.deepin.org/zh/01_deepin配套生态/01_deepin入门/02_开发相关/deepin-community分支与Tag管理

+ netkit-telnet (0.17.1-deepin1) unstable; urgency=medium
+
+  * Fix build on RISC-V
+
+ -- Author <xxx@xxx>  Fri, 18 Nov 2022 04:11:01 +0000

netkit-telnet (0.17-42) unstable; urgency=medium

  * QA upload.
  * Orphan package (no maintainer activity since 2016).
  * Add debian/patches/telnet-netbufwrite-fix.diff (Closes: #974428)
    - Thanks to Nachiketa Prachanda for the patch.
 -- Andreas Henriksson <andreas@fatal.se>  Wed, 17 Feb 2021 14:41:40 +0100
...

最后在github上提交changelog+patch+series的pr。

posted @ 2022-11-19 21:17  Gui-Yue  阅读(337)  评论(0编辑  收藏  举报