Advertisement
Guest User

Untitled

a guest
Jun 28th, 2011
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 189.77 KB | None | 0 0
  1. declare -x ALSA_CARDS=""
  2. declare -x ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol"
  3. declare -x APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias"
  4. declare -x ARCH="x86"
  5. declare -- BINPATH="/usr/i486-pc-linux-gnu/gcc-bin/4.4.5"
  6. declare -- BRANCH_UPDATE=""
  7. declare -x BRANDING_GCC_PKGVERSION="Gentoo 4.4.5 p1.2, pie-0.4.5"
  8. declare -x CALLIGRA_FEATURES="braindump flow karbon kexi kpresenter krita tables words"
  9. declare -x CAMERAS="ptp2"
  10. declare -x CBUILD="i486-pc-linux-gnu"
  11. declare -x CFLAGS="-Os -march=i486"
  12. declare -x CFLAGS_default=""
  13. declare -x CHOST="i486-pc-linux-gnu"
  14. declare -x CHOST_default="i486-pc-linux-gnu"
  15. declare -x COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog"
  16. declare -x CROSSCOMPILE_OPTS=""
  17. declare -x CTARGET="i486-pc-linux-gnu"
  18. declare -x CTARGET_default="i486-pc-linux-gnu"
  19. declare -x CXXFLAGS="-Os -march=i486"
  20. declare -- DATAPATH="/usr/share/gcc-data/i486-pc-linux-gnu/4.4.5"
  21. declare -x DEBUGBUILD="1"
  22. declare -x DEFAULT_ABI="default"
  23. declare -x DEFINED_PHASES=" compile install postinst postrm preinst prerm setup test unpack"
  24. declare -- DEPEND=">=sys-libs/zlib-1.1.4
  25. >=sys-devel/gcc-config-1.4
  26. virtual/libiconv
  27. >=dev-libs/gmp-4.2.1
  28. >=dev-libs/mpfr-2.3.2
  29. graphite? (
  30. >=dev-libs/ppl-0.10
  31. >=dev-libs/cloog-ppl-0.15.4
  32. )
  33. !build? (
  34. gcj? (
  35. gtk? (
  36. x11-libs/libXt
  37. x11-libs/libX11
  38. x11-libs/libXtst
  39. x11-proto/xproto
  40. x11-proto/xextproto
  41. =x11-libs/gtk+-2*
  42. x11-libs/pango
  43. )
  44. >=media-libs/libart_lgpl-2.1
  45. app-arch/zip
  46. app-arch/unzip
  47. )
  48. >=sys-libs/ncurses-5.2-r2
  49. nls? ( sys-devel/gettext )
  50. )
  51. test? ( >=dev-util/dejagnu-1.4.4 >=sys-devel/autogen-5.5.4 )
  52. >=sys-apps/texinfo-4.8
  53. >=sys-devel/bison-1.875
  54. elibc_glibc? ( >=sys-libs/glibc-2.8 )
  55. amd64? ( multilib? ( gcj? ( app-emulation/emul-linux-x86-xlibs ) ) )
  56. ppc? ( >=sys-devel/binutils-2.17 )
  57. ppc64? ( >=sys-devel/binutils-2.17 )
  58. >=sys-devel/binutils-2.15.94 sys-devel/gnuconfig >=sys-apps/sed-4"
  59. declare -- DESCRIPTION="The GNU Compiler Collection"
  60. declare -x DESTTREE="/usr"
  61. declare -x DIROPTIONS="-m0755"
  62. declare -x EAPI="0"
  63. declare -x ELIBC="glibc"
  64. declare -x ELT_APPLIED_PATCHES=" 1.5.4 2.2 1.5.6 2.2.6"
  65. declare -- ELT_PATCH_DIR="/usr/portage/eclass/ELT-patches"
  66. declare -- EPATCH_EXCLUDE=""
  67. declare -- EPATCH_FORCE="no"
  68. declare -- EPATCH_MULTI_MSG="Applying various patches (bugfixes/updates) ..."
  69. declare -- EPATCH_OPTS="-g0 -E --no-backup-if-mismatch"
  70. declare -- EPATCH_SINGLE_MSG=""
  71. declare -- EPATCH_SOURCE="/var/tmp/portage/sys-devel/gcc-4.4.5/work/patch"
  72. declare -- EPATCH_SUFFIX="patch"
  73. declare -- ETYPE="gcc-compiler"
  74. declare -x EXEOPTIONS="-m0755"
  75. declare -x FCFLAGS=""
  76. declare -x FETCHCOMMAND_SSH="bash -c \"x=\\\${2#ssh://} ; host=\\\${x%%/*} ; port=\\\${host##*:} ; host=\\\${host%:*} ; [[ \\\${host} = \\\${port} ]] && port=22 ; exec rsync --rsh=\\\"ssh -p\\\${port}\\\" -avP \\\"\\\${host}:/\\\${x#*/}\\\" \\\"\\\$1\\\"\" rsync \"\${DISTDIR}/\${FILE}\" \"\${URI}\""
  77. declare -x FFLAGS=""
  78. declare -- GCCMAJOR="4"
  79. declare -- GCCMICRO="5"
  80. declare -- GCCMINOR="4"
  81. declare -- GCC_BRANCH_VER="4.4"
  82. declare -- GCC_CONFIG_VER="4.4.5"
  83. declare -x GCC_FILESDIR="/usr/portage/sys-devel/gcc/files"
  84. declare -- GCC_LIB_COMPAT_ONLY="false"
  85. declare -- GCC_PV="4.4.5"
  86. declare -- GCC_PVR="4.4.5"
  87. declare -- GCC_RELEASE_VER="4.4.5"
  88. declare -- GCC_VAR_TYPE="versioned"
  89. declare -x GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf superstar2 timing tsip tripmate tnt ubx"
  90. declare -- HOMEPAGE="http://gcc.gnu.org/"
  91. declare -x HTB_GCC_VER="4.4.5"
  92. declare -- INCLUDEPATH="/usr/lib/gcc/i486-pc-linux-gnu/4.4.5/include"
  93. declare -x INHERITED="toolchain portability flag-o-matic versionator multilib fixheadtails libtool gnuconfig toolchain-funcs eutils"
  94. declare -x INPUT_DEVICES="keyboard mouse evdev"
  95. declare -x INSDESTTREE=""
  96. declare -x INSOPTIONS="-m0644"
  97. declare -- IUSE=" multislot nptl test vanilla altivec build fortran nls nocxx nopie nossp bootstrap doc gcj gtk hardened libffi multilib objc objc-gc mudflap objc++ openmp fixed-point graphite nossp"
  98. declare -x KERNEL="linux"
  99. declare -x KERNEL_ABI="default"
  100. declare -x KEYWORDS="alpha amd64 arm hppa ia64 ~m68k ~mips ppc ppc64 s390 sh sparc x86 ~x86-fbsd"
  101. declare -x KV="2.6.36-gentoo-r8-ebox"
  102. declare -x LANG="es_ES@euro"
  103. declare -x LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text"
  104. declare -x LC_COLLATE="C"
  105. declare -x LDFLAGS="-Wl,-O1 -Wl,--as-needed"
  106. declare -x LDFLAGS_default=""
  107. declare -x LIBDIR_default="lib"
  108. declare -x LIBOPTIONS="-m0644"
  109. declare -- LIBPATH="/usr/lib/gcc/i486-pc-linux-gnu/4.4.5"
  110. declare -x LICENSE="GPL-3 LGPL-3 || ( GPL-3 libgcc libstdc++ gcc-runtime-library-exception-3.1 ) FDL-1.2"
  111. declare -x MAIL="/var/mail/root"
  112. declare -x MAKEOPTS="-j1"
  113. declare -x MULTILIB_ABIS="default"
  114. declare -x NETBEANS="apisupport cnd groovy gsf harness ide identity j2ee java mobility nb php profiler soa visualweb webcommon websvccommon xml"
  115. declare -x PATCH_GCC_VER="4.4.5"
  116. declare -- PATCH_VER="1.2"
  117. declare -x PATH="/usr/lib/portage/bin/ebuild-helpers:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:/usr/i486-pc-linux-gnu/gcc-bin/4.4.5"
  118. declare -- PDEPEND=">=sys-devel/gcc-config-1.4 elibc_glibc? ( >=sys-libs/glibc-2.8 ) "
  119. declare -x PHP_TARGETS=""
  120. declare -x PIE_GCC_VER="4.4.5"
  121. declare -- PIE_GLIBC_STABLE="x86 amd64 ppc ppc64 arm ia64"
  122. declare -- PIE_UCLIBC_STABLE="x86 arm amd64 ppc ppc64"
  123. declare -- PIE_VER="0.4.5"
  124. declare -x PORTAGE_COMPRESS_EXCLUDE_SUFFIXES="css gif htm[l]? jp[e]?g js pdf png"
  125. declare -a PORTAGE_DOCOMPRESS='([0]="/usr/share/doc" [1]="/usr/share/info" [2]="/usr/share/man")'
  126. declare -a PORTAGE_DOCOMPRESS_SKIP='([0]="/usr/share/doc/gcc-4.4.5/html")'
  127. declare -x PP_GCC_VER="4.4.5"
  128. declare -- PREFIX="/usr"
  129. declare -x PROFILE_ONLY_VARIABLES="ARCH ELIBC KERNEL USERLAND"
  130. declare -x PROPERTIES=""
  131. declare -x PROVIDE=""
  132. declare -x PYTHONDONTWRITEBYTECODE="1"
  133. declare -x RDEPEND=">=sys-libs/zlib-1.1.4
  134. >=sys-devel/gcc-config-1.4
  135. virtual/libiconv
  136. >=dev-libs/gmp-4.2.1
  137. >=dev-libs/mpfr-2.3.2
  138. graphite? (
  139. >=dev-libs/ppl-0.10
  140. >=dev-libs/cloog-ppl-0.15.4
  141. )
  142. !build? (
  143. gcj? (
  144. gtk? (
  145. x11-libs/libXt
  146. x11-libs/libX11
  147. x11-libs/libXtst
  148. x11-proto/xproto
  149. x11-proto/xextproto
  150. =x11-libs/gtk+-2*
  151. x11-libs/pango
  152. )
  153. >=media-libs/libart_lgpl-2.1
  154. app-arch/zip
  155. app-arch/unzip
  156. )
  157. >=sys-libs/ncurses-5.2-r2
  158. nls? ( sys-devel/gettext )
  159. ) "
  160. declare -- REQUIRED_USE=" "
  161. declare -x RESTRICT="strip"
  162. declare -x RESUMECOMMAND_SSH="bash -c \"x=\\\${2#ssh://} ; host=\\\${x%%/*} ; port=\\\${host##*:} ; host=\\\${host%:*} ; [[ \\\${host} = \\\${port} ]] && port=22 ; exec rsync --rsh=\\\"ssh -p\\\${port}\\\" -avP \\\"\\\${host}:/\\\${x#*/}\\\" \\\"\\\$1\\\"\" rsync \"\${DISTDIR}/\${FILE}\" \"\${URI}\""
  163. declare -x RUBY_TARGETS=""
  164. declare -x S="/var/tmp/portage/sys-devel/gcc-4.4.5/work/gcc-4.4.5"
  165. declare -x SANDBOX_DEBUG="0"
  166. declare -x SANDBOX_DENY=""
  167. declare -x SANDBOX_PID="2620"
  168. declare -x SANDBOX_PREDICT="/var/tmp/portage/sys-devel/gcc-4.4.5/homedir:/dev/crypto"
  169. declare -x SANDBOX_READ="/:/dev/stdin:/var/tmp"
  170. declare -x SANDBOX_VERBOSE="1"
  171. declare -x SANDBOX_WRITE=":/dev/console:/dev/fd:/dev/full:/dev/null:/dev/pts/:/dev/pty:/dev/shm:/dev/stderr:/dev/stdout:/dev/tts:/dev/tty:/dev/vc/:/dev/zero:/proc/self/fd:/tmp/:/usr/lib/cf:/usr/lib/conftest:/usr/lib32/cf:/usr/lib32/conftest:/usr/lib64/cf:/usr/lib64/conftest:/usr/tmp/cf:/usr/tmp/conftest:/var/tmp:/var/tmp/:/var/tmp/portage/sys-devel/gcc-4.4.5/homedir/.bash_history"
  172. declare -x SLOT="4.4"
  173. declare -x SPECS_GCC_VER="4.4.3"
  174. declare -- SPECS_VER="0.2.0"
  175. declare -- SRC_URI="mirror://gnu/gcc/gcc-4.4.5/gcc-4.4.5.tar.bz2 mirror://gentoo/gcc-4.4.5-uclibc-patches-1.0.tar.bz2 http://dev.gentoo.org/~lv/GCC/gcc-4.4.5-uclibc-patches-1.0.tar.bz2 http://dev.gentoo.org/~eradicator/gcc/gcc-4.4.5-uclibc-patches-1.0.tar.bz2 http://dev.gentoo.org/~vapier/dist/gcc-4.4.5-uclibc-patches-1.0.tar.bz2 http://dev.gentoo.org/~halcy0n/patches/gcc-4.4.5-uclibc-patches-1.0.tar.bz2 http://dev.gentoo.org/~zorry/patches/gcc/gcc-4.4.5-uclibc-patches-1.0.tar.bz2 http://dev.gentoo.org/~dirtyepic/dist/gcc-4.4.5-uclibc-patches-1.0.tar.bz2 mirror://gentoo/gcc-4.4.5-patches-1.2.tar.bz2 http://dev.gentoo.org/~lv/GCC/gcc-4.4.5-patches-1.2.tar.bz2 http://dev.gentoo.org/~eradicator/gcc/gcc-4.4.5-patches-1.2.tar.bz2 http://dev.gentoo.org/~vapier/dist/gcc-4.4.5-patches-1.2.tar.bz2 http://dev.gentoo.org/~halcy0n/patches/gcc-4.4.5-patches-1.2.tar.bz2 http://dev.gentoo.org/~zorry/patches/gcc/gcc-4.4.5-patches-1.2.tar.bz2 http://dev.gentoo.org/~dirtyepic/dist/gcc-4.4.5-patches-1.2.tar.bz2 mirror://gentoo/gcc-4.4.5-piepatches-v0.4.5.tar.bz2 http://dev.gentoo.org/~lv/GCC/gcc-4.4.5-piepatches-v0.4.5.tar.bz2 http://dev.gentoo.org/~eradicator/gcc/gcc-4.4.5-piepatches-v0.4.5.tar.bz2 http://dev.gentoo.org/~vapier/dist/gcc-4.4.5-piepatches-v0.4.5.tar.bz2 http://dev.gentoo.org/~halcy0n/patches/gcc-4.4.5-piepatches-v0.4.5.tar.bz2 http://dev.gentoo.org/~zorry/patches/gcc/gcc-4.4.5-piepatches-v0.4.5.tar.bz2 http://dev.gentoo.org/~dirtyepic/dist/gcc-4.4.5-piepatches-v0.4.5.tar.bz2 mirror://gentoo/gcc-4.4.3-specs-0.2.0.tar.bz2 http://dev.gentoo.org/~lv/GCC/gcc-4.4.3-specs-0.2.0.tar.bz2 http://dev.gentoo.org/~eradicator/gcc/gcc-4.4.3-specs-0.2.0.tar.bz2 http://dev.gentoo.org/~vapier/dist/gcc-4.4.3-specs-0.2.0.tar.bz2 http://dev.gentoo.org/~halcy0n/patches/gcc-4.4.3-specs-0.2.0.tar.bz2 http://dev.gentoo.org/~zorry/patches/gcc/gcc-4.4.3-specs-0.2.0.tar.bz2 http://dev.gentoo.org/~dirtyepic/dist/gcc-4.4.3-specs-0.2.0.tar.bz2
  176. gcj? ( ftp://sourceware.org/pub/java/ecj-4.3.jar )"
  177. declare -x SSH_CLIENT="10.0.1.11 1903 22"
  178. declare -x SSH_CONNECTION="10.0.1.11 1903 10.0.1.29 22"
  179. declare -x SSH_TTY="/dev/pts/0"
  180. declare -- SSP_STABLE="amd64 x86 ppc ppc64 arm"
  181. declare -- SSP_UCLIBC_STABLE=""
  182. declare -- STDCXX_INCDIR="/usr/lib/gcc/i486-pc-linux-gnu/4.4.5/include/g++-v4"
  183. declare -x UCLIBC_GCC_VER="4.4.5"
  184. declare -- UCLIBC_VER="1.0"
  185. declare -x USE="elibc_glibc fortran kernel_linux mudflap nls nptl openmp userland_GNU x86"
  186. declare -x USERLAND="GNU"
  187. declare -x VIDEO_CARDS=""
  188. declare -x XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
  189. declare -- _="PKG_INSTALL_MASK"
  190. declare -x _E_DOCDESTTREE_=""
  191. declare -x _E_EXEDESTTREE_=""
  192. declare -a __ESHOPTS_SAVE__='()'
  193. declare -- ___ECLASS_RECUR_MULTILIB="yes"
  194. declare -- ___ECLASS_RECUR_TOOLCHAIN_FUNCS="yes"
  195. declare -- gcc_common_hard="-DEFAULT_RELRO -DEFAULT_BIND_NOW"
  196. ELT_libtool_version ()
  197. {
  198. ( unset VERSION;
  199. eval $(grep -e '^[[:space:]]*VERSION=' "$1");
  200. echo "${VERSION:-0}" )
  201. }
  202. ELT_try_and_apply_patch ()
  203. {
  204. local ret=0;
  205. local file=$1;
  206. local patch=$2;
  207. echo -e "\nTrying $(basename "$(dirname "${patch}")")-${patch##*/}.patch on ${file}" >> "${T}/elibtool.log" 2>&1;
  208. if patch -p0 --dry-run "${file}" "${patch}" >> "${T}/elibtool.log" 2>&1; then
  209. einfo " Applying $(basename "$(dirname "${patch}")")-${patch##*/}.patch ...";
  210. patch -p0 -g0 --no-backup-if-mismatch "${file}" "${patch}" >> "${T}/elibtool.log" 2>&1;
  211. ret=$?;
  212. export ELT_APPLIED_PATCHES="${ELT_APPLIED_PATCHES} ${patch##*/}";
  213. else
  214. ret=1;
  215. fi;
  216. return "${ret}"
  217. }
  218. ELT_walk_patches ()
  219. {
  220. local patch;
  221. local ret=1;
  222. local file=$1;
  223. local patch_set=$2;
  224. local patch_dir="${ELT_PATCH_DIR}/${patch_set}";
  225. local rem_int_dep=$3;
  226. [[ -z ${patch_set} ]] && return 1;
  227. [[ ! -d ${patch_dir} ]] && return 1;
  228. pushd "${ELT_PATCH_DIR}" > /dev/null;
  229. for patch in $(find "${patch_set}" -maxdepth 1 -type f | LC_ALL=C sort -r);
  230. do
  231. if [[ -n ${rem_int_dep} ]]; then
  232. local tmp="${T}/$$.rem_int_deps.patch";
  233. sed -e "s|@REM_INT_DEP@|${rem_int_dep}|g" "${patch}" > "${tmp}";
  234. patch=${tmp};
  235. fi;
  236. if ELT_try_and_apply_patch "${file}" "${patch}"; then
  237. ret=0;
  238. break;
  239. fi;
  240. done;
  241. popd > /dev/null;
  242. return ${ret}
  243. }
  244. VER_major ()
  245. {
  246. [[ -z $1 ]] && return 1;
  247. local VER=$@;
  248. echo "${VER%%[^[:digit:]]*}"
  249. }
  250. VER_micro ()
  251. {
  252. [[ -z $1 ]] && return 1;
  253. local VER=$@;
  254. VER=${VER#*.*.};
  255. echo "${VER%%[^[:digit:]]*}"
  256. }
  257. VER_minor ()
  258. {
  259. [[ -z $1 ]] && return 1;
  260. local VER=$@;
  261. VER=${VER#*.};
  262. echo "${VER%%[^[:digit:]]*}"
  263. }
  264. VER_to_int ()
  265. {
  266. [[ -z $1 ]] && return 1;
  267. local VER_MAJOR=$(VER_major "$1");
  268. local VER_MINOR=$(VER_minor "$1");
  269. local VER_MICRO=$(VER_micro "$1");
  270. local VER_int=$(( VER_MAJOR * 65536 + VER_MINOR * 256 + VER_MICRO ));
  271. if [[ ${VER_int} -ge 65536 ]]; then
  272. echo "${VER_int}";
  273. return 0;
  274. fi;
  275. echo 1;
  276. return 1
  277. }
  278. XGCC ()
  279. {
  280. get_make_var GCC_FOR_TARGET
  281. }
  282. __do_sed_fix ()
  283. {
  284. einfo " - fixed $1";
  285. 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"
  286. }
  287. __versionator__test_version_compare ()
  288. {
  289. eshopts_push -s extglob;
  290. local lt=1 eq=2 gt=3 p q;
  291. function __versionator__test_version_compare_t ()
  292. {
  293. version_compare "${1}" "${3}";
  294. local r=$?;
  295. [[ ${r} -eq ${2} ]] || echo "FAIL: ${@} (got ${r} exp ${2})"
  296. };
  297. echo "
  298. 0 $lt 1
  299. 1 $lt 2
  300. 2 $gt 1
  301. 2 $eq 2
  302. 0 $eq 0
  303. 10 $lt 20
  304. 68 $eq 068
  305. 068 $gt 67
  306. 068 $lt 69
  307.  
  308. 1.0 $lt 2.0
  309. 2.0 $eq 2.0
  310. 2.0 $gt 1.0
  311.  
  312. 1.0 $gt 0.0
  313. 0.0 $eq 0.0
  314. 0.0 $lt 1.0
  315.  
  316. 0.1 $lt 0.2
  317. 0.2 $eq 0.2
  318. 0.3 $gt 0.2
  319.  
  320. 1.2 $lt 2.1
  321. 2.1 $gt 1.2
  322.  
  323. 1.2.3 $lt 1.2.4
  324. 1.2.4 $gt 1.2.3
  325.  
  326. 1.2.0 $eq 1.2
  327. 1.2.1 $gt 1.2
  328. 1.2 $lt 1.2.1
  329.  
  330. 1.2b $eq 1.2b
  331. 1.2b $lt 1.2c
  332. 1.2b $gt 1.2a
  333. 1.2b $gt 1.2
  334. 1.2 $lt 1.2a
  335.  
  336. 1.3 $gt 1.2a
  337. 1.3 $lt 1.3a
  338.  
  339. 1.0_alpha7 $lt 1.0_beta7
  340. 1.0_beta $lt 1.0_pre
  341. 1.0_pre5 $lt 1.0_rc2
  342. 1.0_rc2 $lt 1.0
  343.  
  344. 1.0_p1 $gt 1.0
  345. 1.0_p1-r1 $gt 1.0_p1
  346.  
  347. 1.0_alpha6-r1 $gt 1.0_alpha6
  348. 1.0_beta6-r1 $gt 1.0_alpha6-r2
  349.  
  350. 1.0_pre1 $lt 1.0-p1
  351.  
  352. 1.0p $gt 1.0_p1
  353. 1.0r $gt 1.0-r1
  354. 1.6.15 $gt 1.6.10-r2
  355. 1.6.10-r2 $lt 1.6.15
  356.  
  357. " | while read a b c; do
  358. [[ -z "${a}${b}${c}" ]] && continue;
  359. __versionator__test_version_compare_t "${a}" "${b}" "${c}";
  360. done;
  361. for q in "alpha beta pre rc=${lt};${gt}" "p r=${gt};${lt}";
  362. do
  363. for p in ${q%%=*};
  364. do
  365. local c=${q##*=};
  366. local alt=${c%%;*} agt=${c##*;};
  367. __versionator__test_version_compare_t "1.0" $agt "1.0_${p}";
  368. __versionator__test_version_compare_t "1.0" $agt "1.0_${p}1";
  369. __versionator__test_version_compare_t "1.0" $agt "1.0_${p}068";
  370. __versionator__test_version_compare_t "2.0_${p}" $alt "2.0";
  371. __versionator__test_version_compare_t "2.0_${p}1" $alt "2.0";
  372. __versionator__test_version_compare_t "2.0_${p}068" $alt "2.0";
  373. __versionator__test_version_compare_t "1.0_${p}" $eq "1.0_${p}";
  374. __versionator__test_version_compare_t "0.0_${p}" $lt "0.0_${p}1";
  375. __versionator__test_version_compare_t "666_${p}3" $gt "666_${p}";
  376. __versionator__test_version_compare_t "1_${p}7" $lt "1_${p}8";
  377. __versionator__test_version_compare_t "1_${p}7" $eq "1_${p}7";
  378. __versionator__test_version_compare_t "1_${p}7" $gt "1_${p}6";
  379. __versionator__test_version_compare_t "1_${p}09" $eq "1_${p}9";
  380. done;
  381. done;
  382. for p in "-r" "_p";
  383. do
  384. __versionator__test_version_compare_t "7.2${p}1" $lt "7.2${p}2";
  385. __versionator__test_version_compare_t "7.2${p}2" $gt "7.2${p}1";
  386. __versionator__test_version_compare_t "7.2${p}3" $gt "7.2${p}2";
  387. __versionator__test_version_compare_t "7.2${p}2" $lt "7.2${p}3";
  388. done;
  389. eshopts_pop
  390. }
  391. _cdrom_locate_file_on_cd ()
  392. {
  393. local mline="";
  394. local showedmsg=0 showjolietmsg=0;
  395. while [[ -z ${CDROM_ROOT} ]]; do
  396. local i=0;
  397. local -a cdset=(${*//:/ });
  398. if [[ -n ${CDROM_SET} ]]; then
  399. cdset=(${cdset[${CDROM_SET}]});
  400. fi;
  401. while [[ -n ${cdset[${i}]} ]]; do
  402. local dir=$(dirname ${cdset[${i}]});
  403. local file=$(basename ${cdset[${i}]});
  404. local point= node= fs= foo=;
  405. while read point node fs foo; do
  406. [[ " cd9660 iso9660 udf " != *" ${fs} "* ]] && ! [[ ${fs} == "subfs" && ",${opts}," == *",fs=cdfss,"* ]] && continue;
  407. point=${point//\040/ };
  408. [[ ! -d ${point}/${dir} ]] && continue;
  409. [[ -z $(find "${point}/${dir}" -maxdepth 1 -iname "${file}") ]] && continue;
  410. export CDROM_ROOT=${point};
  411. export CDROM_SET=${i};
  412. export CDROM_MATCH=${cdset[${i}]};
  413. return;
  414. done <<< "$(get_mounts)";
  415. ((++i));
  416. done;
  417. echo;
  418. if [[ ${showedmsg} -eq 0 ]]; then
  419. if [[ ${CDROM_TOTAL_CDS} -eq 1 ]]; then
  420. if [[ -z ${CDROM_NAME} ]]; then
  421. einfo "Please insert+mount the cdrom for ${PN} now !";
  422. else
  423. einfo "Please insert+mount the ${CDROM_NAME} cdrom now !";
  424. fi;
  425. else
  426. if [[ -z ${CDROM_NAME_1} ]]; then
  427. einfo "Please insert+mount cd #${CDROM_CURRENT_CD} for ${PN} now !";
  428. else
  429. local var="CDROM_NAME_${CDROM_CURRENT_CD}";
  430. einfo "Please insert+mount the ${!var} cdrom now !";
  431. fi;
  432. fi;
  433. showedmsg=1;
  434. fi;
  435. einfo "Press return to scan for the cd again";
  436. einfo "or hit CTRL+C to abort the emerge.";
  437. echo;
  438. if [[ ${showjolietmsg} -eq 0 ]]; then
  439. showjolietmsg=1;
  440. else
  441. ewarn "If you are having trouble with the detection";
  442. ewarn "of your CD, it is possible that you do not have";
  443. ewarn "Joliet support enabled in your kernel. Please";
  444. ewarn "check that CONFIG_JOLIET is enabled in your kernel.";
  445. ebeep 5;
  446. fi;
  447. read || die "something is screwed with your system";
  448. done
  449. }
  450. _create_specs_file ()
  451. {
  452. local uflag=$1 name=$2 flags=${*:3};
  453. ebegin "Creating a ${name} gcc specs file";
  454. pushd "${WORKDIR}"/build/gcc > /dev/null;
  455. if [[ -z ${uflag} ]] || use ${uflag}; then
  456. cp Makefile Makefile.orig;
  457. sed -i -e '/^HARD_CFLAGS/s:=.*:='"${flags}"':' Makefile;
  458. mv xgcc xgcc.foo;
  459. mv gcc.o gcc.o.foo;
  460. emake -s xgcc;
  461. $(XGCC) -dumpspecs > "${WORKDIR}"/build/${name}.specs;
  462. mv gcc.o.foo gcc.o;
  463. mv xgcc.foo xgcc;
  464. mv Makefile.orig Makefile;
  465. else
  466. $(XGCC) -dumpspecs > "${WORKDIR}"/build/${name}.specs;
  467. fi;
  468. popd > /dev/null;
  469. eend $([[ -s ${WORKDIR}/build/${name}.specs ]] ; echo $?)
  470. }
  471. _epatch_draw_line ()
  472. {
  473. [[ -z $1 ]] && set "$(printf "%65s" '')";
  474. echo "${1//?/=}"
  475. }
  476. _filter-hardened ()
  477. {
  478. local f;
  479. for f in "$@";
  480. do
  481. case "${f}" in
  482. -fPIC | -fpic | -fPIE | -fpie | -Wl,pie | -pie)
  483. gcc-specs-pie || continue;
  484. is-flagq -nopie || append-flags -nopie
  485. ;;
  486. -fstack-protector)
  487. gcc-specs-ssp || continue;
  488. is-flagq -fno-stack-protector || append-flags $(test-flags -fno-stack-protector)
  489. ;;
  490. -fstack-protector-all)
  491. gcc-specs-ssp-to-all || continue;
  492. is-flagq -fno-stack-protector-all || append-flags $(test-flags -fno-stack-protector-all)
  493. ;;
  494. -fno-strict-overflow)
  495. gcc-specs-nostrict || continue;
  496. is-flagq -fstrict-overflow || append-flags $(test-flags -fstrict-overflow)
  497. ;;
  498. esac;
  499. done
  500. }
  501. _filter-var ()
  502. {
  503. local f x VAR VAL;
  504. declare -a new;
  505. VAR=$1;
  506. shift;
  507. eval VAL=\${${VAR}};
  508. for f in ${VAL};
  509. do
  510. for x in "$@";
  511. do
  512. [[ ${f} == ${x} ]] && continue 2;
  513. done;
  514. eval new\[\${\#new\[@]}]=\${f};
  515. done;
  516. eval export ${VAR}=\${new\[*]}
  517. }
  518. _gcc-install-dir ()
  519. {
  520. echo "$(LC_ALL=C $(tc-getCC) -print-search-dirs 2> /dev/null | awk '$1=="install:" {print $2}')"
  521. }
  522. _gcc-specs-directive_raw ()
  523. {
  524. local cc=$(tc-getCC);
  525. local specfiles=$(LC_ALL=C ${cc} -v 2>&1 | awk '$1=="Reading" {print $NF}');
  526. ${cc} -dumpspecs 2> /dev/null | cat - ${specfiles} | awk -v directive=$1 'BEGIN { pspec=""; spec=""; outside=1 }
  527. $1=="*"directive":" { pspec=spec; spec=""; outside=0; next }
  528. outside || NF==0 || ( substr($1,1,1)=="*" && substr($1,length($1),1)==":" ) { outside=1; next }
  529. spec=="" && substr($0,1,1)=="+" { spec=pspec " " substr($0,2); next }
  530. { spec=spec $0 }
  531. END { print spec }';
  532. return 0
  533. }
  534. _gcc-specs-exists ()
  535. {
  536. [[ -f $(_gcc-install-dir)/$1 ]]
  537. }
  538. _gcc_fullversion ()
  539. {
  540. local ver="$1";
  541. shift;
  542. set -- `$(tc-getCPP "$@") -E -P - <<<"__GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__"`;
  543. eval echo "$ver"
  544. }
  545. _is_flagq ()
  546. {
  547. local x;
  548. for x in ${!1};
  549. do
  550. [[ ${x} == $2 ]] && return 0;
  551. done;
  552. return 1
  553. }
  554. _unpack_tar ()
  555. {
  556. if [ "${y}" == "tar" ]; then
  557. $1 -c -- "$srcdir$x" | tar xof -;
  558. assert_sigpipe_ok "$myfail";
  559. else
  560. $1 -c -- "${srcdir}${x}" > ${x%.*} || die "$myfail";
  561. fi
  562. }
  563. _want_stuff ()
  564. {
  565. local var=$1 flag=$2;
  566. [[ -z ${!var} ]] && return 1;
  567. use ${flag} && return 0;
  568. return 1
  569. }
  570. add_version_to_shared ()
  571. {
  572. local sharedlib sharedlibdir;
  573. [[ -z $1 ]] && sharedlibdir=${D} || sharedlibdir=$1;
  574. for sharedlib in $(find ${sharedlibdir} -name *.so.*);
  575. do
  576. if [[ ! -L ${sharedlib} ]]; then
  577. einfo "Renaming `basename "${sharedlib}"` to `basename "${sharedlib/.so*/}-${GCC_CONFIG_VER}.so.${sharedlib/*.so./}"`";
  578. mv "${sharedlib}" "${sharedlib/.so*/}-${GCC_CONFIG_VER}.so.${sharedlib/*.so./}" || die;
  579. pushd `dirname "${sharedlib}"` > /dev/null || die;
  580. ln -sf "`basename "${sharedlib/.so*/}-${GCC_CONFIG_VER}.so.${sharedlib/*.so./}"`" "`basename "${sharedlib}"`" || die;
  581. popd > /dev/null || die;
  582. fi;
  583. done
  584. }
  585. append-cflags ()
  586. {
  587. [[ -z $* ]] && return 0;
  588. export CFLAGS="${CFLAGS} $*";
  589. return 0
  590. }
  591. append-cppflags ()
  592. {
  593. [[ -z $* ]] && return 0;
  594. export CPPFLAGS="${CPPFLAGS} $*";
  595. return 0
  596. }
  597. append-cxxflags ()
  598. {
  599. [[ -z $* ]] && return 0;
  600. export CXXFLAGS="${CXXFLAGS} $*";
  601. return 0
  602. }
  603. append-fflags ()
  604. {
  605. [[ -z $* ]] && return 0;
  606. export FFLAGS="${FFLAGS} $*";
  607. export FCFLAGS="${FCFLAGS} $*";
  608. return 0
  609. }
  610. append-flags ()
  611. {
  612. [[ -z $* ]] && return 0;
  613. append-cflags "$@";
  614. append-cxxflags "$@";
  615. append-fflags "$@";
  616. return 0
  617. }
  618. append-ldflags ()
  619. {
  620. [[ -z $* ]] && return 0;
  621. local flag;
  622. for flag in "$@";
  623. do
  624. [[ ${flag} == -l* ]] && ewarn "Appending a library link instruction (${flag}); libraries to link to should not be passed through LDFLAGS";
  625. done;
  626. export LDFLAGS="${LDFLAGS} $*";
  627. return 0
  628. }
  629. append-lfs-flags ()
  630. {
  631. [[ -n $@ ]] && die "append-lfs-flags takes no arguments";
  632. append-cppflags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
  633. }
  634. append-libs ()
  635. {
  636. [[ -z $* ]] && return 0;
  637. local flag;
  638. for flag in "$@";
  639. do
  640. [[ ${flag} == -l* ]] && flag=${flag#-l};
  641. export LIBS="${LIBS} -l${flag}";
  642. done;
  643. return 0
  644. }
  645. built_with_use ()
  646. {
  647. local hidden="no";
  648. if [[ $1 == "--hidden" ]]; then
  649. hidden="yes";
  650. shift;
  651. fi;
  652. local missing_action="die";
  653. if [[ $1 == "--missing" ]]; then
  654. missing_action=$2;
  655. shift;
  656. shift;
  657. case ${missing_action} in
  658. true | false | die)
  659.  
  660. ;;
  661. *)
  662. die "unknown action '${missing_action}'"
  663. ;;
  664. esac;
  665. fi;
  666. local opt=$1;
  667. [[ ${opt:0:1} = "-" ]] && shift || opt="-a";
  668. local PKG=$(best_version $1);
  669. [[ -z ${PKG} ]] && die "Unable to resolve $1 to an installed package";
  670. shift;
  671. local USEFILE=${ROOT}/var/db/pkg/${PKG}/USE;
  672. local IUSEFILE=${ROOT}/var/db/pkg/${PKG}/IUSE;
  673. if [[ ! -e ${USEFILE} ]] || [[ ! -e ${IUSEFILE} && ${hidden} == "no" ]]; then
  674. case ${missing_action} in
  675. true)
  676. return 0
  677. ;;
  678. false)
  679. return 1
  680. ;;
  681. die)
  682. die "Unable to determine what USE flags $PKG was built with"
  683. ;;
  684. esac;
  685. fi;
  686. if [[ ${hidden} == "no" ]]; then
  687. local IUSE_BUILT=($(<"${IUSEFILE}"));
  688. local expand;
  689. for expand in $(echo ${USE_EXPAND} | tr '[:upper:]' '[:lower:]');
  690. do
  691. if [[ $1 == ${expand}_* ]]; then
  692. expand="";
  693. break;
  694. fi;
  695. done;
  696. if [[ -n ${expand} ]]; then
  697. if ! has $1 ${IUSE_BUILT[@]#[-+]}; then
  698. case ${missing_action} in
  699. true)
  700. return 0
  701. ;;
  702. false)
  703. return 1
  704. ;;
  705. die)
  706. die "$PKG does not actually support the $1 USE flag!"
  707. ;;
  708. esac;
  709. fi;
  710. fi;
  711. fi;
  712. local USE_BUILT=$(<${USEFILE});
  713. while [[ $# -gt 0 ]]; do
  714. if [[ ${opt} = "-o" ]]; then
  715. has $1 ${USE_BUILT} && return 0;
  716. else
  717. has $1 ${USE_BUILT} || return 1;
  718. fi;
  719. shift;
  720. done;
  721. [[ ${opt} = "-a" ]]
  722. }
  723. cdrom_get_cds ()
  724. {
  725. local cdcnt=0;
  726. local f=;
  727. for f in "$@";
  728. do
  729. ((++cdcnt));
  730. export CDROM_CHECK_${cdcnt}="$f";
  731. done;
  732. export CDROM_TOTAL_CDS=${cdcnt};
  733. export CDROM_CURRENT_CD=1;
  734. if [[ -n ${CD_ROOT}${CD_ROOT_1} ]]; then
  735. local var=;
  736. cdcnt=0;
  737. while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]]; do
  738. ((++cdcnt));
  739. var="CD_ROOT_${cdcnt}";
  740. [[ -z ${!var} ]] && var="CD_ROOT";
  741. if [[ -z ${!var} ]]; then
  742. eerror "You must either use just the CD_ROOT";
  743. eerror "or specify ALL the CD_ROOT_X variables.";
  744. eerror "In this case, you will need ${CDROM_TOTAL_CDS} CD_ROOT_X variables.";
  745. die "could not locate CD_ROOT_${cdcnt}";
  746. fi;
  747. done;
  748. export CDROM_ROOT=${CD_ROOT_1:-${CD_ROOT}};
  749. einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}";
  750. export CDROM_SET=-1;
  751. for f in ${CDROM_CHECK_1//:/ };
  752. do
  753. ((++CDROM_SET));
  754. [[ -e ${CDROM_ROOT}/${f} ]] && break;
  755. done;
  756. export CDROM_MATCH=${f};
  757. return;
  758. fi;
  759. if [[ ${CDROM_TOTAL_CDS} -eq 1 ]]; then
  760. einfo "This ebuild will need the ${CDROM_NAME:-cdrom for ${PN}}";
  761. echo;
  762. einfo "If you do not have the CD, but have the data files";
  763. einfo "mounted somewhere on your filesystem, just export";
  764. einfo "the variable CD_ROOT so that it points to the";
  765. einfo "directory containing the files.";
  766. echo;
  767. einfo "For example:";
  768. einfo "export CD_ROOT=/mnt/cdrom";
  769. echo;
  770. else
  771. if [[ -n ${CDROM_NAME_SET} ]]; then
  772. cdcnt=0;
  773. while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]]; do
  774. ((++cdcnt));
  775. export CDROM_NAME_${cdcnt}="${CDROM_NAME_SET[$((${cdcnt}-1))]}";
  776. done;
  777. fi;
  778. einfo "This package will need access to ${CDROM_TOTAL_CDS} cds.";
  779. cdcnt=0;
  780. while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]]; do
  781. ((++cdcnt));
  782. var="CDROM_NAME_${cdcnt}";
  783. [[ ! -z ${!var} ]] && einfo " CD ${cdcnt}: ${!var}";
  784. done;
  785. echo;
  786. einfo "If you do not have the CDs, but have the data files";
  787. einfo "mounted somewhere on your filesystem, just export";
  788. einfo "the following variables so they point to the right place:";
  789. einfon "";
  790. cdcnt=0;
  791. while [[ ${cdcnt} -lt ${CDROM_TOTAL_CDS} ]]; do
  792. ((++cdcnt));
  793. echo -n " CD_ROOT_${cdcnt}";
  794. done;
  795. echo;
  796. einfo "Or, if you have all the files in the same place, or";
  797. einfo "you only have one cdrom, you can export CD_ROOT";
  798. einfo "and that place will be used as the same data source";
  799. einfo "for all the CDs.";
  800. echo;
  801. einfo "For example:";
  802. einfo "export CD_ROOT_1=/mnt/cdrom";
  803. echo;
  804. fi;
  805. export CDROM_SET="";
  806. export CDROM_CURRENT_CD=0;
  807. cdrom_load_next_cd
  808. }
  809. cdrom_load_next_cd ()
  810. {
  811. local var;
  812. ((++CDROM_CURRENT_CD));
  813. unset CDROM_ROOT;
  814. var=CD_ROOT_${CDROM_CURRENT_CD};
  815. [[ -z ${!var} ]] && var="CD_ROOT";
  816. if [[ -z ${!var} ]]; then
  817. var="CDROM_CHECK_${CDROM_CURRENT_CD}";
  818. _cdrom_locate_file_on_cd ${!var};
  819. else
  820. export CDROM_ROOT=${!var};
  821. fi;
  822. einfo "Found CD #${CDROM_CURRENT_CD} root at ${CDROM_ROOT}"
  823. }
  824. check_license ()
  825. {
  826. local lic=$1;
  827. if [ -z "${lic}" ]; then
  828. lic="${PORTDIR}/licenses/${LICENSE}";
  829. else
  830. if [ -e "${PORTDIR}/licenses/${lic}" ]; then
  831. lic="${PORTDIR}/licenses/${lic}";
  832. else
  833. if [ -e "${PWD}/${lic}" ]; then
  834. lic="${PWD}/${lic}";
  835. else
  836. if [ -e "${lic}" ]; then
  837. lic="${lic}";
  838. fi;
  839. fi;
  840. fi;
  841. fi;
  842. local l="`basename ${lic}`";
  843. local alic;
  844. eshopts_push -o noglob;
  845. for alic in ${ACCEPT_LICENSE};
  846. do
  847. if [[ ${alic} == ${l} ]]; then
  848. eshopts_pop;
  849. return 0;
  850. fi;
  851. done;
  852. eshopts_pop;
  853. [ ! -f "${lic}" ] && die "Could not find requested license ${lic}";
  854. local licmsg=$(emktemp);
  855. cat > ${licmsg} <<-EOF
  856. **********************************************************
  857. The following license outlines the terms of use of this
  858. package. You MUST accept this license for installation to
  859. continue. When you are done viewing, hit 'q'. If you
  860. CTRL+C out of this, the install will not run!
  861. **********************************************************
  862.  
  863. EOF
  864.  
  865. cat ${lic} >> ${licmsg};
  866. ${PAGER:-less} ${licmsg} || die "Could not execute pager (${PAGER}) to accept ${lic}";
  867. einfon "Do you accept the terms of this license (${l})? [yes/no] ";
  868. read alic;
  869. case ${alic} in
  870. yes | Yes | y | Y)
  871. return 0
  872. ;;
  873. *)
  874. echo;
  875. echo;
  876. echo;
  877. eerror "You MUST accept the license to continue! Exiting!";
  878. die "Failed to accept license"
  879. ;;
  880. esac
  881. }
  882. copy_minispecs_gcc_specs ()
  883. {
  884. if hardened_gcc_works; then
  885. create_gcc_env_entry hardenednopiessp;
  886. fi;
  887. if hardened_gcc_works pie; then
  888. create_gcc_env_entry hardenednopie;
  889. fi;
  890. if hardened_gcc_works ssp; then
  891. create_gcc_env_entry hardenednossp;
  892. fi;
  893. create_gcc_env_entry vanilla;
  894. insinto ${LIBPATH};
  895. doins "${WORKDIR}"/specs/*.specs || die "failed to install specs";
  896. if ! tc_version_is_at_least 4.4; then
  897. $(XGCC) -dumpspecs > "${WORKDIR}"/specs/specs;
  898. cat "${WORKDIR}"/build.specs >> "${WORKDIR}"/specs/specs;
  899. doins "${WORKDIR}"/specs/specs || die "failed to install the specs file";
  900. fi
  901. }
  902. create_gcc_env_entry ()
  903. {
  904. dodir /etc/env.d/gcc;
  905. local gcc_envd_base="/etc/env.d/gcc/${CTARGET}-${GCC_CONFIG_VER}";
  906. if [[ -z $1 ]]; then
  907. gcc_envd_file="${D}${gcc_envd_base}";
  908. gcc_specs_file="";
  909. else
  910. gcc_envd_file="${D}${gcc_envd_base}-$1";
  911. gcc_specs_file="${LIBPATH}/$1.specs";
  912. fi;
  913. echo "PATH=\"${BINPATH}\"" > ${gcc_envd_file};
  914. echo "ROOTPATH=\"${BINPATH}\"" >> ${gcc_envd_file};
  915. echo "GCC_PATH=\"${BINPATH}\"" >> ${gcc_envd_file};
  916. if is_multilib; then
  917. LDPATH="${LIBPATH}";
  918. for path in 32 64;
  919. do
  920. [[ -d ${LIBPATH}/${path} ]] && LDPATH="${LDPATH}:${LIBPATH}/${path}";
  921. done;
  922. else
  923. local MULTIDIR;
  924. LDPATH="${LIBPATH}";
  925. local abi=${DEFAULT_ABI};
  926. local MULTIDIR=$($(XGCC) $(get_abi_CFLAGS ${abi}) --print-multi-directory);
  927. if [[ ${MULTIDIR} == "." ]]; then
  928. LDPATH=${LIBPATH};
  929. else
  930. LDPATH=${LIBPATH}/${MULTIDIR};
  931. fi;
  932. for abi in $(get_all_abis);
  933. do
  934. [[ ${abi} == ${DEFAULT_ABI} ]] && continue;
  935. MULTIDIR=$($(XGCC) $(get_abi_CFLAGS ${abi}) --print-multi-directory);
  936. if [[ ${MULTIDIR} == "." ]]; then
  937. LDPATH=${LDPATH}:${LIBPATH};
  938. else
  939. LDPATH=${LDPATH}:${LIBPATH}/${MULTIDIR};
  940. fi;
  941. done;
  942. fi;
  943. echo "LDPATH=\"${LDPATH}\"" >> ${gcc_envd_file};
  944. echo "MANPATH=\"${DATAPATH}/man\"" >> ${gcc_envd_file};
  945. echo "INFOPATH=\"${DATAPATH}/info\"" >> ${gcc_envd_file};
  946. echo "STDCXX_INCDIR=\"${STDCXX_INCDIR##*/}\"" >> ${gcc_envd_file};
  947. is_crosscompile && echo "CTARGET=${CTARGET}" >> ${gcc_envd_file};
  948. [[ -n ${gcc_specs_file} ]] && echo "GCC_SPECS=\"${gcc_specs_file}\"" >> ${gcc_envd_file}
  949. }
  950. create_hardened_specs_file ()
  951. {
  952. _create_specs_file !hardened hardened ${gcc_common_hard} -DEFAULT_PIE_SSP
  953. }
  954. create_hardenednopie_specs_file ()
  955. {
  956. _create_specs_file "" hardenednopie ${gcc_common_hard} -DEFAULT_SSP
  957. }
  958. create_hardenednopiessp_specs_file ()
  959. {
  960. _create_specs_file "" hardenednopiessp ${gcc_common_hard}
  961. }
  962. create_hardenednossp_specs_file ()
  963. {
  964. _create_specs_file "" hardenednossp ${gcc_common_hard} -DEFAULT_PIE
  965. }
  966. create_vanilla_specs_file ()
  967. {
  968. _create_specs_file hardened vanilla
  969. }
  970. darwintoolize ()
  971. {
  972. die "Use elibtoolize"
  973. }
  974. delete_all_version_separators ()
  975. {
  976. eshopts_push -s extglob;
  977. replace_all_version_separators "" "${1}";
  978. eshopts_pop
  979. }
  980. delete_version_separator ()
  981. {
  982. eshopts_push -s extglob;
  983. replace_version_separator "${1}" "" "${2}";
  984. eshopts_pop
  985. }
  986. disable_multilib_libjava ()
  987. {
  988. if is_gcj; then
  989. pushd "${S}" > /dev/null;
  990. sed -i -e 's/^all: all-redirect/ifeq (\$(MULTISUBDIR),)\nall: all-redirect\nelse\nall:\n\techo Multilib libjava build disabled\nendif/' libjava/Makefile.in;
  991. sed -i -e 's/^install: install-redirect/ifeq (\$(MULTISUBDIR),)\ninstall: install-redirect\nelse\ninstall:\n\techo Multilib libjava install disabled\nendif/' libjava/Makefile.in;
  992. sed -i -e 's/^check: check-redirect/ifeq (\$(MULTISUBDIR),)\ncheck: check-redirect\nelse\ncheck:\n\techo Multilib libjava check disabled\nendif/' libjava/Makefile.in;
  993. sed -i -e 's/^all: all-recursive/ifeq (\$(MULTISUBDIR),)\nall: all-recursive\nelse\nall:\n\techo Multilib libjava build disabled\nendif/' libjava/Makefile.in;
  994. sed -i -e 's/^install: install-recursive/ifeq (\$(MULTISUBDIR),)\ninstall: install-recursive\nelse\ninstall:\n\techo Multilib libjava install disabled\nendif/' libjava/Makefile.in;
  995. sed -i -e 's/^check: check-recursive/ifeq (\$(MULTISUBDIR),)\ncheck: check-recursive\nelse\ncheck:\n\techo Multilib libjava check disabled\nendif/' libjava/Makefile.in;
  996. popd > /dev/null;
  997. fi
  998. }
  999. dlopen_lib ()
  1000. {
  1001. case "${CHOST}" in
  1002. *-linux-gnu* | *-linux-uclibc | *-interix*)
  1003. echo "-ldl"
  1004. ;;
  1005. esac
  1006. }
  1007. do_gcc_HTB_patches ()
  1008. {
  1009. if ! want_boundschecking || ( want_ssp && [[ ${HTB_EXCLUSIVE} == "true" ]] ); then
  1010. do_gcc_stub htb;
  1011. return 0;
  1012. fi;
  1013. epatch "${WORKDIR}/bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch";
  1014. BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, HTB-${HTB_GCC_VER}-${HTB_VER}"
  1015. }
  1016. do_gcc_PIE_patches ()
  1017. {
  1018. if ! want_pie || ( want_boundschecking && [[ ${HTB_EXCLUSIVE} == "true" ]] ); then
  1019. return 0;
  1020. fi;
  1021. want_boundschecking && rm -f "${WORKDIR}"/piepatch/*/*-boundschecking-no.patch* || rm -f "${WORKDIR}"/piepatch/*/*-boundschecking-yes.patch*;
  1022. use vanilla && return 0;
  1023. if tc_version_is_at_least 4.3.2; then
  1024. guess_patch_type_in_dir "${WORKDIR}"/piepatch/;
  1025. EPATCH_MULTI_MSG="Applying pie patches ..." epatch "${WORKDIR}"/piepatch/;
  1026. else
  1027. guess_patch_type_in_dir "${WORKDIR}"/piepatch/upstream;
  1028. EPATCH_MULTI_MSG="Applying upstream pie patches ..." epatch "${WORKDIR}"/piepatch/upstream;
  1029. EPATCH_MULTI_MSG="Applying non-default pie patches ..." epatch "${WORKDIR}"/piepatch/nondef;
  1030. EPATCH_MULTI_MSG="Applying default pie patches ..." epatch "${WORKDIR}"/piepatch/def;
  1031. fi;
  1032. sed -e '/^ALL_CFLAGS/iHARD_CFLAGS = ' -e 's|^ALL_CFLAGS = |ALL_CFLAGS = $(HARD_CFLAGS) |' -i "${S}"/gcc/Makefile.in;
  1033. BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, pie-${PIE_VER}"
  1034. }
  1035. do_gcc_SSP_patches ()
  1036. {
  1037. if [[ $(tc-arch) == "hppa" ]] || ! want_ssp || ( want_boundschecking && [[ ${HTB_EXCLUSIVE} == "true" ]] ); then
  1038. do_gcc_stub ssp;
  1039. return 0;
  1040. fi;
  1041. local ssppatch;
  1042. local sspdocs;
  1043. if [[ -n ${PP_FVER} ]]; then
  1044. if tc_version_is_at_least 3.4.1; then
  1045. ssppatch="${S}/gcc_${PP_VER}.dif";
  1046. sspdocs="yes";
  1047. else
  1048. if tc_version_is_at_least 3.4.0; then
  1049. ssppatch="${S}/protector.dif";
  1050. sspdocs="no";
  1051. else
  1052. if tc_version_is_at_least 3.2.3; then
  1053. mv "${S}"/protector.{c,h} "${S}"/gcc;
  1054. ssppatch="${S}/protector.dif";
  1055. sspdocs="no";
  1056. fi;
  1057. fi;
  1058. fi;
  1059. else
  1060. mv "${WORKDIR}"/ssp/protector.{c,h} "${S}"/gcc/;
  1061. ssppatch=${WORKDIR}/ssp/gcc-${PP_GCC_VER}-ssp.patch;
  1062. ( want_boundschecking && [[ -e ${WORKDIR}/ssp/htb-ssp.patch ]] ) && patch -s "${ssppatch}" "${WORKDIR}"/ssp/htb-ssp.patch;
  1063. fi;
  1064. [[ -z ${ssppatch} ]] && die "Sorry, SSP is not supported in this version";
  1065. epatch ${ssppatch};
  1066. if [[ ${PN} == "gcc" && ${sspdocs} == "no" ]]; then
  1067. epatch "${GCC_FILESDIR}"/pro-police-docs.patch;
  1068. fi;
  1069. sed -e 's|^CRTSTUFF_CFLAGS = |CRTSTUFF_CFLAGS = -fno-stack-protector |' -i gcc/Makefile.in || die "Failed to update crtstuff!";
  1070. if use build && tc_version_is_at_least 3.4.0; then
  1071. if gcc -dumpspecs | grep -q "fno-stack-protector:"; then
  1072. epatch "${GCC_FILESDIR}"/3.4.0/gcc-3.4.0-cc1-no-stack-protector.patch;
  1073. fi;
  1074. fi;
  1075. BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, ssp-${PP_FVER:-${PP_GCC_VER}-${PP_VER}}";
  1076. if want_libssp; then
  1077. update_gcc_for_libssp;
  1078. else
  1079. update_gcc_for_libc_ssp;
  1080. fi;
  1081. sed -e 's|^\(LIBGCC2_CFLAGS.*\)$|\1 -fno-stack-protector|' -i gcc/Makefile.in || die "Failed to update gcc!"
  1082. }
  1083. do_gcc_config ()
  1084. {
  1085. if ! should_we_gcc_config; then
  1086. env -i ROOT="${ROOT}" gcc-config --use-old --force;
  1087. return 0;
  1088. fi;
  1089. local current_gcc_config="" current_specs="" use_specs="";
  1090. current_gcc_config=$(env -i ROOT="${ROOT}" gcc-config -c ${CTARGET} 2>/dev/null);
  1091. if [[ -n ${current_gcc_config} ]]; then
  1092. current_specs=$(gcc-config -S ${current_gcc_config} | awk '{print $3}');
  1093. [[ -n ${current_specs} ]] && use_specs=-${current_specs};
  1094. fi;
  1095. if [[ -n ${use_specs} ]] && [[ ! -e ${ROOT}/etc/env.d/gcc/${CTARGET}-${GCC_CONFIG_VER}${use_specs} ]]; then
  1096. ewarn "The currently selected specs-specific gcc config,";
  1097. ewarn "${current_specs}, doesn't exist anymore. This is usually";
  1098. ewarn "due to enabling/disabling hardened or switching to a version";
  1099. ewarn "of gcc that doesnt create multiple specs files. The default";
  1100. ewarn "config will be used, and the previous preference forgotten.";
  1101. ebeep;
  1102. epause;
  1103. use_specs="";
  1104. fi;
  1105. gcc-config ${CTARGET}-${GCC_CONFIG_VER}${use_specs}
  1106. }
  1107. do_gcc_rename_java_bins ()
  1108. {
  1109. einfo "Renaming jdk executables rmic and rmiregistry to grmic and grmiregistry.";
  1110. for manfile in rmic rmiregistry;
  1111. do
  1112. [[ -f ${S}/gcc/doc/${manfile}.1 ]] || continue;
  1113. mv "${S}"/gcc/doc/${manfile}.1 "${S}"/gcc/doc/g${manfile}.1;
  1114. done;
  1115. for jfile in gcc/doc/gcj.info gcc/doc/grmic.1 gcc/doc/grmiregistry.1 gcc/java/gcj.texi;
  1116. do
  1117. [[ -f ${S}/${jfile} ]] || continue;
  1118. sed -i -e 's:rmiregistry:grmiregistry:g' "${S}"/${jfile} || die "Failed to fixup file ${jfile} for rename to grmiregistry";
  1119. sed -i -e 's:rmic:grmic:g' "${S}"/${jfile} || die "Failed to fixup file ${jfile} for rename to grmic";
  1120. done;
  1121. for jfile in libjava/Makefile.am libjava/Makefile.in gcc/java/Make-lang.in;
  1122. do
  1123. sed -i -e 's:rmiregistry:grmiregistry:g' "${S}"/${jfile} || die "Failed to fixup file ${jfile} for rename to grmiregistry";
  1124. sed -i -e 's:rmic\([$_ ]\):grmic\1:g' "${S}"/${jfile} || die "Failed to fixup file ${jfile} for rename to grmic";
  1125. done
  1126. }
  1127. do_gcc_stub ()
  1128. {
  1129. local v stub_patch="";
  1130. for v in ${GCC_RELEASE_VER} ${GCC_BRANCH_VER};
  1131. do
  1132. stub_patch=${GCC_FILESDIR}/stubs/gcc-${v}-$1-stub.patch;
  1133. if [[ -e ${stub_patch} ]] && ! use vanilla; then
  1134. EPATCH_SINGLE_MSG="Applying stub patch for $1 ..." epatch "${stub_patch}";
  1135. return 0;
  1136. fi;
  1137. done
  1138. }
  1139. doicon ()
  1140. {
  1141. ( local i j ret;
  1142. insinto /usr/share/pixmaps;
  1143. for i in "$@";
  1144. do
  1145. if [[ -f ${i} ]]; then
  1146. doins "${i}";
  1147. ((ret+=$?));
  1148. else
  1149. if [[ -d ${i} ]]; then
  1150. for j in "${i}"/*.png;
  1151. do
  1152. doins "${j}";
  1153. ((ret+=$?));
  1154. done;
  1155. else
  1156. ((++ret));
  1157. fi;
  1158. fi;
  1159. done;
  1160. exit ${ret} )
  1161. }
  1162. domenu ()
  1163. {
  1164. ( local i j ret=0;
  1165. insinto /usr/share/applications;
  1166. for i in "$@";
  1167. do
  1168. if [[ -f ${i} ]]; then
  1169. doins "${i}";
  1170. ((ret+=$?));
  1171. else
  1172. if [[ -d ${i} ]]; then
  1173. for j in "${i}"/*.desktop;
  1174. do
  1175. doins "${j}";
  1176. ((ret+=$?));
  1177. done;
  1178. else
  1179. ((++ret));
  1180. fi;
  1181. fi;
  1182. done;
  1183. exit ${ret} )
  1184. }
  1185. dyn_pretend ()
  1186. {
  1187. if [[ -e $PORTAGE_BUILDDIR/.pretended ]]; then
  1188. vecho ">>> It appears that '$PF' is already pretended; skipping.";
  1189. vecho ">>> Remove '$PORTAGE_BUILDDIR/.pretended' to force pretend.";
  1190. return 0;
  1191. fi;
  1192. ebuild_phase pre_pkg_pretend;
  1193. ebuild_phase pkg_pretend;
  1194. >> "$PORTAGE_BUILDDIR/.pretended" || die "Failed to create $PORTAGE_BUILDDIR/.pretended";
  1195. ebuild_phase post_pkg_pretend
  1196. }
  1197. ebeep ()
  1198. {
  1199. local n;
  1200. if [[ -z ${EBEEP_IGNORE} ]]; then
  1201. for ((n=1 ; n <= ${1:-5} ; n++))
  1202. do
  1203. echo -ne "\a";
  1204. sleep 0.1 &>/dev/null;
  1205. sleep 0,1 &>/dev/null;
  1206. echo -ne "\a";
  1207. sleep 1;
  1208. done;
  1209. fi
  1210. }
  1211. ecvs_clean ()
  1212. {
  1213. [[ -z $* ]] && set -- .;
  1214. find "$@" -type d -name 'CVS' -prune -print0 | xargs -0 rm -rf;
  1215. find "$@" -type f -name '.cvs*' -print0 | xargs -0 rm -rf
  1216. }
  1217. edos2unix ()
  1218. {
  1219. echo "$@" | xargs sed -i 's/\r$//'
  1220. }
  1221. egetent ()
  1222. {
  1223. case ${CHOST} in
  1224. *-darwin[678])
  1225. case "$2" in
  1226. *[!0-9]*)
  1227. nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2\$/) {print \$0;exit;} }"
  1228. ;;
  1229. *)
  1230. nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }"
  1231. ;;
  1232. esac
  1233. ;;
  1234. *-darwin*)
  1235. local mytype=$1;
  1236. [[ "passwd" == $mytype ]] && mytype="Users";
  1237. [[ "group" == $mytype ]] && mytype="Groups";
  1238. case "$2" in
  1239. *[!0-9]*)
  1240. dscl . -read /$mytype/$2 2> /dev/null | grep RecordName
  1241. ;;
  1242. *)
  1243. local mykey="UniqueID";
  1244. [[ $mytype == "Groups" ]] && mykey="PrimaryGroupID";
  1245. dscl . -search /$mytype $mykey $2 2> /dev/null
  1246. ;;
  1247. esac
  1248. ;;
  1249. *-freebsd* | *-dragonfly*)
  1250. local opts action="user";
  1251. [[ $1 == "passwd" ]] || action="group";
  1252. if [[ $2 == [[:digit:]]* ]]; then
  1253. [[ ${action} == "user" ]] && opts="-u" || opts="-g";
  1254. fi;
  1255. pw show ${action} ${opts} "$2" -q
  1256. ;;
  1257. *-netbsd* | *-openbsd*)
  1258. grep "$2:\*:" /etc/$1
  1259. ;;
  1260. *)
  1261. type -p nscd &>/dev/null && nscd -i "$1";
  1262. getent "$1" "$2"
  1263. ;;
  1264. esac
  1265. }
  1266. egethome ()
  1267. {
  1268. ent=$(egetent passwd $1);
  1269. case ${CHOST} in
  1270. *-darwin* | *-freebsd* | *-dragonfly*)
  1271. echo ${ent} | cut -d: -f9
  1272. ;;
  1273. *)
  1274. echo ${ent} | cut -d: -f6
  1275. ;;
  1276. esac
  1277. }
  1278. egetshell ()
  1279. {
  1280. ent=$(egetent passwd "$1");
  1281. case ${CHOST} in
  1282. *-darwin* | *-freebsd* | *-dragonfly*)
  1283. echo ${ent} | cut -d: -f10
  1284. ;;
  1285. *)
  1286. echo ${ent} cut -d: -f7
  1287. ;;
  1288. esac
  1289. }
  1290. elibtoolize ()
  1291. {
  1292. local x;
  1293. local do_portage="no";
  1294. local do_reversedeps="no";
  1295. local do_only_patches="no";
  1296. local do_uclibc="yes";
  1297. local deptoremove=;
  1298. local do_shallow="no";
  1299. local elt_patches="install-sh ltmain portage relink max_cmd_len sed test tmp cross as-needed";
  1300. for x in "$@";
  1301. do
  1302. case ${x} in
  1303. --portage)
  1304. do_portage="yes"
  1305. ;;
  1306. --reverse-deps)
  1307. do_reversedeps="yes";
  1308. elt_patches+=" fix-relink"
  1309. ;;
  1310. --patch-only)
  1311. do_only_patches="yes"
  1312. ;;
  1313. --remove-internal-dep=*)
  1314. deptoremove=${x#--remove-internal-dep=};
  1315. [[ -n ${deptoremove} ]] && elt_patches+=" rem-int-dep"
  1316. ;;
  1317. --shallow)
  1318. do_shallow="yes"
  1319. ;;
  1320. --no-uclibc)
  1321. do_uclibc="no"
  1322. ;;
  1323. *)
  1324. eerror "Invalid elibtoolize option: ${x}";
  1325. die "elibtoolize called with ${x} ??"
  1326. ;;
  1327. esac;
  1328. done;
  1329. [[ ${do_uclibc} == "yes" ]] && elt_patches+=" uclibc-conf uclibc-ltconf";
  1330. case ${CHOST} in
  1331. *-aix*)
  1332. elt_patches+=" hardcode aixrtl aix-noundef"
  1333. ;;
  1334. *-darwin*)
  1335. elt_patches+=" darwin-ltconf darwin-ltmain darwin-conf"
  1336. ;;
  1337. *-freebsd*)
  1338. elt_patches+=" fbsd-conf fbsd-ltconf"
  1339. ;;
  1340. *-hpux*)
  1341. elt_patches+=" hpux-conf deplibs hc-flag-ld hardcode hardcode-relink relink-prog no-lc"
  1342. ;;
  1343. *-irix*)
  1344. elt_patches+=" irix-ltmain"
  1345. ;;
  1346. *-mint*)
  1347. elt_patches+=" mint-conf"
  1348. ;;
  1349. esac;
  1350. if $(tc-getLD) --version 2>&1 | grep -qs 'GNU gold'; then
  1351. elt_patches+=" gold-conf";
  1352. fi;
  1353. set --;
  1354. if [[ ${do_shallow} == "yes" ]]; then
  1355. [[ -f ${S}/ltmain.sh ]] && set -- "${S}";
  1356. else
  1357. set -- $(find "${S}" -name ltmain.sh -printf '%h ');
  1358. fi;
  1359. local d p;
  1360. for d in "$@";
  1361. do
  1362. export ELT_APPLIED_PATCHES=;
  1363. [[ -f ${d}/.elibtoolized ]] && continue;
  1364. einfo "Running elibtoolize in: ${d#${WORKDIR}/}/";
  1365. for p in ${elt_patches};
  1366. do
  1367. local ret=0;
  1368. case ${p} in
  1369. portage)
  1370. if ! grep -qs 'We do not want portage' "${d}/ltmain.sh"; then
  1371. ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1372. ret=$?;
  1373. fi
  1374. ;;
  1375. rem-int-dep)
  1376. ELT_walk_patches "${d}/ltmain.sh" "${p}" "${deptoremove}";
  1377. ret=$?
  1378. ;;
  1379. fix-relink)
  1380. if grep -qs 'inst_prefix_dir' "${d}/ltmain.sh"; then
  1381. ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1382. ret=$?;
  1383. fi
  1384. ;;
  1385. max_cmd_len)
  1386. if grep -qs 'max_cmd_len' "${d}/ltmain.sh"; then
  1387. ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1388. ret=$?;
  1389. fi
  1390. ;;
  1391. as-needed)
  1392. ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1393. ret=$?
  1394. ;;
  1395. uclibc-conf)
  1396. if grep -qs 'Transform linux' "${d}/configure"; then
  1397. ELT_walk_patches "${d}/configure" "${p}";
  1398. ret=$?;
  1399. else
  1400. if [[ ! -e ${d}/configure ]] && grep -qs 'Transform linux' "${d}/../configure"; then
  1401. ELT_walk_patches "${d}/../configure" "${p}";
  1402. ret=$?;
  1403. fi;
  1404. fi
  1405. ;;
  1406. uclibc-ltconf)
  1407. if [[ -s ${d}/ltconfig ]]; then
  1408. ELT_walk_patches "${d}/ltconfig" "${p}";
  1409. ret=$?;
  1410. fi
  1411. ;;
  1412. fbsd-conf)
  1413. if grep -qs 'version_type=freebsd-' "${d}/configure"; then
  1414. ELT_walk_patches "${d}/configure" "${p}";
  1415. ret=$?;
  1416. else
  1417. if [[ ! -e ${d}/configure ]] && grep -qs 'version_type=freebsd-' "${d}/../configure"; then
  1418. ELT_walk_patches "${d}/../configure" "${p}";
  1419. ret=$?;
  1420. fi;
  1421. fi
  1422. ;;
  1423. fbsd-ltconf)
  1424. if [[ -s ${d}/ltconfig ]]; then
  1425. ELT_walk_patches "${d}/ltconfig" "${p}";
  1426. ret=$?;
  1427. fi
  1428. ;;
  1429. darwin-conf)
  1430. if grep -qs '&& echo \.so ||' "${d}/configure"; then
  1431. ELT_walk_patches "${d}/configure" "${p}";
  1432. ret=$?;
  1433. else
  1434. if [[ ! -e ${d}/configure ]] && grep -qs '&& echo \.so ||' "${d}/../configure"; then
  1435. ELT_walk_patches "${d}/../configure" "${p}";
  1436. ret=$?;
  1437. fi;
  1438. fi
  1439. ;;
  1440. darwin-ltconf)
  1441. if [[ -s ${d}/ltconfig ]]; then
  1442. ELT_walk_patches "${d}/ltconfig" "${p}";
  1443. ret=$?;
  1444. fi
  1445. ;;
  1446. darwin-ltmain)
  1447. if [[ -e ${d}/ltmain.sh ]] && ! grep -qs 'verstring="-compatibility_version' "${d}/ltmain.sh"; then
  1448. ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1449. ret=$?;
  1450. fi
  1451. ;;
  1452. aixrtl | hpux-conf)
  1453. ret=1;
  1454. local subret=0;
  1455. while [[ $subret -eq 0 ]]; do
  1456. subret=1;
  1457. if [[ -e ${d}/configure ]]; then
  1458. ELT_walk_patches "${d}/configure" "${p}";
  1459. subret=$?;
  1460. else
  1461. if [[ ! -e ${d}/configure && -e ${d}/../configure ]]; then
  1462. ELT_walk_patches "${d}/../configure" "${p}";
  1463. subret=$?;
  1464. fi;
  1465. fi;
  1466. if [[ $subret -eq 0 ]]; then
  1467. ret=0;
  1468. fi;
  1469. done
  1470. ;;
  1471. mint-conf | gold-conf)
  1472. ret=1;
  1473. local subret=1;
  1474. if [[ -e ${d}/configure ]]; then
  1475. ELT_walk_patches "${d}/configure" "${p}";
  1476. subret=$?;
  1477. else
  1478. if [[ -e ${d}/../configure ]]; then
  1479. ELT_walk_patches "${d}/../configure" "${p}";
  1480. subret=$?;
  1481. else
  1482. if [[ -e ${d}/../../configure ]]; then
  1483. ELT_walk_patches "${d}/../../configure" "${p}";
  1484. subret=$?;
  1485. fi;
  1486. fi;
  1487. fi;
  1488. if [[ $subret -eq 0 ]]; then
  1489. ret=0;
  1490. fi
  1491. ;;
  1492. install-sh)
  1493. ELT_walk_patches "${d}/install-sh" "${p}";
  1494. ret=$?
  1495. ;;
  1496. cross)
  1497. if tc-is-cross-compiler; then
  1498. ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1499. ret=$?;
  1500. fi
  1501. ;;
  1502. *)
  1503. ELT_walk_patches "${d}/ltmain.sh" "${p}";
  1504. ret=$?
  1505. ;;
  1506. esac;
  1507. if [[ ${ret} -ne 0 ]]; then
  1508. case ${p} in
  1509. relink)
  1510. local version=$(ELT_libtool_version "${d}/ltmain.sh");
  1511. if ! grep -qs 'inst_prefix_dir' "${d}/ltmain.sh" && [[ $(VER_to_int "${version}") -ge $(VER_to_int "1.4.0") ]]; then
  1512. ewarn " Could not apply relink.patch!";
  1513. fi
  1514. ;;
  1515. portage)
  1516. if [[ ${do_portage} == "yes" ]]; then
  1517. if ! grep -qs 'We do not want portage' "${d}/ltmain.sh"; then
  1518. echo;
  1519. eerror "Portage patch requested, but failed to apply!";
  1520. eerror "Please file a bug report to add a proper patch.";
  1521. die "Portage patch requested, but failed to apply!";
  1522. fi;
  1523. else
  1524. if grep -qs 'We do not want portage' "${d}/ltmain.sh"; then
  1525. :;
  1526. else
  1527. local version=$(ELT_libtool_version "${d}"/ltmain.sh);
  1528. echo;
  1529. eerror "Portage patch failed to apply (ltmain.sh version ${version})!";
  1530. eerror "Please file a bug report to add a proper patch.";
  1531. die "Portage patch failed to apply!";
  1532. fi;
  1533. ELT_APPLIED_PATCHES="portage";
  1534. fi
  1535. ;;
  1536. uclibc-*)
  1537. [[ ${CHOST} == *-uclibc ]] && ewarn " uClibc patch set '${p}' failed to apply!"
  1538. ;;
  1539. fbsd-*)
  1540. if [[ ${CHOST} == *-freebsd* ]]; then
  1541. if [[ -z $(grep 'Handle Gentoo/FreeBSD as it was Linux' "${d}/configure" "${d}/../configure" 2>/dev/null) ]]; then
  1542. eerror " FreeBSD patch set '${p}' failed to apply!";
  1543. die "FreeBSD patch set '${p}' failed to apply!";
  1544. fi;
  1545. fi
  1546. ;;
  1547. darwin-*)
  1548. [[ ${CHOST} == *"-darwin"* ]] && ewarn " Darwin patch set '${p}' failed to apply!"
  1549. ;;
  1550. esac;
  1551. fi;
  1552. done;
  1553. if [[ -z ${ELT_APPLIED_PATCHES} ]]; then
  1554. if [[ ${do_portage} == "no" && ${do_reversedeps} == "no" && ${do_only_patches} == "no" && ${deptoremove} == "" ]]; then
  1555. ewarn "Cannot apply any patches, please file a bug about this";
  1556. die;
  1557. fi;
  1558. fi;
  1559. rm -f "${d}/libtool";
  1560. > "${d}/.elibtoolized";
  1561. done
  1562. }
  1563. emktemp ()
  1564. {
  1565. local exe="touch";
  1566. [[ $1 == -d ]] && exe="mkdir" && shift;
  1567. local topdir=$1;
  1568. if [[ -z ${topdir} ]]; then
  1569. [[ -z ${T} ]] && topdir="/tmp" || topdir=${T};
  1570. fi;
  1571. if ! type -P mktemp > /dev/null; then
  1572. local tmp=/;
  1573. while [[ -e ${tmp} ]]; do
  1574. tmp=${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM};
  1575. done;
  1576. ${exe} "${tmp}" || ${exe} -p "${tmp}";
  1577. echo "${tmp}";
  1578. else
  1579. if [[ ${exe} == "touch" ]]; then
  1580. TMPDIR="${topdir}" mktemp -t tmp.XXXXXXXXXX;
  1581. else
  1582. TMPDIR="${topdir}" mktemp -dt tmp.XXXXXXXXXX;
  1583. fi;
  1584. fi
  1585. }
  1586. enewgroup ()
  1587. {
  1588. case ${EBUILD_PHASE} in
  1589. unpack | compile | test | install)
  1590. eerror "'enewgroup()' called from '${EBUILD_PHASE}()' which is not a pkg_* function.";
  1591. eerror "Package fails at QA and at life. Please file a bug.";
  1592. die "Bad package! enewgroup is only for use in pkg_* functions!"
  1593. ;;
  1594. esac;
  1595. local egroup="$1";
  1596. shift;
  1597. if [ -z "${egroup}" ]; then
  1598. eerror "No group specified !";
  1599. die "Cannot call enewgroup without a group";
  1600. fi;
  1601. if [[ -n $(egetent group "${egroup}") ]]; then
  1602. return 0;
  1603. fi;
  1604. einfo "Adding group '${egroup}' to your system ...";
  1605. local opts=;
  1606. local egid="$1";
  1607. shift;
  1608. if [ ! -z "${egid}" ]; then
  1609. if [ "${egid}" -gt 0 ]; then
  1610. if [ -z "`egetent group ${egid}`" ]; then
  1611. if [[ "${CHOST}" == *-darwin* ]]; then
  1612. opts="${opts} ${egid}";
  1613. else
  1614. opts="${opts} -g ${egid}";
  1615. fi;
  1616. else
  1617. egid="next available; requested gid taken";
  1618. fi;
  1619. else
  1620. eerror "Groupid given but is not greater than 0 !";
  1621. die "${egid} is not a valid GID";
  1622. fi;
  1623. else
  1624. egid="next available";
  1625. fi;
  1626. einfo " - Groupid: ${egid}";
  1627. local eextra="$@";
  1628. opts="${opts} ${eextra}";
  1629. local oldsandbox="${SANDBOX_ON}";
  1630. export SANDBOX_ON="0";
  1631. case ${CHOST} in
  1632. *-darwin*)
  1633. if [ ! -z "${eextra}" ]; then
  1634. einfo "Extra options are not supported on Darwin/OS X yet";
  1635. einfo "Please report the ebuild along with the info below";
  1636. einfo "eextra: ${eextra}";
  1637. die "Required function missing";
  1638. fi;
  1639. case ${egid} in
  1640. *[!0-9]*)
  1641. for ((egid = 101; egid <= 999; egid++))
  1642. do
  1643. [[ -z $(egetent group ${egid}) ]] && break;
  1644. done
  1645. ;;
  1646. esac;
  1647. dscl . create /groups/${egroup} gid ${egid};
  1648. dscl . create /groups/${egroup} passwd '*'
  1649. ;;
  1650. *-freebsd* | *-dragonfly*)
  1651. case ${egid} in
  1652. *[!0-9]*)
  1653. for ((egid = 101; egid <= 999; egid++))
  1654. do
  1655. [[ -z $(egetent group ${egid}) ]] && break;
  1656. done
  1657. ;;
  1658. esac;
  1659. pw groupadd ${egroup} -g ${egid} || die "enewgroup failed"
  1660. ;;
  1661. *-netbsd*)
  1662. case ${egid} in
  1663. *[!0-9]*)
  1664. for ((egid = 101; egid <= 999; egid++))
  1665. do
  1666. [[ -z $(egetent group ${egid}) ]] && break;
  1667. done
  1668. ;;
  1669. esac;
  1670. groupadd -g ${egid} ${egroup} || die "enewgroup failed"
  1671. ;;
  1672. *)
  1673. groupadd -r ${opts} ${egroup} || die "enewgroup failed"
  1674. ;;
  1675. esac;
  1676. export SANDBOX_ON="${oldsandbox}"
  1677. }
  1678. enewuser ()
  1679. {
  1680. case ${EBUILD_PHASE} in
  1681. unpack | compile | test | install)
  1682. eerror "'enewuser()' called from '${EBUILD_PHASE}()' which is not a pkg_* function.";
  1683. eerror "Package fails at QA and at life. Please file a bug.";
  1684. die "Bad package! enewuser is only for use in pkg_* functions!"
  1685. ;;
  1686. esac;
  1687. local euser=$1;
  1688. shift;
  1689. if [[ -z ${euser} ]]; then
  1690. eerror "No username specified !";
  1691. die "Cannot call enewuser without a username";
  1692. fi;
  1693. if [[ -n $(egetent passwd "${euser}") ]]; then
  1694. return 0;
  1695. fi;
  1696. einfo "Adding user '${euser}' to your system ...";
  1697. local opts=;
  1698. local euid=$1;
  1699. shift;
  1700. if [[ -n ${euid} && ${euid} != -1 ]]; then
  1701. if [[ ${euid} -gt 0 ]]; then
  1702. if [[ -n $(egetent passwd ${euid}) ]]; then
  1703. euid="next";
  1704. fi;
  1705. else
  1706. eerror "Userid given but is not greater than 0 !";
  1707. die "${euid} is not a valid UID";
  1708. fi;
  1709. else
  1710. euid="next";
  1711. fi;
  1712. if [[ ${euid} == "next" ]]; then
  1713. for ((euid = 101; euid <= 999; euid++))
  1714. do
  1715. [[ -z $(egetent passwd ${euid}) ]] && break;
  1716. done;
  1717. fi;
  1718. opts="${opts} -u ${euid}";
  1719. einfo " - Userid: ${euid}";
  1720. local eshell=$1;
  1721. shift;
  1722. if [[ ! -z ${eshell} ]] && [[ ${eshell} != "-1" ]]; then
  1723. if [[ ! -e ${ROOT}${eshell} ]]; then
  1724. eerror "A shell was specified but it does not exist !";
  1725. die "${eshell} does not exist in ${ROOT}";
  1726. fi;
  1727. if [[ ${eshell} == */false || ${eshell} == */nologin ]]; then
  1728. eerror "Do not specify ${eshell} yourself, use -1";
  1729. die "Pass '-1' as the shell parameter";
  1730. fi;
  1731. else
  1732. for shell in /sbin/nologin /usr/sbin/nologin /bin/false /usr/bin/false /dev/null;
  1733. do
  1734. [[ -x ${ROOT}${shell} ]] && break;
  1735. done;
  1736. if [[ ${shell} == "/dev/null" ]]; then
  1737. eerror "Unable to identify the shell to use, proceeding with userland default.";
  1738. case ${USERLAND} in
  1739. GNU)
  1740. shell="/bin/false"
  1741. ;;
  1742. BSD)
  1743. shell="/sbin/nologin"
  1744. ;;
  1745. Darwin)
  1746. shell="/usr/sbin/nologin"
  1747. ;;
  1748. *)
  1749. die "Unable to identify the default shell for userland ${USERLAND}"
  1750. ;;
  1751. esac;
  1752. fi;
  1753. eshell=${shell};
  1754. fi;
  1755. einfo " - Shell: ${eshell}";
  1756. opts="${opts} -s ${eshell}";
  1757. local ehome=$1;
  1758. shift;
  1759. if [[ -z ${ehome} ]] || [[ ${ehome} == "-1" ]]; then
  1760. ehome="/dev/null";
  1761. fi;
  1762. einfo " - Home: ${ehome}";
  1763. opts="${opts} -d ${ehome}";
  1764. local egroups=$1;
  1765. shift;
  1766. if [[ ! -z ${egroups} ]]; then
  1767. local oldifs=${IFS};
  1768. local defgroup="" exgroups="";
  1769. export IFS=",";
  1770. for g in ${egroups};
  1771. do
  1772. export IFS=${oldifs};
  1773. if [[ -z $(egetent group "${g}") ]]; then
  1774. eerror "You must add group ${g} to the system first";
  1775. die "${g} is not a valid GID";
  1776. fi;
  1777. if [[ -z ${defgroup} ]]; then
  1778. defgroup=${g};
  1779. else
  1780. exgroups="${exgroups},${g}";
  1781. fi;
  1782. export IFS=",";
  1783. done;
  1784. export IFS=${oldifs};
  1785. opts="${opts} -g ${defgroup}";
  1786. if [[ ! -z ${exgroups} ]]; then
  1787. opts="${opts} -G ${exgroups:1}";
  1788. fi;
  1789. else
  1790. egroups="(none)";
  1791. fi;
  1792. einfo " - Groups: ${egroups}";
  1793. local oldsandbox=${SANDBOX_ON};
  1794. export SANDBOX_ON="0";
  1795. case ${CHOST} in
  1796. *-darwin*)
  1797. if [[ -z $@ ]]; then
  1798. dscl . create /users/${euser} uid ${euid};
  1799. dscl . create /users/${euser} shell ${eshell};
  1800. dscl . create /users/${euser} home ${ehome};
  1801. dscl . create /users/${euser} realname "added by portage for ${PN}";
  1802. local oldifs=${IFS};
  1803. export IFS=",";
  1804. for g in ${egroups};
  1805. do
  1806. dscl . merge /groups/${g} users ${euser};
  1807. done;
  1808. export IFS=${oldifs};
  1809. else
  1810. einfo "Extra options are not supported on Darwin yet";
  1811. einfo "Please report the ebuild along with the info below";
  1812. einfo "eextra: $@";
  1813. die "Required function missing";
  1814. fi
  1815. ;;
  1816. *-freebsd* | *-dragonfly*)
  1817. if [[ -z $@ ]]; then
  1818. pw useradd ${euser} ${opts} -c "added by portage for ${PN}" die "enewuser failed";
  1819. else
  1820. einfo " - Extra: $@";
  1821. pw useradd ${euser} ${opts} "$@" || die "enewuser failed";
  1822. fi
  1823. ;;
  1824. *-netbsd*)
  1825. if [[ -z $@ ]]; then
  1826. useradd ${opts} ${euser} || die "enewuser failed";
  1827. else
  1828. einfo " - Extra: $@";
  1829. useradd ${opts} ${euser} "$@" || die "enewuser failed";
  1830. fi
  1831. ;;
  1832. *-openbsd*)
  1833. if [[ -z $@ ]]; then
  1834. useradd -u ${euid} -s ${eshell} -d ${ehome} -c "Added by portage for ${PN}" -g ${egroups} ${euser} || die "enewuser failed";
  1835. else
  1836. einfo " - Extra: $@";
  1837. useradd -u ${euid} -s ${eshell} -d ${ehome} -c "Added by portage for ${PN}" -g ${egroups} ${euser} "$@" || die "enewuser failed";
  1838. fi
  1839. ;;
  1840. *)
  1841. if [[ -z $@ ]]; then
  1842. useradd -r ${opts} -c "added by portage for ${PN}" ${euser} || die "enewuser failed";
  1843. else
  1844. einfo " - Extra: $@";
  1845. useradd -r ${opts} "$@" ${euser} || die "enewuser failed";
  1846. fi
  1847. ;;
  1848. esac;
  1849. if [[ ! -e ${ROOT}/${ehome} ]]; then
  1850. einfo " - Creating ${ehome} in ${ROOT}";
  1851. mkdir -p "${ROOT}/${ehome}";
  1852. chown ${euser} "${ROOT}/${ehome}";
  1853. chmod 755 "${ROOT}/${ehome}";
  1854. fi;
  1855. export SANDBOX_ON=${oldsandbox}
  1856. }
  1857. epatch ()
  1858. {
  1859. function _epatch_draw_line ()
  1860. {
  1861. [[ -z $1 ]] && set "$(printf "%65s" '')";
  1862. echo "${1//?/=}"
  1863. };
  1864. unset P4CONFIG P4PORT P4USER;
  1865. if [[ $# -gt 1 ]]; then
  1866. local m;
  1867. for m in "$@";
  1868. do
  1869. epatch "${m}";
  1870. done;
  1871. return 0;
  1872. fi;
  1873. local SINGLE_PATCH="no";
  1874. [[ $# -eq 0 ]] && set -- "${EPATCH_SOURCE}";
  1875. if [[ -f $1 ]]; then
  1876. SINGLE_PATCH="yes";
  1877. set -- "$1";
  1878. local EPATCH_SUFFIX=$1;
  1879. else
  1880. if [[ -d $1 ]]; then
  1881. set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"};
  1882. else
  1883. [[ $# -ne 0 ]] && EPATCH_SOURCE=$1;
  1884. echo;
  1885. eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:";
  1886. eerror;
  1887. eerror " ${EPATCH_SOURCE}";
  1888. eerror " ( ${EPATCH_SOURCE##*/} )";
  1889. echo;
  1890. die "Cannot find \$EPATCH_SOURCE!";
  1891. fi;
  1892. fi;
  1893. local PIPE_CMD;
  1894. case ${EPATCH_SUFFIX##*\.} in
  1895. xz)
  1896. PIPE_CMD="xz -dc"
  1897. ;;
  1898. lzma)
  1899. PIPE_CMD="lzma -dc"
  1900. ;;
  1901. bz2)
  1902. PIPE_CMD="bzip2 -dc"
  1903. ;;
  1904. gz | Z | z)
  1905. PIPE_CMD="gzip -dc"
  1906. ;;
  1907. ZIP | zip)
  1908. PIPE_CMD="unzip -p"
  1909. ;;
  1910. *)
  1911.  
  1912. ;;
  1913. esac;
  1914. [[ ${SINGLE_PATCH} == "no" ]] && einfo "${EPATCH_MULTI_MSG}";
  1915. local x;
  1916. for x in "$@";
  1917. do
  1918. [[ ! -f ${x} ]] && continue;
  1919. local patchname=${x##*/};
  1920. local a=${patchname#*_};
  1921. a=${a%%_*};
  1922. if ! [[ ${SINGLE_PATCH} == "yes" || ${EPATCH_FORCE} == "yes" || ${a} == all || ${a} == ${ARCH} ]]; then
  1923. continue;
  1924. fi;
  1925. if [[ -n ${EPATCH_EXCLUDE} ]]; then
  1926. eshopts_push -o noglob;
  1927. local ex;
  1928. for ex in ${EPATCH_EXCLUDE};
  1929. do
  1930. if [[ ${patchname} == ${ex} ]]; then
  1931. eshopts_pop;
  1932. continue 2;
  1933. fi;
  1934. done;
  1935. eshopts_pop;
  1936. fi;
  1937. if [[ ${SINGLE_PATCH} == "yes" ]]; then
  1938. if [[ -n ${EPATCH_SINGLE_MSG} ]]; then
  1939. einfo "${EPATCH_SINGLE_MSG}";
  1940. else
  1941. einfo "Applying ${patchname} ...";
  1942. fi;
  1943. else
  1944. einfo " ${patchname} ...";
  1945. fi;
  1946. local STDERR_TARGET="${T}/${patchname}.out";
  1947. if [[ -e ${STDERR_TARGET} ]]; then
  1948. STDERR_TARGET="${T}/${patchname}-$$.out";
  1949. fi;
  1950. printf "***** %s *****\n\n" "${patchname}" > "${STDERR_TARGET}";
  1951. local count=0;
  1952. local PATCH_TARGET;
  1953. if [[ -n ${PIPE_CMD} ]]; then
  1954. PATCH_TARGET="${T}/$$.patch";
  1955. echo "PIPE_COMMAND: ${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> "${STDERR_TARGET}";
  1956. if ! ( ${PIPE_CMD} "${x}" > "${PATCH_TARGET}" ) >> "${STDERR_TARGET}" 2>&1; then
  1957. echo;
  1958. eerror "Could not extract patch!";
  1959. count=5;
  1960. break;
  1961. fi;
  1962. else
  1963. PATCH_TARGET=${x};
  1964. fi;
  1965. local abs_paths=$(egrep -n '^[-+]{3} /' "${PATCH_TARGET}" | awk '$2 != "/dev/null" { print }');
  1966. if [[ -n ${abs_paths} ]]; then
  1967. count=1;
  1968. printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}";
  1969. fi;
  1970. local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}");
  1971. if [[ -n ${rel_paths} ]]; then
  1972. eqawarn "QA Notice: Your patch uses relative paths '../'.";
  1973. eqawarn " In the future this will cause a failure.";
  1974. eqawarn "${rel_paths}";
  1975. fi;
  1976. while [[ ${count} -lt 5 ]]; do
  1977. ( _epatch_draw_line "***** ${patchname} *****";
  1978. echo;
  1979. echo "PATCH COMMAND: patch -p${count} ${EPATCH_OPTS} < '${PATCH_TARGET}'";
  1980. echo;
  1981. _epatch_draw_line "***** ${patchname} *****" ) >> "${STDERR_TARGET}";
  1982. if ( patch -p${count} ${EPATCH_OPTS} --dry-run -f < "${PATCH_TARGET}" ) >> "${STDERR_TARGET}" 2>&1; then
  1983. ( _epatch_draw_line "***** ${patchname} *****";
  1984. echo;
  1985. echo "ACTUALLY APPLYING ${patchname} ...";
  1986. echo;
  1987. _epatch_draw_line "***** ${patchname} *****";
  1988. patch -p${count} ${EPATCH_OPTS} < "${PATCH_TARGET}" 2>&1 ) >> "${STDERR_TARGET}";
  1989. if [ $? -ne 0 ]; then
  1990. echo;
  1991. eerror "A dry-run of patch command succeeded, but actually";
  1992. eerror "applying the patch failed!";
  1993. count=5;
  1994. fi;
  1995. break;
  1996. fi;
  1997. : $(( count++ ));
  1998. done;
  1999. if [[ -n ${PIPE_CMD} ]]; then
  2000. rm -f "${PATCH_TARGET}";
  2001. fi;
  2002. if [[ ${count} -ge 5 ]]; then
  2003. echo;
  2004. eerror "Failed Patch: ${patchname} !";
  2005. eerror " ( ${PATCH_TARGET} )";
  2006. eerror;
  2007. eerror "Include in your bugreport the contents of:";
  2008. eerror;
  2009. eerror " ${STDERR_TARGET}";
  2010. echo;
  2011. die "Failed Patch: ${patchname}!";
  2012. fi;
  2013. rm -f "${STDERR_TARGET}";
  2014. eend 0;
  2015. done;
  2016. [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching";
  2017. :
  2018. }
  2019. epatch_user ()
  2020. {
  2021. [[ $# -ne 0 ]] && die "epatch_user takes no options";
  2022. local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches;
  2023. for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}};
  2024. do
  2025. EPATCH_SOURCE=${base}/${CTARGET}/${check};
  2026. [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check};
  2027. [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check};
  2028. if [[ -d ${EPATCH_SOURCE} ]]; then
  2029. EPATCH_SOURCE=${EPATCH_SOURCE} EPATCH_SUFFIX="patch" EPATCH_FORCE="yes" EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." epatch;
  2030. return 0;
  2031. fi;
  2032. done;
  2033. return 1
  2034. }
  2035. epause ()
  2036. {
  2037. [[ -z ${EPAUSE_IGNORE} ]] && sleep ${1:-5}
  2038. }
  2039. epunt_cxx ()
  2040. {
  2041. local dir=$1;
  2042. [[ -z ${dir} ]] && dir=${S};
  2043. ebegin "Removing useless C++ checks";
  2044. local f;
  2045. find "${dir}" -name configure | while read f; do
  2046. patch --no-backup-if-mismatch -p0 "${f}" "${PORTDIR}/eclass/ELT-patches/nocxx/nocxx.patch" > /dev/null;
  2047. done;
  2048. eend 0
  2049. }
  2050. eshopts_pop ()
  2051. {
  2052. [[ $# -ne 0 ]] && die "eshopts_pop takes no arguments";
  2053. local i=$(( ${#__ESHOPTS_SAVE__[@]} - 1 ));
  2054. [[ ${i} -eq -1 ]] && die "eshopts_{push,pop}: unbalanced pair";
  2055. local s=${__ESHOPTS_SAVE__[$i]};
  2056. unset __ESHOPTS_SAVE__[$i];
  2057. if [[ ${s} == "shopt -"* ]]; then
  2058. eval "${s}" || die "eshopts_pop: sanity: invalid shopt options: ${s}";
  2059. else
  2060. set +$- || die "eshopts_pop: sanity: invalid shell settings: $-";
  2061. set -${s} || die "eshopts_pop: sanity: unable to restore saved shell settings: ${s}";
  2062. fi
  2063. }
  2064. eshopts_push ()
  2065. {
  2066. local i=${#__ESHOPTS_SAVE__[@]};
  2067. if [[ $1 == -[su] ]]; then
  2068. __ESHOPTS_SAVE__[$i]=$(shopt -p);
  2069. [[ $# -eq 0 ]] && return 0;
  2070. shopt "$@" || die "eshopts_push: bad options to shopt: $*";
  2071. else
  2072. __ESHOPTS_SAVE__[$i]=$-;
  2073. [[ $# -eq 0 ]] && return 0;
  2074. set "$@" || die "eshopts_push: bad options to set: $*";
  2075. fi
  2076. }
  2077. esvn_clean ()
  2078. {
  2079. [[ -z $* ]] && set -- .;
  2080. find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf
  2081. }
  2082. exclude_gcc_patches ()
  2083. {
  2084. local i;
  2085. for i in ${GENTOO_PATCH_EXCLUDE};
  2086. do
  2087. if [[ -f ${WORKDIR}/patch/${i} ]]; then
  2088. einfo "Excluding patch ${i}";
  2089. rm -f "${WORKDIR}"/patch/${i} || die "failed to delete ${i}";
  2090. fi;
  2091. done;
  2092. for i in ${PIEPATCH_EXCLUDE};
  2093. do
  2094. if [[ -f ${WORKDIR}/piepatch/${i} ]]; then
  2095. einfo "Excluding piepatch ${i}";
  2096. rm -f "${WORKDIR}"/piepatch/${i} || die "failed to delete ${i}";
  2097. fi;
  2098. done
  2099. }
  2100. filter-flags ()
  2101. {
  2102. _filter-hardened "$@";
  2103. _filter-var CFLAGS "$@";
  2104. _filter-var CPPFLAGS "$@";
  2105. _filter-var CXXFLAGS "$@";
  2106. _filter-var FFLAGS "$@";
  2107. _filter-var FCFLAGS "$@";
  2108. return 0
  2109. }
  2110. filter-ldflags ()
  2111. {
  2112. _filter-var LDFLAGS "$@";
  2113. return 0
  2114. }
  2115. filter-lfs-flags ()
  2116. {
  2117. [[ -n $@ ]] && die "filter-lfs-flags takes no arguments";
  2118. filter-flags -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
  2119. }
  2120. filter-mfpmath ()
  2121. {
  2122. local orig_mfpmath new_math prune_math;
  2123. orig_mfpmath=$(get-flag -mfpmath);
  2124. new_math=$(get-flag mfpmath);
  2125. new_math=" ${new_math//,/ } ";
  2126. prune_math="";
  2127. for prune_math in "$@";
  2128. do
  2129. new_math=${new_math/ ${prune_math} / };
  2130. done;
  2131. new_math=$(echo ${new_math});
  2132. new_math=${new_math// /,};
  2133. if [[ -z ${new_math} ]]; then
  2134. filter-flags ${orig_mfpmath};
  2135. else
  2136. replace-flags ${orig_mfpmath} -mfpmath=${new_math};
  2137. fi;
  2138. return 0
  2139. }
  2140. find_unpackable_file ()
  2141. {
  2142. local src=$1;
  2143. if [[ -z ${src} ]]; then
  2144. src=${DISTDIR}/${A};
  2145. else
  2146. if [[ -e ${DISTDIR}/${src} ]]; then
  2147. src=${DISTDIR}/${src};
  2148. else
  2149. if [[ -e ${PWD}/${src} ]]; then
  2150. src=${PWD}/${src};
  2151. else
  2152. if [[ -e ${src} ]]; then
  2153. src=${src};
  2154. fi;
  2155. fi;
  2156. fi;
  2157. fi;
  2158. [[ ! -e ${src} ]] && return 1;
  2159. echo "${src}"
  2160. }
  2161. fix_libtool_libdir_paths ()
  2162. {
  2163. pushd "${D}" > /dev/null;
  2164. pushd "./${1}" > /dev/null;
  2165. local dir="${PWD#${D%/}}";
  2166. local allarchives=$(echo *.la);
  2167. allarchives="\(${allarchives// /\\|}\)";
  2168. popd > /dev/null;
  2169. sed -i -e "/^libdir=/s:=.*:='${dir}':" ./${dir}/*.la;
  2170. sed -i -e "/^dependency_libs=/s:/[^ ]*/${allarchives}:${LIBPATH}/\1:g" $(find ./${PREFIX}/lib* -maxdepth 3 -name '*.la') ./${dir}/*.la;
  2171. popd > /dev/null
  2172. }
  2173. gcc-compiler-configure ()
  2174. {
  2175. if is_multilib; then
  2176. confgcc="${confgcc} --enable-multilib";
  2177. else
  2178. confgcc="${confgcc} --disable-multilib";
  2179. fi;
  2180. if tc_version_is_at_least "4.0"; then
  2181. if has mudflap ${IUSE}; then
  2182. confgcc="${confgcc} $(use_enable mudflap libmudflap)";
  2183. else
  2184. confgcc="${confgcc} --disable-libmudflap";
  2185. fi;
  2186. if want_libssp; then
  2187. confgcc="${confgcc} --enable-libssp";
  2188. else
  2189. export gcc_cv_libc_provides_ssp=yes;
  2190. confgcc="${confgcc} --disable-libssp";
  2191. fi;
  2192. if tc_version_is_at_least 4.4 && want_minispecs; then
  2193. confgcc="${confgcc} $(use_enable hardened esp)";
  2194. fi;
  2195. if tc_version_is_at_least "4.2"; then
  2196. if has openmp ${IUSE}; then
  2197. if ! is_crosscompile || $(tc-getCPP ${CTARGET}) -E - <<< "#include <pthread.h>" &>/dev/null; then
  2198. confgcc="${confgcc} $(use_enable openmp libgomp)";
  2199. else
  2200. confgcc="${confgcc} --disable-libgomp";
  2201. fi;
  2202. else
  2203. confgcc="${confgcc} --disable-libgomp";
  2204. fi;
  2205. fi;
  2206. if tc_version_is_at_least "4.3"; then
  2207. if ! has ${ARCH} ${KEYWORDS}; then
  2208. confgcc="${confgcc} --enable-cld";
  2209. fi;
  2210. fi;
  2211. if tc_version_is_at_least "4.4"; then
  2212. confgcc="${confgcc} --with-python-dir=${DATAPATH/$PREFIX/}/python";
  2213. fi;
  2214. fi;
  2215. if tc_version_is_at_least 4 || [[ -n ${GCC_CHECKS_LIST} ]]; then
  2216. confgcc="${confgcc} --enable-checking=${GCC_CHECKS_LIST:-release}";
  2217. else
  2218. confgcc="${confgcc} --disable-checking";
  2219. fi;
  2220. if ! is_gcj; then
  2221. confgcc="${confgcc} --disable-libgcj";
  2222. else
  2223. if use gtk; then
  2224. confgcc="${confgcc} --enable-java-awt=gtk";
  2225. fi;
  2226. fi;
  2227. case $(tc-arch) in
  2228. arm)
  2229. local arm_arch="${CTARGET%%-*}";
  2230. if [[ ${arm_arch} == armv* ]]; then
  2231. [[ ${arm_arch} == armv7? ]] && arm_arch=${arm_arch/7/7-};
  2232. [[ ${arm_arch} == *l ]] && arm_arch=${arm_arch%l};
  2233. [[ ${arm_arch} == *eb ]] && arm_arch=${arm_arch%eb};
  2234. confgcc="${confgcc} --with-arch=${arm_arch}";
  2235. fi;
  2236. if [[ ${CTARGET##*-} == *eabi ]] && [[ $(tc-is-hardfloat) == yes ]] && tc_version_is_at_least "4.5"; then
  2237. confgcc="${confgcc} --with-float=hard";
  2238. fi
  2239. ;;
  2240. mips)
  2241. local mips_abi="";
  2242. [[ ${DEFAULT_ABI} == n64 ]] && mips_abi="--with-abi=64";
  2243. [[ ${DEFAULT_ABI} == n32 ]] && mips_abi="--with-abi=n32";
  2244. [[ -n ${mips_abi} ]] && confgcc="${confgcc} ${mips_abi}"
  2245. ;;
  2246. x86)
  2247. confgcc="${confgcc} --with-arch=${CTARGET%%-*}"
  2248. ;;
  2249. hppa)
  2250. [[ ${GCCMAJOR} == "3" ]] && confgcc="${confgcc} --enable-sjlj-exceptions"
  2251. ;;
  2252. ppc)
  2253. is-flagq -mfloat-gprs=double && confgcc+=" --enable-e500-double";
  2254. [[ ${CTARGET//_/-} == *-e500v2-* ]] && confgcc+=" --enable-e500-double"
  2255. ;;
  2256. esac;
  2257. GCC_LANG="c";
  2258. is_cxx && GCC_LANG="${GCC_LANG},c++";
  2259. is_d && GCC_LANG="${GCC_LANG},d";
  2260. is_gcj && GCC_LANG="${GCC_LANG},java";
  2261. is_go && GCC_LANG="${GCC_LANG},go";
  2262. if is_objc || is_objcxx; then
  2263. GCC_LANG="${GCC_LANG},objc";
  2264. if tc_version_is_at_least "4.0"; then
  2265. use objc-gc && confgcc="${confgcc} --enable-objc-gc";
  2266. fi;
  2267. is_objcxx && GCC_LANG="${GCC_LANG},obj-c++";
  2268. fi;
  2269. is_treelang && GCC_LANG="${GCC_LANG},treelang";
  2270. is_fortran && GCC_LANG="${GCC_LANG},fortran";
  2271. is_f77 && GCC_LANG="${GCC_LANG},f77";
  2272. is_f95 && GCC_LANG="${GCC_LANG},f95";
  2273. einfo "configuring for GCC_LANG: ${GCC_LANG}"
  2274. }
  2275. gcc-compiler_pkg_postinst ()
  2276. {
  2277. do_gcc_config;
  2278. if ! is_crosscompile; then
  2279. echo;
  2280. ewarn "If you have issues with packages unable to locate libstdc++.la,";
  2281. ewarn "then try running 'fix_libtool_files.sh' on the old gcc versions.";
  2282. echo;
  2283. ewarn "You might want to review the GCC upgrade guide when moving between";
  2284. ewarn "major versions (like 4.2 to 4.3):";
  2285. ewarn "http://www.gentoo.org/doc/en/gcc-upgrading.xml";
  2286. echo;
  2287. fi;
  2288. if ! has_version '>=sys-devel/gcc-config-1.3.10-r1' && [[ ${GCC_CONFIG_VER/-/} != ${GCC_CONFIG_VER} ]]; then
  2289. ewarn "Your version of gcc-config will issue about having an invalid profile";
  2290. ewarn "when switching to this profile. It is safe to ignore this warning,";
  2291. ewarn "and this problem has been corrected in >=sys-devel/gcc-config-1.3.10-r1.";
  2292. fi;
  2293. if ! is_crosscompile && ! use multislot && [[ ${GCCMAJOR}.${GCCMINOR} == 3.4 ]]; then
  2294. echo;
  2295. ewarn "You should make sure to rebuild all your C++ packages when";
  2296. ewarn "upgrading between different versions of gcc. For example,";
  2297. ewarn "when moving to gcc-3.4 from gcc-3.3, emerge gentoolkit and run:";
  2298. ewarn " # revdep-rebuild --library libstdc++.so.5";
  2299. echo;
  2300. fi;
  2301. if ! is_crosscompile; then
  2302. [[ ! -d ${ROOT}/$(get_libdir)/rcscripts/awk ]] && mkdir -p "${ROOT}"/$(get_libdir)/rcscripts/awk;
  2303. [[ ! -d ${ROOT}/sbin ]] && mkdir -p "${ROOT}"/sbin;
  2304. cp "${ROOT}/${DATAPATH}"/fixlafiles.awk "${ROOT}"/$(get_libdir)/rcscripts/awk/ || die "installing fixlafiles.awk";
  2305. cp "${ROOT}/${DATAPATH}"/fix_libtool_files.sh "${ROOT}"/sbin/ || die "installing fix_libtool_files.sh";
  2306. [[ ! -d ${ROOT}/usr/bin ]] && mkdir -p "${ROOT}"/usr/bin;
  2307. for x in "${ROOT}/${DATAPATH}"/c{89,99};
  2308. do
  2309. if [[ -e ${x} ]]; then
  2310. cp ${x} "${ROOT}"/usr/bin/ || die "installing c89/c99";
  2311. fi;
  2312. done;
  2313. fi
  2314. }
  2315. gcc-compiler_pkg_postrm ()
  2316. {
  2317. if is_crosscompile; then
  2318. if [[ -z $(ls "${ROOT}"/etc/env.d/gcc/${CTARGET}* 2>/dev/null) ]]; then
  2319. rm -f "${ROOT}"/etc/env.d/gcc/config-${CTARGET};
  2320. rm -f "${ROOT}"/etc/env.d/??gcc-${CTARGET};
  2321. rm -f "${ROOT}"/usr/bin/${CTARGET}-{gcc,{g,c}++}{,32,64};
  2322. fi;
  2323. return 0;
  2324. fi;
  2325. [[ ${ROOT} != "/" ]] && return 0;
  2326. if [[ ! -e ${LIBPATH}/libstdc++.so ]]; then
  2327. do_gcc_config;
  2328. einfo "Running 'fix_libtool_files.sh ${GCC_RELEASE_VER}'";
  2329. /sbin/fix_libtool_files.sh ${GCC_RELEASE_VER};
  2330. if [[ -n ${BRANCH_UPDATE} ]]; then
  2331. einfo "Running 'fix_libtool_files.sh ${GCC_RELEASE_VER}-${BRANCH_UPDATE}'";
  2332. /sbin/fix_libtool_files.sh ${GCC_RELEASE_VER}-${BRANCH_UPDATE};
  2333. fi;
  2334. fi;
  2335. return 0
  2336. }
  2337. gcc-compiler_pkg_preinst ()
  2338. {
  2339. :
  2340. }
  2341. gcc-compiler_pkg_prerm ()
  2342. {
  2343. touch -c "${ROOT}"/sbin/fix_libtool_files.sh "${ROOT}"/$(get_libdir)/rcscripts/awk/fixlafiles.awk
  2344. }
  2345. gcc-compiler_src_install ()
  2346. {
  2347. local x=;
  2348. cd "${WORKDIR}"/build;
  2349. find gcc/include*/ -type l -print0 | xargs -0 rm -f;
  2350. for x in $(find gcc/include*/ -name '*.h');
  2351. do
  2352. grep -q 'It has been auto-edited by fixincludes from' "${x}" && rm -f "${x}";
  2353. done;
  2354. S=${WORKDIR}/build emake -j1 DESTDIR="${D}" install || die;
  2355. find "${D}" -name install-tools -prune -type d -exec rm -rf "{}" \;;
  2356. find "${D}" -name libiberty.a -exec rm -f "{}" \;;
  2357. gcc_movelibs;
  2358. if ! is_crosscompile; then
  2359. local EXEEXT;
  2360. eval $(grep ^EXEEXT= "${WORKDIR}"/build/gcc/config.log);
  2361. [[ -r ${D}${BINPATH}/gcc${EXEEXT} ]] || die "gcc not found in ${D}";
  2362. fi;
  2363. dodir /etc/env.d/gcc;
  2364. create_gcc_env_entry;
  2365. if want_split_specs; then
  2366. if use hardened; then
  2367. create_gcc_env_entry vanilla;
  2368. fi;
  2369. ! use hardened && hardened_gcc_works && create_gcc_env_entry hardened;
  2370. if hardened_gcc_works || hardened_gcc_works pie; then
  2371. create_gcc_env_entry hardenednossp;
  2372. fi;
  2373. if hardened_gcc_works || hardened_gcc_works ssp; then
  2374. create_gcc_env_entry hardenednopie;
  2375. fi;
  2376. create_gcc_env_entry hardenednopiessp;
  2377. insinto ${LIBPATH};
  2378. doins "${WORKDIR}"/build/*.specs || die "failed to install specs";
  2379. fi;
  2380. if want_minispecs; then
  2381. copy_minispecs_gcc_specs;
  2382. fi;
  2383. gcc_slot_java;
  2384. [[ -f ${D}${STDCXX_INCDIR}/cxxabi.h ]] && mv -f "${D}"${STDCXX_INCDIR}/cxxabi.h "${D}"${LIBPATH}/include/;
  2385. dodir /usr/bin;
  2386. cd "${D}"${BINPATH};
  2387. for x in cpp gcc g++ c++ g77 gcj gcjh gfortran gccgo;
  2388. do
  2389. [[ -f ${x} ]] && mv ${x} ${CTARGET}-${x};
  2390. if [[ -f ${CTARGET}-${x} ]] && ! is_crosscompile; then
  2391. ln -sf ${CTARGET}-${x} ${x};
  2392. dosym ${BINPATH}/${CTARGET}-${x} /usr/bin/${CTARGET}-${x}-${GCC_CONFIG_VER};
  2393. dosym ${BINPATH}/${CTARGET}-${x} /usr/bin/${x}-${GCC_CONFIG_VER};
  2394. fi;
  2395. if [[ -f ${CTARGET}-${x}-${GCC_CONFIG_VER} ]]; then
  2396. rm -f ${CTARGET}-${x}-${GCC_CONFIG_VER};
  2397. ln -sf ${CTARGET}-${x} ${CTARGET}-${x}-${GCC_CONFIG_VER};
  2398. fi;
  2399. done;
  2400. if [[ -d ${D}${LIBPATH}/include/libffi ]]; then
  2401. mv -i "${D}"${LIBPATH}/include/libffi/* "${D}"${LIBPATH}/include || die;
  2402. rm -r "${D}"${LIBPATH}/include/libffi || die;
  2403. fi;
  2404. env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${BINPATH}";
  2405. env RESTRICT="" CHOST=${CTARGET} prepstrip "${D}${LIBPATH}";
  2406. [[ -d ${D}${PREFIX}/libexec/gcc ]] && env RESTRICT="" CHOST=${CHOST} prepstrip "${D}${PREFIX}/libexec/gcc/${CTARGET}/${GCC_CONFIG_VER}";
  2407. cd "${S}";
  2408. if is_crosscompile; then
  2409. rm -rf "${D}"/usr/share/{man,info};
  2410. rm -rf "${D}"${DATAPATH}/{man,info};
  2411. else
  2412. local cxx_mandir=${WORKDIR}/build/${CTARGET}/libstdc++-v3/docs/doxygen/man;
  2413. if [[ -d ${cxx_mandir} ]]; then
  2414. find "${cxx_mandir}" -name '*_build_*' -exec rm {} \;;
  2415. cp -r "${cxx_mandir}"/man? "${D}/${DATAPATH}"/man/;
  2416. fi;
  2417. has noinfo ${FEATURES} && rm -r "${D}/${DATAPATH}"/info || prepinfo "${DATAPATH}";
  2418. has noman ${FEATURES} && rm -r "${D}/${DATAPATH}"/man || prepman "${DATAPATH}";
  2419. fi;
  2420. for x in 1 2 3 4;
  2421. do
  2422. find "${D}" -type d -exec rmdir "{}" \; &>/dev/null;
  2423. done;
  2424. if use test; then
  2425. docinto testsuite;
  2426. find "${WORKDIR}"/build -type f -name "*.sum" -print0 | xargs -0 dodoc;
  2427. find "${WORKDIR}"/build -type f -path "*/testsuite/*.log" -print0 | xargs -0 dodoc;
  2428. fi;
  2429. if ! is_crosscompile; then
  2430. insinto "${DATAPATH}";
  2431. if tc_version_is_at_least 4.0; then
  2432. newins "${GCC_FILESDIR}"/awk/fixlafiles.awk-no_gcc_la fixlafiles.awk || die;
  2433. find "${D}/${LIBPATH}" -name libstdc++.la -type f -exec rm "{}" \;;
  2434. else
  2435. doins "${GCC_FILESDIR}"/awk/fixlafiles.awk || die;
  2436. fi;
  2437. exeinto "${DATAPATH}";
  2438. doexe "${GCC_FILESDIR}"/fix_libtool_files.sh || die;
  2439. doexe "${GCC_FILESDIR}"/c{89,99} || die;
  2440. fi;
  2441. chown -R root:0 "${D}"${LIBPATH};
  2442. gdbdir=/usr/share/gdb/auto-load${LIBPATH/\/lib\//\/$(get_libdir)\/};
  2443. for i in "${D}"${LIBPATH}{,/32}/*-gdb.py;
  2444. do
  2445. if [[ -e ${i} ]]; then
  2446. basedir="$(dirname ${i/${D}${LIBPATH}/})";
  2447. sed -i -e "s:^\(libdir = \).*:\1'${LIBPATH}${basedir}':" "${i}";
  2448. insinto "${gdbdir}${basedir}";
  2449. doins "${i}";
  2450. rm "${i}";
  2451. fi;
  2452. done;
  2453. export QA_EXECSTACK="usr/lib*/go/*/*.gox";
  2454. export QA_WX_LOAD="usr/lib*/go/*/*.gox"
  2455. }
  2456. gcc-compiler_src_unpack ()
  2457. {
  2458. want_pie && use hardened && glibc_have_pie;
  2459. if use hardened; then
  2460. einfo "updating configuration to build hardened GCC";
  2461. make_gcc_hard || die "failed to make gcc hard";
  2462. fi;
  2463. if is_libffi; then
  2464. sed -i -e '/^libgcj=/s:target-libffi::' -e '/^target_lib/s:=":="target-libffi :' "${S}"/configure || die;
  2465. fi
  2466. }
  2467. gcc-fullversion ()
  2468. {
  2469. _gcc_fullversion '$1.$2.$3' "$@"
  2470. }
  2471. gcc-lang-supported ()
  2472. {
  2473. grep ^language=\"${1}\" "${S}"/gcc/*/config-lang.in > /dev/null || return 1;
  2474. [[ -z ${TOOLCHAIN_ALLOWED_LANGS} ]] && return 0;
  2475. has $1 ${TOOLCHAIN_ALLOWED_LANGS}
  2476. }
  2477. gcc-library-configure ()
  2478. {
  2479. if is_multilib; then
  2480. confgcc="${confgcc} --enable-multilib";
  2481. else
  2482. confgcc="${confgcc} --disable-multilib";
  2483. fi
  2484. }
  2485. gcc-library_src_install ()
  2486. {
  2487. cd "${WORKDIR}"/build;
  2488. S=${WORKDIR}/build emake -j1 DESTDIR="${D}" prefix=${PREFIX} bindir=${BINPATH} includedir=${LIBPATH}/include datadir=${DATAPATH} mandir=${DATAPATH}/man infodir=${DATAPATH}/info LIBPATH="${LIBPATH}" ${GCC_INSTALL_TARGET} || die;
  2489. if [[ ${GCC_LIB_COMPAT_ONLY} == "true" ]]; then
  2490. rm -rf "${D}"${INCLUDEPATH};
  2491. rm -rf "${D}"${DATAPATH};
  2492. pushd "${D}"${LIBPATH}/;
  2493. rm *.a *.la *.so;
  2494. popd;
  2495. fi;
  2496. if [[ -n ${GCC_LIB_USE_SUBDIR} ]]; then
  2497. mkdir -p "${WORKDIR}"/${GCC_LIB_USE_SUBDIR}/;
  2498. mv "${D}"${LIBPATH}/* "${WORKDIR}"/${GCC_LIB_USE_SUBDIR}/;
  2499. mv "${WORKDIR}"/${GCC_LIB_USE_SUBDIR}/ "${D}"${LIBPATH};
  2500. dodir /etc/env.d;
  2501. echo "LDPATH=\"${LIBPATH}/${GCC_LIB_USE_SUBDIR}/\"" >> "${D}"/etc/env.d/99${PN};
  2502. fi;
  2503. if [[ ${GCC_VAR_TYPE} == "non-versioned" ]]; then
  2504. add_version_to_shared;
  2505. fi
  2506. }
  2507. gcc-library_src_unpack ()
  2508. {
  2509. :
  2510. }
  2511. gcc-major-version ()
  2512. {
  2513. _gcc_fullversion '$1' "$@"
  2514. }
  2515. gcc-micro-version ()
  2516. {
  2517. _gcc_fullversion '$3' "$@"
  2518. }
  2519. gcc-minor-version ()
  2520. {
  2521. _gcc_fullversion '$2' "$@"
  2522. }
  2523. gcc-specs-directive ()
  2524. {
  2525. local directive subdname subdirective;
  2526. directive="$(_gcc-specs-directive_raw $1)";
  2527. while [[ ${directive} == *%\(*\)* ]]; do
  2528. subdname=${directive/*%\(};
  2529. subdname=${subdname/\)*};
  2530. subdirective="$(_gcc-specs-directive_raw ${subdname})";
  2531. directive="${directive//\%(${subdname})/${subdirective}}";
  2532. done;
  2533. echo "${directive}";
  2534. return 0
  2535. }
  2536. gcc-specs-nostrict ()
  2537. {
  2538. local directive;
  2539. directive=$(gcc-specs-directive cc1);
  2540. return $([[ "${directive/\{!fstrict-overflow:}" != "${directive}" ]])
  2541. }
  2542. gcc-specs-now ()
  2543. {
  2544. local directive;
  2545. directive=$(gcc-specs-directive link_command);
  2546. return $([[ "${directive/\{!nonow:}" != "${directive}" ]])
  2547. }
  2548. gcc-specs-pie ()
  2549. {
  2550. local directive;
  2551. directive=$(gcc-specs-directive cc1);
  2552. return $([[ "${directive/\{!nopie:}" != "${directive}" ]])
  2553. }
  2554. gcc-specs-relro ()
  2555. {
  2556. local directive;
  2557. directive=$(gcc-specs-directive link_command);
  2558. return $([[ "${directive/\{!norelro:}" != "${directive}" ]])
  2559. }
  2560. gcc-specs-ssp ()
  2561. {
  2562. local directive;
  2563. directive=$(gcc-specs-directive cc1);
  2564. return $([[ "${directive/\{!fno-stack-protector:}" != "${directive}" ]])
  2565. }
  2566. gcc-specs-ssp-to-all ()
  2567. {
  2568. local directive;
  2569. directive=$(gcc-specs-directive cc1);
  2570. return $([[ "${directive/\{!fno-stack-protector-all:}" != "${directive}" ]])
  2571. }
  2572. gcc-version ()
  2573. {
  2574. _gcc_fullversion '$1.$2' "$@"
  2575. }
  2576. gcc_do_configure ()
  2577. {
  2578. local confgcc;
  2579. confgcc="${confgcc} --prefix=${PREFIX} --bindir=${BINPATH} --includedir=${INCLUDEPATH} --datadir=${DATAPATH} --mandir=${DATAPATH}/man --infodir=${DATAPATH}/info --with-gxx-include-dir=${STDCXX_INCDIR}";
  2580. [[ ${CTARGET} == *-darwin* ]] && confgcc="${confgcc} --enable-version-specific-runtime-libs";
  2581. confgcc="${confgcc} --host=${CHOST}";
  2582. if is_crosscompile || tc-is-cross-compiler; then
  2583. confgcc="${confgcc} --target=${CTARGET}";
  2584. fi;
  2585. [[ -n ${CBUILD} ]] && confgcc="${confgcc} --build=${CBUILD}";
  2586. confgcc="${confgcc} $(use_enable altivec)";
  2587. tc_version_is_at_least "4.3" && confgcc="${confgcc} $(use_enable fixed-point)";
  2588. if tc_version_is_at_least "4.4"; then
  2589. confgcc="${confgcc} $(use_with graphite ppl)";
  2590. confgcc="${confgcc} $(use_with graphite cloog)";
  2591. if use graphite; then
  2592. confgcc="${confgcc} --disable-ppl-version-check";
  2593. if has_version '>=dev-libs/cloog-ppl-0.15.10'; then
  2594. confgcc="${confgcc} --with-cloog-include=/usr/include/cloog-ppl";
  2595. else
  2596. confgcc="${confgcc} --with-cloog-include=/usr/include/cloog";
  2597. fi;
  2598. fi;
  2599. fi;
  2600. [[ ${GCC_BRANCH_VER} == 4.5 ]] && confgcc="${confgcc} $(use_enable lto)";
  2601. [[ ${GCC_BRANCH_VER} > 4.5 ]] && confgcc="${confgcc} --enable-lto";
  2602. [[ $(tc-is-softfloat) == "yes" ]] && confgcc="${confgcc} --with-float=soft";
  2603. [[ $(tc-is-hardfloat) == "yes" ]] && confgcc="${confgcc} --with-float=hard";
  2604. if use nls; then
  2605. confgcc="${confgcc} --enable-nls --without-included-gettext";
  2606. else
  2607. confgcc="${confgcc} --disable-nls";
  2608. fi;
  2609. confgcc="${confgcc} --with-system-zlib --disable-werror --enable-secureplt";
  2610. einfo "running ${ETYPE}-configure";
  2611. ${ETYPE}-configure || die;
  2612. GCC_LANG=${GCC_LANG:-c};
  2613. confgcc="${confgcc} --enable-languages=${GCC_LANG}";
  2614. if is_crosscompile; then
  2615. local needed_libc="";
  2616. case ${CTARGET} in
  2617. *-linux)
  2618. needed_libc=no-fucking-clue
  2619. ;;
  2620. *-dietlibc)
  2621. needed_libc=dietlibc
  2622. ;;
  2623. *-elf | *-eabi)
  2624. needed_libc=newlib
  2625. ;;
  2626. *-freebsd*)
  2627. needed_libc=freebsd-lib
  2628. ;;
  2629. *-gnu*)
  2630. needed_libc=glibc
  2631. ;;
  2632. *-klibc)
  2633. needed_libc=klibc
  2634. ;;
  2635. *-uclibc*)
  2636. needed_libc=uclibc
  2637. ;;
  2638. *-cygwin)
  2639. needed_libc=cygwin
  2640. ;;
  2641. mingw* | *-mingw*)
  2642. needed_libc=mingw-runtime
  2643. ;;
  2644. avr)
  2645. confgcc="${confgcc} --enable-shared --disable-threads"
  2646. ;;
  2647. esac;
  2648. if [[ -n ${needed_libc} ]]; then
  2649. if ! has_version ${CATEGORY}/${needed_libc}; then
  2650. confgcc="${confgcc} --disable-shared --disable-threads --without-headers";
  2651. else
  2652. if built_with_use --hidden --missing false ${CATEGORY}/${needed_libc} crosscompile_opts_headers-only; then
  2653. confgcc="${confgcc} --disable-shared --with-sysroot=${PREFIX}/${CTARGET}";
  2654. else
  2655. confgcc="${confgcc} --with-sysroot=${PREFIX}/${CTARGET}";
  2656. fi;
  2657. fi;
  2658. fi;
  2659. if [[ ${GCCMAJOR}.${GCCMINOR} > 4.1 ]]; then
  2660. confgcc="${confgcc} --disable-bootstrap";
  2661. fi;
  2662. else
  2663. if tc-is-static-only; then
  2664. confgcc="${confgcc} --disable-shared";
  2665. else
  2666. confgcc="${confgcc} --enable-shared";
  2667. fi;
  2668. case ${CHOST} in
  2669. mingw* | *-mingw* | *-cygwin)
  2670. confgcc="${confgcc} --enable-threads=win32"
  2671. ;;
  2672. *)
  2673. confgcc="${confgcc} --enable-threads=posix"
  2674. ;;
  2675. esac;
  2676. fi;
  2677. case ${CTARGET} in
  2678. *-uclibc*)
  2679. confgcc="${confgcc} --disable-__cxa_atexit --enable-target-optspace $(use_enable nptl tls)";
  2680. [[ ${GCCMAJOR}.${GCCMINOR} == 3.3 ]] && confgcc="${confgcc} --enable-sjlj-exceptions";
  2681. if tc_version_is_at_least 3.4 && [[ ${GCCMAJOR}.${GCCMINOR} < 4.3 ]]; then
  2682. confgcc="${confgcc} --enable-clocale=uclibc";
  2683. fi
  2684. ;;
  2685. *-elf | *-eabi)
  2686. confgcc="${confgcc} --with-newlib"
  2687. ;;
  2688. *-gnu*)
  2689. confgcc="${confgcc} --enable-__cxa_atexit";
  2690. confgcc="${confgcc} --enable-clocale=gnu"
  2691. ;;
  2692. *-freebsd*)
  2693. confgcc="${confgcc} --enable-__cxa_atexit"
  2694. ;;
  2695. *-solaris*)
  2696. confgcc="${confgcc} --enable-__cxa_atexit"
  2697. ;;
  2698. esac;
  2699. [[ ${GCCMAJOR}.${GCCMINOR} < 3.4 ]] && confgcc="${confgcc} --disable-libunwind-exceptions";
  2700. if [[ ${CTARGET} == sparc*linux* ]] && is_multilib && ! is_crosscompile && [[ ${GCCMAJOR}.${GCCMINOR} > 4.2 ]]; then
  2701. confgcc="${confgcc} --enable-targets=all";
  2702. fi;
  2703. tc_version_is_at_least 4.3 && set -- "$@" --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion="${BRANDING_GCC_PKGVERSION}";
  2704. set -- ${confgcc} "$@" ${EXTRA_ECONF};
  2705. echo;
  2706. einfo "PREFIX: ${PREFIX}";
  2707. einfo "BINPATH: ${BINPATH}";
  2708. einfo "LIBPATH: ${LIBPATH}";
  2709. einfo "DATAPATH: ${DATAPATH}";
  2710. einfo "STDCXX_INCDIR: ${STDCXX_INCDIR}";
  2711. echo;
  2712. einfo "Configuring GCC with: ${@//--/\n\t--}";
  2713. echo;
  2714. mkdir -p "${WORKDIR}"/build;
  2715. pushd "${WORKDIR}"/build > /dev/null;
  2716. addwrite /dev/zero;
  2717. echo "${S}"/configure "$@";
  2718. "${S}"/configure "$@" || die "failed to run configure";
  2719. popd > /dev/null
  2720. }
  2721. gcc_do_filter_flags ()
  2722. {
  2723. strip-flags;
  2724. replace-flags -O? -O2;
  2725. strip-unsupported-flags;
  2726. filter-flags '-mabi*' -m31 -m32 -m64;
  2727. case ${GCC_BRANCH_VER} in
  2728. 3.2 | 3.3)
  2729. replace-cpu-flags k8 athlon64 opteron i686 x86-64;
  2730. replace-cpu-flags pentium-m pentium3m pentium3;
  2731. case $(tc-arch) in
  2732. amd64 | x86)
  2733. filter-flags '-mtune=*'
  2734. ;;
  2735. ppc64)
  2736. filter-flags "-mcpu=*"
  2737. ;;
  2738. esac;
  2739. case $(tc-arch) in
  2740. amd64)
  2741. replace-cpu-flags core2 nocona
  2742. ;;
  2743. x86)
  2744. replace-cpu-flags core2 prescott
  2745. ;;
  2746. esac;
  2747. replace-cpu-flags G3 750;
  2748. replace-cpu-flags G4 7400;
  2749. replace-cpu-flags G5 7400;
  2750. filter-flags -f{no-,}unit-at-a-time -f{no-,}web -mno-tls-direct-seg-refs;
  2751. filter-flags -f{no-,}stack-protector{,-all};
  2752. filter-flags -fvisibility-inlines-hidden -fvisibility=hidden
  2753. ;;
  2754. 3.4 | 4.*)
  2755. case $(tc-arch) in
  2756. x86 | amd64)
  2757. filter-flags '-mcpu=*'
  2758. ;;
  2759. *-macos)
  2760. [[ ${GCC_BRANCH_VER} == 4.0 || ${GCC_BRANCH_VER} == 4.1 ]] && filter-flags '-mcpu=*' '-march=*' '-mtune=*'
  2761. ;;
  2762. esac
  2763. ;;
  2764. esac;
  2765. if is_crosscompile; then
  2766. CFLAGS="-O2 -pipe";
  2767. local VAR="CFLAGS_"${CTARGET//-/_};
  2768. CXXFLAGS=${!VAR};
  2769. fi;
  2770. export GCJFLAGS=${GCJFLAGS:-${CFLAGS}}
  2771. }
  2772. gcc_do_make ()
  2773. {
  2774. local OLDS=${S};
  2775. S=${WORKDIR}/build;
  2776. [[ -n $1 ]] && GCC_MAKE_TARGET=$1;
  2777. if is_crosscompile || tc-is-cross-compiler; then
  2778. GCC_MAKE_TARGET=${GCC_MAKE_TARGET-all};
  2779. else
  2780. GCC_MAKE_TARGET=${GCC_MAKE_TARGET-bootstrap-lean};
  2781. fi;
  2782. [[ ${GCC_MAKE_TARGET} == "profiledbootstrap" ]] && export MAKEOPTS="${MAKEOPTS} -j1";
  2783. want_boundschecking && export MAKEOPTS="${MAKEOPTS} -j1";
  2784. if [[ ${GCC_MAKE_TARGET} == "all" ]]; then
  2785. STAGE1_CFLAGS=${STAGE1_CFLAGS-"${CFLAGS}"};
  2786. else
  2787. if [[ $(gcc-version) == "3.4" && ${GCC_BRANCH_VER} == "3.4" ]] && gcc-specs-ssp; then
  2788. STAGE1_CFLAGS=${STAGE1_CFLAGS-"-O2"};
  2789. fi;
  2790. fi;
  2791. if is_crosscompile; then
  2792. BOOT_CFLAGS=${BOOT_CFLAGS-"-O2"};
  2793. else
  2794. BOOT_CFLAGS=${BOOT_CFLAGS-"$(get_abi_CFLAGS) ${CFLAGS}"};
  2795. fi;
  2796. pushd "${WORKDIR}"/build;
  2797. emake LDFLAGS="${LDFLAGS}" STAGE1_CFLAGS="${STAGE1_CFLAGS}" LIBPATH="${LIBPATH}" BOOT_CFLAGS="${BOOT_CFLAGS}" ${GCC_MAKE_TARGET} || die "emake failed with ${GCC_MAKE_TARGET}";
  2798. if ! is_crosscompile && ! use nocxx && use doc; then
  2799. if type -p doxygen > /dev/null; then
  2800. if tc_version_is_at_least 4.3; then
  2801. cd "${CTARGET}"/libstdc++-v3/doc;
  2802. emake doc-man-doxygen || ewarn "failed to make docs";
  2803. else
  2804. if tc_version_is_at_least 3.0; then
  2805. cd "${CTARGET}"/libstdc++-v3;
  2806. emake doxygen-man || ewarn "failed to make docs";
  2807. fi;
  2808. fi;
  2809. else
  2810. ewarn "Skipping libstdc++ manpage generation since you don't have doxygen installed";
  2811. fi;
  2812. fi;
  2813. popd
  2814. }
  2815. gcc_get_s_dir ()
  2816. {
  2817. local GCC_S;
  2818. if [[ -n ${PRERELEASE} ]]; then
  2819. GCC_S=${WORKDIR}/gcc-${PRERELEASE};
  2820. else
  2821. if [[ -n ${SNAPSHOT} ]]; then
  2822. GCC_S=${WORKDIR}/gcc-${SNAPSHOT};
  2823. else
  2824. GCC_S=${WORKDIR}/gcc-${GCC_RELEASE_VER};
  2825. fi;
  2826. fi;
  2827. echo "${GCC_S}"
  2828. }
  2829. gcc_movelibs ()
  2830. {
  2831. tc_version_is_at_least 3.0 || return 0;
  2832. local multiarg removedirs="";
  2833. for multiarg in $($(XGCC) -print-multi-lib);
  2834. do
  2835. multiarg=${multiarg#*;};
  2836. multiarg=${multiarg//@/ -};
  2837. local OS_MULTIDIR=$($(XGCC) ${multiarg} --print-multi-os-directory);
  2838. local MULTIDIR=$($(XGCC) ${multiarg} --print-multi-directory);
  2839. local TODIR=${D}${LIBPATH}/${MULTIDIR};
  2840. local FROMDIR=;
  2841. [[ -d ${TODIR} ]] || mkdir -p ${TODIR};
  2842. for FROMDIR in ${LIBPATH}/${OS_MULTIDIR} ${LIBPATH}/../${MULTIDIR} ${PREFIX}/lib/${OS_MULTIDIR} ${PREFIX}/${CTARGET}/lib/${OS_MULTIDIR} ${PREFIX}/lib/${MULTIDIR};
  2843. do
  2844. removedirs="${removedirs} ${FROMDIR}";
  2845. FROMDIR=${D}${FROMDIR};
  2846. if [[ ${FROMDIR} != "${TODIR}" && -d ${FROMDIR} ]]; then
  2847. local files=$(find "${FROMDIR}" -maxdepth 1 ! -type d 2>/dev/null);
  2848. if [[ -n ${files} ]]; then
  2849. mv ${files} "${TODIR}";
  2850. fi;
  2851. fi;
  2852. done;
  2853. fix_libtool_libdir_paths "${LIBPATH}/${MULTIDIR}";
  2854. done;
  2855. for FROMDIR in ${removedirs};
  2856. do
  2857. rmdir "${D}"${FROMDIR} &>/dev/null;
  2858. done;
  2859. find "${D}" -type d | xargs rmdir &>/dev/null
  2860. }
  2861. gcc_pkg_setup ()
  2862. {
  2863. [[ -z ${ETYPE} ]] && die "Your ebuild needs to set the ETYPE variable";
  2864. if [[ ${ETYPE} == "gcc-compiler" ]]; then
  2865. if is_crosscompile; then
  2866. multilib_env ${CTARGET};
  2867. if ! is_multilib; then
  2868. MULTILIB_ABIS=${DEFAULT_ABI};
  2869. fi;
  2870. fi;
  2871. unset GCC_SPECS;
  2872. if use nocxx; then
  2873. use go && ewarn 'Go requires a C++ compiler, disabled due to USE="nocxx"';
  2874. use objc++ && ewarn 'Obj-C++ requires a C++ compiler, disabled due to USE="nocxx"';
  2875. use gcj && ewarn 'GCJ requires a C++ compiler, disabled due to USE="nocxx"';
  2876. fi;
  2877. fi;
  2878. want_libssp && libc_has_ssp && die "libssp cannot be used with a glibc that has been patched to provide ssp symbols";
  2879. want_minispecs;
  2880. unset LANGUAGES
  2881. }
  2882. gcc_quick_unpack ()
  2883. {
  2884. pushd "${WORKDIR}" > /dev/null;
  2885. export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}};
  2886. export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}};
  2887. export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}};
  2888. export PP_GCC_VER=${PP_GCC_VER:-${GCC_RELEASE_VER}};
  2889. export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}};
  2890. export SPECS_GCC_VER=${SPECS_GCC_VER:-${GCC_RELEASE_VER}};
  2891. if [[ -n ${GCC_A_FAKEIT} ]]; then
  2892. unpack ${GCC_A_FAKEIT};
  2893. else
  2894. if [[ -n ${PRERELEASE} ]]; then
  2895. unpack gcc-${PRERELEASE}.tar.bz2;
  2896. else
  2897. if [[ -n ${SNAPSHOT} ]]; then
  2898. unpack gcc-${SNAPSHOT}.tar.bz2;
  2899. else
  2900. unpack gcc-${GCC_RELEASE_VER}.tar.bz2;
  2901. if [[ -n ${BRANCH_UPDATE} ]]; then
  2902. pushd "${S}" > /dev/null;
  2903. epatch "${DISTDIR}"/gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2;
  2904. popd > /dev/null;
  2905. fi;
  2906. fi;
  2907. fi;
  2908. fi;
  2909. if [[ -n ${D_VER} ]] && use d; then
  2910. pushd "${S}"/gcc > /dev/null;
  2911. unpack gdc-${D_VER}-src.tar.bz2;
  2912. cd ..;
  2913. ebegin "Adding support for the D language";
  2914. ./gcc/d/setup-gcc.sh &>"${T}"/dgcc.log;
  2915. if ! eend $?; then
  2916. eerror "The D gcc package failed to apply";
  2917. eerror "Please include this log file when posting a bug report:";
  2918. eerror " ${T}/dgcc.log";
  2919. die "failed to include the D language";
  2920. fi;
  2921. popd > /dev/null;
  2922. fi;
  2923. [[ -n ${PATCH_VER} ]] && unpack gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2;
  2924. [[ -n ${UCLIBC_VER} ]] && unpack gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}.tar.bz2;
  2925. if want_ssp; then
  2926. if [[ -n ${PP_FVER} ]]; then
  2927. pushd "${S}" > /dev/null;
  2928. unpack protector-${PP_FVER}.tar.gz;
  2929. popd > /dev/null;
  2930. else
  2931. unpack gcc-${PP_GCC_VER}-ssp-${PP_VER}.tar.bz2;
  2932. fi;
  2933. fi;
  2934. if want_pie; then
  2935. if [[ -n ${PIE_CORE} ]]; then
  2936. unpack ${PIE_CORE};
  2937. else
  2938. unpack gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}.tar.bz2;
  2939. fi;
  2940. [[ -n ${SPECS_VER} ]] && unpack gcc-${SPECS_GCC_VER}-specs-${SPECS_VER}.tar.bz2;
  2941. fi;
  2942. want_boundschecking && unpack "bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2";
  2943. popd > /dev/null
  2944. }
  2945. gcc_slot_java ()
  2946. {
  2947. local x;
  2948. for x in "${D}"${PREFIX}/include/gc*.h "${D}"${PREFIX}/include/j*.h;
  2949. do
  2950. [[ -f ${x} ]] && mv -f "${x}" "${D}"${LIBPATH}/include/;
  2951. done;
  2952. for x in gcj gnu java javax org;
  2953. do
  2954. if [[ -d ${D}${PREFIX}/include/${x} ]]; then
  2955. dodir /${LIBPATH}/include/${x};
  2956. mv -f "${D}"${PREFIX}/include/${x}/* "${D}"${LIBPATH}/include/${x}/;
  2957. rm -rf "${D}"${PREFIX}/include/${x};
  2958. fi;
  2959. done;
  2960. if [[ -d ${D}${PREFIX}/lib/security ]] || [[ -d ${D}${PREFIX}/$(get_libdir)/security ]]; then
  2961. dodir /${LIBPATH}/security;
  2962. mv -f "${D}"${PREFIX}/lib*/security/* "${D}"${LIBPATH}/security;
  2963. rm -rf "${D}"${PREFIX}/lib*/security;
  2964. fi;
  2965. [[ -f ${D}${PREFIX}/lib/libgcj.spec ]] && mv -f "${D}"${PREFIX}/lib/libgcj.spec "${D}"${LIBPATH}/libgcj.spec;
  2966. local libgcj=$(find "${D}"${PREFIX}/lib/pkgconfig/ -name 'libgcj*.pc');
  2967. if [[ -n ${libgcj} ]]; then
  2968. sed -i "/^libdir=/s:=.*:=${LIBPATH}:" "${libgcj}";
  2969. mv "${libgcj}" "${D}"/usr/lib/pkgconfig/libgcj-${GCC_PV}.pc || die;
  2970. fi;
  2971. cd "${D}"${BINPATH};
  2972. [[ -f jar ]] && mv -f jar gcj-jar
  2973. }
  2974. gcc_src_compile ()
  2975. {
  2976. gcc_do_filter_flags;
  2977. einfo "CFLAGS=\"${CFLAGS}\"";
  2978. einfo "CXXFLAGS=\"${CXXFLAGS}\"";
  2979. if ! tc_version_is_at_least 4.4 && want_minispecs; then
  2980. setup_minispecs_gcc_build_specs;
  2981. fi;
  2982. mkdir -p "${WORKDIR}"/build;
  2983. pushd "${WORKDIR}"/build > /dev/null;
  2984. [[ ! -x /usr/bin/perl ]] && [[ -n ${MAN_VER} ]] && unpack gcc-${MAN_VER}-manpages.tar.bz2;
  2985. einfo "Configuring ${PN} ...";
  2986. gcc_do_configure;
  2987. touch "${S}"/gcc/c-gperf.h;
  2988. [[ ! -x /usr/bin/perl ]] && find "${WORKDIR}"/build -name '*.[17]' | xargs touch;
  2989. einfo "Compiling ${PN} ...";
  2990. gcc_do_make ${GCC_MAKE_TARGET};
  2991. if [[ ${ETYPE} == "gcc-compiler" ]] && want_split_specs && ! want_minispecs; then
  2992. split_out_specs_files || die "failed to split out specs";
  2993. fi;
  2994. popd > /dev/null
  2995. }
  2996. gcc_src_test ()
  2997. {
  2998. cd "${WORKDIR}"/build;
  2999. emake -k check || ewarn "check failed and that sucks :("
  3000. }
  3001. gcc_src_unpack ()
  3002. {
  3003. export BRANDING_GCC_PKGVERSION="Gentoo ${GCC_PVR}";
  3004. [[ -z ${UCLIBC_VER} ]] && [[ ${CTARGET} == *-uclibc* ]] && die "Sorry, this version does not support uClibc";
  3005. gcc_quick_unpack;
  3006. exclude_gcc_patches;
  3007. cd "${S}";
  3008. if ! use vanilla; then
  3009. if [[ -n ${PATCH_VER} ]]; then
  3010. guess_patch_type_in_dir "${WORKDIR}"/patch;
  3011. EPATCH_MULTI_MSG="Applying Gentoo patches ..." epatch "${WORKDIR}"/patch;
  3012. BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION} p${PATCH_VER}";
  3013. fi;
  3014. if [[ -n ${UCLIBC_VER} ]]; then
  3015. guess_patch_type_in_dir "${WORKDIR}"/uclibc;
  3016. EPATCH_MULTI_MSG="Applying uClibc patches ..." epatch "${WORKDIR}"/uclibc;
  3017. fi;
  3018. fi;
  3019. do_gcc_HTB_patches;
  3020. do_gcc_SSP_patches;
  3021. do_gcc_PIE_patches;
  3022. epatch_user;
  3023. ${ETYPE}_src_unpack || die "failed to ${ETYPE}_src_unpack";
  3024. if [[ ${GCCMAJOR}.${GCCMINOR} < 4.5 ]]; then
  3025. if ! is_crosscompile && ! use elibc_FreeBSD; then
  3026. sed -i -e '/^LANGUAGES =/s:$: proto:' "${S}"/gcc/Makefile.in;
  3027. fi;
  3028. fi;
  3029. if ! tc_version_is_at_least 4.3; then
  3030. fix_files="";
  3031. for x in contrib/test_summary libstdc++-v3/scripts/check_survey.in;
  3032. do
  3033. [[ -e ${x} ]] && fix_files="${fix_files} ${x}";
  3034. done;
  3035. ht_fix_file ${fix_files} */configure *.sh */Makefile.in;
  3036. fi;
  3037. setup_multilib_osdirnames;
  3038. gcc_version_patch;
  3039. if [[ ${GCCMAJOR}.${GCCMINOR} > 4.0 ]]; then
  3040. if [[ -n ${SNAPSHOT} || -n ${PRERELEASE} ]]; then
  3041. echo ${PV/_/-} > "${S}"/gcc/BASE-VER;
  3042. fi;
  3043. fi;
  3044. if [[ ${GCCMAJOR}.${GCCMINOR} > 4.2 ]] && use gcj; then
  3045. if tc_version_is_at_least "4.5"; then
  3046. einfo "Copying ecj-4.5.jar";
  3047. cp -pPR "${DISTDIR}/ecj-4.5.jar" "${S}/ecj.jar" || die;
  3048. else
  3049. if tc_version_is_at_least "4.3"; then
  3050. einfo "Copying ecj-4.3.jar";
  3051. cp -pPR "${DISTDIR}/ecj-4.3.jar" "${S}/ecj.jar" || die;
  3052. fi;
  3053. fi;
  3054. fi;
  3055. if ! tc_version_is_at_least 3.4.4; then
  3056. sed -i -e s/HAVE_LD_AS_NEEDED/USE_LD_AS_NEEDED/g "${S}"/gcc/config.in;
  3057. fi;
  3058. if [[ ${GCCMAJOR} == 3 ]] && [[ ${GCCMINOR} -ge 3 ]]; then
  3059. do_gcc_rename_java_bins;
  3060. fi;
  3061. cd "${S}";
  3062. elibtoolize --portage --shallow --no-uclibc;
  3063. gnuconfig_update;
  3064. local f;
  3065. einfo "Fixing misc issues in configure files";
  3066. tc_version_is_at_least 4.1 && epatch "${GCC_FILESDIR}"/gcc-configure-texinfo.patch;
  3067. for f in $(grep -l 'autoconf version 2.13' $(find "${S}" -name configure));
  3068. do
  3069. ebegin " Updating ${f/${S}\/} [LANG]";
  3070. patch "${f}" "${GCC_FILESDIR}"/gcc-configure-LANG.patch &>"${T}"/configure-patch.log || eerror "Please file a bug about this";
  3071. eend $?;
  3072. done;
  3073. sed -i 's|A-Za-z0-9|[:alnum:]|g' "${S}"/gcc/*.awk;
  3074. if [[ -x contrib/gcc_update ]]; then
  3075. einfo "Touching generated files";
  3076. ./contrib/gcc_update --touch | while read f; do
  3077. einfo " ${f%%...}";
  3078. done;
  3079. fi;
  3080. disable_multilib_libjava || die "failed to disable multilib java"
  3081. }
  3082. gcc_version_patch ()
  3083. {
  3084. tc_version_is_at_least 4.3 && return 0;
  3085. local version_string=${GCC_CONFIG_VER};
  3086. [[ -n ${BRANCH_UPDATE} ]] && version_string="${version_string} ${BRANCH_UPDATE}";
  3087. einfo "patching gcc version: ${version_string} (${BRANDING_GCC_PKGVERSION})";
  3088. if grep -qs VERSUFFIX "${S}"/gcc/version.c; then
  3089. sed -i -e "s~VERSUFFIX \"\"~VERSUFFIX \" (${BRANDING_GCC_PKGVERSION})\"~" "${S}"/gcc/version.c || die "failed to update VERSUFFIX with Gentoo branding";
  3090. else
  3091. version_string="${version_string} (${BRANDING_GCC_PKGVERSION})";
  3092. sed -i -e "s~\(const char version_string\[\] = \"\).*\(\".*\)~\1$version_string\2~" "${S}"/gcc/version.c || die "failed to update version.c with Gentoo branding.";
  3093. fi;
  3094. sed -i -e 's~gcc\.gnu\.org\/bugs\.html~bugs\.gentoo\.org\/~' "${S}"/gcc/version.c || die "Failed to change the bug URL"
  3095. }
  3096. gen_usr_ldscript ()
  3097. {
  3098. local lib libdir=$(get_libdir) output_format="" auto=false suffix=$(get_libname);
  3099. [[ -z ${ED+set} ]] && local ED=${D%/}${EPREFIX}/;
  3100. tc-is-static-only && return;
  3101. dodir /usr/${libdir};
  3102. if [[ $1 == "-a" ]]; then
  3103. auto=true;
  3104. shift;
  3105. dodir /${libdir};
  3106. fi;
  3107. output_format=$($(tc-getCC) ${CFLAGS} ${LDFLAGS} -Wl,--verbose 2>&1 | sed -n 's/^OUTPUT_FORMAT("\([^"]*\)",.*/\1/p');
  3108. [[ -n ${output_format} ]] && output_format="OUTPUT_FORMAT ( ${output_format} )";
  3109. for lib in "$@";
  3110. do
  3111. local tlib;
  3112. if ${auto}; then
  3113. lib="lib${lib}${suffix}";
  3114. else
  3115. [[ -r ${ED}/${libdir}/${lib} ]] || continue;
  3116. fi;
  3117. case ${CTARGET:-${CHOST}} in
  3118. *-darwin*)
  3119. if ${auto}; then
  3120. tlib=$(scanmacho -qF'%S#F' "${ED}"/usr/${libdir}/${lib});
  3121. else
  3122. tlib=$(scanmacho -qF'%S#F' "${ED}"/${libdir}/${lib});
  3123. fi;
  3124. [[ -z ${tlib} ]] && die "unable to read install_name from ${lib}";
  3125. tlib=${tlib##*/};
  3126. if ${auto}; then
  3127. mv "${ED}"/usr/${libdir}/${lib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die;
  3128. if [[ ${tlib} != ${lib%${suffix}}.*${suffix#.} ]]; then
  3129. mv "${ED}"/usr/${libdir}/${tlib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die;
  3130. fi;
  3131. rm -f "${ED}"/${libdir}/${lib};
  3132. fi;
  3133. if [[ ! -w "${ED}/${libdir}/${tlib}" ]]; then
  3134. chmod u+w "${ED}${libdir}/${tlib}";
  3135. local nowrite=yes;
  3136. fi;
  3137. install_name_tool -id "${EPREFIX}"/${libdir}/${tlib} "${ED}"/${libdir}/${tlib} || die "install_name_tool failed";
  3138. [[ -n ${nowrite} ]] && chmod u-w "${ED}${libdir}/${tlib}";
  3139. pushd "${ED}/usr/${libdir}" > /dev/null;
  3140. ln -snf "../../${libdir}/${tlib}" "${lib}";
  3141. popd > /dev/null
  3142. ;;
  3143. *-aix* | *-irix* | *64*-hpux* | *-interix* | *-winnt*)
  3144. if ${auto}; then
  3145. mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die;
  3146. tlib=$(readlink "${ED}"/${libdir}/${lib});
  3147. tlib=${tlib##*/};
  3148. if [[ -z ${tlib} ]]; then
  3149. tlib=${lib};
  3150. else
  3151. rm -f "${ED}"/${libdir}/${lib};
  3152. fi;
  3153. else
  3154. tlib=${lib};
  3155. fi;
  3156. pushd "${ED}/usr/${libdir}" > /dev/null;
  3157. ln -snf "../../${libdir}/${tlib}" "${lib}";
  3158. popd > /dev/null
  3159. ;;
  3160. hppa*-hpux*)
  3161. if ${auto}; then
  3162. tlib=$(chatr "${ED}"/usr/${libdir}/${lib} | sed -n '/internal name:/{n;s/^ *//;p;q}');
  3163. [[ -z ${tlib} ]] && tlib=${lib};
  3164. tlib=${tlib##*/};
  3165. mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die;
  3166. if [[ ${tlib} != ${lib}* ]]; then
  3167. mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die;
  3168. fi;
  3169. [[ ${tlib} != ${lib} ]] && rm -f "${ED}"/${libdir}/${lib};
  3170. else
  3171. tlib=$(chatr "${ED}"/${libdir}/${lib} | sed -n '/internal name:/{n;s/^ *//;p;q}');
  3172. [[ -z ${tlib} ]] && tlib=${lib};
  3173. tlib=${tlib##*/};
  3174. fi;
  3175. pushd "${ED}"/usr/${libdir} > /dev/null;
  3176. ln -snf "../../${libdir}/${tlib}" "${lib}";
  3177. [[ ${tlib} != ${lib} ]] && ln -snf "../../${libdir}/${tlib}" "${tlib}";
  3178. popd > /dev/null
  3179. ;;
  3180. *)
  3181. if ${auto}; then
  3182. tlib=$(scanelf -qF'%S#F' "${ED}"/usr/${libdir}/${lib});
  3183. [[ -z ${tlib} ]] && die "unable to read SONAME from ${lib}";
  3184. mv "${ED}"/usr/${libdir}/${lib}* "${ED}"/${libdir}/ || die;
  3185. if [[ ${tlib} != ${lib}* ]]; then
  3186. mv "${ED}"/usr/${libdir}/${tlib}* "${ED}"/${libdir}/ || die;
  3187. fi;
  3188. rm -f "${ED}"/${libdir}/${lib};
  3189. else
  3190. tlib=${lib};
  3191. fi;
  3192. cat > "${ED}/usr/${libdir}/${lib}" <<-END_LDSCRIPT
  3193. /* GNU ld script
  3194. Since Gentoo has critical dynamic libraries in /lib, and the static versions
  3195. in /usr/lib, we need to have a "fake" dynamic lib in /usr/lib, otherwise we
  3196. run into linking problems. This "fake" dynamic lib is a linker script that
  3197. redirects the linker to the real lib. And yes, this works in the cross-
  3198. compiling scenario as the sysroot-ed linker will prepend the real path.
  3199.  
  3200. See bug http://bugs.gentoo.org/4411 for more info.
  3201. */
  3202. ${output_format}
  3203. GROUP ( ${EPREFIX}/${libdir}/${tlib} )
  3204. END_LDSCRIPT
  3205.  
  3206. ;;
  3207. esac
  3208. fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${lib}";
  3209. done
  3210. }
  3211. gentoo_urls ()
  3212. {
  3213. local devspace="HTTP~lv/GCC/URI HTTP~eradicator/gcc/URI HTTP~vapier/dist/URI
  3214. HTTP~halcy0n/patches/URI HTTP~zorry/patches/gcc/URI HTTP~dirtyepic/dist/URI";
  3215. devspace=${devspace//HTTP/http:\/\/dev.gentoo.org\/};
  3216. echo mirror://gentoo/$1 ${devspace//URI/$1}
  3217. }
  3218. get-flag ()
  3219. {
  3220. local f findflag="$1";
  3221. for f in ${CFLAGS} ${CXXFLAGS} ${FFLAGS} ${FCFLAGS};
  3222. do
  3223. if [ "${f/${findflag}}" != "${f}" ]; then
  3224. printf "%s\n" "${f/-${findflag}=}";
  3225. return 0;
  3226. fi;
  3227. done;
  3228. return 1
  3229. }
  3230. get_abi_ASFLAGS ()
  3231. {
  3232. get_abi_var ASFLAGS "$@"
  3233. }
  3234. get_abi_CFLAGS ()
  3235. {
  3236. get_abi_var CFLAGS "$@"
  3237. }
  3238. get_abi_CHOST ()
  3239. {
  3240. get_abi_var CHOST "$@"
  3241. }
  3242. get_abi_CTARGET ()
  3243. {
  3244. get_abi_var CTARGET "$@"
  3245. }
  3246. get_abi_FAKE_TARGETS ()
  3247. {
  3248. get_abi_var FAKE_TARGETS "$@"
  3249. }
  3250. get_abi_LDFLAGS ()
  3251. {
  3252. get_abi_var LDFLAGS "$@"
  3253. }
  3254. get_abi_LIBDIR ()
  3255. {
  3256. get_abi_var LIBDIR "$@"
  3257. }
  3258. get_abi_var ()
  3259. {
  3260. local flag=$1;
  3261. local abi;
  3262. if [ $# -gt 1 ]; then
  3263. abi=${2};
  3264. else
  3265. if [ -n "${ABI}" ]; then
  3266. abi=${ABI};
  3267. else
  3268. if [ -n "${DEFAULT_ABI}" ]; then
  3269. abi=${DEFAULT_ABI};
  3270. else
  3271. abi="default";
  3272. fi;
  3273. fi;
  3274. fi;
  3275. local var="${flag}_${abi}";
  3276. echo ${!var}
  3277. }
  3278. get_after_major_version ()
  3279. {
  3280. eshopts_push -s extglob;
  3281. echo $(get_version_component_range 2- "${1:-${PV}}" );
  3282. eshopts_pop
  3283. }
  3284. get_all_abis ()
  3285. {
  3286. local order="";
  3287. if [[ -z ${MULTILIB_ABIS} ]]; then
  3288. echo "default";
  3289. return 0;
  3290. fi;
  3291. for x in ${MULTILIB_ABIS};
  3292. do
  3293. if [[ ${x} != ${DEFAULT_ABI} ]]; then
  3294. order="${order:+${order} }${x}";
  3295. fi;
  3296. done;
  3297. order="${order:+${order} }${DEFAULT_ABI}";
  3298. echo ${order};
  3299. return 0
  3300. }
  3301. get_all_libdirs ()
  3302. {
  3303. local libdirs;
  3304. local abi;
  3305. local dir;
  3306. for abi in ${MULTILIB_ABIS};
  3307. do
  3308. libdirs+=" $(get_abi_LIBDIR ${abi})";
  3309. done;
  3310. [[ " ${libdirs} " != *" lib "* ]] && libdirs+=" lib";
  3311. echo "${libdirs}"
  3312. }
  3313. get_all_version_components ()
  3314. {
  3315. eshopts_push -s extglob;
  3316. local ver_str=${1:-${PV}} result result_idx=0;
  3317. result=();
  3318. if [[ "${VERSIONATOR_CACHE_VER_STR}" == "${ver_str}" ]]; then
  3319. echo ${VERSIONATOR_CACHE_RESULT};
  3320. eshopts_pop;
  3321. return;
  3322. fi;
  3323. export VERSIONATOR_CACHE_VER_STR="${ver_str}";
  3324. while [[ -n "$ver_str" ]]; do
  3325. case "${ver_str:0:1}" in
  3326. [[:digit:]])
  3327. result[$result_idx]="${ver_str%%[^[:digit:]]*}";
  3328. ver_str="${ver_str##+([[:digit:]])}";
  3329. result_idx=$(($result_idx + 1))
  3330. ;;
  3331. [-_.])
  3332. result[$result_idx]="${ver_str:0:1}";
  3333. ver_str="${ver_str:1}";
  3334. result_idx=$(($result_idx + 1))
  3335. ;;
  3336. [[:alpha:]])
  3337. local not_match="${ver_str##+([[:alpha:]])*([[:digit:]])}";
  3338. result[$result_idx]=${ver_str:0:$((${#ver_str} - ${#not_match}))};
  3339. ver_str="${not_match}";
  3340. result_idx=$(($result_idx + 1))
  3341. ;;
  3342. *)
  3343. result[$result_idx]="${ver_str:0:1}";
  3344. ver_str="${ver_str:1}";
  3345. result_idx=$(($result_idx + 1))
  3346. ;;
  3347. esac;
  3348. done;
  3349. export VERSIONATOR_CACHE_RESULT="${result[@]}";
  3350. echo ${result[@]};
  3351. eshopts_pop
  3352. }
  3353. get_bmake ()
  3354. {
  3355. if [[ ${USERLAND} == *BSD ]]; then
  3356. echo make;
  3357. else
  3358. if [[ ${USERLAND} == "Darwin" ]]; then
  3359. echo bsdmake;
  3360. else
  3361. echo pmake;
  3362. fi;
  3363. fi
  3364. }
  3365. get_gcc_src_uri ()
  3366. {
  3367. export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}};
  3368. export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}};
  3369. export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}};
  3370. export PP_GCC_VER=${PP_GCC_VER:-${GCC_RELEASE_VER}};
  3371. export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}};
  3372. export SPECS_GCC_VER=${SPECS_GCC_VER:-${GCC_RELEASE_VER}};
  3373. if [[ -n ${PRERELEASE} ]]; then
  3374. GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/prerelease-${PRERELEASE}/gcc-${PRERELEASE}.tar.bz2";
  3375. else
  3376. if [[ -n ${SNAPSHOT} ]]; then
  3377. GCC_SRC_URI="ftp://sources.redhat.com/pub/gcc/snapshots/${SNAPSHOT}/gcc-${SNAPSHOT}.tar.bz2";
  3378. else
  3379. GCC_SRC_URI="mirror://gnu/gcc/gcc-${GCC_PV}/gcc-${GCC_RELEASE_VER}.tar.bz2";
  3380. [[ -n ${BRANCH_UPDATE} ]] && GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${GCC_RELEASE_VER}-branch-update-${BRANCH_UPDATE}.patch.bz2)";
  3381. fi;
  3382. fi;
  3383. if [[ -n ${PP_VER} ]]; then
  3384. if [[ -n ${PP_FVER} ]]; then
  3385. GCC_SRC_URI="${GCC_SRC_URI}
  3386. !nossp? (
  3387. http://www.research.ibm.com/trl/projects/security/ssp/gcc${PP_VER}/protector-${PP_FVER}.tar.gz
  3388. $(gentoo_urls protector-${PP_FVER}.tar.gz)
  3389. )";
  3390. else
  3391. GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${PP_GCC_VER}-ssp-${PP_VER}.tar.bz2)";
  3392. fi;
  3393. fi;
  3394. [[ -n ${UCLIBC_VER} ]] && GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}.tar.bz2)";
  3395. [[ -n ${MAN_VER} ]] && GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${MAN_VER}-manpages.tar.bz2)";
  3396. [[ -n ${PATCH_VER} ]] && GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2)";
  3397. [[ -n ${PIE_VER} ]] && PIE_CORE=${PIE_CORE:-gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}.tar.bz2} && GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls ${PIE_CORE})";
  3398. [[ -n ${SPECS_VER} ]] && GCC_SRC_URI="${GCC_SRC_URI} $(gentoo_urls gcc-${SPECS_GCC_VER}-specs-${SPECS_VER}.tar.bz2)";
  3399. if [[ -n ${HTB_VER} ]]; then
  3400. local HTBFILE="bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2";
  3401. GCC_SRC_URI="${GCC_SRC_URI}
  3402. boundschecking? (
  3403. mirror://sourceforge/boundschecking/${HTBFILE}
  3404. $(gentoo_urls ${HTBFILE})
  3405. )";
  3406. fi;
  3407. [[ -n ${D_VER} ]] && GCC_SRC_URI="${GCC_SRC_URI} d? ( mirror://sourceforge/dgcc/gdc-${D_VER}-src.tar.bz2 )";
  3408. if [[ ${PN} != "kgcc64" && ${PN} != gcc-* ]]; then
  3409. if tc_version_is_at_least "4.5"; then
  3410. GCC_SRC_URI="${GCC_SRC_URI}
  3411. gcj? ( ftp://sourceware.org/pub/java/ecj-4.5.jar )";
  3412. else
  3413. if tc_version_is_at_least "4.3"; then
  3414. GCC_SRC_URI="${GCC_SRC_URI}
  3415. gcj? ( ftp://sourceware.org/pub/java/ecj-4.3.jar )";
  3416. fi;
  3417. fi;
  3418. fi;
  3419. echo "${GCC_SRC_URI}"
  3420. }
  3421. get_install_abis ()
  3422. {
  3423. local order="";
  3424. if [[ -z ${MULTILIB_ABIS} ]]; then
  3425. echo "default";
  3426. return 0;
  3427. fi;
  3428. if [[ ${EMULTILIB_PKG} == "true" ]]; then
  3429. for x in ${MULTILIB_ABIS};
  3430. do
  3431. if [[ ${x} != "${DEFAULT_ABI}" ]]; then
  3432. hasq ${x} ${ABI_DENY} || order="${order} ${x}";
  3433. fi;
  3434. done;
  3435. hasq ${DEFAULT_ABI} ${ABI_DENY} || order="${order} ${DEFAULT_ABI}";
  3436. if [[ -n ${ABI_ALLOW} ]]; then
  3437. local ordera="";
  3438. for x in ${order};
  3439. do
  3440. if hasq ${x} ${ABI_ALLOW}; then
  3441. ordera="${ordera} ${x}";
  3442. fi;
  3443. done;
  3444. order=${ordera};
  3445. fi;
  3446. else
  3447. order=${DEFAULT_ABI};
  3448. fi;
  3449. if [[ -z ${order} ]]; then
  3450. 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.";
  3451. fi;
  3452. echo ${order};
  3453. return 0
  3454. }
  3455. get_last_version_component_index ()
  3456. {
  3457. eshopts_push -s extglob;
  3458. echo $(( $(get_version_component_count "${1:-${PV}}" ) - 1 ));
  3459. eshopts_pop
  3460. }
  3461. get_libdir ()
  3462. {
  3463. local CONF_LIBDIR;
  3464. if [ -n "${CONF_LIBDIR_OVERRIDE}" ]; then
  3465. echo ${CONF_LIBDIR_OVERRIDE};
  3466. else
  3467. get_abi_LIBDIR;
  3468. fi
  3469. }
  3470. get_libdir_override ()
  3471. {
  3472. if has_multilib_profile; then
  3473. eerror "get_libdir_override called, but it shouldn't be needed with the new multilib approach. Please file a bug at http://bugs.gentoo.org and assign it to eradicator@gentoo.org";
  3474. exit 1;
  3475. fi;
  3476. CONF_LIBDIR="$1";
  3477. CONF_LIBDIR_OVERRIDE="$1";
  3478. LIBDIR_default="$1"
  3479. }
  3480. get_libname ()
  3481. {
  3482. local libname;
  3483. local ver=$1;
  3484. case ${CHOST} in
  3485. *-cygwin | mingw* | *-mingw*)
  3486. libname="dll"
  3487. ;;
  3488. *-darwin*)
  3489. libname="dylib"
  3490. ;;
  3491. *-mint*)
  3492. libname="irrelevant"
  3493. ;;
  3494. hppa*-hpux*)
  3495. libname="sl"
  3496. ;;
  3497. *)
  3498. libname="so"
  3499. ;;
  3500. esac;
  3501. if [[ -z $* ]]; then
  3502. echo ".${libname}";
  3503. else
  3504. for ver in "$@";
  3505. do
  3506. case ${CHOST} in
  3507. *-darwin*)
  3508. echo ".${ver}.${libname}"
  3509. ;;
  3510. *-mint*)
  3511. echo ".${libname}"
  3512. ;;
  3513. *)
  3514. echo ".${libname}.${ver}"
  3515. ;;
  3516. esac;
  3517. done;
  3518. fi
  3519. }
  3520. get_major_version ()
  3521. {
  3522. eshopts_push -s extglob;
  3523. local c;
  3524. c=($(get_all_version_components "${1:-${PV}}" ));
  3525. echo ${c[0]};
  3526. eshopts_pop
  3527. }
  3528. get_make_var ()
  3529. {
  3530. local var=$1 makefile=${2:-${WORKDIR}/build/Makefile};
  3531. echo -e "e:\\n\\t@echo \$(${var})\\ninclude ${makefile}" | r=${makefile%/*} emake --no-print-directory -s -f - 2> /dev/null
  3532. }
  3533. get_modname ()
  3534. {
  3535. local modname;
  3536. local ver=$1;
  3537. case ${CHOST} in
  3538. *-darwin*)
  3539. modname="bundle"
  3540. ;;
  3541. *)
  3542. modname="so"
  3543. ;;
  3544. esac;
  3545. echo ".${modname}"
  3546. }
  3547. get_mounts ()
  3548. {
  3549. local point= node= fs= opts= foo=;
  3550. if [[ $(uname -s) == "Linux" ]]; then
  3551. while read node point fs opts foo; do
  3552. echo "${point} ${node} ${fs} ${opts}";
  3553. done < /proc/mounts;
  3554. return;
  3555. fi;
  3556. local IFS=' ';
  3557. LC_ALL=C mount -p | while read node point fs foo; do
  3558. opts=${fs#* };
  3559. fs=${fs%% *};
  3560. echo "${point// /\040} ${node// /\040} ${fs%% *} ${opts// /\040}";
  3561. done
  3562. }
  3563. get_multilibdir ()
  3564. {
  3565. if has_multilib_profile; then
  3566. eerror "get_multilibdir called, but it shouldn't be needed with the new multilib approach. Please file a bug at http://bugs.gentoo.org and assign it to eradicator@gentoo.org";
  3567. exit 1;
  3568. fi;
  3569. echo ${CONF_MULTILIBDIR:=lib32}
  3570. }
  3571. get_version_component_count ()
  3572. {
  3573. eshopts_push -s extglob;
  3574. local a;
  3575. a=($(get_version_components "${1:-${PV}}" ));
  3576. echo ${#a[@]};
  3577. eshopts_pop
  3578. }
  3579. get_version_component_range ()
  3580. {
  3581. eshopts_push -s extglob;
  3582. local c v="${2:-${PV}}" range="${1}" range_start range_end i=-1 j=0;
  3583. c=($(get_all_version_components ${v} ));
  3584. range_start="${range%-*}";
  3585. range_start="${range_start:-1}";
  3586. range_end="${range#*-}";
  3587. range_end="${range_end:-${#c[@]}}";
  3588. while (( j < ${range_start} )); do
  3589. i=$(($i + 1));
  3590. [[ $i -gt ${#c[@]} ]] && eshopts_pop && return;
  3591. [[ -n "${c[${i}]//[-._]}" ]] && j=$(($j + 1));
  3592. done;
  3593. while (( j <= ${range_end} )); do
  3594. echo -n ${c[$i]};
  3595. [[ $i -gt ${#c[@]} ]] && eshopts_pop && return;
  3596. [[ -n "${c[${i}]//[-._]}" ]] && j=$(($j + 1));
  3597. i=$(($i + 1));
  3598. done;
  3599. eshopts_pop
  3600. }
  3601. get_version_components ()
  3602. {
  3603. eshopts_push -s extglob;
  3604. local c="$(get_all_version_components "${1:-${PV}}")";
  3605. c=(${c[@]//[-._]/ });
  3606. echo ${c[@]};
  3607. eshopts_pop
  3608. }
  3609. glibc_have_pie ()
  3610. {
  3611. if [[ ! -f ${ROOT}/usr/$(get_libdir)/Scrt1.o ]]; then
  3612. echo;
  3613. ewarn "Your glibc does not have support for pie, the file Scrt1.o is missing";
  3614. ewarn "Please update your glibc to a proper version or disable hardened";
  3615. echo;
  3616. return 1;
  3617. fi
  3618. }
  3619. gnuconfig_do_update ()
  3620. {
  3621. local configsubs_dir target targetlist file;
  3622. [[ $# -eq 0 ]] && die "do not call gnuconfig_do_update; use gnuconfig_update";
  3623. configsubs_dir=$(gnuconfig_findnewest);
  3624. einfo "Using GNU config files from ${configsubs_dir}";
  3625. for file in "$@";
  3626. do
  3627. if [[ ! -r ${configsubs_dir}/${file} ]]; then
  3628. eerror "Can't read ${configsubs_dir}/${file}, skipping..";
  3629. continue;
  3630. fi;
  3631. targetlist=$(find "${startdir}" -name "${file}");
  3632. if [[ -n ${targetlist} ]]; then
  3633. for target in ${targetlist};
  3634. do
  3635. [[ -L ${target} ]] && rm -f "${target}";
  3636. einfo " Updating ${target/$startdir\//}";
  3637. cp -f "${configsubs_dir}/${file}" "${target}";
  3638. eend $?;
  3639. done;
  3640. else
  3641. ewarn " No ${file} found in ${startdir}, skipping ...";
  3642. fi;
  3643. done;
  3644. return 0
  3645. }
  3646. gnuconfig_findnewest ()
  3647. {
  3648. local locations="
  3649. /usr/share/gnuconfig/config.sub
  3650. /usr/share/automake-1.9/config.sub
  3651. /usr/share/automake-1.8/config.sub
  3652. /usr/share/automake-1.7/config.sub
  3653. /usr/share/automake-1.6/config.sub
  3654. /usr/share/automake-1.5/config.sub
  3655. /usr/share/automake-1.4/config.sub
  3656. /usr/share/libtool/config.sub
  3657. ";
  3658. grep -s '^timestamp' ${locations} | sort -n -t\' -k2 | tail -n 1 | sed 's,/config.sub:.*$,,'
  3659. }
  3660. gnuconfig_update ()
  3661. {
  3662. local startdir;
  3663. if [[ $1 == /* ]]; then
  3664. startdir=$1;
  3665. shift;
  3666. else
  3667. startdir=${S};
  3668. fi;
  3669. if [[ $# -gt 0 ]]; then
  3670. gnuconfig_do_update "$@";
  3671. else
  3672. gnuconfig_do_update config.sub config.guess;
  3673. fi;
  3674. return $?
  3675. }
  3676. guess_patch_type_in_dir ()
  3677. {
  3678. [[ -n $(ls "$1"/*.bz2 2>/dev/null) ]] && EPATCH_SUFFIX="patch.bz2" || EPATCH_SUFFIX="patch"
  3679. }
  3680. hardened_gcc_check_unsupported ()
  3681. {
  3682. local tocheck="";
  3683. if [[ $1 == "pie" ]]; then
  3684. if [[ ${CTARGET} == *-uclibc* ]]; then
  3685. [[ -z ${PIE_UCLIBC_UNSUPPORTED} ]] && return 0;
  3686. tocheck="${tocheck} ${PIE_UCLIBC_UNSUPPORTED}";
  3687. else
  3688. [[ -z ${PIE_GLIBC_UNSUPPORTED} ]] && return 0;
  3689. tocheck="${tocheck} ${PIE_GLIBC_UNSUPPORTED}";
  3690. fi;
  3691. else
  3692. if [[ $1 == "ssp" ]]; then
  3693. if [[ ${CTARGET} == *-uclibc* ]]; then
  3694. [[ -z ${SSP_UCLIBC_UNSUPPORTED} ]] && return 0;
  3695. tocheck="${tocheck} ${SSP_UCLIBC_UNSUPPORTED}";
  3696. else
  3697. [[ -z ${SSP_UNSUPPORTED} ]] && return 0;
  3698. tocheck="${tocheck} ${SSP_UNSUPPORTED}";
  3699. fi;
  3700. else
  3701. die "hardened_gcc_check_unsupported needs to be called with pie or ssp";
  3702. fi;
  3703. fi;
  3704. hasq $(tc-arch) ${tocheck} && return 0;
  3705. return 1
  3706. }
  3707. hardened_gcc_is_stable ()
  3708. {
  3709. if [[ $1 == "pie" ]]; then
  3710. local tocheck="${HARDENED_PIE_WORKS} ${HARDENED_GCC_WORKS}";
  3711. if [[ ${CTARGET} == *-uclibc* ]]; then
  3712. tocheck="${tocheck} ${PIE_UCLIBC_STABLE}";
  3713. else
  3714. tocheck="${tocheck} ${PIE_GLIBC_STABLE}";
  3715. fi;
  3716. else
  3717. if [[ $1 == "ssp" ]]; then
  3718. local tocheck="${HARDENED_SSP_WORKS} ${HARDENED_GCC_WORKS}";
  3719. if [[ ${CTARGET} == *-uclibc* ]]; then
  3720. tocheck="${tocheck} ${SSP_UCLIBC_STABLE}";
  3721. else
  3722. tocheck="${tocheck} ${SSP_STABLE}";
  3723. fi;
  3724. else
  3725. die "hardened_gcc_stable needs to be called with pie or ssp";
  3726. fi;
  3727. fi;
  3728. hasq $(tc-arch) ${tocheck} && return 0;
  3729. return 1
  3730. }
  3731. hardened_gcc_works ()
  3732. {
  3733. if [[ $1 == "pie" ]]; then
  3734. [[ ${CTARGET} == *-freebsd* ]] && return 1;
  3735. want_pie || return 1;
  3736. tc_version_is_at_least 4.3.2 && use nopie && return 1;
  3737. hardened_gcc_is_stable pie && return 0;
  3738. if has "~$(tc-arch)" ${ACCEPT_KEYWORDS}; then
  3739. hardened_gcc_check_unsupported pie && return 1;
  3740. ewarn "Allowing pie-by-default for an unstable arch ($(tc-arch))";
  3741. return 0;
  3742. fi;
  3743. return 1;
  3744. else
  3745. if [[ $1 == "ssp" ]]; then
  3746. [[ -n ${PP_VER} ]] || [[ -n ${SPECS_VER} ]] || return 1;
  3747. tc_version_is_at_least 4.3.2 && use nossp && return 1;
  3748. hardened_gcc_is_stable ssp && return 0;
  3749. if has "~$(tc-arch)" ${ACCEPT_KEYWORDS}; then
  3750. hardened_gcc_check_unsupported ssp && return 1;
  3751. ewarn "Allowing ssp-by-default for an unstable arch ($(tc-arch))";
  3752. return 0;
  3753. fi;
  3754. return 1;
  3755. else
  3756. hardened_gcc_works pie || return 1;
  3757. hardened_gcc_works ssp || return 1;
  3758. return 0;
  3759. fi;
  3760. fi
  3761. }
  3762. has_hardened ()
  3763. {
  3764. ewarn "has_hardened: deprecated, please use gcc-specs-{relro,now}()!" 1>&2;
  3765. test_version_info Hardened && return 0;
  3766. [[ -f ${GCC_SPECS} && ${GCC_SPECS} != ${GCC_SPECS/hardened/} ]]
  3767. }
  3768. has_libssp ()
  3769. {
  3770. [[ -e /$(get_libdir)/libssp.so ]] && return 0;
  3771. return 1
  3772. }
  3773. has_m32 ()
  3774. {
  3775. [ "$(tc-arch)" = "amd64" ] && has_multilib_profile && return 0;
  3776. local temp=$(emktemp);
  3777. echo "int main() { return(0); }" > "${temp}".c;
  3778. MY_CC=$(tc-getCC);
  3779. ${MY_CC/ .*/} -m32 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1;
  3780. local ret=$?;
  3781. rm -f "${temp}".c;
  3782. [[ ${ret} != 1 ]] && return 0;
  3783. return 1
  3784. }
  3785. has_m64 ()
  3786. {
  3787. local temp="$(emktemp)";
  3788. echo "int main() { return(0); }" > "${temp}".c;
  3789. MY_CC=$(tc-getCC);
  3790. ${MY_CC/ .*/} -m64 -o "$(emktemp)" "${temp}".c > /dev/null 2>&1;
  3791. local ret=$?;
  3792. rm -f "${temp}".c;
  3793. [[ ${ret} != 1 ]] && return 0;
  3794. return 1
  3795. }
  3796. has_multilib_profile ()
  3797. {
  3798. [ -n "${MULTILIB_ABIS}" -a "${MULTILIB_ABIS}" != "${MULTILIB_ABIS/ /}" ]
  3799. }
  3800. has_pic ()
  3801. {
  3802. ewarn "has_pic: deprecated, please use gcc-specs-pie()!" 1>&2;
  3803. [[ ${CFLAGS/-fPIC} != ${CFLAGS} || ${CFLAGS/-fpic} != ${CFLAGS} ]] || gcc-specs-pie
  3804. }
  3805. has_pie ()
  3806. {
  3807. ewarn "has_pie: deprecated, please use gcc-specs-pie()!" 1>&2;
  3808. [[ ${CFLAGS/-fPIE} != ${CFLAGS} || ${CFLAGS/-fpie} != ${CFLAGS} ]] || gcc-specs-pie
  3809. }
  3810. has_ssp ()
  3811. {
  3812. ewarn "has_ssp: deprecated, please use gcc-specs-ssp()!" 1>&2;
  3813. [[ ${CFLAGS/-fstack-protector} != ${CFLAGS} || -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__) ]] || gcc-specs-ssp
  3814. }
  3815. has_ssp_all ()
  3816. {
  3817. ewarn "has_ssp_all: deprecated, please use gcc-specs-ssp()!" 1>&2;
  3818. [[ ${CFLAGS/-fstack-protector-all} != ${CFLAGS} || -n $(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__) ]] || gcc-specs-ssp-to-all
  3819. }
  3820. helpers_die ()
  3821. {
  3822. case "${EAPI:-0}" in
  3823. 0 | 1 | 2 | 3)
  3824. echo -e "$@" 1>&2
  3825. ;;
  3826. *)
  3827. die "$@"
  3828. ;;
  3829. esac
  3830. }
  3831. ht_fix_all ()
  3832. {
  3833. local MATCHES;
  3834. MATCHES=$(grep -l -s -i -R -e "head -[ 0-9]" -e "tail [+-][ 0-9]" * | sort -u);
  3835. [[ -n ${MATCHES} ]] && ht_fix_file ${MATCHES} || einfo "No need for ht_fix_all anymore !"
  3836. }
  3837. ht_fix_file ()
  3838. {
  3839. local i;
  3840. einfo "Replacing obsolete head/tail with POSIX compliant ones";
  3841. for i in "$@";
  3842. do
  3843. __do_sed_fix "$i";
  3844. done
  3845. }
  3846. is-flag ()
  3847. {
  3848. is-flagq "$@" && echo true
  3849. }
  3850. is-flagq ()
  3851. {
  3852. [[ -n $2 ]] && die "Usage: is-flag <flag>";
  3853. _is_flagq CFLAGS $1 || _is_flagq CXXFLAGS $1 || _is_flagq FFLAGS $1 || _is_flagq FCFLAGS $1
  3854. }
  3855. is-ldflag ()
  3856. {
  3857. is-ldflagq "$@" && echo true
  3858. }
  3859. is-ldflagq ()
  3860. {
  3861. [[ -n $2 ]] && die "Usage: is-ldflag <flag>";
  3862. _is_flagq LDFLAGS $1
  3863. }
  3864. is-login-disabled ()
  3865. {
  3866. shell=$(egetshell "$1");
  3867. case ${shell} in
  3868. /bin/false | /usr/bin/false | /sbin/nologin | /usr/sbin/nologin)
  3869. return 0
  3870. ;;
  3871. *)
  3872. return 1
  3873. ;;
  3874. esac
  3875. }
  3876. is_ada ()
  3877. {
  3878. gcc-lang-supported ada || return 1;
  3879. use ada
  3880. }
  3881. is_crosscompile ()
  3882. {
  3883. [[ ${CHOST} != ${CTARGET} ]]
  3884. }
  3885. is_cxx ()
  3886. {
  3887. gcc-lang-supported 'c++' || return 1;
  3888. ! use nocxx
  3889. }
  3890. is_d ()
  3891. {
  3892. gcc-lang-supported d || return 1;
  3893. use d
  3894. }
  3895. is_f77 ()
  3896. {
  3897. gcc-lang-supported f77 || return 1;
  3898. use fortran
  3899. }
  3900. is_f95 ()
  3901. {
  3902. gcc-lang-supported f95 || return 1;
  3903. use fortran
  3904. }
  3905. is_final_abi ()
  3906. {
  3907. has_multilib_profile || return 0;
  3908. set -- $(get_install_abis);
  3909. local LAST_ABI=$#;
  3910. [[ ${!LAST_ABI} == ${ABI} ]]
  3911. }
  3912. is_fortran ()
  3913. {
  3914. gcc-lang-supported fortran || return 1;
  3915. use fortran
  3916. }
  3917. is_gcj ()
  3918. {
  3919. gcc-lang-supported java || return 1;
  3920. ! use nocxx && use gcj
  3921. }
  3922. is_go ()
  3923. {
  3924. gcc-lang-supported go || return 1;
  3925. ! use nocxx && use go
  3926. }
  3927. is_libffi ()
  3928. {
  3929. has libffi ${IUSE} || return 1;
  3930. use libffi
  3931. }
  3932. is_multilib ()
  3933. {
  3934. [[ ${GCCMAJOR} < 3 ]] && return 1;
  3935. use multilib
  3936. }
  3937. is_objc ()
  3938. {
  3939. gcc-lang-supported objc || return 1;
  3940. use objc
  3941. }
  3942. is_objcxx ()
  3943. {
  3944. gcc-lang-supported 'obj-c++' || return 1;
  3945. ! use nocxx && use objc++
  3946. }
  3947. is_treelang ()
  3948. {
  3949. has boundschecking ${IUSE} && use boundschecking && return 1;
  3950. is_crosscompile && return 1;
  3951. gcc-lang-supported treelang || return 1;
  3952. return 0
  3953. }
  3954. libc_has_ssp ()
  3955. {
  3956. [[ ${ROOT} != "/" ]] && return 0;
  3957. echo 'int main(){}' > "${T}"/libctest.c;
  3958. LC_ALL=C gcc "${T}"/libctest.c -lc -o libctest -Wl,-verbose &>"${T}"/libctest.log || return 1;
  3959. local libc_file=$(awk '/attempt to open/ { if (($4 ~ /\/libc\.so/) && ($5 == "succeeded")) LIBC = $4; }; END {print LIBC}' "${T}"/libctest.log);
  3960. [[ -z ${libc_file} ]] && die "Unable to find a libc !?";
  3961. if [[ -n $(readelf -s "${libc_file}" 2>/dev/null | grep 'FUNC.*GLOBAL.*__stack_chk_fail') ]]; then
  3962. return 0;
  3963. else
  3964. if [[ -n $(readelf -s "${libc_file}" 2>/dev/null | grep 'OBJECT.*GLOBAL.*__guard') ]] && [[ -n $(readelf -s "${libc_file}" 2>/dev/null | grep 'FUNC.*GLOBAL.*__stack_smash_handler') ]]; then
  3965. return 0;
  3966. else
  3967. if is_crosscompile; then
  3968. die "'${libc_file}' was detected w/out ssp, that sucks (a lot)";
  3969. else
  3970. return 1;
  3971. fi;
  3972. fi;
  3973. fi
  3974. }
  3975. make_desktop_entry ()
  3976. {
  3977. [[ -z $1 ]] && die "make_desktop_entry: You must specify the executable";
  3978. local exec=${1};
  3979. local name=${2:-${PN}};
  3980. local icon=${3:-${PN}};
  3981. local type=${4};
  3982. local fields=${5};
  3983. if [[ -z ${type} ]]; then
  3984. local catmaj=${CATEGORY%%-*};
  3985. local catmin=${CATEGORY##*-};
  3986. case ${catmaj} in
  3987. app)
  3988. case ${catmin} in
  3989. accessibility)
  3990. type=Accessibility
  3991. ;;
  3992. admin)
  3993. type=System
  3994. ;;
  3995. antivirus)
  3996. type=System
  3997. ;;
  3998. arch)
  3999. type=Archiving
  4000. ;;
  4001. backup)
  4002. type=Archiving
  4003. ;;
  4004. cdr)
  4005. type=DiscBurning
  4006. ;;
  4007. dicts)
  4008. type=Dictionary
  4009. ;;
  4010. doc)
  4011. type=Documentation
  4012. ;;
  4013. editors)
  4014. type=TextEditor
  4015. ;;
  4016. emacs)
  4017. type=TextEditor
  4018. ;;
  4019. emulation)
  4020. type=Emulator
  4021. ;;
  4022. laptop)
  4023. type=HardwareSettings
  4024. ;;
  4025. office)
  4026. type=Office
  4027. ;;
  4028. pda)
  4029. type=PDA
  4030. ;;
  4031. vim)
  4032. type=TextEditor
  4033. ;;
  4034. xemacs)
  4035. type=TextEditor
  4036. ;;
  4037. esac
  4038. ;;
  4039. dev)
  4040. type="Development"
  4041. ;;
  4042. games)
  4043. case ${catmin} in
  4044. action | fps)
  4045. type=ActionGame
  4046. ;;
  4047. arcade)
  4048. type=ArcadeGame
  4049. ;;
  4050. board)
  4051. type=BoardGame
  4052. ;;
  4053. emulation)
  4054. type=Emulator
  4055. ;;
  4056. kids)
  4057. type=KidsGame
  4058. ;;
  4059. puzzle)
  4060. type=LogicGame
  4061. ;;
  4062. roguelike)
  4063. type=RolePlaying
  4064. ;;
  4065. rpg)
  4066. type=RolePlaying
  4067. ;;
  4068. simulation)
  4069. type=Simulation
  4070. ;;
  4071. sports)
  4072. type=SportsGame
  4073. ;;
  4074. strategy)
  4075. type=StrategyGame
  4076. ;;
  4077. esac;
  4078. type="Game;${type}"
  4079. ;;
  4080. gnome)
  4081. type="Gnome;GTK"
  4082. ;;
  4083. kde)
  4084. type="KDE;Qt"
  4085. ;;
  4086. mail)
  4087. type="Network;Email"
  4088. ;;
  4089. media)
  4090. case ${catmin} in
  4091. gfx)
  4092. type=Graphics
  4093. ;;
  4094. *)
  4095. case ${catmin} in
  4096. radio)
  4097. type=Tuner
  4098. ;;
  4099. sound)
  4100. type=Audio
  4101. ;;
  4102. tv)
  4103. type=TV
  4104. ;;
  4105. video)
  4106. type=Video
  4107. ;;
  4108. esac;
  4109. type="AudioVideo;${type}"
  4110. ;;
  4111. esac
  4112. ;;
  4113. net)
  4114. case ${catmin} in
  4115. dialup)
  4116. type=Dialup
  4117. ;;
  4118. ftp)
  4119. type=FileTransfer
  4120. ;;
  4121. im)
  4122. type=InstantMessaging
  4123. ;;
  4124. irc)
  4125. type=IRCClient
  4126. ;;
  4127. mail)
  4128. type=Email
  4129. ;;
  4130. news)
  4131. type=News
  4132. ;;
  4133. nntp)
  4134. type=News
  4135. ;;
  4136. p2p)
  4137. type=FileTransfer
  4138. ;;
  4139. voip)
  4140. type=Telephony
  4141. ;;
  4142. esac;
  4143. type="Network;${type}"
  4144. ;;
  4145. sci)
  4146. case ${catmin} in
  4147. astro*)
  4148. type=Astronomy
  4149. ;;
  4150. bio*)
  4151. type=Biology
  4152. ;;
  4153. calc*)
  4154. type=Calculator
  4155. ;;
  4156. chem*)
  4157. type=Chemistry
  4158. ;;
  4159. elec*)
  4160. type=Electronics
  4161. ;;
  4162. geo*)
  4163. type=Geology
  4164. ;;
  4165. math*)
  4166. type=Math
  4167. ;;
  4168. physics)
  4169. type=Physics
  4170. ;;
  4171. visual*)
  4172. type=DataVisualization
  4173. ;;
  4174. esac;
  4175. type="Education;Science;${type}"
  4176. ;;
  4177. sys)
  4178. type="System"
  4179. ;;
  4180. www)
  4181. case ${catmin} in
  4182. client)
  4183. type=WebBrowser
  4184. ;;
  4185. esac;
  4186. type="Network;${type}"
  4187. ;;
  4188. *)
  4189. type=
  4190. ;;
  4191. esac;
  4192. fi;
  4193. if [ "${SLOT}" == "0" ]; then
  4194. local desktop_name="${PN}";
  4195. else
  4196. local desktop_name="${PN}-${SLOT}";
  4197. fi;
  4198. local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop";
  4199. type=${type%;}${type:+;};
  4200. eshopts_push -s extglob;
  4201. if [[ -n ${icon} && ${icon} != /* ]] && [[ ${icon} == *.xpm || ${icon} == *.png || ${icon} == *.svg ]]; then
  4202. ewarn "As described in the Icon Theme Specification, icon file extensions are not";
  4203. ewarn "allowed in .desktop files if the value is not an absolute path.";
  4204. icon=${icon%.@(xpm|png|svg)};
  4205. fi;
  4206. eshopts_pop;
  4207. cat > "${desktop}" <<-EOF
  4208. [Desktop Entry]
  4209. Name=${name}
  4210. Type=Application
  4211. Comment=${DESCRIPTION}
  4212. Exec=${exec}
  4213. TryExec=${exec%% *}
  4214. Icon=${icon}
  4215. Categories=${type}
  4216. EOF
  4217.  
  4218. if [[ ${fields:-=} != *=* ]]; then
  4219. ewarn "make_desktop_entry: update your 5th arg to read Path=${fields}";
  4220. fields="Path=${fields}";
  4221. fi;
  4222. [[ -n ${fields} ]] && printf '%b\n' "${fields}" >> "${desktop}";
  4223. ( insinto /usr/share/applications;
  4224. doins "${desktop}" ) || die "installing desktop file failed"
  4225. }
  4226. make_gcc_hard ()
  4227. {
  4228. if hardened_gcc_works; then
  4229. einfo "Updating gcc to use automatic PIE + SSP building ...";
  4230. sed -e "s|^HARD_CFLAGS = |HARD_CFLAGS = -DEFAULT_PIE_SSP ${gcc_common_hard} |" -i "${S}"/gcc/Makefile.in || die "Failed to update gcc!";
  4231. else
  4232. if hardened_gcc_works pie; then
  4233. einfo "Updating gcc to use automatic PIE building ...";
  4234. ewarn "SSP has not been enabled by default";
  4235. sed -e "s|^HARD_CFLAGS = |HARD_CFLAGS = -DEFAULT_PIE ${gcc_common_hard} |" -i "${S}"/gcc/Makefile.in || die "Failed to update gcc!";
  4236. else
  4237. if hardened_gcc_works ssp; then
  4238. einfo "Updating gcc to use automatic SSP building ...";
  4239. ewarn "PIE has not been enabled by default";
  4240. sed -e "s|^HARD_CFLAGS = |HARD_CFLAGS = -DEFAULT_SSP ${gcc_common_hard} |" -i "${S}"/gcc/Makefile.in || die "Failed to update gcc!";
  4241. else
  4242. ewarn "hardened is not supported for this arch in this gcc version";
  4243. ebeep;
  4244. return 0;
  4245. fi;
  4246. fi;
  4247. fi;
  4248. BRANDING_GCC_PKGVERSION=${BRANDING_GCC_PKGVERSION/Gentoo/Gentoo Hardened}
  4249. }
  4250. make_session_desktop ()
  4251. {
  4252. [[ -z $1 ]] && eerror "$0: You must specify the title" && return 1;
  4253. [[ -z $2 ]] && eerror "$0: You must specify the command" && return 1;
  4254. local title=$1;
  4255. local command=$2;
  4256. local desktop=${T}/${wm:-${PN}}.desktop;
  4257. shift 2;
  4258. cat > "${desktop}" <<-EOF
  4259. [Desktop Entry]
  4260. Name=${title}
  4261. Comment=This session logs you into ${title}
  4262. Exec=${command} $*
  4263. TryExec=${command}
  4264. Type=XSession
  4265. EOF
  4266.  
  4267. ( insinto /usr/share/xsessions;
  4268. doins "${desktop}" )
  4269. }
  4270. make_wrapper ()
  4271. {
  4272. local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5;
  4273. local tmpwrapper=$(emktemp);
  4274. cat > "${tmpwrapper}" <<EOF
  4275. #!/bin/sh
  4276. cd "${chdir:-.}"
  4277. if [ -n "${libdir}" ] ; then
  4278. if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
  4279. export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
  4280. else
  4281. export LD_LIBRARY_PATH="${libdir}"
  4282. fi
  4283. fi
  4284. exec ${bin} "\$@"
  4285. EOF
  4286.  
  4287. chmod go+rx "${tmpwrapper}";
  4288. if [[ -n ${path} ]]; then
  4289. ( exeinto "${path}";
  4290. newexe "${tmpwrapper}" "${wrapper}" ) || die;
  4291. else
  4292. newbin "${tmpwrapper}" "${wrapper}" || die;
  4293. fi
  4294. }
  4295. multilib_env ()
  4296. {
  4297. local CTARGET=${1:-${CTARGET}};
  4298. case ${CTARGET} in
  4299. x86_64*)
  4300. export CFLAGS_x86=${CFLAGS_x86--m32};
  4301. export CHOST_x86=${CTARGET/x86_64/i686};
  4302. export CTARGET_x86=${CHOST_x86};
  4303. if [[ ${SYMLINK_LIB} == "yes" ]]; then
  4304. export LIBDIR_x86="lib32";
  4305. else
  4306. export LIBDIR_x86="lib";
  4307. fi;
  4308. export CFLAGS_amd64=${CFLAGS_amd64--m64};
  4309. export CHOST_amd64=${CTARGET};
  4310. export CTARGET_amd64=${CHOST_amd64};
  4311. export LIBDIR_amd64="lib64";
  4312. export CFLAGS_x32=${CFLAGS_x32--mx32};
  4313. export CHOST_x32=${CTARGET};
  4314. export CTARGET_x32=${CHOST_x32};
  4315. export LIBDIR_x32="libx32";
  4316. : ${MULTILIB_ABIS=amd64 x86};
  4317. : ${DEFAULT_ABI=amd64}
  4318. ;;
  4319. mips64*)
  4320. export CFLAGS_o32=${CFLAGS_o32--mabi=32};
  4321. export CHOST_o32=${CTARGET/mips64/mips};
  4322. export CTARGET_o32=${CHOST_o32};
  4323. export LIBDIR_o32="lib";
  4324. export CFLAGS_n32=${CFLAGS_n32--mabi=n32};
  4325. export CHOST_n32=${CTARGET};
  4326. export CTARGET_n32=${CHOST_n32};
  4327. export LIBDIR_n32="lib32";
  4328. export CFLAGS_n64=${CFLAGS_n64--mabi=64};
  4329. export CHOST_n64=${CTARGET};
  4330. export CTARGET_n64=${CHOST_n64};
  4331. export LIBDIR_n64="lib64";
  4332. : ${MULTILIB_ABIS=n64 n32 o32};
  4333. : ${DEFAULT_ABI=n32}
  4334. ;;
  4335. powerpc64*)
  4336. export CFLAGS_ppc=${CFLAGS_ppc--m32};
  4337. export CHOST_ppc=${CTARGET/powerpc64/powerpc};
  4338. export CTARGET_ppc=${CHOST_ppc};
  4339. export LIBDIR_ppc="lib";
  4340. export CFLAGS_ppc64=${CFLAGS_ppc64--m64};
  4341. export CHOST_ppc64=${CTARGET};
  4342. export CTARGET_ppc64=${CHOST_ppc64};
  4343. export LIBDIR_ppc64="lib64";
  4344. : ${MULTILIB_ABIS=ppc64 ppc};
  4345. : ${DEFAULT_ABI=ppc64}
  4346. ;;
  4347. s390x*)
  4348. export CFLAGS_s390=${CFLAGS_s390--m31};
  4349. export CHOST_s390=${CTARGET/s390x/s390};
  4350. export CTARGET_s390=${CHOST_s390};
  4351. export LIBDIR_s390="lib";
  4352. export CFLAGS_s390x=${CFLAGS_s390x--m64};
  4353. export CHOST_s390x=${CTARGET};
  4354. export CTARGET_s390x=${CHOST_s390x};
  4355. export LIBDIR_s390x="lib64";
  4356. : ${MULTILIB_ABIS=s390x s390};
  4357. : ${DEFAULT_ABI=s390x}
  4358. ;;
  4359. sparc*)
  4360. export CFLAGS_sparc32=${CFLAGS_sparc32};
  4361. export CHOST_sparc32=${CTARGET/sparc64/sparc};
  4362. export CTARGET_sparc32=${CHOST_sparc32};
  4363. export LIBDIR_sparc32="lib";
  4364. export CFLAGS_sparc64=${CFLAGS_sparc64--m64};
  4365. export CHOST_sparc64=${CTARGET};
  4366. export CTARGET_sparc64=${CHOST_sparc64};
  4367. export LIBDIR_sparc64="lib64";
  4368. : ${MULTILIB_ABIS=sparc64 sparc32};
  4369. : ${DEFAULT_ABI=sparc64}
  4370. ;;
  4371. *)
  4372. : ${MULTILIB_ABIS=default};
  4373. : ${DEFAULT_ABI=default}
  4374. ;;
  4375. esac;
  4376. export MULTILIB_ABIS DEFAULT_ABI
  4377. }
  4378. multilib_toolchain_setup ()
  4379. {
  4380. local v vv;
  4381. export ABI=$1;
  4382. if [[ ${__DEFAULT_ABI_SAVED} == "true" ]]; then
  4383. for v in CHOST CBUILD AS CC CXX LD;
  4384. do
  4385. vv="__abi_saved_${v}";
  4386. export ${v}="${!vv}";
  4387. unset ${vv};
  4388. done;
  4389. unset __DEFAULT_ABI_SAVED;
  4390. fi;
  4391. if [[ ${ABI} != ${DEFAULT_ABI} ]]; then
  4392. for v in CHOST CBUILD AS CC CXX LD;
  4393. do
  4394. export __abi_saved_${v}="${!v}";
  4395. done;
  4396. export __DEFAULT_ABI_SAVED="true";
  4397. export CHOST=$(get_abi_CHOST ${DEFAULT_ABI});
  4398. export AS="$(tc-getAS) $(get_abi_ASFLAGS)";
  4399. export CC="$(tc-getCC) $(get_abi_CFLAGS)";
  4400. export CXX="$(tc-getCXX) $(get_abi_CFLAGS)";
  4401. export LD="$(tc-getLD) $(get_abi_LDFLAGS)";
  4402. export CHOST=$(get_abi_CHOST $1);
  4403. export CBUILD=$(get_abi_CHOST $1);
  4404. fi
  4405. }
  4406. newicon ()
  4407. {
  4408. ( insinto /usr/share/pixmaps;
  4409. newins "$@" )
  4410. }
  4411. newmenu ()
  4412. {
  4413. ( insinto /usr/share/applications;
  4414. newins "$@" )
  4415. }
  4416. no-as-needed ()
  4417. {
  4418. case $($(tc-getLD) -v 2>&1 </dev/null) in
  4419. *GNU*)
  4420. echo "-Wl,--no-as-needed"
  4421. ;;
  4422. esac
  4423. }
  4424. nonfatal ()
  4425. {
  4426. if has "${EAPI:-0}" 0 1 2 3 3_pre2; then
  4427. die "$FUNCNAME() not supported in this EAPI";
  4428. fi;
  4429. if [[ $# -lt 1 ]]; then
  4430. die "$FUNCNAME(): Missing argument";
  4431. fi;
  4432. PORTAGE_NONFATAL=1 "$@"
  4433. }
  4434. number_abis ()
  4435. {
  4436. set -- `get_install_abis`;
  4437. echo $#
  4438. }
  4439. path_exists ()
  4440. {
  4441. local opt=$1;
  4442. [[ ${opt} == -[ao] ]] && shift || opt="-a";
  4443. [[ $# -eq 0 ]] && return 1;
  4444. local p r=0;
  4445. for p in "$@";
  4446. do
  4447. [[ -e ${p} ]];
  4448. : $(( r += $? ));
  4449. done;
  4450. case ${opt} in
  4451. -a)
  4452. return $(( r != 0 ))
  4453. ;;
  4454. -o)
  4455. return $(( r == $# ))
  4456. ;;
  4457. esac
  4458. }
  4459. pkg_nofetch ()
  4460. {
  4461. _eapi0_pkg_nofetch "$@"
  4462. }
  4463. pkg_postinst ()
  4464. {
  4465. toolchain_pkg_postinst "$@"
  4466. }
  4467. pkg_postrm ()
  4468. {
  4469. toolchain_pkg_postrm "$@"
  4470. }
  4471. pkg_preinst ()
  4472. {
  4473. toolchain_pkg_preinst "$@"
  4474. }
  4475. pkg_prerm ()
  4476. {
  4477. toolchain_pkg_prerm "$@"
  4478. }
  4479. pkg_setup ()
  4480. {
  4481. gcc_pkg_setup;
  4482. if use graphite; then
  4483. ewarn "Graphite support is still experimental and unstable.";
  4484. ewarn "Any bugs resulting from the use of Graphite will not be fixed.";
  4485. fi
  4486. }
  4487. preserve_old_lib ()
  4488. {
  4489. if [[ ${EBUILD_PHASE} != "preinst" ]]; then
  4490. eerror "preserve_old_lib() must be called from pkg_preinst() only";
  4491. die "Invalid preserve_old_lib() usage";
  4492. fi;
  4493. [[ -z $1 ]] && die "Usage: preserve_old_lib <library to preserve> [more libraries to preserve]";
  4494. has preserve-libs ${FEATURES} && return 0;
  4495. local lib dir;
  4496. for lib in "$@";
  4497. do
  4498. [[ -e ${ROOT}/${lib} ]] || continue;
  4499. dir=${lib%/*};
  4500. dodir ${dir} || die "dodir ${dir} failed";
  4501. cp "${ROOT}"/${lib} "${D}"/${lib} || die "cp ${lib} failed";
  4502. touch "${D}"/${lib};
  4503. done
  4504. }
  4505. preserve_old_lib_notify ()
  4506. {
  4507. if [[ ${EBUILD_PHASE} != "postinst" ]]; then
  4508. eerror "preserve_old_lib_notify() must be called from pkg_postinst() only";
  4509. die "Invalid preserve_old_lib_notify() usage";
  4510. fi;
  4511. has preserve-libs ${FEATURES} && return 0;
  4512. local lib notice=0;
  4513. for lib in "$@";
  4514. do
  4515. [[ -e ${ROOT}/${lib} ]] || continue;
  4516. if [[ ${notice} -eq 0 ]]; then
  4517. notice=1;
  4518. ewarn "Old versions of installed libraries were detected on your system.";
  4519. ewarn "In order to avoid breaking packages that depend on these old libs,";
  4520. ewarn "the libraries are not being removed. You need to run revdep-rebuild";
  4521. ewarn "in order to remove these old dependencies. If you do not have this";
  4522. ewarn "helper program, simply emerge the 'gentoolkit' package.";
  4523. ewarn;
  4524. fi;
  4525. [[ ${PN} == "mpfr" ]] && lib=${lib##*/};
  4526. ewarn " # revdep-rebuild --library '${lib}'";
  4527. done;
  4528. if [[ ${notice} -eq 1 ]]; then
  4529. ewarn;
  4530. ewarn "Once you've finished running revdep-rebuild, it should be safe to";
  4531. ewarn "delete the old libraries. Here is a copy & paste for the lazy:";
  4532. for lib in "$@";
  4533. do
  4534. ewarn " # rm '${lib}'";
  4535. done;
  4536. fi
  4537. }
  4538. raw-ldflags ()
  4539. {
  4540. local x input="$@";
  4541. [[ -z ${input} ]] && input=${LDFLAGS};
  4542. set --;
  4543. for x in ${input};
  4544. do
  4545. x=${x#-Wl,};
  4546. set -- "$@" ${x//,/ };
  4547. done;
  4548. echo "$@"
  4549. }
  4550. register_success_hook ()
  4551. {
  4552. local x;
  4553. for x in $*;
  4554. do
  4555. hasq $x $EBUILD_SUCCESS_HOOKS || export EBUILD_SUCCESS_HOOKS="$EBUILD_SUCCESS_HOOKS $x";
  4556. done
  4557. }
  4558. replace-cpu-flags ()
  4559. {
  4560. local newcpu="$#";
  4561. newcpu="${!newcpu}";
  4562. while [ $# -gt 1 ]; do
  4563. replace-flags "-march=${1}" "-march=${newcpu}";
  4564. replace-flags "-mcpu=${1}" "-mcpu=${newcpu}";
  4565. replace-flags "-mtune=${1}" "-mtune=${newcpu}";
  4566. shift;
  4567. done;
  4568. return 0
  4569. }
  4570. replace-flags ()
  4571. {
  4572. [[ $# != 2 ]] && echo && eerror "Usage: replace-flags <old flag> <new flag>" && die "replace-flags takes 2 arguments, not $#";
  4573. local f fset;
  4574. declare -a new_CFLAGS new_CXXFLAGS new_FFLAGS new_FCFLAGS;
  4575. for fset in CFLAGS CXXFLAGS FFLAGS FCFLAGS;
  4576. do
  4577. for f in ${!fset};
  4578. do
  4579. [[ ${f} == ${1} ]] && f=${2};
  4580. eval new_${fset}\[\${\#new_${fset}\[@]}]=\${f};
  4581. done;
  4582. eval export ${fset}=\${new_${fset}\[*]};
  4583. done;
  4584. return 0
  4585. }
  4586. replace-sparc64-flags ()
  4587. {
  4588. local SPARC64_CPUS="ultrasparc3 ultrasparc v9";
  4589. if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then
  4590. for x in ${SPARC64_CPUS};
  4591. do
  4592. CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8}";
  4593. done;
  4594. else
  4595. for x in ${SPARC64_CPUS};
  4596. do
  4597. CFLAGS="${CFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}";
  4598. done;
  4599. fi;
  4600. if [ "${CXXFLAGS/mtune}" != "${CXXFLAGS}" ]; then
  4601. for x in ${SPARC64_CPUS};
  4602. do
  4603. CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8}";
  4604. done;
  4605. else
  4606. for x in ${SPARC64_CPUS};
  4607. do
  4608. CXXFLAGS="${CXXFLAGS/-mcpu=${x}/-mcpu=v8 -mtune=${x}}";
  4609. done;
  4610. fi;
  4611. export CFLAGS CXXFLAGS
  4612. }
  4613. replace_all_version_separators ()
  4614. {
  4615. eshopts_push -s extglob;
  4616. local c;
  4617. c=($(get_all_version_components "${2:-${PV}}" ));
  4618. c="${c[@]//[-._]/$1}";
  4619. echo ${c// };
  4620. eshopts_pop
  4621. }
  4622. replace_version_separator ()
  4623. {
  4624. eshopts_push -s extglob;
  4625. local w i c found=0 v="${3:-${PV}}";
  4626. w=${1:-1};
  4627. c=($(get_all_version_components ${v} ));
  4628. if [[ "${w//[[:digit:]]/}" == "${w}" ]]; then
  4629. for ((i = 0 ; i < ${#c[@]} ; i = $i + 1 ))
  4630. do
  4631. if [[ "${c[${i}]}" == "${w}" ]]; then
  4632. c[${i}]="${2}";
  4633. break;
  4634. fi;
  4635. done;
  4636. else
  4637. for ((i = 0 ; i < ${#c[@]} ; i = $i + 1 ))
  4638. do
  4639. if [[ -n "${c[${i}]//[^-._]}" ]]; then
  4640. found=$(($found + 1));
  4641. if [[ "$found" == "${w}" ]]; then
  4642. c[${i}]="${2}";
  4643. break;
  4644. fi;
  4645. fi;
  4646. done;
  4647. fi;
  4648. c=${c[@]};
  4649. echo ${c// };
  4650. eshopts_pop
  4651. }
  4652. seq ()
  4653. {
  4654. local p=$(type -P seq);
  4655. if [[ -n ${p} ]]; then
  4656. "${p}" "$@";
  4657. return $?;
  4658. fi;
  4659. case $# in
  4660. 1)
  4661. min=1 max=$1 step=1
  4662. ;;
  4663. 2)
  4664. min=$1 max=$2 step=1
  4665. ;;
  4666. 3)
  4667. min=$1 max=$3 step=$2
  4668. ;;
  4669. *)
  4670. die "seq called with wrong number of arguments"
  4671. ;;
  4672. esac;
  4673. p=$(type -P jot);
  4674. if [[ -n ${p} ]]; then
  4675. local reps;
  4676. if [[ ${step} != 0 ]]; then
  4677. reps=$(( (max - min) / step + 1 ));
  4678. else
  4679. reps=0;
  4680. fi;
  4681. jot $reps $min $max $step;
  4682. return $?;
  4683. fi;
  4684. while :; do
  4685. [[ $max < $min && $step > 0 ]] && break;
  4686. [[ $min < $max && $step < 0 ]] && break;
  4687. echo $min;
  4688. : $(( min += step ));
  4689. done;
  4690. return 0
  4691. }
  4692. setup-allowed-flags ()
  4693. {
  4694. if [[ -z ${ALLOWED_FLAGS} ]]; then
  4695. export ALLOWED_FLAGS="-pipe";
  4696. export ALLOWED_FLAGS="${ALLOWED_FLAGS} -O -O0 -O1 -O2 -mcpu -march -mtune";
  4697. export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fstack-protector -fstack-protector-all";
  4698. export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fbounds-checking -fno-strict-overflow";
  4699. export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-PIE -fno-pie -fno-unit-at-a-time";
  4700. export ALLOWED_FLAGS="${ALLOWED_FLAGS} -g -g[0-9] -ggdb -ggdb[0-9] -gstabs -gstabs+";
  4701. export ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-ident -fpermissive";
  4702. export ALLOWED_FLAGS="${ALLOWED_FLAGS} -W* -w";
  4703. fi;
  4704. ALLOWED_FLAGS="${ALLOWED_FLAGS} -fno-stack-protector -fno-stack-protector-all -fno-strict-aliasing -fno-bounds-checking -fstrict-overflow -fno-omit-frame-pointer";
  4705. ALLOWED_FLAGS="${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 -mabi -mlittle-endian -mbig-endian -EL -EB -fPIC -mlive-g0 -mcmodel -mstack-bias -mno-stack-bias -msecure-plt -m*-toc -D* -U*";
  4706. ALLOWED_FLAGS="${ALLOWED_FLAGS} -mno-fma4 -mno-movbe -mno-xop -mno-lwp";
  4707. ALLOWED_FLAGS="${ALLOWED_FLAGS} -mno-fsgsbase -mno-rdrnd -mno-f16c -mno-bmi -mno-tbm";
  4708. export UNSTABLE_FLAGS="-Os -O3 -freorder-blocks";
  4709. return 0
  4710. }
  4711. setup_minispecs_gcc_build_specs ()
  4712. {
  4713. if hardened_gcc_works pie; then
  4714. cat "${WORKDIR}"/specs/pie.specs >> "${WORKDIR}"/build.specs;
  4715. fi;
  4716. if hardened_gcc_works ssp; then
  4717. for s in ssp sspall;
  4718. do
  4719. cat "${WORKDIR}"/specs/${s}.specs >> "${WORKDIR}"/build.specs;
  4720. done;
  4721. fi;
  4722. for s in nostrict znow;
  4723. do
  4724. cat "${WORKDIR}"/specs/${s}.specs >> "${WORKDIR}"/build.specs;
  4725. done;
  4726. export GCC_SPECS="${WORKDIR}"/build.specs
  4727. }
  4728. setup_multilib_osdirnames ()
  4729. {
  4730. is_multilib || return 0;
  4731. local config;
  4732. local libdirs;
  4733. if [[ ${SYMLINK_LIB} == "yes" ]]; then
  4734. libdirs="../lib64 ../lib32";
  4735. else
  4736. libdirs="../lib64 ../lib";
  4737. fi;
  4738. case ${CTARGET} in
  4739. x86_64*-linux*)
  4740. config="i386"
  4741. ;;
  4742. powerpc64*-linux*)
  4743. config="rs6000"
  4744. ;;
  4745. sparc64*-linux*)
  4746. config="sparc"
  4747. ;;
  4748. s390x*-linux*)
  4749. config="s390"
  4750. ;;
  4751. *)
  4752. return 0
  4753. ;;
  4754. esac;
  4755. config+="/t-linux64";
  4756. einfo "updating multilib directories to be: ${libdirs}";
  4757. sed -i -e "/^MULTILIB_OSDIRNAMES/s:=.*:= ${libdirs}:" "${S}"/gcc/config/${config} || die
  4758. }
  4759. should_we_gcc_config ()
  4760. {
  4761. use bootstrap && return 0;
  4762. use build && return 0;
  4763. local curr_config;
  4764. curr_config=$(env -i ROOT="${ROOT}" gcc-config -c ${CTARGET} 2>&1) || return 0;
  4765. local curr_config_ver=$(env -i ROOT="${ROOT}" gcc-config -S ${curr_config} | awk '{print $2}');
  4766. local curr_branch_ver=$(get_version_component_range 1-2 ${curr_config_ver});
  4767. use multislot && return $([[ ${curr_config_ver} == ${GCC_CONFIG_VER} ]]);
  4768. if [[ ${curr_branch_ver} == ${GCC_BRANCH_VER} ]]; then
  4769. return 0;
  4770. else
  4771. einfo "The current gcc config appears valid, so it will not be";
  4772. einfo "automatically switched for you. If you would like to";
  4773. einfo "switch to the newly installed gcc version, do the";
  4774. einfo "following:";
  4775. echo;
  4776. einfo "gcc-config ${CTARGET}-${GCC_CONFIG_VER}";
  4777. einfo "source /etc/profile";
  4778. echo;
  4779. ebeep;
  4780. return 1;
  4781. fi
  4782. }
  4783. split_out_specs_files ()
  4784. {
  4785. local s spec_list="hardenednopiessp vanilla";
  4786. if hardened_gcc_works; then
  4787. spec_list="${spec_list} hardened hardenednossp hardenednopie";
  4788. else
  4789. if hardened_gcc_works pie; then
  4790. spec_list="${spec_list} hardenednossp";
  4791. else
  4792. if hardened_gcc_works ssp; then
  4793. spec_list="${spec_list} hardenednopie";
  4794. fi;
  4795. fi;
  4796. fi;
  4797. for s in ${spec_list};
  4798. do
  4799. create_${s}_specs_file || return 1;
  4800. done
  4801. }
  4802. src_compile ()
  4803. {
  4804. toolchain_src_compile "$@"
  4805. }
  4806. src_install ()
  4807. {
  4808. toolchain_src_install "$@"
  4809. }
  4810. src_test ()
  4811. {
  4812. toolchain_src_test "$@"
  4813. }
  4814. src_unpack ()
  4815. {
  4816. gcc_src_unpack;
  4817. use vanilla && return 0;
  4818. sed -i 's/use_fixproto=yes/:/' gcc/config.gcc;
  4819. [[ ${CHOST} == ${CTARGET} ]] && epatch "${FILESDIR}"/gcc-spec-env.patch;
  4820. [[ ${CTARGET} == *-softfloat-* ]] && epatch "${FILESDIR}"/4.4.0/gcc-4.4.0-softfloat.patch
  4821. }
  4822. strip-flags ()
  4823. {
  4824. local x y flag NEW_CFLAGS NEW_CXXFLAGS NEW_FFLAGS NEW_FCFLAGS;
  4825. setup-allowed-flags;
  4826. local NEW_CFLAGS="";
  4827. local NEW_CXXFLAGS="";
  4828. local NEW_FFLAGS="";
  4829. local NEW_FCFLAGS="";
  4830. if has "~$(tc-arch)" ${ACCEPT_KEYWORDS}; then
  4831. ALLOWED_FLAGS="${ALLOWED_FLAGS} ${UNSTABLE_FLAGS}";
  4832. fi;
  4833. set -f;
  4834. for x in ${CFLAGS};
  4835. do
  4836. for y in ${ALLOWED_FLAGS};
  4837. do
  4838. flag=${x%%=*};
  4839. if [ "${flag%%${y}}" = "" ]; then
  4840. NEW_CFLAGS="${NEW_CFLAGS} ${x}";
  4841. break;
  4842. fi;
  4843. done;
  4844. done;
  4845. for x in ${CXXFLAGS};
  4846. do
  4847. for y in ${ALLOWED_FLAGS};
  4848. do
  4849. flag=${x%%=*};
  4850. if [ "${flag%%${y}}" = "" ]; then
  4851. NEW_CXXFLAGS="${NEW_CXXFLAGS} ${x}";
  4852. break;
  4853. fi;
  4854. done;
  4855. done;
  4856. for x in ${FFLAGS};
  4857. do
  4858. for y in ${ALLOWED_FLAGS};
  4859. do
  4860. flag=${x%%=*};
  4861. if [ "${flag%%${y}}" = "" ]; then
  4862. NEW_FFLAGS="${NEW_FFLAGS} ${x}";
  4863. break;
  4864. fi;
  4865. done;
  4866. done;
  4867. for x in ${FCFLAGS};
  4868. do
  4869. for y in ${ALLOWED_FLAGS};
  4870. do
  4871. flag=${x%%=*};
  4872. if [ "${flag%%${y}}" = "" ]; then
  4873. NEW_FCFLAGS="${NEW_FCFLAGS} ${x}";
  4874. break;
  4875. fi;
  4876. done;
  4877. done;
  4878. if [ "${CFLAGS/-O}" != "${CFLAGS}" -a "${NEW_CFLAGS/-O}" = "${NEW_CFLAGS}" ]; then
  4879. NEW_CFLAGS="${NEW_CFLAGS} -O2";
  4880. fi;
  4881. if [ "${CXXFLAGS/-O}" != "${CXXFLAGS}" -a "${NEW_CXXFLAGS/-O}" = "${NEW_CXXFLAGS}" ]; then
  4882. NEW_CXXFLAGS="${NEW_CXXFLAGS} -O2";
  4883. fi;
  4884. if [ "${FFLAGS/-O}" != "${FFLAGS}" -a "${NEW_FFLAGS/-O}" = "${NEW_FFLAGS}" ]; then
  4885. NEW_FFLAGS="${NEW_FFLAGS} -O2";
  4886. fi;
  4887. if [ "${FCFLAGS/-O}" != "${FCFLAGS}" -a "${NEW_FCFLAGS/-O}" = "${NEW_FCFLAGS}" ]; then
  4888. NEW_FCFLAGS="${NEW_FCFLAGS} -O2";
  4889. fi;
  4890. set +f;
  4891. export CFLAGS="${NEW_CFLAGS}";
  4892. export CXXFLAGS="${NEW_CXXFLAGS}";
  4893. export FFLAGS="${NEW_FFLAGS}";
  4894. export FCFLAGS="${NEW_FCFLAGS}";
  4895. return 0
  4896. }
  4897. strip-linguas ()
  4898. {
  4899. local ls newls nols;
  4900. if [[ $1 == "-i" ]] || [[ $1 == "-u" ]]; then
  4901. local op=$1;
  4902. shift;
  4903. ls=$(find "$1" -name '*.po' -exec basename {} .po ';');
  4904. shift;
  4905. local d f;
  4906. for d in "$@";
  4907. do
  4908. if [[ ${op} == "-u" ]]; then
  4909. newls=${ls};
  4910. else
  4911. newls="";
  4912. fi;
  4913. for f in $(find "$d" -name '*.po' -exec basename {} .po ';');
  4914. do
  4915. if [[ ${op} == "-i" ]]; then
  4916. hasq ${f} ${ls} && newls="${newls} ${f}";
  4917. else
  4918. hasq ${f} ${ls} || newls="${newls} ${f}";
  4919. fi;
  4920. done;
  4921. ls=${newls};
  4922. done;
  4923. else
  4924. ls="$@";
  4925. fi;
  4926. nols="";
  4927. newls="";
  4928. for f in ${LINGUAS};
  4929. do
  4930. if hasq ${f} ${ls}; then
  4931. newls="${newls} ${f}";
  4932. else
  4933. nols="${nols} ${f}";
  4934. fi;
  4935. done;
  4936. [[ -n ${nols} ]] && ewarn "Sorry, but ${PN} does not support the LINGUAS:" ${nols};
  4937. export LINGUAS=${newls:1}
  4938. }
  4939. strip-unsupported-flags ()
  4940. {
  4941. export CFLAGS=$(test-flags-CC ${CFLAGS});
  4942. export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS});
  4943. export FFLAGS=$(test-flags-F77 ${FFLAGS});
  4944. export FCFLAGS=$(test-flags-FC ${FCFLAGS})
  4945. }
  4946. tc-arch ()
  4947. {
  4948. tc-ninja_magic_to_arch portage "$@"
  4949. }
  4950. tc-arch-kernel ()
  4951. {
  4952. tc-ninja_magic_to_arch kern "$@"
  4953. }
  4954. tc-endian ()
  4955. {
  4956. local host=$1;
  4957. [[ -z ${host} ]] && host=${CTARGET:-${CHOST}};
  4958. host=${host%%-*};
  4959. case ${host} in
  4960. alpha*)
  4961. echo big
  4962. ;;
  4963. arm*b*)
  4964. echo big
  4965. ;;
  4966. arm*)
  4967. echo little
  4968. ;;
  4969. cris*)
  4970. echo little
  4971. ;;
  4972. hppa*)
  4973. echo big
  4974. ;;
  4975. i?86*)
  4976. echo little
  4977. ;;
  4978. ia64*)
  4979. echo little
  4980. ;;
  4981. m68*)
  4982. echo big
  4983. ;;
  4984. mips*l*)
  4985. echo little
  4986. ;;
  4987. mips*)
  4988. echo big
  4989. ;;
  4990. powerpc*)
  4991. echo big
  4992. ;;
  4993. s390*)
  4994. echo big
  4995. ;;
  4996. sh*b*)
  4997. echo big
  4998. ;;
  4999. sh*)
  5000. echo little
  5001. ;;
  5002. sparc*)
  5003. echo big
  5004. ;;
  5005. x86_64*)
  5006. echo little
  5007. ;;
  5008. *)
  5009. echo wtf
  5010. ;;
  5011. esac
  5012. }
  5013. tc-export ()
  5014. {
  5015. local var;
  5016. for var in "$@";
  5017. do
  5018. [[ $(type -t tc-get${var}) != "function" ]] && die "tc-export: invalid export variable '${var}'";
  5019. eval tc-get${var} > /dev/null;
  5020. done
  5021. }
  5022. tc-getAR ()
  5023. {
  5024. tc-getPROG AR ar "$@"
  5025. }
  5026. tc-getAS ()
  5027. {
  5028. tc-getPROG AS as "$@"
  5029. }
  5030. tc-getBUILD_CC ()
  5031. {
  5032. local v;
  5033. for v in CC_FOR_BUILD BUILD_CC HOSTCC;
  5034. do
  5035. if [[ -n ${!v} ]]; then
  5036. export BUILD_CC=${!v};
  5037. echo "${!v}";
  5038. return 0;
  5039. fi;
  5040. done;
  5041. local search=;
  5042. if [[ -n ${CBUILD} ]]; then
  5043. search=$(type -p ${CBUILD}-gcc);
  5044. search=${search##*/};
  5045. fi;
  5046. search=${search:-gcc};
  5047. export BUILD_CC=${search};
  5048. echo "${search}"
  5049. }
  5050. tc-getCC ()
  5051. {
  5052. tc-getPROG CC gcc "$@"
  5053. }
  5054. tc-getCPP ()
  5055. {
  5056. tc-getPROG CPP cpp "$@"
  5057. }
  5058. tc-getCXX ()
  5059. {
  5060. tc-getPROG CXX g++ "$@"
  5061. }
  5062. tc-getDLLWRAP ()
  5063. {
  5064. tc-getPROG DLLWRAP dllwrap "$@"
  5065. }
  5066. tc-getF77 ()
  5067. {
  5068. tc-getPROG F77 gfortran "$@"
  5069. }
  5070. tc-getFC ()
  5071. {
  5072. tc-getPROG FC gfortran "$@"
  5073. }
  5074. tc-getGCJ ()
  5075. {
  5076. tc-getPROG GCJ gcj "$@"
  5077. }
  5078. tc-getLD ()
  5079. {
  5080. tc-getPROG LD ld "$@"
  5081. }
  5082. tc-getNM ()
  5083. {
  5084. tc-getPROG NM nm "$@"
  5085. }
  5086. tc-getOBJCOPY ()
  5087. {
  5088. tc-getPROG OBJCOPY objcopy "$@"
  5089. }
  5090. tc-getPKG_CONFIG ()
  5091. {
  5092. tc-getPROG PKG_CONFIG pkg-config "$@"
  5093. }
  5094. tc-getPROG ()
  5095. {
  5096. local var=$1;
  5097. local prog=$2;
  5098. if [[ -n ${!var} ]]; then
  5099. echo "${!var}";
  5100. return 0;
  5101. fi;
  5102. local search=;
  5103. [[ -n $3 ]] && search=$(type -p "$3-${prog}");
  5104. [[ -z ${search} && -n ${CHOST} ]] && search=$(type -p "${CHOST}-${prog}");
  5105. [[ -n ${search} ]] && prog=${search##*/};
  5106. export ${var}=${prog};
  5107. echo "${!var}"
  5108. }
  5109. tc-getRANLIB ()
  5110. {
  5111. tc-getPROG RANLIB ranlib "$@"
  5112. }
  5113. tc-getRC ()
  5114. {
  5115. tc-getPROG RC windres "$@"
  5116. }
  5117. tc-getSTRIP ()
  5118. {
  5119. tc-getPROG STRIP strip "$@"
  5120. }
  5121. tc-has-openmp ()
  5122. {
  5123. local base="${T}/test-tc-openmp";
  5124. cat > "${base}.c" <<-EOF
  5125. #include <omp.h>
  5126. int main() {
  5127. int nthreads, tid, ret = 0;
  5128. #pragma omp parallel private(nthreads, tid)
  5129. {
  5130. tid = omp_get_thread_num();
  5131. nthreads = omp_get_num_threads(); ret += tid + nthreads;
  5132. }
  5133. return ret;
  5134. }
  5135. EOF
  5136.  
  5137. $(tc-getCC "$@") -fopenmp "${base}.c" -o "${base}" &>/dev/null;
  5138. local ret=$?;
  5139. rm -f "${base}"*;
  5140. return ${ret}
  5141. }
  5142. tc-has-tls ()
  5143. {
  5144. local base="${T}/test-tc-tls";
  5145. cat > "${base}.c" <<-EOF
  5146. int foo(int *i) {
  5147. static __thread int j = 0;
  5148. return *i ? j : *i;
  5149. }
  5150. EOF
  5151.  
  5152. local flags;
  5153. case $1 in
  5154. -s)
  5155. flags="-S"
  5156. ;;
  5157. -c)
  5158. flags="-c"
  5159. ;;
  5160. -l)
  5161.  
  5162. ;;
  5163. -*)
  5164. die "Usage: tc-has-tls [-c|-l] [toolchain prefix]"
  5165. ;;
  5166. esac;
  5167. : ${flags:=-fPIC -shared -Wl,-z,defs};
  5168. [[ $1 == -* ]] && shift;
  5169. $(tc-getCC "$@") ${flags} "${base}.c" -o "${base}" &>/dev/null;
  5170. local ret=$?;
  5171. rm -f "${base}"*;
  5172. return ${ret}
  5173. }
  5174. tc-is-cross-compiler ()
  5175. {
  5176. return $([[ ${CBUILD:-${CHOST}} != ${CHOST} ]])
  5177. }
  5178. tc-is-hardfloat ()
  5179. {
  5180. [[ ${CTARGET//_/-} == *-hardfloat-* ]] && echo "yes" || echo "no"
  5181. }
  5182. tc-is-softfloat ()
  5183. {
  5184. case ${CTARGET} in
  5185. bfin* | h8300*)
  5186. echo "only"
  5187. ;;
  5188. *)
  5189. [[ ${CTARGET//_/-} == *-softfloat-* ]] && echo "yes" || echo "no"
  5190. ;;
  5191. esac
  5192. }
  5193. tc-is-static-only ()
  5194. {
  5195. local host=${CTARGET:-${CHOST}};
  5196. return $([[ ${host} == *-mint* ]])
  5197. }
  5198. tc-ninja_magic_to_arch ()
  5199. {
  5200. function ninj ()
  5201. {
  5202. [[ ${type} == "kern" ]] && echo $1 || echo $2
  5203. };
  5204. local type=$1;
  5205. local host=$2;
  5206. [[ -z ${host} ]] && host=${CTARGET:-${CHOST}};
  5207. case ${host} in
  5208. alpha*)
  5209. echo alpha
  5210. ;;
  5211. arm*)
  5212. echo arm
  5213. ;;
  5214. avr*)
  5215. ninj avr32 avr
  5216. ;;
  5217. bfin*)
  5218. ninj blackfin bfin
  5219. ;;
  5220. cris*)
  5221. echo cris
  5222. ;;
  5223. hppa*)
  5224. ninj parisc hppa
  5225. ;;
  5226. i?86*)
  5227. if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -lt $(KV_to_int 2.6.24) || ${host} == *freebsd* ]]; then
  5228. echo i386;
  5229. else
  5230. echo x86;
  5231. fi
  5232. ;;
  5233. ia64*)
  5234. echo ia64
  5235. ;;
  5236. m68*)
  5237. echo m68k
  5238. ;;
  5239. mips*)
  5240. echo mips
  5241. ;;
  5242. nios2*)
  5243. echo nios2
  5244. ;;
  5245. nios*)
  5246. echo nios
  5247. ;;
  5248. powerpc*)
  5249. if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.16) ]]; then
  5250. echo powerpc;
  5251. else
  5252. if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -eq $(KV_to_int 2.6.15) ]]; then
  5253. if [[ ${host} == powerpc64* ]] || [[ ${PROFILE_ARCH} == "ppc64" ]]; then
  5254. echo powerpc;
  5255. else
  5256. echo ppc;
  5257. fi;
  5258. else
  5259. if [[ ${host} == powerpc64* ]]; then
  5260. echo ppc64;
  5261. else
  5262. if [[ ${PROFILE_ARCH} == "ppc64" ]]; then
  5263. ninj ppc64 ppc;
  5264. else
  5265. echo ppc;
  5266. fi;
  5267. fi;
  5268. fi;
  5269. fi
  5270. ;;
  5271. s390*)
  5272. echo s390
  5273. ;;
  5274. sh64*)
  5275. ninj sh64 sh
  5276. ;;
  5277. sh*)
  5278. echo sh
  5279. ;;
  5280. sparc64*)
  5281. ninj sparc64 sparc
  5282. ;;
  5283. sparc*)
  5284. [[ ${PROFILE_ARCH} == "sparc64" ]] && ninj sparc64 sparc || echo sparc
  5285. ;;
  5286. vax*)
  5287. echo vax
  5288. ;;
  5289. x86_64*)
  5290. if [[ ${type} == "kern" ]] && [[ $(KV_to_int ${KV}) -ge $(KV_to_int 2.6.24) ]]; then
  5291. echo x86;
  5292. else
  5293. ninj x86_64 amd64;
  5294. fi
  5295. ;;
  5296. *)
  5297. echo unknown
  5298. ;;
  5299. esac
  5300. }
  5301. tc_version_is_at_least ()
  5302. {
  5303. version_is_at_least "$1" "${2:-${GCC_RELEASE_VER}}"
  5304. }
  5305. test-flag-CC ()
  5306. {
  5307. test-flag-PROG "CC" "$1"
  5308. }
  5309. test-flag-CXX ()
  5310. {
  5311. test-flag-PROG "CXX" "$1"
  5312. }
  5313. test-flag-F77 ()
  5314. {
  5315. test-flag-PROG "F77" "$1"
  5316. }
  5317. test-flag-FC ()
  5318. {
  5319. test-flag-PROG "FC" "$1"
  5320. }
  5321. test-flag-PROG ()
  5322. {
  5323. local comp=$1;
  5324. local flags="$2";
  5325. [[ -z ${comp} || -z ${flags} ]] && return 1;
  5326. local PROG=$(tc-get${comp});
  5327. ${PROG} ${flags} -S -o /dev/null -xc /dev/null > /dev/null 2>&1
  5328. }
  5329. test-flags ()
  5330. {
  5331. test-flags-CC "$@"
  5332. }
  5333. test-flags-CC ()
  5334. {
  5335. test-flags-PROG "CC" "$@"
  5336. }
  5337. test-flags-CXX ()
  5338. {
  5339. test-flags-PROG "CXX" "$@"
  5340. }
  5341. test-flags-F77 ()
  5342. {
  5343. test-flags-PROG "F77" "$@"
  5344. }
  5345. test-flags-FC ()
  5346. {
  5347. test-flags-PROG "FC" "$@"
  5348. }
  5349. test-flags-PROG ()
  5350. {
  5351. local comp=$1;
  5352. local flags;
  5353. local x;
  5354. shift;
  5355. [[ -z ${comp} ]] && return 1;
  5356. x="";
  5357. for x in "$@";
  5358. do
  5359. test-flag-${comp} "${x}" && flags="${flags}${flags:+ }${x}";
  5360. done;
  5361. echo "${flags}";
  5362. [[ -n ${flags} ]]
  5363. }
  5364. test_flag ()
  5365. {
  5366. ewarn "test_flag: deprecated, please use test-flags()!" 1>&2;
  5367. test-flags-CC "$@"
  5368. }
  5369. test_version_info ()
  5370. {
  5371. if [[ $($(tc-getCC) --version 2>&1) == *$1* ]]; then
  5372. return 0;
  5373. else
  5374. return 1;
  5375. fi
  5376. }
  5377. toolchain_pkg_postinst ()
  5378. {
  5379. ${ETYPE}_pkg_postinst
  5380. }
  5381. toolchain_pkg_postrm ()
  5382. {
  5383. ${ETYPE}_pkg_postrm
  5384. }
  5385. toolchain_pkg_preinst ()
  5386. {
  5387. ${ETYPE}_pkg_preinst
  5388. }
  5389. toolchain_pkg_prerm ()
  5390. {
  5391. ${ETYPE}_pkg_prerm
  5392. }
  5393. toolchain_pkg_setup ()
  5394. {
  5395. gcc_pkg_setup
  5396. }
  5397. toolchain_src_compile ()
  5398. {
  5399. gcc_src_compile
  5400. }
  5401. toolchain_src_install ()
  5402. {
  5403. ${ETYPE}_src_install
  5404. }
  5405. toolchain_src_test ()
  5406. {
  5407. gcc_src_test
  5408. }
  5409. toolchain_src_unpack ()
  5410. {
  5411. gcc_src_unpack
  5412. }
  5413. treecopy ()
  5414. {
  5415. dest=${!#};
  5416. files_count=$#;
  5417. while (( $# > 1 )); do
  5418. dirstruct=$(dirname "$1");
  5419. mkdir -p "${dest}/${dirstruct}";
  5420. cp -pPR "$1" "${dest}/${dirstruct}";
  5421. shift;
  5422. done
  5423. }
  5424. uclibctoolize ()
  5425. {
  5426. die "Use elibtoolize"
  5427. }
  5428. unpack_makeself ()
  5429. {
  5430. local src_input=${1:-${A}};
  5431. local src=$(find_unpackable_file "${src_input}");
  5432. local skip=$2;
  5433. local exe=$3;
  5434. [[ -z ${src} ]] && die "Could not locate source for '${src_input}'";
  5435. local shrtsrc=$(basename "${src}");
  5436. echo ">>> Unpacking ${shrtsrc} to ${PWD}";
  5437. if [[ -z ${skip} ]]; then
  5438. local ver=$(grep -m1 -a '#.*Makeself' "${src}" | awk '{print $NF}');
  5439. local skip=0;
  5440. exe=tail;
  5441. case ${ver} in
  5442. 1.5.* | 1.6.0-nv)
  5443. skip=$(grep -a ^skip= "${src}" | cut -d= -f2)
  5444. ;;
  5445. 2.0 | 2.0.1)
  5446. skip=$(grep -a ^' 'tail "${src}" | awk '{print $2}' | cut -b2-)
  5447. ;;
  5448. 2.1.1)
  5449. skip=$(grep -a ^offset= "${src}" | awk '{print $2}' | cut -b2-);
  5450. (( skip++ ))
  5451. ;;
  5452. 2.1.2)
  5453. skip=$(grep -a ^offset= "${src}" | awk '{print $3}' | head -n 1);
  5454. (( skip++ ))
  5455. ;;
  5456. 2.1.3)
  5457. skip=`grep -a ^offset= "${src}" | awk '{print $3}'`;
  5458. (( skip++ ))
  5459. ;;
  5460. 2.1.4 | 2.1.5)
  5461. skip=$(grep -a offset=.*head.*wc "${src}" | awk '{print $3}' | head -n 1);
  5462. skip=$(head -n ${skip} "${src}" | wc -c);
  5463. exe="dd"
  5464. ;;
  5465. *)
  5466. eerror "I'm sorry, but I was unable to support the Makeself file.";
  5467. eerror "The version I detected was '${ver}'.";
  5468. eerror "Please file a bug about the file ${shrtsrc} at";
  5469. eerror "http://bugs.gentoo.org/ so that support can be added.";
  5470. die "makeself version '${ver}' not supported"
  5471. ;;
  5472. esac;
  5473. debug-print "Detected Makeself version ${ver} ... using ${skip} as offset";
  5474. fi;
  5475. case ${exe} in
  5476. tail)
  5477. exe="tail -n +${skip} '${src}'"
  5478. ;;
  5479. dd)
  5480. exe="dd ibs=${skip} skip=1 if='${src}'"
  5481. ;;
  5482. *)
  5483. die "makeself cant handle exe '${exe}'"
  5484. ;;
  5485. esac;
  5486. local filetype tmpfile=$(emktemp);
  5487. eval ${exe} 2> /dev/null | head -c 512 > "${tmpfile}";
  5488. filetype=$(file -b "${tmpfile}") || die;
  5489. case ${filetype} in
  5490. *tar\ archive*)
  5491. eval ${exe} | tar --no-same-owner -xf -
  5492. ;;
  5493. bzip2*)
  5494. eval ${exe} | bzip2 -dc | tar --no-same-owner -xf -
  5495. ;;
  5496. gzip*)
  5497. eval ${exe} | tar --no-same-owner -xzf -
  5498. ;;
  5499. compress*)
  5500. eval ${exe} | gunzip | tar --no-same-owner -xf -
  5501. ;;
  5502. *)
  5503. eerror "Unknown filetype \"${filetype}\" ?";
  5504. false
  5505. ;;
  5506. esac;
  5507. assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})"
  5508. }
  5509. unpack_pdv ()
  5510. {
  5511. local src=$(find_unpackable_file "$1");
  5512. local sizeoff_t=$2;
  5513. [[ -z ${src} ]] && die "Could not locate source for '$1'";
  5514. [[ -z ${sizeoff_t} ]] && die "No idea what off_t size was used for this pdv :(";
  5515. local shrtsrc=$(basename "${src}");
  5516. echo ">>> Unpacking ${shrtsrc} to ${PWD}";
  5517. local metaskip=$(tail -c ${sizeoff_t} "${src}" | hexdump -e \"%i\");
  5518. local tailskip=$(tail -c $((${sizeoff_t}*2)) "${src}" | head -c ${sizeoff_t} | hexdump -e \"%i\");
  5519. local metafile=$(emktemp);
  5520. tail -c +$((${metaskip}+1)) "${src}" > "${metafile}";
  5521. local datafile=$(tail -c +$((${metaskip}+1)) "${src}" | strings | head -n 1);
  5522. datafile=$(basename "${datafile}");
  5523. local tmpfile=$(emktemp);
  5524. tail -c +$((${tailskip}+1)) ${src} 2> /dev/null | head -c 512 > ${tmpfile};
  5525. local iscompressed=$(file -b "${tmpfile}");
  5526. if [[ ${iscompressed:0:8} == "compress" ]]; then
  5527. iscompressed=1;
  5528. mv ${tmpfile}{,.Z};
  5529. gunzip ${tmpfile};
  5530. else
  5531. iscompressed=0;
  5532. fi;
  5533. local istar=$(file -b "${tmpfile}");
  5534. if [[ ${istar:0:9} == "POSIX tar" ]]; then
  5535. istar=1;
  5536. else
  5537. istar=0;
  5538. fi;
  5539. if [ ${iscompressed} -eq 1 ]; then
  5540. if [ ${istar} -eq 1 ]; then
  5541. tail -c +$((${tailskip}+1)) ${src} 2> /dev/null | head -c $((${metaskip}-${tailskip})) | tar -xzf -;
  5542. else
  5543. tail -c +$((${tailskip}+1)) ${src} 2> /dev/null | head -c $((${metaskip}-${tailskip})) | gzip -dc > ${datafile};
  5544. fi;
  5545. else
  5546. if [ ${istar} -eq 1 ]; then
  5547. tail -c +$((${tailskip}+1)) ${src} 2> /dev/null | head -c $((${metaskip}-${tailskip})) | tar --no-same-owner -xf -;
  5548. else
  5549. tail -c +$((${tailskip}+1)) ${src} 2> /dev/null | head -c $((${metaskip}-${tailskip})) > ${datafile};
  5550. fi;
  5551. fi;
  5552. true
  5553. }
  5554. update_gcc_for_libc_ssp ()
  5555. {
  5556. if libc_has_ssp; then
  5557. einfo "Updating gcc to use SSP from libc ...";
  5558. sed -e 's|^\(LIBGCC2_CFLAGS.*\)$|\1 -D_LIBC_PROVIDES_SSP_|' -i "${S}"/gcc/Makefile.in || die "Failed to update gcc!";
  5559. fi
  5560. }
  5561. update_gcc_for_libssp ()
  5562. {
  5563. einfo "Updating gcc to use SSP from libssp...";
  5564. sed -e 's|^\(INTERNAL_CFLAGS.*\)$|\1 -D_LIBSSP_PROVIDES_SSP_|' -i "${S}"/gcc/Makefile.in || die "Failed to update gcc!"
  5565. }
  5566. validate_desktop_entries ()
  5567. {
  5568. if [[ -x /usr/bin/desktop-file-validate ]]; then
  5569. einfo "Checking desktop entry validity";
  5570. local directories="";
  5571. for d in /usr/share/applications $@;
  5572. do
  5573. [[ -d ${D}${d} ]] && directories="${directories} ${D}${d}";
  5574. done;
  5575. if [[ -n ${directories} ]]; then
  5576. for FILE in $(find ${directories} -name "*\.desktop" -not -path '*.hidden*' | sort -u 2>/dev/null);
  5577. do
  5578. local temp=$(desktop-file-validate ${FILE} | grep -v "warning:" | sed -e "s|error: ||" -e "s|${FILE}:|--|g" );
  5579. [[ -n $temp ]] && elog ${temp/--/${FILE/${D}/}:};
  5580. done;
  5581. fi;
  5582. echo "";
  5583. else
  5584. einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo.";
  5585. fi
  5586. }
  5587. version_compare ()
  5588. {
  5589. eshopts_push -s extglob;
  5590. local ver_a=${1} ver_b=${2} parts_a parts_b cur_idx_a=0 cur_idx_b=0;
  5591. parts_a=($(get_all_version_components "${ver_a}" ));
  5592. parts_b=($(get_all_version_components "${ver_b}" ));
  5593. local inf_loop=0;
  5594. while true; do
  5595. inf_loop=$(( ${inf_loop} + 1 ));
  5596. [[ ${inf_loop} -gt 20 ]] && die "versionator compare bug [numbers, ${ver_a}, ${ver_b}]";
  5597. local cur_tok_a=${parts_a[${cur_idx_a}]};
  5598. local cur_tok_b=${parts_b[${cur_idx_b}]};
  5599. if [[ -n ${cur_tok_a} ]] && [[ -z ${cur_tok_a//[[:digit:]]} ]]; then
  5600. cur_idx_a=$(( ${cur_idx_a} + 1 ));
  5601. [[ ${parts_a[${cur_idx_a}]} == "." ]] && cur_idx_a=$(( ${cur_idx_a} + 1 ));
  5602. else
  5603. cur_tok_a="";
  5604. fi;
  5605. if [[ -n ${cur_tok_b} ]] && [[ -z ${cur_tok_b//[[:digit:]]} ]]; then
  5606. cur_idx_b=$(( ${cur_idx_b} + 1 ));
  5607. [[ ${parts_b[${cur_idx_b}]} == "." ]] && cur_idx_b=$(( ${cur_idx_b} + 1 ));
  5608. else
  5609. cur_tok_b="";
  5610. fi;
  5611. [[ -z ${cur_tok_a} ]] && [[ -z ${cur_tok_b} ]] && break;
  5612. cur_tok_a=${cur_tok_a##+(0)};
  5613. cur_tok_b=${cur_tok_b##+(0)};
  5614. [[ -z ${cur_tok_a} ]] && cur_tok_a=0;
  5615. [[ -z ${cur_tok_b} ]] && cur_tok_b=0;
  5616. [[ ${cur_tok_a} -lt ${cur_tok_b} ]] && eshopts_pop && return 1;
  5617. [[ ${cur_tok_a} -gt ${cur_tok_b} ]] && eshopts_pop && return 3;
  5618. done;
  5619. local letter_a=;
  5620. letter_a=${parts_a[${cur_idx_a}]};
  5621. if [[ ${#letter_a} -eq 1 ]] && [[ -z ${letter_a/[a-z]} ]]; then
  5622. cur_idx_a=$(( ${cur_idx_a} + 1 ));
  5623. else
  5624. letter_a="@";
  5625. fi;
  5626. local letter_b=;
  5627. letter_b=${parts_b[${cur_idx_b}]};
  5628. if [[ ${#letter_b} -eq 1 ]] && [[ -z ${letter_b/[a-z]} ]]; then
  5629. cur_idx_b=$(( ${cur_idx_b} + 1 ));
  5630. else
  5631. letter_b="@";
  5632. fi;
  5633. [[ ${letter_a} < ${letter_b} ]] && eshopts_pop && return 1;
  5634. [[ ${letter_a} > ${letter_b} ]] && eshopts_pop && return 3;
  5635. local suffix rule part r_lt r_gt;
  5636. for rule in "alpha=1" "beta=1" "pre=1" "rc=1" "p=3" "r=3";
  5637. do
  5638. suffix=${rule%%=*};
  5639. r_lt=${rule##*=};
  5640. [[ ${r_lt} -eq 1 ]] && r_gt=3 || r_gt=1;
  5641. local suffix_a=;
  5642. for part in ${parts_a[@]};
  5643. do
  5644. [[ ${part#${suffix}} != ${part} ]] && [[ -z ${part##${suffix}*([[:digit:]])} ]] && suffix_a=${part#${suffix}}0;
  5645. done;
  5646. local suffix_b=;
  5647. for part in ${parts_b[@]};
  5648. do
  5649. [[ ${part#${suffix}} != ${part} ]] && [[ -z ${part##${suffix}*([[:digit:]])} ]] && suffix_b=${part#${suffix}}0;
  5650. done;
  5651. [[ -z ${suffix_a} ]] && [[ -z ${suffix_b} ]] && continue;
  5652. [[ -z ${suffix_a} ]] && eshopts_pop && return ${r_gt};
  5653. [[ -z ${suffix_b} ]] && eshopts_pop && return ${r_lt};
  5654. suffix_a=${suffix_a##+(0)};
  5655. suffix_a=${suffix_a:-0};
  5656. suffix_b=${suffix_b##+(0)};
  5657. suffix_b=${suffix_b:-0};
  5658. [[ ${suffix_a} -lt ${suffix_b} ]] && eshopts_pop && return 1;
  5659. [[ ${suffix_a} -gt ${suffix_b} ]] && eshopts_pop && return 3;
  5660. done;
  5661. eshopts_pop;
  5662. return 2
  5663. }
  5664. version_format_string ()
  5665. {
  5666. local fstr=$1;
  5667. shift;
  5668. set -- $(get_version_components "$@");
  5669. eval echo "${fstr}"
  5670. }
  5671. version_is_at_least ()
  5672. {
  5673. eshopts_push -s extglob;
  5674. local want_s="$1" have_s="${2:-${PVR}}" r;
  5675. version_compare "${want_s}" "${have_s}";
  5676. r=$?;
  5677. case $r in
  5678. 1 | 2)
  5679. eshopts_pop;
  5680. return 0
  5681. ;;
  5682. 3)
  5683. eshopts_pop;
  5684. return 1
  5685. ;;
  5686. *)
  5687. eshopts_pop;
  5688. die "versionator compare bug [atleast, ${want_s}, ${have_s}, ${r}]"
  5689. ;;
  5690. esac;
  5691. eshopts_pop
  5692. }
  5693. version_sort ()
  5694. {
  5695. eshopts_push -s extglob;
  5696. local items= left=0;
  5697. items=($@);
  5698. while [[ ${left} -lt ${#items[@]} ]]; do
  5699. local lowest_idx=${left};
  5700. local idx=$(( ${lowest_idx} + 1 ));
  5701. while [[ ${idx} -lt ${#items[@]} ]]; do
  5702. version_compare "${items[${lowest_idx}]}" "${items[${idx}]}";
  5703. [[ $? -eq 3 ]] && lowest_idx=${idx};
  5704. idx=$(( ${idx} + 1 ));
  5705. done;
  5706. local tmp=${items[${lowest_idx}]};
  5707. items[${lowest_idx}]=${items[${left}]};
  5708. items[${left}]=${tmp};
  5709. left=$(( ${left} + 1 ));
  5710. done;
  5711. echo ${items[@]};
  5712. eshopts_pop
  5713. }
  5714. want_boundschecking ()
  5715. {
  5716. _want_stuff HTB_VER boundschecking
  5717. }
  5718. want_libssp ()
  5719. {
  5720. [[ ${GCC_LIBSSP_SUPPORT} == "true" ]] || return 1;
  5721. has_libssp || return 1;
  5722. [[ -n ${PP_VER} ]] || return 1;
  5723. return 0
  5724. }
  5725. want_minispecs ()
  5726. {
  5727. if tc_version_is_at_least 4.3.2 && use hardened; then
  5728. if ! want_pie; then
  5729. ewarn "PIE_VER or SPECS_VER is not defiend in the GCC ebuild.";
  5730. else
  5731. if use vanilla; then
  5732. ewarn "You will not get hardened features if you have the vanilla USE-flag.";
  5733. else
  5734. if use nopie && use nossp; then
  5735. ewarn "You will not get hardened features if you have the nopie and nossp USE-flag.";
  5736. else
  5737. if ! hardened_gcc_works pie && ! hardened_gcc_works ssp && ! use nopie; then
  5738. ewarn "Your $(tc-arch) arch is not supported.";
  5739. else
  5740. return 0;
  5741. fi;
  5742. fi;
  5743. fi;
  5744. fi;
  5745. ewarn "Hope you know what you are doing. Hardened will not work.";
  5746. return 0;
  5747. fi;
  5748. return 1
  5749. }
  5750. want_pie ()
  5751. {
  5752. ! use hardened && [[ -n ${PIE_VER} ]] && use nopie && return 1;
  5753. [[ -n ${PIE_VER} ]] && [[ -n ${SPECS_VER} ]] && return 0;
  5754. tc_version_is_at_least 4.3.2 && return 1;
  5755. _want_stuff PIE_VER !nopie
  5756. }
  5757. want_split_specs ()
  5758. {
  5759. tc_version_is_at_least 4.4 && return 1;
  5760. [[ ${SPLIT_SPECS} == "true" ]] && want_pie
  5761. }
  5762. want_ssp ()
  5763. {
  5764. _want_stuff PP_VER !nossp
  5765. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement