/[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.278 - (hide annotations) (download)
Fri Jan 15 22:08:17 2016 UTC (3 years, 6 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint66c, checkpoint66b, checkpoint66a, checkpoint65z, checkpoint65x, checkpoint65y, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u
Changes since 1.277: +2 -5 lines
remove option "-nooptfile": a) not much used; and
b) easy to recover with: -of NONE (short version of: -optfile='NONE')
c) could be confusing with NOOPTFILES (= list of files to compile without
   compiler optimisation flags) setting.

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