/[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.251 - (hide annotations) (download)
Sun Jul 21 23:21:36 2013 UTC (6 years, 2 months ago) by jmc
Branch: MAIN
Changes since 1.250: +80 -25 lines
- remove default setting of MPIINCLUDEDIR from $MPIHOME (always been broken);
- only create local ./mpi_headers dir if using MPI and MPIINCLUDEDIR is set;
- add new variable (LOCAL_MPI_HEADERS, replace MPI_HEADER_FILES_INC) in
  Makefile, which is set by genmake2, and check which mpi-headers are needed.
  Note: need to update adjoint_options/adjoint_diva_mpi accordingly.
- update target "CLEAN" (to remove ./mpi_headers/ dir).

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