<?xml version="1.0"?>
<package name="gcc">
	<description>GNU compiler collection</description>
	<!-- rebuild libtool after every gcc version change as it hardcodes versioned paths -->
	<releases>
		<release version="15.2.0" revision="1" tag="bootstrap">
			<build>
				<script>
					<archive name="gcc-$VERSION" 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-$VERSION/gcc/config/i386/i386.h</cmd>
						<!-- default to -ftrivial-auto-var-init=zero -->
						<cmd>sed -i -e '/^Common/s/AUTO_INIT_UNINITIALIZED/AUTO_INIT_ZERO/' ../gcc-$VERSION/gcc/common.opt</cmd>
						<cmd>../gcc-$VERSION/configure --build=$HOST --host=$HOST --target=$TARGET --enable-languages=c --without-headers --disable-threads --disable-shared --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 install-gcc</cmd>
						<cmd>make install-target-libgcc</cmd>
					</archive>
				</script>
			</build>
		</release>
		<release version="15.2.0" revision="2" tag="stage1">
			<deps>
				<dep name="glibc" tag="stage2"/>
			</deps>
			<build>
				<script>
					<archive name="gcc-$VERSION" builddir="gcc-build">
						<!-- fix build with glibc 2.43, already upstream -->
						<patch name="gcc-$VERSION-glibc-2.43-1"/>

						<!-- don't use /lib64 on x86_64 -->
						<cmd>sed -i -e 's@/lib64@/lib@g' ../gcc-$VERSION/gcc/config/i386/{linux64.h,t-linux64}</cmd>
						<!-- the following modifications are necessary because glibc has been installed in /stage2 instead of /usr -->
						<!-- dynamic linker is in /stage2/lib, not in /lib -->
						<cmd>sed -i -e 's@/lib/ld-linux.so.2@/stage2/lib/ld-linux.so.2@g' ../gcc-$VERSION/gcc/config/i386/linux.h</cmd>
						<cmd>sed -i -e 's@/lib/ld-linux-x86-64.so.2@/stage2/lib/ld-linux-x86-64.so.2@g' ../gcc-$VERSION/gcc/config/i386/linux64.h</cmd>
						<cmd>sed -i -e 's@/lib/ld-linux.so.3@/stage2/lib/ld-linux.so.3@g' ../gcc-$VERSION/gcc/config/arm/linux-eabi.h</cmd>
						<!-- startfiles are in /stage2/lib, not in /usr/lib -->
						<cmd>echo "
#undef STARTFILE_PREFIX_SPEC
#define STARTFILE_PREFIX_SPEC \"/stage2/lib/\"" &gt;&gt; ../gcc-$VERSION/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-$VERSION/gcc/config/i386/i386.h</cmd>
						<!-- default to -ftrivial-auto-var-init=zero -->
						<cmd>sed -i -e '/^Common/s/AUTO_INIT_UNINITIALIZED/AUTO_INIT_ZERO/' ../gcc-$VERSION/gcc/common.opt</cmd>
						<cmd>../gcc-$VERSION/configure --with-local-prefix=/stage2 --build=$HOST --host=$HOST --target=$TARGET --enable-languages=c,c++ --with-sysroot=/upkg --with-native-system-header-dir=/stage2/include --with-headers=/stage2/include --enable-shared --disable-multilib --enable-clocale=gnu --enable-threads=posix --enable-__cxa_atexit --disable-libstdcxx-pch --disable-nls --disable-bootstrap --with-linker-hash-style=gnu --enable-default-pie --enable-default-ssp --without-zstd --disable-libsanitizer</cmd>
						<cmd>make</cmd>
						<cmd>make install</cmd>
					</archive>
				</script>
			</build>
		</release>
		<release version="15.2.0" revision="2" tag="stage2">
			<deps>
				<dep name="glibc" tag="stage2"/>
				<dep name="gmp" tag="stage2"/>
				<dep name="mpfr" tag="stage2"/>
				<dep name="mpc" tag="stage2"/>
			</deps>
			<build>
				<script>
					<archive name="gcc-$VERSION" builddir="gcc-build">
						<!-- fix build with glibc 2.43, already upstream -->
						<patch name="gcc-$VERSION-glibc-2.43-1"/>

						<!-- don't use /lib64 on x86_64 -->
						<cmd>sed -i -e 's@/lib64@/lib@g' ../gcc-$VERSION/gcc/config/i386/{linux64.h,t-linux64}</cmd>
						<!-- the following modifications are necessary because glibc has been installed in /stage2 instead of /usr -->
						<!-- dynamic linker is in /stage2/lib, not in /lib -->
						<cmd>sed -i -e 's@/lib/ld-linux.so.2@/stage2/lib/ld-linux.so.2@g' ../gcc-$VERSION/gcc/config/i386/linux.h</cmd>
						<cmd>sed -i -e 's@/lib/ld-linux-x86-64.so.2@/stage2/lib/ld-linux-x86-64.so.2@g' ../gcc-$VERSION/gcc/config/i386/linux64.h</cmd>
						<cmd>sed -i -e 's@/lib/ld-linux.so.3@/stage2/lib/ld-linux.so.3@g' ../gcc-$VERSION/gcc/config/arm/linux-eabi.h</cmd>
						<!-- startfiles are in /stage2/lib, not in /usr/lib -->
						<cmd>echo "
#undef STARTFILE_PREFIX_SPEC
#define STARTFILE_PREFIX_SPEC \"/stage2/lib/\"" &gt;&gt; ../gcc-$VERSION/gcc/config/linux.h</cmd>
						<!-- default to -ftrivial-auto-var-init=zero -->
						<cmd>sed -i -e '/^Common/s/AUTO_INIT_UNINITIALIZED/AUTO_INIT_ZERO/' ../gcc-$VERSION/gcc/common.opt</cmd>
						<cmd>../gcc-$VERSION/configure --with-local-prefix=/stage2 --build=$HOST --host=$TARGET --target=$TARGET --enable-languages=c,c++ --with-build-sysroot=/upkg --with-native-system-header-dir=/stage2/include --enable-shared --disable-multilib --enable-clocale=gnu --enable-threads=posix --enable-__cxa_atexit --disable-libstdcxx-pch --disable-nls --disable-bootstrap --with-linker-hash-style=gnu --enable-default-pie --enable-default-ssp --without-zstd --disable-libsanitizer</cmd>
						<!-- when cross-compiling a target native compiler, gcc uses the wrong assembler / linker to perform configure tests, so specify the right tools -->
						<cmd>make AS_FOR_TARGET=/stage1/bin/$TARGET-as LD_FOR_TARGET=/stage1/bin/$TARGET-ld</cmd>
						<cmd>make install</cmd>
					</archive>
				</script>
			</build>
		</release>
		<release version="15.2.0" revision="2">
			<deps>
				<dep name="glibc"/>
				<dep name="libxcrypt"/>
				<dep name="gmp"/>
				<dep name="mpfr"/>
				<dep name="mpc"/>
			</deps>
			<build>
				<script>
					<archive name="gcc-$VERSION" builddir="gcc-build">
						<!-- fix build with glibc 2.43, already upstream -->
						<patch name="gcc-$VERSION-glibc-2.43-1"/>

						<!-- don't use /lib64 on x86_64 -->
						<cmd>sed -i -e 's@/lib64@/lib@g' ../gcc-$VERSION/gcc/config/i386/{linux64.h,t-linux64}</cmd>
						<!-- don't install libiberty.a (we use the version from binutils) -->
						<cmd>sed -i -e 's/install_to_$(INSTALL_DEST) //' ../gcc-$VERSION/libiberty/Makefile.in</cmd>
						<!-- default to -ftrivial-auto-var-init=zero -->
						<cmd>sed -i -e '/^Common/s/AUTO_INIT_UNINITIALIZED/AUTO_INIT_ZERO/' ../gcc-$VERSION/gcc/common.opt</cmd>
						<cmd>../gcc-$VERSION/configure --enable-languages=c,c++ --enable-shared --disable-multilib --enable-clocale=gnu --enable-threads=posix --enable-__cxa_atexit --disable-libstdcxx-pch --disable-bootstrap --with-linker-hash-style=gnu --enable-default-pie --enable-default-ssp --without-zstd</cmd>
						<cmd>make</cmd>
						<cmd>make install</cmd>

						<cmd>ln -svf /usr/bin/cpp /lib</cmd>
						<cmd>ln -svf gcc /usr/bin/cc</cmd>
					</archive>
				</script>
			</build>
		</release>
	</releases>
</package>
