summaryrefslogtreecommitdiff
blob: 1df348e2b817eee797c22c33b73f60e1719f7e7e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/eclass/rox.eclass,v 1.20 2007/02/09 17:27:39 lack Exp $

# ROX eclass Version 2

# This eclass was created by Sergey Kuleshov (svyatogor@gentoo.org) and
# Alexander Simonov (devil@gentoo.org.ua) to ease installation of ROX desktop
# applications. Enhancements and python additions by Peter Hyman.
# Small fixes and current maintenance by the Rox herd (rox@gentoo.org)

# These variables are used in the GLOBAL scope to decide on DEPENDs, so they
# must be set BEFORE you 'inherit rox':
#
# ROX_VER - the minimum version of rox filer required. Default is 2.1.0
# ROX_LIB_VER - version of rox-lib required if any
# ROX_CLIB_VER - version of rox-clib required if any
#
# These variables are only used in local scopes, and so may be set anywhere in
# the ebuild:
#
# APPNAME - the actual name of the application as the app folder is named
# WRAPPERNAME - the name of the wrapper installed into /usr/bin
#    Defaults to 'rox-${PN}', or just ${PN} if it already starts with 'rox'.
#    This does not normally need to be overridden.
#    If overridden with the reserved word 'skip' no wrapper will be created.
# APPNAME_COLLISION - If not set, the old naming convention for wrappers of
#    /usr/bin/${APPNAME} will still be around.  Needs only be set in packages
#    with known collisions (such as Pager, which collides with afterstep)
# APPCATEGORY - the .desktop categories this application should be placed in.
#    If unset, no .desktop file will be created.  For a list of acceptable
#    category names, see
#    http://standards.freedesktop.org/menu-spec/latest/apa.html
# KEEP_SRC - this flag, if set, will not remove the source directory
#    but will do a make clean in it.  This is useful if users wish to
#    preserve the source code for some reason.

# TODO: Not used yet
# FEED_FILES - The list of files te check for a 0install feed.  If found, this
#    feed will be edited, and installed such that 0install can see it.  If you set
#    'ZEROINSTALL_STRIP_REQUIRES' this editing will also strip any 3rd-party
#    requirements from the feed as well.
#    Default:  "${APPNAME}/${APPNAME}.xml ${APPNAME}.xml"
# LOCAL_FEED_SRC - If set, will install the ebuild-supplied feed file so 0install
#    can see it.  This feed will not be edited, but installed as-is.
#    Default:  Not set

# For examples refer to ebuilds in rox-extra/ or rox-base/

# need python to byte compile modules, if any
# need autotools to run autoreconf, if required
inherit multilib python autotools eutils # 0install

if [[ -z "${ROX_VER}" ]]; then
	ROX_VER="2.1.0"
fi

RDEPEND=">=rox-base/rox-${ROX_VER}"

if [[ -n "${ROX_LIB_VER}" ]]; then
	RDEPEND="${RDEPEND}
		>=rox-base/rox-lib-${ROX_LIB_VER}"
fi

if [[ -n "${ROX_CLIB_VER}" ]]; then
	RDEPEND="${RDEPEND}
		>=rox-base/rox-clib-${ROX_CLIB_VER}"
	DEPEND="${RDEPEND}
		>=dev-util/pkgconfig-0.20"
fi

# This is the new wrapper name (for /usr/bin/)
#   It is also used for the icon name in /usr/share/pixmaps
#
# Use rox-${PN} unless ${PN} already starts with 'rox'
a="rox-${PN}"
b=${a/rox-rox*}
WRAPPERNAME=${b:-${PN}}

# Default for LOCAL_FEED_SRC
LOCAL_FEED_SRC=""

# This is the location where all applications are installed
APPDIR="/usr/$(get_libdir)/rox"
LIBDIR="/usr/$(get_libdir)"

# Utility Functions

# Creates a .desktop file for this rox application
# (Adapted from eutils::make_desktop_entry)
#
# rox_desktop_entry <exec> <name> <icon> <type> [<extra> ...]
#  exec - The executable to run
#  name - The name to display
#  icon - The icon file to display
#  Any other arguments will be appended verbatim to the desktop file.
#
# The name of the desktop file will be ${exec}.desktop
#
rox_desktop_entry() {
	# Coppied from etuils:make_desktop_entry
	local exec=${1}; shift
	local name=${1}; shift
	local icon=${1}; shift
	local type=${1}; shift

	local desktop="${exec}.desktop"

	cat <<-EOF > "${desktop}"
	[Desktop Entry]
	Encoding=UTF-8
	Version=1.0
	Name=${name}
	Type=Application
	Comment=${DESCRIPTION}
	Exec=${exec}
	TryExec=${exec%% *}
	Icon=${icon}
	Categories=ROX;Application;${type};
	EOF

	local extra=${1}; shift
	while [[ "${extra}" ]]; do
		echo "${extra}" >> "${desktop}"
		extra=${1}; shift
	done

	(
		# wrap the env here so that the 'insinto' call
		# doesn't corrupt the env of the caller
		insinto /usr/share/applications
		doins "${desktop}"
	)
}

# Exported functions
rox_src_compile() {
	cd "${APPNAME}"
	#Some packages need to be compiled.
	chmod 755 AppRun
	if [[ -d src/ ]]; then
		# Bug 150303: Check with Rox-Clib will fail if the user has 0install
		# installed on their system somewhere, so remove the check for it in the
		# configure script, and adjust the path that the 'libdir' program uses
		# to search for it:
		# TODO: Use 0compile instead, maybe?
		if [[ -f src/configure.in ]]; then
			cd src
			sed -i.bak -e 's/ROX_CLIB_0LAUNCH/ROX_CLIB/' configure.in
			# TODO: This should really be 'eautoreconf', but that breaks a number
			# of packages (such as pager-1.0.1)
			eautoconf
			cd ..
		fi
		export LIBDIRPATH="${LIBDIR}"

		# Most rox self-compiles have a 'read' call to wait for the user to
		# press return if the compile fails.
		# Find and remove this:
		sed -i.bak -e 's/\<read\>/#read/' AppRun

		./AppRun --compile || die "Failed to compile the package"
		if [[ -n "${KEEP_SRC}" ]]; then
			cd src
			make clean
			cd ..
		else
			rm -rf src
		fi
		if [[ -d build ]]; then
			rm -rf build
		fi

		# Restore the original AppRun
		mv AppRun.bak AppRun
	fi
}

rox_src_install() {
	if [[ -d "${APPNAME}/Help/" ]]; then
		for i in "${APPNAME}"/Help/*; do
			dodoc "${i}"
		done
	fi

	insinto ${APPDIR}

	# Use 'cp -pPR' and not 'doins -r' here so we don't have to do a flurry of
	# 'chmod' calls on the executables in the appdir - Just be sure that all the
	# files in the original appdir prior to this step are correct, as they will
	# all be preserved.
	cp -pPR ${APPNAME} ${D}${APPDIR}/${APPNAME}

	if [[ "${WRAPPERNAME}" != "skip" ]]; then
		#create a script in bin to run the application from command line
		dodir /usr/bin/
		cat >"${D}/usr/bin/${WRAPPERNAME}" <<EOF
#!/bin/sh
if [[ "\${LIBDIRPATH}" ]]; then
	export LIBDIRPATH="\${LIBDIRPATH}:${LIBDIR}"
else
	export LIBDIRPATH="${LIBDIR}"
fi

if [[ "\${APPDIRPATH}" ]]; then
	export APPDIRPATH="\${APPDIRPATH}:${APPDIR}"
else
	export APPDIRPATH="${APPDIR}"
fi
exec "${APPDIR}/${APPNAME}/AppRun" "\$@"
EOF
		chmod 755 "${D}/usr/bin/${WRAPPERNAME}"

		# Old name of cmdline wrapper: /usr/bin/${APPNAME}
		if [[ ! "${APPNAME_COLLISION}" ]]; then
			ln -s ${WRAPPERNAME} ${D}/usr/bin/${APPNAME}
			# TODO: Migrate this away... eventually
		else
			ewarn "The wrapper script /usr/bin/${APPNAME} has been removed"
			ewarn "due to a name collision.  You must run ${APPNAME} as"
			ewarn "/usr/bin/${WRAPPERNAME} instead."
		fi
	fi

	# Create a .desktop file if the proper category is supplied
	if [[ -n "${APPCATEGORY}" ]]; then
		# Copy the .DirIcon into /usr/share/pixmaps with the proper extension
		if [[ -f "${APPNAME}/.DirIcon" ]]; then
			local APPDIRICON=${APPNAME}/.DirIcon
			case "$(file -b ${APPDIRICON})" in
				"PNG image data"*)
					export APPICON=${WRAPPERNAME}.png
					;;
				"XML 1.0 document text"*)
					export APPICON=${WRAPPERNAME}.svg
					;;
				"X pixmap image text"*)
					export APPICON=${WRAPPERNAME}.xpm
					;;
				"symbolic link"*)
					APPDIRICON=$(dirname ${APPDIRICON})/$(readlink ${APPDIRICON})
					export APPICON=${WRAPPERNAME}.${APPDIRICON##*.}
					;;
				*)
					# Unknown... Remark on it, and just copy without an extension
					ewarn "Could not detect the file type of the application icon,"
					ewarn "copying without an extension."
					export APPICON=${WRAPPERNAME}
					;;
			esac
			insinto /usr/share/pixmaps
			newins "${APPDIRICON}" "${APPICON}"
		fi

		rox_desktop_entry "${WRAPPERNAME}" "${APPNAME}" "${APPICON}" "${APPCATEGORY}"
	fi

	# TODO: Once 0install actually works, we'll want this, or something like it:
	#if [[ -f "${LOCAL_FEED_SRC}" ]]; then
	#	# Install the ebuild-supplied feed
	#	0install_install_feed "${LOCAL_FEED_SRC}" "${APPDIR}/${APPNAME}"
	#else
	#	# Install the local feed, if appropriate
	#	local search_list=${FEED_FILES:-"${APPNAME}/${APPNAME}.xml ${APPNAME}.xml"}
	#	for feed in ${search_list}; do
	#		elog "Looking for feed $feed"
	#		if [[ -f "${feed}" ]]; then
	#			0install_local_feed "${feed}" "${APPDIR}/${APPNAME}"
	#		fi
	#	done
	#fi

	#now compile any and all python files
	python_mod_optimize "${D}${APPDIR}/${APPNAME}" >/dev/null 2>&1
}

rox_pkg_postinst() {
	einfo "${APPNAME} has been installed into ${APPDIR}"
	if [[ "${WRAPPERNAME}" != "skip" ]]; then
		einfo "You can run it by typing ${WRAPPERNAME} at the command line."
		einfo "Or, you can run it by pointing the ROX file manager to the"
	else
		einfo "You can run it by pointing the ROX file manager to the"
	fi
	einfo "install location -- ${APPDIR} -- and click"
	einfo "on ${APPNAME}'s icon, drag it to a panel, desktop, etc."
}

EXPORT_FUNCTIONS src_compile src_install pkg_postinst