blob: e08807afade194dfd61fe9bf89a3f0ccbaddcdbc [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001inherit cross
2
3INHIBIT_DEFAULT_DEPS = "1"
4EXTRADEPENDS = ""
Brad Bishop19323692019-04-05 15:28:33 -04005DEPENDS = "virtual/${TARGET_PREFIX}binutils ${EXTRADEPENDS} ${NATIVEDEPS}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006PROVIDES = "virtual/${TARGET_PREFIX}gcc virtual/${TARGET_PREFIX}g++"
7python () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -05008 if d.getVar("TARGET_OS").startswith("linux"):
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009 d.setVar("EXTRADEPENDS", "linux-libc-headers")
10}
11
12PN = "gcc-cross-${TARGET_ARCH}"
13
Brad Bishop6e60e8b2018-02-01 10:27:11 -050014# Ignore how TARGET_ARCH is computed.
15TARGET_ARCH[vardepvalue] = "${TARGET_ARCH}"
16
Patrick Williamsc124f4f2015-09-15 14:41:29 -050017require gcc-configure-common.inc
18
Patrick Williamsc0f7c042017-02-23 20:41:17 -060019# 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.
22LINKER_HASH_STYLE ?= "sysv"
23
Andrew Geissler95ac1b82021-03-31 14:34:31 -050024EXTRA_OECONF += "--enable-poison-system-directories=error"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025EXTRA_OECONF_append_sh4 = " \
26 --with-multilib-list= \
27 --enable-incomplete-targets \
28"
29
30EXTRA_OECONF += "\
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031 --with-system-zlib \
32"
33
Patrick Williamsc124f4f2015-09-15 14:41:29 -050034EXTRA_OECONF_append_libc-baremetal = " --without-headers"
35EXTRA_OECONF_remove_libc-baremetal = "--enable-threads=posix"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080036EXTRA_OECONF_remove_libc-newlib = "--enable-threads=posix"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037
38EXTRA_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
44ARCH_FLAGS_FOR_TARGET += "-isystem${STAGING_DIR_TARGET}${target_includedir}"
45
Brad Bishop19323692019-04-05 15:28:33 -040046
47do_configure_prepend () {
48 install -d ${RECIPE_SYSROOT}${target_includedir}
49 touch ${RECIPE_SYSROOT}${target_includedir}/limits.h
50}
51
Patrick Williamsc124f4f2015-09-15 14:41:29 -050052do_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 Geissler82c905d2020-04-13 13:39:40 -050064 # 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 Williamsc124f4f2015-09-15 14:41:29 -050078 oe_runmake all-host configure-target-libgcc
Brad Bishopd7bf8c12018-02-25 22:55:05 -050079 (cd ${B}/${TARGET_SYS}/libgcc; oe_runmake enable-execute-stack.c unwind.h md-unwind-support.h sfp-machine.h gthr-default.h)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050080}
81
82INHIBIT_PACKAGE_STRIP = "1"
83
84# Compute how to get from libexecdir to bindir in python (easier than shell)
85BINRELPATH = "${@os.path.relpath(d.expand("${STAGING_DIR_NATIVE}${prefix_native}/bin/${TARGET_SYS}"), d.expand("${libexecdir}/gcc/${TARGET_SYS}/${BINV}"))}"
86
87do_install () {
Brad Bishopd7bf8c12018-02-25 22:55:05 -050088 ( cd ${B}/${TARGET_SYS}/libgcc; oe_runmake 'DESTDIR=${D}' install-unwind_h-forbuild install-unwind_h )
Patrick Williamsc124f4f2015-09-15 14:41:29 -050089 oe_runmake 'DESTDIR=${D}' install-host
90
91 install -d ${D}${target_base_libdir}
92 install -d ${D}${target_libdir}
Brad Bishopd7bf8c12018-02-25 22:55:05 -050093
Patrick Williamsc124f4f2015-09-15 14:41:29 -050094 # Link gfortran to g77 to satisfy not-so-smart configure or hard coded g77
95 # gfortran is fully backwards compatible. This is a safe and practical solution.
Brad Bishopd7bf8c12018-02-25 22:55:05 -050096 if [ -n "${@d.getVar('FORTRAN')}" ]; then
97 ln -sf ${STAGING_DIR_NATIVE}${prefix_native}/bin/${TARGET_PREFIX}gfortran ${STAGING_DIR_NATIVE}${prefix_native}/bin/${TARGET_PREFIX}g77 || true
98 fortsymlinks="g77 gfortran"
99 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500100
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500101 # Insert symlinks into libexec so when tools without a prefix are searched for, the correct ones are
102 # found. These need to be relative paths so they work in different locations.
103 dest=${D}${libexecdir}/gcc/${TARGET_SYS}/${BINV}/
104 install -d $dest
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500105 for t in ar as ld ld.bfd ld.gold nm objcopy objdump ranlib strip gcc cpp $fortsymlinks; do
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500106 ln -sf ${BINRELPATH}/${TARGET_PREFIX}$t $dest$t
107 ln -sf ${BINRELPATH}/${TARGET_PREFIX}$t ${dest}${TARGET_PREFIX}$t
108 done
109
110 # Remove things we don't need but keep share/java
111 for d in info man share/doc share/locale share/man share/info; do
112 rm -rf ${D}${STAGING_DIR_NATIVE}${prefix_native}/$d
113 done
114
115 # libquadmath headers need to be available in the gcc libexec dir
116 install -d ${D}${libdir}/gcc/${TARGET_SYS}/${BINV}/include/
117 cp ${S}/libquadmath/quadmath.h ${D}${libdir}/gcc/${TARGET_SYS}/${BINV}/include/
118 cp ${S}/libquadmath/quadmath_weak.h ${D}${libdir}/gcc/${TARGET_SYS}/${BINV}/include/
119
Brad Bishop79641f22019-09-10 07:20:22 -0400120 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
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500121}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500122
123do_package[noexec] = "1"
124do_packagedata[noexec] = "1"
125do_package_write_ipk[noexec] = "1"
126do_package_write_rpm[noexec] = "1"
127do_package_write_deb[noexec] = "1"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500128
Brad Bishopa34c0302019-09-23 22:34:48 -0400129inherit chrpath
130
131python gcc_stash_builddir_fixrpaths() {
132 # rewrite rpaths, breaking hardlinks as required
133 process_dir("/", d.getVar("BUILDDIRSTASH"), d, break_hardlinks = True)
134}
135
136BUILDDIRSTASH = "${WORKDIR}/stashed-builddir/build"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500137do_gcc_stash_builddir[dirs] = "${B}"
138do_gcc_stash_builddir[cleandirs] = "${BUILDDIRSTASH}"
Brad Bishopa34c0302019-09-23 22:34:48 -0400139do_gcc_stash_builddir[postfuncs] += "gcc_stash_builddir_fixrpaths"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500140do_gcc_stash_builddir () {
141 dest=${BUILDDIRSTASH}
142 hardlinkdir . $dest
Brad Bishop79641f22019-09-10 07:20:22 -0400143 # Makefile does move-if-change which can end up with 'timestamp' as file contents so break links to those files
144 rm $dest/gcc/include/*.h
145 cp gcc/include/*.h $dest/gcc/include/
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500146}
147addtask do_gcc_stash_builddir after do_compile before do_install
148SSTATETASKS += "do_gcc_stash_builddir"
149do_gcc_stash_builddir[sstate-inputdirs] = "${BUILDDIRSTASH}"
Brad Bishop19323692019-04-05 15:28:33 -0400150do_gcc_stash_builddir[sstate-outputdirs] = "${COMPONENTS_DIR}/${BUILD_ARCH}/gcc-stashed-builddir-${TARGET_SYS}"
151do_gcc_stash_builddir[sstate-fixmedir] = "${COMPONENTS_DIR}/${BUILD_ARCH}/gcc-stashed-builddir-${TARGET_SYS}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500152
153python do_gcc_stash_builddir_setscene () {
154 sstate_setscene(d)
155}
156addtask do_gcc_stash_builddir_setscene