source: palm/trunk/SCRIPTS/palmbuild @ 2824

Last change on this file since 2824 was 2732, checked in by raasch, 7 years ago

bugfix: keyword Rev set for scrpts palmrun and palmbuild

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