From 5d47f0600294b95799a15cfef0476fff81812efa Mon Sep 17 00:00:00 2001 From: SY Wang Date: Thu, 22 Oct 2026 19:02:33 +0800 Subject: [PATCH 1/4] Precommit: Prettify toolchain scripts --- .pre-commit-config.yaml | 5 + toolchain/build_abacus_aocc-aocl.sh | 81 +- toolchain/build_abacus_gcc-aocl.sh | 81 +- toolchain/build_abacus_gcc-mkl.sh | 79 +- toolchain/build_abacus_gnu.sh | 81 +- toolchain/build_abacus_intel.sh | 81 +- toolchain/build_abacus_windows.sh | 94 +- toolchain/install_abacus_toolchain_new.sh | 334 +-- toolchain/pre_set.sh | 2 +- toolchain/scripts/common_vars.sh | 26 +- toolchain/scripts/lib/config_manager.sh | 2268 ++++++++--------- toolchain/scripts/lib/config_validator.sh | 860 +++---- toolchain/scripts/lib/error_handler.sh | 186 +- toolchain/scripts/lib/package_manager.sh | 691 +++-- toolchain/scripts/lib/user_interface.sh | 1730 ++++++------- toolchain/scripts/lib/version_helper.sh | 440 ++-- toolchain/scripts/lib/version_loader.sh | 102 +- toolchain/scripts/package_versions.sh | 270 +- toolchain/scripts/stage0/install_amd.sh | 112 +- toolchain/scripts/stage0/install_cmake.sh | 156 +- toolchain/scripts/stage0/install_gcc.sh | 344 +-- toolchain/scripts/stage0/install_intel.sh | 120 +- toolchain/scripts/stage1/install_intelmpi.sh | 188 +- toolchain/scripts/stage1/install_mpich.sh | 224 +- toolchain/scripts/stage1/install_openmpi.sh | 292 +-- toolchain/scripts/stage2/install_aocl.sh | 72 +- toolchain/scripts/stage2/install_mathlibs.sh | 36 +- toolchain/scripts/stage2/install_mkl.sh | 180 +- toolchain/scripts/stage2/install_openblas.sh | 232 +- toolchain/scripts/stage3/install_elpa.sh | 406 +-- toolchain/scripts/stage3/install_fftw.sh | 186 +- toolchain/scripts/stage3/install_libxc.sh | 142 +- toolchain/scripts/stage3/install_scalapack.sh | 146 +- toolchain/scripts/stage4/install_cereal.sh | 166 +- toolchain/scripts/stage4/install_dftd4.sh | 124 +- toolchain/scripts/stage4/install_json.sh | 74 +- toolchain/scripts/stage4/install_libcomm.sh | 142 +- toolchain/scripts/stage4/install_libnpy.sh | 126 +- toolchain/scripts/stage4/install_libri.sh | 142 +- toolchain/scripts/stage4/install_libtorch.sh | 146 +- toolchain/scripts/stage4/install_nep.sh | 98 +- toolchain/scripts/tool_kit.sh | 276 +- .../tests/test_installer_argument_failures.sh | 2 +- toolchain/toolchain_aocc-aocl.sh | 22 +- toolchain/toolchain_gcc-aocl.sh | 20 +- toolchain/toolchain_gcc-mkl.sh | 20 +- toolchain/toolchain_gnu.sh | 22 +- toolchain/toolchain_intel.sh | 41 +- toolchain/toolchain_windows.sh | 24 +- 49 files changed, 5846 insertions(+), 5846 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b94491ca55f..bcf107e8d1a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -15,6 +15,11 @@ repos: hooks: - id: cmake-format additional_dependencies: [pyyaml] + - repo: https://github.com/scop/pre-commit-shfmt + rev: v3.14.1-1 + hooks: + - id: shfmt + args: [--write, --language-dialect=bash, --indent=2] - repo: local hooks: - id: abacus-agent-governance diff --git a/toolchain/build_abacus_aocc-aocl.sh b/toolchain/build_abacus_aocc-aocl.sh index 08bfab5fe43..da6f2fff5e7 100755 --- a/toolchain/build_abacus_aocc-aocl.sh +++ b/toolchain/build_abacus_aocc-aocl.sh @@ -28,7 +28,7 @@ SCALAPACK=$AOCLhome/lib FFTW3=$AOCLhome LIBRI=${LIBRI_ROOT} LIBCOMM=${LIBCOMM_ROOT} -USE_CUDA=OFF # set ON to enable gpu-abacus +USE_CUDA=OFF # set ON to enable gpu-abacus # NEP_DIR=$INSTALL_DIR/NEP_CPU-main # LIBTORCH=$INSTALL_DIR/libtorch-2.1.2/share/cmake/Torch # LIBNPY=$INSTALL_DIR/libnpy-1.0.1/include @@ -37,64 +37,61 @@ USE_CUDA=OFF # set ON to enable gpu-abacus NUM_JOBS="$(nproc)" while [[ $# -gt 0 ]]; do case $1 in - -j) - if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then - NUM_JOBS="${2}" - shift 2 - else - echo "ERROR: -j requires a number argument" - exit 1 - fi - ;; - -j[0-9]*) - NUM_JOBS="${1#-j}" - shift - ;; - *) - echo "ERROR: Unsupported argument: $1" >&2 - echo "Usage: $0 [-j N|-jN]" >&2 + -j) + if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then + NUM_JOBS="${2}" + shift 2 + else + echo "ERROR: -j requires a number argument" exit 1 - ;; + fi + ;; + -j[0-9]*) + NUM_JOBS="${1#-j}" + shift + ;; + *) + echo "ERROR: Unsupported argument: $1" >&2 + echo "Usage: $0 [-j N|-jN]" >&2 + exit 1 + ;; esac done # if clang++ have problem, switch back to g++ cmake -B $BUILD_DIR -DCMAKE_INSTALL_PREFIX=$PREFIX \ - -DCMAKE_CXX_COMPILER=clang++ \ - -DMPI_CXX_COMPILER=mpicxx \ - -DLAPACK_DIR=$LAPACK \ - -DSCALAPACK_DIR=$SCALAPACK \ - -DFFTW3_DIR=$FFTW3 \ - -DCEREAL_INCLUDE_DIR=$CEREAL \ - -DENABLE_LCAO=ON \ - -DENABLE_LIBXC=ON \ - -DENABLE_OPENMP=ON \ - -DENABLE_ELPA=ON \ - -DENABLE_JSON=ON \ - -DENABLE_LIBRI=ON \ - -DLIBRI_DIR=$LIBRI \ - -DLIBCOMM_DIR=$LIBCOMM \ - -DUSE_CUDA=$USE_CUDA \ -# -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc \ -# -DNEP_DIR=$NEP_DIR \ -# -DENABLE_MLALGO=1 \ -# -DTorch_DIR=$LIBTORCH \ -# -Dlibnpy_INCLUDE_DIR=$LIBNPY \ -# -DDeePMD_DIR=$DEEPMD \ -# -DENABLE_CUSOLVERMP=ON \ + -DCMAKE_CXX_COMPILER=clang++ \ + -DMPI_CXX_COMPILER=mpicxx \ + -DLAPACK_DIR=$LAPACK \ + -DSCALAPACK_DIR=$SCALAPACK \ + -DFFTW3_DIR=$FFTW3 \ + -DCEREAL_INCLUDE_DIR=$CEREAL \ + -DENABLE_LCAO=ON \ + -DENABLE_LIBXC=ON \ + -DENABLE_OPENMP=ON \ + -DENABLE_ELPA=ON \ + -DENABLE_JSON=ON \ + -DENABLE_LIBRI=ON \ + -DLIBRI_DIR=$LIBRI \ + -DLIBCOMM_DIR=$LIBCOMM \ + -DUSE_CUDA=$USE_CUDA# -DTorch_DIR=$LIBTORCH# -DENABLE_MLALGO=1 # -DNEP_DIR=$NEP_DIR \ +# -DDeePMD_DIR=$DEEPMD \ +# -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc \ +# -Dlibnpy_INCLUDE_DIR=$LIBNPY \ +# -DENABLE_CUSOLVERMP=ON \ cmake --build $BUILD_DIR --target install -j "${NUM_JOBS}" # generate abacus_env.sh -cat << EOF > "${TOOL}/abacus_env.sh" +cat <"${TOOL}/abacus_env.sh" #!/bin/bash source $INSTALL_DIR/setup export PATH="${PREFIX}/bin":\${PATH} EOF # generate information -cat << EOF +cat <&2 - echo "Usage: $0 [-j N|-jN]" >&2 + -j) + if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then + NUM_JOBS="${2}" + shift 2 + else + echo "ERROR: -j requires a number argument" exit 1 - ;; + fi + ;; + -j[0-9]*) + NUM_JOBS="${1#-j}" + shift + ;; + *) + echo "ERROR: Unsupported argument: $1" >&2 + echo "Usage: $0 [-j N|-jN]" >&2 + exit 1 + ;; esac done cmake -B $BUILD_DIR -DCMAKE_INSTALL_PREFIX=$PREFIX \ - -DCMAKE_CXX_COMPILER=g++ \ - -DMPI_CXX_COMPILER=mpicxx \ - -DLAPACK_DIR=$LAPACK \ - -DSCALAPACK_DIR=$SCALAPACK \ - -DFFTW3_DIR=$FFTW3 \ - -DENABLE_LCAO=ON \ - -DENABLE_LIBXC=ON \ - -DENABLE_OPENMP=ON \ - -DENABLE_ELPA=ON \ - -DENABLE_JSON=ON \ - -DENABLE_LIBRI=ON \ - -DLIBRI_DIR=$LIBRI \ - -DLIBCOMM_DIR=$LIBCOMM \ - -DUSE_CUDA=$USE_CUDA \ -# -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc \ -# -DNEP_DIR=$NEP_DIR \ -# -DENABLE_MLALGO=1 \ -# -DTorch_DIR=$LIBTORCH \ -# -Dlibnpy_INCLUDE_DIR=$LIBNPY \ -# -DDeePMD_DIR=$DEEPMD \ -# -DENABLE_CUSOLVERMP=ON \ + -DCMAKE_CXX_COMPILER=g++ \ + -DMPI_CXX_COMPILER=mpicxx \ + -DLAPACK_DIR=$LAPACK \ + -DSCALAPACK_DIR=$SCALAPACK \ + -DFFTW3_DIR=$FFTW3 \ + -DENABLE_LCAO=ON \ + -DENABLE_LIBXC=ON \ + -DENABLE_OPENMP=ON \ + -DENABLE_ELPA=ON \ + -DENABLE_JSON=ON \ + -DENABLE_LIBRI=ON \ + -DLIBRI_DIR=$LIBRI \ + -DLIBCOMM_DIR=$LIBCOMM \ + -DUSE_CUDA=$USE_CUDA# -DTorch_DIR=$LIBTORCH# -DENABLE_MLALGO=1 # -DNEP_DIR=$NEP_DIR \ +# -DDeePMD_DIR=$DEEPMD \ +# -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc \ +# -Dlibnpy_INCLUDE_DIR=$LIBNPY \ +# -DENABLE_CUSOLVERMP=ON \ cmake --build $BUILD_DIR --target install -j "${NUM_JOBS}" # generate abacus_env.sh -cat << EOF > "${TOOL}/abacus_env.sh" +cat <"${TOOL}/abacus_env.sh" #!/bin/bash source $INSTALL_DIR/setup export PATH="${PREFIX}/bin":\${PATH} EOF # generate information -cat << EOF +cat <&2 - echo "Usage: $0 [-j N|-jN]" >&2 + -j) + if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then + NUM_JOBS="${2}" + shift 2 + else + echo "ERROR: -j requires a number argument" exit 1 - ;; + fi + ;; + -j[0-9]*) + NUM_JOBS="${1#-j}" + shift + ;; + *) + echo "ERROR: Unsupported argument: $1" >&2 + echo "Usage: $0 [-j N|-jN]" >&2 + exit 1 + ;; esac done cmake -B $BUILD_DIR -DCMAKE_INSTALL_PREFIX=$PREFIX \ - -DCMAKE_CXX_COMPILER=g++ \ - -DMPI_CXX_COMPILER=mpicxx \ - -DMKLROOT=$MKLROOT \ - -DENABLE_FLOAT_FFTW=ON \ - -DENABLE_LCAO=ON \ - -DENABLE_LIBXC=ON \ - -DENABLE_OPENMP=ON \ - -DENABLE_ELPA=ON \ - -DENABLE_DFTD4=ON \ - -DENABLE_JSON=ON \ - -DENABLE_LIBRI=ON \ - -DLIBRI_DIR=$LIBRI \ - -DLIBCOMM_DIR=$LIBCOMM \ - -DUSE_CUDA=$USE_CUDA \ -# -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc \ -# -DNEP_DIR=$NEP_DIR \ -# -DENABLE_MLALGO=1 \ -# -DTorch_DIR=$LIBTORCH \ -# -Dlibnpy_INCLUDE_DIR=$LIBNPY \ -# -DDeePMD_DIR=$DEEPMD \ -# -DENABLE_CUSOLVERMP=ON \ + -DCMAKE_CXX_COMPILER=g++ \ + -DMPI_CXX_COMPILER=mpicxx \ + -DMKLROOT=$MKLROOT \ + -DENABLE_FLOAT_FFTW=ON \ + -DENABLE_LCAO=ON \ + -DENABLE_LIBXC=ON \ + -DENABLE_OPENMP=ON \ + -DENABLE_ELPA=ON \ + -DENABLE_DFTD4=ON \ + -DENABLE_JSON=ON \ + -DENABLE_LIBRI=ON \ + -DLIBRI_DIR=$LIBRI \ + -DLIBCOMM_DIR=$LIBCOMM \ + -DUSE_CUDA=$USE_CUDA# -DTorch_DIR=$LIBTORCH# -DENABLE_MLALGO=1 # -DNEP_DIR=$NEP_DIR \ +# -DDeePMD_DIR=$DEEPMD \ +# -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc \ +# -Dlibnpy_INCLUDE_DIR=$LIBNPY \ +# -DENABLE_CUSOLVERMP=ON \ cmake --build $BUILD_DIR --target install -j "${NUM_JOBS}" # generate abacus_env.sh -cat << EOF > "${TOOL}/abacus_env.sh" +cat <"${TOOL}/abacus_env.sh" #!/bin/bash source $INSTALL_DIR/setup export PATH="${PREFIX}/bin":\${PATH} EOF # generate information -cat << EOF +cat <&2 - echo "Usage: $0 [-j N|-jN]" >&2 + -j) + if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then + NUM_JOBS="${2}" + shift 2 + else + echo "ERROR: -j requires a number argument" exit 1 - ;; + fi + ;; + -j[0-9]*) + NUM_JOBS="${1#-j}" + shift + ;; + *) + echo "ERROR: Unsupported argument: $1" >&2 + echo "Usage: $0 [-j N|-jN]" >&2 + exit 1 + ;; esac done cmake -B $BUILD_DIR -DCMAKE_INSTALL_PREFIX=$PREFIX \ - -DCMAKE_CXX_COMPILER=g++ \ - -DMPI_CXX_COMPILER=mpicxx \ - -DLAPACK_DIR=$LAPACK \ - -DSCALAPACK_DIR=$SCALAPACK \ - -DFFTW3_DIR=$FFTW3 \ - -DENABLE_LCAO=ON \ - -DENABLE_LIBXC=ON \ - -DENABLE_OPENMP=ON \ - -DENABLE_ELPA=ON \ - -DENABLE_DFTD4=ON \ - -DENABLE_JSON=ON \ - -DENABLE_LIBRI=ON \ - -DLIBRI_DIR=$LIBRI \ - -DLIBCOMM_DIR=$LIBCOMM \ - -DUSE_CUDA=$USE_CUDA \ -# -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc \ -# -DNEP_DIR=$NEP_DIR \ -# -DENABLE_MLALGO=1 \ -# -DTorch_DIR=$LIBTORCH \ -# -Dlibnpy_INCLUDE_DIR=$LIBNPY \ -# -DDeePMD_DIR=$DEEPMD \ -# -DENABLE_CUSOLVERMP=ON \ + -DCMAKE_CXX_COMPILER=g++ \ + -DMPI_CXX_COMPILER=mpicxx \ + -DLAPACK_DIR=$LAPACK \ + -DSCALAPACK_DIR=$SCALAPACK \ + -DFFTW3_DIR=$FFTW3 \ + -DENABLE_LCAO=ON \ + -DENABLE_LIBXC=ON \ + -DENABLE_OPENMP=ON \ + -DENABLE_ELPA=ON \ + -DENABLE_DFTD4=ON \ + -DENABLE_JSON=ON \ + -DENABLE_LIBRI=ON \ + -DLIBRI_DIR=$LIBRI \ + -DLIBCOMM_DIR=$LIBCOMM \ + -DUSE_CUDA=$USE_CUDA# -DTorch_DIR=$LIBTORCH# -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc # -DNEP_DIR=$NEP_DIR \ +# -DDeePMD_DIR=$DEEPMD \ +# -DENABLE_MLALGO=1 \ +# -Dlibnpy_INCLUDE_DIR=$LIBNPY \ +# -DENABLE_CUSOLVERMP=ON \ cmake --build $BUILD_DIR --target install -j "${NUM_JOBS}" # generate abacus_env.sh -cat << EOF > "${TOOL}/abacus_env.sh" +cat <"${TOOL}/abacus_env.sh" #!/bin/bash source $INSTALL_DIR/setup export PATH="${PREFIX}/bin":\${PATH} EOF # generate information -cat << EOF +cat <&2 - echo "Usage: $0 [-j N|-jN]" >&2 + -j) + if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then + NUM_JOBS="${2}" + shift 2 + else + echo "ERROR: -j requires a number argument" exit 1 - ;; + fi + ;; + -j[0-9]*) + NUM_JOBS="${1#-j}" + shift + ;; + *) + echo "ERROR: Unsupported argument: $1" >&2 + echo "Usage: $0 [-j N|-jN]" >&2 + exit 1 + ;; esac done -# Notice: if you are compiling with AMD-CPU or GPU-version ABACUS, then `icpc` and `mpiicpc` compilers are needed +# Notice: if you are compiling with AMD-CPU or GPU-version ABACUS, then `icpc` and `mpiicpc` compilers are needed cmake -B $BUILD_DIR -DCMAKE_INSTALL_PREFIX=$PREFIX \ - -DCMAKE_CXX_COMPILER=icpx \ - -DMPI_CXX_COMPILER=mpiicpx \ - -DMKLROOT=$MKLROOT \ - -DENABLE_FLOAT_FFTW=ON \ - -DENABLE_LCAO=ON \ - -DENABLE_LIBXC=ON \ - -DENABLE_OPENMP=ON \ - -DENABLE_ELPA=ON \ - -DENABLE_DFTD4=ON \ - -DENABLE_JSON=ON \ - -DENABLE_LIBRI=ON \ - -DLIBRI_DIR=$LIBRI \ - -DLIBCOMM_DIR=$LIBCOMM \ - -DUSE_CUDA=$USE_CUDA \ -# -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc \ -# -DNEP_DIR=$NEP_DIR \ -# -DENABLE_MLALGO=1 \ -# -DTorch_DIR=$LIBTORCH \ -# -Dlibnpy_INCLUDE_DIR=$LIBNPY \ -# -DDeePMD_DIR=$DEEPMD \ -# -DENABLE_CUSOLVERMP=ON \ + -DCMAKE_CXX_COMPILER=icpx \ + -DMPI_CXX_COMPILER=mpiicpx \ + -DMKLROOT=$MKLROOT \ + -DENABLE_FLOAT_FFTW=ON \ + -DENABLE_LCAO=ON \ + -DENABLE_LIBXC=ON \ + -DENABLE_OPENMP=ON \ + -DENABLE_ELPA=ON \ + -DENABLE_DFTD4=ON \ + -DENABLE_JSON=ON \ + -DENABLE_LIBRI=ON \ + -DLIBRI_DIR=$LIBRI \ + -DLIBCOMM_DIR=$LIBCOMM \ + -DUSE_CUDA=$USE_CUDA# -DTorch_DIR=$LIBTORCH# -DENABLE_MLALGO=1 # -DNEP_DIR=$NEP_DIR \ +# -DDeePMD_DIR=$DEEPMD \ +# -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc \ +# -Dlibnpy_INCLUDE_DIR=$LIBNPY \ +# -DENABLE_CUSOLVERMP=ON \ cmake --build $BUILD_DIR --target install -j "${NUM_JOBS}" # generate abacus_env.sh -cat << EOF > "${TOOL}/abacus_env.sh" +cat <"${TOOL}/abacus_env.sh" #!/bin/bash source $INSTALL_DIR/setup export PATH="${PREFIX}/bin":\${PATH} EOF # generate information -cat << EOF +cat <&2; echo "Usage: $0 [-j N|-jN]" >&2; exit 1 ;; + -j) + if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then + NUM_JOBS="${2}" + shift 2 + else + echo "ERROR: -j requires a number argument" + exit 1 + fi + ;; + -j[0-9]*) + NUM_JOBS="${1#-j}" + shift + ;; + *) + echo "ERROR: Unsupported argument: $1" >&2 + echo "Usage: $0 [-j N|-jN]" >&2 + exit 1 + ;; esac done echo "Building with -j ${NUM_JOBS} (override with -j N; lower it if cc1plus runs out of memory)." @@ -60,7 +74,7 @@ echo "Building with -j ${NUM_JOBS} (override with -j N; lower it if cc1plus runs MPI_ARGS=() if [ "$ENABLE_MPI" = "ON" ]; then MPI_ARGS=(-DMPI_CXX_INCLUDE_PATH=$MINGW_PREFIX/include - -DMPI_CXX_LIBRARIES=$MINGW_PREFIX/lib/libmsmpi.dll.a) + -DMPI_CXX_LIBRARIES=$MINGW_PREFIX/lib/libmsmpi.dll.a) fi # Notes on the non-default options: @@ -74,26 +88,26 @@ fi # dropped transitive standard headers; force-include the common ones so the # existing sources build unchanged. (Not Windows-specific; tied to GCC>=15.) cmake -B $BUILD_DIR -G Ninja -DCMAKE_INSTALL_PREFIX=$PREFIX \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_C_COMPILER=gcc \ - -DCMAKE_CXX_COMPILER=g++ \ - -DENABLE_MPI=$ENABLE_MPI \ - -DENABLE_LCAO=$ENABLE_LCAO \ - -DENABLE_OPENMP=ON \ - -DENABLE_ELPA=ON \ - -DENABLE_PEXSI=OFF \ - -DENABLE_LIBRI=OFF \ - -DENABLE_MLALGO=OFF \ - -DUSE_CUDA=OFF \ - -DBUILD_TESTING=OFF \ - -DCOMMIT_INFO=OFF \ - -DBLA_VENDOR=OpenBLAS \ - -DENABLE_FLOAT_FFTW=ON \ - -DLAPACK_DIR=$LAPACK \ - -DFFTW3_DIR=$FFTW3 \ - -DCMAKE_PREFIX_PATH=$MINGW_PREFIX \ - "${MPI_ARGS[@]}" \ - -DCMAKE_CXX_FLAGS="-include cstdint -include cstring -include algorithm" + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_C_COMPILER=gcc \ + -DCMAKE_CXX_COMPILER=g++ \ + -DENABLE_MPI=$ENABLE_MPI \ + -DENABLE_LCAO=$ENABLE_LCAO \ + -DENABLE_OPENMP=ON \ + -DENABLE_ELPA=ON \ + -DENABLE_PEXSI=OFF \ + -DENABLE_LIBRI=OFF \ + -DENABLE_MLALGO=OFF \ + -DUSE_CUDA=OFF \ + -DBUILD_TESTING=OFF \ + -DCOMMIT_INFO=OFF \ + -DBLA_VENDOR=OpenBLAS \ + -DENABLE_FLOAT_FFTW=ON \ + -DLAPACK_DIR=$LAPACK \ + -DFFTW3_DIR=$FFTW3 \ + -DCMAKE_PREFIX_PATH=$MINGW_PREFIX \ + "${MPI_ARGS[@]}" \ + -DCMAKE_CXX_FLAGS="-include cstdint -include cstring -include algorithm" cmake --build $BUILD_DIR -j "${NUM_JOBS}" @@ -105,10 +119,10 @@ cmake --build $BUILD_DIR -j "${NUM_JOBS}" # but not the abacus.exe copy itself (no underscore). built_exe=$(ls "${ABACUS_DIR}/${BUILD_DIR}"/abacus_*.exe 2>/dev/null | head -n 1) if [ -n "$built_exe" ]; then - cp -f "$built_exe" "${ABACUS_DIR}/${BUILD_DIR}/abacus.exe" - echo "Created generic launcher: ${ABACUS_DIR}/${BUILD_DIR}/abacus.exe -> $(basename "$built_exe")" + cp -f "$built_exe" "${ABACUS_DIR}/${BUILD_DIR}/abacus.exe" + echo "Created generic launcher: ${ABACUS_DIR}/${BUILD_DIR}/abacus.exe -> $(basename "$built_exe")" else - echo "WARNING: no abacus_*.exe found in ${BUILD_DIR}; 'abacus' command not created." + echo "WARNING: no abacus_*.exe found in ${BUILD_DIR}; 'abacus' command not created." fi # Bundle the dependent MinGW / OpenBLAS / FFTW / ScaLAPACK runtime DLLs next to @@ -119,10 +133,10 @@ fi # stdout to a file ("error while loading shared libraries"). System DLLs # (msmpi.dll in System32, kernel32, ...) resolve on their own and are skipped. if [ -n "$built_exe" ]; then - echo "Bundling dependent DLLs into ${BUILD_DIR}/ ..." - ldd "${ABACUS_DIR}/${BUILD_DIR}/abacus.exe" 2>/dev/null \ - | awk -v p="$MINGW_PREFIX" '$3 ~ p {print $3}' | sort -u \ - | while read -r dll; do cp -f "$dll" "${ABACUS_DIR}/${BUILD_DIR}/"; done + echo "Bundling dependent DLLs into ${BUILD_DIR}/ ..." + ldd "${ABACUS_DIR}/${BUILD_DIR}/abacus.exe" 2>/dev/null | + awk -v p="$MINGW_PREFIX" '$3 ~ p {print $3}' | sort -u | + while read -r dll; do cp -f "$dll" "${ABACUS_DIR}/${BUILD_DIR}/"; done fi # When MPI is on, drop an `mpirun` shim next to the binary so the shared test @@ -131,15 +145,15 @@ fi # one thread per rank -- otherwise each rank's multithreaded OpenBLAS # oversubscribes the cores and its buffer allocator fails under several ranks. if [ "$ENABLE_MPI" = "ON" ]; then - cat << 'SHIM' > "${ABACUS_DIR}/${BUILD_DIR}/mpirun" + cat <<'SHIM' >"${ABACUS_DIR}/${BUILD_DIR}/mpirun" #!/bin/bash # mpirun -> mpiexec shim for native Windows (MS-MPI). See build_abacus_windows.sh. export OMP_NUM_THREADS=1 export OPENBLAS_NUM_THREADS=1 exec mpiexec "$@" SHIM - chmod +x "${ABACUS_DIR}/${BUILD_DIR}/mpirun" - echo "Created mpirun->mpiexec shim: ${ABACUS_DIR}/${BUILD_DIR}/mpirun" + chmod +x "${ABACUS_DIR}/${BUILD_DIR}/mpirun" + echo "Created mpirun->mpiexec shim: ${ABACUS_DIR}/${BUILD_DIR}/mpirun" fi # generate abacus_env.sh: sourcing it puts the MinGW runtime DLLs (via the @@ -148,7 +162,7 @@ fi # OPENBLAS_NUM_THREADS) is what actually caps its threads; pin it to 1 so that # `mpiexec -n N abacus` doesn't oversubscribe and trip OpenBLAS's buffer # allocator. (Both are set; OPENBLAS_NUM_THREADS alone has no effect here.) -cat << EOF > "${TOOL}/abacus_env.sh" +cat <"${TOOL}/abacus_env.sh" #!/bin/bash [ -f "${INSTALL_DIR}/setup" ] && source "${INSTALL_DIR}/setup" export PATH="${ABACUS_DIR}/${BUILD_DIR}":\${PATH} @@ -159,7 +173,7 @@ export OMP_NUM_THREADS=1 export OPENBLAS_NUM_THREADS=1 EOF -cat << EOF +cat < "$SETUPFILE" -#!/bin/bash -source "${SCRIPTDIR}/tool_kit.sh" -export ABACUS_TOOLCHAIN_OPTIONS="${TOOLCHAIN_OPTIONS}" -EOF + local args=("$@") + + # Initialize configuration with command line arguments + if ! config_init "${args[@]}"; then + show_help + exit 1 + fi - ui_info "Compiling with $(get_nprocs) processes for target ${TARGET_CPU}" - - write_toolchain_env ${INSTALLDIR} - - # write toolchain config - ui_info "Writing toolchain configuration..." - echo "tool_list=\"${tool_list}\"" > ${INSTALLDIR}/toolchain.conf - for ii in ${package_list}; do - install_mode="$(eval echo \${with_${ii}})" - echo "with_${ii}=\"${install_mode}\"" >> ${INSTALLDIR}/toolchain.conf - done - - # Exit if dry run - if [[ "$(config_get dry_run)" == "__TRUE__" ]]; then - ui_success "Configuration files generated successfully (dry-run mode)" - ui_info "To proceed with actual installation, run without --dry-run" - exit 0 + # Handle special version-related requests + if [[ "$(config_get show_version)" == "__TRUE__" ]]; then + version_show_available + exit 0 + fi + + local version_info_request="$(config_get show_version_info)" + if [[ -n "$version_info_request" ]]; then + if [[ "$version_info_request" == "all" ]]; then + version_show_available + else + version_show_available "$version_info_request" fi - - # Build packages (following original toolchain logic) - ui_section "Starting Package Installation" - ui_info "Initializing build environment..." - echo "# Leak suppressions" > ${INSTALLDIR}/lsan.supp - - # Install packages stage by stage with enhanced progress display - ui_stage_progress "0" "Build Tools & Compilers" - ./scripts/stage0/install_stage0.sh - - ui_stage_progress "1" "MPI Implementations" - ./scripts/stage1/install_stage1.sh - - ui_stage_progress "2" "Mathematical Libraries" - ./scripts/stage2/install_stage2.sh - - ui_stage_progress "3" "Scientific Computing Libraries" - ./scripts/stage3/install_stage3.sh - - ui_stage_progress "4" "Advanced Feature Libraries" - ./scripts/stage4/install_stage4.sh - - # Show beautiful completion message - ui_section "Installation Complete" - ui_success "ABACUS Toolchain installation completed successfully!" - echo "" - - # Enhanced usage instructions with beautiful formatting - ui_print_color "${UI_BLUE}${UI_BOLD}" "🎉 Congratulations! Your ABACUS toolchain installation finished successfully." - echo "" - ui_print_color "${UI_CYAN}${UI_BOLD}" "$(printf '═%.0s' $(seq 1 60))" - ui_print_color "${UI_BLUE}${UI_BOLD}" " USAGE INSTRUCTIONS" - ui_print_color "${UI_CYAN}${UI_BOLD}" "$(printf '═%.0s' $(seq 1 60))" + exit 0 + fi + + if [[ "$(config_get show_help)" == "__TRUE__" ]]; then + show_help + version_show_help + exit 0 + fi + + # Show beautiful welcome banner (only when actually running installation) + ui_welcome_banner + + # Show configuration summary with enhanced styling + if [[ "$(config_get dry_run)" == "__TRUE__" ]]; then + ui_section "Dry Run Mode" + ui_warning "Configuration will be written but no packages will be installed" echo "" - - ui_print_color "${UI_GREEN}${UI_BOLD}" "🔧 To activate the toolchain environment:" - ui_print_color "${UI_WHITE}" " source ${SETUPFILE}" + fi + + if [[ "$(config_get PACK_RUN)" == "__TRUE__" ]]; then + ui_section "Pack Run Mode" + ui_info "Only downloading packages, skipping installation" echo "" - - ui_print_color "${UI_GREEN}${UI_BOLD}" "🚀 Build ABACUS with your preferred toolchain:" - ui_print_color "${UI_WHITE}" " ./build_abacus_gnu.sh # GNU toolchain (GCC + OpenBLAS)" - ui_print_color "${UI_WHITE}" " ./build_abacus_intel.sh # Intel toolchain (ICC + MKL)" - ui_print_color "${UI_WHITE}" " ./build_abacus_gcc-mkl.sh # GCC + MKL" - ui_print_color "${UI_WHITE}" " ./build_abacus_gcc-aocl.sh # AMD GCC + AOCL" - ui_print_color "${UI_WHITE}" " ./build_abacus_aocc-aocl.sh # AMD AOCC + AOCL" + fi + + # Show version configuration + version_show_current + + # Show enhanced summary + ui_show_summary + + # Validate version configuration + if ! version_validate_config; then echo "" - - ui_print_color "${UI_ORANGE}${UI_BOLD}" "💡 Pro Tips:" - ui_print_color "${UI_GRAY}" " • Modify the builder scripts to suit your specific needs" - ui_print_color "${UI_GRAY}" " • The environment setup is required for each new shell session" - ui_print_color "${UI_GRAY}" " • Check the generated setup file for all available environment variables" + ui_warning "Some version configuration issues were detected" + ui_info "Please review the warnings above" echo "" - - ui_print_color "${UI_CYAN}${UI_BOLD}" "$(printf '═%.0s' $(seq 1 60))" - ui_print_color "${UI_GREEN}${UI_BOLD}" "✨ Happy DFT calculation with ABACUS! ✨" - ui_print_color "${UI_CYAN}${UI_BOLD}" "$(printf '═%.0s' $(seq 1 60))" + fi + + # Run configuration validation unless skipped + if ! should_skip_validation; then echo "" - - return 0 + ui_section "System Validation" + if ! validate_configuration; then + echo "" + report_error $LINENO "Configuration validation failed with errors" "CONFIG_ERROR" + ui_error "Please fix the configuration issues above and try again" + ui_info "You can skip validation with --skip-system-checks if needed" + exit 1 + fi + ui_success "System validation completed successfully" + fi + + # Skip user confirmation - proceed directly with installation + + # Export configuration to environment variables + config_export_to_env + + # Export version configuration for stage scripts + package_export_version_config + + # Preliminaries + ui_section "Preparing Installation Environment" + ui_info "Creating installation directories..." + mkdir -p ${INSTALLDIR} + + # Start writing setup file + ui_info "Generating setup configuration..." + cat <"$SETUPFILE" +#!/bin/bash +source "${SCRIPTDIR}/tool_kit.sh" +export ABACUS_TOOLCHAIN_OPTIONS="${TOOLCHAIN_OPTIONS}" +EOF + + ui_info "Compiling with $(get_nprocs) processes for target ${TARGET_CPU}" + + write_toolchain_env ${INSTALLDIR} + + # write toolchain config + ui_info "Writing toolchain configuration..." + echo "tool_list=\"${tool_list}\"" >${INSTALLDIR}/toolchain.conf + for ii in ${package_list}; do + install_mode="$(eval echo \${with_${ii}})" + echo "with_${ii}=\"${install_mode}\"" >>${INSTALLDIR}/toolchain.conf + done + + # Exit if dry run + if [[ "$(config_get dry_run)" == "__TRUE__" ]]; then + ui_success "Configuration files generated successfully (dry-run mode)" + ui_info "To proceed with actual installation, run without --dry-run" + exit 0 + fi + + # Build packages (following original toolchain logic) + ui_section "Starting Package Installation" + ui_info "Initializing build environment..." + echo "# Leak suppressions" >${INSTALLDIR}/lsan.supp + + # Install packages stage by stage with enhanced progress display + ui_stage_progress "0" "Build Tools & Compilers" + ./scripts/stage0/install_stage0.sh + + ui_stage_progress "1" "MPI Implementations" + ./scripts/stage1/install_stage1.sh + + ui_stage_progress "2" "Mathematical Libraries" + ./scripts/stage2/install_stage2.sh + + ui_stage_progress "3" "Scientific Computing Libraries" + ./scripts/stage3/install_stage3.sh + + ui_stage_progress "4" "Advanced Feature Libraries" + ./scripts/stage4/install_stage4.sh + + # Show beautiful completion message + ui_section "Installation Complete" + ui_success "ABACUS Toolchain installation completed successfully!" + echo "" + + # Enhanced usage instructions with beautiful formatting + ui_print_color "${UI_BLUE}${UI_BOLD}" "🎉 Congratulations! Your ABACUS toolchain installation finished successfully." + echo "" + ui_print_color "${UI_CYAN}${UI_BOLD}" "$(printf '═%.0s' $(seq 1 60))" + ui_print_color "${UI_BLUE}${UI_BOLD}" " USAGE INSTRUCTIONS" + ui_print_color "${UI_CYAN}${UI_BOLD}" "$(printf '═%.0s' $(seq 1 60))" + echo "" + + ui_print_color "${UI_GREEN}${UI_BOLD}" "🔧 To activate the toolchain environment:" + ui_print_color "${UI_WHITE}" " source ${SETUPFILE}" + echo "" + + ui_print_color "${UI_GREEN}${UI_BOLD}" "🚀 Build ABACUS with your preferred toolchain:" + ui_print_color "${UI_WHITE}" " ./build_abacus_gnu.sh # GNU toolchain (GCC + OpenBLAS)" + ui_print_color "${UI_WHITE}" " ./build_abacus_intel.sh # Intel toolchain (ICC + MKL)" + ui_print_color "${UI_WHITE}" " ./build_abacus_gcc-mkl.sh # GCC + MKL" + ui_print_color "${UI_WHITE}" " ./build_abacus_gcc-aocl.sh # AMD GCC + AOCL" + ui_print_color "${UI_WHITE}" " ./build_abacus_aocc-aocl.sh # AMD AOCC + AOCL" + echo "" + + ui_print_color "${UI_ORANGE}${UI_BOLD}" "💡 Pro Tips:" + ui_print_color "${UI_GRAY}" " • Modify the builder scripts to suit your specific needs" + ui_print_color "${UI_GRAY}" " • The environment setup is required for each new shell session" + ui_print_color "${UI_GRAY}" " • Check the generated setup file for all available environment variables" + echo "" + + ui_print_color "${UI_CYAN}${UI_BOLD}" "$(printf '═%.0s' $(seq 1 60))" + ui_print_color "${UI_GREEN}${UI_BOLD}" "✨ Happy DFT calculation with ABACUS! ✨" + ui_print_color "${UI_CYAN}${UI_BOLD}" "$(printf '═%.0s' $(seq 1 60))" + echo "" + + return 0 } # Run main function with all arguments diff --git a/toolchain/pre_set.sh b/toolchain/pre_set.sh index 25d597f1d3c..305a7017238 100755 --- a/toolchain/pre_set.sh +++ b/toolchain/pre_set.sh @@ -1,4 +1,4 @@ #!/bin/bash # for pre-setting abacus toolchain for avoid some problem dos2unix * */* */*/* -chmod +x *.sh */*.sh */*.py */*/*.sh \ No newline at end of file +chmod +x *.sh */*.sh */*.py */*/*.sh diff --git a/toolchain/scripts/common_vars.sh b/toolchain/scripts/common_vars.sh index 78a5833faa3..b5b46037dce 100755 --- a/toolchain/scripts/common_vars.sh +++ b/toolchain/scripts/common_vars.sh @@ -16,18 +16,18 @@ VERSION_FILE=${VERSION_FILE:-"${SCRIPTDIR}/VERSION"} # host architecture SYSTEM_ARCH=${SYSTEM_ARCH:-"$(uname -m)"} case "${SYSTEM_ARCH}" in - x86_64 | amd64) - SYSTEM_ARCH="x86_64" - ;; - aarch64 | arm64) - SYSTEM_ARCH="arm64" - ;; - i?86) - SYSTEM_ARCH="i386" - ;; - *) - # Keep other architectures as reported by uname. - ;; +x86_64 | amd64) + SYSTEM_ARCH="x86_64" + ;; +aarch64 | arm64) + SYSTEM_ARCH="arm64" + ;; +i?86) + SYSTEM_ARCH="i386" + ;; +*) + # Keep other architectures as reported by uname. + ;; esac export SYSTEM_ARCH @@ -49,6 +49,6 @@ MATH_MODE=${MATH_MODE:-openblas} export LOG_LINES="200" # download configuration -DOWNLOAD_CERT_POLICY=${DOWNLOAD_CERT_POLICY:-"smart"} # strict|smart|skip +DOWNLOAD_CERT_POLICY=${DOWNLOAD_CERT_POLICY:-"smart"} # strict|smart|skip export NVCC=${NVCC:-nvcc} diff --git a/toolchain/scripts/lib/config_manager.sh b/toolchain/scripts/lib/config_manager.sh index ce9345617c9..8a2fadcfe53 100644 --- a/toolchain/scripts/lib/config_manager.sh +++ b/toolchain/scripts/lib/config_manager.sh @@ -25,1252 +25,1252 @@ package_list="${tool_list} ${mpi_list} ${math_list} ${lib_list}" # Configuration file paths for loading in advance # Not in use now CONFIG_FILE_PATHS=( - "${ROOTDIR}/toolchain_config.conf" + "${ROOTDIR}/toolchain_config.conf" ) # Load configuration from file # Usage: config_load_from_file [config_file_path] config_load_from_file() { - local config_file="$1" - - # If no file specified, search for default locations - if [[ -z "$config_file" ]]; then - for path in "${CONFIG_FILE_PATHS[@]}"; do - if [[ -f "$path" && -r "$path" ]]; then - config_file="$path" - break + local config_file="$1" + + # If no file specified, search for default locations + if [[ -z "$config_file" ]]; then + for path in "${CONFIG_FILE_PATHS[@]}"; do + if [[ -f "$path" && -r "$path" ]]; then + config_file="$path" + break + fi + done + fi + + # If still no config file found, return silently (not an error) + if [[ -z "$config_file" || ! -f "$config_file" ]]; then + return 0 + fi + + echo "Loading configuration from: $config_file" + + # Read configuration file line by line + local line_num=0 + while IFS= read -r line || [[ -n "$line" ]]; do + line_num=$((line_num + 1)) + + # Skip empty lines and comments + [[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue + + # Remove leading/trailing whitespace + line=$(echo "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') + + # Parse variable assignments + if [[ "$line" =~ ^([A-Z_][A-Z0-9_]*)=(.*)$ ]]; then + local var_name="${BASH_REMATCH[1]}" + local var_value="${BASH_REMATCH[2]}" + + # Remove quotes if present + var_value=$(echo "$var_value" | sed 's/^"//;s/"$//') + + # Validate and store configuration + case "$var_name" in + # Basic configuration + INSTALL_PREFIX | BUILD_PREFIX) + CONFIG_CACHE["$var_name"]="$var_value" + ;; + NPROCS) + if [[ "$var_value" =~ ^[0-9]+$ ]]; then + CONFIG_CACHE["NPROCS_OVERWRITE"]="$var_value" + else + echo "Warning: Invalid NPROCS value '$var_value' in config file line $line_num" + fi + ;; + + # Mode selections + MPI_MODE) + case "$var_value" in + mpich | openmpi | intelmpi | none) + CONFIG_CACHE["MPI_MODE"]="$var_value" + ;; + *) + echo "Warning: Invalid MPI_MODE value '$var_value' in config file line $line_num" + ;; + esac + ;; + MATH_MODE) + case "$var_value" in + mkl | aocl | openblas | none) + CONFIG_CACHE["MATH_MODE"]="$var_value" + ;; + *) + echo "Warning: Invalid MATH_MODE value '$var_value' in config file line $line_num" + ;; + esac + ;; + + # Package configurations + WITH_*) + local package_name=$(echo "${var_name#WITH_}" | tr '[:upper:]' '[:lower:]') + # Handle special case for 4th-openmpi (convert to OPENMPI_4TH) + if [[ "$package_name" == "4th-openmpi" ]]; then + case "$var_value" in + yes | no | __DONTUSE__) + # Map __DONTUSE__ to "no" for OPENMPI_4TH + if [[ "$var_value" == "__DONTUSE__" ]]; then + CONFIG_CACHE["OPENMPI_4TH"]="no" + else + CONFIG_CACHE["OPENMPI_4TH"]="$var_value" fi - done - fi - - # If still no config file found, return silently (not an error) - if [[ -z "$config_file" || ! -f "$config_file" ]]; then - return 0 - fi - - echo "Loading configuration from: $config_file" - - # Read configuration file line by line - local line_num=0 - while IFS= read -r line || [[ -n "$line" ]]; do - line_num=$((line_num + 1)) - - # Skip empty lines and comments - [[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue - - # Remove leading/trailing whitespace - line=$(echo "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') - - # Parse variable assignments - if [[ "$line" =~ ^([A-Z_][A-Z0-9_]*)=(.*)$ ]]; then - local var_name="${BASH_REMATCH[1]}" - local var_value="${BASH_REMATCH[2]}" - - # Remove quotes if present - var_value=$(echo "$var_value" | sed 's/^"//;s/"$//') - - # Validate and store configuration - case "$var_name" in - # Basic configuration - INSTALL_PREFIX|BUILD_PREFIX) - CONFIG_CACHE["$var_name"]="$var_value" - ;; - NPROCS) - if [[ "$var_value" =~ ^[0-9]+$ ]]; then - CONFIG_CACHE["NPROCS_OVERWRITE"]="$var_value" - else - echo "Warning: Invalid NPROCS value '$var_value' in config file line $line_num" - fi - ;; - - # Mode selections - MPI_MODE) - case "$var_value" in - mpich|openmpi|intelmpi|none) - CONFIG_CACHE["MPI_MODE"]="$var_value" - ;; - *) - echo "Warning: Invalid MPI_MODE value '$var_value' in config file line $line_num" - ;; - esac - ;; - MATH_MODE) - case "$var_value" in - mkl|aocl|openblas|none) - CONFIG_CACHE["MATH_MODE"]="$var_value" - ;; - *) - echo "Warning: Invalid MATH_MODE value '$var_value' in config file line $line_num" - ;; - esac - ;; - - # Package configurations - WITH_*) - local package_name=$(echo "${var_name#WITH_}" | tr '[:upper:]' '[:lower:]') - # Handle special case for 4th-openmpi (convert to OPENMPI_4TH) - if [[ "$package_name" == "4th-openmpi" ]]; then - case "$var_value" in - yes|no|__DONTUSE__) - # Map __DONTUSE__ to "no" for OPENMPI_4TH - if [[ "$var_value" == "__DONTUSE__" ]]; then - CONFIG_CACHE["OPENMPI_4TH"]="no" - else - CONFIG_CACHE["OPENMPI_4TH"]="$var_value" - fi - ;; - *) - echo "Warning: Invalid value '$var_value' for WITH_4TH_OPENMPI in config file line $line_num" - ;; - esac - else - case "$var_value" in - __SYSTEM__|__INSTALL__|__DONTUSE__) - CONFIG_CACHE["with_${package_name}"]="$var_value" - ;; - *) - # Allow custom paths for some packages - CONFIG_CACHE["with_${package_name}"]="$var_value" - ;; - esac - fi - ;; - - # Version strategy options (NEW) - VERSION_STRATEGY) - case "$var_value" in - main|alt) - CONFIG_CACHE["VERSION_STRATEGY"]="$var_value" - ;; - *) - echo "Warning: Invalid VERSION_STRATEGY value '$var_value' in config file line $line_num. Valid options: main, alt" - ;; - esac - ;; - PACKAGE_VERSION_*) - # Extract package name from PACKAGE_VERSION_PACKAGENAME - local pkg_name="${var_name#PACKAGE_VERSION_}" - case "$var_value" in - main|alt) - CONFIG_CACHE["PACKAGE_VERSION_${pkg_name}"]="$var_value" - ;; - *) - echo "Warning: Invalid package version value '$var_value' for $var_name in config file line $line_num. Valid options: main, alt" - ;; - esac - ;; - - # Advanced options - # Not in use, leave it for future - DEBUG_MODE|VERBOSE_MODE|SKIP_SYSTEM_CHECKS|FORCE_REINSTALL) - case "$var_value" in - true|false) - CONFIG_CACHE["$var_name"]="$var_value" - ;; - *) - echo "Warning: Invalid boolean value '$var_value' for $var_name in config file line $line_num" - ;; - esac - ;; - - *) - echo "Warning: Unknown configuration option '$var_name' in config file line $line_num" - ;; - esac - elif [[ -n "$line" ]]; then - echo "Warning: Invalid configuration syntax in config file line $line_num: $line" + ;; + *) + echo "Warning: Invalid value '$var_value' for WITH_4TH_OPENMPI in config file line $line_num" + ;; + esac + else + case "$var_value" in + __SYSTEM__ | __INSTALL__ | __DONTUSE__) + CONFIG_CACHE["with_${package_name}"]="$var_value" + ;; + *) + # Allow custom paths for some packages + CONFIG_CACHE["with_${package_name}"]="$var_value" + ;; + esac fi - done < "$config_file" - - CONFIG_FILE_LOADED=true - echo "Configuration loaded successfully from: $config_file" - return 0 + ;; + + # Version strategy options (NEW) + VERSION_STRATEGY) + case "$var_value" in + main | alt) + CONFIG_CACHE["VERSION_STRATEGY"]="$var_value" + ;; + *) + echo "Warning: Invalid VERSION_STRATEGY value '$var_value' in config file line $line_num. Valid options: main, alt" + ;; + esac + ;; + PACKAGE_VERSION_*) + # Extract package name from PACKAGE_VERSION_PACKAGENAME + local pkg_name="${var_name#PACKAGE_VERSION_}" + case "$var_value" in + main | alt) + CONFIG_CACHE["PACKAGE_VERSION_${pkg_name}"]="$var_value" + ;; + *) + echo "Warning: Invalid package version value '$var_value' for $var_name in config file line $line_num. Valid options: main, alt" + ;; + esac + ;; + + # Advanced options + # Not in use, leave it for future + DEBUG_MODE | VERBOSE_MODE | SKIP_SYSTEM_CHECKS | FORCE_REINSTALL) + case "$var_value" in + true | false) + CONFIG_CACHE["$var_name"]="$var_value" + ;; + *) + echo "Warning: Invalid boolean value '$var_value' for $var_name in config file line $line_num" + ;; + esac + ;; + + *) + echo "Warning: Unknown configuration option '$var_name' in config file line $line_num" + ;; + esac + elif [[ -n "$line" ]]; then + echo "Warning: Invalid configuration syntax in config file line $line_num: $line" + fi + done <"$config_file" + + CONFIG_FILE_LOADED=true + echo "Configuration loaded successfully from: $config_file" + return 0 } # Apply mode-based configuration after loading from file # Usage: config_apply_modes_from_file config_apply_modes_from_file() { - # Apply MPI mode if set in config file (silent mode to avoid duplicate output) - if [[ -n "${CONFIG_CACHE[MPI_MODE]}" ]]; then - case "${CONFIG_CACHE[MPI_MODE]}" in - mpich) - CONFIG_CACHE["with_mpich"]="__INSTALL__" - CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" - ;; - openmpi) - CONFIG_CACHE["with_mpich"]="__DONTUSE__" - CONFIG_CACHE["with_openmpi"]="__INSTALL__" - CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" - ;; - intelmpi) - CONFIG_CACHE["with_mpich"]="__DONTUSE__" - CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - CONFIG_CACHE["with_intelmpi"]="__INSTALL__" - ;; - none) - CONFIG_CACHE["with_mpich"]="__DONTUSE__" - CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" - ;; - esac - fi - - # Apply Math mode if set in config file (silent mode to avoid duplicate output) - if [[ -n "${CONFIG_CACHE[MATH_MODE]}" ]]; then - case "${CONFIG_CACHE[MATH_MODE]}" in - mkl) - CONFIG_CACHE["with_mkl"]="__SYSTEM__" - CONFIG_CACHE["with_aocl"]="__DONTUSE__" - CONFIG_CACHE["with_openblas"]="__DONTUSE__" - # MKL provides FFTW and ScaLAPACK, so disable them (original logic) - CONFIG_CACHE["with_fftw"]="__DONTUSE__" - CONFIG_CACHE["with_scalapack"]="__DONTUSE__" - ;; - aocl) - CONFIG_CACHE["with_mkl"]="__DONTUSE__" - CONFIG_CACHE["with_aocl"]="__INSTALL__" - CONFIG_CACHE["with_openblas"]="__DONTUSE__" - ;; - openblas) - CONFIG_CACHE["with_mkl"]="__DONTUSE__" - CONFIG_CACHE["with_aocl"]="__DONTUSE__" - CONFIG_CACHE["with_openblas"]="__INSTALL__" - ;; - none) - CONFIG_CACHE["with_mkl"]="__DONTUSE__" - CONFIG_CACHE["with_aocl"]="__DONTUSE__" - CONFIG_CACHE["with_openblas"]="__DONTUSE__" - ;; - esac - fi + # Apply MPI mode if set in config file (silent mode to avoid duplicate output) + if [[ -n "${CONFIG_CACHE[MPI_MODE]}" ]]; then + case "${CONFIG_CACHE[MPI_MODE]}" in + mpich) + CONFIG_CACHE["with_mpich"]="__INSTALL__" + CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" + ;; + openmpi) + CONFIG_CACHE["with_mpich"]="__DONTUSE__" + CONFIG_CACHE["with_openmpi"]="__INSTALL__" + CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" + ;; + intelmpi) + CONFIG_CACHE["with_mpich"]="__DONTUSE__" + CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + CONFIG_CACHE["with_intelmpi"]="__INSTALL__" + ;; + none) + CONFIG_CACHE["with_mpich"]="__DONTUSE__" + CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" + ;; + esac + fi + + # Apply Math mode if set in config file (silent mode to avoid duplicate output) + if [[ -n "${CONFIG_CACHE[MATH_MODE]}" ]]; then + case "${CONFIG_CACHE[MATH_MODE]}" in + mkl) + CONFIG_CACHE["with_mkl"]="__SYSTEM__" + CONFIG_CACHE["with_aocl"]="__DONTUSE__" + CONFIG_CACHE["with_openblas"]="__DONTUSE__" + # MKL provides FFTW and ScaLAPACK, so disable them (original logic) + CONFIG_CACHE["with_fftw"]="__DONTUSE__" + CONFIG_CACHE["with_scalapack"]="__DONTUSE__" + ;; + aocl) + CONFIG_CACHE["with_mkl"]="__DONTUSE__" + CONFIG_CACHE["with_aocl"]="__INSTALL__" + CONFIG_CACHE["with_openblas"]="__DONTUSE__" + ;; + openblas) + CONFIG_CACHE["with_mkl"]="__DONTUSE__" + CONFIG_CACHE["with_aocl"]="__DONTUSE__" + CONFIG_CACHE["with_openblas"]="__INSTALL__" + ;; + none) + CONFIG_CACHE["with_mkl"]="__DONTUSE__" + CONFIG_CACHE["with_aocl"]="__DONTUSE__" + CONFIG_CACHE["with_openblas"]="__DONTUSE__" + ;; + esac + fi } # Initialize configuration manager # Usage: config_manager_init config_manager_init() { - if [[ "$CONFIG_INITIALIZED" == "true" ]]; then - return 0 - fi - - # Version management is now handled directly in individual scripts via package_versions.sh - - # Set default configuration first - config_set_defaults - - # Load configuration from file (if available) - this will override defaults - config_load_from_file - - # Apply mode-based configurations from file - this will override defaults - config_apply_modes_from_file - - CONFIG_INITIALIZED=true - + if [[ "$CONFIG_INITIALIZED" == "true" ]]; then return 0 + fi + + # Version management is now handled directly in individual scripts via package_versions.sh + + # Set default configuration first + config_set_defaults + + # Load configuration from file (if available) - this will override defaults + config_load_from_file + + # Apply mode-based configurations from file - this will override defaults + config_apply_modes_from_file + + CONFIG_INITIALIZED=true + + return 0 } # Set default configuration values # Usage: config_set_defaults config_set_defaults() { - # First set everything to __DONTUSE__ - for ii in ${package_list}; do - CONFIG_CACHE["with_${ii}"]="__DONTUSE__" - done + # First set everything to __DONTUSE__ + for ii in ${package_list}; do + CONFIG_CACHE["with_${ii}"]="__DONTUSE__" + done - # Tools to turn on by default - CONFIG_CACHE["with_gcc"]="__SYSTEM__" - CONFIG_CACHE["with_cmake"]="__INSTALL__" - - # Set default parallel jobs (NEW: Fix for parallel jobs parameter) - if [[ -z "${NPROCS_OVERWRITE}" ]]; then - if command -v nproc > /dev/null 2>&1; then - CONFIG_CACHE["NPROCS_OVERWRITE"]="$(nproc --all)" - elif command -v sysctl > /dev/null 2>&1; then - CONFIG_CACHE["NPROCS_OVERWRITE"]="$(sysctl -n hw.ncpu)" - else - CONFIG_CACHE["NPROCS_OVERWRITE"]="1" - fi + # Tools to turn on by default + CONFIG_CACHE["with_gcc"]="__SYSTEM__" + CONFIG_CACHE["with_cmake"]="__INSTALL__" + + # Set default parallel jobs (NEW: Fix for parallel jobs parameter) + if [[ -z "${NPROCS_OVERWRITE}" ]]; then + if command -v nproc >/dev/null 2>&1; then + CONFIG_CACHE["NPROCS_OVERWRITE"]="$(nproc --all)" + elif command -v sysctl >/dev/null 2>&1; then + CONFIG_CACHE["NPROCS_OVERWRITE"]="$(sysctl -n hw.ncpu)" else - CONFIG_CACHE["NPROCS_OVERWRITE"]="${NPROCS_OVERWRITE}" + CONFIG_CACHE["NPROCS_OVERWRITE"]="1" fi - - # Default MPI and Math modes (following original script logic) - # Default math library settings to openblas - CONFIG_CACHE["MATH_MODE"]="openblas" - - # Set math library defaults based on MATH_MODE (before user input processing) - case "${CONFIG_CACHE[MATH_MODE]}" in - mkl) - CONFIG_CACHE["with_mkl"]="__SYSTEM__" - ;; - aocl) - CONFIG_CACHE["with_aocl"]="__SYSTEM__" - ;; - openblas) - CONFIG_CACHE["with_openblas"]="__INSTALL__" - ;; - esac - - # For MPI, we try to detect system MPI variant (following original script logic) - # Only detect if MPI_MODE is not already set (to avoid duplicate detection) - if [[ -z "${CONFIG_CACHE[MPI_MODE]}" ]] && command -v mpiexec > /dev/null 2>&1; then - # check if we are dealing with openmpi, mpich or intelmpi - if mpiexec --version 2>&1 | grep -s -q "HYDRA"; then - if command -v ui_info &> /dev/null; then - ui_info "🔍 Detected system MPI: MPICH" - else - echo "MPI is detected and it appears to be MPICH" - fi - CONFIG_CACHE["MPI_MODE"]="mpich" - CONFIG_CACHE["with_mpich"]="__SYSTEM__" - elif mpiexec --version 2>&1 | grep -s -q "OpenRTE"; then - if command -v ui_info &> /dev/null; then - ui_info "🔍 Detected system MPI: OpenMPI" - else - echo "MPI is detected and it appears to be OpenMPI" - fi - CONFIG_CACHE["MPI_MODE"]="openmpi" - CONFIG_CACHE["with_openmpi"]="__SYSTEM__" - elif mpiexec --version 2>&1 | grep -s -q "Intel"; then - if command -v ui_info &> /dev/null; then - ui_info "🔍 Detected system MPI: Intel MPI" - else - echo "MPI is detected and it appears to be Intel MPI" - fi - CONFIG_CACHE["with_gcc"]="__DONTUSE__" - CONFIG_CACHE["with_amd"]="__DONTUSE__" - CONFIG_CACHE["with_aocl"]="__DONTUSE__" - CONFIG_CACHE["with_intel"]="__SYSTEM__" - CONFIG_CACHE["with_intelmpi"]="__SYSTEM__" - CONFIG_CACHE["MPI_MODE"]="intelmpi" - else # default to mpich - if command -v ui_info &> /dev/null; then - ui_info "🔍 MPI detected, defaulting to MPICH configuration" - else - echo "MPI is detected and defaults to MPICH" - fi - CONFIG_CACHE["MPI_MODE"]="mpich" - CONFIG_CACHE["with_mpich"]="__SYSTEM__" - fi - else - if command -v report_warning &> /dev/null; then - report_warning ${LINENO} "No MPI installation detected (ignore this message in Cray Linux Environment or when MPI installation was requested)." - else - echo "Warning: No MPI installation detected (ignore this message in Cray Linux Environment or when MPI installation was requested)." - fi - CONFIG_CACHE["MPI_MODE"]="no" + else + CONFIG_CACHE["NPROCS_OVERWRITE"]="${NPROCS_OVERWRITE}" + fi + + # Default MPI and Math modes (following original script logic) + # Default math library settings to openblas + CONFIG_CACHE["MATH_MODE"]="openblas" + + # Set math library defaults based on MATH_MODE (before user input processing) + case "${CONFIG_CACHE[MATH_MODE]}" in + mkl) + CONFIG_CACHE["with_mkl"]="__SYSTEM__" + ;; + aocl) + CONFIG_CACHE["with_aocl"]="__SYSTEM__" + ;; + openblas) + CONFIG_CACHE["with_openblas"]="__INSTALL__" + ;; + esac + + # For MPI, we try to detect system MPI variant (following original script logic) + # Only detect if MPI_MODE is not already set (to avoid duplicate detection) + if [[ -z "${CONFIG_CACHE[MPI_MODE]}" ]] && command -v mpiexec >/dev/null 2>&1; then + # check if we are dealing with openmpi, mpich or intelmpi + if mpiexec --version 2>&1 | grep -s -q "HYDRA"; then + if command -v ui_info &>/dev/null; then + ui_info "🔍 Detected system MPI: MPICH" + else + echo "MPI is detected and it appears to be MPICH" + fi + CONFIG_CACHE["MPI_MODE"]="mpich" + CONFIG_CACHE["with_mpich"]="__SYSTEM__" + elif mpiexec --version 2>&1 | grep -s -q "OpenRTE"; then + if command -v ui_info &>/dev/null; then + ui_info "🔍 Detected system MPI: OpenMPI" + else + echo "MPI is detected and it appears to be OpenMPI" + fi + CONFIG_CACHE["MPI_MODE"]="openmpi" + CONFIG_CACHE["with_openmpi"]="__SYSTEM__" + elif mpiexec --version 2>&1 | grep -s -q "Intel"; then + if command -v ui_info &>/dev/null; then + ui_info "🔍 Detected system MPI: Intel MPI" + else + echo "MPI is detected and it appears to be Intel MPI" + fi + CONFIG_CACHE["with_gcc"]="__DONTUSE__" + CONFIG_CACHE["with_amd"]="__DONTUSE__" + CONFIG_CACHE["with_aocl"]="__DONTUSE__" + CONFIG_CACHE["with_intel"]="__SYSTEM__" + CONFIG_CACHE["with_intelmpi"]="__SYSTEM__" + CONFIG_CACHE["MPI_MODE"]="intelmpi" + else # default to mpich + if command -v ui_info &>/dev/null; then + ui_info "🔍 MPI detected, defaulting to MPICH configuration" + else + echo "MPI is detected and defaults to MPICH" + fi + CONFIG_CACHE["MPI_MODE"]="mpich" + CONFIG_CACHE["with_mpich"]="__SYSTEM__" fi - - # Default libraries to install - CONFIG_CACHE["with_fftw"]="__INSTALL__" - CONFIG_CACHE["with_libxc"]="__INSTALL__" - CONFIG_CACHE["with_scalapack"]="__INSTALL__" - CONFIG_CACHE["with_elpa"]="__INSTALL__" - CONFIG_CACHE["with_cereal"]="__INSTALL__" - CONFIG_CACHE["with_json"]="__INSTALL__" - CONFIG_CACHE["with_libri"]="__INSTALL__" - CONFIG_CACHE["with_libcomm"]="__INSTALL__" - CONFIG_CACHE["with_nep"]="__DONTUSE__" - CONFIG_CACHE["with_dftd4"]="__DONTUSE__" - - # Default enable options (following original script logic) - CONFIG_CACHE["dry_run"]="__FALSE__" - CONFIG_CACHE["ENABLE_TSAN"]="__FALSE__" - CONFIG_CACHE["enable_opencl"]="__FALSE__" - CONFIG_CACHE["enable_cuda"]="__FALSE__" - CONFIG_CACHE["enable_hip"]="__FALSE__" - CONFIG_CACHE["intel_classic"]="no" - CONFIG_CACHE["PACK_RUN"]="__FALSE__" - CONFIG_CACHE["INTELMPI_CLASSIC"]="no" - CONFIG_CACHE["WITH_IFX"]="yes" - CONFIG_CACHE["WITH_FLANG"]="no" - CONFIG_CACHE["OPENMPI_4TH"]="no" - CONFIG_CACHE["GPUVER"]="no" - CONFIG_CACHE["MPICH_DEVICE"]="ch4" - CONFIG_CACHE["TARGET_CPU"]="native" - CONFIG_CACHE["LOG_LINES"]="200" - CONFIG_CACHE["show_help"]="false" - - # Version strategy defaults (NEW) - CONFIG_CACHE["VERSION_STRATEGY"]="main" - - # Defaults for CRAY Linux Environment (following original script logic) - if [[ -n "${CRAY_LD_LIBRARY_PATH}" ]]; then - CONFIG_CACHE["enable_cray"]="__TRUE__" - CONFIG_CACHE["MATH_MODE"]="cray" - # Default MPI used by CLE is assumed to be MPICH, in any case - # do not use the installers for the MPI libraries - CONFIG_CACHE["with_mpich"]="__DONTUSE__" - CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" - CONFIG_CACHE["MPI_MODE"]="mpich" - # set default value for some installers appropriate for CLE - CONFIG_CACHE["with_gcc"]="__DONTUSE__" - # Reset math library defaults for CRAY environment - CONFIG_CACHE["with_mkl"]="__DONTUSE__" - CONFIG_CACHE["with_aocl"]="__DONTUSE__" - CONFIG_CACHE["with_openblas"]="__DONTUSE__" + else + if command -v report_warning &>/dev/null; then + report_warning ${LINENO} "No MPI installation detected (ignore this message in Cray Linux Environment or when MPI installation was requested)." + else + echo "Warning: No MPI installation detected (ignore this message in Cray Linux Environment or when MPI installation was requested)." fi - - return 0 + CONFIG_CACHE["MPI_MODE"]="no" + fi + + # Default libraries to install + CONFIG_CACHE["with_fftw"]="__INSTALL__" + CONFIG_CACHE["with_libxc"]="__INSTALL__" + CONFIG_CACHE["with_scalapack"]="__INSTALL__" + CONFIG_CACHE["with_elpa"]="__INSTALL__" + CONFIG_CACHE["with_cereal"]="__INSTALL__" + CONFIG_CACHE["with_json"]="__INSTALL__" + CONFIG_CACHE["with_libri"]="__INSTALL__" + CONFIG_CACHE["with_libcomm"]="__INSTALL__" + CONFIG_CACHE["with_nep"]="__DONTUSE__" + CONFIG_CACHE["with_dftd4"]="__DONTUSE__" + + # Default enable options (following original script logic) + CONFIG_CACHE["dry_run"]="__FALSE__" + CONFIG_CACHE["ENABLE_TSAN"]="__FALSE__" + CONFIG_CACHE["enable_opencl"]="__FALSE__" + CONFIG_CACHE["enable_cuda"]="__FALSE__" + CONFIG_CACHE["enable_hip"]="__FALSE__" + CONFIG_CACHE["intel_classic"]="no" + CONFIG_CACHE["PACK_RUN"]="__FALSE__" + CONFIG_CACHE["INTELMPI_CLASSIC"]="no" + CONFIG_CACHE["WITH_IFX"]="yes" + CONFIG_CACHE["WITH_FLANG"]="no" + CONFIG_CACHE["OPENMPI_4TH"]="no" + CONFIG_CACHE["GPUVER"]="no" + CONFIG_CACHE["MPICH_DEVICE"]="ch4" + CONFIG_CACHE["TARGET_CPU"]="native" + CONFIG_CACHE["LOG_LINES"]="200" + CONFIG_CACHE["show_help"]="false" + + # Version strategy defaults (NEW) + CONFIG_CACHE["VERSION_STRATEGY"]="main" + + # Defaults for CRAY Linux Environment (following original script logic) + if [[ -n "${CRAY_LD_LIBRARY_PATH}" ]]; then + CONFIG_CACHE["enable_cray"]="__TRUE__" + CONFIG_CACHE["MATH_MODE"]="cray" + # Default MPI used by CLE is assumed to be MPICH, in any case + # do not use the installers for the MPI libraries + CONFIG_CACHE["with_mpich"]="__DONTUSE__" + CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" + CONFIG_CACHE["MPI_MODE"]="mpich" + # set default value for some installers appropriate for CLE + CONFIG_CACHE["with_gcc"]="__DONTUSE__" + # Reset math library defaults for CRAY environment + CONFIG_CACHE["with_mkl"]="__DONTUSE__" + CONFIG_CACHE["with_aocl"]="__DONTUSE__" + CONFIG_CACHE["with_openblas"]="__DONTUSE__" + fi + + return 0 } # Helper function to read --enable-* options # Usage: read_enable_option "--enable-feature=value" read_enable_option() { - local arg="$1" - if [[ "$arg" == *"="* ]]; then - local value="${arg#*=}" - case "$value" in - yes|true|1) echo "__TRUE__" ;; - no|false|0) echo "__FALSE__" ;; - *) echo "__INVALID__" ;; - esac - else - echo "__TRUE__" - fi + local arg="$1" + if [[ "$arg" == *"="* ]]; then + local value="${arg#*=}" + case "$value" in + yes | true | 1) echo "__TRUE__" ;; + no | false | 0) echo "__FALSE__" ;; + *) echo "__INVALID__" ;; + esac + else + echo "__TRUE__" + fi } # Helper function to read --with-* options # Usage: read_with_option "--with-package=value" read_with_option() { - local arg="$1" - if [[ "$arg" == *"="* ]]; then - local value="${arg#*=}" - case "$value" in - install) echo "__INSTALL__" ;; - system) echo "__SYSTEM__" ;; - no) echo "__DONTUSE__" ;; - *) echo "$value" ;; # Allow custom paths - esac - else - echo "__INSTALL__" - fi + local arg="$1" + if [[ "$arg" == *"="* ]]; then + local value="${arg#*=}" + case "$value" in + install) echo "__INSTALL__" ;; + system) echo "__SYSTEM__" ;; + no) echo "__DONTUSE__" ;; + *) echo "$value" ;; # Allow custom paths + esac + else + echo "__INSTALL__" + fi } # Validate configuration # Usage: config_validate config_validate() { - # Validate numeric values - if [[ -n "${CONFIG_CACHE[NPROCS_OVERWRITE]}" ]]; then - if ! [[ "${CONFIG_CACHE[NPROCS_OVERWRITE]}" =~ ^[0-9]+$ ]]; then - report_error ${LINENO} "Invalid number of processes: ${CONFIG_CACHE[NPROCS_OVERWRITE]}" - return 1 - fi - fi - - if ! [[ "${CONFIG_CACHE[LOG_LINES]}" =~ ^[0-9]+$ ]]; then - report_error ${LINENO} "Invalid log lines value: ${CONFIG_CACHE[LOG_LINES]}" - return 1 + # Validate numeric values + if [[ -n "${CONFIG_CACHE[NPROCS_OVERWRITE]}" ]]; then + if ! [[ "${CONFIG_CACHE[NPROCS_OVERWRITE]}" =~ ^[0-9]+$ ]]; then + report_error ${LINENO} "Invalid number of processes: ${CONFIG_CACHE[NPROCS_OVERWRITE]}" + return 1 fi - - # Validate GPU version - support only numeric formats - local gpu_ver="${CONFIG_CACHE[GPUVER]}" - if [[ "$gpu_ver" != "no" ]]; then - # Set ARCH_NUM based on GPUVER (remove decimal point for numeric versions) - local arch_num="${gpu_ver//.}" - - # Check if it's a valid numeric format (like 8.0, 70, 80, etc.) - if [[ "$arch_num" =~ ^[1-9][0-9]*$ ]]; then - CONFIG_CACHE["ARCH_NUM"]="$arch_num" - else - report_error ${LINENO} "Invalid GPU version: $gpu_ver. Supported formats: numeric with decimal (6.0, 7.0, 8.0, 8.9, etc.) or numeric without decimal (60, 70, 80, 89, etc.)" - return 1 - fi + fi + + if ! [[ "${CONFIG_CACHE[LOG_LINES]}" =~ ^[0-9]+$ ]]; then + report_error ${LINENO} "Invalid log lines value: ${CONFIG_CACHE[LOG_LINES]}" + return 1 + fi + + # Validate GPU version - support only numeric formats + local gpu_ver="${CONFIG_CACHE[GPUVER]}" + if [[ "$gpu_ver" != "no" ]]; then + # Set ARCH_NUM based on GPUVER (remove decimal point for numeric versions) + local arch_num="${gpu_ver//./}" + + # Check if it's a valid numeric format (like 8.0, 70, 80, etc.) + if [[ "$arch_num" =~ ^[1-9][0-9]*$ ]]; then + CONFIG_CACHE["ARCH_NUM"]="$arch_num" else - CONFIG_CACHE["ARCH_NUM"]="no" - fi - - # Backward compatibility: also export ARCH_NUM to environment when set - if [[ -n "${CONFIG_CACHE[ARCH_NUM]}" ]]; then - export ARCH_NUM="${CONFIG_CACHE[ARCH_NUM]}" + report_error ${LINENO} "Invalid GPU version: $gpu_ver. Supported formats: numeric with decimal (6.0, 7.0, 8.0, 8.9, etc.) or numeric without decimal (60, 70, 80, 89, etc.)" + return 1 fi - - return 0 + else + CONFIG_CACHE["ARCH_NUM"]="no" + fi + + # Backward compatibility: also export ARCH_NUM to environment when set + if [[ -n "${CONFIG_CACHE[ARCH_NUM]}" ]]; then + export ARCH_NUM="${CONFIG_CACHE[ARCH_NUM]}" + fi + + return 0 } # Apply environment variable processing logic (from original script lines 668-744) # Usage: config_apply_env_logic config_apply_env_logic() { - # Compiler conflicts (from original script L668-677) - if [ "${CONFIG_CACHE[with_intel]}" != "__DONTUSE__" ] && [ "${CONFIG_CACHE[with_gcc]}" = "__INSTALL__" ]; then - echo "You have chosen to use the Intel compiler, therefore the installation of the GNU compiler will be skipped." - CONFIG_CACHE["with_gcc"]="__SYSTEM__" + # Compiler conflicts (from original script L668-677) + if [ "${CONFIG_CACHE[with_intel]}" != "__DONTUSE__" ] && [ "${CONFIG_CACHE[with_gcc]}" = "__INSTALL__" ]; then + echo "You have chosen to use the Intel compiler, therefore the installation of the GNU compiler will be skipped." + CONFIG_CACHE["with_gcc"]="__SYSTEM__" + fi + if [ "${CONFIG_CACHE[with_amd]}" != "__DONTUSE__" ] && [ "${CONFIG_CACHE[with_gcc]}" = "__INSTALL__" ]; then + echo "You have chosen to use the AMD compiler, therefore the installation of the GNU compiler will be skipped." + CONFIG_CACHE["with_gcc"]="__SYSTEM__" + fi + if [ "${CONFIG_CACHE[with_amd]}" != "__DONTUSE__" ] && [ "${CONFIG_CACHE[with_intel]}" != "__DONTUSE__" ]; then + report_error "You have chosen to use the AMD and the Intel compiler to compile dependent packages. Select only one compiler." + exit 1 + fi + + # MPI library conflicts (from original script L679-710) + if [ "${CONFIG_CACHE[MPI_MODE]}" = "no" ]; then + if [ "${CONFIG_CACHE[with_scalapack]}" != "__DONTUSE__" ]; then + echo "Not using MPI, so scalapack is disabled." + CONFIG_CACHE["with_scalapack"]="__DONTUSE__" fi - if [ "${CONFIG_CACHE[with_amd]}" != "__DONTUSE__" ] && [ "${CONFIG_CACHE[with_gcc]}" = "__INSTALL__" ]; then - echo "You have chosen to use the AMD compiler, therefore the installation of the GNU compiler will be skipped." - CONFIG_CACHE["with_gcc"]="__SYSTEM__" + if [ "${CONFIG_CACHE[with_elpa]}" != "__DONTUSE__" ]; then + echo "Not using MPI, so ELPA is disabled." + CONFIG_CACHE["with_elpa"]="__DONTUSE__" fi - if [ "${CONFIG_CACHE[with_amd]}" != "__DONTUSE__" ] && [ "${CONFIG_CACHE[with_intel]}" != "__DONTUSE__" ]; then - report_error "You have chosen to use the AMD and the Intel compiler to compile dependent packages. Select only one compiler." - exit 1 + else + # if gcc is installed, then mpi needs to be installed too + if [ "${CONFIG_CACHE[with_gcc]}" = "__INSTALL__" ]; then + echo "You have chosen to install the GNU compiler, therefore MPI libraries have to be installed too" + case ${CONFIG_CACHE[MPI_MODE]} in + mpich) + CONFIG_CACHE["with_mpich"]="__INSTALL__" + CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + ;; + openmpi) + CONFIG_CACHE["with_mpich"]="__DONTUSE__" + CONFIG_CACHE["with_openmpi"]="__INSTALL__" + ;; + esac + echo "and the use of the Intel compiler and Intel MPI will be disabled." + CONFIG_CACHE["with_intel"]="__DONTUSE__" + CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" fi + # Enable only one MPI implementation + case ${CONFIG_CACHE[MPI_MODE]} in + mpich) + CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" + ;; + openmpi) + CONFIG_CACHE["with_mpich"]="__DONTUSE__" + CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" + ;; + intelmpi) + CONFIG_CACHE["with_mpich"]="__DONTUSE__" + CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + ;; + esac + fi - # MPI library conflicts (from original script L679-710) - if [ "${CONFIG_CACHE[MPI_MODE]}" = "no" ]; then - if [ "${CONFIG_CACHE[with_scalapack]}" != "__DONTUSE__" ]; then - echo "Not using MPI, so scalapack is disabled." - CONFIG_CACHE["with_scalapack"]="__DONTUSE__" - fi - if [ "${CONFIG_CACHE[with_elpa]}" != "__DONTUSE__" ]; then - echo "Not using MPI, so ELPA is disabled." - CONFIG_CACHE["with_elpa"]="__DONTUSE__" - fi - else - # if gcc is installed, then mpi needs to be installed too - if [ "${CONFIG_CACHE[with_gcc]}" = "__INSTALL__" ]; then - echo "You have chosen to install the GNU compiler, therefore MPI libraries have to be installed too" - case ${CONFIG_CACHE[MPI_MODE]} in - mpich) - CONFIG_CACHE["with_mpich"]="__INSTALL__" - CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - ;; - openmpi) - CONFIG_CACHE["with_mpich"]="__DONTUSE__" - CONFIG_CACHE["with_openmpi"]="__INSTALL__" - ;; - esac - echo "and the use of the Intel compiler and Intel MPI will be disabled." - CONFIG_CACHE["with_intel"]="__DONTUSE__" - CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" - fi - # Enable only one MPI implementation - case ${CONFIG_CACHE[MPI_MODE]} in - mpich) - CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" - ;; - openmpi) - CONFIG_CACHE["with_mpich"]="__DONTUSE__" - CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" - ;; - intelmpi) - CONFIG_CACHE["with_mpich"]="__DONTUSE__" - CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - ;; - esac + # If MATH_MODE is mkl, then openblas, scalapack and fftw is not needed + # QuantumMisaka in 2023-09-17 + if [ "${CONFIG_CACHE[MATH_MODE]}" = "mkl" ]; then + if [ "${CONFIG_CACHE[with_openblas]}" != "__DONTUSE__" ]; then + echo "Using MKL, so openblas is disabled." + CONFIG_CACHE["with_openblas"]="__DONTUSE__" fi - - # If MATH_MODE is mkl, then openblas, scalapack and fftw is not needed - # QuantumMisaka in 2023-09-17 - if [ "${CONFIG_CACHE[MATH_MODE]}" = "mkl" ]; then - if [ "${CONFIG_CACHE[with_openblas]}" != "__DONTUSE__" ]; then - echo "Using MKL, so openblas is disabled." - CONFIG_CACHE["with_openblas"]="__DONTUSE__" - fi - if [ "${CONFIG_CACHE[with_scalapack]}" != "__DONTUSE__" ]; then - echo "Using MKL, so scalapack is disabled." - CONFIG_CACHE["with_scalapack"]="__DONTUSE__" - fi - if [ "${CONFIG_CACHE[with_fftw]}" != "__DONTUSE__" ]; then - echo "Using MKL, so fftw is disabled." - CONFIG_CACHE["with_fftw"]="__DONTUSE__" - fi - if [ "${CONFIG_CACHE[with_libtorch]}" = "__INSTALL__" ]; then - report_error ${LINENO} \ - "Installing the current prebuilt libtorch package is disabled for oneMKL builds due to known conflicts between bundled and externally linked oneMKL libraries. Please provide a compatible libtorch installation via --with-libtorch=system or --with-libtorch=." - exit 1 - fi + if [ "${CONFIG_CACHE[with_scalapack]}" != "__DONTUSE__" ]; then + echo "Using MKL, so scalapack is disabled." + CONFIG_CACHE["with_scalapack"]="__DONTUSE__" fi - - # Select the correct compute number based on the GPU architecture - # QuantumMisaka in 2025-03-19 - local gpuver="${CONFIG_CACHE[GPUVER]}" - if [ "$gpuver" != "no" ]; then - export ARCH_NUM="${gpuver//.}" - CONFIG_CACHE["ARCH_NUM"]="$ARCH_NUM" - else - export ARCH_NUM="no" - CONFIG_CACHE["ARCH_NUM"]="no" + if [ "${CONFIG_CACHE[with_fftw]}" != "__DONTUSE__" ]; then + echo "Using MKL, so fftw is disabled." + CONFIG_CACHE["with_fftw"]="__DONTUSE__" fi - - # If CUDA or HIP are enabled, make sure the GPU version has been defined. - if [ "${CONFIG_CACHE[enable_cuda]}" = "__TRUE__" ] || [ "${CONFIG_CACHE[enable_hip]}" = "__TRUE__" ]; then - if [ "${CONFIG_CACHE[GPUVER]}" = "no" ]; then - report_error "Please choose GPU architecture to compile for with --gpu-ver" - exit 1 - fi - if [[ "$ARCH_NUM" =~ ^[1-9][0-9]*$ ]] || [ "$ARCH_NUM" = "no" ]; then - echo "Notice: GPU compilation is enabled, and GPU compatibility is set via --gpu-ver to sm_${ARCH_NUM}." - else - report_error ${LINENO} \ - "When GPU compilation is enabled, the --gpu-ver variable should be properly set regarding to GPU compatibility. For check your GPU compatibility, visit https://developer.nvidia.com/cuda-gpus. For example: A100 -> 8.0 (or 80), V100 -> 7.0 (or 70), 4090 -> 8.9 (or 89)" - exit 1 - fi + if [ "${CONFIG_CACHE[with_libtorch]}" = "__INSTALL__" ]; then + report_error ${LINENO} \ + "Installing the current prebuilt libtorch package is disabled for oneMKL builds due to known conflicts between bundled and externally linked oneMKL libraries. Please provide a compatible libtorch installation via --with-libtorch=system or --with-libtorch=." + exit 1 fi + fi + + # Select the correct compute number based on the GPU architecture + # QuantumMisaka in 2025-03-19 + local gpuver="${CONFIG_CACHE[GPUVER]}" + if [ "$gpuver" != "no" ]; then + export ARCH_NUM="${gpuver//./}" + CONFIG_CACHE["ARCH_NUM"]="$ARCH_NUM" + else + export ARCH_NUM="no" + CONFIG_CACHE["ARCH_NUM"]="no" + fi - # ABACUS itself and some dependencies require cmake. - if [ "${CONFIG_CACHE[with_cmake]}" = "__DONTUSE__" ]; then - report_error "CMake is required for ABACUS and some dependencies. Please enable it." - exit 1 + # If CUDA or HIP are enabled, make sure the GPU version has been defined. + if [ "${CONFIG_CACHE[enable_cuda]}" = "__TRUE__" ] || [ "${CONFIG_CACHE[enable_hip]}" = "__TRUE__" ]; then + if [ "${CONFIG_CACHE[GPUVER]}" = "no" ]; then + report_error "Please choose GPU architecture to compile for with --gpu-ver" + exit 1 + fi + if [[ "$ARCH_NUM" =~ ^[1-9][0-9]*$ ]] || [ "$ARCH_NUM" = "no" ]; then + echo "Notice: GPU compilation is enabled, and GPU compatibility is set via --gpu-ver to sm_${ARCH_NUM}." + else + report_error ${LINENO} \ + "When GPU compilation is enabled, the --gpu-ver variable should be properly set regarding to GPU compatibility. For check your GPU compatibility, visit https://developer.nvidia.com/cuda-gpus. For example: A100 -> 8.0 (or 80), V100 -> 7.0 (or 70), 4090 -> 8.9 (or 89)" + exit 1 fi + fi + + # ABACUS itself and some dependencies require cmake. + if [ "${CONFIG_CACHE[with_cmake]}" = "__DONTUSE__" ]; then + report_error "CMake is required for ABACUS and some dependencies. Please enable it." + exit 1 + fi } # Export configuration to environment variables # Usage: config_export_to_env config_export_to_env() { - # Apply environment variable processing logic first - config_apply_env_logic - - # Export all configuration values as environment variables - for key in "${!CONFIG_CACHE[@]}"; do - case "$key" in - enable_*) ;; - *) export "$key"="${CONFIG_CACHE[$key]}" ;; - esac - done + # Apply environment variable processing logic first + config_apply_env_logic - export ENABLE_CUDA="${CONFIG_CACHE[enable_cuda]}" - export ENABLE_HIP="${CONFIG_CACHE[enable_hip]}" - export ENABLE_OPENCL="${CONFIG_CACHE[enable_opencl]}" - export ENABLE_CRAY="${CONFIG_CACHE[enable_cray]:-"__FALSE__"}" - - # Export package list variables - export tool_list - export mpi_list - export math_list - export lib_list - export package_list + # Export all configuration values as environment variables + for key in "${!CONFIG_CACHE[@]}"; do + case "$key" in + enable_*) ;; + *) export "$key"="${CONFIG_CACHE[$key]}" ;; + esac + done + + export ENABLE_CUDA="${CONFIG_CACHE[enable_cuda]}" + export ENABLE_HIP="${CONFIG_CACHE[enable_hip]}" + export ENABLE_OPENCL="${CONFIG_CACHE[enable_opencl]}" + export ENABLE_CRAY="${CONFIG_CACHE[enable_cray]:-"__FALSE__"}" + + # Export package list variables + export tool_list + export mpi_list + export math_list + export lib_list + export package_list } # Get configuration value # Usage: config_get "key" config_get() { - local key="$1" - echo "${CONFIG_CACHE[$key]}" + local key="$1" + echo "${CONFIG_CACHE[$key]}" } # Set configuration value # Usage: config_set "key" "value" config_set() { - local key="$1" - local value="$2" - CONFIG_CACHE["$key"]="$value" + local key="$1" + local value="$2" + CONFIG_CACHE["$key"]="$value" } # Check if configuration key exists # Usage: config_has "key" config_has() { - local key="$1" - [[ -n "${CONFIG_CACHE[$key]}" ]] + local key="$1" + [[ -n "${CONFIG_CACHE[$key]}" ]] } # Print configuration summary # Usage: config_print_summary config_print_summary() { - echo "Configuration Summary:" - echo "=====================" - echo "MPI Mode: ${CONFIG_CACHE[MPI_MODE]}" - echo "Math Mode: ${CONFIG_CACHE[MATH_MODE]}" - echo "Target CPU: ${CONFIG_CACHE[TARGET_CPU]}" - echo "GPU Version: ${CONFIG_CACHE[GPUVER]}" - echo "Parallel Jobs: ${CONFIG_CACHE[NPROCS_OVERWRITE]:-$(get_nprocs)}" - echo "Dry Run: ${CONFIG_CACHE[dry_run]}" - echo "" - - echo "Package Configuration:" - echo "=====================" - for pkg in ${package_list}; do - local status="${CONFIG_CACHE[with_${pkg}]}" - if [[ "$status" != "__DONTUSE__" ]]; then - printf "%-15s: %s\n" "$pkg" "$status" - fi - done - echo "" + echo "Configuration Summary:" + echo "=====================" + echo "MPI Mode: ${CONFIG_CACHE[MPI_MODE]}" + echo "Math Mode: ${CONFIG_CACHE[MATH_MODE]}" + echo "Target CPU: ${CONFIG_CACHE[TARGET_CPU]}" + echo "GPU Version: ${CONFIG_CACHE[GPUVER]}" + echo "Parallel Jobs: ${CONFIG_CACHE[NPROCS_OVERWRITE]:-$(get_nprocs)}" + echo "Dry Run: ${CONFIG_CACHE[dry_run]}" + echo "" + + echo "Package Configuration:" + echo "=====================" + for pkg in ${package_list}; do + local status="${CONFIG_CACHE[with_${pkg}]}" + if [[ "$status" != "__DONTUSE__" ]]; then + printf "%-15s: %s\n" "$pkg" "$status" + fi + done + echo "" } # Parse command line arguments (New unified version) # Usage: config_parse_arguments "$@" config_parse_arguments() { - local show_help=false - local show_version=false - - while [[ $# -gt 0 ]]; do - case $1 in - # Help and version - -h|--help) - show_help=true - shift - ;; - --version) - show_version=true - shift - ;; - --version-info) - if [[ -n "$2" && "$2" != -* ]]; then - CONFIG_CACHE["show_version_info"]="$2" - shift 2 - else - CONFIG_CACHE["show_version_info"]="all" - shift - fi - ;; - - # Build options - -j) - if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then - CONFIG_CACHE["NPROCS_OVERWRITE"]="$2" - shift 2 - else - report_error $LINENO "-j requires a number argument" - return 1 - fi - ;; - -j[0-9]*) - local nprocs_overwrite="${1#-j}" - if [[ -n "$nprocs_overwrite" && "$nprocs_overwrite" =~ ^[0-9]+$ ]]; then - CONFIG_CACHE["NPROCS_OVERWRITE"]="$nprocs_overwrite" - shift - else - report_error $LINENO "-j requires a number argument" - return 1 - fi - ;; - --dry-run) - CONFIG_CACHE["dry_run"]="__TRUE__" - shift - ;; - --pack-run) - CONFIG_CACHE["PACK_RUN"]="__TRUE__" - shift - ;; - - # Package version selection - Support multiple package:version pairs - --package-version) - local package_version_args="" - local processed_count=0 - - # Handle --package-version=value format - if [[ "$1" =~ ^--package-version=(.+)$ ]]; then - package_version_args="${BASH_REMATCH[1]}" - shift - processed_count=1 - else - # Collect all consecutive non-option arguments - shift # Skip --package-version - while [[ $# -gt 0 && "$1" != -* ]]; do - if [[ -n "$package_version_args" ]]; then - package_version_args="$package_version_args $1" - else - package_version_args="$1" - fi - shift - ((processed_count++)) - done - fi - - # Validate we have at least one argument - if [[ -z "$package_version_args" ]]; then - report_error $LINENO "--package-version requires at least one package:version argument" - return 1 - fi - - # Process each package:version pair - local pair_count=0 - for pair in $package_version_args; do - if [[ "$pair" =~ ^([a-zA-Z0-9_]+):(main|alt)$ ]]; then - local pkg="${BASH_REMATCH[1]}" - local ver="${BASH_REMATCH[2]}" - CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="$ver" - ((pair_count++)) - else - report_error $LINENO "Invalid package version format: '$pair'. Use format 'package:version' (e.g., openmpi:alt, openblas:main)" - return 1 - fi - done - - # Report successful processing - if [[ $pair_count -gt 1 ]]; then - echo "INFO: Processed $pair_count package version overrides" - fi - ;; - - # Configuration file - --config-file) - if [[ -n "$2" && "$2" != -* ]]; then - config_load_from_file "$2" - shift 2 - else - report_error $LINENO "--config-file requires an argument" - return 1 - fi - ;; - - # Mode selections - Support both --mode=value and --mode value formats - --mpi-mode|--mpi-mode=*) - local mpi_value="" - # Handle --mpi-mode=value format - if [[ "$1" =~ ^--mpi-mode=(.+)$ ]]; then - mpi_value="${BASH_REMATCH[1]}" - shift - elif [[ -n "$2" && "$2" != -* ]]; then - mpi_value="$2" - shift 2 - else - report_error $LINENO "--mpi-mode requires an argument" - return 1 - fi - - case "$mpi_value" in - mpich|openmpi|intelmpi|no) - CONFIG_CACHE["MPI_MODE"]="$mpi_value" - ;; - *) - report_error $LINENO "Invalid MPI mode: $mpi_value. Valid options: mpich, openmpi, intelmpi, no" - return 1 - ;; - esac - ;; - --math-mode|--math-mode=*) - local math_value="" - # Handle --math-mode=value format - if [[ "$1" =~ ^--math-mode=(.+)$ ]]; then - math_value="${BASH_REMATCH[1]}" - shift - elif [[ -n "$2" && "$2" != -* ]]; then - math_value="$2" - shift 2 - else - report_error $LINENO "--math-mode requires an argument" - return 1 - fi - - case "$math_value" in - mkl|aocl|openblas|cray|no) - CONFIG_CACHE["MATH_MODE"]="$math_value" - # Apply automatic parameter settings for specific math modes - case "$math_value" in - aocl) - CONFIG_CACHE["with_aocl"]="__SYSTEM__" - CONFIG_CACHE["with_fftw"]="__SYSTEM__" - CONFIG_CACHE["with_scalapack"]="__SYSTEM__" - ;; - esac - ;; - *) - report_error $LINENO "Invalid math mode: $math_value. Valid options: mkl, aocl, openblas, cray, no" - return 1 - ;; - esac - ;; - - # Package options - --with-*) - local option="${1#--with-}" - local value="__INSTALL__" - - # Handle --with-package=value format - if [[ "$option" =~ ^(.+)=(.+)$ ]]; then - option="${BASH_REMATCH[1]}" - value="${BASH_REMATCH[2]}" - fi - - # Special handling for --with-mpich-device=* (must be handled before general mpich) - if [[ "$option" == "mpich-device" ]]; then - CONFIG_CACHE["MPICH_DEVICE"]="$value" - CONFIG_CACHE["MPI_MODE"]="mpich" - shift - continue - fi - - # Convert value to internal format (matching original read_with function) - case "$value" in - system) - value="__SYSTEM__" - ;; - install) - value="__INSTALL__" - ;; - no) - value="__DONTUSE__" - ;; - __SYSTEM__|__INSTALL__|__DONTUSE__) - # Already in internal format, keep as is - ;; - *) - # For custom paths, expand ~ to $HOME (matching original behavior) - value="${value//\~/$HOME}" - ;; - esac - - # Handle special cases with specific processing logic - case "$option" in - 4th-openmpi) - # Handle --with-4th-openmpi parameter (only yes/no options) - case "$value" in - "yes"|"install"|"__INSTALL__") - CONFIG_CACHE["OPENMPI_4TH"]="yes" - ;; - "no"|"__DONTUSE__") - CONFIG_CACHE["OPENMPI_4TH"]="no" - ;; - *) - # Default to "no" for any other values - CONFIG_CACHE["OPENMPI_4TH"]="no" - ;; - esac - ;; - mpich) - CONFIG_CACHE["with_mpich"]="$value" - USER_EXPLICIT_MPI["with_mpich"]="true" # Mark as explicitly set by user - # Set MPI_MODE if not disabled - if [ "$value" != "__DONTUSE__" ]; then - CONFIG_CACHE["MPI_MODE"]="mpich" - fi - ;; - openmpi) - CONFIG_CACHE["with_openmpi"]="$value" - USER_EXPLICIT_MPI["with_openmpi"]="true" # Mark as explicitly set by user - # Set MPI_MODE if not disabled - if [ "$value" != "__DONTUSE__" ]; then - CONFIG_CACHE["MPI_MODE"]="openmpi" - fi - ;; - intelmpi) - CONFIG_CACHE["with_intelmpi"]="$value" - USER_EXPLICIT_MPI["with_intelmpi"]="true" # Mark as explicitly set by user - # Set MPI_MODE if not disabled - if [ "$value" != "__DONTUSE__" ]; then - CONFIG_CACHE["MPI_MODE"]="intelmpi" - fi - ;; - intel-classic) - # Special handling for intel-classic: only accepts yes/no values - case "$value" in - "__INSTALL__"|""|"__DONTUSE__") - value="no" # Default to "no" - ;; - "yes") - value="yes" - ;; - "no") - value="no" - ;; - *) - report_error $LINENO "Invalid value '$value' for --with-intel-classic. Only 'yes' or 'no' are allowed." "CONFIG_ERROR" - return 1 - ;; - esac - CONFIG_CACHE["intel_classic"]="$value" - ;; - intel-mpi-clas*) - # Special handling for intel-mpi-classic: only accepts yes/no values - case "$value" in - "__INSTALL__"|""|"__DONTUSE__") - value="no" # Default to "no" - ;; - "yes") - value="yes" - ;; - "no") - value="no" - ;; - *) - report_error $LINENO "Invalid value '$value' for --with-intel-mpi-classic. Only 'yes' or 'no' are allowed." "CONFIG_ERROR" - return 1 - ;; - esac - CONFIG_CACHE["INTELMPI_CLASSIC"]="$value" - ;; - intel) - CONFIG_CACHE["with_intel"]="$value" - ;; - ifx) - # Special handling for ifx: only accepts yes/no values - case "$value" in - "__INSTALL__"|""|"__DONTUSE__") - value="no" # Default to "no" - ;; - "yes") - value="yes" - ;; - "no") - value="no" - ;; - *) - report_error $LINENO "Invalid value '$value' for --with-ifx. Only 'yes' or 'no' are allowed." "CONFIG_ERROR" - return 1 - ;; - esac - CONFIG_CACHE["WITH_IFX"]="$value" - ;; - amd) - CONFIG_CACHE["with_amd"]="$value" - ;; - flang) - # Special handling for flang: only accepts yes/no values - case "$value" in - "__INSTALL__"|""|"__DONTUSE__") - value="no" # Default to "no" - ;; - "yes") - value="yes" - ;; - "no") - value="no" - ;; - *) - report_error $LINENO "Invalid value '$value' for --with-flang. Only 'yes' or 'no' are allowed." "CONFIG_ERROR" - return 1 - ;; - esac - CONFIG_CACHE["WITH_FLANG"]="$value" - ;; - aocl) - CONFIG_CACHE["with_aocl"]="$value" - USER_EXPLICIT_MATH["with_aocl"]="true" # Mark as explicitly set by user - ;; - mkl) - CONFIG_CACHE["with_mkl"]="$value" - USER_EXPLICIT_MATH["with_mkl"]="true" # Mark as explicitly set by user - # Set MATH_MODE if not disabled - if [ "$value" != "__DONTUSE__" ]; then - CONFIG_CACHE["MATH_MODE"]="mkl" - fi - ;; - openblas) - CONFIG_CACHE["with_openblas"]="$value" - USER_EXPLICIT_MATH["with_openblas"]="true" # Mark as explicitly set by user - # Set MATH_MODE if not disabled - if [ "$value" != "__DONTUSE__" ]; then - CONFIG_CACHE["MATH_MODE"]="openblas" - fi - ;; - fftw) - CONFIG_CACHE["with_fftw"]="$value" - USER_EXPLICIT_MATH["with_fftw"]="true" # Mark as explicitly set by user - ;; - scalapack) - CONFIG_CACHE["with_scalapack"]="$value" - USER_EXPLICIT_MATH["with_scalapack"]="true" # Mark as explicitly set by user - ;; - *) - # Convert to standard format for all other options - option="${option,,}" # Convert to lowercase - CONFIG_CACHE["with_${option}"]="$value" - ;; - esac - shift - ;; - - # Enable options - --enable-*) - local option="${1#--enable-}" - local value="__TRUE__" - - # Handle --enable-feature=value format - if [[ "$option" =~ ^(.+)=(.+)$ ]]; then - option="${BASH_REMATCH[1]}" - value="${BASH_REMATCH[2]}" - case "$value" in - yes|true|1) value="__TRUE__" ;; - no|false|0) value="__FALSE__" ;; - *) - report_error $LINENO "Invalid value for --enable-${option}: $value. Use yes/no" - return 1 - ;; - esac - fi - - CONFIG_CACHE["enable_${option}"]="$value" - shift - ;; - - # GPU version - --gpu-ver|--gpu-ver=*) - local gpu_value="" - # Handle --gpu-ver=value format - if [[ "$1" =~ ^--gpu-ver=(.+)$ ]]; then - gpu_value="${BASH_REMATCH[1]}" - shift - elif [[ -n "$2" && "$2" != -* ]]; then - gpu_value="$2" - shift 2 - else - report_error $LINENO "--gpu-ver requires an argument" - return 1 - fi - CONFIG_CACHE["GPUVER"]="$gpu_value" - ;; - - # Target CPU - --target-cpu|--target-cpu=*) - local cpu_value="" - # Handle --target-cpu=value format - if [[ "$1" =~ ^--target-cpu=(.+)$ ]]; then - cpu_value="${BASH_REMATCH[1]}" - shift - elif [[ -n "$2" && "$2" != -* ]]; then - cpu_value="$2" - shift 2 - else - report_error $LINENO "--target-cpu requires an argument" - return 1 - fi - CONFIG_CACHE["TARGET_CPU"]="$cpu_value" - ;; - - # Log lines - --log-lines|--log-lines=*) - local log_value="" - # Handle --log-lines=value format - if [[ "$1" =~ ^--log-lines=(.+)$ ]]; then - log_value="${BASH_REMATCH[1]}" - shift - elif [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then - log_value="$2" - shift 2 - else - report_error $LINENO "--log-lines requires a number argument" - return 1 - fi - - if [[ "$log_value" =~ ^[0-9]+$ ]]; then - CONFIG_CACHE["LOG_LINES"]="$log_value" - else - report_error $LINENO "--log-lines requires a number argument" - return 1 - fi - ;; - - # Skip system checks - --skip-system-checks) - CONFIG_CACHE["skip_system_checks"]="__TRUE__" - shift - ;; - - # Positional arguments (ignored for now) - *) - shift - ;; - esac - done - - # Handle help and version requests - if [[ "$show_help" == true ]]; then - CONFIG_CACHE["show_help"]="__TRUE__" - return 0 - fi - - if [[ "$show_version" == true ]]; then - CONFIG_CACHE["show_version"]="__TRUE__" - return 0 - fi - - return 0 -} + local show_help=false + local show_version=false -# Initialize configuration with command line arguments -# Usage: config_init "$@" -config_init() { - # Set defaults first - config_set_defaults + while [[ $# -gt 0 ]]; do + case $1 in + # Help and version + -h | --help) + show_help=true + shift + ;; + --version) + show_version=true + shift + ;; + --version-info) + if [[ -n "$2" && "$2" != -* ]]; then + CONFIG_CACHE["show_version_info"]="$2" + shift 2 + else + CONFIG_CACHE["show_version_info"]="all" + shift + fi + ;; - # Initialize version helper to ensure VERSION_STRATEGY defaults are set - if command -v version_helper_init > /dev/null 2>&1; then - version_helper_init - fi + # Build options + -j) + if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then + CONFIG_CACHE["NPROCS_OVERWRITE"]="$2" + shift 2 + else + report_error $LINENO "-j requires a number argument" + return 1 + fi + ;; + -j[0-9]*) + local nprocs_overwrite="${1#-j}" + if [[ -n "$nprocs_overwrite" && "$nprocs_overwrite" =~ ^[0-9]+$ ]]; then + CONFIG_CACHE["NPROCS_OVERWRITE"]="$nprocs_overwrite" + shift + else + report_error $LINENO "-j requires a number argument" + return 1 + fi + ;; + --dry-run) + CONFIG_CACHE["dry_run"]="__TRUE__" + shift + ;; + --pack-run) + CONFIG_CACHE["PACK_RUN"]="__TRUE__" + shift + ;; - # Load configuration from file (if available) - this will override defaults - if ! config_load_from_file; then + # Package version selection - Support multiple package:version pairs + --package-version) + local package_version_args="" + local processed_count=0 + + # Handle --package-version=value format + if [[ "$1" =~ ^--package-version=(.+)$ ]]; then + package_version_args="${BASH_REMATCH[1]}" + shift + processed_count=1 + else + # Collect all consecutive non-option arguments + shift # Skip --package-version + while [[ $# -gt 0 && "$1" != -* ]]; do + if [[ -n "$package_version_args" ]]; then + package_version_args="$package_version_args $1" + else + package_version_args="$1" + fi + shift + ((processed_count++)) + done + fi + + # Validate we have at least one argument + if [[ -z "$package_version_args" ]]; then + report_error $LINENO "--package-version requires at least one package:version argument" return 1 - fi + fi + + # Process each package:version pair + local pair_count=0 + for pair in $package_version_args; do + if [[ "$pair" =~ ^([a-zA-Z0-9_]+):(main|alt)$ ]]; then + local pkg="${BASH_REMATCH[1]}" + local ver="${BASH_REMATCH[2]}" + CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="$ver" + ((pair_count++)) + else + report_error $LINENO "Invalid package version format: '$pair'. Use format 'package:version' (e.g., openmpi:alt, openblas:main)" + return 1 + fi + done - # Apply mode-based configurations from file - this will override defaults - if ! config_apply_modes_from_file; then + # Report successful processing + if [[ $pair_count -gt 1 ]]; then + echo "INFO: Processed $pair_count package version overrides" + fi + ;; + + # Configuration file + --config-file) + if [[ -n "$2" && "$2" != -* ]]; then + config_load_from_file "$2" + shift 2 + else + report_error $LINENO "--config-file requires an argument" return 1 - fi + fi + ;; - # Parse command line arguments - this will override file settings - if ! config_parse_arguments "$@"; then + # Mode selections - Support both --mode=value and --mode value formats + --mpi-mode | --mpi-mode=*) + local mpi_value="" + # Handle --mpi-mode=value format + if [[ "$1" =~ ^--mpi-mode=(.+)$ ]]; then + mpi_value="${BASH_REMATCH[1]}" + shift + elif [[ -n "$2" && "$2" != -* ]]; then + mpi_value="$2" + shift 2 + else + report_error $LINENO "--mpi-mode requires an argument" return 1 - fi + fi - # Apply mode-based configurations from command line - if ! config_apply_modes; then + case "$mpi_value" in + mpich | openmpi | intelmpi | no) + CONFIG_CACHE["MPI_MODE"]="$mpi_value" + ;; + *) + report_error $LINENO "Invalid MPI mode: $mpi_value. Valid options: mpich, openmpi, intelmpi, no" return 1 - fi + ;; + esac + ;; + --math-mode | --math-mode=*) + local math_value="" + # Handle --math-mode=value format + if [[ "$1" =~ ^--math-mode=(.+)$ ]]; then + math_value="${BASH_REMATCH[1]}" + shift + elif [[ -n "$2" && "$2" != -* ]]; then + math_value="$2" + shift 2 + else + report_error $LINENO "--math-mode requires an argument" + return 1 + fi - # Validate configuration - if ! config_validate; then + case "$math_value" in + mkl | aocl | openblas | cray | no) + CONFIG_CACHE["MATH_MODE"]="$math_value" + # Apply automatic parameter settings for specific math modes + case "$math_value" in + aocl) + CONFIG_CACHE["with_aocl"]="__SYSTEM__" + CONFIG_CACHE["with_fftw"]="__SYSTEM__" + CONFIG_CACHE["with_scalapack"]="__SYSTEM__" + ;; + esac + ;; + *) + report_error $LINENO "Invalid math mode: $math_value. Valid options: mkl, aocl, openblas, cray, no" return 1 - fi + ;; + esac + ;; + + # Package options + --with-*) + local option="${1#--with-}" + local value="__INSTALL__" + # Handle --with-package=value format + if [[ "$option" =~ ^(.+)=(.+)$ ]]; then + option="${BASH_REMATCH[1]}" + value="${BASH_REMATCH[2]}" + fi + + # Special handling for --with-mpich-device=* (must be handled before general mpich) + if [[ "$option" == "mpich-device" ]]; then + CONFIG_CACHE["MPICH_DEVICE"]="$value" + CONFIG_CACHE["MPI_MODE"]="mpich" + shift + continue + fi + + # Convert value to internal format (matching original read_with function) + case "$value" in + system) + value="__SYSTEM__" + ;; + install) + value="__INSTALL__" + ;; + no) + value="__DONTUSE__" + ;; + __SYSTEM__ | __INSTALL__ | __DONTUSE__) + # Already in internal format, keep as is + ;; + *) + # For custom paths, expand ~ to $HOME (matching original behavior) + value="${value//\~/$HOME}" + ;; + esac + + # Handle special cases with specific processing logic + case "$option" in + 4th-openmpi) + # Handle --with-4th-openmpi parameter (only yes/no options) + case "$value" in + "yes" | "install" | "__INSTALL__") + CONFIG_CACHE["OPENMPI_4TH"]="yes" + ;; + "no" | "__DONTUSE__") + CONFIG_CACHE["OPENMPI_4TH"]="no" + ;; + *) + # Default to "no" for any other values + CONFIG_CACHE["OPENMPI_4TH"]="no" + ;; + esac + ;; + mpich) + CONFIG_CACHE["with_mpich"]="$value" + USER_EXPLICIT_MPI["with_mpich"]="true" # Mark as explicitly set by user + # Set MPI_MODE if not disabled + if [ "$value" != "__DONTUSE__" ]; then + CONFIG_CACHE["MPI_MODE"]="mpich" + fi + ;; + openmpi) + CONFIG_CACHE["with_openmpi"]="$value" + USER_EXPLICIT_MPI["with_openmpi"]="true" # Mark as explicitly set by user + # Set MPI_MODE if not disabled + if [ "$value" != "__DONTUSE__" ]; then + CONFIG_CACHE["MPI_MODE"]="openmpi" + fi + ;; + intelmpi) + CONFIG_CACHE["with_intelmpi"]="$value" + USER_EXPLICIT_MPI["with_intelmpi"]="true" # Mark as explicitly set by user + # Set MPI_MODE if not disabled + if [ "$value" != "__DONTUSE__" ]; then + CONFIG_CACHE["MPI_MODE"]="intelmpi" + fi + ;; + intel-classic) + # Special handling for intel-classic: only accepts yes/no values + case "$value" in + "__INSTALL__" | "" | "__DONTUSE__") + value="no" # Default to "no" + ;; + "yes") + value="yes" + ;; + "no") + value="no" + ;; + *) + report_error $LINENO "Invalid value '$value' for --with-intel-classic. Only 'yes' or 'no' are allowed." "CONFIG_ERROR" + return 1 + ;; + esac + CONFIG_CACHE["intel_classic"]="$value" + ;; + intel-mpi-clas*) + # Special handling for intel-mpi-classic: only accepts yes/no values + case "$value" in + "__INSTALL__" | "" | "__DONTUSE__") + value="no" # Default to "no" + ;; + "yes") + value="yes" + ;; + "no") + value="no" + ;; + *) + report_error $LINENO "Invalid value '$value' for --with-intel-mpi-classic. Only 'yes' or 'no' are allowed." "CONFIG_ERROR" + return 1 + ;; + esac + CONFIG_CACHE["INTELMPI_CLASSIC"]="$value" + ;; + intel) + CONFIG_CACHE["with_intel"]="$value" + ;; + ifx) + # Special handling for ifx: only accepts yes/no values + case "$value" in + "__INSTALL__" | "" | "__DONTUSE__") + value="no" # Default to "no" + ;; + "yes") + value="yes" + ;; + "no") + value="no" + ;; + *) + report_error $LINENO "Invalid value '$value' for --with-ifx. Only 'yes' or 'no' are allowed." "CONFIG_ERROR" + return 1 + ;; + esac + CONFIG_CACHE["WITH_IFX"]="$value" + ;; + amd) + CONFIG_CACHE["with_amd"]="$value" + ;; + flang) + # Special handling for flang: only accepts yes/no values + case "$value" in + "__INSTALL__" | "" | "__DONTUSE__") + value="no" # Default to "no" + ;; + "yes") + value="yes" + ;; + "no") + value="no" + ;; + *) + report_error $LINENO "Invalid value '$value' for --with-flang. Only 'yes' or 'no' are allowed." "CONFIG_ERROR" + return 1 + ;; + esac + CONFIG_CACHE["WITH_FLANG"]="$value" + ;; + aocl) + CONFIG_CACHE["with_aocl"]="$value" + USER_EXPLICIT_MATH["with_aocl"]="true" # Mark as explicitly set by user + ;; + mkl) + CONFIG_CACHE["with_mkl"]="$value" + USER_EXPLICIT_MATH["with_mkl"]="true" # Mark as explicitly set by user + # Set MATH_MODE if not disabled + if [ "$value" != "__DONTUSE__" ]; then + CONFIG_CACHE["MATH_MODE"]="mkl" + fi + ;; + openblas) + CONFIG_CACHE["with_openblas"]="$value" + USER_EXPLICIT_MATH["with_openblas"]="true" # Mark as explicitly set by user + # Set MATH_MODE if not disabled + if [ "$value" != "__DONTUSE__" ]; then + CONFIG_CACHE["MATH_MODE"]="openblas" + fi + ;; + fftw) + CONFIG_CACHE["with_fftw"]="$value" + USER_EXPLICIT_MATH["with_fftw"]="true" # Mark as explicitly set by user + ;; + scalapack) + CONFIG_CACHE["with_scalapack"]="$value" + USER_EXPLICIT_MATH["with_scalapack"]="true" # Mark as explicitly set by user + ;; + *) + # Convert to standard format for all other options + option="${option,,}" # Convert to lowercase + CONFIG_CACHE["with_${option}"]="$value" + ;; + esac + shift + ;; + + # Enable options + --enable-*) + local option="${1#--enable-}" + local value="__TRUE__" + + # Handle --enable-feature=value format + if [[ "$option" =~ ^(.+)=(.+)$ ]]; then + option="${BASH_REMATCH[1]}" + value="${BASH_REMATCH[2]}" + case "$value" in + yes | true | 1) value="__TRUE__" ;; + no | false | 0) value="__FALSE__" ;; + *) + report_error $LINENO "Invalid value for --enable-${option}: $value. Use yes/no" + return 1 + ;; + esac + fi + + CONFIG_CACHE["enable_${option}"]="$value" + shift + ;; + + # GPU version + --gpu-ver | --gpu-ver=*) + local gpu_value="" + # Handle --gpu-ver=value format + if [[ "$1" =~ ^--gpu-ver=(.+)$ ]]; then + gpu_value="${BASH_REMATCH[1]}" + shift + elif [[ -n "$2" && "$2" != -* ]]; then + gpu_value="$2" + shift 2 + else + report_error $LINENO "--gpu-ver requires an argument" + return 1 + fi + CONFIG_CACHE["GPUVER"]="$gpu_value" + ;; + + # Target CPU + --target-cpu | --target-cpu=*) + local cpu_value="" + # Handle --target-cpu=value format + if [[ "$1" =~ ^--target-cpu=(.+)$ ]]; then + cpu_value="${BASH_REMATCH[1]}" + shift + elif [[ -n "$2" && "$2" != -* ]]; then + cpu_value="$2" + shift 2 + else + report_error $LINENO "--target-cpu requires an argument" + return 1 + fi + CONFIG_CACHE["TARGET_CPU"]="$cpu_value" + ;; + + # Log lines + --log-lines | --log-lines=*) + local log_value="" + # Handle --log-lines=value format + if [[ "$1" =~ ^--log-lines=(.+)$ ]]; then + log_value="${BASH_REMATCH[1]}" + shift + elif [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then + log_value="$2" + shift 2 + else + report_error $LINENO "--log-lines requires a number argument" + return 1 + fi + + if [[ "$log_value" =~ ^[0-9]+$ ]]; then + CONFIG_CACHE["LOG_LINES"]="$log_value" + else + report_error $LINENO "--log-lines requires a number argument" + return 1 + fi + ;; + + # Skip system checks + --skip-system-checks) + CONFIG_CACHE["skip_system_checks"]="__TRUE__" + shift + ;; + + # Positional arguments (ignored for now) + *) + shift + ;; + esac + done + + # Handle help and version requests + if [[ "$show_help" == true ]]; then + CONFIG_CACHE["show_help"]="__TRUE__" + return 0 + fi + + if [[ "$show_version" == true ]]; then + CONFIG_CACHE["show_version"]="__TRUE__" return 0 + fi + + return 0 +} + +# Initialize configuration with command line arguments +# Usage: config_init "$@" +config_init() { + # Set defaults first + config_set_defaults + + # Initialize version helper to ensure VERSION_STRATEGY defaults are set + if command -v version_helper_init >/dev/null 2>&1; then + version_helper_init + fi + + # Load configuration from file (if available) - this will override defaults + if ! config_load_from_file; then + return 1 + fi + + # Apply mode-based configurations from file - this will override defaults + if ! config_apply_modes_from_file; then + return 1 + fi + + # Parse command line arguments - this will override file settings + if ! config_parse_arguments "$@"; then + return 1 + fi + + # Apply mode-based configurations from command line + if ! config_apply_modes; then + return 1 + fi + + # Validate configuration + if ! config_validate; then + return 1 + fi + + return 0 } # Apply configuration based on modes # Usage: config_apply_modes config_apply_modes() { - # Apply MPI mode settings (with output for user feedback) - local mpi_mode="${CONFIG_CACHE[MPI_MODE]}" - if [[ -n "$mpi_mode" ]]; then - if command -v ui_info &> /dev/null; then - ui_info "⚙️ Configuring MPI mode: $mpi_mode" - else - echo "Applying MPI mode: $mpi_mode" - fi - case "$mpi_mode" in - mpich) - # Only override if user hasn't explicitly set these values via command line - [[ -z "${USER_EXPLICIT_MPI[with_mpich]}" ]] && CONFIG_CACHE["with_mpich"]="__INSTALL__" - [[ -z "${USER_EXPLICIT_MPI[with_openmpi]}" ]] && CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MPI[with_intelmpi]}" ]] && CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" - ;; - openmpi) - [[ -z "${USER_EXPLICIT_MPI[with_mpich]}" ]] && CONFIG_CACHE["with_mpich"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MPI[with_openmpi]}" ]] && CONFIG_CACHE["with_openmpi"]="__INSTALL__" - [[ -z "${USER_EXPLICIT_MPI[with_intelmpi]}" ]] && CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" - ;; - intelmpi) - [[ -z "${USER_EXPLICIT_MPI[with_mpich]}" ]] && CONFIG_CACHE["with_mpich"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MPI[with_openmpi]}" ]] && CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MPI[with_intelmpi]}" ]] && CONFIG_CACHE["with_intelmpi"]="__INSTALL__" - ;; - no) - [[ -z "${USER_EXPLICIT_MPI[with_mpich]}" ]] && CONFIG_CACHE["with_mpich"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MPI[with_openmpi]}" ]] && CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MPI[with_intelmpi]}" ]] && CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" - ;; - esac + # Apply MPI mode settings (with output for user feedback) + local mpi_mode="${CONFIG_CACHE[MPI_MODE]}" + if [[ -n "$mpi_mode" ]]; then + if command -v ui_info &>/dev/null; then + ui_info "⚙️ Configuring MPI mode: $mpi_mode" + else + echo "Applying MPI mode: $mpi_mode" fi - - # Apply math mode settings (with output for user feedback) - local math_mode="${CONFIG_CACHE[MATH_MODE]}" - if [[ -n "$math_mode" ]]; then - if command -v ui_info &> /dev/null; then - ui_info "🧮 Configuring Math mode: $math_mode" - else - echo "Applying Math mode: $math_mode" - fi - case "$math_mode" in - mkl) - [[ -z "${USER_EXPLICIT_MATH[with_mkl]}" ]] && CONFIG_CACHE["with_mkl"]="__SYSTEM__" - [[ -z "${USER_EXPLICIT_MATH[with_aocl]}" ]] && CONFIG_CACHE["with_aocl"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MATH[with_openblas]}" ]] && CONFIG_CACHE["with_openblas"]="__DONTUSE__" - # MKL provides FFTW and ScaLAPACK, so disable them (original logic) - [[ -z "${USER_EXPLICIT_MATH[with_fftw]}" ]] && CONFIG_CACHE["with_fftw"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MATH[with_scalapack]}" ]] && CONFIG_CACHE["with_scalapack"]="__DONTUSE__" - ;; - aocl) - [[ -z "${USER_EXPLICIT_MATH[with_mkl]}" ]] && CONFIG_CACHE["with_mkl"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MATH[with_aocl]}" ]] && CONFIG_CACHE["with_aocl"]="__SYSTEM__" - [[ -z "${USER_EXPLICIT_MATH[with_openblas]}" ]] && CONFIG_CACHE["with_openblas"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MATH[with_fftw]}" ]] && CONFIG_CACHE["with_fftw"]="__SYSTEM__" - [[ -z "${USER_EXPLICIT_MATH[with_scalapack]}" ]] && CONFIG_CACHE["with_scalapack"]="__SYSTEM__" - ;; - openblas) - [[ -z "${USER_EXPLICIT_MATH[with_mkl]}" ]] && CONFIG_CACHE["with_mkl"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MATH[with_aocl]}" ]] && CONFIG_CACHE["with_aocl"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MATH[with_openblas]}" ]] && CONFIG_CACHE["with_openblas"]="__INSTALL__" - ;; - cray) - [[ -z "${USER_EXPLICIT_MATH[with_mkl]}" ]] && CONFIG_CACHE["with_mkl"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MATH[with_aocl]}" ]] && CONFIG_CACHE["with_aocl"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MATH[with_openblas]}" ]] && CONFIG_CACHE["with_openblas"]="__DONTUSE__" - ;; - esac + case "$mpi_mode" in + mpich) + # Only override if user hasn't explicitly set these values via command line + [[ -z "${USER_EXPLICIT_MPI[with_mpich]}" ]] && CONFIG_CACHE["with_mpich"]="__INSTALL__" + [[ -z "${USER_EXPLICIT_MPI[with_openmpi]}" ]] && CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MPI[with_intelmpi]}" ]] && CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" + ;; + openmpi) + [[ -z "${USER_EXPLICIT_MPI[with_mpich]}" ]] && CONFIG_CACHE["with_mpich"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MPI[with_openmpi]}" ]] && CONFIG_CACHE["with_openmpi"]="__INSTALL__" + [[ -z "${USER_EXPLICIT_MPI[with_intelmpi]}" ]] && CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" + ;; + intelmpi) + [[ -z "${USER_EXPLICIT_MPI[with_mpich]}" ]] && CONFIG_CACHE["with_mpich"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MPI[with_openmpi]}" ]] && CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MPI[with_intelmpi]}" ]] && CONFIG_CACHE["with_intelmpi"]="__INSTALL__" + ;; + no) + [[ -z "${USER_EXPLICIT_MPI[with_mpich]}" ]] && CONFIG_CACHE["with_mpich"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MPI[with_openmpi]}" ]] && CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MPI[with_intelmpi]}" ]] && CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" + ;; + esac + fi + + # Apply math mode settings (with output for user feedback) + local math_mode="${CONFIG_CACHE[MATH_MODE]}" + if [[ -n "$math_mode" ]]; then + if command -v ui_info &>/dev/null; then + ui_info "🧮 Configuring Math mode: $math_mode" + else + echo "Applying Math mode: $math_mode" fi + case "$math_mode" in + mkl) + [[ -z "${USER_EXPLICIT_MATH[with_mkl]}" ]] && CONFIG_CACHE["with_mkl"]="__SYSTEM__" + [[ -z "${USER_EXPLICIT_MATH[with_aocl]}" ]] && CONFIG_CACHE["with_aocl"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MATH[with_openblas]}" ]] && CONFIG_CACHE["with_openblas"]="__DONTUSE__" + # MKL provides FFTW and ScaLAPACK, so disable them (original logic) + [[ -z "${USER_EXPLICIT_MATH[with_fftw]}" ]] && CONFIG_CACHE["with_fftw"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MATH[with_scalapack]}" ]] && CONFIG_CACHE["with_scalapack"]="__DONTUSE__" + ;; + aocl) + [[ -z "${USER_EXPLICIT_MATH[with_mkl]}" ]] && CONFIG_CACHE["with_mkl"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MATH[with_aocl]}" ]] && CONFIG_CACHE["with_aocl"]="__SYSTEM__" + [[ -z "${USER_EXPLICIT_MATH[with_openblas]}" ]] && CONFIG_CACHE["with_openblas"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MATH[with_fftw]}" ]] && CONFIG_CACHE["with_fftw"]="__SYSTEM__" + [[ -z "${USER_EXPLICIT_MATH[with_scalapack]}" ]] && CONFIG_CACHE["with_scalapack"]="__SYSTEM__" + ;; + openblas) + [[ -z "${USER_EXPLICIT_MATH[with_mkl]}" ]] && CONFIG_CACHE["with_mkl"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MATH[with_aocl]}" ]] && CONFIG_CACHE["with_aocl"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MATH[with_openblas]}" ]] && CONFIG_CACHE["with_openblas"]="__INSTALL__" + ;; + cray) + [[ -z "${USER_EXPLICIT_MATH[with_mkl]}" ]] && CONFIG_CACHE["with_mkl"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MATH[with_aocl]}" ]] && CONFIG_CACHE["with_aocl"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MATH[with_openblas]}" ]] && CONFIG_CACHE["with_openblas"]="__DONTUSE__" + ;; + esac + fi - return 0 + return 0 } diff --git a/toolchain/scripts/lib/config_validator.sh b/toolchain/scripts/lib/config_validator.sh index 5064637f2b3..783935fefba 100644 --- a/toolchain/scripts/lib/config_validator.sh +++ b/toolchain/scripts/lib/config_validator.sh @@ -18,530 +18,530 @@ VALIDATION_INITIALIZED=false # Initialize configuration validator # Usage: config_validator_init config_validator_init() { - if [[ "$VALIDATION_INITIALIZED" == "true" ]]; then - return 0 - fi - - VALIDATION_ERRORS=() - VALIDATION_WARNINGS=() - VALIDATION_ERROR_GROUPS=() - VALIDATION_WARNING_GROUPS=() - VALIDATION_INITIALIZED=true - + if [[ "$VALIDATION_INITIALIZED" == "true" ]]; then return 0 + fi + + VALIDATION_ERRORS=() + VALIDATION_WARNINGS=() + VALIDATION_ERROR_GROUPS=() + VALIDATION_WARNING_GROUPS=() + VALIDATION_INITIALIZED=true + + return 0 } # Add validation error # Usage: add_validation_error "error message" add_validation_error() { - local message="$1" - VALIDATION_ERRORS+=("ERROR: $message") + local message="$1" + VALIDATION_ERRORS+=("ERROR: $message") } # Add validation warning # Usage: add_validation_warning "warning message" add_validation_warning() { - local message="$1" - VALIDATION_WARNINGS+=("WARNING: $message") + local message="$1" + VALIDATION_WARNINGS+=("WARNING: $message") } # Start a new error group (represents one logical error) # Usage: start_error_group "group_name" start_error_group() { - local group_name="$1" - VALIDATION_ERROR_GROUPS+=("$group_name") + local group_name="$1" + VALIDATION_ERROR_GROUPS+=("$group_name") } # Start a new warning group (represents one logical warning) # Usage: start_warning_group "group_name" start_warning_group() { - local group_name="$1" - VALIDATION_WARNING_GROUPS+=("$group_name") + local group_name="$1" + VALIDATION_WARNING_GROUPS+=("$group_name") } # Add validation error group (complete error with all details) # Usage: add_validation_error_group "group_name" "line1" "line2" ... add_validation_error_group() { - local group_name="$1" - shift - - # Add the group to track unique errors - VALIDATION_ERROR_GROUPS+=("$group_name") - - # Add all error lines - for line in "$@"; do - VALIDATION_ERRORS+=("ERROR: $line") - done + local group_name="$1" + shift + + # Add the group to track unique errors + VALIDATION_ERROR_GROUPS+=("$group_name") + + # Add all error lines + for line in "$@"; do + VALIDATION_ERRORS+=("ERROR: $line") + done } # Add validation warning group (complete warning with all details) # Usage: add_validation_warning_group "group_name" "line1" "line2" ... add_validation_warning_group() { - local group_name="$1" - shift - - # Add the group to track unique warnings - VALIDATION_WARNING_GROUPS+=("$group_name") - - # Add all warning lines - for line in "$@"; do - VALIDATION_WARNINGS+=("WARNING: $line") - done + local group_name="$1" + shift + + # Add the group to track unique warnings + VALIDATION_WARNING_GROUPS+=("$group_name") + + # Add all warning lines + for line in "$@"; do + VALIDATION_WARNINGS+=("WARNING: $line") + done } # Add validation info (for successful validations) # Usage: add_validation_info "info message" add_validation_info() { - local message="$1" - # Info messages are displayed immediately during validation - echo "INFO: $message" + local message="$1" + # Info messages are displayed immediately during validation + echo "INFO: $message" } # Check for conflicting math libraries # Usage: validate_math_libraries validate_math_libraries() { - local math_libs_enabled=0 - local enabled_libs=() - - # Check which math libraries are enabled - for lib in mkl aocl openblas; do - if [[ "${CONFIG_CACHE[with_${lib}]}" == "__INSTALL__" || "${CONFIG_CACHE[with_${lib}]}" == "__SYSTEM__" ]]; then - math_libs_enabled=$((math_libs_enabled + 1)) - enabled_libs+=("$lib") - fi - done - - # Validate math library configuration - if [[ $math_libs_enabled -gt 1 ]]; then - add_validation_error "Multiple math libraries enabled: ${enabled_libs[*]}. Only one should be active." - elif [[ $math_libs_enabled -eq 0 ]]; then - add_validation_warning "No math library enabled. This may cause compilation issues." + local math_libs_enabled=0 + local enabled_libs=() + + # Check which math libraries are enabled + for lib in mkl aocl openblas; do + if [[ "${CONFIG_CACHE[with_${lib}]}" == "__INSTALL__" || "${CONFIG_CACHE[with_${lib}]}" == "__SYSTEM__" ]]; then + math_libs_enabled=$((math_libs_enabled + 1)) + enabled_libs+=("$lib") fi - - # Check MKL-specific conflicts - if [[ "${CONFIG_CACHE[with_mkl]}" == "__SYSTEM__" || "${CONFIG_CACHE[with_mkl]}" == "__INSTALL__" ]]; then - if [[ "${CONFIG_CACHE[with_fftw]}" == "__INSTALL__" ]]; then - add_validation_warning "MKL includes FFTW interface. Consider setting FFTW to __DONTUSE__ or __SYSTEM__." - fi - if [[ "${CONFIG_CACHE[with_scalapack]}" == "__INSTALL__" ]]; then - add_validation_warning "MKL includes ScaLAPACK. Consider setting ScaLAPACK to __DONTUSE__ or __SYSTEM__." - fi + done + + # Validate math library configuration + if [[ $math_libs_enabled -gt 1 ]]; then + add_validation_error "Multiple math libraries enabled: ${enabled_libs[*]}. Only one should be active." + elif [[ $math_libs_enabled -eq 0 ]]; then + add_validation_warning "No math library enabled. This may cause compilation issues." + fi + + # Check MKL-specific conflicts + if [[ "${CONFIG_CACHE[with_mkl]}" == "__SYSTEM__" || "${CONFIG_CACHE[with_mkl]}" == "__INSTALL__" ]]; then + if [[ "${CONFIG_CACHE[with_fftw]}" == "__INSTALL__" ]]; then + add_validation_warning "MKL includes FFTW interface. Consider setting FFTW to __DONTUSE__ or __SYSTEM__." + fi + if [[ "${CONFIG_CACHE[with_scalapack]}" == "__INSTALL__" ]]; then + add_validation_warning "MKL includes ScaLAPACK. Consider setting ScaLAPACK to __DONTUSE__ or __SYSTEM__." fi + fi } # Check for conflicting MPI implementations # Usage: validate_mpi_implementations validate_mpi_implementations() { - local mpi_libs_enabled=0 - local enabled_mpis=() - - # Check which MPI implementations are enabled - for mpi in mpich openmpi intelmpi; do - if [[ "${CONFIG_CACHE[with_${mpi}]}" == "__INSTALL__" || "${CONFIG_CACHE[with_${mpi}]}" == "__SYSTEM__" ]]; then - mpi_libs_enabled=$((mpi_libs_enabled + 1)) - enabled_mpis+=("$mpi") - fi - done - - # Validate MPI configuration - if [[ $mpi_libs_enabled -gt 1 ]]; then - add_validation_error "Multiple MPI implementations enabled: ${enabled_mpis[*]}. Only one should be active." - elif [[ $mpi_libs_enabled -eq 0 ]]; then - add_validation_warning "No MPI implementation enabled. This may limit parallel functionality." + local mpi_libs_enabled=0 + local enabled_mpis=() + + # Check which MPI implementations are enabled + for mpi in mpich openmpi intelmpi; do + if [[ "${CONFIG_CACHE[with_${mpi}]}" == "__INSTALL__" || "${CONFIG_CACHE[with_${mpi}]}" == "__SYSTEM__" ]]; then + mpi_libs_enabled=$((mpi_libs_enabled + 1)) + enabled_mpis+=("$mpi") fi + done + + # Validate MPI configuration + if [[ $mpi_libs_enabled -gt 1 ]]; then + add_validation_error "Multiple MPI implementations enabled: ${enabled_mpis[*]}. Only one should be active." + elif [[ $mpi_libs_enabled -eq 0 ]]; then + add_validation_warning "No MPI implementation enabled. This may limit parallel functionality." + fi } # Check for compiler consistency # Usage: validate_compiler_consistency validate_compiler_consistency() { - local compilers_enabled=0 - local enabled_compilers=() - - # Check which compilers are enabled - for compiler in gcc intel amd; do - if [[ "${CONFIG_CACHE[with_${compiler}]}" == "__INSTALL__" || "${CONFIG_CACHE[with_${compiler}]}" == "__SYSTEM__" ]]; then - compilers_enabled=$((compilers_enabled + 1)) - enabled_compilers+=("$compiler") - fi - done - - # Validate compiler configuration - if [[ $compilers_enabled -gt 1 ]]; then - add_validation_warning "Multiple compilers enabled: ${enabled_compilers[*]}. This may cause compatibility issues." - elif [[ $compilers_enabled -eq 0 ]]; then - add_validation_error "No compiler enabled. At least one compiler must be available." + local compilers_enabled=0 + local enabled_compilers=() + + # Check which compilers are enabled + for compiler in gcc intel amd; do + if [[ "${CONFIG_CACHE[with_${compiler}]}" == "__INSTALL__" || "${CONFIG_CACHE[with_${compiler}]}" == "__SYSTEM__" ]]; then + compilers_enabled=$((compilers_enabled + 1)) + enabled_compilers+=("$compiler") fi - - # Check Intel-specific dependencies - if [[ "${CONFIG_CACHE[with_intel]}" == "__SYSTEM__" || "${CONFIG_CACHE[with_intel]}" == "__INSTALL__" ]]; then - if [[ "${CONFIG_CACHE[with_mkl]}" == "__DONTUSE__" ]]; then - add_validation_warning "Intel compiler is enabled but MKL is disabled. Consider enabling MKL for optimal performance." - fi - if [[ "${CONFIG_CACHE[with_intelmpi]}" == "__DONTUSE__" ]]; then - add_validation_warning "Intel compiler is enabled but Intel MPI is disabled. Consider using Intel MPI for better integration." - fi + done + + # Validate compiler configuration + if [[ $compilers_enabled -gt 1 ]]; then + add_validation_warning "Multiple compilers enabled: ${enabled_compilers[*]}. This may cause compatibility issues." + elif [[ $compilers_enabled -eq 0 ]]; then + add_validation_error "No compiler enabled. At least one compiler must be available." + fi + + # Check Intel-specific dependencies + if [[ "${CONFIG_CACHE[with_intel]}" == "__SYSTEM__" || "${CONFIG_CACHE[with_intel]}" == "__INSTALL__" ]]; then + if [[ "${CONFIG_CACHE[with_mkl]}" == "__DONTUSE__" ]]; then + add_validation_warning "Intel compiler is enabled but MKL is disabled. Consider enabling MKL for optimal performance." + fi + if [[ "${CONFIG_CACHE[with_intelmpi]}" == "__DONTUSE__" ]]; then + add_validation_warning "Intel compiler is enabled but Intel MPI is disabled. Consider using Intel MPI for better integration." fi + fi } # Check system requirements # Usage: validate_system_requirements validate_system_requirements() { - # ABACUS itself and some dependencies require cmake. - # Check cmake requirement based on configuration (mirrors original L768-772) - if [[ "${CONFIG_CACHE[with_cmake]}" == "__DONTUSE__" ]]; then - add_validation_error_group "cmake_required" \ - "CMake is required for ABACUS and some dependencies. Please enable it." \ - "" \ - "SOLUTION: Use '--with-cmake=install' to automatically install CMake:" \ - " ./install_abacus_toolchain_new.sh --with-cmake=install [other options]" + # ABACUS itself and some dependencies require cmake. + # Check cmake requirement based on configuration (mirrors original L768-772) + if [[ "${CONFIG_CACHE[with_cmake]}" == "__DONTUSE__" ]]; then + add_validation_error_group "cmake_required" \ + "CMake is required for ABACUS and some dependencies. Please enable it." \ + "" \ + "SOLUTION: Use '--with-cmake=install' to automatically install CMake:" \ + " ./install_abacus_toolchain_new.sh --with-cmake=install [other options]" + return + fi + + # Check for required system tools (excluding cmake which is handled above) + local required_tools=("make" "git" "wget" "tar" "gzip") + local missing_tools=() + + # Only check for system cmake if using system cmake + if [[ "${CONFIG_CACHE[with_cmake]}" == "__SYSTEM__" ]]; then + if ! command -v "cmake" &>/dev/null; then + missing_tools+=("cmake") + else + # Check cmake version if it exists + local cmake_min_version="3.16" + local cmake_version=$(cmake --version 2>/dev/null | head -n 1 | awk '{print $3}') + + if [[ -z "$cmake_version" ]]; then + add_validation_error "Failed to determine CMake version" + add_validation_error "This usually indicates a corrupted or non-standard CMake installation." + add_validation_error "" + add_validation_error "SOLUTION: Use '--with-cmake=install' to install a known-good CMake version:" + add_validation_error " ./install_abacus_toolchain_new.sh --with-cmake=install [other options]" + add_validation_error "" + add_validation_error "This will install CMake ${cmake_ver:-3.29.6} with proper version information." + return + fi + + # Extract major and minor version numbers for comparison + local cmake_major=$(echo "$cmake_version" | awk -F. '{print $1}') + local cmake_minor=$(echo "$cmake_version" | awk -F. '{print $2}') + local min_major=$(echo "$cmake_min_version" | awk -F. '{print $1}') + local min_minor=$(echo "$cmake_min_version" | awk -F. '{print $2}') + + # Validate version format + if ! [[ "$cmake_major" =~ ^[0-9]+$ ]] || ! [[ "$cmake_minor" =~ ^[0-9]+$ ]]; then + add_validation_error "Unable to parse CMake version from: $cmake_version" + add_validation_error "Expected format: X.Y.Z (e.g., 3.29.6), but got: $cmake_version" + add_validation_error "" + add_validation_error "SOLUTION: Use '--with-cmake=install' to install a standard CMake version:" + add_validation_error " ./install_abacus_toolchain_new.sh --with-cmake=install [other options]" + add_validation_error "" + add_validation_error "This will install CMake ${cmake_ver:-3.29.6} with standard version format." + return + fi + + # Compare versions (major.minor comparison) + local version_too_old=false + if [[ "$cmake_major" -lt "$min_major" ]]; then + version_too_old=true + elif [[ "$cmake_major" -eq "$min_major" ]] && [[ "$cmake_minor" -lt "$min_minor" ]]; then + version_too_old=true + fi + + if [[ "$version_too_old" == "true" ]]; then + add_validation_error "CMake version $cmake_version is too old" + add_validation_error "Minimum required: CMake $cmake_min_version or newer (ABACUS requirement)" + add_validation_error "" + add_validation_error_group "cmake_outdated" \ + "Your system CMake is outdated and may cause build failures." \ + "" \ + "SOLUTION: Use '--with-cmake=install' to install a modern CMake version:" \ + " ./install_abacus_toolchain_new.sh --with-cmake=install [other options]" \ + "" \ + "This will install CMake ${cmake_ver:-3.29.6} (>= $cmake_min_version) with full feature support." return + fi + + # Success - add informational message + add_validation_info "System CMake validated: version $cmake_version (>= $cmake_min_version required)" fi - - # Check for required system tools (excluding cmake which is handled above) - local required_tools=("make" "git" "wget" "tar" "gzip") - local missing_tools=() - - # Only check for system cmake if using system cmake - if [[ "${CONFIG_CACHE[with_cmake]}" == "__SYSTEM__" ]]; then - if ! command -v "cmake" &> /dev/null; then - missing_tools+=("cmake") - else - # Check cmake version if it exists - local cmake_min_version="3.16" - local cmake_version=$(cmake --version 2>/dev/null | head -n 1 | awk '{print $3}') - - if [[ -z "$cmake_version" ]]; then - add_validation_error "Failed to determine CMake version" - add_validation_error "This usually indicates a corrupted or non-standard CMake installation." - add_validation_error "" - add_validation_error "SOLUTION: Use '--with-cmake=install' to install a known-good CMake version:" - add_validation_error " ./install_abacus_toolchain_new.sh --with-cmake=install [other options]" - add_validation_error "" - add_validation_error "This will install CMake ${cmake_ver:-3.29.6} with proper version information." - return - fi - - # Extract major and minor version numbers for comparison - local cmake_major=$(echo "$cmake_version" | awk -F. '{print $1}') - local cmake_minor=$(echo "$cmake_version" | awk -F. '{print $2}') - local min_major=$(echo "$cmake_min_version" | awk -F. '{print $1}') - local min_minor=$(echo "$cmake_min_version" | awk -F. '{print $2}') - - # Validate version format - if ! [[ "$cmake_major" =~ ^[0-9]+$ ]] || ! [[ "$cmake_minor" =~ ^[0-9]+$ ]]; then - add_validation_error "Unable to parse CMake version from: $cmake_version" - add_validation_error "Expected format: X.Y.Z (e.g., 3.29.6), but got: $cmake_version" - add_validation_error "" - add_validation_error "SOLUTION: Use '--with-cmake=install' to install a standard CMake version:" - add_validation_error " ./install_abacus_toolchain_new.sh --with-cmake=install [other options]" - add_validation_error "" - add_validation_error "This will install CMake ${cmake_ver:-3.29.6} with standard version format." - return - fi - - # Compare versions (major.minor comparison) - local version_too_old=false - if [[ "$cmake_major" -lt "$min_major" ]]; then - version_too_old=true - elif [[ "$cmake_major" -eq "$min_major" ]] && [[ "$cmake_minor" -lt "$min_minor" ]]; then - version_too_old=true - fi - - if [[ "$version_too_old" == "true" ]]; then - add_validation_error "CMake version $cmake_version is too old" - add_validation_error "Minimum required: CMake $cmake_min_version or newer (ABACUS requirement)" - add_validation_error "" - add_validation_error_group "cmake_outdated" \ - "Your system CMake is outdated and may cause build failures." \ - "" \ - "SOLUTION: Use '--with-cmake=install' to install a modern CMake version:" \ - " ./install_abacus_toolchain_new.sh --with-cmake=install [other options]" \ - "" \ - "This will install CMake ${cmake_ver:-3.29.6} (>= $cmake_min_version) with full feature support." - return - fi - - # Success - add informational message - add_validation_info "System CMake validated: version $cmake_version (>= $cmake_min_version required)" - fi + fi + + for tool in "${required_tools[@]}"; do + if ! command -v "$tool" &>/dev/null; then + missing_tools+=("$tool") fi - - for tool in "${required_tools[@]}"; do - if ! command -v "$tool" &> /dev/null; then - missing_tools+=("$tool") + done + + if [[ ${#missing_tools[@]} -gt 0 ]]; then + # Check if cmake is in the missing tools and provide specific guidance + if [[ " ${missing_tools[*]} " =~ " cmake " ]]; then + add_validation_error_group "cmake_missing" \ + "CMake is not installed on your system" \ + "CMake is required for building ABACUS and its dependencies." \ + "" \ + "SOLUTION: Use '--with-cmake=install' to automatically install CMake:" \ + " ./install_abacus_toolchain_new.sh --with-cmake=install [other options]" \ + "" \ + "This will install CMake ${cmake_ver:-3.29.6} with full feature support." + + # Remove cmake from missing_tools to avoid duplicate error messages + local filtered_tools=() + for tool in "${missing_tools[@]}"; do + if [[ "$tool" != "cmake" ]]; then + filtered_tools+=("$tool") fi - done - + done + missing_tools=("${filtered_tools[@]}") + fi + + # Report other missing tools if any if [[ ${#missing_tools[@]} -gt 0 ]]; then - # Check if cmake is in the missing tools and provide specific guidance - if [[ " ${missing_tools[*]} " =~ " cmake " ]]; then - add_validation_error_group "cmake_missing" \ - "CMake is not installed on your system" \ - "CMake is required for building ABACUS and its dependencies." \ - "" \ - "SOLUTION: Use '--with-cmake=install' to automatically install CMake:" \ - " ./install_abacus_toolchain_new.sh --with-cmake=install [other options]" \ - "" \ - "This will install CMake ${cmake_ver:-3.29.6} with full feature support." - - # Remove cmake from missing_tools to avoid duplicate error messages - local filtered_tools=() - for tool in "${missing_tools[@]}"; do - if [[ "$tool" != "cmake" ]]; then - filtered_tools+=("$tool") - fi - done - missing_tools=("${filtered_tools[@]}") - fi - - # Report other missing tools if any - if [[ ${#missing_tools[@]} -gt 0 ]]; then - add_validation_error "Missing required system tools: ${missing_tools[*]}" - fi + add_validation_error "Missing required system tools: ${missing_tools[*]}" fi - - # Check for development packages (common names) - local dev_packages=("build-essential" "gcc" "g++" "gfortran") - local missing_dev=() - - for pkg in "${dev_packages[@]}"; do - if ! command -v "$pkg" &> /dev/null && ! dpkg -l | grep -q "$pkg" 2>/dev/null; then - missing_dev+=("$pkg") - fi - done - - if [[ ${#missing_dev[@]} -gt 0 ]]; then - add_validation_warning "Potentially missing development packages: ${missing_dev[*]}" + fi + + # Check for development packages (common names) + local dev_packages=("build-essential" "gcc" "g++" "gfortran") + local missing_dev=() + + for pkg in "${dev_packages[@]}"; do + if ! command -v "$pkg" &>/dev/null && ! dpkg -l | grep -q "$pkg" 2>/dev/null; then + missing_dev+=("$pkg") fi - - # Check GCC version consistency and minimum requirements - # This mirrors the logic from original install_abacus_toolchain.sh L636-667 - if [[ "${CONFIG_CACHE[with_gcc]}" != "__INSTALL__" ]]; then - local gcc_min_version=5 - - # Check if GCC tools are available - if ! command -v gcc &> /dev/null || ! command -v g++ &> /dev/null || ! command -v gfortran &> /dev/null; then - local missing_tools=() - ! command -v gcc &> /dev/null && missing_tools+=("gcc") - ! command -v g++ &> /dev/null && missing_tools+=("g++") - ! command -v gfortran &> /dev/null && missing_tools+=("gfortran") - - add_validation_error_group "gcc_incomplete" \ - "System GCC toolchain incomplete. Missing: ${missing_tools[*]}" \ - "" \ - "SOLUTION: Use '--with-gcc=install' to automatically download and install a complete GCC toolchain:" \ - " ./install_abacus_toolchain_new.sh --with-gcc=install [other options]" \ - "" \ - "This will install GCC ${gcc_ver:-13.2.0} with all required components (gcc, g++, gfortran)." - return - fi - - # Get versions of GCC components - local gcc_version=$(gcc --version 2>/dev/null | head -n 1 | awk '{print $NF}') - local gxx_version=$(g++ --version 2>/dev/null | head -n 1 | awk '{print $NF}') - local gfc_version=$(gfortran --version 2>/dev/null | head -n 1 | awk '{print $NF}') - - # Check if version extraction was successful - if [[ -z "$gcc_version" || -z "$gxx_version" || -z "$gfc_version" ]]; then - local failed_tools=() - [[ -z "$gcc_version" ]] && failed_tools+=("gcc") - [[ -z "$gxx_version" ]] && failed_tools+=("g++") - [[ -z "$gfc_version" ]] && failed_tools+=("gfortran") - - add_validation_error_group "gcc_version_failed" \ - "Failed to determine GCC toolchain versions for: ${failed_tools[*]}" \ - "This usually indicates corrupted or non-standard GCC installation." \ - "" \ - "SOLUTION: Use '--with-gcc=install' to install a known-good GCC version:" \ - " ./install_abacus_toolchain_new.sh --with-gcc=install [other options]" \ - "" \ - "This will install GCC ${gcc_ver:-13.2.0} with proper version information." - return - fi - - # Check version consistency - if [[ "$gcc_version" != "$gxx_version" ]] || [[ "$gcc_version" != "$gfc_version" ]]; then - add_validation_error_group "gcc_version_inconsistent" \ - "GCC toolchain versions are inconsistent:" \ - " gcc: $gcc_version" \ - " g++: $gxx_version" \ - " gfortran: $gfc_version" \ - "" \ - "All GCC components must have the same version for proper compilation." \ - "SOLUTION: Use '--with-gcc=install' to install a consistent GCC toolchain:" \ - " ./install_abacus_toolchain_new.sh --with-gcc=install [other options]" \ - "" \ - "This will install GCC ${gcc_ver:-13.2.0} with all components at the same version." - return - fi - - # Extract major version number - local gcc_major=$(echo "$gcc_version" | awk -F. '{print $1}') - - # Validate major version is numeric and meets minimum requirement - if ! [[ "$gcc_major" =~ ^[0-9]+$ ]]; then - add_validation_error_group "gcc_version_parse_failed" \ - "Unable to parse GCC major version from: $gcc_version" \ - "Expected format: X.Y.Z (e.g., 13.2.0), but got: $gcc_version" \ - "" \ - "SOLUTION: Use '--with-gcc=install' to install a standard GCC version:" \ - " ./install_abacus_toolchain_new.sh --with-gcc=install [other options]" \ - "" \ - "This will install GCC ${gcc_ver:-13.2.0} with standard version format." - return - fi - - if [[ "$gcc_major" -lt "$gcc_min_version" ]]; then - add_validation_error_group "gcc_version_too_old" \ - "GCC version $gcc_version is too old (major version: $gcc_major)" \ - "Minimum required: GCC $gcc_min_version.x or newer (ABACUS requirement)" \ - "" \ - "Your system GCC is outdated and may cause compilation failures." \ - "" \ - "SOLUTION: Use '--with-gcc=install' to install a modern GCC version:" \ - " ./install_abacus_toolchain_new.sh --with-gcc=install [other options]" \ - "" \ - "This will install GCC ${gcc_ver:-13.2.0} (>= $gcc_min_version.x) with full C++17/C++20 support." - return - fi + done - local cuda_major="" - if command -v nvidia-smi &> /dev/null; then - local nvidia_banner=$(nvidia-smi 2>/dev/null | head -n 3 | tr '\n' ' ') - local cuda_version=$(echo "$nvidia_banner" | sed -n 's/.*CUDA Version:[[:space:]]*\([0-9.]*\).*/\1/p') - cuda_major=$(echo "$cuda_version" | awk -F. '{print $1}') - fi - if [[ "$gcc_major" -ge 14 ]] && [[ -n "$cuda_major" ]] && [[ "$cuda_major" =~ ^[0-9]+$ ]] && [[ "$cuda_major" -lt 13 ]]; then - add_validation_warning_group "gcc_cuda_compat_risk" \ - "Potential GCC/CUDA incompatibility risk detected:" \ - " gcc: $gcc_version (>= 14)" \ - " cuda: $cuda_major.x (< 13, from nvidia-smi)" \ - "" \ - "This combination may cause CUDA-related compilation failures." \ - "Consider upgrading CUDA (>= 13) or using a compatible GCC toolchain." - fi - - # Success - add informational message - add_validation_info "System GCC toolchain validated: version $gcc_version (>= $gcc_min_version.x required)" + if [[ ${#missing_dev[@]} -gt 0 ]]; then + add_validation_warning "Potentially missing development packages: ${missing_dev[*]}" + fi + + # Check GCC version consistency and minimum requirements + # This mirrors the logic from original install_abacus_toolchain.sh L636-667 + if [[ "${CONFIG_CACHE[with_gcc]}" != "__INSTALL__" ]]; then + local gcc_min_version=5 + + # Check if GCC tools are available + if ! command -v gcc &>/dev/null || ! command -v g++ &>/dev/null || ! command -v gfortran &>/dev/null; then + local missing_tools=() + ! command -v gcc &>/dev/null && missing_tools+=("gcc") + ! command -v g++ &>/dev/null && missing_tools+=("g++") + ! command -v gfortran &>/dev/null && missing_tools+=("gfortran") + + add_validation_error_group "gcc_incomplete" \ + "System GCC toolchain incomplete. Missing: ${missing_tools[*]}" \ + "" \ + "SOLUTION: Use '--with-gcc=install' to automatically download and install a complete GCC toolchain:" \ + " ./install_abacus_toolchain_new.sh --with-gcc=install [other options]" \ + "" \ + "This will install GCC ${gcc_ver:-13.2.0} with all required components (gcc, g++, gfortran)." + return + fi + + # Get versions of GCC components + local gcc_version=$(gcc --version 2>/dev/null | head -n 1 | awk '{print $NF}') + local gxx_version=$(g++ --version 2>/dev/null | head -n 1 | awk '{print $NF}') + local gfc_version=$(gfortran --version 2>/dev/null | head -n 1 | awk '{print $NF}') + + # Check if version extraction was successful + if [[ -z "$gcc_version" || -z "$gxx_version" || -z "$gfc_version" ]]; then + local failed_tools=() + [[ -z "$gcc_version" ]] && failed_tools+=("gcc") + [[ -z "$gxx_version" ]] && failed_tools+=("g++") + [[ -z "$gfc_version" ]] && failed_tools+=("gfortran") + + add_validation_error_group "gcc_version_failed" \ + "Failed to determine GCC toolchain versions for: ${failed_tools[*]}" \ + "This usually indicates corrupted or non-standard GCC installation." \ + "" \ + "SOLUTION: Use '--with-gcc=install' to install a known-good GCC version:" \ + " ./install_abacus_toolchain_new.sh --with-gcc=install [other options]" \ + "" \ + "This will install GCC ${gcc_ver:-13.2.0} with proper version information." + return + fi + + # Check version consistency + if [[ "$gcc_version" != "$gxx_version" ]] || [[ "$gcc_version" != "$gfc_version" ]]; then + add_validation_error_group "gcc_version_inconsistent" \ + "GCC toolchain versions are inconsistent:" \ + " gcc: $gcc_version" \ + " g++: $gxx_version" \ + " gfortran: $gfc_version" \ + "" \ + "All GCC components must have the same version for proper compilation." \ + "SOLUTION: Use '--with-gcc=install' to install a consistent GCC toolchain:" \ + " ./install_abacus_toolchain_new.sh --with-gcc=install [other options]" \ + "" \ + "This will install GCC ${gcc_ver:-13.2.0} with all components at the same version." + return + fi + + # Extract major version number + local gcc_major=$(echo "$gcc_version" | awk -F. '{print $1}') + + # Validate major version is numeric and meets minimum requirement + if ! [[ "$gcc_major" =~ ^[0-9]+$ ]]; then + add_validation_error_group "gcc_version_parse_failed" \ + "Unable to parse GCC major version from: $gcc_version" \ + "Expected format: X.Y.Z (e.g., 13.2.0), but got: $gcc_version" \ + "" \ + "SOLUTION: Use '--with-gcc=install' to install a standard GCC version:" \ + " ./install_abacus_toolchain_new.sh --with-gcc=install [other options]" \ + "" \ + "This will install GCC ${gcc_ver:-13.2.0} with standard version format." + return + fi + + if [[ "$gcc_major" -lt "$gcc_min_version" ]]; then + add_validation_error_group "gcc_version_too_old" \ + "GCC version $gcc_version is too old (major version: $gcc_major)" \ + "Minimum required: GCC $gcc_min_version.x or newer (ABACUS requirement)" \ + "" \ + "Your system GCC is outdated and may cause compilation failures." \ + "" \ + "SOLUTION: Use '--with-gcc=install' to install a modern GCC version:" \ + " ./install_abacus_toolchain_new.sh --with-gcc=install [other options]" \ + "" \ + "This will install GCC ${gcc_ver:-13.2.0} (>= $gcc_min_version.x) with full C++17/C++20 support." + return + fi + + local cuda_major="" + if command -v nvidia-smi &>/dev/null; then + local nvidia_banner=$(nvidia-smi 2>/dev/null | head -n 3 | tr '\n' ' ') + local cuda_version=$(echo "$nvidia_banner" | sed -n 's/.*CUDA Version:[[:space:]]*\([0-9.]*\).*/\1/p') + cuda_major=$(echo "$cuda_version" | awk -F. '{print $1}') + fi + if [[ "$gcc_major" -ge 14 ]] && [[ -n "$cuda_major" ]] && [[ "$cuda_major" =~ ^[0-9]+$ ]] && [[ "$cuda_major" -lt 13 ]]; then + add_validation_warning_group "gcc_cuda_compat_risk" \ + "Potential GCC/CUDA incompatibility risk detected:" \ + " gcc: $gcc_version (>= 14)" \ + " cuda: $cuda_major.x (< 13, from nvidia-smi)" \ + "" \ + "This combination may cause CUDA-related compilation failures." \ + "Consider upgrading CUDA (>= 13) or using a compatible GCC toolchain." fi + + # Success - add informational message + add_validation_info "System GCC toolchain validated: version $gcc_version (>= $gcc_min_version.x required)" + fi } # Check for logical inconsistencies # Usage: validate_logical_consistency validate_logical_consistency() { - # Check if ELPA is enabled without ScaLAPACK - if [[ "${CONFIG_CACHE[with_elpa]}" == "__INSTALL__" || "${CONFIG_CACHE[with_elpa]}" == "__SYSTEM__" ]]; then - if [[ "${CONFIG_CACHE[with_scalapack]}" == "__DONTUSE__" ]]; then - # Check if MKL is enabled (MKL provides ScaLAPACK functionality) - if [[ "${CONFIG_CACHE[MATH_MODE]}" == "mkl" || "${CONFIG_CACHE[with_mkl]}" == "__SYSTEM__" || "${CONFIG_CACHE[with_mkl]}" == "__INSTALL__" ]]; then - # MKL provides ScaLAPACK, so this is acceptable - : - else - add_validation_error "ELPA requires ScaLAPACK but ScaLAPACK is disabled." - fi - fi + # Check if ELPA is enabled without ScaLAPACK + if [[ "${CONFIG_CACHE[with_elpa]}" == "__INSTALL__" || "${CONFIG_CACHE[with_elpa]}" == "__SYSTEM__" ]]; then + if [[ "${CONFIG_CACHE[with_scalapack]}" == "__DONTUSE__" ]]; then + # Check if MKL is enabled (MKL provides ScaLAPACK functionality) + if [[ "${CONFIG_CACHE[MATH_MODE]}" == "mkl" || "${CONFIG_CACHE[with_mkl]}" == "__SYSTEM__" || "${CONFIG_CACHE[with_mkl]}" == "__INSTALL__" ]]; then + # MKL provides ScaLAPACK, so this is acceptable + : + else + add_validation_error "ELPA requires ScaLAPACK but ScaLAPACK is disabled." + fi fi - - # Check if ScaLAPACK is enabled without MPI - if [[ "${CONFIG_CACHE[with_scalapack]}" == "__INSTALL__" || "${CONFIG_CACHE[with_scalapack]}" == "__SYSTEM__" ]]; then - local mpi_enabled=false - for mpi in mpich openmpi intelmpi; do - if [[ "${CONFIG_CACHE[with_${mpi}]}" == "__INSTALL__" || "${CONFIG_CACHE[with_${mpi}]}" == "__SYSTEM__" ]]; then - mpi_enabled=true - break - fi - done - - if [[ "$mpi_enabled" == "false" ]]; then - add_validation_warning "ScaLAPACK is enabled but no MPI implementation is active." - fi + fi + + # Check if ScaLAPACK is enabled without MPI + if [[ "${CONFIG_CACHE[with_scalapack]}" == "__INSTALL__" || "${CONFIG_CACHE[with_scalapack]}" == "__SYSTEM__" ]]; then + local mpi_enabled=false + for mpi in mpich openmpi intelmpi; do + if [[ "${CONFIG_CACHE[with_${mpi}]}" == "__INSTALL__" || "${CONFIG_CACHE[with_${mpi}]}" == "__SYSTEM__" ]]; then + mpi_enabled=true + break + fi + done + + if [[ "$mpi_enabled" == "false" ]]; then + add_validation_warning "ScaLAPACK is enabled but no MPI implementation is active." fi - - # Check for GPU-related inconsistencies - if [[ "${CONFIG_CACHE[GPUVER]}" != "no" ]]; then - if [[ "${CONFIG_CACHE[with_elpa]}" == "__INSTALL__" ]]; then - add_validation_warning "GPU support is enabled. Ensure ELPA is compiled with GPU support." - fi + fi + + # Check for GPU-related inconsistencies + if [[ "${CONFIG_CACHE[GPUVER]}" != "no" ]]; then + if [[ "${CONFIG_CACHE[with_elpa]}" == "__INSTALL__" ]]; then + add_validation_warning "GPU support is enabled. Ensure ELPA is compiled with GPU support." fi + fi } # Validate package versions compatibility # Usage: validate_package_versions validate_package_versions() { - # This is a placeholder for version compatibility checks - # In a real implementation, you would check for known incompatible version combinations - - # Example: Check for known problematic combinations - if [[ "${CONFIG_CACHE[with_gcc]}" == "__INSTALL__" ]]; then - local gcc_version="${gcc_ver:-unknown}" - if [[ "$gcc_version" == "unknown" ]]; then - add_validation_warning "GCC version not specified. Using default version." - fi + # This is a placeholder for version compatibility checks + # In a real implementation, you would check for known incompatible version combinations + + # Example: Check for known problematic combinations + if [[ "${CONFIG_CACHE[with_gcc]}" == "__INSTALL__" ]]; then + local gcc_version="${gcc_ver:-unknown}" + if [[ "$gcc_version" == "unknown" ]]; then + add_validation_warning "GCC version not specified. Using default version." fi + fi } # Run all validation checks # Usage: validate_configuration validate_configuration() { - config_validator_init - - echo "Running configuration validation..." - - # Run all validation checks - validate_math_libraries - validate_mpi_implementations - validate_compiler_consistency - validate_system_requirements - validate_logical_consistency - validate_package_versions - - # Report results using error groups for accurate counting - local error_groups=${#VALIDATION_ERROR_GROUPS[@]} - local warning_groups=${#VALIDATION_WARNING_GROUPS[@]} - local total_issues=$((error_groups + warning_groups)) - - if [[ ${#VALIDATION_ERRORS[@]} -gt 0 ]]; then - echo "" - echo "Configuration Errors Found:" - echo "==========================" - for error in "${VALIDATION_ERRORS[@]}"; do - echo " $error" - done - fi - - if [[ ${#VALIDATION_WARNINGS[@]} -gt 0 ]]; then - echo "" - echo "Configuration Warnings:" - echo "======================" - for warning in "${VALIDATION_WARNINGS[@]}"; do - echo " $warning" - done - fi - - if [[ $total_issues -eq 0 ]]; then - echo "✓ Configuration validation passed with no issues." - return 0 + config_validator_init + + echo "Running configuration validation..." + + # Run all validation checks + validate_math_libraries + validate_mpi_implementations + validate_compiler_consistency + validate_system_requirements + validate_logical_consistency + validate_package_versions + + # Report results using error groups for accurate counting + local error_groups=${#VALIDATION_ERROR_GROUPS[@]} + local warning_groups=${#VALIDATION_WARNING_GROUPS[@]} + local total_issues=$((error_groups + warning_groups)) + + if [[ ${#VALIDATION_ERRORS[@]} -gt 0 ]]; then + echo "" + echo "Configuration Errors Found:" + echo "==========================" + for error in "${VALIDATION_ERRORS[@]}"; do + echo " $error" + done + fi + + if [[ ${#VALIDATION_WARNINGS[@]} -gt 0 ]]; then + echo "" + echo "Configuration Warnings:" + echo "======================" + for warning in "${VALIDATION_WARNINGS[@]}"; do + echo " $warning" + done + fi + + if [[ $total_issues -eq 0 ]]; then + echo "✓ Configuration validation passed with no issues." + return 0 + else + echo "" + echo "Configuration validation completed with $total_issues issue(s)." + echo " Errors: $error_groups" + echo " Warnings: $warning_groups" + + # Return error code if there are validation errors + if [[ $error_groups -gt 0 ]]; then + return 1 else - echo "" - echo "Configuration validation completed with $total_issues issue(s)." - echo " Errors: $error_groups" - echo " Warnings: $warning_groups" - - # Return error code if there are validation errors - if [[ $error_groups -gt 0 ]]; then - return 1 - else - return 0 - fi + return 0 fi + fi } # Check if validation should be skipped # Usage: should_skip_validation should_skip_validation() { - if [[ "${CONFIG_CACHE[skip_system_checks]}" == "__TRUE__" ]]; then - echo "Skipping configuration validation (--skip-system-checks)" - return 0 - fi - return 1 + if [[ "${CONFIG_CACHE[skip_system_checks]}" == "__TRUE__" ]]; then + echo "Skipping configuration validation (--skip-system-checks)" + return 0 + fi + return 1 } diff --git a/toolchain/scripts/lib/error_handler.sh b/toolchain/scripts/lib/error_handler.sh index 322fb2a4988..c4c329fa2b6 100644 --- a/toolchain/scripts/lib/error_handler.sh +++ b/toolchain/scripts/lib/error_handler.sh @@ -14,122 +14,122 @@ ERROR_HANDLER_INITIALIZED=false # Initialize error handler # Usage: error_handler_init error_handler_init() { - if [[ "$ERROR_HANDLER_INITIALIZED" == "true" ]]; then - return 0 - fi - - # Set up error trapping - set -e - trap 'error_handler ${LINENO}' ERR - - ERROR_HANDLER_INITIALIZED=true + if [[ "$ERROR_HANDLER_INITIALIZED" == "true" ]]; then return 0 + fi + + # Set up error trapping + set -e + trap 'error_handler ${LINENO}' ERR + + ERROR_HANDLER_INITIALIZED=true + return 0 } # Main error handler function # Usage: error_handler line_number [error_code] error_handler() { - local line_number="$1" - local error_code="${2:-$?}" - local script_name="${SCRIPT_NAME:-${BASH_SOURCE[1]}}" - - echo "ERROR: Script failed at line $line_number in $script_name (exit code: $error_code)" >&2 - echo "Command that failed: ${BASH_COMMAND}" >&2 - - # Print stack trace - echo "Call stack:" >&2 - local frame=0 - while caller $frame; do - ((frame++)) - done | while read line func file; do - echo " at $func ($file:$line)" >&2 - done - - exit $error_code + local line_number="$1" + local error_code="${2:-$?}" + local script_name="${SCRIPT_NAME:-${BASH_SOURCE[1]}}" + + echo "ERROR: Script failed at line $line_number in $script_name (exit code: $error_code)" >&2 + echo "Command that failed: ${BASH_COMMAND}" >&2 + + # Print stack trace + echo "Call stack:" >&2 + local frame=0 + while caller $frame; do + ((frame++)) + done | while read line func file; do + echo " at $func ($file:$line)" >&2 + done + + exit $error_code } # Report error with context # Usage: report_error line_number "error message" [context] report_error() { - local line_number="" - local message="" - local context="" - - if [[ $# -gt 1 ]]; then - line_number="$1" - message="$2" - context="${3:-}" - else - message="$1" - fi - - local location="" - if [[ -n "$line_number" ]]; then - location=", line $line_number" - fi - - echo "ERROR: (${SCRIPT_NAME:-$0}${location}) $message" >&2 - if [[ -n "$context" ]]; then - echo "Context: $context" >&2 - fi + local line_number="" + local message="" + local context="" + + if [[ $# -gt 1 ]]; then + line_number="$1" + message="$2" + context="${3:-}" + else + message="$1" + fi + + local location="" + if [[ -n "$line_number" ]]; then + location=", line $line_number" + fi + + echo "ERROR: (${SCRIPT_NAME:-$0}${location}) $message" >&2 + if [[ -n "$context" ]]; then + echo "Context: $context" >&2 + fi } # Report warning with context # Usage: report_warning line_number "warning message" [context] report_warning() { - local line_number="" - local message="" - local context="" - - if [[ $# -gt 1 ]]; then - line_number="$1" - message="$2" - context="${3:-}" - else - message="$1" - fi - - local location="" - if [[ -n "$line_number" ]]; then - location=", line $line_number" - fi - - echo "WARNING: (${SCRIPT_NAME:-$0}${location}) $message" >&2 - if [[ -n "$context" ]]; then - echo "Context: $context" >&2 - fi + local line_number="" + local message="" + local context="" + + if [[ $# -gt 1 ]]; then + line_number="$1" + message="$2" + context="${3:-}" + else + message="$1" + fi + + local location="" + if [[ -n "$line_number" ]]; then + location=", line $line_number" + fi + + echo "WARNING: (${SCRIPT_NAME:-$0}${location}) $message" >&2 + if [[ -n "$context" ]]; then + echo "Context: $context" >&2 + fi } # Enhanced error reporting with error codes # Usage: report_error_enhanced error_code "error message" [context] [line_number] report_error_enhanced() { - local error_code="$1" - local error_message="$2" - local context="${3:-}" - local line_number="${4:-}" - - local location="" - if [[ -n "$line_number" ]]; then - location=", line $line_number" - fi - - echo "ERROR [$error_code]: (${SCRIPT_NAME:-$0}${location}) $error_message" >&2 - if [[ -n "$context" ]]; then - echo "Context: $context" >&2 - fi - - return $error_code + local error_code="$1" + local error_message="$2" + local context="${3:-}" + local line_number="${4:-}" + + local location="" + if [[ -n "$line_number" ]]; then + location=", line $line_number" + fi + + echo "ERROR [$error_code]: (${SCRIPT_NAME:-$0}${location}) $error_message" >&2 + if [[ -n "$context" ]]; then + echo "Context: $context" >&2 + fi + + return $error_code } # Enhanced warning reporting with severity levels # Usage: report_warning_enhanced severity "warning message" [context] report_warning_enhanced() { - local severity="$1" - local warning_message="$2" - local context="${3:-}" - - echo "$severity: (${SCRIPT_NAME:-$0}) $warning_message" >&2 - if [[ -n "$context" ]]; then - echo "Context: $context" >&2 - fi -} \ No newline at end of file + local severity="$1" + local warning_message="$2" + local context="${3:-}" + + echo "$severity: (${SCRIPT_NAME:-$0}) $warning_message" >&2 + if [[ -n "$context" ]]; then + echo "Context: $context" >&2 + fi +} diff --git a/toolchain/scripts/lib/package_manager.sh b/toolchain/scripts/lib/package_manager.sh index 0bdac523a06..bf410e34e23 100644 --- a/toolchain/scripts/lib/package_manager.sh +++ b/toolchain/scripts/lib/package_manager.sh @@ -16,455 +16,454 @@ declare -A PACKAGE_DEPENDENCIES # Initialize package manager # Usage: package_manager_init package_manager_init() { - if [[ "$PACKAGE_MANAGER_INITIALIZED" == "true" ]]; then - return 0 - fi - - # Initialize dependencies - if ! command -v config_manager_init &> /dev/null; then - source "${SCRIPTDIR}/lib/config_manager.sh" - fi - - config_manager_init - - # Define package dependencies - package_manager_define_dependencies - - PACKAGE_MANAGER_INITIALIZED=true + if [[ "$PACKAGE_MANAGER_INITIALIZED" == "true" ]]; then return 0 + fi + + # Initialize dependencies + if ! command -v config_manager_init &>/dev/null; then + source "${SCRIPTDIR}/lib/config_manager.sh" + fi + + config_manager_init + + # Define package dependencies + package_manager_define_dependencies + + PACKAGE_MANAGER_INITIALIZED=true + return 0 } # Define package dependencies # Usage: package_manager_define_dependencies package_manager_define_dependencies() { - # Stage 0: Compilers and Build Tools - PACKAGE_DEPENDENCIES["gcc"]="" - PACKAGE_DEPENDENCIES["intel"]="" - PACKAGE_DEPENDENCIES["amd"]="" - PACKAGE_DEPENDENCIES["cmake"]="" - - # Stage 1: MPI Implementations (depend on compilers) - PACKAGE_DEPENDENCIES["openmpi"]="gcc cmake" - PACKAGE_DEPENDENCIES["mpich"]="gcc cmake" - PACKAGE_DEPENDENCIES["intelmpi"]="intel" - - # Stage 2: Mathematical Libraries (depend on compilers and MPI) - PACKAGE_DEPENDENCIES["openblas"]="gcc cmake" - PACKAGE_DEPENDENCIES["mkl"]="intel" - PACKAGE_DEPENDENCIES["aocl"]="amd" - - # Stage 3: Scientific Computing Libraries (depend on math libs and MPI) - PACKAGE_DEPENDENCIES["fftw"]="gcc cmake" - PACKAGE_DEPENDENCIES["libxc"]="gcc cmake" - PACKAGE_DEPENDENCIES["scalapack"]="openblas" - PACKAGE_DEPENDENCIES["elpa"]="scalapack" - - # Stage 4: Advanced Libraries - PACKAGE_DEPENDENCIES["dftd4"]="cmake" - PACKAGE_DEPENDENCIES["cereal"]="gcc cmake" - PACKAGE_DEPENDENCIES["json"]="gcc cmake" - PACKAGE_DEPENDENCIES["libtorch"]="gcc cmake" - PACKAGE_DEPENDENCIES["libnpy"]="gcc cmake" - PACKAGE_DEPENDENCIES["libri"]="gcc cmake" - PACKAGE_DEPENDENCIES["libcomm"]="gcc cmake" - PACKAGE_DEPENDENCIES["nep"]="gcc cmake" + # Stage 0: Compilers and Build Tools + PACKAGE_DEPENDENCIES["gcc"]="" + PACKAGE_DEPENDENCIES["intel"]="" + PACKAGE_DEPENDENCIES["amd"]="" + PACKAGE_DEPENDENCIES["cmake"]="" + + # Stage 1: MPI Implementations (depend on compilers) + PACKAGE_DEPENDENCIES["openmpi"]="gcc cmake" + PACKAGE_DEPENDENCIES["mpich"]="gcc cmake" + PACKAGE_DEPENDENCIES["intelmpi"]="intel" + + # Stage 2: Mathematical Libraries (depend on compilers and MPI) + PACKAGE_DEPENDENCIES["openblas"]="gcc cmake" + PACKAGE_DEPENDENCIES["mkl"]="intel" + PACKAGE_DEPENDENCIES["aocl"]="amd" + + # Stage 3: Scientific Computing Libraries (depend on math libs and MPI) + PACKAGE_DEPENDENCIES["fftw"]="gcc cmake" + PACKAGE_DEPENDENCIES["libxc"]="gcc cmake" + PACKAGE_DEPENDENCIES["scalapack"]="openblas" + PACKAGE_DEPENDENCIES["elpa"]="scalapack" + + # Stage 4: Advanced Libraries + PACKAGE_DEPENDENCIES["dftd4"]="cmake" + PACKAGE_DEPENDENCIES["cereal"]="gcc cmake" + PACKAGE_DEPENDENCIES["json"]="gcc cmake" + PACKAGE_DEPENDENCIES["libtorch"]="gcc cmake" + PACKAGE_DEPENDENCIES["libnpy"]="gcc cmake" + PACKAGE_DEPENDENCIES["libri"]="gcc cmake" + PACKAGE_DEPENDENCIES["libcomm"]="gcc cmake" + PACKAGE_DEPENDENCIES["nep"]="gcc cmake" } # Check if package is enabled for installation # Usage: package_is_enabled "package_name" package_is_enabled() { - local package="$1" - local status=$(config_get "with_${package}") - - case "$status" in - "__INSTALL__"|"__SYSTEM__") - return 0 - ;; - *) - return 1 - ;; - esac + local package="$1" + local status=$(config_get "with_${package}") + + case "$status" in + "__INSTALL__" | "__SYSTEM__") + return 0 + ;; + *) + return 1 + ;; + esac } # Get package installation mode # Usage: package_get_mode "package_name" package_get_mode() { - local package="$1" - config_get "with_${package}" + local package="$1" + config_get "with_${package}" } - # Mark package as built # Usage: package_mark_built "package_name" package_mark_built() { - local package="$1" - PACKAGE_BUILD_STATUS["$package"]="built" + local package="$1" + PACKAGE_BUILD_STATUS["$package"]="built" } # Get package dependencies # Usage: package_get_dependencies "package_name" package_get_dependencies() { - local package="$1" - echo "${PACKAGE_DEPENDENCIES[$package]}" + local package="$1" + echo "${PACKAGE_DEPENDENCIES[$package]}" } # Check if all dependencies are satisfied # Usage: package_check_dependencies "package_name" package_check_dependencies() { - local package="$1" - local deps=$(package_get_dependencies "$package") - - for dep in $deps; do - if package_is_enabled "$dep"; then - if ! package_is_built "$dep"; then - echo "Dependency $dep for $package is not built yet" - return 1 - fi - fi - done - - return 0 + local package="$1" + local deps=$(package_get_dependencies "$package") + + for dep in $deps; do + if package_is_enabled "$dep"; then + if ! package_is_built "$dep"; then + echo "Dependency $dep for $package is not built yet" + return 1 + fi + fi + done + + return 0 } # Install package by stage # Usage: package_install_stage "stage_number" package_install_stage() { - local stage="$1" - local stage_script="${SCRIPTDIR}/stage${stage}/install_stage${stage}.sh" - - if [[ ! -f "$stage_script" ]]; then - report_error ${LINENO} "Stage script not found: $stage_script" - return 1 - fi - - echo "Installing Stage ${stage} packages..." - - # Check if dry run mode - if [[ "$(config_get dry_run)" == "__TRUE__" ]]; then - echo "Dry run: would execute $stage_script" - return 0 - fi - - # Export version configuration for stage scripts - package_export_version_config - - # Execute stage installation script - if ! "$stage_script"; then - report_error ${LINENO} "Failed to install Stage ${stage} packages" - return 1 - fi - - echo "Stage ${stage} installation completed successfully" + local stage="$1" + local stage_script="${SCRIPTDIR}/stage${stage}/install_stage${stage}.sh" + + if [[ ! -f "$stage_script" ]]; then + report_error ${LINENO} "Stage script not found: $stage_script" + return 1 + fi + + echo "Installing Stage ${stage} packages..." + + # Check if dry run mode + if [[ "$(config_get dry_run)" == "__TRUE__" ]]; then + echo "Dry run: would execute $stage_script" return 0 + fi + + # Export version configuration for stage scripts + package_export_version_config + + # Execute stage installation script + if ! "$stage_script"; then + report_error ${LINENO} "Failed to install Stage ${stage} packages" + return 1 + fi + + echo "Stage ${stage} installation completed successfully" + return 0 } # Install all enabled packages # Usage: package_install_all package_install_all() { - echo "Starting package installation process..." - - # Check if pack run mode (only check and install required packages) - if [[ "$(config_get PACK_RUN)" == "__TRUE__" ]]; then - echo "Pack run mode: checking and installing required packages only" - package_check_system_requirements - return $? + echo "Starting package installation process..." + + # Check if pack run mode (only check and install required packages) + if [[ "$(config_get PACK_RUN)" == "__TRUE__" ]]; then + echo "Pack run mode: checking and installing required packages only" + package_check_system_requirements + return $? + fi + + # Install packages by stages + for stage in 0 1 2 3 4; do + if ! package_install_stage "$stage"; then + report_error ${LINENO} "Failed to install stage $stage" + return 1 fi - - # Install packages by stages - for stage in 0 1 2 3 4; do - if ! package_install_stage "$stage"; then - report_error ${LINENO} "Failed to install stage $stage" - return 1 - fi - done - - echo "All package installations completed successfully" - return 0 + done + + echo "All package installations completed successfully" + return 0 } # Check system requirements # Usage: package_check_system_requirements package_check_system_requirements() { - echo "Checking system requirements..." - - # Check for essential system tools - local required_tools="wget curl tar gzip make" - local missing_tools="" - - for tool in $required_tools; do - if ! command -v "$tool" &> /dev/null; then - missing_tools="$missing_tools $tool" - fi - done - - if [[ -n "$missing_tools" ]]; then - report_error ${LINENO} "Missing required system tools:$missing_tools" - echo "Please install these tools using your system package manager" - return 1 + echo "Checking system requirements..." + + # Check for essential system tools + local required_tools="wget curl tar gzip make" + local missing_tools="" + + for tool in $required_tools; do + if ! command -v "$tool" &>/dev/null; then + missing_tools="$missing_tools $tool" fi - - # Check for compiler availability - local compiler_mode=$(config_get MATH_MODE) - case "$compiler_mode" in - gcc) - if ! command -v gcc &> /dev/null; then - report_warning ${LINENO} "GCC compiler not found in system PATH" - fi - ;; - intel) - if ! command -v icc &> /dev/null && ! command -v icx &> /dev/null; then - report_warning ${LINENO} "Intel compiler not found in system PATH" - fi - ;; - amd) - if ! command -v clang &> /dev/null; then - report_warning ${LINENO} "AMD/Clang compiler not found in system PATH" - fi - ;; - esac - - echo "System requirements check completed" - return 0 + done + + if [[ -n "$missing_tools" ]]; then + report_error ${LINENO} "Missing required system tools:$missing_tools" + echo "Please install these tools using your system package manager" + return 1 + fi + + # Check for compiler availability + local compiler_mode=$(config_get MATH_MODE) + case "$compiler_mode" in + gcc) + if ! command -v gcc &>/dev/null; then + report_warning ${LINENO} "GCC compiler not found in system PATH" + fi + ;; + intel) + if ! command -v icc &>/dev/null && ! command -v icx &>/dev/null; then + report_warning ${LINENO} "Intel compiler not found in system PATH" + fi + ;; + amd) + if ! command -v clang &>/dev/null; then + report_warning ${LINENO} "AMD/Clang compiler not found in system PATH" + fi + ;; + esac + + echo "System requirements check completed" + return 0 } # Generate package configuration file # Usage: package_write_config "config_file" package_write_config() { - local config_file="$1" - - echo "# ABACUS Toolchain Package Configuration" > "$config_file" - echo "# Generated on $(date)" >> "$config_file" - echo "" >> "$config_file" - - # Write package lists - echo "tool_list=\"${tool_list}\"" >> "$config_file" - echo "mpi_list=\"${mpi_list}\"" >> "$config_file" - echo "math_list=\"${math_list}\"" >> "$config_file" - echo "lib_list=\"${lib_list}\"" >> "$config_file" - echo "package_list=\"${package_list}\"" >> "$config_file" - echo "" >> "$config_file" - - # Write package configurations - for pkg in ${package_list}; do - local status=$(config_get "with_${pkg}") - echo "with_${pkg}=\"${status}\"" >> "$config_file" - done - - echo "" >> "$config_file" - echo "# Configuration modes" >> "$config_file" - echo "MPI_MODE=\"$(config_get MPI_MODE)\"" >> "$config_file" - echo "MATH_MODE=\"$(config_get MATH_MODE)\"" >> "$config_file" - echo "TARGET_CPU=\"$(config_get TARGET_CPU)\"" >> "$config_file" - echo "GPUVER=\"$(config_get GPUVER)\"" >> "$config_file" - - echo "Package configuration written to: $config_file" + local config_file="$1" + + echo "# ABACUS Toolchain Package Configuration" >"$config_file" + echo "# Generated on $(date)" >>"$config_file" + echo "" >>"$config_file" + + # Write package lists + echo "tool_list=\"${tool_list}\"" >>"$config_file" + echo "mpi_list=\"${mpi_list}\"" >>"$config_file" + echo "math_list=\"${math_list}\"" >>"$config_file" + echo "lib_list=\"${lib_list}\"" >>"$config_file" + echo "package_list=\"${package_list}\"" >>"$config_file" + echo "" >>"$config_file" + + # Write package configurations + for pkg in ${package_list}; do + local status=$(config_get "with_${pkg}") + echo "with_${pkg}=\"${status}\"" >>"$config_file" + done + + echo "" >>"$config_file" + echo "# Configuration modes" >>"$config_file" + echo "MPI_MODE=\"$(config_get MPI_MODE)\"" >>"$config_file" + echo "MATH_MODE=\"$(config_get MATH_MODE)\"" >>"$config_file" + echo "TARGET_CPU=\"$(config_get TARGET_CPU)\"" >>"$config_file" + echo "GPUVER=\"$(config_get GPUVER)\"" >>"$config_file" + + echo "Package configuration written to: $config_file" } # Get list of packages to install # Usage: package_list_to_install package_list_to_install() { - local install_packages="" - - for pkg in ${package_list}; do - if [[ "$(config_get with_${pkg})" == "__INSTALL__" ]]; then - install_packages="$install_packages $pkg" - fi - done - - echo "$install_packages" + local install_packages="" + + for pkg in ${package_list}; do + if [[ "$(config_get with_${pkg})" == "__INSTALL__" ]]; then + install_packages="$install_packages $pkg" + fi + done + + echo "$install_packages" } # Get list of system packages # Usage: package_get_system_list package_get_system_list() { - local system_packages="" - - for pkg in ${package_list}; do - if [[ "$(config_get with_${pkg})" == "__SYSTEM__" ]]; then - system_packages="$system_packages $pkg" - fi - done - - echo "$system_packages" + local system_packages="" + + for pkg in ${package_list}; do + if [[ "$(config_get with_${pkg})" == "__SYSTEM__" ]]; then + system_packages="$system_packages $pkg" + fi + done + + echo "$system_packages" } # Print package installation summary # Usage: package_print_summary package_print_summary() { - echo "Package Installation Summary:" - echo "============================" + echo "Package Installation Summary:" + echo "============================" + echo "" + + local install_list=$(package_get_install_list) + local system_list=$(package_get_system_list) + + if [[ -n "$install_list" ]]; then + echo "Packages to be installed from source:" + for pkg in $install_list; do + echo " - $pkg" + done echo "" - - local install_list=$(package_get_install_list) - local system_list=$(package_get_system_list) - - if [[ -n "$install_list" ]]; then - echo "Packages to be installed from source:" - for pkg in $install_list; do - echo " - $pkg" - done - echo "" - fi - - if [[ -n "$system_list" ]]; then - echo "Packages to be used from system:" - for pkg in $system_list; do - echo " - $pkg" - done - echo "" - fi - - echo "Installation modes:" - echo " MPI Mode: $(config_get MPI_MODE)" - echo " Math Mode: $(config_get MATH_MODE)" - echo " Target CPU: $(config_get TARGET_CPU)" - echo " GPU Version: $(config_get GPUVER)" + fi + + if [[ -n "$system_list" ]]; then + echo "Packages to be used from system:" + for pkg in $system_list; do + echo " - $pkg" + done echo "" + fi + + echo "Installation modes:" + echo " MPI Mode: $(config_get MPI_MODE)" + echo " Math Mode: $(config_get MATH_MODE)" + echo " Target CPU: $(config_get TARGET_CPU)" + echo " GPU Version: $(config_get GPUVER)" + echo "" } # Validate package configuration # Usage: package_validate_config package_validate_config() { - local errors=0 - - # Check for conflicting MPI implementations - local mpi_count=0 - for mpi in mpich openmpi intelmpi; do - if [[ "$(config_get with_${mpi})" != "__DONTUSE__" ]]; then - ((mpi_count++)) - fi - done - - if [[ $mpi_count -gt 1 ]]; then - report_error ${LINENO} "Multiple MPI implementations selected. Please choose only one." - ((errors++)) + local errors=0 + + # Check for conflicting MPI implementations + local mpi_count=0 + for mpi in mpich openmpi intelmpi; do + if [[ "$(config_get with_${mpi})" != "__DONTUSE__" ]]; then + ((mpi_count++)) fi - - # Check for conflicting math libraries - local math_count=0 - for math in mkl openblas aocl; do - if [[ "$(config_get with_${math})" != "__DONTUSE__" ]]; then - ((math_count++)) - fi - done - - if [[ $math_count -gt 1 ]]; then - report_warning ${LINENO} "Multiple math libraries selected. This may cause conflicts." + done + + if [[ $mpi_count -gt 1 ]]; then + report_error ${LINENO} "Multiple MPI implementations selected. Please choose only one." + ((errors++)) + fi + + # Check for conflicting math libraries + local math_count=0 + for math in mkl openblas aocl; do + if [[ "$(config_get with_${math})" != "__DONTUSE__" ]]; then + ((math_count++)) fi - - # Check for GPU support consistency - local gpu_ver=$(config_get GPUVER) - if [[ "$gpu_ver" != "no" ]]; then - if [[ "$(config_get enable_cuda)" != "__TRUE__" && "$(config_get enable_hip)" != "__TRUE__" ]]; then - report_warning ${LINENO} "GPU version specified but no GPU support enabled" - fi + done + + if [[ $math_count -gt 1 ]]; then + report_warning ${LINENO} "Multiple math libraries selected. This may cause conflicts." + fi + + # Check for GPU support consistency + local gpu_ver=$(config_get GPUVER) + if [[ "$gpu_ver" != "no" ]]; then + if [[ "$(config_get enable_cuda)" != "__TRUE__" && "$(config_get enable_hip)" != "__TRUE__" ]]; then + report_warning ${LINENO} "GPU version specified but no GPU support enabled" fi - - return $errors + fi + + return $errors } # Clean build directories # Usage: package_clean_build package_clean_build() { - if [[ -d "$BUILDDIR" ]]; then - echo "Cleaning build directory: $BUILDDIR" - rm -rf "$BUILDDIR" - fi - mkdir -p "$BUILDDIR" + if [[ -d "$BUILDDIR" ]]; then + echo "Cleaning build directory: $BUILDDIR" + rm -rf "$BUILDDIR" + fi + mkdir -p "$BUILDDIR" } # Clean install directories # Usage: package_clean_install package_clean_install() { - if [[ -d "$INSTALLDIR" ]]; then - echo "Cleaning install directory: $INSTALLDIR" - rm -rf "$INSTALLDIR" - fi - mkdir -p "$INSTALLDIR" + if [[ -d "$INSTALLDIR" ]]; then + echo "Cleaning install directory: $INSTALLDIR" + rm -rf "$INSTALLDIR" + fi + mkdir -p "$INSTALLDIR" } # Install all packages in pack run mode # Usage: package_install_all_pack_run package_install_all_pack_run() { - echo "Pack run mode - installing all packages in sequence" - - # Execute all stages in sequence - for stage in 0 1 2 3 4; do - local stage_script="${SCRIPTDIR}/stage${stage}/install_stage${stage}.sh" - if [[ -f "$stage_script" ]]; then - echo "Executing stage $stage in pack run mode..." - if ! "$stage_script"; then - echo "Stage $stage failed in pack run mode" - return 1 - fi - fi - done - - return 0 + echo "Pack run mode - installing all packages in sequence" + + # Execute all stages in sequence + for stage in 0 1 2 3 4; do + local stage_script="${SCRIPTDIR}/stage${stage}/install_stage${stage}.sh" + if [[ -f "$stage_script" ]]; then + echo "Executing stage $stage in pack run mode..." + if ! "$stage_script"; then + echo "Stage $stage failed in pack run mode" + return 1 + fi + fi + done + + return 0 } # Export version configuration for stage scripts # Usage: package_export_version_config package_export_version_config() { - # Export version suffix configuration - local use_alt_versions=$(config_get use_alt_versions) - - if [[ "$use_alt_versions" == "__TRUE__" ]]; then - export ABACUS_TOOLCHAIN_VERSION_SUFFIX="alt" - else - export ABACUS_TOOLCHAIN_VERSION_SUFFIX="main" - fi - - # Build package versions string from CONFIG_CACHE PACKAGE_VERSION_* entries - local package_versions="" - for key in "${!CONFIG_CACHE[@]}"; do - if [[ "$key" =~ ^PACKAGE_VERSION_(.+)$ ]]; then - local pkg_name="${BASH_REMATCH[1]}" - local pkg_version="${CONFIG_CACHE[$key]}" - local pkg_lower=$(echo "$pkg_name" | tr '[:upper:]' '[:lower:]') - - if [[ -n "$package_versions" ]]; then - package_versions="${package_versions} ${pkg_lower}:${pkg_version}" - else - package_versions="${pkg_lower}:${pkg_version}" - fi - fi - done - - # Export individual package version overrides - if [[ -n "$package_versions" ]]; then - export ABACUS_TOOLCHAIN_PACKAGE_VERSIONS="$package_versions" + # Export version suffix configuration + local use_alt_versions=$(config_get use_alt_versions) + + if [[ "$use_alt_versions" == "__TRUE__" ]]; then + export ABACUS_TOOLCHAIN_VERSION_SUFFIX="alt" + else + export ABACUS_TOOLCHAIN_VERSION_SUFFIX="main" + fi + + # Build package versions string from CONFIG_CACHE PACKAGE_VERSION_* entries + local package_versions="" + for key in "${!CONFIG_CACHE[@]}"; do + if [[ "$key" =~ ^PACKAGE_VERSION_(.+)$ ]]; then + local pkg_name="${BASH_REMATCH[1]}" + local pkg_version="${CONFIG_CACHE[$key]}" + local pkg_lower=$(echo "$pkg_name" | tr '[:upper:]' '[:lower:]') + + if [[ -n "$package_versions" ]]; then + package_versions="${package_versions} ${pkg_lower}:${pkg_version}" + else + package_versions="${pkg_lower}:${pkg_version}" + fi fi - - # Export for backward compatibility - export VERSION_SUFFIX="$ABACUS_TOOLCHAIN_VERSION_SUFFIX" + done + + # Export individual package version overrides + if [[ -n "$package_versions" ]]; then + export ABACUS_TOOLCHAIN_PACKAGE_VERSIONS="$package_versions" + fi + + # Export for backward compatibility + export VERSION_SUFFIX="$ABACUS_TOOLCHAIN_VERSION_SUFFIX" } # Execute stage-based installation (stage0 -> stage1 -> stage2 -> stage3 -> stage4) # This follows the original toolchain logic exactly package_install_all_stages() { - echo "Starting stage-based installation..." - - # Export version configuration before starting stages - package_export_version_config - - # Execute stages in order, just like the original fallback version - local stages=("stage0" "stage1" "stage2" "stage3" "stage4") - - for stage in "${stages[@]}"; do - local stage_script="${SCRIPTDIR}/${stage}/install_${stage}.sh" - - if [[ -f "$stage_script" ]]; then - echo "Executing ${stage}..." - if ! "$stage_script"; then - report_error ${LINENO} "Failed to execute ${stage}" - return 1 - fi - else - echo "Warning: Stage script not found: $stage_script" - fi - done - - echo "All stages completed successfully." - return 0 + echo "Starting stage-based installation..." + + # Export version configuration before starting stages + package_export_version_config + + # Execute stages in order, just like the original fallback version + local stages=("stage0" "stage1" "stage2" "stage3" "stage4") + + for stage in "${stages[@]}"; do + local stage_script="${SCRIPTDIR}/${stage}/install_${stage}.sh" + + if [[ -f "$stage_script" ]]; then + echo "Executing ${stage}..." + if ! "$stage_script"; then + report_error ${LINENO} "Failed to execute ${stage}" + return 1 + fi + else + echo "Warning: Stage script not found: $stage_script" + fi + done + + echo "All stages completed successfully." + return 0 } diff --git a/toolchain/scripts/lib/user_interface.sh b/toolchain/scripts/lib/user_interface.sh index 3ef91c1731e..8b0bcbfd596 100644 --- a/toolchain/scripts/lib/user_interface.sh +++ b/toolchain/scripts/lib/user_interface.sh @@ -17,53 +17,53 @@ UI_LOG_FILE="" # Enhanced color definitions with harmonious blue-based theme if [[ -t 1 ]]; then - # Terminal supports colors - Enhanced color palette - readonly UI_RED='\033[38;5;196m' # Bright red for errors - readonly UI_GREEN='\033[38;5;46m' # Bright green for success - readonly UI_YELLOW='\033[38;5;226m' # Bright yellow for warnings - readonly UI_BLUE='\033[38;5;39m' # Bright blue for info (main theme) - readonly UI_PURPLE='\033[38;5;141m' # Purple for debug - readonly UI_CYAN='\033[38;5;51m' # Cyan for progress - readonly UI_WHITE='\033[38;5;255m' # Pure white - readonly UI_GRAY='\033[38;5;244m' # Gray for secondary text - readonly UI_ORANGE='\033[38;5;208m' # Orange for highlights - - # Style definitions - readonly UI_BOLD='\033[1m' - readonly UI_DIM='\033[2m' - readonly UI_ITALIC='\033[3m' - readonly UI_UNDERLINE='\033[4m' - readonly UI_BLINK='\033[5m' - readonly UI_REVERSE='\033[7m' - readonly UI_NC='\033[0m' # No Color - - # Background colors for special effects - readonly UI_BG_RED='\033[48;5;196m' - readonly UI_BG_GREEN='\033[48;5;46m' - readonly UI_BG_BLUE='\033[48;5;39m' - readonly UI_BG_YELLOW='\033[48;5;226m' + # Terminal supports colors - Enhanced color palette + readonly UI_RED='\033[38;5;196m' # Bright red for errors + readonly UI_GREEN='\033[38;5;46m' # Bright green for success + readonly UI_YELLOW='\033[38;5;226m' # Bright yellow for warnings + readonly UI_BLUE='\033[38;5;39m' # Bright blue for info (main theme) + readonly UI_PURPLE='\033[38;5;141m' # Purple for debug + readonly UI_CYAN='\033[38;5;51m' # Cyan for progress + readonly UI_WHITE='\033[38;5;255m' # Pure white + readonly UI_GRAY='\033[38;5;244m' # Gray for secondary text + readonly UI_ORANGE='\033[38;5;208m' # Orange for highlights + + # Style definitions + readonly UI_BOLD='\033[1m' + readonly UI_DIM='\033[2m' + readonly UI_ITALIC='\033[3m' + readonly UI_UNDERLINE='\033[4m' + readonly UI_BLINK='\033[5m' + readonly UI_REVERSE='\033[7m' + readonly UI_NC='\033[0m' # No Color + + # Background colors for special effects + readonly UI_BG_RED='\033[48;5;196m' + readonly UI_BG_GREEN='\033[48;5;46m' + readonly UI_BG_BLUE='\033[48;5;39m' + readonly UI_BG_YELLOW='\033[48;5;226m' else - # No color support - fallback to empty strings - readonly UI_RED='' - readonly UI_GREEN='' - readonly UI_YELLOW='' - readonly UI_BLUE='' - readonly UI_PURPLE='' - readonly UI_CYAN='' - readonly UI_WHITE='' - readonly UI_GRAY='' - readonly UI_ORANGE='' - readonly UI_BOLD='' - readonly UI_DIM='' - readonly UI_ITALIC='' - readonly UI_UNDERLINE='' - readonly UI_BLINK='' - readonly UI_REVERSE='' - readonly UI_NC='' - readonly UI_BG_RED='' - readonly UI_BG_GREEN='' - readonly UI_BG_BLUE='' - readonly UI_BG_YELLOW='' + # No color support - fallback to empty strings + readonly UI_RED='' + readonly UI_GREEN='' + readonly UI_YELLOW='' + readonly UI_BLUE='' + readonly UI_PURPLE='' + readonly UI_CYAN='' + readonly UI_WHITE='' + readonly UI_GRAY='' + readonly UI_ORANGE='' + readonly UI_BOLD='' + readonly UI_DIM='' + readonly UI_ITALIC='' + readonly UI_UNDERLINE='' + readonly UI_BLINK='' + readonly UI_REVERSE='' + readonly UI_NC='' + readonly UI_BG_RED='' + readonly UI_BG_GREEN='' + readonly UI_BG_BLUE='' + readonly UI_BG_YELLOW='' fi # Terminal Unicode support detection @@ -72,90 +72,90 @@ UI_UNICODE_SUPPORT="" # Detect terminal Unicode support capability # Returns: "full", "basic", or "none" ui_detect_unicode_support() { - # Check if already detected - if [[ -n "$UI_UNICODE_SUPPORT" ]]; then - echo "$UI_UNICODE_SUPPORT" - return 0 - fi - - # Manual override via environment variable - if [[ "${ABACUS_UI_SIMPLE:-}" == "1" ]] || [[ "${ABACUS_UI_ASCII:-}" == "1" ]]; then - UI_UNICODE_SUPPORT="none" - echo "none" - return 0 - fi - - # Force Unicode mode if explicitly requested - if [[ "${ABACUS_UI_UNICODE:-}" == "1" ]]; then - UI_UNICODE_SUPPORT="full" - echo "full" - return 0 - fi - - # Check if we're in a non-interactive environment - if [[ ! -t 1 ]]; then - UI_UNICODE_SUPPORT="none" - echo "none" - return 0 + # Check if already detected + if [[ -n "$UI_UNICODE_SUPPORT" ]]; then + echo "$UI_UNICODE_SUPPORT" + return 0 + fi + + # Manual override via environment variable + if [[ "${ABACUS_UI_SIMPLE:-}" == "1" ]] || [[ "${ABACUS_UI_ASCII:-}" == "1" ]]; then + UI_UNICODE_SUPPORT="none" + echo "none" + return 0 + fi + + # Force Unicode mode if explicitly requested + if [[ "${ABACUS_UI_UNICODE:-}" == "1" ]]; then + UI_UNICODE_SUPPORT="full" + echo "full" + return 0 + fi + + # Check if we're in a non-interactive environment + if [[ ! -t 1 ]]; then + UI_UNICODE_SUPPORT="none" + echo "none" + return 0 + fi + + # Check locale settings for UTF-8 support + local locale_utf8=false + + # First check environment variables + if [[ "${LC_ALL:-}" =~ [Uu][Tt][Ff]-?8 ]] || + [[ "${LC_CTYPE:-}" =~ [Uu][Tt][Ff]-?8 ]] || + [[ "${LANG:-}" =~ [Uu][Tt][Ff]-?8 ]]; then + locale_utf8=true + fi + + # Additional check using locale command if available + if [[ "$locale_utf8" == "false" ]] && command -v locale &>/dev/null; then + local charset=$(locale charmap 2>/dev/null || echo "") + if [[ "$charset" =~ UTF-?8 ]]; then + locale_utf8=true fi - - # Check locale settings for UTF-8 support - local locale_utf8=false - - # First check environment variables - if [[ "${LC_ALL:-}" =~ [Uu][Tt][Ff]-?8 ]] || \ - [[ "${LC_CTYPE:-}" =~ [Uu][Tt][Ff]-?8 ]] || \ - [[ "${LANG:-}" =~ [Uu][Tt][Ff]-?8 ]]; then - locale_utf8=true + fi + + # Check terminal type and capabilities + local term_support="none" + case "${TERM:-}" in + xterm* | screen* | tmux* | rxvt* | gnome* | konsole* | alacritty* | kitty* | iterm*) + if [[ "$locale_utf8" == "true" ]]; then + term_support="full" + else + term_support="basic" fi - - # Additional check using locale command if available - if [[ "$locale_utf8" == "false" ]] && command -v locale &>/dev/null; then - local charset=$(locale charmap 2>/dev/null || echo "") - if [[ "$charset" =~ UTF-?8 ]]; then - locale_utf8=true - fi + ;; + linux | vt*) + # Linux console - basic Unicode support + if [[ "$locale_utf8" == "true" ]]; then + term_support="basic" + else + term_support="none" fi - - # Check terminal type and capabilities - local term_support="none" - case "${TERM:-}" in - xterm*|screen*|tmux*|rxvt*|gnome*|konsole*|alacritty*|kitty*|iterm*) - if [[ "$locale_utf8" == "true" ]]; then - term_support="full" - else - term_support="basic" - fi - ;; - linux|vt*) - # Linux console - basic Unicode support - if [[ "$locale_utf8" == "true" ]]; then - term_support="basic" - else - term_support="none" - fi - ;; - dumb|unknown) - term_support="none" - ;; - *) - # Unknown terminal - be conservative - if [[ "$locale_utf8" == "true" ]]; then - term_support="basic" - else - term_support="none" - fi - ;; - esac - - # Final validation - ensure we have both locale and terminal support - if [[ "$term_support" != "none" && "$locale_utf8" == "false" ]]; then - # Terminal claims support but locale doesn't - be conservative - term_support="none" + ;; + dumb | unknown) + term_support="none" + ;; + *) + # Unknown terminal - be conservative + if [[ "$locale_utf8" == "true" ]]; then + term_support="basic" + else + term_support="none" fi - - UI_UNICODE_SUPPORT="$term_support" - echo "$term_support" + ;; + esac + + # Final validation - ensure we have both locale and terminal support + if [[ "$term_support" != "none" && "$locale_utf8" == "false" ]]; then + # Terminal claims support but locale doesn't - be conservative + term_support="none" + fi + + UI_UNICODE_SUPPORT="$term_support" + echo "$term_support" } # Unicode symbols with ASCII fallbacks @@ -184,373 +184,373 @@ UI_PROGRESS_EMPTY="" # Initialize Unicode icons based on terminal capability ui_init_icons() { - local support=$(ui_detect_unicode_support) - - case "$support" in - "full") - # Full Unicode support - use emoji and special symbols - readonly UI_ICON_SUCCESS="✅" - readonly UI_ICON_ERROR="❌" - readonly UI_ICON_WARNING="⚠️" - readonly UI_ICON_INFO="ℹ️" - readonly UI_ICON_PROGRESS="🔄" - readonly UI_ICON_ROCKET="🚀" - readonly UI_ICON_GEAR="⚙️" - readonly UI_ICON_PACKAGE="📦" - readonly UI_ICON_DOWNLOAD="⬇️" - readonly UI_ICON_BUILD="🔨" - readonly UI_ICON_INSTALL="📥" - readonly UI_ICON_CHECK="✓" - readonly UI_ICON_CROSS="✗" - readonly UI_ICON_ARROW="→" - readonly UI_ICON_STAR="⭐" - # Full Unicode progress bar - readonly UI_PROGRESS_FULL="█" - readonly UI_PROGRESS_PARTIAL1="▓" - readonly UI_PROGRESS_PARTIAL2="▒" - readonly UI_PROGRESS_EMPTY="░" - ;; - "basic") - # Basic Unicode support - use simple Unicode symbols - readonly UI_ICON_SUCCESS="✓" - readonly UI_ICON_ERROR="✗" - readonly UI_ICON_WARNING="!" - readonly UI_ICON_INFO="i" - readonly UI_ICON_PROGRESS="*" - readonly UI_ICON_ROCKET="^" - readonly UI_ICON_GEAR="*" - readonly UI_ICON_PACKAGE="+" - readonly UI_ICON_DOWNLOAD="v" - readonly UI_ICON_BUILD="#" - readonly UI_ICON_INSTALL="+" - readonly UI_ICON_CHECK="✓" - readonly UI_ICON_CROSS="✗" - readonly UI_ICON_ARROW="→" - readonly UI_ICON_STAR="*" - # Basic Unicode progress bar - readonly UI_PROGRESS_FULL="█" - readonly UI_PROGRESS_PARTIAL1="▓" - readonly UI_PROGRESS_PARTIAL2="▒" - readonly UI_PROGRESS_EMPTY="░" - ;; - *) - # ASCII fallback - maximum compatibility - readonly UI_ICON_SUCCESS="[OK]" - readonly UI_ICON_ERROR="[ERR]" - readonly UI_ICON_WARNING="[WARN]" - readonly UI_ICON_INFO="[INFO]" - readonly UI_ICON_PROGRESS="[*]" - readonly UI_ICON_ROCKET="[^]" - readonly UI_ICON_GEAR="[*]" - readonly UI_ICON_PACKAGE="[+]" - readonly UI_ICON_DOWNLOAD="[v]" - readonly UI_ICON_BUILD="[#]" - readonly UI_ICON_INSTALL="[+]" - readonly UI_ICON_CHECK="[+]" - readonly UI_ICON_CROSS="[-]" - readonly UI_ICON_ARROW="->" - readonly UI_ICON_STAR="[*]" - # ASCII progress bar - readonly UI_PROGRESS_FULL="#" - readonly UI_PROGRESS_PARTIAL1="#" - readonly UI_PROGRESS_PARTIAL2="-" - readonly UI_PROGRESS_EMPTY="." - ;; - esac + local support=$(ui_detect_unicode_support) + + case "$support" in + "full") + # Full Unicode support - use emoji and special symbols + readonly UI_ICON_SUCCESS="✅" + readonly UI_ICON_ERROR="❌" + readonly UI_ICON_WARNING="⚠️" + readonly UI_ICON_INFO="ℹ️" + readonly UI_ICON_PROGRESS="🔄" + readonly UI_ICON_ROCKET="🚀" + readonly UI_ICON_GEAR="⚙️" + readonly UI_ICON_PACKAGE="📦" + readonly UI_ICON_DOWNLOAD="⬇️" + readonly UI_ICON_BUILD="🔨" + readonly UI_ICON_INSTALL="📥" + readonly UI_ICON_CHECK="✓" + readonly UI_ICON_CROSS="✗" + readonly UI_ICON_ARROW="→" + readonly UI_ICON_STAR="⭐" + # Full Unicode progress bar + readonly UI_PROGRESS_FULL="█" + readonly UI_PROGRESS_PARTIAL1="▓" + readonly UI_PROGRESS_PARTIAL2="▒" + readonly UI_PROGRESS_EMPTY="░" + ;; + "basic") + # Basic Unicode support - use simple Unicode symbols + readonly UI_ICON_SUCCESS="✓" + readonly UI_ICON_ERROR="✗" + readonly UI_ICON_WARNING="!" + readonly UI_ICON_INFO="i" + readonly UI_ICON_PROGRESS="*" + readonly UI_ICON_ROCKET="^" + readonly UI_ICON_GEAR="*" + readonly UI_ICON_PACKAGE="+" + readonly UI_ICON_DOWNLOAD="v" + readonly UI_ICON_BUILD="#" + readonly UI_ICON_INSTALL="+" + readonly UI_ICON_CHECK="✓" + readonly UI_ICON_CROSS="✗" + readonly UI_ICON_ARROW="→" + readonly UI_ICON_STAR="*" + # Basic Unicode progress bar + readonly UI_PROGRESS_FULL="█" + readonly UI_PROGRESS_PARTIAL1="▓" + readonly UI_PROGRESS_PARTIAL2="▒" + readonly UI_PROGRESS_EMPTY="░" + ;; + *) + # ASCII fallback - maximum compatibility + readonly UI_ICON_SUCCESS="[OK]" + readonly UI_ICON_ERROR="[ERR]" + readonly UI_ICON_WARNING="[WARN]" + readonly UI_ICON_INFO="[INFO]" + readonly UI_ICON_PROGRESS="[*]" + readonly UI_ICON_ROCKET="[^]" + readonly UI_ICON_GEAR="[*]" + readonly UI_ICON_PACKAGE="[+]" + readonly UI_ICON_DOWNLOAD="[v]" + readonly UI_ICON_BUILD="[#]" + readonly UI_ICON_INSTALL="[+]" + readonly UI_ICON_CHECK="[+]" + readonly UI_ICON_CROSS="[-]" + readonly UI_ICON_ARROW="->" + readonly UI_ICON_STAR="[*]" + # ASCII progress bar + readonly UI_PROGRESS_FULL="#" + readonly UI_PROGRESS_PARTIAL1="#" + readonly UI_PROGRESS_PARTIAL2="-" + readonly UI_PROGRESS_EMPTY="." + ;; + esac } # Initialize user interface # Usage: ui_init [verbose] [quiet] [log_file] ui_init() { - if [[ "$UI_INITIALIZED" == "true" ]]; then - return 0 - fi - - # Parse options - while [[ $# -gt 0 ]]; do - case "$1" in - verbose) - UI_VERBOSE=true - ;; - quiet) - UI_QUIET=true - ;; - --log-file=*) - UI_LOG_FILE="${1#*=}" - ;; - *) - # Assume it's a log file path - UI_LOG_FILE="$1" - ;; - esac - shift - done - - # Initialize icons based on terminal capability - ui_init_icons - - UI_INITIALIZED=true + if [[ "$UI_INITIALIZED" == "true" ]]; then return 0 + fi + + # Parse options + while [[ $# -gt 0 ]]; do + case "$1" in + verbose) + UI_VERBOSE=true + ;; + quiet) + UI_QUIET=true + ;; + --log-file=*) + UI_LOG_FILE="${1#*=}" + ;; + *) + # Assume it's a log file path + UI_LOG_FILE="$1" + ;; + esac + shift + done + + # Initialize icons based on terminal capability + ui_init_icons + + UI_INITIALIZED=true + return 0 } # Print colored message with enhanced formatting # Usage: ui_print_color "color" "message" [icon] ui_print_color() { - local color="$1" - local message="$2" - local icon="${3:-}" - - if [[ "$UI_QUIET" == "true" ]]; then - return 0 - fi - - if [[ -n "$icon" ]]; then - echo -e "${color}${icon} ${message}${UI_NC}" - else - echo -e "${color}${message}${UI_NC}" - fi - - # Log to file if specified - if [[ -n "$UI_LOG_FILE" ]]; then - echo "[$(date '+%Y-%m-%d %H:%M:%S')] $message" >> "$UI_LOG_FILE" - fi + local color="$1" + local message="$2" + local icon="${3:-}" + + if [[ "$UI_QUIET" == "true" ]]; then + return 0 + fi + + if [[ -n "$icon" ]]; then + echo -e "${color}${icon} ${message}${UI_NC}" + else + echo -e "${color}${message}${UI_NC}" + fi + + # Log to file if specified + if [[ -n "$UI_LOG_FILE" ]]; then + echo "[$(date '+%Y-%m-%d %H:%M:%S')] $message" >>"$UI_LOG_FILE" + fi } # Print info message with enhanced styling # Usage: ui_info "message" ui_info() { - ui_print_color "${UI_BLUE}${UI_BOLD}" "$1" "$UI_ICON_INFO" + ui_print_color "${UI_BLUE}${UI_BOLD}" "$1" "$UI_ICON_INFO" } # Print success message with enhanced styling # Usage: ui_success "message" ui_success() { - ui_print_color "${UI_GREEN}${UI_BOLD}" "$1" "$UI_ICON_SUCCESS" + ui_print_color "${UI_GREEN}${UI_BOLD}" "$1" "$UI_ICON_SUCCESS" } # Print warning message with enhanced styling # Usage: ui_warning "message" ui_warning() { - ui_print_color "${UI_YELLOW}${UI_BOLD}" "$1" "$UI_ICON_WARNING" + ui_print_color "${UI_YELLOW}${UI_BOLD}" "$1" "$UI_ICON_WARNING" } # Print error message with enhanced styling # Usage: ui_error "message" ui_error() { - ui_print_color "${UI_RED}${UI_BOLD}" "$1" "$UI_ICON_ERROR" >&2 + ui_print_color "${UI_RED}${UI_BOLD}" "$1" "$UI_ICON_ERROR" >&2 } # Print debug message (only in verbose mode) with enhanced styling # Usage: ui_debug "message" ui_debug() { - if [[ "$UI_VERBOSE" == "true" ]]; then - ui_print_color "${UI_PURPLE}${UI_DIM}" "DEBUG: $1" "🔍" - fi + if [[ "$UI_VERBOSE" == "true" ]]; then + ui_print_color "${UI_PURPLE}${UI_DIM}" "DEBUG: $1" "🔍" + fi } # Detect glibc version using multiple methods for maximum compatibility # Usage: ui_get_glibc_version ui_get_glibc_version() { - local glibc_version="unknown" - - # Skip on non-Linux systems - if [[ "$(uname -s)" != "Linux" ]]; then - echo "unknown" + local glibc_version="unknown" + + # Skip on non-Linux systems + if [[ "$(uname -s)" != "Linux" ]]; then + echo "unknown" + return 0 + fi + + # Method 1: ldd --version (most reliable) + if command -v ldd &>/dev/null; then + local ldd_output=$(ldd --version 2>/dev/null | head -n1) + if [[ $? -eq 0 && -n "$ldd_output" ]]; then + # Extract version from ldd output (e.g., "ldd (Ubuntu GLIBC 2.35-0ubuntu3.1) 2.35") + glibc_version=$(echo "$ldd_output" | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1) + if [[ -n "$glibc_version" ]]; then + echo "$glibc_version" return 0 + fi fi - - # Method 1: ldd --version (most reliable) - if command -v ldd &> /dev/null; then - local ldd_output=$(ldd --version 2>/dev/null | head -n1) - if [[ $? -eq 0 && -n "$ldd_output" ]]; then - # Extract version from ldd output (e.g., "ldd (Ubuntu GLIBC 2.35-0ubuntu3.1) 2.35") - glibc_version=$(echo "$ldd_output" | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1) - if [[ -n "$glibc_version" ]]; then - echo "$glibc_version" - return 0 - fi + fi + + # Method 2: Direct library call (fallback) + local libc_paths=( + "/lib/x86_64-linux-gnu/libc.so.6" + "/lib64/libc.so.6" + "/lib/libc.so.6" + "/usr/lib/x86_64-linux-gnu/libc.so.6" + "/usr/lib64/libc.so.6" + ) + + for libc_path in "${libc_paths[@]}"; do + if [[ -x "$libc_path" ]]; then + local libc_output=$("$libc_path" 2>/dev/null | head -n1) + if [[ $? -eq 0 && -n "$libc_output" ]]; then + # Extract version from libc output + glibc_version=$(echo "$libc_output" | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1) + if [[ -n "$glibc_version" ]]; then + echo "$glibc_version" + return 0 fi + fi fi - - # Method 2: Direct library call (fallback) - local libc_paths=( - "/lib/x86_64-linux-gnu/libc.so.6" - "/lib64/libc.so.6" - "/lib/libc.so.6" - "/usr/lib/x86_64-linux-gnu/libc.so.6" - "/usr/lib64/libc.so.6" - ) - - for libc_path in "${libc_paths[@]}"; do - if [[ -x "$libc_path" ]]; then - local libc_output=$("$libc_path" 2>/dev/null | head -n1) - if [[ $? -eq 0 && -n "$libc_output" ]]; then - # Extract version from libc output - glibc_version=$(echo "$libc_output" | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1) - if [[ -n "$glibc_version" ]]; then - echo "$glibc_version" - return 0 - fi - fi - fi - done - - # Method 3: getconf GNU_LIBC_VERSION (alternative) - if command -v getconf &> /dev/null; then - local getconf_output=$(getconf GNU_LIBC_VERSION 2>/dev/null) - if [[ $? -eq 0 && -n "$getconf_output" ]]; then - # Extract version from getconf output (e.g., "glibc 2.35") - glibc_version=$(echo "$getconf_output" | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1) - if [[ -n "$glibc_version" ]]; then - echo "$glibc_version" - return 0 - fi - fi + done + + # Method 3: getconf GNU_LIBC_VERSION (alternative) + if command -v getconf &>/dev/null; then + local getconf_output=$(getconf GNU_LIBC_VERSION 2>/dev/null) + if [[ $? -eq 0 && -n "$getconf_output" ]]; then + # Extract version from getconf output (e.g., "glibc 2.35") + glibc_version=$(echo "$getconf_output" | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1) + if [[ -n "$glibc_version" ]]; then + echo "$glibc_version" + return 0 + fi fi - - # Method 4: Check /proc/version_signature or similar (last resort) - if [[ -r "/proc/version" ]]; then - local proc_version=$(cat /proc/version 2>/dev/null) - if [[ -n "$proc_version" ]]; then - # Look for glibc version in kernel version string (rare but possible) - glibc_version=$(echo "$proc_version" | grep -oE 'glibc[[:space:]]*[0-9]+\.[0-9]+(\.[0-9]+)?' | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1) - if [[ -n "$glibc_version" ]]; then - echo "$glibc_version" - return 0 - fi - fi + fi + + # Method 4: Check /proc/version_signature or similar (last resort) + if [[ -r "/proc/version" ]]; then + local proc_version=$(cat /proc/version 2>/dev/null) + if [[ -n "$proc_version" ]]; then + # Look for glibc version in kernel version string (rare but possible) + glibc_version=$(echo "$proc_version" | grep -oE 'glibc[[:space:]]*[0-9]+\.[0-9]+(\.[0-9]+)?' | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1) + if [[ -n "$glibc_version" ]]; then + echo "$glibc_version" + return 0 + fi fi - - # All methods failed - return unknown - echo "unknown" - return 0 + fi + + # All methods failed - return unknown + echo "unknown" + return 0 } # Read version from VERSION file # Usage: ui_get_version ui_get_version() { - local version_file - local version="Unknown" - - # Try to find VERSION file in multiple locations - if [[ -n "${SCRIPT_DIR:-}" && -f "${SCRIPT_DIR}/VERSION" ]]; then - version_file="${SCRIPT_DIR}/VERSION" - elif [[ -f "$(dirname "${BASH_SOURCE[0]}")/../VERSION" ]]; then - version_file="$(dirname "${BASH_SOURCE[0]}")/../VERSION" - elif [[ -f "./scripts/VERSION" ]]; then - version_file="./scripts/VERSION" - elif [[ -f "./VERSION" ]]; then - version_file="./VERSION" + local version_file + local version="Unknown" + + # Try to find VERSION file in multiple locations + if [[ -n "${SCRIPT_DIR:-}" && -f "${SCRIPT_DIR}/VERSION" ]]; then + version_file="${SCRIPT_DIR}/VERSION" + elif [[ -f "$(dirname "${BASH_SOURCE[0]}")/../VERSION" ]]; then + version_file="$(dirname "${BASH_SOURCE[0]}")/../VERSION" + elif [[ -f "./scripts/VERSION" ]]; then + version_file="./scripts/VERSION" + elif [[ -f "./VERSION" ]]; then + version_file="./VERSION" + fi + + if [[ -n "$version_file" && -f "$version_file" ]]; then + # Extract version from VERSION file, handling different formats + version=$(grep -E '^VERSION=' "$version_file" 2>/dev/null | cut -d'=' -f2 | tr -d '"' | tr -d "'" | xargs) + if [[ -z "$version" ]]; then + # Fallback: try to read the entire file content if no VERSION= line + version=$(head -n 1 "$version_file" 2>/dev/null | grep -v '^#' | xargs) fi - - if [[ -n "$version_file" && -f "$version_file" ]]; then - # Extract version from VERSION file, handling different formats - version=$(grep -E '^VERSION=' "$version_file" 2>/dev/null | cut -d'=' -f2 | tr -d '"' | tr -d "'" | xargs) - if [[ -z "$version" ]]; then - # Fallback: try to read the entire file content if no VERSION= line - version=$(head -n 1 "$version_file" 2>/dev/null | grep -v '^#' | xargs) - fi - if [[ -z "$version" ]]; then - version="Unknown" - fi + if [[ -z "$version" ]]; then + version="Unknown" fi - - echo "$version" + fi + + echo "$version" } # Print beautiful welcome banner # Usage: ui_welcome_banner ui_welcome_banner() { - if [[ "$UI_QUIET" == "true" ]]; then - return 0 - fi - - local banner_width=80 - local title="ABACUS Toolchain Installation" - local subtitle="DFT Calculation Made Simple" - local version=$(ui_get_version) - local version_text="Version $version" - - echo "" - ui_print_color "${UI_CYAN}${UI_BOLD}" "$(printf '═%.0s' $(seq 1 $banner_width))" - echo "" - ui_print_color "${UI_BLUE}${UI_BOLD}" "$(printf '%*s' $(((banner_width + ${#title}) / 2)) "$title")" - ui_print_color "${UI_GRAY}${UI_ITALIC}" "$(printf '%*s' $(((banner_width + ${#subtitle}) / 2)) "$subtitle")" - ui_print_color "${UI_GRAY}${UI_DIM}" "$(printf '%*s' $(((banner_width + ${#version_text}) / 2)) "$version_text")" - echo "" - ui_print_color "${UI_CYAN}${UI_BOLD}" "$(printf '═%.0s' $(seq 1 $banner_width))" - echo "" + if [[ "$UI_QUIET" == "true" ]]; then + return 0 + fi + + local banner_width=80 + local title="ABACUS Toolchain Installation" + local subtitle="DFT Calculation Made Simple" + local version=$(ui_get_version) + local version_text="Version $version" + + echo "" + ui_print_color "${UI_CYAN}${UI_BOLD}" "$(printf '═%.0s' $(seq 1 $banner_width))" + echo "" + ui_print_color "${UI_BLUE}${UI_BOLD}" "$(printf '%*s' $(((banner_width + ${#title}) / 2)) "$title")" + ui_print_color "${UI_GRAY}${UI_ITALIC}" "$(printf '%*s' $(((banner_width + ${#subtitle}) / 2)) "$subtitle")" + ui_print_color "${UI_GRAY}${UI_DIM}" "$(printf '%*s' $(((banner_width + ${#version_text}) / 2)) "$version_text")" + echo "" + ui_print_color "${UI_CYAN}${UI_BOLD}" "$(printf '═%.0s' $(seq 1 $banner_width))" + echo "" } # Print beautiful section header with enhanced styling # Usage: ui_section "title" ui_section() { - local title="$1" - local line_width=60 - - if [[ "$UI_QUIET" != "true" ]]; then - echo "" - ui_print_color "${UI_CYAN}${UI_BOLD}" "$(printf '─%.0s' $(seq 1 $line_width))" - ui_print_color "${UI_BLUE}${UI_BOLD}" "${UI_ICON_GEAR} $title" - ui_print_color "${UI_CYAN}${UI_BOLD}" "$(printf '─%.0s' $(seq 1 $line_width))" - echo "" - fi + local title="$1" + local line_width=60 + + if [[ "$UI_QUIET" != "true" ]]; then + echo "" + ui_print_color "${UI_CYAN}${UI_BOLD}" "$(printf '─%.0s' $(seq 1 $line_width))" + ui_print_color "${UI_BLUE}${UI_BOLD}" "${UI_ICON_GEAR} $title" + ui_print_color "${UI_CYAN}${UI_BOLD}" "$(printf '─%.0s' $(seq 1 $line_width))" + echo "" + fi } # Print enhanced progress bar with percentage and ETA # Usage: ui_progress "current" "total" "description" [eta_seconds] ui_progress() { - local current="$1" - local total="$2" - local description="$3" - local eta_seconds="${4:-}" - - if [[ "$UI_QUIET" == "true" ]]; then - return 0 - fi - - local percent=$((current * 100 / total)) - local filled=$((percent / 2)) - local empty=$((50 - filled)) - - # Create progress bar with gradient effect using detected characters - local progress_bar="" - for ((i=1; i<=filled; i++)); do - if [[ $i -le 10 ]]; then - progress_bar+="$UI_PROGRESS_FULL" - elif [[ $i -le 30 ]]; then - progress_bar+="$UI_PROGRESS_PARTIAL1" - else - progress_bar+="$UI_PROGRESS_PARTIAL2" - fi - done - - for ((i=1; i<=empty; i++)); do - progress_bar+="$UI_PROGRESS_EMPTY" - done - - # Format ETA if provided - local eta_text="" - if [[ -n "$eta_seconds" && "$eta_seconds" -gt 0 ]]; then - local eta_min=$((eta_seconds / 60)) - local eta_sec=$((eta_seconds % 60)) - eta_text=" (ETA: ${eta_min}m${eta_sec}s)" - fi - - printf "\r${UI_CYAN}${UI_ICON_PROGRESS} Progress: ${UI_BOLD}[${progress_bar}]${UI_NC} ${UI_GREEN}${percent}%%${UI_NC} - ${UI_BLUE}%s${UI_NC}${eta_text}" "$description" - - if [[ $current -eq $total ]]; then - echo "" - ui_success "Task completed successfully!" + local current="$1" + local total="$2" + local description="$3" + local eta_seconds="${4:-}" + + if [[ "$UI_QUIET" == "true" ]]; then + return 0 + fi + + local percent=$((current * 100 / total)) + local filled=$((percent / 2)) + local empty=$((50 - filled)) + + # Create progress bar with gradient effect using detected characters + local progress_bar="" + for ((i = 1; i <= filled; i++)); do + if [[ $i -le 10 ]]; then + progress_bar+="$UI_PROGRESS_FULL" + elif [[ $i -le 30 ]]; then + progress_bar+="$UI_PROGRESS_PARTIAL1" + else + progress_bar+="$UI_PROGRESS_PARTIAL2" fi + done + + for ((i = 1; i <= empty; i++)); do + progress_bar+="$UI_PROGRESS_EMPTY" + done + + # Format ETA if provided + local eta_text="" + if [[ -n "$eta_seconds" && "$eta_seconds" -gt 0 ]]; then + local eta_min=$((eta_seconds / 60)) + local eta_sec=$((eta_seconds % 60)) + eta_text=" (ETA: ${eta_min}m${eta_sec}s)" + fi + + printf "\r${UI_CYAN}${UI_ICON_PROGRESS} Progress: ${UI_BOLD}[${progress_bar}]${UI_NC} ${UI_GREEN}${percent}%%${UI_NC} - ${UI_BLUE}%s${UI_NC}${eta_text}" "$description" + + if [[ $current -eq $total ]]; then + echo "" + ui_success "Task completed successfully!" + fi } # Show enhanced help message with beautiful formatting # Usage: ui_show_help ui_show_help() { - ui_welcome_banner - - cat << 'EOF' + ui_welcome_banner + + cat <<'EOF' USAGE: install_abacus_toolchain_new.sh [OPTIONS] @@ -674,523 +674,523 @@ NOTES: 🚀 Use toolchain_*.sh scripts for easier pre-configured installations EOF - - ui_print_color "${UI_ORANGE}${UI_BOLD}" "${UI_ICON_STAR} For the best experience, start with: ${UI_WHITE}./install_abacus_toolchain_new.sh --dry-run${UI_NC}" - echo "" + + ui_print_color "${UI_ORANGE}${UI_BOLD}" "${UI_ICON_STAR} For the best experience, start with: ${UI_WHITE}./install_abacus_toolchain_new.sh --dry-run${UI_NC}" + echo "" } # Show enhanced package installation summary with beautiful table formatting # Usage: ui_show_summary ui_show_summary() { - ui_section "Installation Configuration Summary" - - # System information box - ui_print_color "${UI_BLUE}${UI_BOLD}" "🖥️ System Information:" - echo " ├─ OS: $(uname -s) $(uname -m)" - echo " ├─ Kernel: $(uname -r)" - echo " ├─ glibc: $(ui_get_glibc_version)" - echo " ├─ CPU Cores: $(nproc 2>/dev/null || echo "unknown")" - # CPU model detection - local cpu_model="unknown" - if command -v lscpu &> /dev/null; then - cpu_model=$(LC_ALL=C lscpu | awk -F: '/^Model name/{print $2}' | sed 's/^[[:space:]]*//') - fi - if [[ -z "$cpu_model" || "$cpu_model" == "unknown" ]] && [[ -r /proc/cpuinfo ]]; then - cpu_model=$(awk -F: '/model name|Hardware|Processor/{print $2; exit}' /proc/cpuinfo | sed 's/^[[:space:]]*//') - fi - echo " ├─ CPU Model: ${cpu_model}" - if command -v free &> /dev/null; then - local mem_gb=$(free -g | awk '/^Mem:/ {print $2}') - echo " ├─ Memory: ${mem_gb}GB" - else - echo " ├─ Memory: unknown" - fi - - # GPU detection with comprehensive vendor support - local gpu_info="no GPU detected" - local gpu_count=0 - local gpu_models="" - - # Method 1: Try nvidia-smi for NVIDIA GPUs - if command -v nvidia-smi &> /dev/null; then - local nvidia_output=$(nvidia-smi --query-gpu=name --format=csv,noheader,nounits 2>/dev/null) - if [[ $? -eq 0 && -n "$nvidia_output" ]]; then - gpu_count=$(echo "$nvidia_output" | wc -l) - if [[ $gpu_count -gt 0 ]]; then - local first_gpu=$(echo "$nvidia_output" | head -n1 | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') - if [[ $gpu_count -eq 1 ]]; then - gpu_info="$first_gpu" - else - gpu_info="$first_gpu (${gpu_count} devices)" - fi - fi + ui_section "Installation Configuration Summary" + + # System information box + ui_print_color "${UI_BLUE}${UI_BOLD}" "🖥️ System Information:" + echo " ├─ OS: $(uname -s) $(uname -m)" + echo " ├─ Kernel: $(uname -r)" + echo " ├─ glibc: $(ui_get_glibc_version)" + echo " ├─ CPU Cores: $(nproc 2>/dev/null || echo "unknown")" + # CPU model detection + local cpu_model="unknown" + if command -v lscpu &>/dev/null; then + cpu_model=$(LC_ALL=C lscpu | awk -F: '/^Model name/{print $2}' | sed 's/^[[:space:]]*//') + fi + if [[ -z "$cpu_model" || "$cpu_model" == "unknown" ]] && [[ -r /proc/cpuinfo ]]; then + cpu_model=$(awk -F: '/model name|Hardware|Processor/{print $2; exit}' /proc/cpuinfo | sed 's/^[[:space:]]*//') + fi + echo " ├─ CPU Model: ${cpu_model}" + if command -v free &>/dev/null; then + local mem_gb=$(free -g | awk '/^Mem:/ {print $2}') + echo " ├─ Memory: ${mem_gb}GB" + else + echo " ├─ Memory: unknown" + fi + + # GPU detection with comprehensive vendor support + local gpu_info="no GPU detected" + local gpu_count=0 + local gpu_models="" + + # Method 1: Try nvidia-smi for NVIDIA GPUs + if command -v nvidia-smi &>/dev/null; then + local nvidia_output=$(nvidia-smi --query-gpu=name --format=csv,noheader,nounits 2>/dev/null) + if [[ $? -eq 0 && -n "$nvidia_output" ]]; then + gpu_count=$(echo "$nvidia_output" | wc -l) + if [[ $gpu_count -gt 0 ]]; then + local first_gpu=$(echo "$nvidia_output" | head -n1 | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') + if [[ $gpu_count -eq 1 ]]; then + gpu_info="$first_gpu" + else + gpu_info="$first_gpu (${gpu_count} devices)" fi + fi fi - - # Method 2: Try rocm-smi for AMD GPUs (if no NVIDIA found) - if [[ "$gpu_info" == "no GPU detected" ]] && command -v rocm-smi &> /dev/null; then - local amd_output=$(rocm-smi --showproductname 2>/dev/null | grep -E "GPU\[" | head -n1) - if [[ $? -eq 0 && -n "$amd_output" ]]; then - local amd_name=$(echo "$amd_output" | sed -n 's/.*: \(.*\)/\1/p' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') - if [[ -n "$amd_name" ]]; then - local amd_count=$(rocm-smi --showproductname 2>/dev/null | grep -c "GPU\[" || echo "1") - if [[ $amd_count -eq 1 ]]; then - gpu_info="$amd_name" - else - gpu_info="$amd_name (${amd_count} devices)" - fi - fi + fi + + # Method 2: Try rocm-smi for AMD GPUs (if no NVIDIA found) + if [[ "$gpu_info" == "no GPU detected" ]] && command -v rocm-smi &>/dev/null; then + local amd_output=$(rocm-smi --showproductname 2>/dev/null | grep -E "GPU\[" | head -n1) + if [[ $? -eq 0 && -n "$amd_output" ]]; then + local amd_name=$(echo "$amd_output" | sed -n 's/.*: \(.*\)/\1/p' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') + if [[ -n "$amd_name" ]]; then + local amd_count=$(rocm-smi --showproductname 2>/dev/null | grep -c "GPU\[" || echo "1") + if [[ $amd_count -eq 1 ]]; then + gpu_info="$amd_name" + else + gpu_info="$amd_name (${amd_count} devices)" fi + fi fi - - # Method 3: Try lspci as fallback for any GPU vendor - if [[ "$gpu_info" == "no GPU detected" ]] && command -v lspci &> /dev/null; then - local pci_gpus=$(lspci 2>/dev/null | grep -i "vga\|3d\|display" | grep -v "audio") - if [[ -n "$pci_gpus" ]]; then - gpu_count=$(echo "$pci_gpus" | wc -l) - local first_gpu_line=$(echo "$pci_gpus" | head -n1) - - # Extract GPU name from lspci output - local gpu_name="" - if echo "$first_gpu_line" | grep -qi "nvidia"; then - gpu_name=$(echo "$first_gpu_line" | sed -n 's/.*NVIDIA Corporation \(.*\) (rev.*/\1/p' | sed 's/\[.*\]//g' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') - [[ -z "$gpu_name" ]] && gpu_name=$(echo "$first_gpu_line" | sed -n 's/.*NVIDIA \(.*\)/\1/p' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') - [[ -z "$gpu_name" ]] && gpu_name="NVIDIA GPU" - elif echo "$first_gpu_line" | grep -qi "amd\|ati\|radeon"; then - gpu_name=$(echo "$first_gpu_line" | sed -n 's/.*Advanced Micro Devices.*\[\(.*\)\].*/\1/p' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') - [[ -z "$gpu_name" ]] && gpu_name=$(echo "$first_gpu_line" | sed -n 's/.*AMD\/ATI \(.*\)/\1/p' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') - [[ -z "$gpu_name" ]] && gpu_name="AMD GPU" - elif echo "$first_gpu_line" | grep -qi "intel"; then - gpu_name=$(echo "$first_gpu_line" | sed -n 's/.*Intel Corporation \(.*\) (rev.*/\1/p' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') - [[ -z "$gpu_name" ]] && gpu_name="Intel GPU" - else - gpu_name="Unknown GPU" - fi - - if [[ -n "$gpu_name" && "$gpu_name" != "Unknown GPU" ]]; then - if [[ $gpu_count -eq 1 ]]; then - gpu_info="$gpu_name" - else - gpu_info="$gpu_name (${gpu_count} devices)" - fi - fi + fi + + # Method 3: Try lspci as fallback for any GPU vendor + if [[ "$gpu_info" == "no GPU detected" ]] && command -v lspci &>/dev/null; then + local pci_gpus=$(lspci 2>/dev/null | grep -i "vga\|3d\|display" | grep -v "audio") + if [[ -n "$pci_gpus" ]]; then + gpu_count=$(echo "$pci_gpus" | wc -l) + local first_gpu_line=$(echo "$pci_gpus" | head -n1) + + # Extract GPU name from lspci output + local gpu_name="" + if echo "$first_gpu_line" | grep -qi "nvidia"; then + gpu_name=$(echo "$first_gpu_line" | sed -n 's/.*NVIDIA Corporation \(.*\) (rev.*/\1/p' | sed 's/\[.*\]//g' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') + [[ -z "$gpu_name" ]] && gpu_name=$(echo "$first_gpu_line" | sed -n 's/.*NVIDIA \(.*\)/\1/p' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') + [[ -z "$gpu_name" ]] && gpu_name="NVIDIA GPU" + elif echo "$first_gpu_line" | grep -qi "amd\|ati\|radeon"; then + gpu_name=$(echo "$first_gpu_line" | sed -n 's/.*Advanced Micro Devices.*\[\(.*\)\].*/\1/p' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') + [[ -z "$gpu_name" ]] && gpu_name=$(echo "$first_gpu_line" | sed -n 's/.*AMD\/ATI \(.*\)/\1/p' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') + [[ -z "$gpu_name" ]] && gpu_name="AMD GPU" + elif echo "$first_gpu_line" | grep -qi "intel"; then + gpu_name=$(echo "$first_gpu_line" | sed -n 's/.*Intel Corporation \(.*\) (rev.*/\1/p' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') + [[ -z "$gpu_name" ]] && gpu_name="Intel GPU" + else + gpu_name="Unknown GPU" + fi + + if [[ -n "$gpu_name" && "$gpu_name" != "Unknown GPU" ]]; then + if [[ $gpu_count -eq 1 ]]; then + gpu_info="$gpu_name" + else + gpu_info="$gpu_name (${gpu_count} devices)" fi + fi fi - - local nvidia_driver="unavailable" - local cuda_version="unavailable" - if command -v nvidia-smi &> /dev/null; then - nvidia_driver=$(nvidia-smi --query-gpu=driver_version --format=csv,noheader 2>/dev/null | head -n1 | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') - if [[ -z "$nvidia_driver" ]]; then - nvidia_driver="unavailable" - fi - local nvidia_banner=$(nvidia-smi 2>/dev/null | head -n 3 | tr '\n' ' ') - cuda_version=$(echo "$nvidia_banner" | sed -n 's/.*CUDA Version:[[:space:]]*\([0-9.]*\).*/\1/p') - cuda_version=$(echo "$cuda_version" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') - if [[ -z "$cuda_version" ]]; then - cuda_version="unavailable" - fi + fi + + local nvidia_driver="unavailable" + local cuda_version="unavailable" + if command -v nvidia-smi &>/dev/null; then + nvidia_driver=$(nvidia-smi --query-gpu=driver_version --format=csv,noheader 2>/dev/null | head -n1 | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') + if [[ -z "$nvidia_driver" ]]; then + nvidia_driver="unavailable" fi - - echo " ├─ GPU: $gpu_info" - echo " ├─ NVIDIA Driver: $nvidia_driver" - echo " └─ CUDA Version: $cuda_version" - echo "" - - # Configuration box with aligned formatting - ui_print_color "${UI_BLUE}${UI_BOLD}" "⚙️ Build Configuration:" - printf " ├─ %-15s %s\n" "MPI Mode:" "$(config_get MPI_MODE)" - printf " ├─ %-15s %s\n" "Math Mode:" "$(config_get MATH_MODE)" - printf " ├─ %-15s %s\n" "Target CPU:" "$(config_get TARGET_CPU)" - printf " ├─ %-15s %s\n" "GPU Version:" "$(config_get GPUVER)" - printf " └─ %-15s %s\n" "Parallel Jobs:" "$(config_get NPROCS_OVERWRITE)" - - # Special modes - if [[ "$(config_get dry_run)" == "__TRUE__" ]]; then - ui_print_color "${UI_YELLOW}${UI_BOLD}" " 🧪 Dry Run Mode: Preview only (no actual installation)" + local nvidia_banner=$(nvidia-smi 2>/dev/null | head -n 3 | tr '\n' ' ') + cuda_version=$(echo "$nvidia_banner" | sed -n 's/.*CUDA Version:[[:space:]]*\([0-9.]*\).*/\1/p') + cuda_version=$(echo "$cuda_version" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') + if [[ -z "$cuda_version" ]]; then + cuda_version="unavailable" fi - if [[ "$(config_get PACK_RUN)" == "__TRUE__" ]]; then - ui_print_color "${UI_YELLOW}${UI_BOLD}" " 📦 Pack Run Mode: System packages only" + fi + + echo " ├─ GPU: $gpu_info" + echo " ├─ NVIDIA Driver: $nvidia_driver" + echo " └─ CUDA Version: $cuda_version" + echo "" + + # Configuration box with aligned formatting + ui_print_color "${UI_BLUE}${UI_BOLD}" "⚙️ Build Configuration:" + printf " ├─ %-15s %s\n" "MPI Mode:" "$(config_get MPI_MODE)" + printf " ├─ %-15s %s\n" "Math Mode:" "$(config_get MATH_MODE)" + printf " ├─ %-15s %s\n" "Target CPU:" "$(config_get TARGET_CPU)" + printf " ├─ %-15s %s\n" "GPU Version:" "$(config_get GPUVER)" + printf " └─ %-15s %s\n" "Parallel Jobs:" "$(config_get NPROCS_OVERWRITE)" + + # Special modes + if [[ "$(config_get dry_run)" == "__TRUE__" ]]; then + ui_print_color "${UI_YELLOW}${UI_BOLD}" " 🧪 Dry Run Mode: Preview only (no actual installation)" + fi + if [[ "$(config_get PACK_RUN)" == "__TRUE__" ]]; then + ui_print_color "${UI_YELLOW}${UI_BOLD}" " 📦 Pack Run Mode: System packages only" + fi + echo "" + + # Package configuration table + ui_print_color "${UI_BLUE}${UI_BOLD}" "📦 Package Configuration:" + local has_packages=false + for pkg in ${package_list}; do + local status=$(config_get "with_${pkg}") + if [[ "$status" != "__DONTUSE__" ]]; then + has_packages=true + # Convert status for display + local display_status="$status" + local status_icon="" + case "$status" in + "__INSTALL__") + display_status="${UI_GREEN}install${UI_NC}" + status_icon="📥" + ;; + "__SYSTEM__") + display_status="${UI_BLUE}system${UI_NC}" + status_icon="🔗" + ;; + "__DONTUSE__") + display_status="${UI_GRAY}disabled${UI_NC}" + status_icon="❌" + ;; + *) + display_status="${UI_ORANGE}${status}${UI_NC}" + status_icon="📁" + ;; + esac + printf " ├─ %s %-12s %b %b\n" "$status_icon" "$pkg:" "$UI_ARROW" "$display_status" fi - echo "" - - # Package configuration table - ui_print_color "${UI_BLUE}${UI_BOLD}" "📦 Package Configuration:" - local has_packages=false - for pkg in ${package_list}; do - local status=$(config_get "with_${pkg}") - if [[ "$status" != "__DONTUSE__" ]]; then - has_packages=true - # Convert status for display - local display_status="$status" - local status_icon="" - case "$status" in - "__INSTALL__") - display_status="${UI_GREEN}install${UI_NC}" - status_icon="📥" - ;; - "__SYSTEM__") - display_status="${UI_BLUE}system${UI_NC}" - status_icon="🔗" - ;; - "__DONTUSE__") - display_status="${UI_GRAY}disabled${UI_NC}" - status_icon="❌" - ;; - *) - display_status="${UI_ORANGE}${status}${UI_NC}" - status_icon="📁" - ;; - esac - printf " ├─ %s %-12s %b %b\n" "$status_icon" "$pkg:" "$UI_ARROW" "$display_status" - fi + done + + if [[ "$has_packages" == "false" ]]; then + ui_print_color "${UI_GRAY}" " └─ No packages configured" + else + echo " └─ Configuration complete" + fi + echo "" + + # Installation summary + local install_list=$(package_list_to_install 2>/dev/null || echo "") + if [[ -n "$install_list" ]]; then + ui_print_color "${UI_GREEN}${UI_BOLD}" "🚀 Packages to be built from source:" + for pkg in $install_list; do + ui_print_color "${UI_GREEN}" " ${UI_ICON_BUILD} $pkg" done - - if [[ "$has_packages" == "false" ]]; then - ui_print_color "${UI_GRAY}" " └─ No packages configured" - else - echo " └─ Configuration complete" - fi echo "" - - # Installation summary - local install_list=$(package_list_to_install 2>/dev/null || echo "") - if [[ -n "$install_list" ]]; then - ui_print_color "${UI_GREEN}${UI_BOLD}" "🚀 Packages to be built from source:" - for pkg in $install_list; do - ui_print_color "${UI_GREEN}" " ${UI_ICON_BUILD} $pkg" - done - echo "" + fi + + # System packages + local system_packages="" + for pkg in ${package_list}; do + if [[ "$(config_get with_${pkg})" == "__SYSTEM__" ]]; then + system_packages="$system_packages $pkg" fi - - # System packages - local system_packages="" - for pkg in ${package_list}; do - if [[ "$(config_get with_${pkg})" == "__SYSTEM__" ]]; then - system_packages="$system_packages $pkg" - fi + done + + if [[ -n "$system_packages" ]]; then + ui_print_color "${UI_BLUE}${UI_BOLD}" "🔗 System packages to be used:" + for pkg in $system_packages; do + ui_print_color "${UI_BLUE}" " ${UI_ICON_CHECK} $pkg" done - - if [[ -n "$system_packages" ]]; then - ui_print_color "${UI_BLUE}${UI_BOLD}" "🔗 System packages to be used:" - for pkg in $system_packages; do - ui_print_color "${UI_BLUE}" " ${UI_ICON_CHECK} $pkg" - done - echo "" - fi + echo "" + fi } # Confirm installation with user # Usage: ui_confirm_installation ui_confirm_installation() { - # Skip confirmation in dry-run mode - if [[ "$(config_get dry_run)" == "__TRUE__" ]]; then - ui_info "Dry run mode - no actual installation will be performed" - return 0 - fi - - # Skip confirmation in quiet mode - if [[ "$UI_QUIET" == "true" ]]; then - return 0 - fi - - # Simple confirmation prompt - echo "" - echo -n "Proceed with installation? [y/N]: " - read -r response - - case "$response" in - [yY]|[yY][eE][sS]) - return 0 - ;; - *) - ui_info "Installation cancelled" - return 1 - ;; - esac + # Skip confirmation in dry-run mode + if [[ "$(config_get dry_run)" == "__TRUE__" ]]; then + ui_info "Dry run mode - no actual installation will be performed" + return 0 + fi + + # Skip confirmation in quiet mode + if [[ "$UI_QUIET" == "true" ]]; then + return 0 + fi + + # Simple confirmation prompt + echo "" + echo -n "Proceed with installation? [y/N]: " + read -r response + + case "$response" in + [yY] | [yY][eE][sS]) + return 0 + ;; + *) + ui_info "Installation cancelled" + return 1 + ;; + esac } # Show installation progress for a stage with enhanced styling # Usage: ui_stage_progress "stage_number" "stage_name" ui_stage_progress() { - local stage="$1" - local name="$2" - - ui_section "Stage $stage: $name" - ui_print_color "${UI_CYAN}${UI_BOLD}" "${UI_ICON_ROCKET} Installing packages for stage $stage..." + local stage="$1" + local name="$2" + + ui_section "Stage $stage: $name" + ui_print_color "${UI_CYAN}${UI_BOLD}" "${UI_ICON_ROCKET} Installing packages for stage $stage..." } # Show package build progress with enhanced visual feedback # Usage: ui_package_progress "package_name" "action" ui_package_progress() { - local package="$1" - local action="$2" - - case "$action" in - start) - ui_print_color "${UI_BLUE}${UI_BOLD}" "${UI_ICON_BUILD} Building $package..." - ;; - download) - ui_debug "${UI_ICON_DOWNLOAD} Downloading $package..." - ;; - extract) - ui_debug "${UI_ICON_PACKAGE} Extracting $package..." - ;; - configure) - ui_debug "${UI_ICON_GEAR} Configuring $package..." - ;; - compile) - ui_debug "${UI_ICON_BUILD} Compiling $package..." - ;; - install) - ui_debug "${UI_ICON_INSTALL} Installing $package..." - ;; - success) - ui_success "Successfully built $package" - ;; - skip) - ui_print_color "${UI_GRAY}${UI_BOLD}" "${UI_ICON_INFO} Skipping $package (already built or disabled)" - ;; - error) - ui_error "Failed to build $package" - ;; - esac + local package="$1" + local action="$2" + + case "$action" in + start) + ui_print_color "${UI_BLUE}${UI_BOLD}" "${UI_ICON_BUILD} Building $package..." + ;; + download) + ui_debug "${UI_ICON_DOWNLOAD} Downloading $package..." + ;; + extract) + ui_debug "${UI_ICON_PACKAGE} Extracting $package..." + ;; + configure) + ui_debug "${UI_ICON_GEAR} Configuring $package..." + ;; + compile) + ui_debug "${UI_ICON_BUILD} Compiling $package..." + ;; + install) + ui_debug "${UI_ICON_INSTALL} Installing $package..." + ;; + success) + ui_success "Successfully built $package" + ;; + skip) + ui_print_color "${UI_GRAY}${UI_BOLD}" "${UI_ICON_INFO} Skipping $package (already built or disabled)" + ;; + error) + ui_error "Failed to build $package" + ;; + esac } # Show enhanced final installation results # Usage: ui_show_results "success_count" "total_count" "failed_packages" ui_show_results() { - local success_count="$1" - local total_count="$2" - local failed_packages="$3" - - ui_section "Installation Results" - - if [[ $success_count -eq $total_count ]]; then - ui_success "All packages installed successfully! ($success_count/$total_count)" - echo "" - ui_print_color "${UI_GREEN}${UI_BOLD}" "${UI_ICON_ROCKET} Ready to use ABACUS toolchain!" - echo "" - ui_print_color "${UI_BLUE}${UI_BOLD}" "🔧 To activate the toolchain environment:" - ui_print_color "${UI_WHITE}" " source ${SETUPFILE:-setup}" - ui_print_color "${UI_GRAY}" " # or alternatively:" - ui_print_color "${UI_WHITE}" " source ${INSTALLDIR:-install}/abacus_env.sh" - echo "" - ui_print_color "${UI_BLUE}${UI_BOLD}" "🚀 Build ABACUS with:" - ui_print_color "${UI_WHITE}" " ./build_abacus_gnu.sh # GNU toolchain" - ui_print_color "${UI_WHITE}" " ./build_abacus_intel.sh # Intel toolchain" - ui_print_color "${UI_WHITE}" " ./build_abacus_gcc-aocl.sh # AMD GCC+AOCL" - ui_print_color "${UI_WHITE}" " ./build_abacus_aocc-aocl.sh # AMD AOCC+AOCL" - else - local failed_count=$((total_count - success_count)) - ui_error "Installation completed with errors ($success_count/$total_count successful)" - echo "" - if [[ -n "$failed_packages" ]]; then - ui_print_color "${UI_RED}${UI_BOLD}" "❌ Failed packages:" - for pkg in $failed_packages; do - ui_print_color "${UI_RED}" " ${UI_ICON_CROSS} $pkg" - done - fi - echo "" - ui_print_color "${UI_YELLOW}${UI_BOLD}" "🔍 Troubleshooting tips:" - ui_print_color "${UI_YELLOW}" " • Check log files for detailed error information" - ui_print_color "${UI_YELLOW}" " • Install missing system dependencies" - ui_print_color "${UI_YELLOW}" " • Verify network connectivity for downloads" - ui_print_color "${UI_YELLOW}" " • Try with --install-all for problematic packages" + local success_count="$1" + local total_count="$2" + local failed_packages="$3" + + ui_section "Installation Results" + + if [[ $success_count -eq $total_count ]]; then + ui_success "All packages installed successfully! ($success_count/$total_count)" + echo "" + ui_print_color "${UI_GREEN}${UI_BOLD}" "${UI_ICON_ROCKET} Ready to use ABACUS toolchain!" + echo "" + ui_print_color "${UI_BLUE}${UI_BOLD}" "🔧 To activate the toolchain environment:" + ui_print_color "${UI_WHITE}" " source ${SETUPFILE:-setup}" + ui_print_color "${UI_GRAY}" " # or alternatively:" + ui_print_color "${UI_WHITE}" " source ${INSTALLDIR:-install}/abacus_env.sh" + echo "" + ui_print_color "${UI_BLUE}${UI_BOLD}" "🚀 Build ABACUS with:" + ui_print_color "${UI_WHITE}" " ./build_abacus_gnu.sh # GNU toolchain" + ui_print_color "${UI_WHITE}" " ./build_abacus_intel.sh # Intel toolchain" + ui_print_color "${UI_WHITE}" " ./build_abacus_gcc-aocl.sh # AMD GCC+AOCL" + ui_print_color "${UI_WHITE}" " ./build_abacus_aocc-aocl.sh # AMD AOCC+AOCL" + else + local failed_count=$((total_count - success_count)) + ui_error "Installation completed with errors ($success_count/$total_count successful)" + echo "" + if [[ -n "$failed_packages" ]]; then + ui_print_color "${UI_RED}${UI_BOLD}" "❌ Failed packages:" + for pkg in $failed_packages; do + ui_print_color "${UI_RED}" " ${UI_ICON_CROSS} $pkg" + done fi + echo "" + ui_print_color "${UI_YELLOW}${UI_BOLD}" "🔍 Troubleshooting tips:" + ui_print_color "${UI_YELLOW}" " • Check log files for detailed error information" + ui_print_color "${UI_YELLOW}" " • Install missing system dependencies" + ui_print_color "${UI_YELLOW}" " • Verify network connectivity for downloads" + ui_print_color "${UI_YELLOW}" " • Try with --install-all for problematic packages" + fi } # Show enhanced environment setup instructions # Usage: ui_show_env_setup ui_show_env_setup() { - ui_section "Environment Setup Instructions" - - ui_print_color "${UI_BLUE}${UI_BOLD}" "🔧 To use the installed ABACUS toolchain:" - echo "" - ui_print_color "${UI_GREEN}${UI_BOLD}" " source ${SETUPFILE:-setup}" - ui_print_color "${UI_GRAY}" " # or" - ui_print_color "${UI_GREEN}${UI_BOLD}" " source ${INSTALLDIR:-install}/abacus_env.sh" - echo "" - ui_print_color "${UI_BLUE}${UI_BOLD}" "🚀 Then build ABACUS with:" - ui_print_color "${UI_GREEN}${UI_BOLD}" " make -j\$(nproc)" - echo "" - ui_warning "The environment setup needs to be done in each new shell session" + ui_section "Environment Setup Instructions" + + ui_print_color "${UI_BLUE}${UI_BOLD}" "🔧 To use the installed ABACUS toolchain:" + echo "" + ui_print_color "${UI_GREEN}${UI_BOLD}" " source ${SETUPFILE:-setup}" + ui_print_color "${UI_GRAY}" " # or" + ui_print_color "${UI_GREEN}${UI_BOLD}" " source ${INSTALLDIR:-install}/abacus_env.sh" + echo "" + ui_print_color "${UI_BLUE}${UI_BOLD}" "🚀 Then build ABACUS with:" + ui_print_color "${UI_GREEN}${UI_BOLD}" " make -j\$(nproc)" + echo "" + ui_warning "The environment setup needs to be done in each new shell session" } # Handle user interruption with graceful cleanup # Usage: ui_handle_interrupt ui_handle_interrupt() { - echo "" - ui_warning "Installation interrupted by user (Ctrl+C)" - ui_print_color "${UI_BLUE}${UI_BOLD}" "${UI_ICON_GEAR} Cleaning up temporary files..." - - # Clean up any temporary files or processes - if [[ -n "$BUILDDIR" && -d "$BUILDDIR" ]]; then - ui_debug "Cleaning build directory: $BUILDDIR" - # Don't remove the entire build directory, just mark as interrupted - touch "$BUILDDIR/.interrupted" - fi - - ui_print_color "${UI_YELLOW}${UI_BOLD}" "${UI_ICON_INFO} Installation cancelled - you can resume later" - exit 130 + echo "" + ui_warning "Installation interrupted by user (Ctrl+C)" + ui_print_color "${UI_BLUE}${UI_BOLD}" "${UI_ICON_GEAR} Cleaning up temporary files..." + + # Clean up any temporary files or processes + if [[ -n "$BUILDDIR" && -d "$BUILDDIR" ]]; then + ui_debug "Cleaning build directory: $BUILDDIR" + # Don't remove the entire build directory, just mark as interrupted + touch "$BUILDDIR/.interrupted" + fi + + ui_print_color "${UI_YELLOW}${UI_BOLD}" "${UI_ICON_INFO} Installation cancelled - you can resume later" + exit 130 } # Set up signal handlers # Usage: ui_setup_signals ui_setup_signals() { - trap ui_handle_interrupt SIGINT SIGTERM + trap ui_handle_interrupt SIGINT SIGTERM } # Enhanced input validation with helpful error messages # Usage: ui_validate_input "input" "type" ui_validate_input() { - local input="$1" - local type="$2" - - case "$type" in - number) - if [[ ! "$input" =~ ^[0-9]+$ ]]; then - ui_error "Invalid number: $input" - ui_info "Please provide a positive integer" - return 1 - fi - ;; - path) - if [[ ! -d "$input" ]]; then - ui_error "Directory does not exist: $input" - ui_info "Please provide a valid directory path" - return 1 - fi - ;; - file) - if [[ ! -f "$input" ]]; then - ui_error "File does not exist: $input" - ui_info "Please provide a valid file path" - return 1 - fi - ;; - mpi_mode) - case "$input" in - mpich|openmpi|intelmpi|no) - return 0 - ;; - *) - ui_error "Invalid MPI mode: $input" - ui_print_color "${UI_BLUE}${UI_BOLD}" "📋 Valid options:" - ui_print_color "${UI_GREEN}" " • mpich - MPICH implementation (recommended)" - ui_print_color "${UI_GREEN}" " • openmpi - Open MPI implementation" - ui_print_color "${UI_GREEN}" " • intelmpi - Intel MPI (requires Intel compiler)" - ui_print_color "${UI_GREEN}" " • no - Disable MPI support" - return 1 - ;; - esac - ;; - math_mode) - case "$input" in - cray|mkl|openblas|aocl) - return 0 - ;; - *) - ui_error "Invalid math mode: $input" - ui_print_color "${UI_BLUE}${UI_BOLD}" "📋 Valid options:" - ui_print_color "${UI_GREEN}" " • openblas - OpenBLAS (open source, recommended)" - ui_print_color "${UI_GREEN}" " • mkl - Intel Math Kernel Library (high performance)" - ui_print_color "${UI_GREEN}" " • aocl - AMD Optimizing CPU Libraries" - ui_print_color "${UI_GREEN}" " • cray - Cray LibSci (for Cray systems)" - return 1 - ;; - esac - ;; - gpu_version) - # Support only numeric formats for GPU versions - if [[ "$input" == "no" ]]; then - return 0 - fi - - # Check if it's a valid numeric format (like 8.0, 70, 80, etc.) - local arch_num="${input//.}" - if [[ "$arch_num" =~ ^[1-9][0-9]*$ ]]; then - return 0 - fi - - # Invalid format - show enhanced error message - ui_error "Invalid GPU version: $input" - ui_print_color "${UI_BLUE}${UI_BOLD}" "📋 Valid formats:" - ui_print_color "${UI_GREEN}" " • Decimal format: 6.0, 7.0, 8.0, 8.9, etc. (CUDA compute capability)" - ui_print_color "${UI_GREEN}" " • Integer format: 60, 70, 80, 89, etc." - ui_print_color "${UI_GREEN}" " • Disable GPU: no" - ui_print_color "${UI_ORANGE}${UI_BOLD}" "💡 Examples:" - ui_print_color "${UI_WHITE}" " • 8.0 or 80 for compute capability 8.0 (RTX 30xx series)" - ui_print_color "${UI_WHITE}" " • 7.5 or 75 for compute capability 7.5 (RTX 20xx series)" - return 1 - ;; - *) - ui_error "Unknown validation type: $type" - return 1 - ;; + local input="$1" + local type="$2" + + case "$type" in + number) + if [[ ! "$input" =~ ^[0-9]+$ ]]; then + ui_error "Invalid number: $input" + ui_info "Please provide a positive integer" + return 1 + fi + ;; + path) + if [[ ! -d "$input" ]]; then + ui_error "Directory does not exist: $input" + ui_info "Please provide a valid directory path" + return 1 + fi + ;; + file) + if [[ ! -f "$input" ]]; then + ui_error "File does not exist: $input" + ui_info "Please provide a valid file path" + return 1 + fi + ;; + mpi_mode) + case "$input" in + mpich | openmpi | intelmpi | no) + return 0 + ;; + *) + ui_error "Invalid MPI mode: $input" + ui_print_color "${UI_BLUE}${UI_BOLD}" "📋 Valid options:" + ui_print_color "${UI_GREEN}" " • mpich - MPICH implementation (recommended)" + ui_print_color "${UI_GREEN}" " • openmpi - Open MPI implementation" + ui_print_color "${UI_GREEN}" " • intelmpi - Intel MPI (requires Intel compiler)" + ui_print_color "${UI_GREEN}" " • no - Disable MPI support" + return 1 + ;; esac - - return 0 + ;; + math_mode) + case "$input" in + cray | mkl | openblas | aocl) + return 0 + ;; + *) + ui_error "Invalid math mode: $input" + ui_print_color "${UI_BLUE}${UI_BOLD}" "📋 Valid options:" + ui_print_color "${UI_GREEN}" " • openblas - OpenBLAS (open source, recommended)" + ui_print_color "${UI_GREEN}" " • mkl - Intel Math Kernel Library (high performance)" + ui_print_color "${UI_GREEN}" " • aocl - AMD Optimizing CPU Libraries" + ui_print_color "${UI_GREEN}" " • cray - Cray LibSci (for Cray systems)" + return 1 + ;; + esac + ;; + gpu_version) + # Support only numeric formats for GPU versions + if [[ "$input" == "no" ]]; then + return 0 + fi + + # Check if it's a valid numeric format (like 8.0, 70, 80, etc.) + local arch_num="${input//./}" + if [[ "$arch_num" =~ ^[1-9][0-9]*$ ]]; then + return 0 + fi + + # Invalid format - show enhanced error message + ui_error "Invalid GPU version: $input" + ui_print_color "${UI_BLUE}${UI_BOLD}" "📋 Valid formats:" + ui_print_color "${UI_GREEN}" " • Decimal format: 6.0, 7.0, 8.0, 8.9, etc. (CUDA compute capability)" + ui_print_color "${UI_GREEN}" " • Integer format: 60, 70, 80, 89, etc." + ui_print_color "${UI_GREEN}" " • Disable GPU: no" + ui_print_color "${UI_ORANGE}${UI_BOLD}" "💡 Examples:" + ui_print_color "${UI_WHITE}" " • 8.0 or 80 for compute capability 8.0 (RTX 30xx series)" + ui_print_color "${UI_WHITE}" " • 7.5 or 75 for compute capability 7.5 (RTX 20xx series)" + return 1 + ;; + *) + ui_error "Unknown validation type: $type" + return 1 + ;; + esac + + return 0 } # Enhanced system information display # Usage: ui_show_system_info ui_show_system_info() { - ui_section "System Information" - - ui_print_color "${UI_BLUE}${UI_BOLD}" "🖥️ Hardware & OS:" - printf " ├─ %-20s %s\n" "Operating System:" "$(uname -s)" - printf " ├─ %-20s %s\n" "Architecture:" "$(uname -m)" - printf " ├─ %-20s %s\n" "Kernel Version:" "$(uname -r)" - printf " ├─ %-20s %s\n" "CPU Cores:" "$(nproc 2>/dev/null || echo "unknown")" - - if command -v free &> /dev/null; then - local mem_gb=$(free -g | awk '/^Mem:/ {print $2}') - printf " ├─ %-20s %sGB\n" "Total Memory:" "$mem_gb" - fi - - printf " ├─ %-20s %s\n" "Shell:" "$SHELL" - printf " ├─ %-20s %s\n" "User:" "$(whoami)" - printf " └─ %-20s %s\n" "Working Directory:" "$(pwd)" - echo "" + ui_section "System Information" + + ui_print_color "${UI_BLUE}${UI_BOLD}" "🖥️ Hardware & OS:" + printf " ├─ %-20s %s\n" "Operating System:" "$(uname -s)" + printf " ├─ %-20s %s\n" "Architecture:" "$(uname -m)" + printf " ├─ %-20s %s\n" "Kernel Version:" "$(uname -r)" + printf " ├─ %-20s %s\n" "CPU Cores:" "$(nproc 2>/dev/null || echo "unknown")" + + if command -v free &>/dev/null; then + local mem_gb=$(free -g | awk '/^Mem:/ {print $2}') + printf " ├─ %-20s %sGB\n" "Total Memory:" "$mem_gb" + fi + + printf " ├─ %-20s %s\n" "Shell:" "$SHELL" + printf " ├─ %-20s %s\n" "User:" "$(whoami)" + printf " └─ %-20s %s\n" "Working Directory:" "$(pwd)" + echo "" } # Enhanced system requirements check # Usage: ui_check_system_requirements ui_check_system_requirements() { - ui_section "System Requirements Check" - - local missing_tools="" - local required_tools="wget curl tar gzip make" - local found_tools="" - - ui_print_color "${UI_BLUE}${UI_BOLD}" "🔍 Checking required system tools..." - - for tool in $required_tools; do - if ! command -v "$tool" &> /dev/null; then - missing_tools="$missing_tools $tool" - ui_print_color "${UI_RED}" " ${UI_ICON_CROSS} $tool - not found" - else - found_tools="$found_tools $tool" - ui_print_color "${UI_GREEN}" " ${UI_ICON_CHECK} $tool - found" - fi - done - - echo "" - - if [[ -n "$missing_tools" ]]; then - ui_error "Missing required system tools:$missing_tools" - echo "" - ui_print_color "${UI_YELLOW}${UI_BOLD}" "📦 Install missing tools using your package manager:" - ui_print_color "${UI_WHITE}" " # Ubuntu/Debian:" - ui_print_color "${UI_GREEN}" " sudo apt-get install$missing_tools" - ui_print_color "${UI_WHITE}" " # CentOS/RHEL:" - ui_print_color "${UI_GREEN}" " sudo yum install$missing_tools" - ui_print_color "${UI_WHITE}" " # Fedora:" - ui_print_color "${UI_GREEN}" " sudo dnf install$missing_tools" - return 1 + ui_section "System Requirements Check" + + local missing_tools="" + local required_tools="wget curl tar gzip make" + local found_tools="" + + ui_print_color "${UI_BLUE}${UI_BOLD}" "🔍 Checking required system tools..." + + for tool in $required_tools; do + if ! command -v "$tool" &>/dev/null; then + missing_tools="$missing_tools $tool" + ui_print_color "${UI_RED}" " ${UI_ICON_CROSS} $tool - not found" else - ui_success "All required system tools are available" - return 0 + found_tools="$found_tools $tool" + ui_print_color "${UI_GREEN}" " ${UI_ICON_CHECK} $tool - found" fi + done + + echo "" + + if [[ -n "$missing_tools" ]]; then + ui_error "Missing required system tools:$missing_tools" + echo "" + ui_print_color "${UI_YELLOW}${UI_BOLD}" "📦 Install missing tools using your package manager:" + ui_print_color "${UI_WHITE}" " # Ubuntu/Debian:" + ui_print_color "${UI_GREEN}" " sudo apt-get install$missing_tools" + ui_print_color "${UI_WHITE}" " # CentOS/RHEL:" + ui_print_color "${UI_GREEN}" " sudo yum install$missing_tools" + ui_print_color "${UI_WHITE}" " # Fedora:" + ui_print_color "${UI_GREEN}" " sudo dnf install$missing_tools" + return 1 + else + ui_success "All required system tools are available" + return 0 + fi } diff --git a/toolchain/scripts/lib/version_helper.sh b/toolchain/scripts/lib/version_helper.sh index d5bde1cfb69..9bb1b969ff6 100644 --- a/toolchain/scripts/lib/version_helper.sh +++ b/toolchain/scripts/lib/version_helper.sh @@ -11,64 +11,64 @@ # Source required modules if [[ -f "${SCRIPTDIR}/package_versions.sh" ]]; then - source "${SCRIPTDIR}/package_versions.sh" + source "${SCRIPTDIR}/package_versions.sh" else - echo "Error: package_versions.sh not found in ${SCRIPTDIR}" >&2 - return 1 + echo "Error: package_versions.sh not found in ${SCRIPTDIR}" >&2 + return 1 fi # Display available package versions # Usage: version_show_available [package_name] version_show_available() { - local package_name="${1:-all}" - - echo "Available Package Versions:" - echo "==========================" - echo - - if [[ "${package_name}" == "all" ]]; then - # Show all packages - for pkg in gcc cmake openmpi mpich openblas elpa fftw libxc scalapack libtorch libnpy; do - version_show_package_info "${pkg}" - done - else - version_show_package_info "${package_name}" - fi + local package_name="${1:-all}" + + echo "Available Package Versions:" + echo "==========================" + echo + + if [[ "${package_name}" == "all" ]]; then + # Show all packages + for pkg in gcc cmake openmpi mpich openblas elpa fftw libxc scalapack libtorch libnpy; do + version_show_package_info "${pkg}" + done + else + version_show_package_info "${package_name}" + fi } # Helper function to show package information version_show_package_info() { - local pkg="$1" - local main_var="${pkg}_main_ver" - local alt_var="${pkg}_alt_ver" - - # Get values using indirect variable expansion - local main_ver="${!main_var}" - local alt_ver="${!alt_var}" - - if [[ -n "$main_ver" || -n "$alt_ver" ]]; then - printf "%-12s: " "$pkg" - - if [[ -n "$main_ver" ]]; then - printf "%s (main)" "$main_ver" - fi - - if [[ -n "$alt_ver" ]]; then - if [[ -n "$main_ver" ]]; then - printf ", %s (alt)" "$alt_ver" - else - printf "%s (alt)" "$alt_ver" - fi - fi - - echo "" + local pkg="$1" + local main_var="${pkg}_main_ver" + local alt_var="${pkg}_alt_ver" + + # Get values using indirect variable expansion + local main_ver="${!main_var}" + local alt_ver="${!alt_var}" + + if [[ -n "$main_ver" || -n "$alt_ver" ]]; then + printf "%-12s: " "$pkg" + + if [[ -n "$main_ver" ]]; then + printf "%s (main)" "$main_ver" + fi + + if [[ -n "$alt_ver" ]]; then + if [[ -n "$main_ver" ]]; then + printf ", %s (alt)" "$alt_ver" + else + printf "%s (alt)" "$alt_ver" + fi fi + + echo "" + fi } # Display version switching help # Usage: version_show_help version_show_help() { - cat << 'EOF' + cat <<'EOF' ABACUS Toolchain Version Switching Help ======================================= @@ -118,213 +118,213 @@ EOF # Interactive version selection interface # Usage: version_interactive_select version_interactive_select() { - echo "Interactive Version Selection" - echo "============================" - echo "" - - local packages=( - "openmpi" "mpich" "openblas" "elpa" "fftw" - "libxc" "scalapack" "libtorch" "libnpy" - ) - - echo "Select versions for packages (press Enter for default 'main'):" - echo "" - - for pkg in "${packages[@]}"; do - local main_var="${pkg^^}_main_ver" - local alt_var="${pkg^^}_alt_ver" - - # Skip if no versions available - if [[ -z "${!main_var}" && -z "${!alt_var}" ]]; then - continue - fi - - printf "%-12s: " "$pkg" - - # Show available versions - if [[ -n "${!main_var}" ]]; then - printf "main(%s)" "${!main_var}" - fi - if [[ -n "${!alt_var}" ]]; then - if [[ -n "${!main_var}" ]]; then - printf ", alt(%s)" "${!alt_var}" - else - printf "alt(%s)" "${!alt_var}" - fi - fi - - printf " [main]: " - read -r user_choice - - # Set user choice or default to main - case "$user_choice" in - alt|alternative) - if [[ -n "${!alt_var}" ]]; then - CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="alt" - echo " → Selected: alt (${!alt_var})" - else - echo " → Alternative version not available, using main" - CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="main" - fi - ;; - main|"") - CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="main" - if [[ -n "${!main_var}" ]]; then - echo " → Selected: main (${!main_var})" - else - echo " → Main version not available" - fi - ;; - *) - echo " → Invalid choice, using main" - CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="main" - ;; - esac - echo "" - done - - echo "Version selection completed!" + echo "Interactive Version Selection" + echo "============================" + echo "" + + local packages=( + "openmpi" "mpich" "openblas" "elpa" "fftw" + "libxc" "scalapack" "libtorch" "libnpy" + ) + + echo "Select versions for packages (press Enter for default 'main'):" + echo "" + + for pkg in "${packages[@]}"; do + local main_var="${pkg^^}_main_ver" + local alt_var="${pkg^^}_alt_ver" + + # Skip if no versions available + if [[ -z "${!main_var}" && -z "${!alt_var}" ]]; then + continue + fi + + printf "%-12s: " "$pkg" + + # Show available versions + if [[ -n "${!main_var}" ]]; then + printf "main(%s)" "${!main_var}" + fi + if [[ -n "${!alt_var}" ]]; then + if [[ -n "${!main_var}" ]]; then + printf ", alt(%s)" "${!alt_var}" + else + printf "alt(%s)" "${!alt_var}" + fi + fi + + printf " [main]: " + read -r user_choice + + # Set user choice or default to main + case "$user_choice" in + alt | alternative) + if [[ -n "${!alt_var}" ]]; then + CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="alt" + echo " → Selected: alt (${!alt_var})" + else + echo " → Alternative version not available, using main" + CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="main" + fi + ;; + main | "") + CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="main" + if [[ -n "${!main_var}" ]]; then + echo " → Selected: main (${!main_var})" + else + echo " → Main version not available" + fi + ;; + *) + echo " → Invalid choice, using main" + CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="main" + ;; + esac echo "" + done + + echo "Version selection completed!" + echo "" } # Get effective version for a package # Usage: version_get_effective PACKAGE_NAME version_get_effective() { - local package_name="$1" - local pkg_upper="${package_name^^}" - - # Check for specific package version setting - local specific_version="${CONFIG_CACHE[PACKAGE_VERSION_${pkg_upper}]}" - if [[ -n "$specific_version" ]]; then - echo "$specific_version" - return 0 - fi - - # Check for global version strategy - local global_strategy="${CONFIG_CACHE[VERSION_STRATEGY]}" - if [[ -n "$global_strategy" ]]; then - echo "$global_strategy" - return 0 - fi - - # Check for legacy OPENMPI_4TH support - if [[ "$package_name" == "openmpi" && "${CONFIG_CACHE[OPENMPI_4TH]}" == "yes" ]]; then - echo "alt" - return 0 - fi - - # Default to main - echo "main" + local package_name="$1" + local pkg_upper="${package_name^^}" + + # Check for specific package version setting + local specific_version="${CONFIG_CACHE[PACKAGE_VERSION_${pkg_upper}]}" + if [[ -n "$specific_version" ]]; then + echo "$specific_version" return 0 + fi + + # Check for global version strategy + local global_strategy="${CONFIG_CACHE[VERSION_STRATEGY]}" + if [[ -n "$global_strategy" ]]; then + echo "$global_strategy" + return 0 + fi + + # Check for legacy OPENMPI_4TH support + if [[ "$package_name" == "openmpi" && "${CONFIG_CACHE[OPENMPI_4TH]}" == "yes" ]]; then + echo "alt" + return 0 + fi + + # Default to main + echo "main" + return 0 } # Load package variables with version selection # Usage: version_load_package_vars PACKAGE_NAME version_load_package_vars() { - local package_name="$1" - local effective_version - - effective_version=$(version_get_effective "$package_name") - - # Convert effective version to suffix for load_package_vars - local version_suffix="" - if [[ "$effective_version" == "alt" ]]; then - version_suffix="alt" - fi - - # Call the original load_package_vars function - load_package_vars "$package_name" "$version_suffix" - - # Export version information for debugging - export "${package_name^^}_EFFECTIVE_VERSION"="$effective_version" + local package_name="$1" + local effective_version + + effective_version=$(version_get_effective "$package_name") + + # Convert effective version to suffix for load_package_vars + local version_suffix="" + if [[ "$effective_version" == "alt" ]]; then + version_suffix="alt" + fi + + # Call the original load_package_vars function + load_package_vars "$package_name" "$version_suffix" + + # Export version information for debugging + export "${package_name^^}_EFFECTIVE_VERSION"="$effective_version" } # Display current version configuration # Usage: version_show_current version_show_current() { - echo "Current Version Configuration:" - echo "=============================" - - # Show global strategy - local global_strategy="${CONFIG_CACHE[VERSION_STRATEGY]}" - if [[ -n "$global_strategy" ]]; then - echo "Global Strategy: $global_strategy" - else - echo "Global Strategy: main (default)" - fi - echo "" - - # Show per-package settings - echo "Package-specific settings:" - local packages=( - "gcc" "cmake" "openmpi" "mpich" "openblas" - "elpa" "fftw" "libxc" "scalapack" "libtorch" "libnpy" - ) - - local has_specific=false - for pkg in "${packages[@]}"; do - local pkg_upper="${pkg^^}" - local specific_version="${CONFIG_CACHE[PACKAGE_VERSION_${pkg_upper}]}" - - if [[ -n "$specific_version" ]]; then - printf " %-12s: %s\n" "$pkg" "$specific_version" - has_specific=true - fi - done - - if [[ "$has_specific" == false ]]; then - echo " (none - using global strategy)" + echo "Current Version Configuration:" + echo "=============================" + + # Show global strategy + local global_strategy="${CONFIG_CACHE[VERSION_STRATEGY]}" + if [[ -n "$global_strategy" ]]; then + echo "Global Strategy: $global_strategy" + else + echo "Global Strategy: main (default)" + fi + echo "" + + # Show per-package settings + echo "Package-specific settings:" + local packages=( + "gcc" "cmake" "openmpi" "mpich" "openblas" + "elpa" "fftw" "libxc" "scalapack" "libtorch" "libnpy" + ) + + local has_specific=false + for pkg in "${packages[@]}"; do + local pkg_upper="${pkg^^}" + local specific_version="${CONFIG_CACHE[PACKAGE_VERSION_${pkg_upper}]}" + + if [[ -n "$specific_version" ]]; then + printf " %-12s: %s\n" "$pkg" "$specific_version" + has_specific=true fi - + done + + if [[ "$has_specific" == false ]]; then + echo " (none - using global strategy)" + fi + + echo "" + + # Show legacy compatibility + if [[ "${CONFIG_CACHE[OPENMPI_4TH]}" == "yes" ]]; then + echo "Legacy compatibility: OPENMPI_4TH=yes (equivalent to openmpi:alt)" echo "" - - # Show legacy compatibility - if [[ "${CONFIG_CACHE[OPENMPI_4TH]}" == "yes" ]]; then - echo "Legacy compatibility: OPENMPI_4TH=yes (equivalent to openmpi:alt)" - echo "" - fi + fi } # Validate version configuration # Usage: version_validate_config version_validate_config() { - local validation_errors=0 - - # Check if requested versions are available - for key in "${!CONFIG_CACHE[@]}"; do - if [[ "$key" =~ ^PACKAGE_VERSION_(.+)$ ]]; then - local pkg_name="${BASH_REMATCH[1]}" - local requested_version="${CONFIG_CACHE[$key]}" - local pkg_lower=$(echo "$pkg_name" | tr '[:upper:]' '[:lower:]') - - # Check if the requested version exists - local version_var="${pkg_lower}_${requested_version}_ver" - if [[ -z "${!version_var}" ]]; then - echo "Warning: Requested version '$requested_version' for package '$pkg_lower' is not available" - validation_errors=$((validation_errors + 1)) - fi - fi - done - - return $validation_errors + local validation_errors=0 + + # Check if requested versions are available + for key in "${!CONFIG_CACHE[@]}"; do + if [[ "$key" =~ ^PACKAGE_VERSION_(.+)$ ]]; then + local pkg_name="${BASH_REMATCH[1]}" + local requested_version="${CONFIG_CACHE[$key]}" + local pkg_lower=$(echo "$pkg_name" | tr '[:upper:]' '[:lower:]') + + # Check if the requested version exists + local version_var="${pkg_lower}_${requested_version}_ver" + if [[ -z "${!version_var}" ]]; then + echo "Warning: Requested version '$requested_version' for package '$pkg_lower' is not available" + validation_errors=$((validation_errors + 1)) + fi + fi + done + + return $validation_errors } # Initialize version helper # Usage: version_helper_init version_helper_init() { - # Set default version strategy if not set - if [[ -z "${CONFIG_CACHE[VERSION_STRATEGY]}" ]]; then - CONFIG_CACHE["VERSION_STRATEGY"]="main" - fi - - # Handle legacy OPENMPI_4TH environment variable - if [[ "${OPENMPI_4TH}" == "yes" && -z "${CONFIG_CACHE[PACKAGE_VERSION_OPENMPI]}" ]]; then - CONFIG_CACHE["PACKAGE_VERSION_OPENMPI"]="alt" - CONFIG_CACHE["OPENMPI_4TH"]="yes" - echo "Notice: Legacy OPENMPI_4TH=yes detected, using openmpi:alt" - fi - - return 0 + # Set default version strategy if not set + if [[ -z "${CONFIG_CACHE[VERSION_STRATEGY]}" ]]; then + CONFIG_CACHE["VERSION_STRATEGY"]="main" + fi + + # Handle legacy OPENMPI_4TH environment variable + if [[ "${OPENMPI_4TH}" == "yes" && -z "${CONFIG_CACHE[PACKAGE_VERSION_OPENMPI]}" ]]; then + CONFIG_CACHE["PACKAGE_VERSION_OPENMPI"]="alt" + CONFIG_CACHE["OPENMPI_4TH"]="yes" + echo "Notice: Legacy OPENMPI_4TH=yes detected, using openmpi:alt" + fi + + return 0 } # Export functions for use by other modules diff --git a/toolchain/scripts/lib/version_loader.sh b/toolchain/scripts/lib/version_loader.sh index 8883a7e789c..6bcec8dfdd6 100644 --- a/toolchain/scripts/lib/version_loader.sh +++ b/toolchain/scripts/lib/version_loader.sh @@ -11,71 +11,71 @@ # Load package variables with version suffix support # Usage: load_package_with_version "package_name" load_package_with_version() { - local package_name="$1" - - # Check for version configuration from environment or individual package setting - local version_suffix="" - - if [[ -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]]; then - # Check for individual package version override - if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "${package_name}:alt"; then - version_suffix="alt" - elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "${package_name}:main"; then - version_suffix="main" - fi - fi - - # Fall back to global version suffix if no individual setting - if [[ -z "$version_suffix" && -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" ]]; then - version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" - fi - - # Load package variables with appropriate version - load_package_vars "$package_name" "$version_suffix" - - # Debug output if verbose mode is enabled - if [[ "${VERBOSE_MODE}" == "__TRUE__" ]]; then - echo "DEBUG: Loaded $package_name with version suffix: ${version_suffix:-main}" + local package_name="$1" + + # Check for version configuration from environment or individual package setting + local version_suffix="" + + if [[ -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]]; then + # Check for individual package version override + if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "${package_name}:alt"; then + version_suffix="alt" + elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "${package_name}:main"; then + version_suffix="main" fi + fi + + # Fall back to global version suffix if no individual setting + if [[ -z "$version_suffix" && -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" ]]; then + version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" + fi + + # Load package variables with appropriate version + load_package_vars "$package_name" "$version_suffix" + + # Debug output if verbose mode is enabled + if [[ "${VERBOSE_MODE}" == "__TRUE__" ]]; then + echo "DEBUG: Loaded $package_name with version suffix: ${version_suffix:-main}" + fi } # Check if version configuration is available # Usage: has_version_config has_version_config() { - [[ -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" || -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]] + [[ -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" || -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]] } # Get effective version suffix for a package # Usage: get_package_version_suffix "package_name" get_package_version_suffix() { - local package_name="$1" - local version_suffix="" - - if [[ -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]]; then - # Check for individual package version override - if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "${package_name}:alt"; then - version_suffix="alt" - elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "${package_name}:main"; then - version_suffix="main" - fi - fi - - # Fall back to global version suffix if no individual setting - if [[ -z "$version_suffix" && -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" ]]; then - version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" + local package_name="$1" + local version_suffix="" + + if [[ -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]]; then + # Check for individual package version override + if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "${package_name}:alt"; then + version_suffix="alt" + elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "${package_name}:main"; then + version_suffix="main" fi - - echo "${version_suffix:-main}" + fi + + # Fall back to global version suffix if no individual setting + if [[ -z "$version_suffix" && -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" ]]; then + version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" + fi + + echo "${version_suffix:-main}" } # Show version information for debugging # Usage: show_version_debug "package_name" show_version_debug() { - local package_name="$1" - local version_suffix=$(get_package_version_suffix "$package_name") - - echo "Version Debug for $package_name:" - echo " Global suffix: ${ABACUS_TOOLCHAIN_VERSION_SUFFIX:-none}" - echo " Package versions: ${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS:-none}" - echo " Effective suffix: $version_suffix" -} \ No newline at end of file + local package_name="$1" + local version_suffix=$(get_package_version_suffix "$package_name") + + echo "Version Debug for $package_name:" + echo " Global suffix: ${ABACUS_TOOLCHAIN_VERSION_SUFFIX:-none}" + echo " Package versions: ${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS:-none}" + echo " Effective suffix: $version_suffix" +} diff --git a/toolchain/scripts/package_versions.sh b/toolchain/scripts/package_versions.sh index 0f19e9db4f3..1ef6ed6d754 100644 --- a/toolchain/scripts/package_versions.sh +++ b/toolchain/scripts/package_versions.sh @@ -1,6 +1,6 @@ #!/bin/bash # ABACUS Toolchain - Centralized Package Version Management -# +# # This file contains all package versions, checksums, and URLs in one place. # # Usage: source this file in install scripts to get package version information @@ -125,138 +125,138 @@ nep_sha256="4d4d3c64211a2a39e5d5c795b77befbba987cc809786e0cd6abfa46d0f3bf8cb" # ============================================================================= load_package_vars() { - local package_name="$1" - local version_suffix="$2" # Optional version suffix for multi-version packages - - case "${package_name}" in - "gcc") - if [ "${version_suffix}" = "alt" ]; then - gcc_ver="${gcc_alt_ver}" - gcc_sha256="${gcc_alt_sha256}" - else - gcc_ver="${gcc_main_ver}" - gcc_sha256="${gcc_main_sha256}" - fi - ;; - "cmake") - if [ "${version_suffix}" = "alt" ]; then - cmake_ver="${cmake_alt_ver}" - else - cmake_ver="${cmake_main_ver}" - fi - ;; - "openmpi") - if [ "${OPENMPI_4TH}" = "yes" ]; then - echo "WARNING: OPENMPI_4TH=yes is deprecated. Please use 'alt' parameter instead." >&2 - openmpi_ver="${openmpi_alt_ver}" - openmpi_sha256="${openmpi_alt_sha256}" - elif [ "${version_suffix}" = "alt" ]; then - openmpi_ver="${openmpi_alt_ver}" - openmpi_sha256="${openmpi_alt_sha256}" - else - openmpi_ver="${openmpi_main_ver}" - openmpi_sha256="${openmpi_main_sha256}" - fi - ;; - "mpich") - if [ "${version_suffix}" = "alt" ]; then - mpich_ver="${mpich_alt_ver}" - mpich_sha256="${mpich_alt_sha256}" - else - mpich_ver="${mpich_main_ver}" - mpich_sha256="${mpich_main_sha256}" - fi - ;; - "openblas") - if [ "${version_suffix}" = "alt" ]; then - openblas_ver="${openblas_alt_ver}" - openblas_sha256="${openblas_alt_sha256}" - else - openblas_ver="${openblas_main_ver}" - openblas_sha256="${openblas_main_sha256}" - fi - ;; - "elpa") - if [ "${version_suffix}" = "alt" ]; then - elpa_ver="${elpa_alt_ver}" - elpa_sha256="${elpa_alt_sha256}" - else - elpa_ver="${elpa_main_ver}" - elpa_sha256="${elpa_main_sha256}" - fi - ;; - "fftw") - if [ "${version_suffix}" = "alt" ]; then - fftw_ver="${fftw_alt_ver}" - fftw_sha256="${fftw_alt_sha256}" - else - fftw_ver="${fftw_main_ver}" - fftw_sha256="${fftw_main_sha256}" - fi - ;; - "libxc") - if [ "${version_suffix}" = "alt" ]; then - libxc_ver="${libxc_alt_ver}" - libxc_sha256="${libxc_alt_sha256}" - else - libxc_ver="${libxc_main_ver}" - libxc_sha256="${libxc_main_sha256}" - fi - ;; - "scalapack") - if [ "${version_suffix}" = "alt" ]; then - scalapack_ver="${scalapack_alt_ver}" - scalapack_sha256="${scalapack_alt_sha256}" - else - scalapack_ver="${scalapack_main_ver}" - scalapack_sha256="${scalapack_main_sha256}" - fi - ;; - "dftd4") - dftd4_ver="${dftd4_ver}" - dftd4_sha256="${dftd4_sha256}" - ;; - "libtorch") - if [ "${version_suffix}" = "alt" ]; then - libtorch_ver="${libtorch_alt_ver}" - libtorch_sha256="${libtorch_alt_sha256}" - else - libtorch_ver="${libtorch_main_ver}" - libtorch_sha256="${libtorch_main_sha256}" - fi - ;; - "libnpy") - if [ "${version_suffix}" = "alt" ]; then - libnpy_ver="${libnpy_alt_ver}" - libnpy_sha256="${libnpy_alt_sha256}" - else - libnpy_ver="${libnpy_main_ver}" - libnpy_sha256="${libnpy_main_sha256}" - fi - ;; - "cereal") - cereal_ver="${cereal_ver}" - cereal_sha256="${cereal_sha256}" - ;; - "libcomm") - libcomm_ver="${libcomm_ver}" - libcomm_sha256="${libcomm_sha256}" - ;; - "libri") - libri_ver="${libri_ver}" - libri_sha256="${libri_sha256}" - ;; - "json") - json_ver="${json_ver}" - json_sha256="${json_sha256}" - ;; - "nep") - nep_ver="${nep_ver}" - nep_sha256="${nep_sha256}" - ;; - *) - echo "Error: Unknown package '${package_name}'" - return 1 - ;; - esac + local package_name="$1" + local version_suffix="$2" # Optional version suffix for multi-version packages + + case "${package_name}" in + "gcc") + if [ "${version_suffix}" = "alt" ]; then + gcc_ver="${gcc_alt_ver}" + gcc_sha256="${gcc_alt_sha256}" + else + gcc_ver="${gcc_main_ver}" + gcc_sha256="${gcc_main_sha256}" + fi + ;; + "cmake") + if [ "${version_suffix}" = "alt" ]; then + cmake_ver="${cmake_alt_ver}" + else + cmake_ver="${cmake_main_ver}" + fi + ;; + "openmpi") + if [ "${OPENMPI_4TH}" = "yes" ]; then + echo "WARNING: OPENMPI_4TH=yes is deprecated. Please use 'alt' parameter instead." >&2 + openmpi_ver="${openmpi_alt_ver}" + openmpi_sha256="${openmpi_alt_sha256}" + elif [ "${version_suffix}" = "alt" ]; then + openmpi_ver="${openmpi_alt_ver}" + openmpi_sha256="${openmpi_alt_sha256}" + else + openmpi_ver="${openmpi_main_ver}" + openmpi_sha256="${openmpi_main_sha256}" + fi + ;; + "mpich") + if [ "${version_suffix}" = "alt" ]; then + mpich_ver="${mpich_alt_ver}" + mpich_sha256="${mpich_alt_sha256}" + else + mpich_ver="${mpich_main_ver}" + mpich_sha256="${mpich_main_sha256}" + fi + ;; + "openblas") + if [ "${version_suffix}" = "alt" ]; then + openblas_ver="${openblas_alt_ver}" + openblas_sha256="${openblas_alt_sha256}" + else + openblas_ver="${openblas_main_ver}" + openblas_sha256="${openblas_main_sha256}" + fi + ;; + "elpa") + if [ "${version_suffix}" = "alt" ]; then + elpa_ver="${elpa_alt_ver}" + elpa_sha256="${elpa_alt_sha256}" + else + elpa_ver="${elpa_main_ver}" + elpa_sha256="${elpa_main_sha256}" + fi + ;; + "fftw") + if [ "${version_suffix}" = "alt" ]; then + fftw_ver="${fftw_alt_ver}" + fftw_sha256="${fftw_alt_sha256}" + else + fftw_ver="${fftw_main_ver}" + fftw_sha256="${fftw_main_sha256}" + fi + ;; + "libxc") + if [ "${version_suffix}" = "alt" ]; then + libxc_ver="${libxc_alt_ver}" + libxc_sha256="${libxc_alt_sha256}" + else + libxc_ver="${libxc_main_ver}" + libxc_sha256="${libxc_main_sha256}" + fi + ;; + "scalapack") + if [ "${version_suffix}" = "alt" ]; then + scalapack_ver="${scalapack_alt_ver}" + scalapack_sha256="${scalapack_alt_sha256}" + else + scalapack_ver="${scalapack_main_ver}" + scalapack_sha256="${scalapack_main_sha256}" + fi + ;; + "dftd4") + dftd4_ver="${dftd4_ver}" + dftd4_sha256="${dftd4_sha256}" + ;; + "libtorch") + if [ "${version_suffix}" = "alt" ]; then + libtorch_ver="${libtorch_alt_ver}" + libtorch_sha256="${libtorch_alt_sha256}" + else + libtorch_ver="${libtorch_main_ver}" + libtorch_sha256="${libtorch_main_sha256}" + fi + ;; + "libnpy") + if [ "${version_suffix}" = "alt" ]; then + libnpy_ver="${libnpy_alt_ver}" + libnpy_sha256="${libnpy_alt_sha256}" + else + libnpy_ver="${libnpy_main_ver}" + libnpy_sha256="${libnpy_main_sha256}" + fi + ;; + "cereal") + cereal_ver="${cereal_ver}" + cereal_sha256="${cereal_sha256}" + ;; + "libcomm") + libcomm_ver="${libcomm_ver}" + libcomm_sha256="${libcomm_sha256}" + ;; + "libri") + libri_ver="${libri_ver}" + libri_sha256="${libri_sha256}" + ;; + "json") + json_ver="${json_ver}" + json_sha256="${json_sha256}" + ;; + "nep") + nep_ver="${nep_ver}" + nep_sha256="${nep_sha256}" + ;; + *) + echo "Error: Unknown package '${package_name}'" + return 1 + ;; + esac } diff --git a/toolchain/scripts/stage0/install_amd.sh b/toolchain/scripts/stage0/install_amd.sh index 616697de192..bd52cb74572 100755 --- a/toolchain/scripts/stage0/install_amd.sh +++ b/toolchain/scripts/stage0/install_amd.sh @@ -23,74 +23,74 @@ mkdir -p "${BUILDDIR}" cd "${BUILDDIR}" case "${with_amd}" in - __INSTALL__) - echo "==================== Installing the AMD compiler ======================" - report_error ${LINENO} "To install the AMD compiler, please contact your system administrator." - exit 1 - ;; - __SYSTEM__) - echo "==================== Finding AMD compiler from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_command clang "amd" && CC="$(realpath $(command -v clang))" || exit 1 - check_command clang++ "amd" && CXX="$(realpath $(command -v clang++))" || exit 1 - if [ "${WITH_FLANG}" = "yes" ]; then - check_command flang "amd" && FC="$(realpath $(command -v flang))" || exit 1 - else - check_command gfortran "gcc" && FC="gfortran" || exit 1 - add_lib_from_paths GCC_LDFLAGS "libgfortran.*" ${LIB_PATHS} - fi - F90="${FC}" - F77="${FC}" - ;; - __DONTUSE__) - # Nothing to do - ;; - *) - echo "==================== Linking AMD compiler to user paths ====================" - pkg_install_dir="${with_amd}" - check_dir "${pkg_install_dir}/bin" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - check_command ${pkg_install_dir}/bin/clang "amd" && CC="${pkg_install_dir}/bin/clang" || exit 1 - check_command ${pkg_install_dir}/bin/clang++ "amd" && CXX="${pkg_install_dir}/bin/clang++" || exit 1 - if [ "${WITH_FLANG}" = "yes" ]; then - check_command ${pkg_install_dir}/bin/flang "amd" && FC="${pkg_install_dir}/bin/flang" || exit 1 - else - check_command gfortran "gcc" && FC="$(command -v gfortran)" || exit 1 - fi - F90="${FC}" - F77="${FC}" - AMD_CFLAGS="-I'${pkg_install_dir}/include'" - AMD_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; +__INSTALL__) + echo "==================== Installing the AMD compiler ======================" + report_error ${LINENO} "To install the AMD compiler, please contact your system administrator." + exit 1 + ;; +__SYSTEM__) + echo "==================== Finding AMD compiler from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_command clang "amd" && CC="$(realpath $(command -v clang))" || exit 1 + check_command clang++ "amd" && CXX="$(realpath $(command -v clang++))" || exit 1 + if [ "${WITH_FLANG}" = "yes" ]; then + check_command flang "amd" && FC="$(realpath $(command -v flang))" || exit 1 + else + check_command gfortran "gcc" && FC="gfortran" || exit 1 + add_lib_from_paths GCC_LDFLAGS "libgfortran.*" ${LIB_PATHS} + fi + F90="${FC}" + F77="${FC}" + ;; +__DONTUSE__) + # Nothing to do + ;; +*) + echo "==================== Linking AMD compiler to user paths ====================" + pkg_install_dir="${with_amd}" + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + check_command ${pkg_install_dir}/bin/clang "amd" && CC="${pkg_install_dir}/bin/clang" || exit 1 + check_command ${pkg_install_dir}/bin/clang++ "amd" && CXX="${pkg_install_dir}/bin/clang++" || exit 1 + if [ "${WITH_FLANG}" = "yes" ]; then + check_command ${pkg_install_dir}/bin/flang "amd" && FC="${pkg_install_dir}/bin/flang" || exit 1 + else + check_command gfortran "gcc" && FC="$(command -v gfortran)" || exit 1 + fi + F90="${FC}" + F77="${FC}" + AMD_CFLAGS="-I'${pkg_install_dir}/include'" + AMD_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "${with_amd}" != "__DONTUSE__" ]; then - echo "CC is ${CC}" - [ $(realpath $(command -v clang) | grep -e aocc-compiler) ] || echo "Check the AMD C compiler path" - echo "CXX is ${CXX}" - [ $(realpath $(command -v clang++) | grep -e aocc-compiler) ] || echo "Check the AMD C++ compiler path" - echo "FC is ${FC}" - if [ "${WITH_FLANG}" = "yes" ]; then - [ $(realpath $(command -v flang) | grep -e aocc-compiler) ] || echo "Check the AMD Fortran compiler path" - else - [ $(realpath $(command -v gfortran) | grep -e aocc-compiler) ] || echo "Check the GNU Fortran compiler path" - fi - cat << EOF > "${BUILDDIR}/setup_amd" + echo "CC is ${CC}" + [ $(realpath $(command -v clang) | grep -e aocc-compiler) ] || echo "Check the AMD C compiler path" + echo "CXX is ${CXX}" + [ $(realpath $(command -v clang++) | grep -e aocc-compiler) ] || echo "Check the AMD C++ compiler path" + echo "FC is ${FC}" + if [ "${WITH_FLANG}" = "yes" ]; then + [ $(realpath $(command -v flang) | grep -e aocc-compiler) ] || echo "Check the AMD Fortran compiler path" + else + [ $(realpath $(command -v gfortran) | grep -e aocc-compiler) ] || echo "Check the GNU Fortran compiler path" + fi + cat <"${BUILDDIR}/setup_amd" export CC="${CC}" export CXX="${CXX}" export FC="${FC}" export F90="${F90}" export F77="${F77}" EOF - cat << EOF >> "${BUILDDIR}/setup_amd" + cat <>"${BUILDDIR}/setup_amd" export AMD_CFLAGS="${AMD_CFLAGS}" export AMD_LDFLAGS="${AMD_LDFLAGS}" export AMD_LIBS="${AMD_LIBS}" EOF - filter_setup "${BUILDDIR}/setup_amd" ${SETUPFILE} + filter_setup "${BUILDDIR}/setup_amd" ${SETUPFILE} fi load "${BUILDDIR}/setup_amd" diff --git a/toolchain/scripts/stage0/install_cmake.sh b/toolchain/scripts/stage0/install_cmake.sh index 55d82b82b2f..cb9d00369c0 100755 --- a/toolchain/scripts/stage0/install_cmake.sh +++ b/toolchain/scripts/stage0/install_cmake.sh @@ -17,16 +17,16 @@ source "${SCRIPT_DIR}"/package_versions.sh # Check for version configuration from environment or individual package setting version_suffix="" if [[ -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]]; then - # Check for individual package version override - if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "cmake:alt"; then - version_suffix="alt" - elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "cmake:main"; then - version_suffix="main" - fi + # Check for individual package version override + if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "cmake:alt"; then + version_suffix="alt" + elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "cmake:main"; then + version_suffix="main" + fi fi # Fall back to global version suffix if no individual setting if [[ -z "$version_suffix" && -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" ]]; then - version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" + version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" fi # Load package variables with appropriate version @@ -40,83 +40,83 @@ source "${INSTALLDIR}"/toolchain.env ! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" cd "${BUILDDIR}" case "${with_cmake}" in - __INSTALL__) - echo "==================== Installing CMake ====================" - case "$(uname -s):${SYSTEM_ARCH}" in - Darwin:x86_64 | Darwin:arm64) - cmake_arch="macos-universal" - cmake_checksum_arch="macos" - ;; - Linux:x86_64) - cmake_arch="linux-x86_64" - cmake_checksum_arch="x86_64" - ;; - Linux:arm64) - cmake_arch="linux-aarch64" - cmake_checksum_arch="aarch64" - ;; - *) - report_error ${LINENO} \ - "cmake installation for ARCH=${SYSTEM_ARCH} under $(uname -s) is not supported. You can try to use the system installation using the flag \"--with-cmake=system\" instead." - exit 1 - ;; - esac +__INSTALL__) + echo "==================== Installing CMake ====================" + case "$(uname -s):${SYSTEM_ARCH}" in + Darwin:x86_64 | Darwin:arm64) + cmake_arch="macos-universal" + cmake_checksum_arch="macos" + ;; + Linux:x86_64) + cmake_arch="linux-x86_64" + cmake_checksum_arch="x86_64" + ;; + Linux:arm64) + cmake_arch="linux-aarch64" + cmake_checksum_arch="aarch64" + ;; + *) + report_error ${LINENO} \ + "cmake installation for ARCH=${SYSTEM_ARCH} under $(uname -s) is not supported. You can try to use the system installation using the flag \"--with-cmake=system\" instead." + exit 1 + ;; + esac - if [ "${version_suffix}" = "alt" ]; then - cmake_checksum_var="cmake_alt_sha256_${cmake_checksum_arch}" - else - cmake_checksum_var="cmake_main_sha256_${cmake_checksum_arch}" - fi - cmake_sha256="${!cmake_checksum_var}" + if [ "${version_suffix}" = "alt" ]; then + cmake_checksum_var="cmake_alt_sha256_${cmake_checksum_arch}" + else + cmake_checksum_var="cmake_main_sha256_${cmake_checksum_arch}" + fi + cmake_sha256="${!cmake_checksum_var}" - pkg_install_dir="${INSTALLDIR}/cmake-${cmake_ver}" - #pkg_install_dir="${HOME}/apps/cmake/${cmake_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - cmake_pkg="cmake-${cmake_ver}-${cmake_arch}.tar.gz" - if verify_checksums "${install_lock_file}"; then - echo "cmake-${cmake_ver} is already installed, skipping it." - else - url="https://cmake.org/files/v${cmake_ver%.*}/${cmake_pkg}" - retrieve_package "${cmake_sha256}" "${cmake_pkg}" "${url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - echo "Installing from scratch into ${pkg_install_dir}" - mkdir -p ${pkg_install_dir} - if [ "${cmake_arch}" = "macos-universal" ]; then - strip_components=3 - else - strip_components=1 - fi - tar --strip-components=${strip_components} -xvf ${cmake_pkg} -C ${pkg_install_dir} > install.log 2>&1 || tail_excerpt install.log - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage0/$(basename ${SCRIPT_NAME})" - fi - ;; - __SYSTEM__) - echo "==================== Finding CMake from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_command cmake "cmake" - ;; - __DONTUSE__) - # Nothing to do - ;; - *) - echo "==================== Linking CMake to user paths ====================" - pkg_install_dir="$with_cmake" - check_dir "${with_cmake}/bin" - ;; + pkg_install_dir="${INSTALLDIR}/cmake-${cmake_ver}" + #pkg_install_dir="${HOME}/apps/cmake/${cmake_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + cmake_pkg="cmake-${cmake_ver}-${cmake_arch}.tar.gz" + if verify_checksums "${install_lock_file}"; then + echo "cmake-${cmake_ver} is already installed, skipping it." + else + url="https://cmake.org/files/v${cmake_ver%.*}/${cmake_pkg}" + retrieve_package "${cmake_sha256}" "${cmake_pkg}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + mkdir -p ${pkg_install_dir} + if [ "${cmake_arch}" = "macos-universal" ]; then + strip_components=3 + else + strip_components=1 + fi + tar --strip-components=${strip_components} -xvf ${cmake_pkg} -C ${pkg_install_dir} >install.log 2>&1 || tail_excerpt install.log + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage0/$(basename ${SCRIPT_NAME})" + fi + ;; +__SYSTEM__) + echo "==================== Finding CMake from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_command cmake "cmake" + ;; +__DONTUSE__) + # Nothing to do + ;; +*) + echo "==================== Linking CMake to user paths ====================" + pkg_install_dir="$with_cmake" + check_dir "${with_cmake}/bin" + ;; esac if [ "${with_cmake}" != "__DONTUSE__" ]; then - if [ "${with_cmake}" != "__SYSTEM__" ]; then - cat << EOF > "${BUILDDIR}/setup_cmake" + if [ "${with_cmake}" != "__SYSTEM__" ]; then + cat <"${BUILDDIR}/setup_cmake" prepend_path PATH "${pkg_install_dir}/bin" EOF - filter_setup "${BUILDDIR}/setup_cmake" $SETUPFILE - fi + filter_setup "${BUILDDIR}/setup_cmake" $SETUPFILE + fi fi load "${BUILDDIR}/setup_cmake" diff --git a/toolchain/scripts/stage0/install_gcc.sh b/toolchain/scripts/stage0/install_gcc.sh index 74855d404fe..7eba97ba127 100755 --- a/toolchain/scripts/stage0/install_gcc.sh +++ b/toolchain/scripts/stage0/install_gcc.sh @@ -17,16 +17,16 @@ source "${SCRIPT_DIR}"/package_versions.sh # Check for version configuration from environment or individual package setting version_suffix="" if [[ -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]]; then - # Check for individual package version override - if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "gcc:alt"; then - version_suffix="alt" - elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "gcc:main"; then - version_suffix="main" - fi + # Check for individual package version override + if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "gcc:alt"; then + version_suffix="alt" + elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "gcc:main"; then + version_suffix="main" + fi fi # Fall back to global version suffix if no individual setting if [[ -z "$version_suffix" && -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" ]]; then - version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" + version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" fi # Load package variables with appropriate version load_package_vars "gcc" "$version_suffix" @@ -43,178 +43,178 @@ TSANFLAGS="" cd "${BUILDDIR}" case "${with_gcc}" in - __INSTALL__) - echo "==================== Installing GCC ====================" - pkg_install_dir="${INSTALLDIR}/gcc-${gcc_ver}" - repack_filename="gcc-${gcc_ver}-with-prereq.tar.gz" - repkg_install_dir="${INSTALLDIR}/${repack_filename}" - #pkg_install_dir="${HOME}/apps/gcc/${gcc_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - if verify_checksums "${install_lock_file}"; then - echo "gcc-${gcc_ver} is already installed, skipping it." - else - # Check if repackaged tarball exists for offline installation - if [ -f "${repack_filename}" ]; then - echo "${repack_filename} is found, extracting it..." - tar -xzf "${repack_filename}" - echo "Successfully extracted ${repack_filename}" - else - url=https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-${gcc_ver}/gcc-${gcc_ver}.tar.gz - retrieve_package "${gcc_sha256}" "gcc-${gcc_ver}.tar.gz" "${url}" - fi - [ -d gcc-${gcc_ver} ] && rm -rf gcc-${gcc_ver} - tar -xzf gcc-${gcc_ver}.tar.gz +__INSTALL__) + echo "==================== Installing GCC ====================" + pkg_install_dir="${INSTALLDIR}/gcc-${gcc_ver}" + repack_filename="gcc-${gcc_ver}-with-prereq.tar.gz" + repkg_install_dir="${INSTALLDIR}/${repack_filename}" + #pkg_install_dir="${HOME}/apps/gcc/${gcc_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "gcc-${gcc_ver} is already installed, skipping it." + else + # Check if repackaged tarball exists for offline installation + if [ -f "${repack_filename}" ]; then + echo "${repack_filename} is found, extracting it..." + tar -xzf "${repack_filename}" + echo "Successfully extracted ${repack_filename}" + else + url=https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-${gcc_ver}/gcc-${gcc_ver}.tar.gz + retrieve_package "${gcc_sha256}" "gcc-${gcc_ver}.tar.gz" "${url}" + fi + [ -d gcc-${gcc_ver} ] && rm -rf gcc-${gcc_ver} + tar -xzf gcc-${gcc_ver}.tar.gz - echo "Installing GCC from scratch into ${pkg_install_dir}" - cd gcc-${gcc_ver} + echo "Installing GCC from scratch into ${pkg_install_dir}" + cd gcc-${gcc_ver} + + # Check network connectivity before downloading prerequisites + if curl -s --connect-timeout 5 https://gcc.gnu.org >/dev/null 2>&1; then + echo "Downloading prerequisites from official GCC site..." + # Try official site first + if ./contrib/download_prerequisites >prereq.log 2>&1; then + echo "Prerequisites downloaded successfully from official site" + else + echo "Official site failed, trying mirror site..." + # Fallback to cp2k.org mirror + sed -i 's|http://gcc.gnu.org/pub/gcc/infrastructure/|https://cp2k.org/static/downloads/|' ./contrib/download_prerequisites + ./contrib/download_prerequisites >prereq.log 2>&1 || tail -n ${LOG_LINES} prereq.log + fi + else + echo "Network unavailable, skipping prerequisites download (offline mode)" + fi - # Check network connectivity before downloading prerequisites - if curl -s --connect-timeout 5 https://gcc.gnu.org > /dev/null 2>&1; then - echo "Downloading prerequisites from official GCC site..." - # Try official site first - if ./contrib/download_prerequisites > prereq.log 2>&1; then - echo "Prerequisites downloaded successfully from official site" - else - echo "Official site failed, trying mirror site..." - # Fallback to cp2k.org mirror - sed -i 's|http://gcc.gnu.org/pub/gcc/infrastructure/|https://cp2k.org/static/downloads/|' ./contrib/download_prerequisites - ./contrib/download_prerequisites > prereq.log 2>&1 || tail -n ${LOG_LINES} prereq.log - fi - else - echo "Network unavailable, skipping prerequisites download (offline mode)" - fi - - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode: repackaging GCC with prerequisites for offline installation" - cd .. - # Create a new tarball with prerequisites included - repack_filename="gcc-${gcc_ver}-with-prereq.tar.gz" - echo "Creating ${repack_filename}..." - tar -czf "${repack_filename}" gcc-${gcc_ver}/ - echo "Successfully created ${repack_filename} for offline installation" - echo "This package contains GCC source code with all prerequisites ready for offline build" - exit 0 - fi - GCCROOT=${PWD} - mkdir obj - cd obj - # TODO: Maybe use --disable-libquadmath-support to improve static linking: - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46539 - # - # TODO: Maybe use --disable-gnu-unique-object to improve static linking: - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60348#c13 - # https://stackoverflow.com/questions/11931420 - # - # TODO: Unfortunately, we can not simply use --disable-shared, because - # it would break OpenBLAS build and probably others too. - COMMON_FLAGS="-O2 -fPIC -fno-omit-frame-pointer -fopenmp -g" - CFLAGS="${COMMON_FLAGS}" - CXXFLAGS="${CFLAGS}" - FCFLAGS="${COMMON_FLAGS} -fbacktrace" - ${GCCROOT}/configure --prefix="${pkg_install_dir}" \ - --libdir="${pkg_install_dir}/lib" \ - --enable-languages=c,c++,fortran \ - --disable-multilib --disable-bootstrap \ - --enable-lto \ - --enable-plugins \ - > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log - make -j $(get_nprocs) \ - CFLAGS="${CFLAGS}" \ - CXXFLAGS="${CXXFLAGS}" \ - FCFLAGS="${FCFLAGS}" \ - > make.log 2>&1 || tail -n ${LOG_LINES} make.log - make -j $(get_nprocs) install > install.log 2>&1 || tail -n ${LOG_LINES} install.log - # thread sanitizer - if [ "${ENABLE_TSAN}" = "__TRUE__" ]; then - # now the tricky bit... we need to recompile in particular - # libgomp with -fsanitize=thread.. there is not configure - # option for this (as far as I know). we need to go in - # the build tree and recompile / reinstall with proper - # options... this is likely to break for later version of - # gcc, tested with 5.1.0 based on - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55374#c10 - cd x86_64*/libgfortran - make clean > clean.log 2>&1 || tail -n ${LOG_LINES} clean.log - CFLAGS="${CFLAGS} -fsanitize=thread" - CXXFLAGS="${CXXFLAGS} -fsanitize=thread" - FCFLAGS="${FCFLAGS} -fsanitize=thread" - make -j $(get_nprocs) \ - CFLAGS="${CFLAGS}" \ - CXXFLAGS="${CXXFLAGS}" \ - FCFLAGS="${FCFLAGS}" \ - LDFLAGS="-B$(pwd)/../libsanitizer/tsan/.libs/ -Wl,-rpath,$(pwd)/../libsanitizer/tsan/.libs/ -fsanitize=thread" \ - > make.log 2>&1 || tail -n ${LOG_LINES} make.log - make install > install.log 2>&1 || tail -n ${LOG_LINES} install.log - cd ../libgomp - make clean > clean.log 2>&1 || tail -n ${LOG_LINES} clean.log - make -j $(get_nprocs) \ - CFLAGS="${CFLAGS}" \ - CXXFLAGS="${CXXFLAGS}" \ - FCFLAGS="${FCFLAGS}" \ - LDFLAGS="-B$(pwd)/../libsanitizer/tsan/.libs/ -Wl,-rpath,$(pwd)/../libsanitizer/tsan/.libs/ -fsanitize=thread" \ - > make.log 2>&1 || tail -n ${LOG_LINES} make.log - make install > install.log 2>&1 || tail -n ${LOG_LINES} install.log - cd ${GCCROOT}/obj/ - fi - cd ../.. - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage0/$(basename ${SCRIPT_NAME})" - fi - check_install ${pkg_install_dir}/bin/gcc "gcc" && CC="${pkg_install_dir}/bin/gcc" || exit 1 - check_install ${pkg_install_dir}/bin/g++ "gcc" && CXX="${pkg_install_dir}/bin/g++" || exit 1 - check_install ${pkg_install_dir}/bin/gfortran "gcc" && FC="${pkg_install_dir}/bin/gfortran" || exit 1 - F90="${FC}" - F77="${FC}" - GCC_CFLAGS="-I'${pkg_install_dir}/include'" - GCC_LDFLAGS="-L'${pkg_install_dir}/lib64' -L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib64' -Wl,-rpath,'${pkg_install_dir}/lib64'" - ;; - __SYSTEM__) - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - echo "==================== Finding GCC from system paths ====================" - check_command gcc "gcc" && CC="$(command -v gcc)" || exit 1 - check_command g++ "gcc" && CXX="$(command -v g++)" || exit 1 - check_command gfortran "gcc" && FC="$(command -v gfortran)" || exit 1 - F90="${FC}" - F77="${FC}" - add_include_from_paths -p GCC_CFLAGS "c++" ${INCLUDE_PATHS} - add_lib_from_paths GCC_LDFLAGS "libgfortran.*" ${LIB_PATHS} - ;; - __DONTUSE__) - # Nothing to do - ;; - *) - echo "==================== Linking GCC to user paths ====================" - pkg_install_dir="${with_gcc}" - check_dir "${pkg_install_dir}/bin" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/lib64" - check_dir "${pkg_install_dir}/include" - check_command ${pkg_install_dir}/bin/gcc "gcc" && CC="${pkg_install_dir}/bin/gcc" || exit 1 - check_command ${pkg_install_dir}/bin/g++ "gcc" && CXX="${pkg_install_dir}/bin/g++" || exit 1 - check_command ${pkg_install_dir}/bin/gfortran "gcc" && FC="${pkg_install_dir}/bin/gfortran" || exit 1 - F90="${FC}" - F77="${FC}" - GCC_CFLAGS="-I'${pkg_install_dir}/include'" - GCC_LDFLAGS="-L'${pkg_install_dir}/lib64' -L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib64' -Wl,-rpath,'${pkg_install_dir}/lib64'" - ;; + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode: repackaging GCC with prerequisites for offline installation" + cd .. + # Create a new tarball with prerequisites included + repack_filename="gcc-${gcc_ver}-with-prereq.tar.gz" + echo "Creating ${repack_filename}..." + tar -czf "${repack_filename}" gcc-${gcc_ver}/ + echo "Successfully created ${repack_filename} for offline installation" + echo "This package contains GCC source code with all prerequisites ready for offline build" + exit 0 + fi + GCCROOT=${PWD} + mkdir obj + cd obj + # TODO: Maybe use --disable-libquadmath-support to improve static linking: + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46539 + # + # TODO: Maybe use --disable-gnu-unique-object to improve static linking: + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60348#c13 + # https://stackoverflow.com/questions/11931420 + # + # TODO: Unfortunately, we can not simply use --disable-shared, because + # it would break OpenBLAS build and probably others too. + COMMON_FLAGS="-O2 -fPIC -fno-omit-frame-pointer -fopenmp -g" + CFLAGS="${COMMON_FLAGS}" + CXXFLAGS="${CFLAGS}" + FCFLAGS="${COMMON_FLAGS} -fbacktrace" + ${GCCROOT}/configure --prefix="${pkg_install_dir}" \ + --libdir="${pkg_install_dir}/lib" \ + --enable-languages=c,c++,fortran \ + --disable-multilib --disable-bootstrap \ + --enable-lto \ + --enable-plugins \ + >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) \ + CFLAGS="${CFLAGS}" \ + CXXFLAGS="${CXXFLAGS}" \ + FCFLAGS="${FCFLAGS}" \ + >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j $(get_nprocs) install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + # thread sanitizer + if [ "${ENABLE_TSAN}" = "__TRUE__" ]; then + # now the tricky bit... we need to recompile in particular + # libgomp with -fsanitize=thread.. there is not configure + # option for this (as far as I know). we need to go in + # the build tree and recompile / reinstall with proper + # options... this is likely to break for later version of + # gcc, tested with 5.1.0 based on + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55374#c10 + cd x86_64*/libgfortran + make clean >clean.log 2>&1 || tail -n ${LOG_LINES} clean.log + CFLAGS="${CFLAGS} -fsanitize=thread" + CXXFLAGS="${CXXFLAGS} -fsanitize=thread" + FCFLAGS="${FCFLAGS} -fsanitize=thread" + make -j $(get_nprocs) \ + CFLAGS="${CFLAGS}" \ + CXXFLAGS="${CXXFLAGS}" \ + FCFLAGS="${FCFLAGS}" \ + LDFLAGS="-B$(pwd)/../libsanitizer/tsan/.libs/ -Wl,-rpath,$(pwd)/../libsanitizer/tsan/.libs/ -fsanitize=thread" \ + >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd ../libgomp + make clean >clean.log 2>&1 || tail -n ${LOG_LINES} clean.log + make -j $(get_nprocs) \ + CFLAGS="${CFLAGS}" \ + CXXFLAGS="${CXXFLAGS}" \ + FCFLAGS="${FCFLAGS}" \ + LDFLAGS="-B$(pwd)/../libsanitizer/tsan/.libs/ -Wl,-rpath,$(pwd)/../libsanitizer/tsan/.libs/ -fsanitize=thread" \ + >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd ${GCCROOT}/obj/ + fi + cd ../.. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage0/$(basename ${SCRIPT_NAME})" + fi + check_install ${pkg_install_dir}/bin/gcc "gcc" && CC="${pkg_install_dir}/bin/gcc" || exit 1 + check_install ${pkg_install_dir}/bin/g++ "gcc" && CXX="${pkg_install_dir}/bin/g++" || exit 1 + check_install ${pkg_install_dir}/bin/gfortran "gcc" && FC="${pkg_install_dir}/bin/gfortran" || exit 1 + F90="${FC}" + F77="${FC}" + GCC_CFLAGS="-I'${pkg_install_dir}/include'" + GCC_LDFLAGS="-L'${pkg_install_dir}/lib64' -L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib64' -Wl,-rpath,'${pkg_install_dir}/lib64'" + ;; +__SYSTEM__) + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + echo "==================== Finding GCC from system paths ====================" + check_command gcc "gcc" && CC="$(command -v gcc)" || exit 1 + check_command g++ "gcc" && CXX="$(command -v g++)" || exit 1 + check_command gfortran "gcc" && FC="$(command -v gfortran)" || exit 1 + F90="${FC}" + F77="${FC}" + add_include_from_paths -p GCC_CFLAGS "c++" ${INCLUDE_PATHS} + add_lib_from_paths GCC_LDFLAGS "libgfortran.*" ${LIB_PATHS} + ;; +__DONTUSE__) + # Nothing to do + ;; +*) + echo "==================== Linking GCC to user paths ====================" + pkg_install_dir="${with_gcc}" + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/lib64" + check_dir "${pkg_install_dir}/include" + check_command ${pkg_install_dir}/bin/gcc "gcc" && CC="${pkg_install_dir}/bin/gcc" || exit 1 + check_command ${pkg_install_dir}/bin/g++ "gcc" && CXX="${pkg_install_dir}/bin/g++" || exit 1 + check_command ${pkg_install_dir}/bin/gfortran "gcc" && FC="${pkg_install_dir}/bin/gfortran" || exit 1 + F90="${FC}" + F77="${FC}" + GCC_CFLAGS="-I'${pkg_install_dir}/include'" + GCC_LDFLAGS="-L'${pkg_install_dir}/lib64' -L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib64' -Wl,-rpath,'${pkg_install_dir}/lib64'" + ;; esac if [ "${ENABLE_TSAN}" = "__TRUE__" ]; then - TSANFLAGS="-fsanitize=thread" + TSANFLAGS="-fsanitize=thread" else - TSANFLAGS="" + TSANFLAGS="" fi if [ "${with_gcc}" != "__DONTUSE__" ]; then - cat << EOF > "${BUILDDIR}/setup_gcc" + cat <"${BUILDDIR}/setup_gcc" export CC="${CC}" export CXX="${CXX}" export FC="${FC}" export F90="${F90}" export F77="${F77}" EOF - if [ "${with_gcc}" != "__SYSTEM__" ]; then - cat << EOF >> "${BUILDDIR}/setup_gcc" + if [ "${with_gcc}" != "__SYSTEM__" ]; then + cat <>"${BUILDDIR}/setup_gcc" # needs full path for mpich/openmpi builds, triggers openblas bug prepend_path PATH "${pkg_install_dir}/bin" prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" @@ -225,13 +225,13 @@ prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" prepend_path LIBRARY_PATH "${pkg_install_dir}/lib64" prepend_path CPATH "${pkg_install_dir}/include" EOF - fi - cat << EOF >> "${BUILDDIR}/setup_gcc" + fi + cat <>"${BUILDDIR}/setup_gcc" export GCC_CFLAGS="${GCC_CFLAGS}" export GCC_LDFLAGS="${GCC_LDFLAGS}" export TSANFLAGS="${TSANFLAGS}" EOF - filter_setup "${BUILDDIR}/setup_gcc" ${SETUPFILE} + filter_setup "${BUILDDIR}/setup_gcc" ${SETUPFILE} fi # ---------------------------------------------------------------------- @@ -240,7 +240,7 @@ fi # this might need to be adjusted for the versions of the software # employed -cat << EOF >> ${INSTALLDIR}/lsan.supp +cat <>${INSTALLDIR}/lsan.supp # known leak either related to mpi or scalapack (e.g. showing randomly for Fist/regtest-7-2/UO2-2x2x2-genpot_units.inp) leak:__cp_fm_types_MOD_cp_fm_write_unformatted # leak related to mpi or scalapack triggers sometimes for regtest-kp-2/cc2.inp @@ -250,7 +250,7 @@ leak:blacs_gridmap_ leak:__dbcsr_tensor_types_MOD___copy_dbcsr_tensor_types_Dbcsr_tas_dist_t leak:__dbcsr_tensor_types_MOD___copy_dbcsr_tensor_types_Dbcsr_tas_blk_size_t EOF -cat << EOF >> ${INSTALLDIR}/tsan.supp +cat <>${INSTALLDIR}/tsan.supp # tsan bugs likely related to gcc # PR66756 deadlock:_gfortran_st_open @@ -262,7 +262,7 @@ race:__dbcsr_transformations_MOD_dbcsr_make_untransposed_blocks EOF # need to also link to the .supp file in setup file -cat << EOF >> ${SETUPFILE} +cat <>${SETUPFILE} export LSAN_OPTIONS=suppressions=${INSTALLDIR}/lsan.supp export TSAN_OPTIONS=suppressions=${INSTALLDIR}/tsan.supp EOF diff --git a/toolchain/scripts/stage0/install_intel.sh b/toolchain/scripts/stage0/install_intel.sh index f8cc9fe8a6e..af63aa792bc 100755 --- a/toolchain/scripts/stage0/install_intel.sh +++ b/toolchain/scripts/stage0/install_intel.sh @@ -23,78 +23,78 @@ mkdir -p "${BUILDDIR}" cd "${BUILDDIR}" case "${with_intel}" in - __INSTALL__) - echo "==================== Installing the Intel compiler ====================" - report_error ${LINENO} "To install the Intel compiler, please contact your system administrator." - exit 1 - ;; - __SYSTEM__) - echo "==================== Finding Intel compiler from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - if [ "${intel_classic}" = "yes" ]; then - check_command icc "intel" && CC="$(realpath $(command -v icc))" || exit 1 - check_command icpc "intel" && CXX="$(realpath $(command -v icpc))" || exit 1 - check_command ifort "intel" && FC="$(realpath $(command -v ifort))" || exit 1 - else - check_command icx "intel" && CC="$(realpath $(command -v icx))" || exit 1 - check_command icpx "intel" && CXX="$(realpath $(command -v icpx))" || exit 1 - if [ "${WITH_IFX}" = "yes" ]; then - check_command ifx "intel" && FC="$(realpath $(command -v ifx))" || exit 1 - else - check_command ifort "intel" && FC="$(realpath $(command -v ifort))" || exit 1 - fi - fi - F90="${FC}" - F77="${FC}" - ;; - __DONTUSE__) - # Nothing to do - ;; - *) - echo "==================== Linking Intel compiler to user paths ====================" - pkg_install_dir="${with_intel}" - check_dir "${pkg_install_dir}/bin" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - if [ "${intel_classic}" = "yes" ]; then - check_command ${pkg_install_dir}/bin/icc "intel" && CC="${pkg_install_dir}/bin/icc" || exit 1 - check_command ${pkg_install_dir}/bin/icpc "intel" && CXX="${pkg_install_dir}/bin/icpc" || exit 1 - check_command ${pkg_install_dir}/bin/ifort "intel" && FC="${pkg_install_dir}/bin/ifort" || exit 1 - else - check_command ${pkg_install_dir}/bin/icx "intel" && CC="${pkg_install_dir}/bin/icx" || exit 1 - check_command ${pkg_install_dir}/bin/icpx "intel" && CXX="${pkg_install_dir}/bin/icpx" || exit 1 - if [ "${WITH_IFX}" = "yes" ]; then - check_command ${pkg_install_dir}/bin/ifx "intel" && FC="${pkg_install_dir}/bin/ifx" || exit 1 - else - check_command ${pkg_install_dir}/bin/ifort "intel" && FC="${pkg_install_dir}/bin/ifort" || exit 1 - fi - fi - F90="${FC}" - F77="${FC}" - INTEL_CFLAGS="-I'${pkg_install_dir}/include'" - INTEL_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; +__INSTALL__) + echo "==================== Installing the Intel compiler ====================" + report_error ${LINENO} "To install the Intel compiler, please contact your system administrator." + exit 1 + ;; +__SYSTEM__) + echo "==================== Finding Intel compiler from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + if [ "${intel_classic}" = "yes" ]; then + check_command icc "intel" && CC="$(realpath $(command -v icc))" || exit 1 + check_command icpc "intel" && CXX="$(realpath $(command -v icpc))" || exit 1 + check_command ifort "intel" && FC="$(realpath $(command -v ifort))" || exit 1 + else + check_command icx "intel" && CC="$(realpath $(command -v icx))" || exit 1 + check_command icpx "intel" && CXX="$(realpath $(command -v icpx))" || exit 1 + if [ "${WITH_IFX}" = "yes" ]; then + check_command ifx "intel" && FC="$(realpath $(command -v ifx))" || exit 1 + else + check_command ifort "intel" && FC="$(realpath $(command -v ifort))" || exit 1 + fi + fi + F90="${FC}" + F77="${FC}" + ;; +__DONTUSE__) + # Nothing to do + ;; +*) + echo "==================== Linking Intel compiler to user paths ====================" + pkg_install_dir="${with_intel}" + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + if [ "${intel_classic}" = "yes" ]; then + check_command ${pkg_install_dir}/bin/icc "intel" && CC="${pkg_install_dir}/bin/icc" || exit 1 + check_command ${pkg_install_dir}/bin/icpc "intel" && CXX="${pkg_install_dir}/bin/icpc" || exit 1 + check_command ${pkg_install_dir}/bin/ifort "intel" && FC="${pkg_install_dir}/bin/ifort" || exit 1 + else + check_command ${pkg_install_dir}/bin/icx "intel" && CC="${pkg_install_dir}/bin/icx" || exit 1 + check_command ${pkg_install_dir}/bin/icpx "intel" && CXX="${pkg_install_dir}/bin/icpx" || exit 1 + if [ "${WITH_IFX}" = "yes" ]; then + check_command ${pkg_install_dir}/bin/ifx "intel" && FC="${pkg_install_dir}/bin/ifx" || exit 1 + else + check_command ${pkg_install_dir}/bin/ifort "intel" && FC="${pkg_install_dir}/bin/ifort" || exit 1 + fi + fi + F90="${FC}" + F77="${FC}" + INTEL_CFLAGS="-I'${pkg_install_dir}/include'" + INTEL_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "${with_intel}" != "__DONTUSE__" ]; then - echo "CC is ${CC}" - echo "CXX is ${CXX}" - echo "FC is ${FC}" - cat << EOF > "${BUILDDIR}/setup_intel" + echo "CC is ${CC}" + echo "CXX is ${CXX}" + echo "FC is ${FC}" + cat <"${BUILDDIR}/setup_intel" export CC="${CC}" export CXX="${CXX}" export FC="${FC}" export F90="${F90}" export F77="${F77}" EOF - cat << EOF >> "${BUILDDIR}/setup_intel" + cat <>"${BUILDDIR}/setup_intel" export INTEL_CFLAGS="${INTEL_CFLAGS}" export INTEL_LDFLAGS="${INTEL_LDFLAGS}" export INTEL_LIBS="${INTEL_LIBS}" EOF - filter_setup "${BUILDDIR}/setup_intel" ${SETUPFILE} + filter_setup "${BUILDDIR}/setup_intel" ${SETUPFILE} fi load "${BUILDDIR}/setup_intel" diff --git a/toolchain/scripts/stage1/install_intelmpi.sh b/toolchain/scripts/stage1/install_intelmpi.sh index bad4ba604a3..db9c826b99b 100755 --- a/toolchain/scripts/stage1/install_intelmpi.sh +++ b/toolchain/scripts/stage1/install_intelmpi.sh @@ -24,105 +24,105 @@ mkdir -p "${BUILDDIR}" cd "${BUILDDIR}" case "${with_intelmpi}" in - __INSTALL__) - echo "==================== Installing Intel MPI ====================" - report_error ${LINENO} "To install Intel MPI, please contact your system administrator." - exit 1 - ;; - __SYSTEM__) - echo "==================== Finding Intel MPI from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - else - check_command mpiexec "intelmpi" && MPIRUN="$(realpath $(command -v mpiexec))" - if [ "${intel_classic}" = "yes" ]; then - # if intel compiler used as classic, so as intelmpi - export INTELMPI_CLASSIC="yes" - fi - if [ "${with_intel}" != "__DONTUSE__" ]; then - if [ "${INTELMPI_CLASSIC}" = "yes" ]; then - check_command mpiicc "intelmpi" && MPICC="$(realpath $(command -v mpiicc))" || exit 1 - check_command mpiicpc "intelmpi" && MPICXX="$(realpath $(command -v mpiicpc))" || exit 1 - check_command mpiifort "intelmpi" && MPIFC="$(realpath $(command -v mpiifort))" || exit 1 - else - check_command mpiicx "intelmpi" && MPICC="$(realpath $(command -v mpiicx))" || exit 1 - check_command mpiicpx "intelmpi" && MPICXX="$(realpath $(command -v mpiicpx))" || exit 1 - if [ "${WITH_IFX}" == "yes" ]; then - check_command mpiifx "intelmpi" && MPIFC="$(realpath $(command -v mpiifx))" || exit 1 - else - check_command mpiifort "intelmpi" && MPIFC="$(realpath $(command -v mpiifort))" || exit 1 - fi - fi - else - echo "The use of Intel MPI is only supported with the Intel compiler" - exit 1 - fi - MPIFORT="${MPIFC}" - MPIF77="${MPIFC}" - # include path is already handled by compiler wrapper scripts (can cause wrong mpi.mod with GNU Fortran) - # add_include_from_paths INTELMPI_CFLAGS "mpi.h" $INCLUDE_PATHS - add_lib_from_paths INTELMPI_LDFLAGS "libmpi.*" $LIB_PATHS - check_lib -lmpi "intelmpi" - check_lib -lmpicxx "intelmpi" - fi - ;; - __DONTUSE__) - # Nothing to do - ;; - *) - echo "==================== Linking INTELMPI to user paths ====================" - pkg_install_dir="${with_intelmpi}" - check_dir "${pkg_install_dir}/bin" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - check_command ${pkg_install_dir}/bin/mpiexec "intel" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 - if [ "${with_intel}" != "__DONTUSE__" ]; then - if [ "${INTELMPI_CLASSIC}" = "yes" ]; then - check_command ${pkg_install_dir}/bin/mpiicc "intel" && MPICC="${pkg_install_dir}/bin/mpiicc" || exit 1 - check_command ${pkg_install_dir}/bin/mpiicpc "intel" && MPICXX="${pkg_install_dir}/bin/mpiicpc" || exit 1 - check_command ${pkg_install_dir}/bin/mpiifort "intel" && MPIFC="${pkg_install_dir}/bin/mpiifort" || exit 1 - else - check_command ${pkg_install_dir}/bin/mpiicx "intel" && MPICC="${pkg_install_dir}/bin/mpiicx" || exit 1 - check_command ${pkg_install_dir}/bin/mpiicpx "intel" && MPICXX="${pkg_install_dir}/bin/mpiicpx" || exit 1 - if [ "${WITH_IFX}" = "yes" ]; then - check_command ${pkg_install_dir}/bin/mpiifx "intel" && MPIFC="${pkg_install_dir}/bin/mpiifx" || exit 1 - else - check_command ${pkg_install_dir}/bin/mpiifort "intel" && MPIFC="${pkg_install_dir}/bin/mpiifort" || exit 1 - fi - fi +__INSTALL__) + echo "==================== Installing Intel MPI ====================" + report_error ${LINENO} "To install Intel MPI, please contact your system administrator." + exit 1 + ;; +__SYSTEM__) + echo "==================== Finding Intel MPI from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + else + check_command mpiexec "intelmpi" && MPIRUN="$(realpath $(command -v mpiexec))" + if [ "${intel_classic}" = "yes" ]; then + # if intel compiler used as classic, so as intelmpi + export INTELMPI_CLASSIC="yes" + fi + if [ "${with_intel}" != "__DONTUSE__" ]; then + if [ "${INTELMPI_CLASSIC}" = "yes" ]; then + check_command mpiicc "intelmpi" && MPICC="$(realpath $(command -v mpiicc))" || exit 1 + check_command mpiicpc "intelmpi" && MPICXX="$(realpath $(command -v mpiicpc))" || exit 1 + check_command mpiifort "intelmpi" && MPIFC="$(realpath $(command -v mpiifort))" || exit 1 + else + check_command mpiicx "intelmpi" && MPICC="$(realpath $(command -v mpiicx))" || exit 1 + check_command mpiicpx "intelmpi" && MPICXX="$(realpath $(command -v mpiicpx))" || exit 1 + if [ "${WITH_IFX}" == "yes" ]; then + check_command mpiifx "intelmpi" && MPIFC="$(realpath $(command -v mpiifx))" || exit 1 else - echo "The use of Intel MPI is only supported with the Intel compiler" - exit 1 + check_command mpiifort "intelmpi" && MPIFC="$(realpath $(command -v mpiifort))" || exit 1 fi - MPIFORT="${MPIFC}" - MPIF77="${MPIFC}" - # include path is already handled by compiler wrapper scripts (can cause wrong mpi.mod with GNU Fortran) - INTELMPI_CFLAGS="-I'${pkg_install_dir}/include'" - INTELMPI_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; + fi + else + echo "The use of Intel MPI is only supported with the Intel compiler" + exit 1 + fi + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + # include path is already handled by compiler wrapper scripts (can cause wrong mpi.mod with GNU Fortran) + # add_include_from_paths INTELMPI_CFLAGS "mpi.h" $INCLUDE_PATHS + add_lib_from_paths INTELMPI_LDFLAGS "libmpi.*" $LIB_PATHS + check_lib -lmpi "intelmpi" + check_lib -lmpicxx "intelmpi" + fi + ;; +__DONTUSE__) + # Nothing to do + ;; +*) + echo "==================== Linking INTELMPI to user paths ====================" + pkg_install_dir="${with_intelmpi}" + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + check_command ${pkg_install_dir}/bin/mpiexec "intel" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 + if [ "${with_intel}" != "__DONTUSE__" ]; then + if [ "${INTELMPI_CLASSIC}" = "yes" ]; then + check_command ${pkg_install_dir}/bin/mpiicc "intel" && MPICC="${pkg_install_dir}/bin/mpiicc" || exit 1 + check_command ${pkg_install_dir}/bin/mpiicpc "intel" && MPICXX="${pkg_install_dir}/bin/mpiicpc" || exit 1 + check_command ${pkg_install_dir}/bin/mpiifort "intel" && MPIFC="${pkg_install_dir}/bin/mpiifort" || exit 1 + else + check_command ${pkg_install_dir}/bin/mpiicx "intel" && MPICC="${pkg_install_dir}/bin/mpiicx" || exit 1 + check_command ${pkg_install_dir}/bin/mpiicpx "intel" && MPICXX="${pkg_install_dir}/bin/mpiicpx" || exit 1 + if [ "${WITH_IFX}" = "yes" ]; then + check_command ${pkg_install_dir}/bin/mpiifx "intel" && MPIFC="${pkg_install_dir}/bin/mpiifx" || exit 1 + else + check_command ${pkg_install_dir}/bin/mpiifort "intel" && MPIFC="${pkg_install_dir}/bin/mpiifort" || exit 1 + fi + fi + else + echo "The use of Intel MPI is only supported with the Intel compiler" + exit 1 + fi + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + # include path is already handled by compiler wrapper scripts (can cause wrong mpi.mod with GNU Fortran) + INTELMPI_CFLAGS="-I'${pkg_install_dir}/include'" + INTELMPI_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "${with_intelmpi}" != "__DONTUSE__" ]; then - if [ "${intel_classic}" = "yes" ]; then - I_MPI_CXX="icpc" - I_MPI_CC="icc" - I_MPI_FC="ifort" + if [ "${intel_classic}" = "yes" ]; then + I_MPI_CXX="icpc" + I_MPI_CC="icc" + I_MPI_FC="ifort" + else + I_MPI_CXX="icpx" + I_MPI_CC="icx" + if [ "${WITH_IFX}" = "yes" ]; then + I_MPI_FC="ifx" else - I_MPI_CXX="icpx" - I_MPI_CC="icx" - if [ "${WITH_IFX}" = "yes" ]; then - I_MPI_FC="ifx" - else - I_MPI_FC="ifort" - fi + I_MPI_FC="ifort" fi - INTELMPI_LIBS="-lmpi -lmpicxx" - echo "I_MPI_CXX is ${I_MPI_CXX}" - echo "I_MPI_CC is ${I_MPI_CC}" - echo "I_MPI_FC is ${I_MPI_FC}" - echo "MPICXX is ${MPICXX}" - echo "MPICC is ${MPICC}" - echo "MPIFC is ${MPIFC}" - cat << EOF > "${BUILDDIR}/setup_intelmpi" + fi + INTELMPI_LIBS="-lmpi -lmpicxx" + echo "I_MPI_CXX is ${I_MPI_CXX}" + echo "I_MPI_CC is ${I_MPI_CC}" + echo "I_MPI_FC is ${I_MPI_FC}" + echo "MPICXX is ${MPICXX}" + echo "MPICC is ${MPICC}" + echo "MPIFC is ${MPIFC}" + cat <"${BUILDDIR}/setup_intelmpi" export I_MPI_CXX="${I_MPI_CXX}" export I_MPI_CC="${I_MPI_CC}" export I_MPI_FC="${I_MPI_FC}" @@ -144,7 +144,7 @@ export CP_CFLAGS="\${CP_CFLAGS} IF_MPI(${INTELMPI_CFLAGS}|)" export CP_LDFLAGS="\${CP_LDFLAGS} IF_MPI(${INTELMPI_LDFLAGS}|)" export CP_LIBS="\${CP_LIBS} IF_MPI(${INTELMPI_LIBS}|)" EOF - filter_setup "${BUILDDIR}/setup_intelmpi" ${SETUPFILE} + filter_setup "${BUILDDIR}/setup_intelmpi" ${SETUPFILE} fi load "${BUILDDIR}/setup_intelmpi" diff --git a/toolchain/scripts/stage1/install_mpich.sh b/toolchain/scripts/stage1/install_mpich.sh index 66cdf1cfbfc..eb571995dd4 100755 --- a/toolchain/scripts/stage1/install_mpich.sh +++ b/toolchain/scripts/stage1/install_mpich.sh @@ -13,16 +13,16 @@ source "${SCRIPT_DIR}"/package_versions.sh # Check for version configuration from environment or individual package setting version_suffix="" if [[ -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]]; then - # Check for individual package version override - if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "mpich:alt"; then - version_suffix="alt" - elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "mpich:main"; then - version_suffix="main" - fi + # Check for individual package version override + if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "mpich:alt"; then + version_suffix="alt" + elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "mpich:main"; then + version_suffix="main" + fi fi # Fall back to global version suffix if no individual setting if [[ -z "$version_suffix" && -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" ]]; then - version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" + version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" fi # Load package variables with appropriate version load_package_vars "mpich" "$version_suffix" @@ -41,109 +41,109 @@ source "${INSTALLDIR}"/toolchain.env cd "${BUILDDIR}" case "${with_mpich}" in - __INSTALL__) - echo "==================== Installing MPICH ====================" - pkg_install_dir="${INSTALLDIR}/mpich-${mpich_ver}" - #pkg_install_dir="${HOME}/apps/mpich/${mpich_ver}-intel" - install_lock_file="${pkg_install_dir}/install_successful" - url="https://www.mpich.org/static/downloads/${mpich_ver}/${mpich_pkg}" - if verify_checksums "${install_lock_file}"; then - echo "mpich-${mpich_ver} is already installed, skipping it." - else - retrieve_package "${mpich_sha256}" "${mpich_pkg}" "${url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - echo "Installing from scratch into ${pkg_install_dir} for MPICH device ${MPICH_DEVICE}" - [ -d mpich-${mpich_ver} ] && rm -rf mpich-${mpich_ver} - tar -xzf ${mpich_pkg} - cd mpich-${mpich_ver} - unset F90 - unset F90FLAGS +__INSTALL__) + echo "==================== Installing MPICH ====================" + pkg_install_dir="${INSTALLDIR}/mpich-${mpich_ver}" + #pkg_install_dir="${HOME}/apps/mpich/${mpich_ver}-intel" + install_lock_file="${pkg_install_dir}/install_successful" + url="https://www.mpich.org/static/downloads/${mpich_ver}/${mpich_pkg}" + if verify_checksums "${install_lock_file}"; then + echo "mpich-${mpich_ver} is already installed, skipping it." + else + retrieve_package "${mpich_sha256}" "${mpich_pkg}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir} for MPICH device ${MPICH_DEVICE}" + [ -d mpich-${mpich_ver} ] && rm -rf mpich-${mpich_ver} + tar -xzf ${mpich_pkg} + cd mpich-${mpich_ver} + unset F90 + unset F90FLAGS - # workaround for compilation with GCC >= 10, until properly fixed: - # https://github.com/pmodels/mpich/issues/4300 - if ("${FC}" --version | grep -q 'GNU'); then - compat_flag=$(allowed_gfortran_flags "-fallow-argument-mismatch") - fi - ./configure \ - --prefix="${pkg_install_dir}" \ - --libdir="${pkg_install_dir}/lib" \ - FFLAGS="${FCFLAGS} ${compat_flag}" \ - FCFLAGS="${FCFLAGS} ${compat_flag}" \ - --with-device=${MPICH_DEVICE} \ - > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log - make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log - make install > install.log 2>&1 || tail -n ${LOG_LINES} install.log - cd .. - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage1/$(basename ${SCRIPT_NAME})" - fi - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_dir "${pkg_install_dir}/bin" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - check_install ${pkg_install_dir}/bin/mpiexec "mpich" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 - check_install ${pkg_install_dir}/bin/mpicc "mpich" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 - check_install ${pkg_install_dir}/bin/mpicxx "mpich" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 - check_install ${pkg_install_dir}/bin/mpifort "mpich" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 - MPIFORT="${MPIFC}" - MPIF77="${MPIFC}" - MPICH_CFLAGS="-I'${pkg_install_dir}/include'" - MPICH_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; - __SYSTEM__) - echo "==================== Finding MPICH from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_command mpiexec "mpich" && MPIRUN="$(command -v mpiexec)" - check_command mpicc "mpich" && MPICC="$(command -v mpicc)" || exit 1 - if [ $(command -v mpic++ > /dev/null 2>&1) ]; then - check_command mpic++ "mpich" && MPICXX="$(command -v mpic++)" || exit 1 - else - check_command mpicxx "mpich" && MPICXX="$(command -v mpicxx)" || exit 1 - fi - check_command mpifort "mpich" && MPIFC="$(command -v mpifort)" || exit 1 - MPIFORT="${MPIFC}" - MPIF77="${MPIFC}" - check_lib -lmpifort "mpich" - check_lib -lmpicxx "mpich" - check_lib -lmpi "mpich" - add_include_from_paths MPICH_CFLAGS "mpi.h" ${INCLUDE_PATHS} - add_lib_from_paths MPICH_LDFLAGS "libmpi.*" ${LIB_PATHS} - ;; - __DONTUSE__) - # Nothing to do - ;; - *) - echo "==================== Linking MPICH to user paths ====================" - pkg_install_dir="${with_mpich}" - check_dir "${pkg_install_dir}/bin" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - check_command ${pkg_install_dir}/bin/mpiexec "mpich" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 - check_command ${pkg_install_dir}/bin/mpicc "mpich" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 - check_command ${pkg_install_dir}/bin/mpicxx "mpich" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 - check_command ${pkg_install_dir}/bin/mpifort "mpich" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 - MPIFORT="${MPIFC}" - MPIF77="${MPIFC}" - MPICH_CFLAGS="-I'${pkg_install_dir}/include'" - MPICH_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; + # workaround for compilation with GCC >= 10, until properly fixed: + # https://github.com/pmodels/mpich/issues/4300 + if ("${FC}" --version | grep -q 'GNU'); then + compat_flag=$(allowed_gfortran_flags "-fallow-argument-mismatch") + fi + ./configure \ + --prefix="${pkg_install_dir}" \ + --libdir="${pkg_install_dir}/lib" \ + FFLAGS="${FCFLAGS} ${compat_flag}" \ + FCFLAGS="${FCFLAGS} ${compat_flag}" \ + --with-device=${MPICH_DEVICE} \ + >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage1/$(basename ${SCRIPT_NAME})" + fi + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + check_install ${pkg_install_dir}/bin/mpiexec "mpich" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 + check_install ${pkg_install_dir}/bin/mpicc "mpich" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 + check_install ${pkg_install_dir}/bin/mpicxx "mpich" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 + check_install ${pkg_install_dir}/bin/mpifort "mpich" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + MPICH_CFLAGS="-I'${pkg_install_dir}/include'" + MPICH_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +__SYSTEM__) + echo "==================== Finding MPICH from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_command mpiexec "mpich" && MPIRUN="$(command -v mpiexec)" + check_command mpicc "mpich" && MPICC="$(command -v mpicc)" || exit 1 + if [ $(command -v mpic++ >/dev/null 2>&1) ]; then + check_command mpic++ "mpich" && MPICXX="$(command -v mpic++)" || exit 1 + else + check_command mpicxx "mpich" && MPICXX="$(command -v mpicxx)" || exit 1 + fi + check_command mpifort "mpich" && MPIFC="$(command -v mpifort)" || exit 1 + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + check_lib -lmpifort "mpich" + check_lib -lmpicxx "mpich" + check_lib -lmpi "mpich" + add_include_from_paths MPICH_CFLAGS "mpi.h" ${INCLUDE_PATHS} + add_lib_from_paths MPICH_LDFLAGS "libmpi.*" ${LIB_PATHS} + ;; +__DONTUSE__) + # Nothing to do + ;; +*) + echo "==================== Linking MPICH to user paths ====================" + pkg_install_dir="${with_mpich}" + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + check_command ${pkg_install_dir}/bin/mpiexec "mpich" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 + check_command ${pkg_install_dir}/bin/mpicc "mpich" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 + check_command ${pkg_install_dir}/bin/mpicxx "mpich" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 + check_command ${pkg_install_dir}/bin/mpifort "mpich" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + MPICH_CFLAGS="-I'${pkg_install_dir}/include'" + MPICH_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "${with_mpich}" != "__DONTUSE__" ]; then - if [ "${with_mpich}" != "__SYSTEM__" ]; then - mpi_bin="${pkg_install_dir}/bin/mpiexec" - else - mpi_bin="mpiexec" - fi - MPICH_LIBS="-lmpifort -lmpicxx -lmpi" - cat << EOF > "${BUILDDIR}/setup_mpich" + if [ "${with_mpich}" != "__SYSTEM__" ]; then + mpi_bin="${pkg_install_dir}/bin/mpiexec" + else + mpi_bin="mpiexec" + fi + MPICH_LIBS="-lmpifort -lmpicxx -lmpi" + cat <"${BUILDDIR}/setup_mpich" export MPI_MODE="${MPI_MODE}" export MPIRUN="${MPIRUN}" export MPICC="${MPICC}" @@ -162,20 +162,20 @@ export CP_CFLAGS="\${CP_CFLAGS} IF_MPI(${MPICH_CFLAGS}|)" export CP_LDFLAGS="\${CP_LDFLAGS} IF_MPI(${MPICH_LDFLAGS}|)" export CP_LIBS="\${CP_LIBS} IF_MPI(${MPICH_LIBS}|)" EOF - if [ "${with_mpich}" != "__SYSTEM__" ]; then - cat << EOF >> "${BUILDDIR}/setup_mpich" + if [ "${with_mpich}" != "__SYSTEM__" ]; then + cat <>"${BUILDDIR}/setup_mpich" prepend_path PATH "${pkg_install_dir}/bin" prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" prepend_path CPATH "${pkg_install_dir}/include" EOF - fi - filter_setup "${BUILDDIR}/setup_mpich" ${SETUPFILE} + fi + filter_setup "${BUILDDIR}/setup_mpich" ${SETUPFILE} fi # Update leak suppression file -cat << EOF >> ${INSTALLDIR}/lsan.supp +cat <>${INSTALLDIR}/lsan.supp # MPICH 3.3.2 with GCC 10.3.0 leak:MPIR_Find_local_and_external leak:MPIU_Find_local_and_external diff --git a/toolchain/scripts/stage1/install_openmpi.sh b/toolchain/scripts/stage1/install_openmpi.sh index f9700776bd4..de1da98a845 100755 --- a/toolchain/scripts/stage1/install_openmpi.sh +++ b/toolchain/scripts/stage1/install_openmpi.sh @@ -13,16 +13,16 @@ source "${SCRIPT_DIR}"/package_versions.sh # Check for version configuration from environment or individual package setting version_suffix="" if [[ -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]]; then - # Check for individual package version override - if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "openmpi:alt"; then - version_suffix="alt" - elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "openmpi:main"; then - version_suffix="main" - fi + # Check for individual package version override + if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "openmpi:alt"; then + version_suffix="alt" + elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "openmpi:main"; then + version_suffix="main" + fi fi # Fall back to global version suffix if no individual setting if [[ -z "$version_suffix" && -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" ]]; then - version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" + version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" fi # Load package variables with appropriate version load_package_vars "openmpi" "$version_suffix" @@ -44,141 +44,141 @@ OPENMPI_LIBS="" cd "${BUILDDIR}" case "${with_openmpi}" in - __INSTALL__) - echo "==================== Installing OpenMPI ====================" - pkg_install_dir="${INSTALLDIR}/openmpi-${openmpi_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - url="https://download.open-mpi.org/release/open-mpi/v${openmpi_ver%.*}/${openmpi_pkg}" - if verify_checksums "${install_lock_file}"; then - echo "openmpi-${openmpi_ver} is already installed, skipping it." - else - retrieve_package "${openmpi_sha256}" "${openmpi_pkg}" "${url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d openmpi-${openmpi_ver} ] && rm -rf openmpi-${openmpi_ver} - tar -xjf ${openmpi_pkg} - cd openmpi-${openmpi_ver} - if [ "${SYSTEM_ARCH}" = "x86_64" ]; then - # can have issue with older glibc libraries, in which case - # we need to add the -fgnu89-inline to CFLAGS. We can check - # the version of glibc using ldd --version, as ldd is part of - # glibc package - glibc_version=$(ldd --version | awk '/ldd/{print $NF}') - glibc_major_ver=${glibc_version%%.*} - glibc_minor_ver=${glibc_version##*.} - if [ $glibc_major_ver -lt 2 ] || - [ $glibc_major_ver -eq 2 -a $glibc_minor_ver -lt 12 ]; then - CFLAGS="${CFLAGS} -fgnu89-inline" - fi - fi +__INSTALL__) + echo "==================== Installing OpenMPI ====================" + pkg_install_dir="${INSTALLDIR}/openmpi-${openmpi_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + url="https://download.open-mpi.org/release/open-mpi/v${openmpi_ver%.*}/${openmpi_pkg}" + if verify_checksums "${install_lock_file}"; then + echo "openmpi-${openmpi_ver} is already installed, skipping it." + else + retrieve_package "${openmpi_sha256}" "${openmpi_pkg}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d openmpi-${openmpi_ver} ] && rm -rf openmpi-${openmpi_ver} + tar -xjf ${openmpi_pkg} + cd openmpi-${openmpi_ver} + if [ "${SYSTEM_ARCH}" = "x86_64" ]; then + # can have issue with older glibc libraries, in which case + # we need to add the -fgnu89-inline to CFLAGS. We can check + # the version of glibc using ldd --version, as ldd is part of + # glibc package + glibc_version=$(ldd --version | awk '/ldd/{print $NF}') + glibc_major_ver=${glibc_version%%.*} + glibc_minor_ver=${glibc_version##*.} + if [ $glibc_major_ver -lt 2 ] || + [ $glibc_major_ver -eq 2 -a $glibc_minor_ver -lt 12 ]; then + CFLAGS="${CFLAGS} -fgnu89-inline" + fi + fi - # Notice for RHEL8 refer https://github.com/open-mpi/ompi/issues/13103 + # Notice for RHEL8 refer https://github.com/open-mpi/ompi/issues/13103 - # OpenMPI 5.0 only supports PMIx - # PMI support is required for Slurm, but not for other schedulers - # default not use - # for OpenMPI 4.1 with pmi slurm, we can open this setting manually - # if [ $(command -v srun) ]; then - # echo "Slurm installation found. OpenMPI will be configured with --with-pmi." - # EXTRA_CONFIGURE_FLAGS="--with-pmi" - # else - # EXTRA_CONFIGURE_FLAGS="" - # fi - ./configure \ - CC=gcc \ - CXX=g++ \ - FC=gfortran \ - F77=gfortran \ - CFLAGS="${CFLAGS}" \ - --prefix=${pkg_install_dir} \ - --libdir="${pkg_install_dir}/lib" \ - --with-libevent=internal \ - ${EXTRA_CONFIGURE_FLAGS} \ - > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log - make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log - make -j $(get_nprocs) install > install.log 2>&1 || tail -n ${LOG_LINES} install.log - cd .. - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage1/$(basename ${SCRIPT_NAME})" - fi - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - else - check_dir "${pkg_install_dir}/bin" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - check_install ${pkg_install_dir}/bin/mpiexec "openmpi" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 - check_install ${pkg_install_dir}/bin/mpicc "openmpi" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 - check_install ${pkg_install_dir}/bin/mpicxx "openmpi" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 - check_install ${pkg_install_dir}/bin/mpifort "openmpi" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 - MPIFORT="${MPIFC}" - MPIF77="${MPIFC}" - OPENMPI_CFLAGS="-I'${pkg_install_dir}/include'" - OPENMPI_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - fi - ;; - __SYSTEM__) - echo "==================== Finding OpenMPI from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_command mpiexec "openmpi" && MPIRUN="$(command -v mpiexec)" - check_command mpicc "openmpi" && MPICC="$(command -v mpicc)" || exit 1 - check_command mpicxx "openmpi" && MPICXX="$(command -v mpicxx)" || exit 1 - check_command mpifort "openmpi" && MPIFC="$(command -v mpifort)" || exit 1 - MPIFORT="${MPIFC}" - MPIF77="${MPIFC}" - ;; - __DONTUSE__) - # Nothing to do - ;; - *) - echo "==================== Linking OpenMPI to user paths ====================" - pkg_install_dir="${with_openmpi}" - check_dir "${pkg_install_dir}/bin" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - check_command ${pkg_install_dir}/bin/mpiexec "openmpi" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 - check_command ${pkg_install_dir}/bin/mpicc "openmpi" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 - check_command ${pkg_install_dir}/bin/mpicxx "openmpi" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 - check_command ${pkg_install_dir}/bin/mpifort "openmpi" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 - MPIFORT="${MPIFC}" - MPIF77="${MPIFC}" - OPENMPI_CFLAGS="-I'${pkg_install_dir}/include'" - OPENMPI_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; + # OpenMPI 5.0 only supports PMIx + # PMI support is required for Slurm, but not for other schedulers + # default not use + # for OpenMPI 4.1 with pmi slurm, we can open this setting manually + # if [ $(command -v srun) ]; then + # echo "Slurm installation found. OpenMPI will be configured with --with-pmi." + # EXTRA_CONFIGURE_FLAGS="--with-pmi" + # else + # EXTRA_CONFIGURE_FLAGS="" + # fi + ./configure \ + CC=gcc \ + CXX=g++ \ + FC=gfortran \ + F77=gfortran \ + CFLAGS="${CFLAGS}" \ + --prefix=${pkg_install_dir} \ + --libdir="${pkg_install_dir}/lib" \ + --with-libevent=internal \ + ${EXTRA_CONFIGURE_FLAGS} \ + >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j $(get_nprocs) install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage1/$(basename ${SCRIPT_NAME})" + fi + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + else + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + check_install ${pkg_install_dir}/bin/mpiexec "openmpi" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 + check_install ${pkg_install_dir}/bin/mpicc "openmpi" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 + check_install ${pkg_install_dir}/bin/mpicxx "openmpi" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 + check_install ${pkg_install_dir}/bin/mpifort "openmpi" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + OPENMPI_CFLAGS="-I'${pkg_install_dir}/include'" + OPENMPI_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + fi + ;; +__SYSTEM__) + echo "==================== Finding OpenMPI from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_command mpiexec "openmpi" && MPIRUN="$(command -v mpiexec)" + check_command mpicc "openmpi" && MPICC="$(command -v mpicc)" || exit 1 + check_command mpicxx "openmpi" && MPICXX="$(command -v mpicxx)" || exit 1 + check_command mpifort "openmpi" && MPIFC="$(command -v mpifort)" || exit 1 + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + ;; +__DONTUSE__) + # Nothing to do + ;; +*) + echo "==================== Linking OpenMPI to user paths ====================" + pkg_install_dir="${with_openmpi}" + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + check_command ${pkg_install_dir}/bin/mpiexec "openmpi" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 + check_command ${pkg_install_dir}/bin/mpicc "openmpi" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 + check_command ${pkg_install_dir}/bin/mpicxx "openmpi" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 + check_command ${pkg_install_dir}/bin/mpifort "openmpi" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + OPENMPI_CFLAGS="-I'${pkg_install_dir}/include'" + OPENMPI_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip env setting" + echo "--pack-run mode specified, skip env setting" else - if [ "${with_openmpi}" != "__DONTUSE__" ]; then - if [ "${with_openmpi}" != "__SYSTEM__" ]; then - mpi_bin="${pkg_install_dir}/bin/mpiexec" - mpicxx_bin="${pkg_install_dir}/bin/mpicxx" - else - mpi_bin="mpiexec" - mpicxx_bin="mpicxx" - fi - # check openmpi version as reported by mpiexec - raw_version=$(${mpi_bin} --version 2>&1 | - grep "(Open MPI)" | awk '{print $4}') - major_version=$(echo ${raw_version} | cut -d '.' -f 1) - minor_version=$(echo ${raw_version} | cut -d '.' -f 2) - OPENMPI_BINDING_POLICY_ENV="export OMPI_MCA_hwloc_base_binding_policy=none" - if [[ "${major_version}" =~ ^[0-9]+$ && "${major_version}" -ge 5 ]]; then - OPENMPI_BINDING_POLICY_ENV="export PRTE_MCA_hwloc_default_binding_policy=none" - fi - OPENMPI_LIBS="" - # grab additional runtime libs (for C/C++) from the mpicxx wrapper, - # and remove them from the LDFLAGS if present - for lib in $("${mpicxx_bin}" --showme:libs); do - OPENMPI_LIBS+=" -l${lib}" - OPENMPI_LDFLAGS="${OPENMPI_LDFLAGS//-l${lib}/}" - done - cat << EOF > "${BUILDDIR}/setup_openmpi" + if [ "${with_openmpi}" != "__DONTUSE__" ]; then + if [ "${with_openmpi}" != "__SYSTEM__" ]; then + mpi_bin="${pkg_install_dir}/bin/mpiexec" + mpicxx_bin="${pkg_install_dir}/bin/mpicxx" + else + mpi_bin="mpiexec" + mpicxx_bin="mpicxx" + fi + # check openmpi version as reported by mpiexec + raw_version=$(${mpi_bin} --version 2>&1 | + grep "(Open MPI)" | awk '{print $4}') + major_version=$(echo ${raw_version} | cut -d '.' -f 1) + minor_version=$(echo ${raw_version} | cut -d '.' -f 2) + OPENMPI_BINDING_POLICY_ENV="export OMPI_MCA_hwloc_base_binding_policy=none" + if [[ "${major_version}" =~ ^[0-9]+$ && "${major_version}" -ge 5 ]]; then + OPENMPI_BINDING_POLICY_ENV="export PRTE_MCA_hwloc_default_binding_policy=none" + fi + OPENMPI_LIBS="" + # grab additional runtime libs (for C/C++) from the mpicxx wrapper, + # and remove them from the LDFLAGS if present + for lib in $("${mpicxx_bin}" --showme:libs); do + OPENMPI_LIBS+=" -l${lib}" + OPENMPI_LDFLAGS="${OPENMPI_LDFLAGS//-l${lib}/}" + done + cat <"${BUILDDIR}/setup_openmpi" export MPI_MODE="${MPI_MODE}" export MPIRUN="${MPIRUN}" export MPICC="${MPICC}" @@ -203,22 +203,22 @@ export CP_CFLAGS="\${CP_CFLAGS} IF_MPI(${OPENMPI_CFLAGS}|)" export CP_LDFLAGS="\${CP_LDFLAGS} IF_MPI(${OPENMPI_LDFLAGS}|)" export CP_LIBS="\${CP_LIBS} IF_MPI(${OPENMPI_LIBS}|)" EOF - if [ "${with_openmpi}" != "__SYSTEM__" ]; then - cat << EOF >> "${BUILDDIR}/setup_openmpi" + if [ "${with_openmpi}" != "__SYSTEM__" ]; then + cat <>"${BUILDDIR}/setup_openmpi" prepend_path PATH "${pkg_install_dir}/bin" prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" prepend_path CPATH "${pkg_install_dir}/include" EOF - fi - filter_setup "${BUILDDIR}/setup_openmpi" ${SETUPFILE} fi + filter_setup "${BUILDDIR}/setup_openmpi" ${SETUPFILE} + fi - # ---------------------------------------------------------------------- - # Suppress reporting of known leaks - # ---------------------------------------------------------------------- - cat << EOF >> ${INSTALLDIR}/valgrind.supp + # ---------------------------------------------------------------------- + # Suppress reporting of known leaks + # ---------------------------------------------------------------------- + cat <>${INSTALLDIR}/valgrind.supp { Memcheck:Leak @@ -265,7 +265,7 @@ EOF fun:ompi_comm_activate } EOF - cat << EOF >> ${INSTALLDIR}/lsan.supp + cat <>${INSTALLDIR}/lsan.supp # leaks related to OpenMPI leak:query_2_0_0 leak:ompi_init_f diff --git a/toolchain/scripts/stage2/install_aocl.sh b/toolchain/scripts/stage2/install_aocl.sh index 2145b647873..b61892950b8 100755 --- a/toolchain/scripts/stage2/install_aocl.sh +++ b/toolchain/scripts/stage2/install_aocl.sh @@ -21,43 +21,43 @@ AOCL_ROOT="" cd "${BUILDDIR}" case "${with_aocl}" in - __INSTALL__) - echo "==================== Installing AOCL ====================" - report_error ${LINENO} "To install AOCL, please contact your system administrator." - exit 1 - ;; - __SYSTEM__) - echo "==================== Finding AOCL from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_lib -lblis "AOCL" - check_lib -lflame "AOCL" - AOCL_LIBS="-lblis -lflame" - add_include_from_paths AOCL_CFLAGS "blis.h" $INCLUDE_PATHS - add_lib_from_paths AOCL_LDFLAGS "libblis.*" $LIB_PATHS - add_include_from_paths AOCL_CFLAGS "lapack.h" $INCLUDE_PATHS - add_lib_from_paths AOCL_LDFLAGS "libflame.*" $LIB_PATHS - ;; - __DONTUSE__) - ;; - *) - echo "==================== Linking AOCL to user paths ====================" - pkg_install_dir="$with_aocl" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_dir "${pkg_install_dir}/include" - check_dir "${pkg_install_dir}/lib" - AOCL_CFLAGS="-I'${pkg_install_dir}/include'" - AOCL_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - AOCL_LIBS="-lblis -lflame" - ;; +__INSTALL__) + echo "==================== Installing AOCL ====================" + report_error ${LINENO} "To install AOCL, please contact your system administrator." + exit 1 + ;; +__SYSTEM__) + echo "==================== Finding AOCL from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_lib -lblis "AOCL" + check_lib -lflame "AOCL" + AOCL_LIBS="-lblis -lflame" + add_include_from_paths AOCL_CFLAGS "blis.h" $INCLUDE_PATHS + add_lib_from_paths AOCL_LDFLAGS "libblis.*" $LIB_PATHS + add_include_from_paths AOCL_CFLAGS "lapack.h" $INCLUDE_PATHS + add_lib_from_paths AOCL_LDFLAGS "libflame.*" $LIB_PATHS + ;; +__DONTUSE__) + ;; +*) + echo "==================== Linking AOCL to user paths ====================" + pkg_install_dir="$with_aocl" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_dir "${pkg_install_dir}/include" + check_dir "${pkg_install_dir}/lib" + AOCL_CFLAGS="-I'${pkg_install_dir}/include'" + AOCL_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + AOCL_LIBS="-lblis -lflame" + ;; esac if [ "$with_aocl" != "__DONTUSE__" ]; then - cat << EOF >> "${BUILDDIR}/setup_aocl" + cat <>"${BUILDDIR}/setup_aocl" export AOCL_ROOT="${pkg_install_dir}" export AOCL_CFLAGS="${AOCL_CFLAGS}" export AOCL_LDFLAGS="${AOCL_LDFLAGS}" @@ -66,7 +66,7 @@ export MATH_CFLAGS="\${MATH_CFLAGS} ${AOCL_CFLAGS}" export MATH_LDFLAGS="\${MATH_LDFLAGS} ${AOCL_LDFLAGS}" export MATH_LIBS="\${MATH_LIBS} ${AOCL_LIBS}" EOF - filter_setup "${BUILDDIR}/setup_aocl" $SETUPFILE + filter_setup "${BUILDDIR}/setup_aocl" $SETUPFILE fi load "${BUILDDIR}/setup_aocl" diff --git a/toolchain/scripts/stage2/install_mathlibs.sh b/toolchain/scripts/stage2/install_mathlibs.sh index f747101c80b..68a589bb77b 100755 --- a/toolchain/scripts/stage2/install_mathlibs.sh +++ b/toolchain/scripts/stage2/install_mathlibs.sh @@ -21,24 +21,24 @@ export MATH_LIBS='' write_toolchain_env "${INSTALLDIR}" case "$MATH_MODE" in - mkl) - "${SCRIPTDIR}"/stage2/install_mkl.sh "${with_mkl}" - load "${BUILDDIR}/setup_mkl" - ;; - aocl) - "${SCRIPTDIR}"/stage2/install_aocl.sh "${with_aocl}" - load "${BUILDDIR}/setup_aocl" - ;; - openblas) - "${SCRIPTDIR}"/stage2/install_openblas.sh "${with_openblas}" - load "${BUILDDIR}/setup_openblas" - ;; - cray) - # note the space is intentional so that the variable is - # non-empty and can pass require_env checks - export MATH_LDFLAGS="${MATH_LDFLAGS} " - export MATH_LIBS="${MATH_LIBS} ${CRAY_EXTRA_LIBS}" - ;; +mkl) + "${SCRIPTDIR}"/stage2/install_mkl.sh "${with_mkl}" + load "${BUILDDIR}/setup_mkl" + ;; +aocl) + "${SCRIPTDIR}"/stage2/install_aocl.sh "${with_aocl}" + load "${BUILDDIR}/setup_aocl" + ;; +openblas) + "${SCRIPTDIR}"/stage2/install_openblas.sh "${with_openblas}" + load "${BUILDDIR}/setup_openblas" + ;; +cray) + # note the space is intentional so that the variable is + # non-empty and can pass require_env checks + export MATH_LDFLAGS="${MATH_LDFLAGS} " + export MATH_LIBS="${MATH_LIBS} ${CRAY_EXTRA_LIBS}" + ;; esac export CP_CFLAGS="${CP_CFLAGS} ${MATH_CFLAGS}" diff --git a/toolchain/scripts/stage2/install_mkl.sh b/toolchain/scripts/stage2/install_mkl.sh index 62d9f0bd6ef..6694aace893 100755 --- a/toolchain/scripts/stage2/install_mkl.sh +++ b/toolchain/scripts/stage2/install_mkl.sh @@ -23,96 +23,94 @@ MKL_FFTW="yes" cd "${BUILDDIR}" case "${with_mkl}" in - __INSTALL__) - echo "==================== Installing MKL ====================" - report_error ${LINENO} "To install MKL, please contact your system administrator." - exit 1 - ;; - __SYSTEM__) - echo "==================== Finding MKL from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - if ! [ -z "${MKLROOT}" ]; then - echo "MKLROOT is found to be ${MKLROOT}" - else - report_error ${LINENO} "Cannot find env variable MKLROOT, the script relies on it being set. Please check in MKL installation and use --with-mkl= to pass the path to MKL root directory to this script." - exit 1 - fi - check_lib -lm - check_lib -ldl - ;; - __DONTUSE__) - # Nothing to do - ;; - *) - echo "==================== Linking MKL to user paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_dir "${with_mkl}" - MKLROOT="${with_mkl}" - ;; +__INSTALL__) + echo "==================== Installing MKL ====================" + report_error ${LINENO} "To install MKL, please contact your system administrator." + exit 1 + ;; +__SYSTEM__) + echo "==================== Finding MKL from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + if ! [ -z "${MKLROOT}" ]; then + echo "MKLROOT is found to be ${MKLROOT}" + else + report_error ${LINENO} "Cannot find env variable MKLROOT, the script relies on it being set. Please check in MKL installation and use --with-mkl= to pass the path to MKL root directory to this script." + exit 1 + fi + check_lib -lm + check_lib -ldl + ;; +__DONTUSE__) + # Nothing to do + ;; +*) + echo "==================== Linking MKL to user paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_dir "${with_mkl}" + MKLROOT="${with_mkl}" + ;; esac if [ "${with_mkl}" != "__DONTUSE__" ]; then - case "${SYSTEM_ARCH}" in - x86_64) - mkl_arch_dir="intel64" - MKL_CFLAGS="-m64" - ;; - i386) - mkl_arch_dir="ia32" - MKL_CFLAGS="-m32" - ;; - *) - report_error $LINENO "MKL only supports intel64 (x86_64) and ia32 (i386) at the moment, but the detected architecture is ${SYSTEM_ARCH}" - exit 1 - ;; - esac - mkl_lib_dir="${MKLROOT}/lib/${mkl_arch_dir}" - # check we have required libraries - mkl_required_libs="libmkl_gf_lp64.so libmkl_sequential.so libmkl_core.so" - for ii in $mkl_required_libs; do - if [ ! -f "$mkl_lib_dir/${ii}" ]; then - report_error $LINENO "missing MKL library ${ii}" - exit 1 - fi - done - - - case ${MPI_MODE} in - intelmpi | mpich) - mkl_scalapack_lib="IF_MPI(-lmkl_scalapack_lp64|)" - mkl_blacs_lib="IF_MPI(-lmkl_blacs_intelmpi_lp64|)" - ;; - openmpi) - mkl_scalapack_lib="IF_MPI(-lmkl_scalapack_lp64|)" - mkl_blacs_lib="IF_MPI(-lmkl_blacs_openmpi_lp64|)" - ;; - *) - echo "Not using MKL provided ScaLAPACK and BLACS" - mkl_scalapack_lib="" - mkl_blacs_lib="" - ;; - esac + case "${SYSTEM_ARCH}" in + x86_64) + mkl_arch_dir="intel64" + MKL_CFLAGS="-m64" + ;; + i386) + mkl_arch_dir="ia32" + MKL_CFLAGS="-m32" + ;; + *) + report_error $LINENO "MKL only supports intel64 (x86_64) and ia32 (i386) at the moment, but the detected architecture is ${SYSTEM_ARCH}" + exit 1 + ;; + esac + mkl_lib_dir="${MKLROOT}/lib/${mkl_arch_dir}" + # check we have required libraries + mkl_required_libs="libmkl_gf_lp64.so libmkl_sequential.so libmkl_core.so" + for ii in $mkl_required_libs; do + if [ ! -f "$mkl_lib_dir/${ii}" ]; then + report_error $LINENO "missing MKL library ${ii}" + exit 1 + fi + done + case ${MPI_MODE} in + intelmpi | mpich) + mkl_scalapack_lib="IF_MPI(-lmkl_scalapack_lp64|)" + mkl_blacs_lib="IF_MPI(-lmkl_blacs_intelmpi_lp64|)" + ;; + openmpi) + mkl_scalapack_lib="IF_MPI(-lmkl_scalapack_lp64|)" + mkl_blacs_lib="IF_MPI(-lmkl_blacs_openmpi_lp64|)" + ;; + *) + echo "Not using MKL provided ScaLAPACK and BLACS" + mkl_scalapack_lib="" + mkl_blacs_lib="" + ;; + esac - # added by trae - MKL_LDFLAGS="-L'${mkl_lib_dir}' -Wl,-rpath,'${mkl_lib_dir}'" - # set the correct lib flags from MLK link adviser - MKL_LIBS="-L${mkl_lib_dir} -Wl,-rpath,${mkl_lib_dir} ${mkl_scalapack_lib}" - MKL_LIBS+=" -Wl,--start-group -lmkl_gf_lp64 -lmkl_sequential -lmkl_core" - MKL_LIBS+=" ${mkl_blacs_lib} -Wl,--end-group -lpthread -lm -ldl" - # setup_mkl disables using separate FFTW library (see below) - MKL_CFLAGS="${MKL_CFLAGS} -I${MKLROOT}/include" - if [ "${MKL_FFTW}" != "no" ]; then - MKL_CFLAGS+=" -I${MKLROOT}/include/fftw" - fi + # added by trae + MKL_LDFLAGS="-L'${mkl_lib_dir}' -Wl,-rpath,'${mkl_lib_dir}'" + # set the correct lib flags from MLK link adviser + MKL_LIBS="-L${mkl_lib_dir} -Wl,-rpath,${mkl_lib_dir} ${mkl_scalapack_lib}" + MKL_LIBS+=" -Wl,--start-group -lmkl_gf_lp64 -lmkl_sequential -lmkl_core" + MKL_LIBS+=" ${mkl_blacs_lib} -Wl,--end-group -lpthread -lm -ldl" + # setup_mkl disables using separate FFTW library (see below) + MKL_CFLAGS="${MKL_CFLAGS} -I${MKLROOT}/include" + if [ "${MKL_FFTW}" != "no" ]; then + MKL_CFLAGS+=" -I${MKLROOT}/include/fftw" + fi # write setup files - cat << EOF > "${BUILDDIR}/setup_mkl" + cat <"${BUILDDIR}/setup_mkl" export MKLROOT="${MKLROOT}" export MKL_CFLAGS="${MKL_CFLAGS}" export MKL_LIBS="${MKL_LIBS}" @@ -120,14 +118,14 @@ export MATH_CFLAGS="\${MATH_CFLAGS} ${MKL_CFLAGS}" export MATH_LIBS="\${MATH_LIBS} ${MKL_LIBS}" export CP_DFLAGS="\${CP_DFLAGS} -D__MKL -D__FFTW3 IF_COVERAGE(IF_MPI(|-U__FFTW3)|)" EOF - if [ -n "${mkl_scalapack_lib}" ]; then - cat << EOF >> "${BUILDDIR}/setup_mkl" + if [ -n "${mkl_scalapack_lib}" ]; then + cat <>"${BUILDDIR}/setup_mkl" export CP_DFLAGS="\${CP_DFLAGS} IF_MPI(-D__SCALAPACK|)" export with_scalapack="__DONTUSE__" EOF - fi - if [ "${MKL_FFTW}" != "no" ]; then - cat << EOF >> "${BUILDDIR}/setup_mkl" + fi + if [ "${MKL_FFTW}" != "no" ]; then + cat <>"${BUILDDIR}/setup_mkl" export with_fftw="__DONTUSE__" export FFTW3_INCLUDES="${MKL_CFLAGS}" export FFTW3_LIBS="${MKL_LIBS}" @@ -135,8 +133,8 @@ export FFTW_CFLAGS="${MKL_CFLAGS}" export FFTW_LDFLAGS="${MKL_LDFLAGS}" export FFTW_LIBS="${MKL_LIBS}" EOF - fi - filter_setup "${BUILDDIR}/setup_mkl" ${SETUPFILE} + fi + filter_setup "${BUILDDIR}/setup_mkl" ${SETUPFILE} fi load "${BUILDDIR}/setup_mkl" diff --git a/toolchain/scripts/stage2/install_openblas.sh b/toolchain/scripts/stage2/install_openblas.sh index 58cc4a9af5a..13b2a3bbe3f 100755 --- a/toolchain/scripts/stage2/install_openblas.sh +++ b/toolchain/scripts/stage2/install_openblas.sh @@ -15,16 +15,16 @@ source "${SCRIPT_DIR}"/package_versions.sh # Check for version configuration from environment or individual package setting version_suffix="" if [[ -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]]; then - # Check for individual package version override - if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "openblas:alt"; then - version_suffix="alt" - elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "openblas:main"; then - version_suffix="main" - fi + # Check for individual package version override + if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "openblas:alt"; then + version_suffix="alt" + elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "openblas:main"; then + version_suffix="main" + fi fi # Fall back to global version suffix if no individual setting if [[ -z "$version_suffix" && -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" ]]; then - version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" + version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" fi # Load package variables with appropriate version load_package_vars "openblas" "$version_suffix" @@ -43,122 +43,122 @@ OPENBLAS_ROOT="" cd "${BUILDDIR}" case "${with_openblas}" in - __INSTALL__) - echo "==================== Installing OpenBLAS ====================" - pkg_install_dir="${INSTALLDIR}/openblas-${openblas_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - if verify_checksums "${install_lock_file}"; then - echo "openblas-${openblas_ver} is already installed, skipping it." - else - url="https://codeload.github.com/OpenMathLib/OpenBLAS/tar.gz/v${openblas_ver}" - retrieve_package "${openblas_sha256}" "${openblas_pkg}" "${url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d OpenBLAS-${openblas_ver} ] && rm -rf OpenBLAS-${openblas_ver} - tar -zxf ${openblas_pkg} - cd OpenBLAS-${openblas_ver} - # Build OpenBLAS with DYNAMIC_ARCH unless native architecture is requested. - # If the latter fails, then build with DYNAMIC_ARCH. - # - # wrt NUM_THREADS=64: this is what the most common Linux distros seem to choose atm - # for a good compromise between memory usage and scalability - # - # Unfortunately, NO_SHARED=1 breaks ScaLAPACK build. - BUILD_DYNAMIC=0 - if [ "native" != "${TARGET_CPU}" ]; then - BUILD_DYNAMIC=1 - fi - if [ "${BUILD_DYNAMIC}" = "0" ]; then - echo "Installing OpenBLAS library for native target" - if ! make -j "$(get_nprocs)" \ - MAKE_NB_JOBS=0 \ - NUM_THREADS=64 \ - USE_THREAD=1 \ - USE_OPENMP=1 \ - NO_AFFINITY=1 \ - CC="${CC}" \ - FC="${FC}" \ - PREFIX="${pkg_install_dir}" \ - > make.log 2>&1; then - tail -n "${LOG_LINES}" make.log - make clean - BUILD_DYNAMIC=1 - fi - fi - if [ "${BUILD_DYNAMIC}" != "0" ]; then - echo "Installing OpenBLAS library for dynamic target" - if ! make -j "$(get_nprocs)" \ - MAKE_NB_JOBS=0 \ - DYNAMIC_ARCH=1 \ - NUM_THREADS=64 \ - USE_THREAD=1 \ - USE_OPENMP=1 \ - NO_AFFINITY=1 \ - CC="${CC}" \ - FC="${FC}" \ - PREFIX="${pkg_install_dir}" \ - > make.log 2>&1; then - tail -n "${LOG_LINES}" make.log - exit 1 - fi - fi - if ! make MAKE_NB_JOBS=0 PREFIX="${pkg_install_dir}" install \ - > install.log 2>&1; then - tail -n "${LOG_LINES}" install.log - exit 1 - fi - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage2/$(basename ${SCRIPT_NAME})" - fi - OPENBLAS_CFLAGS="-I'${pkg_install_dir}/include'" - OPENBLAS_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - OPENBLAS_ROOT="${pkg_install_dir}" - OPENBLAS_LIBS="-lopenblas" - ;; - __SYSTEM__) - echo "==================== Finding OpenBLAS/LAPACK from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - # assume that system openblas is threaded - check_lib -lopenblas "OpenBLAS" - OPENBLAS_LIBS="-lopenblas" - # detect separate omp builds - check_lib -lopenblas_openmp 2> /dev/null && OPENBLAS_LIBS="-lopenblas_openmp" - check_lib -lopenblas_omp 2> /dev/null && OPENBLAS_LIBS="-lopenblas_omp" - add_include_from_paths OPENBLAS_CFLAGS "openblas_config.h" $INCLUDE_PATHS - add_lib_from_paths OPENBLAS_LDFLAGS "libopenblas.*" $LIB_PATHS - ;; - __DONTUSE__) ;; +__INSTALL__) + echo "==================== Installing OpenBLAS ====================" + pkg_install_dir="${INSTALLDIR}/openblas-${openblas_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "openblas-${openblas_ver} is already installed, skipping it." + else + url="https://codeload.github.com/OpenMathLib/OpenBLAS/tar.gz/v${openblas_ver}" + retrieve_package "${openblas_sha256}" "${openblas_pkg}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d OpenBLAS-${openblas_ver} ] && rm -rf OpenBLAS-${openblas_ver} + tar -zxf ${openblas_pkg} + cd OpenBLAS-${openblas_ver} + # Build OpenBLAS with DYNAMIC_ARCH unless native architecture is requested. + # If the latter fails, then build with DYNAMIC_ARCH. + # + # wrt NUM_THREADS=64: this is what the most common Linux distros seem to choose atm + # for a good compromise between memory usage and scalability + # + # Unfortunately, NO_SHARED=1 breaks ScaLAPACK build. + BUILD_DYNAMIC=0 + if [ "native" != "${TARGET_CPU}" ]; then + BUILD_DYNAMIC=1 + fi + if [ "${BUILD_DYNAMIC}" = "0" ]; then + echo "Installing OpenBLAS library for native target" + if ! make -j "$(get_nprocs)" \ + MAKE_NB_JOBS=0 \ + NUM_THREADS=64 \ + USE_THREAD=1 \ + USE_OPENMP=1 \ + NO_AFFINITY=1 \ + CC="${CC}" \ + FC="${FC}" \ + PREFIX="${pkg_install_dir}" \ + >make.log 2>&1; then + tail -n "${LOG_LINES}" make.log + make clean + BUILD_DYNAMIC=1 + fi + fi + if [ "${BUILD_DYNAMIC}" != "0" ]; then + echo "Installing OpenBLAS library for dynamic target" + if ! make -j "$(get_nprocs)" \ + MAKE_NB_JOBS=0 \ + DYNAMIC_ARCH=1 \ + NUM_THREADS=64 \ + USE_THREAD=1 \ + USE_OPENMP=1 \ + NO_AFFINITY=1 \ + CC="${CC}" \ + FC="${FC}" \ + PREFIX="${pkg_install_dir}" \ + >make.log 2>&1; then + tail -n "${LOG_LINES}" make.log + exit 1 + fi + fi + if ! make MAKE_NB_JOBS=0 PREFIX="${pkg_install_dir}" install \ + >install.log 2>&1; then + tail -n "${LOG_LINES}" install.log + exit 1 + fi + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage2/$(basename ${SCRIPT_NAME})" + fi + OPENBLAS_CFLAGS="-I'${pkg_install_dir}/include'" + OPENBLAS_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + OPENBLAS_ROOT="${pkg_install_dir}" + OPENBLAS_LIBS="-lopenblas" + ;; +__SYSTEM__) + echo "==================== Finding OpenBLAS/LAPACK from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + # assume that system openblas is threaded + check_lib -lopenblas "OpenBLAS" + OPENBLAS_LIBS="-lopenblas" + # detect separate omp builds + check_lib -lopenblas_openmp 2>/dev/null && OPENBLAS_LIBS="-lopenblas_openmp" + check_lib -lopenblas_omp 2>/dev/null && OPENBLAS_LIBS="-lopenblas_omp" + add_include_from_paths OPENBLAS_CFLAGS "openblas_config.h" $INCLUDE_PATHS + add_lib_from_paths OPENBLAS_LDFLAGS "libopenblas.*" $LIB_PATHS + ;; +__DONTUSE__) ;; - *) - echo "==================== Linking OpenBLAS/LAPACK to user paths ====================" - pkg_install_dir="$with_openblas" - check_dir "${pkg_install_dir}/include" - check_dir "${pkg_install_dir}/lib" - OPENBLAS_CFLAGS="-I'${pkg_install_dir}/include'" - OPENBLAS_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - OPENBLAS_LIBS="-lopenblas" - # detect separate omp builds - (__libdir="${pkg_install_dir}/lib" LIB_PATHS="__libdir" check_lib -lopenblas_openmp 2> /dev/null) && - OPENBLAS_LIBS="-lopenblas_openmp" - (__libdir="${pkg_install_dir}/lib" LIB_PATHS="__libdir" check_lib -lopenblas_omp 2> /dev/null) && - OPENBLAS_LIBS="-lopenblas_omp" - ;; +*) + echo "==================== Linking OpenBLAS/LAPACK to user paths ====================" + pkg_install_dir="$with_openblas" + check_dir "${pkg_install_dir}/include" + check_dir "${pkg_install_dir}/lib" + OPENBLAS_CFLAGS="-I'${pkg_install_dir}/include'" + OPENBLAS_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + OPENBLAS_LIBS="-lopenblas" + # detect separate omp builds + (__libdir="${pkg_install_dir}/lib" LIB_PATHS="__libdir" check_lib -lopenblas_openmp 2>/dev/null) && + OPENBLAS_LIBS="-lopenblas_openmp" + (__libdir="${pkg_install_dir}/lib" LIB_PATHS="__libdir" check_lib -lopenblas_omp 2>/dev/null) && + OPENBLAS_LIBS="-lopenblas_omp" + ;; esac if [ "$with_openblas" != "__DONTUSE__" ]; then - if [ "$with_openblas" != "__SYSTEM__" ]; then - cat << EOF > "${BUILDDIR}/setup_openblas" + if [ "$with_openblas" != "__SYSTEM__" ]; then + cat <"${BUILDDIR}/setup_openblas" prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" prepend_path CPATH "${pkg_install_dir}/include" EOF - fi - cat << EOF >> "${BUILDDIR}/setup_openblas" + fi + cat <>"${BUILDDIR}/setup_openblas" export OPENBLAS_ROOT="${pkg_install_dir}" export OPENBLAS_CFLAGS="${OPENBLAS_CFLAGS}" export OPENBLAS_LDFLAGS="${OPENBLAS_LDFLAGS}" @@ -169,7 +169,7 @@ export MATH_LIBS="\${MATH_LIBS} ${OPENBLAS_LIBS}" prepend_path PKG_CONFIG_PATH "${pkg_install_dir}/lib/pkgconfig" prepend_path CMAKE_PREFIX_PATH "${pkg_install_dir}" EOF - filter_setup "${BUILDDIR}/setup_openblas" $SETUPFILE + filter_setup "${BUILDDIR}/setup_openblas" $SETUPFILE fi load "${BUILDDIR}/setup_openblas" diff --git a/toolchain/scripts/stage3/install_elpa.sh b/toolchain/scripts/stage3/install_elpa.sh index 58b4b8bc2a1..84e1be1a07c 100755 --- a/toolchain/scripts/stage3/install_elpa.sh +++ b/toolchain/scripts/stage3/install_elpa.sh @@ -18,16 +18,16 @@ source "${SCRIPT_DIR}"/package_versions.sh # Check for version configuration from environment or individual package setting version_suffix="" if [[ -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]]; then - # Check for individual package version override - if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "elpa:alt"; then - version_suffix="alt" - elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "elpa:main"; then - version_suffix="main" - fi + # Check for individual package version override + if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "elpa:alt"; then + version_suffix="alt" + elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "elpa:main"; then + version_suffix="main" + fi fi # Fall back to global version suffix if no individual setting if [[ -z "$version_suffix" && -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" ]]; then - version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" + version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" fi # Load package variables with appropriate version load_package_vars "elpa" "$version_suffix" @@ -48,212 +48,212 @@ cd "${BUILDDIR}" # elpa only works with MPI switched on if [ $MPI_MODE = no ]; then - report_warning $LINENO "MPI is disabled, skipping elpa installation" - exit 0 + report_warning $LINENO "MPI is disabled, skipping elpa installation" + exit 0 fi case "$with_elpa" in - __INSTALL__) - echo "==================== Installing ELPA ====================" - pkg_install_dir="${INSTALLDIR}/elpa-${elpa_ver}" - #pkg_install_dir="${HOME}/lib/elpa/${elpa_ver}-gcc8" - install_lock_file="${pkg_install_dir}/install_successful" - enable_openmp="yes" +__INSTALL__) + echo "==================== Installing ELPA ====================" + pkg_install_dir="${INSTALLDIR}/elpa-${elpa_ver}" + #pkg_install_dir="${HOME}/lib/elpa/${elpa_ver}-gcc8" + install_lock_file="${pkg_install_dir}/install_successful" + enable_openmp="yes" + + # specific settings needed on CRAY Linux Environment + if [ "$ENABLE_CRAY" = "__TRUE__" ]; then + if [ ${CRAY_PRGENVCRAY} ]; then + # extra LDFLAGS needed + cray_ldflags="-dynamic" + fi + # enable_openmp="no" + fi - # specific settings needed on CRAY Linux Environment - if [ "$ENABLE_CRAY" = "__TRUE__" ]; then - if [ ${CRAY_PRGENVCRAY} ]; then - # extra LDFLAGS needed - cray_ldflags="-dynamic" - fi - # enable_openmp="no" - fi + if verify_checksums "${install_lock_file}"; then + echo "elpa-${elpa_ver} is already installed, skipping it." + else + require_env MATH_LIBS + url="https://elpa.mpcdf.mpg.de/software/tarball-archive/Releases/${elpa_ver}/${elpa_pkg}" + retrieve_package "${elpa_sha256}" "${elpa_pkg}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + [ -d elpa-${elpa_ver} ] && rm -rf elpa-${elpa_ver} + tar -xzf ${elpa_pkg} - if verify_checksums "${install_lock_file}"; then - echo "elpa-${elpa_ver} is already installed, skipping it." - else - require_env MATH_LIBS - url="https://elpa.mpcdf.mpg.de/software/tarball-archive/Releases/${elpa_ver}/${elpa_pkg}" - retrieve_package "${elpa_sha256}" "${elpa_pkg}" "${url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - [ -d elpa-${elpa_ver} ] && rm -rf elpa-${elpa_ver} - tar -xzf ${elpa_pkg} + # elpa expect FC to be an mpi fortran compiler that is happy + # with long lines, and that a bunch of libs can be found + cd elpa-${elpa_ver} - # elpa expect FC to be an mpi fortran compiler that is happy - # with long lines, and that a bunch of libs can be found - cd elpa-${elpa_ver} + # ELPA-2017xxxx enables AVX2 by default, switch off if machine doesn't support it. + AVX_flag="" + AVX512_flags="" + FMA_flag="" + SSE4_flag="" + config_flags="--disable-avx-kernels --disable-avx2-kernels --disable-avx512-kernels --disable-sse-kernels --disable-sse-assembly-kernels" + if [ "${TARGET_CPU}" = "native" ]; then + if [ -f /proc/cpuinfo ] && [ "${SYSTEM_ARCH}" = "x86_64" ]; then + has_AVX=$(grep '\bavx\b' /proc/cpuinfo 1>/dev/null && echo 'yes' || echo 'no') + [ "${has_AVX}" = "yes" ] && AVX_flag="-mavx" || AVX_flag="" + has_AVX2=$(grep '\bavx2\b' /proc/cpuinfo 1>/dev/null && echo 'yes' || echo 'no') + [ "${has_AVX2}" = "yes" ] && AVX_flag="-mavx2" + has_AVX512=$(grep '\bavx512f\b' /proc/cpuinfo 1>/dev/null && echo 'yes' || echo 'no') + [ "${has_AVX512}" = "yes" ] && AVX512_flags="-mavx512f" + FMA_flag=$(grep '\bfma\b' /proc/cpuinfo 1>/dev/null && echo '-mfma' || echo '-mno-fma') + SSE4_flag=$(grep '\bsse4_1\b' /proc/cpuinfo 1>/dev/null && echo '-msse4' || echo '-mno-sse4') + grep '\bavx512dq\b' /proc/cpuinfo 1>/dev/null && AVX512_flags+=" -mavx512dq" + grep '\bavx512cd\b' /proc/cpuinfo 1>/dev/null && AVX512_flags+=" -mavx512cd" + grep '\bavx512bw\b' /proc/cpuinfo 1>/dev/null && AVX512_flags+=" -mavx512bw" + grep '\bavx512vl\b' /proc/cpuinfo 1>/dev/null && AVX512_flags+=" -mavx512vl" + config_flags="--enable-avx-kernels=${has_AVX} --enable-avx2-kernels=${has_AVX2} --enable-avx512-kernels=${has_AVX512}" + fi + fi - # ELPA-2017xxxx enables AVX2 by default, switch off if machine doesn't support it. - AVX_flag="" - AVX512_flags="" - FMA_flag="" - SSE4_flag="" - config_flags="--disable-avx-kernels --disable-avx2-kernels --disable-avx512-kernels --disable-sse-kernels --disable-sse-assembly-kernels" - if [ "${TARGET_CPU}" = "native" ]; then - if [ -f /proc/cpuinfo ] && [ "${SYSTEM_ARCH}" = "x86_64" ]; then - has_AVX=$(grep '\bavx\b' /proc/cpuinfo 1> /dev/null && echo 'yes' || echo 'no') - [ "${has_AVX}" = "yes" ] && AVX_flag="-mavx" || AVX_flag="" - has_AVX2=$(grep '\bavx2\b' /proc/cpuinfo 1> /dev/null && echo 'yes' || echo 'no') - [ "${has_AVX2}" = "yes" ] && AVX_flag="-mavx2" - has_AVX512=$(grep '\bavx512f\b' /proc/cpuinfo 1> /dev/null && echo 'yes' || echo 'no') - [ "${has_AVX512}" = "yes" ] && AVX512_flags="-mavx512f" - FMA_flag=$(grep '\bfma\b' /proc/cpuinfo 1> /dev/null && echo '-mfma' || echo '-mno-fma') - SSE4_flag=$(grep '\bsse4_1\b' /proc/cpuinfo 1> /dev/null && echo '-msse4' || echo '-mno-sse4') - grep '\bavx512dq\b' /proc/cpuinfo 1> /dev/null && AVX512_flags+=" -mavx512dq" - grep '\bavx512cd\b' /proc/cpuinfo 1> /dev/null && AVX512_flags+=" -mavx512cd" - grep '\bavx512bw\b' /proc/cpuinfo 1> /dev/null && AVX512_flags+=" -mavx512bw" - grep '\bavx512vl\b' /proc/cpuinfo 1> /dev/null && AVX512_flags+=" -mavx512vl" - config_flags="--enable-avx-kernels=${has_AVX} --enable-avx2-kernels=${has_AVX2} --enable-avx512-kernels=${has_AVX512}" - fi - fi + # GCC 15.2 miscompiles ELPA's double-complex AVX/AVX2 BLOCK2 + # kernels when tree SLP vectorization is enabled. + elpa_c_workaround_flags="" + cc_version="$("${MPICC}" -dumpfullversion -dumpversion 2>/dev/null || true)" + cc_banner="$("${MPICC}" --version 2>/dev/null | head -n 1 || true)" + if [[ "${cc_banner}" == *gcc* || "${cc_banner}" == *GCC* ]] && + [[ "${cc_version}" =~ ^15\.2(\.|$) ]]; then + elpa_c_workaround_flags="-fno-tree-slp-vectorize" + fi - # GCC 15.2 miscompiles ELPA's double-complex AVX/AVX2 BLOCK2 - # kernels when tree SLP vectorization is enabled. - elpa_c_workaround_flags="" - cc_version="$("${MPICC}" -dumpfullversion -dumpversion 2>/dev/null || true)" - cc_banner="$("${MPICC}" --version 2>/dev/null | head -n 1 || true)" - if [[ "${cc_banner}" == *gcc* || "${cc_banner}" == *GCC* ]] && - [[ "${cc_version}" =~ ^15\.2(\.|$) ]]; then - elpa_c_workaround_flags="-fno-tree-slp-vectorize" - fi + for TARGET in "cpu" "nvidia"; do + # Accept both uppercase and lowercase GPU enable flags for compatibility + gpu_enabled="${ENABLE_CUDA}" + [ "$TARGET" = "nvidia" ] && [ "$gpu_enabled" != "__TRUE__" ] && continue + # disable cpu if cuda is enabled, only install one + [ "$TARGET" != "nvidia" ] && [ "$gpu_enabled" = "__TRUE__" ] && continue - for TARGET in "cpu" "nvidia"; do - # Accept both uppercase and lowercase GPU enable flags for compatibility - gpu_enabled="${ENABLE_CUDA}" - [ "$TARGET" = "nvidia" ] && [ "$gpu_enabled" != "__TRUE__" ] && continue - # disable cpu if cuda is enabled, only install one - [ "$TARGET" != "nvidia" ] && [ "$gpu_enabled" = "__TRUE__" ] && continue + echo "Installing from scratch into ${pkg_install_dir}/${TARGET}" + mkdir -p "build_${TARGET}" + cd "build_${TARGET}" + if [ "${with_amd}" != "__DONTUSE__" ] && [ "${WITH_FLANG}" = "yes" ]; then + # special option for flang compiler + echo "AMD fortran compiler detected, enable special option operation" + ../configure --prefix="${pkg_install_dir}/${TARGET}" \ + --libdir="${pkg_install_dir}/${TARGET}/lib" \ + --enable-openmp=${enable_openmp} \ + --enable-static=no \ + --enable-shared=yes \ + --disable-c-tests \ + --disable-cpp-tests \ + ${config_flags} \ + --with-cuda-path=${CUDA_PATH:-${CUDA_HOME:-/CUDA_HOME-notset}} \ + --enable-nvidia-gpu-kernels=$([ "$TARGET" = "nvidia" ] && echo "yes" || echo "no") \ + --with-NVIDIA-GPU-compute-capability=$([ "$TARGET" = "nvidia" ] && echo "sm_$ARCH_NUM" || echo "sm_70") \ + --enable-nvidia-cub --with-cusolver \ + OMPI_MCA_plm_rsh_agent=/bin/false \ + FC=${MPIFC} \ + CC=${MPICC} \ + CXX=${MPICXX} \ + CPP="cpp -E" \ + FCFLAGS="${FCFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ + CFLAGS="${CFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto ${elpa_c_workaround_flags}" \ + CXXFLAGS="${CXXFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ + LDFLAGS="${MATH_LDFLAGS} ${SCALAPACK_LDFLAGS} ${cray_ldflags} -lstdc++" \ + LIBS="${SCALAPACK_LIBS} $(resolve_string "${MATH_LIBS}" "MPI") ${MPI_LIBS}" \ + SCALAPACK_LDFLAGS="${SCALAPACK_LDFLAGS}" \ + SCALAPACK_FCFLAGS="${SCALAPACK_CFLAGS}" \ + >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + # remove unsupported compile option in libtool + sed -i ./libtool \ + -e 's/\\$wl-soname //g' \ + -e 's/\\$wl--whole-archive\\$convenience \\$wl--no-whole-archive//g' \ + -e 's/\\$wl\\$soname //g' + else + # normal installation + ../configure --prefix="${pkg_install_dir}/${TARGET}" \ + --libdir="${pkg_install_dir}/${TARGET}/lib" \ + --enable-openmp=${enable_openmp} \ + --enable-static=no \ + --enable-shared=yes \ + --disable-c-tests \ + --disable-cpp-tests \ + ${config_flags} \ + --enable-nvidia-gpu-kernels=$([ "$TARGET" = "nvidia" ] && echo "yes" || echo "no") \ + --with-cuda-path=${CUDA_PATH:-${CUDA_HOME:-/CUDA_HOME-notset}} \ + --with-NVIDIA-GPU-compute-capability=$([ "$TARGET" = "nvidia" ] && echo "sm_$ARCH_NUM" || echo "sm_70") \ + --enable-nvidia-cub --with-cusolver \ + FC=${MPIFC} \ + CC=${MPICC} \ + CXX=${MPICXX} \ + CPP="cpp -E" \ + FCFLAGS="${FCFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ + CFLAGS="${CFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto ${elpa_c_workaround_flags}" \ + CXXFLAGS="${CXXFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ + LDFLAGS="-Wl,--allow-multiple-definition -Wl,--enable-new-dtags ${MATH_LDFLAGS} ${SCALAPACK_LDFLAGS} ${cray_ldflags} -lstdc++" \ + LIBS="${SCALAPACK_LIBS} $(resolve_string "${MATH_LIBS}" "MPI")" \ + SCALAPACK_LDFLAGS="${SCALAPACK_LDFLAGS}" \ + SCALAPACK_FCFLAGS="${SCALAPACK_CFLAGS}" \ + >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + fi + make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + # link elpa + link=${pkg_install_dir}/${TARGET}/include/elpa + if [[ ! -d $link ]]; then + ln -s ${pkg_install_dir}/${TARGET}/include/elpa_openmp-${elpa_ver}/elpa $link + fi + done + cd .. - echo "Installing from scratch into ${pkg_install_dir}/${TARGET}" - mkdir -p "build_${TARGET}" - cd "build_${TARGET}" - if [ "${with_amd}" != "__DONTUSE__" ] && [ "${WITH_FLANG}" = "yes" ] ; then - # special option for flang compiler - echo "AMD fortran compiler detected, enable special option operation" - ../configure --prefix="${pkg_install_dir}/${TARGET}" \ - --libdir="${pkg_install_dir}/${TARGET}/lib" \ - --enable-openmp=${enable_openmp} \ - --enable-static=no \ - --enable-shared=yes \ - --disable-c-tests \ - --disable-cpp-tests \ - ${config_flags} \ - --with-cuda-path=${CUDA_PATH:-${CUDA_HOME:-/CUDA_HOME-notset}} \ - --enable-nvidia-gpu-kernels=$([ "$TARGET" = "nvidia" ] && echo "yes" || echo "no") \ - --with-NVIDIA-GPU-compute-capability=$([ "$TARGET" = "nvidia" ] && echo "sm_$ARCH_NUM" || echo "sm_70") \ - --enable-nvidia-cub --with-cusolver \ - OMPI_MCA_plm_rsh_agent=/bin/false \ - FC=${MPIFC} \ - CC=${MPICC} \ - CXX=${MPICXX} \ - CPP="cpp -E" \ - FCFLAGS="${FCFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ - CFLAGS="${CFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto ${elpa_c_workaround_flags}" \ - CXXFLAGS="${CXXFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ - LDFLAGS="${MATH_LDFLAGS} ${SCALAPACK_LDFLAGS} ${cray_ldflags} -lstdc++" \ - LIBS="${SCALAPACK_LIBS} $(resolve_string "${MATH_LIBS}" "MPI") ${MPI_LIBS}" \ - SCALAPACK_LDFLAGS="${SCALAPACK_LDFLAGS}" \ - SCALAPACK_FCFLAGS="${SCALAPACK_CFLAGS}" \ - > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log - # remove unsupported compile option in libtool - sed -i ./libtool \ - -e 's/\\$wl-soname //g' \ - -e 's/\\$wl--whole-archive\\$convenience \\$wl--no-whole-archive//g' \ - -e 's/\\$wl\\$soname //g' - else - # normal installation - ../configure --prefix="${pkg_install_dir}/${TARGET}" \ - --libdir="${pkg_install_dir}/${TARGET}/lib" \ - --enable-openmp=${enable_openmp} \ - --enable-static=no \ - --enable-shared=yes \ - --disable-c-tests \ - --disable-cpp-tests \ - ${config_flags} \ - --enable-nvidia-gpu-kernels=$([ "$TARGET" = "nvidia" ] && echo "yes" || echo "no") \ - --with-cuda-path=${CUDA_PATH:-${CUDA_HOME:-/CUDA_HOME-notset}} \ - --with-NVIDIA-GPU-compute-capability=$([ "$TARGET" = "nvidia" ] && echo "sm_$ARCH_NUM" || echo "sm_70") \ - --enable-nvidia-cub --with-cusolver \ - FC=${MPIFC} \ - CC=${MPICC} \ - CXX=${MPICXX} \ - CPP="cpp -E" \ - FCFLAGS="${FCFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ - CFLAGS="${CFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto ${elpa_c_workaround_flags}" \ - CXXFLAGS="${CXXFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ - LDFLAGS="-Wl,--allow-multiple-definition -Wl,--enable-new-dtags ${MATH_LDFLAGS} ${SCALAPACK_LDFLAGS} ${cray_ldflags} -lstdc++" \ - LIBS="${SCALAPACK_LIBS} $(resolve_string "${MATH_LIBS}" "MPI")" \ - SCALAPACK_LDFLAGS="${SCALAPACK_LDFLAGS}" \ - SCALAPACK_FCFLAGS="${SCALAPACK_CFLAGS}" \ - > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log - fi - make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log - make install > install.log 2>&1 || tail -n ${LOG_LINES} install.log - cd .. - # link elpa - link=${pkg_install_dir}/${TARGET}/include/elpa - if [[ ! -d $link ]]; then - ln -s ${pkg_install_dir}/${TARGET}/include/elpa_openmp-${elpa_ver}/elpa $link - fi - done - cd .. - - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" - fi - [ "$enable_openmp" != "yes" ] && elpa_dir_openmp="" - elpa_include="${pkg_install_dir}/IF_CUDA(nvidia|cpu)/include/elpa${elpa_dir_openmp}-${elpa_ver}" - ELPA_CFLAGS="-I'$elpa_include/modules' -I'$elpa_include/elpa'" - ELPA_LDFLAGS="-L'${pkg_install_dir}/IF_CUDA(nvidia|cpu)/lib' -Wl,-rpath,'${pkg_install_dir}/IF_CUDA(nvidia|cpu)/lib'" - ;; - __SYSTEM__) - echo "==================== Finding ELPA from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_lib -lelpa_openmp "ELPA" - # get the include paths - elpa_include="$(find_in_paths "elpa_openmp-*" $INCLUDE_PATHS)" - if [ "$elpa_include" != "__FALSE__" ]; then - echo "ELPA include directory threaded version is found to be $elpa_include" - ELPA_CFLAGS="-I'$elpa_include/modules' -I'$elpa_include/elpa'" - else - echo "Cannot find elpa_openmp-${elpa_ver} from paths $INCLUDE_PATHS" - exit 1 - fi - # get the lib paths - add_lib_from_paths ELPA_LDFLAGS "libelpa.*" $LIB_PATHS - ;; - __DONTUSE__) ;; + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" + fi + [ "$enable_openmp" != "yes" ] && elpa_dir_openmp="" + elpa_include="${pkg_install_dir}/IF_CUDA(nvidia|cpu)/include/elpa${elpa_dir_openmp}-${elpa_ver}" + ELPA_CFLAGS="-I'$elpa_include/modules' -I'$elpa_include/elpa'" + ELPA_LDFLAGS="-L'${pkg_install_dir}/IF_CUDA(nvidia|cpu)/lib' -Wl,-rpath,'${pkg_install_dir}/IF_CUDA(nvidia|cpu)/lib'" + ;; +__SYSTEM__) + echo "==================== Finding ELPA from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_lib -lelpa_openmp "ELPA" + # get the include paths + elpa_include="$(find_in_paths "elpa_openmp-*" $INCLUDE_PATHS)" + if [ "$elpa_include" != "__FALSE__" ]; then + echo "ELPA include directory threaded version is found to be $elpa_include" + ELPA_CFLAGS="-I'$elpa_include/modules' -I'$elpa_include/elpa'" + else + echo "Cannot find elpa_openmp-${elpa_ver} from paths $INCLUDE_PATHS" + exit 1 + fi + # get the lib paths + add_lib_from_paths ELPA_LDFLAGS "libelpa.*" $LIB_PATHS + ;; +__DONTUSE__) ;; - *) - echo "==================== Linking ELPA to user paths ====================" - pkg_install_dir="$with_elpa" - check_dir "${pkg_install_dir}/include" - check_dir "${pkg_install_dir}/lib" - user_include_path="${pkg_install_dir}/include" - elpa_include="$(find_in_paths "elpa_openmp-*" user_include_path)" - if [ "$elpa_include" != "__FALSE__" ]; then - echo "ELPA include directory threaded version is found to be $elpa_include/modules" - check_dir "$elpa_include/modules" - ELPA_CFLAGS="-I'$elpa_include/modules' -I'$elpa_include/elpa'" - else - echo "Cannot find elpa_openmp-* from path $user_include_path" - exit 1 - fi - ELPA_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; +*) + echo "==================== Linking ELPA to user paths ====================" + pkg_install_dir="$with_elpa" + check_dir "${pkg_install_dir}/include" + check_dir "${pkg_install_dir}/lib" + user_include_path="${pkg_install_dir}/include" + elpa_include="$(find_in_paths "elpa_openmp-*" user_include_path)" + if [ "$elpa_include" != "__FALSE__" ]; then + echo "ELPA include directory threaded version is found to be $elpa_include/modules" + check_dir "$elpa_include/modules" + ELPA_CFLAGS="-I'$elpa_include/modules' -I'$elpa_include/elpa'" + else + echo "Cannot find elpa_openmp-* from path $user_include_path" + exit 1 + fi + ELPA_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "$with_elpa" != "__DONTUSE__" ]; then - ELPA_LIBS="-lelpa${elpa_dir_openmp}" - cat << EOF > "${BUILDDIR}/setup_elpa" + ELPA_LIBS="-lelpa${elpa_dir_openmp}" + cat <"${BUILDDIR}/setup_elpa" prepend_path CPATH "$elpa_include" EOF - if [ "$with_elpa" != "__SYSTEM__" ]; then - cat << EOF >> "${BUILDDIR}/setup_elpa" + if [ "$with_elpa" != "__SYSTEM__" ]; then + cat <>"${BUILDDIR}/setup_elpa" prepend_path PATH "${pkg_install_dir}/cpu/bin" prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/cpu/lib" prepend_path LD_RUN_PATH "${pkg_install_dir}/cpu/lib" @@ -261,8 +261,8 @@ prepend_path LIBRARY_PATH "${pkg_install_dir}/cpu/lib" prepend_path PKG_CONFIG_PATH "${pkg_install_dir}/cpu/lib/pkgconfig" prepend_path CMAKE_PREFIX_PATH "${pkg_install_dir}/cpu" EOF - if [ -d ${pkg_install_dir}/nvidia ]; then - cat << EOF >> "${BUILDDIR}/setup_elpa" + if [ -d ${pkg_install_dir}/nvidia ]; then + cat <>"${BUILDDIR}/setup_elpa" prepend_path PATH "${pkg_install_dir}/nvidia/bin" prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/nvidia/lib" prepend_path LD_RUN_PATH "${pkg_install_dir}/nvidia/lib" @@ -270,9 +270,9 @@ prepend_path LIBRARY_PATH "${pkg_install_dir}/nvidia/lib" prepend_path PKG_CONFIG_PATH "${pkg_install_dir}/nvidia/lib/pkgconfig" prepend_path CMAKE_PREFIX_PATH "${pkg_install_dir}/nvidia" EOF - fi fi - cat << EOF >> "${BUILDDIR}/setup_elpa" + fi + cat <>"${BUILDDIR}/setup_elpa" export ELPA_ROOT="${pkg_install_dir}" export ELPA_CFLAGS="${ELPA_CFLAGS}" export ELPA_LDFLAGS="${ELPA_LDFLAGS}" @@ -283,7 +283,7 @@ export CP_LDFLAGS="\${CP_LDFLAGS} IF_MPI(${ELPA_LDFLAGS}|)" export CP_LIBS="IF_MPI(${ELPA_LIBS}|) \${CP_LIBS}" export ELPA_VERSION="${elpa_ver}" EOF - filter_setup "${BUILDDIR}/setup_elpa" $SETUPFILE + filter_setup "${BUILDDIR}/setup_elpa" $SETUPFILE fi load "${BUILDDIR}/setup_elpa" diff --git a/toolchain/scripts/stage3/install_fftw.sh b/toolchain/scripts/stage3/install_fftw.sh index 4ad04705574..35e75cc59e7 100755 --- a/toolchain/scripts/stage3/install_fftw.sh +++ b/toolchain/scripts/stage3/install_fftw.sh @@ -15,16 +15,16 @@ source "${SCRIPT_DIR}"/package_versions.sh # Check for version configuration from environment or individual package setting version_suffix="" if [[ -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]]; then - # Check for individual package version override - if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "fftw:alt"; then - version_suffix="alt" - elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "fftw:main"; then - version_suffix="main" - fi + # Check for individual package version override + if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "fftw:alt"; then + version_suffix="alt" + elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "fftw:main"; then + version_suffix="main" + fi fi # Fall back to global version suffix if no individual setting if [[ -z "$version_suffix" && -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" ]]; then - version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" + version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" fi # Load package variables with appropriate version load_package_vars "fftw" "$version_suffix" @@ -41,98 +41,98 @@ FFTW_LIBS="" cd "${BUILDDIR}" case "$with_fftw" in - __INSTALL__) - require_env MPI_LIBS - echo "==================== Installing FFTW ====================" - pkg_install_dir="${INSTALLDIR}/fftw-${fftw_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - if verify_checksums "${install_lock_file}"; then - echo "fftw-${fftw_ver} is already installed, skipping it." - else - url="http://www.fftw.org/${fftw_pkg}" - retrieve_package "${fftw_sha256}" "${fftw_pkg}" "${url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d fftw-${fftw_ver} ] && rm -rf fftw-${fftw_ver} - tar -xzf ${fftw_pkg} - cd fftw-${fftw_ver} - FFTW_FLAGS="--enable-openmp --enable-shared" - # fftw has mpi support but not compiled by default. so compile it if we build with mpi. - # it will create a second library to link with if needed - [ "${MPI_MODE}" != "no" ] && FFTW_FLAGS="--enable-mpi ${FFTW_FLAGS}" - if [ "${TARGET_CPU}" = "native" ]; then - if [ -f /proc/cpuinfo ]; then - grep '\bavx\b' /proc/cpuinfo 1> /dev/null && FFTW_FLAGS="${FFTW_FLAGS} --enable-avx" - grep '\bavx2\b' /proc/cpuinfo 1> /dev/null && FFTW_FLAGS="${FFTW_FLAGS} --enable-avx2" - grep '\bavx512f\b' /proc/cpuinfo 1> /dev/null && FFTW_FLAGS="${FFTW_FLAGS} --enable-avx512" - fi - fi - # ABACUS need float version and double version fftw at the same time - # install float version fftw - echo "install float version fftw" - ./configure --prefix="${pkg_install_dir}" \ - --libdir="${pkg_install_dir}/lib" \ - --enable-float \ - ${FFTW_FLAGS} \ - > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log - make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log - make install > install.log 2>&1 || tail -n ${LOG_LINES} install.log - # install double version fftw - echo "clean" - make distclean > /dev/null 2>&1 || true - echo "install double version fftw" - ./configure --prefix="${pkg_install_dir}" \ - --libdir="${pkg_install_dir}/lib" \ - ${FFTW_FLAGS} \ - > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log - make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log - make install > install.log 2>&1 || tail -n ${LOG_LINES} install.log - cd .. - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" - fi - FFTW_CFLAGS="-I'${pkg_install_dir}/include'" - FFTW_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; - __SYSTEM__) - echo "==================== Finding FFTW from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_lib -lfftw3 "FFTW" - check_lib -lfftw3_omp "FFTW" - [ "${MPI_MODE}" != "no" ] && check_lib -lfftw3_mpi "FFTW" - add_include_from_paths FFTW_CFLAGS "fftw3.h" FFTW_INC ${INCLUDE_PATHS} - add_lib_from_paths FFTW_LDFLAGS "libfftw3.*" ${LIB_PATHS} - ;; - __DONTUSE__) - ;; - *) - echo "==================== Linking FFTW to user paths ====================" - pkg_install_dir="$with_fftw" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - FFTW_CFLAGS="-I'${pkg_install_dir}/include'" - FFTW_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; +__INSTALL__) + require_env MPI_LIBS + echo "==================== Installing FFTW ====================" + pkg_install_dir="${INSTALLDIR}/fftw-${fftw_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "fftw-${fftw_ver} is already installed, skipping it." + else + url="http://www.fftw.org/${fftw_pkg}" + retrieve_package "${fftw_sha256}" "${fftw_pkg}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d fftw-${fftw_ver} ] && rm -rf fftw-${fftw_ver} + tar -xzf ${fftw_pkg} + cd fftw-${fftw_ver} + FFTW_FLAGS="--enable-openmp --enable-shared" + # fftw has mpi support but not compiled by default. so compile it if we build with mpi. + # it will create a second library to link with if needed + [ "${MPI_MODE}" != "no" ] && FFTW_FLAGS="--enable-mpi ${FFTW_FLAGS}" + if [ "${TARGET_CPU}" = "native" ]; then + if [ -f /proc/cpuinfo ]; then + grep '\bavx\b' /proc/cpuinfo 1>/dev/null && FFTW_FLAGS="${FFTW_FLAGS} --enable-avx" + grep '\bavx2\b' /proc/cpuinfo 1>/dev/null && FFTW_FLAGS="${FFTW_FLAGS} --enable-avx2" + grep '\bavx512f\b' /proc/cpuinfo 1>/dev/null && FFTW_FLAGS="${FFTW_FLAGS} --enable-avx512" + fi + fi + # ABACUS need float version and double version fftw at the same time + # install float version fftw + echo "install float version fftw" + ./configure --prefix="${pkg_install_dir}" \ + --libdir="${pkg_install_dir}/lib" \ + --enable-float \ + ${FFTW_FLAGS} \ + >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + # install double version fftw + echo "clean" + make distclean >/dev/null 2>&1 || true + echo "install double version fftw" + ./configure --prefix="${pkg_install_dir}" \ + --libdir="${pkg_install_dir}/lib" \ + ${FFTW_FLAGS} \ + >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" + fi + FFTW_CFLAGS="-I'${pkg_install_dir}/include'" + FFTW_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +__SYSTEM__) + echo "==================== Finding FFTW from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_lib -lfftw3 "FFTW" + check_lib -lfftw3_omp "FFTW" + [ "${MPI_MODE}" != "no" ] && check_lib -lfftw3_mpi "FFTW" + add_include_from_paths FFTW_CFLAGS "fftw3.h" FFTW_INC ${INCLUDE_PATHS} + add_lib_from_paths FFTW_LDFLAGS "libfftw3.*" ${LIB_PATHS} + ;; +__DONTUSE__) + ;; +*) + echo "==================== Linking FFTW to user paths ====================" + pkg_install_dir="$with_fftw" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + FFTW_CFLAGS="-I'${pkg_install_dir}/include'" + FFTW_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "$with_fftw" != "__DONTUSE__" ]; then - [ "$MPI_MODE" != "no" ] && FFTW_LIBS="IF_MPI(-lfftw3_mpi|)" - FFTW_LIBS+="-lfftw3 -lfftw3_omp" - if [ "$with_fftw" != "__SYSTEM__" ]; then - cat << EOF > "${BUILDDIR}/setup_fftw" + [ "$MPI_MODE" != "no" ] && FFTW_LIBS="IF_MPI(-lfftw3_mpi|)" + FFTW_LIBS+="-lfftw3 -lfftw3_omp" + if [ "$with_fftw" != "__SYSTEM__" ]; then + cat <"${BUILDDIR}/setup_fftw" prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" prepend_path PKG_CONFIG_PATH "${pkg_install_dir}/lib/pkgconfig" prepend_path CMAKE_PREFIX_PATH "${pkg_install_dir}" EOF - fi - # we may also want to cover FFT_SG - cat << EOF >> "${BUILDDIR}/setup_fftw" + fi + # we may also want to cover FFT_SG + cat <>"${BUILDDIR}/setup_fftw" export FFTW3_INCLUDES="${FFTW_CFLAGS}" export FFTW3_LIBS="${FFTW_LIBS}" export FFTW_CFLAGS="${FFTW_CFLAGS}" @@ -142,14 +142,14 @@ export CP_LIBS="${FFTW_LIBS} \${CP_LIBS}" export FFTW_ROOT=${FFTW_ROOT:-${pkg_install_dir}} export FFTW3_ROOT=${pkg_install_dir} EOF - filter_setup "${BUILDDIR}/setup_fftw" $SETUPFILE + filter_setup "${BUILDDIR}/setup_fftw" $SETUPFILE fi cd "${ROOTDIR}" # ---------------------------------------------------------------------- # Suppress reporting of known leaks # ---------------------------------------------------------------------- -cat << EOF >> ${INSTALLDIR}/valgrind.supp +cat <>${INSTALLDIR}/valgrind.supp { Memcheck:Addr32 diff --git a/toolchain/scripts/stage3/install_libxc.sh b/toolchain/scripts/stage3/install_libxc.sh index e8ab08ffeb5..92643e16ba6 100755 --- a/toolchain/scripts/stage3/install_libxc.sh +++ b/toolchain/scripts/stage3/install_libxc.sh @@ -17,16 +17,16 @@ source "${SCRIPT_DIR}"/package_versions.sh # Check for version configuration from environment or individual package setting version_suffix="" if [[ -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]]; then - # Check for individual package version override - if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "libxc:alt"; then - version_suffix="alt" - elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "libxc:main"; then - version_suffix="main" - fi + # Check for individual package version override + if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "libxc:alt"; then + version_suffix="alt" + elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "libxc:main"; then + version_suffix="main" + fi fi # Fall back to global version suffix if no individual setting if [[ -z "$version_suffix" && -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" ]]; then - version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" + version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" fi # Load package variables with appropriate version load_package_vars "libxc" "$version_suffix" @@ -43,70 +43,70 @@ LIBXC_LIBS="" cd "${BUILDDIR}" case "$with_libxc" in - __INSTALL__) - echo "==================== Installing LIBXC ====================" - pkg_install_dir="${INSTALLDIR}/libxc-${libxc_ver}" - #pkg_install_dir="${HOME}/lib/libxc/${libxc_ver}-gcc8" - install_lock_file="${pkg_install_dir}/install_successful" - if verify_checksums "${install_lock_file}"; then - echo "libxc-${libxc_ver} is already installed, skipping it." - else - libxc_url="https://gitlab.com/libxc/libxc/-/archive/${libxc_ver}/${libxc_pkg}" - retrieve_package "${libxc_sha256}" "${libxc_pkg}" "${libxc_url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d libxc-${libxc_ver} ] && rm -rf libxc-${libxc_ver} - tar -xjf ${libxc_pkg} - cd libxc-${libxc_ver} - mkdir build - cd build - cmake \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=${pkg_install_dir} \ - -DBUILD_SHARED_LIBS=ON \ - -DCMAKE_INSTALL_LIBDIR=lib \ - -DCMAKE_VERBOSE_MAKEFILE=ON \ - -DENABLE_FORTRAN=ON \ - -DENABLE_PYTHON=OFF \ - -DBUILD_TESTING=OFF .. \ - > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log - make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log - make install > install.log 2>&1 || tail -n ${LOG_LINES} install.log - cd ../.. - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" - fi - LIBXC_CFLAGS="-I'${pkg_install_dir}/include'" - LIBXC_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; - __SYSTEM__) - echo "==================== Finding LIBXC from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_lib -lxcf03 "libxc" - check_lib -lxc "libxc" - add_include_from_paths LIBXC_CFLAGS "xc.h" $INCLUDE_PATHS - add_lib_from_paths LIBXC_LDFLAGS "libxc.*" $LIB_PATHS - ;; - __DONTUSE__) ;; +__INSTALL__) + echo "==================== Installing LIBXC ====================" + pkg_install_dir="${INSTALLDIR}/libxc-${libxc_ver}" + #pkg_install_dir="${HOME}/lib/libxc/${libxc_ver}-gcc8" + install_lock_file="${pkg_install_dir}/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "libxc-${libxc_ver} is already installed, skipping it." + else + libxc_url="https://gitlab.com/libxc/libxc/-/archive/${libxc_ver}/${libxc_pkg}" + retrieve_package "${libxc_sha256}" "${libxc_pkg}" "${libxc_url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d libxc-${libxc_ver} ] && rm -rf libxc-${libxc_ver} + tar -xjf ${libxc_pkg} + cd libxc-${libxc_ver} + mkdir build + cd build + cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=${pkg_install_dir} \ + -DBUILD_SHARED_LIBS=ON \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DENABLE_FORTRAN=ON \ + -DENABLE_PYTHON=OFF \ + -DBUILD_TESTING=OFF .. \ + >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd ../.. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" + fi + LIBXC_CFLAGS="-I'${pkg_install_dir}/include'" + LIBXC_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +__SYSTEM__) + echo "==================== Finding LIBXC from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_lib -lxcf03 "libxc" + check_lib -lxc "libxc" + add_include_from_paths LIBXC_CFLAGS "xc.h" $INCLUDE_PATHS + add_lib_from_paths LIBXC_LDFLAGS "libxc.*" $LIB_PATHS + ;; +__DONTUSE__) ;; - *) - echo "==================== Linking LIBXC to user paths ====================" - pkg_install_dir="$with_libxc" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - LIBXC_CFLAGS="-I'${pkg_install_dir}/include'" - LIBXC_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; +*) + echo "==================== Linking LIBXC to user paths ====================" + pkg_install_dir="$with_libxc" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + LIBXC_CFLAGS="-I'${pkg_install_dir}/include'" + LIBXC_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "$with_libxc" != "__DONTUSE__" ]; then - LIBXC_LIBS="-lxcf03 -lxc" - if [ "$with_libxc" != "__SYSTEM__" ]; then - cat << EOF > "${BUILDDIR}/setup_libxc" + LIBXC_LIBS="-lxcf03 -lxc" + if [ "$with_libxc" != "__SYSTEM__" ]; then + cat <"${BUILDDIR}/setup_libxc" prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" @@ -114,8 +114,8 @@ prepend_path CPATH "${pkg_install_dir}/include" prepend_path PKG_CONFIG_PATH "${pkg_install_dir}/lib/pkgconfig" prepend_path CMAKE_PREFIX_PATH "${pkg_install_dir}" EOF - fi - cat << EOF >> "${BUILDDIR}/setup_libxc" + fi + cat <>"${BUILDDIR}/setup_libxc" export LIBXC_CFLAGS="${LIBXC_CFLAGS}" export LIBXC_LDFLAGS="${LIBXC_LDFLAGS}" export LIBXC_LIBS="${LIBXC_LIBS}" @@ -125,7 +125,7 @@ export CP_LDFLAGS="\${CP_LDFLAGS} ${LIBXC_LDFLAGS}" export CP_LIBS="${LIBXC_LIBS} \${CP_LIBS}" export LIBXC_ROOT="${pkg_install_dir}" EOF - filter_setup "${BUILDDIR}/setup_libxc" $SETUPFILE + filter_setup "${BUILDDIR}/setup_libxc" $SETUPFILE fi load "${BUILDDIR}/setup_libxc" diff --git a/toolchain/scripts/stage3/install_scalapack.sh b/toolchain/scripts/stage3/install_scalapack.sh index f5641eb047f..1bb911d0bcc 100755 --- a/toolchain/scripts/stage3/install_scalapack.sh +++ b/toolchain/scripts/stage3/install_scalapack.sh @@ -15,16 +15,16 @@ source "${SCRIPT_DIR}"/package_versions.sh # Check for version configuration from environment or individual package setting version_suffix="" if [[ -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]]; then - # Check for individual package version override - if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "scalapack:alt"; then - version_suffix="alt" - elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "scalapack:main"; then - version_suffix="main" - fi + # Check for individual package version override + if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "scalapack:alt"; then + version_suffix="alt" + elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "scalapack:main"; then + version_suffix="main" + fi fi # Fall back to global version suffix if no individual setting if [[ -z "$version_suffix" && -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" ]]; then - version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" + version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" fi # Load package variables with appropriate version load_package_vars "scalapack" "$version_suffix" @@ -41,82 +41,82 @@ SCALAPACK_LIBS="" cd "${BUILDDIR}" case "${with_scalapack}" in - __INSTALL__) - echo "==================== Installing ScaLAPACK ====================" - pkg_install_dir="${INSTALLDIR}/scalapack-${scalapack_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - if verify_checksums "${install_lock_file}"; then - echo "scalapack-${scalapack_ver} is already installed, skipping it." - else - require_env MATH_LIBS - url="https://codeload.github.com/Reference-ScaLAPACK/scalapack/tar.gz/v${scalapack_ver}" - retrieve_package "${scalapack_sha256}" "${scalapack_pkg}" "${url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d scalapack-${scalapack_ver} ] && rm -rf scalapack-${scalapack_ver} - tar -xzf ${scalapack_pkg} +__INSTALL__) + echo "==================== Installing ScaLAPACK ====================" + pkg_install_dir="${INSTALLDIR}/scalapack-${scalapack_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "scalapack-${scalapack_ver} is already installed, skipping it." + else + require_env MATH_LIBS + url="https://codeload.github.com/Reference-ScaLAPACK/scalapack/tar.gz/v${scalapack_ver}" + retrieve_package "${scalapack_sha256}" "${scalapack_pkg}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d scalapack-${scalapack_ver} ] && rm -rf scalapack-${scalapack_ver} + tar -xzf ${scalapack_pkg} - mkdir -p "scalapack-${scalapack_ver}/build" - pushd "scalapack-${scalapack_ver}/build" > /dev/null + mkdir -p "scalapack-${scalapack_ver}/build" + pushd "scalapack-${scalapack_ver}/build" >/dev/null - cflags="" - fflags="" - if ("${FC}" --version | grep -q 'GNU'); then - cflags="-fpermissive" - fflags=$(allowed_gfortran_flags "-fallow-argument-mismatch") - fi - CFLAGS=${cflags} FFLAGS=${fflags} \ - cmake -DCMAKE_FIND_ROOT_PATH="$ROOTDIR" \ - -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ - -DCMAKE_INSTALL_LIBDIR="lib" \ - -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ - -DCMAKE_VERBOSE_MAKEFILE=ON \ - -DBUILD_SHARED_LIBS=YES \ - -DCMAKE_BUILD_TYPE=Release .. \ - -DBUILD_TESTING=NO \ - -DSCALAPACK_BUILD_TESTS=NO \ - > configure.log 2>&1 || tail -n ${LOG_LINES} configure.log - make -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log - make install >> make.log 2>&1 || tail -n ${LOG_LINES} make.log + cflags="" + fflags="" + if ("${FC}" --version | grep -q 'GNU'); then + cflags="-fpermissive" + fflags=$(allowed_gfortran_flags "-fallow-argument-mismatch") + fi + CFLAGS=${cflags} FFLAGS=${fflags} \ + cmake -DCMAKE_FIND_ROOT_PATH="$ROOTDIR" \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR="lib" \ + -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DBUILD_SHARED_LIBS=YES \ + -DCMAKE_BUILD_TYPE=Release .. \ + -DBUILD_TESTING=NO \ + -DSCALAPACK_BUILD_TESTS=NO \ + >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install >>make.log 2>&1 || tail -n ${LOG_LINES} make.log - popd > /dev/null - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" - fi - SCALAPACK_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; - __SYSTEM__) - echo "==================== Finding ScaLAPACK from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_lib -lscalapack "ScaLAPACK" - add_lib_from_paths SCALAPACK_LDFLAGS "libscalapack.*" $LIB_PATHS - ;; - __DONTUSE__) ;; + popd >/dev/null + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" + fi + SCALAPACK_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; +__SYSTEM__) + echo "==================== Finding ScaLAPACK from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_lib -lscalapack "ScaLAPACK" + add_lib_from_paths SCALAPACK_LDFLAGS "libscalapack.*" $LIB_PATHS + ;; +__DONTUSE__) ;; - *) - echo "==================== Linking ScaLAPACK to user paths ====================" - pkg_install_dir="$with_scalapack" - check_dir "${pkg_install_dir}/lib" - SCALAPACK_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; +*) + echo "==================== Linking ScaLAPACK to user paths ====================" + pkg_install_dir="$with_scalapack" + check_dir "${pkg_install_dir}/lib" + SCALAPACK_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "$with_scalapack" != "__DONTUSE__" ]; then - SCALAPACK_LIBS="-lscalapack" - if [ "$with_scalapack" != "__SYSTEM__" ]; then - cat << EOF > "${BUILDDIR}/setup_scalapack" + SCALAPACK_LIBS="-lscalapack" + if [ "$with_scalapack" != "__SYSTEM__" ]; then + cat <"${BUILDDIR}/setup_scalapack" prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" prepend_path PKG_CONFIG_PATH "${pkg_install_dir}/lib/pkgconfig" prepend_path CMAKE_PREFIX_PATH "${pkg_install_dir}" EOF - fi - cat << EOF >> "${BUILDDIR}/setup_scalapack" + fi + cat <>"${BUILDDIR}/setup_scalapack" export SCALAPACK_ROOT="${pkg_install_dir}" export SCALAPACK_LDFLAGS="${SCALAPACK_LDFLAGS}" export SCALAPACK_LIBS="${SCALAPACK_LIBS}" @@ -124,14 +124,14 @@ export CP_DFLAGS="\${CP_DFLAGS} IF_MPI(-D__SCALAPACK|)" export CP_LDFLAGS="\${CP_LDFLAGS} IF_MPI(${SCALAPACK_LDFLAGS}|)" export CP_LIBS="IF_MPI(-lscalapack|) \${CP_LIBS}" EOF - filter_setup "${BUILDDIR}/setup_scalapack" $SETUPFILE + filter_setup "${BUILDDIR}/setup_scalapack" $SETUPFILE fi cd "${ROOTDIR}" # ---------------------------------------------------------------------- # Suppress reporting of known leaks # ---------------------------------------------------------------------- -cat << EOF >> ${INSTALLDIR}/lsan.supp +cat <>${INSTALLDIR}/lsan.supp # leaks related to SCALAPACK leak:pdpotrf_ EOF diff --git a/toolchain/scripts/stage4/install_cereal.sh b/toolchain/scripts/stage4/install_cereal.sh index 3c84b8822b6..ada3c88977f 100755 --- a/toolchain/scripts/stage4/install_cereal.sh +++ b/toolchain/scripts/stage4/install_cereal.sh @@ -17,16 +17,16 @@ source "${SCRIPT_DIR}"/package_versions.sh # Check for version configuration from environment or individual package setting version_suffix="" if [[ -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]]; then - # Check for individual package version override - if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "cereal:alt"; then - version_suffix="alt" - elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "cereal:main"; then - version_suffix="main" - fi + # Check for individual package version override + if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "cereal:alt"; then + version_suffix="alt" + elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "cereal:main"; then + version_suffix="main" + fi fi # Fall back to global version suffix if no individual setting if [[ -z "$version_suffix" && -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" ]]; then - version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" + version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" fi # Load package variables with appropriate version load_package_vars "cereal" "$version_suffix" @@ -42,89 +42,89 @@ CEREAL_CFLAGS="" cd "${BUILDDIR}" case "$with_cereal" in - __INSTALL__) - echo "==================== Installing CEREAL ====================" - pkg_install_dir="${INSTALLDIR}/$dirname" - #pkg_install_dir="${HOME}/lib/cereal/${cereal_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - # url construction rules: - # - Branch names (master, main, develop) without v prefix - # - Version tags (e.g., 1.0.0) with v prefix - if [[ "${cereal_ver}" =~ ^([0-9a-f]{7}|[0-9a-f]{40})$ ]]; then - url="https://codeload.github.com/USCiLab/cereal/tar.gz/${cereal_ver}" - else - url="https://codeload.github.com/USCiLab/cereal/tar.gz/v${cereal_ver}" - fi - if verify_checksums "${install_lock_file}"; then - echo "$dirname is already installed, skipping it." - else - retrieve_package "${cereal_sha256}" "${filename}" "${url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d $dirname ] && rm -rf $dirname - tar -xzf $filename - cd "${dirname}" - # - mkdir build && cd build - cmake \ - -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ - -DCMAKE_INSTALL_LIBDIR="lib" \ - -DCMAKE_VERBOSE_MAKEFILE=ON \ - -DBUILD_DOC=OFF \ - -DBUILD_SANDBOX=OFF \ - -DBUILD_TESTS=OFF \ - -DTHREAD_SAFE=ON \ - -DSKIP_PORTABILITY_TEST=ON \ - -DSKIP_PERFORMANCE_COMPARISON=ON \ - .. > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log - make install -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" - fi - CEREAL_CFLAGS="-I'${pkg_install_dir}/include'" - ;; - __SYSTEM__) - echo "==================== Finding CEREAL from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - # Find cereal header file and derive package root directory - cereal_header_path="$(find_in_paths "cereal/cereal.hpp" $INCLUDE_PATHS)" - if [ "$cereal_header_path" != "__FALSE__" ]; then - # Derive pkg_install_dir from found header path - # cereal/cereal.hpp -> remove /cereal/cereal.hpp -> get include dir -> get parent dir - cereal_include_dir="$(dirname "$(dirname "$cereal_header_path")")" - pkg_install_dir="$(dirname "$cereal_include_dir")" - echo "Found cereal at: ${pkg_install_dir}" - CEREAL_CFLAGS="-I'${cereal_include_dir}'" - else - report_error "Cannot find cereal/cereal.hpp in system paths" - exit 1 - fi - ;; - __DONTUSE__) ;; - - *) - echo "==================== Linking CEREAL to user paths ====================" - pkg_install_dir="${with_cereal}" - check_dir "${pkg_install_dir}" - CEREAL_CFLAGS="-I'${pkg_install_dir}/include'" - ;; +__INSTALL__) + echo "==================== Installing CEREAL ====================" + pkg_install_dir="${INSTALLDIR}/$dirname" + #pkg_install_dir="${HOME}/lib/cereal/${cereal_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + # url construction rules: + # - Branch names (master, main, develop) without v prefix + # - Version tags (e.g., 1.0.0) with v prefix + if [[ "${cereal_ver}" =~ ^([0-9a-f]{7}|[0-9a-f]{40})$ ]]; then + url="https://codeload.github.com/USCiLab/cereal/tar.gz/${cereal_ver}" + else + url="https://codeload.github.com/USCiLab/cereal/tar.gz/v${cereal_ver}" + fi + if verify_checksums "${install_lock_file}"; then + echo "$dirname is already installed, skipping it." + else + retrieve_package "${cereal_sha256}" "${filename}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d $dirname ] && rm -rf $dirname + tar -xzf $filename + cd "${dirname}" + # + mkdir build && cd build + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR="lib" \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DBUILD_DOC=OFF \ + -DBUILD_SANDBOX=OFF \ + -DBUILD_TESTS=OFF \ + -DTHREAD_SAFE=ON \ + -DSKIP_PORTABILITY_TEST=ON \ + -DSKIP_PERFORMANCE_COMPARISON=ON \ + .. >cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make install -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" + fi + CEREAL_CFLAGS="-I'${pkg_install_dir}/include'" + ;; +__SYSTEM__) + echo "==================== Finding CEREAL from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + # Find cereal header file and derive package root directory + cereal_header_path="$(find_in_paths "cereal/cereal.hpp" $INCLUDE_PATHS)" + if [ "$cereal_header_path" != "__FALSE__" ]; then + # Derive pkg_install_dir from found header path + # cereal/cereal.hpp -> remove /cereal/cereal.hpp -> get include dir -> get parent dir + cereal_include_dir="$(dirname "$(dirname "$cereal_header_path")")" + pkg_install_dir="$(dirname "$cereal_include_dir")" + echo "Found cereal at: ${pkg_install_dir}" + CEREAL_CFLAGS="-I'${cereal_include_dir}'" + else + report_error "Cannot find cereal/cereal.hpp in system paths" + exit 1 + fi + ;; +__DONTUSE__) ;; + +*) + echo "==================== Linking CEREAL to user paths ====================" + pkg_install_dir="${with_cereal}" + check_dir "${pkg_install_dir}" + CEREAL_CFLAGS="-I'${pkg_install_dir}/include'" + ;; esac if [ "$with_cereal" != "__DONTUSE__" ]; then - if [ "$with_cereal" != "__SYSTEM__" ]; then - cat << EOF > "${BUILDDIR}/setup_cereal" + if [ "$with_cereal" != "__SYSTEM__" ]; then + cat <"${BUILDDIR}/setup_cereal" prepend_path CMAKE_PREFIX_PATH "${pkg_install_dir}" EOF - fi - cat << EOF >> "${BUILDDIR}/setup_cereal" + fi + cat <>"${BUILDDIR}/setup_cereal" export CEREAL_ROOT="${pkg_install_dir}" export CEREAL_VERSION="${cereal_ver}" EOF - filter_setup "${BUILDDIR}/setup_cereal" $SETUPFILE + filter_setup "${BUILDDIR}/setup_cereal" $SETUPFILE fi load "${BUILDDIR}/setup_cereal" diff --git a/toolchain/scripts/stage4/install_dftd4.sh b/toolchain/scripts/stage4/install_dftd4.sh index b9595226b84..1c7196f8ff4 100755 --- a/toolchain/scripts/stage4/install_dftd4.sh +++ b/toolchain/scripts/stage4/install_dftd4.sh @@ -23,72 +23,72 @@ source "${INSTALLDIR}"/toolchain.env cd "${BUILDDIR}" case "${with_dftd4}" in - __INSTALL__) - echo "==================== Installing DFT-D4 ====================" - url="https://github.com/dftd4/dftd4/releases/download/v${dftd4_ver}/${dftd4_pkg}" - pkg_install_dir="${INSTALLDIR}/dftd4-${dftd4_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - - if verify_checksums "${install_lock_file}"; then - echo "dftd4-${dftd4_ver} is already installed, skipping it." - else - retrieve_package "${dftd4_sha256}" "${dftd4_pkg}" "${url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - - echo "Installing from scratch into ${pkg_install_dir}" - [ -d "dftd4-${dftd4_ver}" ] && rm -rf "dftd4-${dftd4_ver}" - tar -xJf "${dftd4_pkg}" - cd dftd4-${dftd4_ver} - - mkdir build && cd build - CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}:${OPENBLAS_ROOT}" cmake \ - -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ - -DCMAKE_INSTALL_LIBDIR=lib \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_VERBOSE_MAKEFILE=ON \ - .. > cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log - make install -j $(get_nprocs) > make.log 2>&1 || tail -n ${LOG_LINES} make.log - cd .. - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" - fi - ;; - - __SYSTEM__) - echo "==================== Finding DFT-D4 from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_command pkg-config --modversion dftd4 - pkg_install_dir="$(dirname $(dirname $(find_in_paths "libdftd4.*" $LIB_PATHS)))" - if [ -d "${pkg_install_dir}/lib/cmake/dftd4" ] || - [ -d "${pkg_install_dir}/lib64/cmake/dftd4" ]; then - echo "Package dftd4 is found and confirmed to be built with CMake." - else - echo "ERROR: ABACUS requires dftd4 to be built with CMake." - exit 1 - fi - ;; - - __DONTUSE__) ;; - - *) - echo "==================== Linking DFT-D4 to user paths ====================" - pkg_install_dir="$with_dftd4" - check_dir "${pkg_install_dir}/include" - ;; +__INSTALL__) + echo "==================== Installing DFT-D4 ====================" + url="https://github.com/dftd4/dftd4/releases/download/v${dftd4_ver}/${dftd4_pkg}" + pkg_install_dir="${INSTALLDIR}/dftd4-${dftd4_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + + if verify_checksums "${install_lock_file}"; then + echo "dftd4-${dftd4_ver} is already installed, skipping it." + else + retrieve_package "${dftd4_sha256}" "${dftd4_pkg}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + + echo "Installing from scratch into ${pkg_install_dir}" + [ -d "dftd4-${dftd4_ver}" ] && rm -rf "dftd4-${dftd4_ver}" + tar -xJf "${dftd4_pkg}" + cd dftd4-${dftd4_ver} + + mkdir build && cd build + CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}:${OPENBLAS_ROOT}" cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + .. >cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make install -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" + fi + ;; + +__SYSTEM__) + echo "==================== Finding DFT-D4 from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_command pkg-config --modversion dftd4 + pkg_install_dir="$(dirname $(dirname $(find_in_paths "libdftd4.*" $LIB_PATHS)))" + if [ -d "${pkg_install_dir}/lib/cmake/dftd4" ] || + [ -d "${pkg_install_dir}/lib64/cmake/dftd4" ]; then + echo "Package dftd4 is found and confirmed to be built with CMake." + else + echo "ERROR: ABACUS requires dftd4 to be built with CMake." + exit 1 + fi + ;; + +__DONTUSE__) ;; + +*) + echo "==================== Linking DFT-D4 to user paths ====================" + pkg_install_dir="$with_dftd4" + check_dir "${pkg_install_dir}/include" + ;; esac if [ "${with_dftd4}" != "__DONTUSE__" ]; then - cat << EOF > "${BUILDDIR}/setup_dftd4" + cat <"${BUILDDIR}/setup_dftd4" export DFTD4_VER="${dftd4_ver}" export DFTD4_ROOT="${pkg_install_dir}" EOF - if [ "${with_dftd4}" != "__SYSTEM__" ]; then - cat << EOF >> "${BUILDDIR}/setup_dftd4" + if [ "${with_dftd4}" != "__SYSTEM__" ]; then + cat <>"${BUILDDIR}/setup_dftd4" prepend_path PATH "${pkg_install_dir}/bin" prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" @@ -96,8 +96,8 @@ prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" prepend_path CPATH "${pkg_install_dir}/include" prepend_path CMAKE_PREFIX_PATH "${pkg_install_dir}" EOF - fi - filter_setup "${BUILDDIR}/setup_dftd4" "${SETUPFILE}" + fi + filter_setup "${BUILDDIR}/setup_dftd4" "${SETUPFILE}" fi load "${BUILDDIR}/setup_dftd4" diff --git a/toolchain/scripts/stage4/install_json.sh b/toolchain/scripts/stage4/install_json.sh index 384e807ac3d..ce1852d3e11 100755 --- a/toolchain/scripts/stage4/install_json.sh +++ b/toolchain/scripts/stage4/install_json.sh @@ -17,48 +17,48 @@ cd "${BUILDDIR}" pkg_install_dir="" case "${with_json}" in - __INSTALL__) - echo "==================== Installing nlohmann-json ====================" - filename="json-${json_ver}.tar.xz" - url="https://github.com/nlohmann/json/releases/download/v${json_ver}/json.tar.xz" - pkg_install_dir="${INSTALLDIR}/json-${json_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - if verify_checksums "${install_lock_file}"; then - echo "json-${json_ver} is already installed, skipping it." - else - retrieve_package "${json_sha256}" "${filename}" "${url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - [ -d "json-${json_ver}" ] && rm -rf "json-${json_ver}" - tar -xJf "json-${json_ver}.tar.xz" - cd "json" - mkdir build && cd build - cmake .. \ - -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ - -DJSON_BuildTests=OFF \ - > cmake.log 2>&1 || tail -n "${LOG_LINES}" cmake.log - make install -j "$(get_nprocs)" > install.log 2>&1 || tail -n "${LOG_LINES}" install.log - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/install_json.sh" - fi - ;; - __SYSTEM__) - # ABACUS resolves the installed configuration with CMake's find_package. - echo "Using system nlohmann-json (resolved by CMake)." - ;; - __DONTUSE__) ;; - *) - pkg_install_dir="${with_json}" - check_dir "${pkg_install_dir}" - ;; +__INSTALL__) + echo "==================== Installing nlohmann-json ====================" + filename="json-${json_ver}.tar.xz" + url="https://github.com/nlohmann/json/releases/download/v${json_ver}/json.tar.xz" + pkg_install_dir="${INSTALLDIR}/json-${json_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "json-${json_ver} is already installed, skipping it." + else + retrieve_package "${json_sha256}" "${filename}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + [ -d "json-${json_ver}" ] && rm -rf "json-${json_ver}" + tar -xJf "json-${json_ver}.tar.xz" + cd "json" + mkdir build && cd build + cmake .. \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DJSON_BuildTests=OFF \ + >cmake.log 2>&1 || tail -n "${LOG_LINES}" cmake.log + make install -j "$(get_nprocs)" >install.log 2>&1 || tail -n "${LOG_LINES}" install.log + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/install_json.sh" + fi + ;; +__SYSTEM__) + # ABACUS resolves the installed configuration with CMake's find_package. + echo "Using system nlohmann-json (resolved by CMake)." + ;; +__DONTUSE__) ;; +*) + pkg_install_dir="${with_json}" + check_dir "${pkg_install_dir}" + ;; esac if [ -n "${pkg_install_dir}" ]; then - cat > "${BUILDDIR}/setup_json" <"${BUILDDIR}/setup_json" < remove /Comm/Comm_Tools.h -> get include dir -> get parent dir - libcomm_include_dir="$(dirname "$(dirname "$libcomm_header_path")")" - pkg_install_dir="$(dirname "$libcomm_include_dir")" - echo "Found libcomm at: ${pkg_install_dir}" - LIBCOMM_CFLAGS="-I'${libcomm_include_dir}'" - else - report_error "Cannot find Comm/Comm_Tools.h in system paths" - exit 1 - fi - ;; - __DONTUSE__) ;; - - *) - echo "==================== Linking LIBCOMM to user paths ====================" - pkg_install_dir="${with_libcomm}" - check_dir "${pkg_install_dir}" - LIBCOMM_CFLAGS="-I'${pkg_install_dir}/include'" - ;; +__INSTALL__) + echo "==================== Installing LIBCOMM ====================" + pkg_install_dir="${INSTALLDIR}/$dirname" + #pkg_install_dir="${HOME}/lib/libcomm/${libcomm_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + # url="https://github.com/abacusmodeling/LibComm/archive/refs/tags/v${libcomm_ver}.tar.gz" + # url construction rules: + # - Branch names (master, main, develop) without v prefix + # - Version tags (e.g., 1.0.0) with v prefix + if [[ "${libcomm_ver}" =~ ^([0-9a-f]{7}|[0-9a-f]{40})$ ]]; then + url="https://codeload.github.com/abacusmodeling/LibComm/tar.gz/${libcomm_ver}" + else + url="https://codeload.github.com/abacusmodeling/LibComm/tar.gz/v${libcomm_ver}" + fi + if verify_checksums "${install_lock_file}"; then + echo "$dirname is already installed, skipping it." + else + retrieve_package "${libcomm_sha256}" "${filename}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d $dirname ] && rm -rf $dirname + tar -xzf $filename + mkdir -p "${pkg_install_dir}" + cp -r $dirname/* "${pkg_install_dir}/" + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" + fi + LIBCOMM_CFLAGS="-I'${pkg_install_dir}/include'" + ;; +__SYSTEM__) + echo "==================== Finding LIBCOMM from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + # Find libcomm header file and derive package root directory + libcomm_header_path="$(find_in_paths "Comm/Comm_Tools.h" $INCLUDE_PATHS)" + if [ "$libcomm_header_path" != "__FALSE__" ]; then + # Derive pkg_install_dir from found header path + # Comm/Comm_Tools.h -> remove /Comm/Comm_Tools.h -> get include dir -> get parent dir + libcomm_include_dir="$(dirname "$(dirname "$libcomm_header_path")")" + pkg_install_dir="$(dirname "$libcomm_include_dir")" + echo "Found libcomm at: ${pkg_install_dir}" + LIBCOMM_CFLAGS="-I'${libcomm_include_dir}'" + else + report_error "Cannot find Comm/Comm_Tools.h in system paths" + exit 1 + fi + ;; +__DONTUSE__) ;; + +*) + echo "==================== Linking LIBCOMM to user paths ====================" + pkg_install_dir="${with_libcomm}" + check_dir "${pkg_install_dir}" + LIBCOMM_CFLAGS="-I'${pkg_install_dir}/include'" + ;; esac if [ "$with_libcomm" != "__DONTUSE__" ]; then - if [ "$with_libcomm" != "__SYSTEM__" ]; then - cat << EOF > "${BUILDDIR}/setup_libcomm" + if [ "$with_libcomm" != "__SYSTEM__" ]; then + cat <"${BUILDDIR}/setup_libcomm" prepend_path CPATH "${pkg_install_dir}/include" EOF - fi - cat << EOF >> "${BUILDDIR}/setup_libcomm" + fi + cat <>"${BUILDDIR}/setup_libcomm" export LIBCOMM_ROOT="${pkg_install_dir}" EOF - filter_setup "${BUILDDIR}/setup_libcomm" $SETUPFILE + filter_setup "${BUILDDIR}/setup_libcomm" $SETUPFILE fi load "${BUILDDIR}/setup_libcomm" diff --git a/toolchain/scripts/stage4/install_libnpy.sh b/toolchain/scripts/stage4/install_libnpy.sh index 4154fe76331..94c3da8a076 100755 --- a/toolchain/scripts/stage4/install_libnpy.sh +++ b/toolchain/scripts/stage4/install_libnpy.sh @@ -20,16 +20,16 @@ source "${SCRIPT_DIR}"/package_versions.sh # Check for version configuration from environment or individual package setting version_suffix="" if [[ -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]]; then - # Check for individual package version override - if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "libnpy:alt"; then - version_suffix="alt" - elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "libnpy:main"; then - version_suffix="main" - fi + # Check for individual package version override + if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "libnpy:alt"; then + version_suffix="alt" + elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "libnpy:main"; then + version_suffix="main" + fi fi # Fall back to global version suffix if no individual setting if [[ -z "$version_suffix" && -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" ]]; then - version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" + version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" fi # Load package variables with appropriate version load_package_vars "libnpy" "$version_suffix" @@ -45,68 +45,68 @@ LIBNPY_CFLAGS="" cd "${BUILDDIR}" case "$with_libnpy" in - __INSTALL__) - echo "==================== Installing LIBNPY ====================" - pkg_install_dir="${INSTALLDIR}/$dirname" - #pkg_install_dir="${HOME}/lib/libnpy/${libnpy_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - url="https://codeload.github.com/llohse/libnpy/tar.gz/v${libnpy_ver}" - if verify_checksums "${install_lock_file}"; then - echo "$dirname is already installed, skipping it." - else - retrieve_package "${libnpy_sha256}" "${filename}" "${url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d $dirname ] && rm -rf $dirname - tar -xzf $filename - mkdir -p "${pkg_install_dir}" - cp -r $dirname/* "${pkg_install_dir}/" - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" - fi - LIBNPY_CFLAGS="-I'${pkg_install_dir}/include'" - ;; - __SYSTEM__) - echo "==================== Finding LIBNPY from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - # Find libnpy header file and derive package root directory - libnpy_header_path="$(find_in_paths "npy.hpp" $INCLUDE_PATHS)" - if [ "$libnpy_header_path" != "__FALSE__" ]; then - # Derive pkg_install_dir from found header path - # npy.hpp -> get include dir -> get parent dir - libnpy_include_dir="$(dirname "$libnpy_header_path")" - pkg_install_dir="$(dirname "$libnpy_include_dir")" - echo "Found libnpy at: ${pkg_install_dir}" - LIBNPY_CFLAGS="-I'${libnpy_include_dir}'" - else - report_error "Cannot find npy.hpp in system paths" - exit 1 - fi - ;; - __DONTUSE__) ;; - - *) - echo "==================== Linking LIBNPY to user paths ====================" - pkg_install_dir="${with_libnpy}" - check_dir "${pkg_install_dir}" - LIBNPY_CFLAGS="-I'${pkg_install_dir}/include'" - ;; +__INSTALL__) + echo "==================== Installing LIBNPY ====================" + pkg_install_dir="${INSTALLDIR}/$dirname" + #pkg_install_dir="${HOME}/lib/libnpy/${libnpy_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + url="https://codeload.github.com/llohse/libnpy/tar.gz/v${libnpy_ver}" + if verify_checksums "${install_lock_file}"; then + echo "$dirname is already installed, skipping it." + else + retrieve_package "${libnpy_sha256}" "${filename}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d $dirname ] && rm -rf $dirname + tar -xzf $filename + mkdir -p "${pkg_install_dir}" + cp -r $dirname/* "${pkg_install_dir}/" + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" + fi + LIBNPY_CFLAGS="-I'${pkg_install_dir}/include'" + ;; +__SYSTEM__) + echo "==================== Finding LIBNPY from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + # Find libnpy header file and derive package root directory + libnpy_header_path="$(find_in_paths "npy.hpp" $INCLUDE_PATHS)" + if [ "$libnpy_header_path" != "__FALSE__" ]; then + # Derive pkg_install_dir from found header path + # npy.hpp -> get include dir -> get parent dir + libnpy_include_dir="$(dirname "$libnpy_header_path")" + pkg_install_dir="$(dirname "$libnpy_include_dir")" + echo "Found libnpy at: ${pkg_install_dir}" + LIBNPY_CFLAGS="-I'${libnpy_include_dir}'" + else + report_error "Cannot find npy.hpp in system paths" + exit 1 + fi + ;; +__DONTUSE__) ;; + +*) + echo "==================== Linking LIBNPY to user paths ====================" + pkg_install_dir="${with_libnpy}" + check_dir "${pkg_install_dir}" + LIBNPY_CFLAGS="-I'${pkg_install_dir}/include'" + ;; esac if [ "$with_libnpy" != "__DONTUSE__" ]; then - if [ "$with_libnpy" != "__SYSTEM__" ]; then - cat << EOF > "${BUILDDIR}/setup_libnpy" + if [ "$with_libnpy" != "__SYSTEM__" ]; then + cat <"${BUILDDIR}/setup_libnpy" prepend_path CPATH "${pkg_install_dir}/include" EOF - fi - cat << EOF >> "${BUILDDIR}/setup_libnpy" + fi + cat <>"${BUILDDIR}/setup_libnpy" export LIBNPY_ROOT="${pkg_install_dir}" EOF - filter_setup "${BUILDDIR}/setup_libnpy" $SETUPFILE + filter_setup "${BUILDDIR}/setup_libnpy" $SETUPFILE fi load "${BUILDDIR}/setup_libnpy" diff --git a/toolchain/scripts/stage4/install_libri.sh b/toolchain/scripts/stage4/install_libri.sh index fde55fb7549..197462af7ab 100755 --- a/toolchain/scripts/stage4/install_libri.sh +++ b/toolchain/scripts/stage4/install_libri.sh @@ -21,16 +21,16 @@ source "${SCRIPT_DIR}"/package_versions.sh # Check for version configuration from environment or individual package setting version_suffix="" if [[ -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]]; then - # Check for individual package version override - if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "libri:alt"; then - version_suffix="alt" - elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "libri:main"; then - version_suffix="main" - fi + # Check for individual package version override + if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "libri:alt"; then + version_suffix="alt" + elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "libri:main"; then + version_suffix="main" + fi fi # Fall back to global version suffix if no individual setting if [[ -z "$version_suffix" && -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" ]]; then - version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" + version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" fi # Load package variables with appropriate version load_package_vars "libri" "$version_suffix" @@ -43,77 +43,77 @@ source "${INSTALLDIR}"/toolchain.env cd "${BUILDDIR}" case "$with_libri" in - __INSTALL__) - echo "==================== Installing LIBRI ====================" - dirname="LibRI-${libri_ver}" - pkg_install_dir="${INSTALLDIR}/$dirname" - #pkg_install_dir="${HOME}/lib/libri/${libri_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - # url construction rules: - # - Branch names (master, main, develop) without v prefix - # - Version tags (e.g., 1.0.0) with v prefix - if [[ "${libri_ver}" =~ ^([0-9a-f]{7}|[0-9a-f]{40})$ ]]; then - url="https://codeload.github.com/abacusmodeling/LibRI/tar.gz/${libri_ver}" - else - url="https://codeload.github.com/abacusmodeling/LibRI/tar.gz/v${libri_ver}" - fi - filename="LibRI-${libri_ver}.tar.gz" - if verify_checksums "${install_lock_file}"; then - echo "$dirname is already installed, skipping it." - else - retrieve_package "${libri_sha256}" "${filename}" "${url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d $dirname ] && rm -rf $dirname - tar -xzf $filename - mkdir -p "${pkg_install_dir}" - cp -r $dirname/* "${pkg_install_dir}/" - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" - fi - LIBRI_CFLAGS="-I'${pkg_install_dir}/include'" - ;; - __SYSTEM__) - echo "==================== Finding LIBRI from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - # Find libri header file and derive package root directory - libri_header_path="$(find_in_paths "RI/version.h" $INCLUDE_PATHS)" - if [ "$libri_header_path" != "__FALSE__" ]; then - # Derive pkg_install_dir from found header path - # RI/version.h -> remove /RI/version.h -> get include dir -> get parent dir - libri_include_dir="$(dirname "$(dirname "$libri_header_path")")" - pkg_install_dir="$(dirname "$libri_include_dir")" - echo "Found libri at: ${pkg_install_dir}" - LIBRI_CFLAGS="-I'${libri_include_dir}'" - else - report_error "Cannot find RI/version.h in system paths" - exit 1 - fi - ;; - __DONTUSE__) ;; +__INSTALL__) + echo "==================== Installing LIBRI ====================" + dirname="LibRI-${libri_ver}" + pkg_install_dir="${INSTALLDIR}/$dirname" + #pkg_install_dir="${HOME}/lib/libri/${libri_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + # url construction rules: + # - Branch names (master, main, develop) without v prefix + # - Version tags (e.g., 1.0.0) with v prefix + if [[ "${libri_ver}" =~ ^([0-9a-f]{7}|[0-9a-f]{40})$ ]]; then + url="https://codeload.github.com/abacusmodeling/LibRI/tar.gz/${libri_ver}" + else + url="https://codeload.github.com/abacusmodeling/LibRI/tar.gz/v${libri_ver}" + fi + filename="LibRI-${libri_ver}.tar.gz" + if verify_checksums "${install_lock_file}"; then + echo "$dirname is already installed, skipping it." + else + retrieve_package "${libri_sha256}" "${filename}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d $dirname ] && rm -rf $dirname + tar -xzf $filename + mkdir -p "${pkg_install_dir}" + cp -r $dirname/* "${pkg_install_dir}/" + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" + fi + LIBRI_CFLAGS="-I'${pkg_install_dir}/include'" + ;; +__SYSTEM__) + echo "==================== Finding LIBRI from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + # Find libri header file and derive package root directory + libri_header_path="$(find_in_paths "RI/version.h" $INCLUDE_PATHS)" + if [ "$libri_header_path" != "__FALSE__" ]; then + # Derive pkg_install_dir from found header path + # RI/version.h -> remove /RI/version.h -> get include dir -> get parent dir + libri_include_dir="$(dirname "$(dirname "$libri_header_path")")" + pkg_install_dir="$(dirname "$libri_include_dir")" + echo "Found libri at: ${pkg_install_dir}" + LIBRI_CFLAGS="-I'${libri_include_dir}'" + else + report_error "Cannot find RI/version.h in system paths" + exit 1 + fi + ;; +__DONTUSE__) ;; - *) - echo "==================== Linking LIBRI to user paths ====================" - pkg_install_dir="${with_libri}" - check_dir "${pkg_install_dir}" - LIBRI_CFLAGS="-I'${pkg_install_dir}/include'" - ;; +*) + echo "==================== Linking LIBRI to user paths ====================" + pkg_install_dir="${with_libri}" + check_dir "${pkg_install_dir}" + LIBRI_CFLAGS="-I'${pkg_install_dir}/include'" + ;; esac if [ "$with_libri" != "__DONTUSE__" ]; then - if [ "$with_libri" != "__SYSTEM__" ]; then - cat << EOF > "${BUILDDIR}/setup_libri" + if [ "$with_libri" != "__SYSTEM__" ]; then + cat <"${BUILDDIR}/setup_libri" prepend_path CPATH "${pkg_install_dir}/include" EOF - fi - cat << EOF >> "${BUILDDIR}/setup_libri" + fi + cat <>"${BUILDDIR}/setup_libri" export LIBRI_ROOT="${pkg_install_dir}" EOF - filter_setup "${BUILDDIR}/setup_libri" $SETUPFILE + filter_setup "${BUILDDIR}/setup_libri" $SETUPFILE fi load "${BUILDDIR}/setup_libri" diff --git a/toolchain/scripts/stage4/install_libtorch.sh b/toolchain/scripts/stage4/install_libtorch.sh index 9edbb59a24c..83c99c3f0fb 100755 --- a/toolchain/scripts/stage4/install_libtorch.sh +++ b/toolchain/scripts/stage4/install_libtorch.sh @@ -19,19 +19,19 @@ source "${SCRIPT_DIR}"/package_versions.sh # Check for version configuration from environment or individual package setting version_suffix="" if [[ -n "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" ]]; then - # Check for individual package version override - if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "libtorch:alt"; then - version_suffix="alt" - elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "libtorch:main"; then - version_suffix="main" - fi + # Check for individual package version override + if echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "libtorch:alt"; then + version_suffix="alt" + elif echo "${ABACUS_TOOLCHAIN_PACKAGE_VERSIONS}" | grep -q "libtorch:main"; then + version_suffix="main" + fi fi # Fall back to global version suffix if no individual setting if [[ -z "$version_suffix" && -n "${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" ]]; then - version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" + version_suffix="${ABACUS_TOOLCHAIN_VERSION_SUFFIX}" fi # Load package variables with appropriate version -load_package_vars "libtorch" "$version_suffix" +load_package_vars "libtorch" "$version_suffix" source "${INSTALLDIR}"/toolchain.conf source "${INSTALLDIR}"/toolchain.env @@ -41,66 +41,66 @@ source "${INSTALLDIR}"/toolchain.env cd "${BUILDDIR}" case "${with_libtorch}" in - __INSTALL__) - echo "==================== Installing libtorch ====================" - dirname="libtorch-${libtorch_ver}" - pkg_install_dir="${INSTALLDIR}/${dirname}" - #pkg_install_dir="${HOME}/lib/libtorch/${libtorch_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - archive_file="libtorch-cxx11-abi-shared-with-deps-${libtorch_ver}%2Bcpu.zip" - filename="${dirname}.zip" - - if verify_checksums "${install_lock_file}"; then - echo "${dirname} is already installed, skipping it." - else - url=https://download.pytorch.org/libtorch/cpu/${archive_file} - retrieve_package "${libtorch_sha256}" "${filename}" "${url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - echo "Installing from scratch into ${pkg_install_dir}" - unzip -q $filename - mkdir -p "${pkg_install_dir}" - mv libtorch/* "${pkg_install_dir}/" - - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" - fi - LIBTORCH_CXXFLAGS="-I${pkg_install_dir}/include" - LIBTORCH_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath='${pkg_install_dir}/lib'" - ;; - __SYSTEM__) - echo "==================== Finding libtorch from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_lib -ltorch "libtorch" - add_include_from_paths LIBTORCH_CXXFLAGS "libtorch.h" $INCLUDE_PATHS - add_lib_from_paths LIBTORCH_LDFLAGS "libtorch.*" "$LIB_PATHS" - ;; - __DONTUSE__) ;; - - *) - echo "==================== Linking libtorch to user paths ====================" - pkg_install_dir="${with_libtorch}" - - # use the lib64 directory if present (multi-abi distros may link lib/ to lib32/ instead) - LIBTORCH_LIBDIR="${pkg_install_dir}/lib" - [ -d "${pkg_install_dir}/lib64" ] && LIBTORCH_LIBDIR="${pkg_install_dir}/lib64" - - check_dir "${LIBTORCH_LIBDIR}" - LIBTORCH_CXXFLAGS="-I${pkg_install_dir}/include" - if [ "$ENABLE_CUDA" = "__TRUE__" ]; then - LIBTORCH_LDFLAGS="-Wl,--no-as-needed,-L'${LIBTORCH_LIBDIR}' -Wl,--no-as-needed,-rpath='${LIBTORCH_LIBDIR}'" - LIBTORCH_LDFLAGS="-L'${LIBTORCH_LIBDIR}' -Wl,-rpath='${LIBTORCH_LIBDIR}'" - fi - ;; +__INSTALL__) + echo "==================== Installing libtorch ====================" + dirname="libtorch-${libtorch_ver}" + pkg_install_dir="${INSTALLDIR}/${dirname}" + #pkg_install_dir="${HOME}/lib/libtorch/${libtorch_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + archive_file="libtorch-cxx11-abi-shared-with-deps-${libtorch_ver}%2Bcpu.zip" + filename="${dirname}.zip" + + if verify_checksums "${install_lock_file}"; then + echo "${dirname} is already installed, skipping it." + else + url=https://download.pytorch.org/libtorch/cpu/${archive_file} + retrieve_package "${libtorch_sha256}" "${filename}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + unzip -q $filename + mkdir -p "${pkg_install_dir}" + mv libtorch/* "${pkg_install_dir}/" + + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" + fi + LIBTORCH_CXXFLAGS="-I${pkg_install_dir}/include" + LIBTORCH_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath='${pkg_install_dir}/lib'" + ;; +__SYSTEM__) + echo "==================== Finding libtorch from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_lib -ltorch "libtorch" + add_include_from_paths LIBTORCH_CXXFLAGS "libtorch.h" $INCLUDE_PATHS + add_lib_from_paths LIBTORCH_LDFLAGS "libtorch.*" "$LIB_PATHS" + ;; +__DONTUSE__) ;; + +*) + echo "==================== Linking libtorch to user paths ====================" + pkg_install_dir="${with_libtorch}" + + # use the lib64 directory if present (multi-abi distros may link lib/ to lib32/ instead) + LIBTORCH_LIBDIR="${pkg_install_dir}/lib" + [ -d "${pkg_install_dir}/lib64" ] && LIBTORCH_LIBDIR="${pkg_install_dir}/lib64" + + check_dir "${LIBTORCH_LIBDIR}" + LIBTORCH_CXXFLAGS="-I${pkg_install_dir}/include" + if [ "$ENABLE_CUDA" = "__TRUE__" ]; then + LIBTORCH_LDFLAGS="-Wl,--no-as-needed,-L'${LIBTORCH_LIBDIR}' -Wl,--no-as-needed,-rpath='${LIBTORCH_LIBDIR}'" + LIBTORCH_LDFLAGS="-L'${LIBTORCH_LIBDIR}' -Wl,-rpath='${LIBTORCH_LIBDIR}'" + fi + ;; esac if [ "$with_libtorch" != "__DONTUSE__" ]; then - if [ "$with_libtorch" != "__SYSTEM__" ]; then - cat << EOF > "${BUILDDIR}/setup_libtorch" + if [ "$with_libtorch" != "__SYSTEM__" ]; then + cat <"${BUILDDIR}/setup_libtorch" prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" @@ -108,22 +108,22 @@ prepend_path PKG_CONFIG_PATH "${pkg_install_dir}/lib/pkgconfig" prepend_path CMAKE_PREFIX_PATH "${pkg_install_dir}" prepend_path CPATH "${pkg_install_dir}/include" EOF - fi - cat << EOF >> "${BUILDDIR}/setup_libtorch" + fi + cat <>"${BUILDDIR}/setup_libtorch" export CP_DFLAGS="\${CP_DFLAGS} -D__LIBTORCH" export CXXFLAGS="\${CXXFLAGS} ${LIBTORCH_CXXFLAGS}" export CP_LDFLAGS="\${CP_LDFLAGS} ${LIBTORCH_LDFLAGS}" EOF - if [ "$ENABLE_CUDA" = "__TRUE__" ]; then - cat << EOF >> "${BUILDDIR}/setup_libtorch" + if [ "$ENABLE_CUDA" = "__TRUE__" ]; then + cat <>"${BUILDDIR}/setup_libtorch" export CP_LIBS="\${CP_LIBS} -lc10 -lc10_cuda -ltorch_cpu -ltorch_cuda -ltorch" EOF - else - cat << EOF >> "${BUILDDIR}/setup_libtorch" + else + cat <>"${BUILDDIR}/setup_libtorch" export CP_LIBS="\${CP_LIBS} -lc10 -ltorch_cpu -ltorch" EOF - fi - filter_setup "${BUILDDIR}/setup_libtorch" "${SETUPFILE}" + fi + filter_setup "${BUILDDIR}/setup_libtorch" "${SETUPFILE}" fi load "${BUILDDIR}/setup_libtorch" diff --git a/toolchain/scripts/stage4/install_nep.sh b/toolchain/scripts/stage4/install_nep.sh index 2d0bbfdbe9d..92ea89a53f6 100755 --- a/toolchain/scripts/stage4/install_nep.sh +++ b/toolchain/scripts/stage4/install_nep.sh @@ -26,29 +26,29 @@ NEP_LIBS="" cd "${BUILDDIR}" case "$with_nep" in - __INSTALL__) - echo "==================== Installing NEP (CPU version) ====================" - dirname="NEP_CPU-${nep_ver}" - pkg_install_dir="${INSTALLDIR}/${dirname}" - install_lock_file="${pkg_install_dir}/install_successful" - filename="nep-${nep_ver}.tar.gz" - url="https://codeload.github.com/brucefan1983/NEP_CPU/tar.gz/${nep_ver}" - - if verify_checksums "${install_lock_file}"; then - echo "$dirname is already installed, skipping it." - else - retrieve_package "${nep_sha256}" "${filename}" "${url}" - - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d $dirname ] && rm -rf $dirname - tar -xzf $filename - cd $dirname - - cat << EOF > Makefile +__INSTALL__) + echo "==================== Installing NEP (CPU version) ====================" + dirname="NEP_CPU-${nep_ver}" + pkg_install_dir="${INSTALLDIR}/${dirname}" + install_lock_file="${pkg_install_dir}/install_successful" + filename="nep-${nep_ver}.tar.gz" + url="https://codeload.github.com/brucefan1983/NEP_CPU/tar.gz/${nep_ver}" + + if verify_checksums "${install_lock_file}"; then + echo "$dirname is already installed, skipping it." + else + retrieve_package "${nep_sha256}" "${filename}" "${url}" + + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d $dirname ] && rm -rf $dirname + tar -xzf $filename + cd $dirname + + cat <Makefile CXX ?= g++ # Compiler flags @@ -89,37 +89,37 @@ install: cp src/*.h \$(PREFIX)/include/ EOF - make > make.log 2>&1 || tail -n ${LOG_LINES} make.log - make PREFIX="${pkg_install_dir}" install > install.log 2>&1 || tail -n ${LOG_LINES} install.log + make >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make PREFIX="${pkg_install_dir}" install >install.log 2>&1 || tail -n ${LOG_LINES} install.log - cd .. - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" - fi - NEP_CFLAGS="-I'${pkg_install_dir}/include'" - NEP_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; - - __SYSTEM__) - echo "==================== Finding NEP_CPU from system paths ====================" - check_lib -lnep "nep" - add_include_from_paths NEP_CFLAGS "nep.h" $INCLUDE_PATHS - add_lib_from_paths NEP_LDFLAGS "libnep.*" $LIB_PATHS - ;; - __DONTUSE__) ;; - *) - echo "==================== Linking NEP_CPU to user paths ====================" - pkg_install_dir="$with_nep" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - NEP_CFLAGS="-I'${pkg_install_dir}/include'" - NEP_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" + fi + NEP_CFLAGS="-I'${pkg_install_dir}/include'" + NEP_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + +__SYSTEM__) + echo "==================== Finding NEP_CPU from system paths ====================" + check_lib -lnep "nep" + add_include_from_paths NEP_CFLAGS "nep.h" $INCLUDE_PATHS + add_lib_from_paths NEP_LDFLAGS "libnep.*" $LIB_PATHS + ;; +__DONTUSE__) ;; +*) + echo "==================== Linking NEP_CPU to user paths ====================" + pkg_install_dir="$with_nep" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + NEP_CFLAGS="-I'${pkg_install_dir}/include'" + NEP_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "$with_nep" != "__DONTUSE__" ]; then NEP_LIBS="-lnep" if [ "$with_nep" != "__SYSTEM__" ]; then - cat << EOF > "${BUILDDIR}/setup_nep" + cat <"${BUILDDIR}/setup_nep" prepend_path LD_LIBRARY_PATH "${pkg_install_dir}/lib" prepend_path LD_RUN_PATH "${pkg_install_dir}/lib" prepend_path LIBRARY_PATH "${pkg_install_dir}/lib" @@ -127,7 +127,7 @@ prepend_path CPATH "${pkg_install_dir}/include" prepend_path CMAKE_PREFIX_PATH "${pkg_install_dir}" EOF fi - cat << EOF >> "${BUILDDIR}/setup_nep" + cat <>"${BUILDDIR}/setup_nep" export NEP_ROOT="${pkg_install_dir}" EOF filter_setup "${BUILDDIR}/setup_nep" $SETUPFILE diff --git a/toolchain/scripts/tool_kit.sh b/toolchain/scripts/tool_kit.sh index 677bb07df64..1bd8194ccd2 100755 --- a/toolchain/scripts/tool_kit.sh +++ b/toolchain/scripts/tool_kit.sh @@ -31,7 +31,7 @@ report_timing_enhanced() { local start_time="$2" local end_time="${3:-$(date +%s)}" local duration=$((end_time - start_time)) - + if [[ $duration -gt 3600 ]]; then printf "Step '%s' completed in %d hours, %d minutes, %d seconds.\n" \ "$step_name" $((duration / 3600)) $(((duration % 3600) / 60)) $((duration % 60)) @@ -77,32 +77,32 @@ report_error_enhanced() { local error_message="$2" local context="${3:-}" local lineno="${4:-}" - + local location="" if [[ -n "$lineno" ]]; then location=", line $lineno" fi - + echo "ERROR [$error_code]: (${SCRIPT_NAME}${location}) $error_message" >&2 if [[ -n "$context" ]]; then echo "Context: $context" >&2 fi - + return $error_code } # Enhanced warning reporting with severity levels report_warning_enhanced() { - local severity="${1:-INFO}" # INFO, WARNING, CRITICAL + local severity="${1:-INFO}" # INFO, WARNING, CRITICAL local message="$2" local context="${3:-}" local lineno="${4:-}" - + local location="" if [[ -n "$lineno" ]]; then location=", line $lineno" fi - + echo "$severity: (${SCRIPT_NAME}${location}) $message" >&2 if [[ -n "$context" ]]; then echo "Context: $context" >&2 @@ -111,10 +111,10 @@ report_warning_enhanced() { # recommend users to use offline installation when download failed # zhaoqing in 2025.10.15 -recommend_offline_installation(){ +recommend_offline_installation() { __filename=$1 __url=$2 - cat << EOF + cat < /dev/null 2>&1); then + elif $(command -v nproc >/dev/null 2>&1); then echo $(nproc) - elif $(command -v sysctl > /dev/null 2>&1); then + elif $(command -v sysctl >/dev/null 2>&1); then echo $(sysctl -n hw.ncpu) else echo 1 @@ -421,32 +421,32 @@ require_env() { validate_env_vars() { local required_vars=("$@") local missing_vars=() - + for var in "${required_vars[@]}"; do if [[ -z "${!var:-}" ]]; then missing_vars+=("$var") fi done - + if [[ ${#missing_vars[@]} -gt 0 ]]; then report_error_enhanced 1 "Missing required environment variables" "$(printf '%s ' "${missing_vars[@]}")" return 1 fi - + return 0 } # Check system requirements check_system_requirements() { - local min_disk_space_gb="${1:-10}" # Default 10GB + local min_disk_space_gb="${1:-10}" # Default 10GB local required_commands=("${@:2}") - + # Check disk space local available_space=$(df . | awk 'NR==2 {print int($4/1024/1024)}') if [[ $available_space -lt $min_disk_space_gb ]]; then report_warning_enhanced "WARNING" "Low disk space: ${available_space}GB available, ${min_disk_space_gb}GB recommended" fi - + # Check required commands for cmd in "${required_commands[@]}"; do if ! command -v "$cmd" >/dev/null 2>&1; then @@ -454,7 +454,7 @@ check_system_requirements() { return 1 fi done - + return 0 } @@ -467,7 +467,7 @@ resolve_string() { shift local __flags=$@ - echo $("${SCRIPTDIR}/parse_if.py" $__flags <<< "${__to_resolve}") + echo $("${SCRIPTDIR}/parse_if.py" $__flags <<<"${__to_resolve}") } # Enhanced string processing with validation @@ -475,26 +475,26 @@ resolve_string_safe() { local __to_resolve="$1" shift local __flags=("$@") - + if [[ -z "$__to_resolve" ]]; then report_error_enhanced 1 "Empty string provided for resolution" return 1 fi - + if [[ ! -f "${SCRIPTDIR}/parse_if.py" ]]; then report_error_enhanced 1 "Parser script not found" "${SCRIPTDIR}/parse_if.py" return 1 fi - + local result - result=$("${SCRIPTDIR}/parse_if.py" "${__flags[@]}" <<< "${__to_resolve}" 2>/dev/null) + result=$("${SCRIPTDIR}/parse_if.py" "${__flags[@]}" <<<"${__to_resolve}" 2>/dev/null) local exit_code=$? - + if [[ $exit_code -ne 0 ]]; then report_error_enhanced $exit_code "String resolution failed" "$__to_resolve" return $exit_code fi - + echo "$result" return 0 } @@ -511,7 +511,7 @@ check_command() { elif [ $# -gt 1 ]; then local __package=${2} fi - if $(command -v ${__command} > /dev/null 2>&1); then + if $(command -v ${__command} >/dev/null 2>&1); then echo "path to ${__command} is $(realpath $(command -v ${__command}))" else report_error "Cannot find ${__command}, please check if the package ${__package} is installed or in system search path" @@ -524,22 +524,22 @@ check_command_version() { local command_name="$1" local min_version="$2" local package_name="${3:-$command_name}" - + if ! command -v "$command_name" >/dev/null 2>&1; then report_error_enhanced 1 "Command not found: $command_name" "Package: $package_name" return 1 fi - + local command_path command_path=$(command -v "$command_name") echo "Found $command_name at: $(realpath "$command_path")" - + if [[ -n "$min_version" ]]; then # This is a placeholder for version checking logic # Different commands have different version output formats echo "Version check for $command_name (minimum: $min_version) - implement as needed" fi - + return 0 } @@ -547,7 +547,7 @@ check_command_version() { check_commands_batch() { local commands=("$@") local failed_commands=() - + for cmd in "${commands[@]}"; do if ! command -v "$cmd" >/dev/null 2>&1; then failed_commands+=("$cmd") @@ -555,12 +555,12 @@ check_commands_batch() { echo "✓ Found: $cmd at $(command -v "$cmd")" fi done - + if [[ ${#failed_commands[@]} -gt 0 ]]; then report_error_enhanced 1 "Missing commands" "$(printf '%s ' "${failed_commands[@]}")" return 1 fi - + return 0 } @@ -584,7 +584,7 @@ check_install() { elif [ $# -gt 1 ]; then local __package=${2} fi - if $(command -v ${__command} > /dev/null 2>&1); then + if $(command -v ${__command} >/dev/null 2>&1); then echo "$(basename ${__command}) is installed as $(command -v ${__command})" else report_error "cannot find ${__command}, please check if the package ${__package} has been installed correctly" @@ -637,7 +637,7 @@ check_lib() { check_gfortran_module() { local __module_name=$1 local __FC=${FC:-gfortran} - cat << EOF | $__FC -c -o /dev/null -xf95 -ffree-form - > /dev/null 2>&1 + cat </dev/null 2>&1 PROGRAM check_gfortran_module USE ${__module_name} IMPLICIT NONE @@ -653,7 +653,7 @@ check_gfortran_flag() { local __FC=${FC:-gfortran} # no need to do a full compilation, just -E -cpp would do for # checking flags - cat << EOF | $__FC -E -cpp $__flag -xf95 -ffree-form - > /dev/null 2>&1 + cat </dev/null 2>&1 PROGRAM test_code IMPLICIT NONE PRINT *, "PASS" @@ -668,7 +668,7 @@ check_gcc_flag() { local __CC=${CC:-gcc} # no need to do a full compilation, just -E -cpp would do for # checking flags - cat << EOF | $__CC -E -cpp $__flag -xc - > /dev/null 2>&1 + cat </dev/null 2>&1 #include int main() { printf("PASS\n"); @@ -683,7 +683,7 @@ check_gxx_flag() { local __CXX=${CXX:-g++} # no need to do a full compilation, just -E -cpp would do for # checking flags - cat << EOF | $__CXX -E -cpp $__flag -xc - > /dev/null 2>&1 + cat </dev/null 2>&1 #include int main() { printf("PASS\n"); @@ -781,19 +781,19 @@ append_path() { read_enable() { local __input_var="${1#*=}" case $__input_var in - "$1") - # if there is no "=" then treat as "yes" - echo "__TRUE__" - ;; - yes) - echo "__TRUE__" - ;; - no) - echo "__FALSE__" - ;; - *) - echo "__INVALID__" - ;; + "$1") + # if there is no "=" then treat as "yes" + echo "__TRUE__" + ;; + yes) + echo "__TRUE__" + ;; + no) + echo "__FALSE__" + ;; + *) + echo "__INVALID__" + ;; esac } @@ -801,26 +801,26 @@ read_enable() { read_with() { local __input_var="${1#--with*=}" case $__input_var in - "${1}") - # if there is no "=" then treat as "install" - if [ ${#} -gt 1 ]; then - echo "${2}" - else - echo "__INSTALL__" - fi - ;; - install) + "${1}") + # if there is no "=" then treat as "install" + if [ ${#} -gt 1 ]; then + echo "${2}" + else echo "__INSTALL__" - ;; - system) - echo "__SYSTEM__" - ;; - no) - echo "__DONTUSE__" - ;; - *) - echo "${__input_var//\~/$HOME}" - ;; + fi + ;; + install) + echo "__INSTALL__" + ;; + system) + echo "__SYSTEM__" + ;; + no) + echo "__DONTUSE__" + ;; + *) + echo "${__input_var//\~/$HOME}" + ;; esac } @@ -828,8 +828,8 @@ read_with() { parse_config_option() { local option="$1" local default_value="${2:-}" - local valid_values="${3:-}" # Space-separated list of valid values - + local valid_values="${3:-}" # Space-separated list of valid values + local parsed_value if [[ "$option" =~ ^--enable ]]; then parsed_value=$(read_enable "$option") @@ -838,7 +838,7 @@ parse_config_option() { else parsed_value="$option" fi - + # Validate against allowed values if provided if [[ -n "$valid_values" && "$parsed_value" != "__INVALID__" ]]; then local is_valid=false @@ -848,13 +848,13 @@ parse_config_option() { break fi done - + if [[ "$is_valid" == false ]]; then report_warning_enhanced "WARNING" "Invalid configuration value: $parsed_value" "Valid options: $valid_values" parsed_value="__INVALID__" fi fi - + echo "$parsed_value" } @@ -869,7 +869,7 @@ checksum() { local __shasum_command='sha256sum' # check if we have sha256sum command, Mac OS X does not have # sha256sum, but has an equivalent with shasum -a 256 - command -v "$__shasum_command" > /dev/null 2>&1 || + command -v "$__shasum_command" >/dev/null 2>&1 || __shasum_command="shasum -a 256" echo "$__sha256 $__filename" | ${__shasum_command} --check } @@ -878,36 +878,36 @@ checksum() { verify_file_integrity() { local filename="$1" local expected_hash="$2" - local hash_type="${3:-sha256}" # Default to SHA256 - + local hash_type="${3:-sha256}" # Default to SHA256 + if [[ ! -f "$filename" ]]; then report_error_enhanced 1 "File not found for integrity check" "$filename" return 1 fi - + local hash_command case "$hash_type" in - sha256) - hash_command="sha256sum" - command -v "$hash_command" >/dev/null 2>&1 || hash_command="shasum -a 256" - ;; - sha1) - hash_command="sha1sum" - command -v "$hash_command" >/dev/null 2>&1 || hash_command="shasum -a 1" - ;; - md5) - hash_command="md5sum" - command -v "$hash_command" >/dev/null 2>&1 || hash_command="md5" - ;; - *) - report_error_enhanced 1 "Unsupported hash type" "$hash_type" - return 1 - ;; + sha256) + hash_command="sha256sum" + command -v "$hash_command" >/dev/null 2>&1 || hash_command="shasum -a 256" + ;; + sha1) + hash_command="sha1sum" + command -v "$hash_command" >/dev/null 2>&1 || hash_command="shasum -a 1" + ;; + md5) + hash_command="md5sum" + command -v "$hash_command" >/dev/null 2>&1 || hash_command="md5" + ;; + *) + report_error_enhanced 1 "Unsupported hash type" "$hash_type" + return 1 + ;; esac - + local computed_hash computed_hash=$($hash_command "$filename" | cut -d' ' -f1) - + if [[ "$computed_hash" == "$expected_hash" ]]; then echo "✓ Integrity check passed for $filename ($hash_type)" return 0 @@ -930,52 +930,52 @@ download_pkg_from_url() { else DOWNLOADER_FLAGS="--quiet --show-progress" fi - + # Smart certificate validation strategy case "${DOWNLOAD_CERT_POLICY:-smart}" in - "strict") - echo "Downloading with strict certificate validation: $__url" - if ! wget ${DOWNLOADER_FLAGS} "$__url" -O "$__filename"; then - rm -f "$__filename" - report_error "failed to download $__url (strict certificate validation)" - recommend_offline_installation "$__filename" "$__url" - if [ "${PACK_RUN}" != "__TRUE__" ]; then - return 1 - fi + "strict") + echo "Downloading with strict certificate validation: $__url" + if ! wget ${DOWNLOADER_FLAGS} "$__url" -O "$__filename"; then + rm -f "$__filename" + report_error "failed to download $__url (strict certificate validation)" + recommend_offline_installation "$__filename" "$__url" + if [ "${PACK_RUN}" != "__TRUE__" ]; then + return 1 + fi + fi + ;; + "skip") + echo "Downloading with certificate validation disabled: $__url" + if ! wget ${DOWNLOADER_FLAGS} "$__url" -O "$__filename" --no-check-certificate; then + rm -f "$__filename" + report_error "failed to download $__url" + recommend_offline_installation "$__filename" "$__url" + if [ "${PACK_RUN}" != "__TRUE__" ]; then + return 1 fi - ;; - "skip") - echo "Downloading with certificate validation disabled: $__url" + fi + ;; + "smart" | *) + # Smart fallback: try with certificate validation first, then without + echo "Attempting secure download: $__url" + if wget ${DOWNLOADER_FLAGS} "$__url" -O "$__filename"; then + echo "Download successful with certificate validation" + else + echo "Certificate validation failed, retrying without certificate check..." if ! wget ${DOWNLOADER_FLAGS} "$__url" -O "$__filename" --no-check-certificate; then rm -f "$__filename" - report_error "failed to download $__url" + report_error "failed to download $__url (both secure and insecure attempts failed)" recommend_offline_installation "$__filename" "$__url" if [ "${PACK_RUN}" != "__TRUE__" ]; then return 1 fi - fi - ;; - "smart"|*) - # Smart fallback: try with certificate validation first, then without - echo "Attempting secure download: $__url" - if wget ${DOWNLOADER_FLAGS} "$__url" -O "$__filename"; then - echo "Download successful with certificate validation" else - echo "Certificate validation failed, retrying without certificate check..." - if ! wget ${DOWNLOADER_FLAGS} "$__url" -O "$__filename" --no-check-certificate; then - rm -f "$__filename" - report_error "failed to download $__url (both secure and insecure attempts failed)" - recommend_offline_installation "$__filename" "$__url" - if [ "${PACK_RUN}" != "__TRUE__" ]; then - return 1 - fi - else - echo "Download successful without certificate validation" - fi + echo "Download successful without certificate validation" fi - ;; + fi + ;; esac - + # checksum if checksum "$__filename" "$__sha256"; then echo "Checksum of $__filename OK" @@ -1014,10 +1014,10 @@ verify_checksums() { # check if we have sha256sum command, Mac OS X does not have # sha256sum, but has an equivalent with shasum -a 256 - command -v "$__shasum_command" > /dev/null 2>&1 || + command -v "$__shasum_command" >/dev/null 2>&1 || __shasum_command="shasum -a 256" - ${__shasum_command} --check "${__checksum_file}" > /dev/null 2>&1 + ${__shasum_command} --check "${__checksum_file}" >/dev/null 2>&1 } # write a checksum file $1 containing checksums for each given file $2, $3, ... (plus the $VERSION_FILE) @@ -1028,10 +1028,10 @@ write_checksums() { # check if we have sha256sum command, Mac OS X does not have # sha256sum, but has an equivalent with shasum -a 256 - command -v "$__shasum_command" > /dev/null 2>&1 || + command -v "$__shasum_command" >/dev/null 2>&1 || __shasum_command="shasum -a 256" - ${__shasum_command} "${VERSION_FILE}" "$@" > "${__checksum_file}" + ${__shasum_command} "${VERSION_FILE}" "$@" >"${__checksum_file}" } # generate a filtered toolchain.env @@ -1055,7 +1055,7 @@ write_toolchain_env() { unset DBUS_SESSION_BUS_ADDRESS export -p - ) > "${__installdir}/toolchain.env" + ) >"${__installdir}/toolchain.env" } # Write a setup file without containing flags unnecessay for building and running ABACUS @@ -1070,6 +1070,6 @@ filter_setup() { fi local filename=$(basename "$source_file") - echo "# ==================== Setup for ${filename#*_} ==================== #" >> "$target_file" - sed '/if[[:space:]]/,/^[[:space:]]*fi$/d' "$source_file" | grep -v -E '# For|# Other|with_|FLAGS|LIBS|INCLUDES' >> "$target_file" + echo "# ==================== Setup for ${filename#*_} ==================== #" >>"$target_file" + sed '/if[[:space:]]/,/^[[:space:]]*fi$/d' "$source_file" | grep -v -E '# For|# Other|with_|FLAGS|LIBS|INCLUDES' >>"$target_file" } diff --git a/toolchain/tests/test_installer_argument_failures.sh b/toolchain/tests/test_installer_argument_failures.sh index 0bdb1d85345..c87f59aed77 100755 --- a/toolchain/tests/test_installer_argument_failures.sh +++ b/toolchain/tests/test_installer_argument_failures.sh @@ -17,7 +17,7 @@ copy_toolchain() { while IFS= read -r -d '' entry; do name="${entry##*/}" case "$name" in - build|install) continue ;; + build | install) continue ;; esac cp -a "$entry" "${tmpdir}/toolchain/" done < <(find "${TOOLCHAIN_DIR}" -mindepth 1 -maxdepth 1 -print0) diff --git a/toolchain/toolchain_aocc-aocl.sh b/toolchain/toolchain_aocc-aocl.sh index 17e2cd1cfec..e433052e195 100755 --- a/toolchain/toolchain_aocc-aocl.sh +++ b/toolchain/toolchain_aocc-aocl.sh @@ -25,12 +25,12 @@ WITH_AOCL="system" MPI_MODE="openmpi" WITH_OPENMPI="install" WITH_MPICH="no" -WITH_4TH_OPENMPI="no" # Set to "yes" for OpenMPI v4, deprecated +WITH_4TH_OPENMPI="no" # Set to "yes" for OpenMPI v4, deprecated # Core Dependencies WITH_CMAKE="install" -WITH_SCALAPACK="system" # AOCL provides ScaLAPACK -WITH_FFTW="system" # AOCL provides FFTW +WITH_SCALAPACK="system" # AOCL provides ScaLAPACK +WITH_FFTW="system" # AOCL provides FFTW WITH_LIBXC="install" WITH_ELPA="install" @@ -48,7 +48,7 @@ WITH_LIBNPY="no" WITH_NEP="no" # AMD Compiler Options -WITH_FLANG="no" # Flang is not recommended in current stage +WITH_FLANG="no" # Flang is not recommended in current stage # ELPA-GPU Support (uncomment and modify as needed) # ENABLE_CUDA="yes" @@ -59,10 +59,10 @@ WITH_FLANG="no" # Flang is not recommended in current stage # Execution Mode Control # ============================================================================ # Dry-run mode: Show what would be done without actually executing -DRY_RUN_MODE="no" # Set to "yes" to enable dry-run mode +DRY_RUN_MODE="no" # Set to "yes" to enable dry-run mode # Pack-run mode: Only check and install required packages -PACK_RUN_MODE="no" # Set to "yes" to enable pack-run mode +PACK_RUN_MODE="no" # Set to "yes" to enable pack-run mode # ============================================================================ # Package Version Selection (main/alt versions) @@ -70,12 +70,12 @@ PACK_RUN_MODE="no" # Set to "yes" to enable pack-run mode # Choose between main (latest stable) and alt (alternative/legacy) versions # Refer to scripts/package_versions.sh for specific version numbers -CMAKE_VERSION="main" # main=3.31.7, alt=3.30.5 -OPENMPI_VERSION="main" # main=5.0.10, alt=4.1.8 -ELPA_VERSION="main" # main=2026.02.001, alt=2024.05.001 -LIBXC_VERSION="main" # main=7.0.0, alt=6.2.2 +CMAKE_VERSION="main" # main=3.31.7, alt=3.30.5 +OPENMPI_VERSION="main" # main=5.0.10, alt=4.1.8 +ELPA_VERSION="main" # main=2026.02.001, alt=2024.05.001 +LIBXC_VERSION="main" # main=7.0.0, alt=6.2.2 # Optional Libraries -LIBTORCH_VERSION="main" # main=2.1.2, alt=1.12.1 (use alt for older GLIBC) +LIBTORCH_VERSION="main" # main=2.1.2, alt=1.12.1 (use alt for older GLIBC) # Note: main(2.1.2) version of LibTorch need glibc > 2.27 # Note: alt(1.12.1) version of LibTorch cannot support DeePMD-Torch for DPA diff --git a/toolchain/toolchain_gcc-aocl.sh b/toolchain/toolchain_gcc-aocl.sh index 6ef8789665d..d066fc06bc7 100755 --- a/toolchain/toolchain_gcc-aocl.sh +++ b/toolchain/toolchain_gcc-aocl.sh @@ -24,13 +24,13 @@ WITH_AOCL="system" # MPI Implementation (OpenMPI recommended) MPI_MODE="openmpi" WITH_OPENMPI="install" -WITH_4TH_OPENMPI="no" # Set to "yes" for OpenMPI v4, deprecated +WITH_4TH_OPENMPI="no" # Set to "yes" for OpenMPI v4, deprecated WITH_MPICH="no" # Core Dependencies WITH_CMAKE="install" -WITH_SCALAPACK="system" # AOCL provides ScaLAPACK -WITH_FFTW="system" # AOCL provides FFTW +WITH_SCALAPACK="system" # AOCL provides ScaLAPACK +WITH_FFTW="system" # AOCL provides FFTW WITH_LIBXC="install" WITH_ELPA="install" @@ -56,10 +56,10 @@ WITH_NEP="no" # Execution Mode Control # ============================================================================ # Dry-run mode: Show what would be done without actually executing -DRY_RUN_MODE="no" # Set to "yes" to enable dry-run mode +DRY_RUN_MODE="no" # Set to "yes" to enable dry-run mode # Pack-run mode: Only check and install required packages -PACK_RUN_MODE="no" # Set to "yes" to enable pack-run mode +PACK_RUN_MODE="no" # Set to "yes" to enable pack-run mode # ============================================================================ # Package Version Selection (main/alt versions) @@ -67,12 +67,12 @@ PACK_RUN_MODE="no" # Set to "yes" to enable pack-run mode # Choose between main (latest stable) and alt (alternative/legacy) versions # Refer to scripts/package_versions.sh for specific version numbers -CMAKE_VERSION="main" # main=3.31.7, alt=3.30.5 -OPENMPI_VERSION="main" # main=5.0.10, alt=4.1.8 -ELPA_VERSION="main" # main=2026.02.001, alt=2024.05.001 -LIBXC_VERSION="main" # main=7.0.0, alt=6.2.2 +CMAKE_VERSION="main" # main=3.31.7, alt=3.30.5 +OPENMPI_VERSION="main" # main=5.0.10, alt=4.1.8 +ELPA_VERSION="main" # main=2026.02.001, alt=2024.05.001 +LIBXC_VERSION="main" # main=7.0.0, alt=6.2.2 # Optional Libraries -LIBTORCH_VERSION="main" # main=2.1.2, alt=1.12.1 (use alt for older GLIBC) +LIBTORCH_VERSION="main" # main=2.1.2, alt=1.12.1 (use alt for older GLIBC) # Note: main(2.1.2) version of LibTorch need glibc > 2.27 # Note: alt(1.12.1) version of LibTorch cannot support DeePMD-Torch for DPA diff --git a/toolchain/toolchain_gcc-mkl.sh b/toolchain/toolchain_gcc-mkl.sh index a44bd5d710a..b9cc9fa3630 100755 --- a/toolchain/toolchain_gcc-mkl.sh +++ b/toolchain/toolchain_gcc-mkl.sh @@ -24,13 +24,13 @@ WITH_MKL="system" # MPI Implementation (OpenMPI recommended) MPI_MODE="openmpi" WITH_OPENMPI="install" -WITH_4TH_OPENMPI="no" # Set to "yes" for OpenMPI v4, deprecated +WITH_4TH_OPENMPI="no" # Set to "yes" for OpenMPI v4, deprecated WITH_MPICH="no" # Core Dependencies WITH_CMAKE="install" -WITH_SCALAPACK="system" # MKL provides ScaLAPACK -WITH_FFTW="system" # MKL provides FFTW +WITH_SCALAPACK="system" # MKL provides ScaLAPACK +WITH_FFTW="system" # MKL provides FFTW WITH_LIBXC="install" WITH_ELPA="install" @@ -59,10 +59,10 @@ WITH_DFTD4="install" # Execution Mode Control # ============================================================================ # Dry-run mode: Show what would be done without actually executing -DRY_RUN_MODE="no" # Set to "yes" to enable dry-run mode +DRY_RUN_MODE="no" # Set to "yes" to enable dry-run mode # Pack-run mode: Only check and install required packages -PACK_RUN_MODE="no" # Set to "yes" to enable pack-run mode +PACK_RUN_MODE="no" # Set to "yes" to enable pack-run mode # ============================================================================ # Package Version Selection (main/alt versions) @@ -70,12 +70,12 @@ PACK_RUN_MODE="no" # Set to "yes" to enable pack-run mode # Choose between main (latest stable) and alt (alternative/legacy) versions # Refer to scripts/package_versions.sh for specific version numbers -CMAKE_VERSION="main" # main=3.31.7, alt=3.30.5 -OPENMPI_VERSION="main" # main=5.0.10, alt=4.1.8 -ELPA_VERSION="main" # main=2026.02.001, alt=2024.05.001 -LIBXC_VERSION="main" # main=7.0.0, alt=6.2.2 +CMAKE_VERSION="main" # main=3.31.7, alt=3.30.5 +OPENMPI_VERSION="main" # main=5.0.10, alt=4.1.8 +ELPA_VERSION="main" # main=2026.02.001, alt=2024.05.001 +LIBXC_VERSION="main" # main=7.0.0, alt=6.2.2 # Optional Libraries -LIBTORCH_VERSION="main" # main=2.1.2, alt=1.12.1 (use alt for older GLIBC) +LIBTORCH_VERSION="main" # main=2.1.2, alt=1.12.1 (use alt for older GLIBC) # Note: main(2.1.2) version of LibTorch need glibc > 2.27 # Note: alt(1.12.1) version of LibTorch cannot support DeePMD-Torch for DPA diff --git a/toolchain/toolchain_gnu.sh b/toolchain/toolchain_gnu.sh index e4b6359afba..a9191d3d99d 100755 --- a/toolchain/toolchain_gnu.sh +++ b/toolchain/toolchain_gnu.sh @@ -25,7 +25,7 @@ WITH_OPENBLAS="install" # MPI Implementation (OpenMPI recommended) MPI_MODE="openmpi" WITH_OPENMPI="install" -WITH_4TH_OPENMPI="no" # Set to "yes" for OpenMPI v4, deprecated +WITH_4TH_OPENMPI="no" # Set to "yes" for OpenMPI v4, deprecated WITH_MPICH="no" # Core Dependencies @@ -60,10 +60,10 @@ WITH_DFTD4="install" # Execution Mode Control # ============================================================================ # Dry-run mode: Show what would be done without actually executing -DRY_RUN_MODE="no" # Set to "yes" to enable dry-run mode +DRY_RUN_MODE="no" # Set to "yes" to enable dry-run mode # Pack-run mode: Only check and install required packages -PACK_RUN_MODE="no" # Set to "yes" to enable pack-run mode +PACK_RUN_MODE="no" # Set to "yes" to enable pack-run mode # ============================================================================ # Package Version Selection (main/alt versions) @@ -71,15 +71,15 @@ PACK_RUN_MODE="no" # Set to "yes" to enable pack-run mode # Choose between main (latest stable) and alt (alternative/legacy) versions # Refer to scripts/package_versions.sh for specific version numbers -CMAKE_VERSION="main" # main=3.31.7, alt=3.30.5 -OPENMPI_VERSION="main" # main=5.0.10, alt=4.1.8 -MPICH_VERSION="main" # main=5.0.1, alt=4.3.2 -OPENBLAS_VERSION="main" # main=0.3.33, alt=0.3.30 -ELPA_VERSION="main" # main=2026.02.001, alt=2024.05.001 -LIBXC_VERSION="main" # main=7.0.0, alt=6.2.2 -SCALAPACK_VERSION="main" # main=2.2.3, alt=2.2.1 +CMAKE_VERSION="main" # main=3.31.7, alt=3.30.5 +OPENMPI_VERSION="main" # main=5.0.10, alt=4.1.8 +MPICH_VERSION="main" # main=5.0.1, alt=4.3.2 +OPENBLAS_VERSION="main" # main=0.3.33, alt=0.3.30 +ELPA_VERSION="main" # main=2026.02.001, alt=2024.05.001 +LIBXC_VERSION="main" # main=7.0.0, alt=6.2.2 +SCALAPACK_VERSION="main" # main=2.2.3, alt=2.2.1 # Optional Libraries -LIBTORCH_VERSION="main" # main=2.1.2, alt=1.12.1 (use alt for older GLIBC) +LIBTORCH_VERSION="main" # main=2.1.2, alt=1.12.1 (use alt for older GLIBC) # Note: main(2.1.2) version of LibTorch need glibc > 2.27 # Note: alt(1.12.1) version of LibTorch cannot support DeePMD-Torch for DPA diff --git a/toolchain/toolchain_intel.sh b/toolchain/toolchain_intel.sh index 4ef5166b55f..6f8009d69df 100755 --- a/toolchain/toolchain_intel.sh +++ b/toolchain/toolchain_intel.sh @@ -20,7 +20,7 @@ WITH_GCC="no" # Math Libraries (Intel MKL recommended) MATH_MODE="mkl" -WITH_MKL="system" # Use system MKL when MATH_MODE is mkl +WITH_MKL="system" # Use system MKL when MATH_MODE is mkl # MPI Implementation (Intel MPI recommended, but OpenMPI/MPICH also supported) MPI_MODE="intelmpi" @@ -30,8 +30,8 @@ WITH_MPICH="no" # Core Dependencies WITH_CMAKE="install" -WITH_SCALAPACK="no" # MKL provides ScaLAPACK -WITH_FFTW="no" # MKL provides FFTW interface +WITH_SCALAPACK="no" # MKL provides ScaLAPACK +WITH_FFTW="no" # MKL provides FFTW interface WITH_LIBXC="install" WITH_ELPA="install" @@ -60,29 +60,28 @@ WITH_DFTD4="install" # Execution Mode Control # ============================================================================ # Dry-run mode: Show what would be done without actually executing -DRY_RUN_MODE="no" # Set to "yes" to enable dry-run mode +DRY_RUN_MODE="no" # Set to "yes" to enable dry-run mode # Pack-run mode: Only check and install required packages -PACK_RUN_MODE="no" # Set to "yes" to enable pack-run mode +PACK_RUN_MODE="no" # Set to "yes" to enable pack-run mode # ============================================================================ # Intel Compiler and MPI Options # ============================================================================ # Intel Compiler Version Selection -WITH_INTEL_CLASSIC="no" # Set to "yes" to use classic Intel compilers (icc/icpc/ifort) - # Set to "no" to use new Intel compilers (icx/icpx/ifx) - # Classic compilers needed for AMD-CPU or GPU-version +WITH_INTEL_CLASSIC="no" # Set to "yes" to use classic Intel compilers (icc/icpc/ifort) +# Set to "no" to use new Intel compilers (icx/icpx/ifx) +# Classic compilers needed for AMD-CPU or GPU-version -WITH_IFX="yes" # Set to "yes" to use new Fortran compiler ifx (default) - # Set to "no" to use traditional ifort - # Only applies when WITH_INTEL_CLASSIC="no" - -# Intel MPI Version Selection -INTELMPI_CLASSIC="no" # Set to "yes" to use classic Intel MPI wrappers (mpiicc/mpiicpc/mpiifort) - # Set to "no" to use new Intel MPI wrappers (mpiicx/mpiicpx/mpiifx) - # Should match WITH_INTEL_CLASSIC setting for consistency - # Classic wrappers recommended for older Intel OneAPI versions +WITH_IFX="yes" # Set to "yes" to use new Fortran compiler ifx (default) +# Set to "no" to use traditional ifort +# Only applies when WITH_INTEL_CLASSIC="no" +# Intel MPI Version Selection +INTELMPI_CLASSIC="no" # Set to "yes" to use classic Intel MPI wrappers (mpiicc/mpiicpc/mpiifort) +# Set to "no" to use new Intel MPI wrappers (mpiicx/mpiicpx/mpiifx) +# Should match WITH_INTEL_CLASSIC setting for consistency +# Classic wrappers recommended for older Intel OneAPI versions # ============================================================================ # Package Version Selection (main/alt versions) @@ -90,11 +89,11 @@ INTELMPI_CLASSIC="no" # Set to "yes" to use classic Intel MPI wrappers (mpiicc # Choose between main (latest stable) and alt (alternative/legacy) versions # Refer to scripts/package_versions.sh for specific version numbers -CMAKE_VERSION="main" # main=3.31.7, alt=3.30.5 -ELPA_VERSION="alt" # main=2026.02.001, alt=2024.05.001 for intel oneapi<2024.2 -LIBXC_VERSION="main" # main=7.0.0, alt=6.2.2 +CMAKE_VERSION="main" # main=3.31.7, alt=3.30.5 +ELPA_VERSION="alt" # main=2026.02.001, alt=2024.05.001 for intel oneapi<2024.2 +LIBXC_VERSION="main" # main=7.0.0, alt=6.2.2 # Optional Libraries -LIBTORCH_VERSION="main" # main=2.1.2, alt=1.12.1 (use alt for older GLIBC) +LIBTORCH_VERSION="main" # main=2.1.2, alt=1.12.1 (use alt for older GLIBC) # Note: main(2.1.2) version of LibTorch need glibc > 2.27 # Note: alt(1.12.1) version of LibTorch cannot support DeePMD-Torch for DPA diff --git a/toolchain/toolchain_windows.sh b/toolchain/toolchain_windows.sh index 7fcc1a88cdb..2fc9389647d 100644 --- a/toolchain/toolchain_windows.sh +++ b/toolchain/toolchain_windows.sh @@ -17,21 +17,21 @@ # ./build_abacus_windows.sh if ! command -v pacman >/dev/null 2>&1; then - echo "ERROR: pacman not found. Run this inside an MSYS2 shell (https://www.msys2.org)." - exit 1 + echo "ERROR: pacman not found. Run this inside an MSYS2 shell (https://www.msys2.org)." + exit 1 fi echo "[*] Installing MinGW-w64 build prerequisites via pacman ..." pacman -S --needed --noconfirm \ - mingw-w64-x86_64-gcc \ - mingw-w64-x86_64-gcc-fortran \ - mingw-w64-x86_64-cmake \ - mingw-w64-x86_64-ninja \ - mingw-w64-x86_64-openblas \ - mingw-w64-x86_64-fftw \ - mingw-w64-x86_64-cereal \ - mingw-w64-x86_64-msmpi \ - mingw-w64-x86_64-scalapack + mingw-w64-x86_64-gcc \ + mingw-w64-x86_64-gcc-fortran \ + mingw-w64-x86_64-cmake \ + mingw-w64-x86_64-ninja \ + mingw-w64-x86_64-openblas \ + mingw-w64-x86_64-fftw \ + mingw-w64-x86_64-cereal \ + mingw-w64-x86_64-msmpi \ + mingw-w64-x86_64-scalapack # Notes: # * cereal : header-only serialization, required by the LCAO build. @@ -52,7 +52,7 @@ pacman -S --needed --noconfirm bc TOOL=$(cd "$(dirname "$0")" && pwd) INSTALL_DIR="$TOOL/install" mkdir -p "$INSTALL_DIR" -cat > "$INSTALL_DIR/setup" <<'EOF' +cat >"$INSTALL_DIR/setup" <<'EOF' # Native Windows (MSYS2/MinGW-w64) prerequisites live under /mingw64. export MINGW_PREFIX="${MINGW_PREFIX:-/mingw64}" export OPENBLAS_ROOT="$MINGW_PREFIX" # OpenBLAS provides BLAS *and* LAPACK From 990c7b5e0ebec04ba698fa67afe4997b2423c8ab Mon Sep 17 00:00:00 2001 From: SY Wang Date: Thu, 22 Oct 2026 19:12:42 +0800 Subject: [PATCH 2/4] Toolchain: CMake arguments in Linux build scripts shfmt breaks the bash logic when combined with `\` and comments --- toolchain/build_abacus_aocc-aocl.sh | 48 +++++++++++++++++------------ toolchain/build_abacus_gcc-aocl.sh | 46 +++++++++++++++------------ toolchain/build_abacus_gcc-mkl.sh | 46 +++++++++++++++------------ toolchain/build_abacus_gnu.sh | 48 +++++++++++++++++------------ toolchain/build_abacus_intel.sh | 46 +++++++++++++++------------ toolchain/build_abacus_windows.sh | 0 6 files changed, 137 insertions(+), 97 deletions(-) mode change 100644 => 100755 toolchain/build_abacus_windows.sh diff --git a/toolchain/build_abacus_aocc-aocl.sh b/toolchain/build_abacus_aocc-aocl.sh index da6f2fff5e7..0434db92995 100755 --- a/toolchain/build_abacus_aocc-aocl.sh +++ b/toolchain/build_abacus_aocc-aocl.sh @@ -60,26 +60,34 @@ done # if clang++ have problem, switch back to g++ -cmake -B $BUILD_DIR -DCMAKE_INSTALL_PREFIX=$PREFIX \ - -DCMAKE_CXX_COMPILER=clang++ \ - -DMPI_CXX_COMPILER=mpicxx \ - -DLAPACK_DIR=$LAPACK \ - -DSCALAPACK_DIR=$SCALAPACK \ - -DFFTW3_DIR=$FFTW3 \ - -DCEREAL_INCLUDE_DIR=$CEREAL \ - -DENABLE_LCAO=ON \ - -DENABLE_LIBXC=ON \ - -DENABLE_OPENMP=ON \ - -DENABLE_ELPA=ON \ - -DENABLE_JSON=ON \ - -DENABLE_LIBRI=ON \ - -DLIBRI_DIR=$LIBRI \ - -DLIBCOMM_DIR=$LIBCOMM \ - -DUSE_CUDA=$USE_CUDA# -DTorch_DIR=$LIBTORCH# -DENABLE_MLALGO=1 # -DNEP_DIR=$NEP_DIR \ -# -DDeePMD_DIR=$DEEPMD \ -# -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc \ -# -Dlibnpy_INCLUDE_DIR=$LIBNPY \ -# -DENABLE_CUSOLVERMP=ON \ +cmake_args=( + -B "$BUILD_DIR" + -DCMAKE_INSTALL_PREFIX="$PREFIX" + -DCMAKE_CXX_COMPILER=clang++ + -DMPI_CXX_COMPILER=mpicxx + -DLAPACK_DIR="$LAPACK" + -DSCALAPACK_DIR="$SCALAPACK" + -DFFTW3_DIR="$FFTW3" + -DCEREAL_INCLUDE_DIR="$CEREAL" + -DENABLE_LCAO=ON + -DENABLE_LIBXC=ON + -DENABLE_OPENMP=ON + -DENABLE_ELPA=ON + -DENABLE_JSON=ON + -DENABLE_LIBRI=ON + -DLIBRI_DIR="$LIBRI" + -DLIBCOMM_DIR="$LIBCOMM" + -DUSE_CUDA="$USE_CUDA" + # -DNEP_DIR="$NEP_DIR" + # -DTorch_DIR="$LIBTORCH" + # -DDeePMD_DIR="$DEEPMD" + # -DENABLE_MLALGO=1 + # -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc + # -Dlibnpy_INCLUDE_DIR="$LIBNPY" + # -DENABLE_CUSOLVERMP=ON +) + +cmake "${cmake_args[@]}" cmake --build $BUILD_DIR --target install -j "${NUM_JOBS}" diff --git a/toolchain/build_abacus_gcc-aocl.sh b/toolchain/build_abacus_gcc-aocl.sh index dd58930dabb..33ecac03adc 100755 --- a/toolchain/build_abacus_gcc-aocl.sh +++ b/toolchain/build_abacus_gcc-aocl.sh @@ -57,25 +57,33 @@ while [[ $# -gt 0 ]]; do esac done -cmake -B $BUILD_DIR -DCMAKE_INSTALL_PREFIX=$PREFIX \ - -DCMAKE_CXX_COMPILER=g++ \ - -DMPI_CXX_COMPILER=mpicxx \ - -DLAPACK_DIR=$LAPACK \ - -DSCALAPACK_DIR=$SCALAPACK \ - -DFFTW3_DIR=$FFTW3 \ - -DENABLE_LCAO=ON \ - -DENABLE_LIBXC=ON \ - -DENABLE_OPENMP=ON \ - -DENABLE_ELPA=ON \ - -DENABLE_JSON=ON \ - -DENABLE_LIBRI=ON \ - -DLIBRI_DIR=$LIBRI \ - -DLIBCOMM_DIR=$LIBCOMM \ - -DUSE_CUDA=$USE_CUDA# -DTorch_DIR=$LIBTORCH# -DENABLE_MLALGO=1 # -DNEP_DIR=$NEP_DIR \ -# -DDeePMD_DIR=$DEEPMD \ -# -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc \ -# -Dlibnpy_INCLUDE_DIR=$LIBNPY \ -# -DENABLE_CUSOLVERMP=ON \ +cmake_args=( + -B "$BUILD_DIR" + -DCMAKE_INSTALL_PREFIX="$PREFIX" + -DCMAKE_CXX_COMPILER=g++ + -DMPI_CXX_COMPILER=mpicxx + -DLAPACK_DIR="$LAPACK" + -DSCALAPACK_DIR="$SCALAPACK" + -DFFTW3_DIR="$FFTW3" + -DENABLE_LCAO=ON + -DENABLE_LIBXC=ON + -DENABLE_OPENMP=ON + -DENABLE_ELPA=ON + -DENABLE_JSON=ON + -DENABLE_LIBRI=ON + -DLIBRI_DIR="$LIBRI" + -DLIBCOMM_DIR="$LIBCOMM" + -DUSE_CUDA="$USE_CUDA" + # -DNEP_DIR="$NEP_DIR" + # -DTorch_DIR="$LIBTORCH" + # -DDeePMD_DIR="$DEEPMD" + # -DENABLE_MLALGO=1 + # -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc + # -Dlibnpy_INCLUDE_DIR="$LIBNPY" + # -DENABLE_CUSOLVERMP=ON +) + +cmake "${cmake_args[@]}" cmake --build $BUILD_DIR --target install -j "${NUM_JOBS}" diff --git a/toolchain/build_abacus_gcc-mkl.sh b/toolchain/build_abacus_gcc-mkl.sh index 7d60d80e2ba..5784fc4cca1 100755 --- a/toolchain/build_abacus_gcc-mkl.sh +++ b/toolchain/build_abacus_gcc-mkl.sh @@ -54,25 +54,33 @@ while [[ $# -gt 0 ]]; do esac done -cmake -B $BUILD_DIR -DCMAKE_INSTALL_PREFIX=$PREFIX \ - -DCMAKE_CXX_COMPILER=g++ \ - -DMPI_CXX_COMPILER=mpicxx \ - -DMKLROOT=$MKLROOT \ - -DENABLE_FLOAT_FFTW=ON \ - -DENABLE_LCAO=ON \ - -DENABLE_LIBXC=ON \ - -DENABLE_OPENMP=ON \ - -DENABLE_ELPA=ON \ - -DENABLE_DFTD4=ON \ - -DENABLE_JSON=ON \ - -DENABLE_LIBRI=ON \ - -DLIBRI_DIR=$LIBRI \ - -DLIBCOMM_DIR=$LIBCOMM \ - -DUSE_CUDA=$USE_CUDA# -DTorch_DIR=$LIBTORCH# -DENABLE_MLALGO=1 # -DNEP_DIR=$NEP_DIR \ -# -DDeePMD_DIR=$DEEPMD \ -# -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc \ -# -Dlibnpy_INCLUDE_DIR=$LIBNPY \ -# -DENABLE_CUSOLVERMP=ON \ +cmake_args=( + -B "$BUILD_DIR" + -DCMAKE_INSTALL_PREFIX="$PREFIX" + -DCMAKE_CXX_COMPILER=g++ + -DMPI_CXX_COMPILER=mpicxx + -DMKLROOT="$MKLROOT" + -DENABLE_FLOAT_FFTW=ON + -DENABLE_LCAO=ON + -DENABLE_LIBXC=ON + -DENABLE_OPENMP=ON + -DENABLE_ELPA=ON + -DENABLE_DFTD4=ON + -DENABLE_JSON=ON + -DENABLE_LIBRI=ON + -DLIBRI_DIR="$LIBRI" + -DLIBCOMM_DIR="$LIBCOMM" + -DUSE_CUDA="$USE_CUDA" + # -DNEP_DIR="$NEP_DIR" + # -DTorch_DIR="$LIBTORCH" + # -DDeePMD_DIR="$DEEPMD" + # -DENABLE_MLALGO=1 + # -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc + # -Dlibnpy_INCLUDE_DIR="$LIBNPY" + # -DENABLE_CUSOLVERMP=ON +) + +cmake "${cmake_args[@]}" cmake --build $BUILD_DIR --target install -j "${NUM_JOBS}" diff --git a/toolchain/build_abacus_gnu.sh b/toolchain/build_abacus_gnu.sh index 4999a891365..b54689dc0ae 100755 --- a/toolchain/build_abacus_gnu.sh +++ b/toolchain/build_abacus_gnu.sh @@ -55,26 +55,34 @@ while [[ $# -gt 0 ]]; do esac done -cmake -B $BUILD_DIR -DCMAKE_INSTALL_PREFIX=$PREFIX \ - -DCMAKE_CXX_COMPILER=g++ \ - -DMPI_CXX_COMPILER=mpicxx \ - -DLAPACK_DIR=$LAPACK \ - -DSCALAPACK_DIR=$SCALAPACK \ - -DFFTW3_DIR=$FFTW3 \ - -DENABLE_LCAO=ON \ - -DENABLE_LIBXC=ON \ - -DENABLE_OPENMP=ON \ - -DENABLE_ELPA=ON \ - -DENABLE_DFTD4=ON \ - -DENABLE_JSON=ON \ - -DENABLE_LIBRI=ON \ - -DLIBRI_DIR=$LIBRI \ - -DLIBCOMM_DIR=$LIBCOMM \ - -DUSE_CUDA=$USE_CUDA# -DTorch_DIR=$LIBTORCH# -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc # -DNEP_DIR=$NEP_DIR \ -# -DDeePMD_DIR=$DEEPMD \ -# -DENABLE_MLALGO=1 \ -# -Dlibnpy_INCLUDE_DIR=$LIBNPY \ -# -DENABLE_CUSOLVERMP=ON \ +cmake_args=( + -B "$BUILD_DIR" + -DCMAKE_INSTALL_PREFIX="$PREFIX" + -DCMAKE_CXX_COMPILER=g++ + -DMPI_CXX_COMPILER=mpicxx + -DLAPACK_DIR="$LAPACK" + -DSCALAPACK_DIR="$SCALAPACK" + -DFFTW3_DIR="$FFTW3" + -DENABLE_LCAO=ON + -DENABLE_LIBXC=ON + -DENABLE_OPENMP=ON + -DENABLE_ELPA=ON + -DENABLE_DFTD4=ON + -DENABLE_JSON=ON + -DENABLE_LIBRI=ON + -DLIBRI_DIR="$LIBRI" + -DLIBCOMM_DIR="$LIBCOMM" + -DUSE_CUDA="$USE_CUDA" + # -DNEP_DIR="$NEP_DIR" + # -DTorch_DIR="$LIBTORCH" + # -DDeePMD_DIR="$DEEPMD" + # -DENABLE_MLALGO=1 + # -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc + # -Dlibnpy_INCLUDE_DIR="$LIBNPY" + # -DENABLE_CUSOLVERMP=ON +) + +cmake "${cmake_args[@]}" cmake --build $BUILD_DIR --target install -j "${NUM_JOBS}" diff --git a/toolchain/build_abacus_intel.sh b/toolchain/build_abacus_intel.sh index 0daeebbcbf4..f7d9399e55e 100755 --- a/toolchain/build_abacus_intel.sh +++ b/toolchain/build_abacus_intel.sh @@ -55,25 +55,33 @@ while [[ $# -gt 0 ]]; do done # Notice: if you are compiling with AMD-CPU or GPU-version ABACUS, then `icpc` and `mpiicpc` compilers are needed -cmake -B $BUILD_DIR -DCMAKE_INSTALL_PREFIX=$PREFIX \ - -DCMAKE_CXX_COMPILER=icpx \ - -DMPI_CXX_COMPILER=mpiicpx \ - -DMKLROOT=$MKLROOT \ - -DENABLE_FLOAT_FFTW=ON \ - -DENABLE_LCAO=ON \ - -DENABLE_LIBXC=ON \ - -DENABLE_OPENMP=ON \ - -DENABLE_ELPA=ON \ - -DENABLE_DFTD4=ON \ - -DENABLE_JSON=ON \ - -DENABLE_LIBRI=ON \ - -DLIBRI_DIR=$LIBRI \ - -DLIBCOMM_DIR=$LIBCOMM \ - -DUSE_CUDA=$USE_CUDA# -DTorch_DIR=$LIBTORCH# -DENABLE_MLALGO=1 # -DNEP_DIR=$NEP_DIR \ -# -DDeePMD_DIR=$DEEPMD \ -# -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc \ -# -Dlibnpy_INCLUDE_DIR=$LIBNPY \ -# -DENABLE_CUSOLVERMP=ON \ +cmake_args=( + -B "$BUILD_DIR" + -DCMAKE_INSTALL_PREFIX="$PREFIX" + -DCMAKE_CXX_COMPILER=icpx + -DMPI_CXX_COMPILER=mpiicpx + -DMKLROOT="$MKLROOT" + -DENABLE_FLOAT_FFTW=ON + -DENABLE_LCAO=ON + -DENABLE_LIBXC=ON + -DENABLE_OPENMP=ON + -DENABLE_ELPA=ON + -DENABLE_DFTD4=ON + -DENABLE_JSON=ON + -DENABLE_LIBRI=ON + -DLIBRI_DIR="$LIBRI" + -DLIBCOMM_DIR="$LIBCOMM" + -DUSE_CUDA="$USE_CUDA" + # -DNEP_DIR="$NEP_DIR" + # -DTorch_DIR="$LIBTORCH" + # -DDeePMD_DIR="$DEEPMD" + # -DENABLE_MLALGO=1 + # -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc + # -Dlibnpy_INCLUDE_DIR="$LIBNPY" + # -DENABLE_CUSOLVERMP=ON +) + +cmake "${cmake_args[@]}" cmake --build $BUILD_DIR --target install -j "${NUM_JOBS}" diff --git a/toolchain/build_abacus_windows.sh b/toolchain/build_abacus_windows.sh old mode 100644 new mode 100755 From c93778979230ae8338c6ac956be694bb2b05ba54 Mon Sep 17 00:00:00 2001 From: SY Wang Date: Thu, 22 Oct 2026 19:19:54 +0800 Subject: [PATCH 3/4] Use quote vars --- toolchain/build_abacus_aocc-aocl.sh | 70 ++++++++++++++--------------- toolchain/build_abacus_gcc-aocl.sh | 66 +++++++++++++-------------- toolchain/build_abacus_gcc-mkl.sh | 56 +++++++++++------------ toolchain/build_abacus_gnu.sh | 66 +++++++++++++-------------- toolchain/build_abacus_intel.sh | 56 +++++++++++------------ 5 files changed, 157 insertions(+), 157 deletions(-) diff --git a/toolchain/build_abacus_aocc-aocl.sh b/toolchain/build_abacus_aocc-aocl.sh index 0434db92995..528f22b97fd 100755 --- a/toolchain/build_abacus_aocc-aocl.sh +++ b/toolchain/build_abacus_aocc-aocl.sh @@ -12,33 +12,33 @@ ABACUS_DIR=.. TOOL=$(pwd) -INSTALL_DIR=$TOOL/install -source $INSTALL_DIR/setup -cd $ABACUS_DIR +INSTALL_DIR="${TOOL}/install" +source "${INSTALL_DIR}/setup" +cd "${ABACUS_DIR}" ABACUS_DIR=$(pwd) #AOCLhome=/opt/aocl-linux-aocc-5.0.0/5.0.0/aocl/ # user should specify this parameter to the aocl installation path BUILD_DIR=build_abacus_aocc_aocl -rm -rf $BUILD_DIR +rm -rf "${BUILD_DIR}" -PREFIX=$ABACUS_DIR -CEREAL=${CEREAL_ROOT}/include -LAPACK=$AOCLhome/lib -SCALAPACK=$AOCLhome/lib -FFTW3=$AOCLhome -LIBRI=${LIBRI_ROOT} -LIBCOMM=${LIBCOMM_ROOT} +PREFIX="${ABACUS_DIR}" +CEREAL="${CEREAL_ROOT}/include" +LAPACK="${AOCLhome}/lib" +SCALAPACK="${AOCLhome}/lib" +FFTW3="${AOCLhome}" +LIBRI="${LIBRI_ROOT}" +LIBCOMM="${LIBCOMM_ROOT}" USE_CUDA=OFF # set ON to enable gpu-abacus -# NEP_DIR=$INSTALL_DIR/NEP_CPU-main -# LIBTORCH=$INSTALL_DIR/libtorch-2.1.2/share/cmake/Torch -# LIBNPY=$INSTALL_DIR/libnpy-1.0.1/include -# DEEPMD=$HOME/apps/anaconda3/envs/deepmd +# NEP_DIR="${INSTALL_DIR}/NEP_CPU-main" +# LIBTORCH="${INSTALL_DIR}/libtorch-2.1.2/share/cmake/Torch" +# LIBNPY="${INSTALL_DIR}/libnpy-1.0.1/include" +# DEEPMD="${HOME}/apps/anaconda3/envs/deepmd" NUM_JOBS="$(nproc)" while [[ $# -gt 0 ]]; do - case $1 in + case "${1}" in -j) - if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then + if [[ -n "${2}" && "${2}" =~ ^[0-9]+$ ]]; then NUM_JOBS="${2}" shift 2 else @@ -51,8 +51,8 @@ while [[ $# -gt 0 ]]; do shift ;; *) - echo "ERROR: Unsupported argument: $1" >&2 - echo "Usage: $0 [-j N|-jN]" >&2 + echo "ERROR: Unsupported argument: ${1}" >&2 + echo "Usage: ${0} [-j N|-jN]" >&2 exit 1 ;; esac @@ -61,40 +61,40 @@ done # if clang++ have problem, switch back to g++ cmake_args=( - -B "$BUILD_DIR" - -DCMAKE_INSTALL_PREFIX="$PREFIX" + -B "${BUILD_DIR}" + -DCMAKE_INSTALL_PREFIX="${PREFIX}" -DCMAKE_CXX_COMPILER=clang++ -DMPI_CXX_COMPILER=mpicxx - -DLAPACK_DIR="$LAPACK" - -DSCALAPACK_DIR="$SCALAPACK" - -DFFTW3_DIR="$FFTW3" - -DCEREAL_INCLUDE_DIR="$CEREAL" + -DLAPACK_DIR="${LAPACK}" + -DSCALAPACK_DIR="${SCALAPACK}" + -DFFTW3_DIR="${FFTW3}" + -DCEREAL_INCLUDE_DIR="${CEREAL}" -DENABLE_LCAO=ON -DENABLE_LIBXC=ON -DENABLE_OPENMP=ON -DENABLE_ELPA=ON -DENABLE_JSON=ON -DENABLE_LIBRI=ON - -DLIBRI_DIR="$LIBRI" - -DLIBCOMM_DIR="$LIBCOMM" - -DUSE_CUDA="$USE_CUDA" - # -DNEP_DIR="$NEP_DIR" - # -DTorch_DIR="$LIBTORCH" - # -DDeePMD_DIR="$DEEPMD" + -DLIBRI_DIR="${LIBRI}" + -DLIBCOMM_DIR="${LIBCOMM}" + -DUSE_CUDA="${USE_CUDA}" + # -DNEP_DIR="${NEP_DIR}" + # -DTorch_DIR="${LIBTORCH}" + # -DDeePMD_DIR="${DEEPMD}" # -DENABLE_MLALGO=1 # -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc - # -Dlibnpy_INCLUDE_DIR="$LIBNPY" + # -Dlibnpy_INCLUDE_DIR="${LIBNPY}" # -DENABLE_CUSOLVERMP=ON ) cmake "${cmake_args[@]}" -cmake --build $BUILD_DIR --target install -j "${NUM_JOBS}" +cmake --build "${BUILD_DIR}" --target install -j "${NUM_JOBS}" # generate abacus_env.sh cat <"${TOOL}/abacus_env.sh" #!/bin/bash -source $INSTALL_DIR/setup +source "${INSTALL_DIR}/setup" export PATH="${PREFIX}/bin":\${PATH} EOF @@ -103,5 +103,5 @@ cat <&2 - echo "Usage: $0 [-j N|-jN]" >&2 + echo "ERROR: Unsupported argument: ${1}" >&2 + echo "Usage: ${0} [-j N|-jN]" >&2 exit 1 ;; esac done cmake_args=( - -B "$BUILD_DIR" - -DCMAKE_INSTALL_PREFIX="$PREFIX" + -B "${BUILD_DIR}" + -DCMAKE_INSTALL_PREFIX="${PREFIX}" -DCMAKE_CXX_COMPILER=g++ -DMPI_CXX_COMPILER=mpicxx - -DLAPACK_DIR="$LAPACK" - -DSCALAPACK_DIR="$SCALAPACK" - -DFFTW3_DIR="$FFTW3" + -DLAPACK_DIR="${LAPACK}" + -DSCALAPACK_DIR="${SCALAPACK}" + -DFFTW3_DIR="${FFTW3}" -DENABLE_LCAO=ON -DENABLE_LIBXC=ON -DENABLE_OPENMP=ON -DENABLE_ELPA=ON -DENABLE_JSON=ON -DENABLE_LIBRI=ON - -DLIBRI_DIR="$LIBRI" - -DLIBCOMM_DIR="$LIBCOMM" - -DUSE_CUDA="$USE_CUDA" - # -DNEP_DIR="$NEP_DIR" - # -DTorch_DIR="$LIBTORCH" - # -DDeePMD_DIR="$DEEPMD" + -DLIBRI_DIR="${LIBRI}" + -DLIBCOMM_DIR="${LIBCOMM}" + -DUSE_CUDA="${USE_CUDA}" + # -DNEP_DIR="${NEP_DIR}" + # -DTorch_DIR="${LIBTORCH}" + # -DDeePMD_DIR="${DEEPMD}" # -DENABLE_MLALGO=1 # -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc - # -Dlibnpy_INCLUDE_DIR="$LIBNPY" + # -Dlibnpy_INCLUDE_DIR="${LIBNPY}" # -DENABLE_CUSOLVERMP=ON ) cmake "${cmake_args[@]}" -cmake --build $BUILD_DIR --target install -j "${NUM_JOBS}" +cmake --build "${BUILD_DIR}" --target install -j "${NUM_JOBS}" # generate abacus_env.sh cat <"${TOOL}/abacus_env.sh" #!/bin/bash -source $INSTALL_DIR/setup +source "${INSTALL_DIR}/setup" export PATH="${PREFIX}/bin":\${PATH} EOF @@ -99,5 +99,5 @@ cat <&2 - echo "Usage: $0 [-j N|-jN]" >&2 + echo "ERROR: Unsupported argument: ${1}" >&2 + echo "Usage: ${0} [-j N|-jN]" >&2 exit 1 ;; esac done cmake_args=( - -B "$BUILD_DIR" - -DCMAKE_INSTALL_PREFIX="$PREFIX" + -B "${BUILD_DIR}" + -DCMAKE_INSTALL_PREFIX="${PREFIX}" -DCMAKE_CXX_COMPILER=g++ -DMPI_CXX_COMPILER=mpicxx - -DMKLROOT="$MKLROOT" + -DMKLROOT="${MKLROOT}" -DENABLE_FLOAT_FFTW=ON -DENABLE_LCAO=ON -DENABLE_LIBXC=ON @@ -68,26 +68,26 @@ cmake_args=( -DENABLE_DFTD4=ON -DENABLE_JSON=ON -DENABLE_LIBRI=ON - -DLIBRI_DIR="$LIBRI" - -DLIBCOMM_DIR="$LIBCOMM" - -DUSE_CUDA="$USE_CUDA" - # -DNEP_DIR="$NEP_DIR" - # -DTorch_DIR="$LIBTORCH" - # -DDeePMD_DIR="$DEEPMD" + -DLIBRI_DIR="${LIBRI}" + -DLIBCOMM_DIR="${LIBCOMM}" + -DUSE_CUDA="${USE_CUDA}" + # -DNEP_DIR="${NEP_DIR}" + # -DTorch_DIR="${LIBTORCH}" + # -DDeePMD_DIR="${DEEPMD}" # -DENABLE_MLALGO=1 # -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc - # -Dlibnpy_INCLUDE_DIR="$LIBNPY" + # -Dlibnpy_INCLUDE_DIR="${LIBNPY}" # -DENABLE_CUSOLVERMP=ON ) cmake "${cmake_args[@]}" -cmake --build $BUILD_DIR --target install -j "${NUM_JOBS}" +cmake --build "${BUILD_DIR}" --target install -j "${NUM_JOBS}" # generate abacus_env.sh cat <"${TOOL}/abacus_env.sh" #!/bin/bash -source $INSTALL_DIR/setup +source "${INSTALL_DIR}/setup" export PATH="${PREFIX}/bin":\${PATH} EOF @@ -96,5 +96,5 @@ cat <&2 - echo "Usage: $0 [-j N|-jN]" >&2 + echo "ERROR: Unsupported argument: ${1}" >&2 + echo "Usage: ${0} [-j N|-jN]" >&2 exit 1 ;; esac done cmake_args=( - -B "$BUILD_DIR" - -DCMAKE_INSTALL_PREFIX="$PREFIX" + -B "${BUILD_DIR}" + -DCMAKE_INSTALL_PREFIX="${PREFIX}" -DCMAKE_CXX_COMPILER=g++ -DMPI_CXX_COMPILER=mpicxx - -DLAPACK_DIR="$LAPACK" - -DSCALAPACK_DIR="$SCALAPACK" - -DFFTW3_DIR="$FFTW3" + -DLAPACK_DIR="${LAPACK}" + -DSCALAPACK_DIR="${SCALAPACK}" + -DFFTW3_DIR="${FFTW3}" -DENABLE_LCAO=ON -DENABLE_LIBXC=ON -DENABLE_OPENMP=ON @@ -70,26 +70,26 @@ cmake_args=( -DENABLE_DFTD4=ON -DENABLE_JSON=ON -DENABLE_LIBRI=ON - -DLIBRI_DIR="$LIBRI" - -DLIBCOMM_DIR="$LIBCOMM" - -DUSE_CUDA="$USE_CUDA" - # -DNEP_DIR="$NEP_DIR" - # -DTorch_DIR="$LIBTORCH" - # -DDeePMD_DIR="$DEEPMD" + -DLIBRI_DIR="${LIBRI}" + -DLIBCOMM_DIR="${LIBCOMM}" + -DUSE_CUDA="${USE_CUDA}" + # -DNEP_DIR="${NEP_DIR}" + # -DTorch_DIR="${LIBTORCH}" + # -DDeePMD_DIR="${DEEPMD}" # -DENABLE_MLALGO=1 # -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc - # -Dlibnpy_INCLUDE_DIR="$LIBNPY" + # -Dlibnpy_INCLUDE_DIR="${LIBNPY}" # -DENABLE_CUSOLVERMP=ON ) cmake "${cmake_args[@]}" -cmake --build $BUILD_DIR --target install -j "${NUM_JOBS}" +cmake --build "${BUILD_DIR}" --target install -j "${NUM_JOBS}" # generate abacus_env.sh cat <"${TOOL}/abacus_env.sh" #!/bin/bash -source $INSTALL_DIR/setup +source "${INSTALL_DIR}/setup" export PATH="${PREFIX}/bin":\${PATH} EOF @@ -98,5 +98,5 @@ cat <&2 - echo "Usage: $0 [-j N|-jN]" >&2 + echo "ERROR: Unsupported argument: ${1}" >&2 + echo "Usage: ${0} [-j N|-jN]" >&2 exit 1 ;; esac @@ -56,11 +56,11 @@ done # Notice: if you are compiling with AMD-CPU or GPU-version ABACUS, then `icpc` and `mpiicpc` compilers are needed cmake_args=( - -B "$BUILD_DIR" - -DCMAKE_INSTALL_PREFIX="$PREFIX" + -B "${BUILD_DIR}" + -DCMAKE_INSTALL_PREFIX="${PREFIX}" -DCMAKE_CXX_COMPILER=icpx -DMPI_CXX_COMPILER=mpiicpx - -DMKLROOT="$MKLROOT" + -DMKLROOT="${MKLROOT}" -DENABLE_FLOAT_FFTW=ON -DENABLE_LCAO=ON -DENABLE_LIBXC=ON @@ -69,26 +69,26 @@ cmake_args=( -DENABLE_DFTD4=ON -DENABLE_JSON=ON -DENABLE_LIBRI=ON - -DLIBRI_DIR="$LIBRI" - -DLIBCOMM_DIR="$LIBCOMM" - -DUSE_CUDA="$USE_CUDA" - # -DNEP_DIR="$NEP_DIR" - # -DTorch_DIR="$LIBTORCH" - # -DDeePMD_DIR="$DEEPMD" + -DLIBRI_DIR="${LIBRI}" + -DLIBCOMM_DIR="${LIBCOMM}" + -DUSE_CUDA="${USE_CUDA}" + # -DNEP_DIR="${NEP_DIR}" + # -DTorch_DIR="${LIBTORCH}" + # -DDeePMD_DIR="${DEEPMD}" # -DENABLE_MLALGO=1 # -DCMAKE_CUDA_COMPILER=/path/to/cuda/bin/nvcc - # -Dlibnpy_INCLUDE_DIR="$LIBNPY" + # -Dlibnpy_INCLUDE_DIR="${LIBNPY}" # -DENABLE_CUSOLVERMP=ON ) cmake "${cmake_args[@]}" -cmake --build $BUILD_DIR --target install -j "${NUM_JOBS}" +cmake --build "${BUILD_DIR}" --target install -j "${NUM_JOBS}" # generate abacus_env.sh cat <"${TOOL}/abacus_env.sh" #!/bin/bash -source $INSTALL_DIR/setup +source "${INSTALL_DIR}/setup" export PATH="${PREFIX}/bin":\${PATH} EOF @@ -97,5 +97,5 @@ cat < Date: Sat, 24 Oct 2026 04:16:11 +0800 Subject: [PATCH 4/4] Apply case indent --- .pre-commit-config.yaml | 2 +- toolchain/build_abacus_aocc-aocl.sh | 34 +- toolchain/build_abacus_gcc-aocl.sh | 34 +- toolchain/build_abacus_gcc-mkl.sh | 34 +- toolchain/build_abacus_gnu.sh | 34 +- toolchain/build_abacus_intel.sh | 34 +- toolchain/build_abacus_windows.sh | 34 +- toolchain/scripts/common_vars.sh | 24 +- toolchain/scripts/lib/config_manager.sh | 1260 ++++++++--------- toolchain/scripts/lib/package_manager.sh | 42 +- toolchain/scripts/lib/user_interface.sh | 462 +++--- toolchain/scripts/lib/version_helper.sh | 40 +- toolchain/scripts/package_versions.sh | 258 ++-- toolchain/scripts/stage0/install_amd.sh | 86 +- toolchain/scripts/stage0/install_cmake.sh | 128 +- toolchain/scripts/stage0/install_gcc.sh | 288 ++-- toolchain/scripts/stage0/install_intel.sh | 100 +- toolchain/scripts/stage1/install_intelmpi.sh | 124 +- toolchain/scripts/stage1/install_mpich.sh | 180 +-- toolchain/scripts/stage1/install_openmpi.sh | 192 +-- toolchain/scripts/stage2/install_aocl.sh | 68 +- toolchain/scripts/stage2/install_mathlibs.sh | 36 +- toolchain/scripts/stage2/install_mkl.sh | 110 +- toolchain/scripts/stage2/install_openblas.sh | 196 +-- toolchain/scripts/stage3/install_elpa.sh | 360 ++--- toolchain/scripts/stage3/install_fftw.sh | 148 +- toolchain/scripts/stage3/install_libxc.sh | 110 +- toolchain/scripts/stage3/install_scalapack.sh | 118 +- toolchain/scripts/stage4/install_cereal.sh | 134 +- toolchain/scripts/stage4/install_dftd4.sh | 104 +- toolchain/scripts/stage4/install_json.sh | 68 +- toolchain/scripts/stage4/install_libcomm.sh | 110 +- toolchain/scripts/stage4/install_libnpy.sh | 94 +- toolchain/scripts/stage4/install_libri.sh | 112 +- toolchain/scripts/stage4/install_libtorch.sh | 104 +- toolchain/scripts/stage4/install_nep.sh | 94 +- toolchain/scripts/tool_kit.sh | 160 +-- .../tests/test_installer_argument_failures.sh | 2 +- 38 files changed, 2759 insertions(+), 2759 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bcf107e8d1a..4bc17df66d0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -19,7 +19,7 @@ repos: rev: v3.14.1-1 hooks: - id: shfmt - args: [--write, --language-dialect=bash, --indent=2] + args: [--write, --language-dialect=bash, --indent=2, --case-indent] - repo: local hooks: - id: abacus-agent-governance diff --git a/toolchain/build_abacus_aocc-aocl.sh b/toolchain/build_abacus_aocc-aocl.sh index 528f22b97fd..63ebc888e4c 100755 --- a/toolchain/build_abacus_aocc-aocl.sh +++ b/toolchain/build_abacus_aocc-aocl.sh @@ -37,24 +37,24 @@ USE_CUDA=OFF # set ON to enable gpu-abacus NUM_JOBS="$(nproc)" while [[ $# -gt 0 ]]; do case "${1}" in - -j) - if [[ -n "${2}" && "${2}" =~ ^[0-9]+$ ]]; then - NUM_JOBS="${2}" - shift 2 - else - echo "ERROR: -j requires a number argument" + -j) + if [[ -n "${2}" && "${2}" =~ ^[0-9]+$ ]]; then + NUM_JOBS="${2}" + shift 2 + else + echo "ERROR: -j requires a number argument" + exit 1 + fi + ;; + -j[0-9]*) + NUM_JOBS="${1#-j}" + shift + ;; + *) + echo "ERROR: Unsupported argument: ${1}" >&2 + echo "Usage: ${0} [-j N|-jN]" >&2 exit 1 - fi - ;; - -j[0-9]*) - NUM_JOBS="${1#-j}" - shift - ;; - *) - echo "ERROR: Unsupported argument: ${1}" >&2 - echo "Usage: ${0} [-j N|-jN]" >&2 - exit 1 - ;; + ;; esac done diff --git a/toolchain/build_abacus_gcc-aocl.sh b/toolchain/build_abacus_gcc-aocl.sh index cd0f63ecf19..1cf7d43451b 100755 --- a/toolchain/build_abacus_gcc-aocl.sh +++ b/toolchain/build_abacus_gcc-aocl.sh @@ -36,24 +36,24 @@ USE_CUDA=OFF # set ON to enable gpu-abacus NUM_JOBS="$(nproc)" while [[ $# -gt 0 ]]; do case "${1}" in - -j) - if [[ -n "${2}" && "${2}" =~ ^[0-9]+$ ]]; then - NUM_JOBS="${2}" - shift 2 - else - echo "ERROR: -j requires a number argument" + -j) + if [[ -n "${2}" && "${2}" =~ ^[0-9]+$ ]]; then + NUM_JOBS="${2}" + shift 2 + else + echo "ERROR: -j requires a number argument" + exit 1 + fi + ;; + -j[0-9]*) + NUM_JOBS="${1#-j}" + shift + ;; + *) + echo "ERROR: Unsupported argument: ${1}" >&2 + echo "Usage: ${0} [-j N|-jN]" >&2 exit 1 - fi - ;; - -j[0-9]*) - NUM_JOBS="${1#-j}" - shift - ;; - *) - echo "ERROR: Unsupported argument: ${1}" >&2 - echo "Usage: ${0} [-j N|-jN]" >&2 - exit 1 - ;; + ;; esac done diff --git a/toolchain/build_abacus_gcc-mkl.sh b/toolchain/build_abacus_gcc-mkl.sh index 550a532411b..f57dfacdd97 100755 --- a/toolchain/build_abacus_gcc-mkl.sh +++ b/toolchain/build_abacus_gcc-mkl.sh @@ -33,24 +33,24 @@ USE_CUDA=OFF # set ON to enable gpu-abacus NUM_JOBS="$(nproc)" while [[ $# -gt 0 ]]; do case "${1}" in - -j) - if [[ -n "${2}" && "${2}" =~ ^[0-9]+$ ]]; then - NUM_JOBS="${2}" - shift 2 - else - echo "ERROR: -j requires a number argument" + -j) + if [[ -n "${2}" && "${2}" =~ ^[0-9]+$ ]]; then + NUM_JOBS="${2}" + shift 2 + else + echo "ERROR: -j requires a number argument" + exit 1 + fi + ;; + -j[0-9]*) + NUM_JOBS="${1#-j}" + shift + ;; + *) + echo "ERROR: Unsupported argument: ${1}" >&2 + echo "Usage: ${0} [-j N|-jN]" >&2 exit 1 - fi - ;; - -j[0-9]*) - NUM_JOBS="${1#-j}" - shift - ;; - *) - echo "ERROR: Unsupported argument: ${1}" >&2 - echo "Usage: ${0} [-j N|-jN]" >&2 - exit 1 - ;; + ;; esac done diff --git a/toolchain/build_abacus_gnu.sh b/toolchain/build_abacus_gnu.sh index 3be64874902..d01681d77a3 100755 --- a/toolchain/build_abacus_gnu.sh +++ b/toolchain/build_abacus_gnu.sh @@ -34,24 +34,24 @@ USE_CUDA=OFF # set ON to enable gpu-abacus NUM_JOBS="$(nproc)" while [[ $# -gt 0 ]]; do case "${1}" in - -j) - if [[ -n "${2}" && "${2}" =~ ^[0-9]+$ ]]; then - NUM_JOBS="${2}" - shift 2 - else - echo "ERROR: -j requires a number argument" + -j) + if [[ -n "${2}" && "${2}" =~ ^[0-9]+$ ]]; then + NUM_JOBS="${2}" + shift 2 + else + echo "ERROR: -j requires a number argument" + exit 1 + fi + ;; + -j[0-9]*) + NUM_JOBS="${1#-j}" + shift + ;; + *) + echo "ERROR: Unsupported argument: ${1}" >&2 + echo "Usage: ${0} [-j N|-jN]" >&2 exit 1 - fi - ;; - -j[0-9]*) - NUM_JOBS="${1#-j}" - shift - ;; - *) - echo "ERROR: Unsupported argument: ${1}" >&2 - echo "Usage: ${0} [-j N|-jN]" >&2 - exit 1 - ;; + ;; esac done diff --git a/toolchain/build_abacus_intel.sh b/toolchain/build_abacus_intel.sh index 4c072cb7377..40fa99492f8 100755 --- a/toolchain/build_abacus_intel.sh +++ b/toolchain/build_abacus_intel.sh @@ -33,24 +33,24 @@ USE_CUDA=OFF # set ON to enable gpu-abacus NUM_JOBS="$(nproc)" while [[ $# -gt 0 ]]; do case "${1}" in - -j) - if [[ -n "${2}" && "${2}" =~ ^[0-9]+$ ]]; then - NUM_JOBS="${2}" - shift 2 - else - echo "ERROR: -j requires a number argument" + -j) + if [[ -n "${2}" && "${2}" =~ ^[0-9]+$ ]]; then + NUM_JOBS="${2}" + shift 2 + else + echo "ERROR: -j requires a number argument" + exit 1 + fi + ;; + -j[0-9]*) + NUM_JOBS="${1#-j}" + shift + ;; + *) + echo "ERROR: Unsupported argument: ${1}" >&2 + echo "Usage: ${0} [-j N|-jN]" >&2 exit 1 - fi - ;; - -j[0-9]*) - NUM_JOBS="${1#-j}" - shift - ;; - *) - echo "ERROR: Unsupported argument: ${1}" >&2 - echo "Usage: ${0} [-j N|-jN]" >&2 - exit 1 - ;; + ;; esac done diff --git a/toolchain/build_abacus_windows.sh b/toolchain/build_abacus_windows.sh index c626efdd7c1..e8d277d085a 100755 --- a/toolchain/build_abacus_windows.sh +++ b/toolchain/build_abacus_windows.sh @@ -48,24 +48,24 @@ if [ -r /proc/meminfo ]; then fi while [[ $# -gt 0 ]]; do case $1 in - -j) - if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then - NUM_JOBS="${2}" - shift 2 - else - echo "ERROR: -j requires a number argument" + -j) + if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then + NUM_JOBS="${2}" + shift 2 + else + echo "ERROR: -j requires a number argument" + exit 1 + fi + ;; + -j[0-9]*) + NUM_JOBS="${1#-j}" + shift + ;; + *) + echo "ERROR: Unsupported argument: $1" >&2 + echo "Usage: $0 [-j N|-jN]" >&2 exit 1 - fi - ;; - -j[0-9]*) - NUM_JOBS="${1#-j}" - shift - ;; - *) - echo "ERROR: Unsupported argument: $1" >&2 - echo "Usage: $0 [-j N|-jN]" >&2 - exit 1 - ;; + ;; esac done echo "Building with -j ${NUM_JOBS} (override with -j N; lower it if cc1plus runs out of memory)." diff --git a/toolchain/scripts/common_vars.sh b/toolchain/scripts/common_vars.sh index b5b46037dce..303090aadca 100755 --- a/toolchain/scripts/common_vars.sh +++ b/toolchain/scripts/common_vars.sh @@ -16,18 +16,18 @@ VERSION_FILE=${VERSION_FILE:-"${SCRIPTDIR}/VERSION"} # host architecture SYSTEM_ARCH=${SYSTEM_ARCH:-"$(uname -m)"} case "${SYSTEM_ARCH}" in -x86_64 | amd64) - SYSTEM_ARCH="x86_64" - ;; -aarch64 | arm64) - SYSTEM_ARCH="arm64" - ;; -i?86) - SYSTEM_ARCH="i386" - ;; -*) - # Keep other architectures as reported by uname. - ;; + x86_64 | amd64) + SYSTEM_ARCH="x86_64" + ;; + aarch64 | arm64) + SYSTEM_ARCH="arm64" + ;; + i?86) + SYSTEM_ARCH="i386" + ;; + *) + # Keep other architectures as reported by uname. + ;; esac export SYSTEM_ARCH diff --git a/toolchain/scripts/lib/config_manager.sh b/toolchain/scripts/lib/config_manager.sh index 8a2fadcfe53..0b79f6b555d 100644 --- a/toolchain/scripts/lib/config_manager.sh +++ b/toolchain/scripts/lib/config_manager.sh @@ -71,111 +71,111 @@ config_load_from_file() { # Validate and store configuration case "$var_name" in - # Basic configuration - INSTALL_PREFIX | BUILD_PREFIX) - CONFIG_CACHE["$var_name"]="$var_value" - ;; - NPROCS) - if [[ "$var_value" =~ ^[0-9]+$ ]]; then - CONFIG_CACHE["NPROCS_OVERWRITE"]="$var_value" - else - echo "Warning: Invalid NPROCS value '$var_value' in config file line $line_num" - fi - ;; - - # Mode selections - MPI_MODE) - case "$var_value" in - mpich | openmpi | intelmpi | none) - CONFIG_CACHE["MPI_MODE"]="$var_value" - ;; - *) - echo "Warning: Invalid MPI_MODE value '$var_value' in config file line $line_num" - ;; - esac - ;; - MATH_MODE) - case "$var_value" in - mkl | aocl | openblas | none) - CONFIG_CACHE["MATH_MODE"]="$var_value" + # Basic configuration + INSTALL_PREFIX | BUILD_PREFIX) + CONFIG_CACHE["$var_name"]="$var_value" ;; - *) - echo "Warning: Invalid MATH_MODE value '$var_value' in config file line $line_num" + NPROCS) + if [[ "$var_value" =~ ^[0-9]+$ ]]; then + CONFIG_CACHE["NPROCS_OVERWRITE"]="$var_value" + else + echo "Warning: Invalid NPROCS value '$var_value' in config file line $line_num" + fi ;; - esac - ;; - # Package configurations - WITH_*) - local package_name=$(echo "${var_name#WITH_}" | tr '[:upper:]' '[:lower:]') - # Handle special case for 4th-openmpi (convert to OPENMPI_4TH) - if [[ "$package_name" == "4th-openmpi" ]]; then + # Mode selections + MPI_MODE) case "$var_value" in - yes | no | __DONTUSE__) - # Map __DONTUSE__ to "no" for OPENMPI_4TH - if [[ "$var_value" == "__DONTUSE__" ]]; then - CONFIG_CACHE["OPENMPI_4TH"]="no" - else - CONFIG_CACHE["OPENMPI_4TH"]="$var_value" - fi - ;; - *) - echo "Warning: Invalid value '$var_value' for WITH_4TH_OPENMPI in config file line $line_num" - ;; + mpich | openmpi | intelmpi | none) + CONFIG_CACHE["MPI_MODE"]="$var_value" + ;; + *) + echo "Warning: Invalid MPI_MODE value '$var_value' in config file line $line_num" + ;; esac - else + ;; + MATH_MODE) case "$var_value" in - __SYSTEM__ | __INSTALL__ | __DONTUSE__) - CONFIG_CACHE["with_${package_name}"]="$var_value" - ;; - *) - # Allow custom paths for some packages - CONFIG_CACHE["with_${package_name}"]="$var_value" - ;; + mkl | aocl | openblas | none) + CONFIG_CACHE["MATH_MODE"]="$var_value" + ;; + *) + echo "Warning: Invalid MATH_MODE value '$var_value' in config file line $line_num" + ;; esac - fi - ;; - - # Version strategy options (NEW) - VERSION_STRATEGY) - case "$var_value" in - main | alt) - CONFIG_CACHE["VERSION_STRATEGY"]="$var_value" ;; - *) - echo "Warning: Invalid VERSION_STRATEGY value '$var_value' in config file line $line_num. Valid options: main, alt" + + # Package configurations + WITH_*) + local package_name=$(echo "${var_name#WITH_}" | tr '[:upper:]' '[:lower:]') + # Handle special case for 4th-openmpi (convert to OPENMPI_4TH) + if [[ "$package_name" == "4th-openmpi" ]]; then + case "$var_value" in + yes | no | __DONTUSE__) + # Map __DONTUSE__ to "no" for OPENMPI_4TH + if [[ "$var_value" == "__DONTUSE__" ]]; then + CONFIG_CACHE["OPENMPI_4TH"]="no" + else + CONFIG_CACHE["OPENMPI_4TH"]="$var_value" + fi + ;; + *) + echo "Warning: Invalid value '$var_value' for WITH_4TH_OPENMPI in config file line $line_num" + ;; + esac + else + case "$var_value" in + __SYSTEM__ | __INSTALL__ | __DONTUSE__) + CONFIG_CACHE["with_${package_name}"]="$var_value" + ;; + *) + # Allow custom paths for some packages + CONFIG_CACHE["with_${package_name}"]="$var_value" + ;; + esac + fi ;; - esac - ;; - PACKAGE_VERSION_*) - # Extract package name from PACKAGE_VERSION_PACKAGENAME - local pkg_name="${var_name#PACKAGE_VERSION_}" - case "$var_value" in - main | alt) - CONFIG_CACHE["PACKAGE_VERSION_${pkg_name}"]="$var_value" + + # Version strategy options (NEW) + VERSION_STRATEGY) + case "$var_value" in + main | alt) + CONFIG_CACHE["VERSION_STRATEGY"]="$var_value" + ;; + *) + echo "Warning: Invalid VERSION_STRATEGY value '$var_value' in config file line $line_num. Valid options: main, alt" + ;; + esac ;; - *) - echo "Warning: Invalid package version value '$var_value' for $var_name in config file line $line_num. Valid options: main, alt" + PACKAGE_VERSION_*) + # Extract package name from PACKAGE_VERSION_PACKAGENAME + local pkg_name="${var_name#PACKAGE_VERSION_}" + case "$var_value" in + main | alt) + CONFIG_CACHE["PACKAGE_VERSION_${pkg_name}"]="$var_value" + ;; + *) + echo "Warning: Invalid package version value '$var_value' for $var_name in config file line $line_num. Valid options: main, alt" + ;; + esac ;; - esac - ;; - # Advanced options - # Not in use, leave it for future - DEBUG_MODE | VERBOSE_MODE | SKIP_SYSTEM_CHECKS | FORCE_REINSTALL) - case "$var_value" in - true | false) - CONFIG_CACHE["$var_name"]="$var_value" + # Advanced options + # Not in use, leave it for future + DEBUG_MODE | VERBOSE_MODE | SKIP_SYSTEM_CHECKS | FORCE_REINSTALL) + case "$var_value" in + true | false) + CONFIG_CACHE["$var_name"]="$var_value" + ;; + *) + echo "Warning: Invalid boolean value '$var_value' for $var_name in config file line $line_num" + ;; + esac ;; + *) - echo "Warning: Invalid boolean value '$var_value' for $var_name in config file line $line_num" + echo "Warning: Unknown configuration option '$var_name' in config file line $line_num" ;; - esac - ;; - - *) - echo "Warning: Unknown configuration option '$var_name' in config file line $line_num" - ;; esac elif [[ -n "$line" ]]; then echo "Warning: Invalid configuration syntax in config file line $line_num: $line" @@ -193,55 +193,55 @@ config_apply_modes_from_file() { # Apply MPI mode if set in config file (silent mode to avoid duplicate output) if [[ -n "${CONFIG_CACHE[MPI_MODE]}" ]]; then case "${CONFIG_CACHE[MPI_MODE]}" in - mpich) - CONFIG_CACHE["with_mpich"]="__INSTALL__" - CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" - ;; - openmpi) - CONFIG_CACHE["with_mpich"]="__DONTUSE__" - CONFIG_CACHE["with_openmpi"]="__INSTALL__" - CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" - ;; - intelmpi) - CONFIG_CACHE["with_mpich"]="__DONTUSE__" - CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - CONFIG_CACHE["with_intelmpi"]="__INSTALL__" - ;; - none) - CONFIG_CACHE["with_mpich"]="__DONTUSE__" - CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" - ;; + mpich) + CONFIG_CACHE["with_mpich"]="__INSTALL__" + CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" + ;; + openmpi) + CONFIG_CACHE["with_mpich"]="__DONTUSE__" + CONFIG_CACHE["with_openmpi"]="__INSTALL__" + CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" + ;; + intelmpi) + CONFIG_CACHE["with_mpich"]="__DONTUSE__" + CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + CONFIG_CACHE["with_intelmpi"]="__INSTALL__" + ;; + none) + CONFIG_CACHE["with_mpich"]="__DONTUSE__" + CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" + ;; esac fi # Apply Math mode if set in config file (silent mode to avoid duplicate output) if [[ -n "${CONFIG_CACHE[MATH_MODE]}" ]]; then case "${CONFIG_CACHE[MATH_MODE]}" in - mkl) - CONFIG_CACHE["with_mkl"]="__SYSTEM__" - CONFIG_CACHE["with_aocl"]="__DONTUSE__" - CONFIG_CACHE["with_openblas"]="__DONTUSE__" - # MKL provides FFTW and ScaLAPACK, so disable them (original logic) - CONFIG_CACHE["with_fftw"]="__DONTUSE__" - CONFIG_CACHE["with_scalapack"]="__DONTUSE__" - ;; - aocl) - CONFIG_CACHE["with_mkl"]="__DONTUSE__" - CONFIG_CACHE["with_aocl"]="__INSTALL__" - CONFIG_CACHE["with_openblas"]="__DONTUSE__" - ;; - openblas) - CONFIG_CACHE["with_mkl"]="__DONTUSE__" - CONFIG_CACHE["with_aocl"]="__DONTUSE__" - CONFIG_CACHE["with_openblas"]="__INSTALL__" - ;; - none) - CONFIG_CACHE["with_mkl"]="__DONTUSE__" - CONFIG_CACHE["with_aocl"]="__DONTUSE__" - CONFIG_CACHE["with_openblas"]="__DONTUSE__" - ;; + mkl) + CONFIG_CACHE["with_mkl"]="__SYSTEM__" + CONFIG_CACHE["with_aocl"]="__DONTUSE__" + CONFIG_CACHE["with_openblas"]="__DONTUSE__" + # MKL provides FFTW and ScaLAPACK, so disable them (original logic) + CONFIG_CACHE["with_fftw"]="__DONTUSE__" + CONFIG_CACHE["with_scalapack"]="__DONTUSE__" + ;; + aocl) + CONFIG_CACHE["with_mkl"]="__DONTUSE__" + CONFIG_CACHE["with_aocl"]="__INSTALL__" + CONFIG_CACHE["with_openblas"]="__DONTUSE__" + ;; + openblas) + CONFIG_CACHE["with_mkl"]="__DONTUSE__" + CONFIG_CACHE["with_aocl"]="__DONTUSE__" + CONFIG_CACHE["with_openblas"]="__INSTALL__" + ;; + none) + CONFIG_CACHE["with_mkl"]="__DONTUSE__" + CONFIG_CACHE["with_aocl"]="__DONTUSE__" + CONFIG_CACHE["with_openblas"]="__DONTUSE__" + ;; esac fi } @@ -300,15 +300,15 @@ config_set_defaults() { # Set math library defaults based on MATH_MODE (before user input processing) case "${CONFIG_CACHE[MATH_MODE]}" in - mkl) - CONFIG_CACHE["with_mkl"]="__SYSTEM__" - ;; - aocl) - CONFIG_CACHE["with_aocl"]="__SYSTEM__" - ;; - openblas) - CONFIG_CACHE["with_openblas"]="__INSTALL__" - ;; + mkl) + CONFIG_CACHE["with_mkl"]="__SYSTEM__" + ;; + aocl) + CONFIG_CACHE["with_aocl"]="__SYSTEM__" + ;; + openblas) + CONFIG_CACHE["with_openblas"]="__INSTALL__" + ;; esac # For MPI, we try to detect system MPI variant (following original script logic) @@ -422,9 +422,9 @@ read_enable_option() { if [[ "$arg" == *"="* ]]; then local value="${arg#*=}" case "$value" in - yes | true | 1) echo "__TRUE__" ;; - no | false | 0) echo "__FALSE__" ;; - *) echo "__INVALID__" ;; + yes | true | 1) echo "__TRUE__" ;; + no | false | 0) echo "__FALSE__" ;; + *) echo "__INVALID__" ;; esac else echo "__TRUE__" @@ -438,10 +438,10 @@ read_with_option() { if [[ "$arg" == *"="* ]]; then local value="${arg#*=}" case "$value" in - install) echo "__INSTALL__" ;; - system) echo "__SYSTEM__" ;; - no) echo "__DONTUSE__" ;; - *) echo "$value" ;; # Allow custom paths + install) echo "__INSTALL__" ;; + system) echo "__SYSTEM__" ;; + no) echo "__DONTUSE__" ;; + *) echo "$value" ;; # Allow custom paths esac else echo "__INSTALL__" @@ -521,14 +521,14 @@ config_apply_env_logic() { if [ "${CONFIG_CACHE[with_gcc]}" = "__INSTALL__" ]; then echo "You have chosen to install the GNU compiler, therefore MPI libraries have to be installed too" case ${CONFIG_CACHE[MPI_MODE]} in - mpich) - CONFIG_CACHE["with_mpich"]="__INSTALL__" - CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - ;; - openmpi) - CONFIG_CACHE["with_mpich"]="__DONTUSE__" - CONFIG_CACHE["with_openmpi"]="__INSTALL__" - ;; + mpich) + CONFIG_CACHE["with_mpich"]="__INSTALL__" + CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + ;; + openmpi) + CONFIG_CACHE["with_mpich"]="__DONTUSE__" + CONFIG_CACHE["with_openmpi"]="__INSTALL__" + ;; esac echo "and the use of the Intel compiler and Intel MPI will be disabled." CONFIG_CACHE["with_intel"]="__DONTUSE__" @@ -536,18 +536,18 @@ config_apply_env_logic() { fi # Enable only one MPI implementation case ${CONFIG_CACHE[MPI_MODE]} in - mpich) - CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" - ;; - openmpi) - CONFIG_CACHE["with_mpich"]="__DONTUSE__" - CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" - ;; - intelmpi) - CONFIG_CACHE["with_mpich"]="__DONTUSE__" - CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - ;; + mpich) + CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" + ;; + openmpi) + CONFIG_CACHE["with_mpich"]="__DONTUSE__" + CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" + ;; + intelmpi) + CONFIG_CACHE["with_mpich"]="__DONTUSE__" + CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + ;; esac fi @@ -615,8 +615,8 @@ config_export_to_env() { # Export all configuration values as environment variables for key in "${!CONFIG_CACHE[@]}"; do case "$key" in - enable_*) ;; - *) export "$key"="${CONFIG_CACHE[$key]}" ;; + enable_*) ;; + *) export "$key"="${CONFIG_CACHE[$key]}" ;; esac done @@ -687,462 +687,462 @@ config_parse_arguments() { while [[ $# -gt 0 ]]; do case $1 in - # Help and version - -h | --help) - show_help=true - shift - ;; - --version) - show_version=true - shift - ;; - --version-info) - if [[ -n "$2" && "$2" != -* ]]; then - CONFIG_CACHE["show_version_info"]="$2" - shift 2 - else - CONFIG_CACHE["show_version_info"]="all" - shift - fi - ;; - - # Build options - -j) - if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then - CONFIG_CACHE["NPROCS_OVERWRITE"]="$2" - shift 2 - else - report_error $LINENO "-j requires a number argument" - return 1 - fi - ;; - -j[0-9]*) - local nprocs_overwrite="${1#-j}" - if [[ -n "$nprocs_overwrite" && "$nprocs_overwrite" =~ ^[0-9]+$ ]]; then - CONFIG_CACHE["NPROCS_OVERWRITE"]="$nprocs_overwrite" + # Help and version + -h | --help) + show_help=true shift - else - report_error $LINENO "-j requires a number argument" - return 1 - fi - ;; - --dry-run) - CONFIG_CACHE["dry_run"]="__TRUE__" - shift - ;; - --pack-run) - CONFIG_CACHE["PACK_RUN"]="__TRUE__" - shift - ;; - - # Package version selection - Support multiple package:version pairs - --package-version) - local package_version_args="" - local processed_count=0 - - # Handle --package-version=value format - if [[ "$1" =~ ^--package-version=(.+)$ ]]; then - package_version_args="${BASH_REMATCH[1]}" + ;; + --version) + show_version=true shift - processed_count=1 - else - # Collect all consecutive non-option arguments - shift # Skip --package-version - while [[ $# -gt 0 && "$1" != -* ]]; do - if [[ -n "$package_version_args" ]]; then - package_version_args="$package_version_args $1" - else - package_version_args="$1" - fi + ;; + --version-info) + if [[ -n "$2" && "$2" != -* ]]; then + CONFIG_CACHE["show_version_info"]="$2" + shift 2 + else + CONFIG_CACHE["show_version_info"]="all" shift - ((processed_count++)) - done - fi - - # Validate we have at least one argument - if [[ -z "$package_version_args" ]]; then - report_error $LINENO "--package-version requires at least one package:version argument" - return 1 - fi + fi + ;; - # Process each package:version pair - local pair_count=0 - for pair in $package_version_args; do - if [[ "$pair" =~ ^([a-zA-Z0-9_]+):(main|alt)$ ]]; then - local pkg="${BASH_REMATCH[1]}" - local ver="${BASH_REMATCH[2]}" - CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="$ver" - ((pair_count++)) + # Build options + -j) + if [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then + CONFIG_CACHE["NPROCS_OVERWRITE"]="$2" + shift 2 else - report_error $LINENO "Invalid package version format: '$pair'. Use format 'package:version' (e.g., openmpi:alt, openblas:main)" + report_error $LINENO "-j requires a number argument" return 1 fi - done - - # Report successful processing - if [[ $pair_count -gt 1 ]]; then - echo "INFO: Processed $pair_count package version overrides" - fi - ;; - - # Configuration file - --config-file) - if [[ -n "$2" && "$2" != -* ]]; then - config_load_from_file "$2" - shift 2 - else - report_error $LINENO "--config-file requires an argument" - return 1 - fi - ;; - - # Mode selections - Support both --mode=value and --mode value formats - --mpi-mode | --mpi-mode=*) - local mpi_value="" - # Handle --mpi-mode=value format - if [[ "$1" =~ ^--mpi-mode=(.+)$ ]]; then - mpi_value="${BASH_REMATCH[1]}" - shift - elif [[ -n "$2" && "$2" != -* ]]; then - mpi_value="$2" - shift 2 - else - report_error $LINENO "--mpi-mode requires an argument" - return 1 - fi - - case "$mpi_value" in - mpich | openmpi | intelmpi | no) - CONFIG_CACHE["MPI_MODE"]="$mpi_value" ;; - *) - report_error $LINENO "Invalid MPI mode: $mpi_value. Valid options: mpich, openmpi, intelmpi, no" - return 1 + -j[0-9]*) + local nprocs_overwrite="${1#-j}" + if [[ -n "$nprocs_overwrite" && "$nprocs_overwrite" =~ ^[0-9]+$ ]]; then + CONFIG_CACHE["NPROCS_OVERWRITE"]="$nprocs_overwrite" + shift + else + report_error $LINENO "-j requires a number argument" + return 1 + fi ;; - esac - ;; - --math-mode | --math-mode=*) - local math_value="" - # Handle --math-mode=value format - if [[ "$1" =~ ^--math-mode=(.+)$ ]]; then - math_value="${BASH_REMATCH[1]}" + --dry-run) + CONFIG_CACHE["dry_run"]="__TRUE__" shift - elif [[ -n "$2" && "$2" != -* ]]; then - math_value="$2" - shift 2 - else - report_error $LINENO "--math-mode requires an argument" - return 1 - fi - - case "$math_value" in - mkl | aocl | openblas | cray | no) - CONFIG_CACHE["MATH_MODE"]="$math_value" - # Apply automatic parameter settings for specific math modes - case "$math_value" in - aocl) - CONFIG_CACHE["with_aocl"]="__SYSTEM__" - CONFIG_CACHE["with_fftw"]="__SYSTEM__" - CONFIG_CACHE["with_scalapack"]="__SYSTEM__" - ;; - esac ;; - *) - report_error $LINENO "Invalid math mode: $math_value. Valid options: mkl, aocl, openblas, cray, no" - return 1 + --pack-run) + CONFIG_CACHE["PACK_RUN"]="__TRUE__" + shift ;; - esac - ;; - # Package options - --with-*) - local option="${1#--with-}" - local value="__INSTALL__" + # Package version selection - Support multiple package:version pairs + --package-version) + local package_version_args="" + local processed_count=0 - # Handle --with-package=value format - if [[ "$option" =~ ^(.+)=(.+)$ ]]; then - option="${BASH_REMATCH[1]}" - value="${BASH_REMATCH[2]}" - fi + # Handle --package-version=value format + if [[ "$1" =~ ^--package-version=(.+)$ ]]; then + package_version_args="${BASH_REMATCH[1]}" + shift + processed_count=1 + else + # Collect all consecutive non-option arguments + shift # Skip --package-version + while [[ $# -gt 0 && "$1" != -* ]]; do + if [[ -n "$package_version_args" ]]; then + package_version_args="$package_version_args $1" + else + package_version_args="$1" + fi + shift + ((processed_count++)) + done + fi - # Special handling for --with-mpich-device=* (must be handled before general mpich) - if [[ "$option" == "mpich-device" ]]; then - CONFIG_CACHE["MPICH_DEVICE"]="$value" - CONFIG_CACHE["MPI_MODE"]="mpich" - shift - continue - fi + # Validate we have at least one argument + if [[ -z "$package_version_args" ]]; then + report_error $LINENO "--package-version requires at least one package:version argument" + return 1 + fi - # Convert value to internal format (matching original read_with function) - case "$value" in - system) - value="__SYSTEM__" - ;; - install) - value="__INSTALL__" - ;; - no) - value="__DONTUSE__" - ;; - __SYSTEM__ | __INSTALL__ | __DONTUSE__) - # Already in internal format, keep as is - ;; - *) - # For custom paths, expand ~ to $HOME (matching original behavior) - value="${value//\~/$HOME}" - ;; - esac + # Process each package:version pair + local pair_count=0 + for pair in $package_version_args; do + if [[ "$pair" =~ ^([a-zA-Z0-9_]+):(main|alt)$ ]]; then + local pkg="${BASH_REMATCH[1]}" + local ver="${BASH_REMATCH[2]}" + CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="$ver" + ((pair_count++)) + else + report_error $LINENO "Invalid package version format: '$pair'. Use format 'package:version' (e.g., openmpi:alt, openblas:main)" + return 1 + fi + done - # Handle special cases with specific processing logic - case "$option" in - 4th-openmpi) - # Handle --with-4th-openmpi parameter (only yes/no options) - case "$value" in - "yes" | "install" | "__INSTALL__") - CONFIG_CACHE["OPENMPI_4TH"]="yes" - ;; - "no" | "__DONTUSE__") - CONFIG_CACHE["OPENMPI_4TH"]="no" - ;; - *) - # Default to "no" for any other values - CONFIG_CACHE["OPENMPI_4TH"]="no" - ;; - esac - ;; - mpich) - CONFIG_CACHE["with_mpich"]="$value" - USER_EXPLICIT_MPI["with_mpich"]="true" # Mark as explicitly set by user - # Set MPI_MODE if not disabled - if [ "$value" != "__DONTUSE__" ]; then - CONFIG_CACHE["MPI_MODE"]="mpich" + # Report successful processing + if [[ $pair_count -gt 1 ]]; then + echo "INFO: Processed $pair_count package version overrides" fi ;; - openmpi) - CONFIG_CACHE["with_openmpi"]="$value" - USER_EXPLICIT_MPI["with_openmpi"]="true" # Mark as explicitly set by user - # Set MPI_MODE if not disabled - if [ "$value" != "__DONTUSE__" ]; then - CONFIG_CACHE["MPI_MODE"]="openmpi" - fi - ;; - intelmpi) - CONFIG_CACHE["with_intelmpi"]="$value" - USER_EXPLICIT_MPI["with_intelmpi"]="true" # Mark as explicitly set by user - # Set MPI_MODE if not disabled - if [ "$value" != "__DONTUSE__" ]; then - CONFIG_CACHE["MPI_MODE"]="intelmpi" + + # Configuration file + --config-file) + if [[ -n "$2" && "$2" != -* ]]; then + config_load_from_file "$2" + shift 2 + else + report_error $LINENO "--config-file requires an argument" + return 1 fi ;; - intel-classic) - # Special handling for intel-classic: only accepts yes/no values - case "$value" in - "__INSTALL__" | "" | "__DONTUSE__") - value="no" # Default to "no" - ;; - "yes") - value="yes" - ;; - "no") - value="no" - ;; - *) - report_error $LINENO "Invalid value '$value' for --with-intel-classic. Only 'yes' or 'no' are allowed." "CONFIG_ERROR" + + # Mode selections - Support both --mode=value and --mode value formats + --mpi-mode | --mpi-mode=*) + local mpi_value="" + # Handle --mpi-mode=value format + if [[ "$1" =~ ^--mpi-mode=(.+)$ ]]; then + mpi_value="${BASH_REMATCH[1]}" + shift + elif [[ -n "$2" && "$2" != -* ]]; then + mpi_value="$2" + shift 2 + else + report_error $LINENO "--mpi-mode requires an argument" return 1 - ;; + fi + + case "$mpi_value" in + mpich | openmpi | intelmpi | no) + CONFIG_CACHE["MPI_MODE"]="$mpi_value" + ;; + *) + report_error $LINENO "Invalid MPI mode: $mpi_value. Valid options: mpich, openmpi, intelmpi, no" + return 1 + ;; esac - CONFIG_CACHE["intel_classic"]="$value" ;; - intel-mpi-clas*) - # Special handling for intel-mpi-classic: only accepts yes/no values - case "$value" in - "__INSTALL__" | "" | "__DONTUSE__") - value="no" # Default to "no" - ;; - "yes") - value="yes" - ;; - "no") - value="no" - ;; - *) - report_error $LINENO "Invalid value '$value' for --with-intel-mpi-classic. Only 'yes' or 'no' are allowed." "CONFIG_ERROR" + --math-mode | --math-mode=*) + local math_value="" + # Handle --math-mode=value format + if [[ "$1" =~ ^--math-mode=(.+)$ ]]; then + math_value="${BASH_REMATCH[1]}" + shift + elif [[ -n "$2" && "$2" != -* ]]; then + math_value="$2" + shift 2 + else + report_error $LINENO "--math-mode requires an argument" return 1 - ;; + fi + + case "$math_value" in + mkl | aocl | openblas | cray | no) + CONFIG_CACHE["MATH_MODE"]="$math_value" + # Apply automatic parameter settings for specific math modes + case "$math_value" in + aocl) + CONFIG_CACHE["with_aocl"]="__SYSTEM__" + CONFIG_CACHE["with_fftw"]="__SYSTEM__" + CONFIG_CACHE["with_scalapack"]="__SYSTEM__" + ;; + esac + ;; + *) + report_error $LINENO "Invalid math mode: $math_value. Valid options: mkl, aocl, openblas, cray, no" + return 1 + ;; esac - CONFIG_CACHE["INTELMPI_CLASSIC"]="$value" - ;; - intel) - CONFIG_CACHE["with_intel"]="$value" ;; - ifx) - # Special handling for ifx: only accepts yes/no values + + # Package options + --with-*) + local option="${1#--with-}" + local value="__INSTALL__" + + # Handle --with-package=value format + if [[ "$option" =~ ^(.+)=(.+)$ ]]; then + option="${BASH_REMATCH[1]}" + value="${BASH_REMATCH[2]}" + fi + + # Special handling for --with-mpich-device=* (must be handled before general mpich) + if [[ "$option" == "mpich-device" ]]; then + CONFIG_CACHE["MPICH_DEVICE"]="$value" + CONFIG_CACHE["MPI_MODE"]="mpich" + shift + continue + fi + + # Convert value to internal format (matching original read_with function) case "$value" in - "__INSTALL__" | "" | "__DONTUSE__") - value="no" # Default to "no" - ;; - "yes") - value="yes" - ;; - "no") - value="no" - ;; - *) - report_error $LINENO "Invalid value '$value' for --with-ifx. Only 'yes' or 'no' are allowed." "CONFIG_ERROR" - return 1 - ;; + system) + value="__SYSTEM__" + ;; + install) + value="__INSTALL__" + ;; + no) + value="__DONTUSE__" + ;; + __SYSTEM__ | __INSTALL__ | __DONTUSE__) + # Already in internal format, keep as is + ;; + *) + # For custom paths, expand ~ to $HOME (matching original behavior) + value="${value//\~/$HOME}" + ;; esac - CONFIG_CACHE["WITH_IFX"]="$value" - ;; - amd) - CONFIG_CACHE["with_amd"]="$value" - ;; - flang) - # Special handling for flang: only accepts yes/no values - case "$value" in - "__INSTALL__" | "" | "__DONTUSE__") - value="no" # Default to "no" - ;; - "yes") - value="yes" - ;; - "no") - value="no" - ;; - *) - report_error $LINENO "Invalid value '$value' for --with-flang. Only 'yes' or 'no' are allowed." "CONFIG_ERROR" - return 1 - ;; + + # Handle special cases with specific processing logic + case "$option" in + 4th-openmpi) + # Handle --with-4th-openmpi parameter (only yes/no options) + case "$value" in + "yes" | "install" | "__INSTALL__") + CONFIG_CACHE["OPENMPI_4TH"]="yes" + ;; + "no" | "__DONTUSE__") + CONFIG_CACHE["OPENMPI_4TH"]="no" + ;; + *) + # Default to "no" for any other values + CONFIG_CACHE["OPENMPI_4TH"]="no" + ;; + esac + ;; + mpich) + CONFIG_CACHE["with_mpich"]="$value" + USER_EXPLICIT_MPI["with_mpich"]="true" # Mark as explicitly set by user + # Set MPI_MODE if not disabled + if [ "$value" != "__DONTUSE__" ]; then + CONFIG_CACHE["MPI_MODE"]="mpich" + fi + ;; + openmpi) + CONFIG_CACHE["with_openmpi"]="$value" + USER_EXPLICIT_MPI["with_openmpi"]="true" # Mark as explicitly set by user + # Set MPI_MODE if not disabled + if [ "$value" != "__DONTUSE__" ]; then + CONFIG_CACHE["MPI_MODE"]="openmpi" + fi + ;; + intelmpi) + CONFIG_CACHE["with_intelmpi"]="$value" + USER_EXPLICIT_MPI["with_intelmpi"]="true" # Mark as explicitly set by user + # Set MPI_MODE if not disabled + if [ "$value" != "__DONTUSE__" ]; then + CONFIG_CACHE["MPI_MODE"]="intelmpi" + fi + ;; + intel-classic) + # Special handling for intel-classic: only accepts yes/no values + case "$value" in + "__INSTALL__" | "" | "__DONTUSE__") + value="no" # Default to "no" + ;; + "yes") + value="yes" + ;; + "no") + value="no" + ;; + *) + report_error $LINENO "Invalid value '$value' for --with-intel-classic. Only 'yes' or 'no' are allowed." "CONFIG_ERROR" + return 1 + ;; + esac + CONFIG_CACHE["intel_classic"]="$value" + ;; + intel-mpi-clas*) + # Special handling for intel-mpi-classic: only accepts yes/no values + case "$value" in + "__INSTALL__" | "" | "__DONTUSE__") + value="no" # Default to "no" + ;; + "yes") + value="yes" + ;; + "no") + value="no" + ;; + *) + report_error $LINENO "Invalid value '$value' for --with-intel-mpi-classic. Only 'yes' or 'no' are allowed." "CONFIG_ERROR" + return 1 + ;; + esac + CONFIG_CACHE["INTELMPI_CLASSIC"]="$value" + ;; + intel) + CONFIG_CACHE["with_intel"]="$value" + ;; + ifx) + # Special handling for ifx: only accepts yes/no values + case "$value" in + "__INSTALL__" | "" | "__DONTUSE__") + value="no" # Default to "no" + ;; + "yes") + value="yes" + ;; + "no") + value="no" + ;; + *) + report_error $LINENO "Invalid value '$value' for --with-ifx. Only 'yes' or 'no' are allowed." "CONFIG_ERROR" + return 1 + ;; + esac + CONFIG_CACHE["WITH_IFX"]="$value" + ;; + amd) + CONFIG_CACHE["with_amd"]="$value" + ;; + flang) + # Special handling for flang: only accepts yes/no values + case "$value" in + "__INSTALL__" | "" | "__DONTUSE__") + value="no" # Default to "no" + ;; + "yes") + value="yes" + ;; + "no") + value="no" + ;; + *) + report_error $LINENO "Invalid value '$value' for --with-flang. Only 'yes' or 'no' are allowed." "CONFIG_ERROR" + return 1 + ;; + esac + CONFIG_CACHE["WITH_FLANG"]="$value" + ;; + aocl) + CONFIG_CACHE["with_aocl"]="$value" + USER_EXPLICIT_MATH["with_aocl"]="true" # Mark as explicitly set by user + ;; + mkl) + CONFIG_CACHE["with_mkl"]="$value" + USER_EXPLICIT_MATH["with_mkl"]="true" # Mark as explicitly set by user + # Set MATH_MODE if not disabled + if [ "$value" != "__DONTUSE__" ]; then + CONFIG_CACHE["MATH_MODE"]="mkl" + fi + ;; + openblas) + CONFIG_CACHE["with_openblas"]="$value" + USER_EXPLICIT_MATH["with_openblas"]="true" # Mark as explicitly set by user + # Set MATH_MODE if not disabled + if [ "$value" != "__DONTUSE__" ]; then + CONFIG_CACHE["MATH_MODE"]="openblas" + fi + ;; + fftw) + CONFIG_CACHE["with_fftw"]="$value" + USER_EXPLICIT_MATH["with_fftw"]="true" # Mark as explicitly set by user + ;; + scalapack) + CONFIG_CACHE["with_scalapack"]="$value" + USER_EXPLICIT_MATH["with_scalapack"]="true" # Mark as explicitly set by user + ;; + *) + # Convert to standard format for all other options + option="${option,,}" # Convert to lowercase + CONFIG_CACHE["with_${option}"]="$value" + ;; esac - CONFIG_CACHE["WITH_FLANG"]="$value" - ;; - aocl) - CONFIG_CACHE["with_aocl"]="$value" - USER_EXPLICIT_MATH["with_aocl"]="true" # Mark as explicitly set by user + shift ;; - mkl) - CONFIG_CACHE["with_mkl"]="$value" - USER_EXPLICIT_MATH["with_mkl"]="true" # Mark as explicitly set by user - # Set MATH_MODE if not disabled - if [ "$value" != "__DONTUSE__" ]; then - CONFIG_CACHE["MATH_MODE"]="mkl" + + # Enable options + --enable-*) + local option="${1#--enable-}" + local value="__TRUE__" + + # Handle --enable-feature=value format + if [[ "$option" =~ ^(.+)=(.+)$ ]]; then + option="${BASH_REMATCH[1]}" + value="${BASH_REMATCH[2]}" + case "$value" in + yes | true | 1) value="__TRUE__" ;; + no | false | 0) value="__FALSE__" ;; + *) + report_error $LINENO "Invalid value for --enable-${option}: $value. Use yes/no" + return 1 + ;; + esac fi + + CONFIG_CACHE["enable_${option}"]="$value" + shift ;; - openblas) - CONFIG_CACHE["with_openblas"]="$value" - USER_EXPLICIT_MATH["with_openblas"]="true" # Mark as explicitly set by user - # Set MATH_MODE if not disabled - if [ "$value" != "__DONTUSE__" ]; then - CONFIG_CACHE["MATH_MODE"]="openblas" + + # GPU version + --gpu-ver | --gpu-ver=*) + local gpu_value="" + # Handle --gpu-ver=value format + if [[ "$1" =~ ^--gpu-ver=(.+)$ ]]; then + gpu_value="${BASH_REMATCH[1]}" + shift + elif [[ -n "$2" && "$2" != -* ]]; then + gpu_value="$2" + shift 2 + else + report_error $LINENO "--gpu-ver requires an argument" + return 1 fi + CONFIG_CACHE["GPUVER"]="$gpu_value" ;; - fftw) - CONFIG_CACHE["with_fftw"]="$value" - USER_EXPLICIT_MATH["with_fftw"]="true" # Mark as explicitly set by user - ;; - scalapack) - CONFIG_CACHE["with_scalapack"]="$value" - USER_EXPLICIT_MATH["with_scalapack"]="true" # Mark as explicitly set by user - ;; - *) - # Convert to standard format for all other options - option="${option,,}" # Convert to lowercase - CONFIG_CACHE["with_${option}"]="$value" - ;; - esac - shift - ;; - - # Enable options - --enable-*) - local option="${1#--enable-}" - local value="__TRUE__" - # Handle --enable-feature=value format - if [[ "$option" =~ ^(.+)=(.+)$ ]]; then - option="${BASH_REMATCH[1]}" - value="${BASH_REMATCH[2]}" - case "$value" in - yes | true | 1) value="__TRUE__" ;; - no | false | 0) value="__FALSE__" ;; - *) - report_error $LINENO "Invalid value for --enable-${option}: $value. Use yes/no" + # Target CPU + --target-cpu | --target-cpu=*) + local cpu_value="" + # Handle --target-cpu=value format + if [[ "$1" =~ ^--target-cpu=(.+)$ ]]; then + cpu_value="${BASH_REMATCH[1]}" + shift + elif [[ -n "$2" && "$2" != -* ]]; then + cpu_value="$2" + shift 2 + else + report_error $LINENO "--target-cpu requires an argument" return 1 - ;; - esac - fi + fi + CONFIG_CACHE["TARGET_CPU"]="$cpu_value" + ;; - CONFIG_CACHE["enable_${option}"]="$value" - shift - ;; + # Log lines + --log-lines | --log-lines=*) + local log_value="" + # Handle --log-lines=value format + if [[ "$1" =~ ^--log-lines=(.+)$ ]]; then + log_value="${BASH_REMATCH[1]}" + shift + elif [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then + log_value="$2" + shift 2 + else + report_error $LINENO "--log-lines requires a number argument" + return 1 + fi - # GPU version - --gpu-ver | --gpu-ver=*) - local gpu_value="" - # Handle --gpu-ver=value format - if [[ "$1" =~ ^--gpu-ver=(.+)$ ]]; then - gpu_value="${BASH_REMATCH[1]}" - shift - elif [[ -n "$2" && "$2" != -* ]]; then - gpu_value="$2" - shift 2 - else - report_error $LINENO "--gpu-ver requires an argument" - return 1 - fi - CONFIG_CACHE["GPUVER"]="$gpu_value" - ;; + if [[ "$log_value" =~ ^[0-9]+$ ]]; then + CONFIG_CACHE["LOG_LINES"]="$log_value" + else + report_error $LINENO "--log-lines requires a number argument" + return 1 + fi + ;; - # Target CPU - --target-cpu | --target-cpu=*) - local cpu_value="" - # Handle --target-cpu=value format - if [[ "$1" =~ ^--target-cpu=(.+)$ ]]; then - cpu_value="${BASH_REMATCH[1]}" + # Skip system checks + --skip-system-checks) + CONFIG_CACHE["skip_system_checks"]="__TRUE__" shift - elif [[ -n "$2" && "$2" != -* ]]; then - cpu_value="$2" - shift 2 - else - report_error $LINENO "--target-cpu requires an argument" - return 1 - fi - CONFIG_CACHE["TARGET_CPU"]="$cpu_value" - ;; + ;; - # Log lines - --log-lines | --log-lines=*) - local log_value="" - # Handle --log-lines=value format - if [[ "$1" =~ ^--log-lines=(.+)$ ]]; then - log_value="${BASH_REMATCH[1]}" + # Positional arguments (ignored for now) + *) shift - elif [[ -n "$2" && "$2" =~ ^[0-9]+$ ]]; then - log_value="$2" - shift 2 - else - report_error $LINENO "--log-lines requires a number argument" - return 1 - fi - - if [[ "$log_value" =~ ^[0-9]+$ ]]; then - CONFIG_CACHE["LOG_LINES"]="$log_value" - else - report_error $LINENO "--log-lines requires a number argument" - return 1 - fi - ;; - - # Skip system checks - --skip-system-checks) - CONFIG_CACHE["skip_system_checks"]="__TRUE__" - shift - ;; - - # Positional arguments (ignored for now) - *) - shift - ;; + ;; esac done @@ -1211,27 +1211,27 @@ config_apply_modes() { echo "Applying MPI mode: $mpi_mode" fi case "$mpi_mode" in - mpich) - # Only override if user hasn't explicitly set these values via command line - [[ -z "${USER_EXPLICIT_MPI[with_mpich]}" ]] && CONFIG_CACHE["with_mpich"]="__INSTALL__" - [[ -z "${USER_EXPLICIT_MPI[with_openmpi]}" ]] && CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MPI[with_intelmpi]}" ]] && CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" - ;; - openmpi) - [[ -z "${USER_EXPLICIT_MPI[with_mpich]}" ]] && CONFIG_CACHE["with_mpich"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MPI[with_openmpi]}" ]] && CONFIG_CACHE["with_openmpi"]="__INSTALL__" - [[ -z "${USER_EXPLICIT_MPI[with_intelmpi]}" ]] && CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" - ;; - intelmpi) - [[ -z "${USER_EXPLICIT_MPI[with_mpich]}" ]] && CONFIG_CACHE["with_mpich"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MPI[with_openmpi]}" ]] && CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MPI[with_intelmpi]}" ]] && CONFIG_CACHE["with_intelmpi"]="__INSTALL__" - ;; - no) - [[ -z "${USER_EXPLICIT_MPI[with_mpich]}" ]] && CONFIG_CACHE["with_mpich"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MPI[with_openmpi]}" ]] && CONFIG_CACHE["with_openmpi"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MPI[with_intelmpi]}" ]] && CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" - ;; + mpich) + # Only override if user hasn't explicitly set these values via command line + [[ -z "${USER_EXPLICIT_MPI[with_mpich]}" ]] && CONFIG_CACHE["with_mpich"]="__INSTALL__" + [[ -z "${USER_EXPLICIT_MPI[with_openmpi]}" ]] && CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MPI[with_intelmpi]}" ]] && CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" + ;; + openmpi) + [[ -z "${USER_EXPLICIT_MPI[with_mpich]}" ]] && CONFIG_CACHE["with_mpich"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MPI[with_openmpi]}" ]] && CONFIG_CACHE["with_openmpi"]="__INSTALL__" + [[ -z "${USER_EXPLICIT_MPI[with_intelmpi]}" ]] && CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" + ;; + intelmpi) + [[ -z "${USER_EXPLICIT_MPI[with_mpich]}" ]] && CONFIG_CACHE["with_mpich"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MPI[with_openmpi]}" ]] && CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MPI[with_intelmpi]}" ]] && CONFIG_CACHE["with_intelmpi"]="__INSTALL__" + ;; + no) + [[ -z "${USER_EXPLICIT_MPI[with_mpich]}" ]] && CONFIG_CACHE["with_mpich"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MPI[with_openmpi]}" ]] && CONFIG_CACHE["with_openmpi"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MPI[with_intelmpi]}" ]] && CONFIG_CACHE["with_intelmpi"]="__DONTUSE__" + ;; esac fi @@ -1244,31 +1244,31 @@ config_apply_modes() { echo "Applying Math mode: $math_mode" fi case "$math_mode" in - mkl) - [[ -z "${USER_EXPLICIT_MATH[with_mkl]}" ]] && CONFIG_CACHE["with_mkl"]="__SYSTEM__" - [[ -z "${USER_EXPLICIT_MATH[with_aocl]}" ]] && CONFIG_CACHE["with_aocl"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MATH[with_openblas]}" ]] && CONFIG_CACHE["with_openblas"]="__DONTUSE__" - # MKL provides FFTW and ScaLAPACK, so disable them (original logic) - [[ -z "${USER_EXPLICIT_MATH[with_fftw]}" ]] && CONFIG_CACHE["with_fftw"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MATH[with_scalapack]}" ]] && CONFIG_CACHE["with_scalapack"]="__DONTUSE__" - ;; - aocl) - [[ -z "${USER_EXPLICIT_MATH[with_mkl]}" ]] && CONFIG_CACHE["with_mkl"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MATH[with_aocl]}" ]] && CONFIG_CACHE["with_aocl"]="__SYSTEM__" - [[ -z "${USER_EXPLICIT_MATH[with_openblas]}" ]] && CONFIG_CACHE["with_openblas"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MATH[with_fftw]}" ]] && CONFIG_CACHE["with_fftw"]="__SYSTEM__" - [[ -z "${USER_EXPLICIT_MATH[with_scalapack]}" ]] && CONFIG_CACHE["with_scalapack"]="__SYSTEM__" - ;; - openblas) - [[ -z "${USER_EXPLICIT_MATH[with_mkl]}" ]] && CONFIG_CACHE["with_mkl"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MATH[with_aocl]}" ]] && CONFIG_CACHE["with_aocl"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MATH[with_openblas]}" ]] && CONFIG_CACHE["with_openblas"]="__INSTALL__" - ;; - cray) - [[ -z "${USER_EXPLICIT_MATH[with_mkl]}" ]] && CONFIG_CACHE["with_mkl"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MATH[with_aocl]}" ]] && CONFIG_CACHE["with_aocl"]="__DONTUSE__" - [[ -z "${USER_EXPLICIT_MATH[with_openblas]}" ]] && CONFIG_CACHE["with_openblas"]="__DONTUSE__" - ;; + mkl) + [[ -z "${USER_EXPLICIT_MATH[with_mkl]}" ]] && CONFIG_CACHE["with_mkl"]="__SYSTEM__" + [[ -z "${USER_EXPLICIT_MATH[with_aocl]}" ]] && CONFIG_CACHE["with_aocl"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MATH[with_openblas]}" ]] && CONFIG_CACHE["with_openblas"]="__DONTUSE__" + # MKL provides FFTW and ScaLAPACK, so disable them (original logic) + [[ -z "${USER_EXPLICIT_MATH[with_fftw]}" ]] && CONFIG_CACHE["with_fftw"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MATH[with_scalapack]}" ]] && CONFIG_CACHE["with_scalapack"]="__DONTUSE__" + ;; + aocl) + [[ -z "${USER_EXPLICIT_MATH[with_mkl]}" ]] && CONFIG_CACHE["with_mkl"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MATH[with_aocl]}" ]] && CONFIG_CACHE["with_aocl"]="__SYSTEM__" + [[ -z "${USER_EXPLICIT_MATH[with_openblas]}" ]] && CONFIG_CACHE["with_openblas"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MATH[with_fftw]}" ]] && CONFIG_CACHE["with_fftw"]="__SYSTEM__" + [[ -z "${USER_EXPLICIT_MATH[with_scalapack]}" ]] && CONFIG_CACHE["with_scalapack"]="__SYSTEM__" + ;; + openblas) + [[ -z "${USER_EXPLICIT_MATH[with_mkl]}" ]] && CONFIG_CACHE["with_mkl"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MATH[with_aocl]}" ]] && CONFIG_CACHE["with_aocl"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MATH[with_openblas]}" ]] && CONFIG_CACHE["with_openblas"]="__INSTALL__" + ;; + cray) + [[ -z "${USER_EXPLICIT_MATH[with_mkl]}" ]] && CONFIG_CACHE["with_mkl"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MATH[with_aocl]}" ]] && CONFIG_CACHE["with_aocl"]="__DONTUSE__" + [[ -z "${USER_EXPLICIT_MATH[with_openblas]}" ]] && CONFIG_CACHE["with_openblas"]="__DONTUSE__" + ;; esac fi diff --git a/toolchain/scripts/lib/package_manager.sh b/toolchain/scripts/lib/package_manager.sh index bf410e34e23..d2e31891ee5 100644 --- a/toolchain/scripts/lib/package_manager.sh +++ b/toolchain/scripts/lib/package_manager.sh @@ -77,12 +77,12 @@ package_is_enabled() { local status=$(config_get "with_${package}") case "$status" in - "__INSTALL__" | "__SYSTEM__") - return 0 - ;; - *) - return 1 - ;; + "__INSTALL__" | "__SYSTEM__") + return 0 + ;; + *) + return 1 + ;; esac } @@ -205,21 +205,21 @@ package_check_system_requirements() { # Check for compiler availability local compiler_mode=$(config_get MATH_MODE) case "$compiler_mode" in - gcc) - if ! command -v gcc &>/dev/null; then - report_warning ${LINENO} "GCC compiler not found in system PATH" - fi - ;; - intel) - if ! command -v icc &>/dev/null && ! command -v icx &>/dev/null; then - report_warning ${LINENO} "Intel compiler not found in system PATH" - fi - ;; - amd) - if ! command -v clang &>/dev/null; then - report_warning ${LINENO} "AMD/Clang compiler not found in system PATH" - fi - ;; + gcc) + if ! command -v gcc &>/dev/null; then + report_warning ${LINENO} "GCC compiler not found in system PATH" + fi + ;; + intel) + if ! command -v icc &>/dev/null && ! command -v icx &>/dev/null; then + report_warning ${LINENO} "Intel compiler not found in system PATH" + fi + ;; + amd) + if ! command -v clang &>/dev/null; then + report_warning ${LINENO} "AMD/Clang compiler not found in system PATH" + fi + ;; esac echo "System requirements check completed" diff --git a/toolchain/scripts/lib/user_interface.sh b/toolchain/scripts/lib/user_interface.sh index 8b0bcbfd596..a7d04601fa3 100644 --- a/toolchain/scripts/lib/user_interface.sh +++ b/toolchain/scripts/lib/user_interface.sh @@ -120,32 +120,32 @@ ui_detect_unicode_support() { # Check terminal type and capabilities local term_support="none" case "${TERM:-}" in - xterm* | screen* | tmux* | rxvt* | gnome* | konsole* | alacritty* | kitty* | iterm*) - if [[ "$locale_utf8" == "true" ]]; then - term_support="full" - else - term_support="basic" - fi - ;; - linux | vt*) - # Linux console - basic Unicode support - if [[ "$locale_utf8" == "true" ]]; then - term_support="basic" - else - term_support="none" - fi - ;; - dumb | unknown) - term_support="none" - ;; - *) - # Unknown terminal - be conservative - if [[ "$locale_utf8" == "true" ]]; then - term_support="basic" - else + xterm* | screen* | tmux* | rxvt* | gnome* | konsole* | alacritty* | kitty* | iterm*) + if [[ "$locale_utf8" == "true" ]]; then + term_support="full" + else + term_support="basic" + fi + ;; + linux | vt*) + # Linux console - basic Unicode support + if [[ "$locale_utf8" == "true" ]]; then + term_support="basic" + else + term_support="none" + fi + ;; + dumb | unknown) term_support="none" - fi - ;; + ;; + *) + # Unknown terminal - be conservative + if [[ "$locale_utf8" == "true" ]]; then + term_support="basic" + else + term_support="none" + fi + ;; esac # Final validation - ensure we have both locale and terminal support @@ -187,75 +187,75 @@ ui_init_icons() { local support=$(ui_detect_unicode_support) case "$support" in - "full") - # Full Unicode support - use emoji and special symbols - readonly UI_ICON_SUCCESS="✅" - readonly UI_ICON_ERROR="❌" - readonly UI_ICON_WARNING="⚠️" - readonly UI_ICON_INFO="ℹ️" - readonly UI_ICON_PROGRESS="🔄" - readonly UI_ICON_ROCKET="🚀" - readonly UI_ICON_GEAR="⚙️" - readonly UI_ICON_PACKAGE="📦" - readonly UI_ICON_DOWNLOAD="⬇️" - readonly UI_ICON_BUILD="🔨" - readonly UI_ICON_INSTALL="📥" - readonly UI_ICON_CHECK="✓" - readonly UI_ICON_CROSS="✗" - readonly UI_ICON_ARROW="→" - readonly UI_ICON_STAR="⭐" - # Full Unicode progress bar - readonly UI_PROGRESS_FULL="█" - readonly UI_PROGRESS_PARTIAL1="▓" - readonly UI_PROGRESS_PARTIAL2="▒" - readonly UI_PROGRESS_EMPTY="░" - ;; - "basic") - # Basic Unicode support - use simple Unicode symbols - readonly UI_ICON_SUCCESS="✓" - readonly UI_ICON_ERROR="✗" - readonly UI_ICON_WARNING="!" - readonly UI_ICON_INFO="i" - readonly UI_ICON_PROGRESS="*" - readonly UI_ICON_ROCKET="^" - readonly UI_ICON_GEAR="*" - readonly UI_ICON_PACKAGE="+" - readonly UI_ICON_DOWNLOAD="v" - readonly UI_ICON_BUILD="#" - readonly UI_ICON_INSTALL="+" - readonly UI_ICON_CHECK="✓" - readonly UI_ICON_CROSS="✗" - readonly UI_ICON_ARROW="→" - readonly UI_ICON_STAR="*" - # Basic Unicode progress bar - readonly UI_PROGRESS_FULL="█" - readonly UI_PROGRESS_PARTIAL1="▓" - readonly UI_PROGRESS_PARTIAL2="▒" - readonly UI_PROGRESS_EMPTY="░" - ;; - *) - # ASCII fallback - maximum compatibility - readonly UI_ICON_SUCCESS="[OK]" - readonly UI_ICON_ERROR="[ERR]" - readonly UI_ICON_WARNING="[WARN]" - readonly UI_ICON_INFO="[INFO]" - readonly UI_ICON_PROGRESS="[*]" - readonly UI_ICON_ROCKET="[^]" - readonly UI_ICON_GEAR="[*]" - readonly UI_ICON_PACKAGE="[+]" - readonly UI_ICON_DOWNLOAD="[v]" - readonly UI_ICON_BUILD="[#]" - readonly UI_ICON_INSTALL="[+]" - readonly UI_ICON_CHECK="[+]" - readonly UI_ICON_CROSS="[-]" - readonly UI_ICON_ARROW="->" - readonly UI_ICON_STAR="[*]" - # ASCII progress bar - readonly UI_PROGRESS_FULL="#" - readonly UI_PROGRESS_PARTIAL1="#" - readonly UI_PROGRESS_PARTIAL2="-" - readonly UI_PROGRESS_EMPTY="." - ;; + "full") + # Full Unicode support - use emoji and special symbols + readonly UI_ICON_SUCCESS="✅" + readonly UI_ICON_ERROR="❌" + readonly UI_ICON_WARNING="⚠️" + readonly UI_ICON_INFO="ℹ️" + readonly UI_ICON_PROGRESS="🔄" + readonly UI_ICON_ROCKET="🚀" + readonly UI_ICON_GEAR="⚙️" + readonly UI_ICON_PACKAGE="📦" + readonly UI_ICON_DOWNLOAD="⬇️" + readonly UI_ICON_BUILD="🔨" + readonly UI_ICON_INSTALL="📥" + readonly UI_ICON_CHECK="✓" + readonly UI_ICON_CROSS="✗" + readonly UI_ICON_ARROW="→" + readonly UI_ICON_STAR="⭐" + # Full Unicode progress bar + readonly UI_PROGRESS_FULL="█" + readonly UI_PROGRESS_PARTIAL1="▓" + readonly UI_PROGRESS_PARTIAL2="▒" + readonly UI_PROGRESS_EMPTY="░" + ;; + "basic") + # Basic Unicode support - use simple Unicode symbols + readonly UI_ICON_SUCCESS="✓" + readonly UI_ICON_ERROR="✗" + readonly UI_ICON_WARNING="!" + readonly UI_ICON_INFO="i" + readonly UI_ICON_PROGRESS="*" + readonly UI_ICON_ROCKET="^" + readonly UI_ICON_GEAR="*" + readonly UI_ICON_PACKAGE="+" + readonly UI_ICON_DOWNLOAD="v" + readonly UI_ICON_BUILD="#" + readonly UI_ICON_INSTALL="+" + readonly UI_ICON_CHECK="✓" + readonly UI_ICON_CROSS="✗" + readonly UI_ICON_ARROW="→" + readonly UI_ICON_STAR="*" + # Basic Unicode progress bar + readonly UI_PROGRESS_FULL="█" + readonly UI_PROGRESS_PARTIAL1="▓" + readonly UI_PROGRESS_PARTIAL2="▒" + readonly UI_PROGRESS_EMPTY="░" + ;; + *) + # ASCII fallback - maximum compatibility + readonly UI_ICON_SUCCESS="[OK]" + readonly UI_ICON_ERROR="[ERR]" + readonly UI_ICON_WARNING="[WARN]" + readonly UI_ICON_INFO="[INFO]" + readonly UI_ICON_PROGRESS="[*]" + readonly UI_ICON_ROCKET="[^]" + readonly UI_ICON_GEAR="[*]" + readonly UI_ICON_PACKAGE="[+]" + readonly UI_ICON_DOWNLOAD="[v]" + readonly UI_ICON_BUILD="[#]" + readonly UI_ICON_INSTALL="[+]" + readonly UI_ICON_CHECK="[+]" + readonly UI_ICON_CROSS="[-]" + readonly UI_ICON_ARROW="->" + readonly UI_ICON_STAR="[*]" + # ASCII progress bar + readonly UI_PROGRESS_FULL="#" + readonly UI_PROGRESS_PARTIAL1="#" + readonly UI_PROGRESS_PARTIAL2="-" + readonly UI_PROGRESS_EMPTY="." + ;; esac } @@ -269,19 +269,19 @@ ui_init() { # Parse options while [[ $# -gt 0 ]]; do case "$1" in - verbose) - UI_VERBOSE=true - ;; - quiet) - UI_QUIET=true - ;; - --log-file=*) - UI_LOG_FILE="${1#*=}" - ;; - *) - # Assume it's a log file path - UI_LOG_FILE="$1" - ;; + verbose) + UI_VERBOSE=true + ;; + quiet) + UI_QUIET=true + ;; + --log-file=*) + UI_LOG_FILE="${1#*=}" + ;; + *) + # Assume it's a log file path + UI_LOG_FILE="$1" + ;; esac shift done @@ -825,22 +825,22 @@ ui_show_summary() { local display_status="$status" local status_icon="" case "$status" in - "__INSTALL__") - display_status="${UI_GREEN}install${UI_NC}" - status_icon="📥" - ;; - "__SYSTEM__") - display_status="${UI_BLUE}system${UI_NC}" - status_icon="🔗" - ;; - "__DONTUSE__") - display_status="${UI_GRAY}disabled${UI_NC}" - status_icon="❌" - ;; - *) - display_status="${UI_ORANGE}${status}${UI_NC}" - status_icon="📁" - ;; + "__INSTALL__") + display_status="${UI_GREEN}install${UI_NC}" + status_icon="📥" + ;; + "__SYSTEM__") + display_status="${UI_BLUE}system${UI_NC}" + status_icon="🔗" + ;; + "__DONTUSE__") + display_status="${UI_GRAY}disabled${UI_NC}" + status_icon="❌" + ;; + *) + display_status="${UI_ORANGE}${status}${UI_NC}" + status_icon="📁" + ;; esac printf " ├─ %s %-12s %b %b\n" "$status_icon" "$pkg:" "$UI_ARROW" "$display_status" fi @@ -900,13 +900,13 @@ ui_confirm_installation() { read -r response case "$response" in - [yY] | [yY][eE][sS]) - return 0 - ;; - *) - ui_info "Installation cancelled" - return 1 - ;; + [yY] | [yY][eE][sS]) + return 0 + ;; + *) + ui_info "Installation cancelled" + return 1 + ;; esac } @@ -927,33 +927,33 @@ ui_package_progress() { local action="$2" case "$action" in - start) - ui_print_color "${UI_BLUE}${UI_BOLD}" "${UI_ICON_BUILD} Building $package..." - ;; - download) - ui_debug "${UI_ICON_DOWNLOAD} Downloading $package..." - ;; - extract) - ui_debug "${UI_ICON_PACKAGE} Extracting $package..." - ;; - configure) - ui_debug "${UI_ICON_GEAR} Configuring $package..." - ;; - compile) - ui_debug "${UI_ICON_BUILD} Compiling $package..." - ;; - install) - ui_debug "${UI_ICON_INSTALL} Installing $package..." - ;; - success) - ui_success "Successfully built $package" - ;; - skip) - ui_print_color "${UI_GRAY}${UI_BOLD}" "${UI_ICON_INFO} Skipping $package (already built or disabled)" - ;; - error) - ui_error "Failed to build $package" - ;; + start) + ui_print_color "${UI_BLUE}${UI_BOLD}" "${UI_ICON_BUILD} Building $package..." + ;; + download) + ui_debug "${UI_ICON_DOWNLOAD} Downloading $package..." + ;; + extract) + ui_debug "${UI_ICON_PACKAGE} Extracting $package..." + ;; + configure) + ui_debug "${UI_ICON_GEAR} Configuring $package..." + ;; + compile) + ui_debug "${UI_ICON_BUILD} Compiling $package..." + ;; + install) + ui_debug "${UI_ICON_INSTALL} Installing $package..." + ;; + success) + ui_success "Successfully built $package" + ;; + skip) + ui_print_color "${UI_GRAY}${UI_BOLD}" "${UI_ICON_INFO} Skipping $package (already built or disabled)" + ;; + error) + ui_error "Failed to build $package" + ;; esac } @@ -1048,86 +1048,86 @@ ui_validate_input() { local type="$2" case "$type" in - number) - if [[ ! "$input" =~ ^[0-9]+$ ]]; then - ui_error "Invalid number: $input" - ui_info "Please provide a positive integer" - return 1 - fi - ;; - path) - if [[ ! -d "$input" ]]; then - ui_error "Directory does not exist: $input" - ui_info "Please provide a valid directory path" - return 1 - fi - ;; - file) - if [[ ! -f "$input" ]]; then - ui_error "File does not exist: $input" - ui_info "Please provide a valid file path" - return 1 - fi - ;; - mpi_mode) - case "$input" in - mpich | openmpi | intelmpi | no) - return 0 + number) + if [[ ! "$input" =~ ^[0-9]+$ ]]; then + ui_error "Invalid number: $input" + ui_info "Please provide a positive integer" + return 1 + fi ;; - *) - ui_error "Invalid MPI mode: $input" - ui_print_color "${UI_BLUE}${UI_BOLD}" "📋 Valid options:" - ui_print_color "${UI_GREEN}" " • mpich - MPICH implementation (recommended)" - ui_print_color "${UI_GREEN}" " • openmpi - Open MPI implementation" - ui_print_color "${UI_GREEN}" " • intelmpi - Intel MPI (requires Intel compiler)" - ui_print_color "${UI_GREEN}" " • no - Disable MPI support" - return 1 + path) + if [[ ! -d "$input" ]]; then + ui_error "Directory does not exist: $input" + ui_info "Please provide a valid directory path" + return 1 + fi ;; - esac - ;; - math_mode) - case "$input" in - cray | mkl | openblas | aocl) - return 0 + file) + if [[ ! -f "$input" ]]; then + ui_error "File does not exist: $input" + ui_info "Please provide a valid file path" + return 1 + fi ;; - *) - ui_error "Invalid math mode: $input" - ui_print_color "${UI_BLUE}${UI_BOLD}" "📋 Valid options:" - ui_print_color "${UI_GREEN}" " • openblas - OpenBLAS (open source, recommended)" - ui_print_color "${UI_GREEN}" " • mkl - Intel Math Kernel Library (high performance)" - ui_print_color "${UI_GREEN}" " • aocl - AMD Optimizing CPU Libraries" - ui_print_color "${UI_GREEN}" " • cray - Cray LibSci (for Cray systems)" - return 1 + mpi_mode) + case "$input" in + mpich | openmpi | intelmpi | no) + return 0 + ;; + *) + ui_error "Invalid MPI mode: $input" + ui_print_color "${UI_BLUE}${UI_BOLD}" "📋 Valid options:" + ui_print_color "${UI_GREEN}" " • mpich - MPICH implementation (recommended)" + ui_print_color "${UI_GREEN}" " • openmpi - Open MPI implementation" + ui_print_color "${UI_GREEN}" " • intelmpi - Intel MPI (requires Intel compiler)" + ui_print_color "${UI_GREEN}" " • no - Disable MPI support" + return 1 + ;; + esac ;; - esac - ;; - gpu_version) - # Support only numeric formats for GPU versions - if [[ "$input" == "no" ]]; then - return 0 - fi + math_mode) + case "$input" in + cray | mkl | openblas | aocl) + return 0 + ;; + *) + ui_error "Invalid math mode: $input" + ui_print_color "${UI_BLUE}${UI_BOLD}" "📋 Valid options:" + ui_print_color "${UI_GREEN}" " • openblas - OpenBLAS (open source, recommended)" + ui_print_color "${UI_GREEN}" " • mkl - Intel Math Kernel Library (high performance)" + ui_print_color "${UI_GREEN}" " • aocl - AMD Optimizing CPU Libraries" + ui_print_color "${UI_GREEN}" " • cray - Cray LibSci (for Cray systems)" + return 1 + ;; + esac + ;; + gpu_version) + # Support only numeric formats for GPU versions + if [[ "$input" == "no" ]]; then + return 0 + fi - # Check if it's a valid numeric format (like 8.0, 70, 80, etc.) - local arch_num="${input//./}" - if [[ "$arch_num" =~ ^[1-9][0-9]*$ ]]; then - return 0 - fi + # Check if it's a valid numeric format (like 8.0, 70, 80, etc.) + local arch_num="${input//./}" + if [[ "$arch_num" =~ ^[1-9][0-9]*$ ]]; then + return 0 + fi - # Invalid format - show enhanced error message - ui_error "Invalid GPU version: $input" - ui_print_color "${UI_BLUE}${UI_BOLD}" "📋 Valid formats:" - ui_print_color "${UI_GREEN}" " • Decimal format: 6.0, 7.0, 8.0, 8.9, etc. (CUDA compute capability)" - ui_print_color "${UI_GREEN}" " • Integer format: 60, 70, 80, 89, etc." - ui_print_color "${UI_GREEN}" " • Disable GPU: no" - ui_print_color "${UI_ORANGE}${UI_BOLD}" "💡 Examples:" - ui_print_color "${UI_WHITE}" " • 8.0 or 80 for compute capability 8.0 (RTX 30xx series)" - ui_print_color "${UI_WHITE}" " • 7.5 or 75 for compute capability 7.5 (RTX 20xx series)" - return 1 - ;; - *) - ui_error "Unknown validation type: $type" - return 1 - ;; + # Invalid format - show enhanced error message + ui_error "Invalid GPU version: $input" + ui_print_color "${UI_BLUE}${UI_BOLD}" "📋 Valid formats:" + ui_print_color "${UI_GREEN}" " • Decimal format: 6.0, 7.0, 8.0, 8.9, etc. (CUDA compute capability)" + ui_print_color "${UI_GREEN}" " • Integer format: 60, 70, 80, 89, etc." + ui_print_color "${UI_GREEN}" " • Disable GPU: no" + ui_print_color "${UI_ORANGE}${UI_BOLD}" "💡 Examples:" + ui_print_color "${UI_WHITE}" " • 8.0 or 80 for compute capability 8.0 (RTX 30xx series)" + ui_print_color "${UI_WHITE}" " • 7.5 or 75 for compute capability 7.5 (RTX 20xx series)" + return 1 + ;; + *) + ui_error "Unknown validation type: $type" + return 1 + ;; esac return 0 diff --git a/toolchain/scripts/lib/version_helper.sh b/toolchain/scripts/lib/version_helper.sh index 9bb1b969ff6..d99996f9d98 100644 --- a/toolchain/scripts/lib/version_helper.sh +++ b/toolchain/scripts/lib/version_helper.sh @@ -158,27 +158,27 @@ version_interactive_select() { # Set user choice or default to main case "$user_choice" in - alt | alternative) - if [[ -n "${!alt_var}" ]]; then - CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="alt" - echo " → Selected: alt (${!alt_var})" - else - echo " → Alternative version not available, using main" + alt | alternative) + if [[ -n "${!alt_var}" ]]; then + CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="alt" + echo " → Selected: alt (${!alt_var})" + else + echo " → Alternative version not available, using main" + CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="main" + fi + ;; + main | "") CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="main" - fi - ;; - main | "") - CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="main" - if [[ -n "${!main_var}" ]]; then - echo " → Selected: main (${!main_var})" - else - echo " → Main version not available" - fi - ;; - *) - echo " → Invalid choice, using main" - CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="main" - ;; + if [[ -n "${!main_var}" ]]; then + echo " → Selected: main (${!main_var})" + else + echo " → Main version not available" + fi + ;; + *) + echo " → Invalid choice, using main" + CONFIG_CACHE["PACKAGE_VERSION_${pkg^^}"]="main" + ;; esac echo "" done diff --git a/toolchain/scripts/package_versions.sh b/toolchain/scripts/package_versions.sh index 1ef6ed6d754..e5471da0f7c 100644 --- a/toolchain/scripts/package_versions.sh +++ b/toolchain/scripts/package_versions.sh @@ -129,134 +129,134 @@ load_package_vars() { local version_suffix="$2" # Optional version suffix for multi-version packages case "${package_name}" in - "gcc") - if [ "${version_suffix}" = "alt" ]; then - gcc_ver="${gcc_alt_ver}" - gcc_sha256="${gcc_alt_sha256}" - else - gcc_ver="${gcc_main_ver}" - gcc_sha256="${gcc_main_sha256}" - fi - ;; - "cmake") - if [ "${version_suffix}" = "alt" ]; then - cmake_ver="${cmake_alt_ver}" - else - cmake_ver="${cmake_main_ver}" - fi - ;; - "openmpi") - if [ "${OPENMPI_4TH}" = "yes" ]; then - echo "WARNING: OPENMPI_4TH=yes is deprecated. Please use 'alt' parameter instead." >&2 - openmpi_ver="${openmpi_alt_ver}" - openmpi_sha256="${openmpi_alt_sha256}" - elif [ "${version_suffix}" = "alt" ]; then - openmpi_ver="${openmpi_alt_ver}" - openmpi_sha256="${openmpi_alt_sha256}" - else - openmpi_ver="${openmpi_main_ver}" - openmpi_sha256="${openmpi_main_sha256}" - fi - ;; - "mpich") - if [ "${version_suffix}" = "alt" ]; then - mpich_ver="${mpich_alt_ver}" - mpich_sha256="${mpich_alt_sha256}" - else - mpich_ver="${mpich_main_ver}" - mpich_sha256="${mpich_main_sha256}" - fi - ;; - "openblas") - if [ "${version_suffix}" = "alt" ]; then - openblas_ver="${openblas_alt_ver}" - openblas_sha256="${openblas_alt_sha256}" - else - openblas_ver="${openblas_main_ver}" - openblas_sha256="${openblas_main_sha256}" - fi - ;; - "elpa") - if [ "${version_suffix}" = "alt" ]; then - elpa_ver="${elpa_alt_ver}" - elpa_sha256="${elpa_alt_sha256}" - else - elpa_ver="${elpa_main_ver}" - elpa_sha256="${elpa_main_sha256}" - fi - ;; - "fftw") - if [ "${version_suffix}" = "alt" ]; then - fftw_ver="${fftw_alt_ver}" - fftw_sha256="${fftw_alt_sha256}" - else - fftw_ver="${fftw_main_ver}" - fftw_sha256="${fftw_main_sha256}" - fi - ;; - "libxc") - if [ "${version_suffix}" = "alt" ]; then - libxc_ver="${libxc_alt_ver}" - libxc_sha256="${libxc_alt_sha256}" - else - libxc_ver="${libxc_main_ver}" - libxc_sha256="${libxc_main_sha256}" - fi - ;; - "scalapack") - if [ "${version_suffix}" = "alt" ]; then - scalapack_ver="${scalapack_alt_ver}" - scalapack_sha256="${scalapack_alt_sha256}" - else - scalapack_ver="${scalapack_main_ver}" - scalapack_sha256="${scalapack_main_sha256}" - fi - ;; - "dftd4") - dftd4_ver="${dftd4_ver}" - dftd4_sha256="${dftd4_sha256}" - ;; - "libtorch") - if [ "${version_suffix}" = "alt" ]; then - libtorch_ver="${libtorch_alt_ver}" - libtorch_sha256="${libtorch_alt_sha256}" - else - libtorch_ver="${libtorch_main_ver}" - libtorch_sha256="${libtorch_main_sha256}" - fi - ;; - "libnpy") - if [ "${version_suffix}" = "alt" ]; then - libnpy_ver="${libnpy_alt_ver}" - libnpy_sha256="${libnpy_alt_sha256}" - else - libnpy_ver="${libnpy_main_ver}" - libnpy_sha256="${libnpy_main_sha256}" - fi - ;; - "cereal") - cereal_ver="${cereal_ver}" - cereal_sha256="${cereal_sha256}" - ;; - "libcomm") - libcomm_ver="${libcomm_ver}" - libcomm_sha256="${libcomm_sha256}" - ;; - "libri") - libri_ver="${libri_ver}" - libri_sha256="${libri_sha256}" - ;; - "json") - json_ver="${json_ver}" - json_sha256="${json_sha256}" - ;; - "nep") - nep_ver="${nep_ver}" - nep_sha256="${nep_sha256}" - ;; - *) - echo "Error: Unknown package '${package_name}'" - return 1 - ;; + "gcc") + if [ "${version_suffix}" = "alt" ]; then + gcc_ver="${gcc_alt_ver}" + gcc_sha256="${gcc_alt_sha256}" + else + gcc_ver="${gcc_main_ver}" + gcc_sha256="${gcc_main_sha256}" + fi + ;; + "cmake") + if [ "${version_suffix}" = "alt" ]; then + cmake_ver="${cmake_alt_ver}" + else + cmake_ver="${cmake_main_ver}" + fi + ;; + "openmpi") + if [ "${OPENMPI_4TH}" = "yes" ]; then + echo "WARNING: OPENMPI_4TH=yes is deprecated. Please use 'alt' parameter instead." >&2 + openmpi_ver="${openmpi_alt_ver}" + openmpi_sha256="${openmpi_alt_sha256}" + elif [ "${version_suffix}" = "alt" ]; then + openmpi_ver="${openmpi_alt_ver}" + openmpi_sha256="${openmpi_alt_sha256}" + else + openmpi_ver="${openmpi_main_ver}" + openmpi_sha256="${openmpi_main_sha256}" + fi + ;; + "mpich") + if [ "${version_suffix}" = "alt" ]; then + mpich_ver="${mpich_alt_ver}" + mpich_sha256="${mpich_alt_sha256}" + else + mpich_ver="${mpich_main_ver}" + mpich_sha256="${mpich_main_sha256}" + fi + ;; + "openblas") + if [ "${version_suffix}" = "alt" ]; then + openblas_ver="${openblas_alt_ver}" + openblas_sha256="${openblas_alt_sha256}" + else + openblas_ver="${openblas_main_ver}" + openblas_sha256="${openblas_main_sha256}" + fi + ;; + "elpa") + if [ "${version_suffix}" = "alt" ]; then + elpa_ver="${elpa_alt_ver}" + elpa_sha256="${elpa_alt_sha256}" + else + elpa_ver="${elpa_main_ver}" + elpa_sha256="${elpa_main_sha256}" + fi + ;; + "fftw") + if [ "${version_suffix}" = "alt" ]; then + fftw_ver="${fftw_alt_ver}" + fftw_sha256="${fftw_alt_sha256}" + else + fftw_ver="${fftw_main_ver}" + fftw_sha256="${fftw_main_sha256}" + fi + ;; + "libxc") + if [ "${version_suffix}" = "alt" ]; then + libxc_ver="${libxc_alt_ver}" + libxc_sha256="${libxc_alt_sha256}" + else + libxc_ver="${libxc_main_ver}" + libxc_sha256="${libxc_main_sha256}" + fi + ;; + "scalapack") + if [ "${version_suffix}" = "alt" ]; then + scalapack_ver="${scalapack_alt_ver}" + scalapack_sha256="${scalapack_alt_sha256}" + else + scalapack_ver="${scalapack_main_ver}" + scalapack_sha256="${scalapack_main_sha256}" + fi + ;; + "dftd4") + dftd4_ver="${dftd4_ver}" + dftd4_sha256="${dftd4_sha256}" + ;; + "libtorch") + if [ "${version_suffix}" = "alt" ]; then + libtorch_ver="${libtorch_alt_ver}" + libtorch_sha256="${libtorch_alt_sha256}" + else + libtorch_ver="${libtorch_main_ver}" + libtorch_sha256="${libtorch_main_sha256}" + fi + ;; + "libnpy") + if [ "${version_suffix}" = "alt" ]; then + libnpy_ver="${libnpy_alt_ver}" + libnpy_sha256="${libnpy_alt_sha256}" + else + libnpy_ver="${libnpy_main_ver}" + libnpy_sha256="${libnpy_main_sha256}" + fi + ;; + "cereal") + cereal_ver="${cereal_ver}" + cereal_sha256="${cereal_sha256}" + ;; + "libcomm") + libcomm_ver="${libcomm_ver}" + libcomm_sha256="${libcomm_sha256}" + ;; + "libri") + libri_ver="${libri_ver}" + libri_sha256="${libri_sha256}" + ;; + "json") + json_ver="${json_ver}" + json_sha256="${json_sha256}" + ;; + "nep") + nep_ver="${nep_ver}" + nep_sha256="${nep_sha256}" + ;; + *) + echo "Error: Unknown package '${package_name}'" + return 1 + ;; esac } diff --git a/toolchain/scripts/stage0/install_amd.sh b/toolchain/scripts/stage0/install_amd.sh index bd52cb74572..82f934c7331 100755 --- a/toolchain/scripts/stage0/install_amd.sh +++ b/toolchain/scripts/stage0/install_amd.sh @@ -23,49 +23,49 @@ mkdir -p "${BUILDDIR}" cd "${BUILDDIR}" case "${with_amd}" in -__INSTALL__) - echo "==================== Installing the AMD compiler ======================" - report_error ${LINENO} "To install the AMD compiler, please contact your system administrator." - exit 1 - ;; -__SYSTEM__) - echo "==================== Finding AMD compiler from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_command clang "amd" && CC="$(realpath $(command -v clang))" || exit 1 - check_command clang++ "amd" && CXX="$(realpath $(command -v clang++))" || exit 1 - if [ "${WITH_FLANG}" = "yes" ]; then - check_command flang "amd" && FC="$(realpath $(command -v flang))" || exit 1 - else - check_command gfortran "gcc" && FC="gfortran" || exit 1 - add_lib_from_paths GCC_LDFLAGS "libgfortran.*" ${LIB_PATHS} - fi - F90="${FC}" - F77="${FC}" - ;; -__DONTUSE__) - # Nothing to do - ;; -*) - echo "==================== Linking AMD compiler to user paths ====================" - pkg_install_dir="${with_amd}" - check_dir "${pkg_install_dir}/bin" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - check_command ${pkg_install_dir}/bin/clang "amd" && CC="${pkg_install_dir}/bin/clang" || exit 1 - check_command ${pkg_install_dir}/bin/clang++ "amd" && CXX="${pkg_install_dir}/bin/clang++" || exit 1 - if [ "${WITH_FLANG}" = "yes" ]; then - check_command ${pkg_install_dir}/bin/flang "amd" && FC="${pkg_install_dir}/bin/flang" || exit 1 - else - check_command gfortran "gcc" && FC="$(command -v gfortran)" || exit 1 - fi - F90="${FC}" - F77="${FC}" - AMD_CFLAGS="-I'${pkg_install_dir}/include'" - AMD_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; + __INSTALL__) + echo "==================== Installing the AMD compiler ======================" + report_error ${LINENO} "To install the AMD compiler, please contact your system administrator." + exit 1 + ;; + __SYSTEM__) + echo "==================== Finding AMD compiler from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_command clang "amd" && CC="$(realpath $(command -v clang))" || exit 1 + check_command clang++ "amd" && CXX="$(realpath $(command -v clang++))" || exit 1 + if [ "${WITH_FLANG}" = "yes" ]; then + check_command flang "amd" && FC="$(realpath $(command -v flang))" || exit 1 + else + check_command gfortran "gcc" && FC="gfortran" || exit 1 + add_lib_from_paths GCC_LDFLAGS "libgfortran.*" ${LIB_PATHS} + fi + F90="${FC}" + F77="${FC}" + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking AMD compiler to user paths ====================" + pkg_install_dir="${with_amd}" + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + check_command ${pkg_install_dir}/bin/clang "amd" && CC="${pkg_install_dir}/bin/clang" || exit 1 + check_command ${pkg_install_dir}/bin/clang++ "amd" && CXX="${pkg_install_dir}/bin/clang++" || exit 1 + if [ "${WITH_FLANG}" = "yes" ]; then + check_command ${pkg_install_dir}/bin/flang "amd" && FC="${pkg_install_dir}/bin/flang" || exit 1 + else + check_command gfortran "gcc" && FC="$(command -v gfortran)" || exit 1 + fi + F90="${FC}" + F77="${FC}" + AMD_CFLAGS="-I'${pkg_install_dir}/include'" + AMD_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "${with_amd}" != "__DONTUSE__" ]; then echo "CC is ${CC}" diff --git a/toolchain/scripts/stage0/install_cmake.sh b/toolchain/scripts/stage0/install_cmake.sh index cb9d00369c0..ec291260251 100755 --- a/toolchain/scripts/stage0/install_cmake.sh +++ b/toolchain/scripts/stage0/install_cmake.sh @@ -40,75 +40,75 @@ source "${INSTALLDIR}"/toolchain.env ! [ -d "${BUILDDIR}" ] && mkdir -p "${BUILDDIR}" cd "${BUILDDIR}" case "${with_cmake}" in -__INSTALL__) - echo "==================== Installing CMake ====================" - case "$(uname -s):${SYSTEM_ARCH}" in - Darwin:x86_64 | Darwin:arm64) - cmake_arch="macos-universal" - cmake_checksum_arch="macos" - ;; - Linux:x86_64) - cmake_arch="linux-x86_64" - cmake_checksum_arch="x86_64" - ;; - Linux:arm64) - cmake_arch="linux-aarch64" - cmake_checksum_arch="aarch64" - ;; - *) - report_error ${LINENO} \ - "cmake installation for ARCH=${SYSTEM_ARCH} under $(uname -s) is not supported. You can try to use the system installation using the flag \"--with-cmake=system\" instead." - exit 1 - ;; - esac + __INSTALL__) + echo "==================== Installing CMake ====================" + case "$(uname -s):${SYSTEM_ARCH}" in + Darwin:x86_64 | Darwin:arm64) + cmake_arch="macos-universal" + cmake_checksum_arch="macos" + ;; + Linux:x86_64) + cmake_arch="linux-x86_64" + cmake_checksum_arch="x86_64" + ;; + Linux:arm64) + cmake_arch="linux-aarch64" + cmake_checksum_arch="aarch64" + ;; + *) + report_error ${LINENO} \ + "cmake installation for ARCH=${SYSTEM_ARCH} under $(uname -s) is not supported. You can try to use the system installation using the flag \"--with-cmake=system\" instead." + exit 1 + ;; + esac - if [ "${version_suffix}" = "alt" ]; then - cmake_checksum_var="cmake_alt_sha256_${cmake_checksum_arch}" - else - cmake_checksum_var="cmake_main_sha256_${cmake_checksum_arch}" - fi - cmake_sha256="${!cmake_checksum_var}" + if [ "${version_suffix}" = "alt" ]; then + cmake_checksum_var="cmake_alt_sha256_${cmake_checksum_arch}" + else + cmake_checksum_var="cmake_main_sha256_${cmake_checksum_arch}" + fi + cmake_sha256="${!cmake_checksum_var}" - pkg_install_dir="${INSTALLDIR}/cmake-${cmake_ver}" - #pkg_install_dir="${HOME}/apps/cmake/${cmake_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - cmake_pkg="cmake-${cmake_ver}-${cmake_arch}.tar.gz" - if verify_checksums "${install_lock_file}"; then - echo "cmake-${cmake_ver} is already installed, skipping it." - else - url="https://cmake.org/files/v${cmake_ver%.*}/${cmake_pkg}" - retrieve_package "${cmake_sha256}" "${cmake_pkg}" "${url}" + pkg_install_dir="${INSTALLDIR}/cmake-${cmake_ver}" + #pkg_install_dir="${HOME}/apps/cmake/${cmake_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + cmake_pkg="cmake-${cmake_ver}-${cmake_arch}.tar.gz" + if verify_checksums "${install_lock_file}"; then + echo "cmake-${cmake_ver} is already installed, skipping it." + else + url="https://cmake.org/files/v${cmake_ver%.*}/${cmake_pkg}" + retrieve_package "${cmake_sha256}" "${cmake_pkg}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + mkdir -p ${pkg_install_dir} + if [ "${cmake_arch}" = "macos-universal" ]; then + strip_components=3 + else + strip_components=1 + fi + tar --strip-components=${strip_components} -xvf ${cmake_pkg} -C ${pkg_install_dir} >install.log 2>&1 || tail_excerpt install.log + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage0/$(basename ${SCRIPT_NAME})" + fi + ;; + __SYSTEM__) + echo "==================== Finding CMake from system paths ====================" if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" + echo "--pack-run mode specified, skip system check" exit 0 fi - echo "Installing from scratch into ${pkg_install_dir}" - mkdir -p ${pkg_install_dir} - if [ "${cmake_arch}" = "macos-universal" ]; then - strip_components=3 - else - strip_components=1 - fi - tar --strip-components=${strip_components} -xvf ${cmake_pkg} -C ${pkg_install_dir} >install.log 2>&1 || tail_excerpt install.log - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage0/$(basename ${SCRIPT_NAME})" - fi - ;; -__SYSTEM__) - echo "==================== Finding CMake from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_command cmake "cmake" - ;; -__DONTUSE__) - # Nothing to do - ;; -*) - echo "==================== Linking CMake to user paths ====================" - pkg_install_dir="$with_cmake" - check_dir "${with_cmake}/bin" - ;; + check_command cmake "cmake" + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking CMake to user paths ====================" + pkg_install_dir="$with_cmake" + check_dir "${with_cmake}/bin" + ;; esac if [ "${with_cmake}" != "__DONTUSE__" ]; then if [ "${with_cmake}" != "__SYSTEM__" ]; then diff --git a/toolchain/scripts/stage0/install_gcc.sh b/toolchain/scripts/stage0/install_gcc.sh index 7eba97ba127..83cf6ab7346 100755 --- a/toolchain/scripts/stage0/install_gcc.sh +++ b/toolchain/scripts/stage0/install_gcc.sh @@ -43,162 +43,162 @@ TSANFLAGS="" cd "${BUILDDIR}" case "${with_gcc}" in -__INSTALL__) - echo "==================== Installing GCC ====================" - pkg_install_dir="${INSTALLDIR}/gcc-${gcc_ver}" - repack_filename="gcc-${gcc_ver}-with-prereq.tar.gz" - repkg_install_dir="${INSTALLDIR}/${repack_filename}" - #pkg_install_dir="${HOME}/apps/gcc/${gcc_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - if verify_checksums "${install_lock_file}"; then - echo "gcc-${gcc_ver} is already installed, skipping it." - else - # Check if repackaged tarball exists for offline installation - if [ -f "${repack_filename}" ]; then - echo "${repack_filename} is found, extracting it..." - tar -xzf "${repack_filename}" - echo "Successfully extracted ${repack_filename}" + __INSTALL__) + echo "==================== Installing GCC ====================" + pkg_install_dir="${INSTALLDIR}/gcc-${gcc_ver}" + repack_filename="gcc-${gcc_ver}-with-prereq.tar.gz" + repkg_install_dir="${INSTALLDIR}/${repack_filename}" + #pkg_install_dir="${HOME}/apps/gcc/${gcc_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "gcc-${gcc_ver} is already installed, skipping it." else - url=https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-${gcc_ver}/gcc-${gcc_ver}.tar.gz - retrieve_package "${gcc_sha256}" "gcc-${gcc_ver}.tar.gz" "${url}" - fi - [ -d gcc-${gcc_ver} ] && rm -rf gcc-${gcc_ver} - tar -xzf gcc-${gcc_ver}.tar.gz + # Check if repackaged tarball exists for offline installation + if [ -f "${repack_filename}" ]; then + echo "${repack_filename} is found, extracting it..." + tar -xzf "${repack_filename}" + echo "Successfully extracted ${repack_filename}" + else + url=https://mirrors.tuna.tsinghua.edu.cn/gnu/gcc/gcc-${gcc_ver}/gcc-${gcc_ver}.tar.gz + retrieve_package "${gcc_sha256}" "gcc-${gcc_ver}.tar.gz" "${url}" + fi + [ -d gcc-${gcc_ver} ] && rm -rf gcc-${gcc_ver} + tar -xzf gcc-${gcc_ver}.tar.gz - echo "Installing GCC from scratch into ${pkg_install_dir}" - cd gcc-${gcc_ver} + echo "Installing GCC from scratch into ${pkg_install_dir}" + cd gcc-${gcc_ver} - # Check network connectivity before downloading prerequisites - if curl -s --connect-timeout 5 https://gcc.gnu.org >/dev/null 2>&1; then - echo "Downloading prerequisites from official GCC site..." - # Try official site first - if ./contrib/download_prerequisites >prereq.log 2>&1; then - echo "Prerequisites downloaded successfully from official site" + # Check network connectivity before downloading prerequisites + if curl -s --connect-timeout 5 https://gcc.gnu.org >/dev/null 2>&1; then + echo "Downloading prerequisites from official GCC site..." + # Try official site first + if ./contrib/download_prerequisites >prereq.log 2>&1; then + echo "Prerequisites downloaded successfully from official site" + else + echo "Official site failed, trying mirror site..." + # Fallback to cp2k.org mirror + sed -i 's|http://gcc.gnu.org/pub/gcc/infrastructure/|https://cp2k.org/static/downloads/|' ./contrib/download_prerequisites + ./contrib/download_prerequisites >prereq.log 2>&1 || tail -n ${LOG_LINES} prereq.log + fi else - echo "Official site failed, trying mirror site..." - # Fallback to cp2k.org mirror - sed -i 's|http://gcc.gnu.org/pub/gcc/infrastructure/|https://cp2k.org/static/downloads/|' ./contrib/download_prerequisites - ./contrib/download_prerequisites >prereq.log 2>&1 || tail -n ${LOG_LINES} prereq.log + echo "Network unavailable, skipping prerequisites download (offline mode)" fi - else - echo "Network unavailable, skipping prerequisites download (offline mode)" - fi - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode: repackaging GCC with prerequisites for offline installation" - cd .. - # Create a new tarball with prerequisites included - repack_filename="gcc-${gcc_ver}-with-prereq.tar.gz" - echo "Creating ${repack_filename}..." - tar -czf "${repack_filename}" gcc-${gcc_ver}/ - echo "Successfully created ${repack_filename} for offline installation" - echo "This package contains GCC source code with all prerequisites ready for offline build" - exit 0 - fi - GCCROOT=${PWD} - mkdir obj - cd obj - # TODO: Maybe use --disable-libquadmath-support to improve static linking: - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46539 - # - # TODO: Maybe use --disable-gnu-unique-object to improve static linking: - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60348#c13 - # https://stackoverflow.com/questions/11931420 - # - # TODO: Unfortunately, we can not simply use --disable-shared, because - # it would break OpenBLAS build and probably others too. - COMMON_FLAGS="-O2 -fPIC -fno-omit-frame-pointer -fopenmp -g" - CFLAGS="${COMMON_FLAGS}" - CXXFLAGS="${CFLAGS}" - FCFLAGS="${COMMON_FLAGS} -fbacktrace" - ${GCCROOT}/configure --prefix="${pkg_install_dir}" \ - --libdir="${pkg_install_dir}/lib" \ - --enable-languages=c,c++,fortran \ - --disable-multilib --disable-bootstrap \ - --enable-lto \ - --enable-plugins \ - >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log - make -j $(get_nprocs) \ - CFLAGS="${CFLAGS}" \ - CXXFLAGS="${CXXFLAGS}" \ - FCFLAGS="${FCFLAGS}" \ - >make.log 2>&1 || tail -n ${LOG_LINES} make.log - make -j $(get_nprocs) install >install.log 2>&1 || tail -n ${LOG_LINES} install.log - # thread sanitizer - if [ "${ENABLE_TSAN}" = "__TRUE__" ]; then - # now the tricky bit... we need to recompile in particular - # libgomp with -fsanitize=thread.. there is not configure - # option for this (as far as I know). we need to go in - # the build tree and recompile / reinstall with proper - # options... this is likely to break for later version of - # gcc, tested with 5.1.0 based on - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55374#c10 - cd x86_64*/libgfortran - make clean >clean.log 2>&1 || tail -n ${LOG_LINES} clean.log - CFLAGS="${CFLAGS} -fsanitize=thread" - CXXFLAGS="${CXXFLAGS} -fsanitize=thread" - FCFLAGS="${FCFLAGS} -fsanitize=thread" - make -j $(get_nprocs) \ - CFLAGS="${CFLAGS}" \ - CXXFLAGS="${CXXFLAGS}" \ - FCFLAGS="${FCFLAGS}" \ - LDFLAGS="-B$(pwd)/../libsanitizer/tsan/.libs/ -Wl,-rpath,$(pwd)/../libsanitizer/tsan/.libs/ -fsanitize=thread" \ - >make.log 2>&1 || tail -n ${LOG_LINES} make.log - make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log - cd ../libgomp - make clean >clean.log 2>&1 || tail -n ${LOG_LINES} clean.log + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode: repackaging GCC with prerequisites for offline installation" + cd .. + # Create a new tarball with prerequisites included + repack_filename="gcc-${gcc_ver}-with-prereq.tar.gz" + echo "Creating ${repack_filename}..." + tar -czf "${repack_filename}" gcc-${gcc_ver}/ + echo "Successfully created ${repack_filename} for offline installation" + echo "This package contains GCC source code with all prerequisites ready for offline build" + exit 0 + fi + GCCROOT=${PWD} + mkdir obj + cd obj + # TODO: Maybe use --disable-libquadmath-support to improve static linking: + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46539 + # + # TODO: Maybe use --disable-gnu-unique-object to improve static linking: + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60348#c13 + # https://stackoverflow.com/questions/11931420 + # + # TODO: Unfortunately, we can not simply use --disable-shared, because + # it would break OpenBLAS build and probably others too. + COMMON_FLAGS="-O2 -fPIC -fno-omit-frame-pointer -fopenmp -g" + CFLAGS="${COMMON_FLAGS}" + CXXFLAGS="${CFLAGS}" + FCFLAGS="${COMMON_FLAGS} -fbacktrace" + ${GCCROOT}/configure --prefix="${pkg_install_dir}" \ + --libdir="${pkg_install_dir}/lib" \ + --enable-languages=c,c++,fortran \ + --disable-multilib --disable-bootstrap \ + --enable-lto \ + --enable-plugins \ + >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log make -j $(get_nprocs) \ CFLAGS="${CFLAGS}" \ CXXFLAGS="${CXXFLAGS}" \ FCFLAGS="${FCFLAGS}" \ - LDFLAGS="-B$(pwd)/../libsanitizer/tsan/.libs/ -Wl,-rpath,$(pwd)/../libsanitizer/tsan/.libs/ -fsanitize=thread" \ >make.log 2>&1 || tail -n ${LOG_LINES} make.log - make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log - cd ${GCCROOT}/obj/ + make -j $(get_nprocs) install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + # thread sanitizer + if [ "${ENABLE_TSAN}" = "__TRUE__" ]; then + # now the tricky bit... we need to recompile in particular + # libgomp with -fsanitize=thread.. there is not configure + # option for this (as far as I know). we need to go in + # the build tree and recompile / reinstall with proper + # options... this is likely to break for later version of + # gcc, tested with 5.1.0 based on + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55374#c10 + cd x86_64*/libgfortran + make clean >clean.log 2>&1 || tail -n ${LOG_LINES} clean.log + CFLAGS="${CFLAGS} -fsanitize=thread" + CXXFLAGS="${CXXFLAGS} -fsanitize=thread" + FCFLAGS="${FCFLAGS} -fsanitize=thread" + make -j $(get_nprocs) \ + CFLAGS="${CFLAGS}" \ + CXXFLAGS="${CXXFLAGS}" \ + FCFLAGS="${FCFLAGS}" \ + LDFLAGS="-B$(pwd)/../libsanitizer/tsan/.libs/ -Wl,-rpath,$(pwd)/../libsanitizer/tsan/.libs/ -fsanitize=thread" \ + >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd ../libgomp + make clean >clean.log 2>&1 || tail -n ${LOG_LINES} clean.log + make -j $(get_nprocs) \ + CFLAGS="${CFLAGS}" \ + CXXFLAGS="${CXXFLAGS}" \ + FCFLAGS="${FCFLAGS}" \ + LDFLAGS="-B$(pwd)/../libsanitizer/tsan/.libs/ -Wl,-rpath,$(pwd)/../libsanitizer/tsan/.libs/ -fsanitize=thread" \ + >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd ${GCCROOT}/obj/ + fi + cd ../.. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage0/$(basename ${SCRIPT_NAME})" fi - cd ../.. - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage0/$(basename ${SCRIPT_NAME})" - fi - check_install ${pkg_install_dir}/bin/gcc "gcc" && CC="${pkg_install_dir}/bin/gcc" || exit 1 - check_install ${pkg_install_dir}/bin/g++ "gcc" && CXX="${pkg_install_dir}/bin/g++" || exit 1 - check_install ${pkg_install_dir}/bin/gfortran "gcc" && FC="${pkg_install_dir}/bin/gfortran" || exit 1 - F90="${FC}" - F77="${FC}" - GCC_CFLAGS="-I'${pkg_install_dir}/include'" - GCC_LDFLAGS="-L'${pkg_install_dir}/lib64' -L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib64' -Wl,-rpath,'${pkg_install_dir}/lib64'" - ;; -__SYSTEM__) - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - echo "==================== Finding GCC from system paths ====================" - check_command gcc "gcc" && CC="$(command -v gcc)" || exit 1 - check_command g++ "gcc" && CXX="$(command -v g++)" || exit 1 - check_command gfortran "gcc" && FC="$(command -v gfortran)" || exit 1 - F90="${FC}" - F77="${FC}" - add_include_from_paths -p GCC_CFLAGS "c++" ${INCLUDE_PATHS} - add_lib_from_paths GCC_LDFLAGS "libgfortran.*" ${LIB_PATHS} - ;; -__DONTUSE__) - # Nothing to do - ;; -*) - echo "==================== Linking GCC to user paths ====================" - pkg_install_dir="${with_gcc}" - check_dir "${pkg_install_dir}/bin" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/lib64" - check_dir "${pkg_install_dir}/include" - check_command ${pkg_install_dir}/bin/gcc "gcc" && CC="${pkg_install_dir}/bin/gcc" || exit 1 - check_command ${pkg_install_dir}/bin/g++ "gcc" && CXX="${pkg_install_dir}/bin/g++" || exit 1 - check_command ${pkg_install_dir}/bin/gfortran "gcc" && FC="${pkg_install_dir}/bin/gfortran" || exit 1 - F90="${FC}" - F77="${FC}" - GCC_CFLAGS="-I'${pkg_install_dir}/include'" - GCC_LDFLAGS="-L'${pkg_install_dir}/lib64' -L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib64' -Wl,-rpath,'${pkg_install_dir}/lib64'" - ;; + check_install ${pkg_install_dir}/bin/gcc "gcc" && CC="${pkg_install_dir}/bin/gcc" || exit 1 + check_install ${pkg_install_dir}/bin/g++ "gcc" && CXX="${pkg_install_dir}/bin/g++" || exit 1 + check_install ${pkg_install_dir}/bin/gfortran "gcc" && FC="${pkg_install_dir}/bin/gfortran" || exit 1 + F90="${FC}" + F77="${FC}" + GCC_CFLAGS="-I'${pkg_install_dir}/include'" + GCC_LDFLAGS="-L'${pkg_install_dir}/lib64' -L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib64' -Wl,-rpath,'${pkg_install_dir}/lib64'" + ;; + __SYSTEM__) + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + echo "==================== Finding GCC from system paths ====================" + check_command gcc "gcc" && CC="$(command -v gcc)" || exit 1 + check_command g++ "gcc" && CXX="$(command -v g++)" || exit 1 + check_command gfortran "gcc" && FC="$(command -v gfortran)" || exit 1 + F90="${FC}" + F77="${FC}" + add_include_from_paths -p GCC_CFLAGS "c++" ${INCLUDE_PATHS} + add_lib_from_paths GCC_LDFLAGS "libgfortran.*" ${LIB_PATHS} + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking GCC to user paths ====================" + pkg_install_dir="${with_gcc}" + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/lib64" + check_dir "${pkg_install_dir}/include" + check_command ${pkg_install_dir}/bin/gcc "gcc" && CC="${pkg_install_dir}/bin/gcc" || exit 1 + check_command ${pkg_install_dir}/bin/g++ "gcc" && CXX="${pkg_install_dir}/bin/g++" || exit 1 + check_command ${pkg_install_dir}/bin/gfortran "gcc" && FC="${pkg_install_dir}/bin/gfortran" || exit 1 + F90="${FC}" + F77="${FC}" + GCC_CFLAGS="-I'${pkg_install_dir}/include'" + GCC_LDFLAGS="-L'${pkg_install_dir}/lib64' -L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib64' -Wl,-rpath,'${pkg_install_dir}/lib64'" + ;; esac if [ "${ENABLE_TSAN}" = "__TRUE__" ]; then TSANFLAGS="-fsanitize=thread" diff --git a/toolchain/scripts/stage0/install_intel.sh b/toolchain/scripts/stage0/install_intel.sh index af63aa792bc..c00a205bd11 100755 --- a/toolchain/scripts/stage0/install_intel.sh +++ b/toolchain/scripts/stage0/install_intel.sh @@ -23,60 +23,60 @@ mkdir -p "${BUILDDIR}" cd "${BUILDDIR}" case "${with_intel}" in -__INSTALL__) - echo "==================== Installing the Intel compiler ====================" - report_error ${LINENO} "To install the Intel compiler, please contact your system administrator." - exit 1 - ;; -__SYSTEM__) - echo "==================== Finding Intel compiler from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - if [ "${intel_classic}" = "yes" ]; then - check_command icc "intel" && CC="$(realpath $(command -v icc))" || exit 1 - check_command icpc "intel" && CXX="$(realpath $(command -v icpc))" || exit 1 - check_command ifort "intel" && FC="$(realpath $(command -v ifort))" || exit 1 - else - check_command icx "intel" && CC="$(realpath $(command -v icx))" || exit 1 - check_command icpx "intel" && CXX="$(realpath $(command -v icpx))" || exit 1 - if [ "${WITH_IFX}" = "yes" ]; then - check_command ifx "intel" && FC="$(realpath $(command -v ifx))" || exit 1 - else - check_command ifort "intel" && FC="$(realpath $(command -v ifort))" || exit 1 + __INSTALL__) + echo "==================== Installing the Intel compiler ====================" + report_error ${LINENO} "To install the Intel compiler, please contact your system administrator." + exit 1 + ;; + __SYSTEM__) + echo "==================== Finding Intel compiler from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 fi - fi - F90="${FC}" - F77="${FC}" - ;; -__DONTUSE__) - # Nothing to do - ;; -*) - echo "==================== Linking Intel compiler to user paths ====================" - pkg_install_dir="${with_intel}" - check_dir "${pkg_install_dir}/bin" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - if [ "${intel_classic}" = "yes" ]; then - check_command ${pkg_install_dir}/bin/icc "intel" && CC="${pkg_install_dir}/bin/icc" || exit 1 - check_command ${pkg_install_dir}/bin/icpc "intel" && CXX="${pkg_install_dir}/bin/icpc" || exit 1 - check_command ${pkg_install_dir}/bin/ifort "intel" && FC="${pkg_install_dir}/bin/ifort" || exit 1 - else - check_command ${pkg_install_dir}/bin/icx "intel" && CC="${pkg_install_dir}/bin/icx" || exit 1 - check_command ${pkg_install_dir}/bin/icpx "intel" && CXX="${pkg_install_dir}/bin/icpx" || exit 1 - if [ "${WITH_IFX}" = "yes" ]; then - check_command ${pkg_install_dir}/bin/ifx "intel" && FC="${pkg_install_dir}/bin/ifx" || exit 1 + if [ "${intel_classic}" = "yes" ]; then + check_command icc "intel" && CC="$(realpath $(command -v icc))" || exit 1 + check_command icpc "intel" && CXX="$(realpath $(command -v icpc))" || exit 1 + check_command ifort "intel" && FC="$(realpath $(command -v ifort))" || exit 1 else + check_command icx "intel" && CC="$(realpath $(command -v icx))" || exit 1 + check_command icpx "intel" && CXX="$(realpath $(command -v icpx))" || exit 1 + if [ "${WITH_IFX}" = "yes" ]; then + check_command ifx "intel" && FC="$(realpath $(command -v ifx))" || exit 1 + else + check_command ifort "intel" && FC="$(realpath $(command -v ifort))" || exit 1 + fi + fi + F90="${FC}" + F77="${FC}" + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking Intel compiler to user paths ====================" + pkg_install_dir="${with_intel}" + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + if [ "${intel_classic}" = "yes" ]; then + check_command ${pkg_install_dir}/bin/icc "intel" && CC="${pkg_install_dir}/bin/icc" || exit 1 + check_command ${pkg_install_dir}/bin/icpc "intel" && CXX="${pkg_install_dir}/bin/icpc" || exit 1 check_command ${pkg_install_dir}/bin/ifort "intel" && FC="${pkg_install_dir}/bin/ifort" || exit 1 + else + check_command ${pkg_install_dir}/bin/icx "intel" && CC="${pkg_install_dir}/bin/icx" || exit 1 + check_command ${pkg_install_dir}/bin/icpx "intel" && CXX="${pkg_install_dir}/bin/icpx" || exit 1 + if [ "${WITH_IFX}" = "yes" ]; then + check_command ${pkg_install_dir}/bin/ifx "intel" && FC="${pkg_install_dir}/bin/ifx" || exit 1 + else + check_command ${pkg_install_dir}/bin/ifort "intel" && FC="${pkg_install_dir}/bin/ifort" || exit 1 + fi fi - fi - F90="${FC}" - F77="${FC}" - INTEL_CFLAGS="-I'${pkg_install_dir}/include'" - INTEL_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; + F90="${FC}" + F77="${FC}" + INTEL_CFLAGS="-I'${pkg_install_dir}/include'" + INTEL_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "${with_intel}" != "__DONTUSE__" ]; then echo "CC is ${CC}" diff --git a/toolchain/scripts/stage1/install_intelmpi.sh b/toolchain/scripts/stage1/install_intelmpi.sh index db9c826b99b..9fd574e79e0 100755 --- a/toolchain/scripts/stage1/install_intelmpi.sh +++ b/toolchain/scripts/stage1/install_intelmpi.sh @@ -24,33 +24,70 @@ mkdir -p "${BUILDDIR}" cd "${BUILDDIR}" case "${with_intelmpi}" in -__INSTALL__) - echo "==================== Installing Intel MPI ====================" - report_error ${LINENO} "To install Intel MPI, please contact your system administrator." - exit 1 - ;; -__SYSTEM__) - echo "==================== Finding Intel MPI from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - else - check_command mpiexec "intelmpi" && MPIRUN="$(realpath $(command -v mpiexec))" - if [ "${intel_classic}" = "yes" ]; then - # if intel compiler used as classic, so as intelmpi - export INTELMPI_CLASSIC="yes" + __INSTALL__) + echo "==================== Installing Intel MPI ====================" + report_error ${LINENO} "To install Intel MPI, please contact your system administrator." + exit 1 + ;; + __SYSTEM__) + echo "==================== Finding Intel MPI from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + else + check_command mpiexec "intelmpi" && MPIRUN="$(realpath $(command -v mpiexec))" + if [ "${intel_classic}" = "yes" ]; then + # if intel compiler used as classic, so as intelmpi + export INTELMPI_CLASSIC="yes" + fi + if [ "${with_intel}" != "__DONTUSE__" ]; then + if [ "${INTELMPI_CLASSIC}" = "yes" ]; then + check_command mpiicc "intelmpi" && MPICC="$(realpath $(command -v mpiicc))" || exit 1 + check_command mpiicpc "intelmpi" && MPICXX="$(realpath $(command -v mpiicpc))" || exit 1 + check_command mpiifort "intelmpi" && MPIFC="$(realpath $(command -v mpiifort))" || exit 1 + else + check_command mpiicx "intelmpi" && MPICC="$(realpath $(command -v mpiicx))" || exit 1 + check_command mpiicpx "intelmpi" && MPICXX="$(realpath $(command -v mpiicpx))" || exit 1 + if [ "${WITH_IFX}" == "yes" ]; then + check_command mpiifx "intelmpi" && MPIFC="$(realpath $(command -v mpiifx))" || exit 1 + else + check_command mpiifort "intelmpi" && MPIFC="$(realpath $(command -v mpiifort))" || exit 1 + fi + fi + else + echo "The use of Intel MPI is only supported with the Intel compiler" + exit 1 + fi + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + # include path is already handled by compiler wrapper scripts (can cause wrong mpi.mod with GNU Fortran) + # add_include_from_paths INTELMPI_CFLAGS "mpi.h" $INCLUDE_PATHS + add_lib_from_paths INTELMPI_LDFLAGS "libmpi.*" $LIB_PATHS + check_lib -lmpi "intelmpi" + check_lib -lmpicxx "intelmpi" fi + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking INTELMPI to user paths ====================" + pkg_install_dir="${with_intelmpi}" + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + check_command ${pkg_install_dir}/bin/mpiexec "intel" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 if [ "${with_intel}" != "__DONTUSE__" ]; then if [ "${INTELMPI_CLASSIC}" = "yes" ]; then - check_command mpiicc "intelmpi" && MPICC="$(realpath $(command -v mpiicc))" || exit 1 - check_command mpiicpc "intelmpi" && MPICXX="$(realpath $(command -v mpiicpc))" || exit 1 - check_command mpiifort "intelmpi" && MPIFC="$(realpath $(command -v mpiifort))" || exit 1 + check_command ${pkg_install_dir}/bin/mpiicc "intel" && MPICC="${pkg_install_dir}/bin/mpiicc" || exit 1 + check_command ${pkg_install_dir}/bin/mpiicpc "intel" && MPICXX="${pkg_install_dir}/bin/mpiicpc" || exit 1 + check_command ${pkg_install_dir}/bin/mpiifort "intel" && MPIFC="${pkg_install_dir}/bin/mpiifort" || exit 1 else - check_command mpiicx "intelmpi" && MPICC="$(realpath $(command -v mpiicx))" || exit 1 - check_command mpiicpx "intelmpi" && MPICXX="$(realpath $(command -v mpiicpx))" || exit 1 - if [ "${WITH_IFX}" == "yes" ]; then - check_command mpiifx "intelmpi" && MPIFC="$(realpath $(command -v mpiifx))" || exit 1 + check_command ${pkg_install_dir}/bin/mpiicx "intel" && MPICC="${pkg_install_dir}/bin/mpiicx" || exit 1 + check_command ${pkg_install_dir}/bin/mpiicpx "intel" && MPICXX="${pkg_install_dir}/bin/mpiicpx" || exit 1 + if [ "${WITH_IFX}" = "yes" ]; then + check_command ${pkg_install_dir}/bin/mpiifx "intel" && MPIFC="${pkg_install_dir}/bin/mpiifx" || exit 1 else - check_command mpiifort "intelmpi" && MPIFC="$(realpath $(command -v mpiifort))" || exit 1 + check_command ${pkg_install_dir}/bin/mpiifort "intel" && MPIFC="${pkg_install_dir}/bin/mpiifort" || exit 1 fi fi else @@ -60,46 +97,9 @@ __SYSTEM__) MPIFORT="${MPIFC}" MPIF77="${MPIFC}" # include path is already handled by compiler wrapper scripts (can cause wrong mpi.mod with GNU Fortran) - # add_include_from_paths INTELMPI_CFLAGS "mpi.h" $INCLUDE_PATHS - add_lib_from_paths INTELMPI_LDFLAGS "libmpi.*" $LIB_PATHS - check_lib -lmpi "intelmpi" - check_lib -lmpicxx "intelmpi" - fi - ;; -__DONTUSE__) - # Nothing to do - ;; -*) - echo "==================== Linking INTELMPI to user paths ====================" - pkg_install_dir="${with_intelmpi}" - check_dir "${pkg_install_dir}/bin" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - check_command ${pkg_install_dir}/bin/mpiexec "intel" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 - if [ "${with_intel}" != "__DONTUSE__" ]; then - if [ "${INTELMPI_CLASSIC}" = "yes" ]; then - check_command ${pkg_install_dir}/bin/mpiicc "intel" && MPICC="${pkg_install_dir}/bin/mpiicc" || exit 1 - check_command ${pkg_install_dir}/bin/mpiicpc "intel" && MPICXX="${pkg_install_dir}/bin/mpiicpc" || exit 1 - check_command ${pkg_install_dir}/bin/mpiifort "intel" && MPIFC="${pkg_install_dir}/bin/mpiifort" || exit 1 - else - check_command ${pkg_install_dir}/bin/mpiicx "intel" && MPICC="${pkg_install_dir}/bin/mpiicx" || exit 1 - check_command ${pkg_install_dir}/bin/mpiicpx "intel" && MPICXX="${pkg_install_dir}/bin/mpiicpx" || exit 1 - if [ "${WITH_IFX}" = "yes" ]; then - check_command ${pkg_install_dir}/bin/mpiifx "intel" && MPIFC="${pkg_install_dir}/bin/mpiifx" || exit 1 - else - check_command ${pkg_install_dir}/bin/mpiifort "intel" && MPIFC="${pkg_install_dir}/bin/mpiifort" || exit 1 - fi - fi - else - echo "The use of Intel MPI is only supported with the Intel compiler" - exit 1 - fi - MPIFORT="${MPIFC}" - MPIF77="${MPIFC}" - # include path is already handled by compiler wrapper scripts (can cause wrong mpi.mod with GNU Fortran) - INTELMPI_CFLAGS="-I'${pkg_install_dir}/include'" - INTELMPI_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; + INTELMPI_CFLAGS="-I'${pkg_install_dir}/include'" + INTELMPI_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "${with_intelmpi}" != "__DONTUSE__" ]; then if [ "${intel_classic}" = "yes" ]; then diff --git a/toolchain/scripts/stage1/install_mpich.sh b/toolchain/scripts/stage1/install_mpich.sh index eb571995dd4..576186900ab 100755 --- a/toolchain/scripts/stage1/install_mpich.sh +++ b/toolchain/scripts/stage1/install_mpich.sh @@ -41,100 +41,100 @@ source "${INSTALLDIR}"/toolchain.env cd "${BUILDDIR}" case "${with_mpich}" in -__INSTALL__) - echo "==================== Installing MPICH ====================" - pkg_install_dir="${INSTALLDIR}/mpich-${mpich_ver}" - #pkg_install_dir="${HOME}/apps/mpich/${mpich_ver}-intel" - install_lock_file="${pkg_install_dir}/install_successful" - url="https://www.mpich.org/static/downloads/${mpich_ver}/${mpich_pkg}" - if verify_checksums "${install_lock_file}"; then - echo "mpich-${mpich_ver} is already installed, skipping it." - else - retrieve_package "${mpich_sha256}" "${mpich_pkg}" "${url}" + __INSTALL__) + echo "==================== Installing MPICH ====================" + pkg_install_dir="${INSTALLDIR}/mpich-${mpich_ver}" + #pkg_install_dir="${HOME}/apps/mpich/${mpich_ver}-intel" + install_lock_file="${pkg_install_dir}/install_successful" + url="https://www.mpich.org/static/downloads/${mpich_ver}/${mpich_pkg}" + if verify_checksums "${install_lock_file}"; then + echo "mpich-${mpich_ver} is already installed, skipping it." + else + retrieve_package "${mpich_sha256}" "${mpich_pkg}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir} for MPICH device ${MPICH_DEVICE}" + [ -d mpich-${mpich_ver} ] && rm -rf mpich-${mpich_ver} + tar -xzf ${mpich_pkg} + cd mpich-${mpich_ver} + unset F90 + unset F90FLAGS + + # workaround for compilation with GCC >= 10, until properly fixed: + # https://github.com/pmodels/mpich/issues/4300 + if ("${FC}" --version | grep -q 'GNU'); then + compat_flag=$(allowed_gfortran_flags "-fallow-argument-mismatch") + fi + ./configure \ + --prefix="${pkg_install_dir}" \ + --libdir="${pkg_install_dir}/lib" \ + FFLAGS="${FCFLAGS} ${compat_flag}" \ + FCFLAGS="${FCFLAGS} ${compat_flag}" \ + --with-device=${MPICH_DEVICE} \ + >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage1/$(basename ${SCRIPT_NAME})" + fi if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" + echo "--pack-run mode specified, skip system check" exit 0 fi - echo "Installing from scratch into ${pkg_install_dir} for MPICH device ${MPICH_DEVICE}" - [ -d mpich-${mpich_ver} ] && rm -rf mpich-${mpich_ver} - tar -xzf ${mpich_pkg} - cd mpich-${mpich_ver} - unset F90 - unset F90FLAGS - - # workaround for compilation with GCC >= 10, until properly fixed: - # https://github.com/pmodels/mpich/issues/4300 - if ("${FC}" --version | grep -q 'GNU'); then - compat_flag=$(allowed_gfortran_flags "-fallow-argument-mismatch") + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + check_install ${pkg_install_dir}/bin/mpiexec "mpich" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 + check_install ${pkg_install_dir}/bin/mpicc "mpich" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 + check_install ${pkg_install_dir}/bin/mpicxx "mpich" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 + check_install ${pkg_install_dir}/bin/mpifort "mpich" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + MPICH_CFLAGS="-I'${pkg_install_dir}/include'" + MPICH_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding MPICH from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 fi - ./configure \ - --prefix="${pkg_install_dir}" \ - --libdir="${pkg_install_dir}/lib" \ - FFLAGS="${FCFLAGS} ${compat_flag}" \ - FCFLAGS="${FCFLAGS} ${compat_flag}" \ - --with-device=${MPICH_DEVICE} \ - >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log - make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log - make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log - cd .. - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage1/$(basename ${SCRIPT_NAME})" - fi - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_dir "${pkg_install_dir}/bin" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - check_install ${pkg_install_dir}/bin/mpiexec "mpich" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 - check_install ${pkg_install_dir}/bin/mpicc "mpich" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 - check_install ${pkg_install_dir}/bin/mpicxx "mpich" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 - check_install ${pkg_install_dir}/bin/mpifort "mpich" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 - MPIFORT="${MPIFC}" - MPIF77="${MPIFC}" - MPICH_CFLAGS="-I'${pkg_install_dir}/include'" - MPICH_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; -__SYSTEM__) - echo "==================== Finding MPICH from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_command mpiexec "mpich" && MPIRUN="$(command -v mpiexec)" - check_command mpicc "mpich" && MPICC="$(command -v mpicc)" || exit 1 - if [ $(command -v mpic++ >/dev/null 2>&1) ]; then - check_command mpic++ "mpich" && MPICXX="$(command -v mpic++)" || exit 1 - else - check_command mpicxx "mpich" && MPICXX="$(command -v mpicxx)" || exit 1 - fi - check_command mpifort "mpich" && MPIFC="$(command -v mpifort)" || exit 1 - MPIFORT="${MPIFC}" - MPIF77="${MPIFC}" - check_lib -lmpifort "mpich" - check_lib -lmpicxx "mpich" - check_lib -lmpi "mpich" - add_include_from_paths MPICH_CFLAGS "mpi.h" ${INCLUDE_PATHS} - add_lib_from_paths MPICH_LDFLAGS "libmpi.*" ${LIB_PATHS} - ;; -__DONTUSE__) - # Nothing to do - ;; -*) - echo "==================== Linking MPICH to user paths ====================" - pkg_install_dir="${with_mpich}" - check_dir "${pkg_install_dir}/bin" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - check_command ${pkg_install_dir}/bin/mpiexec "mpich" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 - check_command ${pkg_install_dir}/bin/mpicc "mpich" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 - check_command ${pkg_install_dir}/bin/mpicxx "mpich" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 - check_command ${pkg_install_dir}/bin/mpifort "mpich" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 - MPIFORT="${MPIFC}" - MPIF77="${MPIFC}" - MPICH_CFLAGS="-I'${pkg_install_dir}/include'" - MPICH_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; + check_command mpiexec "mpich" && MPIRUN="$(command -v mpiexec)" + check_command mpicc "mpich" && MPICC="$(command -v mpicc)" || exit 1 + if [ $(command -v mpic++ >/dev/null 2>&1) ]; then + check_command mpic++ "mpich" && MPICXX="$(command -v mpic++)" || exit 1 + else + check_command mpicxx "mpich" && MPICXX="$(command -v mpicxx)" || exit 1 + fi + check_command mpifort "mpich" && MPIFC="$(command -v mpifort)" || exit 1 + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + check_lib -lmpifort "mpich" + check_lib -lmpicxx "mpich" + check_lib -lmpi "mpich" + add_include_from_paths MPICH_CFLAGS "mpi.h" ${INCLUDE_PATHS} + add_lib_from_paths MPICH_LDFLAGS "libmpi.*" ${LIB_PATHS} + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking MPICH to user paths ====================" + pkg_install_dir="${with_mpich}" + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + check_command ${pkg_install_dir}/bin/mpiexec "mpich" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 + check_command ${pkg_install_dir}/bin/mpicc "mpich" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 + check_command ${pkg_install_dir}/bin/mpicxx "mpich" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 + check_command ${pkg_install_dir}/bin/mpifort "mpich" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + MPICH_CFLAGS="-I'${pkg_install_dir}/include'" + MPICH_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "${with_mpich}" != "__DONTUSE__" ]; then if [ "${with_mpich}" != "__SYSTEM__" ]; then diff --git a/toolchain/scripts/stage1/install_openmpi.sh b/toolchain/scripts/stage1/install_openmpi.sh index de1da98a845..71797ce5c18 100755 --- a/toolchain/scripts/stage1/install_openmpi.sh +++ b/toolchain/scripts/stage1/install_openmpi.sh @@ -44,112 +44,112 @@ OPENMPI_LIBS="" cd "${BUILDDIR}" case "${with_openmpi}" in -__INSTALL__) - echo "==================== Installing OpenMPI ====================" - pkg_install_dir="${INSTALLDIR}/openmpi-${openmpi_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - url="https://download.open-mpi.org/release/open-mpi/v${openmpi_ver%.*}/${openmpi_pkg}" - if verify_checksums "${install_lock_file}"; then - echo "openmpi-${openmpi_ver} is already installed, skipping it." - else - retrieve_package "${openmpi_sha256}" "${openmpi_pkg}" "${url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d openmpi-${openmpi_ver} ] && rm -rf openmpi-${openmpi_ver} - tar -xjf ${openmpi_pkg} - cd openmpi-${openmpi_ver} - if [ "${SYSTEM_ARCH}" = "x86_64" ]; then - # can have issue with older glibc libraries, in which case - # we need to add the -fgnu89-inline to CFLAGS. We can check - # the version of glibc using ldd --version, as ldd is part of - # glibc package - glibc_version=$(ldd --version | awk '/ldd/{print $NF}') - glibc_major_ver=${glibc_version%%.*} - glibc_minor_ver=${glibc_version##*.} - if [ $glibc_major_ver -lt 2 ] || - [ $glibc_major_ver -eq 2 -a $glibc_minor_ver -lt 12 ]; then - CFLAGS="${CFLAGS} -fgnu89-inline" + __INSTALL__) + echo "==================== Installing OpenMPI ====================" + pkg_install_dir="${INSTALLDIR}/openmpi-${openmpi_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + url="https://download.open-mpi.org/release/open-mpi/v${openmpi_ver%.*}/${openmpi_pkg}" + if verify_checksums "${install_lock_file}"; then + echo "openmpi-${openmpi_ver} is already installed, skipping it." + else + retrieve_package "${openmpi_sha256}" "${openmpi_pkg}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d openmpi-${openmpi_ver} ] && rm -rf openmpi-${openmpi_ver} + tar -xjf ${openmpi_pkg} + cd openmpi-${openmpi_ver} + if [ "${SYSTEM_ARCH}" = "x86_64" ]; then + # can have issue with older glibc libraries, in which case + # we need to add the -fgnu89-inline to CFLAGS. We can check + # the version of glibc using ldd --version, as ldd is part of + # glibc package + glibc_version=$(ldd --version | awk '/ldd/{print $NF}') + glibc_major_ver=${glibc_version%%.*} + glibc_minor_ver=${glibc_version##*.} + if [ $glibc_major_ver -lt 2 ] || + [ $glibc_major_ver -eq 2 -a $glibc_minor_ver -lt 12 ]; then + CFLAGS="${CFLAGS} -fgnu89-inline" + fi fi - fi - # Notice for RHEL8 refer https://github.com/open-mpi/ompi/issues/13103 + # Notice for RHEL8 refer https://github.com/open-mpi/ompi/issues/13103 - # OpenMPI 5.0 only supports PMIx - # PMI support is required for Slurm, but not for other schedulers - # default not use - # for OpenMPI 4.1 with pmi slurm, we can open this setting manually - # if [ $(command -v srun) ]; then - # echo "Slurm installation found. OpenMPI will be configured with --with-pmi." - # EXTRA_CONFIGURE_FLAGS="--with-pmi" - # else - # EXTRA_CONFIGURE_FLAGS="" - # fi - ./configure \ - CC=gcc \ - CXX=g++ \ - FC=gfortran \ - F77=gfortran \ - CFLAGS="${CFLAGS}" \ - --prefix=${pkg_install_dir} \ - --libdir="${pkg_install_dir}/lib" \ - --with-libevent=internal \ - ${EXTRA_CONFIGURE_FLAGS} \ - >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log - make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log - make -j $(get_nprocs) install >install.log 2>&1 || tail -n ${LOG_LINES} install.log - cd .. - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage1/$(basename ${SCRIPT_NAME})" - fi - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - else + # OpenMPI 5.0 only supports PMIx + # PMI support is required for Slurm, but not for other schedulers + # default not use + # for OpenMPI 4.1 with pmi slurm, we can open this setting manually + # if [ $(command -v srun) ]; then + # echo "Slurm installation found. OpenMPI will be configured with --with-pmi." + # EXTRA_CONFIGURE_FLAGS="--with-pmi" + # else + # EXTRA_CONFIGURE_FLAGS="" + # fi + ./configure \ + CC=gcc \ + CXX=g++ \ + FC=gfortran \ + F77=gfortran \ + CFLAGS="${CFLAGS}" \ + --prefix=${pkg_install_dir} \ + --libdir="${pkg_install_dir}/lib" \ + --with-libevent=internal \ + ${EXTRA_CONFIGURE_FLAGS} \ + >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make -j $(get_nprocs) install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage1/$(basename ${SCRIPT_NAME})" + fi + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + else + check_dir "${pkg_install_dir}/bin" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + check_install ${pkg_install_dir}/bin/mpiexec "openmpi" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 + check_install ${pkg_install_dir}/bin/mpicc "openmpi" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 + check_install ${pkg_install_dir}/bin/mpicxx "openmpi" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 + check_install ${pkg_install_dir}/bin/mpifort "openmpi" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + OPENMPI_CFLAGS="-I'${pkg_install_dir}/include'" + OPENMPI_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + fi + ;; + __SYSTEM__) + echo "==================== Finding OpenMPI from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_command mpiexec "openmpi" && MPIRUN="$(command -v mpiexec)" + check_command mpicc "openmpi" && MPICC="$(command -v mpicc)" || exit 1 + check_command mpicxx "openmpi" && MPICXX="$(command -v mpicxx)" || exit 1 + check_command mpifort "openmpi" && MPIFC="$(command -v mpifort)" || exit 1 + MPIFORT="${MPIFC}" + MPIF77="${MPIFC}" + ;; + __DONTUSE__) + # Nothing to do + ;; + *) + echo "==================== Linking OpenMPI to user paths ====================" + pkg_install_dir="${with_openmpi}" check_dir "${pkg_install_dir}/bin" check_dir "${pkg_install_dir}/lib" check_dir "${pkg_install_dir}/include" - check_install ${pkg_install_dir}/bin/mpiexec "openmpi" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 - check_install ${pkg_install_dir}/bin/mpicc "openmpi" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 - check_install ${pkg_install_dir}/bin/mpicxx "openmpi" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 - check_install ${pkg_install_dir}/bin/mpifort "openmpi" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 + check_command ${pkg_install_dir}/bin/mpiexec "openmpi" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 + check_command ${pkg_install_dir}/bin/mpicc "openmpi" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 + check_command ${pkg_install_dir}/bin/mpicxx "openmpi" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 + check_command ${pkg_install_dir}/bin/mpifort "openmpi" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 MPIFORT="${MPIFC}" MPIF77="${MPIFC}" OPENMPI_CFLAGS="-I'${pkg_install_dir}/include'" OPENMPI_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - fi - ;; -__SYSTEM__) - echo "==================== Finding OpenMPI from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_command mpiexec "openmpi" && MPIRUN="$(command -v mpiexec)" - check_command mpicc "openmpi" && MPICC="$(command -v mpicc)" || exit 1 - check_command mpicxx "openmpi" && MPICXX="$(command -v mpicxx)" || exit 1 - check_command mpifort "openmpi" && MPIFC="$(command -v mpifort)" || exit 1 - MPIFORT="${MPIFC}" - MPIF77="${MPIFC}" - ;; -__DONTUSE__) - # Nothing to do - ;; -*) - echo "==================== Linking OpenMPI to user paths ====================" - pkg_install_dir="${with_openmpi}" - check_dir "${pkg_install_dir}/bin" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - check_command ${pkg_install_dir}/bin/mpiexec "openmpi" && MPIRUN="${pkg_install_dir}/bin/mpiexec" || exit 1 - check_command ${pkg_install_dir}/bin/mpicc "openmpi" && MPICC="${pkg_install_dir}/bin/mpicc" || exit 1 - check_command ${pkg_install_dir}/bin/mpicxx "openmpi" && MPICXX="${pkg_install_dir}/bin/mpicxx" || exit 1 - check_command ${pkg_install_dir}/bin/mpifort "openmpi" && MPIFC="${pkg_install_dir}/bin/mpifort" || exit 1 - MPIFORT="${MPIFC}" - MPIF77="${MPIFC}" - OPENMPI_CFLAGS="-I'${pkg_install_dir}/include'" - OPENMPI_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; + ;; esac if [ "${PACK_RUN}" = "__TRUE__" ]; then echo "--pack-run mode specified, skip env setting" diff --git a/toolchain/scripts/stage2/install_aocl.sh b/toolchain/scripts/stage2/install_aocl.sh index b61892950b8..48f8ad87b42 100755 --- a/toolchain/scripts/stage2/install_aocl.sh +++ b/toolchain/scripts/stage2/install_aocl.sh @@ -21,40 +21,40 @@ AOCL_ROOT="" cd "${BUILDDIR}" case "${with_aocl}" in -__INSTALL__) - echo "==================== Installing AOCL ====================" - report_error ${LINENO} "To install AOCL, please contact your system administrator." - exit 1 - ;; -__SYSTEM__) - echo "==================== Finding AOCL from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_lib -lblis "AOCL" - check_lib -lflame "AOCL" - AOCL_LIBS="-lblis -lflame" - add_include_from_paths AOCL_CFLAGS "blis.h" $INCLUDE_PATHS - add_lib_from_paths AOCL_LDFLAGS "libblis.*" $LIB_PATHS - add_include_from_paths AOCL_CFLAGS "lapack.h" $INCLUDE_PATHS - add_lib_from_paths AOCL_LDFLAGS "libflame.*" $LIB_PATHS - ;; -__DONTUSE__) - ;; -*) - echo "==================== Linking AOCL to user paths ====================" - pkg_install_dir="$with_aocl" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_dir "${pkg_install_dir}/include" - check_dir "${pkg_install_dir}/lib" - AOCL_CFLAGS="-I'${pkg_install_dir}/include'" - AOCL_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - AOCL_LIBS="-lblis -lflame" - ;; + __INSTALL__) + echo "==================== Installing AOCL ====================" + report_error ${LINENO} "To install AOCL, please contact your system administrator." + exit 1 + ;; + __SYSTEM__) + echo "==================== Finding AOCL from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_lib -lblis "AOCL" + check_lib -lflame "AOCL" + AOCL_LIBS="-lblis -lflame" + add_include_from_paths AOCL_CFLAGS "blis.h" $INCLUDE_PATHS + add_lib_from_paths AOCL_LDFLAGS "libblis.*" $LIB_PATHS + add_include_from_paths AOCL_CFLAGS "lapack.h" $INCLUDE_PATHS + add_lib_from_paths AOCL_LDFLAGS "libflame.*" $LIB_PATHS + ;; + __DONTUSE__) + ;; + *) + echo "==================== Linking AOCL to user paths ====================" + pkg_install_dir="$with_aocl" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_dir "${pkg_install_dir}/include" + check_dir "${pkg_install_dir}/lib" + AOCL_CFLAGS="-I'${pkg_install_dir}/include'" + AOCL_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + AOCL_LIBS="-lblis -lflame" + ;; esac if [ "$with_aocl" != "__DONTUSE__" ]; then cat <>"${BUILDDIR}/setup_aocl" diff --git a/toolchain/scripts/stage2/install_mathlibs.sh b/toolchain/scripts/stage2/install_mathlibs.sh index 68a589bb77b..3ad3aef336f 100755 --- a/toolchain/scripts/stage2/install_mathlibs.sh +++ b/toolchain/scripts/stage2/install_mathlibs.sh @@ -21,24 +21,24 @@ export MATH_LIBS='' write_toolchain_env "${INSTALLDIR}" case "$MATH_MODE" in -mkl) - "${SCRIPTDIR}"/stage2/install_mkl.sh "${with_mkl}" - load "${BUILDDIR}/setup_mkl" - ;; -aocl) - "${SCRIPTDIR}"/stage2/install_aocl.sh "${with_aocl}" - load "${BUILDDIR}/setup_aocl" - ;; -openblas) - "${SCRIPTDIR}"/stage2/install_openblas.sh "${with_openblas}" - load "${BUILDDIR}/setup_openblas" - ;; -cray) - # note the space is intentional so that the variable is - # non-empty and can pass require_env checks - export MATH_LDFLAGS="${MATH_LDFLAGS} " - export MATH_LIBS="${MATH_LIBS} ${CRAY_EXTRA_LIBS}" - ;; + mkl) + "${SCRIPTDIR}"/stage2/install_mkl.sh "${with_mkl}" + load "${BUILDDIR}/setup_mkl" + ;; + aocl) + "${SCRIPTDIR}"/stage2/install_aocl.sh "${with_aocl}" + load "${BUILDDIR}/setup_aocl" + ;; + openblas) + "${SCRIPTDIR}"/stage2/install_openblas.sh "${with_openblas}" + load "${BUILDDIR}/setup_openblas" + ;; + cray) + # note the space is intentional so that the variable is + # non-empty and can pass require_env checks + export MATH_LDFLAGS="${MATH_LDFLAGS} " + export MATH_LIBS="${MATH_LIBS} ${CRAY_EXTRA_LIBS}" + ;; esac export CP_CFLAGS="${CP_CFLAGS} ${MATH_CFLAGS}" diff --git a/toolchain/scripts/stage2/install_mkl.sh b/toolchain/scripts/stage2/install_mkl.sh index 6694aace893..26e4a7ba02a 100755 --- a/toolchain/scripts/stage2/install_mkl.sh +++ b/toolchain/scripts/stage2/install_mkl.sh @@ -23,53 +23,53 @@ MKL_FFTW="yes" cd "${BUILDDIR}" case "${with_mkl}" in -__INSTALL__) - echo "==================== Installing MKL ====================" - report_error ${LINENO} "To install MKL, please contact your system administrator." - exit 1 - ;; -__SYSTEM__) - echo "==================== Finding MKL from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - if ! [ -z "${MKLROOT}" ]; then - echo "MKLROOT is found to be ${MKLROOT}" - else - report_error ${LINENO} "Cannot find env variable MKLROOT, the script relies on it being set. Please check in MKL installation and use --with-mkl= to pass the path to MKL root directory to this script." + __INSTALL__) + echo "==================== Installing MKL ====================" + report_error ${LINENO} "To install MKL, please contact your system administrator." exit 1 - fi - check_lib -lm - check_lib -ldl - ;; -__DONTUSE__) - # Nothing to do - ;; -*) - echo "==================== Linking MKL to user paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_dir "${with_mkl}" - MKLROOT="${with_mkl}" - ;; -esac -if [ "${with_mkl}" != "__DONTUSE__" ]; then - case "${SYSTEM_ARCH}" in - x86_64) - mkl_arch_dir="intel64" - MKL_CFLAGS="-m64" ;; - i386) - mkl_arch_dir="ia32" - MKL_CFLAGS="-m32" + __SYSTEM__) + echo "==================== Finding MKL from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + if ! [ -z "${MKLROOT}" ]; then + echo "MKLROOT is found to be ${MKLROOT}" + else + report_error ${LINENO} "Cannot find env variable MKLROOT, the script relies on it being set. Please check in MKL installation and use --with-mkl= to pass the path to MKL root directory to this script." + exit 1 + fi + check_lib -lm + check_lib -ldl + ;; + __DONTUSE__) + # Nothing to do ;; *) - report_error $LINENO "MKL only supports intel64 (x86_64) and ia32 (i386) at the moment, but the detected architecture is ${SYSTEM_ARCH}" - exit 1 + echo "==================== Linking MKL to user paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_dir "${with_mkl}" + MKLROOT="${with_mkl}" ;; +esac +if [ "${with_mkl}" != "__DONTUSE__" ]; then + case "${SYSTEM_ARCH}" in + x86_64) + mkl_arch_dir="intel64" + MKL_CFLAGS="-m64" + ;; + i386) + mkl_arch_dir="ia32" + MKL_CFLAGS="-m32" + ;; + *) + report_error $LINENO "MKL only supports intel64 (x86_64) and ia32 (i386) at the moment, but the detected architecture is ${SYSTEM_ARCH}" + exit 1 + ;; esac mkl_lib_dir="${MKLROOT}/lib/${mkl_arch_dir}" # check we have required libraries @@ -82,19 +82,19 @@ if [ "${with_mkl}" != "__DONTUSE__" ]; then done case ${MPI_MODE} in - intelmpi | mpich) - mkl_scalapack_lib="IF_MPI(-lmkl_scalapack_lp64|)" - mkl_blacs_lib="IF_MPI(-lmkl_blacs_intelmpi_lp64|)" - ;; - openmpi) - mkl_scalapack_lib="IF_MPI(-lmkl_scalapack_lp64|)" - mkl_blacs_lib="IF_MPI(-lmkl_blacs_openmpi_lp64|)" - ;; - *) - echo "Not using MKL provided ScaLAPACK and BLACS" - mkl_scalapack_lib="" - mkl_blacs_lib="" - ;; + intelmpi | mpich) + mkl_scalapack_lib="IF_MPI(-lmkl_scalapack_lp64|)" + mkl_blacs_lib="IF_MPI(-lmkl_blacs_intelmpi_lp64|)" + ;; + openmpi) + mkl_scalapack_lib="IF_MPI(-lmkl_scalapack_lp64|)" + mkl_blacs_lib="IF_MPI(-lmkl_blacs_openmpi_lp64|)" + ;; + *) + echo "Not using MKL provided ScaLAPACK and BLACS" + mkl_scalapack_lib="" + mkl_blacs_lib="" + ;; esac # added by trae diff --git a/toolchain/scripts/stage2/install_openblas.sh b/toolchain/scripts/stage2/install_openblas.sh index 13b2a3bbe3f..757b655915b 100755 --- a/toolchain/scripts/stage2/install_openblas.sh +++ b/toolchain/scripts/stage2/install_openblas.sh @@ -43,111 +43,111 @@ OPENBLAS_ROOT="" cd "${BUILDDIR}" case "${with_openblas}" in -__INSTALL__) - echo "==================== Installing OpenBLAS ====================" - pkg_install_dir="${INSTALLDIR}/openblas-${openblas_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - if verify_checksums "${install_lock_file}"; then - echo "openblas-${openblas_ver} is already installed, skipping it." - else - url="https://codeload.github.com/OpenMathLib/OpenBLAS/tar.gz/v${openblas_ver}" - retrieve_package "${openblas_sha256}" "${openblas_pkg}" "${url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d OpenBLAS-${openblas_ver} ] && rm -rf OpenBLAS-${openblas_ver} - tar -zxf ${openblas_pkg} - cd OpenBLAS-${openblas_ver} - # Build OpenBLAS with DYNAMIC_ARCH unless native architecture is requested. - # If the latter fails, then build with DYNAMIC_ARCH. - # - # wrt NUM_THREADS=64: this is what the most common Linux distros seem to choose atm - # for a good compromise between memory usage and scalability - # - # Unfortunately, NO_SHARED=1 breaks ScaLAPACK build. - BUILD_DYNAMIC=0 - if [ "native" != "${TARGET_CPU}" ]; then - BUILD_DYNAMIC=1 - fi - if [ "${BUILD_DYNAMIC}" = "0" ]; then - echo "Installing OpenBLAS library for native target" - if ! make -j "$(get_nprocs)" \ - MAKE_NB_JOBS=0 \ - NUM_THREADS=64 \ - USE_THREAD=1 \ - USE_OPENMP=1 \ - NO_AFFINITY=1 \ - CC="${CC}" \ - FC="${FC}" \ - PREFIX="${pkg_install_dir}" \ - >make.log 2>&1; then - tail -n "${LOG_LINES}" make.log - make clean + __INSTALL__) + echo "==================== Installing OpenBLAS ====================" + pkg_install_dir="${INSTALLDIR}/openblas-${openblas_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "openblas-${openblas_ver} is already installed, skipping it." + else + url="https://codeload.github.com/OpenMathLib/OpenBLAS/tar.gz/v${openblas_ver}" + retrieve_package "${openblas_sha256}" "${openblas_pkg}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d OpenBLAS-${openblas_ver} ] && rm -rf OpenBLAS-${openblas_ver} + tar -zxf ${openblas_pkg} + cd OpenBLAS-${openblas_ver} + # Build OpenBLAS with DYNAMIC_ARCH unless native architecture is requested. + # If the latter fails, then build with DYNAMIC_ARCH. + # + # wrt NUM_THREADS=64: this is what the most common Linux distros seem to choose atm + # for a good compromise between memory usage and scalability + # + # Unfortunately, NO_SHARED=1 breaks ScaLAPACK build. + BUILD_DYNAMIC=0 + if [ "native" != "${TARGET_CPU}" ]; then BUILD_DYNAMIC=1 fi - fi - if [ "${BUILD_DYNAMIC}" != "0" ]; then - echo "Installing OpenBLAS library for dynamic target" - if ! make -j "$(get_nprocs)" \ - MAKE_NB_JOBS=0 \ - DYNAMIC_ARCH=1 \ - NUM_THREADS=64 \ - USE_THREAD=1 \ - USE_OPENMP=1 \ - NO_AFFINITY=1 \ - CC="${CC}" \ - FC="${FC}" \ - PREFIX="${pkg_install_dir}" \ - >make.log 2>&1; then - tail -n "${LOG_LINES}" make.log + if [ "${BUILD_DYNAMIC}" = "0" ]; then + echo "Installing OpenBLAS library for native target" + if ! make -j "$(get_nprocs)" \ + MAKE_NB_JOBS=0 \ + NUM_THREADS=64 \ + USE_THREAD=1 \ + USE_OPENMP=1 \ + NO_AFFINITY=1 \ + CC="${CC}" \ + FC="${FC}" \ + PREFIX="${pkg_install_dir}" \ + >make.log 2>&1; then + tail -n "${LOG_LINES}" make.log + make clean + BUILD_DYNAMIC=1 + fi + fi + if [ "${BUILD_DYNAMIC}" != "0" ]; then + echo "Installing OpenBLAS library for dynamic target" + if ! make -j "$(get_nprocs)" \ + MAKE_NB_JOBS=0 \ + DYNAMIC_ARCH=1 \ + NUM_THREADS=64 \ + USE_THREAD=1 \ + USE_OPENMP=1 \ + NO_AFFINITY=1 \ + CC="${CC}" \ + FC="${FC}" \ + PREFIX="${pkg_install_dir}" \ + >make.log 2>&1; then + tail -n "${LOG_LINES}" make.log + exit 1 + fi + fi + if ! make MAKE_NB_JOBS=0 PREFIX="${pkg_install_dir}" install \ + >install.log 2>&1; then + tail -n "${LOG_LINES}" install.log exit 1 fi + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage2/$(basename ${SCRIPT_NAME})" fi - if ! make MAKE_NB_JOBS=0 PREFIX="${pkg_install_dir}" install \ - >install.log 2>&1; then - tail -n "${LOG_LINES}" install.log - exit 1 + OPENBLAS_CFLAGS="-I'${pkg_install_dir}/include'" + OPENBLAS_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + OPENBLAS_ROOT="${pkg_install_dir}" + OPENBLAS_LIBS="-lopenblas" + ;; + __SYSTEM__) + echo "==================== Finding OpenBLAS/LAPACK from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 fi - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage2/$(basename ${SCRIPT_NAME})" - fi - OPENBLAS_CFLAGS="-I'${pkg_install_dir}/include'" - OPENBLAS_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - OPENBLAS_ROOT="${pkg_install_dir}" - OPENBLAS_LIBS="-lopenblas" - ;; -__SYSTEM__) - echo "==================== Finding OpenBLAS/LAPACK from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - # assume that system openblas is threaded - check_lib -lopenblas "OpenBLAS" - OPENBLAS_LIBS="-lopenblas" - # detect separate omp builds - check_lib -lopenblas_openmp 2>/dev/null && OPENBLAS_LIBS="-lopenblas_openmp" - check_lib -lopenblas_omp 2>/dev/null && OPENBLAS_LIBS="-lopenblas_omp" - add_include_from_paths OPENBLAS_CFLAGS "openblas_config.h" $INCLUDE_PATHS - add_lib_from_paths OPENBLAS_LDFLAGS "libopenblas.*" $LIB_PATHS - ;; -__DONTUSE__) ;; + # assume that system openblas is threaded + check_lib -lopenblas "OpenBLAS" + OPENBLAS_LIBS="-lopenblas" + # detect separate omp builds + check_lib -lopenblas_openmp 2>/dev/null && OPENBLAS_LIBS="-lopenblas_openmp" + check_lib -lopenblas_omp 2>/dev/null && OPENBLAS_LIBS="-lopenblas_omp" + add_include_from_paths OPENBLAS_CFLAGS "openblas_config.h" $INCLUDE_PATHS + add_lib_from_paths OPENBLAS_LDFLAGS "libopenblas.*" $LIB_PATHS + ;; + __DONTUSE__) ;; -*) - echo "==================== Linking OpenBLAS/LAPACK to user paths ====================" - pkg_install_dir="$with_openblas" - check_dir "${pkg_install_dir}/include" - check_dir "${pkg_install_dir}/lib" - OPENBLAS_CFLAGS="-I'${pkg_install_dir}/include'" - OPENBLAS_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - OPENBLAS_LIBS="-lopenblas" - # detect separate omp builds - (__libdir="${pkg_install_dir}/lib" LIB_PATHS="__libdir" check_lib -lopenblas_openmp 2>/dev/null) && - OPENBLAS_LIBS="-lopenblas_openmp" - (__libdir="${pkg_install_dir}/lib" LIB_PATHS="__libdir" check_lib -lopenblas_omp 2>/dev/null) && - OPENBLAS_LIBS="-lopenblas_omp" - ;; + *) + echo "==================== Linking OpenBLAS/LAPACK to user paths ====================" + pkg_install_dir="$with_openblas" + check_dir "${pkg_install_dir}/include" + check_dir "${pkg_install_dir}/lib" + OPENBLAS_CFLAGS="-I'${pkg_install_dir}/include'" + OPENBLAS_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + OPENBLAS_LIBS="-lopenblas" + # detect separate omp builds + (__libdir="${pkg_install_dir}/lib" LIB_PATHS="__libdir" check_lib -lopenblas_openmp 2>/dev/null) && + OPENBLAS_LIBS="-lopenblas_openmp" + (__libdir="${pkg_install_dir}/lib" LIB_PATHS="__libdir" check_lib -lopenblas_omp 2>/dev/null) && + OPENBLAS_LIBS="-lopenblas_omp" + ;; esac if [ "$with_openblas" != "__DONTUSE__" ]; then if [ "$with_openblas" != "__SYSTEM__" ]; then diff --git a/toolchain/scripts/stage3/install_elpa.sh b/toolchain/scripts/stage3/install_elpa.sh index 84e1be1a07c..99097720889 100755 --- a/toolchain/scripts/stage3/install_elpa.sh +++ b/toolchain/scripts/stage3/install_elpa.sh @@ -53,199 +53,199 @@ if [ $MPI_MODE = no ]; then fi case "$with_elpa" in -__INSTALL__) - echo "==================== Installing ELPA ====================" - pkg_install_dir="${INSTALLDIR}/elpa-${elpa_ver}" - #pkg_install_dir="${HOME}/lib/elpa/${elpa_ver}-gcc8" - install_lock_file="${pkg_install_dir}/install_successful" - enable_openmp="yes" + __INSTALL__) + echo "==================== Installing ELPA ====================" + pkg_install_dir="${INSTALLDIR}/elpa-${elpa_ver}" + #pkg_install_dir="${HOME}/lib/elpa/${elpa_ver}-gcc8" + install_lock_file="${pkg_install_dir}/install_successful" + enable_openmp="yes" - # specific settings needed on CRAY Linux Environment - if [ "$ENABLE_CRAY" = "__TRUE__" ]; then - if [ ${CRAY_PRGENVCRAY} ]; then - # extra LDFLAGS needed - cray_ldflags="-dynamic" + # specific settings needed on CRAY Linux Environment + if [ "$ENABLE_CRAY" = "__TRUE__" ]; then + if [ ${CRAY_PRGENVCRAY} ]; then + # extra LDFLAGS needed + cray_ldflags="-dynamic" + fi + # enable_openmp="no" fi - # enable_openmp="no" - fi - if verify_checksums "${install_lock_file}"; then - echo "elpa-${elpa_ver} is already installed, skipping it." - else - require_env MATH_LIBS - url="https://elpa.mpcdf.mpg.de/software/tarball-archive/Releases/${elpa_ver}/${elpa_pkg}" - retrieve_package "${elpa_sha256}" "${elpa_pkg}" "${url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - [ -d elpa-${elpa_ver} ] && rm -rf elpa-${elpa_ver} - tar -xzf ${elpa_pkg} + if verify_checksums "${install_lock_file}"; then + echo "elpa-${elpa_ver} is already installed, skipping it." + else + require_env MATH_LIBS + url="https://elpa.mpcdf.mpg.de/software/tarball-archive/Releases/${elpa_ver}/${elpa_pkg}" + retrieve_package "${elpa_sha256}" "${elpa_pkg}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + [ -d elpa-${elpa_ver} ] && rm -rf elpa-${elpa_ver} + tar -xzf ${elpa_pkg} - # elpa expect FC to be an mpi fortran compiler that is happy - # with long lines, and that a bunch of libs can be found - cd elpa-${elpa_ver} + # elpa expect FC to be an mpi fortran compiler that is happy + # with long lines, and that a bunch of libs can be found + cd elpa-${elpa_ver} - # ELPA-2017xxxx enables AVX2 by default, switch off if machine doesn't support it. - AVX_flag="" - AVX512_flags="" - FMA_flag="" - SSE4_flag="" - config_flags="--disable-avx-kernels --disable-avx2-kernels --disable-avx512-kernels --disable-sse-kernels --disable-sse-assembly-kernels" - if [ "${TARGET_CPU}" = "native" ]; then - if [ -f /proc/cpuinfo ] && [ "${SYSTEM_ARCH}" = "x86_64" ]; then - has_AVX=$(grep '\bavx\b' /proc/cpuinfo 1>/dev/null && echo 'yes' || echo 'no') - [ "${has_AVX}" = "yes" ] && AVX_flag="-mavx" || AVX_flag="" - has_AVX2=$(grep '\bavx2\b' /proc/cpuinfo 1>/dev/null && echo 'yes' || echo 'no') - [ "${has_AVX2}" = "yes" ] && AVX_flag="-mavx2" - has_AVX512=$(grep '\bavx512f\b' /proc/cpuinfo 1>/dev/null && echo 'yes' || echo 'no') - [ "${has_AVX512}" = "yes" ] && AVX512_flags="-mavx512f" - FMA_flag=$(grep '\bfma\b' /proc/cpuinfo 1>/dev/null && echo '-mfma' || echo '-mno-fma') - SSE4_flag=$(grep '\bsse4_1\b' /proc/cpuinfo 1>/dev/null && echo '-msse4' || echo '-mno-sse4') - grep '\bavx512dq\b' /proc/cpuinfo 1>/dev/null && AVX512_flags+=" -mavx512dq" - grep '\bavx512cd\b' /proc/cpuinfo 1>/dev/null && AVX512_flags+=" -mavx512cd" - grep '\bavx512bw\b' /proc/cpuinfo 1>/dev/null && AVX512_flags+=" -mavx512bw" - grep '\bavx512vl\b' /proc/cpuinfo 1>/dev/null && AVX512_flags+=" -mavx512vl" - config_flags="--enable-avx-kernels=${has_AVX} --enable-avx2-kernels=${has_AVX2} --enable-avx512-kernels=${has_AVX512}" + # ELPA-2017xxxx enables AVX2 by default, switch off if machine doesn't support it. + AVX_flag="" + AVX512_flags="" + FMA_flag="" + SSE4_flag="" + config_flags="--disable-avx-kernels --disable-avx2-kernels --disable-avx512-kernels --disable-sse-kernels --disable-sse-assembly-kernels" + if [ "${TARGET_CPU}" = "native" ]; then + if [ -f /proc/cpuinfo ] && [ "${SYSTEM_ARCH}" = "x86_64" ]; then + has_AVX=$(grep '\bavx\b' /proc/cpuinfo 1>/dev/null && echo 'yes' || echo 'no') + [ "${has_AVX}" = "yes" ] && AVX_flag="-mavx" || AVX_flag="" + has_AVX2=$(grep '\bavx2\b' /proc/cpuinfo 1>/dev/null && echo 'yes' || echo 'no') + [ "${has_AVX2}" = "yes" ] && AVX_flag="-mavx2" + has_AVX512=$(grep '\bavx512f\b' /proc/cpuinfo 1>/dev/null && echo 'yes' || echo 'no') + [ "${has_AVX512}" = "yes" ] && AVX512_flags="-mavx512f" + FMA_flag=$(grep '\bfma\b' /proc/cpuinfo 1>/dev/null && echo '-mfma' || echo '-mno-fma') + SSE4_flag=$(grep '\bsse4_1\b' /proc/cpuinfo 1>/dev/null && echo '-msse4' || echo '-mno-sse4') + grep '\bavx512dq\b' /proc/cpuinfo 1>/dev/null && AVX512_flags+=" -mavx512dq" + grep '\bavx512cd\b' /proc/cpuinfo 1>/dev/null && AVX512_flags+=" -mavx512cd" + grep '\bavx512bw\b' /proc/cpuinfo 1>/dev/null && AVX512_flags+=" -mavx512bw" + grep '\bavx512vl\b' /proc/cpuinfo 1>/dev/null && AVX512_flags+=" -mavx512vl" + config_flags="--enable-avx-kernels=${has_AVX} --enable-avx2-kernels=${has_AVX2} --enable-avx512-kernels=${has_AVX512}" + fi fi - fi - # GCC 15.2 miscompiles ELPA's double-complex AVX/AVX2 BLOCK2 - # kernels when tree SLP vectorization is enabled. - elpa_c_workaround_flags="" - cc_version="$("${MPICC}" -dumpfullversion -dumpversion 2>/dev/null || true)" - cc_banner="$("${MPICC}" --version 2>/dev/null | head -n 1 || true)" - if [[ "${cc_banner}" == *gcc* || "${cc_banner}" == *GCC* ]] && - [[ "${cc_version}" =~ ^15\.2(\.|$) ]]; then - elpa_c_workaround_flags="-fno-tree-slp-vectorize" - fi + # GCC 15.2 miscompiles ELPA's double-complex AVX/AVX2 BLOCK2 + # kernels when tree SLP vectorization is enabled. + elpa_c_workaround_flags="" + cc_version="$("${MPICC}" -dumpfullversion -dumpversion 2>/dev/null || true)" + cc_banner="$("${MPICC}" --version 2>/dev/null | head -n 1 || true)" + if [[ "${cc_banner}" == *gcc* || "${cc_banner}" == *GCC* ]] && + [[ "${cc_version}" =~ ^15\.2(\.|$) ]]; then + elpa_c_workaround_flags="-fno-tree-slp-vectorize" + fi - for TARGET in "cpu" "nvidia"; do - # Accept both uppercase and lowercase GPU enable flags for compatibility - gpu_enabled="${ENABLE_CUDA}" - [ "$TARGET" = "nvidia" ] && [ "$gpu_enabled" != "__TRUE__" ] && continue - # disable cpu if cuda is enabled, only install one - [ "$TARGET" != "nvidia" ] && [ "$gpu_enabled" = "__TRUE__" ] && continue + for TARGET in "cpu" "nvidia"; do + # Accept both uppercase and lowercase GPU enable flags for compatibility + gpu_enabled="${ENABLE_CUDA}" + [ "$TARGET" = "nvidia" ] && [ "$gpu_enabled" != "__TRUE__" ] && continue + # disable cpu if cuda is enabled, only install one + [ "$TARGET" != "nvidia" ] && [ "$gpu_enabled" = "__TRUE__" ] && continue - echo "Installing from scratch into ${pkg_install_dir}/${TARGET}" - mkdir -p "build_${TARGET}" - cd "build_${TARGET}" - if [ "${with_amd}" != "__DONTUSE__" ] && [ "${WITH_FLANG}" = "yes" ]; then - # special option for flang compiler - echo "AMD fortran compiler detected, enable special option operation" - ../configure --prefix="${pkg_install_dir}/${TARGET}" \ - --libdir="${pkg_install_dir}/${TARGET}/lib" \ - --enable-openmp=${enable_openmp} \ - --enable-static=no \ - --enable-shared=yes \ - --disable-c-tests \ - --disable-cpp-tests \ - ${config_flags} \ - --with-cuda-path=${CUDA_PATH:-${CUDA_HOME:-/CUDA_HOME-notset}} \ - --enable-nvidia-gpu-kernels=$([ "$TARGET" = "nvidia" ] && echo "yes" || echo "no") \ - --with-NVIDIA-GPU-compute-capability=$([ "$TARGET" = "nvidia" ] && echo "sm_$ARCH_NUM" || echo "sm_70") \ - --enable-nvidia-cub --with-cusolver \ - OMPI_MCA_plm_rsh_agent=/bin/false \ - FC=${MPIFC} \ - CC=${MPICC} \ - CXX=${MPICXX} \ - CPP="cpp -E" \ - FCFLAGS="${FCFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ - CFLAGS="${CFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto ${elpa_c_workaround_flags}" \ - CXXFLAGS="${CXXFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ - LDFLAGS="${MATH_LDFLAGS} ${SCALAPACK_LDFLAGS} ${cray_ldflags} -lstdc++" \ - LIBS="${SCALAPACK_LIBS} $(resolve_string "${MATH_LIBS}" "MPI") ${MPI_LIBS}" \ - SCALAPACK_LDFLAGS="${SCALAPACK_LDFLAGS}" \ - SCALAPACK_FCFLAGS="${SCALAPACK_CFLAGS}" \ - >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log - # remove unsupported compile option in libtool - sed -i ./libtool \ - -e 's/\\$wl-soname //g' \ - -e 's/\\$wl--whole-archive\\$convenience \\$wl--no-whole-archive//g' \ - -e 's/\\$wl\\$soname //g' - else - # normal installation - ../configure --prefix="${pkg_install_dir}/${TARGET}" \ - --libdir="${pkg_install_dir}/${TARGET}/lib" \ - --enable-openmp=${enable_openmp} \ - --enable-static=no \ - --enable-shared=yes \ - --disable-c-tests \ - --disable-cpp-tests \ - ${config_flags} \ - --enable-nvidia-gpu-kernels=$([ "$TARGET" = "nvidia" ] && echo "yes" || echo "no") \ - --with-cuda-path=${CUDA_PATH:-${CUDA_HOME:-/CUDA_HOME-notset}} \ - --with-NVIDIA-GPU-compute-capability=$([ "$TARGET" = "nvidia" ] && echo "sm_$ARCH_NUM" || echo "sm_70") \ - --enable-nvidia-cub --with-cusolver \ - FC=${MPIFC} \ - CC=${MPICC} \ - CXX=${MPICXX} \ - CPP="cpp -E" \ - FCFLAGS="${FCFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ - CFLAGS="${CFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto ${elpa_c_workaround_flags}" \ - CXXFLAGS="${CXXFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ - LDFLAGS="-Wl,--allow-multiple-definition -Wl,--enable-new-dtags ${MATH_LDFLAGS} ${SCALAPACK_LDFLAGS} ${cray_ldflags} -lstdc++" \ - LIBS="${SCALAPACK_LIBS} $(resolve_string "${MATH_LIBS}" "MPI")" \ - SCALAPACK_LDFLAGS="${SCALAPACK_LDFLAGS}" \ - SCALAPACK_FCFLAGS="${SCALAPACK_CFLAGS}" \ - >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log - fi - make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log - make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + echo "Installing from scratch into ${pkg_install_dir}/${TARGET}" + mkdir -p "build_${TARGET}" + cd "build_${TARGET}" + if [ "${with_amd}" != "__DONTUSE__" ] && [ "${WITH_FLANG}" = "yes" ]; then + # special option for flang compiler + echo "AMD fortran compiler detected, enable special option operation" + ../configure --prefix="${pkg_install_dir}/${TARGET}" \ + --libdir="${pkg_install_dir}/${TARGET}/lib" \ + --enable-openmp=${enable_openmp} \ + --enable-static=no \ + --enable-shared=yes \ + --disable-c-tests \ + --disable-cpp-tests \ + ${config_flags} \ + --with-cuda-path=${CUDA_PATH:-${CUDA_HOME:-/CUDA_HOME-notset}} \ + --enable-nvidia-gpu-kernels=$([ "$TARGET" = "nvidia" ] && echo "yes" || echo "no") \ + --with-NVIDIA-GPU-compute-capability=$([ "$TARGET" = "nvidia" ] && echo "sm_$ARCH_NUM" || echo "sm_70") \ + --enable-nvidia-cub --with-cusolver \ + OMPI_MCA_plm_rsh_agent=/bin/false \ + FC=${MPIFC} \ + CC=${MPICC} \ + CXX=${MPICXX} \ + CPP="cpp -E" \ + FCFLAGS="${FCFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ + CFLAGS="${CFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto ${elpa_c_workaround_flags}" \ + CXXFLAGS="${CXXFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ + LDFLAGS="${MATH_LDFLAGS} ${SCALAPACK_LDFLAGS} ${cray_ldflags} -lstdc++" \ + LIBS="${SCALAPACK_LIBS} $(resolve_string "${MATH_LIBS}" "MPI") ${MPI_LIBS}" \ + SCALAPACK_LDFLAGS="${SCALAPACK_LDFLAGS}" \ + SCALAPACK_FCFLAGS="${SCALAPACK_CFLAGS}" \ + >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + # remove unsupported compile option in libtool + sed -i ./libtool \ + -e 's/\\$wl-soname //g' \ + -e 's/\\$wl--whole-archive\\$convenience \\$wl--no-whole-archive//g' \ + -e 's/\\$wl\\$soname //g' + else + # normal installation + ../configure --prefix="${pkg_install_dir}/${TARGET}" \ + --libdir="${pkg_install_dir}/${TARGET}/lib" \ + --enable-openmp=${enable_openmp} \ + --enable-static=no \ + --enable-shared=yes \ + --disable-c-tests \ + --disable-cpp-tests \ + ${config_flags} \ + --enable-nvidia-gpu-kernels=$([ "$TARGET" = "nvidia" ] && echo "yes" || echo "no") \ + --with-cuda-path=${CUDA_PATH:-${CUDA_HOME:-/CUDA_HOME-notset}} \ + --with-NVIDIA-GPU-compute-capability=$([ "$TARGET" = "nvidia" ] && echo "sm_$ARCH_NUM" || echo "sm_70") \ + --enable-nvidia-cub --with-cusolver \ + FC=${MPIFC} \ + CC=${MPICC} \ + CXX=${MPICXX} \ + CPP="cpp -E" \ + FCFLAGS="${FCFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ + CFLAGS="${CFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto ${elpa_c_workaround_flags}" \ + CXXFLAGS="${CXXFLAGS} ${MATH_CFLAGS} ${SCALAPACK_CFLAGS} ${AVX_flag} ${FMA_flag} ${SSE4_flag} ${AVX512_flags} -fno-lto" \ + LDFLAGS="-Wl,--allow-multiple-definition -Wl,--enable-new-dtags ${MATH_LDFLAGS} ${SCALAPACK_LDFLAGS} ${cray_ldflags} -lstdc++" \ + LIBS="${SCALAPACK_LIBS} $(resolve_string "${MATH_LIBS}" "MPI")" \ + SCALAPACK_LDFLAGS="${SCALAPACK_LDFLAGS}" \ + SCALAPACK_FCFLAGS="${SCALAPACK_CFLAGS}" \ + >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + fi + make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + # link elpa + link=${pkg_install_dir}/${TARGET}/include/elpa + if [[ ! -d $link ]]; then + ln -s ${pkg_install_dir}/${TARGET}/include/elpa_openmp-${elpa_ver}/elpa $link + fi + done cd .. - # link elpa - link=${pkg_install_dir}/${TARGET}/include/elpa - if [[ ! -d $link ]]; then - ln -s ${pkg_install_dir}/${TARGET}/include/elpa_openmp-${elpa_ver}/elpa $link - fi - done - cd .. - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" - fi - [ "$enable_openmp" != "yes" ] && elpa_dir_openmp="" - elpa_include="${pkg_install_dir}/IF_CUDA(nvidia|cpu)/include/elpa${elpa_dir_openmp}-${elpa_ver}" - ELPA_CFLAGS="-I'$elpa_include/modules' -I'$elpa_include/elpa'" - ELPA_LDFLAGS="-L'${pkg_install_dir}/IF_CUDA(nvidia|cpu)/lib' -Wl,-rpath,'${pkg_install_dir}/IF_CUDA(nvidia|cpu)/lib'" - ;; -__SYSTEM__) - echo "==================== Finding ELPA from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_lib -lelpa_openmp "ELPA" - # get the include paths - elpa_include="$(find_in_paths "elpa_openmp-*" $INCLUDE_PATHS)" - if [ "$elpa_include" != "__FALSE__" ]; then - echo "ELPA include directory threaded version is found to be $elpa_include" + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" + fi + [ "$enable_openmp" != "yes" ] && elpa_dir_openmp="" + elpa_include="${pkg_install_dir}/IF_CUDA(nvidia|cpu)/include/elpa${elpa_dir_openmp}-${elpa_ver}" ELPA_CFLAGS="-I'$elpa_include/modules' -I'$elpa_include/elpa'" - else - echo "Cannot find elpa_openmp-${elpa_ver} from paths $INCLUDE_PATHS" - exit 1 - fi - # get the lib paths - add_lib_from_paths ELPA_LDFLAGS "libelpa.*" $LIB_PATHS - ;; -__DONTUSE__) ;; + ELPA_LDFLAGS="-L'${pkg_install_dir}/IF_CUDA(nvidia|cpu)/lib' -Wl,-rpath,'${pkg_install_dir}/IF_CUDA(nvidia|cpu)/lib'" + ;; + __SYSTEM__) + echo "==================== Finding ELPA from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_lib -lelpa_openmp "ELPA" + # get the include paths + elpa_include="$(find_in_paths "elpa_openmp-*" $INCLUDE_PATHS)" + if [ "$elpa_include" != "__FALSE__" ]; then + echo "ELPA include directory threaded version is found to be $elpa_include" + ELPA_CFLAGS="-I'$elpa_include/modules' -I'$elpa_include/elpa'" + else + echo "Cannot find elpa_openmp-${elpa_ver} from paths $INCLUDE_PATHS" + exit 1 + fi + # get the lib paths + add_lib_from_paths ELPA_LDFLAGS "libelpa.*" $LIB_PATHS + ;; + __DONTUSE__) ;; -*) - echo "==================== Linking ELPA to user paths ====================" - pkg_install_dir="$with_elpa" - check_dir "${pkg_install_dir}/include" - check_dir "${pkg_install_dir}/lib" - user_include_path="${pkg_install_dir}/include" - elpa_include="$(find_in_paths "elpa_openmp-*" user_include_path)" - if [ "$elpa_include" != "__FALSE__" ]; then - echo "ELPA include directory threaded version is found to be $elpa_include/modules" - check_dir "$elpa_include/modules" - ELPA_CFLAGS="-I'$elpa_include/modules' -I'$elpa_include/elpa'" - else - echo "Cannot find elpa_openmp-* from path $user_include_path" - exit 1 - fi - ELPA_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; + *) + echo "==================== Linking ELPA to user paths ====================" + pkg_install_dir="$with_elpa" + check_dir "${pkg_install_dir}/include" + check_dir "${pkg_install_dir}/lib" + user_include_path="${pkg_install_dir}/include" + elpa_include="$(find_in_paths "elpa_openmp-*" user_include_path)" + if [ "$elpa_include" != "__FALSE__" ]; then + echo "ELPA include directory threaded version is found to be $elpa_include/modules" + check_dir "$elpa_include/modules" + ELPA_CFLAGS="-I'$elpa_include/modules' -I'$elpa_include/elpa'" + else + echo "Cannot find elpa_openmp-* from path $user_include_path" + exit 1 + fi + ELPA_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "$with_elpa" != "__DONTUSE__" ]; then ELPA_LIBS="-lelpa${elpa_dir_openmp}" diff --git a/toolchain/scripts/stage3/install_fftw.sh b/toolchain/scripts/stage3/install_fftw.sh index 35e75cc59e7..d50e9bf8458 100755 --- a/toolchain/scripts/stage3/install_fftw.sh +++ b/toolchain/scripts/stage3/install_fftw.sh @@ -41,83 +41,83 @@ FFTW_LIBS="" cd "${BUILDDIR}" case "$with_fftw" in -__INSTALL__) - require_env MPI_LIBS - echo "==================== Installing FFTW ====================" - pkg_install_dir="${INSTALLDIR}/fftw-${fftw_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - if verify_checksums "${install_lock_file}"; then - echo "fftw-${fftw_ver} is already installed, skipping it." - else - url="http://www.fftw.org/${fftw_pkg}" - retrieve_package "${fftw_sha256}" "${fftw_pkg}" "${url}" + __INSTALL__) + require_env MPI_LIBS + echo "==================== Installing FFTW ====================" + pkg_install_dir="${INSTALLDIR}/fftw-${fftw_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "fftw-${fftw_ver} is already installed, skipping it." + else + url="http://www.fftw.org/${fftw_pkg}" + retrieve_package "${fftw_sha256}" "${fftw_pkg}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d fftw-${fftw_ver} ] && rm -rf fftw-${fftw_ver} + tar -xzf ${fftw_pkg} + cd fftw-${fftw_ver} + FFTW_FLAGS="--enable-openmp --enable-shared" + # fftw has mpi support but not compiled by default. so compile it if we build with mpi. + # it will create a second library to link with if needed + [ "${MPI_MODE}" != "no" ] && FFTW_FLAGS="--enable-mpi ${FFTW_FLAGS}" + if [ "${TARGET_CPU}" = "native" ]; then + if [ -f /proc/cpuinfo ]; then + grep '\bavx\b' /proc/cpuinfo 1>/dev/null && FFTW_FLAGS="${FFTW_FLAGS} --enable-avx" + grep '\bavx2\b' /proc/cpuinfo 1>/dev/null && FFTW_FLAGS="${FFTW_FLAGS} --enable-avx2" + grep '\bavx512f\b' /proc/cpuinfo 1>/dev/null && FFTW_FLAGS="${FFTW_FLAGS} --enable-avx512" + fi + fi + # ABACUS need float version and double version fftw at the same time + # install float version fftw + echo "install float version fftw" + ./configure --prefix="${pkg_install_dir}" \ + --libdir="${pkg_install_dir}/lib" \ + --enable-float \ + ${FFTW_FLAGS} \ + >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + # install double version fftw + echo "clean" + make distclean >/dev/null 2>&1 || true + echo "install double version fftw" + ./configure --prefix="${pkg_install_dir}" \ + --libdir="${pkg_install_dir}/lib" \ + ${FFTW_FLAGS} \ + >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" + fi + FFTW_CFLAGS="-I'${pkg_install_dir}/include'" + FFTW_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding FFTW from system paths ====================" if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" + echo "--pack-run mode specified, skip system check" exit 0 fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d fftw-${fftw_ver} ] && rm -rf fftw-${fftw_ver} - tar -xzf ${fftw_pkg} - cd fftw-${fftw_ver} - FFTW_FLAGS="--enable-openmp --enable-shared" - # fftw has mpi support but not compiled by default. so compile it if we build with mpi. - # it will create a second library to link with if needed - [ "${MPI_MODE}" != "no" ] && FFTW_FLAGS="--enable-mpi ${FFTW_FLAGS}" - if [ "${TARGET_CPU}" = "native" ]; then - if [ -f /proc/cpuinfo ]; then - grep '\bavx\b' /proc/cpuinfo 1>/dev/null && FFTW_FLAGS="${FFTW_FLAGS} --enable-avx" - grep '\bavx2\b' /proc/cpuinfo 1>/dev/null && FFTW_FLAGS="${FFTW_FLAGS} --enable-avx2" - grep '\bavx512f\b' /proc/cpuinfo 1>/dev/null && FFTW_FLAGS="${FFTW_FLAGS} --enable-avx512" - fi - fi - # ABACUS need float version and double version fftw at the same time - # install float version fftw - echo "install float version fftw" - ./configure --prefix="${pkg_install_dir}" \ - --libdir="${pkg_install_dir}/lib" \ - --enable-float \ - ${FFTW_FLAGS} \ - >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log - make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log - make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log - # install double version fftw - echo "clean" - make distclean >/dev/null 2>&1 || true - echo "install double version fftw" - ./configure --prefix="${pkg_install_dir}" \ - --libdir="${pkg_install_dir}/lib" \ - ${FFTW_FLAGS} \ - >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log - make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log - make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log - cd .. - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" - fi - FFTW_CFLAGS="-I'${pkg_install_dir}/include'" - FFTW_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; -__SYSTEM__) - echo "==================== Finding FFTW from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_lib -lfftw3 "FFTW" - check_lib -lfftw3_omp "FFTW" - [ "${MPI_MODE}" != "no" ] && check_lib -lfftw3_mpi "FFTW" - add_include_from_paths FFTW_CFLAGS "fftw3.h" FFTW_INC ${INCLUDE_PATHS} - add_lib_from_paths FFTW_LDFLAGS "libfftw3.*" ${LIB_PATHS} - ;; -__DONTUSE__) - ;; -*) - echo "==================== Linking FFTW to user paths ====================" - pkg_install_dir="$with_fftw" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - FFTW_CFLAGS="-I'${pkg_install_dir}/include'" - FFTW_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; + check_lib -lfftw3 "FFTW" + check_lib -lfftw3_omp "FFTW" + [ "${MPI_MODE}" != "no" ] && check_lib -lfftw3_mpi "FFTW" + add_include_from_paths FFTW_CFLAGS "fftw3.h" FFTW_INC ${INCLUDE_PATHS} + add_lib_from_paths FFTW_LDFLAGS "libfftw3.*" ${LIB_PATHS} + ;; + __DONTUSE__) + ;; + *) + echo "==================== Linking FFTW to user paths ====================" + pkg_install_dir="$with_fftw" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + FFTW_CFLAGS="-I'${pkg_install_dir}/include'" + FFTW_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "$with_fftw" != "__DONTUSE__" ]; then [ "$MPI_MODE" != "no" ] && FFTW_LIBS="IF_MPI(-lfftw3_mpi|)" diff --git a/toolchain/scripts/stage3/install_libxc.sh b/toolchain/scripts/stage3/install_libxc.sh index 92643e16ba6..54553bfb848 100755 --- a/toolchain/scripts/stage3/install_libxc.sh +++ b/toolchain/scripts/stage3/install_libxc.sh @@ -43,65 +43,65 @@ LIBXC_LIBS="" cd "${BUILDDIR}" case "$with_libxc" in -__INSTALL__) - echo "==================== Installing LIBXC ====================" - pkg_install_dir="${INSTALLDIR}/libxc-${libxc_ver}" - #pkg_install_dir="${HOME}/lib/libxc/${libxc_ver}-gcc8" - install_lock_file="${pkg_install_dir}/install_successful" - if verify_checksums "${install_lock_file}"; then - echo "libxc-${libxc_ver} is already installed, skipping it." - else - libxc_url="https://gitlab.com/libxc/libxc/-/archive/${libxc_ver}/${libxc_pkg}" - retrieve_package "${libxc_sha256}" "${libxc_pkg}" "${libxc_url}" + __INSTALL__) + echo "==================== Installing LIBXC ====================" + pkg_install_dir="${INSTALLDIR}/libxc-${libxc_ver}" + #pkg_install_dir="${HOME}/lib/libxc/${libxc_ver}-gcc8" + install_lock_file="${pkg_install_dir}/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "libxc-${libxc_ver} is already installed, skipping it." + else + libxc_url="https://gitlab.com/libxc/libxc/-/archive/${libxc_ver}/${libxc_pkg}" + retrieve_package "${libxc_sha256}" "${libxc_pkg}" "${libxc_url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d libxc-${libxc_ver} ] && rm -rf libxc-${libxc_ver} + tar -xjf ${libxc_pkg} + cd libxc-${libxc_ver} + mkdir build + cd build + cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=${pkg_install_dir} \ + -DBUILD_SHARED_LIBS=ON \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DENABLE_FORTRAN=ON \ + -DENABLE_PYTHON=OFF \ + -DBUILD_TESTING=OFF .. \ + >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + cd ../.. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" + fi + LIBXC_CFLAGS="-I'${pkg_install_dir}/include'" + LIBXC_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding LIBXC from system paths ====================" if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" + echo "--pack-run mode specified, skip system check" exit 0 fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d libxc-${libxc_ver} ] && rm -rf libxc-${libxc_ver} - tar -xjf ${libxc_pkg} - cd libxc-${libxc_ver} - mkdir build - cd build - cmake \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=${pkg_install_dir} \ - -DBUILD_SHARED_LIBS=ON \ - -DCMAKE_INSTALL_LIBDIR=lib \ - -DCMAKE_VERBOSE_MAKEFILE=ON \ - -DENABLE_FORTRAN=ON \ - -DENABLE_PYTHON=OFF \ - -DBUILD_TESTING=OFF .. \ - >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log - make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log - make install >install.log 2>&1 || tail -n ${LOG_LINES} install.log - cd ../.. - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" - fi - LIBXC_CFLAGS="-I'${pkg_install_dir}/include'" - LIBXC_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; -__SYSTEM__) - echo "==================== Finding LIBXC from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_lib -lxcf03 "libxc" - check_lib -lxc "libxc" - add_include_from_paths LIBXC_CFLAGS "xc.h" $INCLUDE_PATHS - add_lib_from_paths LIBXC_LDFLAGS "libxc.*" $LIB_PATHS - ;; -__DONTUSE__) ;; + check_lib -lxcf03 "libxc" + check_lib -lxc "libxc" + add_include_from_paths LIBXC_CFLAGS "xc.h" $INCLUDE_PATHS + add_lib_from_paths LIBXC_LDFLAGS "libxc.*" $LIB_PATHS + ;; + __DONTUSE__) ;; -*) - echo "==================== Linking LIBXC to user paths ====================" - pkg_install_dir="$with_libxc" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - LIBXC_CFLAGS="-I'${pkg_install_dir}/include'" - LIBXC_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; + *) + echo "==================== Linking LIBXC to user paths ====================" + pkg_install_dir="$with_libxc" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + LIBXC_CFLAGS="-I'${pkg_install_dir}/include'" + LIBXC_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "$with_libxc" != "__DONTUSE__" ]; then LIBXC_LIBS="-lxcf03 -lxc" diff --git a/toolchain/scripts/stage3/install_scalapack.sh b/toolchain/scripts/stage3/install_scalapack.sh index 1bb911d0bcc..66d686df23a 100755 --- a/toolchain/scripts/stage3/install_scalapack.sh +++ b/toolchain/scripts/stage3/install_scalapack.sh @@ -41,69 +41,69 @@ SCALAPACK_LIBS="" cd "${BUILDDIR}" case "${with_scalapack}" in -__INSTALL__) - echo "==================== Installing ScaLAPACK ====================" - pkg_install_dir="${INSTALLDIR}/scalapack-${scalapack_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - if verify_checksums "${install_lock_file}"; then - echo "scalapack-${scalapack_ver} is already installed, skipping it." - else - require_env MATH_LIBS - url="https://codeload.github.com/Reference-ScaLAPACK/scalapack/tar.gz/v${scalapack_ver}" - retrieve_package "${scalapack_sha256}" "${scalapack_pkg}" "${url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d scalapack-${scalapack_ver} ] && rm -rf scalapack-${scalapack_ver} - tar -xzf ${scalapack_pkg} + __INSTALL__) + echo "==================== Installing ScaLAPACK ====================" + pkg_install_dir="${INSTALLDIR}/scalapack-${scalapack_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "scalapack-${scalapack_ver} is already installed, skipping it." + else + require_env MATH_LIBS + url="https://codeload.github.com/Reference-ScaLAPACK/scalapack/tar.gz/v${scalapack_ver}" + retrieve_package "${scalapack_sha256}" "${scalapack_pkg}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d scalapack-${scalapack_ver} ] && rm -rf scalapack-${scalapack_ver} + tar -xzf ${scalapack_pkg} - mkdir -p "scalapack-${scalapack_ver}/build" - pushd "scalapack-${scalapack_ver}/build" >/dev/null + mkdir -p "scalapack-${scalapack_ver}/build" + pushd "scalapack-${scalapack_ver}/build" >/dev/null - cflags="" - fflags="" - if ("${FC}" --version | grep -q 'GNU'); then - cflags="-fpermissive" - fflags=$(allowed_gfortran_flags "-fallow-argument-mismatch") - fi - CFLAGS=${cflags} FFLAGS=${fflags} \ - cmake -DCMAKE_FIND_ROOT_PATH="$ROOTDIR" \ - -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ - -DCMAKE_INSTALL_LIBDIR="lib" \ - -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ - -DCMAKE_VERBOSE_MAKEFILE=ON \ - -DBUILD_SHARED_LIBS=YES \ - -DCMAKE_BUILD_TYPE=Release .. \ - -DBUILD_TESTING=NO \ - -DSCALAPACK_BUILD_TESTS=NO \ - >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log - make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log - make install >>make.log 2>&1 || tail -n ${LOG_LINES} make.log + cflags="" + fflags="" + if ("${FC}" --version | grep -q 'GNU'); then + cflags="-fpermissive" + fflags=$(allowed_gfortran_flags "-fallow-argument-mismatch") + fi + CFLAGS=${cflags} FFLAGS=${fflags} \ + cmake -DCMAKE_FIND_ROOT_PATH="$ROOTDIR" \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR="lib" \ + -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DBUILD_SHARED_LIBS=YES \ + -DCMAKE_BUILD_TYPE=Release .. \ + -DBUILD_TESTING=NO \ + -DSCALAPACK_BUILD_TESTS=NO \ + >configure.log 2>&1 || tail -n ${LOG_LINES} configure.log + make -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make install >>make.log 2>&1 || tail -n ${LOG_LINES} make.log - popd >/dev/null - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" - fi - SCALAPACK_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; -__SYSTEM__) - echo "==================== Finding ScaLAPACK from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_lib -lscalapack "ScaLAPACK" - add_lib_from_paths SCALAPACK_LDFLAGS "libscalapack.*" $LIB_PATHS - ;; -__DONTUSE__) ;; + popd >/dev/null + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage3/$(basename ${SCRIPT_NAME})" + fi + SCALAPACK_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding ScaLAPACK from system paths ====================" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip system check" + exit 0 + fi + check_lib -lscalapack "ScaLAPACK" + add_lib_from_paths SCALAPACK_LDFLAGS "libscalapack.*" $LIB_PATHS + ;; + __DONTUSE__) ;; -*) - echo "==================== Linking ScaLAPACK to user paths ====================" - pkg_install_dir="$with_scalapack" - check_dir "${pkg_install_dir}/lib" - SCALAPACK_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; + *) + echo "==================== Linking ScaLAPACK to user paths ====================" + pkg_install_dir="$with_scalapack" + check_dir "${pkg_install_dir}/lib" + SCALAPACK_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "$with_scalapack" != "__DONTUSE__" ]; then SCALAPACK_LIBS="-lscalapack" diff --git a/toolchain/scripts/stage4/install_cereal.sh b/toolchain/scripts/stage4/install_cereal.sh index ada3c88977f..0f24b42d1ef 100755 --- a/toolchain/scripts/stage4/install_cereal.sh +++ b/toolchain/scripts/stage4/install_cereal.sh @@ -42,77 +42,77 @@ CEREAL_CFLAGS="" cd "${BUILDDIR}" case "$with_cereal" in -__INSTALL__) - echo "==================== Installing CEREAL ====================" - pkg_install_dir="${INSTALLDIR}/$dirname" - #pkg_install_dir="${HOME}/lib/cereal/${cereal_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - # url construction rules: - # - Branch names (master, main, develop) without v prefix - # - Version tags (e.g., 1.0.0) with v prefix - if [[ "${cereal_ver}" =~ ^([0-9a-f]{7}|[0-9a-f]{40})$ ]]; then - url="https://codeload.github.com/USCiLab/cereal/tar.gz/${cereal_ver}" - else - url="https://codeload.github.com/USCiLab/cereal/tar.gz/v${cereal_ver}" - fi - if verify_checksums "${install_lock_file}"; then - echo "$dirname is already installed, skipping it." - else - retrieve_package "${cereal_sha256}" "${filename}" "${url}" + __INSTALL__) + echo "==================== Installing CEREAL ====================" + pkg_install_dir="${INSTALLDIR}/$dirname" + #pkg_install_dir="${HOME}/lib/cereal/${cereal_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + # url construction rules: + # - Branch names (master, main, develop) without v prefix + # - Version tags (e.g., 1.0.0) with v prefix + if [[ "${cereal_ver}" =~ ^([0-9a-f]{7}|[0-9a-f]{40})$ ]]; then + url="https://codeload.github.com/USCiLab/cereal/tar.gz/${cereal_ver}" + else + url="https://codeload.github.com/USCiLab/cereal/tar.gz/v${cereal_ver}" + fi + if verify_checksums "${install_lock_file}"; then + echo "$dirname is already installed, skipping it." + else + retrieve_package "${cereal_sha256}" "${filename}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d $dirname ] && rm -rf $dirname + tar -xzf $filename + cd "${dirname}" + # + mkdir build && cd build + cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR="lib" \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DBUILD_DOC=OFF \ + -DBUILD_SANDBOX=OFF \ + -DBUILD_TESTS=OFF \ + -DTHREAD_SAFE=ON \ + -DSKIP_PORTABILITY_TEST=ON \ + -DSKIP_PERFORMANCE_COMPARISON=ON \ + .. >cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make install -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" + fi + CEREAL_CFLAGS="-I'${pkg_install_dir}/include'" + ;; + __SYSTEM__) + echo "==================== Finding CEREAL from system paths ====================" if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" + echo "--pack-run mode specified, skip system check" exit 0 fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d $dirname ] && rm -rf $dirname - tar -xzf $filename - cd "${dirname}" - # - mkdir build && cd build - cmake \ - -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ - -DCMAKE_INSTALL_LIBDIR="lib" \ - -DCMAKE_VERBOSE_MAKEFILE=ON \ - -DBUILD_DOC=OFF \ - -DBUILD_SANDBOX=OFF \ - -DBUILD_TESTS=OFF \ - -DTHREAD_SAFE=ON \ - -DSKIP_PORTABILITY_TEST=ON \ - -DSKIP_PERFORMANCE_COMPARISON=ON \ - .. >cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log - make install -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" - fi - CEREAL_CFLAGS="-I'${pkg_install_dir}/include'" - ;; -__SYSTEM__) - echo "==================== Finding CEREAL from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - # Find cereal header file and derive package root directory - cereal_header_path="$(find_in_paths "cereal/cereal.hpp" $INCLUDE_PATHS)" - if [ "$cereal_header_path" != "__FALSE__" ]; then - # Derive pkg_install_dir from found header path - # cereal/cereal.hpp -> remove /cereal/cereal.hpp -> get include dir -> get parent dir - cereal_include_dir="$(dirname "$(dirname "$cereal_header_path")")" - pkg_install_dir="$(dirname "$cereal_include_dir")" - echo "Found cereal at: ${pkg_install_dir}" - CEREAL_CFLAGS="-I'${cereal_include_dir}'" - else - report_error "Cannot find cereal/cereal.hpp in system paths" - exit 1 - fi - ;; -__DONTUSE__) ;; + # Find cereal header file and derive package root directory + cereal_header_path="$(find_in_paths "cereal/cereal.hpp" $INCLUDE_PATHS)" + if [ "$cereal_header_path" != "__FALSE__" ]; then + # Derive pkg_install_dir from found header path + # cereal/cereal.hpp -> remove /cereal/cereal.hpp -> get include dir -> get parent dir + cereal_include_dir="$(dirname "$(dirname "$cereal_header_path")")" + pkg_install_dir="$(dirname "$cereal_include_dir")" + echo "Found cereal at: ${pkg_install_dir}" + CEREAL_CFLAGS="-I'${cereal_include_dir}'" + else + report_error "Cannot find cereal/cereal.hpp in system paths" + exit 1 + fi + ;; + __DONTUSE__) ;; -*) - echo "==================== Linking CEREAL to user paths ====================" - pkg_install_dir="${with_cereal}" - check_dir "${pkg_install_dir}" - CEREAL_CFLAGS="-I'${pkg_install_dir}/include'" - ;; + *) + echo "==================== Linking CEREAL to user paths ====================" + pkg_install_dir="${with_cereal}" + check_dir "${pkg_install_dir}" + CEREAL_CFLAGS="-I'${pkg_install_dir}/include'" + ;; esac if [ "$with_cereal" != "__DONTUSE__" ]; then if [ "$with_cereal" != "__SYSTEM__" ]; then diff --git a/toolchain/scripts/stage4/install_dftd4.sh b/toolchain/scripts/stage4/install_dftd4.sh index 1c7196f8ff4..bf9d786cce5 100755 --- a/toolchain/scripts/stage4/install_dftd4.sh +++ b/toolchain/scripts/stage4/install_dftd4.sh @@ -23,63 +23,63 @@ source "${INSTALLDIR}"/toolchain.env cd "${BUILDDIR}" case "${with_dftd4}" in -__INSTALL__) - echo "==================== Installing DFT-D4 ====================" - url="https://github.com/dftd4/dftd4/releases/download/v${dftd4_ver}/${dftd4_pkg}" - pkg_install_dir="${INSTALLDIR}/dftd4-${dftd4_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - - if verify_checksums "${install_lock_file}"; then - echo "dftd4-${dftd4_ver} is already installed, skipping it." - else - retrieve_package "${dftd4_sha256}" "${dftd4_pkg}" "${url}" + __INSTALL__) + echo "==================== Installing DFT-D4 ====================" + url="https://github.com/dftd4/dftd4/releases/download/v${dftd4_ver}/${dftd4_pkg}" + pkg_install_dir="${INSTALLDIR}/dftd4-${dftd4_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + + if verify_checksums "${install_lock_file}"; then + echo "dftd4-${dftd4_ver} is already installed, skipping it." + else + retrieve_package "${dftd4_sha256}" "${dftd4_pkg}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + + echo "Installing from scratch into ${pkg_install_dir}" + [ -d "dftd4-${dftd4_ver}" ] && rm -rf "dftd4-${dftd4_ver}" + tar -xJf "${dftd4_pkg}" + cd dftd4-${dftd4_ver} + + mkdir build && cd build + CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}:${OPENBLAS_ROOT}" cmake \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + .. >cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log + make install -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" + fi + ;; + + __SYSTEM__) + echo "==================== Finding DFT-D4 from system paths ====================" if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" + echo "--pack-run mode specified, skip system check" exit 0 fi + check_command pkg-config --modversion dftd4 + pkg_install_dir="$(dirname $(dirname $(find_in_paths "libdftd4.*" $LIB_PATHS)))" + if [ -d "${pkg_install_dir}/lib/cmake/dftd4" ] || + [ -d "${pkg_install_dir}/lib64/cmake/dftd4" ]; then + echo "Package dftd4 is found and confirmed to be built with CMake." + else + echo "ERROR: ABACUS requires dftd4 to be built with CMake." + exit 1 + fi + ;; - echo "Installing from scratch into ${pkg_install_dir}" - [ -d "dftd4-${dftd4_ver}" ] && rm -rf "dftd4-${dftd4_ver}" - tar -xJf "${dftd4_pkg}" - cd dftd4-${dftd4_ver} - - mkdir build && cd build - CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}:${OPENBLAS_ROOT}" cmake \ - -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ - -DCMAKE_INSTALL_LIBDIR=lib \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_VERBOSE_MAKEFILE=ON \ - .. >cmake.log 2>&1 || tail -n ${LOG_LINES} cmake.log - make install -j $(get_nprocs) >make.log 2>&1 || tail -n ${LOG_LINES} make.log - cd .. - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" - fi - ;; - -__SYSTEM__) - echo "==================== Finding DFT-D4 from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_command pkg-config --modversion dftd4 - pkg_install_dir="$(dirname $(dirname $(find_in_paths "libdftd4.*" $LIB_PATHS)))" - if [ -d "${pkg_install_dir}/lib/cmake/dftd4" ] || - [ -d "${pkg_install_dir}/lib64/cmake/dftd4" ]; then - echo "Package dftd4 is found and confirmed to be built with CMake." - else - echo "ERROR: ABACUS requires dftd4 to be built with CMake." - exit 1 - fi - ;; - -__DONTUSE__) ;; + __DONTUSE__) ;; -*) - echo "==================== Linking DFT-D4 to user paths ====================" - pkg_install_dir="$with_dftd4" - check_dir "${pkg_install_dir}/include" - ;; + *) + echo "==================== Linking DFT-D4 to user paths ====================" + pkg_install_dir="$with_dftd4" + check_dir "${pkg_install_dir}/include" + ;; esac if [ "${with_dftd4}" != "__DONTUSE__" ]; then diff --git a/toolchain/scripts/stage4/install_json.sh b/toolchain/scripts/stage4/install_json.sh index ce1852d3e11..a7fce477ea2 100755 --- a/toolchain/scripts/stage4/install_json.sh +++ b/toolchain/scripts/stage4/install_json.sh @@ -17,41 +17,41 @@ cd "${BUILDDIR}" pkg_install_dir="" case "${with_json}" in -__INSTALL__) - echo "==================== Installing nlohmann-json ====================" - filename="json-${json_ver}.tar.xz" - url="https://github.com/nlohmann/json/releases/download/v${json_ver}/json.tar.xz" - pkg_install_dir="${INSTALLDIR}/json-${json_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - if verify_checksums "${install_lock_file}"; then - echo "json-${json_ver} is already installed, skipping it." - else - retrieve_package "${json_sha256}" "${filename}" "${url}" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 + __INSTALL__) + echo "==================== Installing nlohmann-json ====================" + filename="json-${json_ver}.tar.xz" + url="https://github.com/nlohmann/json/releases/download/v${json_ver}/json.tar.xz" + pkg_install_dir="${INSTALLDIR}/json-${json_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + if verify_checksums "${install_lock_file}"; then + echo "json-${json_ver} is already installed, skipping it." + else + retrieve_package "${json_sha256}" "${filename}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + [ -d "json-${json_ver}" ] && rm -rf "json-${json_ver}" + tar -xJf "json-${json_ver}.tar.xz" + cd "json" + mkdir build && cd build + cmake .. \ + -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ + -DJSON_BuildTests=OFF \ + >cmake.log 2>&1 || tail -n "${LOG_LINES}" cmake.log + make install -j "$(get_nprocs)" >install.log 2>&1 || tail -n "${LOG_LINES}" install.log + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/install_json.sh" fi - [ -d "json-${json_ver}" ] && rm -rf "json-${json_ver}" - tar -xJf "json-${json_ver}.tar.xz" - cd "json" - mkdir build && cd build - cmake .. \ - -DCMAKE_INSTALL_PREFIX="${pkg_install_dir}" \ - -DJSON_BuildTests=OFF \ - >cmake.log 2>&1 || tail -n "${LOG_LINES}" cmake.log - make install -j "$(get_nprocs)" >install.log 2>&1 || tail -n "${LOG_LINES}" install.log - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/install_json.sh" - fi - ;; -__SYSTEM__) - # ABACUS resolves the installed configuration with CMake's find_package. - echo "Using system nlohmann-json (resolved by CMake)." - ;; -__DONTUSE__) ;; -*) - pkg_install_dir="${with_json}" - check_dir "${pkg_install_dir}" - ;; + ;; + __SYSTEM__) + # ABACUS resolves the installed configuration with CMake's find_package. + echo "Using system nlohmann-json (resolved by CMake)." + ;; + __DONTUSE__) ;; + *) + pkg_install_dir="${with_json}" + check_dir "${pkg_install_dir}" + ;; esac if [ -n "${pkg_install_dir}" ]; then diff --git a/toolchain/scripts/stage4/install_libcomm.sh b/toolchain/scripts/stage4/install_libcomm.sh index 6f3cbad9966..1c491fc38d2 100755 --- a/toolchain/scripts/stage4/install_libcomm.sh +++ b/toolchain/scripts/stage4/install_libcomm.sh @@ -45,65 +45,65 @@ source "${INSTALLDIR}"/toolchain.env cd "${BUILDDIR}" case "$with_libcomm" in -__INSTALL__) - echo "==================== Installing LIBCOMM ====================" - pkg_install_dir="${INSTALLDIR}/$dirname" - #pkg_install_dir="${HOME}/lib/libcomm/${libcomm_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - # url="https://github.com/abacusmodeling/LibComm/archive/refs/tags/v${libcomm_ver}.tar.gz" - # url construction rules: - # - Branch names (master, main, develop) without v prefix - # - Version tags (e.g., 1.0.0) with v prefix - if [[ "${libcomm_ver}" =~ ^([0-9a-f]{7}|[0-9a-f]{40})$ ]]; then - url="https://codeload.github.com/abacusmodeling/LibComm/tar.gz/${libcomm_ver}" - else - url="https://codeload.github.com/abacusmodeling/LibComm/tar.gz/v${libcomm_ver}" - fi - if verify_checksums "${install_lock_file}"; then - echo "$dirname is already installed, skipping it." - else - retrieve_package "${libcomm_sha256}" "${filename}" "${url}" + __INSTALL__) + echo "==================== Installing LIBCOMM ====================" + pkg_install_dir="${INSTALLDIR}/$dirname" + #pkg_install_dir="${HOME}/lib/libcomm/${libcomm_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + # url="https://github.com/abacusmodeling/LibComm/archive/refs/tags/v${libcomm_ver}.tar.gz" + # url construction rules: + # - Branch names (master, main, develop) without v prefix + # - Version tags (e.g., 1.0.0) with v prefix + if [[ "${libcomm_ver}" =~ ^([0-9a-f]{7}|[0-9a-f]{40})$ ]]; then + url="https://codeload.github.com/abacusmodeling/LibComm/tar.gz/${libcomm_ver}" + else + url="https://codeload.github.com/abacusmodeling/LibComm/tar.gz/v${libcomm_ver}" + fi + if verify_checksums "${install_lock_file}"; then + echo "$dirname is already installed, skipping it." + else + retrieve_package "${libcomm_sha256}" "${filename}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d $dirname ] && rm -rf $dirname + tar -xzf $filename + mkdir -p "${pkg_install_dir}" + cp -r $dirname/* "${pkg_install_dir}/" + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" + fi + LIBCOMM_CFLAGS="-I'${pkg_install_dir}/include'" + ;; + __SYSTEM__) + echo "==================== Finding LIBCOMM from system paths ====================" if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" + echo "--pack-run mode specified, skip system check" exit 0 fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d $dirname ] && rm -rf $dirname - tar -xzf $filename - mkdir -p "${pkg_install_dir}" - cp -r $dirname/* "${pkg_install_dir}/" - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" - fi - LIBCOMM_CFLAGS="-I'${pkg_install_dir}/include'" - ;; -__SYSTEM__) - echo "==================== Finding LIBCOMM from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - # Find libcomm header file and derive package root directory - libcomm_header_path="$(find_in_paths "Comm/Comm_Tools.h" $INCLUDE_PATHS)" - if [ "$libcomm_header_path" != "__FALSE__" ]; then - # Derive pkg_install_dir from found header path - # Comm/Comm_Tools.h -> remove /Comm/Comm_Tools.h -> get include dir -> get parent dir - libcomm_include_dir="$(dirname "$(dirname "$libcomm_header_path")")" - pkg_install_dir="$(dirname "$libcomm_include_dir")" - echo "Found libcomm at: ${pkg_install_dir}" - LIBCOMM_CFLAGS="-I'${libcomm_include_dir}'" - else - report_error "Cannot find Comm/Comm_Tools.h in system paths" - exit 1 - fi - ;; -__DONTUSE__) ;; + # Find libcomm header file and derive package root directory + libcomm_header_path="$(find_in_paths "Comm/Comm_Tools.h" $INCLUDE_PATHS)" + if [ "$libcomm_header_path" != "__FALSE__" ]; then + # Derive pkg_install_dir from found header path + # Comm/Comm_Tools.h -> remove /Comm/Comm_Tools.h -> get include dir -> get parent dir + libcomm_include_dir="$(dirname "$(dirname "$libcomm_header_path")")" + pkg_install_dir="$(dirname "$libcomm_include_dir")" + echo "Found libcomm at: ${pkg_install_dir}" + LIBCOMM_CFLAGS="-I'${libcomm_include_dir}'" + else + report_error "Cannot find Comm/Comm_Tools.h in system paths" + exit 1 + fi + ;; + __DONTUSE__) ;; -*) - echo "==================== Linking LIBCOMM to user paths ====================" - pkg_install_dir="${with_libcomm}" - check_dir "${pkg_install_dir}" - LIBCOMM_CFLAGS="-I'${pkg_install_dir}/include'" - ;; + *) + echo "==================== Linking LIBCOMM to user paths ====================" + pkg_install_dir="${with_libcomm}" + check_dir "${pkg_install_dir}" + LIBCOMM_CFLAGS="-I'${pkg_install_dir}/include'" + ;; esac if [ "$with_libcomm" != "__DONTUSE__" ]; then if [ "$with_libcomm" != "__SYSTEM__" ]; then diff --git a/toolchain/scripts/stage4/install_libnpy.sh b/toolchain/scripts/stage4/install_libnpy.sh index 94c3da8a076..a0ecf8697b2 100755 --- a/toolchain/scripts/stage4/install_libnpy.sh +++ b/toolchain/scripts/stage4/install_libnpy.sh @@ -45,57 +45,57 @@ LIBNPY_CFLAGS="" cd "${BUILDDIR}" case "$with_libnpy" in -__INSTALL__) - echo "==================== Installing LIBNPY ====================" - pkg_install_dir="${INSTALLDIR}/$dirname" - #pkg_install_dir="${HOME}/lib/libnpy/${libnpy_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - url="https://codeload.github.com/llohse/libnpy/tar.gz/v${libnpy_ver}" - if verify_checksums "${install_lock_file}"; then - echo "$dirname is already installed, skipping it." - else - retrieve_package "${libnpy_sha256}" "${filename}" "${url}" + __INSTALL__) + echo "==================== Installing LIBNPY ====================" + pkg_install_dir="${INSTALLDIR}/$dirname" + #pkg_install_dir="${HOME}/lib/libnpy/${libnpy_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + url="https://codeload.github.com/llohse/libnpy/tar.gz/v${libnpy_ver}" + if verify_checksums "${install_lock_file}"; then + echo "$dirname is already installed, skipping it." + else + retrieve_package "${libnpy_sha256}" "${filename}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d $dirname ] && rm -rf $dirname + tar -xzf $filename + mkdir -p "${pkg_install_dir}" + cp -r $dirname/* "${pkg_install_dir}/" + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" + fi + LIBNPY_CFLAGS="-I'${pkg_install_dir}/include'" + ;; + __SYSTEM__) + echo "==================== Finding LIBNPY from system paths ====================" if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" + echo "--pack-run mode specified, skip system check" exit 0 fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d $dirname ] && rm -rf $dirname - tar -xzf $filename - mkdir -p "${pkg_install_dir}" - cp -r $dirname/* "${pkg_install_dir}/" - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" - fi - LIBNPY_CFLAGS="-I'${pkg_install_dir}/include'" - ;; -__SYSTEM__) - echo "==================== Finding LIBNPY from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - # Find libnpy header file and derive package root directory - libnpy_header_path="$(find_in_paths "npy.hpp" $INCLUDE_PATHS)" - if [ "$libnpy_header_path" != "__FALSE__" ]; then - # Derive pkg_install_dir from found header path - # npy.hpp -> get include dir -> get parent dir - libnpy_include_dir="$(dirname "$libnpy_header_path")" - pkg_install_dir="$(dirname "$libnpy_include_dir")" - echo "Found libnpy at: ${pkg_install_dir}" - LIBNPY_CFLAGS="-I'${libnpy_include_dir}'" - else - report_error "Cannot find npy.hpp in system paths" - exit 1 - fi - ;; -__DONTUSE__) ;; + # Find libnpy header file and derive package root directory + libnpy_header_path="$(find_in_paths "npy.hpp" $INCLUDE_PATHS)" + if [ "$libnpy_header_path" != "__FALSE__" ]; then + # Derive pkg_install_dir from found header path + # npy.hpp -> get include dir -> get parent dir + libnpy_include_dir="$(dirname "$libnpy_header_path")" + pkg_install_dir="$(dirname "$libnpy_include_dir")" + echo "Found libnpy at: ${pkg_install_dir}" + LIBNPY_CFLAGS="-I'${libnpy_include_dir}'" + else + report_error "Cannot find npy.hpp in system paths" + exit 1 + fi + ;; + __DONTUSE__) ;; -*) - echo "==================== Linking LIBNPY to user paths ====================" - pkg_install_dir="${with_libnpy}" - check_dir "${pkg_install_dir}" - LIBNPY_CFLAGS="-I'${pkg_install_dir}/include'" - ;; + *) + echo "==================== Linking LIBNPY to user paths ====================" + pkg_install_dir="${with_libnpy}" + check_dir "${pkg_install_dir}" + LIBNPY_CFLAGS="-I'${pkg_install_dir}/include'" + ;; esac if [ "$with_libnpy" != "__DONTUSE__" ]; then if [ "$with_libnpy" != "__SYSTEM__" ]; then diff --git a/toolchain/scripts/stage4/install_libri.sh b/toolchain/scripts/stage4/install_libri.sh index 197462af7ab..c6fce10280f 100755 --- a/toolchain/scripts/stage4/install_libri.sh +++ b/toolchain/scripts/stage4/install_libri.sh @@ -43,66 +43,66 @@ source "${INSTALLDIR}"/toolchain.env cd "${BUILDDIR}" case "$with_libri" in -__INSTALL__) - echo "==================== Installing LIBRI ====================" - dirname="LibRI-${libri_ver}" - pkg_install_dir="${INSTALLDIR}/$dirname" - #pkg_install_dir="${HOME}/lib/libri/${libri_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - # url construction rules: - # - Branch names (master, main, develop) without v prefix - # - Version tags (e.g., 1.0.0) with v prefix - if [[ "${libri_ver}" =~ ^([0-9a-f]{7}|[0-9a-f]{40})$ ]]; then - url="https://codeload.github.com/abacusmodeling/LibRI/tar.gz/${libri_ver}" - else - url="https://codeload.github.com/abacusmodeling/LibRI/tar.gz/v${libri_ver}" - fi - filename="LibRI-${libri_ver}.tar.gz" - if verify_checksums "${install_lock_file}"; then - echo "$dirname is already installed, skipping it." - else - retrieve_package "${libri_sha256}" "${filename}" "${url}" + __INSTALL__) + echo "==================== Installing LIBRI ====================" + dirname="LibRI-${libri_ver}" + pkg_install_dir="${INSTALLDIR}/$dirname" + #pkg_install_dir="${HOME}/lib/libri/${libri_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + # url construction rules: + # - Branch names (master, main, develop) without v prefix + # - Version tags (e.g., 1.0.0) with v prefix + if [[ "${libri_ver}" =~ ^([0-9a-f]{7}|[0-9a-f]{40})$ ]]; then + url="https://codeload.github.com/abacusmodeling/LibRI/tar.gz/${libri_ver}" + else + url="https://codeload.github.com/abacusmodeling/LibRI/tar.gz/v${libri_ver}" + fi + filename="LibRI-${libri_ver}.tar.gz" + if verify_checksums "${install_lock_file}"; then + echo "$dirname is already installed, skipping it." + else + retrieve_package "${libri_sha256}" "${filename}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d $dirname ] && rm -rf $dirname + tar -xzf $filename + mkdir -p "${pkg_install_dir}" + cp -r $dirname/* "${pkg_install_dir}/" + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" + fi + LIBRI_CFLAGS="-I'${pkg_install_dir}/include'" + ;; + __SYSTEM__) + echo "==================== Finding LIBRI from system paths ====================" if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" + echo "--pack-run mode specified, skip system check" exit 0 fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d $dirname ] && rm -rf $dirname - tar -xzf $filename - mkdir -p "${pkg_install_dir}" - cp -r $dirname/* "${pkg_install_dir}/" - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" - fi - LIBRI_CFLAGS="-I'${pkg_install_dir}/include'" - ;; -__SYSTEM__) - echo "==================== Finding LIBRI from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - # Find libri header file and derive package root directory - libri_header_path="$(find_in_paths "RI/version.h" $INCLUDE_PATHS)" - if [ "$libri_header_path" != "__FALSE__" ]; then - # Derive pkg_install_dir from found header path - # RI/version.h -> remove /RI/version.h -> get include dir -> get parent dir - libri_include_dir="$(dirname "$(dirname "$libri_header_path")")" - pkg_install_dir="$(dirname "$libri_include_dir")" - echo "Found libri at: ${pkg_install_dir}" - LIBRI_CFLAGS="-I'${libri_include_dir}'" - else - report_error "Cannot find RI/version.h in system paths" - exit 1 - fi - ;; -__DONTUSE__) ;; + # Find libri header file and derive package root directory + libri_header_path="$(find_in_paths "RI/version.h" $INCLUDE_PATHS)" + if [ "$libri_header_path" != "__FALSE__" ]; then + # Derive pkg_install_dir from found header path + # RI/version.h -> remove /RI/version.h -> get include dir -> get parent dir + libri_include_dir="$(dirname "$(dirname "$libri_header_path")")" + pkg_install_dir="$(dirname "$libri_include_dir")" + echo "Found libri at: ${pkg_install_dir}" + LIBRI_CFLAGS="-I'${libri_include_dir}'" + else + report_error "Cannot find RI/version.h in system paths" + exit 1 + fi + ;; + __DONTUSE__) ;; -*) - echo "==================== Linking LIBRI to user paths ====================" - pkg_install_dir="${with_libri}" - check_dir "${pkg_install_dir}" - LIBRI_CFLAGS="-I'${pkg_install_dir}/include'" - ;; + *) + echo "==================== Linking LIBRI to user paths ====================" + pkg_install_dir="${with_libri}" + check_dir "${pkg_install_dir}" + LIBRI_CFLAGS="-I'${pkg_install_dir}/include'" + ;; esac if [ "$with_libri" != "__DONTUSE__" ]; then if [ "$with_libri" != "__SYSTEM__" ]; then diff --git a/toolchain/scripts/stage4/install_libtorch.sh b/toolchain/scripts/stage4/install_libtorch.sh index 83c99c3f0fb..b9b425ff948 100755 --- a/toolchain/scripts/stage4/install_libtorch.sh +++ b/toolchain/scripts/stage4/install_libtorch.sh @@ -41,61 +41,61 @@ source "${INSTALLDIR}"/toolchain.env cd "${BUILDDIR}" case "${with_libtorch}" in -__INSTALL__) - echo "==================== Installing libtorch ====================" - dirname="libtorch-${libtorch_ver}" - pkg_install_dir="${INSTALLDIR}/${dirname}" - #pkg_install_dir="${HOME}/lib/libtorch/${libtorch_ver}" - install_lock_file="${pkg_install_dir}/install_successful" - archive_file="libtorch-cxx11-abi-shared-with-deps-${libtorch_ver}%2Bcpu.zip" - filename="${dirname}.zip" - - if verify_checksums "${install_lock_file}"; then - echo "${dirname} is already installed, skipping it." - else - url=https://download.pytorch.org/libtorch/cpu/${archive_file} - retrieve_package "${libtorch_sha256}" "${filename}" "${url}" + __INSTALL__) + echo "==================== Installing libtorch ====================" + dirname="libtorch-${libtorch_ver}" + pkg_install_dir="${INSTALLDIR}/${dirname}" + #pkg_install_dir="${HOME}/lib/libtorch/${libtorch_ver}" + install_lock_file="${pkg_install_dir}/install_successful" + archive_file="libtorch-cxx11-abi-shared-with-deps-${libtorch_ver}%2Bcpu.zip" + filename="${dirname}.zip" + + if verify_checksums "${install_lock_file}"; then + echo "${dirname} is already installed, skipping it." + else + url=https://download.pytorch.org/libtorch/cpu/${archive_file} + retrieve_package "${libtorch_sha256}" "${filename}" "${url}" + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + unzip -q $filename + mkdir -p "${pkg_install_dir}" + mv libtorch/* "${pkg_install_dir}/" + + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" + fi + LIBTORCH_CXXFLAGS="-I${pkg_install_dir}/include" + LIBTORCH_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath='${pkg_install_dir}/lib'" + ;; + __SYSTEM__) + echo "==================== Finding libtorch from system paths ====================" if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" + echo "--pack-run mode specified, skip system check" exit 0 fi - echo "Installing from scratch into ${pkg_install_dir}" - unzip -q $filename - mkdir -p "${pkg_install_dir}" - mv libtorch/* "${pkg_install_dir}/" - - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" - fi - LIBTORCH_CXXFLAGS="-I${pkg_install_dir}/include" - LIBTORCH_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath='${pkg_install_dir}/lib'" - ;; -__SYSTEM__) - echo "==================== Finding libtorch from system paths ====================" - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip system check" - exit 0 - fi - check_lib -ltorch "libtorch" - add_include_from_paths LIBTORCH_CXXFLAGS "libtorch.h" $INCLUDE_PATHS - add_lib_from_paths LIBTORCH_LDFLAGS "libtorch.*" "$LIB_PATHS" - ;; -__DONTUSE__) ;; - -*) - echo "==================== Linking libtorch to user paths ====================" - pkg_install_dir="${with_libtorch}" - - # use the lib64 directory if present (multi-abi distros may link lib/ to lib32/ instead) - LIBTORCH_LIBDIR="${pkg_install_dir}/lib" - [ -d "${pkg_install_dir}/lib64" ] && LIBTORCH_LIBDIR="${pkg_install_dir}/lib64" - - check_dir "${LIBTORCH_LIBDIR}" - LIBTORCH_CXXFLAGS="-I${pkg_install_dir}/include" - if [ "$ENABLE_CUDA" = "__TRUE__" ]; then - LIBTORCH_LDFLAGS="-Wl,--no-as-needed,-L'${LIBTORCH_LIBDIR}' -Wl,--no-as-needed,-rpath='${LIBTORCH_LIBDIR}'" - LIBTORCH_LDFLAGS="-L'${LIBTORCH_LIBDIR}' -Wl,-rpath='${LIBTORCH_LIBDIR}'" - fi - ;; + check_lib -ltorch "libtorch" + add_include_from_paths LIBTORCH_CXXFLAGS "libtorch.h" $INCLUDE_PATHS + add_lib_from_paths LIBTORCH_LDFLAGS "libtorch.*" "$LIB_PATHS" + ;; + __DONTUSE__) ;; + + *) + echo "==================== Linking libtorch to user paths ====================" + pkg_install_dir="${with_libtorch}" + + # use the lib64 directory if present (multi-abi distros may link lib/ to lib32/ instead) + LIBTORCH_LIBDIR="${pkg_install_dir}/lib" + [ -d "${pkg_install_dir}/lib64" ] && LIBTORCH_LIBDIR="${pkg_install_dir}/lib64" + + check_dir "${LIBTORCH_LIBDIR}" + LIBTORCH_CXXFLAGS="-I${pkg_install_dir}/include" + if [ "$ENABLE_CUDA" = "__TRUE__" ]; then + LIBTORCH_LDFLAGS="-Wl,--no-as-needed,-L'${LIBTORCH_LIBDIR}' -Wl,--no-as-needed,-rpath='${LIBTORCH_LIBDIR}'" + LIBTORCH_LDFLAGS="-L'${LIBTORCH_LIBDIR}' -Wl,-rpath='${LIBTORCH_LIBDIR}'" + fi + ;; esac if [ "$with_libtorch" != "__DONTUSE__" ]; then diff --git a/toolchain/scripts/stage4/install_nep.sh b/toolchain/scripts/stage4/install_nep.sh index 92ea89a53f6..4d956ac38d0 100755 --- a/toolchain/scripts/stage4/install_nep.sh +++ b/toolchain/scripts/stage4/install_nep.sh @@ -26,29 +26,29 @@ NEP_LIBS="" cd "${BUILDDIR}" case "$with_nep" in -__INSTALL__) - echo "==================== Installing NEP (CPU version) ====================" - dirname="NEP_CPU-${nep_ver}" - pkg_install_dir="${INSTALLDIR}/${dirname}" - install_lock_file="${pkg_install_dir}/install_successful" - filename="nep-${nep_ver}.tar.gz" - url="https://codeload.github.com/brucefan1983/NEP_CPU/tar.gz/${nep_ver}" - - if verify_checksums "${install_lock_file}"; then - echo "$dirname is already installed, skipping it." - else - retrieve_package "${nep_sha256}" "${filename}" "${url}" - - if [ "${PACK_RUN}" = "__TRUE__" ]; then - echo "--pack-run mode specified, skip installation" - exit 0 - fi - echo "Installing from scratch into ${pkg_install_dir}" - [ -d $dirname ] && rm -rf $dirname - tar -xzf $filename - cd $dirname - - cat <Makefile + __INSTALL__) + echo "==================== Installing NEP (CPU version) ====================" + dirname="NEP_CPU-${nep_ver}" + pkg_install_dir="${INSTALLDIR}/${dirname}" + install_lock_file="${pkg_install_dir}/install_successful" + filename="nep-${nep_ver}.tar.gz" + url="https://codeload.github.com/brucefan1983/NEP_CPU/tar.gz/${nep_ver}" + + if verify_checksums "${install_lock_file}"; then + echo "$dirname is already installed, skipping it." + else + retrieve_package "${nep_sha256}" "${filename}" "${url}" + + if [ "${PACK_RUN}" = "__TRUE__" ]; then + echo "--pack-run mode specified, skip installation" + exit 0 + fi + echo "Installing from scratch into ${pkg_install_dir}" + [ -d $dirname ] && rm -rf $dirname + tar -xzf $filename + cd $dirname + + cat <Makefile CXX ?= g++ # Compiler flags @@ -89,31 +89,31 @@ install: cp src/*.h \$(PREFIX)/include/ EOF - make >make.log 2>&1 || tail -n ${LOG_LINES} make.log - make PREFIX="${pkg_install_dir}" install >install.log 2>&1 || tail -n ${LOG_LINES} install.log + make >make.log 2>&1 || tail -n ${LOG_LINES} make.log + make PREFIX="${pkg_install_dir}" install >install.log 2>&1 || tail -n ${LOG_LINES} install.log - cd .. - write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" - fi - NEP_CFLAGS="-I'${pkg_install_dir}/include'" - NEP_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; - -__SYSTEM__) - echo "==================== Finding NEP_CPU from system paths ====================" - check_lib -lnep "nep" - add_include_from_paths NEP_CFLAGS "nep.h" $INCLUDE_PATHS - add_lib_from_paths NEP_LDFLAGS "libnep.*" $LIB_PATHS - ;; -__DONTUSE__) ;; -*) - echo "==================== Linking NEP_CPU to user paths ====================" - pkg_install_dir="$with_nep" - check_dir "${pkg_install_dir}/lib" - check_dir "${pkg_install_dir}/include" - NEP_CFLAGS="-I'${pkg_install_dir}/include'" - NEP_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" - ;; + cd .. + write_checksums "${install_lock_file}" "${SCRIPT_DIR}/stage4/$(basename ${SCRIPT_NAME})" + fi + NEP_CFLAGS="-I'${pkg_install_dir}/include'" + NEP_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; + + __SYSTEM__) + echo "==================== Finding NEP_CPU from system paths ====================" + check_lib -lnep "nep" + add_include_from_paths NEP_CFLAGS "nep.h" $INCLUDE_PATHS + add_lib_from_paths NEP_LDFLAGS "libnep.*" $LIB_PATHS + ;; + __DONTUSE__) ;; + *) + echo "==================== Linking NEP_CPU to user paths ====================" + pkg_install_dir="$with_nep" + check_dir "${pkg_install_dir}/lib" + check_dir "${pkg_install_dir}/include" + NEP_CFLAGS="-I'${pkg_install_dir}/include'" + NEP_LDFLAGS="-L'${pkg_install_dir}/lib' -Wl,-rpath,'${pkg_install_dir}/lib'" + ;; esac if [ "$with_nep" != "__DONTUSE__" ]; then diff --git a/toolchain/scripts/tool_kit.sh b/toolchain/scripts/tool_kit.sh index 1bd8194ccd2..94899286525 100755 --- a/toolchain/scripts/tool_kit.sh +++ b/toolchain/scripts/tool_kit.sh @@ -781,19 +781,19 @@ append_path() { read_enable() { local __input_var="${1#*=}" case $__input_var in - "$1") - # if there is no "=" then treat as "yes" - echo "__TRUE__" - ;; - yes) - echo "__TRUE__" - ;; - no) - echo "__FALSE__" - ;; - *) - echo "__INVALID__" - ;; + "$1") + # if there is no "=" then treat as "yes" + echo "__TRUE__" + ;; + yes) + echo "__TRUE__" + ;; + no) + echo "__FALSE__" + ;; + *) + echo "__INVALID__" + ;; esac } @@ -801,26 +801,26 @@ read_enable() { read_with() { local __input_var="${1#--with*=}" case $__input_var in - "${1}") - # if there is no "=" then treat as "install" - if [ ${#} -gt 1 ]; then - echo "${2}" - else + "${1}") + # if there is no "=" then treat as "install" + if [ ${#} -gt 1 ]; then + echo "${2}" + else + echo "__INSTALL__" + fi + ;; + install) echo "__INSTALL__" - fi - ;; - install) - echo "__INSTALL__" - ;; - system) - echo "__SYSTEM__" - ;; - no) - echo "__DONTUSE__" - ;; - *) - echo "${__input_var//\~/$HOME}" - ;; + ;; + system) + echo "__SYSTEM__" + ;; + no) + echo "__DONTUSE__" + ;; + *) + echo "${__input_var//\~/$HOME}" + ;; esac } @@ -887,22 +887,22 @@ verify_file_integrity() { local hash_command case "$hash_type" in - sha256) - hash_command="sha256sum" - command -v "$hash_command" >/dev/null 2>&1 || hash_command="shasum -a 256" - ;; - sha1) - hash_command="sha1sum" - command -v "$hash_command" >/dev/null 2>&1 || hash_command="shasum -a 1" - ;; - md5) - hash_command="md5sum" - command -v "$hash_command" >/dev/null 2>&1 || hash_command="md5" - ;; - *) - report_error_enhanced 1 "Unsupported hash type" "$hash_type" - return 1 - ;; + sha256) + hash_command="sha256sum" + command -v "$hash_command" >/dev/null 2>&1 || hash_command="shasum -a 256" + ;; + sha1) + hash_command="sha1sum" + command -v "$hash_command" >/dev/null 2>&1 || hash_command="shasum -a 1" + ;; + md5) + hash_command="md5sum" + command -v "$hash_command" >/dev/null 2>&1 || hash_command="md5" + ;; + *) + report_error_enhanced 1 "Unsupported hash type" "$hash_type" + return 1 + ;; esac local computed_hash @@ -933,47 +933,47 @@ download_pkg_from_url() { # Smart certificate validation strategy case "${DOWNLOAD_CERT_POLICY:-smart}" in - "strict") - echo "Downloading with strict certificate validation: $__url" - if ! wget ${DOWNLOADER_FLAGS} "$__url" -O "$__filename"; then - rm -f "$__filename" - report_error "failed to download $__url (strict certificate validation)" - recommend_offline_installation "$__filename" "$__url" - if [ "${PACK_RUN}" != "__TRUE__" ]; then - return 1 - fi - fi - ;; - "skip") - echo "Downloading with certificate validation disabled: $__url" - if ! wget ${DOWNLOADER_FLAGS} "$__url" -O "$__filename" --no-check-certificate; then - rm -f "$__filename" - report_error "failed to download $__url" - recommend_offline_installation "$__filename" "$__url" - if [ "${PACK_RUN}" != "__TRUE__" ]; then - return 1 + "strict") + echo "Downloading with strict certificate validation: $__url" + if ! wget ${DOWNLOADER_FLAGS} "$__url" -O "$__filename"; then + rm -f "$__filename" + report_error "failed to download $__url (strict certificate validation)" + recommend_offline_installation "$__filename" "$__url" + if [ "${PACK_RUN}" != "__TRUE__" ]; then + return 1 + fi fi - fi - ;; - "smart" | *) - # Smart fallback: try with certificate validation first, then without - echo "Attempting secure download: $__url" - if wget ${DOWNLOADER_FLAGS} "$__url" -O "$__filename"; then - echo "Download successful with certificate validation" - else - echo "Certificate validation failed, retrying without certificate check..." + ;; + "skip") + echo "Downloading with certificate validation disabled: $__url" if ! wget ${DOWNLOADER_FLAGS} "$__url" -O "$__filename" --no-check-certificate; then rm -f "$__filename" - report_error "failed to download $__url (both secure and insecure attempts failed)" + report_error "failed to download $__url" recommend_offline_installation "$__filename" "$__url" if [ "${PACK_RUN}" != "__TRUE__" ]; then return 1 fi + fi + ;; + "smart" | *) + # Smart fallback: try with certificate validation first, then without + echo "Attempting secure download: $__url" + if wget ${DOWNLOADER_FLAGS} "$__url" -O "$__filename"; then + echo "Download successful with certificate validation" else - echo "Download successful without certificate validation" + echo "Certificate validation failed, retrying without certificate check..." + if ! wget ${DOWNLOADER_FLAGS} "$__url" -O "$__filename" --no-check-certificate; then + rm -f "$__filename" + report_error "failed to download $__url (both secure and insecure attempts failed)" + recommend_offline_installation "$__filename" "$__url" + if [ "${PACK_RUN}" != "__TRUE__" ]; then + return 1 + fi + else + echo "Download successful without certificate validation" + fi fi - fi - ;; + ;; esac # checksum diff --git a/toolchain/tests/test_installer_argument_failures.sh b/toolchain/tests/test_installer_argument_failures.sh index c87f59aed77..29d5066cbee 100755 --- a/toolchain/tests/test_installer_argument_failures.sh +++ b/toolchain/tests/test_installer_argument_failures.sh @@ -17,7 +17,7 @@ copy_toolchain() { while IFS= read -r -d '' entry; do name="${entry##*/}" case "$name" in - build | install) continue ;; + build | install) continue ;; esac cp -a "$entry" "${tmpdir}/toolchain/" done < <(find "${TOOLCHAIN_DIR}" -mindepth 1 -maxdepth 1 -print0)