Index: python.eselect =================================================================== --- python.eselect (revision 189) +++ python.eselect (working copy) @@ -24,20 +24,54 @@ find_targets() { done } -set_python_script() { - local script="${INTERPRETER_PATH}${1}" target="${2}" - cat << EOF > "${script}" -#!/bin/bash -# Gentoo Python wrapper script +set_python() { + local program="${INTERPRETER_PATH}python" target="${1}" + cat << EOF > /tmp/python.c +#include +#include +#include +#include -[[ "\${EPYTHON}" =~ (/|^python\$) ]] && EPYTHON="${target}" -"\${0%/*}/\${EPYTHON:-${target}}" "\$@" +const char* name = "### Gentoo Python wrapper for ${target} program ###"; + +int main(int argc, char** argv) +{ + if (strlen(name) == 0) + { + abort(); + } + + char* EPYTHON = getenv("EPYTHON"); + if (! EPYTHON || (strcmp(EPYTHON, "python") == 0) || strchr(EPYTHON, '/')) + { + EPYTHON = "${target}"; + } + + char buf[PATH_MAX + 1]; + if (readlink("/proc/self/exe", buf, sizeof(buf) - 1) != -1) + { + char* last_path_sep = strrchr(buf, '/'); + if (last_path_sep) + { + *last_path_sep = 0; + } + char* absolute_python_path = strcat(strcat(buf, "/"), EPYTHON); + execv(absolute_python_path, argv); + } + else + { + execvp(EPYTHON, argv); + } + + return 1; +} EOF - chmod +x "${script}" + ${CC:-gcc} ${CFLAGS} ${LDFLAGS} /tmp/python.c -o "${program}" + rm -f /tmp/python.c } -set_python_config_script() { - local script="${INTERPRETER_PATH}${1}" target="${2}" +set_python_config() { + local script="${INTERPRETER_PATH}python-config" target="${1}" cat << EOF > "${script}" #!/bin/bash # Gentoo python-config wrapper script @@ -100,11 +134,11 @@ set_scripts_and_symlinks() { if [[ -f "${INTERPRETER_PATH}${target}" ]]; then remove_symlinks set_man_symlink "${target}" - + pushd "${INTERPRETER_PATH}" 1>/dev/null - set_python_script "python" "${target}" + set_python "${target}" ln -nfs "${target}" "${target%.*}" - set_python_config_script "python-config" "${target/python/python-config-}" + set_python_config "${target/python/python-config-}" ln -nfs "${target/python/pydoc}" pydoc ln -nfs "${target/python/idle}" idle # 2to3 for >=2.6 @@ -138,8 +172,9 @@ describe_show() { } do_show() { - active=$(canonicalise "${INTERPRETER_PATH}python") - echo ${active#${INTERPRETER_PATH}} + active=$(< "${INTERPRETER_PATH}python") + active=$(echo "${active}" | grep -Eo "### Gentoo Python wrapper for [^[:space:]]+ program ###" | sed -e "s/.*### Gentoo Python wrapper for \([^[:space:]]\+\) program ###.*/\1/") + echo "${active}" } ### list action ### @@ -178,6 +213,13 @@ do_set() { elif [[ -n "${2}" ]]; then die -q "Too many parameters" else + if [[ -z "${CFLAGS}" && -f /etc/make.conf ]]; then + CFLAGS="$(. /etc/make.conf; echo "${CFLAGS}")" + fi + if [[ -z "${LDFLAGS}" && -f /etc/make.conf ]]; then + LDFLAGS="$(. /etc/make.conf; echo "${LDFLAGS}")" + fi + if ! remove_symlinks; then die -q "Can't remove existing provider" elif ! set_scripts_and_symlinks "${1}"; then @@ -220,7 +262,7 @@ do_update() { fi local targets=( $(cd "${INTERPRETER_PATH}"; ls python?.?|sort -r) ) target - + # Ignore slots for slot in ${ignored_slots[@]}; do targets=( ${targets[@]/python${slot}/} )