#!/bin/sh -eE

if [ ! -d "$HPCX_DIR" ]; then

cat << "EOF"

Error: no hpcx environment loaded

Please load hpcx environment from module or shell script and rerun this script
Refer to README.txt file for more info

Example:

% module use $HPCX_DIR/modulefiles
% module load hpcx

-or-

% source $HPCX_DIR/hpcx_init.sh
% load_hpcx

EOF
exit 1

fi

if [ ! -w "$HPCX_DIR" ]; then
    echo "Error: $HPCX_DIR is not writable for user $USER, please fix and rerun"
    exit 1
fi

for la_file in $(find $HPCX_DIR/{mxm,fca,hcoll,ucx} -name "*.la" -print); do
    la_dir=$(dirname $la_file)
    sed -i -e "s,^libdir=.*,libdir='$la_dir',g" $la_file
done

for pc_file in $(find $HPCX_DIR/ -name "*.pc" -print); do
    sed -i -e "s,^hpcx_home .*,hpcx_home = $HPCX_DIR,g" $pc_file
done

exit 0
