Ticket #302: environment

File environment, 131.0 KB (added by jc, 2 years ago)
Line 
1declare -x ALSA_CARDS=""
2declare -x ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol"
3declare -x APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias"
4declare -x ARCH="arm"
5declare -- AT_GNUCONF_UPDATE="no"
6declare -- AT_M4DIR=""
7declare -- AUTOTOOLS_AUTO_DEPEND="yes"
8declare -- AUTOTOOLS_DEPEND="|| (  =sys-devel/automake-1.11* =sys-devel/automake-1.10* ) >=sys-devel/autoconf-2.61 >=sys-devel/libtool-2.2.6b"
9declare -- BASE_INDIVIDUAL_URI="http://xorg.freedesktop.org/releases/individual"
10declare -x CBUILD="armv4tl-softfloat-linux-gnueabi"
11declare -x CDEFINE_default="__unix__"
12declare -x CFLAGS="-Os -march=armv4t -mtune=arm920t -mabi=aapcs-linux -mlittle-endian -msoft-float -mthumb-interwork -marm -pipe -Wno-error"
13declare -x CFLAGS_default=""
14declare -x CHOST="armv4tl-softfloat-linux-gnueabi"
15declare -x CHOST_default="armv4tl-softfloat-linux-gnueabi"
16declare -x CROSSCOMPILE_OPTS=""
17declare -x CTARGET_default="armv4tl-softfloat-linux-gnueabi"
18declare -x CVS_RSH="ssh"
19declare -x CXXFLAGS="-Os -march=armv4t -mtune=arm920t -mabi=aapcs-linux -mlittle-endian -msoft-float -mthumb-interwork -marm -pipe -Wno-error"
20declare -- DEBUGGABLE="yes"
21declare -x DEFAULT_ABI="default"
22declare -- DEFINED_PHASES=" compile install postinst postrm preinst unpack"
23declare -- DEPEND=">=x11-base/xorg-server-1.5
24        x11-proto/randrproto
25        x11-proto/renderproto
26        x11-proto/xextproto
27        x11-proto/xproto
28        x11-proto/videoproto  || (  =sys-devel/automake-1.11* =sys-devel/automake-1.10* ) >=sys-devel/autoconf-2.61 >=sys-devel/libtool-2.2.6b >=dev-vcs/git-1.6
29                >=sys-devel/libtool-1.5
30                >=sys-devel/m4-1.4
31        >=dev-util/pkgconfig-0.18
32                >=x11-misc/util-macros-1.3.0
33                sys-devel/binutils >=dev-vcs/git-1.6"
34declare -- DESCRIPTION="Experimental video driver for SMedia Glamo"
35declare -x DESTTREE="/usr"
36declare -x DIROPTIONS="-m0755"
37declare -- DRIVER="yes"
38declare -x EAPI="0"
39declare -- EGIT="git.eclass"
40declare -- EGIT_BOOTSTRAP=""
41declare -- EGIT_BRANCH="master"
42declare -- EGIT_COMMIT="master"
43declare -- EGIT_DIFFSTAT_CMD="git --no-pager diff --stat"
44declare -- EGIT_FETCH_CMD="git clone"
45declare -- EGIT_HAS_SUBMODULES="false"
46declare -- EGIT_MASTER="master"
47declare -- EGIT_OFFLINE=""
48declare -- EGIT_OPTIONS=""
49declare -- EGIT_PROJECT="xf86-video-glamo"
50declare -- EGIT_PRUNE="false"
51declare -- EGIT_QUIET="OFF"
52declare -- EGIT_REPACK="false"
53declare -- EGIT_REPO_URI="git://git.openmoko.org/git/xf86-video-glamo.git"
54declare -- EGIT_STORE_DIR="/tmp/distfiles/git-src"
55declare -- EGIT_UPDATE_CMD="git fetch -f -u"
56declare -x EGIT_VERSION="a5ef0525ab34d7d5590aba51651ae1a6f40858bc"
57declare -x ELIBC="glibc"
58declare -- ELIBTOOL_VERSION="2.0.2"
59declare -x ELT_APPLIED_PATCHES=" 2.2 1.5.6 2.2.6"
60declare -x ELT_LTMAIN_SH="/var/tmp/portage/x11-drivers/xf86-video-glamo-9999/work/xf86-video-glamo-9999/ltmain.sh"
61declare -- ELT_PATCH_DIR="/usr/portage/eclass/ELT-patches"
62declare -- EPATCH_EXCLUDE=""
63declare -- EPATCH_FORCE="no"
64declare -- EPATCH_MULTI_MSG="Applying various patches (bugfixes/updates) ..."
65declare -- EPATCH_OPTS="-g0 -E --no-backup-if-mismatch"
66declare -- EPATCH_SINGLE_MSG=""
67declare -- EPATCH_SOURCE="/var/tmp/portage/x11-drivers/xf86-video-glamo-9999/work/patch"
68declare -- EPATCH_SUFFIX="patch.bz2"
69declare -x EXEOPTIONS="-m0755"
70declare -- EXPORTED_FUNCTIONS="src_unpack"
71declare -x FCFLAGS=" -Wno-error"
72declare -x FEATURES="assume-digests distlocks fixpackages news parallel-fetch protect-owned sandbox sfperms strict unmerge-logs unmerge-orphans userfetch"
73declare -x FFLAGS=" -Wno-error"
74declare -- FONT_ECLASS=""
75declare -x GCC_SPECS=""
76declare -- GIT_ECLASS="git"
77declare -- HOMEPAGE="http://www.openmoko.org/"
78declare -x INHERITED="git toolchain-funcs portability flag-o-matic x-modular multilib libtool autotools eutils"
79declare -x INPUT_DEVICES=""
80declare -x INSDESTTREE=""
81declare -x INSOPTIONS="-m0644"
82declare -- IUSE="dri   debug"
83declare -x KERNEL="linux"
84declare -x KERNEL_ABI="default"
85declare -x KEYWORDS="~arm"
86declare -x KV=""
87declare -x LCD_DEVICES=""
88declare -x LDFLAGS="-Wl,-O1"
89declare -x LDFLAGS_default=""
90declare -x LIBDIR_default="lib"
91declare -x LIBOPTIONS="-m0644"
92declare -x LICENSE="GPL-2"
93declare -x MAIL="/var/mail/root"
94declare -- MODULE="driver"
95declare -x MULTILIB_ABIS="default"
96declare -x NETBEANS="apisupport cnd groovy gsf harness ide identity j2ee java mobility nb php profiler soa visualweb webcommon websvccommon xml"
97declare -x OPENGL_PROFILE="xorg-x11"
98declare -x PATH="/usr/lib/portage/bin/ebuild-helpers:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/armv4tl-softfloat-linux-gnueabi/gcc-bin/4.3.4"
99declare -- PDEPEND=" "
100declare -x PORTAGE_COMPRESS_EXCLUDE_SUFFIXES="css gif htm[l]? jp[e]?g js pdf png"
101declare -x PROFILE_ONLY_VARIABLES="ARCH ELIBC KERNEL USERLAND"
102declare -x PROPERTIES=""
103declare -x PROVIDE=""
104declare -x PYTHONDONTWRITEBYTECODE="1"
105declare -x RDEPEND=">=x11-base/xorg-server-1.5   
106        !<=x11-base/xorg-x11-6.9"
107declare -x RESTRICT=""
108declare -x RUBY_TARGETS=""
109declare -x S="/var/tmp/portage/x11-drivers/xf86-video-glamo-9999/work/xf86-video-glamo-9999"
110declare -x SANDBOX_DEBUG="0"
111declare -x SANDBOX_DENY="/etc/ld.so.preload"
112declare -x SANDBOX_PID="26095"
113declare -x SANDBOX_PREDICT="/var/tmp/portage/x11-drivers/xf86-video-glamo-9999/homedir:/dev/crypto"
114declare -x SANDBOX_READ="/:/dev/stdin:/var/tmp"
115declare -x SANDBOX_VERBOSE="1"
116declare -x SANDBOX_WRITE=":/dev/console:/dev/fd:/dev/full:/dev/null:/dev/pts/:/dev/pty:/dev/shm:/dev/stderr:/dev/stdout:/dev/tts:/dev/tty:/dev/vc/:/dev/zero:/proc/self/fd:/tmp:/tmp/:/usr/lib/cf:/usr/lib/conftest:/usr/lib32/cf:/usr/lib32/conftest:/usr/lib64/cf:/usr/lib64/conftest:/usr/tmp/cf:/usr/tmp/conftest:/var/tmp:/var/tmp/:/var/tmp/portage/x11-drivers/xf86-video-glamo-9999/homedir/.bash_history:/tmp/distfiles/git-src"
117declare -x SANE_BACKENDS=""
118declare -x SLOT="0"
119declare -- SNAPSHOT="yes"
120declare -- SRC_URI=""
121declare -x SSH_CLIENT="192.168.2.10 39947 22"
122declare -x SSH_CONNECTION="192.168.2.10 39947 192.168.2.15 22"
123declare -x SSH_TTY="/dev/pts/0"
124declare -x USE="arm elibc_glibc kernel_linux userland_GNU"
125declare -x USERLAND="GNU"
126declare -x VIDEO_CARDS=""
127declare -x WANT_AUTOCONF="2.5"
128declare -x WANT_AUTOMAKE="1.11"
129declare -- X=""
130declare -- XDIR="/usr"
131declare -- XDPVER="-1"
132declare -x XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
133declare -x XZ_OPT="--memory=128M"
134declare -- _="PKG_INSTALL_MASK"
135declare -x _E_DOCDESTTREE_=""
136declare -x _E_EXEDESTTREE_=""
137declare -- _LATEST_AUTOMAKE="1.11 1.10"
138declare -- ___ECLASS_RECUR_MULTILIB="yes"
139declare -- ___ECLASS_RECUR_TOOLCHAIN_FUNCS="yes"
140declare -- elogcmd="elog"
141declare -- filter_opts=""
142declare -- str="git_bootstrap: entering function"
143ELT_find_ltmain_sh ()
144{
145    local x=;
146    local dirlist=;
147    for x in $(find "${S}" -name 'ltmain.sh');
148    do
149        dirlist="${dirlist} ${x%/*}";
150    done;
151    echo "${dirlist}"
152}
153ELT_libtool_version ()
154{
155    local ltmain_sh=$1;
156    local version=;
157    version=$(eval $(grep -e '^[[:space:]]*VERSION=' "${ltmain_sh}");                    echo "${VERSION}");
158    [[ -z ${version} ]] && version="0";
159    echo "${version}"
160}
161ELT_try_and_apply_patch ()
162{
163    local ret=0;
164    local file=$1;
165    local patch=$2;
166    if patch -p0 --dry-run "${file}" "${patch}" &>"${T}/elibtool.log"; then
167        einfo "  Applying $(basename "$(dirname "${patch}")")-${patch##*/}.patch ...";
168        patch -p0 -g0 --no-backup-if-mismatch "${file}" "${patch}" &>"${T}/elibtool.log";
169        ret=$?;
170        export ELT_APPLIED_PATCHES="${ELT_APPLIED_PATCHES} ${patch##*/}";
171    else
172        ret=1;
173    fi;
174    return "${ret}"
175}
176ELT_walk_patches ()
177{
178    local patch;
179    local ret=1;
180    local file=$1;
181    local patch_set=$2;
182    local patch_dir="${ELT_PATCH_DIR}/${patch_set}";
183    local rem_int_dep=$3;
184    [[ -z ${patch_set} ]] && return 1;
185    [[ ! -d ${patch_dir} ]] && return 1;
186    pushd "${ELT_PATCH_DIR}" > /dev/null;
187    for patch in $(find "${patch_set}" -maxdepth 1 -type f | LC_ALL=C sort -r);
188    do
189        if [[ -n ${rem_int_dep} ]]; then
190            local tmp="${T}/$$.rem_int_deps.patch";
191            sed -e "s|@REM_INT_DEP@|${rem_int_dep}|g" "${patch}" > "${tmp}";
192            patch=${tmp};
193        fi;
194        if ELT_try_and_apply_patch "${file}" "${patch}"; then
195            ret=0;
196            break;
197        fi;
198    done;
199    popd > /dev/null;
200    return ${ret}
201}
202VER_major ()
203{
204    [[ -z $1 ]] && return 1;
205    local VER=$@;
206    echo "${VER%%[^[:digit:]]*}"
207}
208VER_micro ()
209{
210    [[ -z $1 ]] && return 1;
211    local VER=$@;
212    VER=${VER#*.*.};
213    echo "${VER%%[^[:digit:]]*}"
214}
215VER_minor ()
216{
217    [[ -z $1 ]] && return 1;
218    local VER=$@;
219    VER=${VER#*.};
220    echo "${VER%%[^[:digit:]]*}"
221}
222VER_to_int ()
223{
224    [[ -z $1 ]] && return 1;
225    local VER_MAJOR=$(VER_major "$1");
226    local VER_MINOR=$(VER_minor "$1");
227    local VER_MICRO=$(VER_micro "$1");
228    local VER_int=$(( VER_MAJOR * 65536 + VER_MINOR * 256 + VER_MICRO ));
229    if [[ ${VER_int} -ge 65536 ]]; then
230        echo "${VER_int}";
231        return 0;
232    fi;
233    echo 1;
234    return 1
235}
236_cdrom_locate_file_on_cd ()
237{
238    local mline="";
239    local showedmsg=0 showjolietmsg=0;
240    while [[ -z ${CDROM_ROOT} ]]; do
241        local i=0;
242        local -a cdset=(${*//:/ });
243        if [[ -n ${CDROM_SET} ]]; then
244            cdset=(${cdset[${CDROM_SET}]});
245        fi;
246        while [[ -n ${cdset[${i}]} ]]; do
247            local dir=$(dirname ${cdset[${i}]});
248            local file=$(basename ${cdset[${i}]});
249            local point= node= fs= foo=;
250            while read point node fs foo; do
251                [[ " cd9660 iso9660 udf " != *" ${fs} "* ]] && ! [[ ${fs} == "subfs" && ",${opts}," == *",fs=cdfss,"* ]] && continue;
252                point=${point//\040/ };
253                [[ ! -d ${point}/${dir} ]] && continue;
254                [[ -z $(find "${point}/${dir}" -maxdepth 1 -iname "${file}") ]] && continue;
255                export CDROM_ROOT=${point};
256                export CDROM_SET=${i};
257                export CDROM_MATCH=${cdset[${i}]};
258                return;
259            done <<< "$(get_mounts)";
260            ((++i));
261        done;
262        echo;
263        if [[ ${showedmsg} -eq 0 ]]; then
264            if [[ ${CDROM_TOTAL_CDS} -eq 1 ]]; then
265                if [[ -z ${CDROM_NAME} ]]; then
266                    einfo "Please insert+mount the cdrom for ${PN} now !";
267                else
268                    einfo "Please insert+mount the ${CDROM_NAME} cdrom now !";
269                fi;
270            else
271                if [[ -z ${CDROM_NAME_1} ]]; then
272                    einfo "Please insert+mount cd #${CDROM_CURRENT_CD} for ${PN} now !";
273                else
274                    local var="CDROM_NAME_${CDROM_CURRENT_CD}";
275                    einfo "Please insert+mount the ${!var} cdrom now !";
276                fi;
277            fi;
278            showedmsg=1;
279        fi;
280        einfo "Press return to scan for the cd again";
281        einfo "or hit CTRL+C to abort the emerge.";
282        echo;
283        if [[ ${showjolietmsg} -eq 0 ]]; then
284            showjolietmsg=1;
285        else
286            ewarn "If you are having trouble with the detection";
287            ewarn "of your CD, it is possible that you do not have";
288            ewarn "Joliet support enabled in your kernel.  Please";
289            ewarn "check that CONFIG_JOLIET is enabled in your kernel.";
290            ebeep 5;
291        fi;
292        read || die "something is screwed with your system";
293    done
294}
295_elibtoolize ()
296{
297    local opts g=;
298    [[ -n $(autotools_check_macro AC_PROG_LIBTOOL AM_PROG_LIBTOOL LT_INIT) ]] || return 0;
299    [[ -f GNUmakefile.am || -f Makefile.am ]] && opts="--automake";
300    [[ ${CHOST} == *-darwin* ]] && g=g;
301    autotools_run_tool ${LIBTOOLIZE:-${g}libtoolize} "$@" ${opts};
302    eaclocal
303}
304_filter-hardened ()
305{
306    local f;
307    for f in "$@";
308    do
309        case "${f}" in
310            -fPIC | -fpic | -fPIE | -fpie | -Wl,pie | -pie)
311                gcc-specs-pie || continue;
312                is-flagq -nopie || append-flags -nopie
313            ;;
314            -fstack-protector)
315                gcc-specs-ssp || continue;
316                is-flagq -fno-stack-protector || append-flags $(test-flags -fno-stack-protector)
317            ;;
318            -fstack-protector-all)
319                gcc-specs-ssp-to-all || continue;
320                is-flagq -fno-stack-protector-all || append-flags $(test-flags -fno-stack-protector-all)
321            ;;
322            -fno-strict-overflow)
323                gcc-specs-nostrict || continue;
324                is-flagq -fstrict-overflow || append-flags $(test-flags -fstrict-overflow)
325            ;;
326        esac;
327    done
328}
329_filter-var ()
330{
331    local f x VAR VAL;
332    declare -a new;
333    VAR=$1;
334    shift;
335    eval VAL=\${${VAR}};
336    for f in ${VAL};
337    do
338        for x in "$@";
339        do
340            [[ ${f} == ${x} ]] && continue 2;
341        done;
342        eval new\[\${\#new\[@]}]=\${f};
343    done;
344    eval export ${VAR}=\${new\[*]}
345}
346_gcc-install-dir ()
347{
348    echo "$(LC_ALL=C $(tc-getCC) -print-search-dirs 2> /dev/null |              awk '$1=="install:" {print $2}')"
349}
350_gcc-specs-directive_raw ()
351{
352    local cc=$(tc-getCC);
353    local specfiles=$(LC_ALL=C ${cc} -v 2>&1 | awk '$1=="Reading" {print $NF}');
354    ${cc} -dumpspecs 2> /dev/null | cat - ${specfiles} | awk -v directive=$1 'BEGIN     { pspec=""; spec=""; outside=1 }
355$1=="*"directive":"  { pspec=spec; spec=""; outside=0; next }
356        outside || NF==0 || ( substr($1,1,1)=="*" && substr($1,length($1),1)==":" ) { outside=1; next }
357        spec=="" && substr($0,1,1)=="+" { spec=pspec " " substr($0,2); next }
358        { spec=spec $0 }
359END     { print spec }';
360    return 0
361}
362_gcc-specs-exists ()
363{
364    [[ -f $(_gcc-install-dir)/$1 ]]
365}
366_is_flagq ()
367{
368    local x;
369    for x in ${!1};
370    do
371        [[ ${x} == $2 ]] && return 0;
372    done;
373    return 1
374}
375append-cflags ()
376{
377    [[ -z $* ]] && return 0;
378    export CFLAGS="${CFLAGS} $*";
379    return 0
380}
381append-cppflags ()
382{
383    [[ -z $* ]] && return 0;
384    export CPPFLAGS="${CPPFLAGS} $*";
385    return 0
386}
387append-cxxflags ()
388{
389    [[ -z $* ]] && return 0;
390    export CXXFLAGS="${CXXFLAGS} $*";
391    return 0
392}
393append-fflags ()
394{
395    [[ -z $* ]] && return 0;
396    export FFLAGS="${FFLAGS} $*";
397    export FCFLAGS="${FCFLAGS} $*";
398    return 0
399}
400append-flags ()
401{
402    [[ -z $* ]] && return 0;
403    append-cflags "$@";
404    append-cxxflags "$@";
405    append-fflags "$@";
406    return 0
407}
408append-ldflags ()
409{
410    [[ -z $* ]] && return 0;
411    local flag;
412    for flag in "$@";
413    do
414        [[ ${flag} == -l* ]] && ewarn "Appending a library link instruction (${flag}); libraries to link to should not be passed through LDFLAGS";
415    done;
416    export LDFLAGS="${LDFLAGS} $*";
417    return 0
418}
419append-lfs-flags ()
420{
421    [[ -n $@ ]] && die "append-lfs-flags takes no arguments";
422    append-cppflags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
423}
424append-libs ()
425{
426    [[ -z $* ]] && return 0;
427    local flag;
428    for flag in "$@";
429    do
430        [[ ${flag} == -l* ]] && flag=${flag#-l};
431        export LIBS="${LIBS} -l${flag}";
432    done;
433    return 0
434}
435autotools_check_macro ()
436{
437    [[ -f configure.ac || -f configure.in ]] || return 0;
438    local macro;
439    for macro in "$@";
440    do
441        WANT_AUTOCONF="2.5" autoconf --trace="${macro}" 2> /dev/null;
442    done;
443    return 0
444}
445autotools_get_auxdir ()
446{
447    local auxdir_scan_out;
448    auxdir_scan_out=$(autotools_check_macro "AC_CONFIG_AUX_DIR");
449    [[ -n ${auxdir_scan_out} ]] || return 0;
450    echo ${auxdir_scan_out} | gawk '($0 !~ /^[[:space:]]*(#|dnl)/) {
451                if (match($0, /AC_CONFIG_AUX_DIR:(.*)$/, res))
452                        print res[1]
453        }' | uniq;
454    return 0
455}
456autotools_get_subdirs ()
457{
458    local subdirs_scan_out;
459    subdirs_scan_out=$(autotools_check_macro "AC_CONFIG_SUBDIRS");
460    [[ -n ${subdirs_scan_out} ]] || return 0;
461    echo "${subdirs_scan_out}" | gawk '($0 !~ /^[[:space:]]*(#|dnl)/) {
462                if (match($0, /AC_CONFIG_SUBDIRS:(.*)$/, res))
463                        print res[1]
464        }' | uniq;
465    return 0
466}
467autotools_run_tool ()
468{
469    if [[ ${EBUILD_PHASE} != "unpack" && ${EBUILD_PHASE} != "prepare" ]]; then
470        ewarn "QA Warning: running $1 in ${EBUILD_PHASE} phase";
471    fi;
472    if [[ ${WANT_AUTOMAKE} == "latest" ]]; then
473        for pv in ${_LATEST_AUTOMAKE};
474        do
475            ROOT=/ has_version "=sys-devel/automake-${pv}*" && export WANT_AUTOMAKE="$pv";
476        done;
477        unset pv;
478        [[ ${WANT_AUTOMAKE} == "latest" ]] && die "Cannot find the latest automake! Tried ${_LATEST_AUTOMAKE}";
479    fi;
480    [[ ${WANT_AUTOCONF} == "latest" ]] && export WANT_AUTOCONF=2.5;
481    local STDERR_TARGET="${T}/$1.out";
482    if [[ -e ${STDERR_TARGET} ]]; then
483        STDERR_TARGET="${T}/$1-$$.out";
484    fi;
485    printf "***** $1 *****\n***** PWD: ${PWD}\n***** $*\n\n" > "${STDERR_TARGET}";
486    ebegin "Running $@";
487    "$@" >> "${STDERR_TARGET}" 2>&1;
488    eend $?;
489    if [[ $? != 0 && ${NO_FAIL} != 1 ]]; then
490        echo;
491        eerror "Failed Running $1 !";
492        eerror;
493        eerror "Include in your bugreport the contents of:";
494        eerror;
495        eerror "  ${STDERR_TARGET}";
496        echo;
497        die "Failed Running $1 !";
498    fi
499}
500built_with_use ()
501{
502    local hidden="no";
503    if [[ $1 == "--hidden" ]]; then
504        hidden="yes";
505        shift;
506    fi;
507    local missing_action="die";
508    if [[ $1 == "--missing" ]]; then
509        missing_action=$2;
510        shift;
511        shift;
512        case ${missing_action} in
513            true | false | die)
514
515            ;;
516            *)
517                die "unknown action '${missing_action}'"
518            ;;
519        esac;
520    fi;
521    local opt=$1;
522    [[ ${opt:0:1} = "-" ]] && shift || opt="-a";
523    local PKG=$(best_version $1);
524    [[ -z ${PKG} ]] && die "Unable to resolve $1 to an installed package";
525    shift;
526    local USEFILE=${ROOT}/var/db/pkg/${PKG}/USE;
527    local IUSEFILE=${ROOT}/var/db/pkg/${PKG}/IUSE;
528    if [[ ! -e ${USEFILE} ]] || [[ ! -e ${IUSEFILE} && ${hidden} == "no" ]]; then
529        case ${missing_action} in
530            true)
531                return 0
532            ;;
533            false)
534                return 1
535            ;;
536            die)
537                die "Unable to determine what USE flags $PKG was built with"
538            ;;
539        esac;
540    fi;
541    if [[ ${hidden} == "no" ]]; then
542        local IUSE_BUILT=($(<"${IUSEFILE}"));
543        local expand;
544        for expand in $(echo ${USE_EXPAND} | tr '[:upper:]' '[:lower:]');
545        do
546            if [[ $1 == ${expand}_* ]]; then
547                expand="";
548                break;
549            fi;
550        done;
551        if [[ -n ${expand} ]]; then
552            if ! has $1 ${IUSE_BUILT[@]#[-+]}; then
553                case ${missing_action} in
554                    true)
555                        return 0
556                    ;;
557                    false)
558                        return 1
559                    ;;
560                    die)
561                        die "$PKG does not actually support the $1 USE flag!"
562                    ;;
563                esac;
564            fi;
565        fi;
566    fi;
567    local USE_BUILT=$(<${USEFILE});
568    while [[ $# -gt 0 ]]; do
569        if [[ ${opt} = "-o" ]]; then
570            has $1 ${USE_BUILT} && return 0;
571        else
572            has $1 ${USE_BUILT} || return 1;
573        fi;
574        shift;
575    done;
576    [[ ${opt} = "-a" ]]
577}
578cdrom_get_cds ()
579{
580    local cdcnt=0;
581    local f=;
582    for f in "$@";
583    do
584        ((++cdcnt));
585        export CDROM_CHECK_${cdcnt}="$f";
586    done;
587    export CDROM_TOTAL_CDS=${cdcnt};
588    export CDROM_CURRENT_CD=1;
589    if [[ -n ${CD_ROOT}${CD_ROOT_1} ]]; then
590        local var=;
591        cdcnt=0;
592        while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]]; do
593            ((++cdcnt));
594            var="CD_ROOT_${cdcnt}";
595            [[ -z ${!var} ]] && var="CD_ROOT";
596            if [[ -z ${!var} ]]; then
597                eerror "You must either use just the CD_ROOT";
598                eerror "or specify ALL the CD_ROOT_X variables.";
599                eerror "In this case, you will need ${CDROM_TOTAL_CDS} CD_ROOT_X variables.";
600                die "could not locate CD_ROOT_${cdcnt}";
601            fi;
602        done;
603        export CDROM_ROOT=${CD_ROOT_1:-${CD_ROOT}};
604        einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}";
605        export CDROM_SET=-1;
606        for f in ${CDROM_CHECK_1//:/ };
607        do
608            ((++CDROM_SET));
609            [[ -e ${CD_ROOT}/${f} ]] && break;
610        done;
611        export CDROM_MATCH=${f};
612        return;
613    fi;
614    if [[ ${CDROM_TOTAL_CDS} -eq 1 ]]; then
615        einfo "This ebuild will need the ${CDROM_NAME:-cdrom for ${PN}}";
616        echo;
617        einfo "If you do not have the CD, but have the data files";
618        einfo "mounted somewhere on your filesystem, just export";
619        einfo "the variable CD_ROOT so that it points to the";
620        einfo "directory containing the files.";
621        echo;
622        einfo "For example:";
623        einfo "export CD_ROOT=/mnt/cdrom";
624        echo;
625    else
626        if [[ -n ${CDROM_NAME_SET} ]]; then
627            cdcnt=0;
628            while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]]; do
629                ((++cdcnt));
630                export CDROM_NAME_${cdcnt}="${CDROM_NAME_SET[$((${cdcnt}-1))]}";
631            done;
632        fi;
633        einfo "This package will need access to ${CDROM_TOTAL_CDS} cds.";
634        cdcnt=0;
635        while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]]; do
636            ((++cdcnt));
637            var="CDROM_NAME_${cdcnt}";
638            [[ ! -z ${!var} ]] && einfo " CD ${cdcnt}: ${!var}";
639        done;
640        echo;
641        einfo "If you do not have the CDs, but have the data files";
642        einfo "mounted somewhere on your filesystem, just export";
643        einfo "the following variables so they point to the right place:";
644        einfon "";
645        cdcnt=0;
646        while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]]; do
647            ((++cdcnt));
648            echo -n " CD_ROOT_${cdcnt}";
649        done;
650        echo;
651        einfo "Or, if you have all the files in the same place, or";
652        einfo "you only have one cdrom, you can export CD_ROOT";
653        einfo "and that place will be used as the same data source";
654        einfo "for all the CDs.";
655        echo;
656        einfo "For example:";
657        einfo "export CD_ROOT_1=/mnt/cdrom";
658        echo;
659    fi;
660    export CDROM_SET="";
661    export CDROM_CURRENT_CD=0;
662    cdrom_load_next_cd
663}
664cdrom_load_next_cd ()
665{
666    local var;
667    ((++CDROM_CURRENT_CD));
668    unset CDROM_ROOT;
669    var=CD_ROOT_${CDROM_CURRENT_CD};
670    [[ -z ${!var} ]] && var="CD_ROOT";
671    if [[ -z ${!var} ]]; then
672        var="CDROM_CHECK_${CDROM_CURRENT_CD}";
673        _cdrom_locate_file_on_cd ${!var};
674    else
675        export CDROM_ROOT=${!var};
676    fi;
677    einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
678}
679check_license ()
680{
681    local lic=$1;
682    if [ -z "${lic}" ]; then
683        lic="${PORTDIR}/licenses/${LICENSE}";
684    else
685        if [ -e "${PORTDIR}/licenses/${lic}" ]; then
686            lic="${PORTDIR}/licenses/${lic}";
687        else
688            if [ -e "${PWD}/${lic}" ]; then
689                lic="${PWD}/${lic}";
690            else
691                if [ -e "${lic}" ]; then
692                    lic="${lic}";
693                fi;
694            fi;
695        fi;
696    fi;
697    local l="`basename ${lic}`";
698    local alic;
699    eshopts_push -o noglob;
700    for alic in ${ACCEPT_LICENSE};
701    do
702        if [[ ${alic} == ${l} ]]; then
703            eshopts_pop;
704            return 0;
705        fi;
706    done;
707    eshopts_pop;
708    [ ! -f "${lic}" ] && die "Could not find requested license ${lic}";
709    local licmsg=$(emktemp);
710    cat > ${licmsg}  <<-EOF
711**********************************************************
712The following license outlines the terms of use of this
713package.  You MUST accept this license for installation to
714continue.  When you are done viewing, hit 'q'.  If you
715CTRL+C out of this, the install will not run!
716**********************************************************
717
718EOF
719
720    cat ${lic} >> ${licmsg};
721    ${PAGER:-less} ${licmsg} || die "Could not execute pager (${PAGER}) to accept ${lic}";
722    einfon "Do you accept the terms of this license (${l})? [yes/no] ";
723    read alic;
724    case ${alic} in
725        yes | Yes | y | Y)
726            return 0
727        ;;
728        *)
729            echo;
730            echo;
731            echo;
732            eerror "You MUST accept the license to continue!  Exiting!";
733            die "Failed to accept license"
734        ;;
735    esac
736}
737cleanup_fonts ()
738{
739    local ALLOWED_FILES="encodings.dir fonts.alias fonts.cache-1 fonts.dir fonts.scale";
740    for DIR in ${FONT_DIR};
741    do
742        unset KEEP_FONTDIR;
743        REAL_DIR=${ROOT}usr/share/fonts/${DIR};
744        ebegin "Checking ${REAL_DIR} for useless files";
745        pushd ${REAL_DIR} &>/dev/null;
746        for FILE in *;
747        do
748            unset MATCH;
749            for ALLOWED_FILE in ${ALLOWED_FILES};
750            do
751                if [[ ${FILE} = ${ALLOWED_FILE} ]]; then
752                    MATCH="yes";
753                    break;
754                fi;
755            done;
756            if [[ -n ${MATCH} ]]; then
757                continue;
758            fi;
759            KEEP_FONTDIR="yes";
760            break;
761        done;
762        popd &>/dev/null;
763        if [[ -z "${KEEP_FONTDIR}" ]]; then
764            rm -rf ${REAL_DIR};
765        fi;
766        eend 0;
767    done
768}
769create_font_cache ()
770{
771    font_pkg_postinst
772}
773create_fonts_dir ()
774{
775    ebegin "Generating fonts.dir files";
776    for DIR in ${FONT_DIR};
777    do
778        x=${ROOT}/usr/share/fonts/${DIR};
779        [[ -z "$(ls ${x}/)" ]] && continue;
780        [[ "$(ls ${x}/)" = "fonts.cache-1" ]] && continue;
781        if [[ "${x/encodings}" = "${x}" ]]; then
782            mkfontdir -e "${ROOT}"/usr/share/fonts/encodings -e "${ROOT}"/usr/share/fonts/encodings/large -- ${x};
783        fi;
784    done;
785    eend 0
786}
787create_fonts_scale ()
788{
789    ebegin "Creating fonts.scale files";
790    local x;
791    for DIR in ${FONT_DIR};
792    do
793        x=${ROOT}/usr/share/fonts/${DIR};
794        [[ -z "$(ls ${x}/)" ]] && continue;
795        [[ "$(ls ${x}/)" = "fonts.cache-1" ]] && continue;
796        if [[ "${x/encodings}" = "${x}" ]] && [[ -n "$(find ${x} -iname '*.[pot][ft][abcf]' -print)" ]]; then
797            mkfontscale -a "${ROOT}"/usr/share/fonts/encodings/encodings.dir -- ${x};
798        fi;
799    done;
800    eend 0
801}
802create_ml_includes ()
803{
804    local dest=$1;
805    shift;
806    local basedirs=$(create_ml_includes-listdirs "$@");
807    create_ml_includes-makedestdirs ${dest} ${basedirs};
808    local file;
809    for file in $(create_ml_includes-allfiles ${basedirs});
810    do
811        ( echo "/* Autogenerated by create_ml_includes() in multilib.eclass */";
812        local dir;
813        for dir in ${basedirs};
814        do
815            if [[ -f ${D}/${dir}/${file} ]]; then
816                echo "";
817                local sym=$(create_ml_includes-sym_for_dir ${dir} "$@");
818                if [[ ${sym/=} != "${sym}" ]]; then
819                    echo "#if ${sym}";
820                else
821                    if [[ ${sym::1} == "!" ]]; then
822                        echo "#ifndef ${sym:1}";
823                    else
824                        echo "#ifdef ${sym}";
825                    fi;
826                fi;
827                echo "# include <$(create_ml_includes-absolute ${dir}/${file})>";
828                echo "#endif /* ${sym} */";
829            fi;
830        done ) > "${D}/${dest}/${file}";
831    done
832}
833create_ml_includes-absolute ()
834{
835    local dst="$(create_ml_includes-tidy_path $1)";
836    dst=(${dst//\// });
837    local i;
838    for ((i=0; i<${#dst[*]}; i++))
839    do
840        [ "${dst[i]}" == "include" ] && break;
841    done;
842    local strip_upto=$i;
843    for ((i=strip_upto+1; i<${#dst[*]}-1; i++))
844    do
845        echo -n ${dst[i]}/;
846    done;
847    echo -n ${dst[i]}
848}
849create_ml_includes-allfiles ()
850{
851    [[ -z ${ED} ]] && local ED=${D};
852    local basedir file;
853    for basedir in "$@";
854    do
855        for file in $(find "${ED}"/${basedir} -type f);
856        do
857            echo ${file/${ED}\/${basedir}\//};
858        done;
859    done | sort | uniq
860}
861create_ml_includes-listdirs ()
862{
863    local dirs;
864    local data;
865    for data in "$@";
866    do
867        dirs="${dirs} ${data/*:/}";
868    done;
869    echo ${dirs:1}
870}
871create_ml_includes-makedestdirs ()
872{
873    local dest=$1;
874    shift;
875    local basedirs=$@;
876    [[ -z ${ED} ]] && local ED=${D};
877    dodir ${dest};
878    local basedir;
879    for basedir in ${basedirs};
880    do
881        local dir;
882        for dir in $(find "${ED}"/${basedir} -type d);
883        do
884            dodir ${dest}/${dir/${ED}\/${basedir}/};
885        done;
886    done
887}
888create_ml_includes-sym_for_dir ()
889{
890    local dir=$1;
891    shift;
892    local data;
893    for data in "$@";
894    do
895        if [[ ${data} == *:${dir} ]]; then
896            echo ${data/:*/};
897            return 0;
898        fi;
899    done;
900    echo "Shouldn't be here -- create_ml_includes-sym_for_dir $1 $@";
901    exit 1
902}
903create_ml_includes-tidy_path ()
904{
905    local removed=$1;
906    if [ -n "${removed}" ]; then
907        while [ "${removed}" != "${removed/\/\//\/}" ]; do
908            removed=${removed/\/\//\/};
909        done;
910        while [ "${removed}" != "${removed//\/.\//\/}" ]; do
911            removed=${removed//\/.\//\/};
912        done;
913        [ "${removed##*/}" = "." ] && removed=${removed%/*};
914        while [ "${removed}" != "${removed//\/..\/}" ]; do
915            local p1="${removed%%\/..\/*}";
916            local p2="${removed#*\/..\/}";
917            removed="${p1%\/*}/${p2}";
918        done;
919        [ "${removed##*/}" = ".." ] && removed=${removed%/*/*};
920        [ "${removed##*/}" = "" ] && removed=${removed%/*};
921        echo ${removed};
922    fi
923}
924darwintoolize ()
925{
926    ewarn "darwintoolize() is deprecated, please just use elibtoolize()!";
927    elibtoolize
928}
929discover_font_dirs ()
930{
931    FONT_DIRS="${FONT_DIR}"
932}
933dlopen_lib ()
934{
935    case "${CHOST}" in
936        *-linux-gnu* | *-linux-uclibc | *-interix*)
937            echo "-ldl"
938        ;;
939    esac
940}
941doicon ()
942{
943    ( local i j ret;
944    insinto /usr/share/pixmaps;
945    for i in "$@";
946    do
947        if [[ -f ${i} ]]; then
948            doins "${i}";
949            ((ret+=$?));
950        else
951            if [[ -d ${i} ]]; then
952                for j in "${i}"/*.png;
953                do
954                    doins "${j}";
955                    ((ret+=$?));
956                done;
957            else
958                ((++ret));
959            fi;
960        fi;
961    done;
962    exit ${ret} )
963}
964domenu ()
965{
966    ( local i j ret=0;
967    insinto /usr/share/applications;
968    for i in "$@";
969    do
970        if [[ -f ${i} ]]; then
971            doins "${i}";
972            ((ret+=$?));
973        else
974            if [[ -d ${i} ]]; then
975                for j in "${i}"/*.desktop;
976                do
977                    doins "${j}";
978                    ((ret+=$?));
979                done;
980            else
981                ((++ret));
982            fi;
983        fi;
984    done;
985    exit ${ret} )
986}
987dyn_pretend ()
988{
989    ebuild_phase_with_hooks pkg_pretend
990}
991eaclocal ()
992{
993    local aclocal_opts;
994    local amflags_file;
995    for amflags_file in GNUmakefile.am Makefile.am GNUmakefile.in Makefile.in;
996    do
997        [[ -e ${amflags_file} ]] || continue;
998        aclocal_opts=$(sed -n '/^ACLOCAL_AMFLAGS[[:space:]]*=/s:[^=]*=::p' ${amflags_file});
999        eval aclocal_opts=\"${aclocal_opts}\";
1000        break;
1001    done;
1002    if [[ -n ${AT_M4DIR} ]]; then
1003        for x in ${AT_M4DIR};
1004        do
1005            case "${x}" in
1006                "-I")
1007
1008                ;;
1009                *)
1010                    [[ ! -d ${x} ]] && ewarn "eaclocal: '${x}' does not exist";
1011                    aclocal_opts="${aclocal_opts} -I ${x}"
1012                ;;
1013            esac;
1014        done;
1015    fi;
1016    [[ ! -f aclocal.m4 || -n $(grep -e 'generated.*by aclocal' aclocal.m4) ]] && autotools_run_tool aclocal "$@" ${aclocal_opts}
1017}
1018eautoconf ()
1019{
1020    if [[ ! -f configure.ac && ! -f configure.in ]]; then
1021        echo;
1022        eerror "No configure.{ac,in} present in '${PWD}'!";
1023        echo;
1024        die "No configure.{ac,in} present!";
1025    fi;
1026    autotools_run_tool autoconf "$@"
1027}
1028eautoheader ()
1029{
1030    [[ -n $(autotools_check_macro "AC_CONFIG_HEADERS") ]] || return 0;
1031    NO_FAIL=1 autotools_run_tool autoheader "$@"
1032}
1033eautomake ()
1034{
1035    local extra_opts;
1036    local makefile_name;
1037    if [[ -f GNUmakefile.am ]]; then
1038        makefile_name="GNUmakefile";
1039    else
1040        if [[ -f Makefile.am ]]; then
1041            makefile_name="Makefile";
1042        else
1043            return 0;
1044        fi;
1045    fi;
1046    if [[ -z ${FROM_EAUTORECONF} && -f ${makefile_name}.in ]]; then
1047        local used_automake;
1048        local installed_automake;
1049        installed_automake=$(WANT_AUTOMAKE= automake --version | head -n 1 |                    sed -e 's:.*(GNU automake) ::');
1050        used_automake=$(head -n 1 < ${makefile_name}.in |                       sed -e 's:.*by automake \(.*\) from .*:\1:');
1051        if [[ ${installed_automake} != ${used_automake} ]]; then
1052            einfo "Automake used for the package (${used_automake}) differs from";
1053            einfo "the installed version (${installed_automake}).";
1054            eautoreconf;
1055            return 0;
1056        fi;
1057    fi;
1058    [[ -f INSTALL && -f AUTHORS && -f ChangeLog && -f NEWS ]] || extra_opts="${extra_opts} --foreign";
1059    autotools_run_tool automake --add-missing --copy ${extra_opts} "$@"
1060}
1061eautopoint ()
1062{
1063    autotools_run_tool autopoint "$@"
1064}
1065eautoreconf ()
1066{
1067    local x auxdir g;
1068    if [[ -z ${AT_NO_RECURSIVE} ]]; then
1069        for x in $(autotools_get_subdirs);
1070        do
1071            if [[ -d ${x} ]]; then
1072                pushd "${x}" > /dev/null;
1073                AT_NOELIBTOOLIZE="yes" eautoreconf;
1074                popd > /dev/null;
1075            fi;
1076        done;
1077    fi;
1078    auxdir=$(autotools_get_auxdir);
1079    einfo "Running eautoreconf in '${PWD}' ...";
1080    [[ -n ${auxdir} ]] && mkdir -p ${auxdir};
1081    eaclocal;
1082    [[ ${CHOST} == *-darwin* ]] && g=g;
1083    if ${LIBTOOLIZE:-${g}libtoolize} -n --install &>/dev/null; then
1084        _elibtoolize --copy --force --install;
1085    else
1086        _elibtoolize --copy --force;
1087    fi;
1088    eautoconf;
1089    eautoheader;
1090    FROM_EAUTORECONF="yes" eautomake ${AM_OPTS};
1091    [[ ${AT_NOELIBTOOLIZE} == "yes" ]] && return 0;
1092    S=${PWD} elibtoolize;
1093    return 0
1094}
1095ebeep ()
1096{
1097    local n;
1098    if [[ -z ${EBEEP_IGNORE} ]]; then
1099        for ((n=1 ; n <= ${1:-5} ; n++))
1100        do
1101            echo -ne "\a";
1102            sleep 0.1 &>/dev/null;
1103            sleep 0,1 &>/dev/null;
1104            echo -ne "\a";
1105            sleep 1;
1106        done;
1107    fi
1108}
1109ecvs_clean ()
1110{
1111    [[ -z $* ]] && set -- .;
1112    find "$@" -type d -name 'CVS' -prune -print0 | xargs -0 rm -rf;
1113    find "$@" -type f -name '.cvs*' -print0 | xargs -0 rm -rf
1114}
1115edos2unix ()
1116{
1117    echo "$@" | xargs sed -i 's/\r$//'
1118}
1119egetent ()
1120{
1121    case ${CHOST} in
1122        *-darwin[678])
1123            case "$2" in
1124                *[!0-9]*)
1125                    nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }"
1126                ;;
1127                *)
1128                    nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }"
1129                ;;
1130            esac
1131        ;;
1132        *-darwin*)
1133            local mytype=$1;
1134            [[ "passwd" == $mytype ]] && mytype="Users";
1135            [[ "group" == $mytype ]] && mytype="Groups";
1136            case "$2" in
1137                *[!0-9]*)
1138                    dscl . -read /$mytype/$2 2> /dev/null | grep RecordName
1139                ;;
1140                *)
1141                    local mykey="UniqueID";
1142                    [[ $mytype == "Groups" ]] && mykey="PrimaryGroupID";
1143                    dscl . -search /$mytype $mykey $2 2> /dev/null
1144                ;;
1145            esac
1146        ;;
1147        *-freebsd* | *-dragonfly*)
1148            local opts action="user";
1149            [[ $1 == "passwd" ]] || action="group";
1150            if [[ $2 == [[:digit:]]* ]]; then
1151                [[ ${action} == "user" ]] && opts="-u" || opts="-g";
1152            fi;
1153            pw show ${action} ${opts} "$2" -q
1154        ;;
1155        *-netbsd* | *-openbsd*)
1156            grep "$2:\*:" /etc/$1
1157        ;;
1158        *)
1159            type -p nscd &>/dev/null && nscd -i "$1";
1160            getent "$1" "$2"
1161        ;;
1162    esac
1163}
1164egethome ()
1165{
1166    ent=$(egetent passwd $1);
1167    case ${CHOST} in
1168        *-darwin* | *-freebsd* | *-dragonfly*)
1169            echo ${ent} | cut -d: -f9
1170        ;;
1171        *)
1172            echo ${ent} | cut -d: -f6
1173        ;;
1174    esac
1175}
1176egetshell ()
1177{
1178    ent=$(egetent passwd "$1");
1179    case ${CHOST} in
1180        *-darwin* | *-freebsd* | *-dragonfly*)
1181            echo ${ent} | cut -d: -f10
1182        ;;
1183        *)
1184            echo ${ent} cut -d: -f7
1185        ;;
1186    esac
1187}
1188elibtoolize ()
1189{
1190    local x=;
1191    local y=;
1192    local do_portage="no";
1193    local do_reversedeps="no";
1194    local do_only_patches="no";
1195    local do_uclibc="yes";
1196    local deptoremove=;
1197    local my_dirlist=;
1198    local elt_patches="install-sh ltmain portage relink max_cmd_len sed test tmp cross as-needed";
1199    local start_dir=${PWD};
1200    my_dirlist=$(ELT_find_ltmain_sh);
1201    for x in "$@";
1202    do
1203        case "${x}" in
1204            "--portage")
1205                do_portage="yes"
1206            ;;
1207            "--reverse-deps")
1208                do_reversedeps="yes";
1209                elt_patches="${elt_patches} fix-relink"
1210            ;;
1211            "--patch-only")
1212                do_only_patches="yes"
1213            ;;
1214            "^--remove-internal-dep="*)
1215                deptoremove=$(echo "${x}" | sed -e 's|--remove-internal-dep=||');
1216                [[ -n ${deptoremove} ]] && elt_patches="${elt_patches} rem-int-dep"
1217            ;;
1218            "--shallow")
1219                if [[ -f ${S}/ltmain.sh ]]; then
1220                    my_dirlist=${S};
1221                else
1222                    my_dirlist=;
1223                fi
1224            ;;
1225            "--no-uclibc")
1226                do_uclibc="no"
1227            ;;
1228            *)
1229                eerror "Invalid elibtoolize option: ${x}";
1230                die "elibtoolize called with ${x} ??"
1231            ;;
1232        esac;
1233    done;
1234    [[ ${do_uclibc} == "yes" ]] && elt_patches="${elt_patches} uclibc-conf uclibc-ltconf";
1235    case "${CHOST}" in
1236        *-aix*)
1237            elt_patches="${elt_patches} hardcode aixrtl"
1238        ;;
1239        *-darwin*)
1240            elt_patches="${elt_patches} darwin-ltconf darwin-ltmain darwin-conf"
1241        ;;
1242        *-freebsd*)
1243            elt_patches="${elt_patches} fbsd-conf fbsd-ltconf"
1244        ;;
1245        *-hpux*)
1246            elt_patches="${elt_patches} hpux-conf deplibs hc-flag-ld hardcode hardcode-relink relink-prog no-lc"
1247        ;;
1248        *-irix*)
1249            elt_patches="${elt_patches} irix-ltmain"
1250        ;;
1251        *-mint*)
1252            elt_patches="${elt_patches} mint-conf"
1253        ;;
1254    esac;
1255    for x in ${my_dirlist};
1256    do
1257        local tmp=$(echo "${x}" | sed -e "s|${WORKDIR}||");
1258        export ELT_APPLIED_PATCHES=;
1259        export ELT_LTMAIN_SH="${x}/ltmain.sh";
1260        [[ -f ${x}/.elibtoolized ]] && continue;
1261        cd ${x};
1262        einfo "Running elibtoolize in: $(echo "/${tmp}" | sed -e 's|//|/|g; s|^/||')";
1263        for y in ${elt_patches};
1264        do
1265            local ret=0;
1266            case "${y}" in
1267                "portage")
1268                    if [[ -z $(grep 'We do not want portage' "${x}/ltmain.sh") ]]; then
1269                        ELT_walk_patches "${x}/ltmain.sh" "${y}";
1270                        ret=$?;
1271                    fi
1272                ;;
1273                "rem-int-dep")
1274                    ELT_walk_patches "${x}/ltmain.sh" "${y}" "${deptoremove}";
1275                    ret=$?
1276                ;;
1277                "fix-relink")
1278                    if [[ -n $(grep 'inst_prefix_dir' "${x}/ltmain.sh") ]]; then
1279                        ELT_walk_patches "${x}/ltmain.sh" "${y}";
1280                        ret=$?;
1281                    fi
1282                ;;
1283                "max_cmd_len")
1284                    if [[ -n $(grep 'max_cmd_len' "${x}/ltmain.sh") ]]; then
1285                        ELT_walk_patches "${x}/ltmain.sh" "${y}";
1286                        ret=$?;
1287                    fi
1288                ;;
1289                "as-needed")
1290                    ELT_walk_patches "${x}/ltmain.sh" "${y}";
1291                    ret=$?
1292                ;;
1293                "uclibc-conf")
1294                    if [[ -e ${x}/configure && -n $(grep 'Transform linux' "${x}/configure") ]]; then
1295                        ELT_walk_patches "${x}/configure" "${y}";
1296                        ret=$?;
1297                    else
1298                        if [[ ! -e ${x}/configure && -e ${x}/../configure && -n $(grep 'Transform linux' "${x}/../configure") ]]; then
1299                            ELT_walk_patches "${x}/../configure" "${y}";
1300                            ret=$?;
1301                        fi;
1302                    fi
1303                ;;
1304                "uclibc-ltconf")
1305                    if [[ -s ${x}/ltconfig ]]; then
1306                        ELT_walk_patches "${x}/ltconfig" "${y}";
1307                        ret=$?;
1308                    fi
1309                ;;
1310                "fbsd-conf")
1311                    if [[ -e ${x}/configure && -n $(grep 'version_type=freebsd-' "${x}/configure") ]]; then
1312                        ELT_walk_patches "${x}/configure" "${y}";
1313                        ret=$?;
1314                    else
1315                        if [[ ! -e ${x}/configure && -e ${x}/../configure && -n $(grep 'version_type=freebsd-' "${x}/../configure") ]]; then
1316                            ELT_walk_patches "${x}/../configure" "${y}";
1317                            ret=$?;
1318                        fi;
1319                    fi
1320                ;;
1321                "fbsd-ltconf")
1322                    if [[ -s ${x}/ltconfig ]]; then
1323                        ELT_walk_patches "${x}/ltconfig" "${y}";
1324                        ret=$?;
1325                    fi
1326                ;;
1327                "darwin-conf")
1328                    if [[ -e ${x}/configure && -n $(grep '&& echo \.so ||' "${x}/configure") ]]; then
1329                        ELT_walk_patches "${x}/configure" "${y}";
1330                        ret=$?;
1331                    else
1332                        if [[ ! -e ${x}/configure && -e ${x}/../configure && -n $(grep '&& echo \.so ||' "${x}/../configure") ]]; then
1333                            ELT_walk_patches "${x}/../configure" "${y}";
1334                            ret=$?;
1335                        fi;
1336                    fi
1337                ;;
1338                "darwin-ltconf")
1339                    if [[ -s ${x}/ltconfig ]]; then
1340                        ELT_walk_patches "${x}/ltconfig" "${y}";
1341                        ret=$?;
1342                    fi
1343                ;;
1344                "darwin-ltmain")
1345                    if [[ -e ${x}/ltmain.sh && -z $(grep 'verstring="-compatibility_version' "${x}/ltmain.sh") ]]; then
1346                        ELT_walk_patches "${x}/ltmain.sh" "${y}";
1347                        ret=$?;
1348                    fi
1349                ;;
1350                "aixrtl" | "hpux-conf")
1351                    ret=1;
1352                    local subret=0;
1353                    while [[ $subret -eq 0 ]]; do
1354                        subret=1;
1355                        if [[ -e ${x}/configure ]]; then
1356                            ELT_walk_patches "${x}/configure" "${y}";
1357                            subret=$?;
1358                        else
1359                            if [[ ! -e ${x}/configure && -e ${x}/../configure ]]; then
1360                                ELT_walk_patches "${x}/../configure" "${y}";
1361                                subret=$?;
1362                            fi;
1363                        fi;
1364                        if [[ $subret -eq 0 ]]; then
1365                            ret=0;
1366                        fi;
1367                    done
1368                ;;
1369                "mint-conf")
1370                    ret=1;
1371                    local subret=1;
1372                    if [[ -e ${x}/configure ]]; then
1373                        ELT_walk_patches "${x}/configure" "${y}";
1374                        subret=$?;
1375                    else
1376                        if [[ ! -e ${x}/configure && -e ${x}/../configure ]]; then
1377                            ELT_walk_patches "${x}/../configure" "${y}";
1378                            subret=$?;
1379                        fi;
1380                    fi;
1381                    if [[ $subret -eq 0 ]]; then
1382                        ret=0;
1383                    fi
1384                ;;
1385                "install-sh")
1386                    ELT_walk_patches "${x}/install-sh" "${y}";
1387                    ret=$?
1388                ;;
1389                "cross")
1390                    if tc-is-cross-compiler; then
1391                        ELT_walk_patches "${x}/ltmain.sh" "${y}";
1392                        ret=$?;
1393                    fi
1394                ;;
1395                *)
1396                    ELT_walk_patches "${x}/ltmain.sh" "${y}";
1397                    ret=$?
1398                ;;
1399            esac;
1400            if [[ ${ret} -ne 0 ]]; then
1401                case ${y} in
1402                    "relink")
1403                        local version=$(ELT_libtool_version "${x}/ltmain.sh");
1404                        if [[ -z $(grep 'inst_prefix_dir' "${x}/ltmain.sh") && $(VER_to_int "${version}") -ge $(VER_to_int "1.4.0") ]]; then
1405                            ewarn "  Could not apply relink.patch!";
1406                        fi
1407                    ;;
1408                    "portage")
1409                        if [[ ${do_portage} == "yes" ]]; then
1410                            if [[ -z $(grep 'We do not want portage' "${x}/ltmain.sh") ]]; then
1411                                echo;
1412                                eerror "Portage patch requested, but failed to apply!";
1413                                eerror "Please file a bug report to add a proper patch.";
1414                                die "Portage patch requested, but failed to apply!";
1415                            fi;
1416                        else
1417                            if [[ -n $(grep 'We do not want portage' "${x}/ltmain.sh") ]]; then
1418                                :;
1419                            else
1420                                local version=$(                                                                        eval $(grep -e '^[[:space:]]*VERSION=' "${x}/ltmain.sh");                                                                       echo "${VERSION}");
1421                                echo;
1422                                eerror "Portage patch failed to apply (ltmain.sh version ${version})!";
1423                                eerror "Please file a bug report to add a proper patch.";
1424                                die "Portage patch failed to apply!";
1425                            fi;
1426                            ELT_APPLIED_PATCHES="portage";
1427                        fi
1428                    ;;
1429                    "uclibc-"*)
1430                        [[ ${CHOST} == *"-uclibc" ]] && ewarn "  uClibc patch set '${y}' failed to apply!"
1431                    ;;
1432                    "fbsd-"*)
1433                        if [[ ${CHOST} == *"-freebsd"* ]]; then
1434                            if [[ -z $(grep 'Handle Gentoo/FreeBSD as it was Linux'                                                             "${x}/configure" "${x}/../configure" 2>/dev/null) ]]; then
1435                                eerror "  FreeBSD patch set '${y}' failed to apply!";
1436                                die "FreeBSD patch set '${y}' failed to apply!";
1437                            fi;
1438                        fi
1439                    ;;
1440                    "darwin-"*)
1441                        [[ ${CHOST} == *"-darwin"* ]] && ewarn "  Darwin patch set '${y}' failed to apply!"
1442                    ;;
1443                esac;
1444            fi;
1445        done;
1446        if [[ -z ${ELT_APPLIED_PATCHES} ]]; then
1447            if [[ ${do_portage} == "no" && ${do_reversedeps} == "no" && ${do_only_patches} == "no" && ${deptoremove} == "" ]]; then
1448                ewarn "Cannot apply any patches, please file a bug about this";
1449                die;
1450            fi;
1451        fi;
1452        [[ -f ${x}/libtool ]] && rm -f "${x}/libtool";
1453         >> "${x}/.elibtoolized";
1454    done;
1455    cd "${start_dir}"
1456}
1457emktemp ()
1458{
1459    local exe="touch";
1460    [[ $1 == -d ]] && exe="mkdir" && shift;
1461    local topdir=$1;
1462    if [[ -z ${topdir} ]]; then
1463        [[ -z ${T} ]] && topdir="/tmp" || topdir=${T};
1464    fi;
1465    if ! type -P mktemp > /dev/null; then
1466        local tmp=/;
1467        while [[ -e ${tmp} ]]; do
1468            tmp=${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM};
1469        done;
1470        ${exe} "${tmp}" || ${exe} -p "${tmp}";
1471        echo "${tmp}";
1472    else
1473        if [[ ${exe} == "touch" ]]; then
1474            TMPDIR="${topdir}" mktemp -t tmp.XXXXXXXXXX;
1475        else
1476            TMPDIR="${topdir}" mktemp -dt tmp.XXXXXXXXXX;
1477        fi;
1478    fi
1479}
1480enewgroup ()
1481{
1482    case ${EBUILD_PHASE} in
1483        unpack | compile | test | install)
1484            eerror "'enewgroup()' called from '${EBUILD_PHASE}()' which is not a pkg_* function.";
1485            eerror "Package fails at QA and at life.  Please file a bug.";
1486            die "Bad package!  enewgroup is only for use in pkg_* functions!"
1487        ;;
1488    esac;
1489    local egroup="$1";
1490    shift;
1491    if [ -z "${egroup}" ]; then
1492        eerror "No group specified !";
1493        die "Cannot call enewgroup without a group";
1494    fi;
1495    if [[ -n $(egetent group "${egroup}") ]]; then
1496        return 0;
1497    fi;
1498    einfo "Adding group '${egroup}' to your system ...";
1499    local opts=;
1500    local egid="$1";
1501    shift;
1502    if [ ! -z "${egid}" ]; then
1503        if [ "${egid}" -gt 0 ]; then
1504            if [ -z "`egetent group ${egid}`" ]; then
1505                if [[ "${CHOST}" == *-darwin* ]]; then
1506                    opts="${opts} ${egid}";
1507                else
1508                    opts="${opts} -g ${egid}";
1509                fi;
1510            else
1511                egid="next available; requested gid taken";
1512            fi;
1513        else
1514            eerror "Groupid given but is not greater than 0 !";
1515            die "${egid} is not a valid GID";
1516        fi;
1517    else
1518        egid="next available";
1519    fi;
1520    einfo " - Groupid: ${egid}";
1521    local eextra="$@";
1522    opts="${opts} ${eextra}";
1523    local oldsandbox="${SANDBOX_ON}";
1524    export SANDBOX_ON="0";
1525    case ${CHOST} in
1526        *-darwin*)
1527            if [ ! -z "${eextra}" ]; then
1528                einfo "Extra options are not supported on Darwin/OS X yet";
1529                einfo "Please report the ebuild along with the info below";
1530                einfo "eextra: ${eextra}";
1531                die "Required function missing";
1532            fi;
1533            case ${egid} in
1534                *[!0-9]*)
1535                    for ((egid = 101; egid <= 999; egid++))
1536                    do
1537                        [[ -z $(egetent group ${egid}) ]] && break;
1538                    done
1539                ;;
1540            esac;
1541            dscl . create /groups/${egroup} gid ${egid};
1542            dscl . create /groups/${egroup} passwd '*'
1543        ;;
1544        *-freebsd* | *-dragonfly*)
1545            case ${egid} in
1546                *[!0-9]*)
1547                    for ((egid = 101; egid <= 999; egid++))
1548                    do
1549                        [[ -z $(egetent group ${egid}) ]] && break;
1550                    done
1551                ;;
1552            esac;
1553            pw groupadd ${egroup} -g ${egid} || die "enewgroup failed"
1554        ;;
1555        *-netbsd*)
1556            case ${egid} in
1557                *[!0-9]*)
1558                    for ((egid = 101; egid <= 999; egid++))
1559                    do
1560                        [[ -z $(egetent group ${egid}) ]] && break;
1561                    done
1562                ;;
1563            esac;
1564            groupadd -g ${egid} ${egroup} || die "enewgroup failed"
1565        ;;
1566        *)
1567            groupadd ${opts} ${egroup} || die "enewgroup failed"
1568        ;;
1569    esac;
1570    export SANDBOX_ON="${oldsandbox}"
1571}
1572enewuser ()
1573{
1574    case ${EBUILD_PHASE} in
1575        unpack | compile | test | install)
1576            eerror "'enewuser()' called from '${EBUILD_PHASE}()' which is not a pkg_* function.";
1577            eerror "Package fails at QA and at life.  Please file a bug.";
1578            die "Bad package!  enewuser is only for use in pkg_* functions!"
1579        ;;
1580    esac;
1581    local euser=$1;
1582    shift;
1583    if [[ -z ${euser} ]]; then
1584        eerror "No username specified !";
1585        die "Cannot call enewuser without a username";
1586    fi;
1587    if [[ -n $(egetent passwd "${euser}") ]]; then
1588        return 0;
1589    fi;
1590    einfo "Adding user '${euser}' to your system ...";
1591    local opts=;
1592    local euid=$1;
1593    shift;
1594    if [[ -n ${euid} && ${euid} != -1 ]]; then
1595        if [[ ${euid} -gt 0 ]]; then
1596            if [[ -n $(egetent passwd ${euid}) ]]; then
1597                euid="next";
1598            fi;
1599        else
1600            eerror "Userid given but is not greater than 0 !";
1601            die "${euid} is not a valid UID";
1602        fi;
1603    else
1604        euid="next";
1605    fi;
1606    if [[ ${euid} == "next" ]]; then
1607        for ((euid = 101; euid <= 999; euid++))
1608        do
1609            [[ -z $(egetent passwd ${euid}) ]] && break;
1610        done;
1611    fi;
1612    opts="${opts} -u ${euid}";
1613    einfo " - Userid: ${euid}";
1614    local eshell=$1;
1615    shift;
1616    if [[ ! -z ${eshell} ]] && [[ ${eshell} != "-1" ]]; then
1617        if [[ ! -e ${ROOT}${eshell} ]]; then
1618            eerror "A shell was specified but it does not exist !";
1619            die "${eshell} does not exist in ${ROOT}";
1620        fi;
1621        if [[ ${eshell} == */false || ${eshell} == */nologin ]]; then
1622            eerror "Do not specify ${eshell} yourself, use -1";
1623            die "Pass '-1' as the shell parameter";
1624        fi;
1625    else
1626        for shell in /sbin/nologin /usr/sbin/nologin /bin/false /usr/bin/false /dev/null;
1627        do
1628            [[ -x ${ROOT}${shell} ]] && break;
1629        done;
1630        if [[ ${shell} == "/dev/null" ]]; then
1631            eerror "Unable to identify the shell to use, proceeding with userland default.";
1632            case ${USERLAND} in
1633                GNU)
1634                    shell="/bin/false"
1635                ;;
1636                BSD)
1637                    shell="/sbin/nologin"
1638                ;;
1639                Darwin)
1640                    shell="/usr/sbin/nologin"
1641                ;;
1642                *)
1643                    die "Unable to identify the default shell for userland ${USERLAND}"
1644                ;;
1645            esac;
1646        fi;
1647        eshell=${shell};
1648    fi;
1649    einfo " - Shell: ${eshell}";
1650    opts="${opts} -s ${eshell}";
1651    local ehome=$1;
1652    shift;
1653    if [[ -z ${ehome} ]] || [[ ${ehome} == "-1" ]]; then
1654        ehome="/dev/null";
1655    fi;
1656    einfo " - Home: ${ehome}";
1657    opts="${opts} -d ${ehome}";
1658    local egroups=$1;
1659    shift;
1660    if [[ ! -z ${egroups} ]]; then
1661        local oldifs=${IFS};
1662        local defgroup="" exgroups="";
1663        export IFS=",";
1664        for g in ${egroups};
1665        do
1666            export IFS=${oldifs};
1667            if [[ -z $(egetent group "${g}") ]]; then
1668                eerror "You must add group ${g} to the system first";
1669                die "${g} is not a valid GID";
1670            fi;
1671            if [[ -z ${defgroup} ]]; then
1672                defgroup=${g};
1673            else
1674                exgroups="${exgroups},${g}";
1675            fi;
1676            export IFS=",";
1677        done;
1678        export IFS=${oldifs};
1679        opts="${opts} -g ${defgroup}";
1680        if [[ ! -z ${exgroups} ]]; then
1681            opts="${opts} -G ${exgroups:1}";
1682        fi;
1683    else
1684        egroups="(none)";
1685    fi;
1686    einfo " - Groups: ${egroups}";
1687    local oldsandbox=${SANDBOX_ON};
1688    export SANDBOX_ON="0";
1689    case ${CHOST} in
1690        *-darwin*)
1691            if [[ -z $@ ]]; then
1692                dscl . create /users/${euser} uid ${euid};
1693                dscl . create /users/${euser} shell ${eshell};
1694                dscl . create /users/${euser} home ${ehome};
1695                dscl . create /users/${euser} realname "added by portage for ${PN}";
1696                local oldifs=${IFS};
1697                export IFS=",";
1698                for g in ${egroups};
1699                do
1700                    dscl . merge /groups/${g} users ${euser};
1701                done;
1702                export IFS=${oldifs};
1703            else
1704                einfo "Extra options are not supported on Darwin yet";
1705                einfo "Please report the ebuild along with the info below";
1706                einfo "eextra: $@";
1707                die "Required function missing";
1708            fi
1709        ;;
1710        *-freebsd* | *-dragonfly*)
1711            if [[ -z $@ ]]; then
1712                pw useradd ${euser} ${opts} -c "added by portage for ${PN}" die "enewuser failed";
1713            else
1714                einfo " - Extra: $@";
1715                pw useradd ${euser} ${opts} "$@" || die "enewuser failed";
1716            fi
1717        ;;
1718        *-netbsd*)
1719            if [[ -z $@ ]]; then
1720                useradd ${opts} ${euser} || die "enewuser failed";
1721            else
1722                einfo " - Extra: $@";
1723                useradd ${opts} ${euser} "$@" || die "enewuser failed";
1724            fi
1725        ;;
1726        *-openbsd*)
1727            if [[ -z $@ ]]; then
1728                useradd -u ${euid} -s ${eshell} -d ${ehome} -c "Added by portage for ${PN}" -g ${egroups} ${euser} || die "enewuser failed";
1729            else
1730                einfo " - Extra: $@";
1731                useradd -u ${euid} -s ${eshell} -d ${ehome} -c "Added by portage for ${PN}" -g ${egroups} ${euser} "$@" || die "enewuser failed";
1732            fi
1733        ;;
1734        *)
1735            if [[ -z $@ ]]; then
1736                useradd ${opts} -c "added by portage for ${PN}" ${euser} || die "enewuser failed";
1737            else
1738                einfo " - Extra: $@";
1739                useradd ${opts} "$@" ${euser} || die "enewuser failed";
1740            fi
1741        ;;
1742    esac;
1743    if [[ ! -e ${ROOT}/${ehome} ]]; then
1744        einfo " - Creating ${ehome} in ${ROOT}";
1745        mkdir -p "${ROOT}/${ehome}";
1746        chown ${euser} "${ROOT}/${ehome}";
1747        chmod 755 "${ROOT}/${ehome}";
1748    fi;
1749    export SANDBOX_ON=${oldsandbox}
1750}
1751epatch ()
1752{
1753    function _epatch_draw_line ()
1754    {
1755        [[ -z $1 ]] && set "$(printf "%65s" '')";
1756        echo "${1//?/=}"
1757    };
1758    unset P4CONFIG P4PORT P4USER;
1759    if [[ $# -gt 1 ]]; then
1760        local m;
1761        for m in "$@";
1762        do
1763            epatch "${m}";
1764        done;
1765        return 0;
1766    fi;
1767    local SINGLE_PATCH="no";
1768    [[ $# -eq 0 ]] && set -- "${EPATCH_SOURCE}";
1769    if [[ -f $1 ]]; then
1770        SINGLE_PATCH="yes";
1771        set -- "$1";
1772        local EPATCH_SUFFIX=$1;
1773    else
1774        if [[ -d $1 ]]; then
1775            set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"};
1776        else
1777            [[ $# -ne 0 ]] && EPATCH_SOURCE=$1;
1778            echo;
1779            eerror "Cannot find \$EPATCH_SOURCE!  Value for \$EPATCH_SOURCE is:";
1780            eerror;
1781            eerror "  ${EPATCH_SOURCE}";
1782            eerror "  ( ${EPATCH_SOURCE##*/} )";
1783            echo;
1784            die "Cannot find \$EPATCH_SOURCE!";
1785        fi;
1786    fi;
1787    local PIPE_CMD;
1788    case ${EPATCH_SUFFIX##*\.} in
1789        xz)
1790            PIPE_CMD="xz -dc"
1791        ;;
1792        lzma)
1793            PIPE_CMD="lzma -dc"
1794        ;;
1795        bz2)
1796            PIPE_CMD="bzip2 -dc"
1797        ;;
1798        gz | Z | z)
1799            PIPE_CMD="gzip -dc"
1800        ;;
1801        ZIP | zip)
1802            PIPE_CMD="unzip -p"
1803        ;;
1804        *)
1805
1806        ;;
1807    esac;
1808    [[ ${SINGLE_PATCH} == "no" ]] && einfo "${EPATCH_MULTI_MSG}";
1809    local x;
1810    for x in "$@";
1811    do
1812        [[ ! -f ${x} ]] && continue;
1813        local patchname=${x##*/};
1814        local a=${patchname#*_};
1815        a=${a%%_*};
1816        if ! [[ ${SINGLE_PATCH} == "yes" || ${EPATCH_FORCE} == "yes" || ${a} == all || ${a} == ${ARCH} ]]; then
1817            continue;
1818        fi;
1819        if [[ -n ${EPATCH_EXCLUDE} ]]; then
1820            eshopts_push -o noglob;
1821            local ex;
1822            for ex in ${EPATCH_EXCLUDE};
1823            do
1824                if [[ ${patchname} == ${ex} ]]; then
1825                    eshopts_pop;
1826                    continue 2;
1827                fi;
1828            done;
1829            eshopts_pop;
1830        fi;
1831        if [[ ${SINGLE_PATCH} == "yes" ]]; then
1832            if [[ -n ${EPATCH_SINGLE_MSG} ]]; then
1833                einfo "${EPATCH_SINGLE_MSG}";
1834            else
1835                einfo "Applying ${patchname} ...";
1836            fi;
1837        else
1838            einfo "  ${patchname} ...";
1839        fi;
1840        local STDERR_TARGET="${T}/${patchname}.out";
1841        if [[ -e ${STDERR_TARGET} ]]; then
1842            STDERR_TARGET="${T}/${patchname}-$$.out";
1843        fi;
1844        printf "***** %s *****\n\n" "${patchname}" > "${STDERR_TARGET}";
1845        local count=0;
1846        local PATCH_TARGET;
1847        if [[ -n ${PIPE_CMD} ]]; then
1848            PATCH_TARGET="${T}/$$.patch";
1849            echo "PIPE_COMMAND:  ${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> "${STDERR_TARGET}";
1850            if ! ( ${PIPE_CMD} "${x}" > "${PATCH_TARGET}" ) >> "${STDERR_TARGET}" 2>&1; then
1851                echo;
1852                eerror "Could not extract patch!";
1853                count=5;
1854                break;
1855            fi;
1856        else
1857            PATCH_TARGET=${x};
1858        fi;
1859        local abs_paths=$(egrep -n '^[-+]{3} /' "${PATCH_TARGET}" | awk '$2 != "/dev/null" { print }');
1860        if [[ -n ${abs_paths} ]]; then
1861            count=1;
1862            printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}";
1863        fi;
1864        while [[ ${count} -lt 5 ]]; do
1865            ( _epatch_draw_line "***** ${patchname} *****";
1866            echo;
1867            echo "PATCH COMMAND:  patch -p${count} ${EPATCH_OPTS} < '${PATCH_TARGET}'";
1868            echo;
1869            _epatch_draw_line "***** ${patchname} *****" ) >> "${STDERR_TARGET}";
1870            if ( patch -p${count} ${EPATCH_OPTS} --dry-run -f < "${PATCH_TARGET}" ) >> "${STDERR_TARGET}" 2>&1; then
1871                ( _epatch_draw_line "***** ${patchname} *****";
1872                echo;
1873                echo "ACTUALLY APPLYING ${patchname} ...";
1874                echo;
1875                _epatch_draw_line "***** ${patchname} *****";
1876                patch -p${count} ${EPATCH_OPTS} < "${PATCH_TARGET}" 2>&1 ) >> "${STDERR_TARGET}";
1877                if [ $? -ne 0 ]; then
1878                    echo;
1879                    eerror "A dry-run of patch command succeeded, but actually";
1880                    eerror "applying the patch failed!";
1881                    count=5;
1882                fi;
1883                break;
1884            fi;
1885            : $(( count++ ));
1886        done;
1887        if [[ -n ${PIPE_CMD} ]]; then
1888            rm -f "${PATCH_TARGET}";
1889        fi;
1890        if [[ ${count} -ge 5 ]]; then
1891            echo;
1892            eerror "Failed Patch: ${patchname} !";
1893            eerror " ( ${PATCH_TARGET} )";
1894            eerror;
1895            eerror "Include in your bugreport the contents of:";
1896            eerror;
1897            eerror "  ${STDERR_TARGET}";
1898            echo;
1899            die "Failed Patch: ${patchname}!";
1900        fi;
1901        rm -f "${STDERR_TARGET}";
1902        eend 0;
1903    done;
1904    [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching";
1905    :
1906}
1907epatch_user ()
1908{
1909    [[ $# -ne 0 ]] && die "epatch_user takes no options";
1910    local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches;
1911    for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}};
1912    do
1913        EPATCH_SOURCE=${base}/${CTARGET}/${check};
1914        [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check};
1915        [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check};
1916        if [[ -d ${EPATCH_SOURCE} ]]; then
1917            EPATCH_SOURCE=${EPATCH_SOURCE} EPATCH_SUFFIX="patch" EPATCH_FORCE="yes" EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." epatch;
1918            break;
1919        fi;
1920    done
1921}
1922epause ()
1923{
1924    [[ -z ${EPAUSE_IGNORE} ]] && sleep ${1:-5}
1925}
1926epunt_cxx ()
1927{
1928    local dir=$1;
1929    [[ -z ${dir} ]] && dir=${S};
1930    ebegin "Removing useless C++ checks";
1931    local f;
1932    find "${dir}" -name configure | while read f; do
1933        patch --no-backup-if-mismatch -p0 "${f}" "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null;
1934    done;
1935    eend 0
1936}
1937eshopts_pop ()
1938{
1939    [[ $# -ne 0 ]] && die "eshopts_pop takes no arguments";
1940    local i=$(( ${#__ESHOPTS_SAVE__[@]} - 1 ));
1941    [[ ${i} -eq -1 ]] && die "eshopts_{push,pop}: unbalanced pair";
1942    local s=${__ESHOPTS_SAVE__[$i]};
1943    unset __ESHOPTS_SAVE__[$i];
1944    if [[ ${s} == "shopt -"* ]]; then
1945        eval "${s}" || die "eshopts_pop: sanity: invalid shopt options: ${s}";
1946    else
1947        set +$- || die "eshopts_pop: sanity: invalid shell settings: $-";
1948        set -${s} || die "eshopts_pop: sanity: unable to restore saved shell settings: ${s}";
1949    fi
1950}
1951eshopts_push ()
1952{
1953    local i=${#__ESHOPTS_SAVE__[@]};
1954    if [[ $1 == -[su] ]]; then
1955        __ESHOPTS_SAVE__[$i]=$(shopt -p);
1956        [[ $# -eq 0 ]] && return 0;
1957        shopt "$@" || die "eshopts_push: bad options to shopt: $*";
1958    else
1959        __ESHOPTS_SAVE__[$i]=$-;
1960        [[ $# -eq 0 ]] && return 0;
1961        set "$@" || die "eshopts_push: bad options to set: $*";
1962    fi
1963}
1964esvn_clean ()
1965{
1966    [[ -z $* ]] && set -- .;
1967    find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf
1968}
1969filter-flags ()
1970{
1971    _filter-hardened "$@";
1972    _filter-var CFLAGS "$@";
1973    _filter-var CPPFLAGS "$@";
1974    _filter-var CXXFLAGS "$@";
1975    _filter-var FFLAGS "$@";
1976    _filter-var FCFLAGS "$@";
1977    return 0
1978}
1979filter-ldflags ()
1980{
1981    _filter-var LDFLAGS "$@";
1982    return 0
1983}
1984filter-lfs-flags ()
1985{
1986    [[ -n $@ ]] && die "filter-lfs-flags takes no arguments";
1987    filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
1988}
1989filter-mfpmath ()
1990{
1991    local orig_mfpmath new_math prune_math;
1992    orig_mfpmath=$(get-flag -mfpmath);
1993    new_math=$(get-flag mfpmath);
1994    new_math=" ${new_math//,/ } ";
1995    prune_math="";
1996    for prune_math in "$@";
1997    do
1998        new_math=${new_math/ ${prune_math} / };
1999    done;
2000    new_math=$(echo ${new_math});
2001    new_math=${new_math// /,};
2002    if [[ -z ${new_math} ]]; then
2003        filter-flags ${orig_mfpmath};
2004    else
2005        replace-flags ${orig_mfpmath} -mfpmath=${new_math};
2006    fi;
2007    return 0
2008}
2009find_unpackable_file ()
2010{
2011    local src=$1;
2012    if [[ -z ${src} ]]; then
2013        src=${DISTDIR}/${A};
2014    else
2015        if [[ -e ${DISTDIR}/${src} ]]; then
2016            src=${DISTDIR}/${src};
2017        else
2018            if [[ -e ${PWD}/${src} ]]; then
2019                src=${PWD}/${src};
2020            else
2021                if [[ -e ${src} ]]; then
2022                    src=${src};
2023                fi;
2024            fi;
2025        fi;
2026    fi;
2027    [[ ! -e ${src} ]] && return 1;
2028    echo "${src}"
2029}
2030gcc-fullversion ()
2031{
2032    $(tc-getCC "$@") -dumpversion
2033}
2034gcc-major-version ()
2035{
2036    gcc-version "$@" | cut -f1 -d.
2037}
2038gcc-micro-version ()
2039{
2040    gcc-fullversion "$@" | cut -f3 -d. | cut -f1 -d-
2041}
2042gcc-minor-version ()
2043{
2044    gcc-version "$@" | cut -f2 -d.
2045}
2046gcc-specs-directive ()
2047{
2048    local directive subdname subdirective;
2049    directive="$(_gcc-specs-directive_raw $1)";
2050    while [[ ${directive} == *%\(*\)* ]]; do
2051        subdname=${directive/*%\(};
2052        subdname=${subdname/\)*};
2053        subdirective="$(_gcc-specs-directive_raw ${subdname})";
2054        directive="${directive//\%(${subdname})/${subdirective}}";
2055    done;
2056    echo "${directive}";
2057    return 0
2058}
2059gcc-specs-nostrict ()
2060{
2061    local directive;
2062    directive=$(gcc-specs-directive cc1);
2063    return $([[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]])
2064}
2065gcc-specs-now ()
2066{
2067    local directive;
2068    directive=$(gcc-specs-directive link_command);
2069    return $([[ "${directive/\{!nonow:}" != "${directive}" ]])
2070}
2071gcc-specs-pie ()
2072{
2073    local directive;
2074    directive=$(gcc-specs-directive cc1);
2075    return $([[ "${directive/\{!nopie:}" != "${directive}" ]])
2076}
2077gcc-specs-relro ()
2078{
2079    local directive;
2080    directive=$(gcc-specs-directive link_command);
2081    return $([[ "${directive/\{!norelro:}" != "${directive}" ]])
2082}
2083gcc-specs-ssp ()
2084{
2085    local directive;
2086    directive=$(gcc-specs-directive cc1);
2087    return $([[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]])
2088}
2089gcc-specs-ssp-to-all ()
2090{
2091    local directive;
2092    directive=$(gcc-specs-directive cc1);
2093    return $([[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]])
2094}
2095gcc-version ()
2096{
2097    gcc-fullversion "$@" | cut -f1,2 -d.
2098}
2099gen_usr_ldscript ()
2100{
2101    local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname);
2102    [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/;
2103    tc-is-static-only && return;
2104    dodir /usr/${libdir};
2105    if [[ $1 == "-a" ]]; then
2106        auto=true;
2107        shift;
2108        dodir /${libdir};
2109    fi;
2110    output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p');
2111    [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )";
2112    for lib in "$@";
2113    do
2114        local tlib;
2115        if ${auto}; then
2116            lib="lib${lib}${suffix}";
2117        else
2118            [[ -r ${ED}/${libdir}/${lib} ]] || continue;
2119        fi;
2120        case ${CTARGET:-${CHOST}} in
2121            *-darwin*)
2122                if ${auto}; then
2123                    tlib=$(scanmacho -qF'%S#F' "${ED}"/usr/${libdir}/${lib});
2124                else
2125                    tlib=$(scanmacho -qF'%S#F' "${ED}"/${libdir}/${lib});
2126                fi;
2127                [[ -z ${tlib} ]] && die "unable to read install_name from ${lib}";
2128                tlib=${tlib##*/};
2129                if ${auto}; then
2130                    mv "${ED}"/usr/${libdir}/${lib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die;
2131                    if [[ ${tlib} != ${lib%${suffix}}.*${suffix#.} ]]; then
2132                        mv "${ED}"/usr/${libdir}/${tlib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die;
2133                    fi;
2134                    rm -f "${ED}"/${libdir}/${lib};
2135                fi;
2136                if [[ ! -w "${ED}/${libdir}/${tlib}" ]]; then
2137                    chmod u+w "${ED}${libdir}/${tlib}";
2138                    local nowrite=yes;
2139                fi;
2140                install_name_tool -id "${EPREFIX}"/${libdir}/${tlib} "${ED}"/${libdir}/${tlib} || die "install_name_tool failed";
2141                [[ -n ${nowrite} ]] && chmod u-w "${ED}${libdir}/${tlib}";
2142                pushd "${ED}/usr/${libdir}" > /dev/null;
2143                ln -snf "../../${libdir}/${tlib}" "${lib}";
2144                popd > /dev/null
2145            ;;
2146            *-aix* | *-irix* | *64*-hpux* | *-interix* | *-winnt*)
2147                if ${auto}; then
2148                    mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die;
2149                    tlib=$(readlink "${ED}"/${libdir}/${lib});
2150                    tlib=${tlib##*/};
2151                    if [[ -z ${tlib} ]]; then
2152                        tlib=${lib};
2153                    else
2154                        rm -f "${ED}"/${libdir}/${lib};
2155                    fi;
2156                else
2157                    tlib=${lib};
2158                fi;
2159                pushd "${ED}/usr/${libdir}" > /dev/null;
2160                ln -snf "../../${libdir}/${tlib}" "${lib}";
2161                popd > /dev/null
2162            ;;
2163            hppa*-hpux*)
2164                if ${auto}; then
2165                    tlib=$(chatr "${ED}"/usr/${libdir}/${lib} | sed -n '/internal name:/{n;s/^ *//;p;q}');
2166                    [[ -z ${tlib} ]] && tlib=${lib};
2167                    tlib=${tlib##*/};
2168                    mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die;
2169                    if [[ ${tlib} != ${lib}* ]]; then
2170                        mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die;
2171                    fi;
2172                    [[ ${tlib} != ${lib} ]] && rm -f "${ED}"/${libdir}/${lib};
2173                else
2174                    tlib=$(chatr "${ED}"/${libdir}/${lib} | sed -n '/internal name:/{n;s/^ *//;p;q}');
2175                    [[ -z ${tlib} ]] && tlib=${lib};
2176                    tlib=${tlib##*/};
2177                fi;
2178                pushd "${ED}"/usr/${libdir} > /dev/null;
2179                ln -snf "../../${libdir}/${tlib}" "${lib}";
2180                [[ ${tlib} != ${lib} ]] && ln -snf "../../${libdir}/${tlib}" "${tlib}";
2181                popd > /dev/null
2182            ;;
2183            *)
2184                if ${auto}; then
2185                    tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib});
2186                    [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}";
2187                    mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die;
2188                    if [[ ${tlib} != ${lib}* ]]; then
2189                        mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die;
2190                    fi;
2191                    rm -f "${ED}"/${libdir}/${lib};
2192                else
2193                    tlib=${lib};
2194                fi;
2195                cat > "${ED}/usr/${libdir}/${lib}"  <<-END_LDSCRIPT
2196/* GNU ld script
2197   Since Gentoo has critical dynamic libraries in /lib, and the static versions
2198   in /usr/lib, we need to have a "fake" dynamic lib in /usr/lib, otherwise we
2199   run into linking problems.  This "fake" dynamic lib is a linker script that
2200   redirects the linker to the real lib.  And yes, this works in the cross-
2201   compiling scenario as the sysroot-ed linker will prepend the real path.
2202
2203   See bug http://bugs.gentoo.org/4411 for more info.
2204 */
2205${output_format}
2206GROUP ( ${EPREFIX}/${libdir}/${tlib} )
2207END_LDSCRIPT
2208
2209            ;;
2210        esac
2211        fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}";
2212    done
2213}
2214get-flag ()
2215{
2216    local f findflag="$1";
2217    for f in ${CFLAGS} ${CXXFLAGS} ${FFLAGS} ${FCFLAGS};
2218    do
2219        if [ "${f/${findflag}}" != "${f}" ]; then
2220            printf "%s\n" "${f/-${findflag}=}";
2221            return 0;
2222        fi;
2223    done;
2224    return 1
2225}
2226get_abi_ASFLAGS ()
2227{
2228    get_abi_var ASFLAGS "$@"
2229}
2230get_abi_CDEFINE ()
2231{
2232    get_abi_var CDEFINE "$@"
2233}
2234get_abi_CFLAGS ()
2235{
2236    get_abi_var CFLAGS "$@"
2237}
2238get_abi_CHOST ()
2239{
2240    get_abi_var CHOST "$@"
2241}
2242get_abi_CTARGET ()
2243{
2244    get_abi_var CTARGET "$@"
2245}
2246get_abi_FAKE_TARGETS ()
2247{
2248    get_abi_var FAKE_TARGETS "$@"
2249}
2250get_abi_LDFLAGS ()
2251{
2252    get_abi_var LDFLAGS "$@"
2253}
2254get_abi_LIBDIR ()
2255{
2256    get_abi_var LIBDIR "$@"
2257}
2258get_abi_var ()
2259{
2260    local flag=$1;
2261    local abi;
2262    if [ $# -gt 1 ]; then
2263        abi=${2};
2264    else
2265        if [ -n "${ABI}" ]; then
2266            abi=${ABI};
2267        else
2268            if [ -n "${DEFAULT_ABI}" ]; then
2269                abi=${DEFAULT_ABI};
2270            else
2271                abi="default";
2272            fi;
2273        fi;
2274    fi;
2275    local var="${flag}_${abi}";
2276    echo ${!var}
2277}
2278get_all_abis ()
2279{
2280    local order="";
2281    if [[ -z ${MULTILIB_ABIS} ]]; then
2282        echo "default";
2283        return 0;
2284    fi;
2285    for x in ${MULTILIB_ABIS};
2286    do
2287        if [[ ${x} != ${DEFAULT_ABI} ]]; then
2288            order="${order:+${order} }${x}";
2289        fi;
2290    done;
2291    order="${order:+${order} }${DEFAULT_ABI}";
2292    echo ${order};
2293    return 0
2294}
2295get_all_libdirs ()
2296{
2297    local libdirs="lib";
2298    local abi;
2299    local dir;
2300    for abi in ${MULTILIB_ABIS};
2301    do
2302        [ "$(get_abi_LIBDIR ${abi})" != "lib" ] && libdirs="${libdirs} $(get_abi_LIBDIR ${abi})";
2303    done;
2304    echo "${libdirs}"
2305}
2306get_bmake ()
2307{
2308    if [[ ${USERLAND} == *BSD ]]; then
2309        echo make;
2310    else
2311        if [[ ${USERLAND} == "Darwin" ]]; then
2312            echo bsdmake;
2313        else
2314            echo pmake;
2315        fi;
2316    fi
2317}
2318get_install_abis ()
2319{
2320    local order="";
2321    if [[ -z ${MULTILIB_ABIS} ]]; then
2322        echo "default";
2323        return 0;
2324    fi;
2325    if [[ ${EMULTILIB_PKG} == "true" ]]; then
2326        for x in ${MULTILIB_ABIS};
2327        do
2328            if [[ ${x} != "${DEFAULT_ABI}" ]]; then
2329                hasq ${x} ${ABI_DENY} || ordera="${ordera} ${x}";
2330            fi;
2331        done;
2332        hasq ${DEFAULT_ABI} ${ABI_DENY} || order="${ordera} ${DEFAULT_ABI}";
2333        if [[ -n ${ABI_ALLOW} ]]; then
2334            local ordera="";
2335            for x in ${order};
2336            do
2337                if hasq ${x} ${ABI_ALLOW}; then
2338                    ordera="${ordera} ${x}";
2339                fi;
2340            done;
2341            order=${ordera};
2342        fi;
2343    else
2344        order=${DEFAULT_ABI};
2345    fi;
2346    if [[ -z ${order} ]]; then
2347        die "The ABI list is empty.  Are you using a proper multilib profile?  Perhaps your USE flags or MULTILIB_ABIS are too restrictive for this package.";
2348    fi;
2349    echo ${order};
2350    return 0
2351}
2352get_libdir ()
2353{
2354    local CONF_LIBDIR;
2355    if [ -n "${CONF_LIBDIR_OVERRIDE}" ]; then
2356        echo ${CONF_LIBDIR_OVERRIDE};
2357    else
2358        get_abi_LIBDIR;
2359    fi
2360}
2361get_libdir_override ()
2362{
2363    if has_multilib_profile; then
2364        eerror "get_libdir_override called, but it shouldn't be needed with the new multilib approach.  Please file a bug at http://bugs.gentoo.org and assign it to eradicator@gentoo.org";
2365        exit 1;
2366    fi;
2367    CONF_LIBDIR="$1";
2368    CONF_LIBDIR_OVERRIDE="$1";
2369    LIBDIR_default="$1"
2370}
2371get_libname ()
2372{
2373    local libname;
2374    local ver=$1;
2375    case ${CHOST} in
2376        *-cygwin | mingw* | *-mingw*)
2377            libname="dll"
2378        ;;
2379        *-darwin*)
2380            libname="dylib"
2381        ;;
2382        *-aix*)
2383            libname="a"
2384        ;;
2385        *-mint*)
2386            libname="irrelevant"
2387        ;;
2388        hppa*-hpux*)
2389            libname="sl"
2390        ;;
2391        *)
2392            libname="so"
2393        ;;
2394    esac;
2395    if [[ -z $* ]]; then
2396        echo ".${libname}";
2397    else
2398        for ver in "$@";
2399        do
2400            case ${CHOST} in
2401                *-darwin*)
2402                    echo ".${ver}.${libname}"
2403                ;;
2404                *-aix*)
2405                    echo ".${libname}"
2406                ;;
2407                *-mint*)
2408                    echo ".${libname}"
2409                ;;
2410                *)
2411                    echo ".${libname}.${ver}"
2412                ;;
2413            esac;
2414        done;
2415    fi
2416}
2417get_ml_incdir ()
2418{
2419    local dir=/usr/include;
2420    if [[ $# -gt 0 ]]; then
2421        incdir=$1;
2422        shift;
2423    fi;
2424    if [[ -z "${MULTILIB_ABIS}" ]]; then
2425        echo ${incdir};
2426        return 0;
2427    fi;
2428    local abi=${ABI-${DEFAULT_ABI}};
2429    if [[ $# -gt 0 ]]; then
2430        abi=$1;
2431        shift;
2432    fi;
2433    if [[ -d "${dir}/gentoo-multilib/${abi}" ]]; then
2434        echo ${dir}/gentoo-multilib/${abi};
2435    else
2436        echo ${dir};
2437    fi
2438}
2439get_modname ()
2440{
2441    local modname;
2442    local ver=$1;
2443    case ${CHOST} in
2444        *-darwin*)
2445            modname="bundle"
2446        ;;
2447        *)
2448            modname="so"
2449        ;;
2450    esac;
2451    echo ".${modname}"
2452}
2453get_mounts ()
2454{
2455    local point= node= fs= opts= foo=;
2456    if [[ $(uname -s) == "Linux" ]]; then
2457        while read node point fs opts foo; do
2458            echo "${point} ${node} ${fs} ${opts}";
2459        done < /proc/mounts;
2460        return;
2461    fi;
2462    local IFS=' ';
2463    LC_ALL=C mount -p | while read node point fs foo; do
2464        opts=${fs#* };
2465        fs=${fs%% *};
2466        echo "${point// /\040} ${node// /\040} ${fs%% *} ${opts// /\040}";
2467    done
2468}
2469get_multilibdir ()
2470{
2471    if has_multilib_profile; then
2472        eerror "get_multilibdir called, but it shouldn't be needed with the new multilib approach.  Please file a bug at http://bugs.gentoo.org and assign it to eradicator@gentoo.org";
2473        exit 1;
2474    fi;
2475    echo ${CONF_MULTILIBDIR:=lib32}
2476}
2477git_apply_patches ()
2478{
2479    debug-print-function ${FUNCNAME} "$@";
2480    pushd "${S}" > /dev/null;
2481    if [[ ${#EGIT_PATCHES[@]} -gt 1 ]]; then
2482        for i in "${EGIT_PATCHES[@]}";
2483        do
2484            debug-print "$FUNCNAME: git_autopatch: patching from ${i}";
2485            epatch "${i}";
2486        done;
2487    else
2488        if [[ ${EGIT_PATCHES} != "" ]]; then
2489            debug-print "$FUNCNAME: git_autopatch: patching from ${EGIT_PATCHES}";
2490            epatch "${EGIT_PATCHES}";
2491        fi;
2492    fi;
2493    popd > /dev/null
2494}
2495git_bootstrap ()
2496{
2497    debug-print-function ${FUNCNAME} "$@";
2498    if [[ -n ${EGIT_BOOTSTRAP} ]]; then
2499        pushd "${S}" > /dev/null;
2500        einfo "Starting bootstrap";
2501        if [[ -f ${EGIT_BOOTSTRAP} ]]; then
2502            debug-print "$FUNCNAME: bootstraping with file \"${EGIT_BOOTSTRAP}\"";
2503            if [[ -x ${EGIT_BOOTSTRAP} ]]; then
2504                eval "./${EGIT_BOOTSTRAP}" || die "${EGIT}: bootstrap script failed";
2505            else
2506                eerror "\"${EGIT_BOOTSTRAP}\" is not executable.";
2507                eerror "Report upstream, or bug ebuild maintainer to remove bootstrap command.";
2508                die "${EGIT}: \"${EGIT_BOOTSTRAP}\" is not executable.";
2509            fi;
2510        else
2511            debug-print "$FUNCNAME: bootstraping with commands \"${EGIT_BOOTSTRAP}\"";
2512            eval "${EGIT_BOOTSTRAP}" || die "${EGIT}: bootstrap commands failed.";
2513        fi;
2514        einfo "Bootstrap finished";
2515        popd > /dev/null;
2516    fi
2517}
2518git_branch ()
2519{
2520    local branchname=branch-${EGIT_BRANCH} src=origin/${EGIT_BRANCH};
2521    if [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]]; then
2522        branchname=tree-${EGIT_COMMIT};
2523        src=${EGIT_COMMIT};
2524    fi;
2525    debug-print "git checkout -b ${branchname} ${src}";
2526    git checkout -b ${branchname} ${src} &>/dev/null;
2527    unset branchname src
2528}
2529git_fetch ()
2530{
2531    debug-print-function ${FUNCNAME} "$@";
2532    local GIT_DIR EGIT_CLONE_DIR oldsha1 cursha1 extra_clone_opts upstream_branch;
2533    ${EGIT_HAS_SUBMODULES} || export GIT_DIR;
2534    if [[ ${EGIT_QUIET} != OFF ]]; then
2535        elogcmd="einfo";
2536    else
2537        elogcmd="elog";
2538    fi;
2539    if [[ ! -z ${EGIT_TREE} ]]; then
2540        EGIT_COMMIT=${EGIT_TREE};
2541        ewarn "QA: Usage of deprecated EGIT_TREE variable detected.";
2542        ewarn "QA: Use EGIT_COMMIT variable instead.";
2543    fi;
2544    [[ -z ${EGIT_REPO_URI} ]] && die "${EGIT}: EGIT_REPO_URI is empty.";
2545    if [[ -z ${EGIT_REPO_URI%%:*} ]]; then
2546        case ${EGIT_REPO_URI%%:*} in
2547            git* | http | https | rsync | ssh)
2548
2549            ;;
2550            *)
2551                die "${EGIT}: protocol for fetch from "${EGIT_REPO_URI%:*}" is not yet implemented in eclass."
2552            ;;
2553        esac;
2554    fi;
2555    if [[ ! -d ${EGIT_STORE_DIR} ]]; then
2556        debug-print "${FUNCNAME}: initial clone. creating git directory";
2557        addwrite /;
2558        mkdir -p "${EGIT_STORE_DIR}" || die "${EGIT}: can't mkdir ${EGIT_STORE_DIR}.";
2559        export SANDBOX_WRITE="${SANDBOX_WRITE%%:/}";
2560    fi;
2561    cd -P "${EGIT_STORE_DIR}" || die "${EGIT}: can't chdir to ${EGIT_STORE_DIR}";
2562    EGIT_STORE_DIR=${PWD};
2563    addwrite "${EGIT_STORE_DIR}";
2564    [[ -z ${EGIT_REPO_URI##*/} ]] && EGIT_REPO_URI="${EGIT_REPO_URI%/}";
2565    EGIT_CLONE_DIR="${EGIT_PROJECT}";
2566    debug-print "${FUNCNAME}: EGIT_OPTIONS = \"${EGIT_OPTIONS}\"";
2567    GIT_DIR="${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}";
2568    if [[ -e "${GIT_DIR}/shallow" ]]; then
2569        rm -rf "${GIT_DIR}";
2570        einfo "The ${EGIT_CLONE_DIR} was shallow copy. Refetching.";
2571    fi;
2572    if ${EGIT_HAS_SUBMODULES} && [[ -d ${GIT_DIR} && ! -d "${GIT_DIR}/.git/" ]]; then
2573        rm -rf "${GIT_DIR}";
2574        einfo "The ${EGIT_CLONE_DIR} was bare copy. Refetching.";
2575    fi;
2576    if ! ${EGIT_HAS_SUBMODULES} && [[ -d ${GIT_DIR} && -d ${GIT_DIR}/.git ]]; then
2577        rm -rf "${GIT_DIR}";
2578        einfo "The ${EGIT_CLONE_DIR} was not a bare copy. Refetching.";
2579    fi;
2580    if ${EGIT_HAS_SUBMODULES}; then
2581        upstream_branch=origin/${EGIT_BRANCH};
2582    else
2583        upstream_branch=${EGIT_BRANCH};
2584        extra_clone_opts=--bare;
2585    fi;
2586    if [[ ! -d ${GIT_DIR} ]]; then
2587        ${elogcmd} "GIT NEW clone -->";
2588        ${elogcmd} "   repository:              ${EGIT_REPO_URI}";
2589        debug-print "${EGIT_FETCH_CMD} ${extra_clone_opts} ${EGIT_OPTIONS} \"${EGIT_REPO_URI}\" ${GIT_DIR}";
2590        ${EGIT_FETCH_CMD} ${extra_clone_opts} ${EGIT_OPTIONS} "${EGIT_REPO_URI}" ${GIT_DIR} || die "${EGIT}: can't fetch from ${EGIT_REPO_URI}.";
2591        pushd "${GIT_DIR}" &>/dev/null;
2592        cursha1=$(git rev-parse ${upstream_branch});
2593        ${elogcmd} "   at the commit:           ${cursha1}";
2594        git_submodules;
2595        popd &>/dev/null;
2596    else
2597        if [[ -n ${EGIT_OFFLINE} ]]; then
2598            pushd "${GIT_DIR}" &>/dev/null;
2599            cursha1=$(git rev-parse ${upstream_branch});
2600            ${elogcmd} "GIT offline update -->";
2601            ${elogcmd} "   repository:          ${EGIT_REPO_URI}";
2602            ${elogcmd} "   at the commit:               ${cursha1}";
2603            popd &>/dev/null;
2604        else
2605            pushd "${GIT_DIR}" &>/dev/null;
2606            git config remote.origin.url "${EGIT_REPO_URI}";
2607            ${elogcmd} "GIT update -->";
2608            ${elogcmd} "   repository:          ${EGIT_REPO_URI}";
2609            oldsha1=$(git rev-parse ${upstream_branch});
2610            if ${EGIT_HAS_SUBMODULES}; then
2611                debug-print "${EGIT_UPDATE_CMD} ${EGIT_OPTIONS}";
2612                git checkout ${EGIT_MASTER};
2613                for x in $(git branch |grep -v "* ${EGIT_MASTER}" |tr '\n' ' ');
2614                do
2615                    git branch -D ${x};
2616                done;
2617                ${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} || die "${EGIT}: can't update from ${EGIT_REPO_URI}.";
2618            else
2619                debug-print "${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} origin ${EGIT_BRANCH}:${EGIT_BRANCH}";
2620                ${EGIT_UPDATE_CMD} ${EGIT_OPTIONS} origin ${EGIT_BRANCH}:${EGIT_BRANCH} || die "${EGIT}: can't update from ${EGIT_REPO_URI}.";
2621            fi;
2622            git_submodules;
2623            cursha1=$(git rev-parse ${upstream_branch});
2624            if [[ ${oldsha1} != ${cursha1} ]]; then
2625                ${elogcmd} "   updating from commit:    ${oldsha1}";
2626                ${elogcmd} "   to commit:               ${cursha1}";
2627            else
2628                ${elogcmd} "   at the commit:           ${cursha1}";
2629                [[ ${LIVE_FAIL_FETCH_IF_REPO_NOT_UPDATED} = true ]] && debug-print "${FUNCNAME}: Repository \"${EGIT_REPO_URI}\" is up-to-date. Skipping." && die "${EGIT}: Repository \"${EGIT_REPO_URI}\" is up-to-date. Skipping.";
2630            fi;
2631            ${EGIT_DIFFSTAT_CMD} ${oldsha1}..${upstream_branch};
2632            popd &>/dev/null;
2633        fi;
2634    fi;
2635    pushd "${GIT_DIR}" &>/dev/null;
2636    if ${EGIT_REPACK} || ${EGIT_PRUNE}; then
2637        ebegin "Garbage collecting the repository";
2638        git gc $(${EGIT_PRUNE} && echo '--prune');
2639        eend $?;
2640    fi;
2641    popd &>/dev/null;
2642    export EGIT_VERSION="${cursha1}";
2643    [[ ${EGIT_COMMIT} != ${EGIT_BRANCH} ]] && elog "   commit:                  ${EGIT_COMMIT}";
2644    ${elogcmd} "   branch:                      ${EGIT_BRANCH}";
2645    ${elogcmd} "   storage directory:   \"${GIT_DIR}\"";
2646    if ${EGIT_HAS_SUBMODULES}; then
2647        pushd "${GIT_DIR}" &>/dev/null;
2648        debug-print "rsync -rlpgo . \"${S}\"";
2649        time rsync -rlpgo . "${S}";
2650        popd &>/dev/null;
2651    else
2652        unset GIT_DIR;
2653        debug-print "git clone -l -s -n \"${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}\" \"${S}\"";
2654        git clone -l -s -n "${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}" "${S}";
2655    fi;
2656    pushd "${S}" &>/dev/null;
2657    git_branch;
2658    [[ -n ${EGIT_OFFLINE} ]] || git_submodules;
2659    popd &>/dev/null;
2660    echo ">>> Unpacked to ${S}"
2661}
2662git_src_prepare ()
2663{
2664    debug-print-function ${FUNCNAME} "$@";
2665    git_apply_patches;
2666    git_bootstrap
2667}
2668git_src_unpack ()
2669{
2670    debug-print-function ${FUNCNAME} "$@";
2671    git_fetch || die "${EGIT}: unknown problem in git_fetch().";
2672    has src_prepare ${EXPORTED_FUNCTIONS} || git_src_prepare
2673}
2674git_submodules ()
2675{
2676    if ${EGIT_HAS_SUBMODULES}; then
2677        debug-print "git submodule init";
2678        git submodule init;
2679        debug-print "git submodule update";
2680        git submodule update;
2681    fi
2682}
2683has_hardened ()
2684{
2685    ewarn "has_hardened: deprecated, please use gcc-specs-{relro,now}()!" 1>&2;
2686    test_version_info Hardened && return 0;
2687    [[ -f ${GCC_SPECS} && ${GCC_SPECS} != ${GCC_SPECS/hardened/} ]]
2688}
2689has_m32 ()
2690{
2691    [ "$(tc-arch)" = "amd64" ] && has_multilib_profile && return 0;
2692    local temp=$(emktemp);
2693    echo "int main() { return(0); }" > "${temp}".c;
2694    MY_CC=$(tc-getCC);
2695    ${MY_CC/ .*/} -m32 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1;
2696    local ret=$?;
2697    rm -f "${temp}".c;
2698    [[ ${ret} != 1 ]] && return 0;
2699    return 1
2700}
2701has_m64 ()
2702{
2703    local temp="$(emktemp)";
2704    echo "int main() { return(0); }" > "${temp}".c;
2705    MY_CC=$(tc-getCC);
2706    ${MY_CC/ .*/} -m64 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1;
2707    local ret=$?;
2708    rm -f "${temp}".c;
2709    [[ ${ret} != 1 ]] && return 0;
2710    return 1
2711}
2712has_multilib_profile ()
2713{
2714    [ -n "${MULTILIB_ABIS}" -a "${MULTILIB_ABIS}" != "${MULTILIB_ABIS/ /}" ]
2715}
2716has_pic ()
2717{
2718    ewarn "has_pic: deprecated, please use gcc-specs-pie()!" 1>&2;
2719    [[ ${CFLAGS/-fPIC} != ${CFLAGS} || ${CFLAGS/-fpic} != ${CFLAGS} ]] || gcc-specs-pie
2720}
2721has_pie ()
2722{
2723    ewarn "has_pie: deprecated, please use gcc-specs-pie()!" 1>&2;
2724    [[ ${CFLAGS/-fPIE} != ${CFLAGS} || ${CFLAGS/-fpie} != ${CFLAGS} ]] || gcc-specs-pie
2725}
2726has_ssp ()
2727{
2728    ewarn "has_ssp: deprecated, please use gcc-specs-ssp()!" 1>&2;
2729    [[ ${CFLAGS/-fstack-protector} != ${CFLAGS} || -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__) ]] || gcc-specs-ssp
2730}
2731has_ssp_all ()
2732{
2733    ewarn "has_ssp_all: deprecated, please use gcc-specs-ssp()!" 1>&2;
2734    [[ ${CFLAGS/-fstack-protector-all} != ${CFLAGS} || -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__) ]] || gcc-specs-ssp-to-all
2735}
2736install_driver_hwdata ()
2737{
2738    insinto /usr/share/hwdata/videoaliases;
2739    for i in "${FILESDIR}"/*.xinf;
2740    do
2741        if [[ -e $i ]]; then
2742            doins $i;
2743        fi;
2744    done
2745}
2746is-flag ()
2747{
2748    is-flagq "$@" && echo true
2749}
2750is-flagq ()
2751{
2752    [[ -n $2 ]] && die "Usage: is-flag <flag>";
2753    _is_flagq CFLAGS $1 || _is_flagq CXXFLAGS $1 || _is_flagq FFLAGS $1 || _is_flagq FCFLAGS $1
2754}
2755is-ldflag ()
2756{
2757    is-ldflagq "$@" && echo true
2758}
2759is-ldflagq ()
2760{
2761    [[ -n $2 ]] && die "Usage: is-ldflag <flag>";
2762    _is_flagq LDFLAGS $1
2763}
2764is-login-disabled ()
2765{
2766    shell=$(egetshell "$1");
2767    case ${shell} in
2768        /bin/false | /usr/bin/false | /sbin/nologin | /usr/sbin/nologin)
2769            return 0
2770        ;;
2771        *)
2772            return 1
2773        ;;
2774    esac
2775}
2776is_final_abi ()
2777{
2778    has_multilib_profile || return 0;
2779    local ALL_ABIS=$(get_install_abis);
2780    local LAST_ABI=${ALL_ABIS/* /};
2781    [[ ${LAST_ABI} == ${ABI} ]]
2782}
2783make_desktop_entry ()
2784{
2785    [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable";
2786    local exec=${1};
2787    local name=${2:-${PN}};
2788    local icon=${3:-${PN}};
2789    local type=${4};
2790    local fields=${5};
2791    if [[ -z ${type} ]]; then
2792        local catmaj=${CATEGORY%%-*};
2793        local catmin=${CATEGORY##*-};
2794        case ${catmaj} in
2795            app)
2796                case ${catmin} in
2797                    accessibility)
2798                        type=Accessibility
2799                    ;;
2800                    admin)
2801                        type=System
2802                    ;;
2803                    antivirus)
2804                        type=System
2805                    ;;
2806                    arch)
2807                        type=Archiving
2808                    ;;
2809                    backup)
2810                        type=Archiving
2811                    ;;
2812                    cdr)
2813                        type=DiscBurning
2814                    ;;
2815                    dicts)
2816                        type=Dictionary
2817                    ;;
2818                    doc)
2819                        type=Documentation
2820                    ;;
2821                    editors)
2822                        type=TextEditor
2823                    ;;
2824                    emacs)
2825                        type=TextEditor
2826                    ;;
2827                    emulation)
2828                        type=Emulator
2829                    ;;
2830                    laptop)
2831                        type=HardwareSettings
2832                    ;;
2833                    office)
2834                        type=Office
2835                    ;;
2836                    pda)
2837                        type=PDA
2838                    ;;
2839                    vim)
2840                        type=TextEditor
2841                    ;;
2842                    xemacs)
2843                        type=TextEditor
2844                    ;;
2845                esac
2846            ;;
2847            dev)
2848                type="Development"
2849            ;;
2850            games)
2851                case ${catmin} in
2852                    action | fps)
2853                        type=ActionGame
2854                    ;;
2855                    arcade)
2856                        type=ArcadeGame
2857                    ;;
2858                    board)
2859                        type=BoardGame
2860                    ;;
2861                    emulation)
2862                        type=Emulator
2863                    ;;
2864                    kids)
2865                        type=KidsGame
2866                    ;;
2867                    puzzle)
2868                        type=LogicGame
2869                    ;;
2870                    roguelike)
2871                        type=RolePlaying
2872                    ;;
2873                    rpg)
2874                        type=RolePlaying
2875                    ;;
2876                    simulation)
2877                        type=Simulation
2878                    ;;
2879                    sports)
2880                        type=SportsGame
2881                    ;;
2882                    strategy)
2883                        type=StrategyGame
2884                    ;;
2885                esac;
2886                type="Game;${type}"
2887            ;;
2888            gnome)
2889                type="Gnome;GTK"
2890            ;;
2891            kde)
2892                type="KDE;Qt"
2893            ;;
2894            mail)
2895                type="Network;Email"
2896            ;;
2897            media)
2898                case ${catmin} in
2899                    gfx)
2900                        type=Graphics
2901                    ;;
2902                    *)
2903                        case ${catmin} in
2904                            radio)
2905                                type=Tuner
2906                            ;;
2907                            sound)
2908                                type=Audio
2909                            ;;
2910                            tv)
2911                                type=TV
2912                            ;;
2913                            video)
2914                                type=Video
2915                            ;;
2916                        esac;
2917                        type="AudioVideo;${type}"
2918                    ;;
2919                esac
2920            ;;
2921            net)
2922                case ${catmin} in
2923                    dialup)
2924                        type=Dialup
2925                    ;;
2926                    ftp)
2927                        type=FileTransfer
2928                    ;;
2929                    im)
2930                        type=InstantMessaging
2931                    ;;
2932                    irc)
2933                        type=IRCClient
2934                    ;;
2935                    mail)
2936                        type=Email
2937                    ;;
2938                    news)
2939                        type=News
2940                    ;;
2941                    nntp)
2942                        type=News
2943                    ;;
2944                    p2p)
2945                        type=FileTransfer
2946                    ;;
2947                    voip)
2948                        type=Telephony
2949                    ;;
2950                esac;
2951                type="Network;${type}"
2952            ;;
2953            sci)
2954                case ${catmin} in
2955                    astro*)
2956                        type=Astronomy
2957                    ;;
2958                    bio*)
2959                        type=Biology
2960                    ;;
2961                    calc*)
2962                        type=Calculator
2963                    ;;
2964                    chem*)
2965                        type=Chemistry
2966                    ;;
2967                    elec*)
2968                        type=Electronics
2969                    ;;
2970                    geo*)
2971                        type=Geology
2972                    ;;
2973                    math*)
2974                        type=Math
2975                    ;;
2976                    physics)
2977                        type=Physics
2978                    ;;
2979                    visual*)
2980                        type=DataVisualization
2981                    ;;
2982                esac;
2983                type="Education;Science;${type}"
2984            ;;
2985            sys)
2986                type="System"
2987            ;;
2988            www)
2989                case ${catmin} in
2990                    client)
2991                        type=WebBrowser
2992                    ;;
2993                esac;
2994                type="Network;${type}"
2995            ;;
2996            *)
2997                type=
2998            ;;
2999        esac;
3000    fi;
3001    if [ "${SLOT}" == "0" ]; then
3002        local desktop_name="${PN}";
3003    else
3004        local desktop_name="${PN}-${SLOT}";
3005    fi;
3006    local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop";
3007    type=${type%;}${type:+;};
3008    eshopts_push -s extglob;
3009    if [[ -n ${icon} && ${icon} != /* ]] && [[ ${icon} == *.xpm || ${icon} == *.png || ${icon} == *.svg ]]; then
3010        ewarn "As described in the Icon Theme Specification, icon file extensions are not";
3011        ewarn "allowed in .desktop files if the value is not an absolute path.";
3012        icon=${icon%.@(xpm|png|svg)};
3013    fi;
3014    eshopts_pop;
3015    cat > "${desktop}"  <<-EOF
3016[Desktop Entry]
3017Name=${name}
3018Type=Application
3019Comment=${DESCRIPTION}
3020Exec=${exec}
3021TryExec=${exec%% *}
3022Icon=${icon}
3023Categories=${type}
3024EOF
3025
3026    if [[ ${fields:-=} != *=* ]]; then
3027        ewarn "make_desktop_entry: update your 5th arg to read Path=${fields}";
3028        fields="Path=${fields}";
3029    fi;
3030    [[ -n ${fields} ]] && printf '%b\n' "${fields}" >> "${desktop}";
3031    ( insinto /usr/share/applications;
3032    doins "${desktop}" ) || die "installing desktop file failed"
3033}
3034make_session_desktop ()
3035{
3036    [[ -z $1 ]] && eerror "$0: You must specify the title" && return 1;
3037    [[ -z $2 ]] && eerror "$0: You must specify the command" && return 1;
3038    local title=$1;
3039    local command=$2;
3040    local desktop=${T}/${wm:-${PN}}.desktop;
3041    shift 2;
3042    cat > "${desktop}"  <<-EOF
3043[Desktop Entry]
3044Name=${title}
3045Comment=This session logs you into ${title}
3046Exec=${command} $*
3047TryExec=${command}
3048Type=XSession
3049EOF
3050
3051    ( insinto /usr/share/xsessions;
3052    doins "${desktop}" )
3053}
3054make_wrapper ()
3055{
3056    local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5;
3057    local tmpwrapper=$(emktemp);
3058    cat > "${tmpwrapper}"  <<EOF
3059#!/bin/sh
3060cd "${chdir:-.}"
3061if [ -n "${libdir}" ] ; then
3062        if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
3063                export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
3064        else
3065                export LD_LIBRARY_PATH="${libdir}"
3066        fi
3067fi
3068exec ${bin} "\$@"
3069EOF
3070
3071    chmod go+rx "${tmpwrapper}";
3072    if [[ -n ${path} ]]; then
3073        ( exeinto "${path}";
3074        newexe "${tmpwrapper}" "${wrapper}" ) || die;
3075    else
3076        newbin "${tmpwrapper}" "${wrapper}" || die;
3077    fi
3078}
3079multilib_env ()
3080{
3081    local CTARGET=${1:-${CTARGET}};
3082    case ${CTARGET} in
3083        x86_64*)
3084            export CFLAGS_x86=${CFLAGS_x86--m32};
3085            export CHOST_x86=${CTARGET/x86_64/i686};
3086            export CTARGET_x86=${CHOST_x86};
3087            export CDEFINE_x86="__i386__";
3088            export LIBDIR_x86="lib";
3089            export CFLAGS_amd64=${CFLAGS_amd64--m64};
3090            export CHOST_amd64=${CTARGET};
3091            export CTARGET_amd64=${CHOST_amd64};
3092            export CDEFINE_amd64="__x86_64__";
3093            export LIBDIR_amd64="lib64";
3094            export MULTILIB_ABIS="amd64 x86";
3095            export DEFAULT_ABI="amd64"
3096        ;;
3097        mips64*)
3098            export CFLAGS_o32=${CFLAGS_o32--mabi=32};
3099            export CHOST_o32=${CTARGET/mips64/mips};
3100            export CTARGET_o32=${CHOST_o32};
3101            export CDEFINE_o32="_MIPS_SIM == _ABIO32";
3102            export LIBDIR_o32="lib";
3103            export CFLAGS_n32=${CFLAGS_n32--mabi=n32};
3104            export CHOST_n32=${CTARGET};
3105            export CTARGET_n32=${CHOST_n32};
3106            export CDEFINE_n32="_MIPS_SIM == _ABIN32";
3107            export LIBDIR_n32="lib32";
3108            export CFLAGS_n64=${CFLAGS_n64--mabi=64};
3109            export CHOST_n64=${CTARGET};
3110            export CTARGET_n64=${CHOST_n64};
3111            export CDEFINE_n64="_MIPS_SIM == _ABI64";
3112            export LIBDIR_n64="lib64";
3113            export MULTILIB_ABIS="n64 n32 o32";
3114            export DEFAULT_ABI="n32"
3115        ;;
3116        powerpc64*)
3117            export CFLAGS_ppc=${CFLAGS_ppc--m32};
3118            export CHOST_ppc=${CTARGET/powerpc64/powerpc};
3119            export CTARGET_ppc=${CHOST_ppc};
3120            export CDEFINE_ppc="!__powerpc64__";
3121            export LIBDIR_ppc="lib";
3122            export CFLAGS_ppc64=${CFLAGS_ppc64--m64};
3123            export CHOST_ppc64=${CTARGET};
3124            export CTARGET_ppc64=${CHOST_ppc64};
3125            export CDEFINE_ppc64="__powerpc64__";
3126            export LIBDIR_ppc64="lib64";
3127            export MULTILIB_ABIS="ppc64 ppc";
3128            export DEFAULT_ABI="ppc64"
3129        ;;
3130        s390x*)
3131            export CFLAGS_s390=${CFLAGS_s390--m31};
3132            export CHOST_s390=${CTARGET/s390x/s390};
3133            export CTARGET_s390=${CHOST_s390};
3134            export CDEFINE_s390="!__s390x__";
3135            export LIBDIR_s390="lib";
3136            export CFLAGS_s390x=${CFLAGS_s390x--m64};
3137            export CHOST_s390x=${CTARGET};
3138            export CTARGET_s390x=${CHOST_s390x};
3139            export CDEFINE_s390x="__s390x__";
3140            export LIBDIR_s390x="lib64";
3141            export MULTILIB_ABIS="s390x s390";
3142            export DEFAULT_ABI="s390x"
3143        ;;
3144        sparc*)
3145            export CFLAGS_sparc32=${CFLAGS_sparc32};
3146            export CHOST_sparc32=${CTARGET/sparc64/sparc};
3147            export CTARGET_sparc32=${CHOST_sparc32};
3148            export CDEFINE_sparc32="!__arch64__";
3149            export LIBDIR_sparc32="lib";
3150            export CFLAGS_sparc64=${CFLAGS_sparc64--m64};
3151            export CHOST_sparc64=${CTARGET};
3152            export CTARGET_sparc64=${CHOST_sparc64};
3153            export CDEFINE_sparc64="__arch64__";
3154            export LIBDIR_sparc64="lib64";
3155            export MULTILIB_ABIS="${MULTILIB_ABIS-sparc64 sparc32}";
3156            export DEFAULT_ABI="${DEFAULT_ABI-sparc64}"
3157        ;;
3158        *)
3159            export MULTILIB_ABIS="default";
3160            export DEFAULT_ABI="default"
3161        ;;
3162    esac
3163}
3164multilib_toolchain_setup ()
3165{
3166    local v vv;
3167    export ABI=$1;
3168    if [[ ${ABI} != ${DEFAULT_ABI} ]]; then
3169        if [[ ${DEFAULT_ABI_SAVED} != "true" ]]; then
3170            for v in CHOST CBUILD AS CC CXX LD;
3171            do
3172                export __abi_saved_${v}="${!v}";
3173            done;
3174            export DEFAULT_ABI_SAVED="true";
3175        fi;
3176        export CHOST=$(get_abi_CHOST ${DEFAULT_ABI});
3177        export AS="$(tc-getAS) $(get_abi_ASFLAGS)";
3178        export CC="$(tc-getCC) $(get_abi_CFLAGS)";
3179        export CXX="$(tc-getCXX) $(get_abi_CFLAGS)";
3180        export LD="$(tc-getLD) $(get_abi_LDFLAGS)";
3181        export CHOST=$(get_abi_CHOST $1);
3182        export CBUILD=$(get_abi_CHOST $1);
3183    else
3184        if [[ ${DEFAULT_ABI_SAVED} == "true" ]]; then
3185            for v in CHOST CBUILD AS CC CXX LD;
3186            do
3187                vv="__abi_saved_${v}";
3188                export ${v}=${!vv};
3189            done;
3190        fi;
3191    fi
3192}
3193newicon ()
3194{
3195    ( insinto /usr/share/pixmaps;
3196    newins "$@" )
3197}
3198newmenu ()
3199{
3200    ( insinto /usr/share/applications;
3201    newins "$@" )
3202}
3203no-as-needed ()
3204{
3205    case $($(tc-getLD) -v 2>&1 </dev/null) in
3206        *GNU*)
3207            echo "-Wl,--no-as-needed"
3208        ;;
3209    esac
3210}
3211nonfatal ()
3212{
3213    if has "${EAPI:-0}" 0 1 2 3 3_pre2; then
3214        die "$FUNCNAME() not supported in this EAPI";
3215    fi;
3216    if [[ $# -lt 1 ]]; then
3217        die "$FUNCNAME(): Missing argument";
3218    fi;
3219    PORTAGE_NONFATAL=1 "$@"
3220}
3221number_abis ()
3222{
3223    get_install_abis | wc -w
3224}
3225pkg_nofetch ()
3226{
3227    _eapi0_pkg_nofetch "$@"
3228}
3229pkg_postinst ()
3230{
3231    x-modular_pkg_postinst "$@"
3232}
3233pkg_postrm ()
3234{
3235    x-modular_pkg_postrm "$@"
3236}
3237pkg_preinst ()
3238{
3239    x-modular_pkg_preinst "$@"
3240}
3241prep_ml_includes ()
3242{
3243    if [[ $(number_abis) -gt 1 ]]; then
3244        local dir;
3245        local dirs;
3246        local base;
3247        if [[ $# -eq 0 ]]; then
3248            dirs=/usr/include;
3249        else
3250            dirs="$@";
3251        fi;
3252        for dir in ${dirs};
3253        do
3254            base=${T}/gentoo-multilib/${dir}/gentoo-multilib;
3255            mkdir -p "${base}";
3256            [[ -d ${base}/${ABI} ]] && rm -rf "${base}/${ABI}";
3257            mv "${D}/${dir}" "${base}/${ABI}";
3258        done;
3259        if is_final_abi; then
3260            base=${T}/gentoo-multilib;
3261            pushd "${base}";
3262            find . | tar -c -T - -f - | tar -x --no-same-owner -f - -C "${D}";
3263            popd;
3264            set --;
3265            for dir in ${dirs};
3266            do
3267                set -- "$@" "${dir}";
3268                local abi;
3269                for abi in $(get_install_abis);
3270                do
3271                    set -- "$@" "$(get_abi_CDEFINE ${abi}):${dir}/gentoo-multilib/${abi}";
3272                done;
3273                create_ml_includes "$@";
3274            done;
3275        fi;
3276    fi
3277}
3278preserve_old_lib ()
3279{
3280    if [[ ${EBUILD_PHASE} != "preinst" ]]; then
3281        eerror "preserve_old_lib() must be called from pkg_preinst() only";
3282        die "Invalid preserve_old_lib() usage";
3283    fi;
3284    [[ -z $1 ]] && die "Usage: preserve_old_lib <library to preserve> [more libraries to preserve]";
3285    has preserve-libs ${FEATURES} && return 0;
3286    local lib dir;
3287    for lib in "$@";
3288    do
3289        [[ -e ${ROOT}/${lib} ]] || continue;
3290        dir=${lib%/*};
3291        dodir ${dir} || die "dodir ${dir} failed";
3292        cp "${ROOT}"/${lib} "${D}"/${lib} || die "cp ${lib} failed";
3293        touch "${D}"/${lib};
3294    done
3295}
3296preserve_old_lib_notify ()
3297{
3298    if [[ ${EBUILD_PHASE} != "postinst" ]]; then
3299        eerror "preserve_old_lib_notify() must be called from pkg_postinst() only";
3300        die "Invalid preserve_old_lib_notify() usage";
3301    fi;
3302    has preserve-libs ${FEATURES} && return 0;
3303    local lib notice=0;
3304    for lib in "$@";
3305    do
3306        [[ -e ${ROOT}/${lib} ]] || continue;
3307        if [[ ${notice} -eq 0 ]]; then
3308            notice=1;
3309            ewarn "Old versions of installed libraries were detected on your system.";
3310            ewarn "In order to avoid breaking packages that depend on these old libs,";
3311            ewarn "the libraries are not being removed.  You need to run revdep-rebuild";
3312            ewarn "in order to remove these old dependencies.  If you do not have this";
3313            ewarn "helper program, simply emerge the 'gentoolkit' package.";
3314            ewarn;
3315        fi;
3316        ewarn "  # revdep-rebuild --library ${lib##*/}";
3317    done;
3318    if [[ ${notice} -eq 1 ]]; then
3319        ewarn;
3320        ewarn "Once you've finished running revdep-rebuild, it should be safe to";
3321        ewarn "delete the old libraries.  Here is a copy & paste for the lazy:";
3322        for lib in "$@";
3323        do
3324            ewarn "  # rm '${lib}'";
3325        done;
3326    fi
3327}
3328raw-ldflags ()
3329{
3330    local x input="$@";
3331    [[ -z ${input} ]] && input=${LDFLAGS};
3332    set --;
3333    for x in ${input};
3334    do
3335        x=${x#-Wl,};
3336        set -- "$@" ${x//,/ };
3337    done;
3338    echo "$@"
3339}
3340register_success_hook ()
3341{
3342    local x;
3343    for x in $*;
3344    do
3345        hasq $x $EBUILD_SUCCESS_HOOKS || export EBUILD_SUCCESS_HOOKS="$EBUILD_SUCCESS_HOOKS $x";
3346    done
3347}
3348remove_font_metadata ()
3349{
3350    local DIR;
3351    for DIR in ${FONT_DIR};
3352    do
3353        if [[ "${DIR}" != "Speedo" ]] && [[ "${DIR}" != "CID" ]]; then
3354            rm -f "${D}"/usr/share/fonts/${DIR}/fonts.{scale,dir,cache-1};
3355        fi;
3356    done
3357}
3358replace-cpu-flags ()
3359{
3360    local newcpu="$#";
3361    newcpu="${!newcpu}";
3362    while [ $# -gt 1 ]; do
3363        replace-flags "-march=${1}" "-march=${newcpu}";
3364        replace-flags "-mcpu=${1}" "-mcpu=${newcpu}";
3365        replace-flags "-mtune=${1}" "-mtune=${newcpu}";
3366        shift;
3367    done;
3368    return 0
3369}
3370replace-flags ()
3371{
3372    [[ $# != 2 ]] && echo && eerror "Usage: replace-flags <old flag> <new flag>" && die "replace-flags takes 2 arguments, not $#";
3373    local f fset;
3374    declare -a new_CFLAGS new_CXXFLAGS new_FFLAGS new_FCFLAGS;
3375    for fset in CFLAGS CXXFLAGS FFLAGS FCFLAGS;
3376    do
3377        for f in ${!fset};
3378        do
3379            [[ ${f} == ${1} ]] && f=${2};
3380            eval new_${fset}\[\${\#new_${fset}\[@]}]=\${f};
3381        done;
3382        eval export ${fset}=\${new_${fset}\[*]};
3383    done;
3384    return 0
3385}
3386replace-sparc64-flags ()
3387{
3388    local SPARC64_CPUS="ultrasparc3 ultrasparc v9";
3389    if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then
3390        for x in ${SPARC64_CPUS};
3391        do
3392            CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}";
3393        done;
3394    else
3395        for x in ${SPARC64_CPUS};
3396        do
3397            CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}";
3398        done;
3399    fi;
3400    if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then
3401        for x in ${SPARC64_CPUS};
3402        do
3403            CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}";
3404        done;
3405    else
3406        for x in ${SPARC64_CPUS};
3407        do
3408            CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}";
3409        done;
3410    fi;
3411    export CFLAGS CXXFLAGS
3412}
3413seq ()
3414{
3415    local p=$(type -P seq);
3416    case $# in
3417        1)
3418            min=1 max=$1 step=1
3419        ;;
3420        2)
3421            min=$1 max=$2 step=1
3422        ;;
3423        3)
3424            min=$1 max=$3 step=$2
3425        ;;
3426        *)
3427            die "seq called with wrong number of arguments"
3428        ;;
3429    esac;
3430    if [[ -z ${p} ]]; then
3431        local reps;
3432        if [[ ${step} != 0 ]]; then
3433            reps=$(( ($max-$min) / $step +1 ));
3434        else
3435            reps=0;
3436        fi;
3437        jot $reps $min $max $step;
3438    else
3439        "${p}" $min $step $max;
3440    fi
3441}
3442setup-allowed-flags ()
3443{
3444    if [[ -z ${ALLOWED_FLAGS} ]]; then
3445        export ALLOWED_FLAGS="-pipe";
3446        export ALLOWED_FLAGS="${ALLOWED_FLAGS} -O -O0 -O1 -O2 -mcpu -march -mtune";
3447        export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fstack-protector -fstack-protector-all";
3448        export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fbounds-checking -fno-strict-overflow";
3449        export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-PIE -fno-pie -fno-unit-at-a-time";
3450        export ALLOWED_FLAGS="${ALLOWED_FLAGS} -g -g[0-9] -ggdb -ggdb[0-9] -gstabs -gstabs+";
3451        export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-ident";
3452        export ALLOWED_FLAGS="${ALLOWED_FLAGS} -W* -w";
3453    fi;
3454    ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all               -fno-strict-aliasing -fno-bounds-checking -fstrict-overflow -fno-omit-frame-pointer";
3455    ALLOWED_FLAGS="${ALLOWED_FLAGS} -mregparm -mno-app-regs -mapp-regs          -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4 -mno-sse4.1          -mno-sse4.2 -mno-avx -mno-aes -mno-pclmul -mno-sse4a -mno-3dnow                 -mno-popcnt -mno-abm            -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 -mplt               -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu                 -mieee -mieee-with-inexact -mschedule           -mtls-direct-seg-refs -mno-tls-direct-seg-refs          -mflat -mno-flat -mno-faster-structs -mfaster-structs           -m32 -m64 -mabi -mlittle-endian -mbig-endian -EL -EB -fPIC              -mlive-g0 -mcmodel -mstack-bias -mno-stack-bias                 -msecure-plt -m*-toc -D* -U*";
3456    ALLOWED_FLAGS="${ALLOWED_FLAGS} -mno-fma4 -mno-movbe -mno-xop -mno-lwp";
3457    export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks";
3458    return 0
3459}
3460setup_fonts ()
3461{
3462    if [[ ! -n "${FONT_DIR}" ]]; then
3463        msg="FONT_DIR is empty. The ebuild should set it to at least one subdir of /usr/share/fonts.";
3464        eerror "${msg}";
3465        die "${msg}";
3466    fi;
3467    create_fonts_scale;
3468    create_fonts_dir;
3469    create_font_cache
3470}
3471src_compile ()
3472{
3473    x-modular_src_compile "$@"
3474}
3475src_install ()
3476{
3477    x-modular_src_install
3478}
3479src_test ()
3480{
3481    _eapi0_src_test "$@"
3482}
3483src_unpack ()
3484{
3485    git_src_unpack;
3486    cd "${S}";
3487    append-flags -Wno-error;
3488    eautoreconf || die "eautoreconf failed"
3489}
3490strip-flags ()
3491{
3492    local x y flag NEW_CFLAGS NEW_CXXFLAGS NEW_FFLAGS NEW_FCFLAGS;
3493    setup-allowed-flags;
3494    local NEW_CFLAGS="";
3495    local NEW_CXXFLAGS="";
3496    local NEW_FFLAGS="";
3497    local NEW_FCFLAGS="";
3498    if has "~$(tc-arch)" ${ACCEPT_KEYWORDS}; then
3499        ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}";
3500    fi;
3501    set -f;
3502    for x in ${CFLAGS};
3503    do
3504        for y in ${ALLOWED_FLAGS};
3505        do
3506            flag=${x%%=*};
3507            if [ "${flag%%${y}}" = "" ]; then
3508                NEW_CFLAGS="${NEW_CFLAGS} ${x}";
3509                break;
3510            fi;
3511        done;
3512    done;
3513    for x in ${CXXFLAGS};
3514    do
3515        for y in ${ALLOWED_FLAGS};
3516        do
3517            flag=${x%%=*};
3518            if [ "${flag%%${y}}" = "" ]; then
3519                NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}";
3520                break;
3521            fi;
3522        done;
3523    done;
3524    for x in ${FFLAGS};
3525    do
3526        for y in ${ALLOWED_FLAGS};
3527        do
3528            flag=${x%%=*};
3529            if [ "${flag%%${y}}" = "" ]; then
3530                NEW_FFLAGS="${NEW_FFLAGS} ${x}";
3531                break;
3532            fi;
3533        done;
3534    done;
3535    for x in ${FCFLAGS};
3536    do
3537        for y in ${ALLOWED_FLAGS};
3538        do
3539            flag=${x%%=*};
3540            if [ "${flag%%${y}}" = "" ]; then
3541                NEW_FCFLAGS="${NEW_FCFLAGS} ${x}";
3542                break;
3543            fi;
3544        done;
3545    done;
3546    if [ "${CFLAGS/-O}" != "${CFLAGS}" -a "${NEW_CFLAGS/-O}" = "${NEW_CFLAGS}" ]; then
3547        NEW_CFLAGS="${NEW_CFLAGS} -O2";
3548    fi;
3549    if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then
3550        NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2";
3551    fi;
3552    if [ "${FFLAGS/-O}" != "${FFLAGS}" -a "${NEW_FFLAGS/-O}" = "${NEW_FFLAGS}" ]; then
3553        NEW_FFLAGS="${NEW_FFLAGS} -O2";
3554    fi;
3555    if [ "${FCFLAGS/-O}" != "${FCFLAGS}" -a "${NEW_FCFLAGS/-O}" = "${NEW_FCFLAGS}" ]; then
3556        NEW_FCFLAGS="${NEW_FCFLAGS} -O2";
3557    fi;
3558    set +f;
3559    export CFLAGS="${NEW_CFLAGS}";
3560    export CXXFLAGS="${NEW_CXXFLAGS}";
3561    export FFLAGS="${NEW_FFLAGS}";
3562    export FCFLAGS="${NEW_FCFLAGS}";
3563    return 0
3564}
3565strip-linguas ()
3566{
3567    local ls newls nols;
3568    if [[ $1 == "-i" ]] || [[ $1 == "-u" ]]; then
3569        local op=$1;
3570        shift;
3571        ls=$(find "$1" -name '*.po' -exec basename {} .po ';');
3572        shift;
3573        local d f;
3574        for d in "$@";
3575        do
3576            if [[ ${op} == "-u" ]]; then
3577                newls=${ls};
3578            else
3579                newls="";
3580            fi;
3581            for f in $(find "$d" -name '*.po' -exec basename {} .po ';');
3582            do
3583                if [[ ${op} == "-i" ]]; then
3584                    hasq ${f} ${ls} && newls="${newls} ${f}";
3585                else
3586                    hasq ${f} ${ls} || newls="${newls} ${f}";
3587                fi;
3588            done;
3589            ls=${newls};
3590        done;
3591    else
3592        ls="$@";
3593    fi;
3594    nols="";
3595    newls="";
3596    for f in ${LINGUAS};
3597    do
3598        if hasq ${f} ${ls}; then
3599            newls="${newls} ${f}";
3600        else
3601            nols="${nols} ${f}";
3602        fi;
3603    done;
3604    [[ -n ${nols} ]] && ewarn "Sorry, but ${PN} does not support the LINGUAS:" ${nols};
3605    export LINGUAS=${newls:1}
3606}
3607strip-unsupported-flags ()
3608{
3609    export CFLAGS=$(test-flags-CC ${CFLAGS});
3610    export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS});
3611    export FFLAGS=$(test-flags-F77 ${FFLAGS});
3612    export FCFLAGS=$(test-flags-FC ${FCFLAGS})
3613}
3614tc-arch ()
3615{
3616    tc-ninja_magic_to_arch portage "$@"
3617}
3618tc-arch-kernel ()
3619{
3620    tc-ninja_magic_to_arch kern "$@"
3621}
3622tc-endian ()
3623{
3624    local host=$1;
3625    [[ -z ${host} ]] && host=${CTARGET:-${CHOST}};
3626    host=${host%%-*};
3627    case ${host} in
3628        alpha*)
3629            echo big
3630        ;;
3631        arm*b*)
3632            echo big
3633        ;;
3634        arm*)
3635            echo little
3636        ;;
3637        cris*)
3638            echo little
3639        ;;
3640        hppa*)
3641            echo big
3642        ;;
3643        i?86*)
3644            echo little
3645        ;;
3646        ia64*)
3647            echo little
3648        ;;
3649        m68*)
3650            echo big
3651        ;;
3652        mips*l*)
3653            echo little
3654        ;;
3655        mips*)
3656            echo big
3657        ;;
3658        powerpc*)
3659            echo big
3660        ;;
3661        s390*)
3662            echo big
3663        ;;
3664        sh*b*)
3665            echo big
3666        ;;
3667        sh*)
3668            echo little
3669        ;;
3670        sparc*)
3671            echo big
3672        ;;
3673        x86_64*)
3674            echo little
3675        ;;
3676        *)
3677            echo wtf
3678        ;;
3679    esac
3680}
3681tc-export ()
3682{
3683    local var;
3684    for var in "$@";
3685    do
3686        [[ $(type -t tc-get${var}) != "function" ]] && die "tc-export: invalid export variable '${var}'";
3687        eval tc-get${var} > /dev/null;
3688    done
3689}
3690tc-getAR ()
3691{
3692    tc-getPROG AR ar "$@"
3693}
3694tc-getAS ()
3695{
3696    tc-getPROG AS as "$@"
3697}
3698tc-getBUILD_CC ()
3699{
3700    local v;
3701    for v in CC_FOR_BUILD BUILD_CC HOSTCC;
3702    do
3703        if [[ -n ${!v} ]]; then
3704            export BUILD_CC=${!v};
3705            echo "${!v}";
3706            return 0;
3707        fi;
3708    done;
3709    local search=;
3710    if [[ -n ${CBUILD} ]]; then
3711        search=$(type -p ${CBUILD}-gcc);
3712        search=${search##*/};
3713    fi;
3714    search=${search:-gcc};
3715    export BUILD_CC=${search};
3716    echo "${search}"
3717}
3718tc-getCC ()
3719{
3720    tc-getPROG CC gcc "$@"
3721}
3722tc-getCPP ()
3723{
3724    tc-getPROG CPP cpp "$@"
3725}
3726tc-getCXX ()
3727{
3728    tc-getPROG CXX g++ "$@"
3729}
3730tc-getDLLWRAP ()
3731{
3732    tc-getPROG DLLWRAP dllwrap "$@"
3733}
3734tc-getF77 ()
3735{
3736    tc-getPROG F77 f77 "$@"
3737}
3738tc-getFC ()
3739{
3740    tc-getPROG FC gfortran "$@"
3741}
3742tc-getGCJ ()
3743{
3744    tc-getPROG GCJ gcj "$@"
3745}
3746tc-getLD ()
3747{
3748    tc-getPROG LD ld "$@"
3749}
3750tc-getNM ()
3751{
3752    tc-getPROG NM nm "$@"
3753}
3754tc-getOBJCOPY ()
3755{
3756    tc-getPROG OBJCOPY objcopy "$@"
3757}
3758tc-getPKG_CONFIG ()
3759{
3760    tc-getPROG PKG_CONFIG pkg-config "$@"
3761}
3762tc-getPROG ()
3763{
3764    local var=$1;
3765    local prog=$2;
3766    if [[ -n ${!var} ]]; then
3767        echo "${!var}";
3768        return 0;
3769    fi;
3770    local search=;
3771    [[ -n $3 ]] && search=$(type -p "$3-${prog}");
3772    [[ -z ${search} && -n ${CHOST} ]] && search=$(type -p "${CHOST}-${prog}");
3773    [[ -n ${search} ]] && prog=${search##*/};
3774    export ${var}=${prog};
3775    echo "${!var}"
3776}
3777tc-getRANLIB ()
3778{
3779    tc-getPROG RANLIB ranlib "$@"
3780}
3781tc-getRC ()
3782{
3783    tc-getPROG RC windres "$@"
3784}
3785tc-getSTRIP ()
3786{
3787    tc-getPROG STRIP strip "$@"
3788}
3789tc-has-tls ()
3790{
3791    local base="${T}/test-tc-tls";
3792    cat > "${base}.c"  <<-EOF
3793int foo(int *i) {
3794static __thread int j = 0;
3795return *i ? j : *i;
3796}
3797EOF
3798
3799    local flags;
3800    case $1 in
3801        -s)
3802            flags="-S"
3803        ;;
3804        -c)
3805            flags="-c"
3806        ;;
3807        -l)
3808
3809        ;;
3810        -*)
3811            die "Usage: tc-has-tls [-c|-l] [toolchain prefix]"
3812        ;;
3813    esac;
3814    : ${flags:=-fPIC -shared -Wl,-z,defs};
3815    [[ $1 == -* ]] && shift;
3816    $(tc-getCC "$@") ${flags} "${base}.c" -o "${base}" &>/dev/null;
3817    local ret=$?;
3818    rm -f "${base}"*;
3819    return ${ret}
3820}
3821tc-is-cross-compiler ()
3822{
3823    return $([[ ${CBUILD:-${CHOST}} != ${CHOST} ]])
3824}
3825tc-is-hardfloat ()
3826{
3827    [[ ${CTARGET//_/-} == *-hardfloat-* ]] && echo "yes" || echo "no"
3828}
3829tc-is-softfloat ()
3830{
3831    case ${CTARGET} in
3832        bfin* | h8300*)
3833            echo "only"
3834        ;;
3835        *)
3836            [[ ${CTARGET//_/-} == *-softfloat-* ]] && echo "yes" || echo "no"
3837        ;;
3838    esac
3839}
3840tc-is-static-only ()
3841{
3842    local host=${CTARGET:-${CHOST}};
3843    return $([[ ${host} == *-mint* ]])
3844}
3845tc-ninja_magic_to_arch ()
3846{
3847    function ninj ()
3848    {
3849        [[ ${type} == "kern" ]] && echo $1 || echo $2
3850    };
3851    local type=$1;
3852    local host=$2;
3853    [[ -z ${host} ]] && host=${CTARGET:-${CHOST}};
3854    case ${host} in
3855        alpha*)
3856            echo alpha
3857        ;;
3858        arm*)
3859            echo arm
3860        ;;
3861        avr*)
3862            ninj avr32 avr
3863        ;;
3864        bfin*)
3865            ninj blackfin bfin
3866        ;;
3867        cris*)
3868            echo cris
3869        ;;
3870        hppa*)
3871            ninj parisc hppa
3872        ;;
3873        i?86*)
3874            if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -lt $(KV_to_int 2.6.24) || ${host} == *freebsd* ]]; then
3875                echo i386;
3876            else
3877                echo x86;
3878            fi
3879        ;;
3880        ia64*)
3881            echo ia64
3882        ;;
3883        m68*)
3884            echo m68k
3885        ;;
3886        mips*)
3887            echo mips
3888        ;;
3889        nios2*)
3890            echo nios2
3891        ;;
3892        nios*)
3893            echo nios
3894        ;;
3895        powerpc*)
3896            if [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]] && [[ ${type} == "kern" ]]; then
3897                echo powerpc;
3898            else
3899                if [[ $(KV_to_int ${KV}) -eq $(KV_to_int 2.6.15) ]] && [[ ${type} == "kern" ]]; then
3900                    if [[ ${host} == powerpc64* ]] || [[ ${PROFILE_ARCH} == "ppc64" ]]; then
3901                        echo powerpc;
3902                    else
3903                        echo ppc;
3904                    fi;
3905                else
3906                    if [[ ${host} == powerpc64* ]]; then
3907                        echo ppc64;
3908                    else
3909                        if [[ ${PROFILE_ARCH} == "ppc64" ]]; then
3910                            ninj ppc64 ppc;
3911                        else
3912                            echo ppc;
3913                        fi;
3914                    fi;
3915                fi;
3916            fi
3917        ;;
3918        s390*)
3919            echo s390
3920        ;;
3921        sh64*)
3922            ninj sh64 sh
3923        ;;
3924        sh*)
3925            echo sh
3926        ;;
3927        sparc64*)
3928            ninj sparc64 sparc
3929        ;;
3930        sparc*)
3931            [[ ${PROFILE_ARCH} == "sparc64" ]] && ninj sparc64 sparc || echo sparc
3932        ;;
3933        vax*)
3934            echo vax
3935        ;;
3936        x86_64*)
3937            if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.24) ]]; then
3938                echo x86;
3939            else
3940                ninj x86_64 amd64;
3941            fi
3942        ;;
3943        *)
3944            echo unknown
3945        ;;
3946    esac
3947}
3948test-flag-CC ()
3949{
3950    test-flag-PROG "CC" "$1"
3951}
3952test-flag-CXX ()
3953{
3954    test-flag-PROG "CXX" "$1"
3955}
3956test-flag-F77 ()
3957{
3958    test-flag-PROG "F77" "$1"
3959}
3960test-flag-FC ()
3961{
3962    test-flag-PROG "FC" "$1"
3963}
3964test-flag-PROG ()
3965{
3966    local comp=$1;
3967    local flags="$2";
3968    [[ -z ${comp} || -z ${flags} ]] && return 1;
3969    local PROG=$(tc-get${comp});
3970    ${PROG} ${flags} -S -o /dev/null -xc /dev/null > /dev/null 2>&1
3971}
3972test-flags ()
3973{
3974    test-flags-CC "$@"
3975}
3976test-flags-CC ()
3977{
3978    test-flags-PROG "CC" "$@"
3979}
3980test-flags-CXX ()
3981{
3982    test-flags-PROG "CXX" "$@"
3983}
3984test-flags-F77 ()
3985{
3986    test-flags-PROG "F77" "$@"
3987}
3988test-flags-FC ()
3989{
3990    test-flags-PROG "FC" "$@"
3991}
3992test-flags-PROG ()
3993{
3994    local comp=$1;
3995    local flags;
3996    local x;
3997    shift;
3998    [[ -z ${comp} ]] && return 1;
3999    x="";
4000    for x in "$@";
4001    do
4002        test-flag-${comp} "${x}" && flags="${flags}${flags:+ }${x}";
4003    done;
4004    echo "${flags}";
4005    [[ -n ${flags} ]]
4006}
4007test_flag ()
4008{
4009    ewarn "test_flag: deprecated, please use test-flags()!" 1>&2;
4010    test-flags-CC "$@"
4011}
4012test_version_info ()
4013{
4014    if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then
4015        return 0;
4016    else
4017        return 1;
4018    fi
4019}
4020treecopy ()
4021{
4022    dest=${!#};
4023    files_count=$#;
4024    while (( $# > 1 )); do
4025        dirstruct=$(dirname "$1");
4026        mkdir -p "${dest}/${dirstruct}";
4027        cp -pPR "$1" "${dest}/${dirstruct}";
4028        shift;
4029    done
4030}
4031uclibctoolize ()
4032{
4033    ewarn "uclibctoolize() is deprecated, please just use elibtoolize()!";
4034    elibtoolize
4035}
4036unpack_makeself ()
4037{
4038    local src_input=${1:-${A}};
4039    local src=$(find_unpackable_file "${src_input}");
4040    local skip=$2;
4041    local exe=$3;
4042    [[ -z ${src} ]] && die "Could not locate source for '${src_input}'";
4043    local shrtsrc=$(basename "${src}");
4044    echo ">>> Unpacking ${shrtsrc} to ${PWD}";
4045    if [[ -z ${skip} ]]; then
4046        local ver=$(grep -m1 -a '#.*Makeself' "${src}" | awk '{print $NF}');
4047        local skip=0;
4048        exe=tail;
4049        case ${ver} in
4050            1.5.* | 1.6.0-nv)
4051                skip=$(grep -a ^skip= "${src}" | cut -d= -f2)
4052            ;;
4053            2.0 | 2.0.1)
4054                skip=$(grep -a ^'       'tail "${src}" | awk '{print $2}' | cut -b2-)
4055            ;;
4056            2.1.1)
4057                skip=$(grep -a ^offset= "${src}" | awk '{print $2}' | cut -b2-);
4058                let skip="skip + 1"
4059            ;;
4060            2.1.2)
4061                skip=$(grep -a ^offset= "${src}" | awk '{print $3}' | head -n 1);
4062                let skip="skip + 1"
4063            ;;
4064            2.1.3)
4065                skip=`grep -a ^offset= "${src}" | awk '{print $3}'`;
4066                let skip="skip + 1"
4067            ;;
4068            2.1.4 | 2.1.5)
4069                skip=$(grep -a offset=.*head.*wc "${src}" | awk '{print $3}' | head -n 1);
4070                skip=$(head -n ${skip} "${src}" | wc -c);
4071                exe="dd"
4072            ;;
4073            *)
4074                eerror "I'm sorry, but I was unable to support the Makeself file.";
4075                eerror "The version I detected was '${ver}'.";
4076                eerror "Please file a bug about the file ${shrtsrc} at";
4077                eerror "http://bugs.gentoo.org/ so that support can be added.";
4078                die "makeself version '${ver}' not supported"
4079            ;;
4080        esac;
4081        debug-print "Detected Makeself version ${ver} ... using ${skip} as offset";
4082    fi;
4083    case ${exe} in
4084        tail)
4085            exe="tail -n +${skip} '${src}'"
4086        ;;
4087        dd)
4088            exe="dd ibs=${skip} skip=1 obs=1024 conv=sync if='${src}'"
4089        ;;
4090        *)
4091            die "makeself cant handle exe '${exe}'"
4092        ;;
4093    esac;
4094    local tmpfile=$(emktemp);
4095    eval ${exe} 2> /dev/null | head -c 512 > "${tmpfile}";
4096    local filetype=$(file -b "${tmpfile}");
4097    case ${filetype} in
4098        *tar\ archive*)
4099            eval ${exe} | tar --no-same-owner -xf -
4100        ;;
4101        bzip2*)
4102            eval ${exe} | bzip2 -dc | tar --no-same-owner -xf -
4103        ;;
4104        gzip*)
4105            eval ${exe} | tar --no-same-owner -xzf -
4106        ;;
4107        compress*)
4108            eval ${exe} | gunzip | tar --no-same-owner -xf -
4109        ;;
4110        *)
4111            eerror "Unknown filetype \"${filetype}\" ?";
4112            false
4113        ;;
4114    esac;
4115    assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})"
4116}
4117unpack_pdv ()
4118{
4119    local src=$(find_unpackable_file "$1");
4120    local sizeoff_t=$2;
4121    [[ -z ${src} ]] && die "Could not locate source for '$1'";
4122    [[ -z ${sizeoff_t} ]] && die "No idea what off_t size was used for this pdv :(";
4123    local shrtsrc=$(basename "${src}");
4124    echo ">>> Unpacking ${shrtsrc} to ${PWD}";
4125    local metaskip=$(tail -c ${sizeoff_t} "${src}" | hexdump -e \"%i\");
4126    local tailskip=$(tail -c $((${sizeoff_t}*2)) "${src}" | head -c ${sizeoff_t} | hexdump -e \"%i\");
4127    local metafile=$(emktemp);
4128    tail -c +$((${metaskip}+1)) "${src}" > "${metafile}";
4129    local datafile=$(tail -c +$((${metaskip}+1)) "${src}" | strings | head -n 1);
4130    datafile=$(basename "${datafile}");
4131    local tmpfile=$(emktemp);
4132    tail -c +$((${tailskip}+1)) ${src} 2> /dev/null | head -c 512 > ${tmpfile};
4133    local iscompressed=$(file -b "${tmpfile}");
4134    if [[ ${iscompressed:0:8} == "compress" ]]; then
4135        iscompressed=1;
4136        mv ${tmpfile}{,.Z};
4137        gunzip ${tmpfile};
4138    else
4139        iscompressed=0;
4140    fi;
4141    local istar=$(file -b "${tmpfile}");
4142    if [[ ${istar:0:9} == "POSIX tar" ]]; then
4143        istar=1;
4144    else
4145        istar=0;
4146    fi;
4147    if [ ${iscompressed} -eq 1 ]; then
4148        if [ ${istar} -eq 1 ]; then
4149            tail -c +$((${tailskip}+1)) ${src} 2> /dev/null | head -c $((${metaskip}-${tailskip})) | tar -xzf -;
4150        else
4151            tail -c +$((${tailskip}+1)) ${src} 2> /dev/null | head -c $((${metaskip}-${tailskip})) | gzip -dc > ${datafile};
4152        fi;
4153    else
4154        if [ ${istar} -eq 1 ]; then
4155            tail -c +$((${tailskip}+1)) ${src} 2> /dev/null | head -c $((${metaskip}-${tailskip})) | tar --no-same-owner -xf -;
4156        else
4157            tail -c +$((${tailskip}+1)) ${src} 2> /dev/null | head -c $((${metaskip}-${tailskip})) > ${datafile};
4158        fi;
4159    fi;
4160    true
4161}
4162validate_desktop_entries ()
4163{
4164    if [[ -x /usr/bin/desktop-file-validate ]]; then
4165        einfo "Checking desktop entry validity";
4166        local directories="";
4167        for d in /usr/share/applications $@;
4168        do
4169            [[ -d ${D}${d} ]] && directories="${directories} ${D}${d}";
4170        done;
4171        if [[ -n ${directories} ]]; then
4172            for FILE in $(find ${directories} -name "*\.desktop"                                                        -not -path '*.hidden*' | sort -u 2>/dev/null);
4173            do
4174                local temp=$(desktop-file-validate ${FILE} | grep -v "warning:" |                                                               sed -e "s|error: ||" -e "s|${FILE}:|--|g" );
4175                [[ -n $temp ]] && elog ${temp/--/${FILE/${D}/}:};
4176            done;
4177        fi;
4178        echo "";
4179    else
4180        einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo.";
4181    fi
4182}
4183x-modular_debug_setup ()
4184{
4185    if [[ -n "${DEBUGGABLE}" ]]; then
4186        if use debug; then
4187            strip-flags;
4188            append-flags -g;
4189        fi;
4190    fi
4191}
4192x-modular_dri_check ()
4193{
4194    if [[ -n "${DRIVER}" ]]; then
4195        if has dri ${IUSE} && use dri; then
4196            einfo "Checking for direct rendering capabilities ...";
4197            if has_version '>=x11-base/xorg-server-1.5.3'; then
4198                if built_with_use x11-base/xorg-server minimal; then
4199                    die "You must build x11-base/xorg-server with USE=-minimal.";
4200                fi;
4201            else
4202                if ! built_with_use x11-base/xorg-server dri; then
4203                    die "You must build x11-base/xorg-server with USE=dri.";
4204                fi;
4205            fi;
4206        fi;
4207    fi
4208}
4209x-modular_font_configure ()
4210{
4211    if [[ -n "${FONT}" ]]; then
4212        if has nls ${IUSE//+} && ! use nls; then
4213            FONT_OPTIONS="${FONT_OPTIONS}
4214                                --disable-iso8859-2
4215                                --disable-iso8859-3
4216                                --disable-iso8859-4
4217                                --disable-iso8859-5
4218                                --disable-iso8859-6
4219                                --disable-iso8859-7
4220                                --disable-iso8859-8
4221                                --disable-iso8859-9
4222                                --disable-iso8859-10
4223                                --disable-iso8859-11
4224                                --disable-iso8859-12
4225                                --disable-iso8859-13
4226                                --disable-iso8859-14
4227                                --disable-iso8859-15
4228                                --disable-iso8859-16
4229                                --disable-jisx0201
4230                                --disable-koi8-r";
4231        fi;
4232    fi
4233}
4234x-modular_patch_source ()
4235{
4236    if [[ -z "${EPATCH_SUFFIX}" ]]; then
4237        EPATCH_SUFFIX="patch";
4238    fi;
4239    if [[ ${#PATCHES[@]} -gt 1 ]]; then
4240        for x in "${PATCHES[@]}";
4241        do
4242            epatch "${x}";
4243        done;
4244    else
4245        if [[ -n "${PATCHES}" ]]; then
4246            for x in ${PATCHES};
4247            do
4248                epatch "${x}";
4249            done;
4250        else
4251            if [[ -n "${PATCH_LOC}" ]]; then
4252                epatch ${PATCH_LOC};
4253            else
4254                if [[ -d "${EPATCH_SOURCE}" ]]; then
4255                    epatch;
4256                fi;
4257            fi;
4258        fi;
4259    fi
4260}
4261x-modular_pkg_postinst ()
4262{
4263    if [[ -n "${FONT}" ]]; then
4264        setup_fonts;
4265    fi
4266}
4267x-modular_pkg_postrm ()
4268{
4269    if [[ -n "${FONT}" ]]; then
4270        cleanup_fonts;
4271        font_pkg_postrm;
4272    fi
4273}
4274x-modular_pkg_preinst ()
4275{
4276    :
4277}
4278x-modular_reconf_source ()
4279{
4280    if [[ "${SNAPSHOT}" = "yes" ]]; then
4281        if [ -f "./configure.ac" ]; then
4282            eautoreconf;
4283        fi;
4284    fi;
4285    elibtoolize
4286}
4287x-modular_server_supports_drivers_check ()
4288{
4289    if [[ -n "${DRIVER}" ]]; then
4290        if has_version '>=x11-base/xorg-server-1.1'; then
4291            if ! built_with_use x11-base/xorg-server xorg; then
4292                eerror "x11-base/xorg-server is not built with support for external drivers.";
4293                die "You must build x11-base/xorg-server with USE=xorg.";
4294            fi;
4295        fi;
4296    fi
4297}
4298x-modular_specs_check ()
4299{
4300    if [[ ${PN:0:11} = "xorg-server" ]] || [[ -n "${DRIVER}" ]]; then
4301        append-ldflags -Wl,-z,lazy;
4302        filter-ldflags -Wl,-z,now;
4303    fi
4304}
4305x-modular_src_compile ()
4306{
4307    has src_configure ${EXPORTED_FUNCTIONS} || x-modular_src_configure;
4308    x-modular_src_make
4309}
4310x-modular_src_configure ()
4311{
4312    x-modular_font_configure;
4313    x-modular_debug_setup;
4314    if [[ -x ${ECONF_SOURCE:-.}/configure ]]; then
4315        econf --prefix=${XDIR} --datadir=${XDIR}/share ${FONT_OPTIONS} ${DRIVER_OPTIONS} ${CONFIGURE_OPTIONS};
4316    fi
4317}
4318x-modular_src_install ()
4319{
4320    if [[ ${CATEGORY} = x11-proto ]]; then
4321        make ${PN/proto/}docdir=/usr/share/doc/${PF} DESTDIR="${D}" install || die;
4322    else
4323        make docdir=/usr/share/doc/${PF} DESTDIR="${D}" install || die;
4324    fi;
4325    if [[ -n ${GIT_ECLASS} ]]; then
4326        pushd "${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}";
4327        git log ${GIT_TREE} > "${S}"/ChangeLog;
4328        popd;
4329    fi;
4330    if [[ -e ${S}/ChangeLog ]]; then
4331        dodoc "${S}"/ChangeLog;
4332    fi;
4333    [[ -n ${DOCS} ]] && dodoc ${DOCS};
4334    if [[ -e ${D}/usr/$(get_libdir)/xorg/modules ]]; then
4335        find "${D}"/usr/$(get_libdir)/xorg/modules -name '*.la' | xargs rm -f;
4336    fi;
4337    if [[ -n "${FONT}" ]]; then
4338        remove_font_metadata;
4339    fi;
4340    if [[ -n "${DRIVER}" ]]; then
4341        install_driver_hwdata;
4342    fi
4343}
4344x-modular_src_make ()
4345{
4346    emake || die "emake failed"
4347}
4348x-modular_src_prepare ()
4349{
4350    [[ -n ${GIT_ECLASS} ]] && has src_prepare ${EXPORTED_FUNCTIONS} && git_src_prepare;
4351    x-modular_patch_source;
4352    x-modular_reconf_source
4353}
4354x-modular_src_unpack ()
4355{
4356    x-modular_specs_check;
4357    x-modular_server_supports_drivers_check;
4358    x-modular_dri_check;
4359    x-modular_unpack_source;
4360    has src_prepare ${EXPORTED_FUNCTIONS} || x-modular_src_prepare
4361}
4362x-modular_unpack_source ()
4363{
4364    if [[ -n ${GIT_ECLASS} ]]; then
4365        git_src_unpack;
4366    else
4367        unpack ${A};
4368    fi;
4369    cd "${S}";
4370    if [[ -n ${FONT_OPTIONS} ]]; then
4371        einfo "Detected font directory: ${FONT_DIR}";
4372    fi
4373}