1inherit cross-canadian
2
3SUMMARY = "GNU cc and gcc C compilers (cross-canadian for ${TARGET_ARCH} target)"
4PN = "gcc-cross-canadian-${TRANSLATED_TARGET_ARCH}"
5
6DEPENDS = "virtual/${TARGET_PREFIX}gcc virtual/${HOST_PREFIX}gcc-crosssdk virtual/${HOST_PREFIX}binutils-crosssdk virtual/nativesdk-libc nativesdk-gettext flex-native virtual/libc"
7
8GCCMULTILIB = "--enable-multilib"
9
10require gcc-configure-common.inc
11
12EXTRA_OECONF += "--with-plugin-ld=ld"
13EXTRA_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 () {
49        if [ ! -d ${RECIPE_SYSROOT}/${target_includedir} ]; then
50            mkdir -p ${RECIPE_SYSROOT}/${target_includedir}
51        fi
52	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
67	(cd ${B}/${TARGET_SYS}/libgcc; oe_runmake enable-execute-stack.c unwind.h md-unwind-support.h sfp-machine.h gthr-default.h)
68}
69
70PACKAGES = "${PN}-dbg ${PN} ${PN}-doc"
71
72FILES:${PN} = "\
73    ${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.* \
82    ${libdir}/bfd-plugins/*.so \
83    ${includedir}/c++/${BINV} \
84    ${prefix}/${TARGET_SYS}/bin/* \
85    ${prefix}/${TARGET_SYS}/lib/* \
86    ${prefix}/${TARGET_SYS}${target_includedir}/* \
87"
88INSANE_SKIP:${PN} += "dev-so"
89
90FILES:${PN}-doc = "\
91    ${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}"))}"
100# linker plugin path
101LIBRELPATH = "${@os.path.relpath(d.expand("${libexecdir}/gcc/${TARGET_SYS}/${BINV}"), d.expand("${libdir}/bfd-plugins"))}"
102
103do_install () {
104	( cd ${B}/${TARGET_SYS}/libgcc; oe_runmake 'DESTDIR=${D}' install-unwind_h-forbuild install-unwind_h )
105	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
116	rm -f ${D}${bindir}/*gcc-${BINV}*
117
118	# 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}
131	for t in ar as ld ld.bfd ld.gold nm objcopy objdump ranlib strip g77 gcc cpp gfortran; do
132		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
138
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
144	# 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
148	chown -R root:root ${D}
149
150	cross_canadian_bindirlinks
151
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
174}
175
176ELFUTILS = "nativesdk-elfutils"
177DEPENDS += "nativesdk-gmp nativesdk-mpfr nativesdk-libmpc ${ELFUTILS} nativesdk-zlib nativesdk-zstd"
178RDEPENDS:${PN} += "nativesdk-mpfr nativesdk-libmpc ${ELFUTILS}"
179
180SYSTEMHEADERS = "${target_includedir}/"
181SYSTEMLIBS = "${target_base_libdir}/"
182SYSTEMLIBS1 = "${target_libdir}/"
183
184EXTRA_OECONF += "--enable-poison-system-directories"
185
186# gcc 4.7 needs -isystem
187export ARCH_FLAGS_FOR_TARGET = "--sysroot=${STAGING_DIR_TARGET} -isystem=${target_includedir}"
188