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

Contents of /eclass/eutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.47 - (show annotations) (download)
Mon Aug 25 13:19:56 2003 UTC (11 years, 2 months ago) by wolf31o2
Branch: MAIN
Changes since 1.46: +2 -2 lines
Updating unpack_makeself to support newer Makeself version used in America's Army 1.9.0

1 # Copyright 1999-2003 Gentoo Technologies, Inc.
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /home/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.46 2003/07/22 18:42:59 vapier Exp $
4 #
5 # Author: Martin Schlemmer <azarah@gentoo.org>
6 #
7 # This eclass is for general purpose functions that most ebuilds
8 # have to implement themselves.
9 #
10 # NB: If you add anything, please comment it!
11
12 ECLASS=eutils
13 INHERITED="$INHERITED $ECLASS"
14
15 DEPEND="$DEPEND !bootstrap? ( sys-devel/patch )"
16
17 DESCRIPTION="Based on the ${ECLASS} eclass"
18
19 # This function generate linker scripts in /usr/lib for dynamic
20 # libs in /lib. This is to fix linking problems when you have
21 # the .so in /lib, and the .a in /usr/lib. What happens is that
22 # in some cases when linking dynamic, the .a in /usr/lib is used
23 # instead of the .so in /lib due to gcc/libtool tweaking ld's
24 # library search path. This cause many builds to fail.
25 # See bug #4411 for more info.
26 #
27 # To use, simply call:
28 #
29 # gen_usr_ldscript libfoo.so
30 #
31 # Note that you should in general use the unversioned name of
32 # the library, as ldconfig should usually update it correctly
33 # to point to the latest version of the library present.
34 #
35 # <azarah@gentoo.org> (26 Oct 2002)
36 #
37 gen_usr_ldscript() {
38
39 # Just make sure it exists
40 dodir /usr/lib
41
42 cat > ${D}/usr/lib/$1 <<"END_LDSCRIPT"
43 /* GNU ld script
44 Because Gentoo have critical dynamic libraries
45 in /lib, and the static versions in /usr/lib, we
46 need to have a "fake" dynamic lib in /usr/lib,
47 otherwise we run into linking problems.
48 See bug #4411 on http://bugs.gentoo.org/ for
49 more info. */
50 GROUP ( /lib/libxxx )
51 END_LDSCRIPT
52
53 dosed "s:libxxx:$1:" /usr/lib/$1
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 #
62 draw_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
89 EPATCH_SOURCE="${WORKDIR}/patch"
90 # Default extension for patches
91 EPATCH_SUFFIX="patch.bz2"
92 # Default options for patch
93 EPATCH_OPTS=""
94 # List of patches not to apply. Not this is only file names,
95 # and not the full path ..
96 EPATCH_EXCLUDE=""
97 # Change the printed message for a single patch.
98 EPATCH_SINGLE_MSG=""
99 # Force applying bulk patches even if not following the style:
100 #
101 # ??_${ARCH}_foo.${EPATCH_SUFFIX}
102 #
103 EPATCH_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 #
138 epatch() {
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
341 have_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 #
387 get_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 # Simplify/standardize adding users to the system
460 # vapier@gentoo.org
461 #
462 # enewuser(username, uid, shell, homedir, groups, extra options)
463 #
464 # Default values if you do not specify any:
465 # username: REQUIRED !
466 # uid: next available (see useradd(8))
467 # note: pass -1 to get default behavior
468 # shell: /bin/false
469 # homedir: /dev/null
470 # groups: none
471 # extra: comment of 'added by portage for ${PN}'
472 enewuser() {
473 # get the username
474 local euser="$1"; shift
475 if [ -z "${euser}" ] ; then
476 eerror "No username specified !"
477 die "Cannot call enewuser without a username"
478 fi
479
480 # setup a file for testing usernames/groups
481 local tmpfile="`mktemp -p ${T}`"
482 touch ${tmpfile}
483 chown ${euser} ${tmpfile} >& /dev/null
484 local realuser="`ls -l ${tmpfile} | awk '{print $3}'`"
485
486 # see if user already exists
487 if [ "${euser}" == "${realuser}" ] ; then
488 return 0
489 fi
490 einfo "Adding user '${euser}' to your system ..."
491
492 # options to pass to useradd
493 local opts=""
494
495 # handle uid
496 local euid="$1"; shift
497 if [ ! -z "${euid}" ] && [ "${euid}" != "-1" ] ; then
498 if [ ${euid} -gt 0 ] ; then
499 opts="${opts} -u ${euid}"
500 else
501 eerror "Userid given but is not greater than 0 !"
502 die "${euid} is not a valid UID"
503 fi
504 else
505 euid="next available"
506 fi
507 einfo " - Userid: ${euid}"
508
509 # handle shell
510 local eshell="$1"; shift
511 if [ ! -z "${eshell}" ] ; then
512 if [ ! -e ${eshell} ] ; then
513 eerror "A shell was specified but it does not exist !"
514 die "${eshell} does not exist"
515 fi
516 else
517 eshell=/bin/false
518 fi
519 einfo " - Shell: ${eshell}"
520 opts="${opts} -s ${eshell}"
521
522 # handle homedir
523 local ehome="$1"; shift
524 if [ -z "${ehome}" ] ; then
525 ehome=/dev/null
526 fi
527 einfo " - Home: ${ehome}"
528 opts="${opts} -d ${ehome}"
529
530 # handle groups
531 local egroups="$1"; shift
532 if [ ! -z "${egroups}" ] ; then
533 local realgroup
534 local oldifs="${IFS}"
535 export IFS=","
536 for g in ${egroups} ; do
537 chgrp ${g} ${tmpfile} >& /dev/null
538 realgroup="`ls -l ${tmpfile} | awk '{print $4}'`"
539 if [ "${g}" != "${realgroup}" ] ; then
540 eerror "You must add ${g} to the system first"
541 die "${g} is not a valid GID"
542 fi
543 done
544 export IFS="${oldifs}"
545 opts="${opts} -g ${egroups}"
546 else
547 egroups="(none)"
548 fi
549 einfo " - Groups: ${egroups}"
550
551 # handle extra and add the user
552 local eextra="$@"
553 local oldsandbox=${SANDBOX_ON}
554 export SANDBOX_ON="0"
555 if [ -z "${eextra}" ] ; then
556 useradd ${opts} ${euser} \
557 -c "added by portage for ${PN}" \
558 || die "enewuser failed"
559 else
560 einfo " - Extra: ${eextra}"
561 useradd ${opts} ${euser} ${eextra} \
562 || die "enewuser failed"
563 fi
564 export SANDBOX_ON="${oldsandbox}"
565
566 if [ ! -e ${ehome} ] && [ ! -e ${D}/${ehome} ] ; then
567 einfo " - Creating ${ehome} in ${D}"
568 dodir ${ehome}
569 fowners ${euser} ${ehome}
570 fperms 755 ${ehome}
571 fi
572 }
573
574 # Simplify/standardize adding groups to the system
575 # vapier@gentoo.org
576 #
577 # enewgroup(group, gid)
578 #
579 # Default values if you do not specify any:
580 # groupname: REQUIRED !
581 # gid: next available (see groupadd(8))
582 # extra: none
583 enewgroup() {
584 # get the group
585 local egroup="$1"; shift
586 if [ -z "${egroup}" ] ; then
587 eerror "No group specified !"
588 die "Cannot call enewgroup without a group"
589 fi
590
591 # setup a file for testing groupname
592 local tmpfile="`mktemp -p ${T}`"
593 touch ${tmpfile}
594 chgrp ${egroup} ${tmpfile} >& /dev/null
595 local realgroup="`ls -l ${tmpfile} | awk '{print $4}'`"
596
597 # see if group already exists
598 if [ "${egroup}" == "${realgroup}" ] ; then
599 return 0
600 fi
601 einfo "Adding group '${egroup}' to your system ..."
602
603 # options to pass to useradd
604 local opts=""
605
606 # handle gid
607 local egid="$1"; shift
608 if [ ! -z "${egid}" ] ; then
609 if [ ${egid} -gt 0 ] ; then
610 opts="${opts} -g ${egid}"
611 else
612 eerror "Groupid given but is not greater than 0 !"
613 die "${egid} is not a valid GID"
614 fi
615 else
616 egid="next available"
617 fi
618 einfo " - Groupid: ${egid}"
619
620 # handle extra
621 local eextra="$@"
622 opts="${opts} ${eextra}"
623
624 # add the group
625 local oldsandbox=${SANDBOX_ON}
626 export SANDBOX_ON="0"
627 groupadd ${opts} ${egroup} || die "enewgroup failed"
628 export SANDBOX_ON="${oldsandbox}"
629 }
630
631 # Simple script to replace 'dos2unix' binaries
632 # vapier@gentoo.org
633 #
634 # edos2unix(file, <more files>...)
635 edos2unix() {
636 for f in $@ ; do
637 cp ${f} ${T}/edos2unix
638 sed 's/\r$//' ${T}/edos2unix > ${f}
639 done
640 }
641
642 # Make a desktop file !
643 # Great for making those icons in kde/gnome startmenu !
644 # Amaze your friends ! Get the women ! Join today !
645 # gnome2 /usr/share/applications
646 # gnome1 /usr/share/gnome/apps/
647 # KDE ${KDEDIR}/share/applnk /usr/share/applnk
648 #
649 # make_desktop_entry(<binary>, [name], [icon], [type], [path])
650 #
651 # binary: what binary does the app run with ?
652 # name: the name that will show up in the menu
653 # icon: give your little like a pretty little icon ...
654 # this can be relative (to /usr/share/pixmaps) or
655 # a full path to an icon
656 # type: what kind of application is this ? for categories:
657 # http://www.freedesktop.org/standards/menu/draft/menu-spec/menu-spec.html
658 # path: if your app needs to startup in a specific dir
659 make_desktop_entry() {
660 [ -z "$1" ] && eerror "You must specify the executable" && return 1
661
662 local exec=${1}
663 local name=${2:-${PN}}
664 local icon=${3:-${PN}.png}
665 local type=${4}
666 local path=${5:-${GAMES_PREFIX}}
667 if [ -z "${type}" ] ; then
668 case ${CATEGORY} in
669 app-emulation) type=Emulator ;;
670 app-games) type=Game ;;
671 *) type="" ;;
672 esac
673 fi
674 local desktop=${T}/${exec}.desktop
675
676 echo "[Desktop Entry]
677 Encoding=UTF-8
678 Version=0.9.2
679 Name=${name}
680 Type=Application
681 Comment=${DESCRIPTION}
682 Exec=${exec}
683 Path=${path}
684 Icon=${icon}
685 Categories=Application;${type};" > ${desktop}
686
687 if [ -d /usr/share/applications ] ; then
688 insinto /usr/share/applications
689 doins ${desktop}
690 fi
691
692 #if [ -d /usr/share/gnome/apps ] ; then
693 # insinto /usr/share/gnome/apps/Games
694 # doins ${desktop}
695 #fi
696
697 #if [ ! -z "`ls /usr/kde/* 2>/dev/null`" ] ; then
698 # for ver in /usr/kde/* ; do
699 # insinto ${ver}/share/applnk/Games
700 # doins ${desktop}
701 # done
702 #fi
703
704 if [ -d /usr/share/applnk ] ; then
705 insinto /usr/share/applnk/${type}
706 doins ${desktop}
707 fi
708
709 return 0
710 }
711
712 # new convenience patch wrapper function to eventually replace epatch(),
713 # $PATCHES, $PATCHES1, src_unpack:patch, src_unpack:autopatch and
714 # /usr/bin/patch
715 # Features:
716 # - bulk patch handling similar to epatch()'s
717 # - automatic patch level detection like epatch()'s
718 # - automatic patch uncompression like epatch()'s
719 # - doesn't have the --dry-run overhead of epatch() - inspects patchfiles
720 # manually instead
721 # - once I decide it's production-ready, it'll be called from base_src_unpack
722 # to handle $PATCHES to avoid defining src_unpack just to use xpatch
723
724 # accepts zero or more parameters specifying patchfiles and/or patchdirs
725
726 # known issues:
727 # - only supports unified style patches (does anyone _really_ use anything
728 # else?)
729 # - because it doesn't use --dry-run there is a risk of it failing
730 # to find the files to patch, ie detect the patchlevel, properly. It doesn't use
731 # any of the backup heuristics that patch employs to discover a filename.
732 # however, this isn't dangerous because if it works for the developer who's
733 # writing the ebuild, it'll always work for the users, and if it doesn't,
734 # then we'll fix it :-)
735 # - no support as yet for patches applying outside $S (and not directly in $WORKDIR).
736 xpatch() {
737
738 debug-print-function $FUNCNAME $*
739
740 local list=""
741 local list2=""
742 declare -i plevel
743
744 # parse patch sources
745 for x in $*; do
746 debug-print "$FUNCNAME: parsing parameter $x"
747 if [ -f "$x" ]; then
748 list="$list $x"
749 elif [ -d "$x" ]; then
750 # handles patchdirs like epatch() for now: no recursion.
751 # patches are sorted by filename, so with an xy_foo naming scheme you'll get the right order.
752 # only patches with _$ARCH_ or _all_ in their filenames are applied.
753 for file in `ls -A $x`; do
754 debug-print "$FUNCNAME: parsing in subdir: file $file"
755 if [ -f "$x/$file" ] && [ "${file}" != "${file/_all_}" -o "${file}" != "${file/_$ARCH_}" ]; then
756 list2="$list2 $x/$file"
757 fi
758 done
759 list="`echo $list2 | sort` $list"
760 else
761 die "Couldn't find $x"
762 fi
763 done
764
765 debug-print "$FUNCNAME: final list of patches: $list"
766
767 for x in $list; do
768 debug-print "$FUNCNAME: processing $x"
769 # deal with compressed files. /usr/bin/file is in the system profile, or should be.
770 case "`/usr/bin/file -b $x`" in
771 *gzip*) patchfile="${T}/current.patch"; ungzip -c "$x" > "${patchfile}";;
772 *bzip2*) patchfile="${T}/current.patch"; bunzip2 -c "$x" > "${patchfile}";;
773 *text*) patchfile="$x";;
774 *) die "Could not determine filetype of patch $x";;
775 esac
776 debug-print "$FUNCNAME: patchfile=$patchfile"
777
778 # determine patchlevel. supports p0 and higher with either $S or $WORKDIR as base.
779 target="`/bin/grep -m 1 '^+++ ' $patchfile`"
780 debug-print "$FUNCNAME: raw target=$target"
781 # strip target down to the path/filename, remove leading +++
782 target="${target/+++ }"; target="${target%% *}"
783 # duplicate slashes are discarded by patch wrt the patchlevel. therefore we need
784 # to discard them as well to calculate the correct patchlevel.
785 target="${target//\/\//\/}"
786 debug-print "$FUNCNAME: stripped target=$target"
787
788 # look for target
789 for basedir in "$S" "$WORKDIR" "${PWD}"; do
790 debug-print "$FUNCNAME: looking in basedir=$basedir"
791 cd "$basedir"
792
793 # try stripping leading directories
794 target2="$target"
795 plevel=0
796 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
797 while [ ! -f "$target2" ]; do
798 target2="${target2#*/}" # removes piece of target2 upto the first occurence of /
799 plevel=plevel+1
800 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
801 [ "$target2" == "${target2/\/}" ] && break
802 done
803 test -f "$target2" && break
804
805 # try stripping filename - needed to support patches creating new files
806 target2="${target%/*}"
807 plevel=0
808 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
809 while [ ! -d "$target2" ]; do
810 target2="${target2#*/}" # removes piece of target2 upto the first occurence of /
811 plevel=plevel+1
812 debug-print "$FUNCNAME: trying target2=$target2, plevel=$plevel"
813 [ "$target2" == "${target2/\/}" ] && break
814 done
815 test -d "$target2" && break
816
817 done
818
819 test -f "${basedir}/${target2}" || test -d "${basedir}/${target2}" || die "Could not determine patchlevel for $x"
820 debug-print "$FUNCNAME: determined plevel=$plevel"
821 # do the patching
822 ebegin "Applying patch ${x##*/}..."
823 /usr/bin/patch -p$plevel < "$patchfile" > /dev/null || die "Failed to apply patch $x"
824 eend $?
825
826 done
827
828 }
829
830 # Unpack those pesky makeself generated files ...
831 # They're shell scripts with the binary package tagged onto
832 # the end of the archive. Loki utilized the format as does
833 # many other game companies.
834 #
835 # Usage: unpack_makeself [file to unpack] [offset]
836 # - If the file is not specified then unpack will utilize ${A}.
837 # - If the offset is not specified then we will attempt to extract
838 # the proper offset from the script itself.
839 unpack_makeself() {
840 local src=$1
841 local skip=$2
842
843 [ -z "${src}" ] && src=${A}
844 [ -e ./${src} ] \
845 && src=${PWD}/${src} \
846 || src=${DISTDIR}/${src}
847 local shrtsrc=`basename ${src}`
848 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
849 if [ -z "${skip}" ] ; then
850 local ver="`grep -a '#.*Makeself' ${src} | awk '{print $NF}'`"
851 local skip=0
852 case ${ver} in
853 1.5.*) # tested 1.5.{3,4,5} ... guessing 1.5.x series is same
854 skip=`grep -a ^skip= ${src} | cut -d= -f2`
855 ;;
856 2.0|2.0.1)
857 skip=`grep -a ^$'\t'tail ${src} | awk '{print $2}' | cut -b2-`
858 ;;
859 2.1.*) # tested 2.1.{1,2,3} ... guessing 2.1.x series is same
860 skip=`grep -a ^offset= ${src} | awk '{print $2}' | cut -b2-`
861 let skip="skip + 1"
862 ;;
863 *)
864 eerror "I'm sorry, but I was unable to support the Makeself file."
865 eerror "The version I detected was '${ver}'."
866 eerror "Please file a bug about the file ${shrtsrc} at"
867 eerror "http://bugs.gentoo.org/ so that support can be added."
868 die "makeself version '${ver}' not supported"
869 ;;
870 esac
871 debug-print "Detected Makeself version ${ver} ... using ${skip} as offset"
872 fi
873
874 # we do this because otherwise a failure in gzip will cause 0 bytes to be sent
875 # to tar which will make tar not extract anything and exit with 0
876 local out="`(tail +${skip} ${src} | gzip -cd | tar -x --no-same-owner -f -) 2>&1`"
877 if [ ! -z "${out}" ] ; then
878 # maybe it isnt gzipped ... they usually are, but not always ...
879 tail +${skip} ${src} | tar -x --no-same-owner -f - \
880 || die "failure unpacking makeself ${shrtsrc} ('${ver}' +${skip})"
881 fi
882 }

  ViewVC Help
Powered by ViewVC 1.1.20