/[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.219 - (show annotations) (download)
Sat Jan 15 19:16:32 2011 UTC (8 years, 6 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint62s, checkpoint62r, checkpoint62w, checkpoint62v, checkpoint62u, checkpoint62t, checkpoint62y, checkpoint62x
Changes since 1.218: +3 -2 lines
updated after changes in testreport (mpi with different number of Proc)

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

  ViewVC Help
Powered by ViewVC 1.1.22