source: palm/trunk/SCRIPTS/palmbuild @ 4814

Last change on this file since 4814 was 4809, checked in by gronemeier, 4 years ago

Abort palmbuild if the execution of the module commands raise an error; update module command for HLRN Lise setup

  • Property svn:executable set to *
  • Property svn:keywords set to Id Rev
File size: 36.2 KB
RevLine 
[2380]1#!/bin/bash
2
3# palmbuild - script for compiling the PALM code and its utility programs
4
5#------------------------------------------------------------------------------#
[2696]6# This file is part of the PALM model system.
[2380]7#
8# PALM is free software: you can redistribute it and/or modify it under the terms
9# of the GNU General Public License as published by the Free Software Foundation,
10# either version 3 of the License, or (at your option) any later version.
11#
12# PALM is distributed in the hope that it will be useful, but WITHOUT ANY
13# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along with
17# PALM. If not, see <http://www.gnu.org/licenses/>.
18#
[4481]19# Copyright 2017-2020  Leibniz Universitaet Hannover
[2380]20#------------------------------------------------------------------------------#
21#
22# Current revisions:
23# ------------------
[4809]24#
25#
[2380]26# Former revisions:
27# -----------------
[3033]28# $Id: palmbuild 4809 2020-12-03 16:37:20Z gronemeier $
[4809]29# Abort if the execution of the module commands raise an error
30#
31# 4556 2020-06-08 06:29:28Z raasch
[4556]32# bugfix for determining the ssh-key givn in the configuration file
[4809]33#
[4556]34# 4481 2020-03-31 18:55:54Z maronga
[4303]35# Abort if SOURCES_FOR_RUN catalog cannot be created
[4809]36#
[4303]37# 4082 2019-07-10 14:42:00Z raasch
[4081]38# bugfix for executing module commands and for interpreting linker options
39# on local machines
[4809]40#
[4081]41# 3756 2019-02-20 11:24:32Z suehring
[4809]42# Disable compilation of postprocessing tool for surface output, until
43# crashes with unexpected segmentation faults with intel compiler are solved.
44#
[3756]45# 3725 2019-02-07 10:11:02Z raasch
[3549]46# ssh-calls for compilations on remote systems modified to avoid output
[3725]47# of login messages on specific systems changed again (reverted as before r3549)
[4809]48#
[3725]49# 3549 2018-11-21 15:44:44Z raasch
50# ssh-calls for compilations on remote systems modified to avoid output
[3549]51# of login messages on specific systems
[4809]52#
[3549]53# 3534 2018-11-19 15:35:16Z raasch
[3534]54# build of inifor added,
55# ssh-calls rearranged to avoid output of system/user-profile messages
[4809]56#
[3534]57# 3523 2018-11-13 16:09:31Z suehring
[3523]58# Enable compilation of post-processing tool for surface output - interface
59# for posix conform sytemcalls is implemented.
[4809]60#
[3523]61# 3499 2018-11-07 10:55:15Z suehring
[4809]62# Temporarily avoid compilation of post-processing tool for surface output
[3499]63# until a workaround for compiler-specific intrinsic functions is found.
[4809]64#
[3499]65# 3494 2018-11-06 14:51:27Z suehring
[3494]66# Add tool for surface-output post-processing
[4809]67#
[3494]68# 3455 2018-10-30 14:12:31Z raasch
[3455]69# options -h and -d renamed -c and -r, respectively
[4809]70#
[3455]71# 3312 2018-10-06 14:15:46Z knoop
[3236]72# "host identifier" in header output renamed "config. identifier",
73# host_configuration renamed configuration_identifier,
74# jobname renamed run_identifier
75# header output of PALM code revision,
76# options -m, -s, and -S removed
[4809]77#
[3236]78# 3210 2018-08-28 07:31:13Z sward
[3210]79# Bugfix: agent_preprocessing stays in MAKE_DEPOSITORY after compilation
[4809]80#
[3210]81# 3208 2018-08-27 13:10:50Z sward
[3208]82# Added building of agent_preprocessing
[4809]83#
[3208]84# 3033 2018-05-23 15:26:19Z raasch
[2834]85# "fname" renamed to "jobname"
[4809]86#
[2834]87# 2718 2018-01-02 08:49:38Z maronga
[2716]88# Corrected "Former revisions" section
[4809]89#
[2716]90# 2696 2017-12-14 17:12:51Z kanani
91# Change in file header (GPL part)
92#
93# 2566 2017-10-20 08:50:47Z raasch
[2566]94# informative messages switched of almost completely in silent mode
95# two header blocks merged into one
[4809]96#
[2566]97# 2506 2017-09-29 08:30:37Z raasch
[2506]98# option -V added to check for an existing SOURCES_FOR_RUN_... folder
99# host configuration added to SOURCES_FOR_RUN_... folder name
100# SOURCES_FOR_RUN_... folder is deleted in case of compilation errors
101# host_identifier renamed host_configuration
[4809]102#
[2506]103# 2500 2017-09-25 11:10:03Z raasch
[2500]104# bugfix for r2492
[4809]105#
[2500]106# 2492 2017-09-21 14:18:48Z raasch
[2489]107# ask for compilation, if SOURCES_FOR_RUN_... exists
[4809]108#
[2489]109# 2487 2017-09-21 11:30:10Z raasch
[2487]110# bugfix: abort in case of compiling/linking errors in silent mode
[4809]111#
[2487]112# 2422 2017-09-08 08:25:41Z raasch
[2422]113# initial revision
[4809]114#
[2380]115#------------------------------------------------------------------------------#
116# palmbuild - script for compiling the PALM code and its utility programs
117#
118# Procedure to compile code on local and remote hosts using the
119# make-mechanism. The source code must be provided on the local host.
120#
121# @note This script does not work on MAC OS
122#------------------------------------------------------------------------------#
123
124
125    # VARIABLE DECLARATIONS + DEFAULT VALUES
126 calltime=""
127 column1=""
128 column2=""
[3236]129 configuration_identifier=default
130 global_revision=""
[2380]131 locat=normal
132 makefile=""
133 make_options=""
134 module_commands=""
135 program_name=palm
136 remote_ip=""
137 silent=false
138 ssh_key=""
139 suf=f90
[2506]140 use_existing_sources_folder=false
[2732]141 version="palmbuild  1.0  Rev$Rev: 4809 $"
[2380]142 working_directory=`pwd`
143
144
[3312]145    # ERROR HANDLING IN CASE OF EXIT
[3236]146 trap 'rm -rf  ${source_path}/${configuration_identifier}_last_make_protocol
[3312]147       if [[ $locat != normal  &&  $locat != control_c ]]
[2380]148       then
[3312]149          printf "\n\n+++ palmbuild crashed \n\n"
[2380]150          exit 1
[3312]151       elif [[ $locat != normal ]]
152       then
153          printf "\n+++ palmbuild killed by \"^C\" \n\n"
154          exit 2
[2380]155       else
[2566]156          if [[ $silent = false ]]
157          then
[3312]158            printf "\n --> palmbuild finished\n\n"
[2566]159          fi
[2380]160          exit 0
[3312]161       fi' exit
[2380]162
163
[3312]164    # ACTIONS IN CASE OF TERMINAL-BREAK (CONTROL-C):
165 trap 'locat=control_c
166       exit 1
[2380]167      ' 2
168
169
170
171    # READ SHELLSCRIPT-OPTIONS
[3455]172 while  getopts  :c:r:uvV  option
[2380]173 do
174   case  $option  in
[3455]175       (c)   configuration_identifier=$OPTARG;;
176       (r)   run_identifier=$OPTARG;;
[2380]177       (v)   silent=true;;
[2506]178       (V)   use_existing_sources_folder=true;;
[2380]179       (\?)  printf "\n  +++ unknown option $OPTARG \n";
180             locat=parameter; exit;;
181   esac
182 done
183
184
[2506]185    # BUILD THE CONFIGURATION-FILE NAME AND THE SOURCES_FOR_RUN-FOLDER NAME
[3236]186 config_file=.palm.config.$configuration_identifier
187 sources_for_run_catalog=SOURCES_FOR_RUN_${configuration_identifier}_$run_identifier
[2380]188
189
190    # CHECK, IF CONFIGURATION-FILE EXISTS
191 if [[ ! -f $config_file ]]
192 then
193    printf "\n  +++ configuration file: "
194    printf "\n           $config_file"
195    printf "\n      does not exist"
[4809]196    locat=configuration; exit
[2380]197 fi
198
199
200    # ### is this really required?
201 config_file=$PWD/$config_file
202
203
204    # READ VARIABLE SETTINGS FROM CONFIG FILE LINE BY LINE
205 while  read line
206 do
207
208       # FIRST REPLACE ENVIRONMENT-VARIABLES BY THEIR RESPECTIVE VALUES
209    eval  line=\"$line\"
210
211
212       # INTERPRET THE LINE
213    if [[ "$(echo $line)" = "" ]]
214    then
215
216          # EMPTY LINE, NO ACTION
217       continue
218
219    elif [[ "$(echo $line | cut -c1)"  =  "#" ]]
220    then
221
222          # LINE IS A COMMENT LINE
223       continue
224
225    elif [[ "$(echo $line | cut -c1)"  =  "%" ]]
226    then
227
228          # LINE DEFINES AN ENVIRONMENT-VARIABLE
229       var=`echo $line | cut -d" " -s -f1 | cut -c2-`
230       value=`echo $line | cut -d" " -s -f2-`
231
232          # REPLACE ":" BY " " IN COMPILER- CPP- OR LINKER-OPTIONS,
233          # "::" IS REPLACED BY ":".
234       #value=`echo $value | sed 's/::/%DUM%/g' | sed 's/:/ /g' | sed 's/%DUM%/:/g'`
235
236
237          # VALUE FROM THE CONFIGURATION-FILE IS ASSIGNED TO THE
238          # ENVIRONMENT-VARIABLE, BUT ONLY IF NO VALUE HAS BEEN ALREADY
239          # ASSIGNED WITHIN THIS SCRIPT (E.G. BY SCRIPT-OPTIONS).
240          # NON-ASSIGNED VARIABLES HAVE VALUE "" OR 0 (IN CASE OF INTEGER).
241          # HENCE THE GENERAL RULE IS: SCRIPT-OPTION OVERWRITES THE
242          # CONFIGURATION-FILE.
243       if [[ "$(eval echo \$$var)" = ""  ||  "$(eval echo \$$var)" = "0" ]]
244       then
245          eval  export  $var="\$value"
246
247             # TERMINAL OUTPUT OF ENVIRONMENT-VARIABLES, IF TRACEBACK IS SWITCHED on
248          if [[ $do_trace = true ]]
249          then
250             printf "\n*** ENVIRONMENT-VARIABLE $var = $value"
251          fi
252       fi
253
254    else
255
256          # SKIP ALL OTHER LINES
257       continue
258
259    fi
260
261 done < $config_file
262
[4809]263
[2404]264    # CHECK, IF THE BASE DIRECTORY PATH HAS BEEN GIVEN
265 if [[ "$base_directory" = "" ]]
266 then
267    printf "\n  +++ no base directory found in configuration file"
268    locat=config_file; exit
269 else
270    if [[ ! -d $base_directory ]]
271    then
272       printf "\n\n  +++ base directory \"$base_directory\" "
273       printf "\n      does not exist"
274       locat=source_path; exit
275    fi
276 fi
277
278
[2380]279    # CHECK SOURCE-CODE PATH
280 if [[ "$source_path" = "" ]]
281 then
282    printf "\n  +++ no source path found in configuration file"
283    locat=config_file; exit
284 else
285    if [[ ! -d $source_path ]]
286    then
287       printf "\n\n  +++ source path \"$source_path\" "
288       printf "\n      does not exist"
289       locat=source_path; exit
290    fi
291 fi
292
293
294    # CHECK MAKEFILE
[3236]295 makefile=$source_path/Makefile
[2380]296 if [[ ! -f $makefile ]]
297 then
298    printf "\n  +++ makefile: "
299    printf "\n           $makefile"
300    printf "\n      does not exist"
[4809]301    locat=makefile; exit
[2380]302 fi
303
304
305    # CHECK COMPILERNAME
306 if [[ "$compiler_name" = "" ]]
307 then
308    printf "\n  +++ no compiler name found in configuration file"
309    locat=config_file; exit
310 fi
311
312
313    # CHECK SERIAL COMPILERNAME
314 if [[ "$compiler_name_ser" = "" ]]
315 then
316    printf "\n  +++ no compiler name for serial compilation in configuration file"
317    locat=config_file; exit
318 fi
319
320
[4556]321    # DETERMINE THE SSH-OPTION IN CASE THAT AN SSH-KEY IS EXPLICITLY GIVEN IN THE
322    # CONFIG-FILE
[2380]323 if [[ "$ssh_key" != "" ]]
324 then
[4556]325    ssh_key="-i $HOME/.ssh/$ssh_key"
[2380]326 fi
327
328
329    #CHECK CPP-OPTIONS
330 if [[ "$cpp_options" = "" ]]
331 then
332    printf "\n  +++ WARNING: no cpp-options found in configuration file"
333 fi
334
335
336    # CHECK SETTINGS IN CASE OF COMPILING ON REMOTE MACHINE
337 if [[ "$remote_ip" != "" ]]
338 then
[4809]339
[2380]340    if [[ "$remote_username" = "" ]]
341    then
342       printf "\n  +++ no user name given in configuration file"
343       locat=config_file; exit
344    fi
345
346       # GET SOURCE AND DEPOSITORY PATH ON THE REMOTE MACHINE WITHOUT EVALUATING
347       # THE $
348       # IF NOT GIVEN, USE THE LOCAL SOURCE AND DEPOSITORY PATH
349    line=`grep %remote_source_path $config_file`
350    if [[ "$line" != "" ]]
351    then
352       remote_source_path=`echo $line | cut -d" " -s -f2`
353    else
354       line=`grep %source_path $config_file`
355       remote_source_path=`echo $line | cut -d" " -s -f2`
356    fi
357
[2404]358    line=`grep %base_directory $config_file`
[3236]359    make_depository=`echo $line | cut -d" " -s -f2`/MAKE_DEPOSITORY_${configuration_identifier}
[2380]360
361 else
362
[3236]363    make_depository=${base_directory}/MAKE_DEPOSITORY_${configuration_identifier}
[2380]364
365 fi
366
[3236]367
368    # GET THE GLOBAL REVISION-NUMBER OF THE SVN-REPOSITORY
369 global_revision=`svnversion $source_path  2>/dev/null`
370 global_revision="Rev: $global_revision"
371
372
[2380]373    # HEADER-OUTPUT (PART1: MESSAGES CONCERNING THE LOCAL HOST)
374 if [[ $silent = false ]]
375 then
[2566]376    calltime=$(date)
377    printf "\n"
378    printf "#------------------------------------------------------------------------# \n"
379    printf "| %-40s%30s | \n" "$version" "$calltime"
[3236]380    printf "| %-40s%30s | \n" "PALM code       $global_revision" " "
[2566]381    printf "|                                                                        | \n"
382    printf "| %-13s%-57s | \n" "called on:" "$(hostname) (IP:$local_ip)"
383    column2=$(echo $config_file | cut -c1-57 )
384    printf "| %-13s%-57s | \n" "config file:" "$column2"
385    line=$(echo "$config_file" | cut -c58-)
386    while [[ "$line" != "" ]]
[2380]387    do
[2566]388       column1=""
389       column2=$(echo $line | cut -c1-57 )
390       printf "| %-13s%-57s | \n" "$column1" "$column2"
391       line=$(echo "$line" | cut -c58-)
[2380]392    done
[2566]393    column2=$(echo $makefile | cut -c1-57 )
394    printf "| %-13s%-57s | \n" "makefile:" "$column2"
395    line=$(echo "$makefile" | cut -c58-)
396    while [[ "$line" != "" ]]
397    do
398       column1=""
399       column2=$(echo $line | cut -c1-57 )
400       printf "| %-13s%-57s | \n" "$column1" "$column2"
401       line=$(echo "$line" | cut -c58-)
402    done
403    column2=$(echo $source_path | cut -c1-57 )
404    printf "| %-13s%-57s | \n" "source path:" "$column2"
405    line=$(echo "$source_path" | cut -c58-)
406    while [[ "$line" != "" ]]
407    do
408       column1=""
409       column2=$(echo $line | cut -c1-57 )
410       printf "| %-13s%-57s | \n" "$column1" "$column2"
411       line=$(echo "$line" | cut -c58-)
412    done
413    printf "|                                                                        | \n"
[4809]414
[2380]415    if [[ "$remote_ip" != "" ]]
416    then
[3236]417       column2="$configuration_identifier"
418       printf "| %-20s%-50s | \n" "config. identifier:" "$column2"
[2404]419       column2=$(echo "$make_depository" | cut -c1-50 )
[2380]420       printf "| %-20s%-50s | \n" "remote depository:" "$column2"
421    else
[3236]422       column2="$configuration_identifier"
423       printf "| %-20s%-50s | \n" "config. identifier:" "$column2"
[2404]424       column2=$(echo "$make_depository" | cut -c1-50 )
[2380]425       printf "| %-20s%-50s | \n" "local depository:" "$column2"
426    fi
[2404]427    line=$(echo "$make_depository" | cut -c51-)
428    while [[ "$line" != "" ]]
429    do
430       column1=""
431       column2=$(echo "$line" | cut -c1-50 )
432       printf "| %-20s%-50s | \n" "$column1" "$column2"
433       line=$(echo "$line" | cut -c51-)
434    done
[4809]435
[2380]436    if [[ "$remote_ip" != "" ]]
437    then
438       printf "| %-20s%-50s | \n" "remote username:" "$remote_username"
439       printf "| %-20s%-50s | \n" "remote address:" "$remote_ip"
440    else
441       printf "| %-20s%-50s | \n" "username:" "$local_username"
442       printf "| %-20s%-50s | \n" "address:" "$local_ip"
443    fi
[4809]444
[2380]445    printf "| %-20s%-50s | \n" "compiler:" "$compiler_name"
446    printf "| %-20s%-50s | \n" "serial compiler:" "$compiler_name_ser"
[4809]447
[2380]448    if [[ "$make_options" != "" ]]
449    then
450       printf "| %-20s%-50s | \n" "make options:" "$make_options"
451    fi
452    column2=$(echo "$cpp_options" | cut -c1-50 )
453    printf "| %-20s%-50s | \n" "cpp options:" "$column2"
454    line=$(echo "$cpp_options" | cut -c51-)
455    while [[ "$line" != "" ]]
456    do
457       column1=""
458       column2=$(echo "$line" | cut -c1-50 )
459       printf "| %-20s%-50s | \n" "$column1" "$column2"
460       line=$(echo "$line" | cut -c51-)
461    done
462    column2=$(echo "$compiler_options" | cut -c1-50 )
463    printf "| %-20s%-50s | \n" "compiler options:" "$column2"
464    line=$(echo "$compiler_options" | cut -c51-)
465    while [[ "$line" != "" ]]
466    do
467       column1=""
468       column2=$(echo "$line" | cut -c1-50 )
469       printf "| %-20s%-50s | \n" "$column1" "$column2"
470       line=$(echo "$line" | cut -c51-)
471    done
[2388]472    column2=$(echo "$linker_options" | cut -c1-50 )
473    printf "| %-20s%-50s | \n" "linker options:" "$column2"
474    line=$(echo "$linker_options" | cut -c51-)
[2380]475    while [[ "$line" != "" ]]
476    do
477       column1=""
478       column2=$(echo "$line" | cut -c1-50 )
479       printf "| %-20s%-50s | \n" "$column1" "$column2"
480       line=$(echo "$line" | cut -c51-)
481    done
482    if [[ "$login_init_cmd" != "" ]]
483    then
484       column2=$(echo "$login_init_cmd" | cut -c1-50 )
485       printf "| %-20s%-50s | \n" "login init command:" "$column2"
486       line=$(echo "$login_init_cmd" | cut -c51-)
487       while [[ "$line" != "" ]]
488       do
489          column1=""
490          column2=$(echo "$line" | cut -c1-50 )
491          printf "| %-20s%-50s | \n" "$column1" "$column2"
492          line=$(echo "$line" | cut -c51-)
493       done
494    fi
495    if [[ "$module_commands" != "" ]]
496    then
497       column2=$(echo "$module_commands" | cut -c1-50 )
498       printf "| %-20s%-50s | \n" "module command(s):" "$column2"
499       line=$(echo "$module_commands" | cut -c51-)
500       while [[ "$line" != "" ]]
501       do
502          column1=""
503          column2=$(echo "$line" | cut -c1-50 )
504          printf "| %-20s%-50s | \n" "$column1" "$column2"
505          line=$(echo "$line" | cut -c51-)
506       done
507    fi
508    printf "#------------------------------------------------------------------------# \n"
509
[2566]510    answer=dummy
511    printf "\n"
[3549]512    while [[ "$answer" != y  &&  "$answer" != Y  && "$answer" != s  &&  "$answer" != S  &&  "$answer" != a  &&  "$answer" != A ]]
[2566]513    do
[3549]514       printf " >>> continue (y(es)/a(bort)) ?  "
[2566]515       read  answer
516    done
517    if [[ $answer = a  ||  $answer = A ]]
[2380]518    then
[2566]519       locat=user_abort; exit
[2380]520    fi
[2566]521 fi
[2380]522
523
[2566]524    # TAR THE SOURCES AND MAKEFILES
525    # UTILITIES ARE TEMPORARILY COPIED TO THE SOURCE DIRECTORY IN ORDER TO TAR
526    # THEM TOO
527 if [[ $silent = false ]]
528 then
529    printf "\n\n  *** tar of makefile and source files in"
530    printf "\n      $source_path\n"
531 fi
532 cd  $source_path
533 cp -p  ../UTIL/combine_plot_fields.f90  .
534 cp -p  ../UTIL/compare_palm_logs.f90  .
[3208]535 cp -p  ../UTIL/agent_preprocessing/agent_preprocessing.f90  .
[3756]536 #cp -p  ../UTIL/surface_output_processing/surface_output_to_vtk.f90  .
[3534]537 cp -p  ../UTIL/inifor/src/inifor*f90  .
[2566]538 cp -p  ../UTIL/Makefile_utilities  .
539 tar -cf  ${program_name}_sources.tar  Makefile*  *.$suf
[3756]540 rm  combine_plot_fields.f90  compare_palm_logs.f90 agent_preprocessing.f90 Makefile_utilities inifor*f90 #surface_output_to_vtk.f90
[2566]541
542
543    # MAKE ON REMOTE HOST
544 if [[ "$remote_ip" != "" ]]
545 then
546
547       # NEXT IS THE BRANCH FOR CREATING THE MAKE_DEPOSITORY_...
[3236]548    if [[ "$run_identifier" = "" ]]
[2380]549    then
550
[2566]551          # COPY CURRENT SOURCE CODE TO SOURCE-CODE DIRECTORY ON THE REMOTE HOST
552          # CREATE THIS DIRECTORY, IF IT DOES NOT EXIST
553       if [[ $silent = false ]]
[2380]554       then
[2566]555          echo " "
[2404]556          echo "  *** copying \"${program_name}_sources.tar\" to \"${remote_ip}:${make_depository}/\" "
[3534]557          ssh  -q  $ssh_key ${remote_username}@${remote_ip}  "[[ ! -d ${make_depository} ]]  &&  (echo \"  *** ${make_depository} will be created\"; mkdir -p  ${make_depository})"  2>&1
[2404]558          scp  $ssh_key ${source_path}/${program_name}_sources.tar  ${remote_username}@${remote_ip}:${make_depository}/${program_name}_sources.tar
[2566]559       else
[3534]560          ssh  -q  $ssh_key ${remote_username}@${remote_ip}  "[[ ! -d ${make_depository} ]]  &&  mkdir -p  ${make_depository}"  2>&1
[2566]561          scp  $ssh_key ${source_path}/${program_name}_sources.tar  ${remote_username}@${remote_ip}:${make_depository}/${program_name}_sources.tar  >  /dev/null
562       fi
[2380]563
564
565
[2566]566
567          # UNTAR PREVIOUS UPDATE ON REMOTE HOST, IF EXISTING
568       if [[ $silent = false ]]
569       then
[2380]570          echo "  *** untar previous update on remote host, if existing"
[2566]571       fi
[3534]572       ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  "cd ${make_depository}; [[ -f ${program_name}_current_version.tar ]]  &&  tar -xf  ${program_name}_current_version.tar"  2>&1
[2380]573
574
[2566]575          # UNTAR CURRENT SOURCES ON REMOTE HOST
576       if [[ $silent = false ]]
577       then
[2380]578          echo "  *** untar current sources on remote host"
[2566]579       fi
[3534]580       ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  "cd ${make_depository}; tar -xf  ${program_name}_sources.tar"  2>&1
[2380]581
582
[2566]583          # CREATE INIT AND MODULE COAMMNDS
584       [[ "$login_init_cmd" != "" ]]   &&  login_init_cmd=${login_init_cmd}";"
585       [[ "$module_commands" != "" ]]  &&  module_commands=${module_commands}";"
[2380]586
587
[2566]588          # FIRST CREATE EXECUTABLES FOR THE UTILITY ROUTINES
589       if [[ $silent = false ]]
590       then
[2380]591          echo " "
592          echo "  *** creating utilities on remote host"
[2566]593       fi
594       make_call_string="make  -f Makefile_utilities  $make_options  F90=$compiler_name  F90_SER=$compiler_name_ser  COPT=\"$cpp_options\"  F90FLAGS=\"$compiler_options\"  LDFLAGS=\"$linker_options\" "
[3725]595###       echo "$login_init_cmd $module_commands cd ${make_depository}; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>/dev/null | tee ${configuration_identifier}_last_make_protocol
596       ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  "$login_init_cmd $module_commands cd ${make_depository}; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR"  2>&1 | tee ${configuration_identifier}_last_make_protocol
[2380]597
[3236]598       if [[ $(grep -c MAKE_ERROR ${configuration_identifier}_last_make_protocol) != 0 ]]
[2566]599       then
600          printf "\a\n  +++ error(s) occurred during compiling or linking of utilities"
[3236]601          printf "\n      for host configuration \"$configuration_identifier\" "
[2566]602          if [[ $silent = false ]]
[2380]603          then
[2566]604             answer=dummy
605             printf "\n"
606             while [[ "$answer" != c  &&  "$answer" != k ]]
607             do
608                printf "  >>> continue / list errors / kill palmbuild (c/l/k) ? "
609                read  answer
610                if [[ "$answer" = l ]]
[2380]611                then
[3236]612                   more ${configuration_identifier}_last_make_protocol
[2380]613                fi
[2566]614             done
615             if [[ $answer = k ]]
616             then
[2487]617                locat=user_abort; exit
[2380]618             fi
[2566]619          else
620                # ABORT ANYWAY
621             locat=user_abort; exit
[2380]622          fi
[2566]623       fi
[2380]624
[2566]625          # NOW COMPILE THE PALM CODE
626          # COMMANDS WILL BE COMMUNICATED TO SSH VIA PIPE, SINCE THIS WAY THE SYSTEM- AND
627          # USER-PROFILES OF THE SHELL ARE COMPLETELY EXECUTED (OTHERWISE, MAKE
628          # MAY E.G. MISS THE COMPILER-PATHS)
629       if [[ $silent = false ]]
630       then
[2380]631          echo " "
632          echo "  *** compile PALM sources on remote host"
[2566]633       fi
634       make_call_string="make  $make_options  PROG=$program_name  F90=$compiler_name  COPT=\"$cpp_options\"  F90FLAGS=\"$compiler_options\"  LDFLAGS=\"$linker_options\" "
[3725]635###       echo "$login_init_cmd $module_commands cd ${make_depository}; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR" | ssh  -q  $ssh_key  ${remote_username}@${remote_ip} 2>&1 | tee ${configuration_identifier}_last_make_protocol
636       ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  "$login_init_cmd $module_commands cd ${make_depository}; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR"  2>&1 | tee ${configuration_identifier}_last_make_protocol
[2380]637
[3236]638       if [[ $(grep -c MAKE_ERROR ${configuration_identifier}_last_make_protocol) != 0 ]]
[2566]639       then
[3236]640          printf "\a\n  +++ error(s) occurred during compiling or linking for host configuration \"$configuration_identifier\" "
[2566]641          if [[ $silent = false ]]
[2380]642          then
[2566]643             answer=dummy
644             printf "\n"
645             while [[ "$answer" != c  &&  "$answer" != k ]]
646             do
647                printf "  >>> continue / list errors / kill palmbuild (c/l/k) ? "
648                read  answer
649                if [[ "$answer" = l ]]
[2380]650                then
[3236]651                   more ${configuration_identifier}_last_make_protocol
[2380]652                fi
[2566]653             done
654             if [[ $answer = k ]]
655             then
[2487]656                locat=user_abort; exit
[2380]657             fi
[2566]658          else
659                # ABORT ANYWAY
660             locat=user_abort; exit
[2380]661          fi
[2566]662       fi
[2380]663
[2566]664          # TAR UPDATED VERSION ON THE REMOTE HOST
665       if [[ $silent = false ]]
666       then
[2380]667          printf "\n  *** tar update on remote host ..."
[2566]668       fi
[3534]669       ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  "cd ${make_depository}; chmod u+w *; tar -cf  ${program_name}_current_version.tar  ${program_name}  *.f90 *.o *.mod *.x"  2>&1
[2380]670
671
[2566]672       # NOW COMES THE BRANCH FOR CREATING THE EXECUTABLE FOR THE CURRENT RUN
673       # INCLUDING E.G. USER-INTERFACE ROUTINES. ALSO ADD OTHER UTILITY EXECUTABLES. EVERYTHING IS
674       # COLLECTED IN DIRECTORY SOURCES_FOR_RUN_...
[3236]675    elif [[ "$run_identifier" != "" ]]
[2566]676    then
677
678          # FIRST CHECK, IF COMPILED SOURCES FOR THIS RUN IDENTIFIER EXISTS
679          # AND ASK, IF THEY SHALL BE USED
[3534]680       ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  "[[ -d ${fast_io_catalog}/${sources_for_run_catalog} ]]  &&  echo sources for run found"  2>&1  >  ${configuration_identifier}_last_make_protocol
[3236]681       if [[ $(grep -c "sources for run found" ${configuration_identifier}_last_make_protocol) != 0  &&  $use_existing_sources_folder = true ]]
[2380]682       then
[3236]683          printf "\a\n  *** compiled sources for run \"$run_identifier\" found on remote host in folder"
[2566]684          printf "\n      ${fast_io_catalog}/${sources_for_run_catalog}"
685          printf "\n      will be used!"
686          exit
687       fi
[2380]688
[2566]689          # COPY MAKE DEPOSITORY ON REMOTE MACHINE TO SOURCES_FOR_RUN_...
690       if [[ $silent = false ]]
691       then
[3236]692          printf "\n  *** copy MAKE_DEPOSITORY_${configuration_identifier} on remote host to $sources_for_run_catalog \n"
[2566]693       fi
[4303]694       ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  "rm -rf ${fast_io_catalog}/${sources_for_run_catalog}; mkdir -p ${fast_io_catalog}/${sources_for_run_catalog}; [[ \$? != 0 ]] && exit 1; cp ${make_depository}/${program_name}_current_version.tar  ${fast_io_catalog}/${sources_for_run_catalog}; cd ${fast_io_catalog}/${sources_for_run_catalog}; tar xf ${program_name}_current_version.tar"  2>&1
695       if [[ $? != 0 ]]
696       then
697          printf "\n  +++ SOURCES_FOR_RUN catalog cannot be created."
698          printf "\n      Check setting of variable fast_io_catalog in your config file."
699          locat=temporary_working_directory
700          exit
701       fi
[2380]702
703
[2566]704          # COPY CONTENTS OF SOURCES_FOR_RUN_... TO SOURCES_FOR_RUN_... ON THE REMOTE MACHINE
705       if [[ $silent = false ]]
706       then
[2506]707          printf "\n  *** copy ${base_directory}/${sources_for_run_catalog}"
708          printf "\n      to $sources_for_run_catalog on remote host \n"
[2566]709       fi
710       scp  -q  $ssh_key  ${base_directory}/${sources_for_run_catalog}/{*,.[!.]*}  ${remote_username}@${remote_ip}:${fast_io_catalog}/${sources_for_run_catalog}
[2380]711
712
[2566]713          # CREATE EXECUTABLE FROM THE NEW/MODIFIED SOURCE FILES, IF THERE ARE ANY
714       if [[ $(ls -1 ${base_directory}/${sources_for_run_catalog}/ | grep -c .$suf) != 0 ]]
715       then
716
717          make_call_string="make  $make_options  PROG=$program_name  F90=$compiler_name  COPT=\"$cpp_options\"  F90FLAGS=\"$compiler_options\"  LDFLAGS=\"$linker_options\" "
718          [[ "$login_init_cmd" != "" ]]   &&  login_init_cmd=${login_init_cmd}";"
719          [[ "$module_commands" != "" ]]  &&  module_commands=${module_commands}";"
720          if [[ $silent = false ]]
[2380]721          then
722             echo "  *** execute \"make\" on remote host"
[2566]723          fi
[3534]724          ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  "$login_init_cmd $module_commands cd ${fast_io_catalog}/${sources_for_run_catalog}; echo $make_call_string > LAST_MAKE_CALL; chmod u+x LAST_MAKE_CALL; $make_call_string; [[ \$? != 0 ]] && echo MAKE_ERROR"  2>&1 | tee ${configuration_identifier}_last_make_protocol
[2380]725
[3236]726          if [[ $(grep -c MAKE_ERROR ${configuration_identifier}_last_make_protocol) != 0 ]]
[2566]727          then
[3236]728             printf "\a\n  +++ error(s) occurred during compiling or linking for host configuration \"$configuration_identifier\" "
[2566]729             if [[ $silent = false ]]
[2380]730             then
[2566]731                answer=dummy
732                printf "\n"
733                while [[ "$answer" != c  &&  "$answer" != k ]]
734                do
735                   printf "  >>> continue / list errors / kill palmbuild (c/l/k) ? "
736                   read  answer
737                   if [[ "$answer" = l ]]
[2380]738                   then
[3236]739                      more ${configuration_identifier}_last_make_protocol
[2380]740                   fi
[2566]741                done
742                if [[ $answer = k ]]
743                then
[3534]744                   ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  "rm -rf ${fast_io_catalog}/${sources_for_run_catalog}"  2>&1
[2487]745                   locat=user_abort; exit
[2380]746                fi
[2566]747             else
748                   # ABORT ANYWAY
[3534]749                ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  "rm -rf ${fast_io_catalog}/${sources_for_run_catalog}"  2>&1
[2566]750                locat=user_abort; exit
[2380]751             fi
[2566]752          fi
[2380]753
[2566]754       else
[2380]755
[2566]756          echo "  *** nothing to compile for this run"
[2380]757
758       fi
759
[2566]760    fi
[2380]761
[3236]762    rm -rf  ${source_path}/${configuration_identifier}_last_make_protocol
[2380]763
764
[2566]765    # MAKE ON LOCAL HOST
766 else
[2380]767
[2566]768
769       # NEXT IS THE BRANCH FOR CREATING THE MAKE_DEPOSITORY_... ON THE
770       # LOCAL HOST
[3236]771    if [[ "$run_identifier" = "" ]]
[2566]772    then
773
774          # SET THE ENVIRONMENT (EXECUTE INIT AND MODULE COMMANDS)
775       if [[ "$login_init_cmd" != "" ]]
[2380]776       then
[4081]777          eval $login_init_cmd
[2566]778       fi
[2380]779
[2566]780       if [[ "$module_commands" != "" ]]
781       then
[4809]782          eval $module_commands || {
783            printf "\n  +++ Module command(s) failed."
784            printf "\n      Check the above output of the command(s)."
785            locat=module_command_error; exit
786          }
[2566]787       fi
[2380]788
[4081]789          # next is required to evaluate environment variables or commands used in the linker option
790       eval linker_options=\"$linker_options\"
[2380]791
[2566]792          # CREATE MAKE-DEPOSITORY, IF IT DOES NOT EXIST
793       eval make_depository=$make_depository
794       if [[ ! -d $make_depository ]]
795       then
796          if  mkdir -p $make_depository
[2380]797          then
[2566]798             if [[ $silent = false ]]
[2380]799             then
800                printf "\n\n  *** directory for local make depository:"
[2404]801                printf "\n           $make_depository"
[2380]802                printf "\n      was created\n"
803             fi
[2566]804          else
805             printf "\n  +++ directory for local make depository:"
806             printf "\n           $make_depository"
807             printf "\n      cannot be created"
808             locat=local_depository; exit
[2380]809          fi
[2566]810       fi
[2380]811
[2566]812          # COPY SOURCE-CODE FROM REPOSITORY TO MAKE-DEPOSITORY
813       if [[ $silent = false ]]
814       then
[2380]815          echo " "
816          echo "  *** untar current source sources on local host in"
[2404]817          echo "      $make_depository"
[2566]818       fi
819       cd  $make_depository
820       cp  $source_path/${program_name}_sources.tar  .
821       tar xf  ${program_name}_sources.tar
[2380]822
823
[2566]824          # FIRST CREATE EXECUTABLES FOR THE UTILITY ROUTINES
825       if [[ $silent = false ]]
826       then
[2380]827          echo " "
828          echo "  *** creating utilities on local host"
[2566]829       fi
[3312]830       make  -f Makefile_utilities  $make_options  F90=$compiler_name  F90_SER=$compiler_name_ser  COPT="$cpp_options"  F90FLAGS="$compiler_options"  LDFLAGS="$linker_options" | tee ${configuration_identifier}_last_make_protocol
[2380]831
[3312]832       if [[ ${PIPESTATUS[0]} != 0 ]]
833       then
834          printf "\a\n  +++ error(s) occurred during compiling of the utilities for host configuration \"$configuration_identifier\" "
835          if [[ $silent = false ]]
836          then
837             answer=dummy
838             printf "\n"
839             while [[ "$answer" != c  &&  "$answer" != k ]]
840             do
841                printf "  >>> continue / list errors / kill palmbuild (c/l/k) ? "
842                read  answer
843                if [[ "$answer" = l ]]
844                then
845                   more ${configuration_identifier}_last_make_protocol
846                fi
847             done
848             if [[ $answer = k ]]
849             then
850                locat=user_abort; exit
851             fi
852          else
853             # ABORT ANYWAY
854             locat=user_abort; exit
855          fi
856       else
857          cp agent_preprocessing $source_path/../SCRIPTS/.
[3534]858          cp inifor $source_path/../SCRIPTS/.
[3312]859       fi
[2380]860
[3312]861
[2566]862          # CALL MAKE ON LOCAL HOST USING THE  OPTIONS DETERMINED FURTHER ABOVE
863       if [[ $silent = false ]]
864       then
[2380]865          echo " "
866          echo "  *** compile PALM sources on local host"
[2566]867       fi
[2380]868
[3236]869       make  $make_options  PROG=$program_name  F90=$compiler_name  COPT="$cpp_options"  F90FLAGS="$compiler_options"  LDFLAGS="$linker_options"  2>&1 | tee ${configuration_identifier}_last_make_protocol
[2380]870
[3312]871       if [[ ${PIPESTATUS[0]} != 0 ]]
[2566]872       then
[3236]873          printf "\a\n  +++ error(s) occurred during compiling or linking for host configuration \"$configuration_identifier\" "
[2566]874          if [[ $silent = false ]]
[2380]875          then
[2566]876             answer=dummy
877             printf "\n"
878             while [[ "$answer" != c  &&  "$answer" != k ]]
879             do
880                printf "  >>> continue / list errors / kill palmbuild (c/l/k) ? "
881                read  answer
882                if [[ "$answer" = l ]]
[2380]883                then
[3236]884                   more ${configuration_identifier}_last_make_protocol
[2380]885                fi
[2566]886             done
887             if [[ $answer = k ]]
888             then
[2487]889                locat=user_abort; exit
[2380]890             fi
[2566]891          else
892                # ABORT ANYWAY
893             locat=user_abort; exit
[2380]894          fi
[2566]895       fi
[2380]896
897
[2566]898          # TAR NEW VERSION ON LOCAL HOST
899       if [[ $silent = false ]]
900       then
[2380]901          printf "\n  *** tar update on local host ..."
[2566]902       fi
903       tar -cf  ${program_name}_current_version.tar  ${program_name} *.$suf *.o *.mod *.x
[2380]904
[2566]905    else
[2380]906
[2566]907          # NOW COMES THE BRANCH FOR CREATING THE EXECUTABLE FOR THE CURRENT RUN
908          # INCLUDING E.G. USER-INTERFACE ROUTINES. ALSO ADD OTHER UTILITY EXECUTABLES. EVERYTHING IS
909          # COLLECTED IN DIRECTORY SOURCES_FOR_RUN_...
[2380]910
[2566]911          # FIRST CHECK, IF COMPILED SOURCES FOR THIS RUN IDENTIFIER EXISTS
912          # AND ASK, IF THEY SHALL BE USED
913       if [[ -d ${fast_io_catalog}/${sources_for_run_catalog}  &&  $use_existing_sources_folder = true ]]
914       then
[3236]915          printf "\a\n  *** compiled sources for run \"$run_identifier\" found on local host in folder"
[2566]916          printf "\n      ${fast_io_catalog}/${sources_for_run_catalog}"
917          printf "\n      will be used!"
918          exit
919       fi
[2489]920
[2566]921          # SECOND CHECK, IF A DEPOSITORY EXISTS ON THE LOCAL MACHINE
922       if [[ ! -d ${make_depository} ]]
923       then
924          printf "\n  +++ directory for local make depository:"
925          printf "\n           $make_depository"
[3455]926          printf "\n      not found. Please run \"palmbuild -c $configuration_identifier\" "
[2566]927          locat=make_depository; exit
928       fi
[2380]929
930
[2566]931          # COPY MAKE DEPOSITORY ON LOCAL MACHINE TO SOURCES_FOR_RUN_...
932       if [[ $silent = false ]]
933       then
[3236]934          printf "\n  *** copy MAKE_DEPOSITORY_${configuration_identifier} on local host to "
[2506]935          printf "\n      ${fast_io_catalog}/${sources_for_run_catalog} \n"
[2566]936       fi
937       rm -rf ${fast_io_catalog}/${sources_for_run_catalog}
938       mkdir -p ${fast_io_catalog}/${sources_for_run_catalog}
[4303]939       if [[ $? != 0 ]]
940       then
941          printf "\n  +++ SOURCES_FOR_RUN catalog cannot be created."
942          printf "\n      Check setting of variable fast_io_catalog in your config file."
943          locat=execution
944          exit
945       fi
[2566]946       cp ${make_depository}/${program_name}_current_version.tar  ${fast_io_catalog}/${sources_for_run_catalog}
947       cd $fast_io_catalog/${sources_for_run_catalog}
948       tar xf ${program_name}_current_version.tar
[2380]949
950
[2566]951          # COPY CONTENTS OF SOURCES_FOR_RUN_... TO SOURCES_FOR_RUN_...
952          # IN THE FAST_IO_CATALOG ON THE LOCAL MACHINE
953       if [[ $silent = false ]]
954       then
[2506]955          printf "\n  *** copy ${base_directory}/${sources_for_run_catalog} to"
956          printf "\n      ${fast_io_catalog}/${sources_for_run_catalog} on local host \n"
[2566]957       fi
958       cp  ${base_directory}/${sources_for_run_catalog}/{*,.[!.]*}  ${fast_io_catalog}/${sources_for_run_catalog}
[2380]959
960
[2566]961          # CREATE EXECUTABLE FROM THE NEW/MODIFIED SOURCE FILES, IF THERE ARE ANY
962       if [[ $(ls -1 ${base_directory}/${sources_for_run_catalog}/ | grep -c .$suf) != 0 ]]
963       then
964
965          if [[ $silent = false ]]
[2380]966          then
967             echo "  *** execute \"make\" on local host"
[2566]968          fi
[4081]969          [[ "$login_init_cmd" != "" ]]   &&  eval $login_init_cmd
[4809]970          [[ "$module_commands" != "" ]]  &&  eval $module_commands || {
971            printf "\n  +++ Module command(s) failed."
972            printf "\n      Check the above output of the command(s)."
973            locat=module_command_error; exit
974          }
[2380]975
[4081]976             # next is required to evaluate environment variables or commands used in the linker option
977          eval linker_options=\"$linker_options\"
978
[2566]979          make  $make_options  PROG=$program_name  F90=$compiler_name  COPT="$cpp_options"  F90FLAGS="$compiler_options"  LDFLAGS="$linker_options"
[2380]980
[3312]981          if [[ ${PIPESTATUS[0]} != 0 ]]
[2566]982          then
983
[3236]984             printf "\a\n  +++ error(s) occurred during compiling or linking for host configuration \"$configuration_identifier\" "
[2566]985             if [[ $silent = false ]]
[2380]986             then
[2566]987                answer=dummy
988                printf "\n"
989                while [[ "$answer" != c  &&  "$answer" != k ]]
990                do
991                   printf "  >>> continue / kill palmbuild (c/k) ? "
992                   read  answer
993                done
994                if [[ $answer = k ]]
[2380]995                then
[2506]996                   rm -rf ${fast_io_catalog}/${sources_for_run_catalog}
[2487]997                   locat=user_abort; exit
[2380]998                fi
[2566]999             else
1000                   # ABORT ANYWAY
1001                rm -rf ${fast_io_catalog}/${sources_for_run_catalog}
1002                locat=user_abort; exit
[2380]1003             fi
[2566]1004          fi
[2380]1005
[2566]1006       else
[2380]1007
[2566]1008          echo "  *** nothing to compile for this run"
[2380]1009
[2566]1010       fi
[2380]1011
1012    fi
[2566]1013 fi
Note: See TracBrowser for help on using the repository browser.