source: palm/trunk/SCRIPTS/palmbuild @ 4855

Last change on this file since 4855 was 4843, checked in by raasch, 4 years ago

local namelist parameter added to switch off the module although the respective module namelist appears in the namelist file, further copyright updates

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