Don't like ads? PRO users don't see any ads ;-)
Guest

blender env

By: a guest on Jun 1st, 2012  |  syntax: None  |  size: 183.70 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. cat /var/tmp/portage/media-gfx/blender-2.49b-r2/temp/environment
  2. declare -x ALSA_CARDS=""
  3. 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"
  4. declare -x APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache 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"
  5. declare -x ARCH="x86"
  6. declare -x BOOTSTRAP_USE="cxx unicode"
  7. declare -x CALLIGRA_FEATURES="kexi words flow plan sheets stage tables krita karbon braindump"
  8. declare -x CAMERAS="ptp2"
  9. declare -x CBUILD="i686-pc-linux-gnu"
  10. declare -x CFLAGS="-O2 -march=i686 -pipe"
  11. declare -x CFLAGS_default
  12. declare -x CHOST="i686-pc-linux-gnu"
  13. declare -x CHOST_default="i686-pc-linux-gnu"
  14. declare -x COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog"
  15. declare -x CROSSCOMPILE_OPTS=""
  16. declare -x CTARGET_default="i686-pc-linux-gnu"
  17. declare -x CXXFLAGS="-O2 -march=i686 -pipe"
  18. declare -x DEFAULT_ABI="default"
  19. declare -x DEFINED_PHASES=" compile configure install postinst preinst prepare"
  20. declare DEPEND=">=dev-util/scons-2
  21.         sys-devel/gcc[openmp?]
  22.         x11-base/xorg-server
  23.         ffmpeg? ( virtual/ffmpeg[encode,theora] )
  24.         >=media-libs/openjpeg-1.5.0
  25.         media-libs/tiff
  26.         >=dev-lang/python-2.5
  27.         nls? ( >=media-libs/freetype-2.0
  28.                 virtual/libintl
  29.                 >=media-libs/ftgl-2.1 )
  30.         openal? ( >=media-libs/openal-1.6.372
  31.                 >=media-libs/freealut-1.1.0-r1 )
  32.         media-libs/openexr
  33.         media-libs/libpng
  34.         blender-game? ( >=media-libs/libsdl-1.2[joystick] )
  35.         >=media-libs/libsdl-1.2
  36.         ogg? ( media-libs/libogg )
  37.         virtual/jpeg
  38.         virtual/opengl dev-util/scons"
  39. declare DESCRIPTION="3D Creation/Animation/Publishing System"
  40. declare -x DESTTREE="/usr"
  41. declare -x DIROPTIONS="-m0755"
  42. declare -x EAPI="2"
  43. declare -x ELIBC="glibc"
  44. declare -- EPATCH_COMMON_OPTS="-g0 -E --no-backup-if-mismatch"
  45. declare -- EPATCH_EXCLUDE=""
  46. declare -- EPATCH_FORCE="no"
  47. declare -- EPATCH_MULTI_MSG="Applying various patches (bugfixes/updates) ..."
  48. declare -- EPATCH_OPTS=""
  49. declare -- EPATCH_SINGLE_MSG=""
  50. declare -- EPATCH_SOURCE="/var/tmp/portage/media-gfx/blender-2.49b-r2/work/patch"
  51. declare -- EPATCH_SUFFIX="patch.bz2"
  52. declare -x EXEOPTIONS="-m0755"
  53. declare -x FCFLAGS=""
  54. 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}\""
  55. declare -x FFLAGS=""
  56. declare -x FLTK_DOCDIR="/usr/share/doc/fltk-1.3.0/html"
  57. declare -x GCC_SPECS=""
  58. declare -x GDK_USE_XFT="1"
  59. 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"
  60. declare -x GRUB_PLATFORMS=""
  61. declare HOMEPAGE="http://www.blender.org/"
  62. declare -x INHERITED=" scons-utils multilib toolchain-funcs user eutils python"
  63. declare -x INPUT_DEVICES="keyboard mouse evdev"
  64. declare -x INSDESTTREE=""
  65. declare -x INSOPTIONS="-m0644"
  66. declare IUSE="blender-game ffmpeg nls ogg openmp verse openal "
  67. declare -x KERNEL="linux"
  68. declare -x KERNEL_ABI="default"
  69. declare -x KEYWORDS="amd64 ppc ppc64 x86"
  70. declare -x KV="3.2.12-gentoo"
  71. declare -x LANG="en_US"
  72. declare -x LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text"
  73. declare -x LDFLAGS="-Wl,-O1 -Wl,--as-needed"
  74. declare -x LDFLAGS_default
  75. declare -x LIBDIR_default="lib"
  76. declare -x LIBOPTIONS="-m0644"
  77. declare -x LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer"
  78. declare -x LICENSE="|| ( GPL-2 BL BSD )"
  79. declare -x MAIL="/var/mail/root"
  80. declare -x MULTILIB_ABIS="default"
  81. declare -x NETBEANS="apisupport cnd groovy gsf harness ide identity j2ee java mobility nb php profiler soa visualweb webcommon websvccommon xml"
  82. declare -x OPENGL_PROFILE="xorg-x11"
  83. declare -x PATH="/usr/lib/portage/bin/ebuild-helpers:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/i686-pc-linux-gnu/gcc-bin/4.5.3"
  84. declare PDEPEND=""
  85. declare -x PHP_TARGETS=""
  86. declare -a PORTAGE_DOCOMPRESS='([0]="/usr/share/doc" [1]="/usr/share/info" [2]="/usr/share/man")'
  87. declare -a PORTAGE_DOCOMPRESS_SKIP='([0]="/usr/share/doc/blender-2.49b-r2/html")'
  88. declare -x PRELINK_PATH_MASK="/usr/lib/libfreebl3.so:/usr/lib/libnssdbm3.so:/usr/lib/libsoftokn3.so"
  89. declare -x PROFILE_ONLY_VARIABLES="ARCH ELIBC KERNEL USERLAND"
  90. declare -x PROPERTIES=""
  91. declare -x PROVIDE=""
  92. declare -x PYTHONDONTWRITEBYTECODE="1"
  93. declare -- PYTHON_COLORS="0"
  94. declare -x PYTHON_TARGETS="python3_2"
  95. declare -- PYTHON_TEST_VERBOSITY="1"
  96. declare -x QT_GRAPHICSSYSTEM="raster"
  97. declare -x QT_PLUGIN_PATH="/usr/lib/kde4/plugins"
  98. declare -x RDEPEND="ffmpeg? ( virtual/ffmpeg[encode,theora] )
  99.         >=media-libs/openjpeg-1.5.0
  100.         media-libs/tiff
  101.         >=dev-lang/python-2.5
  102.         nls? ( >=media-libs/freetype-2.0
  103.                 virtual/libintl
  104.                 >=media-libs/ftgl-2.1 )
  105.         openal? ( >=media-libs/openal-1.6.372
  106.                 >=media-libs/freealut-1.1.0-r1 )
  107.         media-libs/openexr
  108.         media-libs/libpng
  109.         blender-game? ( >=media-libs/libsdl-1.2[joystick] )
  110.         >=media-libs/libsdl-1.2
  111.         ogg? ( media-libs/libogg )
  112.         virtual/jpeg
  113.         virtual/opengl "
  114. declare REPOSITORY
  115. declare REQUIRED_USE=""
  116. declare -x RESTRICT=""
  117. 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}\""
  118. declare -x RUBY_TARGETS=""
  119. declare -x R_HOME="/usr/lib/R"
  120. declare -x S="/var/tmp/portage/media-gfx/blender-2.49b-r2/work/blender-2.49b"
  121. declare -x SANDBOX_DEBUG="0"
  122. declare -x SANDBOX_DENY=""
  123. declare -x SANDBOX_PID="18593"
  124. declare -x SANDBOX_PREDICT="/var/tmp/portage/media-gfx/blender-2.49b-r2/homedir:/dev/crypto:/var/cache/fontconfig"
  125. declare -x SANDBOX_READ="/:/var/tmp"
  126. declare -x SANDBOX_VERBOSE="1"
  127. 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/lib32/cf:/usr/lib32/conftest:/usr/lib64/cf:/usr/lib64/conftest:/usr/lib/cf:/usr/lib/conftest:/usr/tmp/cf:/usr/tmp/conftest:/var/tmp:/var/tmp/:/var/tmp/portage/media-gfx/blender-2.49b-r2/homedir/.bash_history"
  128. declare -x SLOT="0"
  129. declare SRC_URI="http://download.blender.org/source/blender-2.49b.tar.gz"
  130. declare -x SSH_CLIENT="192.168.1.100 63213 22"
  131. declare -x SSH_CONNECTION="192.168.1.100 63213 192.168.1.11 22"
  132. declare -x SSH_TTY="/dev/pts/2"
  133. declare -x USE="blender-game consolekit elibc_glibc ffmpeg kernel_linux nls ogg openal openmp policykit userland_GNU verse x86"
  134. declare -x USERLAND="GNU"
  135. declare -- USE_SCONS_FALSE="0"
  136. declare -- USE_SCONS_TRUE="1"
  137. declare -x VIDEO_CARDS=""
  138. declare -x VISUAL="/usr/bin/vi"
  139. declare -x XDG_CONFIG_DIRS="/etc/xdg"
  140. declare -x XDG_DATA_DIRS="/usr/local/share:/usr/share"
  141. 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"
  142. declare -a _CPYTHON2_GLOBALLY_SUPPORTED_ABIS='([0]="2.4" [1]="2.5" [2]="2.6" [3]="2.7")'
  143. declare -a _CPYTHON3_GLOBALLY_SUPPORTED_ABIS='([0]="3.1" [1]="3.2")'
  144. declare -x _E_DOCDESTTREE_=""
  145. declare -x _E_EXEDESTTREE_=""
  146. declare -a _JYTHON_GLOBALLY_SUPPORTED_ABIS='([0]="2.5-jython")'
  147. declare -a _PYPY_GLOBALLY_SUPPORTED_ABIS='([0]="2.7-pypy-1.7" [1]="2.7-pypy-1.8")'
  148. declare -- _PYTHON_ABI_EXTRACTION_COMMAND="import platform
  149. import sys
  150. sys.stdout.write(\".\".join(str(x) for x in sys.version_info[:2]))
  151. if platform.system()[:4] == \"Java\":
  152.         sys.stdout.write(\"-jython\")
  153. elif hasattr(platform, \"python_implementation\") and platform.python_implementation() == \"PyPy\":
  154.         sys.stdout.write(\"-pypy-\" + \".\".join(str(x) for x in sys.pypy_version_info[:2]))"
  155. declare -- _PYTHON_ABI_PATTERN_REGEX="([[:alnum:]]|\\.|-|\\*|\\[|\\])+"
  156. declare -- _PYTHON_ECLASS_INHERITED="1"
  157. declare -a _PYTHON_GLOBALLY_SUPPORTED_ABIS='([0]="2.4" [1]="2.5" [2]="2.6" [3]="2.7" [4]="3.1" [5]="3.2" [6]="2.5-jython" [7]="2.7-pypy-1.7" [8]="2.7-pypy-1.8")'
  158. declare -- _PYTHON_SHEBANG_BASE_PART_REGEX="^#![[:space:]]*([^[:space:]]*/usr/bin/env[[:space:]]+)?([^[:space:]]*/)?(jython|pypy-c|python)"
  159. declare -- ___ECLASS_ONCE_EUTILS="recur -_+^+_- spank"
  160. declare -- ___ECLASS_ONCE_MULTILIB="recur -_+^+_- spank"
  161. declare -- ___ECLASS_ONCE_TOOLCHAIN_FUNCS="recur -_+^+_- spank"
  162. declare -- ___ECLASS_ONCE_USER="recur -_+^+_- spank"
  163. declare -- arg="verse"
  164. declare -- phase_func
  165. PYTHON ()
  166. {
  167.     _python_check_python_pkg_setup_execution;
  168.     local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0";
  169.     while (($#)); do
  170.         case "$1" in
  171.             -2)
  172.                 python2="1"
  173.             ;;
  174.             -3)
  175.                 python3="1"
  176.             ;;
  177.             --ABI)
  178.                 ABI_output="1"
  179.             ;;
  180.             -a | --absolute-path)
  181.                 absolute_path_output="1"
  182.             ;;
  183.             -f | --final-ABI)
  184.                 final_ABI="1"
  185.             ;;
  186.             --)
  187.                 shift;
  188.                 break
  189.             ;;
  190.             -*)
  191.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  192.             ;;
  193.             *)
  194.                 break
  195.             ;;
  196.         esac;
  197.         shift;
  198.     done;
  199.     if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then
  200.         die "${FUNCNAME}(): '--ABI' and '--absolute-path' options cannot be specified simultaneously";
  201.     fi;
  202.     if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then
  203.         die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously";
  204.     fi;
  205.     if [[ "$#" -eq 0 ]]; then
  206.         if [[ "${final_ABI}" == "1" ]]; then
  207.             if ! _python_package_supporting_installation_for_multiple_python_abis; then
  208.                 die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  209.             fi;
  210.             _python_calculate_PYTHON_ABIS;
  211.             PYTHON_ABI="${PYTHON_ABIS##* }";
  212.         else
  213.             if [[ "${python2}" == "1" ]]; then
  214.                 PYTHON_ABI="$(ROOT="/" eselect python show --python2 --ABI)";
  215.                 if [[ -z "${PYTHON_ABI}" ]]; then
  216.                     die "${FUNCNAME}(): Active version of CPython 2 not set";
  217.                 else
  218.                     if [[ "${PYTHON_ABI}" != "2."* ]]; then
  219.                         die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`";
  220.                     fi;
  221.                 fi;
  222.             else
  223.                 if [[ "${python3}" == "1" ]]; then
  224.                     PYTHON_ABI="$(ROOT="/" eselect python show --python3 --ABI)";
  225.                     if [[ -z "${PYTHON_ABI}" ]]; then
  226.                         die "${FUNCNAME}(): Active version of CPython 3 not set";
  227.                     else
  228.                         if [[ "${PYTHON_ABI}" != "3."* ]]; then
  229.                             die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`";
  230.                         fi;
  231.                     fi;
  232.                 else
  233.                     if _python_package_supporting_installation_for_multiple_python_abis; then
  234.                         if ! _python_abi-specific_local_scope; then
  235.                             die "${FUNCNAME}() should be used in ABI-specific local scope";
  236.                         fi;
  237.                     else
  238.                         PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")";
  239.                         if [[ -z "${PYTHON_ABI}" ]]; then
  240.                             die "${FUNCNAME}(): Failure of extraction of locally active version of Python";
  241.                         fi;
  242.                     fi;
  243.                 fi;
  244.             fi;
  245.         fi;
  246.     else
  247.         if [[ "$#" -eq 1 ]]; then
  248.             if [[ "${final_ABI}" == "1" ]]; then
  249.                 die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously";
  250.             fi;
  251.             if [[ "${python2}" == "1" ]]; then
  252.                 die "${FUNCNAME}(): '-2' option and Python ABI cannot be specified simultaneously";
  253.             fi;
  254.             if [[ "${python3}" == "1" ]]; then
  255.                 die "${FUNCNAME}(): '-3' option and Python ABI cannot be specified simultaneously";
  256.             fi;
  257.             PYTHON_ABI="$1";
  258.         else
  259.             die "${FUNCNAME}(): Invalid usage";
  260.         fi;
  261.     fi;
  262.     if [[ "${ABI_output}" == "1" ]]; then
  263.         echo -n "${PYTHON_ABI}";
  264.         return;
  265.     else
  266.         if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  267.             python_interpreter="python${PYTHON_ABI}";
  268.         else
  269.             if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  270.                 python_interpreter="jython${PYTHON_ABI%-jython}";
  271.             else
  272.                 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  273.                     python_interpreter="pypy-c${PYTHON_ABI#*-pypy-}";
  274.                 fi;
  275.             fi;
  276.         fi;
  277.         if [[ "${absolute_path_output}" == "1" ]]; then
  278.             echo -n "${EPREFIX}/usr/bin/${python_interpreter}";
  279.         else
  280.             echo -n "${python_interpreter}";
  281.         fi;
  282.     fi;
  283.     if [[ -n "${ABI}" && "${ABI}" != "${DEFAULT_ABI}" && "${DEFAULT_ABI}" != "default" ]]; then
  284.         echo -n "-${ABI}";
  285.     fi
  286. }
  287. _assert_pkg_ebuild_phase ()
  288. {
  289.     case ${EBUILD_PHASE} in
  290.         setup | preinst | postinst)
  291.  
  292.         ;;
  293.         *)
  294.             eerror "'$1()' called from '${EBUILD_PHASE}' phase which is not OK:";
  295.             eerror "You may only call from pkg_{setup,preinst,postinst} functions.";
  296.             eerror "Package fails at QA and at life.  Please file a bug.";
  297.             die "Bad package!  $1 is only for use in some pkg_* functions!"
  298.         ;;
  299.     esac
  300. }
  301. _epatch_draw_line ()
  302. {
  303.     [[ -z $1 ]] && set "$(printf "%65s" '')";
  304.     echo "${1//?/=}"
  305. }
  306. _gcc-install-dir ()
  307. {
  308.     echo "$(LC_ALL=C $(tc-getCC) -print-search-dirs 2> /dev/null |              awk '$1=="install:" {print $2}')"
  309. }
  310. _gcc-specs-directive_raw ()
  311. {
  312.     local cc=$(tc-getCC);
  313.     local specfiles=$(LC_ALL=C ${cc} -v 2>&1 | awk '$1=="Reading" {print $NF}');
  314.     ${cc} -dumpspecs 2> /dev/null | cat - ${specfiles} | awk -v directive=$1 'BEGIN     { pspec=""; spec=""; outside=1 }
  315. $1=="*"directive":"  { pspec=spec; spec=""; outside=0; next }
  316.         outside || NF==0 || ( substr($1,1,1)=="*" && substr($1,length($1),1)==":" ) { outside=1; next }
  317.         spec=="" && substr($0,1,1)=="+" { spec=pspec " " substr($0,2); next }
  318.         { spec=spec $0 }
  319. END     { print spec }';
  320.     return 0
  321. }
  322. _gcc-specs-exists ()
  323. {
  324.     [[ -f $(_gcc-install-dir)/$1 ]]
  325. }
  326. _gcc_fullversion ()
  327. {
  328.     local ver="$1";
  329.     shift;
  330.     set -- `$(tc-getCPP "$@") -E -P - <<<"__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__"`;
  331.     eval echo "$ver"
  332. }
  333. _python_abi-specific_local_scope ()
  334. {
  335.     [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]]
  336. }
  337. _python_calculate_PYTHON_ABIS ()
  338. {
  339.     if ! _python_package_supporting_installation_for_multiple_python_abis; then
  340.         die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  341.     fi;
  342.     _python_initial_sanity_checks;
  343.     if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then
  344.         local PYTHON_ABI;
  345.         if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
  346.             local cpython_enabled="0";
  347.             if [[ -z "${USE_PYTHON}" ]]; then
  348.                 die "USE_PYTHON variable is empty";
  349.             fi;
  350.             for PYTHON_ABI in ${USE_PYTHON};
  351.             do
  352.                 if ! has "${PYTHON_ABI}" "${_PYTHON_GLOBALLY_SUPPORTED_ABIS[@]}"; then
  353.                     die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'";
  354.                 fi;
  355.                 if has "${PYTHON_ABI}" "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; then
  356.                     cpython_enabled="1";
  357.                 fi;
  358.                 if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
  359.                     export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}";
  360.                 fi;
  361.             done;
  362.             if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
  363.                 die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}";
  364.             fi;
  365.             if [[ "${cpython_enabled}" == "0" ]]; then
  366.                 die "USE_PYTHON variable does not enable any CPython ABI";
  367.             fi;
  368.         else
  369.             local python_version python2_version python3_version support_python_major_version;
  370.             if ! has_version "dev-lang/python"; then
  371.                 die "${FUNCNAME}(): 'dev-lang/python' is not installed";
  372.             fi;
  373.             python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')";
  374.             if has_version "=dev-lang/python-2*"; then
  375.                 if [[ "$(readlink "${EPREFIX}/usr/bin/python2")" != "python2."* ]]; then
  376.                     die "'${EPREFIX}/usr/bin/python2' is not valid symlink";
  377.                 fi;
  378.                 python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')";
  379.                 support_python_major_version="0";
  380.                 for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}";
  381.                 do
  382.                     if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
  383.                         support_python_major_version="1";
  384.                         break;
  385.                     fi;
  386.                 done;
  387.                 if [[ "${support_python_major_version}" == "1" ]]; then
  388.                     if _python_check_python_abi_matching --patterns-list "${python2_version}" "${RESTRICT_PYTHON_ABIS}"; then
  389.                         die "Active version of CPython 2 is not supported by ${CATEGORY}/${PF}";
  390.                     fi;
  391.                 else
  392.                     python2_version="";
  393.                 fi;
  394.             fi;
  395.             if has_version "=dev-lang/python-3*"; then
  396.                 if [[ "$(readlink "${EPREFIX}/usr/bin/python3")" != "python3."* ]]; then
  397.                     die "'${EPREFIX}/usr/bin/python3' is not valid symlink";
  398.                 fi;
  399.                 python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')";
  400.                 support_python_major_version="0";
  401.                 for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}";
  402.                 do
  403.                     if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
  404.                         support_python_major_version="1";
  405.                         break;
  406.                     fi;
  407.                 done;
  408.                 if [[ "${support_python_major_version}" == "1" ]]; then
  409.                     if _python_check_python_abi_matching --patterns-list "${python3_version}" "${RESTRICT_PYTHON_ABIS}"; then
  410.                         die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}";
  411.                     fi;
  412.                 else
  413.                     python3_version="";
  414.                 fi;
  415.             fi;
  416.             if [[ -z "${python2_version}" && -z "${python3_version}" ]]; then
  417.                 eerror "${CATEGORY}/${PF} requires at least one of the following packages:";
  418.                 for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}";
  419.                 do
  420.                     if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
  421.                         eerror "    dev-lang/python:${PYTHON_ABI}";
  422.                     fi;
  423.                 done;
  424.                 die "No supported version of CPython installed";
  425.             fi;
  426.             if [[ -n "${python2_version}" && "${python_version}" == "2."* && "${python_version}" != "${python2_version}" ]]; then
  427.                 eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python2' symlink";
  428.                 eerror "is set incorrectly. Use \`eselect python\` to fix configuration.";
  429.                 die "Incorrect configuration of Python";
  430.             fi;
  431.             if [[ -n "${python3_version}" && "${python_version}" == "3."* && "${python_version}" != "${python3_version}" ]]; then
  432.                 eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python3' symlink";
  433.                 eerror "is set incorrectly. Use \`eselect python\` to fix configuration.";
  434.                 die "Incorrect configuration of Python";
  435.             fi;
  436.             PYTHON_ABIS="${python2_version} ${python3_version}";
  437.             PYTHON_ABIS="${PYTHON_ABIS# }";
  438.             export PYTHON_ABIS="${PYTHON_ABIS% }";
  439.         fi;
  440.     fi;
  441.     _python_final_sanity_checks
  442. }
  443. _python_check_python_abi_matching ()
  444. {
  445.     local pattern patterns patterns_list="0" PYTHON_ABI;
  446.     while (($#)); do
  447.         case "$1" in
  448.             --patterns-list)
  449.                 patterns_list="1"
  450.             ;;
  451.             --)
  452.                 shift;
  453.                 break
  454.             ;;
  455.             -*)
  456.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  457.             ;;
  458.             *)
  459.                 break
  460.             ;;
  461.         esac;
  462.         shift;
  463.     done;
  464.     if [[ "$#" -ne 2 ]]; then
  465.         die "${FUNCNAME}() requires 2 arguments";
  466.     fi;
  467.     PYTHON_ABI="$1";
  468.     if [[ "${patterns_list}" == "0" ]]; then
  469.         pattern="$2";
  470.         if [[ "${pattern}" == *"-cpython" ]]; then
  471.             [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ && "${PYTHON_ABI}" == ${pattern%-cpython} ]];
  472.         else
  473.             if [[ "${pattern}" == *"-jython" ]]; then
  474.                 [[ "${PYTHON_ABI}" == ${pattern} ]];
  475.             else
  476.                 if [[ "${pattern}" == *"-pypy-"* ]]; then
  477.                     [[ "${PYTHON_ABI}" == ${pattern} ]];
  478.                 else
  479.                     if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
  480.                         [[ "${PYTHON_ABI}" == ${pattern} ]];
  481.                     else
  482.                         if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then
  483.                             [[ "${PYTHON_ABI%-jython}" == ${pattern} ]];
  484.                         else
  485.                             if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-pypy-[[:digit:]]+\.[[:digit:]]+$ ]]; then
  486.                                 [[ "${PYTHON_ABI%-pypy-*}" == ${pattern} ]];
  487.                             else
  488.                                 die "${FUNCNAME}(): Unrecognized Python ABI '${PYTHON_ABI}'";
  489.                             fi;
  490.                         fi;
  491.                     fi;
  492.                 fi;
  493.             fi;
  494.         fi;
  495.     else
  496.         patterns="${2// /
  497. }";
  498.         while read pattern; do
  499.             if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
  500.                 return 0;
  501.             fi;
  502.         done <<< "${patterns}";
  503.         return 1;
  504.     fi
  505. }
  506. _python_check_python_pkg_setup_execution ()
  507. {
  508.     [[ " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " ]] && return;
  509.     if ! has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_PKG_SETUP_EXECUTED}" ]]; then
  510.         die "python_pkg_setup() not called";
  511.     fi
  512. }
  513. _python_clean_compiled_modules ()
  514. {
  515.     _python_initialize_prefix_variables;
  516.     _python_set_color_variables;
  517.     [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage";
  518.     local base_module_name compiled_file compiled_files=() dir path py_file root;
  519.     root="${EROOT%/}";
  520.     for path in "$@";
  521.     do
  522.         compiled_files=();
  523.         if [[ -d "${path}" ]]; then
  524.             while read -d '' -r compiled_file; do
  525.                 compiled_files+=("${compiled_file}");
  526.             done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0);
  527.             if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
  528.                 find "${path}" -type d | sort -r | while read -r dir; do
  529.                     if rmdir "${dir}" 2> /dev/null; then
  530.                         echo "${_CYAN}<<< ${dir}${_NORMAL}";
  531.                     fi;
  532.                 done;
  533.             fi;
  534.         else
  535.             if [[ "${path}" == *.py ]]; then
  536.                 base_module_name="${path##*/}";
  537.                 base_module_name="${base_module_name%.py}";
  538.                 if [[ -d "${path%/*}/__pycache__" ]]; then
  539.                     while read -d '' -r compiled_file; do
  540.                         compiled_files+=("${compiled_file}");
  541.                     done < <(find "${path%/*}/__pycache__" "(" -name "${base_module_name}.*.py[co]" -o -name "${base_module_name}\$py.class" ")" -print0);
  542.                 fi;
  543.                 compiled_files+=("${path}c" "${path}o" "${path%.py}\$py.class");
  544.             fi;
  545.         fi;
  546.         for compiled_file in "${compiled_files[@]}";
  547.         do
  548.             [[ ! -f "${compiled_file}" ]] && continue;
  549.             dir="${compiled_file%/*}";
  550.             dir="${dir##*/}";
  551.             if [[ "${compiled_file}" == *.py[co] ]]; then
  552.                 if [[ "${dir}" == "__pycache__" ]]; then
  553.                     base_module_name="${compiled_file##*/}";
  554.                     base_module_name="${base_module_name%.*py[co]}";
  555.                     base_module_name="${base_module_name%.*}";
  556.                     py_file="${compiled_file%__pycache__/*}${base_module_name}.py";
  557.                 else
  558.                     py_file="${compiled_file%[co]}";
  559.                 fi;
  560.                 if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
  561.                     [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue;
  562.                 else
  563.                     [[ -f "${py_file}" ]] && continue;
  564.                 fi;
  565.                 echo "${_BLUE}<<< ${compiled_file%[co]}[co]${_NORMAL}";
  566.                 rm -f "${compiled_file%[co]}"[co];
  567.             else
  568.                 if [[ "${compiled_file}" == *\$py.class ]]; then
  569.                     if [[ "${dir}" == "__pycache__" ]]; then
  570.                         base_module_name="${compiled_file##*/}";
  571.                         base_module_name="${base_module_name%\$py.class}";
  572.                         py_file="${compiled_file%__pycache__/*}${base_module_name}.py";
  573.                     else
  574.                         py_file="${compiled_file%\$py.class}.py";
  575.                     fi;
  576.                     if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
  577.                         [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue;
  578.                     else
  579.                         [[ -f "${py_file}" ]] && continue;
  580.                     fi;
  581.                     echo "${_BLUE}<<< ${compiled_file}${_NORMAL}";
  582.                     rm -f "${compiled_file}";
  583.                 else
  584.                     die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'";
  585.                 fi;
  586.             fi;
  587.             dir="${compiled_file%/*}";
  588.             while [[ "${dir}" != "${root}" ]]; do
  589.                 if rmdir "${dir}" 2> /dev/null; then
  590.                     echo "${_CYAN}<<< ${dir}${_NORMAL}";
  591.                 else
  592.                     break;
  593.                 fi;
  594.                 dir="${dir%/*}";
  595.             done;
  596.         done;
  597.     done
  598. }
  599. _python_final_sanity_checks ()
  600. {
  601.     if ! _python_implementation && [[ "$(declare -p PYTHON_SANITY_CHECKS_EXECUTED 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS_EXECUTED="* || " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " && -z "${PYTHON_SKIP_SANITY_CHECKS}" ]]; then
  602.         local PYTHON_ABI="${PYTHON_ABI}";
  603.         for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}};
  604.         do
  605.             if ! has_version "$(python_get_implementational_package)"; then
  606.                 die "$(python_get_implementational_package) is not installed";
  607.             fi;
  608.             if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then
  609.                 eerror "Path to 'python':                 '$(type -p python)'";
  610.                 eerror "ABI:                              '${ABI}'";
  611.                 eerror "DEFAULT_ABI:                      '${DEFAULT_ABI}'";
  612.                 eerror "EPYTHON:                          '$(PYTHON)'";
  613.                 eerror "PYTHON_ABI:                       '${PYTHON_ABI}'";
  614.                 eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'";
  615.                 die "'python' does not respect EPYTHON variable";
  616.             fi;
  617.         done;
  618.     fi;
  619.     PYTHON_SANITY_CHECKS_EXECUTED="1"
  620. }
  621. _python_get_implementation ()
  622. {
  623.     local ignore_invalid="0";
  624.     while (($#)); do
  625.         case "$1" in
  626.             --ignore-invalid)
  627.                 ignore_invalid="1"
  628.             ;;
  629.             --)
  630.                 shift;
  631.                 break
  632.             ;;
  633.             -*)
  634.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  635.             ;;
  636.             *)
  637.                 break
  638.             ;;
  639.         esac;
  640.         shift;
  641.     done;
  642.     if [[ "$#" -ne 1 ]]; then
  643.         die "${FUNCNAME}() requires 1 argument";
  644.     fi;
  645.     if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
  646.         echo "CPython";
  647.     else
  648.         if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then
  649.             echo "Jython";
  650.         else
  651.             if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-pypy-[[:digit:]]+\.[[:digit:]]+$ ]]; then
  652.                 echo "PyPy";
  653.             else
  654.                 if [[ "${ignore_invalid}" == "0" ]]; then
  655.                     die "${FUNCNAME}(): Unrecognized Python ABI '$1'";
  656.                 fi;
  657.             fi;
  658.         fi;
  659.     fi
  660. }
  661. _python_implementation ()
  662. {
  663.     if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then
  664.         return 0;
  665.     else
  666.         if [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then
  667.             return 0;
  668.         else
  669.             if [[ "${CATEGORY}/${PN}" == "dev-python/pypy" ]]; then
  670.                 return 0;
  671.             else
  672.                 return 1;
  673.             fi;
  674.         fi;
  675.     fi
  676. }
  677. _python_initial_sanity_checks ()
  678. {
  679.     if [[ "$(declare -p PYTHON_SANITY_CHECKS_EXECUTED 2> /dev/null)" != "declare -- PYTHON_SANITY_CHECKS_EXECUTED="* || " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " && -z "${PYTHON_SKIP_SANITY_CHECKS}" ]]; then
  680.         if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
  681.             eerror "'${EPREFIX}/usr/bin/python' is not valid symlink.";
  682.             eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem.";
  683.             die "'${EPREFIX}/usr/bin/python' is not valid symlink";
  684.         fi;
  685.         if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then
  686.             eerror "'${EPREFIX}/usr/bin/python-config' is not valid script";
  687.             eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem.";
  688.             die "'${EPREFIX}/usr/bin/python-config' is not valid script";
  689.         fi;
  690.     fi
  691. }
  692. _python_initialize_prefix_variables ()
  693. {
  694.     if has "${EAPI:-0}" 0 1 2; then
  695.         if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
  696.             EROOT="${ROOT%/}${EPREFIX}/";
  697.         fi;
  698.         if [[ -n "${D}" && -z "${ED}" ]]; then
  699.             ED="${D%/}${EPREFIX}/";
  700.         fi;
  701.     fi
  702. }
  703. _python_package_supporting_installation_for_multiple_python_abis ()
  704. {
  705.     if has "${EAPI:-0}" 0 1 2 3 4; then
  706.         if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
  707.             return 0;
  708.         else
  709.             return 1;
  710.         fi;
  711.     else
  712.         die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented";
  713.     fi
  714. }
  715. _python_prepare_flags ()
  716. {
  717.     local array=() deleted_flag element flags new_value old_flag old_value operator pattern prefix variable;
  718.     for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS;
  719.     do
  720.         eval "_PYTHON_SAVED_${variable}=\"\${!variable}\"";
  721.         for prefix in PYTHON_USER_ PYTHON_;
  722.         do
  723.             if [[ "$(declare -p ${prefix}${variable} 2> /dev/null)" == "declare -a ${prefix}${variable}="* ]]; then
  724.                 eval "array=(\"\${${prefix}${variable}[@]}\")";
  725.                 for element in "${array[@]}";
  726.                 do
  727.                     if [[ "${element}" =~ ^${_PYTHON_ABI_PATTERN_REGEX}\ (\+|-)\ .+ ]]; then
  728.                         pattern="${element%% *}";
  729.                         element="${element#* }";
  730.                         operator="${element%% *}";
  731.                         flags="${element#* }";
  732.                         if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
  733.                             if [[ "${operator}" == "+" ]]; then
  734.                                 eval "export ${variable}+=\"\${variable:+ }${flags}\"";
  735.                             else
  736.                                 if [[ "${operator}" == "-" ]]; then
  737.                                     flags="${flags// /
  738. }";
  739.                                     old_value="${!variable// /
  740. }";
  741.                                     new_value="";
  742.                                     while read old_flag; do
  743.                                         while read deleted_flag; do
  744.                                             if [[ "${old_flag}" == ${deleted_flag} ]]; then
  745.                                                 continue 2;
  746.                                             fi;
  747.                                         done <<< "${flags}";
  748.                                         new_value+="${new_value:+ }${old_flag}";
  749.                                     done <<< "${old_value}";
  750.                                     eval "export ${variable}=\"\${new_value}\"";
  751.                                 fi;
  752.                             fi;
  753.                         fi;
  754.                     else
  755.                         die "Element '${element}' of ${prefix}${variable} array has invalid syntax";
  756.                     fi;
  757.                 done;
  758.             else
  759.                 if [[ -n "$(declare -p ${prefix}${variable} 2> /dev/null)" ]]; then
  760.                     die "${prefix}${variable} should be indexed array";
  761.                 fi;
  762.             fi;
  763.         done;
  764.     done
  765. }
  766. _python_restore_flags ()
  767. {
  768.     local variable;
  769.     for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS;
  770.     do
  771.         eval "${variable}=\"\${_PYTHON_SAVED_${variable}}\"";
  772.         unset _PYTHON_SAVED_${variable};
  773.     done
  774. }
  775. _python_set_color_variables ()
  776. {
  777.     if [[ "${PYTHON_COLORS}" != "0" && "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
  778.         _BOLD='';
  779.         _RED='';
  780.         _GREEN='';
  781.         _BLUE='';
  782.         _CYAN='';
  783.         _NORMAL='';
  784.     else
  785.         _BOLD=;
  786.         _RED=;
  787.         _GREEN=;
  788.         _BLUE=;
  789.         _CYAN=;
  790.         _NORMAL=;
  791.     fi
  792. }
  793. _python_test_hook ()
  794. {
  795.     if [[ "$#" -ne 1 ]]; then
  796.         die "${FUNCNAME}() requires 1 argument";
  797.     fi;
  798.     if _python_package_supporting_installation_for_multiple_python_abis && [[ "$(type -t "${_PYTHON_TEST_FUNCTION}_$1_hook")" == "function" ]]; then
  799.         "${_PYTHON_TEST_FUNCTION}_$1_hook";
  800.     fi
  801. }
  802. _tc-getPROG ()
  803. {
  804.     local tuple=$1;
  805.     local v var vars=$2;
  806.     local prog=$3;
  807.     var=${vars%% *};
  808.     for v in ${vars};
  809.     do
  810.         if [[ -n ${!v} ]]; then
  811.             export ${var}="${!v}";
  812.             echo "${!v}";
  813.             return 0;
  814.         fi;
  815.     done;
  816.     local search=;
  817.     [[ -n $4 ]] && search=$(type -p "$4-${prog}");
  818.     [[ -z ${search} && -n ${!tuple} ]] && search=$(type -p "${!tuple}-${prog}");
  819.     [[ -n ${search} ]] && prog=${search##*/};
  820.     export ${var}=${prog};
  821.     echo "${!var}"
  822. }
  823. blend_with ()
  824. {
  825.     local UWORD="$2";
  826.     if [ -z "${UWORD}" ]; then
  827.         UWORD="$1";
  828.     fi;
  829.     if use $1; then
  830.         echo "WITH_BF_${UWORD}=1" | tr '[:lower:]' '[:upper:]' >> "${S}"/user-config.py;
  831.     else
  832.         echo "WITH_BF_${UWORD}=0" | tr '[:lower:]' '[:upper:]' >> "${S}"/user-config.py;
  833.     fi
  834. }
  835. built_with_use ()
  836. {
  837.     local hidden="no";
  838.     if [[ $1 == "--hidden" ]]; then
  839.         hidden="yes";
  840.         shift;
  841.     fi;
  842.     local missing_action="die";
  843.     if [[ $1 == "--missing" ]]; then
  844.         missing_action=$2;
  845.         shift;
  846.         shift;
  847.         case ${missing_action} in
  848.             true | false | die)
  849.  
  850.             ;;
  851.             *)
  852.                 die "unknown action '${missing_action}'"
  853.             ;;
  854.         esac;
  855.     fi;
  856.     local opt=$1;
  857.     [[ ${opt:0:1} = "-" ]] && shift || opt="-a";
  858.     local PKG=$(best_version $1);
  859.     [[ -z ${PKG} ]] && die "Unable to resolve $1 to an installed package";
  860.     shift;
  861.     local USEFILE=${ROOT}/var/db/pkg/${PKG}/USE;
  862.     local IUSEFILE=${ROOT}/var/db/pkg/${PKG}/IUSE;
  863.     if [[ ! -e ${USEFILE} ]] || [[ ! -e ${IUSEFILE} && ${hidden} == "no" ]]; then
  864.         case ${missing_action} in
  865.             true)
  866.                 return 0
  867.             ;;
  868.             false)
  869.                 return 1
  870.             ;;
  871.             die)
  872.                 die "Unable to determine what USE flags $PKG was built with"
  873.             ;;
  874.         esac;
  875.     fi;
  876.     if [[ ${hidden} == "no" ]]; then
  877.         local IUSE_BUILT=($(<"${IUSEFILE}"));
  878.         local expand;
  879.         for expand in $(echo ${USE_EXPAND} | tr '[:upper:]' '[:lower:]');
  880.         do
  881.             if [[ $1 == ${expand}_* ]]; then
  882.                 expand="";
  883.                 break;
  884.             fi;
  885.         done;
  886.         if [[ -n ${expand} ]]; then
  887.             if ! has $1 ${IUSE_BUILT[@]#[-+]}; then
  888.                 case ${missing_action} in
  889.                     true)
  890.                         return 0
  891.                     ;;
  892.                     false)
  893.                         return 1
  894.                     ;;
  895.                     die)
  896.                         die "$PKG does not actually support the $1 USE flag!"
  897.                     ;;
  898.                 esac;
  899.             fi;
  900.         fi;
  901.     fi;
  902.     local USE_BUILT=$(<${USEFILE});
  903.     while [[ $# -gt 0 ]]; do
  904.         if [[ ${opt} = "-o" ]]; then
  905.             has $1 ${USE_BUILT} && return 0;
  906.         else
  907.             has $1 ${USE_BUILT} || return 1;
  908.         fi;
  909.         shift;
  910.     done;
  911.     [[ ${opt} = "-a" ]]
  912. }
  913. check_license ()
  914. {
  915.     die "you no longer need this as portage supports ACCEPT_LICENSE itself"
  916. }
  917. doicon ()
  918. {
  919.     ( local i j ret;
  920.     insinto /usr/share/pixmaps;
  921.     for i in "$@";
  922.     do
  923.         if [[ -f ${i} ]]; then
  924.             doins "${i}";
  925.             ((ret+=$?));
  926.         else
  927.             if [[ -d ${i} ]]; then
  928.                 for j in "${i}"/*.png;
  929.                 do
  930.                     doins "${j}";
  931.                     ((ret+=$?));
  932.                 done;
  933.             else
  934.                 ((++ret));
  935.             fi;
  936.         fi;
  937.     done;
  938.     exit ${ret} )
  939. }
  940. domenu ()
  941. {
  942.     ( local i j ret=0;
  943.     insinto /usr/share/applications;
  944.     for i in "$@";
  945.     do
  946.         if [[ -f ${i} ]]; then
  947.             doins "${i}";
  948.             ((ret+=$?));
  949.         else
  950.             if [[ -d ${i} ]]; then
  951.                 for j in "${i}"/*.desktop;
  952.                 do
  953.                     doins "${j}";
  954.                     ((ret+=$?));
  955.                 done;
  956.             else
  957.                 ((++ret));
  958.             fi;
  959.         fi;
  960.     done;
  961.     exit ${ret} )
  962. }
  963. ebeep ()
  964. {
  965.     local n;
  966.     if [[ -z ${EBEEP_IGNORE} ]]; then
  967.         for ((n=1 ; n <= ${1:-5} ; n++))
  968.         do
  969.             echo -ne "\a";
  970.             sleep 0.1 &>/dev/null;
  971.             sleep 0,1 &>/dev/null;
  972.             echo -ne "\a";
  973.             sleep 1;
  974.         done;
  975.     fi
  976. }
  977. econf_build ()
  978. {
  979.     tc-env_build econf --build=${CBUILD:-${CHOST}} "$@"
  980. }
  981. ecvs_clean ()
  982. {
  983.     [[ -z $* ]] && set -- .;
  984.     find "$@" -type d -name 'CVS' -prune -print0 | xargs -0 rm -rf;
  985.     find "$@" -type f -name '.cvs*' -print0 | xargs -0 rm -rf
  986. }
  987. edos2unix ()
  988. {
  989.     [[ $# -eq 0 ]] && return 0;
  990.     sed -i 's/\r$//' -- "$@" || die
  991. }
  992. egetent ()
  993. {
  994.     local db=$1 key=$2;
  995.     [[ $# -ge 3 ]] && die "usage: egetent <database> <key>";
  996.     case ${db} in
  997.         passwd | group)
  998.  
  999.         ;;
  1000.         *)
  1001.             die "sorry, database '${db}' not yet supported; file a bug"
  1002.         ;;
  1003.     esac;
  1004.     case ${CHOST} in
  1005.         *-darwin[678])
  1006.             case ${key} in
  1007.                 *[!0-9]*)
  1008.                     nidump ${db} . | awk -F: "(\$1 ~ /^${key}\$/) {print;exit;}"
  1009.                 ;;
  1010.                 *)
  1011.                     nidump ${db} . | awk -F: "(\$3 == ${key}) {print;exit;}"
  1012.                 ;;
  1013.             esac
  1014.         ;;
  1015.         *-darwin*)
  1016.             local mykey;
  1017.             case ${db} in
  1018.                 passwd)
  1019.                     db="Users" mykey="UniqueID"
  1020.                 ;;
  1021.                 group)
  1022.                     db="Groups" mykey="PrimaryGroupID"
  1023.                 ;;
  1024.             esac;
  1025.             case ${key} in
  1026.                 *[!0-9]*)
  1027.                     dscl . -read /${db}/${key} 2> /dev/null | grep RecordName
  1028.                 ;;
  1029.                 *)
  1030.                     dscl . -search /${db} ${mykey} ${key} 2> /dev/null
  1031.                 ;;
  1032.             esac
  1033.         ;;
  1034.         *-freebsd* | *-dragonfly*)
  1035.             case ${db} in
  1036.                 passwd)
  1037.                     db="user"
  1038.                 ;;
  1039.                 *)
  1040.  
  1041.                 ;;
  1042.             esac;
  1043.             local opts;
  1044.             if [[ ${key} == [[:digit:]]* ]]; then
  1045.                 [[ ${db} == "user" ]] && opts="-u" || opts="-g";
  1046.             fi;
  1047.             pw show ${db} ${opts} "${key}" -q
  1048.         ;;
  1049.         *-netbsd* | *-openbsd*)
  1050.             grep "${key}:\*:" /etc/${db}
  1051.         ;;
  1052.         *)
  1053.             nscd -i "${db}" 2> /dev/null;
  1054.             getent "${db}" "${key}"
  1055.         ;;
  1056.     esac
  1057. }
  1058. egethome ()
  1059. {
  1060.     local pos;
  1061.     [[ $# -eq 1 ]] || die "usage: egethome <user>";
  1062.     case ${CHOST} in
  1063.         *-darwin* | *-freebsd* | *-dragonfly*)
  1064.             pos=9
  1065.         ;;
  1066.         *)
  1067.             pos=6
  1068.         ;;
  1069.     esac;
  1070.     egetent passwd "$1" | cut -d: -f${pos}
  1071. }
  1072. egetshell ()
  1073. {
  1074.     local pos;
  1075.     [[ $# -eq 1 ]] || die "usage: egetshell <user>";
  1076.     case ${CHOST} in
  1077.         *-darwin* | *-freebsd* | *-dragonfly*)
  1078.             pos=10
  1079.         ;;
  1080.         *)
  1081.             pos=7
  1082.         ;;
  1083.     esac;
  1084.     egetent passwd "$1" | cut -d: -f${pos}
  1085. }
  1086. emktemp ()
  1087. {
  1088.     local exe="touch";
  1089.     [[ $1 == -d ]] && exe="mkdir" && shift;
  1090.     local topdir=$1;
  1091.     if [[ -z ${topdir} ]]; then
  1092.         [[ -z ${T} ]] && topdir="/tmp" || topdir=${T};
  1093.     fi;
  1094.     if ! type -P mktemp > /dev/null; then
  1095.         local tmp=/;
  1096.         while [[ -e ${tmp} ]]; do
  1097.             tmp=${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM};
  1098.         done;
  1099.         ${exe} "${tmp}" || ${exe} -p "${tmp}";
  1100.         echo "${tmp}";
  1101.     else
  1102.         if [[ ${exe} == "touch" ]]; then
  1103.             TMPDIR="${topdir}" mktemp -t tmp.XXXXXXXXXX;
  1104.         else
  1105.             TMPDIR="${topdir}" mktemp -dt tmp.XXXXXXXXXX;
  1106.         fi;
  1107.     fi
  1108. }
  1109. enewgroup ()
  1110. {
  1111.     _assert_pkg_ebuild_phase ${FUNCNAME};
  1112.     local egroup=$1;
  1113.     shift;
  1114.     if [[ -z ${egroup} ]]; then
  1115.         eerror "No group specified !";
  1116.         die "Cannot call enewgroup without a group";
  1117.     fi;
  1118.     if [[ -n $(egetent group "${egroup}") ]]; then
  1119.         return 0;
  1120.     fi;
  1121.     einfo "Adding group '${egroup}' to your system ...";
  1122.     local egid=$1;
  1123.     shift;
  1124.     if [[ ! -z ${egid} ]]; then
  1125.         if [[ ${egid} -gt 0 ]]; then
  1126.             if [[ -n $(egetent group ${egid}) ]]; then
  1127.                 egid="next available; requested gid taken";
  1128.             fi;
  1129.         else
  1130.             eerror "Groupid given but is not greater than 0 !";
  1131.             die "${egid} is not a valid GID";
  1132.         fi;
  1133.     else
  1134.         egid="next available";
  1135.     fi;
  1136.     einfo " - Groupid: ${egid}";
  1137.     if [[ $# -gt 0 ]]; then
  1138.         die "extra arguments no longer supported; please file a bug";
  1139.     fi;
  1140.     function _enewgroup_next_gid ()
  1141.     {
  1142.         if [[ ${egid} == *[!0-9]* ]]; then
  1143.             for ((egid = 101; egid <= 999; egid++))
  1144.             do
  1145.                 [[ -z $(egetent group ${egid}) ]] && break;
  1146.             done;
  1147.         fi
  1148.     };
  1149.     case ${CHOST} in
  1150.         *-darwin*)
  1151.             _enewgroup_next_gid;
  1152.             dscl . create "/groups/${egroup}" gid ${egid};
  1153.             dscl . create "/groups/${egroup}" passwd '*'
  1154.         ;;
  1155.         *-freebsd* | *-dragonfly*)
  1156.             _enewgroup_next_gid;
  1157.             pw groupadd "${egroup}" -g ${egid} || die
  1158.         ;;
  1159.         *-netbsd*)
  1160.             _enewgroup_next_gid;
  1161.             groupadd -g ${egid} "${egroup}" || die
  1162.         ;;
  1163.         *)
  1164.             local opts;
  1165.             if [[ ${egid} == *[!0-9]* ]]; then
  1166.                 opts="";
  1167.             else
  1168.                 opts="-g ${egid}";
  1169.             fi;
  1170.             groupadd -r ${opts} "${egroup}" || die
  1171.         ;;
  1172.     esac
  1173. }
  1174. enewuser ()
  1175. {
  1176.     _assert_pkg_ebuild_phase ${FUNCNAME};
  1177.     local euser=$1;
  1178.     shift;
  1179.     if [[ -z ${euser} ]]; then
  1180.         eerror "No username specified !";
  1181.         die "Cannot call enewuser without a username";
  1182.     fi;
  1183.     if [[ -n $(egetent passwd "${euser}") ]]; then
  1184.         return 0;
  1185.     fi;
  1186.     einfo "Adding user '${euser}' to your system ...";
  1187.     local opts=();
  1188.     local euid=$1;
  1189.     shift;
  1190.     if [[ -n ${euid} && ${euid} != -1 ]]; then
  1191.         if [[ ${euid} -gt 0 ]]; then
  1192.             if [[ -n $(egetent passwd ${euid}) ]]; then
  1193.                 euid="next";
  1194.             fi;
  1195.         else
  1196.             eerror "Userid given but is not greater than 0 !";
  1197.             die "${euid} is not a valid UID";
  1198.         fi;
  1199.     else
  1200.         euid="next";
  1201.     fi;
  1202.     if [[ ${euid} == "next" ]]; then
  1203.         for ((euid = 101; euid <= 999; euid++))
  1204.         do
  1205.             [[ -z $(egetent passwd ${euid}) ]] && break;
  1206.         done;
  1207.     fi;
  1208.     opts+=(-u ${euid});
  1209.     einfo " - Userid: ${euid}";
  1210.     local eshell=$1;
  1211.     shift;
  1212.     if [[ ! -z ${eshell} ]] && [[ ${eshell} != "-1" ]]; then
  1213.         if [[ ! -e ${ROOT}${eshell} ]]; then
  1214.             eerror "A shell was specified but it does not exist !";
  1215.             die "${eshell} does not exist in ${ROOT}";
  1216.         fi;
  1217.         if [[ ${eshell} == */false || ${eshell} == */nologin ]]; then
  1218.             eerror "Do not specify ${eshell} yourself, use -1";
  1219.             die "Pass '-1' as the shell parameter";
  1220.         fi;
  1221.     else
  1222.         for eshell in /sbin/nologin /usr/sbin/nologin /bin/false /usr/bin/false /dev/null;
  1223.         do
  1224.             [[ -x ${ROOT}${eshell} ]] && break;
  1225.         done;
  1226.         if [[ ${eshell} == "/dev/null" ]]; then
  1227.             eerror "Unable to identify the shell to use, proceeding with userland default.";
  1228.             case ${USERLAND} in
  1229.                 GNU)
  1230.                     eshell="/bin/false"
  1231.                 ;;
  1232.                 BSD)
  1233.                     eshell="/sbin/nologin"
  1234.                 ;;
  1235.                 Darwin)
  1236.                     eshell="/usr/sbin/nologin"
  1237.                 ;;
  1238.                 *)
  1239.                     die "Unable to identify the default shell for userland ${USERLAND}"
  1240.                 ;;
  1241.             esac;
  1242.         fi;
  1243.     fi;
  1244.     einfo " - Shell: ${eshell}";
  1245.     opts+=(-s "${eshell}");
  1246.     local ehome=$1;
  1247.     shift;
  1248.     if [[ -z ${ehome} ]] || [[ ${ehome} == "-1" ]]; then
  1249.         ehome="/dev/null";
  1250.     fi;
  1251.     einfo " - Home: ${ehome}";
  1252.     opts+=(-d "${ehome}");
  1253.     local egroups=$1;
  1254.     shift;
  1255.     local g egroups_arr;
  1256.     IFS="," read -r -a egroups_arr <<< "${egroups}";
  1257.     shift;
  1258.     if [[ ${#egroups_arr[@]} -gt 0 ]]; then
  1259.         local defgroup exgroups;
  1260.         for g in "${egroups_arr[@]}";
  1261.         do
  1262.             if [[ -z $(egetent group "${g}") ]]; then
  1263.                 eerror "You must add group ${g} to the system first";
  1264.                 die "${g} is not a valid GID";
  1265.             fi;
  1266.             if [[ -z ${defgroup} ]]; then
  1267.                 defgroup=${g};
  1268.             else
  1269.                 exgroups+=",${g}";
  1270.             fi;
  1271.         done;
  1272.         opts+=(-g "${defgroup}");
  1273.         if [[ ! -z ${exgroups} ]]; then
  1274.             opts+=(-G "${exgroups:1}");
  1275.         fi;
  1276.     fi;
  1277.     einfo " - Groups: ${egroups:-(none)}";
  1278.     if [[ $# -gt 0 ]]; then
  1279.         die "extra arguments no longer supported; please file a bug";
  1280.     else
  1281.         local comment="added by portage for ${PN}";
  1282.         opts+=(-c "${comment}");
  1283.         einfo " - GECOS: ${comment}";
  1284.     fi;
  1285.     case ${CHOST} in
  1286.         *-darwin*)
  1287.             dscl . create "/users/${euser}" uid ${euid};
  1288.             dscl . create "/users/${euser}" shell "${eshell}";
  1289.             dscl . create "/users/${euser}" home "${ehome}";
  1290.             dscl . create "/users/${euser}" realname "added by portage for ${PN}";
  1291.             for g in "${egroups_arr[@]}";
  1292.             do
  1293.                 dscl . merge "/groups/${g}" users "${euser}";
  1294.             done
  1295.         ;;
  1296.         *-freebsd* | *-dragonfly*)
  1297.             pw useradd "${euser}" "${opts[@]}" || die
  1298.         ;;
  1299.         *-netbsd*)
  1300.             useradd "${opts[@]}" "${euser}" || die
  1301.         ;;
  1302.         *-openbsd*)
  1303.             useradd -u ${euid} -s "${eshell}" -d "${ehome}" -g "${egroups}" "${euser}" || die
  1304.         ;;
  1305.         *)
  1306.             useradd -r "${opts[@]}" "${euser}" || die
  1307.         ;;
  1308.     esac;
  1309.     if [[ ! -e ${ROOT}/${ehome} ]]; then
  1310.         einfo " - Creating ${ehome} in ${ROOT}";
  1311.         mkdir -p "${ROOT}/${ehome}";
  1312.         chown "${euser}" "${ROOT}/${ehome}";
  1313.         chmod 755 "${ROOT}/${ehome}";
  1314.     fi
  1315. }
  1316. epatch ()
  1317. {
  1318.     function _epatch_draw_line ()
  1319.     {
  1320.         [[ -z $1 ]] && set "$(printf "%65s" '')";
  1321.         echo "${1//?/=}"
  1322.     };
  1323.     unset P4CONFIG P4PORT P4USER;
  1324.     local EPATCH_OPTS=(${EPATCH_OPTS[*]});
  1325.     while [[ $# -gt 0 ]]; do
  1326.         case $1 in
  1327.             -*)
  1328.                 EPATCH_OPTS+=("$1")
  1329.             ;;
  1330.             *)
  1331.                 break
  1332.             ;;
  1333.         esac;
  1334.         shift;
  1335.     done;
  1336.     if [[ $# -gt 1 ]]; then
  1337.         local m;
  1338.         for m in "$@";
  1339.         do
  1340.             epatch "${m}";
  1341.         done;
  1342.         return 0;
  1343.     fi;
  1344.     local SINGLE_PATCH="no";
  1345.     [[ $# -eq 0 ]] && set -- "${EPATCH_SOURCE}";
  1346.     if [[ -f $1 ]]; then
  1347.         SINGLE_PATCH="yes";
  1348.         set -- "$1";
  1349.         local EPATCH_SUFFIX=$1;
  1350.     else
  1351.         if [[ -d $1 ]]; then
  1352.             set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"};
  1353.         else
  1354.             if [[ -f ${EPATCH_SOURCE}/$1 ]]; then
  1355.                 epatch "${EPATCH_SOURCE}/$1";
  1356.                 return $?;
  1357.             else
  1358.                 [[ $# -ne 0 ]] && EPATCH_SOURCE=$1;
  1359.                 echo;
  1360.                 eerror "Cannot find \$EPATCH_SOURCE!  Value for \$EPATCH_SOURCE is:";
  1361.                 eerror;
  1362.                 eerror "  ${EPATCH_SOURCE}";
  1363.                 eerror "  ( ${EPATCH_SOURCE##*/} )";
  1364.                 echo;
  1365.                 die "Cannot find \$EPATCH_SOURCE!";
  1366.             fi;
  1367.         fi;
  1368.     fi;
  1369.     EPATCH_OPTS="${EPATCH_COMMON_OPTS} ${EPATCH_OPTS[*]}";
  1370.     local PIPE_CMD;
  1371.     case ${EPATCH_SUFFIX##*\.} in
  1372.         xz)
  1373.             PIPE_CMD="xz -dc"
  1374.         ;;
  1375.         lzma)
  1376.             PIPE_CMD="lzma -dc"
  1377.         ;;
  1378.         bz2)
  1379.             PIPE_CMD="bzip2 -dc"
  1380.         ;;
  1381.         gz | Z | z)
  1382.             PIPE_CMD="gzip -dc"
  1383.         ;;
  1384.         ZIP | zip)
  1385.             PIPE_CMD="unzip -p"
  1386.         ;;
  1387.         *)
  1388.  
  1389.         ;;
  1390.     esac;
  1391.     [[ ${SINGLE_PATCH} == "no" ]] && einfo "${EPATCH_MULTI_MSG}";
  1392.     local x;
  1393.     for x in "$@";
  1394.     do
  1395.         [[ ! -f ${x} ]] && continue;
  1396.         local patchname=${x##*/};
  1397.         local a=${patchname#*_};
  1398.         a=${a%%_*};
  1399.         if ! [[ ${SINGLE_PATCH} == "yes" || ${EPATCH_FORCE} == "yes" || ${a} == all || ${a} == ${ARCH} ]]; then
  1400.             continue;
  1401.         fi;
  1402.         if [[ -n ${EPATCH_EXCLUDE} ]]; then
  1403.             eshopts_push -o noglob;
  1404.             local ex;
  1405.             for ex in ${EPATCH_EXCLUDE};
  1406.             do
  1407.                 if [[ ${patchname} == ${ex} ]]; then
  1408.                     eshopts_pop;
  1409.                     continue 2;
  1410.                 fi;
  1411.             done;
  1412.             eshopts_pop;
  1413.         fi;
  1414.         if [[ ${SINGLE_PATCH} == "yes" ]]; then
  1415.             if [[ -n ${EPATCH_SINGLE_MSG} ]]; then
  1416.                 einfo "${EPATCH_SINGLE_MSG}";
  1417.             else
  1418.                 einfo "Applying ${patchname} ...";
  1419.             fi;
  1420.         else
  1421.             einfo "  ${patchname} ...";
  1422.         fi;
  1423.         local STDERR_TARGET="${T}/${patchname}.out";
  1424.         if [[ -e ${STDERR_TARGET} ]]; then
  1425.             STDERR_TARGET="${T}/${patchname}-$$.out";
  1426.         fi;
  1427.         printf "***** %s *****\nPWD: %s\n\n" "${patchname}" "${PWD}" > "${STDERR_TARGET}";
  1428.         local count=0;
  1429.         local PATCH_TARGET;
  1430.         if [[ -n ${PIPE_CMD} ]]; then
  1431.             PATCH_TARGET="${T}/$$.patch";
  1432.             echo "PIPE_COMMAND:  ${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> "${STDERR_TARGET}";
  1433.             if ! ( ${PIPE_CMD} "${x}" > "${PATCH_TARGET}" ) >> "${STDERR_TARGET}" 2>&1; then
  1434.                 echo;
  1435.                 eerror "Could not extract patch!";
  1436.                 count=5;
  1437.                 break;
  1438.             fi;
  1439.         else
  1440.             PATCH_TARGET=${x};
  1441.         fi;
  1442.         local abs_paths=$(egrep -n '^[-+]{3} /' "${PATCH_TARGET}" | awk '$2 != "/dev/null" { print }');
  1443.         if [[ -n ${abs_paths} ]]; then
  1444.             count=1;
  1445.             printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}";
  1446.         fi;
  1447.         local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}");
  1448.         if [[ -n ${rel_paths} ]]; then
  1449.             eqawarn "QA Notice: Your patch uses relative paths '../'.";
  1450.             eqawarn " In the future this will cause a failure.";
  1451.             eqawarn "${rel_paths}";
  1452.         fi;
  1453.         local patch_cmd;
  1454.         while [[ ${count} -lt 5 ]]; do
  1455.             patch_cmd="${BASH_ALIASES[patch]:-patch} -p${count} ${EPATCH_OPTS}";
  1456.             ( _epatch_draw_line "***** ${patchname} *****";
  1457.             echo;
  1458.             echo "PATCH COMMAND:  ${patch_cmd} < '${PATCH_TARGET}'";
  1459.             echo;
  1460.             _epatch_draw_line "***** ${patchname} *****";
  1461.             ${patch_cmd} --dry-run -f < "${PATCH_TARGET}" 2>&1;
  1462.             ret=$?;
  1463.             echo;
  1464.             echo "patch program exited with status ${ret}";
  1465.             exit ${ret} ) >> "${STDERR_TARGET}";
  1466.             if [ $? -eq 0 ]; then
  1467.                 ( _epatch_draw_line "***** ${patchname} *****";
  1468.                 echo;
  1469.                 echo "ACTUALLY APPLYING ${patchname} ...";
  1470.                 echo;
  1471.                 _epatch_draw_line "***** ${patchname} *****";
  1472.                 ${patch_cmd} < "${PATCH_TARGET}" 2>&1;
  1473.                 ret=$?;
  1474.                 echo;
  1475.                 echo "patch program exited with status ${ret}";
  1476.                 exit ${ret} ) >> "${STDERR_TARGET}";
  1477.                 if [ $? -ne 0 ]; then
  1478.                     echo;
  1479.                     eerror "A dry-run of patch command succeeded, but actually";
  1480.                     eerror "applying the patch failed!";
  1481.                     count=5;
  1482.                 fi;
  1483.                 break;
  1484.             fi;
  1485.             : $(( count++ ));
  1486.         done;
  1487.         if [[ -n ${PIPE_CMD} ]]; then
  1488.             rm -f "${PATCH_TARGET}";
  1489.         fi;
  1490.         if [[ ${count} -ge 5 ]]; then
  1491.             echo;
  1492.             eerror "Failed Patch: ${patchname} !";
  1493.             eerror " ( ${PATCH_TARGET} )";
  1494.             eerror;
  1495.             eerror "Include in your bugreport the contents of:";
  1496.             eerror;
  1497.             eerror "  ${STDERR_TARGET}";
  1498.             echo;
  1499.             die "Failed Patch: ${patchname}!";
  1500.         fi;
  1501.         rm -f "${STDERR_TARGET}";
  1502.         cat >> "${T}/epatch.log"  <<-EOF
  1503. PATCH: ${x}
  1504. CMD: ${patch_cmd}
  1505. PWD: ${PWD}
  1506.  
  1507. EOF
  1508.  
  1509.         eend 0;
  1510.     done;
  1511.     [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching";
  1512.     :
  1513. }
  1514. epatch_user ()
  1515. {
  1516.     [[ $# -ne 0 ]] && die "epatch_user takes no options";
  1517.     local applied="${T}/epatch_user.log";
  1518.     [[ -e ${applied} ]] && return 2;
  1519.     local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches;
  1520.     for check in ${CATEGORY}/{${P}-${PR},${P},${PN}};
  1521.     do
  1522.         EPATCH_SOURCE=${base}/${CTARGET}/${check};
  1523.         [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check};
  1524.         [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check};
  1525.         if [[ -d ${EPATCH_SOURCE} ]]; then
  1526.             EPATCH_SOURCE=${EPATCH_SOURCE} EPATCH_SUFFIX="patch" EPATCH_FORCE="yes" EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." epatch;
  1527.             echo "${EPATCH_SOURCE}" > "${applied}";
  1528.             return 0;
  1529.         fi;
  1530.     done;
  1531.     echo "none" > "${applied}";
  1532.     return 1
  1533. }
  1534. epause ()
  1535. {
  1536.     [[ -z ${EPAUSE_IGNORE} ]] && sleep ${1:-5}
  1537. }
  1538. epunt_cxx ()
  1539. {
  1540.     local dir=$1;
  1541.     [[ -z ${dir} ]] && dir=${S};
  1542.     ebegin "Removing useless C++ checks";
  1543.     local f;
  1544.     find "${dir}" -name configure | while read f; do
  1545.         patch --no-backup-if-mismatch -p0 "${f}" "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null;
  1546.     done;
  1547.     eend 0
  1548. }
  1549. escons ()
  1550. {
  1551.     local ret;
  1552.     debug-print-function ${FUNCNAME} "${@}";
  1553.     set -- scons ${SCONSOPTS-$(scons_clean_makeopts)} ${EXTRA_ESCONS} "${myesconsargs[@]}" "${@}";
  1554.     echo "${@}" 1>&2;
  1555.     "${@}";
  1556.     ret=${?};
  1557.     [[ ${ret} -ne 0 && ${EAPI} == 4 ]] && die "escons failed.";
  1558.     return ${ret}
  1559. }
  1560. eshopts_pop ()
  1561. {
  1562.     local s;
  1563.     estack_pop eshopts s || die "${FUNCNAME}: unbalanced push";
  1564.     if [[ ${s} == "shopt -"* ]]; then
  1565.         eval "${s}" || die "${FUNCNAME}: sanity: invalid shopt options: ${s}";
  1566.     else
  1567.         set +$- || die "${FUNCNAME}: sanity: invalid shell settings: $-";
  1568.         set -${s} || die "${FUNCNAME}: sanity: unable to restore saved shell settings: ${s}";
  1569.     fi
  1570. }
  1571. eshopts_push ()
  1572. {
  1573.     if [[ $1 == -[su] ]]; then
  1574.         estack_push eshopts "$(shopt -p)";
  1575.         [[ $# -eq 0 ]] && return 0;
  1576.         shopt "$@" || die "${FUNCNAME}: bad options to shopt: $*";
  1577.     else
  1578.         estack_push eshopts $-;
  1579.         [[ $# -eq 0 ]] && return 0;
  1580.         set "$@" || die "${FUNCNAME}: bad options to set: $*";
  1581.     fi
  1582. }
  1583. estack_pop ()
  1584. {
  1585.     [[ $# -eq 0 || $# -gt 2 ]] && die "estack_pop: incorrect # of arguments";
  1586.     local __estack_name="__ESTACK_$1__";
  1587.     shift;
  1588.     local __estack_retvar=$1;
  1589.     shift;
  1590.     eval local __estack_i=\${#${__estack_name}\[@\]};
  1591.     [[ $(( --__estack_i )) -eq -1 ]] && return 1;
  1592.     if [[ -n ${__estack_retvar} ]]; then
  1593.         eval ${__estack_retvar}=\"\${${__estack_name}\[${__estack_i}\]}\";
  1594.     fi;
  1595.     eval unset ${__estack_name}\[${__estack_i}\]
  1596. }
  1597. estack_push ()
  1598. {
  1599.     [[ $# -eq 0 ]] && die "estack_push: incorrect # of arguments";
  1600.     local stack_name="__ESTACK_$1__";
  1601.     shift;
  1602.     eval ${stack_name}+=\( \"\$@\" \)
  1603. }
  1604. esvn_clean ()
  1605. {
  1606.     [[ -z $* ]] && set -- .;
  1607.     find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf
  1608. }
  1609. eumask_pop ()
  1610. {
  1611.     [[ $# -eq 0 ]] || die "${FUNCNAME}: we take no options";
  1612.     local s;
  1613.     estack_pop eumask s || die "${FUNCNAME}: unbalanced push";
  1614.     umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}"
  1615. }
  1616. eumask_push ()
  1617. {
  1618.     estack_push eumask "$(umask)";
  1619.     umask "$@" || die "${FUNCNAME}: bad options to umask: $*"
  1620. }
  1621. gcc-fullversion ()
  1622. {
  1623.     _gcc_fullversion '$1.$2.$3' "$@"
  1624. }
  1625. gcc-major-version ()
  1626. {
  1627.     _gcc_fullversion '$1' "$@"
  1628. }
  1629. gcc-micro-version ()
  1630. {
  1631.     _gcc_fullversion '$3' "$@"
  1632. }
  1633. gcc-minor-version ()
  1634. {
  1635.     _gcc_fullversion '$2' "$@"
  1636. }
  1637. gcc-specs-directive ()
  1638. {
  1639.     local directive subdname subdirective;
  1640.     directive="$(_gcc-specs-directive_raw $1)";
  1641.     while [[ ${directive} == *%\(*\)* ]]; do
  1642.         subdname=${directive/*%\(};
  1643.         subdname=${subdname/\)*};
  1644.         subdirective="$(_gcc-specs-directive_raw ${subdname})";
  1645.         directive="${directive//\%(${subdname})/${subdirective}}";
  1646.     done;
  1647.     echo "${directive}";
  1648.     return 0
  1649. }
  1650. gcc-specs-nostrict ()
  1651. {
  1652.     local directive;
  1653.     directive=$(gcc-specs-directive cc1);
  1654.     return $([[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]])
  1655. }
  1656. gcc-specs-now ()
  1657. {
  1658.     local directive;
  1659.     directive=$(gcc-specs-directive link_command);
  1660.     return $([[ "${directive/\{!nonow:}" != "${directive}" ]])
  1661. }
  1662. gcc-specs-pie ()
  1663. {
  1664.     local directive;
  1665.     directive=$(gcc-specs-directive cc1);
  1666.     return $([[ "${directive/\{!nopie:}" != "${directive}" ]])
  1667. }
  1668. gcc-specs-relro ()
  1669. {
  1670.     local directive;
  1671.     directive=$(gcc-specs-directive link_command);
  1672.     return $([[ "${directive/\{!norelro:}" != "${directive}" ]])
  1673. }
  1674. gcc-specs-ssp ()
  1675. {
  1676.     local directive;
  1677.     directive=$(gcc-specs-directive cc1);
  1678.     return $([[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]])
  1679. }
  1680. gcc-specs-ssp-to-all ()
  1681. {
  1682.     local directive;
  1683.     directive=$(gcc-specs-directive cc1);
  1684.     return $([[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]])
  1685. }
  1686. gcc-version ()
  1687. {
  1688.     _gcc_fullversion '$1.$2' "$@"
  1689. }
  1690. gen_usr_ldscript ()
  1691. {
  1692.     local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname);
  1693.     [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/;
  1694.     tc-is-static-only && return;
  1695.     dodir /usr/${libdir};
  1696.     if [[ $1 == "-a" ]]; then
  1697.         auto=true;
  1698.         shift;
  1699.         dodir /${libdir};
  1700.     fi;
  1701.     output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p');
  1702.     [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )";
  1703.     for lib in "$@";
  1704.     do
  1705.         local tlib;
  1706.         if ${auto}; then
  1707.             lib="lib${lib}${suffix}";
  1708.         else
  1709.             [[ -r ${ED}/${libdir}/${lib} ]] || continue;
  1710.         fi;
  1711.         case ${CTARGET:-${CHOST}} in
  1712.             *-darwin*)
  1713.                 if ${auto}; then
  1714.                     tlib=$(scanmacho -qF'%S#F' "${ED}"/usr/${libdir}/${lib});
  1715.                 else
  1716.                     tlib=$(scanmacho -qF'%S#F' "${ED}"/${libdir}/${lib});
  1717.                 fi;
  1718.                 [[ -z ${tlib} ]] && die "unable to read install_name from ${lib}";
  1719.                 tlib=${tlib##*/};
  1720.                 if ${auto}; then
  1721.                     mv "${ED}"/usr/${libdir}/${lib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die;
  1722.                     if [[ ${tlib} != ${lib%${suffix}}.*${suffix#.} ]]; then
  1723.                         mv "${ED}"/usr/${libdir}/${tlib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die;
  1724.                     fi;
  1725.                     rm -f "${ED}"/${libdir}/${lib};
  1726.                 fi;
  1727.                 if [[ ! -w "${ED}/${libdir}/${tlib}" ]]; then
  1728.                     chmod u+w "${ED}${libdir}/${tlib}";
  1729.                     local nowrite=yes;
  1730.                 fi;
  1731.                 install_name_tool -id "${EPREFIX}"/${libdir}/${tlib} "${ED}"/${libdir}/${tlib} || die "install_name_tool failed";
  1732.                 [[ -n ${nowrite} ]] && chmod u-w "${ED}${libdir}/${tlib}";
  1733.                 pushd "${ED}/usr/${libdir}" > /dev/null;
  1734.                 ln -snf "../../${libdir}/${tlib}" "${lib}";
  1735.                 popd > /dev/null
  1736.             ;;
  1737.             *-aix* | *-irix* | *64*-hpux* | *-interix* | *-winnt*)
  1738.                 if ${auto}; then
  1739.                     mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die;
  1740.                     tlib=$(readlink "${ED}"/${libdir}/${lib});
  1741.                     tlib=${tlib##*/};
  1742.                     if [[ -z ${tlib} ]]; then
  1743.                         tlib=${lib};
  1744.                     else
  1745.                         rm -f "${ED}"/${libdir}/${lib};
  1746.                     fi;
  1747.                 else
  1748.                     tlib=${lib};
  1749.                 fi;
  1750.                 pushd "${ED}/usr/${libdir}" > /dev/null;
  1751.                 ln -snf "../../${libdir}/${tlib}" "${lib}";
  1752.                 popd > /dev/null
  1753.             ;;
  1754.             hppa*-hpux*)
  1755.                 if ${auto}; then
  1756.                     tlib=$(chatr "${ED}"/usr/${libdir}/${lib} | sed -n '/internal name:/{n;s/^ *//;p;q}');
  1757.                     [[ -z ${tlib} ]] && tlib=${lib};
  1758.                     tlib=${tlib##*/};
  1759.                     mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die;
  1760.                     if [[ ${tlib} != ${lib}* ]]; then
  1761.                         mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die;
  1762.                     fi;
  1763.                     [[ ${tlib} != ${lib} ]] && rm -f "${ED}"/${libdir}/${lib};
  1764.                 else
  1765.                     tlib=$(chatr "${ED}"/${libdir}/${lib} | sed -n '/internal name:/{n;s/^ *//;p;q}');
  1766.                     [[ -z ${tlib} ]] && tlib=${lib};
  1767.                     tlib=${tlib##*/};
  1768.                 fi;
  1769.                 pushd "${ED}"/usr/${libdir} > /dev/null;
  1770.                 ln -snf "../../${libdir}/${tlib}" "${lib}";
  1771.                 [[ ${tlib} != ${lib} ]] && ln -snf "../../${libdir}/${tlib}" "${tlib}";
  1772.                 popd > /dev/null
  1773.             ;;
  1774.             *)
  1775.                 if ${auto}; then
  1776.                     tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib});
  1777.                     [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}";
  1778.                     mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die;
  1779.                     if [[ ${tlib} != ${lib}* ]]; then
  1780.                         mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die;
  1781.                     fi;
  1782.                     rm -f "${ED}"/${libdir}/${lib};
  1783.                 else
  1784.                     tlib=${lib};
  1785.                 fi;
  1786.                 cat > "${ED}/usr/${libdir}/${lib}"  <<-END_LDSCRIPT
  1787. /* GNU ld script
  1788.    Since Gentoo has critical dynamic libraries in /lib, and the static versions
  1789.    in /usr/lib, we need to have a "fake" dynamic lib in /usr/lib, otherwise we
  1790.    run into linking problems.  This "fake" dynamic lib is a linker script that
  1791.    redirects the linker to the real lib.  And yes, this works in the cross-
  1792.    compiling scenario as the sysroot-ed linker will prepend the real path.
  1793.  
  1794.    See bug http://bugs.gentoo.org/4411 for more info.
  1795.  */
  1796. ${output_format}
  1797. GROUP ( ${EPREFIX}/${libdir}/${tlib} )
  1798. END_LDSCRIPT
  1799.  
  1800.             ;;
  1801.         esac
  1802.         fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}";
  1803.     done
  1804. }
  1805. get_abi_CFLAGS ()
  1806. {
  1807.     get_abi_var CFLAGS "$@"
  1808. }
  1809. get_abi_CHOST ()
  1810. {
  1811.     get_abi_var CHOST "$@"
  1812. }
  1813. get_abi_CTARGET ()
  1814. {
  1815.     get_abi_var CTARGET "$@"
  1816. }
  1817. get_abi_FAKE_TARGETS ()
  1818. {
  1819.     get_abi_var FAKE_TARGETS "$@"
  1820. }
  1821. get_abi_LDFLAGS ()
  1822. {
  1823.     get_abi_var LDFLAGS "$@"
  1824. }
  1825. get_abi_LIBDIR ()
  1826. {
  1827.     get_abi_var LIBDIR "$@"
  1828. }
  1829. get_abi_var ()
  1830. {
  1831.     local flag=$1;
  1832.     local abi=${2:-${ABI:-${DEFAULT_ABI:-default}}};
  1833.     local var="${flag}_${abi}";
  1834.     echo ${!var}
  1835. }
  1836. get_all_abis ()
  1837. {
  1838.     local order="";
  1839.     if [[ -z ${MULTILIB_ABIS} ]]; then
  1840.         echo "default";
  1841.         return 0;
  1842.     fi;
  1843.     for x in ${MULTILIB_ABIS};
  1844.     do
  1845.         if [[ ${x} != ${DEFAULT_ABI} ]]; then
  1846.             order="${order:+${order} }${x}";
  1847.         fi;
  1848.     done;
  1849.     order="${order:+${order} }${DEFAULT_ABI}";
  1850.     echo ${order};
  1851.     return 0
  1852. }
  1853. get_all_libdirs ()
  1854. {
  1855.     local libdirs;
  1856.     local abi;
  1857.     local dir;
  1858.     for abi in ${MULTILIB_ABIS};
  1859.     do
  1860.         libdirs+=" $(get_abi_LIBDIR ${abi})";
  1861.     done;
  1862.     [[ " ${libdirs} " != *" lib "* ]] && libdirs+=" lib";
  1863.     echo "${libdirs}"
  1864. }
  1865. get_install_abis ()
  1866. {
  1867.     local order="";
  1868.     if [[ -z ${MULTILIB_ABIS} ]]; then
  1869.         echo "default";
  1870.         return 0;
  1871.     fi;
  1872.     if [[ ${EMULTILIB_PKG} == "true" ]]; then
  1873.         for x in ${MULTILIB_ABIS};
  1874.         do
  1875.             if [[ ${x} != "${DEFAULT_ABI}" ]]; then
  1876.                 has ${x} ${ABI_DENY} || order="${order} ${x}";
  1877.             fi;
  1878.         done;
  1879.         has ${DEFAULT_ABI} ${ABI_DENY} || order="${order} ${DEFAULT_ABI}";
  1880.         if [[ -n ${ABI_ALLOW} ]]; then
  1881.             local ordera="";
  1882.             for x in ${order};
  1883.             do
  1884.                 if has ${x} ${ABI_ALLOW}; then
  1885.                     ordera="${ordera} ${x}";
  1886.                 fi;
  1887.             done;
  1888.             order=${ordera};
  1889.         fi;
  1890.     else
  1891.         order=${DEFAULT_ABI};
  1892.     fi;
  1893.     if [[ -z ${order} ]]; then
  1894.         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.";
  1895.     fi;
  1896.     echo ${order};
  1897.     return 0
  1898. }
  1899. get_libdir ()
  1900. {
  1901.     local CONF_LIBDIR;
  1902.     if [ -n "${CONF_LIBDIR_OVERRIDE}" ]; then
  1903.         echo ${CONF_LIBDIR_OVERRIDE};
  1904.     else
  1905.         get_abi_LIBDIR;
  1906.     fi
  1907. }
  1908. get_libname ()
  1909. {
  1910.     local libname;
  1911.     local ver=$1;
  1912.     case ${CHOST} in
  1913.         *-cygwin | mingw* | *-mingw*)
  1914.             libname="dll"
  1915.         ;;
  1916.         *-darwin*)
  1917.             libname="dylib"
  1918.         ;;
  1919.         *-mint*)
  1920.             libname="irrelevant"
  1921.         ;;
  1922.         hppa*-hpux*)
  1923.             libname="sl"
  1924.         ;;
  1925.         *)
  1926.             libname="so"
  1927.         ;;
  1928.     esac;
  1929.     if [[ -z $* ]]; then
  1930.         echo ".${libname}";
  1931.     else
  1932.         for ver in "$@";
  1933.         do
  1934.             case ${CHOST} in
  1935.                 *-darwin*)
  1936.                     echo ".${ver}.${libname}"
  1937.                 ;;
  1938.                 *-mint*)
  1939.                     echo ".${libname}"
  1940.                 ;;
  1941.                 *)
  1942.                     echo ".${libname}.${ver}"
  1943.                 ;;
  1944.             esac;
  1945.         done;
  1946.     fi
  1947. }
  1948. get_modname ()
  1949. {
  1950.     local modname;
  1951.     local ver=$1;
  1952.     case ${CHOST} in
  1953.         *-darwin*)
  1954.             modname="bundle"
  1955.         ;;
  1956.         *)
  1957.             modname="so"
  1958.         ;;
  1959.     esac;
  1960.     echo ".${modname}"
  1961. }
  1962. has_multilib_profile ()
  1963. {
  1964.     [ -n "${MULTILIB_ABIS}" -a "${MULTILIB_ABIS}" != "${MULTILIB_ABIS/ /}" ]
  1965. }
  1966. in_iuse ()
  1967. {
  1968.     debug-print-function ${FUNCNAME} "${@}";
  1969.     [[ ${#} -eq 1 ]] || die "Invalid args to ${FUNCNAME}()";
  1970.     local flag=${1};
  1971.     local liuse=(${IUSE});
  1972.     has "${flag}" "${liuse[@]#[+-]}"
  1973. }
  1974. is_final_abi ()
  1975. {
  1976.     has_multilib_profile || return 0;
  1977.     set -- $(get_install_abis);
  1978.     local LAST_ABI=$#;
  1979.     [[ ${!LAST_ABI} == ${ABI} ]]
  1980. }
  1981. make_desktop_entry ()
  1982. {
  1983.     [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable";
  1984.     local exec=${1};
  1985.     local name=${2:-${PN}};
  1986.     local icon=${3:-${PN}};
  1987.     local type=${4};
  1988.     local fields=${5};
  1989.     if [[ -z ${type} ]]; then
  1990.         local catmaj=${CATEGORY%%-*};
  1991.         local catmin=${CATEGORY##*-};
  1992.         case ${catmaj} in
  1993.             app)
  1994.                 case ${catmin} in
  1995.                     accessibility)
  1996.                         type="Utility;Accessibility"
  1997.                     ;;
  1998.                     admin)
  1999.                         type=System
  2000.                     ;;
  2001.                     antivirus)
  2002.                         type=System
  2003.                     ;;
  2004.                     arch)
  2005.                         type="Utility;Archiving"
  2006.                     ;;
  2007.                     backup)
  2008.                         type="Utility;Archiving"
  2009.                     ;;
  2010.                     cdr)
  2011.                         type="AudioVideo;DiscBurning"
  2012.                     ;;
  2013.                     dicts)
  2014.                         type="Office;Dictionary"
  2015.                     ;;
  2016.                     doc)
  2017.                         type=Documentation
  2018.                     ;;
  2019.                     editors)
  2020.                         type="Utility;TextEditor"
  2021.                     ;;
  2022.                     emacs)
  2023.                         type="Development;TextEditor"
  2024.                     ;;
  2025.                     emulation)
  2026.                         type="System;Emulator"
  2027.                     ;;
  2028.                     laptop)
  2029.                         type="Settings;HardwareSettings"
  2030.                     ;;
  2031.                     office)
  2032.                         type=Office
  2033.                     ;;
  2034.                     pda)
  2035.                         type="Office;PDA"
  2036.                     ;;
  2037.                     vim)
  2038.                         type="Development;TextEditor"
  2039.                     ;;
  2040.                     xemacs)
  2041.                         type="Development;TextEditor"
  2042.                     ;;
  2043.                 esac
  2044.             ;;
  2045.             dev)
  2046.                 type="Development"
  2047.             ;;
  2048.             games)
  2049.                 case ${catmin} in
  2050.                     action | fps)
  2051.                         type=ActionGame
  2052.                     ;;
  2053.                     arcade)
  2054.                         type=ArcadeGame
  2055.                     ;;
  2056.                     board)
  2057.                         type=BoardGame
  2058.                     ;;
  2059.                     emulation)
  2060.                         type=Emulator
  2061.                     ;;
  2062.                     kids)
  2063.                         type=KidsGame
  2064.                     ;;
  2065.                     puzzle)
  2066.                         type=LogicGame
  2067.                     ;;
  2068.                     roguelike)
  2069.                         type=RolePlaying
  2070.                     ;;
  2071.                     rpg)
  2072.                         type=RolePlaying
  2073.                     ;;
  2074.                     simulation)
  2075.                         type=Simulation
  2076.                     ;;
  2077.                     sports)
  2078.                         type=SportsGame
  2079.                     ;;
  2080.                     strategy)
  2081.                         type=StrategyGame
  2082.                     ;;
  2083.                 esac;
  2084.                 type="Game;${type}"
  2085.             ;;
  2086.             gnome)
  2087.                 type="Gnome;GTK"
  2088.             ;;
  2089.             kde)
  2090.                 type="KDE;Qt"
  2091.             ;;
  2092.             mail)
  2093.                 type="Network;Email"
  2094.             ;;
  2095.             media)
  2096.                 case ${catmin} in
  2097.                     gfx)
  2098.                         type=Graphics
  2099.                     ;;
  2100.                     *)
  2101.                         case ${catmin} in
  2102.                             radio)
  2103.                                 type=Tuner
  2104.                             ;;
  2105.                             sound)
  2106.                                 type=Audio
  2107.                             ;;
  2108.                             tv)
  2109.                                 type=TV
  2110.                             ;;
  2111.                             video)
  2112.                                 type=Video
  2113.                             ;;
  2114.                         esac;
  2115.                         type="AudioVideo;${type}"
  2116.                     ;;
  2117.                 esac
  2118.             ;;
  2119.             net)
  2120.                 case ${catmin} in
  2121.                     dialup)
  2122.                         type=Dialup
  2123.                     ;;
  2124.                     ftp)
  2125.                         type=FileTransfer
  2126.                     ;;
  2127.                     im)
  2128.                         type=InstantMessaging
  2129.                     ;;
  2130.                     irc)
  2131.                         type=IRCClient
  2132.                     ;;
  2133.                     mail)
  2134.                         type=Email
  2135.                     ;;
  2136.                     news)
  2137.                         type=News
  2138.                     ;;
  2139.                     nntp)
  2140.                         type=News
  2141.                     ;;
  2142.                     p2p)
  2143.                         type=FileTransfer
  2144.                     ;;
  2145.                     voip)
  2146.                         type=Telephony
  2147.                     ;;
  2148.                 esac;
  2149.                 type="Network;${type}"
  2150.             ;;
  2151.             sci)
  2152.                 case ${catmin} in
  2153.                     astro*)
  2154.                         type=Astronomy
  2155.                     ;;
  2156.                     bio*)
  2157.                         type=Biology
  2158.                     ;;
  2159.                     calc*)
  2160.                         type=Calculator
  2161.                     ;;
  2162.                     chem*)
  2163.                         type=Chemistry
  2164.                     ;;
  2165.                     elec*)
  2166.                         type=Electronics
  2167.                     ;;
  2168.                     geo*)
  2169.                         type=Geology
  2170.                     ;;
  2171.                     math*)
  2172.                         type=Math
  2173.                     ;;
  2174.                     physics)
  2175.                         type=Physics
  2176.                     ;;
  2177.                     visual*)
  2178.                         type=DataVisualization
  2179.                     ;;
  2180.                 esac;
  2181.                 type="Education;Science;${type}"
  2182.             ;;
  2183.             sys)
  2184.                 type="System"
  2185.             ;;
  2186.             www)
  2187.                 case ${catmin} in
  2188.                     client)
  2189.                         type=WebBrowser
  2190.                     ;;
  2191.                 esac;
  2192.                 type="Network;${type}"
  2193.             ;;
  2194.             *)
  2195.                 type=
  2196.             ;;
  2197.         esac;
  2198.     fi;
  2199.     if [ "${SLOT}" == "0" ]; then
  2200.         local desktop_name="${PN}";
  2201.     else
  2202.         local desktop_name="${PN}-${SLOT}";
  2203.     fi;
  2204.     local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop";
  2205.     type=${type%;}${type:+;};
  2206.     eshopts_push -s extglob;
  2207.     if [[ -n ${icon} && ${icon} != /* ]] && [[ ${icon} == *.xpm || ${icon} == *.png || ${icon} == *.svg ]]; then
  2208.         ewarn "As described in the Icon Theme Specification, icon file extensions are not";
  2209.         ewarn "allowed in .desktop files if the value is not an absolute path.";
  2210.         icon=${icon%.@(xpm|png|svg)};
  2211.     fi;
  2212.     eshopts_pop;
  2213.     cat > "${desktop}"  <<-EOF
  2214. [Desktop Entry]
  2215. Name=${name}
  2216. Type=Application
  2217. Comment=${DESCRIPTION}
  2218. Exec=${exec}
  2219. TryExec=${exec%% *}
  2220. Icon=${icon}
  2221. Categories=${type}
  2222. EOF
  2223.  
  2224.     if [[ ${fields:-=} != *=* ]]; then
  2225.         ewarn "make_desktop_entry: update your 5th arg to read Path=${fields}";
  2226.         fields="Path=${fields}";
  2227.     fi;
  2228.     [[ -n ${fields} ]] && printf '%b\n' "${fields}" >> "${desktop}";
  2229.     ( insinto /usr/share/applications;
  2230.     doins "${desktop}" ) || die "installing desktop file failed"
  2231. }
  2232. make_session_desktop ()
  2233. {
  2234.     [[ -z $1 ]] && eerror "$0: You must specify the title" && return 1;
  2235.     [[ -z $2 ]] && eerror "$0: You must specify the command" && return 1;
  2236.     local title=$1;
  2237.     local command=$2;
  2238.     local desktop=${T}/${wm:-${PN}}.desktop;
  2239.     shift 2;
  2240.     cat > "${desktop}"  <<-EOF
  2241. [Desktop Entry]
  2242. Name=${title}
  2243. Comment=This session logs you into ${title}
  2244. Exec=${command} $*
  2245. TryExec=${command}
  2246. Type=XSession
  2247. EOF
  2248.  
  2249.     ( insinto /usr/share/xsessions;
  2250.     doins "${desktop}" )
  2251. }
  2252. make_wrapper ()
  2253. {
  2254.     local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5;
  2255.     local tmpwrapper=$(emktemp);
  2256.     cat > "${tmpwrapper}"  <<EOF
  2257. #!/bin/sh
  2258. cd "${chdir:-.}"
  2259. if [ -n "${libdir}" ] ; then
  2260.         if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
  2261.                 export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
  2262.         else
  2263.                 export LD_LIBRARY_PATH="${libdir}"
  2264.         fi
  2265. fi
  2266. exec ${bin} "\$@"
  2267. EOF
  2268.  
  2269.     chmod go+rx "${tmpwrapper}";
  2270.     if [[ -n ${path} ]]; then
  2271.         ( exeinto "${path}";
  2272.         newexe "${tmpwrapper}" "${wrapper}" ) || die;
  2273.     else
  2274.         newbin "${tmpwrapper}" "${wrapper}" || die;
  2275.     fi
  2276. }
  2277. makeopts_jobs ()
  2278. {
  2279.     [[ $# -eq 0 ]] && set -- ${MAKEOPTS};
  2280.     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');
  2281.     echo ${jobs:-1}
  2282. }
  2283. multilib_env ()
  2284. {
  2285.     local CTARGET=${1:-${CTARGET}};
  2286.     case ${CTARGET} in
  2287.         x86_64*)
  2288.             export CFLAGS_x86=${CFLAGS_x86--m32};
  2289.             export CHOST_x86=${CTARGET/x86_64/i686};
  2290.             export CTARGET_x86=${CHOST_x86};
  2291.             if [[ ${SYMLINK_LIB} == "yes" ]]; then
  2292.                 export LIBDIR_x86="lib32";
  2293.             else
  2294.                 export LIBDIR_x86="lib";
  2295.             fi;
  2296.             export CFLAGS_amd64=${CFLAGS_amd64--m64};
  2297.             export CHOST_amd64=${CTARGET};
  2298.             export CTARGET_amd64=${CHOST_amd64};
  2299.             export LIBDIR_amd64="lib64";
  2300.             export CFLAGS_x32=${CFLAGS_x32--mx32};
  2301.             export CHOST_x32=${CTARGET};
  2302.             export CTARGET_x32=${CHOST_x32};
  2303.             export LIBDIR_x32="libx32";
  2304.             : ${MULTILIB_ABIS=amd64 x86};
  2305.             : ${DEFAULT_ABI=amd64}
  2306.         ;;
  2307.         mips64*)
  2308.             export CFLAGS_o32=${CFLAGS_o32--mabi=32};
  2309.             export CHOST_o32=${CTARGET/mips64/mips};
  2310.             export CTARGET_o32=${CHOST_o32};
  2311.             export LIBDIR_o32="lib";
  2312.             export CFLAGS_n32=${CFLAGS_n32--mabi=n32};
  2313.             export CHOST_n32=${CTARGET};
  2314.             export CTARGET_n32=${CHOST_n32};
  2315.             export LIBDIR_n32="lib32";
  2316.             export CFLAGS_n64=${CFLAGS_n64--mabi=64};
  2317.             export CHOST_n64=${CTARGET};
  2318.             export CTARGET_n64=${CHOST_n64};
  2319.             export LIBDIR_n64="lib64";
  2320.             : ${MULTILIB_ABIS=n64 n32 o32};
  2321.             : ${DEFAULT_ABI=n32}
  2322.         ;;
  2323.         powerpc64*)
  2324.             export CFLAGS_ppc=${CFLAGS_ppc--m32};
  2325.             export CHOST_ppc=${CTARGET/powerpc64/powerpc};
  2326.             export CTARGET_ppc=${CHOST_ppc};
  2327.             export LIBDIR_ppc="lib";
  2328.             export CFLAGS_ppc64=${CFLAGS_ppc64--m64};
  2329.             export CHOST_ppc64=${CTARGET};
  2330.             export CTARGET_ppc64=${CHOST_ppc64};
  2331.             export LIBDIR_ppc64="lib64";
  2332.             : ${MULTILIB_ABIS=ppc64 ppc};
  2333.             : ${DEFAULT_ABI=ppc64}
  2334.         ;;
  2335.         s390x*)
  2336.             export CFLAGS_s390=${CFLAGS_s390--m31};
  2337.             export CHOST_s390=${CTARGET/s390x/s390};
  2338.             export CTARGET_s390=${CHOST_s390};
  2339.             export LIBDIR_s390="lib";
  2340.             export CFLAGS_s390x=${CFLAGS_s390x--m64};
  2341.             export CHOST_s390x=${CTARGET};
  2342.             export CTARGET_s390x=${CHOST_s390x};
  2343.             export LIBDIR_s390x="lib64";
  2344.             : ${MULTILIB_ABIS=s390x s390};
  2345.             : ${DEFAULT_ABI=s390x}
  2346.         ;;
  2347.         sparc*)
  2348.             export CFLAGS_sparc32=${CFLAGS_sparc32--m32};
  2349.             export CHOST_sparc32=${CTARGET/sparc64/sparc};
  2350.             export CTARGET_sparc32=${CHOST_sparc32};
  2351.             export LIBDIR_sparc32="lib";
  2352.             export CFLAGS_sparc64=${CFLAGS_sparc64--m64};
  2353.             export CHOST_sparc64=${CTARGET};
  2354.             export CTARGET_sparc64=${CHOST_sparc64};
  2355.             export LIBDIR_sparc64="lib64";
  2356.             : ${MULTILIB_ABIS=sparc64 sparc32};
  2357.             : ${DEFAULT_ABI=sparc64}
  2358.         ;;
  2359.         *)
  2360.             : ${MULTILIB_ABIS=default};
  2361.             : ${DEFAULT_ABI=default}
  2362.         ;;
  2363.     esac;
  2364.     export MULTILIB_ABIS DEFAULT_ABI
  2365. }
  2366. multilib_toolchain_setup ()
  2367. {
  2368.     local v vv;
  2369.     export ABI=$1;
  2370.     if [[ ${__DEFAULT_ABI_SAVED} == "true" ]]; then
  2371.         for v in CHOST CBUILD AS CC CXX LD;
  2372.         do
  2373.             vv="__abi_saved_${v}";
  2374.             export ${v}="${!vv}";
  2375.             unset ${vv};
  2376.         done;
  2377.         unset __DEFAULT_ABI_SAVED;
  2378.     fi;
  2379.     if [[ ${ABI} != ${DEFAULT_ABI} ]]; then
  2380.         for v in CHOST CBUILD AS CC CXX LD;
  2381.         do
  2382.             export __abi_saved_${v}="${!v}";
  2383.         done;
  2384.         export __DEFAULT_ABI_SAVED="true";
  2385.         export CHOST=$(get_abi_CHOST ${DEFAULT_ABI});
  2386.         export CC="$(tc-getCC) $(get_abi_CFLAGS)";
  2387.         export CXX="$(tc-getCXX) $(get_abi_CFLAGS)";
  2388.         export LD="$(tc-getLD) $(get_abi_LDFLAGS)";
  2389.         export CHOST=$(get_abi_CHOST $1);
  2390.         export CBUILD=$(get_abi_CHOST $1);
  2391.     fi
  2392. }
  2393. newicon ()
  2394. {
  2395.     ( insinto /usr/share/pixmaps;
  2396.     newins "$@" )
  2397. }
  2398. newmenu ()
  2399. {
  2400.     ( insinto /usr/share/applications;
  2401.     newins "$@" )
  2402. }
  2403. number_abis ()
  2404. {
  2405.     set -- `get_install_abis`;
  2406.     echo $#
  2407. }
  2408. path_exists ()
  2409. {
  2410.     local opt=$1;
  2411.     [[ ${opt} == -[ao] ]] && shift || opt="-a";
  2412.     [[ $# -eq 0 ]] && return 1;
  2413.     local p r=0;
  2414.     for p in "$@";
  2415.     do
  2416.         [[ -e ${p} ]];
  2417.         : $(( r += $? ));
  2418.     done;
  2419.     case ${opt} in
  2420.         -a)
  2421.             return $(( r != 0 ))
  2422.         ;;
  2423.         -o)
  2424.             return $(( r == $# ))
  2425.         ;;
  2426.     esac
  2427. }
  2428. pkg_nofetch ()
  2429. {
  2430.     _eapi0_pkg_nofetch "$@"
  2431. }
  2432. pkg_postinst ()
  2433. {
  2434.     elog "blender uses python integration.  As such, may have some";
  2435.     elog "inherit risks with running unknown python scripting.";
  2436.     elog " ";
  2437.     elog "CVE-2008-1103-1.patch has been removed as it interferes";
  2438.     elog "with autosave undo features. Up stream blender coders";
  2439.     elog "have not addressed the CVE issue as the status is still";
  2440.     elog "a CANDIDATE and not CONFIRMED.";
  2441.     elog " ";
  2442.     elog "It is recommended to change your blender temp directory";
  2443.     elog "from /tmp to ~tmp or another tmp file under your home";
  2444.     elog "directory. This can be done by starting blender, then";
  2445.     elog "dragging the main menu down do display all paths."
  2446. }
  2447. pkg_preinst ()
  2448. {
  2449.     if [ -h "${ROOT}/usr/$(get_libdir)/blender/plugins/include" ]; then
  2450.         rm -f "${ROOT}"/usr/$(get_libdir)/blender/plugins/include;
  2451.     fi
  2452. }
  2453. preserve_old_lib ()
  2454. {
  2455.     if [[ ${EBUILD_PHASE} != "preinst" ]]; then
  2456.         eerror "preserve_old_lib() must be called from pkg_preinst() only";
  2457.         die "Invalid preserve_old_lib() usage";
  2458.     fi;
  2459.     [[ -z $1 ]] && die "Usage: preserve_old_lib <library to preserve> [more libraries to preserve]";
  2460.     has preserve-libs ${FEATURES} && return 0;
  2461.     local lib dir;
  2462.     for lib in "$@";
  2463.     do
  2464.         [[ -e ${ROOT}/${lib} ]] || continue;
  2465.         dir=${lib%/*};
  2466.         dodir ${dir} || die "dodir ${dir} failed";
  2467.         cp "${ROOT}"/${lib} "${D}"/${lib} || die "cp ${lib} failed";
  2468.         touch "${D}"/${lib};
  2469.     done
  2470. }
  2471. preserve_old_lib_notify ()
  2472. {
  2473.     if [[ ${EBUILD_PHASE} != "postinst" ]]; then
  2474.         eerror "preserve_old_lib_notify() must be called from pkg_postinst() only";
  2475.         die "Invalid preserve_old_lib_notify() usage";
  2476.     fi;
  2477.     has preserve-libs ${FEATURES} && return 0;
  2478.     local lib notice=0;
  2479.     for lib in "$@";
  2480.     do
  2481.         [[ -e ${ROOT}/${lib} ]] || continue;
  2482.         if [[ ${notice} -eq 0 ]]; then
  2483.             notice=1;
  2484.             ewarn "Old versions of installed libraries were detected on your system.";
  2485.             ewarn "In order to avoid breaking packages that depend on these old libs,";
  2486.             ewarn "the libraries are not being removed.  You need to run revdep-rebuild";
  2487.             ewarn "in order to remove these old dependencies.  If you do not have this";
  2488.             ewarn "helper program, simply emerge the 'gentoolkit' package.";
  2489.             ewarn;
  2490.         fi;
  2491.         [[ ${PN} == "mpfr" ]] && lib=${lib##*/};
  2492.         ewarn "  # revdep-rebuild --library '${lib}' && rm '${lib}'";
  2493.     done
  2494. }
  2495. python_clean_installation_image ()
  2496. {
  2497.     if [[ "${EBUILD_PHASE}" != "install" ]]; then
  2498.         die "${FUNCNAME}() can be used only in src_install() phase";
  2499.     fi;
  2500.     _python_check_python_pkg_setup_execution;
  2501.     _python_initialize_prefix_variables;
  2502.     local file files=() quiet="0";
  2503.     while (($#)); do
  2504.         case "$1" in
  2505.             -q | --quiet)
  2506.                 quiet="1"
  2507.             ;;
  2508.             -*)
  2509.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  2510.             ;;
  2511.             *)
  2512.                 die "${FUNCNAME}(): Invalid usage"
  2513.             ;;
  2514.         esac;
  2515.         shift;
  2516.     done;
  2517.     while read -d '' -r file; do
  2518.         files+=("${file}");
  2519.     done < <(find "${ED}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -type f -print0);
  2520.     if [[ "${#files[@]}" -gt 0 ]]; then
  2521.         if [[ "${quiet}" == "0" ]]; then
  2522.             ewarn "Deleting byte-compiled Python modules needlessly generated by build system:";
  2523.         fi;
  2524.         for file in "${files[@]}";
  2525.         do
  2526.             if [[ "${quiet}" == "0" ]]; then
  2527.                 ewarn " ${file}";
  2528.             fi;
  2529.             rm -f "${file}";
  2530.             if [[ "${file%/*}" == *"/__pycache__" ]]; then
  2531.                 rmdir "${file%/*}" 2> /dev/null;
  2532.             fi;
  2533.         done;
  2534.     fi;
  2535.     function python_clean_sitedirs ()
  2536.     {
  2537.         if [[ -d "${ED}$(python_get_sitedir)" ]]; then
  2538.             find "${ED}$(python_get_sitedir)" "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f;
  2539.         fi
  2540.     };
  2541.     if _python_package_supporting_installation_for_multiple_python_abis; then
  2542.         python_execute_function -q python_clean_sitedirs;
  2543.     else
  2544.         python_clean_sitedirs;
  2545.     fi;
  2546.     unset -f python_clean_sitedirs
  2547. }
  2548. python_clean_py-compile_files ()
  2549. {
  2550.     _python_check_python_pkg_setup_execution;
  2551.     local file files=() quiet="0";
  2552.     while (($#)); do
  2553.         case "$1" in
  2554.             -q | --quiet)
  2555.                 quiet="1"
  2556.             ;;
  2557.             -*)
  2558.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  2559.             ;;
  2560.             *)
  2561.                 die "${FUNCNAME}(): Invalid usage"
  2562.             ;;
  2563.         esac;
  2564.         shift;
  2565.     done;
  2566.     while read -d '' -r file; do
  2567.         files+=("${file#./}");
  2568.     done < <(find -name py-compile -type f -print0);
  2569.     for file in "${files[@]}";
  2570.     do
  2571.         if [[ "${quiet}" == "0" ]]; then
  2572.             einfo "Cleaning '${file}' file";
  2573.         fi;
  2574.         echo "#!/bin/sh" > "${file}";
  2575.     done
  2576. }
  2577. python_convert_shebangs ()
  2578. {
  2579.     _python_check_python_pkg_setup_execution;
  2580.     local argument file files=() only_executables="0" python_interpreter quiet="0" recursive="0" shebangs_converted="0";
  2581.     while (($#)); do
  2582.         case "$1" in
  2583.             -r | --recursive)
  2584.                 recursive="1"
  2585.             ;;
  2586.             -q | --quiet)
  2587.                 quiet="1"
  2588.             ;;
  2589.             -x | --only-executables)
  2590.                 only_executables="1"
  2591.             ;;
  2592.             --)
  2593.                 shift;
  2594.                 break
  2595.             ;;
  2596.             -*)
  2597.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  2598.             ;;
  2599.             *)
  2600.                 break
  2601.             ;;
  2602.         esac;
  2603.         shift;
  2604.     done;
  2605.     if [[ "$#" -eq 0 ]]; then
  2606.         die "${FUNCNAME}(): Missing Python version and files or directories";
  2607.     else
  2608.         if [[ "$#" -eq 1 ]]; then
  2609.             die "${FUNCNAME}(): Missing files or directories";
  2610.         fi;
  2611.     fi;
  2612.     if [[ -n "$(_python_get_implementation --ignore-invalid "$1")" ]]; then
  2613.         python_interpreter="$(PYTHON "$1")";
  2614.     else
  2615.         python_interpreter="python$1";
  2616.     fi;
  2617.     shift;
  2618.     for argument in "$@";
  2619.     do
  2620.         if [[ ! -e "${argument}" ]]; then
  2621.             die "${FUNCNAME}(): '${argument}' does not exist";
  2622.         else
  2623.             if [[ -f "${argument}" ]]; then
  2624.                 files+=("${argument}");
  2625.             else
  2626.                 if [[ -d "${argument}" ]]; then
  2627.                     if [[ "${recursive}" == "1" ]]; then
  2628.                         while read -d '' -r file; do
  2629.                             files+=("${file}");
  2630.                         done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0);
  2631.                     else
  2632.                         die "${FUNCNAME}(): '${argument}' is not a regular file";
  2633.                     fi;
  2634.                 else
  2635.                     die "${FUNCNAME}(): '${argument}' is not a regular file or a directory";
  2636.                 fi;
  2637.             fi;
  2638.         fi;
  2639.     done;
  2640.     for file in "${files[@]}";
  2641.     do
  2642.         file="${file#./}";
  2643.         [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue;
  2644.         if [[ "$(head -n1 "${file}")" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX} ]]; then
  2645.             [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue;
  2646.             shebangs_converted="1";
  2647.             if [[ "${quiet}" == "0" ]]; then
  2648.                 einfo "Converting shebang in '${file}'";
  2649.             fi;
  2650.             sed -e "1s:^#![[:space:]]*\([^[:space:]]*/usr/bin/env[[:space:]]\)\?[[:space:]]*\([^[:space:]]*/\)\?\(jython\|pypy-c\|python\)\([[:digit:]]\+\(\.[[:digit:]]\+\)\?\)\?\(\$\|[[:space:]].*\):#!\1\2${python_interpreter}\6:" -i "${file}" || die "Conversion of shebang in '${file}' failed";
  2651.         fi;
  2652.     done;
  2653.     if [[ "${shebangs_converted}" == "0" ]]; then
  2654.         ewarn "${FUNCNAME}(): Python scripts not found";
  2655.     fi
  2656. }
  2657. python_copy_sources ()
  2658. {
  2659.     if ! _python_package_supporting_installation_for_multiple_python_abis; then
  2660.         die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  2661.     fi;
  2662.     _python_check_python_pkg_setup_execution;
  2663.     local dir dirs=() PYTHON_ABI;
  2664.     if [[ "$#" -eq 0 ]]; then
  2665.         if [[ "${WORKDIR}" == "${S}" ]]; then
  2666.             die "${FUNCNAME}() cannot be used with current value of S variable";
  2667.         fi;
  2668.         dirs=("${S%/}");
  2669.     else
  2670.         dirs=("$@");
  2671.     fi;
  2672.     _python_calculate_PYTHON_ABIS;
  2673.     for PYTHON_ABI in ${PYTHON_ABIS};
  2674.     do
  2675.         for dir in "${dirs[@]}";
  2676.         do
  2677.             cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed";
  2678.         done;
  2679.     done
  2680. }
  2681. python_disable_pyc ()
  2682. {
  2683.     _python_check_python_pkg_setup_execution;
  2684.     if [[ "$#" -ne 0 ]]; then
  2685.         die "${FUNCNAME}() does not accept arguments";
  2686.     fi;
  2687.     export PYTHONDONTWRITEBYTECODE="1"
  2688. }
  2689. python_enable_pyc ()
  2690. {
  2691.     _python_check_python_pkg_setup_execution;
  2692.     if [[ "$#" -ne 0 ]]; then
  2693.         die "${FUNCNAME}() does not accept arguments";
  2694.     fi;
  2695.     unset PYTHONDONTWRITEBYTECODE
  2696. }
  2697. python_execute_function ()
  2698. {
  2699.     if ! _python_package_supporting_installation_for_multiple_python_abis; then
  2700.         die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  2701.     fi;
  2702.     _python_check_python_pkg_setup_execution;
  2703.     _python_set_color_variables;
  2704.     local action action_message action_message_template default_function="0" failure_message failure_message_template final_ABI="0" function iterated_PYTHON_ABIS nonfatal="0" previous_directory previous_directory_stack previous_directory_stack_length PYTHON_ABI quiet="0" return_code separate_build_dirs="0" source_dir;
  2705.     while (($#)); do
  2706.         case "$1" in
  2707.             --action-message)
  2708.                 action_message_template="$2";
  2709.                 shift
  2710.             ;;
  2711.             -d | --default-function)
  2712.                 default_function="1"
  2713.             ;;
  2714.             --failure-message)
  2715.                 failure_message_template="$2";
  2716.                 shift
  2717.             ;;
  2718.             -f | --final-ABI)
  2719.                 final_ABI="1"
  2720.             ;;
  2721.             --nonfatal)
  2722.                 nonfatal="1"
  2723.             ;;
  2724.             -q | --quiet)
  2725.                 quiet="1"
  2726.             ;;
  2727.             -s | --separate-build-dirs)
  2728.                 separate_build_dirs="1"
  2729.             ;;
  2730.             --source-dir)
  2731.                 source_dir="$2";
  2732.                 shift
  2733.             ;;
  2734.             --)
  2735.                 shift;
  2736.                 break
  2737.             ;;
  2738.             -*)
  2739.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  2740.             ;;
  2741.             *)
  2742.                 break
  2743.             ;;
  2744.         esac;
  2745.         shift;
  2746.     done;
  2747.     if [[ -n "${source_dir}" && "${separate_build_dirs}" == 0 ]]; then
  2748.         die "${FUNCNAME}(): '--source-dir' option can be specified only with '--separate-build-dirs' option";
  2749.     fi;
  2750.     if [[ "${default_function}" == "0" ]]; then
  2751.         if [[ "$#" -eq 0 ]]; then
  2752.             die "${FUNCNAME}(): Missing function name";
  2753.         fi;
  2754.         function="$1";
  2755.         shift;
  2756.         if [[ -z "$(type -t "${function}")" ]]; then
  2757.             die "${FUNCNAME}(): '${function}' function is not defined";
  2758.         fi;
  2759.     else
  2760.         if has "${EAPI:-0}" 0 1; then
  2761.             die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI";
  2762.         fi;
  2763.         if [[ "${EBUILD_PHASE}" == "configure" ]]; then
  2764.             if has "${EAPI}" 2 3; then
  2765.                 function python_default_function ()
  2766.                 {
  2767.                     econf "$@"
  2768.                 };
  2769.             else
  2770.                 function python_default_function ()
  2771.                 {
  2772.                     nonfatal econf "$@"
  2773.                 };
  2774.             fi;
  2775.         else
  2776.             if [[ "${EBUILD_PHASE}" == "compile" ]]; then
  2777.                 function python_default_function ()
  2778.                 {
  2779.                     emake "$@"
  2780.                 };
  2781.             else
  2782.                 if [[ "${EBUILD_PHASE}" == "test" ]]; then
  2783.                     function python_default_function ()
  2784.                     {
  2785.                         local emake_cmd="${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE}";
  2786.                         if ${emake_cmd} -j1 -n check &>/dev/null; then
  2787.                             ${emake_cmd} -j1 check "$@";
  2788.                         else
  2789.                             if ${emake_cmd} -j1 -n test &>/dev/null; then
  2790.                                 ${emake_cmd} -j1 test "$@";
  2791.                             fi;
  2792.                         fi
  2793.                     };
  2794.                 else
  2795.                     if [[ "${EBUILD_PHASE}" == "install" ]]; then
  2796.                         function python_default_function ()
  2797.                         {
  2798.                             emake DESTDIR="${D}" install "$@"
  2799.                         };
  2800.                     else
  2801.                         die "${FUNCNAME}(): '--default-function' option cannot be used in this ebuild phase";
  2802.                     fi;
  2803.                 fi;
  2804.             fi;
  2805.         fi;
  2806.         function="python_default_function";
  2807.     fi;
  2808.     if _python_abi-specific_local_scope; then
  2809.         die "${FUNCNAME}(): Invalid call stack";
  2810.     fi;
  2811.     if [[ "${quiet}" == "0" ]]; then
  2812.         [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up";
  2813.         [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking";
  2814.         [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation";
  2815.         [[ "${EBUILD_PHASE}" == "configure" ]] && action="Configuration";
  2816.         [[ "${EBUILD_PHASE}" == "compile" ]] && action="Building";
  2817.         [[ "${EBUILD_PHASE}" == "test" ]] && action="Testing";
  2818.         [[ "${EBUILD_PHASE}" == "install" ]] && action="Installation";
  2819.         [[ "${EBUILD_PHASE}" == "preinst" ]] && action="Preinstallation";
  2820.         [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation";
  2821.         [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation";
  2822.         [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation";
  2823.     fi;
  2824.     _python_calculate_PYTHON_ABIS;
  2825.     if [[ "${final_ABI}" == "1" ]]; then
  2826.         iterated_PYTHON_ABIS="$(PYTHON -f --ABI)";
  2827.     else
  2828.         iterated_PYTHON_ABIS="${PYTHON_ABIS}";
  2829.     fi;
  2830.     for PYTHON_ABI in ${iterated_PYTHON_ABIS};
  2831.     do
  2832.         if [[ "${EBUILD_PHASE}" == "test" ]] && _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${PYTHON_TESTS_RESTRICTED_ABIS}"; then
  2833.             if [[ "${quiet}" == "0" ]]; then
  2834.                 echo " ${_GREEN}*${_NORMAL} ${_BLUE}Testing of ${CATEGORY}/${PF} with $(python_get_implementation_and_version) skipped${_NORMAL}";
  2835.             fi;
  2836.             continue;
  2837.         fi;
  2838.         _python_prepare_flags;
  2839.         if [[ "${quiet}" == "0" ]]; then
  2840.             if [[ -n "${action_message_template}" ]]; then
  2841.                 eval "action_message=\"${action_message_template}\"";
  2842.             else
  2843.                 action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation_and_version)...";
  2844.             fi;
  2845.             echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}";
  2846.         fi;
  2847.         if [[ "${separate_build_dirs}" == "1" ]]; then
  2848.             if [[ -n "${source_dir}" ]]; then
  2849.                 export BUILDDIR="${S}/${source_dir}-${PYTHON_ABI}";
  2850.             else
  2851.                 export BUILDDIR="${S}-${PYTHON_ABI}";
  2852.             fi;
  2853.             pushd "${BUILDDIR}" > /dev/null || die "pushd failed";
  2854.         else
  2855.             export BUILDDIR="${S}";
  2856.         fi;
  2857.         previous_directory="$(pwd)";
  2858.         previous_directory_stack="$(dirs -p)";
  2859.         previous_directory_stack_length="$(dirs -p | wc -l)";
  2860.         if ! has "${EAPI}" 0 1 2 3 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
  2861.             EPYTHON="$(PYTHON)" nonfatal "${function}" "$@";
  2862.         else
  2863.             EPYTHON="$(PYTHON)" "${function}" "$@";
  2864.         fi;
  2865.         return_code="$?";
  2866.         _python_restore_flags;
  2867.         if [[ "${return_code}" -ne 0 ]]; then
  2868.             if [[ -n "${failure_message_template}" ]]; then
  2869.                 eval "failure_message=\"${failure_message_template}\"";
  2870.             else
  2871.                 failure_message="${action} failed with $(python_get_implementation_and_version) in ${function}() function";
  2872.             fi;
  2873.             if [[ "${nonfatal}" == "1" ]]; then
  2874.                 if [[ "${quiet}" == "0" ]]; then
  2875.                     ewarn "${failure_message}";
  2876.                 fi;
  2877.             else
  2878.                 if [[ "${final_ABI}" == "0" ]] && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
  2879.                     if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
  2880.                         local enabled_PYTHON_ABIS= other_PYTHON_ABI;
  2881.                         for other_PYTHON_ABI in ${PYTHON_ABIS};
  2882.                         do
  2883.                             [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}";
  2884.                         done;
  2885.                         export PYTHON_ABIS="${enabled_PYTHON_ABIS}";
  2886.                     fi;
  2887.                     if [[ "${quiet}" == "0" ]]; then
  2888.                         ewarn "${failure_message}";
  2889.                     fi;
  2890.                     if [[ -z "${PYTHON_ABIS}" ]]; then
  2891.                         die "${function}() function failed with all enabled Python ABIs";
  2892.                     fi;
  2893.                 else
  2894.                     die "${failure_message}";
  2895.                 fi;
  2896.             fi;
  2897.         fi;
  2898.         if [[ "$(dirs -p | wc -l)" -lt "${previous_directory_stack_length}" ]]; then
  2899.             die "Directory stack decreased illegally";
  2900.         fi;
  2901.         while [[ "$(dirs -p | wc -l)" -gt "${previous_directory_stack_length}" ]]; do
  2902.             popd > /dev/null || die "popd failed";
  2903.         done;
  2904.         cd "${previous_directory}";
  2905.         if [[ "$(dirs -p)" != "${previous_directory_stack}" ]]; then
  2906.             die "Directory stack changed illegally";
  2907.         fi;
  2908.         if [[ "${separate_build_dirs}" == "1" ]]; then
  2909.             popd > /dev/null || die "popd failed";
  2910.         fi;
  2911.         unset BUILDDIR;
  2912.     done;
  2913.     if [[ "${default_function}" == "1" ]]; then
  2914.         unset -f python_default_function;
  2915.     fi
  2916. }
  2917. python_execute_nosetests ()
  2918. {
  2919.     _python_check_python_pkg_setup_execution;
  2920.     _python_set_color_variables;
  2921.     local PYTHONPATH_template separate_build_dirs;
  2922.     while (($#)); do
  2923.         case "$1" in
  2924.             -P | --PYTHONPATH)
  2925.                 PYTHONPATH_template="$2";
  2926.                 shift
  2927.             ;;
  2928.             -s | --separate-build-dirs)
  2929.                 separate_build_dirs="1"
  2930.             ;;
  2931.             --)
  2932.                 shift;
  2933.                 break
  2934.             ;;
  2935.             -*)
  2936.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  2937.             ;;
  2938.             *)
  2939.                 break
  2940.             ;;
  2941.         esac;
  2942.         shift;
  2943.     done;
  2944.     function python_test_function ()
  2945.     {
  2946.         local evaluated_PYTHONPATH;
  2947.         eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"";
  2948.         _PYTHON_TEST_FUNCTION="python_execute_nosetests" _python_test_hook pre;
  2949.         if [[ -n "${evaluated_PYTHONPATH}" ]]; then
  2950.             echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL};
  2951.             PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?";
  2952.         else
  2953.             echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL};
  2954.             nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?";
  2955.         fi;
  2956.         _PYTHON_TEST_FUNCTION="python_execute_nosetests" _python_test_hook post
  2957.     };
  2958.     if _python_package_supporting_installation_for_multiple_python_abis; then
  2959.         python_execute_function ${separate_build_dirs:+-s} python_test_function "$@";
  2960.     else
  2961.         if [[ -n "${separate_build_dirs}" ]]; then
  2962.             die "${FUNCNAME}(): Invalid usage";
  2963.         fi;
  2964.         python_test_function "$@" || die "Testing failed";
  2965.     fi;
  2966.     unset -f python_test_function
  2967. }
  2968. python_execute_py.test ()
  2969. {
  2970.     _python_check_python_pkg_setup_execution;
  2971.     _python_set_color_variables;
  2972.     local PYTHONPATH_template separate_build_dirs;
  2973.     while (($#)); do
  2974.         case "$1" in
  2975.             -P | --PYTHONPATH)
  2976.                 PYTHONPATH_template="$2";
  2977.                 shift
  2978.             ;;
  2979.             -s | --separate-build-dirs)
  2980.                 separate_build_dirs="1"
  2981.             ;;
  2982.             --)
  2983.                 shift;
  2984.                 break
  2985.             ;;
  2986.             -*)
  2987.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  2988.             ;;
  2989.             *)
  2990.                 break
  2991.             ;;
  2992.         esac;
  2993.         shift;
  2994.     done;
  2995.     function python_test_function ()
  2996.     {
  2997.         local evaluated_PYTHONPATH;
  2998.         eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"";
  2999.         _PYTHON_TEST_FUNCTION="python_execute_py.test" _python_test_hook pre;
  3000.         if [[ -n "${evaluated_PYTHONPATH}" ]]; then
  3001.             echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL};
  3002.             PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" || return "$?";
  3003.         else
  3004.             echo ${_BOLD}py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"${_NORMAL};
  3005.             py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?";
  3006.         fi;
  3007.         _PYTHON_TEST_FUNCTION="python_execute_py.test" _python_test_hook post
  3008.     };
  3009.     if _python_package_supporting_installation_for_multiple_python_abis; then
  3010.         python_execute_function ${separate_build_dirs:+-s} python_test_function "$@";
  3011.     else
  3012.         if [[ -n "${separate_build_dirs}" ]]; then
  3013.             die "${FUNCNAME}(): Invalid usage";
  3014.         fi;
  3015.         python_test_function "$@" || die "Testing failed";
  3016.     fi;
  3017.     unset -f python_test_function
  3018. }
  3019. python_execute_trial ()
  3020. {
  3021.     _python_check_python_pkg_setup_execution;
  3022.     _python_set_color_variables;
  3023.     local PYTHONPATH_template separate_build_dirs;
  3024.     while (($#)); do
  3025.         case "$1" in
  3026.             -P | --PYTHONPATH)
  3027.                 PYTHONPATH_template="$2";
  3028.                 shift
  3029.             ;;
  3030.             -s | --separate-build-dirs)
  3031.                 separate_build_dirs="1"
  3032.             ;;
  3033.             --)
  3034.                 shift;
  3035.                 break
  3036.             ;;
  3037.             -*)
  3038.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  3039.             ;;
  3040.             *)
  3041.                 break
  3042.             ;;
  3043.         esac;
  3044.         shift;
  3045.     done;
  3046.     function python_test_function ()
  3047.     {
  3048.         local evaluated_PYTHONPATH;
  3049.         eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"";
  3050.         _PYTHON_TEST_FUNCTION="python_execute_trial" _python_test_hook pre;
  3051.         if [[ -n "${evaluated_PYTHONPATH}" ]]; then
  3052.             echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL};
  3053.             PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?";
  3054.         else
  3055.             echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL};
  3056.             trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?";
  3057.         fi;
  3058.         _PYTHON_TEST_FUNCTION="python_execute_trial" _python_test_hook post
  3059.     };
  3060.     if _python_package_supporting_installation_for_multiple_python_abis; then
  3061.         python_execute_function ${separate_build_dirs:+-s} python_test_function "$@";
  3062.     else
  3063.         if [[ -n "${separate_build_dirs}" ]]; then
  3064.             die "${FUNCNAME}(): Invalid usage";
  3065.         fi;
  3066.         python_test_function "$@" || die "Testing failed";
  3067.     fi;
  3068.     unset -f python_test_function
  3069. }
  3070. python_generate_wrapper_scripts ()
  3071. {
  3072.     if [[ "${EBUILD_PHASE}" != "install" ]]; then
  3073.         die "${FUNCNAME}() can be used only in src_install() phase";
  3074.     fi;
  3075.     if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3076.         die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3077.     fi;
  3078.     _python_check_python_pkg_setup_execution;
  3079.     _python_initialize_prefix_variables;
  3080.     local eselect_python_option file force="0" quiet="0" PYTHON_ABI PYTHON_ABIS_list python2_enabled="0" python3_enabled="0" respect_EPYTHON="0";
  3081.     while (($#)); do
  3082.         case "$1" in
  3083.             -E | --respect-EPYTHON)
  3084.                 respect_EPYTHON="1"
  3085.             ;;
  3086.             -f | --force)
  3087.                 force="1"
  3088.             ;;
  3089.             -q | --quiet)
  3090.                 quiet="1"
  3091.             ;;
  3092.             --)
  3093.                 shift;
  3094.                 break
  3095.             ;;
  3096.             -*)
  3097.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  3098.             ;;
  3099.             *)
  3100.                 break
  3101.             ;;
  3102.         esac;
  3103.         shift;
  3104.     done;
  3105.     if [[ "$#" -eq 0 ]]; then
  3106.         die "${FUNCNAME}(): Missing arguments";
  3107.     fi;
  3108.     _python_calculate_PYTHON_ABIS;
  3109.     for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}";
  3110.     do
  3111.         if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
  3112.             python2_enabled="1";
  3113.         fi;
  3114.     done;
  3115.     for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}";
  3116.     do
  3117.         if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
  3118.             python3_enabled="1";
  3119.         fi;
  3120.     done;
  3121.     if [[ "${python2_enabled}" == "1" && "${python3_enabled}" == "1" ]]; then
  3122.         eselect_python_option=;
  3123.     else
  3124.         if [[ "${python2_enabled}" == "1" && "${python3_enabled}" == "0" ]]; then
  3125.             eselect_python_option="--python2";
  3126.         else
  3127.             if [[ "${python2_enabled}" == "0" && "${python3_enabled}" == "1" ]]; then
  3128.                 eselect_python_option="--python3";
  3129.             else
  3130.                 die "${FUNCNAME}(): Unsupported environment";
  3131.             fi;
  3132.         fi;
  3133.     fi;
  3134.     PYTHON_ABIS_list="$("$(PYTHON -f)" -c "print(', '.join('\"%s\"' % x for x in reversed('${PYTHON_ABIS}'.split())))")";
  3135.     for file in "$@";
  3136.     do
  3137.         if [[ -f "${file}" && "${force}" == "0" ]]; then
  3138.             die "${FUNCNAME}(): '${file}' already exists";
  3139.         fi;
  3140.         if [[ "${quiet}" == "0" ]]; then
  3141.             einfo "Generating '${file#${ED%/}}' wrapper script";
  3142.         fi;
  3143.         cat > "${file}"  <<EOF
  3144. #!/usr/bin/env python
  3145. # Gentoo '${file##*/}' wrapper script generated by python_generate_wrapper_scripts()
  3146.  
  3147. import os
  3148. import re
  3149. import subprocess
  3150. import sys
  3151.  
  3152. cpython_ABI_re = re.compile(r"^(\d+\.\d+)$")
  3153. jython_ABI_re = re.compile(r"^(\d+\.\d+)-jython$")
  3154. pypy_ABI_re = re.compile(r"^\d+\.\d+-pypy-(\d+\.\d+)$")
  3155. cpython_interpreter_re = re.compile(r"^python(\d+\.\d+)$")
  3156. jython_interpreter_re = re.compile(r"^jython(\d+\.\d+)$")
  3157. pypy_interpreter_re = re.compile(r"^pypy-c(\d+\.\d+)$")
  3158. cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)")
  3159. python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)")
  3160. python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$")
  3161.  
  3162. pypy_versions_mapping = {
  3163.         "1.5": "2.7",
  3164.         "1.6": "2.7",
  3165.         "1.7": "2.7",
  3166.         "1.8": "2.7",
  3167. }
  3168.  
  3169. def get_PYTHON_ABI(python_interpreter):
  3170.         cpython_matched = cpython_interpreter_re.match(python_interpreter)
  3171.         jython_matched = jython_interpreter_re.match(python_interpreter)
  3172.         pypy_matched = pypy_interpreter_re.match(python_interpreter)
  3173.         if cpython_matched is not None:
  3174.                 PYTHON_ABI = cpython_matched.group(1)
  3175.         elif jython_matched is not None:
  3176.                 PYTHON_ABI = jython_matched.group(1) + "-jython"
  3177.         elif pypy_matched is not None:
  3178.                 PYTHON_ABI = pypy_versions_mapping[pypy_matched.group(1)] + "-pypy-" + pypy_matched.group(1)
  3179.         else:
  3180.                 PYTHON_ABI = None
  3181.         return PYTHON_ABI
  3182.  
  3183. def get_python_interpreter(PYTHON_ABI):
  3184.         cpython_matched = cpython_ABI_re.match(PYTHON_ABI)
  3185.         jython_matched = jython_ABI_re.match(PYTHON_ABI)
  3186.         pypy_matched = pypy_ABI_re.match(PYTHON_ABI)
  3187.         if cpython_matched is not None:
  3188.                 python_interpreter = "python" + cpython_matched.group(1)
  3189.         elif jython_matched is not None:
  3190.                 python_interpreter = "jython" + jython_matched.group(1)
  3191.         elif pypy_matched is not None:
  3192.                 python_interpreter = "pypy-c" + pypy_matched.group(1)
  3193.         else:
  3194.                 python_interpreter = None
  3195.         return python_interpreter
  3196.  
  3197. EOF
  3198.  
  3199.         if [[ "$?" != "0" ]]; then
  3200.             die "${FUNCNAME}(): Generation of '$1' failed";
  3201.         fi;
  3202.         if [[ "${respect_EPYTHON}" == "1" ]]; then
  3203.             cat >> "${file}"  <<EOF
  3204. python_interpreter = os.environ.get("EPYTHON")
  3205. if python_interpreter:
  3206.         PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
  3207.         if PYTHON_ABI is None:
  3208.                 sys.stderr.write("%s: EPYTHON variable has unrecognized value '%s'\n" % (sys.argv[0], python_interpreter))
  3209.                 sys.exit(1)
  3210. else:
  3211.         try:
  3212.                 environment = os.environ.copy()
  3213.                 environment["ROOT"] = "/"
  3214.                 eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], env=environment, stdout=subprocess.PIPE)
  3215.                 if eselect_process.wait() != 0:
  3216.                         raise ValueError
  3217.         except (OSError, ValueError):
  3218.                 sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0])
  3219.                 sys.exit(1)
  3220.  
  3221.         python_interpreter = eselect_process.stdout.read()
  3222.         if not isinstance(python_interpreter, str):
  3223.                 # Python 3
  3224.                 python_interpreter = python_interpreter.decode()
  3225.         python_interpreter = python_interpreter.rstrip("\n")
  3226.  
  3227.         PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
  3228.         if PYTHON_ABI is None:
  3229.                 sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], python_interpreter))
  3230.                 sys.exit(1)
  3231.  
  3232. wrapper_script_path = os.path.realpath(sys.argv[0])
  3233. target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
  3234. if not os.path.exists(target_executable_path):
  3235.         sys.stderr.write("%s: '%s' does not exist\n" % (sys.argv[0], target_executable_path))
  3236.         sys.exit(1)
  3237. EOF
  3238.  
  3239.             if [[ "$?" != "0" ]]; then
  3240.                 die "${FUNCNAME}(): Generation of '$1' failed";
  3241.             fi;
  3242.         else
  3243.             cat >> "${file}"  <<EOF
  3244. try:
  3245.         environment = os.environ.copy()
  3246.         environment["ROOT"] = "/"
  3247.         eselect_process = subprocess.Popen(["${EPREFIX}/usr/bin/eselect", "python", "show"${eselect_python_option:+, $(echo "\"")}${eselect_python_option}${eselect_python_option:+$(echo "\"")}], env=environment, stdout=subprocess.PIPE)
  3248.         if eselect_process.wait() != 0:
  3249.                 raise ValueError
  3250. except (OSError, ValueError):
  3251.         sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0])
  3252.         sys.exit(1)
  3253.  
  3254. python_interpreter = eselect_process.stdout.read()
  3255. if not isinstance(python_interpreter, str):
  3256.         # Python 3
  3257.         python_interpreter = python_interpreter.decode()
  3258. python_interpreter = python_interpreter.rstrip("\n")
  3259.  
  3260. PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
  3261. if PYTHON_ABI is None:
  3262.         sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], python_interpreter))
  3263.         sys.exit(1)
  3264.  
  3265. wrapper_script_path = os.path.realpath(sys.argv[0])
  3266. for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]:
  3267.         target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
  3268.         if os.path.exists(target_executable_path):
  3269.                 break
  3270. else:
  3271.         sys.stderr.write("%s: No target script exists for '%s'\n" % (sys.argv[0], wrapper_script_path))
  3272.         sys.exit(1)
  3273.  
  3274. python_interpreter = get_python_interpreter(PYTHON_ABI)
  3275. if python_interpreter is None:
  3276.         sys.stderr.write("%s: Unrecognized Python ABI '%s'\n" % (sys.argv[0], PYTHON_ABI))
  3277.         sys.exit(1)
  3278. EOF
  3279.  
  3280.             if [[ "$?" != "0" ]]; then
  3281.                 die "${FUNCNAME}(): Generation of '$1' failed";
  3282.             fi;
  3283.         fi
  3284.         cat >> "${file}"  <<EOF
  3285.  
  3286. target_executable = open(target_executable_path, "rb")
  3287. target_executable_first_line = target_executable.readline()
  3288. target_executable.close()
  3289. if not isinstance(target_executable_first_line, str):
  3290.         # Python 3
  3291.         target_executable_first_line = target_executable_first_line.decode("utf_8", "replace")
  3292.  
  3293. options = []
  3294. python_shebang_options_matched = python_shebang_options_re.match(target_executable_first_line)
  3295. if python_shebang_options_matched is not None:
  3296.         options = [python_shebang_options_matched.group(1)]
  3297.  
  3298. cpython_shebang_matched = cpython_shebang_re.match(target_executable_first_line)
  3299.  
  3300. if cpython_shebang_matched is not None:
  3301.         try:
  3302.                 python_interpreter_path = "${EPREFIX}/usr/bin/%s" % python_interpreter
  3303.                 os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1"
  3304.                 python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE)
  3305.                 del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
  3306.                 if python_verification_process.wait() != 0:
  3307.                         raise ValueError
  3308.  
  3309.                 python_verification_output = python_verification_process.stdout.read()
  3310.                 if not isinstance(python_verification_output, str):
  3311.                         # Python 3
  3312.                         python_verification_output = python_verification_output.decode()
  3313.  
  3314.                 if not python_verification_output_re.match(python_verification_output):
  3315.                         raise ValueError
  3316.  
  3317.                 if cpython_interpreter_re.match(python_interpreter) is not None:
  3318.                         os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0])
  3319.                         os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
  3320.                         os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
  3321.  
  3322.                 if hasattr(os, "execv"):
  3323.                         os.execv(python_interpreter_path, [python_interpreter_path] + options + sys.argv)
  3324.                 else:
  3325.                         sys.exit(subprocess.Popen([python_interpreter_path] + options + sys.argv).wait())
  3326.         except (KeyboardInterrupt, SystemExit):
  3327.                 raise
  3328.         except:
  3329.                 pass
  3330.         for variable in ("GENTOO_PYTHON_PROCESS_NAME", "GENTOO_PYTHON_WRAPPER_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"):
  3331.                 if variable in os.environ:
  3332.                         del os.environ[variable]
  3333.  
  3334. if hasattr(os, "execv"):
  3335.         os.execv(target_executable_path, sys.argv)
  3336. else:
  3337.         sys.exit(subprocess.Popen([target_executable_path] + sys.argv[1:]).wait())
  3338. EOF
  3339.  
  3340.         if [[ "$?" != "0" ]]; then
  3341.             die "${FUNCNAME}(): Generation of '$1' failed";
  3342.         fi;
  3343.         fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed";
  3344.     done
  3345. }
  3346. python_get_implementation ()
  3347. {
  3348.     _python_check_python_pkg_setup_execution;
  3349.     local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}";
  3350.     while (($#)); do
  3351.         case "$1" in
  3352.             -f | --final-ABI)
  3353.                 final_ABI="1"
  3354.             ;;
  3355.             -*)
  3356.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  3357.             ;;
  3358.             *)
  3359.                 die "${FUNCNAME}(): Invalid usage"
  3360.             ;;
  3361.         esac;
  3362.         shift;
  3363.     done;
  3364.     if [[ "${final_ABI}" == "1" ]]; then
  3365.         if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3366.             die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3367.         fi;
  3368.         PYTHON_ABI="$(PYTHON -f --ABI)";
  3369.     else
  3370.         if _python_package_supporting_installation_for_multiple_python_abis; then
  3371.             if ! _python_abi-specific_local_scope; then
  3372.                 die "${FUNCNAME}() should be used in ABI-specific local scope";
  3373.             fi;
  3374.         else
  3375.             PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  3376.         fi;
  3377.     fi;
  3378.     echo "$(_python_get_implementation "${PYTHON_ABI}")"
  3379. }
  3380. python_get_implementation_and_version ()
  3381. {
  3382.     _python_check_python_pkg_setup_execution;
  3383.     local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}";
  3384.     while (($#)); do
  3385.         case "$1" in
  3386.             -f | --final-ABI)
  3387.                 final_ABI="1"
  3388.             ;;
  3389.             -*)
  3390.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  3391.             ;;
  3392.             *)
  3393.                 die "${FUNCNAME}(): Invalid usage"
  3394.             ;;
  3395.         esac;
  3396.         shift;
  3397.     done;
  3398.     if [[ "${final_ABI}" == "1" ]]; then
  3399.         if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3400.             die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3401.         fi;
  3402.         PYTHON_ABI="$(PYTHON -f --ABI)";
  3403.     else
  3404.         if _python_package_supporting_installation_for_multiple_python_abis; then
  3405.             if ! _python_abi-specific_local_scope; then
  3406.                 die "${FUNCNAME}() should be used in ABI-specific local scope";
  3407.             fi;
  3408.         else
  3409.             PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  3410.         fi;
  3411.     fi;
  3412.     if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-[[:alnum:]]+-[[:digit:]]+\.[[:digit:]]+$ ]]; then
  3413.         echo "$(_python_get_implementation "${PYTHON_ABI}") ${PYTHON_ABI##*-} (Python ${PYTHON_ABI%%-*})";
  3414.     else
  3415.         echo "$(_python_get_implementation "${PYTHON_ABI}") ${PYTHON_ABI%%-*}";
  3416.     fi
  3417. }
  3418. python_get_implementational_package ()
  3419. {
  3420.     _python_check_python_pkg_setup_execution;
  3421.     local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}";
  3422.     while (($#)); do
  3423.         case "$1" in
  3424.             -f | --final-ABI)
  3425.                 final_ABI="1"
  3426.             ;;
  3427.             -*)
  3428.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  3429.             ;;
  3430.             *)
  3431.                 die "${FUNCNAME}(): Invalid usage"
  3432.             ;;
  3433.         esac;
  3434.         shift;
  3435.     done;
  3436.     if [[ "${final_ABI}" == "1" ]]; then
  3437.         if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3438.             die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3439.         fi;
  3440.         PYTHON_ABI="$(PYTHON -f --ABI)";
  3441.     else
  3442.         if _python_package_supporting_installation_for_multiple_python_abis; then
  3443.             if ! _python_abi-specific_local_scope; then
  3444.                 die "${FUNCNAME}() should be used in ABI-specific local scope";
  3445.             fi;
  3446.         else
  3447.             PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  3448.         fi;
  3449.     fi;
  3450.     if [[ "${EAPI:-0}" == "0" ]]; then
  3451.         if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  3452.             echo "=dev-lang/python-${PYTHON_ABI}*";
  3453.         else
  3454.             if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  3455.                 echo "=dev-java/jython-${PYTHON_ABI%-jython}*";
  3456.             else
  3457.                 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  3458.                     echo "=dev-python/pypy-${PYTHON_ABI#*-pypy-}*";
  3459.                 fi;
  3460.             fi;
  3461.         fi;
  3462.     else
  3463.         if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  3464.             echo "dev-lang/python:${PYTHON_ABI}";
  3465.         else
  3466.             if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  3467.                 echo "dev-java/jython:${PYTHON_ABI%-jython}";
  3468.             else
  3469.                 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  3470.                     echo "dev-python/pypy:${PYTHON_ABI#*-pypy-}";
  3471.                 fi;
  3472.             fi;
  3473.         fi;
  3474.     fi
  3475. }
  3476. python_get_includedir ()
  3477. {
  3478.     _python_check_python_pkg_setup_execution;
  3479.     local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}";
  3480.     while (($#)); do
  3481.         case "$1" in
  3482.             -b | --base-path)
  3483.                 base_path="1"
  3484.             ;;
  3485.             -f | --final-ABI)
  3486.                 final_ABI="1"
  3487.             ;;
  3488.             -*)
  3489.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  3490.             ;;
  3491.             *)
  3492.                 die "${FUNCNAME}(): Invalid usage"
  3493.             ;;
  3494.         esac;
  3495.         shift;
  3496.     done;
  3497.     if [[ "${base_path}" == "0" ]]; then
  3498.         prefix="/";
  3499.     fi;
  3500.     if [[ "${final_ABI}" == "1" ]]; then
  3501.         if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3502.             die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3503.         fi;
  3504.         PYTHON_ABI="$(PYTHON -f --ABI)";
  3505.     else
  3506.         if _python_package_supporting_installation_for_multiple_python_abis; then
  3507.             if ! _python_abi-specific_local_scope; then
  3508.                 die "${FUNCNAME}() should be used in ABI-specific local scope";
  3509.             fi;
  3510.         else
  3511.             PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  3512.         fi;
  3513.     fi;
  3514.     if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  3515.         echo "${prefix}usr/include/python${PYTHON_ABI}";
  3516.     else
  3517.         if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  3518.             echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Include";
  3519.         else
  3520.             if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  3521.                 echo "${prefix}usr/$(get_libdir)/pypy${PYTHON_ABI#*-pypy-}/include";
  3522.             fi;
  3523.         fi;
  3524.     fi
  3525. }
  3526. python_get_libdir ()
  3527. {
  3528.     _python_check_python_pkg_setup_execution;
  3529.     local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}";
  3530.     while (($#)); do
  3531.         case "$1" in
  3532.             -b | --base-path)
  3533.                 base_path="1"
  3534.             ;;
  3535.             -f | --final-ABI)
  3536.                 final_ABI="1"
  3537.             ;;
  3538.             -*)
  3539.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  3540.             ;;
  3541.             *)
  3542.                 die "${FUNCNAME}(): Invalid usage"
  3543.             ;;
  3544.         esac;
  3545.         shift;
  3546.     done;
  3547.     if [[ "${base_path}" == "0" ]]; then
  3548.         prefix="/";
  3549.     fi;
  3550.     if [[ "${final_ABI}" == "1" ]]; then
  3551.         if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3552.             die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3553.         fi;
  3554.         PYTHON_ABI="$(PYTHON -f --ABI)";
  3555.     else
  3556.         if _python_package_supporting_installation_for_multiple_python_abis; then
  3557.             if ! _python_abi-specific_local_scope; then
  3558.                 die "${FUNCNAME}() should be used in ABI-specific local scope";
  3559.             fi;
  3560.         else
  3561.             PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  3562.         fi;
  3563.     fi;
  3564.     if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  3565.         echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}";
  3566.     else
  3567.         if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  3568.             echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib";
  3569.         else
  3570.             if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  3571.                 die "${FUNCNAME}(): PyPy has multiple standard library directories";
  3572.             fi;
  3573.         fi;
  3574.     fi
  3575. }
  3576. python_get_library ()
  3577. {
  3578.     _python_check_python_pkg_setup_execution;
  3579.     local base_path="0" final_ABI="0" linker_option="0" prefix PYTHON_ABI="${PYTHON_ABI}";
  3580.     while (($#)); do
  3581.         case "$1" in
  3582.             -b | --base-path)
  3583.                 base_path="1"
  3584.             ;;
  3585.             -f | --final-ABI)
  3586.                 final_ABI="1"
  3587.             ;;
  3588.             -l | --linker-option)
  3589.                 linker_option="1"
  3590.             ;;
  3591.             -*)
  3592.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  3593.             ;;
  3594.             *)
  3595.                 die "${FUNCNAME}(): Invalid usage"
  3596.             ;;
  3597.         esac;
  3598.         shift;
  3599.     done;
  3600.     if [[ "${base_path}" == "0" ]]; then
  3601.         prefix="/";
  3602.     fi;
  3603.     if [[ "${base_path}" == "1" && "${linker_option}" == "1" ]]; then
  3604.         die "${FUNCNAME}(): '--base-path' and '--linker-option' options cannot be specified simultaneously";
  3605.     fi;
  3606.     if [[ "${final_ABI}" == "1" ]]; then
  3607.         if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3608.             die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3609.         fi;
  3610.         PYTHON_ABI="$(PYTHON -f --ABI)";
  3611.     else
  3612.         if _python_package_supporting_installation_for_multiple_python_abis; then
  3613.             if ! _python_abi-specific_local_scope; then
  3614.                 die "${FUNCNAME}() should be used in ABI-specific local scope";
  3615.             fi;
  3616.         else
  3617.             PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  3618.         fi;
  3619.     fi;
  3620.     if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  3621.         if [[ "${linker_option}" == "1" ]]; then
  3622.             echo "-lpython${PYTHON_ABI}";
  3623.         else
  3624.             echo "${prefix}usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)";
  3625.         fi;
  3626.     else
  3627.         if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  3628.             die "${FUNCNAME}(): Jython does not have shared library";
  3629.         else
  3630.             if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  3631.                 die "${FUNCNAME}(): PyPy does not have shared library";
  3632.             fi;
  3633.         fi;
  3634.     fi
  3635. }
  3636. python_get_sitedir ()
  3637. {
  3638.     _python_check_python_pkg_setup_execution;
  3639.     local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}";
  3640.     while (($#)); do
  3641.         case "$1" in
  3642.             -b | --base-path)
  3643.                 base_path="1"
  3644.             ;;
  3645.             -f | --final-ABI)
  3646.                 final_ABI="1"
  3647.             ;;
  3648.             -*)
  3649.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  3650.             ;;
  3651.             *)
  3652.                 die "${FUNCNAME}(): Invalid usage"
  3653.             ;;
  3654.         esac;
  3655.         shift;
  3656.     done;
  3657.     if [[ "${base_path}" == "0" ]]; then
  3658.         prefix="/";
  3659.     fi;
  3660.     if [[ "${final_ABI}" == "1" ]]; then
  3661.         if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3662.             die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3663.         fi;
  3664.         PYTHON_ABI="$(PYTHON -f --ABI)";
  3665.     else
  3666.         if _python_package_supporting_installation_for_multiple_python_abis; then
  3667.             if ! _python_abi-specific_local_scope; then
  3668.                 die "${FUNCNAME}() should be used in ABI-specific local scope";
  3669.             fi;
  3670.         else
  3671.             PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  3672.         fi;
  3673.     fi;
  3674.     if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  3675.         echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}/site-packages";
  3676.     else
  3677.         if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  3678.             echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib/site-packages";
  3679.         else
  3680.             if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  3681.                 echo "${prefix}usr/$(get_libdir)/pypy${PYTHON_ABI#*-pypy-}/site-packages";
  3682.             fi;
  3683.         fi;
  3684.     fi
  3685. }
  3686. python_get_version ()
  3687. {
  3688.     _python_check_python_pkg_setup_execution;
  3689.     local final_ABI="0" language="0" language_version full="0" major="0" minor="0" micro="0" PYTHON_ABI="${PYTHON_ABI}" python_command;
  3690.     while (($#)); do
  3691.         case "$1" in
  3692.             -f | --final-ABI)
  3693.                 final_ABI="1"
  3694.             ;;
  3695.             -l | --language)
  3696.                 language="1"
  3697.             ;;
  3698.             --full)
  3699.                 full="1"
  3700.             ;;
  3701.             --major)
  3702.                 major="1"
  3703.             ;;
  3704.             --minor)
  3705.                 minor="1"
  3706.             ;;
  3707.             --micro)
  3708.                 micro="1"
  3709.             ;;
  3710.             -*)
  3711.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  3712.             ;;
  3713.             *)
  3714.                 die "${FUNCNAME}(): Invalid usage"
  3715.             ;;
  3716.         esac;
  3717.         shift;
  3718.     done;
  3719.     if [[ "${final_ABI}" == "1" ]]; then
  3720.         if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3721.             die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3722.         fi;
  3723.     else
  3724.         if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
  3725.             die "${FUNCNAME}() should be used in ABI-specific local scope";
  3726.         fi;
  3727.     fi;
  3728.     if [[ "$((${full} + ${major} + ${minor} + ${micro}))" -gt 1 ]]; then
  3729.         die "${FUNCNAME}(): '--full', '--major', '--minor' or '--micro' options cannot be specified simultaneously";
  3730.     fi;
  3731.     if [[ "${language}" == "1" ]]; then
  3732.         if [[ "${final_ABI}" == "1" ]]; then
  3733.             PYTHON_ABI="$(PYTHON -f --ABI)";
  3734.         else
  3735.             if [[ -z "${PYTHON_ABI}" ]]; then
  3736.                 PYTHON_ABI="$(PYTHON --ABI)";
  3737.             fi;
  3738.         fi;
  3739.         language_version="${PYTHON_ABI%%-*}";
  3740.         if [[ "${full}" == "1" ]]; then
  3741.             die "${FUNCNAME}(): '--language' and '--full' options cannot be specified simultaneously";
  3742.         else
  3743.             if [[ "${major}" == "1" ]]; then
  3744.                 echo "${language_version%.*}";
  3745.             else
  3746.                 if [[ "${minor}" == "1" ]]; then
  3747.                     echo "${language_version#*.}";
  3748.                 else
  3749.                     if [[ "${micro}" == "1" ]]; then
  3750.                         die "${FUNCNAME}(): '--language' and '--micro' options cannot be specified simultaneously";
  3751.                     else
  3752.                         echo "${language_version}";
  3753.                     fi;
  3754.                 fi;
  3755.             fi;
  3756.         fi;
  3757.     else
  3758.         if [[ "${full}" == "1" ]]; then
  3759.             python_command="import sys; print('.'.join(str(x) for x in getattr(sys, 'pypy_version_info', sys.version_info)[:3]))";
  3760.         else
  3761.             if [[ "${major}" == "1" ]]; then
  3762.                 python_command="import sys; print(getattr(sys, 'pypy_version_info', sys.version_info)[0])";
  3763.             else
  3764.                 if [[ "${minor}" == "1" ]]; then
  3765.                     python_command="import sys; print(getattr(sys, 'pypy_version_info', sys.version_info)[1])";
  3766.                 else
  3767.                     if [[ "${micro}" == "1" ]]; then
  3768.                         python_command="import sys; print(getattr(sys, 'pypy_version_info', sys.version_info)[2])";
  3769.                     else
  3770.                         if [[ -n "${PYTHON_ABI}" && "${final_ABI}" == "0" ]]; then
  3771.                             if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  3772.                                 echo "${PYTHON_ABI}";
  3773.                             else
  3774.                                 if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  3775.                                     echo "${PYTHON_ABI%-jython}";
  3776.                                 else
  3777.                                     if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  3778.                                         echo "${PYTHON_ABI#*-pypy-}";
  3779.                                     fi;
  3780.                                 fi;
  3781.                             fi;
  3782.                             return;
  3783.                         fi;
  3784.                         python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))";
  3785.                     fi;
  3786.                 fi;
  3787.             fi;
  3788.         fi;
  3789.         if [[ "${final_ABI}" == "1" ]]; then
  3790.             "$(PYTHON -f)" -c "${python_command}";
  3791.         else
  3792.             "$(PYTHON ${PYTHON_ABI})" -c "${python_command}";
  3793.         fi;
  3794.     fi
  3795. }
  3796. python_merge_intermediate_installation_images ()
  3797. {
  3798.     if [[ "${EBUILD_PHASE}" != "install" ]]; then
  3799.         die "${FUNCNAME}() can be used only in src_install() phase";
  3800.     fi;
  3801.     if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3802.         die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3803.     fi;
  3804.     _python_check_python_pkg_setup_execution;
  3805.     _python_initialize_prefix_variables;
  3806.     local absolute_file b file files=() intermediate_installation_images_directory PYTHON_ABI quiet="0" regex shebang version_executable wrapper_scripts=() wrapper_scripts_set=();
  3807.     while (($#)); do
  3808.         case "$1" in
  3809.             -q | --quiet)
  3810.                 quiet="1"
  3811.             ;;
  3812.             --)
  3813.                 shift;
  3814.                 break
  3815.             ;;
  3816.             -*)
  3817.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  3818.             ;;
  3819.             *)
  3820.                 break
  3821.             ;;
  3822.         esac;
  3823.         shift;
  3824.     done;
  3825.     if [[ "$#" -ne 1 ]]; then
  3826.         die "${FUNCNAME}() requires 1 argument";
  3827.     fi;
  3828.     intermediate_installation_images_directory="$1";
  3829.     if [[ ! -d "${intermediate_installation_images_directory}" ]]; then
  3830.         die "${FUNCNAME}(): Intermediate installation images directory '${intermediate_installation_images_directory}' does not exist";
  3831.     fi;
  3832.     _python_calculate_PYTHON_ABIS;
  3833.     if [[ "$(PYTHON -f --ABI)" == 3.* ]]; then
  3834.         b="b";
  3835.     fi;
  3836.     while read -d '' -r file; do
  3837.         files+=("${file}");
  3838.     done < <("$(PYTHON -f)" -c "import os
  3839. import sys
  3840.  
  3841. if hasattr(sys.stdout, 'buffer'):
  3842.         # Python 3
  3843.         stdout = sys.stdout.buffer
  3844. else:
  3845.         # Python 2
  3846.         stdout = sys.stdout
  3847.  
  3848. files_set = set()
  3849.  
  3850. os.chdir(${b}'${intermediate_installation_images_directory}')
  3851.  
  3852. for PYTHON_ABI in ${b}'${PYTHON_ABIS}'.split():
  3853.         for root, dirs, files in os.walk(PYTHON_ABI + ${b}'${EPREFIX}'):
  3854.                 root = root[len(PYTHON_ABI + ${b}'${EPREFIX}')+1:]
  3855.                 files_set.update(root + ${b}'/' + file for file in files)
  3856.  
  3857. for file in sorted(files_set):
  3858.         stdout.write(file)
  3859.         stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of files in intermediate installation images");
  3860.     for PYTHON_ABI in ${PYTHON_ABIS};
  3861.     do
  3862.         if [[ ! -d "${intermediate_installation_images_directory}/${PYTHON_ABI}" ]]; then
  3863.             die "${FUNCNAME}(): Intermediate installation image for Python ABI '${PYTHON_ABI}' does not exist";
  3864.         fi;
  3865.         pushd "${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}" > /dev/null || die "pushd failed";
  3866.         for file in "${files[@]}";
  3867.         do
  3868.             version_executable="0";
  3869.             for regex in "/usr/bin/.*" "/usr/sbin/.*" "${PYTHON_VERSIONED_SCRIPTS[@]}";
  3870.             do
  3871.                 if [[ "/${file}" =~ ^${regex}$ ]]; then
  3872.                     version_executable="1";
  3873.                     break;
  3874.                 fi;
  3875.             done;
  3876.             for regex in "${PYTHON_VERSIONED_EXECUTABLES[@]}";
  3877.             do
  3878.                 if [[ "/${file}" =~ ^${regex}$ ]]; then
  3879.                     version_executable="2";
  3880.                     break;
  3881.                 fi;
  3882.             done;
  3883.             if [[ "${version_executable}" != "0" ]]; then
  3884.                 for regex in "${PYTHON_NONVERSIONED_EXECUTABLES[@]}";
  3885.                 do
  3886.                     if [[ "/${file}" =~ ^${regex}$ ]]; then
  3887.                         version_executable="0";
  3888.                         break;
  3889.                     fi;
  3890.                 done;
  3891.             fi;
  3892.             [[ "${version_executable}" == "0" ]] && continue;
  3893.             if [[ -L "${file}" ]]; then
  3894.                 absolute_file="$(readlink "${file}")";
  3895.                 if [[ "${absolute_file}" == /* ]]; then
  3896.                     absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${absolute_file##/}";
  3897.                 else
  3898.                     if [[ "${file}" == */* ]]; then
  3899.                         absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${file%/*}/${absolute_file}";
  3900.                     else
  3901.                         absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${absolute_file}";
  3902.                     fi;
  3903.                 fi;
  3904.             else
  3905.                 absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${file}";
  3906.             fi;
  3907.             [[ ! -x "${absolute_file}" ]] && continue;
  3908.             shebang="$(head -n1 "${absolute_file}")" || die "Extraction of shebang from '${absolute_file}' failed";
  3909.             if [[ "${version_executable}" == "2" ]]; then
  3910.                 wrapper_scripts+=("${ED}${file}");
  3911.             else
  3912.                 if [[ "${version_executable}" == "1" ]]; then
  3913.                     if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}([[:digit:]]+(\.[[:digit:]]+)?)?($|[[:space:]]+) ]]; then
  3914.                         wrapper_scripts+=("${ED}${file}");
  3915.                     else
  3916.                         version_executable="0";
  3917.                     fi;
  3918.                 fi;
  3919.             fi;
  3920.             [[ "${version_executable}" == "0" ]] && continue;
  3921.             if [[ -e "${file}-${PYTHON_ABI}" ]]; then
  3922.                 die "${FUNCNAME}(): '${EPREFIX}/${file}-${PYTHON_ABI}' already exists";
  3923.             fi;
  3924.             mv "${file}" "${file}-${PYTHON_ABI}" || die "Renaming of '${file}' failed";
  3925.             if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}[[:digit:]]*($|[[:space:]]+) ]]; then
  3926.                 if [[ -L "${file}-${PYTHON_ABI}" ]]; then
  3927.                     python_convert_shebangs $([[ "${quiet}" == "1" ]] && echo --quiet) "${PYTHON_ABI}" "${absolute_file}";
  3928.                 else
  3929.                     python_convert_shebangs $([[ "${quiet}" == "1" ]] && echo --quiet) "${PYTHON_ABI}" "${file}-${PYTHON_ABI}";
  3930.                 fi;
  3931.             fi;
  3932.         done;
  3933.         popd > /dev/null || die "popd failed";
  3934.         if ROOT="/" has_version '>=sys-apps/coreutils-6.9.90'; then
  3935.             cp -fr --preserve=all --no-preserve=context "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed";
  3936.         else
  3937.             if ROOT="/" has_version sys-apps/coreutils; then
  3938.                 cp -fr --preserve=all "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed";
  3939.             else
  3940.                 cp -fpr "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed";
  3941.             fi;
  3942.         fi;
  3943.     done;
  3944.     rm -fr "${intermediate_installation_images_directory}";
  3945.     if [[ "${#wrapper_scripts[@]}" -ge 1 ]]; then
  3946.         rm -f "${T}/python_wrapper_scripts";
  3947.         for file in "${wrapper_scripts[@]}";
  3948.         do
  3949.             echo -n "${file}" >> "${T}/python_wrapper_scripts";
  3950.             echo -en "\x00" >> "${T}/python_wrapper_scripts";
  3951.         done;
  3952.         while read -d '' -r file; do
  3953.             wrapper_scripts_set+=("${file}");
  3954.         done < <("$(PYTHON -f)" -c "import sys
  3955.  
  3956. if hasattr(sys.stdout, 'buffer'):
  3957.         # Python 3
  3958.         stdout = sys.stdout.buffer
  3959. else:
  3960.         # Python 2
  3961.         stdout = sys.stdout
  3962.  
  3963. python_wrapper_scripts_file = open('${T}/python_wrapper_scripts', 'rb')
  3964. files = set(python_wrapper_scripts_file.read().rstrip(${b}'\x00').split(${b}'\x00'))
  3965. python_wrapper_scripts_file.close()
  3966.  
  3967. for file in sorted(files):
  3968.         stdout.write(file)
  3969.         stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of set of wrapper scripts");
  3970.         python_generate_wrapper_scripts $([[ "${quiet}" == "1" ]] && echo --quiet) "${wrapper_scripts_set[@]}";
  3971.     fi
  3972. }
  3973. python_mod_cleanup ()
  3974. {
  3975.     if [[ "${EBUILD_PHASE}" != "postrm" ]]; then
  3976.         die "${FUNCNAME}() can be used only in pkg_postrm() phase";
  3977.     fi;
  3978.     _python_check_python_pkg_setup_execution;
  3979.     _python_initialize_prefix_variables;
  3980.     local allow_evaluated_non_sitedir_paths="0" dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir;
  3981.     if _python_package_supporting_installation_for_multiple_python_abis; then
  3982.         if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
  3983.             die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called";
  3984.         fi;
  3985.         iterated_PYTHON_ABIS="${PYTHON_ABIS}";
  3986.     else
  3987.         if has "${EAPI:-0}" 0 1 2 3; then
  3988.             iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}";
  3989.         else
  3990.             iterated_PYTHON_ABIS="${PYTHON_ABI}";
  3991.         fi;
  3992.     fi;
  3993.     root="${EROOT%/}";
  3994.     while (($#)); do
  3995.         case "$1" in
  3996.             --allow-evaluated-non-sitedir-paths)
  3997.                 allow_evaluated_non_sitedir_paths="1"
  3998.             ;;
  3999.             --)
  4000.                 shift;
  4001.                 break
  4002.             ;;
  4003.             -*)
  4004.                 die "${FUNCNAME}(): Unrecognized option '$1'"
  4005.             ;;
  4006.             *)
  4007.                 break
  4008.             ;;
  4009.         esac;
  4010.         shift;
  4011.     done;
  4012.     if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
  4013.         die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4014.     fi;
  4015.     if [[ "$#" -eq 0 ]]; then
  4016.         die "${FUNCNAME}(): Missing files or directories";
  4017.     fi;
  4018.     if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
  4019.         while (($#)); do
  4020.             if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
  4021.                 die "${FUNCNAME}(): Invalid argument '$1'";
  4022.             else
  4023.                 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
  4024.                     die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories";
  4025.                 else
  4026.                     if [[ "$1" =~ ^/ ]]; then
  4027.                         if _python_package_supporting_installation_for_multiple_python_abis; then
  4028.                             if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
  4029.                                 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs";
  4030.                             fi;
  4031.                             if [[ "$1" != *\$* ]]; then
  4032.                                 die "${FUNCNAME}(): '$1' has invalid syntax";
  4033.                             fi;
  4034.                             for PYTHON_ABI in ${iterated_PYTHON_ABIS};
  4035.                             do
  4036.                                 eval "search_paths+=(\"\${root}$1\")";
  4037.                             done;
  4038.                         else
  4039.                             search_paths+=("${root}$1");
  4040.                         fi;
  4041.                     else
  4042.                         for PYTHON_ABI in ${iterated_PYTHON_ABIS};
  4043.                         do
  4044.                             search_paths+=("${root}$(python_get_sitedir)/$1");
  4045.                         done;
  4046.                     fi;
  4047.                 fi;
  4048.             fi;
  4049.             shift;
  4050.         done;
  4051.     else
  4052.         ewarn;
  4053.         ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation";
  4054.         ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-08-01.";
  4055.         ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax.";
  4056.         ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported.";
  4057.         ewarn;
  4058.         search_paths=("${@#/}");
  4059.         search_paths=("${search_paths[@]/#/${root}/}");
  4060.     fi;
  4061.     _python_clean_compiled_modules "${search_paths[@]}"
  4062. }
  4063. python_mod_optimize ()
  4064. {
  4065.     if [[ "${EBUILD_PHASE}" != "postinst" ]]; then
  4066.         die "${FUNCNAME}() can be used only in pkg_postinst() phase";
  4067.     fi;
  4068.     _python_check_python_pkg_setup_execution;
  4069.     _python_initialize_prefix_variables;
  4070.     if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
  4071.         local allow_evaluated_non_sitedir_paths="0" dir dirs=() evaluated_dirs=() evaluated_files=() file files=() iterated_PYTHON_ABIS options=() other_dirs=() other_files=() previous_PYTHON_ABI="${PYTHON_ABI}" return_code root site_packages_dirs=() site_packages_files=() stderr stderr_line;
  4072.         if _python_package_supporting_installation_for_multiple_python_abis; then
  4073.             if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
  4074.                 die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called";
  4075.             fi;
  4076.             iterated_PYTHON_ABIS="${PYTHON_ABIS}";
  4077.         else
  4078.             if has "${EAPI:-0}" 0 1 2 3; then
  4079.                 iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}";
  4080.             else
  4081.                 iterated_PYTHON_ABIS="${PYTHON_ABI}";
  4082.             fi;
  4083.         fi;
  4084.         root="${EROOT%/}";
  4085.         while (($#)); do
  4086.             case "$1" in
  4087.                 --allow-evaluated-non-sitedir-paths)
  4088.                     allow_evaluated_non_sitedir_paths="1"
  4089.                 ;;
  4090.                 -l | -f | -q)
  4091.                     options+=("$1")
  4092.                 ;;
  4093.                 -d | -x)
  4094.                     options+=("$1" "$2");
  4095.                     shift
  4096.                 ;;
  4097.                 --)
  4098.                     shift;
  4099.                     break
  4100.                 ;;
  4101.                 -*)
  4102.                     die "${FUNCNAME}(): Unrecognized option '$1'"
  4103.                 ;;
  4104.                 *)
  4105.                     break
  4106.                 ;;
  4107.             esac;
  4108.             shift;
  4109.         done;
  4110.         if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
  4111.             die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4112.         fi;
  4113.         if [[ "$#" -eq 0 ]]; then
  4114.             die "${FUNCNAME}(): Missing files or directories";
  4115.         fi;
  4116.         while (($#)); do
  4117.             if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
  4118.                 die "${FUNCNAME}(): Invalid argument '$1'";
  4119.             else
  4120.                 if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
  4121.                     die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories";
  4122.                 else
  4123.                     if [[ "$1" =~ ^/ ]]; then
  4124.                         if _python_package_supporting_installation_for_multiple_python_abis; then
  4125.                             if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
  4126.                                 die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs";
  4127.                             fi;
  4128.                             if [[ "$1" != *\$* ]]; then
  4129.                                 die "${FUNCNAME}(): '$1' has invalid syntax";
  4130.                             fi;
  4131.                             if [[ "$1" == *.py ]]; then
  4132.                                 evaluated_files+=("$1");
  4133.                             else
  4134.                                 evaluated_dirs+=("$1");
  4135.                             fi;
  4136.                         else
  4137.                             if [[ -d "${root}$1" ]]; then
  4138.                                 other_dirs+=("${root}$1");
  4139.                             else
  4140.                                 if [[ -f "${root}$1" ]]; then
  4141.                                     other_files+=("${root}$1");
  4142.                                 else
  4143.                                     if [[ -e "${root}$1" ]]; then
  4144.                                         eerror "${FUNCNAME}(): '${root}$1' is not a regular file or a directory";
  4145.                                     else
  4146.                                         eerror "${FUNCNAME}(): '${root}$1' does not exist";
  4147.                                     fi;
  4148.                                 fi;
  4149.                             fi;
  4150.                         fi;
  4151.                     else
  4152.                         for PYTHON_ABI in ${iterated_PYTHON_ABIS};
  4153.                         do
  4154.                             if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
  4155.                                 site_packages_dirs+=("$1");
  4156.                                 break;
  4157.                             else
  4158.                                 if [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
  4159.                                     site_packages_files+=("$1");
  4160.                                     break;
  4161.                                 else
  4162.                                     if [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
  4163.                                         eerror "${FUNCNAME}(): '$1' is not a regular file or a directory";
  4164.                                     else
  4165.                                         eerror "${FUNCNAME}(): '$1' does not exist";
  4166.                                     fi;
  4167.                                 fi;
  4168.                             fi;
  4169.                         done;
  4170.                     fi;
  4171.                 fi;
  4172.             fi;
  4173.             shift;
  4174.         done;
  4175.         options+=("-q");
  4176.         for PYTHON_ABI in ${iterated_PYTHON_ABIS};
  4177.         do
  4178.             if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})) || ((${#evaluated_dirs[@]})) || ((${#evaluated_files[@]})); then
  4179.                 return_code="0";
  4180.                 stderr="";
  4181.                 ebegin "Compilation and optimization of Python modules for $(python_get_implementation_and_version)";
  4182.                 if ((${#site_packages_dirs[@]})) || ((${#evaluated_dirs[@]})); then
  4183.                     for dir in "${site_packages_dirs[@]}";
  4184.                     do
  4185.                         dirs+=("${root}$(python_get_sitedir)/${dir}");
  4186.                     done;
  4187.                     for dir in "${evaluated_dirs[@]}";
  4188.                     do
  4189.                         eval "dirs+=(\"\${root}${dir}\")";
  4190.                     done;
  4191.                     stderr+="${stderr:+
  4192. }$("$(PYTHON)" -m compileall "${options[@]}" "${dirs[@]}" 2>&1)" || return_code="1";
  4193.                     if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
  4194.                         "$(PYTHON)" -O -m compileall "${options[@]}" "${dirs[@]}" &>/dev/null || return_code="1";
  4195.                     fi;
  4196.                     _python_clean_compiled_modules "${dirs[@]}";
  4197.                 fi;
  4198.                 if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then
  4199.                     for file in "${site_packages_files[@]}";
  4200.                     do
  4201.                         files+=("${root}$(python_get_sitedir)/${file}");
  4202.                     done;
  4203.                     for file in "${evaluated_files[@]}";
  4204.                     do
  4205.                         eval "files+=(\"\${root}${file}\")";
  4206.                     done;
  4207.                     stderr+="${stderr:+
  4208. }$("$(PYTHON)" -m py_compile "${files[@]}" 2>&1)" || return_code="1";
  4209.                     if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
  4210.                         "$(PYTHON)" -O -m py_compile "${files[@]}" &>/dev/null || return_code="1";
  4211.                     fi;
  4212.                     _python_clean_compiled_modules "${files[@]}";
  4213.                 fi;
  4214.                 eend "${return_code}";
  4215.                 if [[ -n "${stderr}" ]]; then
  4216.                     eerror "Syntax errors / warnings in Python modules for $(python_get_implementation_and_version):" &>/dev/null;
  4217.                     while read stderr_line; do
  4218.                         eerror "    ${stderr_line}";
  4219.                     done <<< "${stderr}";
  4220.                 fi;
  4221.             fi;
  4222.             unset dirs files;
  4223.         done;
  4224.         if _python_package_supporting_installation_for_multiple_python_abis; then
  4225.             if [[ -n "${previous_PYTHON_ABI}" ]]; then
  4226.                 PYTHON_ABI="${previous_PYTHON_ABI}";
  4227.             else
  4228.                 unset PYTHON_ABI;
  4229.             fi;
  4230.         fi;
  4231.         if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
  4232.             return_code="0";
  4233.             stderr="";
  4234.             ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation_and_version)";
  4235.             if ((${#other_dirs[@]})); then
  4236.                 stderr+="${stderr:+
  4237. }$("$(PYTHON ${PYTHON_ABI})" -m compileall "${options[@]}" "${other_dirs[@]}" 2>&1)" || return_code="1";
  4238.                 if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
  4239.                     "$(PYTHON ${PYTHON_ABI})" -O -m compileall "${options[@]}" "${other_dirs[@]}" &>/dev/null || return_code="1";
  4240.                 fi;
  4241.                 _python_clean_compiled_modules "${other_dirs[@]}";
  4242.             fi;
  4243.             if ((${#other_files[@]})); then
  4244.                 stderr+="${stderr:+
  4245. }$("$(PYTHON ${PYTHON_ABI})" -m py_compile "${other_files[@]}" 2>&1)" || return_code="1";
  4246.                 if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
  4247.                     "$(PYTHON ${PYTHON_ABI})" -O -m py_compile "${other_files[@]}" &>/dev/null || return_code="1";
  4248.                 fi;
  4249.                 _python_clean_compiled_modules "${other_files[@]}";
  4250.             fi;
  4251.             eend "${return_code}";
  4252.             if [[ -n "${stderr}" ]]; then
  4253.                 eerror "Syntax errors / warnings in Python modules placed outside of site-packages directories for $(python_get_implementation_and_version):" &>/dev/null;
  4254.                 while read stderr_line; do
  4255.                     eerror "    ${stderr_line}";
  4256.                 done <<< "${stderr}";
  4257.             fi;
  4258.         fi;
  4259.     else
  4260.         ewarn;
  4261.         ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation";
  4262.         ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-08-01.";
  4263.         ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax.";
  4264.         ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported.";
  4265.         ewarn;
  4266.         local myroot mydirs=() myfiles=() myopts=() return_code="0";
  4267.         myroot="${EROOT%/}";
  4268.         while (($#)); do
  4269.             case "$1" in
  4270.                 -l | -f | -q)
  4271.                     myopts+=("$1")
  4272.                 ;;
  4273.                 -d | -x)
  4274.                     myopts+=("$1" "$2");
  4275.                     shift
  4276.                 ;;
  4277.                 --)
  4278.                     shift;
  4279.                     break
  4280.                 ;;
  4281.                 -*)
  4282.                     die "${FUNCNAME}(): Unrecognized option '$1'"
  4283.                 ;;
  4284.                 *)
  4285.                     break
  4286.                 ;;
  4287.             esac;
  4288.             shift;
  4289.         done;
  4290.         if [[ "$#" -eq 0 ]]; then
  4291.             die "${FUNCNAME}(): Missing files or directories";
  4292.         fi;
  4293.         while (($#)); do
  4294.             if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
  4295.                 die "${FUNCNAME}(): Invalid argument '$1'";
  4296.             else
  4297.                 if [[ -d "${myroot}/${1#/}" ]]; then
  4298.                     mydirs+=("${myroot}/${1#/}");
  4299.                 else
  4300.                     if [[ -f "${myroot}/${1#/}" ]]; then
  4301.                         myfiles+=("${myroot}/${1#/}");
  4302.                     else
  4303.                         if [[ -e "${myroot}/${1#/}" ]]; then
  4304.                             eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory";
  4305.                         else
  4306.                             eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist";
  4307.                         fi;
  4308.                     fi;
  4309.                 fi;
  4310.             fi;
  4311.             shift;
  4312.         done;
  4313.         myopts+=(-q);
  4314.         PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  4315.         ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)";
  4316.         if ((${#mydirs[@]})); then
  4317.             "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1";
  4318.             "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &>/dev/null || return_code="1";
  4319.             _python_clean_compiled_modules "${mydirs[@]}";
  4320.         fi;
  4321.         if ((${#myfiles[@]})); then
  4322.             "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" || return_code="1";
  4323.             "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &>/dev/null || return_code="1";
  4324.             _python_clean_compiled_modules "${myfiles[@]}";
  4325.         fi;
  4326.         eend "${return_code}";
  4327.     fi
  4328. }
  4329. python_need_rebuild ()
  4330. {
  4331.     if _python_package_supporting_installation_for_multiple_python_abis; then
  4332.         die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs";
  4333.     fi;
  4334.     _python_check_python_pkg_setup_execution;
  4335.     if [[ "$#" -ne 0 ]]; then
  4336.         die "${FUNCNAME}() does not accept arguments";
  4337.     fi;
  4338.     export PYTHON_NEED_REBUILD="$(PYTHON --ABI)"
  4339. }
  4340. python_pkg_setup ()
  4341. {
  4342.     if [[ "${EBUILD_PHASE}" != "setup" ]]; then
  4343.         die "${FUNCNAME}() can be used only in pkg_setup() phase";
  4344.     fi;
  4345.     if [[ "$#" -ne 0 ]]; then
  4346.         die "${FUNCNAME}() does not accept arguments";
  4347.     fi;
  4348.     export JYTHON_SYSTEM_CACHEDIR="1";
  4349.     addwrite "${EPREFIX}/var/cache/jython";
  4350.     if _python_package_supporting_installation_for_multiple_python_abis; then
  4351.         _python_calculate_PYTHON_ABIS;
  4352.         export EPYTHON="$(PYTHON -f)";
  4353.     else
  4354.         PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  4355.     fi;
  4356.     if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then
  4357.         if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
  4358.             if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then
  4359.                 use ${PYTHON_USE_WITH_OPT#!} && return;
  4360.             else
  4361.                 use !${PYTHON_USE_WITH_OPT} && return;
  4362.             fi;
  4363.         fi;
  4364.         function python_pkg_setup_check_USE_flags ()
  4365.         {
  4366.             local python_atom USE_flag;
  4367.             python_atom="$(python_get_implementational_package)";
  4368.             for USE_flag in ${PYTHON_USE_WITH};
  4369.             do
  4370.                 if ! has_version "${python_atom}[${USE_flag}]"; then
  4371.                     eerror "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}";
  4372.                     die "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}";
  4373.                 fi;
  4374.             done;
  4375.             for USE_flag in ${PYTHON_USE_WITH_OR};
  4376.             do
  4377.                 if has_version "${python_atom}[${USE_flag}]"; then
  4378.                     return;
  4379.                 fi;
  4380.             done;
  4381.             if [[ -n ${PYTHON_USE_WITH_OR} ]]; then
  4382.                 eerror "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}";
  4383.                 die "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}";
  4384.             fi
  4385.         };
  4386.         if _python_package_supporting_installation_for_multiple_python_abis; then
  4387.             PYTHON_SKIP_SANITY_CHECKS="1" python_execute_function -q python_pkg_setup_check_USE_flags;
  4388.         else
  4389.             python_pkg_setup_check_USE_flags;
  4390.         fi;
  4391.         unset -f python_pkg_setup_check_USE_flags;
  4392.     fi;
  4393.     PYTHON_PKG_SETUP_EXECUTED="1"
  4394. }
  4395. python_set_active_version ()
  4396. {
  4397.     if [[ "${EBUILD_PHASE}" != "setup" ]]; then
  4398.         die "${FUNCNAME}() can be used only in pkg_setup() phase";
  4399.     fi;
  4400.     if _python_package_supporting_installation_for_multiple_python_abis; then
  4401.         die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs";
  4402.     fi;
  4403.     if [[ "$#" -ne 1 ]]; then
  4404.         die "${FUNCNAME}() requires 1 argument";
  4405.     fi;
  4406.     _python_initial_sanity_checks;
  4407.     if [[ -z "${PYTHON_ABI}" ]]; then
  4408.         if [[ -n "$(_python_get_implementation --ignore-invalid "$1")" ]]; then
  4409.             PYTHON_ABI="$1";
  4410.             if ! _python_implementation && ! has_version "$(python_get_implementational_package)"; then
  4411.                 die "${FUNCNAME}(): '$(python_get_implementational_package)' is not installed";
  4412.             fi;
  4413.             export EPYTHON="$(PYTHON "$1")";
  4414.         else
  4415.             if [[ "$1" == "2" ]]; then
  4416.                 if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then
  4417.                     die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed";
  4418.                 fi;
  4419.                 export EPYTHON="$(PYTHON -2)";
  4420.                 PYTHON_ABI="${EPYTHON#python}";
  4421.                 PYTHON_ABI="${PYTHON_ABI%%-*}";
  4422.             else
  4423.                 if [[ "$1" == "3" ]]; then
  4424.                     if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then
  4425.                         die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed";
  4426.                     fi;
  4427.                     export EPYTHON="$(PYTHON -3)";
  4428.                     PYTHON_ABI="${EPYTHON#python}";
  4429.                     PYTHON_ABI="${PYTHON_ABI%%-*}";
  4430.                 else
  4431.                     die "${FUNCNAME}(): Unrecognized argument '$1'";
  4432.                 fi;
  4433.             fi;
  4434.         fi;
  4435.     fi;
  4436.     _python_final_sanity_checks;
  4437.     PYTHON_REQUESTED_ACTIVE_VERSION="$1"
  4438. }
  4439. python_src_compile ()
  4440. {
  4441.     if [[ "${EBUILD_PHASE}" != "compile" ]]; then
  4442.         die "${FUNCNAME}() can be used only in src_compile() phase";
  4443.     fi;
  4444.     if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4445.         die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4446.     fi;
  4447.     _python_check_python_pkg_setup_execution;
  4448.     python_execute_function -d -s -- "$@"
  4449. }
  4450. python_src_configure ()
  4451. {
  4452.     if [[ "${EBUILD_PHASE}" != "configure" ]]; then
  4453.         die "${FUNCNAME}() can be used only in src_configure() phase";
  4454.     fi;
  4455.     if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4456.         die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4457.     fi;
  4458.     _python_check_python_pkg_setup_execution;
  4459.     python_execute_function -d -s -- "$@"
  4460. }
  4461. python_src_install ()
  4462. {
  4463.     if [[ "${EBUILD_PHASE}" != "install" ]]; then
  4464.         die "${FUNCNAME}() can be used only in src_install() phase";
  4465.     fi;
  4466.     if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4467.         die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4468.     fi;
  4469.     _python_check_python_pkg_setup_execution;
  4470.     if has "${EAPI:-0}" 0 1 2 3; then
  4471.         python_execute_function -d -s -- "$@";
  4472.     else
  4473.         function python_installation ()
  4474.         {
  4475.             emake DESTDIR="${T}/images/${PYTHON_ABI}" install "$@"
  4476.         };
  4477.         python_execute_function -s python_installation "$@";
  4478.         unset python_installation;
  4479.         python_merge_intermediate_installation_images "${T}/images";
  4480.     fi
  4481. }
  4482. python_src_prepare ()
  4483. {
  4484.     if [[ "${EBUILD_PHASE}" != "prepare" ]]; then
  4485.         die "${FUNCNAME}() can be used only in src_prepare() phase";
  4486.     fi;
  4487.     if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4488.         die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4489.     fi;
  4490.     _python_check_python_pkg_setup_execution;
  4491.     if [[ "$#" -ne 0 ]]; then
  4492.         die "${FUNCNAME}() does not accept arguments";
  4493.     fi;
  4494.     python_copy_sources
  4495. }
  4496. python_src_test ()
  4497. {
  4498.     if [[ "${EBUILD_PHASE}" != "test" ]]; then
  4499.         die "${FUNCNAME}() can be used only in src_test() phase";
  4500.     fi;
  4501.     if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4502.         die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4503.     fi;
  4504.     _python_check_python_pkg_setup_execution;
  4505.     python_execute_function -d -s -- "$@"
  4506. }
  4507. scons_clean_makeopts ()
  4508. {
  4509.     local new_makeopts;
  4510.     debug-print-function ${FUNCNAME} "${@}";
  4511.     if [[ ${#} -eq 0 ]]; then
  4512.         debug-print "Using MAKEOPTS: [${MAKEOPTS}]";
  4513.         set -- ${MAKEOPTS};
  4514.     else
  4515.         set -- ${*};
  4516.     fi;
  4517.     if [[ ${*} = ${_SCONS_CACHE_MAKEOPTS} ]]; then
  4518.         set -- ${_SCONS_CACHE_SCONSOPTS};
  4519.         debug-print "Cache hit: [${*}]";
  4520.         echo ${*};
  4521.         return;
  4522.     fi;
  4523.     export _SCONS_CACHE_MAKEOPTS=${*};
  4524.     while [[ ${#} -gt 0 ]]; do
  4525.         case ${1} in
  4526.             --jobs=* | --keep-going)
  4527.                 new_makeopts=${new_makeopts+${new_makeopts} }${1}
  4528.             ;;
  4529.             --jobs)
  4530.                 if [[ ${#} -gt 1 && ${2} =~ ^[0-9]+$ ]]; then
  4531.                     new_makeopts="${new_makeopts+${new_makeopts} }${1} ${2}";
  4532.                     shift;
  4533.                 else
  4534.                     new_makeopts=${new_makeopts+${new_makeopts} }${1}=5;
  4535.                 fi
  4536.             ;;
  4537.             --*)
  4538.  
  4539.             ;;
  4540.             -*)
  4541.                 local str new_optstr;
  4542.                 new_optstr=;
  4543.                 str=${1#-};
  4544.                 while [[ -n ${str} ]]; do
  4545.                     case ${str} in
  4546.                         k*)
  4547.                             new_optstr=${new_optstr}k
  4548.                         ;;
  4549.                         j)
  4550.                             if [[ ${#} -gt 1 && ${2} =~ ^[0-9]+$ ]]; then
  4551.                                 new_optstr="${new_optstr}j ${2}";
  4552.                                 shift;
  4553.                             else
  4554.                                 new_optstr="${new_optstr}j 5";
  4555.                             fi
  4556.                         ;;
  4557.                         j*)
  4558.                             new_optstr=${new_optstr}${str};
  4559.                             break
  4560.                         ;;
  4561.                     esac;
  4562.                     str=${str#?};
  4563.                 done;
  4564.                 if [[ -n ${new_optstr} ]]; then
  4565.                     new_makeopts=${new_makeopts+${new_makeopts} }-${new_optstr};
  4566.                 fi
  4567.             ;;
  4568.         esac;
  4569.         shift;
  4570.     done;
  4571.     set -- ${new_makeopts};
  4572.     export _SCONS_CACHE_SCONSOPTS=${*};
  4573.     debug-print "New SCONSOPTS: [${*}]";
  4574.     echo ${*}
  4575. }
  4576. src_compile ()
  4577. {
  4578.     escons || die '!!! Please add "${S}/scons.config" when filing bugs reports \
  4579.         to bugs.gentoo.org';
  4580.     cd "${WORKDIR}"/install/linux2/plugins;
  4581.     chmod 755 bmake;
  4582.     emake || die
  4583. }
  4584. src_configure ()
  4585. {
  4586.     cat >> "${S}"/user-config.py  <<-EOF
  4587. BF_FFMPEG="/usr"
  4588. BF_FFMPEG_LIB="avdevice avformat avcodec swscale avutil"
  4589. EOF
  4590.  
  4591.     cat >> "${S}"/user-config.py  <<-EOF
  4592. BF_PYTHON_VERSION="$(python_get_version)"
  4593. BF_PYTHON_INC="$(python_get_includedir)"
  4594. BF_PYTHON_BINARY="$(PYTHON -a)"
  4595. BF_PYTHON_LIB="python$(python_get_version)"
  4596. EOF
  4597.  
  4598.     cat >> "${S}"/user-config.py  <<-EOF
  4599. BF_OPENJPEG = "/usr"
  4600. BF_OPENJPEG_INC = "/usr/include"
  4601. BF_OPENJPEG_LIB = "openjpeg"
  4602. EOF
  4603.  
  4604.     echo "CFLAGS= [`for i in ${CFLAGS[@]}; do printf "%s \'$i"\',; done`] " | sed -e "s:,]: ]:" >> "${S}"/user-config.py;
  4605.     echo "CXXFLAGS= [`for i in ${CFLAGS[@]}; do printf "%s \'$i"\',; done`]" | sed -e "s:,]: ]:" >> "${S}"/user-config.py;
  4606.     for arg in 'openal' 'ffmpeg' 'blender-game player' 'blender-game gameengine' 'nls international' 'ogg' 'openmp' 'verse';
  4607.     do
  4608.         blend_with ${arg};
  4609.     done
  4610. }
  4611. src_install ()
  4612. {
  4613.     exeinto /usr/bin/;
  4614.     doexe "${WORKDIR}"/install/linux2/blender;
  4615.     use blender-game && doexe "${WORKDIR}"/install/linux2/blenderplayer;
  4616.     dodir /usr/share/${PN};
  4617.     exeinto /usr/$(get_libdir)/${PN}/textures;
  4618.     doexe "${WORKDIR}"/install/linux2/plugins/texture/*.so;
  4619.     exeinto /usr/$(get_libdir)/${PN}/sequences;
  4620.     doexe "${WORKDIR}"/install/linux2/plugins/sequence/*.so;
  4621.     insinto /usr/include/${PN};
  4622.     doins "${WORKDIR}"/install/linux2/plugins/include/*.h;
  4623.     if use nls; then
  4624.         mv "${WORKDIR}"/install/linux2/.blender/{.Blanguages,.bfont.ttf} "${D}"/usr/share/${PN};
  4625.         mv "${WORKDIR}"/install/linux2/.blender/locale "${D}"/usr/share/locale;
  4626.     fi;
  4627.     mv "${WORKDIR}"/install/linux2/.blender/scripts "${D}"/usr/share/${PN};
  4628.     insinto /usr/share/pixmaps;
  4629.     doins "${WORKDIR}"/install/linux2/icons/scalable/blender.svg;
  4630.     insinto /usr/share/applications;
  4631.     doins "${FILESDIR}"/${PN}.desktop || die;
  4632.     doins "${FILESDIR}"/${P}-insecure.desktop || die;
  4633.     dodoc INSTALL README;
  4634.     dodoc "${WORKDIR}"/install/linux2/BlenderQuickStart.pdf
  4635. }
  4636. src_prepare ()
  4637. {
  4638.     epatch "${FILESDIR}"/blender-2.48a-CVE-2008-4863.patch;
  4639.     epatch "${FILESDIR}"/${PN}-2.37-dirs.patch;
  4640.     epatch "${FILESDIR}"/${PN}-2.44-scriptsdir.patch;
  4641.     epatch "${FILESDIR}"/${PN}-2.49a-sys-openjpeg.patch;
  4642.     epatch "${FILESDIR}"/${PN}-2.49b-CVE-2009-3850-v4.patch;
  4643.     epatch "${FILESDIR}"/${PN}-2.57-linux-3.patch;
  4644.     epatch "${FILESDIR}"/${PN}-2.49b-subversion-1.7.patch;
  4645.     epatch "${FILESDIR}"/${P}-libav-0.7.patch;
  4646.     rm -f "${S}/release/scripts/bpymodules/"*.pyc;
  4647.     sed -i -e '/parameters.*tile_size_on/s:false:FALSE:' source/blender/imbuf/intern/jp2.c || die
  4648. }
  4649. src_test ()
  4650. {
  4651.     _eapi0_src_test "$@"
  4652. }
  4653. src_unpack ()
  4654. {
  4655.     _eapi0_src_unpack "$@"
  4656. }
  4657. strip-linguas ()
  4658. {
  4659.     local ls newls nols;
  4660.     if [[ $1 == "-i" ]] || [[ $1 == "-u" ]]; then
  4661.         local op=$1;
  4662.         shift;
  4663.         ls=$(find "$1" -name '*.po' -exec basename {} .po ';');
  4664.         shift;
  4665.         local d f;
  4666.         for d in "$@";
  4667.         do
  4668.             if [[ ${op} == "-u" ]]; then
  4669.                 newls=${ls};
  4670.             else
  4671.                 newls="";
  4672.             fi;
  4673.             for f in $(find "$d" -name '*.po' -exec basename {} .po ';');
  4674.             do
  4675.                 if [[ ${op} == "-i" ]]; then
  4676.                     has ${f} ${ls} && newls="${newls} ${f}";
  4677.                 else
  4678.                     has ${f} ${ls} || newls="${newls} ${f}";
  4679.                 fi;
  4680.             done;
  4681.             ls=${newls};
  4682.         done;
  4683.     else
  4684.         ls="$@";
  4685.     fi;
  4686.     nols="";
  4687.     newls="";
  4688.     for f in ${LINGUAS};
  4689.     do
  4690.         if has ${f} ${ls}; then
  4691.             newls="${newls} ${f}";
  4692.         else
  4693.             nols="${nols} ${f}";
  4694.         fi;
  4695.     done;
  4696.     [[ -n ${nols} ]] && einfo "Sorry, but ${PN} does not support the LINGUAS:" ${nols};
  4697.     export LINGUAS=${newls:1}
  4698. }
  4699. tc-arch ()
  4700. {
  4701.     tc-ninja_magic_to_arch portage "$@"
  4702. }
  4703. tc-arch-kernel ()
  4704. {
  4705.     tc-ninja_magic_to_arch kern "$@"
  4706. }
  4707. tc-endian ()
  4708. {
  4709.     local host=$1;
  4710.     [[ -z ${host} ]] && host=${CTARGET:-${CHOST}};
  4711.     host=${host%%-*};
  4712.     case ${host} in
  4713.         alpha*)
  4714.             echo big
  4715.         ;;
  4716.         arm*b*)
  4717.             echo big
  4718.         ;;
  4719.         arm*)
  4720.             echo little
  4721.         ;;
  4722.         cris*)
  4723.             echo little
  4724.         ;;
  4725.         hppa*)
  4726.             echo big
  4727.         ;;
  4728.         i?86*)
  4729.             echo little
  4730.         ;;
  4731.         ia64*)
  4732.             echo little
  4733.         ;;
  4734.         m68*)
  4735.             echo big
  4736.         ;;
  4737.         mips*l*)
  4738.             echo little
  4739.         ;;
  4740.         mips*)
  4741.             echo big
  4742.         ;;
  4743.         powerpc*)
  4744.             echo big
  4745.         ;;
  4746.         s390*)
  4747.             echo big
  4748.         ;;
  4749.         sh*b*)
  4750.             echo big
  4751.         ;;
  4752.         sh*)
  4753.             echo little
  4754.         ;;
  4755.         sparc*)
  4756.             echo big
  4757.         ;;
  4758.         x86_64*)
  4759.             echo little
  4760.         ;;
  4761.         *)
  4762.             echo wtf
  4763.         ;;
  4764.     esac
  4765. }
  4766. tc-env_build ()
  4767. {
  4768.     CFLAGS=${BUILD_CFLAGS:--O1 -pipe} CXXFLAGS=${BUILD_CXXFLAGS:--O1 -pipe} 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) "$@"
  4769. }
  4770. tc-export ()
  4771. {
  4772.     local var;
  4773.     for var in "$@";
  4774.     do
  4775.         [[ $(type -t tc-get${var}) != "function" ]] && die "tc-export: invalid export variable '${var}'";
  4776.         eval tc-get${var} > /dev/null;
  4777.     done
  4778. }
  4779. tc-getAR ()
  4780. {
  4781.     tc-getPROG AR ar "$@"
  4782. }
  4783. tc-getAS ()
  4784. {
  4785.     tc-getPROG AS as "$@"
  4786. }
  4787. tc-getBUILD_AR ()
  4788. {
  4789.     tc-getBUILD_PROG AR ar "$@"
  4790. }
  4791. tc-getBUILD_AS ()
  4792. {
  4793.     tc-getBUILD_PROG AS as "$@"
  4794. }
  4795. tc-getBUILD_CC ()
  4796. {
  4797.     tc-getBUILD_PROG CC gcc "$@"
  4798. }
  4799. tc-getBUILD_CPP ()
  4800. {
  4801.     tc-getBUILD_PROG CPP cpp "$@"
  4802. }
  4803. tc-getBUILD_CXX ()
  4804. {
  4805.     tc-getBUILD_PROG CXX g++ "$@"
  4806. }
  4807. tc-getBUILD_LD ()
  4808. {
  4809.     tc-getBUILD_PROG LD ld "$@"
  4810. }
  4811. tc-getBUILD_NM ()
  4812. {
  4813.     tc-getBUILD_PROG NM nm "$@"
  4814. }
  4815. tc-getBUILD_OBJCOPY ()
  4816. {
  4817.     tc-getBUILD_PROG OBJCOPY objcopy "$@"
  4818. }
  4819. tc-getBUILD_PKG_CONFIG ()
  4820. {
  4821.     tc-getBUILD_PROG PKG_CONFIG pkg-config "$@"
  4822. }
  4823. tc-getBUILD_PROG ()
  4824. {
  4825.     _tc-getPROG CBUILD "BUILD_$1 $1_FOR_BUILD HOST$1" "${@:2}"
  4826. }
  4827. tc-getBUILD_RANLIB ()
  4828. {
  4829.     tc-getBUILD_PROG RANLIB ranlib "$@"
  4830. }
  4831. tc-getBUILD_STRIP ()
  4832. {
  4833.     tc-getBUILD_PROG STRIP strip "$@"
  4834. }
  4835. tc-getCC ()
  4836. {
  4837.     tc-getPROG CC gcc "$@"
  4838. }
  4839. tc-getCPP ()
  4840. {
  4841.     tc-getPROG CPP cpp "$@"
  4842. }
  4843. tc-getCXX ()
  4844. {
  4845.     tc-getPROG CXX g++ "$@"
  4846. }
  4847. tc-getDLLWRAP ()
  4848. {
  4849.     tc-getPROG DLLWRAP dllwrap "$@"
  4850. }
  4851. tc-getF77 ()
  4852. {
  4853.     tc-getPROG F77 gfortran "$@"
  4854. }
  4855. tc-getFC ()
  4856. {
  4857.     tc-getPROG FC gfortran "$@"
  4858. }
  4859. tc-getGCJ ()
  4860. {
  4861.     tc-getPROG GCJ gcj "$@"
  4862. }
  4863. tc-getLD ()
  4864. {
  4865.     tc-getPROG LD ld "$@"
  4866. }
  4867. tc-getNM ()
  4868. {
  4869.     tc-getPROG NM nm "$@"
  4870. }
  4871. tc-getOBJCOPY ()
  4872. {
  4873.     tc-getPROG OBJCOPY objcopy "$@"
  4874. }
  4875. tc-getPKG_CONFIG ()
  4876. {
  4877.     tc-getPROG PKG_CONFIG pkg-config "$@"
  4878. }
  4879. tc-getPROG ()
  4880. {
  4881.     _tc-getPROG CHOST "$@"
  4882. }
  4883. tc-getRANLIB ()
  4884. {
  4885.     tc-getPROG RANLIB ranlib "$@"
  4886. }
  4887. tc-getRC ()
  4888. {
  4889.     tc-getPROG RC windres "$@"
  4890. }
  4891. tc-getSTRIP ()
  4892. {
  4893.     tc-getPROG STRIP strip "$@"
  4894. }
  4895. tc-has-openmp ()
  4896. {
  4897.     local base="${T}/test-tc-openmp";
  4898.     cat > "${base}.c"  <<-EOF
  4899. #include <omp.h>
  4900. int main() {
  4901. int nthreads, tid, ret = 0;
  4902. #pragma omp parallel private(nthreads, tid)
  4903. {
  4904. tid = omp_get_thread_num();
  4905. nthreads = omp_get_num_threads(); ret += tid + nthreads;
  4906. }
  4907. return ret;
  4908. }
  4909. EOF
  4910.  
  4911.     $(tc-getCC "$@") -fopenmp "${base}.c" -o "${base}" &>/dev/null;
  4912.     local ret=$?;
  4913.     rm -f "${base}"*;
  4914.     return ${ret}
  4915. }
  4916. tc-has-tls ()
  4917. {
  4918.     local base="${T}/test-tc-tls";
  4919.     cat > "${base}.c"  <<-EOF
  4920. int foo(int *i) {
  4921. static __thread int j = 0;
  4922. return *i ? j : *i;
  4923. }
  4924. EOF
  4925.  
  4926.     local flags;
  4927.     case $1 in
  4928.         -s)
  4929.             flags="-S"
  4930.         ;;
  4931.         -c)
  4932.             flags="-c"
  4933.         ;;
  4934.         -l)
  4935.  
  4936.         ;;
  4937.         -*)
  4938.             die "Usage: tc-has-tls [-c|-l] [toolchain prefix]"
  4939.         ;;
  4940.     esac;
  4941.     : ${flags:=-fPIC -shared -Wl,-z,defs};
  4942.     [[ $1 == -* ]] && shift;
  4943.     $(tc-getCC "$@") ${flags} "${base}.c" -o "${base}" &>/dev/null;
  4944.     local ret=$?;
  4945.     rm -f "${base}"*;
  4946.     return ${ret}
  4947. }
  4948. tc-is-cross-compiler ()
  4949. {
  4950.     return $([[ ${CBUILD:-${CHOST}} != ${CHOST} ]])
  4951. }
  4952. tc-is-hardfloat ()
  4953. {
  4954.     [[ ${CTARGET//_/-} == *-hardfloat-* ]] && echo "yes" || echo "no"
  4955. }
  4956. tc-is-softfloat ()
  4957. {
  4958.     local CTARGET=${CTARGET:-${CHOST}};
  4959.     case ${CTARGET} in
  4960.         bfin* | h8300*)
  4961.             echo "only"
  4962.         ;;
  4963.         *)
  4964.             [[ ${CTARGET//_/-} == *-softfloat-* ]] && echo "yes" || echo "no"
  4965.         ;;
  4966.     esac
  4967. }
  4968. tc-is-static-only ()
  4969. {
  4970.     local host=${CTARGET:-${CHOST}};
  4971.     return $([[ ${host} == *-mint* ]])
  4972. }
  4973. tc-ninja_magic_to_arch ()
  4974. {
  4975.     function ninj ()
  4976.     {
  4977.         [[ ${type} == "kern" ]] && echo $1 || echo $2
  4978.     };
  4979.     local type=$1;
  4980.     local host=$2;
  4981.     [[ -z ${host} ]] && host=${CTARGET:-${CHOST}};
  4982.     case ${host} in
  4983.         alpha*)
  4984.             echo alpha
  4985.         ;;
  4986.         arm*)
  4987.             echo arm
  4988.         ;;
  4989.         avr*)
  4990.             ninj avr32 avr
  4991.         ;;
  4992.         bfin*)
  4993.             ninj blackfin bfin
  4994.         ;;
  4995.         cris*)
  4996.             echo cris
  4997.         ;;
  4998.         hppa*)
  4999.             ninj parisc hppa
  5000.         ;;
  5001.         i?86*)
  5002.             if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -lt $(KV_to_int 2.6.24) || ${host} == *freebsd* ]]; then
  5003.                 echo i386;
  5004.             else
  5005.                 echo x86;
  5006.             fi
  5007.         ;;
  5008.         ia64*)
  5009.             echo ia64
  5010.         ;;
  5011.         m68*)
  5012.             echo m68k
  5013.         ;;
  5014.         mips*)
  5015.             echo mips
  5016.         ;;
  5017.         nios2*)
  5018.             echo nios2
  5019.         ;;
  5020.         nios*)
  5021.             echo nios
  5022.         ;;
  5023.         powerpc*)
  5024.             if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]]; then
  5025.                 echo powerpc;
  5026.             else
  5027.                 if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -eq $(KV_to_int 2.6.15) ]]; then
  5028.                     if [[ ${host} == powerpc64* ]] || [[ ${PROFILE_ARCH} == "ppc64" ]]; then
  5029.                         echo powerpc;
  5030.                     else
  5031.                         echo ppc;
  5032.                     fi;
  5033.                 else
  5034.                     if [[ ${host} == powerpc64* ]]; then
  5035.                         echo ppc64;
  5036.                     else
  5037.                         if [[ ${PROFILE_ARCH} == "ppc64" ]]; then
  5038.                             ninj ppc64 ppc;
  5039.                         else
  5040.                             echo ppc;
  5041.                         fi;
  5042.                     fi;
  5043.                 fi;
  5044.             fi
  5045.         ;;
  5046.         s390*)
  5047.             echo s390
  5048.         ;;
  5049.         sh64*)
  5050.             ninj sh64 sh
  5051.         ;;
  5052.         sh*)
  5053.             echo sh
  5054.         ;;
  5055.         sparc64*)
  5056.             ninj sparc64 sparc
  5057.         ;;
  5058.         sparc*)
  5059.             [[ ${PROFILE_ARCH} == "sparc64" ]] && ninj sparc64 sparc || echo sparc
  5060.         ;;
  5061.         vax*)
  5062.             echo vax
  5063.         ;;
  5064.         x86_64*freebsd*)
  5065.             echo amd64
  5066.         ;;
  5067.         x86_64*)
  5068.             if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.24) ]]; then
  5069.                 echo x86;
  5070.             else
  5071.                 ninj x86_64 amd64;
  5072.             fi
  5073.         ;;
  5074.         *)
  5075.             echo unknown
  5076.         ;;
  5077.     esac
  5078. }
  5079. use_if_iuse ()
  5080. {
  5081.     in_iuse $1 || return 1;
  5082.     use $1
  5083. }
  5084. use_scons ()
  5085. {
  5086.     local flag=${1};
  5087.     local varname=${2:-${flag/\!/no}};
  5088.     local vartrue=${3:-${USE_SCONS_TRUE}};
  5089.     local varfalse=${4:-${USE_SCONS_FALSE}};
  5090.     debug-print-function ${FUNCNAME} "${@}";
  5091.     if [[ ${#} -eq 0 ]]; then
  5092.         eerror "Usage: scons-use <use-flag> [var-name] [var-opt-true] [var-opt-false]";
  5093.         die 'scons-use(): not enough arguments';
  5094.     fi;
  5095.     if use "${flag}"; then
  5096.         echo "${varname}=${vartrue}";
  5097.     else
  5098.         echo "${varname}=${varfalse}";
  5099.     fi
  5100. }
  5101. usex ()
  5102. {
  5103.     use "$1" && echo "${2-yes}$4" || echo "${3-no}$5"
  5104. }
  5105. validate_desktop_entries ()
  5106. {
  5107.     if [[ -x /usr/bin/desktop-file-validate ]]; then
  5108.         einfo "Checking desktop entry validity";
  5109.         local directories="";
  5110.         for d in /usr/share/applications $@;
  5111.         do
  5112.             [[ -d ${D}${d} ]] && directories="${directories} ${D}${d}";
  5113.         done;
  5114.         if [[ -n ${directories} ]]; then
  5115.             for FILE in $(find ${directories} -name "*\.desktop"                                                        -not -path '*.hidden*' | sort -u 2>/dev/null);
  5116.             do
  5117.                 local temp=$(desktop-file-validate ${FILE} | grep -v "warning:" |                                                               sed -e "s|error: ||" -e "s|${FILE}:|--|g" );
  5118.                 [[ -n $temp ]] && elog ${temp/--/${FILE/${D}/}:};
  5119.             done;
  5120.         fi;
  5121.         echo "";
  5122.     else
  5123.         einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo.";
  5124.     fi
  5125. }