source: palm/trunk/SCRIPTS/palmbuild @ 2563

Last change on this file since 2563 was 2506, checked in by raasch, 7 years ago

new options -V and -W plus other small changes in PALM scripts

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