功能点:使用linuxdeployqt 使用dkpg打包deb,自动替换版本号
注意:此代码并不能给各位开箱即用,需要根据实际修改部分使用
linuxdeployqt ${package_path}/${exe_name} -unsupported-allow-new-glibc -verbose=1 -qmake=/home/xhp/Qt/5.15.2/gcc_64/bin/qmake, 我觉得这能有用
linuxdeployqt源代码:https://github.com/probonopd/linuxdeployqt
deb打包的软件包结构:
cat ./com.xx.xx/DEBIAN/control
Package: com.demo.test
Version: 1.6.0.3
Priority: optional
Architecture: amd64
Maintainer: xxx[xxx@xxx.xx]
Depends: libxcb-xinerama0
Build-Depends: debhelper (>= 11)
Standards-Version: 4.1.3
Homepage: http://www.xxx.com
Description: xxxx客户端
下面是一个完整的项目发布为deb的shell脚本:
version=""
addlibtype=""
package_root="./com.demo.test" #软件包路径
package_name="com.demo.test" #软件包名称
# echo "$@"
while getopts "av:h" opt; do
case $opt in
a)
addlibtype="all"
echo "-a 重新打包全部库 by linuxdeployqt"
;;
v)
version=$OPTARG
echo "-v 指定本次打包版本: ${version} index:$OPTIND"
sed -i "2c Version:\ ${version}" ${package_root}/DEBIAN/control
sed -i "4c \"version\":\ \"${version}\"," ${package_root}/opt/apps/${package_name}/info
;;
:)
echo "Option -$OPTARG requires an argument."
exit 1
;;
h)
echo "-a 重新打包全部库"
echo "-v 指定本次打包版本"
exit 1
;;
?) #当有不认识的选项的时候arg为?
echo "Invalid option: -$OPTARG index:$OPTIND"
exit 1
;;
esac
done
if [ "$version" == "" ];then
echo "未指定本次打包版本 -v"
exit 1
fi
#add qt env
export PATH=/home/Qt/5.15.2/gcc_64/bin:$PATH
export LIB_PATH=/home/Qt/5.15.2/gcc_64/lib:$LIB_PATH
export PLUGIN_PATH=/home/Qt/5.15.2/gcc_64/plugins:$PLUGIN_PATH
export QML2_PATH=/home/Qt/5.15.2/gcc_64/qml:$QML2_PATH
exe_path="../64/Release/"
exe_name="jyclient"
exe_file_path=$exe_path$exe_name
common_path="../64/Common"
package_path="${package_root}/opt/apps/${package_name}/files/bin/"
if [ ! -f ${exe_file_path} ];then
echo -e "ERROR: ${exe_file_path}不存在\n"
exit 2
fi
echo "拷贝exe文件 拷贝Common目录 [${exe_path} ===> ${package_path}]"
cp -f ${exe_file_path} ${package_path}
cp -rf ${common_path} ${package_path}../
if [ "$addlibtype" == "all" ];then
echo "${package_path}${exe_name} 开始运行 linuxdeployqt"
#另一种加载所需库方式 ldd
# output_path=$(cd "$(dirname "$0")";pwd)
# deplist=$(ldd ${exe_name} | awk '{if (match($3,"/")){ printf("%s "),$3 } }')
# echo "depends libs: $deplist"
# echo "开始拷贝动态库到exe目录下"
# cp $deplist $output_path
linuxdeployqt ${package_path}/${exe_name} -unsupported-allow-new-glibc -verbose=1 -qmake=/home/xhp/Qt/5.15.2/gcc_64/bin/qmake
else
echo "${package_path}${exe_name} 开始拷贝自建动态库"
cp $exe_path/*.so ${package_path}../lib/
fi
echo "成功"
echo "打包目录大小:"
du -hs ${package_root}
echo "开始dpkg..."
export_file_name="${package_name}-${version}"
dpkg -b ${package_name} ${export_file_name}.deb