为Gentoo gstreamer ebuild制作Loongarch补丁
gstreamer跟ffmpeg一样,也是一个媒体框架,可以实现采集,编码,解码,渲染,滤镜等一条龙的媒体解决方案,很多软件都需要它的支持。
在Gentoo For Loongarch版上emerge media-libs/gstreamer的时候,遇到错误提示
>>> Failed to emerge media-libs/gstreamer-1.20.1, Log file:
>>> ‘/var/tmp/portage/media-libs/gstreamer-1.20.1/temp/build.log’
* Messages for package media-libs/gstreamer-1.20.1:
* ERROR: media-libs/gstreamer-1.20.1::gentoo failed (compile phase):
* ninja -v -j4 -l0 failed
*
* Call stack:
* ebuild.sh, line 127: Called src_compile
* environment, line 3076: Called multilib-minimal_src_compile
* environment, line 2084: Called multilib_foreach_abi ‘multilib-minimal_abi_src_compile’
* environment, line 2351: Called multibuild_foreach_variant ‘_multilib_multibuild_wrapper’ ‘multilib-minimal_abi_src_compile’
* environment, line 2044: Called _multibuild_run ‘_multilib_multibuild_wrapper’ ‘multilib-minimal_abi_src_compile’
* environment, line 2042: Called _multilib_multibuild_wrapper ‘multilib-minimal_abi_src_compile’
* environment, line 616: Called multilib-minimal_abi_src_compile
* environment, line 2078: Called multilib_src_compile
* environment, line 2563: Called gstreamer_multilib_src_compile
* environment, line 1733: Called eninja
* environment, line 1281: Called die
* The specific snippet of code:
* “$@” || die “${nonfatal_args[@]}” “${*} failed”
*
* If you need support, post the output of ‘emerge --info ‘=media-libs/gstreamer-1.20.1::gentoo'’,
* the complete build log and the output of ‘emerge -pqv ‘=media-libs/gstreamer-1.20.1::gentoo'’.
* The complete build log is located at ‘/var/tmp/portage/media-libs/gstreamer-1.20.1/temp/build.log’.
* The ebuild environment file is located at ‘/var/tmp/portage/media-libs/gstreamer-1.20.1/temp/environment’.
* Working directory: ‘/var/tmp/portage/media-libs/gstreamer-1.20.1/work/gstreamer-1.20.1-.lp64d’
* S: ‘/var/tmp/portage/media-libs/gstreamer-1.20.1/work/gstreamer-1.20.1‘
经过对build.log的分析定位错误位置和原因,是认不到架构,由于Loongarch是比较新的架构,很多软件在编写时候没有把它写进去,但是做一些简单修改后,是可以在Loongarch电脑上正常编译运行的。
./gst/gstconfig.h:132:4: error: #error “Could not detect architecture; don’t know whether it supports una
ligned access! Please file a bug.”
进入编译工作目录
#cd /var/tmp/portage/media-libs/gstreamer-1.20.1/work/gstreamer-1.20.1-.lp64d
编辑gst/gstconfig.h,对于不认识Loongarch这种问题,我们在解决的时候,首先查找它的亲戚mips,找到后照样子添加loongarch的支持代码即可。
#nano gst/gstconfig.h
#if defined(__alpha__) || defined(__arc__) || defined(__arm__) || defined(__aarch64__) || defined(__bfin)
|| defined(__hppa__) || defined(__nios2__) || defined(__MICROBLAZE__) || defined(__mips__) || defined(__
or1k__) || defined(__sh__) || defined(__SH4__) || defined(__sparc__) || defined(__sparc) || defined(__ia6
4__) || defined(_M_ALPHA) || defined(_M_ARM) || defined(_M_ARM64) || defined(_M_IA64) || defined(__xtensa
__) || defined(__e2k__) || defined(__riscv) || defined(__ARC64__) || defined(__loongarch__)
保存退出
#ninja
编译通过
问题成功解决后我们开始制作补丁文件。
进入源码目录
cd /var/tmp/portage/media-libs/gstreamer-1.20.1/work/gstreamer-1.20.1
同样编辑gst/gstconfig.h,发现文件不存在
使用通配符查找,发现文件和工作目录下的有点不一样,但内容是一样的,那要修改的文件就是它了
#ls gst/gstconfig*
gst/gstconfig.h.in
先对文件进行备份
#mkdir b
#cp gst/gstconfig.h.in b/
然后对备份的文件进行修改
#nano b/gstconfig.h.in
#if defined(__alpha__) || defined(__arc__) || defined(__arm__) || defined(__aarch64__) || defined(__bfin)
|| defined(__hppa__) || defined(__nios2__) || defined(__MICROBLAZE__) || defined(__mips__) || defined(__
or1k__) || defined(__sh__) || defined(__SH4__) || defined(__sparc__) || defined(__sparc) || defined(__ia6
4__) || defined(_M_ALPHA) || defined(_M_ARM) || defined(_M_ARM64) || defined(_M_IA64) || defined(__xtensa
__) || defined(__e2k__) || defined(__riscv) || defined(__ARC64__) || (defined__loongarch__)
修改完成后用diff命令制作补丁
#diff -Nur gst/gstconfig.h.in b/gstconfig.h.in >> ~/add_loongarch.patch
修改补丁文件前两行路径
#nano ~/add_loongarch.patch
--- a/gst/gstconfig.h.in 2022-03-14 11:33:40.000000000 -0000
+++ b/gst/gstconfig.h.in 2022-03-29 00:36:09.033428510 -0000
保存退出
在loongson overlay的文件夹下建立media-libs文件夹
#mkdir /var/db/repos/loongson/media-libs
复制gentoo下的gstreamer文件夹到刚才建立的文件夹中
#cp -rf /var/db/repos/gentoo/media-libs/gstreamer /var/db/repos/loongson/media-libs/
#cd /var/db/repos/loongson/media-libs/gstreamer/
建立存放补丁的文件夹
#mkdir files
复制补丁文件
#cp ~/add_loongarch.parth files/
编辑ebuild文件,增加两处
#nano gstreamer-1.20.1.ebuild
1)在KEYWORDS中加入loong
KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~loong ~mips ~ppc ~ppc64 ~riscv ~sparc ~x86 ~amd64-li
nux ~x86-linux ~ppc-macos ~x64-macos ~sparc-solaris ~x64-solaris ~x86-solaris”
2)在multilib_src_configure()位置上方添加以下内容
PATCHES=(
“${FILESDIR}/add_loongarch.patch”
)
最后,更新Manifest
#ebuild gstreamer-1.20.1.ebuild digest
整个补丁制作完成
现在可以成功安装gstreamer了
#emerge media-libs/gstreamer