Advertisement
Guest User

/var/tmp/portage/net-dns/avahi-0.6.30-r2/temp/environment

a guest
Jan 1st, 2012
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 229.02 KB | None | 0 0
  1. declare -x ABI="amd64"
  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 ANT_HOME="/usr/share/ant"
  5. 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"
  6. declare -x ARCH="amd64"
  7. declare -- AT_M4DIR=""
  8. declare -- AT_SYS_M4DIR=""
  9. declare -- AUTOTOOLS_AUTO_DEPEND="yes"
  10. declare -- AUTOTOOLS_DEPEND="|| ( =sys-devel/automake-1.11* ) >=sys-devel/autoconf-2.61 sys-devel/libtool"
  11. declare -x BOOTSTRAP_USE="cxx unicode multilib"
  12. declare -x CALLIGRA_FEATURES="kexi words flow plan stage tables krita karbon braindump"
  13. declare -x CAMERAS="canon"
  14. declare -x CBUILD="x86_64-pc-linux-gnu"
  15. declare -x CFLAGS="-march=core2 -O2 -pipe"
  16. declare -x CFLAGS_amd64="-m64"
  17. declare -x CFLAGS_default
  18. declare -x CFLAGS_x32="-mx32"
  19. declare -x CFLAGS_x86="-m32"
  20. declare -x CG_COMPILER_EXE="/opt/bin/cgc"
  21. declare -x CHOST="x86_64-pc-linux-gnu"
  22. declare -x CHOST_amd64="x86_64-pc-linux-gnu"
  23. declare -x CHOST_default="x86_64-pc-linux-gnu"
  24. declare -x CHOST_x32="x86_64-pc-linux-gnu"
  25. declare -x CHOST_x86="i686-pc-linux-gnu"
  26. declare -x COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog"
  27. declare -- COMMON_DEPEND=">=dev-libs/libdaemon-0.14
  28. dev-libs/expat
  29. dev-libs/glib:2
  30. gdbm? ( sys-libs/gdbm )
  31. qt4? ( x11-libs/qt-core:4 )
  32. gtk? ( >=x11-libs/gtk+-2.14.0:2 )
  33. gtk3? ( x11-libs/gtk+:3 )
  34. dbus? (
  35. >=sys-apps/dbus-0.30
  36. python? ( dev-python/dbus-python )
  37. )
  38. mono? (
  39. >=dev-lang/mono-1.1.10
  40. gtk? ( >=dev-dotnet/gtk-sharp-2 )
  41. )
  42. howl-compat? ( >=sys-apps/dbus-0.30 )
  43. introspection? ( >=dev-libs/gobject-introspection-0.9.5 )
  44. mdnsresponder-compat? ( >=sys-apps/dbus-0.30 )
  45. python? (
  46. gtk? ( >=dev-python/pygtk-2 )
  47. )
  48. bookmarks? (
  49. dev-python/twisted
  50. dev-python/twisted-web
  51. )
  52. kernel_linux? ( sys-libs/libcap )"
  53. declare -x CROSSCOMPILE_OPTS=""
  54. declare -x CTARGET_default="x86_64-pc-linux-gnu"
  55. declare -x CXXFLAGS="-march=core2 -O2 -pipe"
  56. declare -- DBUS_DEPEND=">=sys-apps/dbus-0.30"
  57. declare -x DEFAULT_ABI="amd64"
  58. declare -x DEFINED_PHASES=" compile configure install postinst postrm preinst prepare setup"
  59. declare DEPEND=">=dev-libs/libdaemon-0.14
  60. dev-libs/expat
  61. dev-libs/glib:2
  62. gdbm? ( sys-libs/gdbm )
  63. qt4? ( x11-libs/qt-core:4 )
  64. gtk? ( >=x11-libs/gtk+-2.14.0:2 )
  65. gtk3? ( x11-libs/gtk+:3 )
  66. dbus? (
  67. >=sys-apps/dbus-0.30
  68. python? ( dev-python/dbus-python )
  69. )
  70. mono? (
  71. >=dev-lang/mono-1.1.10
  72. gtk? ( >=dev-dotnet/gtk-sharp-2 )
  73. )
  74. howl-compat? ( >=sys-apps/dbus-0.30 )
  75. introspection? ( >=dev-libs/gobject-introspection-0.9.5 )
  76. mdnsresponder-compat? ( >=sys-apps/dbus-0.30 )
  77. python? (
  78. gtk? ( >=dev-python/pygtk-2 )
  79. )
  80. bookmarks? (
  81. dev-python/twisted
  82. dev-python/twisted-web
  83. )
  84. kernel_linux? ( sys-libs/libcap )
  85. >=dev-util/intltool-0.40.5
  86. >=dev-util/pkgconfig-0.9.0
  87. doc? (
  88. app-doc/doxygen
  89. mono? ( >=virtual/monodoc-1.1.8 )
  90. ) || ( =sys-devel/automake-1.11* ) >=sys-devel/autoconf-2.61 sys-devel/libtool >=app-admin/eselect-python-20091230 python? ( =dev-lang/python-2* ) python? ( =dev-lang/python-2*[gdbm] )"
  91. declare DESCRIPTION="System which facilitates service discovery on a local network"
  92. declare -x DESTTREE="/usr"
  93. declare -x DIROPTIONS="-m0755"
  94. declare -x EAPI="3"
  95. declare -- ECLASSDIR_LOCAL="/usr/portage/eclass"
  96. declare -x ELIBC="glibc"
  97. declare -- EPATCH_EXCLUDE=""
  98. declare -- EPATCH_FORCE="no"
  99. declare -- EPATCH_MULTI_MSG="Applying various patches (bugfixes/updates) ..."
  100. declare -- EPATCH_OPTS="-g0 -E --no-backup-if-mismatch"
  101. declare -- EPATCH_SINGLE_MSG=""
  102. declare -- EPATCH_SOURCE="/var/tmp/portage/net-dns/avahi-0.6.30-r2/work/patch"
  103. declare -- EPATCH_SUFFIX="patch.bz2"
  104. declare -x EXEOPTIONS="-m0755"
  105. declare -x FCFLAGS=""
  106. 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}\""
  107. declare -x FFLAGS=""
  108. declare -x GCC_SPECS=""
  109. declare -x GDK_USE_XFT="1"
  110. 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"
  111. declare -x GRUB_PLATFORMS=""
  112. declare -x GSETTINGS_BACKEND="dconf"
  113. declare HOMEPAGE="http://avahi.org/"
  114. declare -x INHERITED=" multilib toolchain-funcs portability user eutils libtool autotools mono python flag-o-matic"
  115. declare -x INPUT_DEVICES="evdev keyboard mouse"
  116. declare -x INSDESTTREE=""
  117. declare -x INSOPTIONS="-m0644"
  118. declare IUSE="autoipd bookmarks dbus doc gdbm gtk gtk3 howl-compat +introspection ipv6
  119. kernel_linux mdnsresponder-compat mono python qt4 test utils "
  120. declare -x KERNEL="linux"
  121. declare -x KERNEL_ABI="amd64"
  122. declare -x KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~x86-fbsd ~x86-linux"
  123. declare -x KV="3.1.6-gentoo"
  124. declare -x LANG="C"
  125. declare -x LCD_DEVICES=""
  126. declare -x LC_ALL="C"
  127. declare -x LDFLAGS="-Wl,-O1 -Wl,--as-needed"
  128. declare -x LDFLAGS_amd64="-m elf_x86_64"
  129. declare -x LDFLAGS_default
  130. declare -x LDFLAGS_x32="-m elf32_x86_64"
  131. declare -x LDFLAGS_x86="-m elf_i386"
  132. declare -x LIBBLURAY_CP="/usr/share/libbluray/lib/libbluray.jar"
  133. declare -x LIBDIR_amd64="lib64"
  134. declare -x LIBDIR_amd64_fbsd="lib64"
  135. declare -x LIBDIR_default="lib"
  136. declare -x LIBDIR_n32="lib32"
  137. declare -x LIBDIR_n64="lib64"
  138. declare -x LIBDIR_o32="lib"
  139. declare -x LIBDIR_ppc="lib32"
  140. declare -x LIBDIR_ppc64="lib64"
  141. declare -x LIBDIR_s390="lib32"
  142. declare -x LIBDIR_s390x="lib64"
  143. declare -x LIBDIR_sparc32="lib32"
  144. declare -x LIBDIR_sparc64="lib64"
  145. declare -x LIBDIR_x32="libx32"
  146. declare -x LIBDIR_x86="lib32"
  147. declare -x LIBDIR_x86_fbsd="lib32"
  148. declare -x LIBOPTIONS="-m0644"
  149. declare -x LICENSE="LGPL-2.1"
  150. declare -x MAIL="/var/mail/root"
  151. declare -x MAKEOPTS="-j5"
  152. declare -x MONO_SHARED_DIR="/var/tmp/portage/net-dns/avahi-0.6.30-r2/temp"
  153. declare -x MULTILIB_ABIS="amd64 x86"
  154. declare -x MULTILIB_STRICT_DENY="64-bit.*shared object"
  155. declare -x MULTILIB_STRICT_DIRS="/lib32 /lib /usr/lib32 /usr/lib /usr/kde/*/lib32 /usr/kde/*/lib /usr/qt/*/lib32 /usr/qt/*/lib /usr/X11R6/lib32 /usr/X11R6/lib"
  156. declare -x MULTILIB_STRICT_EXEMPT="(perl5|gcc|gcc-lib|binutils|eclipse-3|debug|portage|udev)"
  157. declare -x NETBEANS="apisupport cnd groovy gsf harness ide identity j2ee java mobility nb php profiler soa visualweb webcommon websvccommon xml"
  158. declare -x OPENGL_PROFILE="nvidia"
  159. declare -x PATH="/usr/lib64/portage/bin/ebuild-helpers:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.5.3"
  160. declare PDEPEND=""
  161. declare -x PHP_TARGETS=""
  162. declare -a PORTAGE_DOCOMPRESS='([0]="/usr/share/doc" [1]="/usr/share/info" [2]="/usr/share/man")'
  163. declare -a PORTAGE_DOCOMPRESS_SKIP='([0]="/usr/share/doc/avahi-0.6.30-r2/html")'
  164. declare -x PRELINK_PATH_MASK="/usr/lib64/libfreebl3.so:/usr/lib64/libnssdbm3.so:/usr/lib64/libsoftokn3.so"
  165. declare -x PROFILE_ONLY_VARIABLES="ARCH ELIBC KERNEL USERLAND"
  166. declare -x PROPERTIES=""
  167. declare -x PROVIDE=""
  168. declare -x PYTHONDONTWRITEBYTECODE="1"
  169. declare -- PYTHON_COLORS="0"
  170. declare -- PYTHON_DEPEND="python? 2"
  171. declare -- PYTHON_TEST_VERBOSITY="1"
  172. declare -- PYTHON_USE_WITH="gdbm"
  173. declare -- PYTHON_USE_WITH_OPT="python"
  174. declare -x QT_PLUGIN_PATH="/usr/lib64/kde4/plugins"
  175. declare -x RDEPEND=">=dev-libs/libdaemon-0.14
  176. dev-libs/expat
  177. dev-libs/glib:2
  178. gdbm? ( sys-libs/gdbm )
  179. qt4? ( x11-libs/qt-core:4 )
  180. gtk? ( >=x11-libs/gtk+-2.14.0:2 )
  181. gtk3? ( x11-libs/gtk+:3 )
  182. dbus? (
  183. >=sys-apps/dbus-0.30
  184. python? ( dev-python/dbus-python )
  185. )
  186. mono? (
  187. >=dev-lang/mono-1.1.10
  188. gtk? ( >=dev-dotnet/gtk-sharp-2 )
  189. )
  190. howl-compat? ( >=sys-apps/dbus-0.30 )
  191. introspection? ( >=dev-libs/gobject-introspection-0.9.5 )
  192. mdnsresponder-compat? ( >=sys-apps/dbus-0.30 )
  193. python? (
  194. gtk? ( >=dev-python/pygtk-2 )
  195. )
  196. bookmarks? (
  197. dev-python/twisted
  198. dev-python/twisted-web
  199. )
  200. kernel_linux? ( sys-libs/libcap )
  201. howl-compat? ( !net-misc/howl )
  202. mdnsresponder-compat? ( !net-misc/mDNSResponder ) >=app-admin/eselect-python-20091230 python? ( =dev-lang/python-2* ) python? ( =dev-lang/python-2*[gdbm] )"
  203. declare REQUIRED_USE=""
  204. declare -x RESTRICT=""
  205. 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}\""
  206. declare -x RUBY_TARGETS="ruby18"
  207. declare -x S="/var/tmp/portage/net-dns/avahi-0.6.30-r2/work/avahi-0.6.30"
  208. declare -x SANDBOX_DEBUG="0"
  209. declare -x SANDBOX_DENY=""
  210. declare -x SANDBOX_PID="2656"
  211. declare -x SANDBOX_PREDICT="/var/tmp/portage/net-dns/avahi-0.6.30-r2/homedir:/dev/crypto:/dev/random:/proc/self/coredump_filter:/var/cache/fontconfig"
  212. declare -x SANDBOX_READ="/:/var/tmp"
  213. declare -x SANDBOX_VERBOSE="1"
  214. declare -x SANDBOX_WRITE=":/dev/console:/dev/fd:/dev/full:/dev/null:/dev/pts/:/dev/pty:/dev/shm:/dev/tts:/dev/tty:/dev/vc/:/dev/zero:/proc/self/fd:/tmp/:/usr/lib/cf:/usr/lib/conftest:/usr/lib32/cf:/usr/lib32/conftest:/usr/lib64/cf:/usr/lib64/conftest:/usr/tmp/cf:/usr/tmp/conftest:/var/tmp:/var/tmp/:/var/tmp/portage/net-dns/avahi-0.6.30-r2/homedir/.bash_history"
  215. declare -x SLOT="0"
  216. declare SRC_URI="http://avahi.org/download/avahi-0.6.30.tar.gz"
  217. declare -x SUDO_COMMAND="/usr/bin/emerge -Davt avahi"
  218. declare -x SUDO_GID="1000"
  219. declare -x SUDO_UID="1000"
  220. declare -x SUDO_USER="ottembomb"
  221. declare -x SYMLINK_LIB="yes"
  222. declare -x USE="amd64 autoipd dbus elibc_glibc gdbm gtk introspection ipv6 kernel_linux mono multilib qt4 userland_GNU"
  223. declare -x USERLAND="GNU"
  224. declare -x USERNAME="root"
  225. declare -x VBOX_APP_HOME="/usr/lib64/virtualbox"
  226. declare -x VIDEO_CARDS=""
  227. declare -x WANT_AUTOCONF="latest"
  228. declare -x WANT_AUTOMAKE="latest"
  229. declare -x WANT_LIBTOOL="latest"
  230. declare -x XDG_CONFIG_DIRS="/etc/xdg"
  231. declare -x XDG_CONFIG_HOME="/var/tmp/portage/net-dns/avahi-0.6.30-r2/temp"
  232. declare -x XDG_DATA_DIRS="/usr/local/share:/usr/share:/usr/share/gdm"
  233. 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"
  234. declare -a _CPYTHON2_GLOBALLY_SUPPORTED_ABIS='([0]="2.4" [1]="2.5" [2]="2.6" [3]="2.7")'
  235. declare -a _CPYTHON3_GLOBALLY_SUPPORTED_ABIS='([0]="3.1" [1]="3.2")'
  236. declare -x _E_DOCDESTTREE_=""
  237. declare -x _E_EXEDESTTREE_=""
  238. declare -a _JYTHON_GLOBALLY_SUPPORTED_ABIS='([0]="2.5-jython")'
  239. declare -- _LATEST_AUTOMAKE="1.11"
  240. declare -a _PYPY_GLOBALLY_SUPPORTED_ABIS='([0]="2.7-pypy-1.7")'
  241. declare -- _PYTHON_ABI_EXTRACTION_COMMAND="import platform
  242. import sys
  243. sys.stdout.write(\".\".join(str(x) for x in sys.version_info[:2]))
  244. if platform.system()[:4] == \"Java\":
  245. sys.stdout.write(\"-jython\")
  246. elif hasattr(platform, \"python_implementation\") and platform.python_implementation() == \"PyPy\":
  247. sys.stdout.write(\"-pypy-\" + \".\".join(str(x) for x in sys.pypy_version_info[:2]))"
  248. declare -- _PYTHON_ABI_PATTERN_REGEX="([[:alnum:]]|\\.|-|\\*|\\[|\\])+"
  249. declare -- _PYTHON_ECLASS_INHERITED="1"
  250. 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")'
  251. declare -- _PYTHON_SHEBANG_BASE_PART_REGEX="^#![[:space:]]*([^[:space:]]*/usr/bin/env[[:space:]]+)?([^[:space:]]*/)?(jython|pypy-c|python)"
  252. declare -- ___ECLASS_ONCE_AUTOTOOLS="recur -_+^+_- spank"
  253. declare -- ___ECLASS_ONCE_EUTILS="recur -_+^+_- spank"
  254. declare -- ___ECLASS_ONCE_FLAG_O_MATIC="recur -_+^+_- spank"
  255. declare -- ___ECLASS_ONCE_LIBTOOL="recur -_+^+_- spank"
  256. declare -- ___ECLASS_ONCE_MULTILIB="recur -_+^+_- spank"
  257. declare -- ___ECLASS_ONCE_PORTABILITY="recur -_+^+_- spank"
  258. declare -- ___ECLASS_ONCE_TOOLCHAIN_FUNCS="recur -_+^+_- spank"
  259. declare -- ___ECLASS_ONCE_USER="recur -_+^+_- spank"
  260. declare -- _libtool_atom="sys-devel/libtool"
  261. declare -- phase_func
  262. ELT_libtool_version ()
  263. {
  264. ( unset VERSION;
  265. eval $(grep -e '^[[:space:]]*VERSION=' "$1");
  266. echo "${VERSION:-0}" )
  267. }
  268. ELT_try_and_apply_patch ()
  269. {
  270. local ret=0;
  271. local file=$1;
  272. local patch=$2;
  273. local src=$3;
  274. local disp="${src} patch";
  275. local log="${T}/elibtool.log";
  276. if [[ -z ${__ELT_NOTED_TMP} ]]; then
  277. __ELT_NOTED_TMP=true;
  278. printf 'temp patch: %s\n' "${patch}" > "${log}";
  279. fi;
  280. printf '\nTrying %s\n' "${disp}" >> "${log}";
  281. if patch -p0 --dry-run "${file}" "${patch}" >> "${log}" 2>&1; then
  282. einfo " Applying ${disp} ...";
  283. patch -p0 -g0 --no-backup-if-mismatch "${file}" "${patch}" >> "${log}" 2>&1;
  284. ret=$?;
  285. export ELT_APPLIED_PATCHES="${ELT_APPLIED_PATCHES} ${src}";
  286. else
  287. ret=1;
  288. fi;
  289. return "${ret}"
  290. }
  291. ELT_walk_patches ()
  292. {
  293. local patch tmp;
  294. local ret=1;
  295. local file=$1;
  296. local patch_set=$2;
  297. local patch_dir="$(elt_patch_dir)/${patch_set}";
  298. local rem_int_dep=$3;
  299. [[ -z ${patch_set} ]] && return 1;
  300. [[ ! -d ${patch_dir} ]] && return 1;
  301. local sed_args=(-e "s:@GENTOO_LIBDIR@:$(get_libdir):g");
  302. if [[ -n ${rem_int_dep} ]]; then
  303. sed_args+=(-e "s|@REM_INT_DEP@|${rem_int_dep}|g");
  304. fi;
  305. pushd "$(elt_patch_dir)" > /dev/null || die;
  306. for patch in $(find "${patch_set}" -maxdepth 1 -type f | LC_ALL=C sort -r);
  307. do
  308. tmp="${T}/libtool-elt.patch";
  309. sed "${sed_args[@]}" "${patch}" > "${tmp}" || die;
  310. if ELT_try_and_apply_patch "${file}" "${tmp}" "${patch}"; then
  311. ret=0;
  312. break;
  313. fi;
  314. done;
  315. popd > /dev/null;
  316. return ${ret}
  317. }
  318. PYTHON ()
  319. {
  320. _python_check_python_pkg_setup_execution;
  321. local ABI_output="0" absolute_path_output="0" final_ABI="0" PYTHON_ABI="${PYTHON_ABI}" python_interpreter python2="0" python3="0";
  322. while (($#)); do
  323. case "$1" in
  324. -2)
  325. python2="1"
  326. ;;
  327. -3)
  328. python3="1"
  329. ;;
  330. --ABI)
  331. ABI_output="1"
  332. ;;
  333. -a | --absolute-path)
  334. absolute_path_output="1"
  335. ;;
  336. -f | --final-ABI)
  337. final_ABI="1"
  338. ;;
  339. --)
  340. shift;
  341. break
  342. ;;
  343. -*)
  344. die "${FUNCNAME}(): Unrecognized option '$1'"
  345. ;;
  346. *)
  347. break
  348. ;;
  349. esac;
  350. shift;
  351. done;
  352. if [[ "${ABI_output}" == "1" && "${absolute_path_output}" == "1" ]]; then
  353. die "${FUNCNAME}(): '--ABI' and '--absolute-path' options cannot be specified simultaneously";
  354. fi;
  355. if [[ "$((${python2} + ${python3} + ${final_ABI}))" -gt 1 ]]; then
  356. die "${FUNCNAME}(): '-2', '-3' or '--final-ABI' options cannot be specified simultaneously";
  357. fi;
  358. if [[ "$#" -eq 0 ]]; then
  359. if [[ "${final_ABI}" == "1" ]]; then
  360. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  361. die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  362. fi;
  363. _python_calculate_PYTHON_ABIS;
  364. PYTHON_ABI="${PYTHON_ABIS##* }";
  365. else
  366. if [[ "${python2}" == "1" ]]; then
  367. PYTHON_ABI="$(ROOT="/" eselect python show --python2 --ABI)";
  368. if [[ -z "${PYTHON_ABI}" ]]; then
  369. die "${FUNCNAME}(): Active version of CPython 2 not set";
  370. else
  371. if [[ "${PYTHON_ABI}" != "2."* ]]; then
  372. die "${FUNCNAME}(): Internal error in \`eselect python show --python2\`";
  373. fi;
  374. fi;
  375. else
  376. if [[ "${python3}" == "1" ]]; then
  377. PYTHON_ABI="$(ROOT="/" eselect python show --python3 --ABI)";
  378. if [[ -z "${PYTHON_ABI}" ]]; then
  379. die "${FUNCNAME}(): Active version of CPython 3 not set";
  380. else
  381. if [[ "${PYTHON_ABI}" != "3."* ]]; then
  382. die "${FUNCNAME}(): Internal error in \`eselect python show --python3\`";
  383. fi;
  384. fi;
  385. else
  386. if _python_package_supporting_installation_for_multiple_python_abis; then
  387. if ! _python_abi-specific_local_scope; then
  388. die "${FUNCNAME}() should be used in ABI-specific local scope";
  389. fi;
  390. else
  391. PYTHON_ABI="$("${EPREFIX}/usr/bin/python" -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")";
  392. if [[ -z "${PYTHON_ABI}" ]]; then
  393. die "${FUNCNAME}(): Failure of extraction of locally active version of Python";
  394. fi;
  395. fi;
  396. fi;
  397. fi;
  398. fi;
  399. else
  400. if [[ "$#" -eq 1 ]]; then
  401. if [[ "${final_ABI}" == "1" ]]; then
  402. die "${FUNCNAME}(): '--final-ABI' option and Python ABI cannot be specified simultaneously";
  403. fi;
  404. if [[ "${python2}" == "1" ]]; then
  405. die "${FUNCNAME}(): '-2' option and Python ABI cannot be specified simultaneously";
  406. fi;
  407. if [[ "${python3}" == "1" ]]; then
  408. die "${FUNCNAME}(): '-3' option and Python ABI cannot be specified simultaneously";
  409. fi;
  410. PYTHON_ABI="$1";
  411. else
  412. die "${FUNCNAME}(): Invalid usage";
  413. fi;
  414. fi;
  415. if [[ "${ABI_output}" == "1" ]]; then
  416. echo -n "${PYTHON_ABI}";
  417. return;
  418. else
  419. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  420. python_interpreter="python${PYTHON_ABI}";
  421. else
  422. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  423. python_interpreter="jython${PYTHON_ABI%-jython}";
  424. else
  425. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  426. python_interpreter="pypy-c${PYTHON_ABI#*-pypy-}";
  427. fi;
  428. fi;
  429. fi;
  430. if [[ "${absolute_path_output}" == "1" ]]; then
  431. echo -n "${EPREFIX}/usr/bin/${python_interpreter}";
  432. else
  433. echo -n "${python_interpreter}";
  434. fi;
  435. fi;
  436. if [[ -n "${ABI}" && "${ABI}" != "${DEFAULT_ABI}" && "${DEFAULT_ABI}" != "default" ]]; then
  437. echo -n "-${ABI}";
  438. fi
  439. }
  440. VER_major ()
  441. {
  442. [[ -z $1 ]] && return 1;
  443. local VER=$@;
  444. echo "${VER%%[^[:digit:]]*}"
  445. }
  446. VER_micro ()
  447. {
  448. [[ -z $1 ]] && return 1;
  449. local VER=$@;
  450. VER=${VER#*.*.};
  451. echo "${VER%%[^[:digit:]]*}"
  452. }
  453. VER_minor ()
  454. {
  455. [[ -z $1 ]] && return 1;
  456. local VER=$@;
  457. VER=${VER#*.};
  458. echo "${VER%%[^[:digit:]]*}"
  459. }
  460. VER_to_int ()
  461. {
  462. [[ -z $1 ]] && return 1;
  463. local VER_MAJOR=$(VER_major "$1");
  464. local VER_MINOR=$(VER_minor "$1");
  465. local VER_MICRO=$(VER_micro "$1");
  466. local VER_int=$(( VER_MAJOR * 65536 + VER_MINOR * 256 + VER_MICRO ));
  467. if [[ ${VER_int} -ge 65536 ]]; then
  468. echo "${VER_int}";
  469. return 0;
  470. fi;
  471. echo 1;
  472. return 1
  473. }
  474. _assert_pkg_ebuild_phase ()
  475. {
  476. case ${EBUILD_PHASE} in
  477. setup | preinst | postinst)
  478.  
  479. ;;
  480. *)
  481. eerror "'$1()' called from '${EBUILD_PHASE}' phase which is not OK:";
  482. eerror "You may only call from pkg_{setup,preinst,postinst} functions.";
  483. eerror "Package fails at QA and at life. Please file a bug.";
  484. die "Bad package! $1 is only for use in some pkg_* functions!"
  485. ;;
  486. esac
  487. }
  488. _autotools_m4dir_include ()
  489. {
  490. local x include_opts;
  491. for x in "$@";
  492. do
  493. case ${x} in
  494. -I)
  495.  
  496. ;;
  497. *)
  498. [[ ! -d ${x} ]] && ewarn "autotools.eclass: '${x}' does not exist";
  499. include_opts+=" -I ${x}"
  500. ;;
  501. esac;
  502. done;
  503. echo ${include_opts}
  504. }
  505. _cdrom_locate_file_on_cd ()
  506. {
  507. local mline="";
  508. local showedmsg=0 showjolietmsg=0;
  509. while [[ -z ${CDROM_ROOT} ]]; do
  510. local i=0;
  511. local -a cdset=(${*//:/ });
  512. if [[ -n ${CDROM_SET} ]]; then
  513. cdset=(${cdset[${CDROM_SET}]});
  514. fi;
  515. while [[ -n ${cdset[${i}]} ]]; do
  516. local dir=$(dirname ${cdset[${i}]});
  517. local file=$(basename ${cdset[${i}]});
  518. local point= node= fs= foo=;
  519. while read point node fs foo; do
  520. [[ " cd9660 iso9660 udf " != *" ${fs} "* ]] && ! [[ ${fs} == "subfs" && ",${opts}," == *",fs=cdfss,"* ]] && continue;
  521. point=${point//\040/ };
  522. [[ ! -d ${point}/${dir} ]] && continue;
  523. [[ -z $(find "${point}/${dir}" -maxdepth 1 -iname "${file}") ]] && continue;
  524. export CDROM_ROOT=${point};
  525. export CDROM_SET=${i};
  526. export CDROM_MATCH=${cdset[${i}]};
  527. return;
  528. done <<< "$(get_mounts)";
  529. ((++i));
  530. done;
  531. echo;
  532. if [[ ${showedmsg} -eq 0 ]]; then
  533. if [[ ${CDROM_TOTAL_CDS} -eq 1 ]]; then
  534. if [[ -z ${CDROM_NAME} ]]; then
  535. einfo "Please insert+mount the cdrom for ${PN} now !";
  536. else
  537. einfo "Please insert+mount the ${CDROM_NAME} cdrom now !";
  538. fi;
  539. else
  540. if [[ -z ${CDROM_NAME_1} ]]; then
  541. einfo "Please insert+mount cd #${CDROM_CURRENT_CD} for ${PN} now !";
  542. else
  543. local var="CDROM_NAME_${CDROM_CURRENT_CD}";
  544. einfo "Please insert+mount the ${!var} cdrom now !";
  545. fi;
  546. fi;
  547. showedmsg=1;
  548. fi;
  549. einfo "Press return to scan for the cd again";
  550. einfo "or hit CTRL+C to abort the emerge.";
  551. echo;
  552. if [[ ${showjolietmsg} -eq 0 ]]; then
  553. showjolietmsg=1;
  554. else
  555. ewarn "If you are having trouble with the detection";
  556. ewarn "of your CD, it is possible that you do not have";
  557. ewarn "Joliet support enabled in your kernel. Please";
  558. ewarn "check that CONFIG_JOLIET is enabled in your kernel.";
  559. ebeep 5;
  560. fi;
  561. read || die "something is screwed with your system";
  562. done
  563. }
  564. _dead_portability_user_funcs ()
  565. {
  566. die "if you really need this, please file a bug for base-system@gentoo.org"
  567. }
  568. _elibtoolize ()
  569. {
  570. local opts g=;
  571. [[ -n $(autotools_check_macro AC_PROG_LIBTOOL AM_PROG_LIBTOOL LT_INIT) ]] || return 0;
  572. [[ -f GNUmakefile.am || -f Makefile.am ]] && opts="--automake";
  573. [[ ${CHOST} == *-darwin* ]] && g=g;
  574. autotools_run_tool ${LIBTOOLIZE:-${g}libtoolize} "$@" ${opts};
  575. eaclocal
  576. }
  577. _filter-hardened ()
  578. {
  579. local f;
  580. for f in "$@";
  581. do
  582. case "${f}" in
  583. -fPIC | -fpic | -fPIE | -fpie | -Wl,pie | -pie)
  584. gcc-specs-pie || continue;
  585. is-flagq -nopie || append-flags -nopie
  586. ;;
  587. -fstack-protector)
  588. gcc-specs-ssp || continue;
  589. is-flagq -fno-stack-protector || append-flags $(test-flags -fno-stack-protector)
  590. ;;
  591. -fstack-protector-all)
  592. gcc-specs-ssp-to-all || continue;
  593. is-flagq -fno-stack-protector-all || append-flags $(test-flags -fno-stack-protector-all)
  594. ;;
  595. -fno-strict-overflow)
  596. gcc-specs-nostrict || continue;
  597. is-flagq -fstrict-overflow || append-flags $(test-flags -fstrict-overflow)
  598. ;;
  599. esac;
  600. done
  601. }
  602. _filter-var ()
  603. {
  604. local f x VAR VAL;
  605. declare -a new;
  606. VAR=$1;
  607. shift;
  608. eval VAL=\${${VAR}};
  609. for f in ${VAL};
  610. do
  611. for x in "$@";
  612. do
  613. [[ ${f} == ${x} ]] && continue 2;
  614. done;
  615. eval new\[\${\#new\[@]}]=\${f};
  616. done;
  617. eval export ${VAR}=\${new\[*]}
  618. }
  619. _gcc-install-dir ()
  620. {
  621. echo "$(LC_ALL=C $(tc-getCC) -print-search-dirs 2> /dev/null | awk '$1=="install:" {print $2}')"
  622. }
  623. _gcc-specs-directive_raw ()
  624. {
  625. local cc=$(tc-getCC);
  626. local specfiles=$(LC_ALL=C ${cc} -v 2>&1 | awk '$1=="Reading" {print $NF}');
  627. ${cc} -dumpspecs 2> /dev/null | cat - ${specfiles} | awk -v directive=$1 'BEGIN { pspec=""; spec=""; outside=1 }
  628. $1=="*"directive":" { pspec=spec; spec=""; outside=0; next }
  629. outside || NF==0 || ( substr($1,1,1)=="*" && substr($1,length($1),1)==":" ) { outside=1; next }
  630. spec=="" && substr($0,1,1)=="+" { spec=pspec " " substr($0,2); next }
  631. { spec=spec $0 }
  632. END { print spec }';
  633. return 0
  634. }
  635. _gcc-specs-exists ()
  636. {
  637. [[ -f $(_gcc-install-dir)/$1 ]]
  638. }
  639. _gcc_fullversion ()
  640. {
  641. local ver="$1";
  642. shift;
  643. set -- `$(tc-getCPP "$@") -E -P - <<<"__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__"`;
  644. eval echo "$ver"
  645. }
  646. _is_flagq ()
  647. {
  648. local x;
  649. for x in ${!1};
  650. do
  651. [[ ${x} == $2 ]] && return 0;
  652. done;
  653. return 1
  654. }
  655. _python_abi-specific_local_scope ()
  656. {
  657. [[ " ${FUNCNAME[@]:2} " =~ " "(_python_final_sanity_checks|python_execute_function|python_mod_optimize|python_mod_cleanup)" " ]]
  658. }
  659. _python_calculate_PYTHON_ABIS ()
  660. {
  661. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  662. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  663. fi;
  664. _python_initial_sanity_checks;
  665. if [[ "$(declare -p PYTHON_ABIS 2> /dev/null)" != "declare -x PYTHON_ABIS="* ]] && has "${EAPI:-0}" 0 1 2 3 4; then
  666. local PYTHON_ABI;
  667. if [[ "$(declare -p USE_PYTHON 2> /dev/null)" == "declare -x USE_PYTHON="* ]]; then
  668. local cpython_enabled="0";
  669. if [[ -z "${USE_PYTHON}" ]]; then
  670. die "USE_PYTHON variable is empty";
  671. fi;
  672. for PYTHON_ABI in ${USE_PYTHON};
  673. do
  674. if ! has "${PYTHON_ABI}" "${_PYTHON_GLOBALLY_SUPPORTED_ABIS[@]}"; then
  675. die "USE_PYTHON variable contains invalid value '${PYTHON_ABI}'";
  676. fi;
  677. if has "${PYTHON_ABI}" "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}" "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}"; then
  678. cpython_enabled="1";
  679. fi;
  680. if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
  681. export PYTHON_ABIS+="${PYTHON_ABIS:+ }${PYTHON_ABI}";
  682. fi;
  683. done;
  684. if [[ -z "${PYTHON_ABIS//[${IFS}]/}" ]]; then
  685. die "USE_PYTHON variable does not enable any Python ABI supported by ${CATEGORY}/${PF}";
  686. fi;
  687. if [[ "${cpython_enabled}" == "0" ]]; then
  688. die "USE_PYTHON variable does not enable any CPython ABI";
  689. fi;
  690. else
  691. local python_version python2_version python3_version support_python_major_version;
  692. if ! has_version "dev-lang/python"; then
  693. die "${FUNCNAME}(): 'dev-lang/python' is not installed";
  694. fi;
  695. python_version="$("${EPREFIX}/usr/bin/python" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')";
  696. if has_version "=dev-lang/python-2*"; then
  697. if [[ "$(readlink "${EPREFIX}/usr/bin/python2")" != "python2."* ]]; then
  698. die "'${EPREFIX}/usr/bin/python2' is not valid symlink";
  699. fi;
  700. python2_version="$("${EPREFIX}/usr/bin/python2" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')";
  701. support_python_major_version="0";
  702. for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}";
  703. do
  704. if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
  705. support_python_major_version="1";
  706. break;
  707. fi;
  708. done;
  709. if [[ "${support_python_major_version}" == "1" ]]; then
  710. if _python_check_python_abi_matching --patterns-list "${python2_version}" "${RESTRICT_PYTHON_ABIS}"; then
  711. die "Active version of CPython 2 is not supported by ${CATEGORY}/${PF}";
  712. fi;
  713. else
  714. python2_version="";
  715. fi;
  716. fi;
  717. if has_version "=dev-lang/python-3*"; then
  718. if [[ "$(readlink "${EPREFIX}/usr/bin/python3")" != "python3."* ]]; then
  719. die "'${EPREFIX}/usr/bin/python3' is not valid symlink";
  720. fi;
  721. python3_version="$("${EPREFIX}/usr/bin/python3" -c 'from sys import version_info; print(".".join(str(x) for x in version_info[:2]))')";
  722. support_python_major_version="0";
  723. for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}";
  724. do
  725. if ! _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${RESTRICT_PYTHON_ABIS}"; then
  726. support_python_major_version="1";
  727. break;
  728. fi;
  729. done;
  730. if [[ "${support_python_major_version}" == "1" ]]; then
  731. if _python_check_python_abi_matching --patterns-list "${python3_version}" "${RESTRICT_PYTHON_ABIS}"; then
  732. die "Active version of CPython 3 is not supported by ${CATEGORY}/${PF}";
  733. fi;
  734. else
  735. python3_version="";
  736. fi;
  737. fi;
  738. if [[ -n "${python2_version}" && "${python_version}" == "2."* && "${python_version}" != "${python2_version}" ]]; then
  739. eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python2' symlink";
  740. eerror "is set incorrectly. Use \`eselect python\` to fix configuration.";
  741. die "Incorrect configuration of Python";
  742. fi;
  743. if [[ -n "${python3_version}" && "${python_version}" == "3."* && "${python_version}" != "${python3_version}" ]]; then
  744. eerror "Python wrapper is configured incorrectly or '${EPREFIX}/usr/bin/python3' symlink";
  745. eerror "is set incorrectly. Use \`eselect python\` to fix configuration.";
  746. die "Incorrect configuration of Python";
  747. fi;
  748. PYTHON_ABIS="${python2_version} ${python3_version}";
  749. PYTHON_ABIS="${PYTHON_ABIS# }";
  750. export PYTHON_ABIS="${PYTHON_ABIS% }";
  751. fi;
  752. fi;
  753. _python_final_sanity_checks
  754. }
  755. _python_check_python_abi_matching ()
  756. {
  757. local pattern patterns patterns_list="0" PYTHON_ABI;
  758. while (($#)); do
  759. case "$1" in
  760. --patterns-list)
  761. patterns_list="1"
  762. ;;
  763. --)
  764. shift;
  765. break
  766. ;;
  767. -*)
  768. die "${FUNCNAME}(): Unrecognized option '$1'"
  769. ;;
  770. *)
  771. break
  772. ;;
  773. esac;
  774. shift;
  775. done;
  776. if [[ "$#" -ne 2 ]]; then
  777. die "${FUNCNAME}() requires 2 arguments";
  778. fi;
  779. PYTHON_ABI="$1";
  780. if [[ "${patterns_list}" == "0" ]]; then
  781. pattern="$2";
  782. if [[ "${pattern}" == *"-cpython" ]]; then
  783. [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ && "${PYTHON_ABI}" == ${pattern%-cpython} ]];
  784. else
  785. if [[ "${pattern}" == *"-jython" ]]; then
  786. [[ "${PYTHON_ABI}" == ${pattern} ]];
  787. else
  788. if [[ "${pattern}" == *"-pypy-"* ]]; then
  789. [[ "${PYTHON_ABI}" == ${pattern} ]];
  790. else
  791. if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
  792. [[ "${PYTHON_ABI}" == ${pattern} ]];
  793. else
  794. if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then
  795. [[ "${PYTHON_ABI%-jython}" == ${pattern} ]];
  796. else
  797. if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-pypy-[[:digit:]]+\.[[:digit:]]+$ ]]; then
  798. [[ "${PYTHON_ABI%-pypy-*}" == ${pattern} ]];
  799. else
  800. die "${FUNCNAME}(): Unrecognized Python ABI '${PYTHON_ABI}'";
  801. fi;
  802. fi;
  803. fi;
  804. fi;
  805. fi;
  806. fi;
  807. else
  808. patterns="${2// /
  809. }";
  810. while read pattern; do
  811. if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
  812. return 0;
  813. fi;
  814. done <<< "${patterns}";
  815. return 1;
  816. fi
  817. }
  818. _python_check_python_pkg_setup_execution ()
  819. {
  820. [[ " ${FUNCNAME[@]:1} " =~ " "(python_set_active_version|python_pkg_setup)" " ]] && return;
  821. if ! has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_PKG_SETUP_EXECUTED}" ]]; then
  822. die "python_pkg_setup() not called";
  823. fi
  824. }
  825. _python_clean_compiled_modules ()
  826. {
  827. _python_initialize_prefix_variables;
  828. _python_set_color_variables;
  829. [[ "${FUNCNAME[1]}" =~ ^(python_mod_optimize|python_mod_cleanup)$ ]] || die "${FUNCNAME}(): Invalid usage";
  830. local base_module_name compiled_file compiled_files=() dir path py_file root;
  831. root="${EROOT%/}";
  832. for path in "$@";
  833. do
  834. compiled_files=();
  835. if [[ -d "${path}" ]]; then
  836. while read -d '' -r compiled_file; do
  837. compiled_files+=("${compiled_file}");
  838. done < <(find "${path}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -print0);
  839. if [[ "${EBUILD_PHASE}" == "postrm" ]]; then
  840. find "${path}" -type d | sort -r | while read -r dir; do
  841. if rmdir "${dir}" 2> /dev/null; then
  842. echo "${_CYAN}<<< ${dir}${_NORMAL}";
  843. fi;
  844. done;
  845. fi;
  846. else
  847. if [[ "${path}" == *.py ]]; then
  848. base_module_name="${path##*/}";
  849. base_module_name="${base_module_name%.py}";
  850. if [[ -d "${path%/*}/__pycache__" ]]; then
  851. while read -d '' -r compiled_file; do
  852. compiled_files+=("${compiled_file}");
  853. done < <(find "${path%/*}/__pycache__" "(" -name "${base_module_name}.*.py[co]" -o -name "${base_module_name}\$py.class" ")" -print0);
  854. fi;
  855. compiled_files+=("${path}c" "${path}o" "${path%.py}\$py.class");
  856. fi;
  857. fi;
  858. for compiled_file in "${compiled_files[@]}";
  859. do
  860. [[ ! -f "${compiled_file}" ]] && continue;
  861. dir="${compiled_file%/*}";
  862. dir="${dir##*/}";
  863. if [[ "${compiled_file}" == *.py[co] ]]; then
  864. if [[ "${dir}" == "__pycache__" ]]; then
  865. base_module_name="${compiled_file##*/}";
  866. base_module_name="${base_module_name%.*py[co]}";
  867. base_module_name="${base_module_name%.*}";
  868. py_file="${compiled_file%__pycache__/*}${base_module_name}.py";
  869. else
  870. py_file="${compiled_file%[co]}";
  871. fi;
  872. if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
  873. [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue;
  874. else
  875. [[ -f "${py_file}" ]] && continue;
  876. fi;
  877. echo "${_BLUE}<<< ${compiled_file%[co]}[co]${_NORMAL}";
  878. rm -f "${compiled_file%[co]}"[co];
  879. else
  880. if [[ "${compiled_file}" == *\$py.class ]]; then
  881. if [[ "${dir}" == "__pycache__" ]]; then
  882. base_module_name="${compiled_file##*/}";
  883. base_module_name="${base_module_name%\$py.class}";
  884. py_file="${compiled_file%__pycache__/*}${base_module_name}.py";
  885. else
  886. py_file="${compiled_file%\$py.class}.py";
  887. fi;
  888. if [[ "${EBUILD_PHASE}" == "postinst" ]]; then
  889. [[ -f "${py_file}" && "${compiled_file}" -nt "${py_file}" ]] && continue;
  890. else
  891. [[ -f "${py_file}" ]] && continue;
  892. fi;
  893. echo "${_BLUE}<<< ${compiled_file}${_NORMAL}";
  894. rm -f "${compiled_file}";
  895. else
  896. die "${FUNCNAME}(): Unrecognized file type: '${compiled_file}'";
  897. fi;
  898. fi;
  899. dir="${compiled_file%/*}";
  900. while [[ "${dir}" != "${root}" ]]; do
  901. if rmdir "${dir}" 2> /dev/null; then
  902. echo "${_CYAN}<<< ${dir}${_NORMAL}";
  903. else
  904. break;
  905. fi;
  906. dir="${dir%/*}";
  907. done;
  908. done;
  909. done
  910. }
  911. _python_final_sanity_checks ()
  912. {
  913. 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
  914. local PYTHON_ABI="${PYTHON_ABI}";
  915. for PYTHON_ABI in ${PYTHON_ABIS-${PYTHON_ABI}};
  916. do
  917. if ! has_version "$(python_get_implementational_package)"; then
  918. die "$(python_get_implementational_package) is not installed";
  919. fi;
  920. if [[ "$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")" != "${PYTHON_ABI}" ]]; then
  921. eerror "Path to 'python': '$(type -p python)'";
  922. eerror "ABI: '${ABI}'";
  923. eerror "DEFAULT_ABI: '${DEFAULT_ABI}'";
  924. eerror "EPYTHON: '$(PYTHON)'";
  925. eerror "PYTHON_ABI: '${PYTHON_ABI}'";
  926. eerror "Locally active version of Python: '$(EPYTHON="$(PYTHON)" python -c "${_PYTHON_ABI_EXTRACTION_COMMAND}")'";
  927. die "'python' does not respect EPYTHON variable";
  928. fi;
  929. done;
  930. fi;
  931. PYTHON_SANITY_CHECKS_EXECUTED="1"
  932. }
  933. _python_get_implementation ()
  934. {
  935. local ignore_invalid="0";
  936. while (($#)); do
  937. case "$1" in
  938. --ignore-invalid)
  939. ignore_invalid="1"
  940. ;;
  941. --)
  942. shift;
  943. break
  944. ;;
  945. -*)
  946. die "${FUNCNAME}(): Unrecognized option '$1'"
  947. ;;
  948. *)
  949. break
  950. ;;
  951. esac;
  952. shift;
  953. done;
  954. if [[ "$#" -ne 1 ]]; then
  955. die "${FUNCNAME}() requires 1 argument";
  956. fi;
  957. if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+$ ]]; then
  958. echo "CPython";
  959. else
  960. if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-jython$ ]]; then
  961. echo "Jython";
  962. else
  963. if [[ "$1" =~ ^[[:digit:]]+\.[[:digit:]]+-pypy-[[:digit:]]+\.[[:digit:]]+$ ]]; then
  964. echo "PyPy";
  965. else
  966. if [[ "${ignore_invalid}" == "0" ]]; then
  967. die "${FUNCNAME}(): Unrecognized Python ABI '$1'";
  968. fi;
  969. fi;
  970. fi;
  971. fi
  972. }
  973. _python_implementation ()
  974. {
  975. if [[ "${CATEGORY}/${PN}" == "dev-lang/python" ]]; then
  976. return 0;
  977. else
  978. if [[ "${CATEGORY}/${PN}" == "dev-java/jython" ]]; then
  979. return 0;
  980. else
  981. if [[ "${CATEGORY}/${PN}" == "dev-python/pypy" ]]; then
  982. return 0;
  983. else
  984. return 1;
  985. fi;
  986. fi;
  987. fi
  988. }
  989. _python_initial_sanity_checks ()
  990. {
  991. 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
  992. if [[ "$(readlink "${EPREFIX}/usr/bin/python")" != "python-wrapper" ]]; then
  993. eerror "'${EPREFIX}/usr/bin/python' is not valid symlink.";
  994. eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem.";
  995. die "'${EPREFIX}/usr/bin/python' is not valid symlink";
  996. fi;
  997. if [[ "$(<"${EPREFIX}/usr/bin/python-config")" != *"Gentoo python-config wrapper script"* ]]; then
  998. eerror "'${EPREFIX}/usr/bin/python-config' is not valid script";
  999. eerror "Use \`eselect python set \${python_interpreter}\` to fix this problem.";
  1000. die "'${EPREFIX}/usr/bin/python-config' is not valid script";
  1001. fi;
  1002. fi
  1003. }
  1004. _python_initialize_prefix_variables ()
  1005. {
  1006. if has "${EAPI:-0}" 0 1 2; then
  1007. if [[ -n "${ROOT}" && -z "${EROOT}" ]]; then
  1008. EROOT="${ROOT%/}${EPREFIX}/";
  1009. fi;
  1010. if [[ -n "${D}" && -z "${ED}" ]]; then
  1011. ED="${D%/}${EPREFIX}/";
  1012. fi;
  1013. fi
  1014. }
  1015. _python_package_supporting_installation_for_multiple_python_abis ()
  1016. {
  1017. if has "${EAPI:-0}" 0 1 2 3 4; then
  1018. if [[ -n "${SUPPORT_PYTHON_ABIS}" ]]; then
  1019. return 0;
  1020. else
  1021. return 1;
  1022. fi;
  1023. else
  1024. die "${FUNCNAME}(): Support for EAPI=\"${EAPI}\" not implemented";
  1025. fi
  1026. }
  1027. _python_prepare_flags ()
  1028. {
  1029. local array=() deleted_flag element flags new_value old_flag old_value operator pattern prefix variable;
  1030. for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS;
  1031. do
  1032. eval "_PYTHON_SAVED_${variable}=\"\${!variable}\"";
  1033. for prefix in PYTHON_USER_ PYTHON_;
  1034. do
  1035. if [[ "$(declare -p ${prefix}${variable} 2> /dev/null)" == "declare -a ${prefix}${variable}="* ]]; then
  1036. eval "array=(\"\${${prefix}${variable}[@]}\")";
  1037. for element in "${array[@]}";
  1038. do
  1039. if [[ "${element}" =~ ^${_PYTHON_ABI_PATTERN_REGEX}\ (\+|-)\ .+ ]]; then
  1040. pattern="${element%% *}";
  1041. element="${element#* }";
  1042. operator="${element%% *}";
  1043. flags="${element#* }";
  1044. if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
  1045. if [[ "${operator}" == "+" ]]; then
  1046. eval "export ${variable}+=\"\${variable:+ }${flags}\"";
  1047. else
  1048. if [[ "${operator}" == "-" ]]; then
  1049. flags="${flags// /
  1050. }";
  1051. old_value="${!variable// /
  1052. }";
  1053. new_value="";
  1054. while read old_flag; do
  1055. while read deleted_flag; do
  1056. if [[ "${old_flag}" == ${deleted_flag} ]]; then
  1057. continue 2;
  1058. fi;
  1059. done <<< "${flags}";
  1060. new_value+="${new_value:+ }${old_flag}";
  1061. done <<< "${old_value}";
  1062. eval "export ${variable}=\"\${new_value}\"";
  1063. fi;
  1064. fi;
  1065. fi;
  1066. else
  1067. die "Element '${element}' of ${prefix}${variable} array has invalid syntax";
  1068. fi;
  1069. done;
  1070. else
  1071. if [[ -n "$(declare -p ${prefix}${variable} 2> /dev/null)" ]]; then
  1072. die "${prefix}${variable} should be indexed array";
  1073. fi;
  1074. fi;
  1075. done;
  1076. done
  1077. }
  1078. _python_restore_flags ()
  1079. {
  1080. local variable;
  1081. for variable in CPPFLAGS CFLAGS CXXFLAGS LDFLAGS;
  1082. do
  1083. eval "${variable}=\"\${_PYTHON_SAVED_${variable}}\"";
  1084. unset _PYTHON_SAVED_${variable};
  1085. done
  1086. }
  1087. _python_set_color_variables ()
  1088. {
  1089. if [[ "${PYTHON_COLORS}" != "0" && "${NOCOLOR:-false}" =~ ^(false|no)$ ]]; then
  1090. _BOLD='';
  1091. _RED='';
  1092. _GREEN='';
  1093. _BLUE='';
  1094. _CYAN='';
  1095. _NORMAL='';
  1096. else
  1097. _BOLD=;
  1098. _RED=;
  1099. _GREEN=;
  1100. _BLUE=;
  1101. _CYAN=;
  1102. _NORMAL=;
  1103. fi
  1104. }
  1105. _python_test_hook ()
  1106. {
  1107. if [[ "$#" -ne 1 ]]; then
  1108. die "${FUNCNAME}() requires 1 argument";
  1109. fi;
  1110. if _python_package_supporting_installation_for_multiple_python_abis && [[ "$(type -t "${_PYTHON_TEST_FUNCTION}_$1_hook")" == "function" ]]; then
  1111. "${_PYTHON_TEST_FUNCTION}_$1_hook";
  1112. fi
  1113. }
  1114. _tc-getPROG ()
  1115. {
  1116. local tuple=$1;
  1117. local v var vars=$2;
  1118. local prog=$3;
  1119. var=${vars%% *};
  1120. for v in ${vars};
  1121. do
  1122. if [[ -n ${!v} ]]; then
  1123. export ${var}="${!v}";
  1124. echo "${!v}";
  1125. return 0;
  1126. fi;
  1127. done;
  1128. local search=;
  1129. [[ -n $4 ]] && search=$(type -p "$4-${prog}");
  1130. [[ -z ${search} && -n ${!tuple} ]] && search=$(type -p "${!tuple}-${prog}");
  1131. [[ -n ${search} ]] && prog=${search##*/};
  1132. export ${var}=${prog};
  1133. echo "${!var}"
  1134. }
  1135. append-cflags ()
  1136. {
  1137. [[ $# -eq 0 ]] && return 0;
  1138. export CFLAGS=$(test-flags-CC ${CFLAGS} "$@");
  1139. return 0
  1140. }
  1141. append-cppflags ()
  1142. {
  1143. [[ $# -eq 0 ]] && return 0;
  1144. export CPPFLAGS="${CPPFLAGS} $*";
  1145. return 0
  1146. }
  1147. append-cxxflags ()
  1148. {
  1149. [[ $# -eq 0 ]] && return 0;
  1150. export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS} "$@");
  1151. return 0
  1152. }
  1153. append-fflags ()
  1154. {
  1155. [[ $# -eq 0 ]] && return 0;
  1156. export FFLAGS=$(test-flags-F77 ${FFLAGS} "$@");
  1157. export FCFLAGS=$(test-flags-FC ${FCFLAGS} "$@");
  1158. return 0
  1159. }
  1160. append-flags ()
  1161. {
  1162. [[ $# -eq 0 ]] && return 0;
  1163. append-cflags "$@";
  1164. append-cxxflags "$@";
  1165. append-fflags "$@";
  1166. return 0
  1167. }
  1168. append-ldflags ()
  1169. {
  1170. [[ $# -eq 0 ]] && return 0;
  1171. local flag;
  1172. for flag in "$@";
  1173. do
  1174. [[ ${flag} == -l* ]] && ewarn "Appending a library link instruction (${flag}); libraries to link to should not be passed through LDFLAGS";
  1175. done;
  1176. export LDFLAGS="${LDFLAGS} $*";
  1177. return 0
  1178. }
  1179. append-lfs-flags ()
  1180. {
  1181. [[ $# -ne 0 ]] && die "append-lfs-flags takes no arguments";
  1182. append-cppflags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
  1183. }
  1184. append-libs ()
  1185. {
  1186. [[ $# -eq 0 ]] && return 0;
  1187. local flag;
  1188. for flag in "$@";
  1189. do
  1190. [[ ${flag} == -l* ]] && flag=${flag#-l};
  1191. export LIBS="${LIBS} -l${flag}";
  1192. done;
  1193. return 0
  1194. }
  1195. autotools_check_macro ()
  1196. {
  1197. [[ -f configure.ac || -f configure.in ]] || return 0;
  1198. local macro;
  1199. for macro in "$@";
  1200. do
  1201. WANT_AUTOCONF="2.5" autoconf $(autotools_m4dir_include) --trace="${macro}" 2> /dev/null;
  1202. done;
  1203. return 0
  1204. }
  1205. autotools_check_macro_val ()
  1206. {
  1207. local macro=$1 scan_out;
  1208. autotools_check_macro "${macro}" | gawk -v macro="${macro}" '($0 !~ /^[[:space:]]*(#|dnl)/) {
  1209. if (match($0, macro ":(.*)$", res))
  1210. print res[1]
  1211. }' | uniq;
  1212. return 0
  1213. }
  1214. autotools_env_setup ()
  1215. {
  1216. if [[ ${WANT_AUTOMAKE} == "latest" ]]; then
  1217. local pv;
  1218. for pv in ${_LATEST_AUTOMAKE};
  1219. do
  1220. ROOT=/ has_version "=sys-devel/automake-${pv}*" && export WANT_AUTOMAKE="$pv";
  1221. done;
  1222. [[ ${WANT_AUTOMAKE} == "latest" ]] && die "Cannot find the latest automake! Tried ${_LATEST_AUTOMAKE}";
  1223. fi;
  1224. [[ ${WANT_AUTOCONF} == "latest" ]] && export WANT_AUTOCONF=2.5
  1225. }
  1226. autotools_get_auxdir ()
  1227. {
  1228. autotools_check_macro_val AC_CONFIG_AUX_DIR
  1229. }
  1230. autotools_get_subdirs ()
  1231. {
  1232. autotools_check_macro_val AC_CONFIG_SUBDIRS
  1233. }
  1234. autotools_m4dir_include ()
  1235. {
  1236. _autotools_m4dir_include ${AT_M4DIR}
  1237. }
  1238. autotools_m4sysdir_include ()
  1239. {
  1240. _autotools_m4dir_include $(eval echo ${AT_SYS_M4DIR})
  1241. }
  1242. autotools_run_tool ()
  1243. {
  1244. local autofail=true m4flags=false;
  1245. while [[ -n $1 ]]; do
  1246. case $1 in
  1247. --at-no-fail)
  1248. autofail=false
  1249. ;;
  1250. --at-m4flags)
  1251. m4flags=true
  1252. ;;
  1253. *)
  1254. break
  1255. ;;
  1256. esac;
  1257. shift;
  1258. done;
  1259. if [[ ${EBUILD_PHASE} != "unpack" && ${EBUILD_PHASE} != "prepare" ]]; then
  1260. ewarn "QA Warning: running $1 in ${EBUILD_PHASE} phase";
  1261. fi;
  1262. autotools_env_setup;
  1263. local STDERR_TARGET="${T}/$1.out";
  1264. if [[ -e ${STDERR_TARGET} ]]; then
  1265. local i=1;
  1266. while :; do
  1267. STDERR_TARGET="${T}/$1-${i}.out";
  1268. [[ -e ${STDERR_TARGET} ]] || break;
  1269. : $(( i++ ));
  1270. done;
  1271. fi;
  1272. if ${m4flags}; then
  1273. set -- "${1}" $(autotools_m4dir_include) "${@:2}" $(autotools_m4sysdir_include);
  1274. fi;
  1275. printf "***** $1 *****\n***** PWD: ${PWD}\n***** $*\n\n" > "${STDERR_TARGET}";
  1276. ebegin "Running $@";
  1277. "$@" >> "${STDERR_TARGET}" 2>&1;
  1278. if ! eend $? && ${autofail}; then
  1279. echo;
  1280. eerror "Failed Running $1 !";
  1281. eerror;
  1282. eerror "Include in your bugreport the contents of:";
  1283. eerror;
  1284. eerror " ${STDERR_TARGET}";
  1285. echo;
  1286. die "Failed Running $1 !";
  1287. fi
  1288. }
  1289. built_with_use ()
  1290. {
  1291. local hidden="no";
  1292. if [[ $1 == "--hidden" ]]; then
  1293. hidden="yes";
  1294. shift;
  1295. fi;
  1296. local missing_action="die";
  1297. if [[ $1 == "--missing" ]]; then
  1298. missing_action=$2;
  1299. shift;
  1300. shift;
  1301. case ${missing_action} in
  1302. true | false | die)
  1303.  
  1304. ;;
  1305. *)
  1306. die "unknown action '${missing_action}'"
  1307. ;;
  1308. esac;
  1309. fi;
  1310. local opt=$1;
  1311. [[ ${opt:0:1} = "-" ]] && shift || opt="-a";
  1312. local PKG=$(best_version $1);
  1313. [[ -z ${PKG} ]] && die "Unable to resolve $1 to an installed package";
  1314. shift;
  1315. local USEFILE=${ROOT}/var/db/pkg/${PKG}/USE;
  1316. local IUSEFILE=${ROOT}/var/db/pkg/${PKG}/IUSE;
  1317. if [[ ! -e ${USEFILE} ]] || [[ ! -e ${IUSEFILE} && ${hidden} == "no" ]]; then
  1318. case ${missing_action} in
  1319. true)
  1320. return 0
  1321. ;;
  1322. false)
  1323. return 1
  1324. ;;
  1325. die)
  1326. die "Unable to determine what USE flags $PKG was built with"
  1327. ;;
  1328. esac;
  1329. fi;
  1330. if [[ ${hidden} == "no" ]]; then
  1331. local IUSE_BUILT=($(<"${IUSEFILE}"));
  1332. local expand;
  1333. for expand in $(echo ${USE_EXPAND} | tr '[:upper:]' '[:lower:]');
  1334. do
  1335. if [[ $1 == ${expand}_* ]]; then
  1336. expand="";
  1337. break;
  1338. fi;
  1339. done;
  1340. if [[ -n ${expand} ]]; then
  1341. if ! has $1 ${IUSE_BUILT[@]#[-+]}; then
  1342. case ${missing_action} in
  1343. true)
  1344. return 0
  1345. ;;
  1346. false)
  1347. return 1
  1348. ;;
  1349. die)
  1350. die "$PKG does not actually support the $1 USE flag!"
  1351. ;;
  1352. esac;
  1353. fi;
  1354. fi;
  1355. fi;
  1356. local USE_BUILT=$(<${USEFILE});
  1357. while [[ $# -gt 0 ]]; do
  1358. if [[ ${opt} = "-o" ]]; then
  1359. has $1 ${USE_BUILT} && return 0;
  1360. else
  1361. has $1 ${USE_BUILT} || return 1;
  1362. fi;
  1363. shift;
  1364. done;
  1365. [[ ${opt} = "-a" ]]
  1366. }
  1367. cdrom_get_cds ()
  1368. {
  1369. local cdcnt=0;
  1370. local f=;
  1371. for f in "$@";
  1372. do
  1373. ((++cdcnt));
  1374. export CDROM_CHECK_${cdcnt}="$f";
  1375. done;
  1376. export CDROM_TOTAL_CDS=${cdcnt};
  1377. export CDROM_CURRENT_CD=1;
  1378. if [[ -n ${CD_ROOT}${CD_ROOT_1} ]]; then
  1379. local var=;
  1380. cdcnt=0;
  1381. while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]]; do
  1382. ((++cdcnt));
  1383. var="CD_ROOT_${cdcnt}";
  1384. [[ -z ${!var} ]] && var="CD_ROOT";
  1385. if [[ -z ${!var} ]]; then
  1386. eerror "You must either use just the CD_ROOT";
  1387. eerror "or specify ALL the CD_ROOT_X variables.";
  1388. eerror "In this case, you will need ${CDROM_TOTAL_CDS} CD_ROOT_X variables.";
  1389. die "could not locate CD_ROOT_${cdcnt}";
  1390. fi;
  1391. done;
  1392. export CDROM_ROOT=${CD_ROOT_1:-${CD_ROOT}};
  1393. einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}";
  1394. export CDROM_SET=-1;
  1395. for f in ${CDROM_CHECK_1//:/ };
  1396. do
  1397. ((++CDROM_SET));
  1398. [[ -e ${CDROM_ROOT}/${f} ]] && break;
  1399. done;
  1400. export CDROM_MATCH=${f};
  1401. return;
  1402. fi;
  1403. if [[ ${CDROM_TOTAL_CDS} -eq 1 ]]; then
  1404. einfo "This ebuild will need the ${CDROM_NAME:-cdrom for ${PN}}";
  1405. echo;
  1406. einfo "If you do not have the CD, but have the data files";
  1407. einfo "mounted somewhere on your filesystem, just export";
  1408. einfo "the variable CD_ROOT so that it points to the";
  1409. einfo "directory containing the files.";
  1410. echo;
  1411. einfo "For example:";
  1412. einfo "export CD_ROOT=/mnt/cdrom";
  1413. echo;
  1414. else
  1415. if [[ -n ${CDROM_NAME_SET} ]]; then
  1416. cdcnt=0;
  1417. while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]]; do
  1418. ((++cdcnt));
  1419. export CDROM_NAME_${cdcnt}="${CDROM_NAME_SET[$((${cdcnt}-1))]}";
  1420. done;
  1421. fi;
  1422. einfo "This package will need access to ${CDROM_TOTAL_CDS} cds.";
  1423. cdcnt=0;
  1424. while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]]; do
  1425. ((++cdcnt));
  1426. var="CDROM_NAME_${cdcnt}";
  1427. [[ ! -z ${!var} ]] && einfo " CD ${cdcnt}: ${!var}";
  1428. done;
  1429. echo;
  1430. einfo "If you do not have the CDs, but have the data files";
  1431. einfo "mounted somewhere on your filesystem, just export";
  1432. einfo "the following variables so they point to the right place:";
  1433. einfon "";
  1434. cdcnt=0;
  1435. while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]]; do
  1436. ((++cdcnt));
  1437. echo -n " CD_ROOT_${cdcnt}";
  1438. done;
  1439. echo;
  1440. einfo "Or, if you have all the files in the same place, or";
  1441. einfo "you only have one cdrom, you can export CD_ROOT";
  1442. einfo "and that place will be used as the same data source";
  1443. einfo "for all the CDs.";
  1444. echo;
  1445. einfo "For example:";
  1446. einfo "export CD_ROOT_1=/mnt/cdrom";
  1447. echo;
  1448. fi;
  1449. export CDROM_SET="";
  1450. export CDROM_CURRENT_CD=0;
  1451. cdrom_load_next_cd
  1452. }
  1453. cdrom_load_next_cd ()
  1454. {
  1455. local var;
  1456. ((++CDROM_CURRENT_CD));
  1457. unset CDROM_ROOT;
  1458. var=CD_ROOT_${CDROM_CURRENT_CD};
  1459. [[ -z ${!var} ]] && var="CD_ROOT";
  1460. if [[ -z ${!var} ]]; then
  1461. var="CDROM_CHECK_${CDROM_CURRENT_CD}";
  1462. _cdrom_locate_file_on_cd ${!var};
  1463. else
  1464. export CDROM_ROOT=${!var};
  1465. fi;
  1466. einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
  1467. }
  1468. check_license ()
  1469. {
  1470. die "you no longer need this as portage supports ACCEPT_LICENSE itself"
  1471. }
  1472. darwintoolize ()
  1473. {
  1474. die "Use elibtoolize"
  1475. }
  1476. dlopen_lib ()
  1477. {
  1478. case "${CHOST}" in
  1479. *-linux-gnu* | *-linux-uclibc | *-interix*)
  1480. echo "-ldl"
  1481. ;;
  1482. esac
  1483. }
  1484. doicon ()
  1485. {
  1486. ( local i j ret;
  1487. insinto /usr/share/pixmaps;
  1488. for i in "$@";
  1489. do
  1490. if [[ -f ${i} ]]; then
  1491. doins "${i}";
  1492. ((ret+=$?));
  1493. else
  1494. if [[ -d ${i} ]]; then
  1495. for j in "${i}"/*.png;
  1496. do
  1497. doins "${j}";
  1498. ((ret+=$?));
  1499. done;
  1500. else
  1501. ((++ret));
  1502. fi;
  1503. fi;
  1504. done;
  1505. exit ${ret} )
  1506. }
  1507. domenu ()
  1508. {
  1509. ( local i j ret=0;
  1510. insinto /usr/share/applications;
  1511. for i in "$@";
  1512. do
  1513. if [[ -f ${i} ]]; then
  1514. doins "${i}";
  1515. ((ret+=$?));
  1516. else
  1517. if [[ -d ${i} ]]; then
  1518. for j in "${i}"/*.desktop;
  1519. do
  1520. doins "${j}";
  1521. ((ret+=$?));
  1522. done;
  1523. else
  1524. ((++ret));
  1525. fi;
  1526. fi;
  1527. done;
  1528. exit ${ret} )
  1529. }
  1530. eaclocal ()
  1531. {
  1532. [[ ! -f aclocal.m4 || -n $(grep -e 'generated.*by aclocal' aclocal.m4) ]] && autotools_run_tool --at-m4flags aclocal "$@" $(eaclocal_amflags)
  1533. }
  1534. eaclocal_amflags ()
  1535. {
  1536. local aclocal_opts amflags_file;
  1537. for amflags_file in GNUmakefile.am Makefile.am GNUmakefile.in Makefile.in;
  1538. do
  1539. [[ -e ${amflags_file} ]] || continue;
  1540. autotools_env_setup;
  1541. aclocal_opts=$(sed -n "/^ACLOCAL_AMFLAGS[[:space:]]*=/{ # match the first line
  1542. s:[^=]*=::p; # then gobble up all escaped lines
  1543. : nextline /\\\\$/{ n; p; b nextline; } }" ${amflags_file});
  1544. eval aclocal_opts=\""${aclocal_opts}"\";
  1545. break;
  1546. done;
  1547. echo ${aclocal_opts}
  1548. }
  1549. eautoconf ()
  1550. {
  1551. if [[ ! -f configure.ac && ! -f configure.in ]]; then
  1552. echo;
  1553. eerror "No configure.{ac,in} present in '${PWD}'!";
  1554. echo;
  1555. die "No configure.{ac,in} present!";
  1556. fi;
  1557. autotools_run_tool --at-m4flags autoconf "$@"
  1558. }
  1559. eautoheader ()
  1560. {
  1561. [[ -n $(autotools_check_macro "AC_CONFIG_HEADERS") ]] || return 0;
  1562. autotools_run_tool --at-no-fail --at-m4flags autoheader "$@"
  1563. }
  1564. eautomake ()
  1565. {
  1566. local extra_opts;
  1567. local makefile_name;
  1568. for makefile_name in {GNUmakefile,{M,m}akefile}.{am,in} "";
  1569. do
  1570. [[ -f ${makefile_name} ]] && break;
  1571. done;
  1572. [[ -z ${makefile_name} ]] && return 0;
  1573. if [[ ${makefile_name} == *.in ]]; then
  1574. if ! grep -qs AM_INIT_AUTOMAKE configure.??; then
  1575. return 0;
  1576. fi;
  1577. else
  1578. if [[ -z ${FROM_EAUTORECONF} && -f ${makefile_name%.am}.in ]]; then
  1579. local used_automake;
  1580. local installed_automake;
  1581. installed_automake=$(WANT_AUTOMAKE= automake --version | head -n 1 | sed -e 's:.*(GNU automake) ::');
  1582. used_automake=$(head -n 1 < ${makefile_name%.am}.in | sed -e 's:.*by automake \(.*\) from .*:\1:');
  1583. if [[ ${installed_automake} != ${used_automake} ]]; then
  1584. einfo "Automake used for the package (${used_automake}) differs from";
  1585. einfo "the installed version (${installed_automake}).";
  1586. eautoreconf;
  1587. return 0;
  1588. fi;
  1589. fi;
  1590. fi;
  1591. [[ -f INSTALL && -f AUTHORS && -f ChangeLog && -f NEWS && -f README ]] || extra_opts="${extra_opts} --foreign";
  1592. autotools_run_tool automake --add-missing --copy ${extra_opts} "$@"
  1593. }
  1594. eautopoint ()
  1595. {
  1596. autotools_run_tool autopoint "$@"
  1597. }
  1598. eautoreconf ()
  1599. {
  1600. local x auxdir g;
  1601. if [[ -z ${AT_NO_RECURSIVE} ]]; then
  1602. for x in $(autotools_get_subdirs);
  1603. do
  1604. if [[ -d ${x} ]]; then
  1605. pushd "${x}" > /dev/null;
  1606. AT_NOELIBTOOLIZE="yes" eautoreconf;
  1607. popd > /dev/null;
  1608. fi;
  1609. done;
  1610. fi;
  1611. auxdir=$(autotools_get_auxdir);
  1612. einfo "Running eautoreconf in '${PWD}' ...";
  1613. [[ -n ${auxdir} ]] && mkdir -p ${auxdir};
  1614. eaclocal;
  1615. [[ ${CHOST} == *-darwin* ]] && g=g;
  1616. if ${LIBTOOLIZE:-${g}libtoolize} -n --install &>/dev/null; then
  1617. _elibtoolize --copy --force --install;
  1618. else
  1619. _elibtoolize --copy --force;
  1620. fi;
  1621. eautoconf;
  1622. eautoheader;
  1623. FROM_EAUTORECONF="yes" eautomake ${AM_OPTS};
  1624. [[ ${AT_NOELIBTOOLIZE} == "yes" ]] && return 0;
  1625. S=${PWD} elibtoolize --force;
  1626. return 0
  1627. }
  1628. ebeep ()
  1629. {
  1630. ewarn "QA Notice: ebeep is not defined in EAPI=${EAPI}, please file a bug at http://bugs.gentoo.org"
  1631. }
  1632. econf_build ()
  1633. {
  1634. tc-env_build econf --build=${CBUILD:-${CHOST}} "$@"
  1635. }
  1636. ecvs_clean ()
  1637. {
  1638. [[ -z $* ]] && set -- .;
  1639. find "$@" -type d -name 'CVS' -prune -print0 | xargs -0 rm -rf;
  1640. find "$@" -type f -name '.cvs*' -print0 | xargs -0 rm -rf
  1641. }
  1642. edos2unix ()
  1643. {
  1644. [[ $# -eq 0 ]] && return 0;
  1645. sed -i 's/\r$//' -- "$@" || die
  1646. }
  1647. egacinstall ()
  1648. {
  1649. use !prefix && has "${EAPI:-0}" 0 1 2 && ED="${D}";
  1650. gacutil -i "${1}" -root "${ED}"/usr/$(get_libdir) -gacdir /usr/$(get_libdir) -package ${2:-${GACPN:-${PN}}} || die "installing ${1} into the Global Assembly Cache failed"
  1651. }
  1652. egetent ()
  1653. {
  1654. local db=$1 key=$2;
  1655. [[ $# -ge 3 ]] && die "usage: egetent <database> <key>";
  1656. case ${db} in
  1657. passwd | group)
  1658.  
  1659. ;;
  1660. *)
  1661. die "sorry, database '${db}' not yet supported; file a bug"
  1662. ;;
  1663. esac;
  1664. case ${CHOST} in
  1665. *-darwin[678])
  1666. case ${key} in
  1667. *[!0-9]*)
  1668. nidump ${db} . | awk -F: "(\$1 ~ /^${key}\$/) {print;exit;}"
  1669. ;;
  1670. *)
  1671. nidump ${db} . | awk -F: "(\$3 == ${key}) {print;exit;}"
  1672. ;;
  1673. esac
  1674. ;;
  1675. *-darwin*)
  1676. local mykey;
  1677. case ${db} in
  1678. passwd)
  1679. db="Users" mykey="UniqueID"
  1680. ;;
  1681. group)
  1682. db="Groups" mykey="PrimaryGroupID"
  1683. ;;
  1684. esac;
  1685. case ${key} in
  1686. *[!0-9]*)
  1687. dscl . -read /${db}/${key} 2> /dev/null | grep RecordName
  1688. ;;
  1689. *)
  1690. dscl . -search /${db} ${mykey} ${key} 2> /dev/null
  1691. ;;
  1692. esac
  1693. ;;
  1694. *-freebsd* | *-dragonfly*)
  1695. case ${db} in
  1696. passwd)
  1697. db="user"
  1698. ;;
  1699. *)
  1700.  
  1701. ;;
  1702. esac;
  1703. local opts;
  1704. if [[ ${key} == [[:digit:]]* ]]; then
  1705. [[ ${db} == "user" ]] && opts="-u" || opts="-g";
  1706. fi;
  1707. pw show ${db} ${opts} "${key}" -q
  1708. ;;
  1709. *-netbsd* | *-openbsd*)
  1710. grep "${key}:\*:" /etc/${db}
  1711. ;;
  1712. *)
  1713. nscd -i "${db}" 2> /dev/null;
  1714. getent "${db}" "${key}"
  1715. ;;
  1716. esac
  1717. }
  1718. egethome ()
  1719. {
  1720. local pos;
  1721. [[ $# -eq 1 ]] || die "usage: egethome <user>";
  1722. case ${CHOST} in
  1723. *-darwin* | *-freebsd* | *-dragonfly*)
  1724. pos=9
  1725. ;;
  1726. *)
  1727. pos=6
  1728. ;;
  1729. esac;
  1730. egetent passwd "$1" | cut -d: -f${pos}
  1731. }
  1732. egetshell ()
  1733. {
  1734. local pos;
  1735. [[ $# -eq 1 ]] || die "usage: egetshell <user>";
  1736. case ${CHOST} in
  1737. *-darwin* | *-freebsd* | *-dragonfly*)
  1738. pos=10
  1739. ;;
  1740. *)
  1741. pos=7
  1742. ;;
  1743. esac;
  1744. egetent passwd "$1" | cut -d: -f${pos}
  1745. }
  1746. elibtoolize ()
  1747. {
  1748. local x;
  1749. local do_portage="no";
  1750. local do_reversedeps="no";
  1751. local do_only_patches="no";
  1752. local do_uclibc="yes";
  1753. local deptoremove=;
  1754. local do_shallow="no";
  1755. local force="false";
  1756. local elt_patches="install-sh ltmain portage relink max_cmd_len sed test tmp cross as-needed";
  1757. for x in "$@";
  1758. do
  1759. case ${x} in
  1760. --portage)
  1761. do_portage="yes"
  1762. ;;
  1763. --reverse-deps)
  1764. do_reversedeps="yes";
  1765. elt_patches+=" fix-relink"
  1766. ;;
  1767. --patch-only)
  1768. do_only_patches="yes"
  1769. ;;
  1770. --remove-internal-dep=*)
  1771. deptoremove=${x#--remove-internal-dep=};
  1772. [[ -n ${deptoremove} ]] && elt_patches+=" rem-int-dep"
  1773. ;;
  1774. --shallow)
  1775. do_shallow="yes"
  1776. ;;
  1777. --no-uclibc)
  1778. do_uclibc="no"
  1779. ;;
  1780. --force)
  1781. force="true"
  1782. ;;
  1783. *)
  1784. eerror "Invalid elibtoolize option: ${x}";
  1785. die "elibtoolize called with ${x} ??"
  1786. ;;
  1787. esac;
  1788. done;
  1789. [[ ${do_uclibc} == "yes" ]] && elt_patches+=" uclibc-conf uclibc-ltconf";
  1790. case ${CHOST} in
  1791. *-aix*)
  1792. elt_patches+=" hardcode aixrtl aix-noundef"
  1793. ;;
  1794. *-darwin*)
  1795. elt_patches+=" darwin-ltconf darwin-ltmain darwin-conf"
  1796. ;;
  1797. *-freebsd*)
  1798. elt_patches+=" fbsd-conf fbsd-ltconf"
  1799. ;;
  1800. *-hpux*)
  1801. elt_patches+=" hpux-conf deplibs hc-flag-ld hardcode hardcode-relink relink-prog no-lc"
  1802. ;;
  1803. *-irix*)
  1804. elt_patches+=" irix-ltmain"
  1805. ;;
  1806. *-mint*)
  1807. elt_patches+=" mint-conf"
  1808. ;;
  1809. esac;
  1810. if $(tc-getLD) --version 2>&1 | grep -qs 'GNU gold'; then
  1811. elt_patches+=" gold-conf";
  1812. fi;
  1813. set --;
  1814. if [[ ${do_shallow} == "yes" ]]; then
  1815. [[ -f ${S}/ltmain.sh ]] && set -- "${S}";
  1816. else
  1817. set -- $(find "${S}" -name ltmain.sh -printf '%h ');
  1818. fi;
  1819. local d p;
  1820. for d in "$@";
  1821. do
  1822. export ELT_APPLIED_PATCHES=;
  1823. if [[ -f ${d}/.elibtoolized ]]; then
  1824. ${force} || continue;
  1825. fi;
  1826. local outfunc="einfo";
  1827. [[ -f ${d}/.elibtoolized ]] && outfunc="ewarn";
  1828. ${outfunc} "Running elibtoolize in: ${d#${WORKDIR}/}/";
  1829. if [[ ${outfunc} == "ewarn" ]]; then
  1830. ewarn " We've already been run in this tree; you should";
  1831. ewarn " avoid this if possible (perhaps by filing a bug)";
  1832. fi;
  1833. for p in ${elt_patches};
  1834. do
  1835. local ret=0;
  1836. case ${p} in
  1837. portage)
  1838. if ! grep -qs 'We do not want portage' "${d}/ltmain.sh"; then
  1839. ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1840. ret=$?;
  1841. fi
  1842. ;;
  1843. rem-int-dep)
  1844. ELT_walk_patches "${d}/ltmain.sh" "${p}" "${deptoremove}";
  1845. ret=$?
  1846. ;;
  1847. fix-relink)
  1848. if grep -qs 'inst_prefix_dir' "${d}/ltmain.sh"; then
  1849. ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1850. ret=$?;
  1851. fi
  1852. ;;
  1853. max_cmd_len)
  1854. if grep -qs 'max_cmd_len' "${d}/ltmain.sh"; then
  1855. ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1856. ret=$?;
  1857. fi
  1858. ;;
  1859. as-needed)
  1860. ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1861. ret=$?
  1862. ;;
  1863. uclibc-conf)
  1864. if grep -qs 'Transform linux' "${d}/configure"; then
  1865. ELT_walk_patches "${d}/configure" "${p}";
  1866. ret=$?;
  1867. else
  1868. if [[ ! -e ${d}/configure ]] && grep -qs 'Transform linux' "${d}/../configure"; then
  1869. ELT_walk_patches "${d}/../configure" "${p}";
  1870. ret=$?;
  1871. fi;
  1872. fi
  1873. ;;
  1874. uclibc-ltconf)
  1875. if [[ -s ${d}/ltconfig ]]; then
  1876. ELT_walk_patches "${d}/ltconfig" "${p}";
  1877. ret=$?;
  1878. fi
  1879. ;;
  1880. fbsd-conf)
  1881. if grep -qs 'version_type=freebsd-' "${d}/configure"; then
  1882. ELT_walk_patches "${d}/configure" "${p}";
  1883. ret=$?;
  1884. else
  1885. if [[ ! -e ${d}/configure ]] && grep -qs 'version_type=freebsd-' "${d}/../configure"; then
  1886. ELT_walk_patches "${d}/../configure" "${p}";
  1887. ret=$?;
  1888. fi;
  1889. fi
  1890. ;;
  1891. fbsd-ltconf)
  1892. if [[ -s ${d}/ltconfig ]]; then
  1893. ELT_walk_patches "${d}/ltconfig" "${p}";
  1894. ret=$?;
  1895. fi
  1896. ;;
  1897. darwin-conf)
  1898. if grep -qs '&& echo \.so ||' "${d}/configure"; then
  1899. ELT_walk_patches "${d}/configure" "${p}";
  1900. ret=$?;
  1901. else
  1902. if [[ ! -e ${d}/configure ]] && grep -qs '&& echo \.so ||' "${d}/../configure"; then
  1903. ELT_walk_patches "${d}/../configure" "${p}";
  1904. ret=$?;
  1905. fi;
  1906. fi
  1907. ;;
  1908. darwin-ltconf)
  1909. if [[ -s ${d}/ltconfig ]]; then
  1910. ELT_walk_patches "${d}/ltconfig" "${p}";
  1911. ret=$?;
  1912. fi
  1913. ;;
  1914. darwin-ltmain)
  1915. if [[ -e ${d}/ltmain.sh ]] && ! grep -qs 'verstring="-compatibility_version' "${d}/ltmain.sh"; then
  1916. ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1917. ret=$?;
  1918. fi
  1919. ;;
  1920. aixrtl | hpux-conf)
  1921. ret=1;
  1922. local subret=0;
  1923. while [[ $subret -eq 0 ]]; do
  1924. subret=1;
  1925. if [[ -e ${d}/configure ]]; then
  1926. ELT_walk_patches "${d}/configure" "${p}";
  1927. subret=$?;
  1928. else
  1929. if [[ ! -e ${d}/configure && -e ${d}/../configure ]]; then
  1930. ELT_walk_patches "${d}/../configure" "${p}";
  1931. subret=$?;
  1932. fi;
  1933. fi;
  1934. if [[ $subret -eq 0 ]]; then
  1935. ret=0;
  1936. fi;
  1937. done
  1938. ;;
  1939. mint-conf | gold-conf)
  1940. ret=1;
  1941. local subret=1;
  1942. if [[ -e ${d}/configure ]]; then
  1943. ELT_walk_patches "${d}/configure" "${p}";
  1944. subret=$?;
  1945. else
  1946. if [[ -e ${d}/../configure ]]; then
  1947. ELT_walk_patches "${d}/../configure" "${p}";
  1948. subret=$?;
  1949. else
  1950. if [[ -e ${d}/../../configure ]]; then
  1951. ELT_walk_patches "${d}/../../configure" "${p}";
  1952. subret=$?;
  1953. fi;
  1954. fi;
  1955. fi;
  1956. if [[ $subret -eq 0 ]]; then
  1957. ret=0;
  1958. fi
  1959. ;;
  1960. install-sh)
  1961. ELT_walk_patches "${d}/install-sh" "${p}";
  1962. ret=$?
  1963. ;;
  1964. cross)
  1965. if tc-is-cross-compiler; then
  1966. ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1967. ret=$?;
  1968. fi
  1969. ;;
  1970. *)
  1971. ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1972. ret=$?
  1973. ;;
  1974. esac;
  1975. if [[ ${ret} -ne 0 ]]; then
  1976. case ${p} in
  1977. relink)
  1978. local version=$(ELT_libtool_version "${d}/ltmain.sh");
  1979. if ! grep -qs 'inst_prefix_dir' "${d}/ltmain.sh" && [[ $(VER_to_int "${version}") -ge $(VER_to_int "1.4.0") ]]; then
  1980. ewarn " Could not apply relink.patch!";
  1981. fi
  1982. ;;
  1983. portage)
  1984. if [[ ${do_portage} == "yes" ]]; then
  1985. if ! grep -qs 'We do not want portage' "${d}/ltmain.sh"; then
  1986. echo;
  1987. eerror "Portage patch requested, but failed to apply!";
  1988. eerror "Please file a bug report to add a proper patch.";
  1989. die "Portage patch requested, but failed to apply!";
  1990. fi;
  1991. else
  1992. if grep -qs 'We do not want portage' "${d}/ltmain.sh"; then
  1993. :;
  1994. else
  1995. local version=$(ELT_libtool_version "${d}"/ltmain.sh);
  1996. echo;
  1997. eerror "Portage patch failed to apply (ltmain.sh version ${version})!";
  1998. eerror "Please file a bug report to add a proper patch.";
  1999. die "Portage patch failed to apply!";
  2000. fi;
  2001. ELT_APPLIED_PATCHES="portage";
  2002. fi
  2003. ;;
  2004. uclibc-*)
  2005. [[ ${CHOST} == *-uclibc ]] && ewarn " uClibc patch set '${p}' failed to apply!"
  2006. ;;
  2007. fbsd-*)
  2008. if [[ ${CHOST} == *-freebsd* ]]; then
  2009. if [[ -z $(grep 'Handle Gentoo/FreeBSD as it was Linux' "${d}/configure" "${d}/../configure" 2>/dev/null) ]]; then
  2010. eerror " FreeBSD patch set '${p}' failed to apply!";
  2011. die "FreeBSD patch set '${p}' failed to apply!";
  2012. fi;
  2013. fi
  2014. ;;
  2015. darwin-*)
  2016. [[ ${CHOST} == *"-darwin"* ]] && ewarn " Darwin patch set '${p}' failed to apply!"
  2017. ;;
  2018. esac;
  2019. fi;
  2020. done;
  2021. if [[ -z ${ELT_APPLIED_PATCHES} ]]; then
  2022. if [[ ${do_portage} == "no" && ${do_reversedeps} == "no" && ${do_only_patches} == "no" && ${deptoremove} == "" ]]; then
  2023. ewarn "Cannot apply any patches, please file a bug about this";
  2024. die;
  2025. fi;
  2026. fi;
  2027. rm -f "${d}/libtool";
  2028. > "${d}/.elibtoolized";
  2029. done
  2030. }
  2031. elt_patch_dir ()
  2032. {
  2033. local d="${ECLASSDIR}/ELT-patches";
  2034. if [[ ! -d ${d} ]]; then
  2035. d="${ECLASSDIR_LOCAL}/ELT-patches";
  2036. fi;
  2037. echo "${d}"
  2038. }
  2039. emktemp ()
  2040. {
  2041. local exe="touch";
  2042. [[ $1 == -d ]] && exe="mkdir" && shift;
  2043. local topdir=$1;
  2044. if [[ -z ${topdir} ]]; then
  2045. [[ -z ${T} ]] && topdir="/tmp" || topdir=${T};
  2046. fi;
  2047. if ! type -P mktemp > /dev/null; then
  2048. local tmp=/;
  2049. while [[ -e ${tmp} ]]; do
  2050. tmp=${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM};
  2051. done;
  2052. ${exe} "${tmp}" || ${exe} -p "${tmp}";
  2053. echo "${tmp}";
  2054. else
  2055. if [[ ${exe} == "touch" ]]; then
  2056. TMPDIR="${topdir}" mktemp -t tmp.XXXXXXXXXX;
  2057. else
  2058. TMPDIR="${topdir}" mktemp -dt tmp.XXXXXXXXXX;
  2059. fi;
  2060. fi
  2061. }
  2062. enewgroup ()
  2063. {
  2064. _assert_pkg_ebuild_phase ${FUNCNAME};
  2065. local egroup=$1;
  2066. shift;
  2067. if [[ -z ${egroup} ]]; then
  2068. eerror "No group specified !";
  2069. die "Cannot call enewgroup without a group";
  2070. fi;
  2071. if [[ -n $(egetent group "${egroup}") ]]; then
  2072. return 0;
  2073. fi;
  2074. einfo "Adding group '${egroup}' to your system ...";
  2075. local egid=$1;
  2076. shift;
  2077. if [[ ! -z ${egid} ]]; then
  2078. if [[ ${egid} -gt 0 ]]; then
  2079. if [[ -n $(egetent group ${egid}) ]]; then
  2080. egid="next available; requested gid taken";
  2081. fi;
  2082. else
  2083. eerror "Groupid given but is not greater than 0 !";
  2084. die "${egid} is not a valid GID";
  2085. fi;
  2086. else
  2087. egid="next available";
  2088. fi;
  2089. einfo " - Groupid: ${egid}";
  2090. if [[ $# -gt 0 ]]; then
  2091. die "extra arguments no longer supported; please file a bug";
  2092. fi;
  2093. function _enewgroup_next_gid ()
  2094. {
  2095. if [[ ${egid} == *[!0-9]* ]]; then
  2096. for ((egid = 101; egid <= 999; egid++))
  2097. do
  2098. [[ -z $(egetent group ${egid}) ]] && break;
  2099. done;
  2100. fi
  2101. };
  2102. case ${CHOST} in
  2103. *-darwin*)
  2104. _enewgroup_next_gid;
  2105. dscl . create "/groups/${egroup}" gid ${egid};
  2106. dscl . create "/groups/${egroup}" passwd '*'
  2107. ;;
  2108. *-freebsd* | *-dragonfly*)
  2109. _enewgroup_next_gid;
  2110. pw groupadd "${egroup}" -g ${egid} || die
  2111. ;;
  2112. *-netbsd*)
  2113. _enewgroup_next_gid;
  2114. groupadd -g ${egid} "${egroup}" || die
  2115. ;;
  2116. *)
  2117. local opts;
  2118. if [[ ${egid} == *[!0-9]* ]]; then
  2119. opts="";
  2120. else
  2121. opts="-g ${egid}";
  2122. fi;
  2123. groupadd -r ${opts} "${egroup}" || die
  2124. ;;
  2125. esac
  2126. }
  2127. enewuser ()
  2128. {
  2129. _assert_pkg_ebuild_phase ${FUNCNAME};
  2130. local euser=$1;
  2131. shift;
  2132. if [[ -z ${euser} ]]; then
  2133. eerror "No username specified !";
  2134. die "Cannot call enewuser without a username";
  2135. fi;
  2136. if [[ -n $(egetent passwd "${euser}") ]]; then
  2137. return 0;
  2138. fi;
  2139. einfo "Adding user '${euser}' to your system ...";
  2140. local opts=();
  2141. local euid=$1;
  2142. shift;
  2143. if [[ -n ${euid} && ${euid} != -1 ]]; then
  2144. if [[ ${euid} -gt 0 ]]; then
  2145. if [[ -n $(egetent passwd ${euid}) ]]; then
  2146. euid="next";
  2147. fi;
  2148. else
  2149. eerror "Userid given but is not greater than 0 !";
  2150. die "${euid} is not a valid UID";
  2151. fi;
  2152. else
  2153. euid="next";
  2154. fi;
  2155. if [[ ${euid} == "next" ]]; then
  2156. for ((euid = 101; euid <= 999; euid++))
  2157. do
  2158. [[ -z $(egetent passwd ${euid}) ]] && break;
  2159. done;
  2160. fi;
  2161. opts+=(-u ${euid});
  2162. einfo " - Userid: ${euid}";
  2163. local eshell=$1;
  2164. shift;
  2165. if [[ ! -z ${eshell} ]] && [[ ${eshell} != "-1" ]]; then
  2166. if [[ ! -e ${ROOT}${eshell} ]]; then
  2167. eerror "A shell was specified but it does not exist !";
  2168. die "${eshell} does not exist in ${ROOT}";
  2169. fi;
  2170. if [[ ${eshell} == */false || ${eshell} == */nologin ]]; then
  2171. eerror "Do not specify ${eshell} yourself, use -1";
  2172. die "Pass '-1' as the shell parameter";
  2173. fi;
  2174. else
  2175. for eshell in /sbin/nologin /usr/sbin/nologin /bin/false /usr/bin/false /dev/null;
  2176. do
  2177. [[ -x ${ROOT}${eshell} ]] && break;
  2178. done;
  2179. if [[ ${eshell} == "/dev/null" ]]; then
  2180. eerror "Unable to identify the shell to use, proceeding with userland default.";
  2181. case ${USERLAND} in
  2182. GNU)
  2183. eshell="/bin/false"
  2184. ;;
  2185. BSD)
  2186. eshell="/sbin/nologin"
  2187. ;;
  2188. Darwin)
  2189. eshell="/usr/sbin/nologin"
  2190. ;;
  2191. *)
  2192. die "Unable to identify the default shell for userland ${USERLAND}"
  2193. ;;
  2194. esac;
  2195. fi;
  2196. fi;
  2197. einfo " - Shell: ${eshell}";
  2198. opts+=(-s "${eshell}");
  2199. local ehome=$1;
  2200. shift;
  2201. if [[ -z ${ehome} ]] || [[ ${ehome} == "-1" ]]; then
  2202. ehome="/dev/null";
  2203. fi;
  2204. einfo " - Home: ${ehome}";
  2205. opts+=(-d "${ehome}");
  2206. local egroups=$1;
  2207. shift;
  2208. local g egroups_arr;
  2209. IFS="," read -r -a egroups_arr <<< "${egroups}";
  2210. shift;
  2211. if [[ ${#egroups_arr[@]} -gt 0 ]]; then
  2212. local defgroup exgroups;
  2213. for g in "${egroups_arr[@]}";
  2214. do
  2215. if [[ -z $(egetent group "${g}") ]]; then
  2216. eerror "You must add group ${g} to the system first";
  2217. die "${g} is not a valid GID";
  2218. fi;
  2219. if [[ -z ${defgroup} ]]; then
  2220. defgroup=${g};
  2221. else
  2222. exgroups+=",${g}";
  2223. fi;
  2224. done;
  2225. opts+=(-g "${defgroup}");
  2226. if [[ ! -z ${exgroups} ]]; then
  2227. opts+=(-G "${exgroups:1}");
  2228. fi;
  2229. fi;
  2230. einfo " - Groups: ${egroups:-(none)}";
  2231. if [[ $# -gt 0 ]]; then
  2232. die "extra arguments no longer supported; please file a bug";
  2233. else
  2234. local comment="added by portage for ${PN}";
  2235. opts+=(-c "${comment}");
  2236. einfo " - GECOS: ${comment}";
  2237. fi;
  2238. case ${CHOST} in
  2239. *-darwin*)
  2240. dscl . create "/users/${euser}" uid ${euid};
  2241. dscl . create "/users/${euser}" shell "${eshell}";
  2242. dscl . create "/users/${euser}" home "${ehome}";
  2243. dscl . create "/users/${euser}" realname "added by portage for ${PN}";
  2244. for g in "${egroups_arr[@]}";
  2245. do
  2246. dscl . merge "/groups/${g}" users "${euser}";
  2247. done
  2248. ;;
  2249. *-freebsd* | *-dragonfly*)
  2250. pw useradd "${euser}" "${opts[@]}" || die
  2251. ;;
  2252. *-netbsd*)
  2253. useradd "${opts[@]}" "${euser}" || die
  2254. ;;
  2255. *-openbsd*)
  2256. useradd -u ${euid} -s "${eshell}" -d "${ehome}" -g "${egroups}" "${euser}" || die
  2257. ;;
  2258. *)
  2259. useradd -r "${opts[@]}" "${euser}" || die
  2260. ;;
  2261. esac;
  2262. if [[ ! -e ${ROOT}/${ehome} ]]; then
  2263. einfo " - Creating ${ehome} in ${ROOT}";
  2264. mkdir -p "${ROOT}/${ehome}";
  2265. chown "${euser}" "${ROOT}/${ehome}";
  2266. chmod 755 "${ROOT}/${ehome}";
  2267. fi
  2268. }
  2269. epatch ()
  2270. {
  2271. function _epatch_draw_line ()
  2272. {
  2273. [[ -z $1 ]] && set "$(printf "%65s" '')";
  2274. echo "${1//?/=}"
  2275. };
  2276. unset P4CONFIG P4PORT P4USER;
  2277. if [[ $# -gt 1 ]]; then
  2278. local m;
  2279. for m in "$@";
  2280. do
  2281. epatch "${m}";
  2282. done;
  2283. return 0;
  2284. fi;
  2285. local SINGLE_PATCH="no";
  2286. [[ $# -eq 0 ]] && set -- "${EPATCH_SOURCE}";
  2287. if [[ -f $1 ]]; then
  2288. SINGLE_PATCH="yes";
  2289. set -- "$1";
  2290. local EPATCH_SUFFIX=$1;
  2291. else
  2292. if [[ -d $1 ]]; then
  2293. set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"};
  2294. else
  2295. if [[ -f ${EPATCH_SOURCE}/$1 ]]; then
  2296. epatch "${EPATCH_SOURCE}/$1";
  2297. return $?;
  2298. else
  2299. [[ $# -ne 0 ]] && EPATCH_SOURCE=$1;
  2300. echo;
  2301. eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:";
  2302. eerror;
  2303. eerror " ${EPATCH_SOURCE}";
  2304. eerror " ( ${EPATCH_SOURCE##*/} )";
  2305. echo;
  2306. die "Cannot find \$EPATCH_SOURCE!";
  2307. fi;
  2308. fi;
  2309. fi;
  2310. local PIPE_CMD;
  2311. case ${EPATCH_SUFFIX##*\.} in
  2312. xz)
  2313. PIPE_CMD="xz -dc"
  2314. ;;
  2315. lzma)
  2316. PIPE_CMD="lzma -dc"
  2317. ;;
  2318. bz2)
  2319. PIPE_CMD="bzip2 -dc"
  2320. ;;
  2321. gz | Z | z)
  2322. PIPE_CMD="gzip -dc"
  2323. ;;
  2324. ZIP | zip)
  2325. PIPE_CMD="unzip -p"
  2326. ;;
  2327. *)
  2328.  
  2329. ;;
  2330. esac;
  2331. [[ ${SINGLE_PATCH} == "no" ]] && einfo "${EPATCH_MULTI_MSG}";
  2332. local x;
  2333. for x in "$@";
  2334. do
  2335. [[ ! -f ${x} ]] && continue;
  2336. local patchname=${x##*/};
  2337. local a=${patchname#*_};
  2338. a=${a%%_*};
  2339. if ! [[ ${SINGLE_PATCH} == "yes" || ${EPATCH_FORCE} == "yes" || ${a} == all || ${a} == ${ARCH} ]]; then
  2340. continue;
  2341. fi;
  2342. if [[ -n ${EPATCH_EXCLUDE} ]]; then
  2343. eshopts_push -o noglob;
  2344. local ex;
  2345. for ex in ${EPATCH_EXCLUDE};
  2346. do
  2347. if [[ ${patchname} == ${ex} ]]; then
  2348. eshopts_pop;
  2349. continue 2;
  2350. fi;
  2351. done;
  2352. eshopts_pop;
  2353. fi;
  2354. if [[ ${SINGLE_PATCH} == "yes" ]]; then
  2355. if [[ -n ${EPATCH_SINGLE_MSG} ]]; then
  2356. einfo "${EPATCH_SINGLE_MSG}";
  2357. else
  2358. einfo "Applying ${patchname} ...";
  2359. fi;
  2360. else
  2361. einfo " ${patchname} ...";
  2362. fi;
  2363. local STDERR_TARGET="${T}/${patchname}.out";
  2364. if [[ -e ${STDERR_TARGET} ]]; then
  2365. STDERR_TARGET="${T}/${patchname}-$$.out";
  2366. fi;
  2367. printf "***** %s *****\nPWD: %s\n\n" "${patchname}" "${PWD}" > "${STDERR_TARGET}";
  2368. local count=0;
  2369. local PATCH_TARGET;
  2370. if [[ -n ${PIPE_CMD} ]]; then
  2371. PATCH_TARGET="${T}/$$.patch";
  2372. echo "PIPE_COMMAND: ${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> "${STDERR_TARGET}";
  2373. if ! ( ${PIPE_CMD} "${x}" > "${PATCH_TARGET}" ) >> "${STDERR_TARGET}" 2>&1; then
  2374. echo;
  2375. eerror "Could not extract patch!";
  2376. count=5;
  2377. break;
  2378. fi;
  2379. else
  2380. PATCH_TARGET=${x};
  2381. fi;
  2382. local abs_paths=$(egrep -n '^[-+]{3} /' "${PATCH_TARGET}" | awk '$2 != "/dev/null" { print }');
  2383. if [[ -n ${abs_paths} ]]; then
  2384. count=1;
  2385. printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}";
  2386. fi;
  2387. local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}");
  2388. if [[ -n ${rel_paths} ]]; then
  2389. eqawarn "QA Notice: Your patch uses relative paths '../'.";
  2390. eqawarn " In the future this will cause a failure.";
  2391. eqawarn "${rel_paths}";
  2392. fi;
  2393. while [[ ${count} -lt 5 ]]; do
  2394. ( _epatch_draw_line "***** ${patchname} *****";
  2395. echo;
  2396. echo "PATCH COMMAND: patch -p${count} ${EPATCH_OPTS} < '${PATCH_TARGET}'";
  2397. echo;
  2398. _epatch_draw_line "***** ${patchname} *****";
  2399. patch -p${count} ${EPATCH_OPTS} --dry-run -f < "${PATCH_TARGET}" 2>&1;
  2400. ret=$?;
  2401. echo;
  2402. echo "patch program exited with status ${ret}";
  2403. exit ${ret} ) >> "${STDERR_TARGET}";
  2404. if [ $? -eq 0 ]; then
  2405. ( _epatch_draw_line "***** ${patchname} *****";
  2406. echo;
  2407. echo "ACTUALLY APPLYING ${patchname} ...";
  2408. echo;
  2409. _epatch_draw_line "***** ${patchname} *****";
  2410. patch -p${count} ${EPATCH_OPTS} < "${PATCH_TARGET}" 2>&1;
  2411. ret=$?;
  2412. echo;
  2413. echo "patch program exited with status ${ret}";
  2414. exit ${ret} ) >> "${STDERR_TARGET}";
  2415. if [ $? -ne 0 ]; then
  2416. echo;
  2417. eerror "A dry-run of patch command succeeded, but actually";
  2418. eerror "applying the patch failed!";
  2419. count=5;
  2420. fi;
  2421. break;
  2422. fi;
  2423. : $(( count++ ));
  2424. done;
  2425. if [[ -n ${PIPE_CMD} ]]; then
  2426. rm -f "${PATCH_TARGET}";
  2427. fi;
  2428. if [[ ${count} -ge 5 ]]; then
  2429. echo;
  2430. eerror "Failed Patch: ${patchname} !";
  2431. eerror " ( ${PATCH_TARGET} )";
  2432. eerror;
  2433. eerror "Include in your bugreport the contents of:";
  2434. eerror;
  2435. eerror " ${STDERR_TARGET}";
  2436. echo;
  2437. die "Failed Patch: ${patchname}!";
  2438. fi;
  2439. rm -f "${STDERR_TARGET}";
  2440. eend 0;
  2441. done;
  2442. [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching";
  2443. :
  2444. }
  2445. epatch_user ()
  2446. {
  2447. [[ $# -ne 0 ]] && die "epatch_user takes no options";
  2448. local applied="${T}/epatch_user.applied";
  2449. [[ -e ${applied} ]] && return 2;
  2450. local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches;
  2451. for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}};
  2452. do
  2453. EPATCH_SOURCE=${base}/${CTARGET}/${check};
  2454. [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check};
  2455. [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check};
  2456. if [[ -d ${EPATCH_SOURCE} ]]; then
  2457. EPATCH_SOURCE=${EPATCH_SOURCE} EPATCH_SUFFIX="patch" EPATCH_FORCE="yes" EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." epatch;
  2458. echo "${EPATCH_SOURCE}" > "${applied}";
  2459. return 0;
  2460. fi;
  2461. done;
  2462. echo "none" > "${applied}";
  2463. return 1
  2464. }
  2465. epause ()
  2466. {
  2467. ewarn "QA Notice: epause is not defined in EAPI=${EAPI}, please file a bug at http://bugs.gentoo.org"
  2468. }
  2469. epunt_cxx ()
  2470. {
  2471. local dir=$1;
  2472. [[ -z ${dir} ]] && dir=${S};
  2473. ebegin "Removing useless C++ checks";
  2474. local f;
  2475. find "${dir}" -name configure | while read f; do
  2476. patch --no-backup-if-mismatch -p0 "${f}" "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null;
  2477. done;
  2478. eend 0
  2479. }
  2480. eshopts_pop ()
  2481. {
  2482. local s;
  2483. estack_pop eshopts s || die "${FUNCNAME}: unbalanced push";
  2484. if [[ ${s} == "shopt -"* ]]; then
  2485. eval "${s}" || die "${FUNCNAME}: sanity: invalid shopt options: ${s}";
  2486. else
  2487. set +$- || die "${FUNCNAME}: sanity: invalid shell settings: $-";
  2488. set -${s} || die "${FUNCNAME}: sanity: unable to restore saved shell settings: ${s}";
  2489. fi
  2490. }
  2491. eshopts_push ()
  2492. {
  2493. if [[ $1 == -[su] ]]; then
  2494. estack_push eshopts "$(shopt -p)";
  2495. [[ $# -eq 0 ]] && return 0;
  2496. shopt "$@" || die "${FUNCNAME}: bad options to shopt: $*";
  2497. else
  2498. estack_push eshopts $-;
  2499. [[ $# -eq 0 ]] && return 0;
  2500. set "$@" || die "${FUNCNAME}: bad options to set: $*";
  2501. fi
  2502. }
  2503. estack_pop ()
  2504. {
  2505. [[ $# -eq 0 || $# -gt 2 ]] && die "estack_pop: incorrect # of arguments";
  2506. local __estack_name="__ESTACK_$1__";
  2507. shift;
  2508. local __estack_retvar=$1;
  2509. shift;
  2510. eval local __estack_i=\${#${__estack_name}\[@\]};
  2511. [[ $(( --__estack_i )) -eq -1 ]] && return 1;
  2512. if [[ -n ${__estack_retvar} ]]; then
  2513. eval ${__estack_retvar}=\"\${${__estack_name}\[${__estack_i}\]}\";
  2514. fi;
  2515. eval unset ${__estack_name}\[${__estack_i}\]
  2516. }
  2517. estack_push ()
  2518. {
  2519. [[ $# -eq 0 ]] && die "estack_push: incorrect # of arguments";
  2520. local stack_name="__ESTACK_$1__";
  2521. shift;
  2522. eval ${stack_name}+=\( \"\$@\" \)
  2523. }
  2524. esvn_clean ()
  2525. {
  2526. [[ -z $* ]] && set -- .;
  2527. find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf
  2528. }
  2529. eumask_pop ()
  2530. {
  2531. local s;
  2532. estack_pop eumask s || die "${FUNCNAME}: unbalanced push";
  2533. umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}"
  2534. }
  2535. eumask_push ()
  2536. {
  2537. estack_push eumask "$(umask)";
  2538. umask "$@" || die "${FUNCNAME}: bad options to umask: $*"
  2539. }
  2540. filter-flags ()
  2541. {
  2542. _filter-hardened "$@";
  2543. _filter-var CFLAGS "$@";
  2544. _filter-var CPPFLAGS "$@";
  2545. _filter-var CXXFLAGS "$@";
  2546. _filter-var FFLAGS "$@";
  2547. _filter-var FCFLAGS "$@";
  2548. return 0
  2549. }
  2550. filter-ldflags ()
  2551. {
  2552. _filter-var LDFLAGS "$@";
  2553. return 0
  2554. }
  2555. filter-lfs-flags ()
  2556. {
  2557. [[ $# -ne 0 ]] && die "filter-lfs-flags takes no arguments";
  2558. filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
  2559. }
  2560. filter-mfpmath ()
  2561. {
  2562. local orig_mfpmath new_math prune_math;
  2563. orig_mfpmath=$(get-flag -mfpmath);
  2564. new_math=$(get-flag mfpmath);
  2565. new_math=" ${new_math//,/ } ";
  2566. prune_math="";
  2567. for prune_math in "$@";
  2568. do
  2569. new_math=${new_math/ ${prune_math} / };
  2570. done;
  2571. new_math=$(echo ${new_math});
  2572. new_math=${new_math// /,};
  2573. if [[ -z ${new_math} ]]; then
  2574. filter-flags ${orig_mfpmath};
  2575. else
  2576. replace-flags ${orig_mfpmath} -mfpmath=${new_math};
  2577. fi;
  2578. return 0
  2579. }
  2580. find_unpackable_file ()
  2581. {
  2582. local src=$1;
  2583. if [[ -z ${src} ]]; then
  2584. src=${DISTDIR}/${A};
  2585. else
  2586. if [[ -e ${DISTDIR}/${src} ]]; then
  2587. src=${DISTDIR}/${src};
  2588. else
  2589. if [[ -e ${PWD}/${src} ]]; then
  2590. src=${PWD}/${src};
  2591. else
  2592. if [[ -e ${src} ]]; then
  2593. src=${src};
  2594. fi;
  2595. fi;
  2596. fi;
  2597. fi;
  2598. [[ ! -e ${src} ]] && return 1;
  2599. echo "${src}"
  2600. }
  2601. gcc-fullversion ()
  2602. {
  2603. _gcc_fullversion '$1.$2.$3' "$@"
  2604. }
  2605. gcc-major-version ()
  2606. {
  2607. _gcc_fullversion '$1' "$@"
  2608. }
  2609. gcc-micro-version ()
  2610. {
  2611. _gcc_fullversion '$3' "$@"
  2612. }
  2613. gcc-minor-version ()
  2614. {
  2615. _gcc_fullversion '$2' "$@"
  2616. }
  2617. gcc-specs-directive ()
  2618. {
  2619. local directive subdname subdirective;
  2620. directive="$(_gcc-specs-directive_raw $1)";
  2621. while [[ ${directive} == *%\(*\)* ]]; do
  2622. subdname=${directive/*%\(};
  2623. subdname=${subdname/\)*};
  2624. subdirective="$(_gcc-specs-directive_raw ${subdname})";
  2625. directive="${directive//\%(${subdname})/${subdirective}}";
  2626. done;
  2627. echo "${directive}";
  2628. return 0
  2629. }
  2630. gcc-specs-nostrict ()
  2631. {
  2632. local directive;
  2633. directive=$(gcc-specs-directive cc1);
  2634. return $([[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]])
  2635. }
  2636. gcc-specs-now ()
  2637. {
  2638. local directive;
  2639. directive=$(gcc-specs-directive link_command);
  2640. return $([[ "${directive/\{!nonow:}" != "${directive}" ]])
  2641. }
  2642. gcc-specs-pie ()
  2643. {
  2644. local directive;
  2645. directive=$(gcc-specs-directive cc1);
  2646. return $([[ "${directive/\{!nopie:}" != "${directive}" ]])
  2647. }
  2648. gcc-specs-relro ()
  2649. {
  2650. local directive;
  2651. directive=$(gcc-specs-directive link_command);
  2652. return $([[ "${directive/\{!norelro:}" != "${directive}" ]])
  2653. }
  2654. gcc-specs-ssp ()
  2655. {
  2656. local directive;
  2657. directive=$(gcc-specs-directive cc1);
  2658. return $([[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]])
  2659. }
  2660. gcc-specs-ssp-to-all ()
  2661. {
  2662. local directive;
  2663. directive=$(gcc-specs-directive cc1);
  2664. return $([[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]])
  2665. }
  2666. gcc-version ()
  2667. {
  2668. _gcc_fullversion '$1.$2' "$@"
  2669. }
  2670. gen_usr_ldscript ()
  2671. {
  2672. local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname);
  2673. [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/;
  2674. tc-is-static-only && return;
  2675. dodir /usr/${libdir};
  2676. if [[ $1 == "-a" ]]; then
  2677. auto=true;
  2678. shift;
  2679. dodir /${libdir};
  2680. fi;
  2681. output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p');
  2682. [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )";
  2683. for lib in "$@";
  2684. do
  2685. local tlib;
  2686. if ${auto}; then
  2687. lib="lib${lib}${suffix}";
  2688. else
  2689. [[ -r ${ED}/${libdir}/${lib} ]] || continue;
  2690. fi;
  2691. case ${CTARGET:-${CHOST}} in
  2692. *-darwin*)
  2693. if ${auto}; then
  2694. tlib=$(scanmacho -qF'%S#F' "${ED}"/usr/${libdir}/${lib});
  2695. else
  2696. tlib=$(scanmacho -qF'%S#F' "${ED}"/${libdir}/${lib});
  2697. fi;
  2698. [[ -z ${tlib} ]] && die "unable to read install_name from ${lib}";
  2699. tlib=${tlib##*/};
  2700. if ${auto}; then
  2701. mv "${ED}"/usr/${libdir}/${lib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die;
  2702. if [[ ${tlib} != ${lib%${suffix}}.*${suffix#.} ]]; then
  2703. mv "${ED}"/usr/${libdir}/${tlib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die;
  2704. fi;
  2705. rm -f "${ED}"/${libdir}/${lib};
  2706. fi;
  2707. if [[ ! -w "${ED}/${libdir}/${tlib}" ]]; then
  2708. chmod u+w "${ED}${libdir}/${tlib}";
  2709. local nowrite=yes;
  2710. fi;
  2711. install_name_tool -id "${EPREFIX}"/${libdir}/${tlib} "${ED}"/${libdir}/${tlib} || die "install_name_tool failed";
  2712. [[ -n ${nowrite} ]] && chmod u-w "${ED}${libdir}/${tlib}";
  2713. pushd "${ED}/usr/${libdir}" > /dev/null;
  2714. ln -snf "../../${libdir}/${tlib}" "${lib}";
  2715. popd > /dev/null
  2716. ;;
  2717. *-aix* | *-irix* | *64*-hpux* | *-interix* | *-winnt*)
  2718. if ${auto}; then
  2719. mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die;
  2720. tlib=$(readlink "${ED}"/${libdir}/${lib});
  2721. tlib=${tlib##*/};
  2722. if [[ -z ${tlib} ]]; then
  2723. tlib=${lib};
  2724. else
  2725. rm -f "${ED}"/${libdir}/${lib};
  2726. fi;
  2727. else
  2728. tlib=${lib};
  2729. fi;
  2730. pushd "${ED}/usr/${libdir}" > /dev/null;
  2731. ln -snf "../../${libdir}/${tlib}" "${lib}";
  2732. popd > /dev/null
  2733. ;;
  2734. hppa*-hpux*)
  2735. if ${auto}; then
  2736. tlib=$(chatr "${ED}"/usr/${libdir}/${lib} | sed -n '/internal name:/{n;s/^ *//;p;q}');
  2737. [[ -z ${tlib} ]] && tlib=${lib};
  2738. tlib=${tlib##*/};
  2739. mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die;
  2740. if [[ ${tlib} != ${lib}* ]]; then
  2741. mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die;
  2742. fi;
  2743. [[ ${tlib} != ${lib} ]] && rm -f "${ED}"/${libdir}/${lib};
  2744. else
  2745. tlib=$(chatr "${ED}"/${libdir}/${lib} | sed -n '/internal name:/{n;s/^ *//;p;q}');
  2746. [[ -z ${tlib} ]] && tlib=${lib};
  2747. tlib=${tlib##*/};
  2748. fi;
  2749. pushd "${ED}"/usr/${libdir} > /dev/null;
  2750. ln -snf "../../${libdir}/${tlib}" "${lib}";
  2751. [[ ${tlib} != ${lib} ]] && ln -snf "../../${libdir}/${tlib}" "${tlib}";
  2752. popd > /dev/null
  2753. ;;
  2754. *)
  2755. if ${auto}; then
  2756. tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib});
  2757. [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}";
  2758. mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die;
  2759. if [[ ${tlib} != ${lib}* ]]; then
  2760. mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die;
  2761. fi;
  2762. rm -f "${ED}"/${libdir}/${lib};
  2763. else
  2764. tlib=${lib};
  2765. fi;
  2766. cat > "${ED}/usr/${libdir}/${lib}" <<-END_LDSCRIPT
  2767. /* GNU ld script
  2768. Since Gentoo has critical dynamic libraries in /lib, and the static versions
  2769. in /usr/lib, we need to have a "fake" dynamic lib in /usr/lib, otherwise we
  2770. run into linking problems. This "fake" dynamic lib is a linker script that
  2771. redirects the linker to the real lib. And yes, this works in the cross-
  2772. compiling scenario as the sysroot-ed linker will prepend the real path.
  2773.  
  2774. See bug http://bugs.gentoo.org/4411 for more info.
  2775. */
  2776. ${output_format}
  2777. GROUP ( ${EPREFIX}/${libdir}/${tlib} )
  2778. END_LDSCRIPT
  2779.  
  2780. ;;
  2781. esac
  2782. fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}";
  2783. done
  2784. }
  2785. get-flag ()
  2786. {
  2787. local f findflag="$1";
  2788. for f in ${CFLAGS} ${CXXFLAGS} ${FFLAGS} ${FCFLAGS};
  2789. do
  2790. if [ "${f/${findflag}}" != "${f}" ]; then
  2791. printf "%s\n" "${f/-${findflag}=}";
  2792. return 0;
  2793. fi;
  2794. done;
  2795. return 1
  2796. }
  2797. get_abi_CFLAGS ()
  2798. {
  2799. get_abi_var CFLAGS "$@"
  2800. }
  2801. get_abi_CHOST ()
  2802. {
  2803. get_abi_var CHOST "$@"
  2804. }
  2805. get_abi_CTARGET ()
  2806. {
  2807. get_abi_var CTARGET "$@"
  2808. }
  2809. get_abi_FAKE_TARGETS ()
  2810. {
  2811. get_abi_var FAKE_TARGETS "$@"
  2812. }
  2813. get_abi_LDFLAGS ()
  2814. {
  2815. get_abi_var LDFLAGS "$@"
  2816. }
  2817. get_abi_LIBDIR ()
  2818. {
  2819. get_abi_var LIBDIR "$@"
  2820. }
  2821. get_abi_var ()
  2822. {
  2823. local flag=$1;
  2824. local abi=${2:-${ABI:-${DEFAULT_ABI:-default}}};
  2825. local var="${flag}_${abi}";
  2826. echo ${!var}
  2827. }
  2828. get_all_abis ()
  2829. {
  2830. local order="";
  2831. if [[ -z ${MULTILIB_ABIS} ]]; then
  2832. echo "default";
  2833. return 0;
  2834. fi;
  2835. for x in ${MULTILIB_ABIS};
  2836. do
  2837. if [[ ${x} != ${DEFAULT_ABI} ]]; then
  2838. order="${order:+${order} }${x}";
  2839. fi;
  2840. done;
  2841. order="${order:+${order} }${DEFAULT_ABI}";
  2842. echo ${order};
  2843. return 0
  2844. }
  2845. get_all_libdirs ()
  2846. {
  2847. local libdirs;
  2848. local abi;
  2849. local dir;
  2850. for abi in ${MULTILIB_ABIS};
  2851. do
  2852. libdirs+=" $(get_abi_LIBDIR ${abi})";
  2853. done;
  2854. [[ " ${libdirs} " != *" lib "* ]] && libdirs+=" lib";
  2855. echo "${libdirs}"
  2856. }
  2857. get_bmake ()
  2858. {
  2859. if [[ ${USERLAND} == *BSD ]]; then
  2860. echo make;
  2861. else
  2862. if [[ ${USERLAND} == "Darwin" ]]; then
  2863. echo bsdmake;
  2864. else
  2865. echo pmake;
  2866. fi;
  2867. fi
  2868. }
  2869. get_install_abis ()
  2870. {
  2871. local order="";
  2872. if [[ -z ${MULTILIB_ABIS} ]]; then
  2873. echo "default";
  2874. return 0;
  2875. fi;
  2876. if [[ ${EMULTILIB_PKG} == "true" ]]; then
  2877. for x in ${MULTILIB_ABIS};
  2878. do
  2879. if [[ ${x} != "${DEFAULT_ABI}" ]]; then
  2880. has ${x} ${ABI_DENY} || order="${order} ${x}";
  2881. fi;
  2882. done;
  2883. has ${DEFAULT_ABI} ${ABI_DENY} || order="${order} ${DEFAULT_ABI}";
  2884. if [[ -n ${ABI_ALLOW} ]]; then
  2885. local ordera="";
  2886. for x in ${order};
  2887. do
  2888. if has ${x} ${ABI_ALLOW}; then
  2889. ordera="${ordera} ${x}";
  2890. fi;
  2891. done;
  2892. order=${ordera};
  2893. fi;
  2894. else
  2895. order=${DEFAULT_ABI};
  2896. fi;
  2897. if [[ -z ${order} ]]; then
  2898. 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.";
  2899. fi;
  2900. echo ${order};
  2901. return 0
  2902. }
  2903. get_libdir ()
  2904. {
  2905. local CONF_LIBDIR;
  2906. if [ -n "${CONF_LIBDIR_OVERRIDE}" ]; then
  2907. echo ${CONF_LIBDIR_OVERRIDE};
  2908. else
  2909. get_abi_LIBDIR;
  2910. fi
  2911. }
  2912. get_libname ()
  2913. {
  2914. local libname;
  2915. local ver=$1;
  2916. case ${CHOST} in
  2917. *-cygwin | mingw* | *-mingw*)
  2918. libname="dll"
  2919. ;;
  2920. *-darwin*)
  2921. libname="dylib"
  2922. ;;
  2923. *-mint*)
  2924. libname="irrelevant"
  2925. ;;
  2926. hppa*-hpux*)
  2927. libname="sl"
  2928. ;;
  2929. *)
  2930. libname="so"
  2931. ;;
  2932. esac;
  2933. if [[ -z $* ]]; then
  2934. echo ".${libname}";
  2935. else
  2936. for ver in "$@";
  2937. do
  2938. case ${CHOST} in
  2939. *-darwin*)
  2940. echo ".${ver}.${libname}"
  2941. ;;
  2942. *-mint*)
  2943. echo ".${libname}"
  2944. ;;
  2945. *)
  2946. echo ".${libname}.${ver}"
  2947. ;;
  2948. esac;
  2949. done;
  2950. fi
  2951. }
  2952. get_modname ()
  2953. {
  2954. local modname;
  2955. local ver=$1;
  2956. case ${CHOST} in
  2957. *-darwin*)
  2958. modname="bundle"
  2959. ;;
  2960. *)
  2961. modname="so"
  2962. ;;
  2963. esac;
  2964. echo ".${modname}"
  2965. }
  2966. get_mounts ()
  2967. {
  2968. local point= node= fs= opts= foo=;
  2969. if [[ $(uname -s) == "Linux" ]]; then
  2970. while read node point fs opts foo; do
  2971. echo "${point} ${node} ${fs} ${opts}";
  2972. done < /proc/mounts;
  2973. return;
  2974. fi;
  2975. local IFS=' ';
  2976. LC_ALL=C mount -p | while read node point fs foo; do
  2977. opts=${fs#* };
  2978. fs=${fs%% *};
  2979. echo "${point// /\040} ${node// /\040} ${fs%% *} ${opts// /\040}";
  2980. done
  2981. }
  2982. has_hardened ()
  2983. {
  2984. die "$0: deprecated, please use gcc-specs-{relro,now}()!"
  2985. }
  2986. has_m32 ()
  2987. {
  2988. [ "$(tc-arch)" = "amd64" ] && has_multilib_profile && return 0;
  2989. local temp=$(emktemp);
  2990. echo "int main() { return(0); }" > "${temp}".c;
  2991. MY_CC=$(tc-getCC);
  2992. ${MY_CC/ .*/} -m32 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1;
  2993. local ret=$?;
  2994. rm -f "${temp}".c;
  2995. [[ ${ret} != 1 ]] && return 0;
  2996. return 1
  2997. }
  2998. has_m64 ()
  2999. {
  3000. local temp="$(emktemp)";
  3001. echo "int main() { return(0); }" > "${temp}".c;
  3002. MY_CC=$(tc-getCC);
  3003. ${MY_CC/ .*/} -m64 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1;
  3004. local ret=$?;
  3005. rm -f "${temp}".c;
  3006. [[ ${ret} != 1 ]] && return 0;
  3007. return 1
  3008. }
  3009. has_multilib_profile ()
  3010. {
  3011. [ -n "${MULTILIB_ABIS}" -a "${MULTILIB_ABIS}" != "${MULTILIB_ABIS/ /}" ]
  3012. }
  3013. has_pic ()
  3014. {
  3015. die "$0: deprecated, please use gcc-specs-pie()!"
  3016. }
  3017. has_pie ()
  3018. {
  3019. die "$0: deprecated, please use gcc-specs-pie()!"
  3020. }
  3021. has_ssp ()
  3022. {
  3023. die "$0: deprecated, please use gcc-specs-ssp()!"
  3024. }
  3025. has_ssp_all ()
  3026. {
  3027. die "$0: deprecated, please use gcc-specs-ssp()!"
  3028. }
  3029. in_iuse ()
  3030. {
  3031. debug-print-function ${FUNCNAME} "${@}";
  3032. [[ ${#} -eq 1 ]] || die "Invalid args to ${FUNCNAME}()";
  3033. local flag=${1};
  3034. local liuse=(${IUSE});
  3035. has "${flag}" "${liuse[@]#[+-]}"
  3036. }
  3037. is-flag ()
  3038. {
  3039. is-flagq "$@" && echo true
  3040. }
  3041. is-flagq ()
  3042. {
  3043. [[ -n $2 ]] && die "Usage: is-flag <flag>";
  3044. _is_flagq CFLAGS $1 || _is_flagq CXXFLAGS $1 || _is_flagq FFLAGS $1 || _is_flagq FCFLAGS $1
  3045. }
  3046. is-ldflag ()
  3047. {
  3048. is-ldflagq "$@" && echo true
  3049. }
  3050. is-ldflagq ()
  3051. {
  3052. [[ -n $2 ]] && die "Usage: is-ldflag <flag>";
  3053. _is_flagq LDFLAGS $1
  3054. }
  3055. is-login-disabled ()
  3056. {
  3057. _dead_portability_user_funcs
  3058. }
  3059. is_final_abi ()
  3060. {
  3061. has_multilib_profile || return 0;
  3062. set -- $(get_install_abis);
  3063. local LAST_ABI=$#;
  3064. [[ ${!LAST_ABI} == ${ABI} ]]
  3065. }
  3066. make_desktop_entry ()
  3067. {
  3068. [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable";
  3069. local exec=${1};
  3070. local name=${2:-${PN}};
  3071. local icon=${3:-${PN}};
  3072. local type=${4};
  3073. local fields=${5};
  3074. if [[ -z ${type} ]]; then
  3075. local catmaj=${CATEGORY%%-*};
  3076. local catmin=${CATEGORY##*-};
  3077. case ${catmaj} in
  3078. app)
  3079. case ${catmin} in
  3080. accessibility)
  3081. type=Accessibility
  3082. ;;
  3083. admin)
  3084. type=System
  3085. ;;
  3086. antivirus)
  3087. type=System
  3088. ;;
  3089. arch)
  3090. type=Archiving
  3091. ;;
  3092. backup)
  3093. type=Archiving
  3094. ;;
  3095. cdr)
  3096. type=DiscBurning
  3097. ;;
  3098. dicts)
  3099. type=Dictionary
  3100. ;;
  3101. doc)
  3102. type=Documentation
  3103. ;;
  3104. editors)
  3105. type=TextEditor
  3106. ;;
  3107. emacs)
  3108. type=TextEditor
  3109. ;;
  3110. emulation)
  3111. type=Emulator
  3112. ;;
  3113. laptop)
  3114. type=HardwareSettings
  3115. ;;
  3116. office)
  3117. type=Office
  3118. ;;
  3119. pda)
  3120. type=PDA
  3121. ;;
  3122. vim)
  3123. type=TextEditor
  3124. ;;
  3125. xemacs)
  3126. type=TextEditor
  3127. ;;
  3128. esac
  3129. ;;
  3130. dev)
  3131. type="Development"
  3132. ;;
  3133. games)
  3134. case ${catmin} in
  3135. action | fps)
  3136. type=ActionGame
  3137. ;;
  3138. arcade)
  3139. type=ArcadeGame
  3140. ;;
  3141. board)
  3142. type=BoardGame
  3143. ;;
  3144. emulation)
  3145. type=Emulator
  3146. ;;
  3147. kids)
  3148. type=KidsGame
  3149. ;;
  3150. puzzle)
  3151. type=LogicGame
  3152. ;;
  3153. roguelike)
  3154. type=RolePlaying
  3155. ;;
  3156. rpg)
  3157. type=RolePlaying
  3158. ;;
  3159. simulation)
  3160. type=Simulation
  3161. ;;
  3162. sports)
  3163. type=SportsGame
  3164. ;;
  3165. strategy)
  3166. type=StrategyGame
  3167. ;;
  3168. esac;
  3169. type="Game;${type}"
  3170. ;;
  3171. gnome)
  3172. type="Gnome;GTK"
  3173. ;;
  3174. kde)
  3175. type="KDE;Qt"
  3176. ;;
  3177. mail)
  3178. type="Network;Email"
  3179. ;;
  3180. media)
  3181. case ${catmin} in
  3182. gfx)
  3183. type=Graphics
  3184. ;;
  3185. *)
  3186. case ${catmin} in
  3187. radio)
  3188. type=Tuner
  3189. ;;
  3190. sound)
  3191. type=Audio
  3192. ;;
  3193. tv)
  3194. type=TV
  3195. ;;
  3196. video)
  3197. type=Video
  3198. ;;
  3199. esac;
  3200. type="AudioVideo;${type}"
  3201. ;;
  3202. esac
  3203. ;;
  3204. net)
  3205. case ${catmin} in
  3206. dialup)
  3207. type=Dialup
  3208. ;;
  3209. ftp)
  3210. type=FileTransfer
  3211. ;;
  3212. im)
  3213. type=InstantMessaging
  3214. ;;
  3215. irc)
  3216. type=IRCClient
  3217. ;;
  3218. mail)
  3219. type=Email
  3220. ;;
  3221. news)
  3222. type=News
  3223. ;;
  3224. nntp)
  3225. type=News
  3226. ;;
  3227. p2p)
  3228. type=FileTransfer
  3229. ;;
  3230. voip)
  3231. type=Telephony
  3232. ;;
  3233. esac;
  3234. type="Network;${type}"
  3235. ;;
  3236. sci)
  3237. case ${catmin} in
  3238. astro*)
  3239. type=Astronomy
  3240. ;;
  3241. bio*)
  3242. type=Biology
  3243. ;;
  3244. calc*)
  3245. type=Calculator
  3246. ;;
  3247. chem*)
  3248. type=Chemistry
  3249. ;;
  3250. elec*)
  3251. type=Electronics
  3252. ;;
  3253. geo*)
  3254. type=Geology
  3255. ;;
  3256. math*)
  3257. type=Math
  3258. ;;
  3259. physics)
  3260. type=Physics
  3261. ;;
  3262. visual*)
  3263. type=DataVisualization
  3264. ;;
  3265. esac;
  3266. type="Education;Science;${type}"
  3267. ;;
  3268. sys)
  3269. type="System"
  3270. ;;
  3271. www)
  3272. case ${catmin} in
  3273. client)
  3274. type=WebBrowser
  3275. ;;
  3276. esac;
  3277. type="Network;${type}"
  3278. ;;
  3279. *)
  3280. type=
  3281. ;;
  3282. esac;
  3283. fi;
  3284. if [ "${SLOT}" == "0" ]; then
  3285. local desktop_name="${PN}";
  3286. else
  3287. local desktop_name="${PN}-${SLOT}";
  3288. fi;
  3289. local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop";
  3290. type=${type%;}${type:+;};
  3291. eshopts_push -s extglob;
  3292. if [[ -n ${icon} && ${icon} != /* ]] && [[ ${icon} == *.xpm || ${icon} == *.png || ${icon} == *.svg ]]; then
  3293. ewarn "As described in the Icon Theme Specification, icon file extensions are not";
  3294. ewarn "allowed in .desktop files if the value is not an absolute path.";
  3295. icon=${icon%.@(xpm|png|svg)};
  3296. fi;
  3297. eshopts_pop;
  3298. cat > "${desktop}" <<-EOF
  3299. [Desktop Entry]
  3300. Name=${name}
  3301. Type=Application
  3302. Comment=${DESCRIPTION}
  3303. Exec=${exec}
  3304. TryExec=${exec%% *}
  3305. Icon=${icon}
  3306. Categories=${type}
  3307. EOF
  3308.  
  3309. if [[ ${fields:-=} != *=* ]]; then
  3310. ewarn "make_desktop_entry: update your 5th arg to read Path=${fields}";
  3311. fields="Path=${fields}";
  3312. fi;
  3313. [[ -n ${fields} ]] && printf '%b\n' "${fields}" >> "${desktop}";
  3314. ( insinto /usr/share/applications;
  3315. doins "${desktop}" ) || die "installing desktop file failed"
  3316. }
  3317. make_session_desktop ()
  3318. {
  3319. [[ -z $1 ]] && eerror "$0: You must specify the title" && return 1;
  3320. [[ -z $2 ]] && eerror "$0: You must specify the command" && return 1;
  3321. local title=$1;
  3322. local command=$2;
  3323. local desktop=${T}/${wm:-${PN}}.desktop;
  3324. shift 2;
  3325. cat > "${desktop}" <<-EOF
  3326. [Desktop Entry]
  3327. Name=${title}
  3328. Comment=This session logs you into ${title}
  3329. Exec=${command} $*
  3330. TryExec=${command}
  3331. Type=XSession
  3332. EOF
  3333.  
  3334. ( insinto /usr/share/xsessions;
  3335. doins "${desktop}" )
  3336. }
  3337. make_wrapper ()
  3338. {
  3339. local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5;
  3340. local tmpwrapper=$(emktemp);
  3341. cat > "${tmpwrapper}" <<EOF
  3342. #!/bin/sh
  3343. cd "${chdir:-.}"
  3344. if [ -n "${libdir}" ] ; then
  3345. if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
  3346. export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
  3347. else
  3348. export LD_LIBRARY_PATH="${libdir}"
  3349. fi
  3350. fi
  3351. exec ${bin} "\$@"
  3352. EOF
  3353.  
  3354. chmod go+rx "${tmpwrapper}";
  3355. if [[ -n ${path} ]]; then
  3356. ( exeinto "${path}";
  3357. newexe "${tmpwrapper}" "${wrapper}" ) || die;
  3358. else
  3359. newbin "${tmpwrapper}" "${wrapper}" || die;
  3360. fi
  3361. }
  3362. mono_multilib_comply ()
  3363. {
  3364. use !prefix && has "${EAPI:-0}" 0 1 2 && ED="${D}";
  3365. local dir finddirs=() mv_command=${mv_command:-mv};
  3366. if [[ -d "${ED}/usr/lib" && "$(get_libdir)" != "lib" ]]; then
  3367. if ! [[ -d "${ED}"/usr/"$(get_libdir)" ]]; then
  3368. mkdir "${ED}"/usr/"$(get_libdir)" || die "Couldn't mkdir ${ED}/usr/$(get_libdir)";
  3369. fi;
  3370. ${mv_command} "${ED}"/usr/lib/* "${ED}"/usr/"$(get_libdir)"/ || die "Moving files into correct libdir failed";
  3371. rm -rf "${ED}"/usr/lib;
  3372. for dir in "${ED}"/usr/"$(get_libdir)"/pkgconfig "${ED}"/usr/share/pkgconfig;
  3373. do
  3374. if [[ -d "${dir}" && "$(find "${dir}" -name '*.pc')" != "" ]]; then
  3375. pushd "${dir}" &>/dev/null;
  3376. sed -i -r -e 's:/(lib)([^a-zA-Z0-9]|$):/'"$(get_libdir)"'\2:g' *.pc || die "Sedding some sense into pkgconfig files failed.";
  3377. popd "${dir}" &>/dev/null;
  3378. fi;
  3379. done;
  3380. if [[ -d "${ED}/usr/bin" ]]; then
  3381. for exe in "${ED}/usr/bin"/*;
  3382. do
  3383. if [[ "$(file "${exe}")" == *"shell script text"* ]]; then
  3384. sed -r -i -e ":/lib(/|$): s:/lib(/|$):/$(get_libdir)\1:" "${exe}" || die "Sedding some sense into ${exe} failed";
  3385. fi;
  3386. done;
  3387. fi;
  3388. fi
  3389. }
  3390. multilib_env ()
  3391. {
  3392. local CTARGET=${1:-${CTARGET}};
  3393. case ${CTARGET} in
  3394. x86_64*)
  3395. export CFLAGS_x86=${CFLAGS_x86--m32};
  3396. export CHOST_x86=${CTARGET/x86_64/i686};
  3397. export CTARGET_x86=${CHOST_x86};
  3398. if [[ ${SYMLINK_LIB} == "yes" ]]; then
  3399. export LIBDIR_x86="lib32";
  3400. else
  3401. export LIBDIR_x86="lib";
  3402. fi;
  3403. export CFLAGS_amd64=${CFLAGS_amd64--m64};
  3404. export CHOST_amd64=${CTARGET};
  3405. export CTARGET_amd64=${CHOST_amd64};
  3406. export LIBDIR_amd64="lib64";
  3407. export CFLAGS_x32=${CFLAGS_x32--mx32};
  3408. export CHOST_x32=${CTARGET};
  3409. export CTARGET_x32=${CHOST_x32};
  3410. export LIBDIR_x32="libx32";
  3411. : ${MULTILIB_ABIS=amd64 x86};
  3412. : ${DEFAULT_ABI=amd64}
  3413. ;;
  3414. mips64*)
  3415. export CFLAGS_o32=${CFLAGS_o32--mabi=32};
  3416. export CHOST_o32=${CTARGET/mips64/mips};
  3417. export CTARGET_o32=${CHOST_o32};
  3418. export LIBDIR_o32="lib";
  3419. export CFLAGS_n32=${CFLAGS_n32--mabi=n32};
  3420. export CHOST_n32=${CTARGET};
  3421. export CTARGET_n32=${CHOST_n32};
  3422. export LIBDIR_n32="lib32";
  3423. export CFLAGS_n64=${CFLAGS_n64--mabi=64};
  3424. export CHOST_n64=${CTARGET};
  3425. export CTARGET_n64=${CHOST_n64};
  3426. export LIBDIR_n64="lib64";
  3427. : ${MULTILIB_ABIS=n64 n32 o32};
  3428. : ${DEFAULT_ABI=n32}
  3429. ;;
  3430. powerpc64*)
  3431. export CFLAGS_ppc=${CFLAGS_ppc--m32};
  3432. export CHOST_ppc=${CTARGET/powerpc64/powerpc};
  3433. export CTARGET_ppc=${CHOST_ppc};
  3434. export LIBDIR_ppc="lib";
  3435. export CFLAGS_ppc64=${CFLAGS_ppc64--m64};
  3436. export CHOST_ppc64=${CTARGET};
  3437. export CTARGET_ppc64=${CHOST_ppc64};
  3438. export LIBDIR_ppc64="lib64";
  3439. : ${MULTILIB_ABIS=ppc64 ppc};
  3440. : ${DEFAULT_ABI=ppc64}
  3441. ;;
  3442. s390x*)
  3443. export CFLAGS_s390=${CFLAGS_s390--m31};
  3444. export CHOST_s390=${CTARGET/s390x/s390};
  3445. export CTARGET_s390=${CHOST_s390};
  3446. export LIBDIR_s390="lib";
  3447. export CFLAGS_s390x=${CFLAGS_s390x--m64};
  3448. export CHOST_s390x=${CTARGET};
  3449. export CTARGET_s390x=${CHOST_s390x};
  3450. export LIBDIR_s390x="lib64";
  3451. : ${MULTILIB_ABIS=s390x s390};
  3452. : ${DEFAULT_ABI=s390x}
  3453. ;;
  3454. sparc*)
  3455. export CFLAGS_sparc32=${CFLAGS_sparc32--m32};
  3456. export CHOST_sparc32=${CTARGET/sparc64/sparc};
  3457. export CTARGET_sparc32=${CHOST_sparc32};
  3458. export LIBDIR_sparc32="lib";
  3459. export CFLAGS_sparc64=${CFLAGS_sparc64--m64};
  3460. export CHOST_sparc64=${CTARGET};
  3461. export CTARGET_sparc64=${CHOST_sparc64};
  3462. export LIBDIR_sparc64="lib64";
  3463. : ${MULTILIB_ABIS=sparc64 sparc32};
  3464. : ${DEFAULT_ABI=sparc64}
  3465. ;;
  3466. *)
  3467. : ${MULTILIB_ABIS=default};
  3468. : ${DEFAULT_ABI=default}
  3469. ;;
  3470. esac;
  3471. export MULTILIB_ABIS DEFAULT_ABI
  3472. }
  3473. multilib_toolchain_setup ()
  3474. {
  3475. local v vv;
  3476. export ABI=$1;
  3477. if [[ ${__DEFAULT_ABI_SAVED} == "true" ]]; then
  3478. for v in CHOST CBUILD AS CC CXX LD;
  3479. do
  3480. vv="__abi_saved_${v}";
  3481. export ${v}="${!vv}";
  3482. unset ${vv};
  3483. done;
  3484. unset __DEFAULT_ABI_SAVED;
  3485. fi;
  3486. if [[ ${ABI} != ${DEFAULT_ABI} ]]; then
  3487. for v in CHOST CBUILD AS CC CXX LD;
  3488. do
  3489. export __abi_saved_${v}="${!v}";
  3490. done;
  3491. export __DEFAULT_ABI_SAVED="true";
  3492. export CHOST=$(get_abi_CHOST ${DEFAULT_ABI});
  3493. export CC="$(tc-getCC) $(get_abi_CFLAGS)";
  3494. export CXX="$(tc-getCXX) $(get_abi_CFLAGS)";
  3495. export LD="$(tc-getLD) $(get_abi_LDFLAGS)";
  3496. export CHOST=$(get_abi_CHOST $1);
  3497. export CBUILD=$(get_abi_CHOST $1);
  3498. fi
  3499. }
  3500. newicon ()
  3501. {
  3502. ( insinto /usr/share/pixmaps;
  3503. newins "$@" )
  3504. }
  3505. newmenu ()
  3506. {
  3507. ( insinto /usr/share/applications;
  3508. newins "$@" )
  3509. }
  3510. no-as-needed ()
  3511. {
  3512. case $($(tc-getLD) -v 2>&1 </dev/null) in
  3513. *GNU*)
  3514. echo "-Wl,--no-as-needed"
  3515. ;;
  3516. esac
  3517. }
  3518. number_abis ()
  3519. {
  3520. set -- `get_install_abis`;
  3521. echo $#
  3522. }
  3523. path_exists ()
  3524. {
  3525. local opt=$1;
  3526. [[ ${opt} == -[ao] ]] && shift || opt="-a";
  3527. [[ $# -eq 0 ]] && return 1;
  3528. local p r=0;
  3529. for p in "$@";
  3530. do
  3531. [[ -e ${p} ]];
  3532. : $(( r += $? ));
  3533. done;
  3534. case ${opt} in
  3535. -a)
  3536. return $(( r != 0 ))
  3537. ;;
  3538. -o)
  3539. return $(( r == $# ))
  3540. ;;
  3541. esac
  3542. }
  3543. pkg_nofetch ()
  3544. {
  3545. _eapi0_pkg_nofetch "$@"
  3546. }
  3547. pkg_postinst ()
  3548. {
  3549. use python && python_mod_optimize avahi $(use dbus && use gtk && echo avahi_discover);
  3550. if use autoipd; then
  3551. echo;
  3552. elog "To use avahi-autoipd to configure your interfaces with IPv4LL (RFC3927)";
  3553. elog "addresses, just set config_<interface>=( autoipd ) in /etc/conf.d/net!";
  3554. fi;
  3555. if use dbus; then
  3556. echo;
  3557. elog "If this is your first install of avahi please reload your dbus config";
  3558. elog "with /etc/init.d/dbus reload before starting avahi-daemon!";
  3559. fi
  3560. }
  3561. pkg_postrm ()
  3562. {
  3563. use python && python_mod_cleanup avahi $(use dbus && use gtk && echo avahi_discover)
  3564. }
  3565. pkg_preinst ()
  3566. {
  3567. enewgroup netdev;
  3568. enewgroup avahi;
  3569. enewuser avahi -1 -1 -1 avahi;
  3570. if use autoipd; then
  3571. enewgroup avahi-autoipd;
  3572. enewuser avahi-autoipd -1 -1 -1 avahi-autoipd;
  3573. fi
  3574. }
  3575. pkg_setup ()
  3576. {
  3577. if use python; then
  3578. python_set_active_version 2;
  3579. python_pkg_setup;
  3580. fi;
  3581. if use python && ! use dbus && ! use gtk; then
  3582. ewarn "For proper python support you should also enable the dbus and gtk USE flags!";
  3583. fi;
  3584. if use utils && ! {
  3585. use gtk || use gtk3
  3586. }; then
  3587. ewarn "To install the avahi utilities, USE='gtk utils' or USE='gtk3 utils''";
  3588. fi
  3589. }
  3590. preserve_old_lib ()
  3591. {
  3592. if [[ ${EBUILD_PHASE} != "preinst" ]]; then
  3593. eerror "preserve_old_lib() must be called from pkg_preinst() only";
  3594. die "Invalid preserve_old_lib() usage";
  3595. fi;
  3596. [[ -z $1 ]] && die "Usage: preserve_old_lib <library to preserve> [more libraries to preserve]";
  3597. has preserve-libs ${FEATURES} && return 0;
  3598. local lib dir;
  3599. for lib in "$@";
  3600. do
  3601. [[ -e ${ROOT}/${lib} ]] || continue;
  3602. dir=${lib%/*};
  3603. dodir ${dir} || die "dodir ${dir} failed";
  3604. cp "${ROOT}"/${lib} "${D}"/${lib} || die "cp ${lib} failed";
  3605. touch "${D}"/${lib};
  3606. done
  3607. }
  3608. preserve_old_lib_notify ()
  3609. {
  3610. if [[ ${EBUILD_PHASE} != "postinst" ]]; then
  3611. eerror "preserve_old_lib_notify() must be called from pkg_postinst() only";
  3612. die "Invalid preserve_old_lib_notify() usage";
  3613. fi;
  3614. has preserve-libs ${FEATURES} && return 0;
  3615. local lib notice=0;
  3616. for lib in "$@";
  3617. do
  3618. [[ -e ${ROOT}/${lib} ]] || continue;
  3619. if [[ ${notice} -eq 0 ]]; then
  3620. notice=1;
  3621. ewarn "Old versions of installed libraries were detected on your system.";
  3622. ewarn "In order to avoid breaking packages that depend on these old libs,";
  3623. ewarn "the libraries are not being removed. You need to run revdep-rebuild";
  3624. ewarn "in order to remove these old dependencies. If you do not have this";
  3625. ewarn "helper program, simply emerge the 'gentoolkit' package.";
  3626. ewarn;
  3627. fi;
  3628. [[ ${PN} == "mpfr" ]] && lib=${lib##*/};
  3629. ewarn " # revdep-rebuild --library '${lib}'";
  3630. done;
  3631. if [[ ${notice} -eq 1 ]]; then
  3632. ewarn;
  3633. ewarn "Once you've finished running revdep-rebuild, it should be safe to";
  3634. ewarn "delete the old libraries. Here is a copy & paste for the lazy:";
  3635. for lib in "$@";
  3636. do
  3637. ewarn " # rm '${lib}'";
  3638. done;
  3639. fi
  3640. }
  3641. python_clean_installation_image ()
  3642. {
  3643. if [[ "${EBUILD_PHASE}" != "install" ]]; then
  3644. die "${FUNCNAME}() can be used only in src_install() phase";
  3645. fi;
  3646. _python_check_python_pkg_setup_execution;
  3647. _python_initialize_prefix_variables;
  3648. local file files=() quiet="0";
  3649. while (($#)); do
  3650. case "$1" in
  3651. -q | --quiet)
  3652. quiet="1"
  3653. ;;
  3654. -*)
  3655. die "${FUNCNAME}(): Unrecognized option '$1'"
  3656. ;;
  3657. *)
  3658. die "${FUNCNAME}(): Invalid usage"
  3659. ;;
  3660. esac;
  3661. shift;
  3662. done;
  3663. while read -d '' -r file; do
  3664. files+=("${file}");
  3665. done < <(find "${ED}" "(" -name "*.py[co]" -o -name "*\$py.class" ")" -type f -print0);
  3666. if [[ "${#files[@]}" -gt 0 ]]; then
  3667. if [[ "${quiet}" == "0" ]]; then
  3668. ewarn "Deleting byte-compiled Python modules needlessly generated by build system:";
  3669. fi;
  3670. for file in "${files[@]}";
  3671. do
  3672. if [[ "${quiet}" == "0" ]]; then
  3673. ewarn " ${file}";
  3674. fi;
  3675. rm -f "${file}";
  3676. if [[ "${file%/*}" == *"/__pycache__" ]]; then
  3677. rmdir "${file%/*}" 2> /dev/null;
  3678. fi;
  3679. done;
  3680. fi;
  3681. function python_clean_sitedirs ()
  3682. {
  3683. if [[ -d "${ED}$(python_get_sitedir)" ]]; then
  3684. find "${ED}$(python_get_sitedir)" "(" -name "*.c" -o -name "*.h" -o -name "*.la" ")" -type f -print0 | xargs -0 rm -f;
  3685. fi
  3686. };
  3687. if _python_package_supporting_installation_for_multiple_python_abis; then
  3688. python_execute_function -q python_clean_sitedirs;
  3689. else
  3690. python_clean_sitedirs;
  3691. fi;
  3692. unset -f python_clean_sitedirs
  3693. }
  3694. python_convert_shebangs ()
  3695. {
  3696. _python_check_python_pkg_setup_execution;
  3697. local argument file files=() only_executables="0" python_interpreter quiet="0" recursive="0";
  3698. while (($#)); do
  3699. case "$1" in
  3700. -r | --recursive)
  3701. recursive="1"
  3702. ;;
  3703. -q | --quiet)
  3704. quiet="1"
  3705. ;;
  3706. -x | --only-executables)
  3707. only_executables="1"
  3708. ;;
  3709. --)
  3710. shift;
  3711. break
  3712. ;;
  3713. -*)
  3714. die "${FUNCNAME}(): Unrecognized option '$1'"
  3715. ;;
  3716. *)
  3717. break
  3718. ;;
  3719. esac;
  3720. shift;
  3721. done;
  3722. if [[ "$#" -eq 0 ]]; then
  3723. die "${FUNCNAME}(): Missing Python version and files or directories";
  3724. else
  3725. if [[ "$#" -eq 1 ]]; then
  3726. die "${FUNCNAME}(): Missing files or directories";
  3727. fi;
  3728. fi;
  3729. if [[ -n "$(_python_get_implementation --ignore-invalid "$1")" ]]; then
  3730. python_interpreter="$(PYTHON "$1")";
  3731. else
  3732. python_interpreter="python$1";
  3733. fi;
  3734. shift;
  3735. for argument in "$@";
  3736. do
  3737. if [[ ! -e "${argument}" ]]; then
  3738. die "${FUNCNAME}(): '${argument}' does not exist";
  3739. else
  3740. if [[ -f "${argument}" ]]; then
  3741. files+=("${argument}");
  3742. else
  3743. if [[ -d "${argument}" ]]; then
  3744. if [[ "${recursive}" == "1" ]]; then
  3745. while read -d '' -r file; do
  3746. files+=("${file}");
  3747. done < <(find "${argument}" $([[ "${only_executables}" == "1" ]] && echo -perm /111) -type f -print0);
  3748. else
  3749. die "${FUNCNAME}(): '${argument}' is not a regular file";
  3750. fi;
  3751. else
  3752. die "${FUNCNAME}(): '${argument}' is not a regular file or a directory";
  3753. fi;
  3754. fi;
  3755. fi;
  3756. done;
  3757. for file in "${files[@]}";
  3758. do
  3759. file="${file#./}";
  3760. [[ "${only_executables}" == "1" && ! -x "${file}" ]] && continue;
  3761. if [[ "$(head -n1 "${file}")" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX} ]]; then
  3762. [[ "$(sed -ne "2p" "${file}")" =~ ^"# Gentoo '".*"' wrapper script generated by python_generate_wrapper_scripts()"$ ]] && continue;
  3763. if [[ "${quiet}" == "0" ]]; then
  3764. einfo "Converting shebang in '${file}'";
  3765. fi;
  3766. 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";
  3767. fi;
  3768. done
  3769. }
  3770. python_copy_sources ()
  3771. {
  3772. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3773. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3774. fi;
  3775. _python_check_python_pkg_setup_execution;
  3776. local dir dirs=() PYTHON_ABI;
  3777. if [[ "$#" -eq 0 ]]; then
  3778. if [[ "${WORKDIR}" == "${S}" ]]; then
  3779. die "${FUNCNAME}() cannot be used with current value of S variable";
  3780. fi;
  3781. dirs=("${S%/}");
  3782. else
  3783. dirs=("$@");
  3784. fi;
  3785. _python_calculate_PYTHON_ABIS;
  3786. for PYTHON_ABI in ${PYTHON_ABIS};
  3787. do
  3788. for dir in "${dirs[@]}";
  3789. do
  3790. cp -pr "${dir}" "${dir}-${PYTHON_ABI}" > /dev/null || die "Copying of sources failed";
  3791. done;
  3792. done
  3793. }
  3794. python_disable_pyc ()
  3795. {
  3796. _python_check_python_pkg_setup_execution;
  3797. if [[ "$#" -ne 0 ]]; then
  3798. die "${FUNCNAME}() does not accept arguments";
  3799. fi;
  3800. export PYTHONDONTWRITEBYTECODE="1"
  3801. }
  3802. python_enable_pyc ()
  3803. {
  3804. _python_check_python_pkg_setup_execution;
  3805. if [[ "$#" -ne 0 ]]; then
  3806. die "${FUNCNAME}() does not accept arguments";
  3807. fi;
  3808. unset PYTHONDONTWRITEBYTECODE
  3809. }
  3810. python_execute_function ()
  3811. {
  3812. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  3813. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  3814. fi;
  3815. _python_check_python_pkg_setup_execution;
  3816. _python_set_color_variables;
  3817. 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;
  3818. while (($#)); do
  3819. case "$1" in
  3820. --action-message)
  3821. action_message_template="$2";
  3822. shift
  3823. ;;
  3824. -d | --default-function)
  3825. default_function="1"
  3826. ;;
  3827. --failure-message)
  3828. failure_message_template="$2";
  3829. shift
  3830. ;;
  3831. -f | --final-ABI)
  3832. final_ABI="1"
  3833. ;;
  3834. --nonfatal)
  3835. nonfatal="1"
  3836. ;;
  3837. -q | --quiet)
  3838. quiet="1"
  3839. ;;
  3840. -s | --separate-build-dirs)
  3841. separate_build_dirs="1"
  3842. ;;
  3843. --source-dir)
  3844. source_dir="$2";
  3845. shift
  3846. ;;
  3847. --)
  3848. shift;
  3849. break
  3850. ;;
  3851. -*)
  3852. die "${FUNCNAME}(): Unrecognized option '$1'"
  3853. ;;
  3854. *)
  3855. break
  3856. ;;
  3857. esac;
  3858. shift;
  3859. done;
  3860. if [[ -n "${source_dir}" && "${separate_build_dirs}" == 0 ]]; then
  3861. die "${FUNCNAME}(): '--source-dir' option can be specified only with '--separate-build-dirs' option";
  3862. fi;
  3863. if [[ "${default_function}" == "0" ]]; then
  3864. if [[ "$#" -eq 0 ]]; then
  3865. die "${FUNCNAME}(): Missing function name";
  3866. fi;
  3867. function="$1";
  3868. shift;
  3869. if [[ -z "$(type -t "${function}")" ]]; then
  3870. die "${FUNCNAME}(): '${function}' function is not defined";
  3871. fi;
  3872. else
  3873. if has "${EAPI:-0}" 0 1; then
  3874. die "${FUNCNAME}(): '--default-function' option cannot be used in this EAPI";
  3875. fi;
  3876. if [[ "${EBUILD_PHASE}" == "configure" ]]; then
  3877. if has "${EAPI}" 2 3; then
  3878. function python_default_function ()
  3879. {
  3880. econf "$@"
  3881. };
  3882. else
  3883. function python_default_function ()
  3884. {
  3885. nonfatal econf "$@"
  3886. };
  3887. fi;
  3888. else
  3889. if [[ "${EBUILD_PHASE}" == "compile" ]]; then
  3890. function python_default_function ()
  3891. {
  3892. emake "$@"
  3893. };
  3894. else
  3895. if [[ "${EBUILD_PHASE}" == "test" ]]; then
  3896. function python_default_function ()
  3897. {
  3898. if emake -j1 -n check &>/dev/null; then
  3899. emake -j1 check "$@";
  3900. else
  3901. if emake -j1 -n test &>/dev/null; then
  3902. emake -j1 test "$@";
  3903. fi;
  3904. fi
  3905. };
  3906. else
  3907. if [[ "${EBUILD_PHASE}" == "install" ]]; then
  3908. function python_default_function ()
  3909. {
  3910. emake DESTDIR="${D}" install "$@"
  3911. };
  3912. else
  3913. die "${FUNCNAME}(): '--default-function' option cannot be used in this ebuild phase";
  3914. fi;
  3915. fi;
  3916. fi;
  3917. fi;
  3918. function="python_default_function";
  3919. fi;
  3920. if _python_abi-specific_local_scope; then
  3921. die "${FUNCNAME}(): Invalid call stack";
  3922. fi;
  3923. if [[ "${quiet}" == "0" ]]; then
  3924. [[ "${EBUILD_PHASE}" == "setup" ]] && action="Setting up";
  3925. [[ "${EBUILD_PHASE}" == "unpack" ]] && action="Unpacking";
  3926. [[ "${EBUILD_PHASE}" == "prepare" ]] && action="Preparation";
  3927. [[ "${EBUILD_PHASE}" == "configure" ]] && action="Configuration";
  3928. [[ "${EBUILD_PHASE}" == "compile" ]] && action="Building";
  3929. [[ "${EBUILD_PHASE}" == "test" ]] && action="Testing";
  3930. [[ "${EBUILD_PHASE}" == "install" ]] && action="Installation";
  3931. [[ "${EBUILD_PHASE}" == "preinst" ]] && action="Preinstallation";
  3932. [[ "${EBUILD_PHASE}" == "postinst" ]] && action="Postinstallation";
  3933. [[ "${EBUILD_PHASE}" == "prerm" ]] && action="Preuninstallation";
  3934. [[ "${EBUILD_PHASE}" == "postrm" ]] && action="Postuninstallation";
  3935. fi;
  3936. _python_calculate_PYTHON_ABIS;
  3937. if [[ "${final_ABI}" == "1" ]]; then
  3938. iterated_PYTHON_ABIS="$(PYTHON -f --ABI)";
  3939. else
  3940. iterated_PYTHON_ABIS="${PYTHON_ABIS}";
  3941. fi;
  3942. for PYTHON_ABI in ${iterated_PYTHON_ABIS};
  3943. do
  3944. if [[ "${EBUILD_PHASE}" == "test" ]] && _python_check_python_abi_matching --patterns-list "${PYTHON_ABI}" "${PYTHON_TESTS_RESTRICTED_ABIS}"; then
  3945. if [[ "${quiet}" == "0" ]]; then
  3946. echo " ${_GREEN}*${_NORMAL} ${_BLUE}Testing of ${CATEGORY}/${PF} with $(python_get_implementation_and_version) skipped${_NORMAL}";
  3947. fi;
  3948. continue;
  3949. fi;
  3950. _python_prepare_flags;
  3951. if [[ "${quiet}" == "0" ]]; then
  3952. if [[ -n "${action_message_template}" ]]; then
  3953. eval "action_message=\"${action_message_template}\"";
  3954. else
  3955. action_message="${action} of ${CATEGORY}/${PF} with $(python_get_implementation_and_version)...";
  3956. fi;
  3957. echo " ${_GREEN}*${_NORMAL} ${_BLUE}${action_message}${_NORMAL}";
  3958. fi;
  3959. if [[ "${separate_build_dirs}" == "1" ]]; then
  3960. if [[ -n "${source_dir}" ]]; then
  3961. export BUILDDIR="${S}/${source_dir}-${PYTHON_ABI}";
  3962. else
  3963. export BUILDDIR="${S}-${PYTHON_ABI}";
  3964. fi;
  3965. pushd "${BUILDDIR}" > /dev/null || die "pushd failed";
  3966. else
  3967. export BUILDDIR="${S}";
  3968. fi;
  3969. previous_directory="$(pwd)";
  3970. previous_directory_stack="$(dirs -p)";
  3971. previous_directory_stack_length="$(dirs -p | wc -l)";
  3972. if ! has "${EAPI}" 0 1 2 3 && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
  3973. EPYTHON="$(PYTHON)" nonfatal "${function}" "$@";
  3974. else
  3975. EPYTHON="$(PYTHON)" "${function}" "$@";
  3976. fi;
  3977. return_code="$?";
  3978. _python_restore_flags;
  3979. if [[ "${return_code}" -ne 0 ]]; then
  3980. if [[ -n "${failure_message_template}" ]]; then
  3981. eval "failure_message=\"${failure_message_template}\"";
  3982. else
  3983. failure_message="${action} failed with $(python_get_implementation_and_version) in ${function}() function";
  3984. fi;
  3985. if [[ "${nonfatal}" == "1" ]]; then
  3986. if [[ "${quiet}" == "0" ]]; then
  3987. ewarn "${failure_message}";
  3988. fi;
  3989. else
  3990. if [[ "${final_ABI}" == "0" ]] && has "${PYTHON_ABI}" ${FAILURE_TOLERANT_PYTHON_ABIS}; then
  3991. if [[ "${EBUILD_PHASE}" != "test" ]] || ! has test-fail-continue ${FEATURES}; then
  3992. local enabled_PYTHON_ABIS= other_PYTHON_ABI;
  3993. for other_PYTHON_ABI in ${PYTHON_ABIS};
  3994. do
  3995. [[ "${other_PYTHON_ABI}" != "${PYTHON_ABI}" ]] && enabled_PYTHON_ABIS+="${enabled_PYTHON_ABIS:+ }${other_PYTHON_ABI}";
  3996. done;
  3997. export PYTHON_ABIS="${enabled_PYTHON_ABIS}";
  3998. fi;
  3999. if [[ "${quiet}" == "0" ]]; then
  4000. ewarn "${failure_message}";
  4001. fi;
  4002. if [[ -z "${PYTHON_ABIS}" ]]; then
  4003. die "${function}() function failed with all enabled Python ABIs";
  4004. fi;
  4005. else
  4006. die "${failure_message}";
  4007. fi;
  4008. fi;
  4009. fi;
  4010. if [[ "$(dirs -p | wc -l)" -lt "${previous_directory_stack_length}" ]]; then
  4011. die "Directory stack decreased illegally";
  4012. fi;
  4013. while [[ "$(dirs -p | wc -l)" -gt "${previous_directory_stack_length}" ]]; do
  4014. popd > /dev/null || die "popd failed";
  4015. done;
  4016. cd "${previous_directory}";
  4017. if [[ "$(dirs -p)" != "${previous_directory_stack}" ]]; then
  4018. die "Directory stack changed illegally";
  4019. fi;
  4020. if [[ "${separate_build_dirs}" == "1" ]]; then
  4021. popd > /dev/null || die "popd failed";
  4022. fi;
  4023. unset BUILDDIR;
  4024. done;
  4025. if [[ "${default_function}" == "1" ]]; then
  4026. unset -f python_default_function;
  4027. fi
  4028. }
  4029. python_execute_nosetests ()
  4030. {
  4031. _python_check_python_pkg_setup_execution;
  4032. _python_set_color_variables;
  4033. local PYTHONPATH_template separate_build_dirs;
  4034. while (($#)); do
  4035. case "$1" in
  4036. -P | --PYTHONPATH)
  4037. PYTHONPATH_template="$2";
  4038. shift
  4039. ;;
  4040. -s | --separate-build-dirs)
  4041. separate_build_dirs="1"
  4042. ;;
  4043. --)
  4044. shift;
  4045. break
  4046. ;;
  4047. -*)
  4048. die "${FUNCNAME}(): Unrecognized option '$1'"
  4049. ;;
  4050. *)
  4051. break
  4052. ;;
  4053. esac;
  4054. shift;
  4055. done;
  4056. function python_test_function ()
  4057. {
  4058. local evaluated_PYTHONPATH;
  4059. eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"";
  4060. _PYTHON_TEST_FUNCTION="python_execute_nosetests" _python_test_hook pre;
  4061. if [[ -n "${evaluated_PYTHONPATH}" ]]; then
  4062. echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL};
  4063. PYTHONPATH="${evaluated_PYTHONPATH}" nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?";
  4064. else
  4065. echo ${_BOLD}nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@"${_NORMAL};
  4066. nosetests --verbosity="${PYTHON_TEST_VERBOSITY}" "$@" || return "$?";
  4067. fi;
  4068. _PYTHON_TEST_FUNCTION="python_execute_nosetests" _python_test_hook post
  4069. };
  4070. if _python_package_supporting_installation_for_multiple_python_abis; then
  4071. python_execute_function ${separate_build_dirs:+-s} python_test_function "$@";
  4072. else
  4073. if [[ -n "${separate_build_dirs}" ]]; then
  4074. die "${FUNCNAME}(): Invalid usage";
  4075. fi;
  4076. python_test_function "$@" || die "Testing failed";
  4077. fi;
  4078. unset -f python_test_function
  4079. }
  4080. python_execute_py.test ()
  4081. {
  4082. _python_check_python_pkg_setup_execution;
  4083. _python_set_color_variables;
  4084. local PYTHONPATH_template separate_build_dirs;
  4085. while (($#)); do
  4086. case "$1" in
  4087. -P | --PYTHONPATH)
  4088. PYTHONPATH_template="$2";
  4089. shift
  4090. ;;
  4091. -s | --separate-build-dirs)
  4092. separate_build_dirs="1"
  4093. ;;
  4094. --)
  4095. shift;
  4096. break
  4097. ;;
  4098. -*)
  4099. die "${FUNCNAME}(): Unrecognized option '$1'"
  4100. ;;
  4101. *)
  4102. break
  4103. ;;
  4104. esac;
  4105. shift;
  4106. done;
  4107. function python_test_function ()
  4108. {
  4109. local evaluated_PYTHONPATH;
  4110. eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"";
  4111. _PYTHON_TEST_FUNCTION="python_execute_py.test" _python_test_hook pre;
  4112. if [[ -n "${evaluated_PYTHONPATH}" ]]; then
  4113. echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@"${_NORMAL};
  4114. PYTHONPATH="${evaluated_PYTHONPATH}" py.test $([[ "${PYTHON_TEST_VERBOSITY}" -ge 2 ]] && echo -v) "$@" || return "$?";
  4115. else
  4116. echo ${_BOLD}py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@"${_NORMAL};
  4117. py.test $([[ "${PYTHON_TEST_VERBOSITY}" -gt 1 ]] && echo -v) "$@" || return "$?";
  4118. fi;
  4119. _PYTHON_TEST_FUNCTION="python_execute_py.test" _python_test_hook post
  4120. };
  4121. if _python_package_supporting_installation_for_multiple_python_abis; then
  4122. python_execute_function ${separate_build_dirs:+-s} python_test_function "$@";
  4123. else
  4124. if [[ -n "${separate_build_dirs}" ]]; then
  4125. die "${FUNCNAME}(): Invalid usage";
  4126. fi;
  4127. python_test_function "$@" || die "Testing failed";
  4128. fi;
  4129. unset -f python_test_function
  4130. }
  4131. python_execute_trial ()
  4132. {
  4133. _python_check_python_pkg_setup_execution;
  4134. _python_set_color_variables;
  4135. local PYTHONPATH_template separate_build_dirs;
  4136. while (($#)); do
  4137. case "$1" in
  4138. -P | --PYTHONPATH)
  4139. PYTHONPATH_template="$2";
  4140. shift
  4141. ;;
  4142. -s | --separate-build-dirs)
  4143. separate_build_dirs="1"
  4144. ;;
  4145. --)
  4146. shift;
  4147. break
  4148. ;;
  4149. -*)
  4150. die "${FUNCNAME}(): Unrecognized option '$1'"
  4151. ;;
  4152. *)
  4153. break
  4154. ;;
  4155. esac;
  4156. shift;
  4157. done;
  4158. function python_test_function ()
  4159. {
  4160. local evaluated_PYTHONPATH;
  4161. eval "evaluated_PYTHONPATH=\"${PYTHONPATH_template}\"";
  4162. _PYTHON_TEST_FUNCTION="python_execute_trial" _python_test_hook pre;
  4163. if [[ -n "${evaluated_PYTHONPATH}" ]]; then
  4164. echo ${_BOLD}PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL};
  4165. PYTHONPATH="${evaluated_PYTHONPATH}" trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?";
  4166. else
  4167. echo ${_BOLD}trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@"${_NORMAL};
  4168. trial $([[ "${PYTHON_TEST_VERBOSITY}" -ge 4 ]] && echo --spew) "$@" || return "$?";
  4169. fi;
  4170. _PYTHON_TEST_FUNCTION="python_execute_trial" _python_test_hook post
  4171. };
  4172. if _python_package_supporting_installation_for_multiple_python_abis; then
  4173. python_execute_function ${separate_build_dirs:+-s} python_test_function "$@";
  4174. else
  4175. if [[ -n "${separate_build_dirs}" ]]; then
  4176. die "${FUNCNAME}(): Invalid usage";
  4177. fi;
  4178. python_test_function "$@" || die "Testing failed";
  4179. fi;
  4180. unset -f python_test_function
  4181. }
  4182. python_generate_wrapper_scripts ()
  4183. {
  4184. if [[ "${EBUILD_PHASE}" != "install" ]]; then
  4185. die "${FUNCNAME}() can be used only in src_install() phase";
  4186. fi;
  4187. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4188. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4189. fi;
  4190. _python_check_python_pkg_setup_execution;
  4191. _python_initialize_prefix_variables;
  4192. local eselect_python_option file force="0" quiet="0" PYTHON_ABI PYTHON_ABIS_list python2_enabled="0" python3_enabled="0" respect_EPYTHON="0";
  4193. while (($#)); do
  4194. case "$1" in
  4195. -E | --respect-EPYTHON)
  4196. respect_EPYTHON="1"
  4197. ;;
  4198. -f | --force)
  4199. force="1"
  4200. ;;
  4201. -q | --quiet)
  4202. quiet="1"
  4203. ;;
  4204. --)
  4205. shift;
  4206. break
  4207. ;;
  4208. -*)
  4209. die "${FUNCNAME}(): Unrecognized option '$1'"
  4210. ;;
  4211. *)
  4212. break
  4213. ;;
  4214. esac;
  4215. shift;
  4216. done;
  4217. if [[ "$#" -eq 0 ]]; then
  4218. die "${FUNCNAME}(): Missing arguments";
  4219. fi;
  4220. _python_calculate_PYTHON_ABIS;
  4221. for PYTHON_ABI in "${_CPYTHON2_GLOBALLY_SUPPORTED_ABIS[@]}";
  4222. do
  4223. if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
  4224. python2_enabled="1";
  4225. fi;
  4226. done;
  4227. for PYTHON_ABI in "${_CPYTHON3_GLOBALLY_SUPPORTED_ABIS[@]}";
  4228. do
  4229. if has "${PYTHON_ABI}" ${PYTHON_ABIS}; then
  4230. python3_enabled="1";
  4231. fi;
  4232. done;
  4233. if [[ "${python2_enabled}" == "1" && "${python3_enabled}" == "1" ]]; then
  4234. eselect_python_option=;
  4235. else
  4236. if [[ "${python2_enabled}" == "1" && "${python3_enabled}" == "0" ]]; then
  4237. eselect_python_option="--python2";
  4238. else
  4239. if [[ "${python2_enabled}" == "0" && "${python3_enabled}" == "1" ]]; then
  4240. eselect_python_option="--python3";
  4241. else
  4242. die "${FUNCNAME}(): Unsupported environment";
  4243. fi;
  4244. fi;
  4245. fi;
  4246. PYTHON_ABIS_list="$("$(PYTHON -f)" -c "print(', '.join('\"%s\"' % x for x in reversed('${PYTHON_ABIS}'.split())))")";
  4247. for file in "$@";
  4248. do
  4249. if [[ -f "${file}" && "${force}" == "0" ]]; then
  4250. die "${FUNCNAME}(): '${file}' already exists";
  4251. fi;
  4252. if [[ "${quiet}" == "0" ]]; then
  4253. einfo "Generating '${file#${ED%/}}' wrapper script";
  4254. fi;
  4255. cat > "${file}" <<EOF
  4256. #!/usr/bin/env python
  4257. # Gentoo '${file##*/}' wrapper script generated by python_generate_wrapper_scripts()
  4258.  
  4259. import os
  4260. import re
  4261. import subprocess
  4262. import sys
  4263.  
  4264. cpython_ABI_re = re.compile(r"^(\d+\.\d+)$")
  4265. jython_ABI_re = re.compile(r"^(\d+\.\d+)-jython$")
  4266. pypy_ABI_re = re.compile(r"^\d+\.\d+-pypy-(\d+\.\d+)$")
  4267. cpython_interpreter_re = re.compile(r"^python(\d+\.\d+)$")
  4268. jython_interpreter_re = re.compile(r"^jython(\d+\.\d+)$")
  4269. pypy_interpreter_re = re.compile(r"^pypy-c(\d+\.\d+)$")
  4270. cpython_shebang_re = re.compile(r"^#![ \t]*(?:${EPREFIX}/usr/bin/python|(?:${EPREFIX})?/usr/bin/env[ \t]+(?:${EPREFIX}/usr/bin/)?python)")
  4271. python_shebang_options_re = re.compile(r"^#![ \t]*${EPREFIX}/usr/bin/(?:jython|pypy-c|python)(?:\d+(?:\.\d+)?)?[ \t]+(-\S)")
  4272. python_verification_output_re = re.compile("^GENTOO_PYTHON_TARGET_SCRIPT_PATH supported\n$")
  4273.  
  4274. pypy_versions_mapping = {
  4275. "1.5": "2.7"
  4276. }
  4277.  
  4278. def get_PYTHON_ABI(python_interpreter):
  4279. cpython_matched = cpython_interpreter_re.match(python_interpreter)
  4280. jython_matched = jython_interpreter_re.match(python_interpreter)
  4281. pypy_matched = pypy_interpreter_re.match(python_interpreter)
  4282. if cpython_matched is not None:
  4283. PYTHON_ABI = cpython_matched.group(1)
  4284. elif jython_matched is not None:
  4285. PYTHON_ABI = jython_matched.group(1) + "-jython"
  4286. elif pypy_matched is not None:
  4287. PYTHON_ABI = pypy_versions_mapping[pypy_matched.group(1)] + "-pypy-" + pypy_matched.group(1)
  4288. else:
  4289. PYTHON_ABI = None
  4290. return PYTHON_ABI
  4291.  
  4292. def get_python_interpreter(PYTHON_ABI):
  4293. cpython_matched = cpython_ABI_re.match(PYTHON_ABI)
  4294. jython_matched = jython_ABI_re.match(PYTHON_ABI)
  4295. pypy_matched = pypy_ABI_re.match(PYTHON_ABI)
  4296. if cpython_matched is not None:
  4297. python_interpreter = "python" + cpython_matched.group(1)
  4298. elif jython_matched is not None:
  4299. python_interpreter = "jython" + jython_matched.group(1)
  4300. elif pypy_matched is not None:
  4301. python_interpreter = "pypy-c" + pypy_matched.group(1)
  4302. else:
  4303. python_interpreter = None
  4304. return python_interpreter
  4305.  
  4306. EOF
  4307.  
  4308. if [[ "$?" != "0" ]]; then
  4309. die "${FUNCNAME}(): Generation of '$1' failed";
  4310. fi;
  4311. if [[ "${respect_EPYTHON}" == "1" ]]; then
  4312. cat >> "${file}" <<EOF
  4313. python_interpreter = os.environ.get("EPYTHON")
  4314. if python_interpreter:
  4315. PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
  4316. if PYTHON_ABI is None:
  4317. sys.stderr.write("%s: EPYTHON variable has unrecognized value '%s'\n" % (sys.argv[0], python_interpreter))
  4318. sys.exit(1)
  4319. else:
  4320. try:
  4321. environment = os.environ.copy()
  4322. environment["ROOT"] = "/"
  4323. 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)
  4324. if eselect_process.wait() != 0:
  4325. raise ValueError
  4326. except (OSError, ValueError):
  4327. sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0])
  4328. sys.exit(1)
  4329.  
  4330. python_interpreter = eselect_process.stdout.read()
  4331. if not isinstance(python_interpreter, str):
  4332. # Python 3
  4333. python_interpreter = python_interpreter.decode()
  4334. python_interpreter = python_interpreter.rstrip("\n")
  4335.  
  4336. PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
  4337. if PYTHON_ABI is None:
  4338. sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], python_interpreter))
  4339. sys.exit(1)
  4340.  
  4341. wrapper_script_path = os.path.realpath(sys.argv[0])
  4342. target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
  4343. if not os.path.exists(target_executable_path):
  4344. sys.stderr.write("%s: '%s' does not exist\n" % (sys.argv[0], target_executable_path))
  4345. sys.exit(1)
  4346. EOF
  4347.  
  4348. if [[ "$?" != "0" ]]; then
  4349. die "${FUNCNAME}(): Generation of '$1' failed";
  4350. fi;
  4351. else
  4352. cat >> "${file}" <<EOF
  4353. try:
  4354. environment = os.environ.copy()
  4355. environment["ROOT"] = "/"
  4356. 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)
  4357. if eselect_process.wait() != 0:
  4358. raise ValueError
  4359. except (OSError, ValueError):
  4360. sys.stderr.write("%s: Execution of 'eselect python show${eselect_python_option:+ }${eselect_python_option}' failed\n" % sys.argv[0])
  4361. sys.exit(1)
  4362.  
  4363. python_interpreter = eselect_process.stdout.read()
  4364. if not isinstance(python_interpreter, str):
  4365. # Python 3
  4366. python_interpreter = python_interpreter.decode()
  4367. python_interpreter = python_interpreter.rstrip("\n")
  4368.  
  4369. PYTHON_ABI = get_PYTHON_ABI(python_interpreter)
  4370. if PYTHON_ABI is None:
  4371. sys.stderr.write("%s: 'eselect python show${eselect_python_option:+ }${eselect_python_option}' printed unrecognized value '%s'\n" % (sys.argv[0], python_interpreter))
  4372. sys.exit(1)
  4373.  
  4374. wrapper_script_path = os.path.realpath(sys.argv[0])
  4375. for PYTHON_ABI in [PYTHON_ABI, ${PYTHON_ABIS_list}]:
  4376. target_executable_path = "%s-%s" % (wrapper_script_path, PYTHON_ABI)
  4377. if os.path.exists(target_executable_path):
  4378. break
  4379. else:
  4380. sys.stderr.write("%s: No target script exists for '%s'\n" % (sys.argv[0], wrapper_script_path))
  4381. sys.exit(1)
  4382.  
  4383. python_interpreter = get_python_interpreter(PYTHON_ABI)
  4384. if python_interpreter is None:
  4385. sys.stderr.write("%s: Unrecognized Python ABI '%s'\n" % (sys.argv[0], PYTHON_ABI))
  4386. sys.exit(1)
  4387. EOF
  4388.  
  4389. if [[ "$?" != "0" ]]; then
  4390. die "${FUNCNAME}(): Generation of '$1' failed";
  4391. fi;
  4392. fi
  4393. cat >> "${file}" <<EOF
  4394.  
  4395. target_executable = open(target_executable_path, "rb")
  4396. target_executable_first_line = target_executable.readline()
  4397. target_executable.close()
  4398. if not isinstance(target_executable_first_line, str):
  4399. # Python 3
  4400. target_executable_first_line = target_executable_first_line.decode("utf_8", "replace")
  4401.  
  4402. options = []
  4403. python_shebang_options_matched = python_shebang_options_re.match(target_executable_first_line)
  4404. if python_shebang_options_matched is not None:
  4405. options = [python_shebang_options_matched.group(1)]
  4406.  
  4407. cpython_shebang_matched = cpython_shebang_re.match(target_executable_first_line)
  4408.  
  4409. if cpython_shebang_matched is not None:
  4410. try:
  4411. python_interpreter_path = "${EPREFIX}/usr/bin/%s" % python_interpreter
  4412. os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"] = "1"
  4413. python_verification_process = subprocess.Popen([python_interpreter_path, "-c", "pass"], stdout=subprocess.PIPE)
  4414. del os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"]
  4415. if python_verification_process.wait() != 0:
  4416. raise ValueError
  4417.  
  4418. python_verification_output = python_verification_process.stdout.read()
  4419. if not isinstance(python_verification_output, str):
  4420. # Python 3
  4421. python_verification_output = python_verification_output.decode()
  4422.  
  4423. if not python_verification_output_re.match(python_verification_output):
  4424. raise ValueError
  4425.  
  4426. if cpython_interpreter_re.match(python_interpreter) is not None:
  4427. os.environ["GENTOO_PYTHON_PROCESS_NAME"] = os.path.basename(sys.argv[0])
  4428. os.environ["GENTOO_PYTHON_WRAPPER_SCRIPT_PATH"] = sys.argv[0]
  4429. os.environ["GENTOO_PYTHON_TARGET_SCRIPT_PATH"] = target_executable_path
  4430.  
  4431. if hasattr(os, "execv"):
  4432. os.execv(python_interpreter_path, [python_interpreter_path] + options + sys.argv)
  4433. else:
  4434. sys.exit(subprocess.Popen([python_interpreter_path] + options + sys.argv).wait())
  4435. except (KeyboardInterrupt, SystemExit):
  4436. raise
  4437. except:
  4438. pass
  4439. for variable in ("GENTOO_PYTHON_PROCESS_NAME", "GENTOO_PYTHON_WRAPPER_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH", "GENTOO_PYTHON_TARGET_SCRIPT_PATH_VERIFICATION"):
  4440. if variable in os.environ:
  4441. del os.environ[variable]
  4442.  
  4443. if hasattr(os, "execv"):
  4444. os.execv(target_executable_path, sys.argv)
  4445. else:
  4446. sys.exit(subprocess.Popen([target_executable_path] + sys.argv[1:]).wait())
  4447. EOF
  4448.  
  4449. if [[ "$?" != "0" ]]; then
  4450. die "${FUNCNAME}(): Generation of '$1' failed";
  4451. fi;
  4452. fperms +x "${file#${ED%/}}" || die "fperms '${file}' failed";
  4453. done
  4454. }
  4455. python_get_implementation ()
  4456. {
  4457. _python_check_python_pkg_setup_execution;
  4458. local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}";
  4459. while (($#)); do
  4460. case "$1" in
  4461. -f | --final-ABI)
  4462. final_ABI="1"
  4463. ;;
  4464. -*)
  4465. die "${FUNCNAME}(): Unrecognized option '$1'"
  4466. ;;
  4467. *)
  4468. die "${FUNCNAME}(): Invalid usage"
  4469. ;;
  4470. esac;
  4471. shift;
  4472. done;
  4473. if [[ "${final_ABI}" == "1" ]]; then
  4474. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4475. die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4476. fi;
  4477. PYTHON_ABI="$(PYTHON -f --ABI)";
  4478. else
  4479. if _python_package_supporting_installation_for_multiple_python_abis; then
  4480. if ! _python_abi-specific_local_scope; then
  4481. die "${FUNCNAME}() should be used in ABI-specific local scope";
  4482. fi;
  4483. else
  4484. PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  4485. fi;
  4486. fi;
  4487. echo "$(_python_get_implementation "${PYTHON_ABI}")"
  4488. }
  4489. python_get_implementation_and_version ()
  4490. {
  4491. _python_check_python_pkg_setup_execution;
  4492. local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}";
  4493. while (($#)); do
  4494. case "$1" in
  4495. -f | --final-ABI)
  4496. final_ABI="1"
  4497. ;;
  4498. -*)
  4499. die "${FUNCNAME}(): Unrecognized option '$1'"
  4500. ;;
  4501. *)
  4502. die "${FUNCNAME}(): Invalid usage"
  4503. ;;
  4504. esac;
  4505. shift;
  4506. done;
  4507. if [[ "${final_ABI}" == "1" ]]; then
  4508. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4509. die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4510. fi;
  4511. PYTHON_ABI="$(PYTHON -f --ABI)";
  4512. else
  4513. if _python_package_supporting_installation_for_multiple_python_abis; then
  4514. if ! _python_abi-specific_local_scope; then
  4515. die "${FUNCNAME}() should be used in ABI-specific local scope";
  4516. fi;
  4517. else
  4518. PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  4519. fi;
  4520. fi;
  4521. if [[ "${PYTHON_ABI}" =~ ^[[:digit:]]+\.[[:digit:]]+-[[:alnum:]]+-[[:digit:]]+\.[[:digit:]]+$ ]]; then
  4522. echo "$(_python_get_implementation "${PYTHON_ABI}") ${PYTHON_ABI##*-} (Python ${PYTHON_ABI%%-*})";
  4523. else
  4524. echo "$(_python_get_implementation "${PYTHON_ABI}") ${PYTHON_ABI%%-*}";
  4525. fi
  4526. }
  4527. python_get_implementational_package ()
  4528. {
  4529. _python_check_python_pkg_setup_execution;
  4530. local final_ABI="0" PYTHON_ABI="${PYTHON_ABI}";
  4531. while (($#)); do
  4532. case "$1" in
  4533. -f | --final-ABI)
  4534. final_ABI="1"
  4535. ;;
  4536. -*)
  4537. die "${FUNCNAME}(): Unrecognized option '$1'"
  4538. ;;
  4539. *)
  4540. die "${FUNCNAME}(): Invalid usage"
  4541. ;;
  4542. esac;
  4543. shift;
  4544. done;
  4545. if [[ "${final_ABI}" == "1" ]]; then
  4546. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4547. die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4548. fi;
  4549. PYTHON_ABI="$(PYTHON -f --ABI)";
  4550. else
  4551. if _python_package_supporting_installation_for_multiple_python_abis; then
  4552. if ! _python_abi-specific_local_scope; then
  4553. die "${FUNCNAME}() should be used in ABI-specific local scope";
  4554. fi;
  4555. else
  4556. PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  4557. fi;
  4558. fi;
  4559. if [[ "${EAPI:-0}" == "0" ]]; then
  4560. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  4561. echo "=dev-lang/python-${PYTHON_ABI}*";
  4562. else
  4563. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  4564. echo "=dev-java/jython-${PYTHON_ABI%-jython}*";
  4565. else
  4566. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  4567. echo "=dev-python/pypy-${PYTHON_ABI#*-pypy-}*";
  4568. fi;
  4569. fi;
  4570. fi;
  4571. else
  4572. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  4573. echo "dev-lang/python:${PYTHON_ABI}";
  4574. else
  4575. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  4576. echo "dev-java/jython:${PYTHON_ABI%-jython}";
  4577. else
  4578. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  4579. echo "dev-python/pypy:${PYTHON_ABI#*-pypy-}";
  4580. fi;
  4581. fi;
  4582. fi;
  4583. fi
  4584. }
  4585. python_get_includedir ()
  4586. {
  4587. _python_check_python_pkg_setup_execution;
  4588. local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}";
  4589. while (($#)); do
  4590. case "$1" in
  4591. -b | --base-path)
  4592. base_path="1"
  4593. ;;
  4594. -f | --final-ABI)
  4595. final_ABI="1"
  4596. ;;
  4597. -*)
  4598. die "${FUNCNAME}(): Unrecognized option '$1'"
  4599. ;;
  4600. *)
  4601. die "${FUNCNAME}(): Invalid usage"
  4602. ;;
  4603. esac;
  4604. shift;
  4605. done;
  4606. if [[ "${base_path}" == "0" ]]; then
  4607. prefix="/";
  4608. fi;
  4609. if [[ "${final_ABI}" == "1" ]]; then
  4610. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4611. die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4612. fi;
  4613. PYTHON_ABI="$(PYTHON -f --ABI)";
  4614. else
  4615. if _python_package_supporting_installation_for_multiple_python_abis; then
  4616. if ! _python_abi-specific_local_scope; then
  4617. die "${FUNCNAME}() should be used in ABI-specific local scope";
  4618. fi;
  4619. else
  4620. PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  4621. fi;
  4622. fi;
  4623. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  4624. echo "${prefix}usr/include/python${PYTHON_ABI}";
  4625. else
  4626. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  4627. echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Include";
  4628. else
  4629. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  4630. echo "${prefix}usr/$(get_libdir)/pypy${PYTHON_ABI#*-pypy-}/include";
  4631. fi;
  4632. fi;
  4633. fi
  4634. }
  4635. python_get_libdir ()
  4636. {
  4637. _python_check_python_pkg_setup_execution;
  4638. local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}";
  4639. while (($#)); do
  4640. case "$1" in
  4641. -b | --base-path)
  4642. base_path="1"
  4643. ;;
  4644. -f | --final-ABI)
  4645. final_ABI="1"
  4646. ;;
  4647. -*)
  4648. die "${FUNCNAME}(): Unrecognized option '$1'"
  4649. ;;
  4650. *)
  4651. die "${FUNCNAME}(): Invalid usage"
  4652. ;;
  4653. esac;
  4654. shift;
  4655. done;
  4656. if [[ "${base_path}" == "0" ]]; then
  4657. prefix="/";
  4658. fi;
  4659. if [[ "${final_ABI}" == "1" ]]; then
  4660. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4661. die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4662. fi;
  4663. PYTHON_ABI="$(PYTHON -f --ABI)";
  4664. else
  4665. if _python_package_supporting_installation_for_multiple_python_abis; then
  4666. if ! _python_abi-specific_local_scope; then
  4667. die "${FUNCNAME}() should be used in ABI-specific local scope";
  4668. fi;
  4669. else
  4670. PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  4671. fi;
  4672. fi;
  4673. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  4674. echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}";
  4675. else
  4676. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  4677. echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib";
  4678. else
  4679. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  4680. die "${FUNCNAME}(): PyPy has multiple standard library directories";
  4681. fi;
  4682. fi;
  4683. fi
  4684. }
  4685. python_get_library ()
  4686. {
  4687. _python_check_python_pkg_setup_execution;
  4688. local base_path="0" final_ABI="0" linker_option="0" prefix PYTHON_ABI="${PYTHON_ABI}";
  4689. while (($#)); do
  4690. case "$1" in
  4691. -b | --base-path)
  4692. base_path="1"
  4693. ;;
  4694. -f | --final-ABI)
  4695. final_ABI="1"
  4696. ;;
  4697. -l | --linker-option)
  4698. linker_option="1"
  4699. ;;
  4700. -*)
  4701. die "${FUNCNAME}(): Unrecognized option '$1'"
  4702. ;;
  4703. *)
  4704. die "${FUNCNAME}(): Invalid usage"
  4705. ;;
  4706. esac;
  4707. shift;
  4708. done;
  4709. if [[ "${base_path}" == "0" ]]; then
  4710. prefix="/";
  4711. fi;
  4712. if [[ "${base_path}" == "1" && "${linker_option}" == "1" ]]; then
  4713. die "${FUNCNAME}(): '--base-path' and '--linker-option' options cannot be specified simultaneously";
  4714. fi;
  4715. if [[ "${final_ABI}" == "1" ]]; then
  4716. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4717. die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4718. fi;
  4719. PYTHON_ABI="$(PYTHON -f --ABI)";
  4720. else
  4721. if _python_package_supporting_installation_for_multiple_python_abis; then
  4722. if ! _python_abi-specific_local_scope; then
  4723. die "${FUNCNAME}() should be used in ABI-specific local scope";
  4724. fi;
  4725. else
  4726. PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  4727. fi;
  4728. fi;
  4729. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  4730. if [[ "${linker_option}" == "1" ]]; then
  4731. echo "-lpython${PYTHON_ABI}";
  4732. else
  4733. echo "${prefix}usr/$(get_libdir)/libpython${PYTHON_ABI}$(get_libname)";
  4734. fi;
  4735. else
  4736. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  4737. die "${FUNCNAME}(): Jython does not have shared library";
  4738. else
  4739. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  4740. die "${FUNCNAME}(): PyPy does not have shared library";
  4741. fi;
  4742. fi;
  4743. fi
  4744. }
  4745. python_get_sitedir ()
  4746. {
  4747. _python_check_python_pkg_setup_execution;
  4748. local base_path="0" final_ABI="0" prefix PYTHON_ABI="${PYTHON_ABI}";
  4749. while (($#)); do
  4750. case "$1" in
  4751. -b | --base-path)
  4752. base_path="1"
  4753. ;;
  4754. -f | --final-ABI)
  4755. final_ABI="1"
  4756. ;;
  4757. -*)
  4758. die "${FUNCNAME}(): Unrecognized option '$1'"
  4759. ;;
  4760. *)
  4761. die "${FUNCNAME}(): Invalid usage"
  4762. ;;
  4763. esac;
  4764. shift;
  4765. done;
  4766. if [[ "${base_path}" == "0" ]]; then
  4767. prefix="/";
  4768. fi;
  4769. if [[ "${final_ABI}" == "1" ]]; then
  4770. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4771. die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4772. fi;
  4773. PYTHON_ABI="$(PYTHON -f --ABI)";
  4774. else
  4775. if _python_package_supporting_installation_for_multiple_python_abis; then
  4776. if ! _python_abi-specific_local_scope; then
  4777. die "${FUNCNAME}() should be used in ABI-specific local scope";
  4778. fi;
  4779. else
  4780. PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  4781. fi;
  4782. fi;
  4783. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  4784. echo "${prefix}usr/$(get_libdir)/python${PYTHON_ABI}/site-packages";
  4785. else
  4786. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  4787. echo "${prefix}usr/share/jython-${PYTHON_ABI%-jython}/Lib/site-packages";
  4788. else
  4789. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  4790. echo "${prefix}usr/$(get_libdir)/pypy${PYTHON_ABI#*-pypy-}/site-packages";
  4791. fi;
  4792. fi;
  4793. fi
  4794. }
  4795. python_get_version ()
  4796. {
  4797. _python_check_python_pkg_setup_execution;
  4798. local final_ABI="0" language="0" language_version full="0" major="0" minor="0" micro="0" PYTHON_ABI="${PYTHON_ABI}" python_command;
  4799. while (($#)); do
  4800. case "$1" in
  4801. -f | --final-ABI)
  4802. final_ABI="1"
  4803. ;;
  4804. -l | --language)
  4805. language="1"
  4806. ;;
  4807. --full)
  4808. full="1"
  4809. ;;
  4810. --major)
  4811. major="1"
  4812. ;;
  4813. --minor)
  4814. minor="1"
  4815. ;;
  4816. --micro)
  4817. micro="1"
  4818. ;;
  4819. -*)
  4820. die "${FUNCNAME}(): Unrecognized option '$1'"
  4821. ;;
  4822. *)
  4823. die "${FUNCNAME}(): Invalid usage"
  4824. ;;
  4825. esac;
  4826. shift;
  4827. done;
  4828. if [[ "${final_ABI}" == "1" ]]; then
  4829. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4830. die "${FUNCNAME}(): '--final-ABI' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4831. fi;
  4832. else
  4833. if _python_package_supporting_installation_for_multiple_python_abis && ! _python_abi-specific_local_scope; then
  4834. die "${FUNCNAME}() should be used in ABI-specific local scope";
  4835. fi;
  4836. fi;
  4837. if [[ "$((${full} + ${major} + ${minor} + ${micro}))" -gt 1 ]]; then
  4838. die "${FUNCNAME}(): '--full', '--major', '--minor' or '--micro' options cannot be specified simultaneously";
  4839. fi;
  4840. if [[ "${language}" == "1" ]]; then
  4841. if [[ "${final_ABI}" == "1" ]]; then
  4842. PYTHON_ABI="$(PYTHON -f --ABI)";
  4843. else
  4844. if [[ -z "${PYTHON_ABI}" ]]; then
  4845. PYTHON_ABI="$(PYTHON --ABI)";
  4846. fi;
  4847. fi;
  4848. language_version="${PYTHON_ABI%%-*}";
  4849. if [[ "${full}" == "1" ]]; then
  4850. die "${FUNCNAME}(): '--language' and '--full' options cannot be specified simultaneously";
  4851. else
  4852. if [[ "${major}" == "1" ]]; then
  4853. echo "${language_version%.*}";
  4854. else
  4855. if [[ "${minor}" == "1" ]]; then
  4856. echo "${language_version#*.}";
  4857. else
  4858. if [[ "${micro}" == "1" ]]; then
  4859. die "${FUNCNAME}(): '--language' and '--micro' options cannot be specified simultaneously";
  4860. else
  4861. echo "${language_version}";
  4862. fi;
  4863. fi;
  4864. fi;
  4865. fi;
  4866. else
  4867. if [[ "${full}" == "1" ]]; then
  4868. python_command="import sys; print('.'.join(str(x) for x in getattr(sys, 'pypy_version_info', sys.version_info)[:3]))";
  4869. else
  4870. if [[ "${major}" == "1" ]]; then
  4871. python_command="import sys; print(getattr(sys, 'pypy_version_info', sys.version_info)[0])";
  4872. else
  4873. if [[ "${minor}" == "1" ]]; then
  4874. python_command="import sys; print(getattr(sys, 'pypy_version_info', sys.version_info)[1])";
  4875. else
  4876. if [[ "${micro}" == "1" ]]; then
  4877. python_command="import sys; print(getattr(sys, 'pypy_version_info', sys.version_info)[2])";
  4878. else
  4879. if [[ -n "${PYTHON_ABI}" && "${final_ABI}" == "0" ]]; then
  4880. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "CPython" ]]; then
  4881. echo "${PYTHON_ABI}";
  4882. else
  4883. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "Jython" ]]; then
  4884. echo "${PYTHON_ABI%-jython}";
  4885. else
  4886. if [[ "$(_python_get_implementation "${PYTHON_ABI}")" == "PyPy" ]]; then
  4887. echo "${PYTHON_ABI#*-pypy-}";
  4888. fi;
  4889. fi;
  4890. fi;
  4891. return;
  4892. fi;
  4893. python_command="from sys import version_info; print('.'.join(str(x) for x in version_info[:2]))";
  4894. fi;
  4895. fi;
  4896. fi;
  4897. fi;
  4898. if [[ "${final_ABI}" == "1" ]]; then
  4899. "$(PYTHON -f)" -c "${python_command}";
  4900. else
  4901. "$(PYTHON ${PYTHON_ABI})" -c "${python_command}";
  4902. fi;
  4903. fi
  4904. }
  4905. python_merge_intermediate_installation_images ()
  4906. {
  4907. if [[ "${EBUILD_PHASE}" != "install" ]]; then
  4908. die "${FUNCNAME}() can be used only in src_install() phase";
  4909. fi;
  4910. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  4911. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  4912. fi;
  4913. _python_check_python_pkg_setup_execution;
  4914. _python_initialize_prefix_variables;
  4915. local absolute_file b file files=() intermediate_installation_images_directory PYTHON_ABI quiet="0" regex shebang version_executable wrapper_scripts=() wrapper_scripts_set=();
  4916. while (($#)); do
  4917. case "$1" in
  4918. -q | --quiet)
  4919. quiet="1"
  4920. ;;
  4921. --)
  4922. shift;
  4923. break
  4924. ;;
  4925. -*)
  4926. die "${FUNCNAME}(): Unrecognized option '$1'"
  4927. ;;
  4928. *)
  4929. break
  4930. ;;
  4931. esac;
  4932. shift;
  4933. done;
  4934. if [[ "$#" -ne 1 ]]; then
  4935. die "${FUNCNAME}() requires 1 argument";
  4936. fi;
  4937. intermediate_installation_images_directory="$1";
  4938. if [[ ! -d "${intermediate_installation_images_directory}" ]]; then
  4939. die "${FUNCNAME}(): Intermediate installation images directory '${intermediate_installation_images_directory}' does not exist";
  4940. fi;
  4941. _python_calculate_PYTHON_ABIS;
  4942. if [[ "$(PYTHON -f --ABI)" == 3.* ]]; then
  4943. b="b";
  4944. fi;
  4945. while read -d '' -r file; do
  4946. files+=("${file}");
  4947. done < <("$(PYTHON -f)" -c "import os
  4948. import sys
  4949.  
  4950. if hasattr(sys.stdout, 'buffer'):
  4951. # Python 3
  4952. stdout = sys.stdout.buffer
  4953. else:
  4954. # Python 2
  4955. stdout = sys.stdout
  4956.  
  4957. files_set = set()
  4958.  
  4959. os.chdir(${b}'${intermediate_installation_images_directory}')
  4960.  
  4961. for PYTHON_ABI in ${b}'${PYTHON_ABIS}'.split():
  4962. for root, dirs, files in os.walk(PYTHON_ABI + ${b}'${EPREFIX}'):
  4963. root = root[len(PYTHON_ABI + ${b}'${EPREFIX}')+1:]
  4964. files_set.update(root + ${b}'/' + file for file in files)
  4965.  
  4966. for file in sorted(files_set):
  4967. stdout.write(file)
  4968. stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of files in intermediate installation images");
  4969. for PYTHON_ABI in ${PYTHON_ABIS};
  4970. do
  4971. if [[ ! -d "${intermediate_installation_images_directory}/${PYTHON_ABI}" ]]; then
  4972. die "${FUNCNAME}(): Intermediate installation image for Python ABI '${PYTHON_ABI}' does not exist";
  4973. fi;
  4974. pushd "${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}" > /dev/null || die "pushd failed";
  4975. for file in "${files[@]}";
  4976. do
  4977. version_executable="0";
  4978. for regex in "/usr/bin/.*" "/usr/sbin/.*" "${PYTHON_VERSIONED_SCRIPTS[@]}";
  4979. do
  4980. if [[ "/${file}" =~ ^${regex}$ ]]; then
  4981. version_executable="1";
  4982. break;
  4983. fi;
  4984. done;
  4985. for regex in "${PYTHON_VERSIONED_EXECUTABLES[@]}";
  4986. do
  4987. if [[ "/${file}" =~ ^${regex}$ ]]; then
  4988. version_executable="2";
  4989. break;
  4990. fi;
  4991. done;
  4992. if [[ "${version_executable}" != "0" ]]; then
  4993. for regex in "${PYTHON_NONVERSIONED_EXECUTABLES[@]}";
  4994. do
  4995. if [[ "/${file}" =~ ^${regex}$ ]]; then
  4996. version_executable="0";
  4997. break;
  4998. fi;
  4999. done;
  5000. fi;
  5001. [[ "${version_executable}" == "0" ]] && continue;
  5002. if [[ -L "${file}" ]]; then
  5003. absolute_file="$(readlink "${file}")";
  5004. if [[ "${absolute_file}" == /* ]]; then
  5005. absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${absolute_file##/}";
  5006. else
  5007. if [[ "${file}" == */* ]]; then
  5008. absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${file%/*}/${absolute_file}";
  5009. else
  5010. absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${absolute_file}";
  5011. fi;
  5012. fi;
  5013. else
  5014. absolute_file="${intermediate_installation_images_directory}/${PYTHON_ABI}${EPREFIX}/${file}";
  5015. fi;
  5016. [[ ! -x "${absolute_file}" ]] && continue;
  5017. shebang="$(head -n1 "${absolute_file}")" || die "Extraction of shebang from '${absolute_file}' failed";
  5018. if [[ "${version_executable}" == "2" ]]; then
  5019. wrapper_scripts+=("${ED}${file}");
  5020. else
  5021. if [[ "${version_executable}" == "1" ]]; then
  5022. if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}([[:digit:]]+(\.[[:digit:]]+)?)?($|[[:space:]]+) ]]; then
  5023. wrapper_scripts+=("${ED}${file}");
  5024. else
  5025. version_executable="0";
  5026. fi;
  5027. fi;
  5028. fi;
  5029. [[ "${version_executable}" == "0" ]] && continue;
  5030. if [[ -e "${file}-${PYTHON_ABI}" ]]; then
  5031. die "${FUNCNAME}(): '${EPREFIX}/${file}-${PYTHON_ABI}' already exists";
  5032. fi;
  5033. mv "${file}" "${file}-${PYTHON_ABI}" || die "Renaming of '${file}' failed";
  5034. if [[ "${shebang}" =~ ${_PYTHON_SHEBANG_BASE_PART_REGEX}[[:digit:]]*($|[[:space:]]+) ]]; then
  5035. if [[ -L "${file}-${PYTHON_ABI}" ]]; then
  5036. python_convert_shebangs $([[ "${quiet}" == "1" ]] && echo --quiet) "${PYTHON_ABI}" "${absolute_file}";
  5037. else
  5038. python_convert_shebangs $([[ "${quiet}" == "1" ]] && echo --quiet) "${PYTHON_ABI}" "${file}-${PYTHON_ABI}";
  5039. fi;
  5040. fi;
  5041. done;
  5042. popd > /dev/null || die "popd failed";
  5043. if ROOT="/" has_version '>=sys-apps/coreutils-6.9.90'; then
  5044. 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";
  5045. else
  5046. if ROOT="/" has_version sys-apps/coreutils; then
  5047. 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";
  5048. else
  5049. cp -fpr "${intermediate_installation_images_directory}/${PYTHON_ABI}/"* "${D}" || die "Merging of intermediate installation image for Python ABI '${PYTHON_ABI} into installation image failed";
  5050. fi;
  5051. fi;
  5052. done;
  5053. rm -fr "${intermediate_installation_images_directory}";
  5054. if [[ "${#wrapper_scripts[@]}" -ge 1 ]]; then
  5055. rm -f "${T}/python_wrapper_scripts";
  5056. for file in "${wrapper_scripts[@]}";
  5057. do
  5058. echo -n "${file}" >> "${T}/python_wrapper_scripts";
  5059. echo -en "\x00" >> "${T}/python_wrapper_scripts";
  5060. done;
  5061. while read -d '' -r file; do
  5062. wrapper_scripts_set+=("${file}");
  5063. done < <("$(PYTHON -f)" -c "import sys
  5064.  
  5065. if hasattr(sys.stdout, 'buffer'):
  5066. # Python 3
  5067. stdout = sys.stdout.buffer
  5068. else:
  5069. # Python 2
  5070. stdout = sys.stdout
  5071.  
  5072. python_wrapper_scripts_file = open('${T}/python_wrapper_scripts', 'rb')
  5073. files = set(python_wrapper_scripts_file.read().rstrip(${b}'\x00').split(${b}'\x00'))
  5074. python_wrapper_scripts_file.close()
  5075.  
  5076. for file in sorted(files):
  5077. stdout.write(file)
  5078. stdout.write(${b}'\x00')" || die "${FUNCNAME}(): Failure of extraction of set of wrapper scripts");
  5079. python_generate_wrapper_scripts $([[ "${quiet}" == "1" ]] && echo --quiet) "${wrapper_scripts_set[@]}";
  5080. fi
  5081. }
  5082. python_mod_cleanup ()
  5083. {
  5084. if [[ "${EBUILD_PHASE}" != "postrm" ]]; then
  5085. die "${FUNCNAME}() can be used only in pkg_postrm() phase";
  5086. fi;
  5087. _python_check_python_pkg_setup_execution;
  5088. _python_initialize_prefix_variables;
  5089. local allow_evaluated_non_sitedir_paths="0" dir iterated_PYTHON_ABIS PYTHON_ABI="${PYTHON_ABI}" root search_paths=() sitedir;
  5090. if _python_package_supporting_installation_for_multiple_python_abis; then
  5091. if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
  5092. die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called";
  5093. fi;
  5094. iterated_PYTHON_ABIS="${PYTHON_ABIS}";
  5095. else
  5096. if has "${EAPI:-0}" 0 1 2 3; then
  5097. iterated_PYTHON_ABIS="${PYTHON_ABI:-$(PYTHON --ABI)}";
  5098. else
  5099. iterated_PYTHON_ABIS="${PYTHON_ABI}";
  5100. fi;
  5101. fi;
  5102. root="${EROOT%/}";
  5103. while (($#)); do
  5104. case "$1" in
  5105. --allow-evaluated-non-sitedir-paths)
  5106. allow_evaluated_non_sitedir_paths="1"
  5107. ;;
  5108. --)
  5109. shift;
  5110. break
  5111. ;;
  5112. -*)
  5113. die "${FUNCNAME}(): Unrecognized option '$1'"
  5114. ;;
  5115. *)
  5116. break
  5117. ;;
  5118. esac;
  5119. shift;
  5120. done;
  5121. if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
  5122. die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  5123. fi;
  5124. if [[ "$#" -eq 0 ]]; then
  5125. die "${FUNCNAME}(): Missing files or directories";
  5126. fi;
  5127. if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
  5128. while (($#)); do
  5129. if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
  5130. die "${FUNCNAME}(): Invalid argument '$1'";
  5131. else
  5132. if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
  5133. die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories";
  5134. else
  5135. if [[ "$1" =~ ^/ ]]; then
  5136. if _python_package_supporting_installation_for_multiple_python_abis; then
  5137. if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
  5138. die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs";
  5139. fi;
  5140. if [[ "$1" != *\$* ]]; then
  5141. die "${FUNCNAME}(): '$1' has invalid syntax";
  5142. fi;
  5143. for PYTHON_ABI in ${iterated_PYTHON_ABIS};
  5144. do
  5145. eval "search_paths+=(\"\${root}$1\")";
  5146. done;
  5147. else
  5148. search_paths+=("${root}$1");
  5149. fi;
  5150. else
  5151. for PYTHON_ABI in ${iterated_PYTHON_ABIS};
  5152. do
  5153. search_paths+=("${root}$(python_get_sitedir)/$1");
  5154. done;
  5155. fi;
  5156. fi;
  5157. fi;
  5158. shift;
  5159. done;
  5160. else
  5161. ewarn;
  5162. ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation";
  5163. ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-08-01.";
  5164. ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax.";
  5165. ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported.";
  5166. ewarn;
  5167. search_paths=("${@#/}");
  5168. search_paths=("${search_paths[@]/#/${root}/}");
  5169. fi;
  5170. _python_clean_compiled_modules "${search_paths[@]}"
  5171. }
  5172. python_mod_optimize ()
  5173. {
  5174. if [[ "${EBUILD_PHASE}" != "postinst" ]]; then
  5175. die "${FUNCNAME}() can be used only in pkg_postinst() phase";
  5176. fi;
  5177. _python_check_python_pkg_setup_execution;
  5178. _python_initialize_prefix_variables;
  5179. if ! has "${EAPI:-0}" 0 1 2 || _python_package_supporting_installation_for_multiple_python_abis || _python_implementation || [[ "${CATEGORY}/${PN}" == "sys-apps/portage" ]]; then
  5180. 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;
  5181. if _python_package_supporting_installation_for_multiple_python_abis; then
  5182. if has "${EAPI:-0}" 0 1 2 3 && [[ -z "${PYTHON_ABIS}" ]]; then
  5183. die "${FUNCNAME}(): python_pkg_setup() or python_execute_function() not called";
  5184. fi;
  5185. iterated_PYTHON_ABIS="${PYTHON_ABIS}";
  5186. else
  5187. if has "${EAPI:-0}" 0 1 2 3; then
  5188. iterated_PYTHON_ABIS="${PYTHON_ABI:=$(PYTHON --ABI)}";
  5189. else
  5190. iterated_PYTHON_ABIS="${PYTHON_ABI}";
  5191. fi;
  5192. fi;
  5193. root="${EROOT%/}";
  5194. while (($#)); do
  5195. case "$1" in
  5196. --allow-evaluated-non-sitedir-paths)
  5197. allow_evaluated_non_sitedir_paths="1"
  5198. ;;
  5199. -l | -f | -q)
  5200. options+=("$1")
  5201. ;;
  5202. -d | -x)
  5203. options+=("$1" "$2");
  5204. shift
  5205. ;;
  5206. --)
  5207. shift;
  5208. break
  5209. ;;
  5210. -*)
  5211. die "${FUNCNAME}(): Unrecognized option '$1'"
  5212. ;;
  5213. *)
  5214. break
  5215. ;;
  5216. esac;
  5217. shift;
  5218. done;
  5219. if [[ "${allow_evaluated_non_sitedir_paths}" == "1" ]] && ! _python_package_supporting_installation_for_multiple_python_abis; then
  5220. die "${FUNCNAME}(): '--allow-evaluated-non-sitedir-paths' option cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  5221. fi;
  5222. if [[ "$#" -eq 0 ]]; then
  5223. die "${FUNCNAME}(): Missing files or directories";
  5224. fi;
  5225. while (($#)); do
  5226. if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
  5227. die "${FUNCNAME}(): Invalid argument '$1'";
  5228. else
  5229. if ! _python_implementation && [[ "$1" =~ ^/usr/lib(32|64)?/python[[:digit:]]+\.[[:digit:]]+ ]]; then
  5230. die "${FUNCNAME}(): Paths of directories / files in site-packages directories must be relative to site-packages directories";
  5231. else
  5232. if [[ "$1" =~ ^/ ]]; then
  5233. if _python_package_supporting_installation_for_multiple_python_abis; then
  5234. if [[ "${allow_evaluated_non_sitedir_paths}" != "1" ]]; then
  5235. die "${FUNCNAME}(): Absolute paths cannot be used in ebuilds of packages supporting installation for multiple Python ABIs";
  5236. fi;
  5237. if [[ "$1" != *\$* ]]; then
  5238. die "${FUNCNAME}(): '$1' has invalid syntax";
  5239. fi;
  5240. if [[ "$1" == *.py ]]; then
  5241. evaluated_files+=("$1");
  5242. else
  5243. evaluated_dirs+=("$1");
  5244. fi;
  5245. else
  5246. if [[ -d "${root}$1" ]]; then
  5247. other_dirs+=("${root}$1");
  5248. else
  5249. if [[ -f "${root}$1" ]]; then
  5250. other_files+=("${root}$1");
  5251. else
  5252. if [[ -e "${root}$1" ]]; then
  5253. eerror "${FUNCNAME}(): '${root}$1' is not a regular file or a directory";
  5254. else
  5255. eerror "${FUNCNAME}(): '${root}$1' does not exist";
  5256. fi;
  5257. fi;
  5258. fi;
  5259. fi;
  5260. else
  5261. for PYTHON_ABI in ${iterated_PYTHON_ABIS};
  5262. do
  5263. if [[ -d "${root}$(python_get_sitedir)/$1" ]]; then
  5264. site_packages_dirs+=("$1");
  5265. break;
  5266. else
  5267. if [[ -f "${root}$(python_get_sitedir)/$1" ]]; then
  5268. site_packages_files+=("$1");
  5269. break;
  5270. else
  5271. if [[ -e "${root}$(python_get_sitedir)/$1" ]]; then
  5272. eerror "${FUNCNAME}(): '$1' is not a regular file or a directory";
  5273. else
  5274. eerror "${FUNCNAME}(): '$1' does not exist";
  5275. fi;
  5276. fi;
  5277. fi;
  5278. done;
  5279. fi;
  5280. fi;
  5281. fi;
  5282. shift;
  5283. done;
  5284. options+=("-q");
  5285. for PYTHON_ABI in ${iterated_PYTHON_ABIS};
  5286. do
  5287. if ((${#site_packages_dirs[@]})) || ((${#site_packages_files[@]})) || ((${#evaluated_dirs[@]})) || ((${#evaluated_files[@]})); then
  5288. return_code="0";
  5289. stderr="";
  5290. ebegin "Compilation and optimization of Python modules for $(python_get_implementation_and_version)";
  5291. if ((${#site_packages_dirs[@]})) || ((${#evaluated_dirs[@]})); then
  5292. for dir in "${site_packages_dirs[@]}";
  5293. do
  5294. dirs+=("${root}$(python_get_sitedir)/${dir}");
  5295. done;
  5296. for dir in "${evaluated_dirs[@]}";
  5297. do
  5298. eval "dirs+=(\"\${root}${dir}\")";
  5299. done;
  5300. stderr+="${stderr:+
  5301. }$("$(PYTHON)" -m compileall "${options[@]}" "${dirs[@]}" 2>&1)" || return_code="1";
  5302. if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
  5303. "$(PYTHON)" -O -m compileall "${options[@]}" "${dirs[@]}" &>/dev/null || return_code="1";
  5304. fi;
  5305. _python_clean_compiled_modules "${dirs[@]}";
  5306. fi;
  5307. if ((${#site_packages_files[@]})) || ((${#evaluated_files[@]})); then
  5308. for file in "${site_packages_files[@]}";
  5309. do
  5310. files+=("${root}$(python_get_sitedir)/${file}");
  5311. done;
  5312. for file in "${evaluated_files[@]}";
  5313. do
  5314. eval "files+=(\"\${root}${file}\")";
  5315. done;
  5316. stderr+="${stderr:+
  5317. }$("$(PYTHON)" -m py_compile "${files[@]}" 2>&1)" || return_code="1";
  5318. if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
  5319. "$(PYTHON)" -O -m py_compile "${files[@]}" &>/dev/null || return_code="1";
  5320. fi;
  5321. _python_clean_compiled_modules "${files[@]}";
  5322. fi;
  5323. eend "${return_code}";
  5324. if [[ -n "${stderr}" ]]; then
  5325. eerror "Syntax errors / warnings in Python modules for $(python_get_implementation_and_version):" &>/dev/null;
  5326. while read stderr_line; do
  5327. eerror " ${stderr_line}";
  5328. done <<< "${stderr}";
  5329. fi;
  5330. fi;
  5331. unset dirs files;
  5332. done;
  5333. if _python_package_supporting_installation_for_multiple_python_abis; then
  5334. if [[ -n "${previous_PYTHON_ABI}" ]]; then
  5335. PYTHON_ABI="${previous_PYTHON_ABI}";
  5336. else
  5337. unset PYTHON_ABI;
  5338. fi;
  5339. fi;
  5340. if ((${#other_dirs[@]})) || ((${#other_files[@]})); then
  5341. return_code="0";
  5342. stderr="";
  5343. ebegin "Compilation and optimization of Python modules placed outside of site-packages directories for $(python_get_implementation_and_version)";
  5344. if ((${#other_dirs[@]})); then
  5345. stderr+="${stderr:+
  5346. }$("$(PYTHON ${PYTHON_ABI})" -m compileall "${options[@]}" "${other_dirs[@]}" 2>&1)" || return_code="1";
  5347. if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
  5348. "$(PYTHON ${PYTHON_ABI})" -O -m compileall "${options[@]}" "${other_dirs[@]}" &>/dev/null || return_code="1";
  5349. fi;
  5350. _python_clean_compiled_modules "${other_dirs[@]}";
  5351. fi;
  5352. if ((${#other_files[@]})); then
  5353. stderr+="${stderr:+
  5354. }$("$(PYTHON ${PYTHON_ABI})" -m py_compile "${other_files[@]}" 2>&1)" || return_code="1";
  5355. if ! has "$(_python_get_implementation "${PYTHON_ABI}")" Jython PyPy; then
  5356. "$(PYTHON ${PYTHON_ABI})" -O -m py_compile "${other_files[@]}" &>/dev/null || return_code="1";
  5357. fi;
  5358. _python_clean_compiled_modules "${other_files[@]}";
  5359. fi;
  5360. eend "${return_code}";
  5361. if [[ -n "${stderr}" ]]; then
  5362. eerror "Syntax errors / warnings in Python modules placed outside of site-packages directories for $(python_get_implementation_and_version):" &>/dev/null;
  5363. while read stderr_line; do
  5364. eerror " ${stderr_line}";
  5365. done <<< "${stderr}";
  5366. fi;
  5367. fi;
  5368. else
  5369. ewarn;
  5370. ewarn "Deprecation Warning: Usage of ${FUNCNAME}() in packages not supporting installation";
  5371. ewarn "for multiple Python ABIs in EAPI <=2 is deprecated and will be disallowed on 2011-08-01.";
  5372. ewarn "Use EAPI >=3 and call ${FUNCNAME}() with paths having appropriate syntax.";
  5373. ewarn "The ebuild needs to be fixed. Please report a bug, if it has not been already reported.";
  5374. ewarn;
  5375. local myroot mydirs=() myfiles=() myopts=() return_code="0";
  5376. myroot="${EROOT%/}";
  5377. while (($#)); do
  5378. case "$1" in
  5379. -l | -f | -q)
  5380. myopts+=("$1")
  5381. ;;
  5382. -d | -x)
  5383. myopts+=("$1" "$2");
  5384. shift
  5385. ;;
  5386. --)
  5387. shift;
  5388. break
  5389. ;;
  5390. -*)
  5391. die "${FUNCNAME}(): Unrecognized option '$1'"
  5392. ;;
  5393. *)
  5394. break
  5395. ;;
  5396. esac;
  5397. shift;
  5398. done;
  5399. if [[ "$#" -eq 0 ]]; then
  5400. die "${FUNCNAME}(): Missing files or directories";
  5401. fi;
  5402. while (($#)); do
  5403. if [[ "$1" =~ ^($|(\.|\.\.|/)($|/)) ]]; then
  5404. die "${FUNCNAME}(): Invalid argument '$1'";
  5405. else
  5406. if [[ -d "${myroot}/${1#/}" ]]; then
  5407. mydirs+=("${myroot}/${1#/}");
  5408. else
  5409. if [[ -f "${myroot}/${1#/}" ]]; then
  5410. myfiles+=("${myroot}/${1#/}");
  5411. else
  5412. if [[ -e "${myroot}/${1#/}" ]]; then
  5413. eerror "${FUNCNAME}(): ${myroot}/${1#/} is not a regular file or directory";
  5414. else
  5415. eerror "${FUNCNAME}(): ${myroot}/${1#/} does not exist";
  5416. fi;
  5417. fi;
  5418. fi;
  5419. fi;
  5420. shift;
  5421. done;
  5422. myopts+=(-q);
  5423. PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  5424. ebegin "Compilation and optimization of Python modules for $(python_get_implementation) $(python_get_version)";
  5425. if ((${#mydirs[@]})); then
  5426. "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" || return_code="1";
  5427. "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/compileall.py" "${myopts[@]}" "${mydirs[@]}" &>/dev/null || return_code="1";
  5428. _python_clean_compiled_modules "${mydirs[@]}";
  5429. fi;
  5430. if ((${#myfiles[@]})); then
  5431. "$(PYTHON ${PYTHON_ABI})" "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" || return_code="1";
  5432. "$(PYTHON ${PYTHON_ABI})" -O "${myroot}$(python_get_libdir)/py_compile.py" "${myfiles[@]}" &>/dev/null || return_code="1";
  5433. _python_clean_compiled_modules "${myfiles[@]}";
  5434. fi;
  5435. eend "${return_code}";
  5436. fi
  5437. }
  5438. python_need_rebuild ()
  5439. {
  5440. if _python_package_supporting_installation_for_multiple_python_abis; then
  5441. die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs";
  5442. fi;
  5443. _python_check_python_pkg_setup_execution;
  5444. if [[ "$#" -ne 0 ]]; then
  5445. die "${FUNCNAME}() does not accept arguments";
  5446. fi;
  5447. export PYTHON_NEED_REBUILD="$(PYTHON --ABI)"
  5448. }
  5449. python_pkg_setup ()
  5450. {
  5451. if [[ "${EBUILD_PHASE}" != "setup" ]]; then
  5452. die "${FUNCNAME}() can be used only in pkg_setup() phase";
  5453. fi;
  5454. if [[ "$#" -ne 0 ]]; then
  5455. die "${FUNCNAME}() does not accept arguments";
  5456. fi;
  5457. export JYTHON_SYSTEM_CACHEDIR="1";
  5458. addwrite "${EPREFIX}/var/cache/jython";
  5459. if _python_package_supporting_installation_for_multiple_python_abis; then
  5460. _python_calculate_PYTHON_ABIS;
  5461. export EPYTHON="$(PYTHON -f)";
  5462. else
  5463. PYTHON_ABI="${PYTHON_ABI:-$(PYTHON --ABI)}";
  5464. fi;
  5465. if ! has "${EAPI:-0}" 0 1 && [[ -n "${PYTHON_USE_WITH}" || -n "${PYTHON_USE_WITH_OR}" ]]; then
  5466. if [[ -n "${PYTHON_USE_WITH_OPT}" ]]; then
  5467. if [[ "${PYTHON_USE_WITH_OPT}" == !* ]]; then
  5468. use ${PYTHON_USE_WITH_OPT#!} && return;
  5469. else
  5470. use !${PYTHON_USE_WITH_OPT} && return;
  5471. fi;
  5472. fi;
  5473. function python_pkg_setup_check_USE_flags ()
  5474. {
  5475. local python_atom USE_flag;
  5476. python_atom="$(python_get_implementational_package)";
  5477. for USE_flag in ${PYTHON_USE_WITH};
  5478. do
  5479. if ! has_version "${python_atom}[${USE_flag}]"; then
  5480. eerror "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}";
  5481. die "Please rebuild ${python_atom} with the following USE flags enabled: ${PYTHON_USE_WITH}";
  5482. fi;
  5483. done;
  5484. for USE_flag in ${PYTHON_USE_WITH_OR};
  5485. do
  5486. if has_version "${python_atom}[${USE_flag}]"; then
  5487. return;
  5488. fi;
  5489. done;
  5490. if [[ -n ${PYTHON_USE_WITH_OR} ]]; then
  5491. eerror "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}";
  5492. die "Please rebuild ${python_atom} with at least one of the following USE flags enabled: ${PYTHON_USE_WITH_OR}";
  5493. fi
  5494. };
  5495. if _python_package_supporting_installation_for_multiple_python_abis; then
  5496. PYTHON_SKIP_SANITY_CHECKS="1" python_execute_function -q python_pkg_setup_check_USE_flags;
  5497. else
  5498. python_pkg_setup_check_USE_flags;
  5499. fi;
  5500. unset -f python_pkg_setup_check_USE_flags;
  5501. fi;
  5502. PYTHON_PKG_SETUP_EXECUTED="1"
  5503. }
  5504. python_set_active_version ()
  5505. {
  5506. if [[ "${EBUILD_PHASE}" != "setup" ]]; then
  5507. die "${FUNCNAME}() can be used only in pkg_setup() phase";
  5508. fi;
  5509. if _python_package_supporting_installation_for_multiple_python_abis; then
  5510. die "${FUNCNAME}() cannot be used in ebuilds of packages supporting installation for multiple Python ABIs";
  5511. fi;
  5512. if [[ "$#" -ne 1 ]]; then
  5513. die "${FUNCNAME}() requires 1 argument";
  5514. fi;
  5515. _python_initial_sanity_checks;
  5516. if [[ -z "${PYTHON_ABI}" ]]; then
  5517. if [[ -n "$(_python_get_implementation --ignore-invalid "$1")" ]]; then
  5518. PYTHON_ABI="$1";
  5519. if ! _python_implementation && ! has_version "$(python_get_implementational_package)"; then
  5520. die "${FUNCNAME}(): '$(python_get_implementational_package)' is not installed";
  5521. fi;
  5522. export EPYTHON="$(PYTHON "$1")";
  5523. else
  5524. if [[ "$1" == "2" ]]; then
  5525. if ! _python_implementation && ! has_version "=dev-lang/python-2*"; then
  5526. die "${FUNCNAME}(): '=dev-lang/python-2*' is not installed";
  5527. fi;
  5528. export EPYTHON="$(PYTHON -2)";
  5529. PYTHON_ABI="${EPYTHON#python}";
  5530. PYTHON_ABI="${PYTHON_ABI%%-*}";
  5531. else
  5532. if [[ "$1" == "3" ]]; then
  5533. if ! _python_implementation && ! has_version "=dev-lang/python-3*"; then
  5534. die "${FUNCNAME}(): '=dev-lang/python-3*' is not installed";
  5535. fi;
  5536. export EPYTHON="$(PYTHON -3)";
  5537. PYTHON_ABI="${EPYTHON#python}";
  5538. PYTHON_ABI="${PYTHON_ABI%%-*}";
  5539. else
  5540. die "${FUNCNAME}(): Unrecognized argument '$1'";
  5541. fi;
  5542. fi;
  5543. fi;
  5544. fi;
  5545. _python_final_sanity_checks;
  5546. PYTHON_REQUESTED_ACTIVE_VERSION="$1"
  5547. }
  5548. python_src_compile ()
  5549. {
  5550. if [[ "${EBUILD_PHASE}" != "compile" ]]; then
  5551. die "${FUNCNAME}() can be used only in src_compile() phase";
  5552. fi;
  5553. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  5554. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  5555. fi;
  5556. _python_check_python_pkg_setup_execution;
  5557. python_execute_function -d -s -- "$@"
  5558. }
  5559. python_src_configure ()
  5560. {
  5561. if [[ "${EBUILD_PHASE}" != "configure" ]]; then
  5562. die "${FUNCNAME}() can be used only in src_configure() phase";
  5563. fi;
  5564. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  5565. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  5566. fi;
  5567. _python_check_python_pkg_setup_execution;
  5568. python_execute_function -d -s -- "$@"
  5569. }
  5570. python_src_install ()
  5571. {
  5572. if [[ "${EBUILD_PHASE}" != "install" ]]; then
  5573. die "${FUNCNAME}() can be used only in src_install() phase";
  5574. fi;
  5575. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  5576. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  5577. fi;
  5578. _python_check_python_pkg_setup_execution;
  5579. if has "${EAPI:-0}" 0 1 2 3; then
  5580. python_execute_function -d -s -- "$@";
  5581. else
  5582. function python_installation ()
  5583. {
  5584. emake DESTDIR="${T}/images/${PYTHON_ABI}" install "$@"
  5585. };
  5586. python_execute_function -s python_installation "$@";
  5587. unset python_installation;
  5588. python_merge_intermediate_installation_images "${T}/images";
  5589. fi
  5590. }
  5591. python_src_prepare ()
  5592. {
  5593. if [[ "${EBUILD_PHASE}" != "prepare" ]]; then
  5594. die "${FUNCNAME}() can be used only in src_prepare() phase";
  5595. fi;
  5596. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  5597. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  5598. fi;
  5599. _python_check_python_pkg_setup_execution;
  5600. if [[ "$#" -ne 0 ]]; then
  5601. die "${FUNCNAME}() does not accept arguments";
  5602. fi;
  5603. python_copy_sources
  5604. }
  5605. python_src_test ()
  5606. {
  5607. if [[ "${EBUILD_PHASE}" != "test" ]]; then
  5608. die "${FUNCNAME}() can be used only in src_test() phase";
  5609. fi;
  5610. if ! _python_package_supporting_installation_for_multiple_python_abis; then
  5611. die "${FUNCNAME}() cannot be used in ebuilds of packages not supporting installation for multiple Python ABIs";
  5612. fi;
  5613. _python_check_python_pkg_setup_execution;
  5614. python_execute_function -d -s -- "$@"
  5615. }
  5616. raw-ldflags ()
  5617. {
  5618. local x input="$@";
  5619. [[ -z ${input} ]] && input=${LDFLAGS};
  5620. set --;
  5621. for x in ${input};
  5622. do
  5623. x=${x#-Wl,};
  5624. set -- "$@" ${x//,/ };
  5625. done;
  5626. echo "$@"
  5627. }
  5628. replace-cpu-flags ()
  5629. {
  5630. local newcpu="$#";
  5631. newcpu="${!newcpu}";
  5632. while [ $# -gt 1 ]; do
  5633. replace-flags "-march=${1}" "-march=${newcpu}";
  5634. replace-flags "-mcpu=${1}" "-mcpu=${newcpu}";
  5635. replace-flags "-mtune=${1}" "-mtune=${newcpu}";
  5636. shift;
  5637. done;
  5638. return 0
  5639. }
  5640. replace-flags ()
  5641. {
  5642. [[ $# != 2 ]] && echo && eerror "Usage: replace-flags <old flag> <new flag>" && die "replace-flags takes 2 arguments, not $#";
  5643. local f fset;
  5644. declare -a new_CFLAGS new_CXXFLAGS new_FFLAGS new_FCFLAGS;
  5645. for fset in CFLAGS CXXFLAGS FFLAGS FCFLAGS;
  5646. do
  5647. for f in ${!fset};
  5648. do
  5649. [[ ${f} == ${1} ]] && f=${2};
  5650. eval new_${fset}\[\${\#new_${fset}\[@]}]=\${f};
  5651. done;
  5652. eval export ${fset}=\${new_${fset}\[*]};
  5653. done;
  5654. return 0
  5655. }
  5656. replace-sparc64-flags ()
  5657. {
  5658. local SPARC64_CPUS="ultrasparc3 ultrasparc v9";
  5659. if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then
  5660. for x in ${SPARC64_CPUS};
  5661. do
  5662. CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}";
  5663. done;
  5664. else
  5665. for x in ${SPARC64_CPUS};
  5666. do
  5667. CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}";
  5668. done;
  5669. fi;
  5670. if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then
  5671. for x in ${SPARC64_CPUS};
  5672. do
  5673. CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}";
  5674. done;
  5675. else
  5676. for x in ${SPARC64_CPUS};
  5677. do
  5678. CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}";
  5679. done;
  5680. fi;
  5681. export CFLAGS CXXFLAGS
  5682. }
  5683. seq ()
  5684. {
  5685. local p=$(type -P seq);
  5686. if [[ -n ${p} ]]; then
  5687. "${p}" "$@";
  5688. return $?;
  5689. fi;
  5690. case $# in
  5691. 1)
  5692. min=1 max=$1 step=1
  5693. ;;
  5694. 2)
  5695. min=$1 max=$2 step=1
  5696. ;;
  5697. 3)
  5698. min=$1 max=$3 step=$2
  5699. ;;
  5700. *)
  5701. die "seq called with wrong number of arguments"
  5702. ;;
  5703. esac;
  5704. p=$(type -P jot);
  5705. if [[ -n ${p} ]]; then
  5706. local reps;
  5707. if [[ ${step} != 0 ]]; then
  5708. reps=$(( (max - min) / step + 1 ));
  5709. else
  5710. reps=0;
  5711. fi;
  5712. jot $reps $min $max $step;
  5713. return $?;
  5714. fi;
  5715. while :; do
  5716. [[ $max < $min && $step > 0 ]] && break;
  5717. [[ $min < $max && $step < 0 ]] && break;
  5718. echo $min;
  5719. : $(( min += step ));
  5720. done;
  5721. return 0
  5722. }
  5723. setup-allowed-flags ()
  5724. {
  5725. ALLOWED_FLAGS="-pipe";
  5726. ALLOWED_FLAGS+=" -O -O1 -O2 -Os -mcpu -march -mtune";
  5727. ALLOWED_FLAGS+=" -fstack-protector -fstack-protector-all";
  5728. ALLOWED_FLAGS+=" -fbounds-checking -fno-strict-overflow";
  5729. ALLOWED_FLAGS+=" -fno-PIE -fno-pie -fno-unit-at-a-time";
  5730. ALLOWED_FLAGS+=" -g -g[0-9] -ggdb -ggdb[0-9] -gstabs -gstabs+";
  5731. ALLOWED_FLAGS+=" -fno-ident -fpermissive";
  5732. ALLOWED_FLAGS+=" -W* -w";
  5733. ALLOWED_FLAGS+=" -fno-stack-protector -fno-stack-protector-all -fno-strict-aliasing -fno-bounds-checking -fstrict-overflow -fno-omit-frame-pointer";
  5734. ALLOWED_FLAGS+=" -mregparm -mno-app-regs -mapp-regs -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4 -mno-sse4.1 -mno-sse4.2 -mno-avx -mno-aes -mno-pclmul -mno-sse4a -mno-3dnow -mno-popcnt -mno-abm -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 -mplt -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu -mieee -mieee-with-inexact -mschedule -mfloat-gprs -mspe -mno-spe -mtls-direct-seg-refs -mno-tls-direct-seg-refs -mflat -mno-flat -mno-faster-structs -mfaster-structs -m32 -m64 -mx32 -mabi -mlittle-endian -mbig-endian -EL -EB -fPIC -mlive-g0 -mcmodel -mstack-bias -mno-stack-bias -msecure-plt -m*-toc -D* -U*";
  5735. ALLOWED_FLAGS+=" -mno-fma4 -mno-movbe -mno-xop -mno-lwp";
  5736. ALLOWED_FLAGS+=" -mno-fsgsbase -mno-rdrnd -mno-f16c -mno-bmi -mno-tbm";
  5737. export ALLOWED_FLAGS;
  5738. return 0
  5739. }
  5740. src_compile ()
  5741. {
  5742. emake || die "emake failed";
  5743. use doc && {
  5744. emake avahi.devhelp || die
  5745. }
  5746. }
  5747. src_configure ()
  5748. {
  5749. use sh && replace-flags -O? -O0;
  5750. local myconf="--disable-static";
  5751. if use python; then
  5752. myconf+="
  5753. $(use_enable dbus python-dbus)
  5754. $(use_enable gtk pygtk)
  5755. ";
  5756. fi;
  5757. if use mono; then
  5758. myconf+=" $(use_enable doc monodoc)";
  5759. fi;
  5760. if use mdnsresponder-compat || use howl-compat || use mono; then
  5761. myconf+=" --enable-dbus";
  5762. fi;
  5763. unset DISPLAY;
  5764. econf --localstatedir="${EPREFIX}/var" --with-distro=gentoo --disable-python-dbus --disable-pygtk --disable-xmltoman --disable-monodoc --enable-glib --enable-gobject $(use_enable test tests) $(use_enable autoipd) $(use_enable mdnsresponder-compat compat-libdns_sd) $(use_enable howl-compat compat-howl) $(use_enable doc doxygen-doc) $(use_enable mono) $(use_enable dbus) $(use_enable python) $(use_enable gtk) $(use_enable gtk3) $(use_enable introspection) $(use_enable utils gtk-utils) --disable-qt3 $(use_enable qt4) $(use_enable gdbm) ${myconf}
  5765. }
  5766. src_install ()
  5767. {
  5768. emake install py_compile=true DESTDIR="${D}" || die "make install failed";
  5769. use bookmarks && use python && use dbus && use gtk || rm -f "${ED}"/usr/bin/avahi-bookmarks;
  5770. use howl-compat && ln -s avahi-compat-howl.pc "${ED}"/usr/$(get_libdir)/pkgconfig/howl.pc;
  5771. use mdnsresponder-compat && ln -s avahi-compat-libdns_sd/dns_sd.h "${ED}"/usr/include/dns_sd.h;
  5772. if use autoipd; then
  5773. insinto /$(get_libdir)/rcscripts/net;
  5774. doins "${FILESDIR}"/autoipd.sh || die;
  5775. insinto /$(get_libdir)/rc/net;
  5776. newins "${FILESDIR}"/autoipd-openrc.sh autoipd.sh || die;
  5777. fi;
  5778. dodoc docs/{AUTHORS,NEWS,README,TODO} || die;
  5779. if use doc; then
  5780. dohtml -r doxygen/html/. || die;
  5781. insinto /usr/share/devhelp/books/avahi;
  5782. doins avahi.devhelp || die;
  5783. fi;
  5784. if use python && use gtk && use dbus; then
  5785. python_convert_shebangs 2 "${ED}usr/bin/avahi-discover";
  5786. fi;
  5787. find "${D}" -name '*.la' -exec rm -f {} + || die
  5788. }
  5789. src_prepare ()
  5790. {
  5791. if use ipv6; then
  5792. sed -i -e s/use-ipv6=no/use-ipv6=yes/ avahi-daemon/avahi-daemon.conf || die;
  5793. fi;
  5794. sed -i -e "s:\\.\\./\\.\\./\\.\\./doc/avahi-docs/html/:../../../doc/${PF}/html/:" doxygen_to_devhelp.xsl || die;
  5795. epatch "${FILESDIR}/${PN}-0.6.30-optional-gtk-utils.patch";
  5796. epatch "${FILESDIR}/${PN}-0.6.x-openrc-0.9.x-init-scripts-fixes.patch";
  5797. sed -i -e 's:-D[A-Z_]*DISABLE_DEPRECATED=1::g' avahi-ui/Makefile.am || die;
  5798. eautoreconf
  5799. }
  5800. src_test ()
  5801. {
  5802. _eapi0_src_test "$@"
  5803. }
  5804. src_unpack ()
  5805. {
  5806. _eapi0_src_unpack "$@"
  5807. }
  5808. strip-flags ()
  5809. {
  5810. local x y flag NEW_CFLAGS NEW_CXXFLAGS NEW_FFLAGS NEW_FCFLAGS;
  5811. setup-allowed-flags;
  5812. local NEW_CFLAGS="";
  5813. local NEW_CXXFLAGS="";
  5814. local NEW_FFLAGS="";
  5815. local NEW_FCFLAGS="";
  5816. set -f;
  5817. for x in ${CFLAGS};
  5818. do
  5819. for y in ${ALLOWED_FLAGS};
  5820. do
  5821. flag=${x%%=*};
  5822. if [ "${flag%%${y}}" = "" ]; then
  5823. NEW_CFLAGS="${NEW_CFLAGS} ${x}";
  5824. break;
  5825. fi;
  5826. done;
  5827. done;
  5828. for x in ${CXXFLAGS};
  5829. do
  5830. for y in ${ALLOWED_FLAGS};
  5831. do
  5832. flag=${x%%=*};
  5833. if [ "${flag%%${y}}" = "" ]; then
  5834. NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}";
  5835. break;
  5836. fi;
  5837. done;
  5838. done;
  5839. for x in ${FFLAGS};
  5840. do
  5841. for y in ${ALLOWED_FLAGS};
  5842. do
  5843. flag=${x%%=*};
  5844. if [ "${flag%%${y}}" = "" ]; then
  5845. NEW_FFLAGS="${NEW_FFLAGS} ${x}";
  5846. break;
  5847. fi;
  5848. done;
  5849. done;
  5850. for x in ${FCFLAGS};
  5851. do
  5852. for y in ${ALLOWED_FLAGS};
  5853. do
  5854. flag=${x%%=*};
  5855. if [ "${flag%%${y}}" = "" ]; then
  5856. NEW_FCFLAGS="${NEW_FCFLAGS} ${x}";
  5857. break;
  5858. fi;
  5859. done;
  5860. done;
  5861. if [ "${CFLAGS/-O}" != "${CFLAGS}" -a "${NEW_CFLAGS/-O}" = "${NEW_CFLAGS}" ]; then
  5862. NEW_CFLAGS="${NEW_CFLAGS} -O2";
  5863. fi;
  5864. if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then
  5865. NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2";
  5866. fi;
  5867. if [ "${FFLAGS/-O}" != "${FFLAGS}" -a "${NEW_FFLAGS/-O}" = "${NEW_FFLAGS}" ]; then
  5868. NEW_FFLAGS="${NEW_FFLAGS} -O2";
  5869. fi;
  5870. if [ "${FCFLAGS/-O}" != "${FCFLAGS}" -a "${NEW_FCFLAGS/-O}" = "${NEW_FCFLAGS}" ]; then
  5871. NEW_FCFLAGS="${NEW_FCFLAGS} -O2";
  5872. fi;
  5873. set +f;
  5874. export CFLAGS="${NEW_CFLAGS}";
  5875. export CXXFLAGS="${NEW_CXXFLAGS}";
  5876. export FFLAGS="${NEW_FFLAGS}";
  5877. export FCFLAGS="${NEW_FCFLAGS}";
  5878. return 0
  5879. }
  5880. strip-linguas ()
  5881. {
  5882. local ls newls nols;
  5883. if [[ $1 == "-i" ]] || [[ $1 == "-u" ]]; then
  5884. local op=$1;
  5885. shift;
  5886. ls=$(find "$1" -name '*.po' -exec basename {} .po ';');
  5887. shift;
  5888. local d f;
  5889. for d in "$@";
  5890. do
  5891. if [[ ${op} == "-u" ]]; then
  5892. newls=${ls};
  5893. else
  5894. newls="";
  5895. fi;
  5896. for f in $(find "$d" -name '*.po' -exec basename {} .po ';');
  5897. do
  5898. if [[ ${op} == "-i" ]]; then
  5899. has ${f} ${ls} && newls="${newls} ${f}";
  5900. else
  5901. has ${f} ${ls} || newls="${newls} ${f}";
  5902. fi;
  5903. done;
  5904. ls=${newls};
  5905. done;
  5906. else
  5907. ls="$@";
  5908. fi;
  5909. nols="";
  5910. newls="";
  5911. for f in ${LINGUAS};
  5912. do
  5913. if has ${f} ${ls}; then
  5914. newls="${newls} ${f}";
  5915. else
  5916. nols="${nols} ${f}";
  5917. fi;
  5918. done;
  5919. [[ -n ${nols} ]] && ewarn "Sorry, but ${PN} does not support the LINGUAS:" ${nols};
  5920. export LINGUAS=${newls:1}
  5921. }
  5922. strip-unsupported-flags ()
  5923. {
  5924. export CFLAGS=$(test-flags-CC ${CFLAGS});
  5925. export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS});
  5926. export FFLAGS=$(test-flags-F77 ${FFLAGS});
  5927. export FCFLAGS=$(test-flags-FC ${FCFLAGS})
  5928. }
  5929. tc-arch ()
  5930. {
  5931. tc-ninja_magic_to_arch portage "$@"
  5932. }
  5933. tc-arch-kernel ()
  5934. {
  5935. tc-ninja_magic_to_arch kern "$@"
  5936. }
  5937. tc-endian ()
  5938. {
  5939. local host=$1;
  5940. [[ -z ${host} ]] && host=${CTARGET:-${CHOST}};
  5941. host=${host%%-*};
  5942. case ${host} in
  5943. alpha*)
  5944. echo big
  5945. ;;
  5946. arm*b*)
  5947. echo big
  5948. ;;
  5949. arm*)
  5950. echo little
  5951. ;;
  5952. cris*)
  5953. echo little
  5954. ;;
  5955. hppa*)
  5956. echo big
  5957. ;;
  5958. i?86*)
  5959. echo little
  5960. ;;
  5961. ia64*)
  5962. echo little
  5963. ;;
  5964. m68*)
  5965. echo big
  5966. ;;
  5967. mips*l*)
  5968. echo little
  5969. ;;
  5970. mips*)
  5971. echo big
  5972. ;;
  5973. powerpc*)
  5974. echo big
  5975. ;;
  5976. s390*)
  5977. echo big
  5978. ;;
  5979. sh*b*)
  5980. echo big
  5981. ;;
  5982. sh*)
  5983. echo little
  5984. ;;
  5985. sparc*)
  5986. echo big
  5987. ;;
  5988. x86_64*)
  5989. echo little
  5990. ;;
  5991. *)
  5992. echo wtf
  5993. ;;
  5994. esac
  5995. }
  5996. tc-env_build ()
  5997. {
  5998. 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) "$@"
  5999. }
  6000. tc-export ()
  6001. {
  6002. local var;
  6003. for var in "$@";
  6004. do
  6005. [[ $(type -t tc-get${var}) != "function" ]] && die "tc-export: invalid export variable '${var}'";
  6006. eval tc-get${var} > /dev/null;
  6007. done
  6008. }
  6009. tc-getAR ()
  6010. {
  6011. tc-getPROG AR ar "$@"
  6012. }
  6013. tc-getAS ()
  6014. {
  6015. tc-getPROG AS as "$@"
  6016. }
  6017. tc-getBUILD_AR ()
  6018. {
  6019. tc-getBUILD_PROG AR ar "$@"
  6020. }
  6021. tc-getBUILD_AS ()
  6022. {
  6023. tc-getBUILD_PROG AS as "$@"
  6024. }
  6025. tc-getBUILD_CC ()
  6026. {
  6027. tc-getBUILD_PROG CC gcc "$@"
  6028. }
  6029. tc-getBUILD_CPP ()
  6030. {
  6031. tc-getBUILD_PROG CPP cpp "$@"
  6032. }
  6033. tc-getBUILD_CXX ()
  6034. {
  6035. tc-getBUILD_PROG CXX g++ "$@"
  6036. }
  6037. tc-getBUILD_LD ()
  6038. {
  6039. tc-getBUILD_PROG LD ld "$@"
  6040. }
  6041. tc-getBUILD_NM ()
  6042. {
  6043. tc-getBUILD_PROG NM nm "$@"
  6044. }
  6045. tc-getBUILD_OBJCOPY ()
  6046. {
  6047. tc-getBUILD_PROG OBJCOPY objcopy "$@"
  6048. }
  6049. tc-getBUILD_PKG_CONFIG ()
  6050. {
  6051. tc-getBUILD_PROG PKG_CONFIG pkg-config "$@"
  6052. }
  6053. tc-getBUILD_PROG ()
  6054. {
  6055. _tc-getPROG CBUILD "BUILD_$1 $1_FOR_BUILD HOST$1" "${@:2}"
  6056. }
  6057. tc-getBUILD_RANLIB ()
  6058. {
  6059. tc-getBUILD_PROG RANLIB ranlib "$@"
  6060. }
  6061. tc-getBUILD_STRIP ()
  6062. {
  6063. tc-getBUILD_PROG STRIP strip "$@"
  6064. }
  6065. tc-getCC ()
  6066. {
  6067. tc-getPROG CC gcc "$@"
  6068. }
  6069. tc-getCPP ()
  6070. {
  6071. tc-getPROG CPP cpp "$@"
  6072. }
  6073. tc-getCXX ()
  6074. {
  6075. tc-getPROG CXX g++ "$@"
  6076. }
  6077. tc-getDLLWRAP ()
  6078. {
  6079. tc-getPROG DLLWRAP dllwrap "$@"
  6080. }
  6081. tc-getF77 ()
  6082. {
  6083. tc-getPROG F77 gfortran "$@"
  6084. }
  6085. tc-getFC ()
  6086. {
  6087. tc-getPROG FC gfortran "$@"
  6088. }
  6089. tc-getGCJ ()
  6090. {
  6091. tc-getPROG GCJ gcj "$@"
  6092. }
  6093. tc-getLD ()
  6094. {
  6095. tc-getPROG LD ld "$@"
  6096. }
  6097. tc-getNM ()
  6098. {
  6099. tc-getPROG NM nm "$@"
  6100. }
  6101. tc-getOBJCOPY ()
  6102. {
  6103. tc-getPROG OBJCOPY objcopy "$@"
  6104. }
  6105. tc-getPKG_CONFIG ()
  6106. {
  6107. tc-getPROG PKG_CONFIG pkg-config "$@"
  6108. }
  6109. tc-getPROG ()
  6110. {
  6111. _tc-getPROG CHOST "$@"
  6112. }
  6113. tc-getRANLIB ()
  6114. {
  6115. tc-getPROG RANLIB ranlib "$@"
  6116. }
  6117. tc-getRC ()
  6118. {
  6119. tc-getPROG RC windres "$@"
  6120. }
  6121. tc-getSTRIP ()
  6122. {
  6123. tc-getPROG STRIP strip "$@"
  6124. }
  6125. tc-has-openmp ()
  6126. {
  6127. local base="${T}/test-tc-openmp";
  6128. cat > "${base}.c" <<-EOF
  6129. #include <omp.h>
  6130. int main() {
  6131. int nthreads, tid, ret = 0;
  6132. #pragma omp parallel private(nthreads, tid)
  6133. {
  6134. tid = omp_get_thread_num();
  6135. nthreads = omp_get_num_threads(); ret += tid + nthreads;
  6136. }
  6137. return ret;
  6138. }
  6139. EOF
  6140.  
  6141. $(tc-getCC "$@") -fopenmp "${base}.c" -o "${base}" &>/dev/null;
  6142. local ret=$?;
  6143. rm -f "${base}"*;
  6144. return ${ret}
  6145. }
  6146. tc-has-tls ()
  6147. {
  6148. local base="${T}/test-tc-tls";
  6149. cat > "${base}.c" <<-EOF
  6150. int foo(int *i) {
  6151. static __thread int j = 0;
  6152. return *i ? j : *i;
  6153. }
  6154. EOF
  6155.  
  6156. local flags;
  6157. case $1 in
  6158. -s)
  6159. flags="-S"
  6160. ;;
  6161. -c)
  6162. flags="-c"
  6163. ;;
  6164. -l)
  6165.  
  6166. ;;
  6167. -*)
  6168. die "Usage: tc-has-tls [-c|-l] [toolchain prefix]"
  6169. ;;
  6170. esac;
  6171. : ${flags:=-fPIC -shared -Wl,-z,defs};
  6172. [[ $1 == -* ]] && shift;
  6173. $(tc-getCC "$@") ${flags} "${base}.c" -o "${base}" &>/dev/null;
  6174. local ret=$?;
  6175. rm -f "${base}"*;
  6176. return ${ret}
  6177. }
  6178. tc-is-cross-compiler ()
  6179. {
  6180. return $([[ ${CBUILD:-${CHOST}} != ${CHOST} ]])
  6181. }
  6182. tc-is-hardfloat ()
  6183. {
  6184. [[ ${CTARGET//_/-} == *-hardfloat-* ]] && echo "yes" || echo "no"
  6185. }
  6186. tc-is-softfloat ()
  6187. {
  6188. case ${CTARGET} in
  6189. bfin* | h8300*)
  6190. echo "only"
  6191. ;;
  6192. *)
  6193. [[ ${CTARGET//_/-} == *-softfloat-* ]] && echo "yes" || echo "no"
  6194. ;;
  6195. esac
  6196. }
  6197. tc-is-static-only ()
  6198. {
  6199. local host=${CTARGET:-${CHOST}};
  6200. return $([[ ${host} == *-mint* ]])
  6201. }
  6202. tc-ninja_magic_to_arch ()
  6203. {
  6204. function ninj ()
  6205. {
  6206. [[ ${type} == "kern" ]] && echo $1 || echo $2
  6207. };
  6208. local type=$1;
  6209. local host=$2;
  6210. [[ -z ${host} ]] && host=${CTARGET:-${CHOST}};
  6211. case ${host} in
  6212. alpha*)
  6213. echo alpha
  6214. ;;
  6215. arm*)
  6216. echo arm
  6217. ;;
  6218. avr*)
  6219. ninj avr32 avr
  6220. ;;
  6221. bfin*)
  6222. ninj blackfin bfin
  6223. ;;
  6224. cris*)
  6225. echo cris
  6226. ;;
  6227. hppa*)
  6228. ninj parisc hppa
  6229. ;;
  6230. i?86*)
  6231. if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -lt $(KV_to_int 2.6.24) || ${host} == *freebsd* ]]; then
  6232. echo i386;
  6233. else
  6234. echo x86;
  6235. fi
  6236. ;;
  6237. ia64*)
  6238. echo ia64
  6239. ;;
  6240. m68*)
  6241. echo m68k
  6242. ;;
  6243. mips*)
  6244. echo mips
  6245. ;;
  6246. nios2*)
  6247. echo nios2
  6248. ;;
  6249. nios*)
  6250. echo nios
  6251. ;;
  6252. powerpc*)
  6253. if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]]; then
  6254. echo powerpc;
  6255. else
  6256. if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -eq $(KV_to_int 2.6.15) ]]; then
  6257. if [[ ${host} == powerpc64* ]] || [[ ${PROFILE_ARCH} == "ppc64" ]]; then
  6258. echo powerpc;
  6259. else
  6260. echo ppc;
  6261. fi;
  6262. else
  6263. if [[ ${host} == powerpc64* ]]; then
  6264. echo ppc64;
  6265. else
  6266. if [[ ${PROFILE_ARCH} == "ppc64" ]]; then
  6267. ninj ppc64 ppc;
  6268. else
  6269. echo ppc;
  6270. fi;
  6271. fi;
  6272. fi;
  6273. fi
  6274. ;;
  6275. s390*)
  6276. echo s390
  6277. ;;
  6278. sh64*)
  6279. ninj sh64 sh
  6280. ;;
  6281. sh*)
  6282. echo sh
  6283. ;;
  6284. sparc64*)
  6285. ninj sparc64 sparc
  6286. ;;
  6287. sparc*)
  6288. [[ ${PROFILE_ARCH} == "sparc64" ]] && ninj sparc64 sparc || echo sparc
  6289. ;;
  6290. vax*)
  6291. echo vax
  6292. ;;
  6293. x86_64*freebsd*)
  6294. echo amd64
  6295. ;;
  6296. x86_64*)
  6297. if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.24) ]]; then
  6298. echo x86;
  6299. else
  6300. ninj x86_64 amd64;
  6301. fi
  6302. ;;
  6303. *)
  6304. echo unknown
  6305. ;;
  6306. esac
  6307. }
  6308. test-flag-CC ()
  6309. {
  6310. test-flag-PROG "CC" "$1"
  6311. }
  6312. test-flag-CXX ()
  6313. {
  6314. test-flag-PROG "CXX" "$1"
  6315. }
  6316. test-flag-F77 ()
  6317. {
  6318. test-flag-PROG "F77" "$1"
  6319. }
  6320. test-flag-FC ()
  6321. {
  6322. test-flag-PROG "FC" "$1"
  6323. }
  6324. test-flag-PROG ()
  6325. {
  6326. local comp=$1;
  6327. local flags="$2";
  6328. [[ -z ${comp} || -z ${flags} ]] && return 1;
  6329. local PROG=$(tc-get${comp});
  6330. ${PROG} ${flags} -c -o /dev/null -xc /dev/null > /dev/null 2>&1
  6331. }
  6332. test-flags ()
  6333. {
  6334. test-flags-CC "$@"
  6335. }
  6336. test-flags-CC ()
  6337. {
  6338. test-flags-PROG "CC" "$@"
  6339. }
  6340. test-flags-CXX ()
  6341. {
  6342. test-flags-PROG "CXX" "$@"
  6343. }
  6344. test-flags-F77 ()
  6345. {
  6346. test-flags-PROG "F77" "$@"
  6347. }
  6348. test-flags-FC ()
  6349. {
  6350. test-flags-PROG "FC" "$@"
  6351. }
  6352. test-flags-PROG ()
  6353. {
  6354. local comp=$1;
  6355. local flags;
  6356. local x;
  6357. shift;
  6358. [[ -z ${comp} ]] && return 1;
  6359. for x in "$@";
  6360. do
  6361. test-flag-${comp} "${x}" && flags="${flags}${flags:+ }${x}";
  6362. done;
  6363. echo "${flags}";
  6364. [[ -n ${flags} ]]
  6365. }
  6366. test_flag ()
  6367. {
  6368. die "$0: deprecated, please use test-flags()!"
  6369. }
  6370. test_version_info ()
  6371. {
  6372. if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then
  6373. return 0;
  6374. else
  6375. return 1;
  6376. fi
  6377. }
  6378. treecopy ()
  6379. {
  6380. dest=${!#};
  6381. files_count=$#;
  6382. while (( $# > 1 )); do
  6383. dirstruct=$(dirname "$1");
  6384. mkdir -p "${dest}/${dirstruct}";
  6385. cp -pPR "$1" "${dest}/${dirstruct}";
  6386. shift;
  6387. done
  6388. }
  6389. uclibctoolize ()
  6390. {
  6391. die "Use elibtoolize"
  6392. }
  6393. unpack_makeself ()
  6394. {
  6395. local src_input=${1:-${A}};
  6396. local src=$(find_unpackable_file "${src_input}");
  6397. local skip=$2;
  6398. local exe=$3;
  6399. [[ -z ${src} ]] && die "Could not locate source for '${src_input}'";
  6400. local shrtsrc=$(basename "${src}");
  6401. echo ">>> Unpacking ${shrtsrc} to ${PWD}";
  6402. if [[ -z ${skip} ]]; then
  6403. local ver=$(grep -m1 -a '#.*Makeself' "${src}" | awk '{print $NF}');
  6404. local skip=0;
  6405. exe=tail;
  6406. case ${ver} in
  6407. 1.5.* | 1.6.0-nv)
  6408. skip=$(grep -a ^skip= "${src}" | cut -d= -f2)
  6409. ;;
  6410. 2.0 | 2.0.1)
  6411. skip=$(grep -a ^' 'tail "${src}" | awk '{print $2}' | cut -b2-)
  6412. ;;
  6413. 2.1.1)
  6414. skip=$(grep -a ^offset= "${src}" | awk '{print $2}' | cut -b2-);
  6415. (( skip++ ))
  6416. ;;
  6417. 2.1.2)
  6418. skip=$(grep -a ^offset= "${src}" | awk '{print $3}' | head -n 1);
  6419. (( skip++ ))
  6420. ;;
  6421. 2.1.3)
  6422. skip=`grep -a ^offset= "${src}" | awk '{print $3}'`;
  6423. (( skip++ ))
  6424. ;;
  6425. 2.1.4 | 2.1.5)
  6426. skip=$(grep -a offset=.*head.*wc "${src}" | awk '{print $3}' | head -n 1);
  6427. skip=$(head -n ${skip} "${src}" | wc -c);
  6428. exe="dd"
  6429. ;;
  6430. *)
  6431. eerror "I'm sorry, but I was unable to support the Makeself file.";
  6432. eerror "The version I detected was '${ver}'.";
  6433. eerror "Please file a bug about the file ${shrtsrc} at";
  6434. eerror "http://bugs.gentoo.org/ so that support can be added.";
  6435. die "makeself version '${ver}' not supported"
  6436. ;;
  6437. esac;
  6438. debug-print "Detected Makeself version ${ver} ... using ${skip} as offset";
  6439. fi;
  6440. case ${exe} in
  6441. tail)
  6442. exe="tail -n +${skip} '${src}'"
  6443. ;;
  6444. dd)
  6445. exe="dd ibs=${skip} skip=1 if='${src}'"
  6446. ;;
  6447. *)
  6448. die "makeself cant handle exe '${exe}'"
  6449. ;;
  6450. esac;
  6451. local filetype tmpfile=$(emktemp);
  6452. eval ${exe} 2> /dev/null | head -c 512 > "${tmpfile}";
  6453. filetype=$(file -b "${tmpfile}") || die;
  6454. case ${filetype} in
  6455. *tar\ archive*)
  6456. eval ${exe} | tar --no-same-owner -xf -
  6457. ;;
  6458. bzip2*)
  6459. eval ${exe} | bzip2 -dc | tar --no-same-owner -xf -
  6460. ;;
  6461. gzip*)
  6462. eval ${exe} | tar --no-same-owner -xzf -
  6463. ;;
  6464. compress*)
  6465. eval ${exe} | gunzip | tar --no-same-owner -xf -
  6466. ;;
  6467. *)
  6468. eerror "Unknown filetype \"${filetype}\" ?";
  6469. false
  6470. ;;
  6471. esac;
  6472. assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})"
  6473. }
  6474. unpack_pdv ()
  6475. {
  6476. local src=$(find_unpackable_file "$1");
  6477. local sizeoff_t=$2;
  6478. [[ -z ${src} ]] && die "Could not locate source for '$1'";
  6479. [[ -z ${sizeoff_t} ]] && die "No idea what off_t size was used for this pdv :(";
  6480. local shrtsrc=$(basename "${src}");
  6481. echo ">>> Unpacking ${shrtsrc} to ${PWD}";
  6482. local metaskip=$(tail -c ${sizeoff_t} "${src}" | hexdump -e \"%i\");
  6483. local tailskip=$(tail -c $((${sizeoff_t}*2)) "${src}" | head -c ${sizeoff_t} | hexdump -e \"%i\");
  6484. local metafile=$(emktemp);
  6485. tail -c +$((${metaskip}+1)) "${src}" > "${metafile}";
  6486. local datafile=$(tail -c +$((${metaskip}+1)) "${src}" | strings | head -n 1);
  6487. datafile=$(basename "${datafile}");
  6488. local tmpfile=$(emktemp);
  6489. tail -c +$((${tailskip}+1)) ${src} 2> /dev/null | head -c 512 > ${tmpfile};
  6490. local iscompressed=$(file -b "${tmpfile}");
  6491. if [[ ${iscompressed:0:8} == "compress" ]]; then
  6492. iscompressed=1;
  6493. mv ${tmpfile}{,.Z};
  6494. gunzip ${tmpfile};
  6495. else
  6496. iscompressed=0;
  6497. fi;
  6498. local istar=$(file -b "${tmpfile}");
  6499. if [[ ${istar:0:9} == "POSIX tar" ]]; then
  6500. istar=1;
  6501. else
  6502. istar=0;
  6503. fi;
  6504. if [ ${iscompressed} -eq 1 ]; then
  6505. if [ ${istar} -eq 1 ]; then
  6506. tail -c +$((${tailskip}+1)) ${src} 2> /dev/null | head -c $((${metaskip}-${tailskip})) | tar -xzf -;
  6507. else
  6508. tail -c +$((${tailskip}+1)) ${src} 2> /dev/null | head -c $((${metaskip}-${tailskip})) | gzip -dc > ${datafile};
  6509. fi;
  6510. else
  6511. if [ ${istar} -eq 1 ]; then
  6512. tail -c +$((${tailskip}+1)) ${src} 2> /dev/null | head -c $((${metaskip}-${tailskip})) | tar --no-same-owner -xf -;
  6513. else
  6514. tail -c +$((${tailskip}+1)) ${src} 2> /dev/null | head -c $((${metaskip}-${tailskip})) > ${datafile};
  6515. fi;
  6516. fi;
  6517. true
  6518. }
  6519. use_if_iuse ()
  6520. {
  6521. in_iuse $1 || return 1;
  6522. use $1
  6523. }
  6524. usex ()
  6525. {
  6526. use "$1" && echo "${2-yes}$4" || echo "${3-no}$5"
  6527. }
  6528. validate_desktop_entries ()
  6529. {
  6530. if [[ -x /usr/bin/desktop-file-validate ]]; then
  6531. einfo "Checking desktop entry validity";
  6532. local directories="";
  6533. for d in /usr/share/applications $@;
  6534. do
  6535. [[ -d ${D}${d} ]] && directories="${directories} ${D}${d}";
  6536. done;
  6537. if [[ -n ${directories} ]]; then
  6538. for FILE in $(find ${directories} -name "*\.desktop" -not -path '*.hidden*' | sort -u 2>/dev/null);
  6539. do
  6540. local temp=$(desktop-file-validate ${FILE} | grep -v "warning:" | sed -e "s|error: ||" -e "s|${FILE}:|--|g" );
  6541. [[ -n $temp ]] && elog ${temp/--/${FILE/${D}/}:};
  6542. done;
  6543. fi;
  6544. echo "";
  6545. else
  6546. einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo.";
  6547. fi
  6548. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement