<?xml version="1.0"?>
<package name="i686-linux-gnu">
	<description>i686-linux-gnu cross-toolchain</description>
	<releases>
		<release version="20260510" revision="2" arch="x86_64">
			<settings>
				<variable name="BINUTILSVERSION">2.46.0</variable>
				<variable name="GCCVERSION">16.1.0</variable>
				<variable name="LINUXHEADERSVERSION">7.0</variable>
				<variable name="GLIBCVERSION">2.43</variable>
			</settings>
			<deps>
				<dep name="gmp"/>
				<dep name="mpfr"/>
				<dep name="mpc"/>
			</deps>
			<preinst>
				<cmd>sed -i -e '/^\/lib\/$NAME/d' /etc/ld.so.conf</cmd>
				<cmd>echo "/lib/$NAME" &gt;&gt; /etc/ld.so.conf</cmd>
				<cmd>sed -i -e '/^\/usr\/lib\/$NAME/d' /etc/ld.so.conf</cmd>
				<cmd>echo "/usr/lib/$NAME" &gt;&gt; /etc/ld.so.conf</cmd>
				<cmd>sed -i -e '/^\/usr\/local\/lib\/$NAME/d' /etc/ld.so.conf</cmd>
				<cmd>echo "/usr/local/lib/$NAME" &gt;&gt; /etc/ld.so.conf</cmd>
			</preinst>
			<build>
				<script>
					<archive name="binutils-$BINUTILSVERSION" builddir="binutils-build">
						<!-- don't install libiberty.a from cross-toolchain -->
						<cmd>sed -i -e 's/install_to_$(INSTALL_DEST) //' ../binutils-$BINUTILSVERSION/libiberty/Makefile.in</cmd>
						<!-- don't install bfd plugins from cross-toolchain -->
						<cmd>sed -i -e '/^install/s/ install-bfdpluginLTLIBRARIES//' ../binutils-$BINUTILSVERSION/ld/Makefile.in</cmd>

						<cmd>../binutils-$BINUTILSVERSION/configure --host=$TARGET --target=$NAME --with-lib-path=/lib/$NAME:/usr/lib/$NAME:/usr/local/lib/$NAME --disable-nls --disable-werror --disable-gprofng</cmd>
						<cmd>make configure-host</cmd>
						<cmd>make</cmd>
						<cmd>make infodir=$PWD/noinst mandir=$PWD/noinst install</cmd>
					</archive>

					<archive name="gcc-$GCCVERSION" builddir="gcc-build">
						<!-- fix build by disabling support for -march=native -->
						<cmd>sed -i -e '/host_detect_local_cpu/,/HAVE_LOCAL_CPU_DETECT/d' ../gcc-$GCCVERSION/gcc/config/i386/i386.h</cmd>
						<cmd>../gcc-$GCCVERSION/configure --host=$TARGET --target=$NAME --enable-languages=c --without-headers --with-slibdir=/usr/lib/$NAME --disable-threads --disable-shared --disable-libatomic --disable-decimal-float --disable-multilib --disable-nls --disable-bootstrap --with-linker-hash-style=gnu --enable-default-pie --enable-default-ssp --without-zstd</cmd>
						<cmd>make all-gcc</cmd>
						<cmd>make all-target-libgcc</cmd>
						<cmd>make tooldir=$PWD/noinst infodir=$PWD/noinst mandir=$PWD/noinst install-gcc</cmd>
						<cmd>make tooldir=$PWD/noinst infodir=$PWD/noinst mandir=$PWD/noinst install-target-libgcc</cmd>
					</archive>
					<!-- build system of glibc expects a libgcc_eh, but gcc built with disable-shared doesn't install libgcc_eh and includes everything in libgcc itself; provide libgcc_eh for glibc -->
					<cmd>ln -sfv libgcc.a $(/usr/bin/$NAME-gcc -print-libgcc-file-name | sed 's/libgcc/&amp;_eh/')</cmd>

					<archive name="linux-$LINUXHEADERSVERSION" srcdir="linux-headers-$LINUXHEADERSVERSION">
						<cmd>make headers_install INSTALL_HDR_PATH=$PWD/dest ARCH=i386</cmd>
						<cmd>mkdir -p /usr/include/$NAME</cmd>
						<cmd>cp -a dest/include/* /usr/include/$NAME</cmd>
					</archive>

					<archive name="glibc-$GLIBCVERSION" builddir="glibc-build">
						<!-- update from release branch -->
						<patch name="glibc-$GLIBCVERSION-20260509"/>

						<!-- gcc-bootstrap is built without C++ support,
						     avoid picking up C++ compiler from the host to fix build -->
						<cmd>echo "ac_cv_prog_CXX=" &gt; config.cache</cmd>
						<cmd>echo "ac_cv_prog_ac_ct_CXX=" &gt;&gt; config.cache</cmd>
						<!-- and disable fallback to g++ if no C++ compiler is found -->
						<cmd>sed -i -e 's/CXX="g++"/CXX=""/' ../glibc-$GLIBCVERSION/configure</cmd>

						<!-- disable stack protector to fix bootstrapping -->
						<cmd>sed -i -e 's/libc_cv_ssp=yes/libc_cv_ssp=no/g' -e 's/libc_cv_ssp_strong=yes/libc_cv_ssp_strong=no/g' ../glibc-$GLIBCVERSION/configure</cmd>

						<!-- fix install without install_root
						     test-installation script is broken -->
						<cmd>sed -i -e '/test-installation.pl/d' ../glibc-$GLIBCVERSION/Makefile</cmd>

						<!-- specify slibdir, rtlddir, and rootsbindir -->
						<cmd>sed -i -e "s%libc_cv_slibdir='/lib'$%libc_cv_slibdir='/lib/$NAME'%" -e "s%libc_cv_rtlddir='/lib'$%libc_cv_rtlddir='/lib/$NAME'%" -e 's%libc_cv_rootsbindir=/sbin$%libc_cv_rootsbindir=/sbin/$NAME%' ../glibc-$GLIBCVERSION/sysdeps/gnu/configure</cmd>
						
						<!-- don't install /etc/rpc -->
						<cmd>sed -i -e 's% $(inst_sysconfdir)/rpc%%' ../glibc-$GLIBCVERSION/sunrpc/Makefile</cmd>

						<cmd>AUTOCONF=no ../glibc-$GLIBCVERSION/configure --libdir=/usr/lib/$NAME --libexecdir=/usr/lib/$NAME --includedir=/usr/include/$NAME --build=$TARGET --host=$NAME --disable-profile --enable-add-ons --with-headers=/usr/include/$NAME --without-gd --disable-build-nscd --disable-nscd --disable-nls --cache-file=config.cache</cmd>
						<cmd>make</cmd>
						<cmd>make bindir=/usr/bin/$NAME sbindir=/usr/sbin/$NAME infodir=$PWD/noinst datadir=$PWD/noinst install</cmd>
						
						<cmd>ln -svf $NAME/ld-linux.so.2 /lib/ld-linux.so.2</cmd>
					</archive>

					<archive name="gcc-$GCCVERSION" builddir="gcc-build">
						<!-- don't install libiberty.a from cross-toolchain -->
						<cmd>sed -i -e 's/install_to_$(INSTALL_DEST) //' ../gcc-$GCCVERSION/libiberty/Makefile.in</cmd>
						<!-- don't install libcc1 from cross-toolchain -->
						<cmd>sed -i -e '/^install-data/s/install-cc1libLTLIBRARIES//' ../gcc-$GCCVERSION/libcc1/Makefile.in</cmd>

						<!-- fix startfiles path -->
						<cmd>echo "
#undef STARTFILE_PREFIX_SPEC
#define STARTFILE_PREFIX_SPEC \"/usr/lib/$NAME/\"" &gt;&gt; ../gcc-$GCCVERSION/gcc/config/linux.h</cmd>
						<!-- fix build by disabling support for -march=native -->
						<cmd>sed -i -e '/host_detect_local_cpu/,/HAVE_LOCAL_CPU_DETECT/d' ../gcc-$GCCVERSION/gcc/config/i386/i386.h</cmd>

						<!-- move toolexeclibdir from /usr/$NAME/lib to /usr/lib/$NAME -->
						<cmd>find ../gcc-$GCCVERSION -name configure | xargs sed -i -e "/toolexeclibdir=.*toolexecdir.*lib/s%=[^ ]\+%='\$(libdir)/$NAME'%"</cmd>

						<!-- default to -ftrivial-auto-var-init=zero -->
						<cmd>sed -i -e '/^Common/s/AUTO_INIT_UNINITIALIZED/AUTO_INIT_ZERO/' ../gcc-$GCCVERSION/gcc/common.opt</cmd>
						<cmd>../gcc-$GCCVERSION/configure --includedir=/usr/include/$NAME --host=$TARGET --target=$NAME --enable-languages=c,c++ --with-native-system-header-dir=/usr/include/$NAME --with-headers=/usr/include/$NAME --with-slibdir=/usr/lib/$NAME --enable-shared --disable-multilib --enable-clocale=gnu --enable-threads=posix --enable-__cxa_atexit --disable-nls --disable-libstdcxx-pch --disable-bootstrap --with-gxx-include-dir=/usr/include/$NAME/c++/$GCCVERSION --with-linker-hash-style=gnu --enable-default-pie --enable-default-ssp --without-zstd --disable-libsanitizer</cmd>
						<cmd>make</cmd>
						<cmd>make infodir=$PWD/noinst mandir=$PWD/noinst datadir=$PWD/noinst localedir=$PWD/noinst install</cmd>
					</archive>
				</script>
			</build>
		</release>
	</releases>
</package>
