source: palm/trunk/SCRIPTS/palmbuild @ 3756

Last change on this file since 3756 was 3756, checked in by suehring, 2 years ago

Disable compilation of postprocessing tool for surface output, until crashes with unexpected segmentation faults with intel compiler are solved.

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