source: palm/trunk/SCRIPTS/palm_simple_build @ 2868

Last change on this file since 2868 was 2868, checked in by hellstea, 7 years ago

Local conditional Neumann conditions for one-way coupling removed

  • Property svn:executable set to *
  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
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#
22#
23# Former revisions:
24# -----------------
25# $Id: palm_simple_build 2868 2018-03-09 13:25:09Z hellstea $
26# Bugfix: adjusted name of build_dir
27#
28# 2852 2018-03-05 14:43:22Z knoop
29# Refactoring of the palm_simple_ build and run scripts
30#
31# 2718 2018-01-02 08:49:38Z maronga
32# Corrected "Former revisions" section
33#
34# 2696 2017-12-14 17:12:51Z kanani
35# Change in file header (GPL part)
36#
37# 2225 2017-05-16 11:36:20Z raasch
38# shell changed to bash
39#
40# 1310 2014-03-14 08:01:56Z raasch
41# update GPL copyright
42#
43# 1046 2012-11-09 14:38:45Z maronga
44# code put under GPL (PALM 3.9)
45#
46# palm_simple_install - a script for simple installation and compilation of
47#                       the palm code without using mbuild
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"
52
53# Options: -i <include file>
54#          one of the include files in ~/palm/current_version/trunk/INSTALL
55
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#------------------------------------------------------------------------------#
61SOURCE="${BASH_SOURCE[0]}"
62while [ -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"
68done
69SCRIPT_LOCATION="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
70
71working_dir=$(readlink -f "${SCRIPT_LOCATION}/../../")
72trunk_dir=$(readlink -f "${SCRIPT_LOCATION}/../")
73
74
75get_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}
87
88print_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}
97
98build_config=unknown
99clean="false"
100
101# Read shellscript options
102while  getopts  :b:xh  option
103do
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
113done
114
115if [[ ${build_config} == "unknown" ]]; then
116   echo "Missing option -b <build-config>"
117   print_help
118   exit 1
119fi
120
121
122build_dir=${working_dir}/BUILD_$build_config
123
124
125# Check, if include file exists
126build_config_file=${trunk_dir}/INSTALL/MAKE.inc.$build_config
127if [[ ! -f ${build_config_file} ]]; then
128   echo "+++ ERROR: no such make include file:"
129   echo "    \"${build_config_file}\""
130   exit 1
131fi
132
133
134# Create the make depository
135if [[ ! -d ${build_dir} ]]; then
136   mkdir -p ${build_dir}
137else
138   if [[ ${clean} == "true" ]]; then
139      echo "Cleaning the build directory..."
140      rm -rf ${build_dir}/*
141   fi
142fi
143
144
145# Copy makefile and all source code files to make depository
146cp -n ${trunk_dir}/SOURCE/Makefile  ${build_dir}/Makefile_in
147cp -n ${build_config_file}          ${build_dir}/MAKE.inc
148cp -n ${trunk_dir}/SOURCE/*.f90     ${build_dir}
149
150
151# Replace comment in makefile by include statement
152sed  's/#to_be_replaced_by_include/include MAKE.inc/g'  ${build_dir}/Makefile_in  >  ${build_dir}/Makefile
153rm  ${build_dir}/Makefile_in
154
155cd ${build_dir}
156make -j $(get_number_of_cpu_cores)
157cd ../
158
159
160echo "*** PALM build finished. Executable can be found in:"
161echo "    \"${build_dir}\""
162exit 0
Note: See TracBrowser for help on using the repository browser.