/[MITgcm]/MITgcm/tools/genmake2
ViewVC logotype

Annotation of /MITgcm/tools/genmake2

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


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

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