source: palm/trunk/SCRIPTS/palmbuild @ 3378

Last change on this file since 3378 was 3312, checked in by knoop, 6 years ago

Added proper exit code to PALM and fixed exit code handling by palmbuild and palmrun

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