source: palm/trunk/SCRIPTS/palmbuild @ 3222

Last change on this file since 3222 was 3210, checked in by sward, 6 years ago

Minor bugfix in agent_preprocessing

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