/[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.281 - (hide annotations) (download)
Thu Feb 16 23:27:08 2017 UTC (7 years, 1 month ago) by jmc
Branch: MAIN
CVS Tags: checkpoint66e
Changes since 1.280: +3 -3 lines
use "expr" instead of "bc -l" (that was used only in one place)

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

  ViewVC Help
Powered by ViewVC 1.1.22