/[MITgcm]/MITgcm_contrib/heimbach/OpenAD/code_shallow_openad3/genmake2
ViewVC logotype

Contents of /MITgcm_contrib/heimbach/OpenAD/code_shallow_openad3/genmake2

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (show annotations) (download)
Thu Dec 19 16:10:21 2013 UTC (11 years, 7 months ago) by utke
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +1 -1 lines
FILE REMOVED
stale

1
2 #! /usr/bin/env bash
3 #
4 # $Header: /u/gcmpack/MITgcm_contrib/heimbach/OpenAD/code_shallow_openad3/genmake2,v 1.8 2007/08/08 19:15:30 utke Exp $
5 #
6 # Makefile generator for MITgcm UV codes
7 # created by cnh 03/98
8 # adapted by aja 06/98
9 # modified by aja 01/00
10 # rewritten in bash by eh3 08/03
11
12 # Search for particular CPP #cmds associated with packages
13 # usage: test_for_package_in_cpp_options CPP_file package_name
14 test_for_package_in_cpp_options() {
15 cpp_options=$1
16 pkg=$2
17 test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg" || exit 99
18 test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg" || exit 99
19 test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg" || exit 99
20 test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg" || exit 99
21 }
22
23 # Search for particular CPP #cmds associated with MPI
24 # usage: test_for_mpi_in_cpp_eeoptions CPP_file
25 test_for_mpi_in_cpp_eeoptions() {
26 cpp_options=$1
27 test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI" || exit 99
28 test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI" || exit 99
29 test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI" || exit 99
30 test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI" || exit 99
31 }
32
33 # Search for particular string in a file. Return 1 if detected, 0 if not
34 # usage: test_for_string_in_file file string
35 test_for_string_in_file() {
36 file=$1
37 strng=$2
38 grep -i "$strng" $file > /dev/null 2>&1
39 RETVAL=$?
40 if test "x${RETVAL}" = x0 ; then
41 printf "Error: In $file there is an illegal line: "
42 grep -i "$strng" $file
43 return 1
44 fi
45 return 0
46 }
47
48 # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to
49 # the package list.
50 expand_pkg_groups() {
51 new_packages=
52 PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"
53 if test -r $PKG_GROUPS ; then
54 cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp
55 cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp
56 matched=0
57 for i in $PACKAGES ; do
58 line=`grep "^ *$i" ./p2.tmp`
59 RETVAL=$?
60 if test "x$RETVAL" = x0 ; then
61 matched=1
62 replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`
63 echo " replacing \"$i\" with: $replace"
64 new_packages="$new_packages $replace"
65 else
66 new_packages="$new_packages $i"
67 fi
68 done
69 PACKAGES=$new_packages
70 rm -f ./p[1,2].tmp
71 return $matched
72 else
73 echo "Warning: can't read package groups definition file: $PKG_GROUPS"
74 fi
75 }
76
77 # Check for broken environments (eg. cygwin, MacOSX w/HFS+) that
78 # cannot distinguish [*.F/*.F90] from [*.f/*.f90] files.
79 check_for_broken_Ff() {
80 # Do we have defaults for $FS and/or $FS90 ?
81 tfs=f
82 tfs9=f90
83 if test "x$FS" != x ; then
84 tfs="$FS"
85 fi
86 if test "x$FS90" != x ; then
87 tfs9="$FS90"
88 fi
89
90 # First check the ability to create a *.F/.f pair.
91 cat <<EOF >> genmake_hello.F
92 program hello
93 write(*,*) 'hi'
94 stop
95 end
96 EOF
97 cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1
98 RETVAL=$?
99 if test "x$RETVAL" != x0 ; then
100 if test "x$FS" = x ; then
101 FS='for'
102 FS90='fr9'
103 check_for_broken_Ff
104 else
105 cat <<EOF 2>&1
106 ERROR: Your file system cannot distinguish between *.F and *.f files
107 (fails the "cp" test) and this program cannot find a suitable
108 replacement extension. Please try a different build environment or
109 contact the <MITgcm-support@mitgcm.org> list for help.
110
111 EOF
112 exit -1
113 fi
114 return
115 fi
116 rm -f genmake_hello.*
117
118 # Check the ability of ${MAKE} and ${LN} to use the current set
119 # of extensions.
120 cat <<EOF >> genmake_hello.F
121 program hello
122 write(*,*) 'hi'
123 stop
124 end
125 EOF
126 test -f $MAKEFILE && mv -f $MAKEFILE $MAKEFILE".tst"
127 cat <<EOF >> $MAKEFILE
128 .SUFFIXES:
129 .SUFFIXES: .$tfs .F
130 .F.$tfs:
131 $LN \$< \$@
132 EOF
133 $MAKE "genmake_hello."$tfs > /dev/null 2>&1
134 RETVAL=$?
135 if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then
136 if test "x$FS" = x ; then
137 FS='for'
138 FS90='fr9'
139 check_for_broken_Ff
140 else
141 cat <<EOF 2>&1
142 ERROR: Your file system cannot distinguish between *.F and *.f files
143 (fails the "make/ln" test) and this program cannot find a suitable
144 replacement extension. Please try a different build environment or
145 contact the <MITgcm-support@mitgcm.org> list for help.
146
147 EOF
148 exit -1
149 return
150 fi
151 fi
152 rm -f genmake_hello.* $MAKEFILE
153 test -f $MAKEFILE".tst" && mv -f $MAKEFILE".tst" $MAKEFILE
154
155 # If we make it here, use the extensions
156 FS=$tfs
157 FS90=$tfs9
158 return
159 }
160
161
162 look_for_makedepend() {
163
164 # The "original" makedepend is part of the Imake system that is
165 # most often distributed with XFree86 or with an XFree86 source
166 # package. As a result, many machines (eg. generic Linux) do not
167 # have a system-default "makedepend" available. For those
168 # systems, we have two fall-back options:
169 #
170 # 1) a makedepend implementation shipped with the cyrus-imapd
171 # package: ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
172 #
173 # 2) a known-buggy xmakedpend shell script
174 #
175 # So the choices are, in order:
176 #
177 # 1) use the user-specified program
178 # 2) use a system-wide default
179 # 3) locally build and use the cyrus implementation
180 # 4) fall back to the buggy local xmakedpend script
181 #
182 if test "x${MAKEDEPEND}" = x ; then
183 which makedepend > /dev/null 2>&1
184 RV0=$?
185 test -f $MAKEFILE && mv -f $MAKEFILE $MAKEFILE".tst"
186 # echo 'MAKEFILE="'$MAKEFILE'"'
187 cat <<EOF >> $MAKEFILE
188 # THIS IS A TEST MAKEFILE GENERATED BY "genmake2"
189 #
190 # Some "makedepend" implementations will die if they cannot
191 # find a Makefile -- so this file is here to gives them an
192 # empty one to find and parse.
193 EOF
194 cat <<EOF >> genmake_tc.f
195 program test
196 write(*,*) 'test'
197 stop
198 end
199 EOF
200 makedepend genmake_tc.f > /dev/null 2>&1
201 RV1=$?
202 test -f $MAKEFILE && rm -f $MAKEFILE
203 test -f $MAKEFILE".tst" && mv -f $MAKEFILE".tst" $MAKEFILE
204 if test "x${RV0}${RV1}" = x00 ; then
205 MAKEDEPEND=makedepend
206 else
207 echo " a system-default makedepend was not found."
208
209 # Try to build the cyrus implementation
210 build_cyrus_makedepend
211 RETVAL=$?
212 if test "x$RETVAL" != x0 ; then
213 MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
214 fi
215 rm -f ./genmake_cy_md
216 fi
217 else
218 # echo "MAKEDEPEND=${MAKEDEPEND}"
219 echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1
220 RETVAL=$?
221 if test x"$RETVAL" = x0 ; then
222 build_cyrus_makedepend
223 fi
224 fi
225 }
226
227
228 build_cyrus_makedepend() {
229 rm -f ./genmake_cy_md
230 (
231 cd $ROOTDIR/tools/cyrus-imapd-makedepend \
232 && ./configure > /dev/null 2>&1 \
233 && make > /dev/null 2>&1
234 if test -x ./makedepend.exe ; then
235 $LN ./makedepend.exe ./makedepend
236 fi
237 ./makedepend ifparser.c > /dev/null 2>&1 \
238 && echo "true"
239 ) > ./genmake_cy_md
240 grep true ./genmake_cy_md > /dev/null 2>&1
241 RETVAL=$?
242 rm -f ./genmake_cy_md
243 if test "x$RETVAL" = x0 ; then
244 MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
245 return 0
246 else
247 echo "WARNING: unable to build cyrus-imapd-makedepend"
248 return 1
249 fi
250 }
251
252 # Guess possible config options for this host
253 find_possible_configs() {
254
255 tmp1=`uname`"_"`uname -m`
256 tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
257 tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
258 tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
259 tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
260 tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
261 PLATFORM=$tmp3
262 echo $PLATFORM | grep cygwin > /dev/null 2>&1 && PLATFORM=cygwin_ia32
263 OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
264 echo " The platform appears to be: $PLATFORM"
265
266 echo "test" > test
267 ln -s ./test link
268 RETVAL=$?
269 if test "x${RETVAL}" = x0 ; then
270 LN="ln -s"
271 else
272 echo "Error: \"ln -s\" does not appear to work on this system!"
273 echo " For help, please contact <MITgcm-support@mitgcm.org>."
274 exit 1
275 fi
276 rm -f test link
277
278 if test "x$CPP" = x ; then
279 CPP="cpp -traditional -P"
280 fi
281
282 look_for_makedepend
283
284 #================================================================
285 # look for possible C compilers
286 tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc"
287 p_CC=
288 for c in $tmp ; do
289 rm -f ./genmake_hello.c ./genmake_hello
290 cat >> genmake_hello.c << EOF
291 #include <stdio.h>
292 int main(int argc, char **argv) {
293 printf("Hello!\n");
294 return 0;
295 }
296 EOF
297 $c -o genmake_hello genmake_hello.c > /dev/null 2>&1
298 RETVAL=$?
299 if test "x${RETVAL}" = x0 ; then
300 p_CC="$p_CC $c"
301 fi
302 done
303 rm -f ./genmake_hello.c ./genmake_hello
304 if test "x${p_CC}" = x ; then
305 cat 1>&2 <<EOF
306
307 Error: No C compilers were found in your path. Please specify one using:
308
309 1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
310 2) the CC or MITGCM_CC environment variables.
311
312 EOF
313 exit 1
314 else
315 echo " The possible C compilers found in your path are:"
316 echo " "$p_CC
317 if test "x$CC" = x ; then
318 CC=`echo $p_CC | $AWK '{print $1}'`
319 echo " Setting C compiler to: "$CC
320 fi
321 fi
322
323 #================================================================
324 # look for possible FORTRAN compilers
325 tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 gfortran"
326 p_FC=
327 for c in $tmp ; do
328 rm -f ./hello.f ./hello
329 cat >> hello.f <<EOF
330 program hello
331 do i=1,3
332 print *, 'hello world : ', i
333 enddo
334 end
335 EOF
336 $c -o hello hello.f > /dev/null 2>&1
337 RETVAL=$?
338 if test "x${RETVAL}" = x0 ; then
339 p_FC="$p_FC $c"
340 fi
341 done
342 rm -f ./hello.f ./hello
343 if test "x${p_FC}" = x ; then
344 cat 1>&2 <<EOF
345
346 Error: No Fortran compilers were found in your path. Please specify one using:
347
348 1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
349 2) a command-line option (eg. "-fc NAME"), or
350 3) the FC or MITGCM_FC environment variables.
351
352 EOF
353 exit 1
354 else
355 echo " The possible FORTRAN compilers found in your path are:"
356 echo " "$p_FC
357 if test "x$FC" = x ; then
358 FC=`echo $p_FC | $AWK '{print $1}'`
359 echo " Setting FORTRAN compiler to: "$FC
360 fi
361 fi
362
363 if test "x$OPTFILE" = x ; then
364 OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
365 if test ! -r $OPTFILE ; then
366 echo " I looked for the file "$OPTFILE" but did not find it"
367 fi
368 fi
369 # echo " The options file: $p_OF"
370 # echo " appears to match so we'll use it."
371 # for i in $p_FC ; do
372 #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
373 #if test -r $p_OF ; then
374 # OPTFILE=$p_OF
375 # echo " The options file: $p_OF"
376 # echo " appears to match so we'll use it."
377 # break
378 #fi
379 # done
380 if test "x$OPTFILE" = x ; then
381 cat 1>&2 <<EOF
382
383 Error: No options file was found in: $ROOTDIR/tools/build_options/
384 that matches this platform ("$PLATFORM") and the compilers found in
385 your path. Please specify an "optfile" using:
386
387 1) the command line (eg. "-optfile=path/to/OPTFILE"), or
388 2) the MITGCM_OF environment variable.
389
390 If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
391
392 EOF
393 exit 1
394 fi
395
396 # # look for possible MPI libraries
397 # mpi_libs=
398 # mpi_fort=`which mpif77 2>/dev/null`
399 # RETVAL=$?
400 # if test "x${RETVAL}" = x0 ; then
401 # cat >>test.f <<EOF
402 # PROGRAM HELLO
403 # DO 10, I=1,10
404 # PRINT *,'Hello World'
405 # 10 CONTINUE
406 # STOP
407 # END
408 # EOF
409 # eval "$mpi_fort -showme test.f > out"
410 # RETVAL=$?
411 # if test "x${RETVAL}" = x0 ; then
412 # a=`cat out`
413 # for i in $a ; do
414 # case $i in
415 # -*)
416 # mpi_libs="$mpi_libs $i" ;;
417 # esac
418 # done
419 # echo "The MPI libs appear to be:"
420 # echo " "$mpi_libs
421 # fi
422 # rm -f test.f out
423 # fi
424
425 }
426
427 # Parse the package dependency information
428 get_pdepend_list() {
429
430 # strip the comments and then convert the dependency file into
431 # two arrays: PNAME, DNAME
432 cat $1 | sed -e 's/#.*$//g' \
433 | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \
434 > ./.pd_tmp
435 . ./.pd_tmp
436 rm -f ./.pd_tmp
437
438 printf "PNAME = "${}
439 }
440
441
442 # Explain usage
443 usage() {
444 cat <<EOF
445
446 Usage: "$0" [OPTIONS]
447 where [OPTIONS] can be:
448
449 -help | --help | -h | --h
450 Print this help message and exit.
451
452 -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
453 -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
454 Use "NAME" as the adoptfile. By default, the file at
455 "tools/adjoint_options/adjoint_default" will be used.
456
457 -nooptfile | --nooptfile
458 -optfile NAME | --optfile NAME | -of NAME | --of NAME
459 -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
460 Use "NAME" as the optfile. By default, an attempt will be
461 made to find an appropriate "standard" optfile in the
462 tools/build_options/ directory.
463
464 -pdepend NAME | --pdepend NAME
465 -pdepend=NAME | --pdepend=NAME
466 Get package dependency information from "NAME".
467
468 -pdefault NAME | --pdefault NAME
469 -pdefault=NAME | --pdefault=NAME
470 Get the default package list from "NAME".
471
472 -make NAME | -m NAME
473 --make=NAME | -m=NAME
474 Use "NAME" for the MAKE program. The default is "make" but
475 many platforms, "gmake" is the preferred choice.
476
477 -makefile NAME | -mf NAME
478 --makefile=NAME | -mf=NAME
479 Call the makefile "NAME". The default is "Makefile".
480
481 -makedepend NAME | -md NAME
482 --makedepend=NAME | -md=NAME
483 Use "NAME" for the MAKEDEPEND program.
484
485 -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
486 -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
487 Specify the location of the MITgcm ROOTDIR as "NAME".
488 By default, genamke will try to find the location by
489 looking in parent directories (up to the 5th parent).
490
491 -mods NAME | --mods NAME | -mo NAME | --mo NAME
492 -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
493 Here, "NAME" specifies a list of directories that are
494 used for additional source code. Files found in the
495 "mods list" are given preference over files of the same
496 name found elsewhere.
497
498 -disable NAME | --disable NAME
499 -disable=NAME | --disable=NAME
500 Here "NAME" specifies a list of packages that we don't
501 want to use. If this violates package dependencies,
502 genamke will exit with an error message.
503
504 -enable NAME | --enable NAME
505 -enable=NAME | --enable=NAME
506 Here "NAME" specifies a list of packages that we wish
507 to specifically enable. If this violates package
508 dependencies, genamke will exit with an error message.
509
510 -standarddirs NAME | --standarddirs NAME
511 -standarddirs=NAME | --standarddirs=NAME
512 Here, "NAME" specifies a list of directories to be
513 used as the "standard" code.
514
515 -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
516 -fc=NAME | --fc=NAME
517 Use "NAME" as the fortran compiler. By default, genmake
518 will search for a working compiler by trying a list of
519 "usual suspects" such as g77, f77, etc.
520
521 -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
522 Use "NAME" as the C compiler. By default, genmake
523 will search for a working compiler by trying a list of
524 "usual suspects" such as gcc, c89, cc, etc.
525
526 -[no]ieee | --[no]ieee
527 Do or don't use IEEE numerics. Note that this option
528 *only* works if it is supported by the OPTFILE that
529 is being used.
530
531 -ts | --ts
532 Produce timing information per timestep
533
534 -mpi | --mpi
535 Include MPI header files and link to MPI libraries
536 -mpi=PATH | --mpi=PATH
537 Include MPI header files and link to MPI libraries using MPI_ROOT
538 set to PATH. i.e. Include files from \$PATH/include, link to libraries
539 from \$PATH/lib and use binaries from \$PATH/bin.
540
541 -bash NAME
542 Explicitly specify the Bourne or BASH shell to use
543
544 While it is most often a single word, the "NAME" variables specified
545 above can in many cases be a space-delimited string such as:
546
547 --enable pkg1 --enable 'pkg1 pkg2' --enable 'pkg1 pkg2 pkg3'
548 -mods=dir1 -mods='dir1' -mods='dir1 dir2 dir3'
549 -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
550
551 which, depending upon your shell, may need to be single-quoted.
552
553 For more detailed genmake documentation, please see:
554
555 http://mitgcm.org/devel_HOWTO/
556
557 EOF
558
559 exit 1
560 }
561
562 # Build a CPP macro to automate calling C routines from FORTRAN
563 get_fortran_c_namemangling() {
564
565 #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
566 if test ! "x$FC_NAMEMANGLE" = x ; then
567 return 0
568 fi
569
570 default_nm="#define FC_NAMEMANGLE(X) X ## _"
571
572 cat > genmake_test.c <<EOF
573 void tcall( char * string ) { tsub( string ); }
574 EOF
575 $MAKE genmake_test.o >> genmake_warnings 2>&1
576 RETVAL=$?
577 if test "x$RETVAL" != x0 ; then
578 FC_NAMEMANGLE=$default_nm
579 cat <<EOF>> genmake_errors
580
581 WARNING: C test compile fails
582 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
583 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
584 EOF
585 return 1
586 fi
587 c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
588 RETVAL=$?
589 if test "x$RETVAL" != x0 ; then
590 FC_NAMEMANGLE=$default_nm
591 cat <<EOF>> genmake_warnings
592
593 WARNING: The "nm" command failed.
594 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
595 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
596 EOF
597 return 1
598 fi
599 cat > genmake_tcomp.$FS <<EOF
600 subroutine tcall( string )
601 character*(*) string
602 call tsub( string )
603 end
604 EOF
605 $FC $FFLAGS $DEFINES -c genmake_tcomp.$FS >> genmake_warnings 2>&1
606 RETVAL=$?
607 if test "x$RETVAL" != x0 ; then
608 FC_NAMEMANGLE=$default_nm
609 cat <<EOF>> genmake_warnings
610
611 WARNING: FORTRAN test compile fails -- please see "genmake_errors"
612 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
613 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
614 EOF
615 return 1
616 fi
617 f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
618 RETVAL=$?
619 if test "x$RETVAL" != x0 ; then
620 FC_NAMEMANGLE=$default_nm
621 cat <<EOF>> genmake_warnings
622
623 WARNING: The "nm" command failed.
624 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
625 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
626 EOF
627 return 1
628 fi
629
630 c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
631 f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
632 c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
633 f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
634
635 nmangle="X"
636 if test "x$c_a" != "x$f_a" ; then
637 comm="echo x$f_a | sed -e 's|x$c_a||'"
638 a=`eval $comm`
639 nmangle="$a ## $nmangle"
640 fi
641 if test "x$c_b" != "x$f_b" ; then
642 comm="echo x$f_b | sed -e 's|x$c_b||'"
643 b=`eval $comm`
644 nmangle="$nmangle ## $b"
645 fi
646
647 FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) $nmangle"
648
649 # cleanup the testing files
650 rm -f genmake_tcomp.* genmake_test.*
651 }
652
653
654 check_HAVE_CLOC() {
655 get_fortran_c_namemangling
656 cat <<EOF > genmake_tc_1.c
657 $FC_NAMEMANGLE
658 #include <stdio.h>
659 #include <stdlib.h>
660 #include <unistd.h>
661 #include <assert.h>
662 #include <sys/time.h>
663 void FC_NAMEMANGLE(cloc) ( double *curtim )
664 {
665 struct timeval tv1;
666 gettimeofday(&tv1 , (void *)NULL );
667 *curtim = (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
668 *curtim = *curtim/1.E6;
669 }
670 EOF
671 make genmake_tc_1.o >> genmake_warnings 2>&1
672 RET_C=$?
673 cat <<EOF > genmake_tc_2.$FS
674 program hello
675 Real*8 wtime
676 external cloc
677 call cloc(wtime)
678 print *," HELLO WORLD", wtime
679 end program hello
680 EOF
681 $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1
682 RET_F=$?
683 test -x ./genmake_tc && ./genmake_tc >> genmake_warnings 2>&1
684 RETVAL=$?
685 if test "x$RETVAL" = x0 ; then
686 HAVE_CLOC=t
687 DEFINES="$DEFINES -DHAVE_CLOC"
688 fi
689 rm -f genmake_tc*
690 }
691
692
693 check_HAVE_STAT() {
694 get_fortran_c_namemangling
695 cat <<EOF > genmake_tc_1.c
696 $FC_NAMEMANGLE
697 #include <stdio.h>
698 #include <stdlib.h>
699 #include <unistd.h>
700 #include <sys/stat.h>
701 #include <sys/types.h>
702 void FC_NAMEMANGLE(tfsize) ( int *nbyte )
703 {
704 char name[512];
705 struct stat astat;
706
707 name[0] = 'a'; name[1] = '\0';
708 if (! stat(name, &astat))
709 *nbyte = (int)(astat.st_size);
710 else
711 *nbyte = -1;
712 }
713 EOF
714 make genmake_tc_1.o >> genmake_tc.log 2>&1
715 RET_C=$?
716 cat <<EOF > genmake_tc_2.$FS
717 program hello
718 integer nbyte
719 call tfsize(nbyte)
720 print *," HELLO WORLD", nbyte
721 end program hello
722 EOF
723 $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_tc.log 2>&1
724 RET_F=$?
725 test -x ./genmake_tc && ./genmake_tc >> genmake_tc.log 2>&1
726 RETVAL=$?
727 if test "x$RETVAL" = x0 ; then
728 HAVE_STAT=t
729 DEFINES="$DEFINES -DHAVE_STAT"
730 fi
731 rm -f genmake_tc*
732 }
733
734
735 check_netcdf_libs() {
736 if test ! "x$SKIP_NETCDF_CHECK" = x ; then
737 return
738 fi
739 echo "" > genmake_tnc.log
740 cat <<EOF > genmake_tnc.F
741 program fgennc
742 #include "netcdf.inc"
743 EOF
744 if test ! "x$MPI" = x ; then
745 echo '#include "mpif.h"' >> genmake_tnc.F
746 fi
747 cat <<EOF >> genmake_tnc.F
748 integer iret, ncid, xid
749 iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
750 IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
751 iret = nf_def_dim(ncid, 'X', 11, xid)
752 IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
753 iret = nf_close(ncid)
754 IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
755 end
756 EOF
757 echo "Executing:" > genmake_tnc.log
758 echo " $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS" \
759 > genmake_tnc.log
760 RET_CPP=f
761 $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null \
762 && RET_CPP=t
763 if test "x$RET_CPP" = xf ; then
764 echo " WARNING: CPP failed to pre-process the netcdf test." \
765 > genmake_tnc.log
766 echo " Please check that \$INCLUDES is properly set." \
767 > genmake_tnc.log
768 fi
769 echo "Executing:" > genmake_tnc.log
770 echo " $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS" > genmake_tnc.log
771 echo " $LINK -o genmake_tnc.o $LIBS" > genmake_tnc.log
772 $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \
773 && $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
774 RET_COMPILE=$?
775
776 #EH3 Remove test program execution for machines that either disallow
777 #EH3 execution or cannot support it (eg. cross-compilers)
778 #EH3
779 #EH3 test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1
780 #EH3 RETVAL=$?
781 #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
782
783 if test "x$RET_COMPILE" = x0 ; then
784 HAVE_NETCDF=t
785 else
786 # try again with "-lnetcdf" added to the libs
787 $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null \
788 && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \
789 && $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
790 RET_COMPILE=$?
791 if test "x$RET_COMPILE" = x0 ; then
792 LIBS="$LIBS -lnetcdf"
793 HAVE_NETCDF=t
794 else
795 cat genmake_tnc.log >> genmake_warnings
796 fi
797 fi
798 rm -f genmake_tnc*
799 }
800
801
802
803 ###############################################################################
804 # Sequential part of script starts here
805 ###############################################################################
806
807 # Set defaults here
808 COMMANDL="$0 $@"
809
810 PLATFORM=
811 LN=
812 S64=
813 KPP=
814 #FC=
815 #CC=gcc
816 #CPP=
817 LINK=
818 DEFINES=
819 PACKAGES=
820 ENABLE=
821 DISABLE=
822 # MAKEFILE=
823 # MAKEDEPEND=
824 PDEPEND=
825 DUMPSTATE=t
826 PDEFAULT=
827 OPTFILE=
828 INCLUDES="-I. $INCLUDES"
829 FFLAGS=
830 FOPTIM=
831 CFLAGS=
832 KFLAGS1=
833 KFLAGS2=
834 #LDADD=
835 LIBS=
836 KPPFILES=
837 NOOPTFILES=
838 NOOPTFLAGS=
839 MPI=
840 MPIPATH=
841 TS=
842
843 # DEFINES checked by test compilation or command-line
844 HAVE_SYSTEM=
845 HAVE_FDATE=
846 FC_NAMEMANGLE=
847 HAVE_CLOC=
848 HAVE_STAT=
849 HAVE_NETCDF=
850 HAVE_ETIME=
851 IGNORE_TIME=
852
853 MODS=
854 TOOLSDIR=
855 SOURCEDIRS=
856 INCLUDEDIRS=
857 STANDARDDIRS="USE_THE_DEFAULT"
858
859 G2ARGS=
860 BASH=
861 PWD=`pwd`
862 test "x$MAKE" = x && MAKE=make
863 test "x$AWK" = x && AWK=awk
864 THISHOST=`hostname`
865 THISCWD=`pwd`
866 THISDATE=`date`
867 THISUSER=`echo $USER`
868 THISVER=
869 MACHINE=`uname -a`
870 EXECUTABLE=
871 EXEHOOK=
872 EXEDIR=
873 PACKAGES_CONF=
874 IEEE=
875 if test "x$MITGCM_IEEE" != x ; then
876 IEEE=$MITGCM_IEEE
877 fi
878 FS=
879 FS90=
880
881 AUTODIFF_PKG_USED=f
882 AD_OPTFILE=
883 TAF=
884 AD_TAF_FLAGS=
885 FTL_TAF_FLAGS=
886 SVD_TAF_FLAGS=
887 TAF_EXTRA=
888 TAMC=
889 AD_TAMC_FLAGS=
890 FTL_TAF_FLAGS=
891 SVD_TAMC_FLAGS=
892 TAMC_EXTRA=
893
894
895 # The following state can be set directly by command-line switches
896 gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
897 gm_s2="FC CPP IEEE TS MPI JAM DUMPSTATE STANDARDDIRS"
898
899 # The following state is not directly set by command-line switches
900 gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
901 gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
902 gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE"
903 gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
904 gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"
905
906 # The following are all related to adjoint/tangent-linear stuff
907 gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
908 gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
909 gm_s12="TAF_EXTRA TAMC_EXTRA"
910
911 gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
912 gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
913
914 cat <<EOF
915
916 GENMAKE :
917
918 A program for GENerating MAKEfiles for the MITgcm project. For a
919 quick list of options, use "genmake -h" or for more detail see:
920
921 http://mitgcm.org/devel_HOWTO/
922
923 EOF
924
925 echo "=== Processing options files and arguments ==="
926 gm_local="genmake_local"
927 modsCount=0
928 for i in . $MODS ; do
929 if test -r $i/$gm_local ; then
930 . $i/$gm_local
931 break
932 fi
933 let modsCount=modsCount+1
934 done
935 if test $modsCount -gt 1 ; then
936 echo "ERROR: some uses of MODS break with more than one directory specified"
937 exit -1;
938 fi
939 printf " getting local config information: "
940 if test -f $gm_local ; then
941 echo "using $gm_local"
942 . $gm_local
943 # echo "DISABLE=$DISABLE"
944 # echo "ENABLE=$ENABLE"
945 else
946 echo "none found"
947 fi
948
949 #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
950 #OPTIONS=
951 #n=0
952 #for i ; do
953 # echo "$i $n"
954 # setvar="OPTIONS[$n]='$i'"
955 # # echo " $setvar"
956 # eval "$setvar"
957 # n=$(( $n + 1 ))
958 #done
959 #parse_options
960 ac_prev=
961 for ac_option in "$@" ; do
962
963 G2ARGS="$G2ARGS \"$ac_option\""
964
965 # If the previous option needs an argument, assign it.
966 if test -n "$ac_prev"; then
967 eval "$ac_prev=\$ac_option"
968 ac_prev=
969 continue
970 fi
971
972 ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
973
974 case $ac_option in
975
976 -help | --help | -h | --h)
977 usage ;;
978
979 -nooptfile | --nooptfile)
980 OPTFILE="NONE" ;;
981 -optfile | --optfile | -of | --of)
982 ac_prev=OPTFILE ;;
983 -optfile=* | --optfile=* | -of=* | --of=*)
984 OPTFILE=$ac_optarg ;;
985
986 -adoptfile | --adoptfile | -adof | --adof)
987 ac_prev=AD_OPTFILE ;;
988 -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
989 AD_OPTFILE=$ac_optarg ;;
990
991 -pdepend | --pdepend)
992 ac_prev=PDEPEND ;;
993 -pdepend=* | --pdepend=*)
994 PDEPEND=$ac_optarg ;;
995
996 -pdefault | --pdefault)
997 ac_prev=PDEFAULT ;;
998 -pdefault=* | --pdefault=*)
999 PDEFAULT=$ac_optarg ;;
1000
1001 -make | --make | -m | --m)
1002 ac_prev=MAKE ;;
1003 -make=* | --make=* | -m=* | --m=*)
1004 MAKE=$ac_optarg ;;
1005
1006 -bash | --bash)
1007 ac_prev=BASH ;;
1008 -bash=* | --bash=*)
1009 BASH=$ac_optarg ;;
1010
1011 -makedepend | --makedepend | -md | --md)
1012 ac_prev=MAKEDEPEND ;;
1013 -makedepend=* | --makedepend=* | -md=* | --md=*)
1014 MAKEDEPEND=$ac_optarg ;;
1015
1016 -makefile | --makefile | -ma | --ma)
1017 ac_prev=MAKEFILE ;;
1018 -makefile=* | --makefile=* | -ma=* | --ma=*)
1019 MAKEFILE=$ac_optarg ;;
1020
1021 -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1022 echo "ERROR: The platform option has been removed. Please specify"
1023 echo " the build options using the \"optfile\" mechanism."
1024 echo
1025 usage
1026 ;;
1027
1028 -rootdir | --rootdir | -rd | --rd)
1029 ac_prev=ROOTDIR ;;
1030 -rootdir=* | --rootdir=* | -rd=* | --rd=*)
1031 ROOTDIR=$ac_optarg ;;
1032
1033 -mods | --mods | -mo | --mo)
1034 ac_prev=MODS ;;
1035 -mods=* | --mods=* | -mo=* | --mo=*)
1036 MODS=$ac_optarg ;;
1037
1038 -disable | --disable)
1039 ac_prev=DISABLE ;;
1040 -disable=* | --disable=*)
1041 DISABLE=$ac_optarg ;;
1042
1043 -enable | --enable)
1044 ac_prev=ENABLE ;;
1045 -enable=* | --enable=*)
1046 ENABLE=$ac_optarg ;;
1047
1048 -standarddirs | --standarddirs)
1049 ac_prev=STANDARDDIRS ;;
1050 -standarddirs=* | --standarddirs=*)
1051 STANDARDDIRS=$ac_optarg ;;
1052
1053 # -cpp | --cpp)
1054 # ac_prev=cpp ;;
1055 # -cpp=* | --cpp=*)
1056 # CPP=$ac_optarg ;;
1057
1058 -cc | --cc)
1059 ac_prev=CC ;;
1060 -cc=* | --cc=*)
1061 CC=$ac_optarg ;;
1062
1063 -fortran | --fortran | -fc | --fc)
1064 ac_prev=FC ;;
1065 -fc=* | --fc=*)
1066 FC=$ac_optarg ;;
1067
1068 -fs | --fs)
1069 ac_prev=FS ;;
1070 -fs=* | --fs=*)
1071 FS=$ac_optarg ;;
1072
1073 -fs90 | --fs90)
1074 ac_prev=FS90 ;;
1075 -fs90=* | --fs90=*)
1076 FS90=$ac_optarg ;;
1077
1078 -ieee | --ieee)
1079 IEEE=true ;;
1080 -noieee | --noieee)
1081 IEEE= ;;
1082
1083 -ts | --ts)
1084 TS=true ;;
1085
1086 -mpi | --mpi)
1087 MPI=true ;;
1088 -mpi=* | --mpi=*)
1089 MPIPATH=$ac_optarg
1090 MPI=true ;;
1091
1092 # -jam | --jam)
1093 # JAM=1 ;;
1094 # -nojam | --nojam)
1095 # JAM=0 ;;
1096
1097 -ds | --ds)
1098 DUMPSTATE=t ;;
1099
1100 -taf_extra | --taf_extra)
1101 ac_prev=TAF_EXTRA ;;
1102 -taf_extra=* | --taf_extra=*)
1103 TAF_EXTRA=$ac_optarg ;;
1104
1105 -tamc_extra | --tamc_extra)
1106 ac_prev=TAMC_EXTRA ;;
1107 -tamc_extra=* | --tamc_extra=*)
1108 TAMC_EXTRA=$ac_optarg ;;
1109
1110 -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1111 IGNORE_TIME="-DIGNORE_TIME" ;;
1112
1113 -*)
1114 echo "Error: unrecognized option: "$ac_option
1115 usage
1116 ;;
1117
1118 *)
1119 echo "Error: unrecognized argument: "$ac_option
1120 usage
1121 ;;
1122
1123 esac
1124
1125 done
1126
1127
1128 if test -f ./.genmakerc ; then
1129 echo
1130 echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
1131 echo " file. This file format is no longer supported. Please see:"
1132 echo
1133 echo " http://mitgcm.org/devel_HOWTO/"
1134 echo
1135 echo " for directions on how to setup and use the new \"genmake2\" input"
1136 echo " files and send an email to MITgcm-support@mitgcm.org if you want help."
1137 echo
1138 fi
1139
1140 # Find the MITgcm ${ROOTDIR}
1141 if test "x${ROOTDIR}" = x ; then
1142 tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1143 if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
1144 ROOTDIR=".."
1145 else
1146 for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1147 if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
1148 ROOTDIR=$d
1149 printf "Warning: ROOTDIR was not specified but there appears to be"
1150 echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
1151 break
1152 fi
1153 done
1154 fi
1155 fi
1156 if test "x${ROOTDIR}" = x ; then
1157 echo "Error: Cannot determine ROOTDIR for MITgcm code."
1158 echo " Please specify a ROOTDIR using either an options "
1159 echo " file or a command-line option."
1160 exit 1
1161 fi
1162 if test ! -d ${ROOTDIR} ; then
1163 echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
1164 exit 1
1165 fi
1166
1167 # Find the MITgcm ${THISVER}
1168 if test -f "${ROOTDIR}/doc/tag-index" ; then
1169 THISVER=`grep '^checkpoint' ${ROOTDIR}/doc/tag-index | head -1`
1170 fi
1171
1172 if test "x$MAKEFILE" = x ; then
1173 MAKEFILE="Makefile"
1174 fi
1175
1176 echo " getting OPTFILE information: "
1177 if test "x${OPTFILE}" = x ; then
1178 if test "x$MITGCM_OF" = x ; then
1179 echo "Warning: no OPTFILE specified so we'll look for possible settings"
1180 printf "\n=== Searching for possible settings for OPTFILE ===\n"
1181 find_possible_configs
1182 else
1183 OPTFILE=$MITGCM_OF
1184 fi
1185 fi
1186 if test "x$OPTFILE" != xNONE ; then
1187 if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
1188 echo " using OPTFILE=\"$OPTFILE\""
1189 . "$OPTFILE"
1190 RETVAL=$?
1191 if test "x$RETVAL" != x0 ; then
1192 printf "Error: failed to source OPTFILE \"$OPTFILE\""
1193 echo "--please check that variable syntax is bash-compatible"
1194 exit 1
1195 fi
1196 if test "x$DUMPSTATE" != xf ; then
1197 cp -f $OPTFILE "genmake_optfile"
1198 fi
1199 else
1200 echo "Error: can't read OPTFILE=\"$OPTFILE\""
1201 exit 1
1202 fi
1203 fi
1204
1205 echo " getting AD_OPTFILE information: "
1206 if test "x${AD_OPTFILE}" = x ; then
1207 if test "x$MITGCM_AD_OF" = x ; then
1208 AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
1209 else
1210 AD_OPTFILE=$MITGCM_AD_OF
1211 fi
1212 fi
1213 if test "x${AD_OPTFILE}" != xNONE ; then
1214 if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
1215 echo " using AD_OPTFILE=\"$AD_OPTFILE\""
1216 . "$AD_OPTFILE"
1217 RETVAL=$?
1218 if test "x$RETVAL" != x0 ; then
1219 printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1220 echo "--please check that variable syntax is bash-compatible"
1221 exit 1
1222 fi
1223 if test "x$DUMPSTATE" != xf ; then
1224 cp -f $AD_OPTFILE "genmake_ad_optfile"
1225 fi
1226 else
1227 echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
1228 exit 1
1229 fi
1230 fi
1231
1232 #====================================================================
1233 # Set default values if not set by the optfile
1234 #
1235 # Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined. If not,
1236 # either set defaults or complain and abort!
1237 if test ! "x$BASH" = x ; then
1238 # add a trailing space so that it works within the Makefile syntax (see below)
1239 BASH="$BASH "
1240 fi
1241 if test "x$FC" = x ; then
1242 cat <<EOF 1>&2
1243
1244 Error: no Fortran compiler: please specify using one of the following:
1245 1) within the options file ("FC=...") as specified by "-of=OPTFILE"
1246 2) the "-fc=XXX" command-line option
1247 3) the "./genmake_local" file
1248 EOF
1249 exit 1
1250 fi
1251 if test "x$CC" = x ; then
1252 CC=cc
1253 # cat <<EOF 1>&2
1254 # Error: no C compiler: please specify using one of the following:
1255 # 1) within the options file ("CC=...") as specified by "-of=OPTFILE"
1256 # 2) the "-cc=XXX" command-line option
1257 # 3) the "./genmake_local" file
1258 # EOF
1259 # exit 1
1260 fi
1261 if test "x$LINK" = x ; then
1262 LINK=$FC
1263 fi
1264 if test "x$MAKE" = x ; then
1265 MAKE="make"
1266 fi
1267 if test "x$CPP" = x ; then
1268 CPP=cpp
1269 fi
1270 #EH3 === UGLY ===
1271 # The following is an ugly little hack to check for $CPP in /lib/ and
1272 # it should eventually be replaced with a more general function that
1273 # searches a combo of the user's path and a list of "usual suspects"
1274 # to find the correct location for binaries such as $CPP.
1275 for i in " " "/lib/" ; do
1276 echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1277 done
1278 #EH3 === UGLY ===
1279 echo "#define A a" | $CPP > test_cpp 2>&1
1280 RETVAL=$?
1281 if test "x$RETVAL" != x0 ; then
1282 cat <<EOF 1>&2
1283
1284 Error: C pre-processor "$CPP" failed the test case: please specify using:
1285
1286 1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1287 2) the "./genmake_local" file
1288 3) with the CPP environment variable
1289
1290 EOF
1291 exit 1
1292 else
1293 rm -f test_cpp
1294 fi
1295 look_for_makedepend
1296 if test "x$LN" = x ; then
1297 LN="ln -s"
1298 fi
1299 echo "test" > genmake_test_ln
1300 $LN genmake_test_ln genmake_tlink
1301 RETVAL=$?
1302 if test "x$RETVAL" != x0 ; then
1303 cat <<EOF 1>&2
1304
1305 Error: The command "ln -s" failed -- please specify a working soft-link
1306 command in the optfile.
1307
1308 EOF
1309 exit 1
1310 fi
1311 rm -f genmake_test_ln genmake_tlink
1312
1313 # Check for broken *.F/*.f handling and fix if possible
1314 check_for_broken_Ff
1315
1316 if test ! "x$MPI" = x ; then
1317 echo " Turning on MPI cpp macros"
1318 DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1319 fi
1320
1321 if test ! "x$TS" = x ; then
1322 echo " Turning on timing per timestep"
1323 DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1324 fi
1325
1326 printf "\n=== Checking system libraries ===\n"
1327 printf " Do we have the system() command using $FC... "
1328 cat > genmake_tcomp.$FS <<EOF
1329 program hello
1330 call system('echo hi')
1331 end
1332 EOF
1333 $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1334 RETVAL=$?
1335 if test "x$RETVAL" = x0 ; then
1336 HAVE_SYSTEM=t
1337 DEFINES="$DEFINES -DHAVE_SYSTEM"
1338 echo "yes"
1339 else
1340 HAVE_SYSTEM=
1341 echo "no"
1342 fi
1343 rm -f genmake_tcomp*
1344
1345 printf " Do we have the fdate() command using $FC... "
1346 cat > genmake_tcomp.$FS <<EOF
1347 program hello
1348 CHARACTER(128) string
1349 string = ' '
1350 call fdate( string )
1351 print *, string
1352 end
1353 EOF
1354 $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1355 RETVAL=$?
1356 if test "x$RETVAL" = x0 ; then
1357 HAVE_FDATE=t
1358 DEFINES="$DEFINES -DHAVE_FDATE"
1359 echo "yes"
1360 else
1361 HAVE_FDATE=
1362 echo "no"
1363 fi
1364 rm -f genmake_tcomp*
1365
1366 printf " Do we have the etime() command using $FC... "
1367 cat > genmake_tcomp.$FS <<EOF
1368 program hello
1369 REAL*4 ACTUAL, TARRAY(2)
1370 EXTERNAL ETIME
1371 REAL*4 ETIME
1372 actual = etime( tarray )
1373 print *, tarray
1374 end
1375 EOF
1376 $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1377 RETVAL=$?
1378 if test "x$RETVAL" = x0 ; then
1379 HAVE_ETIME=t
1380 DEFINES="$DEFINES -DHAVE_ETIME"
1381 echo "yes"
1382 else
1383 HAVE_ETIME=
1384 echo "no"
1385 fi
1386 rm -f genmake_tcomp*
1387
1388 printf " Can we call simple C routines (here, \"cloc()\") using $FC... "
1389 check_HAVE_CLOC
1390 if test "x$HAVE_CLOC" != x ; then
1391 echo "yes"
1392 else
1393 echo "no"
1394 fi
1395 rm -f genmake_t*
1396
1397 printf " Can we use stat() through C calls... "
1398 check_HAVE_STAT
1399 if test "x$HAVE_STAT" != x ; then
1400 echo "yes"
1401 else
1402 echo "no"
1403 fi
1404 rm -f genmake_t*
1405
1406 printf " Can we create NetCDF-enabled binaries... "
1407 check_netcdf_libs
1408 if test "x$HAVE_NETCDF" != x ; then
1409 echo "yes"
1410 else
1411 echo "no"
1412 fi
1413 DEFINES="$DEFINES $IGNORE_TIME"
1414
1415 printf "\n=== Setting defaults ===\n"
1416 printf " Adding MODS directories: "
1417 for d in $MODS ; do
1418 if test ! -d $d ; then
1419 echo
1420 echo "Error: MODS directory \"$d\" not found!"
1421 exit 1
1422 else
1423 printf " $d"
1424 SOURCEDIRS="$SOURCEDIRS $d"
1425 INCLUDEDIRS="$INCLUDEDIRS $d"
1426 fi
1427 done
1428 echo
1429
1430 if test "x${PLATFORM}" = x ; then
1431 PLATFORM=$p_PLATFORM
1432 fi
1433
1434 if test "x${EXEDIR}" = x ; then
1435 tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1436 if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
1437 EXEDIR=../exe
1438 else
1439 EXEDIR=.
1440 fi
1441 fi
1442 if test ! -d ${EXEDIR} ; then
1443 echo "Error: the specified EXEDIR (\"$EXEDIR\") does not exist!"
1444 exit 1
1445 fi
1446
1447 if test "x${TOOLSDIR}" = x ; then
1448 TOOLSDIR="$ROOTDIR/tools"
1449 fi
1450 if test ! -d ${TOOLSDIR} ; then
1451 echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1452 exit 1
1453 fi
1454 if test "x$S64" = x ; then
1455 echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
1456 RETVAL=$?
1457 if test "x${RETVAL}" = x0 ; then
1458 S64='$(TOOLSDIR)/set64bitConst.sh'
1459 else
1460 echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
1461 RETVAL=$?
1462 if test "x${RETVAL}" = x0 ; then
1463 S64='$(TOOLSDIR)/set64bitConst.csh'
1464 else
1465 cat <<EOF
1466
1467 ERROR: neither of the two default scripts:
1468
1469 ${TOOLSDIR}/set64bitConst.sh
1470 ${TOOLSDIR}/set64bitConst.csh
1471
1472 are working so please check paths or specify (with \$S64) a
1473 working version of this script.
1474
1475 EOF
1476 exit 1
1477 fi
1478 fi
1479 fi
1480 THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1481
1482 EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1483
1484 # We have a special set of source files in eesupp/src which are
1485 # generated from some template source files. We'll make them first so
1486 # they appear as regular source code
1487 if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
1488 echo " Making source files in eesupp from templates"
1489 ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
1490 RETVAL=$?
1491 if test "x${RETVAL}" = x0 ; then
1492 rm -f make_eesupp.errors
1493 else
1494 echo "Error: problem encountered while building source files in eesupp:"
1495 cat make_eesupp.errors 1>&2
1496 exit 1
1497 fi
1498 fi
1499
1500 #same for exch2
1501 if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then
1502 echo " Making source files in exch2 from templates"
1503 ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1
1504 RETVAL=$?
1505 if test "x${RETVAL}" = x0 ; then
1506 rm -f make_exch2.errors
1507 else
1508 echo "Error: problem encountered while building source files in exch2:"
1509 cat make_exch2.errors 1>&2
1510 exit 1
1511 fi
1512 fi
1513
1514 printf "\n=== Determining package settings ===\n"
1515 if test "x${PDEPEND}" = x ; then
1516 tmp=$ROOTDIR"/pkg/pkg_depend"
1517 if test -r $tmp ; then
1518 PDEPEND=$tmp
1519 else
1520 echo "Warning: No package dependency information was specified."
1521 echo " Please check that ROOTDIR/pkg/pkg_depend exists."
1522 fi
1523 else
1524 if test ! -r ${PDEPEND} ; then
1525 echo "Error: can't read package dependency info from PDEPEND=\"$PDEPEND\""
1526 exit 1
1527 fi
1528 fi
1529 echo " getting package dependency info from $PDEPEND"
1530 # Strip the comments and then convert the dependency file into
1531 # two arrays: PNAME, DNAME
1532 cat $PDEPEND | sed -e 's/#.*$//g' \
1533 | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
1534 > ./.pd_tmp
1535 RETVAL=$?
1536 if test ! "x${RETVAL}" = x0 ; then
1537 echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
1538 exit 1
1539 fi
1540 . ./.pd_tmp
1541 rm -f ./.pd_tmp
1542
1543 # Search for default packages. Note that a "$ROOTDIR/pkg/pkg_groups"
1544 # file should eventually be added so that, for convenience, one can
1545 # specify groups of packages using names like "ocean" and "atmosphere".
1546 echo " checking default package list: "
1547 if test "x${PDEFAULT}" = x ; then
1548 for i in "." $MODS ; do
1549 if test -r $i"/packages.conf" ; then
1550 PDEFAULT=$i"/packages.conf"
1551 break
1552 fi
1553 done
1554 fi
1555 if test "x${PDEFAULT}" = x ; then
1556 PDEFAULT="$ROOTDIR/pkg/pkg_default"
1557 fi
1558 if test "x${PDEFAULT}" = xNONE ; then
1559 echo " default packages file disabled"
1560 else
1561 if test ! -r $PDEFAULT ; then
1562 echo "Warning: can't read default packages from PDEFAULT=\"$PDEFAULT\""
1563 else
1564 echo " using PDEFAULT=\"$PDEFAULT\""
1565 # Strip the comments and add all the names
1566 def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1567 RETVAL=$?
1568 if test "x${RETVAL}" != x0 ; then
1569 printf "Error: can't parse default package list "
1570 echo "-- please check PDEFAULT=\"$PDEFAULT\""
1571 exit 1
1572 fi
1573 for i in $def ; do
1574 PACKAGES="$PACKAGES $i"
1575 done
1576 echo " before group expansion packages are: $PACKAGES"
1577 RET=1
1578 while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
1579 echo " after group expansion packages are: $PACKAGES"
1580 fi
1581 fi
1582
1583 echo " applying DISABLE settings"
1584 for i in $PACKAGES ; do
1585 echo $i >> ./.tmp_pack
1586 done
1587 for i in `grep "-" ./.tmp_pack` ; do
1588 j=`echo $i | sed 's/[-]//'`
1589 DISABLE="$DISABLE $j"
1590 done
1591 pack=
1592 for p in $PACKAGES ; do
1593 addit="t"
1594 for d in $DISABLE ; do
1595 if test "x$p" = "x$d" ; then
1596 addit="f"
1597 fi
1598 done
1599 if test "x$addit" = xt ; then
1600 pack="$pack $p"
1601 fi
1602 done
1603 PACKAGES="$pack"
1604 echo " applying ENABLE settings"
1605 echo "" > ./.tmp_pack
1606 PACKAGES="$PACKAGES $ENABLE"
1607 # Test if each explicitly referenced package exists
1608 for i in $PACKAGES ; do
1609 j=`echo $i | sed 's/[-+]//'`
1610 if test ! -d "$ROOTDIR/pkg/$j" ; then
1611 echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
1612 exit 1
1613 fi
1614 echo $i >> ./.tmp_pack
1615 done
1616 PACKAGES=
1617 for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
1618 PACKAGES="$PACKAGES $i"
1619 done
1620 rm -f ./.tmp_pack
1621 echo " packages are: $PACKAGES"
1622
1623 # Check availability of NetCDF and then either build the MNC template
1624 # files or delete mnc from the list of available packages.
1625 echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1626 RETVAL=$?
1627 if test "x$RETVAL" = x0 ; then
1628 if test "x$HAVE_NETCDF" != xt ; then
1629 cat <<EOF
1630
1631 *********************************************************************
1632 WARNING: the "mnc" package was enabled but tests failed to compile
1633 NetCDF applications. Please check that:
1634
1635 1) NetCDF is correctly installed for this compiler and
1636 2) the LIBS variable (within the "optfile") specifies the correct
1637 NetCDF library to link against.
1638
1639 Due to this failure, the "mnc" package is now DISABLED.
1640 *********************************************************************
1641
1642 EOF
1643 PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
1644 DISABLE="$DISABLE mnc"
1645 else
1646 ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
1647 RETVAL=$?
1648 if test "x${RETVAL}" = x0 ; then
1649 rm -f make_mnc.errors
1650 else
1651 echo "Error: problem encountered while building source files in pkg/mnc:"
1652 cat make_mnc.errors 1>&2
1653 exit 1
1654 fi
1655 fi
1656 fi
1657
1658 echo " applying package dependency rules"
1659 ck=
1660 while test "x$ck" != xtt ; do
1661 i=0
1662 # rtot=${#PNAME[@]}
1663 rtot=$nname
1664 while test $i -lt $rtot ; do
1665
1666 # Is $pname in the current $PACKAGES list?
1667 # pname=${PNAME[$i]}
1668 tmp="pname=\"\$PNAME_$i\""
1669 eval $tmp
1670 pin="f"
1671 for p in $PACKAGES ; do
1672 if test "x$p" = "x$pname" ; then
1673 pin="t"
1674 fi
1675 done
1676
1677 # Is the DNAME entry a (+) or (-) rule ?
1678 tmp="dname=\"\$DNAME_$i\""
1679 eval $tmp
1680 plus="-"
1681 echo $dname | grep '^+' > /dev/null 2>&1
1682 RETVAL=$?
1683 if test "x$RETVAL" = x0 ; then
1684 plus="+"
1685 fi
1686
1687 # Is $dname in the current $PACKAGES list?
1688 dname=`echo $dname | sed -e 's/^[+-]//'`
1689 din="f"
1690 for p in $PACKAGES ; do
1691 if test "x$p" = "x$dname" ; then
1692 din="t"
1693 fi
1694 done
1695
1696 # Do we need to add $dname according to the dependency rules?
1697 if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
1698 in_dis="f"
1699 for dis in $DISABLE ; do
1700 if test "x$dis" = "x$dname" ; then
1701 in_dis="t"
1702 fi
1703 done
1704 if test "x$in_dis" = xt ; then
1705 echo "Error: can't satisfy package dependencies:"
1706 echo " \"$dname\" is required by the dependency rules"
1707 echo " but is disallowed by the DISABLE settings"
1708 exit 1
1709 else
1710 PACKAGES="$PACKAGES $dname"
1711 ck=
1712 fi
1713 fi
1714
1715 # Do we need to get rid of $dname according to the dependency rules?
1716 if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
1717 echo "Error: can't satisfy package dependencies:"
1718 echo " \"$pname\" was requested but is disallowed by"
1719 echo " the dependency rules for \"$dname\""
1720 exit 1
1721 fi
1722 i=`echo "$i + 1" | bc -l`
1723 #i=$(( $i + 1 ))
1724 done
1725 ck=$ck"t"
1726 done
1727 echo " packages are: $PACKAGES"
1728 for i in $PACKAGES ; do
1729 adr="$ROOTDIR/pkg/$i"
1730 if test -d $adr ; then
1731 SOURCEDIRS="$SOURCEDIRS $adr"
1732 INCLUDEDIRS="$INCLUDEDIRS $adr"
1733 if test "x$i" = xautodiff ; then
1734 AUTODIFF_PKG_USED=t
1735 fi
1736 else
1737 echo "Error: the directory \"$adr\" for package $i doesn't exist"
1738 exit 1
1739 fi
1740 done
1741
1742 # Create a list of #define and #undef to enable/disable packages
1743 PACKAGES_DOT_H=PACKAGES_CONFIG.h
1744 # The following UGLY HACK sets multiple "#undef"s and it needs to go
1745 # away. On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
1746 # file would eventually be split up so that all package-related #define
1747 # statements could be separated and handled only by genmake.
1748 names=`ls -1 "$ROOTDIR/pkg"`
1749 all_pack=
1750 DISABLED_PACKAGES=
1751 for n in $names ; do
1752 if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
1753 has_pack="f"
1754 for pack in $PACKAGES ; do
1755 if test "x$pack" = "x$n" ; then
1756 has_pack="t"
1757 break
1758 fi
1759 done
1760 if test "x$has_pack" = xf ; then
1761 undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1762 DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
1763 fi
1764 fi
1765 done
1766 ENABLED_PACKAGES=
1767 for i in $PACKAGES ; do
1768 def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1769 ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
1770 #eh3 DEFINES="$DEFINES -D$def"
1771
1772 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
1773 case $i in
1774 aim_v23)
1775 ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
1776 echo "Warning: ALLOW_AIM is set to enable aim_v23."
1777 ;;
1778 esac
1779 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
1780
1781 done
1782
1783 echo " Adding STANDARDDIRS"
1784 BUILDDIR=${BUILDDIR:-.}
1785 if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
1786 STANDARDDIRS="eesupp model"
1787 fi
1788 if test "x$STANDARDDIRS" != x ; then
1789 for d in $STANDARDDIRS ; do
1790 adr="$ROOTDIR/$d/src"
1791 if test ! -d $adr ; then
1792 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1793 echo " is correct and that you correctly specified the STANDARDDIRS option"
1794 exit 1
1795 else
1796 SOURCEDIRS="$SOURCEDIRS $adr"
1797 fi
1798 adr="$ROOTDIR/$d/inc"
1799 if test ! -d $adr ; then
1800 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1801 echo " is correct and that you correctly specified the STANDARDDIRS option"
1802 exit 1
1803 else
1804 INCLUDEDIRS="$INCLUDEDIRS $adr"
1805 fi
1806 done
1807 fi
1808
1809 echo " Searching for *OPTIONS.h files in order to warn about the presence"
1810 echo " of \"#define \"-type statements that are no longer allowed:"
1811 CPP_OPTIONS=
1812 CPP_EEOPTIONS=
1813 spaths=". $INCLUDEDIRS"
1814 names=`ls -1 "$ROOTDIR/pkg"`
1815 for i in $spaths ; do
1816 try="$i/CPP_OPTIONS.h"
1817 if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
1818 echo " found CPP_OPTIONS=\"$try\""
1819 CPP_OPTIONS="$try"
1820 # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1821 for n in $names ; do
1822 test_for_package_in_cpp_options $CPP_OPTIONS $n
1823 done
1824 fi
1825 try="$i/CPP_EEOPTIONS.h"
1826 if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
1827 echo " found CPP_EEOPTIONS=\"$try\""
1828 # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
1829 #**** not yet enabled ****
1830 # test_for_mpi_in_cpp_eeoptions $try
1831 #**** not yet enabled ****
1832 CPP_EEOPTIONS="$try"
1833 fi
1834 done
1835 if test "x$CPP_OPTIONS" = x ; then
1836 echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
1837 exit 1
1838 fi
1839
1840 # Here, we build the list of files to be "run through" the adjoint
1841 # compiler.
1842 if test -f ./adSrcFiles.tmp ; then
1843 rm -f ./adSrcFiles.tmp
1844 fi
1845 echo " Creating the list of files for the adjoint compiler."
1846 for i in $SOURCEDIRS ; do
1847 list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
1848 for j in $list_files ; do
1849 cat $i/$j >> adSrcFiles.tmp
1850 done
1851 done
1852
1853 if test ! "x"$FS = "x.f" ; then
1854 cat adSrcFiles.tmp | sed -e "s/\.f/.$FS/g" > adSrcFiles.tmp_f
1855 mv -f adSrcFiles.tmp_f adSrcFiles.tmp
1856 fi
1857
1858 echo
1859 echo "=== Creating the Makefile ==="
1860 echo " setting INCLUDES"
1861 for i in $INCLUDEDIRS ; do
1862 if test ! -d $i ; then
1863 echo "Warning: can't find INCLUDEDIRS=\"$i\""
1864 fi
1865 done
1866
1867 echo " Determining the list of source and include files"
1868 rm -rf .links.tmp
1869 mkdir .links.tmp
1870 echo "# This section creates symbolic links" > srclinks.tmp
1871 echo "" >> srclinks.tmp
1872 printf 'F77_SRC_FILES = ' > F77srclist.tmp
1873 printf 'NON_AD_F77_SRC_FILES = ' > nonADF77srclist.tmp
1874 printf 'C_SRC_FILES = ' > csrclist.tmp
1875 printf 'F90_SRC_FILES = ' > F90srclist.tmp
1876 printf 'H_SRC_FILES = ' > hsrclist.tmp
1877 alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1878 for d in $alldirs ; do
1879 deplist=
1880 sfiles=`( cd $d; echo *.[h,c,F] | grep -v _cb2m)`
1881 sfiles=`( echo $sfiles; cd $d; echo *.F90 | grep -v _cb2m)`
1882 for sf in $sfiles ; do
1883 if test ! -r ".links.tmp/$sf" ; then
1884 if test -f "$d/$sf" ; then
1885 case $d/$sf in
1886 ./$PACKAGES_DOT_H)
1887 ;;
1888 ./AD_CONFIG.h)
1889 ;;
1890 ./FC_NAMEMANGLE.h)
1891 ;;
1892 ./BUILD_INFO.h)
1893 ;;
1894 *)
1895 touch .links.tmp/$sf
1896 deplist="$deplist $sf"
1897 ;;
1898 esac
1899 extn=`echo $sf | $AWK -F. '{print $NF}'`
1900 case $extn in
1901 F)
1902 echo " \\" >> F77srclist.tmp
1903 printf " $sf" >> F77srclist.tmp
1904 basename=${sf%%.F}
1905 isAD=`egrep ^$basename.f'[ ]*' adSrcFiles.tmp`
1906 if test -z "$isAD" ; then
1907 toBeIgnored=`egrep ^$basename'[ ]*' ${MODS}/dontCompile`
1908 if test -z "$toBeIgnored" ; then
1909 echo " \\" >> nonADF77srclist.tmp
1910 printf " $sf" >> nonADF77srclist.tmp
1911 else
1912 echo "Ignoring $sf"
1913 fi
1914 fi
1915 ;;
1916 F90)
1917 echo " \\" >> F90srclist.tmp
1918 printf " $sf" >> F90srclist.tmp
1919 ;;
1920 c)
1921 echo " \\" >> csrclist.tmp
1922 printf " $sf" >> csrclist.tmp
1923 ;;
1924 h)
1925 echo " \\" >> hsrclist.tmp
1926 printf " $sf" >> hsrclist.tmp
1927 ;;
1928 esac
1929 fi
1930 fi
1931 done
1932 if test "x$deplist" != x ; then
1933 if test "$d" != "." ; then
1934 echo "" >> srclinks.tmp
1935 echo "# These files are linked from $d" >> srclinks.tmp
1936 echo "$deplist :" >> srclinks.tmp
1937 printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp
1938 fi
1939 fi
1940 done
1941 rm -rf .links.tmp
1942 echo "" >> F77srclist.tmp
1943 for i in `cat ${MODS}/keepOriginal`
1944 do
1945 echo " \\" >> nonADF77srclist.tmp
1946 printf " $i" >> nonADF77srclist.tmp
1947 done
1948 echo "" >> nonADF77srclist.tmp
1949 echo "" >> csrclist.tmp
1950 echo "" >> F90srclist.tmp
1951 echo "" >> hsrclist.tmp
1952
1953 if test -f $MAKEFILE ; then
1954 mv -f $MAKEFILE "$MAKEFILE.bak"
1955 fi
1956
1957 echo " Writing makefile: $MAKEFILE"
1958
1959 echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
1960 echo "# $MACHINE" >> $MAKEFILE
1961 echo "# This makefile was generated automatically on" >> $MAKEFILE
1962 echo "# $THISDATE" >> $MAKEFILE
1963 echo "# by the command:" >> $MAKEFILE
1964 echo "# $0 $G2ARGS" >> $MAKEFILE
1965 echo "# executed by:" >> $MAKEFILE
1966 echo "# ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
1967
1968 EXE_AD=$EXECUTABLE"_ad"
1969 EXE_FTL=$EXECUTABLE"_ftl"
1970 EXE_SVD=$EXECUTABLE"_svd"
1971
1972 cat >>$MAKEFILE <<EOF
1973 #
1974 # OPTFILE="$OPTFILE"
1975 #
1976 # BUILDDIR : Directory where object files are written
1977 # SOURCEDIRS : Directories containing the source (.F) files
1978 # INCLUDEDIRS : Directories containing the header-source (.h) files
1979 # EXEDIR : Directory where executable that is generated is written
1980 # EXECUTABLE : Full path of executable binary
1981 #
1982 # CPP : C-preprocessor command
1983 # INCLUDES : Directories searched for header files
1984 # DEFINES : Macro definitions for CPP
1985 # MAKEDEPEND : Dependency generator
1986 # KPP : Special preprocessor command (specific to platform)
1987 # KFLAGS : Flags for KPP
1988 # FC : Fortran compiler command
1989 # FFLAGS : Configuration/debugging options for FC
1990 # FOPTIM : Optimization options for FC
1991 # LINK : Command for link editor program
1992 # LIBS : Library flags /or/ additional optimization/debugging flags
1993
1994 ROOTDIR = ${ROOTDIR}
1995 BUILDDIR = ${BUILDDIR}
1996 SOURCEDIRS = ${SOURCEDIRS}
1997 INCLUDEDIRS = ${INCLUDEDIRS}
1998 EXEDIR = ${EXEDIR}
1999 EXECUTABLE = \$(EXEDIR)/${EXECUTABLE}
2000 TOOLSDIR = ${TOOLSDIR}
2001
2002 #eh3 new defines for the adjoint work
2003 AUTODIFF = ${ROOTDIR}/pkg/autodiff
2004 EXE_AD = ${EXE_AD}
2005 EXE_FTL = ${EXE_FTL}
2006 EXE_SVD = ${EXE_SVD}
2007
2008 ENABLED_PACKAGES = ${ENABLED_PACKAGES}
2009 DISABLED_PACKAGES = ${DISABLED_PACKAGES}
2010
2011 # These files are created by Makefile
2012 SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
2013
2014 EOF
2015
2016 # Note: figure out some way to add Hyades JAM libraries here
2017
2018 cat >>$MAKEFILE <<EOF
2019 # Unix ln (link)
2020 LN = ${LN}
2021 # C preprocessor
2022 CPP = cat \$< | ${S64} | ${CPP}
2023 # Dependency generator
2024 MAKEDEPEND = ${MAKEDEPEND}
2025 # Special preprocessor (KAP on DECs, FPP on Crays)
2026 KPP = ${KPP}
2027 # Fortran compiler
2028 FC = ${FC}
2029 # Fortran compiler
2030 F90C = ${F90C}
2031 # C compiler
2032 CC = ${CC}
2033 # Link editor
2034 LINK = ${LINK} ${LDADD}
2035
2036 # Defines for CPP
2037 DEFINES = ${DEFINES}
2038 # Includes for CPP
2039 INCLUDES = ${INCLUDES}
2040 # Flags for KPP
2041 KFLAGS1 = ${KFLAGS1}
2042 KFLAGS2 = ${KFLAGS2}
2043 # Optim./debug for FC
2044 FFLAGS = ${FFLAGS}
2045 FOPTIM = ${FOPTIM}
2046 # Optim./debug/format for FC
2047 F90FLAGS = ${F90FLAGS}
2048 F90OPTIM = ${F90OPTIM}
2049 F90FIXEDFORMAT = ${F90FIXEDFORMAT}
2050 # Flags for CC
2051 CFLAGS = ${CFLAGS}
2052 # Files that should not be optimized
2053 NOOPTFILES = ${NOOPTFILES}
2054 NOOPTFLAGS = ${NOOPTFLAGS}
2055 # Flags and libraries needed for linking
2056 LIBS = ${LIBS}
2057 # Name of the Mekfile
2058 MAKEFILE=${MAKEFILE}
2059
2060 EOF
2061
2062 cat F77srclist.tmp >> $MAKEFILE
2063 cat nonADF77srclist.tmp >> $MAKEFILE
2064 cat csrclist.tmp >> $MAKEFILE
2065 cat F90srclist.tmp >> $MAKEFILE
2066 cat hsrclist.tmp >> $MAKEFILE
2067
2068 rm -f F77srclist.tmp nonADF77srclist.tmp csrclist.tmp hsrclist.tmp flist.tmp clist.tmp F90srclist.tmp
2069
2070 echo >> $MAKEFILE
2071
2072 # add definitions for preprocessed sources
2073 # and note that not all systems allow case sensitive extensions
2074 # hence the $FS and $FS90 here.
2075 # for fixed format f90 files we use ff90 or FF90 resp
2076 # but these are not expected to be the original source files
2077
2078 echo 'F77_PP_SRC_FILES = $(F77_SRC_FILES:.F=.'$FS')' >> $MAKEFILE
2079 echo 'F90_PP_SRC_FILES = $(F90_SRC_FILES:.F90=.'$FS90')' >> $MAKEFILE
2080 echo >> $MAKEFILE
2081 echo '.SUFFIXES:' >> $MAKEFILE
2082 echo '.SUFFIXES: .o .'$FS' .p .F .c .f'$FS90' .'$FS90' .FF90 .F90' >> $MAKEFILE
2083
2084 cat >>$MAKEFILE <<EOF
2085
2086 # all the source files linked from the various locations:
2087 ALL_LINKED_FILES= \
2088 \$(F77_SRC_FILES) \
2089 \$(C_SRC_FILES) \
2090 \$(H_SRC_FILES) \
2091 \$(F90_SRC_FILES) \
2092 \$(SPECIAL_FILES)
2093
2094 all: depend \$(EXECUTABLE)
2095
2096 depend: \$(ALL_LINKED_FILES)
2097 \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
2098 \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2099 -rm -f makedepend.out
2100
2101 .PHONY: depend
2102
2103 OBJFILES= \$(F77_SRC_FILES:.F=.o) \$(C_SRC_FILES:.c=.o) \$(F90_SRC_FILES:.F90=.o)
2104
2105 \$(EXECUTABLE): \$(OBJFILES)
2106 @echo Creating \$@ ...
2107 \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2108
2109 output.txt: \$(EXECUTABLE)
2110 @printf 'running ... '
2111 @\$(EXECUTABLE) > \$@
2112
2113 # Special targets (SPECIAL_FILES) which are created by make
2114 ${PACKAGES_DOT_H}:
2115 @echo Creating \$@ ...
2116 @$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) > \$@
2117 AD_CONFIG.h:
2118 @echo Creating \$@ ...
2119 @$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 > \$@
2120 FC_NAMEMANGLE.h:
2121 @echo Creating \$@ ...
2122 echo "$FC_NAMEMANGLE" > \$@
2123
2124 BUILD_INFO.h:
2125 @echo Creating \$@ ...
2126 EOF
2127
2128 test ! "x$THISVER" = x && echo " -echo \"#define THISVER '$THISVER'\" > \$@" >> $MAKEFILE
2129 test ! "x$THISUSER" = x && echo " -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
2130 test ! "x$THISDATE" = x && echo " -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2131 test ! "x$THISHOST" = x && echo " -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2132
2133 cat >>$MAKEFILE <<EOF
2134
2135 # The normal chain of rules is ( .F - .$FS - .o )
2136
2137 ## This nullifies any default implicit rules concerning these two file types:
2138 %.o : %.F
2139
2140 .F.$FS:
2141 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2142 .$FS.o:
2143 \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2144 .F90.$FS90:
2145 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2146 .FF90.f$FS90:
2147 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2148 .$FS90.o:
2149 \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
2150 .f$FS90.o:
2151 \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$(F90FIXEDFORMAT) \$<
2152 .c.o:
2153 \$(CC) \$(CFLAGS) -c \$<
2154
2155 # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
2156 .F.p:
2157 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2158 .p.$FS:
2159 \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
2160
2161 #=========================================
2162 #=== Cleanup Rules ===
2163
2164 CLEAN: Clean
2165 -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2166 -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2167 -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2168 -rm -f \$(EXECUTABLE) output.txt ad_output.txt STD*
2169
2170 Clean: clean cleanlinks
2171 -rm -f *.F
2172 -rm -f \$(SPECIAL_FILES)
2173 -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak
2174
2175 clean:
2176 -rm -rf *.o *.$FS *.p *.f$FS90 *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template *_mod.h *_mod.F90 *.FF90 *.mod-whirl ad_input*
2177 -rm -rf temp.sed reslice.dat
2178
2179 cleanlinks:
2180 -find . -type l -exec rm {} \;
2181
2182 .PHONY: clean Clean CLEAN
2183
2184
2185 #=========================================
2186 #=== self regeneration ===
2187 # can't call this target "Makefile"
2188 # because unfortunately the genmake script
2189 # invoked here uses
2190 # make itself for checking things and we
2191 # end up in a recursion.
2192
2193 makefile:
2194 $THIS_SCRIPT $G2ARGS
2195
2196 # because the file is called Makefile
2197 .PHONY: makefile
2198
2199 #====================================
2200 #=== Automatic Differentiation ===
2201
2202 ifndef OPENADROOT
2203 \$(error "Error: environment variable OPENADROOT not defined!")
2204 endif
2205
2206 ifndef XAIFSCHEMAROOT
2207 \$(error "Error: environment variable XAIFSCHEMAROOT not defined!")
2208 endif
2209
2210 ifndef XAIFBOOSTERROOT
2211 \$(error "Error: environment variable XAIFBOOSTERROOT not defined!")
2212 endif
2213
2214 EOF
2215
2216 echo " Add the source list for AD code generation"
2217 echo >> $MAKEFILE
2218 printf "AD_FILES = " >> $MAKEFILE
2219 AD_FILES=`cat adSrcFiles.tmp`
2220 for i in $AD_FILES ; do
2221 echo " \\" >> $MAKEFILE
2222 printf " $i" >> $MAKEFILE
2223 done
2224 echo >> $MAKEFILE
2225 rm -f adSrcFiles.tmp
2226
2227 cat >>$MAKEFILE <<EOF
2228
2229
2230 # files to be converted:
2231 # right now there is no quick hack
2232 # to pick these out automatically
2233 # but we will be using the
2234 # canonicalizer anyway
2235 CB2M_F90_SRC_NAMES = \
2236 SIZE \
2237 EEPARAMS \
2238 PARAMS \
2239 BAR2 \
2240 BARRIER \
2241 CD_CODE_VARS \
2242 CG2D \
2243 CG3D \
2244 DFILE \
2245 DYNVARS \
2246 EEIO \
2247 EESUPPORT \
2248 EOS \
2249 EXCH_JAM \
2250 EXCH \
2251 FC_NAMEMANGLE \
2252 FFIELDS \
2253 GAD \
2254 GLOBAL_MAX \
2255 GLOBAL_SUM \
2256 GMREDI \
2257 GMREDI_TAVE \
2258 GRID \
2259 MPI_INFO \
2260 SOLVE_FOR_PRESSURE3D \
2261 SOLVE_FOR_PRESSURE \
2262 SURFACE \
2263 tamc \
2264 tamc_keys \
2265 cost \
2266 g_cost \
2267 ctrl \
2268 ctrl_dummy \
2269 ctrl_weights \
2270 optim \
2271 grdchk
2272
2273 .PHONY: adAll
2274 adAll: \$(EXE_AD) ncheckLev.conf
2275
2276 CB2M_F90_PP_SRC_FILES=\$(addsuffix _mod.f$FS90, \$(CB2M_F90_SRC_NAMES))
2277
2278 .PRECIOUS: \$(CB2M_F90_PP_SRC_FILES) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.ff90)
2279
2280 .PHONY: adDepend
2281 adDepend: \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(addsuffix _mod.FF90, \$(CB2M_F90_SRC_NAMES)) \$(F77_SRC_FILES:.F=_cb2m.FF90)
2282 \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
2283 \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2284 -rm -f makedepend.out
2285
2286 OPENAD_SUPPORT_F90_SRC_FILES = \
2287 w2f__types.f90 \
2288 active_module.f90 \
2289 OpenAD_checkpoints.f90 \
2290 OpenAD_dct.f90 \
2291 OpenAD_rev.f90 \
2292 OpenAD_tape.f90
2293
2294 OPENAD_SUPPORT_C_SRC_FILES = \
2295 iaddr.c \
2296 timeRatio.c
2297
2298 f95_test_mods.f90: \$(OPENAD_SUPPORT_F90_SRC_FILES)
2299 cat \$^ > \$@
2300
2301 f95_test.f90: all_mods.xb.x2w.w2f.pp.f \$(NON_AD_F77_SRC_FILES:.F=_cb2m.ff90) ad_input_code.w2f.canon.xb.x2w.w2f.rs.pp.f
2302 cat \$^ > \$@
2303
2304 f95_test.out: f95_test_mods.f90 f95_test.f90
2305 f95 -w=unused -maxcontin=132 -c f95_test_mods.f90 > \$@ 2>&1
2306 f95 -w=unused -maxcontin=132 -c -fixed f95_test.f90 >> \$@ 2>&1
2307
2308 AD_OBJ_FILES=\$(OPENAD_SUPPORT_F90_SRC_FILES:.f90=.o) \$(OPENAD_SUPPORT_C_SRC_FILES:.c=.o) all_mods.xb.x2w.w2f.pp.o ad_input_code.w2f.canon.xb.x2w.w2f.rs.pp.o \$(NON_AD_F77_SRC_FILES:.F=_cb2m.o) \$(C_SRC_FILES:.c=.o) \$(F90_SRC_FILES:.F90=.o)
2309
2310 \$(EXE_AD): \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(AD_OBJ_FILES)
2311 @echo Creating \$@ ...
2312 \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES) \$(LIBS)
2313
2314 # makefile debug rule
2315 openad: ad_input_code.w2f.canon.xb.x2w.w2f.rs.pp.f
2316 .PHONY: openad
2317
2318 # create the module files
2319 %_mod.FF90 : %.h ${MODS}/cb2mGetModules.csh ${MODS}/cb2mGetModules.awk
2320 ${MODS}/cb2mGetModules.csh $< ${MODS}/cb2mGetModules.awk
2321
2322 # create the header files
2323 %_mod.h : %.h ${MODS}/cb2mGetHeaders.csh ${MODS}/cb2mGetHeaders.awk
2324 ${MODS}/cb2mGetHeaders.csh $< ${MODS}/cb2mGetHeaders.awk
2325
2326 # change everybody else to use the new module files:
2327 %_cb2m.FF90 : %.F ${MODS}/cb2mUseModules.bash
2328 ${MODS}/cb2mUseModules.bash $<
2329
2330 # makefile debug rule
2331 small_f: \$(CB2M_F90_PP_SRC_FILES)
2332 .PHONY: small_f
2333
2334 ad_output.txt: \$(EXE_AD)
2335 @printf 'linking data files ... '
2336 \$(LN) -f ../input_ad/data* ../input_ad/eedata .
2337 \$(LN) -f ../../global_ocean.90x40x15/input/*.bin .
2338 @printf 'running ... '
2339 @./\$(EXE_AD) > \$@
2340
2341 CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.ff90)
2342 ad_input_code.$FS: ${MODS}/maxMinDefs.f \$(CB2M_AD_FILES)
2343 cat \$^ > \$@
2344
2345 # strip all comments and blanks to reduce
2346 # the file size in order to reduce perl's memory requirements
2347 ad_input_code_sf.f : ad_input_code.f
2348 cat \$^ | sed -f ${MODS}/strip.sed | sed -f ${MODS}/stop2print.sed > \$@
2349
2350 # mfef90 preprocessing
2351 # expand statement functions
2352 # expose mfef90 specific substring handling
2353 # add the w2f__types module
2354 ad_input_code_sf.w2f.f: ad_input_code_sf.f mfef90 whirl2f whirl2f_be w2f__types.f90
2355 ./mfef90 -z -F -N132 \$<
2356 ./whirl2f \$<
2357 cat w2f__types.f90 \$@ > \$@.1
2358 mv \$@.1 \$@
2359
2360 # canonicalizer
2361 ad_input_code_sf.w2f.canon.f: ad_input_code_sf.w2f.f canon.v1.py
2362 python canon.v1.py \$< > \$@
2363
2364 # F -> WHIRL
2365 # note that the canonicalized version cuts off at col 72
2366 # doing this also for string constants which is ok as long
2367 # as we are in fixed mode and cut of exactly there.
2368 # Otherwise mfef90 patches in spaces to fill up to 72 (or 132)
2369 # characters respectively.
2370 ad_input_code_sf.w2f.canon.B: ad_input_code_sf.w2f.canon.f mfef90
2371 ./mfef90 -z -F \$<
2372
2373 # WHIRL -> XAIF
2374 ad_input_code_sf.w2f.canon.xaif : ad_input_code_sf.w2f.canon.B whirl2xaif
2375 ./whirl2xaif -s -n --debug 1 -o \$@ \$<
2376
2377 # XAIF -> XAIF'
2378 ad_input_code_sf.w2f.canon.xb.xaif : ad_input_code_sf.w2f.canon.xaif xaif.xsd xaif_base.xsd xaif_inlinable_intrinsics.xsd xaif_derivative_propagator.xsd xaif_output.xsd openad_adm
2379 ./openad_adm -f -t forward_step -i \$< -c \${XAIFSCHEMAROOT}/schema/examples/inlinable_intrinsics.xaif -o \$@ -I -r -p "recip_hFacC recip_rA GM_Kmin_horiz"
2380
2381 # XAIF' -> WHIRL'
2382 ad_input_code_sf.w2f.canon.xb.x2w.B : ad_input_code_sf.w2f.canon.xb.xaif xaif2whirl
2383 ./xaif2whirl --debug 1 --structured ad_input_code_sf.w2f.canon.B \$<
2384
2385 # WHIRL' -> F'
2386 ad_input_code_sf.w2f.canon.xb.x2w.w2f.f: ad_input_code_sf.w2f.canon.xb.x2w.B whirl2f whirl2f_be
2387 ./whirl2f -openad \$<
2388
2389 # undo slice hiding
2390 # insert template directives
2391 ad_input_code_sf.w2f.canon.xb.x2w.w2f.rs.f: ad_input_code_sf.w2f.canon.xb.x2w.w2f.f reslicer.py ${MODS}/insertTemplateDir.bash
2392 python reslicer.py \$< > \$<.1
2393 ${MODS}/insertTemplateDir.bash \$<.1 \$@
2394 rm \$<.1
2395
2396 # postprocess F'
2397 ad_input_code_sf.w2f.canon.xb.x2w.w2f.rs.pp.f: ad_input_code_sf.w2f.canon.xb.x2w.w2f.rs.f multi-pp.pl ${MODS}/ad_inline.f ${MODS}/ad_template.checkpoint.f ${MODS}/ad_template.plain.f ${MODS}/ad_template.split.f ${MODS}/ad_template.sa_cg2d.f
2398 perl multi-pp.pl -inline=${MODS}/ad_inline.f \$<
2399 cat \$@ | sed 's/RETURN//' > \$@.1
2400 mv \$@.1 \$@
2401
2402 # extract all transformed modules
2403 all_mods.xb.x2w.w2f.pp.f: ad_input_code_sf.w2f.canon.xb.x2w.w2f.rs.pp.f
2404 cat \$< | sed -n '/MODULE /,/END MODULE/p' > \$@
2405
2406 # remove the transformed globals module from the
2407 # transformed ad_input_code file
2408 # and remove for now the duplicate variables
2409 # and fix 2 data statements
2410 ad_input_code.w2f.canon.xb.x2w.w2f.rs.pp.f: ad_input_code_sf.w2f.canon.xb.x2w.w2f.rs.pp.f ${MODS}/fixData.sed
2411 # cat \$< | sed '/MODULE /,/END MODULE/d' | sed '/^ INTEGER(w2f__i4) DOLOOP_UB/d' | sed -f ${MODS}/fixData.sed > \$@
2412 cat \$< | sed '/MODULE /,/END MODULE/d' | sed '/^ INTEGER(w2f__i4) DOLOOP_UB/d' > \$@
2413
2414 # setup some links
2415 %.xsd:
2416 \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ .
2417
2418 mfef90:
2419 \$(LN) \${OPENADROOT}/Open64/osprey1.0/targ_ia32_ia64_linux/crayf90/sgi/mfef90 .
2420
2421 # link the support files:
2422 \$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES) ncheckLev.conf :
2423 \$(LN) ${MODS}/\$@ .
2424
2425 whirl2xaif xaif2whirl:
2426 \$(LN) \${OPENADROOT}/OpenADFortTk/OpenADFortTk-x86-Linux/bin/\$@ .
2427
2428 %.pl:
2429 \$(LN) \${OPENADROOT}/OpenADFortTk/OpenADFortTk-x86-Linux/bin/\$@ .
2430
2431 %.py:
2432 \$(LN) \${OPENADROOT}/OpenADFortTk/tools/canonicalize/\$@ .
2433
2434 whirl2f whirl2f_be:
2435 \$(LN) \${OPENADROOT}/Open64/osprey1.0/targ_ia32_ia64_linux/whirl2f/\$@ .
2436
2437 openad_adm:
2438 \$(LN) \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/test/t \$@
2439
2440 EOF
2441
2442 if test "x$EXEHOOK" != x ; then
2443 printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
2444 fi
2445
2446 echo " Making list of \"exceptions\" that need \".p\" files"
2447 for i in $KPPFILES ; do
2448 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
2449 RETVAL=$?
2450 if test "x$RETVAL" != x0 ; then
2451 echo "Error: unable to add file \"$i\" to the exceptions list"
2452 fi
2453 echo "$base.$FS: $base.p" >> $MAKEFILE
2454 done
2455
2456 echo " Making list of NOOPTFILES"
2457 for i in $NOOPTFILES ; do
2458 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
2459 RETVAL=$?
2460 if test "x$RETVAL" != x0 ; then
2461 echo "Error: unable to add file \"$i\" to the exceptions list"
2462 fi
2463 echo "$base.o: $base.$FS" >> $MAKEFILE
2464 printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
2465 done
2466
2467 echo " Add rules for links"
2468 cat srclinks.tmp >> $MAKEFILE
2469 rm -f srclinks.tmp
2470
2471 printf "\n=== Done ===\n"
2472
2473 # Create special header files
2474 $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"
2475 if test ! -f $PACKAGES_DOT_H ; then
2476 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2477 else
2478 cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
2479 RETVAL=$?
2480 if test "x$RETVAL" = x0 ; then
2481 rm -f $PACKAGES_DOT_H".tmp"
2482 else
2483 mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
2484 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2485 fi
2486 fi
2487 if test ! -f AD_CONFIG.h ; then
2488 $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
2489 fi
2490
2491
2492 # Write the "state" for future records
2493 if test "x$DUMPSTATE" != xf ; then
2494 printf "" > genmake_state
2495 for i in $gm_state ; do
2496 t1="t2=\$$i"
2497 eval $t1
2498 echo "$i='$t2'" >> genmake_state
2499 done
2500 fi

  ViewVC Help
Powered by ViewVC 1.1.22