source: palm/trunk/SCRIPTS/palmbuild @ 3209

Last change on this file since 3209 was 3208, checked in by sward, 6 years ago

Renamed nav_mesh to agent_preprocessing and added it to palmbuild

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