#!/bin/bash
set -e

if [ -f "${LFS}/sources/chapter6/cleanup" ]; then
	printf "%b" "  ${IGRN}Cleanup already performed${RST}\n"
else

	printf "%b" "${GRN}Cleaning up ${YLW}${LFS}${RST}... "

	{
	find "${LFS}"/usr/lib -name \*.la -delete
	find "${LFS}"/usr/libexec -name \*.la -delete

	rm -rfv "${LFS}"/usr/share/doc
	rm -rfv "${LFS}"/usr/share/info
	rm -rfv "${LFS}"/usr/share/man

	strip --strip-debug "${LFS}"/usr/lib/* || true
	strip --strip-unneeded "${LFS}"/usr/bin/* || true
	strip --strip-unneeded "${LFS}"/usr/sbin/* || true
	strip --strip-unneeded "${LFS}"/tools/bin/* || true

} >"${LFS}"/sources/log/chapter6/cleanup.log 2>&1

	success "OK"
	touch "${LFS}"/sources/chapter6/cleanup
fi