Advertisement
Guest User

environement

a guest
Feb 18th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 130.67 KB | None | 0 0
  1. declare -x ABI="amd64"
  2. declare -a ALL_AUTOTOOLS_MACROS='([0]="AC_PROG_LIBTOOL" [1]="AM_PROG_LIBTOOL" [2]="LT_INIT" [3]="AC_CONFIG_HEADERS" [4]="AC_CONFIG_SUBDIRS" [5]="AC_CONFIG_AUX_DIR" [6]="AC_CONFIG_MACRO_DIR" [7]="AM_INIT_AUTOMAKE" [8]="AM_GLIB_GNU_GETTEXT" [9]="AM_GNU_GETTEXT_VERSION" [10]="AC_PROG_INTLTOOL" [11]="IT_PROG_INTLTOOL" [12]="GTK_DOC_CHECK" [13]="GNOME_DOC_INIT")'
  3. declare -x ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci"
  4. declare -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"
  5. declare -x ANT_HOME="/usr/share/ant"
  6. declare -x APACHE2_MODULES="authn_core authz_core socache_shmcb unixd 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 cgi cgid 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"
  7. declare -x ARCH="amd64"
  8. declare -- AT_M4DIR=""
  9. declare -- AT_SYS_M4DIR=""
  10. declare -- AUTOTOOLS_AUTO_DEPEND="yes"
  11. declare -- AUTOTOOLS_BUILD_DIR="/var/tmp/portage/x11-misc/xkeyboard-config-2.8/work/xkeyboard-config-2.8_build"
  12. declare -- AUTOTOOLS_DEPEND="|| ( >=sys-devel/automake-1.11.1:1.11 >=sys-devel/automake-1.12:1.12  ) >=sys-devel/autoconf-2.68 sys-devel/libtool"
  13. declare -x BOOTSTRAP_USE="cxx unicode multilib"
  14. declare -- BUILD_DIR="/var/tmp/portage/x11-misc/xkeyboard-config-2.8/work/xkeyboard-config-2.8_build"
  15. declare -x CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump"
  16. declare -x CAMERAS="ptp2"
  17. declare -x CBUILD="x86_64-pc-linux-gnu"
  18. declare -x CFLAGS="-march=native -O2 -pipe"
  19. declare -x CFLAGS_amd64="-m64"
  20. declare -x CFLAGS_default
  21. declare -x CFLAGS_x32="-mx32"
  22. declare -x CFLAGS_x86="-m32"
  23. declare -x CHOST="x86_64-pc-linux-gnu"
  24. declare -x CHOST_amd64="x86_64-pc-linux-gnu"
  25. declare -x CHOST_default="x86_64-pc-linux-gnu"
  26. declare -x CHOST_x32="x86_64-pc-linux-gnux32"
  27. declare -x CHOST_x86="i686-pc-linux-gnu"
  28. declare -x COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog"
  29. declare -x CONF_PREFIX="/usr"
  30. declare -x CTARGET_default="x86_64-pc-linux-gnu"
  31. declare -x CXXFLAGS="-march=native -O2 -pipe"
  32. declare -x DEFAULT_ABI="amd64"
  33. declare -x DEFINED_PHASES=" compile configure install postinst postrm prepare test unpack"
  34. declare DEPEND=">=x11-apps/xkbcomp-1.2.3
  35.     >=x11-libs/libX11-1.4.3
  36.     dev-util/intltool
  37.     >=x11-proto/xproto-7.0.20 || ( >=sys-devel/automake-1.11.1:1.11 >=sys-devel/automake-1.12:1.12  ) >=sys-devel/autoconf-2.68 sys-devel/libtool   x86-interix? (
  38.     >=sys-devel/libtool-2.2.6a
  39.     sys-devel/m4 >=x11-misc/util-macros-1.17 >=media-fonts/font-util-1.2.0 ) ppc-aix? (
  40.     >=sys-devel/libtool-2.2.6a
  41.     sys-devel/m4 >=x11-misc/util-macros-1.17 >=media-fonts/font-util-1.2.0 ) x86-winnt? (
  42.     >=sys-devel/libtool-2.2.6a
  43.     sys-devel/m4 >=x11-misc/util-macros-1.17 >=media-fonts/font-util-1.2.0 ) virtual/pkgconfig "
  44. declare DESCRIPTION="X keyboard configuration database"
  45. declare -x DESTTREE="/usr"
  46. declare -x DIROPTIONS="-m0755"
  47. declare -- DRI_COMMON_DEPEND="
  48.     x11-base/xorg-server[-minimal]
  49.     x11-libs/libdrm
  50. "
  51. declare -x EAPI="5"
  52. declare -- ECLASSDIR_LOCAL="/usr/portage/eclass"
  53. declare -- ECONF_SOURCE="/var/tmp/portage/x11-misc/xkeyboard-config-2.8/work/xkeyboard-config-2.8"
  54. declare -- EGIT_REPO_URI="git://anongit.freedesktop.org/git/xkeyboard-config"
  55. declare -x ELIBC="glibc"
  56. declare -- EPATCH_COMMON_OPTS="-g0 -E --no-backup-if-mismatch"
  57. declare -- EPATCH_EXCLUDE=""
  58. declare -- EPATCH_FORCE="no"
  59. declare -- EPATCH_MULTI_MSG="Applying various patches (bugfixes/updates) ..."
  60. declare -- EPATCH_OPTS=""
  61. declare -- EPATCH_SINGLE_MSG=""
  62. declare -- EPATCH_SOURCE="/var/tmp/portage/x11-misc/xkeyboard-config-2.8/work/patch"
  63. declare -- EPATCH_SUFFIX="patch.bz2"
  64. declare -x EXEOPTIONS="-m0755"
  65. declare -- EXPORTED_FUNCTIONS="src_unpack src_compile src_install pkg_postinst pkg_postrm src_prepare src_configure"
  66. declare -x FCFLAGS="-O2 -pipe"
  67. declare -x FETCHCOMMAND_SSH="bash -c \"x=\\\${2#ssh://} ; host=\\\${x%%/*} ; port=\\\${host##*:} ; host=\\\${host%:*} ; [[ \\\${host} = \\\${port} ]] && port=22 ; exec rsync --rsh=\\\"ssh -p\\\${port}\\\" -avP \\\"\\\${host}:/\\\${x#*/}\\\" \\\"\\\$1\\\"\" rsync \"\${DISTDIR}/\${FILE}\" \"\${URI}\""
  68. declare -x FFLAGS="-O2 -pipe"
  69. declare -- FONT_ECLASS=""
  70. declare -x GCC_SPECS=""
  71. declare -x GDK_USE_XFT="1"
  72. declare -- GIT_ECLASS=""
  73. declare -x GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx"
  74. declare -x GRUB_PLATFORMS=""
  75. declare -x GSETTINGS_BACKEND="gconf"
  76. declare -x GUILE_LOAD_PATH="/usr/share/guile/1.8"
  77. declare HDEPEND=""
  78. declare -x HG="/usr/bin/hg"
  79. declare HOMEPAGE="http://www.freedesktop.org/wiki/Software/XKeyboardConfig"
  80. declare -x HUSHLOGIN="FALSE"
  81. declare -x INHERITED=" multilib toolchain-funcs libtool multiprocessing autotools user eutils autotools-utils flag-o-matic xorg-2"
  82. declare -x INPUT_DEVICES="evdev synaptics"
  83. declare -x INSDESTTREE=""
  84. declare -x INSOPTIONS="-m0644"
  85. declare IUSE=""
  86. declare -x IUSE_EFFECTIVE="alpha amd64 amd64-fbsd amd64-linux arm arm-linux elibc_AIX elibc_Cygwin elibc_Darwin elibc_FreeBSD elibc_HPUX elibc_Interix elibc_NetBSD elibc_OpenBSD elibc_SunOS elibc_Winnt elibc_glibc elibc_mintlib elibc_uclibc hppa hppa-hpux ia64 ia64-hpux ia64-linux kernel_AIX kernel_Cygwin kernel_Darwin kernel_FreeBSD kernel_HPUX kernel_Interix kernel_NetBSD kernel_OpenBSD kernel_SunOS kernel_Winnt kernel_freemint kernel_linux m68k m68k-mint mips ppc ppc-aix ppc-macos ppc-openbsd ppc64 ppc64-linux prefix s390 sh sparc sparc-fbsd sparc-solaris sparc64-freebsd sparc64-solaris userland_BSD userland_GNU x64-freebsd x64-macos x64-openbsd x64-solaris x86 x86-cygwin x86-fbsd x86-freebsd x86-interix x86-linux x86-macos x86-netbsd x86-openbsd x86-solaris x86-winnt"
  87. declare -x IUSE_IMPLICIT="prefix"
  88. declare -x JAVAC="/etc/java-config-2/current-system-vm/bin/javac"
  89. declare -x JAVACC_HOME="/usr/share/javacc/"
  90. declare -x JAVA_HOME="/etc/java-config-2/current-system-vm"
  91. declare -x JDK_HOME="/etc/java-config-2/current-system-vm"
  92. declare -x KERNEL="linux"
  93. declare -x KERNEL_ABI="amd64"
  94. declare -x KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-fbsd ~x86-fbsd ~x86-interix ~amd64-linux ~x86-linux ~ppc-macos ~x86-macos ~sparc-solaris ~x86-solaris"
  95. declare -x LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text"
  96. declare -x LC_CTYPE=""
  97. declare -x LDFLAGS="-Wl,-O1 -Wl,--as-needed"
  98. declare -x LDFLAGS_amd64="-m elf_x86_64"
  99. declare -x LDFLAGS_default
  100. declare -x LDFLAGS_x32="-m elf32_x86_64"
  101. declare -x LDFLAGS_x86="-m elf_i386"
  102. declare -x LIBDIR_amd64="lib64"
  103. declare -x LIBDIR_amd64_fbsd="lib64"
  104. declare -x LIBDIR_default="lib"
  105. declare -x LIBDIR_n32="lib32"
  106. declare -x LIBDIR_n64="lib64"
  107. declare -x LIBDIR_o32="lib"
  108. declare -x LIBDIR_ppc="lib32"
  109. declare -x LIBDIR_ppc64="lib64"
  110. declare -x LIBDIR_s390="lib32"
  111. declare -x LIBDIR_s390x="lib64"
  112. declare -x LIBDIR_sparc32="lib32"
  113. declare -x LIBDIR_sparc64="lib64"
  114. declare -x LIBDIR_x32="libx32"
  115. declare -x LIBDIR_x86="lib32"
  116. declare -x LIBDIR_x86_fbsd="lib32"
  117. declare -x LIBOPTIONS="-m0644"
  118. declare -x LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer"
  119. declare -x LICENSE="MIT"
  120. declare -x LSCOLORS="Gxfxcxdxbxegedabagacad"
  121. declare -x MAIL="/var/mail/root"
  122. declare -x MAKEOPTS="-j5"
  123. declare -x MULTILIB_ABIS="amd64 x86"
  124. declare -x MULTILIB_STRICT_DENY="64-bit.*shared object"
  125. declare -x MULTILIB_STRICT_DIRS="/lib32 /lib /usr/lib32 /usr/lib /usr/kde/*/lib32 /usr/kde/*/lib /usr/qt/*/lib32 /usr/qt/*/lib /usr/X11R6/lib32 /usr/X11R6/lib"
  126. declare -x MULTILIB_STRICT_EXEMPT="(perl5|gcc|gcc-lib|binutils|eclipse-3|debug|portage|udev)"
  127. declare -x NETBEANS="apisupport cnd groovy gsf harness ide identity j2ee java mobility nb php profiler soa visualweb webcommon websvccommon xml"
  128. declare -x OPENCL_PROFILE="nvidia"
  129. declare -x OPENGL_PROFILE="xorg-x11"
  130. declare -x PATH="/usr/lib64/portage/bin/ebuild-helpers:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.6.3"
  131. declare PDEPEND=""
  132. declare -x PHP_TARGETS="php5-3"
  133. declare -x PKG_CONFIG_PATH="/usr/lib64/pkgconfig"
  134. declare -a PORTAGE_DOCOMPRESS='([0]="/usr/share/doc" [1]="/usr/share/info" [2]="/usr/share/man")'
  135. declare -a PORTAGE_DOCOMPRESS_SKIP='([0]="/usr/share/doc/xkeyboard-config-2.8/html")'
  136. declare -x PRELINK_PATH_MASK="/usr/lib64/libfreebl3.so:/usr/lib64/libnssdbm3.so:/usr/lib64/libsoftokn3.so"
  137. declare -x PROFILE_ONLY_VARIABLES="ARCH ELIBC IUSE_IMPLICIT KERNEL USERLAND USE_EXPAND_IMPLICIT USE_EXPAND_UNPREFIXED USE_EXPAND_VALUES_ARCH USE_EXPAND_VALUES_ELIBC USE_EXPAND_VALUES_KERNEL USE_EXPAND_VALUES_USERLAND"
  138. declare -x PROPERTIES=""
  139. declare -x PROVIDE=""
  140. declare -x PYTHONDONTWRITEBYTECODE="1"
  141. declare -x PYTHONPATH="/usr/lib/portage/pym"
  142. declare -x PYTHON_SINGLE_TARGET="python2_7"
  143. declare -x PYTHON_TARGETS="python2_7 python3_2"
  144. declare -x QT_GRAPHICSSYSTEM="raster"
  145. declare -x QT_PLUGIN_PATH="/usr/lib64/kde4/plugins"
  146. declare RDEPEND=">=x11-apps/xkbcomp-1.2.3
  147.     >=x11-libs/libX11-1.4.3  "
  148. declare REPOSITORY
  149. declare REQUIRED_USE=""
  150. declare -x RESTRICT=""
  151. declare -x RESUMECOMMAND_SSH="bash -c \"x=\\\${2#ssh://} ; host=\\\${x%%/*} ; port=\\\${host##*:} ; host=\\\${host%:*} ; [[ \\\${host} = \\\${port} ]] && port=22 ; exec rsync --rsh=\\\"ssh -p\\\${port}\\\" -avP \\\"\\\${host}:/\\\${x#*/}\\\" \\\"\\\$1\\\"\" rsync \"\${DISTDIR}/\${FILE}\" \"\${URI}\""
  152. declare -x RUBYOPT="-rauto_gem"
  153. declare -x RUBY_TARGETS="ruby18 ruby19"
  154. declare -x S="/var/tmp/portage/x11-misc/xkeyboard-config-2.8/work/xkeyboard-config-2.8"
  155. declare -x SANDBOX_DEBUG="0"
  156. declare -x SANDBOX_DENY=""
  157. declare -x SANDBOX_PID="3197"
  158. declare -x SANDBOX_PREDICT="/var/tmp/portage/x11-misc/xkeyboard-config-2.8/homedir:/dev/crypto:/proc/self/coredump_filter:/dev/random:/proc/self/coredump_filter:/dev/random:/proc/self/coredump_filter:/var/cache/fontconfig"
  159. declare -x SANDBOX_READ="/:/var/tmp"
  160. declare -x SANDBOX_VERBOSE="1"
  161. declare -x SANDBOX_WRITE=":/dev/console:/dev/fd:/dev/full:/dev/null:/dev/pts/:/dev/pty:/dev/shm:/dev/tts:/dev/tty:/dev/vc/:/dev/zero:/proc/self/fd:/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-misc/xkeyboard-config-2.8/homedir/.bash_history"
  162. declare -x SLOT="0"
  163. declare SRC_URI="http://xorg.freedesktop.org/releases/individual/data/xkeyboard-config/xkeyboard-config-2.8.tar.bz2"
  164. declare -x SYMLINK_LIB="yes"
  165. declare -x USE="amd64 elibc_glibc kernel_linux userland_GNU"
  166. declare -x USERLAND="GNU"
  167. declare -x USE_EXPAND_IMPLICIT="ARCH ELIBC KERNEL USERLAND"
  168. declare -x USE_EXPAND_UNPREFIXED="ARCH"
  169. declare -x USE_EXPAND_VALUES_ARCH="alpha amd64 amd64-fbsd amd64-linux arm arm-linux hppa hppa-hpux ia64 ia64-hpux ia64-linux m68k m68k-mint mips ppc ppc64 ppc64-linux ppc-aix ppc-macos ppc-openbsd s390 sh sparc sparc64-freebsd sparc64-solaris sparc-fbsd sparc-solaris x64-freebsd x64-macos x64-openbsd x64-solaris x86 x86-cygwin x86-fbsd x86-freebsd x86-interix x86-linux x86-macos x86-netbsd x86-openbsd x86-solaris x86-winnt"
  170. declare -x USE_EXPAND_VALUES_ELIBC="AIX Cygwin Darwin FreeBSD glibc HPUX Interix mintlib NetBSD OpenBSD SunOS uclibc Winnt"
  171. declare -x USE_EXPAND_VALUES_KERNEL="AIX Cygwin Darwin FreeBSD freemint HPUX Interix linux NetBSD OpenBSD SunOS Winnt"
  172. declare -x USE_EXPAND_VALUES_USERLAND="BSD GNU"
  173. declare -x VBOX_APP_HOME="/usr/lib64/virtualbox"
  174. declare -x VIDEO_CARDS="nvidia"
  175. declare -x WANT_AUTOCONF="latest"
  176. declare -x WANT_AUTOMAKE="latest"
  177. declare -x WANT_LIBTOOL="latest"
  178. declare -x XDG_CONFIG_DIRS="/etc/xdg"
  179. declare -x XDG_DATA_DIRS="/usr/local/share:/usr/share"
  180. declare -x XDG_SESSION_COOKIE="24974cad64a72cbf5469ff5750eded8b-1361226108.791472-969995989"
  181. declare -- XORG_BASE_INDIVIDUAL_URI="http://xorg.freedesktop.org/releases/individual"
  182. declare -a XORG_CONFIGURE_OPTIONS='([0]="--with-xkb-base=/usr/share/X11/xkb" [1]="--enable-compat-rules" [2]="--disable-runtime-deps" [3]="--with-xkb-rules-symlink=xorg")'
  183. declare -- XORG_DOC="no"
  184. declare -- XORG_DRI="no"
  185. declare -- XORG_EAUTORECONF="no"
  186. declare -- XORG_EAUTORECONF_ARCHES="x86-interix ppc-aix x86-winnt"
  187. declare -- XORG_MODULE="util/"
  188. declare -- XORG_MODULE_REBUILD="no"
  189. declare -- XORG_PACKAGE_NAME="xkeyboard-config"
  190. declare -- XORG_STATIC="no"
  191. declare -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"
  192. declare -x _E_DOCDESTTREE_=""
  193. declare -x _E_EXEDESTTREE_=""
  194. declare -a _LATEST_AUTOMAKE='([0]="1.11.1:1.11" [1]="1.12:1.12")'
  195. declare -- ___ECLASS_ONCE_AUTOTOOLS="recur -_+^+_- spank"
  196. declare -- ___ECLASS_ONCE_EUTILS="recur -_+^+_- spank"
  197. declare -- ___ECLASS_ONCE_FLAG_O_MATIC="recur -_+^+_- spank"
  198. declare -- ___ECLASS_ONCE_LIBTOOL="recur -_+^+_- spank"
  199. declare -- ___ECLASS_ONCE_MULTILIB="recur -_+^+_- spank"
  200. declare -- ___ECLASS_ONCE_MULTIPROCESSING="recur -_+^+_- spank"
  201. declare -- ___ECLASS_ONCE_TOOLCHAIN_FUNCS="recur -_+^+_- spank"
  202. declare -- ___ECLASS_ONCE_USER="recur -_+^+_- spank"
  203. declare -- _libtool_atom="sys-devel/libtool"
  204. declare -- arch="x86-winnt"
  205. declare -- phase_func
  206. declare -x vcs_info_msg_0_=""
  207. declare -x vcs_info_msg_1_=""
  208. ELT_libtool_version ()
  209. {
  210.     ( unset VERSION;
  211.     eval $(grep -e '^[[:space:]]*VERSION=' "$1");
  212.     echo "${VERSION:-0}" )
  213. }
  214. ELT_try_and_apply_patch ()
  215. {
  216.     local ret=0;
  217.     local file=$1;
  218.     local patch=$2;
  219.     local src=$3;
  220.     local disp="${src} patch";
  221.     local log="${T}/elibtool.log";
  222.     if [[ -z ${__ELT_NOTED_TMP} ]]; then
  223.         __ELT_NOTED_TMP=true;
  224.         printf 'temp patch: %s\n' "${patch}" > "${log}";
  225.     fi;
  226.     printf '\nTrying %s\n' "${disp}" >> "${log}";
  227.     if patch -p0 --dry-run "${file}" "${patch}" >> "${log}" 2>&1; then
  228.         einfo "  Applying ${disp} ...";
  229.         patch -p0 -g0 --no-backup-if-mismatch "${file}" "${patch}" >> "${log}" 2>&1;
  230.         ret=$?;
  231.         export ELT_APPLIED_PATCHES="${ELT_APPLIED_PATCHES} ${src}";
  232.     else
  233.         ret=1;
  234.     fi;
  235.     return "${ret}"
  236. }
  237. ELT_walk_patches ()
  238. {
  239.     local patch tmp;
  240.     local ret=1;
  241.     local file=$1;
  242.     local patch_set=$2;
  243.     local patch_dir="$(elt_patch_dir)/${patch_set}";
  244.     local rem_int_dep=$3;
  245.     [[ -z ${patch_set} ]] && return 1;
  246.     [[ ! -d ${patch_dir} ]] && return 1;
  247.     local sed_args=(-e "s:@GENTOO_LIBDIR@:$(get_libdir):g");
  248.     if [[ -n ${rem_int_dep} ]]; then
  249.         sed_args+=(-e "s|@REM_INT_DEP@|${rem_int_dep}|g");
  250.     fi;
  251.     pushd "$(elt_patch_dir)" > /dev/null || die;
  252.     for patch in $(find "${patch_set}" -maxdepth 1 -type f | LC_ALL=C sort -r);
  253.     do
  254.         tmp="${T}/libtool-elt.patch";
  255.         sed "${sed_args[@]}" "${patch}" > "${tmp}" || die;
  256.         if ELT_try_and_apply_patch "${file}" "${tmp}" "${patch}"; then
  257.             ret=0;
  258.             break;
  259.         fi;
  260.     done;
  261.     popd > /dev/null;
  262.     return ${ret}
  263. }
  264. VER_major ()
  265. {
  266.     [[ -z $1 ]] && return 1;
  267.     local VER=$@;
  268.     echo "${VER%%[^[:digit:]]*}"
  269. }
  270. VER_micro ()
  271. {
  272.     [[ -z $1 ]] && return 1;
  273.     local VER=$@;
  274.     VER=${VER#*.*.};
  275.     echo "${VER%%[^[:digit:]]*}"
  276. }
  277. VER_minor ()
  278. {
  279.     [[ -z $1 ]] && return 1;
  280.     local VER=$@;
  281.     VER=${VER#*.};
  282.     echo "${VER%%[^[:digit:]]*}"
  283. }
  284. VER_to_int ()
  285. {
  286.     [[ -z $1 ]] && return 1;
  287.     local VER_MAJOR=$(VER_major "$1");
  288.     local VER_MINOR=$(VER_minor "$1");
  289.     local VER_MICRO=$(VER_micro "$1");
  290.     local VER_int=$(( VER_MAJOR * 65536 + VER_MINOR * 256 + VER_MICRO ));
  291.     if [[ ${VER_int} -ge 65536 ]]; then
  292.         echo "${VER_int}";
  293.         return 0;
  294.     fi;
  295.     echo 1;
  296.     return 1
  297. }
  298. _assert_pkg_ebuild_phase ()
  299. {
  300.     case ${EBUILD_PHASE} in
  301.         setup | preinst | postinst)
  302.  
  303.         ;;
  304.         *)
  305.             eerror "'$1()' called from '${EBUILD_PHASE}' phase which is not OK:";
  306.             eerror "You may only call from pkg_{setup,preinst,postinst} functions.";
  307.             eerror "Package fails at QA and at life.  Please file a bug.";
  308.             die "Bad package!  $1 is only for use in some pkg_* functions!"
  309.         ;;
  310.     esac
  311. }
  312. _at_uses_autoheader ()
  313. {
  314.     _at_uses_pkg AC_CONFIG_HEADERS
  315. }
  316. _at_uses_automake ()
  317. {
  318.     _at_uses_pkg AM_INIT_AUTOMAKE
  319. }
  320. _at_uses_gettext ()
  321. {
  322.     _at_uses_pkg AM_GNU_GETTEXT_VERSION
  323. }
  324. _at_uses_glibgettext ()
  325. {
  326.     _at_uses_pkg AM_GLIB_GNU_GETTEXT
  327. }
  328. _at_uses_gnomedoc ()
  329. {
  330.     _at_uses_pkg GNOME_DOC_INIT
  331. }
  332. _at_uses_gtkdoc ()
  333. {
  334.     _at_uses_pkg GTK_DOC_CHECK
  335. }
  336. _at_uses_intltool ()
  337. {
  338.     _at_uses_pkg {AC,IT}_PROG_INTLTOOL
  339. }
  340. _at_uses_libtool ()
  341. {
  342.     _at_uses_pkg A{C,M}_PROG_LIBTOOL LT_INIT
  343. }
  344. _at_uses_pkg ()
  345. {
  346.     if [[ -n $(autotools_check_macro "$@") ]]; then
  347.         return 0;
  348.     else
  349.         local macro args=();
  350.         for macro in "$@";
  351.         do
  352.             args+=(-e "^[[:space:]]*${macro}\>");
  353.         done;
  354.         egrep -q "${args[@]}" configure.??;
  355.     fi
  356. }
  357. _autotools_m4dir_include ()
  358. {
  359.     local x include_opts flag;
  360.     [[ ${WANT_AUTOCONF} == "2.1" ]] && flag="l" || flag="I";
  361.     for x in "$@";
  362.     do
  363.         case ${x} in
  364.             -${flag})
  365.  
  366.             ;;
  367.             *)
  368.                 [[ ! -d ${x} ]] && ewarn "autotools.eclass: '${x}' does not exist";
  369.                 include_opts+=" -${flag} ${x}"
  370.             ;;
  371.         esac;
  372.     done;
  373.     echo ${include_opts}
  374. }
  375. _check_build_dir ()
  376. {
  377.     : ${ECONF_SOURCE:=${S}};
  378.     if [[ -n ${AUTOTOOLS_IN_SOURCE_BUILD} ]]; then
  379.         BUILD_DIR="${ECONF_SOURCE}";
  380.     else
  381.         if [[ ! -n ${BUILD_DIR} && -n ${AUTOTOOLS_BUILD_DIR} ]]; then
  382.             eqawarn "The AUTOTOOLS_BUILD_DIR variable has been renamed to BUILD_DIR.";
  383.             eqawarn "Please migrate the ebuild to use the new one.";
  384.             _RESPECT_AUTOTOOLS_BUILD_DIR=1;
  385.         fi;
  386.         if [[ -n ${_RESPECT_AUTOTOOLS_BUILD_DIR} ]]; then
  387.             BUILD_DIR=${AUTOTOOLS_BUILD_DIR:-${WORKDIR}/${P}_build};
  388.         else
  389.             : ${BUILD_DIR:=${WORKDIR}/${P}_build};
  390.         fi;
  391.     fi;
  392.     AUTOTOOLS_BUILD_DIR=${BUILD_DIR};
  393.     echo ">>> Working in BUILD_DIR: \"${BUILD_DIR}\""
  394. }
  395. _elibtoolize ()
  396. {
  397.     local LIBTOOLIZE=${LIBTOOLIZE:-$(type -P glibtoolize > /dev/null && echo glibtoolize || echo libtoolize)};
  398.     [[ -f GNUmakefile.am || -f Makefile.am ]] && set -- "$@" --automake;
  399.     if [[ $1 == "--install" ]]; then
  400.         ${LIBTOOLIZE} -n --install &>/dev/null || shift;
  401.     fi;
  402.     autotools_run_tool ${LIBTOOLIZE} "$@" ${opts}
  403. }
  404. _filter-hardened ()
  405. {
  406.     local f;
  407.     for f in "$@";
  408.     do
  409.         case "${f}" in
  410.             -fPIC | -fpic | -fPIE | -fpie | -Wl,pie | -pie)
  411.                 gcc-specs-pie || continue;
  412.                 is-flagq -nopie || append-flags -nopie
  413.             ;;
  414.             -fstack-protector)
  415.                 gcc-specs-ssp || continue;
  416.                 is-flagq -fno-stack-protector || append-flags $(test-flags -fno-stack-protector)
  417.             ;;
  418.             -fstack-protector-all)
  419.                 gcc-specs-ssp-to-all || continue;
  420.                 is-flagq -fno-stack-protector-all || append-flags $(test-flags -fno-stack-protector-all)
  421.             ;;
  422.             -fno-strict-overflow)
  423.                 gcc-specs-nostrict || continue;
  424.                 is-flagq -fstrict-overflow || append-flags $(test-flags -fstrict-overflow)
  425.             ;;
  426.         esac;
  427.     done
  428. }
  429. _filter-var ()
  430. {
  431.     local f x var=$1 new=();
  432.     shift;
  433.     for f in ${!var};
  434.     do
  435.         for x in "$@";
  436.         do
  437.             [[ ${f} == ${x} ]] && continue 2;
  438.         done;
  439.         new+=("${f}");
  440.     done;
  441.     eval export ${var}=\""${new[*]}"\"
  442. }
  443. _gcc-install-dir ()
  444. {
  445.     echo "$(LC_ALL=C $(tc-getCC) -print-search-dirs 2> /dev/null |      awk '$1=="install:" {print $2}')"
  446. }
  447. _gcc-specs-directive_raw ()
  448. {
  449.     local cc=$(tc-getCC);
  450.     local specfiles=$(LC_ALL=C ${cc} -v 2>&1 | awk '$1=="Reading" {print $NF}');
  451.     ${cc} -dumpspecs 2> /dev/null | cat - ${specfiles} | awk -v directive=$1 'BEGIN { pspec=""; spec=""; outside=1 }
  452. $1=="*"directive":"  { pspec=spec; spec=""; outside=0; next }
  453.     outside || NF==0 || ( substr($1,1,1)=="*" && substr($1,length($1),1)==":" ) { outside=1; next }
  454.     spec=="" && substr($0,1,1)=="+" { spec=pspec " " substr($0,2); next }
  455.     { spec=spec $0 }
  456. END { print spec }';
  457.     return 0
  458. }
  459. _gcc-specs-exists ()
  460. {
  461.     [[ -f $(_gcc-install-dir)/$1 ]]
  462. }
  463. _gcc_fullversion ()
  464. {
  465.     local ver="$1";
  466.     shift;
  467.     set -- `$(tc-getCPP "$@") -E -P - <<<"__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__"`;
  468.     eval echo "$ver"
  469. }
  470. _iconins ()
  471. {
  472.     ( local funcname=$1;
  473.     shift;
  474.     local size dir;
  475.     local context=apps;
  476.     local theme=hicolor;
  477.     while [[ $# -gt 0 ]]; do
  478.         case $1 in
  479.             -s | --size)
  480.                 if [[ ${2%%x*}x${2%%x*} == "$2" ]]; then
  481.                     size=${2%%x*};
  482.                 else
  483.                     size=${2};
  484.                 fi;
  485.                 case ${size} in
  486.                     16 | 22 | 24 | 32 | 36 | 48 | 64 | 72 | 96 | 128 | 192 | 256)
  487.                         size=${size}x${size}
  488.                     ;;
  489.                     scalable)
  490.  
  491.                     ;;
  492.                     *)
  493.                         eerror "${size} is an unsupported icon size!";
  494.                         exit 1
  495.                     ;;
  496.                 esac;
  497.                 shift 2
  498.             ;;
  499.             -t | --theme)
  500.                 theme=${2};
  501.                 shift 2
  502.             ;;
  503.             -c | --context)
  504.                 context=${2};
  505.                 shift 2
  506.             ;;
  507.             *)
  508.                 if [[ -z ${size} ]]; then
  509.                     insinto /usr/share/pixmaps;
  510.                 else
  511.                     insinto /usr/share/icons/${theme}/${size}/${context};
  512.                 fi;
  513.                 if [[ ${funcname} == doicon ]]; then
  514.                     if [[ -f $1 ]]; then
  515.                         doins "${1}";
  516.                     else
  517.                         if [[ -d $1 ]]; then
  518.                             shopt -s nullglob;
  519.                             doins "${1}"/*.{png,svg};
  520.                             shopt -u nullglob;
  521.                         else
  522.                             eerror "${1} is not a valid file/directory!";
  523.                             exit 1;
  524.                         fi;
  525.                     fi;
  526.                 else
  527.                     break;
  528.                 fi;
  529.                 shift 1
  530.             ;;
  531.         esac;
  532.     done;
  533.     if [[ ${funcname} == newicon ]]; then
  534.         newins "$@";
  535.     fi ) || die
  536. }
  537. _is_flagq ()
  538. {
  539.     local x var;
  540.     eval var=\""\${$1[*]}"\";
  541.     for x in ${var};
  542.     do
  543.         [[ ${x} == $2 ]] && return 0;
  544.     done;
  545.     return 1
  546. }
  547. _multijob_fork ()
  548. {
  549.     [[ $# -eq 1 ]] || die "incorrect number of arguments";
  550.     local ret=0;
  551.     [[ $1 == "post" ]] && : $(( ++mj_num_jobs ));
  552.     if [[ ${mj_num_jobs} -ge ${mj_max_jobs} ]]; then
  553.         multijob_finish_one;
  554.         ret=$?;
  555.     fi;
  556.     [[ $1 == "pre" ]] && : $(( ++mj_num_jobs ));
  557.     return ${ret}
  558. }
  559. _tc-getPROG ()
  560. {
  561.     local tuple=$1;
  562.     local v var vars=$2;
  563.     local prog=$3;
  564.     var=${vars%% *};
  565.     for v in ${vars};
  566.     do
  567.         if [[ -n ${!v} ]]; then
  568.             export ${var}="${!v}";
  569.             echo "${!v}";
  570.             return 0;
  571.         fi;
  572.     done;
  573.     local search=;
  574.     [[ -n $4 ]] && search=$(type -p "$4-${prog}");
  575.     [[ -z ${search} && -n ${!tuple} ]] && search=$(type -p "${!tuple}-${prog}");
  576.     [[ -n ${search} ]] && prog=${search##*/};
  577.     export ${var}=${prog};
  578.     echo "${!var}"
  579. }
  580. all-flag-vars ()
  581. {
  582.     echo {C,CPP,CXX,CCAS,F,FC,LD}FLAGS
  583. }
  584. append-cflags ()
  585. {
  586.     [[ $# -eq 0 ]] && return 0;
  587.     export CFLAGS=$(test-flags-CC ${CFLAGS} "$@");
  588.     return 0
  589. }
  590. append-cppflags ()
  591. {
  592.     [[ $# -eq 0 ]] && return 0;
  593.     export CPPFLAGS="${CPPFLAGS} $*";
  594.     return 0
  595. }
  596. append-cxxflags ()
  597. {
  598.     [[ $# -eq 0 ]] && return 0;
  599.     export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS} "$@");
  600.     return 0
  601. }
  602. append-fflags ()
  603. {
  604.     [[ $# -eq 0 ]] && return 0;
  605.     export FFLAGS=$(test-flags-F77 ${FFLAGS} "$@");
  606.     export FCFLAGS=$(test-flags-FC ${FCFLAGS} "$@");
  607.     return 0
  608. }
  609. append-flags ()
  610. {
  611.     [[ $# -eq 0 ]] && return 0;
  612.     case " $* " in
  613.         *' '-[DIU]*)
  614.             eqawarn 'please use append-cppflags for preprocessor flags'
  615.         ;;
  616.         *' '-L* | *' '-Wl,*)
  617.             eqawarn 'please use append-ldflags for linker flags'
  618.         ;;
  619.     esac;
  620.     append-cflags "$@";
  621.     append-cxxflags "$@";
  622.     append-fflags "$@";
  623.     return 0
  624. }
  625. append-ldflags ()
  626. {
  627.     [[ $# -eq 0 ]] && return 0;
  628.     local flag;
  629.     for flag in "$@";
  630.     do
  631.         [[ ${flag} == -l* ]] && eqawarn "Appending a library link instruction (${flag}); libraries to link to should not be passed through LDFLAGS";
  632.     done;
  633.     export LDFLAGS="${LDFLAGS} $*";
  634.     return 0
  635. }
  636. append-lfs-flags ()
  637. {
  638.     [[ $# -ne 0 ]] && die "append-lfs-flags takes no arguments";
  639.     append-cppflags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
  640. }
  641. append-libs ()
  642. {
  643.     [[ $# -eq 0 ]] && return 0;
  644.     local flag;
  645.     for flag in "$@";
  646.     do
  647.         [[ ${flag} == -l* ]] && flag=${flag#-l};
  648.         export LIBS="${LIBS} -l${flag}";
  649.     done;
  650.     return 0
  651. }
  652. at_checksum ()
  653. {
  654.     find '(' -name 'Makefile.am' -o -name 'configure.ac' -o -name 'configure.in' ')' -exec cksum {} + | sort -k2
  655. }
  656. autotools-utils_autoreconf ()
  657. {
  658.     debug-print-function ${FUNCNAME} "$@";
  659.     eqawarn "The autotools-utils_autoreconf() function was deprecated.";
  660.     eqawarn "Please call autotools-utils_src_prepare()";
  661.     eqawarn "with AUTOTOOLS_AUTORECONF set instead.";
  662.     function autotools_check_macro ()
  663.     {
  664.         local x;
  665.         [[ ${1} = AC_CONFIG_HEADERS ]] && set -- "${@}" AC_CONFIG_HEADER AM_CONFIG_HEADER;
  666.         for x in "$@";
  667.         do
  668.             grep -h "^${x}" configure.{ac,in} 2> /dev/null;
  669.         done
  670.     };
  671.     einfo "Autoreconfiguring '${PWD}' ...";
  672.     local auxdir=$(sed -n -e 's/^AC_CONFIG_AUX_DIR(\(.*\))$/\1/p'           configure.{ac,in} 2>/dev/null);
  673.     if [[ -n ${auxdir} ]]; then
  674.         auxdir=${auxdir%%]};
  675.         mkdir -p ${auxdir##[};
  676.     fi;
  677.     if [[ -n $(autotools_check_macro AM_GLIB_GNU_GETTEXT) ]]; then
  678.         echo 'no' | autotools_run_tool glib-gettextize --copy --force;
  679.     else
  680.         if [[ -n $(autotools_check_macro AM_GNU_GETTEXT) ]]; then
  681.             eautopoint --force;
  682.         fi;
  683.     fi;
  684.     if [[ -n $(autotools_check_macro AC_PROG_INTLTOOL IT_PROG_INTLTOOL) ]]; then
  685.         autotools_run_tool intltoolize --copy --automake --force;
  686.     fi;
  687.     if [[ -n $(autotools_check_macro GTK_DOC_CHECK) ]]; then
  688.         autotools_run_tool gtkdocize --copy;
  689.     fi;
  690.     if [[ -n $(autotools_check_macro GNOME_DOC_INIT) ]]; then
  691.         autotools_run_tool gnome-doc-prepare --copy --force;
  692.     fi;
  693.     if [[ -n $(autotools_check_macro AC_PROG_LIBTOOL AM_PROG_LIBTOOL LT_INIT) ]]; then
  694.         _elibtoolize --copy --force --install;
  695.     fi;
  696.     eaclocal;
  697.     eautoconf;
  698.     eautoheader;
  699.     FROM_EAUTORECONF=sure eautomake;
  700.     local x;
  701.     for x in $(autotools_check_macro_val AC_CONFIG_SUBDIRS);
  702.     do
  703.         if [[ -d ${x} ]]; then
  704.             pushd "${x}" > /dev/null || die;
  705.             autotools-utils_autoreconf;
  706.             popd > /dev/null || die;
  707.         fi;
  708.     done
  709. }
  710. autotools-utils_src_compile ()
  711. {
  712.     debug-print-function ${FUNCNAME} "$@";
  713.     _check_build_dir;
  714.     pushd "${BUILD_DIR}" > /dev/null || die;
  715.     emake "$@" || die 'emake failed';
  716.     popd > /dev/null || die
  717. }
  718. autotools-utils_src_configure ()
  719. {
  720.     debug-print-function ${FUNCNAME} "$@";
  721.     [[ -z ${myeconfargs+1} || $(declare -p myeconfargs) == 'declare -a'* ]] || die 'autotools-utils.eclass: myeconfargs has to be an array.';
  722.     [[ ${EAPI} == 2 ]] && ! use prefix && EPREFIX=;
  723.     local econfargs=();
  724.     _check_build_dir;
  725.     if "${ECONF_SOURCE}"/configure --help 2>&1 | grep -q '^ *--docdir='; then
  726.         econfargs+=(--docdir="${EPREFIX}"/usr/share/doc/${PF});
  727.     fi;
  728.     if in_iuse static-libs; then
  729.         econfargs+=(--enable-shared $(use_enable static-libs static));
  730.     fi;
  731.     econfargs+=("${myeconfargs[@]}");
  732.     mkdir -p "${BUILD_DIR}" || die;
  733.     pushd "${BUILD_DIR}" > /dev/null || die;
  734.     econf "${econfargs[@]}" "$@";
  735.     popd > /dev/null || die
  736. }
  737. autotools-utils_src_install ()
  738. {
  739.     debug-print-function ${FUNCNAME} "$@";
  740.     _check_build_dir;
  741.     pushd "${BUILD_DIR}" > /dev/null || die;
  742.     emake DESTDIR="${D}" "$@" install || die "emake install failed";
  743.     popd > /dev/null || die;
  744.     if [[ ${EAPI} == [23] ]] && path_exists "${D}${EPREFIX}"/usr/share/doc/${PF}/*; then
  745.         if [[ -n $(find "${D}${EPREFIX}"/usr/share/doc/${PF}/* -type d) ]]; then
  746.             eqawarn "autotools-utils: directories in docdir require at least EAPI 4";
  747.         else
  748.             mkdir "${T}"/temp-docdir;
  749.             mv "${D}${EPREFIX}"/usr/share/doc/${PF}/* "${T}"/temp-docdir/ || die "moving docs to tempdir failed";
  750.             dodoc "${T}"/temp-docdir/* || die "docdir dodoc failed";
  751.             rm -r "${T}"/temp-docdir || die;
  752.         fi;
  753.     fi;
  754.     if declare -p DOCS &>/dev/null; then
  755.         if [[ -n ${DOCS[@]} ]]; then
  756.             if [[ ${EAPI} == [23] ]]; then
  757.                 dodoc "${DOCS[@]}" || die;
  758.             else
  759.                 dodoc -r "${DOCS[@]}";
  760.             fi;
  761.         fi;
  762.     else
  763.         local f;
  764.         for f in README* ChangeLog AUTHORS NEWS TODO CHANGES THANKS BUGS FAQ CREDITS CHANGELOG;
  765.         do
  766.             if [[ -s ${f} ]]; then
  767.                 dodoc "${f}" || die "(default) dodoc ${f} failed";
  768.             fi;
  769.         done;
  770.     fi;
  771.     if [[ -n ${HTML_DOCS} ]]; then
  772.         dohtml -r "${HTML_DOCS[@]}" || die "dohtml failed";
  773.     fi;
  774.     prune_libtool_files
  775. }
  776. autotools-utils_src_prepare ()
  777. {
  778.     debug-print-function ${FUNCNAME} "$@";
  779.     local want_autoreconf=${AUTOTOOLS_AUTORECONF};
  780.     [[ -n ${PATCHES} ]] && epatch "${PATCHES[@]}";
  781.     function at_checksum ()
  782.     {
  783.         find '(' -name 'Makefile.am' -o -name 'configure.ac' -o -name 'configure.in' ')' -exec cksum {} + | sort -k2
  784.     };
  785.     [[ ! -n ${want_autoreconf} ]] && local checksum=$(at_checksum);
  786.     epatch_user;
  787.     if [[ ! -n ${want_autoreconf} ]]; then
  788.         if [[ ${checksum} != $(at_checksum) ]]; then
  789.             einfo 'Will autoreconfigure due to user patches applied.';
  790.             want_autoreconf=yep;
  791.         fi;
  792.     fi;
  793.     [[ -n ${want_autoreconf} ]] && eautoreconf;
  794.     elibtoolize --patch-only
  795. }
  796. autotools-utils_src_test ()
  797. {
  798.     debug-print-function ${FUNCNAME} "$@";
  799.     _check_build_dir;
  800.     pushd "${BUILD_DIR}" > /dev/null || die;
  801.     default_src_test;
  802.     popd > /dev/null || die
  803. }
  804. autotools_check_macro ()
  805. {
  806.     [[ -f configure.ac || -f configure.in ]] || return 0;
  807.     local trace_file=".__autoconf_trace_data";
  808.     if [[ ! -e ${trace_file} ]] || [[ ! aclocal.m4 -ot ${trace_file} ]]; then
  809.         WANT_AUTOCONF="2.5" autoconf $(autotools_m4dir_include) ${ALL_AUTOTOOLS_MACROS[@]/#/--trace=} > ${trace_file} 2> /dev/null;
  810.     fi;
  811.     local macro args=();
  812.     for macro in "$@";
  813.     do
  814.         has ${macro} ${ALL_AUTOTOOLS_MACROS[@]} || die "internal error: add ${macro} to ALL_AUTOTOOLS_MACROS";
  815.         args+=(-e ":${macro}:");
  816.     done;
  817.     grep "${args[@]}" ${trace_file}
  818. }
  819. autotools_check_macro_val ()
  820. {
  821.     local macro scan_out;
  822.     for macro in "$@";
  823.     do
  824.         autotools_check_macro "${macro}" | gawk -v macro="${macro}" '($0 !~ /^[[:space:]]*(#|dnl)/) {
  825.                     if (match($0, macro ":(.*)$", res))
  826.                         print res[1]
  827.                 }' | uniq;
  828.     done;
  829.     return 0
  830. }
  831. autotools_env_setup ()
  832. {
  833.     if [[ ${WANT_AUTOMAKE} == "latest" ]]; then
  834.         local pv;
  835.         for pv in ${_LATEST_AUTOMAKE[@]/#*:};
  836.         do
  837.             ROOT=/ has_version "=sys-devel/automake-${pv}*" && export WANT_AUTOMAKE="${pv}";
  838.         done;
  839.         [[ ${WANT_AUTOMAKE} == "latest" ]] && die "Cannot find the latest automake! Tried ${_LATEST_AUTOMAKE}";
  840.     fi;
  841.     [[ ${WANT_AUTOCONF} == "latest" ]] && export WANT_AUTOCONF=2.5
  842. }
  843. autotools_m4dir_include ()
  844. {
  845.     _autotools_m4dir_include ${AT_M4DIR}
  846. }
  847. autotools_m4sysdir_include ()
  848. {
  849.     _autotools_m4dir_include $(eval echo ${AT_SYS_M4DIR})
  850. }
  851. autotools_run_tool ()
  852. {
  853.     local autofail=true m4flags=false missing_ok=false;
  854.     while [[ -n $1 ]]; do
  855.         case $1 in
  856.             --at-no-fail)
  857.                 autofail=false
  858.             ;;
  859.             --at-m4flags)
  860.                 m4flags=true
  861.             ;;
  862.             --at-missing)
  863.                 missing_ok=true
  864.             ;;
  865.             *)
  866.                 break
  867.             ;;
  868.         esac;
  869.         shift;
  870.     done;
  871.     if [[ ${EBUILD_PHASE} != "unpack" && ${EBUILD_PHASE} != "prepare" ]]; then
  872.         ewarn "QA Warning: running $1 in ${EBUILD_PHASE} phase";
  873.     fi;
  874.     if ${missing_ok} && ! type -P ${1} > /dev/null; then
  875.         einfo "Skipping '$*' due $1 not installed";
  876.         return 0;
  877.     fi;
  878.     autotools_env_setup;
  879.     local STDERR_TARGET="${T}/$1.out";
  880.     if [[ -e ${STDERR_TARGET} ]]; then
  881.         local i=1;
  882.         while :; do
  883.             STDERR_TARGET="${T}/$1-${i}.out";
  884.             [[ -e ${STDERR_TARGET} ]] || break;
  885.             : $(( i++ ));
  886.         done;
  887.     fi;
  888.     if ${m4flags}; then
  889.         set -- "${1}" $(autotools_m4dir_include) "${@:2}" $(autotools_m4sysdir_include);
  890.     fi;
  891.     printf "***** $1 *****\n***** PWD: ${PWD}\n***** $*\n\n" > "${STDERR_TARGET}";
  892.     ebegin "Running $@";
  893.     "$@" >> "${STDERR_TARGET}" 2>&1;
  894.     if ! eend $? && ${autofail}; then
  895.         echo;
  896.         eerror "Failed Running $1 !";
  897.         eerror;
  898.         eerror "Include in your bugreport the contents of:";
  899.         eerror;
  900.         eerror "  ${STDERR_TARGET}";
  901.         echo;
  902.         die "Failed Running $1 !";
  903.     fi
  904. }
  905. built_with_use ()
  906. {
  907.     local hidden="no";
  908.     if [[ $1 == "--hidden" ]]; then
  909.         hidden="yes";
  910.         shift;
  911.     fi;
  912.     local missing_action="die";
  913.     if [[ $1 == "--missing" ]]; then
  914.         missing_action=$2;
  915.         shift;
  916.         shift;
  917.         case ${missing_action} in
  918.             true | false | die)
  919.  
  920.             ;;
  921.             *)
  922.                 die "unknown action '${missing_action}'"
  923.             ;;
  924.         esac;
  925.     fi;
  926.     local opt=$1;
  927.     [[ ${opt:0:1} = "-" ]] && shift || opt="-a";
  928.     local PKG=$(best_version $1);
  929.     [[ -z ${PKG} ]] && die "Unable to resolve $1 to an installed package";
  930.     shift;
  931.     local USEFILE=${ROOT}/var/db/pkg/${PKG}/USE;
  932.     local IUSEFILE=${ROOT}/var/db/pkg/${PKG}/IUSE;
  933.     if [[ ! -e ${USEFILE} ]] || [[ ! -e ${IUSEFILE} && ${hidden} == "no" ]]; then
  934.         case ${missing_action} in
  935.             true)
  936.                 return 0
  937.             ;;
  938.             false)
  939.                 return 1
  940.             ;;
  941.             die)
  942.                 die "Unable to determine what USE flags $PKG was built with"
  943.             ;;
  944.         esac;
  945.     fi;
  946.     if [[ ${hidden} == "no" ]]; then
  947.         local IUSE_BUILT=($(<"${IUSEFILE}"));
  948.         local expand;
  949.         for expand in $(echo ${USE_EXPAND} | tr '[:upper:]' '[:lower:]');
  950.         do
  951.             if [[ $1 == ${expand}_* ]]; then
  952.                 expand="";
  953.                 break;
  954.             fi;
  955.         done;
  956.         if [[ -n ${expand} ]]; then
  957.             if ! has $1 ${IUSE_BUILT[@]#[-+]}; then
  958.                 case ${missing_action} in
  959.                     true)
  960.                         return 0
  961.                     ;;
  962.                     false)
  963.                         return 1
  964.                     ;;
  965.                     die)
  966.                         die "$PKG does not actually support the $1 USE flag!"
  967.                     ;;
  968.                 esac;
  969.             fi;
  970.         fi;
  971.     fi;
  972.     local USE_BUILT=$(<${USEFILE});
  973.     while [[ $# -gt 0 ]]; do
  974.         if [[ ${opt} = "-o" ]]; then
  975.             has $1 ${USE_BUILT} && return 0;
  976.         else
  977.             has $1 ${USE_BUILT} || return 1;
  978.         fi;
  979.         shift;
  980.     done;
  981.     [[ ${opt} = "-a" ]]
  982. }
  983. check_license ()
  984. {
  985.     die "you no longer need this as portage supports ACCEPT_LICENSE itself"
  986. }
  987. config_rpath_update ()
  988. {
  989.     local dst src=$(type -P gettext | sed 's:bin/gettext:share/gettext/config.rpath:');
  990.     [[ $# -eq 0 ]] && set -- $(find -name config.rpath);
  991.     [[ $# -eq 0 ]] && return 0;
  992.     einfo "Updating all config.rpath files";
  993.     for dst in "$@";
  994.     do
  995.         einfo "   ${dst}";
  996.         cp "${src}" "${dst}" || die;
  997.     done
  998. }
  999. create_fonts_dir ()
  1000. {
  1001.     debug-print-function ${FUNCNAME} "$@";
  1002.     ebegin "Generating fonts.dir";
  1003.     mkfontdir -e "${EROOT}"/usr/share/fonts/encodings -e "${EROOT}"/usr/share/fonts/encodings/large -- "${EROOT}/usr/share/fonts/${FONT_DIR}";
  1004.     eend $?
  1005. }
  1006. create_fonts_scale ()
  1007. {
  1008.     debug-print-function ${FUNCNAME} "$@";
  1009.     if [[ ${FONT_DIR} != Speedo && ${FONT_DIR} != CID ]]; then
  1010.         ebegin "Generating fonts.scale";
  1011.         mkfontscale -a "${EROOT}/usr/share/fonts/encodings/encodings.dir" -- "${EROOT}/usr/share/fonts/${FONT_DIR}";
  1012.         eend $?;
  1013.     fi
  1014. }
  1015. darwintoolize ()
  1016. {
  1017.     die "Use elibtoolize"
  1018. }
  1019. doicon ()
  1020. {
  1021.     _iconins ${FUNCNAME} "$@"
  1022. }
  1023. domenu ()
  1024. {
  1025.     ( local i j ret=0;
  1026.     insinto /usr/share/applications;
  1027.     for i in "$@";
  1028.     do
  1029.         if [[ -f ${i} ]]; then
  1030.             doins "${i}";
  1031.             ((ret+=$?));
  1032.         else
  1033.             if [[ -d ${i} ]]; then
  1034.                 for j in "${i}"/*.desktop;
  1035.                 do
  1036.                     doins "${j}";
  1037.                     ((ret+=$?));
  1038.                 done;
  1039.             else
  1040.                 ((++ret));
  1041.             fi;
  1042.         fi;
  1043.     done;
  1044.     exit ${ret} )
  1045. }
  1046. eaclocal ()
  1047. {
  1048.     [[ ! -f aclocal.m4 || -n $(grep -e 'generated.*by aclocal' aclocal.m4) ]] && autotools_run_tool --at-m4flags aclocal "$@" $(eaclocal_amflags)
  1049. }
  1050. eaclocal_amflags ()
  1051. {
  1052.     local aclocal_opts amflags_file;
  1053.     for amflags_file in GNUmakefile.am Makefile.am GNUmakefile.in Makefile.in;
  1054.     do
  1055.         [[ -e ${amflags_file} ]] || continue;
  1056.         autotools_env_setup;
  1057.         aclocal_opts=$(sed -n           "/^ACLOCAL_AMFLAGS[[:space:]]*=/{             # match the first line
  1058.               s:[^=]*=::p;            # then gobble up all escaped lines
  1059.               : nextline /\\\\$/{ n; p; b nextline; }           }" ${amflags_file});
  1060.         eval aclocal_opts=\""${aclocal_opts}"\";
  1061.         break;
  1062.     done;
  1063.     echo ${aclocal_opts}
  1064. }
  1065. eautoconf ()
  1066. {
  1067.     if [[ ! -f configure.ac && ! -f configure.in ]]; then
  1068.         echo;
  1069.         eerror "No configure.{ac,in} present in '${PWD}'!";
  1070.         echo;
  1071.         die "No configure.{ac,in} present!";
  1072.     fi;
  1073.     autotools_run_tool --at-m4flags autoconf "$@"
  1074. }
  1075. eautoheader ()
  1076. {
  1077.     _at_uses_autoheader || return 0;
  1078.     autotools_run_tool --at-no-fail --at-m4flags autoheader "$@"
  1079. }
  1080. eautomake ()
  1081. {
  1082.     local extra_opts;
  1083.     local makefile_name;
  1084.     for makefile_name in {GNUmakefile,{M,m}akefile}.am "";
  1085.     do
  1086.         [[ -f ${makefile_name} ]] && break;
  1087.     done;
  1088.     if [[ -z ${makefile_name} ]]; then
  1089.         _at_uses_automake || return 0;
  1090.     else
  1091.         if [[ -z ${FROM_EAUTORECONF} && -f ${makefile_name%.am}.in ]]; then
  1092.             local used_automake;
  1093.             local installed_automake;
  1094.             installed_automake=$(WANT_AUTOMAKE= automake --version | head -n 1 |            sed -e 's:.*(GNU automake) ::');
  1095.             used_automake=$(head -n 1 < ${makefile_name%.am}.in |           sed -e 's:.*by automake \(.*\) from .*:\1:');
  1096.             if [[ ${installed_automake} != ${used_automake} ]]; then
  1097.                 einfo "Automake used for the package (${used_automake}) differs from";
  1098.                 einfo "the installed version (${installed_automake}).";
  1099.                 eautoreconf;
  1100.                 return 0;
  1101.             fi;
  1102.         fi;
  1103.     fi;
  1104.     [[ -f INSTALL && -f AUTHORS && -f ChangeLog && -f NEWS && -f README ]] || extra_opts="${extra_opts} --foreign";
  1105.     autotools_run_tool automake --add-missing --copy ${extra_opts} "$@"
  1106. }
  1107. eautopoint ()
  1108. {
  1109.     autotools_run_tool autopoint "$@"
  1110. }
  1111. eautoreconf ()
  1112. {
  1113.     local x g multitop;
  1114.     if [[ -z ${AT_TOPLEVEL_EAUTORECONF} ]]; then
  1115.         AT_TOPLEVEL_EAUTORECONF="yes";
  1116.         multitop="yes";
  1117.         multijob_init;
  1118.     fi;
  1119.     if [[ -z ${AT_NO_RECURSIVE} ]]; then
  1120.         for x in $(autotools_check_macro_val AC_CONFIG_SUBDIRS);
  1121.         do
  1122.             if [[ -d ${x} ]]; then
  1123.                 pushd "${x}" > /dev/null;
  1124.                 if [[ -z ${PAST_TOPLEVEL_EAUTORECONF} ]]; then
  1125.                     PAST_TOPLEVEL_EAUTORECONF="yes" AT_NOELIBTOOLIZE="yes" multijob_child_init eautoreconf || die;
  1126.                 else
  1127.                     AT_NOELIBTOOLIZE="yes" eautoreconf || die;
  1128.                 fi;
  1129.                 popd > /dev/null;
  1130.             fi;
  1131.         done;
  1132.     fi;
  1133.     einfo "Running eautoreconf in '${PWD}' ...";
  1134.     local m4dirs=$(autotools_check_macro_val AC_CONFIG_{AUX,MACRO}_DIR);
  1135.     [[ -n ${m4dirs} ]] && mkdir -p ${m4dirs};
  1136.     local i tools=(glibgettext false "autotools_run_tool glib-gettextize --copy --force" gettext false "autotools_run_tool --at-missing autopoint --force" intltool false "autotools_run_tool intltoolize --automake --copy --force" gtkdoc false "autotools_run_tool --at-missing gtkdocize --copy" gnomedoc false "autotools_run_tool --at-missing gnome-doc-prepare --copy --force" libtool false "_elibtoolize --install --copy --force");
  1137.     for ((i = 0; i < ${#tools[@]}; i += 3 ))
  1138.     do
  1139.         if _at_uses_${tools[i]}; then
  1140.             tools[i+1]=true;
  1141.             ${tools[i+2]};
  1142.         fi;
  1143.     done;
  1144.     local rerun_aclocal=false;
  1145.     eaclocal;
  1146.     for ((i = 0; i < ${#tools[@]}; i += 3 ))
  1147.     do
  1148.         if ! ${tools[i+1]} && _at_uses_${tools[i]}; then
  1149.             ${tools[i+2]};
  1150.             rerun_aclocal=true;
  1151.         fi;
  1152.     done;
  1153.     ${rerun_aclocal} && eaclocal;
  1154.     eautoconf;
  1155.     eautoheader;
  1156.     [[ ${AT_NOEAUTOMAKE} != "yes" ]] && FROM_EAUTORECONF="yes" eautomake ${AM_OPTS};
  1157.     if [[ ${AT_NOELIBTOOLIZE} != "yes" ]]; then
  1158.         S=${PWD} elibtoolize --force;
  1159.     fi;
  1160.     if [[ -n ${multitop} ]]; then
  1161.         unset AT_TOPLEVEL_EAUTORECONF;
  1162.         multijob_finish || die;
  1163.     fi;
  1164.     return 0
  1165. }
  1166. ebeep ()
  1167. {
  1168.     ewarn "QA Notice: ebeep is not defined in EAPI=${EAPI}, please file a bug at http://bugs.gentoo.org"
  1169. }
  1170. econf_build ()
  1171. {
  1172.     tc-env_build econf --build=${CBUILD:-${CHOST}} "$@"
  1173. }
  1174. ecvs_clean ()
  1175. {
  1176.     [[ -z $* ]] && set -- .;
  1177.     find "$@" -type d -name 'CVS' -prune -print0 | xargs -0 rm -rf;
  1178.     find "$@" -type f -name '.cvs*' -print0 | xargs -0 rm -rf
  1179. }
  1180. edos2unix ()
  1181. {
  1182.     [[ $# -eq 0 ]] && return 0;
  1183.     sed -i 's/\r$//' -- "$@" || die
  1184. }
  1185. egetent ()
  1186. {
  1187.     local db=$1 key=$2;
  1188.     [[ $# -ge 3 ]] && die "usage: egetent <database> <key>";
  1189.     case ${db} in
  1190.         passwd | group)
  1191.  
  1192.         ;;
  1193.         *)
  1194.             die "sorry, database '${db}' not yet supported; file a bug"
  1195.         ;;
  1196.     esac;
  1197.     case ${CHOST} in
  1198.         *-darwin[678])
  1199.             case ${key} in
  1200.                 *[!0-9]*)
  1201.                     nidump ${db} . | awk -F: "(\$1 ~ /^${key}\$/) {print;exit;}"
  1202.                 ;;
  1203.                 *)
  1204.                     nidump ${db} . | awk -F: "(\$3 == ${key}) {print;exit;}"
  1205.                 ;;
  1206.             esac
  1207.         ;;
  1208.         *-darwin*)
  1209.             local mykey;
  1210.             case ${db} in
  1211.                 passwd)
  1212.                     db="Users" mykey="UniqueID"
  1213.                 ;;
  1214.                 group)
  1215.                     db="Groups" mykey="PrimaryGroupID"
  1216.                 ;;
  1217.             esac;
  1218.             case ${key} in
  1219.                 *[!0-9]*)
  1220.                     dscl . -read /${db}/${key} 2> /dev/null | grep RecordName
  1221.                 ;;
  1222.                 *)
  1223.                     dscl . -search /${db} ${mykey} ${key} 2> /dev/null
  1224.                 ;;
  1225.             esac
  1226.         ;;
  1227.         *-freebsd* | *-dragonfly*)
  1228.             case ${db} in
  1229.                 passwd)
  1230.                     db="user"
  1231.                 ;;
  1232.                 *)
  1233.  
  1234.                 ;;
  1235.             esac;
  1236.             local opts;
  1237.             if [[ ${key} == [[:digit:]]* ]]; then
  1238.                 [[ ${db} == "user" ]] && opts="-u" || opts="-g";
  1239.             fi;
  1240.             pw show ${db} ${opts} "${key}" -q
  1241.         ;;
  1242.         *-netbsd* | *-openbsd*)
  1243.             grep "${key}:\*:" /etc/${db}
  1244.         ;;
  1245.         *)
  1246.             nscd -i "${db}" 2> /dev/null;
  1247.             getent "${db}" "${key}"
  1248.         ;;
  1249.     esac
  1250. }
  1251. egethome ()
  1252. {
  1253.     local pos;
  1254.     [[ $# -eq 1 ]] || die "usage: egethome <user>";
  1255.     case ${CHOST} in
  1256.         *-darwin* | *-freebsd* | *-dragonfly*)
  1257.             pos=9
  1258.         ;;
  1259.         *)
  1260.             pos=6
  1261.         ;;
  1262.     esac;
  1263.     egetent passwd "$1" | cut -d: -f${pos}
  1264. }
  1265. egetshell ()
  1266. {
  1267.     local pos;
  1268.     [[ $# -eq 1 ]] || die "usage: egetshell <user>";
  1269.     case ${CHOST} in
  1270.         *-darwin* | *-freebsd* | *-dragonfly*)
  1271.             pos=10
  1272.         ;;
  1273.         *)
  1274.             pos=7
  1275.         ;;
  1276.     esac;
  1277.     egetent passwd "$1" | cut -d: -f${pos}
  1278. }
  1279. elibtoolize ()
  1280. {
  1281.     local x;
  1282.     local do_portage="no";
  1283.     local do_reversedeps="no";
  1284.     local do_only_patches="no";
  1285.     local do_uclibc="yes";
  1286.     local deptoremove=;
  1287.     local do_shallow="no";
  1288.     local force="false";
  1289.     local elt_patches="install-sh ltmain portage relink max_cmd_len sed test tmp cross as-needed";
  1290.     for x in "$@";
  1291.     do
  1292.         case ${x} in
  1293.             --portage)
  1294.                 do_portage="yes"
  1295.             ;;
  1296.             --reverse-deps)
  1297.                 do_reversedeps="yes";
  1298.                 elt_patches+=" fix-relink"
  1299.             ;;
  1300.             --patch-only)
  1301.                 do_only_patches="yes"
  1302.             ;;
  1303.             --remove-internal-dep=*)
  1304.                 deptoremove=${x#--remove-internal-dep=};
  1305.                 [[ -n ${deptoremove} ]] && elt_patches+=" rem-int-dep"
  1306.             ;;
  1307.             --shallow)
  1308.                 do_shallow="yes"
  1309.             ;;
  1310.             --no-uclibc)
  1311.                 do_uclibc="no"
  1312.             ;;
  1313.             --force)
  1314.                 force="true"
  1315.             ;;
  1316.             *)
  1317.                 eerror "Invalid elibtoolize option: ${x}";
  1318.                 die "elibtoolize called with ${x} ??"
  1319.             ;;
  1320.         esac;
  1321.     done;
  1322.     [[ ${do_uclibc} == "yes" ]] && elt_patches+=" uclibc-conf uclibc-ltconf";
  1323.     case ${CHOST} in
  1324.         *-aix*)
  1325.             elt_patches+=" hardcode aixrtl aix-noundef"
  1326.         ;;
  1327.         *-darwin*)
  1328.             elt_patches+=" darwin-ltconf darwin-ltmain darwin-conf"
  1329.         ;;
  1330.         *-solaris*)
  1331.             elt_patches+=" sol2-conf sol2-ltmain"
  1332.         ;;
  1333.         *-freebsd*)
  1334.             elt_patches+=" fbsd-conf fbsd-ltconf"
  1335.         ;;
  1336.         *-hpux*)
  1337.             elt_patches+=" hpux-conf deplibs hc-flag-ld hardcode hardcode-relink relink-prog no-lc"
  1338.         ;;
  1339.         *-irix*)
  1340.             elt_patches+=" irix-ltmain"
  1341.         ;;
  1342.         *-mint*)
  1343.             elt_patches+=" mint-conf"
  1344.         ;;
  1345.     esac;
  1346.     if $(tc-getLD) --version 2>&1 | grep -qs 'GNU gold'; then
  1347.         elt_patches+=" gold-conf";
  1348.     fi;
  1349.     set --;
  1350.     if [[ ${do_shallow} == "yes" ]]; then
  1351.         [[ -f ${S}/ltmain.sh ]] && set -- "${S}";
  1352.     else
  1353.         set -- $(find "${S}" -name ltmain.sh -printf '%h ');
  1354.     fi;
  1355.     local d p;
  1356.     for d in "$@";
  1357.     do
  1358.         export ELT_APPLIED_PATCHES=;
  1359.         if [[ -f ${d}/.elibtoolized ]]; then
  1360.             ${force} || continue;
  1361.         fi;
  1362.         local outfunc="einfo";
  1363.         [[ -f ${d}/.elibtoolized ]] && outfunc="ewarn";
  1364.         ${outfunc} "Running elibtoolize in: ${d#${WORKDIR}/}/";
  1365.         if [[ ${outfunc} == "ewarn" ]]; then
  1366.             ewarn "  We've already been run in this tree; you should";
  1367.             ewarn "  avoid this if possible (perhaps by filing a bug)";
  1368.         fi;
  1369.         for p in ${elt_patches};
  1370.         do
  1371.             local ret=0;
  1372.             case ${p} in
  1373.                 portage)
  1374.                     if ! grep -qs 'We do not want portage' "${d}/ltmain.sh"; then
  1375.                         ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1376.                         ret=$?;
  1377.                     fi
  1378.                 ;;
  1379.                 rem-int-dep)
  1380.                     ELT_walk_patches "${d}/ltmain.sh" "${p}" "${deptoremove}";
  1381.                     ret=$?
  1382.                 ;;
  1383.                 fix-relink)
  1384.                     if grep -qs 'inst_prefix_dir' "${d}/ltmain.sh"; then
  1385.                         ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1386.                         ret=$?;
  1387.                     fi
  1388.                 ;;
  1389.                 max_cmd_len)
  1390.                     if grep -qs 'max_cmd_len' "${d}/ltmain.sh"; then
  1391.                         ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1392.                         ret=$?;
  1393.                     fi
  1394.                 ;;
  1395.                 as-needed)
  1396.                     ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1397.                     ret=$?
  1398.                 ;;
  1399.                 uclibc-conf)
  1400.                     if grep -qs 'Transform linux' "${d}/configure"; then
  1401.                         ELT_walk_patches "${d}/configure" "${p}";
  1402.                         ret=$?;
  1403.                     else
  1404.                         if [[ ! -e ${d}/configure ]] && grep -qs 'Transform linux' "${d}/../configure"; then
  1405.                             ELT_walk_patches "${d}/../configure" "${p}";
  1406.                             ret=$?;
  1407.                         fi;
  1408.                     fi
  1409.                 ;;
  1410.                 uclibc-ltconf)
  1411.                     if [[ -s ${d}/ltconfig ]]; then
  1412.                         ELT_walk_patches "${d}/ltconfig" "${p}";
  1413.                         ret=$?;
  1414.                     fi
  1415.                 ;;
  1416.                 fbsd-conf)
  1417.                     if grep -qs 'version_type=freebsd-' "${d}/configure"; then
  1418.                         ELT_walk_patches "${d}/configure" "${p}";
  1419.                         ret=$?;
  1420.                     else
  1421.                         if [[ ! -e ${d}/configure ]] && grep -qs 'version_type=freebsd-' "${d}/../configure"; then
  1422.                             ELT_walk_patches "${d}/../configure" "${p}";
  1423.                             ret=$?;
  1424.                         fi;
  1425.                     fi
  1426.                 ;;
  1427.                 fbsd-ltconf)
  1428.                     if [[ -s ${d}/ltconfig ]]; then
  1429.                         ELT_walk_patches "${d}/ltconfig" "${p}";
  1430.                         ret=$?;
  1431.                     fi
  1432.                 ;;
  1433.                 darwin-conf)
  1434.                     if grep -qs '&& echo \.so ||' "${d}/configure"; then
  1435.                         ELT_walk_patches "${d}/configure" "${p}";
  1436.                         ret=$?;
  1437.                     else
  1438.                         if [[ ! -e ${d}/configure ]] && grep -qs '&& echo \.so ||' "${d}/../configure"; then
  1439.                             ELT_walk_patches "${d}/../configure" "${p}";
  1440.                             ret=$?;
  1441.                         fi;
  1442.                     fi
  1443.                 ;;
  1444.                 darwin-ltconf)
  1445.                     if [[ -s ${d}/ltconfig ]]; then
  1446.                         ELT_walk_patches "${d}/ltconfig" "${p}";
  1447.                         ret=$?;
  1448.                     fi
  1449.                 ;;
  1450.                 darwin-ltmain)
  1451.                     if [[ -e ${d}/ltmain.sh ]] && ! grep -qs 'verstring="-compatibility_version' "${d}/ltmain.sh"; then
  1452.                         ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1453.                         ret=$?;
  1454.                     fi
  1455.                 ;;
  1456.                 aixrtl | hpux-conf)
  1457.                     ret=1;
  1458.                     local subret=0;
  1459.                     while [[ $subret -eq 0 ]]; do
  1460.                         subret=1;
  1461.                         if [[ -e ${d}/configure ]]; then
  1462.                             ELT_walk_patches "${d}/configure" "${p}";
  1463.                             subret=$?;
  1464.                         else
  1465.                             if [[ ! -e ${d}/configure && -e ${d}/../configure ]]; then
  1466.                                 ELT_walk_patches "${d}/../configure" "${p}";
  1467.                                 subret=$?;
  1468.                             fi;
  1469.                         fi;
  1470.                         if [[ $subret -eq 0 ]]; then
  1471.                             ret=0;
  1472.                         fi;
  1473.                     done
  1474.                 ;;
  1475.                 mint-conf | gold-conf | sol2-conf)
  1476.                     ret=1;
  1477.                     local subret=1;
  1478.                     if [[ -e ${d}/configure ]]; then
  1479.                         ELT_walk_patches "${d}/configure" "${p}";
  1480.                         subret=$?;
  1481.                     else
  1482.                         if [[ -e ${d}/../configure ]]; then
  1483.                             ELT_walk_patches "${d}/../configure" "${p}";
  1484.                             subret=$?;
  1485.                         else
  1486.                             if [[ -e ${d}/../../configure ]]; then
  1487.                                 ELT_walk_patches "${d}/../../configure" "${p}";
  1488.                                 subret=$?;
  1489.                             fi;
  1490.                         fi;
  1491.                     fi;
  1492.                     if [[ $subret -eq 0 ]]; then
  1493.                         ret=0;
  1494.                     fi
  1495.                 ;;
  1496.                 install-sh)
  1497.                     ELT_walk_patches "${d}/install-sh" "${p}";
  1498.                     ret=$?
  1499.                 ;;
  1500.                 cross)
  1501.                     if tc-is-cross-compiler; then
  1502.                         ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1503.                         ret=$?;
  1504.                     fi
  1505.                 ;;
  1506.                 *)
  1507.                     ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1508.                     ret=$?
  1509.                 ;;
  1510.             esac;
  1511.             if [[ ${ret} -ne 0 ]]; then
  1512.                 case ${p} in
  1513.                     relink)
  1514.                         local version=$(ELT_libtool_version "${d}/ltmain.sh");
  1515.                         if ! grep -qs 'inst_prefix_dir' "${d}/ltmain.sh" && [[ $(VER_to_int "${version}") -ge $(VER_to_int "1.4.0") ]]; then
  1516.                             ewarn "  Could not apply relink.patch!";
  1517.                         fi
  1518.                     ;;
  1519.                     portage)
  1520.                         if [[ ${do_portage} == "yes" ]]; then
  1521.                             if ! grep -qs 'We do not want portage' "${d}/ltmain.sh"; then
  1522.                                 echo;
  1523.                                 eerror "Portage patch requested, but failed to apply!";
  1524.                                 eerror "Please file a bug report to add a proper patch.";
  1525.                                 die "Portage patch requested, but failed to apply!";
  1526.                             fi;
  1527.                         else
  1528.                             if grep -qs 'We do not want portage' "${d}/ltmain.sh"; then
  1529.                                 :;
  1530.                             else
  1531.                                 local version=$(ELT_libtool_version "${d}"/ltmain.sh);
  1532.                                 echo;
  1533.                                 eerror "Portage patch failed to apply (ltmain.sh version ${version})!";
  1534.                                 eerror "Please file a bug report to add a proper patch.";
  1535.                                 die "Portage patch failed to apply!";
  1536.                             fi;
  1537.                             ELT_APPLIED_PATCHES="portage";
  1538.                         fi
  1539.                     ;;
  1540.                     uclibc-*)
  1541.                         [[ ${CHOST} == *-uclibc ]] && ewarn "  uClibc patch set '${p}' failed to apply!"
  1542.                     ;;
  1543.                     fbsd-*)
  1544.                         if [[ ${CHOST} == *-freebsd* ]]; then
  1545.                             if [[ -z $(grep 'Handle Gentoo/FreeBSD as it was Linux'                                 "${d}/configure" "${d}/../configure" 2>/dev/null) ]]; then
  1546.                                 eerror "  FreeBSD patch set '${p}' failed to apply!";
  1547.                                 die "FreeBSD patch set '${p}' failed to apply!";
  1548.                             fi;
  1549.                         fi
  1550.                     ;;
  1551.                     darwin-*)
  1552.                         [[ ${CHOST} == *"-darwin"* ]] && ewarn "  Darwin patch set '${p}' failed to apply!"
  1553.                     ;;
  1554.                 esac;
  1555.             fi;
  1556.         done;
  1557.         if [[ -z ${ELT_APPLIED_PATCHES} ]]; then
  1558.             if [[ ${do_portage} == "no" && ${do_reversedeps} == "no" && ${do_only_patches} == "no" && ${deptoremove} == "" ]]; then
  1559.                 ewarn "Cannot apply any patches, please file a bug about this";
  1560.                 die;
  1561.             fi;
  1562.         fi;
  1563.         rm -f "${d}/libtool";
  1564.          > "${d}/.elibtoolized";
  1565.     done
  1566. }
  1567. elt_patch_dir ()
  1568. {
  1569.     local d="${ECLASSDIR}/ELT-patches";
  1570.     if [[ ! -d ${d} ]]; then
  1571.         d="${ECLASSDIR_LOCAL}/ELT-patches";
  1572.     fi;
  1573.     echo "${d}"
  1574. }
  1575. emktemp ()
  1576. {
  1577.     local exe="touch";
  1578.     [[ $1 == -d ]] && exe="mkdir" && shift;
  1579.     local topdir=$1;
  1580.     if [[ -z ${topdir} ]]; then
  1581.         [[ -z ${T} ]] && topdir="/tmp" || topdir=${T};
  1582.     fi;
  1583.     if ! type -P mktemp > /dev/null; then
  1584.         local tmp=/;
  1585.         while [[ -e ${tmp} ]]; do
  1586.             tmp=${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM};
  1587.         done;
  1588.         ${exe} "${tmp}" || ${exe} -p "${tmp}";
  1589.         echo "${tmp}";
  1590.     else
  1591.         if [[ ${exe} == "touch" ]]; then
  1592.             TMPDIR="${topdir}" mktemp -t tmp.XXXXXXXXXX;
  1593.         else
  1594.             TMPDIR="${topdir}" mktemp -dt tmp.XXXXXXXXXX;
  1595.         fi;
  1596.     fi
  1597. }
  1598. enewgroup ()
  1599. {
  1600.     _assert_pkg_ebuild_phase ${FUNCNAME};
  1601.     local egroup=$1;
  1602.     shift;
  1603.     if [[ -z ${egroup} ]]; then
  1604.         eerror "No group specified !";
  1605.         die "Cannot call enewgroup without a group";
  1606.     fi;
  1607.     if [[ -n $(egetent group "${egroup}") ]]; then
  1608.         return 0;
  1609.     fi;
  1610.     einfo "Adding group '${egroup}' to your system ...";
  1611.     local egid=$1;
  1612.     shift;
  1613.     if [[ ! -z ${egid} ]]; then
  1614.         if [[ ${egid} -gt 0 ]]; then
  1615.             if [[ -n $(egetent group ${egid}) ]]; then
  1616.                 egid="next available; requested gid taken";
  1617.             fi;
  1618.         else
  1619.             eerror "Groupid given but is not greater than 0 !";
  1620.             die "${egid} is not a valid GID";
  1621.         fi;
  1622.     else
  1623.         egid="next available";
  1624.     fi;
  1625.     einfo " - Groupid: ${egid}";
  1626.     if [[ $# -gt 0 ]]; then
  1627.         die "extra arguments no longer supported; please file a bug";
  1628.     fi;
  1629.     function _enewgroup_next_gid ()
  1630.     {
  1631.         if [[ ${egid} == *[!0-9]* ]]; then
  1632.             for ((egid = 101; egid <= 999; egid++))
  1633.             do
  1634.                 [[ -z $(egetent group ${egid}) ]] && break;
  1635.             done;
  1636.         fi
  1637.     };
  1638.     case ${CHOST} in
  1639.         *-darwin*)
  1640.             _enewgroup_next_gid;
  1641.             dscl . create "/groups/${egroup}" gid ${egid};
  1642.             dscl . create "/groups/${egroup}" passwd '*'
  1643.         ;;
  1644.         *-freebsd* | *-dragonfly*)
  1645.             _enewgroup_next_gid;
  1646.             pw groupadd "${egroup}" -g ${egid} || die
  1647.         ;;
  1648.         *-netbsd*)
  1649.             _enewgroup_next_gid;
  1650.             groupadd -g ${egid} "${egroup}" || die
  1651.         ;;
  1652.         *)
  1653.             local opts;
  1654.             if [[ ${egid} == *[!0-9]* ]]; then
  1655.                 opts="";
  1656.             else
  1657.                 opts="-g ${egid}";
  1658.             fi;
  1659.             groupadd -r ${opts} "${egroup}" || die
  1660.         ;;
  1661.     esac
  1662. }
  1663. enewuser ()
  1664. {
  1665.     _assert_pkg_ebuild_phase ${FUNCNAME};
  1666.     local euser=$1;
  1667.     shift;
  1668.     if [[ -z ${euser} ]]; then
  1669.         eerror "No username specified !";
  1670.         die "Cannot call enewuser without a username";
  1671.     fi;
  1672.     if [[ -n $(egetent passwd "${euser}") ]]; then
  1673.         return 0;
  1674.     fi;
  1675.     einfo "Adding user '${euser}' to your system ...";
  1676.     local opts=();
  1677.     local euid=$1;
  1678.     shift;
  1679.     if [[ -n ${euid} && ${euid} != -1 ]]; then
  1680.         if [[ ${euid} -gt 0 ]]; then
  1681.             if [[ -n $(egetent passwd ${euid}) ]]; then
  1682.                 euid="next";
  1683.             fi;
  1684.         else
  1685.             eerror "Userid given but is not greater than 0 !";
  1686.             die "${euid} is not a valid UID";
  1687.         fi;
  1688.     else
  1689.         euid="next";
  1690.     fi;
  1691.     if [[ ${euid} == "next" ]]; then
  1692.         for ((euid = 101; euid <= 999; euid++))
  1693.         do
  1694.             [[ -z $(egetent passwd ${euid}) ]] && break;
  1695.         done;
  1696.     fi;
  1697.     opts+=(-u ${euid});
  1698.     einfo " - Userid: ${euid}";
  1699.     local eshell=$1;
  1700.     shift;
  1701.     if [[ ! -z ${eshell} ]] && [[ ${eshell} != "-1" ]]; then
  1702.         if [[ ! -e ${ROOT}${eshell} ]]; then
  1703.             eerror "A shell was specified but it does not exist !";
  1704.             die "${eshell} does not exist in ${ROOT}";
  1705.         fi;
  1706.         if [[ ${eshell} == */false || ${eshell} == */nologin ]]; then
  1707.             eerror "Do not specify ${eshell} yourself, use -1";
  1708.             die "Pass '-1' as the shell parameter";
  1709.         fi;
  1710.     else
  1711.         for eshell in /sbin/nologin /usr/sbin/nologin /bin/false /usr/bin/false /dev/null;
  1712.         do
  1713.             [[ -x ${ROOT}${eshell} ]] && break;
  1714.         done;
  1715.         if [[ ${eshell} == "/dev/null" ]]; then
  1716.             eerror "Unable to identify the shell to use, proceeding with userland default.";
  1717.             case ${USERLAND} in
  1718.                 GNU)
  1719.                     eshell="/bin/false"
  1720.                 ;;
  1721.                 BSD)
  1722.                     eshell="/sbin/nologin"
  1723.                 ;;
  1724.                 Darwin)
  1725.                     eshell="/usr/sbin/nologin"
  1726.                 ;;
  1727.                 *)
  1728.                     die "Unable to identify the default shell for userland ${USERLAND}"
  1729.                 ;;
  1730.             esac;
  1731.         fi;
  1732.     fi;
  1733.     einfo " - Shell: ${eshell}";
  1734.     opts+=(-s "${eshell}");
  1735.     local ehome=$1;
  1736.     shift;
  1737.     if [[ -z ${ehome} ]] || [[ ${ehome} == "-1" ]]; then
  1738.         ehome="/dev/null";
  1739.     fi;
  1740.     einfo " - Home: ${ehome}";
  1741.     opts+=(-d "${ehome}");
  1742.     local egroups=$1;
  1743.     shift;
  1744.     local g egroups_arr;
  1745.     IFS="," read -r -a egroups_arr <<< "${egroups}";
  1746.     shift;
  1747.     if [[ ${#egroups_arr[@]} -gt 0 ]]; then
  1748.         local defgroup exgroups;
  1749.         for g in "${egroups_arr[@]}";
  1750.         do
  1751.             if [[ -z $(egetent group "${g}") ]]; then
  1752.                 eerror "You must add group ${g} to the system first";
  1753.                 die "${g} is not a valid GID";
  1754.             fi;
  1755.             if [[ -z ${defgroup} ]]; then
  1756.                 defgroup=${g};
  1757.             else
  1758.                 exgroups+=",${g}";
  1759.             fi;
  1760.         done;
  1761.         opts+=(-g "${defgroup}");
  1762.         if [[ ! -z ${exgroups} ]]; then
  1763.             opts+=(-G "${exgroups:1}");
  1764.         fi;
  1765.     fi;
  1766.     einfo " - Groups: ${egroups:-(none)}";
  1767.     if [[ $# -gt 0 ]]; then
  1768.         die "extra arguments no longer supported; please file a bug";
  1769.     else
  1770.         local comment="added by portage for ${PN}";
  1771.         opts+=(-c "${comment}");
  1772.         einfo " - GECOS: ${comment}";
  1773.     fi;
  1774.     case ${CHOST} in
  1775.         *-darwin*)
  1776.             dscl . create "/users/${euser}" uid ${euid};
  1777.             dscl . create "/users/${euser}" shell "${eshell}";
  1778.             dscl . create "/users/${euser}" home "${ehome}";
  1779.             dscl . create "/users/${euser}" realname "added by portage for ${PN}";
  1780.             for g in "${egroups_arr[@]}";
  1781.             do
  1782.                 dscl . merge "/groups/${g}" users "${euser}";
  1783.             done
  1784.         ;;
  1785.         *-freebsd* | *-dragonfly*)
  1786.             pw useradd "${euser}" "${opts[@]}" || die
  1787.         ;;
  1788.         *-netbsd*)
  1789.             useradd "${opts[@]}" "${euser}" || die
  1790.         ;;
  1791.         *-openbsd*)
  1792.             useradd -u ${euid} -s "${eshell}" -d "${ehome}" -g "${egroups}" "${euser}" || die
  1793.         ;;
  1794.         *)
  1795.             useradd -r "${opts[@]}" "${euser}" || die
  1796.         ;;
  1797.     esac;
  1798.     if [[ ! -e ${ROOT}/${ehome} ]]; then
  1799.         einfo " - Creating ${ehome} in ${ROOT}";
  1800.         mkdir -p "${ROOT}/${ehome}";
  1801.         chown "${euser}" "${ROOT}/${ehome}";
  1802.         chmod 755 "${ROOT}/${ehome}";
  1803.     fi
  1804. }
  1805. epatch ()
  1806. {
  1807.     function _epatch_draw_line ()
  1808.     {
  1809.         [[ -z $1 ]] && set "$(printf "%65s" '')";
  1810.         echo "${1//?/=}"
  1811.     };
  1812.     unset P4CONFIG P4PORT P4USER;
  1813.     local EPATCH_OPTS=(${EPATCH_OPTS[*]});
  1814.     while [[ $# -gt 0 ]]; do
  1815.         case $1 in
  1816.             -*)
  1817.                 EPATCH_OPTS+=("$1")
  1818.             ;;
  1819.             *)
  1820.                 break
  1821.             ;;
  1822.         esac;
  1823.         shift;
  1824.     done;
  1825.     if [[ $# -gt 1 ]]; then
  1826.         local m;
  1827.         for m in "$@";
  1828.         do
  1829.             epatch "${m}";
  1830.         done;
  1831.         return 0;
  1832.     fi;
  1833.     local SINGLE_PATCH="no";
  1834.     [[ $# -eq 0 ]] && set -- "${EPATCH_SOURCE}";
  1835.     if [[ -f $1 ]]; then
  1836.         SINGLE_PATCH="yes";
  1837.         set -- "$1";
  1838.         local EPATCH_SUFFIX=$1;
  1839.     else
  1840.         if [[ -d $1 ]]; then
  1841.             set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"};
  1842.        else
  1843.            if [[ -f ${EPATCH_SOURCE}/$1 ]]; then
  1844.                epatch "${EPATCH_SOURCE}/$1";
  1845.                return $?;
  1846.            else
  1847.                [[ $# -ne 0 ]] && EPATCH_SOURCE=$1;
  1848.                echo;
  1849.                eerror "Cannot find \$EPATCH_SOURCE!  Value for \$EPATCH_SOURCE is:";
  1850.                eerror;
  1851.                eerror "  ${EPATCH_SOURCE}";
  1852.                eerror "  ( ${EPATCH_SOURCE##*/} )";
  1853.                echo;
  1854.                die "Cannot find \$EPATCH_SOURCE!";
  1855.            fi;
  1856.        fi;
  1857.    fi;
  1858.    EPATCH_OPTS="${EPATCH_COMMON_OPTS} ${EPATCH_OPTS[*]}";
  1859.    local PIPE_CMD;
  1860.    case ${EPATCH_SUFFIX##*\.} in
  1861.        xz)
  1862.            PIPE_CMD="xz -dc"
  1863.        ;;
  1864.        lzma)
  1865.            PIPE_CMD="lzma -dc"
  1866.        ;;
  1867.        bz2)
  1868.            PIPE_CMD="bzip2 -dc"
  1869.        ;;
  1870.        gz | Z | z)
  1871.            PIPE_CMD="gzip -dc"
  1872.        ;;
  1873.        ZIP | zip)
  1874.            PIPE_CMD="unzip -p"
  1875.        ;;
  1876.        *)
  1877.  
  1878.        ;;
  1879.    esac;
  1880.    [[ ${SINGLE_PATCH} == "no" ]] && einfo "${EPATCH_MULTI_MSG}";
  1881.    local x;
  1882.    for x in "$@";
  1883.    do
  1884.        [[ ! -f ${x} ]] && continue;
  1885.        local patchname=${x##*/};
  1886.        local a=${patchname#*_};
  1887.        a=${a%%_*};
  1888.        if ! [[ ${SINGLE_PATCH} == "yes" || ${EPATCH_FORCE} == "yes" || ${a} == all || ${a} == ${ARCH} ]]; then
  1889.            continue;
  1890.        fi;
  1891.        if [[ -n ${EPATCH_EXCLUDE} ]]; then
  1892.            eshopts_push -o noglob;
  1893.            local ex;
  1894.            for ex in ${EPATCH_EXCLUDE};
  1895.            do
  1896.                if [[ ${patchname} == ${ex} ]]; then
  1897.                    eshopts_pop;
  1898.                    continue 2;
  1899.                fi;
  1900.            done;
  1901.            eshopts_pop;
  1902.        fi;
  1903.        if [[ ${SINGLE_PATCH} == "yes" ]]; then
  1904.            if [[ -n ${EPATCH_SINGLE_MSG} ]]; then
  1905.                einfo "${EPATCH_SINGLE_MSG}";
  1906.            else
  1907.                einfo "Applying ${patchname} ...";
  1908.            fi;
  1909.        else
  1910.            einfo "  ${patchname} ...";
  1911.        fi;
  1912.        local STDERR_TARGET="${T}/${patchname}.out";
  1913.        if [[ -e ${STDERR_TARGET} ]]; then
  1914.            STDERR_TARGET="${T}/${patchname}-$$.out";
  1915.        fi;
  1916.        printf "***** %s *****\nPWD: %s\n\n" "${patchname}" "${PWD}" > "${STDERR_TARGET}";
  1917.        local count=0;
  1918.        local PATCH_TARGET;
  1919.        if [[ -n ${PIPE_CMD} ]]; then
  1920.            PATCH_TARGET="${T}/$$.patch";
  1921.            echo "PIPE_COMMAND:  ${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> "${STDERR_TARGET}";
  1922.            if ! ( ${PIPE_CMD} "${x}" > "${PATCH_TARGET}" ) >> "${STDERR_TARGET}" 2>&1; then
  1923.                echo;
  1924.                eerror "Could not extract patch!";
  1925.                count=5;
  1926.                break;
  1927.            fi;
  1928.        else
  1929.            PATCH_TARGET=${x};
  1930.        fi;
  1931.        local abs_paths=$(egrep -n '^[-+]{3} /' "${PATCH_TARGET}" | awk '$2 != "/dev/null" { print }');
  1932.        if [[ -n ${abs_paths} ]]; then
  1933.            count=1;
  1934.            printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}";
  1935.        fi;
  1936.         local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}");
  1937.        if [[ -n ${rel_paths} ]]; then
  1938.            eqawarn "QA Notice: Your patch uses relative paths '../'.";
  1939.            eqawarn " In the future this will cause a failure.";
  1940.            eqawarn "${rel_paths}";
  1941.        fi;
  1942.        local patch_cmd;
  1943.        while [[ ${count} -lt 5 ]]; do
  1944.            patch_cmd="${BASH_ALIASES[patch]:-patch} -p${count} ${EPATCH_OPTS}";
  1945.            ( _epatch_draw_line "***** ${patchname} *****";
  1946.            echo;
  1947.            echo "PATCH COMMAND:  ${patch_cmd} < '${PATCH_TARGET}'";
  1948.            echo;
  1949.            _epatch_draw_line "***** ${patchname} *****";
  1950.            ${patch_cmd} --dry-run -f < "${PATCH_TARGET}" 2>&1;
  1951.            ret=$?;
  1952.            echo;
  1953.            echo "patch program exited with status ${ret}";
  1954.            exit ${ret} ) >> "${STDERR_TARGET}";
  1955.            if [ $? -eq 0 ]; then
  1956.                ( _epatch_draw_line "***** ${patchname} *****";
  1957.                echo;
  1958.                echo "ACTUALLY APPLYING ${patchname} ...";
  1959.                echo;
  1960.                _epatch_draw_line "***** ${patchname} *****";
  1961.                ${patch_cmd} < "${PATCH_TARGET}" 2>&1;
  1962.                ret=$?;
  1963.                echo;
  1964.                echo "patch program exited with status ${ret}";
  1965.                exit ${ret} ) >> "${STDERR_TARGET}";
  1966.                if [ $? -ne 0 ]; then
  1967.                    echo;
  1968.                    eerror "A dry-run of patch command succeeded, but actually";
  1969.                    eerror "applying the patch failed!";
  1970.                    count=5;
  1971.                fi;
  1972.                break;
  1973.            fi;
  1974.            : $(( count++ ));
  1975.        done;
  1976.        if [[ -n ${PIPE_CMD} ]]; then
  1977.            rm -f "${PATCH_TARGET}";
  1978.        fi;
  1979.        if [[ ${count} -ge 5 ]]; then
  1980.            echo;
  1981.            eerror "Failed Patch: ${patchname} !";
  1982.            eerror " ( ${PATCH_TARGET} )";
  1983.            eerror;
  1984.            eerror "Include in your bugreport the contents of:";
  1985.            eerror;
  1986.            eerror "  ${STDERR_TARGET}";
  1987.            echo;
  1988.            die "Failed Patch: ${patchname}!";
  1989.        fi;
  1990.        rm -f "${STDERR_TARGET}";
  1991.        cat >> "${T}/epatch.log"  <<-EOF
  1992. PATCH: ${x}
  1993. CMD: ${patch_cmd}
  1994. PWD: ${PWD}
  1995.  
  1996. EOF
  1997.  
  1998.        eend 0;
  1999.    done;
  2000.    [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching";
  2001.    :
  2002. }
  2003. epatch_user ()
  2004. {
  2005.    [[ $# -ne 0 ]] && die "epatch_user takes no options";
  2006.    local applied="${T}/epatch_user.log";
  2007.    [[ -e ${applied} ]] && return 2;
  2008.    local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches;
  2009.    for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}{,:${SLOT}};
  2010.    do
  2011.        EPATCH_SOURCE=${base}/${CTARGET}/${check};
  2012.        [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check};
  2013.        [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check};
  2014.        if [[ -d ${EPATCH_SOURCE} ]]; then
  2015.            EPATCH_SOURCE=${EPATCH_SOURCE} EPATCH_SUFFIX="patch" EPATCH_FORCE="yes" EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." epatch;
  2016.            echo "${EPATCH_SOURCE}" > "${applied}";
  2017.            return 0;
  2018.        fi;
  2019.    done;
  2020.    echo "none" > "${applied}";
  2021.    return 1
  2022. }
  2023. epause ()
  2024. {
  2025.    ewarn "QA Notice: epause is not defined in EAPI=${EAPI}, please file a bug at http://bugs.gentoo.org"
  2026. }
  2027. epunt_cxx ()
  2028. {
  2029.    local dir=$1;
  2030.    [[ -z ${dir} ]] && dir=${S};
  2031.    ebegin "Removing useless C++ checks";
  2032.    local f any_found;
  2033.    find "${dir}" -name configure | while read f; do
  2034.        patch --no-backup-if-mismatch -p0 "${f}" "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null && any_found=1;
  2035.    done;
  2036.    if [[ -z ${any_found} ]]; then
  2037.        eqawarn "epunt_cxx called unnecessarily (no C++ checks to punt).";
  2038.    fi;
  2039.    eend 0
  2040. }
  2041. esethome ()
  2042. {
  2043.    _assert_pkg_ebuild_phase ${FUNCNAME};
  2044.    local euser=$1;
  2045.    shift;
  2046.    if [[ -z ${euser} ]]; then
  2047.        eerror "No username specified !";
  2048.        die "Cannot call esethome without a username";
  2049.    fi;
  2050.    if [[ -z $(egetent passwd "${euser}") ]]; then
  2051.        ewarn "User does not exist, cannot set home dir -- skipping.";
  2052.        return 1;
  2053.    fi;
  2054.    local ehome=$1;
  2055.    shift;
  2056.    if [[ -z ${ehome} ]]; then
  2057.        eerror "No home directory specified !";
  2058.        die "Cannot call esethome without a home directory or '-1'";
  2059.    fi;
  2060.    if [[ ${ehome} == "-1" ]]; then
  2061.        ehome="/dev/null";
  2062.    fi;
  2063.    if [[ $(egethome "${euser}") == ${ehome} ]]; then
  2064.        return 0;
  2065.    fi;
  2066.    einfo "Updating home for user '${euser}' ...";
  2067.    einfo " - Home: ${ehome}";
  2068.    if [[ ! -e ${ROOT}/${ehome} ]]; then
  2069.        einfo " - Creating ${ehome} in ${ROOT}";
  2070.        mkdir -p "${ROOT}/${ehome}";
  2071.        chown "${euser}" "${ROOT}/${ehome}";
  2072.        chmod 755 "${ROOT}/${ehome}";
  2073.    fi;
  2074.    case ${CHOST} in
  2075.        *-darwin*)
  2076.            dscl . change "/users/${euser}" home "${ehome}"
  2077.        ;;
  2078.        *-freebsd* | *-dragonfly*)
  2079.            pw usermod "${euser}" -d "${ehome}" && return 0;
  2080.            [[ $? == 8 ]] && eerror "${euser} is in use, cannot update home";
  2081.            eerror "There was an error when attempting to update the home directory for ${euser}";
  2082.            eerror "Please update it manually on your system:";
  2083.            eerror "\t pw usermod \"${euser}\" -d \"${ehome}\""
  2084.        ;;
  2085.        *)
  2086.            usermod -d "${ehome}" "${euser}" && return 0;
  2087.            [[ $? == 8 ]] && eerror "${euser} is in use, cannot update home";
  2088.            eerror "There was an error when attempting to update the home directory for ${euser}";
  2089.            eerror "Please update it manually on your system (as root):";
  2090.            eerror "\t usermod -d \"${ehome}\" \"${euser}\""
  2091.        ;;
  2092.    esac
  2093. }
  2094. eshopts_pop ()
  2095. {
  2096.    local s;
  2097.    estack_pop eshopts s || die "${FUNCNAME}: unbalanced push";
  2098.    if [[ ${s} == "shopt -"* ]]; then
  2099.        eval "${s}" || die "${FUNCNAME}: sanity: invalid shopt options: ${s}";
  2100.    else
  2101.        set +$- || die "${FUNCNAME}: sanity: invalid shell settings: $-";
  2102.        set -${s} || die "${FUNCNAME}: sanity: unable to restore saved shell settings: ${s}";
  2103.    fi
  2104. }
  2105. eshopts_push ()
  2106. {
  2107.    if [[ $1 == -[su] ]]; then
  2108.        estack_push eshopts "$(shopt -p)";
  2109.        [[ $# -eq 0 ]] && return 0;
  2110.        shopt "$@" || die "${FUNCNAME}: bad options to shopt: $*";
  2111.    else
  2112.        estack_push eshopts $-;
  2113.        [[ $# -eq 0 ]] && return 0;
  2114.        set "$@" || die "${FUNCNAME}: bad options to set: $*";
  2115.    fi
  2116. }
  2117. estack_pop ()
  2118. {
  2119.    [[ $# -eq 0 || $# -gt 2 ]] && die "estack_pop: incorrect # of arguments";
  2120.     local __estack_name="__ESTACK_$1__";
  2121.     shift;
  2122.     local __estack_retvar=$1;
  2123.     shift;
  2124.     eval local __estack_i=\${#${__estack_name}\[@\]};
  2125.     [[ $(( --__estack_i )) -eq -1 ]] && return 1;
  2126.     if [[ -n ${__estack_retvar} ]]; then
  2127.         eval ${__estack_retvar}=\"\${${__estack_name}\[${__estack_i}\]}\";
  2128.     fi;
  2129.     eval unset ${__estack_name}\[${__estack_i}\]
  2130. }
  2131. estack_push ()
  2132. {
  2133.     [[ $# -eq 0 ]] && die "estack_push: incorrect # of arguments";
  2134.     local stack_name="__ESTACK_$1__";
  2135.     shift;
  2136.     eval ${stack_name}+=\( \"\$@\" \)
  2137. }
  2138. esvn_clean ()
  2139. {
  2140.     [[ -z $* ]] && set -- .;
  2141.     find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf
  2142. }
  2143. eumask_pop ()
  2144. {
  2145.     [[ $# -eq 0 ]] || die "${FUNCNAME}: we take no options";
  2146.     local s;
  2147.     estack_pop eumask s || die "${FUNCNAME}: unbalanced push";
  2148.     umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}"
  2149. }
  2150. eumask_push ()
  2151. {
  2152.     estack_push eumask "$(umask)";
  2153.     umask "$@" || die "${FUNCNAME}: bad options to umask: $*"
  2154. }
  2155. filter-flags ()
  2156. {
  2157.     _filter-hardened "$@";
  2158.     local v;
  2159.     for v in $(all-flag-vars);
  2160.     do
  2161.         _filter-var ${v} "$@";
  2162.     done;
  2163.     return 0
  2164. }
  2165. filter-ldflags ()
  2166. {
  2167.     _filter-var LDFLAGS "$@";
  2168.     return 0
  2169. }
  2170. filter-lfs-flags ()
  2171. {
  2172.     [[ $# -ne 0 ]] && die "filter-lfs-flags takes no arguments";
  2173.     filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
  2174. }
  2175. filter-mfpmath ()
  2176. {
  2177.     local orig_mfpmath new_math prune_math;
  2178.     orig_mfpmath=$(get-flag -mfpmath);
  2179.     new_math=$(get-flag mfpmath);
  2180.     new_math=" ${new_math//,/ } ";
  2181.     prune_math="";
  2182.     for prune_math in "$@";
  2183.     do
  2184.         new_math=${new_math/ ${prune_math} / };
  2185.     done;
  2186.     new_math=$(echo ${new_math});
  2187.     new_math=${new_math// /,};
  2188.     if [[ -z ${new_math} ]]; then
  2189.         filter-flags ${orig_mfpmath};
  2190.     else
  2191.         replace-flags ${orig_mfpmath} -mfpmath=${new_math};
  2192.     fi;
  2193.     return 0
  2194. }
  2195. gcc-fullversion ()
  2196. {
  2197.     _gcc_fullversion '$1.$2.$3' "$@"
  2198. }
  2199. gcc-major-version ()
  2200. {
  2201.     _gcc_fullversion '$1' "$@"
  2202. }
  2203. gcc-micro-version ()
  2204. {
  2205.     _gcc_fullversion '$3' "$@"
  2206. }
  2207. gcc-minor-version ()
  2208. {
  2209.     _gcc_fullversion '$2' "$@"
  2210. }
  2211. gcc-specs-directive ()
  2212. {
  2213.     local directive subdname subdirective;
  2214.     directive="$(_gcc-specs-directive_raw $1)";
  2215.     while [[ ${directive} == *%\(*\)* ]]; do
  2216.         subdname=${directive/*%\(};
  2217.         subdname=${subdname/\)*};
  2218.         subdirective="$(_gcc-specs-directive_raw ${subdname})";
  2219.         directive="${directive//\%(${subdname})/${subdirective}}";
  2220.     done;
  2221.     echo "${directive}";
  2222.     return 0
  2223. }
  2224. gcc-specs-nostrict ()
  2225. {
  2226.     local directive;
  2227.     directive=$(gcc-specs-directive cc1);
  2228.     return $([[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]])
  2229. }
  2230. gcc-specs-now ()
  2231. {
  2232.     local directive;
  2233.     directive=$(gcc-specs-directive link_command);
  2234.     return $([[ "${directive/\{!nonow:}" != "${directive}" ]])
  2235. }
  2236. gcc-specs-pie ()
  2237. {
  2238.     local directive;
  2239.     directive=$(gcc-specs-directive cc1);
  2240.     return $([[ "${directive/\{!nopie:}" != "${directive}" ]])
  2241. }
  2242. gcc-specs-relro ()
  2243. {
  2244.     local directive;
  2245.     directive=$(gcc-specs-directive link_command);
  2246.     return $([[ "${directive/\{!norelro:}" != "${directive}" ]])
  2247. }
  2248. gcc-specs-ssp ()
  2249. {
  2250.     local directive;
  2251.     directive=$(gcc-specs-directive cc1);
  2252.     return $([[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]])
  2253. }
  2254. gcc-specs-ssp-to-all ()
  2255. {
  2256.     local directive;
  2257.     directive=$(gcc-specs-directive cc1);
  2258.     return $([[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]])
  2259. }
  2260. gcc-version ()
  2261. {
  2262.     _gcc_fullversion '$1.$2' "$@"
  2263. }
  2264. gen_usr_ldscript ()
  2265. {
  2266.     local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname);
  2267.     [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/;
  2268.     tc-is-static-only && return;
  2269.     case ${CTARGET:-${CHOST}} in
  2270.         *-darwin*)
  2271.  
  2272.         ;;
  2273.         *linux* | *-freebsd* | *-openbsd* | *-netbsd*)
  2274.             use prefix && return 0
  2275.         ;;
  2276.         *)
  2277.             return 0
  2278.         ;;
  2279.     esac;
  2280.     dodir /usr/${libdir};
  2281.     if [[ $1 == "-a" ]]; then
  2282.         auto=true;
  2283.         shift;
  2284.         dodir /${libdir};
  2285.     fi;
  2286.     output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p');
  2287.     [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )";
  2288.     for lib in "$@";
  2289.     do
  2290.         local tlib;
  2291.         if ${auto}; then
  2292.             lib="lib${lib}${suffix}";
  2293.         else
  2294.             [[ -r ${ED}/${libdir}/${lib} ]] || continue;
  2295.         fi;
  2296.         case ${CTARGET:-${CHOST}} in
  2297.             *-darwin*)
  2298.                 if ${auto}; then
  2299.                     tlib=$(scanmacho -qF'%S#F' "${ED}"/usr/${libdir}/${lib});
  2300.                 else
  2301.                     tlib=$(scanmacho -qF'%S#F' "${ED}"/${libdir}/${lib});
  2302.                 fi;
  2303.                 [[ -z ${tlib} ]] && die "unable to read install_name from ${lib}";
  2304.                 tlib=${tlib##*/};
  2305.                 if ${auto}; then
  2306.                     mv "${ED}"/usr/${libdir}/${lib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die;
  2307.                     if [[ ${tlib} != ${lib%${suffix}}.*${suffix#.} ]]; then
  2308.                         mv "${ED}"/usr/${libdir}/${tlib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die;
  2309.                     fi;
  2310.                     rm -f "${ED}"/${libdir}/${lib};
  2311.                 fi;
  2312.                 if [[ ! -w "${ED}/${libdir}/${tlib}" ]]; then
  2313.                     chmod u+w "${ED}${libdir}/${tlib}";
  2314.                     local nowrite=yes;
  2315.                 fi;
  2316.                 install_name_tool -id "${EPREFIX}"/${libdir}/${tlib} "${ED}"/${libdir}/${tlib} || die "install_name_tool failed";
  2317.                 [[ -n ${nowrite} ]] && chmod u-w "${ED}${libdir}/${tlib}";
  2318.                 pushd "${ED}/usr/${libdir}" > /dev/null;
  2319.                 ln -snf "../../${libdir}/${tlib}" "${lib}";
  2320.                 popd > /dev/null
  2321.             ;;
  2322.             *)
  2323.                 if ${auto}; then
  2324.                     tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib});
  2325.                     [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}";
  2326.                     mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die;
  2327.                     if [[ ${tlib} != ${lib}* ]]; then
  2328.                         mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die;
  2329.                     fi;
  2330.                     rm -f "${ED}"/${libdir}/${lib};
  2331.                 else
  2332.                     tlib=${lib};
  2333.                 fi;
  2334.                 cat > "${ED}/usr/${libdir}/${lib}"  <<-END_LDSCRIPT
  2335. /* GNU ld script
  2336.    Since Gentoo has critical dynamic libraries in /lib, and the static versions
  2337.    in /usr/lib, we need to have a "fake" dynamic lib in /usr/lib, otherwise we
  2338.    run into linking problems.  This "fake" dynamic lib is a linker script that
  2339.    redirects the linker to the real lib.  And yes, this works in the cross-
  2340.    compiling scenario as the sysroot-ed linker will prepend the real path.
  2341.  
  2342.    See bug http://bugs.gentoo.org/4411 for more info.
  2343.  */
  2344. ${output_format}
  2345. GROUP ( ${EPREFIX}/${libdir}/${tlib} )
  2346. END_LDSCRIPT
  2347.  
  2348.             ;;
  2349.         esac
  2350.         fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}";
  2351.     done
  2352. }
  2353. get-flag ()
  2354. {
  2355.     local f var findflag="$1";
  2356.     for var in $(all-flag-vars);
  2357.     do
  2358.         for f in ${!var};
  2359.         do
  2360.             if [ "${f/${findflag}}" != "${f}" ]; then
  2361.                 printf "%s\n" "${f/-${findflag}=}";
  2362.                 return 0;
  2363.             fi;
  2364.         done;
  2365.     done;
  2366.     return 1
  2367. }
  2368. get_abi_CFLAGS ()
  2369. {
  2370.     get_abi_var CFLAGS "$@"
  2371. }
  2372. get_abi_CHOST ()
  2373. {
  2374.     get_abi_var CHOST "$@"
  2375. }
  2376. get_abi_CTARGET ()
  2377. {
  2378.     get_abi_var CTARGET "$@"
  2379. }
  2380. get_abi_FAKE_TARGETS ()
  2381. {
  2382.     get_abi_var FAKE_TARGETS "$@"
  2383. }
  2384. get_abi_LDFLAGS ()
  2385. {
  2386.     get_abi_var LDFLAGS "$@"
  2387. }
  2388. get_abi_LIBDIR ()
  2389. {
  2390.     get_abi_var LIBDIR "$@"
  2391. }
  2392. get_abi_var ()
  2393. {
  2394.     local flag=$1;
  2395.     local abi=${2:-${ABI:-${DEFAULT_ABI:-default}}};
  2396.     local var="${flag}_${abi}";
  2397.     echo ${!var}
  2398. }
  2399. get_all_abis ()
  2400. {
  2401.     local x order="" mvar dvar;
  2402.     mvar="MULTILIB_ABIS";
  2403.     dvar="DEFAULT_ABI";
  2404.     if [[ -n $1 ]]; then
  2405.         mvar="$1_${mvar}";
  2406.         dvar="$1_${dvar}";
  2407.     fi;
  2408.     if [[ -z ${!mvar} ]]; then
  2409.         echo "default";
  2410.         return 0;
  2411.     fi;
  2412.     for x in ${!mvar};
  2413.     do
  2414.         if [[ ${x} != ${!dvar} ]]; then
  2415.             order="${order:+${order} }${x}";
  2416.         fi;
  2417.     done;
  2418.     order="${order:+${order} }${!dvar}";
  2419.     echo ${order};
  2420.     return 0
  2421. }
  2422. get_all_libdirs ()
  2423. {
  2424.     local libdirs abi;
  2425.     for abi in ${MULTILIB_ABIS};
  2426.     do
  2427.         libdirs+=" $(get_abi_LIBDIR ${abi})";
  2428.     done;
  2429.     [[ " ${libdirs} " != *" lib "* ]] && libdirs+=" lib";
  2430.     echo "${libdirs}"
  2431. }
  2432. get_install_abis ()
  2433. {
  2434.     local x order="";
  2435.     if [[ -z ${MULTILIB_ABIS} ]]; then
  2436.         echo "default";
  2437.         return 0;
  2438.     fi;
  2439.     if [[ ${EMULTILIB_PKG} == "true" ]]; then
  2440.         for x in ${MULTILIB_ABIS};
  2441.         do
  2442.             if [[ ${x} != "${DEFAULT_ABI}" ]]; then
  2443.                 has ${x} ${ABI_DENY} || order="${order} ${x}";
  2444.             fi;
  2445.         done;
  2446.         has ${DEFAULT_ABI} ${ABI_DENY} || order="${order} ${DEFAULT_ABI}";
  2447.         if [[ -n ${ABI_ALLOW} ]]; then
  2448.             local ordera="";
  2449.             for x in ${order};
  2450.             do
  2451.                 if has ${x} ${ABI_ALLOW}; then
  2452.                     ordera="${ordera} ${x}";
  2453.                 fi;
  2454.             done;
  2455.             order=${ordera};
  2456.         fi;
  2457.     else
  2458.         order=${DEFAULT_ABI};
  2459.     fi;
  2460.     if [[ -z ${order} ]]; then
  2461.         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.";
  2462.     fi;
  2463.     echo ${order};
  2464.     return 0
  2465. }
  2466. get_libdir ()
  2467. {
  2468.     local CONF_LIBDIR;
  2469.     if [ -n "${CONF_LIBDIR_OVERRIDE}" ]; then
  2470.         echo ${CONF_LIBDIR_OVERRIDE};
  2471.     else
  2472.         get_abi_LIBDIR;
  2473.     fi
  2474. }
  2475. get_libname ()
  2476. {
  2477.     local libname;
  2478.     local ver=$1;
  2479.     case ${CHOST} in
  2480.         *-cygwin | mingw* | *-mingw*)
  2481.             libname="dll"
  2482.         ;;
  2483.         *-darwin*)
  2484.             libname="dylib"
  2485.         ;;
  2486.         *-mint*)
  2487.             libname="irrelevant"
  2488.         ;;
  2489.         hppa*-hpux*)
  2490.             libname="sl"
  2491.         ;;
  2492.         *)
  2493.             libname="so"
  2494.         ;;
  2495.     esac;
  2496.     if [[ -z $* ]]; then
  2497.         echo ".${libname}";
  2498.     else
  2499.         for ver in "$@";
  2500.         do
  2501.             case ${CHOST} in
  2502.                 *-darwin*)
  2503.                     echo ".${ver}.${libname}"
  2504.                 ;;
  2505.                 *-mint*)
  2506.                     echo ".${libname}"
  2507.                 ;;
  2508.                 *)
  2509.                     echo ".${libname}.${ver}"
  2510.                 ;;
  2511.             esac;
  2512.         done;
  2513.     fi
  2514. }
  2515. get_modname ()
  2516. {
  2517.     local modname;
  2518.     local ver=$1;
  2519.     case ${CHOST} in
  2520.         *-darwin*)
  2521.             modname="bundle"
  2522.         ;;
  2523.         *)
  2524.             modname="so"
  2525.         ;;
  2526.     esac;
  2527.     echo ".${modname}"
  2528. }
  2529. has_m32 ()
  2530. {
  2531.     die "${FUNCNAME}: don't use this anymore"
  2532. }
  2533. has_m64 ()
  2534. {
  2535.     eqawarn "${FUNCNAME}: don't use this anymore";
  2536.     local temp="$(emktemp)";
  2537.     echo "int main() { return(0); }" > "${temp}".c;
  2538.     MY_CC=$(tc-getCC);
  2539.     ${MY_CC/ .*/} -m64 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1;
  2540.     local ret=$?;
  2541.     rm -f "${temp}".c;
  2542.     [[ ${ret} != 1 ]] && return 0;
  2543.     return 1
  2544. }
  2545. has_multilib_profile ()
  2546. {
  2547.     [ -n "${MULTILIB_ABIS}" -a "${MULTILIB_ABIS}" != "${MULTILIB_ABIS/ /}" ]
  2548. }
  2549. in_iuse ()
  2550. {
  2551.     debug-print-function ${FUNCNAME} "${@}";
  2552.     [[ ${#} -eq 1 ]] || die "Invalid args to ${FUNCNAME}()";
  2553.     local flag=${1};
  2554.     local liuse=(${IUSE});
  2555.     has "${flag}" "${liuse[@]#[+-]}"
  2556. }
  2557. is-flag ()
  2558. {
  2559.     is-flagq "$@" && echo true
  2560. }
  2561. is-flagq ()
  2562. {
  2563.     [[ -n $2 ]] && die "Usage: is-flag <flag>";
  2564.     local var;
  2565.     for var in $(all-flag-vars);
  2566.     do
  2567.         _is_flagq ${var} "$1" && return 0;
  2568.     done;
  2569.     return 1
  2570. }
  2571. is-ldflag ()
  2572. {
  2573.     is-ldflagq "$@" && echo true
  2574. }
  2575. is-ldflagq ()
  2576. {
  2577.     [[ -n $2 ]] && die "Usage: is-ldflag <flag>";
  2578.     _is_flagq LDFLAGS $1
  2579. }
  2580. is_final_abi ()
  2581. {
  2582.     has_multilib_profile || return 0;
  2583.     set -- $(get_install_abis);
  2584.     local LAST_ABI=$#;
  2585.     [[ ${!LAST_ABI} == ${ABI} ]]
  2586. }
  2587. make_desktop_entry ()
  2588. {
  2589.     [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable";
  2590.     local exec=${1};
  2591.     local name=${2:-${PN}};
  2592.     local icon=${3:-${PN}};
  2593.     local type=${4};
  2594.     local fields=${5};
  2595.     if [[ -z ${type} ]]; then
  2596.         local catmaj=${CATEGORY%%-*};
  2597.         local catmin=${CATEGORY##*-};
  2598.         case ${catmaj} in
  2599.             app)
  2600.                 case ${catmin} in
  2601.                     accessibility)
  2602.                         type="Utility;Accessibility"
  2603.                     ;;
  2604.                     admin)
  2605.                         type=System
  2606.                     ;;
  2607.                     antivirus)
  2608.                         type=System
  2609.                     ;;
  2610.                     arch)
  2611.                         type="Utility;Archiving"
  2612.                     ;;
  2613.                     backup)
  2614.                         type="Utility;Archiving"
  2615.                     ;;
  2616.                     cdr)
  2617.                         type="AudioVideo;DiscBurning"
  2618.                     ;;
  2619.                     dicts)
  2620.                         type="Office;Dictionary"
  2621.                     ;;
  2622.                     doc)
  2623.                         type=Documentation
  2624.                     ;;
  2625.                     editors)
  2626.                         type="Utility;TextEditor"
  2627.                     ;;
  2628.                     emacs)
  2629.                         type="Development;TextEditor"
  2630.                     ;;
  2631.                     emulation)
  2632.                         type="System;Emulator"
  2633.                     ;;
  2634.                     laptop)
  2635.                         type="Settings;HardwareSettings"
  2636.                     ;;
  2637.                     office)
  2638.                         type=Office
  2639.                     ;;
  2640.                     pda)
  2641.                         type="Office;PDA"
  2642.                     ;;
  2643.                     vim)
  2644.                         type="Development;TextEditor"
  2645.                     ;;
  2646.                     xemacs)
  2647.                         type="Development;TextEditor"
  2648.                     ;;
  2649.                 esac
  2650.             ;;
  2651.             dev)
  2652.                 type="Development"
  2653.             ;;
  2654.             games)
  2655.                 case ${catmin} in
  2656.                     action | fps)
  2657.                         type=ActionGame
  2658.                     ;;
  2659.                     arcade)
  2660.                         type=ArcadeGame
  2661.                     ;;
  2662.                     board)
  2663.                         type=BoardGame
  2664.                     ;;
  2665.                     emulation)
  2666.                         type=Emulator
  2667.                     ;;
  2668.                     kids)
  2669.                         type=KidsGame
  2670.                     ;;
  2671.                     puzzle)
  2672.                         type=LogicGame
  2673.                     ;;
  2674.                     roguelike)
  2675.                         type=RolePlaying
  2676.                     ;;
  2677.                     rpg)
  2678.                         type=RolePlaying
  2679.                     ;;
  2680.                     simulation)
  2681.                         type=Simulation
  2682.                     ;;
  2683.                     sports)
  2684.                         type=SportsGame
  2685.                     ;;
  2686.                     strategy)
  2687.                         type=StrategyGame
  2688.                     ;;
  2689.                 esac;
  2690.                 type="Game;${type}"
  2691.             ;;
  2692.             gnome)
  2693.                 type="Gnome;GTK"
  2694.             ;;
  2695.             kde)
  2696.                 type="KDE;Qt"
  2697.             ;;
  2698.             mail)
  2699.                 type="Network;Email"
  2700.             ;;
  2701.             media)
  2702.                 case ${catmin} in
  2703.                     gfx)
  2704.                         type=Graphics
  2705.                     ;;
  2706.                     *)
  2707.                         case ${catmin} in
  2708.                             radio)
  2709.                                 type=Tuner
  2710.                             ;;
  2711.                             sound)
  2712.                                 type=Audio
  2713.                             ;;
  2714.                             tv)
  2715.                                 type=TV
  2716.                             ;;
  2717.                             video)
  2718.                                 type=Video
  2719.                             ;;
  2720.                         esac;
  2721.                         type="AudioVideo;${type}"
  2722.                     ;;
  2723.                 esac
  2724.             ;;
  2725.             net)
  2726.                 case ${catmin} in
  2727.                     dialup)
  2728.                         type=Dialup
  2729.                     ;;
  2730.                     ftp)
  2731.                         type=FileTransfer
  2732.                     ;;
  2733.                     im)
  2734.                         type=InstantMessaging
  2735.                     ;;
  2736.                     irc)
  2737.                         type=IRCClient
  2738.                     ;;
  2739.                     mail)
  2740.                         type=Email
  2741.                     ;;
  2742.                     news)
  2743.                         type=News
  2744.                     ;;
  2745.                     nntp)
  2746.                         type=News
  2747.                     ;;
  2748.                     p2p)
  2749.                         type=FileTransfer
  2750.                     ;;
  2751.                     voip)
  2752.                         type=Telephony
  2753.                     ;;
  2754.                 esac;
  2755.                 type="Network;${type}"
  2756.             ;;
  2757.             sci)
  2758.                 case ${catmin} in
  2759.                     astro*)
  2760.                         type=Astronomy
  2761.                     ;;
  2762.                     bio*)
  2763.                         type=Biology
  2764.                     ;;
  2765.                     calc*)
  2766.                         type=Calculator
  2767.                     ;;
  2768.                     chem*)
  2769.                         type=Chemistry
  2770.                     ;;
  2771.                     elec*)
  2772.                         type=Electronics
  2773.                     ;;
  2774.                     geo*)
  2775.                         type=Geology
  2776.                     ;;
  2777.                     math*)
  2778.                         type=Math
  2779.                     ;;
  2780.                     physics)
  2781.                         type=Physics
  2782.                     ;;
  2783.                     visual*)
  2784.                         type=DataVisualization
  2785.                     ;;
  2786.                 esac;
  2787.                 type="Education;Science;${type}"
  2788.             ;;
  2789.             sys)
  2790.                 type="System"
  2791.             ;;
  2792.             www)
  2793.                 case ${catmin} in
  2794.                     client)
  2795.                         type=WebBrowser
  2796.                     ;;
  2797.                 esac;
  2798.                 type="Network;${type}"
  2799.             ;;
  2800.             *)
  2801.                 type=
  2802.             ;;
  2803.         esac;
  2804.     fi;
  2805.     if [ "${SLOT}" == "0" ]; then
  2806.         local desktop_name="${PN}";
  2807.     else
  2808.         local desktop_name="${PN}-${SLOT}";
  2809.     fi;
  2810.     local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop";
  2811.     type=${type%;}${type:+;};
  2812.     eshopts_push -s extglob;
  2813.     if [[ -n ${icon} && ${icon} != /* ]] && [[ ${icon} == *.xpm || ${icon} == *.png || ${icon} == *.svg ]]; then
  2814.         ewarn "As described in the Icon Theme Specification, icon file extensions are not";
  2815.         ewarn "allowed in .desktop files if the value is not an absolute path.";
  2816.         icon=${icon%.@(xpm|png|svg)};
  2817.     fi;
  2818.     eshopts_pop;
  2819.     cat > "${desktop}"  <<-EOF
  2820. [Desktop Entry]
  2821. Name=${name}
  2822. Type=Application
  2823. Comment=${DESCRIPTION}
  2824. Exec=${exec}
  2825. TryExec=${exec%% *}
  2826. Icon=${icon}
  2827. Categories=${type}
  2828. EOF
  2829.  
  2830.     if [[ ${fields:-=} != *=* ]]; then
  2831.         ewarn "make_desktop_entry: update your 5th arg to read Path=${fields}";
  2832.         fields="Path=${fields}";
  2833.     fi;
  2834.     [[ -n ${fields} ]] && printf '%b\n' "${fields}" >> "${desktop}";
  2835.     ( insinto /usr/share/applications;
  2836.     doins "${desktop}" ) || die "installing desktop file failed"
  2837. }
  2838. make_session_desktop ()
  2839. {
  2840.     [[ -z $1 ]] && eerror "$0: You must specify the title" && return 1;
  2841.     [[ -z $2 ]] && eerror "$0: You must specify the command" && return 1;
  2842.     local title=$1;
  2843.     local command=$2;
  2844.     local desktop=${T}/${wm:-${PN}}.desktop;
  2845.     shift 2;
  2846.     cat > "${desktop}"  <<-EOF
  2847. [Desktop Entry]
  2848. Name=${title}
  2849. Comment=This session logs you into ${title}
  2850. Exec=${command} $*
  2851. TryExec=${command}
  2852. Type=XSession
  2853. EOF
  2854.  
  2855.     ( insinto /usr/share/xsessions;
  2856.     doins "${desktop}" )
  2857. }
  2858. make_wrapper ()
  2859. {
  2860.     local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5;
  2861.     local tmpwrapper=$(emktemp);
  2862.     cat > "${tmpwrapper}"  <<EOF
  2863. #!/bin/sh
  2864. cd "${chdir:-.}"
  2865. if [ -n "${libdir}" ] ; then
  2866.     if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
  2867.         export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
  2868.     else
  2869.         export LD_LIBRARY_PATH="${libdir}"
  2870.     fi
  2871. fi
  2872. exec ${bin} "\$@"
  2873. EOF
  2874.  
  2875.     chmod go+rx "${tmpwrapper}";
  2876.     if [[ -n ${path} ]]; then
  2877.         ( exeinto "${path}";
  2878.         newexe "${tmpwrapper}" "${wrapper}" ) || die;
  2879.     else
  2880.         newbin "${tmpwrapper}" "${wrapper}" || die;
  2881.     fi
  2882. }
  2883. makeopts_jobs ()
  2884. {
  2885.     [[ $# -eq 0 ]] && set -- ${MAKEOPTS};
  2886.     local jobs=$(echo " $* " | sed -r -n        -e 's:.*[[:space:]](-j|--jobs[=[:space:]])[[:space:]]*([0-9]+).*:\2:p'      -e 's:.*[[:space:]](-j|--jobs)[[:space:]].*:999:p');
  2887.     echo ${jobs:-1}
  2888. }
  2889. multijob_child_init ()
  2890. {
  2891.     local mode="pre";
  2892.     case $1 in
  2893.         --pre)
  2894.             mode="pre";
  2895.             shift
  2896.         ;;
  2897.         --post)
  2898.             mode="post";
  2899.             shift
  2900.         ;;
  2901.     esac;
  2902.     if [[ $# -eq 0 ]]; then
  2903.         trap 'echo ${BASHPID} $? >&'${mj_control_fd} EXIT;
  2904.         trap 'exit 1' INT TERM;
  2905.     else
  2906.         local ret;
  2907.         [[ ${mode} == "pre" ]] && {
  2908.             multijob_pre_fork;
  2909.             ret=$?
  2910.         };
  2911.         ( multijob_child_init;
  2912.         "$@" ) & [[ ${mode} == "post" ]] && {
  2913.             multijob_post_fork;
  2914.             ret=$?
  2915.         };
  2916.         return ${ret};
  2917.     fi
  2918. }
  2919. multijob_finish ()
  2920. {
  2921.     local ret=0;
  2922.     while [[ ${mj_num_jobs} -gt 0 ]]; do
  2923.         multijob_finish_one;
  2924.         : $(( ret |= $? ));
  2925.     done;
  2926.     wait;
  2927.     [[ $# -eq 0 ]] || die "${FUNCNAME} takes no arguments";
  2928.     EBUILD_DEATH_HOOKS=${EBUILD_DEATH_HOOKS/ wait / };
  2929.     return ${ret}
  2930. }
  2931. multijob_finish_one ()
  2932. {
  2933.     [[ $# -eq 0 ]] || die "${FUNCNAME} takes no arguments";
  2934.     local pid ret;
  2935.     read -r -u ${mj_control_fd} pid ret || die;
  2936.     : $(( --mj_num_jobs ));
  2937.     return ${ret}
  2938. }
  2939. multijob_init ()
  2940. {
  2941.     has wait ${EBUILD_DEATH_HOOKS} || EBUILD_DEATH_HOOKS+=" wait ";
  2942.     local pipe="${T}/multijob.pipe";
  2943.     mkfifo "${pipe}";
  2944.     redirect_alloc_fd mj_control_fd "${pipe}";
  2945.     rm -f "${pipe}";
  2946.     mj_max_jobs=$(makeopts_jobs "$@");
  2947.     mj_num_jobs=0
  2948. }
  2949. multijob_post_fork ()
  2950. {
  2951.     _multijob_fork post "$@"
  2952. }
  2953. multijob_pre_fork ()
  2954. {
  2955.     _multijob_fork pre "$@"
  2956. }
  2957. multilib_env ()
  2958. {
  2959.     local CTARGET=${1:-${CTARGET}};
  2960.     case ${CTARGET} in
  2961.         x86_64*)
  2962.             export CFLAGS_x86=${CFLAGS_x86--m32};
  2963.             export CHOST_x86=${CTARGET/x86_64/i686};
  2964.             CHOST_x86=${CHOST_x86/%-gnux32/-gnu};
  2965.             export CTARGET_x86=${CHOST_x86};
  2966.             if [[ ${SYMLINK_LIB} == "yes" ]]; then
  2967.                 export LIBDIR_x86="lib32";
  2968.             else
  2969.                 export LIBDIR_x86="lib";
  2970.             fi;
  2971.             export CFLAGS_amd64=${CFLAGS_amd64--m64};
  2972.             export CHOST_amd64=${CTARGET/%-gnux32/-gnu};
  2973.             export CTARGET_amd64=${CHOST_amd64};
  2974.             export LIBDIR_amd64="lib64";
  2975.             export CFLAGS_x32=${CFLAGS_x32--mx32};
  2976.             export CHOST_x32=${CTARGET/%-gnu/-gnux32};
  2977.             export CTARGET_x32=${CHOST_x32};
  2978.             export LIBDIR_x32="libx32";
  2979.             case ${CTARGET} in
  2980.                 *-gnux32)
  2981.                     : ${MULTILIB_ABIS=x32 amd64 x86};
  2982.                     : ${DEFAULT_ABI=x32}
  2983.                 ;;
  2984.                 *)
  2985.                     : ${MULTILIB_ABIS=amd64 x86};
  2986.                     : ${DEFAULT_ABI=amd64}
  2987.                 ;;
  2988.             esac
  2989.         ;;
  2990.         mips64*)
  2991.             export CFLAGS_o32=${CFLAGS_o32--mabi=32};
  2992.             export CHOST_o32=${CTARGET/mips64/mips};
  2993.             export CTARGET_o32=${CHOST_o32};
  2994.             export LIBDIR_o32="lib";
  2995.             export CFLAGS_n32=${CFLAGS_n32--mabi=n32};
  2996.             export CHOST_n32=${CTARGET};
  2997.             export CTARGET_n32=${CHOST_n32};
  2998.             export LIBDIR_n32="lib32";
  2999.             export CFLAGS_n64=${CFLAGS_n64--mabi=64};
  3000.             export CHOST_n64=${CTARGET};
  3001.             export CTARGET_n64=${CHOST_n64};
  3002.             export LIBDIR_n64="lib64";
  3003.             : ${MULTILIB_ABIS=n64 n32 o32};
  3004.             : ${DEFAULT_ABI=n32}
  3005.         ;;
  3006.         powerpc64*)
  3007.             export CFLAGS_ppc=${CFLAGS_ppc--m32};
  3008.             export CHOST_ppc=${CTARGET/powerpc64/powerpc};
  3009.             export CTARGET_ppc=${CHOST_ppc};
  3010.             export LIBDIR_ppc="lib";
  3011.             export CFLAGS_ppc64=${CFLAGS_ppc64--m64};
  3012.             export CHOST_ppc64=${CTARGET};
  3013.             export CTARGET_ppc64=${CHOST_ppc64};
  3014.             export LIBDIR_ppc64="lib64";
  3015.             : ${MULTILIB_ABIS=ppc64 ppc};
  3016.             : ${DEFAULT_ABI=ppc64}
  3017.         ;;
  3018.         s390x*)
  3019.             export CFLAGS_s390=${CFLAGS_s390--m31};
  3020.             export CHOST_s390=${CTARGET/s390x/s390};
  3021.             export CTARGET_s390=${CHOST_s390};
  3022.             export LIBDIR_s390="lib";
  3023.             export CFLAGS_s390x=${CFLAGS_s390x--m64};
  3024.             export CHOST_s390x=${CTARGET};
  3025.             export CTARGET_s390x=${CHOST_s390x};
  3026.             export LIBDIR_s390x="lib64";
  3027.             : ${MULTILIB_ABIS=s390x s390};
  3028.             : ${DEFAULT_ABI=s390x}
  3029.         ;;
  3030.         sparc64*)
  3031.             export CFLAGS_sparc32=${CFLAGS_sparc32--m32};
  3032.             export CHOST_sparc32=${CTARGET/sparc64/sparc};
  3033.             export CTARGET_sparc32=${CHOST_sparc32};
  3034.             export LIBDIR_sparc32="lib";
  3035.             export CFLAGS_sparc64=${CFLAGS_sparc64--m64};
  3036.             export CHOST_sparc64=${CTARGET};
  3037.             export CTARGET_sparc64=${CHOST_sparc64};
  3038.             export LIBDIR_sparc64="lib64";
  3039.             : ${MULTILIB_ABIS=sparc64 sparc32};
  3040.             : ${DEFAULT_ABI=sparc64}
  3041.         ;;
  3042.         *)
  3043.             : ${MULTILIB_ABIS=default};
  3044.             : ${DEFAULT_ABI=default}
  3045.         ;;
  3046.     esac;
  3047.     export MULTILIB_ABIS DEFAULT_ABI
  3048. }
  3049. multilib_toolchain_setup ()
  3050. {
  3051.     local v vv;
  3052.     export ABI=$1;
  3053.     if [[ ${__DEFAULT_ABI_SAVED} == "true" ]]; then
  3054.         for v in CHOST CBUILD AS CC CXX LD PKG_CONFIG_{LIBDIR,PATH};
  3055.         do
  3056.             vv="__abi_saved_${v}";
  3057.             export ${v}="${!vv}";
  3058.             unset ${vv};
  3059.         done;
  3060.         unset __DEFAULT_ABI_SAVED;
  3061.     fi;
  3062.     if [[ ${ABI} != ${DEFAULT_ABI} ]]; then
  3063.         for v in CHOST CBUILD AS CC CXX LD PKG_CONFIG_{LIBDIR,PATH};
  3064.         do
  3065.             export __abi_saved_${v}="${!v}";
  3066.         done;
  3067.         export __DEFAULT_ABI_SAVED="true";
  3068.         export CHOST=$(get_abi_CHOST ${DEFAULT_ABI});
  3069.         export CC="$(tc-getCC) $(get_abi_CFLAGS)";
  3070.         export CXX="$(tc-getCXX) $(get_abi_CFLAGS)";
  3071.         export LD="$(tc-getLD) $(get_abi_LDFLAGS)";
  3072.         export CHOST=$(get_abi_CHOST $1);
  3073.         export CBUILD=$(get_abi_CHOST $1);
  3074.         export PKG_CONFIG_LIBDIR=${EPREFIX}/usr/$(get_libdir)/pkgconfig;
  3075.         export PKG_CONFIG_PATH=${EPREFIX}/usr/share/pkgconfig;
  3076.     fi
  3077. }
  3078. newicon ()
  3079. {
  3080.     _iconins ${FUNCNAME} "$@"
  3081. }
  3082. newmenu ()
  3083. {
  3084.     ( insinto /usr/share/applications;
  3085.     newins "$@" )
  3086. }
  3087. no-as-needed ()
  3088. {
  3089.     case $($(tc-getLD) -v 2>&1 </dev/null) in
  3090.         *GNU*)
  3091.             echo "-Wl,--no-as-needed"
  3092.         ;;
  3093.     esac
  3094. }
  3095. number_abis ()
  3096. {
  3097.     set -- `get_install_abis`;
  3098.     echo $#
  3099. }
  3100. path_exists ()
  3101. {
  3102.     local opt=$1;
  3103.     [[ ${opt} == -[ao] ]] && shift || opt="-a";
  3104.     [[ $# -eq 0 ]] && return 1;
  3105.     local p r=0;
  3106.     for p in "$@";
  3107.     do
  3108.         [[ -e ${p} ]];
  3109.         : $(( r += $? ));
  3110.     done;
  3111.     case ${opt} in
  3112.         -a)
  3113.             return $(( r != 0 ))
  3114.         ;;
  3115.         -o)
  3116.             return $(( r == $# ))
  3117.         ;;
  3118.     esac
  3119. }
  3120. pkg_nofetch ()
  3121. {
  3122.     __eapi0_pkg_nofetch "$@"
  3123. }
  3124. pkg_postinst ()
  3125. {
  3126.     xorg-2_pkg_postinst "$@"
  3127. }
  3128. pkg_postrm ()
  3129. {
  3130.     xorg-2_pkg_postrm "$@"
  3131. }
  3132. preserve_old_lib ()
  3133. {
  3134.     if [[ ${EBUILD_PHASE} != "preinst" ]]; then
  3135.         eerror "preserve_old_lib() must be called from pkg_preinst() only";
  3136.         die "Invalid preserve_old_lib() usage";
  3137.     fi;
  3138.     [[ -z $1 ]] && die "Usage: preserve_old_lib <library to preserve> [more libraries to preserve]";
  3139.     has preserve-libs ${FEATURES} && return 0;
  3140.     local lib dir;
  3141.     for lib in "$@";
  3142.     do
  3143.         [[ -e ${ROOT}/${lib} ]] || continue;
  3144.         dir=${lib%/*};
  3145.         dodir ${dir} || die "dodir ${dir} failed";
  3146.         cp "${ROOT}"/${lib} "${D}"/${lib} || die "cp ${lib} failed";
  3147.         touch "${D}"/${lib};
  3148.     done
  3149. }
  3150. preserve_old_lib_notify ()
  3151. {
  3152.     if [[ ${EBUILD_PHASE} != "postinst" ]]; then
  3153.         eerror "preserve_old_lib_notify() must be called from pkg_postinst() only";
  3154.         die "Invalid preserve_old_lib_notify() usage";
  3155.     fi;
  3156.     has preserve-libs ${FEATURES} && return 0;
  3157.     local lib notice=0;
  3158.     for lib in "$@";
  3159.     do
  3160.         [[ -e ${ROOT}/${lib} ]] || continue;
  3161.         if [[ ${notice} -eq 0 ]]; then
  3162.             notice=1;
  3163.             ewarn "Old versions of installed libraries were detected on your system.";
  3164.             ewarn "In order to avoid breaking packages that depend on these old libs,";
  3165.             ewarn "the libraries are not being removed.  You need to run revdep-rebuild";
  3166.             ewarn "in order to remove these old dependencies.  If you do not have this";
  3167.             ewarn "helper program, simply emerge the 'gentoolkit' package.";
  3168.             ewarn;
  3169.         fi;
  3170.         ewarn "  # revdep-rebuild --library '${lib}' && rm '${lib}'";
  3171.     done
  3172. }
  3173. prune_libtool_files ()
  3174. {
  3175.     debug-print-function ${FUNCNAME} "$@";
  3176.     local removing_all removing_modules opt;
  3177.     for opt in "$@";
  3178.     do
  3179.         case "${opt}" in
  3180.             --all)
  3181.                 removing_all=1;
  3182.                 removing_modules=1
  3183.             ;;
  3184.             --modules)
  3185.                 removing_modules=1
  3186.             ;;
  3187.             *)
  3188.                 die "Invalid argument to ${FUNCNAME}(): ${opt}"
  3189.             ;;
  3190.         esac;
  3191.     done;
  3192.     local f;
  3193.     local queue=();
  3194.     while IFS= read -r -d '' f; do
  3195.         local archivefile=${f/%.la/.a};
  3196.         [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed';
  3197.         local reason pkgconfig_scanned;
  3198.         if grep -q '^shouldnotlink=yes$' "${f}"; then
  3199.             if [[ -f ${archivefile} ]]; then
  3200.                 einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)";
  3201.                 queue+=("${archivefile}");
  3202.             fi;
  3203.             if [[ -n ${removing_modules} ]]; then
  3204.                 reason='module';
  3205.             fi;
  3206.         else
  3207.             if [[ -n ${removing_all} ]]; then
  3208.                 reason='requested';
  3209.             else
  3210.                 if [[ ! -f ${archivefile} ]]; then
  3211.                     reason='no static archive';
  3212.                 else
  3213.                     if [[ ! -n $(sed -nre               "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p"              "${f}") ]]; then
  3214.                         reason='no libs & flags';
  3215.                     else
  3216.                         if [[ ! -n ${pkgconfig_scanned} ]]; then
  3217.                             local pc_libs=();
  3218.                             if [[ ! -n ${removing_all} ]]; then
  3219.                                 local pc;
  3220.                                 local tf=${T}/prune-lt-files.pc;
  3221.                                 local pkgconf=$(tc-getPKG_CONFIG);
  3222.                                 while IFS= read -r -d '' pc; do
  3223.                                     local arg;
  3224.                                     sed -e '/^Requires:/d' "${pc}" > "${tf}";
  3225.                                     for arg in $("${pkgconf}" --libs "${tf}");
  3226.                                     do
  3227.                                         [[ ${arg} == -l* ]] && pc_libs+=(lib${arg#-l}.la);
  3228.                                     done;
  3229.                                 done < <(find "${D}" -type f -name '*.pc' -print0);
  3230.                                 rm -f "${tf}";
  3231.                             fi;
  3232.                             pkgconfig_scanned=1;
  3233.                         fi;
  3234.                         has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc';
  3235.                     fi;
  3236.                 fi;
  3237.             fi;
  3238.         fi;
  3239.         if [[ -n ${reason} ]]; then
  3240.             einfo "Removing unnecessary ${f#${D%/}} (${reason})";
  3241.             queue+=("${f}");
  3242.         fi;
  3243.     done < <(find "${D}" -xtype f -name '*.la' -print0);
  3244.     if [[ -n ${queue[@]} ]]; then
  3245.         rm -f "${queue[@]}";
  3246.     fi
  3247. }
  3248. raw-ldflags ()
  3249. {
  3250.     local x input="$@";
  3251.     [[ -z ${input} ]] && input=${LDFLAGS};
  3252.     set --;
  3253.     for x in ${input};
  3254.     do
  3255.         case ${x} in
  3256.             -Wl,*)
  3257.                 x=${x#-Wl,};
  3258.                 set -- "$@" ${x//,/ }
  3259.             ;;
  3260.             *)
  3261.  
  3262.             ;;
  3263.         esac;
  3264.     done;
  3265.     echo "$@"
  3266. }
  3267. redirect_alloc_fd ()
  3268. {
  3269.     local var=$1 file=$2 redir=${3:-"<>"};
  3270.     if [[ $(( (BASH_VERSINFO[0] << 8) + BASH_VERSINFO[1] )) -ge $(( (4 << 8) + 1 )) ]]; then
  3271.         eval "exec {${var}}${redir}'${file}'";
  3272.     else
  3273.         local fd=10;
  3274.         while :; do
  3275.             if [[ ! -e /dev/fd/${fd} ]] && [[ ! -L /dev/fd/${fd} ]]; then
  3276.                 eval "exec ${fd}${redir}'${file}'" && break;
  3277.             fi;
  3278.             [[ ${fd} -gt 1024 ]] && die 'could not locate a free temp fd !?';
  3279.             : $(( ++fd ));
  3280.         done;
  3281.         : $(( ${var} = fd ));
  3282.     fi
  3283. }
  3284. remove_font_metadata ()
  3285. {
  3286.     debug-print-function ${FUNCNAME} "$@";
  3287.     if [[ ${FONT_DIR} != Speedo && ${FONT_DIR} != CID ]]; then
  3288.         einfo "Removing font metadata";
  3289.         rm -rf "${ED}"/usr/share/fonts/${FONT_DIR}/fonts.{scale,dir,cache-1};
  3290.     fi
  3291. }
  3292. remove_libtool_files ()
  3293. {
  3294.     debug-print-function ${FUNCNAME} "$@";
  3295.     local removing_all;
  3296.     eqawarn "The remove_libtool_files() function was deprecated.";
  3297.     eqawarn "Please use prune_libtool_files() from eutils eclass instead.";
  3298.     [[ ${#} -le 1 ]] || die "Invalid number of args to ${FUNCNAME}()";
  3299.     if [[ ${#} -eq 1 ]]; then
  3300.         case "${1}" in
  3301.             all)
  3302.                 removing_all=1
  3303.             ;;
  3304.             *)
  3305.                 die "Invalid argument to ${FUNCNAME}(): ${1}"
  3306.             ;;
  3307.         esac;
  3308.     fi;
  3309.     local pc_libs=();
  3310.     if [[ ! -n ${removing_all} ]]; then
  3311.         local arg;
  3312.         for arg in $(find "${D}" -name '*.pc' -exec                     sed -n -e 's;^Libs:;;p' {} +);
  3313.         do
  3314.             [[ ${arg} == -l* ]] && pc_libs+=(lib${arg#-l}.la);
  3315.         done;
  3316.     fi;
  3317.     local f;
  3318.     find "${D}" -type f -name '*.la' -print0 | while read -r -d '' f; do
  3319.         local shouldnotlink=$(sed -ne '/^shouldnotlink=yes$/p' "${f}");
  3320.         local archivefile=${f/%.la/.a};
  3321.         [[ "${f}" != "${archivefile}" ]] || die 'regex sanity check failed';
  3322.         if [[ -n ${shouldnotlink} ]]; then
  3323.             einfo "Removing unnecessary ${archivefile#${D%/}}";
  3324.             rm -f "${archivefile}" || die;
  3325.             [[ -n ${removing_all} ]] || continue;
  3326.         fi;
  3327.         local removing;
  3328.         if [[ -n ${removing_all} ]]; then
  3329.             removing='forced';
  3330.         else
  3331.             if [[ ! -f ${archivefile} ]]; then
  3332.                 removing='no static archive';
  3333.             else
  3334.                 if has "$(basename "${f}")" "${pc_libs[@]}"; then
  3335.                     removing='covered by .pc';
  3336.                 else
  3337.                     if [[ ! -n $(sed -n -e          "s/^\(dependency_libs\|inherited_linker_flags\)='\(.*\)'$/\2/p"             "${f}") ]]; then
  3338.                         removing='no libs & flags';
  3339.                     fi;
  3340.                 fi;
  3341.             fi;
  3342.         fi;
  3343.         if [[ -n ${removing} ]]; then
  3344.             einfo "Removing unnecessary ${f#${D%/}} (${removing})";
  3345.             rm -f "${f}" || die;
  3346.         fi;
  3347.     done
  3348. }
  3349. replace-cpu-flags ()
  3350. {
  3351.     local newcpu="$#";
  3352.     newcpu="${!newcpu}";
  3353.     while [ $# -gt 1 ]; do
  3354.         replace-flags "-march=${1}" "-march=${newcpu}";
  3355.         replace-flags "-mcpu=${1}" "-mcpu=${newcpu}";
  3356.         replace-flags "-mtune=${1}" "-mtune=${newcpu}";
  3357.         shift;
  3358.     done;
  3359.     return 0
  3360. }
  3361. replace-flags ()
  3362. {
  3363.     [[ $# != 2 ]] && die "Usage: replace-flags <old flag> <new flag>";
  3364.     local f var new;
  3365.     for var in $(all-flag-vars);
  3366.     do
  3367.         new=();
  3368.         for f in ${!var};
  3369.         do
  3370.             [[ ${f} == ${1} ]] && f=${2};
  3371.             new+=("${f}");
  3372.         done;
  3373.         eval export ${var}=\""${new[*]}"\";
  3374.     done;
  3375.     return 0
  3376. }
  3377. replace-sparc64-flags ()
  3378. {
  3379.     local SPARC64_CPUS="ultrasparc3 ultrasparc v9";
  3380.     if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then
  3381.         for x in ${SPARC64_CPUS};
  3382.         do
  3383.             CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}";
  3384.         done;
  3385.     else
  3386.         for x in ${SPARC64_CPUS};
  3387.         do
  3388.             CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}";
  3389.         done;
  3390.     fi;
  3391.     if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then
  3392.         for x in ${SPARC64_CPUS};
  3393.         do
  3394.             CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}";
  3395.         done;
  3396.     else
  3397.         for x in ${SPARC64_CPUS};
  3398.         do
  3399.             CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}";
  3400.         done;
  3401.     fi;
  3402.     export CFLAGS CXXFLAGS
  3403. }
  3404. setup-allowed-flags ()
  3405. {
  3406.     ALLOWED_FLAGS="-pipe";
  3407.     ALLOWED_FLAGS+=" -O -O1 -O2 -Os -mcpu -march -mtune";
  3408.     ALLOWED_FLAGS+=" -fstack-protector -fstack-protector-all";
  3409.     ALLOWED_FLAGS+=" -fbounds-checking -fno-strict-overflow";
  3410.     ALLOWED_FLAGS+=" -fno-PIE -fno-pie -fno-unit-at-a-time";
  3411.     ALLOWED_FLAGS+=" -g -g[0-9] -ggdb -ggdb[0-9] -gstabs -gstabs+";
  3412.     ALLOWED_FLAGS+=" -fno-ident -fpermissive";
  3413.     ALLOWED_FLAGS+=" -W* -w";
  3414.     ALLOWED_FLAGS+=" -fno-stack-protector -fno-stack-protector-all      -fno-strict-aliasing -fno-bounds-checking -fstrict-overflow         -fno-omit-frame-pointer";
  3415.     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 -mfloat-gprs -mspe -mno-spe       -mtls-direct-seg-refs -mno-tls-direct-seg-refs -mflat -mno-flat         -mno-faster-structs -mfaster-structs -m32 -m64 -mx32 -mabi      -mlittle-endian -mbig-endian -EL -EB -fPIC -mlive-g0 -mcmodel       -mstack-bias -mno-stack-bias -msecure-plt -m*-toc -mfloat-abi       -D* -U*";
  3416.     ALLOWED_FLAGS+=" -mno-fma4 -mno-movbe -mno-xop -mno-lwp";
  3417.     ALLOWED_FLAGS+=" -mno-fsgsbase -mno-rdrnd -mno-f16c -mno-bmi -mno-tbm";
  3418.     ALLOWED_FLAGS+=" -mno-avx2 -mno-bmi2 -mno-fma -mno-lzcnt";
  3419.     ALLOWED_FLAGS+=" -I* -L* -R* -Wl,*";
  3420.     export ALLOWED_FLAGS;
  3421.     return 0
  3422. }
  3423. src_compile ()
  3424. {
  3425.     xorg-2_src_compile clean;
  3426.     xorg-2_src_compile
  3427. }
  3428. src_configure ()
  3429. {
  3430.     xorg-2_src_configure "$@"
  3431. }
  3432. src_install ()
  3433. {
  3434.     xorg-2_src_install "$@"
  3435. }
  3436. src_prepare ()
  3437. {
  3438.     xorg-2_src_prepare;
  3439.     if [[ ${XORG_EAUTORECONF} != no ]]; then
  3440.         intltoolize --copy --automake || die;
  3441.     fi
  3442. }
  3443. src_test ()
  3444. {
  3445.     autotools-utils_src_test "$@"
  3446. }
  3447. src_unpack ()
  3448. {
  3449.     xorg-2_src_unpack "$@"
  3450. }
  3451. strip-flags ()
  3452. {
  3453.     local x y var;
  3454.     setup-allowed-flags;
  3455.     set -f;
  3456.     for var in $(all-flag-vars);
  3457.     do
  3458.         local new=();
  3459.         for x in ${!var};
  3460.         do
  3461.             local flag=${x%%=*};
  3462.             for y in ${ALLOWED_FLAGS};
  3463.             do
  3464.                 if [[ -z ${flag%%${y}} ]]; then
  3465.                     new+=("${x}");
  3466.                     break;
  3467.                 fi;
  3468.             done;
  3469.         done;
  3470.         if _is_flagq ${var} "-O*" && ! _is_flagq new "-O*"; then
  3471.             new+=(-O2);
  3472.         fi;
  3473.         eval export ${var}=\""${new[*]}"\";
  3474.     done;
  3475.     set +f;
  3476.     return 0
  3477. }
  3478. strip-linguas ()
  3479. {
  3480.     local ls newls nols;
  3481.     if [[ $1 == "-i" ]] || [[ $1 == "-u" ]]; then
  3482.         local op=$1;
  3483.         shift;
  3484.         ls=$(find "$1" -name '*.po' -exec basename {} .po ';');
  3485.         shift;
  3486.         local d f;
  3487.         for d in "$@";
  3488.         do
  3489.             if [[ ${op} == "-u" ]]; then
  3490.                 newls=${ls};
  3491.             else
  3492.                 newls="";
  3493.             fi;
  3494.             for f in $(find "$d" -name '*.po' -exec basename {} .po ';');
  3495.             do
  3496.                 if [[ ${op} == "-i" ]]; then
  3497.                     has ${f} ${ls} && newls="${newls} ${f}";
  3498.                 else
  3499.                     has ${f} ${ls} || newls="${newls} ${f}";
  3500.                 fi;
  3501.             done;
  3502.             ls=${newls};
  3503.         done;
  3504.     else
  3505.         ls="$@";
  3506.     fi;
  3507.     nols="";
  3508.     newls="";
  3509.     for f in ${LINGUAS};
  3510.     do
  3511.         if has ${f} ${ls}; then
  3512.             newls="${newls} ${f}";
  3513.         else
  3514.             nols="${nols} ${f}";
  3515.         fi;
  3516.     done;
  3517.     [[ -n ${nols} ]] && einfo "Sorry, but ${PN} does not support the LINGUAS:" ${nols};
  3518.     export LINGUAS=${newls:1}
  3519. }
  3520. strip-unsupported-flags ()
  3521. {
  3522.     export CFLAGS=$(test-flags-CC ${CFLAGS});
  3523.     export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS});
  3524.     export FFLAGS=$(test-flags-F77 ${FFLAGS});
  3525.     export FCFLAGS=$(test-flags-FC ${FCFLAGS})
  3526. }
  3527. tc-arch ()
  3528. {
  3529.     tc-ninja_magic_to_arch portage "$@"
  3530. }
  3531. tc-arch-kernel ()
  3532. {
  3533.     tc-ninja_magic_to_arch kern "$@"
  3534. }
  3535. tc-endian ()
  3536. {
  3537.     local host=$1;
  3538.     [[ -z ${host} ]] && host=${CTARGET:-${CHOST}};
  3539.     host=${host%%-*};
  3540.     case ${host} in
  3541.         aarch64*be)
  3542.             echo big
  3543.         ;;
  3544.         aarch64)
  3545.             echo little
  3546.         ;;
  3547.         alpha*)
  3548.             echo big
  3549.         ;;
  3550.         arm*b*)
  3551.             echo big
  3552.         ;;
  3553.         arm*)
  3554.             echo little
  3555.         ;;
  3556.         cris*)
  3557.             echo little
  3558.         ;;
  3559.         hppa*)
  3560.             echo big
  3561.         ;;
  3562.         i?86*)
  3563.             echo little
  3564.         ;;
  3565.         ia64*)
  3566.             echo little
  3567.         ;;
  3568.         m68*)
  3569.             echo big
  3570.         ;;
  3571.         mips*l*)
  3572.             echo little
  3573.         ;;
  3574.         mips*)
  3575.             echo big
  3576.         ;;
  3577.         powerpc*)
  3578.             echo big
  3579.         ;;
  3580.         s390*)
  3581.             echo big
  3582.         ;;
  3583.         sh*b*)
  3584.             echo big
  3585.         ;;
  3586.         sh*)
  3587.             echo little
  3588.         ;;
  3589.         sparc*)
  3590.             echo big
  3591.         ;;
  3592.         x86_64*)
  3593.             echo little
  3594.         ;;
  3595.         *)
  3596.             echo wtf
  3597.         ;;
  3598.     esac
  3599. }
  3600. tc-env_build ()
  3601. {
  3602.     tc-export_build_env;
  3603.     CFLAGS=${BUILD_CFLAGS} CXXFLAGS=${BUILD_CXXFLAGS} CPPFLAGS=${BUILD_CPPFLAGS} LDFLAGS=${BUILD_LDFLAGS} AR=$(tc-getBUILD_AR) AS=$(tc-getBUILD_AS) CC=$(tc-getBUILD_CC) CPP=$(tc-getBUILD_CPP) CXX=$(tc-getBUILD_CXX) LD=$(tc-getBUILD_LD) NM=$(tc-getBUILD_NM) PKG_CONFIG=$(tc-getBUILD_PKG_CONFIG) RANLIB=$(tc-getBUILD_RANLIB) "$@"
  3604. }
  3605. tc-export ()
  3606. {
  3607.     local var;
  3608.     for var in "$@";
  3609.     do
  3610.         [[ $(type -t tc-get${var}) != "function" ]] && die "tc-export: invalid export variable '${var}'";
  3611.         eval tc-get${var} > /dev/null;
  3612.     done
  3613. }
  3614. tc-export_build_env ()
  3615. {
  3616.     tc-export "$@";
  3617.     : ${BUILD_CFLAGS:=-O1 -pipe};
  3618.     : ${BUILD_CXXFLAGS:=-O1 -pipe};
  3619.     : ${BUILD_CPPFLAGS:=};
  3620.     : ${BUILD_LDFLAGS:=};
  3621.     export BUILD_{C,CXX,CPP,LD}FLAGS
  3622. }
  3623. tc-getAR ()
  3624. {
  3625.     tc-getPROG AR ar "$@"
  3626. }
  3627. tc-getAS ()
  3628. {
  3629.     tc-getPROG AS as "$@"
  3630. }
  3631. tc-getBUILD_AR ()
  3632. {
  3633.     tc-getBUILD_PROG AR ar "$@"
  3634. }
  3635. tc-getBUILD_AS ()
  3636. {
  3637.     tc-getBUILD_PROG AS as "$@"
  3638. }
  3639. tc-getBUILD_CC ()
  3640. {
  3641.     tc-getBUILD_PROG CC gcc "$@"
  3642. }
  3643. tc-getBUILD_CPP ()
  3644. {
  3645.     tc-getBUILD_PROG CPP cpp "$@"
  3646. }
  3647. tc-getBUILD_CXX ()
  3648. {
  3649.     tc-getBUILD_PROG CXX g++ "$@"
  3650. }
  3651. tc-getBUILD_LD ()
  3652. {
  3653.     tc-getBUILD_PROG LD ld "$@"
  3654. }
  3655. tc-getBUILD_NM ()
  3656. {
  3657.     tc-getBUILD_PROG NM nm "$@"
  3658. }
  3659. tc-getBUILD_OBJCOPY ()
  3660. {
  3661.     tc-getBUILD_PROG OBJCOPY objcopy "$@"
  3662. }
  3663. tc-getBUILD_PKG_CONFIG ()
  3664. {
  3665.     tc-getBUILD_PROG PKG_CONFIG pkg-config "$@"
  3666. }
  3667. tc-getBUILD_PROG ()
  3668. {
  3669.     _tc-getPROG CBUILD "BUILD_$1 $1_FOR_BUILD HOST$1" "${@:2}"
  3670. }
  3671. tc-getBUILD_RANLIB ()
  3672. {
  3673.     tc-getBUILD_PROG RANLIB ranlib "$@"
  3674. }
  3675. tc-getBUILD_STRIP ()
  3676. {
  3677.     tc-getBUILD_PROG STRIP strip "$@"
  3678. }
  3679. tc-getCC ()
  3680. {
  3681.     tc-getPROG CC gcc "$@"
  3682. }
  3683. tc-getCPP ()
  3684. {
  3685.     tc-getPROG CPP cpp "$@"
  3686. }
  3687. tc-getCXX ()
  3688. {
  3689.     tc-getPROG CXX g++ "$@"
  3690. }
  3691. tc-getDLLWRAP ()
  3692. {
  3693.     tc-getPROG DLLWRAP dllwrap "$@"
  3694. }
  3695. tc-getF77 ()
  3696. {
  3697.     tc-getPROG F77 gfortran "$@"
  3698. }
  3699. tc-getFC ()
  3700. {
  3701.     tc-getPROG FC gfortran "$@"
  3702. }
  3703. tc-getGCJ ()
  3704. {
  3705.     tc-getPROG GCJ gcj "$@"
  3706. }
  3707. tc-getLD ()
  3708. {
  3709.     tc-getPROG LD ld "$@"
  3710. }
  3711. tc-getNM ()
  3712. {
  3713.     tc-getPROG NM nm "$@"
  3714. }
  3715. tc-getOBJCOPY ()
  3716. {
  3717.     tc-getPROG OBJCOPY objcopy "$@"
  3718. }
  3719. tc-getPKG_CONFIG ()
  3720. {
  3721.     tc-getPROG PKG_CONFIG pkg-config "$@"
  3722. }
  3723. tc-getPROG ()
  3724. {
  3725.     _tc-getPROG CHOST "$@"
  3726. }
  3727. tc-getRANLIB ()
  3728. {
  3729.     tc-getPROG RANLIB ranlib "$@"
  3730. }
  3731. tc-getRC ()
  3732. {
  3733.     tc-getPROG RC windres "$@"
  3734. }
  3735. tc-getSTRIP ()
  3736. {
  3737.     tc-getPROG STRIP strip "$@"
  3738. }
  3739. tc-has-openmp ()
  3740. {
  3741.     local base="${T}/test-tc-openmp";
  3742.     cat > "${base}.c"  <<-EOF
  3743. #include <omp.h>
  3744. int main() {
  3745. int nthreads, tid, ret = 0;
  3746. #pragma omp parallel private(nthreads, tid)
  3747. {
  3748. tid = omp_get_thread_num();
  3749. nthreads = omp_get_num_threads(); ret += tid + nthreads;
  3750. }
  3751. return ret;
  3752. }
  3753. EOF
  3754.  
  3755.     $(tc-getCC "$@") -fopenmp "${base}.c" -o "${base}" &>/dev/null;
  3756.     local ret=$?;
  3757.     rm -f "${base}"*;
  3758.     return ${ret}
  3759. }
  3760. tc-has-tls ()
  3761. {
  3762.     local base="${T}/test-tc-tls";
  3763.     cat > "${base}.c"  <<-EOF
  3764. int foo(int *i) {
  3765. static __thread int j = 0;
  3766. return *i ? j : *i;
  3767. }
  3768. EOF
  3769.  
  3770.     local flags;
  3771.     case $1 in
  3772.         -s)
  3773.             flags="-S"
  3774.         ;;
  3775.         -c)
  3776.             flags="-c"
  3777.         ;;
  3778.         -l)
  3779.  
  3780.         ;;
  3781.         -*)
  3782.             die "Usage: tc-has-tls [-c|-l] [toolchain prefix]"
  3783.         ;;
  3784.     esac;
  3785.     : ${flags:=-fPIC -shared -Wl,-z,defs};
  3786.     [[ $1 == -* ]] && shift;
  3787.     $(tc-getCC "$@") ${flags} "${base}.c" -o "${base}" &>/dev/null;
  3788.     local ret=$?;
  3789.     rm -f "${base}"*;
  3790.     return ${ret}
  3791. }
  3792. tc-is-cross-compiler ()
  3793. {
  3794.     return $([[ ${CBUILD:-${CHOST}} != ${CHOST} ]])
  3795. }
  3796. tc-is-softfloat ()
  3797. {
  3798.     local CTARGET=${CTARGET:-${CHOST}};
  3799.     case ${CTARGET} in
  3800.         bfin* | h8300*)
  3801.             echo "only"
  3802.         ;;
  3803.         *)
  3804.             if [[ ${CTARGET//_/-} == *-softfloat-* ]]; then
  3805.                 echo "yes";
  3806.             else
  3807.                 if [[ ${CTARGET//_/-} == *-softfp-* ]]; then
  3808.                     echo "softfp";
  3809.                 else
  3810.                     echo "no";
  3811.                 fi;
  3812.             fi
  3813.         ;;
  3814.     esac
  3815. }
  3816. tc-is-static-only ()
  3817. {
  3818.     local host=${CTARGET:-${CHOST}};
  3819.     return $([[ ${host} == *-mint* ]])
  3820. }
  3821. tc-ninja_magic_to_arch ()
  3822. {
  3823.     function ninj ()
  3824.     {
  3825.         [[ ${type} == "kern" ]] && echo $1 || echo $2
  3826.     };
  3827.     local type=$1;
  3828.     local host=$2;
  3829.     [[ -z ${host} ]] && host=${CTARGET:-${CHOST}};
  3830.     local KV=${KV:-${KV_FULL}};
  3831.     [[ ${type} == "kern" ]] && [[ -z ${KV} ]] && ewarn "QA: Kernel version could not be determined, please inherit kernel-2 or linux-info";
  3832.     case ${host} in
  3833.         aarch64*)
  3834.             ninj arm64 arm
  3835.         ;;
  3836.         alpha*)
  3837.             echo alpha
  3838.         ;;
  3839.         arm*)
  3840.             echo arm
  3841.         ;;
  3842.         avr*)
  3843.             ninj avr32 avr
  3844.         ;;
  3845.         bfin*)
  3846.             ninj blackfin bfin
  3847.         ;;
  3848.         cris*)
  3849.             echo cris
  3850.         ;;
  3851.         hppa*)
  3852.             ninj parisc hppa
  3853.         ;;
  3854.         i?86*)
  3855.             if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -lt $(KV_to_int 2.6.24) || ${host} == *freebsd* ]]; then
  3856.                 echo i386;
  3857.             else
  3858.                 echo x86;
  3859.             fi
  3860.         ;;
  3861.         ia64*)
  3862.             echo ia64
  3863.         ;;
  3864.         m68*)
  3865.             echo m68k
  3866.         ;;
  3867.         mips*)
  3868.             echo mips
  3869.         ;;
  3870.         nios2*)
  3871.             echo nios2
  3872.         ;;
  3873.         nios*)
  3874.             echo nios
  3875.         ;;
  3876.         powerpc*)
  3877.             if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]]; then
  3878.                 echo powerpc;
  3879.             else
  3880.                 if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -eq $(KV_to_int 2.6.15) ]]; then
  3881.                     if [[ ${host} == powerpc64* ]] || [[ ${PROFILE_ARCH} == "ppc64" ]]; then
  3882.                         echo powerpc;
  3883.                     else
  3884.                         echo ppc;
  3885.                     fi;
  3886.                 else
  3887.                     if [[ ${host} == powerpc64* ]]; then
  3888.                         echo ppc64;
  3889.                     else
  3890.                         if [[ ${PROFILE_ARCH} == "ppc64" ]]; then
  3891.                             ninj ppc64 ppc;
  3892.                         else
  3893.                             echo ppc;
  3894.                         fi;
  3895.                     fi;
  3896.                 fi;
  3897.             fi
  3898.         ;;
  3899.         s390*)
  3900.             echo s390
  3901.         ;;
  3902.         sh64*)
  3903.             ninj sh64 sh
  3904.         ;;
  3905.         sh*)
  3906.             echo sh
  3907.         ;;
  3908.         sparc64*)
  3909.             ninj sparc64 sparc
  3910.         ;;
  3911.         sparc*)
  3912.             [[ ${PROFILE_ARCH} == "sparc64" ]] && ninj sparc64 sparc || echo sparc
  3913.         ;;
  3914.         vax*)
  3915.             echo vax
  3916.         ;;
  3917.         x86_64*freebsd*)
  3918.             echo amd64
  3919.         ;;
  3920.         x86_64*)
  3921.             if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.24) ]]; then
  3922.                 echo x86;
  3923.             else
  3924.                 ninj x86_64 amd64;
  3925.             fi
  3926.         ;;
  3927.         *)
  3928.             echo unknown
  3929.         ;;
  3930.     esac
  3931. }
  3932. test-flag-CC ()
  3933. {
  3934.     test-flag-PROG "CC" c "$1"
  3935. }
  3936. test-flag-CXX ()
  3937. {
  3938.     test-flag-PROG "CXX" c++ "$1"
  3939. }
  3940. test-flag-F77 ()
  3941. {
  3942.     test-flag-PROG "F77" f77 "$1"
  3943. }
  3944. test-flag-FC ()
  3945. {
  3946.     test-flag-PROG "FC" f95 "$1"
  3947. }
  3948. test-flag-PROG ()
  3949. {
  3950.     local comp=$1;
  3951.     local lang=$2;
  3952.     local flag=$3;
  3953.     [[ -z ${comp} || -z ${flag} ]] && return 1;
  3954.     local PROG=$(tc-get${comp});
  3955.     if ${PROG} -c -o /dev/null -x${lang} - < /dev/null > /dev/null 2>&1; then
  3956.         ${PROG} "${flag}" -c -o /dev/null -x${lang} - < /dev/null > /dev/null 2>&1;
  3957.     else
  3958.         ${PROG} "${flag}" -c -o /dev/null /dev/null > /dev/null 2>&1;
  3959.     fi
  3960. }
  3961. test-flags ()
  3962. {
  3963.     test-flags-CC "$@"
  3964. }
  3965. test-flags-CC ()
  3966. {
  3967.     test-flags-PROG "CC" "$@"
  3968. }
  3969. test-flags-CXX ()
  3970. {
  3971.     test-flags-PROG "CXX" "$@"
  3972. }
  3973. test-flags-F77 ()
  3974. {
  3975.     test-flags-PROG "F77" "$@"
  3976. }
  3977. test-flags-FC ()
  3978. {
  3979.     test-flags-PROG "FC" "$@"
  3980. }
  3981. test-flags-PROG ()
  3982. {
  3983.     local comp=$1;
  3984.     local flags=();
  3985.     local x;
  3986.     shift;
  3987.     [[ -z ${comp} ]] && return 1;
  3988.     for x in "$@";
  3989.     do
  3990.         test-flag-${comp} "${x}" && flags+=("${x}");
  3991.     done;
  3992.     echo "${flags[*]}";
  3993.     [[ ${#flags[@]} -gt 0 ]]
  3994. }
  3995. test_version_info ()
  3996. {
  3997.     if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then
  3998.         return 0;
  3999.     else
  4000.         return 1;
  4001.     fi
  4002. }
  4003. uclibctoolize ()
  4004. {
  4005.     die "Use elibtoolize"
  4006. }
  4007. use_if_iuse ()
  4008. {
  4009.     in_iuse $1 || return 1;
  4010.     use $1
  4011. }
  4012. validate_desktop_entries ()
  4013. {
  4014.     if [[ -x /usr/bin/desktop-file-validate ]]; then
  4015.         einfo "Checking desktop entry validity";
  4016.         local directories="";
  4017.         for d in /usr/share/applications $@;
  4018.         do
  4019.             [[ -d ${D}${d} ]] && directories="${directories} ${D}${d}";
  4020.         done;
  4021.         if [[ -n ${directories} ]]; then
  4022.             for FILE in $(find ${directories} -name "*\.desktop"                            -not -path '*.hidden*' | sort -u 2>/dev/null);
  4023.             do
  4024.                 local temp=$(desktop-file-validate ${FILE} | grep -v "warning:" |                               sed -e "s|error: ||" -e "s|${FILE}:|--|g" );
  4025.                 [[ -n $temp ]] && elog ${temp/--/${FILE/${D}/}:};
  4026.             done;
  4027.         fi;
  4028.         echo "";
  4029.     else
  4030.         einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo.";
  4031.     fi
  4032. }
  4033. xorg-2_flags_setup ()
  4034. {
  4035.     debug-print-function ${FUNCNAME} "$@";
  4036.     [[ ${CHOST} == *-winnt* ]] && append-cppflags -DWIN32 -D__STDC__;
  4037.     [[ ${PN} = xorg-server || -n ${DRIVER} ]] && append-ldflags -Wl,-z,lazy;
  4038.     if has static-libs ${IUSE//+}; then
  4039.         filter-flags -Wl,-Bdirect;
  4040.         filter-ldflags -Bdirect;
  4041.         filter-ldflags -Wl,-Bdirect;
  4042.     fi
  4043. }
  4044. xorg-2_font_configure ()
  4045. {
  4046.     debug-print-function ${FUNCNAME} "$@";
  4047.     if has nls ${IUSE//+} && ! use nls; then
  4048.         if grep -q -s "disable-all-encodings" ${ECONF_SOURCE:-.}/configure; then
  4049.             FONT_OPTIONS+="
  4050.                 --disable-all-encodings";
  4051.         else
  4052.             FONT_OPTIONS+="
  4053.                 --disable-iso8859-2
  4054.                 --disable-iso8859-3
  4055.                 --disable-iso8859-4
  4056.                 --disable-iso8859-5
  4057.                 --disable-iso8859-6
  4058.                 --disable-iso8859-7
  4059.                 --disable-iso8859-8
  4060.                 --disable-iso8859-9
  4061.                 --disable-iso8859-10
  4062.                 --disable-iso8859-11
  4063.                 --disable-iso8859-12
  4064.                 --disable-iso8859-13
  4065.                 --disable-iso8859-14
  4066.                 --disable-iso8859-15
  4067.                 --disable-iso8859-16
  4068.                 --disable-jisx0201
  4069.                 --disable-koi8-r";
  4070.         fi;
  4071.     fi
  4072. }
  4073. xorg-2_patch_source ()
  4074. {
  4075.     debug-print-function ${FUNCNAME} "$@";
  4076.     EPATCH_SUFFIX=${EPATCH_SUFFIX:=patch};
  4077.     [[ -d "${EPATCH_SOURCE}" ]] && epatch
  4078. }
  4079. xorg-2_pkg_postinst ()
  4080. {
  4081.     debug-print-function ${FUNCNAME} "$@";
  4082.     if [[ -n ${FONT} ]]; then
  4083.         create_fonts_scale;
  4084.         create_fonts_dir;
  4085.         font_pkg_postinst "$@";
  4086.     fi
  4087. }
  4088. xorg-2_pkg_postrm ()
  4089. {
  4090.     debug-print-function ${FUNCNAME} "$@";
  4091.     if [[ -n ${FONT} ]]; then
  4092.         if [[ ${EAPI} -lt 4 || -z ${REPLACED_BY_VERSION} ]]; then
  4093.             create_fonts_scale;
  4094.             create_fonts_dir;
  4095.             font_pkg_postrm "$@";
  4096.         fi;
  4097.     fi
  4098. }
  4099. xorg-2_pkg_setup ()
  4100. {
  4101.     debug-print-function ${FUNCNAME} "$@";
  4102.     [[ ${FONT} == yes ]] && font_pkg_setup "$@"
  4103. }
  4104. xorg-2_reconf_source ()
  4105. {
  4106.     debug-print-function ${FUNCNAME} "$@";
  4107.     case ${CHOST} in
  4108.         *-interix* | *-aix* | *-winnt*)
  4109.             [[ -e "./configure.ac" || -e "./configure.in" ]] && AUTOTOOLS_AUTORECONF=1
  4110.         ;;
  4111.         *)
  4112.             [[ ${XORG_EAUTORECONF} != no && ( -e "./configure.ac" || -e "./configure.in" ) ]] && AUTOTOOLS_AUTORECONF=1
  4113.         ;;
  4114.     esac
  4115. }
  4116. xorg-2_src_compile ()
  4117. {
  4118.     debug-print-function ${FUNCNAME} "$@";
  4119.     autotools-utils_src_compile "$@"
  4120. }
  4121. xorg-2_src_configure ()
  4122. {
  4123.     debug-print-function ${FUNCNAME} "$@";
  4124.     xorg-2_flags_setup;
  4125.     if [[ $(declare -p XORG_CONFIGURE_OPTIONS 2>&-) != "declare -a"* ]]; then
  4126.         if [[ -n "${CONFIGURE_OPTIONS}" ]]; then
  4127.             eqawarn "CONFIGURE_OPTIONS are deprecated. Please migrate to XORG_CONFIGURE_OPTIONS";
  4128.             eqawarn "to preserve namespace.";
  4129.         fi;
  4130.         local xorgconfadd=(${CONFIGURE_OPTIONS} ${XORG_CONFIGURE_OPTIONS});
  4131.     else
  4132.         local xorgconfadd=("${XORG_CONFIGURE_OPTIONS[@]}");
  4133.     fi;
  4134.     [[ -n "${FONT}" ]] && xorg-2_font_configure;
  4135.     if grep -q -s "disable-depencency-tracking" ${ECONF_SOURCE:-.}/configure; then
  4136.         local dep_track="--disable-dependency-tracking";
  4137.     fi;
  4138.     local myeconfargs=(${dep_track} ${FONT_OPTIONS} "${xorgconfadd[@]}");
  4139.     autotools-utils_src_configure "$@"
  4140. }
  4141. xorg-2_src_install ()
  4142. {
  4143.     debug-print-function ${FUNCNAME} "$@";
  4144.     if [[ ${CATEGORY} == x11-proto ]]; then
  4145.         autotools-utils_src_install ${PN/proto/}docdir="${EPREFIX}/usr/share/doc/${PF}" docdir="${EPREFIX}/usr/share/doc/${PF}";
  4146.     else
  4147.         autotools-utils_src_install docdir="${EPREFIX}/usr/share/doc/${PF}";
  4148.     fi;
  4149.     if [[ -n ${GIT_ECLASS} ]]; then
  4150.         pushd "${EGIT_STORE_DIR}/${EGIT_CLONE_DIR}" > /dev/null;
  4151.         git log ${EGIT_COMMIT} > "${S}"/ChangeLog;
  4152.         popd > /dev/null;
  4153.     fi;
  4154.     if [[ -e "${S}"/ChangeLog ]]; then
  4155.         dodoc "${S}"/ChangeLog || die "dodoc failed";
  4156.     fi;
  4157.     prune_libtool_files --all;
  4158.     [[ -n ${FONT} ]] && remove_font_metadata
  4159. }
  4160. xorg-2_src_prepare ()
  4161. {
  4162.     debug-print-function ${FUNCNAME} "$@";
  4163.     xorg-2_patch_source;
  4164.     xorg-2_reconf_source;
  4165.     autotools-utils_src_prepare "$@"
  4166. }
  4167. xorg-2_src_unpack ()
  4168. {
  4169.     debug-print-function ${FUNCNAME} "$@";
  4170.     if [[ -n ${GIT_ECLASS} ]]; then
  4171.         git-2_src_unpack;
  4172.     else
  4173.         unpack ${A};
  4174.     fi;
  4175.     [[ -n ${FONT_OPTIONS} ]] && einfo "Detected font directory: ${FONT_DIR}"
  4176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement