blob: ec87b462193f7d4837fb57ed9dbda98a21bdbd47 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001inherit cross-canadian
2
3SUMMARY = "GNU cc and gcc C compilers (cross-canadian for ${TARGET_ARCH} target)"
4PN = "gcc-cross-canadian-${TRANSLATED_TARGET_ARCH}"
5
Andrew Geissler028142b2023-05-05 11:29:21 -05006DEPENDS = "virtual/${TARGET_PREFIX}gcc virtual/${HOST_PREFIX}gcc virtual/${HOST_PREFIX}binutils virtual/nativesdk-libc nativesdk-gettext flex-native virtual/libc"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007
8GCCMULTILIB = "--enable-multilib"
9
10require gcc-configure-common.inc
11
Andrew Geissler87f5cff2022-09-30 13:13:31 -050012EXTRA_OECONF += "--with-plugin-ld=ld"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013EXTRA_OECONF_PATHS = "\
14 --with-gxx-include-dir=/not/exist${target_includedir}/c++/${BINV} \
15 --with-build-time-tools=${STAGING_DIR_NATIVE}${prefix_native}/${TARGET_SYS}/bin \
16 --with-sysroot=/not/exist \
17 --with-build-sysroot=${STAGING_DIR_TARGET} \
18"
19# We have to point gcc at a sysroot but we don't need to rebuild if this changes
20# e.g. we switch between different machines with different tunes.
21EXTRA_OECONF_PATHS[vardepsexclude] = "TUNE_PKGARCH"
22TARGET_ARCH[vardepsexclude] = "TUNE_ARCH"
23get_gcc_float_setting[vardepvalue] = ""
24
25#
26# gcc-cross looks and finds these in ${exec_prefix} but we're not so lucky
27# for the sdk. Hardcoding the paths ensures the build doesn't go canadian or worse.
28#
29export AR_FOR_TARGET = "${TARGET_PREFIX}ar"
30export AS_FOR_TARGET = "${TARGET_PREFIX}as"
31export DLLTOOL_FOR_TARGET = "${TARGET_PREFIX}dlltool"
32export CC_FOR_TARGET = "${TARGET_PREFIX}gcc"
33export CXX_FOR_TARGET = "${TARGET_PREFIX}g++"
34export GCC_FOR_TARGET = "${TARGET_PREFIX}gcc"
35export LD_FOR_TARGET = "${TARGET_PREFIX}ld"
36export LIPO_FOR_TARGET = "${TARGET_PREFIX}lipo"
37export NM_FOR_TARGET = "${TARGET_PREFIX}nm"
38export OBJDUMP_FOR_TARGET = "${TARGET_PREFIX}objdump"
39export RANLIB_FOR_TARGET = "${TARGET_PREFIX}ranlib"
40export STRIP_FOR_TARGET = "${TARGET_PREFIX}strip"
41export WINDRES_FOR_TARGET = "${TARGET_PREFIX}windres"
42
43#
44# We need to override this and make sure the compiler can find staging
45#
46export ARCH_FLAGS_FOR_TARGET = "--sysroot=${STAGING_DIR_TARGET}"
47
48do_configure () {
Andrew Geissler595f6302022-01-24 19:11:47 +000049 if [ ! -d ${RECIPE_SYSROOT}/${target_includedir} ]; then
50 mkdir -p ${RECIPE_SYSROOT}/${target_includedir}
51 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -050052 export CC_FOR_BUILD="${BUILD_CC}"
53 export CXX_FOR_BUILD="${BUILD_CXX}"
54 export CFLAGS_FOR_BUILD="${BUILD_CFLAGS}"
55 export CPPFLAGS_FOR_BUILD="${BUILD_CPPFLAGS}"
56 export CXXFLAGS_FOR_BUILD="${BUILD_CXXFLAGS}"
57 export LDFLAGS_FOR_BUILD="${BUILD_LDFLAGS}"
58 export CFLAGS_FOR_TARGET="${TARGET_CFLAGS}"
59 export CPPFLAGS_FOR_TARGET="${TARGET_CPPFLAGS}"
60 export CXXFLAGS_FOR_TARGET="${TARGET_CXXFLAGS}"
61 export LDFLAGS_FOR_TARGET="${TARGET_LDFLAGS}"
62 oe_runconf
63}
64
65do_compile () {
66 oe_runmake all-host configure-target-libgcc
Brad Bishopd7bf8c12018-02-25 22:55:05 -050067 (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 -050068}
69
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070PACKAGES = "${PN}-dbg ${PN} ${PN}-doc"
71
Patrick Williams213cb262021-08-07 19:21:33 -050072FILES:${PN} = "\
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073 ${exec_prefix}/bin/* \
74 ${libexecdir}/gcc/${TARGET_SYS}/${BINV}/* \
75 ${gcclibdir}/${TARGET_SYS}/${BINV}/*.o \
76 ${gcclibdir}/${TARGET_SYS}/${BINV}/specs \
77 ${gcclibdir}/${TARGET_SYS}/${BINV}/lib* \
78 ${gcclibdir}/${TARGET_SYS}/${BINV}/include \
79 ${gcclibdir}/${TARGET_SYS}/${BINV}/include-fixed \
80 ${gcclibdir}/${TARGET_SYS}/${BINV}/plugin/include/ \
81 ${gcclibdir}/${TARGET_SYS}/${BINV}/plugin/gtype.* \
Andrew Geisslerc926e172021-05-07 16:11:35 -050082 ${libdir}/bfd-plugins/*.so \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050083 ${includedir}/c++/${BINV} \
84 ${prefix}/${TARGET_SYS}/bin/* \
85 ${prefix}/${TARGET_SYS}/lib/* \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050086 ${prefix}/${TARGET_SYS}${target_includedir}/* \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050087"
Patrick Williams213cb262021-08-07 19:21:33 -050088INSANE_SKIP:${PN} += "dev-so"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050089
Patrick Williams213cb262021-08-07 19:21:33 -050090FILES:${PN}-doc = "\
Patrick Williamsc124f4f2015-09-15 14:41:29 -050091 ${infodir} \
92 ${mandir} \
93 ${gcclibdir}/${TARGET_SYS}/${BINV}/include/README \
94"
95
96EXEEXT = ""
97
98# Compute how to get from libexecdir to bindir in python (easier than shell)
99BINRELPATH = "${@os.path.relpath(d.expand("${bindir}"), d.expand("${libexecdir}/gcc/${TARGET_SYS}/${BINV}"))}"
Andrew Geisslerc926e172021-05-07 16:11:35 -0500100# linker plugin path
101LIBRELPATH = "${@os.path.relpath(d.expand("${libexecdir}/gcc/${TARGET_SYS}/${BINV}"), d.expand("${libdir}/bfd-plugins"))}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500102
103do_install () {
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500104 ( cd ${B}/${TARGET_SYS}/libgcc; oe_runmake 'DESTDIR=${D}' install-unwind_h-forbuild install-unwind_h )
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500105 oe_runmake 'DESTDIR=${D}' install-host
106
107 # Cleanup some of the ${libdir}{,exec}/gcc stuff ...
108 rm -r ${D}${libdir}/gcc/${TARGET_SYS}/${BINV}/install-tools
109 rm -r ${D}${libexecdir}/gcc/${TARGET_SYS}/${BINV}/install-tools
110 rm -rf ${D}${libdir}/gcc/${TARGET_SYS}/${BINV}/finclude
111
112 # We care about g++ not c++
113 rm -f ${D}${bindir}/*c++
114
115 # We don't care about the gcc-<version> copies
Andrew Geissler635e0e42020-08-21 15:58:33 -0500116 rm -f ${D}${bindir}/*gcc-${BINV}*
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500117
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500118 # Cleanup empty directories which are not shipped
119 # we use rmdir instead of 'rm -f' to ensure the non empty directories are not deleted
120 # ${D}${libdir}/../lib only seems to appear with SDKMACHINE=i686
121 local empty_dirs="${D}${libdir}/../lib ${D}${prefix}/${TARGET_SYS}/lib ${D}${prefix}/${TARGET_SYS} ${D}${includedir}"
122 for i in $empty_dirs; do
123 [ -d $i ] && rmdir --ignore-fail-on-non-empty $i
124 done
125
126 # Insert symlinks into libexec so when tools without a prefix are searched for, the correct ones are
127 # found.
128 dest=${D}${libexecdir}/gcc/${TARGET_SYS}/${BINV}/
129 install -d $dest
130 suffix=${EXEEXT}
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700131 for t in ar as ld ld.bfd ld.gold nm objcopy objdump ranlib strip g77 gcc cpp gfortran; do
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500132 if [ "$t" = "g77" -o "$t" = "gfortran" ] && [ ! -e ${D}${bindir}/${TARGET_PREFIX}$t$suffix ]; then
133 continue
134 fi
135
136 ln -sf ${BINRELPATH}/${TARGET_PREFIX}$t$suffix $dest$t$suffix
137 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500138
139 # libquadmath headers need to be available in the gcc libexec dir
140 install -d ${D}${libdir}/gcc/${TARGET_SYS}/${BINV}/include/
141 cp ${S}/libquadmath/quadmath.h ${D}${libdir}/gcc/${TARGET_SYS}/${BINV}/include/
142 cp ${S}/libquadmath/quadmath_weak.h ${D}${libdir}/gcc/${TARGET_SYS}/${BINV}/include/
143
Andrew Geisslerc926e172021-05-07 16:11:35 -0500144 # install LTO linker plugins where binutils tools can find it
145 install -d ${D}${libdir}/bfd-plugins
146 ln -sf ${LIBRELPATH}/liblto_plugin.so ${D}${libdir}/bfd-plugins/liblto_plugin.so
147
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500148 chown -R root:root ${D}
Andrew Geisslerc926e172021-05-07 16:11:35 -0500149
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500150 cross_canadian_bindirlinks
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500151
152 for i in linux ${CANADIANEXTRAOS}
153 do
154 for v in ${CANADIANEXTRAVENDOR}
155 do
156 d=${D}${bindir}/../${TARGET_ARCH}$v-$i
157 install -d $d
158 for j in ${TARGET_PREFIX}gcc${EXEEXT} ${TARGET_PREFIX}g++${EXEEXT}
159 do
160 p=${TARGET_ARCH}$v-$i-`echo $j | sed -e s,${TARGET_PREFIX},,`
161 case $i in
162 *musl*)
163 rm -rf $d/$p
164 echo "#!/usr/bin/env sh" > $d/$p
165 echo "exec \`dirname \$0\`/../${TARGET_SYS}/$j -mmusl \$@" >> $d/$p
166 chmod 0755 $d/$p
167 ;;
168 *)
169 ;;
170 esac
171 done
172 done
173 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500174}
175
176ELFUTILS = "nativesdk-elfutils"
Andrew Geissler78b72792022-06-14 06:47:25 -0500177DEPENDS += "nativesdk-gmp nativesdk-mpfr nativesdk-libmpc ${ELFUTILS} nativesdk-zlib nativesdk-zstd"
Patrick Williams213cb262021-08-07 19:21:33 -0500178RDEPENDS:${PN} += "nativesdk-mpfr nativesdk-libmpc ${ELFUTILS}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500179
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500180SYSTEMHEADERS = "${target_includedir}/"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500181SYSTEMLIBS = "${target_base_libdir}/"
182SYSTEMLIBS1 = "${target_libdir}/"
183
184EXTRA_OECONF += "--enable-poison-system-directories"
Andrew Geissler595f6302022-01-24 19:11:47 +0000185
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500186# gcc 4.7 needs -isystem
187export ARCH_FLAGS_FOR_TARGET = "--sysroot=${STAGING_DIR_TARGET} -isystem=${target_includedir}"