/[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.238 - (hide annotations) (download)
Tue Aug 28 21:11:22 2012 UTC (7 years, 2 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint63s
Changes since 1.237: +53 -61 lines
- define variable MAKE within Makefile and use it in place of 'make';
- update AD_CONFIG.h (if needed) before building any of the executable
  (forward, adjoint or tangent-lin); this involves a 2nd invocation of make;
  and add the usual #ifndef/#define AD_CONFIG_H in AD_CONFIG.h;

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