Skip site navigation (1)Skip section navigation (2)
Date:      Sun,  3 Apr 2005 19:03:28 +0200 (CEST)
From:      Jean-Yves Lefort <jylefort@brutele.be>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   ports/79509: add .desktop file facilities to bsd.port.mk
Message-ID:  <20050403170328.EE87181E4@jsite.lefort.net>
Resent-Message-ID: <200504031710.j33HA6fi038640@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         79509
>Category:       ports
>Synopsis:       add .desktop file facilities to bsd.port.mk
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Apr 03 17:10:06 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     Jean-Yves Lefort
>Release:        FreeBSD 5.3-RELEASE-p6 i386
>Organization:
>Environment:
System: FreeBSD jsite.lefort.net 5.3-RELEASE-p6 FreeBSD 5.3-RELEASE-p6 #0: Tue Mar 29 00:14:29 CEST 2005 jylefort@jsite.lefort.net:/usr/obj/usr/src/sys/JSITE i386
>Description:
A lot of X ports do not ship with a .desktop file. It would be good to
create desktop entries for these ports, so that the applications show
up in the menus of fd.o-compliant desktop environments (such as GNOME,
KDE, ...).

To ease the task, this patch adds a DESKTOP_ENTRIES variable. Porters
can now easily create and install one or more .desktop file for their
port. The files are automatically added to the packing list. They are
installed in DESKTOPDIR, which defaults to PREFIX/share/applications
(path recommended by the fd.o spec). Although there should be no
reason for an user or port to override DESKTOPDIR, the code supports
any DESKTOPDIR, even if it's outside of PREFIX.

Along with the patch, I provide an example use for
x11/nvidia-settings.
>How-To-Repeat:
>Fix:
--- bsd.port.mk.orig	Fri Mar 18 00:22:07 2005
+++ bsd.port.mk	Sun Apr  3 18:59:27 2005
@@ -844,6 +844,36 @@
 # DATADIR		- Name of the directory to install the packages shared data in.
 #				  Default: ${PREFIX}/share/${PORTNAME}
 #
+# DESKTOPDIR	- Name of the directory to install ${DESKTOP_ENTRIES} in.
+#				  Default: ${PREFIX}/share/applications
+# DESKTOP_ENTRIES
+#				- List of desktop entry files to generate and install in
+#				  ${DESKTOPDIR}. The format is
+#				  "Name" "Comment" "Icon" "Exec" "Categories" StartupNotify
+#				  Rules:
+#					* Only add desktop entries for applications which do not
+#					  require a terminal (ie. X applications).
+#					* If the upstream distribution already installs .desktop
+#					  files, you do not need to use this.
+#					* If you require a more elaborate .desktop file than this
+#					  variable permits, write it yourself and install it
+#					  in ${DESKTOPDIR}.
+#				  Notes:
+#					* Comment and Icon may be empty strings (""). The other
+#					  fields are mandatory.
+#					* Exec will also be used to name the .desktop file.
+#					* The files will be automatically added to ${PLIST}.
+#				  Example:
+#					"X Window Information" \
+#					"Get information about X windows" \
+#					"wininfo.png" \
+#					"wininfo" \
+#					"Application;System;" \
+#					true
+#				  See http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
+#				  for an explanation of the fields. If you need to create more
+#				  than one file, just chain them into a single variable.
+#
 # Note that the install target will automatically add manpages (see
 # above) and also substitute special sequences of characters (delimited
 # by "%%") as defined in PLIST_SUB to generate ${TMPPLIST}.  For
@@ -2718,6 +2748,14 @@
 		EXAMPLESDIR="${EXAMPLESDIR:S,^${PREFIX}/,,}" \
 		DATADIR="${DATADIR:S,^${PREFIX}/,,}"
 
+DESKTOPDIR?=		${PREFIX}/share/applications
+_DESKTOPDIR_REL=	${DESKTOPDIR:S,^${PREFIX}/,,}/
+
+.if ${_DESKTOPDIR_REL} == ${DESKTOPDIR}/
+# DESKTOPDIR is not beneath PREFIX
+_DESKTOPDIR_REL=
+.endif
+
 # Put this as far down as possible so it will catch all PLIST_SUB definitions.
 
 .if defined(INSTALLS_SHLIB)
@@ -3715,10 +3753,10 @@
 			    run-depends lib-depends apply-slist pre-install \
 				pre-install-script generate-plist check-already-installed
 _INSTALL_SUSEQ= check-umask install-mtree pre-su-install \
-				pre-su-install-script do-install post-install \
-				post-install-script add-plist-info add-plist-docs \
-				add-plist-post install-rc-script compress-man run-ldconfig \
-				fake-pkg security-check
+				pre-su-install-script do-install install-desktop-entries \
+				post-install post-install-script add-plist-info \
+				add-plist-docs add-plist-post install-rc-script compress-man \
+				run-ldconfig fake-pkg security-check
 _PACKAGE_DEP=	install
 _PACKAGE_SEQ=	package-message pre-package pre-package-script \
 				do-package post-package-script
@@ -5139,6 +5177,44 @@
 	@for dir in ${.CURDIR} $$(${ALL-DEPENDS-LIST}); do \
 		(cd $$dir; ${MAKE} rmconfig); \
 	done
+.endif
+
+.if !target(install-desktop-entries)
+install-desktop-entries:
+.if defined(DESKTOP_ENTRIES)
+	@(${MKDIR} "${DESKTOPDIR}" 2> /dev/null) || \
+		(${ECHO_MSG} "===> Cannot create ${DESKTOPDIR}, check permissions"; exit 1)
+	@set ${DESKTOP_ENTRIES} XXX; \
+	if [ -z "${_DESKTOPDIR_REL}" ]; then \
+		${ECHO_CMD} "@cwd ${DESKTOPDIR}" >> ${TMPPLIST}; \
+	fi; \
+	while [ $$# -gt 6 ]; do \
+		filename="$$4.desktop"; \
+		pathname="${DESKTOPDIR}/$$filename"; \
+		${ECHO_CMD} "${_DESKTOPDIR_REL}$$filename" >> ${TMPPLIST}; \
+		${ECHO_CMD} "[Desktop Entry]" > $$pathname; \
+		${ECHO_CMD} "Type=Application" >> $$pathname; \
+		${ECHO_CMD} "Version=0.9.4" >> $$pathname; \
+		${ECHO_CMD} "Encoding=UTF-8" >> $$pathname; \
+		${ECHO_CMD} "Name=$$1" >> $$pathname; \
+		if [ -n "$$2" ]; then \
+			${ECHO_CMD} "Comment=$$2" >> $$pathname; \
+		fi; \
+		if [ -n "$$3" ]; then \
+			${ECHO_CMD} "Icon=$$3" >> $$pathname; \
+		fi; \
+		${ECHO_CMD} "Exec=$$4" >> $$pathname; \
+		${ECHO_CMD} "Categories=$$5" >> $$pathname; \
+		${ECHO_CMD} "StartupNotify=$$6" >> $$pathname; \
+		shift 6; \
+	done; \
+	${ECHO_CMD} "@unexec rmdir ${DESKTOPDIR} 2>/dev/null || true" >> ${TMPPLIST}; \
+	if [ -z "${_DESKTOPDIR_REL}" ]; then \
+		${ECHO_CMD} "@cwd ${PREFIX}" >> ${TMPPLIST}; \
+	fi
+.else
+	@${DO_NADA}
+.endif
 .endif
 
 .endif

diff -ruN /usr/ports/x11/nvidia-settings/Makefile nvidia-settings/Makefile
--- /usr/ports/x11/nvidia-settings/Makefile	Mon Mar 14 00:30:35 2005
+++ nvidia-settings/Makefile	Sun Apr  3 18:34:28 2005
@@ -7,7 +7,7 @@
 
 PORTNAME=	nvidia-settings
 PORTVERSION=	1.0
-PORTREVISION=	3
+PORTREVISION=	4
 CATEGORIES=	x11
 MASTER_SITES=	http://download.nvidia.com/XFree86/nvidia-settings/
 
@@ -23,5 +23,12 @@
 MAKE_ENV=	ROOT=${PREFIX}
 
 ONLY_FOR_ARCHS=	i386
+
+DESKTOP_ENTRIES=	"NVIDIA X Server Settings" \
+			"Configure your NVIDIA card" \
+			"" \
+			"nvidia-settings" \
+			"Application;Settings;" \
+			true
 
 .include <bsd.port.mk>
>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050403170328.EE87181E4>