spacepaste

  1.  
  2. declare -x ABI="arm64"
  3. declare -x ABI_MIPS=""
  4. declare -x ABI_PPC=""
  5. declare -x ABI_S390=""
  6. declare -x ABI_X86=""
  7. declare -x ADAFLAGS=""
  8. declare -x ALSA_CARDS=""
  9. declare -x APACHE2_MODULES=""
  10. declare -x APACHE2_MPMS=""
  11. declare -x ARCH="arm64"
  12. declare BDEPEND=""
  13. declare -- BINPATH="/usr/x86_64-pc-linux-gnu/binutils-bin/2.31.1"
  14. declare -x BOOTSTRAP_USE="cxx unicode internal-glib split-usr python_targets_python3_6 python_targets_python2_7 multilib"
  15. declare -x CALLIGRA_EXPERIMENTAL_FEATURES=""
  16. declare -x CALLIGRA_FEATURES=""
  17. declare -x CAMERAS=""
  18. declare -x CBUILD="aarch64-RPi3B-linux-musl"
  19. declare -x CCASFLAGS=""
  20. declare -x CFLAGS="-march=armv8-a+crc -mtune=cortex-a53 -O2 -pipe"
  21. declare -x CFLAGS_default
  22. declare -x CHOST="x86_64-pc-linux-gnu"
  23. declare -x CHOST_arm64="aarch64-unknown-linux-gnu"
  24. declare -x CHOST_default="x86_64-pc-linux-gnu"
  25. declare -x COLLECTD_PLUGINS=""
  26. declare -x CPPFLAGS=""
  27. declare -x CPU_FLAGS_ARM=""
  28. declare -x CPU_FLAGS_X86=""
  29. declare -x CTARGET="x86_64-pc-linux-gnu"
  30. declare -x CTARGET_default="x86_64-pc-linux-gnu"
  31. declare -x CURL_SSL=""
  32. declare -x CXXFLAGS="-march=armv8-a+crc -mtune=cortex-a53 -O2 -pipe"
  33. declare -- DATAPATH="/usr/share/binutils-data/x86_64-pc-linux-gnu/2.31.1"
  34. declare -x DCC_EMAILLOG_WHOM_TO_BLAME=""
  35. declare -x DEFAULT_ABI="arm64"
  36. declare -x DEFINED_PHASES=" compile configure install postinst postrm prepare test unpack"
  37. declare DEPEND="
  38. >=sys-devel/binutils-config-3
  39. sys-libs/zlib
  40. doc? ( sys-apps/texinfo )
  41. test? ( dev-util/dejagnu )
  42. nls? ( sys-devel/gettext )
  43. sys-devel/flex
  44. virtual/yacc
  45. >=app-portage/elt-patches-20170815 sys-devel/gnuconfig"
  46. declare DESCRIPTION="Tools necessary to build programs"
  47. declare -x DESTTREE="/usr"
  48. declare -x DIROPTIONS="-m0755"
  49. declare -x EAPI="6"
  50. declare -x ELIBC="glibc"
  51. declare -x ENLIGHTENMENT_MODULES=""
  52. declare -x ENV_UNSET="DBUS_SESSION_BUS_ADDRESS DISPLAY PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
  53. declare -- EPATCH_COMMON_OPTS="-g0 -E --no-backup-if-mismatch"
  54. declare -- EPATCH_EXCLUDE=""
  55. declare -- EPATCH_FORCE="no"
  56. declare -- EPATCH_MULTI_MSG="Applying various patches (bugfixes/updates) ..."
  57. declare -- EPATCH_OPTS=""
  58. declare -- EPATCH_SINGLE_MSG=""
  59. declare -- EPATCH_SOURCE="/var/tmp/portage/sys-devel/binutils-2.31.1-r1/work/patch"
  60. declare -- EPATCH_SUFFIX="patch.bz2"
  61. declare -x EXEOPTIONS="-m0755"
  62. declare -x FCFLAGS="-O2"
  63. declare -x FETCHCOMMAND_SSH="bash -c \"x=\\\${2#ssh://} ; host=\\\${x%%/*} ; port=\\\${host##*:} ; host=\\\${host%:*} ; [[ \\\${host} = \\\${port} ]] && port= ; exec rsync --rsh=\\\"ssh \\\${port:+-p\\\${port}} \\\${3}\\\" -avP \\\"\\\${host}:/\\\${x#*/}\\\" \\\"\\\$1\\\"\" rsync \"\${DISTDIR}/\${FILE}\" \"\${URI}\" \"\${PORTAGE_SSH_OPTS}\""
  64. declare -x FFLAGS="-O2"
  65. declare -x FFTOOLS=""
  66. declare -x GCC_SPECS=""
  67. declare -x GPSD_PROTOCOLS=""
  68. declare -x GRUB_PLATFORMS=""
  69. declare HDEPEND=""
  70. declare HOMEPAGE="https://sourceware.org/binutils/"
  71. declare -- INCPATH="/usr/lib64/binutils/x86_64-pc-linux-gnu/2.31.1/include"
  72. declare -x INHERITED=" desktop epatch estack toolchain-funcs multilib ltprune preserve-libs vcs-clean eutils libtool flag-o-matic gnuconfig versionator"
  73. declare -x INPUT_DEVICES=""
  74. declare -x INSDESTTREE=""
  75. declare -x INSOPTIONS="-m0644"
  76. declare IUSE="+cxx doc multitarget +nls static-libs test "
  77. declare -x IUSE_EFFECTIVE="alpha amd64 amd64-fbsd amd64-linux arm arm64 cxx doc elibc_AIX elibc_Cygwin elibc_Darwin elibc_DragonFly elibc_FreeBSD elibc_HPUX elibc_Interix elibc_NetBSD elibc_OpenBSD elibc_SunOS elibc_Winnt elibc_bionic elibc_glibc elibc_mingw elibc_mintlib elibc_musl elibc_uclibc hppa ia64 kernel_AIX kernel_Darwin kernel_FreeBSD kernel_HPUX kernel_NetBSD kernel_OpenBSD kernel_SunOS kernel_Winnt kernel_freemint kernel_linux m68k m68k-mint mips multitarget nls ppc ppc-aix ppc-macos ppc64 ppc64-linux prefix prefix-chain prefix-guest s390 sh sparc sparc-solaris sparc64-solaris static-libs test userland_BSD userland_GNU x64-cygwin x64-macos x64-solaris x86 x86-cygwin x86-fbsd x86-linux x86-macos x86-solaris x86-winnt"
  78. declare -x IUSE_IMPLICIT="prefix prefix-chain prefix-guest"
  79. declare -x KERNEL="linux"
  80. declare -x KERNEL_ABI="arm64"
  81. declare -x KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-fbsd ~x86-fbsd"
  82. declare -x L10N=""
  83. declare -x LANG="en_US.utf8"
  84. declare -x LANGUAGE="en_US.utf8"
  85. declare -x LCD_DEVICES=""
  86. declare -x LC_ADDRESS="en_US.utf8"
  87. declare -x LC_COLLATE="C"
  88. declare -x LC_CTYPE="en_US.utf8"
  89. declare -x LC_IDENTIFICATION="en_US.utf8"
  90. declare -x LC_MEASUREMENT="en_US.utf8"
  91. declare -x LC_MESSAGES="en_US.utf8"
  92. declare -x LC_MONETARY="en_US.utf8"
  93. declare -x LC_NAME="en_US.utf8"
  94. declare -x LC_NUMERIC="en_US.utf8"
  95. declare -x LC_PAPER="en_US.utf8"
  96. declare -x LC_TELEPHONE="en_US.utf8"
  97. declare -x LC_TIME="en_US.utf8"
  98. declare -x LDFLAGS="-Wl,-O1 -Wl,--as-needed"
  99. declare -x LDFLAGS_default
  100. declare -x LIBDIR_arm64="lib64"
  101. declare -x LIBDIR_default="lib"
  102. declare -x LIBOPTIONS="-m0644"
  103. declare -- LIBPATH="/usr/lib64/binutils/x86_64-pc-linux-gnu/2.31.1"
  104. declare -x LIBREOFFICE_EXTENSIONS=""
  105. declare -x LICENSE="GPL-3+"
  106. declare -x LINGUAS=""
  107. declare -x LIRC_DEVICES=""
  108. declare -x LLVM_TARGETS=""
  109. declare -x MAKEOPTS="-j9 -l4"
  110. declare -x MANPAGER="manpager"
  111. declare -x MONKEYD_PLUGINS=""
  112. declare -x MULTILIB_ABIS="arm64"
  113. declare -x MULTILIB_STRICT_DENY="64-bit.*shared object"
  114. 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"
  115. declare -x MULTILIB_STRICT_EXEMPT="(perl5|gcc|gcc-lib|binutils|eclipse-3|debug|portage|udev|systemd|clang|python-exec|llvm)"
  116. declare -- MY_BUILDDIR="/var/tmp/portage/sys-devel/binutils-2.31.1-r1/work/build"
  117. declare -x NETBEANS="apisupport cnd groovy gsf harness ide identity j2ee java mobility nb php profiler soa visualweb webcommon websvccommon xml"
  118. declare -x NETBEANS_MODULES=""
  119. declare -x NGINX_MODULES_HTTP=""
  120. declare -x NGINX_MODULES_MAIL=""
  121. declare -x NGINX_MODULES_STREAM=""
  122. declare -x OFED_DRIVERS=""
  123. declare -x OFFICE_IMPLEMENTATION=""
  124. declare -x OPENMPI_FABRICS=""
  125. declare -x OPENMPI_OFED_FEATURES=""
  126. declare -x OPENMPI_RM=""
  127. declare -- PATCH_BINUTILS_VER="2.31.1"
  128. declare -- PATCH_DEV="slyfox"
  129. declare -- PATCH_VER="3"
  130. declare -x PATH="/usr/lib/portage/python3.6/ebuild-helpers/xattr:/usr/lib/portage/python3.6/ebuild-helpers:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin"
  131. declare PDEPEND=""
  132. declare -x PHP_TARGETS=""
  133. declare -x PKG_CONFIG_PATH="/usr/lib64/pkgconfig"
  134. declare -x PORTAGE_COMPRESSION_COMMAND="bzip2"
  135. declare -a PORTAGE_DOCOMPRESS=([0]="/usr/share/doc" [1]="/usr/share/info" [2]="/usr/share/man")
  136. declare -x PORTAGE_DOCOMPRESS_SIZE_LIMIT="128"
  137. declare -a PORTAGE_DOCOMPRESS_SKIP=([0]="/usr/share/doc/binutils-2.31.1-r1/html")
  138. declare -a PORTAGE_DOSTRIP=([0]="/")
  139. declare -a PORTAGE_DOSTRIP_SKIP=()
  140. declare -x POSTGRES_TARGETS=""
  141. declare -x PROFILE_ONLY_VARIABLES="ARCH ELIBC IUSE_IMPLICIT KERNEL USERLAND USE_EXPAND_IMPLICIT USE_EXPAND_UNPREFIXED USE_EXPAND_VALUES_ARCH USE_EXPAND_VALUES_ELIBC USE_EXPAND_VALUES_KERNEL USE_EXPAND_VALUES_USERLAND"
  142. declare -x PROPERTIES=""
  143. declare -x PYTHONDONTWRITEBYTECODE="1"
  144. declare -x PYTHON_SINGLE_TARGET=""
  145. declare -x PYTHON_TARGETS=""
  146. declare -x QEMU_SOFTMMU_TARGETS=""
  147. declare -x QEMU_USER_TARGETS=""
  148. declare RDEPEND="
  149. >=sys-devel/binutils-config-3
  150. sys-libs/zlib
  151. "
  152. declare REPOSITORY
  153. declare REQUIRED_USE=""
  154. declare -x RESTRICT=""
  155. declare -x RESUMECOMMAND_SSH="bash -c \"x=\\\${2#ssh://} ; host=\\\${x%%/*} ; port=\\\${host##*:} ; host=\\\${host%:*} ; [[ \\\${host} = \\\${port} ]] && port= ; exec rsync --rsh=\\\"ssh \\\${port:+-p\\\${port}} \\\${3}\\\" -avP \\\"\\\${host}:/\\\${x#*/}\\\" \\\"\\\$1\\\"\" rsync \"\${DISTDIR}/\${FILE}\" \"\${URI}\" \"\${PORTAGE_SSH_OPTS}\""
  156. declare -x ROS_MESSAGES=""
  157. declare -x RUBY_TARGETS=""
  158. declare -x S="/var/tmp/portage/sys-devel/binutils-2.31.1-r1/work/binutils-2.31.1"
  159. declare -x SANDBOX_DEBUG="0"
  160. declare -x SANDBOX_DENY=""
  161. declare -x SANDBOX_PREDICT="/var/tmp/portage/sys-devel/binutils-2.31.1-r1/homedir:/dev/crypto"
  162. declare -x SANDBOX_READ="/:/var/tmp"
  163. declare -x SANDBOX_VERBOSE="1"
  164. declare -x SANDBOX_WRITE=":/dev/console:/dev/fd:/dev/full:/dev/null:/dev/ptmx:/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/sys-devel/binutils-2.31.1-r1/homedir/.bash_history"
  165. declare -x SANE_BACKENDS=""
  166. declare -x SHELL="/bin/bash"
  167. declare -x SLOT="2.31"
  168. declare SRC_URI="mirror://gnu/binutils/binutils-2.31.1.tar.xz
  169. https://dev.gentoo.org/~slyfox/distfiles/binutils-2.31.1-patches-3.tar.xz"
  170. declare -- TOOLPATH="/usr/x86_64-pc-linux-gnu"
  171. declare -x TWISTED_DISABLE_WRITING_OF_PLUGIN_CACHE="1"
  172. declare -x UNCACHED_ERR_FD=""
  173. declare -x USE="arm64 cxx elibc_glibc kernel_linux nls userland_GNU"
  174. declare -x USERLAND="GNU"
  175. declare -x USE_EXPAND_IMPLICIT="ARCH ELIBC KERNEL USERLAND"
  176. declare -x USE_EXPAND_UNPREFIXED="ARCH"
  177. declare -x USE_EXPAND_VALUES_ARCH="alpha amd64 amd64-fbsd amd64-linux arm arm64 hppa ia64 m68k m68k-mint mips ppc ppc64 ppc64-linux ppc-aix ppc-macos s390 sh sparc sparc64-solaris sparc-solaris x64-cygwin x64-macos x64-solaris x86 x86-cygwin x86-fbsd x86-linux x86-macos x86-solaris x86-winnt"
  178. declare -x USE_EXPAND_VALUES_ELIBC="AIX bionic Cygwin Darwin DragonFly FreeBSD glibc HPUX Interix mingw mintlib musl NetBSD OpenBSD SunOS uclibc Winnt"
  179. declare -x USE_EXPAND_VALUES_KERNEL="AIX Darwin FreeBSD freemint HPUX linux NetBSD OpenBSD SunOS Winnt"
  180. declare -x USE_EXPAND_VALUES_USERLAND="BSD GNU"
  181. declare -x UWSGI_PLUGINS=""
  182. declare -x VIDEO_CARDS=""
  183. declare -x VOICEMAIL_STORAGE=""
  184. declare -x XFCE_PLUGINS=""
  185. declare -x XTABLES_ADDONS=""
  186. declare -- _DESKTOP_ECLASS="1"
  187. declare -- _EPATCH_ECLASS="1"
  188. declare -- _ESTACK_ECLASS="1"
  189. declare -- _EUTILS_ECLASS="1"
  190. declare -x _E_DOCDESTTREE_=""
  191. declare -x _E_EXEDESTTREE_=""
  192. declare -- _FLAG_O_MATIC_ECLASS="1"
  193. declare -- _LIBTOOL_ECLASS="1"
  194. declare -- _LTPRUNE_ECLASS="1"
  195. declare -- _MULTILIB_ECLASS="1"
  196. declare -- _PRESERVE_LIBS_ECLASS="1"
  197. declare -- _TOOLCHAIN_FUNCS_ECLASS="1"
  198. declare -- _VERSIONATOR_ECLASS="1"
  199. declare -- phase_func
  200. declare -- started_applying="1"
  201. __eapi6_src_install ()
  202. {
  203. if [[ -f Makefile || -f GNUmakefile || -f makefile ]]; then
  204. emake DESTDIR="${D}" install;
  205. fi;
  206. einstalldocs
  207. }
  208. __eapi6_src_prepare ()
  209. {
  210. if [[ $(declare -p PATCHES 2>/dev/null) == "declare -a"* ]]; then
  211. [[ ${#PATCHES[@]} -gt 0 ]] && eapply "${PATCHES[@]}";
  212. else
  213. if [[ -n ${PATCHES} ]]; then
  214. eapply ${PATCHES};
  215. fi;
  216. fi;
  217. eapply_user
  218. }
  219. _clang_fullversion ()
  220. {
  221. local ver="$1";
  222. shift;
  223. set -- $($(tc-getCPP "$@") -E -P - <<<"__clang_major__ __clang_minor__ __clang_patchlevel__");
  224. eval echo "$ver"
  225. }
  226. _eapply_patch ()
  227. {
  228. local f=${1};
  229. local prefix=${2};
  230. started_applying=1;
  231. ebegin "${prefix:-Applying }${f##*/}";
  232. ${patch_cmd} -p1 -f -s -g0 --no-backup-if-mismatch "${patch_options[@]}" < "${f}";
  233. failed=${?};
  234. if ! eend "${failed}"; then
  235. __helpers_die "patch -p1 ${patch_options[*]} failed with ${f}";
  236. fi
  237. }
  238. _filter-hardened ()
  239. {
  240. local f;
  241. for f in "$@";
  242. do
  243. case "${f}" in
  244. -fPIC | -fpic | -fPIE | -fpie | -Wl,pie | -pie)
  245. gcc-specs-pie || continue;
  246. if ! is-flagq -nopie && ! is-flagq -no-pie; then
  247. if test-flags -nopie > /dev/null; then
  248. append-flags -nopie;
  249. else
  250. append-flags -no-pie;
  251. fi;
  252. fi
  253. ;;
  254. -fstack-protector)
  255. gcc-specs-ssp || continue;
  256. is-flagq -fno-stack-protector || append-flags $(test-flags -fno-stack-protector)
  257. ;;
  258. -fstack-protector-all)
  259. gcc-specs-ssp-to-all || continue;
  260. is-flagq -fno-stack-protector-all || append-flags $(test-flags -fno-stack-protector-all)
  261. ;;
  262. -fno-strict-overflow)
  263. gcc-specs-nostrict || continue;
  264. is-flagq -fstrict-overflow || append-flags $(test-flags -fstrict-overflow)
  265. ;;
  266. esac;
  267. done
  268. }
  269. _filter-var ()
  270. {
  271. local f x var=$1 new=();
  272. shift;
  273. for f in ${!var};
  274. do
  275. for x in "$@";
  276. do
  277. [[ ${f} == ${x} ]] && continue 2;
  278. done;
  279. new+=("${f}");
  280. done;
  281. export ${var}="${new[*]}"
  282. }
  283. _gcc-install-dir ()
  284. {
  285. echo "$(LC_ALL=C $(tc-getCC) -print-search-dirs 2> /dev/null | awk '$1=="install:" {print $2}')"
  286. }
  287. _gcc-specs-directive_raw ()
  288. {
  289. local cc=$(tc-getCC);
  290. local specfiles=$(LC_ALL=C ${cc} -v 2>&1 | awk '$1=="Reading" {print $NF}');
  291. ${cc} -dumpspecs 2> /dev/null | cat - ${specfiles} | awk -v directive=$1 'BEGIN { pspec=""; spec=""; outside=1 }
  292. $1=="*"directive":" { pspec=spec; spec=""; outside=0; next }
  293. outside || NF==0 || ( substr($1,1,1)=="*" && substr($1,length($1),1)==":" ) { outside=1; next }
  294. spec=="" && substr($0,1,1)=="+" { spec=pspec " " substr($0,2); next }
  295. { spec=spec $0 }
  296. END { print spec }';
  297. return 0
  298. }
  299. _gcc-specs-exists ()
  300. {
  301. [[ -f $(_gcc-install-dir)/$1 ]]
  302. }
  303. _gcc_fullversion ()
  304. {
  305. local ver="$1";
  306. shift;
  307. set -- $($(tc-getCPP "$@") -E -P - <<<"__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__");
  308. eval echo "$ver"
  309. }
  310. _iconins ()
  311. {
  312. ( insopts -m 0644;
  313. local funcname=$1;
  314. shift;
  315. local size dir;
  316. local context=apps;
  317. local theme=hicolor;
  318. while [[ $# -gt 0 ]]; do
  319. case $1 in
  320. -s | --size)
  321. if [[ ${2%%x*}x${2%%x*} == "$2" ]]; then
  322. size=${2%%x*};
  323. else
  324. size=${2};
  325. fi;
  326. case ${size} in
  327. 16 | 22 | 24 | 32 | 36 | 48 | 64 | 72 | 96 | 128 | 192 | 256 | 512)
  328. size=${size}x${size}
  329. ;;
  330. scalable)
  331. ;;
  332. *)
  333. eerror "${size} is an unsupported icon size!";
  334. exit 1
  335. ;;
  336. esac;
  337. shift 2
  338. ;;
  339. -t | --theme)
  340. theme=${2};
  341. shift 2
  342. ;;
  343. -c | --context)
  344. context=${2};
  345. shift 2
  346. ;;
  347. *)
  348. if [[ -z ${size} ]]; then
  349. insinto /usr/share/pixmaps;
  350. else
  351. insinto /usr/share/icons/${theme}/${size}/${context};
  352. fi;
  353. if [[ ${funcname} == doicon ]]; then
  354. if [[ -f $1 ]]; then
  355. doins "${1}";
  356. else
  357. if [[ -d $1 ]]; then
  358. shopt -s nullglob;
  359. doins "${1}"/*.{png,svg};
  360. shopt -u nullglob;
  361. else
  362. eerror "${1} is not a valid file/directory!";
  363. exit 1;
  364. fi;
  365. fi;
  366. else
  367. break;
  368. fi;
  369. shift 1
  370. ;;
  371. esac;
  372. done;
  373. if [[ ${funcname} == newicon ]]; then
  374. newins "$@";
  375. fi ) || die
  376. }
  377. _is_flagq ()
  378. {
  379. local x var="$1[*]";
  380. for x in ${!var};
  381. do
  382. [[ ${x} == $2 ]] && return 0;
  383. done;
  384. return 1
  385. }
  386. _tc-getPROG ()
  387. {
  388. local tuple=$1;
  389. local v var vars=$2;
  390. local prog=($3);
  391. var=${vars%% *};
  392. for v in ${vars};
  393. do
  394. if [[ -n ${!v} ]]; then
  395. export ${var}="${!v}";
  396. echo "${!v}";
  397. return 0;
  398. fi;
  399. done;
  400. local search=;
  401. [[ -n $4 ]] && search=$(type -p $4-${prog[0]});
  402. [[ -z ${search} && -n ${!tuple} ]] && search=$(type -p ${!tuple}-${prog[0]});
  403. [[ -n ${search} ]] && prog[0]=${search##*/};
  404. export ${var}="${prog[*]}";
  405. echo "${!var}"
  406. }
  407. all-flag-vars ()
  408. {
  409. echo {ADA,C,CPP,CXX,CCAS,F,FC,LD}FLAGS
  410. }
  411. append-cflags ()
  412. {
  413. [[ $# -eq 0 ]] && return 0;
  414. export CFLAGS+=" $*";
  415. return 0
  416. }
  417. append-cppflags ()
  418. {
  419. [[ $# -eq 0 ]] && return 0;
  420. export CPPFLAGS+=" $*";
  421. return 0
  422. }
  423. append-cxxflags ()
  424. {
  425. [[ $# -eq 0 ]] && return 0;
  426. export CXXFLAGS+=" $*";
  427. return 0
  428. }
  429. append-fflags ()
  430. {
  431. [[ $# -eq 0 ]] && return 0;
  432. export FFLAGS+=" $*";
  433. export FCFLAGS+=" $*";
  434. return 0
  435. }
  436. append-flags ()
  437. {
  438. [[ $# -eq 0 ]] && return 0;
  439. case " $* " in
  440. *' '-[DIU]*)
  441. eqawarn 'please use append-cppflags for preprocessor flags'
  442. ;;
  443. *' '-L* | *' '-Wl,*)
  444. eqawarn 'please use append-ldflags for linker flags'
  445. ;;
  446. esac;
  447. append-cflags "$@";
  448. append-cxxflags "$@";
  449. append-fflags "$@";
  450. return 0
  451. }
  452. append-ldflags ()
  453. {
  454. [[ $# -eq 0 ]] && return 0;
  455. local flag;
  456. for flag in "$@";
  457. do
  458. [[ ${flag} == -l* ]] && eqawarn "Appending a library link instruction (${flag}); libraries to link to should not be passed through LDFLAGS";
  459. done;
  460. export LDFLAGS="${LDFLAGS} $*";
  461. return 0
  462. }
  463. append-lfs-flags ()
  464. {
  465. [[ $# -ne 0 ]] && die "append-lfs-flags takes no arguments";
  466. append-cppflags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
  467. }
  468. append-libs ()
  469. {
  470. [[ $# -eq 0 ]] && return 0;
  471. local flag;
  472. for flag in "$@";
  473. do
  474. if [[ -z "${flag// }" ]]; then
  475. eqawarn "Appending an empty argument to LIBS is invalid! Skipping.";
  476. continue;
  477. fi;
  478. case $flag in
  479. -[lL]*)
  480. export LIBS="${LIBS} ${flag}"
  481. ;;
  482. -*)
  483. eqawarn "Appending non-library to LIBS (${flag}); Other linker flags should be passed via LDFLAGS";
  484. export LIBS="${LIBS} ${flag}"
  485. ;;
  486. *)
  487. export LIBS="${LIBS} -l${flag}"
  488. ;;
  489. esac;
  490. done;
  491. return 0
  492. }
  493. clang-fullversion ()
  494. {
  495. _clang_fullversion '$1.$2.$3' "$@"
  496. }
  497. clang-major-version ()
  498. {
  499. _clang_fullversion '$1' "$@"
  500. }
  501. clang-micro-version ()
  502. {
  503. _clang_fullversion '$3' "$@"
  504. }
  505. clang-minor-version ()
  506. {
  507. _clang_fullversion '$2' "$@"
  508. }
  509. clang-version ()
  510. {
  511. _clang_fullversion '$1.$2' "$@"
  512. }
  513. darwintoolize ()
  514. {
  515. die "Use elibtoolize"
  516. }
  517. delete_all_version_separators ()
  518. {
  519. replace_all_version_separators "" "${1}"
  520. }
  521. delete_version_separator ()
  522. {
  523. replace_version_separator "${1}" "" "${2}"
  524. }
  525. doicon ()
  526. {
  527. _iconins ${FUNCNAME} "$@"
  528. }
  529. domenu ()
  530. {
  531. ( local i ret=0;
  532. insopts -m 0644;
  533. insinto /usr/share/applications;
  534. for i in "$@";
  535. do
  536. if [[ -d ${i} ]]; then
  537. doins "${i}"/*.desktop;
  538. ((ret|=$?));
  539. else
  540. doins "${i}";
  541. ((ret|=$?));
  542. fi;
  543. done;
  544. exit ${ret} )
  545. }
  546. eapply ()
  547. {
  548. local failed patch_cmd=patch;
  549. local -x LC_COLLATE=POSIX;
  550. type -P gpatch > /dev/null && patch_cmd=gpatch;
  551. function _eapply_patch ()
  552. {
  553. local f=${1};
  554. local prefix=${2};
  555. started_applying=1;
  556. ebegin "${prefix:-Applying }${f##*/}";
  557. ${patch_cmd} -p1 -f -s -g0 --no-backup-if-mismatch "${patch_options[@]}" < "${f}";
  558. failed=${?};
  559. if ! eend "${failed}"; then
  560. __helpers_die "patch -p1 ${patch_options[*]} failed with ${f}";
  561. fi
  562. };
  563. local patch_options=() files=();
  564. local i found_doublehyphen;
  565. for ((i = 1; i <= ${#@}; ++i ))
  566. do
  567. if [[ ${@:i:1} == -- ]]; then
  568. patch_options=("${@:1:i-1}");
  569. files=("${@:i+1}");
  570. found_doublehyphen=1;
  571. break;
  572. fi;
  573. done;
  574. if [[ -z ${found_doublehyphen} ]]; then
  575. for ((i = 1; i <= ${#@}; ++i ))
  576. do
  577. if [[ ${@:i:1} != -* ]]; then
  578. patch_options=("${@:1:i-1}");
  579. files=("${@:i}");
  580. break;
  581. fi;
  582. done;
  583. for i in "${files[@]}";
  584. do
  585. if [[ ${i} == -* ]]; then
  586. die "eapply: all options must be passed before non-options";
  587. fi;
  588. done;
  589. fi;
  590. if [[ ${#files[@]} -eq 0 ]]; then
  591. die "eapply: no files specified";
  592. fi;
  593. local f;
  594. for f in "${files[@]}";
  595. do
  596. if [[ -d ${f} ]]; then
  597. function _eapply_get_files ()
  598. {
  599. local LC_ALL=POSIX;
  600. local prev_shopt=$(shopt -p nullglob);
  601. shopt -s nullglob;
  602. local f;
  603. for f in "${1}"/*;
  604. do
  605. if [[ ${f} == *.diff || ${f} == *.patch ]]; then
  606. files+=("${f}");
  607. fi;
  608. done;
  609. ${prev_shopt}
  610. };
  611. local files=();
  612. _eapply_get_files "${f}";
  613. [[ ${#files[@]} -eq 0 ]] && die "No *.{patch,diff} files in directory ${f}";
  614. einfo "Applying patches from ${f} ...";
  615. local f2;
  616. for f2 in "${files[@]}";
  617. do
  618. _eapply_patch "${f2}" ' ';
  619. [[ ${failed} -ne 0 ]] && return "${failed}";
  620. done;
  621. else
  622. _eapply_patch "${f}";
  623. [[ ${failed} -ne 0 ]] && return "${failed}";
  624. fi;
  625. done;
  626. return 0
  627. }
  628. eapply_user ()
  629. {
  630. [[ ${EBUILD_PHASE} == prepare ]] || die "eapply_user() called during invalid phase: ${EBUILD_PHASE}";
  631. local tagfile=${T}/.portage_user_patches_applied;
  632. [[ -f ${tagfile} ]] && return;
  633. >> "${tagfile}";
  634. local basedir=${PORTAGE_CONFIGROOT%/}/etc/portage/patches;
  635. local applied d f;
  636. local -A _eapply_user_patches;
  637. local prev_shopt=$(shopt -p nullglob);
  638. shopt -s nullglob;
  639. for d in "${basedir}"/${CATEGORY}/{${P}-${PR},${P},${PN}}{:${SLOT%/*},};
  640. do
  641. for f in "${d}"/*;
  642. do
  643. if [[ ( ${f} == *.diff || ${f} == *.patch ) && -z ${_eapply_user_patches[${f##*/}]} ]]; then
  644. _eapply_user_patches[${f##*/}]=${f};
  645. fi;
  646. done;
  647. done;
  648. if [[ ${#_eapply_user_patches[@]} -gt 0 ]]; then
  649. while read -r -d '' f; do
  650. f=${_eapply_user_patches[${f}]};
  651. if [[ -s ${f} ]]; then
  652. eapply "${f}";
  653. applied=1;
  654. fi;
  655. done < <(printf -- '%s\0' "${!_eapply_user_patches[@]}" |
  656. LC_ALL=C sort -z);
  657. fi;
  658. ${prev_shopt};
  659. [[ -n ${applied} ]] && ewarn "User patches applied."
  660. }
  661. ebeep ()
  662. {
  663. ewarn "QA Notice: ebeep is not defined in EAPI=${EAPI}, please file a bug at https://bugs.gentoo.org"
  664. }
  665. econf_build ()
  666. {
  667. local CBUILD=${CBUILD:-${CHOST}};
  668. tc-env_build econf --build=${CBUILD} --host=${CBUILD} "$@"
  669. }
  670. ecvs_clean ()
  671. {
  672. [[ $# -eq 0 ]] && set -- .;
  673. find "$@" '(' -type d -name 'CVS' -prune -o -type f -name '.cvs*' ')' -exec rm -rf '{}' +
  674. }
  675. edos2unix ()
  676. {
  677. [[ $# -eq 0 ]] && return 0;
  678. sed -i 's/\r$//' -- "$@" || die
  679. }
  680. egit_clean ()
  681. {
  682. [[ $# -eq 0 ]] && set -- .;
  683. find "$@" -type d -name '.git*' -prune -exec rm -rf '{}' +
  684. }
  685. einstalldocs ()
  686. {
  687. ( if ! declare -p DOCS &> /dev/null; then
  688. local d;
  689. for d in README* ChangeLog AUTHORS NEWS TODO CHANGES THANKS BUGS FAQ CREDITS CHANGELOG;
  690. do
  691. [[ -f ${d} && -s ${d} ]] && docinto / && dodoc "${d}";
  692. done;
  693. else
  694. if [[ $(declare -p DOCS) == "declare -a"* ]]; then
  695. [[ ${#DOCS[@]} -gt 0 ]] && docinto / && dodoc -r "${DOCS[@]}";
  696. else
  697. [[ -n ${DOCS} ]] && docinto / && dodoc -r ${DOCS};
  698. fi;
  699. fi );
  700. ( if [[ $(declare -p HTML_DOCS 2>/dev/null) == "declare -a"* ]]; then
  701. [[ ${#HTML_DOCS[@]} -gt 0 ]] && docinto html && dodoc -r "${HTML_DOCS[@]}";
  702. else
  703. [[ -n ${HTML_DOCS} ]] && docinto html && dodoc -r ${HTML_DOCS};
  704. fi )
  705. }
  706. elibtoolize ()
  707. {
  708. type -P eltpatch &> /dev/null || die "eltpatch not found; is app-portage/elt-patches installed?";
  709. ELT_LOGDIR=${T} LD=$(tc-getLD) eltpatch "${@}" || die "eltpatch failed"
  710. }
  711. emktemp ()
  712. {
  713. local exe="touch";
  714. [[ $1 == -d ]] && exe="mkdir" && shift;
  715. local topdir=$1;
  716. if [[ -z ${topdir} ]]; then
  717. [[ -z ${T} ]] && topdir="/tmp" || topdir=${T};
  718. fi;
  719. if ! type -P mktemp > /dev/null; then
  720. local tmp=/;
  721. while [[ -e ${tmp} ]]; do
  722. tmp=${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM};
  723. done;
  724. ${exe} "${tmp}" || ${exe} -p "${tmp}";
  725. echo "${tmp}";
  726. else
  727. if [[ ${exe} == "touch" ]]; then
  728. TMPDIR="${topdir}" mktemp -t tmp.XXXXXXXXXX;
  729. else
  730. TMPDIR="${topdir}" mktemp -dt tmp.XXXXXXXXXX;
  731. fi;
  732. fi
  733. }
  734. epatch ()
  735. {
  736. function _epatch_draw_line ()
  737. {
  738. [[ -z $1 ]] && set "$(printf "%65s" '')";
  739. echo "${1//?/=}"
  740. };
  741. unset P4CONFIG P4PORT P4USER;
  742. local EPATCH_OPTS=(${EPATCH_OPTS[*]});
  743. while [[ $# -gt 0 ]]; do
  744. case $1 in
  745. -*)
  746. EPATCH_OPTS+=("$1")
  747. ;;
  748. *)
  749. break
  750. ;;
  751. esac;
  752. shift;
  753. done;
  754. if [[ $# -gt 1 ]]; then
  755. local m;
  756. for m in "$@";
  757. do
  758. epatch "${m}";
  759. done;
  760. return 0;
  761. fi;
  762. local SINGLE_PATCH="no";
  763. [[ $# -eq 0 ]] && set -- "${EPATCH_SOURCE}";
  764. if [[ -f $1 ]]; then
  765. SINGLE_PATCH="yes";
  766. set -- "$1";
  767. local EPATCH_SUFFIX=$1;
  768. else
  769. if [[ -d $1 ]]; then
  770. evar_push_set LC_COLLATE C;
  771. set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"};
  772. evar_pop;
  773. else
  774. if [[ -f ${EPATCH_SOURCE}/$1 ]]; then
  775. epatch "${EPATCH_SOURCE}/$1";
  776. return $?;
  777. else
  778. [[ $# -ne 0 ]] && EPATCH_SOURCE=$1;
  779. echo;
  780. eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:";
  781. eerror;
  782. eerror " ${EPATCH_SOURCE}";
  783. eerror " ( ${EPATCH_SOURCE##*/} )";
  784. echo;
  785. die "Cannot find \$EPATCH_SOURCE!";
  786. fi;
  787. fi;
  788. fi;
  789. EPATCH_OPTS="${EPATCH_COMMON_OPTS} ${EPATCH_OPTS[*]}";
  790. local PIPE_CMD;
  791. case ${EPATCH_SUFFIX##*\.} in
  792. xz)
  793. PIPE_CMD="xz -dc"
  794. ;;
  795. lzma)
  796. PIPE_CMD="lzma -dc"
  797. ;;
  798. bz2)
  799. PIPE_CMD="bzip2 -dc"
  800. ;;
  801. gz | Z | z)
  802. PIPE_CMD="gzip -dc"
  803. ;;
  804. ZIP | zip)
  805. PIPE_CMD="unzip -p"
  806. ;;
  807. *)
  808. ;;
  809. esac;
  810. [[ ${SINGLE_PATCH} == "no" ]] && einfo "${EPATCH_MULTI_MSG}";
  811. local x;
  812. for x in "$@";
  813. do
  814. [[ ! -f ${x} ]] && continue;
  815. local patchname=${x##*/};
  816. local a=${patchname#*_};
  817. a=${a%%_*};
  818. if ! [[ ${SINGLE_PATCH} == "yes" || ${EPATCH_FORCE} == "yes" || ${a} == all || ${a} == ${ARCH} ]]; then
  819. continue;
  820. fi;
  821. if [[ -n ${EPATCH_EXCLUDE}${EPATCH_USER_EXCLUDE} ]]; then
  822. local prev_noglob=$(shopt -p -o noglob);
  823. set -o noglob;
  824. local ex;
  825. for ex in ${EPATCH_EXCLUDE};
  826. do
  827. if [[ ${patchname} == ${ex} ]]; then
  828. einfo " Skipping ${patchname} due to EPATCH_EXCLUDE ...";
  829. ${prev_noglob};
  830. continue 2;
  831. fi;
  832. done;
  833. for ex in ${EPATCH_USER_EXCLUDE};
  834. do
  835. if [[ ${patchname} == ${ex} ]]; then
  836. einfo " Skipping ${patchname} due to EPATCH_USER_EXCLUDE ...";
  837. ${prev_noglob};
  838. continue 2;
  839. fi;
  840. done;
  841. ${prev_noglob};
  842. fi;
  843. if [[ ${SINGLE_PATCH} == "yes" ]]; then
  844. if [[ -n ${EPATCH_SINGLE_MSG} ]]; then
  845. einfo "${EPATCH_SINGLE_MSG}";
  846. else
  847. einfo "Applying ${patchname} ...";
  848. fi;
  849. else
  850. einfo " ${patchname} ...";
  851. fi;
  852. local patch="patch";
  853. eval $(alias patch 2>/dev/null | sed 's:^alias ::');
  854. local STDERR_TARGET="${T}/${patchname}.out";
  855. if [[ -e ${STDERR_TARGET} ]]; then
  856. STDERR_TARGET="${T}/${patchname}-$$.out";
  857. fi;
  858. printf "***** %s *****\nPWD: %s\nPATCH TOOL: %s -> %s\nVERSION INFO:\n%s\n\n" "${patchname}" "${PWD}" "${patch}" "$(type -P "${patch}")" "$(${patch} --version)" > "${STDERR_TARGET}";
  859. local count=0;
  860. local PATCH_TARGET;
  861. if [[ -n ${PIPE_CMD} ]]; then
  862. PATCH_TARGET="${T}/$$.patch";
  863. echo "PIPE_COMMAND: ${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> "${STDERR_TARGET}";
  864. if ! ( ${PIPE_CMD} "${x}" > "${PATCH_TARGET}" ) >> "${STDERR_TARGET}" 2>&1; then
  865. echo;
  866. eerror "Could not extract patch!";
  867. count=5;
  868. break;
  869. fi;
  870. else
  871. PATCH_TARGET=${x};
  872. fi;
  873. local abs_paths=$(egrep -n '^[-+]{3} /' "${PATCH_TARGET}" | awk '$2 != "/dev/null" { print }');
  874. if [[ -n ${abs_paths} ]]; then
  875. count=1;
  876. printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}";
  877. fi;
  878. local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}");
  879. if [[ -n ${rel_paths} ]]; then
  880. echo;
  881. eerror "Rejected Patch: ${patchname} !";
  882. eerror " ( ${PATCH_TARGET} )";
  883. eerror;
  884. eerror "Your patch uses relative paths '../':";
  885. eerror "${rel_paths}";
  886. echo;
  887. die "you need to fix the relative paths in patch";
  888. fi;
  889. local patch_cmd;
  890. while [[ ${count} -lt 5 ]]; do
  891. patch_cmd="${patch} -p${count} ${EPATCH_OPTS}";
  892. ( _epatch_draw_line "***** ${patchname} *****";
  893. echo;
  894. echo "PATCH COMMAND: ${patch_cmd} --dry-run -f < '${PATCH_TARGET}'";
  895. echo;
  896. _epatch_draw_line "***** ${patchname} *****";
  897. ${patch_cmd} --dry-run -f < "${PATCH_TARGET}" 2>&1;
  898. ret=$?;
  899. echo;
  900. echo "patch program exited with status ${ret}";
  901. exit ${ret} ) >> "${STDERR_TARGET}";
  902. if [ $? -eq 0 ]; then
  903. ( _epatch_draw_line "***** ${patchname} *****";
  904. echo;
  905. echo "ACTUALLY APPLYING ${patchname} ...";
  906. echo "PATCH COMMAND: ${patch_cmd} < '${PATCH_TARGET}'";
  907. echo;
  908. _epatch_draw_line "***** ${patchname} *****";
  909. ${patch_cmd} < "${PATCH_TARGET}" 2>&1;
  910. ret=$?;
  911. echo;
  912. echo "patch program exited with status ${ret}";
  913. exit ${ret} ) >> "${STDERR_TARGET}";
  914. if [ $? -ne 0 ]; then
  915. echo;
  916. eerror "A dry-run of patch command succeeded, but actually";
  917. eerror "applying the patch failed!";
  918. count=5;
  919. fi;
  920. break;
  921. fi;
  922. : $(( count++ ));
  923. done;
  924. (( EPATCH_N_APPLIED_PATCHES++ ));
  925. if [[ -n ${PIPE_CMD} ]]; then
  926. rm -f "${PATCH_TARGET}";
  927. fi;
  928. if [[ ${count} -ge 5 ]]; then
  929. echo;
  930. eerror "Failed Patch: ${patchname} !";
  931. eerror " ( ${PATCH_TARGET} )";
  932. eerror;
  933. eerror "Include in your bugreport the contents of:";
  934. eerror;
  935. eerror " ${STDERR_TARGET}";
  936. echo;
  937. die "Failed Patch: ${patchname}!";
  938. fi;
  939. rm -f "${STDERR_TARGET}";
  940. cat >> "${T}/epatch.log" <<-EOF
  941. PATCH: ${x}
  942. CMD: ${patch_cmd}
  943. PWD: ${PWD}
  944. EOF
  945. eend 0;
  946. done;
  947. [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching";
  948. :
  949. }
  950. epause ()
  951. {
  952. ewarn "QA Notice: epause is not defined in EAPI=${EAPI}, please file a bug at https://bugs.gentoo.org"
  953. }
  954. eshopts_pop ()
  955. {
  956. local s;
  957. estack_pop eshopts s || die "${FUNCNAME}: unbalanced push";
  958. eval "${s}" || die "${FUNCNAME}: sanity: invalid shopt options: ${s}"
  959. }
  960. eshopts_push ()
  961. {
  962. if [[ $1 == -[su] ]]; then
  963. estack_push eshopts "$(shopt -p)";
  964. [[ $# -eq 0 ]] && return 0;
  965. shopt "$@" || die "${FUNCNAME}: bad options to shopt: $*";
  966. else
  967. estack_push eshopts "$(shopt -p -o)";
  968. [[ $# -eq 0 ]] && return 0;
  969. set "$@" || die "${FUNCNAME}: bad options to set: $*";
  970. fi
  971. }
  972. estack_pop ()
  973. {
  974. [[ $# -eq 0 || $# -gt 2 ]] && die "estack_pop: incorrect # of arguments";
  975. local _estack_name="_ESTACK_$1_";
  976. shift;
  977. local _estack_retvar=$1;
  978. shift;
  979. eval local _estack_i=\${#${_estack_name}\[@\]};
  980. [[ $(( --_estack_i )) -eq -1 ]] && return 1;
  981. if [[ -n ${_estack_retvar} ]]; then
  982. eval ${_estack_retvar}=\"\${${_estack_name}\[${_estack_i}\]}\";
  983. fi;
  984. eval unset \"${_estack_name}\[${_estack_i}\]\"
  985. }
  986. estack_push ()
  987. {
  988. [[ $# -eq 0 ]] && die "estack_push: incorrect # of arguments";
  989. local stack_name="_ESTACK_$1_";
  990. shift;
  991. eval ${stack_name}+=\( \"\$@\" \)
  992. }
  993. esvn_clean ()
  994. {
  995. [[ $# -eq 0 ]] && set -- .;
  996. find "$@" -type d -name '.svn' -prune -exec rm -rf '{}' +
  997. }
  998. eumask_pop ()
  999. {
  1000. [[ $# -eq 0 ]] || die "${FUNCNAME}: we take no options";
  1001. local s;
  1002. estack_pop eumask s || die "${FUNCNAME}: unbalanced push";
  1003. umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}"
  1004. }
  1005. eumask_push ()
  1006. {
  1007. estack_push eumask "$(umask)";
  1008. umask "$@" || die "${FUNCNAME}: bad options to umask: $*"
  1009. }
  1010. evar_pop ()
  1011. {
  1012. local cnt=${1:-bad};
  1013. case $# in
  1014. 0)
  1015. cnt=1
  1016. ;;
  1017. 1)
  1018. isdigit "${cnt}" || die "${FUNCNAME}: first arg must be a number: $*"
  1019. ;;
  1020. *)
  1021. die "${FUNCNAME}: only accepts one arg: $*"
  1022. ;;
  1023. esac;
  1024. local var val;
  1025. while (( cnt-- )); do
  1026. estack_pop evar val || die "${FUNCNAME}: unbalanced push";
  1027. estack_pop evar var || die "${FUNCNAME}: unbalanced push";
  1028. [[ ${val} == "unset_76fc3c462065bb4ca959f939e6793f94" ]] && unset ${var} || printf -v "${var}" '%s' "${val}";
  1029. done
  1030. }
  1031. evar_push ()
  1032. {
  1033. local var val;
  1034. for var in "$@";
  1035. do
  1036. [[ ${!var+set} == "set" ]] && val=${!var} || val="unset_76fc3c462065bb4ca959f939e6793f94";
  1037. estack_push evar "${var}" "${val}";
  1038. done
  1039. }
  1040. evar_push_set ()
  1041. {
  1042. local var=$1;
  1043. evar_push ${var};
  1044. case $# in
  1045. 1)
  1046. unset ${var}
  1047. ;;
  1048. 2)
  1049. printf -v "${var}" '%s' "$2"
  1050. ;;
  1051. *)
  1052. die "${FUNCNAME}: incorrect # of args: $*"
  1053. ;;
  1054. esac
  1055. }
  1056. filter-flags ()
  1057. {
  1058. _filter-hardened "$@";
  1059. local v;
  1060. for v in $(all-flag-vars);
  1061. do
  1062. _filter-var ${v} "$@";
  1063. done;
  1064. return 0
  1065. }
  1066. filter-ldflags ()
  1067. {
  1068. _filter-var LDFLAGS "$@";
  1069. return 0
  1070. }
  1071. filter-lfs-flags ()
  1072. {
  1073. [[ $# -ne 0 ]] && die "filter-lfs-flags takes no arguments";
  1074. filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
  1075. }
  1076. filter-mfpmath ()
  1077. {
  1078. local orig_mfpmath new_math prune_math;
  1079. orig_mfpmath=$(get-flag -mfpmath);
  1080. new_math=$(get-flag mfpmath);
  1081. new_math=${new_math/both/387,sse};
  1082. new_math=" ${new_math//[,+]/ } ";
  1083. prune_math="";
  1084. for prune_math in "$@";
  1085. do
  1086. new_math=${new_math/ ${prune_math} / };
  1087. done;
  1088. new_math=$(echo ${new_math});
  1089. new_math=${new_math// /,};
  1090. if [[ -z ${new_math} ]]; then
  1091. filter-flags ${orig_mfpmath};
  1092. else
  1093. replace-flags ${orig_mfpmath} -mfpmath=${new_math};
  1094. fi;
  1095. return 0
  1096. }
  1097. gcc-fullversion ()
  1098. {
  1099. _gcc_fullversion '$1.$2.$3' "$@"
  1100. }
  1101. gcc-major-version ()
  1102. {
  1103. _gcc_fullversion '$1' "$@"
  1104. }
  1105. gcc-micro-version ()
  1106. {
  1107. _gcc_fullversion '$3' "$@"
  1108. }
  1109. gcc-minor-version ()
  1110. {
  1111. _gcc_fullversion '$2' "$@"
  1112. }
  1113. gcc-specs-directive ()
  1114. {
  1115. local directive subdname subdirective;
  1116. directive="$(_gcc-specs-directive_raw $1)";
  1117. while [[ ${directive} == *%\(*\)* ]]; do
  1118. subdname=${directive/*%\(};
  1119. subdname=${subdname/\)*};
  1120. subdirective="$(_gcc-specs-directive_raw ${subdname})";
  1121. directive="${directive//\%(${subdname})/${subdirective}}";
  1122. done;
  1123. echo "${directive}";
  1124. return 0
  1125. }
  1126. gcc-specs-nostrict ()
  1127. {
  1128. local directive;
  1129. directive=$(gcc-specs-directive cc1);
  1130. [[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]]
  1131. }
  1132. gcc-specs-now ()
  1133. {
  1134. local directive;
  1135. directive=$(gcc-specs-directive link_command);
  1136. [[ "${directive/\{!nonow:}" != "${directive}" ]]
  1137. }
  1138. gcc-specs-pie ()
  1139. {
  1140. local directive;
  1141. directive=$(gcc-specs-directive cc1);
  1142. [[ "${directive/\{!nopie:}" != "${directive}" ]]
  1143. }
  1144. gcc-specs-relro ()
  1145. {
  1146. local directive;
  1147. directive=$(gcc-specs-directive link_command);
  1148. [[ "${directive/\{!norelro:}" != "${directive}" ]]
  1149. }
  1150. gcc-specs-ssp ()
  1151. {
  1152. local directive;
  1153. directive=$(gcc-specs-directive cc1);
  1154. [[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]]
  1155. }
  1156. gcc-specs-ssp-to-all ()
  1157. {
  1158. local directive;
  1159. directive=$(gcc-specs-directive cc1);
  1160. [[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]]
  1161. }
  1162. gcc-specs-stack-check ()
  1163. {
  1164. local directive;
  1165. directive=$(gcc-specs-directive cc1);
  1166. [[ "${directive/\{!fno-stack-check:}" != "${directive}" ]]
  1167. }
  1168. gcc-version ()
  1169. {
  1170. _gcc_fullversion '$1.$2' "$@"
  1171. }
  1172. gen_usr_ldscript ()
  1173. {
  1174. local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname);
  1175. [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/;
  1176. tc-is-static-only && return;
  1177. if [[ $(type -t multilib_is_native_abi) == "function" ]]; then
  1178. multilib_is_native_abi || return 0;
  1179. fi;
  1180. case ${CTARGET:-${CHOST}} in
  1181. *-darwin*)
  1182. ;;
  1183. *-android*)
  1184. return 0
  1185. ;;
  1186. *linux* | *-freebsd* | *-openbsd* | *-netbsd*)
  1187. use prefix && return 0
  1188. ;;
  1189. *)
  1190. return 0
  1191. ;;
  1192. esac;
  1193. dodir /usr/${libdir};
  1194. if [[ $1 == "-a" ]]; then
  1195. auto=true;
  1196. shift;
  1197. dodir /${libdir};
  1198. fi;
  1199. local flags=(${CFLAGS} ${LDFLAGS} -Wl,--verbose);
  1200. if $(tc-getLD) --version | grep -q 'GNU gold'; then
  1201. local d="${T}/bfd-linker";
  1202. mkdir -p "${d}";
  1203. ln -sf $(which ${CHOST}-ld.bfd) "${d}"/ld;
  1204. flags+=(-B"${d}");
  1205. fi;
  1206. output_format=$($(tc-getCC) "${flags[@]}" 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p');
  1207. [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )";
  1208. for lib in "$@";
  1209. do
  1210. local tlib;
  1211. if ${auto}; then
  1212. lib="lib${lib}${suffix}";
  1213. else
  1214. [[ -r ${ED}/${libdir}/${lib} ]] || continue;
  1215. fi;
  1216. case ${CTARGET:-${CHOST}} in
  1217. *-darwin*)
  1218. if ${auto}; then
  1219. tlib=$(scanmacho -qF'%S#F' "${ED}"/usr/${libdir}/${lib});
  1220. else
  1221. tlib=$(scanmacho -qF'%S#F' "${ED}"/${libdir}/${lib});
  1222. fi;
  1223. [[ -z ${tlib} ]] && die "unable to read install_name from ${lib}";
  1224. tlib=${tlib##*/};
  1225. if ${auto}; then
  1226. mv "${ED}"/usr/${libdir}/${lib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die;
  1227. if [[ ${tlib} != ${lib%${suffix}}.*${suffix#.} ]]; then
  1228. mv "${ED}"/usr/${libdir}/${tlib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die;
  1229. fi;
  1230. rm -f "${ED}"/${libdir}/${lib};
  1231. fi;
  1232. if [[ ! -w "${ED}/${libdir}/${tlib}" ]]; then
  1233. chmod u+w "${ED}${libdir}/${tlib}";
  1234. local nowrite=yes;
  1235. fi;
  1236. install_name_tool -id "${EPREFIX}"/${libdir}/${tlib} "${ED}"/${libdir}/${tlib} || die "install_name_tool failed";
  1237. [[ -n ${nowrite} ]] && chmod u-w "${ED}${libdir}/${tlib}";
  1238. pushd "${ED}/usr/${libdir}" > /dev/null;
  1239. ln -snf "../../${libdir}/${tlib}" "${lib}";
  1240. popd > /dev/null
  1241. ;;
  1242. *)
  1243. if ${auto}; then
  1244. tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib});
  1245. [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}";
  1246. mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die;
  1247. if [[ ${tlib} != ${lib}* ]]; then
  1248. mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die;
  1249. fi;
  1250. rm -f "${ED}"/${libdir}/${lib};
  1251. else
  1252. tlib=${lib};
  1253. fi;
  1254. cat > "${ED}/usr/${libdir}/${lib}" <<-END_LDSCRIPT
  1255. /* GNU ld script
  1256. Since Gentoo has critical dynamic libraries in /lib, and the static versions
  1257. in /usr/lib, we need to have a "fake" dynamic lib in /usr/lib, otherwise we
  1258. run into linking problems. This "fake" dynamic lib is a linker script that
  1259. redirects the linker to the real lib. And yes, this works in the cross-
  1260. compiling scenario as the sysroot-ed linker will prepend the real path.
  1261. See bug https://bugs.gentoo.org/4411 for more info.
  1262. */
  1263. ${output_format}
  1264. GROUP ( ${EPREFIX}/${libdir}/${tlib} )
  1265. END_LDSCRIPT
  1266. ;;
  1267. esac
  1268. fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}";
  1269. done
  1270. }
  1271. get-flag ()
  1272. {
  1273. local f var findflag="$1";
  1274. for var in $(all-flag-vars);
  1275. do
  1276. for f in ${!var};
  1277. do
  1278. if [ "${f/${findflag}}" != "${f}" ]; then
  1279. printf "%s\n" "${f/-${findflag}=}";
  1280. return 0;
  1281. fi;
  1282. done;
  1283. done;
  1284. return 1
  1285. }
  1286. get_abi_CFLAGS ()
  1287. {
  1288. get_abi_var CFLAGS "$@"
  1289. }
  1290. get_abi_CHOST ()
  1291. {
  1292. get_abi_var CHOST "$@"
  1293. }
  1294. get_abi_CTARGET ()
  1295. {
  1296. get_abi_var CTARGET "$@"
  1297. }
  1298. get_abi_FAKE_TARGETS ()
  1299. {
  1300. get_abi_var FAKE_TARGETS "$@"
  1301. }
  1302. get_abi_LDFLAGS ()
  1303. {
  1304. get_abi_var LDFLAGS "$@"
  1305. }
  1306. get_abi_LIBDIR ()
  1307. {
  1308. get_abi_var LIBDIR "$@"
  1309. }
  1310. get_abi_var ()
  1311. {
  1312. local flag=$1;
  1313. local abi=${2:-${ABI:-${DEFAULT_ABI:-default}}};
  1314. local var="${flag}_${abi}";
  1315. echo ${!var}
  1316. }
  1317. get_after_major_version ()
  1318. {
  1319. echo $(get_version_component_range 2- "${1:-${PV}}")
  1320. }
  1321. get_all_abis ()
  1322. {
  1323. local x order="" mvar dvar;
  1324. mvar="MULTILIB_ABIS";
  1325. dvar="DEFAULT_ABI";
  1326. if [[ -n $1 ]]; then
  1327. mvar="$1_${mvar}";
  1328. dvar="$1_${dvar}";
  1329. fi;
  1330. if [[ -z ${!mvar} ]]; then
  1331. echo "default";
  1332. return 0;
  1333. fi;
  1334. for x in ${!mvar};
  1335. do
  1336. if [[ ${x} != ${!dvar} ]]; then
  1337. order="${order:+${order} }${x}";
  1338. fi;
  1339. done;
  1340. order="${order:+${order} }${!dvar}";
  1341. echo ${order};
  1342. return 0
  1343. }
  1344. get_all_libdirs ()
  1345. {
  1346. local libdirs abi;
  1347. for abi in ${MULTILIB_ABIS};
  1348. do
  1349. libdirs+=" $(get_abi_LIBDIR ${abi})";
  1350. done;
  1351. [[ " ${libdirs} " != *" lib "* ]] && libdirs+=" lib";
  1352. echo "${libdirs}"
  1353. }
  1354. get_all_version_components ()
  1355. {
  1356. eshopts_push -s extglob;
  1357. local ver_str=${1:-${PV}} result;
  1358. result=();
  1359. if [[ ${VERSIONATOR_CACHE_VER_STR} == ${ver_str} ]]; then
  1360. echo ${VERSIONATOR_CACHE_RESULT};
  1361. eshopts_pop;
  1362. return;
  1363. fi;
  1364. export VERSIONATOR_CACHE_VER_STR=${ver_str};
  1365. while [[ -n $ver_str ]]; do
  1366. case "${ver_str::1}" in
  1367. [[:digit:]])
  1368. result+=("${ver_str%%[^[:digit:]]*}");
  1369. ver_str=${ver_str##+([[:digit:]])}
  1370. ;;
  1371. [-_.])
  1372. result+=("${ver_str::1}");
  1373. ver_str=${ver_str:1}
  1374. ;;
  1375. [[:alpha:]])
  1376. local not_match=${ver_str##+([[:alpha:]])*([[:digit:]])};
  1377. result+=("${ver_str::${#ver_str} - ${#not_match}}");
  1378. ver_str=${not_match}
  1379. ;;
  1380. *)
  1381. result+=("${ver_str::1}");
  1382. ver_str=${ver_str:1}
  1383. ;;
  1384. esac;
  1385. done;
  1386. export VERSIONATOR_CACHE_RESULT=${result[*]};
  1387. echo ${result[@]};
  1388. eshopts_pop
  1389. }
  1390. get_exeext ()
  1391. {
  1392. case ${CHOST} in
  1393. *-cygwin* | mingw* | *-mingw*)
  1394. echo ".exe"
  1395. ;;
  1396. esac
  1397. }
  1398. get_install_abis ()
  1399. {
  1400. local x order="";
  1401. if [[ -z ${MULTILIB_ABIS} ]]; then
  1402. echo "default";
  1403. return 0;
  1404. fi;
  1405. if [[ ${EMULTILIB_PKG} == "true" ]]; then
  1406. for x in ${MULTILIB_ABIS};
  1407. do
  1408. if [[ ${x} != "${DEFAULT_ABI}" ]]; then
  1409. has ${x} ${ABI_DENY} || order="${order} ${x}";
  1410. fi;
  1411. done;
  1412. has ${DEFAULT_ABI} ${ABI_DENY} || order="${order} ${DEFAULT_ABI}";
  1413. if [[ -n ${ABI_ALLOW} ]]; then
  1414. local ordera="";
  1415. for x in ${order};
  1416. do
  1417. if has ${x} ${ABI_ALLOW}; then
  1418. ordera="${ordera} ${x}";
  1419. fi;
  1420. done;
  1421. order=${ordera};
  1422. fi;
  1423. else
  1424. order=${DEFAULT_ABI};
  1425. fi;
  1426. if [[ -z ${order} ]]; then
  1427. 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.";
  1428. fi;
  1429. echo ${order};
  1430. return 0
  1431. }
  1432. get_last_version_component_index ()
  1433. {
  1434. echo $(($(get_version_component_count "${1:-${PV}}" ) - 1))
  1435. }
  1436. get_libdir ()
  1437. {
  1438. local libdir_var="LIBDIR_${ABI}";
  1439. local libdir="lib";
  1440. [[ -n ${ABI} && -n ${!libdir_var} ]] && libdir=${!libdir_var};
  1441. echo "${libdir}"
  1442. }
  1443. get_libname ()
  1444. {
  1445. local libname;
  1446. local ver=$1;
  1447. case ${CHOST} in
  1448. *-cygwin*)
  1449. libname="dll.a"
  1450. ;;
  1451. mingw* | *-mingw*)
  1452. libname="dll"
  1453. ;;
  1454. *-darwin*)
  1455. libname="dylib"
  1456. ;;
  1457. *-mint*)
  1458. libname="irrelevant"
  1459. ;;
  1460. hppa*-hpux*)
  1461. libname="sl"
  1462. ;;
  1463. *)
  1464. libname="so"
  1465. ;;
  1466. esac;
  1467. if [[ -z $* ]]; then
  1468. echo ".${libname}";
  1469. else
  1470. for ver in "$@";
  1471. do
  1472. case ${CHOST} in
  1473. *-cygwin*)
  1474. echo ".${ver}.${libname}"
  1475. ;;
  1476. *-darwin*)
  1477. echo ".${ver}.${libname}"
  1478. ;;
  1479. *-mint*)
  1480. echo ".${libname}"
  1481. ;;
  1482. *)
  1483. echo ".${libname}.${ver}"
  1484. ;;
  1485. esac;
  1486. done;
  1487. fi
  1488. }
  1489. get_major_version ()
  1490. {
  1491. local c=($(get_all_version_components "${1:-${PV}}"));
  1492. echo ${c[0]}
  1493. }
  1494. get_modname ()
  1495. {
  1496. local modname;
  1497. local ver=$1;
  1498. case ${CHOST} in
  1499. *-darwin*)
  1500. modname="bundle"
  1501. ;;
  1502. *)
  1503. modname="so"
  1504. ;;
  1505. esac;
  1506. echo ".${modname}"
  1507. }
  1508. get_version_component_count ()
  1509. {
  1510. local a=($(get_version_components "${1:-${PV}}"));
  1511. echo ${#a[@]}
  1512. }
  1513. get_version_component_range ()
  1514. {
  1515. eshopts_push -s extglob;
  1516. local c v="${2:-${PV}}" range="${1}" range_start range_end;
  1517. local -i i=-1 j=0;
  1518. c=($(get_all_version_components "${v}"));
  1519. range_start=${range%-*};
  1520. range_start=${range_start:-1};
  1521. range_end=${range#*-};
  1522. range_end=${range_end:-${#c[@]}};
  1523. while ((j < range_start)); do
  1524. i+=1;
  1525. ((i > ${#c[@]})) && eshopts_pop && return;
  1526. [[ -n "${c[i]//[-._]}" ]] && j+=1;
  1527. done;
  1528. while ((j <= range_end)); do
  1529. echo -n ${c[i]};
  1530. ((i > ${#c[@]})) && eshopts_pop && return;
  1531. [[ -n "${c[i]//[-._]}" ]] && j+=1;
  1532. i+=1;
  1533. done;
  1534. eshopts_pop
  1535. }
  1536. get_version_components ()
  1537. {
  1538. local c=$(get_all_version_components "${1:-${PV}}");
  1539. echo ${c//[-._]/ }
  1540. }
  1541. gnuconfig_do_update ()
  1542. {
  1543. local configsubs_dir target targetlist file;
  1544. [[ $# -eq 0 ]] && die "do not call gnuconfig_do_update; use gnuconfig_update";
  1545. configsubs_dir=$(gnuconfig_findnewest);
  1546. einfo "Using GNU config files from ${configsubs_dir}";
  1547. for file in "$@";
  1548. do
  1549. if [[ ! -r ${configsubs_dir}/${file} ]]; then
  1550. eerror "Can't read ${configsubs_dir}/${file}, skipping..";
  1551. continue;
  1552. fi;
  1553. targetlist=$(find "${startdir}" -name "${file}");
  1554. if [[ -n ${targetlist} ]]; then
  1555. for target in ${targetlist};
  1556. do
  1557. [[ -L ${target} ]] && rm -f "${target}";
  1558. einfo " Updating ${target/$startdir\//}";
  1559. cp -f "${configsubs_dir}/${file}" "${target}";
  1560. eend $?;
  1561. done;
  1562. else
  1563. ewarn " No ${file} found in ${startdir}, skipping ...";
  1564. fi;
  1565. done;
  1566. return 0
  1567. }
  1568. gnuconfig_findnewest ()
  1569. {
  1570. local locations=("${EPREFIX}"/usr/share/misc/config.sub "${EPREFIX}"/usr/share/gnuconfig/config.sub "${EPREFIX}"/usr/share/automake*/config.sub "${EPREFIX}"/usr/share/libtool/config.sub);
  1571. grep -s '^timestamp' "${locations[@]}" | sort -r -n -t\' -k2 | sed -n '1{s,/config.sub:.*$,,;p;q}'
  1572. }
  1573. gnuconfig_update ()
  1574. {
  1575. local startdir;
  1576. if [[ $1 == /* ]]; then
  1577. startdir=$1;
  1578. shift;
  1579. else
  1580. startdir=${S};
  1581. fi;
  1582. if [[ $# -gt 0 ]]; then
  1583. gnuconfig_do_update "$@";
  1584. else
  1585. gnuconfig_do_update config.sub config.guess;
  1586. fi;
  1587. return $?
  1588. }
  1589. has_m32 ()
  1590. {
  1591. die "${FUNCNAME}: don't use this anymore"
  1592. }
  1593. has_m64 ()
  1594. {
  1595. die "${FUNCNAME}: don't use this anymore"
  1596. }
  1597. has_multilib_profile ()
  1598. {
  1599. [ -n "${MULTILIB_ABIS}" -a "${MULTILIB_ABIS}" != "${MULTILIB_ABIS/ /}" ]
  1600. }
  1601. in_iuse ()
  1602. {
  1603. local use=${1};
  1604. if [[ -z "${use}" ]]; then
  1605. echo "!!! in_iuse() called without a parameter." 1>&2;
  1606. echo "!!! in_iuse <USEFLAG>" 1>&2;
  1607. die "in_iuse() called without a parameter";
  1608. fi;
  1609. local liuse=(${IUSE_EFFECTIVE});
  1610. has "${use}" "${liuse[@]#[+-]}"
  1611. }
  1612. is-flag ()
  1613. {
  1614. is-flagq "$@" && echo true
  1615. }
  1616. is-flagq ()
  1617. {
  1618. [[ -n $2 ]] && die "Usage: is-flag <flag>";
  1619. local var;
  1620. for var in $(all-flag-vars);
  1621. do
  1622. _is_flagq ${var} "$1" && return 0;
  1623. done;
  1624. return 1
  1625. }
  1626. is-ldflag ()
  1627. {
  1628. is-ldflagq "$@" && echo true
  1629. }
  1630. is-ldflagq ()
  1631. {
  1632. [[ -n $2 ]] && die "Usage: is-ldflag <flag>";
  1633. _is_flagq LDFLAGS $1
  1634. }
  1635. is_cross ()
  1636. {
  1637. [[ ${CHOST} != ${CTARGET} ]]
  1638. }
  1639. is_final_abi ()
  1640. {
  1641. has_multilib_profile || return 0;
  1642. set -- $(get_install_abis);
  1643. local LAST_ABI=$#;
  1644. [[ ${!LAST_ABI} == ${ABI} ]]
  1645. }
  1646. isdigit ()
  1647. {
  1648. local d;
  1649. for d in "$@";
  1650. do
  1651. [[ ${d:-bad} == *[!0-9]* ]] && return 1;
  1652. done;
  1653. return 0
  1654. }
  1655. make_desktop_entry ()
  1656. {
  1657. [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable";
  1658. local exec=${1};
  1659. local name=${2:-${PN}};
  1660. local icon=${3:-${PN}};
  1661. local type=${4};
  1662. local fields=${5};
  1663. if [[ -z ${type} ]]; then
  1664. local catmaj=${CATEGORY%%-*};
  1665. local catmin=${CATEGORY##*-};
  1666. case ${catmaj} in
  1667. app)
  1668. case ${catmin} in
  1669. accessibility)
  1670. type="Utility;Accessibility"
  1671. ;;
  1672. admin)
  1673. type=System
  1674. ;;
  1675. antivirus)
  1676. type=System
  1677. ;;
  1678. arch)
  1679. type="Utility;Archiving"
  1680. ;;
  1681. backup)
  1682. type="Utility;Archiving"
  1683. ;;
  1684. cdr)
  1685. type="AudioVideo;DiscBurning"
  1686. ;;
  1687. dicts)
  1688. type="Office;Dictionary"
  1689. ;;
  1690. doc)
  1691. type=Documentation
  1692. ;;
  1693. editors)
  1694. type="Utility;TextEditor"
  1695. ;;
  1696. emacs)
  1697. type="Development;TextEditor"
  1698. ;;
  1699. emulation)
  1700. type="System;Emulator"
  1701. ;;
  1702. laptop)
  1703. type="Settings;HardwareSettings"
  1704. ;;
  1705. office)
  1706. type=Office
  1707. ;;
  1708. pda)
  1709. type="Office;PDA"
  1710. ;;
  1711. vim)
  1712. type="Development;TextEditor"
  1713. ;;
  1714. xemacs)
  1715. type="Development;TextEditor"
  1716. ;;
  1717. esac
  1718. ;;
  1719. dev)
  1720. type="Development"
  1721. ;;
  1722. games)
  1723. case ${catmin} in
  1724. action | fps)
  1725. type=ActionGame
  1726. ;;
  1727. arcade)
  1728. type=ArcadeGame
  1729. ;;
  1730. board)
  1731. type=BoardGame
  1732. ;;
  1733. emulation)
  1734. type=Emulator
  1735. ;;
  1736. kids)
  1737. type=KidsGame
  1738. ;;
  1739. puzzle)
  1740. type=LogicGame
  1741. ;;
  1742. roguelike)
  1743. type=RolePlaying
  1744. ;;
  1745. rpg)
  1746. type=RolePlaying
  1747. ;;
  1748. simulation)
  1749. type=Simulation
  1750. ;;
  1751. sports)
  1752. type=SportsGame
  1753. ;;
  1754. strategy)
  1755. type=StrategyGame
  1756. ;;
  1757. esac;
  1758. type="Game;${type}"
  1759. ;;
  1760. gnome)
  1761. type="Gnome;GTK"
  1762. ;;
  1763. kde)
  1764. type="KDE;Qt"
  1765. ;;
  1766. mail)
  1767. type="Network;Email"
  1768. ;;
  1769. media)
  1770. case ${catmin} in
  1771. gfx)
  1772. type=Graphics
  1773. ;;
  1774. *)
  1775. case ${catmin} in
  1776. radio)
  1777. type=Tuner
  1778. ;;
  1779. sound)
  1780. type=Audio
  1781. ;;
  1782. tv)
  1783. type=TV
  1784. ;;
  1785. video)
  1786. type=Video
  1787. ;;
  1788. esac;
  1789. type="AudioVideo;${type}"
  1790. ;;
  1791. esac
  1792. ;;
  1793. net)
  1794. case ${catmin} in
  1795. dialup)
  1796. type=Dialup
  1797. ;;
  1798. ftp)
  1799. type=FileTransfer
  1800. ;;
  1801. im)
  1802. type=InstantMessaging
  1803. ;;
  1804. irc)
  1805. type=IRCClient
  1806. ;;
  1807. mail)
  1808. type=Email
  1809. ;;
  1810. news)
  1811. type=News
  1812. ;;
  1813. nntp)
  1814. type=News
  1815. ;;
  1816. p2p)
  1817. type=FileTransfer
  1818. ;;
  1819. voip)
  1820. type=Telephony
  1821. ;;
  1822. esac;
  1823. type="Network;${type}"
  1824. ;;
  1825. sci)
  1826. case ${catmin} in
  1827. astro*)
  1828. type=Astronomy
  1829. ;;
  1830. bio*)
  1831. type=Biology
  1832. ;;
  1833. calc*)
  1834. type=Calculator
  1835. ;;
  1836. chem*)
  1837. type=Chemistry
  1838. ;;
  1839. elec*)
  1840. type=Electronics
  1841. ;;
  1842. geo*)
  1843. type=Geology
  1844. ;;
  1845. math*)
  1846. type=Math
  1847. ;;
  1848. physics)
  1849. type=Physics
  1850. ;;
  1851. visual*)
  1852. type=DataVisualization
  1853. ;;
  1854. esac;
  1855. type="Education;Science;${type}"
  1856. ;;
  1857. sys)
  1858. type="System"
  1859. ;;
  1860. www)
  1861. case ${catmin} in
  1862. client)
  1863. type=WebBrowser
  1864. ;;
  1865. esac;
  1866. type="Network;${type}"
  1867. ;;
  1868. *)
  1869. type=
  1870. ;;
  1871. esac;
  1872. fi;
  1873. local slot=${SLOT%/*};
  1874. if [[ ${slot} == "0" ]]; then
  1875. local desktop_name="${PN}";
  1876. else
  1877. local desktop_name="${PN}-${slot}";
  1878. fi;
  1879. local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop";
  1880. type=${type%;}${type:+;};
  1881. if [[ -n ${icon} && ${icon} != /* ]] && [[ ${icon} == *.xpm || ${icon} == *.png || ${icon} == *.svg ]]; then
  1882. ewarn "As described in the Icon Theme Specification, icon file extensions are not";
  1883. ewarn "allowed in .desktop files if the value is not an absolute path.";
  1884. icon=${icon%.*};
  1885. fi;
  1886. cat > "${desktop}" <<-EOF ||
  1887. [Desktop Entry]
  1888. Name=${name}
  1889. Type=Application
  1890. Comment=${DESCRIPTION}
  1891. Exec=${exec}
  1892. TryExec=${exec%% *}
  1893. Icon=${icon}
  1894. Categories=${type}
  1895. EOF
  1896. die
  1897. if [[ ${fields:-=} != *=* ]]; then
  1898. ewarn "make_desktop_entry: update your 5th arg to read Path=${fields}";
  1899. fields="Path=${fields}";
  1900. fi;
  1901. if [[ -n ${fields} ]]; then
  1902. printf '%b\n' "${fields}" >> "${desktop}" || die;
  1903. fi;
  1904. ( insopts -m 0644;
  1905. insinto /usr/share/applications;
  1906. doins "${desktop}" ) || die "installing desktop file failed"
  1907. }
  1908. make_session_desktop ()
  1909. {
  1910. [[ -z $1 ]] && eerror "$0: You must specify the title" && return 1;
  1911. [[ -z $2 ]] && eerror "$0: You must specify the command" && return 1;
  1912. local title=$1;
  1913. local command=$2;
  1914. local desktop=${T}/${wm:-${PN}}.desktop;
  1915. shift 2;
  1916. cat > "${desktop}" <<-EOF ||
  1917. [Desktop Entry]
  1918. Name=${title}
  1919. Comment=This session logs you into ${title}
  1920. Exec=${command} $*
  1921. TryExec=${command}
  1922. Type=XSession
  1923. EOF
  1924. die
  1925. ( insopts -m 0644;
  1926. insinto /usr/share/xsessions;
  1927. doins "${desktop}" )
  1928. }
  1929. make_wrapper ()
  1930. {
  1931. local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5;
  1932. local tmpwrapper=$(emktemp);
  1933. has "${EAPI:-0}" 0 1 2 && local EPREFIX="";
  1934. ( echo '#!/bin/sh';
  1935. if [[ -n ${libdir} ]]; then
  1936. local var;
  1937. if [[ ${CHOST} == *-darwin* ]]; then
  1938. var=DYLD_LIBRARY_PATH;
  1939. else
  1940. var=LD_LIBRARY_PATH;
  1941. fi;
  1942. cat <<-EOF
  1943. if [ "\${${var}+set}" = "set" ] ; then
  1944. export ${var}="\${${var}}:${EPREFIX}${libdir}"
  1945. else
  1946. export ${var}="${EPREFIX}${libdir}"
  1947. fi
  1948. EOF
  1949. fi
  1950. [[ -n ${chdir} ]] && printf 'cd "%s" &&\n' "${EPREFIX}${chdir}";
  1951. printf 'exec %s "$@"\n' "${bin/#\//${EPREFIX}/}" ) > "${tmpwrapper}";
  1952. chmod go+rx "${tmpwrapper}";
  1953. if [[ -n ${path} ]]; then
  1954. ( exeopts -m 0755;
  1955. exeinto "${path}";
  1956. newexe "${tmpwrapper}" "${wrapper}" ) || die;
  1957. else
  1958. newbin "${tmpwrapper}" "${wrapper}" || die;
  1959. fi
  1960. }
  1961. multilib_env ()
  1962. {
  1963. local CTARGET=${1:-${CTARGET}};
  1964. local cpu=${CTARGET%%*-};
  1965. case ${cpu} in
  1966. aarch64*)
  1967. export CFLAGS_arm=${CFLAGS_arm-};
  1968. case ${cpu} in
  1969. aarch64*be)
  1970. export CHOST_arm="armv8b-${CTARGET#*-}"
  1971. ;;
  1972. *)
  1973. export CHOST_arm="armv8l-${CTARGET#*-}"
  1974. ;;
  1975. esac;
  1976. CHOST_arm=${CHOST_arm/%-gnu/-gnueabi};
  1977. export CTARGET_arm=${CHOST_arm};
  1978. export LIBDIR_arm="lib";
  1979. export CFLAGS_arm64=${CFLAGS_arm64-};
  1980. export CHOST_arm64=${CTARGET};
  1981. export CTARGET_arm64=${CHOST_arm64};
  1982. export LIBDIR_arm64="lib64";
  1983. : ${MULTILIB_ABIS=arm64};
  1984. : ${DEFAULT_ABI=arm64}
  1985. ;;
  1986. x86_64*)
  1987. export CFLAGS_x86=${CFLAGS_x86--m32};
  1988. export CHOST_x86=${CTARGET/x86_64/i686};
  1989. CHOST_x86=${CHOST_x86/%-gnux32/-gnu};
  1990. export CTARGET_x86=${CHOST_x86};
  1991. if [[ ${SYMLINK_LIB} == "yes" ]]; then
  1992. export LIBDIR_x86="lib32";
  1993. else
  1994. export LIBDIR_x86="lib";
  1995. fi;
  1996. export CFLAGS_amd64=${CFLAGS_amd64--m64};
  1997. export CHOST_amd64=${CTARGET/%-gnux32/-gnu};
  1998. export CTARGET_amd64=${CHOST_amd64};
  1999. export LIBDIR_amd64="lib64";
  2000. export CFLAGS_x32=${CFLAGS_x32--mx32};
  2001. export CHOST_x32=${CTARGET/%-gnu/-gnux32};
  2002. export CTARGET_x32=${CHOST_x32};
  2003. export LIBDIR_x32="libx32";
  2004. case ${CTARGET} in
  2005. *-gnux32)
  2006. : ${MULTILIB_ABIS=x32 amd64 x86};
  2007. : ${DEFAULT_ABI=x32}
  2008. ;;
  2009. *)
  2010. : ${MULTILIB_ABIS=amd64 x86};
  2011. : ${DEFAULT_ABI=amd64}
  2012. ;;
  2013. esac
  2014. ;;
  2015. mips64* | mipsisa64*)
  2016. export CFLAGS_o32=${CFLAGS_o32--mabi=32};
  2017. export CHOST_o32=${CTARGET/mips64/mips};
  2018. export CHOST_o32=${CHOST_o32/mipsisa64/mipsisa32};
  2019. export CTARGET_o32=${CHOST_o32};
  2020. export LIBDIR_o32="lib";
  2021. export CFLAGS_n32=${CFLAGS_n32--mabi=n32};
  2022. export CHOST_n32=${CTARGET};
  2023. export CTARGET_n32=${CHOST_n32};
  2024. export LIBDIR_n32="lib32";
  2025. export CFLAGS_n64=${CFLAGS_n64--mabi=64};
  2026. export CHOST_n64=${CTARGET};
  2027. export CTARGET_n64=${CHOST_n64};
  2028. export LIBDIR_n64="lib64";
  2029. : ${MULTILIB_ABIS=n64 n32 o32};
  2030. : ${DEFAULT_ABI=n32}
  2031. ;;
  2032. powerpc64*)
  2033. export CFLAGS_ppc=${CFLAGS_ppc--m32};
  2034. export CHOST_ppc=${CTARGET/powerpc64/powerpc};
  2035. export CTARGET_ppc=${CHOST_ppc};
  2036. export LIBDIR_ppc="lib";
  2037. export CFLAGS_ppc64=${CFLAGS_ppc64--m64};
  2038. export CHOST_ppc64=${CTARGET};
  2039. export CTARGET_ppc64=${CHOST_ppc64};
  2040. export LIBDIR_ppc64="lib64";
  2041. : ${MULTILIB_ABIS=ppc64 ppc};
  2042. : ${DEFAULT_ABI=ppc64}
  2043. ;;
  2044. s390x*)
  2045. export CFLAGS_s390=${CFLAGS_s390--m31};
  2046. export CHOST_s390=${CTARGET/s390x/s390};
  2047. export CTARGET_s390=${CHOST_s390};
  2048. export LIBDIR_s390="lib";
  2049. export CFLAGS_s390x=${CFLAGS_s390x--m64};
  2050. export CHOST_s390x=${CTARGET};
  2051. export CTARGET_s390x=${CHOST_s390x};
  2052. export LIBDIR_s390x="lib64";
  2053. : ${MULTILIB_ABIS=s390x s390};
  2054. : ${DEFAULT_ABI=s390x}
  2055. ;;
  2056. sparc64*)
  2057. export CFLAGS_sparc32=${CFLAGS_sparc32--m32};
  2058. export CHOST_sparc32=${CTARGET/sparc64/sparc};
  2059. export CTARGET_sparc32=${CHOST_sparc32};
  2060. export LIBDIR_sparc32="lib";
  2061. export CFLAGS_sparc64=${CFLAGS_sparc64--m64};
  2062. export CHOST_sparc64=${CTARGET};
  2063. export CTARGET_sparc64=${CHOST_sparc64};
  2064. export LIBDIR_sparc64="lib64";
  2065. : ${MULTILIB_ABIS=sparc64 sparc32};
  2066. : ${DEFAULT_ABI=sparc64}
  2067. ;;
  2068. *)
  2069. : ${MULTILIB_ABIS=default};
  2070. : ${DEFAULT_ABI=default}
  2071. ;;
  2072. esac;
  2073. export MULTILIB_ABIS DEFAULT_ABI
  2074. }
  2075. multilib_toolchain_setup ()
  2076. {
  2077. local v vv;
  2078. export ABI=$1;
  2079. if [[ ${_DEFAULT_ABI_SAVED} == "true" ]]; then
  2080. for v in CHOST CBUILD AS CC CXX F77 FC LD PKG_CONFIG_{LIBDIR,PATH};
  2081. do
  2082. vv="_abi_saved_${v}";
  2083. [[ ${!vv+set} == "set" ]] && export ${v}="${!vv}" || unset ${v};
  2084. unset ${vv};
  2085. done;
  2086. unset _DEFAULT_ABI_SAVED;
  2087. fi;
  2088. if [[ ${ABI} != ${DEFAULT_ABI} ]]; then
  2089. for v in CHOST CBUILD AS CC CXX F77 FC LD PKG_CONFIG_{LIBDIR,PATH};
  2090. do
  2091. vv="_abi_saved_${v}";
  2092. [[ ${!v+set} == "set" ]] && export ${vv}="${!v}" || unset ${vv};
  2093. done;
  2094. export _DEFAULT_ABI_SAVED="true";
  2095. if [[ ${CBUILD} == "${CHOST}" ]]; then
  2096. export CBUILD=$(get_abi_CHOST $1);
  2097. fi;
  2098. export CHOST=$(get_abi_CHOST ${DEFAULT_ABI});
  2099. export CC="$(tc-getCC) $(get_abi_CFLAGS)";
  2100. export CXX="$(tc-getCXX) $(get_abi_CFLAGS)";
  2101. export F77="$(tc-getF77) $(get_abi_CFLAGS)";
  2102. export FC="$(tc-getFC) $(get_abi_CFLAGS)";
  2103. export LD="$(tc-getLD) $(get_abi_LDFLAGS)";
  2104. export CHOST=$(get_abi_CHOST $1);
  2105. export PKG_CONFIG_LIBDIR=${EPREFIX}/usr/$(get_libdir)/pkgconfig;
  2106. export PKG_CONFIG_PATH=${EPREFIX}/usr/share/pkgconfig;
  2107. fi
  2108. }
  2109. newicon ()
  2110. {
  2111. _iconins ${FUNCNAME} "$@"
  2112. }
  2113. newmenu ()
  2114. {
  2115. ( insopts -m 0644;
  2116. insinto /usr/share/applications;
  2117. newins "$@" )
  2118. }
  2119. no-as-needed ()
  2120. {
  2121. case $($(tc-getLD) -v 2>&1 </dev/null) in
  2122. *GNU*)
  2123. echo "-Wl,--no-as-needed"
  2124. ;;
  2125. esac
  2126. }
  2127. number_abis ()
  2128. {
  2129. set -- `get_install_abis`;
  2130. echo $#
  2131. }
  2132. optfeature ()
  2133. {
  2134. debug-print-function ${FUNCNAME} "$@";
  2135. local i j msg;
  2136. local desc=$1;
  2137. local flag=0;
  2138. shift;
  2139. for i in "$@";
  2140. do
  2141. for j in ${i};
  2142. do
  2143. if has_version "${j}"; then
  2144. flag=1;
  2145. else
  2146. flag=0;
  2147. break;
  2148. fi;
  2149. done;
  2150. if [[ ${flag} -eq 1 ]]; then
  2151. break;
  2152. fi;
  2153. done;
  2154. if [[ ${flag} -eq 0 ]]; then
  2155. for i in "$@";
  2156. do
  2157. msg=" ";
  2158. for j in ${i};
  2159. do
  2160. msg+=" ${j} and";
  2161. done;
  2162. msg="${msg:0: -4} for ${desc}";
  2163. elog "${msg}";
  2164. done;
  2165. fi
  2166. }
  2167. path_exists ()
  2168. {
  2169. eerror "path_exists has been removed. Please see the following post";
  2170. eerror "for a replacement snippet:";
  2171. eerror "https://blogs.gentoo.org/mgorny/2018/08/09/inlining-path_exists/";
  2172. die "path_exists is banned"
  2173. }
  2174. pkg_nofetch ()
  2175. {
  2176. default
  2177. }
  2178. pkg_postinst ()
  2179. {
  2180. [[ -e ${EROOT}/etc/env.d/binutils/config-${CTARGET} ]] && return 0;
  2181. binutils-config ${CTARGET}-${PV}
  2182. }
  2183. pkg_postrm ()
  2184. {
  2185. local current_profile=$(binutils-config -c ${CTARGET});
  2186. if [[ ! -e ${EPREFIX}${BINPATH}/ld ]] && [[ ${current_profile} == ${CTARGET}-${PV} ]]; then
  2187. local choice=$(binutils-config -l | grep ${CTARGET} | awk '{print $2}');
  2188. choice=${choice//'
  2189. '/ };
  2190. choice=${choice/* };
  2191. if [[ -z ${choice} ]]; then
  2192. binutils-config -u ${CTARGET};
  2193. else
  2194. binutils-config ${choice};
  2195. fi;
  2196. else
  2197. if [[ $(CHOST=${CTARGET} binutils-config -c) == ${CTARGET}-${PV} ]]; then
  2198. binutils-config ${CTARGET}-${PV};
  2199. fi;
  2200. fi
  2201. }
  2202. preserve_old_lib ()
  2203. {
  2204. if [[ ${EBUILD_PHASE} != "preinst" ]]; then
  2205. eerror "preserve_old_lib() must be called from pkg_preinst() only";
  2206. die "Invalid preserve_old_lib() usage";
  2207. fi;
  2208. [[ -z $1 ]] && die "Usage: preserve_old_lib <library to preserve> [more libraries to preserve]";
  2209. has preserve-libs ${FEATURES} && return 0;
  2210. has "${EAPI:-0}" 0 1 2 && local ED=${D} EROOT=${ROOT};
  2211. local lib dir;
  2212. for lib in "$@";
  2213. do
  2214. [[ -e ${EROOT}/${lib} ]] || continue;
  2215. dir=${lib%/*};
  2216. dodir ${dir} || die "dodir ${dir} failed";
  2217. cp "${EROOT}"/${lib} "${ED}"/${lib} || die "cp ${lib} failed";
  2218. touch "${ED}"/${lib};
  2219. done
  2220. }
  2221. preserve_old_lib_notify ()
  2222. {
  2223. if [[ ${EBUILD_PHASE} != "postinst" ]]; then
  2224. eerror "preserve_old_lib_notify() must be called from pkg_postinst() only";
  2225. die "Invalid preserve_old_lib_notify() usage";
  2226. fi;
  2227. has preserve-libs ${FEATURES} && return 0;
  2228. has "${EAPI:-0}" 0 1 2 && local EROOT=${ROOT};
  2229. local lib notice=0;
  2230. for lib in "$@";
  2231. do
  2232. [[ -e ${EROOT}/${lib} ]] || continue;
  2233. if [[ ${notice} -eq 0 ]]; then
  2234. notice=1;
  2235. ewarn "Old versions of installed libraries were detected on your system.";
  2236. ewarn "In order to avoid breaking packages that depend on these old libs,";
  2237. ewarn "the libraries are not being removed. You need to run revdep-rebuild";
  2238. ewarn "in order to remove these old dependencies. If you do not have this";
  2239. ewarn "helper program, simply emerge the 'gentoolkit' package.";
  2240. ewarn;
  2241. fi;
  2242. ewarn " # revdep-rebuild --library '${lib}' && rm '${lib}'";
  2243. done
  2244. }
  2245. prune_libtool_files ()
  2246. {
  2247. debug-print-function ${FUNCNAME} "$@";
  2248. local removing_all removing_modules opt;
  2249. for opt in "$@";
  2250. do
  2251. case "${opt}" in
  2252. --all)
  2253. removing_all=1;
  2254. removing_modules=1
  2255. ;;
  2256. --modules)
  2257. removing_modules=1
  2258. ;;
  2259. *)
  2260. die "Invalid argument to ${FUNCNAME}(): ${opt}"
  2261. ;;
  2262. esac;
  2263. done;
  2264. local f;
  2265. local queue=();
  2266. while IFS= read -r -d '' f; do
  2267. local archivefile=${f/%.la/.a};
  2268. if ! sed -n -e '/^# Generated by .*libtool/q0;4q1' "${f}"; then
  2269. continue;
  2270. fi;
  2271. [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed';
  2272. local reason= pkgconfig_scanned=;
  2273. local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}");
  2274. if [[ ${snotlink} == yes ]]; then
  2275. if [[ -f ${archivefile} ]]; then
  2276. einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)";
  2277. queue+=("${archivefile}");
  2278. fi;
  2279. if [[ -n ${removing_modules} ]]; then
  2280. reason='module';
  2281. fi;
  2282. else
  2283. if [[ -n ${removing_all} ]]; then
  2284. reason='requested';
  2285. else
  2286. if [[ ! -f ${archivefile} ]]; then
  2287. reason='no static archive';
  2288. else
  2289. if [[ ! -n $(sed -nre "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" "${f}") ]]; then
  2290. reason='no libs & flags';
  2291. else
  2292. if [[ ! -n ${pkgconfig_scanned} ]]; then
  2293. local pc_libs=();
  2294. if [[ ! -n ${removing_all} ]]; then
  2295. local pc;
  2296. local tf=${T}/prune-lt-files.pc;
  2297. local pkgconf=$(tc-getPKG_CONFIG);
  2298. while IFS= read -r -d '' pc; do
  2299. local arg libs;
  2300. if ${pkgconf} --exists "${pc}" &> /dev/null; then
  2301. sed -e '/^Requires:/d' "${pc}" > "${tf}";
  2302. libs=$(${pkgconf} --libs "${tf}");
  2303. else
  2304. libs=$(sed -ne 's/^Libs://p' "${pc}");
  2305. fi;
  2306. for arg in ${libs};
  2307. do
  2308. if [[ ${arg} == -l* ]]; then
  2309. if [[ ${arg} == '*$*' ]]; then
  2310. eerror "${FUNCNAME}: variable substitution likely failed in ${pc}";
  2311. eerror "(arg: ${arg})";
  2312. eerror "Most likely, you need to add virtual/pkgconfig to DEPEND.";
  2313. die "${FUNCNAME}: unsubstituted variable found in .pc";
  2314. fi;
  2315. pc_libs+=(lib${arg#-l}.la);
  2316. fi;
  2317. done;
  2318. done < <(find "${D}" -type f -name '*.pc' -print0);
  2319. rm -f "${tf}";
  2320. fi;
  2321. pkgconfig_scanned=1;
  2322. fi;
  2323. has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc';
  2324. fi;
  2325. fi;
  2326. fi;
  2327. fi;
  2328. if [[ -n ${reason} ]]; then
  2329. einfo "Removing unnecessary ${f#${D%/}} (${reason})";
  2330. queue+=("${f}");
  2331. fi;
  2332. done < <(find "${D}" -xtype f -name '*.la' -print0);
  2333. if [[ -n ${queue[@]} ]]; then
  2334. rm -f "${queue[@]}";
  2335. fi
  2336. }
  2337. raw-ldflags ()
  2338. {
  2339. local x input="$@";
  2340. [[ -z ${input} ]] && input=${LDFLAGS};
  2341. set --;
  2342. for x in ${input};
  2343. do
  2344. case ${x} in
  2345. -Wl,*)
  2346. x=${x#-Wl,};
  2347. set -- "$@" ${x//,/ }
  2348. ;;
  2349. *)
  2350. ;;
  2351. esac;
  2352. done;
  2353. echo "$@"
  2354. }
  2355. replace-cpu-flags ()
  2356. {
  2357. local newcpu="$#";
  2358. newcpu="${!newcpu}";
  2359. while [ $# -gt 1 ]; do
  2360. replace-flags "-march=${1}" "-march=${newcpu}";
  2361. replace-flags "-mcpu=${1}" "-mcpu=${newcpu}";
  2362. replace-flags "-mtune=${1}" "-mtune=${newcpu}";
  2363. shift;
  2364. done;
  2365. return 0
  2366. }
  2367. replace-flags ()
  2368. {
  2369. [[ $# != 2 ]] && die "Usage: replace-flags <old flag> <new flag>";
  2370. local f var new;
  2371. for var in $(all-flag-vars);
  2372. do
  2373. new=();
  2374. for f in ${!var};
  2375. do
  2376. [[ ${f} == ${1} ]] && f=${2};
  2377. new+=("${f}");
  2378. done;
  2379. export ${var}="${new[*]}";
  2380. done;
  2381. return 0
  2382. }
  2383. replace-sparc64-flags ()
  2384. {
  2385. local SPARC64_CPUS="ultrasparc3 ultrasparc v9";
  2386. if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then
  2387. for x in ${SPARC64_CPUS};
  2388. do
  2389. CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}";
  2390. done;
  2391. else
  2392. for x in ${SPARC64_CPUS};
  2393. do
  2394. CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}";
  2395. done;
  2396. fi;
  2397. if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then
  2398. for x in ${SPARC64_CPUS};
  2399. do
  2400. CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}";
  2401. done;
  2402. else
  2403. for x in ${SPARC64_CPUS};
  2404. do
  2405. CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}";
  2406. done;
  2407. fi;
  2408. export CFLAGS CXXFLAGS
  2409. }
  2410. replace_all_version_separators ()
  2411. {
  2412. local c=($(get_all_version_components "${2:-${PV}}"));
  2413. c=${c[@]//[-._]/$1};
  2414. echo ${c// }
  2415. }
  2416. replace_version_separator ()
  2417. {
  2418. eshopts_push -s extglob;
  2419. local w c v="${3:-${PV}}";
  2420. declare -i i found=0;
  2421. w=${1:-1};
  2422. c=($(get_all_version_components ${v}));
  2423. if [[ ${w} != *[[:digit:]]* ]]; then
  2424. for ((i = 0; i < ${#c[@]}; i++))
  2425. do
  2426. if [[ ${c[i]} == ${w} ]]; then
  2427. c[i]=${2};
  2428. break;
  2429. fi;
  2430. done;
  2431. else
  2432. for ((i = 0; i < ${#c[@]}; i++))
  2433. do
  2434. if [[ -n "${c[i]//[^-._]}" ]]; then
  2435. found+=1;
  2436. if ((found == w)); then
  2437. c[i]=${2};
  2438. break;
  2439. fi;
  2440. fi;
  2441. done;
  2442. fi;
  2443. c=${c[*]};
  2444. echo ${c// };
  2445. eshopts_pop
  2446. }
  2447. setup-allowed-flags ()
  2448. {
  2449. ALLOWED_FLAGS=(-pipe -O '-O[12sg]' -mcpu -march -mtune '-fstack-protector*' '-fsanitize*' '-fstack-check*' -fno-stack-check -fbounds-check -fbounds-checking -fno-strict-overflow -fno-PIE -fno-pie -nopie -no-pie -fno-unit-at-a-time -g '-g[0-9]' -ggdb '-ggdb[0-9]' '-gdwarf-*' gstabs -gstabs+ -gz -fno-ident -fpermissive -frecord-gcc-switches '-fdiagnostics*' '-fplugin*' '-W*' -w '-[DUILR]*' '-Wl,*' '-fuse-ld');
  2450. ALLOWED_FLAGS+=('-fno-stack-protector*' '-fabi-version=*' -fno-strict-aliasing -fno-bounds-check -fno-bounds-checking -fstrict-overflow -fno-omit-frame-pointer '-fno-builtin*');
  2451. ALLOWED_FLAGS+=(-mregparm -mno-app-regs -mapp-regs -mno-mmx -mno-sse -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4 -mno-sse4.1 -mno-sse4.2 -mno-avx -mno-aes -mno-pclmul -mno-sse4a -mno-3dnow -mno-popcnt -mno-abm -mips1 -mips2 -mips3 -mips4 -mips32 -mips64 -mips16 -mplt -msoft-float -mno-soft-float -mhard-float -mno-hard-float -mfpu -mieee -mieee-with-inexact -mschedule -mfloat-gprs -mspe -mno-spe -mtls-direct-seg-refs -mno-tls-direct-seg-refs -mflat -mno-flat -mno-faster-structs -mfaster-structs -m32 -m64 -mx32 -mabi -mlittle-endian -mbig-endian -EL -EB -fPIC -mlive-g0 -mcmodel -mstack-bias -mno-stack-bias -msecure-plt '-m*-toc' -mfloat-abi -mfix-r10000 -mno-fix-r10000 -mthumb -marm -mno-fma4 -mno-movbe -mno-xop -mno-lwp -mno-fsgsbase -mno-rdrnd -mno-f16c -mno-bmi -mno-tbm -mno-avx2 -mno-bmi2 -mno-fma -mno-lzcnt -mno-fxsr -mno-hle -mno-rtm -mno-xsave -mno-xsaveopt -mno-avx512cd -mno-avx512er -mno-avx512f -mno-avx512pf -mno-sha)
  2452. }
  2453. src_compile ()
  2454. {
  2455. cd "${MY_BUILDDIR}";
  2456. emake tooldir="${EPREFIX}${TOOLPATH}" all;
  2457. if use doc; then
  2458. emake info;
  2459. fi;
  2460. find . -name '*.1' -a -size 0 -delete
  2461. }
  2462. src_configure ()
  2463. {
  2464. LIBPATH=/usr/$(get_libdir)/binutils/${CTARGET}/${PV};
  2465. INCPATH=${LIBPATH}/include;
  2466. DATAPATH=/usr/share/binutils-data/${CTARGET}/${PV};
  2467. if is_cross; then
  2468. TOOLPATH=/usr/${CHOST}/${CTARGET};
  2469. else
  2470. TOOLPATH=/usr/${CTARGET};
  2471. fi;
  2472. BINPATH=${TOOLPATH}/binutils-bin/${PV};
  2473. strip-linguas -u */po;
  2474. strip-flags;
  2475. local x;
  2476. echo;
  2477. for x in CATEGORY CBUILD CHOST CTARGET CFLAGS LDFLAGS;
  2478. do
  2479. einfo "$(printf '%10s' ${x}:) ${!x}";
  2480. done;
  2481. echo;
  2482. cd "${MY_BUILDDIR}";
  2483. local myconf=();
  2484. if use cxx; then
  2485. myconf+=(--enable-gold);
  2486. myconf+=(--enable-plugins);
  2487. fi;
  2488. if use nls; then
  2489. myconf+=(--without-included-gettext);
  2490. else
  2491. myconf+=(--disable-nls);
  2492. fi;
  2493. myconf+=(--with-system-zlib);
  2494. case $(tc-arch) in
  2495. ppc | sparc | x86)
  2496. myconf+=(--enable-64-bit-bfd)
  2497. ;;
  2498. esac;
  2499. use multitarget && myconf+=(--enable-targets=all --enable-64-bit-bfd);
  2500. [[ -n ${CBUILD} ]] && myconf+=(--build=${CBUILD});
  2501. is_cross && myconf+=(--with-sysroot="${EPREFIX}"/usr/${CTARGET} --enable-poison-system-directories);
  2502. has_version ">=${CATEGORY}/glibc-2.5" && myconf+=(--enable-secureplt);
  2503. has_version ">=sys-libs/glibc-2.5" && myconf+=(--enable-secureplt);
  2504. if [[ $(tc-arch) != mips ]]; then
  2505. myconf+=(--enable-default-hash-style=gnu);
  2506. fi;
  2507. myconf+=(--prefix="${EPREFIX}"/usr --host=${CHOST} --target=${CTARGET} --datadir="${EPREFIX}"${DATAPATH} --datarootdir="${EPREFIX}"${DATAPATH} --infodir="${EPREFIX}"${DATAPATH}/info --mandir="${EPREFIX}"${DATAPATH}/man --bindir="${EPREFIX}"${BINPATH} --libdir="${EPREFIX}"${LIBPATH} --libexecdir="${EPREFIX}"${LIBPATH} --includedir="${EPREFIX}"${INCPATH} --enable-obsolete --enable-shared --enable-threads --enable-relro --enable-install-libiberty --disable-werror --with-bugurl="$(toolchain-binutils_bugurl)" --with-pkgversion="$(toolchain-binutils_pkgversion)" $(use_enable static-libs static) ${EXTRA_ECONF} --disable-{gdb,libdecnumber,readline,sim} --without-stage1-ldflags --with-extra-soversion-suffix=gentoo-${CATEGORY}-${PN}-$(usex multitarget mt st));
  2508. echo ./configure "${myconf[@]}";
  2509. "${S}"/configure "${myconf[@]}" || die;
  2510. if ! use doc; then
  2511. sed -i -e '/^MAKEINFO/s:=.*:= true:' Makefile || die;
  2512. fi
  2513. }
  2514. src_install ()
  2515. {
  2516. local x d;
  2517. cd "${MY_BUILDDIR}";
  2518. emake DESTDIR="${D}" tooldir="${EPREFIX}${LIBPATH}" install;
  2519. rm -rf "${ED}"/${LIBPATH}/bin;
  2520. use static-libs || find "${ED}" -name '*.la' -delete;
  2521. cd "${ED}"/${LIBPATH};
  2522. for d in ../*;
  2523. do
  2524. [[ ${d} == ../${PV} ]] && continue;
  2525. mv ${d}/* . || die;
  2526. rmdir ${d} || die;
  2527. done;
  2528. if is_cross; then
  2529. cd "${ED}"/${BINPATH};
  2530. for x in *;
  2531. do
  2532. mv ${x} ${x/${CTARGET}-};
  2533. done;
  2534. if [[ -d ${ED}/usr/${CHOST}/${CTARGET} ]]; then
  2535. mv "${ED}"/usr/${CHOST}/${CTARGET}/include "${ED}"/${INCPATH};
  2536. mv "${ED}"/usr/${CHOST}/${CTARGET}/lib/* "${ED}"/${LIBPATH}/;
  2537. rm -r "${ED}"/usr/${CHOST}/{include,lib};
  2538. fi;
  2539. fi;
  2540. insinto ${INCPATH};
  2541. local libiberty_headers=(demangle.h dyn-string.h fibheap.h hashtab.h libiberty.h objalloc.h splay-tree.h);
  2542. doins "${libiberty_headers[@]/#/${S}/include/}" || die;
  2543. if [[ -d ${ED}/${LIBPATH}/lib ]]; then
  2544. mv "${ED}"/${LIBPATH}/lib/* "${ED}"/${LIBPATH}/;
  2545. rm -r "${ED}"/${LIBPATH}/lib;
  2546. fi;
  2547. insinto /etc/env.d/binutils;
  2548. cat > "${T}"/env.d <<-EOF
  2549. TARGET="${CTARGET}"
  2550. VER="${PV}"
  2551. LIBPATH="${EPREFIX}${LIBPATH}"
  2552. EOF
  2553. newins "${T}"/env.d ${CTARGET}-${PV};
  2554. if ! is_cross; then
  2555. cd "${S}";
  2556. dodoc README;
  2557. docinto bfd;
  2558. dodoc bfd/ChangeLog* bfd/README bfd/PORTING bfd/TODO;
  2559. docinto binutils;
  2560. dodoc binutils/ChangeLog binutils/NEWS binutils/README;
  2561. docinto gas;
  2562. dodoc gas/ChangeLog* gas/CONTRIBUTORS gas/NEWS gas/README*;
  2563. docinto gprof;
  2564. dodoc gprof/ChangeLog* gprof/TEST gprof/TODO gprof/bbconv.pl;
  2565. docinto ld;
  2566. dodoc ld/ChangeLog* ld/README ld/NEWS ld/TODO;
  2567. docinto libiberty;
  2568. dodoc libiberty/ChangeLog* libiberty/README;
  2569. docinto opcodes;
  2570. dodoc opcodes/ChangeLog*;
  2571. fi;
  2572. rm -f "${ED}"/${DATAPATH}/info/{dir,configure.info,standards.info};
  2573. find "${ED}" -depth -type d -exec rmdir {} + 2> /dev/null
  2574. }
  2575. src_prepare ()
  2576. {
  2577. if [[ ! -z ${PATCH_VER} ]]; then
  2578. einfo "Applying binutils-${PATCH_BINUTILS_VER} patchset ${PATCH_VER}";
  2579. eapply "${WORKDIR}/patch"/*.patch;
  2580. fi;
  2581. if [[ ${CTARGET} == *-uclibc* ]]; then
  2582. if grep -qs 'linux-gnu' "${S}"/ltconfig; then
  2583. die "sorry, but this binutils doesn't yet support uClibc :(";
  2584. fi;
  2585. fi;
  2586. sed -i -e 's:@bfdlibdir@:@libdir@:g' -e 's:@bfdincludedir@:@includedir@:g' {bfd,opcodes}/Makefile.in || die;
  2587. if [[ -e ${FILESDIR}/binutils-configure-LANG.patch ]]; then
  2588. einfo "Fixing misc issues in configure files";
  2589. for f in $(find "${S}" -name configure -exec grep -l 'autoconf version 2.13' {} +);
  2590. do
  2591. ebegin " Updating ${f/${S}\/}";
  2592. patch "${f}" "${FILESDIR}"/binutils-configure-LANG.patch &> "${T}"/configure-patch.log || eerror "Please file a bug about this";
  2593. eend $?;
  2594. done;
  2595. fi;
  2596. if [[ -e libiberty/testsuite/test-demangle.c ]]; then
  2597. sed -i 's:\<getline\>:get_line:g' libiberty/testsuite/test-demangle.c;
  2598. fi;
  2599. default;
  2600. gnuconfig_update;
  2601. elibtoolize --portage --no-uclibc
  2602. }
  2603. src_test ()
  2604. {
  2605. cd "${MY_BUILDDIR}";
  2606. emake -k check
  2607. }
  2608. src_unpack ()
  2609. {
  2610. case ${PV} in
  2611. *9999)
  2612. git-r3_src_unpack
  2613. ;;
  2614. *)
  2615. ;;
  2616. esac;
  2617. default;
  2618. mkdir -p "${MY_BUILDDIR}"
  2619. }
  2620. strip-flags ()
  2621. {
  2622. local x y var;
  2623. local ALLOWED_FLAGS;
  2624. setup-allowed-flags;
  2625. set -f;
  2626. for var in $(all-flag-vars);
  2627. do
  2628. local new=();
  2629. for x in ${!var};
  2630. do
  2631. local flag=${x%%=*};
  2632. for y in "${ALLOWED_FLAGS[@]}";
  2633. do
  2634. if [[ -z ${flag%%${y}} ]]; then
  2635. new+=("${x}");
  2636. break;
  2637. fi;
  2638. done;
  2639. done;
  2640. if _is_flagq ${var} "-O*" && ! _is_flagq new "-O*"; then
  2641. new+=(-O2);
  2642. fi;
  2643. if [[ ${!var} != "${new[*]}" ]]; then
  2644. einfo "strip-flags: ${var}: changed '${!var}' to '${new[*]}'";
  2645. fi;
  2646. export ${var}="${new[*]}";
  2647. done;
  2648. set +f;
  2649. return 0
  2650. }
  2651. strip-linguas ()
  2652. {
  2653. local ls newls nols;
  2654. if [[ $1 == "-i" ]] || [[ $1 == "-u" ]]; then
  2655. local op=$1;
  2656. shift;
  2657. ls=$(find "$1" -name '*.po' -exec basename {} .po ';');
  2658. shift;
  2659. local d f;
  2660. for d in "$@";
  2661. do
  2662. if [[ ${op} == "-u" ]]; then
  2663. newls=${ls};
  2664. else
  2665. newls="";
  2666. fi;
  2667. for f in $(find "$d" -name '*.po' -exec basename {} .po ';');
  2668. do
  2669. if [[ ${op} == "-i" ]]; then
  2670. has ${f} ${ls} && newls="${newls} ${f}";
  2671. else
  2672. has ${f} ${ls} || newls="${newls} ${f}";
  2673. fi;
  2674. done;
  2675. ls=${newls};
  2676. done;
  2677. else
  2678. ls="$@";
  2679. fi;
  2680. nols="";
  2681. newls="";
  2682. for f in ${LINGUAS};
  2683. do
  2684. if has ${f} ${ls}; then
  2685. newls="${newls} ${f}";
  2686. else
  2687. nols="${nols} ${f}";
  2688. fi;
  2689. done;
  2690. [[ -n ${nols} ]] && einfo "Sorry, but ${PN} does not support the LINGUAS:" ${nols};
  2691. export LINGUAS=${newls:1}
  2692. }
  2693. strip-unsupported-flags ()
  2694. {
  2695. export CFLAGS=$(test-flags-CC ${CFLAGS});
  2696. export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS});
  2697. export FFLAGS=$(test-flags-F77 ${FFLAGS});
  2698. export FCFLAGS=$(test-flags-FC ${FCFLAGS});
  2699. export LDFLAGS=$(test-flags-CC ${LDFLAGS})
  2700. }
  2701. tc-arch ()
  2702. {
  2703. tc-ninja_magic_to_arch portage "$@"
  2704. }
  2705. tc-arch-kernel ()
  2706. {
  2707. tc-ninja_magic_to_arch kern "$@"
  2708. }
  2709. tc-check-openmp ()
  2710. {
  2711. if ! tc-has-openmp; then
  2712. eerror "Your current compiler does not support OpenMP!";
  2713. if tc-is-gcc; then
  2714. eerror "Enable OpenMP support by building sys-devel/gcc with USE=\"openmp\".";
  2715. else
  2716. if tc-is-clang; then
  2717. eerror "OpenMP support in sys-devel/clang is provided by sys-libs/libomp.";
  2718. fi;
  2719. fi;
  2720. die "Active compiler does not have required support for OpenMP";
  2721. fi
  2722. }
  2723. tc-cpp-is-true ()
  2724. {
  2725. local CONDITION=${1};
  2726. shift;
  2727. local RESULT=$($(tc-getTARGET_CPP) "${@}" -P - <<-EOF 2>/dev/null
  2728. #if ${CONDITION}
  2729. true
  2730. #endif
  2731. EOF
  2732. );
  2733. [[ ${RESULT} == true ]]
  2734. }
  2735. tc-detect-is-softfloat ()
  2736. {
  2737. [[ $(tc-getTARGET_CPP) == "gcc -E" ]] && return 1;
  2738. case ${CTARGET:-${CHOST}} in
  2739. *-newlib | *-elf | *-eabi)
  2740. return 1
  2741. ;;
  2742. arm*)
  2743. if tc-cpp-is-true "defined(__ARM_PCS_VFP)"; then
  2744. echo "no";
  2745. else
  2746. if tc-cpp-is-true "defined(__SOFTFP__)"; then
  2747. echo "yes";
  2748. else
  2749. echo "softfp";
  2750. fi;
  2751. fi;
  2752. return 0
  2753. ;;
  2754. *)
  2755. return 1
  2756. ;;
  2757. esac
  2758. }
  2759. tc-enables-pie ()
  2760. {
  2761. tc-cpp-is-true "defined(__PIE__)" ${CPPFLAGS} ${CFLAGS}
  2762. }
  2763. tc-enables-ssp ()
  2764. {
  2765. tc-cpp-is-true "defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS}
  2766. }
  2767. tc-enables-ssp-all ()
  2768. {
  2769. tc-cpp-is-true "defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS}
  2770. }
  2771. tc-enables-ssp-strong ()
  2772. {
  2773. tc-cpp-is-true "defined(__SSP_STRONG__) || defined(__SSP_ALL__)" ${CPPFLAGS} ${CFLAGS}
  2774. }
  2775. tc-endian ()
  2776. {
  2777. local host=$1;
  2778. [[ -z ${host} ]] && host=${CTARGET:-${CHOST}};
  2779. host=${host%%-*};
  2780. case ${host} in
  2781. aarch64*be)
  2782. echo big
  2783. ;;
  2784. aarch64)
  2785. echo little
  2786. ;;
  2787. alpha*)
  2788. echo little
  2789. ;;
  2790. arm*b*)
  2791. echo big
  2792. ;;
  2793. arm*)
  2794. echo little
  2795. ;;
  2796. cris*)
  2797. echo little
  2798. ;;
  2799. hppa*)
  2800. echo big
  2801. ;;
  2802. i?86*)
  2803. echo little
  2804. ;;
  2805. ia64*)
  2806. echo little
  2807. ;;
  2808. m68*)
  2809. echo big
  2810. ;;
  2811. mips*l*)
  2812. echo little
  2813. ;;
  2814. mips*)
  2815. echo big
  2816. ;;
  2817. powerpc*le)
  2818. echo little
  2819. ;;
  2820. powerpc*)
  2821. echo big
  2822. ;;
  2823. s390*)
  2824. echo big
  2825. ;;
  2826. sh*b*)
  2827. echo big
  2828. ;;
  2829. sh*)
  2830. echo little
  2831. ;;
  2832. sparc*)
  2833. echo big
  2834. ;;
  2835. x86_64*)
  2836. echo little
  2837. ;;
  2838. *)
  2839. echo wtf
  2840. ;;
  2841. esac
  2842. }
  2843. tc-env_build ()
  2844. {
  2845. tc-export_build_env;
  2846. CFLAGS=${BUILD_CFLAGS} CXXFLAGS=${BUILD_CXXFLAGS} CPPFLAGS=${BUILD_CPPFLAGS} LDFLAGS=${BUILD_LDFLAGS} AR=$(tc-getBUILD_AR) AS=$(tc-getBUILD_AS) CC=$(tc-getBUILD_CC) CPP=$(tc-getBUILD_CPP) CXX=$(tc-getBUILD_CXX) LD=$(tc-getBUILD_LD) NM=$(tc-getBUILD_NM) PKG_CONFIG=$(tc-getBUILD_PKG_CONFIG) RANLIB=$(tc-getBUILD_RANLIB) "$@"
  2847. }
  2848. tc-export ()
  2849. {
  2850. local var;
  2851. for var in "$@";
  2852. do
  2853. [[ $(type -t "tc-get${var}") != "function" ]] && die "tc-export: invalid export variable '${var}'";
  2854. "tc-get${var}" > /dev/null;
  2855. done
  2856. }
  2857. tc-export_build_env ()
  2858. {
  2859. tc-export "$@";
  2860. if tc-is-cross-compiler; then
  2861. : ${BUILD_CFLAGS:=-O1 -pipe};
  2862. : ${BUILD_CXXFLAGS:=-O1 -pipe};
  2863. : ${BUILD_CPPFLAGS:= };
  2864. : ${BUILD_LDFLAGS:= };
  2865. else
  2866. : ${BUILD_CFLAGS:=${CFLAGS}};
  2867. : ${BUILD_CXXFLAGS:=${CXXFLAGS}};
  2868. : ${BUILD_CPPFLAGS:=${CPPFLAGS}};
  2869. : ${BUILD_LDFLAGS:=${LDFLAGS}};
  2870. fi;
  2871. export BUILD_{C,CXX,CPP,LD}FLAGS;
  2872. local v;
  2873. for v in BUILD_{C,CXX,CPP,LD}FLAGS;
  2874. do
  2875. export ${v#BUILD_}_FOR_BUILD="${!v}";
  2876. done
  2877. }
  2878. tc-get-compiler-type ()
  2879. {
  2880. local code='
  2881. #if defined(__PATHSCALE__)
  2882. HAVE_PATHCC
  2883. #elif defined(__clang__)
  2884. HAVE_CLANG
  2885. #elif defined(__GNUC__)
  2886. HAVE_GCC
  2887. #endif
  2888. ';
  2889. local res=$($(tc-getCPP "$@") -E -P - <<<"${code}");
  2890. case ${res} in
  2891. *HAVE_PATHCC*)
  2892. echo pathcc
  2893. ;;
  2894. *HAVE_CLANG*)
  2895. echo clang
  2896. ;;
  2897. *HAVE_GCC*)
  2898. echo gcc
  2899. ;;
  2900. *)
  2901. echo unknown
  2902. ;;
  2903. esac
  2904. }
  2905. tc-getAR ()
  2906. {
  2907. tc-getPROG AR ar "$@"
  2908. }
  2909. tc-getAS ()
  2910. {
  2911. tc-getPROG AS as "$@"
  2912. }
  2913. tc-getBUILD_AR ()
  2914. {
  2915. tc-getBUILD_PROG AR ar "$@"
  2916. }
  2917. tc-getBUILD_AS ()
  2918. {
  2919. tc-getBUILD_PROG AS as "$@"
  2920. }
  2921. tc-getBUILD_CC ()
  2922. {
  2923. tc-getBUILD_PROG CC gcc "$@"
  2924. }
  2925. tc-getBUILD_CPP ()
  2926. {
  2927. tc-getBUILD_PROG CPP "$(tc-getBUILD_CC) -E" "$@"
  2928. }
  2929. tc-getBUILD_CXX ()
  2930. {
  2931. tc-getBUILD_PROG CXX g++ "$@"
  2932. }
  2933. tc-getBUILD_LD ()
  2934. {
  2935. tc-getBUILD_PROG LD ld "$@"
  2936. }
  2937. tc-getBUILD_NM ()
  2938. {
  2939. tc-getBUILD_PROG NM nm "$@"
  2940. }
  2941. tc-getBUILD_OBJCOPY ()
  2942. {
  2943. tc-getBUILD_PROG OBJCOPY objcopy "$@"
  2944. }
  2945. tc-getBUILD_PKG_CONFIG ()
  2946. {
  2947. tc-getBUILD_PROG PKG_CONFIG pkg-config "$@"
  2948. }
  2949. tc-getBUILD_PROG ()
  2950. {
  2951. local vars="BUILD_$1 $1_FOR_BUILD HOST$1";
  2952. tc-is-cross-compiler || vars+=" $1";
  2953. _tc-getPROG CBUILD "${vars}" "${@:2}"
  2954. }
  2955. tc-getBUILD_RANLIB ()
  2956. {
  2957. tc-getBUILD_PROG RANLIB ranlib "$@"
  2958. }
  2959. tc-getBUILD_STRIP ()
  2960. {
  2961. tc-getBUILD_PROG STRIP strip "$@"
  2962. }
  2963. tc-getCC ()
  2964. {
  2965. tc-getPROG CC gcc "$@"
  2966. }
  2967. tc-getCPP ()
  2968. {
  2969. tc-getPROG CPP "${CC:-gcc} -E" "$@"
  2970. }
  2971. tc-getCXX ()
  2972. {
  2973. tc-getPROG CXX g++ "$@"
  2974. }
  2975. tc-getDLLWRAP ()
  2976. {
  2977. tc-getPROG DLLWRAP dllwrap "$@"
  2978. }
  2979. tc-getF77 ()
  2980. {
  2981. tc-getPROG F77 gfortran "$@"
  2982. }
  2983. tc-getFC ()
  2984. {
  2985. tc-getPROG FC gfortran "$@"
  2986. }
  2987. tc-getGCJ ()
  2988. {
  2989. tc-getPROG GCJ gcj "$@"
  2990. }
  2991. tc-getGO ()
  2992. {
  2993. tc-getPROG GO gccgo "$@"
  2994. }
  2995. tc-getLD ()
  2996. {
  2997. tc-getPROG LD ld "$@"
  2998. }
  2999. tc-getNM ()
  3000. {
  3001. tc-getPROG NM nm "$@"
  3002. }
  3003. tc-getOBJCOPY ()
  3004. {
  3005. tc-getPROG OBJCOPY objcopy "$@"
  3006. }
  3007. tc-getOBJDUMP ()
  3008. {
  3009. tc-getPROG OBJDUMP objdump "$@"
  3010. }
  3011. tc-getPKG_CONFIG ()
  3012. {
  3013. tc-getPROG PKG_CONFIG pkg-config "$@"
  3014. }
  3015. tc-getPROG ()
  3016. {
  3017. _tc-getPROG CHOST "$@"
  3018. }
  3019. tc-getRANLIB ()
  3020. {
  3021. tc-getPROG RANLIB ranlib "$@"
  3022. }
  3023. tc-getRC ()
  3024. {
  3025. tc-getPROG RC windres "$@"
  3026. }
  3027. tc-getSTRIP ()
  3028. {
  3029. tc-getPROG STRIP strip "$@"
  3030. }
  3031. tc-getTARGET_CPP ()
  3032. {
  3033. if [[ -n ${CTARGET} ]]; then
  3034. _tc-getPROG CTARGET TARGET_CPP "gcc -E" "$@";
  3035. else
  3036. tc-getCPP "$@";
  3037. fi
  3038. }
  3039. tc-has-openmp ()
  3040. {
  3041. local base="${T}/test-tc-openmp";
  3042. cat > "${base}.c" <<-EOF
  3043. #include <omp.h>
  3044. int main() {
  3045. int nthreads, tid, ret = 0;
  3046. #pragma omp parallel private(nthreads, tid)
  3047. {
  3048. tid = omp_get_thread_num();
  3049. nthreads = omp_get_num_threads(); ret += tid + nthreads;
  3050. }
  3051. return ret;
  3052. }
  3053. EOF
  3054. $(tc-getCC "$@") -fopenmp "${base}.c" -o "${base}" &> /dev/null;
  3055. local ret=$?;
  3056. rm -f "${base}"*;
  3057. return ${ret}
  3058. }
  3059. tc-has-tls ()
  3060. {
  3061. local base="${T}/test-tc-tls";
  3062. cat > "${base}.c" <<-EOF
  3063. int foo(int *i) {
  3064. static __thread int j = 0;
  3065. return *i ? j : *i;
  3066. }
  3067. EOF
  3068. local flags;
  3069. case $1 in
  3070. -s)
  3071. flags="-S"
  3072. ;;
  3073. -c)
  3074. flags="-c"
  3075. ;;
  3076. -l)
  3077. ;;
  3078. -*)
  3079. die "Usage: tc-has-tls [-c|-l] [toolchain prefix]"
  3080. ;;
  3081. esac;
  3082. : ${flags:=-fPIC -shared -Wl,-z,defs};
  3083. [[ $1 == -* ]] && shift;
  3084. $(tc-getCC "$@") ${flags} "${base}.c" -o "${base}" &> /dev/null;
  3085. local ret=$?;
  3086. rm -f "${base}"*;
  3087. return ${ret}
  3088. }
  3089. tc-is-clang ()
  3090. {
  3091. [[ $(tc-get-compiler-type) == clang ]]
  3092. }
  3093. tc-is-cross-compiler ()
  3094. {
  3095. [[ ${CBUILD:-${CHOST}} != ${CHOST} ]]
  3096. }
  3097. tc-is-gcc ()
  3098. {
  3099. [[ $(tc-get-compiler-type) == gcc ]]
  3100. }
  3101. tc-is-softfloat ()
  3102. {
  3103. tc-detect-is-softfloat || tc-tuple-is-softfloat
  3104. }
  3105. tc-is-static-only ()
  3106. {
  3107. local host=${CTARGET:-${CHOST}};
  3108. [[ ${host} == *-mint* ]]
  3109. }
  3110. tc-ld-disable-gold ()
  3111. {
  3112. if ! tc-ld-is-gold "$@"; then
  3113. return;
  3114. fi;
  3115. ewarn "Forcing usage of the BFD linker instead of GOLD";
  3116. local ld=$(tc-getLD "$@");
  3117. local bfd_ld="${ld%% *}.bfd";
  3118. local path_ld=$(which "${bfd_ld}" 2>/dev/null);
  3119. [[ -e ${path_ld} ]] && export LD=${bfd_ld};
  3120. local fallback="true";
  3121. if tc-is-gcc; then
  3122. local major=$(gcc-major-version "$@");
  3123. local minor=$(gcc-minor-version "$@");
  3124. if [[ ${major} -gt 4 ]] || [[ ${major} -eq 4 && ${minor} -ge 8 ]]; then
  3125. export LDFLAGS="${LDFLAGS} -fuse-ld=bfd";
  3126. fallback="false";
  3127. fi;
  3128. else
  3129. if tc-is-clang; then
  3130. local major=$(clang-major-version "$@");
  3131. local minor=$(clang-minor-version "$@");
  3132. if [[ ${major} -gt 3 ]] || [[ ${major} -eq 3 && ${minor} -ge 5 ]]; then
  3133. export LDFLAGS="${LDFLAGS} -fuse-ld=bfd";
  3134. fallback="false";
  3135. fi;
  3136. fi;
  3137. fi;
  3138. if [[ ${fallback} == "true" ]]; then
  3139. if [[ -e ${path_ld} ]]; then
  3140. local d="${T}/bfd-linker";
  3141. mkdir -p "${d}";
  3142. ln -sf "${path_ld}" "${d}"/ld;
  3143. export LDFLAGS="${LDFLAGS} -B${d}";
  3144. else
  3145. die "unable to locate a BFD linker to bypass gold";
  3146. fi;
  3147. fi
  3148. }
  3149. tc-ld-is-gold ()
  3150. {
  3151. local out;
  3152. out=$($(tc-getLD "$@") --version 2>&1);
  3153. if [[ ${out} == *"GNU gold"* ]]; then
  3154. return 0;
  3155. fi;
  3156. local base="${T}/test-tc-gold";
  3157. cat > "${base}.c" <<-EOF
  3158. int main() { return 0; }
  3159. EOF
  3160. out=$($(tc-getCC "$@") ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -Wl,--version "${base}.c" -o "${base}" 2>&1);
  3161. rm -f "${base}"*;
  3162. if [[ ${out} == *"GNU gold"* ]]; then
  3163. return 0;
  3164. fi;
  3165. return 1
  3166. }
  3167. tc-ninja_magic_to_arch ()
  3168. {
  3169. function ninj ()
  3170. {
  3171. [[ ${type} == "kern" ]] && echo $1 || echo $2
  3172. };
  3173. local type=$1;
  3174. local host=$2;
  3175. [[ -z ${host} ]] && host=${CTARGET:-${CHOST}};
  3176. case ${host} in
  3177. aarch64*)
  3178. echo arm64
  3179. ;;
  3180. alpha*)
  3181. echo alpha
  3182. ;;
  3183. arm*)
  3184. echo arm
  3185. ;;
  3186. avr*)
  3187. ninj avr32 avr
  3188. ;;
  3189. bfin*)
  3190. ninj blackfin bfin
  3191. ;;
  3192. c6x*)
  3193. echo c6x
  3194. ;;
  3195. cris*)
  3196. echo cris
  3197. ;;
  3198. frv*)
  3199. echo frv
  3200. ;;
  3201. hexagon*)
  3202. echo hexagon
  3203. ;;
  3204. hppa*)
  3205. ninj parisc hppa
  3206. ;;
  3207. i?86*)
  3208. if [[ ${type} == "kern" && ${host} == *freebsd* ]]; then
  3209. echo i386;
  3210. else
  3211. echo x86;
  3212. fi
  3213. ;;
  3214. ia64*)
  3215. echo ia64
  3216. ;;
  3217. m68*)
  3218. echo m68k
  3219. ;;
  3220. metag*)
  3221. echo metag
  3222. ;;
  3223. microblaze*)
  3224. echo microblaze
  3225. ;;
  3226. mips*)
  3227. echo mips
  3228. ;;
  3229. nios2*)
  3230. echo nios2
  3231. ;;
  3232. nios*)
  3233. echo nios
  3234. ;;
  3235. or1k | or32*)
  3236. echo openrisc
  3237. ;;
  3238. powerpc*)
  3239. if [[ ${type} == "kern" ]]; then
  3240. echo powerpc;
  3241. else
  3242. if [[ ${host} == powerpc64* ]]; then
  3243. echo ppc64;
  3244. else
  3245. echo ppc;
  3246. fi;
  3247. fi
  3248. ;;
  3249. riscv*)
  3250. echo riscv
  3251. ;;
  3252. s390*)
  3253. echo s390
  3254. ;;
  3255. score*)
  3256. echo score
  3257. ;;
  3258. sh64*)
  3259. ninj sh64 sh
  3260. ;;
  3261. sh*)
  3262. echo sh
  3263. ;;
  3264. sparc64*)
  3265. ninj sparc64 sparc
  3266. ;;
  3267. sparc*)
  3268. [[ ${PROFILE_ARCH} == "sparc64" ]] && ninj sparc64 sparc || echo sparc
  3269. ;;
  3270. tile*)
  3271. echo tile
  3272. ;;
  3273. vax*)
  3274. echo vax
  3275. ;;
  3276. x86_64*freebsd*)
  3277. echo amd64
  3278. ;;
  3279. x86_64*)
  3280. if [[ ${type} == "kern" ]]; then
  3281. echo x86;
  3282. else
  3283. echo amd64;
  3284. fi
  3285. ;;
  3286. xtensa*)
  3287. echo xtensa
  3288. ;;
  3289. *)
  3290. echo unknown
  3291. ;;
  3292. esac
  3293. }
  3294. tc-stack-grows-down ()
  3295. {
  3296. case ${ARCH} in
  3297. hppa | metag)
  3298. return 1
  3299. ;;
  3300. esac;
  3301. return 0
  3302. }
  3303. tc-tuple-is-softfloat ()
  3304. {
  3305. local CTARGET=${CTARGET:-${CHOST}};
  3306. case ${CTARGET//_/-} in
  3307. bfin* | h8300*)
  3308. echo "only"
  3309. ;;
  3310. *-softfloat-*)
  3311. echo "yes"
  3312. ;;
  3313. *-softfp-*)
  3314. echo "softfp"
  3315. ;;
  3316. arm*-hardfloat-* | arm*eabihf)
  3317. echo "no"
  3318. ;;
  3319. *-newlib | *-elf | *-eabi)
  3320. echo "no"
  3321. ;;
  3322. arm*)
  3323. echo "yes"
  3324. ;;
  3325. *)
  3326. echo "no"
  3327. ;;
  3328. esac
  3329. }
  3330. test-flag-CC ()
  3331. {
  3332. test-flag-PROG "CC" c "$@"
  3333. }
  3334. test-flag-CXX ()
  3335. {
  3336. test-flag-PROG "CXX" c++ "$@"
  3337. }
  3338. test-flag-F77 ()
  3339. {
  3340. test-flag-PROG "F77" f77 "$@"
  3341. }
  3342. test-flag-FC ()
  3343. {
  3344. test-flag-PROG "FC" f95 "$@"
  3345. }
  3346. test-flag-PROG ()
  3347. {
  3348. local comp=$1;
  3349. local lang=$2;
  3350. shift 2;
  3351. [[ -z ${comp} || -z $1 ]] && return 1;
  3352. local cmdline=($(tc-get${comp}) -Werror -c -o /dev/null);
  3353. if "${cmdline[@]}" -x${lang} - < /dev/null &> /dev/null; then
  3354. cmdline+=("$@" -x${lang} -);
  3355. else
  3356. cmdline+=("$@" -c -o /dev/null /dev/null);
  3357. fi;
  3358. if ! "${cmdline[@]}" < /dev/null &> /dev/null; then
  3359. cmdline+=(-Qunused-arguments);
  3360. "${cmdline[@]}" < /dev/null &> /dev/null;
  3361. fi
  3362. }
  3363. test-flags ()
  3364. {
  3365. test-flags-CC "$@"
  3366. }
  3367. test-flags-CC ()
  3368. {
  3369. test-flags-PROG "CC" "$@"
  3370. }
  3371. test-flags-CXX ()
  3372. {
  3373. test-flags-PROG "CXX" "$@"
  3374. }
  3375. test-flags-F77 ()
  3376. {
  3377. test-flags-PROG "F77" "$@"
  3378. }
  3379. test-flags-FC ()
  3380. {
  3381. test-flags-PROG "FC" "$@"
  3382. }
  3383. test-flags-PROG ()
  3384. {
  3385. local comp=$1;
  3386. local flags=();
  3387. local x;
  3388. shift;
  3389. [[ -z ${comp} ]] && return 1;
  3390. while (( $# )); do
  3391. case "$1" in
  3392. --param)
  3393. if test-flag-${comp} "$1" "$2"; then
  3394. flags+=("$1" "$2");
  3395. fi;
  3396. shift 2
  3397. ;;
  3398. *)
  3399. if test-flag-${comp} "$1"; then
  3400. flags+=("$1");
  3401. fi;
  3402. shift 1
  3403. ;;
  3404. esac;
  3405. done;
  3406. echo "${flags[*]}";
  3407. [[ ${#flags[@]} -gt 0 ]]
  3408. }
  3409. test_version_info ()
  3410. {
  3411. if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then
  3412. return 0;
  3413. else
  3414. return 1;
  3415. fi
  3416. }
  3417. toolchain-binutils_bugurl ()
  3418. {
  3419. printf "https://bugs.gentoo.org/"
  3420. }
  3421. toolchain-binutils_pkgversion ()
  3422. {
  3423. printf "Gentoo ${PV}";
  3424. [[ -n ${PATCH_VER} ]] && printf " p${PATCH_VER}"
  3425. }
  3426. uclibctoolize ()
  3427. {
  3428. die "Use elibtoolize"
  3429. }
  3430. use_if_iuse ()
  3431. {
  3432. in_iuse $1 || return 1;
  3433. use $1
  3434. }
  3435. version_compare ()
  3436. {
  3437. eshopts_push -s extglob;
  3438. local ver_a=${1} ver_b=${2} parts_a parts_b;
  3439. local cur_tok_a cur_tok_b num_part_a num_part_b;
  3440. local -i cur_idx_a=0 cur_idx_b=0 prev_idx_a prev_idx_b;
  3441. parts_a=($(get_all_version_components "${ver_a}" ));
  3442. parts_b=($(get_all_version_components "${ver_b}" ));
  3443. local -i inf_loop=0;
  3444. while true; do
  3445. inf_loop+=1;
  3446. ((inf_loop > 20)) && die "versionator compare bug [numbers, ${ver_a}, ${ver_b}]";
  3447. prev_idx_a=cur_idx_a;
  3448. prev_idx_b=cur_idx_b;
  3449. cur_tok_a=${parts_a[cur_idx_a]};
  3450. cur_tok_b=${parts_b[cur_idx_b]};
  3451. if [[ -n ${cur_tok_a} ]] && [[ -z ${cur_tok_a//[[:digit:]]} ]]; then
  3452. cur_idx_a+=1;
  3453. [[ ${parts_a[cur_idx_a]} == . ]] && cur_idx_a+=1;
  3454. else
  3455. cur_tok_a=;
  3456. fi;
  3457. if [[ -n ${cur_tok_b} ]] && [[ -z ${cur_tok_b//[[:digit:]]} ]]; then
  3458. cur_idx_b+=1;
  3459. [[ ${parts_b[cur_idx_b]} == . ]] && cur_idx_b+=1;
  3460. else
  3461. cur_tok_b=;
  3462. fi;
  3463. [[ -z ${cur_tok_a} && -z ${cur_tok_b} ]] && break;
  3464. [[ -z ${cur_tok_a} ]] && eshopts_pop && return 1;
  3465. [[ -z ${cur_tok_b} ]] && eshopts_pop && return 3;
  3466. if (( prev_idx_a != 0 && prev_idx_b != 0 )) && [[ ${cur_tok_a} == 0* || ${cur_tok_b} == 0* ]]; then
  3467. cur_tok_a=${cur_tok_a%%+(0)};
  3468. cur_tok_b=${cur_tok_b%%+(0)};
  3469. [[ ${cur_tok_a} < ${cur_tok_b} ]] && eshopts_pop && return 1;
  3470. [[ ${cur_tok_a} > ${cur_tok_b} ]] && eshopts_pop && return 3;
  3471. else
  3472. cur_tok_a=${cur_tok_a##+(0)};
  3473. cur_tok_b=${cur_tok_b##+(0)};
  3474. : ${cur_tok_a:=0};
  3475. : ${cur_tok_b:=0};
  3476. ((cur_tok_a < cur_tok_b)) && eshopts_pop && return 1;
  3477. ((cur_tok_a > cur_tok_b)) && eshopts_pop && return 3;
  3478. fi;
  3479. done;
  3480. local letter_a=;
  3481. letter_a=${parts_a[cur_idx_a]};
  3482. if [[ ${#letter_a} -eq 1 && -z ${letter_a/[a-z]} ]]; then
  3483. cur_idx_a+=1;
  3484. else
  3485. letter_a=@;
  3486. fi;
  3487. local letter_b=;
  3488. letter_b=${parts_b[cur_idx_b]};
  3489. if [[ ${#letter_b} -eq 1 && -z ${letter_b/[a-z]} ]]; then
  3490. cur_idx_b+=1;
  3491. else
  3492. letter_b=@;
  3493. fi;
  3494. [[ ${letter_a} < ${letter_b} ]] && eshopts_pop && return 1;
  3495. [[ ${letter_a} > ${letter_b} ]] && eshopts_pop && return 3;
  3496. inf_loop=0;
  3497. while true; do
  3498. inf_loop+=1;
  3499. ((inf_loop > 20)) && die "versionator compare bug [numbers, ${ver_a}, ${ver_b}]";
  3500. [[ ${parts_a[cur_idx_a]} == _ ]] && ((cur_idx_a++));
  3501. [[ ${parts_b[cur_idx_b]} == _ ]] && ((cur_idx_b++));
  3502. cur_tok_a=${parts_a[cur_idx_a]};
  3503. cur_tok_b=${parts_b[cur_idx_b]};
  3504. num_part_a=0;
  3505. num_part_b=0;
  3506. if has ${cur_tok_a%%+([0-9])} "alpha" "beta" "pre" "rc" "p"; then
  3507. cur_idx_a+=1;
  3508. num_part_a=${cur_tok_a##+([a-z])};
  3509. num_part_a=${num_part_a##+(0)};
  3510. : ${num_part_a:=0};
  3511. cur_tok_a=${cur_tok_a%%+([0-9])};
  3512. else
  3513. cur_tok_a=;
  3514. fi;
  3515. if has ${cur_tok_b%%+([0-9])} alpha beta pre rc p; then
  3516. cur_idx_b+=1;
  3517. num_part_b=${cur_tok_b##+([a-z])};
  3518. num_part_b=${num_part_b##+(0)};
  3519. : ${num_part_b:=0};
  3520. cur_tok_b=${cur_tok_b%%+([0-9])};
  3521. else
  3522. cur_tok_b=;
  3523. fi;
  3524. if [[ ${cur_tok_a} != ${cur_tok_b} ]]; then
  3525. local suffix;
  3526. for suffix in alpha beta pre rc "" p;
  3527. do
  3528. [[ ${cur_tok_a} == ${suffix} ]] && eshopts_pop && return 1;
  3529. [[ ${cur_tok_b} == ${suffix} ]] && eshopts_pop && return 3;
  3530. done;
  3531. else
  3532. if [[ -z ${cur_tok_a} && -z ${cur_tok_b} ]]; then
  3533. break;
  3534. else
  3535. ((num_part_a < num_part_b)) && eshopts_pop && return 1;
  3536. ((num_part_a > num_part_b)) && eshopts_pop && return 3;
  3537. fi;
  3538. fi;
  3539. done;
  3540. [[ ${parts_a[cur_idx_a]} == - ]] && ((cur_idx_a++));
  3541. [[ ${parts_b[cur_idx_b]} == - ]] && ((cur_idx_b++));
  3542. if [[ -n ${parts_a[cur_idx_a]/r+([0-9])} || -n ${parts_b[cur_idx_b]/r+([0-9])} ]]; then
  3543. die "versionator compare bug [revisions, ${ver_a}, ${ver_b}]";
  3544. fi;
  3545. num_part_a=${parts_a[cur_idx_a]#r};
  3546. num_part_a=${num_part_a##+(0)};
  3547. : ${num_part_a:=0};
  3548. num_part_b=${parts_b[cur_idx_b]#r};
  3549. num_part_b=${num_part_b##+(0)};
  3550. : ${num_part_b:=0};
  3551. ((num_part_a < num_part_b)) && eshopts_pop && return 1;
  3552. ((num_part_a > num_part_b)) && eshopts_pop && return 3;
  3553. eshopts_pop;
  3554. return 2
  3555. }
  3556. version_format_string ()
  3557. {
  3558. local fstr=$1;
  3559. shift;
  3560. set -- $(get_version_components "$@");
  3561. eval echo "${fstr}"
  3562. }
  3563. version_is_at_least ()
  3564. {
  3565. local want_s="$1" have_s="${2:-${PVR}}" r;
  3566. version_compare "${want_s}" "${have_s}";
  3567. r=$?;
  3568. case $r in
  3569. 1 | 2)
  3570. return 0
  3571. ;;
  3572. 3)
  3573. return 1
  3574. ;;
  3575. *)
  3576. die "versionator compare bug [atleast, ${want_s}, ${have_s}, ${r}]"
  3577. ;;
  3578. esac
  3579. }
  3580. version_sort ()
  3581. {
  3582. eshopts_push -s extglob;
  3583. local items=;
  3584. local -i left=0;
  3585. items=("$@");
  3586. while ((left < ${#items[@]})); do
  3587. local -i lowest_idx=left;
  3588. local -i idx=lowest_idx+1;
  3589. while ((idx < ${#items[@]})); do
  3590. version_compare "${items[lowest_idx]}" "${items[idx]}";
  3591. [[ $? -eq 3 ]] && lowest_idx=idx;
  3592. idx+=1;
  3593. done;
  3594. local tmp=${items[lowest_idx]};
  3595. items[lowest_idx]=${items[left]};
  3596. items[left]=${tmp};
  3597. left+=1;
  3598. done;
  3599. echo ${items[@]};
  3600. eshopts_pop
  3601. }
  3602.