source: palm/trunk/SCRIPTS/palmbuild @ 3740

Last change on this file since 3740 was 3725, checked in by raasch, 5 years ago

modifications to avoid compiler warnings about unused variables, temperton-fft: GOTO statements replaced, file re-formatted corresponding to coding standards, ssh-calls for compilations on remote systems modified to avoid output of login messages on specific systems changed again (palmbuild, reverted as before r3549), error messages for failed restarts extended (palmrun)

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