第一个GTK程序:中国农历 之五

生成desktop文件方法很多,有使用.desktop.in.in方式的,也有直接放一个.desktop文件方式的

其实两者差别不大,因为对于我们来说,一个工程的.desktop基本上确定的。

比如使用.desktop.in.in方式,我们在根目录下面创建一个data目录,将.desktop.in.in文件及Makefile.am文件放入其中

[Desktop Entry]
_Name=Lunar Calendar
_Name[zh_CN]=中国农历
_GenericName=Lunar Calendar
TryExec=@PACKAGE@
Exec=@PACKAGE@
Icon=pixmaps/@PACKAGE@.png
Terminal=false
Type=Application
Categories=Application;GTK;utiliy;
StartupNotify=true
Encoding=UTF-8
@INTLTOOL_DESKTOP_RULE@

SUBDIRS =

desktop_in_in_files = lunarcalendar.desktop.in.in
desktop_in_files = $(desktop_in_in_files:.desktop.in.in=.desktop.in)

desktopdir = $(datadir)/applications
desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)

gtk_update_icon_cache = gtk-update-icon-cache -f -t $(datadir)/icons/hicolor

install-data-hook: update-icon-cache
uninstall-hook: update-icon-cache
update-icon-cache:
    if test -z "$(DESTDIR)"; then \
       echo "Updating Gtk icon cache."; \
       $(gtk_update_icon_cache); \
    else \
       echo "*** Icon cache not updated.  After (un)install, run this:"; \
       echo "***   $(gtk_update_icon_cache)"; \
    fi

EXTRA_DIST = \
    $(desktop_DATA)     

DISTCLEANFILES = \
    $(desktop_in_files) \
    $(desktop_DATA)

对于这种方式,关键在于在Makefile.am中增加一个INTLTOOL_DESKTOP_RULE项

另外,由于使用的是.desktop.in.in方式,会使用到intltool工具,因此,我们在configure.ac中增加测试IT_PROG_INTLTOOL(0.35.6)

我们现在根目录下的Makefile.am中的SUBDIRS中增加data目录,重新使用autogen.sh/configure/make/make install,就可以自动将.desktop生成并安装在对应的application目录下了

此时打包的源代码文件:lunarcalendar.0.0.5.zip

直接放一个.desktop那就更简单了,写一个.desktop文件及Makefile.am,依然放在data目录

[Desktop Entry]
Name=Lunar Calendar
Name[zh_CN]=中国农历
GenericName=Lunar Calendar
GenericName[zh_CN]=中国农历
TryExec=lunarcalendar
Exec=lunarcalendar
Icon=pixmaps/lunarcalendar.png
Terminal=false
Type=Application
Categories=Application;GTK;utiliy;
StartupNotify=true
Encoding=UTF-8
appdir = $(datadir)/applications

app_DATA = *.desktop

EXTRA_DIST = *.desktop     

重新使用autogen.sh/configure/make/make install,就可以自动将.desktop生成并安装在对应的application目录下了

此时的源代码打包:lunarcalendar.0.0.6.zip

记住,无论哪种方式,configure.ac都需要增加AC_CONFIG_FILES的内容:

AC_CONFIG_FILES([Makefile po/Makefile.in  
                 src/Makefile
                 data/Makefile
                 data/lunarcalendar.desktop.in])

AC_CONFIG_FILES([Makefile po/Makefile.in  
                 src/Makefile
                 data/Makefile])

第二种方式不依赖于intltool,反倒更简单

原文地址:https://www.cnblogs.com/eaglexmw/p/3034240.html