#!/bin/bash set -e if [ "mpich" != "serial" ]; then update-alternatives \ --install /usr/bin/h5pcc h5pcc /usr/bin/h5pcc.mpich 10 \ --slave /usr/bin/h5pfc h5pfc /usr/bin/h5pfc.mpich \ --slave /usr/share/man/man1/h5pcc.1.gz h5pcc.1.gz /usr/share/man/man1/h5pcc.mpich.1.gz \ --slave /usr/share/man/man1/h5pfc.1.gz h5pfc.1.gz /usr/share/man/man1/h5pfc.mpich.1.gz fi update-alternatives \ --install /usr/lib/x86_64-linux-gnu/pkgconfig/hdf5.pc hdf5.pc /usr/lib/x86_64-linux-gnu/pkgconfig/hdf5_mpich.pc 10 \ --slave /usr/lib/x86_64-linux-gnu/pkgconfig/hdf5_hl.pc hdf5_hl.pc /usr/lib/x86_64-linux-gnu/pkgconfig/hdf5_mpich_hl.pc \ --slave /usr/lib/x86_64-linux-gnu/pkgconfig/hdf5_hl_fortran.pc hdf5_hl_fortran.pc /usr/lib/x86_64-linux-gnu/pkgconfig/hdf5_mpich_hl_fortran.pc \ --slave /usr/lib/x86_64-linux-gnu/pkgconfig/hdf5_fortran.pc hdf5_fortran.pc /usr/lib/x86_64-linux-gnu/pkgconfig/hdf5_mpich_fortran.pc \ --slave /usr/lib/x86_64-linux-gnu/pkgconfig/hdf5_cpp.pc hdf5_cpp.pc /usr/lib/x86_64-linux-gnu/pkgconfig/hdf5_mpich_cpp.pc \ --slave /usr/lib/x86_64-linux-gnu/pkgconfig/hdf5_hl_cpp.pc hdf5_hl_cpp.pc /usr/lib/x86_64-linux-gnu/pkgconfig/hdf5_mpich_hl_cpp.pc update-alternatives \ --install /usr/lib/x86_64-linux-gnu/cmake/hdf5 hdf5.cmake /usr/lib/x86_64-linux-gnu/cmake/hdf5_mpich 10 # Transitionning from hdf5-mpich.pc to hdf5_mpich.pc if update-alternatives --list hdf5.pc | grep -q '/hdf5-mpich\.pc'; then current_status=$(update-alternatives --query hdf5.pc | grep '^Status: ' | cut -d ' ' -f 2) current_value=$(update-alternatives --query hdf5.pc | grep '^Value: ' | cut -d ' ' -f 2) if [ "$current_status" != auto ] && [ "${current_value##*/}" = hdf5-mpich.pc ]; then update-alternatives --set hdf5.pc /usr/lib/x86_64-linux-gnu/pkgconfig/hdf5_mpich.pc fi update-alternatives --remove hdf5.pc /usr/lib/x86_64-linux-gnu/pkgconfig/hdf5-mpich.pc fi # We drop support for hdf5-mpi.pc as a slave of the 'mpi' alternatives # This is too complex and faulty # See #953021 and #968559 for references # # There is no way to simply add a new slave. We must parse the existing # mpi alternatives, then reinstall the whole related alternative plus the # wanted --slave part function read_alt_slaves () { # See #973261 local -n slaves=$1 set -- $(echo "$2" | sed -n '/Slaves:/{: while;n;s/^ //;T end;p;b while;: end;q}') while [ -n "$1" ]; do slaves["$1"]="$2" shift 2 done } if [ "mpich" != "serial" ]; then # Parse existing mpi alternatives mpi_alt=$(update-alternatives --query mpi) mpi_alt_sig=$(echo "$mpi_alt" | sed '/^$/q') mpi_alt_impl=$(echo "$mpi_alt" | sed -n -e '\!^Alternative: /usr/bin/mpicc.mpich!p' -e '0,\!^Alternative: /usr/bin/mpicc.mpich!d' -e '/^$/q' -e 'p') mpi_impl_priority=$(echo "$mpi_alt_impl" | sed -n '/^Priority: /{s/Priority: \(.*\)$/\1/;p}') declare -A slave_links slave_targets read_alt_slaves slave_links "$mpi_alt_sig" read_alt_slaves slave_targets "$mpi_alt_impl" # At this point: # * slave_links holds all the slaves name,link pairs # * slave_targets holds all the slaves name,target pairs for our mpi flavor # # If there is a 'hdf5-mpi.pc' key, the slave need to be removed if grep -E '(^| )hdf5-mpi\.pc( |$)' <<<"${!slave_targets[@]}"; then # Construct the slaves related part of the update-alternatives command current_slaves= for key in "${!slave_targets[@]}"; do # Do not keep the 'hdf5-mpi.pc' slave if [ "$key" = "hdf5-mpi.pc" ]; then continue fi current_slaves="$current_slaves --slave ${slave_links[$key]} $key ${slave_targets[$key]}" done # Re-install the whole alternative without our 'hdf5-*.pc' slave update-alternatives --install /usr/bin/mpicc mpi /usr/bin/mpicc.mpich "$mpi_impl_priority" $current_slaves fi # Drop the hdf5-mpi.pc choice from the hdf5.pc alternatives if present if update-alternatives --list hdf5.pc | grep '/hdf5-mpi.pc$'; then update-alternatives --remove hdf5.pc /usr/lib/x86_64-linux-gnu/pkgconfig/hdf5-mpi.pc fi fi exit 0