File autogen.sh of Package failed_python-cangjie

#!/bin/sh
set -eu

# autogen.sh - generate the configure script and friends.
# This wrapper creates a small "cython" helper in the source directory
# that forces cython to be executed using python3.11 (if available).
# It also patches the generated configure script so that the build system
# will prefer this wrapper unless CYTHON is explicitly overridden.
#
# This fixes an issue on systems where the default "python3" is 3.12
# and distutils is not available, causing the system cython wrapper
# (which may use /usr/bin/env python3) to run under Python 3.12 and fail.

# Determine source directory (this script is expected at project root)
srcdir="$(cd "$(dirname "$0")" && pwd)"

# Create a small cython wrapper script in the source directory.
# It will run "python3.11 -m cython" if python3.11 is available,
# otherwise fall back to trying "python3 -m cython" or /usr/bin/env cython.
cat > "$srcdir/cython" <<'EOF'
#!/bin/sh
# cython wrapper: prefer python3.11 to avoid running cython under Python 3.12
if command -v python3.11 >/dev/null 2>&1 ; then
    exec python3.11 -m cython "$@"
fi

# If python3 reports being 3.11, use it
if command -v python3 >/dev/null 2>&1 ; then
    pyv="$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))' 2>/dev/null || true)"
    case "$pyv" in
        3.11|3.11.*)
            exec python3 -m cython "$@"
            ;;
    esac
fi

# Fallback: try to use cython from PATH
exec /usr/bin/env cython "$@"
EOF
chmod +x "$srcdir/cython"

# Run autotools to generate configure, Makefile.in, etc.
# tolerate missing programs where appropriate (some build environments
# already have generated artifacts), but try to run the usual commands.
# These commands mirror what many upstream autogen.sh scripts do.
if command -v libtoolize >/dev/null 2>&1; then
    libtoolize --automake --copy || true
fi

if command -v aclocal >/dev/null 2>&1; then
    aclocal -I m4 || true
fi

if command -v autoheader >/dev/null 2>&1; then
    autoheader || true
fi

if command -v automake >/dev/null 2>&1; then
    automake --add-missing --copy || true
fi

if command -v autoconf >/dev/null 2>&1; then
    autoconf || true
fi

# If configure was just generated, patch it so that the build will use
# the wrapper we just created unless CYTHON is explicitly set.
# We insert a line near the top that sets a default for CYTHON to point
# to the wrapper in the source directory.
if [ -f "$srcdir/configure" ]; then
    abs_srcdir="$srcdir"
    # Insert the CYTHON default right after the first line (the interpreter line).
    awk -v wrapper="$abs_srcdir/cython" 'NR==1{print; print "CYTHON=\"${CYTHON:-" wrapper "}\""; next} {print}' "$srcdir/configure" > "$srcdir/configure.tmp" && mv "$srcdir/configure.tmp" "$srcdir/configure"
    chmod +x "$srcdir/configure"
fi

echo "autogen.sh: created cython wrapper at $srcdir/cython and patched configure if present."
exit 0
openSUSE Build Service is sponsored by