spacepaste

  1.  
  2. declare -x ABI="amd64"
  3. declare -x ABI_MIPS=""
  4. declare -x ABI_PPC=""
  5. declare -x ABI_S390=""
  6. declare -x ABI_X86="64"
  7. declare -x ADAFLAGS=""
  8. declare -x ALSA_CARDS=""
  9. declare -x APACHE2_MODULES=""
  10. declare -x APACHE2_MPMS=""
  11. declare -x ARCH="amd64"
  12. declare BDEPEND=""
  13. declare -- BINPATH="/usr/x86_64-pc-linux-gnu/gcc-bin/7.3.0"
  14. declare -x BOOTSTRAP_USE="cxx unicode internal-glib split-usr python_targets_python3_5 python_targets_python2_7 multilib hardened pic xtpax -jit -orc"
  15. declare -- BRANCH_UPDATE=""
  16. declare -x BRANDING_GCC_PKGVERSION="Gentoo Hardened 7.3.0-r3 p1.4"
  17. declare -x CALLIGRA_EXPERIMENTAL_FEATURES=""
  18. declare -x CALLIGRA_FEATURES=""
  19. declare -x CAMERAS=""
  20. declare -x CBUILD="x86_64-pc-linux-gnu"
  21. declare -x CCASFLAGS=""
  22. declare -x CFLAGS="-march=native -O2"
  23. declare -x CFLAGS_amd64="-m64"
  24. declare -x CFLAGS_default
  25. declare -x CFLAGS_x32="-mx32"
  26. declare -x CFLAGS_x86="-m32"
  27. declare -x CHOST="x86_64-pc-linux-gnu"
  28. declare -x CHOST_amd64="x86_64-pc-linux-gnu"
  29. declare -x CHOST_default="x86_64-pc-linux-gnu"
  30. declare -x CHOST_x32="x86_64-pc-linux-gnux32"
  31. declare -x CHOST_x86="i686-pc-linux-gnu"
  32. declare -x COLLECTD_PLUGINS=""
  33. declare -x CPPFLAGS=""
  34. declare -x CPU_FLAGS_ARM=""
  35. declare -x CPU_FLAGS_X86=""
  36. declare -x CTARGET="x86_64-pc-linux-gnu"
  37. declare -x CTARGET_default="x86_64-pc-linux-gnu"
  38. declare -x CURL_SSL=""
  39. declare -x CXXFLAGS="-march=core2 -O2 -fstack-protector-all -fstack-check"
  40. declare -- DATAPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/7.3.0"
  41. declare -x DEBUGBUILD="1"
  42. declare -x DEFAULT_ABI="amd64"
  43. declare -x DEFINED_PHASES=" compile configure install postinst postrm prepare pretend setup test unpack"
  44. declare DEPEND="
  45. elibc_glibc? ( >=sys-libs/glibc-2.13 )
  46. >=sys-devel/binutils-2.20 >=sys-apps/sed-4 sys-devel/gnuconfig >=app-portage/elt-patches-20170422 sys-libs/zlib
  47. nls? ( virtual/libintl ) virtual/libiconv >=dev-libs/gmp-4.3.2:0= >=dev-libs/mpfr-2.4.2:0= >=dev-libs/mpc-0.8.1:0= objc-gc? ( >=dev-libs/boehm-gc-7.4.2 ) graphite? ( >=dev-libs/isl-0.14:0= )
  48. >=sys-devel/bison-1.875
  49. >=sys-devel/flex-2.5.4
  50. nls? ( sys-devel/gettext )
  51. regression-test? (
  52. >=dev-util/dejagnu-1.4.4
  53. >=sys-devel/autogen-5.5.4
  54. )"
  55. declare DESCRIPTION="The GNU Compiler Collection"
  56. declare -x DESTTREE="/usr"
  57. declare -x DIROPTIONS="-m0755"
  58. declare -x EAPI="5"
  59. declare -- EBUILD_DEATH_HOOKS=" toolchain_death_notice"
  60. declare -x ELIBC="glibc"
  61. declare -x ENLIGHTENMENT_MODULES=""
  62. 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"
  63. declare -- EPATCH_COMMON_OPTS="-g0 -E --no-backup-if-mismatch"
  64. declare -- EPATCH_EXCLUDE=""
  65. declare -- EPATCH_FORCE="no"
  66. declare -- EPATCH_MULTI_MSG="Applying various patches (bugfixes/updates) ..."
  67. declare -- EPATCH_N_APPLIED_PATCHES="15"
  68. declare -- EPATCH_OPTS=""
  69. declare -- EPATCH_SINGLE_MSG=""
  70. declare -- EPATCH_SOURCE="/var/tmp/portage/sys-devel/gcc-7.3.0-r3/work/patch"
  71. declare -- EPATCH_SUFFIX="patch"
  72. declare -- EPATCH_USER_SOURCE="/etc/portage/patches"
  73. declare -x EXEOPTIONS="-m0755"
  74. declare -x FCFLAGS=""
  75. 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}\""
  76. declare -x FFLAGS=""
  77. declare -x FFTOOLS=""
  78. declare -- GCCMAJOR="7"
  79. declare -- GCCMICRO="0"
  80. declare -- GCCMINOR="3"
  81. declare -- GCC_BRANCH_VER="7.3"
  82. declare -- GCC_CONFIG_VER="7.3.0"
  83. declare -- GCC_PV="7.3.0"
  84. declare -- GCC_PVR="7.3.0-r3"
  85. declare -- GCC_RELEASE_VER="7.3.0"
  86. declare -x GCJFLAGS="-march=native -O2"
  87. declare -- GMP_MPFR_DEPS=">=dev-libs/gmp-4.3.2:0= >=dev-libs/mpfr-2.4.2:0="
  88. declare -x GPSD_PROTOCOLS=""
  89. declare -x GRUB_PLATFORMS=""
  90. declare HDEPEND=""
  91. declare HOMEPAGE="https://gcc.gnu.org/"
  92. declare -x HTB_GCC_VER="7.3.0"
  93. declare -x HUSHLOGIN="FALSE"
  94. declare -- INCLUDEPATH="/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include"
  95. declare -x INHERITED=" desktop estack epatch toolchain-funcs multilib ltprune preserve-libs vcs-clean eutils fixheadtails flag-o-matic gnuconfig libtool pax-utils versionator prefix toolchain"
  96. declare -x INPUT_DEVICES=""
  97. declare -x INSDESTTREE=""
  98. declare -x INSOPTIONS="-m0644"
  99. declare IUSE="regression-test vanilla altivec debug doc hardened multilib objc pgo objc-gc libssp objc++ fixed-point go graphite cilk +vtv jit mpx +pie +ssp +pch +nls +nptl +cxx +fortran +openmp +sanitize"
  100. declare -a IUSE_DEF=([0]="nls" [1]="nptl" [2]="cxx" [3]="fortran" [4]="openmp" [5]="sanitize")
  101. declare -x IUSE_EFFECTIVE="abi_x86_64 alpha altivec amd64 amd64-fbsd amd64-linux arm arm-linux arm64 cilk cxx debug 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 fixed-point fortran go graphite hardened hppa ia64 jit kernel_AIX kernel_Darwin kernel_FreeBSD kernel_HPUX kernel_NetBSD kernel_OpenBSD kernel_SunOS kernel_Winnt kernel_freemint kernel_linux libssp m68k m68k-mint mips mpx multilib nls nptl objc objc++ objc-gc openmp pch pgo pie ppc ppc-aix ppc-macos ppc64 ppc64-linux prefix prefix-chain prefix-guest regression-test s390 sanitize sh sparc sparc-solaris sparc64-solaris ssp userland_BSD userland_GNU vanilla vtv x64-cygwin x64-macos x64-solaris x86 x86-cygwin x86-fbsd x86-linux x86-macos x86-solaris x86-winnt"
  102. declare -x IUSE_IMPLICIT="abi_x86_64 prefix prefix-chain prefix-guest"
  103. declare -x JAR="no"
  104. declare -x KERNEL="linux"
  105. declare -x KERNEL_ABI="amd64"
  106. declare -x KEYWORDS="~alpha amd64 ~arm arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc x86 ~amd64-fbsd ~x86-fbsd ~ppc-macos"
  107. declare -x L10N=""
  108. declare -x LANG="en_US"
  109. declare -x LCD_DEVICES=""
  110. declare -x LC_MESSAGES="C"
  111. declare -x LDFLAGS="-Wl,-O1 -Wl,--as-needed"
  112. declare -x LDFLAGS_amd64="-m elf_x86_64"
  113. declare -x LDFLAGS_default
  114. declare -x LDFLAGS_x32="-m elf32_x86_64"
  115. declare -x LDFLAGS_x86="-m elf_i386"
  116. declare -x LIBDIR_amd64="lib64"
  117. declare -x LIBDIR_default="lib"
  118. declare -x LIBDIR_x32="libx32"
  119. declare -x LIBDIR_x86="lib32"
  120. declare -x LIBOPTIONS="-m0644"
  121. declare -- LIBPATH="/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0"
  122. declare -x LIBREOFFICE_EXTENSIONS=""
  123. declare -x LICENSE="GPL-3+ LGPL-3+ || ( GPL-3+ libgcc libstdc++ gcc-runtime-library-exception-3.1 ) FDL-1.3+"
  124. declare -x LIRC_DEVICES=""
  125. declare -x LLVM_TARGETS=""
  126. declare -x MAIL="/var/mail/root"
  127. declare -x MAKEOPTS="-j4"
  128. declare -x MANPAGER="manpager"
  129. declare -x MONKEYD_PLUGINS=""
  130. declare -x MULTILIB_ABIS="amd64 x86"
  131. declare -x MULTILIB_STRICT_DENY="64-bit.*shared object"
  132. 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"
  133. declare -x MULTILIB_STRICT_EXEMPT="(perl5|gcc|gcc-lib|binutils|eclipse-3|debug|portage|udev|systemd|clang|python-exec|llvm)"
  134. declare -x NETBEANS="apisupport cnd groovy gsf harness ide identity j2ee java mobility nb php profiler soa visualweb webcommon websvccommon xml"
  135. declare -x NETBEANS_MODULES=""
  136. declare -x NGINX_MODULES_HTTP=""
  137. declare -x NGINX_MODULES_MAIL=""
  138. declare -x NGINX_MODULES_STREAM=""
  139. declare -x OFED_DRIVERS=""
  140. declare -x OFFICE_IMPLEMENTATION=""
  141. declare -x OPENMPI_FABRICS=""
  142. declare -x OPENMPI_OFED_FEATURES=""
  143. declare -x OPENMPI_RM=""
  144. declare -x PATCH_GCC_VER="7.3.0"
  145. declare -- PATCH_VER="1.4"
  146. declare -x PATH="/usr/lib/portage/bin/ebuild-helpers/xattr:/usr/lib/portage/bin/ebuild-helpers:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/6.4.0:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin"
  147. declare -x PAX_MARKINGS="XT"
  148. declare PDEPEND=" elibc_glibc? ( >=sys-libs/glibc-2.13 ) >=sys-devel/gcc-config-1.7"
  149. declare -x PHP_TARGETS=""
  150. declare -x PIE_GCC_VER="7.3.0"
  151. declare -x PKG_CONFIG_PATH="/usr/lib64/pkgconfig"
  152. declare -x POLICY_TYPES="strict targeted"
  153. declare -x PORTAGE_COMPRESSION_COMMAND="bzip2"
  154. declare -a PORTAGE_DOCOMPRESS=([0]="/usr/share/doc" [1]="/usr/share/info" [2]="/usr/share/man")
  155. declare -x PORTAGE_DOCOMPRESS_SIZE_LIMIT="128"
  156. declare -a PORTAGE_DOCOMPRESS_SKIP=([0]="/usr/share/doc/gcc-7.3.0-r3/html")
  157. declare -a PORTAGE_DOSTRIP=()
  158. declare -a PORTAGE_DOSTRIP_SKIP=()
  159. declare -x PORTAGE_FETCH_T="portage_fetch_t"
  160. declare -x PORTAGE_NICENESS="10"
  161. declare -x PORTAGE_SANDBOX_T="portage_sandbox_t"
  162. declare -x PORTAGE_T="portage_t"
  163. declare -x POSTGRES_TARGETS=""
  164. declare -- PREFIX="/usr"
  165. declare -x PROFILE_IS_HARDENED="1"
  166. 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"
  167. declare -x PROPERTIES=""
  168. declare -x PYTHONDONTWRITEBYTECODE="1"
  169. declare -x PYTHON_SINGLE_TARGET=""
  170. declare -x PYTHON_TARGETS=""
  171. declare -x QEMU_SOFTMMU_TARGETS=""
  172. declare -x QEMU_USER_TARGETS=""
  173. declare RDEPEND="sys-libs/zlib
  174. nls? ( virtual/libintl ) virtual/libiconv >=dev-libs/gmp-4.3.2:0= >=dev-libs/mpfr-2.4.2:0= >=dev-libs/mpc-0.8.1:0= objc-gc? ( >=dev-libs/boehm-gc-7.4.2 ) graphite? ( >=dev-libs/isl-0.14:0= )"
  175. declare REPOSITORY
  176. declare REQUIRED_USE=""
  177. declare -x RESTRICT="strip"
  178. 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}\""
  179. declare -x ROS_MESSAGES=""
  180. declare -x RUBY_TARGETS=""
  181. declare -x S="/var/tmp/portage/sys-devel/gcc-7.3.0-r3/work/gcc-7.3.0"
  182. declare -x SANDBOX_DEBUG="0"
  183. declare -x SANDBOX_DENY=""
  184. declare -x SANDBOX_PREDICT="/var/tmp/portage/sys-devel/gcc-7.3.0-r3/homedir:/dev/crypto"
  185. declare -x SANDBOX_READ="/:/var/tmp"
  186. declare -x SANDBOX_VERBOSE="1"
  187. 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/:/proc/self/fd:/selinux/:/sys/fs/selinux/:/tmp/:/usr/lib32/cf:/usr/lib32/conftest:/usr/lib64/cf:/usr/lib64/conftest:/usr/lib/cf:/usr/lib/conftest:/usr/tmp/cf:/usr/tmp/conftest:/var/tmp:/var/tmp/:/var/tmp/portage/sys-devel/gcc-7.3.0-r3/homedir/.bash_history:/selinux/:/sys/fs/selinux/:/proc/self/:/dev/zero"
  188. declare -x SANE_BACKENDS=""
  189. declare -x SHELL="/bin/bash"
  190. declare -x SLOT="7.3.0"
  191. declare -x SPECS_GCC_VER="7.3.0"
  192. declare SRC_URI="mirror://gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.xz mirror://gentoo/gcc-7.3.0-patches-1.4.tar.bz2 https://dev.gentoo.org/~vapier/dist/gcc-7.3.0-patches-1.4.tar.bz2 https://dev.gentoo.org/~rhill/dist/gcc-7.3.0-patches-1.4.tar.bz2 https://dev.gentoo.org/~zorry/patches/gcc/gcc-7.3.0-patches-1.4.tar.bz2 https://dev.gentoo.org/~blueness/dist/gcc-7.3.0-patches-1.4.tar.bz2 https://dev.gentoo.org/~tamiko/distfiles/gcc-7.3.0-patches-1.4.tar.bz2 https://dev.gentoo.org/~slyfox/distfiles/gcc-7.3.0-patches-1.4.tar.bz2"
  193. declare -- STDCXX_INCDIR="/usr/lib/gcc/x86_64-pc-linux-gnu/7.3.0/include/g++-v7"
  194. declare -x SYMLINK_LIB="yes"
  195. declare -x SYSROOT=""
  196. declare -- TARGET_ABI="amd64"
  197. declare -- TARGET_DEFAULT_ABI="amd64"
  198. declare -- TARGET_MULTILIB_ABIS="amd64 x86"
  199. declare -x TWISTED_DISABLE_WRITING_OF_PLUGIN_CACHE="1"
  200. declare -x UCLIBC_GCC_VER="7.3.0"
  201. declare -x USE="abi_x86_64 amd64 cxx debug elibc_glibc hardened kernel_linux multilib nls nptl openmp pie ssp userland_GNU vtv"
  202. declare -x USERLAND="GNU"
  203. declare -x USE_EXPAND_IMPLICIT="ARCH ELIBC KERNEL USERLAND"
  204. declare -x USE_EXPAND_UNPREFIXED="ARCH"
  205. declare -x USE_EXPAND_VALUES_ARCH="alpha amd64 amd64-fbsd amd64-linux arm arm-linux 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"
  206. declare -x USE_EXPAND_VALUES_ELIBC="AIX bionic Cygwin Darwin DragonFly FreeBSD glibc HPUX Interix mingw mintlib musl NetBSD OpenBSD SunOS uclibc Winnt"
  207. declare -x USE_EXPAND_VALUES_KERNEL="AIX Darwin FreeBSD freemint HPUX linux NetBSD OpenBSD SunOS Winnt"
  208. declare -x USE_EXPAND_VALUES_USERLAND="BSD GNU"
  209. declare -x UWSGI_PLUGINS=""
  210. declare -x VIDEO_CARDS=""
  211. declare -x VOICEMAIL_STORAGE=""
  212. declare -x XFCE_PLUGINS=""
  213. declare -x XTABLES_ADDONS=""
  214. declare -- _DESKTOP_ECLASS="1"
  215. declare -- _EPATCH_ECLASS="1"
  216. declare -- _ESTACK_ECLASS="1"
  217. declare -a _ESTACK_eshopts_=()
  218. declare -a _ESTACK_evar_=()
  219. declare -- _EUTILS_ECLASS="1"
  220. declare -x _E_DOCDESTTREE_=""
  221. declare -x _E_EXEDESTTREE_=""
  222. declare -- _FLAG_O_MATIC_ECLASS="1"
  223. declare -- _LIBTOOL_ECLASS="1"
  224. declare -- _LTPRUNE_ECLASS="1"
  225. declare -- _MULTILIB_ECLASS="1"
  226. declare -- _PAX_UTILS_ECLASS="1"
  227. declare -- _PRESERVE_LIBS_ECLASS="1"
  228. declare -- _TOOLCHAIN_FUNCS_ECLASS="1"
  229. declare -- _VERSIONATOR_ECLASS="1"
  230. declare -x ac_cv_have_x="have_x=yes ac_x_includes= ac_x_libraries="
  231. declare -x gcc_cv_prog_makeinfo_modern="no"
  232. declare -- phase_func
  233. XGCC ()
  234. {
  235. get_make_var GCC_FOR_TARGET
  236. }
  237. __eapi6_src_install ()
  238. {
  239. if [[ -f Makefile || -f GNUmakefile || -f makefile ]]; then
  240. emake DESTDIR="${D}" install;
  241. fi;
  242. einstalldocs
  243. }
  244. __eapi6_src_prepare ()
  245. {
  246. if [[ $(declare -p PATCHES 2>/dev/null) == "declare -a"* ]]; then
  247. [[ ${#PATCHES[@]} -gt 0 ]] && eapply "${PATCHES[@]}";
  248. else
  249. if [[ -n ${PATCHES} ]]; then
  250. eapply ${PATCHES};
  251. fi;
  252. fi;
  253. eapply_user
  254. }
  255. _clang_fullversion ()
  256. {
  257. local ver="$1";
  258. shift;
  259. set -- $($(tc-getCPP "$@") -E -P - <<<"__clang_major__ __clang_minor__ __clang_patchlevel__");
  260. eval echo "$ver"
  261. }
  262. _do_sed_fix ()
  263. {
  264. einfo " - fixed $1";
  265. sed -i -e 's/head \+-\([0-9]\)/head -n \1/g' -e 's/tail \+\([-+][0-9]\+\)c/tail -c \1/g' -e 's/tail \+\([-+][0-9]\)/tail -n \1/g' ${1} || die "sed ${1} failed"
  266. }
  267. _epatch_draw_line ()
  268. {
  269. [[ -z $1 ]] && set "$(printf "%65s" '')";
  270. echo "${1//?/=}"
  271. }
  272. _filter-hardened ()
  273. {
  274. local f;
  275. for f in "$@";
  276. do
  277. case "${f}" in
  278. -fPIC | -fpic | -fPIE | -fpie | -Wl,pie | -pie)
  279. gcc-specs-pie || continue;
  280. if ! is-flagq -nopie && ! is-flagq -no-pie; then
  281. if test-flags -nopie > /dev/null; then
  282. append-flags -nopie;
  283. else
  284. append-flags -no-pie;
  285. fi;
  286. fi
  287. ;;
  288. -fstack-protector)
  289. gcc-specs-ssp || continue;
  290. is-flagq -fno-stack-protector || append-flags $(test-flags -fno-stack-protector)
  291. ;;
  292. -fstack-protector-all)
  293. gcc-specs-ssp-to-all || continue;
  294. is-flagq -fno-stack-protector-all || append-flags $(test-flags -fno-stack-protector-all)
  295. ;;
  296. -fno-strict-overflow)
  297. gcc-specs-nostrict || continue;
  298. is-flagq -fstrict-overflow || append-flags $(test-flags -fstrict-overflow)
  299. ;;
  300. esac;
  301. done
  302. }
  303. _filter-var ()
  304. {
  305. local f x var=$1 new=();
  306. shift;
  307. for f in ${!var};
  308. do
  309. for x in "$@";
  310. do
  311. [[ ${f} == ${x} ]] && continue 2;
  312. done;
  313. new+=("${f}");
  314. done;
  315. export ${var}="${new[*]}"
  316. }
  317. _gcc-install-dir ()
  318. {
  319. echo "$(LC_ALL=C $(tc-getCC) -print-search-dirs 2> /dev/null | awk '$1=="install:" {print $2}')"
  320. }
  321. _gcc-specs-directive_raw ()
  322. {
  323. local cc=$(tc-getCC);
  324. local specfiles=$(LC_ALL=C ${cc} -v 2>&1 | awk '$1=="Reading" {print $NF}');
  325. ${cc} -dumpspecs 2> /dev/null | cat - ${specfiles} | awk -v directive=$1 'BEGIN { pspec=""; spec=""; outside=1 }
  326. $1=="*"directive":" { pspec=spec; spec=""; outside=0; next }
  327. outside || NF==0 || ( substr($1,1,1)=="*" && substr($1,length($1),1)==":" ) { outside=1; next }
  328. spec=="" && substr($0,1,1)=="+" { spec=pspec " " substr($0,2); next }
  329. { spec=spec $0 }
  330. END { print spec }';
  331. return 0
  332. }
  333. _gcc-specs-exists ()
  334. {
  335. [[ -f $(_gcc-install-dir)/$1 ]]
  336. }
  337. _gcc_fullversion ()
  338. {
  339. local ver="$1";
  340. shift;
  341. set -- $($(tc-getCPP "$@") -E -P - <<<"__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__");
  342. eval echo "$ver"
  343. }
  344. _iconins ()
  345. {
  346. ( insopts -m 0644;
  347. local funcname=$1;
  348. shift;
  349. local size dir;
  350. local context=apps;
  351. local theme=hicolor;
  352. while [[ $# -gt 0 ]]; do
  353. case $1 in
  354. -s | --size)
  355. if [[ ${2%%x*}x${2%%x*} == "$2" ]]; then
  356. size=${2%%x*};
  357. else
  358. size=${2};
  359. fi;
  360. case ${size} in
  361. 16 | 22 | 24 | 32 | 36 | 48 | 64 | 72 | 96 | 128 | 192 | 256 | 512)
  362. size=${size}x${size}
  363. ;;
  364. scalable)
  365. ;;
  366. *)
  367. eerror "${size} is an unsupported icon size!";
  368. exit 1
  369. ;;
  370. esac;
  371. shift 2
  372. ;;
  373. -t | --theme)
  374. theme=${2};
  375. shift 2
  376. ;;
  377. -c | --context)
  378. context=${2};
  379. shift 2
  380. ;;
  381. *)
  382. if [[ -z ${size} ]]; then
  383. insinto /usr/share/pixmaps;
  384. else
  385. insinto /usr/share/icons/${theme}/${size}/${context};
  386. fi;
  387. if [[ ${funcname} == doicon ]]; then
  388. if [[ -f $1 ]]; then
  389. doins "${1}";
  390. else
  391. if [[ -d $1 ]]; then
  392. shopt -s nullglob;
  393. doins "${1}"/*.{png,svg};
  394. shopt -u nullglob;
  395. else
  396. eerror "${1} is not a valid file/directory!";
  397. exit 1;
  398. fi;
  399. fi;
  400. else
  401. break;
  402. fi;
  403. shift 1
  404. ;;
  405. esac;
  406. done;
  407. if [[ ${funcname} == newicon ]]; then
  408. newins "$@";
  409. fi ) || die
  410. }
  411. _is_flagq ()
  412. {
  413. local x var="$1[*]";
  414. for x in ${!var};
  415. do
  416. [[ ${x} == $2 ]] && return 0;
  417. done;
  418. return 1
  419. }
  420. _pax_list_files ()
  421. {
  422. local f cmd;
  423. cmd=$1;
  424. shift;
  425. for f in "$@";
  426. do
  427. ${cmd} " ${f}";
  428. done
  429. }
  430. _tc-getPROG ()
  431. {
  432. local tuple=$1;
  433. local v var vars=$2;
  434. local prog=($3);
  435. var=${vars%% *};
  436. for v in ${vars};
  437. do
  438. if [[ -n ${!v} ]]; then
  439. export ${var}="${!v}";
  440. echo "${!v}";
  441. return 0;
  442. fi;
  443. done;
  444. local search=;
  445. [[ -n $4 ]] && search=$(type -p $4-${prog[0]});
  446. [[ -z ${search} && -n ${!tuple} ]] && search=$(type -p ${!tuple}-${prog[0]});
  447. [[ -n ${search} ]] && prog[0]=${search##*/};
  448. export ${var}="${prog[*]}";
  449. echo "${!var}"
  450. }
  451. all-flag-vars ()
  452. {
  453. echo {ADA,C,CPP,CXX,CCAS,F,FC,LD}FLAGS
  454. }
  455. append-cflags ()
  456. {
  457. [[ $# -eq 0 ]] && return 0;
  458. export CFLAGS+=" $*";
  459. return 0
  460. }
  461. append-cppflags ()
  462. {
  463. [[ $# -eq 0 ]] && return 0;
  464. export CPPFLAGS+=" $*";
  465. return 0
  466. }
  467. append-cxxflags ()
  468. {
  469. [[ $# -eq 0 ]] && return 0;
  470. export CXXFLAGS+=" $*";
  471. return 0
  472. }
  473. append-fflags ()
  474. {
  475. [[ $# -eq 0 ]] && return 0;
  476. export FFLAGS+=" $*";
  477. export FCFLAGS+=" $*";
  478. return 0
  479. }
  480. append-flags ()
  481. {
  482. [[ $# -eq 0 ]] && return 0;
  483. case " $* " in
  484. *' '-[DIU]*)
  485. eqawarn 'please use append-cppflags for preprocessor flags'
  486. ;;
  487. *' '-L* | *' '-Wl,*)
  488. eqawarn 'please use append-ldflags for linker flags'
  489. ;;
  490. esac;
  491. append-cflags "$@";
  492. append-cxxflags "$@";
  493. append-fflags "$@";
  494. return 0
  495. }
  496. append-ldflags ()
  497. {
  498. [[ $# -eq 0 ]] && return 0;
  499. local flag;
  500. for flag in "$@";
  501. do
  502. [[ ${flag} == -l* ]] && eqawarn "Appending a library link instruction (${flag}); libraries to link to should not be passed through LDFLAGS";
  503. done;
  504. export LDFLAGS="${LDFLAGS} $*";
  505. return 0
  506. }
  507. append-lfs-flags ()
  508. {
  509. [[ $# -ne 0 ]] && die "append-lfs-flags takes no arguments";
  510. append-cppflags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
  511. }
  512. append-libs ()
  513. {
  514. [[ $# -eq 0 ]] && return 0;
  515. local flag;
  516. for flag in "$@";
  517. do
  518. if [[ -z "${flag// }" ]]; then
  519. eqawarn "Appending an empty argument to LIBS is invalid! Skipping.";
  520. continue;
  521. fi;
  522. case $flag in
  523. -[lL]*)
  524. export LIBS="${LIBS} ${flag}"
  525. ;;
  526. -*)
  527. eqawarn "Appending non-library to LIBS (${flag}); Other linker flags should be passed via LDFLAGS";
  528. export LIBS="${LIBS} ${flag}"
  529. ;;
  530. *)
  531. export LIBS="${LIBS} -l${flag}"
  532. ;;
  533. esac;
  534. done;
  535. return 0
  536. }
  537. clang-fullversion ()
  538. {
  539. _clang_fullversion '$1.$2.$3' "$@"
  540. }
  541. clang-major-version ()
  542. {
  543. _clang_fullversion '$1' "$@"
  544. }
  545. clang-micro-version ()
  546. {
  547. _clang_fullversion '$3' "$@"
  548. }
  549. clang-minor-version ()
  550. {
  551. _clang_fullversion '$2' "$@"
  552. }
  553. clang-version ()
  554. {
  555. _clang_fullversion '$1.$2' "$@"
  556. }
  557. copy_minispecs_gcc_specs ()
  558. {
  559. if tc_version_is_at_least 6.0; then
  560. return 0;
  561. fi;
  562. if hardened_gcc_works; then
  563. create_gcc_env_entry hardenednopiessp;
  564. fi;
  565. if hardened_gcc_works pie; then
  566. create_gcc_env_entry hardenednopie;
  567. fi;
  568. if hardened_gcc_works ssp; then
  569. create_gcc_env_entry hardenednossp;
  570. fi;
  571. create_gcc_env_entry vanilla;
  572. insinto ${LIBPATH#${EPREFIX}};
  573. doins "${WORKDIR}"/specs/*.specs || die "failed to install specs";
  574. if ! tc_version_is_at_least 4.4; then
  575. $(XGCC) -dumpspecs > "${WORKDIR}"/specs/specs;
  576. cat "${WORKDIR}"/build.specs >> "${WORKDIR}"/specs/specs;
  577. doins "${WORKDIR}"/specs/specs || die "failed to install the specs file";
  578. fi
  579. }
  580. create_gcc_env_entry ()
  581. {
  582. dodir /etc/env.d/gcc;
  583. local gcc_envd_base="/etc/env.d/gcc/${CTARGET}-${GCC_CONFIG_VER}";
  584. local gcc_specs_file;
  585. local gcc_envd_file="${ED}${gcc_envd_base}";
  586. if [[ -z $1 ]]; then
  587. gcc_specs_file="";
  588. else
  589. gcc_envd_file+="-$1";
  590. gcc_specs_file="${LIBPATH}/$1.specs";
  591. fi;
  592. local ldpaths mosdirs;
  593. if tc_version_is_at_least 3.2; then
  594. local mdir mosdir abi ldpath;
  595. for abi in $(get_all_abis TARGET);
  596. do
  597. mdir=$($(XGCC) $(get_abi_CFLAGS ${abi}) --print-multi-directory);
  598. ldpath=${LIBPATH};
  599. [[ ${mdir} != "." ]] && ldpath+="/${mdir}";
  600. ldpaths="${ldpath}${ldpaths:+:${ldpaths}}";
  601. mosdir=$($(XGCC) $(get_abi_CFLAGS ${abi}) -print-multi-os-directory);
  602. mosdirs="${mosdir}${mosdirs:+:${mosdirs}}";
  603. done;
  604. else
  605. ldpaths=${LIBPATH};
  606. fi;
  607. cat > ${gcc_envd_file} <<-EOF
  608. PATH="${BINPATH}"
  609. ROOTPATH="${BINPATH}"
  610. GCC_PATH="${BINPATH}"
  611. LDPATH="${ldpaths}"
  612. MANPATH="${DATAPATH}/man"
  613. INFOPATH="${DATAPATH}/info"
  614. STDCXX_INCDIR="${STDCXX_INCDIR##*/}"
  615. CTARGET="${CTARGET}"
  616. GCC_SPECS="${gcc_specs_file}"
  617. MULTIOSDIRS="${mosdirs}"
  618. EOF
  619. }
  620. darwintoolize ()
  621. {
  622. die "Use elibtoolize"
  623. }
  624. delete_all_version_separators ()
  625. {
  626. replace_all_version_separators "" "${1}"
  627. }
  628. delete_version_separator ()
  629. {
  630. replace_version_separator "${1}" "" "${2}"
  631. }
  632. do_gcc_HTB_patches ()
  633. {
  634. use_if_iuse boundschecking || return 0;
  635. epatch "${WORKDIR}/bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch";
  636. BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, HTB-${HTB_GCC_VER}-${HTB_VER}"
  637. }
  638. do_gcc_PIE_patches ()
  639. {
  640. want_pie || return 0;
  641. use vanilla && return 0;
  642. if tc_version_is_at_least 4.3.2; then
  643. guess_patch_type_in_dir "${WORKDIR}"/piepatch/;
  644. EPATCH_MULTI_MSG="Applying pie patches ..." epatch "${WORKDIR}"/piepatch/;
  645. else
  646. guess_patch_type_in_dir "${WORKDIR}"/piepatch/upstream;
  647. EPATCH_MULTI_MSG="Applying upstream pie patches ..." epatch "${WORKDIR}"/piepatch/upstream;
  648. EPATCH_MULTI_MSG="Applying non-default pie patches ..." epatch "${WORKDIR}"/piepatch/nondef;
  649. EPATCH_MULTI_MSG="Applying default pie patches ..." epatch "${WORKDIR}"/piepatch/def;
  650. fi;
  651. BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, pie-${PIE_VER}"
  652. }
  653. do_gcc_config ()
  654. {
  655. if ! should_we_gcc_config; then
  656. gcc-config --use-old --force;
  657. return 0;
  658. fi;
  659. local current_gcc_config target;
  660. current_gcc_config=$(gcc-config -c ${CTARGET} 2>/dev/null);
  661. if [[ -n ${current_gcc_config} ]]; then
  662. local current_specs use_specs;
  663. current_specs=$(gcc-config -S ${current_gcc_config} | awk '{print $3}');
  664. [[ -n ${current_specs} ]] && use_specs=-${current_specs};
  665. if [[ -n ${use_specs} ]] && [[ ! -e ${ROOT}/etc/env.d/gcc/${CTARGET}-${GCC_CONFIG_VER}${use_specs} ]]; then
  666. ewarn "The currently selected specs-specific gcc config,";
  667. ewarn "${current_specs}, doesn't exist anymore. This is usually";
  668. ewarn "due to enabling/disabling hardened or switching to a version";
  669. ewarn "of gcc that doesnt create multiple specs files. The default";
  670. ewarn "config will be used, and the previous preference forgotten.";
  671. use_specs="";
  672. fi;
  673. target="${CTARGET}-${GCC_CONFIG_VER}${use_specs}";
  674. else
  675. target=$(gcc-config -l 2>/dev/null | grep " ${CTARGET}-[0-9]" | tail -1 | awk '{print $2}');
  676. fi;
  677. gcc-config "${target}"
  678. }
  679. do_gcc_rename_java_bins ()
  680. {
  681. einfo "Renaming jdk executables rmic and rmiregistry to grmic and grmiregistry.";
  682. for manfile in rmic rmiregistry;
  683. do
  684. [[ -f ${S}/gcc/doc/${manfile}.1 ]] || continue;
  685. mv "${S}"/gcc/doc/${manfile}.1 "${S}"/gcc/doc/g${manfile}.1;
  686. done;
  687. for jfile in gcc/doc/gcj.info gcc/doc/grmic.1 gcc/doc/grmiregistry.1 gcc/java/gcj.texi;
  688. do
  689. [[ -f ${S}/${jfile} ]] || continue;
  690. sed -i -e 's:rmiregistry:grmiregistry:g' "${S}"/${jfile} || die "Failed to fixup file ${jfile} for rename to grmiregistry";
  691. sed -i -e 's:rmic:grmic:g' "${S}"/${jfile} || die "Failed to fixup file ${jfile} for rename to grmic";
  692. done;
  693. for jfile in libjava/Makefile.am libjava/Makefile.in gcc/java/Make-lang.in;
  694. do
  695. sed -i -e 's:rmiregistry:grmiregistry:g' "${S}"/${jfile} || die "Failed to fixup file ${jfile} for rename to grmiregistry";
  696. sed -i -e 's:rmic\([$_ ]\):grmic\1:g' "${S}"/${jfile} || die "Failed to fixup file ${jfile} for rename to grmic";
  697. done
  698. }
  699. doicon ()
  700. {
  701. _iconins ${FUNCNAME} "$@"
  702. }
  703. domenu ()
  704. {
  705. ( local i j ret=0;
  706. insopts -m 0644;
  707. insinto /usr/share/applications;
  708. for i in "$@";
  709. do
  710. if [[ -f ${i} ]]; then
  711. doins "${i}";
  712. ((ret+=$?));
  713. else
  714. if [[ -d ${i} ]]; then
  715. for j in "${i}"/*.desktop;
  716. do
  717. doins "${j}";
  718. ((ret+=$?));
  719. done;
  720. else
  721. ((++ret));
  722. fi;
  723. fi;
  724. done;
  725. exit ${ret} )
  726. }
  727. downgrade_arch_flags ()
  728. {
  729. local arch bver i isa myarch mytune rep ver;
  730. bver=${1:-${GCC_BRANCH_VER}};
  731. [[ $(gcc-version) < ${bver} ]] && return 0;
  732. [[ $(tc-arch) != amd64 && $(tc-arch) != x86 ]] && return 0;
  733. myarch=$(get-flag march);
  734. mytune=$(get-flag mtune);
  735. if [[ ${myarch} == native || ${mytune} == native ]]; then
  736. if [[ ${bver} < 4.2 ]]; then
  737. arch=$($(tc-getCC) -march=native -v -E -P - </dev/null 2>&1 | sed -rn "/cc1.*-march/s:.*-march=([^ ']*).*:\1:p");
  738. replace-cpu-flags native ${arch};
  739. fi;
  740. fi;
  741. [[ ${mytune} == intel && ${bver} < 4.9 ]] && replace-cpu-flags intel generic;
  742. [[ ${mytune} == generic && ${bver} < 4.2 ]] && filter-flags '-mtune=*';
  743. [[ ${mytune} == x86-64 ]] && filter-flags '-mtune=*';
  744. [[ ${bver} < 3.4 ]] && filter-flags '-mtune=*';
  745. local archlist=(4.9 bdver4 bdver3 4.9 bonnell atom 4.9 broadwell core-avx2 4.9 haswell core-avx2 4.9 ivybridge core-avx-i 4.9 nehalem corei7 4.9 sandybridge corei7-avx 4.9 silvermont corei7 4.9 westmere corei7 4.8 bdver3 bdver2 4.8 btver2 btver1 4.7 bdver2 bdver1 4.7 core-avx2 core-avx-i 4.6 bdver1 amdfam10 4.6 btver1 amdfam10 4.6 core-avx-i core2 4.6 corei7 core2 4.6 corei7-avx core2 4.5 atom core2 4.3 amdfam10 k8 4.3 athlon64-sse3 k8 4.3 barcelona k8 4.3 core2 nocona 4.3 geode k6-2 4.3 k8-sse3 k8 4.3 opteron-sse3 k8 3.4 athlon-fx x86-64 3.4 athlon64 x86-64 3.4 c3-2 c3 3.4 k8 x86-64 3.4 opteron x86-64 3.4 pentium-m pentium3 3.4 pentium3m pentium3 3.4 pentium4m pentium4);
  746. for ((i = 0; i < ${#archlist[@]}; i += 3))
  747. do
  748. myarch=$(get-flag march);
  749. mytune=$(get-flag mtune);
  750. ver=${archlist[i]};
  751. arch=${archlist[i + 1]};
  752. rep=${archlist[i + 2]};
  753. [[ ${myarch} != ${arch} && ${mytune} != ${arch} ]] && continue;
  754. if [[ ${ver} > ${bver} ]]; then
  755. einfo "Replacing ${myarch} (added in gcc ${ver}) with ${rep}...";
  756. [[ ${myarch} == ${arch} ]] && replace-cpu-flags ${myarch} ${rep};
  757. [[ ${mytune} == ${arch} ]] && replace-cpu-flags ${mytune} ${rep};
  758. continue;
  759. else
  760. break;
  761. fi;
  762. done;
  763. local isalist=(4.9 -mno-sha 4.9 -mno-avx512pf 4.9 -mno-avx512f 4.9 -mno-avx512er 4.9 -mno-avx512cd 4.8 -mno-xsaveopt 4.8 -mno-xsave 4.8 -mno-rtm 4.8 -mno-fxsr 4.7 -mno-lzcnt 4.7 -mno-bmi2 4.7 -mno-avx2 4.6 -mno-tbm 4.6 -mno-rdrnd 4.6 -mno-fsgsbase 4.6 -mno-f16c 4.6 -mno-bmi 4.5 -mno-xop 4.5 -mno-movbe 4.5 -mno-lwp 4.5 -mno-fma4 4.4 -mno-pclmul 4.4 -mno-fma 4.4 -mno-avx 4.4 -mno-aes 4.3 -mno-ssse3 4.3 -mno-sse4a 4.3 -mno-sse4 4.3 -mno-sse4.2 4.3 -mno-sse4.1 4.3 -mno-popcnt 4.3 -mno-abm);
  764. for ((i = 0; i < ${#isalist[@]}; i += 2))
  765. do
  766. ver=${isalist[i]};
  767. isa=${isalist[i + 1]};
  768. [[ ${ver} > ${bver} ]] && filter-flags ${isa} ${isa/-m/-mno-};
  769. done
  770. }
  771. ebeep ()
  772. {
  773. ewarn "QA Notice: ebeep is not defined in EAPI=${EAPI}, please file a bug at https://bugs.gentoo.org"
  774. }
  775. econf_build ()
  776. {
  777. local CBUILD=${CBUILD:-${CHOST}};
  778. tc-env_build econf --build=${CBUILD} --host=${CBUILD} "$@"
  779. }
  780. ecvs_clean ()
  781. {
  782. [[ $# -eq 0 ]] && set -- .;
  783. find "$@" '(' -type d -name 'CVS' -prune -o -type f -name '.cvs*' ')' -exec rm -rf '{}' +
  784. }
  785. edos2unix ()
  786. {
  787. [[ $# -eq 0 ]] && return 0;
  788. sed -i 's/\r$//' -- "$@" || die
  789. }
  790. egit_clean ()
  791. {
  792. [[ $# -eq 0 ]] && set -- .;
  793. find "$@" -type d -name '.git*' -prune -exec rm -rf '{}' +
  794. }
  795. einstalldocs ()
  796. {
  797. debug-print-function ${FUNCNAME} "${@}";
  798. local dodoc_opts=-r;
  799. has ${EAPI} 0 1 2 3 && dodoc_opts=;
  800. if ! declare -p DOCS &> /dev/null; then
  801. local d;
  802. for d in README* ChangeLog AUTHORS NEWS TODO CHANGES THANKS BUGS FAQ CREDITS CHANGELOG;
  803. do
  804. if [[ -s ${d} ]]; then
  805. dodoc "${d}" || die;
  806. fi;
  807. done;
  808. else
  809. if [[ $(declare -p DOCS) == "declare -a"* ]]; then
  810. if [[ -n ${DOCS[@]} ]]; then
  811. dodoc ${dodoc_opts} "${DOCS[@]}" || die;
  812. fi;
  813. else
  814. if [[ -n ${DOCS} ]]; then
  815. dodoc ${dodoc_opts} ${DOCS} || die;
  816. fi;
  817. fi;
  818. fi;
  819. if [[ $(declare -p HTML_DOCS 2>/dev/null) == "declare -a"* ]]; then
  820. if [[ -n ${HTML_DOCS[@]} ]]; then
  821. dohtml -r "${HTML_DOCS[@]}" || die;
  822. fi;
  823. else
  824. if [[ -n ${HTML_DOCS} ]]; then
  825. dohtml -r ${HTML_DOCS} || die;
  826. fi;
  827. fi;
  828. return 0
  829. }
  830. elibtoolize ()
  831. {
  832. type -P eltpatch &> /dev/null || die "eltpatch not found; is app-portage/elt-patches installed?";
  833. ELT_LOGDIR=${T} LD=$(tc-getLD) eltpatch "${@}" || die "eltpatch failed"
  834. }
  835. emktemp ()
  836. {
  837. local exe="touch";
  838. [[ $1 == -d ]] && exe="mkdir" && shift;
  839. local topdir=$1;
  840. if [[ -z ${topdir} ]]; then
  841. [[ -z ${T} ]] && topdir="/tmp" || topdir=${T};
  842. fi;
  843. if ! type -P mktemp > /dev/null; then
  844. local tmp=/;
  845. while [[ -e ${tmp} ]]; do
  846. tmp=${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM};
  847. done;
  848. ${exe} "${tmp}" || ${exe} -p "${tmp}";
  849. echo "${tmp}";
  850. else
  851. if [[ ${exe} == "touch" ]]; then
  852. TMPDIR="${topdir}" mktemp -t tmp.XXXXXXXXXX;
  853. else
  854. TMPDIR="${topdir}" mktemp -dt tmp.XXXXXXXXXX;
  855. fi;
  856. fi
  857. }
  858. epatch ()
  859. {
  860. function _epatch_draw_line ()
  861. {
  862. [[ -z $1 ]] && set "$(printf "%65s" '')";
  863. echo "${1//?/=}"
  864. };
  865. unset P4CONFIG P4PORT P4USER;
  866. local EPATCH_OPTS=(${EPATCH_OPTS[*]});
  867. while [[ $# -gt 0 ]]; do
  868. case $1 in
  869. -*)
  870. EPATCH_OPTS+=("$1")
  871. ;;
  872. *)
  873. break
  874. ;;
  875. esac;
  876. shift;
  877. done;
  878. if [[ $# -gt 1 ]]; then
  879. local m;
  880. for m in "$@";
  881. do
  882. epatch "${m}";
  883. done;
  884. return 0;
  885. fi;
  886. local SINGLE_PATCH="no";
  887. [[ $# -eq 0 ]] && set -- "${EPATCH_SOURCE}";
  888. if [[ -f $1 ]]; then
  889. SINGLE_PATCH="yes";
  890. set -- "$1";
  891. local EPATCH_SUFFIX=$1;
  892. else
  893. if [[ -d $1 ]]; then
  894. evar_push_set LC_COLLATE C;
  895. set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"};
  896. evar_pop;
  897. else
  898. if [[ -f ${EPATCH_SOURCE}/$1 ]]; then
  899. epatch "${EPATCH_SOURCE}/$1";
  900. return $?;
  901. else
  902. [[ $# -ne 0 ]] && EPATCH_SOURCE=$1;
  903. echo;
  904. eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:";
  905. eerror;
  906. eerror " ${EPATCH_SOURCE}";
  907. eerror " ( ${EPATCH_SOURCE##*/} )";
  908. echo;
  909. die "Cannot find \$EPATCH_SOURCE!";
  910. fi;
  911. fi;
  912. fi;
  913. EPATCH_OPTS="${EPATCH_COMMON_OPTS} ${EPATCH_OPTS[*]}";
  914. local PIPE_CMD;
  915. case ${EPATCH_SUFFIX##*\.} in
  916. xz)
  917. PIPE_CMD="xz -dc"
  918. ;;
  919. lzma)
  920. PIPE_CMD="lzma -dc"
  921. ;;
  922. bz2)
  923. PIPE_CMD="bzip2 -dc"
  924. ;;
  925. gz | Z | z)
  926. PIPE_CMD="gzip -dc"
  927. ;;
  928. ZIP | zip)
  929. PIPE_CMD="unzip -p"
  930. ;;
  931. *)
  932. ;;
  933. esac;
  934. [[ ${SINGLE_PATCH} == "no" ]] && einfo "${EPATCH_MULTI_MSG}";
  935. local x;
  936. for x in "$@";
  937. do
  938. [[ ! -f ${x} ]] && continue;
  939. local patchname=${x##*/};
  940. local a=${patchname#*_};
  941. a=${a%%_*};
  942. if ! [[ ${SINGLE_PATCH} == "yes" || ${EPATCH_FORCE} == "yes" || ${a} == all || ${a} == ${ARCH} ]]; then
  943. continue;
  944. fi;
  945. if [[ -n ${EPATCH_EXCLUDE}${EPATCH_USER_EXCLUDE} ]]; then
  946. eshopts_push -o noglob;
  947. local ex;
  948. for ex in ${EPATCH_EXCLUDE};
  949. do
  950. if [[ ${patchname} == ${ex} ]]; then
  951. einfo " Skipping ${patchname} due to EPATCH_EXCLUDE ...";
  952. eshopts_pop;
  953. continue 2;
  954. fi;
  955. done;
  956. for ex in ${EPATCH_USER_EXCLUDE};
  957. do
  958. if [[ ${patchname} == ${ex} ]]; then
  959. einfo " Skipping ${patchname} due to EPATCH_USER_EXCLUDE ...";
  960. eshopts_pop;
  961. continue 2;
  962. fi;
  963. done;
  964. eshopts_pop;
  965. fi;
  966. if [[ ${SINGLE_PATCH} == "yes" ]]; then
  967. if [[ -n ${EPATCH_SINGLE_MSG} ]]; then
  968. einfo "${EPATCH_SINGLE_MSG}";
  969. else
  970. einfo "Applying ${patchname} ...";
  971. fi;
  972. else
  973. einfo " ${patchname} ...";
  974. fi;
  975. local patch="patch";
  976. eval $(alias patch 2>/dev/null | sed 's:^alias ::');
  977. local STDERR_TARGET="${T}/${patchname}.out";
  978. if [[ -e ${STDERR_TARGET} ]]; then
  979. STDERR_TARGET="${T}/${patchname}-$$.out";
  980. fi;
  981. printf "***** %s *****\nPWD: %s\nPATCH TOOL: %s -> %s\nVERSION INFO:\n%s\n\n" "${patchname}" "${PWD}" "${patch}" "$(type -P "${patch}")" "$(${patch} --version)" > "${STDERR_TARGET}";
  982. local count=0;
  983. local PATCH_TARGET;
  984. if [[ -n ${PIPE_CMD} ]]; then
  985. PATCH_TARGET="${T}/$$.patch";
  986. echo "PIPE_COMMAND: ${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> "${STDERR_TARGET}";
  987. if ! ( ${PIPE_CMD} "${x}" > "${PATCH_TARGET}" ) >> "${STDERR_TARGET}" 2>&1; then
  988. echo;
  989. eerror "Could not extract patch!";
  990. count=5;
  991. break;
  992. fi;
  993. else
  994. PATCH_TARGET=${x};
  995. fi;
  996. local abs_paths=$(egrep -n '^[-+]{3} /' "${PATCH_TARGET}" | awk '$2 != "/dev/null" { print }');
  997. if [[ -n ${abs_paths} ]]; then
  998. count=1;
  999. printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}";
  1000. fi;
  1001. local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}");
  1002. if [[ -n ${rel_paths} ]]; then
  1003. echo;
  1004. eerror "Rejected Patch: ${patchname} !";
  1005. eerror " ( ${PATCH_TARGET} )";
  1006. eerror;
  1007. eerror "Your patch uses relative paths '../':";
  1008. eerror "${rel_paths}";
  1009. echo;
  1010. die "you need to fix the relative paths in patch";
  1011. fi;
  1012. local patch_cmd;
  1013. while [[ ${count} -lt 5 ]]; do
  1014. patch_cmd="${patch} -p${count} ${EPATCH_OPTS}";
  1015. ( _epatch_draw_line "***** ${patchname} *****";
  1016. echo;
  1017. echo "PATCH COMMAND: ${patch_cmd} --dry-run -f < '${PATCH_TARGET}'";
  1018. echo;
  1019. _epatch_draw_line "***** ${patchname} *****";
  1020. ${patch_cmd} --dry-run -f < "${PATCH_TARGET}" 2>&1;
  1021. ret=$?;
  1022. echo;
  1023. echo "patch program exited with status ${ret}";
  1024. exit ${ret} ) >> "${STDERR_TARGET}";
  1025. if [ $? -eq 0 ]; then
  1026. ( _epatch_draw_line "***** ${patchname} *****";
  1027. echo;
  1028. echo "ACTUALLY APPLYING ${patchname} ...";
  1029. echo "PATCH COMMAND: ${patch_cmd} < '${PATCH_TARGET}'";
  1030. echo;
  1031. _epatch_draw_line "***** ${patchname} *****";
  1032. ${patch_cmd} < "${PATCH_TARGET}" 2>&1;
  1033. ret=$?;
  1034. echo;
  1035. echo "patch program exited with status ${ret}";
  1036. exit ${ret} ) >> "${STDERR_TARGET}";
  1037. if [ $? -ne 0 ]; then
  1038. echo;
  1039. eerror "A dry-run of patch command succeeded, but actually";
  1040. eerror "applying the patch failed!";
  1041. count=5;
  1042. fi;
  1043. break;
  1044. fi;
  1045. : $(( count++ ));
  1046. done;
  1047. (( EPATCH_N_APPLIED_PATCHES++ ));
  1048. if [[ -n ${PIPE_CMD} ]]; then
  1049. rm -f "${PATCH_TARGET}";
  1050. fi;
  1051. if [[ ${count} -ge 5 ]]; then
  1052. echo;
  1053. eerror "Failed Patch: ${patchname} !";
  1054. eerror " ( ${PATCH_TARGET} )";
  1055. eerror;
  1056. eerror "Include in your bugreport the contents of:";
  1057. eerror;
  1058. eerror " ${STDERR_TARGET}";
  1059. echo;
  1060. die "Failed Patch: ${patchname}!";
  1061. fi;
  1062. rm -f "${STDERR_TARGET}";
  1063. cat >> "${T}/epatch.log" <<-EOF
  1064. PATCH: ${x}
  1065. CMD: ${patch_cmd}
  1066. PWD: ${PWD}
  1067. EOF
  1068. eend 0;
  1069. done;
  1070. [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching";
  1071. :
  1072. }
  1073. epatch_user ()
  1074. {
  1075. [[ $# -ne 0 ]] && die "epatch_user takes no options";
  1076. local applied="${T}/epatch_user.log";
  1077. [[ -e ${applied} ]] && return 2;
  1078. local EPATCH_SOURCE check;
  1079. for check in ${CATEGORY}/{${P}-${PR},${P},${PN}}{,:${SLOT%/*}};
  1080. do
  1081. EPATCH_SOURCE=${EPATCH_USER_SOURCE}/${CTARGET}/${check};
  1082. [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${EPATCH_USER_SOURCE}/${CHOST}/${check};
  1083. [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${EPATCH_USER_SOURCE}/${check};
  1084. if [[ -d ${EPATCH_SOURCE} ]]; then
  1085. local old_n_applied_patches=${EPATCH_N_APPLIED_PATCHES:-0};
  1086. EPATCH_SOURCE=${EPATCH_SOURCE} EPATCH_SUFFIX="patch" EPATCH_FORCE="yes" EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." epatch;
  1087. echo "${EPATCH_SOURCE}" > "${applied}";
  1088. if [[ ${old_n_applied_patches} -lt ${EPATCH_N_APPLIED_PATCHES} ]]; then
  1089. has epatch_user_death_notice ${EBUILD_DEATH_HOOKS} || EBUILD_DEATH_HOOKS+=" epatch_user_death_notice";
  1090. fi;
  1091. return 0;
  1092. fi;
  1093. done;
  1094. echo "none" > "${applied}";
  1095. return 1
  1096. }
  1097. epatch_user_death_notice ()
  1098. {
  1099. ewarn "!!! User patches were applied to this build!"
  1100. }
  1101. epause ()
  1102. {
  1103. ewarn "QA Notice: epause is not defined in EAPI=${EAPI}, please file a bug at https://bugs.gentoo.org"
  1104. }
  1105. eprefixify ()
  1106. {
  1107. [[ $# -lt 1 ]] && die "at least one argument required";
  1108. einfo "Adjusting to prefix ${EPREFIX:-/}";
  1109. local x;
  1110. for x in "$@";
  1111. do
  1112. if [[ -e ${x} ]]; then
  1113. ebegin " ${x##*/}";
  1114. sed -i -e "s|@GENTOO_PORTAGE_EPREFIX@|${EPREFIX}|g" "${x}";
  1115. eend $? || die "failed to eprefixify ${x}";
  1116. else
  1117. die "${x} does not exist";
  1118. fi;
  1119. done;
  1120. return 0
  1121. }
  1122. eshopts_pop ()
  1123. {
  1124. local s;
  1125. estack_pop eshopts s || die "${FUNCNAME}: unbalanced push";
  1126. eval "${s}" || die "${FUNCNAME}: sanity: invalid shopt options: ${s}"
  1127. }
  1128. eshopts_push ()
  1129. {
  1130. if [[ $1 == -[su] ]]; then
  1131. estack_push eshopts "$(shopt -p)";
  1132. [[ $# -eq 0 ]] && return 0;
  1133. shopt "$@" || die "${FUNCNAME}: bad options to shopt: $*";
  1134. else
  1135. estack_push eshopts "$(shopt -p -o)";
  1136. [[ $# -eq 0 ]] && return 0;
  1137. set "$@" || die "${FUNCNAME}: bad options to set: $*";
  1138. fi
  1139. }
  1140. estack_pop ()
  1141. {
  1142. [[ $# -eq 0 || $# -gt 2 ]] && die "estack_pop: incorrect # of arguments";
  1143. local _estack_name="_ESTACK_$1_";
  1144. shift;
  1145. local _estack_retvar=$1;
  1146. shift;
  1147. eval local _estack_i=\${#${_estack_name}\[@\]};
  1148. [[ $(( --_estack_i )) -eq -1 ]] && return 1;
  1149. if [[ -n ${_estack_retvar} ]]; then
  1150. eval ${_estack_retvar}=\"\${${_estack_name}\[${_estack_i}\]}\";
  1151. fi;
  1152. eval unset \"${_estack_name}\[${_estack_i}\]\"
  1153. }
  1154. estack_push ()
  1155. {
  1156. [[ $# -eq 0 ]] && die "estack_push: incorrect # of arguments";
  1157. local stack_name="_ESTACK_$1_";
  1158. shift;
  1159. eval ${stack_name}+=\( \"\$@\" \)
  1160. }
  1161. esvn_clean ()
  1162. {
  1163. [[ $# -eq 0 ]] && set -- .;
  1164. find "$@" -type d -name '.svn' -prune -exec rm -rf '{}' +
  1165. }
  1166. eumask_pop ()
  1167. {
  1168. [[ $# -eq 0 ]] || die "${FUNCNAME}: we take no options";
  1169. local s;
  1170. estack_pop eumask s || die "${FUNCNAME}: unbalanced push";
  1171. umask ${s} || die "${FUNCNAME}: sanity: could not restore umask: ${s}"
  1172. }
  1173. eumask_push ()
  1174. {
  1175. estack_push eumask "$(umask)";
  1176. umask "$@" || die "${FUNCNAME}: bad options to umask: $*"
  1177. }
  1178. evar_pop ()
  1179. {
  1180. local cnt=${1:-bad};
  1181. case $# in
  1182. 0)
  1183. cnt=1
  1184. ;;
  1185. 1)
  1186. isdigit "${cnt}" || die "${FUNCNAME}: first arg must be a number: $*"
  1187. ;;
  1188. *)
  1189. die "${FUNCNAME}: only accepts one arg: $*"
  1190. ;;
  1191. esac;
  1192. local var val;
  1193. while (( cnt-- )); do
  1194. estack_pop evar val || die "${FUNCNAME}: unbalanced push";
  1195. estack_pop evar var || die "${FUNCNAME}: unbalanced push";
  1196. [[ ${val} == "unset_76fc3c462065bb4ca959f939e6793f94" ]] && unset ${var} || printf -v "${var}" '%s' "${val}";
  1197. done
  1198. }
  1199. evar_push ()
  1200. {
  1201. local var val;
  1202. for var in "$@";
  1203. do
  1204. [[ ${!var+set} == "set" ]] && val=${!var} || val="unset_76fc3c462065bb4ca959f939e6793f94";
  1205. estack_push evar "${var}" "${val}";
  1206. done
  1207. }
  1208. evar_push_set ()
  1209. {
  1210. local var=$1;
  1211. evar_push ${var};
  1212. case $# in
  1213. 1)
  1214. unset ${var}
  1215. ;;
  1216. 2)
  1217. printf -v "${var}" '%s' "$2"
  1218. ;;
  1219. *)
  1220. die "${FUNCNAME}: incorrect # of args: $*"
  1221. ;;
  1222. esac
  1223. }
  1224. filter-flags ()
  1225. {
  1226. _filter-hardened "$@";
  1227. local v;
  1228. for v in $(all-flag-vars);
  1229. do
  1230. _filter-var ${v} "$@";
  1231. done;
  1232. return 0
  1233. }
  1234. filter-ldflags ()
  1235. {
  1236. _filter-var LDFLAGS "$@";
  1237. return 0
  1238. }
  1239. filter-lfs-flags ()
  1240. {
  1241. [[ $# -ne 0 ]] && die "filter-lfs-flags takes no arguments";
  1242. filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
  1243. }
  1244. filter-mfpmath ()
  1245. {
  1246. local orig_mfpmath new_math prune_math;
  1247. orig_mfpmath=$(get-flag -mfpmath);
  1248. new_math=$(get-flag mfpmath);
  1249. new_math=${new_math/both/387,sse};
  1250. new_math=" ${new_math//[,+]/ } ";
  1251. prune_math="";
  1252. for prune_math in "$@";
  1253. do
  1254. new_math=${new_math/ ${prune_math} / };
  1255. done;
  1256. new_math=$(echo ${new_math});
  1257. new_math=${new_math// /,};
  1258. if [[ -z ${new_math} ]]; then
  1259. filter-flags ${orig_mfpmath};
  1260. else
  1261. replace-flags ${orig_mfpmath} -mfpmath=${new_math};
  1262. fi;
  1263. return 0
  1264. }
  1265. fix_libtool_libdir_paths ()
  1266. {
  1267. local libpath="$1";
  1268. pushd "${D}" > /dev/null;
  1269. pushd "./${libpath}" > /dev/null;
  1270. local dir="${PWD#${D%/}}";
  1271. local allarchives=$(echo *.la);
  1272. allarchives="\(${allarchives// /\\|}\)";
  1273. popd > /dev/null;
  1274. find "./${dir}" -maxdepth 1 -name '*.la' -exec sed -i -e "/^libdir=/s:=.*:='${dir}':" {} + || die;
  1275. find "./${PREFIX}"/lib* -maxdepth 3 -name '*.la' -exec sed -i -e "/^dependency_libs=/s:/[^ ]*/${allarchives}:${libpath}/\1:g" {} + || die;
  1276. find "./${dir}/" -maxdepth 1 -name '*.la' -exec sed -i -e "/^dependency_libs=/s:/[^ ]*/${allarchives}:${libpath}/\1:g" {} + || die;
  1277. popd > /dev/null
  1278. }
  1279. gcc-abi-map ()
  1280. {
  1281. local map=();
  1282. case ${CTARGET} in
  1283. mips*)
  1284. map=("o32 32" "n32 n32" "n64 64")
  1285. ;;
  1286. x86_64*)
  1287. map=("amd64 m64" "x86 m32" "x32 mx32")
  1288. ;;
  1289. esac;
  1290. local m;
  1291. for m in "${map[@]}";
  1292. do
  1293. l=(${m});
  1294. [[ $1 == ${l[0]} ]] && echo ${l[1]} && break;
  1295. done
  1296. }
  1297. gcc-fullversion ()
  1298. {
  1299. _gcc_fullversion '$1.$2.$3' "$@"
  1300. }
  1301. gcc-lang-supported ()
  1302. {
  1303. grep ^language=\"${1}\" "${S}"/gcc/*/config-lang.in > /dev/null || return 1;
  1304. [[ -z ${TOOLCHAIN_ALLOWED_LANGS} ]] && return 0;
  1305. has $1 ${TOOLCHAIN_ALLOWED_LANGS}
  1306. }
  1307. gcc-major-version ()
  1308. {
  1309. _gcc_fullversion '$1' "$@"
  1310. }
  1311. gcc-micro-version ()
  1312. {
  1313. _gcc_fullversion '$3' "$@"
  1314. }
  1315. gcc-minor-version ()
  1316. {
  1317. _gcc_fullversion '$2' "$@"
  1318. }
  1319. gcc-multilib-configure ()
  1320. {
  1321. if ! is_multilib; then
  1322. confgcc+=(--disable-multilib);
  1323. else
  1324. confgcc+=(--enable-multilib);
  1325. fi;
  1326. local abi list;
  1327. for abi in $(get_all_abis TARGET);
  1328. do
  1329. local l=$(gcc-abi-map ${abi});
  1330. [[ -n ${l} ]] && list+=",${l}";
  1331. done;
  1332. if [[ -n ${list} ]]; then
  1333. case ${CTARGET} in
  1334. x86_64*)
  1335. tc_version_is_at_least 4.8 && confgcc+=(--with-multilib-list=${list:1})
  1336. ;;
  1337. esac;
  1338. fi
  1339. }
  1340. gcc-specs-directive ()
  1341. {
  1342. local directive subdname subdirective;
  1343. directive="$(_gcc-specs-directive_raw $1)";
  1344. while [[ ${directive} == *%\(*\)* ]]; do
  1345. subdname=${directive/*%\(};
  1346. subdname=${subdname/\)*};
  1347. subdirective="$(_gcc-specs-directive_raw ${subdname})";
  1348. directive="${directive//\%(${subdname})/${subdirective}}";
  1349. done;
  1350. echo "${directive}";
  1351. return 0
  1352. }
  1353. gcc-specs-nostrict ()
  1354. {
  1355. local directive;
  1356. directive=$(gcc-specs-directive cc1);
  1357. [[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]]
  1358. }
  1359. gcc-specs-now ()
  1360. {
  1361. local directive;
  1362. directive=$(gcc-specs-directive link_command);
  1363. [[ "${directive/\{!nonow:}" != "${directive}" ]]
  1364. }
  1365. gcc-specs-pie ()
  1366. {
  1367. local directive;
  1368. directive=$(gcc-specs-directive cc1);
  1369. [[ "${directive/\{!nopie:}" != "${directive}" ]]
  1370. }
  1371. gcc-specs-relro ()
  1372. {
  1373. local directive;
  1374. directive=$(gcc-specs-directive link_command);
  1375. [[ "${directive/\{!norelro:}" != "${directive}" ]]
  1376. }
  1377. gcc-specs-ssp ()
  1378. {
  1379. local directive;
  1380. directive=$(gcc-specs-directive cc1);
  1381. [[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]]
  1382. }
  1383. gcc-specs-ssp-to-all ()
  1384. {
  1385. local directive;
  1386. directive=$(gcc-specs-directive cc1);
  1387. [[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]]
  1388. }
  1389. gcc-specs-stack-check ()
  1390. {
  1391. local directive;
  1392. directive=$(gcc-specs-directive cc1);
  1393. [[ "${directive/\{!fno-stack-check:}" != "${directive}" ]]
  1394. }
  1395. gcc-version ()
  1396. {
  1397. _gcc_fullversion '$1.$2' "$@"
  1398. }
  1399. gcc_do_filter_flags ()
  1400. {
  1401. strip-flags;
  1402. replace-flags -O? -O2;
  1403. filter-flags '-mabi*' -m31 -m32 -m64;
  1404. filter-flags -frecord-gcc-switches;
  1405. filter-flags -mno-rtm -mno-htm;
  1406. if tc_version_is_between 3.2 3.4; then
  1407. replace-cpu-flags G3 750;
  1408. replace-cpu-flags G4 7400;
  1409. replace-cpu-flags G5 7400;
  1410. filter-flags -f{no-,}unit-at-a-time -f{no-,}web -mno-tls-direct-seg-refs;
  1411. filter-flags -f{no-,}stack-protector{,-all};
  1412. filter-flags -fvisibility-inlines-hidden -fvisibility=hidden;
  1413. fi;
  1414. if tc_version_is_at_least 3.4; then
  1415. case $(tc-arch) in
  1416. amd64 | x86)
  1417. filter-flags '-mcpu=*';
  1418. tc_version_is_between 4.4 4.5 && append-flags -mno-avx;
  1419. if tc_version_is_between 4.6 4.7; then
  1420. replace-cpu-flags c3-2 pentium2 pentium3 pentium3m pentium-m i686;
  1421. fi
  1422. ;;
  1423. alpha)
  1424. append-ldflags -Wl,--no-relax
  1425. ;;
  1426. sparc)
  1427. tc_version_is_between 4.6 4.8 && MAKEOPTS+=" -j1"
  1428. ;;
  1429. *-macos)
  1430. tc_version_is_between 4.0 4.2 && filter-flags '-mcpu=*' '-march=*' '-mtune=*'
  1431. ;;
  1432. esac;
  1433. fi;
  1434. strip-unsupported-flags;
  1435. if is_crosscompile; then
  1436. CFLAGS="-O2 -pipe";
  1437. FFLAGS=${CFLAGS};
  1438. FCFLAGS=${CFLAGS};
  1439. local VAR="CFLAGS_"${CTARGET//[-.]/_};
  1440. CXXFLAGS=${!VAR-${CFLAGS}};
  1441. fi;
  1442. export GCJFLAGS=${GCJFLAGS:-${CFLAGS}}
  1443. }
  1444. gcc_do_make ()
  1445. {
  1446. [[ -n ${1} ]] && GCC_MAKE_TARGET=${1};
  1447. if is_crosscompile || tc-is-cross-compiler; then
  1448. GCC_MAKE_TARGET=${GCC_MAKE_TARGET-all};
  1449. else
  1450. if tc_version_is_at_least 3.3 && use_if_iuse pgo; then
  1451. GCC_MAKE_TARGET=${GCC_MAKE_TARGET-profiledbootstrap};
  1452. else
  1453. GCC_MAKE_TARGET=${GCC_MAKE_TARGET-bootstrap-lean};
  1454. fi;
  1455. fi;
  1456. if [[ ${GCC_MAKE_TARGET} == "profiledbootstrap" ]] || use_if_iuse boundschecking; then
  1457. ! tc_version_is_at_least 4.6 && export MAKEOPTS="${MAKEOPTS} -j1";
  1458. fi;
  1459. if [[ ${GCC_MAKE_TARGET} == "all" ]]; then
  1460. STAGE1_CFLAGS=${STAGE1_CFLAGS-"${CFLAGS}"};
  1461. else
  1462. if [[ $(gcc-version) == "3.4" && ${GCC_BRANCH_VER} == "3.4" ]] && gcc-specs-ssp; then
  1463. STAGE1_CFLAGS=${STAGE1_CFLAGS-"-O2"};
  1464. fi;
  1465. fi;
  1466. if is_crosscompile; then
  1467. BOOT_CFLAGS=${BOOT_CFLAGS-"-O2"};
  1468. else
  1469. BOOT_CFLAGS=${BOOT_CFLAGS-"$(get_abi_CFLAGS ${TARGET_DEFAULT_ABI}) ${CFLAGS}"};
  1470. fi;
  1471. einfo "Compiling ${PN} (${GCC_MAKE_TARGET})...";
  1472. pushd "${WORKDIR}"/build > /dev/null;
  1473. emake LDFLAGS="${LDFLAGS}" STAGE1_CFLAGS="${STAGE1_CFLAGS}" LIBPATH="${LIBPATH}" BOOT_CFLAGS="${BOOT_CFLAGS}" ${GCC_MAKE_TARGET} || die "emake failed with ${GCC_MAKE_TARGET}";
  1474. if ! is_crosscompile && use_if_iuse cxx && use_if_iuse doc; then
  1475. if type -p doxygen > /dev/null; then
  1476. if tc_version_is_at_least 4.3; then
  1477. cd "${CTARGET}"/libstdc++-v3/doc;
  1478. emake doc-man-doxygen || ewarn "failed to make docs";
  1479. else
  1480. if tc_version_is_at_least 3.0; then
  1481. cd "${CTARGET}"/libstdc++-v3;
  1482. emake doxygen-man || ewarn "failed to make docs";
  1483. fi;
  1484. fi;
  1485. find -name '*_build_*' -delete;
  1486. find -name '*_.3' -exec grep -l ' Directory Reference ' {} + | xargs rm -f;
  1487. else
  1488. ewarn "Skipping libstdc++ manpage generation since you don't have doxygen installed";
  1489. fi;
  1490. fi;
  1491. popd > /dev/null
  1492. }
  1493. gcc_movelibs ()
  1494. {
  1495. tc_version_is_at_least 3.2 || return 0;
  1496. if tc_version_is_at_least 5 && is_crosscompile; then
  1497. dodir "${HOSTLIBPATH#${EPREFIX}}";
  1498. mv "${ED}"usr/$(get_libdir)/libcc1* "${D}${HOSTLIBPATH}" || die;
  1499. fi;
  1500. local x multiarg removedirs="";
  1501. for multiarg in $($(XGCC) -print-multi-lib);
  1502. do
  1503. multiarg=${multiarg#*;};
  1504. multiarg=${multiarg//@/ -};
  1505. local OS_MULTIDIR=$($(XGCC) ${multiarg} --print-multi-os-directory);
  1506. local MULTIDIR=$($(XGCC) ${multiarg} --print-multi-directory);
  1507. local TODIR="${D}${LIBPATH}"/${MULTIDIR};
  1508. local FROMDIR=;
  1509. [[ -d ${TODIR} ]] || mkdir -p ${TODIR};
  1510. for FROMDIR in "${LIBPATH}"/${OS_MULTIDIR} "${LIBPATH}"/../${MULTIDIR} "${PREFIX}"/lib/${OS_MULTIDIR} "${PREFIX}"/${CTARGET}/lib/${OS_MULTIDIR};
  1511. do
  1512. removedirs="${removedirs} ${FROMDIR}";
  1513. FROMDIR=${D}${FROMDIR};
  1514. if [[ ${FROMDIR} != "${TODIR}" && -d ${FROMDIR} ]]; then
  1515. local files=$(find "${FROMDIR}" -maxdepth 1 ! -type d 2>/dev/null);
  1516. if [[ -n ${files} ]]; then
  1517. mv ${files} "${TODIR}" || die;
  1518. fi;
  1519. fi;
  1520. done;
  1521. fix_libtool_libdir_paths "${LIBPATH}/${MULTIDIR}";
  1522. FROMDIR="${PREFIX}/lib/${OS_MULTIDIR}";
  1523. for x in "${D}${FROMDIR}"/pkgconfig/libgcj*.pc;
  1524. do
  1525. [[ -f ${x} ]] || continue;
  1526. sed -i "/^libdir=/s:=.*:=${LIBPATH}/${MULTIDIR}:" "${x}" || die;
  1527. mv "${x}" "${D}${FROMDIR}"/pkgconfig/libgcj-${GCC_PV}.pc || die;
  1528. done;
  1529. done;
  1530. for FROMDIR in ${removedirs};
  1531. do
  1532. rmdir "${D}"${FROMDIR} &> /dev/null;
  1533. done;
  1534. find -depth "${D}" -type d -exec rmdir {} + &> /dev/null
  1535. }
  1536. gcc_quick_unpack ()
  1537. {
  1538. pushd "${WORKDIR}" > /dev/null;
  1539. export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}};
  1540. export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}};
  1541. export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}};
  1542. export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}};
  1543. export SPECS_GCC_VER=${SPECS_GCC_VER:-${GCC_RELEASE_VER}};
  1544. if [[ -n ${GCC_A_FAKEIT} ]]; then
  1545. unpack ${GCC_A_FAKEIT};
  1546. else
  1547. if [[ -n ${PRERELEASE} ]]; then
  1548. unpack gcc-${PRERELEASE}.tar.bz2;
  1549. else
  1550. if [[ -n ${SNAPSHOT} ]]; then
  1551. if tc_version_is_between 5.5 6 || tc_version_is_between 6.4 7 || tc_version_is_at_least 7.2; then
  1552. unpack gcc-${SNAPSHOT}.tar.xz;
  1553. else
  1554. unpack gcc-${SNAPSHOT}.tar.bz2;
  1555. fi;
  1556. else
  1557. if [[ ${PV} != *9999* ]]; then
  1558. if tc_version_is_between 5.5 6 || tc_version_is_between 6.4 7 || tc_version_is_at_least 7.2; then
  1559. unpack gcc-${GCC_RELEASE_VER}.tar.xz;
  1560. else
  1561. unpack gcc-${GCC_RELEASE_VER}.tar.bz2;
  1562. fi;
  1563. if [[ -n ${BRANCH_UPDATE} ]]; then
  1564. pushd "${S}" > /dev/null;
  1565. epatch "${DISTDIR}"/gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2;
  1566. popd > /dev/null;
  1567. fi;
  1568. fi;
  1569. fi;
  1570. fi;
  1571. fi;
  1572. if [[ -n ${D_VER} ]] && use d; then
  1573. pushd "${S}"/gcc > /dev/null;
  1574. unpack gdc-${D_VER}-src.tar.bz2;
  1575. cd ..;
  1576. ebegin "Adding support for the D language";
  1577. ./gcc/d/setup-gcc.sh &> "${T}"/dgcc.log;
  1578. if ! eend $?; then
  1579. eerror "The D GCC package failed to apply";
  1580. eerror "Please include this log file when posting a bug report:";
  1581. eerror " ${T}/dgcc.log";
  1582. die "failed to include the D language";
  1583. fi;
  1584. popd > /dev/null;
  1585. fi;
  1586. [[ -n ${PATCH_VER} ]] && unpack gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2;
  1587. [[ -n ${UCLIBC_VER} ]] && unpack gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}.tar.bz2;
  1588. if want_pie; then
  1589. if [[ -n ${PIE_CORE} ]]; then
  1590. unpack ${PIE_CORE};
  1591. else
  1592. unpack gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}.tar.bz2;
  1593. fi;
  1594. [[ -n ${SPECS_VER} ]] && unpack gcc-${SPECS_GCC_VER}-specs-${SPECS_VER}.tar.bz2;
  1595. fi;
  1596. use_if_iuse boundschecking && unpack "bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2";
  1597. popd > /dev/null
  1598. }
  1599. gcc_slot_java ()
  1600. {
  1601. local x;
  1602. for x in "${D}${PREFIX}"/include/gc*.h "${D}${PREFIX}"/include/j*.h;
  1603. do
  1604. [[ -f ${x} ]] && mv -f "${x}" "${D}${LIBPATH}"/include/;
  1605. done;
  1606. for x in gcj gnu java javax org;
  1607. do
  1608. if [[ -d ${D}${PREFIX}/include/${x} ]]; then
  1609. dodir /${LIBPATH#${EPREFIX}}/include/${x};
  1610. mv -f "${D}${PREFIX}"/include/${x}/* "${D}${LIBPATH}"/include/${x}/;
  1611. rm -rf "${D}${PREFIX}"/include/${x};
  1612. fi;
  1613. done;
  1614. if [[ -d ${D}${PREFIX}/lib/security ]] || [[ -d ${D}${PREFIX}/$(get_libdir)/security ]]; then
  1615. dodir /${LIBPATH#${EPREFIX}}/security;
  1616. mv -f "${D}${PREFIX}"/lib*/security/* "${D}${LIBPATH}"/security;
  1617. rm -rf "${D}${PREFIX}"/lib*/security;
  1618. fi;
  1619. for x in libgcj.spec logging.properties;
  1620. do
  1621. x="${D}${PREFIX}/lib/${x}";
  1622. [[ -f ${x} ]] && mv -f "${x}" "${D}${LIBPATH}"/;
  1623. done;
  1624. cd "${D}${BINPATH}";
  1625. [[ -f jar ]] && mv -f jar gcj-jar
  1626. }
  1627. gcc_version_patch ()
  1628. {
  1629. tc_version_is_at_least 4.3 && return 0;
  1630. local version_string=${GCC_CONFIG_VER};
  1631. [[ -n ${BRANCH_UPDATE} ]] && version_string+=" ${BRANCH_UPDATE}";
  1632. einfo "patching gcc version: ${version_string} (${BRANDING_GCC_PKGVERSION})";
  1633. local gcc_sed=(-e 's:gcc\.gnu\.org/bugs\.html:bugs\.gentoo\.org/:');
  1634. if grep -qs VERSUFFIX "${S}"/gcc/version.c; then
  1635. gcc_sed+=(-e "/VERSUFFIX \"\"/s:\"\":\" (${BRANDING_GCC_PKGVERSION})\":");
  1636. else
  1637. version_string="${version_string} (${BRANDING_GCC_PKGVERSION})";
  1638. gcc_sed+=(-e "/const char version_string\[\] = /s:= \".*\":= \"${version_string}\":");
  1639. fi;
  1640. sed -i "${gcc_sed[@]}" "${S}"/gcc/version.c || die
  1641. }
  1642. gen_usr_ldscript ()
  1643. {
  1644. local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname);
  1645. [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/;
  1646. tc-is-static-only && return;
  1647. if [[ $(type -t multilib_is_native_abi) == "function" ]]; then
  1648. multilib_is_native_abi || return 0;
  1649. fi;
  1650. case ${CTARGET:-${CHOST}} in
  1651. *-darwin*)
  1652. ;;
  1653. *-android*)
  1654. return 0
  1655. ;;
  1656. *linux* | *-freebsd* | *-openbsd* | *-netbsd*)
  1657. use prefix && return 0
  1658. ;;
  1659. *)
  1660. return 0
  1661. ;;
  1662. esac;
  1663. dodir /usr/${libdir};
  1664. if [[ $1 == "-a" ]]; then
  1665. auto=true;
  1666. shift;
  1667. dodir /${libdir};
  1668. fi;
  1669. local flags=(${CFLAGS} ${LDFLAGS} -Wl,--verbose);
  1670. if $(tc-getLD) --version | grep -q 'GNU gold'; then
  1671. local d="${T}/bfd-linker";
  1672. mkdir -p "${d}";
  1673. ln -sf $(which ${CHOST}-ld.bfd) "${d}"/ld;
  1674. flags+=(-B"${d}");
  1675. fi;
  1676. output_format=$($(tc-getCC) "${flags[@]}" 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p');
  1677. [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )";
  1678. for lib in "$@";
  1679. do
  1680. local tlib;
  1681. if ${auto}; then
  1682. lib="lib${lib}${suffix}";
  1683. else
  1684. [[ -r ${ED}/${libdir}/${lib} ]] || continue;
  1685. fi;
  1686. case ${CTARGET:-${CHOST}} in
  1687. *-darwin*)
  1688. if ${auto}; then
  1689. tlib=$(scanmacho -qF'%S#F' "${ED}"/usr/${libdir}/${lib});
  1690. else
  1691. tlib=$(scanmacho -qF'%S#F' "${ED}"/${libdir}/${lib});
  1692. fi;
  1693. [[ -z ${tlib} ]] && die "unable to read install_name from ${lib}";
  1694. tlib=${tlib##*/};
  1695. if ${auto}; then
  1696. mv "${ED}"/usr/${libdir}/${lib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die;
  1697. if [[ ${tlib} != ${lib%${suffix}}.*${suffix#.} ]]; then
  1698. mv "${ED}"/usr/${libdir}/${tlib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die;
  1699. fi;
  1700. rm -f "${ED}"/${libdir}/${lib};
  1701. fi;
  1702. if [[ ! -w "${ED}/${libdir}/${tlib}" ]]; then
  1703. chmod u+w "${ED}${libdir}/${tlib}";
  1704. local nowrite=yes;
  1705. fi;
  1706. install_name_tool -id "${EPREFIX}"/${libdir}/${tlib} "${ED}"/${libdir}/${tlib} || die "install_name_tool failed";
  1707. [[ -n ${nowrite} ]] && chmod u-w "${ED}${libdir}/${tlib}";
  1708. pushd "${ED}/usr/${libdir}" > /dev/null;
  1709. ln -snf "../../${libdir}/${tlib}" "${lib}";
  1710. popd > /dev/null
  1711. ;;
  1712. *)
  1713. if ${auto}; then
  1714. tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib});
  1715. [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}";
  1716. mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die;
  1717. if [[ ${tlib} != ${lib}* ]]; then
  1718. mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die;
  1719. fi;
  1720. rm -f "${ED}"/${libdir}/${lib};
  1721. else
  1722. tlib=${lib};
  1723. fi;
  1724. cat > "${ED}/usr/${libdir}/${lib}" <<-END_LDSCRIPT
  1725. /* GNU ld script
  1726. Since Gentoo has critical dynamic libraries in /lib, and the static versions
  1727. in /usr/lib, we need to have a "fake" dynamic lib in /usr/lib, otherwise we
  1728. run into linking problems. This "fake" dynamic lib is a linker script that
  1729. redirects the linker to the real lib. And yes, this works in the cross-
  1730. compiling scenario as the sysroot-ed linker will prepend the real path.
  1731. See bug https://bugs.gentoo.org/4411 for more info.
  1732. */
  1733. ${output_format}
  1734. GROUP ( ${EPREFIX}/${libdir}/${tlib} )
  1735. END_LDSCRIPT
  1736. ;;
  1737. esac
  1738. fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}";
  1739. done
  1740. }
  1741. gentoo_urls ()
  1742. {
  1743. local devspace="HTTP~vapier/dist/URI HTTP~rhill/dist/URI
  1744. HTTP~zorry/patches/gcc/URI HTTP~blueness/dist/URI
  1745. HTTP~tamiko/distfiles/URI HTTP~slyfox/distfiles/URI";
  1746. devspace=${devspace//HTTP/https:\/\/dev.gentoo.org\/};
  1747. echo mirror://gentoo/$1 ${devspace//URI/$1}
  1748. }
  1749. get-flag ()
  1750. {
  1751. local f var findflag="$1";
  1752. for var in $(all-flag-vars);
  1753. do
  1754. for f in ${!var};
  1755. do
  1756. if [ "${f/${findflag}}" != "${f}" ]; then
  1757. printf "%s\n" "${f/-${findflag}=}";
  1758. return 0;
  1759. fi;
  1760. done;
  1761. done;
  1762. return 1
  1763. }
  1764. get_abi_CFLAGS ()
  1765. {
  1766. get_abi_var CFLAGS "$@"
  1767. }
  1768. get_abi_CHOST ()
  1769. {
  1770. get_abi_var CHOST "$@"
  1771. }
  1772. get_abi_CTARGET ()
  1773. {
  1774. get_abi_var CTARGET "$@"
  1775. }
  1776. get_abi_FAKE_TARGETS ()
  1777. {
  1778. get_abi_var FAKE_TARGETS "$@"
  1779. }
  1780. get_abi_LDFLAGS ()
  1781. {
  1782. get_abi_var LDFLAGS "$@"
  1783. }
  1784. get_abi_LIBDIR ()
  1785. {
  1786. get_abi_var LIBDIR "$@"
  1787. }
  1788. get_abi_var ()
  1789. {
  1790. local flag=$1;
  1791. local abi=${2:-${ABI:-${DEFAULT_ABI:-default}}};
  1792. local var="${flag}_${abi}";
  1793. echo ${!var}
  1794. }
  1795. get_after_major_version ()
  1796. {
  1797. echo $(get_version_component_range 2- "${1:-${PV}}")
  1798. }
  1799. get_all_abis ()
  1800. {
  1801. local x order="" mvar dvar;
  1802. mvar="MULTILIB_ABIS";
  1803. dvar="DEFAULT_ABI";
  1804. if [[ -n $1 ]]; then
  1805. mvar="$1_${mvar}";
  1806. dvar="$1_${dvar}";
  1807. fi;
  1808. if [[ -z ${!mvar} ]]; then
  1809. echo "default";
  1810. return 0;
  1811. fi;
  1812. for x in ${!mvar};
  1813. do
  1814. if [[ ${x} != ${!dvar} ]]; then
  1815. order="${order:+${order} }${x}";
  1816. fi;
  1817. done;
  1818. order="${order:+${order} }${!dvar}";
  1819. echo ${order};
  1820. return 0
  1821. }
  1822. get_all_libdirs ()
  1823. {
  1824. local libdirs abi;
  1825. for abi in ${MULTILIB_ABIS};
  1826. do
  1827. libdirs+=" $(get_abi_LIBDIR ${abi})";
  1828. done;
  1829. [[ " ${libdirs} " != *" lib "* ]] && libdirs+=" lib";
  1830. echo "${libdirs}"
  1831. }
  1832. get_all_version_components ()
  1833. {
  1834. eshopts_push -s extglob;
  1835. local ver_str=${1:-${PV}} result;
  1836. result=();
  1837. if [[ ${VERSIONATOR_CACHE_VER_STR} == ${ver_str} ]]; then
  1838. echo ${VERSIONATOR_CACHE_RESULT};
  1839. eshopts_pop;
  1840. return;
  1841. fi;
  1842. export VERSIONATOR_CACHE_VER_STR=${ver_str};
  1843. while [[ -n $ver_str ]]; do
  1844. case "${ver_str::1}" in
  1845. [[:digit:]])
  1846. result+=("${ver_str%%[^[:digit:]]*}");
  1847. ver_str=${ver_str##+([[:digit:]])}
  1848. ;;
  1849. [-_.])
  1850. result+=("${ver_str::1}");
  1851. ver_str=${ver_str:1}
  1852. ;;
  1853. [[:alpha:]])
  1854. local not_match=${ver_str##+([[:alpha:]])*([[:digit:]])};
  1855. result+=("${ver_str::${#ver_str} - ${#not_match}}");
  1856. ver_str=${not_match}
  1857. ;;
  1858. *)
  1859. result+=("${ver_str::1}");
  1860. ver_str=${ver_str:1}
  1861. ;;
  1862. esac;
  1863. done;
  1864. export VERSIONATOR_CACHE_RESULT=${result[*]};
  1865. echo ${result[@]};
  1866. eshopts_pop
  1867. }
  1868. get_exeext ()
  1869. {
  1870. case ${CHOST} in
  1871. *-cygwin* | mingw* | *-mingw*)
  1872. echo ".exe"
  1873. ;;
  1874. esac
  1875. }
  1876. get_gcc_src_uri ()
  1877. {
  1878. export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}};
  1879. export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}};
  1880. export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}};
  1881. export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}};
  1882. export SPECS_GCC_VER=${SPECS_GCC_VER:-${GCC_RELEASE_VER}};
  1883. if [[ ${PV} == *9999* ]]; then
  1884. :;
  1885. else
  1886. if [[ -n ${PRERELEASE} ]]; then
  1887. GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/prerelease-${PRERELEASE}/gcc-${PRERELEASE}.tar.bz2";
  1888. else
  1889. if [[ -n ${SNAPSHOT} ]]; then
  1890. if tc_version_is_between 5.5 6 || tc_version_is_between 6.4 7 || tc_version_is_at_least 7.2; then
  1891. GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/snapshots/${SNAPSHOT}/gcc-${SNAPSHOT}.tar.xz";
  1892. else
  1893. GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/snapshots/${SNAPSHOT}/gcc-${SNAPSHOT}.tar.bz2";
  1894. fi;
  1895. else
  1896. if tc_version_is_between 5.5 6 || tc_version_is_between 6.4 7 || tc_version_is_at_least 7.2; then
  1897. GCC_SRC_URI="mirror://gnu/gcc/gcc-${GCC_PV}/gcc-${GCC_RELEASE_VER}.tar.xz";
  1898. else
  1899. GCC_SRC_URI="mirror://gnu/gcc/gcc-${GCC_PV}/gcc-${GCC_RELEASE_VER}.tar.bz2";
  1900. fi;
  1901. [[ -n ${BRANCH_UPDATE} ]] && GCC_SRC_URI+=" $(gentoo_urls gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2)";
  1902. fi;
  1903. fi;
  1904. fi;
  1905. [[ -n ${UCLIBC_VER} ]] && GCC_SRC_URI+=" $(gentoo_urls gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}.tar.bz2)";
  1906. [[ -n ${PATCH_VER} ]] && GCC_SRC_URI+=" $(gentoo_urls gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2)";
  1907. [[ -n ${PIE_VER} ]] && PIE_CORE=${PIE_CORE:-gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}.tar.bz2} && GCC_SRC_URI+=" $(gentoo_urls ${PIE_CORE})";
  1908. [[ -n ${SPECS_VER} ]] && GCC_SRC_URI+=" $(gentoo_urls gcc-${SPECS_GCC_VER}-specs-${SPECS_VER}.tar.bz2)";
  1909. if [[ -n ${HTB_VER} ]]; then
  1910. local HTBFILE="bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2";
  1911. GCC_SRC_URI+="
  1912. boundschecking? (
  1913. mirror://sourceforge/boundschecking/${HTBFILE}
  1914. $(gentoo_urls ${HTBFILE})
  1915. )";
  1916. fi;
  1917. [[ -n ${D_VER} ]] && GCC_SRC_URI+=" d? ( mirror://sourceforge/dgcc/gdc-${D_VER}-src.tar.bz2 )";
  1918. if in_iuse gcj; then
  1919. if tc_version_is_at_least 4.5; then
  1920. GCC_SRC_URI+=" gcj? ( ftp://sourceware.org/pub/java/ecj-4.5.jar )";
  1921. else
  1922. if tc_version_is_at_least 4.3; then
  1923. GCC_SRC_URI+=" gcj? ( ftp://sourceware.org/pub/java/ecj-4.3.jar )";
  1924. fi;
  1925. fi;
  1926. fi;
  1927. echo "${GCC_SRC_URI}"
  1928. }
  1929. get_install_abis ()
  1930. {
  1931. local x order="";
  1932. if [[ -z ${MULTILIB_ABIS} ]]; then
  1933. echo "default";
  1934. return 0;
  1935. fi;
  1936. if [[ ${EMULTILIB_PKG} == "true" ]]; then
  1937. for x in ${MULTILIB_ABIS};
  1938. do
  1939. if [[ ${x} != "${DEFAULT_ABI}" ]]; then
  1940. has ${x} ${ABI_DENY} || order="${order} ${x}";
  1941. fi;
  1942. done;
  1943. has ${DEFAULT_ABI} ${ABI_DENY} || order="${order} ${DEFAULT_ABI}";
  1944. if [[ -n ${ABI_ALLOW} ]]; then
  1945. local ordera="";
  1946. for x in ${order};
  1947. do
  1948. if has ${x} ${ABI_ALLOW}; then
  1949. ordera="${ordera} ${x}";
  1950. fi;
  1951. done;
  1952. order=${ordera};
  1953. fi;
  1954. else
  1955. order=${DEFAULT_ABI};
  1956. fi;
  1957. if [[ -z ${order} ]]; then
  1958. 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.";
  1959. fi;
  1960. echo ${order};
  1961. return 0
  1962. }
  1963. get_last_version_component_index ()
  1964. {
  1965. echo $(($(get_version_component_count "${1:-${PV}}" ) - 1))
  1966. }
  1967. get_libdir ()
  1968. {
  1969. local CONF_LIBDIR;
  1970. if [ -n "${CONF_LIBDIR_OVERRIDE}" ]; then
  1971. echo ${CONF_LIBDIR_OVERRIDE};
  1972. else
  1973. get_abi_LIBDIR;
  1974. fi
  1975. }
  1976. get_libname ()
  1977. {
  1978. local libname;
  1979. local ver=$1;
  1980. case ${CHOST} in
  1981. *-cygwin*)
  1982. libname="dll.a"
  1983. ;;
  1984. mingw* | *-mingw*)
  1985. libname="dll"
  1986. ;;
  1987. *-darwin*)
  1988. libname="dylib"
  1989. ;;
  1990. *-mint*)
  1991. libname="irrelevant"
  1992. ;;
  1993. hppa*-hpux*)
  1994. libname="sl"
  1995. ;;
  1996. *)
  1997. libname="so"
  1998. ;;
  1999. esac;
  2000. if [[ -z $* ]]; then
  2001. echo ".${libname}";
  2002. else
  2003. for ver in "$@";
  2004. do
  2005. case ${CHOST} in
  2006. *-cygwin*)
  2007. echo ".${ver}.${libname}"
  2008. ;;
  2009. *-darwin*)
  2010. echo ".${ver}.${libname}"
  2011. ;;
  2012. *-mint*)
  2013. echo ".${libname}"
  2014. ;;
  2015. *)
  2016. echo ".${libname}.${ver}"
  2017. ;;
  2018. esac;
  2019. done;
  2020. fi
  2021. }
  2022. get_major_version ()
  2023. {
  2024. local c=($(get_all_version_components "${1:-${PV}}"));
  2025. echo ${c[0]}
  2026. }
  2027. get_make_var ()
  2028. {
  2029. local var=$1 makefile=${2:-${WORKDIR}/build/Makefile};
  2030. echo -e "e:\\n\\t@echo \$(${var})\\ninclude ${makefile}" | r=${makefile%/*} emake --no-print-directory -s -f - 2> /dev/null
  2031. }
  2032. get_modname ()
  2033. {
  2034. local modname;
  2035. local ver=$1;
  2036. case ${CHOST} in
  2037. *-darwin*)
  2038. modname="bundle"
  2039. ;;
  2040. *)
  2041. modname="so"
  2042. ;;
  2043. esac;
  2044. echo ".${modname}"
  2045. }
  2046. get_version_component_count ()
  2047. {
  2048. local a=($(get_version_components "${1:-${PV}}"));
  2049. echo ${#a[@]}
  2050. }
  2051. get_version_component_range ()
  2052. {
  2053. eshopts_push -s extglob;
  2054. local c v="${2:-${PV}}" range="${1}" range_start range_end;
  2055. local -i i=-1 j=0;
  2056. c=($(get_all_version_components "${v}"));
  2057. range_start=${range%-*};
  2058. range_start=${range_start:-1};
  2059. range_end=${range#*-};
  2060. range_end=${range_end:-${#c[@]}};
  2061. while ((j < range_start)); do
  2062. i+=1;
  2063. ((i > ${#c[@]})) && eshopts_pop && return;
  2064. [[ -n "${c[i]//[-._]}" ]] && j+=1;
  2065. done;
  2066. while ((j <= range_end)); do
  2067. echo -n ${c[i]};
  2068. ((i > ${#c[@]})) && eshopts_pop && return;
  2069. [[ -n "${c[i]//[-._]}" ]] && j+=1;
  2070. i+=1;
  2071. done;
  2072. eshopts_pop
  2073. }
  2074. get_version_components ()
  2075. {
  2076. local c=$(get_all_version_components "${1:-${PV}}");
  2077. echo ${c//[-._]/ }
  2078. }
  2079. gnuconfig_do_update ()
  2080. {
  2081. local configsubs_dir target targetlist file;
  2082. [[ $# -eq 0 ]] && die "do not call gnuconfig_do_update; use gnuconfig_update";
  2083. configsubs_dir=$(gnuconfig_findnewest);
  2084. einfo "Using GNU config files from ${configsubs_dir}";
  2085. for file in "$@";
  2086. do
  2087. if [[ ! -r ${configsubs_dir}/${file} ]]; then
  2088. eerror "Can't read ${configsubs_dir}/${file}, skipping..";
  2089. continue;
  2090. fi;
  2091. targetlist=$(find "${startdir}" -name "${file}");
  2092. if [[ -n ${targetlist} ]]; then
  2093. for target in ${targetlist};
  2094. do
  2095. [[ -L ${target} ]] && rm -f "${target}";
  2096. einfo " Updating ${target/$startdir\//}";
  2097. cp -f "${configsubs_dir}/${file}" "${target}";
  2098. eend $?;
  2099. done;
  2100. else
  2101. ewarn " No ${file} found in ${startdir}, skipping ...";
  2102. fi;
  2103. done;
  2104. return 0
  2105. }
  2106. gnuconfig_findnewest ()
  2107. {
  2108. 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);
  2109. grep -s '^timestamp' "${locations[@]}" | sort -r -n -t\' -k2 | sed -n '1{s,/config.sub:.*$,,;p;q}'
  2110. }
  2111. gnuconfig_update ()
  2112. {
  2113. local startdir;
  2114. if [[ $1 == /* ]]; then
  2115. startdir=$1;
  2116. shift;
  2117. else
  2118. startdir=${S};
  2119. fi;
  2120. if [[ $# -gt 0 ]]; then
  2121. gnuconfig_do_update "$@";
  2122. else
  2123. gnuconfig_do_update config.sub config.guess;
  2124. fi;
  2125. return $?
  2126. }
  2127. guess_patch_type_in_dir ()
  2128. {
  2129. [[ -n $(ls "$1"/*.bz2 2>/dev/null) ]] && EPATCH_SUFFIX="patch.bz2" || EPATCH_SUFFIX="patch"
  2130. }
  2131. hardened_gcc_is_stable ()
  2132. {
  2133. local tocheck;
  2134. if [[ $1 == "pie" ]]; then
  2135. if [[ ${CTARGET} == *-uclibc* ]]; then
  2136. tocheck=${PIE_UCLIBC_STABLE};
  2137. else
  2138. tocheck=${PIE_GLIBC_STABLE};
  2139. fi;
  2140. else
  2141. if [[ $1 == "ssp" ]]; then
  2142. if [[ ${CTARGET} == *-uclibc* ]]; then
  2143. tocheck=${SSP_UCLIBC_STABLE};
  2144. else
  2145. if [[ ${CTARGET} == *-gnu* ]]; then
  2146. tocheck=${SSP_STABLE};
  2147. fi;
  2148. fi;
  2149. else
  2150. die "hardened_gcc_stable needs to be called with pie or ssp";
  2151. fi;
  2152. fi;
  2153. has $(tc-arch) ${tocheck} && return 0;
  2154. return 1
  2155. }
  2156. hardened_gcc_works ()
  2157. {
  2158. if [[ $1 == "pie" ]]; then
  2159. [[ ${CTARGET} == *-freebsd* ]] && return 1;
  2160. want_pie || return 1;
  2161. use_if_iuse nopie && return 1;
  2162. hardened_gcc_is_stable pie;
  2163. return $?;
  2164. else
  2165. if [[ $1 == "ssp" ]]; then
  2166. [[ -n ${SPECS_VER} ]] || return 1;
  2167. use_if_iuse nossp && return 1;
  2168. hardened_gcc_is_stable ssp;
  2169. return $?;
  2170. else
  2171. hardened_gcc_works pie || return 1;
  2172. hardened_gcc_works ssp || return 1;
  2173. return 0;
  2174. fi;
  2175. fi
  2176. }
  2177. has_m32 ()
  2178. {
  2179. die "${FUNCNAME}: don't use this anymore"
  2180. }
  2181. has_m64 ()
  2182. {
  2183. die "${FUNCNAME}: don't use this anymore"
  2184. }
  2185. has_multilib_profile ()
  2186. {
  2187. [ -n "${MULTILIB_ABIS}" -a "${MULTILIB_ABIS}" != "${MULTILIB_ABIS/ /}" ]
  2188. }
  2189. host-is-pax ()
  2190. {
  2191. grep -qs ^PaX: /proc/self/status
  2192. }
  2193. hprefixify ()
  2194. {
  2195. use prefix || return 0;
  2196. local xl=() x;
  2197. while [[ $# -gt 0 ]]; do
  2198. case $1 in
  2199. -e)
  2200. local PREFIX_EXTRA_REGEX="$2";
  2201. shift
  2202. ;;
  2203. -w)
  2204. local PREFIX_LINE_MATCH="$2";
  2205. shift
  2206. ;;
  2207. -q)
  2208. local PREFIX_QUOTE_CHAR="${EPREFIX:+$2}";
  2209. shift
  2210. ;;
  2211. *)
  2212. xl+=("$1")
  2213. ;;
  2214. esac;
  2215. shift;
  2216. done;
  2217. local dirs="/(usr|lib(|[onx]?32|n?64)|etc|bin|sbin|var|opt|run)" eprefix="${PREFIX_QUOTE_CHAR}${EPREFIX}${PREFIX_QUOTE_CHAR}";
  2218. [[ ${#xl[@]} -lt 1 ]] && die "at least one file operand is required";
  2219. einfo "Adjusting to prefix ${EPREFIX:-/}";
  2220. for x in "${xl[@]}";
  2221. do
  2222. if [[ -e ${x} ]]; then
  2223. ebegin " ${x##*/}";
  2224. sed -r -e "${PREFIX_LINE_MATCH}s,([^[:alnum:]}\)\.])${dirs},\1${eprefix}/\2,g" -e "${PREFIX_LINE_MATCH}s,^${dirs},${eprefix}/\1," -e "${PREFIX_EXTRA_REGEX}" -i "${x}";
  2225. eend $? || die "failed to prefixify ${x}";
  2226. else
  2227. die "${x} does not exist";
  2228. fi;
  2229. done
  2230. }
  2231. ht_fix_all ()
  2232. {
  2233. local MATCHES;
  2234. MATCHES=$(grep -l -s -i -R -e "head -[ 0-9]" -e "tail [+-][ 0-9]" * | sort -u);
  2235. [[ -n ${MATCHES} ]] && ht_fix_file ${MATCHES} || einfo "No need for ht_fix_all anymore !"
  2236. }
  2237. ht_fix_file ()
  2238. {
  2239. local i;
  2240. einfo "Replacing obsolete head/tail with POSIX compliant ones";
  2241. for i in "$@";
  2242. do
  2243. _do_sed_fix "$i";
  2244. done
  2245. }
  2246. in_iuse ()
  2247. {
  2248. debug-print-function ${FUNCNAME} "${@}";
  2249. [[ ${#} -eq 1 ]] || die "Invalid args to ${FUNCNAME}()";
  2250. local flag=${1};
  2251. local liuse=(${IUSE});
  2252. has "${flag}" "${liuse[@]#[+-]}"
  2253. }
  2254. is-flag ()
  2255. {
  2256. is-flagq "$@" && echo true
  2257. }
  2258. is-flagq ()
  2259. {
  2260. [[ -n $2 ]] && die "Usage: is-flag <flag>";
  2261. local var;
  2262. for var in $(all-flag-vars);
  2263. do
  2264. _is_flagq ${var} "$1" && return 0;
  2265. done;
  2266. return 1
  2267. }
  2268. is-ldflag ()
  2269. {
  2270. is-ldflagq "$@" && echo true
  2271. }
  2272. is-ldflagq ()
  2273. {
  2274. [[ -n $2 ]] && die "Usage: is-ldflag <flag>";
  2275. _is_flagq LDFLAGS $1
  2276. }
  2277. is_ada ()
  2278. {
  2279. gcc-lang-supported ada || return 1;
  2280. use_if_iuse ada
  2281. }
  2282. is_crosscompile ()
  2283. {
  2284. [[ ${CHOST} != ${CTARGET} ]]
  2285. }
  2286. is_cxx ()
  2287. {
  2288. gcc-lang-supported 'c++' || return 1;
  2289. ! is_crosscompile && tc_version_is_at_least 4.8 && return 0;
  2290. use_if_iuse cxx
  2291. }
  2292. is_d ()
  2293. {
  2294. gcc-lang-supported d || return 1;
  2295. use_if_iuse d
  2296. }
  2297. is_f77 ()
  2298. {
  2299. gcc-lang-supported f77 || return 1;
  2300. use_if_iuse fortran
  2301. }
  2302. is_f95 ()
  2303. {
  2304. gcc-lang-supported f95 || return 1;
  2305. use_if_iuse fortran
  2306. }
  2307. is_final_abi ()
  2308. {
  2309. has_multilib_profile || return 0;
  2310. set -- $(get_install_abis);
  2311. local LAST_ABI=$#;
  2312. [[ ${!LAST_ABI} == ${ABI} ]]
  2313. }
  2314. is_fortran ()
  2315. {
  2316. gcc-lang-supported fortran || return 1;
  2317. use_if_iuse fortran
  2318. }
  2319. is_gcj ()
  2320. {
  2321. gcc-lang-supported java || return 1;
  2322. use_if_iuse cxx && use_if_iuse gcj
  2323. }
  2324. is_go ()
  2325. {
  2326. gcc-lang-supported go || return 1;
  2327. use_if_iuse cxx && use_if_iuse go
  2328. }
  2329. is_jit ()
  2330. {
  2331. gcc-lang-supported jit || return 1;
  2332. use_if_iuse jit
  2333. }
  2334. is_multilib ()
  2335. {
  2336. tc_version_is_at_least 3 || return 1;
  2337. use_if_iuse multilib
  2338. }
  2339. is_objc ()
  2340. {
  2341. gcc-lang-supported objc || return 1;
  2342. use_if_iuse objc
  2343. }
  2344. is_objcxx ()
  2345. {
  2346. gcc-lang-supported 'obj-c++' || return 1;
  2347. use_if_iuse cxx && use_if_iuse objc++
  2348. }
  2349. isdigit ()
  2350. {
  2351. local d;
  2352. for d in "$@";
  2353. do
  2354. [[ ${d:-bad} == *[!0-9]* ]] && return 1;
  2355. done;
  2356. return 0
  2357. }
  2358. list-paxables ()
  2359. {
  2360. file "$@" 2> /dev/null | grep -E 'ELF.*(executable|shared object)' | sed -e 's/: .*$//'
  2361. }
  2362. make_desktop_entry ()
  2363. {
  2364. [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable";
  2365. local exec=${1};
  2366. local name=${2:-${PN}};
  2367. local icon=${3:-${PN}};
  2368. local type=${4};
  2369. local fields=${5};
  2370. if [[ -z ${type} ]]; then
  2371. local catmaj=${CATEGORY%%-*};
  2372. local catmin=${CATEGORY##*-};
  2373. case ${catmaj} in
  2374. app)
  2375. case ${catmin} in
  2376. accessibility)
  2377. type="Utility;Accessibility"
  2378. ;;
  2379. admin)
  2380. type=System
  2381. ;;
  2382. antivirus)
  2383. type=System
  2384. ;;
  2385. arch)
  2386. type="Utility;Archiving"
  2387. ;;
  2388. backup)
  2389. type="Utility;Archiving"
  2390. ;;
  2391. cdr)
  2392. type="AudioVideo;DiscBurning"
  2393. ;;
  2394. dicts)
  2395. type="Office;Dictionary"
  2396. ;;
  2397. doc)
  2398. type=Documentation
  2399. ;;
  2400. editors)
  2401. type="Utility;TextEditor"
  2402. ;;
  2403. emacs)
  2404. type="Development;TextEditor"
  2405. ;;
  2406. emulation)
  2407. type="System;Emulator"
  2408. ;;
  2409. laptop)
  2410. type="Settings;HardwareSettings"
  2411. ;;
  2412. office)
  2413. type=Office
  2414. ;;
  2415. pda)
  2416. type="Office;PDA"
  2417. ;;
  2418. vim)
  2419. type="Development;TextEditor"
  2420. ;;
  2421. xemacs)
  2422. type="Development;TextEditor"
  2423. ;;
  2424. esac
  2425. ;;
  2426. dev)
  2427. type="Development"
  2428. ;;
  2429. games)
  2430. case ${catmin} in
  2431. action | fps)
  2432. type=ActionGame
  2433. ;;
  2434. arcade)
  2435. type=ArcadeGame
  2436. ;;
  2437. board)
  2438. type=BoardGame
  2439. ;;
  2440. emulation)
  2441. type=Emulator
  2442. ;;
  2443. kids)
  2444. type=KidsGame
  2445. ;;
  2446. puzzle)
  2447. type=LogicGame
  2448. ;;
  2449. roguelike)
  2450. type=RolePlaying
  2451. ;;
  2452. rpg)
  2453. type=RolePlaying
  2454. ;;
  2455. simulation)
  2456. type=Simulation
  2457. ;;
  2458. sports)
  2459. type=SportsGame
  2460. ;;
  2461. strategy)
  2462. type=StrategyGame
  2463. ;;
  2464. esac;
  2465. type="Game;${type}"
  2466. ;;
  2467. gnome)
  2468. type="Gnome;GTK"
  2469. ;;
  2470. kde)
  2471. type="KDE;Qt"
  2472. ;;
  2473. mail)
  2474. type="Network;Email"
  2475. ;;
  2476. media)
  2477. case ${catmin} in
  2478. gfx)
  2479. type=Graphics
  2480. ;;
  2481. *)
  2482. case ${catmin} in
  2483. radio)
  2484. type=Tuner
  2485. ;;
  2486. sound)
  2487. type=Audio
  2488. ;;
  2489. tv)
  2490. type=TV
  2491. ;;
  2492. video)
  2493. type=Video
  2494. ;;
  2495. esac;
  2496. type="AudioVideo;${type}"
  2497. ;;
  2498. esac
  2499. ;;
  2500. net)
  2501. case ${catmin} in
  2502. dialup)
  2503. type=Dialup
  2504. ;;
  2505. ftp)
  2506. type=FileTransfer
  2507. ;;
  2508. im)
  2509. type=InstantMessaging
  2510. ;;
  2511. irc)
  2512. type=IRCClient
  2513. ;;
  2514. mail)
  2515. type=Email
  2516. ;;
  2517. news)
  2518. type=News
  2519. ;;
  2520. nntp)
  2521. type=News
  2522. ;;
  2523. p2p)
  2524. type=FileTransfer
  2525. ;;
  2526. voip)
  2527. type=Telephony
  2528. ;;
  2529. esac;
  2530. type="Network;${type}"
  2531. ;;
  2532. sci)
  2533. case ${catmin} in
  2534. astro*)
  2535. type=Astronomy
  2536. ;;
  2537. bio*)
  2538. type=Biology
  2539. ;;
  2540. calc*)
  2541. type=Calculator
  2542. ;;
  2543. chem*)
  2544. type=Chemistry
  2545. ;;
  2546. elec*)
  2547. type=Electronics
  2548. ;;
  2549. geo*)
  2550. type=Geology
  2551. ;;
  2552. math*)
  2553. type=Math
  2554. ;;
  2555. physics)
  2556. type=Physics
  2557. ;;
  2558. visual*)
  2559. type=DataVisualization
  2560. ;;
  2561. esac;
  2562. type="Education;Science;${type}"
  2563. ;;
  2564. sys)
  2565. type="System"
  2566. ;;
  2567. www)
  2568. case ${catmin} in
  2569. client)
  2570. type=WebBrowser
  2571. ;;
  2572. esac;
  2573. type="Network;${type}"
  2574. ;;
  2575. *)
  2576. type=
  2577. ;;
  2578. esac;
  2579. fi;
  2580. local slot=${SLOT%/*};
  2581. if [[ ${slot} == "0" ]]; then
  2582. local desktop_name="${PN}";
  2583. else
  2584. local desktop_name="${PN}-${slot}";
  2585. fi;
  2586. local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop";
  2587. type=${type%;}${type:+;};
  2588. if [[ -n ${icon} && ${icon} != /* ]] && [[ ${icon} == *.xpm || ${icon} == *.png || ${icon} == *.svg ]]; then
  2589. ewarn "As described in the Icon Theme Specification, icon file extensions are not";
  2590. ewarn "allowed in .desktop files if the value is not an absolute path.";
  2591. icon=${icon%.*};
  2592. fi;
  2593. cat > "${desktop}" <<-EOF
  2594. [Desktop Entry]
  2595. Name=${name}
  2596. Type=Application
  2597. Comment=${DESCRIPTION}
  2598. Exec=${exec}
  2599. TryExec=${exec%% *}
  2600. Icon=${icon}
  2601. Categories=${type}
  2602. EOF
  2603. if [[ ${fields:-=} != *=* ]]; then
  2604. ewarn "make_desktop_entry: update your 5th arg to read Path=${fields}";
  2605. fields="Path=${fields}";
  2606. fi;
  2607. [[ -n ${fields} ]] && printf '%b\n' "${fields}" >> "${desktop}";
  2608. ( insopts -m 0644;
  2609. insinto /usr/share/applications;
  2610. doins "${desktop}" ) || die "installing desktop file failed"
  2611. }
  2612. make_gcc_hard ()
  2613. {
  2614. local gcc_hard_flags="";
  2615. if ! tc_version_is_at_least 6.0 && [[ $(gcc-major-version) -ge 6 ]]; then
  2616. einfo "Disabling PIE in stage1 (only) ...";
  2617. sed -i -e "/^STAGE1_LDFLAGS/ s/$/ -no-pie/" "${S}"/Makefile.in || die;
  2618. fi;
  2619. if tc_version_is_at_least 6.0; then
  2620. if use_if_iuse pie; then
  2621. einfo "Updating gcc to use automatic PIE building ...";
  2622. fi;
  2623. if use_if_iuse ssp; then
  2624. einfo "Updating gcc to use automatic SSP building ...";
  2625. fi;
  2626. if use_if_iuse hardened; then
  2627. gcc_hard_flags+=" -DEXTRA_OPTIONS";
  2628. BRANDING_GCC_PKGVERSION=${BRANDING_GCC_PKGVERSION/Gentoo/Gentoo Hardened};
  2629. fi;
  2630. else
  2631. if use_if_iuse hardened; then
  2632. BRANDING_GCC_PKGVERSION=${BRANDING_GCC_PKGVERSION/Gentoo/Gentoo Hardened};
  2633. if hardened_gcc_works; then
  2634. einfo "Updating gcc to use automatic PIE + SSP building ...";
  2635. gcc_hard_flags+=" -DEFAULT_PIE_SSP";
  2636. else
  2637. if hardened_gcc_works pie; then
  2638. einfo "Updating gcc to use automatic PIE building ...";
  2639. ewarn "SSP has not been enabled by default";
  2640. gcc_hard_flags+=" -DEFAULT_PIE";
  2641. else
  2642. if hardened_gcc_works ssp; then
  2643. einfo "Updating gcc to use automatic SSP building ...";
  2644. ewarn "PIE has not been enabled by default";
  2645. gcc_hard_flags+=" -DEFAULT_SSP";
  2646. else
  2647. ewarn "hardened is not supported for this arch in this gcc version";
  2648. return 0;
  2649. fi;
  2650. fi;
  2651. fi;
  2652. else
  2653. if hardened_gcc_works ssp; then
  2654. einfo "Updating gcc to use automatic SSP building ...";
  2655. gcc_hard_flags+=" -DEFAULT_SSP";
  2656. fi;
  2657. fi;
  2658. fi;
  2659. sed -e '/^ALL_CFLAGS/iHARD_CFLAGS = ' -e 's|^ALL_CFLAGS = |ALL_CFLAGS = $(HARD_CFLAGS) |' -i "${S}"/gcc/Makefile.in;
  2660. if tc_version_is_at_least 4.7; then
  2661. sed -e '/^ALL_CXXFLAGS/iHARD_CFLAGS = ' -e 's|^ALL_CXXFLAGS = |ALL_CXXFLAGS = $(HARD_CFLAGS) |' -i "${S}"/gcc/Makefile.in;
  2662. fi;
  2663. sed -i -e "/^HARD_CFLAGS = /s|=|= ${gcc_hard_flags} |" "${S}"/gcc/Makefile.in || die
  2664. }
  2665. make_session_desktop ()
  2666. {
  2667. [[ -z $1 ]] && eerror "$0: You must specify the title" && return 1;
  2668. [[ -z $2 ]] && eerror "$0: You must specify the command" && return 1;
  2669. local title=$1;
  2670. local command=$2;
  2671. local desktop=${T}/${wm:-${PN}}.desktop;
  2672. shift 2;
  2673. cat > "${desktop}" <<-EOF
  2674. [Desktop Entry]
  2675. Name=${title}
  2676. Comment=This session logs you into ${title}
  2677. Exec=${command} $*
  2678. TryExec=${command}
  2679. Type=XSession
  2680. EOF
  2681. ( insopts -m 0644;
  2682. insinto /usr/share/xsessions;
  2683. doins "${desktop}" )
  2684. }
  2685. make_wrapper ()
  2686. {
  2687. local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5;
  2688. local tmpwrapper=$(emktemp);
  2689. has "${EAPI:-0}" 0 1 2 && local EPREFIX="";
  2690. ( echo '#!/bin/sh';
  2691. [[ -n ${chdir} ]] && printf 'cd "%s"\n' "${EPREFIX}${chdir}";
  2692. if [[ -n ${libdir} ]]; then
  2693. local var;
  2694. if [[ ${CHOST} == *-darwin* ]]; then
  2695. var=DYLD_LIBRARY_PATH;
  2696. else
  2697. var=LD_LIBRARY_PATH;
  2698. fi;
  2699. cat <<-EOF
  2700. if [ "\${${var}+set}" = "set" ] ; then
  2701. export ${var}="\${${var}}:${EPREFIX}${libdir}"
  2702. else
  2703. export ${var}="${EPREFIX}${libdir}"
  2704. fi
  2705. EOF
  2706. fi
  2707. printf 'exec %s "$@"\n' "${bin/#\//${EPREFIX}/}" ) > "${tmpwrapper}";
  2708. chmod go+rx "${tmpwrapper}";
  2709. if [[ -n ${path} ]]; then
  2710. ( exeopts -m 0755;
  2711. exeinto "${path}";
  2712. newexe "${tmpwrapper}" "${wrapper}" ) || die;
  2713. else
  2714. newbin "${tmpwrapper}" "${wrapper}" || die;
  2715. fi
  2716. }
  2717. multilib_env ()
  2718. {
  2719. local CTARGET=${1:-${CTARGET}};
  2720. local cpu=${CTARGET%%*-};
  2721. case ${cpu} in
  2722. aarch64*)
  2723. export CFLAGS_arm=${CFLAGS_arm-};
  2724. case ${cpu} in
  2725. aarch64*be)
  2726. export CHOST_arm="armv8b-${CTARGET#*-}"
  2727. ;;
  2728. *)
  2729. export CHOST_arm="armv8l-${CTARGET#*-}"
  2730. ;;
  2731. esac;
  2732. CHOST_arm=${CHOST_arm/%-gnu/-gnueabi};
  2733. export CTARGET_arm=${CHOST_arm};
  2734. export LIBDIR_arm="lib";
  2735. export CFLAGS_arm64=${CFLAGS_arm64-};
  2736. export CHOST_arm64=${CTARGET};
  2737. export CTARGET_arm64=${CHOST_arm64};
  2738. export LIBDIR_arm64="lib64";
  2739. : ${MULTILIB_ABIS=arm64};
  2740. : ${DEFAULT_ABI=arm64}
  2741. ;;
  2742. x86_64*)
  2743. export CFLAGS_x86=${CFLAGS_x86--m32};
  2744. export CHOST_x86=${CTARGET/x86_64/i686};
  2745. CHOST_x86=${CHOST_x86/%-gnux32/-gnu};
  2746. export CTARGET_x86=${CHOST_x86};
  2747. if [[ ${SYMLINK_LIB} == "yes" ]]; then
  2748. export LIBDIR_x86="lib32";
  2749. else
  2750. export LIBDIR_x86="lib";
  2751. fi;
  2752. export CFLAGS_amd64=${CFLAGS_amd64--m64};
  2753. export CHOST_amd64=${CTARGET/%-gnux32/-gnu};
  2754. export CTARGET_amd64=${CHOST_amd64};
  2755. export LIBDIR_amd64="lib64";
  2756. export CFLAGS_x32=${CFLAGS_x32--mx32};
  2757. export CHOST_x32=${CTARGET/%-gnu/-gnux32};
  2758. export CTARGET_x32=${CHOST_x32};
  2759. export LIBDIR_x32="libx32";
  2760. case ${CTARGET} in
  2761. *-gnux32)
  2762. : ${MULTILIB_ABIS=x32 amd64 x86};
  2763. : ${DEFAULT_ABI=x32}
  2764. ;;
  2765. *)
  2766. : ${MULTILIB_ABIS=amd64 x86};
  2767. : ${DEFAULT_ABI=amd64}
  2768. ;;
  2769. esac
  2770. ;;
  2771. mips64*)
  2772. export CFLAGS_o32=${CFLAGS_o32--mabi=32};
  2773. export CHOST_o32=${CTARGET/mips64/mips};
  2774. export CTARGET_o32=${CHOST_o32};
  2775. export LIBDIR_o32="lib";
  2776. export CFLAGS_n32=${CFLAGS_n32--mabi=n32};
  2777. export CHOST_n32=${CTARGET};
  2778. export CTARGET_n32=${CHOST_n32};
  2779. export LIBDIR_n32="lib32";
  2780. export CFLAGS_n64=${CFLAGS_n64--mabi=64};
  2781. export CHOST_n64=${CTARGET};
  2782. export CTARGET_n64=${CHOST_n64};
  2783. export LIBDIR_n64="lib64";
  2784. : ${MULTILIB_ABIS=n64 n32 o32};
  2785. : ${DEFAULT_ABI=n32}
  2786. ;;
  2787. powerpc64*)
  2788. export CFLAGS_ppc=${CFLAGS_ppc--m32};
  2789. export CHOST_ppc=${CTARGET/powerpc64/powerpc};
  2790. export CTARGET_ppc=${CHOST_ppc};
  2791. export LIBDIR_ppc="lib";
  2792. export CFLAGS_ppc64=${CFLAGS_ppc64--m64};
  2793. export CHOST_ppc64=${CTARGET};
  2794. export CTARGET_ppc64=${CHOST_ppc64};
  2795. export LIBDIR_ppc64="lib64";
  2796. : ${MULTILIB_ABIS=ppc64 ppc};
  2797. : ${DEFAULT_ABI=ppc64}
  2798. ;;
  2799. s390x*)
  2800. export CFLAGS_s390=${CFLAGS_s390--m31};
  2801. export CHOST_s390=${CTARGET/s390x/s390};
  2802. export CTARGET_s390=${CHOST_s390};
  2803. export LIBDIR_s390="lib";
  2804. export CFLAGS_s390x=${CFLAGS_s390x--m64};
  2805. export CHOST_s390x=${CTARGET};
  2806. export CTARGET_s390x=${CHOST_s390x};
  2807. export LIBDIR_s390x="lib64";
  2808. : ${MULTILIB_ABIS=s390x s390};
  2809. : ${DEFAULT_ABI=s390x}
  2810. ;;
  2811. sparc64*)
  2812. export CFLAGS_sparc32=${CFLAGS_sparc32--m32};
  2813. export CHOST_sparc32=${CTARGET/sparc64/sparc};
  2814. export CTARGET_sparc32=${CHOST_sparc32};
  2815. export LIBDIR_sparc32="lib";
  2816. export CFLAGS_sparc64=${CFLAGS_sparc64--m64};
  2817. export CHOST_sparc64=${CTARGET};
  2818. export CTARGET_sparc64=${CHOST_sparc64};
  2819. export LIBDIR_sparc64="lib64";
  2820. : ${MULTILIB_ABIS=sparc64 sparc32};
  2821. : ${DEFAULT_ABI=sparc64}
  2822. ;;
  2823. *)
  2824. : ${MULTILIB_ABIS=default};
  2825. : ${DEFAULT_ABI=default}
  2826. ;;
  2827. esac;
  2828. export MULTILIB_ABIS DEFAULT_ABI
  2829. }
  2830. multilib_toolchain_setup ()
  2831. {
  2832. local v vv;
  2833. export ABI=$1;
  2834. if [[ ${_DEFAULT_ABI_SAVED} == "true" ]]; then
  2835. for v in CHOST CBUILD AS CC CXX F77 FC LD PKG_CONFIG_{LIBDIR,PATH};
  2836. do
  2837. vv="_abi_saved_${v}";
  2838. [[ ${!vv+set} == "set" ]] && export ${v}="${!vv}" || unset ${v};
  2839. unset ${vv};
  2840. done;
  2841. unset _DEFAULT_ABI_SAVED;
  2842. fi;
  2843. if [[ ${ABI} != ${DEFAULT_ABI} ]]; then
  2844. for v in CHOST CBUILD AS CC CXX F77 FC LD PKG_CONFIG_{LIBDIR,PATH};
  2845. do
  2846. vv="_abi_saved_${v}";
  2847. [[ ${!v+set} == "set" ]] && export ${vv}="${!v}" || unset ${vv};
  2848. done;
  2849. export _DEFAULT_ABI_SAVED="true";
  2850. if [[ ${CBUILD} == "${CHOST}" ]]; then
  2851. export CBUILD=$(get_abi_CHOST $1);
  2852. fi;
  2853. export CHOST=$(get_abi_CHOST ${DEFAULT_ABI});
  2854. export CC="$(tc-getCC) $(get_abi_CFLAGS)";
  2855. export CXX="$(tc-getCXX) $(get_abi_CFLAGS)";
  2856. export F77="$(tc-getF77) $(get_abi_CFLAGS)";
  2857. export FC="$(tc-getFC) $(get_abi_CFLAGS)";
  2858. export LD="$(tc-getLD) $(get_abi_LDFLAGS)";
  2859. export CHOST=$(get_abi_CHOST $1);
  2860. export PKG_CONFIG_LIBDIR=${EPREFIX}/usr/$(get_libdir)/pkgconfig;
  2861. export PKG_CONFIG_PATH=${EPREFIX}/usr/share/pkgconfig;
  2862. fi
  2863. }
  2864. newicon ()
  2865. {
  2866. _iconins ${FUNCNAME} "$@"
  2867. }
  2868. newmenu ()
  2869. {
  2870. ( insopts -m 0644;
  2871. insinto /usr/share/applications;
  2872. newins "$@" )
  2873. }
  2874. no-as-needed ()
  2875. {
  2876. case $($(tc-getLD) -v 2>&1 </dev/null) in
  2877. *GNU*)
  2878. echo "-Wl,--no-as-needed"
  2879. ;;
  2880. esac
  2881. }
  2882. number_abis ()
  2883. {
  2884. set -- `get_install_abis`;
  2885. echo $#
  2886. }
  2887. optfeature ()
  2888. {
  2889. debug-print-function ${FUNCNAME} "$@";
  2890. local i j msg;
  2891. local desc=$1;
  2892. local flag=0;
  2893. shift;
  2894. for i in "$@";
  2895. do
  2896. for j in ${i};
  2897. do
  2898. if has_version "${j}"; then
  2899. flag=1;
  2900. else
  2901. flag=0;
  2902. break;
  2903. fi;
  2904. done;
  2905. if [[ ${flag} -eq 1 ]]; then
  2906. break;
  2907. fi;
  2908. done;
  2909. if [[ ${flag} -eq 0 ]]; then
  2910. for i in "$@";
  2911. do
  2912. msg=" ";
  2913. for j in ${i};
  2914. do
  2915. msg+=" ${j} and";
  2916. done;
  2917. msg="${msg:0: -4} for ${desc}";
  2918. elog "${msg}";
  2919. done;
  2920. fi
  2921. }
  2922. path_exists ()
  2923. {
  2924. local opt=$1;
  2925. [[ ${opt} == -[ao] ]] && shift || opt="-a";
  2926. [[ $# -eq 0 ]] && return 1;
  2927. local p r=0;
  2928. for p in "$@";
  2929. do
  2930. [[ -e ${p} ]];
  2931. : $(( r += $? ));
  2932. done;
  2933. case ${opt} in
  2934. -a)
  2935. return $(( r != 0 ))
  2936. ;;
  2937. -o)
  2938. return $(( r == $# ))
  2939. ;;
  2940. esac
  2941. }
  2942. pax-mark ()
  2943. {
  2944. local f;
  2945. local flags;
  2946. local ret=0;
  2947. flags="${1//[!zPpEeMmRrSs]}";
  2948. [[ -n "${flags}" ]] || return 0;
  2949. shift;
  2950. local dodefault="";
  2951. [[ -n "${flags//[!z]}" ]] && dodefault="yes";
  2952. if has PT ${PAX_MARKINGS}; then
  2953. for f in "$@";
  2954. do
  2955. if type -p paxctl > /dev/null; then
  2956. einfo "PT_PAX marking -${flags} ${f} with paxctl";
  2957. paxctl -q${flags} "${f}" > /dev/null 2>&1 && continue;
  2958. fi;
  2959. if type -p paxctl-ng > /dev/null && paxctl-ng -L; then
  2960. einfo "PT_PAX marking -${flags} ${f} with paxctl-ng";
  2961. flags="${flags//z}";
  2962. [[ ${dodefault} == "yes" ]] && paxctl-ng -L -z "${f}" > /dev/null 2>&1;
  2963. [[ -n "${flags}" ]] || continue;
  2964. paxctl-ng -L -${flags} "${f}" > /dev/null 2>&1 && continue;
  2965. fi;
  2966. if type -p scanelf > /dev/null && [[ ${PAX_MARKINGS} != "none" ]]; then
  2967. einfo "PT_PAX marking -${flags} ${f} with scanelf";
  2968. scanelf -Xxz ${flags} "$f" > /dev/null 2>&1;
  2969. else
  2970. if [[ ${PAX_MARKINGS} != "none" ]]; then
  2971. elog "Failed to set PT_PAX markings -${flags} ${f}.";
  2972. ret=1;
  2973. fi;
  2974. fi;
  2975. done;
  2976. fi;
  2977. if has XT ${PAX_MARKINGS}; then
  2978. flags="${flags//z}";
  2979. for f in "$@";
  2980. do
  2981. if type -p paxctl-ng > /dev/null && paxctl-ng -l; then
  2982. einfo "XATTR_PAX marking -${flags} ${f} with paxctl-ng";
  2983. [[ ${dodefault} == "yes" ]] && paxctl-ng -d "${f}" > /dev/null 2>&1;
  2984. [[ -n "${flags}" ]] || continue;
  2985. paxctl-ng -l -${flags} "${f}" > /dev/null 2>&1 && continue;
  2986. fi;
  2987. if type -p setfattr > /dev/null; then
  2988. [[ -n "${flags//[!Ee]}" ]] || flags+="e";
  2989. einfo "XATTR_PAX marking -${flags} ${f} with setfattr";
  2990. [[ ${dodefault} == "yes" ]] && setfattr -x "user.pax.flags" "${f}" > /dev/null 2>&1;
  2991. setfattr -n "user.pax.flags" -v "${flags}" "${f}" > /dev/null 2>&1 && continue;
  2992. fi;
  2993. if [[ ${PAX_MARKINGS} != "none" ]]; then
  2994. elog "Failed to set XATTR_PAX markings -${flags} ${f}.";
  2995. ret=1;
  2996. fi;
  2997. done;
  2998. fi;
  2999. return ${ret}
  3000. }
  3001. pkg_nofetch ()
  3002. {
  3003. default
  3004. }
  3005. pkg_postinst ()
  3006. {
  3007. toolchain_pkg_postinst "$@"
  3008. }
  3009. pkg_postrm ()
  3010. {
  3011. toolchain_pkg_postrm "$@"
  3012. }
  3013. pkg_pretend ()
  3014. {
  3015. toolchain_pkg_pretend "$@"
  3016. }
  3017. pkg_setup ()
  3018. {
  3019. toolchain_pkg_setup "$@"
  3020. }
  3021. prefixify_ro ()
  3022. {
  3023. if [[ -e $1 ]]; then
  3024. local f=${1##*/};
  3025. cp "$1" "${T}" || die "failed to copy file";
  3026. local x="${T}"/${f};
  3027. if grep -qs @GENTOO_PORTAGE_EPREFIX@ "${x}"; then
  3028. eprefixify "${T}"/${f} 1>&2;
  3029. else
  3030. hprefixify "${T}"/${f} 1>&2;
  3031. fi;
  3032. echo "${x}";
  3033. else
  3034. die "$1 does not exist";
  3035. fi
  3036. }
  3037. preserve_old_lib ()
  3038. {
  3039. if [[ ${EBUILD_PHASE} != "preinst" ]]; then
  3040. eerror "preserve_old_lib() must be called from pkg_preinst() only";
  3041. die "Invalid preserve_old_lib() usage";
  3042. fi;
  3043. [[ -z $1 ]] && die "Usage: preserve_old_lib <library to preserve> [more libraries to preserve]";
  3044. has preserve-libs ${FEATURES} && return 0;
  3045. has "${EAPI:-0}" 0 1 2 && local ED=${D} EROOT=${ROOT};
  3046. local lib dir;
  3047. for lib in "$@";
  3048. do
  3049. [[ -e ${EROOT}/${lib} ]] || continue;
  3050. dir=${lib%/*};
  3051. dodir ${dir} || die "dodir ${dir} failed";
  3052. cp "${EROOT}"/${lib} "${ED}"/${lib} || die "cp ${lib} failed";
  3053. touch "${ED}"/${lib};
  3054. done
  3055. }
  3056. preserve_old_lib_notify ()
  3057. {
  3058. if [[ ${EBUILD_PHASE} != "postinst" ]]; then
  3059. eerror "preserve_old_lib_notify() must be called from pkg_postinst() only";
  3060. die "Invalid preserve_old_lib_notify() usage";
  3061. fi;
  3062. has preserve-libs ${FEATURES} && return 0;
  3063. has "${EAPI:-0}" 0 1 2 && local EROOT=${ROOT};
  3064. local lib notice=0;
  3065. for lib in "$@";
  3066. do
  3067. [[ -e ${EROOT}/${lib} ]] || continue;
  3068. if [[ ${notice} -eq 0 ]]; then
  3069. notice=1;
  3070. ewarn "Old versions of installed libraries were detected on your system.";
  3071. ewarn "In order to avoid breaking packages that depend on these old libs,";
  3072. ewarn "the libraries are not being removed. You need to run revdep-rebuild";
  3073. ewarn "in order to remove these old dependencies. If you do not have this";
  3074. ewarn "helper program, simply emerge the 'gentoolkit' package.";
  3075. ewarn;
  3076. fi;
  3077. ewarn " # revdep-rebuild --library '${lib}' && rm '${lib}'";
  3078. done
  3079. }
  3080. prune_libtool_files ()
  3081. {
  3082. debug-print-function ${FUNCNAME} "$@";
  3083. local removing_all removing_modules opt;
  3084. for opt in "$@";
  3085. do
  3086. case "${opt}" in
  3087. --all)
  3088. removing_all=1;
  3089. removing_modules=1
  3090. ;;
  3091. --modules)
  3092. removing_modules=1
  3093. ;;
  3094. *)
  3095. die "Invalid argument to ${FUNCNAME}(): ${opt}"
  3096. ;;
  3097. esac;
  3098. done;
  3099. local f;
  3100. local queue=();
  3101. while IFS= read -r -d '' f; do
  3102. local archivefile=${f/%.la/.a};
  3103. if ! sed -n -e '/^# Generated by .*libtool/q0;4q1' "${f}"; then
  3104. continue;
  3105. fi;
  3106. [[ ${f} != ${archivefile} ]] || die 'regex sanity check failed';
  3107. local reason= pkgconfig_scanned=;
  3108. local snotlink=$(sed -n -e 's:^shouldnotlink=::p' "${f}");
  3109. if [[ ${snotlink} == yes ]]; then
  3110. if [[ -f ${archivefile} ]]; then
  3111. einfo "Removing unnecessary ${archivefile#${D%/}} (static plugin)";
  3112. queue+=("${archivefile}");
  3113. fi;
  3114. if [[ -n ${removing_modules} ]]; then
  3115. reason='module';
  3116. fi;
  3117. else
  3118. if [[ -n ${removing_all} ]]; then
  3119. reason='requested';
  3120. else
  3121. if [[ ! -f ${archivefile} ]]; then
  3122. reason='no static archive';
  3123. else
  3124. if [[ ! -n $(sed -nre "s/^(dependency_libs|inherited_linker_flags)='(.*)'$/\2/p" "${f}") ]]; then
  3125. reason='no libs & flags';
  3126. else
  3127. if [[ ! -n ${pkgconfig_scanned} ]]; then
  3128. local pc_libs=();
  3129. if [[ ! -n ${removing_all} ]]; then
  3130. local pc;
  3131. local tf=${T}/prune-lt-files.pc;
  3132. local pkgconf=$(tc-getPKG_CONFIG);
  3133. while IFS= read -r -d '' pc; do
  3134. local arg libs;
  3135. if ${pkgconf} --exists "${pc}" &> /dev/null; then
  3136. sed -e '/^Requires:/d' "${pc}" > "${tf}";
  3137. libs=$(${pkgconf} --libs "${tf}");
  3138. else
  3139. libs=$(sed -ne 's/^Libs://p' "${pc}");
  3140. fi;
  3141. for arg in ${libs};
  3142. do
  3143. if [[ ${arg} == -l* ]]; then
  3144. if [[ ${arg} == '*$*' ]]; then
  3145. eerror "${FUNCNAME}: variable substitution likely failed in ${pc}";
  3146. eerror "(arg: ${arg})";
  3147. eerror "Most likely, you need to add virtual/pkgconfig to DEPEND.";
  3148. die "${FUNCNAME}: unsubstituted variable found in .pc";
  3149. fi;
  3150. pc_libs+=(lib${arg#-l}.la);
  3151. fi;
  3152. done;
  3153. done < <(find "${D}" -type f -name '*.pc' -print0);
  3154. rm -f "${tf}";
  3155. fi;
  3156. pkgconfig_scanned=1;
  3157. fi;
  3158. has "${f##*/}" "${pc_libs[@]}" && reason='covered by .pc';
  3159. fi;
  3160. fi;
  3161. fi;
  3162. fi;
  3163. if [[ -n ${reason} ]]; then
  3164. einfo "Removing unnecessary ${f#${D%/}} (${reason})";
  3165. queue+=("${f}");
  3166. fi;
  3167. done < <(find "${D}" -xtype f -name '*.la' -print0);
  3168. if [[ -n ${queue[@]} ]]; then
  3169. rm -f "${queue[@]}";
  3170. fi
  3171. }
  3172. raw-ldflags ()
  3173. {
  3174. local x input="$@";
  3175. [[ -z ${input} ]] && input=${LDFLAGS};
  3176. set --;
  3177. for x in ${input};
  3178. do
  3179. case ${x} in
  3180. -Wl,*)
  3181. x=${x#-Wl,};
  3182. set -- "$@" ${x//,/ }
  3183. ;;
  3184. *)
  3185. ;;
  3186. esac;
  3187. done;
  3188. echo "$@"
  3189. }
  3190. replace-cpu-flags ()
  3191. {
  3192. local newcpu="$#";
  3193. newcpu="${!newcpu}";
  3194. while [ $# -gt 1 ]; do
  3195. replace-flags "-march=${1}" "-march=${newcpu}";
  3196. replace-flags "-mcpu=${1}" "-mcpu=${newcpu}";
  3197. replace-flags "-mtune=${1}" "-mtune=${newcpu}";
  3198. shift;
  3199. done;
  3200. return 0
  3201. }
  3202. replace-flags ()
  3203. {
  3204. [[ $# != 2 ]] && die "Usage: replace-flags <old flag> <new flag>";
  3205. local f var new;
  3206. for var in $(all-flag-vars);
  3207. do
  3208. new=();
  3209. for f in ${!var};
  3210. do
  3211. [[ ${f} == ${1} ]] && f=${2};
  3212. new+=("${f}");
  3213. done;
  3214. export ${var}="${new[*]}";
  3215. done;
  3216. return 0
  3217. }
  3218. replace-sparc64-flags ()
  3219. {
  3220. local SPARC64_CPUS="ultrasparc3 ultrasparc v9";
  3221. if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then
  3222. for x in ${SPARC64_CPUS};
  3223. do
  3224. CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}";
  3225. done;
  3226. else
  3227. for x in ${SPARC64_CPUS};
  3228. do
  3229. CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}";
  3230. done;
  3231. fi;
  3232. if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then
  3233. for x in ${SPARC64_CPUS};
  3234. do
  3235. CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}";
  3236. done;
  3237. else
  3238. for x in ${SPARC64_CPUS};
  3239. do
  3240. CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}";
  3241. done;
  3242. fi;
  3243. export CFLAGS CXXFLAGS
  3244. }
  3245. replace_all_version_separators ()
  3246. {
  3247. local c=($(get_all_version_components "${2:-${PV}}"));
  3248. c=${c[@]//[-._]/$1};
  3249. echo ${c// }
  3250. }
  3251. replace_version_separator ()
  3252. {
  3253. eshopts_push -s extglob;
  3254. local w c v="${3:-${PV}}";
  3255. declare -i i found=0;
  3256. w=${1:-1};
  3257. c=($(get_all_version_components ${v}));
  3258. if [[ ${w} != *[[:digit:]]* ]]; then
  3259. for ((i = 0; i < ${#c[@]}; i++))
  3260. do
  3261. if [[ ${c[i]} == ${w} ]]; then
  3262. c[i]=${2};
  3263. break;
  3264. fi;
  3265. done;
  3266. else
  3267. for ((i = 0; i < ${#c[@]}; i++))
  3268. do
  3269. if [[ -n "${c[i]//[^-._]}" ]]; then
  3270. found+=1;
  3271. if ((found == w)); then
  3272. c[i]=${2};
  3273. break;
  3274. fi;
  3275. fi;
  3276. done;
  3277. fi;
  3278. c=${c[*]};
  3279. echo ${c// };
  3280. eshopts_pop
  3281. }
  3282. setup-allowed-flags ()
  3283. {
  3284. 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,*');
  3285. ALLOWED_FLAGS+=('-fno-stack-protector*' '-fabi-version=*' -fno-strict-aliasing -fno-bounds-check -fno-bounds-checking -fstrict-overflow -fno-omit-frame-pointer '-fno-builtin*');
  3286. 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)
  3287. }
  3288. setup_minispecs_gcc_build_specs ()
  3289. {
  3290. if hardened_gcc_works pie; then
  3291. cat "${WORKDIR}"/specs/pie.specs >> "${WORKDIR}"/build.specs;
  3292. fi;
  3293. if hardened_gcc_works ssp; then
  3294. for s in ssp sspall;
  3295. do
  3296. cat "${WORKDIR}"/specs/${s}.specs >> "${WORKDIR}"/build.specs;
  3297. done;
  3298. fi;
  3299. for s in nostrict znow;
  3300. do
  3301. cat "${WORKDIR}"/specs/${s}.specs >> "${WORKDIR}"/build.specs;
  3302. done;
  3303. export GCC_SPECS="${WORKDIR}"/build.specs
  3304. }
  3305. setup_multilib_osdirnames ()
  3306. {
  3307. is_multilib || return 0;
  3308. local config;
  3309. local libdirs="../lib64 ../lib32";
  3310. case ${CTARGET} in
  3311. x86_64*-linux*)
  3312. config="i386"
  3313. ;;
  3314. powerpc64*-linux*)
  3315. config="rs6000"
  3316. ;;
  3317. sparc64*-linux*)
  3318. config="sparc"
  3319. ;;
  3320. s390x*-linux*)
  3321. config="s390"
  3322. ;;
  3323. *)
  3324. return 0
  3325. ;;
  3326. esac;
  3327. config+="/t-linux64";
  3328. local sed_args=();
  3329. if tc_version_is_at_least 4.6; then
  3330. sed_args+=(-e 's:$[(]call if_multiarch[^)]*[)]::g');
  3331. fi;
  3332. if [[ ${SYMLINK_LIB} == "yes" ]]; then
  3333. einfo "updating multilib directories to be: ${libdirs}";
  3334. if tc_version_is_at_least 4.6.4 || tc_version_is_at_least 4.7; then
  3335. sed_args+=(-e '/^MULTILIB_OSDIRNAMES.*lib32/s:[$][(]if.*):../lib32:');
  3336. else
  3337. sed_args+=(-e "/^MULTILIB_OSDIRNAMES/s:=.*:= ${libdirs}:");
  3338. fi;
  3339. else
  3340. einfo "using upstream multilib; disabling lib32 autodetection";
  3341. sed_args+=(-r -e 's:[$][(]if.*,(.*)[)]:\1:');
  3342. fi;
  3343. sed -i "${sed_args[@]}" "${S}"/gcc/config/${config} || die
  3344. }
  3345. should_we_gcc_config ()
  3346. {
  3347. local curr_config;
  3348. curr_config=$(gcc-config -c ${CTARGET} 2>&1) || return 0;
  3349. local curr_config_ver=$(gcc-config -S ${curr_config} | awk '{print $2}');
  3350. local curr_branch_ver=$(get_version_component_range 1-2 ${curr_config_ver});
  3351. if [[ ${curr_branch_ver} == ${GCC_BRANCH_VER} ]]; then
  3352. return 0;
  3353. else
  3354. if [[ ${EBUILD_PHASE} == *"inst" ]]; then
  3355. einfo "The current gcc config appears valid, so it will not be";
  3356. einfo "automatically switched for you. If you would like to";
  3357. einfo "switch to the newly installed gcc version, do the";
  3358. einfo "following:";
  3359. echo;
  3360. einfo "gcc-config ${CTARGET}-${GCC_CONFIG_VER}";
  3361. einfo "source /etc/profile";
  3362. echo;
  3363. fi;
  3364. return 1;
  3365. fi
  3366. }
  3367. src_compile ()
  3368. {
  3369. toolchain_src_compile "$@"
  3370. }
  3371. src_configure ()
  3372. {
  3373. toolchain_src_configure "$@"
  3374. }
  3375. src_install ()
  3376. {
  3377. toolchain_src_install "$@"
  3378. }
  3379. src_prepare ()
  3380. {
  3381. toolchain_src_prepare
  3382. }
  3383. src_test ()
  3384. {
  3385. toolchain_src_test "$@"
  3386. }
  3387. src_unpack ()
  3388. {
  3389. toolchain_src_unpack "$@"
  3390. }
  3391. strip-flags ()
  3392. {
  3393. local x y var;
  3394. local ALLOWED_FLAGS;
  3395. setup-allowed-flags;
  3396. set -f;
  3397. for var in $(all-flag-vars);
  3398. do
  3399. local new=();
  3400. for x in ${!var};
  3401. do
  3402. local flag=${x%%=*};
  3403. for y in "${ALLOWED_FLAGS[@]}";
  3404. do
  3405. if [[ -z ${flag%%${y}} ]]; then
  3406. new+=("${x}");
  3407. break;
  3408. fi;
  3409. done;
  3410. done;
  3411. if _is_flagq ${var} "-O*" && ! _is_flagq new "-O*"; then
  3412. new+=(-O2);
  3413. fi;
  3414. if [[ ${!var} != "${new[*]}" ]]; then
  3415. einfo "strip-flags: ${var}: changed '${!var}' to '${new[*]}'";
  3416. fi;
  3417. export ${var}="${new[*]}";
  3418. done;
  3419. set +f;
  3420. return 0
  3421. }
  3422. strip-linguas ()
  3423. {
  3424. local ls newls nols;
  3425. if [[ $1 == "-i" ]] || [[ $1 == "-u" ]]; then
  3426. local op=$1;
  3427. shift;
  3428. ls=$(find "$1" -name '*.po' -exec basename {} .po ';');
  3429. shift;
  3430. local d f;
  3431. for d in "$@";
  3432. do
  3433. if [[ ${op} == "-u" ]]; then
  3434. newls=${ls};
  3435. else
  3436. newls="";
  3437. fi;
  3438. for f in $(find "$d" -name '*.po' -exec basename {} .po ';');
  3439. do
  3440. if [[ ${op} == "-i" ]]; then
  3441. has ${f} ${ls} && newls="${newls} ${f}";
  3442. else
  3443. has ${f} ${ls} || newls="${newls} ${f}";
  3444. fi;
  3445. done;
  3446. ls=${newls};
  3447. done;
  3448. else
  3449. ls="$@";
  3450. fi;
  3451. nols="";
  3452. newls="";
  3453. for f in ${LINGUAS};
  3454. do
  3455. if has ${f} ${ls}; then
  3456. newls="${newls} ${f}";
  3457. else
  3458. nols="${nols} ${f}";
  3459. fi;
  3460. done;
  3461. [[ -n ${nols} ]] && einfo "Sorry, but ${PN} does not support the LINGUAS:" ${nols};
  3462. export LINGUAS=${newls:1}
  3463. }
  3464. strip-unsupported-flags ()
  3465. {
  3466. export CFLAGS=$(test-flags-CC ${CFLAGS});
  3467. export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS});
  3468. export FFLAGS=$(test-flags-F77 ${FFLAGS});
  3469. export FCFLAGS=$(test-flags-FC ${FCFLAGS});
  3470. export LDFLAGS=$(test-flags-CC ${LDFLAGS})
  3471. }
  3472. tc-arch ()
  3473. {
  3474. tc-ninja_magic_to_arch portage "$@"
  3475. }
  3476. tc-arch-kernel ()
  3477. {
  3478. tc-ninja_magic_to_arch kern "$@"
  3479. }
  3480. tc-check-openmp ()
  3481. {
  3482. if ! tc-has-openmp; then
  3483. eerror "Your current compiler does not support OpenMP!";
  3484. if tc-is-gcc; then
  3485. eerror "Enable OpenMP support by building sys-devel/gcc with USE=\"openmp\".";
  3486. else
  3487. if tc-is-clang; then
  3488. eerror "OpenMP support in sys-devel/clang is provided by sys-libs/libomp.";
  3489. fi;
  3490. fi;
  3491. die "Active compiler does not have required support for OpenMP";
  3492. fi
  3493. }
  3494. tc-enables-pie ()
  3495. {
  3496. local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null | grep '^true$'
  3497. #if defined(__PIE__)
  3498. true
  3499. #endif
  3500. EOF
  3501. )";
  3502. [[ ${ret} == true ]]
  3503. }
  3504. tc-enables-ssp ()
  3505. {
  3506. local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null | grep '^true$'
  3507. #if defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__)
  3508. true
  3509. #endif
  3510. EOF
  3511. )";
  3512. [[ ${ret} == true ]]
  3513. }
  3514. tc-enables-ssp-all ()
  3515. {
  3516. local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null | grep '^true$'
  3517. #if defined(__SSP_ALL__)
  3518. true
  3519. #endif
  3520. EOF
  3521. )";
  3522. [[ ${ret} == true ]]
  3523. }
  3524. tc-enables-ssp-strong ()
  3525. {
  3526. local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null | grep '^true$'
  3527. #if defined(__SSP_STRONG__) || defined(__SSP_ALL__)
  3528. true
  3529. #endif
  3530. EOF
  3531. )";
  3532. [[ ${ret} == true ]]
  3533. }
  3534. tc-endian ()
  3535. {
  3536. local host=$1;
  3537. [[ -z ${host} ]] && host=${CTARGET:-${CHOST}};
  3538. host=${host%%-*};
  3539. case ${host} in
  3540. aarch64*be)
  3541. echo big
  3542. ;;
  3543. aarch64)
  3544. echo little
  3545. ;;
  3546. alpha*)
  3547. echo little
  3548. ;;
  3549. arm*b*)
  3550. echo big
  3551. ;;
  3552. arm*)
  3553. echo little
  3554. ;;
  3555. cris*)
  3556. echo little
  3557. ;;
  3558. hppa*)
  3559. echo big
  3560. ;;
  3561. i?86*)
  3562. echo little
  3563. ;;
  3564. ia64*)
  3565. echo little
  3566. ;;
  3567. m68*)
  3568. echo big
  3569. ;;
  3570. mips*l*)
  3571. echo little
  3572. ;;
  3573. mips*)
  3574. echo big
  3575. ;;
  3576. powerpc*le)
  3577. echo little
  3578. ;;
  3579. powerpc*)
  3580. echo big
  3581. ;;
  3582. s390*)
  3583. echo big
  3584. ;;
  3585. sh*b*)
  3586. echo big
  3587. ;;
  3588. sh*)
  3589. echo little
  3590. ;;
  3591. sparc*)
  3592. echo big
  3593. ;;
  3594. x86_64*)
  3595. echo little
  3596. ;;
  3597. *)
  3598. echo wtf
  3599. ;;
  3600. esac
  3601. }
  3602. tc-env_build ()
  3603. {
  3604. tc-export_build_env;
  3605. 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) "$@"
  3606. }
  3607. tc-export ()
  3608. {
  3609. local var;
  3610. for var in "$@";
  3611. do
  3612. [[ $(type -t "tc-get${var}") != "function" ]] && die "tc-export: invalid export variable '${var}'";
  3613. "tc-get${var}" > /dev/null;
  3614. done
  3615. }
  3616. tc-export_build_env ()
  3617. {
  3618. tc-export "$@";
  3619. if tc-is-cross-compiler; then
  3620. : ${BUILD_CFLAGS:=-O1 -pipe};
  3621. : ${BUILD_CXXFLAGS:=-O1 -pipe};
  3622. : ${BUILD_CPPFLAGS:= };
  3623. : ${BUILD_LDFLAGS:= };
  3624. else
  3625. : ${BUILD_CFLAGS:=${CFLAGS}};
  3626. : ${BUILD_CXXFLAGS:=${CXXFLAGS}};
  3627. : ${BUILD_CPPFLAGS:=${CPPFLAGS}};
  3628. : ${BUILD_LDFLAGS:=${LDFLAGS}};
  3629. fi;
  3630. export BUILD_{C,CXX,CPP,LD}FLAGS;
  3631. local v;
  3632. for v in BUILD_{C,CXX,CPP,LD}FLAGS;
  3633. do
  3634. export ${v#BUILD_}_FOR_BUILD="${!v}";
  3635. done
  3636. }
  3637. tc-get-compiler-type ()
  3638. {
  3639. local code='
  3640. #if defined(__PATHSCALE__)
  3641. HAVE_PATHCC
  3642. #elif defined(__clang__)
  3643. HAVE_CLANG
  3644. #elif defined(__GNUC__)
  3645. HAVE_GCC
  3646. #endif
  3647. ';
  3648. local res=$($(tc-getCPP "$@") -E -P - <<<"${code}");
  3649. case ${res} in
  3650. *HAVE_PATHCC*)
  3651. echo pathcc
  3652. ;;
  3653. *HAVE_CLANG*)
  3654. echo clang
  3655. ;;
  3656. *HAVE_GCC*)
  3657. echo gcc
  3658. ;;
  3659. *)
  3660. echo unknown
  3661. ;;
  3662. esac
  3663. }
  3664. tc-getAR ()
  3665. {
  3666. tc-getPROG AR ar "$@"
  3667. }
  3668. tc-getAS ()
  3669. {
  3670. tc-getPROG AS as "$@"
  3671. }
  3672. tc-getBUILD_AR ()
  3673. {
  3674. tc-getBUILD_PROG AR ar "$@"
  3675. }
  3676. tc-getBUILD_AS ()
  3677. {
  3678. tc-getBUILD_PROG AS as "$@"
  3679. }
  3680. tc-getBUILD_CC ()
  3681. {
  3682. tc-getBUILD_PROG CC gcc "$@"
  3683. }
  3684. tc-getBUILD_CPP ()
  3685. {
  3686. tc-getBUILD_PROG CPP "$(tc-getBUILD_CC) -E" "$@"
  3687. }
  3688. tc-getBUILD_CXX ()
  3689. {
  3690. tc-getBUILD_PROG CXX g++ "$@"
  3691. }
  3692. tc-getBUILD_LD ()
  3693. {
  3694. tc-getBUILD_PROG LD ld "$@"
  3695. }
  3696. tc-getBUILD_NM ()
  3697. {
  3698. tc-getBUILD_PROG NM nm "$@"
  3699. }
  3700. tc-getBUILD_OBJCOPY ()
  3701. {
  3702. tc-getBUILD_PROG OBJCOPY objcopy "$@"
  3703. }
  3704. tc-getBUILD_PKG_CONFIG ()
  3705. {
  3706. tc-getBUILD_PROG PKG_CONFIG pkg-config "$@"
  3707. }
  3708. tc-getBUILD_PROG ()
  3709. {
  3710. local vars="BUILD_$1 $1_FOR_BUILD HOST$1";
  3711. tc-is-cross-compiler || vars+=" $1";
  3712. _tc-getPROG CBUILD "${vars}" "${@:2}"
  3713. }
  3714. tc-getBUILD_RANLIB ()
  3715. {
  3716. tc-getBUILD_PROG RANLIB ranlib "$@"
  3717. }
  3718. tc-getBUILD_STRIP ()
  3719. {
  3720. tc-getBUILD_PROG STRIP strip "$@"
  3721. }
  3722. tc-getCC ()
  3723. {
  3724. tc-getPROG CC gcc "$@"
  3725. }
  3726. tc-getCPP ()
  3727. {
  3728. tc-getPROG CPP "${CC:-gcc} -E" "$@"
  3729. }
  3730. tc-getCXX ()
  3731. {
  3732. tc-getPROG CXX g++ "$@"
  3733. }
  3734. tc-getDLLWRAP ()
  3735. {
  3736. tc-getPROG DLLWRAP dllwrap "$@"
  3737. }
  3738. tc-getF77 ()
  3739. {
  3740. tc-getPROG F77 gfortran "$@"
  3741. }
  3742. tc-getFC ()
  3743. {
  3744. tc-getPROG FC gfortran "$@"
  3745. }
  3746. tc-getGCJ ()
  3747. {
  3748. tc-getPROG GCJ gcj "$@"
  3749. }
  3750. tc-getGO ()
  3751. {
  3752. tc-getPROG GO gccgo "$@"
  3753. }
  3754. tc-getLD ()
  3755. {
  3756. tc-getPROG LD ld "$@"
  3757. }
  3758. tc-getNM ()
  3759. {
  3760. tc-getPROG NM nm "$@"
  3761. }
  3762. tc-getOBJCOPY ()
  3763. {
  3764. tc-getPROG OBJCOPY objcopy "$@"
  3765. }
  3766. tc-getOBJDUMP ()
  3767. {
  3768. tc-getPROG OBJDUMP objdump "$@"
  3769. }
  3770. tc-getPKG_CONFIG ()
  3771. {
  3772. tc-getPROG PKG_CONFIG pkg-config "$@"
  3773. }
  3774. tc-getPROG ()
  3775. {
  3776. _tc-getPROG CHOST "$@"
  3777. }
  3778. tc-getRANLIB ()
  3779. {
  3780. tc-getPROG RANLIB ranlib "$@"
  3781. }
  3782. tc-getRC ()
  3783. {
  3784. tc-getPROG RC windres "$@"
  3785. }
  3786. tc-getSTRIP ()
  3787. {
  3788. tc-getPROG STRIP strip "$@"
  3789. }
  3790. tc-has-openmp ()
  3791. {
  3792. local base="${T}/test-tc-openmp";
  3793. cat > "${base}.c" <<-EOF
  3794. #include <omp.h>
  3795. int main() {
  3796. int nthreads, tid, ret = 0;
  3797. #pragma omp parallel private(nthreads, tid)
  3798. {
  3799. tid = omp_get_thread_num();
  3800. nthreads = omp_get_num_threads(); ret += tid + nthreads;
  3801. }
  3802. return ret;
  3803. }
  3804. EOF
  3805. $(tc-getCC "$@") -fopenmp "${base}.c" -o "${base}" &> /dev/null;
  3806. local ret=$?;
  3807. rm -f "${base}"*;
  3808. return ${ret}
  3809. }
  3810. tc-has-tls ()
  3811. {
  3812. local base="${T}/test-tc-tls";
  3813. cat > "${base}.c" <<-EOF
  3814. int foo(int *i) {
  3815. static __thread int j = 0;
  3816. return *i ? j : *i;
  3817. }
  3818. EOF
  3819. local flags;
  3820. case $1 in
  3821. -s)
  3822. flags="-S"
  3823. ;;
  3824. -c)
  3825. flags="-c"
  3826. ;;
  3827. -l)
  3828. ;;
  3829. -*)
  3830. die "Usage: tc-has-tls [-c|-l] [toolchain prefix]"
  3831. ;;
  3832. esac;
  3833. : ${flags:=-fPIC -shared -Wl,-z,defs};
  3834. [[ $1 == -* ]] && shift;
  3835. $(tc-getCC "$@") ${flags} "${base}.c" -o "${base}" &> /dev/null;
  3836. local ret=$?;
  3837. rm -f "${base}"*;
  3838. return ${ret}
  3839. }
  3840. tc-is-clang ()
  3841. {
  3842. [[ $(tc-get-compiler-type) == clang ]]
  3843. }
  3844. tc-is-cross-compiler ()
  3845. {
  3846. [[ ${CBUILD:-${CHOST}} != ${CHOST} ]]
  3847. }
  3848. tc-is-gcc ()
  3849. {
  3850. [[ $(tc-get-compiler-type) == gcc ]]
  3851. }
  3852. tc-is-softfloat ()
  3853. {
  3854. local CTARGET=${CTARGET:-${CHOST}};
  3855. case ${CTARGET} in
  3856. bfin* | h8300*)
  3857. echo "only"
  3858. ;;
  3859. *)
  3860. if [[ ${CTARGET//_/-} == *-softfloat-* ]]; then
  3861. echo "yes";
  3862. else
  3863. if [[ ${CTARGET//_/-} == *-softfp-* ]]; then
  3864. echo "softfp";
  3865. else
  3866. echo "no";
  3867. fi;
  3868. fi
  3869. ;;
  3870. esac
  3871. }
  3872. tc-is-static-only ()
  3873. {
  3874. local host=${CTARGET:-${CHOST}};
  3875. [[ ${host} == *-mint* ]]
  3876. }
  3877. tc-ld-disable-gold ()
  3878. {
  3879. if ! tc-ld-is-gold "$@"; then
  3880. return;
  3881. fi;
  3882. ewarn "Forcing usage of the BFD linker instead of GOLD";
  3883. local ld=$(tc-getLD "$@");
  3884. local bfd_ld="${ld%% *}.bfd";
  3885. local path_ld=$(which "${bfd_ld}" 2>/dev/null);
  3886. [[ -e ${path_ld} ]] && export LD=${bfd_ld};
  3887. local fallback="true";
  3888. if tc-is-gcc; then
  3889. local major=$(gcc-major-version "$@");
  3890. local minor=$(gcc-minor-version "$@");
  3891. if [[ ${major} -gt 4 ]] || [[ ${major} -eq 4 && ${minor} -ge 8 ]]; then
  3892. export LDFLAGS="${LDFLAGS} -fuse-ld=bfd";
  3893. fallback="false";
  3894. fi;
  3895. else
  3896. if tc-is-clang; then
  3897. local major=$(clang-major-version "$@");
  3898. local minor=$(clang-minor-version "$@");
  3899. if [[ ${major} -gt 3 ]] || [[ ${major} -eq 3 && ${minor} -ge 5 ]]; then
  3900. export LDFLAGS="${LDFLAGS} -fuse-ld=bfd";
  3901. fallback="false";
  3902. fi;
  3903. fi;
  3904. fi;
  3905. if [[ ${fallback} == "true" ]]; then
  3906. if [[ -e ${path_ld} ]]; then
  3907. local d="${T}/bfd-linker";
  3908. mkdir -p "${d}";
  3909. ln -sf "${path_ld}" "${d}"/ld;
  3910. export LDFLAGS="${LDFLAGS} -B${d}";
  3911. else
  3912. die "unable to locate a BFD linker to bypass gold";
  3913. fi;
  3914. fi
  3915. }
  3916. tc-ld-is-gold ()
  3917. {
  3918. local out;
  3919. out=$($(tc-getLD "$@") --version 2>&1);
  3920. if [[ ${out} == *"GNU gold"* ]]; then
  3921. return 0;
  3922. fi;
  3923. local base="${T}/test-tc-gold";
  3924. cat > "${base}.c" <<-EOF
  3925. int main() { return 0; }
  3926. EOF
  3927. out=$($(tc-getCC "$@") ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -Wl,--version "${base}.c" -o "${base}" 2>&1);
  3928. rm -f "${base}"*;
  3929. if [[ ${out} == *"GNU gold"* ]]; then
  3930. return 0;
  3931. fi;
  3932. return 1
  3933. }
  3934. tc-ninja_magic_to_arch ()
  3935. {
  3936. function ninj ()
  3937. {
  3938. [[ ${type} == "kern" ]] && echo $1 || echo $2
  3939. };
  3940. local type=$1;
  3941. local host=$2;
  3942. [[ -z ${host} ]] && host=${CTARGET:-${CHOST}};
  3943. case ${host} in
  3944. aarch64*)
  3945. echo arm64
  3946. ;;
  3947. alpha*)
  3948. echo alpha
  3949. ;;
  3950. arm*)
  3951. echo arm
  3952. ;;
  3953. avr*)
  3954. ninj avr32 avr
  3955. ;;
  3956. bfin*)
  3957. ninj blackfin bfin
  3958. ;;
  3959. c6x*)
  3960. echo c6x
  3961. ;;
  3962. cris*)
  3963. echo cris
  3964. ;;
  3965. frv*)
  3966. echo frv
  3967. ;;
  3968. hexagon*)
  3969. echo hexagon
  3970. ;;
  3971. hppa*)
  3972. ninj parisc hppa
  3973. ;;
  3974. i?86*)
  3975. if [[ ${type} == "kern" && ${host} == *freebsd* ]]; then
  3976. echo i386;
  3977. else
  3978. echo x86;
  3979. fi
  3980. ;;
  3981. ia64*)
  3982. echo ia64
  3983. ;;
  3984. m68*)
  3985. echo m68k
  3986. ;;
  3987. metag*)
  3988. echo metag
  3989. ;;
  3990. microblaze*)
  3991. echo microblaze
  3992. ;;
  3993. mips*)
  3994. echo mips
  3995. ;;
  3996. nios2*)
  3997. echo nios2
  3998. ;;
  3999. nios*)
  4000. echo nios
  4001. ;;
  4002. or1k | or32*)
  4003. echo openrisc
  4004. ;;
  4005. powerpc*)
  4006. if [[ ${type} == "kern" ]]; then
  4007. echo powerpc;
  4008. else
  4009. if [[ ${host} == powerpc64* ]]; then
  4010. echo ppc64;
  4011. else
  4012. echo ppc;
  4013. fi;
  4014. fi
  4015. ;;
  4016. riscv*)
  4017. echo riscv
  4018. ;;
  4019. s390*)
  4020. echo s390
  4021. ;;
  4022. score*)
  4023. echo score
  4024. ;;
  4025. sh64*)
  4026. ninj sh64 sh
  4027. ;;
  4028. sh*)
  4029. echo sh
  4030. ;;
  4031. sparc64*)
  4032. ninj sparc64 sparc
  4033. ;;
  4034. sparc*)
  4035. [[ ${PROFILE_ARCH} == "sparc64" ]] && ninj sparc64 sparc || echo sparc
  4036. ;;
  4037. tile*)
  4038. echo tile
  4039. ;;
  4040. vax*)
  4041. echo vax
  4042. ;;
  4043. x86_64*freebsd*)
  4044. echo amd64
  4045. ;;
  4046. x86_64*)
  4047. if [[ ${type} == "kern" ]]; then
  4048. echo x86;
  4049. else
  4050. echo amd64;
  4051. fi
  4052. ;;
  4053. xtensa*)
  4054. echo xtensa
  4055. ;;
  4056. *)
  4057. echo unknown
  4058. ;;
  4059. esac
  4060. }
  4061. tc-stack-grows-down ()
  4062. {
  4063. case ${ARCH} in
  4064. hppa | metag)
  4065. return 1
  4066. ;;
  4067. esac;
  4068. return 0
  4069. }
  4070. tc_version_is_at_least ()
  4071. {
  4072. version_is_at_least "$1" "${2:-${GCC_RELEASE_VER}}"
  4073. }
  4074. tc_version_is_between ()
  4075. {
  4076. tc_version_is_at_least "${1}" && ! tc_version_is_at_least "${2}"
  4077. }
  4078. test-flag-CC ()
  4079. {
  4080. test-flag-PROG "CC" c "$@"
  4081. }
  4082. test-flag-CXX ()
  4083. {
  4084. test-flag-PROG "CXX" c++ "$@"
  4085. }
  4086. test-flag-F77 ()
  4087. {
  4088. test-flag-PROG "F77" f77 "$@"
  4089. }
  4090. test-flag-FC ()
  4091. {
  4092. test-flag-PROG "FC" f95 "$@"
  4093. }
  4094. test-flag-PROG ()
  4095. {
  4096. local comp=$1;
  4097. local lang=$2;
  4098. shift 2;
  4099. [[ -z ${comp} || -z $1 ]] && return 1;
  4100. local cmdline=($(tc-get${comp}) -Werror -c -o /dev/null);
  4101. if "${cmdline[@]}" -x${lang} - < /dev/null &> /dev/null; then
  4102. cmdline+=("$@" -x${lang} -);
  4103. else
  4104. cmdline+=("$@" -c -o /dev/null /dev/null);
  4105. fi;
  4106. if ! "${cmdline[@]}" < /dev/null &> /dev/null; then
  4107. cmdline+=(-Qunused-arguments);
  4108. "${cmdline[@]}" < /dev/null &> /dev/null;
  4109. fi
  4110. }
  4111. test-flags ()
  4112. {
  4113. test-flags-CC "$@"
  4114. }
  4115. test-flags-CC ()
  4116. {
  4117. test-flags-PROG "CC" "$@"
  4118. }
  4119. test-flags-CXX ()
  4120. {
  4121. test-flags-PROG "CXX" "$@"
  4122. }
  4123. test-flags-F77 ()
  4124. {
  4125. test-flags-PROG "F77" "$@"
  4126. }
  4127. test-flags-FC ()
  4128. {
  4129. test-flags-PROG "FC" "$@"
  4130. }
  4131. test-flags-PROG ()
  4132. {
  4133. local comp=$1;
  4134. local flags=();
  4135. local x;
  4136. shift;
  4137. [[ -z ${comp} ]] && return 1;
  4138. while (( $# )); do
  4139. case "$1" in
  4140. --param)
  4141. if test-flag-${comp} "$1" "$2"; then
  4142. flags+=("$1" "$2");
  4143. fi;
  4144. shift 2
  4145. ;;
  4146. *)
  4147. if test-flag-${comp} "$1"; then
  4148. flags+=("$1");
  4149. fi;
  4150. shift 1
  4151. ;;
  4152. esac;
  4153. done;
  4154. echo "${flags[*]}";
  4155. [[ ${#flags[@]} -gt 0 ]]
  4156. }
  4157. test_version_info ()
  4158. {
  4159. if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then
  4160. return 0;
  4161. else
  4162. return 1;
  4163. fi
  4164. }
  4165. toolchain_death_notice ()
  4166. {
  4167. if [[ -e "${WORKDIR}"/build ]]; then
  4168. pushd "${WORKDIR}"/build > /dev/null;
  4169. ( echo '' | $(tc-getCC ${CTARGET}) ${CFLAGS} -v -E - 2>&1 ) > gccinfo.log;
  4170. [[ -e "${T}"/build.log ]] && cp "${T}"/build.log .;
  4171. tar jcf "${WORKDIR}"/gcc-build-logs.tar.bz2 gccinfo.log build.log $(find -name config.log);
  4172. rm gccinfo.log build.log;
  4173. eerror;
  4174. eerror "Please include ${WORKDIR}/gcc-build-logs.tar.bz2 in your bug report.";
  4175. eerror;
  4176. popd > /dev/null;
  4177. fi
  4178. }
  4179. toolchain_pkg_postinst ()
  4180. {
  4181. do_gcc_config;
  4182. if [[ ${ROOT} == / && -f ${EPREFIX}/usr/share/eselect/modules/compiler-shadow.eselect ]]; then
  4183. eselect compiler-shadow update all;
  4184. fi;
  4185. if ! is_crosscompile && [[ ${PN} != "kgcc64" ]]; then
  4186. echo;
  4187. ewarn "If you have issues with packages unable to locate libstdc++.la,";
  4188. ewarn "then try running 'fix_libtool_files.sh' on the old gcc versions.";
  4189. echo;
  4190. ewarn "You might want to review the GCC upgrade guide when moving between";
  4191. ewarn "major versions (like 4.2 to 4.3):";
  4192. ewarn "https://wiki.gentoo.org/wiki/Upgrading_GCC";
  4193. echo;
  4194. rm -f "${EROOT}"*/rcscripts/awk/fixlafiles.awk "${EROOT}"sbin/fix_libtool_files.sh;
  4195. rmdir "${EROOT}"*/rcscripts{/awk,} 2> /dev/null;
  4196. mkdir -p "${EROOT}"usr/{share/gcc-data,sbin,bin};
  4197. cp "${ROOT}${DATAPATH}"/fixlafiles.awk "${EROOT}"usr/share/gcc-data/ || die;
  4198. cp "${ROOT}${DATAPATH}"/fix_libtool_files.sh "${EROOT}"usr/sbin/ || die;
  4199. cp "${ROOT}${DATAPATH}"/c{89,99} "${EROOT}"usr/bin/ 2> /dev/null;
  4200. fi;
  4201. if use regression-test; then
  4202. elog "Testsuite results have been installed into /usr/share/doc/${PF}/testsuite";
  4203. echo;
  4204. fi;
  4205. if [[ -n ${PRERELEASE}${SNAPSHOT} ]]; then
  4206. einfo "This GCC ebuild is provided for your convenience, and the use";
  4207. einfo "of this compiler is not supported by the Gentoo Developers.";
  4208. einfo "Please report bugs to upstream at http://gcc.gnu.org/bugzilla/";
  4209. fi
  4210. }
  4211. toolchain_pkg_postrm ()
  4212. {
  4213. if [[ ${ROOT} == / && -f ${EPREFIX}/usr/share/eselect/modules/compiler-shadow.eselect ]]; then
  4214. eselect compiler-shadow clean all;
  4215. fi;
  4216. if is_crosscompile; then
  4217. if [[ -z $(ls "${EROOT}"etc/env.d/gcc/${CTARGET}* 2>/dev/null) ]]; then
  4218. rm -f "${EROOT}"etc/env.d/gcc/config-${CTARGET};
  4219. rm -f "${EROOT}"etc/env.d/??gcc-${CTARGET};
  4220. rm -f "${EROOT}"usr/bin/${CTARGET}-{gcc,{g,c}++}{,32,64};
  4221. fi;
  4222. return 0;
  4223. fi;
  4224. [[ ${ROOT} != "/" ]] && return 0;
  4225. if [[ ! -e ${LIBPATH}/libstdc++.so ]]; then
  4226. do_gcc_config;
  4227. einfo "Running 'fix_libtool_files.sh ${GCC_RELEASE_VER}'";
  4228. fix_libtool_files.sh ${GCC_RELEASE_VER};
  4229. if [[ -n ${BRANCH_UPDATE} ]]; then
  4230. einfo "Running 'fix_libtool_files.sh ${GCC_RELEASE_VER}-${BRANCH_UPDATE}'";
  4231. fix_libtool_files.sh ${GCC_RELEASE_VER}-${BRANCH_UPDATE};
  4232. fi;
  4233. fi;
  4234. return 0
  4235. }
  4236. toolchain_pkg_pretend ()
  4237. {
  4238. if [[ -n ${PRERELEASE}${SNAPSHOT} || ${PV} == *9999* ]] && [[ -z ${I_PROMISE_TO_SUPPLY_PATCHES_WITH_BUGS} ]]; then
  4239. die "Please \`export I_PROMISE_TO_SUPPLY_PATCHES_WITH_BUGS=1\` or define it" "in your make.conf if you want to use this version.";
  4240. fi;
  4241. if ! use_if_iuse cxx; then
  4242. use_if_iuse go && ewarn 'Go requires a C++ compiler, disabled due to USE="-cxx"';
  4243. use_if_iuse objc++ && ewarn 'Obj-C++ requires a C++ compiler, disabled due to USE="-cxx"';
  4244. use_if_iuse gcj && ewarn 'GCJ requires a C++ compiler, disabled due to USE="-cxx"';
  4245. fi;
  4246. want_minispecs
  4247. }
  4248. toolchain_pkg_setup ()
  4249. {
  4250. unset GCC_SPECS;
  4251. unset LANGUAGES
  4252. }
  4253. toolchain_src_compile ()
  4254. {
  4255. touch "${S}"/gcc/c-gperf.h;
  4256. [[ ! -x /usr/bin/perl ]] && find "${WORKDIR}"/build -name '*.[17]' -exec touch {} +;
  4257. gcc_do_make ${GCC_MAKE_TARGET}
  4258. }
  4259. toolchain_src_configure ()
  4260. {
  4261. downgrade_arch_flags;
  4262. gcc_do_filter_flags;
  4263. einfo "CFLAGS=\"${CFLAGS}\"";
  4264. einfo "CXXFLAGS=\"${CXXFLAGS}\"";
  4265. einfo "LDFLAGS=\"${LDFLAGS}\"";
  4266. export JAR=no;
  4267. if ! tc_version_is_at_least 4.4 && want_minispecs; then
  4268. setup_minispecs_gcc_build_specs;
  4269. fi;
  4270. local confgcc=(--host=${CHOST});
  4271. if is_crosscompile || tc-is-cross-compiler; then
  4272. confgcc+=(--target=${CTARGET});
  4273. fi;
  4274. [[ -n ${CBUILD} ]] && confgcc+=(--build=${CBUILD});
  4275. confgcc+=(--prefix="${PREFIX}" --bindir="${BINPATH}" --includedir="${INCLUDEPATH}" --datadir="${DATAPATH}" --mandir="${DATAPATH}/man" --infodir="${DATAPATH}/info" --with-gxx-include-dir="${STDCXX_INCDIR}");
  4276. if tc_version_is_at_least 4.4; then
  4277. confgcc+=(--with-python-dir=${DATAPATH/$PREFIX/}/python);
  4278. fi;
  4279. local GCC_LANG="c";
  4280. is_cxx && GCC_LANG+=",c++";
  4281. is_d && GCC_LANG+=",d";
  4282. is_gcj && GCC_LANG+=",java";
  4283. is_go && GCC_LANG+=",go";
  4284. is_jit && GCC_LANG+=",jit";
  4285. if is_objc || is_objcxx; then
  4286. GCC_LANG+=",objc";
  4287. if tc_version_is_at_least 4; then
  4288. use objc-gc && confgcc+=(--enable-objc-gc);
  4289. fi;
  4290. is_objcxx && GCC_LANG+=",obj-c++";
  4291. fi;
  4292. is_fortran && GCC_LANG+=",fortran";
  4293. is_f77 && GCC_LANG+=",f77";
  4294. is_f95 && GCC_LANG+=",f95";
  4295. confgcc+=(--enable-languages=${GCC_LANG});
  4296. confgcc+=(--enable-obsolete --enable-secureplt --disable-werror --with-system-zlib);
  4297. if use nls; then
  4298. confgcc+=(--enable-nls --without-included-gettext);
  4299. else
  4300. confgcc+=(--disable-nls);
  4301. fi;
  4302. tc_version_is_at_least 3.4 || confgcc+=(--disable-libunwind-exceptions);
  4303. if tc_version_is_at_least 3.4 && in_iuse debug; then
  4304. local off=$(tc_version_is_at_least 4.0 && echo release || echo no);
  4305. confgcc+=(--enable-checking="${GCC_CHECKS_LIST:-$(usex debug yes ${off})}");
  4306. fi;
  4307. tc_version_is_at_least 4.3 && confgcc+=(--with-bugurl=https://bugs.gentoo.org/ --with-pkgversion="${BRANDING_GCC_PKGVERSION}");
  4308. if tc_version_is_at_least 4.4 && want_minispecs && in_iuse hardened; then
  4309. confgcc+=($(use_enable hardened esp));
  4310. fi;
  4311. if tc_version_is_at_least 4.4 && is_cxx; then
  4312. confgcc+=(--enable-libstdcxx-time);
  4313. fi;
  4314. if tc_version_is_at_least 6.0 && ! use_if_iuse pch; then
  4315. confgcc+=(--disable-libstdcxx-pch);
  4316. fi;
  4317. is_jit && confgcc+=(--enable-host-shared);
  4318. if tc_version_is_between 4.7 4.8 && ! is_cxx; then
  4319. confgcc+=(--disable-build-with-cxx --disable-build-poststage1-with-cxx);
  4320. fi;
  4321. if is_crosscompile; then
  4322. confgcc+=(--enable-poison-system-directories);
  4323. local needed_libc="";
  4324. case ${CTARGET} in
  4325. *-linux)
  4326. needed_libc=no-fucking-clue
  4327. ;;
  4328. *-dietlibc)
  4329. needed_libc=dietlibc
  4330. ;;
  4331. *-elf | *-eabi)
  4332. needed_libc=newlib;
  4333. confgcc+=(--disable-libstdcxx-time)
  4334. ;;
  4335. *-freebsd*)
  4336. needed_libc=freebsd-lib
  4337. ;;
  4338. *-gnu*)
  4339. needed_libc=glibc
  4340. ;;
  4341. *-klibc)
  4342. needed_libc=klibc
  4343. ;;
  4344. *-musl*)
  4345. needed_libc=musl
  4346. ;;
  4347. *-uclibc*)
  4348. if ! echo '#include <features.h>' | $(tc-getCPP ${CTARGET}) -E -dD - 2> /dev/null | grep -q __HAVE_SHARED__; then
  4349. confgcc+=(--disable-shared);
  4350. fi;
  4351. needed_libc=uclibc
  4352. ;;
  4353. *-cygwin)
  4354. needed_libc=cygwin
  4355. ;;
  4356. x86_64-*-mingw* | *-w64-mingw*)
  4357. needed_libc=mingw64-runtime
  4358. ;;
  4359. mingw* | *-mingw*)
  4360. needed_libc=mingw-runtime
  4361. ;;
  4362. avr)
  4363. confgcc+=(--enable-shared --disable-threads)
  4364. ;;
  4365. esac;
  4366. if [[ -n ${needed_libc} ]]; then
  4367. local confgcc_no_libc=(--disable-shared);
  4368. tc_version_is_at_least 4.8 && confgcc_no_libc+=(--disable-libatomic);
  4369. if ! has_version ${CATEGORY}/${needed_libc}; then
  4370. confgcc+=("${confgcc_no_libc[@]}" --disable-threads --without-headers);
  4371. else
  4372. if has_version "${CATEGORY}/${needed_libc}[headers-only(-)]"; then
  4373. confgcc+=("${confgcc_no_libc[@]}" --with-sysroot="${PREFIX}"/${CTARGET});
  4374. else
  4375. confgcc+=(--with-sysroot="${PREFIX}"/${CTARGET});
  4376. fi;
  4377. fi;
  4378. fi;
  4379. tc_version_is_at_least 4.2 && confgcc+=(--disable-bootstrap);
  4380. else
  4381. if tc-is-static-only; then
  4382. confgcc+=(--disable-shared);
  4383. else
  4384. confgcc+=(--enable-shared);
  4385. fi;
  4386. case ${CHOST} in
  4387. mingw* | *-mingw* | *-cygwin)
  4388. confgcc+=(--enable-threads=win32)
  4389. ;;
  4390. *)
  4391. confgcc+=(--enable-threads=posix)
  4392. ;;
  4393. esac;
  4394. fi;
  4395. case ${CTARGET} in
  4396. *-uclibc*)
  4397. confgcc+=(--disable-__cxa_atexit $(use_enable nptl tls));
  4398. tc_version_is_between 3.3 3.4 && confgcc+=(--enable-sjlj-exceptions);
  4399. if tc_version_is_between 3.4 4.3; then
  4400. confgcc+=(--enable-clocale=uclibc);
  4401. fi
  4402. ;;
  4403. *-elf | *-eabi)
  4404. confgcc+=(--with-newlib)
  4405. ;;
  4406. *-gnu*)
  4407. confgcc+=(--enable-__cxa_atexit --enable-clocale=gnu)
  4408. ;;
  4409. *-freebsd*)
  4410. confgcc+=(--enable-__cxa_atexit)
  4411. ;;
  4412. *-solaris*)
  4413. confgcc+=(--enable-__cxa_atexit)
  4414. ;;
  4415. esac;
  4416. gcc-multilib-configure;
  4417. in_iuse altivec && confgcc+=($(use_enable altivec));
  4418. tc_version_is_at_least 4.3 && in_iuse fixed-point && confgcc+=($(use_enable fixed-point));
  4419. case $(tc-is-softfloat) in
  4420. yes)
  4421. confgcc+=(--with-float=soft)
  4422. ;;
  4423. softfp)
  4424. confgcc+=(--with-float=softfp)
  4425. ;;
  4426. *)
  4427. case ${CTARGET//_/-} in
  4428. *-hardfloat-* | *eabihf)
  4429. confgcc+=(--with-float=hard)
  4430. ;;
  4431. esac
  4432. ;;
  4433. esac;
  4434. local with_abi_map=();
  4435. case $(tc-arch) in
  4436. arm)
  4437. local a arm_arch=${CTARGET%%-*};
  4438. for a in e{b,l} {b,l}e b l;
  4439. do
  4440. if [[ ${arm_arch} == *${a} ]]; then
  4441. arm_arch=${arm_arch%${a}};
  4442. break;
  4443. fi;
  4444. done;
  4445. [[ ${arm_arch} == armv7? ]] && arm_arch=${arm_arch/7/7-};
  4446. if ( srcdir=${S}/gcc target=${CTARGET} with_arch=${arm_arch};
  4447. . "${srcdir}"/config.gcc ) &> /dev/null; then
  4448. confgcc+=(--with-arch=${arm_arch});
  4449. fi;
  4450. [[ ${arm_arch} == *-m ]] && confgcc+=(--with-mode=thumb);
  4451. if [[ $(tc-is-softfloat) == "no" ]] && [[ ${CTARGET} == armv[67]* ]] && tc_version_is_at_least 4.5; then
  4452. confgcc+=(--with-float=hard);
  4453. case ${CTARGET} in
  4454. armv6*)
  4455. confgcc+=(--with-fpu=vfp)
  4456. ;;
  4457. armv7*)
  4458. confgcc+=(--with-fpu=vfpv3-d16)
  4459. ;;
  4460. esac;
  4461. fi
  4462. ;;
  4463. mips)
  4464. confgcc+=(--with-abi=$(gcc-abi-map ${TARGET_DEFAULT_ABI}))
  4465. ;;
  4466. amd64)
  4467. if tc_version_is_at_least 4.8 && has x32 $(get_all_abis TARGET); then
  4468. confgcc+=(--with-abi=$(gcc-abi-map ${TARGET_DEFAULT_ABI}));
  4469. fi
  4470. ;;
  4471. x86)
  4472. confgcc+=(--with-arch=${CTARGET%%-*})
  4473. ;;
  4474. hppa)
  4475. [[ ${GCCMAJOR} == "3" ]] && confgcc+=(--enable-sjlj-exceptions)
  4476. ;;
  4477. ppc)
  4478. is-flagq -mfloat-gprs=double && confgcc+=(--enable-e500-double);
  4479. [[ ${CTARGET//_/-} == *-e500v2-* ]] && confgcc+=(--enable-e500-double)
  4480. ;;
  4481. esac;
  4482. case $(tc-arch) in
  4483. ppc | ppc64)
  4484. tc_version_is_at_least 3.4 && confgcc+=(--enable-targets=all)
  4485. ;;
  4486. sparc)
  4487. tc_version_is_at_least 4.4 && confgcc+=(--enable-targets=all)
  4488. ;;
  4489. amd64 | x86)
  4490. tc_version_is_at_least 4.3 && confgcc+=(--enable-targets=all)
  4491. ;;
  4492. esac;
  4493. [[ ${CTARGET} == *-darwin* ]] && confgcc+=(--enable-version-specific-runtime-libs);
  4494. if ! is_gcj; then
  4495. confgcc+=(--disable-libgcj);
  4496. else
  4497. if use awt; then
  4498. confgcc+=(--enable-java-awt=gtk);
  4499. fi;
  4500. fi;
  4501. if tc_version_is_at_least 4.2; then
  4502. if in_iuse openmp; then
  4503. if ! is_crosscompile || $(tc-getCPP ${CTARGET}) -E - <<< "#include <pthread.h>" &> /dev/null; then
  4504. confgcc+=($(use_enable openmp libgomp));
  4505. else
  4506. confgcc+=(--disable-libgomp);
  4507. fi;
  4508. else
  4509. confgcc+=(--disable-libgomp);
  4510. fi;
  4511. fi;
  4512. if tc_version_is_at_least 4.0; then
  4513. if in_iuse mudflap; then
  4514. confgcc+=($(use_enable mudflap libmudflap));
  4515. else
  4516. confgcc+=(--disable-libmudflap);
  4517. fi;
  4518. if use_if_iuse libssp; then
  4519. confgcc+=(--enable-libssp);
  4520. else
  4521. if hardened_gcc_is_stable ssp; then
  4522. export gcc_cv_libc_provides_ssp=yes;
  4523. fi;
  4524. if use_if_iuse ssp; then
  4525. case ${CTARGET} in
  4526. mingw* | *-mingw*)
  4527. ewarn "Not disabling libssp"
  4528. ;;
  4529. *)
  4530. confgcc+=(--disable-libssp)
  4531. ;;
  4532. esac;
  4533. else
  4534. confgcc+=(--disable-libssp);
  4535. fi;
  4536. fi;
  4537. fi;
  4538. if in_iuse cilk; then
  4539. confgcc+=($(use_enable cilk libcilkrts));
  4540. fi;
  4541. if in_iuse mpx; then
  4542. confgcc+=($(use_enable mpx libmpx));
  4543. fi;
  4544. if in_iuse systemtap; then
  4545. confgcc+=($(use_enable systemtap));
  4546. fi;
  4547. if in_iuse vtv; then
  4548. confgcc+=($(use_enable vtv vtable-verify) $(use_enable vtv libvtv));
  4549. fi;
  4550. if tc_version_is_at_least 4.6 && ! is_fortran; then
  4551. confgcc+=(--disable-libquadmath);
  4552. fi;
  4553. if tc_version_is_at_least 4.6; then
  4554. confgcc+=(--enable-lto);
  4555. else
  4556. if tc_version_is_at_least 4.5; then
  4557. confgcc+=(--disable-lto);
  4558. fi;
  4559. fi;
  4560. if tc_version_is_at_least 5.0 && in_iuse graphite; then
  4561. confgcc+=($(use_with graphite isl));
  4562. use graphite && confgcc+=(--disable-isl-version-check);
  4563. else
  4564. if tc_version_is_at_least 4.8 && in_iuse graphite; then
  4565. confgcc+=($(use_with graphite cloog));
  4566. use graphite && confgcc+=(--disable-isl-version-check);
  4567. else
  4568. if tc_version_is_at_least 4.4; then
  4569. confgcc+=(--without-{cloog,ppl});
  4570. fi;
  4571. fi;
  4572. fi;
  4573. if tc_version_is_at_least 4.8 && in_iuse sanitize; then
  4574. confgcc+=($(use_enable sanitize libsanitizer));
  4575. fi;
  4576. if tc_version_is_at_least 6.0 && in_iuse pie; then
  4577. confgcc+=($(use_enable pie default-pie));
  4578. fi;
  4579. if tc_version_is_at_least 6.0 && in_iuse ssp; then
  4580. confgcc+=($(use_enable ssp default-ssp));
  4581. fi;
  4582. export gcc_cv_prog_makeinfo_modern=no;
  4583. export ac_cv_have_x='have_x=yes ac_x_includes= ac_x_libraries=';
  4584. confgcc+=("$@" ${EXTRA_ECONF});
  4585. echo;
  4586. einfo "PREFIX: ${PREFIX}";
  4587. einfo "BINPATH: ${BINPATH}";
  4588. einfo "LIBPATH: ${LIBPATH}";
  4589. einfo "DATAPATH: ${DATAPATH}";
  4590. einfo "STDCXX_INCDIR: ${STDCXX_INCDIR}";
  4591. echo;
  4592. einfo "Languages: ${GCC_LANG}";
  4593. echo;
  4594. einfo "Configuring GCC with: ${confgcc[@]//--/\n\t--}";
  4595. echo;
  4596. mkdir -p "${WORKDIR}"/build;
  4597. pushd "${WORKDIR}"/build > /dev/null;
  4598. addwrite /dev/zero;
  4599. echo "${S}"/configure "${confgcc[@]}";
  4600. CONFIG_SHELL="${EPREFIX}/bin/bash" bash "${S}"/configure "${confgcc[@]}" || die "failed to run configure";
  4601. popd > /dev/null
  4602. }
  4603. toolchain_src_install ()
  4604. {
  4605. cd "${WORKDIR}"/build;
  4606. find gcc/include*/ -type l -delete;
  4607. mkdir -p gcc/doc;
  4608. local x=;
  4609. for x in "${S}"/gcc/doc/*.info*;
  4610. do
  4611. if [[ -f ${x} ]]; then
  4612. cp "${x}" gcc/doc/ || die;
  4613. fi;
  4614. done;
  4615. while read x; do
  4616. grep -q 'It has been auto-edited by fixincludes from' "${x}" && rm -f "${x}";
  4617. done < <(find gcc/include*/ -name '*.h');
  4618. S="${WORKDIR}"/build emake -j1 DESTDIR="${D}" install || die;
  4619. find "${D}" -name install-tools -prune -type d -exec rm -rf "{}" \;;
  4620. find "${D}" -name libiberty.a -delete;
  4621. gcc_movelibs;
  4622. if ! is_crosscompile; then
  4623. local EXEEXT;
  4624. eval $(grep ^EXEEXT= "${WORKDIR}"/build/gcc/config.log);
  4625. [[ -r ${D}${BINPATH}/gcc${EXEEXT} ]] || die "gcc not found in ${D}";
  4626. fi;
  4627. dodir /etc/env.d/gcc;
  4628. create_gcc_env_entry;
  4629. want_minispecs && copy_minispecs_gcc_specs;
  4630. gcc_slot_java;
  4631. dodir /usr/bin;
  4632. cd "${D}"${BINPATH};
  4633. for x in cpp gcc g++ c++ gcov g77 gcj gcjh gfortran gccgo;
  4634. do
  4635. if [[ -f ${x} ]]; then
  4636. rm -f ${CTARGET}-${x};
  4637. mv ${x} ${CTARGET}-${x};
  4638. fi;
  4639. if [[ -f ${CTARGET}-${x} ]]; then
  4640. if ! is_crosscompile; then
  4641. ln -sf ${CTARGET}-${x} ${x};
  4642. dosym ${BINPATH#${EPREFIX}}/${CTARGET}-${x} /usr/bin/${x}-${GCC_CONFIG_VER};
  4643. fi;
  4644. dosym ${BINPATH#${EPREFIX}}/${CTARGET}-${x} /usr/bin/${CTARGET}-${x}-${GCC_CONFIG_VER};
  4645. fi;
  4646. if [[ -f ${CTARGET}-${x}-${GCC_CONFIG_VER} ]]; then
  4647. rm -f ${CTARGET}-${x}-${GCC_CONFIG_VER};
  4648. ln -sf ${CTARGET}-${x} ${CTARGET}-${x}-${GCC_CONFIG_VER};
  4649. fi;
  4650. done;
  4651. if tc_version_is_at_least 5 && is_go; then
  4652. for x in go gofmt;
  4653. do
  4654. mv ${x} ${x}-${GCCMAJOR} || die;
  4655. done;
  4656. fi;
  4657. env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${BINPATH}";
  4658. is_crosscompile && env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${HOSTLIBPATH}";
  4659. env RESTRICT="" CHOST=${CTARGET} prepstrip "${D}${LIBPATH}";
  4660. [[ -d ${D}${PREFIX}/libexec/gcc ]] && env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}";
  4661. cd "${S}";
  4662. if is_crosscompile; then
  4663. rm -rf "${ED}"usr/share/{man,info};
  4664. rm -rf "${D}"${DATAPATH}/{man,info};
  4665. else
  4666. if tc_version_is_at_least 3.0; then
  4667. local cxx_mandir=$(find "${WORKDIR}/build/${CTARGET}/libstdc++-v3" -name man);
  4668. if [[ -d ${cxx_mandir} ]]; then
  4669. cp -r "${cxx_mandir}"/man? "${D}/${DATAPATH}"/man/;
  4670. fi;
  4671. fi;
  4672. has noinfo ${FEATURES} && rm -r "${D}${DATAPATH}"/info || prepinfo "${DATAPATH#${EPREFIX}}";
  4673. has noman ${FEATURES} && rm -r "${D}${DATAPATH}"/man || prepman "${DATAPATH#${EPREFIX}}";
  4674. fi;
  4675. find "${D}" -depth -type d -delete 2> /dev/null;
  4676. if use regression-test; then
  4677. docinto testsuite;
  4678. find "${WORKDIR}"/build -type f -name "*.sum" -exec dodoc {} +;
  4679. find "${WORKDIR}"/build -type f -path "*/testsuite/*.log" -exec dodoc {} +;
  4680. fi;
  4681. if ! is_crosscompile && [[ ${PN} != "kgcc64" ]]; then
  4682. insinto "${DATAPATH#${EPREFIX}}";
  4683. newins "$(prefixify_ro "${FILESDIR}"/awk/fixlafiles.awk-no_gcc_la)" fixlafiles.awk || die;
  4684. exeinto "${DATAPATH#${EPREFIX}}";
  4685. doexe "$(prefixify_ro "${FILESDIR}"/fix_libtool_files.sh)" || die;
  4686. doexe "${FILESDIR}"/c{89,99} || die;
  4687. fi;
  4688. find "${D}/${LIBPATH}" '(' -name libstdc++.la -o -name libstdc++fs.la -o -name libsupc++.la -o -name libcc1.la -o -name libcc1plugin.la -o -name libcp1plugin.la -o -name 'libgomp.la' -o -name 'libgomp-plugin-*.la' -o -name libgfortran.la -o -name libgfortranbegin.la -o -name libmpx.la -o -name libmpxwrappers.la -o -name libitm.la -o -name libvtv.la -o -name 'lib*san.la' ')' -type f -delete;
  4689. chown -R root:0 "${D}${LIBPATH}" 2> /dev/null;
  4690. local py gdbdir=/usr/share/gdb/auto-load${LIBPATH/\/lib\//\/$(get_libdir)\/};
  4691. pushd "${D}${LIBPATH}" > /dev/null;
  4692. for py in $(find . -name '*-gdb.py');
  4693. do
  4694. local multidir=${py%/*};
  4695. insinto "${gdbdir}/${multidir}";
  4696. sed -i "/^libdir =/s:=.*:= '${LIBPATH}/${multidir}':" "${py}" || die;
  4697. doins "${py}" || die;
  4698. rm "${py}" || die;
  4699. done;
  4700. popd > /dev/null;
  4701. export QA_EXECSTACK="usr/lib*/go/*/*.gox";
  4702. export QA_WX_LOAD="usr/lib*/go/*/*.gox";
  4703. if tc_version_is_at_least 4.3; then
  4704. pax-mark -r "${D}${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}/cc1";
  4705. pax-mark -r "${D}${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}/cc1plus";
  4706. fi;
  4707. if is_gcj; then
  4708. pax-mark -m "${D}${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}/ecj1";
  4709. pax-mark -m "${D}${PREFIX}/${CTARGET}/gcc-bin/${GCC_CONFIG_VER}/gij";
  4710. fi
  4711. }
  4712. toolchain_src_prepare ()
  4713. {
  4714. export BRANDING_GCC_PKGVERSION="Gentoo ${GCC_PVR}";
  4715. cd "${S}";
  4716. if ! use vanilla; then
  4717. if [[ -n ${PATCH_VER} ]]; then
  4718. guess_patch_type_in_dir "${WORKDIR}"/patch;
  4719. EPATCH_MULTI_MSG="Applying Gentoo patches ..." epatch "${WORKDIR}"/patch;
  4720. BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION} p${PATCH_VER}";
  4721. fi;
  4722. if [[ -n ${UCLIBC_VER} ]]; then
  4723. guess_patch_type_in_dir "${WORKDIR}"/uclibc;
  4724. EPATCH_MULTI_MSG="Applying uClibc patches ..." epatch "${WORKDIR}"/uclibc;
  4725. fi;
  4726. fi;
  4727. do_gcc_HTB_patches;
  4728. do_gcc_PIE_patches;
  4729. epatch_user;
  4730. if ( tc_version_is_at_least 4.8.2 || use_if_iuse hardened ) && ! use vanilla; then
  4731. make_gcc_hard;
  4732. fi;
  4733. if tc_version_is_between 4.5 4.7; then
  4734. sed -i '/^pythondir =/s:=.*:= $(datadir)/python:' "${S}"/libstdc++-v3/python/Makefile.in || die;
  4735. fi;
  4736. find "${S}" -name Makefile.in -exec sed -i '/^pkgconfigdir/s:=.*:=$(toolexeclibdir)/pkgconfig:' {} +;
  4737. if ! tc_version_is_at_least 4.3; then
  4738. fix_files="";
  4739. for x in contrib/test_summary libstdc++-v3/scripts/check_survey.in;
  4740. do
  4741. [[ -e ${x} ]] && fix_files="${fix_files} ${x}";
  4742. done;
  4743. ht_fix_file ${fix_files} */configure *.sh */Makefile.in;
  4744. fi;
  4745. setup_multilib_osdirnames;
  4746. gcc_version_patch;
  4747. if tc_version_is_at_least 4.1; then
  4748. if [[ -n ${SNAPSHOT} || -n ${PRERELEASE} ]]; then
  4749. echo ${PV/_/-} > "${S}"/gcc/BASE-VER;
  4750. fi;
  4751. fi;
  4752. if tc_version_is_at_least 4.3 && use_if_iuse gcj; then
  4753. if tc_version_is_at_least 4.5; then
  4754. einfo "Copying ecj-4.5.jar";
  4755. cp -pPR "${DISTDIR}/ecj-4.5.jar" "${S}/ecj.jar" || die;
  4756. else
  4757. einfo "Copying ecj-4.3.jar";
  4758. cp -pPR "${DISTDIR}/ecj-4.3.jar" "${S}/ecj.jar" || die;
  4759. fi;
  4760. fi;
  4761. if ! tc_version_is_at_least 3.4.4; then
  4762. sed -i -e s/HAVE_LD_AS_NEEDED/USE_LD_AS_NEEDED/g "${S}"/gcc/config.in;
  4763. fi;
  4764. if tc_version_is_between 3.3 4.0; then
  4765. do_gcc_rename_java_bins;
  4766. fi;
  4767. if tc_version_is_between 3.0 4.8; then
  4768. sed -i -e 's/\(install.*:\) install-.*recursive/\1/' "${S}"/libffi/Makefile.in || die;
  4769. sed -i -e 's/\(install-data-am:\).*/\1/' "${S}"/libffi/include/Makefile.in || die;
  4770. fi;
  4771. elibtoolize --portage --shallow --no-uclibc;
  4772. gnuconfig_update;
  4773. local f;
  4774. einfo "Fixing misc issues in configure files";
  4775. for f in $(grep -l 'autoconf version 2.13' $(find "${S}" -name configure));
  4776. do
  4777. ebegin " Updating ${f/${S}\/} [LANG]";
  4778. patch "${f}" "${FILESDIR}"/gcc-configure-LANG.patch &> "${T}"/configure-patch.log || eerror "Please file a bug about this";
  4779. eend $?;
  4780. done;
  4781. sed -i 's|A-Za-z0-9|[:alnum:]|g' "${S}"/gcc/*.awk;
  4782. tc_version_is_at_least 4.1 && epatch "${FILESDIR}"/gcc-configure-texinfo.patch;
  4783. if [[ -x contrib/gcc_update ]]; then
  4784. einfo "Touching generated files";
  4785. ./contrib/gcc_update --touch | while read f; do
  4786. einfo " ${f%%...}";
  4787. done;
  4788. fi
  4789. }
  4790. toolchain_src_test ()
  4791. {
  4792. if use regression-test; then
  4793. cd "${WORKDIR}"/build;
  4794. emake -k check;
  4795. fi
  4796. }
  4797. toolchain_src_unpack ()
  4798. {
  4799. if [[ ${PV} == *9999* ]]; then
  4800. git-2_src_unpack;
  4801. else
  4802. gcc_quick_unpack;
  4803. fi
  4804. }
  4805. uclibctoolize ()
  4806. {
  4807. die "Use elibtoolize"
  4808. }
  4809. use_if_iuse ()
  4810. {
  4811. in_iuse $1 || return 1;
  4812. use $1
  4813. }
  4814. version_compare ()
  4815. {
  4816. eshopts_push -s extglob;
  4817. local ver_a=${1} ver_b=${2} parts_a parts_b;
  4818. local cur_tok_a cur_tok_b num_part_a num_part_b;
  4819. local -i cur_idx_a=0 cur_idx_b=0 prev_idx_a prev_idx_b;
  4820. parts_a=($(get_all_version_components "${ver_a}" ));
  4821. parts_b=($(get_all_version_components "${ver_b}" ));
  4822. local -i inf_loop=0;
  4823. while true; do
  4824. inf_loop+=1;
  4825. ((inf_loop > 20)) && die "versionator compare bug [numbers, ${ver_a}, ${ver_b}]";
  4826. prev_idx_a=cur_idx_a;
  4827. prev_idx_b=cur_idx_b;
  4828. cur_tok_a=${parts_a[cur_idx_a]};
  4829. cur_tok_b=${parts_b[cur_idx_b]};
  4830. if [[ -n ${cur_tok_a} ]] && [[ -z ${cur_tok_a//[[:digit:]]} ]]; then
  4831. cur_idx_a+=1;
  4832. [[ ${parts_a[cur_idx_a]} == . ]] && cur_idx_a+=1;
  4833. else
  4834. cur_tok_a=;
  4835. fi;
  4836. if [[ -n ${cur_tok_b} ]] && [[ -z ${cur_tok_b//[[:digit:]]} ]]; then
  4837. cur_idx_b+=1;
  4838. [[ ${parts_b[cur_idx_b]} == . ]] && cur_idx_b+=1;
  4839. else
  4840. cur_tok_b=;
  4841. fi;
  4842. [[ -z ${cur_tok_a} && -z ${cur_tok_b} ]] && break;
  4843. [[ -z ${cur_tok_a} ]] && eshopts_pop && return 1;
  4844. [[ -z ${cur_tok_b} ]] && eshopts_pop && return 3;
  4845. if (( prev_idx_a != 0 && prev_idx_b != 0 )) && [[ ${cur_tok_a} == 0* || ${cur_tok_b} == 0* ]]; then
  4846. cur_tok_a=${cur_tok_a%%+(0)};
  4847. cur_tok_b=${cur_tok_b%%+(0)};
  4848. [[ ${cur_tok_a} < ${cur_tok_b} ]] && eshopts_pop && return 1;
  4849. [[ ${cur_tok_a} > ${cur_tok_b} ]] && eshopts_pop && return 3;
  4850. else
  4851. cur_tok_a=${cur_tok_a##+(0)};
  4852. cur_tok_b=${cur_tok_b##+(0)};
  4853. : ${cur_tok_a:=0};
  4854. : ${cur_tok_b:=0};
  4855. ((cur_tok_a < cur_tok_b)) && eshopts_pop && return 1;
  4856. ((cur_tok_a > cur_tok_b)) && eshopts_pop && return 3;
  4857. fi;
  4858. done;
  4859. local letter_a=;
  4860. letter_a=${parts_a[cur_idx_a]};
  4861. if [[ ${#letter_a} -eq 1 && -z ${letter_a/[a-z]} ]]; then
  4862. cur_idx_a+=1;
  4863. else
  4864. letter_a=@;
  4865. fi;
  4866. local letter_b=;
  4867. letter_b=${parts_b[cur_idx_b]};
  4868. if [[ ${#letter_b} -eq 1 && -z ${letter_b/[a-z]} ]]; then
  4869. cur_idx_b+=1;
  4870. else
  4871. letter_b=@;
  4872. fi;
  4873. [[ ${letter_a} < ${letter_b} ]] && eshopts_pop && return 1;
  4874. [[ ${letter_a} > ${letter_b} ]] && eshopts_pop && return 3;
  4875. inf_loop=0;
  4876. while true; do
  4877. inf_loop+=1;
  4878. ((inf_loop > 20)) && die "versionator compare bug [numbers, ${ver_a}, ${ver_b}]";
  4879. [[ ${parts_a[cur_idx_a]} == _ ]] && ((cur_idx_a++));
  4880. [[ ${parts_b[cur_idx_b]} == _ ]] && ((cur_idx_b++));
  4881. cur_tok_a=${parts_a[cur_idx_a]};
  4882. cur_tok_b=${parts_b[cur_idx_b]};
  4883. num_part_a=0;
  4884. num_part_b=0;
  4885. if has ${cur_tok_a%%+([0-9])} "alpha" "beta" "pre" "rc" "p"; then
  4886. cur_idx_a+=1;
  4887. num_part_a=${cur_tok_a##+([a-z])};
  4888. num_part_a=${num_part_a##+(0)};
  4889. : ${num_part_a:=0};
  4890. cur_tok_a=${cur_tok_a%%+([0-9])};
  4891. else
  4892. cur_tok_a=;
  4893. fi;
  4894. if has ${cur_tok_b%%+([0-9])} alpha beta pre rc p; then
  4895. cur_idx_b+=1;
  4896. num_part_b=${cur_tok_b##+([a-z])};
  4897. num_part_b=${num_part_b##+(0)};
  4898. : ${num_part_b:=0};
  4899. cur_tok_b=${cur_tok_b%%+([0-9])};
  4900. else
  4901. cur_tok_b=;
  4902. fi;
  4903. if [[ ${cur_tok_a} != ${cur_tok_b} ]]; then
  4904. local suffix;
  4905. for suffix in alpha beta pre rc "" p;
  4906. do
  4907. [[ ${cur_tok_a} == ${suffix} ]] && eshopts_pop && return 1;
  4908. [[ ${cur_tok_b} == ${suffix} ]] && eshopts_pop && return 3;
  4909. done;
  4910. else
  4911. if [[ -z ${cur_tok_a} && -z ${cur_tok_b} ]]; then
  4912. break;
  4913. else
  4914. ((num_part_a < num_part_b)) && eshopts_pop && return 1;
  4915. ((num_part_a > num_part_b)) && eshopts_pop && return 3;
  4916. fi;
  4917. fi;
  4918. done;
  4919. [[ ${parts_a[cur_idx_a]} == - ]] && ((cur_idx_a++));
  4920. [[ ${parts_b[cur_idx_b]} == - ]] && ((cur_idx_b++));
  4921. if [[ -n ${parts_a[cur_idx_a]/r+([0-9])} || -n ${parts_b[cur_idx_b]/r+([0-9])} ]]; then
  4922. die "versionator compare bug [revisions, ${ver_a}, ${ver_b}]";
  4923. fi;
  4924. num_part_a=${parts_a[cur_idx_a]#r};
  4925. num_part_a=${num_part_a##+(0)};
  4926. : ${num_part_a:=0};
  4927. num_part_b=${parts_b[cur_idx_b]#r};
  4928. num_part_b=${num_part_b##+(0)};
  4929. : ${num_part_b:=0};
  4930. ((num_part_a < num_part_b)) && eshopts_pop && return 1;
  4931. ((num_part_a > num_part_b)) && eshopts_pop && return 3;
  4932. eshopts_pop;
  4933. return 2
  4934. }
  4935. version_format_string ()
  4936. {
  4937. local fstr=$1;
  4938. shift;
  4939. set -- $(get_version_components "$@");
  4940. eval echo "${fstr}"
  4941. }
  4942. version_is_at_least ()
  4943. {
  4944. local want_s="$1" have_s="${2:-${PVR}}" r;
  4945. version_compare "${want_s}" "${have_s}";
  4946. r=$?;
  4947. case $r in
  4948. 1 | 2)
  4949. return 0
  4950. ;;
  4951. 3)
  4952. return 1
  4953. ;;
  4954. *)
  4955. die "versionator compare bug [atleast, ${want_s}, ${have_s}, ${r}]"
  4956. ;;
  4957. esac
  4958. }
  4959. version_sort ()
  4960. {
  4961. eshopts_push -s extglob;
  4962. local items=;
  4963. local -i left=0;
  4964. items=("$@");
  4965. while ((left < ${#items[@]})); do
  4966. local -i lowest_idx=left;
  4967. local -i idx=lowest_idx+1;
  4968. while ((idx < ${#items[@]})); do
  4969. version_compare "${items[lowest_idx]}" "${items[idx]}";
  4970. [[ $? -eq 3 ]] && lowest_idx=idx;
  4971. idx+=1;
  4972. done;
  4973. local tmp=${items[lowest_idx]};
  4974. items[lowest_idx]=${items[left]};
  4975. items[left]=${tmp};
  4976. left+=1;
  4977. done;
  4978. echo ${items[@]};
  4979. eshopts_pop
  4980. }
  4981. want_minispecs ()
  4982. {
  4983. if tc_version_is_at_least 6.0; then
  4984. return 0;
  4985. fi;
  4986. if tc_version_is_at_least 4.3.2 && use_if_iuse hardened; then
  4987. if ! want_pie; then
  4988. ewarn "PIE_VER or SPECS_VER is not defined in the GCC ebuild.";
  4989. else
  4990. if use vanilla; then
  4991. ewarn "You will not get hardened features if you have the vanilla USE-flag.";
  4992. else
  4993. if use_if_iuse nopie && use_if_iuse nossp; then
  4994. ewarn "You will not get hardened features if you have the nopie and nossp USE-flag.";
  4995. else
  4996. if ! hardened_gcc_works; then
  4997. ewarn "Your $(tc-arch) arch is not supported.";
  4998. else
  4999. return 0;
  5000. fi;
  5001. fi;
  5002. fi;
  5003. fi;
  5004. ewarn "Hope you know what you are doing. Hardened will not work.";
  5005. return 0;
  5006. fi;
  5007. return 1
  5008. }
  5009. want_pie ()
  5010. {
  5011. ! use_if_iuse hardened && [[ -n ${PIE_VER} ]] && use_if_iuse nopie && return 1;
  5012. [[ -n ${PIE_VER} ]] && [[ -n ${SPECS_VER} ]] && return 0;
  5013. tc_version_is_at_least 4.3.2 && return 1;
  5014. [[ -z ${PIE_VER} ]] && return 1;
  5015. use_if_iuse nopie || return 0;
  5016. return 1
  5017. }
  5018.