Skip to content

Haiwang's spack env setup script

Haiwang Yu edited this page Aug 4, 2022 · 1 revision
list ()
{
    echo $1 | tr ':' '\n'
}

path-remove ()
{
    local IFS=':';
    local NEWPATH;
    local DIR;
    local PATHVARIABLE=${2:-PATH};
    for DIR in ${!PATHVARIABLE};
    do
        if [ "$DIR" != "$1" ]; then
            NEWPATH=${NEWPATH:+$NEWPATH:}$DIR;
        fi;
    done;
    export $PATHVARIABLE="$NEWPATH"
}

path-prepend ()
{
    path-remove "$1" "$2";
    local PATHVARIABLE="${2:-PATH}";
    export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}"
}

path-append ()
{
    path-remove "$1" "$2";
    local PATHVARIABLE="${2:-PATH}";
    export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1"
}

one ()
{
    package=$1
    path=$2
    inc_suffix=$3
    lib_suffix=$4
    upper=`echo $package | tr '[:lower:]' '[:upper:]'`
    echo $upper
    dir="${upper}_DIR"
    inc="${upper}_INC"
    lib="${upper}_LIB"
    export $dir=$path
    export $inc=$path/$inc_suffix
    export $lib=$path/$lib_suffix
    echo "$dir=${!dir}"
    echo "$inc=${!inc}"
    echo "$lib=${!lib}"
}

. /home/hyu/spack/share/spack/setup-env.sh
spack load [email protected]

packages=( "boost" "eigen" "jsoncpp" "jsonnet" "spdlog" "wirecell" )
inc_suffixes=( "include" "include/eigen3" "include" "include" "include" "include" )
lib_suffixes=( "lib" "lib" "lib" "lib" "lib" "lib" )
for i in "${!packages[@]}"
do
    package=${packages[$i]}
    inc_suffix=${inc_suffixes[$i]}
    lib_suffix=${lib_suffixes[$i]}
    path=`list $CMAKE_PREFIX_PATH | grep $package | head -1`
    if [[ "$package" == "wirecell" ]]; then
        path=`list $CMAKE_PREFIX_PATH | grep "wire-cell-toolkit" | head -1`
    elif [[ "$package" == "spdlog" ]]; then
        path=/home/hyu/opt/spdlog
    fi
    one $package $path $inc_suffix $lib_suffix
done

path-prepend /home/hyu/opt/bin/ PATH
export WIRECELL_PATH=/home/hyu/wire-cell-gen-kokkos/cfg:/home/hyu/wire-cell-toolkit/cfg:/home/hyu/wire-cell-data/
path-prepend /home/hyu/wire-cell-gen-kokkos/build/kokkos LD_LIBRARY_PATH
Clone this wiki locally