/[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.212 - (show annotations) (download)
Thu Nov 4 18:01:22 2010 UTC (13 years, 4 months ago) by jmc
Branch: MAIN
Changes since 1.211: +79 -68 lines
- in get_fortran_c_namemangling: use "$CC $CFLAG" to compile C test programm
  (instead of "$MAKE genmake_test.o", since a pre-existing Makefile can be wrong)
- when looking for an optfile (not specified), only search for Fortran compiler
  (remove sym-link test + setting of CPP + makedepend check + C-compiler check).
- set default CPP to "cpp -traditional -P" (was the case without specifying
  an optfile, but otherwise default was just "cpp").
- when "CC" is not set in the optfile, look for possible C compiler
  (instead of just setting CC=cc).
- comment out PLATFORM=$p_PLATFORM (no idea where p_PLATFORM comes from).

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

  ViewVC Help
Powered by ViewVC 1.1.22