--- /usr/portage/sys-devel/gcc/gcc-5.3.0-r1.ebuild	2017-01-09 12:47:51.108842847 -0800
+++ /usr/local/portage/sys-devel/gcc/gcc-5.3.0-r1.ebuild	2017-05-30 15:09:35.414611286 -0700
@@ -183,6 +183,17 @@
 		fi
 	fi
 
+	if is_crosscompile; then
+		# if we don't tell it where to go, libcc1 stuff ends up in ${ROOT}/usr/lib (or rather dies colliding)
+		CC1DIR="${WORKDIR}/${P}/libcc1"
+		sed -i 's%cc1libdir = .*%cc1libdir = /usr/$(host_noncanonical)/$(target_noncanonical)/lib/$(gcc_version)%' ${CC1DIR}/Makefile.am
+		sed -i 's%plugindir = .*%plugindir = /usr/lib/gcc/$(target_noncanonical)/$(gcc_version)/plugin%' ${CC1DIR}/Makefile.am
+		sed -i 's%cc1libdir = .*%cc1libdir = /usr/$(host_noncanonical)/$(target_noncanonical)/lib/$(gcc_version)%' ${CC1DIR}/Makefile.in
+		sed -i 's%plugindir = .*%plugindir = /usr/lib/gcc/$(target_noncanonical)/$(gcc_version)/plugin%' ${CC1DIR}/Makefile.in
+		if [[ ${CTARGET}==avr* ]]; then
+			sed -i 's%native_system_header_dir=/usr/include%native_system_header_dir=/include%' ${WORKDIR}/${P}/gcc/config.gcc
+		fi
+	fi
 	# Ada gnat compiler bootstrap preparation
 	if use ada && use amd64; then
 		make -C ${WORKDIR}/${GNAT64%%.*} ins-all prefix=${S}/gnatboot > /dev/null || die "ada preparation failed"
@@ -208,21 +219,22 @@
 			*-klibc)			needed_libc=klibc;;
 			*-musl*)			needed_libc=musl;;
 			*-uclibc*)			needed_libc=uclibc;;
+			avr*)				needed_libc=avr-libc;;
 		esac
-		confgcc+=" --disable-bootstrap --enable-poision-system-directories"
+		confgcc+=" --disable-bootstrap --enable-poison-system-directories"
 		if ! has_version ${CATEGORY}/${needed_libc}; then
 			# we are building with libc that is not installed:
-			confgcc+=" --disable-shared --disable-libatomic --disable-threads --without-headers"
+			confgcc+=" --disable-shared --disable-libatomic --disable-threads --without-headers --disable-libstdcxx"
 		elif built_with_use --hidden --missing false ${CATEGORY}/${needed_libc} crosscompile_opts_headers-only; then
 			# libc installed, but has USE="crosscompile_opts_headers-only" to only install headers:
-			confgcc+=" --disable-shared --disable-libatomic --with-sysroot=${PREFIX}/${CTARGET}"
+			confgcc+=" --disable-shared --disable-libatomic --with-sysroot=${PREFIX}/${CTARGET} --disable-libstdcxx"
 		else
 			# libc is installed:
-			confgcc+=" --with-sysroot=${PREFIX}/${CTARGET}"
+			confgcc+=" --with-sysroot=${PREFIX}/${CTARGET} --enable-libstdcxx-time"
 		fi
 		confgcc+=" --disable-libgomp"
 	else
-		confgcc+=" $(use_enable openmp libgomp)"
+		confgcc+=" $(use_enable openmp libgomp) --enable-libstdcxx-time"
 	fi
 	[[ -n ${CBUILD} ]] && confgcc+=" --build=${CBUILD}"
 	# Determine language support:
@@ -239,6 +251,9 @@
 		export PATH="${S}/gnatboot/bin:${PATH}"
 	fi
 	confgcc+=" $(use_enable openmp libgomp)"
+	#if [[ ${CTARGET}==avr* ]]; then
+	#	confgcc+=" --enable-openmp=no"
+	#fi
 	confgcc+=" --enable-languages=${GCC_LANG} --disable-libgcj"
 	confgcc+=" $(use_enable hardened esp)"
 	confgcc+=" $(use_enable sanitize libsanitizer)"
@@ -315,7 +330,6 @@
 		--mandir=${DATAPATH}/man \
 		--infodir=${DATAPATH}/info \
 		--with-gxx-include-dir=${STDCXX_INCDIR} \
-		--enable-libstdcxx-time \
 		--enable-__cxa_atexit \
 		--enable-clocale=gnu \
 		--host=$CHOST \
@@ -338,13 +352,17 @@
 	# due to mpfr dir structure changes. We look for includes in the source directory,
 	# and libraries in the build (objdir) directory.
 
-	if use arm ; then
+#	if use arm ; then
+# That fails miserably when cross-compiling on armv7a
+	if use arm && ! is_crosscompile; then
 		# Source : https://sourceware.org/bugzilla/attachment.cgi?id=6807
 		# Workaround for a problem introduced with GMP 5.1.0.
 		# If configured by gcc with the "none" host & target, it will result in undefined references
 		# to '__gmpn_invert_limb' during linking.
 		# Should be fixed by next version of gcc.
 		sed -i "s/none-/${arm_arch_without_dash}-/" ${WORKDIR}/objdir/Makefile || die
+	elif use arm && is_crosscompile; then		
+		sed -i "s/none-/${CHOST%%-*}-/g" ${WORKDIR}/objdir/Makefile || die	
 	fi
 
 }
@@ -472,6 +490,14 @@
 
 # GENTOO ENV SETUP
 
+	if is_crosscompile; then
+		if ! has_version ${CATEGORY}/${needed_libc} || built_with_use --hidden --missing false ${CATEGORY}/${needed_libc} crosscompile_opts_headers-only; then
+			# not cruft!  glibc needs this for 2nd (real) pass else it fails, we'll delete it on gcc 2nd pass
+			dodir /etc/env.d
+			echo -e "PATH=/usr/${CHOST}/${CTARGET}/gcc-bin/${PV}\nROOTPATH=/usr/${CHOST}/${CTARGET}/gcc-bin/${PV}" > \
+				"${D}"/etc/env.d/05gcc-${CTARGET}
+		fi
+	fi
 	dodir /etc/env.d/gcc
 	create_gcc_env_entry
 
@@ -524,7 +550,9 @@
 	if is_crosscompile ; then
 		if [[ -z $(ls "${ROOT}"/etc/env.d/gcc/${CTARGET}* 2>/dev/null) ]] ; then
 			rm -f "${ROOT}"/etc/env.d/gcc/config-${CTARGET}
-			rm -f "${ROOT}"/etc/env.d/??gcc-${CTARGET}
+			if ! built_with_use --hidden --missing false ${CATEGORY}/${needed_libc} crosscompile_opts_headers-only; then
+				rm -f "${ROOT}"/etc/env.d/??gcc-${CTARGET}
+			fi	
 			rm -f "${ROOT}"/usr/bin/${CTARGET}-{gcc,{g,c}++}{,32,64}
 		fi
 		return 0
