source: palm/trunk/SCRIPTS/palm_simple_build @ 2852

Last change on this file since 2852 was 2852, checked in by knoop, 7 years ago

Added simple build setup for gfortran

  • 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# Bugfix: adjusted name of build_dir
22#
23# Former revisions:
24# -----------------
25# $Id: palm_simple_build 2852 2018-03-05 14:43:22Z knoop $
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#------------------------------------------------------------------------------#
58SOURCE="${BASH_SOURCE[0]}"
59while [ -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"
65done
66SCRIPT_LOCATION="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
67
68working_dir=$(readlink -f "${SCRIPT_LOCATION}/../../")
69trunk_dir=$(readlink -f "${SCRIPT_LOCATION}/../")
70
71
72get_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
85print_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
95build_config=unknown
96clean="false"
97
98# Read shellscript options
99while  getopts  :b:xh  option
100do
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
110done
111
112if [[ ${build_config} == "unknown" ]]; then
113   echo "Missing option -b <build-config>"
114   print_help
115   exit 1
116fi
117
118
119build_dir=${working_dir}/BUILD_$build_config
120
121
122# Check, if include file exists
123build_config_file=${trunk_dir}/INSTALL/MAKE.inc.$build_config
124if [[ ! -f ${build_config_file} ]]; then
125   echo "+++ ERROR: no such make include file:"
126   echo "    \"${build_config_file}\""
127   exit 1
128fi
129
130
131# Create the make depository
132if [[ ! -d ${build_dir} ]]; then
133   mkdir -p ${build_dir}
134else
135   if [[ ${clean} == "true" ]]; then
136      echo "Cleaning the build directory..."
137      rm -rf ${build_dir}/*
138   fi
139fi
140
141
142# Copy makefile and all source code files to make depository
143cp -n ${trunk_dir}/SOURCE/Makefile  ${build_dir}/Makefile_in
144cp -n ${build_config_file}          ${build_dir}/MAKE.inc
145cp -n ${trunk_dir}/SOURCE/*.f90     ${build_dir}
146
147
148# Replace comment in makefile by include statement
149sed  's/#to_be_replaced_by_include/include MAKE.inc/g'  ${build_dir}/Makefile_in  >  ${build_dir}/Makefile
150rm  ${build_dir}/Makefile_in
151
152cd ${build_dir}
153make -j $(get_number_of_cpu_cores)
154cd ../
155
156
157echo "*** PALM build finished. Executable can be found in:"
158echo "    \"${build_dir}\""
159exit 0
Note: See TracBrowser for help on using the repository browser.