source: palm/trunk/SCRIPTS/palmbuild @ 3210

Last change on this file since 3210 was 3210, checked in by sward, 6 years ago

Minor bugfix in agent_preprocessing

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