gnatbuild.eclass 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  1. # Copyright 1999-2016 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. #
  4. # Author: George Shapovalov <george@gentoo.org>
  5. # Author: Steve Arnold <nerdboy@gentoo.org>
  6. # No maintainer <maintainer-needed@gentoo.org>
  7. #
  8. # Notes:
  9. # HOMEPAGE and LICENSE are set in appropriate ebuild, as
  10. # gnat is developed by FSF and AdaCore "in parallel"
  11. #
  12. # The following vars can be set in ebuild before inheriting this eclass. They
  13. # will be respected:
  14. # SLOT
  15. # BOOT_SLOT - where old bootstrap is used as it works fine
  16. #WANT_AUTOMAKE="1.8"
  17. #WANT_AUTOCONF="2.1"
  18. inherit eutils fixheadtails flag-o-matic gnuconfig libtool multilib pax-utils toolchain-funcs versionator
  19. FEATURES=${FEATURES/multilib-strict/}
  20. EXPORT_FUNCTIONS="pkg_setup pkg_postinst pkg_postrm src_unpack src_configure src_compile src_install"
  21. IUSE="nls"
  22. # multilib is supported via profiles now, multilib usevar is deprecated
  23. RDEPEND="app-eselect/eselect-gnat
  24. virtual/libiconv
  25. nls? ( virtual/libintl )"
  26. DEPEND="${RDEPEND}
  27. >=app-eselect/eselect-gnat-1.3-r1
  28. >=sys-libs/glibc-2.12
  29. >=sys-devel/binutils-2.23
  30. sys-devel/bc
  31. >=sys-devel/bison-1.875
  32. >=sys-devel/flex-2.5.4
  33. nls? ( sys-devel/gettext )"
  34. # Note!
  35. # It may not be safe to source this at top level. Only source inside local
  36. # functions!
  37. GnatCommon="/usr/share/gnat/lib/gnat-common.bash"
  38. #---->> globals and SLOT <<----
  39. # just a check, this location seems to vary too much, easier to track it in
  40. # ebuild
  41. #[ -z "${GNATSOURCE}" ] && die "please set GNATSOURCE in ebuild! (before inherit)"
  42. # versioning
  43. # because of gnatpro/gnatgpl we need to track both gcc and gnat versions
  44. # these simply default to $PV
  45. GNATMAJOR=$(get_version_component_range 1)
  46. GNATMINOR=$(get_version_component_range 2)
  47. GNATBRANCH=$(get_version_component_range 1-2)
  48. GNATRELEASE=$(get_version_component_range 1-3)
  49. # this one is for the gnat-gpl which is versioned by gcc backend and ACT version
  50. # number added on top
  51. ACT_Ver=$(get_version_component_range 4)
  52. # GCCVER and SLOT logic
  53. #
  54. # I better define vars for package names, as there was discussion on proper
  55. # naming and it may change
  56. PN_GnatGCC="gnat-gcc"
  57. PN_GnatGpl="gnat-gpl"
  58. # ATTN! GCCVER stands for the provided backend gcc, not the one on the system
  59. # so tc-* functions are of no use here. The present versioning scheme makes
  60. # GCCVER basically a part of PV, but *this may change*!!
  61. #
  62. # GCCVER can be set in the ebuild.
  63. [[ -z ${GCCVER} ]] && GCCVER="${GNATRELEASE}"
  64. # finally extract GCC version strings
  65. GCCMAJOR=$(get_version_component_range 1 "${GCCVER}")
  66. GCCMINOR=$(get_version_component_range 2 "${GCCVER}")
  67. GCCBRANCH=$(get_version_component_range 1-2 "${GCCVER}")
  68. GCCRELEASE=$(get_version_component_range 1-3 "${GCCVER}")
  69. # SLOT logic, make it represent gcc backend, as this is what matters most
  70. # There are some special cases, so we allow it to be defined in the ebuild
  71. # ATTN!! If you set SLOT in the ebuild, don't forget to make sure that
  72. # BOOT_SLOT is also set properly!
  73. [[ -z ${SLOT} ]] && SLOT="${GCCBRANCH}"
  74. # possible future crosscompilation support
  75. export CTARGET=${CTARGET:-${CHOST}}
  76. is_crosscompile() {
  77. [[ ${CHOST} != ${CTARGET} ]]
  78. }
  79. # Bootstrap CTARGET and SLOT logic. For now BOOT_TARGET=CHOST is "guaranteed" by
  80. # profiles, so mostly watch out for the right SLOT used in the bootstrap.
  81. # As above, with SLOT, it may need to be defined in the ebuild
  82. BOOT_TARGET=${CTARGET}
  83. [[ -z ${BOOT_SLOT} ]] && BOOT_SLOT=${SLOT}
  84. # set our install locations
  85. PREFIX=${GNATBUILD_PREFIX:-/usr} # not sure we need this hook, but may be..
  86. LIBPATH=${PREFIX}/$(get_libdir)/${PN}/${CTARGET}/${SLOT}
  87. LIBEXECPATH=${PREFIX}/libexec/${PN}/${CTARGET}/${SLOT}
  88. INCLUDEPATH=${LIBPATH}/include
  89. BINPATH=${PREFIX}/${CTARGET}/${PN}-bin/${SLOT}
  90. DATAPATH=${PREFIX}/share/${PN}-data/${CTARGET}/${SLOT}
  91. # ATTN! the one below should match the path defined in eselect-gnat module
  92. CONFIG_PATH="/usr/share/gnat/eselect"
  93. gnat_profile="${CTARGET}-${PN}-${SLOT}"
  94. gnat_config_file="${CONFIG_PATH}/${gnat_profile}"
  95. # ebuild globals
  96. if [[ ${PN} == "${PN_GnatPro}" ]] && [[ ${GNATMAJOR} == "3" ]]; then
  97. DEPEND="x86? ( >=app-shells/tcsh-6.0 )"
  98. fi
  99. S="${WORKDIR}/gcc-${GCCVER}"
  100. # bootstrap globals, common to src_unpack and src_compile
  101. GNATBOOT="${WORKDIR}/usr"
  102. GNATBUILD="${WORKDIR}/build"
  103. # necessary for detecting lib locations and creating env.d entry
  104. #XGCC="${GNATBUILD}/gcc/xgcc -B${GNATBUILD}/gcc"
  105. #----<< globals and SLOT >>----
  106. # set SRC_URI's in ebuilds for now
  107. #----<< support checks >>----
  108. # skipping this section - do not care about hardened/multilib for now
  109. #---->> specs + env.d logic <<----
  110. # TODO!!!
  111. # set MANPATH, etc..
  112. #----<< specs + env.d logic >>----
  113. #---->> some helper functions <<----
  114. is_multilib() {
  115. [[ ${GCCMAJOR} < 3 ]] && return 1
  116. case ${CTARGET} in
  117. mips64*|powerpc64*|s390x*|sparc64*|x86_64*)
  118. has_multilib_profile ;;
  119. *) false ;;
  120. esac
  121. }
  122. # adapted from toolchain,
  123. # left only basic multilib functionality and cut off mips stuff
  124. create_specs_file() {
  125. einfo "Creating a vanilla gcc specs file"
  126. "${WORKDIR}"/build/gcc/xgcc -dumpspecs > "${WORKDIR}"/build/vanilla.specs
  127. }
  128. # eselect stuff taken straight from toolchain.eclass and greatly simplified
  129. add_profile_eselect_conf() {
  130. local gnat_config_file=$1
  131. local abi=$2
  132. local var
  133. echo >> "${D}/${gnat_config_file}"
  134. if ! is_multilib ; then
  135. echo " ctarget=${CTARGET}" >> "${D}/${gnat_config_file}"
  136. else
  137. echo "[${abi}]" >> "${D}/${gnat_config_file}"
  138. var="CTARGET_${abi}"
  139. if [[ -n ${!var} ]] ; then
  140. echo " ctarget=${!var}" >> "${D}/${gnat_config_file}"
  141. else
  142. var="CHOST_${abi}"
  143. if [[ -n ${!var} ]] ; then
  144. echo " ctarget=${!var}" >> "${D}/${gnat_config_file}"
  145. else
  146. echo " ctarget=${CTARGET}" >> "${D}/${gnat_config_file}"
  147. fi
  148. fi
  149. fi
  150. var="CFLAGS_${abi}"
  151. if [[ -n ${!var} ]] ; then
  152. echo " cflags=${!var}" >> "${D}/${gnat_config_file}"
  153. fi
  154. }
  155. create_eselect_conf() {
  156. local abi
  157. dodir ${CONFIG_PATH}
  158. echo "[global]" > "${D}/${gnat_config_file}"
  159. echo " version=${CTARGET}-${SLOT}" >> "${D}/${gnat_config_file}"
  160. echo " binpath=${BINPATH}" >> "${D}/${gnat_config_file}"
  161. echo " libexecpath=${LIBEXECPATH}" >> "${D}/${gnat_config_file}"
  162. echo " ldpath=${LIBPATH}" >> "${D}/${gnat_config_file}"
  163. echo " manpath=${DATAPATH}/man" >> "${D}/${gnat_config_file}"
  164. echo " infopath=${DATAPATH}/info" >> "${D}/${gnat_config_file}"
  165. echo " bin_prefix=${CTARGET}" >> "${D}/${gnat_config_file}"
  166. for abi in $(get_all_abis) ; do
  167. add_profile_eselect_conf "${gnat_config_file}" "${abi}"
  168. done
  169. }
  170. should_we_eselect_gnat() {
  171. # we only want to switch compilers if installing to / or /tmp/stage1root
  172. [[ ${ROOT} == "/" ]] || return 1
  173. # if the current config is invalid, we definitely want a new one
  174. # Note: due to bash quirkiness, the following must not be 1 line
  175. local curr_config
  176. curr_config=$(eselect --colour=no gnat show | grep ${CTARGET} | awk '{ print $1 }') || return 0
  177. [[ -z ${curr_config} ]] && return 0
  178. # The logic is basically "try to keep the same profile if possible"
  179. if [[ ${curr_config} == ${CTARGET}-${PN}-${SLOT} ]] ; then
  180. return 0
  181. else
  182. elog "The current gcc config appears valid, so it will not be"
  183. elog "automatically switched for you. If you would like to"
  184. elog "switch to the newly installed gcc version, do the"
  185. elog "following:"
  186. echo
  187. elog "eselect gnat set <profile>"
  188. echo
  189. ebeep
  190. return 1
  191. fi
  192. }
  193. # active compiler selection, called from pkg_postinst
  194. do_gnat_config() {
  195. eselect gnat set ${CTARGET}-${PN}-${SLOT} &> /dev/null
  196. elog "The following gnat profile has been activated:"
  197. elog "${CTARGET}-${PN}-${SLOT}"
  198. elog ""
  199. elog "The compiler has been installed as gnatgcc, and the coverage testing"
  200. elog "tool as gnatgcov."
  201. elog ""
  202. elog "Ada handling in Gentoo allows you to have multiple gnat variants"
  203. elog "installed in parallel and automatically manage Ada libs."
  204. elog "Please take a look at the Ada project page for some documentation:"
  205. elog "http://www.gentoo.org/proj/en/prog_lang/ada/index.xml"
  206. }
  207. # Taken straight from the toolchain.eclass. Only removed the "obsolete hunk"
  208. #
  209. # The purpose of this DISGUSTING gcc multilib hack is to allow 64bit libs
  210. # to live in lib instead of lib64 where they belong, with 32bit libraries
  211. # in lib32. This hack has been around since the beginning of the amd64 port,
  212. # and we're only now starting to fix everything that's broken. Eventually
  213. # this should go away.
  214. #
  215. # Travis Tilley <lv@gentoo.org> (03 Sep 2004)
  216. #
  217. disgusting_gcc_multilib_HACK() {
  218. local config
  219. local libdirs
  220. if has_multilib_profile ; then
  221. case $(tc-arch) in
  222. amd64)
  223. config="i386/t-linux64"
  224. libdirs="../$(get_abi_LIBDIR amd64) ../$(get_abi_LIBDIR x86)" \
  225. ;;
  226. ppc64)
  227. config="rs6000/t-linux64"
  228. libdirs="../$(get_abi_LIBDIR ppc64) ../$(get_abi_LIBDIR ppc)" \
  229. ;;
  230. esac
  231. else
  232. die "Your profile is no longer supported by portage."
  233. fi
  234. einfo "updating multilib directories to be: ${libdirs}"
  235. sed -i -e "s:^MULTILIB_OSDIRNAMES.*:MULTILIB_OSDIRNAMES = ${libdirs}:" "${S}"/gcc/config/${config}
  236. }
  237. #---->> pkg_* <<----
  238. gnatbuild_pkg_setup() {
  239. debug-print-function ${FUNCNAME} $@
  240. # Setup variables which would normally be in the profile
  241. if is_crosscompile ; then
  242. multilib_env ${CTARGET}
  243. fi
  244. # we dont want to use the installed compiler's specs to build gnat!
  245. unset GCC_SPECS
  246. }
  247. gnatbuild_pkg_postinst() {
  248. if should_we_eselect_gnat; then
  249. do_gnat_config
  250. else
  251. eselect gnat update
  252. fi
  253. # if primary compiler list is empty, add this profile to the list, so
  254. # that users are not left without active compilers (making sure that
  255. # libs are getting built for at least one)
  256. elog
  257. . ${GnatCommon} || die "failed to source common code"
  258. if [[ ! -f ${PRIMELIST} ]] || [[ ! -s ${PRIMELIST} ]]; then
  259. echo "${gnat_profile}" > ${PRIMELIST}
  260. elog "The list of primary compilers was empty and got assigned ${gnat_profile}."
  261. fi
  262. elog "Please edit ${PRIMELIST} and list there gnat profiles intended"
  263. elog "for common use."
  264. }
  265. gnatbuild_pkg_postrm() {
  266. # "eselect gnat update" now removes the env.d file if the corresponding
  267. # gnat profile was unmerged
  268. eselect gnat update
  269. elog "If you just unmerged the last gnat in this SLOT, your active gnat"
  270. elog "profile got unset. Please check what eselect gnat show tells you"
  271. elog "and set the desired profile"
  272. }
  273. #---->> pkg_* <<----
  274. #---->> src_* <<----
  275. # common unpack stuff
  276. gnatbuild_src_unpack() {
  277. debug-print-function ${FUNCNAME} $@
  278. if [[ -z "$1" ]]; then
  279. gnatbuild_src_unpack all
  280. return $?
  281. fi
  282. while [ "$1" ]; do
  283. case $1 in
  284. base_unpack)
  285. unpack ${A}
  286. pax-mark E $(find ${GNATBOOT} -name gnat1)
  287. cd "${S}"
  288. # patching gcc sources, following the toolchain
  289. # first, the common patches
  290. if [[ -d "${FILESDIR}"/patches ]] && [[ ! -z $(ls "${FILESDIR}"/patches/*.patch 2>/dev/null) ]] ; then
  291. EPATCH_MULTI_MSG="Applying common Gentoo patches ..." \
  292. epatch "${FILESDIR}"/patches/*.patch
  293. fi
  294. #
  295. # then per SLOT
  296. if [[ -d "${FILESDIR}"/patches/${SLOT} ]] && [[ ! -z $(ls "${FILESDIR}"/patches/${SLOT}/*.patch 2>/dev/null) ]] ; then
  297. EPATCH_MULTI_MSG="Applying SLOT-specific Gentoo patches ..." \
  298. epatch "${FILESDIR}"/patches/${SLOT}/*.patch
  299. fi
  300. # Replacing obsolete head/tail with POSIX compliant ones
  301. ht_fix_file */configure
  302. # if ! is_crosscompile && is_multilib && \
  303. # [[ ( $(tc-arch) == "amd64" || $(tc-arch) == "ppc64" ) && -z ${SKIP_MULTILIB_HACK} ]] ; then
  304. # disgusting_gcc_multilib_HACK || die "multilib hack failed"
  305. # fi
  306. # Fixup libtool to correctly generate .la files with portage
  307. cd "${S}"
  308. elibtoolize --portage --shallow --no-uclibc
  309. gnuconfig_update
  310. # update configure files
  311. einfo "Fixing misc issues in configure files"
  312. for f in $(grep -l 'autoconf version 2.13' $(find "${S}" -name configure)) ; do
  313. ebegin " Updating ${f}"
  314. patch "${f}" "${FILESDIR}"/gcc-configure-LANG.patch >& "${T}"/configure-patch.log \
  315. || eerror "Please file a bug about this"
  316. eend $?
  317. done
  318. # this is only needed for gnat-gpl-4.1 and breaks for gnat-gcc, so
  319. # this block was moved to corresponding ebuild
  320. # pushd "${S}"/gnattools &> /dev/null
  321. # eautoconf
  322. # popd &> /dev/null
  323. ;;
  324. common_prep)
  325. # Prepare the gcc source directory
  326. cd "${S}/gcc"
  327. touch cstamp-h.in
  328. touch ada/[es]info.h
  329. touch ada/nmake.ad[bs]
  330. # set the compiler name to gnatgcc
  331. for i in `find ada/ -name '*.ad[sb]'`; do \
  332. sed -i -e "s/\"gcc\"/\"gnatgcc\"/g" ${i}; \
  333. done
  334. # add -fPIC flag to shared libs for 3.4* backend
  335. if [ "3.4" == "${GCCBRANCH}" ] ; then
  336. cd ada
  337. epatch "${FILESDIR}"/gnat-Make-lang.in.patch
  338. fi
  339. # gcc 4.3 sources seem to have a common omission of $(DESTDIR),
  340. # that leads to make install trying to rm -f file on live system.
  341. # As we do not need this rm, we simply remove the whole line
  342. if [ "4.3" == "${GCCBRANCH}" ] ; then
  343. sed -i -e "/\$(RM) \$(bindir)/d" "${S}"/gcc/ada/Make-lang.in
  344. fi
  345. mkdir -p "${GNATBUILD}"
  346. ;;
  347. all)
  348. gnatbuild_src_unpack base_unpack common_prep
  349. ;;
  350. esac
  351. shift
  352. done
  353. }
  354. # for now just dont run default configure
  355. gnatbuild_src_configure() {
  356. # do nothing
  357. :
  358. }
  359. # it would be nice to split configure and make steps
  360. # but both need to operate inside specially tuned evironment
  361. # so just do sections for now (as in eclass section of handbook)
  362. # sections are: configure, make-tools, bootstrap,
  363. # gnatlib_and_tools, gnatlib-shared
  364. gnatbuild_src_compile() {
  365. debug-print-function ${FUNCNAME} $@
  366. if [[ -z "$1" ]]; then
  367. gnatbuild_src_compile all
  368. return $?
  369. fi
  370. if [[ "all" == "$1" ]]
  371. then # specialcasing "all" to avoid scanning sources unnecessarily
  372. gnatbuild_src_compile configure make-tools \
  373. bootstrap gnatlib_and_tools gnatlib-shared
  374. else
  375. # Set some paths to our bootstrap compiler.
  376. export PATH="${GNATBOOT}/bin:${PATH}"
  377. # !ATTN! the bootstrap compilers have a very simplystic structure,
  378. # so many paths are not identical to the installed ones.
  379. # Plus it was simplified even more in new releases.
  380. if [[ ${BOOT_SLOT} > 4.1 ]] ; then
  381. case $(tc-arch) in
  382. arm)
  383. GNATLIB="${GNATBOOT}/lib/gcc/${BOOT_TARGET}/${BOOT_SLOT}"
  384. ;;
  385. *)
  386. GNATLIB="${GNATBOOT}/lib"
  387. ;;
  388. esac
  389. else
  390. GNATLIB="${GNATBOOT}/lib/gnatgcc/${BOOT_TARGET}/${BOOT_SLOT}"
  391. fi
  392. export CC="${GNATBOOT}/bin/gnatgcc"
  393. # CPATH is supposed to be applied for any language, thus
  394. # superceding either of C/CPLUS/OBJC_INCLUDE_PATHs
  395. export CPATH="${GNATLIB}/include"
  396. #export INCLUDE_DIR="${GNATLIB}/include"
  397. #export C_INCLUDE_PATH="${GNATLIB}/include"
  398. #export CPLUS_INCLUDE_PATH="${GNATLIB}/include"
  399. export LIB_DIR="${GNATLIB}"
  400. export LDFLAGS="-L${GNATLIB}"
  401. # additional vars from gnuada and elsewhere
  402. #export LD_RUN_PATH="${LIBPATH}"
  403. export LIBRARY_PATH="${GNATLIB}"
  404. #export LD_LIBRARY_PATH="${GNATLIB}"
  405. # export COMPILER_PATH="${GNATBOOT}/bin/"
  406. export ADA_OBJECTS_PATH="${GNATLIB}/adalib"
  407. export ADA_INCLUDE_PATH="${GNATLIB}/adainclude"
  408. einfo "CC=${CC},
  409. ADA_INCLUDE_PATH=${ADA_INCLUDE_PATH},
  410. LDFLAGS=${LDFLAGS},
  411. PATH=${PATH}"
  412. while [ "$1" ]; do
  413. case $1 in
  414. configure)
  415. debug-print-section configure
  416. # Configure gcc
  417. local confgcc
  418. # some cross-compile logic from toolchain
  419. confgcc="${confgcc} --host=${CHOST}"
  420. if is_crosscompile || tc-is-cross-compiler ; then
  421. confgcc="${confgcc} --target=${CTARGET}"
  422. fi
  423. [[ -n ${CBUILD} ]] && confgcc="${confgcc} --build=${CBUILD}"
  424. # Native Language Support
  425. if use nls ; then
  426. confgcc="${confgcc} --enable-nls --without-included-gettext"
  427. else
  428. confgcc="${confgcc} --disable-nls"
  429. fi
  430. if version_is_at_least 4.6 ; then
  431. confgcc="${confgcc} --enable-lto"
  432. elif tc_version_is_at_least 4.5 ; then
  433. confgcc="${confgcc} --disable-lto --disable-plugin"
  434. fi
  435. # reasonably sane globals (from toolchain)
  436. # also disable mudflap and ssp
  437. confgcc="${confgcc} \
  438. --with-system-zlib \
  439. --disable-checking \
  440. --disable-werror \
  441. --disable-libmudflap \
  442. --disable-libssp \
  443. --disable-altivec \
  444. --disable-fixed-point \
  445. --disable-libgcj \
  446. --disable-libcilkrts \
  447. --disable-libsanitizer \
  448. --disable-libunwind-exceptions"
  449. if in_iuse openmp ; then
  450. # Make sure target has pthreads support. #326757 #335883
  451. # There shouldn't be a chicken&egg problem here as openmp won't
  452. # build without a C library, and you can't build that w/out
  453. # already having a compiler ...
  454. if ! is_crosscompile || \
  455. $(tc-getCPP ${CTARGET}) -E - <<<"#include <pthread.h>" >& /dev/null
  456. then
  457. case $(tc-arch) in
  458. arm)
  459. confgcc="${confgcc} --disable-libgomp"
  460. ;;
  461. *)
  462. confgcc="${confgcc} $(use_enable openmp libgomp)"
  463. ;;
  464. esac
  465. else
  466. # Force disable as the configure script can be dumb #359855
  467. confgcc="${confgcc} --disable-libgomp"
  468. fi
  469. else
  470. # For gcc variants where we don't want openmp (e.g. kgcc)
  471. confgcc="${confgcc} --disable-libgomp"
  472. fi
  473. # ACT's gnat-gpl does not like libada for whatever reason..
  474. if version_is_at_least 4.2 ; then
  475. confgcc="${confgcc} --enable-libada"
  476. # else
  477. # einfo "ACT's gnat-gpl does not like libada, disabling"
  478. # confgcc="${confgcc} --disable-libada"
  479. fi
  480. # set some specifics available in later versions
  481. if version_is_at_least 4.7 ; then
  482. einfo "setting gnat thread model"
  483. confgcc="${confgcc} --enable-threads=posix"
  484. confgcc="${confgcc} --enable-shared=boehm-gc,ada,libada"
  485. elif version_is_at_least 4.3 ; then
  486. confgcc="${confgcc} --enable-threads=gnat"
  487. confgcc="${confgcc} --enable-shared=boehm-gc,ada,libada"
  488. else
  489. confgcc="${confgcc} --enable-threads=posix"
  490. confgcc="${confgcc} --enable-shared"
  491. fi
  492. # multilib support
  493. if is_multilib ; then
  494. confgcc="${confgcc} --enable-multilib"
  495. else
  496. confgcc="${confgcc} --disable-multilib"
  497. fi
  498. # __cxa_atexit is "essential for fully standards-compliant handling of
  499. # destructors", but apparently requires glibc.
  500. if [[ ${CTARGET} == *-gnu* ]] ; then
  501. confgcc="${confgcc} --enable-__cxa_atexit"
  502. confgcc="${confgcc} --enable-clocale=gnu"
  503. fi
  504. einfo "confgcc=${confgcc}"
  505. export gcc_cv_lto_plugin=1 # okay to build, default to opt-in
  506. export gcc_cv_prog_makeinfo_modern=no
  507. export ac_cv_have_x='have_x=yes ac_x_includes= ac_x_libraries='
  508. export gcc_cv_libc_provides_ssp=yes
  509. # need to strip graphite/lto flags or we'll get the
  510. # dreaded C compiler cannot create executables...
  511. # error.
  512. strip-flags
  513. replace-flags -O? -O2
  514. filter-flags '-mabi*' -m31 -m32 -m64
  515. filter-flags -frecord-gcc-switches
  516. filter-flags -mno-rtm -mno-htm
  517. #filter-flags -floop-interchange -floop-strip-mine -floop-block
  518. #filter-flags -fuse-linker-plugin -flto*
  519. cd "${GNATBUILD}"
  520. CC="${CC}" CFLAGS="${CFLAGS}" CXXFLAGS="${CFLAGS}" "${S}"/configure \
  521. --prefix="${PREFIX}" \
  522. --bindir="${BINPATH}" \
  523. --includedir="${INCLUDEPATH}" \
  524. --libdir="${LIBPATH}" \
  525. --libexecdir="${LIBEXECPATH}" \
  526. --datadir="${DATAPATH}" \
  527. --mandir="${DATAPATH}"/man \
  528. --infodir="${DATAPATH}"/info \
  529. --enable-languages=c,ada \
  530. --with-gcc \
  531. ${confgcc} || die "configure failed"
  532. ;;
  533. make-tools)
  534. debug-print-section make-tools
  535. # Compile helper tools
  536. cd "${GNATBOOT}"
  537. cp "${S}"/gcc/ada/xtreeprs.adb .
  538. cp "${S}"/gcc/ada/xsinfo.adb .
  539. cp "${S}"/gcc/ada/xeinfo.adb .
  540. cp "${S}"/gcc/ada/xnmake.adb .
  541. cp "${S}"/gcc/ada/xutil.ad{s,b} .
  542. if (( ${GNATMINOR} > 5 )) ; then
  543. cp "${S}"/gcc/ada/einfo.ad{s,b} .
  544. cp "${S}"/gcc/ada/csinfo.adb .
  545. cp "${S}"/gcc/ada/ceinfo.adb .
  546. fi
  547. gnatmake xtreeprs && \
  548. gnatmake xsinfo && \
  549. gnatmake xeinfo && \
  550. gnatmake xnmake || die "building helper tools"
  551. mv xeinfo xnmake xsinfo xtreeprs bin/
  552. ;;
  553. bootstrap)
  554. debug-print-section bootstrap
  555. # and, finally, the build itself
  556. cd "${GNATBUILD}"
  557. emake \
  558. LDFLAGS="${LDFLAGS}" \
  559. LIBPATH="${LIBPATH}" \
  560. CC="${CC}" \
  561. bootstrap-lean || die "bootstrap failed"
  562. ;;
  563. gnatlib_and_tools)
  564. debug-print-section gnatlib_and_tools
  565. einfo "building gnatlib_and_tools"
  566. cd "${GNATBUILD}"
  567. emake -j1 -C gcc gnatlib_and_tools || \
  568. die "gnatlib_and_tools failed"
  569. ;;
  570. gnatlib-shared)
  571. debug-print-section gnatlib-shared
  572. einfo "building shared lib"
  573. cd "${GNATBUILD}"
  574. rm -f gcc/ada/rts/*.{o,ali} || die
  575. #otherwise make tries to reuse already compiled (without -fPIC) objs..
  576. emake -j1 -C gcc gnatlib-shared LIBRARY_VERSION="${GCCBRANCH}" || \
  577. die "gnatlib-shared failed"
  578. ;;
  579. esac
  580. shift
  581. done # while
  582. fi # "all" == "$1"
  583. }
  584. # -- end gnatbuild_src_compile
  585. gnatbuild_src_install() {
  586. debug-print-function ${FUNCNAME} $@
  587. if [[ -z "$1" ]] ; then
  588. gnatbuild_src_install all
  589. return $?
  590. fi
  591. while [ "$1" ]; do
  592. case $1 in
  593. install) # runs provided make install
  594. debug-print-section install
  595. # Looks like we need an access to the bootstrap compiler here too
  596. # as gnat apparently wants to compile something during the installation
  597. # The spotted obuser was xgnatugn, used to process gnat_ugn_urw.texi,
  598. # during preparison of the docs.
  599. export PATH="${GNATBOOT}/bin:${PATH}"
  600. if [[ ${BOOT_SLOT} > 4.1 ]] ; then
  601. GNATLIB="${GNATBOOT}/lib"
  602. else
  603. GNATLIB="${GNATBOOT}/lib/gnatgcc/${BOOT_TARGET}/${BOOT_SLOT}"
  604. fi
  605. export CC="${GNATBOOT}/bin/gnatgcc"
  606. export INCLUDE_DIR="${GNATLIB}/include"
  607. export C_INCLUDE_PATH="${GNATLIB}/include"
  608. export CPLUS_INCLUDE_PATH="${GNATLIB}/include"
  609. export LIB_DIR="${GNATLIB}"
  610. export LDFLAGS="-L${GNATLIB}"
  611. export ADA_OBJECTS_PATH="${GNATLIB}/adalib"
  612. export ADA_INCLUDE_PATH="${GNATLIB}/adainclude"
  613. # Do not allow symlinks in /usr/lib/gcc/${CHOST}/${MY_PV}/include as
  614. # this can break the build.
  615. for x in "${GNATBUILD}"/gcc/include/* ; do
  616. if [ -L ${x} ] ; then
  617. rm -f ${x}
  618. fi
  619. done
  620. # Remove generated headers, as they can cause things to break
  621. # (ncurses, openssl, etc). (from toolchain.eclass)
  622. for x in $(find "${WORKDIR}"/build/gcc/include/ -name '*.h') ; do
  623. grep -q 'It has been auto-edited by fixincludes from' "${x}" \
  624. && rm -f "${x}"
  625. done
  626. cd "${GNATBUILD}"
  627. make DESTDIR="${D}" install || die
  628. # Disable RANDMMAP so PCH works. #301299
  629. pax-mark r "${D}"${LIBEXECPATH}/{gnat1,cc1,cc1plus}
  630. # Quiet QA warnings, wait for adacore exec stack patch in gcc 7
  631. export QA_EXECSTACK="${BINPATH:1}/gnatls ${BINPATH:1}/gnatname
  632. ${BINPATH:1}/gnatmake ${BINPATH:1}/gnatclean ${BINPATH:1}/gnat"
  633. if use doc ; then
  634. if (( $(bc <<< "${GNATBRANCH} > 4.3") )) ; then
  635. #make a convenience info link
  636. ewarn "Yay! Math works."
  637. dosym gnat_ugn.info ${DATAPATH}/info/gnat.info
  638. fi
  639. fi
  640. ;;
  641. move_libs)
  642. debug-print-section move_libs
  643. # first we need to remove some stuff to make moving easier
  644. rm -rf "${D}${LIBPATH}"/{32,include,libiberty.a}
  645. # gcc insists on installing libs in its own place
  646. mv "${D}${LIBPATH}/gcc/${CTARGET}/${GCCRELEASE}"/* "${D}${LIBPATH}"
  647. mv "${D}${LIBEXECPATH}/gcc/${CTARGET}/${GCCRELEASE}"/* "${D}${LIBEXECPATH}"
  648. # libgcc_s and, with gcc>=4.0, other libs get installed in multilib specific locations by gcc
  649. # we pull everything together to simplify working environment
  650. if has_multilib_profile ; then
  651. case $(tc-arch) in
  652. amd64)
  653. mv "${D}${LIBPATH}"/../$(get_abi_LIBDIR amd64)/* "${D}${LIBPATH}"
  654. mv "${D}${LIBPATH}"/../$(get_abi_LIBDIR x86)/* "${D}${LIBPATH}"/32
  655. ;;
  656. ppc64)
  657. # not supported yet, will have to be adjusted when we
  658. # actually build gnat for that arch
  659. ;;
  660. esac
  661. fi
  662. # force gnatgcc to use its own specs - versions prior to 3.4.6 read specs
  663. # from system gcc location. Do the simple wrapper trick for now
  664. # !ATTN! change this if eselect-gnat starts to follow eselect-compiler
  665. cd "${D}${BINPATH}"
  666. if [[ ${GCCVER} < 3.4.6 ]] ; then
  667. # gcc 4.1 uses builtin specs. What about 4.0?
  668. mv gnatgcc gnatgcc_2wrap
  669. cat > gnatgcc << EOF
  670. #! /bin/bash
  671. # wrapper to cause gnatgcc read appropriate specs and search for the right .h
  672. # files (in case no matching gcc is installed)
  673. BINDIR=\$(dirname \$0)
  674. # The paths in the next line have to be absolute, as gnatgcc may be called from
  675. # any location
  676. \${BINDIR}/gnatgcc_2wrap -specs="${LIBPATH}/specs" -I"${LIBPATH}/include" \$@
  677. EOF
  678. chmod a+x gnatgcc
  679. else
  680. local i
  681. for i in cpp gcc gcov ; do
  682. ln -s ${i} gnat${i}
  683. done
  684. fi
  685. # earlier gnat's generate some Makefile's at generic location, need to
  686. # move to avoid collisions
  687. [ -f "${D}${PREFIX}"/share/gnat/Makefile.generic ] &&
  688. mv "${D}${PREFIX}"/share/gnat/Makefile.* "${D}${DATAPATH}"
  689. # use gid of 0 because some stupid ports don't have
  690. # the group 'root' set to gid 0 (toolchain.eclass)
  691. # chown -R root:0 "${D}${LIBPATH}"
  692. ;;
  693. cleanup)
  694. debug-print-section cleanup
  695. rm -rf "${D}${LIBPATH}"/{gcc,install-tools,../lib{32,64}}
  696. rm -rf "${D}${LIBEXECPATH}"/{gcc,install-tools}
  697. # this one is installed by gcc and is a duplicate even here anyway
  698. rm -f "${D}${BINPATH}/${CTARGET}-gcc-${GCCRELEASE}"
  699. # remove duplicate docs
  700. rm -f "${D}${DATAPATH}"/info/{dir,gcc,cpp}*
  701. rm -rf "${D}${DATAPATH}"/man/man7/
  702. # fix .la path for lto plugin
  703. if use lto ; then
  704. sed -i -e \
  705. "/libdir=/c\libdir='${LIBEXECPATH}'" \
  706. "${D}${LIBEXECPATH}"/liblto_plugin.la \
  707. || die "sed update of .la file failed!"
  708. fi
  709. ;;
  710. prep_env)
  711. # instead of putting junk under /etc/env.d/gnat we recreate env files as
  712. # needed with eselect
  713. create_eselect_conf
  714. ;;
  715. all)
  716. gnatbuild_src_install install move_libs cleanup prep_env
  717. ;;
  718. esac
  719. shift
  720. done # while
  721. }
  722. # -- end gnatbuild_src_install