source: palm/trunk/SCRIPTS/palmbuild @ 3523

Last change on this file since 3523 was 3523, checked in by suehring, 6 years ago

Implement interface for posix conform C-systemcalls in order to replace non-standard FORTRAN functions ftell and fseek

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