/[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.237 - (hide annotations) (download)
Fri Aug 24 23:41:17 2012 UTC (11 years, 7 months ago) by jmc
Branch: MAIN
Changes since 1.236: +93 -91 lines
- fix option '-makefile' short-name (-mf according to genmake2 -help)
- source local config file "genmake_local" just after processing the genmake2
  command arguments (previously done before processing arg).

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

  ViewVC Help
Powered by ViewVC 1.1.22