教你如何将你的Qt项目打包安装在MeeGo系统中

教你如何将你的Qt项目打包安装在MeeGo系统中

本帖最后由 暗影 于 2010-7-25 12:01 编辑
原文链接http://www.meegochinadev.com/viewthread.php?tid=68&extra=page%3D1
简介

本文将教你怎样将你写的Qt项目打包并安装在MeeGo设备上运行。这里通过Qt示例中一个名叫"textures"的OpenGL项目来为例来讲述。这个原始项目是一个没有图标不能从MeeGo UI 启动的Qt例子,我们将使它看起来更像一个独立的应用程序,可以从MeeGo 应用程序面板中直接启动并且以rpm包格式安装在MeeGo设备上。

前期准备

准备材料是一个包含在qt-example包中的Qt demo例子,具体位置在 /usr/lib/qt4/example/opengl/textures。



将它拷贝到你的$workspace目录下做为一个独立的项目。既可以是MeeGo SDK chroot下也可以是安装qt-examples的linux机器上。代码:

  1. cp -a /usr/lib/qt4/examples/opengl/textures $workspace/textures-0.0.1
  2. cd $workspace/textures-0.0.1
复制代码


为程序添加图标,此处我们使用例子中的项目图标作为我们的应用程序图标。

  1. cp images/side6.png textures.png
复制代码


添加一个桌面文件,可以使我们在MeeGo应用程序面板中找到我们的程序。

  1. vim textures.desktop
复制代码


内容是:

  1. [Desktop Entry]
  2. Name=QtDemoTextures
  3. Comment=Qt Demo Textures
  4. Exec=textures
  5. Categories=Development;
  6. Icon=textures
  7. Type=Application
  8. Terminal=false
  9. StartupNotify=true
复制代码


编辑textures.pro文件,去除一些用于Qt Example中的定义并且加入图标、桌面安装。

  1. vim textures.pro
复制代码


修改后的内容如下:

  1. HEADERS = glwidget.h /
  2. window.h
  3. SOURCES = glwidget.cpp /
  4. main.cpp /
  5. window.cpp
  6. RESOURCES = textures.qrc
  7. QT += opengl
  8. # install
  9. #target.path = $$[QT_INSTALL_EXAMPLES]/opengl/textures
  10. #sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS textures.pro images
  11. #sources.path = $$[QT_INSTALL_EXAMPLES]/opengl/textures
  12. target.path = $$[install_prefix]/bin
  13. icon.files = textures.png
  14. icon.path = $$[install_prefix]/share/icons
  15. desktop.files = textures.desktop
  16. desktop.path = $$[install_prefix]/share/applications
  17. INSTALLS += target icon desktop
复制代码


如果你想在打包之前测试下,你可以在MeeGo SDK chroot下构建调试,请参考:第一个MeeGo 程序:Hello world!

  1. qmake PREFIX=/usr
  2. make
  3. make install
复制代码


清理项目,创建源码压缩包,准备打包。

  1. make distclean
  2. cd ..
  3. tar jcvf textures-0.0.1.tar.bz2 textures-0.0.1
复制代码



创建spec文件

MeeGo推荐使用Spectacle工具创建MeeGo spec文件或者将一个存在的spec文件转换成MeeGo spec文件。

安装Spectacle

在MeeGo 平台 或 MeeGo chroot 环境,可以直接安装。

  1. yum install python-cheetah
  2. yum install spectacle
复制代码


如果您是代理,那么在运行上面命令之前需要设置:

  1. export http_proxy=http://proxy_server:port
复制代码


在Linux主机上安装,可以参考:Spectacle Installation


创建 YAML 包元数据文件

Spectacle使用包元数据文件作为输入来产生MeeGo spec 文件,这个元数据文件是YAML格式的,语法参见:Syntax of Spectacle YAML.

我们在$workspace/folder下创建一个textures.yaml文件

  1. vim $workspace/textures.yaml
复制代码


内容如下:
  1. Name: textures
  2. Summary: Qt Demo - OpenGL Textures
  3. Version: 0.0.1
  4. Release: 1
  5. Group: Development/Tools
  6. License: LGPLv2.1
  7. URL: http://qt.nokia.com
  8. Sources:
  9.     - "%{name}-%{version}.tar.bz2"
  10. Description: Qt Demo OpenGL Textures
  11. PkgConfigBR:
  12.     - QtCore >= 4.6.0
  13.     - QtOpenGL
  14.     - QtGui
  15. Configure: none
  16. Builder: none
  17. Files:
  18.     - "%{_bindir}/textures"
  19.     - "%{_datadir}/applications/*.desktop"
  20.     - "%{_datadir}/icons/*.png"
复制代码


YAML文件也可以从已存在的spec文件创建

  1. spec2spectacle package_name.spec
复制代码


Spectacle详细用法请参考:Spectacle Usage


从YAML文件生成spec文件

使用YAML文件,很容易生成spec 文件:

  1. specify textures.yaml
复制代码


生成的$workspace/textures.spec 文件内容是:

  1. #
  2. # Do not Edit! Generated by:
  3. # spectacle version 0.15
  4. #
  5. # >> macros
  6. # << macros
  7. Name:       textures
  8. Summary:    Qt Demo - OpenGL Textures
  9. Version:    0.0.1
  10. Release:    1
  11. Group:      Amusements/Graphics
  12. License:    LGPLv2.1
  13. URL:        http://qt.nokia.com
  14. Source0:    %{name}-%{version}.tar.bz2
  15. Source100:  textures.yaml
  16. Requires(post): desktop-file-utils
  17. Requires(post): /bin/touch
  18. Requires(postun): desktop-file-utils
  19. BuildRequires:  pkgconfig(QtCore) >= 4.6.0
  20. BuildRequires:  pkgconfig(QtOpenGL)
  21. BuildRequires:  pkgconfig(QtGui)
  22. BuildRequires:  desktop-file-utils
  23. %description
  24. Qt Demo OpenGL Textures
  25. %prep
  26. %setup -q -n %{name}-%{version}
  27. # >> setup
  28. # << setup
  29. %build
  30. # >> build pre
  31. # << build pre
  32. # >> build post
  33. # << build post
  34. %install
  35. rm -rf %{buildroot}
  36. # >> install pre
  37. # << install pre
  38. # >> install post
  39. # << install post
  40. desktop-file-install --delete-original       /
  41.   --dir %{buildroot}%{_datadir}/applications             /
  42.    %{buildroot}%{_datadir}/applications/*
  43. %post
  44. /bin/touch --no-create %{_datadir}/icons/hicolor || :
  45. %{_bindir}/gtk-update-icon-cache /
  46.   --quiet %{_datadir}/icons/hicolor 2> /dev/null|| :
  47. update-desktop-database %{_datadir}/applications &> /dev/null || :
  48. %postun
  49. /bin/touch --no-create %{_datadir}/icons/hicolor || :
  50. %{_bindir}/gtk-update-icon-cache /
  51.   --quiet %{_datadir}/icons/hicolor 2> /dev/null|| :
  52. update-desktop-database %{_datadir}/applications &> /dev/null || :
  53. %files
  54. %defattr(-,root,root,-)
  55. %{_bindir}/textures
  56. %{_datadir}/applications/*.desktop
  57. %{_datadir}/icons/*.png
  58. # >> files
  59. # << files
复制代码


修改textures.spec文件添加qt 建构信息:"build pre"和"install post" 段。

  1. # >> build pre
  2. export PATH=/usr/lib/qt4/bin:$PATH
  3. qmake PREFIX=%{_prefix}
  4. # << build pre
复制代码

  1. # >> install post
  2. make INSTALL_ROOT=%{buildroot}/usr install
  3. # << install post
复制代码



在MeeGo SDK chroot 下构建rpm

对于应用程序开发者来说,他们可以在MeeGo SDK chroot环境下直接创建包,通过rpmbuild是非常容易的。

首先进入chroot环境。
安装rpmbuild和MeeGo rpm 构建配置

  1. zypper install rpm-build
  2. zypper install meego-rpm-config
复制代码


拷贝源码和spec文件到正确的地方

  1. cp textures-0.0.1.tar.bz2 ~/rpmbuild/SOURCES/
  2. cp textures.yaml ~/rpmbuild/SOURCES/
  3. cp textures.spec ~/rpmbuild/SPECS/
复制代码


生成rpm包

  1. cd ~/rpmbuild/SPECS
  2. rpmbuild -ba textures.spec
复制代码

这个rpm包将生成在:

  1. ~/rpmbuild/RPMS/i586/textures-0.0.1-1.i586.rpm
  2. ~/rpmbuild/SRPMS/textures-0.0.1-1.src.rpm
复制代码


更多的rpmbuild使用参拷:rpmbuild


不用chroot 或 OBS 构建 rpm包

对于一些构建或release的人来说,他们可能想去构建不需要MeeGo SDK chroot环境的rpm包,那么步骤如下:

Linux

在Linux下,有一个工具叫“build”可以直接从spec文件创建rpm包。

@在你的主机上安装build。
@利用build工具和spec文件创建rpm包

  1. sudo build --repository http://repo.meego.com/MeeGo/release/1.0/core/repo/ia32/os/ --arch i686 textures.spec
复制代码


这个包将被生成在/var/tmp/build-root/home/abuild/rpmbuild/RPMS/ 和 /var/tmp/build-root/home/abuild/rpmbuild/SRPMS/目录下,你可以配置你的http_proxy来确保repo成功。

  1. export http_proxy=http://proxy_server:port
复制代码


验证rpm包

rpm包可以被直接安装在MeeGo设备上或MeeGo SDK模拟程序中,拷贝rpm到目标设备或模拟器上并运行。

  1. zypper --no-gpg-checks install textures-0.0.1-1.i586.rpm
复制代码


此时你可以在applications下的Programming中找到QtDemoTextures,它已经被列入其中了。

源文:http://wiki.meego.com/Packaging/Tutorial
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值