/[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.236 - (show annotations) (download)
Fri Aug 24 23:07:27 2012 UTC (11 years, 7 months ago) by jmc
Branch: MAIN
Changes since 1.235: +92 -93 lines
- improve error msg when failing in 2nd test of check_for_broken_Ff
- rename FLOFILES -> FLOWFILES

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

  ViewVC Help
Powered by ViewVC 1.1.22