lalbornoz 340f4c
# Order: stage1, runtime, full, native
lalbornoz 340f4c
lalbornoz 340f4c
if is_build_script_done finished; then
lalbornoz 340f4c
        exit 212;
lalbornoz 340f4c
elif [ "x${3}" = "xruntime" ]\
lalbornoz 340f4c
||   [ "x${3}" = "xfull" ]; then
lalbornoz 340f4c
	export CFLAGS="${GCCFLAGS}" CXXFLAGS="${GCCFLAGS}";
lalbornoz 340f4c
	set_build_dir "cbb-gcc-${GCC_VERSION}" "${TARGET}";
lalbornoz 340f4c
	cd "${_build_dir}";
lalbornoz 340f4c
	if [ "x${3}" = "xruntime" ]; then
lalbornoz 340f4c
		# GCC, compiler runtime.
lalbornoz 340f4c
		if ! is_build_script_done built; then
lalbornoz 340f4c
			make ${MAKEFLAGS} all-target-libgcc;
lalbornoz 340f4c
			set_build_script_done built -installed;
lalbornoz 340f4c
		fi;
lalbornoz 340f4c
		if ! is_build_script_done installed; then
lalbornoz 340f4c
			make ${MAKEFLAGS} install-target-libgcc;
lalbornoz 340f4c
			set_build_script_done installed finished;
lalbornoz 340f4c
		fi;
lalbornoz 340f4c
	elif [ "x${3}" = "xfull" ]; then
lalbornoz 340f4c
		# GCC, everything else.
lalbornoz 340f4c
		if ! is_build_script_done built1; then
lalbornoz 340f4c
			make ${MAKEFLAGS} all-target-libstdc++-v3;
lalbornoz 340f4c
			set_build_script_done built1 -installed1;
lalbornoz 340f4c
		fi;
lalbornoz 340f4c
		if ! is_build_script_done installed1; then
lalbornoz 340f4c
			make ${MAKEFLAGS} install-target-libstdc++-v3;
lalbornoz 340f4c
			set_build_script_done installed1 -built2;
lalbornoz 340f4c
		fi;
lalbornoz 340f4c
		if ! is_build_script_done built2; then
lalbornoz 340f4c
			make ${MAKEFLAGS};
lalbornoz 340f4c
			set_build_script_done built2 -installed2;
lalbornoz 340f4c
		fi;
lalbornoz 340f4c
		if ! is_build_script_done installed2; then
lalbornoz 340f4c
			make ${MAKEFLAGS} install;
lalbornoz 340f4c
			set_build_script_done installed2 finished;
lalbornoz 340f4c
		fi;
lalbornoz 340f4c
	fi;
lalbornoz 340f4c
else
lalbornoz 340f4c
	if [ "x${3}" = "xstage1" ]; then
lalbornoz 340f4c
		# GCC, stage1.
lalbornoz 340f4c
		set_build_dir "cbb-gcc-${GCC_VERSION}" "${TARGET}";
lalbornoz 340f4c
		export	cbb_ldflags_for_target="--sysroot=${PREFIX_TARGET}"	\
lalbornoz 340f4c
			cbb_sysroot_for_libgcc="${PREFIX_TARGET}"		\
lalbornoz 340f4c
			cbb_target="${TARGET}"					\
lalbornoz 340f4c
			cbb_neutral_libiberty="no"				\
lalbornoz 340f4c
			cbb_xgcc_for_specs="${WORKDIR}/${_build_dir}/gcc/xgcc";
lalbornoz 340f4c
		GCCTARGET_FLAGS="-DIN_TARGET_LIBRARY_BUILD --sysroot=${PREFIX_TARGET}";
lalbornoz 340f4c
	elif [ "x${3}" = "xnative" ]; then
lalbornoz 340f4c
		# GCC, native.
lalbornoz 340f4c
		set_build_dir "cbb-gcc-${GCC_VERSION}" "native";
lalbornoz 340f4c
		export 	cbb_ldflags_for_target="--sysroot=${PREFIX_NATIVE}"	\
lalbornoz 340f4c
			cbb_sysroot_for_libgcc="${PREFIX_NATIVE}"		\
lalbornoz 340f4c
			cbb_target="${TARGET}"					\
lalbornoz 340f4c
			cbb_xgcc_for_specs="${TARGET}-gcc";
lalbornoz 340f4c
		GCCTARGET_FLAGS="-DIN_TARGET_LIBRARY_BUILD --sysroot=${PREFIX_NATIVE}";
lalbornoz 340f4c
	fi;
lalbornoz 340f4c
	GCCFLAGS="${CFLAGS:+${CFLAGS} }--include $(readlink -f ${WORKDIR}/cbb-gcc-${GCC_VERSION}/libc/cbb-musl-pe.h)";
lalbornoz 340f4c
	set_env_vars "${GCCFLAGS}" CFLAGS CFLAGS_FOR_BUILD CPPFLAGS_FOR_BUILD CXXFLAGS CXXFLAGS_FOR_BUILD;
lalbornoz 340f4c
	set_env_vars "${CFLAGS_FOR_BUILD}" cbb_cflags_for_stage1 cbb_cflags_for_stage2 cbb_cflags_for_stage3 cbb_cflags_for_stage4;
lalbornoz 340f4c
	set_env_vars "${GCCTARGET_FLAGS}" CFLAGS_FOR_TARGET CPPFLAGS_FOR_TARGET CXXFLAGS_FOR_TARGET LIBCFLAGS_FOR_TARGET XGCC_FLAGS_FOR_TARGET;
lalbornoz 340f4c
	export CFLAGS CXXFLAGS CFLAGS_FOR_BUILD CPPFLAGS_FOR_BUILD CXXFLAGS_FOR_BUILD CFLAGS_FOR_TARGET XGCC_FLAGS_FOR_TARGET CPPFLAGS_FOR_TARGET CXXFLAGS_FOR_TARGET LIBCFLAGS_FOR_TARGET;
lalbornoz 340f4c
	if ! is_build_script_done configured; then
lalbornoz 340f4c
		if [ "x${3}" = "xstage1" ]; then
lalbornoz 340f4c
			mkdir -p "${PREFIX_TARGET}/include";
lalbornoz 340f4c
			[ \! -d "${PREFIX_TARGET}/usr" ] &&		\
lalbornoz 340f4c
				ln -s . "${PREFIX_TARGET}/usr";
lalbornoz 340f4c
			_configure_args="--prefix=${PREFIX} --with-sysroot=${PREFIX_TARGET}";
lalbornoz 340f4c
		elif [ "x${3}" = "xnative" ]; then
lalbornoz 340f4c
			mkdir -p "${PREFIX_NATIVE}/${TARGET}";
lalbornoz 340f4c
			if [ \! -d "${PREFIX_NATIVE}/${TARGET}/usr" ]; then
lalbornoz 340f4c
				ln -s . "${PREFIX_NATIVE}/${TARGET}/usr";
lalbornoz 340f4c
			fi;
lalbornoz 340f4c
			_configure_args="			\
lalbornoz 340f4c
				--host=x86_64-nt64-midipix	\
lalbornoz 340f4c
				--prefix=/			\
lalbornoz 340f4c
				--with-elf=${PREFIX_NATIVE}	\
lalbornoz 340f4c
				--with-gmp=${PREFIX_NATIVE}	\
lalbornoz 340f4c
				--with-mpc=${PREFIX_NATIVE}	\
lalbornoz 340f4c
				--with-mpfr=${PREFIX_NATIVE}	\
lalbornoz 340f4c
				--with-sysroot=";
lalbornoz 340f4c
		fi;
lalbornoz 340f4c
		rm_if_exists -m -c "${_build_dir}";
lalbornoz 340f4c
		"../cbb-gcc-${GCC_VERSION}/configure"		\
lalbornoz 340f4c
			--disable-bootstrap			\
lalbornoz 340f4c
			--disable-libmudflap			\
lalbornoz 340f4c
			--disable-multilib			\
lalbornoz 340f4c
			--disable-nls				\
lalbornoz 340f4c
			--disable-obsolete			\
lalbornoz 340f4c
			--disable-sjlj-exceptions		\
lalbornoz 340f4c
			--disable-symvers			\
lalbornoz 340f4c
			--enable-canonical-system-headers	\
lalbornoz 340f4c
			--enable-__cxa_atexit			\
lalbornoz 340f4c
			--enable-debug				\
lalbornoz 340f4c
			--enable-gnu-indirect-function		\
lalbornoz 340f4c
			--enable-gnu-unique-object		\
lalbornoz 340f4c
			--enable-initfini-array			\
lalbornoz 340f4c
			--enable-languages=c,c++,objc,lto	\
lalbornoz 340f4c
			--enable-libstdcxx-debug		\
lalbornoz 340f4c
			--enable-lto				\
lalbornoz 340f4c
			--enable-multiarch			\
lalbornoz 340f4c
			--enable-secureplt			\
lalbornoz 340f4c
			--enable-shared				\
lalbornoz 340f4c
			--enable-threads=posix			\
lalbornoz 340f4c
			--target=${TARGET}			\
lalbornoz 340f4c
			--with-fpmath=sse			\
lalbornoz 340f4c
			${_configure_args};
lalbornoz 340f4c
		set_build_script_done configured -built;
lalbornoz 340f4c
	else
lalbornoz 340f4c
		cd "${_build_dir}";
lalbornoz 340f4c
	fi;
lalbornoz 340f4c
	if ! is_build_script_done built; then
lalbornoz 340f4c
		if [ "x${3}" = "xstage1" ]; then
lalbornoz 340f4c
			make ${MAKEFLAGS} all-gcc;
lalbornoz 340f4c
		elif [ "x${3}" = "xnative" ]; then
lalbornoz 340f4c
			make -j18 all-gcc;
lalbornoz 340f4c
			make -j18 all-target-libgcc;
lalbornoz 340f4c
			make -j18 all-target-libstdc++-v3;
lalbornoz 340f4c
			make -j18 all;
lalbornoz 340f4c
		fi;
lalbornoz 340f4c
		set_build_script_done built -installed;
lalbornoz 340f4c
	fi;
lalbornoz 340f4c
	if ! is_build_script_done installed; then
lalbornoz 340f4c
		if [ "x${3}" = "xstage1" ]; then
lalbornoz 340f4c
			make ${MAKEFLAGS} install-gcc;
lalbornoz 340f4c
		elif [ "x${3}" = "xnative" ]; then
lalbornoz 340f4c
			make -j18 DESTDIR="${PREFIX_NATIVE}" install;
lalbornoz 340f4c
		fi;
lalbornoz 340f4c
		set_build_script_done installed finished;
lalbornoz 340f4c
	fi;
lalbornoz 340f4c
fi;
lalbornoz 340f4c
lalbornoz 340f4c
# vim:filetype=sh