/[MITgcm]/MITgcm/tools/genmake2
ViewVC logotype

Contents of /MITgcm/tools/genmake2

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.250 - (show annotations) (download)
Fri Apr 5 21:10:55 2013 UTC (10 years, 11 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint64i, checkpoint64h, checkpoint64j, checkpoint64g
Changes since 1.249: +31 -17 lines
change default makedepend from the system default to tools/xmakedepend:
When no makedepend is specified, select tools/xmakedepend it the test pass,
 otherwise select the system default (if exist and pass the test) or
 try to build cyrus-makedepend ; stop if none of the 3 works.

1 #! /usr/bin/env bash
2 #
3 # $Header: /u/gcmpack/MITgcm/tools/genmake2,v 1.249 2013/02/23 04:24:42 utke Exp $
4 # $Name: $
5 #
6 # Makefile generator for MITgcm UV codes
7 # created by cnh 03/98
8 # adapted by aja 06/98
9 # modified by aja 01/00
10 # rewritten in bash by eh3 08/03
11
12 # Explain usage
13 usage() {
14 cat <<EOF
15
16 Usage: "$0" [OPTIONS]
17 where [OPTIONS] can be:
18
19 -help | --help | -h | --h
20 Print this help message and exit.
21
22 -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
23 -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
24 Use "NAME" as the adoptfile. By default, the file at
25 "tools/adjoint_options/adjoint_default" will be used.
26
27 -nooptfile | --nooptfile
28 -optfile NAME | --optfile NAME | -of NAME | --of NAME
29 -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
30 Use "NAME" as the optfile. By default, an attempt will be
31 made to find an appropriate "standard" optfile in the
32 tools/build_options/ directory.
33
34 -pdepend NAME | --pdepend NAME
35 -pdepend=NAME | --pdepend=NAME
36 Get package dependency information from "NAME".
37
38 -pgroups NAME | --pgroups NAME
39 -pgroups=NAME | --pgroups=NAME
40 Get the package groups information from "NAME".
41
42 -bash NAME
43 Explicitly specify the Bourne or BASH shell to use
44
45 -make NAME | -m NAME
46 --make=NAME | -m=NAME
47 Use "NAME" for the MAKE program. The default is "make" but
48 many platforms, "gmake" is the preferred choice.
49
50 -makefile NAME | -mf NAME
51 --makefile=NAME | -mf=NAME
52 Call the makefile "NAME". The default is "Makefile".
53
54 -makedepend NAME | -md NAME
55 --makedepend=NAME | -md=NAME
56 Use "NAME" for the MAKEDEPEND program.
57
58 -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
59 -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
60 Specify the location of the MITgcm ROOTDIR as "NAME".
61 By default, genamke will try to find the location by
62 looking in parent directories (up to the 5th parent).
63
64 -mods NAME | --mods NAME | -mo NAME | --mo NAME
65 -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
66 Here, "NAME" specifies a list of directories that are
67 used for additional source code. Files found in the
68 "mods list" are given preference over files of the same
69 name found elsewhere.
70
71 -disable NAME | --disable NAME
72 -disable=NAME | --disable=NAME
73 Here "NAME" specifies a list of packages that we don't
74 want to use. If this violates package dependencies,
75 genamke will exit with an error message.
76
77 -enable NAME | --enable NAME
78 -enable=NAME | --enable=NAME
79 Here "NAME" specifies a list of packages that we wish
80 to specifically enable. If this violates package
81 dependencies, genamke will exit with an error message.
82
83 -standarddirs NAME | --standarddirs NAME
84 -standarddirs=NAME | --standarddirs=NAME
85 Here, "NAME" specifies a list of directories to be
86 used as the "standard" code.
87
88 -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
89 -fc=NAME | --fc=NAME
90 Use "NAME" as the fortran compiler. By default, genmake
91 will search for a working compiler by trying a list of
92 "usual suspects" such as g77, f77, etc.
93
94 -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
95 Use "NAME" as the C compiler. By default, genmake
96 will search for a working compiler by trying a list of
97 "usual suspects" such as gcc, c89, cc, etc.
98
99 -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4
100 Use "real*4" type for _RS variable (#undef REAL4_IS_SLOW)
101 *only* works if CPP_EEOPTIONS.h allows this.
102
103 -ignoretime | -ignore_time | --ignoretime | --ignore_time
104 Ignore all the "wall clock" routines entirely. This will
105 not in any way hurt the model results -- it simply means
106 that the code that checks how long the model spends in
107 various routines will give junk values.
108
109 -ts | --ts
110 Produce timing information per timestep
111 -papis | --papis
112 Produce summary MFlop/s (and IPC) with PAPI per timestep
113 -pcls | --pcls
114 Produce summary MFlop/s etc. with PCL per timestep
115 -foolad | --foolad
116 Fool the AD code generator
117 -papi | --papi
118 Performance analysis with PAPI
119 -pcl | --pcl
120 Performance analysis with PCL
121 -hpmt | --hpmt
122 Performance analysis with the HPM Toolkit
123
124 -ieee | --ieee
125 use IEEE numerics. Note that this option *only* works
126 if it is supported by the OPTFILE that is being used.
127 -devel | --devel
128 Add additional warning and debugging flags for development
129 (if supported by the OPTFILE); also switch to IEEE numerics.
130 -gsl | --gsl
131 Use GSL to control floating point rounding and precision
132
133 -mpi | --mpi
134 Include MPI header files and link to MPI libraries
135 -mpi=PATH | --mpi=PATH
136 Include MPI header files and link to MPI libraries using MPI_ROOT
137 set to PATH. i.e. Include files from \$PATH/include, link to libraries
138 from \$PATH/lib and use binaries from \$PATH/bin.
139
140 -omp | --omp
141 Activate OpenMP code + use Compiler option OMPFLAG
142 -omp=OMPFLAG | --omp=OMPFLAG
143 Activate OpenMP code + use Compiler option OMPFLAG
144
145 -es | --es | -embed-source | --embed-source
146 Embed a tarball containing the full source code
147 (including the Makefile, etc.) used to build the
148 executable [off by default]
149
150 -ds | --ds
151 Report genmake internal variables status (DUMPSTATE)
152 to file "genmake_state" (for debug purpose)
153
154 While it is most often a single word, the "NAME" variables specified
155 above can in many cases be a space-delimited string such as:
156
157 --enable pkg1 --enable 'pkg1 pkg2' --enable 'pkg1 pkg2 pkg3'
158 -mods=dir1 -mods='dir1' -mods='dir1 dir2 dir3'
159 -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
160
161 which, depending upon your shell, may need to be single-quoted.
162
163 For more detailed genmake documentation, please see:
164
165 http://mitgcm.org/public/devel_HOWTO/
166
167 EOF
168
169 exit 1
170 }
171
172 # Search for particular CPP #cmds associated with packages
173 # usage: test_for_package_in_cpp_options CPP_file package_name
174 test_for_package_in_cpp_options() {
175 cpp_options=$1
176 pkg=$2
177 test_for_string_in_file $cpp_options "^ *# *define *\<ALLOW_$pkg\>"
178 test_for_string_in_file $cpp_options "^ *# *undef *\<ALLOW_$pkg\>"
179 test_for_string_in_file $cpp_options "^ *# *define *\<DISABLE_$pkg\>"
180 test_for_string_in_file $cpp_options "^ *# *undef *\<DISABLE_$pkg\>"
181 }
182
183 # Search for particular CPP #cmds associated with MPI
184 # usage: test_for_mpi_in_cpp_eeoptions CPP_file
185 test_for_mpi_in_cpp_eeoptions() {
186 cpp_options=$1
187 test_for_string_in_file $cpp_options "^ *# *define *\<ALLOW_USE_MPI\>"
188 test_for_string_in_file $cpp_options "^ *# *undef *\<ALLOW_USE_MPI\>"
189 }
190
191 # Search for particular string in a file. Return 1 if detected, 0 if not
192 # usage: test_for_string_in_file file string
193 test_for_string_in_file() {
194 file=$1
195 strng=$2
196 grep "$strng" $file > /dev/null 2>&1
197 RETVAL=$?
198 if test "x${RETVAL}" = x0 ; then
199 printf "Error: In $file there is an illegal line: "
200 grep -i "$strng" $file
201 exit 99
202 fi
203 return 0
204 }
205
206 # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to
207 # the package list.
208 expand_pkg_groups() {
209 new_packages=
210 if test -r $PKG_GROUPS ; then
211 cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp
212 cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp
213 matched=0
214 for i in $PACKAGES ; do
215 line=`grep "^ *$i" ./p2.tmp`
216 RETVAL=$?
217 if test "x$RETVAL" = x0 ; then
218 matched=1
219 replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`
220 echo " replacing \"$i\" with:$replace"
221 new_packages="$new_packages $replace"
222 else
223 new_packages="$new_packages $i"
224 fi
225 done
226 PACKAGES=$new_packages
227 rm -f ./p[1,2].tmp
228 return $matched
229 else
230 echo "Warning: can't read package groups definition file: $PKG_GROUPS"
231 fi
232 }
233
234 # Check for broken environments (eg. cygwin, MacOSX w/HFS+) that
235 # cannot distinguish [*.F/*.F90] from [*.f/*.f90] files.
236 check_for_broken_Ff() {
237 # Do we have defaults for $FS and/or $FS90 ?
238 tfs=f
239 tfs9=f90
240 if test "x$FS" != x ; then
241 tfs="$FS"
242 fi
243 if test "x$FS90" != x ; then
244 tfs9="$FS90"
245 fi
246
247 # First check the ability to create a *.F/.f pair.
248 cat <<EOF >> genmake_hello.F
249 program hello
250 write(*,*) 'hi'
251 stop
252 end
253 EOF
254 cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1
255 RETVAL=$?
256 if test "x$RETVAL" != x0 ; then
257 if test "x$FS" = x ; then
258 FS='for'
259 FS90='fr9'
260 check_for_broken_Ff
261 else
262 cat <<EOF 2>&1
263 ERROR: Your file system cannot distinguish between *.F and *.f files
264 (fails the "cp" test) and this program cannot find a suitable
265 replacement extension. Please try a different build environment or
266 contact the <MITgcm-support@mitgcm.org> list for help.
267
268 EOF
269 exit -1
270 fi
271 return
272 fi
273 rm -f genmake_hello.*
274
275 # Check the ability of ${MAKE} and ${LN} to use the current set
276 # of extensions.
277 cat <<EOF >> genmake_hello.F
278 program hello
279 write(*,*) 'hi'
280 stop
281 end
282 EOF
283 test -f $MAKEFILE && mv -f $MAKEFILE $MAKEFILE".tst"
284 cat <<EOF >> $MAKEFILE
285 .SUFFIXES:
286 .SUFFIXES: .$tfs .F
287 .F.$tfs:
288 $LN \$< \$@
289 EOF
290 $MAKE -f $MAKEFILE "genmake_hello."$tfs > /dev/null 2>&1
291 RETVAL=$?
292 if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then
293 if test "x$FS" = x ; then
294 FS='for'
295 FS90='fr9'
296 check_for_broken_Ff
297 else
298 echo "ERROR: test: '$MAKE -f $MAKEFILE genmake_hello.$tfs' Failed"
299 echo " see simple makefile: '$MAKEFILE' (left here)"
300 echo " Please check (1) your '$MAKE' command, (2) your '$LN' command"
301 echo " and (3) the allowed sufix '.F' and '.$tfs' in makefile"
302 echo " or contact the <MITgcm-support@mitgcm.org> list for help."
303 echo ""
304 exit -1
305 return
306 fi
307 fi
308 rm -f genmake_hello.* $MAKEFILE
309 test -f $MAKEFILE".tst" && mv -f $MAKEFILE".tst" $MAKEFILE
310
311 # If we make it here, use the extensions
312 FS=$tfs
313 FS90=$tfs9
314 return
315 }
316
317 look_for_makedepend() {
318
319 # The "original" makedepend is part of the Imake system that is
320 # most often distributed with XFree86 or with an XFree86 source
321 # package. As a result, many machines (eg. generic Linux) do not
322 # have a system-default "makedepend" available. For those
323 # systems, we have two fall-back options:
324 #
325 # 1) a makedepend implementation shipped with the cyrus-imapd
326 # package: ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
327 # 2) a local tools/xmakedepend shell script
328 #
329 # So the choices are, in order:
330 # 1) use the user-specified program
331 # 2) use the local xmakedepend script (get all dependencies, but slower)
332 # 3) use a system-wide default
333 # 4) locally build and use the cyrus makedepend
334 # (faster, but can miss some dependencies)
335 #
336 echo >> $LOGFILE
337 echo "running: look_for_makedepend()" >> $LOGFILE
338 if test "x${MAKEDEPEND}" != x ; then
339 echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1
340 RETVAL=$?
341 if test x"$RETVAL" = x0 ; then
342 build_cyrus_makedepend
343 RETVAL=$?
344 if test "x$RETVAL" != x0 ; then
345 echo "WARNING: unable to build cyrus-makedepend. Try other 'makedepend'"
346 MAKEDEPEND=
347 fi
348 else
349 echo "${MAKEDEPEND}" | grep 'tools.xmakedepend' > /dev/null 2>&1
350 RETVAL=$?
351 if test "x$RETVAL" = x0 ; then
352 MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
353 fi
354 echo " --> MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
355 fi
356 fi
357 if test "x${MAKEDEPEND}" = x ; then
358 test -f $MAKEFILE && mv -f $MAKEFILE $MAKEFILE".tst"
359 # echo 'MAKEFILE="'$MAKEFILE'"'
360 cat <<EOF >> $MAKEFILE
361 # THIS IS A TEST MAKEFILE GENERATED BY "genmake2"
362 #
363 # Some "makedepend" implementations will die if they cannot
364 # find a Makefile -- so this file is here to gives them an
365 # empty one to find and parse.
366 EOF
367 cat <<EOF >> genmake_tc.f
368 program test
369 write(*,*) 'test'
370 stop
371 end
372 EOF
373 $ROOTDIR/tools/xmakedepend -f $MAKEFILE genmake_tc.f > /dev/null 2>&1
374 RV1=$?
375 which makedepend > /dev/null 2>&1
376 RV2=$?
377 if test "x${RV2}" = x0 ; then
378 makedepend -f $MAKEFILE genmake_tc.f > /dev/null 2>&1
379 RV3=$? ; loc_msg='not working.'
380 else RV3=$RV2 ; loc_msg='not found.'
381 fi
382 test -f $MAKEFILE && rm -f $MAKEFILE
383 test -f $MAKEFILE".tst" && mv -f $MAKEFILE".tst" $MAKEFILE
384 echo " check makedepend (local: $RV1, system: $RV2, $RV3)"
385 if test "x${RV1}" = x0 ; then
386 MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
387 echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
388 elif test "x${RV3}" = x0 ; then
389 echo " local tools/xmakedepend not working. Use system-default makedepend"
390 MAKEDEPEND=makedepend
391 echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
392 else
393 echo " local tools/xmakedepend not working; system-default makedepend $loc_msg"
394 echo -n " Try to build cyrus-makedepend ..."
395 # Try to build the cyrus implementation
396 build_cyrus_makedepend
397 RETVAL=$?
398 if test "x$RETVAL" = x0 ; then
399 echo " Works"
400 else
401 echo " Fails" ; echo "" >> $LOGFILE
402 echo "ERROR: no working makedepend found ; look_for_makedepend FAILED" | tee -a $LOGFILE
403 echo ""
404 exit -1
405 return
406 fi
407 fi
408 fi
409 }
410
411 build_cyrus_makedepend() {
412 echo >> $LOGFILE
413 echo "running: build_cyrus_makedepend()" >> $LOGFILE
414 rm -f ./genmake_cy_md
415 (
416 cd $ROOTDIR/tools/cyrus-imapd-makedepend \
417 && ./configure > /dev/null 2>&1 \
418 && $MAKE > /dev/null 2>&1
419 if test -x ./makedepend.exe ; then
420 $LN ./makedepend.exe ./makedepend
421 fi
422 ./makedepend ifparser.c > /dev/null 2>&1 \
423 && echo "true"
424 ) > ./genmake_cy_md
425 grep true ./genmake_cy_md > /dev/null 2>&1
426 RETVAL=$?
427 rm -f ./genmake_cy_md
428 if test "x$RETVAL" = x0 ; then
429 MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
430 echo " --> set MAKEDEPEND=${MAKEDEPEND}" >> $LOGFILE
431 return 0
432 else
433 echo "WARNING: fail to build cyrus-imapd-makedepend" >> $LOGFILE
434 return 1
435 fi
436 }
437
438 build_embed_encode()
439 {
440 printf " building the embed-encode utility... "
441 if test ! -e "$ROOTDIR/tools/embed_encode/encode_files" ; then
442 if test ! -d "$ROOTDIR/tools/embed_encode" ; then
443 echo
444 echo " Error: can't locate \"$ROOTDIR/tools/embed_encode\""
445 echo
446 EMBED_SRC=f
447 return 1
448 fi
449 clist="cc gcc c89 $CC"
450 for ic in $clist ; do
451 comm="$ic -o encode_files encode_files.c"
452 ( cd $ROOTDIR/tools/embed_encode && $comm ) > /dev/null 2>&1
453 RETVAL=$?
454 if test "x$RETVAL" = x0 ; then
455 echo "OK"
456 return 0
457 fi
458 done
459 echo
460 echo " Error: unable to build $ROOTDIR/embed_encode/encode_files"
461 echo " so it has been disabled"
462 echo
463 EMBED_SRC=f
464 return 1
465 fi
466 echo "OK"
467 }
468
469 # look for possible C compilers
470 look_for_C_compilers() {
471 echo >> $LOGFILE
472 echo "running: look_for_C_compilers()" >> $LOGFILE
473 rm -f ./genmake_hello.c ./genmake_hello
474 cat >> genmake_hello.c << EOF
475 #include <stdio.h>
476 int main(int argc, char **argv) {
477 printf("Hello!\n");
478 return 0;
479 }
480 EOF
481 tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc icc"
482 p_CC=
483 for c in $tmp ; do
484 COMM="$c $CFLAGS -o genmake_hello genmake_hello.c"
485 echo $COMM >> $LOGFILE
486 $COMM >> $LOGFILE 2>&1
487 RETVAL=$?
488 if test "x${RETVAL}" = x0 ; then
489 echo " $c test successful" >> $LOGFILE
490 p_CC="$p_CC $c"
491 fi
492 done
493 rm -f ./genmake_hello.c ./genmake_hello
494 if test "x${p_CC}" = x ; then
495 cat 1>&2 <<EOF
496
497 Error: No C compilers were found in your path. Please specify one using:
498
499 1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
500 2) the CC or MITGCM_CC environment variables.
501
502 EOF
503 exit 1
504 else
505 echo " The possible C compilers found in your path are: $p_CC" | tee -a $LOGFILE
506 if test "x$CC" = x ; then
507 CC=`echo $p_CC | $AWK '{print $1}'`
508 echo " Setting C compiler to: "$CC
509 fi
510 fi
511 echo " --> set CC='$CC'" >> $LOGFILE
512 }
513
514 # Guess possible config options for this host
515 find_possible_optfile() {
516
517 echo >> $LOGFILE
518 echo "running: find_possible_optfile()" >> $LOGFILE
519 tmp1=`uname`"_"`uname -m`
520 tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
521 tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
522 tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
523 tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
524 tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
525 PLATFORM=$tmp3
526 echo $PLATFORM | grep cygwin > /dev/null 2>&1 && PLATFORM=cygwin_ia32
527 OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
528 echo " The platform appears to be: $PLATFORM" | tee -a $LOGFILE
529
530 #================================================================
531 # look for possible FORTRAN compilers
532 echo " look for possible FORTRAN compilers" >> $LOGFILE
533 tmp="$MITGCM_FC $FC efc gfortran g77 f77 pgf77 pgf95 ifc ifort f90 f95 mpif77 mpf77 mpxlf95 g95"
534 p_FC=
535 rm -f ./genmake_hello.f
536 cat >> genmake_hello.f <<EOF
537 program hello
538 do i=1,3
539 print *, 'hello world : ', i
540 enddo
541 end
542 EOF
543 for f in $tmp ; do
544 COMM="$f -o genmake_hello genmake_hello.f"
545 echo $COMM >> $LOGFILE
546 $COMM >> $LOGFILE 2>&1
547 RETVAL=$?
548 if test "x${RETVAL}" = x0 ; then
549 echo " $f test successful" >> $LOGFILE
550 p_FC="$p_FC $f"
551 fi
552 done
553 rm -f ./genmake_hello.f ./genmake_hello
554 if test "x${p_FC}" = x ; then
555 cat 1>&2 <<EOF
556
557 Error: No Fortran compilers were found in your path. Please specify one using:
558
559 1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
560 2) a command-line option (eg. "-fc NAME"), or
561 3) the FC or MITGCM_FC environment variables.
562
563 EOF
564 exit 1
565 else
566 echo " The possible FORTRAN compilers found in your path are: $p_FC" | tee -a $LOGFILE
567 fi
568
569 # Use the first of the compilers found in the current PATH
570 # that has a correctly-named optfile
571 if test "x$OPTFILE" = x -a "x$FC" = x ; then
572 for i in $p_FC ; do
573 OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
574 if test -r $OPTFILE ; then
575 echo " Setting OPTFILE to: "$OPTFILE | tee -a $LOGFILE
576 break
577 fi
578 done
579 fi
580
581 if test "x$OPTFILE" = x ; then
582 OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
583 if test ! -r $OPTFILE ; then
584 echo " I looked for the file "$OPTFILE" but did not find it"
585 fi
586 fi
587
588 if test "x$OPTFILE" = x ; then
589 cat 1>&2 <<EOF
590
591 Error: No options file was found in: $ROOTDIR/tools/build_options/
592 that matches this platform ("$PLATFORM") and the compilers found in
593 your path. Please specify an "optfile" using:
594
595 1) the command line (eg. "-optfile=path/to/OPTFILE"), or
596 2) the MITGCM_OF environment variable.
597
598 If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
599
600 EOF
601 exit 1
602 fi
603 }
604
605 # Parse the package dependency information
606 get_pdepend_list() {
607
608 # strip the comments and then convert the dependency file into
609 # two arrays: PNAME, DNAME
610 cat $1 | sed -e 's/#.*$//g' \
611 | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
612 > ./.pd_tmp
613 RETVAL=$?
614 if test ! "x${RETVAL}" = x0 ; then
615 echo "Error: unable to parse package dependencies -- please check PKG_DEPEND=\"$1\""
616 exit 1
617 fi
618 . ./.pd_tmp
619 rm -f ./.pd_tmp
620 }
621
622 # Build a CPP macro to automate calling C routines from FORTRAN
623 get_fortran_c_namemangling() {
624
625 #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
626 if test ! "x$FC_NAMEMANGLE" = x ; then
627 return 0
628 fi
629 echo " running: get_fortran_c_namemangling()" >> $LOGFILE
630
631 default_nm="#define FC_NAMEMANGLE(X) X ## _"
632
633 cat > genmake_test.c <<EOF
634 void tcall( char * string ) { tsub( string ); }
635 EOF
636 COMM="$CC $CFLAGS -c genmake_test.c"
637 echo ' '$COMM >> $LOGFILE
638 $COMM >> $LOGFILE 2>&1
639 RETVAL=$?
640 if test "x$RETVAL" != x0 ; then
641 FC_NAMEMANGLE=$default_nm
642 cat <<EOF>> $LOGFILE
643
644 WARNING: C test compile fails
645 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
646 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
647 EOF
648 return 1
649 fi
650 c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
651 RETVAL=$?
652 if test "x$RETVAL" != x0 ; then
653 FC_NAMEMANGLE=$default_nm
654 cat <<EOF>> $LOGFILE
655
656 WARNING: The "nm" command failed.
657 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
658 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
659 EOF
660 return 1
661 fi
662 cat > genmake_tcomp.$FS <<EOF
663 subroutine tcall( string )
664 character*(*) string
665 call tsub( string )
666 end
667 EOF
668 COMM="$FC $FFLAGS -c genmake_tcomp.$FS"
669 echo ' '$COMM >> $LOGFILE
670 $COMM >> $LOGFILE 2>&1
671 RETVAL=$?
672 if test "x$RETVAL" != x0 ; then
673 FC_NAMEMANGLE=$default_nm
674 cat <<EOF>> $LOGFILE
675
676 WARNING: FORTRAN test compile fails -- please see '$LOGFILE'
677 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
678 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
679 EOF
680 return 1
681 fi
682 f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
683 RETVAL=$?
684 if test "x$RETVAL" != x0 ; then
685 FC_NAMEMANGLE=$default_nm
686 cat <<EOF>> $LOGFILE
687
688 WARNING: The "nm" command failed.
689 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
690 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
691 EOF
692 return 1
693 fi
694
695 c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
696 f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
697 c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
698 f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
699
700 nmangle="X"
701 if test "x$c_a" != "x$f_a" ; then
702 comm="echo x$f_a | sed -e 's|x$c_a||'"
703 a=`eval $comm`
704 nmangle="$a ## $nmangle"
705 fi
706 if test "x$c_b" != "x$f_b" ; then
707 comm="echo x$f_b | sed -e 's|x$c_b||'"
708 b=`eval $comm`
709 nmangle="$nmangle ## $b"
710 fi
711
712 FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) $nmangle"
713
714 # cleanup the testing files
715 rm -f genmake_tcomp.* genmake_test.*
716
717 echo " --> set FC_NAMEMANGLE='$FC_NAMEMANGLE'" >> $LOGFILE
718 }
719
720 check_HAVE_CLOC() {
721 echo >> $LOGFILE
722 echo "running: check_HAVE_CLOC()" >> $LOGFILE
723 get_fortran_c_namemangling
724 cat <<EOF > genmake_tc_1.c
725 $FC_NAMEMANGLE
726 #include <stdio.h>
727 #include <stdlib.h>
728 #include <unistd.h>
729 #include <assert.h>
730 #include <sys/time.h>
731 void FC_NAMEMANGLE(cloc) ( double *curtim )
732 {
733 struct timeval tv1;
734 gettimeofday(&tv1 , (void *)NULL );
735 *curtim = (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
736 *curtim = *curtim/1.E6;
737 }
738 EOF
739 COMM="$CC $CFLAGS -c genmake_tc_1.c"
740 echo $COMM >> $LOGFILE
741 $COMM >> $LOGFILE 2>&1
742 RET_C=$?
743 cat <<EOF > genmake_tc_2.$FS
744 program hello
745 REAL*8 wtime
746 external cloc
747 call cloc(wtime)
748 print *," HELLO WORLD", wtime
749 end
750 EOF
751 COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
752 echo $COMM >> $LOGFILE
753 $COMM >> $LOGFILE 2>&1
754 RET_F=$?
755 test -x ./genmake_tc && ./genmake_tc >> $LOGFILE 2>&1
756 RETVAL=$?
757 if test "x$RETVAL" = x0 ; then
758 HAVE_CLOC=t
759 fi
760 rm -f genmake_tc*
761 echo " --> set HAVE_CLOC='$HAVE_CLOC'" >> $LOGFILE
762 }
763
764 check_HAVE_SIGREG() {
765 if test ! "x$HAVE_SIGREG" = x ; then
766 return
767 fi
768 echo >> $LOGFILE
769 echo "running: check_HAVE_SIGREG()" >> $LOGFILE
770 get_fortran_c_namemangling
771 cat <<EOF > genmake_tc_1.c
772 $FC_NAMEMANGLE
773 #include <stdlib.h>
774 #include <stdio.h>
775 #include <signal.h>
776 #include <errno.h>
777 #include <ucontext.h>
778
779 int * ip;
780
781 static void killhandler(
782 unsigned int sn, siginfo_t si, struct ucontext *sc )
783 {
784 *ip = *ip + 1;
785 return;
786 }
787
788 void FC_NAMEMANGLE(sigreg) (int * aip)
789 {
790 struct sigaction s;
791 ip = aip;
792 s.sa_flags = SA_SIGINFO;
793 s.sa_sigaction = (void *)killhandler;
794 if(sigaction (SIGTERM,&s,(struct sigaction *)NULL)) {
795 printf("Sigaction returned error = %d\n", errno);
796 exit(0);
797 }
798 return;
799 }
800 EOF
801 COMM="$CC $CFLAGS -c genmake_tc_1.c"
802 echo $COMM >> $LOGFILE
803 $COMM >> $LOGFILE 2>&1
804 RET_C=$?
805 cat <<EOF > genmake_tc_2.$FS
806 program hello
807 integer anint
808 common /iv/ anint
809 external sigreg
810 call sigreg(anint)
811 end
812 EOF
813 cat genmake_tc_2.$FS >> $LOGFILE
814 COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
815 echo $COMM >> $LOGFILE
816 $COMM >> $LOGFILE 2>&1
817 RETVAL=$?
818 if test "x$RETVAL" = x0 ; then
819 HAVE_SIGREG=t
820 fi
821 rm -f genmake_tc*
822 echo " --> set HAVE_SIGREG='$HAVE_SIGREG'" >> $LOGFILE
823 }
824
825 check_HAVE_SETRLSTK() {
826 if test ! "x$HAVE_SETRLSTK" = x ; then
827 return
828 fi
829 echo >> $LOGFILE
830 echo "running: check_HAVE_SETRLSTK()" >> $LOGFILE
831 get_fortran_c_namemangling
832 cat <<EOF > genmake_tc_1.c
833 $FC_NAMEMANGLE
834 #include <sys/time.h>
835 #include <sys/resource.h>
836 #include <unistd.h>
837 void FC_NAMEMANGLE(setrlstk) ()
838 {
839 struct rlimit rls;
840 rls.rlim_cur = RLIM_INFINITY;
841 rls.rlim_max = RLIM_INFINITY;
842 setrlimit(RLIMIT_STACK, &rls);
843 return;
844 }
845 EOF
846 COMM="$CC $CFLAGS -c genmake_tc_1.c"
847 echo $COMM >> $LOGFILE
848 $COMM >> $LOGFILE 2>&1
849 RET_C=$?
850 cat <<EOF > genmake_tc_2.$FS
851 program hello
852 external setrlstk
853 call setrlstk()
854 end
855 EOF
856 cat genmake_tc_2.$FS >> $LOGFILE
857 COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
858 echo $COMM >> $LOGFILE
859 $COMM >> $LOGFILE 2>&1
860 RETVAL=$?
861 if test "x$RETVAL" = x0 ; then
862 HAVE_SETRLSTK=t
863 fi
864 rm -f genmake_tc*
865 echo " --> set HAVE_SETRLSTK='$HAVE_SETRLSTK'" >> $LOGFILE
866 }
867
868 check_HAVE_STAT() {
869 echo >> $LOGFILE
870 echo "running: check_HAVE_STAT()" >> $LOGFILE
871 get_fortran_c_namemangling
872 cat <<EOF > genmake_tc_1.c
873 $FC_NAMEMANGLE
874 #include <stdio.h>
875 #include <stdlib.h>
876 #include <unistd.h>
877 #include <sys/stat.h>
878 #include <sys/types.h>
879 void FC_NAMEMANGLE(tfsize) ( int *nbyte )
880 {
881 char name[512];
882 struct stat astat;
883
884 name[0] = 'a'; name[1] = '\0';
885 if (! stat(name, &astat))
886 *nbyte = (int)(astat.st_size);
887 else
888 *nbyte = -1;
889 }
890 EOF
891 COMM="$CC $CFLAGS -c genmake_tc_1.c"
892 echo $COMM >> $LOGFILE
893 $COMM >> genmake_tc.log 2>&1
894 RET_C=$?
895 cat <<EOF > genmake_tc_2.$FS
896 program hello
897 integer nbyte
898 call tfsize(nbyte)
899 print *," HELLO WORLD", nbyte
900 end
901 EOF
902 cat genmake_tc_2.$FS >> $LOGFILE
903 COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
904 echo $COMM >> $LOGFILE
905 $COMM >> genmake_tc.log 2>&1
906 RETVAL=$?
907 if test "x$RETVAL" = x0 ; then
908 HAVE_STAT=t
909 fi
910 rm -f genmake_tc*
911 echo " --> set HAVE_STAT='$HAVE_STAT'" >> $LOGFILE
912 }
913
914 check_netcdf_libs() {
915 if test ! "x$SKIP_NETCDF_CHECK" = x ; then
916 return
917 fi
918 echo >> $LOGFILE
919 echo "running: check_netcdf_libs()" >> $LOGFILE
920 cat <<EOF > genmake_tnc.F
921 program fgennc
922 #include "netcdf.inc"
923 EOF
924 #if test ! "x$MPI" = x ; then
925 # echo '#include "mpif.h"' >> genmake_tnc.F
926 #fi
927 cat <<EOF >> genmake_tnc.F
928 integer iret, ncid, xid
929 iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
930 IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
931 iret = nf_def_dim(ncid, 'X', 11, xid)
932 IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
933 iret = nf_close(ncid)
934 IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
935 end
936 EOF
937 echo "=== genmake_tnc.F >>>" > genmake_tnc.log
938 cat genmake_tnc.F >> genmake_tnc.log
939 echo "<<< genmake_tnc.F ===" >> genmake_tnc.log
940 RET_CPP=f
941 COMM="cat genmake_tnc.F | $CPP $DEFINES $INCLUDES"
942 echo "$COMM" >> genmake_tnc.log
943 eval $COMM > genmake_tnc.$FS 2>/dev/null && RET_CPP=t
944 if test "x$RET_CPP" = xf ; then
945 echo " WARNING: CPP failed to pre-process the netcdf test." \
946 >> genmake_tnc.log
947 echo " Please check that \$INCLUDES is properly set." \
948 >> genmake_tnc.log
949 fi
950 echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
951 echo " && $LINK $FFLAGS $FOPTIM -o genmake_tnc.o $LIBS" >> genmake_tnc.log
952 $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \
953 && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
954 RET_COMPILE=$?
955 cat genmake_tnc.log >> $LOGFILE
956
957 #EH3 Remove test program execution for machines that either disallow
958 #EH3 execution or cannot support it (eg. cross-compilers)
959 #EH3
960 #EH3 test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1
961 #EH3 RETVAL=$?
962 #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
963
964 if test "x$RET_COMPILE" = x0 ; then
965 HAVE_NETCDF=t
966 echo "check_netcdf: successful" >> $LOGFILE
967 else
968 # try again with "-lnetcdf" added to the libs
969 echo "==> try again with added '-lnetcdf'" > genmake_tnc.log
970 echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
971 echo " && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
972 echo " && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
973 cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null \
974 && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \
975 && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
976 RET_COMPILE=$?
977 echo >> $LOGFILE
978 cat genmake_tnc.log >> $LOGFILE
979 if test "x$RET_COMPILE" = x0 ; then
980 LIBS="$LIBS -lnetcdf"
981 HAVE_NETCDF=t
982 echo "check_netcdf: successful" >> $LOGFILE
983 else
984 # try again with "-lnetcdff" added to the libs
985 echo "==> try again with added '-lnetcdff -lnetcdf'" > genmake_tnc.log
986 echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
987 echo " && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
988 echo " && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
989 cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null \
990 && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \
991 && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdff -lnetcdf >> genmake_tnc.log 2>&1
992 RET_COMPILE=$?
993 echo >> $LOGFILE
994 cat genmake_tnc.log >> $LOGFILE
995 if test "x$RET_COMPILE" = x0 ; then
996 LIBS="$LIBS -lnetcdff -lnetcdf"
997 HAVE_NETCDF=t
998 echo "check_netcdf: successful" >> $LOGFILE
999 fi
1000 fi
1001 fi
1002 rm -f genmake_tnc*
1003 echo " --> set HAVE_NETCDF='$HAVE_NETCDF'" >> $LOGFILE
1004 }
1005
1006 check_lapack_libs() {
1007 if test ! "x$SKIP_LAPACK_CHECK" = x ; then
1008 return
1009 fi
1010 echo >> $LOGFILE
1011 echo "running: check_lapack_libs()" >> $LOGFILE
1012 cat <<EOF > genmake_tla.F
1013 program fgenla
1014 integer info
1015 integer ipiv( 2 )
1016 double precision ab( 4, 2 ), b( 2 )
1017 data ab / 0., 0., 1., 2., 0., 2., 1., 0. /
1018 data b / 1., 1. /
1019 call dgbsv( 2, 1, 1, 1, ab, 4, ipiv, b, 2, info )
1020 IF (info .NE. 0) write(*,*) 'Error:', info
1021 write(*,*) b
1022 end
1023 EOF
1024 echo "=== genmake_tla.F >>>" > genmake_tla.log
1025 cat genmake_tla.F >> genmake_tla.log
1026 echo "<<< genmake_tla.F ===" >> genmake_tla.log
1027 RET_CPP=f
1028 COMM="cat genmake_tla.F | $CPP $DEFINES $INCLUDES"
1029 echo "$COMM" >> genmake_tla.log
1030 eval $COMM > genmake_tla.$FS 2>/dev/null && RET_CPP=t
1031 if test "x$RET_CPP" = xf ; then
1032 echo " WARNING: CPP failed to pre-process the lapack test." \
1033 >> genmake_tla.log
1034 echo " Please check that \$INCLUDES is properly set." \
1035 >> genmake_tla.log
1036 fi
1037 echo "$FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1038 echo " && $LINK $FFLAGS $FOPTIM -o genmake_tla.o $LIBS" >> genmake_tla.log
1039 $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1 \
1040 && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS >> genmake_tla.log 2>&1
1041 RET_COMPILE=$?
1042 cat genmake_tla.log >> $LOGFILE
1043
1044 # test program execution not always possible (see check_netcdf_libs)
1045 #
1046 #test -x ./genmake_tla && ./genmake_tla >> genmake_tla.log 2>&1
1047 #RETVAL=$?
1048 #if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
1049
1050 if test "x$RET_COMPILE" = x0 ; then
1051 HAVE_LAPACK=t
1052 echo "check_lapack: successful" >> $LOGFILE
1053 else
1054 # try again with "-llapack" added to the libs
1055 echo "==> try again with added '-llapack'" > genmake_tla.log
1056 echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1057 echo " && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1058 echo " && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack" >> genmake_tla.log
1059 cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null \
1060 && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1 \
1061 && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack >> genmake_tla.log 2>&1
1062 RET_COMPILE=$?
1063 echo >> $LOGFILE
1064 cat genmake_tla.log >> $LOGFILE
1065 if test "x$RET_COMPILE" = x0 ; then
1066 LIBS="$LIBS -llapack"
1067 HAVE_LAPACK=t
1068 echo "check_lapack: successful" >> $LOGFILE
1069 else
1070 # try again with "-lf77blas -lcblas" added to the libs
1071 echo "==> try again with added '-llapack -lf77blas -lcblas'" > genmake_tla.log
1072 echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1073 echo " && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1074 echo " && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas" >> genmake_tla.log
1075 cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null \
1076 && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1 \
1077 && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas >> genmake_tla.log 2>&1
1078 RET_COMPILE=$?
1079 echo >> $LOGFILE
1080 cat genmake_tla.log >> $LOGFILE
1081 if test "x$RET_COMPILE" = x0 ; then
1082 LIBS="$LIBS -llapack -lf77blas -lcblas"
1083 HAVE_LAPACK=t
1084 echo "check_lapack: successful" >> $LOGFILE
1085 else
1086 # try again with "-latlas" added to the libs
1087 echo "==> try again with added '-llapack -lf77blas -lcblas -latlas'" > genmake_tla.log
1088 echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1089 echo " && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1090 echo " && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas" >> genmake_tla.log
1091 cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null \
1092 && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1 \
1093 && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas >> genmake_tla.log 2>&1
1094 RET_COMPILE=$?
1095 echo >> $LOGFILE
1096 cat genmake_tla.log >> $LOGFILE
1097 if test "x$RET_COMPILE" = x0 ; then
1098 LIBS="$LIBS -llapack -lf77blas -lcblas -latlas"
1099 HAVE_LAPACK=t
1100 echo "check_lapack: successful" >> $LOGFILE
1101 fi
1102 fi
1103 fi
1104 fi
1105 rm -f genmake_tla*
1106 echo " --> set HAVE_LAPACK='$HAVE_LAPACK'" >> $LOGFILE
1107 }
1108
1109 check_HAVE_FLUSH() {
1110 if test ! "x$SKIP_CHECK_FLUSH" = x ; then
1111 return
1112 fi
1113 echo >> $LOGFILE
1114 echo "running: check_HAVE_FLUSH()" >> $LOGFILE
1115 cat <<EOF > genmake_tflsh.$FS
1116 program fgenflsh
1117 integer iounit
1118 character*9 fname
1119 iounit = 26
1120 fname = 'tmp.tflsh'
1121 open(iounit,FILE=fname,STATUS='unknown')
1122 write(iounit,*) 'genmake_tflsh: hello'
1123 call flush(iounit)
1124 close(iounit)
1125 end
1126 EOF
1127 echo "=== genmake_tflsh.$FS >>>" > genmake_tflsh.log
1128 cat genmake_tflsh.$FS >> genmake_tflsh.log
1129 echo "<<< genmake_tflsh.$FS ===" >> genmake_tflsh.log
1130
1131 echo "$FC $FFLAGS $FOPTIM -c genmake_tflsh.$FS \ " >> genmake_tflsh.log
1132 echo " && $LINK $FFLAGS $FOPTIM -o genmake_tflsh.o $LIBS" >> genmake_tflsh.log
1133 $FC $FFLAGS $FOPTIM -c genmake_tflsh.$FS >> genmake_tflsh.log 2>&1 \
1134 && $LINK $FFLAGS $FOPTIM -o genmake_tflsh genmake_tflsh.o $LIBS >> genmake_tflsh.log 2>&1
1135 RET_COMPILE=$?
1136
1137 if test "x$RET_COMPILE" = x0 ; then
1138 HAVE_FLUSH=t
1139 #cat genmake_tflsh.log >> $LOGFILE
1140 echo " check_HAVE_FLUSH: successful" >> $LOGFILE
1141 else
1142 HAVE_FLUSH=f
1143 cat genmake_tflsh.log >> $LOGFILE
1144 fi
1145 rm -f genmake_tflsh*
1146 echo " --> set HAVE_FLUSH='$HAVE_FLUSH'" >> $LOGFILE
1147 }
1148
1149 ###############################################################################
1150 # Sequential part of script starts here
1151 ###############################################################################
1152
1153 # Set defaults here
1154 COMMANDL="$0 $@"
1155
1156 PLATFORM=
1157 LN=
1158 S64=
1159 KPP=
1160 #FC=
1161 #CC=gcc
1162 #CPP=
1163 LINK=
1164 DEFINES=
1165 PACKAGES=
1166 ENABLE=
1167 DISABLE=
1168 # MAKEFILE=
1169 # MAKEDEPEND=
1170 PKG_DEPEND=
1171 PKG_GROUPS=
1172 DUMPSTATE=f
1173 OPTFILE=
1174 INCLUDES="-I. $INCLUDES"
1175 FFLAGS=
1176 FOPTIM=
1177 FEXTRAFLAGS=
1178 USE_EXTENDED_SRC=
1179 EXTENDED_SRC_FLAG=
1180 GET_FC_VERSION=
1181 CFLAGS=
1182 KFLAGS1=
1183 KFLAGS2=
1184 #LDADD=
1185 LIBS=
1186 KPPFILES=
1187 NOOPTFILES=
1188 NOOPTFLAGS=
1189 MPI=
1190 MPIPATH=
1191 OMP=
1192 OMPFLAG=
1193 USE_R4=
1194 TS=
1195 PAPIS=
1196 PCLS=
1197 FOOLAD=
1198 PAPI=
1199 PCL=
1200 HPMT=
1201 GSL=
1202 DEVEL=
1203 HAVE_TEST_L=
1204
1205 # comment this line out to enable lapack test
1206 SKIP_LAPACK_CHECK=t
1207
1208 # DEFINES checked by test compilation or command-line
1209 HAVE_SYSTEM=
1210 HAVE_FDATE=
1211 FC_NAMEMANGLE=
1212 HAVE_CLOC=
1213 # HAVE_SETRLSTK=
1214 HAVE_STAT=
1215 HAVE_NETCDF=
1216 HAVE_ETIME=
1217 IGNORE_TIME=
1218 HAVE_LAPACK=
1219 HAVE_FLUSH=
1220
1221 MODS=
1222 TOOLSDIR=
1223 SOURCEDIRS=
1224 INCLUDEDIRS=
1225 STANDARDDIRS="USE_THE_DEFAULT"
1226
1227 #- local config file
1228 gm_local="genmake_local"
1229
1230 G2ARGS=
1231 BASH=
1232 PWD=`pwd`
1233 test "x$MAKE" = x && MAKE=make
1234 test "x$AWK" = x && AWK=awk
1235 EMBED_SRC=
1236 THISHOST=`hostname`
1237 THISCWD=`pwd`
1238 THISDATE=`date`
1239 THISUSER=`echo $USER`
1240 THISVER=
1241 MACHINE=`uname -a`
1242 EXECUTABLE=
1243 EXEHOOK=
1244 EXEDIR=
1245 IEEE=
1246 if test "x$MITGCM_IEEE" != x ; then
1247 IEEE=$MITGCM_IEEE
1248 fi
1249 FS=
1250 FS90=
1251
1252 AUTODIFF_PKG_USED=f
1253 AD_OPTFILE=
1254 TAF=
1255 AD_TAF_FLAGS=
1256 FTL_TAF_FLAGS=
1257 SVD_TAF_FLAGS=
1258 TAF_EXTRA=
1259 TAMC=
1260 AD_TAMC_FLAGS=
1261 FTL_TAF_FLAGS=
1262 SVD_TAMC_FLAGS=
1263 TAMC_EXTRA=
1264
1265 # The following state can be set directly by command-line switches
1266 gm_s1="ROOTDIR STANDARDDIRS MODS PKG_DEPEND PKG_GROUPS DISABLE ENABLE"
1267 gm_s2="PLATFORM OPTFILE MAKE MAKEFILE MAKEDEPEND FC CC MPI OMP USE_R4"
1268 gm_s3="FEXTRAFLAGS IEEE DEVEL GSL TS PAPIS PCLS PAPI PCL HPMT DUMPSTATE"
1269
1270 # The following state is not directly set by command-line switches
1271 gm_s4="LN S64 LINK PACKAGES INCLUDES FFLAGS FOPTIM"
1272 gm_s5="CFLAGS LIBS KPP KFLAGS1 KFLAGS2 KPPFILES NOOPTFILES NOOPTFLAGS"
1273 gm_s6="PWD TOOLSDIR SOURCEDIRS INCLUDEDIRS EXEDIR EXECUTABLE EXEHOOK"
1274 gm_s7="THISHOST THISUSER THISDATE THISVER MACHINE FC_NAMEMANGLE"
1275 gm_s8="HAVE_NETCDF HAVE_SYSTEM HAVE_FDATE HAVE_ETIME HAVE_LAPACK HAVE_FLUSH"
1276
1277 # The following are all related to adjoint/tangent-linear stuff
1278 gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
1279 gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1280 gm_s12="TAF_EXTRA TAMC_EXTRA"
1281
1282 gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8"
1283 gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
1284
1285 cat <<EOF
1286
1287 GENMAKE :
1288
1289 A program for GENerating MAKEfiles for the MITgcm project.
1290 For a quick list of options, use "genmake2 -h"
1291 or for more detail see the Developer's HOWTO manual at:
1292 http://mitgcm.org/public/docs.html
1293
1294 EOF
1295
1296 LOGFILE="genmake.log"
1297 #- clean-up previous genmake logfiles:
1298 rm -f genmake_state genmake_*optfile $LOGFILE
1299
1300 echo "=== Processing options files and arguments ==="
1301
1302 #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
1303 #parse_options
1304 ac_prev=
1305 for ac_option in "$@" ; do
1306
1307 G2ARGS="$G2ARGS \"$ac_option\""
1308
1309 # If the previous option needs an argument, assign it.
1310 if test -n "$ac_prev"; then
1311 eval "$ac_prev=\$ac_option"
1312 ac_prev=
1313 continue
1314 fi
1315
1316 ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
1317
1318 case $ac_option in
1319
1320 -help | --help | -h | --h)
1321 usage ;;
1322
1323 -nooptfile | --nooptfile)
1324 OPTFILE="NONE" ;;
1325 -optfile | --optfile | -of | --of)
1326 ac_prev=OPTFILE ;;
1327 -optfile=* | --optfile=* | -of=* | --of=*)
1328 OPTFILE=$ac_optarg ;;
1329
1330 -adoptfile | --adoptfile | -adof | --adof)
1331 ac_prev=AD_OPTFILE ;;
1332 -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
1333 AD_OPTFILE=$ac_optarg ;;
1334
1335 -pdepend | --pdepend)
1336 ac_prev=PKG_DEPEND ;;
1337 -pdepend=* | --pdepend=*)
1338 PKG_DEPEND=$ac_optarg ;;
1339
1340 -pgroups | --pgroups)
1341 ac_prev=PKG_GROUPS ;;
1342 -pgroups=* | --pgroups=*)
1343 PKG_GROUPS=$ac_optarg ;;
1344
1345 -make | --make | -m | --m)
1346 ac_prev=MAKE ;;
1347 -make=* | --make=* | -m=* | --m=*)
1348 MAKE=$ac_optarg ;;
1349
1350 -bash | --bash)
1351 ac_prev=BASH ;;
1352 -bash=* | --bash=*)
1353 BASH=$ac_optarg ;;
1354
1355 -makedepend | --makedepend | -md | --md)
1356 ac_prev=MAKEDEPEND ;;
1357 -makedepend=* | --makedepend=* | -md=* | --md=*)
1358 MAKEDEPEND=$ac_optarg ;;
1359
1360 -makefile | --makefile | -mf | --mf)
1361 ac_prev=MAKEFILE ;;
1362 -makefile=* | --makefile=* | -mf=* | --mf=*)
1363 MAKEFILE=$ac_optarg ;;
1364
1365 -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1366 echo "ERROR: The platform option has been removed. Please specify"
1367 echo " the build options using the \"optfile\" mechanism."
1368 echo
1369 usage
1370 ;;
1371
1372 -rootdir | --rootdir | -rd | --rd)
1373 ac_prev=ROOTDIR ;;
1374 -rootdir=* | --rootdir=* | -rd=* | --rd=*)
1375 ROOTDIR=$ac_optarg ;;
1376
1377 -mods | --mods | -mo | --mo)
1378 ac_prev=MODS ;;
1379 -mods=* | --mods=* | -mo=* | --mo=*)
1380 MODS=$ac_optarg ;;
1381
1382 -disable | --disable)
1383 ac_prev=DISABLE ;;
1384 -disable=* | --disable=*)
1385 DISABLE=$ac_optarg ;;
1386
1387 -enable | --enable)
1388 ac_prev=ENABLE ;;
1389 -enable=* | --enable=*)
1390 ENABLE=$ac_optarg ;;
1391
1392 -standarddirs | --standarddirs)
1393 ac_prev=STANDARDDIRS ;;
1394 -standarddirs=* | --standarddirs=*)
1395 STANDARDDIRS=$ac_optarg ;;
1396
1397 # -cpp | --cpp)
1398 # ac_prev=cpp ;;
1399 # -cpp=* | --cpp=*)
1400 # CPP=$ac_optarg ;;
1401
1402 -cc | --cc)
1403 ac_prev=CC ;;
1404 -cc=* | --cc=*)
1405 CC=$ac_optarg ;;
1406
1407 -fortran | --fortran | -fc | --fc)
1408 ac_prev=FC ;;
1409 -fc=* | --fc=*)
1410 FC=$ac_optarg ;;
1411
1412 -fs | --fs)
1413 ac_prev=FS ;;
1414 -fs=* | --fs=*)
1415 FS=$ac_optarg ;;
1416
1417 -fs90 | --fs90)
1418 ac_prev=FS90 ;;
1419 -fs90=* | --fs90=*)
1420 FS90=$ac_optarg ;;
1421
1422 -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4 )
1423 USE_R4=true ;;
1424
1425 -ieee | --ieee)
1426 IEEE=true ;;
1427 -noieee | --noieee)
1428 echo "Warning: ignore option '$ac_option' (default is already without '-ieee')" ;;
1429 -devel | --devel)
1430 IEEE=true ; DEVEL=true ;;
1431 -gsl | --gsl)
1432 GSL=true ;;
1433
1434 -ts | --ts)
1435 TS=true ;;
1436 -papis | --papis)
1437 PAPIS=true ;;
1438 -pcls | --pcls)
1439 PCLS=true ;;
1440 -foolad | --foolad)
1441 FOOLAD=true ;;
1442 -papi | --papi)
1443 PAPI=true ;;
1444 -pcl | --pcl)
1445 PCL=true ;;
1446 -hpmt | --hpmt)
1447 HPMT=true ;;
1448
1449 -mpi | --mpi)
1450 MPI=true ;;
1451 -mpi=* | --mpi=*)
1452 MPIPATH=$ac_optarg
1453 MPI=true ;;
1454
1455 -omp | --omp)
1456 OMP=true ;;
1457 -omp=* | --omp=*)
1458 OMPFLAG=$ac_optarg
1459 OMP=true ;;
1460
1461 -ds | --ds)
1462 DUMPSTATE=t ;;
1463
1464 -extra_flag | --extra_flag)
1465 ac_prev=FEXTRAFLAGS ;;
1466 -extra_flag=* | --extra_flag=*)
1467 FEXTRAFLAGS=$ac_optarg ;;
1468
1469 -taf_extra | --taf_extra)
1470 ac_prev=TAF_EXTRA ;;
1471 -taf_extra=* | --taf_extra=*)
1472 TAF_EXTRA=$ac_optarg ;;
1473
1474 -tamc_extra | --tamc_extra)
1475 ac_prev=TAMC_EXTRA ;;
1476 -tamc_extra=* | --tamc_extra=*)
1477 TAMC_EXTRA=$ac_optarg ;;
1478
1479 -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1480 IGNORE_TIME="-DIGNORE_TIME" ;;
1481
1482 -es | --es | -embed-source | --embed-source)
1483 EMBED_SRC=t ;;
1484
1485 -*)
1486 echo "Error: unrecognized option: "$ac_option
1487 usage
1488 ;;
1489
1490 *)
1491 echo "Error: unrecognized argument: "$ac_option
1492 usage
1493 ;;
1494
1495 esac
1496
1497 done
1498
1499 printf " getting local config information: "
1500 if test -f $gm_local ; then
1501 echo "using $gm_local"
1502 . $gm_local
1503 else
1504 echo "none found"
1505 fi
1506
1507 if test -f ./.genmakerc ; then
1508 echo
1509 echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
1510 echo " file. This file format is no longer supported. For directions on"
1511 echo " how to setup and use the new \"genmake2\" script, please see:"
1512 echo " http://mitgcm.org/public/devel_HOWTO/"
1513 echo " and send an email to MITgcm-support@mitgcm.org if you need help."
1514 echo "WARNING: ignore \"./.genmakerc\" and continue."
1515 echo
1516 fi
1517
1518 # Find the MITgcm ${ROOTDIR}
1519 if test "x${ROOTDIR}" = x ; then
1520 tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1521 if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesupp -a -d ../pkg ; then
1522 ROOTDIR=".."
1523 else
1524 for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1525 if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
1526 ROOTDIR=$d
1527 printf "Warning: ROOTDIR was not specified ;"
1528 echo " try using a local copy of MITgcm found at \"$ROOTDIR\""
1529 break
1530 fi
1531 done
1532 fi
1533 fi
1534 if test "x${ROOTDIR}" = x ; then
1535 echo "Error: Cannot determine ROOTDIR for MITgcm code."
1536 echo " Please specify a ROOTDIR using either an options "
1537 echo " file or a command-line option."
1538 exit 1
1539 fi
1540 if test ! -d ${ROOTDIR} ; then
1541 echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
1542 exit 1
1543 fi
1544
1545 # Find the MITgcm ${THISVER}
1546 version_file="${ROOTDIR}/doc/tag-index"
1547 if test -f $version_file ; then
1548 THISVER=`$AWK '/^checkpoint/{print $1; exit}' $version_file`
1549 #- remove ./BUILD_INFO.h file if older than version_file
1550 if test -f ./BUILD_INFO.h -a ./BUILD_INFO.h -ot $version_file ; then
1551 echo " remove ./BUILD_INFO.h (older than ${version_file})"
1552 rm -f ./BUILD_INFO.h
1553 fi
1554 fi
1555
1556 if test "x$MAKEFILE" = x ; then
1557 MAKEFILE="Makefile"
1558 fi
1559
1560 echo " getting OPTFILE information:"
1561 if test "x${OPTFILE}" = x ; then
1562 if test "x$MITGCM_OF" = x ; then
1563 echo "Warning: no OPTFILE specified so we'll look for possible settings"
1564 printf "\n=== Searching for possible settings for OPTFILE ===\n"
1565 find_possible_optfile
1566 else
1567 OPTFILE=$MITGCM_OF
1568 fi
1569 fi
1570 if test "x$OPTFILE" != xNONE ; then
1571 if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
1572 echo " using OPTFILE=\"$OPTFILE\""
1573 . "$OPTFILE"
1574 RETVAL=$?
1575 if test "x$RETVAL" != x0 ; then
1576 printf "Error: failed to source OPTFILE \"$OPTFILE\""
1577 echo "--please check that variable syntax is bash-compatible"
1578 exit 1
1579 fi
1580 if test "x$DUMPSTATE" = xt ; then
1581 cp -f $OPTFILE "genmake_optfile"
1582 fi
1583 else
1584 echo "Error: can't read OPTFILE=\"$OPTFILE\""
1585 exit 1
1586 fi
1587 fi
1588
1589 echo " getting AD_OPTFILE information:"
1590 if test "x${AD_OPTFILE}" = x ; then
1591 if test "x$MITGCM_AD_OF" = x ; then
1592 AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
1593 else
1594 AD_OPTFILE=$MITGCM_AD_OF
1595 fi
1596 fi
1597 if test "x${AD_OPTFILE}" != xNONE ; then
1598 if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
1599 echo " using AD_OPTFILE=\"$AD_OPTFILE\""
1600 . "$AD_OPTFILE"
1601 RETVAL=$?
1602 if test "x$RETVAL" != x0 ; then
1603 printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1604 echo "--please check that variable syntax is bash-compatible"
1605 exit 1
1606 fi
1607 if test "x$DUMPSTATE" = xt ; then
1608 cp -f $AD_OPTFILE "genmake_ad_optfile"
1609 fi
1610 else
1611 echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
1612 exit 1
1613 fi
1614 fi
1615
1616 #====================================================================
1617 # Set default values if not set by the optfile
1618 #
1619 # Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined. If not,
1620 # either set defaults or complain and abort!
1621 if test ! "x$BASH" = x ; then
1622 # add a trailing space so that it works within the Makefile syntax (see below)
1623 BASH="$BASH "
1624 fi
1625 if test "x$FC" = x ; then
1626 cat <<EOF 1>&2
1627
1628 Error: no Fortran compiler: please specify using one of the following:
1629 1) within the options file ("FC=...") as specified by "-of=OPTFILE"
1630 2) the "-fc=XXX" command-line option
1631 3) the "./genmake_local" file
1632 EOF
1633 exit 1
1634 fi
1635 if test "x$GET_FC_VERSION" != x ; then
1636 echo "Get compiler version using: $FC $GET_FC_VERSION" >> $LOGFILE
1637 ff=`echo $FC | sed 's/ .*//'` ; xx=`echo $ff | sed 's/^./& /' | sed 's/ .*//'`
1638 if test $xx != '/' ; then which $ff >> $LOGFILE ; fi
1639 $FC $GET_FC_VERSION > genmake_fc_vers1 2> genmake_fc_vers2
1640 if test -s genmake_fc_vers1 ; then
1641 cat genmake_fc_vers1 >> $LOGFILE
1642 else
1643 cat genmake_fc_vers2 >> $LOGFILE
1644 fi
1645 echo "<-- compiler version ----" >> $LOGFILE
1646 rm -f genmake_fc_vers1 genmake_fc_vers2
1647 fi
1648
1649 if test "x$CC" = x ; then
1650 look_for_C_compilers
1651 fi
1652
1653 if test "x$LINK" = x ; then
1654 LINK=$FC
1655 fi
1656 if test "x$MAKE" = x ; then
1657 MAKE="make"
1658 fi
1659 if test "x$CPP" = x ; then
1660 CPP="cpp -traditional -P"
1661 fi
1662 #EH3 === UGLY ===
1663 # The following is an ugly little hack to check for $CPP in /lib/ and
1664 # it should eventually be replaced with a more general function that
1665 # searches a combo of the user's path and a list of "usual suspects"
1666 # to find the correct location for binaries such as $CPP.
1667 for i in " " "/lib/" ; do
1668 echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1669 done
1670 #EH3 === UGLY ===
1671 echo "#define A a" | $CPP > test_cpp 2>&1
1672 RETVAL=$?
1673 if test "x$RETVAL" != x0 ; then
1674 cat <<EOF 1>&2
1675
1676 Error: C pre-processor "$CPP" failed the test case: please specify using:
1677
1678 1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1679 2) the "./genmake_local" file
1680 3) with the CPP environment variable
1681
1682 EOF
1683 exit 1
1684 else
1685 rm -f test_cpp
1686 fi
1687
1688 look_for_makedepend
1689
1690 # Check that soft-link command is set and usable
1691 if test "x$LN" = x ; then
1692 LN="ln -s"
1693 fi
1694 echo "test" > genmake_test_ln
1695 $LN genmake_test_ln genmake_tlink
1696 RETVAL=$?
1697 if test "x$RETVAL" != x0 ; then
1698 cat <<EOF 1>&2
1699
1700 Error: The command "$LN" failed -- please specify a working soft-link
1701 command in the optfile.
1702
1703 EOF
1704 exit 1
1705 fi
1706 test -L genmake_tlink > /dev/null 2>&1
1707 RETVAL=$?
1708 if test "x$RETVAL" = x0 ; then
1709 HAVE_TEST_L=t
1710 fi
1711 rm -f genmake_test_ln genmake_tlink
1712
1713 # Check for broken *.F/*.f handling and fix if possible
1714 check_for_broken_Ff
1715
1716 if test ! "x$MPI" = x ; then
1717 echo " Turning on MPI cpp macros"
1718 DEFINES="$DEFINES -DALLOW_USE_MPI"
1719 #- To compile code older than checkpoint63s (2012/09/05), un-comment the following line:
1720 # DEFINES="$DEFINES -DALWAYS_USE_MPI"
1721 fi
1722 if test ! "x$OMP" = x ; then
1723 echo " Add OMPFLAG and turn on OpenMP cpp macros"
1724 FFLAGS="$FFLAGS $OMPFLAG"
1725 F90FLAGS="$F90FLAGS $OMPFLAG"
1726 DEFINES="$DEFINES -DUSE_OMP_THREADING"
1727 fi
1728
1729 if test ! "x$USE_R4" = x ; then
1730 echo " Turning on LET_RS_BE_REAL4 cpp flag"
1731 DEFINES="$DEFINES -DLET_RS_BE_REAL4"
1732 fi
1733
1734 if test ! "x$TS" = x ; then
1735 echo " Turning on timing per timestep"
1736 if test ! "x$FOOLAD" = x ; then
1737 DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP"
1738 else
1739 DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1740 fi
1741 PACKAGES="$PACKAGES showflops"
1742 fi
1743 if test ! "x$PAPIS" = x ; then
1744 echo " Turning on PAPI flop summary per timestep"
1745 echo " Please make sure PAPIINC, PAPILIB are defined"
1746 if test ! "x$FOOLAD" = x ; then
1747 DEFINES="$DEFINES -DUSE_PAPI_FLOPS_SFP"
1748 else
1749 DEFINES="$DEFINES -DUSE_PAPI_FLOPS"
1750 fi
1751 INCLUDES="$INCLUDES $PAPIINC"
1752 LIBS="$LIBS $PAPILIB"
1753 PACKAGES="$PACKAGES showflops"
1754 fi
1755 if test ! "x$PCLS" = x ; then
1756 echo " Turning on PCL counter summary per timestep"
1757 echo " Please make sure PCLINC, PCLLIB are defined"
1758 if test ! "x$FOOLAD" = x ; then
1759 DEFINES="$DEFINES -DUSE_PCL_FLOPS_SFP"
1760 else
1761 DEFINES="$DEFINES -DUSE_PCL_FLOPS"
1762 fi
1763 INCLUDES="$INCLUDES $PCLINC"
1764 LIBS="$LIBS $PCLLIB"
1765 PACKAGES="$PACKAGES showflops"
1766 fi
1767 if test ! "x$PAPI" = x ; then
1768 if test ! "x$PAPIS" = x ; then
1769 echo " PAPI performance analysis and flop summary per timestep cannot co-exist!"
1770 echo " Sticking with PAPI flop summary per timestep!"
1771 else
1772 echo " Turning on performance analysis with PAPI"
1773 echo " Please make sure PAPIINC, PAPILIB are defined"
1774 DEFINES="$DEFINES -DUSE_PAPI"
1775 INCLUDES="$INCLUDES $PAPIINC"
1776 LIBS="$LIBS $PAPILIB"
1777 fi
1778 fi
1779 if test ! "x$PCL" = x ; then
1780 if test ! "x$PCLS" = x ; then
1781 echo " PCL performance analysis and flop summary per timestep cannot co-exist!"
1782 echo " Sticking with PCL flop summary per timestep!"
1783 else
1784 echo " Turning on performance analysis with PCL"
1785 echo " Please make sure PCLINC, PCLLIB are defined"
1786 DEFINES="$DEFINES -DUSE_PCL"
1787 INCLUDES="$INCLUDES $PCLINC"
1788 LIBS="$LIBS $PCLLIB"
1789 fi
1790 fi
1791 if test ! "x$HPMT" = x ; then
1792 if test ! "x$PAPI" = x ; then
1793 echo " PAPI and the HPM Toolkit cannot co-exist!"
1794 echo " Sticking with PAPI!"
1795 else
1796 if test ! "x$PCL" = x ; then
1797 echo " PCL and the HPM Toolkit cannot co-exist!"
1798 echo " Sticking with PCL!"
1799 else
1800 echo " Turning on performance analysis with the HPM Toolkit"
1801 echo " Please make sure HPMTINC, HPMTLIB are defined"
1802 DEFINES="$DEFINES -DUSE_LIBHPM"
1803 INCLUDES="$INCLUDES $HPMTINC"
1804 LIBS="$LIBS $HPMTLIB"
1805 fi
1806 fi
1807 fi
1808 if test ! "x$GSL" = x ; then
1809 echo " Turning on use of GSL to control floating point calculations"
1810 echo " Please make sure GSLINC, GSLLIB are defined"
1811 DEFINES="$DEFINES -DUSE_GSL_IEEE"
1812 INCLUDES="$INCLUDES $GSLINC"
1813 LIBS="$LIBS $GSLLIB"
1814 fi
1815 #- if USE_EXTENDED_SRC is set, add EXTENDED_SRC_FLAG to FFLAGS :
1816 if test ! "x$USE_EXTENDED_SRC" = x ; then
1817 FFLAGS="$FFLAGS $EXTENDED_SRC_FLAG"
1818 F90FIXEDFORMAT="$F90FIXEDFORMAT $EXTENDED_SRC_FLAG"
1819 fi
1820
1821 printf "\n=== Checking system libraries ===\n"
1822 printf " Do we have the system() command using $FC... "
1823 cat > genmake_tcomp.$FS <<EOF
1824 program hello
1825 call system('echo hi')
1826 end
1827 EOF
1828 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1829 RETVAL=$?
1830 if test "x$RETVAL" = x0 ; then
1831 HAVE_SYSTEM=t
1832 DEFINES="$DEFINES -DHAVE_SYSTEM"
1833 echo "yes"
1834 else
1835 HAVE_SYSTEM=
1836 echo "no"
1837 fi
1838 rm -f genmake_tcomp*
1839
1840 printf " Do we have the fdate() command using $FC... "
1841 cat > genmake_tcomp.$FS <<EOF
1842 program hello
1843 CHARACTER*(128) string
1844 string = ' '
1845 call fdate( string )
1846 print *, string
1847 end
1848 EOF
1849 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1850 RETVAL=$?
1851 if test "x$RETVAL" = x0 ; then
1852 HAVE_FDATE=t
1853 DEFINES="$DEFINES -DHAVE_FDATE"
1854 echo "yes"
1855 else
1856 HAVE_FDATE=
1857 echo "no"
1858 fi
1859 rm -f genmake_tcomp*
1860
1861 printf " Do we have the etime() command using $FC... "
1862 cat > genmake_tcomp.$FS <<EOF
1863 program hello
1864 REAL*4 ACTUAL, TARRAY(2)
1865 EXTERNAL ETIME
1866 REAL*4 ETIME
1867 actual = etime( tarray )
1868 print *, tarray
1869 end
1870 EOF
1871 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1872 RETVAL=$?
1873 if test "x$RETVAL" = x0 ; then
1874 HAVE_ETIME=t
1875 DEFINES="$DEFINES -DHAVE_ETIME"
1876 echo "yes"
1877 else
1878 HAVE_ETIME=
1879 echo "no"
1880 fi
1881 rm -f genmake_tcomp*
1882
1883 printf " Can we call simple C routines (here, \"cloc()\") using $FC... "
1884 check_HAVE_CLOC
1885 if test "x$HAVE_CLOC" != x ; then
1886 DEFINES="$DEFINES -DHAVE_CLOC"
1887 echo "yes"
1888 else
1889 echo "no"
1890 if test "x$EMBED_SRC" = xt ; then
1891 echo " WARNING: you requested file embedding but it has"
1892 echo " been disabled since C code cannot be called"
1893 EMBED_SRC=
1894 fi
1895 fi
1896 rm -f genmake_t*
1897
1898 printf " Can we unlimit the stack size using $FC... "
1899 check_HAVE_SETRLSTK
1900 if test "x$HAVE_SETRLSTK" = xt ; then
1901 DEFINES="$DEFINES -DHAVE_SETRLSTK"
1902 echo "yes"
1903 else
1904 echo "no"
1905 fi
1906 rm -f genmake_t*
1907
1908 printf " Can we register a signal handler using $FC... "
1909 check_HAVE_SIGREG
1910 if test "x$HAVE_SIGREG" = xt ; then
1911 DEFINES="$DEFINES -DHAVE_SIGREG"
1912 echo "yes"
1913 else
1914 echo "no"
1915 fi
1916 rm -f genmake_t*
1917
1918 printf " Can we use stat() through C calls... "
1919 check_HAVE_STAT
1920 if test "x$HAVE_STAT" != x ; then
1921 DEFINES="$DEFINES -DHAVE_STAT"
1922 echo "yes"
1923 else
1924 echo "no"
1925 fi
1926 rm -f genmake_t*
1927
1928 printf " Can we create NetCDF-enabled binaries... "
1929 check_netcdf_libs
1930 if test "x$HAVE_NETCDF" != x ; then
1931 DEFINES="$DEFINES -DHAVE_NETCDF"
1932 echo "yes"
1933 else
1934 echo "no"
1935 fi
1936
1937 printf " Can we create LAPACK-enabled binaries... "
1938 check_lapack_libs
1939 if test "x$HAVE_LAPACK" != x ; then
1940 DEFINES="$DEFINES -DHAVE_LAPACK"
1941 echo "yes"
1942 else
1943 echo "no"
1944 fi
1945
1946 printf " Can we call FLUSH intrinsic subroutine... "
1947 check_HAVE_FLUSH
1948 if test "x$HAVE_FLUSH" = xt ; then
1949 DEFINES="$DEFINES -DHAVE_FLUSH"
1950 echo "yes"
1951 else
1952 echo "no"
1953 fi
1954
1955 DEFINES="$DEFINES $IGNORE_TIME"
1956 if test "x$EMBED_SRC" = xt ; then
1957 build_embed_encode
1958 fi
1959 if test "x$EMBED_SRC" = xt ; then
1960 ENABLE="$ENABLE embed_files"
1961 # DEFINES="$DEFINES -DHAVE_EMBED_SRC"
1962 fi
1963
1964 printf "\n=== Setting defaults ===\n"
1965 printf " Adding MODS directories: "
1966 for d in $MODS ; do
1967 if test ! -d $d ; then
1968 echo
1969 echo "Error: MODS directory \"$d\" not found!"
1970 exit 1
1971 else
1972 printf "$d "
1973 SOURCEDIRS="$SOURCEDIRS $d"
1974 INCLUDEDIRS="$INCLUDEDIRS $d"
1975 fi
1976 done
1977 echo
1978
1979 #if test "x${PLATFORM}" = x ; then
1980 # PLATFORM=$p_PLATFORM
1981 #fi
1982
1983 if test "x${EXEDIR}" = x ; then
1984 tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1985 if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
1986 EXEDIR=../exe
1987 else
1988 EXEDIR=.
1989 fi
1990 fi
1991 if test ! -d ${EXEDIR} ; then
1992 echo "Error: the specified EXEDIR (\"$EXEDIR\") does not exist!"
1993 exit 1
1994 fi
1995
1996 if test "x${TOOLSDIR}" = x ; then
1997 TOOLSDIR="$ROOTDIR/tools"
1998 fi
1999 if test ! -d ${TOOLSDIR} ; then
2000 echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
2001 exit 1
2002 fi
2003 if test "x$S64" = x ; then
2004 echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
2005 RETVAL=$?
2006 if test "x${RETVAL}" = x0 ; then
2007 S64='$(TOOLSDIR)/set64bitConst.sh'
2008 else
2009 echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
2010 RETVAL=$?
2011 if test "x${RETVAL}" = x0 ; then
2012 S64='$(TOOLSDIR)/set64bitConst.csh'
2013 else
2014 cat <<EOF
2015
2016 ERROR: neither of the two default scripts:
2017
2018 ${TOOLSDIR}/set64bitConst.sh
2019 ${TOOLSDIR}/set64bitConst.csh
2020
2021 are working so please check paths or specify (with \$S64) a
2022 working version of this script.
2023
2024 EOF
2025 exit 1
2026 fi
2027 fi
2028 fi
2029 THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
2030
2031 EXECUTABLE=${EXECUTABLE:-mitgcmuv}
2032
2033 # Set Standard Code Directories:
2034 if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
2035 STANDARDDIRS="eesupp model"
2036 fi
2037 # if model in Standard-Code-Dir, add eesupp (needed to compile model)
2038 echo " $STANDARDDIRS " | grep ' model ' > /dev/null 2>&1
2039 ckM=$?
2040 echo " $STANDARDDIRS " | grep ' eesupp ' > /dev/null 2>&1
2041 ckE=$?
2042 if test $ckM = 0 -a $ckE = 1 ; then
2043 STANDARDDIRS="$STANDARDDIRS eesupp"
2044 fi
2045
2046 # We have a special set of source files in eesupp/src which are
2047 # generated from some template source files. We'll make them first so
2048 # they appear as regular source code
2049 if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
2050 echo " Making source files in eesupp from templates"
2051 ( cd $ROOTDIR"/eesupp/src/" && $MAKE clean_old && $MAKE \
2052 ) > make_eesupp.errors 2>&1
2053 RETVAL=$?
2054 if test "x${RETVAL}" = x0 ; then
2055 rm -f make_eesupp.errors
2056 else
2057 echo "Error: problem encountered while building source files in eesupp:"
2058 cat make_eesupp.errors 1>&2
2059 exit 1
2060 fi
2061 fi
2062
2063 #same for pkg/exch2 and pkg/regrid
2064 for pdir in exch2 regrid ; do
2065 if test -r $ROOTDIR"/pkg/${pdir}/Makefile" ; then
2066 echo " Making source files in pkg/${pdir} from templates"
2067 ( cd $ROOTDIR"/pkg/"${pdir} && $MAKE clean_old && $MAKE \
2068 ) > make_${pdir}.errors 2>&1
2069 RETVAL=$?
2070 if test "x${RETVAL}" = x0 ; then
2071 rm -f make_${pdir}.errors
2072 else
2073 echo "Error: problem encountered while building source files in pkg/${pdir}:"
2074 cat make_${pdir}.errors 1>&2
2075 exit 1
2076 fi
2077 fi
2078 done
2079
2080 printf "\n=== Determining package settings ===\n"
2081 if test "x${PKG_DEPEND}" = x ; then
2082 tmp=$ROOTDIR"/pkg/pkg_depend"
2083 if test -r $tmp ; then PKG_DEPEND=$tmp ; fi
2084 fi
2085 if test "x${PKG_DEPEND}" = x ; then
2086 echo "Warning: No package dependency information was specified."
2087 echo " Please check that ROOTDIR/pkg/pkg_depend exists."
2088 else
2089 if test ! -r ${PKG_DEPEND} ; then
2090 echo "Error: can't read package dependency info from PKG_DEPEND=\"$PKG_DEPEND\""
2091 exit 1
2092 fi
2093 echo " getting package dependency info from $PKG_DEPEND"
2094 # Strip the comments and then convert the dependency file into arrays: PNAME, DNAME
2095 get_pdepend_list $PKG_DEPEND
2096 fi
2097
2098 # A default package groups file "$ROOTDIR/pkg/pkg_groups" is provided
2099 # to define the "default_pkg_list" and package groups (for convenience, one
2100 # can specify a group of packages using names like "ocean" and "atmosphere").
2101 if test "x${PKG_GROUPS}" = x ; then
2102 tmp=$ROOTDIR"/pkg/pkg_groups"
2103 if test -r $tmp ; then PKG_GROUPS=$tmp ; fi
2104 fi
2105 if test "x${PKG_GROUPS}" = x ; then
2106 echo "Warning: No package groups information was specified."
2107 echo " Please check that ROOTDIR/pkg/pkg_groups exists."
2108 else
2109 if test ! -r ${PKG_GROUPS} ; then
2110 echo "Error: can't read package groups info from PKG_GROUPS=\"$PKG_GROUPS\""
2111 exit 1
2112 fi
2113 echo " getting package groups info from $PKG_GROUPS"
2114 fi
2115
2116 # Search for packages to compile.
2117 echo " checking list of packages to compile:"
2118 PKG_LIST=
2119 if test "x${PKG_LIST}" = x ; then
2120 for i in "." $MODS ; do
2121 if test -r $i"/packages.conf" ; then
2122 PKG_LIST=$i"/packages.conf"
2123 break
2124 fi
2125 done
2126 fi
2127 if test "x${PKG_LIST}" = x ; then
2128 pkg_list='default_pkg_list'
2129 if test "x${PKG_GROUPS}" = x ; then
2130 echo "Error: need package groups info to expand pkg_list=\"$pkg_list\""
2131 exit 1
2132 fi
2133 else
2134 if test ! -r $PKG_LIST ; then
2135 echo "Error: can't read package list from PKG_LIST=\"$PKG_LIST\""
2136 exit 1
2137 else
2138 echo " using PKG_LIST=\"$PKG_LIST\""
2139 # Strip the comments and add all the names
2140 pkg_list=`cat $PKG_LIST | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
2141 RETVAL=$?
2142 if test "x${RETVAL}" != x0 ; then
2143 printf "Error: can't parse package list "
2144 echo "-- please check PKG_LIST=\"$PKG_LIST\""
2145 exit 1
2146 fi
2147 fi
2148 fi
2149 for i in $pkg_list ; do
2150 PACKAGES="$PACKAGES $i"
2151 done
2152 echo " before group expansion packages are:$PACKAGES"
2153 if test "x${PKG_GROUPS}" != x ; then
2154 RET=1
2155 while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
2156 echo " after group expansion packages are: $PACKAGES"
2157 fi
2158
2159 echo " applying DISABLE settings"
2160 echo "" > ./.tmp_pack
2161 for i in $PACKAGES ; do
2162 echo $i >> ./.tmp_pack
2163 done
2164 for i in `grep "-" ./.tmp_pack` ; do
2165 j=`echo $i | sed 's/[-]//'`
2166 DISABLE="$DISABLE $j"
2167 done
2168 pack=
2169 for p in $PACKAGES ; do
2170 addit="t"
2171 for d in $DISABLE ; do
2172 if test "x$p" = "x$d" ; then
2173 addit="f"
2174 fi
2175 done
2176 if test "x$addit" = xt ; then
2177 pack="$pack $p"
2178 fi
2179 done
2180 PACKAGES="$pack"
2181 echo " applying ENABLE settings"
2182 echo "" > ./.tmp_pack
2183 PACKAGES="$PACKAGES $ENABLE"
2184 # Test if each explicitly referenced package exists
2185 for i in $PACKAGES ; do
2186 j=`echo $i | sed 's/[-+]//'`
2187 if test ! -d "$ROOTDIR/pkg/$j" ; then
2188 echo "Error: dir '$ROOTDIR/pkg/$i' missing for package '$i'"
2189 exit 1
2190 fi
2191 echo $i >> ./.tmp_pack
2192 done
2193 PACKAGES=
2194 for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
2195 PACKAGES="$PACKAGES $i"
2196 done
2197 rm -f ./.tmp_pack
2198 echo " packages are: $PACKAGES"
2199
2200 # Check for package MNC: if NetCDF is available, then build the MNC
2201 # template files ; otherwise, delete mnc from the list of packages.
2202 echo " $PACKAGES " | grep ' mnc ' > /dev/null 2>&1
2203 mnc_in=$?
2204 if test "x$HAVE_NETCDF" != xt ; then
2205 if test "x$mnc_in" = x0 ; then
2206 cat <<EOF
2207 *********************************************************************
2208 WARNING: the "mnc" package was enabled but tests failed to compile
2209 NetCDF applications. Please check that:
2210
2211 1) NetCDF is correctly installed for this compiler and
2212 2) the LIBS variable (within the "optfile") specifies the correct
2213 NetCDF library to link against.
2214
2215 Due to this failure, the "mnc" package is now DISABLED.
2216 *********************************************************************
2217 EOF
2218 PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
2219 DISABLE="$DISABLE mnc"
2220 else
2221 # this prevent to add mnc (due to pdepend rules) if not available
2222 DISABLE="$DISABLE mnc"
2223 fi
2224 else
2225 # we have NetCDF, we try to build MNC template files
2226 ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
2227 RETVAL=$?
2228 if test "x${RETVAL}" = x0 ; then
2229 rm -f make_mnc.errors
2230 else
2231 echo "Error: problem encountered while building source files in pkg/mnc:"
2232 cat make_mnc.errors 1>&2
2233 if test "x$mnc_in" = x0 ; then
2234 exit 1
2235 else
2236 DISABLE="$DISABLE mnc"
2237 fi
2238 fi
2239 fi
2240
2241 # Check for package PROFILES: if NetCDF is not available,
2242 # then delete profiles from the list of available packages.
2243 if test "x$HAVE_NETCDF" != xt ; then
2244 echo " $PACKAGES " | grep ' profiles ' > /dev/null 2>&1
2245 RETVAL=$?
2246 if test "x$RETVAL" = x0 ; then
2247 cat <<EOF
2248 *********************************************************************
2249 WARNING: the "profiles" package was enabled but tests failed to
2250 compile NetCDF applications. Please check that:
2251
2252 1) NetCDF is correctly installed for this compiler and
2253 2) the LIBS variable (within the "optfile") specifies the correct
2254 NetCDF library to link against.
2255
2256 Due to this failure, the "profiles" package is now DISABLED.
2257 *********************************************************************
2258 EOF
2259 PACKAGES=`echo $PACKAGES | sed -e 's/profiles//g'`
2260 DISABLE="$DISABLE profiles"
2261 else
2262 # this prevent to add profiles (due to pdepend rules) if not available
2263 DISABLE="$DISABLE profiles"
2264 fi
2265 fi
2266
2267 # Check for package RADTRANS: if LAPACK is not available,
2268 # then issue a warning that the direct radtrans solver is not available.
2269 if test "x$HAVE_LAPACK" != xt ; then
2270 echo " $PACKAGES " | grep ' radtrans ' > /dev/null 2>&1
2271 RETVAL=$?
2272 if test "x$RETVAL" = x0 ; then
2273 cat <<EOF
2274 *********************************************************************
2275 WARNING: the "radtrans" package was enabled but tests failed to
2276 compile LAPACK applications. This means that the direct radtrans
2277 solver is not available and compilation will fail if it is enabled.
2278 If you want to use the direct solver, please check that:
2279
2280 1) LAPACK is correctly installed for this compiler and
2281 2) the LIBS variable (within the "optfile") specifies the correct
2282 LAPACK library to link against.
2283 *********************************************************************
2284 EOF
2285 fi
2286 fi
2287
2288 if test "x${PKG_DEPEND}" != x ; then
2289 echo " applying package dependency rules"
2290 ck=
2291 while test "x$ck" != xtt ; do
2292 i=0
2293 # rtot=${#PNAME[@]}
2294 rtot=$nname
2295 while test $i -le $rtot ; do
2296
2297 # Is $pname in the current $PACKAGES list?
2298 # pname=${PNAME[$i]}
2299 tmp="pname=\"\$PNAME_$i\""
2300 eval $tmp
2301 pin="f"
2302 for p in $PACKAGES ; do
2303 if test "x$p" = "x$pname" ; then
2304 pin="t"
2305 fi
2306 done
2307 # or in the current $STANDARDDIRS list?
2308 for p in $STANDARDDIRS ; do
2309 if test "x$p" = "x$pname" ; then pin="t" ; fi
2310 done
2311
2312 # Is the DNAME entry a (+) or (-) rule ?
2313 tmp="dname=\"\$DNAME_$i\""
2314 eval $tmp
2315 plus="-"
2316 echo $dname | grep '^+' > /dev/null 2>&1
2317 RETVAL=$?
2318 if test "x$RETVAL" = x0 ; then
2319 plus="+"
2320 fi
2321
2322 # Is $dname in the current $PACKAGES list?
2323 dname=`echo $dname | sed -e 's/^[+-]//'`
2324 din="f"
2325 for p in $PACKAGES ; do
2326 if test "x$p" = "x$dname" ; then
2327 din="t"
2328 fi
2329 done
2330
2331 # Do we need to add $dname according to the dependency rules?
2332 if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
2333 #echo " " $pname ": need to add :" $dname
2334 in_dis="f"
2335 for dis in $DISABLE ; do
2336 if test "x$dis" = "x$dname" ; then
2337 in_dis="t"
2338 fi
2339 done
2340 if test "x$in_dis" = xt ; then
2341 echo "Error: can't satisfy package dependencies:"
2342 echo " \"$dname\" is required by the dependency rules"
2343 echo " but is disallowed by the DISABLE settings"
2344 exit 1
2345 else
2346 PACKAGES="$PACKAGES $dname"
2347 ck=
2348 fi
2349 fi
2350
2351 # Do we need to get rid of $dname according to the dependency rules?
2352 if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
2353 echo "Error: can't satisfy package dependencies:"
2354 echo " \"$pname\" was requested but is disallowed by"
2355 echo " the dependency rules for \"$dname\""
2356 exit 1
2357 fi
2358 i=`echo "$i + 1" | bc -l`
2359 #i=$(( $i + 1 ))
2360 done
2361 ck=$ck"t"
2362 done
2363 echo " packages are: $PACKAGES"
2364 fi
2365 for i in $PACKAGES ; do
2366 adr="$ROOTDIR/pkg/$i"
2367 if test -d $adr ; then
2368 SOURCEDIRS="$SOURCEDIRS $adr"
2369 INCLUDEDIRS="$INCLUDEDIRS $adr"
2370 if test "x$i" = xautodiff ; then
2371 AUTODIFF_PKG_USED=t
2372 fi
2373 else
2374 echo "Error: the directory \"$adr\" for package $i doesn't exist"
2375 exit 1
2376 fi
2377 done
2378
2379 # Create a list of #define and #undef to enable/disable packages
2380 PACKAGES_DOT_H=PACKAGES_CONFIG.h
2381 # The following UGLY HACK sets multiple "#undef"s and it needs to go
2382 # away. On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
2383 # file would eventually be split up so that all package-related #define
2384 # statements could be separated and handled only by genmake.
2385 names=`ls -1 "$ROOTDIR/pkg"`
2386 all_pack=
2387 DISABLED_PACKAGES=
2388 for n in $names ; do
2389 if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
2390 has_pack="f"
2391 for pack in $PACKAGES ; do
2392 if test "x$pack" = "x$n" ; then
2393 has_pack="t"
2394 break
2395 fi
2396 done
2397 if test "x$has_pack" = xf ; then
2398 undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2399 DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
2400 fi
2401 fi
2402 done
2403 ENABLED_PACKAGES=
2404 for i in $PACKAGES ; do
2405 def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2406 ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
2407 #eh3 DEFINES="$DEFINES -D$def"
2408
2409 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
2410 case $i in
2411 aim_v23)
2412 ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
2413 echo "Warning: ALLOW_AIM is set to enable aim_v23."
2414 ;;
2415 esac
2416 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
2417
2418 done
2419
2420 echo " Adding STANDARDDIRS='$STANDARDDIRS'"
2421 BUILDDIR=${BUILDDIR:-.}
2422 if test "x$STANDARDDIRS" != x ; then
2423 for d in $STANDARDDIRS ; do
2424 adr="$ROOTDIR/$d/src"
2425 if test ! -d $adr ; then
2426 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2427 echo " is correct and that you correctly specified the STANDARDDIRS option"
2428 exit 1
2429 else
2430 SOURCEDIRS="$SOURCEDIRS $adr"
2431 fi
2432 adr="$ROOTDIR/$d/inc"
2433 if test ! -d $adr ; then
2434 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2435 echo " is correct and that you correctly specified the STANDARDDIRS option"
2436 exit 1
2437 else
2438 INCLUDEDIRS="$INCLUDEDIRS $adr"
2439 fi
2440 done
2441 fi
2442
2443 echo " Searching for *OPTIONS.h files in order to warn about the presence"
2444 echo " of \"#define \"-type statements that are no longer allowed:"
2445 CPP_OPTIONS=
2446 CPP_EEOPTIONS=
2447 spaths=". $INCLUDEDIRS"
2448 names=`ls -1 "$ROOTDIR/pkg"`
2449 for i in $spaths ; do
2450 try="$i/CPP_OPTIONS.h"
2451 if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
2452 echo " found CPP_OPTIONS=\"$try\""
2453 CPP_OPTIONS="$try"
2454 # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
2455 for n in $names ; do
2456 test_for_package_in_cpp_options $CPP_OPTIONS $n
2457 done
2458 fi
2459 try="$i/CPP_EEOPTIONS.h"
2460 if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
2461 echo " found CPP_EEOPTIONS=\"$try\""
2462 # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
2463 #**** not yet enabled ****
2464 # test_for_mpi_in_cpp_eeoptions $try
2465 #**** not yet enabled ****
2466 CPP_EEOPTIONS="$try"
2467 fi
2468 done
2469 if test "x$CPP_OPTIONS" = x ; then
2470 echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
2471 exit 1
2472 fi
2473
2474 # Here, we build the list of files to be "run through" the adjoint
2475 # compiler.
2476 if test -f ./adSrcFiles.tmp ; then
2477 rm -f ./adSrcFiles.tmp
2478 fi
2479 echo " Creating the list of files for the adjoint compiler."
2480 touch adSrcFiles.tmp
2481 for i in $SOURCEDIRS ; do
2482 list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
2483 for j in $list_files ; do
2484 cat $i/$j >> adSrcFiles.tmp
2485 done
2486 done
2487 if test ! "x"$FS = "x.f" ; then
2488 cat adSrcFiles.tmp | sed -e "s/\.f/.$FS/g" > adSrcFiles.tmp_f
2489 mv -f adSrcFiles.tmp_f adSrcFiles.tmp
2490 fi
2491
2492 echo
2493 echo "=== Creating the Makefile ==="
2494 echo " setting INCLUDES"
2495 for i in $INCLUDEDIRS ; do
2496 if test ! -d $i ; then
2497 echo "Warning: can't find INCLUDEDIRS=\"$i\""
2498 fi
2499 done
2500
2501 if test ! "x$DIVA" = x ; then
2502 echo " Creating the pseudo-MPI include directory"
2503 INCLUDES="-I./mpi_headers $INCLUDES"
2504 rm -rf ./mpi_headers
2505 mkdir -p ./mpi_headers
2506
2507 if test "x$MPIINCLUDEDIR" = x ; then
2508 if test "x$MPIHOME" = x ; then
2509 MPIHOME='/usr'
2510 fi
2511 MPIINCLUDEDIR='$MPIHOME/include'
2512 fi
2513
2514 if test -r $MPIINCLUDEDIR/mpif.h ; then
2515 for i in $MPI_HEADER_FILES; do
2516 cp -p $MPIINCLUDEDIR/$i ./mpi_headers
2517 done
2518
2519 perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h
2520 else
2521 echo " We cannot create a copy of mpif.h!"
2522 # exit -1
2523 fi
2524 fi
2525
2526 echo " Determining the list of source and include files"
2527 rm -rf .links.tmp
2528 mkdir .links.tmp
2529 touch .links.tmp/foo
2530 if test ! -r ".links.tmp/foo" ; then
2531 echo
2532 echo "ERROR : something is wrong with your directory permissions or"
2533 echo " your user file-creation mask (\"umask\") since creating a"
2534 echo " sub-dir, touch-ing a file within it, and then reading it is"
2535 echo " not working. Please try setting your umask to something"
2536 echo " sane such as:"
2537 echo
2538 echo " umask 0002"
2539 echo
2540 echo " and please verify that you have the proper permissions for"
2541 echo " creating sub-directories and then reading files created"
2542 echo " within them."
2543 echo
2544 exit 1
2545 fi
2546 rm -f .links.tmp/foo
2547
2548 if test "x$OPENAD" != x ; then
2549 OAD_DONT_COMPILE="/dev/null"
2550 OAD_DONT_TRANSFORM="/dev/null"
2551 OAD_KEEP_ORIGINAL="/dev/null"
2552 OAD_CB2M_FILES="/dev/null"
2553 OADTOOLS="$TOOLSDIR/OAD_support"
2554 test -f "oadtempflile" && \rm -f "oadtempflile"
2555 cat >> "oadtempflile" <<EOF
2556 $OADTOOLS
2557 EOF
2558 echo " looking for dontCompile file: "
2559 for i in "." $MODS ; do
2560 if test -r $i"/dontCompile" ; then
2561 OAD_DONT_COMPILE=$i"/dontCompile"
2562 echo " found $OAD_DONT_COMPILE"
2563 break
2564 fi
2565 done
2566 echo " looking for dontTransform file: "
2567 for i in "." $MODS ; do
2568 if test -r $i"/dontTransform" ; then
2569 OAD_DONT_TRANSFORM=$i"/dontTransform"
2570 echo " found $OAD_DONT_TRANSFORM"
2571 break
2572 fi
2573 done
2574 echo " looking for keepOriginal file: "
2575 for i in "." $MODS ; do
2576 if test -r $i"/keepOriginal" ; then
2577 OAD_KEEP_ORIGINAL=$i"/keepOriginal"
2578 echo " found $OAD_KEEP_ORIGINAL"
2579 break
2580 fi
2581 done
2582 echo " looking for cb2mFiles: "
2583 for i in "." $MODS ; do
2584 if test -r $i"/cb2mFiles" ; then
2585 OAD_CB2M_FILES=$i"/cb2mFiles"
2586 echo " found $OAD_CB2M_FILES"
2587 break
2588 fi
2589 done
2590 echo " OpenAD exceptions: "
2591 fi
2592
2593 echo "# This section creates symbolic links" > srclinks.tmp
2594 echo "" >> srclinks.tmp
2595 printf 'F77_SRC_FILES = ' > F77srclist.tmp
2596 printf 'NON_AD_F77_SRC_FILES = ' > nonADF77srclist.tmp
2597 printf 'C_SRC_FILES = ' > csrclist.tmp
2598 printf 'F90_SRC_FILES = ' > F90srclist.tmp
2599 printf 'H_SRC_FILES = ' > hsrclist.tmp
2600 printf 'AD_FLOW_FILES = ' > ad_flow_files.tmp
2601 alldirs="$SOURCEDIRS $INCLUDEDIRS ."
2602 for d in $alldirs ; do
2603 deplist=
2604 sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
2605 sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
2606 if test "x$OPENAD" != x ; then
2607 sfiles=`( echo $sfiles | grep -v _cb2m\. )`
2608 fi
2609 for sf in $sfiles ; do
2610 if test ! -r ".links.tmp/$sf" ; then
2611 if test -f "$d/$sf" ; then
2612 ignore_f=f
2613 case $d/$sf in
2614 ./$PACKAGES_DOT_H)
2615 ignore_f=t
2616 ;;
2617 ./AD_CONFIG.h)
2618 ignore_f=t
2619 ;;
2620 ./FC_NAMEMANGLE.h)
2621 ignore_f=t
2622 ;;
2623 ./BUILD_INFO.h)
2624 ignore_f=t
2625 ;;
2626 ./EMBEDDED_FILES.h)
2627 ignore_f=t
2628 ;;
2629 *)
2630 # For the local directory *ONLY*,
2631 # ignore all soft-links
2632 if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
2633 ignore_f=t
2634 else
2635 touch .links.tmp/$sf
2636 deplist="$deplist $sf"
2637 fi
2638 ;;
2639 esac
2640 if test "x$ignore_f" = xf ; then
2641 extn=`echo $sf | $AWK -F. '{print $NF}'`
2642 case $extn in
2643 F)
2644 echo " \\" >> F77srclist.tmp
2645 printf " $sf" >> F77srclist.tmp
2646 if test "x$OPENAD" != x ; then
2647 basename=${sf%%.F}
2648 isAD=`egrep ^$basename.f'[ ]*' adSrcFiles.tmp`
2649 if test -z "$isAD" ; then
2650 toBeIgnored=`egrep ^$basename'[ ]*' ${OAD_DONT_COMPILE}`
2651 if test -z "$toBeIgnored" ; then
2652 echo " \\" >> nonADF77srclist.tmp
2653 printf " $sf" >> nonADF77srclist.tmp
2654 else
2655 echo " not to be compiled : $sf"
2656 fi
2657 else # file is initially listed as an AD file we want to exclude it
2658 # or we want to retain the untransformed version
2659 notToBeTransformed=`egrep ^$basename'[ ]*' ${OAD_DONT_TRANSFORM}`
2660 untransformedVersionToBeKept=`egrep ^$basename'[ ]*' ${OAD_KEEP_ORIGINAL}`
2661 if test -n "$notToBeTransformed"; then
2662 echo " not to be transformed: $sf"
2663 fi
2664 if test -n "$untransformedVersionToBeKept" ; then
2665 echo " original to be kept : $sf"
2666 fi
2667 if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then
2668 echo " \\" >> nonADF77srclist.tmp
2669 printf " $sf" >> nonADF77srclist.tmp
2670 fi
2671 fi
2672 fi
2673 ;;
2674 F90)
2675 echo " \\" >> F90srclist.tmp
2676 printf " $sf" >> F90srclist.tmp
2677 ;;
2678 c)
2679 echo " \\" >> csrclist.tmp
2680 printf " $sf" >> csrclist.tmp
2681 ;;
2682 h)
2683 echo " \\" >> hsrclist.tmp
2684 printf " $sf" >> hsrclist.tmp
2685 ;;
2686 flow)
2687 echo " \\" >> ad_flow_files.tmp
2688 printf " $sf" >> ad_flow_files.tmp
2689 ;;
2690 esac
2691 fi
2692 fi
2693 fi
2694 done
2695 if test "x$deplist" != x ; then
2696 if test "$d" != "." ; then
2697 echo "" >> srclinks.tmp
2698 echo "# These files are linked from $d" >> srclinks.tmp
2699 echo "$deplist :" >> srclinks.tmp
2700 # We need to make sure that the link isn't already there.
2701 # This may happen when make thinks that a header file has to be "remade"
2702 # because a module it depends on has changed. In this case we do nothing.
2703 printf "\tif [ ! -L \$@ ]; then \$(LN) %s/\$@ \$@; fi\n" $d >> srclinks.tmp
2704 fi
2705 fi
2706 done
2707 rm -rf .links.tmp
2708 echo "" >> F77srclist.tmp
2709 echo "" >> nonADF77srclist.tmp
2710 echo "" >> csrclist.tmp
2711 echo "" >> F90srclist.tmp
2712 echo "" >> hsrclist.tmp
2713 echo "" >> ad_flow_files.tmp
2714
2715 CMDLINE=$0
2716 for xx in "$@" ; do nw=`echo $xx | wc -w`
2717 if test $nw = '1' ; then CMDLINE="$CMDLINE $xx"
2718 else CMDLINE="$CMDLINE '$xx'" ; fi
2719 done
2720
2721 if test -f $MAKEFILE ; then
2722 mv -f $MAKEFILE "$MAKEFILE.old"
2723 fi
2724 echo " Writing makefile: $MAKEFILE"
2725 echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
2726 echo "# $MACHINE" >> $MAKEFILE
2727 echo "# This makefile was generated automatically on" >> $MAKEFILE
2728 echo "# $THISDATE" >> $MAKEFILE
2729 echo "# by the command:" >> $MAKEFILE
2730 echo "# $CMDLINE" >> $MAKEFILE
2731 echo "# executed by:" >> $MAKEFILE
2732 echo "# ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
2733
2734 EXE_AD=$EXECUTABLE"_ad"
2735 EXE_FTL=$EXECUTABLE"_ftl"
2736 EXE_SVD=$EXECUTABLE"_svd"
2737
2738 cat >>$MAKEFILE <<EOF
2739 #
2740 # OPTFILE="$OPTFILE"
2741 #
2742 # BUILDDIR : Directory where object files are written
2743 # SOURCEDIRS : Directories containing the source (.F) files
2744 # INCLUDEDIRS : Directories containing the header-source (.h) files
2745 # EXEDIR : Directory where executable that is generated is written
2746 # EXECUTABLE : Full path of executable binary
2747 #
2748 # CPP : C-preprocessor command
2749 # INCLUDES : Directories searched for header files
2750 # DEFINES : Macro definitions for CPP
2751 # MAKEDEPEND : Dependency generator
2752 # FC : Fortran compiler command
2753 # FFLAGS : Configuration/debugging options for FC
2754 # FOPTIM : Optimization options for FC
2755 # LINK : Command for link editor program
2756 # LIBS : Library flags /or/ additional optimization/debugging flags
2757
2758 ROOTDIR = ${ROOTDIR}
2759 BUILDDIR = ${BUILDDIR}
2760 SOURCEDIRS = ${SOURCEDIRS}
2761 INCLUDEDIRS = ${INCLUDEDIRS}
2762 EXEDIR = ${EXEDIR}
2763 EXECUTABLE = \$(EXEDIR)/${EXECUTABLE}
2764 TOOLSDIR = ${TOOLSDIR}
2765 OADTOOLS = ${OADTOOLS}
2766
2767 #eh3 new defines for the adjoint work
2768 AUTODIFF = ${ROOTDIR}/pkg/autodiff
2769 EXE_AD = ${EXE_AD}
2770 EXE_FTL = ${EXE_FTL}
2771 EXE_SVD = ${EXE_SVD}
2772
2773 ENABLED_PACKAGES = ${ENABLED_PACKAGES}
2774 DISABLED_PACKAGES = ${DISABLED_PACKAGES}
2775
2776 # These files are created by Makefile
2777 SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
2778 EOF
2779
2780 if test "x$EMBED_SRC" = xt ; then
2781 echo "EMBEDDED_FILES = EMBEDDED_FILES.h" >>$MAKEFILE
2782 else
2783 echo "EMBEDDED_FILES = " >>$MAKEFILE
2784 fi
2785
2786 # extract default cpp search path so we can pass it to makedepend
2787 CPPINCLUDES=`cat /dev/null | $CPP -v 2>&1 | awk '/^End of search/{f=0}!/^\#/{if(f){printf " -I%s", $1;}}/^\#include "..." search start/{f=1}'`
2788
2789 cat >>$MAKEFILE <<EOF
2790 # Unix ln (link)
2791 LN = ${LN}
2792 # Dependency generator
2793 MAKEDEPEND = ${MAKEDEPEND}
2794 # Special preprocessor (KAP on DECs, FPP on Crays)
2795 KPP = ${KPP}
2796 # Fortran compiler
2797 FC = ${FC}
2798 # Fortran compiler
2799 F90C = ${F90C}
2800 # C compiler
2801 CC = ${CC}
2802 # Link editor
2803 LINK = ${LINK} ${LDADD}
2804
2805 # Defines for CPP
2806 DEFINES = ${DEFINES}
2807 # Includes for CPP
2808 INCLUDES = ${INCLUDES}
2809 # default CPP includes for makedepend
2810 CPPINCLUDES = ${CPPINCLUDES}
2811 # Flags for KPP
2812 KFLAGS1 = ${KFLAGS1}
2813 KFLAGS2 = ${KFLAGS2}
2814 # Optim./debug for FC
2815 FFLAGS = ${FFLAGS} ${FEXTRAFLAGS}
2816 FOPTIM = ${FOPTIM}
2817 # Optim./debug for FC
2818 F90FLAGS = ${F90FLAGS}
2819 F90OPTIM = ${F90OPTIM}
2820 F90FIXEDFORMAT = ${F90FIXEDFORMAT}
2821 # Flags for CC
2822 CFLAGS = ${CFLAGS}
2823 # Files that should not be optimized
2824 NOOPTFILES = ${NOOPTFILES}
2825 NOOPTFLAGS = ${NOOPTFLAGS}
2826 # Flags and libraries needed for linking
2827 LIBS = ${LIBS}
2828 # Name of the makefile
2829 MAKEFILE = ${MAKEFILE}
2830 # Name of the make program
2831 MAKE = ${MAKE}
2832
2833 EOF
2834
2835 cat F77srclist.tmp >> $MAKEFILE
2836 cat nonADF77srclist.tmp >> $MAKEFILE
2837 cat csrclist.tmp >> $MAKEFILE
2838 cat F90srclist.tmp >> $MAKEFILE
2839 cat hsrclist.tmp >> $MAKEFILE
2840 cat ad_flow_files.tmp >> $MAKEFILE
2841
2842 rm -f F77srclist.tmp nonADF77srclist.tmp csrclist.tmp F90srclist.tmp hsrclist.tmp ad_flow_files.tmp
2843
2844 echo >> $MAKEFILE
2845
2846 # add definitions for preprocessed sources
2847 # and note that not all systems allow case sensitive extensions
2848 # hence the $FS and $FS90 here.
2849 # for fixed format f90 files we use ff90 or FF90 resp
2850 # but these are not expected to be the original source files
2851
2852 echo 'F77_PP_SRC_FILES = $(F77_SRC_FILES:.F=.'$FS')' >> $MAKEFILE
2853 echo 'F90_PP_SRC_FILES = $(F90_SRC_FILES:.F90=.'$FS90')' >> $MAKEFILE
2854 echo 'OBJFILES= $(F77_SRC_FILES:.F=.o) $(C_SRC_FILES:.c=.o) $(F90_SRC_FILES:.F90=.o)' >> $MAKEFILE
2855 echo 'FLOWFILES = $(AD_FLOW_FILES:.flow=.flowdir)' >> $MAKEFILE
2856 echo >> $MAKEFILE
2857 echo '.SUFFIXES:' >> $MAKEFILE
2858 echo '.SUFFIXES: .o .'$FS' .p .F .c .f'$FS90' .'$FS90' .FF90 .F90 .flowdir .flow' >> $MAKEFILE
2859
2860 cat >>$MAKEFILE <<EOF
2861
2862 all: fwd_exe_target
2863 fwd_exe_target:
2864 @echo Update AD_CONFIG.h and make \$(EXECUTABLE)
2865 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Forward version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
2866 @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
2867 @-rm -f ad_config.template
2868 \$(MAKE) -f \$(MAKEFILE) \$(EXECUTABLE)
2869
2870 \$(EXECUTABLE): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(OBJFILES) \$(EMBEDDED_FILES)
2871 @echo Creating \$@ ...
2872 \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2873
2874 depend:
2875 @\$(MAKE) -f \$(MAKEFILE) links
2876 \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(CPPINCLUDES) \$(F77_SRC_FILES)
2877 \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2878 -rm -f makedepend.out
2879
2880 lib: libmitgcmuv.a
2881
2882 libmitgcmuv.a: \$(OBJFILES)
2883 ar rcv libmitgcmuv.a \$(OBJFILES)
2884 ar d libmitgcmuv.a main.o
2885
2886 obj: \$(OBJFILES)
2887
2888 links: \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(SPECIAL_FILES)
2889
2890 small_f: \$(F77_PP_SRC_FILES) \$(F90_PP_SRC_FILES)
2891
2892 output.txt: \$(EXECUTABLE)
2893 @printf 'running ... '
2894 @\$(EXECUTABLE) > \$@
2895
2896 # remove most of the files that "make" generates
2897 clean:
2898 -rm -rf *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
2899 -rm -rf *.o
2900 -rm -rf *.$FS *.flowdir
2901 -rm -rf *.f$FS90 \$(AD_CLEAN) ad_input*
2902
2903 # remove most of the files that "make" and "make depend" generate
2904 Clean:
2905 @\$(MAKE) -f \$(MAKEFILE) clean
2906 @\$(MAKE) -f \$(MAKEFILE) cleanlinks
2907 -rm -f \$(SPECIAL_FILES) f90mkdepend.log $MAKEFILE.old
2908 -rm -f taf_command taf_output taf_ad.log taf_ad_flow.log taf_ftl.log
2909 -rm -f genmake_warnings genmake_errors make.log
2910
2911 # remove also the executable, files that "genmake2" generates (except Makefile)
2912 # and output from a run (plus log files from testreport)
2913 CLEAN:
2914 @\$(MAKE) -f \$(MAKEFILE) Clean
2915 -rm -f \$(EXECUTABLE) \$(EXE_AD) \$(EXE_FTL) *.bak
2916 -rm -f $LOGFILE genmake_state genmake_*optfile
2917 -rm -f SIZE.h.mpi genmake.tr_log make.tr_log
2918 -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2919 -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2920 -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2921 -rm -f *.txt STD* *diagnostics.log datetime
2922 -rm -f *_MIT_CE_000.opt0000 costfunction*0000
2923 -rm -rf mnc_test_*
2924
2925 makefile:
2926 $THIS_SCRIPT $G2ARGS
2927 cleanlinks:
2928 -find . -type l -exec rm {} \;
2929
2930 # Special targets (SPECIAL_FILES) which are created by make
2931 ${PACKAGES_DOT_H}:
2932 @echo Creating \$@ ...
2933 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@
2934 AD_CONFIG.h:
2935 @echo Creating \$@ ...
2936 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Default version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > \$@
2937 FC_NAMEMANGLE.h:
2938 @echo Creating \$@ ...
2939 echo "$FC_NAMEMANGLE" > \$@
2940
2941 BUILD_INFO.h:
2942 @echo Creating \$@ ...
2943 EOF
2944
2945 test ! "x$THISVER" = x && echo " -echo \"#define THISVER '$THISVER'\" > \$@" >> $MAKEFILE
2946 test ! "x$THISUSER" = x && echo " -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
2947 test ! "x$THISDATE" = x && echo " -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2948 test ! "x$THISHOST" = x && echo " -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2949
2950 if test "x$EMBED_SRC" = xt ; then
2951 cat >>$MAKEFILE <<EOF
2952
2953 decode_files.o : EMBEDDED_FILES.h
2954
2955 ## \$(F77_PP_SRC_FILES)
2956 all_fF.tar.gz : \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
2957 @echo Creating \$@ ...
2958 -tar -hcf all_fF.tar \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
2959 -rm -f all_fF.tar.gz
2960 -gzip all_fF.tar
2961
2962 EMBEDDED_FILES.h : all_fF.tar.gz
2963 @echo Creating \$@ ...
2964 -\${ROOTDIR}/tools/embed_encode/encode_files EMBEDDED_FILES.h all_fF.tar.gz
2965
2966 EOF
2967 fi
2968
2969 cat >>$MAKEFILE <<EOF
2970
2971 # The normal chain of rules is ( .F - .$FS - .o )
2972
2973 ## This nullifies any default implicit rules concerning these two file types:
2974 ## %.o : %.F
2975
2976 # C preprocessing and replacing the _d in constants:
2977 CPPCMD = cat \$< | ${CPP} \$(DEFINES) \$(INCLUDES) | ${S64}
2978
2979 .F.$FS:
2980 \$(CPPCMD) > \$@
2981 .$FS.o:
2982 \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2983 .F.o:
2984 \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2985 .F90.$FS90:
2986 \$(CPPCMD) > \$@
2987 .FF90.f$FS90:
2988 \$(CPPCMD) > \$@
2989 .$FS90.o:
2990 \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
2991 .f$FS90.o:
2992 cp \$< \$(basename \$<).f90
2993 \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$(F90FIXEDFORMAT) \$(basename \$<).f90
2994 .c.o:
2995 \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$<
2996 .flow.flowdir:
2997 \$(CPPCMD) > \$@
2998
2999 # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
3000 .F.p:
3001 \$(CPPCMD) > \$@
3002 .p.$FS:
3003 \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
3004
3005 EOF
3006
3007 #=========================================
3008 #=== Automatic Differentiation Rules ===
3009 #=== for TAMC/TAF ======================
3010
3011 if test "x$OPENAD" = x ; then
3012
3013 cat >>$MAKEFILE <<EOF
3014
3015 TAMC = ${TAMC}
3016 TAF = ${TAF}
3017
3018 TAF_EXTRA = ${TAF_EXTRA}
3019 TAMC_EXTRA = ${TAMC_EXTRA}
3020
3021 EOF
3022
3023 ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
3024 ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
3025 ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
3026 for i in $ad_vars ; do
3027 name=$i
3028 t1="t2=\$"`echo "$i"`
3029 eval $t1
3030 printf "%-20s = " $name >> $MAKEFILE
3031 echo "$t2" | sed -e 's| \+| |g' >> $MAKEFILE
3032 done
3033
3034 echo " Add the source list for AD code generation"
3035 echo >> $MAKEFILE
3036 printf "AD_FILES = " >> $MAKEFILE
3037 AD_FILES=`cat adSrcFiles.tmp`
3038 for i in $AD_FILES ; do
3039 echo " \\" >> $MAKEFILE
3040 printf " $i" >> $MAKEFILE
3041 done
3042 echo >> $MAKEFILE
3043 rm -f adSrcFiles.tmp
3044
3045 cat >>$MAKEFILE <<EOF
3046
3047 # ... AD ...
3048 adall: ad_exe_target
3049 adtaf: ad_taf_output.$FS
3050 adtamc: ad_tamc_output.$FS
3051
3052 ad_exe_target:
3053 @echo Update AD_CONFIG.h and make \$(EXE_AD)
3054 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3055 @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3056 @-rm -f ad_config.template
3057 \$(MAKE) -f \$(MAKEFILE) \$(EXE_AD)
3058
3059 ad_input_code.$FS: \$(AD_FILES) \$(AD_FLOW_FILES)
3060 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3061 cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3062 @-rm -f ad_config.template
3063 @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3064 @\$(MAKE) -f \$(MAKEFILE) \$(FLOWFILES)
3065 cat \$(FLOWFILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ad_input_code.$FS
3066
3067 ad_taf_output.$FS: ad_input_code.$FS
3068 \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3069 ls -l ad_input_code_ad.$FS
3070 cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
3071
3072 adtafonly:
3073 \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3074 ls -l ad_input_code_ad.$FS
3075 cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
3076
3077 \$(EXE_AD): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) ad_taf_output.o \$(OBJFILES) \$(EMBEDDED_FILES)
3078 \$(LINK) -o \${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
3079
3080 ad_tamc_output.$FS: ad_input_code.$FS
3081 \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
3082 cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
3083
3084 ad_tamc: ad_tamc_output.o \$(OBJFILES)
3085 \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
3086
3087 adonlyfwd:
3088 patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
3089
3090 adtrick:
3091 patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
3092
3093 adobj: ad_taf_output.o \$(OBJFILES)
3094
3095 # ... FTL ...
3096 ftlall: ftl_exe_target
3097 ftltaf: ftl_taf_output.$FS
3098 ftltamc: ftl_tamc_output.$FS
3099
3100 ftl_exe_target:
3101 @echo Update AD_CONFIG.h and make \$(EXE_FTL)
3102 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3103 @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3104 @-rm -f ad_config.template
3105 \$(MAKE) -f \$(MAKEFILE) \$(EXE_FTL)
3106
3107 ftl_input_code.$FS: \$(AD_FILES)
3108 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3109 cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3110 @-rm -f ad_config.template
3111 @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3112 @\$(MAKE) -f \$(MAKEFILE) \$(AD_FLOW_FILES)
3113 cat \$(AD_FLOW_FILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ftl_input_code.$FS
3114
3115 ftl_taf_output.$FS: ftl_input_code.$FS
3116 \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3117 ls -l ftl_input_code_ftl.$FS
3118 cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3119
3120 ftltafonly:
3121 \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3122 ls -l ftl_input_code_ftl.$FS
3123 cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3124
3125 \$(EXE_FTL): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) ftl_taf_output.o \$(OBJFILES) \$(EMBEDDED_FILES)
3126 \$(LINK) -o \${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
3127
3128 ftl_tamc_output.$FS: ftl_input_code.$FS
3129 \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
3130 cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
3131
3132 ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
3133 \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
3134
3135 # ... SVD ...
3136 svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
3137 @echo "--->>> Only ran TAF to generate SVD code! <<<---"
3138 @echo "--->>> Do make svdall afterwards to compile. <<<---"
3139 svdall: svd_touch svd_taf
3140
3141 svd_taf: \$(OBJFILES)
3142 \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
3143
3144 @echo "--->>> Only COMPILE svd code! <<<---"
3145 @echo "--->>> Assumes you previously <<<---"
3146 @echo "--->>> did make svdtaf <<<---"
3147
3148 svd_touch:
3149 @echo "--->>> Only COMPILE svd code! <<<---"
3150 @echo "--->>> Assumes you previously <<<---"
3151 @echo "--->>> did make svdtaf <<<---"
3152 touch ad_taf_output.$FS ftl_taf_output.$FS
3153 \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
3154 \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
3155 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "SVD version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3156 cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3157 @-rm -f ad_config.template
3158
3159 EOF
3160
3161 fi
3162
3163 #=== for OpenAD ========================
3164
3165 if test "x$OPENAD" != x ; then
3166
3167 # ============ begin OpenAD specific section ==============
3168
3169 cat >>$MAKEFILE <<EOF
3170
3171 # all the source files linked from the various locations:
3172 ALL_LINKED_FILES= \
3173 \$(F77_SRC_FILES) \
3174 \$(C_SRC_FILES) \
3175 \$(H_SRC_FILES) \
3176 \$(F90_SRC_FILES) \
3177 \$(SPECIAL_FILES)
3178
3179 ifndef OPENADROOT
3180 \$(error "Error: environment variable OPENADROOT not defined!")
3181 endif
3182
3183 ifndef XAIFSCHEMAROOT
3184 \$(error "Error: environment variable XAIFSCHEMAROOT not defined!")
3185 endif
3186
3187 ifndef XAIFBOOSTERROOT
3188 \$(error "Error: environment variable XAIFBOOSTERROOT not defined!")
3189 endif
3190
3191 EOF
3192
3193 echo " Add the source list for common block to module conversion "
3194 echo >> $MAKEFILE
3195 printf "CB2M_F90_SRC_NAMES = " >> $MAKEFILE
3196 for i in `cat ${OAD_CB2M_FILES}` ; do
3197 echo " \\" >> $MAKEFILE
3198 printf " $i" >> $MAKEFILE
3199 done
3200 echo >> $MAKEFILE
3201
3202 echo " Add the source list for AD code generation"
3203 echo >> $MAKEFILE
3204 printf "AD_FILES = " >> $MAKEFILE
3205 for i in `cat ${OAD_CB2M_FILES}` ; do
3206 echo " \\" >> $MAKEFILE
3207 printf " ${i}_mod.f$FS90" >> $MAKEFILE
3208 done
3209 AD_FILES=`cat adSrcFiles.tmp`
3210 for i in $AD_FILES ; do
3211 basename=${i%%.f}
3212 toBeIgnored=`egrep ^$basename'[ ]*' ${OAD_DONT_COMPILE} ${OAD_DONT_TRANSFORM}`
3213 if test -z "$toBeIgnored" ; then
3214 echo " \\" >> $MAKEFILE
3215 printf " $i" >> $MAKEFILE
3216 fi
3217 done
3218 echo >> $MAKEFILE
3219 rm -f adSrcFiles.tmp
3220
3221 cat >>$MAKEFILE <<EOF
3222
3223 adAll: \$(EXE_AD)
3224 .PHONY: adAll
3225
3226 CB2M_F90_PP_SRC_FILES=\$(addsuffix _mod.f$FS90, \$(CB2M_F90_SRC_NAMES))
3227
3228 .PRECIOUS: \$(CB2M_F90_PP_SRC_FILES) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90)
3229
3230 .PHONY: adDepend
3231 adDepend: \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(addsuffix _mod.FF90, \$(CB2M_F90_SRC_NAMES)) \$(F77_SRC_FILES:.F=_cb2m.FF90)
3232 \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
3233 \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
3234 -rm -f makedepend.out
3235
3236 OPENAD_SUPPORT_F90_SRC_FILES = \
3237 w2f__types.F90 \
3238 OAD_active.F90 \
3239 OAD_cp.F90 \
3240 OAD_rev.F90 \
3241 OAD_tape.F90 \
3242 revolve.F90
3243
3244 OPENAD_SUPPORT_C_SRC_FILES = \
3245 iaddr.c \
3246 timeRatio.c
3247
3248 f95_test_mods.f90: \$(OPENAD_SUPPORT_F90_SRC_FILES:F90=$FS90)
3249 cat \$^ > \$@
3250
3251 f95_test.f90: all_mods.xb.x2w.w2f.pp.f$FS90 \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90) ad_input_code.w2f.pre.xb.x2w.w2f.td.pp.f$FS90
3252 cat \$^ > \$@
3253
3254 f95_test.out: f95_test_mods.f90 f95_test.f90
3255 f95 -fixed -w=unused -maxcontin=132 -c f95_test_mods.f90 > \$@ 2>&1
3256 f95 -fixed -w=unused -maxcontin=132 -c -fixed f95_test.f90 >> \$@ 2>&1
3257
3258 CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.f$FS90)
3259
3260 AD_OBJ_FILES_S1=\$(OPENAD_SUPPORT_F90_SRC_FILES:.F90=.o) \$(OPENAD_SUPPORT_C_SRC_FILES:.c=.o) OAD_intrinsics_oad.o \$(CB2M_AD_FILES:.f$FS90=_oad.o)
3261
3262 AD_OBJ_FILES_S2=\$(AD_OBJ_FILES_S1) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.o) \$(C_SRC_FILES:.c=.o) \$(F90_SRC_FILES:.F90=.o)
3263
3264 \$(EXE_AD): \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) postProcess.tag \$(AD_OBJ_FILES_S2)
3265 \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES_S2) \$(LIBS)
3266
3267 # create sources files modules from header files containing common blocks
3268 %_mod.FF90 : %.h \${OADTOOLS}/cb2mGetModules.csh \${OADTOOLS}/cb2mGetModules.awk
3269 \${OADTOOLS}/cb2mGetModules.csh $< \${OADTOOLS}/cb2mGetModules.awk
3270
3271 # create new header files with USE statements for the new modules made above
3272 %_mod.h : %.h \${OADTOOLS}/cb2mGetHeaders.csh \${OADTOOLS}/cb2mGetHeaders.awk
3273 \${OADTOOLS}/cb2mGetHeaders.csh $< \${OADTOOLS}/cb2mGetHeaders.awk \$(CB2M_F90_SRC_NAMES)
3274
3275 # change the include directives of everybody to refer to the new header files with the USE statements
3276 %_cb2m.FF90 : %.F \${OADTOOLS}/cb2mUseModules.bash
3277 \${OADTOOLS}/cb2mUseModules.bash $< ${MPI}
3278
3279 # makefile debug rule
3280 small_f: \$(CB2M_F90_PP_SRC_FILES)
3281 .PHONY: small_f
3282
3283 ad_output.txt: \$(EXE_AD)
3284 @printf 'linking data files ... '
3285 \$(LN) -f ../input_ad/data* ../input_ad/eedata .
3286 \$(LN) -f ../../global_ocean.90x40x15/input/*.bin .
3287 @printf 'running ... '
3288 @./\$(EXE_AD) > \$@
3289
3290 ad_input_code.f$FS90: \$(CB2M_AD_FILES)
3291 cat \$^ > \$@
3292
3293 # canonicalizer
3294 ad_input_code_sf.pre.f90 : \$(CB2M_AD_FILES)
3295 \${OPENADFORTTK_BASE}/tools/SourceProcessing/preProcess.py --timing --r8 -H -S -o \$@ \$^
3296
3297 # replace stop statements (to avoid the implied unstructured control flow) with print statements
3298 ad_input_code_sf.pre.s2p.f90 : ad_input_code_sf.pre.f90
3299 cat \$< | sed -f \${OADTOOLS}/stop2print.sed > ad_input_code_sf.pre.s2p.f90
3300
3301 # F -> WHIRL
3302 ad_input_code_sf.pre.s2p.B: ad_input_code_sf.pre.s2p.f90
3303 \${OPEN64ROOT}/crayf90/sgi/mfef90 -r8 -z -F ad_input_code_sf.pre.s2p.f90
3304
3305 # WHIRL -> XAIF
3306 ad_input_code_sf.pre.s2p.xaif : ad_input_code_sf.pre.s2p.B
3307 \${OPENADFORTTK}/bin/whirl2xaif -s -n --debug 1 -o \$@ \$<
3308
3309 # XAIF -> XAIF'
3310 ad_input_code_sf.pre.s2p.xb.xaif : ad_input_code_sf.pre.s2p.xaif xaif.xsd xaif_base.xsd xaif_inlinable_intrinsics.xsd xaif_derivative_propagator.xsd xaif_output.xsd
3311 \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/driver/oadDriver -f -t forward_step -i \$< -c \${XAIFSCHEMAROOT}/schema/examples/inlinable_intrinsics.xaif -o \$@ -I -r
3312
3313 # XAIF' -> WHIRL'
3314 ad_input_code_sf.pre.s2p.xb.x2w.B : ad_input_code_sf.pre.s2p.xb.xaif
3315 \${OPENADFORTTK}/bin/xaif2whirl --debug 1 ad_input_code_sf.pre.s2p.B \$<
3316
3317 # WHIRL' -> F'
3318 ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS90: ad_input_code_sf.pre.s2p.xb.x2w.B
3319 \${OPEN64ROOT}/whirl2f/whirl2f -FLIST:ftn_file=\$@ -openad \$<
3320
3321 # insert template directives
3322 ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90: ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS90 \${OADTOOLS}/insertTemplateDir.bash
3323 \${OADTOOLS}/insertTemplateDir.bash \$< \$@
3324
3325 PPEXTRAS=\$(wildcard \${OADTOOLS}/ad_template.*.F) \${OADTOOLS}/ad_inline.F
3326 # postprocess F'
3327 postProcess.tag: ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90 \$(PPEXTRAS:.F=.f) | w2f__types.f90
3328 \${OPENADFORTTK_BASE}/tools/SourceProcessing/postProcess.py --progress --timing --infoUnitFile w2f__types.f90 --outputFormat=fixed --separateOutput --pathSuffix "" --filenameSuffix "_oad" -m r -i \${OADTOOLS}/ad_inline.f \$<
3329 # the target is a placeholder to trigger a single execution of the rule
3330 touch \$@
3331 # put this so make knows about the postprocessing output
3332 OAD_intrinsics_oad.f \$(CB2M_AD_FILES:.f$FS90=_oad.f): postProcess.tag
3333
3334 # link the XAIF schema files
3335 %.xsd:
3336 \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ .
3337
3338 # link the support files:
3339 \$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES):
3340 \$(LN) \${OADTOOLS}/\$@ .
3341
3342 AD_CLEAN += *_mod.h *_mod.F90 *.FF90 *.mod-whirl temp.sed oad_cp.* postProcess.tag \$(PPEXTRAS:.F=.f)
3343
3344 # ============ end OpenAD specific section ==============
3345
3346 EOF
3347
3348 fi
3349
3350 #=========================================
3351
3352 if test "x$EXEHOOK" != x ; then
3353 printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
3354 fi
3355
3356 echo " Making list of \"exceptions\" that need \".p\" files"
3357 for i in $KPPFILES ; do
3358 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
3359 RETVAL=$?
3360 if test "x$RETVAL" != x0 ; then
3361 echo "Error: unable to add file \"$i\" to the exceptions list"
3362 fi
3363 echo "$base.$FS: $base.p" >> $MAKEFILE
3364 done
3365
3366 echo " Making list of NOOPTFILES"
3367 for i in $NOOPTFILES ; do
3368 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
3369 RETVAL=$?
3370 if test "x$RETVAL" != x0 ; then
3371 echo "Error: unable to add file \"$i\" to the exceptions list"
3372 fi
3373 echo "$base.o: $base.$FS" >> $MAKEFILE
3374 printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
3375 done
3376
3377 echo " Add rules for links"
3378 cat srclinks.tmp >> $MAKEFILE
3379 rm -f srclinks.tmp
3380
3381 echo " Adding makedepend marker"
3382 printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
3383
3384 printf "\n=== Done ===\n"
3385
3386 # Create special header files
3387 $BASH $TOOLSDIR/convert_cpp_cmd2defines -bPACKAGES_CONFIG_H "Disabled packages:" $DISABLED_PACKAGES " " "Enabled packages:" $ENABLED_PACKAGES > $PACKAGES_DOT_H".tmp"
3388 if test ! -f $PACKAGES_DOT_H ; then
3389 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
3390 else
3391 cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
3392 RETVAL=$?
3393 if test "x$RETVAL" = x0 ; then
3394 rm -f $PACKAGES_DOT_H".tmp"
3395 else
3396 mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
3397 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
3398 fi
3399 fi
3400 if test ! -f AD_CONFIG.h ; then
3401 $BASH $TOOLSDIR/convert_cpp_cmd2defines "Default version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > AD_CONFIG.h
3402 fi
3403
3404 # Write the "state" for future records
3405 if test "x$DUMPSTATE" = xt ; then
3406 printf "" > genmake_state
3407 for i in $gm_state ; do
3408 t1="t2=\$$i"
3409 eval $t1
3410 echo "$i='$t2'" | sed -e 's/ */ /g' >> genmake_state
3411 done
3412 fi

  ViewVC Help
Powered by ViewVC 1.1.22