gcc-cross.inc 6.4 KB

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