source: palm/trunk/SCRIPTS/palmbuild @ 4410

Last change on this file since 4410 was 4303, checked in by raasch, 5 years ago

Abort if temporary working catalog / SOURCES_FOR_RUN catalog cannot be created

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