Changeset 2850 for palm/trunk/SCRIPTS/palm_simple_build
- Timestamp:
- Mar 5, 2018 2:24:40 PM (7 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
palm/trunk/SCRIPTS/palm_simple_build
r2849 r2850 1 #!/ bin/bash1 #!/usr/bin/env bash 2 2 #--------------------------------------------------------------------------------# 3 3 # This file is part of the PALM model system. … … 24 24 # ----------------- 25 25 # $Id$ 26 # Refactoring of the palm_simple_ build and run scripts 27 # 28 # 2718 2018-01-02 08:49:38Z maronga 26 29 # Corrected "Former revisions" section 27 30 # … … 40 43 # palm_simple_install - a script for simple installation and compilation of 41 44 # the palm code without using mbuild 42 43 44 45 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" 46 49 47 48 50 # Options: -i <include file> 51 # one of the include files in ~/palm/current_version/trunk/INSTALL 49 52 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 #------------------------------------------------------------------------------# 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}/../") 54 70 55 71 56 # Variable declarations + default values 57 include_file=unknown 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 58 117 59 118 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 119 build_dir=${working_dir}/MAKE_DEPOSITORY_$build_config 70 120 71 121 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 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 81 129 82 130 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 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 90 140 91 141 92 93 cp trunk/SOURCE/Makefile MAKE_DEPOSITORY_simple/Makefile_old 94 cp trunk/INSTALL/$include_file MAKE_DEPOSITORY_simple/MAKE.inc95 cp trunk/SOURCE/*.f90 MAKE_DEPOSITORY_simple 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} 96 146 97 147 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 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 ../ 101 155 102 156 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 157 echo "*** PALM build finished. Executable can be found in:" 158 echo " \"${build_dir}\"" 159 exit 0
Note: See TracChangeset
for help on using the changeset viewer.