/[MITgcm]/MITgcm/tools/genmake2
ViewVC logotype

Contents of /MITgcm/tools/genmake2

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.136 - (show annotations) (download)
Thu Nov 24 17:52:15 2005 UTC (13 years, 11 months ago) by edhill
Branch: MAIN
Changes since 1.135: +13 -5 lines
 o small cleanup of the default-compiler-selection code

1 #! /usr/bin/env bash
2 #
3 # $Header: /u/gcmpack/MITgcm/tools/genmake2,v 1.135 2005/11/17 20:06:08 edhill Exp $
4 #
5 # Makefile generator for MITgcm UV codes
6 # created by cnh 03/98
7 # adapted by aja 06/98
8 # modified by aja 01/00
9 # rewritten in bash by eh3 08/03
10
11 # Search for particular CPP #cmds associated with packages
12 # usage: test_for_package_in_cpp_options CPP_file package_name
13 test_for_package_in_cpp_options() {
14 cpp_options=$1
15 pkg=$2
16 test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_$pkg" || exit 99
17 test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_$pkg" || exit 99
18 test_for_string_in_file $cpp_options "^[ ]*#define.*DISABLE_$pkg" || exit 99
19 test_for_string_in_file $cpp_options "^[ ]*#undef.*DISABLE_$pkg" || exit 99
20 }
21
22 # Search for particular CPP #cmds associated with MPI
23 # usage: test_for_mpi_in_cpp_eeoptions CPP_file
24 test_for_mpi_in_cpp_eeoptions() {
25 cpp_options=$1
26 test_for_string_in_file $cpp_options "^[ ]*#define.*ALLOW_USE_MPI" || exit 99
27 test_for_string_in_file $cpp_options "^[ ]*#undef.*ALLOW_USE_MPI" || exit 99
28 test_for_string_in_file $cpp_options "^[ ]*#define.*ALWAYS_USE_MPI" || exit 99
29 test_for_string_in_file $cpp_options "^[ ]*#undef.*ALWAYS_USE_MPI" || exit 99
30 }
31
32 # Search for particular string in a file. Return 1 if detected, 0 if not
33 # usage: test_for_string_in_file file string
34 test_for_string_in_file() {
35 file=$1
36 strng=$2
37 grep -i "$strng" $file > /dev/null 2>&1
38 RETVAL=$?
39 if test "x${RETVAL}" = x0 ; then
40 printf "Error: In $file there is an illegal line: "
41 grep -i "$strng" $file
42 return 1
43 fi
44 return 0
45 }
46
47 # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to
48 # the package list.
49 expand_pkg_groups() {
50 new_packages=
51 PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"
52 if test -r $PKG_GROUPS ; then
53 cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp
54 cat ./p1.tmp | $AWK '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp
55 matched=0
56 for i in $PACKAGES ; do
57 line=`grep "^ *$i" ./p2.tmp`
58 RETVAL=$?
59 if test "x$RETVAL" = x0 ; then
60 matched=1
61 replace=`echo $line | $AWK '{ $1=""; $2=""; print $0 }'`
62 echo " replacing \"$i\" with: $replace"
63 new_packages="$new_packages $replace"
64 else
65 new_packages="$new_packages $i"
66 fi
67 done
68 PACKAGES=$new_packages
69 rm -f ./p[1,2].tmp
70 return $matched
71 else
72 echo "Warning: can't read package groups definition file: $PKG_GROUPS"
73 fi
74 }
75
76 # Check for broken environments (eg. cygwin, MacOSX w/HFS+) that
77 # cannot distinguish [*.F/*.F90] from [*.f/*.f90] files.
78 check_for_broken_Ff() {
79 # Do we have defaults for $FS and/or $FS90 ?
80 tfs=f
81 tfs9=f90
82 if test "x$FS" != x ; then
83 tfs="$FS"
84 fi
85 if test "x$FS90" != x ; then
86 tfs9="$FS90"
87 fi
88
89 # First check the ability to create a *.F/.f pair.
90 cat <<EOF >> genmake_hello.F
91 program hello
92 write(*,*) 'hi'
93 stop
94 end
95 EOF
96 cp genmake_hello.F "genmake_hello."$tfs > /dev/null 2>&1
97 RETVAL=$?
98 if test "x$RETVAL" != x0 ; then
99 if test "x$FS" = x ; then
100 FS='for'
101 FS90='fr9'
102 check_for_broken_Ff
103 else
104 cat <<EOF 2>&1
105 ERROR: Your file system cannot distinguish between *.F and *.f files
106 (fails the "cp" test) and this program cannot find a suitable
107 replacement extension. Please try a different build environment or
108 contact the <MITgcm-support@mitgcm.org> list for help.
109
110 EOF
111 exit -1
112 fi
113 return
114 fi
115 rm -f genmake_hello.*
116
117 # Check the ability of ${MAKE} and ${LN} to use the current set
118 # of extensions.
119 cat <<EOF >> genmake_hello.F
120 program hello
121 write(*,*) 'hi'
122 stop
123 end
124 EOF
125 test -f $MAKEFILE && mv -f $MAKEFILE $MAKEFILE".tst"
126 cat <<EOF >> $MAKEFILE
127 .SUFFIXES:
128 .SUFFIXES: .$tfs .F
129 .F.$tfs:
130 $LN \$< \$@
131 EOF
132 $MAKE "genmake_hello."$tfs > /dev/null 2>&1
133 RETVAL=$?
134 if test "x$RETVAL" != x0 -o ! -f "genmake_hello."$tfs ; then
135 if test "x$FS" = x ; then
136 FS='for'
137 FS90='fr9'
138 check_for_broken_Ff
139 else
140 cat <<EOF 2>&1
141 ERROR: Your file system cannot distinguish between *.F and *.f files
142 (fails the "make/ln" test) and this program cannot find a suitable
143 replacement extension. Please try a different build environment or
144 contact the <MITgcm-support@mitgcm.org> list for help.
145
146 EOF
147 exit -1
148 return
149 fi
150 fi
151 rm -f genmake_hello.* $MAKEFILE
152 test -f $MAKEFILE".tst" && mv -f $MAKEFILE".tst" $MAKEFILE
153
154 # If we make it here, use the extensions
155 FS=$tfs
156 FS90=$tfs9
157 return
158 }
159
160
161 look_for_makedepend() {
162
163 # The "original" makedepend is part of the Imake system that is
164 # most often distributed with XFree86 or with an XFree86 source
165 # package. As a result, many machines (eg. generic Linux) do not
166 # have a system-default "makedepend" available. For those
167 # systems, we have two fall-back options:
168 #
169 # 1) a makedepend implementation shipped with the cyrus-imapd
170 # package: ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/
171 #
172 # 2) a known-buggy xmakedpend shell script
173 #
174 # So the choices are, in order:
175 #
176 # 1) use the user-specified program
177 # 2) use a system-wide default
178 # 3) locally build and use the cyrus implementation
179 # 4) fall back to the buggy local xmakedpend script
180 #
181 if test "x${MAKEDEPEND}" = x ; then
182 which makedepend > /dev/null 2>&1
183 RV0=$?
184 test -f $MAKEFILE && mv -f $MAKEFILE $MAKEFILE".tst"
185 # echo 'MAKEFILE="'$MAKEFILE'"'
186 cat <<EOF >> $MAKEFILE
187 # THIS IS A TEST MAKEFILE GENERATED BY "genmake2"
188 #
189 # Some "makedepend" implementations will die if they cannot
190 # find a Makefile -- so this file is here to gives them an
191 # empty one to find and parse.
192 EOF
193 cat <<EOF >> genmake_tc.f
194 program test
195 write(*,*) 'test'
196 stop
197 end
198 EOF
199 makedepend genmake_tc.f > /dev/null 2>&1
200 RV1=$?
201 test -f $MAKEFILE && rm -f $MAKEFILE
202 test -f $MAKEFILE".tst" && mv -f $MAKEFILE".tst" $MAKEFILE
203 if test "x${RV0}${RV1}" = x00 ; then
204 MAKEDEPEND=makedepend
205 else
206 echo " a system-default makedepend was not found."
207
208 # Try to build the cyrus implementation
209 build_cyrus_makedepend
210 RETVAL=$?
211 if test "x$RETVAL" != x0 ; then
212 MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
213 fi
214 rm -f ./genmake_cy_md
215 fi
216 else
217 # echo "MAKEDEPEND=${MAKEDEPEND}"
218 echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1
219 RETVAL=$?
220 if test x"$RETVAL" = x0 ; then
221 build_cyrus_makedepend
222 fi
223 fi
224 }
225
226
227 build_cyrus_makedepend() {
228 rm -f ./genmake_cy_md
229 (
230 cd $ROOTDIR/tools/cyrus-imapd-makedepend \
231 && ./configure > /dev/null 2>&1 \
232 && make > /dev/null 2>&1
233 if test -x ./makedepend.exe ; then
234 $LN ./makedepend.exe ./makedepend
235 fi
236 ./makedepend ifparser.c > /dev/null 2>&1 \
237 && echo "true"
238 ) > ./genmake_cy_md
239 grep true ./genmake_cy_md > /dev/null 2>&1
240 RETVAL=$?
241 rm -f ./genmake_cy_md
242 if test "x$RETVAL" = x0 ; then
243 MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend'
244 return 0
245 else
246 echo "WARNING: unable to build cyrus-imapd-makedepend"
247 return 1
248 fi
249 }
250
251 # Guess possible config options for this host
252 find_possible_configs() {
253
254 tmp1=`uname`"_"`uname -m`
255 tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
256 tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
257 tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'`
258 tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
259 tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'`
260 PLATFORM=$tmp3
261 echo $PLATFORM | grep cygwin > /dev/null 2>&1 && PLATFORM=cygwin_ia32
262 OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
263 echo " The platform appears to be: $PLATFORM"
264
265 echo "test" > test
266 ln -s ./test link
267 RETVAL=$?
268 if test "x${RETVAL}" = x0 ; then
269 LN="ln -s"
270 else
271 echo "Error: \"ln -s\" does not appear to work on this system!"
272 echo " For help, please contact <MITgcm-support@mitgcm.org>."
273 exit 1
274 fi
275 rm -f test link
276
277 if test "x$CPP" = x ; then
278 CPP="cpp -traditional -P"
279 fi
280
281 look_for_makedepend
282
283 #================================================================
284 # look for possible C compilers
285 tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc"
286 p_CC=
287 for c in $tmp ; do
288 rm -f ./genmake_hello.c ./genmake_hello
289 cat >> genmake_hello.c << EOF
290 #include <stdio.h>
291 int main(int argc, char **argv) {
292 printf("Hello!\n");
293 return 0;
294 }
295 EOF
296 $c -o genmake_hello genmake_hello.c > /dev/null 2>&1
297 RETVAL=$?
298 if test "x${RETVAL}" = x0 ; then
299 p_CC="$p_CC $c"
300 fi
301 done
302 rm -f ./genmake_hello.c ./genmake_hello
303 if test "x${p_CC}" = x ; then
304 cat 1>&2 <<EOF
305
306 Error: No C compilers were found in your path. Please specify one using:
307
308 1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
309 2) the CC or MITGCM_CC environment variables.
310
311 EOF
312 exit 1
313 else
314 echo " The possible C compilers found in your path are:"
315 echo " "$p_CC
316 if test "x$CC" = x ; then
317 CC=`echo $p_CC | $AWK '{print $1}'`
318 echo " Setting C compiler to: "$CC
319 fi
320 fi
321
322 #================================================================
323 # look for possible FORTRAN compilers
324 tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 gfortran"
325 p_FC=
326 for c in $tmp ; do
327 rm -f ./hello.f ./hello
328 cat >> hello.f <<EOF
329 program hello
330 do i=1,3
331 print *, 'hello world : ', i
332 enddo
333 end
334 EOF
335 $c -o hello hello.f > /dev/null 2>&1
336 RETVAL=$?
337 if test "x${RETVAL}" = x0 ; then
338 p_FC="$p_FC $c"
339 fi
340 done
341 rm -f ./hello.f ./hello
342 if test "x${p_FC}" = x ; then
343 cat 1>&2 <<EOF
344
345 Error: No Fortran compilers were found in your path. Please specify one using:
346
347 1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
348 2) a command-line option (eg. "-fc NAME"), or
349 3) the FC or MITGCM_FC environment variables.
350
351 EOF
352 exit 1
353 else
354 echo " The possible FORTRAN compilers found in your path are:"
355 echo " "$p_FC
356 fi
357
358 # Use the first of the compilers found in the current PATH
359 # that has a correctly-named optfile
360 if test "x$OPTFILE" = x -a "x$FC" = x ; then
361 for i in $p_FC ; do
362 OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
363 if test -r $OPTFILE ; then
364 echo " Setting OPTFILE to: "$OPTFILE
365 break
366 fi
367 done
368 fi
369
370 if test "x$OPTFILE" = x ; then
371 OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
372 if test ! -r $OPTFILE ; then
373 echo " I looked for the file "$OPTFILE" but did not find it"
374 fi
375 fi
376 # echo " The options file: $p_OF"
377 # echo " appears to match so we'll use it."
378 # for i in $p_FC ; do
379 #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
380 #if test -r $p_OF ; then
381 # OPTFILE=$p_OF
382 # echo " The options file: $p_OF"
383 # echo " appears to match so we'll use it."
384 # break
385 #fi
386 # done
387 if test "x$OPTFILE" = x ; then
388 cat 1>&2 <<EOF
389
390 Error: No options file was found in: $ROOTDIR/tools/build_options/
391 that matches this platform ("$PLATFORM") and the compilers found in
392 your path. Please specify an "optfile" using:
393
394 1) the command line (eg. "-optfile=path/to/OPTFILE"), or
395 2) the MITGCM_OF environment variable.
396
397 If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
398
399 EOF
400 exit 1
401 fi
402
403 # # look for possible MPI libraries
404 # mpi_libs=
405 # mpi_fort=`which mpif77 2>/dev/null`
406 # RETVAL=$?
407 # if test "x${RETVAL}" = x0 ; then
408 # cat >>test.f <<EOF
409 # PROGRAM HELLO
410 # DO 10, I=1,10
411 # PRINT *,'Hello World'
412 # 10 CONTINUE
413 # STOP
414 # END
415 # EOF
416 # eval "$mpi_fort -showme test.f > out"
417 # RETVAL=$?
418 # if test "x${RETVAL}" = x0 ; then
419 # a=`cat out`
420 # for i in $a ; do
421 # case $i in
422 # -*)
423 # mpi_libs="$mpi_libs $i" ;;
424 # esac
425 # done
426 # echo "The MPI libs appear to be:"
427 # echo " "$mpi_libs
428 # fi
429 # rm -f test.f out
430 # fi
431
432 }
433
434 # Parse the package dependency information
435 get_pdepend_list() {
436
437 # strip the comments and then convert the dependency file into
438 # two arrays: PNAME, DNAME
439 cat $1 | sed -e 's/#.*$//g' \
440 | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \
441 > ./.pd_tmp
442 . ./.pd_tmp
443 rm -f ./.pd_tmp
444
445 printf "PNAME = "${}
446 }
447
448
449 # Explain usage
450 usage() {
451 cat <<EOF
452
453 Usage: "$0" [OPTIONS]
454 where [OPTIONS] can be:
455
456 -help | --help | -h | --h
457 Print this help message and exit.
458
459 -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
460 -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
461 Use "NAME" as the adoptfile. By default, the file at
462 "tools/adjoint_options/adjoint_default" will be used.
463
464 -nooptfile | --nooptfile
465 -optfile NAME | --optfile NAME | -of NAME | --of NAME
466 -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
467 Use "NAME" as the optfile. By default, an attempt will be
468 made to find an appropriate "standard" optfile in the
469 tools/build_options/ directory.
470
471 -pdepend NAME | --pdepend NAME
472 -pdepend=NAME | --pdepend=NAME
473 Get package dependency information from "NAME".
474
475 -pdefault NAME | --pdefault NAME
476 -pdefault=NAME | --pdefault=NAME
477 Get the default package list from "NAME".
478
479 -make NAME | -m NAME
480 --make=NAME | -m=NAME
481 Use "NAME" for the MAKE program. The default is "make" but
482 many platforms, "gmake" is the preferred choice.
483
484 -makefile NAME | -mf NAME
485 --makefile=NAME | -mf=NAME
486 Call the makefile "NAME". The default is "Makefile".
487
488 -makedepend NAME | -md NAME
489 --makedepend=NAME | -md=NAME
490 Use "NAME" for the MAKEDEPEND program.
491
492 -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
493 -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
494 Specify the location of the MITgcm ROOTDIR as "NAME".
495 By default, genamke will try to find the location by
496 looking in parent directories (up to the 5th parent).
497
498 -mods NAME | --mods NAME | -mo NAME | --mo NAME
499 -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
500 Here, "NAME" specifies a list of directories that are
501 used for additional source code. Files found in the
502 "mods list" are given preference over files of the same
503 name found elsewhere.
504
505 -disable NAME | --disable NAME
506 -disable=NAME | --disable=NAME
507 Here "NAME" specifies a list of packages that we don't
508 want to use. If this violates package dependencies,
509 genamke will exit with an error message.
510
511 -enable NAME | --enable NAME
512 -enable=NAME | --enable=NAME
513 Here "NAME" specifies a list of packages that we wish
514 to specifically enable. If this violates package
515 dependencies, genamke will exit with an error message.
516
517 -standarddirs NAME | --standarddirs NAME
518 -standarddirs=NAME | --standarddirs=NAME
519 Here, "NAME" specifies a list of directories to be
520 used as the "standard" code.
521
522 -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
523 -fc=NAME | --fc=NAME
524 Use "NAME" as the fortran compiler. By default, genmake
525 will search for a working compiler by trying a list of
526 "usual suspects" such as g77, f77, etc.
527
528 -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
529 Use "NAME" as the C compiler. By default, genmake
530 will search for a working compiler by trying a list of
531 "usual suspects" such as gcc, c89, cc, etc.
532
533 -[no]ieee | --[no]ieee
534 Do or don't use IEEE numerics. Note that this option
535 *only* works if it is supported by the OPTFILE that
536 is being used.
537
538 -ts | --ts
539 Produce timing information per timestep
540
541 -mpi | --mpi
542 Include MPI header files and link to MPI libraries
543 -mpi=PATH | --mpi=PATH
544 Include MPI header files and link to MPI libraries using MPI_ROOT
545 set to PATH. i.e. Include files from \$PATH/include, link to libraries
546 from \$PATH/lib and use binaries from \$PATH/bin.
547
548 -bash NAME
549 Explicitly specify the Bourne or BASH shell to use
550
551 While it is most often a single word, the "NAME" variables specified
552 above can in many cases be a space-delimited string such as:
553
554 --enable pkg1 --enable 'pkg1 pkg2' --enable 'pkg1 pkg2 pkg3'
555 -mods=dir1 -mods='dir1' -mods='dir1 dir2 dir3'
556 -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
557
558 which, depending upon your shell, may need to be single-quoted.
559
560 For more detailed genmake documentation, please see:
561
562 http://mitgcm.org/devel_HOWTO/
563
564 EOF
565
566 exit 1
567 }
568
569 # Build a CPP macro to automate calling C routines from FORTRAN
570 get_fortran_c_namemangling() {
571
572 #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
573 if test ! "x$FC_NAMEMANGLE" = x ; then
574 return 0
575 fi
576
577 default_nm="#define FC_NAMEMANGLE(X) X ## _"
578
579 cat > genmake_test.c <<EOF
580 void tcall( char * string ) { tsub( string ); }
581 EOF
582 $MAKE genmake_test.o >> genmake_warnings 2>&1
583 RETVAL=$?
584 if test "x$RETVAL" != x0 ; then
585 FC_NAMEMANGLE=$default_nm
586 cat <<EOF>> genmake_errors
587
588 WARNING: C test compile fails
589 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
590 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
591 EOF
592 return 1
593 fi
594 c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
595 RETVAL=$?
596 if test "x$RETVAL" != x0 ; then
597 FC_NAMEMANGLE=$default_nm
598 cat <<EOF>> genmake_warnings
599
600 WARNING: The "nm" command failed.
601 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
602 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
603 EOF
604 return 1
605 fi
606 cat > genmake_tcomp.$FS <<EOF
607 subroutine tcall( string )
608 character*(*) string
609 call tsub( string )
610 end
611 EOF
612 $FC $FFLAGS -c genmake_tcomp.$FS >> genmake_warnings 2>&1
613 RETVAL=$?
614 if test "x$RETVAL" != x0 ; then
615 FC_NAMEMANGLE=$default_nm
616 cat <<EOF>> genmake_warnings
617
618 WARNING: FORTRAN test compile fails -- please see "genmake_errors"
619 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
620 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
621 EOF
622 return 1
623 fi
624 f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
625 RETVAL=$?
626 if test "x$RETVAL" != x0 ; then
627 FC_NAMEMANGLE=$default_nm
628 cat <<EOF>> genmake_warnings
629
630 WARNING: The "nm" command failed.
631 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
632 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
633 EOF
634 return 1
635 fi
636
637 c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
638 f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
639 c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
640 f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
641
642 nmangle="X"
643 if test "x$c_a" != "x$f_a" ; then
644 comm="echo x$f_a | sed -e 's|x$c_a||'"
645 a=`eval $comm`
646 nmangle="$a ## $nmangle"
647 fi
648 if test "x$c_b" != "x$f_b" ; then
649 comm="echo x$f_b | sed -e 's|x$c_b||'"
650 b=`eval $comm`
651 nmangle="$nmangle ## $b"
652 fi
653
654 FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) $nmangle"
655
656 # cleanup the testing files
657 rm -f genmake_tcomp.* genmake_test.*
658 }
659
660
661 check_HAVE_CLOC() {
662 get_fortran_c_namemangling
663 cat <<EOF > genmake_tc_1.c
664 $FC_NAMEMANGLE
665 #include <stdio.h>
666 #include <stdlib.h>
667 #include <unistd.h>
668 #include <assert.h>
669 #include <sys/time.h>
670 void FC_NAMEMANGLE(cloc) ( double *curtim )
671 {
672 struct timeval tv1;
673 gettimeofday(&tv1 , (void *)NULL );
674 *curtim = (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
675 *curtim = *curtim/1.E6;
676 }
677 EOF
678 make genmake_tc_1.o >> genmake_warnings 2>&1
679 RET_C=$?
680 cat <<EOF > genmake_tc_2.$FS
681 program hello
682 REAL*8 wtime
683 external cloc
684 call cloc(wtime)
685 print *," HELLO WORLD", wtime
686 end
687 EOF
688 $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1
689 RET_F=$?
690 test -x ./genmake_tc && ./genmake_tc >> genmake_warnings 2>&1
691 RETVAL=$?
692 if test "x$RETVAL" = x0 ; then
693 HAVE_CLOC=t
694 DEFINES="$DEFINES -DHAVE_CLOC"
695 fi
696 rm -f genmake_tc*
697 }
698
699
700 check_HAVE_SETRLSTK() {
701 get_fortran_c_namemangling
702 cat <<EOF > genmake_tc_1.c
703 $FC_NAMEMANGLE
704 #include <sys/time.h>
705 #include <sys/resource.h>
706 #include <unistd.h>
707 void FC_NAMEMANGLE(setrlstk) ()
708 {
709 struct rlimit rls;
710 rls.rlim_cur = RLIM_INFINITY;
711 rls.rlim_max = RLIM_INFINITY;
712 setrlimit(RLIMIT_STACK, &rls);
713 return;
714 }
715 EOF
716 make genmake_tc_1.o >> genmake_warnings 2>&1
717 RET_C=$?
718 cat <<EOF > genmake_tc_2.$FS
719 program hello
720 external setrlstk
721 call setrlstk()
722 end
723 EOF
724 echo >> genmake_warnings
725 echo "running: check_HAVE_SETRLSTK()" >> genmake_warnings
726 cat genmake_tc_2.$FS >> genmake_warnings
727 COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
728 echo $COMM >> genmake_warnings
729 $COMM >> genmake_warnings 2>&1
730 RETVAL=$?
731 if test "x$RETVAL" = x0 ; then
732 HAVE_SETRLSTK=t
733 DEFINES="$DEFINES -DHAVE_SETRLSTK"
734 fi
735 rm -f genmake_tc*
736 }
737
738
739 check_HAVE_STAT() {
740 get_fortran_c_namemangling
741 cat <<EOF > genmake_tc_1.c
742 $FC_NAMEMANGLE
743 #include <stdio.h>
744 #include <stdlib.h>
745 #include <unistd.h>
746 #include <sys/stat.h>
747 #include <sys/types.h>
748 void FC_NAMEMANGLE(tfsize) ( int *nbyte )
749 {
750 char name[512];
751 struct stat astat;
752
753 name[0] = 'a'; name[1] = '\0';
754 if (! stat(name, &astat))
755 *nbyte = (int)(astat.st_size);
756 else
757 *nbyte = -1;
758 }
759 EOF
760 make genmake_tc_1.o >> genmake_tc.log 2>&1
761 RET_C=$?
762 cat <<EOF > genmake_tc_2.$FS
763 program hello
764 integer nbyte
765 call tfsize(nbyte)
766 print *," HELLO WORLD", nbyte
767 end
768 EOF
769 echo >> genmake_warnings
770 echo "running: check_HAVE_STAT()" >> genmake_warnings
771 cat genmake_tc_2.$FS >> genmake_warnings
772 COMM="$FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o"
773 echo $COMM >> genmake_warnings
774 $COMM >> genmake_tc.log 2>&1
775 RETVAL=$?
776 if test "x$RETVAL" = x0 ; then
777 HAVE_STAT=t
778 DEFINES="$DEFINES -DHAVE_STAT"
779 fi
780 rm -f genmake_tc*
781 }
782
783
784 check_netcdf_libs() {
785 if test ! "x$SKIP_NETCDF_CHECK" = x ; then
786 return
787 fi
788 echo >> genmake_warnings
789 echo "running: check_netcdf_libs()" >> genmake_warnings
790 cat <<EOF > genmake_tnc.F
791 program fgennc
792 #include "netcdf.inc"
793 EOF
794 if test ! "x$MPI" = x ; then
795 echo '#include "mpif.h"' >> genmake_tnc.F
796 fi
797 cat <<EOF >> genmake_tnc.F
798 integer iret, ncid, xid
799 iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
800 IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
801 iret = nf_def_dim(ncid, 'X', 11, xid)
802 IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
803 iret = nf_close(ncid)
804 IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
805 end
806 EOF
807 echo "=== genmake_tnc.F ===" > genmake_tnc.log
808 cat genmake_tnc.F >> genmake_tnc.log
809 echo "=== genmake_tnc.F ===" >> genmake_tnc.log
810 RET_CPP=f
811 COMM="$CPP $DEFINES $INCLUDES genmake_tnc.F"
812 echo "$COMM" >> genmake_tnc.log
813 $COMM > genmake_tnc.$FS 2>/dev/null && RET_CPP=t
814 if test "x$RET_CPP" = xf ; then
815 echo " WARNING: CPP failed to pre-process the netcdf test." \
816 >> genmake_tnc.log
817 echo " Please check that \$INCLUDES is properly set." \
818 >> genmake_tnc.log
819 fi
820 echo "$FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
821 echo " && $LINK -o genmake_tnc.o $LIBS" >> genmake_tnc.log
822 $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \
823 && $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
824 RET_COMPILE=$?
825 cat genmake_tnc.log >> genmake_warnings
826
827 #EH3 Remove test program execution for machines that either disallow
828 #EH3 execution or cannot support it (eg. cross-compilers)
829 #EH3
830 #EH3 test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1
831 #EH3 RETVAL=$?
832 #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
833
834 if test "x$RET_COMPILE" = x0 ; then
835 HAVE_NETCDF=t
836 else
837 # try again with "-lnetcdf" added to the libs
838 echo "try again with added '-lnetcdf'" > genmake_tnc.log
839 echo "$CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS \ " >> genmake_tnc.log
840 echo " && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS \ " >> genmake_tnc.log
841 echo " && $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf" >> genmake_tnc.log
842 $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null \
843 && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \
844 && $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
845 RET_COMPILE=$?
846 cat genmake_tnc.log >> genmake_warnings
847 if test "x$RET_COMPILE" = x0 ; then
848 LIBS="$LIBS -lnetcdf"
849 HAVE_NETCDF=t
850 fi
851 fi
852 rm -f genmake_tnc*
853 }
854
855
856
857 ###############################################################################
858 # Sequential part of script starts here
859 ###############################################################################
860
861 # Set defaults here
862 COMMANDL="$0 $@"
863
864 PLATFORM=
865 LN=
866 S64=
867 KPP=
868 #FC=
869 #CC=gcc
870 #CPP=
871 LINK=
872 DEFINES=
873 PACKAGES=
874 ENABLE=
875 DISABLE=
876 # MAKEFILE=
877 # MAKEDEPEND=
878 PDEPEND=
879 DUMPSTATE=t
880 PDEFAULT=
881 OPTFILE=
882 INCLUDES="-I. $INCLUDES"
883 FFLAGS=
884 FOPTIM=
885 CFLAGS=
886 KFLAGS1=
887 KFLAGS2=
888 #LDADD=
889 LIBS=
890 KPPFILES=
891 NOOPTFILES=
892 NOOPTFLAGS=
893 MPI=
894 MPIPATH=
895 TS=
896 HAVE_TEST_L=
897
898 # DEFINES checked by test compilation or command-line
899 HAVE_SYSTEM=
900 HAVE_FDATE=
901 FC_NAMEMANGLE=
902 HAVE_CLOC=
903 HAVE_SETRLSTK=
904 HAVE_STAT=
905 HAVE_NETCDF=
906 HAVE_ETIME=
907 IGNORE_TIME=
908
909 MODS=
910 TOOLSDIR=
911 SOURCEDIRS=
912 INCLUDEDIRS=
913 STANDARDDIRS="USE_THE_DEFAULT"
914
915 G2ARGS=
916 BASH=
917 PWD=`pwd`
918 test "x$MAKE" = x && MAKE=make
919 test "x$AWK" = x && AWK=awk
920 THISHOST=`hostname`
921 THISCWD=`pwd`
922 THISDATE=`date`
923 THISUSER=`echo $USER`
924 THISVER=
925 MACHINE=`uname -a`
926 EXECUTABLE=
927 EXEHOOK=
928 EXEDIR=
929 PACKAGES_CONF=
930 IEEE=
931 if test "x$MITGCM_IEEE" != x ; then
932 IEEE=$MITGCM_IEEE
933 fi
934 FS=
935 FS90=
936
937 AUTODIFF_PKG_USED=f
938 AD_OPTFILE=
939 TAF=
940 AD_TAF_FLAGS=
941 FTL_TAF_FLAGS=
942 SVD_TAF_FLAGS=
943 TAF_EXTRA=
944 TAMC=
945 AD_TAMC_FLAGS=
946 FTL_TAF_FLAGS=
947 SVD_TAMC_FLAGS=
948 TAMC_EXTRA=
949
950
951 # The following state can be set directly by command-line switches
952 gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
953 gm_s2="FC CPP IEEE TS MPI JAM DUMPSTATE STANDARDDIRS"
954
955 # The following state is not directly set by command-line switches
956 gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
957 gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
958 gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE"
959 gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
960 gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"
961
962 # The following are all related to adjoint/tangent-linear stuff
963 gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
964 gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
965 gm_s12="TAF_EXTRA TAMC_EXTRA"
966
967 gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
968 gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
969
970 cat <<EOF
971
972 GENMAKE :
973
974 A program for GENerating MAKEfiles for the MITgcm project. For a
975 quick list of options, use "genmake -h" or for more detail see:
976
977 http://mitgcm.org/devel_HOWTO/
978
979 EOF
980
981 echo "=== Processing options files and arguments ==="
982 gm_local="genmake_local"
983 for i in . $MODS ; do
984 if test -r $i/$gm_local ; then
985 . $i/$gm_local
986 break
987 fi
988 done
989 printf " getting local config information: "
990 if test -f $gm_local ; then
991 echo "using $gm_local"
992 . $gm_local
993 # echo "DISABLE=$DISABLE"
994 # echo "ENABLE=$ENABLE"
995 else
996 echo "none found"
997 fi
998
999 #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
1000 #OPTIONS=
1001 #n=0
1002 #for i ; do
1003 # echo "$i $n"
1004 # setvar="OPTIONS[$n]='$i'"
1005 # # echo " $setvar"
1006 # eval "$setvar"
1007 # n=$(( $n + 1 ))
1008 #done
1009 #parse_options
1010 ac_prev=
1011 for ac_option in "$@" ; do
1012
1013 G2ARGS="$G2ARGS \"$ac_option\""
1014
1015 # If the previous option needs an argument, assign it.
1016 if test -n "$ac_prev"; then
1017 eval "$ac_prev=\$ac_option"
1018 ac_prev=
1019 continue
1020 fi
1021
1022 ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
1023
1024 case $ac_option in
1025
1026 -help | --help | -h | --h)
1027 usage ;;
1028
1029 -nooptfile | --nooptfile)
1030 OPTFILE="NONE" ;;
1031 -optfile | --optfile | -of | --of)
1032 ac_prev=OPTFILE ;;
1033 -optfile=* | --optfile=* | -of=* | --of=*)
1034 OPTFILE=$ac_optarg ;;
1035
1036 -adoptfile | --adoptfile | -adof | --adof)
1037 ac_prev=AD_OPTFILE ;;
1038 -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
1039 AD_OPTFILE=$ac_optarg ;;
1040
1041 -pdepend | --pdepend)
1042 ac_prev=PDEPEND ;;
1043 -pdepend=* | --pdepend=*)
1044 PDEPEND=$ac_optarg ;;
1045
1046 -pdefault | --pdefault)
1047 ac_prev=PDEFAULT ;;
1048 -pdefault=* | --pdefault=*)
1049 PDEFAULT=$ac_optarg ;;
1050
1051 -make | --make | -m | --m)
1052 ac_prev=MAKE ;;
1053 -make=* | --make=* | -m=* | --m=*)
1054 MAKE=$ac_optarg ;;
1055
1056 -bash | --bash)
1057 ac_prev=BASH ;;
1058 -bash=* | --bash=*)
1059 BASH=$ac_optarg ;;
1060
1061 -makedepend | --makedepend | -md | --md)
1062 ac_prev=MAKEDEPEND ;;
1063 -makedepend=* | --makedepend=* | -md=* | --md=*)
1064 MAKEDEPEND=$ac_optarg ;;
1065
1066 -makefile | --makefile | -ma | --ma)
1067 ac_prev=MAKEFILE ;;
1068 -makefile=* | --makefile=* | -ma=* | --ma=*)
1069 MAKEFILE=$ac_optarg ;;
1070
1071 -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1072 echo "ERROR: The platform option has been removed. Please specify"
1073 echo " the build options using the \"optfile\" mechanism."
1074 echo
1075 usage
1076 ;;
1077
1078 -rootdir | --rootdir | -rd | --rd)
1079 ac_prev=ROOTDIR ;;
1080 -rootdir=* | --rootdir=* | -rd=* | --rd=*)
1081 ROOTDIR=$ac_optarg ;;
1082
1083 -mods | --mods | -mo | --mo)
1084 ac_prev=MODS ;;
1085 -mods=* | --mods=* | -mo=* | --mo=*)
1086 MODS=$ac_optarg ;;
1087
1088 -disable | --disable)
1089 ac_prev=DISABLE ;;
1090 -disable=* | --disable=*)
1091 DISABLE=$ac_optarg ;;
1092
1093 -enable | --enable)
1094 ac_prev=ENABLE ;;
1095 -enable=* | --enable=*)
1096 ENABLE=$ac_optarg ;;
1097
1098 -standarddirs | --standarddirs)
1099 ac_prev=STANDARDDIRS ;;
1100 -standarddirs=* | --standarddirs=*)
1101 STANDARDDIRS=$ac_optarg ;;
1102
1103 # -cpp | --cpp)
1104 # ac_prev=cpp ;;
1105 # -cpp=* | --cpp=*)
1106 # CPP=$ac_optarg ;;
1107
1108 -cc | --cc)
1109 ac_prev=CC ;;
1110 -cc=* | --cc=*)
1111 CC=$ac_optarg ;;
1112
1113 -fortran | --fortran | -fc | --fc)
1114 ac_prev=FC ;;
1115 -fc=* | --fc=*)
1116 FC=$ac_optarg ;;
1117
1118 -fs | --fs)
1119 ac_prev=FS ;;
1120 -fs=* | --fs=*)
1121 FS=$ac_optarg ;;
1122
1123 -fs90 | --fs90)
1124 ac_prev=FS90 ;;
1125 -fs90=* | --fs90=*)
1126 FS90=$ac_optarg ;;
1127
1128 -ieee | --ieee)
1129 IEEE=true ;;
1130 -noieee | --noieee)
1131 IEEE= ;;
1132
1133 -ts | --ts)
1134 TS=true ;;
1135
1136 -mpi | --mpi)
1137 MPI=true ;;
1138 -mpi=* | --mpi=*)
1139 MPIPATH=$ac_optarg
1140 MPI=true ;;
1141
1142 # -jam | --jam)
1143 # JAM=1 ;;
1144 # -nojam | --nojam)
1145 # JAM=0 ;;
1146
1147 -ds | --ds)
1148 DUMPSTATE=t ;;
1149
1150 -taf_extra | --taf_extra)
1151 ac_prev=TAF_EXTRA ;;
1152 -taf_extra=* | --taf_extra=*)
1153 TAF_EXTRA=$ac_optarg ;;
1154
1155 -tamc_extra | --tamc_extra)
1156 ac_prev=TAMC_EXTRA ;;
1157 -tamc_extra=* | --tamc_extra=*)
1158 TAMC_EXTRA=$ac_optarg ;;
1159
1160 -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1161 IGNORE_TIME="-DIGNORE_TIME" ;;
1162
1163 -*)
1164 echo "Error: unrecognized option: "$ac_option
1165 usage
1166 ;;
1167
1168 *)
1169 echo "Error: unrecognized argument: "$ac_option
1170 usage
1171 ;;
1172
1173 esac
1174
1175 done
1176
1177
1178 if test -f ./.genmakerc ; then
1179 echo
1180 echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
1181 echo " file. This file format is no longer supported. Please see:"
1182 echo
1183 echo " http://mitgcm.org/devel_HOWTO/"
1184 echo
1185 echo " for directions on how to setup and use the new \"genmake2\" input"
1186 echo " files and send an email to MITgcm-support@mitgcm.org if you want help."
1187 echo
1188 fi
1189
1190 # Find the MITgcm ${ROOTDIR}
1191 if test "x${ROOTDIR}" = x ; then
1192 tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1193 if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
1194 ROOTDIR=".."
1195 else
1196 for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1197 if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
1198 ROOTDIR=$d
1199 printf "Warning: ROOTDIR was not specified but there appears to be"
1200 echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
1201 break
1202 fi
1203 done
1204 fi
1205 fi
1206 if test "x${ROOTDIR}" = x ; then
1207 echo "Error: Cannot determine ROOTDIR for MITgcm code."
1208 echo " Please specify a ROOTDIR using either an options "
1209 echo " file or a command-line option."
1210 exit 1
1211 fi
1212 if test ! -d ${ROOTDIR} ; then
1213 echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
1214 exit 1
1215 fi
1216
1217 # Find the MITgcm ${THISVER}
1218 if test -f "${ROOTDIR}/doc/tag-index" ; then
1219 THISVER=`grep '^checkpoint' ${ROOTDIR}/doc/tag-index | head -1`
1220 fi
1221
1222 if test "x$MAKEFILE" = x ; then
1223 MAKEFILE="Makefile"
1224 fi
1225
1226 echo " getting OPTFILE information: "
1227 if test "x${OPTFILE}" = x ; then
1228 if test "x$MITGCM_OF" = x ; then
1229 echo "Warning: no OPTFILE specified so we'll look for possible settings"
1230 printf "\n=== Searching for possible settings for OPTFILE ===\n"
1231 find_possible_configs
1232 else
1233 OPTFILE=$MITGCM_OF
1234 fi
1235 fi
1236 if test "x$OPTFILE" != xNONE ; then
1237 if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
1238 echo " using OPTFILE=\"$OPTFILE\""
1239 . "$OPTFILE"
1240 RETVAL=$?
1241 if test "x$RETVAL" != x0 ; then
1242 printf "Error: failed to source OPTFILE \"$OPTFILE\""
1243 echo "--please check that variable syntax is bash-compatible"
1244 exit 1
1245 fi
1246 if test "x$DUMPSTATE" != xf ; then
1247 cp -f $OPTFILE "genmake_optfile"
1248 fi
1249 else
1250 echo "Error: can't read OPTFILE=\"$OPTFILE\""
1251 exit 1
1252 fi
1253 fi
1254
1255 echo " getting AD_OPTFILE information: "
1256 if test "x${AD_OPTFILE}" = x ; then
1257 if test "x$MITGCM_AD_OF" = x ; then
1258 AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
1259 else
1260 AD_OPTFILE=$MITGCM_AD_OF
1261 fi
1262 fi
1263 if test "x${AD_OPTFILE}" != xNONE ; then
1264 if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
1265 echo " using AD_OPTFILE=\"$AD_OPTFILE\""
1266 . "$AD_OPTFILE"
1267 RETVAL=$?
1268 if test "x$RETVAL" != x0 ; then
1269 printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1270 echo "--please check that variable syntax is bash-compatible"
1271 exit 1
1272 fi
1273 if test "x$DUMPSTATE" != xf ; then
1274 cp -f $AD_OPTFILE "genmake_ad_optfile"
1275 fi
1276 else
1277 echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
1278 exit 1
1279 fi
1280 fi
1281
1282 #====================================================================
1283 # Set default values if not set by the optfile
1284 #
1285 # Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined. If not,
1286 # either set defaults or complain and abort!
1287 if test ! "x$BASH" = x ; then
1288 # add a trailing space so that it works within the Makefile syntax (see below)
1289 BASH="$BASH "
1290 fi
1291 if test "x$FC" = x ; then
1292 cat <<EOF 1>&2
1293
1294 Error: no Fortran compiler: please specify using one of the following:
1295 1) within the options file ("FC=...") as specified by "-of=OPTFILE"
1296 2) the "-fc=XXX" command-line option
1297 3) the "./genmake_local" file
1298 EOF
1299 exit 1
1300 fi
1301 if test "x$CC" = x ; then
1302 CC=cc
1303 # cat <<EOF 1>&2
1304 # Error: no C compiler: please specify using one of the following:
1305 # 1) within the options file ("CC=...") as specified by "-of=OPTFILE"
1306 # 2) the "-cc=XXX" command-line option
1307 # 3) the "./genmake_local" file
1308 # EOF
1309 # exit 1
1310 fi
1311 if test "x$LINK" = x ; then
1312 LINK=$FC
1313 fi
1314 if test "x$MAKE" = x ; then
1315 MAKE="make"
1316 fi
1317 if test "x$CPP" = x ; then
1318 CPP=cpp
1319 fi
1320 #EH3 === UGLY ===
1321 # The following is an ugly little hack to check for $CPP in /lib/ and
1322 # it should eventually be replaced with a more general function that
1323 # searches a combo of the user's path and a list of "usual suspects"
1324 # to find the correct location for binaries such as $CPP.
1325 for i in " " "/lib/" ; do
1326 echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1327 done
1328 #EH3 === UGLY ===
1329 echo "#define A a" | $CPP > test_cpp 2>&1
1330 RETVAL=$?
1331 if test "x$RETVAL" != x0 ; then
1332 cat <<EOF 1>&2
1333
1334 Error: C pre-processor "$CPP" failed the test case: please specify using:
1335
1336 1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1337 2) the "./genmake_local" file
1338 3) with the CPP environment variable
1339
1340 EOF
1341 exit 1
1342 else
1343 rm -f test_cpp
1344 fi
1345 look_for_makedepend
1346 if test "x$LN" = x ; then
1347 LN="ln -s"
1348 fi
1349 echo "test" > genmake_test_ln
1350 $LN genmake_test_ln genmake_tlink
1351 RETVAL=$?
1352 if test "x$RETVAL" != x0 ; then
1353 cat <<EOF 1>&2
1354
1355 Error: The command "ln -s" failed -- please specify a working soft-link
1356 command in the optfile.
1357
1358 EOF
1359 exit 1
1360 fi
1361 test -L genmake_tlink > /dev/null 2>&1
1362 RETVAL=$?
1363 if test "x$RETVAL" = x0 ; then
1364 HAVE_TEST_L=t
1365 fi
1366 rm -f genmake_test_ln genmake_tlink
1367
1368 # Check for broken *.F/*.f handling and fix if possible
1369 check_for_broken_Ff
1370
1371 if test ! "x$MPI" = x ; then
1372 echo " Turning on MPI cpp macros"
1373 DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1374 fi
1375
1376 if test ! "x$TS" = x ; then
1377 echo " Turning on timing per timestep"
1378 DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1379 fi
1380
1381 printf "\n=== Checking system libraries ===\n"
1382 printf " Do we have the system() command using $FC... "
1383 cat > genmake_tcomp.$FS <<EOF
1384 program hello
1385 call system('echo hi')
1386 end
1387 EOF
1388 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1389 RETVAL=$?
1390 if test "x$RETVAL" = x0 ; then
1391 HAVE_SYSTEM=t
1392 DEFINES="$DEFINES -DHAVE_SYSTEM"
1393 echo "yes"
1394 else
1395 HAVE_SYSTEM=
1396 echo "no"
1397 fi
1398 rm -f genmake_tcomp*
1399
1400 printf " Do we have the fdate() command using $FC... "
1401 cat > genmake_tcomp.$FS <<EOF
1402 program hello
1403 CHARACTER*(128) string
1404 string = ' '
1405 call fdate( string )
1406 print *, string
1407 end
1408 EOF
1409 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1410 RETVAL=$?
1411 if test "x$RETVAL" = x0 ; then
1412 HAVE_FDATE=t
1413 DEFINES="$DEFINES -DHAVE_FDATE"
1414 echo "yes"
1415 else
1416 HAVE_FDATE=
1417 echo "no"
1418 fi
1419 rm -f genmake_tcomp*
1420
1421 printf " Do we have the etime() command using $FC... "
1422 cat > genmake_tcomp.$FS <<EOF
1423 program hello
1424 REAL*4 ACTUAL, TARRAY(2)
1425 EXTERNAL ETIME
1426 REAL*4 ETIME
1427 actual = etime( tarray )
1428 print *, tarray
1429 end
1430 EOF
1431 $FC $FFLAGS -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1432 RETVAL=$?
1433 if test "x$RETVAL" = x0 ; then
1434 HAVE_ETIME=t
1435 DEFINES="$DEFINES -DHAVE_ETIME"
1436 echo "yes"
1437 else
1438 HAVE_ETIME=
1439 echo "no"
1440 fi
1441 rm -f genmake_tcomp*
1442
1443 printf " Can we call simple C routines (here, \"cloc()\") using $FC... "
1444 check_HAVE_CLOC
1445 if test "x$HAVE_CLOC" != x ; then
1446 echo "yes"
1447 else
1448 echo "no"
1449 fi
1450 rm -f genmake_t*
1451
1452 printf " Can we unlimit the stack size using $FC... "
1453 check_HAVE_SETRLSTK
1454 if test "x$HAVE_SETRLSTK" != x ; then
1455 echo "yes"
1456 else
1457 echo "no"
1458 fi
1459 rm -f genmake_t*
1460
1461 printf " Can we use stat() through C calls... "
1462 check_HAVE_STAT
1463 if test "x$HAVE_STAT" != x ; then
1464 echo "yes"
1465 else
1466 echo "no"
1467 fi
1468 rm -f genmake_t*
1469
1470 printf " Can we create NetCDF-enabled binaries... "
1471 check_netcdf_libs
1472 if test "x$HAVE_NETCDF" != x ; then
1473 echo "yes"
1474 else
1475 echo "no"
1476 fi
1477 DEFINES="$DEFINES $IGNORE_TIME"
1478
1479 printf "\n=== Setting defaults ===\n"
1480 printf " Adding MODS directories: "
1481 for d in $MODS ; do
1482 if test ! -d $d ; then
1483 echo
1484 echo "Error: MODS directory \"$d\" not found!"
1485 exit 1
1486 else
1487 printf " $d"
1488 SOURCEDIRS="$SOURCEDIRS $d"
1489 INCLUDEDIRS="$INCLUDEDIRS $d"
1490 fi
1491 done
1492 echo
1493
1494 if test "x${PLATFORM}" = x ; then
1495 PLATFORM=$p_PLATFORM
1496 fi
1497
1498 if test "x${EXEDIR}" = x ; then
1499 tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1500 if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
1501 EXEDIR=../exe
1502 else
1503 EXEDIR=.
1504 fi
1505 fi
1506 if test ! -d ${EXEDIR} ; then
1507 echo "Error: the specified EXEDIR (\"$EXEDIR\") does not exist!"
1508 exit 1
1509 fi
1510
1511 if test "x${TOOLSDIR}" = x ; then
1512 TOOLSDIR="$ROOTDIR/tools"
1513 fi
1514 if test ! -d ${TOOLSDIR} ; then
1515 echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1516 exit 1
1517 fi
1518 if test "x$S64" = x ; then
1519 echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
1520 RETVAL=$?
1521 if test "x${RETVAL}" = x0 ; then
1522 S64='$(TOOLSDIR)/set64bitConst.sh'
1523 else
1524 echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
1525 RETVAL=$?
1526 if test "x${RETVAL}" = x0 ; then
1527 S64='$(TOOLSDIR)/set64bitConst.csh'
1528 else
1529 cat <<EOF
1530
1531 ERROR: neither of the two default scripts:
1532
1533 ${TOOLSDIR}/set64bitConst.sh
1534 ${TOOLSDIR}/set64bitConst.csh
1535
1536 are working so please check paths or specify (with \$S64) a
1537 working version of this script.
1538
1539 EOF
1540 exit 1
1541 fi
1542 fi
1543 fi
1544 THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1545
1546 EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1547
1548 # We have a special set of source files in eesupp/src which are
1549 # generated from some template source files. We'll make them first so
1550 # they appear as regular source code
1551 if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
1552 echo " Making source files in eesupp from templates"
1553 ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
1554 RETVAL=$?
1555 if test "x${RETVAL}" = x0 ; then
1556 rm -f make_eesupp.errors
1557 else
1558 echo "Error: problem encountered while building source files in eesupp:"
1559 cat make_eesupp.errors 1>&2
1560 exit 1
1561 fi
1562 fi
1563
1564 #same for exch2
1565 if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then
1566 echo " Making source files in exch2 from templates"
1567 ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1
1568 RETVAL=$?
1569 if test "x${RETVAL}" = x0 ; then
1570 rm -f make_exch2.errors
1571 else
1572 echo "Error: problem encountered while building source files in exch2:"
1573 cat make_exch2.errors 1>&2
1574 exit 1
1575 fi
1576 fi
1577
1578 printf "\n=== Determining package settings ===\n"
1579 if test "x${PDEPEND}" = x ; then
1580 tmp=$ROOTDIR"/pkg/pkg_depend"
1581 if test -r $tmp ; then
1582 PDEPEND=$tmp
1583 else
1584 echo "Warning: No package dependency information was specified."
1585 echo " Please check that ROOTDIR/pkg/pkg_depend exists."
1586 fi
1587 else
1588 if test ! -r ${PDEPEND} ; then
1589 echo "Error: can't read package dependency info from PDEPEND=\"$PDEPEND\""
1590 exit 1
1591 fi
1592 fi
1593 echo " getting package dependency info from $PDEPEND"
1594 # Strip the comments and then convert the dependency file into
1595 # two arrays: PNAME, DNAME
1596 cat $PDEPEND | sed -e 's/#.*$//g' \
1597 | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
1598 > ./.pd_tmp
1599 RETVAL=$?
1600 if test ! "x${RETVAL}" = x0 ; then
1601 echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
1602 exit 1
1603 fi
1604 . ./.pd_tmp
1605 rm -f ./.pd_tmp
1606
1607 # Search for default packages. Note that a "$ROOTDIR/pkg/pkg_groups"
1608 # file should eventually be added so that, for convenience, one can
1609 # specify groups of packages using names like "ocean" and "atmosphere".
1610 echo " checking default package list: "
1611 if test "x${PDEFAULT}" = x ; then
1612 for i in "." $MODS ; do
1613 if test -r $i"/packages.conf" ; then
1614 PDEFAULT=$i"/packages.conf"
1615 break
1616 fi
1617 done
1618 fi
1619 if test "x${PDEFAULT}" = x ; then
1620 PDEFAULT="$ROOTDIR/pkg/pkg_default"
1621 fi
1622 if test "x${PDEFAULT}" = xNONE ; then
1623 echo " default packages file disabled"
1624 else
1625 if test ! -r $PDEFAULT ; then
1626 echo "Warning: can't read default packages from PDEFAULT=\"$PDEFAULT\""
1627 else
1628 echo " using PDEFAULT=\"$PDEFAULT\""
1629 # Strip the comments and add all the names
1630 def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1631 RETVAL=$?
1632 if test "x${RETVAL}" != x0 ; then
1633 printf "Error: can't parse default package list "
1634 echo "-- please check PDEFAULT=\"$PDEFAULT\""
1635 exit 1
1636 fi
1637 for i in $def ; do
1638 PACKAGES="$PACKAGES $i"
1639 done
1640 echo " before group expansion packages are: $PACKAGES"
1641 RET=1
1642 while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
1643 echo " after group expansion packages are: $PACKAGES"
1644 fi
1645 fi
1646
1647 echo " applying DISABLE settings"
1648 for i in $PACKAGES ; do
1649 echo $i >> ./.tmp_pack
1650 done
1651 for i in `grep "-" ./.tmp_pack` ; do
1652 j=`echo $i | sed 's/[-]//'`
1653 DISABLE="$DISABLE $j"
1654 done
1655 pack=
1656 for p in $PACKAGES ; do
1657 addit="t"
1658 for d in $DISABLE ; do
1659 if test "x$p" = "x$d" ; then
1660 addit="f"
1661 fi
1662 done
1663 if test "x$addit" = xt ; then
1664 pack="$pack $p"
1665 fi
1666 done
1667 PACKAGES="$pack"
1668 echo " applying ENABLE settings"
1669 echo "" > ./.tmp_pack
1670 PACKAGES="$PACKAGES $ENABLE"
1671 # Test if each explicitly referenced package exists
1672 for i in $PACKAGES ; do
1673 j=`echo $i | sed 's/[-+]//'`
1674 if test ! -d "$ROOTDIR/pkg/$j" ; then
1675 echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
1676 exit 1
1677 fi
1678 echo $i >> ./.tmp_pack
1679 done
1680 PACKAGES=
1681 for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
1682 PACKAGES="$PACKAGES $i"
1683 done
1684 rm -f ./.tmp_pack
1685 echo " packages are: $PACKAGES"
1686
1687 # Check availability of NetCDF and then either build the MNC template
1688 # files or delete mnc from the list of available packages.
1689 echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1690 RETVAL=$?
1691 if test "x$RETVAL" = x0 ; then
1692 if test "x$HAVE_NETCDF" != xt ; then
1693 cat <<EOF
1694
1695 *********************************************************************
1696 WARNING: the "mnc" package was enabled but tests failed to compile
1697 NetCDF applications. Please check that:
1698
1699 1) NetCDF is correctly installed for this compiler and
1700 2) the LIBS variable (within the "optfile") specifies the correct
1701 NetCDF library to link against.
1702
1703 Due to this failure, the "mnc" package is now DISABLED.
1704 *********************************************************************
1705
1706 EOF
1707 PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
1708 DISABLE="$DISABLE mnc"
1709 else
1710 ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
1711 RETVAL=$?
1712 if test "x${RETVAL}" = x0 ; then
1713 rm -f make_mnc.errors
1714 else
1715 echo "Error: problem encountered while building source files in pkg/mnc:"
1716 cat make_mnc.errors 1>&2
1717 exit 1
1718 fi
1719 fi
1720 fi
1721
1722 echo " applying package dependency rules"
1723 ck=
1724 while test "x$ck" != xtt ; do
1725 i=0
1726 # rtot=${#PNAME[@]}
1727 rtot=$nname
1728 while test $i -lt $rtot ; do
1729
1730 # Is $pname in the current $PACKAGES list?
1731 # pname=${PNAME[$i]}
1732 tmp="pname=\"\$PNAME_$i\""
1733 eval $tmp
1734 pin="f"
1735 for p in $PACKAGES ; do
1736 if test "x$p" = "x$pname" ; then
1737 pin="t"
1738 fi
1739 done
1740
1741 # Is the DNAME entry a (+) or (-) rule ?
1742 tmp="dname=\"\$DNAME_$i\""
1743 eval $tmp
1744 plus="-"
1745 echo $dname | grep '^+' > /dev/null 2>&1
1746 RETVAL=$?
1747 if test "x$RETVAL" = x0 ; then
1748 plus="+"
1749 fi
1750
1751 # Is $dname in the current $PACKAGES list?
1752 dname=`echo $dname | sed -e 's/^[+-]//'`
1753 din="f"
1754 for p in $PACKAGES ; do
1755 if test "x$p" = "x$dname" ; then
1756 din="t"
1757 fi
1758 done
1759
1760 # Do we need to add $dname according to the dependency rules?
1761 if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
1762 in_dis="f"
1763 for dis in $DISABLE ; do
1764 if test "x$dis" = "x$dname" ; then
1765 in_dis="t"
1766 fi
1767 done
1768 if test "x$in_dis" = xt ; then
1769 echo "Error: can't satisfy package dependencies:"
1770 echo " \"$dname\" is required by the dependency rules"
1771 echo " but is disallowed by the DISABLE settings"
1772 exit 1
1773 else
1774 PACKAGES="$PACKAGES $dname"
1775 ck=
1776 fi
1777 fi
1778
1779 # Do we need to get rid of $dname according to the dependency rules?
1780 if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
1781 echo "Error: can't satisfy package dependencies:"
1782 echo " \"$pname\" was requested but is disallowed by"
1783 echo " the dependency rules for \"$dname\""
1784 exit 1
1785 fi
1786 i=`echo "$i + 1" | bc -l`
1787 #i=$(( $i + 1 ))
1788 done
1789 ck=$ck"t"
1790 done
1791 echo " packages are: $PACKAGES"
1792 for i in $PACKAGES ; do
1793 adr="$ROOTDIR/pkg/$i"
1794 if test -d $adr ; then
1795 SOURCEDIRS="$SOURCEDIRS $adr"
1796 INCLUDEDIRS="$INCLUDEDIRS $adr"
1797 if test "x$i" = xautodiff ; then
1798 AUTODIFF_PKG_USED=t
1799 fi
1800 else
1801 echo "Error: the directory \"$adr\" for package $i doesn't exist"
1802 exit 1
1803 fi
1804 done
1805
1806 # Create a list of #define and #undef to enable/disable packages
1807 PACKAGES_DOT_H=PACKAGES_CONFIG.h
1808 # The following UGLY HACK sets multiple "#undef"s and it needs to go
1809 # away. On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
1810 # file would eventually be split up so that all package-related #define
1811 # statements could be separated and handled only by genmake.
1812 names=`ls -1 "$ROOTDIR/pkg"`
1813 all_pack=
1814 DISABLED_PACKAGES=
1815 for n in $names ; do
1816 if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
1817 has_pack="f"
1818 for pack in $PACKAGES ; do
1819 if test "x$pack" = "x$n" ; then
1820 has_pack="t"
1821 break
1822 fi
1823 done
1824 if test "x$has_pack" = xf ; then
1825 undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1826 DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
1827 fi
1828 fi
1829 done
1830 ENABLED_PACKAGES=
1831 for i in $PACKAGES ; do
1832 def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1833 ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
1834 #eh3 DEFINES="$DEFINES -D$def"
1835
1836 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
1837 case $i in
1838 aim_v23)
1839 ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
1840 echo "Warning: ALLOW_AIM is set to enable aim_v23."
1841 ;;
1842 esac
1843 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
1844
1845 done
1846
1847 echo " Adding STANDARDDIRS"
1848 BUILDDIR=${BUILDDIR:-.}
1849 if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
1850 STANDARDDIRS="eesupp model"
1851 fi
1852 if test "x$STANDARDDIRS" != x ; then
1853 for d in $STANDARDDIRS ; do
1854 adr="$ROOTDIR/$d/src"
1855 if test ! -d $adr ; then
1856 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1857 echo " is correct and that you correctly specified the STANDARDDIRS option"
1858 exit 1
1859 else
1860 SOURCEDIRS="$SOURCEDIRS $adr"
1861 fi
1862 adr="$ROOTDIR/$d/inc"
1863 if test ! -d $adr ; then
1864 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1865 echo " is correct and that you correctly specified the STANDARDDIRS option"
1866 exit 1
1867 else
1868 INCLUDEDIRS="$INCLUDEDIRS $adr"
1869 fi
1870 done
1871 fi
1872
1873 echo " Searching for *OPTIONS.h files in order to warn about the presence"
1874 echo " of \"#define \"-type statements that are no longer allowed:"
1875 CPP_OPTIONS=
1876 CPP_EEOPTIONS=
1877 spaths=". $INCLUDEDIRS"
1878 names=`ls -1 "$ROOTDIR/pkg"`
1879 for i in $spaths ; do
1880 try="$i/CPP_OPTIONS.h"
1881 if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
1882 echo " found CPP_OPTIONS=\"$try\""
1883 CPP_OPTIONS="$try"
1884 # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1885 for n in $names ; do
1886 test_for_package_in_cpp_options $CPP_OPTIONS $n
1887 done
1888 fi
1889 try="$i/CPP_EEOPTIONS.h"
1890 if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
1891 echo " found CPP_EEOPTIONS=\"$try\""
1892 # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
1893 #**** not yet enabled ****
1894 # test_for_mpi_in_cpp_eeoptions $try
1895 #**** not yet enabled ****
1896 CPP_EEOPTIONS="$try"
1897 fi
1898 done
1899 if test "x$CPP_OPTIONS" = x ; then
1900 echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
1901 exit 1
1902 fi
1903
1904 # Here, we build the list of files to be "run through" the adjoint
1905 # compiler.
1906 if test -f ./ad_files ; then
1907 rm -f ./ad_files
1908 fi
1909 echo " Creating the list of files for the adjoint compiler."
1910 for i in $SOURCEDIRS ; do
1911 list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
1912 for j in $list_files ; do
1913 cat $i/$j >> ad_files
1914 done
1915 done
1916 if test ! "x"$FS = "x.f" ; then
1917 cat ad_files | sed -e "s/\.f/.$FS/g" > ad_files_f
1918 mv -f ad_files_f ad_files
1919 fi
1920
1921 echo
1922 echo "=== Creating the Makefile ==="
1923 echo " setting INCLUDES"
1924 for i in $INCLUDEDIRS ; do
1925 if test ! -d $i ; then
1926 echo "Warning: can't find INCLUDEDIRS=\"$i\""
1927 fi
1928 done
1929
1930 echo " Determining the list of source and include files"
1931 rm -rf .links.tmp
1932 mkdir .links.tmp
1933 echo "# This section creates symbolic links" > srclinks.tmp
1934 echo "" >> srclinks.tmp
1935 printf 'SRCFILES = ' > srclist.inc
1936 printf 'CSRCFILES = ' > csrclist.inc
1937 printf 'F90SRCFILES = ' > f90srclist.inc
1938 printf 'HEADERFILES = ' > hlist.inc
1939 printf 'AD_FLOW_FILES = ' > ad_flow_files.inc
1940 alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1941 for d in $alldirs ; do
1942 deplist=
1943 sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
1944 sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
1945 for sf in $sfiles ; do
1946 if test ! -r ".links.tmp/$sf" ; then
1947 if test -f "$d/$sf" ; then
1948 ignore_f=f
1949 case $d/$sf in
1950 ./$PACKAGES_DOT_H)
1951 ;;
1952 ./AD_CONFIG.h)
1953 ;;
1954 ./FC_NAMEMANGLE.h)
1955 ;;
1956 ./BUILD_INFO.h)
1957 ;;
1958 *)
1959 # For the local directory *ONLY*,
1960 # ignore all soft-links
1961 if test "x$HAVE_TEST_L" = xt -a "x$d" = x. -a -L $sf ; then
1962 ignore_f=t
1963 else
1964 touch .links.tmp/$sf
1965 deplist="$deplist $sf"
1966 fi
1967 ;;
1968 esac
1969 if test "x$ignore_f" = xf ; then
1970 extn=`echo $sf | $AWK -F. '{print $NF}'`
1971 case $extn in
1972 F)
1973 echo " \\" >> srclist.inc
1974 printf " $sf" >> srclist.inc
1975 ;;
1976 F90)
1977 echo " \\" >> f90srclist.inc
1978 printf " $sf" >> f90srclist.inc
1979 ;;
1980 c)
1981 echo " \\" >> csrclist.inc
1982 printf " $sf" >> csrclist.inc
1983 ;;
1984 h)
1985 echo " \\" >> hlist.inc
1986 printf " $sf" >> hlist.inc
1987 ;;
1988 flow)
1989 echo " \\" >> ad_flow_files.inc
1990 printf " $sf" >> ad_flow_files.inc
1991 ;;
1992 esac
1993 fi
1994 fi
1995 fi
1996 done
1997 if test "x$deplist" != x ; then
1998 echo "" >> srclinks.tmp
1999 echo "# These files are linked from $d" >> srclinks.tmp
2000 echo "$deplist :" >> srclinks.tmp
2001 printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp
2002 fi
2003 done
2004 rm -rf .links.tmp
2005 echo "" >> srclist.inc
2006 echo "" >> csrclist.inc
2007 echo "" >> f90srclist.inc
2008 echo "" >> hlist.inc
2009 echo "" >> ad_flow_files.inc
2010
2011 if test -f $MAKEFILE ; then
2012 mv -f $MAKEFILE "$MAKEFILE.bak"
2013 fi
2014 echo " Writing makefile: $MAKEFILE"
2015 echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
2016 echo "# $MACHINE" >> $MAKEFILE
2017 echo "# This makefile was generated automatically on" >> $MAKEFILE
2018 echo "# $THISDATE" >> $MAKEFILE
2019 echo "# by the command:" >> $MAKEFILE
2020 echo "# $0 $G2ARGS" >> $MAKEFILE
2021 echo "# executed by:" >> $MAKEFILE
2022 echo "# ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
2023
2024 EXE_AD=$EXECUTABLE"_ad"
2025 EXE_FTL=$EXECUTABLE"_ftl"
2026 EXE_SVD=$EXECUTABLE"_svd"
2027
2028 cat >>$MAKEFILE <<EOF
2029 #
2030 # OPTFILE="$OPTFILE"
2031 #
2032 # BUILDDIR : Directory where object files are written
2033 # SOURCEDIRS : Directories containing the source (.F) files
2034 # INCLUDEDIRS : Directories containing the header-source (.h) files
2035 # EXEDIR : Directory where executable that is generated is written
2036 # EXECUTABLE : Full path of executable binary
2037 #
2038 # CPP : C-preprocessor command
2039 # INCLUDES : Directories searched for header files
2040 # DEFINES : Macro definitions for CPP
2041 # MAKEDEPEND : Dependency generator
2042 # KPP : Special preprocessor command (specific to platform)
2043 # KFLAGS : Flags for KPP
2044 # FC : Fortran compiler command
2045 # FFLAGS : Configuration/debugging options for FC
2046 # FOPTIM : Optimization options for FC
2047 # LINK : Command for link editor program
2048 # LIBS : Library flags /or/ additional optimization/debugging flags
2049
2050 ROOTDIR = ${ROOTDIR}
2051 BUILDDIR = ${BUILDDIR}
2052 SOURCEDIRS = ${SOURCEDIRS}
2053 INCLUDEDIRS = ${INCLUDEDIRS}
2054 EXEDIR = ${EXEDIR}
2055 EXECUTABLE = \$(EXEDIR)/${EXECUTABLE}
2056 TOOLSDIR = ${TOOLSDIR}
2057
2058 #eh3 new defines for the adjoint work
2059 AUTODIFF = ${ROOTDIR}/pkg/autodiff
2060 EXE_AD = ${EXE_AD}
2061 EXE_FTL = ${EXE_FTL}
2062 EXE_SVD = ${EXE_SVD}
2063
2064 ENABLED_PACKAGES = ${ENABLED_PACKAGES}
2065 DISABLED_PACKAGES = ${DISABLED_PACKAGES}
2066
2067 # These files are created by Makefile
2068 SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
2069
2070 EOF
2071
2072 # Note: figure out some way to add Hyades JAM libraries here
2073
2074 cat >>$MAKEFILE <<EOF
2075 # Unix ln (link)
2076 LN = ${LN}
2077 # C preprocessor
2078 CPP = cat \$< | ${S64} | ${CPP}
2079 # Dependency generator
2080 MAKEDEPEND = ${MAKEDEPEND}
2081 # Special preprocessor (KAP on DECs, FPP on Crays)
2082 KPP = ${KPP}
2083 # Fortran compiler
2084 FC = ${FC}
2085 # Fortran compiler
2086 F90C = ${F90C}
2087 # C compiler
2088 CC = ${CC}
2089 # Link editor
2090 LINK = ${LINK} ${LDADD}
2091
2092 # Defines for CPP
2093 DEFINES = ${DEFINES}
2094 # Includes for CPP
2095 INCLUDES = ${INCLUDES}
2096 # Flags for KPP
2097 KFLAGS1 = ${KFLAGS1}
2098 KFLAGS2 = ${KFLAGS2}
2099 # Optim./debug for FC
2100 FFLAGS = ${FFLAGS}
2101 FOPTIM = ${FOPTIM}
2102 # Optim./debug for FC
2103 F90FLAGS = ${F90FLAGS}
2104 F90OPTIM = ${F90OPTIM}
2105 # Flags for CC
2106 CFLAGS = ${CFLAGS}
2107 # Files that should not be optimized
2108 NOOPTFILES = ${NOOPTFILES}
2109 NOOPTFLAGS = ${NOOPTFLAGS}
2110 # Flags and libraries needed for linking
2111 LIBS = ${LIBS}
2112 # Name of the Mekfile
2113 MAKEFILE=${MAKEFILE}
2114
2115 EOF
2116
2117 cat srclist.inc >> $MAKEFILE
2118 cat csrclist.inc >> $MAKEFILE
2119 cat f90srclist.inc >> $MAKEFILE
2120 cat hlist.inc >> $MAKEFILE
2121 cat ad_flow_files.inc >> $MAKEFILE
2122 echo >> $MAKEFILE
2123 echo 'F77FILES = $(SRCFILES:.F=.'$FS')' >> $MAKEFILE
2124 echo 'F90FILES = $(F90SRCFILES:.F90=.'$FS90')' >> $MAKEFILE
2125 echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
2126 echo >> $MAKEFILE
2127 echo '.SUFFIXES:' >> $MAKEFILE
2128 echo '.SUFFIXES: .o .'$FS' .p .F .c .'$FS90' .F90' >> $MAKEFILE
2129 rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc
2130 rm -f ad_flow_files.inc
2131
2132 cat >>$MAKEFILE <<EOF
2133
2134 all: \$(EXECUTABLE)
2135 \$(EXECUTABLE): \$(SPECIAL_FILES) \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(OBJFILES)
2136 @echo Creating \$@ ...
2137 \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2138 depend:
2139 @make links
2140 \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
2141 \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2142 -rm -f makedepend.out
2143
2144 lib: libmitgcmuv.a
2145
2146 libmitgcmuv.a: \$(OBJFILES)
2147 ar rcv libmitgcmuv.a \$(OBJFILES)
2148
2149 links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES) \$(SPECIAL_FILES)
2150
2151 small_f: \$(F77FILES) \$(F90FILES)
2152
2153 output.txt: \$(EXECUTABLE)
2154 @printf 'running ... '
2155 @\$(EXECUTABLE) > \$@
2156
2157 clean:
2158 -rm -rf *.o *.$FS *.p *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template
2159 Clean:
2160 @make clean
2161 @make cleanlinks
2162 -rm -f \$(SPECIAL_FILES)
2163 -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak
2164 CLEAN:
2165 @make Clean
2166 -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2167 -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2168 -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2169 -rm -f \$(EXECUTABLE) output.txt STD*
2170
2171 #eh3 Makefile: makefile
2172 makefile:
2173 $THIS_SCRIPT $G2ARGS
2174 cleanlinks:
2175 -find . -type l -exec rm {} \;
2176
2177 # Special targets (SPECIAL_FILES) which are create by make
2178 ${PACKAGES_DOT_H}:
2179 @echo Creating \$@ ...
2180 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" \$(DISABLED_PACKAGES) " " "Enabled packages:" \$(ENABLED_PACKAGES) > \$@
2181 AD_CONFIG.h:
2182 @echo Creating \$@ ...
2183 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bAD_CONFIG_H -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > \$@
2184 FC_NAMEMANGLE.h:
2185 @echo Creating \$@ ...
2186 echo "$FC_NAMEMANGLE" > \$@
2187
2188 BUILD_INFO.h:
2189 @echo Creating \$@ ...
2190 EOF
2191
2192 test ! "x$THISVER" = x && echo " -echo \"#define THISVER '$THISVER'\" > \$@" >> $MAKEFILE
2193 test ! "x$THISUSER" = x && echo " -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
2194 test ! "x$THISDATE" = x && echo " -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2195 test ! "x$THISHOST" = x && echo " -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2196
2197 cat >>$MAKEFILE <<EOF
2198
2199 # The normal chain of rules is ( .F - .$FS - .o )
2200
2201 ## This nullifies any default implicit rules concerning these two file types:
2202 ## %.o : %.F
2203
2204 .F.$FS:
2205 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2206 .$FS.o:
2207 \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2208 .F90.$FS90:
2209 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2210 .$FS90.o:
2211 \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
2212 .c.o:
2213 \$(CC) \$(CFLAGS) -c \$<
2214
2215 # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
2216 .F.p:
2217 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2218 .p.$FS:
2219 \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
2220
2221 #=========================================
2222 #=== Automatic Differentiation Rules ===
2223
2224 TAMC = ${TAMC}
2225 TAF = ${TAF}
2226
2227 TAF_EXTRA = ${TAF_EXTRA}
2228 TAMC_EXTRA = ${TAMC_EXTRA}
2229
2230 EOF
2231
2232 ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
2233 ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
2234 ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
2235 for i in $ad_vars ; do
2236 name=$i
2237 t1="t2=\$"`echo $i`
2238 eval $t1
2239 printf "%-20s = " $name >> $MAKEFILE
2240 echo $t2 >> $MAKEFILE
2241 done
2242
2243 echo " Add the source list for AD code generation"
2244 echo >> $MAKEFILE
2245 printf "AD_FILES = " >> $MAKEFILE
2246 AD_FILES=`cat ad_files`
2247 for i in $AD_FILES ; do
2248 echo " \\" >> $MAKEFILE
2249 printf " $i" >> $MAKEFILE
2250 done
2251 echo >> $MAKEFILE
2252 rm -f ad_files
2253
2254 cat >>$MAKEFILE <<EOF
2255
2256 # ... AD ...
2257 adall: ad_taf
2258 adtaf: ad_taf_output.$FS
2259 adtamc: ad_tamc_output.$FS
2260
2261 ad_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2262 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -DALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ad_config.template
2263 cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
2264 -rm -f ad_config.template
2265 @make \$(F77FILES)
2266 @make \$(AD_FLOW_FILES)
2267 cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.$FS
2268
2269 ad_taf_output.$FS: ad_input_code.$FS
2270 \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2271 cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2272
2273 adtafonly:
2274 \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.$FS
2275 cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_taf_output.$FS
2276
2277 ad_taf: ad_taf_output.o \$(OBJFILES)
2278 \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
2279
2280 ad_tamc_output.$FS: ad_input_code.$FS
2281 \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.$FS
2282 cat ad_input_code_ad.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ad_tamc_output.$FS
2283
2284 ad_tamc: ad_tamc_output.o \$(OBJFILES)
2285 \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
2286
2287 adonlyfwd:
2288 patch < \$(TOOLSDIR)/ad_taf_output.f.onlyfwd.diff
2289
2290 adtrick:
2291 patch < \$(TOOLSDIR)/ad_taf_output.f.adtrick.diff
2292
2293 # ... FTL ...
2294 ftlall: ftl_taf
2295 ftltaf: ftl_taf_output.$FS
2296 ftltamc: ftl_tamc_output.$FS
2297
2298 ftl_input_code.$FS: \$(AD_FILES) \$(HEADERFILES)
2299 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ftl_config.template
2300 cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2301 -rm -f ftl_config.template
2302 @make \$(F77FILES)
2303 @make \$(AD_FLOW_FILES)
2304 cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.$FS
2305
2306 ftl_taf_output.$FS: ftl_input_code.$FS
2307 \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2308 cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2309
2310 ftltafonly:
2311 \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.$FS
2312 cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_taf_output.$FS
2313
2314 ftl_taf: ftl_taf_output.o \$(OBJFILES)
2315 \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
2316
2317 ftl_tamc_output.$FS: ftl_input_code.$FS
2318 \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.$FS
2319 cat ftl_input_code_ftl.$FS | sed -f \$(TOOLSDIR)/adjoint_sed > ftl_tamc_output.$FS
2320
2321 ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
2322 \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
2323
2324
2325 # ... SVD ...
2326 svdtaf: ad_taf_output.$FS ftl_taf_output.$FS
2327 @echo "--->>> Only ran TAF to generate SVD code! <<<---"
2328 @echo "--->>> Do make svdall afterwards to compile. <<<---"
2329 svdall: svd_touch svd_taf
2330
2331 svd_taf: \$(OBJFILES)
2332 \$(LINK) -o mitgcmuv_svd \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o ftl_taf_output.o \$(LIBS)
2333
2334 @echo "--->>> Only COMPILE svd code! <<<---"
2335 @echo "--->>> Assumes you previously <<<---"
2336 @echo "--->>> did make svdtaf <<<---"
2337
2338 svd_touch:
2339 @echo "--->>> Only COMPILE svd code! <<<---"
2340 @echo "--->>> Assumes you previously <<<---"
2341 @echo "--->>> did make svdtaf <<<---"
2342 touch ad_taf_output.$FS ftl_taf_output.$FS
2343 \$(FC) \$(FFLAGS) \$(FOPTIM) -c ad_taf_output.$FS
2344 \$(FC) \$(FFLAGS) \$(FOPTIM) -c ftl_taf_output.$FS
2345 @$BASH\$(TOOLSDIR)/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -DALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > ftl_config.template
2346 cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
2347 -rm -f ftl_config.template
2348
2349 #=========================================
2350
2351 EOF
2352
2353 if test "x$EXEHOOK" != x ; then
2354 printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
2355 fi
2356
2357 echo " Making list of \"exceptions\" that need \".p\" files"
2358 for i in $KPPFILES ; do
2359 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
2360 RETVAL=$?
2361 if test "x$RETVAL" != x0 ; then
2362 echo "Error: unable to add file \"$i\" to the exceptions list"
2363 fi
2364 echo "$base.$FS: $base.p" >> $MAKEFILE
2365 done
2366
2367 echo " Making list of NOOPTFILES"
2368 for i in $NOOPTFILES ; do
2369 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
2370 RETVAL=$?
2371 if test "x$RETVAL" != x0 ; then
2372 echo "Error: unable to add file \"$i\" to the exceptions list"
2373 fi
2374 echo "$base.o: $base.$FS" >> $MAKEFILE
2375 printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
2376 done
2377
2378 echo " Add rules for links"
2379 cat srclinks.tmp >> $MAKEFILE
2380 rm -f srclinks.tmp
2381
2382 echo " Adding makedepend marker"
2383 printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
2384
2385 printf "\n=== Done ===\n"
2386
2387 # Create special header files
2388 $BASH $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -bPACKAGES_CONFIG_H "Disabled packages:" $DISABLED_PACKAGES " " "Enabled packages:" $ENABLED_PACKAGES > $PACKAGES_DOT_H".tmp"
2389 if test ! -f $PACKAGES_DOT_H ; then
2390 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2391 else
2392 cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
2393 RETVAL=$?
2394 if test "x$RETVAL" = x0 ; then
2395 rm -f $PACKAGES_DOT_H".tmp"
2396 else
2397 mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
2398 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2399 fi
2400 fi
2401 if test ! -f AD_CONFIG.h ; then
2402 $BASH $TOOLSDIR/convert_cpp_cmd2defines "Warning - this file is automatically generated - do NOT edit" -UALLOW_ADJOINT_RUN -UALLOW_TANGENTLINEAR_RUN -UALLOW_ECCO_OPTIMIZATION > AD_CONFIG.h
2403 fi
2404
2405
2406 # Write the "state" for future records
2407 if test "x$DUMPSTATE" != xf ; then
2408 printf "" > genmake_state
2409 for i in $gm_state ; do
2410 t1="t2=\$$i"
2411 eval $t1
2412 echo "$i='$t2'" >> genmake_state
2413 done
2414 fi

  ViewVC Help
Powered by ViewVC 1.1.22