/[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.237 - (show annotations) (download)
Fri Aug 24 23:41:17 2012 UTC (6 years, 10 months ago) by jmc
Branch: MAIN
Changes since 1.236: +93 -91 lines
- fix option '-makefile' short-name (-mf according to genmake2 -help)
- source local config file "genmake_local" just after processing the genmake2
  command arguments (previously done before processing arg).

1 #! /usr/bin/env bash
2 #
3 # $Header: /u/gcmpack/MITgcm/tools/genmake2,v 1.236 2012/08/24 23:07:27 jmc Exp $
4 # $Name: $
5 #
6 # Makefile generator for MITgcm UV codes
7 # created by cnh 03/98
8 # adapted by aja 06/98
9 # modified by aja 01/00
10 # rewritten in bash by eh3 08/03
11
12 # Explain usage
13 usage() {
14 cat <<EOF
15
16 Usage: "$0" [OPTIONS]
17 where [OPTIONS] can be:
18
19 -help | --help | -h | --h
20 Print this help message and exit.
21
22 -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
23 -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
24 Use "NAME" as the adoptfile. By default, the file at
25 "tools/adjoint_options/adjoint_default" will be used.
26
27 -nooptfile | --nooptfile
28 -optfile NAME | --optfile NAME | -of NAME | --of NAME
29 -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
30 Use "NAME" as the optfile. By default, an attempt will be
31 made to find an appropriate "standard" optfile in the
32 tools/build_options/ directory.
33
34 -pdepend NAME | --pdepend NAME
35 -pdepend=NAME | --pdepend=NAME
36 Get package dependency information from "NAME".
37
38 -pgroups NAME | --pgroups NAME
39 -pgroups=NAME | --pgroups=NAME
40 Get the package groups information from "NAME".
41
42 -bash NAME
43 Explicitly specify the Bourne or BASH shell to use
44
45 -make NAME | -m NAME
46 --make=NAME | -m=NAME
47 Use "NAME" for the MAKE program. The default is "make" but
48 many platforms, "gmake" is the preferred choice.
49
50 -makefile NAME | -mf NAME
51 --makefile=NAME | -mf=NAME
52 Call the makefile "NAME". The default is "Makefile".
53
54 -makedepend NAME | -md NAME
55 --makedepend=NAME | -md=NAME
56 Use "NAME" for the MAKEDEPEND program.
57
58 -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
59 -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
60 Specify the location of the MITgcm ROOTDIR as "NAME".
61 By default, genamke will try to find the location by
62 looking in parent directories (up to the 5th parent).
63
64 -mods NAME | --mods NAME | -mo NAME | --mo NAME
65 -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
66 Here, "NAME" specifies a list of directories that are
67 used for additional source code. Files found in the
68 "mods list" are given preference over files of the same
69 name found elsewhere.
70
71 -disable NAME | --disable NAME
72 -disable=NAME | --disable=NAME
73 Here "NAME" specifies a list of packages that we don't
74 want to use. If this violates package dependencies,
75 genamke will exit with an error message.
76
77 -enable NAME | --enable NAME
78 -enable=NAME | --enable=NAME
79 Here "NAME" specifies a list of packages that we wish
80 to specifically enable. If this violates package
81 dependencies, genamke will exit with an error message.
82
83 -standarddirs NAME | --standarddirs NAME
84 -standarddirs=NAME | --standarddirs=NAME
85 Here, "NAME" specifies a list of directories to be
86 used as the "standard" code.
87
88 -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
89 -fc=NAME | --fc=NAME
90 Use "NAME" as the fortran compiler. By default, genmake
91 will search for a working compiler by trying a list of
92 "usual suspects" such as g77, f77, etc.
93
94 -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
95 Use "NAME" as the C compiler. By default, genmake
96 will search for a working compiler by trying a list of
97 "usual suspects" such as gcc, c89, cc, etc.
98
99 -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 #- local config file
1210 gm_local="genmake_local"
1211
1212 G2ARGS=
1213 BASH=
1214 PWD=`pwd`
1215 test "x$MAKE" = x && MAKE=make
1216 test "x$AWK" = x && AWK=awk
1217 EMBED_SRC=
1218 THISHOST=`hostname`
1219 THISCWD=`pwd`
1220 THISDATE=`date`
1221 THISUSER=`echo $USER`
1222 THISVER=
1223 MACHINE=`uname -a`
1224 EXECUTABLE=
1225 EXEHOOK=
1226 EXEDIR=
1227 IEEE=
1228 if test "x$MITGCM_IEEE" != x ; then
1229 IEEE=$MITGCM_IEEE
1230 fi
1231 FS=
1232 FS90=
1233
1234 AUTODIFF_PKG_USED=f
1235 AD_OPTFILE=
1236 TAF=
1237 AD_TAF_FLAGS=
1238 FTL_TAF_FLAGS=
1239 SVD_TAF_FLAGS=
1240 TAF_EXTRA=
1241 TAMC=
1242 AD_TAMC_FLAGS=
1243 FTL_TAF_FLAGS=
1244 SVD_TAMC_FLAGS=
1245 TAMC_EXTRA=
1246
1247 # The following state can be set directly by command-line switches
1248 gm_s1="OPTFILE PKG_DEPEND PKG_GROUPS DISABLE ENABLE MAKEFILE MAKEDEPEND PLATFORM"
1249 gm_s2="FC CC MPI OMP USE_R4 TS PAPIS PCLS PAPI PCL HPMT IEEE DEVEL GSL FEXTRAFLAGS"
1250 gm_s3="ROOTDIR STANDARDDIRS MODS DUMPSTATE"
1251
1252 # The following state is not directly set by command-line switches
1253 gm_s4="LN S64 LINK MAKE PACKAGES INCLUDES FFLAGS FOPTIM"
1254 gm_s5="CFLAGS LIBS KPP KFLAGS1 KFLAGS2 KPPFILES NOOPTFILES NOOPTFLAGS"
1255 gm_s6="TOOLSDIR SOURCEDIRS INCLUDEDIRS EXEDIR EXECUTABLE EXEHOOK"
1256 gm_s7="PWD THISHOST THISUSER THISDATE THISVER MACHINE"
1257 gm_s8="FC_NAMEMANGLE HAVE_NETCDF HAVE_SYSTEM HAVE_FDATE HAVE_ETIME HAVE_LAPACK"
1258
1259 # The following are all related to adjoint/tangent-linear stuff
1260 gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
1261 gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1262 gm_s12="TAF_EXTRA TAMC_EXTRA"
1263
1264 gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8"
1265 gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
1266
1267 cat <<EOF
1268
1269 GENMAKE :
1270
1271 A program for GENerating MAKEfiles for the MITgcm project.
1272 For a quick list of options, use "genmake2 -h"
1273 or for more detail see the Developer's HOWTO manual at:
1274 http://mitgcm.org/public/docs.html
1275
1276 EOF
1277
1278 LOGFILE="genmake.log"
1279 #- clean-up previous genmake logfiles:
1280 rm -f genmake_state genmake_*optfile $LOGFILE
1281
1282 echo "=== Processing options files and arguments ==="
1283
1284 #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
1285 #parse_options
1286 ac_prev=
1287 for ac_option in "$@" ; do
1288
1289 G2ARGS="$G2ARGS \"$ac_option\""
1290
1291 # If the previous option needs an argument, assign it.
1292 if test -n "$ac_prev"; then
1293 eval "$ac_prev=\$ac_option"
1294 ac_prev=
1295 continue
1296 fi
1297
1298 ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
1299
1300 case $ac_option in
1301
1302 -help | --help | -h | --h)
1303 usage ;;
1304
1305 -nooptfile | --nooptfile)
1306 OPTFILE="NONE" ;;
1307 -optfile | --optfile | -of | --of)
1308 ac_prev=OPTFILE ;;
1309 -optfile=* | --optfile=* | -of=* | --of=*)
1310 OPTFILE=$ac_optarg ;;
1311
1312 -adoptfile | --adoptfile | -adof | --adof)
1313 ac_prev=AD_OPTFILE ;;
1314 -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
1315 AD_OPTFILE=$ac_optarg ;;
1316
1317 -pdepend | --pdepend)
1318 ac_prev=PKG_DEPEND ;;
1319 -pdepend=* | --pdepend=*)
1320 PKG_DEPEND=$ac_optarg ;;
1321
1322 -pgroups | --pgroups)
1323 ac_prev=PKG_GROUPS ;;
1324 -pgroups=* | --pgroups=*)
1325 PKG_GROUPS=$ac_optarg ;;
1326
1327 -make | --make | -m | --m)
1328 ac_prev=MAKE ;;
1329 -make=* | --make=* | -m=* | --m=*)
1330 MAKE=$ac_optarg ;;
1331
1332 -bash | --bash)
1333 ac_prev=BASH ;;
1334 -bash=* | --bash=*)
1335 BASH=$ac_optarg ;;
1336
1337 -makedepend | --makedepend | -md | --md)
1338 ac_prev=MAKEDEPEND ;;
1339 -makedepend=* | --makedepend=* | -md=* | --md=*)
1340 MAKEDEPEND=$ac_optarg ;;
1341
1342 -makefile | --makefile | -mf | --mf)
1343 ac_prev=MAKEFILE ;;
1344 -makefile=* | --makefile=* | -mf=* | --mf=*)
1345 MAKEFILE=$ac_optarg ;;
1346
1347 -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1348 echo "ERROR: The platform option has been removed. Please specify"
1349 echo " the build options using the \"optfile\" mechanism."
1350 echo
1351 usage
1352 ;;
1353
1354 -rootdir | --rootdir | -rd | --rd)
1355 ac_prev=ROOTDIR ;;
1356 -rootdir=* | --rootdir=* | -rd=* | --rd=*)
1357 ROOTDIR=$ac_optarg ;;
1358
1359 -mods | --mods | -mo | --mo)
1360 ac_prev=MODS ;;
1361 -mods=* | --mods=* | -mo=* | --mo=*)
1362 MODS=$ac_optarg ;;
1363
1364 -disable | --disable)
1365 ac_prev=DISABLE ;;
1366 -disable=* | --disable=*)
1367 DISABLE=$ac_optarg ;;
1368
1369 -enable | --enable)
1370 ac_prev=ENABLE ;;
1371 -enable=* | --enable=*)
1372 ENABLE=$ac_optarg ;;
1373
1374 -standarddirs | --standarddirs)
1375 ac_prev=STANDARDDIRS ;;
1376 -standarddirs=* | --standarddirs=*)
1377 STANDARDDIRS=$ac_optarg ;;
1378
1379 # -cpp | --cpp)
1380 # ac_prev=cpp ;;
1381 # -cpp=* | --cpp=*)
1382 # CPP=$ac_optarg ;;
1383
1384 -cc | --cc)
1385 ac_prev=CC ;;
1386 -cc=* | --cc=*)
1387 CC=$ac_optarg ;;
1388
1389 -fortran | --fortran | -fc | --fc)
1390 ac_prev=FC ;;
1391 -fc=* | --fc=*)
1392 FC=$ac_optarg ;;
1393
1394 -fs | --fs)
1395 ac_prev=FS ;;
1396 -fs=* | --fs=*)
1397 FS=$ac_optarg ;;
1398
1399 -fs90 | --fs90)
1400 ac_prev=FS90 ;;
1401 -fs90=* | --fs90=*)
1402 FS90=$ac_optarg ;;
1403
1404 -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4 )
1405 USE_R4=true ;;
1406
1407 -ieee | --ieee)
1408 IEEE=true ;;
1409 -noieee | --noieee)
1410 echo "Warning: ignore option '$ac_option' (default is already without '-ieee')" ;;
1411 -devel | --devel)
1412 IEEE=true ; DEVEL=true ;;
1413 -gsl | --gsl)
1414 GSL=true ;;
1415
1416 -ts | --ts)
1417 TS=true ;;
1418 -papis | --papis)
1419 PAPIS=true ;;
1420 -pcls | --pcls)
1421 PCLS=true ;;
1422 -foolad | --foolad)
1423 FOOLAD=true ;;
1424 -papi | --papi)
1425 PAPI=true ;;
1426 -pcl | --pcl)
1427 PCL=true ;;
1428 -hpmt | --hpmt)
1429 HPMT=true ;;
1430
1431 -mpi | --mpi)
1432 MPI=true ;;
1433 -mpi=* | --mpi=*)
1434 MPIPATH=$ac_optarg
1435 MPI=true ;;
1436
1437 -omp | --omp)
1438 OMP=true ;;
1439 -omp=* | --omp=*)
1440 OMPFLAG=$ac_optarg
1441 OMP=true ;;
1442
1443 -ds | --ds)
1444 DUMPSTATE=t ;;
1445
1446 -extra_flag | --extra_flag)
1447 ac_prev=FEXTRAFLAGS ;;
1448 -extra_flag=* | --extra_flag=*)
1449 FEXTRAFLAGS=$ac_optarg ;;
1450
1451 -taf_extra | --taf_extra)
1452 ac_prev=TAF_EXTRA ;;
1453 -taf_extra=* | --taf_extra=*)
1454 TAF_EXTRA=$ac_optarg ;;
1455
1456 -tamc_extra | --tamc_extra)
1457 ac_prev=TAMC_EXTRA ;;
1458 -tamc_extra=* | --tamc_extra=*)
1459 TAMC_EXTRA=$ac_optarg ;;
1460
1461 -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1462 IGNORE_TIME="-DIGNORE_TIME" ;;
1463
1464 -es | --es | -embed-source | --embed-source)
1465 EMBED_SRC=t ;;
1466
1467 -*)
1468 echo "Error: unrecognized option: "$ac_option
1469 usage
1470 ;;
1471
1472 *)
1473 echo "Error: unrecognized argument: "$ac_option
1474 usage
1475 ;;
1476
1477 esac
1478
1479 done
1480
1481 printf " getting local config information: "
1482 if test -f $gm_local ; then
1483 echo "using $gm_local"
1484 . $gm_local
1485 else
1486 echo "none found"
1487 fi
1488
1489 if test -f ./.genmakerc ; then
1490 echo
1491 echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
1492 echo " file. This file format is no longer supported. For directions on"
1493 echo " how to setup and use the new \"genmake2\" script, please see:"
1494 echo " http://mitgcm.org/public/devel_HOWTO/"
1495 echo " and send an email to MITgcm-support@mitgcm.org if you need help."
1496 echo "WARNING: ignore \"./.genmakerc\" and continue."
1497 echo
1498 fi
1499
1500 # Find the MITgcm ${ROOTDIR}
1501 if test "x${ROOTDIR}" = x ; then
1502 tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1503 if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesupp -a -d ../pkg ; then
1504 ROOTDIR=".."
1505 else
1506 for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1507 if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
1508 ROOTDIR=$d
1509 printf "Warning: ROOTDIR was not specified ;"
1510 echo " try using a local copy of MITgcm found at \"$ROOTDIR\""
1511 break
1512 fi
1513 done
1514 fi
1515 fi
1516 if test "x${ROOTDIR}" = x ; then
1517 echo "Error: Cannot determine ROOTDIR for MITgcm code."
1518 echo " Please specify a ROOTDIR using either an options "
1519 echo " file or a command-line option."
1520 exit 1
1521 fi
1522 if test ! -d ${ROOTDIR} ; then
1523 echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
1524 exit 1
1525 fi
1526
1527 # Find the MITgcm ${THISVER}
1528 version_file="${ROOTDIR}/doc/tag-index"
1529 if test -f $version_file ; then
1530 THISVER=`$AWK '/^checkpoint/{print $1; exit}' $version_file`
1531 #- remove ./BUILD_INFO.h file if older than version_file
1532 if test -f ./BUILD_INFO.h -a ./BUILD_INFO.h -ot $version_file ; then
1533 echo " remove ./BUILD_INFO.h (older than ${version_file})"
1534 rm -f ./BUILD_INFO.h
1535 fi
1536 fi
1537
1538 if test "x$MAKEFILE" = x ; then
1539 MAKEFILE="Makefile"
1540 fi
1541
1542 echo " getting OPTFILE information:"
1543 if test "x${OPTFILE}" = x ; then
1544 if test "x$MITGCM_OF" = x ; then
1545 echo "Warning: no OPTFILE specified so we'll look for possible settings"
1546 printf "\n=== Searching for possible settings for OPTFILE ===\n"
1547 find_possible_optfile
1548 else
1549 OPTFILE=$MITGCM_OF
1550 fi
1551 fi
1552 if test "x$OPTFILE" != xNONE ; then
1553 if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
1554 echo " using OPTFILE=\"$OPTFILE\""
1555 . "$OPTFILE"
1556 RETVAL=$?
1557 if test "x$RETVAL" != x0 ; then
1558 printf "Error: failed to source OPTFILE \"$OPTFILE\""
1559 echo "--please check that variable syntax is bash-compatible"
1560 exit 1
1561 fi
1562 if test "x$DUMPSTATE" = xt ; then
1563 cp -f $OPTFILE "genmake_optfile"
1564 fi
1565 else
1566 echo "Error: can't read OPTFILE=\"$OPTFILE\""
1567 exit 1
1568 fi
1569 fi
1570
1571 echo " getting AD_OPTFILE information:"
1572 if test "x${AD_OPTFILE}" = x ; then
1573 if test "x$MITGCM_AD_OF" = x ; then
1574 AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
1575 else
1576 AD_OPTFILE=$MITGCM_AD_OF
1577 fi
1578 fi
1579 if test "x${AD_OPTFILE}" != xNONE ; then
1580 if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
1581 echo " using AD_OPTFILE=\"$AD_OPTFILE\""
1582 . "$AD_OPTFILE"
1583 RETVAL=$?
1584 if test "x$RETVAL" != x0 ; then
1585 printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1586 echo "--please check that variable syntax is bash-compatible"
1587 exit 1
1588 fi
1589 if test "x$DUMPSTATE" = xt ; then
1590 cp -f $AD_OPTFILE "genmake_ad_optfile"
1591 fi
1592 else
1593 echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
1594 exit 1
1595 fi
1596 fi
1597
1598 #====================================================================
1599 # Set default values if not set by the optfile
1600 #
1601 # Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined. If not,
1602 # either set defaults or complain and abort!
1603 if test ! "x$BASH" = x ; then
1604 # add a trailing space so that it works within the Makefile syntax (see below)
1605 BASH="$BASH "
1606 fi
1607 if test "x$FC" = x ; then
1608 cat <<EOF 1>&2
1609
1610 Error: no Fortran compiler: please specify using one of the following:
1611 1) within the options file ("FC=...") as specified by "-of=OPTFILE"
1612 2) the "-fc=XXX" command-line option
1613 3) the "./genmake_local" file
1614 EOF
1615 exit 1
1616 fi
1617 if test "x$GET_FC_VERSION" != x ; then
1618 echo "Get compiler version using: $FC $GET_FC_VERSION" >> $LOGFILE
1619 ff=`echo $FC | sed 's/ .*//'` ; xx=`echo $ff | sed 's/^./& /' | sed 's/ .*//'`
1620 if test $xx != '/' ; then which $ff >> $LOGFILE ; fi
1621 $FC $GET_FC_VERSION > genmake_fc_vers1 2> genmake_fc_vers2
1622 if test -s genmake_fc_vers1 ; then
1623 cat genmake_fc_vers1 >> $LOGFILE
1624 else
1625 cat genmake_fc_vers2 >> $LOGFILE
1626 fi
1627 echo "<-- compiler version ----" >> $LOGFILE
1628 rm -f genmake_fc_vers1 genmake_fc_vers2
1629 fi
1630
1631 if test "x$CC" = x ; then
1632 look_for_C_compilers
1633 fi
1634
1635 if test "x$LINK" = x ; then
1636 LINK=$FC
1637 fi
1638 if test "x$MAKE" = x ; then
1639 MAKE="make"
1640 fi
1641 if test "x$CPP" = x ; then
1642 CPP="cpp -traditional -P"
1643 fi
1644 #EH3 === UGLY ===
1645 # The following is an ugly little hack to check for $CPP in /lib/ and
1646 # it should eventually be replaced with a more general function that
1647 # searches a combo of the user's path and a list of "usual suspects"
1648 # to find the correct location for binaries such as $CPP.
1649 for i in " " "/lib/" ; do
1650 echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1651 done
1652 #EH3 === UGLY ===
1653 echo "#define A a" | $CPP > test_cpp 2>&1
1654 RETVAL=$?
1655 if test "x$RETVAL" != x0 ; then
1656 cat <<EOF 1>&2
1657
1658 Error: C pre-processor "$CPP" failed the test case: please specify using:
1659
1660 1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1661 2) the "./genmake_local" file
1662 3) with the CPP environment variable
1663
1664 EOF
1665 exit 1
1666 else
1667 rm -f test_cpp
1668 fi
1669
1670 look_for_makedepend
1671
1672 # Check that soft-link command is set and usable
1673 if test "x$LN" = x ; then
1674 LN="ln -s"
1675 fi
1676 echo "test" > genmake_test_ln
1677 $LN genmake_test_ln genmake_tlink
1678 RETVAL=$?
1679 if test "x$RETVAL" != x0 ; then
1680 cat <<EOF 1>&2
1681
1682 Error: The command "$LN" failed -- please specify a working soft-link
1683 command in the optfile.
1684
1685 EOF
1686 exit 1
1687 fi
1688 test -L genmake_tlink > /dev/null 2>&1
1689 RETVAL=$?
1690 if test "x$RETVAL" = x0 ; then
1691 HAVE_TEST_L=t
1692 fi
1693 rm -f genmake_test_ln genmake_tlink
1694
1695 # Check for broken *.F/*.f handling and fix if possible
1696 check_for_broken_Ff
1697
1698 if test ! "x$MPI" = x ; then
1699 echo " Turning on MPI cpp macros"
1700 DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1701 fi
1702 if test ! "x$OMP" = x ; then
1703 echo " Add OMPFLAG and turn on OpenMP cpp macros"
1704 FFLAGS="$FFLAGS $OMPFLAG"
1705 F90FLAGS="$F90FLAGS $OMPFLAG"
1706 DEFINES="$DEFINES -DUSE_OMP_THREADING"
1707 fi
1708
1709 if test ! "x$USE_R4" = x ; then
1710 echo " Turning on LET_RS_BE_REAL4 cpp flag"
1711 DEFINES="$DEFINES -DLET_RS_BE_REAL4"
1712 fi
1713
1714 if test ! "x$TS" = x ; then
1715 echo " Turning on timing per timestep"
1716 if test ! "x$FOOLAD" = x ; then
1717 DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP"
1718 else
1719 DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1720 fi
1721 PACKAGES="$PACKAGES showflops"
1722 fi
1723 if test ! "x$PAPIS" = x ; then
1724 echo " Turning on PAPI flop summary per timestep"
1725 echo " Please make sure PAPIINC, PAPILIB are defined"
1726 if test ! "x$FOOLAD" = x ; then
1727 DEFINES="$DEFINES -DUSE_PAPI_FLOPS_SFP"
1728 else
1729 DEFINES="$DEFINES -DUSE_PAPI_FLOPS"
1730 fi
1731 INCLUDES="$INCLUDES $PAPIINC"
1732 LIBS="$LIBS $PAPILIB"
1733 PACKAGES="$PACKAGES showflops"
1734 fi
1735 if test ! "x$PCLS" = x ; then
1736 echo " Turning on PCL counter summary per timestep"
1737 echo " Please make sure PCLINC, PCLLIB are defined"
1738 if test ! "x$FOOLAD" = x ; then
1739 DEFINES="$DEFINES -DUSE_PCL_FLOPS_SFP"
1740 else
1741 DEFINES="$DEFINES -DUSE_PCL_FLOPS"
1742 fi
1743 INCLUDES="$INCLUDES $PCLINC"
1744 LIBS="$LIBS $PCLLIB"
1745 PACKAGES="$PACKAGES showflops"
1746 fi
1747 if test ! "x$PAPI" = x ; then
1748 if test ! "x$PAPIS" = x ; then
1749 echo " PAPI performance analysis and flop summary per timestep cannot co-exist!"
1750 echo " Sticking with PAPI flop summary per timestep!"
1751 else
1752 echo " Turning on performance analysis with PAPI"
1753 echo " Please make sure PAPIINC, PAPILIB are defined"
1754 DEFINES="$DEFINES -DUSE_PAPI"
1755 INCLUDES="$INCLUDES $PAPIINC"
1756 LIBS="$LIBS $PAPILIB"
1757 fi
1758 fi
1759 if test ! "x$PCL" = x ; then
1760 if test ! "x$PCLS" = x ; then
1761 echo " PCL performance analysis and flop summary per timestep cannot co-exist!"
1762 echo " Sticking with PCL flop summary per timestep!"
1763 else
1764 echo " Turning on performance analysis with PCL"
1765 echo " Please make sure PCLINC, PCLLIB are defined"
1766 DEFINES="$DEFINES -DUSE_PCL"
1767 INCLUDES="$INCLUDES $PCLINC"
1768 LIBS="$LIBS $PCLLIB"
1769 fi
1770 fi
1771 if test ! "x$HPMT" = x ; then
1772 if test ! "x$PAPI" = x ; then
1773 echo " PAPI and the HPM Toolkit cannot co-exist!"
1774 echo " Sticking with PAPI!"
1775 else
1776 if test ! "x$PCL" = x ; then
1777 echo " PCL and the HPM Toolkit cannot co-exist!"
1778 echo " Sticking with PCL!"
1779 else
1780 echo " Turning on performance analysis with the HPM Toolkit"
1781 echo " Please make sure HPMTINC, HPMTLIB are defined"
1782 DEFINES="$DEFINES -DUSE_LIBHPM"
1783 INCLUDES="$INCLUDES $HPMTINC"
1784 LIBS="$LIBS $HPMTLIB"
1785 fi
1786 fi
1787 fi
1788 if test ! "x$GSL" = x ; then
1789 echo " Turning on use of GSL to control floating point calculations"
1790 echo " Please make sure GSLINC, GSLLIB are defined"
1791 DEFINES="$DEFINES -DUSE_GSL_IEEE"
1792 INCLUDES="$INCLUDES $GSLINC"
1793 LIBS="$LIBS $GSLLIB"
1794 fi
1795 #- if USE_EXTENDED_SRC is set, add EXTENDED_SRC_FLAG to FFLAGS :
1796 if test ! "x$USE_EXTENDED_SRC" = x ; then
1797 FFLAGS="$FFLAGS $EXTENDED_SRC_FLAG"
1798 F90FIXEDFORMAT="$F90FIXEDFORMAT $EXTENDED_SRC_FLAG"
1799 fi
1800
1801 printf "\n=== Checking system libraries ===\n"
1802 printf " Do we have the system() command using $FC... "
1803 cat > genmake_tcomp.$FS <<EOF
1804 program hello
1805 call system('echo hi')
1806 end
1807 EOF
1808 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1809 RETVAL=$?
1810 if test "x$RETVAL" = x0 ; then
1811 HAVE_SYSTEM=t
1812 DEFINES="$DEFINES -DHAVE_SYSTEM"
1813 echo "yes"
1814 else
1815 HAVE_SYSTEM=
1816 echo "no"
1817 fi
1818 rm -f genmake_tcomp*
1819
1820 printf " Do we have the fdate() command using $FC... "
1821 cat > genmake_tcomp.$FS <<EOF
1822 program hello
1823 CHARACTER*(128) string
1824 string = ' '
1825 call fdate( string )
1826 print *, string
1827 end
1828 EOF
1829 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1830 RETVAL=$?
1831 if test "x$RETVAL" = x0 ; then
1832 HAVE_FDATE=t
1833 DEFINES="$DEFINES -DHAVE_FDATE"
1834 echo "yes"
1835 else
1836 HAVE_FDATE=
1837 echo "no"
1838 fi
1839 rm -f genmake_tcomp*
1840
1841 printf " Do we have the etime() command using $FC... "
1842 cat > genmake_tcomp.$FS <<EOF
1843 program hello
1844 REAL*4 ACTUAL, TARRAY(2)
1845 EXTERNAL ETIME
1846 REAL*4 ETIME
1847 actual = etime( tarray )
1848 print *, tarray
1849 end
1850 EOF
1851 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1852 RETVAL=$?
1853 if test "x$RETVAL" = x0 ; then
1854 HAVE_ETIME=t
1855 DEFINES="$DEFINES -DHAVE_ETIME"
1856 echo "yes"
1857 else
1858 HAVE_ETIME=
1859 echo "no"
1860 fi
1861 rm -f genmake_tcomp*
1862
1863 printf " Can we call simple C routines (here, \"cloc()\") using $FC... "
1864 check_HAVE_CLOC
1865 if test "x$HAVE_CLOC" != x ; then
1866 DEFINES="$DEFINES -DHAVE_CLOC"
1867 echo "yes"
1868 else
1869 echo "no"
1870 if test "x$EMBED_SRC" = xt ; then
1871 echo " WARNING: you requested file embedding but it has"
1872 echo " been disabled since C code cannot be called"
1873 EMBED_SRC=
1874 fi
1875 fi
1876 rm -f genmake_t*
1877
1878 printf " Can we unlimit the stack size using $FC... "
1879 check_HAVE_SETRLSTK
1880 if test "x$HAVE_SETRLSTK" = xt ; then
1881 DEFINES="$DEFINES -DHAVE_SETRLSTK"
1882 echo "yes"
1883 else
1884 echo "no"
1885 fi
1886 rm -f genmake_t*
1887
1888 printf " Can we register a signal handler using $FC... "
1889 check_HAVE_SIGREG
1890 if test "x$HAVE_SIGREG" = xt ; then
1891 DEFINES="$DEFINES -DHAVE_SIGREG"
1892 echo "yes"
1893 else
1894 echo "no"
1895 fi
1896 rm -f genmake_t*
1897
1898 printf " Can we use stat() through C calls... "
1899 check_HAVE_STAT
1900 if test "x$HAVE_STAT" != x ; then
1901 DEFINES="$DEFINES -DHAVE_STAT"
1902 echo "yes"
1903 else
1904 echo "no"
1905 fi
1906 rm -f genmake_t*
1907
1908 printf " Can we create NetCDF-enabled binaries... "
1909 check_netcdf_libs
1910 if test "x$HAVE_NETCDF" != x ; then
1911 DEFINES="$DEFINES -DHAVE_NETCDF"
1912 echo "yes"
1913 else
1914 echo "no"
1915 fi
1916
1917 printf " Can we create LAPACK-enabled binaries... "
1918 check_lapack_libs
1919 if test "x$HAVE_LAPACK" != x ; then
1920 DEFINES="$DEFINES -DHAVE_LAPACK"
1921 echo "yes"
1922 else
1923 echo "no"
1924 fi
1925 DEFINES="$DEFINES $IGNORE_TIME"
1926
1927 if test "x$EMBED_SRC" = xt ; then
1928 build_embed_encode
1929 fi
1930 if test "x$EMBED_SRC" = xt ; then
1931 ENABLE="$ENABLE embed_files"
1932 # DEFINES="$DEFINES -DHAVE_EMBED_SRC"
1933 fi
1934
1935 printf "\n=== Setting defaults ===\n"
1936 printf " Adding MODS directories: "
1937 for d in $MODS ; do
1938 if test ! -d $d ; then
1939 echo
1940 echo "Error: MODS directory \"$d\" not found!"
1941 exit 1
1942 else
1943 printf "$d "
1944 SOURCEDIRS="$SOURCEDIRS $d"
1945 INCLUDEDIRS="$INCLUDEDIRS $d"
1946 fi
1947 done
1948 echo
1949
1950 #if test "x${PLATFORM}" = x ; then
1951 # PLATFORM=$p_PLATFORM
1952 #fi
1953
1954 if test "x${EXEDIR}" = x ; then
1955 tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1956 if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
1957 EXEDIR=../exe
1958 else
1959 EXEDIR=.
1960 fi
1961 fi
1962 if test ! -d ${EXEDIR} ; then
1963 echo "Error: the specified EXEDIR (\"$EXEDIR\") does not exist!"
1964 exit 1
1965 fi
1966
1967 if test "x${TOOLSDIR}" = x ; then
1968 TOOLSDIR="$ROOTDIR/tools"
1969 fi
1970 if test ! -d ${TOOLSDIR} ; then
1971 echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1972 exit 1
1973 fi
1974 if test "x$S64" = x ; then
1975 echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
1976 RETVAL=$?
1977 if test "x${RETVAL}" = x0 ; then
1978 S64='$(TOOLSDIR)/set64bitConst.sh'
1979 else
1980 echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
1981 RETVAL=$?
1982 if test "x${RETVAL}" = x0 ; then
1983 S64='$(TOOLSDIR)/set64bitConst.csh'
1984 else
1985 cat <<EOF
1986
1987 ERROR: neither of the two default scripts:
1988
1989 ${TOOLSDIR}/set64bitConst.sh
1990 ${TOOLSDIR}/set64bitConst.csh
1991
1992 are working so please check paths or specify (with \$S64) a
1993 working version of this script.
1994
1995 EOF
1996 exit 1
1997 fi
1998 fi
1999 fi
2000 THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
2001
2002 EXECUTABLE=${EXECUTABLE:-mitgcmuv}
2003
2004 # Set Standard Code Directories:
2005 if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
2006 STANDARDDIRS="eesupp model"
2007 fi
2008 # if model in Standard-Code-Dir, add eesupp (needed to compile model)
2009 echo " $STANDARDDIRS " | grep ' model ' > /dev/null 2>&1
2010 ckM=$?
2011 echo " $STANDARDDIRS " | grep ' eesupp ' > /dev/null 2>&1
2012 ckE=$?
2013 if test $ckM = 0 -a $ckE = 1 ; then
2014 STANDARDDIRS="$STANDARDDIRS eesupp"
2015 fi
2016
2017 # We have a special set of source files in eesupp/src which are
2018 # generated from some template source files. We'll make them first so
2019 # they appear as regular source code
2020 if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
2021 echo " Making source files in eesupp from templates"
2022 ( cd $ROOTDIR"/eesupp/src/" && $MAKE clean_old && $MAKE \
2023 ) > make_eesupp.errors 2>&1
2024 RETVAL=$?
2025 if test "x${RETVAL}" = x0 ; then
2026 rm -f make_eesupp.errors
2027 else
2028 echo "Error: problem encountered while building source files in eesupp:"
2029 cat make_eesupp.errors 1>&2
2030 exit 1
2031 fi
2032 fi
2033
2034 #same for pkg/exch2 and pkg/regrid
2035 for pdir in exch2 regrid ; do
2036 if test -r $ROOTDIR"/pkg/${pdir}/Makefile" ; then
2037 echo " Making source files in pkg/${pdir} from templates"
2038 ( cd $ROOTDIR"/pkg/"${pdir} && $MAKE clean_old && $MAKE \
2039 ) > make_${pdir}.errors 2>&1
2040 RETVAL=$?
2041 if test "x${RETVAL}" = x0 ; then
2042 rm -f make_${pdir}.errors
2043 else
2044 echo "Error: problem encountered while building source files in pkg/${pdir}:"
2045 cat make_${pdir}.errors 1>&2
2046 exit 1
2047 fi
2048 fi
2049 done
2050
2051 printf "\n=== Determining package settings ===\n"
2052 if test "x${PKG_DEPEND}" = x ; then
2053 tmp=$ROOTDIR"/pkg/pkg_depend"
2054 if test -r $tmp ; then PKG_DEPEND=$tmp ; fi
2055 fi
2056 if test "x${PKG_DEPEND}" = x ; then
2057 echo "Warning: No package dependency information was specified."
2058 echo " Please check that ROOTDIR/pkg/pkg_depend exists."
2059 else
2060 if test ! -r ${PKG_DEPEND} ; then
2061 echo "Error: can't read package dependency info from PKG_DEPEND=\"$PKG_DEPEND\""
2062 exit 1
2063 fi
2064 echo " getting package dependency info from $PKG_DEPEND"
2065 # Strip the comments and then convert the dependency file into arrays: PNAME, DNAME
2066 get_pdepend_list $PKG_DEPEND
2067 fi
2068
2069 # A default package groups file "$ROOTDIR/pkg/pkg_groups" is provided
2070 # to define the "default_pkg_list" and package groups (for convenience, one
2071 # can specify a group of packages using names like "ocean" and "atmosphere").
2072 if test "x${PKG_GROUPS}" = x ; then
2073 tmp=$ROOTDIR"/pkg/pkg_groups"
2074 if test -r $tmp ; then PKG_GROUPS=$tmp ; fi
2075 fi
2076 if test "x${PKG_GROUPS}" = x ; then
2077 echo "Warning: No package groups information was specified."
2078 echo " Please check that ROOTDIR/pkg/pkg_groups exists."
2079 else
2080 if test ! -r ${PKG_GROUPS} ; then
2081 echo "Error: can't read package groups info from PKG_GROUPS=\"$PKG_GROUPS\""
2082 exit 1
2083 fi
2084 echo " getting package groups info from $PKG_GROUPS"
2085 fi
2086
2087 # Search for packages to compile.
2088 echo " checking list of packages to compile:"
2089 PKG_LIST=
2090 if test "x${PKG_LIST}" = x ; then
2091 for i in "." $MODS ; do
2092 if test -r $i"/packages.conf" ; then
2093 PKG_LIST=$i"/packages.conf"
2094 break
2095 fi
2096 done
2097 fi
2098 if test "x${PKG_LIST}" = x ; then
2099 pkg_list='default_pkg_list'
2100 if test "x${PKG_GROUPS}" = x ; then
2101 echo "Error: need package groups info to expand pkg_list=\"$pkg_list\""
2102 exit 1
2103 fi
2104 else
2105 if test ! -r $PKG_LIST ; then
2106 echo "Error: can't read package list from PKG_LIST=\"$PKG_LIST\""
2107 exit 1
2108 else
2109 echo " using PKG_LIST=\"$PKG_LIST\""
2110 # Strip the comments and add all the names
2111 pkg_list=`cat $PKG_LIST | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
2112 RETVAL=$?
2113 if test "x${RETVAL}" != x0 ; then
2114 printf "Error: can't parse package list "
2115 echo "-- please check PKG_LIST=\"$PKG_LIST\""
2116 exit 1
2117 fi
2118 fi
2119 fi
2120 for i in $pkg_list ; do
2121 PACKAGES="$PACKAGES $i"
2122 done
2123 echo " before group expansion packages are:$PACKAGES"
2124 if test "x${PKG_GROUPS}" != x ; then
2125 RET=1
2126 while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
2127 echo " after group expansion packages are: $PACKAGES"
2128 fi
2129
2130 echo " applying DISABLE settings"
2131 echo "" > ./.tmp_pack
2132 for i in $PACKAGES ; do
2133 echo $i >> ./.tmp_pack
2134 done
2135 for i in `grep "-" ./.tmp_pack` ; do
2136 j=`echo $i | sed 's/[-]//'`
2137 DISABLE="$DISABLE $j"
2138 done
2139 pack=
2140 for p in $PACKAGES ; do
2141 addit="t"
2142 for d in $DISABLE ; do
2143 if test "x$p" = "x$d" ; then
2144 addit="f"
2145 fi
2146 done
2147 if test "x$addit" = xt ; then
2148 pack="$pack $p"
2149 fi
2150 done
2151 PACKAGES="$pack"
2152 echo " applying ENABLE settings"
2153 echo "" > ./.tmp_pack
2154 PACKAGES="$PACKAGES $ENABLE"
2155 # Test if each explicitly referenced package exists
2156 for i in $PACKAGES ; do
2157 j=`echo $i | sed 's/[-+]//'`
2158 if test ! -d "$ROOTDIR/pkg/$j" ; then
2159 echo "Error: dir '$ROOTDIR/pkg/$i' missing for package '$i'"
2160 exit 1
2161 fi
2162 echo $i >> ./.tmp_pack
2163 done
2164 PACKAGES=
2165 for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
2166 PACKAGES="$PACKAGES $i"
2167 done
2168 rm -f ./.tmp_pack
2169 echo " packages are: $PACKAGES"
2170
2171 # Check for package MNC: if NetCDF is available, then build the MNC
2172 # template files ; otherwise, delete mnc from the list of packages.
2173 echo " $PACKAGES " | grep ' mnc ' > /dev/null 2>&1
2174 mnc_in=$?
2175 if test "x$HAVE_NETCDF" != xt ; then
2176 if test "x$mnc_in" = x0 ; then
2177 cat <<EOF
2178 *********************************************************************
2179 WARNING: the "mnc" package was enabled but tests failed to compile
2180 NetCDF applications. Please check that:
2181
2182 1) NetCDF is correctly installed for this compiler and
2183 2) the LIBS variable (within the "optfile") specifies the correct
2184 NetCDF library to link against.
2185
2186 Due to this failure, the "mnc" package is now DISABLED.
2187 *********************************************************************
2188 EOF
2189 PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
2190 DISABLE="$DISABLE mnc"
2191 else
2192 # this prevent to add mnc (due to pdepend rules) if not available
2193 DISABLE="$DISABLE mnc"
2194 fi
2195 else
2196 # we have NetCDF, we try to build MNC template files
2197 ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
2198 RETVAL=$?
2199 if test "x${RETVAL}" = x0 ; then
2200 rm -f make_mnc.errors
2201 else
2202 echo "Error: problem encountered while building source files in pkg/mnc:"
2203 cat make_mnc.errors 1>&2
2204 if test "x$mnc_in" = x0 ; then
2205 exit 1
2206 else
2207 DISABLE="$DISABLE mnc"
2208 fi
2209 fi
2210 fi
2211
2212 # Check for package PROFILES: if NetCDF is not available,
2213 # then delete profiles from the list of available packages.
2214 if test "x$HAVE_NETCDF" != xt ; then
2215 echo " $PACKAGES " | grep ' profiles ' > /dev/null 2>&1
2216 RETVAL=$?
2217 if test "x$RETVAL" = x0 ; then
2218 cat <<EOF
2219 *********************************************************************
2220 WARNING: the "profiles" package was enabled but tests failed to
2221 compile NetCDF applications. Please check that:
2222
2223 1) NetCDF is correctly installed for this compiler and
2224 2) the LIBS variable (within the "optfile") specifies the correct
2225 NetCDF library to link against.
2226
2227 Due to this failure, the "profiles" package is now DISABLED.
2228 *********************************************************************
2229 EOF
2230 PACKAGES=`echo $PACKAGES | sed -e 's/profiles//g'`
2231 DISABLE="$DISABLE profiles"
2232 else
2233 # this prevent to add profiles (due to pdepend rules) if not available
2234 DISABLE="$DISABLE profiles"
2235 fi
2236 fi
2237
2238 # Check for package RADTRANS: if LAPACK is not available,
2239 # then issue a warning that the direct radtrans solver is not available.
2240 if test "x$HAVE_LAPACK" != xt ; then
2241 echo " $PACKAGES " | grep ' radtrans ' > /dev/null 2>&1
2242 RETVAL=$?
2243 if test "x$RETVAL" = x0 ; then
2244 cat <<EOF
2245 *********************************************************************
2246 WARNING: the "radtrans" package was enabled but tests failed to
2247 compile LAPACK applications. This means that the direct radtrans
2248 solver is not available and compilation will fail if it is enabled.
2249 If you want to use the direct solver, please check that:
2250
2251 1) LAPACK is correctly installed for this compiler and
2252 2) the LIBS variable (within the "optfile") specifies the correct
2253 LAPACK library to link against.
2254 *********************************************************************
2255 EOF
2256 fi
2257 fi
2258
2259 if test "x${PKG_DEPEND}" != x ; then
2260 echo " applying package dependency rules"
2261 ck=
2262 while test "x$ck" != xtt ; do
2263 i=0
2264 # rtot=${#PNAME[@]}
2265 rtot=$nname
2266 while test $i -le $rtot ; do
2267
2268 # Is $pname in the current $PACKAGES list?
2269 # pname=${PNAME[$i]}
2270 tmp="pname=\"\$PNAME_$i\""
2271 eval $tmp
2272 pin="f"
2273 for p in $PACKAGES ; do
2274 if test "x$p" = "x$pname" ; then
2275 pin="t"
2276 fi
2277 done
2278 # or in the current $STANDARDDIRS list?
2279 for p in $STANDARDDIRS ; do
2280 if test "x$p" = "x$pname" ; then pin="t" ; fi
2281 done
2282
2283 # Is the DNAME entry a (+) or (-) rule ?
2284 tmp="dname=\"\$DNAME_$i\""
2285 eval $tmp
2286 plus="-"
2287 echo $dname | grep '^+' > /dev/null 2>&1
2288 RETVAL=$?
2289 if test "x$RETVAL" = x0 ; then
2290 plus="+"
2291 fi
2292
2293 # Is $dname in the current $PACKAGES list?
2294 dname=`echo $dname | sed -e 's/^[+-]//'`
2295 din="f"
2296 for p in $PACKAGES ; do
2297 if test "x$p" = "x$dname" ; then
2298 din="t"
2299 fi
2300 done
2301
2302 # Do we need to add $dname according to the dependency rules?
2303 if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
2304 #echo " " $pname ": need to add :" $dname
2305 in_dis="f"
2306 for dis in $DISABLE ; do
2307 if test "x$dis" = "x$dname" ; then
2308 in_dis="t"
2309 fi
2310 done
2311 if test "x$in_dis" = xt ; then
2312 echo "Error: can't satisfy package dependencies:"
2313 echo " \"$dname\" is required by the dependency rules"
2314 echo " but is disallowed by the DISABLE settings"
2315 exit 1
2316 else
2317 PACKAGES="$PACKAGES $dname"
2318 ck=
2319 fi
2320 fi
2321
2322 # Do we need to get rid of $dname according to the dependency rules?
2323 if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
2324 echo "Error: can't satisfy package dependencies:"
2325 echo " \"$pname\" was requested but is disallowed by"
2326 echo " the dependency rules for \"$dname\""
2327 exit 1
2328 fi
2329 i=`echo "$i + 1" | bc -l`
2330 #i=$(( $i + 1 ))
2331 done
2332 ck=$ck"t"
2333 done
2334 echo " packages are: $PACKAGES"
2335 fi
2336 for i in $PACKAGES ; do
2337 adr="$ROOTDIR/pkg/$i"
2338 if test -d $adr ; then
2339 SOURCEDIRS="$SOURCEDIRS $adr"
2340 INCLUDEDIRS="$INCLUDEDIRS $adr"
2341 if test "x$i" = xautodiff ; then
2342 AUTODIFF_PKG_USED=t
2343 fi
2344 else
2345 echo "Error: the directory \"$adr\" for package $i doesn't exist"
2346 exit 1
2347 fi
2348 done
2349
2350 # Create a list of #define and #undef to enable/disable packages
2351 PACKAGES_DOT_H=PACKAGES_CONFIG.h
2352 # The following UGLY HACK sets multiple "#undef"s and it needs to go
2353 # away. On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
2354 # file would eventually be split up so that all package-related #define
2355 # statements could be separated and handled only by genmake.
2356 names=`ls -1 "$ROOTDIR/pkg"`
2357 all_pack=
2358 DISABLED_PACKAGES=
2359 for n in $names ; do
2360 if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
2361 has_pack="f"
2362 for pack in $PACKAGES ; do
2363 if test "x$pack" = "x$n" ; then
2364 has_pack="t"
2365 break
2366 fi
2367 done
2368 if test "x$has_pack" = xf ; then
2369 undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2370 DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
2371 fi
2372 fi
2373 done
2374 ENABLED_PACKAGES=
2375 for i in $PACKAGES ; do
2376 def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2377 ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
2378 #eh3 DEFINES="$DEFINES -D$def"
2379
2380 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
2381 case $i in
2382 aim_v23)
2383 ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
2384 echo "Warning: ALLOW_AIM is set to enable aim_v23."
2385 ;;
2386 esac
2387 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
2388
2389 done
2390
2391 echo " Adding STANDARDDIRS='$STANDARDDIRS'"
2392 BUILDDIR=${BUILDDIR:-.}
2393 if test "x$STANDARDDIRS" != x ; then
2394 for d in $STANDARDDIRS ; do
2395 adr="$ROOTDIR/$d/src"
2396 if test ! -d $adr ; then
2397 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2398 echo " is correct and that you correctly specified the STANDARDDIRS option"
2399 exit 1
2400 else
2401 SOURCEDIRS="$SOURCEDIRS $adr"
2402 fi
2403 adr="$ROOTDIR/$d/inc"
2404 if test ! -d $adr ; then
2405 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2406 echo " is correct and that you correctly specified the STANDARDDIRS option"
2407 exit 1
2408 else
2409 INCLUDEDIRS="$INCLUDEDIRS $adr"
2410 fi
2411 done
2412 fi
2413
2414 echo " Searching for *OPTIONS.h files in order to warn about the presence"
2415 echo " of \"#define \"-type statements that are no longer allowed:"
2416 CPP_OPTIONS=
2417 CPP_EEOPTIONS=
2418 spaths=". $INCLUDEDIRS"
2419 names=`ls -1 "$ROOTDIR/pkg"`
2420 for i in $spaths ; do
2421 try="$i/CPP_OPTIONS.h"
2422 if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
2423 echo " found CPP_OPTIONS=\"$try\""
2424 CPP_OPTIONS="$try"
2425 # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
2426 for n in $names ; do
2427 test_for_package_in_cpp_options $CPP_OPTIONS $n
2428 done
2429 fi
2430 try="$i/CPP_EEOPTIONS.h"
2431 if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
2432 echo " found CPP_EEOPTIONS=\"$try\""
2433 # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
2434 #**** not yet enabled ****
2435 # test_for_mpi_in_cpp_eeoptions $try
2436 #**** not yet enabled ****
2437 CPP_EEOPTIONS="$try"
2438 fi
2439 done
2440 if test "x$CPP_OPTIONS" = x ; then
2441 echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
2442 exit 1
2443 fi
2444
2445 # Here, we build the list of files to be "run through" the adjoint
2446 # compiler.
2447 if test -f ./adSrcFiles.tmp ; then
2448 rm -f ./adSrcFiles.tmp
2449 fi
2450 echo " Creating the list of files for the adjoint compiler."
2451 touch adSrcFiles.tmp
2452 for i in $SOURCEDIRS ; do
2453 list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
2454 for j in $list_files ; do
2455 cat $i/$j >> adSrcFiles.tmp
2456 done
2457 done
2458 if test ! "x"$FS = "x.f" ; then
2459 cat adSrcFiles.tmp | sed -e "s/\.f/.$FS/g" > adSrcFiles.tmp_f
2460 mv -f adSrcFiles.tmp_f adSrcFiles.tmp
2461 fi
2462
2463 echo
2464 echo "=== Creating the Makefile ==="
2465 echo " setting INCLUDES"
2466 for i in $INCLUDEDIRS ; do
2467 if test ! -d $i ; then
2468 echo "Warning: can't find INCLUDEDIRS=\"$i\""
2469 fi
2470 done
2471
2472 if test ! "x$DIVA" = x ; then
2473 echo " Creating the pseudo-MPI include directory"
2474 INCLUDES="-I./mpi_headers $INCLUDES"
2475 rm -rf ./mpi_headers
2476 mkdir -p ./mpi_headers
2477
2478 if test "x$MPIINCLUDEDIR" = x ; then
2479 if test "x$MPIHOME" = x ; then
2480 MPIHOME='/usr'
2481 fi
2482 MPIINCLUDEDIR='$MPIHOME/include'
2483 fi
2484
2485 if test -r $MPIINCLUDEDIR/mpif.h ; then
2486 for i in $MPI_HEADER_FILES; do
2487 cp -p $MPIINCLUDEDIR/$i ./mpi_headers
2488 done
2489
2490 perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h
2491 else
2492 echo " We cannot create a copy of mpif.h!"
2493 # exit -1
2494 fi
2495 fi
2496
2497 echo " Determining the list of source and include files"
2498 rm -rf .links.tmp
2499 mkdir .links.tmp
2500 touch .links.tmp/foo
2501 if test ! -r ".links.tmp/foo" ; then
2502 echo
2503 echo "ERROR : something is wrong with your directory permissions or"
2504 echo " your user file-creation mask (\"umask\") since creating a"
2505 echo " sub-dir, touch-ing a file within it, and then reading it is"
2506 echo " not working. Please try setting your umask to something"
2507 echo " sane such as:"
2508 echo
2509 echo " umask 0002"
2510 echo
2511 echo " and please verify that you have the proper permissions for"
2512 echo " creating sub-directories and then reading files created"
2513 echo " within them."
2514 echo
2515 exit 1
2516 fi
2517 rm -f .links.tmp/foo
2518
2519 if test "x$OPENAD" != x ; then
2520 OAD_DONT_COMPILE="/dev/null"
2521 OAD_DONT_TRANSFORM="/dev/null"
2522 OAD_KEEP_ORIGINAL="/dev/null"
2523 OAD_CB2M_FILES="/dev/null"
2524 echo " looking for dontCompile file: "
2525 for i in "." $MODS ; do
2526 if test -r $i"/dontCompile" ; then
2527 OAD_DONT_COMPILE=$i"/dontCompile"
2528 echo " found $OAD_DONT_COMPILE"
2529 break
2530 fi
2531 done
2532 echo " looking for dontTransform file: "
2533 for i in "." $MODS ; do
2534 if test -r $i"/dontTransform" ; then
2535 OAD_DONT_TRANSFORM=$i"/dontTransform"
2536 echo " found $OAD_DONT_TRANSFORM"
2537 break
2538 fi
2539 done
2540 echo " looking for keepOriginal file: "
2541 for i in "." $MODS ; do
2542 if test -r $i"/keepOriginal" ; then
2543 OAD_KEEP_ORIGINAL=$i"/keepOriginal"
2544 echo " found $OAD_KEEP_ORIGINAL"
2545 break
2546 fi
2547 done
2548 echo " looking for cb2mFiles: "
2549 for i in "." $MODS ; do
2550 if test -r $i"/cb2mFiles" ; then
2551 OAD_CB2M_FILES=$i"/cb2mFiles"
2552 echo " found $OAD_CB2M_FILES"
2553 break
2554 fi
2555 done
2556 echo " OpenAD exceptions: "
2557 fi
2558
2559 echo "# This section creates symbolic links" > srclinks.tmp
2560 echo "" >> srclinks.tmp
2561 printf 'F77_SRC_FILES = ' > F77srclist.tmp
2562 printf 'NON_AD_F77_SRC_FILES = ' > nonADF77srclist.tmp
2563 printf 'C_SRC_FILES = ' > csrclist.tmp
2564 printf 'F90_SRC_FILES = ' > F90srclist.tmp
2565 printf 'H_SRC_FILES = ' > hsrclist.tmp
2566 printf 'AD_FLOW_FILES = ' > ad_flow_files.tmp
2567 alldirs="$SOURCEDIRS $INCLUDEDIRS ."
2568 for d in $alldirs ; do
2569 deplist=
2570 sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
2571 sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
2572 if test "x$OPENAD" != x ; then
2573 sfiles=`( echo $sfiles | grep -v _cb2m\. )`
2574 fi
2575 for sf in $sfiles ; do
2576 if test ! -r ".links.tmp/$sf" ; then
2577 if test -f "$d/$sf" ; then
2578 ignore_f=f
2579 case $d/$sf in
2580 ./$PACKAGES_DOT_H)
2581 ignore_f=t
2582 ;;
2583 ./AD_CONFIG.h)
2584 ignore_f=t
2585 ;;
2586 ./FC_NAMEMANGLE.h)
2587 ignore_f=t
2588 ;;
2589 ./BUILD_INFO.h)
2590 ignore_f=t
2591 ;;
2592 ./EMBEDDED_FILES.h)
2593 ignore_f=t
2594 ;;
2595 *)
2596 # For the local directory *ONLY*,
2597 # ignore all soft-links
2598 if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
2599 ignore_f=t
2600 else
2601 touch .links.tmp/$sf
2602 deplist="$deplist $sf"
2603 fi
2604 ;;
2605 esac
2606 if test "x$ignore_f" = xf ; then
2607 extn=`echo $sf | $AWK -F. '{print $NF}'`
2608 case $extn in
2609 F)
2610 echo " \\" >> F77srclist.tmp
2611 printf " $sf" >> F77srclist.tmp
2612 if test "x$OPENAD" != x ; then
2613 basename=${sf%%.F}
2614 isAD=`egrep ^$basename.f'[ ]*' adSrcFiles.tmp`
2615 if test -z "$isAD" ; then
2616 toBeIgnored=`egrep ^$basename'[ ]*' ${OAD_DONT_COMPILE}`
2617 if test -z "$toBeIgnored" ; then
2618 echo " \\" >> nonADF77srclist.tmp
2619 printf " $sf" >> nonADF77srclist.tmp
2620 else
2621 echo " not to be compiled : $sf"
2622 fi
2623 else # file is initially listed as an AD file we want to exclude it
2624 # or we want to retain the untransformed version
2625 notToBeTransformed=`egrep ^$basename'[ ]*' ${OAD_DONT_TRANSFORM}`
2626 untransformedVersionToBeKept=`egrep ^$basename'[ ]*' ${OAD_KEEP_ORIGINAL}`
2627 if test -n "$notToBeTransformed"; then
2628 echo " not to be transformed: $sf"
2629 fi
2630 if test -n "$untransformedVersionToBeKept" ; then
2631 echo " original to be kept : $sf"
2632 fi
2633 if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then
2634 echo " \\" >> nonADF77srclist.tmp
2635 printf " $sf" >> nonADF77srclist.tmp
2636 fi
2637 fi
2638 fi
2639 ;;
2640 F90)
2641 echo " \\" >> F90srclist.tmp
2642 printf " $sf" >> F90srclist.tmp
2643 ;;
2644 c)
2645 echo " \\" >> csrclist.tmp
2646 printf " $sf" >> csrclist.tmp
2647 ;;
2648 h)
2649 echo " \\" >> hsrclist.tmp
2650 printf " $sf" >> hsrclist.tmp
2651 ;;
2652 flow)
2653 echo " \\" >> ad_flow_files.tmp
2654 printf " $sf" >> ad_flow_files.tmp
2655 ;;
2656 esac
2657 fi
2658 fi
2659 fi
2660 done
2661 if test "x$deplist" != x ; then
2662 if test "$d" != "." ; then
2663 echo "" >> srclinks.tmp
2664 echo "# These files are linked from $d" >> srclinks.tmp
2665 echo "$deplist :" >> srclinks.tmp
2666 # We need to make sure that the link isn't already there.
2667 # This may happen when make thinks that a header file has to be "remade"
2668 # because a module it depends on has changed. In this case we do nothing.
2669 printf "\tif [ ! -L \$@ ]; then \$(LN) %s/\$@ \$@; fi\n" $d >> srclinks.tmp
2670 fi
2671 fi
2672 done
2673 rm -rf .links.tmp
2674 echo "" >> F77srclist.tmp
2675 echo "" >> nonADF77srclist.tmp
2676 echo "" >> csrclist.tmp
2677 echo "" >> F90srclist.tmp
2678 echo "" >> hsrclist.tmp
2679 echo "" >> ad_flow_files.tmp
2680
2681 CMDLINE=$0
2682 for xx in "$@" ; do nw=`echo $xx | wc -w`
2683 if test $nw = '1' ; then CMDLINE="$CMDLINE $xx"
2684 else CMDLINE="$CMDLINE '$xx'" ; fi
2685 done
2686
2687 if test -f $MAKEFILE ; then
2688 mv -f $MAKEFILE "$MAKEFILE.old"
2689 fi
2690 echo " Writing makefile: $MAKEFILE"
2691 echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
2692 echo "# $MACHINE" >> $MAKEFILE
2693 echo "# This makefile was generated automatically on" >> $MAKEFILE
2694 echo "# $THISDATE" >> $MAKEFILE
2695 echo "# by the command:" >> $MAKEFILE
2696 echo "# $CMDLINE" >> $MAKEFILE
2697 echo "# executed by:" >> $MAKEFILE
2698 echo "# ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
2699
2700 EXE_AD=$EXECUTABLE"_ad"
2701 EXE_FTL=$EXECUTABLE"_ftl"
2702 EXE_SVD=$EXECUTABLE"_svd"
2703
2704 cat >>$MAKEFILE <<EOF
2705 #
2706 # OPTFILE="$OPTFILE"
2707 #
2708 # BUILDDIR : Directory where object files are written
2709 # SOURCEDIRS : Directories containing the source (.F) files
2710 # INCLUDEDIRS : Directories containing the header-source (.h) files
2711 # EXEDIR : Directory where executable that is generated is written
2712 # EXECUTABLE : Full path of executable binary
2713 #
2714 # CPP : C-preprocessor command
2715 # INCLUDES : Directories searched for header files
2716 # DEFINES : Macro definitions for CPP
2717 # MAKEDEPEND : Dependency generator
2718 # KPP : Special preprocessor command (specific to platform)
2719 # KFLAGS : Flags for KPP
2720 # FC : Fortran compiler command
2721 # FFLAGS : Configuration/debugging options for FC
2722 # FOPTIM : Optimization options for FC
2723 # LINK : Command for link editor program
2724 # LIBS : Library flags /or/ additional optimization/debugging flags
2725
2726 ROOTDIR = ${ROOTDIR}
2727 BUILDDIR = ${BUILDDIR}
2728 SOURCEDIRS = ${SOURCEDIRS}
2729 INCLUDEDIRS = ${INCLUDEDIRS}
2730 EXEDIR = ${EXEDIR}
2731 EXECUTABLE = \$(EXEDIR)/${EXECUTABLE}
2732 TOOLSDIR = ${TOOLSDIR}
2733
2734 #eh3 new defines for the adjoint work
2735 AUTODIFF = ${ROOTDIR}/pkg/autodiff
2736 EXE_AD = ${EXE_AD}
2737 EXE_FTL = ${EXE_FTL}
2738 EXE_SVD = ${EXE_SVD}
2739
2740 ENABLED_PACKAGES = ${ENABLED_PACKAGES}
2741 DISABLED_PACKAGES = ${DISABLED_PACKAGES}
2742
2743 # These files are created by Makefile
2744 SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
2745 EOF
2746
2747 if test "x$EMBED_SRC" = xt ; then
2748 echo "EMBEDDED_FILES = EMBEDDED_FILES.h" >>$MAKEFILE
2749 else
2750 echo "EMBEDDED_FILES = " >>$MAKEFILE
2751 fi
2752
2753 cat >>$MAKEFILE <<EOF
2754 # Unix ln (link)
2755 LN = ${LN}
2756 # C preprocessor
2757 CPP = cat \$< | ${S64} | ${CPP}
2758 # Dependency generator
2759 MAKEDEPEND = ${MAKEDEPEND}
2760 # Special preprocessor (KAP on DECs, FPP on Crays)
2761 KPP = ${KPP}
2762 # Fortran compiler
2763 FC = ${FC}
2764 # Fortran compiler
2765 F90C = ${F90C}
2766 # C compiler
2767 CC = ${CC}
2768 # Link editor
2769 LINK = ${LINK} ${LDADD}
2770
2771 # Defines for CPP
2772 DEFINES = ${DEFINES}
2773 # Includes for CPP
2774 INCLUDES = ${INCLUDES}
2775 # Flags for KPP
2776 KFLAGS1 = ${KFLAGS1}
2777 KFLAGS2 = ${KFLAGS2}
2778 # Optim./debug for FC
2779 FFLAGS = ${FFLAGS} ${FEXTRAFLAGS}
2780 FOPTIM = ${FOPTIM}
2781 # Optim./debug for FC
2782 F90FLAGS = ${F90FLAGS}
2783 F90OPTIM = ${F90OPTIM}
2784 F90FIXEDFORMAT = ${F90FIXEDFORMAT}
2785 # Flags for CC
2786 CFLAGS = ${CFLAGS}
2787 # Files that should not be optimized
2788 NOOPTFILES = ${NOOPTFILES}
2789 NOOPTFLAGS = ${NOOPTFLAGS}
2790 # Flags and libraries needed for linking
2791 LIBS = ${LIBS}
2792 # Name of the makefile
2793 MAKEFILE=${MAKEFILE}
2794
2795 EOF
2796
2797 cat F77srclist.tmp >> $MAKEFILE
2798 cat nonADF77srclist.tmp >> $MAKEFILE
2799 cat csrclist.tmp >> $MAKEFILE
2800 cat F90srclist.tmp >> $MAKEFILE
2801 cat hsrclist.tmp >> $MAKEFILE
2802 cat ad_flow_files.tmp >> $MAKEFILE
2803
2804 rm -f F77srclist.tmp nonADF77srclist.tmp csrclist.tmp F90srclist.tmp hsrclist.tmp ad_flow_files.tmp
2805
2806 echo >> $MAKEFILE
2807
2808 # add definitions for preprocessed sources
2809 # and note that not all systems allow case sensitive extensions
2810 # hence the $FS and $FS90 here.
2811 # for fixed format f90 files we use ff90 or FF90 resp
2812 # but these are not expected to be the original source files
2813
2814 echo 'F77_PP_SRC_FILES = $(F77_SRC_FILES:.F=.'$FS')' >> $MAKEFILE
2815 echo 'F90_PP_SRC_FILES = $(F90_SRC_FILES:.F90=.'$FS90')' >> $MAKEFILE
2816 echo 'OBJFILES= $(F77_SRC_FILES:.F=.o) $(C_SRC_FILES:.c=.o) $(F90_SRC_FILES:.F90=.o)' >> $MAKEFILE
2817 echo 'FLOWFILES = $(AD_FLOW_FILES:.flow=.flowdir)' >> $MAKEFILE
2818 echo >> $MAKEFILE
2819 echo '.SUFFIXES:' >> $MAKEFILE
2820 echo '.SUFFIXES: .o .'$FS' .p .F .c .f'$FS90' .'$FS90' .FF90 .F90 .flowdir .flow' >> $MAKEFILE
2821
2822 cat >>$MAKEFILE <<EOF
2823
2824 all: \$(EXECUTABLE)
2825 \$(EXECUTABLE): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(OBJFILES) \$(EMBEDDED_FILES)
2826 @echo Creating \$@ ...
2827 \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2828
2829 depend:
2830 @make -f \$(MAKEFILE) links
2831 \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
2832 \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2833 -rm -f makedepend.out
2834
2835 lib: libmitgcmuv.a
2836
2837 libmitgcmuv.a: \$(OBJFILES)
2838 ar rcv libmitgcmuv.a \$(OBJFILES)
2839 ar d libmitgcmuv.a main.o
2840
2841 obj: \$(OBJFILES)
2842
2843 links: \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(SPECIAL_FILES)
2844
2845 small_f: \$(F77_PP_SRC_FILES) \$(F90_PP_SRC_FILES)
2846
2847 output.txt: \$(EXECUTABLE)
2848 @printf 'running ... '
2849 @\$(EXECUTABLE) > \$@
2850
2851 # remove most of the files that "make" generates
2852 clean:
2853 -rm -rf *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
2854 -rm -rf *.o
2855 -rm -rf *.$FS *.flowdir
2856 -rm -rf *.f$FS90 \$(AD_CLEAN) ad_input*
2857
2858 # remove most of the files that "make" and "make depend" generate
2859 Clean:
2860 @make -f \$(MAKEFILE) clean
2861 @make -f \$(MAKEFILE) cleanlinks
2862 -rm -f \$(SPECIAL_FILES) f90mkdepend.log $MAKEFILE.old
2863 -rm -f taf_command taf_output taf_ad.log taf_ad_flow.log taf_ftl.log
2864 -rm -f genmake_warnings genmake_errors make.log
2865
2866 # remove also the executable, files that "genmake2" generates (except Makefile)
2867 # and output from a run (plus log files from testreport)
2868 CLEAN:
2869 @make -f \$(MAKEFILE) Clean
2870 -rm -f \$(EXECUTABLE) \$(EXE_AD) \$(EXE_FTL) *.bak
2871 -rm -f $LOGFILE genmake_state genmake_*optfile
2872 -rm -f SIZE.h.mpi genmake.tr_log make.tr_log
2873 -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2874 -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2875 -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2876 -rm -f *.txt STD* *diagnostics.log datetime
2877 -rm -f *_MIT_CE_000.opt0000 costfunction*0000
2878 -rm -rf mnc_test_*
2879
2880 makefile:
2881 $THIS_SCRIPT $G2ARGS
2882 cleanlinks:
2883 -find . -type l -exec rm {} \;
2884
2885 # Special targets (SPECIAL_FILES) which are created by make
2886 ${PACKAGES_DOT_H}:
2887 @echo Creating \$@ ...
2888 @$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) > \$@
2889 AD_CONFIG.h:
2890 @echo Creating \$@ ...
2891 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > \$@
2892 FC_NAMEMANGLE.h:
2893 @echo Creating \$@ ...
2894 echo "$FC_NAMEMANGLE" > \$@
2895
2896 BUILD_INFO.h:
2897 @echo Creating \$@ ...
2898 EOF
2899
2900 test ! "x$THISVER" = x && echo " -echo \"#define THISVER '$THISVER'\" > \$@" >> $MAKEFILE
2901 test ! "x$THISUSER" = x && echo " -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
2902 test ! "x$THISDATE" = x && echo " -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2903 test ! "x$THISHOST" = x && echo " -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2904
2905 if test "x$EMBED_SRC" = xt ; then
2906 cat >>$MAKEFILE <<EOF
2907
2908 decode_files.o : EMBEDDED_FILES.h
2909
2910 ## \$(F77_PP_SRC_FILES)
2911 all_fF.tar.gz : \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
2912 @echo Creating \$@ ...
2913 -tar -hcf all_fF.tar \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
2914 -rm -f all_fF.tar.gz
2915 -gzip all_fF.tar
2916
2917 EMBEDDED_FILES.h : all_fF.tar.gz
2918 @echo Creating \$@ ...
2919 -\${ROOTDIR}/tools/embed_encode/encode_files EMBEDDED_FILES.h all_fF.tar.gz
2920
2921 EOF
2922 fi
2923
2924 cat >>$MAKEFILE <<EOF
2925
2926 # The normal chain of rules is ( .F - .$FS - .o )
2927
2928 ## This nullifies any default implicit rules concerning these two file types:
2929 ## %.o : %.F
2930
2931 .F.$FS:
2932 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2933 .$FS.o:
2934 \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2935 .F.o:
2936 \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2937 .F90.$FS90:
2938 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2939 .FF90.f$FS90:
2940 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2941 .$FS90.o:
2942 \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
2943 .f$FS90.o:
2944 cp \$< \$(basename \$<).f90
2945 \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$(F90FIXEDFORMAT) \$(basename \$<).f90
2946 .c.o:
2947 \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$<
2948 .flow.flowdir:
2949 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2950
2951 # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
2952 .F.p:
2953 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2954 .p.$FS:
2955 \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
2956
2957 EOF
2958
2959 #=========================================
2960 #=== Automatic Differentiation Rules ===
2961 #=== for TAMC/TAF ======================
2962
2963 if test "x$OPENAD" = x ; then
2964
2965 cat >>$MAKEFILE <<EOF
2966
2967 TAMC = ${TAMC}
2968 TAF = ${TAF}
2969
2970 TAF_EXTRA = ${TAF_EXTRA}
2971 TAMC_EXTRA = ${TAMC_EXTRA}
2972
2973 EOF
2974
2975 ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
2976 ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
2977 ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
2978 for i in $ad_vars ; do
2979 name=$i
2980 t1="t2=\$"`echo "$i"`
2981 eval $t1
2982 printf "%-20s = " $name >> $MAKEFILE
2983 echo "$t2" | sed -e 's| \+| |g' >> $MAKEFILE
2984 done
2985
2986 echo " Add the source list for AD code generation"
2987 echo >> $MAKEFILE
2988 printf "AD_FILES = " >> $MAKEFILE
2989 AD_FILES=`cat adSrcFiles.tmp`
2990 for i in $AD_FILES ; do
2991 echo " \\" >> $MAKEFILE
2992 printf " $i" >> $MAKEFILE
2993 done
2994 echo >> $MAKEFILE
2995 rm -f adSrcFiles.tmp
2996
2997 cat >>$MAKEFILE <<EOF
2998
2999 # ... AD ...
3000 adall: \$(EXE_AD)
3001 adtaf: ad_taf_output.$FS
3002 adtamc: ad_tamc_output.$FS
3003
3004 ad_input_code.$FS: \$(AD_FILES) \$(H_SRC_FILES) \$(AD_FLOW_FILES)
3005 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3006 cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3007 -rm -f ad_config.template
3008 @make -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3009 @make -f \$(MAKEFILE) \$(FLOWFILES)
3010 cat \$(FLOWFILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ad_input_code.$FS
3011
3012 ad_taf_output.$FS: ad_input_code.$FS
3013 \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3014 ls -l ad_input_code_ad.$FS
3015 cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
3016
3017 adtafonly:
3018 \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3019 ls -l ad_input_code_ad.$FS
3020 cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
3021
3022 \${EXE_AD}: ad_taf_output.o \$(OBJFILES)
3023 \$(LINK) -o \${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
3024
3025 ad_tamc_output.$FS: ad_input_code.$FS
3026 \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
3027 cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
3028
3029 ad_tamc: ad_tamc_output.o \$(OBJFILES)
3030 \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
3031
3032 adonlyfwd:
3033 patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
3034
3035 adtrick:
3036 patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
3037
3038 adobj: ad_taf_output.o \$(OBJFILES)
3039
3040 # ... FTL ...
3041 ftlall: \$(EXE_FTL)
3042 ftltaf: ftl_taf_output.$FS
3043 ftltamc: ftl_tamc_output.$FS
3044
3045 ftl_input_code.$FS: \$(AD_FILES) \$(H_SRC_FILES)
3046 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ftl_config.template
3047 cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
3048 -rm -f ftl_config.template
3049 @make -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3050 @make -f \$(MAKEFILE) \$(AD_FLOW_FILES)
3051 cat \$(AD_FLOW_FILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ftl_input_code.$FS
3052
3053 ftl_taf_output.$FS: ftl_input_code.$FS
3054 \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3055 ls -l ftl_input_code_ftl.$FS
3056 cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3057
3058 ftltafonly:
3059 \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3060 ls -l ftl_input_code_ftl.$FS
3061 cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3062
3063 \${EXE_FTL}: ftl_taf_output.o \$(OBJFILES)
3064 \$(LINK) -o \${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
3065
3066 ftl_tamc_output.$FS: ftl_input_code.$FS
3067 \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
3068 cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
3069
3070 ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
3071 \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
3072
3073 # ... SVD ...
3074 svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
3075 @echo "--->>> Only ran TAF to generate SVD code! <<<---"
3076 @echo "--->>> Do make svdall afterwards to compile. <<<---"
3077 svdall: svd_touch svd_taf
3078
3079 svd_taf: \$(OBJFILES)
3080 \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
3081
3082 @echo "--->>> Only COMPILE svd code! <<<---"
3083 @echo "--->>> Assumes you previously <<<---"
3084 @echo "--->>> did make svdtaf <<<---"
3085
3086 svd_touch:
3087 @echo "--->>> Only COMPILE svd code! <<<---"
3088 @echo "--->>> Assumes you previously <<<---"
3089 @echo "--->>> did make svdtaf <<<---"
3090 touch ad_taf_output.$FS ftl_taf_output.$FS
3091 \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
3092 \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
3093 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ftl_config.template
3094 cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
3095 -rm -f ftl_config.template
3096
3097 EOF
3098
3099 fi
3100
3101 #=== for OpenAD ========================
3102
3103 if test "x$OPENAD" != x ; then
3104
3105 # ============ begin OpenAD specific section ==============
3106
3107 cat >>$MAKEFILE <<EOF
3108
3109 # all the source files linked from the various locations:
3110 ALL_LINKED_FILES= \
3111 \$(F77_SRC_FILES) \
3112 \$(C_SRC_FILES) \
3113 \$(H_SRC_FILES) \
3114 \$(F90_SRC_FILES) \
3115 \$(SPECIAL_FILES)
3116
3117 ifndef OPENADROOT
3118 \$(error "Error: environment variable OPENADROOT not defined!")
3119 endif
3120
3121 ifndef XAIFSCHEMAROOT
3122 \$(error "Error: environment variable XAIFSCHEMAROOT not defined!")
3123 endif
3124
3125 ifndef XAIFBOOSTERROOT
3126 \$(error "Error: environment variable XAIFBOOSTERROOT not defined!")
3127 endif
3128
3129 EOF
3130
3131 echo " Add the source list for common block to module conversion "
3132 echo >> $MAKEFILE
3133 printf "CB2M_F90_SRC_NAMES = " >> $MAKEFILE
3134 for i in `cat ${OAD_CB2M_FILES}` ; do
3135 echo " \\" >> $MAKEFILE
3136 printf " $i" >> $MAKEFILE
3137 done
3138 echo >> $MAKEFILE
3139
3140 echo " Add the source list for AD code generation"
3141 echo >> $MAKEFILE
3142 printf "AD_FILES = " >> $MAKEFILE
3143 for i in `cat ${OAD_CB2M_FILES}` ; do
3144 echo " \\" >> $MAKEFILE
3145 printf " ${i}_mod.f$FS90" >> $MAKEFILE
3146 done
3147 AD_FILES=`cat adSrcFiles.tmp`
3148 for i in $AD_FILES ; do
3149 basename=${i%%.f}
3150 toBeIgnored=`egrep ^$basename'[ ]*' ${OAD_DONT_COMPILE} ${OAD_DONT_TRANSFORM}`
3151 if test -z "$toBeIgnored" ; then
3152 echo " \\" >> $MAKEFILE
3153 printf " $i" >> $MAKEFILE
3154 fi
3155 done
3156 echo >> $MAKEFILE
3157 rm -f adSrcFiles.tmp
3158
3159 cat >>$MAKEFILE <<EOF
3160
3161 adAll: \$(EXE_AD)
3162 .PHONY: adAll
3163
3164 CB2M_F90_PP_SRC_FILES=\$(addsuffix _mod.f$FS90, \$(CB2M_F90_SRC_NAMES))
3165
3166 .PRECIOUS: \$(CB2M_F90_PP_SRC_FILES) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90)
3167
3168 .PHONY: adDepend
3169 adDepend: \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(addsuffix _mod.FF90, \$(CB2M_F90_SRC_NAMES)) \$(F77_SRC_FILES:.F=_cb2m.FF90)
3170 \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
3171 \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
3172 -rm -f makedepend.out
3173
3174 OPENAD_SUPPORT_F90_SRC_FILES = \
3175 w2f__types.F90 \
3176 OAD_active.F90 \
3177 OAD_cp.F90 \
3178 OAD_rev.F90 \
3179 OAD_tape.F90
3180
3181 OPENAD_SUPPORT_C_SRC_FILES = \
3182 iaddr.c \
3183 timeRatio.c
3184
3185 f95_test_mods.f90: \$(OPENAD_SUPPORT_F90_SRC_FILES:F90=$FS90)
3186 cat \$^ > \$@
3187
3188 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
3189 cat \$^ > \$@
3190
3191 f95_test.out: f95_test_mods.f90 f95_test.f90
3192 f95 -fixed -w=unused -maxcontin=132 -c f95_test_mods.f90 > \$@ 2>&1
3193 f95 -fixed -w=unused -maxcontin=132 -c -fixed f95_test.f90 >> \$@ 2>&1
3194
3195 CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.f$FS90)
3196
3197 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)
3198
3199 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)
3200
3201 \$(EXE_AD): \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) postProcess.tag \$(AD_OBJ_FILES_S2)
3202 \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES_S2) \$(LIBS)
3203
3204 # create sources files modules from header files containing common blocks
3205 %_mod.FF90 : %.h ../OAD_support/cb2mGetModules.csh ../OAD_support/cb2mGetModules.awk
3206 ../OAD_support/cb2mGetModules.csh $< ../OAD_support/cb2mGetModules.awk
3207
3208 # create new header files with USE statements for the new modules made above
3209 %_mod.h : %.h ../OAD_support/cb2mGetHeaders.csh ../OAD_support/cb2mGetHeaders.awk
3210 ../OAD_support/cb2mGetHeaders.csh $< ../OAD_support/cb2mGetHeaders.awk \$(CB2M_F90_SRC_NAMES)
3211
3212 # change the include directives of everybody to refer to the new header files with the USE statements
3213 %_cb2m.FF90 : %.F ../OAD_support/cb2mUseModules.bash
3214 ../OAD_support/cb2mUseModules.bash $< ${MPI}
3215
3216 # makefile debug rule
3217 small_f: \$(CB2M_F90_PP_SRC_FILES)
3218 .PHONY: small_f
3219
3220 ad_output.txt: \$(EXE_AD)
3221 @printf 'linking data files ... '
3222 \$(LN) -f ../input_ad/data* ../input_ad/eedata .
3223 \$(LN) -f ../../global_ocean.90x40x15/input/*.bin .
3224 @printf 'running ... '
3225 @./\$(EXE_AD) > \$@
3226
3227 ad_input_code.f$FS90: \$(CB2M_AD_FILES)
3228 cat \$^ > \$@
3229
3230 # canonicalizer
3231 ad_input_code_sf.pre.f90 : \$(CB2M_AD_FILES)
3232 \${OPENADFORTTK_BASE}/tools/SourceProcessing/preProcess.py --timing --r8 -H -S -o \$@ \$^
3233
3234 # replace stop statements (to avoid the implied unstructured control flow) with print statements
3235 ad_input_code_sf.pre.s2p.f90 : ad_input_code_sf.pre.f90
3236 cat \$< | sed -f ../OAD_support/stop2print.sed > ad_input_code_sf.pre.s2p.f90
3237
3238 # F -> WHIRL
3239 ad_input_code_sf.pre.s2p.B: ad_input_code_sf.pre.s2p.f90
3240 \${OPEN64ROOT}/crayf90/sgi/mfef90 -r8 -z -F ad_input_code_sf.pre.s2p.f90
3241
3242 # WHIRL -> XAIF
3243 ad_input_code_sf.pre.s2p.xaif : ad_input_code_sf.pre.s2p.B
3244 \${OPENADFORTTK}/bin/whirl2xaif -s -n --debug 1 -o \$@ \$<
3245
3246 # XAIF -> XAIF'
3247 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
3248 \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/driver/oadDriver -f -t forward_step -i \$< -c \${XAIFSCHEMAROOT}/schema/examples/inlinable_intrinsics.xaif -o \$@ -I -r
3249
3250 # XAIF' -> WHIRL'
3251 ad_input_code_sf.pre.s2p.xb.x2w.B : ad_input_code_sf.pre.s2p.xb.xaif
3252 \${OPENADFORTTK}/bin/xaif2whirl --debug 1 ad_input_code_sf.pre.s2p.B \$<
3253
3254 # WHIRL' -> F'
3255 ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS90: ad_input_code_sf.pre.s2p.xb.x2w.B
3256 \${OPEN64ROOT}/whirl2f/whirl2f -FLIST:ftn_file=\$@ -openad \$<
3257
3258 # insert template directives
3259 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
3260 ../OAD_support/insertTemplateDir.bash \$< \$@
3261
3262 PPEXTRAS=\$(wildcard ../OAD_support/ad_template.*.F) ../OAD_support/ad_inline.F
3263 # postprocess F'
3264 postProcess.tag: ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90 \$(PPEXTRAS:.F=.f) | w2f__types.f90
3265 \${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 \$<
3266 # the target is a placeholder to trigger a single execution of the rule
3267 touch \$@
3268 # put this so make knows about the postprocessing output
3269 OAD_intrinsics_oad.f \$(CB2M_AD_FILES:.f$FS90=_oad.f): postProcess.tag
3270
3271 # link the XAIF schema files
3272 %.xsd:
3273 \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ .
3274
3275 # link the support files:
3276 \$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES):
3277 \$(LN) ../OAD_support/\$@ .
3278
3279 AD_CLEAN += *_mod.h *_mod.F90 *.FF90 *.mod-whirl temp.sed oad_cp.* postProcess.tag \$(PPEXTRAS:.F=.f)
3280
3281 # ============ end OpenAD specific section ==============
3282
3283 EOF
3284
3285 fi
3286
3287 #=========================================
3288
3289 if test "x$EXEHOOK" != x ; then
3290 printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
3291 fi
3292
3293 echo " Making list of \"exceptions\" that need \".p\" files"
3294 for i in $KPPFILES ; do
3295 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
3296 RETVAL=$?
3297 if test "x$RETVAL" != x0 ; then
3298 echo "Error: unable to add file \"$i\" to the exceptions list"
3299 fi
3300 echo "$base.$FS: $base.p" >> $MAKEFILE
3301 done
3302
3303 echo " Making list of NOOPTFILES"
3304 for i in $NOOPTFILES ; do
3305 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
3306 RETVAL=$?
3307 if test "x$RETVAL" != x0 ; then
3308 echo "Error: unable to add file \"$i\" to the exceptions list"
3309 fi
3310 echo "$base.o: $base.$FS" >> $MAKEFILE
3311 printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
3312 done
3313
3314 echo " Add rules for links"
3315 cat srclinks.tmp >> $MAKEFILE
3316 rm -f srclinks.tmp
3317
3318 echo " Adding makedepend marker"
3319 printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
3320
3321 printf "\n=== Done ===\n"
3322
3323 # Create special header files
3324 $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"
3325 if test ! -f $PACKAGES_DOT_H ; then
3326 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
3327 else
3328 cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
3329 RETVAL=$?
3330 if test "x$RETVAL" = x0 ; then
3331 rm -f $PACKAGES_DOT_H".tmp"
3332 else
3333 mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
3334 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
3335 fi
3336 fi
3337 if test ! -f AD_CONFIG.h ; then
3338 $BASH $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > AD_CONFIG.h
3339 fi
3340
3341 # Write the "state" for future records
3342 if test "x$DUMPSTATE" = xt ; then
3343 printf "" > genmake_state
3344 for i in $gm_state ; do
3345 t1="t2=\$$i"
3346 eval $t1
3347 echo "$i='$t2'" | sed -e 's/ */ /g' >> genmake_state
3348 done
3349 fi

  ViewVC Help
Powered by ViewVC 1.1.22