[2850] | 1 | #!/usr/bin/env bash |
---|
[1046] | 2 | #--------------------------------------------------------------------------------# |
---|
[2696] | 3 | # This file is part of the PALM model system. |
---|
[1046] | 4 | # |
---|
| 5 | # PALM is free software: you can redistribute it and/or modify it under the terms |
---|
| 6 | # of the GNU General Public License as published by the Free Software Foundation, |
---|
| 7 | # either version 3 of the License, or (at your option) any later version. |
---|
| 8 | # |
---|
| 9 | # PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 10 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 11 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 12 | # |
---|
| 13 | # You should have received a copy of the GNU General Public License along with |
---|
| 14 | # PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 15 | # |
---|
[2718] | 16 | # Copyright 1997-2018 Leibniz Universitaet Hannover |
---|
[1046] | 17 | #--------------------------------------------------------------------------------# |
---|
| 18 | # |
---|
| 19 | # Current revisions: |
---|
| 20 | # ----------------- |
---|
[2226] | 21 | # |
---|
[2868] | 22 | # |
---|
[1046] | 23 | # Former revisions: |
---|
| 24 | # ----------------- |
---|
| 25 | # $Id: palm_simple_build 2868 2018-03-09 13:25:09Z hellstea $ |
---|
[2868] | 26 | # Bugfix: adjusted name of build_dir |
---|
| 27 | # |
---|
| 28 | # 2852 2018-03-05 14:43:22Z knoop |
---|
[2850] | 29 | # Refactoring of the palm_simple_ build and run scripts |
---|
| 30 | # |
---|
| 31 | # 2718 2018-01-02 08:49:38Z maronga |
---|
[2716] | 32 | # Corrected "Former revisions" section |
---|
[1047] | 33 | # |
---|
[2716] | 34 | # 2696 2017-12-14 17:12:51Z kanani |
---|
| 35 | # Change in file header (GPL part) |
---|
| 36 | # |
---|
[2226] | 37 | # 2225 2017-05-16 11:36:20Z raasch |
---|
| 38 | # shell changed to bash |
---|
| 39 | # |
---|
[2716] | 40 | # 1310 2014-03-14 08:01:56Z raasch |
---|
| 41 | # update GPL copyright |
---|
| 42 | # |
---|
[1047] | 43 | # 1046 2012-11-09 14:38:45Z maronga |
---|
| 44 | # code put under GPL (PALM 3.9) |
---|
| 45 | # |
---|
[421] | 46 | # palm_simple_install - a script for simple installation and compilation of |
---|
| 47 | # the palm code without using mbuild |
---|
[2850] | 48 | # This script creates (from the working copy of the palm repository) |
---|
| 49 | # a subdirectory MAKE_DEPOSITORY_simple which contains a copy of the |
---|
| 50 | # palm source code and a modified makefile which loads required compiler |
---|
| 51 | # and preprocessor settings via "include MAKE.inc" |
---|
[421] | 52 | |
---|
[2850] | 53 | # Options: -i <include file> |
---|
| 54 | # one of the include files in ~/palm/current_version/trunk/INSTALL |
---|
[421] | 55 | |
---|
[2850] | 56 | # Last changes: |
---|
| 57 | # 25/01/10 - Siggi - Generating the first version |
---|
| 58 | # 18/03/10 - Siggi - switch to palm/current_version removed: working |
---|
| 59 | # copy can be in any directory |
---|
| 60 | #------------------------------------------------------------------------------# |
---|
| 61 | SOURCE="${BASH_SOURCE[0]}" |
---|
| 62 | while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink |
---|
| 63 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
---|
| 64 | SOURCE="$(readlink "$SOURCE")" |
---|
| 65 | # if $SOURCE was a relative symlink, we need to resolve it |
---|
| 66 | # relative to the path where the symlink file was located |
---|
| 67 | [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" |
---|
| 68 | done |
---|
| 69 | SCRIPT_LOCATION="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
---|
[421] | 70 | |
---|
[2850] | 71 | working_dir=$(readlink -f "${SCRIPT_LOCATION}/../../") |
---|
| 72 | trunk_dir=$(readlink -f "${SCRIPT_LOCATION}/../") |
---|
[421] | 73 | |
---|
| 74 | |
---|
[2850] | 75 | get_number_of_cpu_cores() { |
---|
| 76 | { |
---|
| 77 | n=$(sysctl -n machdep.cpu.core_count 2> /dev/null) |
---|
| 78 | } || { |
---|
| 79 | n=$(grep -c ^processor /proc/cpuinfo 2> /dev/null) |
---|
| 80 | } || { |
---|
| 81 | if ! [[ $n =~ ^-?[0-9]+$ ]]; then |
---|
| 82 | n=1 |
---|
| 83 | fi |
---|
| 84 | } |
---|
| 85 | echo $n |
---|
| 86 | } |
---|
[421] | 87 | |
---|
[2850] | 88 | print_help() { |
---|
| 89 | echo "Usage: palm_simple_run -b <build-config> [-x]" |
---|
| 90 | echo "" |
---|
| 91 | echo "List of allowed option:" |
---|
| 92 | echo "" |
---|
| 93 | echo " -b <build-config> Suffix of any MAKE.inc.<build-config> file in the trunk/INSTALL dir." |
---|
| 94 | echo " -x Clean the build directory from last build attempts" |
---|
| 95 | echo "" |
---|
| 96 | } |
---|
[421] | 97 | |
---|
[2850] | 98 | build_config=unknown |
---|
| 99 | clean="false" |
---|
[421] | 100 | |
---|
[2850] | 101 | # Read shellscript options |
---|
| 102 | while getopts :b:xh option |
---|
| 103 | do |
---|
| 104 | case $option in |
---|
| 105 | (b) build_config=$OPTARG;; |
---|
| 106 | (x) clean="true";; |
---|
| 107 | (h) print_help |
---|
| 108 | exit 0;; |
---|
| 109 | (\?) echo "Unknown option -$OPTARG" |
---|
| 110 | print_help |
---|
| 111 | exit 1;; |
---|
| 112 | esac |
---|
| 113 | done |
---|
[421] | 114 | |
---|
[2850] | 115 | if [[ ${build_config} == "unknown" ]]; then |
---|
| 116 | echo "Missing option -b <build-config>" |
---|
| 117 | print_help |
---|
| 118 | exit 1 |
---|
| 119 | fi |
---|
[421] | 120 | |
---|
| 121 | |
---|
[2852] | 122 | build_dir=${working_dir}/BUILD_$build_config |
---|
[421] | 123 | |
---|
| 124 | |
---|
[2850] | 125 | # Check, if include file exists |
---|
| 126 | build_config_file=${trunk_dir}/INSTALL/MAKE.inc.$build_config |
---|
| 127 | if [[ ! -f ${build_config_file} ]]; then |
---|
| 128 | echo "+++ ERROR: no such make include file:" |
---|
| 129 | echo " \"${build_config_file}\"" |
---|
| 130 | exit 1 |
---|
| 131 | fi |
---|
[421] | 132 | |
---|
| 133 | |
---|
[2850] | 134 | # Create the make depository |
---|
| 135 | if [[ ! -d ${build_dir} ]]; then |
---|
| 136 | mkdir -p ${build_dir} |
---|
| 137 | else |
---|
| 138 | if [[ ${clean} == "true" ]]; then |
---|
| 139 | echo "Cleaning the build directory..." |
---|
| 140 | rm -rf ${build_dir}/* |
---|
| 141 | fi |
---|
| 142 | fi |
---|
[421] | 143 | |
---|
| 144 | |
---|
[2850] | 145 | # Copy makefile and all source code files to make depository |
---|
| 146 | cp -n ${trunk_dir}/SOURCE/Makefile ${build_dir}/Makefile_in |
---|
| 147 | cp -n ${build_config_file} ${build_dir}/MAKE.inc |
---|
| 148 | cp -n ${trunk_dir}/SOURCE/*.f90 ${build_dir} |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | # Replace comment in makefile by include statement |
---|
| 152 | sed 's/#to_be_replaced_by_include/include MAKE.inc/g' ${build_dir}/Makefile_in > ${build_dir}/Makefile |
---|
| 153 | rm ${build_dir}/Makefile_in |
---|
| 154 | |
---|
| 155 | cd ${build_dir} |
---|
| 156 | make -j $(get_number_of_cpu_cores) |
---|
| 157 | cd ../ |
---|
| 158 | |
---|
| 159 | |
---|
| 160 | echo "*** PALM build finished. Executable can be found in:" |
---|
| 161 | echo " \"${build_dir}\"" |
---|
| 162 | exit 0 |
---|