/[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.77 - (show annotations) (download)
Thu Apr 8 23:48:43 2004 UTC (15 years, 3 months ago) by edhill
Branch: MAIN
CVS Tags: checkpoint52m_post
Changes since 1.76: +26 -10 lines
 o MITgcm now builds and runs on cygwin
   - Note that there is still a problem due to directories in
     verification named "aux".  Apparently, windows is such
     broken crap that that you cannot use "aux" as a file or
     dir name.  In the mean time, check out the code using:
       cvs co MITgcm_verif_basic
     and you can avoid those directories.

1 #! /usr/bin/env bash
2 #
3 # $Header: /u/gcmpack/MITgcm/tools/genmake2,v 1.76 2004/04/08 21:32:11 edhill 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" || exit 99
17 test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg" || exit 99
18 test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg" || exit 99
19 test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg" || exit 99
20 }
21
22 # Search for particular CPP #cmds associated with MPI
23 # usage: test_for_mpi_in_cpp_eeoptions CPP_file
24 test_for_mpi_in_cpp_eeoptions() {
25 cpp_options=$1
26 test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI" || exit 99
27 test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI" || exit 99
28 test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI" || exit 99
29 test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI" || exit 99
30 }
31
32 # Search for particular string in a file. Return 1 if detected, 0 if not
33 # usage: test_for_string_in_file file string
34 test_for_string_in_file() {
35 file=$1
36 strng=$2
37 grep -i "$strng" $file > /dev/null 2>&1
38 RETVAL=$?
39 if test "x${RETVAL}" = x0 ; then
40 printf "Error: In $file there is an illegal line: "
41 grep -i "$strng" $file
42 return 1
43 fi
44 return 0
45 }
46
47 # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to
48 # the package list.
49 expand_pkg_groups() {
50 new_packages=
51 PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"
52 if test -r $PKG_GROUPS ; then
53 cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp
54 cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp
55 matched=0
56 for i in $PACKAGES ; do
57 line=`grep "^ *$i" ./p2.tmp`
58 RETVAL=$?
59 if test "x$RETVAL" = x0 ; then
60 matched=1
61 replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`
62 echo " replacing \"$i\" with: $replace"
63 new_packages="$new_packages $replace"
64 else
65 new_packages="$new_packages $i"
66 fi
67 done
68 PACKAGES=$new_packages
69 rm -f ./p[1,2].tmp
70 return $matched
71 else
72 echo "Warning: can't read package groups definition file: $PKG_GROUPS"
73 fi
74 }
75
76 # Check for broken environments (eg. cygwin, MacOSX w/HFS+) that
77 # cannot distinguish [*.F/*.F90] from [*.f/*.f90] files.
78 check_for_broken_Ff() {
79 # Do we have defaults for $FS and/or $FS90 ?
80 tfs=f
81 tfs9=f90
82 if test "x$FS" != x ; then
83 tfs="$FS"
84 fi
85 if test "x$FS90" != x ; then
86 tfs9="$FS90"
87 fi
88
89 # First check the ability to create a *.F/.f pair.
90 cat <<EOF >> genmake_hello.F
91 program hello
92 write(*,*) 'hi'
93 stop
94 end
95 EOF
96 cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1
97 RETVAL=$?
98 if test "x$RETVAL" != x0 ; then
99 if test "x$FS" = x ; then
100 FS='for'
101 FS90='fr9'
102 check_for_broken_Ff
103 else
104 cat <<EOF 2>&1
105 ERROR: Your file system cannot distinguish between *.F and *.f files
106 (fails the "cp" test) and this program cannot find a suitable
107 replacement extension. Please try a different build environment or
108 contact the <MITgcm-support@mitgcm.org> list for help.
109
110 EOF
111 exit -1
112 fi
113 return
114 fi
115 rm -f genmake_hello.*
116
117 # Check the ability of ${MAKE} and ${LN} to use the current set
118 # of extensions.
119 cat <<EOF >> genmake_hello.F
120 program hello
121 write(*,*) 'hi'
122 stop
123 end
124 EOF
125 test -e Makefile && mv -f Makefile Makefile.bak
126 cat <<EOF >> Makefile
127 %.$tfs : %.F
128 .SUFFIXES:
129 genmake_hello.$tfs: genmake_hello.F
130 $LN genmake_hello.F genmake_hello.$tfs
131 EOF
132 $MAKE "genmake_hello."$tfs > /dev/null 2>&1
133 RETVAL=$?
134 if test "x$RETVAL" != x0 -o ! -e "genmake_hello."$tfs ; then
135 if test "x$FS" = x ; then
136 FS='for'
137 FS90='fr9'
138 check_for_broken_Ff
139 else
140 cat <<EOF 2>&1
141 ERROR: Your file system cannot distinguish between *.F and *.f files
142 (fails the "make/ln" test) and this program cannot find a suitable
143 replacement extension. Please try a different build environment or
144 contact the <MITgcm-support@mitgcm.org> list for help.
145
146 EOF
147 exit -1
148 return
149 fi
150 fi
151 rm -f genmake_hello.* Makefile
152 test -e Makefile && mv -f Makefile.bak Makefile
153
154 # If we make it here, use the extensions
155 FS=$tfs
156 FS90=$tfs9
157 return
158 }
159
160
161 # Guess possible config options for this host
162 find_possible_configs() {
163
164 tmp1=`uname`"_"`uname -m`
165 tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
166 tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
167 tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
168 tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
169 tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
170 PLATFORM=$tmp3
171 echo $PLATFORM | grep cygwin > /dev/null 2>&1 && PLATFORM=cygwin_ia32
172 OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
173 echo " The platform appears to be: $PLATFORM"
174
175 echo "test" > test
176 ln -s ./test link
177 RETVAL=$?
178 if test "x${RETVAL}" = x0 ; then
179 LN="ln -s"
180 else
181 echo "Error: \"ln -s\" does not appear to work on this system!"
182 echo " For help, please contact <MITgcm-support@mitgcm.org>."
183 exit 1
184 fi
185 rm -f test link
186
187 if test "x$CPP" = x ; then
188 CPP="cpp -traditional -P"
189 fi
190
191 # The "original" makedepend is part of the Imake system that is
192 # most often distributed with XFree86 or with an XFree86 source
193 # package. As a result, many machines (eg. generic Linux) do not
194 # have a system-default "makedepend" available. For those
195 # systems, we have two fall-back options:
196 #
197 # 1) a makedepend implementation shipped with the cyrus-imapd
198 # package: ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
199 #
200 # 2) a known-buggy xmakedpend shell script
201 #
202 # So the choices are, in order:
203 #
204 # 1) use the user-specified program
205 # 2) use a system-wide default
206 # 3) locally build and use the cyrus implementation
207 # 4) fall back to the buggy local xmakedpend script
208 #
209 if test "x${MAKEDEPEND}" = x ; then
210 which makedepend > /dev/null 2>&1
211 RV0=$?
212 cat <<EOF >> genmake_tc.f
213 program test
214 write(*,*) 'test'
215 stop
216 end
217 EOF
218 makedepend genmake_tc.f > /dev/null 2>&1
219 RV1=$?
220 if test ! "x${RV0}${RV1}" = x00 ; then
221 echo " a system-default makedepend was not found."
222
223 # Try to build the cyrus impl
224 rm -f ./genmake_cy_md
225 (
226 cd $ROOTDIR/tools/cyrus-imapd-makedepend \
227 && ./configure > /dev/null 2>&1 \
228 && make > /dev/null 2>&1
229 if test -x ./makedepend.exe ; then
230 $LN ./makedepend.exe ./makedepend
231 fi
232 ./makedepend ifparser.c > /dev/null 2>&1 \
233 && echo "true"
234 ) > ./genmake_cy_md
235 grep true ./genmake_cy_md > /dev/null 2>&1
236 RETVAL=$?
237 if test "x$RETVAL" = x0 ; then
238 MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
239 else
240 MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
241 fi
242 rm -f ./genmake_cy_md
243 fi
244 fi
245
246 # look for possible fortran compilers
247 tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"
248 p_FC=
249 for c in $tmp ; do
250 rm -f ./hello.f ./hello
251 cat >> hello.f <<EOF
252 program hello
253 do i=1,3
254 print *, 'hello world : ', i
255 enddo
256 end
257 EOF
258 $c -o hello hello.f > /dev/null 2>&1
259 RETVAL=$?
260 if test "x${RETVAL}" = x0 ; then
261 p_FC="$p_FC $c"
262 fi
263 done
264 rm -f ./hello.f ./hello
265 if test "x${p_FC}" = x ; then
266 cat 1>&2 <<EOF
267
268 Error: No Fortran compilers were found in your path. Please specify one using:
269
270 1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
271 2) a command-line option (eg. "-fc NAME"), or
272 3) the MITGCM_FC environment variable.
273
274 EOF
275 exit 1
276 else
277 echo " The possible FORTRAN compilers found in your path are:"
278 echo " "$p_FC
279 if test "x$FC" = x ; then
280 FC=`echo $p_FC | $AWK '{print $1}'`
281 echo " Setting FORTRAN compiler to: "$FC
282 fi
283 fi
284
285 if test "x$OPTFILE" = x ; then
286 OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
287 if test ! -r $OPTFILE ; then
288 echo " I looked for the file "$OPTFILE" but did not find it"
289 fi
290 fi
291 # echo " The options file: $p_OF"
292 # echo " appears to match so we'll use it."
293 # for i in $p_FC ; do
294 #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
295 #if test -r $p_OF ; then
296 # OPTFILE=$p_OF
297 # echo " The options file: $p_OF"
298 # echo " appears to match so we'll use it."
299 # break
300 #fi
301 # done
302 if test "x$OPTFILE" = x ; then
303 cat 1>&2 <<EOF
304
305 Error: No options file was found in: $ROOTDIR/tools/build_options/
306 that matches this platform ("$PLATFORM") and the compilers found in
307 your path. Please specify an "optfile" using:
308
309 1) the command line (eg. "-optfile=path/to/OPTFILE"), or
310 2) the MITGCM_OF environment variable.
311
312 If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
313
314 EOF
315 exit 1
316 fi
317
318 # # look for possible MPI libraries
319 # mpi_libs=
320 # mpi_fort=`which mpif77 2>/dev/null`
321 # RETVAL=$?
322 # if test "x${RETVAL}" = x0 ; then
323 # cat >>test.f <<EOF
324 # PROGRAM HELLO
325 # DO 10, I=1,10
326 # PRINT *,'Hello World'
327 # 10 CONTINUE
328 # STOP
329 # END
330 # EOF
331 # eval "$mpi_fort -showme test.f > out"
332 # RETVAL=$?
333 # if test "x${RETVAL}" = x0 ; then
334 # a=`cat out`
335 # for i in $a ; do
336 # case $i in
337 # -*)
338 # mpi_libs="$mpi_libs $i" ;;
339 # esac
340 # done
341 # echo "The MPI libs appear to be:"
342 # echo " "$mpi_libs
343 # fi
344 # rm -f test.f out
345 # fi
346
347 }
348
349 # Parse the package dependency information
350 get_pdepend_list() {
351
352 # strip the comments and then convert the dependency file into
353 # two arrays: PNAME, DNAME
354 cat $1 | sed -e 's/#.*$//g' \
355 | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \
356 > ./.pd_tmp
357 . ./.pd_tmp
358 rm -f ./.pd_tmp
359
360 printf "PNAME = "${}
361 }
362
363
364 # Explain usage
365 usage() {
366 cat <<EOF
367
368 Usage: "$0" [OPTIONS]
369 where [OPTIONS] can be:
370
371 -help | --help | -h | --h
372 Print this help message and exit.
373
374 -nooptfile | --nooptfile
375 -optfile NAME | --optfile NAME | -of NAME | --of NAME
376 -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
377 Use "NAME" as the optfile. By default, an attempt will be
378 made to find an appropriate "standard" optfile in the
379 tools/build_options/ directory.
380
381 -pdepend NAME | --pdepend NAME
382 -pdepend=NAME | --pdepend=NAME
383 Get package dependency information from "NAME".
384
385 -pdefault NAME | --pdefault NAME
386 -pdefault=NAME | --pdefault=NAME
387 Get the default package list from "NAME".
388
389 -make NAME | -m NAME
390 --make=NAME | -m=NAME
391 Use "NAME" for the MAKE program. The default is "make" but
392 many platforms, "gmake" is the preferred choice.
393
394 -makefile NAME | -mf NAME
395 --makefile=NAME | -mf=NAME
396 Call the makefile "NAME". The default is "Makefile".
397
398 -makedepend NAME | -md NAME
399 --makedepend=NAME | -md=NAME
400 Use "NAME" for the MAKEDEPEND program.
401
402 -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
403 -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
404 Specify the location of the MITgcm ROOTDIR as "NAME".
405 By default, genamke will try to find the location by
406 looking in parent directories (up to the 5th parent).
407
408 -mods NAME | --mods NAME | -mo NAME | --mo NAME
409 -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
410 Here, "NAME" specifies a list of directories that are
411 used for additional source code. Files found in the
412 "mods list" are given preference over files of the same
413 name found elsewhere.
414
415 -disable NAME | --disable NAME
416 -disable=NAME | --disable=NAME
417 Here "NAME" specifies a list of packages that we don't
418 want to use. If this violates package dependencies,
419 genamke will exit with an error message.
420
421 -enable NAME | --enable NAME
422 -enable=NAME | --enable=NAME
423 Here "NAME" specifies a list of packages that we wish
424 to specifically enable. If this violates package
425 dependencies, genamke will exit with an error message.
426
427 -standarddirs NAME | --standarddirs NAME
428 -standarddirs=NAME | --standarddirs=NAME
429 Here, "NAME" specifies a list of directories to be
430 used as the "standard" code.
431
432 -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
433 -fc=NAME | --fc=NAME
434 Use "NAME" as the fortran compiler. By default, genmake
435 will search for a working compiler by trying a list of
436 "usual suspects" such as g77, f77, etc.
437
438 -[no]ieee | --[no]ieee
439 Do or don't use IEEE numerics. Note that this option
440 *only* works if it is supported by the OPTFILE that
441 is being used.
442
443 -mpi | --mpi
444 Include MPI header files and link to MPI libraries
445 -mpi=PATH | --mpi=PATH
446 Include MPI header files and link to MPI libraries using MPI_ROOT
447 set to PATH. i.e. Include files from $PATH/include, link to libraries
448 from $PATH/lib and use binaries from $PATH/bin.
449
450 -bash NAME
451 Explicitly specify the Bourne or BASH shell to use
452
453 While it is most often a single word, the "NAME" variables specified
454 above can in many cases be a space-delimited string such as:
455
456 --enable pkg1 --enable 'pkg1 pkg2' --enable 'pkg1 pkg2 pkg3'
457 -mods=dir1 -mods='dir1' -mods='dir1 dir2 dir3'
458 -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
459
460 which, depending upon your shell, may need to be single-quoted.
461
462 For more detailed genmake documentation, please see:
463
464 http://mitgcm.org/devel_HOWTO/
465
466 EOF
467
468 exit 1
469 }
470
471 # Build a CPP macro to automate calling C routines from FORTRAN
472 get_fortran_c_namemangling() {
473 default_nm="#define FC_NAMEMANGLE(X) X ## _"
474
475 cat > genmake_test.c <<EOF
476 void tcall( char * string ) { tsub( string ); }
477 EOF
478 $MAKE genmake_test.o >> genmake_warnings 2>&1
479 RETVAL=$?
480 if test "x$RETVAL" != x0 ; then
481 FC_NAMEMANGLE=$default_nm
482 cat <<EOF>> genmake_errors
483
484 WARNING: C test compile fails
485 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
486 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
487 EOF
488 return 1
489 fi
490 c_tcall=`nm genmake_test.o | grep 'T ' | grep tcall | cut -d ' ' -f 3`
491 RETVAL=$?
492 if test "x$RETVAL" != x0 ; then
493 FC_NAMEMANGLE=$default_nm
494 cat <<EOF>> genmake_warnings
495
496 WARNING: The "nm" command failed.
497 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
498 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
499 EOF
500 return 1
501 fi
502 cat > genmake_tcomp.f <<EOF
503 subroutine tcall( string )
504 character*(*) string
505 call tsub( string )
506 end
507 EOF
508 $FC $FFLAGS $DEFINES -c genmake_tcomp.f >> genmake_warnings 2>&1
509 RETVAL=$?
510 if test "x$RETVAL" != x0 ; then
511 FC_NAMEMANGLE=$default_nm
512 cat <<EOF>> genmake_warnings
513
514 WARNING: FORTRAN test compile fails -- please see "genmake_errors"
515 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
516 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
517 EOF
518 return 1
519 fi
520 f_tcall=`nm genmake_tcomp.o | grep 'T ' | grep tcall | cut -d ' ' -f 3`
521 RETVAL=$?
522 if test "x$RETVAL" != x0 ; then
523 FC_NAMEMANGLE=$default_nm
524 cat <<EOF>> genmake_warnings
525
526 WARNING: The "nm" command failed.
527 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
528 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
529 EOF
530 return 1
531 fi
532
533 c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
534 f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
535 c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
536 f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
537
538 nmangle="X"
539 if test "x$c_a" != "x$f_a" ; then
540 comm="echo x$f_a | sed -e 's|x$c_a||'"
541 a=`eval $comm`
542 nmangle="$a ## $nmangle"
543 fi
544 if test "x$c_b" != "x$f_b" ; then
545 comm="echo x$f_b | sed -e 's|x$c_b||'"
546 b=`eval $comm`
547 nmangle="$nmangle ## $b"
548 fi
549
550 FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) $nmangle"
551
552 # cleanup the testing files
553 rm -f genmake_tcomp.* genmake_test.*
554 }
555
556
557 check_HAVE_CLOC() {
558 get_fortran_c_namemangling
559 cat <<EOF > genmake_tc_1.c
560 $FC_NAMEMANGLE
561 #include <stdio.h>
562 #include <stdlib.h>
563 #include <unistd.h>
564 #include <assert.h>
565 #include <sys/time.h>
566 void FC_NAMEMANGLE(cloc) ( double *curtim )
567 {
568 struct timeval tv1;
569 gettimeofday(&tv1 , (void *)NULL );
570 *curtim = (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
571 *curtim = *curtim/1.E6;
572 }
573 EOF
574 make genmake_tc_1.o >> genmake_tc.log 2>&1
575 RET_C=$?
576 cat <<EOF > genmake_tc_2.f
577 program hello
578 Real*8 wtime
579 external cloc
580 call cloc(wtime)
581 print *," HELLO WORLD", wtime
582 end program hello
583 EOF
584 $FC $FFLAGS -o genmake_tc genmake_tc_2.f genmake_tc_1.o >> genmake_tc.log 2>&1
585 RET_F=$?
586 test -x ./genmake_tc && ./genmake_tc >> genmake_tc.log 2>&1
587 RETVAL=$?
588 if test "x$RETVAL" = x0 ; then
589 HAVE_CLOC=t
590 DEFINES="$DEFINES -DHAVE_CLOC"
591 fi
592 rm -f genmake_tc*
593 }
594
595
596 check_netcdf_libs() {
597 cat <<EOF > genmake_tnc.for
598 program fgennc
599 #include "netcdf.inc"
600 integer iret, ncid, xid
601 iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
602 IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
603 iret = nf_def_dim(ncid, 'X', 11, xid)
604 IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
605 iret = nf_close(ncid)
606 IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
607 end
608 EOF
609 $CPP genmake_tnc.for > genmake_tnc.f \
610 && $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f $LIBS >> genmake_tnc.log 2>&1
611 RET_COMPILE=$?
612 test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1
613 RETVAL=$?
614 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
615 HAVE_NETCDF=t
616 else
617 # try again with "-lnetcdf" added to the libs
618 $CPP genmake_tnc.for > genmake_tnc.f \
619 && $FC $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.f \
620 $LIBS -lnetcdf >> genmake_tnc_2.log 2>&1
621 RET_COMPILE=$?
622 test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1
623 RETVAL=$?
624 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
625 LIBS="$LIBS -lnetcdf"
626 HAVE_NETCDF=t
627 else
628 cat genmake_tnc.log >> genmake_warnings
629 fi
630 fi
631 rm -f genmake_tnc*
632 }
633
634
635
636 ###############################################################################
637 # Sequential part of script starts here
638 ###############################################################################
639
640 # Set defaults here
641 COMMANDL="$0 $@"
642
643 PLATFORM=
644 LN=
645 S64=
646 KPP=
647 FC=
648 CPP=
649 LINK=
650 DEFINES=
651 PACKAGES=
652 ENABLE=
653 DISABLE=
654 MAKEFILE=
655 MAKEDEPEND=
656 PDEPEND=
657 DUMPSTATE=t
658 PDEFAULT=
659 OPTFILE=
660 INCLUDES="-I."
661 FFLAGS=
662 FOPTIM=
663 CFLAGS=
664 KFLAGS1=
665 KFLAGS2=
666 #LDADD=
667 LIBS=
668 KPPFILES=
669 NOOPTFILES=
670 NOOPTFLAGS=
671 MPI=
672 MPIPATH=
673
674 # DEFINES checked by test compilation
675 HAVE_SYSTEM=
676 HAVE_FDATE=
677 FC_NAMEMANGLE=
678 HAVE_CLOC=
679 HAVE_NETCDF=
680
681 MODS=
682 TOOLSDIR=
683 SOURCEDIRS=
684 INCLUDEDIRS=
685 STANDARDDIRS="USE_THE_DEFAULT"
686
687 G2ARGS=
688 BASH=
689 PWD=`pwd`
690 MAKE=make
691 AWK=awk
692 THISHOSTNAME=`hostname`
693 THISCWD=`pwd`
694 THISDATE=`date`
695 MACHINE=`uname -a`
696 EXECUTABLE=
697 EXEHOOK=
698 EXEDIR=
699 PACKAGES_CONF=
700 IEEE=
701 if test "x$MITGCM_IEEE" != x ; then
702 IEEE=$MITGCM_IEEE
703 fi
704 FS=
705 FS90=
706
707 AUTODIFF_PKG_USED=f
708 AD_OPTFILE=
709 TAF=
710 AD_TAF_FLAGS=
711 FTL_TAF_FLAGS=
712 SVD_TAF_FLAGS=
713 TAF_EXTRA=
714 TAMC=
715 AD_TAMC_FLAGS=
716 FTL_TAF_FLAGS=
717 SVD_TAMC_FLAGS=
718 TAMC_EXTRA=
719
720
721 # The following state can be set directly by command-line switches
722 gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
723 gm_s2="FC CPP IEEE MPI JAM DUMPSTATE STANDARDDIRS"
724
725 # The following state is not directly set by command-line switches
726 gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
727 gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
728 gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"
729 gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
730 gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE"
731
732 # The following are all related to adjoint/tangent-linear stuff
733 gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
734 gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
735 gm_s12="TAF_EXTRA TAMC_EXTRA"
736
737 gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
738 gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
739
740 cat <<EOF
741
742 GENMAKE :
743
744 A program for GENerating MAKEfiles for the MITgcm project. For a
745 quick list of options, use "genmake -h" or for more detail see:
746
747 http://mitgcm.org/devel_HOWTO/
748
749 EOF
750
751 echo "=== Processing options files and arguments ==="
752 gm_local="genmake_local"
753 for i in . $MODS ; do
754 if test -r $i/$gm_local ; then
755 . $i/$gm_local
756 break
757 fi
758 done
759 printf " getting local config information: "
760 if test -e $gm_local ; then
761 echo "using $gm_local"
762 . $gm_local
763 # echo "DISABLE=$DISABLE"
764 # echo "ENABLE=$ENABLE"
765 else
766 echo "none found"
767 fi
768
769 # echo "$0::$1:$2:$3:$4:$5:$6:$7:"
770 #OPTIONS=
771 #n=0
772 #for i ; do
773 # echo "$i $n"
774 # setvar="OPTIONS[$n]='$i'"
775 # # echo " $setvar"
776 # eval "$setvar"
777 # n=$(( $n + 1 ))
778 #done
779 #parse_options
780 ac_prev=
781 for ac_option ; do
782
783 G2ARGS="$G2ARGS \"$ac_option\""
784
785 # If the previous option needs an argument, assign it.
786 if test -n "$ac_prev"; then
787 eval "$ac_prev=\$ac_option"
788 ac_prev=
789 continue
790 fi
791
792 ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
793
794 case $ac_option in
795
796 -help | --help | -h | --h)
797 usage ;;
798
799 -nooptfile | --nooptfile)
800 OPTFILE="NONE" ;;
801 -optfile | --optfile | -of | --of)
802 ac_prev=OPTFILE ;;
803 -optfile=* | --optfile=* | -of=* | --of=*)
804 OPTFILE=$ac_optarg ;;
805
806 -adoptfile | --adoptfile | -adof | --adof)
807 ac_prev=AD_OPTFILE ;;
808 -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
809 AD_OPTFILE=$ac_optarg ;;
810
811 -pdepend | --pdepend)
812 ac_prev=PDEPEND ;;
813 -pdepend=* | --pdepend=*)
814 PDEPEND=$ac_optarg ;;
815
816 -pdefault | --pdefault)
817 ac_prev=PDEFAULT ;;
818 -pdefault=* | --pdefault=*)
819 PDEFAULT=$ac_optarg ;;
820
821 -make | --make | -m | --m)
822 ac_prev=MAKE ;;
823 -make=* | --make=* | -m=* | --m=*)
824 MAKE=$ac_optarg ;;
825
826 -bash | --bash)
827 ac_prev=BASH ;;
828 -bash=* | --bash=*)
829 BASH=$ac_optarg ;;
830
831 -makedepend | --makedepend | -md | --md)
832 ac_prev=MAKEDEPEND ;;
833 -makedepend=* | --makedepend=* | -md=* | --md=*)
834 MAKEDEPEND=$ac_optarg ;;
835
836 -makefile | --makefile | -ma | --ma)
837 ac_prev=MAKEFILE ;;
838 -makefile=* | --makefile=* | -ma=* | --ma=*)
839 MAKEFILE=$ac_optarg ;;
840
841 -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
842 echo "ERROR: The platform option has been removed. Please specify"
843 echo " the build options using the \"optfile\" mechanism."
844 echo
845 usage
846 ;;
847
848 -rootdir | --rootdir | -rd | --rd)
849 ac_prev=ROOTDIR ;;
850 -rootdir=* | --rootdir=* | -rd=* | --rd=*)
851 ROOTDIR=$ac_optarg ;;
852
853 -mods | --mods | -mo | --mo)
854 ac_prev=MODS ;;
855 -mods=* | --mods=* | -mo=* | --mo=*)
856 MODS=$ac_optarg ;;
857
858 -disable | --disable)
859 ac_prev=DISABLE ;;
860 -disable=* | --disable=*)
861 DISABLE=$ac_optarg ;;
862
863 -enable | --enable)
864 ac_prev=ENABLE ;;
865 -enable=* | --enable=*)
866 ENABLE=$ac_optarg ;;
867
868 -standarddirs | --standarddirs)
869 ac_prev=STANDARDDIRS ;;
870 -standarddirs=* | --standarddirs=*)
871 STANDARDDIRS=$ac_optarg ;;
872
873 # -cpp | --cpp)
874 # ac_prev=cpp ;;
875 # -cpp=* | --cpp=*)
876 # CPP=$ac_optarg ;;
877
878 -fortran | --fortran | -fc | --fc)
879 ac_prev=FC ;;
880 -fc=* | --fc=*)
881 FC=$ac_optarg ;;
882
883 -fs | --fs)
884 ac_prev=FS ;;
885 -fs=* | --fs=*)
886 FS=$ac_optarg ;;
887
888 -fs90 | --fs90)
889 ac_prev=FS90 ;;
890 -fs90=* | --fs90=*)
891 FS90=$ac_optarg ;;
892
893 -ieee | --ieee)
894 IEEE=true ;;
895 -noieee | --noieee)
896 IEEE= ;;
897
898 -mpi | --mpi)
899 MPI=true ;;
900 -mpi=* | --mpi=*)
901 MPIPATH=$ac_optarg
902 MPI=true ;;
903
904 # -jam | --jam)
905 # JAM=1 ;;
906 # -nojam | --nojam)
907 # JAM=0 ;;
908
909 -ds | --ds)
910 DUMPSTATE=t ;;
911
912 -taf_extra | --taf_extra)
913 ac_prev=TAF_EXTRA ;;
914 -taf_extra=* | --taf_extra=*)
915 TAF_EXTRA=$ac_optarg ;;
916
917 -tamc_extra | --tamc_extra)
918 ac_prev=TAMC_EXTRA ;;
919 -tamc_extra=* | --tamc_extra=*)
920 TAMC_EXTRA=$ac_optarg ;;
921
922 -*)
923 echo "Error: unrecognized option: "$ac_option
924 usage
925 ;;
926
927 *)
928 echo "Error: unrecognized argument: "$ac_option
929 usage
930 ;;
931
932 esac
933
934 done
935
936 if test -f ./.genmakerc ; then
937 echo
938 echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
939 echo " file. This file format is no longer supported. Please see:"
940 echo
941 echo " http://mitgcm.org/devel_HOWTO/"
942 echo
943 echo " for directions on how to setup and use the new \"genmake2\" input"
944 echo " files and send an email to MITgcm-support@mitgcm.org if you want help."
945 echo
946 fi
947
948 if test "x${ROOTDIR}" = x ; then
949 if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
950 ROOTDIR=".."
951 else
952 for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
953 if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
954 ROOTDIR=$d
955 printf "Warning: ROOTDIR was not specified but there appears to be"
956 echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
957 break
958 fi
959 done
960 fi
961 fi
962 if test "x${ROOTDIR}" = x ; then
963 echo "Error: Cannot determine ROOTDIR for MITgcm code."
964 echo " Please specify a ROOTDIR using either an options "
965 echo " file or a command-line option."
966 exit 1
967 fi
968 if test ! -d ${ROOTDIR} ; then
969 echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
970 exit 1
971 fi
972
973 echo " getting OPTFILE information: "
974 if test "x${OPTFILE}" = x ; then
975 if test "x$MITGCM_OF" = x ; then
976 echo "Warning: no OPTFILE specified so we'll look for possible settings"
977 printf "\n=== Searching for possible settings for OPTFILE ===\n"
978 find_possible_configs
979 else
980 OPTFILE=$MITGCM_OF
981 fi
982 fi
983 if test "x$OPTFILE" != xNONE ; then
984 if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
985 echo " using OPTFILE=\"$OPTFILE\""
986 . "$OPTFILE"
987 RETVAL=$?
988 if test "x$RETVAL" != x0 ; then
989 printf "Error: failed to source OPTFILE \"$OPTFILE\""
990 echo "--please check that variable syntax is bash-compatible"
991 exit 1
992 fi
993 if test "x$DUMPSTATE" != xf ; then
994 cp -f $OPTFILE "genmake_optfile"
995 fi
996 else
997 echo "Error: can't read OPTFILE=\"$OPTFILE\""
998 exit 1
999 fi
1000 fi
1001
1002 # Check for broken systems that cannot correctly distinguish *.F and *.f files
1003 # check_for_broken_Ff
1004
1005 echo " getting AD_OPTFILE information: "
1006 if test "x${AD_OPTFILE}" = x ; then
1007 if test "x$MITGCM_AD_OF" = x ; then
1008 AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
1009 else
1010 AD_OPTFILE=$MITGCM_AD_OF
1011 fi
1012 fi
1013 if test "x${AD_OPTFILE}" != xNONE ; then
1014 if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
1015 echo " using AD_OPTFILE=\"$AD_OPTFILE\""
1016 . "$AD_OPTFILE"
1017 RETVAL=$?
1018 if test "x$RETVAL" != x0 ; then
1019 printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1020 echo "--please check that variable syntax is bash-compatible"
1021 exit 1
1022 fi
1023 if test "x$DUMPSTATE" != xf ; then
1024 cp -f $AD_OPTFILE "genmake_ad_optfile"
1025 fi
1026 else
1027 echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
1028 exit 1
1029 fi
1030 fi
1031
1032 # Check that FC, LINK, CPP, S64, LN, and MAKE are defined. If not,
1033 # either set defaults or complain and abort!
1034 if test ! "x$BASH" = x ; then
1035 # add a trailing space so that it works within the Makefile syntax (see below)
1036 BASH="$BASH "
1037 fi
1038 if test "x$FC" = x ; then
1039 cat <<EOF 1>&2
1040
1041 Error: no Fortran compiler: please specify using one of the following:
1042 1) within the options file ("FC=...") as specified by "-of=OPTFILE"
1043 2) the "-fc=XXX" command-line option
1044 3) the "./genmake_local" file
1045 EOF
1046 exit 1
1047 fi
1048 if test "x$LINK" = x ; then
1049 LINK=$FC
1050 fi
1051 if test "x$MAKE" = x ; then
1052 MAKE="make"
1053 fi
1054 if test "x$CPP" = x ; then
1055 CPP=cpp
1056 fi
1057 #EH3 === UGLY ===
1058 # The following is an ugly little hack to check for $CPP in /lib/ and
1059 # it should eventually be replaced with a more general function that
1060 # searches a combo of the user's path and a list of "usual suspects"
1061 # to find the correct location for binaries such as $CPP.
1062 for i in " " "/lib/" ; do
1063 echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1064 done
1065 #EH3 === UGLY ===
1066 echo "#define A a" | $CPP > test_cpp 2>&1
1067 RETVAL=$?
1068 if test "x$RETVAL" != x0 ; then
1069 cat <<EOF 1>&2
1070
1071 Error: C pre-processor "$CPP" failed the test case: please specify using:
1072
1073 1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1074 2) the "./genmake_local" file
1075 3) with the CPP environment variable
1076
1077 EOF
1078 exit 1
1079 else
1080 rm -f test_cpp
1081 fi
1082 if test "x$MAKEDEPEND" = x ; then
1083 MAKEDEPEND=makedepend
1084 fi
1085 if test "x$LN" = x ; then
1086 LN="ln -s"
1087 fi
1088 echo "test" > genmake_test_ln
1089 $LN genmake_test_ln genmake_tlink
1090 RETVAL=$?
1091 if test "x$RETVAL" != x0 ; then
1092 cat <<EOF 1>&2
1093
1094 Error: The command "ln -s" failed -- please specify a working soft-link
1095 command in the optfile.
1096
1097 EOF
1098 exit 1
1099 fi
1100 rm -f genmake_test_ln genmake_tlink
1101
1102 # Check for broken *.F/*.f handling and fix if possible
1103 check_for_broken_Ff
1104
1105 if test ! "x$MPI" = x ; then
1106 echo " Turning on MPI cpp macros"
1107 DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1108 fi
1109
1110 printf "\n=== Checking system libraries ===\n"
1111 printf " Do we have the system() command using $FC... "
1112 cat > genmake_tcomp.f <<EOF
1113 program hello
1114 call system('echo hi')
1115 end
1116 EOF
1117 $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
1118 RETVAL=$?
1119 if test "x$RETVAL" = x0 ; then
1120 HAVE_SYSTEM=t
1121 DEFINES="$DEFINES -DHAVE_SYSTEM"
1122 echo "yes"
1123 else
1124 HAVE_SYSTEM=
1125 echo "no"
1126 fi
1127 rm -f genmake_tcomp*
1128
1129 printf " Do we have the fdate() command using $FC... "
1130 cat > genmake_tcomp.f <<EOF
1131 program hello
1132 CHARACTER(128) string
1133 string = ' '
1134 call fdate( string )
1135 print *, string
1136 end
1137 EOF
1138 $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
1139 RETVAL=$?
1140 if test "x$RETVAL" = x0 ; then
1141 HAVE_FDATE=t
1142 DEFINES="$DEFINES -DHAVE_FDATE"
1143 echo "yes"
1144 else
1145 HAVE_FDATE=
1146 echo "no"
1147 fi
1148 rm -f genmake_tcomp*
1149
1150 printf " Can we call simple C routines (here, \"cloc()\") using $FC... "
1151 check_HAVE_CLOC
1152 if test "x$HAVE_CLOC" != x ; then
1153 echo "yes"
1154 else
1155 echo "no"
1156 fi
1157 rm -f genmake_t*
1158
1159 printf " Can we create NetCDF-enabled binaries... "
1160 check_netcdf_libs
1161 if test "x$HAVE_NETCDF" != x ; then
1162 echo "yes"
1163 else
1164 echo "no"
1165 fi
1166
1167
1168 printf "\n=== Setting defaults ===\n"
1169 printf " Adding MODS directories: "
1170 for d in $MODS ; do
1171 if test ! -d $d ; then
1172 echo
1173 echo "Error: MODS directory \"$d\" not found!"
1174 exit 1
1175 else
1176 printf " $d"
1177 SOURCEDIRS="$SOURCEDIRS $d"
1178 INCLUDEDIRS="$INCLUDEDIRS $d"
1179 fi
1180 done
1181 echo
1182
1183 if test "x$MAKEFILE" = x ; then
1184 MAKEFILE="Makefile"
1185 fi
1186 if test "x${PLATFORM}" = x ; then
1187 PLATFORM=$p_PLATFORM
1188 fi
1189
1190 if test "x${EXEDIR}" = x ; then
1191 if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then
1192 EXEDIR=../exe
1193 else
1194 EXEDIR=.
1195 fi
1196 fi
1197 if test ! -d ${EXEDIR} ; then
1198 echo "Error: the specified EXEDIR (\"$EXEDIR\") does not exist!"
1199 exit 1
1200 fi
1201
1202 if test "x${TOOLSDIR}" = x ; then
1203 TOOLSDIR="$ROOTDIR/tools"
1204 fi
1205 if test ! -d ${TOOLSDIR} ; then
1206 echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1207 exit 1
1208 fi
1209 if test "x$S64" = x ; then
1210 S64='$(TOOLSDIR)/set64bitConst.sh'
1211 fi
1212 THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1213
1214 EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1215
1216 # We have a special set of source files in eesupp/src which are
1217 # generated from some template source files. We'll make them first so
1218 # they appear as regular source code
1219 if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
1220 echo " Making source files in eesupp from templates"
1221 ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
1222 RETVAL=$?
1223 if test "x${RETVAL}" = x0 ; then
1224 rm -f make_eesupp.errors
1225 else
1226 echo "Error: problem encountered while building source files in eesupp:"
1227 cat make_eesupp.errors 1>&2
1228 exit 1
1229 fi
1230 fi
1231
1232 #same for exch2
1233 if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then
1234 echo " Making source files in exch2 from templates"
1235 ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1
1236 RETVAL=$?
1237 if test "x${RETVAL}" = x0 ; then
1238 rm -f make_exch2.errors
1239 else
1240 echo "Error: problem encountered while building source files in exch2:"
1241 cat make_exch2.errors 1>&2
1242 exit 1
1243 fi
1244 fi
1245
1246 printf "\n=== Determining package settings ===\n"
1247 if test "x${PDEPEND}" = x ; then
1248 tmp=$ROOTDIR"/pkg/pkg_depend"
1249 if test -r $tmp ; then
1250 PDEPEND=$tmp
1251 else
1252 echo "Warning: No package dependency information was specified."
1253 echo " Please check that ROOTDIR/pkg/pkg_depend exists."
1254 fi
1255 else
1256 if test ! -r ${PDEPEND} ; then
1257 echo "Error: can't read package dependency info from PDEPEND=\"$PDEPEND\""
1258 exit 1
1259 fi
1260 fi
1261 echo " getting package dependency info from $PDEPEND"
1262 # Strip the comments and then convert the dependency file into
1263 # two arrays: PNAME, DNAME
1264 cat $PDEPEND | sed -e 's/#.*$//g' \
1265 | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
1266 > ./.pd_tmp
1267 RETVAL=$?
1268 if test ! "x${RETVAL}" = x0 ; then
1269 echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
1270 exit 1
1271 fi
1272 . ./.pd_tmp
1273 rm -f ./.pd_tmp
1274
1275 # Search for default packages. Note that a "$ROOTDIR/pkg/pkg_groups"
1276 # file should eventually be added so that, for convenience, one can
1277 # specify groups of packages using names like "ocean" and "atmosphere".
1278 echo " checking default package list: "
1279 if test "x${PDEFAULT}" = x ; then
1280 for i in "." $MODS ; do
1281 if test -r $i"/packages.conf" ; then
1282 PDEFAULT=$i"/packages.conf"
1283 break
1284 fi
1285 done
1286 fi
1287 if test "x${PDEFAULT}" = x ; then
1288 PDEFAULT="$ROOTDIR/pkg/pkg_default"
1289 fi
1290 if test "x${PDEFAULT}" = xNONE ; then
1291 echo " default packages file disabled"
1292 else
1293 if test ! -r $PDEFAULT ; then
1294 echo "Warning: can't read default packages from PDEFAULT=\"$PDEFAULT\""
1295 else
1296 echo " using PDEFAULT=\"$PDEFAULT\""
1297 # Strip the comments and add all the names
1298 def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1299 RETVAL=$?
1300 if test "x${RETVAL}" != x0 ; then
1301 printf "Error: can't parse default package list "
1302 echo "-- please check PDEFAULT=\"$PDEFAULT\""
1303 exit 1
1304 fi
1305 for i in $def ; do
1306 PACKAGES="$PACKAGES $i"
1307 done
1308 echo " before group expansion packages are: $PACKAGES"
1309 while ! expand_pkg_groups; do echo > /dev/null; done
1310 echo " after group expansion packages are: $PACKAGES"
1311 fi
1312 fi
1313
1314 echo " applying DISABLE settings"
1315 for i in $PACKAGES ; do
1316 echo $i >> ./.tmp_pack
1317 done
1318 for i in `grep "-" ./.tmp_pack` ; do
1319 j=`echo $i | sed 's/[-]//'`
1320 DISABLE="$DISABLE $j"
1321 done
1322 pack=
1323 for p in $PACKAGES ; do
1324 addit="t"
1325 for d in $DISABLE ; do
1326 if test "x$p" = "x$d" ; then
1327 addit="f"
1328 fi
1329 done
1330 if test "x$addit" = xt ; then
1331 pack="$pack $p"
1332 fi
1333 done
1334 PACKAGES="$pack"
1335 echo " applying ENABLE settings"
1336 echo "" > ./.tmp_pack
1337 PACKAGES="$PACKAGES $ENABLE"
1338 # Test if each explicitly referenced package exists
1339 for i in $PACKAGES ; do
1340 j=`echo $i | sed 's/[-+]//'`
1341 if test ! -d "$ROOTDIR/pkg/$j" ; then
1342 echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
1343 exit 1
1344 fi
1345 echo $i >> ./.tmp_pack
1346 done
1347 PACKAGES=
1348 for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
1349 PACKAGES="$PACKAGES $i"
1350 done
1351 rm -f ./.tmp_pack
1352 echo " packages are: $PACKAGES"
1353
1354 echo " applying package dependency rules"
1355 ck=
1356 while test "x$ck" != xtt ; do
1357 i=0
1358 # rtot=${#PNAME[@]}
1359 rtot=$nname
1360 while test $i -lt $rtot ; do
1361
1362 # Is $pname in the current $PACKAGES list?
1363 # pname=${PNAME[$i]}
1364 tmp="pname=\"\$PNAME_$i\""
1365 eval $tmp
1366 pin="f"
1367 for p in $PACKAGES ; do
1368 if test "x$p" = "x$pname" ; then
1369 pin="t"
1370 fi
1371 done
1372
1373 # Is the DNAME entry a (+) or (-) rule ?
1374 tmp="dname=\"\$DNAME_$i\""
1375 eval $tmp
1376 plus="-"
1377 echo $dname | grep '^+' > /dev/null 2>&1
1378 RETVAL=$?
1379 if test "x$RETVAL" = x0 ; then
1380 plus="+"
1381 fi
1382
1383 # Is $dname in the current $PACKAGES list?
1384 dname=`echo $dname | sed -e 's/^[+-]//'`
1385 din="f"
1386 for p in $PACKAGES ; do
1387 if test "x$p" = "x$dname" ; then
1388 din="t"
1389 fi
1390 done
1391
1392 # Do we need to add $dname according to the dependency rules?
1393 if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
1394 in_dis="f"
1395 for dis in $DISABLE ; do
1396 if test "x$dis" = "x$dname" ; then
1397 in_dis="t"
1398 fi
1399 done
1400 if test "x$in_dis" = xt ; then
1401 echo "Error: can't satisfy package dependencies:"
1402 echo " \"$dname\" is required by the dependency rules"
1403 echo " but is disallowed by the DISABLE settings"
1404 exit 1
1405 else
1406 PACKAGES="$PACKAGES $dname"
1407 ck=
1408 fi
1409 fi
1410
1411 # Do we need to get rid of $dname according to the dependency rules?
1412 if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
1413 echo "Error: can't satisfy package dependencies:"
1414 echo " \"$pname\" was requested but is disallowed by"
1415 echo " the dependency rules for \"$dname\""
1416 exit 1
1417 fi
1418 i=$(( $i + 1 ))
1419 done
1420 ck=$ck"t"
1421 done
1422 echo " packages are: $PACKAGES"
1423 for i in $PACKAGES ; do
1424 adr="$ROOTDIR/pkg/$i"
1425 if test -d $adr ; then
1426 SOURCEDIRS="$SOURCEDIRS $adr"
1427 INCLUDEDIRS="$INCLUDEDIRS $adr"
1428 if test "x$i" = xautodiff ; then
1429 AUTODIFF_PKG_USED=t
1430 fi
1431 else
1432 echo "Error: the directory \"$adr\" for package $i doesn't exist"
1433 exit 1
1434 fi
1435 done
1436
1437 # Build MNC templates and check for ability to build and use NetCDF
1438 echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1439 RETVAL=$?
1440 if test "x$RETVAL" = x0 ; then
1441 ( cd $ROOTDIR"/pkg/mnc" && $MAKE templates ) > make_mnc.errors 2>&1
1442 RETVAL=$?
1443 if test "x${RETVAL}" = x0 ; then
1444 rm -f make_mnc.errors
1445 else
1446 echo "Error: problem encountered while building source files in pkg/mnc:"
1447 cat make_mnc.errors 1>&2
1448 exit 1
1449 fi
1450 if test "x$HAVE_NETCDF" != xt ; then
1451 cat <<EOF
1452
1453 WARNING: the "mnc" package has been enabled but tests failed to
1454 compile and/or execute NetCDF applications. Please check that:
1455
1456 1) NetCDF is installed for your compiler and
1457 2) the LIBS variable (within the 'optfile") specifies the correct
1458 NetCDF library to link against.
1459
1460 EOF
1461 fi
1462 fi
1463
1464 # Create a list of #define and #undef to enable/disable packages
1465 PACKAGES_DOT_H=PACKAGES_CONFIG.h
1466 # The following UGLY HACK sets multiple "#undef"s and it needs to go
1467 # away. On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
1468 # file would eventually be split up so that all package-related #define
1469 # statements could be separated and handled only by genmake.
1470 names=`ls -1 "$ROOTDIR/pkg"`
1471 all_pack=
1472 DISABLED_PACKAGES=
1473 for n in $names ; do
1474 if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
1475 has_pack="f"
1476 for pack in $PACKAGES ; do
1477 if test "x$pack" = "x$n" ; then
1478 has_pack="t"
1479 break
1480 fi
1481 done
1482 if test "x$has_pack" = xf ; then
1483 undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`
1484 DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
1485 fi
1486 fi
1487 done
1488 ENABLED_PACKAGES=
1489 for i in $PACKAGES ; do
1490 def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`
1491 ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
1492 #eh3 DEFINES="$DEFINES -D$def"
1493
1494 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
1495 case $i in
1496 aim_v23)
1497 ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
1498 echo "Warning: ALLOW_AIM is set to enable aim_v23."
1499 ;;
1500 esac
1501 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
1502
1503 done
1504
1505 echo " Adding STANDARDDIRS"
1506 BUILDDIR=${BUILDDIR:-.}
1507 if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
1508 STANDARDDIRS="eesupp model"
1509 fi
1510 if test "x$STANDARDDIRS" != x ; then
1511 for d in $STANDARDDIRS ; do
1512 adr="$ROOTDIR/$d/src"
1513 if test ! -d $adr ; then
1514 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1515 echo " is correct and that you correctly specified the STANDARDDIRS option"
1516 exit 1
1517 else
1518 SOURCEDIRS="$SOURCEDIRS $adr"
1519 fi
1520 adr="$ROOTDIR/$d/inc"
1521 if test ! -d $adr ; then
1522 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1523 echo " is correct and that you correctly specified the STANDARDDIRS option"
1524 exit 1
1525 else
1526 INCLUDEDIRS="$INCLUDEDIRS $adr"
1527 fi
1528 done
1529 fi
1530
1531 echo " Searching for *OPTIONS.h files in order to warn about the presence"
1532 echo " of \"#define \"-type statements that are no longer allowed:"
1533 CPP_OPTIONS=
1534 CPP_EEOPTIONS=
1535 spaths=". $INCLUDEDIRS"
1536 names=`ls -1 "$ROOTDIR/pkg"`
1537 for i in $spaths ; do
1538 try="$i/CPP_OPTIONS.h"
1539 if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
1540 echo " found CPP_OPTIONS=\"$try\""
1541 CPP_OPTIONS="$try"
1542 # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1543 for n in $names ; do
1544 test_for_package_in_cpp_options $CPP_OPTIONS $n
1545 done
1546 fi
1547 try="$i/CPP_EEOPTIONS.h"
1548 if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
1549 echo " found CPP_EEOPTIONS=\"$try\""
1550 # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
1551 #**** not yet enabled ****
1552 # test_for_mpi_in_cpp_eeoptions $try
1553 #**** not yet enabled ****
1554 CPP_EEOPTIONS="$try"
1555 fi
1556 done
1557 if test "x$CPP_OPTIONS" = x ; then
1558 echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
1559 exit 1
1560 fi
1561
1562 # Here, we build the list of files to be "run through" the adjoint
1563 # compiler.
1564 if test -f ./ad_files ; then
1565 rm -f ./ad_files
1566 fi
1567 echo " Creating the list of files for the adjoint compiler."
1568 for i in $SOURCEDIRS ; do
1569 list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
1570 for j in $list_files ; do
1571 cat $i/$j >> ad_files
1572 done
1573 done
1574
1575
1576 echo
1577 echo "=== Creating the Makefile ==="
1578 echo " setting INCLUDES"
1579 for i in $INCLUDEDIRS ; do
1580 if ! test -d $i ; then
1581 # INCLUDES="$INCLUDES -I$i"
1582 # else
1583 echo "Warning: can't find INCLUDEDIRS=\"$i\""
1584 fi
1585 done
1586
1587 echo " Determining the list of source and include files"
1588 rm -rf .links.tmp
1589 mkdir .links.tmp
1590 echo "# This section creates symbolic links" > srclinks.tmp
1591 echo "" >> srclinks.tmp
1592 printf 'SRCFILES = ' > srclist.inc
1593 printf 'CSRCFILES = ' > csrclist.inc
1594 printf 'F90SRCFILES = ' > f90srclist.inc
1595 printf 'HEADERFILES = ' > hlist.inc
1596 printf 'AD_FLOW_FILES = ' > ad_flow_files.inc
1597 alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1598 for d in $alldirs ; do
1599 deplist=
1600 sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
1601 sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
1602 for sf in $sfiles ; do
1603 if test ! -r ".links.tmp/$sf" ; then
1604 if test -f "$d/$sf" ; then
1605 case $d/$sf in
1606 ./$PACKAGES_DOT_H)
1607 ;;
1608 ./AD_CONFIG.h)
1609 ;;
1610 ./FC_NAMEMANGLE.h)
1611 ;;
1612 *)
1613 touch .links.tmp/$sf
1614 deplist="$deplist $sf"
1615 ;;
1616 esac
1617 extn=`echo $sf | $AWK -F '.' '{print $NF}'`
1618 case $extn in
1619 F)
1620 echo " \\" >> srclist.inc
1621 printf " $sf" >> srclist.inc
1622 ;;
1623 F90)
1624 echo " \\" >> f90srclist.inc
1625 printf " $sf" >> f90srclist.inc
1626 ;;
1627 c)
1628 echo " \\" >> csrclist.inc
1629 printf " $sf" >> csrclist.inc
1630 ;;
1631 h)
1632 echo " \\" >> hlist.inc
1633 printf " $sf" >> hlist.inc
1634 ;;
1635 flow)
1636 echo " \\" >> ad_flow_files.inc
1637 printf " $sf" >> ad_flow_files.inc
1638 ;;
1639 esac
1640 fi
1641 fi
1642 done
1643 if test "x$deplist" != x ; then
1644 echo "" >> srclinks.tmp
1645 echo "# These files are linked from $d" >> srclinks.tmp
1646 echo "$deplist :" >> srclinks.tmp
1647 printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp
1648 fi
1649 done
1650 rm -rf .links.tmp
1651 echo "" >> srclist.inc
1652 echo "" >> csrclist.inc
1653 echo "" >> f90srclist.inc
1654 echo "" >> hlist.inc
1655 echo "" >> ad_flow_files.inc
1656
1657 if test -e $MAKEFILE ; then
1658 mv -f $MAKEFILE "$MAKEFILE.bak"
1659 fi
1660 echo " Writing makefile: $MAKEFILE"
1661 echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
1662 echo "# $MACHINE" >> $MAKEFILE
1663 echo "# This makefile was generated automatically on" >> $MAKEFILE
1664 echo "# $THISDATE" >> $MAKEFILE
1665 echo "# by the command:" >> $MAKEFILE
1666 echo "# $0 $G2ARGS" >> $MAKEFILE
1667 echo "# executed by:" >> $MAKEFILE
1668 echo "# $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE
1669
1670 EXE_AD=$EXECUTABLE"_ad"
1671 EXE_FTL=$EXECUTABLE"_ftl"
1672 EXE_SVD=$EXECUTABLE"_svd"
1673
1674 cat >>$MAKEFILE <<EOF
1675 #
1676 # OPTFILE="$OPTFILE"
1677 #
1678 # BUILDDIR : Directory where object files are written
1679 # SOURCEDIRS : Directories containing the source (.F) files
1680 # INCLUDEDIRS : Directories containing the header-source (.h) files
1681 # EXEDIR : Directory where executable that is generated is written
1682 # EXECUTABLE : Full path of executable binary
1683 #
1684 # CPP : C-preprocessor command
1685 # INCLUDES : Directories searched for header files
1686 # DEFINES : Macro definitions for CPP
1687 # MAKEDEPEND : Dependency generator
1688 # KPP : Special preprocessor command (specific to platform)
1689 # KFLAGS : Flags for KPP
1690 # FC : Fortran compiler command
1691 # FFLAGS : Configuration/debugging options for FC
1692 # FOPTIM : Optimization options for FC
1693 # LINK : Command for link editor program
1694 # LIBS : Library flags /or/ additional optimization/debugging flags
1695
1696 ROOTDIR = ${ROOTDIR}
1697 BUILDDIR = ${BUILDDIR}
1698 SOURCEDIRS = ${SOURCEDIRS}
1699 INCLUDEDIRS = ${INCLUDEDIRS}
1700 EXEDIR = ${EXEDIR}
1701 EXECUTABLE = \$(EXEDIR)/${EXECUTABLE}
1702 TOOLSDIR = ${TOOLSDIR}
1703
1704 #eh3 new defines for the adjoint work
1705 AUTODIFF = ${ROOTDIR}/pkg/autodiff
1706 EXE_AD = ${EXE_AD}
1707 EXE_FTL = ${EXE_FTL}
1708 EXE_SVD = ${EXE_SVD}
1709
1710 ENABLED_PACKAGES = ${ENABLED_PACKAGES}
1711 DISABLED_PACKAGES = ${DISABLED_PACKAGES}
1712
1713 # These files are created by Makefile
1714 SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h
1715
1716 EOF
1717
1718 # Note: figure out some way to add Hyades JAM libraries here
1719
1720 cat >>$MAKEFILE <<EOF
1721 # Unix ln (link)
1722 LN = ${LN}
1723 # C preprocessor
1724 CPP = cat \$< | ${S64} | ${CPP}
1725 # Dependency generator
1726 MAKEDEPEND = ${MAKEDEPEND}
1727 # Special preprocessor (KAP on DECs, FPP on Crays)
1728 KPP = ${KPP}
1729 # Fortran compiler
1730 FC = ${FC}
1731 # Fortran compiler
1732 F90C = ${F90C}
1733 # Link editor
1734 LINK = ${LINK} ${LDADD}
1735
1736 # Defines for CPP
1737 DEFINES = ${DEFINES}
1738 # Includes for CPP
1739 INCLUDES = ${INCLUDES}
1740 # Flags for KPP
1741 KFLAGS1 = ${KFLAGS1}
1742 KFLAGS2 = ${KFLAGS2}
1743 # Optim./debug for FC
1744 FFLAGS = ${FFLAGS}
1745 FOPTIM = ${FOPTIM}
1746 # Optim./debug for FC
1747 F90FLAGS = ${F90FLAGS}
1748 F90OPTIM = ${F90OPTIM}
1749 # Flags for CC
1750 CFLAGS = ${CFLAGS}
1751 # Files that should not be optimized
1752 NOOPTFILES = ${NOOPTFILES}
1753 NOOPTFLAGS = ${NOOPTFLAGS}
1754 # Flags and libraries needed for linking
1755 LIBS = ${LIBS} \$(XLIBS)
1756 # Name of the Mekfile
1757 MAKEFILE=${MAKEFILE}
1758
1759 EOF
1760
1761 cat srclist.inc >> $MAKEFILE
1762 cat csrclist.inc >> $MAKEFILE
1763 cat f90srclist.inc >> $MAKEFILE
1764 cat hlist.inc >> $MAKEFILE
1765 cat ad_flow_files.inc >> $MAKEFILE
1766 echo >> $MAKEFILE
1767 echo 'F77FILES = $(SRCFILES:.F=.'$FS')' >> $MAKEFILE
1768 echo 'F90FILES = $(F90SRCFILES:.F=.'$FS90')' >> $MAKEFILE
1769 echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
1770 echo >> $MAKEFILE
1771 echo '.SUFFIXES:' >> $MAKEFILE
1772 echo '.SUFFIXES: .o .F .p .'$FS' .c .F90 .'$FS90 >> $MAKEFILE
1773 rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc
1774 rm -f ad_flow_files.inc
1775
1776 cat >>$MAKEFILE <<EOF
1777
1778 all: \$(EXECUTABLE)
1779 \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES)
1780 @echo Creating \$@ ...
1781 \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
1782 depend:
1783 @make links
1784 \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
1785 \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
1786 -rm -f makedepend.out
1787
1788 links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)
1789
1790 small_f: \$(F77FILES) \$(F90FILES)
1791
1792 output.txt: \$(EXECUTABLE)
1793 @printf 'running ... '
1794 @\$(EXECUTABLE) > \$@
1795
1796 clean:
1797 -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
1798 Clean:
1799 @make clean
1800 @make cleanlinks
1801 -rm -f \$(SPECIAL_FILES)
1802 -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak
1803 CLEAN:
1804 @make Clean
1805 -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
1806 -find \$(EXEDIR) -name "*.data" -exec rm {} \;
1807 -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
1808 -rm -f \$(EXECUTABLE) output.txt
1809
1810 #eh3 Makefile: makefile
1811 makefile:
1812 $THIS_SCRIPT $G2ARGS
1813 cleanlinks:
1814 -find . -type l -exec rm {} \;
1815
1816 # Special targets ($SPECIAL_FILES) which are create by make
1817 ${PACKAGES_DOT_H}:
1818 @echo Creating \$@ ...
1819 @$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) > \$@
1820 AD_CONFIG.h:
1821 @echo Creating \$@ ...
1822 @$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 > \$@
1823 FC_NAMEMANGLE.h:
1824 @echo Creating \$@ ...
1825 echo "$FC_NAMEMANGLE" > \$@
1826
1827 # The normal chain of rules is ( .F - .$FS - .o )
1828
1829 %.o : %.F
1830
1831 .F.$FS:
1832 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1833 .$FS.o:
1834 \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
1835 .F90.$FS90:
1836 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1837 .$FS90.o:
1838 \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
1839 .c.o:
1840 \$(CC) \$(CFLAGS) -c \$<
1841
1842 # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
1843 .F.p:
1844 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1845 .p.$FS:
1846 \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
1847
1848 #=========================================
1849 #=== Automatic Differentiation Rules ===
1850
1851 TAMC = ${TAMC}
1852 TAF = ${TAF}
1853
1854 TAF_EXTRA = ${TAF_EXTRA}
1855 TAMC_EXTRA = ${TAMC_EXTRA}
1856
1857 EOF
1858
1859 ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
1860 ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
1861 ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1862 for i in $ad_vars ; do
1863 name=$i
1864 t1="t2=\$"`echo $i`
1865 eval $t1
1866 printf "%-20s = " $name >> $MAKEFILE
1867 echo $t2 >> $MAKEFILE
1868 done
1869
1870 echo " Add the source list for AD code generation"
1871 echo >> $MAKEFILE
1872 printf "AD_FILES = " >> $MAKEFILE
1873 AD_FILES=`cat ad_files`
1874 for i in $AD_FILES ; do
1875 echo " \\" >> $MAKEFILE
1876 printf " $i" >> $MAKEFILE
1877 done
1878 echo >> $MAKEFILE
1879 rm -f ad_files
1880
1881 cat >>$MAKEFILE <<EOF
1882
1883 # ... AD ...
1884 adall: ad_taf
1885 adtaf: ad_taf_output.f
1886 adtamc: ad_tamc_output.f
1887
1888 ad_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1889 @$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
1890 cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
1891 -rm -f ad_config.template
1892 @make \$(F77FILES)
1893 @make \$(AD_FLOW_FILES)
1894 cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f
1895
1896 ad_taf_output.f: ad_input_code.f
1897 \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1898 cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f
1899
1900 adtafonly:
1901 \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1902 cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.f
1903
1904 ad_taf: ad_taf_output.o \$(OBJFILES)
1905 \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
1906
1907 ad_tamc_output.f: ad_input_code.f
1908 \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f
1909 cat ad_input_code_ad.f | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.f
1910
1911 ad_tamc: ad_tamc_output.o \$(OBJFILES)
1912 \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
1913
1914
1915 # ... FTL ...
1916 ftlall: ftl_taf
1917 ftltaf: ftl_taf_output.f
1918 ftltamc: ftl_tamc_output.f
1919
1920 ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1921 @$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
1922 cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
1923 -rm -f ftl_config.template
1924 @make \$(F77FILES)
1925 @make \$(AD_FLOW_FILES)
1926 cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f
1927
1928 ftl_taf_output.f: ftl_input_code.f
1929 \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1930 cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f
1931
1932 ftltafonly:
1933 \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1934 cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.f
1935
1936 ftl_taf: ftl_taf_output.o \$(OBJFILES)
1937 \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
1938
1939 ftl_tamc_output.f: ftl_input_code.f
1940 \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f
1941 cat ftl_input_code_ftl.f | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.f
1942
1943 ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
1944 \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
1945
1946
1947 # ... SVD ...
1948 svdtaf: ad_taf_output.f ftl_taf_output.f
1949 svdall: svd_taf
1950
1951 svd_taf: ad_taf_output.o ftl_taf_output.o \$(OBJFILES)
1952 \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
1953
1954
1955 #=========================================
1956
1957 EOF
1958
1959 if test "x$EXEHOOK" != x ; then
1960 printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
1961 fi
1962
1963 echo " Making list of \"exceptions\" that need \".p\" files"
1964 for i in $KPPFILES ; do
1965 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
1966 RETVAL=$?
1967 if test "x$RETVAL" != x0 ; then
1968 echo "Error: unable to add file \"$i\" to the exceptions list"
1969 fi
1970 echo "$base.$FS: $base.p" >> $MAKEFILE
1971 done
1972
1973 echo " Making list of NOOPTFILES"
1974 for i in $NOOPTFILES ; do
1975 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
1976 RETVAL=$?
1977 if test "x$RETVAL" != x0 ; then
1978 echo "Error: unable to add file \"$i\" to the exceptions list"
1979 fi
1980 echo "$base.o: $base.$FS" >> $MAKEFILE
1981 printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
1982 done
1983
1984 echo " Add rules for links"
1985 cat srclinks.tmp >> $MAKEFILE
1986 rm -f srclinks.tmp
1987
1988 echo " Adding makedepend marker"
1989 printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
1990
1991 printf "\n=== Done ===\n"
1992
1993 # Create special header files
1994 $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"
1995 if test ! -f $PACKAGES_DOT_H ; then
1996 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1997 else
1998 cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
1999 RETVAL=$?
2000 if test "x$RETVAL" = x0 ; then
2001 rm -f $PACKAGES_DOT_H".tmp"
2002 else
2003 mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
2004 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2005 fi
2006 fi
2007 if test ! -f AD_CONFIG.h ; then
2008 $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
2009 fi
2010
2011
2012 # Write the "state" for future records
2013 if test "x$DUMPSTATE" != xf ; then
2014 printf "" > genmake_state
2015 for i in $gm_state ; do
2016 t1="t2=\$$i"
2017 eval $t1
2018 echo "$i='$t2'" >> genmake_state
2019 done
2020 fi

  ViewVC Help
Powered by ViewVC 1.1.22