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