#!/usr/bin/env bash #--------------------------------------------------------------------------------# # This file is part of the PALM model system. # # PALM is free software: you can redistribute it and/or modify it under the terms # of the GNU General Public License as published by the Free Software Foundation, # either version 3 of the License, or (at your option) any later version. # # PALM is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR # A PARTICULAR PURPOSE. See the GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along with # PALM. If not, see . # # Copyright 1997-2021 Leibniz Universitaet Hannover #--------------------------------------------------------------------------------# # project install script #--------------------------------------------------------------------------------# SOURCE="${BASH_SOURCE[0]}" while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" SOURCE="$(readlink "$SOURCE")" [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located done SCRIPT_LOCATION="$( cd -P "$( dirname "$SOURCE" )" && pwd )" project_root_dir=$(readlink -f "${SCRIPT_LOCATION}/") project_bin_dir=$(readlink -f "${project_root_dir}/bin/") project_build_dir=$(readlink -f "${project_root_dir}/build/") project_share_dir=$(readlink -f "${project_root_dir}/share/") project_src_dir=$(readlink -f "${project_root_dir}/src/") project_kpp_dir=$(readlink -f "${project_root_dir}/kpp/") install_prefix="${project_build_dir}" program_name="kpp4palm" install_function() { printf "### %s\n" "Installing ${program_name} ..." if [ "${do_clean}" == "true" ]; then rm -r ${project_build_dir} rm -r ${project_bin_dir} PROG=${program_name}.exe make -C ${project_src_dir} clean make -C ${project_kpp_dir} distclean fi # build kpp mkdir -p ${project_kpp_dir}/bin make -C ${project_kpp_dir} if [ ${?} -ne 0 ]; then echo "ERROR: Compilation of kpp failed." exit 1 fi # build kpp4palm mkdir -p ${project_bin_dir} PROG=${program_name}.exe make -C ${project_src_dir} if [ ${?} -ne 0 ]; then echo "ERROR: Compilation of ${program_name} failed." exit 1 fi cp -pf ${project_src_dir}/${program_name}.exe ${project_bin_dir}/. mkdir -p ${install_prefix} cd ${install_prefix} install_bin_dir=${install_prefix}/bin mkdir -p ${install_bin_dir} chmod a+x $(realpath "${project_root_dir}/scripts/kpp4palm.sh") ln -s -f $(realpath --relative-to="${install_bin_dir}" "${project_root_dir}/scripts/kpp4palm.sh") ${install_bin_dir}/${program_name} if ! test ${install_bin_dir}/${program_name}; then echo "ERROR: Installation of ${program_name} failed." exit 1 fi printf "### %s\n" "Installing ${program_name} finished." } show_usage() { echo "Usage: $0 [-h] [-p ] [-x]" } show_help() { show_usage echo " -h show this help message" echo " -p set installation directory" echo " -x clean already existing build files" } while getopts ":p:hx" o; do case "${o}" in p) install_prefix="$(readlink -m "${OPTARG}")" ;; x) do_clean="true" ;; h) show_help exit 0 ;; *) show_usage exit 1 ;; esac done # strip all parsed options from the options list shift $((OPTIND-1)) install_function