sed -i "/progname =/s/python/python${_pybasever}/" Python/pythonrun.c

sed -i "/SQLITE_OMIT_LOAD_EXTENSION/d" setup.py

sed -i -e "s|^#.* /usr/local/bin/python|#!/usr/bin/python2|" Lib/cgi.py

sed -i "s/python2.3/python2/g" Lib/distutils/tests/test_build_scripts.py \
    Lib/distutils/tests/test_install_scripts.py
 
rm -r Modules/expat
rm -r Modules/zlib

for SUBDIR in darwin libffi libffi_arm_wince libffi_msvc libffi_osx ; do
  rm -r Modules/_ctypes/$SUBDIR || exit 1 ;
done

find . -name '*.py' | \
    xargs sed -i "s|#[ ]*![ ]*/usr/bin/env python$|#!/usr/bin/env python2|"

touch Include/Python-ast.h Python/Python-ast.c

if [[ "${CROSS:-$ARCH}" = "ppc64el" ]]; then
    abinfo "Disabling x86 intrinsics to fix build on ppc64el ..."
    export CPPFLAGS="${CPPFLAGS/-DNO_WARN_X86_INTRINSICS/}"
fi

# FIXME: build failure with modern compilers (e.g., GCC 15+) that use C23 by default.
# The C23 standard introduces 'bool', 'true', and 'false' as reserved keywords.
# This conflicts with Python 2.7's legacy definition in 'Include/asdl.h':
# "typedef enum {false, true} bool;"
# Forced the compiler to use an older C standard (GNU99) to resolve this.
# 
# Error log:
# Include/asdl.h:9:15: error: cannot use keyword ‘false’ as enumeration constant
#    9 | typedef enum {false, true} bool;
#      |               ^~~~
# Include/asdl.h:9:15: note: ‘false’ is a keyword with ‘-std=c23’ onwards
export CFLAGS="$CFLAGS -std=gnu99"
