Ignore:
Timestamp:
Mar 5, 2018 2:24:40 PM (4 years ago)
Author:
knoop
Message:

Refactoring of the palm_simple_ build and run scripts

File:
1 moved

Legend:

Unmodified
Added
Removed
  • palm/trunk/SCRIPTS/palm_simple_build

    r2849 r2850  
    1 #!/bin/bash
     1#!/usr/bin/env bash
    22#--------------------------------------------------------------------------------#
    33# This file is part of the PALM model system.
     
    2424# -----------------
    2525# $Id$
     26# Refactoring of the palm_simple_ build and run scripts
     27#
     28# 2718 2018-01-02 08:49:38Z maronga
    2629# Corrected "Former revisions" section
    2730#
     
    4043# palm_simple_install - a script for simple installation and compilation of
    4144#                       the palm code without using mbuild
    42      # This script creates (from the working copy of the palm repository)
    43      # a subdirectory MAKE_DEPOSITORY_simple which contains a copy of the
    44      # palm source code and  a modified makefile which loads required compiler
    45      # and preprocessor settings via "include MAKE.inc"
     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"
    4649
    47      # Options: -i <include file>
    48      #          one of the include files in ~/palm/current_version/trunk/INSTALL
     50# Options: -i <include file>
     51#          one of the include files in ~/palm/current_version/trunk/INSTALL
    4952
    50      # Last changes:
    51      # 25/01/10 - Siggi - Generating the first version
    52      # 18/03/10 - Siggi - switch to palm/current_version removed: working
    53      #                    copy can be in any directory
     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}/../")
    5470
    5571
    56     # Variable declarations + default values
    57  include_file=unknown
     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
    58117
    59118
    60     # Read shellscript options
    61  while  getopts  :i:  option
    62  do
    63    case  $option  in
    64        (i)   include_file=$OPTARG;;
    65        (\?)  printf "\n  +++ unknown option $OPTARG \n"
    66              printf "\n      allowed option are -d, -f, -l, -s \n"
    67              exit;;
    68    esac
    69  done
     119build_dir=${working_dir}/MAKE_DEPOSITORY_$build_config
    70120
    71121
    72 
    73     # Check, if include file exists
    74  if [[ ! -f trunk/INSTALL/$include_file ]]
    75  then
    76     echo "+++ ERROR: include file"
    77     echo "    \"trunk/INSTALL/$include_file\""
    78     echo "    not found"
    79     exit
    80  fi
     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
    81129
    82130
    83      # Create the make depository
    84  if [[ ! -d MAKE_DEPOSITORY_simple ]]
    85  then
    86     mkdir  MAKE_DEPOSITORY_simple
    87  else
    88     rm  MAKE_DEPOSITORY_simple/*
    89  fi
     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
    90140
    91141
    92      # Copy makefile and all source code files to make depository
    93  cp  trunk/SOURCE/Makefile        MAKE_DEPOSITORY_simple/Makefile_old
    94  cp  trunk/INSTALL/$include_file  MAKE_DEPOSITORY_simple/MAKE.inc
    95  cp  trunk/SOURCE/*.f90           MAKE_DEPOSITORY_simple
     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}
    96146
    97147
    98      # Replace comment in makefile by include statement
    99  sed  's/#to_be_replaced_by_include/include MAKE.inc/g'  MAKE_DEPOSITORY_simple/Makefile_old  >  MAKE_DEPOSITORY_simple/Makefile
    100  rm  MAKE_DEPOSITORY_simple/Makefile_old
     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 ../
    101155
    102156
    103      # Create directory for input files
    104  if [[ ! -d JOBS/example_cbl/INPUT ]]
    105  then
    106     mkdir -p  JOBS/example_cbl/INPUT
    107     cp trunk/INSTALL/example_cbl_p3d  JOBS/example_cbl/INPUT
    108  fi
     157echo "*** PALM build finished. Executable can be found in:"
     158echo "    \"${build_dir}\""
     159exit 0
Note: See TracChangeset for help on using the changeset viewer.