/[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.250 - (hide annotations) (download)
Fri Apr 5 21:10:55 2013 UTC (10 years, 11 months ago) by jmc
Branch: MAIN
CVS Tags: checkpoint64i, checkpoint64h, checkpoint64j, checkpoint64g
Changes since 1.249: +31 -17 lines
change default makedepend from the system default to tools/xmakedepend:
When no makedepend is specified, select tools/xmakedepend it the test pass,
 otherwise select the system default (if exist and pass the test) or
 try to build cyrus-makedepend ; stop if none of the 3 works.

1 edhill 1.86 #! /usr/bin/env bash
2 edhill 1.1 #
3 jmc 1.250 # $Header: /u/gcmpack/MITgcm/tools/genmake2,v 1.249 2013/02/23 04:24:42 utke 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     # Parse the package dependency information
606     get_pdepend_list() {
607    
608     # strip the comments and then convert the dependency file into
609     # two arrays: PNAME, DNAME
610     cat $1 | sed -e 's/#.*$//g' \
611 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}' \
612 edhill 1.1 > ./.pd_tmp
613 jmc 1.205 RETVAL=$?
614     if test ! "x${RETVAL}" = x0 ; then
615 jmc 1.208 echo "Error: unable to parse package dependencies -- please check PKG_DEPEND=\"$1\""
616 jmc 1.205 exit 1
617     fi
618 edhill 1.34 . ./.pd_tmp
619 edhill 1.1 rm -f ./.pd_tmp
620     }
621    
622 edhill 1.31 # Build a CPP macro to automate calling C routines from FORTRAN
623     get_fortran_c_namemangling() {
624 edhill 1.89
625     #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
626     if test ! "x$FC_NAMEMANGLE" = x ; then
627 jmc 1.236 return 0
628 edhill 1.89 fi
629 jmc 1.212 echo " running: get_fortran_c_namemangling()" >> $LOGFILE
630 edhill 1.89
631 edhill 1.31 default_nm="#define FC_NAMEMANGLE(X) X ## _"
632 jmc 1.206
633 edhill 1.31 cat > genmake_test.c <<EOF
634     void tcall( char * string ) { tsub( string ); }
635     EOF
636 jmc 1.212 COMM="$CC $CFLAGS -c genmake_test.c"
637     echo ' '$COMM >> $LOGFILE
638     $COMM >> $LOGFILE 2>&1
639 edhill 1.31 RETVAL=$?
640     if test "x$RETVAL" != x0 ; then
641     FC_NAMEMANGLE=$default_nm
642 jmc 1.211 cat <<EOF>> $LOGFILE
643 edhill 1.39
644 jmc 1.212 WARNING: C test compile fails
645     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
646     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
647 edhill 1.39 EOF
648 edhill 1.31 return 1
649     fi
650 edhill 1.91 c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
651 edhill 1.31 RETVAL=$?
652     if test "x$RETVAL" != x0 ; then
653     FC_NAMEMANGLE=$default_nm
654 jmc 1.211 cat <<EOF>> $LOGFILE
655 edhill 1.39
656 jmc 1.212 WARNING: The "nm" command failed.
657     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
658     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
659 edhill 1.39 EOF
660 edhill 1.31 return 1
661     fi
662 edhill 1.118 cat > genmake_tcomp.$FS <<EOF
663 edhill 1.31 subroutine tcall( string )
664     character*(*) string
665     call tsub( string )
666     end
667     EOF
668 jmc 1.212 COMM="$FC $FFLAGS -c genmake_tcomp.$FS"
669     echo ' '$COMM >> $LOGFILE
670     $COMM >> $LOGFILE 2>&1
671 edhill 1.31 RETVAL=$?
672     if test "x$RETVAL" != x0 ; then
673     FC_NAMEMANGLE=$default_nm
674 jmc 1.211 cat <<EOF>> $LOGFILE
675 edhill 1.39
676 jmc 1.212 WARNING: FORTRAN test compile fails -- please see '$LOGFILE'
677     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
678     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
679 edhill 1.39 EOF
680 edhill 1.31 return 1
681     fi
682 edhill 1.91 f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
683 edhill 1.31 RETVAL=$?
684     if test "x$RETVAL" != x0 ; then
685     FC_NAMEMANGLE=$default_nm
686 jmc 1.211 cat <<EOF>> $LOGFILE
687 edhill 1.39
688 jmc 1.212 WARNING: The "nm" command failed.
689     WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
690     WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
691 edhill 1.39 EOF
692 edhill 1.31 return 1
693     fi
694    
695     c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
696     f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
697     c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
698     f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
699    
700     nmangle="X"
701     if test "x$c_a" != "x$f_a" ; then
702     comm="echo x$f_a | sed -e 's|x$c_a||'"
703     a=`eval $comm`
704     nmangle="$a ## $nmangle"
705     fi
706     if test "x$c_b" != "x$f_b" ; then
707     comm="echo x$f_b | sed -e 's|x$c_b||'"
708     b=`eval $comm`
709     nmangle="$nmangle ## $b"
710     fi
711    
712     FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) $nmangle"
713 edhill 1.32
714     # cleanup the testing files
715     rm -f genmake_tcomp.* genmake_test.*
716 jmc 1.212
717     echo " --> set FC_NAMEMANGLE='$FC_NAMEMANGLE'" >> $LOGFILE
718 edhill 1.31 }
719 edhill 1.1
720 edhill 1.39 check_HAVE_CLOC() {
721 jmc 1.211 echo >> $LOGFILE
722     echo "running: check_HAVE_CLOC()" >> $LOGFILE
723 edhill 1.39 get_fortran_c_namemangling
724     cat <<EOF > genmake_tc_1.c
725     $FC_NAMEMANGLE
726     #include <stdio.h>
727     #include <stdlib.h>
728     #include <unistd.h>
729     #include <assert.h>
730     #include <sys/time.h>
731     void FC_NAMEMANGLE(cloc) ( double *curtim )
732     {
733     struct timeval tv1;
734     gettimeofday(&tv1 , (void *)NULL );
735     *curtim = (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
736     *curtim = *curtim/1.E6;
737     }
738     EOF
739 mlosch 1.168 COMM="$CC $CFLAGS -c genmake_tc_1.c"
740 jmc 1.211 echo $COMM >> $LOGFILE
741     $COMM >> $LOGFILE 2>&1
742 edhill 1.39 RET_C=$?
743 edhill 1.118 cat <<EOF > genmake_tc_2.$FS
744 edhill 1.39 program hello
745 edhill 1.129 REAL*8 wtime
746 edhill 1.39 external cloc
747     call cloc(wtime)
748     print *," HELLO WORLD", wtime
749 edhill 1.128 end
750 edhill 1.39 EOF
751 mlosch 1.163 COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
752 jmc 1.211 echo $COMM >> $LOGFILE
753     $COMM >> $LOGFILE 2>&1
754 edhill 1.39 RET_F=$?
755 jmc 1.211 test -x ./genmake_tc && ./genmake_tc >> $LOGFILE 2>&1
756 edhill 1.39 RETVAL=$?
757     if test "x$RETVAL" = x0 ; then
758     HAVE_CLOC=t
759     fi
760     rm -f genmake_tc*
761 jmc 1.212 echo " --> set HAVE_CLOC='$HAVE_CLOC'" >> $LOGFILE
762 edhill 1.39 }
763    
764 edhill 1.137 check_HAVE_SIGREG() {
765 edhill 1.150 if test ! "x$HAVE_SIGREG" = x ; then
766     return
767     fi
768 jmc 1.211 echo >> $LOGFILE
769     echo "running: check_HAVE_SIGREG()" >> $LOGFILE
770 edhill 1.137 get_fortran_c_namemangling
771     cat <<EOF > genmake_tc_1.c
772     $FC_NAMEMANGLE
773     #include <stdlib.h>
774     #include <stdio.h>
775     #include <signal.h>
776     #include <errno.h>
777     #include <ucontext.h>
778    
779     int * ip;
780    
781     static void killhandler(
782     unsigned int sn, siginfo_t si, struct ucontext *sc )
783     {
784     *ip = *ip + 1;
785     return;
786     }
787    
788     void FC_NAMEMANGLE(sigreg) (int * aip)
789     {
790 edhill 1.138 struct sigaction s;
791 edhill 1.137 ip = aip;
792     s.sa_flags = SA_SIGINFO;
793     s.sa_sigaction = (void *)killhandler;
794     if(sigaction (SIGTERM,&s,(struct sigaction *)NULL)) {
795     printf("Sigaction returned error = %d\n", errno);
796     exit(0);
797     }
798     return;
799     }
800     EOF
801 mlosch 1.168 COMM="$CC $CFLAGS -c genmake_tc_1.c"
802 jmc 1.211 echo $COMM >> $LOGFILE
803     $COMM >> $LOGFILE 2>&1
804 edhill 1.137 RET_C=$?
805     cat <<EOF > genmake_tc_2.$FS
806     program hello
807     integer anint
808     common /iv/ anint
809     external sigreg
810     call sigreg(anint)
811     end
812     EOF
813 jmc 1.211 cat genmake_tc_2.$FS >> $LOGFILE
814 edhill 1.137 COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
815 jmc 1.211 echo $COMM >> $LOGFILE
816     $COMM >> $LOGFILE 2>&1
817 edhill 1.137 RETVAL=$?
818     if test "x$RETVAL" = x0 ; then
819     HAVE_SIGREG=t
820     fi
821     rm -f genmake_tc*
822 jmc 1.212 echo " --> set HAVE_SIGREG='$HAVE_SIGREG'" >> $LOGFILE
823 edhill 1.137 }
824    
825 edhill 1.130 check_HAVE_SETRLSTK() {
826 edhill 1.151 if test ! "x$HAVE_SETRLSTK" = x ; then
827     return
828     fi
829 jmc 1.211 echo >> $LOGFILE
830     echo "running: check_HAVE_SETRLSTK()" >> $LOGFILE
831 edhill 1.130 get_fortran_c_namemangling
832     cat <<EOF > genmake_tc_1.c
833     $FC_NAMEMANGLE
834     #include <sys/time.h>
835     #include <sys/resource.h>
836     #include <unistd.h>
837     void FC_NAMEMANGLE(setrlstk) ()
838     {
839     struct rlimit rls;
840     rls.rlim_cur = RLIM_INFINITY;
841     rls.rlim_max = RLIM_INFINITY;
842     setrlimit(RLIMIT_STACK, &rls);
843     return;
844     }
845     EOF
846 mlosch 1.168 COMM="$CC $CFLAGS -c genmake_tc_1.c"
847 jmc 1.211 echo $COMM >> $LOGFILE
848     $COMM >> $LOGFILE 2>&1
849 edhill 1.130 RET_C=$?
850     cat <<EOF > genmake_tc_2.$FS
851     program hello
852     external setrlstk
853     call setrlstk()
854     end
855     EOF
856 jmc 1.211 cat genmake_tc_2.$FS >> $LOGFILE
857 edhill 1.135 COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
858 jmc 1.211 echo $COMM >> $LOGFILE
859     $COMM >> $LOGFILE 2>&1
860 edhill 1.130 RETVAL=$?
861     if test "x$RETVAL" = x0 ; then
862     HAVE_SETRLSTK=t
863     fi
864     rm -f genmake_tc*
865 jmc 1.212 echo " --> set HAVE_SETRLSTK='$HAVE_SETRLSTK'" >> $LOGFILE
866 edhill 1.130 }
867    
868 edhill 1.108 check_HAVE_STAT() {
869 jmc 1.211 echo >> $LOGFILE
870     echo "running: check_HAVE_STAT()" >> $LOGFILE
871 edhill 1.108 get_fortran_c_namemangling
872     cat <<EOF > genmake_tc_1.c
873     $FC_NAMEMANGLE
874     #include <stdio.h>
875     #include <stdlib.h>
876     #include <unistd.h>
877     #include <sys/stat.h>
878     #include <sys/types.h>
879     void FC_NAMEMANGLE(tfsize) ( int *nbyte )
880     {
881     char name[512];
882     struct stat astat;
883    
884     name[0] = 'a'; name[1] = '\0';
885     if (! stat(name, &astat))
886     *nbyte = (int)(astat.st_size);
887     else
888     *nbyte = -1;
889     }
890     EOF
891 mlosch 1.168 COMM="$CC $CFLAGS -c genmake_tc_1.c"
892 jmc 1.211 echo $COMM >> $LOGFILE
893 mlosch 1.168 $COMM >> genmake_tc.log 2>&1
894 edhill 1.108 RET_C=$?
895 edhill 1.118 cat <<EOF > genmake_tc_2.$FS
896 edhill 1.108 program hello
897     integer nbyte
898     call tfsize(nbyte)
899     print *," HELLO WORLD", nbyte
900 edhill 1.128 end
901 edhill 1.108 EOF
902 jmc 1.211 cat genmake_tc_2.$FS >> $LOGFILE
903 edhill 1.135 COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
904 jmc 1.211 echo $COMM >> $LOGFILE
905 edhill 1.135 $COMM >> genmake_tc.log 2>&1
906 edhill 1.108 RETVAL=$?
907     if test "x$RETVAL" = x0 ; then
908     HAVE_STAT=t
909     fi
910     rm -f genmake_tc*
911 jmc 1.212 echo " --> set HAVE_STAT='$HAVE_STAT'" >> $LOGFILE
912 edhill 1.108 }
913    
914 edhill 1.60 check_netcdf_libs() {
915 edhill 1.113 if test ! "x$SKIP_NETCDF_CHECK" = x ; then
916     return
917     fi
918 jmc 1.211 echo >> $LOGFILE
919     echo "running: check_netcdf_libs()" >> $LOGFILE
920 edhill 1.117 cat <<EOF > genmake_tnc.F
921 edhill 1.60 program fgennc
922     #include "netcdf.inc"
923 edhill 1.113 EOF
924 jmc 1.245 #if test ! "x$MPI" = x ; then
925     # echo '#include "mpif.h"' >> genmake_tnc.F
926     #fi
927 edhill 1.117 cat <<EOF >> genmake_tnc.F
928 edhill 1.60 integer iret, ncid, xid
929     iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
930     IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
931     iret = nf_def_dim(ncid, 'X', 11, xid)
932     IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
933     iret = nf_close(ncid)
934     IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
935     end
936     EOF
937 jmc 1.210 echo "=== genmake_tnc.F >>>" > genmake_tnc.log
938 edhill 1.135 cat genmake_tnc.F >> genmake_tnc.log
939 jmc 1.210 echo "<<< genmake_tnc.F ===" >> genmake_tnc.log
940 edhill 1.111 RET_CPP=f
941 edhill 1.149 COMM="cat genmake_tnc.F | $CPP $DEFINES $INCLUDES"
942 edhill 1.135 echo "$COMM" >> genmake_tnc.log
943 dfer 1.155 eval $COMM > genmake_tnc.$FS 2>/dev/null && RET_CPP=t
944 edhill 1.111 if test "x$RET_CPP" = xf ; then
945     echo " WARNING: CPP failed to pre-process the netcdf test." \
946 edhill 1.133 >> genmake_tnc.log
947 edhill 1.111 echo " Please check that \$INCLUDES is properly set." \
948 edhill 1.133 >> genmake_tnc.log
949 edhill 1.111 fi
950 edhill 1.135 echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
951 edhill 1.153 echo " && $LINK $FFLAGS $FOPTIM -o genmake_tnc.o $LIBS" >> genmake_tnc.log
952 edhill 1.117 $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \
953 edhill 1.153 && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
954 edhill 1.60 RET_COMPILE=$?
955 jmc 1.211 cat genmake_tnc.log >> $LOGFILE
956 edhill 1.99
957     #EH3 Remove test program execution for machines that either disallow
958     #EH3 execution or cannot support it (eg. cross-compilers)
959     #EH3
960     #EH3 test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1
961     #EH3 RETVAL=$?
962     #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
963    
964     if test "x$RET_COMPILE" = x0 ; then
965 edhill 1.60 HAVE_NETCDF=t
966 jmc 1.211 echo "check_netcdf: successful" >> $LOGFILE
967 edhill 1.60 else
968 edhill 1.66 # try again with "-lnetcdf" added to the libs
969 jmc 1.210 echo "==> try again with added '-lnetcdf'" > genmake_tnc.log
970 edhill 1.149 echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
971 edhill 1.133 echo " && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
972 edhill 1.153 echo " && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
973 edhill 1.149 cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null \
974 edhill 1.117 && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \
975 edhill 1.153 && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
976 edhill 1.66 RET_COMPILE=$?
977 jmc 1.211 echo >> $LOGFILE
978     cat genmake_tnc.log >> $LOGFILE
979 edhill 1.99 if test "x$RET_COMPILE" = x0 ; then
980 edhill 1.66 LIBS="$LIBS -lnetcdf"
981     HAVE_NETCDF=t
982 jmc 1.211 echo "check_netcdf: successful" >> $LOGFILE
983 ce107 1.160 else
984     # try again with "-lnetcdff" added to the libs
985 jmc 1.210 echo "==> try again with added '-lnetcdff -lnetcdf'" > genmake_tnc.log
986 ce107 1.160 echo "cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS \ " >> genmake_tnc.log
987     echo " && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
988     echo " && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
989     cat genmake_tnc.F | $CPP $DEFINES $INCLUDES > genmake_tnc.$FS 2>/dev/null \
990     && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \
991     && $LINK $FFLAGS $FOPTIM -o genmake_tnc genmake_tnc.o $LIBS -lnetcdff -lnetcdf >> genmake_tnc.log 2>&1
992     RET_COMPILE=$?
993 jmc 1.211 echo >> $LOGFILE
994     cat genmake_tnc.log >> $LOGFILE
995 ce107 1.160 if test "x$RET_COMPILE" = x0 ; then
996     LIBS="$LIBS -lnetcdff -lnetcdf"
997     HAVE_NETCDF=t
998 jmc 1.211 echo "check_netcdf: successful" >> $LOGFILE
999 ce107 1.160 fi
1000 edhill 1.66 fi
1001 edhill 1.60 fi
1002     rm -f genmake_tnc*
1003 jmc 1.212 echo " --> set HAVE_NETCDF='$HAVE_NETCDF'" >> $LOGFILE
1004 edhill 1.60 }
1005    
1006 jahn 1.232 check_lapack_libs() {
1007     if test ! "x$SKIP_LAPACK_CHECK" = x ; then
1008     return
1009     fi
1010     echo >> $LOGFILE
1011     echo "running: check_lapack_libs()" >> $LOGFILE
1012     cat <<EOF > genmake_tla.F
1013     program fgenla
1014 jmc 1.236 integer info
1015 jahn 1.232 integer ipiv( 2 )
1016     double precision ab( 4, 2 ), b( 2 )
1017     data ab / 0., 0., 1., 2., 0., 2., 1., 0. /
1018     data b / 1., 1. /
1019     call dgbsv( 2, 1, 1, 1, ab, 4, ipiv, b, 2, info )
1020     IF (info .NE. 0) write(*,*) 'Error:', info
1021     write(*,*) b
1022     end
1023     EOF
1024     echo "=== genmake_tla.F >>>" > genmake_tla.log
1025     cat genmake_tla.F >> genmake_tla.log
1026     echo "<<< genmake_tla.F ===" >> genmake_tla.log
1027     RET_CPP=f
1028     COMM="cat genmake_tla.F | $CPP $DEFINES $INCLUDES"
1029     echo "$COMM" >> genmake_tla.log
1030     eval $COMM > genmake_tla.$FS 2>/dev/null && RET_CPP=t
1031     if test "x$RET_CPP" = xf ; then
1032     echo " WARNING: CPP failed to pre-process the lapack test." \
1033     >> genmake_tla.log
1034     echo " Please check that \$INCLUDES is properly set." \
1035     >> genmake_tla.log
1036     fi
1037     echo "$FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1038     echo " && $LINK $FFLAGS $FOPTIM -o genmake_tla.o $LIBS" >> genmake_tla.log
1039     $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1 \
1040     && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS >> genmake_tla.log 2>&1
1041     RET_COMPILE=$?
1042     cat genmake_tla.log >> $LOGFILE
1043    
1044     # test program execution not always possible (see check_netcdf_libs)
1045     #
1046     #test -x ./genmake_tla && ./genmake_tla >> genmake_tla.log 2>&1
1047     #RETVAL=$?
1048     #if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
1049    
1050     if test "x$RET_COMPILE" = x0 ; then
1051     HAVE_LAPACK=t
1052     echo "check_lapack: successful" >> $LOGFILE
1053     else
1054     # try again with "-llapack" added to the libs
1055     echo "==> try again with added '-llapack'" > genmake_tla.log
1056     echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1057     echo " && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1058     echo " && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack" >> genmake_tla.log
1059     cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null \
1060     && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1 \
1061     && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack >> genmake_tla.log 2>&1
1062     RET_COMPILE=$?
1063     echo >> $LOGFILE
1064     cat genmake_tla.log >> $LOGFILE
1065     if test "x$RET_COMPILE" = x0 ; then
1066     LIBS="$LIBS -llapack"
1067     HAVE_LAPACK=t
1068     echo "check_lapack: successful" >> $LOGFILE
1069     else
1070     # try again with "-lf77blas -lcblas" added to the libs
1071     echo "==> try again with added '-llapack -lf77blas -lcblas'" > genmake_tla.log
1072     echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1073     echo " && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1074     echo " && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas" >> genmake_tla.log
1075     cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null \
1076     && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1 \
1077     && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas >> genmake_tla.log 2>&1
1078     RET_COMPILE=$?
1079     echo >> $LOGFILE
1080     cat genmake_tla.log >> $LOGFILE
1081     if test "x$RET_COMPILE" = x0 ; then
1082     LIBS="$LIBS -llapack -lf77blas -lcblas"
1083     HAVE_LAPACK=t
1084     echo "check_lapack: successful" >> $LOGFILE
1085 jmc 1.236 else
1086     # try again with "-latlas" added to the libs
1087     echo "==> try again with added '-llapack -lf77blas -lcblas -latlas'" > genmake_tla.log
1088     echo "cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS \ " >> genmake_tla.log
1089     echo " && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS \ " >> genmake_tla.log
1090     echo " && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas" >> genmake_tla.log
1091     cat genmake_tla.F | $CPP $DEFINES $INCLUDES > genmake_tla.$FS 2>/dev/null \
1092     && $FC $FFLAGS $FOPTIM -c genmake_tla.$FS >> genmake_tla.log 2>&1 \
1093     && $LINK $FFLAGS $FOPTIM -o genmake_tla genmake_tla.o $LIBS -llapack -lf77blas -lcblas -latlas >> genmake_tla.log 2>&1
1094     RET_COMPILE=$?
1095     echo >> $LOGFILE
1096     cat genmake_tla.log >> $LOGFILE
1097     if test "x$RET_COMPILE" = x0 ; then
1098     LIBS="$LIBS -llapack -lf77blas -lcblas -latlas"
1099     HAVE_LAPACK=t
1100     echo "check_lapack: successful" >> $LOGFILE
1101     fi
1102 jahn 1.232 fi
1103     fi
1104     fi
1105     rm -f genmake_tla*
1106     echo " --> set HAVE_LAPACK='$HAVE_LAPACK'" >> $LOGFILE
1107     }
1108    
1109 jmc 1.244 check_HAVE_FLUSH() {
1110     if test ! "x$SKIP_CHECK_FLUSH" = x ; then
1111     return
1112     fi
1113     echo >> $LOGFILE
1114     echo "running: check_HAVE_FLUSH()" >> $LOGFILE
1115     cat <<EOF > genmake_tflsh.$FS
1116     program fgenflsh
1117     integer iounit
1118     character*9 fname
1119     iounit = 26
1120     fname = 'tmp.tflsh'
1121     open(iounit,FILE=fname,STATUS='unknown')
1122     write(iounit,*) 'genmake_tflsh: hello'
1123     call flush(iounit)
1124     close(iounit)
1125     end
1126     EOF
1127     echo "=== genmake_tflsh.$FS >>>" > genmake_tflsh.log
1128     cat genmake_tflsh.$FS >> genmake_tflsh.log
1129     echo "<<< genmake_tflsh.$FS ===" >> genmake_tflsh.log
1130    
1131     echo "$FC $FFLAGS $FOPTIM -c genmake_tflsh.$FS \ " >> genmake_tflsh.log
1132     echo " && $LINK $FFLAGS $FOPTIM -o genmake_tflsh.o $LIBS" >> genmake_tflsh.log
1133     $FC $FFLAGS $FOPTIM -c genmake_tflsh.$FS >> genmake_tflsh.log 2>&1 \
1134     && $LINK $FFLAGS $FOPTIM -o genmake_tflsh genmake_tflsh.o $LIBS >> genmake_tflsh.log 2>&1
1135     RET_COMPILE=$?
1136    
1137     if test "x$RET_COMPILE" = x0 ; then
1138     HAVE_FLUSH=t
1139     #cat genmake_tflsh.log >> $LOGFILE
1140     echo " check_HAVE_FLUSH: successful" >> $LOGFILE
1141     else
1142     HAVE_FLUSH=f
1143     cat genmake_tflsh.log >> $LOGFILE
1144     fi
1145     rm -f genmake_tflsh*
1146     echo " --> set HAVE_FLUSH='$HAVE_FLUSH'" >> $LOGFILE
1147     }
1148 edhill 1.60
1149 adcroft 1.67 ###############################################################################
1150     # Sequential part of script starts here
1151     ###############################################################################
1152    
1153 edhill 1.1 # Set defaults here
1154 edhill 1.5 COMMANDL="$0 $@"
1155    
1156 edhill 1.1 PLATFORM=
1157     LN=
1158     S64=
1159     KPP=
1160 edhill 1.114 #FC=
1161 edhill 1.93 #CC=gcc
1162 edhill 1.114 #CPP=
1163 edhill 1.1 LINK=
1164 edhill 1.31 DEFINES=
1165 edhill 1.1 PACKAGES=
1166     ENABLE=
1167     DISABLE=
1168 edhill 1.119 # MAKEFILE=
1169     # MAKEDEPEND=
1170 jmc 1.208 PKG_DEPEND=
1171     PKG_GROUPS=
1172 jmc 1.211 DUMPSTATE=f
1173 edhill 1.1 OPTFILE=
1174 edhill 1.111 INCLUDES="-I. $INCLUDES"
1175 edhill 1.1 FFLAGS=
1176     FOPTIM=
1177 mlosch 1.165 FEXTRAFLAGS=
1178 jmc 1.181 USE_EXTENDED_SRC=
1179     EXTENDED_SRC_FLAG=
1180 jmc 1.216 GET_FC_VERSION=
1181 edhill 1.1 CFLAGS=
1182     KFLAGS1=
1183     KFLAGS2=
1184 edhill 1.70 #LDADD=
1185 edhill 1.1 LIBS=
1186     KPPFILES=
1187     NOOPTFILES=
1188     NOOPTFLAGS=
1189 adcroft 1.67 MPI=
1190     MPIPATH=
1191 jmc 1.187 OMP=
1192     OMPFLAG=
1193 jmc 1.203 USE_R4=
1194 ce107 1.126 TS=
1195 ce107 1.139 PAPIS=
1196 ce107 1.147 PCLS=
1197 ce107 1.139 FOOLAD=
1198     PAPI=
1199 ce107 1.147 PCL=
1200 ce107 1.139 HPMT=
1201     GSL=
1202 ce107 1.160 DEVEL=
1203 edhill 1.131 HAVE_TEST_L=
1204 edhill 1.1
1205 jahn 1.246 # comment this line out to enable lapack test
1206     SKIP_LAPACK_CHECK=t
1207    
1208 edhill 1.124 # DEFINES checked by test compilation or command-line
1209 edhill 1.29 HAVE_SYSTEM=
1210     HAVE_FDATE=
1211     FC_NAMEMANGLE=
1212 edhill 1.39 HAVE_CLOC=
1213 edhill 1.151 # HAVE_SETRLSTK=
1214 edhill 1.108 HAVE_STAT=
1215 edhill 1.60 HAVE_NETCDF=
1216 cnh 1.81 HAVE_ETIME=
1217 edhill 1.124 IGNORE_TIME=
1218 jahn 1.232 HAVE_LAPACK=
1219 jmc 1.244 HAVE_FLUSH=
1220 edhill 1.29
1221 edhill 1.1 MODS=
1222     TOOLSDIR=
1223     SOURCEDIRS=
1224     INCLUDEDIRS=
1225 edhill 1.57 STANDARDDIRS="USE_THE_DEFAULT"
1226 edhill 1.1
1227 jmc 1.237 #- local config file
1228     gm_local="genmake_local"
1229    
1230 edhill 1.73 G2ARGS=
1231 edhill 1.71 BASH=
1232 edhill 1.1 PWD=`pwd`
1233 edhill 1.114 test "x$MAKE" = x && MAKE=make
1234     test "x$AWK" = x && AWK=awk
1235 edhill 1.141 EMBED_SRC=
1236 edhill 1.97 THISHOST=`hostname`
1237 edhill 1.1 THISCWD=`pwd`
1238     THISDATE=`date`
1239 edhill 1.97 THISUSER=`echo $USER`
1240     THISVER=
1241 edhill 1.1 MACHINE=`uname -a`
1242 edhill 1.7 EXECUTABLE=
1243     EXEHOOK=
1244     EXEDIR=
1245 edhill 1.12 IEEE=
1246     if test "x$MITGCM_IEEE" != x ; then
1247     IEEE=$MITGCM_IEEE
1248     fi
1249 edhill 1.76 FS=
1250     FS90=
1251 edhill 1.1
1252 edhill 1.14 AUTODIFF_PKG_USED=f
1253     AD_OPTFILE=
1254 edhill 1.17 TAF=
1255     AD_TAF_FLAGS=
1256     FTL_TAF_FLAGS=
1257     SVD_TAF_FLAGS=
1258     TAF_EXTRA=
1259     TAMC=
1260     AD_TAMC_FLAGS=
1261     FTL_TAF_FLAGS=
1262     SVD_TAMC_FLAGS=
1263     TAMC_EXTRA=
1264    
1265 edhill 1.5 # The following state can be set directly by command-line switches
1266 jmc 1.238 gm_s1="ROOTDIR STANDARDDIRS MODS PKG_DEPEND PKG_GROUPS DISABLE ENABLE"
1267     gm_s2="PLATFORM OPTFILE MAKE MAKEFILE MAKEDEPEND FC CC MPI OMP USE_R4"
1268     gm_s3="FEXTRAFLAGS IEEE DEVEL GSL TS PAPIS PCLS PAPI PCL HPMT DUMPSTATE"
1269 edhill 1.5
1270     # The following state is not directly set by command-line switches
1271 jmc 1.238 gm_s4="LN S64 LINK PACKAGES INCLUDES FFLAGS FOPTIM"
1272 jmc 1.222 gm_s5="CFLAGS LIBS KPP KFLAGS1 KFLAGS2 KPPFILES NOOPTFILES NOOPTFLAGS"
1273 jmc 1.244 gm_s6="PWD TOOLSDIR SOURCEDIRS INCLUDEDIRS EXEDIR EXECUTABLE EXEHOOK"
1274     gm_s7="THISHOST THISUSER THISDATE THISVER MACHINE FC_NAMEMANGLE"
1275     gm_s8="HAVE_NETCDF HAVE_SYSTEM HAVE_FDATE HAVE_ETIME HAVE_LAPACK HAVE_FLUSH"
1276 edhill 1.5
1277 edhill 1.14 # The following are all related to adjoint/tangent-linear stuff
1278 edhill 1.29 gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
1279     gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1280     gm_s12="TAF_EXTRA TAMC_EXTRA"
1281 edhill 1.14
1282 jmc 1.222 gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8"
1283 edhill 1.29 gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
1284 edhill 1.5
1285 edhill 1.41 cat <<EOF
1286    
1287     GENMAKE :
1288    
1289 jmc 1.211 A program for GENerating MAKEfiles for the MITgcm project.
1290     For a quick list of options, use "genmake2 -h"
1291     or for more detail see the Developer's HOWTO manual at:
1292     http://mitgcm.org/public/docs.html
1293 edhill 1.41
1294     EOF
1295 edhill 1.5
1296 jmc 1.211 LOGFILE="genmake.log"
1297 jmc 1.210 #- clean-up previous genmake logfiles:
1298 jmc 1.211 rm -f genmake_state genmake_*optfile $LOGFILE
1299 jmc 1.209
1300 edhill 1.2 echo "=== Processing options files and arguments ==="
1301 edhill 1.1
1302 edhill 1.103 #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
1303 edhill 1.2 #parse_options
1304     ac_prev=
1305 edhill 1.102 for ac_option in "$@" ; do
1306 edhill 1.2
1307 edhill 1.73 G2ARGS="$G2ARGS \"$ac_option\""
1308    
1309 edhill 1.2 # If the previous option needs an argument, assign it.
1310     if test -n "$ac_prev"; then
1311     eval "$ac_prev=\$ac_option"
1312     ac_prev=
1313     continue
1314     fi
1315 jmc 1.206
1316 edhill 1.2 ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
1317 jmc 1.206
1318 edhill 1.2 case $ac_option in
1319 jmc 1.236
1320 edhill 1.2 -help | --help | -h | --h)
1321     usage ;;
1322 jmc 1.236
1323 edhill 1.2 -nooptfile | --nooptfile)
1324     OPTFILE="NONE" ;;
1325     -optfile | --optfile | -of | --of)
1326 edhill 1.4 ac_prev=OPTFILE ;;
1327 edhill 1.2 -optfile=* | --optfile=* | -of=* | --of=*)
1328     OPTFILE=$ac_optarg ;;
1329 jmc 1.236
1330 edhill 1.50 -adoptfile | --adoptfile | -adof | --adof)
1331 edhill 1.14 ac_prev=AD_OPTFILE ;;
1332     -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
1333     AD_OPTFILE=$ac_optarg ;;
1334 jmc 1.236
1335 edhill 1.2 -pdepend | --pdepend)
1336 jmc 1.208 ac_prev=PKG_DEPEND ;;
1337 edhill 1.2 -pdepend=* | --pdepend=*)
1338 jmc 1.208 PKG_DEPEND=$ac_optarg ;;
1339 jmc 1.236
1340 jmc 1.208 -pgroups | --pgroups)
1341     ac_prev=PKG_GROUPS ;;
1342     -pgroups=* | --pgroups=*)
1343     PKG_GROUPS=$ac_optarg ;;
1344 jmc 1.236
1345 edhill 1.6 -make | --make | -m | --m)
1346     ac_prev=MAKE ;;
1347     -make=* | --make=* | -m=* | --m=*)
1348     MAKE=$ac_optarg ;;
1349 jmc 1.236
1350 edhill 1.71 -bash | --bash)
1351     ac_prev=BASH ;;
1352     -bash=* | --bash=*)
1353     BASH=$ac_optarg ;;
1354 jmc 1.236
1355 edhill 1.69 -makedepend | --makedepend | -md | --md)
1356     ac_prev=MAKEDEPEND ;;
1357     -makedepend=* | --makedepend=* | -md=* | --md=*)
1358     MAKEDEPEND=$ac_optarg ;;
1359 jmc 1.236
1360 jmc 1.237 -makefile | --makefile | -mf | --mf)
1361 edhill 1.4 ac_prev=MAKEFILE ;;
1362 jmc 1.237 -makefile=* | --makefile=* | -mf=* | --mf=*)
1363 edhill 1.2 MAKEFILE=$ac_optarg ;;
1364 jmc 1.236
1365 edhill 1.41 -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1366     echo "ERROR: The platform option has been removed. Please specify"
1367     echo " the build options using the \"optfile\" mechanism."
1368     echo
1369     usage
1370     ;;
1371 jmc 1.236
1372 edhill 1.2 -rootdir | --rootdir | -rd | --rd)
1373 edhill 1.4 ac_prev=ROOTDIR ;;
1374 edhill 1.2 -rootdir=* | --rootdir=* | -rd=* | --rd=*)
1375     ROOTDIR=$ac_optarg ;;
1376 jmc 1.236
1377 edhill 1.2 -mods | --mods | -mo | --mo)
1378 edhill 1.4 ac_prev=MODS ;;
1379 edhill 1.2 -mods=* | --mods=* | -mo=* | --mo=*)
1380     MODS=$ac_optarg ;;
1381 jmc 1.236
1382 edhill 1.2 -disable | --disable)
1383 edhill 1.4 ac_prev=DISABLE ;;
1384 edhill 1.2 -disable=* | --disable=*)
1385     DISABLE=$ac_optarg ;;
1386 jmc 1.236
1387 edhill 1.2 -enable | --enable)
1388 edhill 1.4 ac_prev=ENABLE ;;
1389 edhill 1.2 -enable=* | --enable=*)
1390     ENABLE=$ac_optarg ;;
1391 jmc 1.236
1392 edhill 1.12 -standarddirs | --standarddirs)
1393     ac_prev=STANDARDDIRS ;;
1394     -standarddirs=* | --standarddirs=*)
1395     STANDARDDIRS=$ac_optarg ;;
1396    
1397 edhill 1.2 # -cpp | --cpp)
1398     # ac_prev=cpp ;;
1399     # -cpp=* | --cpp=*)
1400     # CPP=$ac_optarg ;;
1401 jmc 1.236
1402 edhill 1.91 -cc | --cc)
1403     ac_prev=CC ;;
1404     -cc=* | --cc=*)
1405     CC=$ac_optarg ;;
1406 jmc 1.236
1407 edhill 1.2 -fortran | --fortran | -fc | --fc)
1408 edhill 1.4 ac_prev=FC ;;
1409 edhill 1.2 -fc=* | --fc=*)
1410     FC=$ac_optarg ;;
1411 jmc 1.236
1412 edhill 1.76 -fs | --fs)
1413     ac_prev=FS ;;
1414     -fs=* | --fs=*)
1415     FS=$ac_optarg ;;
1416 jmc 1.236
1417 edhill 1.76 -fs90 | --fs90)
1418     ac_prev=FS90 ;;
1419     -fs90=* | --fs90=*)
1420     FS90=$ac_optarg ;;
1421 jmc 1.236
1422 jmc 1.220 -use_real4 | -use_r4 | -ur4 | --use_real4 | --use_r4 | --ur4 )
1423     USE_R4=true ;;
1424    
1425 edhill 1.2 -ieee | --ieee)
1426 edhill 1.12 IEEE=true ;;
1427 edhill 1.2 -noieee | --noieee)
1428 jmc 1.220 echo "Warning: ignore option '$ac_option' (default is already without '-ieee')" ;;
1429 jmc 1.237 -devel | --devel)
1430 jmc 1.220 IEEE=true ; DEVEL=true ;;
1431 jmc 1.237 -gsl | --gsl)
1432 jmc 1.220 GSL=true ;;
1433 jmc 1.203
1434 ce107 1.126 -ts | --ts)
1435     TS=true ;;
1436 ce107 1.139 -papis | --papis)
1437     PAPIS=true ;;
1438 ce107 1.147 -pcls | --pcls)
1439     PCLS=true ;;
1440 ce107 1.139 -foolad | --foolad)
1441     FOOLAD=true ;;
1442     -papi | --papi)
1443     PAPI=true ;;
1444 ce107 1.147 -pcl | --pcl)
1445     PCL=true ;;
1446 ce107 1.139 -hpmt | --hpmt)
1447     HPMT=true ;;
1448    
1449 adcroft 1.67 -mpi | --mpi)
1450     MPI=true ;;
1451     -mpi=* | --mpi=*)
1452     MPIPATH=$ac_optarg
1453     MPI=true ;;
1454 jmc 1.236
1455     -omp | --omp)
1456     OMP=true ;;
1457 jmc 1.187 -omp=* | --omp=*)
1458     OMPFLAG=$ac_optarg
1459     OMP=true ;;
1460 jmc 1.236
1461 edhill 1.5 -ds | --ds)
1462     DUMPSTATE=t ;;
1463 jmc 1.236
1464 jmc 1.222 -extra_flag | --extra_flag)
1465     ac_prev=FEXTRAFLAGS ;;
1466     -extra_flag=* | --extra_flag=*)
1467     FEXTRAFLAGS=$ac_optarg ;;
1468 jmc 1.236
1469 edhill 1.17 -taf_extra | --taf_extra)
1470     ac_prev=TAF_EXTRA ;;
1471     -taf_extra=* | --taf_extra=*)
1472     TAF_EXTRA=$ac_optarg ;;
1473    
1474     -tamc_extra | --tamc_extra)
1475     ac_prev=TAMC_EXTRA ;;
1476     -tamc_extra=* | --tamc_extra=*)
1477     TAMC_EXTRA=$ac_optarg ;;
1478 jmc 1.236
1479 edhill 1.124 -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1480     IGNORE_TIME="-DIGNORE_TIME" ;;
1481 edhill 1.17
1482 edhill 1.141 -es | --es | -embed-source | --embed-source)
1483     EMBED_SRC=t ;;
1484    
1485 edhill 1.2 -*)
1486     echo "Error: unrecognized option: "$ac_option
1487     usage
1488     ;;
1489 jmc 1.236
1490 edhill 1.2 *)
1491     echo "Error: unrecognized argument: "$ac_option
1492     usage
1493     ;;
1494 jmc 1.236
1495 edhill 1.2 esac
1496 jmc 1.206
1497 edhill 1.1 done
1498    
1499 jmc 1.237 printf " getting local config information: "
1500     if test -f $gm_local ; then
1501     echo "using $gm_local"
1502     . $gm_local
1503     else
1504     echo "none found"
1505     fi
1506    
1507 edhill 1.12 if test -f ./.genmakerc ; then
1508     echo
1509     echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
1510 jmc 1.161 echo " file. This file format is no longer supported. For directions on"
1511     echo " how to setup and use the new \"genmake2\" script, please see:"
1512 jmc 1.220 echo " http://mitgcm.org/public/devel_HOWTO/"
1513 jmc 1.161 echo " and send an email to MITgcm-support@mitgcm.org if you need help."
1514     echo "WARNING: ignore \"./.genmakerc\" and continue."
1515 jmc 1.206 echo
1516 edhill 1.12 fi
1517    
1518 edhill 1.97 # Find the MITgcm ${ROOTDIR}
1519 edhill 1.11 if test "x${ROOTDIR}" = x ; then
1520 edhill 1.112 tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1521 edhill 1.154 if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesupp -a -d ../pkg ; then
1522 edhill 1.11 ROOTDIR=".."
1523     else
1524     for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1525     if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
1526     ROOTDIR=$d
1527 jmc 1.218 printf "Warning: ROOTDIR was not specified ;"
1528     echo " try using a local copy of MITgcm found at \"$ROOTDIR\""
1529 edhill 1.11 break
1530     fi
1531     done
1532     fi
1533     fi
1534     if test "x${ROOTDIR}" = x ; then
1535     echo "Error: Cannot determine ROOTDIR for MITgcm code."
1536     echo " Please specify a ROOTDIR using either an options "
1537     echo " file or a command-line option."
1538     exit 1
1539     fi
1540     if test ! -d ${ROOTDIR} ; then
1541     echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
1542     exit 1
1543     fi
1544    
1545 edhill 1.97 # Find the MITgcm ${THISVER}
1546 jmc 1.179 version_file="${ROOTDIR}/doc/tag-index"
1547     if test -f $version_file ; then
1548 jmc 1.200 THISVER=`$AWK '/^checkpoint/{print $1; exit}' $version_file`
1549 jmc 1.179 #- remove ./BUILD_INFO.h file if older than version_file
1550     if test -f ./BUILD_INFO.h -a ./BUILD_INFO.h -ot $version_file ; then
1551     echo " remove ./BUILD_INFO.h (older than ${version_file})"
1552     rm -f ./BUILD_INFO.h
1553     fi
1554 edhill 1.97 fi
1555    
1556 edhill 1.119 if test "x$MAKEFILE" = x ; then
1557     MAKEFILE="Makefile"
1558     fi
1559    
1560 jmc 1.222 echo " getting OPTFILE information:"
1561 edhill 1.1 if test "x${OPTFILE}" = x ; then
1562 edhill 1.11 if test "x$MITGCM_OF" = x ; then
1563     echo "Warning: no OPTFILE specified so we'll look for possible settings"
1564     printf "\n=== Searching for possible settings for OPTFILE ===\n"
1565 jmc 1.212 find_possible_optfile
1566 edhill 1.1 else
1567 edhill 1.11 OPTFILE=$MITGCM_OF
1568     fi
1569     fi
1570     if test "x$OPTFILE" != xNONE ; then
1571     if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
1572     echo " using OPTFILE=\"$OPTFILE\""
1573 edhill 1.34 . "$OPTFILE"
1574 edhill 1.11 RETVAL=$?
1575     if test "x$RETVAL" != x0 ; then
1576 edhill 1.71 printf "Error: failed to source OPTFILE \"$OPTFILE\""
1577 edhill 1.11 echo "--please check that variable syntax is bash-compatible"
1578 edhill 1.1 exit 1
1579     fi
1580 jmc 1.211 if test "x$DUMPSTATE" = xt ; then
1581 edhill 1.12 cp -f $OPTFILE "genmake_optfile"
1582 edhill 1.11 fi
1583     else
1584     echo "Error: can't read OPTFILE=\"$OPTFILE\""
1585     exit 1
1586 edhill 1.1 fi
1587     fi
1588 edhill 1.8
1589 jmc 1.222 echo " getting AD_OPTFILE information:"
1590 edhill 1.14 if test "x${AD_OPTFILE}" = x ; then
1591     if test "x$MITGCM_AD_OF" = x ; then
1592     AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
1593     else
1594     AD_OPTFILE=$MITGCM_AD_OF
1595     fi
1596     fi
1597     if test "x${AD_OPTFILE}" != xNONE ; then
1598     if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
1599     echo " using AD_OPTFILE=\"$AD_OPTFILE\""
1600 edhill 1.34 . "$AD_OPTFILE"
1601 edhill 1.14 RETVAL=$?
1602     if test "x$RETVAL" != x0 ; then
1603 edhill 1.71 printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1604 edhill 1.14 echo "--please check that variable syntax is bash-compatible"
1605     exit 1
1606     fi
1607 jmc 1.211 if test "x$DUMPSTATE" = xt ; then
1608 edhill 1.14 cp -f $AD_OPTFILE "genmake_ad_optfile"
1609     fi
1610     else
1611     echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
1612     exit 1
1613     fi
1614     fi
1615    
1616 edhill 1.119 #====================================================================
1617     # Set default values if not set by the optfile
1618     #
1619 edhill 1.91 # Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined. If not,
1620 edhill 1.39 # either set defaults or complain and abort!
1621 edhill 1.71 if test ! "x$BASH" = x ; then
1622     # add a trailing space so that it works within the Makefile syntax (see below)
1623     BASH="$BASH "
1624     fi
1625 edhill 1.8 if test "x$FC" = x ; then
1626     cat <<EOF 1>&2
1627    
1628     Error: no Fortran compiler: please specify using one of the following:
1629     1) within the options file ("FC=...") as specified by "-of=OPTFILE"
1630     2) the "-fc=XXX" command-line option
1631 edhill 1.12 3) the "./genmake_local" file
1632 edhill 1.8 EOF
1633     exit 1
1634     fi
1635 jmc 1.216 if test "x$GET_FC_VERSION" != x ; then
1636     echo "Get compiler version using: $FC $GET_FC_VERSION" >> $LOGFILE
1637 jmc 1.225 ff=`echo $FC | sed 's/ .*//'` ; xx=`echo $ff | sed 's/^./& /' | sed 's/ .*//'`
1638     if test $xx != '/' ; then which $ff >> $LOGFILE ; fi
1639 jmc 1.224 $FC $GET_FC_VERSION > genmake_fc_vers1 2> genmake_fc_vers2
1640     if test -s genmake_fc_vers1 ; then
1641     cat genmake_fc_vers1 >> $LOGFILE
1642     else
1643     cat genmake_fc_vers2 >> $LOGFILE
1644     fi
1645 jmc 1.217 echo "<-- compiler version ----" >> $LOGFILE
1646 jmc 1.224 rm -f genmake_fc_vers1 genmake_fc_vers2
1647 jmc 1.216 fi
1648 jmc 1.212
1649 edhill 1.91 if test "x$CC" = x ; then
1650 jmc 1.212 look_for_C_compilers
1651 edhill 1.91 fi
1652 jmc 1.212
1653 edhill 1.8 if test "x$LINK" = x ; then
1654     LINK=$FC
1655     fi
1656 edhill 1.39 if test "x$MAKE" = x ; then
1657     MAKE="make"
1658     fi
1659 edhill 1.63 if test "x$CPP" = x ; then
1660 jmc 1.212 CPP="cpp -traditional -P"
1661 edhill 1.63 fi
1662     #EH3 === UGLY ===
1663 edhill 1.76 # The following is an ugly little hack to check for $CPP in /lib/ and
1664     # it should eventually be replaced with a more general function that
1665 edhill 1.63 # searches a combo of the user's path and a list of "usual suspects"
1666     # to find the correct location for binaries such as $CPP.
1667     for i in " " "/lib/" ; do
1668     echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1669     done
1670     #EH3 === UGLY ===
1671 edhill 1.13 echo "#define A a" | $CPP > test_cpp 2>&1
1672 edhill 1.11 RETVAL=$?
1673     if test "x$RETVAL" != x0 ; then
1674 edhill 1.8 cat <<EOF 1>&2
1675    
1676 edhill 1.11 Error: C pre-processor "$CPP" failed the test case: please specify using:
1677    
1678 edhill 1.8 1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1679 edhill 1.12 2) the "./genmake_local" file
1680 edhill 1.30 3) with the CPP environment variable
1681 edhill 1.11
1682 edhill 1.8 EOF
1683     exit 1
1684 edhill 1.11 else
1685     rm -f test_cpp
1686 edhill 1.8 fi
1687 jmc 1.212
1688 edhill 1.84 look_for_makedepend
1689 jmc 1.212
1690     # Check that soft-link command is set and usable
1691 edhill 1.35 if test "x$LN" = x ; then
1692     LN="ln -s"
1693     fi
1694     echo "test" > genmake_test_ln
1695     $LN genmake_test_ln genmake_tlink
1696     RETVAL=$?
1697     if test "x$RETVAL" != x0 ; then
1698     cat <<EOF 1>&2
1699 edhill 1.29
1700 jmc 1.212 Error: The command "$LN" failed -- please specify a working soft-link
1701 edhill 1.35 command in the optfile.
1702    
1703     EOF
1704     exit 1
1705     fi
1706 edhill 1.131 test -L genmake_tlink > /dev/null 2>&1
1707     RETVAL=$?
1708     if test "x$RETVAL" = x0 ; then
1709     HAVE_TEST_L=t
1710     fi
1711 edhill 1.35 rm -f genmake_test_ln genmake_tlink
1712 edhill 1.77
1713     # Check for broken *.F/*.f handling and fix if possible
1714     check_for_broken_Ff
1715 edhill 1.29
1716 adcroft 1.67 if test ! "x$MPI" = x ; then
1717     echo " Turning on MPI cpp macros"
1718 jmc 1.239 DEFINES="$DEFINES -DALLOW_USE_MPI"
1719 jmc 1.248 #- To compile code older than checkpoint63s (2012/09/05), un-comment the following line:
1720     # DEFINES="$DEFINES -DALWAYS_USE_MPI"
1721 adcroft 1.67 fi
1722 jmc 1.187 if test ! "x$OMP" = x ; then
1723     echo " Add OMPFLAG and turn on OpenMP cpp macros"
1724     FFLAGS="$FFLAGS $OMPFLAG"
1725     F90FLAGS="$F90FLAGS $OMPFLAG"
1726     DEFINES="$DEFINES -DUSE_OMP_THREADING"
1727     fi
1728 edhill 1.39
1729 jmc 1.203 if test ! "x$USE_R4" = x ; then
1730     echo " Turning on LET_RS_BE_REAL4 cpp flag"
1731     DEFINES="$DEFINES -DLET_RS_BE_REAL4"
1732     fi
1733    
1734 ce107 1.126 if test ! "x$TS" = x ; then
1735     echo " Turning on timing per timestep"
1736 ce107 1.139 if test ! "x$FOOLAD" = x ; then
1737 jmc 1.236 DEFINES="$DEFINES -DTIME_PER_TIMESTEP_SFP"
1738 ce107 1.139 else
1739     DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1740     fi
1741 ce107 1.164 PACKAGES="$PACKAGES showflops"
1742 ce107 1.139 fi
1743     if test ! "x$PAPIS" = x ; then
1744     echo " Turning on PAPI flop summary per timestep"
1745     echo " Please make sure PAPIINC, PAPILIB are defined"
1746     if test ! "x$FOOLAD" = x ; then
1747     DEFINES="$DEFINES -DUSE_PAPI_FLOPS_SFP"
1748     else
1749     DEFINES="$DEFINES -DUSE_PAPI_FLOPS"
1750     fi
1751     INCLUDES="$INCLUDES $PAPIINC"
1752     LIBS="$LIBS $PAPILIB"
1753 ce107 1.164 PACKAGES="$PACKAGES showflops"
1754 ce107 1.139 fi
1755 ce107 1.147 if test ! "x$PCLS" = x ; then
1756     echo " Turning on PCL counter summary per timestep"
1757     echo " Please make sure PCLINC, PCLLIB are defined"
1758     if test ! "x$FOOLAD" = x ; then
1759     DEFINES="$DEFINES -DUSE_PCL_FLOPS_SFP"
1760     else
1761     DEFINES="$DEFINES -DUSE_PCL_FLOPS"
1762     fi
1763     INCLUDES="$INCLUDES $PCLINC"
1764     LIBS="$LIBS $PCLLIB"
1765 ce107 1.164 PACKAGES="$PACKAGES showflops"
1766 ce107 1.147 fi
1767 ce107 1.139 if test ! "x$PAPI" = x ; then
1768     if test ! "x$PAPIS" = x ; then
1769     echo " PAPI performance analysis and flop summary per timestep cannot co-exist!"
1770     echo " Sticking with PAPI flop summary per timestep!"
1771     else
1772     echo " Turning on performance analysis with PAPI"
1773 jmc 1.236 echo " Please make sure PAPIINC, PAPILIB are defined"
1774 ce107 1.139 DEFINES="$DEFINES -DUSE_PAPI"
1775     INCLUDES="$INCLUDES $PAPIINC"
1776     LIBS="$LIBS $PAPILIB"
1777     fi
1778     fi
1779 ce107 1.147 if test ! "x$PCL" = x ; then
1780     if test ! "x$PCLS" = x ; then
1781     echo " PCL performance analysis and flop summary per timestep cannot co-exist!"
1782     echo " Sticking with PCL flop summary per timestep!"
1783     else
1784     echo " Turning on performance analysis with PCL"
1785 jmc 1.236 echo " Please make sure PCLINC, PCLLIB are defined"
1786 ce107 1.147 DEFINES="$DEFINES -DUSE_PCL"
1787     INCLUDES="$INCLUDES $PCLINC"
1788     LIBS="$LIBS $PCLLIB"
1789     fi
1790     fi
1791 ce107 1.139 if test ! "x$HPMT" = x ; then
1792     if test ! "x$PAPI" = x ; then
1793     echo " PAPI and the HPM Toolkit cannot co-exist!"
1794     echo " Sticking with PAPI!"
1795 jmc 1.237 else
1796     if test ! "x$PCL" = x ; then
1797 ce107 1.147 echo " PCL and the HPM Toolkit cannot co-exist!"
1798     echo " Sticking with PCL!"
1799 jmc 1.237 else
1800 ce107 1.139 echo " Turning on performance analysis with the HPM Toolkit"
1801 jmc 1.236 echo " Please make sure HPMTINC, HPMTLIB are defined"
1802 ce107 1.139 DEFINES="$DEFINES -DUSE_LIBHPM"
1803 jmc 1.236 INCLUDES="$INCLUDES $HPMTINC"
1804 ce107 1.139 LIBS="$LIBS $HPMTLIB"
1805 jmc 1.237 fi
1806 ce107 1.148 fi
1807 ce107 1.139 fi
1808     if test ! "x$GSL" = x ; then
1809     echo " Turning on use of GSL to control floating point calculations"
1810     echo " Please make sure GSLINC, GSLLIB are defined"
1811     DEFINES="$DEFINES -DUSE_GSL_IEEE"
1812     INCLUDES="$INCLUDES $GSLINC"
1813     LIBS="$LIBS $GSLLIB"
1814 ce107 1.126 fi
1815 jmc 1.181 #- if USE_EXTENDED_SRC is set, add EXTENDED_SRC_FLAG to FFLAGS :
1816     if test ! "x$USE_EXTENDED_SRC" = x ; then
1817     FFLAGS="$FFLAGS $EXTENDED_SRC_FLAG"
1818     F90FIXEDFORMAT="$F90FIXEDFORMAT $EXTENDED_SRC_FLAG"
1819     fi
1820 ce107 1.126
1821 edhill 1.29 printf "\n=== Checking system libraries ===\n"
1822 edhill 1.71 printf " Do we have the system() command using $FC... "
1823 edhill 1.118 cat > genmake_tcomp.$FS <<EOF
1824 edhill 1.29 program hello
1825     call system('echo hi')
1826     end
1827     EOF
1828 edhill 1.134 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1829 edhill 1.29 RETVAL=$?
1830     if test "x$RETVAL" = x0 ; then
1831     HAVE_SYSTEM=t
1832     DEFINES="$DEFINES -DHAVE_SYSTEM"
1833     echo "yes"
1834     else
1835     HAVE_SYSTEM=
1836     echo "no"
1837     fi
1838     rm -f genmake_tcomp*
1839    
1840 edhill 1.71 printf " Do we have the fdate() command using $FC... "
1841 edhill 1.118 cat > genmake_tcomp.$FS <<EOF
1842 edhill 1.29 program hello
1843 edhill 1.129 CHARACTER*(128) string
1844 edhill 1.29 string = ' '
1845     call fdate( string )
1846     print *, string
1847     end
1848     EOF
1849 edhill 1.134 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1850 edhill 1.29 RETVAL=$?
1851     if test "x$RETVAL" = x0 ; then
1852     HAVE_FDATE=t
1853     DEFINES="$DEFINES -DHAVE_FDATE"
1854     echo "yes"
1855     else
1856     HAVE_FDATE=
1857     echo "no"
1858     fi
1859     rm -f genmake_tcomp*
1860    
1861 cnh 1.81 printf " Do we have the etime() command using $FC... "
1862 edhill 1.118 cat > genmake_tcomp.$FS <<EOF
1863 cnh 1.81 program hello
1864 cnh 1.82 REAL*4 ACTUAL, TARRAY(2)
1865     EXTERNAL ETIME
1866     REAL*4 ETIME
1867     actual = etime( tarray )
1868 cnh 1.81 print *, tarray
1869     end
1870     EOF
1871 edhill 1.134 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1872 cnh 1.81 RETVAL=$?
1873     if test "x$RETVAL" = x0 ; then
1874     HAVE_ETIME=t
1875     DEFINES="$DEFINES -DHAVE_ETIME"
1876     echo "yes"
1877     else
1878     HAVE_ETIME=
1879     echo "no"
1880     fi
1881     rm -f genmake_tcomp*
1882    
1883 edhill 1.71 printf " Can we call simple C routines (here, \"cloc()\") using $FC... "
1884 edhill 1.39 check_HAVE_CLOC
1885     if test "x$HAVE_CLOC" != x ; then
1886 jmc 1.230 DEFINES="$DEFINES -DHAVE_CLOC"
1887 edhill 1.39 echo "yes"
1888     else
1889     echo "no"
1890 edhill 1.141 if test "x$EMBED_SRC" = xt ; then
1891     echo " WARNING: you requested file embedding but it has"
1892     echo " been disabled since C code cannot be called"
1893     EMBED_SRC=
1894     fi
1895 edhill 1.29 fi
1896 edhill 1.39 rm -f genmake_t*
1897 edhill 1.29
1898 edhill 1.130 printf " Can we unlimit the stack size using $FC... "
1899     check_HAVE_SETRLSTK
1900 edhill 1.151 if test "x$HAVE_SETRLSTK" = xt ; then
1901 jmc 1.230 DEFINES="$DEFINES -DHAVE_SETRLSTK"
1902 edhill 1.130 echo "yes"
1903     else
1904     echo "no"
1905     fi
1906     rm -f genmake_t*
1907    
1908 edhill 1.137 printf " Can we register a signal handler using $FC... "
1909     check_HAVE_SIGREG
1910 edhill 1.150 if test "x$HAVE_SIGREG" = xt ; then
1911 jmc 1.230 DEFINES="$DEFINES -DHAVE_SIGREG"
1912 edhill 1.137 echo "yes"
1913     else
1914     echo "no"
1915     fi
1916     rm -f genmake_t*
1917    
1918 edhill 1.108 printf " Can we use stat() through C calls... "
1919     check_HAVE_STAT
1920     if test "x$HAVE_STAT" != x ; then
1921 jmc 1.230 DEFINES="$DEFINES -DHAVE_STAT"
1922 edhill 1.108 echo "yes"
1923     else
1924     echo "no"
1925     fi
1926     rm -f genmake_t*
1927    
1928 edhill 1.71 printf " Can we create NetCDF-enabled binaries... "
1929 edhill 1.60 check_netcdf_libs
1930     if test "x$HAVE_NETCDF" != x ; then
1931 jmc 1.230 DEFINES="$DEFINES -DHAVE_NETCDF"
1932 edhill 1.60 echo "yes"
1933     else
1934     echo "no"
1935     fi
1936 jahn 1.232
1937     printf " Can we create LAPACK-enabled binaries... "
1938     check_lapack_libs
1939     if test "x$HAVE_LAPACK" != x ; then
1940     DEFINES="$DEFINES -DHAVE_LAPACK"
1941     echo "yes"
1942     else
1943     echo "no"
1944     fi
1945 jmc 1.244
1946     printf " Can we call FLUSH intrinsic subroutine... "
1947     check_HAVE_FLUSH
1948     if test "x$HAVE_FLUSH" = xt ; then
1949     DEFINES="$DEFINES -DHAVE_FLUSH"
1950     echo "yes"
1951     else
1952     echo "no"
1953     fi
1954    
1955 edhill 1.124 DEFINES="$DEFINES $IGNORE_TIME"
1956 edhill 1.141 if test "x$EMBED_SRC" = xt ; then
1957     build_embed_encode
1958     fi
1959     if test "x$EMBED_SRC" = xt ; then
1960     ENABLE="$ENABLE embed_files"
1961 jmc 1.230 # DEFINES="$DEFINES -DHAVE_EMBED_SRC"
1962 edhill 1.141 fi
1963    
1964 edhill 1.2 printf "\n=== Setting defaults ===\n"
1965 jmc 1.185 printf " Adding MODS directories: "
1966 edhill 1.1 for d in $MODS ; do
1967     if test ! -d $d ; then
1968 edhill 1.2 echo
1969     echo "Error: MODS directory \"$d\" not found!"
1970 edhill 1.1 exit 1
1971     else
1972 jmc 1.185 printf "$d "
1973 edhill 1.1 SOURCEDIRS="$SOURCEDIRS $d"
1974     INCLUDEDIRS="$INCLUDEDIRS $d"
1975     fi
1976     done
1977     echo
1978    
1979 jmc 1.212 #if test "x${PLATFORM}" = x ; then
1980     # PLATFORM=$p_PLATFORM
1981     #fi
1982 edhill 1.1
1983     if test "x${EXEDIR}" = x ; then
1984 edhill 1.112 tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1985 edhill 1.87 if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
1986 edhill 1.1 EXEDIR=../exe
1987     else
1988     EXEDIR=.
1989     fi
1990     fi
1991     if test ! -d ${EXEDIR} ; then
1992     echo "Error: the specified EXEDIR (\"$EXEDIR\") does not exist!"
1993     exit 1
1994     fi
1995    
1996     if test "x${TOOLSDIR}" = x ; then
1997     TOOLSDIR="$ROOTDIR/tools"
1998     fi
1999     if test ! -d ${TOOLSDIR} ; then
2000 cnh 1.65 echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
2001 edhill 1.1 exit 1
2002     fi
2003 edhill 1.11 if test "x$S64" = x ; then
2004 edhill 1.104 echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
2005     RETVAL=$?
2006     if test "x${RETVAL}" = x0 ; then
2007     S64='$(TOOLSDIR)/set64bitConst.sh'
2008     else
2009     echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
2010     RETVAL=$?
2011     if test "x${RETVAL}" = x0 ; then
2012     S64='$(TOOLSDIR)/set64bitConst.csh'
2013     else
2014     cat <<EOF
2015    
2016     ERROR: neither of the two default scripts:
2017    
2018     ${TOOLSDIR}/set64bitConst.sh
2019     ${TOOLSDIR}/set64bitConst.csh
2020    
2021 jmc 1.206 are working so please check paths or specify (with \$S64) a
2022 edhill 1.104 working version of this script.
2023    
2024     EOF
2025     exit 1
2026     fi
2027     fi
2028 edhill 1.11 fi
2029 adcroft 1.44 THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
2030 edhill 1.1
2031     EXECUTABLE=${EXECUTABLE:-mitgcmuv}
2032    
2033 jmc 1.205 # Set Standard Code Directories:
2034     if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
2035     STANDARDDIRS="eesupp model"
2036     fi
2037     # if model in Standard-Code-Dir, add eesupp (needed to compile model)
2038     echo " $STANDARDDIRS " | grep ' model ' > /dev/null 2>&1
2039     ckM=$?
2040     echo " $STANDARDDIRS " | grep ' eesupp ' > /dev/null 2>&1
2041     ckE=$?
2042 jmc 1.206 if test $ckM = 0 -a $ckE = 1 ; then
2043 jmc 1.205 STANDARDDIRS="$STANDARDDIRS eesupp"
2044     fi
2045    
2046 edhill 1.1 # We have a special set of source files in eesupp/src which are
2047     # generated from some template source files. We'll make them first so
2048     # they appear as regular source code
2049     if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
2050     echo " Making source files in eesupp from templates"
2051 jmc 1.207 ( cd $ROOTDIR"/eesupp/src/" && $MAKE clean_old && $MAKE \
2052     ) > make_eesupp.errors 2>&1
2053 edhill 1.1 RETVAL=$?
2054 edhill 1.2 if test "x${RETVAL}" = x0 ; then
2055 edhill 1.1 rm -f make_eesupp.errors
2056     else
2057     echo "Error: problem encountered while building source files in eesupp:"
2058 edhill 1.62 cat make_eesupp.errors 1>&2
2059 edhill 1.1 exit 1
2060 afe 1.58 fi
2061     fi
2062    
2063 edhill 1.154 #same for pkg/exch2 and pkg/regrid
2064     for pdir in exch2 regrid ; do
2065     if test -r $ROOTDIR"/pkg/${pdir}/Makefile" ; then
2066     echo " Making source files in pkg/${pdir} from templates"
2067 jmc 1.207 ( cd $ROOTDIR"/pkg/"${pdir} && $MAKE clean_old && $MAKE \
2068     ) > make_${pdir}.errors 2>&1
2069 edhill 1.154 RETVAL=$?
2070     if test "x${RETVAL}" = x0 ; then
2071     rm -f make_${pdir}.errors
2072     else
2073     echo "Error: problem encountered while building source files in pkg/${pdir}:"
2074     cat make_${pdir}.errors 1>&2
2075     exit 1
2076     fi
2077 edhill 1.1 fi
2078 edhill 1.154 done
2079 edhill 1.1
2080 edhill 1.2 printf "\n=== Determining package settings ===\n"
2081 jmc 1.208 if test "x${PKG_DEPEND}" = x ; then
2082 edhill 1.1 tmp=$ROOTDIR"/pkg/pkg_depend"
2083 jmc 1.208 if test -r $tmp ; then PKG_DEPEND=$tmp ; fi
2084     fi
2085     if test "x${PKG_DEPEND}" = x ; then
2086 edhill 1.1 echo "Warning: No package dependency information was specified."
2087     echo " Please check that ROOTDIR/pkg/pkg_depend exists."
2088 jmc 1.208 else
2089     if test ! -r ${PKG_DEPEND} ; then
2090     echo "Error: can't read package dependency info from PKG_DEPEND=\"$PKG_DEPEND\""
2091     exit 1
2092 edhill 1.1 fi
2093 jmc 1.208 echo " getting package dependency info from $PKG_DEPEND"
2094     # Strip the comments and then convert the dependency file into arrays: PNAME, DNAME
2095     get_pdepend_list $PKG_DEPEND
2096     fi
2097    
2098     # A default package groups file "$ROOTDIR/pkg/pkg_groups" is provided
2099     # to define the "default_pkg_list" and package groups (for convenience, one
2100     # can specify a group of packages using names like "ocean" and "atmosphere").
2101     if test "x${PKG_GROUPS}" = x ; then
2102     tmp=$ROOTDIR"/pkg/pkg_groups"
2103     if test -r $tmp ; then PKG_GROUPS=$tmp ; fi
2104     fi
2105     if test "x${PKG_GROUPS}" = x ; then
2106     echo "Warning: No package groups information was specified."
2107     echo " Please check that ROOTDIR/pkg/pkg_groups exists."
2108 edhill 1.1 else
2109 jmc 1.208 if test ! -r ${PKG_GROUPS} ; then
2110     echo "Error: can't read package groups info from PKG_GROUPS=\"$PKG_GROUPS\""
2111 edhill 1.1 exit 1
2112     fi
2113 jmc 1.208 echo " getting package groups info from $PKG_GROUPS"
2114 edhill 1.1 fi
2115 jmc 1.208
2116     # Search for packages to compile.
2117     echo " checking list of packages to compile:"
2118     PKG_LIST=
2119     if test "x${PKG_LIST}" = x ; then
2120 edhill 1.12 for i in "." $MODS ; do
2121     if test -r $i"/packages.conf" ; then
2122 jmc 1.208 PKG_LIST=$i"/packages.conf"
2123 edhill 1.12 break
2124     fi
2125     done
2126     fi
2127 jmc 1.208 if test "x${PKG_LIST}" = x ; then
2128     pkg_list='default_pkg_list'
2129     if test "x${PKG_GROUPS}" = x ; then
2130     echo "Error: need package groups info to expand pkg_list=\"$pkg_list\""
2131     exit 1
2132     fi
2133 edhill 1.1 else
2134 jmc 1.208 if test ! -r $PKG_LIST ; then
2135     echo "Error: can't read package list from PKG_LIST=\"$PKG_LIST\""
2136     exit 1
2137 edhill 1.1 else
2138 jmc 1.208 echo " using PKG_LIST=\"$PKG_LIST\""
2139 jmc 1.237 # Strip the comments and add all the names
2140 jmc 1.208 pkg_list=`cat $PKG_LIST | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
2141 edhill 1.1 RETVAL=$?
2142     if test "x${RETVAL}" != x0 ; then
2143 jmc 1.208 printf "Error: can't parse package list "
2144     echo "-- please check PKG_LIST=\"$PKG_LIST\""
2145 edhill 1.1 exit 1
2146     fi
2147     fi
2148     fi
2149 jmc 1.208 for i in $pkg_list ; do
2150     PACKAGES="$PACKAGES $i"
2151     done
2152     echo " before group expansion packages are:$PACKAGES"
2153     if test "x${PKG_GROUPS}" != x ; then
2154     RET=1
2155     while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
2156     echo " after group expansion packages are: $PACKAGES"
2157     fi
2158 edhill 1.1
2159     echo " applying DISABLE settings"
2160 jmc 1.205 echo "" > ./.tmp_pack
2161 adcroft 1.74 for i in $PACKAGES ; do
2162     echo $i >> ./.tmp_pack
2163     done
2164     for i in `grep "-" ./.tmp_pack` ; do
2165     j=`echo $i | sed 's/[-]//'`
2166     DISABLE="$DISABLE $j"
2167     done
2168 edhill 1.1 pack=
2169     for p in $PACKAGES ; do
2170     addit="t"
2171     for d in $DISABLE ; do
2172     if test "x$p" = "x$d" ; then
2173     addit="f"
2174     fi
2175     done
2176     if test "x$addit" = xt ; then
2177     pack="$pack $p"
2178     fi
2179     done
2180     PACKAGES="$pack"
2181     echo " applying ENABLE settings"
2182 edhill 1.12 echo "" > ./.tmp_pack
2183 edhill 1.1 PACKAGES="$PACKAGES $ENABLE"
2184 adcroft 1.74 # Test if each explicitly referenced package exists
2185 edhill 1.1 for i in $PACKAGES ; do
2186 adcroft 1.74 j=`echo $i | sed 's/[-+]//'`
2187     if test ! -d "$ROOTDIR/pkg/$j" ; then
2188 jmc 1.208 echo "Error: dir '$ROOTDIR/pkg/$i' missing for package '$i'"
2189 jmc 1.236 exit 1
2190 edhill 1.1 fi
2191     echo $i >> ./.tmp_pack
2192     done
2193     PACKAGES=
2194 adcroft 1.74 for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
2195 edhill 1.1 PACKAGES="$PACKAGES $i"
2196     done
2197 adcroft 1.74 rm -f ./.tmp_pack
2198 jmc 1.205 echo " packages are: $PACKAGES"
2199 edhill 1.1
2200 jmc 1.206 # Check for package MNC: if NetCDF is available, then build the MNC
2201 jmc 1.161 # template files ; otherwise, delete mnc from the list of packages.
2202 jmc 1.205 echo " $PACKAGES " | grep ' mnc ' > /dev/null 2>&1
2203 jmc 1.206 mnc_in=$?
2204     if test "x$HAVE_NETCDF" != xt ; then
2205     if test "x$mnc_in" = x0 ; then
2206 edhill 1.100 cat <<EOF
2207     *********************************************************************
2208     WARNING: the "mnc" package was enabled but tests failed to compile
2209     NetCDF applications. Please check that:
2210    
2211     1) NetCDF is correctly installed for this compiler and
2212 jmc 1.206 2) the LIBS variable (within the "optfile") specifies the correct
2213 edhill 1.100 NetCDF library to link against.
2214    
2215     Due to this failure, the "mnc" package is now DISABLED.
2216     *********************************************************************
2217     EOF
2218     PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
2219     DISABLE="$DISABLE mnc"
2220     else
2221 jmc 1.206 # this prevent to add mnc (due to pdepend rules) if not available
2222     DISABLE="$DISABLE mnc"
2223     fi
2224     else
2225     # we have NetCDF, we try to build MNC template files
2226     ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
2227     RETVAL=$?
2228     if test "x${RETVAL}" = x0 ; then
2229     rm -f make_mnc.errors
2230     else
2231     echo "Error: problem encountered while building source files in pkg/mnc:"
2232     cat make_mnc.errors 1>&2
2233     if test "x$mnc_in" = x0 ; then
2234 jmc 1.237 exit 1
2235 edhill 1.100 else
2236 jmc 1.206 DISABLE="$DISABLE mnc"
2237 edhill 1.100 fi
2238     fi
2239     fi
2240    
2241 jmc 1.161 # Check for package PROFILES: if NetCDF is not available,
2242     # then delete profiles from the list of available packages.
2243 jmc 1.206 if test "x$HAVE_NETCDF" != xt ; then
2244     echo " $PACKAGES " | grep ' profiles ' > /dev/null 2>&1
2245     RETVAL=$?
2246     if test "x$RETVAL" = x0 ; then
2247 jmc 1.161 cat <<EOF
2248     *********************************************************************
2249     WARNING: the "profiles" package was enabled but tests failed to
2250     compile NetCDF applications. Please check that:
2251    
2252     1) NetCDF is correctly installed for this compiler and
2253 jmc 1.206 2) the LIBS variable (within the "optfile") specifies the correct
2254 jmc 1.161 NetCDF library to link against.
2255    
2256     Due to this failure, the "profiles" package is now DISABLED.
2257     *********************************************************************
2258     EOF
2259     PACKAGES=`echo $PACKAGES | sed -e 's/profiles//g'`
2260     DISABLE="$DISABLE profiles"
2261 jmc 1.206 else
2262     # this prevent to add profiles (due to pdepend rules) if not available
2263     DISABLE="$DISABLE profiles"
2264 jmc 1.161 fi
2265     fi
2266    
2267 jahn 1.232 # Check for package RADTRANS: if LAPACK is not available,
2268     # then issue a warning that the direct radtrans solver is not available.
2269     if test "x$HAVE_LAPACK" != xt ; then
2270     echo " $PACKAGES " | grep ' radtrans ' > /dev/null 2>&1
2271     RETVAL=$?
2272     if test "x$RETVAL" = x0 ; then
2273     cat <<EOF
2274     *********************************************************************
2275     WARNING: the "radtrans" package was enabled but tests failed to
2276     compile LAPACK applications. This means that the direct radtrans
2277     solver is not available and compilation will fail if it is enabled.
2278     If you want to use the direct solver, please check that:
2279    
2280     1) LAPACK is correctly installed for this compiler and
2281     2) the LIBS variable (within the "optfile") specifies the correct
2282     LAPACK library to link against.
2283     *********************************************************************
2284     EOF
2285     fi
2286     fi
2287    
2288 jmc 1.208 if test "x${PKG_DEPEND}" != x ; then
2289     echo " applying package dependency rules"
2290     ck=
2291     while test "x$ck" != xtt ; do
2292 edhill 1.1 i=0
2293 edhill 1.2 # rtot=${#PNAME[@]}
2294     rtot=$nname
2295 jmc 1.162 while test $i -le $rtot ; do
2296 edhill 1.1
2297     # Is $pname in the current $PACKAGES list?
2298 edhill 1.2 # pname=${PNAME[$i]}
2299     tmp="pname=\"\$PNAME_$i\""
2300     eval $tmp
2301 edhill 1.1 pin="f"
2302     for p in $PACKAGES ; do
2303     if test "x$p" = "x$pname" ; then
2304     pin="t"
2305     fi
2306     done
2307 jmc 1.205 # or in the current $STANDARDDIRS list?
2308     for p in $STANDARDDIRS ; do
2309     if test "x$p" = "x$pname" ; then pin="t" ; fi
2310     done
2311 edhill 1.1
2312     # Is the DNAME entry a (+) or (-) rule ?
2313 edhill 1.2 tmp="dname=\"\$DNAME_$i\""
2314     eval $tmp
2315 edhill 1.1 plus="-"
2316 edhill 1.2 echo $dname | grep '^+' > /dev/null 2>&1
2317 edhill 1.1 RETVAL=$?
2318     if test "x$RETVAL" = x0 ; then
2319     plus="+"
2320     fi
2321    
2322     # Is $dname in the current $PACKAGES list?
2323 edhill 1.2 dname=`echo $dname | sed -e 's/^[+-]//'`
2324 edhill 1.1 din="f"
2325     for p in $PACKAGES ; do
2326     if test "x$p" = "x$dname" ; then
2327     din="t"
2328     fi
2329     done
2330    
2331     # Do we need to add $dname according to the dependency rules?
2332     if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
2333 jmc 1.236 #echo " " $pname ": need to add :" $dname
2334 edhill 1.1 in_dis="f"
2335     for dis in $DISABLE ; do
2336     if test "x$dis" = "x$dname" ; then
2337     in_dis="t"
2338     fi
2339     done
2340     if test "x$in_dis" = xt ; then
2341     echo "Error: can't satisfy package dependencies:"
2342     echo " \"$dname\" is required by the dependency rules"
2343     echo " but is disallowed by the DISABLE settings"
2344     exit 1
2345     else
2346     PACKAGES="$PACKAGES $dname"
2347     ck=
2348     fi
2349     fi
2350    
2351     # Do we need to get rid of $dname according to the dependency rules?
2352     if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
2353     echo "Error: can't satisfy package dependencies:"
2354 jmc 1.206 echo " \"$pname\" was requested but is disallowed by"
2355 edhill 1.1 echo " the dependency rules for \"$dname\""
2356     exit 1
2357     fi
2358 jmc 1.236 i=`echo "$i + 1" | bc -l`
2359 edhill 1.87 #i=$(( $i + 1 ))
2360 edhill 1.1 done
2361     ck=$ck"t"
2362 jmc 1.208 done
2363     echo " packages are: $PACKAGES"
2364     fi
2365 edhill 1.1 for i in $PACKAGES ; do
2366     adr="$ROOTDIR/pkg/$i"
2367     if test -d $adr ; then
2368     SOURCEDIRS="$SOURCEDIRS $adr"
2369     INCLUDEDIRS="$INCLUDEDIRS $adr"
2370 edhill 1.14 if test "x$i" = xautodiff ; then
2371     AUTODIFF_PKG_USED=t
2372     fi
2373 edhill 1.1 else
2374     echo "Error: the directory \"$adr\" for package $i doesn't exist"
2375     exit 1
2376     fi
2377     done
2378    
2379 edhill 1.12 # Create a list of #define and #undef to enable/disable packages
2380     PACKAGES_DOT_H=PACKAGES_CONFIG.h
2381 jmc 1.206 # The following UGLY HACK sets multiple "#undef"s and it needs to go
2382     # away. On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
2383 edhill 1.1 # file would eventually be split up so that all package-related #define
2384     # statements could be separated and handled only by genmake.
2385     names=`ls -1 "$ROOTDIR/pkg"`
2386     all_pack=
2387 adcroft 1.44 DISABLED_PACKAGES=
2388 edhill 1.1 for n in $names ; do
2389     if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
2390     has_pack="f"
2391     for pack in $PACKAGES ; do
2392     if test "x$pack" = "x$n" ; then
2393     has_pack="t"
2394     break
2395     fi
2396     done
2397     if test "x$has_pack" = xf ; then
2398 edhill 1.116 undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2399 jmc 1.236 DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
2400 edhill 1.1 fi
2401     fi
2402     done
2403 adcroft 1.44 ENABLED_PACKAGES=
2404 edhill 1.1 for i in $PACKAGES ; do
2405 edhill 1.116 def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
2406 adcroft 1.44 ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
2407 edhill 1.12 #eh3 DEFINES="$DEFINES -D$def"
2408 edhill 1.1
2409     #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
2410 jmc 1.206 case $i in
2411 edhill 1.1 aim_v23)
2412 jmc 1.236 ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
2413 jmc 1.55 echo "Warning: ALLOW_AIM is set to enable aim_v23."
2414 edhill 1.1 ;;
2415     esac
2416     #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
2417    
2418     done
2419    
2420 jmc 1.205 echo " Adding STANDARDDIRS='$STANDARDDIRS'"
2421 edhill 1.1 BUILDDIR=${BUILDDIR:-.}
2422 edhill 1.57 if test "x$STANDARDDIRS" != x ; then
2423     for d in $STANDARDDIRS ; do
2424     adr="$ROOTDIR/$d/src"
2425     if test ! -d $adr ; then
2426     echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2427     echo " is correct and that you correctly specified the STANDARDDIRS option"
2428     exit 1
2429     else
2430     SOURCEDIRS="$SOURCEDIRS $adr"
2431     fi
2432     adr="$ROOTDIR/$d/inc"
2433     if test ! -d $adr ; then
2434     echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
2435     echo " is correct and that you correctly specified the STANDARDDIRS option"
2436     exit 1
2437     else
2438     INCLUDEDIRS="$INCLUDEDIRS $adr"
2439     fi
2440     done
2441     fi
2442 edhill 1.1
2443 adcroft 1.52 echo " Searching for *OPTIONS.h files in order to warn about the presence"
2444     echo " of \"#define \"-type statements that are no longer allowed:"
2445 edhill 1.12 CPP_OPTIONS=
2446 adcroft 1.52 CPP_EEOPTIONS=
2447 edhill 1.12 spaths=". $INCLUDEDIRS"
2448 adcroft 1.52 names=`ls -1 "$ROOTDIR/pkg"`
2449 edhill 1.12 for i in $spaths ; do
2450     try="$i/CPP_OPTIONS.h"
2451 edhill 1.54 if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
2452 edhill 1.12 echo " found CPP_OPTIONS=\"$try\""
2453     CPP_OPTIONS="$try"
2454 jmc 1.236 # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
2455     for n in $names ; do
2456     test_for_package_in_cpp_options $CPP_OPTIONS $n
2457     done
2458 adcroft 1.52 fi
2459     try="$i/CPP_EEOPTIONS.h"
2460 edhill 1.54 if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
2461 adcroft 1.52 echo " found CPP_EEOPTIONS=\"$try\""
2462 jmc 1.236 # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
2463 adcroft 1.52 #**** not yet enabled ****
2464     # test_for_mpi_in_cpp_eeoptions $try
2465     #**** not yet enabled ****
2466     CPP_EEOPTIONS="$try"
2467 edhill 1.12 fi
2468     done
2469     if test "x$CPP_OPTIONS" = x ; then
2470     echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
2471     exit 1
2472     fi
2473 edhill 1.1
2474 edhill 1.14 # Here, we build the list of files to be "run through" the adjoint
2475     # compiler.
2476 jmc 1.176 if test -f ./adSrcFiles.tmp ; then
2477     rm -f ./adSrcFiles.tmp
2478 edhill 1.14 fi
2479     echo " Creating the list of files for the adjoint compiler."
2480 jmc 1.207 touch adSrcFiles.tmp
2481 edhill 1.14 for i in $SOURCEDIRS ; do
2482     list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
2483     for j in $list_files ; do
2484 jmc 1.176 cat $i/$j >> adSrcFiles.tmp
2485 edhill 1.14 done
2486     done
2487 edhill 1.121 if test ! "x"$FS = "x.f" ; then
2488 jmc 1.176 cat adSrcFiles.tmp | sed -e "s/\.f/.$FS/g" > adSrcFiles.tmp_f
2489     mv -f adSrcFiles.tmp_f adSrcFiles.tmp
2490 edhill 1.121 fi
2491 edhill 1.14
2492 edhill 1.2 echo
2493     echo "=== Creating the Makefile ==="
2494 edhill 1.1 echo " setting INCLUDES"
2495     for i in $INCLUDEDIRS ; do
2496 edhill 1.87 if test ! -d $i ; then
2497 edhill 1.1 echo "Warning: can't find INCLUDEDIRS=\"$i\""
2498     fi
2499     done
2500    
2501 ce107 1.139 if test ! "x$DIVA" = x ; then
2502 ce107 1.140 echo " Creating the pseudo-MPI include directory"
2503 ce107 1.139 INCLUDES="-I./mpi_headers $INCLUDES"
2504     rm -rf ./mpi_headers
2505     mkdir -p ./mpi_headers
2506    
2507     if test "x$MPIINCLUDEDIR" = x ; then
2508     if test "x$MPIHOME" = x ; then
2509     MPIHOME='/usr'
2510     fi
2511     MPIINCLUDEDIR='$MPIHOME/include'
2512     fi
2513 jmc 1.206
2514 ce107 1.139 if test -r $MPIINCLUDEDIR/mpif.h ; then
2515     for i in $MPI_HEADER_FILES; do
2516     cp -p $MPIINCLUDEDIR/$i ./mpi_headers
2517     done
2518    
2519     perl -i -pe 's/MPI_DISPLACEMENT_CURRENT=-1_8/MPI_DISPLACEMENT_CURRENT=-1/g' mpi_headers/mpif.h
2520     else
2521     echo " We cannot create a copy of mpif.h!"
2522 heimbach 1.156 # exit -1
2523 ce107 1.139 fi
2524     fi
2525    
2526 edhill 1.1 echo " Determining the list of source and include files"
2527     rm -rf .links.tmp
2528     mkdir .links.tmp
2529 edhill 1.142 touch .links.tmp/foo
2530     if test ! -r ".links.tmp/foo" ; then
2531     echo
2532     echo "ERROR : something is wrong with your directory permissions or"
2533     echo " your user file-creation mask (\"umask\") since creating a"
2534     echo " sub-dir, touch-ing a file within it, and then reading it is"
2535     echo " not working. Please try setting your umask to something"
2536     echo " sane such as:"
2537     echo
2538     echo " umask 0002"
2539     echo
2540     echo " and please verify that you have the proper permissions for"
2541     echo " creating sub-directories and then reading files created"
2542     echo " within them."
2543     echo
2544     exit 1
2545     fi
2546     rm -f .links.tmp/foo
2547 jmc 1.176
2548 jmc 1.206 if test "x$OPENAD" != x ; then
2549 jmc 1.176 OAD_DONT_COMPILE="/dev/null"
2550     OAD_DONT_TRANSFORM="/dev/null"
2551     OAD_KEEP_ORIGINAL="/dev/null"
2552     OAD_CB2M_FILES="/dev/null"
2553 heimbach 1.242 OADTOOLS="$TOOLSDIR/OAD_support"
2554     test -f "oadtempflile" && \rm -f "oadtempflile"
2555     cat >> "oadtempflile" <<EOF
2556     $OADTOOLS
2557     EOF
2558 jmc 1.176 echo " looking for dontCompile file: "
2559     for i in "." $MODS ; do
2560     if test -r $i"/dontCompile" ; then
2561     OAD_DONT_COMPILE=$i"/dontCompile"
2562     echo " found $OAD_DONT_COMPILE"
2563     break
2564     fi
2565     done
2566     echo " looking for dontTransform file: "
2567     for i in "." $MODS ; do
2568     if test -r $i"/dontTransform" ; then
2569     OAD_DONT_TRANSFORM=$i"/dontTransform"
2570     echo " found $OAD_DONT_TRANSFORM"
2571     break
2572     fi
2573     done
2574     echo " looking for keepOriginal file: "
2575     for i in "." $MODS ; do
2576     if test -r $i"/keepOriginal" ; then
2577     OAD_KEEP_ORIGINAL=$i"/keepOriginal"
2578     echo " found $OAD_KEEP_ORIGINAL"
2579     break
2580     fi
2581     done
2582     echo " looking for cb2mFiles: "
2583     for i in "." $MODS ; do
2584     if test -r $i"/cb2mFiles" ; then
2585     OAD_CB2M_FILES=$i"/cb2mFiles"
2586     echo " found $OAD_CB2M_FILES"
2587     break
2588     fi
2589     done
2590     echo " OpenAD exceptions: "
2591     fi
2592    
2593 edhill 1.1 echo "# This section creates symbolic links" > srclinks.tmp
2594     echo "" >> srclinks.tmp
2595 jmc 1.176 printf 'F77_SRC_FILES = ' > F77srclist.tmp
2596     printf 'NON_AD_F77_SRC_FILES = ' > nonADF77srclist.tmp
2597     printf 'C_SRC_FILES = ' > csrclist.tmp
2598     printf 'F90_SRC_FILES = ' > F90srclist.tmp
2599     printf 'H_SRC_FILES = ' > hsrclist.tmp
2600     printf 'AD_FLOW_FILES = ' > ad_flow_files.tmp
2601 adcroft 1.9 alldirs="$SOURCEDIRS $INCLUDEDIRS ."
2602 edhill 1.1 for d in $alldirs ; do
2603     deplist=
2604 edhill 1.14 sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
2605 cnh 1.3 sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
2606 jmc 1.206 if test "x$OPENAD" != x ; then
2607 jmc 1.176 sfiles=`( echo $sfiles | grep -v _cb2m\. )`
2608     fi
2609 edhill 1.1 for sf in $sfiles ; do
2610     if test ! -r ".links.tmp/$sf" ; then
2611     if test -f "$d/$sf" ; then
2612 edhill 1.131 ignore_f=f
2613 jmc 1.236 case $d/$sf in
2614     ./$PACKAGES_DOT_H)
2615 edhill 1.141 ignore_f=t
2616 adcroft 1.44 ;;
2617 jmc 1.236 ./AD_CONFIG.h)
2618 edhill 1.141 ignore_f=t
2619 adcroft 1.44 ;;
2620 jmc 1.236 ./FC_NAMEMANGLE.h)
2621 edhill 1.141 ignore_f=t
2622 adcroft 1.44 ;;
2623 jmc 1.236 ./BUILD_INFO.h)
2624 edhill 1.141 ignore_f=t
2625     ;;
2626 jmc 1.236 ./EMBEDDED_FILES.h)
2627 edhill 1.141 ignore_f=t
2628 edhill 1.98 ;;
2629 jmc 1.236 *)
2630 edhill 1.131 # For the local directory *ONLY*,
2631     # ignore all soft-links
2632     if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
2633     ignore_f=t
2634     else
2635     touch .links.tmp/$sf
2636     deplist="$deplist $sf"
2637     fi
2638 adcroft 1.44 ;;
2639 jmc 1.236 esac
2640 edhill 1.131 if test "x$ignore_f" = xf ; then
2641     extn=`echo $sf | $AWK -F. '{print $NF}'`
2642     case $extn in
2643 jmc 1.176 F)
2644     echo " \\" >> F77srclist.tmp
2645     printf " $sf" >> F77srclist.tmp
2646 jmc 1.206 if test "x$OPENAD" != x ; then
2647 jmc 1.176 basename=${sf%%.F}
2648     isAD=`egrep ^$basename.f'[ ]*' adSrcFiles.tmp`
2649 jmc 1.206 if test -z "$isAD" ; then
2650 jmc 1.176 toBeIgnored=`egrep ^$basename'[ ]*' ${OAD_DONT_COMPILE}`
2651 jmc 1.206 if test -z "$toBeIgnored" ; then
2652 jmc 1.176 echo " \\" >> nonADF77srclist.tmp
2653     printf " $sf" >> nonADF77srclist.tmp
2654 jmc 1.206 else
2655 jmc 1.176 echo " not to be compiled : $sf"
2656     fi
2657 jmc 1.206 else # file is initially listed as an AD file we want to exclude it
2658 jmc 1.176 # or we want to retain the untransformed version
2659     notToBeTransformed=`egrep ^$basename'[ ]*' ${OAD_DONT_TRANSFORM}`
2660     untransformedVersionToBeKept=`egrep ^$basename'[ ]*' ${OAD_KEEP_ORIGINAL}`
2661 jmc 1.206 if test -n "$notToBeTransformed"; then
2662 jmc 1.176 echo " not to be transformed: $sf"
2663     fi
2664     if test -n "$untransformedVersionToBeKept" ; then
2665     echo " original to be kept : $sf"
2666 jmc 1.206 fi
2667 jmc 1.176 if test -n "$notToBeTransformed" -o -n "$untransformedVersionToBeKept" ; then
2668     echo " \\" >> nonADF77srclist.tmp
2669     printf " $sf" >> nonADF77srclist.tmp
2670     fi
2671     fi
2672     fi
2673     ;;
2674     F90)
2675     echo " \\" >> F90srclist.tmp
2676     printf " $sf" >> F90srclist.tmp
2677     ;;
2678     c)
2679     echo " \\" >> csrclist.tmp
2680     printf " $sf" >> csrclist.tmp
2681     ;;
2682     h)
2683     echo " \\" >> hsrclist.tmp
2684     printf " $sf" >> hsrclist.tmp
2685     ;;
2686 jmc 1.236 flow)
2687 jmc 1.176 echo " \\" >> ad_flow_files.tmp
2688     printf " $sf" >> ad_flow_files.tmp
2689     ;;
2690     esac
2691     fi
2692 edhill 1.1 fi
2693     fi
2694     done
2695     if test "x$deplist" != x ; then
2696 jmc 1.176 if test "$d" != "." ; then
2697 jmc 1.236 echo "" >> srclinks.tmp
2698 edhill 1.2 echo "# These files are linked from $d" >> srclinks.tmp
2699 edhill 1.1 echo "$deplist :" >> srclinks.tmp
2700 jahn 1.170 # We need to make sure that the link isn't already there.
2701     # This may happen when make thinks that a header file has to be "remade"
2702     # because a module it depends on has changed. In this case we do nothing.
2703     printf "\tif [ ! -L \$@ ]; then \$(LN) %s/\$@ \$@; fi\n" $d >> srclinks.tmp
2704 jmc 1.176 fi
2705 edhill 1.1 fi
2706     done
2707     rm -rf .links.tmp
2708 jmc 1.176 echo "" >> F77srclist.tmp
2709     echo "" >> nonADF77srclist.tmp
2710     echo "" >> csrclist.tmp
2711     echo "" >> F90srclist.tmp
2712     echo "" >> hsrclist.tmp
2713     echo "" >> ad_flow_files.tmp
2714 edhill 1.1
2715 jmc 1.192 CMDLINE=$0
2716     for xx in "$@" ; do nw=`echo $xx | wc -w`
2717     if test $nw = '1' ; then CMDLINE="$CMDLINE $xx"
2718 jmc 1.237 else CMDLINE="$CMDLINE '$xx'" ; fi
2719 jmc 1.192 done
2720    
2721 edhill 1.88 if test -f $MAKEFILE ; then
2722 jmc 1.205 mv -f $MAKEFILE "$MAKEFILE.old"
2723 edhill 1.1 fi
2724     echo " Writing makefile: $MAKEFILE"
2725     echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
2726     echo "# $MACHINE" >> $MAKEFILE
2727     echo "# This makefile was generated automatically on" >> $MAKEFILE
2728     echo "# $THISDATE" >> $MAKEFILE
2729     echo "# by the command:" >> $MAKEFILE
2730 jmc 1.192 echo "# $CMDLINE" >> $MAKEFILE
2731 edhill 1.1 echo "# executed by:" >> $MAKEFILE
2732 edhill 1.97 echo "# ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
2733 edhill 1.21
2734     EXE_AD=$EXECUTABLE"_ad"
2735     EXE_FTL=$EXECUTABLE"_ftl"
2736     EXE_SVD=$EXECUTABLE"_svd"
2737    
2738 edhill 1.1 cat >>$MAKEFILE <<EOF
2739 edhill 1.53 #
2740     # OPTFILE="$OPTFILE"
2741 jmc 1.205 #
2742 edhill 1.1 # BUILDDIR : Directory where object files are written
2743     # SOURCEDIRS : Directories containing the source (.F) files
2744     # INCLUDEDIRS : Directories containing the header-source (.h) files
2745     # EXEDIR : Directory where executable that is generated is written
2746     # EXECUTABLE : Full path of executable binary
2747     #
2748     # CPP : C-preprocessor command
2749     # INCLUDES : Directories searched for header files
2750     # DEFINES : Macro definitions for CPP
2751     # MAKEDEPEND : Dependency generator
2752     # FC : Fortran compiler command
2753     # FFLAGS : Configuration/debugging options for FC
2754     # FOPTIM : Optimization options for FC
2755     # LINK : Command for link editor program
2756     # LIBS : Library flags /or/ additional optimization/debugging flags
2757    
2758     ROOTDIR = ${ROOTDIR}
2759 jmc 1.205 BUILDDIR = ${BUILDDIR}
2760 edhill 1.1 SOURCEDIRS = ${SOURCEDIRS}
2761     INCLUDEDIRS = ${INCLUDEDIRS}
2762     EXEDIR = ${EXEDIR}
2763     EXECUTABLE = \$(EXEDIR)/${EXECUTABLE}
2764     TOOLSDIR = ${TOOLSDIR}
2765 heimbach 1.242 OADTOOLS = ${OADTOOLS}
2766 edhill 1.1
2767 edhill 1.14 #eh3 new defines for the adjoint work
2768     AUTODIFF = ${ROOTDIR}/pkg/autodiff
2769 edhill 1.21 EXE_AD = ${EXE_AD}
2770     EXE_FTL = ${EXE_FTL}
2771     EXE_SVD = ${EXE_SVD}
2772 edhill 1.14
2773 adcroft 1.44 ENABLED_PACKAGES = ${ENABLED_PACKAGES}
2774     DISABLED_PACKAGES = ${DISABLED_PACKAGES}
2775    
2776 adcroft 1.52 # These files are created by Makefile
2777 edhill 1.97 SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
2778 edhill 1.141 EOF
2779 adcroft 1.52
2780 edhill 1.141 if test "x$EMBED_SRC" = xt ; then
2781     echo "EMBEDDED_FILES = EMBEDDED_FILES.h" >>$MAKEFILE
2782     else
2783     echo "EMBEDDED_FILES = " >>$MAKEFILE
2784     fi
2785 edhill 1.1
2786 jahn 1.247 # extract default cpp search path so we can pass it to makedepend
2787     CPPINCLUDES=`cat /dev/null | $CPP -v 2>&1 | awk '/^End of search/{f=0}!/^\#/{if(f){printf " -I%s", $1;}}/^\#include "..." search start/{f=1}'`
2788    
2789 edhill 1.1 cat >>$MAKEFILE <<EOF
2790     # Unix ln (link)
2791     LN = ${LN}
2792     # Dependency generator
2793     MAKEDEPEND = ${MAKEDEPEND}
2794     # Special preprocessor (KAP on DECs, FPP on Crays)
2795     KPP = ${KPP}
2796     # Fortran compiler
2797 edhill 1.94 FC = ${FC}
2798 cnh 1.3 # Fortran compiler
2799     F90C = ${F90C}
2800 edhill 1.92 # C compiler
2801     CC = ${CC}
2802 edhill 1.1 # Link editor
2803 edhill 1.70 LINK = ${LINK} ${LDADD}
2804 edhill 1.1
2805     # Defines for CPP
2806     DEFINES = ${DEFINES}
2807     # Includes for CPP
2808     INCLUDES = ${INCLUDES}
2809 jahn 1.247 # default CPP includes for makedepend
2810     CPPINCLUDES = ${CPPINCLUDES}
2811 edhill 1.1 # Flags for KPP
2812     KFLAGS1 = ${KFLAGS1}
2813     KFLAGS2 = ${KFLAGS2}
2814     # Optim./debug for FC
2815 mlosch 1.165 FFLAGS = ${FFLAGS} ${FEXTRAFLAGS}
2816 edhill 1.1 FOPTIM = ${FOPTIM}
2817 cnh 1.3 # Optim./debug for FC
2818     F90FLAGS = ${F90FLAGS}
2819     F90OPTIM = ${F90OPTIM}
2820 jmc 1.176 F90FIXEDFORMAT = ${F90FIXEDFORMAT}
2821 edhill 1.1 # Flags for CC
2822     CFLAGS = ${CFLAGS}
2823     # Files that should not be optimized
2824     NOOPTFILES = ${NOOPTFILES}
2825     NOOPTFLAGS = ${NOOPTFLAGS}
2826     # Flags and libraries needed for linking
2827 edhill 1.107 LIBS = ${LIBS}
2828 jmc 1.228 # Name of the makefile
2829 jmc 1.238 MAKEFILE = ${MAKEFILE}
2830     # Name of the make program
2831     MAKE = ${MAKE}
2832 edhill 1.1
2833     EOF
2834    
2835 jmc 1.176 cat F77srclist.tmp >> $MAKEFILE
2836     cat nonADF77srclist.tmp >> $MAKEFILE
2837     cat csrclist.tmp >> $MAKEFILE
2838     cat F90srclist.tmp >> $MAKEFILE
2839     cat hsrclist.tmp >> $MAKEFILE
2840     cat ad_flow_files.tmp >> $MAKEFILE
2841    
2842     rm -f F77srclist.tmp nonADF77srclist.tmp csrclist.tmp F90srclist.tmp hsrclist.tmp ad_flow_files.tmp
2843    
2844 edhill 1.75 echo >> $MAKEFILE
2845 jmc 1.176
2846 jmc 1.205 # add definitions for preprocessed sources
2847     # and note that not all systems allow case sensitive extensions
2848     # hence the $FS and $FS90 here.
2849     # for fixed format f90 files we use ff90 or FF90 resp
2850 jmc 1.176 # but these are not expected to be the original source files
2851    
2852     echo 'F77_PP_SRC_FILES = $(F77_SRC_FILES:.F=.'$FS')' >> $MAKEFILE
2853     echo 'F90_PP_SRC_FILES = $(F90_SRC_FILES:.F90=.'$FS90')' >> $MAKEFILE
2854     echo 'OBJFILES= $(F77_SRC_FILES:.F=.o) $(C_SRC_FILES:.c=.o) $(F90_SRC_FILES:.F90=.o)' >> $MAKEFILE
2855 jmc 1.236 echo 'FLOWFILES = $(AD_FLOW_FILES:.flow=.flowdir)' >> $MAKEFILE
2856 edhill 1.75 echo >> $MAKEFILE
2857     echo '.SUFFIXES:' >> $MAKEFILE
2858 jmc 1.176 echo '.SUFFIXES: .o .'$FS' .p .F .c .f'$FS90' .'$FS90' .FF90 .F90 .flowdir .flow' >> $MAKEFILE
2859 edhill 1.1
2860     cat >>$MAKEFILE <<EOF
2861    
2862 jmc 1.238 all: fwd_exe_target
2863     fwd_exe_target:
2864     @echo Update AD_CONFIG.h and make \$(EXECUTABLE)
2865     @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Forward version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
2866     @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
2867     @-rm -f ad_config.template
2868     \$(MAKE) -f \$(MAKEFILE) \$(EXECUTABLE)
2869    
2870 jmc 1.176 \$(EXECUTABLE): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(OBJFILES) \$(EMBEDDED_FILES)
2871 adcroft 1.44 @echo Creating \$@ ...
2872 edhill 1.1 \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2873 jmc 1.222
2874 edhill 1.1 depend:
2875 jmc 1.238 @\$(MAKE) -f \$(MAKEFILE) links
2876 jahn 1.247 \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(CPPINCLUDES) \$(F77_SRC_FILES)
2877 adcroft 1.44 \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2878 edhill 1.72 -rm -f makedepend.out
2879 edhill 1.1
2880 cnh 1.132 lib: libmitgcmuv.a
2881    
2882     libmitgcmuv.a: \$(OBJFILES)
2883     ar rcv libmitgcmuv.a \$(OBJFILES)
2884 cnh 1.159 ar d libmitgcmuv.a main.o
2885 cnh 1.132
2886 jmc 1.222 obj: \$(OBJFILES)
2887    
2888 jmc 1.176 links: \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(SPECIAL_FILES)
2889 edhill 1.1
2890 jmc 1.176 small_f: \$(F77_PP_SRC_FILES) \$(F90_PP_SRC_FILES)
2891 edhill 1.1
2892     output.txt: \$(EXECUTABLE)
2893     @printf 'running ... '
2894     @\$(EXECUTABLE) > \$@
2895    
2896 jmc 1.210 # remove most of the files that "make" generates
2897 edhill 1.1 clean:
2898 heimbach 1.157 -rm -rf *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
2899     -rm -rf *.o
2900 dfer 1.172 -rm -rf *.$FS *.flowdir
2901 utke 1.193 -rm -rf *.f$FS90 \$(AD_CLEAN) ad_input*
2902 jmc 1.210
2903     # remove most of the files that "make" and "make depend" generate
2904 edhill 1.1 Clean:
2905 jmc 1.238 @\$(MAKE) -f \$(MAKEFILE) clean
2906     @\$(MAKE) -f \$(MAKEFILE) cleanlinks
2907 jmc 1.215 -rm -f \$(SPECIAL_FILES) f90mkdepend.log $MAKEFILE.old
2908 jmc 1.233 -rm -f taf_command taf_output taf_ad.log taf_ad_flow.log taf_ftl.log
2909 jmc 1.211 -rm -f genmake_warnings genmake_errors make.log
2910 jmc 1.210
2911     # remove also the executable, files that "genmake2" generates (except Makefile)
2912 jmc 1.211 # and output from a run (plus log files from testreport)
2913 edhill 1.1 CLEAN:
2914 jmc 1.238 @\$(MAKE) -f \$(MAKEFILE) Clean
2915 jmc 1.233 -rm -f \$(EXECUTABLE) \$(EXE_AD) \$(EXE_FTL) *.bak
2916 jmc 1.219 -rm -f $LOGFILE genmake_state genmake_*optfile
2917     -rm -f SIZE.h.mpi genmake.tr_log make.tr_log
2918 edhill 1.1 -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2919     -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2920     -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2921 jmc 1.210 -rm -f *.txt STD* *diagnostics.log datetime
2922 jmc 1.166 -rm -f *_MIT_CE_000.opt0000 costfunction*0000
2923 edhill 1.144 -rm -rf mnc_test_*
2924 edhill 1.1
2925     makefile:
2926 edhill 1.73 $THIS_SCRIPT $G2ARGS
2927 edhill 1.1 cleanlinks:
2928     -find . -type l -exec rm {} \;
2929    
2930 jmc 1.176 # Special targets (SPECIAL_FILES) which are created by make
2931 adcroft 1.44 ${PACKAGES_DOT_H}:
2932     @echo Creating \$@ ...
2933 jmc 1.238 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@
2934 adcroft 1.44 AD_CONFIG.h:
2935     @echo Creating \$@ ...
2936 jmc 1.238 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Default version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > \$@
2937 adcroft 1.52 FC_NAMEMANGLE.h:
2938     @echo Creating \$@ ...
2939     echo "$FC_NAMEMANGLE" > \$@
2940 adcroft 1.44
2941 edhill 1.97 BUILD_INFO.h:
2942     @echo Creating \$@ ...
2943     EOF
2944    
2945     test ! "x$THISVER" = x && echo " -echo \"#define THISVER '$THISVER'\" > \$@" >> $MAKEFILE
2946     test ! "x$THISUSER" = x && echo " -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
2947     test ! "x$THISDATE" = x && echo " -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2948     test ! "x$THISHOST" = x && echo " -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2949    
2950 edhill 1.141 if test "x$EMBED_SRC" = xt ; then
2951     cat >>$MAKEFILE <<EOF
2952    
2953     decode_files.o : EMBEDDED_FILES.h
2954    
2955 jmc 1.205 ## \$(F77_PP_SRC_FILES)
2956 jmc 1.176 all_fF.tar.gz : \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
2957 edhill 1.141 @echo Creating \$@ ...
2958 jmc 1.176 -tar -hcf all_fF.tar \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) \$(F77_PP_SRC_FILES) Makefile
2959 edhill 1.141 -rm -f all_fF.tar.gz
2960     -gzip all_fF.tar
2961    
2962     EMBEDDED_FILES.h : all_fF.tar.gz
2963     @echo Creating \$@ ...
2964     -\${ROOTDIR}/tools/embed_encode/encode_files EMBEDDED_FILES.h all_fF.tar.gz
2965    
2966     EOF
2967     fi
2968    
2969 edhill 1.97 cat >>$MAKEFILE <<EOF
2970    
2971 edhill 1.76 # The normal chain of rules is ( .F - .$FS - .o )
2972    
2973 edhill 1.101 ## This nullifies any default implicit rules concerning these two file types:
2974 jmc 1.177 ## %.o : %.F
2975 edhill 1.76
2976 jmc 1.244 # C preprocessing and replacing the _d in constants:
2977 utke 1.241 CPPCMD = cat \$< | ${CPP} \$(DEFINES) \$(INCLUDES) | ${S64}
2978    
2979 edhill 1.76 .F.$FS:
2980 utke 1.241 \$(CPPCMD) > \$@
2981 edhill 1.76 .$FS.o:
2982 edhill 1.1 \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2983 jmc 1.214 .F.o:
2984     \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2985 jmc 1.176 .F90.$FS90:
2986 utke 1.241 \$(CPPCMD) > \$@
2987 jmc 1.176 .FF90.f$FS90:
2988 utke 1.241 \$(CPPCMD) > \$@
2989 jmc 1.176 .$FS90.o:
2990 cnh 1.3 \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
2991 jmc 1.176 .f$FS90.o:
2992     cp \$< \$(basename \$<).f90
2993     \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$(F90FIXEDFORMAT) \$(basename \$<).f90
2994 edhill 1.1 .c.o:
2995 ce107 1.139 \$(CC) \$(CFLAGS) \$(DEFINES) \$(INCLUDES) -c \$<
2996 dfer 1.172 .flow.flowdir:
2997 utke 1.241 \$(CPPCMD) > \$@
2998 edhill 1.1
2999 edhill 1.76 # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
3000     .F.p:
3001 utke 1.241 \$(CPPCMD) > \$@
3002 edhill 1.76 .p.$FS:
3003 edhill 1.1 \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
3004 edhill 1.14
3005 jmc 1.176 EOF
3006    
3007 edhill 1.14 #=========================================
3008     #=== Automatic Differentiation Rules ===
3009 jmc 1.176 #=== for TAMC/TAF ======================
3010    
3011 jmc 1.206 if test "x$OPENAD" = x ; then
3012 jmc 1.176
3013     cat >>$MAKEFILE <<EOF
3014 edhill 1.14
3015     TAMC = ${TAMC}
3016     TAF = ${TAF}
3017    
3018 edhill 1.17 TAF_EXTRA = ${TAF_EXTRA}
3019     TAMC_EXTRA = ${TAMC_EXTRA}
3020    
3021 edhill 1.14 EOF
3022    
3023     ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
3024     ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
3025     ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
3026     for i in $ad_vars ; do
3027     name=$i
3028 edhill 1.151 t1="t2=\$"`echo "$i"`
3029 edhill 1.14 eval $t1
3030     printf "%-20s = " $name >> $MAKEFILE
3031 edhill 1.151 echo "$t2" | sed -e 's| \+| |g' >> $MAKEFILE
3032 edhill 1.14 done
3033    
3034     echo " Add the source list for AD code generation"
3035     echo >> $MAKEFILE
3036 edhill 1.71 printf "AD_FILES = " >> $MAKEFILE
3037 jmc 1.176 AD_FILES=`cat adSrcFiles.tmp`
3038 edhill 1.14 for i in $AD_FILES ; do
3039     echo " \\" >> $MAKEFILE
3040 edhill 1.71 printf " $i" >> $MAKEFILE
3041 edhill 1.14 done
3042     echo >> $MAKEFILE
3043 jmc 1.176 rm -f adSrcFiles.tmp
3044 edhill 1.14
3045     cat >>$MAKEFILE <<EOF
3046    
3047 edhill 1.16 # ... AD ...
3048 jmc 1.238 adall: ad_exe_target
3049 edhill 1.121 adtaf: ad_taf_output.$FS
3050     adtamc: ad_tamc_output.$FS
3051 edhill 1.21
3052 jmc 1.238 ad_exe_target:
3053     @echo Update AD_CONFIG.h and make \$(EXE_AD)
3054     @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3055     @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3056     @-rm -f ad_config.template
3057     \$(MAKE) -f \$(MAKEFILE) \$(EXE_AD)
3058    
3059 jmc 1.240 ad_input_code.$FS: \$(AD_FILES) \$(AD_FLOW_FILES)
3060 jmc 1.238 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Adjoint version" -bAD_CONFIG_H -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > ad_config.template
3061 edhill 1.23 cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3062 jmc 1.238 @-rm -f ad_config.template
3063     @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3064     @\$(MAKE) -f \$(MAKEFILE) \$(FLOWFILES)
3065 jmc 1.236 cat \$(FLOWFILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ad_input_code.$FS
3066 edhill 1.22
3067 edhill 1.121 ad_taf_output.$FS: ad_input_code.$FS
3068     \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3069 jmc 1.173 ls -l ad_input_code_ad.$FS
3070 edhill 1.121 cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
3071 heimbach 1.37
3072     adtafonly:
3073 edhill 1.121 \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
3074 jmc 1.173 ls -l ad_input_code_ad.$FS
3075 edhill 1.121 cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
3076 edhill 1.14
3077 jmc 1.240 \$(EXE_AD): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) ad_taf_output.o \$(OBJFILES) \$(EMBEDDED_FILES)
3078 jmc 1.206 \$(LINK) -o \${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
3079 edhill 1.14
3080 edhill 1.121 ad_tamc_output.$FS: ad_input_code.$FS
3081     \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
3082     cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
3083 edhill 1.14
3084     ad_tamc: ad_tamc_output.o \$(OBJFILES)
3085 jmc 1.206 \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
3086 edhill 1.14
3087 heimbach 1.105 adonlyfwd:
3088 edhill 1.106 patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
3089 jmc 1.206
3090 heimbach 1.105 adtrick:
3091 edhill 1.106 patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
3092 edhill 1.14
3093 jmc 1.226 adobj: ad_taf_output.o \$(OBJFILES)
3094    
3095 edhill 1.19 # ... FTL ...
3096 jmc 1.238 ftlall: ftl_exe_target
3097 edhill 1.121 ftltaf: ftl_taf_output.$FS
3098     ftltamc: ftl_tamc_output.$FS
3099 edhill 1.21
3100 jmc 1.238 ftl_exe_target:
3101     @echo Update AD_CONFIG.h and make \$(EXE_FTL)
3102     @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3103     @cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3104     @-rm -f ad_config.template
3105     \$(MAKE) -f \$(MAKEFILE) \$(EXE_FTL)
3106    
3107 jmc 1.240 ftl_input_code.$FS: \$(AD_FILES)
3108 jmc 1.238 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "TangLin version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3109     cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3110     @-rm -f ad_config.template
3111     @\$(MAKE) -f \$(MAKEFILE) \$(F77_PP_SRC_FILES)
3112     @\$(MAKE) -f \$(MAKEFILE) \$(AD_FLOW_FILES)
3113 jmc 1.234 cat \$(AD_FLOW_FILES) \$(AD_FILES) | sed -f \$(TOOLSDIR)/remove_comments_sed > ftl_input_code.$FS
3114 edhill 1.22
3115 edhill 1.121 ftl_taf_output.$FS: ftl_input_code.$FS
3116     \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3117 jmc 1.173 ls -l ftl_input_code_ftl.$FS
3118 edhill 1.121 cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3119 edhill 1.14
3120 heimbach 1.40 ftltafonly:
3121 edhill 1.121 \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
3122 jmc 1.173 ls -l ftl_input_code_ftl.$FS
3123 edhill 1.121 cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
3124 heimbach 1.40
3125 jmc 1.240 \$(EXE_FTL): \$(SPECIAL_FILES) \$(F77_SRC_FILES) \$(C_SRC_FILES) \$(H_SRC_FILES) \$(F90_SRC_FILES) ftl_taf_output.o \$(OBJFILES) \$(EMBEDDED_FILES)
3126 jmc 1.233 \$(LINK) -o \${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
3127 edhill 1.14
3128 edhill 1.121 ftl_tamc_output.$FS: ftl_input_code.$FS
3129     \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
3130     cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
3131 edhill 1.16
3132 edhill 1.19 ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
3133 jmc 1.206 \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
3134 edhill 1.16
3135     # ... SVD ...
3136 edhill 1.121 svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
3137 heimbach 1.109 @echo "--->>> Only ran TAF to generate SVD code! <<<---"
3138     @echo "--->>> Do make svdall afterwards to compile. <<<---"
3139     svdall: svd_touch svd_taf
3140 edhill 1.16
3141 heimbach 1.109 svd_taf: \$(OBJFILES)
3142 heimbach 1.40 \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
3143 edhill 1.14
3144 heimbach 1.109 @echo "--->>> Only COMPILE svd code! <<<---"
3145     @echo "--->>> Assumes you previously <<<---"
3146     @echo "--->>> did make svdtaf <<<---"
3147    
3148     svd_touch:
3149     @echo "--->>> Only COMPILE svd code! <<<---"
3150     @echo "--->>> Assumes you previously <<<---"
3151     @echo "--->>> did make svdtaf <<<---"
3152 edhill 1.121 touch ad_taf_output.$FS ftl_taf_output.$FS
3153     \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
3154     \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
3155 jmc 1.238 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "SVD version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN > ad_config.template
3156     cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
3157     @-rm -f ad_config.template
3158 edhill 1.14
3159 jmc 1.176 EOF
3160    
3161 jmc 1.206 fi
3162 jmc 1.176
3163     #=== for OpenAD ========================
3164    
3165 jmc 1.206 if test "x$OPENAD" != x ; then
3166 jmc 1.176
3167     # ============ begin OpenAD specific section ==============
3168    
3169     cat >>$MAKEFILE <<EOF
3170    
3171 jmc 1.206 # all the source files linked from the various locations:
3172 jmc 1.176 ALL_LINKED_FILES= \
3173     \$(F77_SRC_FILES) \
3174     \$(C_SRC_FILES) \
3175     \$(H_SRC_FILES) \
3176     \$(F90_SRC_FILES) \
3177     \$(SPECIAL_FILES)
3178    
3179     ifndef OPENADROOT
3180     \$(error "Error: environment variable OPENADROOT not defined!")
3181     endif
3182    
3183     ifndef XAIFSCHEMAROOT
3184     \$(error "Error: environment variable XAIFSCHEMAROOT not defined!")
3185     endif
3186    
3187     ifndef XAIFBOOSTERROOT
3188     \$(error "Error: environment variable XAIFBOOSTERROOT not defined!")
3189     endif
3190    
3191     EOF
3192    
3193     echo " Add the source list for common block to module conversion "
3194     echo >> $MAKEFILE
3195     printf "CB2M_F90_SRC_NAMES = " >> $MAKEFILE
3196     for i in `cat ${OAD_CB2M_FILES}` ; do
3197     echo " \\" >> $MAKEFILE
3198     printf " $i" >> $MAKEFILE
3199     done
3200     echo >> $MAKEFILE
3201    
3202     echo " Add the source list for AD code generation"
3203     echo >> $MAKEFILE
3204     printf "AD_FILES = " >> $MAKEFILE
3205     for i in `cat ${OAD_CB2M_FILES}` ; do
3206     echo " \\" >> $MAKEFILE
3207     printf " ${i}_mod.f$FS90" >> $MAKEFILE
3208     done
3209     AD_FILES=`cat adSrcFiles.tmp`
3210     for i in $AD_FILES ; do
3211     basename=${i%%.f}
3212     toBeIgnored=`egrep ^$basename'[ ]*' ${OAD_DONT_COMPILE} ${OAD_DONT_TRANSFORM}`
3213     if test -z "$toBeIgnored" ; then
3214     echo " \\" >> $MAKEFILE
3215     printf " $i" >> $MAKEFILE
3216     fi
3217     done
3218     echo >> $MAKEFILE
3219     rm -f adSrcFiles.tmp
3220    
3221     cat >>$MAKEFILE <<EOF
3222    
3223 jmc 1.206 adAll: \$(EXE_AD)
3224 jmc 1.176 .PHONY: adAll
3225    
3226     CB2M_F90_PP_SRC_FILES=\$(addsuffix _mod.f$FS90, \$(CB2M_F90_SRC_NAMES))
3227    
3228     .PRECIOUS: \$(CB2M_F90_PP_SRC_FILES) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90)
3229    
3230     .PHONY: adDepend
3231     adDepend: \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(addsuffix _mod.FF90, \$(CB2M_F90_SRC_NAMES)) \$(F77_SRC_FILES:.F=_cb2m.FF90)
3232 jmc 1.229 \$(MAKEDEPEND) -f \$(MAKEFILE) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
3233 jmc 1.176 \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
3234     -rm -f makedepend.out
3235    
3236     OPENAD_SUPPORT_F90_SRC_FILES = \
3237     w2f__types.F90 \
3238     OAD_active.F90 \
3239     OAD_cp.F90 \
3240     OAD_rev.F90 \
3241 utke 1.249 OAD_tape.F90 \
3242     revolve.F90
3243 jmc 1.176
3244     OPENAD_SUPPORT_C_SRC_FILES = \
3245     iaddr.c \
3246     timeRatio.c
3247    
3248     f95_test_mods.f90: \$(OPENAD_SUPPORT_F90_SRC_FILES:F90=$FS90)
3249     cat \$^ > \$@
3250    
3251 jmc 1.206 f95_test.f90: all_mods.xb.x2w.w2f.pp.f$FS90 \$(NON_AD_F77_SRC_FILES:.F=_cb2m.f$FS90) ad_input_code.w2f.pre.xb.x2w.w2f.td.pp.f$FS90
3252 jmc 1.176 cat \$^ > \$@
3253    
3254     f95_test.out: f95_test_mods.f90 f95_test.f90
3255     f95 -fixed -w=unused -maxcontin=132 -c f95_test_mods.f90 > \$@ 2>&1
3256     f95 -fixed -w=unused -maxcontin=132 -c -fixed f95_test.f90 >> \$@ 2>&1
3257    
3258 utke 1.235 CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.f$FS90)
3259 utke 1.193
3260 utke 1.235 AD_OBJ_FILES_S1=\$(OPENAD_SUPPORT_F90_SRC_FILES:.F90=.o) \$(OPENAD_SUPPORT_C_SRC_FILES:.c=.o) OAD_intrinsics_oad.o \$(CB2M_AD_FILES:.f$FS90=_oad.o)
3261 utke 1.193
3262     AD_OBJ_FILES_S2=\$(AD_OBJ_FILES_S1) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.o) \$(C_SRC_FILES:.c=.o) \$(F90_SRC_FILES:.F90=.o)
3263    
3264 utke 1.235 \$(EXE_AD): \$(ALL_LINKED_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) postProcess.tag \$(AD_OBJ_FILES_S2)
3265 utke 1.193 \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(AD_OBJ_FILES_S2) \$(LIBS)
3266 jmc 1.176
3267 utke 1.235 # create sources files modules from header files containing common blocks
3268 heimbach 1.242 %_mod.FF90 : %.h \${OADTOOLS}/cb2mGetModules.csh \${OADTOOLS}/cb2mGetModules.awk
3269     \${OADTOOLS}/cb2mGetModules.csh $< \${OADTOOLS}/cb2mGetModules.awk
3270 jmc 1.176
3271 jmc 1.236 # create new header files with USE statements for the new modules made above
3272 heimbach 1.242 %_mod.h : %.h \${OADTOOLS}/cb2mGetHeaders.csh \${OADTOOLS}/cb2mGetHeaders.awk
3273     \${OADTOOLS}/cb2mGetHeaders.csh $< \${OADTOOLS}/cb2mGetHeaders.awk \$(CB2M_F90_SRC_NAMES)
3274 jmc 1.176
3275 utke 1.235 # change the include directives of everybody to refer to the new header files with the USE statements
3276 heimbach 1.242 %_cb2m.FF90 : %.F \${OADTOOLS}/cb2mUseModules.bash
3277     \${OADTOOLS}/cb2mUseModules.bash $< ${MPI}
3278 jmc 1.176
3279     # makefile debug rule
3280     small_f: \$(CB2M_F90_PP_SRC_FILES)
3281     .PHONY: small_f
3282    
3283     ad_output.txt: \$(EXE_AD)
3284     @printf 'linking data files ... '
3285     \$(LN) -f ../input_ad/data* ../input_ad/eedata .
3286     \$(LN) -f ../../global_ocean.90x40x15/input/*.bin .
3287     @printf 'running ... '
3288     @./\$(EXE_AD) > \$@
3289    
3290 utke 1.194 ad_input_code.f$FS90: \$(CB2M_AD_FILES)
3291 jmc 1.176 cat \$^ > \$@
3292    
3293 utke 1.235 # canonicalizer
3294 jmc 1.236 ad_input_code_sf.pre.f90 : \$(CB2M_AD_FILES)
3295 utke 1.235 \${OPENADFORTTK_BASE}/tools/SourceProcessing/preProcess.py --timing --r8 -H -S -o \$@ \$^
3296 jmc 1.176
3297 utke 1.235 # replace stop statements (to avoid the implied unstructured control flow) with print statements
3298     ad_input_code_sf.pre.s2p.f90 : ad_input_code_sf.pre.f90
3299 heimbach 1.242 cat \$< | sed -f \${OADTOOLS}/stop2print.sed > ad_input_code_sf.pre.s2p.f90
3300 jmc 1.176
3301     # F -> WHIRL
3302 utke 1.235 ad_input_code_sf.pre.s2p.B: ad_input_code_sf.pre.s2p.f90
3303     \${OPEN64ROOT}/crayf90/sgi/mfef90 -r8 -z -F ad_input_code_sf.pre.s2p.f90
3304 jmc 1.176
3305     # WHIRL -> XAIF
3306 jmc 1.236 ad_input_code_sf.pre.s2p.xaif : ad_input_code_sf.pre.s2p.B
3307 utke 1.235 \${OPENADFORTTK}/bin/whirl2xaif -s -n --debug 1 -o \$@ \$<
3308 jmc 1.176
3309     # XAIF -> XAIF'
3310 jmc 1.236 ad_input_code_sf.pre.s2p.xb.xaif : ad_input_code_sf.pre.s2p.xaif xaif.xsd xaif_base.xsd xaif_inlinable_intrinsics.xsd xaif_derivative_propagator.xsd xaif_output.xsd
3311 utke 1.235 \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/driver/oadDriver -f -t forward_step -i \$< -c \${XAIFSCHEMAROOT}/schema/examples/inlinable_intrinsics.xaif -o \$@ -I -r
3312 jmc 1.176
3313     # XAIF' -> WHIRL'
3314 jmc 1.236 ad_input_code_sf.pre.s2p.xb.x2w.B : ad_input_code_sf.pre.s2p.xb.xaif
3315 utke 1.235 \${OPENADFORTTK}/bin/xaif2whirl --debug 1 ad_input_code_sf.pre.s2p.B \$<
3316 jmc 1.176
3317     # WHIRL' -> F'
3318 jmc 1.236 ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS90: ad_input_code_sf.pre.s2p.xb.x2w.B
3319 utke 1.235 \${OPEN64ROOT}/whirl2f/whirl2f -FLIST:ftn_file=\$@ -openad \$<
3320 jmc 1.176
3321     # insert template directives
3322 heimbach 1.242 ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90: ad_input_code_sf.pre.s2p.xb.x2w.w2f.f$FS90 \${OADTOOLS}/insertTemplateDir.bash
3323     \${OADTOOLS}/insertTemplateDir.bash \$< \$@
3324 jmc 1.176
3325 heimbach 1.242 PPEXTRAS=\$(wildcard \${OADTOOLS}/ad_template.*.F) \${OADTOOLS}/ad_inline.F
3326 jmc 1.176 # postprocess F'
3327 utke 1.235 postProcess.tag: ad_input_code_sf.pre.s2p.xb.x2w.w2f.td.f$FS90 \$(PPEXTRAS:.F=.f) | w2f__types.f90
3328 heimbach 1.242 \${OPENADFORTTK_BASE}/tools/SourceProcessing/postProcess.py --progress --timing --infoUnitFile w2f__types.f90 --outputFormat=fixed --separateOutput --pathSuffix "" --filenameSuffix "_oad" -m r -i \${OADTOOLS}/ad_inline.f \$<
3329 utke 1.235 # the target is a placeholder to trigger a single execution of the rule
3330 utke 1.193 touch \$@
3331 jmc 1.236 # put this so make knows about the postprocessing output
3332 utke 1.235 OAD_intrinsics_oad.f \$(CB2M_AD_FILES:.f$FS90=_oad.f): postProcess.tag
3333 jmc 1.176
3334 utke 1.235 # link the XAIF schema files
3335 jmc 1.176 %.xsd:
3336     \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ .
3337    
3338     # link the support files:
3339 jmc 1.206 \$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES):
3340 heimbach 1.242 \$(LN) \${OADTOOLS}/\$@ .
3341 jmc 1.176
3342 utke 1.243 AD_CLEAN += *_mod.h *_mod.F90 *.FF90 *.mod-whirl temp.sed oad_cp.* postProcess.tag \$(PPEXTRAS:.F=.f)
3343 utke 1.193
3344 jmc 1.176 # ============ end OpenAD specific section ==============
3345 edhill 1.1
3346     EOF
3347 edhill 1.7
3348 jmc 1.176 fi
3349    
3350     #=========================================
3351    
3352 edhill 1.7 if test "x$EXEHOOK" != x ; then
3353     printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
3354     fi
3355 edhill 1.1
3356     echo " Making list of \"exceptions\" that need \".p\" files"
3357     for i in $KPPFILES ; do
3358     base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
3359     RETVAL=$?
3360     if test "x$RETVAL" != x0 ; then
3361     echo "Error: unable to add file \"$i\" to the exceptions list"
3362     fi
3363 edhill 1.76 echo "$base.$FS: $base.p" >> $MAKEFILE
3364 edhill 1.1 done
3365    
3366     echo " Making list of NOOPTFILES"
3367     for i in $NOOPTFILES ; do
3368     base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
3369     RETVAL=$?
3370     if test "x$RETVAL" != x0 ; then
3371     echo "Error: unable to add file \"$i\" to the exceptions list"
3372     fi
3373 edhill 1.76 echo "$base.o: $base.$FS" >> $MAKEFILE
3374 edhill 1.2 printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
3375 edhill 1.1 done
3376    
3377     echo " Add rules for links"
3378     cat srclinks.tmp >> $MAKEFILE
3379     rm -f srclinks.tmp
3380    
3381     echo " Adding makedepend marker"
3382 edhill 1.2 printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
3383 edhill 1.1
3384 edhill 1.2 printf "\n=== Done ===\n"
3385 adcroft 1.47
3386     # Create special header files
3387 jmc 1.238 $BASH $TOOLSDIR/convert_cpp_cmd2defines -bPACKAGES_CONFIG_H "Disabled packages:" $DISABLED_PACKAGES " " "Enabled packages:" $ENABLED_PACKAGES > $PACKAGES_DOT_H".tmp"
3388 adcroft 1.47 if test ! -f $PACKAGES_DOT_H ; then
3389     mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
3390     else
3391 edhill 1.61 cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
3392 adcroft 1.47 RETVAL=$?
3393     if test "x$RETVAL" = x0 ; then
3394     rm -f $PACKAGES_DOT_H".tmp"
3395     else
3396     mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
3397     mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
3398     fi
3399     fi
3400     if test ! -f AD_CONFIG.h ; then
3401 jmc 1.238 $BASH $TOOLSDIR/convert_cpp_cmd2defines "Default version" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN > AD_CONFIG.h
3402 adcroft 1.47 fi
3403 edhill 1.5
3404     # Write the "state" for future records
3405 jmc 1.211 if test "x$DUMPSTATE" = xt ; then
3406 edhill 1.71 printf "" > genmake_state
3407 edhill 1.5 for i in $gm_state ; do
3408     t1="t2=\$$i"
3409     eval $t1
3410 jmc 1.222 echo "$i='$t2'" | sed -e 's/ */ /g' >> genmake_state
3411 edhill 1.5 done
3412     fi

  ViewVC Help
Powered by ViewVC 1.1.22