# -*-eselect-*- vim: ft=eselect # Copyright 1999-2018 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 inherit config multilib DESCRIPTION="Manage the system default wxWidgets profile" MAINTAINER="wxwidgets@gentoo.org" VERSION="20180529" WXCONFFILE="${EROOT}"/var/lib/wxwidgets/current get_confdir() { echo "${EROOT}/usr/$(get_libdir)/wx/config" } find_targets() { local conf for conf in ${WXCONFDIR}/*; do [[ -e ${conf} ]] && basename ${conf} done } set_config() { local target="${1}" targets if is_number "${target}"; then targets=( $(find_targets) ) [[ ${1} -ge 1 && ${1} -le ${#targets[@]} ]] \ || die -q "Number out of range: ${1}" target=${targets[$(( ${target} - 1 ))]} fi # we shouldn't change the profile to "none" if there are available configs # this can happen if WXCONFFILE got deleted somehow if [[ ${target} == "none" ]]; then targets=( $(find_targets) ) [[ ${#targets[@]} -ge 1 ]] && target=${targets[0]} fi if [[ ! ${target} == "none" && ! -e ${WXCONFDIR}/${target} ]]; then die -q "\"${1}\" doesn't appear to be a valid profile name" fi echo echo "Setting wxWidgets profile to ${target}" echo store_config ${WXCONFFILE} WXCONFIG ${target} if [[ ! ${target} == "none" ]]; then # expose the slot number of the selected target for various uses local wxslot=${target##*-} fi # symlink bakefile presets to current slot (Bug #209150) local f pushd "${EROOT}"/usr/share/bakefile/presets/ &> /dev/null for f in .bkl _presets.py _unix.bkl _win32.bkl _xrc.bkl; do if [[ -e wx${f} || -L wx${f} ]]; then rm -f wx${f} || die -q "Error removing wx${f}" fi if [[ ! ${target} == "none" ]]; then if [[ -e wx${wxslot/./}${f} ]]; then ln -sf wx${wxslot/./}${f} wx${f} \ || die -q "Error symlinking wx${wxslot/./}${f}" fi fi done popd &> /dev/null } ### show action ### describe_show() { echo "Show the currently selected profile" } do_show() { [[ ${#@} -gt 0 ]] && die -q "Too many parameters" write_list_start "Current wxWidgets profile:" if [[ -e ${WXCONFFILE} ]]; then write_kv_list_entry "$(load_config ${WXCONFFILE} WXCONFIG)" "" else write_kv_list_entry "(none)" "" fi } ### list action ### describe_list() { echo "List available profiles" } do_list() { local WXCONFDIR=$(get_confdir) local i targets currconf targets=( $(find_targets) ) [[ -e ${WXCONFFILE} ]] && currconf=$(load_config ${WXCONFFILE} WXCONFIG) for (( i = 0; i < ${#targets[@]}; i++ )); do # highlight current version [[ ${targets[i]} = ${currconf} ]] \ && targets[i]=$(highlight_marker "${targets[i]}") done write_list_start "Available wxWidgets profiles:" write_numbered_list -m "(none found)" "${targets[@]}" } ### set action ### describe_set() { echo "Set the system wxWidgets profile" } describe_set_options() { echo " : Profile name or number (from 'list')" } describe_set_parameters() { echo "" } do_set() { [[ ! ${#@} -eq 1 ]] \ && die -q "You must specify a profile name or number" [[ ! -w "${EROOT}"/var/lib/ ]] \ && die -q "You need write permission to /var/lib to perform this action." local WXCONFDIR=$(get_confdir) set_config "${1}" } describe_update() { echo "Check current profile and update it if invalid (internal use only)" } do_update() { [[ ! -e ${WXCONFFILE} ]] && do_set none local WXCONFDIR=$(get_confdir) currconf=$(load_config ${WXCONFFILE} WXCONFIG) # if current config is valid leave it alone [[ -e ${WXCONFDIR}/${currconf} ]] && return 0 # split the current config into components OIFS=${IFS} IFS=- set -- ${currconf} IFS=${OIFS} declare -a wxtoolkit wxchar wxdebug wxver # put them into the first element of the arrays wxtoolkit=(${1}) wxchar=(${2}) if [[ $# -eq 3 ]]; then # >=2.9 doesn't have a debug component, so fake it wxdebug=(release) wxver=(${3}) else wxdebug=(${3}) wxver=(${4}) fi # now put all possible components into the next elements local component toolkit char debug ver i opt for component in toolkit char debug ver; do i=1 case ${component} in toolkit) for opt in base gtk2 mac; do if [[ ${opt} == ${wxtoolkit[0]} ]]; then continue else wxtoolkit[${i}]=${opt} (( i++ )) fi done ;; char) for opt in ansi unicode; do if [[ ${opt} == ${wxchar[0]} ]]; then continue else wxchar[${i}]=${opt} (( i++ )) fi done ;; debug) for opt in release debug; do if [[ ${opt} == ${wxdebug[0]} ]]; then continue else wxdebug[${i}]=${opt} (( i++ )) fi done ;; ver) for opt in 3.0 2.9 2.8; do if [[ ${opt} == ${wxver[0]} ]]; then continue else wxver[${i}]=${opt} (( i++ )) fi done ;; esac done # Now we iterate through all the installed configs and find the closest match # ( debug -> char -> toolkit -> ver ) # meaning w/ a current config of gtk2-unicode-debug-2.8, it will pick # gtk2-unicode-release-2.8 before # base-unicode-debug-2.8 before # gtk2-unicode-2.9 local d c t v checkconf foundconf for (( v = 0 ; v < ${#wxver[@]} ; v++ )); do for (( t = 0 ; t < ${#wxtoolkit[@]} ; t++ )); do for (( c = 0 ; c < ${#wxchar[@]} ; c++ )); do for (( d = 0 ; d < ${#wxdebug[@]} ; d++ )); do if [[ ${wxver[$v]} != 2.8 ]]; then # >=2.9 doesn't have a debug component checkconf="${wxtoolkit[$t]}-${wxchar[$c]}-${wxver[$v]}" else checkconf="${wxtoolkit[$t]}-${wxchar[$c]}-${wxdebug[$d]}-${wxver[$v]}" fi [[ -e ${WXCONFDIR}/${checkconf} ]] || continue foundconf=${checkconf} break 4 done done done done # nothing installed [[ -z ${foundconf} ]] && foundconf="none" if [[ ${currconf} != "none" && ${foundconf} != "none" ]]; then echo write_warning_msg "Your currently selected wxWidgets profile: ( ${currconf} )" write_warning_msg "is no longer available." write_warning_msg write_warning_msg "The closest matching profile: ( ${foundconf} )" write_warning_msg "will be activated in its place." fi do_set ${foundconf} }