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
Line 
1#!/bin/bash
2
3# palmbuild - script for compiling the PALM code and its utility programs
4
5#------------------------------------------------------------------------------#
6# This file is part of the PALM model system.
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#
19# Copyright 2017-2020  Leibniz Universitaet Hannover
20#------------------------------------------------------------------------------#
21#
22# Current revisions:
23# ------------------
24#
25#
26# Former revisions:
27# -----------------
28# $Id: palmbuild 4809 2020-12-03 16:37:20Z gronemeier $
29# Abort if the execution of the module commands raise an error
30#
31# 4556 2020-06-08 06:29:28Z raasch
32# bugfix for determining the ssh-key givn in the configuration file
33#
34# 4481 2020-03-31 18:55:54Z maronga
35# Abort if SOURCES_FOR_RUN catalog cannot be created
36#
37# 4082 2019-07-10 14:42:00Z raasch
38# bugfix for executing module commands and for interpreting linker options
39# on local machines
40#
41# 3756 2019-02-20 11:24:32Z suehring
42# Disable compilation of postprocessing tool for surface output, until
43# crashes with unexpected segmentation faults with intel compiler are solved.
44#
45# 3725 2019-02-07 10:11:02Z raasch
46# ssh-calls for compilations on remote systems modified to avoid output
47# of login messages on specific systems changed again (reverted as before r3549)
48#
49# 3549 2018-11-21 15:44:44Z raasch
50# ssh-calls for compilations on remote systems modified to avoid output
51# of login messages on specific systems
52#
53# 3534 2018-11-19 15:35:16Z raasch
54# build of inifor added,
55# ssh-calls rearranged to avoid output of system/user-profile messages
56#
57# 3523 2018-11-13 16:09:31Z suehring
58# Enable compilation of post-processing tool for surface output - interface
59# for posix conform sytemcalls is implemented.
60#
61# 3499 2018-11-07 10:55:15Z suehring
62# Temporarily avoid compilation of post-processing tool for surface output
63# until a workaround for compiler-specific intrinsic functions is found.
64#
65# 3494 2018-11-06 14:51:27Z suehring
66# Add tool for surface-output post-processing
67#
68# 3455 2018-10-30 14:12:31Z raasch
69# options -h and -d renamed -c and -r, respectively
70#
71# 3312 2018-10-06 14:15:46Z knoop
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
77#
78# 3210 2018-08-28 07:31:13Z sward
79# Bugfix: agent_preprocessing stays in MAKE_DEPOSITORY after compilation
80#
81# 3208 2018-08-27 13:10:50Z sward
82# Added building of agent_preprocessing
83#
84# 3033 2018-05-23 15:26:19Z raasch
85# "fname" renamed to "jobname"
86#
87# 2718 2018-01-02 08:49:38Z maronga
88# Corrected "Former revisions" section
89#
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
94# informative messages switched of almost completely in silent mode
95# two header blocks merged into one
96#
97# 2506 2017-09-29 08:30:37Z raasch
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
102#
103# 2500 2017-09-25 11:10:03Z raasch
104# bugfix for r2492
105#
106# 2492 2017-09-21 14:18:48Z raasch
107# ask for compilation, if SOURCES_FOR_RUN_... exists
108#
109# 2487 2017-09-21 11:30:10Z raasch
110# bugfix: abort in case of compiling/linking errors in silent mode
111#
112# 2422 2017-09-08 08:25:41Z raasch
113# initial revision
114#
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=""
129 configuration_identifier=default
130 global_revision=""
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
140 use_existing_sources_folder=false
141 version="palmbuild  1.0  Rev$Rev: 4809 $"
142 working_directory=`pwd`
143
144
145    # ERROR HANDLING IN CASE OF EXIT
146 trap 'rm -rf  ${source_path}/${configuration_identifier}_last_make_protocol
147       if [[ $locat != normal  &&  $locat != control_c ]]
148       then
149          printf "\n\n+++ palmbuild crashed \n\n"
150          exit 1
151       elif [[ $locat != normal ]]
152       then
153          printf "\n+++ palmbuild killed by \"^C\" \n\n"
154          exit 2
155       else
156          if [[ $silent = false ]]
157          then
158            printf "\n --> palmbuild finished\n\n"
159          fi
160          exit 0
161       fi' exit
162
163
164    # ACTIONS IN CASE OF TERMINAL-BREAK (CONTROL-C):
165 trap 'locat=control_c
166       exit 1
167      ' 2
168
169
170
171    # READ SHELLSCRIPT-OPTIONS
172 while  getopts  :c:r:uvV  option
173 do
174   case  $option  in
175       (c)   configuration_identifier=$OPTARG;;
176       (r)   run_identifier=$OPTARG;;
177       (v)   silent=true;;
178       (V)   use_existing_sources_folder=true;;
179       (\?)  printf "\n  +++ unknown option $OPTARG \n";
180             locat=parameter; exit;;
181   esac
182 done
183
184
185    # BUILD THE CONFIGURATION-FILE NAME AND THE SOURCES_FOR_RUN-FOLDER NAME
186 config_file=.palm.config.$configuration_identifier
187 sources_for_run_catalog=SOURCES_FOR_RUN_${configuration_identifier}_$run_identifier
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"
196    locat=configuration; exit
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
263
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
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
295 makefile=$source_path/Makefile
296 if [[ ! -f $makefile ]]
297 then
298    printf "\n  +++ makefile: "
299    printf "\n           $makefile"
300    printf "\n      does not exist"
301    locat=makefile; exit
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
321    # DETERMINE THE SSH-OPTION IN CASE THAT AN SSH-KEY IS EXPLICITLY GIVEN IN THE
322    # CONFIG-FILE
323 if [[ "$ssh_key" != "" ]]
324 then
325    ssh_key="-i $HOME/.ssh/$ssh_key"
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
339
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
358    line=`grep %base_directory $config_file`
359    make_depository=`echo $line | cut -d" " -s -f2`/MAKE_DEPOSITORY_${configuration_identifier}
360
361 else
362
363    make_depository=${base_directory}/MAKE_DEPOSITORY_${configuration_identifier}
364
365 fi
366
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
373    # HEADER-OUTPUT (PART1: MESSAGES CONCERNING THE LOCAL HOST)
374 if [[ $silent = false ]]
375 then
376    calltime=$(date)
377    printf "\n"
378    printf "#------------------------------------------------------------------------# \n"
379    printf "| %-40s%30s | \n" "$version" "$calltime"
380    printf "| %-40s%30s | \n" "PALM code       $global_revision" " "
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" != "" ]]
387    do
388       column1=""
389       column2=$(echo $line | cut -c1-57 )
390       printf "| %-13s%-57s | \n" "$column1" "$column2"
391       line=$(echo "$line" | cut -c58-)
392    done
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"
414
415    if [[ "$remote_ip" != "" ]]
416    then
417       column2="$configuration_identifier"
418       printf "| %-20s%-50s | \n" "config. identifier:" "$column2"
419       column2=$(echo "$make_depository" | cut -c1-50 )
420       printf "| %-20s%-50s | \n" "remote depository:" "$column2"
421    else
422       column2="$configuration_identifier"
423       printf "| %-20s%-50s | \n" "config. identifier:" "$column2"
424       column2=$(echo "$make_depository" | cut -c1-50 )
425       printf "| %-20s%-50s | \n" "local depository:" "$column2"
426    fi
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
435
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
444
445    printf "| %-20s%-50s | \n" "compiler:" "$compiler_name"
446    printf "| %-20s%-50s | \n" "serial compiler:" "$compiler_name_ser"
447
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
472    column2=$(echo "$linker_options" | cut -c1-50 )
473    printf "| %-20s%-50s | \n" "linker options:" "$column2"
474    line=$(echo "$linker_options" | cut -c51-)
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
510    answer=dummy
511    printf "\n"
512    while [[ "$answer" != y  &&  "$answer" != Y  && "$answer" != s  &&  "$answer" != S  &&  "$answer" != a  &&  "$answer" != A ]]
513    do
514       printf " >>> continue (y(es)/a(bort)) ?  "
515       read  answer
516    done
517    if [[ $answer = a  ||  $answer = A ]]
518    then
519       locat=user_abort; exit
520    fi
521 fi
522
523
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  .
535 cp -p  ../UTIL/agent_preprocessing/agent_preprocessing.f90  .
536 #cp -p  ../UTIL/surface_output_processing/surface_output_to_vtk.f90  .
537 cp -p  ../UTIL/inifor/src/inifor*f90  .
538 cp -p  ../UTIL/Makefile_utilities  .
539 tar -cf  ${program_name}_sources.tar  Makefile*  *.$suf
540 rm  combine_plot_fields.f90  compare_palm_logs.f90 agent_preprocessing.f90 Makefile_utilities inifor*f90 #surface_output_to_vtk.f90
541
542
543    # MAKE ON REMOTE HOST
544 if [[ "$remote_ip" != "" ]]
545 then
546
547       # NEXT IS THE BRANCH FOR CREATING THE MAKE_DEPOSITORY_...
548    if [[ "$run_identifier" = "" ]]
549    then
550
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 ]]
554       then
555          echo " "
556          echo "  *** copying \"${program_name}_sources.tar\" to \"${remote_ip}:${make_depository}/\" "
557          ssh  -q  $ssh_key ${remote_username}@${remote_ip}  "[[ ! -d ${make_depository} ]]  &&  (echo \"  *** ${make_depository} will be created\"; mkdir -p  ${make_depository})"  2>&1
558          scp  $ssh_key ${source_path}/${program_name}_sources.tar  ${remote_username}@${remote_ip}:${make_depository}/${program_name}_sources.tar
559       else
560          ssh  -q  $ssh_key ${remote_username}@${remote_ip}  "[[ ! -d ${make_depository} ]]  &&  mkdir -p  ${make_depository}"  2>&1
561          scp  $ssh_key ${source_path}/${program_name}_sources.tar  ${remote_username}@${remote_ip}:${make_depository}/${program_name}_sources.tar  >  /dev/null
562       fi
563
564
565
566
567          # UNTAR PREVIOUS UPDATE ON REMOTE HOST, IF EXISTING
568       if [[ $silent = false ]]
569       then
570          echo "  *** untar previous update on remote host, if existing"
571       fi
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
573
574
575          # UNTAR CURRENT SOURCES ON REMOTE HOST
576       if [[ $silent = false ]]
577       then
578          echo "  *** untar current sources on remote host"
579       fi
580       ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  "cd ${make_depository}; tar -xf  ${program_name}_sources.tar"  2>&1
581
582
583          # CREATE INIT AND MODULE COAMMNDS
584       [[ "$login_init_cmd" != "" ]]   &&  login_init_cmd=${login_init_cmd}";"
585       [[ "$module_commands" != "" ]]  &&  module_commands=${module_commands}";"
586
587
588          # FIRST CREATE EXECUTABLES FOR THE UTILITY ROUTINES
589       if [[ $silent = false ]]
590       then
591          echo " "
592          echo "  *** creating utilities on remote host"
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\" "
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
597
598       if [[ $(grep -c MAKE_ERROR ${configuration_identifier}_last_make_protocol) != 0 ]]
599       then
600          printf "\a\n  +++ error(s) occurred during compiling or linking of utilities"
601          printf "\n      for host configuration \"$configuration_identifier\" "
602          if [[ $silent = false ]]
603          then
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 ]]
611                then
612                   more ${configuration_identifier}_last_make_protocol
613                fi
614             done
615             if [[ $answer = k ]]
616             then
617                locat=user_abort; exit
618             fi
619          else
620                # ABORT ANYWAY
621             locat=user_abort; exit
622          fi
623       fi
624
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
631          echo " "
632          echo "  *** compile PALM sources on remote host"
633       fi
634       make_call_string="make  $make_options  PROG=$program_name  F90=$compiler_name  COPT=\"$cpp_options\"  F90FLAGS=\"$compiler_options\"  LDFLAGS=\"$linker_options\" "
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
637
638       if [[ $(grep -c MAKE_ERROR ${configuration_identifier}_last_make_protocol) != 0 ]]
639       then
640          printf "\a\n  +++ error(s) occurred during compiling or linking for host configuration \"$configuration_identifier\" "
641          if [[ $silent = false ]]
642          then
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 ]]
650                then
651                   more ${configuration_identifier}_last_make_protocol
652                fi
653             done
654             if [[ $answer = k ]]
655             then
656                locat=user_abort; exit
657             fi
658          else
659                # ABORT ANYWAY
660             locat=user_abort; exit
661          fi
662       fi
663
664          # TAR UPDATED VERSION ON THE REMOTE HOST
665       if [[ $silent = false ]]
666       then
667          printf "\n  *** tar update on remote host ..."
668       fi
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
670
671
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_...
675    elif [[ "$run_identifier" != "" ]]
676    then
677
678          # FIRST CHECK, IF COMPILED SOURCES FOR THIS RUN IDENTIFIER EXISTS
679          # AND ASK, IF THEY SHALL BE USED
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
681       if [[ $(grep -c "sources for run found" ${configuration_identifier}_last_make_protocol) != 0  &&  $use_existing_sources_folder = true ]]
682       then
683          printf "\a\n  *** compiled sources for run \"$run_identifier\" found on remote host in folder"
684          printf "\n      ${fast_io_catalog}/${sources_for_run_catalog}"
685          printf "\n      will be used!"
686          exit
687       fi
688
689          # COPY MAKE DEPOSITORY ON REMOTE MACHINE TO SOURCES_FOR_RUN_...
690       if [[ $silent = false ]]
691       then
692          printf "\n  *** copy MAKE_DEPOSITORY_${configuration_identifier} on remote host to $sources_for_run_catalog \n"
693       fi
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
702
703
704          # COPY CONTENTS OF SOURCES_FOR_RUN_... TO SOURCES_FOR_RUN_... ON THE REMOTE MACHINE
705       if [[ $silent = false ]]
706       then
707          printf "\n  *** copy ${base_directory}/${sources_for_run_catalog}"
708          printf "\n      to $sources_for_run_catalog on remote host \n"
709       fi
710       scp  -q  $ssh_key  ${base_directory}/${sources_for_run_catalog}/{*,.[!.]*}  ${remote_username}@${remote_ip}:${fast_io_catalog}/${sources_for_run_catalog}
711
712
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 ]]
721          then
722             echo "  *** execute \"make\" on remote host"
723          fi
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
725
726          if [[ $(grep -c MAKE_ERROR ${configuration_identifier}_last_make_protocol) != 0 ]]
727          then
728             printf "\a\n  +++ error(s) occurred during compiling or linking for host configuration \"$configuration_identifier\" "
729             if [[ $silent = false ]]
730             then
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 ]]
738                   then
739                      more ${configuration_identifier}_last_make_protocol
740                   fi
741                done
742                if [[ $answer = k ]]
743                then
744                   ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  "rm -rf ${fast_io_catalog}/${sources_for_run_catalog}"  2>&1
745                   locat=user_abort; exit
746                fi
747             else
748                   # ABORT ANYWAY
749                ssh  -q  $ssh_key  ${remote_username}@${remote_ip}  "rm -rf ${fast_io_catalog}/${sources_for_run_catalog}"  2>&1
750                locat=user_abort; exit
751             fi
752          fi
753
754       else
755
756          echo "  *** nothing to compile for this run"
757
758       fi
759
760    fi
761
762    rm -rf  ${source_path}/${configuration_identifier}_last_make_protocol
763
764
765    # MAKE ON LOCAL HOST
766 else
767
768
769       # NEXT IS THE BRANCH FOR CREATING THE MAKE_DEPOSITORY_... ON THE
770       # LOCAL HOST
771    if [[ "$run_identifier" = "" ]]
772    then
773
774          # SET THE ENVIRONMENT (EXECUTE INIT AND MODULE COMMANDS)
775       if [[ "$login_init_cmd" != "" ]]
776       then
777          eval $login_init_cmd
778       fi
779
780       if [[ "$module_commands" != "" ]]
781       then
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          }
787       fi
788
789          # next is required to evaluate environment variables or commands used in the linker option
790       eval linker_options=\"$linker_options\"
791
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
797          then
798             if [[ $silent = false ]]
799             then
800                printf "\n\n  *** directory for local make depository:"
801                printf "\n           $make_depository"
802                printf "\n      was created\n"
803             fi
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
809          fi
810       fi
811
812          # COPY SOURCE-CODE FROM REPOSITORY TO MAKE-DEPOSITORY
813       if [[ $silent = false ]]
814       then
815          echo " "
816          echo "  *** untar current source sources on local host in"
817          echo "      $make_depository"
818       fi
819       cd  $make_depository
820       cp  $source_path/${program_name}_sources.tar  .
821       tar xf  ${program_name}_sources.tar
822
823
824          # FIRST CREATE EXECUTABLES FOR THE UTILITY ROUTINES
825       if [[ $silent = false ]]
826       then
827          echo " "
828          echo "  *** creating utilities on local host"
829       fi
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
831
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/.
858          cp inifor $source_path/../SCRIPTS/.
859       fi
860
861
862          # CALL MAKE ON LOCAL HOST USING THE  OPTIONS DETERMINED FURTHER ABOVE
863       if [[ $silent = false ]]
864       then
865          echo " "
866          echo "  *** compile PALM sources on local host"
867       fi
868
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
870
871       if [[ ${PIPESTATUS[0]} != 0 ]]
872       then
873          printf "\a\n  +++ error(s) occurred during compiling or linking for host configuration \"$configuration_identifier\" "
874          if [[ $silent = false ]]
875          then
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 ]]
883                then
884                   more ${configuration_identifier}_last_make_protocol
885                fi
886             done
887             if [[ $answer = k ]]
888             then
889                locat=user_abort; exit
890             fi
891          else
892                # ABORT ANYWAY
893             locat=user_abort; exit
894          fi
895       fi
896
897
898          # TAR NEW VERSION ON LOCAL HOST
899       if [[ $silent = false ]]
900       then
901          printf "\n  *** tar update on local host ..."
902       fi
903       tar -cf  ${program_name}_current_version.tar  ${program_name} *.$suf *.o *.mod *.x
904
905    else
906
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_...
910
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
915          printf "\a\n  *** compiled sources for run \"$run_identifier\" found on local host in folder"
916          printf "\n      ${fast_io_catalog}/${sources_for_run_catalog}"
917          printf "\n      will be used!"
918          exit
919       fi
920
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"
926          printf "\n      not found. Please run \"palmbuild -c $configuration_identifier\" "
927          locat=make_depository; exit
928       fi
929
930
931          # COPY MAKE DEPOSITORY ON LOCAL MACHINE TO SOURCES_FOR_RUN_...
932       if [[ $silent = false ]]
933       then
934          printf "\n  *** copy MAKE_DEPOSITORY_${configuration_identifier} on local host to "
935          printf "\n      ${fast_io_catalog}/${sources_for_run_catalog} \n"
936       fi
937       rm -rf ${fast_io_catalog}/${sources_for_run_catalog}
938       mkdir -p ${fast_io_catalog}/${sources_for_run_catalog}
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
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
949
950
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
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"
957       fi
958       cp  ${base_directory}/${sources_for_run_catalog}/{*,.[!.]*}  ${fast_io_catalog}/${sources_for_run_catalog}
959
960
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 ]]
966          then
967             echo "  *** execute \"make\" on local host"
968          fi
969          [[ "$login_init_cmd" != "" ]]   &&  eval $login_init_cmd
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          }
975
976             # next is required to evaluate environment variables or commands used in the linker option
977          eval linker_options=\"$linker_options\"
978
979          make  $make_options  PROG=$program_name  F90=$compiler_name  COPT="$cpp_options"  F90FLAGS="$compiler_options"  LDFLAGS="$linker_options"
980
981          if [[ ${PIPESTATUS[0]} != 0 ]]
982          then
983
984             printf "\a\n  +++ error(s) occurred during compiling or linking for host configuration \"$configuration_identifier\" "
985             if [[ $silent = false ]]
986             then
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 ]]
995                then
996                   rm -rf ${fast_io_catalog}/${sources_for_run_catalog}
997                   locat=user_abort; exit
998                fi
999             else
1000                   # ABORT ANYWAY
1001                rm -rf ${fast_io_catalog}/${sources_for_run_catalog}
1002                locat=user_abort; exit
1003             fi
1004          fi
1005
1006       else
1007
1008          echo "  *** nothing to compile for this run"
1009
1010       fi
1011
1012    fi
1013 fi
Note: See TracBrowser for help on using the repository browser.