abinfo "Creating build directory ..."
mkdir -pv "$BLDDIR"

abinfo "Removing -fomit-frame-pointer from CFLAGS ..." 
export CFLAGS="${CFLAGS/-fomit-frame-pointer/}"

abinfo "Dropping -ffunction-sections, -fdata-sections, --gc-sections flags to fix build ..."
export CFLAGS="${CFLAGS/-ffunction-sections -fdata-sections/}"
export LDFLAGS="${LDFLAGS/-Wl,--gc-sections/}"

# FIXME: Steam can not launch games. Enable stack realignment[1] to ensure
# compatibility with a portion of 32-bit games, which generates function
# prologue and epilogue that realigns the stack at runtime[2]. This allows
# the legacy code with 4-byte aligned stack to run on "modern" codes which
# keeps 16-byte alignment.
# [1]: https://forums.gentoo.org/viewtopic-p-8685379.html?sid=8605a596c5bd932511f4f32755d932b2
# [2]: https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html#index-mstackrealign
export CFLAGS="${CFLAGS} -mstackrealign"
abinfo "Writing configure parameters ..."
echo "sbindir=/opt/32/bin" >> "$BLDDIR"/configparms
echo "rootsbindir=/opt/32/bin" >> "$BLDDIR"/configparms
echo "slibdir=/opt/32/lib" >> "$BLDDIR"/configparms
echo "rtlddir=/opt/32/lib" >> "$BLDDIR"/configparms
