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