source: palm/trunk/SCRIPTS/palmbuild @ 4150

Last change on this file since 4150 was 4082, checked in by raasch, 5 years ago

bugfix for last commit

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