/[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.79 - (show annotations) (download)
Wed Jun 16 21:15:47 2004 UTC (15 years, 4 months ago) by edhill
Branch: MAIN
CVS Tags: checkpoint53f_post
Changes since 1.78: +6 -1 lines
 o add description of "-adof" and synonymous options to the "--help" output

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

  ViewVC Help
Powered by ViewVC 1.1.22