source: palm/trunk/SCRIPTS/palmbuild @ 3299

Last change on this file since 3299 was 3236, checked in by raasch, 6 years ago

host identifier in header output renamed config. identifier, host_configuration renamed configuration_identifier, jobname renamed run_identifier, palmbuild: header output of PALM code revision, options -m, -s, and -S removed, palmrun: run_id renamed run_id_number, job_id renamed run_id, option -r renamed -i

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