/[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.218 - (hide annotations) (download)
Sun Dec 26 01:04:45 2010 UTC (13 years, 2 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint62q
Changes since 1.217: +27 -13 lines
if asking for cyrus-makedepend but unable to build it, return to default

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

  ViewVC Help
Powered by ViewVC 1.1.22