教你如何将你的Qt项目打包安装在MeeGo系统中
2010-08-28 09:43
344 查看
简介
本文将教你怎样将你写的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机器上。代码:
cp -a /usr/lib/qt4/examples/opengl/textures $workspace/textures-0.0.1
cd $workspace/textures-0.0.1
复制代码
为程序添加图标,此处我们使用例子中的项目图标作为我们的应用程序图标。
cp images/side6.png textures.png
复制代码
添加一个桌面文件,可以使我们在MeeGo应用程序面板中找到我们的程序。
vim textures.desktop
复制代码
内容是:
[Desktop Entry]
Name=QtDemoTextures
Comment=Qt Demo Textures
Exec=textures
Categories=Development;
Icon=textures
Type=Application
Terminal=false
StartupNotify=true
复制代码
编辑textures.pro文件,去除一些用于Qt Example中的定义并且加入图标、桌面安装。
vim textures.pro
复制代码
修改后的内容如下:
HEADERS = glwidget.h \
window.h
SOURCES = glwidget.cpp \
main.cpp \
window.cpp
RESOURCES = textures.qrc
QT += opengl
# install
#target.path = $[QT_INSTALL_EXAMPLES]/opengl/textures
#sources.files = $SOURCES $HEADERS $RESOURCES $FORMS textures.pro images
#sources.path = $[QT_INSTALL_EXAMPLES]/opengl/textures
target.path = $[install_prefix]/bin
icon.files = textures.png
icon.path = $[install_prefix]/share/icons
desktop.files = textures.desktop
desktop.path = $[install_prefix]/share/applications
INSTALLS += target icon desktop
复制代码
如果你想在打包之前测试下,你可以在MeeGo SDK chroot下构建调试,请参考:Hello World - Linux上的 MeeGo x86 开发
qmake PREFIX=/usr
make
make install
复制代码
清理项目,创建源码压缩包,准备打包。
make distclean
cd ..
tar jcvf textures-0.0.1.tar.bz2 textures-0.0.1
复制代码
创建spec文件
MeeGo推荐使用Spectacle工具创建MeeGo spec文件或者将一个存在的spec文件转换成MeeGo spec文件。
安装Spectacle
在MeeGo 平台 或 MeeGo chroot 环境,可以直接安装。
yum install python-cheetah
yum install spectacle
复制代码
如果您是代理,那么在运行上面命令之前需要设置:
export http_proxy=http://proxy_server:port
复制代码
在Linux主机上安装,可以参考:Spectacle Installation
创建 YAML 包元数据文件
Spectacle使用包元数据文件作为输入来产生MeeGo spec 文件,这个元数据文件是YAML格式的,语法参见:Syntax of Spectacle YAML.
我们在$workspace/folder下创建一个textures.yaml文件
vim $workspace/textures.yaml
复制代码
内容如下:
Name: textures
Summary: Qt Demo - OpenGL Textures
Version: 0.0.1
Release: 1
Group: Development/Tools
License: LGPLv2.1
URL: http://qt.nokia.com
Sources:
- "%{name}-%{version}.tar.bz2"
Description: Qt Demo OpenGL Textures
PkgConfigBR:
- QtCore >= 4.6.0
- QtOpenGL
- QtGui
Configure: none
Builder: none
Files:
- "%{_bindir}/textures"
- "%{_datadir}/applications/*.desktop"
- "%{_datadir}/icons/*.png"
复制代码
YAML文件也可以从已存在的spec文件创建
spec2spectacle package_name.spec
复制代码
Spectacle详细用法请参考:Spectacle Usage
从YAML文件生成spec文件
使用YAML文件,很容易生成spec 文件:
specify textures.yaml
复制代码
生成的$workspace/textures.spec 文件内容是:
#
# Do not Edit! Generated by:
# spectacle version 0.15
#
# >> macros
# << macros
Name: textures
Summary: Qt Demo - OpenGL Textures
Version: 0.0.1
Release: 1
Group: Amusements/Graphics
License: LGPLv2.1
URL: http://qt.nokia.com
Source0: %{name}-%{version}.tar.bz2
Source100: textures.yaml
Requires(post): desktop-file-utils
Requires(post): /bin/touch
Requires(postun): desktop-file-utils
BuildRequires: pkgconfig(QtCore) >= 4.6.0
BuildRequires: pkgconfig(QtOpenGL)
BuildRequires: pkgconfig(QtGui)
BuildRequires: desktop-file-utils
%description
Qt Demo OpenGL Textures
%prep
%setup -q -n %{name}-%{version}
# >> setup
# << setup
%build
# >> build pre
# << build pre
# >> build post
# << build post
%install
rm -rf %{buildroot}
# >> install pre
# << install pre
# >> install post
# << install post
desktop-file-install --delete-original \
--dir %{buildroot}%{_datadir}/applications \
%{buildroot}%{_datadir}/applications/*
%post
/bin/touch --no-create %{_datadir}/icons/hicolor || :
%{_bindir}/gtk-update-icon-cache \
--quiet %{_datadir}/icons/hicolor 2> /dev/null|| :
update-desktop-database %{_datadir}/applications &> /dev/null || :
%postun
/bin/touch --no-create %{_datadir}/icons/hicolor || :
%{_bindir}/gtk-update-icon-cache \
--quiet %{_datadir}/icons/hicolor 2> /dev/null|| :
update-desktop-database %{_datadir}/applications &> /dev/null || :
%files
%defattr(-,root,root,-)
%{_bindir}/textures
%{_datadir}/applications/*.desktop
%{_datadir}/icons/*.png
# >> files
# << files
复制代码
修改textures.spec文件添加qt 建构信息:"build pre"和"install post" 段。
# >> build pre
export PATH=/usr/lib/qt4/bin: $PATH
qmake PREFIX=%{_prefix}
# << build pre
复制代码
# >> install post
make INSTALL_ROOT=%{buildroot}/usr install
# << install post
复制代码
在MeeGo SDK chroot 下构建rpm
对于应用程序开发者来说,他们可以在MeeGo SDK chroot环境下直接创建包,通过rpmbuild是非常容易的。
首先进入chroot环境。
安装rpmbuild和MeeGo rpm 构建配置
zypper install rpm-build
zypper install meego-rpm-config
复制代码
拷贝源码和spec文件到正确的地方
cp textures-0.0.1.tar.bz2 ~/rpmbuild/SOURCES/
cp textures.yaml ~/rpmbuild/SOURCES/
cp textures.spec ~/rpmbuild/SPECS/
复制代码
生成rpm包
cd ~/rpmbuild/SPECS
rpmbuild -ba textures.spec
复制代码
这个rpm包将生成在:
~/rpmbuild/RPMS/i586/textures-0.0.1-1.i586.rpm
~/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包
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成功。
export http_proxy=http://proxy_server:port
复制代码
验证rpm包
rpm包可以被直接安装在MeeGo设备上或MeeGo SDK模拟程序中,拷贝rpm到目标设备或模拟器上并运行。
zypper --no-gpg-checks install textures-0.0.1-1.i586.rpm
复制代码
此时你可以在applications下的Programming中找到QtDemoTextures,它已经被列入其中了。
本文将教你怎样将你写的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机器上。代码:
cp -a /usr/lib/qt4/examples/opengl/textures $workspace/textures-0.0.1
cd $workspace/textures-0.0.1
复制代码
为程序添加图标,此处我们使用例子中的项目图标作为我们的应用程序图标。
cp images/side6.png textures.png
复制代码
添加一个桌面文件,可以使我们在MeeGo应用程序面板中找到我们的程序。
vim textures.desktop
复制代码
内容是:
[Desktop Entry]
Name=QtDemoTextures
Comment=Qt Demo Textures
Exec=textures
Categories=Development;
Icon=textures
Type=Application
Terminal=false
StartupNotify=true
复制代码
编辑textures.pro文件,去除一些用于Qt Example中的定义并且加入图标、桌面安装。
vim textures.pro
复制代码
修改后的内容如下:
HEADERS = glwidget.h \
window.h
SOURCES = glwidget.cpp \
main.cpp \
window.cpp
RESOURCES = textures.qrc
QT += opengl
# install
#target.path = $[QT_INSTALL_EXAMPLES]/opengl/textures
#sources.files = $SOURCES $HEADERS $RESOURCES $FORMS textures.pro images
#sources.path = $[QT_INSTALL_EXAMPLES]/opengl/textures
target.path = $[install_prefix]/bin
icon.files = textures.png
icon.path = $[install_prefix]/share/icons
desktop.files = textures.desktop
desktop.path = $[install_prefix]/share/applications
INSTALLS += target icon desktop
复制代码
如果你想在打包之前测试下,你可以在MeeGo SDK chroot下构建调试,请参考:Hello World - Linux上的 MeeGo x86 开发
qmake PREFIX=/usr
make
make install
复制代码
清理项目,创建源码压缩包,准备打包。
make distclean
cd ..
tar jcvf textures-0.0.1.tar.bz2 textures-0.0.1
复制代码
创建spec文件
MeeGo推荐使用Spectacle工具创建MeeGo spec文件或者将一个存在的spec文件转换成MeeGo spec文件。
安装Spectacle
在MeeGo 平台 或 MeeGo chroot 环境,可以直接安装。
yum install python-cheetah
yum install spectacle
复制代码
如果您是代理,那么在运行上面命令之前需要设置:
export http_proxy=http://proxy_server:port
复制代码
在Linux主机上安装,可以参考:Spectacle Installation
创建 YAML 包元数据文件
Spectacle使用包元数据文件作为输入来产生MeeGo spec 文件,这个元数据文件是YAML格式的,语法参见:Syntax of Spectacle YAML.
我们在$workspace/folder下创建一个textures.yaml文件
vim $workspace/textures.yaml
复制代码
内容如下:
Name: textures
Summary: Qt Demo - OpenGL Textures
Version: 0.0.1
Release: 1
Group: Development/Tools
License: LGPLv2.1
URL: http://qt.nokia.com
Sources:
- "%{name}-%{version}.tar.bz2"
Description: Qt Demo OpenGL Textures
PkgConfigBR:
- QtCore >= 4.6.0
- QtOpenGL
- QtGui
Configure: none
Builder: none
Files:
- "%{_bindir}/textures"
- "%{_datadir}/applications/*.desktop"
- "%{_datadir}/icons/*.png"
复制代码
YAML文件也可以从已存在的spec文件创建
spec2spectacle package_name.spec
复制代码
Spectacle详细用法请参考:Spectacle Usage
从YAML文件生成spec文件
使用YAML文件,很容易生成spec 文件:
specify textures.yaml
复制代码
生成的$workspace/textures.spec 文件内容是:
#
# Do not Edit! Generated by:
# spectacle version 0.15
#
# >> macros
# << macros
Name: textures
Summary: Qt Demo - OpenGL Textures
Version: 0.0.1
Release: 1
Group: Amusements/Graphics
License: LGPLv2.1
URL: http://qt.nokia.com
Source0: %{name}-%{version}.tar.bz2
Source100: textures.yaml
Requires(post): desktop-file-utils
Requires(post): /bin/touch
Requires(postun): desktop-file-utils
BuildRequires: pkgconfig(QtCore) >= 4.6.0
BuildRequires: pkgconfig(QtOpenGL)
BuildRequires: pkgconfig(QtGui)
BuildRequires: desktop-file-utils
%description
Qt Demo OpenGL Textures
%prep
%setup -q -n %{name}-%{version}
# >> setup
# << setup
%build
# >> build pre
# << build pre
# >> build post
# << build post
%install
rm -rf %{buildroot}
# >> install pre
# << install pre
# >> install post
# << install post
desktop-file-install --delete-original \
--dir %{buildroot}%{_datadir}/applications \
%{buildroot}%{_datadir}/applications/*
%post
/bin/touch --no-create %{_datadir}/icons/hicolor || :
%{_bindir}/gtk-update-icon-cache \
--quiet %{_datadir}/icons/hicolor 2> /dev/null|| :
update-desktop-database %{_datadir}/applications &> /dev/null || :
%postun
/bin/touch --no-create %{_datadir}/icons/hicolor || :
%{_bindir}/gtk-update-icon-cache \
--quiet %{_datadir}/icons/hicolor 2> /dev/null|| :
update-desktop-database %{_datadir}/applications &> /dev/null || :
%files
%defattr(-,root,root,-)
%{_bindir}/textures
%{_datadir}/applications/*.desktop
%{_datadir}/icons/*.png
# >> files
# << files
复制代码
修改textures.spec文件添加qt 建构信息:"build pre"和"install post" 段。
# >> build pre
export PATH=/usr/lib/qt4/bin: $PATH
qmake PREFIX=%{_prefix}
# << build pre
复制代码
# >> install post
make INSTALL_ROOT=%{buildroot}/usr install
# << install post
复制代码
在MeeGo SDK chroot 下构建rpm
对于应用程序开发者来说,他们可以在MeeGo SDK chroot环境下直接创建包,通过rpmbuild是非常容易的。
首先进入chroot环境。
安装rpmbuild和MeeGo rpm 构建配置
zypper install rpm-build
zypper install meego-rpm-config
复制代码
拷贝源码和spec文件到正确的地方
cp textures-0.0.1.tar.bz2 ~/rpmbuild/SOURCES/
cp textures.yaml ~/rpmbuild/SOURCES/
cp textures.spec ~/rpmbuild/SPECS/
复制代码
生成rpm包
cd ~/rpmbuild/SPECS
rpmbuild -ba textures.spec
复制代码
这个rpm包将生成在:
~/rpmbuild/RPMS/i586/textures-0.0.1-1.i586.rpm
~/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包
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成功。
export http_proxy=http://proxy_server:port
复制代码
验证rpm包
rpm包可以被直接安装在MeeGo设备上或MeeGo SDK模拟程序中,拷贝rpm到目标设备或模拟器上并运行。
zypper --no-gpg-checks install textures-0.0.1-1.i586.rpm
复制代码
此时你可以在applications下的Programming中找到QtDemoTextures,它已经被列入其中了。
相关文章推荐
- 教你如何将你的Qt项目打包安装在MeeGo系统中
- 教你如何将你的Qt项目打包安装在MeeGo系统中
- 教你如何将你的Qt项目打包安装在MeeGo系统中
- 教你如何将你的Qt项目打包安装在MeeGo系统中
- 教你如何将你的Qt项目打包安装在MeeGo系统中
- 教你如何将你的Qt项目打包安装在MeeGo系统中
- 如何将你的Qt项目打包安装在MeeGo系统中
- 如何将你的Qt项目打包安装在MeeGo系统中
- WEB项目(B/S系统)打包安装总结
- 如何用maven 手动把本地jar安装到本地仓库和将本地项目打包并安装到本地资源仓库
- 如何在centOS6.7上安装jdk、mysql、tomcat,以及部署打包成war包的web项目
- WEB项目(B/S系统)打包安装(总结篇)
- Windows系统下将Qt生成的应用程序打包成可以安装的文件setup***.exe
- 在Linux 下如何打包免安装的QT程序
- vs2005中如何发布网站及打包web项目生成安装文件
- WEB项目(B/S系统)打包安装程序总结-部署安装(VS2013)
- 如何把同一个Android项目同时安装到手机上--Android系统如何区分不同app
- (C#)如何用.NET的安装项目打包程序?
- WEB项目(B/S系统)打包安装(总结篇)
- WEB项目(B/S系统)打包安装(总结篇)