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