Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | inherit cross |
| 2 | |
| 3 | INHIBIT_DEFAULT_DEPS = "1" |
| 4 | EXTRADEPENDS = "" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 5 | DEPENDS = "virtual/${TARGET_PREFIX}binutils ${EXTRADEPENDS} ${NATIVEDEPS}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | PROVIDES = "virtual/${TARGET_PREFIX}gcc virtual/${TARGET_PREFIX}g++" |
| 7 | python () { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 8 | if d.getVar("TARGET_OS").startswith("linux"): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9 | d.setVar("EXTRADEPENDS", "linux-libc-headers") |
| 10 | } |
| 11 | |
| 12 | PN = "gcc-cross-${TARGET_ARCH}" |
| 13 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 14 | # Ignore how TARGET_ARCH is computed. |
| 15 | TARGET_ARCH[vardepvalue] = "${TARGET_ARCH}" |
| 16 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 17 | require gcc-configure-common.inc |
| 18 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 19 | # While we want the 'gnu' hash style, we explicitly set it to sysv here to |
| 20 | # ensure that any recipe which doesn't obey our LDFLAGS (which also set it to |
| 21 | # gnu) will hit a QA failure. |
| 22 | LINKER_HASH_STYLE ?= "sysv" |
| 23 | |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 24 | EXTRA_OECONF += "--enable-poison-system-directories=error" |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 25 | EXTRA_OECONF:append:sh4 = " \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | --with-multilib-list= \ |
| 27 | --enable-incomplete-targets \ |
| 28 | " |
| 29 | |
| 30 | EXTRA_OECONF += "\ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 31 | --with-system-zlib \ |
| 32 | " |
| 33 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 34 | EXTRA_OECONF:append:libc-baremetal = " --without-headers" |
| 35 | EXTRA_OECONF:remove:libc-baremetal = "--enable-threads=posix" |
| 36 | EXTRA_OECONF:remove:libc-newlib = "--enable-threads=posix" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 37 | |
| 38 | EXTRA_OECONF_PATHS = "\ |
| 39 | --with-gxx-include-dir=/not/exist${target_includedir}/c++/${BINV} \ |
| 40 | --with-sysroot=/not/exist \ |
| 41 | --with-build-sysroot=${STAGING_DIR_TARGET} \ |
| 42 | " |
| 43 | |
| 44 | ARCH_FLAGS_FOR_TARGET += "-isystem${STAGING_DIR_TARGET}${target_includedir}" |
| 45 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 46 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 47 | do_configure:prepend () { |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 48 | install -d ${RECIPE_SYSROOT}${target_includedir} |
| 49 | touch ${RECIPE_SYSROOT}${target_includedir}/limits.h |
| 50 | } |
| 51 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 52 | do_compile () { |
| 53 | export CC="${BUILD_CC}" |
| 54 | export AR_FOR_TARGET="${TARGET_SYS}-ar" |
| 55 | export RANLIB_FOR_TARGET="${TARGET_SYS}-ranlib" |
| 56 | export LD_FOR_TARGET="${TARGET_SYS}-ld" |
| 57 | export NM_FOR_TARGET="${TARGET_SYS}-nm" |
| 58 | export CC_FOR_TARGET="${CCACHE} ${TARGET_SYS}-gcc" |
| 59 | export CFLAGS_FOR_TARGET="${TARGET_CFLAGS}" |
| 60 | export CPPFLAGS_FOR_TARGET="${TARGET_CPPFLAGS}" |
| 61 | export CXXFLAGS_FOR_TARGET="${TARGET_CXXFLAGS}" |
| 62 | export LDFLAGS_FOR_TARGET="${TARGET_LDFLAGS}" |
| 63 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 64 | # Prevent native/host sysroot path from being used in configargs.h header, |
| 65 | # as it will be rewritten when used by other sysroots preventing support |
| 66 | # for gcc plugins |
| 67 | oe_runmake configure-gcc |
| 68 | sed -i 's@${STAGING_DIR_TARGET}@/host@g' ${B}/gcc/configargs.h |
| 69 | sed -i 's@${STAGING_DIR_HOST}@/host@g' ${B}/gcc/configargs.h |
| 70 | |
| 71 | # Prevent sysroot/workdir paths from being used in checksum-options. |
| 72 | # checksum-options is used to generate a checksum which is embedded into |
| 73 | # the output binary. |
| 74 | oe_runmake TARGET-gcc=checksum-options all-gcc |
| 75 | sed -i 's@${DEBUG_PREFIX_MAP}@@g' ${B}/gcc/checksum-options |
| 76 | sed -i 's@${STAGING_DIR_HOST}@/host@g' ${B}/gcc/checksum-options |
| 77 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 78 | oe_runmake all-host configure-target-libgcc |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 79 | (cd ${B}/${TARGET_SYS}/libgcc; oe_runmake enable-execute-stack.c unwind.h md-unwind-support.h sfp-machine.h gthr-default.h) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | INHIBIT_PACKAGE_STRIP = "1" |
| 83 | |
| 84 | # Compute how to get from libexecdir to bindir in python (easier than shell) |
| 85 | BINRELPATH = "${@os.path.relpath(d.expand("${STAGING_DIR_NATIVE}${prefix_native}/bin/${TARGET_SYS}"), d.expand("${libexecdir}/gcc/${TARGET_SYS}/${BINV}"))}" |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 86 | # linker plugin path |
| 87 | LIBRELPATH = "${@os.path.relpath(d.expand("${libexecdir}/gcc/${TARGET_SYS}/${BINV}"), d.expand("${STAGING_LIBDIR_NATIVE}/${TARGET_SYS}/bfd-plugins"))}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 88 | |
| 89 | do_install () { |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 90 | ( cd ${B}/${TARGET_SYS}/libgcc; oe_runmake 'DESTDIR=${D}' install-unwind_h-forbuild install-unwind_h ) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 91 | oe_runmake 'DESTDIR=${D}' install-host |
| 92 | |
| 93 | install -d ${D}${target_base_libdir} |
| 94 | install -d ${D}${target_libdir} |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 95 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 96 | # Link gfortran to g77 to satisfy not-so-smart configure or hard coded g77 |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 97 | # gfortran is fully backwards compatible. This is a safe and practical solution. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 98 | if [ -n "${@d.getVar('FORTRAN')}" ]; then |
| 99 | ln -sf ${STAGING_DIR_NATIVE}${prefix_native}/bin/${TARGET_PREFIX}gfortran ${STAGING_DIR_NATIVE}${prefix_native}/bin/${TARGET_PREFIX}g77 || true |
| 100 | fortsymlinks="g77 gfortran" |
| 101 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 102 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 103 | # Insert symlinks into libexec so when tools without a prefix are searched for, the correct ones are |
| 104 | # found. These need to be relative paths so they work in different locations. |
| 105 | dest=${D}${libexecdir}/gcc/${TARGET_SYS}/${BINV}/ |
| 106 | install -d $dest |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 107 | for t in ar as ld ld.bfd ld.gold nm objcopy objdump ranlib strip gcc cpp $fortsymlinks; do |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 108 | ln -sf ${BINRELPATH}/${TARGET_PREFIX}$t $dest$t |
| 109 | ln -sf ${BINRELPATH}/${TARGET_PREFIX}$t ${dest}${TARGET_PREFIX}$t |
| 110 | done |
| 111 | |
| 112 | # Remove things we don't need but keep share/java |
| 113 | for d in info man share/doc share/locale share/man share/info; do |
| 114 | rm -rf ${D}${STAGING_DIR_NATIVE}${prefix_native}/$d |
| 115 | done |
| 116 | |
| 117 | # libquadmath headers need to be available in the gcc libexec dir |
| 118 | install -d ${D}${libdir}/gcc/${TARGET_SYS}/${BINV}/include/ |
| 119 | cp ${S}/libquadmath/quadmath.h ${D}${libdir}/gcc/${TARGET_SYS}/${BINV}/include/ |
| 120 | cp ${S}/libquadmath/quadmath_weak.h ${D}${libdir}/gcc/${TARGET_SYS}/${BINV}/include/ |
| 121 | |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 122 | find ${D}${libdir}/gcc/${TARGET_SYS}/${BINV}/include-fixed -type f -not -name "README" -not -name limits.h -not -name syslimits.h | xargs rm -f |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 123 | |
| 124 | # install LTO linker plugins where binutils tools can find it |
| 125 | install -d ${D}${libdir}/bfd-plugins |
| 126 | ln -sf ${LIBRELPATH}/liblto_plugin.so ${D}${libdir}/bfd-plugins/liblto_plugin.so |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 127 | } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 128 | |
| 129 | do_package[noexec] = "1" |
| 130 | do_packagedata[noexec] = "1" |
| 131 | do_package_write_ipk[noexec] = "1" |
| 132 | do_package_write_rpm[noexec] = "1" |
| 133 | do_package_write_deb[noexec] = "1" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 134 | |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 135 | inherit chrpath |
| 136 | |
| 137 | python gcc_stash_builddir_fixrpaths() { |
| 138 | # rewrite rpaths, breaking hardlinks as required |
| 139 | process_dir("/", d.getVar("BUILDDIRSTASH"), d, break_hardlinks = True) |
| 140 | } |
| 141 | |
| 142 | BUILDDIRSTASH = "${WORKDIR}/stashed-builddir/build" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 143 | do_gcc_stash_builddir[dirs] = "${B}" |
| 144 | do_gcc_stash_builddir[cleandirs] = "${BUILDDIRSTASH}" |
Brad Bishop | a34c030 | 2019-09-23 22:34:48 -0400 | [diff] [blame] | 145 | do_gcc_stash_builddir[postfuncs] += "gcc_stash_builddir_fixrpaths" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 146 | do_gcc_stash_builddir () { |
| 147 | dest=${BUILDDIRSTASH} |
| 148 | hardlinkdir . $dest |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 149 | # Makefile does move-if-change which can end up with 'timestamp' as file contents so break links to those files |
| 150 | rm $dest/gcc/include/*.h |
| 151 | cp gcc/include/*.h $dest/gcc/include/ |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 152 | sysroot-relativelinks.py $dest |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 153 | } |
| 154 | addtask do_gcc_stash_builddir after do_compile before do_install |
| 155 | SSTATETASKS += "do_gcc_stash_builddir" |
| 156 | do_gcc_stash_builddir[sstate-inputdirs] = "${BUILDDIRSTASH}" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 157 | do_gcc_stash_builddir[sstate-outputdirs] = "${COMPONENTS_DIR}/${BUILD_ARCH}/gcc-stashed-builddir-${TARGET_SYS}" |
| 158 | do_gcc_stash_builddir[sstate-fixmedir] = "${COMPONENTS_DIR}/${BUILD_ARCH}/gcc-stashed-builddir-${TARGET_SYS}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 159 | |
| 160 | python do_gcc_stash_builddir_setscene () { |
| 161 | sstate_setscene(d) |
| 162 | } |
| 163 | addtask do_gcc_stash_builddir_setscene |