/[gentoo-x86]/eclass/eutils.eclass
Gentoo

Diff of /eclass/eutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1 Revision 1.52
1# Copyright 1999-2002 Gentoo Technologies, Inc. 1# Copyright 1999-2003 Gentoo Technologies, Inc.
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.52 2003/09/13 19:24:21 vapier Exp $
4#
3# Author: Martin Schlemmer <azarah@gentoo.org> 5# Author: Martin Schlemmer <azarah@gentoo.org>
4# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.1 2002/10/26 09:16:03 azarah Exp $ 6#
5# This eclass is for general purpose functions that most ebuilds 7# This eclass is for general purpose functions that most ebuilds
6# have to implement themselfs. 8# have to implement themselves.
7# 9#
8# NB: If you add anything, please comment it! 10# NB: If you add anything, please comment it!
9 11
10ECLASS=eutils 12ECLASS=eutils
11INHERITED="$INHERITED $ECLASS" 13INHERITED="$INHERITED $ECLASS"
12 14
13newdepend sys-devel/patch 15newdepend "!bootstrap? ( sys-devel/patch )"
14 16
15DESCRIPTION="Based on the ${ECLASS} eclass" 17DESCRIPTION="Based on the ${ECLASS} eclass"
16 18
17# This function generate linker scripts in /usr/lib for dynamic 19# This function generate linker scripts in /usr/lib for dynamic
18# libs in /lib. This is to fix linking problems when you have 20# libs in /lib. This is to fix linking problems when you have
34# 36#
35gen_usr_ldscript() { 37gen_usr_ldscript() {
36 38
37 # Just make sure it exists 39 # Just make sure it exists
38 dodir /usr/lib 40 dodir /usr/lib
39 41
40 cat > ${D}/usr/lib/$1 <<"END_LDSCRIPT" 42 cat > ${D}/usr/lib/$1 <<"END_LDSCRIPT"
41/* GNU ld script 43/* GNU ld script
42 Because Gentoo have critical dynamic libraries 44 Because Gentoo have critical dynamic libraries
43 in /lib, and the static versions in /usr/lib, we 45 in /lib, and the static versions in /usr/lib, we
44 need to have a "fake" dynamic lib in /usr/lib, 46 need to have a "fake" dynamic lib in /usr/lib,
47 more info. */ 49 more info. */
48GROUP ( /lib/libxxx ) 50GROUP ( /lib/libxxx )
49END_LDSCRIPT 51END_LDSCRIPT
50 52
51 dosed "s:libxxx:$1:" /usr/lib/$1 53 dosed "s:libxxx:$1:" /usr/lib/$1
52}
53 54
55 return 0
56}
57
58# Simple function to draw a line consisting of '=' the same length as $*
59#
60# <azarah@gentoo.org> (11 Nov 2002)
61#
62draw_line() {
63 local i=0
64 local str_length=""
65
66 # Handle calls that do not have args, or wc not being installed ...
67 if [ -z "$1" -o ! -x "$(which wc 2>/dev/null)" ]
68 then
69 echo "==============================================================="
70 return 0
71 fi
72
73 # Get the length of $*
74 str_length="$(echo -n "$*" | wc -m)"
75
76 while [ "$i" -lt "${str_length}" ]
77 do
78 echo -n "="
79
80 i=$((i + 1))
81 done
82
83 echo
84
85 return 0
86}
87
88# Default directory where patches are located
89EPATCH_SOURCE="${WORKDIR}/patch"
90# Default extension for patches
91EPATCH_SUFFIX="patch.bz2"
92# Default options for patch
93EPATCH_OPTS=""
94# List of patches not to apply. Not this is only file names,
95# and not the full path ..
96EPATCH_EXCLUDE=""
97# Change the printed message for a single patch.
98EPATCH_SINGLE_MSG=""
99# Force applying bulk patches even if not following the style:
100#
101# ??_${ARCH}_foo.${EPATCH_SUFFIX}
102#
103EPATCH_FORCE="no"
104
105# This function is for bulk patching, or in theory for just one
106# or two patches.
107#
108# It should work with .bz2, .gz, .zip and plain text patches.
109# Currently all patches should be the same format.
110#
111# You do not have to specify '-p' option to patch, as it will
112# try with -p0 to -p5 until it succeed, or fail at -p5.
113#
114# Above EPATCH_* variables can be used to control various defaults,
115# bug they should be left as is to ensure an ebuild can rely on
116# them for.
117#
118# Patches are applied in current directory.
119#
120# Bulk Patches should preferibly have the form of:
121#
122# ??_${ARCH}_foo.${EPATCH_SUFFIX}
123#
124# For example:
125#
126# 01_all_misc-fix.patch.bz2
127# 02_sparc_another-fix.patch.bz2
128#
129# This ensures that there are a set order, and you can have ARCH
130# specific patches.
131#
132# If you however give an argument to epatch(), it will treat it as a
133# single patch that need to be applied if its a file. If on the other
134# hand its a directory, it will set EPATCH_SOURCE to this.
135#
136# <azarah@gentoo.org> (10 Nov 2002)
137#
138epatch() {
139 local PIPE_CMD=""
140 local STDERR_TARGET="${T}/$$.out"
141 local PATCH_TARGET="${T}/$$.patch"
142 local PATCH_SUFFIX=""
143 local SINGLE_PATCH="no"
144 local x=""
145
146 if [ "$#" -gt 1 ]
147 then
148 eerror "Invalid arguments to epatch()"
149 die "Invalid arguments to epatch()"
150 fi
151
152 if [ -n "$1" -a -f "$1" ]
153 then
154 SINGLE_PATCH="yes"
155
156 local EPATCH_SOURCE="$1"
157 local EPATCH_SUFFIX="${1##*\.}"
158
159 elif [ -n "$1" -a -d "$1" ]
160 then
161 # Allow no extension if EPATCH_FORCE=yes ... used by vim for example ...
162 if [ "${EPATCH_FORCE}" = "yes" ] && [ -z "${EPATCH_SUFFIX}" ]
163 then
164 local EPATCH_SOURCE="$1/*"
165 else
166 local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}"
167 fi
168 else
169 if [ ! -d ${EPATCH_SOURCE} ]
170 then
171 if [ -n "$1" -a "${EPATCH_SOURCE}" = "${WORKDIR}/patch" ]
172 then
173 EPATCH_SOURCE="$1"
174 fi
175
176 echo
177 eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:"
178 eerror
179 eerror " ${EPATCH_SOURCE}"
180 echo
181 die "Cannot find \$EPATCH_SOURCE!"
182 fi
183
184 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}"
185 fi
186
187 case ${EPATCH_SUFFIX##*\.} in
188 bz2)
189 PIPE_CMD="bzip2 -dc"
190 PATCH_SUFFIX="bz2"
191 ;;
192 gz|Z|z)
193 PIPE_CMD="gzip -dc"
194 PATCH_SUFFIX="gz"
195 ;;
196 ZIP|zip)
197 PIPE_CMD="unzip -p"
198 PATCH_SUFFIX="zip"
199 ;;
200 *)
201 PIPE_CMD="cat"
202 PATCH_SUFFIX="patch"
203 ;;
204 esac
205
206 if [ "${SINGLE_PATCH}" = "no" ]
207 then
208 einfo "Applying various patches (bugfixes/updates)..."
209 fi
210 for x in ${EPATCH_SOURCE}
211 do
212 # New ARCH dependant patch naming scheme...
213 #
214 # ???_arch_foo.patch
215 #
216 if [ -f ${x} ] && \
217 ([ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ] || \
218 [ "${EPATCH_FORCE}" = "yes" ])
219 then
220 local count=0
221 local popts="${EPATCH_OPTS}"
222
223 if [ -n "${EPATCH_EXCLUDE}" ]
224 then
225 if [ "`eval echo \$\{EPATCH_EXCLUDE/${x##*/}\}`" != "${EPATCH_EXCLUDE}" ]
226 then
227 continue
228 fi
229 fi
230
231 if [ "${SINGLE_PATCH}" = "yes" ]
232 then
233 if [ -n "${EPATCH_SINGLE_MSG}" ]
234 then
235 einfo "${EPATCH_SINGLE_MSG}"
236 else
237 einfo "Applying ${x##*/}..."
238 fi
239 else
240 einfo " ${x##*/}..."
241 fi
242
243 echo "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
244 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
245
246 # Allow for prefix to differ ... im lazy, so shoot me :/
247 while [ "${count}" -lt 5 ]
248 do
249 # Generate some useful debug info ...
250 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
251 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
252
253 if [ "${PATCH_SUFFIX}" != "patch" ]
254 then
255 echo -n "PIPE_COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
256 echo "${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
257 else
258 PATCH_TARGET="${x}"
259 fi
260
261 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
262 echo "patch ${popts} -p${count} < ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
263
264 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
265 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
266
267 if [ "${PATCH_SUFFIX}" != "patch" ]
268 then
269 if ! (${PIPE_CMD} ${x} > ${PATCH_TARGET}) >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
270 then
271 echo
272 eerror "Could not extract patch!"
273 #die "Could not extract patch!"
274 count=5
275 break
276 fi
277 fi
278
279 if (cat ${PATCH_TARGET} | patch ${popts} --dry-run -f -p${count}) >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
280 then
281 draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
282 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
283 echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
284 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
285 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
286
287 cat ${PATCH_TARGET} | patch ${popts} -p${count} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 2>&1
288
289 if [ "$?" -ne 0 ]
290 then
291 cat ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
292 echo
293 eerror "A dry-run of patch command succeeded, but actually"
294 eerror "applying the patch failed!"
295 #die "Real world sux compared to the dreamworld!"
296 count=5
297 fi
298
299 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
300
301 break
302 fi
303
304 count=$((count + 1))
305 done
306
307 if [ "${PATCH_SUFFIX}" != "patch" ]
308 then
309 rm -f ${PATCH_TARGET}
310 fi
311
312 if [ "${count}" -eq 5 ]
313 then
314 echo
315 eerror "Failed Patch: ${x##*/}!"
316 eerror
317 eerror "Include in your bugreport the contents of:"
318 eerror
319 eerror " ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}"
320 echo
321 die "Failed Patch: ${x##*/}!"
322 fi
323
324 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
325
326 eend 0
327 fi
328 done
329 if [ "${SINGLE_PATCH}" = "no" ]
330 then
331 einfo "Done with patching"
332 fi
333}
334
335# This function return true if we are using the NPTL pthreads
336# implementation.
337#
338# <azarah@gentoo.org> (06 March 2003)
339#
340
341have_NPTL() {
342
343 cat > ${T}/test-nptl.c <<-"END"
344 #define _XOPEN_SOURCE
345 #include <unistd.h>
346 #include <stdio.h>
347
348 int main()
349 {
350 char buf[255];
351 char *str = buf;
352
353 confstr(_CS_GNU_LIBPTHREAD_VERSION, str, 255);
354 if (NULL != str) {
355 printf("%s\n", str);
356 if (NULL != strstr(str, "NPTL"))
357 return 0;
358 }
359
360 return 1;
361 }
362 END
363
364 einfon "Checking for _CS_GNU_LIBPTHREAD_VERSION support in glibc ... "
365 if gcc -o ${T}/nptl ${T}/test-nptl.c &> /dev/null
366 then
367 echo "yes"
368 einfon "Checking what PTHREADS implementation we have ... "
369 if ${T}/nptl
370 then
371 return 0
372 else
373 return 1
374 fi
375 else
376 echo "no"
377 fi
378
379 return 1
380}
381
382# This function check how many cpu's are present, and then set
383# -j in MAKEOPTS accordingly.
384#
385# Thanks to nall <nall@gentoo.org> for this.
386#
387get_number_of_jobs() {
388 local jobs=0
389
390 if [ ! -r /proc/cpuinfo ]
391 then
392 return 1
393 fi
394
395 # This bit is from H?kan Wessberg <nacka-gentoo@refug.org>, bug #13565.
396 if [ "`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | wc -l`" -gt 0 ]
397 then
398 ADMINOPTS="`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | cut -d= -f2 | sed 's/\"//g'`"
399 ADMINPARAM="`echo ${ADMINOPTS} | gawk '{match($0, /-j *[0-9]*/, opt); print opt[0]}'`"
400 ADMINPARAM="${ADMINPARAM/-j}"
401 fi
402
403 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`"
404
405 if [ "${ARCH}" = "amd64" -o "${ARCH}" = "x86" -o "${ARCH}" = "hppa" -o \
406 "${ARCH}" = "arm" -o "${ARCH}" = "mips" ]
407 then
408 # these archs will always have "[Pp]rocessor"
409 jobs="$((`grep -c ^[Pp]rocessor /proc/cpuinfo` * 2))"
410
411 elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ]
412 then
413 # sparc always has "ncpus active"
414 jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
415
416 elif [ "${ARCH}" = "alpha" ]
417 then
418 # alpha has "cpus active", but only when compiled with SMP
419 if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ]
420 then
421 jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
422 else
423 jobs=2
424 fi
425
426 elif [ "${ARCH}" = "ppc" ]
427 then
428 # ppc has "processor", but only when compiled with SMP
429 if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ]
430 then
431 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
432 else
433 jobs=2
434 fi
435 else
436 jobs="$((`grep -c ^cpu /proc/cpuinfo` * 2))"
437 die "Unknown ARCH -- ${ARCH}!"
438 fi
439
440 # Make sure the number is valid ...
441 if [ "${jobs}" -lt 1 ]
442 then
443 jobs=1
444 fi
445
446 if [ -n "${ADMINPARAM}" ]
447 then
448 if [ "${jobs}" -gt "${ADMINPARAM}" ]
449 then
450 einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge..."
451 export MAKEOPTS="${MAKEOPTS} -j${ADMINPARAM}"
452 else
453 einfo "Setting make jobs to \"-j${jobs}\" to ensure successful merge..."
454 export MAKEOPTS="${MAKEOPTS} -j${jobs}"
455 fi
456 fi
457}
458
459# Cheap replacement for when debianutils (and thus mktemp)
460# do not exist on the users system
461# vapier@gentoo.org
462#
463# Takes just 1 parameter (the directory to create tmpfile in)
464mymktemp() {
465 local topdir=$1
466 [ -z "${topdir}" ] && topdir=/tmp
467 if [ `which mktemp 2>/dev/null` ] ; then
468 mktemp -p ${topdir}
469 else
470 local tmp="${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM}"
471 touch ${tmp}
472 echo ${tmp}
473 fi
474}
475
476# Simplify/standardize adding users to the system
477# vapier@gentoo.org
478#
479# enewuser(username, uid, shell, homedir, groups, extra options)
480#
481# Default values if you do not specify any:
482# username: REQUIRED !
483# uid: next available (see useradd(8))
484# note: pass -1 to get default behavior
485# shell: /bin/false
486# homedir: /dev/null
487# groups: none
488# extra: comment of 'added by portage for ${PN}'
489enewuser() {
490 # get the username
491 local euser="$1"; shift
492 if [ -z "${euser}" ] ; then
493 eerror "No username specified !"
494 die "Cannot call enewuser without a username"
495 fi
496
497 # setup a file for testing usernames/groups
498 local tmpfile="`mymktemp ${T}`"
499 chown ${euser} ${tmpfile} >& /dev/null
500 local realuser="`ls -l ${tmpfile} | awk '{print $3}'`"
501
502 # see if user already exists
503 if [ "${euser}" == "${realuser}" ] ; then
504 return 0
505 fi
506 einfo "Adding user '${euser}' to your system ..."
507
508 # options to pass to useradd
509 local opts=""
510
511 # handle uid
512 local euid="$1"; shift
513 if [ ! -z "${euid}" ] && [ "${euid}" != "-1" ] ; then
514 if [ ${euid} -gt 0 ] ; then
515 opts="${opts} -u ${euid}"
516 else
517 eerror "Userid given but is not greater than 0 !"
518 die "${euid} is not a valid UID"
519 fi
520 else
521 euid="next available"
522 fi
523 einfo " - Userid: ${euid}"
524
525 # handle shell
526 local eshell="$1"; shift
527 if [ ! -z "${eshell}" ] ; then
528 if [ ! -e ${eshell} ] ; then
529 eerror "A shell was specified but it does not exist !"
530 die "${eshell} does not exist"
531 fi
532 else
533 eshell=/bin/false
534 fi
535 einfo " - Shell: ${eshell}"
536 opts="${opts} -s ${eshell}"
537
538 # handle homedir
539 local ehome="$1"; shift
540 if [ -z "${ehome}" ] ; then
541 ehome=/dev/null
542 fi
543 einfo " - Home: ${ehome}"
544 opts="${opts} -d ${ehome}"
545
546 # handle groups
547 local egroups="$1"; shift
548 if [ ! -z "${egroups}" ] ; then
549 local realgroup
550 local oldifs="${IFS}"
551 export IFS=","
552 for g in ${egroups} ; do
553 chgrp ${g} ${tmpfile} >& /dev/null
554 realgroup="`ls -l ${tmpfile} | awk '{print $4}'`"
555 if [ "${g}" != "${realgroup}" ] ; then
556 eerror "You must add ${g} to the system first"
557 die "${g} is not a valid GID"
558 fi
559 done
560 export IFS="${oldifs}"
561 opts="${opts} -g ${egroups}"
562 else
563 egroups="(none)"
564 fi
565 einfo " - Groups: ${egroups}"
566
567 # handle extra and add the user
568 local eextra="$@"
569 local oldsandbox=${SANDBOX_ON}
570 export SANDBOX_ON="0"
571 if [ -z "${eextra}" ] ; then
572 useradd ${opts} ${euser} \
573 -c "added by portage for ${PN}" \
574 || die "enewuser failed"
575 else
576 einfo " - Extra: ${eextra}"
577 useradd ${opts} ${euser} ${eextra} \
578 || die "enewuser failed"
579 fi
580 export SANDBOX_ON="${oldsandbox}"
581
582 if [ ! -e ${ehome} ] && [ ! -e ${D}/${ehome} ] ; then
583 einfo " - Creating ${ehome} in ${D}"
584 dodir ${ehome}
585 fowners ${euser} ${ehome}
586 fperms 755 ${ehome}
587 fi
588}
589
590# Simplify/standardize adding groups to the system
591# vapier@gentoo.org
592#
593# enewgroup(group, gid)
594#
595# Default values if you do not specify any:
596# groupname: REQUIRED !
597# gid: next available (see groupadd(8))
598# extra: none
599enewgroup() {
600 # get the group
601 local egroup="$1"; shift
602 if [ -z "${egroup}" ] ; then
603 eerror "No group specified !"
604 die "Cannot call enewgroup without a group"
605 fi
606
607 # setup a file for testing groupname
608 local tmpfile="`mymktemp ${T}`"
609 chgrp ${egroup} ${tmpfile} >& /dev/null
610 local realgroup="`ls -l ${tmpfile} | awk '{print $4}'`"
611
612 # see if group already exists
613 if [ "${egroup}" == "${realgroup}" ] ; then
614 return 0
615 fi
616 einfo "Adding group '${egroup}' to your system ..."
617
618 # options to pass to useradd
619 local opts=""
620
621 # handle gid
622 local egid="$1"; shift
623 if [ ! -z "${egid}" ] ; then
624 if [ ${egid} -gt 0 ] ; then
625 opts="${opts} -g ${egid}"
626 else
627 eerror "Groupid given but is not greater than 0 !"
628 die "${egid} is not a valid GID"
629 fi
630 else
631 egid="next available"
632 fi
633 einfo " - Groupid: ${egid}"
634
635 # handle extra
636 local eextra="$@"
637 opts="${opts} ${eextra}"
638
639 # add the group
640 local oldsandbox=${SANDBOX_ON}
641 export SANDBOX_ON="0"
642 groupadd ${opts} ${egroup} || die "enewgroup failed"
643 export SANDBOX_ON="${oldsandbox}"
644}
645
646# Simple script to replace 'dos2unix' binaries
647# vapier@gentoo.org
648#
649# edos2unix(file, <more files>...)
650edos2unix() {
651 for f in $@ ; do
652 cp ${f} ${T}/edos2unix
653 sed 's/\r$//' ${T}/edos2unix > ${f}
654 done
655}
656
657# Make a desktop file !
658# Great for making those icons in kde/gnome startmenu !
659# Amaze your friends ! Get the women ! Join today !
660# gnome2 /usr/share/applications
661# gnome1 /usr/share/gnome/apps/
662# KDE ${KDEDIR}/share/applnk /usr/share/applnk
663#
664# make_desktop_entry(<binary>, [name], [icon], [type], [path])
665#
666# binary: what binary does the app run with ?
667# name: the name that will show up in the menu
668# icon: give your little like a pretty little icon ...
669# this can be relative (to /usr/share/pixmaps) or
670# a full path to an icon
671# type: what kind of application is this ? for categories:
672# http://www.freedesktop.org/standards/menu/draft/menu-spec/menu-spec.html
673# path: if your app needs to startup in a specific dir
674make_desktop_entry() {
675 [ -z "$1" ] && eerror "You must specify the executable" && return 1
676
677 local exec=${1}
678 local name=${2:-${PN}}
679 local icon=${3:-${PN}.png}
680 local type=${4}
681 local path=${5:-${GAMES_PREFIX}}
682 if [ -z "${type}" ] ; then
683 case ${CATEGORY} in
684 app-emulation) type=Emulator ;;
685 app-games) type=Game ;;
686 *) type="" ;;
687 esac
688 fi
689 local desktop=${T}/${exec}.desktop
690
691echo "[Desktop Entry]
692Encoding=UTF-8
693Version=0.9.2
694Name=${name}
695Type=Application
696Comment=${DESCRIPTION}
697Exec=${exec}
698Path=${path}
699Icon=${icon}
700Categories=Application;${type};" > ${desktop}
701
702 if [ -d /usr/share/applications ] ; then
703 insinto /usr/share/applications
704 doins ${desktop}
705 fi
706
707 #if [ -d /usr/share/gnome/apps ] ; then
708 # insinto /usr/share/gnome/apps/Games
709 # doins ${desktop}
710 #fi
711
712 #if [ ! -z "`ls /usr/kde/* 2>/dev/null`" ] ; then
713 # for ver in /usr/kde/* ; do
714 # insinto ${ver}/share/applnk/Games
715 # doins ${desktop}
716 # done
717 #fi
718
719 if [ -d /usr/share/applnk ] ; then
720 insinto /usr/share/applnk/${type}
721 doins ${desktop}
722 fi
723
724 return 0
725}
726
727# new convenience patch wrapper function to eventually replace epatch(),
728# $PATCHES, $PATCHES1, src_unpack:patch, src_unpack:autopatch and
729# /usr/bin/patch
730# Features:
731# - bulk patch handling similar to epatch()'s
732# - automatic patch level detection like epatch()'s
733# - automatic patch uncompression like epatch()'s
734# - doesn't have the --dry-run overhead of epatch() - inspects patchfiles
735# manually instead
736# - once I decide it's production-ready, it'll be called from base_src_unpack
737# to handle $PATCHES to avoid defining src_unpack just to use xpatch
738
739# accepts zero or more parameters specifying patchfiles and/or patchdirs
740
741# known issues:
742# - only supports unified style patches (does anyone _really_ use anything
743# else?)
744# - because it doesn't use --dry-run there is a risk of it failing
745# to find the files to patch, ie detect the patchlevel, properly. It doesn't use
746# any of the backup heuristics that patch employs to discover a filename.
747# however, this isn't dangerous because if it works for the developer who's
748# writing the ebuild, it'll always work for the users, and if it doesn't,
749# then we'll fix it :-)
750# - no support as yet for patches applying outside $S (and not directly in $WORKDIR).
751xpatch() {
752
753 debug-print-function $FUNCNAME $*
754
755 local list=""
756 local list2=""
757 declare -i plevel
758
759 # parse patch sources
760 for x in $*; do
761 debug-print "$FUNCNAME: parsing parameter $x"
762 if [ -f "$x" ]; then
763 list="$list $x"
764 elif [ -d "$x" ]; then
765 # handles patchdirs like epatch() for now: no recursion.
766 # patches are sorted by filename, so with an xy_foo naming scheme you'll get the right order.
767 # only patches with _$ARCH_ or _all_ in their filenames are applied.
768 for file in `ls -A $x`; do
769 debug-print "$FUNCNAME: parsing in subdir: file $file"
770 if [ -f "$x/$file" ] && [ "${file}" != "${file/_all_}" -o "${file}" != "${file/_$ARCH_}" ]; then
771 list2="$list2 $x/$file"
772 fi
773 done
774 list="`echo $list2 | sort` $list"
775 else
776 die "Couldn't find $x"
777 fi
778 done
779
780 debug-print "$FUNCNAME: final list of patches: $list"
781
782 for x in $list; do
783 debug-print "$FUNCNAME: processing $x"
784 # deal with compressed files. /usr/bin/file is in the system profile, or should be.
785 case "`/usr/bin/file -b $x`" in
786 *gzip*) patchfile="${T}/current.patch"; ungzip -c "$x" > "${patchfile}";;
787 *bzip2*) patchfile="${T}/current.patch"; bunzip2 -c "$x" > "${patchfile}";;
788 *text*) patchfile="$x";;
789 *) die "Could not determine filetype of patch $x";;
790 esac
791 debug-print "$FUNCNAME: patchfile=$patchfile"
792
793 # determine patchlevel. supports p0 and higher with either $S or $WORKDIR as base.
794 target="`/bin/grep -m 1 '^+++ ' $patchfile`"
795 debug-print "$FUNCNAME: raw target=$target"
796 # strip target down to the path/filename, remove leading +++
797 target="${target/+++ }"; target="${target%% *}"
798 # duplicate slashes are discarded by patch wrt the patchlevel. therefore we need
799 # to discard them as well to calculate the correct patchlevel.
800 target="${target//\/\//\/}"
801 debug-print "$FUNCNAME: stripped target=$target"
802
803 # look for target
804 for basedir in "$S" "$WORKDIR" "${PWD}"; do
805 debug-print "$FUNCNAME: looking in basedir=$basedir"
806 cd "$basedir"
807
808 # try stripping leading directories
809 target2="$target"
810 plevel=0
811 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
812 while [ ! -f "$target2" ]; do
813 target2="${target2#*/}" # removes piece of target2 upto the first occurence of /
814 plevel=plevel+1
815 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
816 [ "$target2" == "${target2/\/}" ] && break
817 done
818 test -f "$target2" && break
819
820 # try stripping filename - needed to support patches creating new files
821 target2="${target%/*}"
822 plevel=0
823 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
824 while [ ! -d "$target2" ]; do
825 target2="${target2#*/}" # removes piece of target2 upto the first occurence of /
826 plevel=plevel+1
827 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
828 [ "$target2" == "${target2/\/}" ] && break
829 done
830 test -d "$target2" && break
831
832 done
833
834 test -f "${basedir}/${target2}" || test -d "${basedir}/${target2}" || die "Could not determine patchlevel for $x"
835 debug-print "$FUNCNAME: determined plevel=$plevel"
836 # do the patching
837 ebegin "Applying patch ${x##*/}..."
838 /usr/bin/patch -p$plevel < "$patchfile" > /dev/null || die "Failed to apply patch $x"
839 eend $?
840
841 done
842
843}
844
845# Unpack those pesky makeself generated files ...
846# They're shell scripts with the binary package tagged onto
847# the end of the archive. Loki utilized the format as does
848# many other game companies.
849#
850# Usage: unpack_makeself [file to unpack] [offset]
851# - If the file is not specified then unpack will utilize ${A}.
852# - If the offset is not specified then we will attempt to extract
853# the proper offset from the script itself.
854unpack_makeself() {
855 local src=$1
856 local skip=$2
857
858 if [ -z "${src}" ] ; then
859 src="${DISTDIR}/${A}"
860 else
861 if [ -e "${DISTDIR}/${src}" ] ; then
862 src="${DISTDIR}/${src}"
863 elif [ -e "${PWD}/${src}" ] ; then
864 src="${PWD}/${src}"
865 elif [ -e "${src}" ] ; then
866 src="${src}"
867 fi
868 fi
869 [ ! -e "${src}" ] && die "Could not find requested makeself archive ${src}"
870
871 local shrtsrc=`basename ${src}`
872 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
873 if [ -z "${skip}" ] ; then
874 local ver="`grep -a '#.*Makeself' ${src} | awk '{print $NF}'`"
875 local skip=0
876 case ${ver} in
877 1.5.*) # tested 1.5.{3,4,5} ... guessing 1.5.x series is same
878 skip=`grep -a ^skip= ${src} | cut -d= -f2`
879 ;;
880 2.0|2.0.1)
881 skip=`grep -a ^$'\t'tail ${src} | awk '{print $2}' | cut -b2-`
882 ;;
883 2.1.1)
884 skip=`grep -a ^offset= ${src} | awk '{print $2}' | cut -b2-`
885 let skip="skip + 1"
886 ;;
887 2.1.2)
888 skip=`grep -a ^offset= ${src} | awk '{print $3}' | head -n 1`
889 let skip="skip + 1"
890 ;;
891 2.1.3)
892 skip=`grep -a ^offset= ${src} | awk '{print $3}'`
893 let skip="skip + 1"
894 ;;
895 *)
896 eerror "I'm sorry, but I was unable to support the Makeself file."
897 eerror "The version I detected was '${ver}'."
898 eerror "Please file a bug about the file ${shrtsrc} at"
899 eerror "http://bugs.gentoo.org/ so that support can be added."
900 die "makeself version '${ver}' not supported"
901 ;;
902 esac
903 debug-print "Detected Makeself version ${ver} ... using ${skip} as offset"
904 fi
905
906 # we do this because otherwise a failure in gzip will cause 0 bytes to be sent
907 # to tar which will make tar not extract anything and exit with 0
908 tail -n +${skip} ${src} | gzip -cd | tar -x --no-same-owner -f - 2>/dev/null
909 local pipestatus="${PIPESTATUS[*]}"
910 pipestatus="${pipestatus// }"
911 if [ "${pipestatus//0}" != "" ] ; then
912 # maybe it isnt gzipped ... they usually are, but not always ...
913 tail -n +${skip} ${src} | tar -x --no-same-owner -f - \
914 || die "failure unpacking makeself ${shrtsrc} ('${ver}' +${skip})"
915 fi
916}

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.52

  ViewVC Help
Powered by ViewVC 1.1.20