source: palm/trunk/SCRIPTS/palm_simple_build @ 4047

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

added file update and unique run dirs to simple installation method

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