/[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.226 - (hide annotations) (download)
Fri Sep 30 20:03:10 2011 UTC (7 years, 9 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint63d
Changes since 1.225: +3 -1 lines
add target "adobj" (just for OBJFILES files) to Makefile

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