source: palm/trunk/SCRIPTS/palmbuild @ 3045

Last change on this file since 3045 was 3033, checked in by raasch, 6 years ago

keyword correction

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