gcc-cross.inc 6.3 KB

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