/[MITgcm]/MITgcm_contrib/heimbach/OpenAD/code_shallow_openad/genmake2
ViewVC logotype

Contents of /MITgcm_contrib/heimbach/OpenAD/code_shallow_openad/genmake2

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


Revision 1.3 - (show annotations) (download)
Tue Jan 3 19:21:36 2006 UTC (20 years, 10 months ago) by utke
Branch: MAIN
Changes since 1.2: +16 -13 lines
pick up path from mods setting

1 #! /usr/bin/env bash
2 #
3 # $Header: /u/gcmpack/MITgcm_contrib/heimbach/OpenAD/code_shallow_openad/genmake2,v 1.2 2005/12/14 19:54:42 utke 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 if test "x$FC" = x ; then
357 FC=`echo $p_FC | $AWK '{print $1}'`
358 echo " Setting FORTRAN compiler to: "$FC
359 fi
360 fi
361
362 if test "x$OPTFILE" = x ; then
363 OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC
364 if test ! -r $OPTFILE ; then
365 echo " I looked for the file "$OPTFILE" but did not find it"
366 fi
367 fi
368 # echo " The options file: $p_OF"
369 # echo " appears to match so we'll use it."
370 # for i in $p_FC ; do
371 #p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
372 #if test -r $p_OF ; then
373 # OPTFILE=$p_OF
374 # echo " The options file: $p_OF"
375 # echo " appears to match so we'll use it."
376 # break
377 #fi
378 # done
379 if test "x$OPTFILE" = x ; then
380 cat 1>&2 <<EOF
381
382 Error: No options file was found in: $ROOTDIR/tools/build_options/
383 that matches this platform ("$PLATFORM") and the compilers found in
384 your path. Please specify an "optfile" using:
385
386 1) the command line (eg. "-optfile=path/to/OPTFILE"), or
387 2) the MITGCM_OF environment variable.
388
389 If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
390
391 EOF
392 exit 1
393 fi
394
395 # # look for possible MPI libraries
396 # mpi_libs=
397 # mpi_fort=`which mpif77 2>/dev/null`
398 # RETVAL=$?
399 # if test "x${RETVAL}" = x0 ; then
400 # cat >>test.f <<EOF
401 # PROGRAM HELLO
402 # DO 10, I=1,10
403 # PRINT *,'Hello World'
404 # 10 CONTINUE
405 # STOP
406 # END
407 # EOF
408 # eval "$mpi_fort -showme test.f > out"
409 # RETVAL=$?
410 # if test "x${RETVAL}" = x0 ; then
411 # a=`cat out`
412 # for i in $a ; do
413 # case $i in
414 # -*)
415 # mpi_libs="$mpi_libs $i" ;;
416 # esac
417 # done
418 # echo "The MPI libs appear to be:"
419 # echo " "$mpi_libs
420 # fi
421 # rm -f test.f out
422 # fi
423
424 }
425
426 # Parse the package dependency information
427 get_pdepend_list() {
428
429 # strip the comments and then convert the dependency file into
430 # two arrays: PNAME, DNAME
431 cat $1 | sed -e 's/#.*$//g' \
432 | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \
433 > ./.pd_tmp
434 . ./.pd_tmp
435 rm -f ./.pd_tmp
436
437 printf "PNAME = "${}
438 }
439
440
441 # Explain usage
442 usage() {
443 cat <<EOF
444
445 Usage: "$0" [OPTIONS]
446 where [OPTIONS] can be:
447
448 -help | --help | -h | --h
449 Print this help message and exit.
450
451 -adoptfile NAME | --adoptfile NAME | -adof NAME | --adof NAME
452 -adoptfile=NAME | --adoptfile=NAME | -adof=NAME | --adof=NAME
453 Use "NAME" as the adoptfile. By default, the file at
454 "tools/adjoint_options/adjoint_default" will be used.
455
456 -nooptfile | --nooptfile
457 -optfile NAME | --optfile NAME | -of NAME | --of NAME
458 -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME
459 Use "NAME" as the optfile. By default, an attempt will be
460 made to find an appropriate "standard" optfile in the
461 tools/build_options/ directory.
462
463 -pdepend NAME | --pdepend NAME
464 -pdepend=NAME | --pdepend=NAME
465 Get package dependency information from "NAME".
466
467 -pdefault NAME | --pdefault NAME
468 -pdefault=NAME | --pdefault=NAME
469 Get the default package list from "NAME".
470
471 -make NAME | -m NAME
472 --make=NAME | -m=NAME
473 Use "NAME" for the MAKE program. The default is "make" but
474 many platforms, "gmake" is the preferred choice.
475
476 -makefile NAME | -mf NAME
477 --makefile=NAME | -mf=NAME
478 Call the makefile "NAME". The default is "Makefile".
479
480 -makedepend NAME | -md NAME
481 --makedepend=NAME | -md=NAME
482 Use "NAME" for the MAKEDEPEND program.
483
484 -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME
485 -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME
486 Specify the location of the MITgcm ROOTDIR as "NAME".
487 By default, genamke will try to find the location by
488 looking in parent directories (up to the 5th parent).
489
490 -mods NAME | --mods NAME | -mo NAME | --mo NAME
491 -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME
492 Here, "NAME" specifies a list of directories that are
493 used for additional source code. Files found in the
494 "mods list" are given preference over files of the same
495 name found elsewhere.
496
497 -disable NAME | --disable NAME
498 -disable=NAME | --disable=NAME
499 Here "NAME" specifies a list of packages that we don't
500 want to use. If this violates package dependencies,
501 genamke will exit with an error message.
502
503 -enable NAME | --enable NAME
504 -enable=NAME | --enable=NAME
505 Here "NAME" specifies a list of packages that we wish
506 to specifically enable. If this violates package
507 dependencies, genamke will exit with an error message.
508
509 -standarddirs NAME | --standarddirs NAME
510 -standarddirs=NAME | --standarddirs=NAME
511 Here, "NAME" specifies a list of directories to be
512 used as the "standard" code.
513
514 -fortran NAME | --fortran NAME | -fc NAME | --fc NAME
515 -fc=NAME | --fc=NAME
516 Use "NAME" as the fortran compiler. By default, genmake
517 will search for a working compiler by trying a list of
518 "usual suspects" such as g77, f77, etc.
519
520 -cc NAME | --cc NAME | -cc=NAME | --cc=NAME
521 Use "NAME" as the C compiler. By default, genmake
522 will search for a working compiler by trying a list of
523 "usual suspects" such as gcc, c89, cc, etc.
524
525 -[no]ieee | --[no]ieee
526 Do or don't use IEEE numerics. Note that this option
527 *only* works if it is supported by the OPTFILE that
528 is being used.
529
530 -ts | --ts
531 Produce timing information per timestep
532
533 -mpi | --mpi
534 Include MPI header files and link to MPI libraries
535 -mpi=PATH | --mpi=PATH
536 Include MPI header files and link to MPI libraries using MPI_ROOT
537 set to PATH. i.e. Include files from \$PATH/include, link to libraries
538 from \$PATH/lib and use binaries from \$PATH/bin.
539
540 -bash NAME
541 Explicitly specify the Bourne or BASH shell to use
542
543 While it is most often a single word, the "NAME" variables specified
544 above can in many cases be a space-delimited string such as:
545
546 --enable pkg1 --enable 'pkg1 pkg2' --enable 'pkg1 pkg2 pkg3'
547 -mods=dir1 -mods='dir1' -mods='dir1 dir2 dir3'
548 -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'
549
550 which, depending upon your shell, may need to be single-quoted.
551
552 For more detailed genmake documentation, please see:
553
554 http://mitgcm.org/devel_HOWTO/
555
556 EOF
557
558 exit 1
559 }
560
561 # Build a CPP macro to automate calling C routines from FORTRAN
562 get_fortran_c_namemangling() {
563
564 #echo "FC_NAMEMANGLE = \"$FC_NAMEMANGLE\""
565 if test ! "x$FC_NAMEMANGLE" = x ; then
566 return 0
567 fi
568
569 default_nm="#define FC_NAMEMANGLE(X) X ## _"
570
571 cat > genmake_test.c <<EOF
572 void tcall( char * string ) { tsub( string ); }
573 EOF
574 $MAKE genmake_test.o >> genmake_warnings 2>&1
575 RETVAL=$?
576 if test "x$RETVAL" != x0 ; then
577 FC_NAMEMANGLE=$default_nm
578 cat <<EOF>> genmake_errors
579
580 WARNING: C test compile fails
581 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
582 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
583 EOF
584 return 1
585 fi
586 c_tcall=`nm genmake_test.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
587 RETVAL=$?
588 if test "x$RETVAL" != x0 ; then
589 FC_NAMEMANGLE=$default_nm
590 cat <<EOF>> genmake_warnings
591
592 WARNING: The "nm" command failed.
593 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
594 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
595 EOF
596 return 1
597 fi
598 cat > genmake_tcomp.$FS <<EOF
599 subroutine tcall( string )
600 character*(*) string
601 call tsub( string )
602 end
603 EOF
604 $FC $FFLAGS $DEFINES -c genmake_tcomp.$FS >> genmake_warnings 2>&1
605 RETVAL=$?
606 if test "x$RETVAL" != x0 ; then
607 FC_NAMEMANGLE=$default_nm
608 cat <<EOF>> genmake_warnings
609
610 WARNING: FORTRAN test compile fails -- please see "genmake_errors"
611 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
612 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
613 EOF
614 return 1
615 fi
616 f_tcall=`nm genmake_tcomp.o 2>/dev/null | grep 'T ' | grep tcall | cut -d ' ' -f 3`
617 RETVAL=$?
618 if test "x$RETVAL" != x0 ; then
619 FC_NAMEMANGLE=$default_nm
620 cat <<EOF>> genmake_warnings
621
622 WARNING: The "nm" command failed.
623 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
624 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
625 EOF
626 return 1
627 fi
628
629 c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
630 f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
631 c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
632 f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
633
634 nmangle="X"
635 if test "x$c_a" != "x$f_a" ; then
636 comm="echo x$f_a | sed -e 's|x$c_a||'"
637 a=`eval $comm`
638 nmangle="$a ## $nmangle"
639 fi
640 if test "x$c_b" != "x$f_b" ; then
641 comm="echo x$f_b | sed -e 's|x$c_b||'"
642 b=`eval $comm`
643 nmangle="$nmangle ## $b"
644 fi
645
646 FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) $nmangle"
647
648 # cleanup the testing files
649 rm -f genmake_tcomp.* genmake_test.*
650 }
651
652
653 check_HAVE_CLOC() {
654 get_fortran_c_namemangling
655 cat <<EOF > genmake_tc_1.c
656 $FC_NAMEMANGLE
657 #include <stdio.h>
658 #include <stdlib.h>
659 #include <unistd.h>
660 #include <assert.h>
661 #include <sys/time.h>
662 void FC_NAMEMANGLE(cloc) ( double *curtim )
663 {
664 struct timeval tv1;
665 gettimeofday(&tv1 , (void *)NULL );
666 *curtim = (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
667 *curtim = *curtim/1.E6;
668 }
669 EOF
670 make genmake_tc_1.o >> genmake_warnings 2>&1
671 RET_C=$?
672 cat <<EOF > genmake_tc_2.$FS
673 program hello
674 Real*8 wtime
675 external cloc
676 call cloc(wtime)
677 print *," HELLO WORLD", wtime
678 end program hello
679 EOF
680 $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_warnings 2>&1
681 RET_F=$?
682 test -x ./genmake_tc && ./genmake_tc >> genmake_warnings 2>&1
683 RETVAL=$?
684 if test "x$RETVAL" = x0 ; then
685 HAVE_CLOC=t
686 DEFINES="$DEFINES -DHAVE_CLOC"
687 fi
688 rm -f genmake_tc*
689 }
690
691
692 check_HAVE_STAT() {
693 get_fortran_c_namemangling
694 cat <<EOF > genmake_tc_1.c
695 $FC_NAMEMANGLE
696 #include <stdio.h>
697 #include <stdlib.h>
698 #include <unistd.h>
699 #include <sys/stat.h>
700 #include <sys/types.h>
701 void FC_NAMEMANGLE(tfsize) ( int *nbyte )
702 {
703 char name[512];
704 struct stat astat;
705
706 name[0] = 'a'; name[1] = '\0';
707 if (! stat(name, &astat))
708 *nbyte = (int)(astat.st_size);
709 else
710 *nbyte = -1;
711 }
712 EOF
713 make genmake_tc_1.o >> genmake_tc.log 2>&1
714 RET_C=$?
715 cat <<EOF > genmake_tc_2.$FS
716 program hello
717 integer nbyte
718 call tfsize(nbyte)
719 print *," HELLO WORLD", nbyte
720 end program hello
721 EOF
722 $FC $FFLAGS -o genmake_tc genmake_tc_2.$FS genmake_tc_1.o >> genmake_tc.log 2>&1
723 RET_F=$?
724 test -x ./genmake_tc && ./genmake_tc >> genmake_tc.log 2>&1
725 RETVAL=$?
726 if test "x$RETVAL" = x0 ; then
727 HAVE_STAT=t
728 DEFINES="$DEFINES -DHAVE_STAT"
729 fi
730 rm -f genmake_tc*
731 }
732
733
734 check_netcdf_libs() {
735 if test ! "x$SKIP_NETCDF_CHECK" = x ; then
736 return
737 fi
738 echo "" > genmake_tnc.log
739 cat <<EOF > genmake_tnc.F
740 program fgennc
741 #include "netcdf.inc"
742 EOF
743 if test ! "x$MPI" = x ; then
744 echo '#include "mpif.h"' >> genmake_tnc.F
745 fi
746 cat <<EOF >> genmake_tnc.F
747 integer iret, ncid, xid
748 iret = nf_create('genmake_tnc.nc', NF_CLOBBER, ncid)
749 IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
750 iret = nf_def_dim(ncid, 'X', 11, xid)
751 IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
752 iret = nf_close(ncid)
753 IF (iret .NE. NF_NOERR) write(*,*) NF_STRERROR(iret)
754 end
755 EOF
756 echo "Executing:" > genmake_tnc.log
757 echo " $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS" \
758 > genmake_tnc.log
759 RET_CPP=f
760 $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null \
761 && RET_CPP=t
762 if test "x$RET_CPP" = xf ; then
763 echo " WARNING: CPP failed to pre-process the netcdf test." \
764 > genmake_tnc.log
765 echo " Please check that \$INCLUDES is properly set." \
766 > genmake_tnc.log
767 fi
768 echo "Executing:" > genmake_tnc.log
769 echo " $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS" > genmake_tnc.log
770 echo " $LINK -o genmake_tnc.o $LIBS" > genmake_tnc.log
771 $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \
772 && $LINK -o genmake_tnc genmake_tnc.o $LIBS >> genmake_tnc.log 2>&1
773 RET_COMPILE=$?
774
775 #EH3 Remove test program execution for machines that either disallow
776 #EH3 execution or cannot support it (eg. cross-compilers)
777 #EH3
778 #EH3 test -x ./genmake_tnc && ./genmake_tnc >> genmake_tnc.log 2>&1
779 #EH3 RETVAL=$?
780 #EH3 if test "x$RET_COMPILE" = x0 -a "x$RETVAL" = x0 ; then
781
782 if test "x$RET_COMPILE" = x0 ; then
783 HAVE_NETCDF=t
784 else
785 # try again with "-lnetcdf" added to the libs
786 $CPP $DEFINES $INCLUDES genmake_tnc.F > genmake_tnc.$FS 2>/dev/null \
787 && $FC $FFLAGS $FOPTIM -c genmake_tnc.$FS >> genmake_tnc.log 2>&1 \
788 && $LINK -o genmake_tnc genmake_tnc.o $LIBS -lnetcdf >> genmake_tnc.log 2>&1
789 RET_COMPILE=$?
790 if test "x$RET_COMPILE" = x0 ; then
791 LIBS="$LIBS -lnetcdf"
792 HAVE_NETCDF=t
793 else
794 cat genmake_tnc.log >> genmake_warnings
795 fi
796 fi
797 rm -f genmake_tnc*
798 }
799
800
801
802 ###############################################################################
803 # Sequential part of script starts here
804 ###############################################################################
805
806 # Set defaults here
807 COMMANDL="$0 $@"
808
809 PLATFORM=
810 LN=
811 S64=
812 KPP=
813 #FC=
814 #CC=gcc
815 #CPP=
816 LINK=
817 DEFINES=
818 PACKAGES=
819 ENABLE=
820 DISABLE=
821 # MAKEFILE=
822 # MAKEDEPEND=
823 PDEPEND=
824 DUMPSTATE=t
825 PDEFAULT=
826 OPTFILE=
827 INCLUDES="-I. $INCLUDES"
828 FFLAGS=
829 FOPTIM=
830 CFLAGS=
831 KFLAGS1=
832 KFLAGS2=
833 #LDADD=
834 LIBS=
835 KPPFILES=
836 NOOPTFILES=
837 NOOPTFLAGS=
838 MPI=
839 MPIPATH=
840 TS=
841
842 # DEFINES checked by test compilation or command-line
843 HAVE_SYSTEM=
844 HAVE_FDATE=
845 FC_NAMEMANGLE=
846 HAVE_CLOC=
847 HAVE_STAT=
848 HAVE_NETCDF=
849 HAVE_ETIME=
850 IGNORE_TIME=
851
852 MODS=
853 TOOLSDIR=
854 SOURCEDIRS=
855 INCLUDEDIRS=
856 STANDARDDIRS="USE_THE_DEFAULT"
857
858 G2ARGS=
859 BASH=
860 PWD=`pwd`
861 test "x$MAKE" = x && MAKE=make
862 test "x$AWK" = x && AWK=awk
863 THISHOST=`hostname`
864 THISCWD=`pwd`
865 THISDATE=`date`
866 THISUSER=`echo $USER`
867 THISVER=
868 MACHINE=`uname -a`
869 EXECUTABLE=
870 EXEHOOK=
871 EXEDIR=
872 PACKAGES_CONF=
873 IEEE=
874 if test "x$MITGCM_IEEE" != x ; then
875 IEEE=$MITGCM_IEEE
876 fi
877 FS=
878 FS90=
879
880 AUTODIFF_PKG_USED=f
881 AD_OPTFILE=
882 TAF=
883 AD_TAF_FLAGS=
884 FTL_TAF_FLAGS=
885 SVD_TAF_FLAGS=
886 TAF_EXTRA=
887 TAMC=
888 AD_TAMC_FLAGS=
889 FTL_TAF_FLAGS=
890 SVD_TAMC_FLAGS=
891 TAMC_EXTRA=
892
893
894 # The following state can be set directly by command-line switches
895 gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE"
896 gm_s2="FC CPP IEEE TS MPI JAM DUMPSTATE STANDARDDIRS"
897
898 # The following state is not directly set by command-line switches
899 gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
900 gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
901 gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOST THISUSER THISDATE THISVER MACHINE"
902 gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
903 gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE HAVE_ETIME"
904
905 # The following are all related to adjoint/tangent-linear stuff
906 gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
907 gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
908 gm_s12="TAF_EXTRA TAMC_EXTRA"
909
910 gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
911 gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
912
913 cat <<EOF
914
915 GENMAKE :
916
917 A program for GENerating MAKEfiles for the MITgcm project. For a
918 quick list of options, use "genmake -h" or for more detail see:
919
920 http://mitgcm.org/devel_HOWTO/
921
922 EOF
923
924 echo "=== Processing options files and arguments ==="
925 gm_local="genmake_local"
926 modsCount=0
927 for i in . $MODS ; do
928 if test -r $i/$gm_local ; then
929 . $i/$gm_local
930 break
931 fi
932 let modsCount=modsCount+1
933 done
934 if test modsCount -gt 1 ; then
935 echo "ERROR: some uses of MODS break with more than one directory specified"
936 exit -1;
937 fi
938 printf " getting local config information: "
939 if test -f $gm_local ; then
940 echo "using $gm_local"
941 . $gm_local
942 # echo "DISABLE=$DISABLE"
943 # echo "ENABLE=$ENABLE"
944 else
945 echo "none found"
946 fi
947
948 #echo "$0::$1:$2:$3:$4:$5:$6:$7:"
949 #OPTIONS=
950 #n=0
951 #for i ; do
952 # echo "$i $n"
953 # setvar="OPTIONS[$n]='$i'"
954 # # echo " $setvar"
955 # eval "$setvar"
956 # n=$(( $n + 1 ))
957 #done
958 #parse_options
959 ac_prev=
960 for ac_option in "$@" ; do
961
962 G2ARGS="$G2ARGS \"$ac_option\""
963
964 # If the previous option needs an argument, assign it.
965 if test -n "$ac_prev"; then
966 eval "$ac_prev=\$ac_option"
967 ac_prev=
968 continue
969 fi
970
971 ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
972
973 case $ac_option in
974
975 -help | --help | -h | --h)
976 usage ;;
977
978 -nooptfile | --nooptfile)
979 OPTFILE="NONE" ;;
980 -optfile | --optfile | -of | --of)
981 ac_prev=OPTFILE ;;
982 -optfile=* | --optfile=* | -of=* | --of=*)
983 OPTFILE=$ac_optarg ;;
984
985 -adoptfile | --adoptfile | -adof | --adof)
986 ac_prev=AD_OPTFILE ;;
987 -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
988 AD_OPTFILE=$ac_optarg ;;
989
990 -pdepend | --pdepend)
991 ac_prev=PDEPEND ;;
992 -pdepend=* | --pdepend=*)
993 PDEPEND=$ac_optarg ;;
994
995 -pdefault | --pdefault)
996 ac_prev=PDEFAULT ;;
997 -pdefault=* | --pdefault=*)
998 PDEFAULT=$ac_optarg ;;
999
1000 -make | --make | -m | --m)
1001 ac_prev=MAKE ;;
1002 -make=* | --make=* | -m=* | --m=*)
1003 MAKE=$ac_optarg ;;
1004
1005 -bash | --bash)
1006 ac_prev=BASH ;;
1007 -bash=* | --bash=*)
1008 BASH=$ac_optarg ;;
1009
1010 -makedepend | --makedepend | -md | --md)
1011 ac_prev=MAKEDEPEND ;;
1012 -makedepend=* | --makedepend=* | -md=* | --md=*)
1013 MAKEDEPEND=$ac_optarg ;;
1014
1015 -makefile | --makefile | -ma | --ma)
1016 ac_prev=MAKEFILE ;;
1017 -makefile=* | --makefile=* | -ma=* | --ma=*)
1018 MAKEFILE=$ac_optarg ;;
1019
1020 -platform | --platform | -pl | --pl | -platform=* | --platform=* | -pl=* | --pl=*)
1021 echo "ERROR: The platform option has been removed. Please specify"
1022 echo " the build options using the \"optfile\" mechanism."
1023 echo
1024 usage
1025 ;;
1026
1027 -rootdir | --rootdir | -rd | --rd)
1028 ac_prev=ROOTDIR ;;
1029 -rootdir=* | --rootdir=* | -rd=* | --rd=*)
1030 ROOTDIR=$ac_optarg ;;
1031
1032 -mods | --mods | -mo | --mo)
1033 ac_prev=MODS ;;
1034 -mods=* | --mods=* | -mo=* | --mo=*)
1035 MODS=$ac_optarg ;;
1036
1037 -disable | --disable)
1038 ac_prev=DISABLE ;;
1039 -disable=* | --disable=*)
1040 DISABLE=$ac_optarg ;;
1041
1042 -enable | --enable)
1043 ac_prev=ENABLE ;;
1044 -enable=* | --enable=*)
1045 ENABLE=$ac_optarg ;;
1046
1047 -standarddirs | --standarddirs)
1048 ac_prev=STANDARDDIRS ;;
1049 -standarddirs=* | --standarddirs=*)
1050 STANDARDDIRS=$ac_optarg ;;
1051
1052 # -cpp | --cpp)
1053 # ac_prev=cpp ;;
1054 # -cpp=* | --cpp=*)
1055 # CPP=$ac_optarg ;;
1056
1057 -cc | --cc)
1058 ac_prev=CC ;;
1059 -cc=* | --cc=*)
1060 CC=$ac_optarg ;;
1061
1062 -fortran | --fortran | -fc | --fc)
1063 ac_prev=FC ;;
1064 -fc=* | --fc=*)
1065 FC=$ac_optarg ;;
1066
1067 -fs | --fs)
1068 ac_prev=FS ;;
1069 -fs=* | --fs=*)
1070 FS=$ac_optarg ;;
1071
1072 -fs90 | --fs90)
1073 ac_prev=FS90 ;;
1074 -fs90=* | --fs90=*)
1075 FS90=$ac_optarg ;;
1076
1077 -ieee | --ieee)
1078 IEEE=true ;;
1079 -noieee | --noieee)
1080 IEEE= ;;
1081
1082 -ts | --ts)
1083 TS=true ;;
1084
1085 -mpi | --mpi)
1086 MPI=true ;;
1087 -mpi=* | --mpi=*)
1088 MPIPATH=$ac_optarg
1089 MPI=true ;;
1090
1091 # -jam | --jam)
1092 # JAM=1 ;;
1093 # -nojam | --nojam)
1094 # JAM=0 ;;
1095
1096 -ds | --ds)
1097 DUMPSTATE=t ;;
1098
1099 -taf_extra | --taf_extra)
1100 ac_prev=TAF_EXTRA ;;
1101 -taf_extra=* | --taf_extra=*)
1102 TAF_EXTRA=$ac_optarg ;;
1103
1104 -tamc_extra | --tamc_extra)
1105 ac_prev=TAMC_EXTRA ;;
1106 -tamc_extra=* | --tamc_extra=*)
1107 TAMC_EXTRA=$ac_optarg ;;
1108
1109 -ignoretime | -ignore_time | --ignoretime | --ignore_time)
1110 IGNORE_TIME="-DIGNORE_TIME" ;;
1111
1112 -*)
1113 echo "Error: unrecognized option: "$ac_option
1114 usage
1115 ;;
1116
1117 *)
1118 echo "Error: unrecognized argument: "$ac_option
1119 usage
1120 ;;
1121
1122 esac
1123
1124 done
1125
1126
1127 if test -f ./.genmakerc ; then
1128 echo
1129 echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
1130 echo " file. This file format is no longer supported. Please see:"
1131 echo
1132 echo " http://mitgcm.org/devel_HOWTO/"
1133 echo
1134 echo " for directions on how to setup and use the new \"genmake2\" input"
1135 echo " files and send an email to MITgcm-support@mitgcm.org if you want help."
1136 echo
1137 fi
1138
1139 # Find the MITgcm ${ROOTDIR}
1140 if test "x${ROOTDIR}" = x ; then
1141 tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1142 if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
1143 ROOTDIR=".."
1144 else
1145 for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
1146 if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
1147 ROOTDIR=$d
1148 printf "Warning: ROOTDIR was not specified but there appears to be"
1149 echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
1150 break
1151 fi
1152 done
1153 fi
1154 fi
1155 if test "x${ROOTDIR}" = x ; then
1156 echo "Error: Cannot determine ROOTDIR for MITgcm code."
1157 echo " Please specify a ROOTDIR using either an options "
1158 echo " file or a command-line option."
1159 exit 1
1160 fi
1161 if test ! -d ${ROOTDIR} ; then
1162 echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
1163 exit 1
1164 fi
1165
1166 # Find the MITgcm ${THISVER}
1167 if test -f "${ROOTDIR}/doc/tag-index" ; then
1168 THISVER=`grep '^checkpoint' ${ROOTDIR}/doc/tag-index | head -1`
1169 fi
1170
1171 if test "x$MAKEFILE" = x ; then
1172 MAKEFILE="Makefile"
1173 fi
1174
1175 echo " getting OPTFILE information: "
1176 if test "x${OPTFILE}" = x ; then
1177 if test "x$MITGCM_OF" = x ; then
1178 echo "Warning: no OPTFILE specified so we'll look for possible settings"
1179 printf "\n=== Searching for possible settings for OPTFILE ===\n"
1180 find_possible_configs
1181 else
1182 OPTFILE=$MITGCM_OF
1183 fi
1184 fi
1185 if test "x$OPTFILE" != xNONE ; then
1186 if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
1187 echo " using OPTFILE=\"$OPTFILE\""
1188 . "$OPTFILE"
1189 RETVAL=$?
1190 if test "x$RETVAL" != x0 ; then
1191 printf "Error: failed to source OPTFILE \"$OPTFILE\""
1192 echo "--please check that variable syntax is bash-compatible"
1193 exit 1
1194 fi
1195 if test "x$DUMPSTATE" != xf ; then
1196 cp -f $OPTFILE "genmake_optfile"
1197 fi
1198 else
1199 echo "Error: can't read OPTFILE=\"$OPTFILE\""
1200 exit 1
1201 fi
1202 fi
1203
1204 echo " getting AD_OPTFILE information: "
1205 if test "x${AD_OPTFILE}" = x ; then
1206 if test "x$MITGCM_AD_OF" = x ; then
1207 AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
1208 else
1209 AD_OPTFILE=$MITGCM_AD_OF
1210 fi
1211 fi
1212 if test "x${AD_OPTFILE}" != xNONE ; then
1213 if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
1214 echo " using AD_OPTFILE=\"$AD_OPTFILE\""
1215 . "$AD_OPTFILE"
1216 RETVAL=$?
1217 if test "x$RETVAL" != x0 ; then
1218 printf "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
1219 echo "--please check that variable syntax is bash-compatible"
1220 exit 1
1221 fi
1222 if test "x$DUMPSTATE" != xf ; then
1223 cp -f $AD_OPTFILE "genmake_ad_optfile"
1224 fi
1225 else
1226 echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
1227 exit 1
1228 fi
1229 fi
1230
1231 #====================================================================
1232 # Set default values if not set by the optfile
1233 #
1234 # Check that FC, CC, LINK, CPP, S64, LN, and MAKE are defined. If not,
1235 # either set defaults or complain and abort!
1236 if test ! "x$BASH" = x ; then
1237 # add a trailing space so that it works within the Makefile syntax (see below)
1238 BASH="$BASH "
1239 fi
1240 if test "x$FC" = x ; then
1241 cat <<EOF 1>&2
1242
1243 Error: no Fortran compiler: please specify using one of the following:
1244 1) within the options file ("FC=...") as specified by "-of=OPTFILE"
1245 2) the "-fc=XXX" command-line option
1246 3) the "./genmake_local" file
1247 EOF
1248 exit 1
1249 fi
1250 if test "x$CC" = x ; then
1251 CC=cc
1252 # cat <<EOF 1>&2
1253 # Error: no C compiler: please specify using one of the following:
1254 # 1) within the options file ("CC=...") as specified by "-of=OPTFILE"
1255 # 2) the "-cc=XXX" command-line option
1256 # 3) the "./genmake_local" file
1257 # EOF
1258 # exit 1
1259 fi
1260 if test "x$LINK" = x ; then
1261 LINK=$FC
1262 fi
1263 if test "x$MAKE" = x ; then
1264 MAKE="make"
1265 fi
1266 if test "x$CPP" = x ; then
1267 CPP=cpp
1268 fi
1269 #EH3 === UGLY ===
1270 # The following is an ugly little hack to check for $CPP in /lib/ and
1271 # it should eventually be replaced with a more general function that
1272 # searches a combo of the user's path and a list of "usual suspects"
1273 # to find the correct location for binaries such as $CPP.
1274 for i in " " "/lib/" ; do
1275 echo "#define A a" | $i$CPP > test_cpp 2>&1 && CPP=$i$CPP
1276 done
1277 #EH3 === UGLY ===
1278 echo "#define A a" | $CPP > test_cpp 2>&1
1279 RETVAL=$?
1280 if test "x$RETVAL" != x0 ; then
1281 cat <<EOF 1>&2
1282
1283 Error: C pre-processor "$CPP" failed the test case: please specify using:
1284
1285 1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
1286 2) the "./genmake_local" file
1287 3) with the CPP environment variable
1288
1289 EOF
1290 exit 1
1291 else
1292 rm -f test_cpp
1293 fi
1294 look_for_makedepend
1295 if test "x$LN" = x ; then
1296 LN="ln -s"
1297 fi
1298 echo "test" > genmake_test_ln
1299 $LN genmake_test_ln genmake_tlink
1300 RETVAL=$?
1301 if test "x$RETVAL" != x0 ; then
1302 cat <<EOF 1>&2
1303
1304 Error: The command "ln -s" failed -- please specify a working soft-link
1305 command in the optfile.
1306
1307 EOF
1308 exit 1
1309 fi
1310 rm -f genmake_test_ln genmake_tlink
1311
1312 # Check for broken *.F/*.f handling and fix if possible
1313 check_for_broken_Ff
1314
1315 if test ! "x$MPI" = x ; then
1316 echo " Turning on MPI cpp macros"
1317 DEFINES="$DEFINES -DALLOW_USE_MPI -DALWAYS_USE_MPI"
1318 fi
1319
1320 if test ! "x$TS" = x ; then
1321 echo " Turning on timing per timestep"
1322 DEFINES="$DEFINES -DTIME_PER_TIMESTEP"
1323 fi
1324
1325 printf "\n=== Checking system libraries ===\n"
1326 printf " Do we have the system() command using $FC... "
1327 cat > genmake_tcomp.$FS <<EOF
1328 program hello
1329 call system('echo hi')
1330 end
1331 EOF
1332 $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1333 RETVAL=$?
1334 if test "x$RETVAL" = x0 ; then
1335 HAVE_SYSTEM=t
1336 DEFINES="$DEFINES -DHAVE_SYSTEM"
1337 echo "yes"
1338 else
1339 HAVE_SYSTEM=
1340 echo "no"
1341 fi
1342 rm -f genmake_tcomp*
1343
1344 printf " Do we have the fdate() command using $FC... "
1345 cat > genmake_tcomp.$FS <<EOF
1346 program hello
1347 CHARACTER(128) string
1348 string = ' '
1349 call fdate( string )
1350 print *, string
1351 end
1352 EOF
1353 $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1354 RETVAL=$?
1355 if test "x$RETVAL" = x0 ; then
1356 HAVE_FDATE=t
1357 DEFINES="$DEFINES -DHAVE_FDATE"
1358 echo "yes"
1359 else
1360 HAVE_FDATE=
1361 echo "no"
1362 fi
1363 rm -f genmake_tcomp*
1364
1365 printf " Do we have the etime() command using $FC... "
1366 cat > genmake_tcomp.$FS <<EOF
1367 program hello
1368 REAL*4 ACTUAL, TARRAY(2)
1369 EXTERNAL ETIME
1370 REAL*4 ETIME
1371 actual = etime( tarray )
1372 print *, tarray
1373 end
1374 EOF
1375 $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.$FS > genmake_tcomp.log 2>&1
1376 RETVAL=$?
1377 if test "x$RETVAL" = x0 ; then
1378 HAVE_ETIME=t
1379 DEFINES="$DEFINES -DHAVE_ETIME"
1380 echo "yes"
1381 else
1382 HAVE_ETIME=
1383 echo "no"
1384 fi
1385 rm -f genmake_tcomp*
1386
1387 printf " Can we call simple C routines (here, \"cloc()\") using $FC... "
1388 check_HAVE_CLOC
1389 if test "x$HAVE_CLOC" != x ; then
1390 echo "yes"
1391 else
1392 echo "no"
1393 fi
1394 rm -f genmake_t*
1395
1396 printf " Can we use stat() through C calls... "
1397 check_HAVE_STAT
1398 if test "x$HAVE_STAT" != x ; then
1399 echo "yes"
1400 else
1401 echo "no"
1402 fi
1403 rm -f genmake_t*
1404
1405 printf " Can we create NetCDF-enabled binaries... "
1406 check_netcdf_libs
1407 if test "x$HAVE_NETCDF" != x ; then
1408 echo "yes"
1409 else
1410 echo "no"
1411 fi
1412 DEFINES="$DEFINES $IGNORE_TIME"
1413
1414 printf "\n=== Setting defaults ===\n"
1415 printf " Adding MODS directories: "
1416 for d in $MODS ; do
1417 if test ! -d $d ; then
1418 echo
1419 echo "Error: MODS directory \"$d\" not found!"
1420 exit 1
1421 else
1422 printf " $d"
1423 SOURCEDIRS="$SOURCEDIRS $d"
1424 INCLUDEDIRS="$INCLUDEDIRS $d"
1425 fi
1426 done
1427 echo
1428
1429 if test "x${PLATFORM}" = x ; then
1430 PLATFORM=$p_PLATFORM
1431 fi
1432
1433 if test "x${EXEDIR}" = x ; then
1434 tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
1435 if test "x$tmp" = "xbin" -a -d ../exe -a $ROOTDIR = .. ; then
1436 EXEDIR=../exe
1437 else
1438 EXEDIR=.
1439 fi
1440 fi
1441 if test ! -d ${EXEDIR} ; then
1442 echo "Error: the specified EXEDIR (\"$EXEDIR\") does not exist!"
1443 exit 1
1444 fi
1445
1446 if test "x${TOOLSDIR}" = x ; then
1447 TOOLSDIR="$ROOTDIR/tools"
1448 fi
1449 if test ! -d ${TOOLSDIR} ; then
1450 echo "Error: the specified TOOLSDIR (\"$TOOLSDIR\") does not exist!"
1451 exit 1
1452 fi
1453 if test "x$S64" = x ; then
1454 echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.sh > /dev/null 2>&1
1455 RETVAL=$?
1456 if test "x${RETVAL}" = x0 ; then
1457 S64='$(TOOLSDIR)/set64bitConst.sh'
1458 else
1459 echo "3.0 _d 3" | ${TOOLSDIR}/set64bitConst.csh > /dev/null 2>&1
1460 RETVAL=$?
1461 if test "x${RETVAL}" = x0 ; then
1462 S64='$(TOOLSDIR)/set64bitConst.csh'
1463 else
1464 cat <<EOF
1465
1466 ERROR: neither of the two default scripts:
1467
1468 ${TOOLSDIR}/set64bitConst.sh
1469 ${TOOLSDIR}/set64bitConst.csh
1470
1471 are working so please check paths or specify (with \$S64) a
1472 working version of this script.
1473
1474 EOF
1475 exit 1
1476 fi
1477 fi
1478 fi
1479 THIS_SCRIPT=`echo ${0} | sed 's:'$TOOLSDIR':\$(TOOLSDIR):'`
1480
1481 EXECUTABLE=${EXECUTABLE:-mitgcmuv}
1482
1483 # We have a special set of source files in eesupp/src which are
1484 # generated from some template source files. We'll make them first so
1485 # they appear as regular source code
1486 if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
1487 echo " Making source files in eesupp from templates"
1488 ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
1489 RETVAL=$?
1490 if test "x${RETVAL}" = x0 ; then
1491 rm -f make_eesupp.errors
1492 else
1493 echo "Error: problem encountered while building source files in eesupp:"
1494 cat make_eesupp.errors 1>&2
1495 exit 1
1496 fi
1497 fi
1498
1499 #same for exch2
1500 if test -r $ROOTDIR"/pkg/exch2/Makefile" ; then
1501 echo " Making source files in exch2 from templates"
1502 ( cd $ROOTDIR"/pkg/exch2/" && $MAKE ) > make_exch2.errors 2>&1
1503 RETVAL=$?
1504 if test "x${RETVAL}" = x0 ; then
1505 rm -f make_exch2.errors
1506 else
1507 echo "Error: problem encountered while building source files in exch2:"
1508 cat make_exch2.errors 1>&2
1509 exit 1
1510 fi
1511 fi
1512
1513 printf "\n=== Determining package settings ===\n"
1514 if test "x${PDEPEND}" = x ; then
1515 tmp=$ROOTDIR"/pkg/pkg_depend"
1516 if test -r $tmp ; then
1517 PDEPEND=$tmp
1518 else
1519 echo "Warning: No package dependency information was specified."
1520 echo " Please check that ROOTDIR/pkg/pkg_depend exists."
1521 fi
1522 else
1523 if test ! -r ${PDEPEND} ; then
1524 echo "Error: can't read package dependency info from PDEPEND=\"$PDEPEND\""
1525 exit 1
1526 fi
1527 fi
1528 echo " getting package dependency info from $PDEPEND"
1529 # Strip the comments and then convert the dependency file into
1530 # two arrays: PNAME, DNAME
1531 cat $PDEPEND | sed -e 's/#.*$//g' \
1532 | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
1533 > ./.pd_tmp
1534 RETVAL=$?
1535 if test ! "x${RETVAL}" = x0 ; then
1536 echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
1537 exit 1
1538 fi
1539 . ./.pd_tmp
1540 rm -f ./.pd_tmp
1541
1542 # Search for default packages. Note that a "$ROOTDIR/pkg/pkg_groups"
1543 # file should eventually be added so that, for convenience, one can
1544 # specify groups of packages using names like "ocean" and "atmosphere".
1545 echo " checking default package list: "
1546 if test "x${PDEFAULT}" = x ; then
1547 for i in "." $MODS ; do
1548 if test -r $i"/packages.conf" ; then
1549 PDEFAULT=$i"/packages.conf"
1550 break
1551 fi
1552 done
1553 fi
1554 if test "x${PDEFAULT}" = x ; then
1555 PDEFAULT="$ROOTDIR/pkg/pkg_default"
1556 fi
1557 if test "x${PDEFAULT}" = xNONE ; then
1558 echo " default packages file disabled"
1559 else
1560 if test ! -r $PDEFAULT ; then
1561 echo "Warning: can't read default packages from PDEFAULT=\"$PDEFAULT\""
1562 else
1563 echo " using PDEFAULT=\"$PDEFAULT\""
1564 # Strip the comments and add all the names
1565 def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
1566 RETVAL=$?
1567 if test "x${RETVAL}" != x0 ; then
1568 printf "Error: can't parse default package list "
1569 echo "-- please check PDEFAULT=\"$PDEFAULT\""
1570 exit 1
1571 fi
1572 for i in $def ; do
1573 PACKAGES="$PACKAGES $i"
1574 done
1575 echo " before group expansion packages are: $PACKAGES"
1576 RET=1
1577 while test $RET = 1 ; do expand_pkg_groups; RET=$?; done
1578 echo " after group expansion packages are: $PACKAGES"
1579 fi
1580 fi
1581
1582 echo " applying DISABLE settings"
1583 for i in $PACKAGES ; do
1584 echo $i >> ./.tmp_pack
1585 done
1586 for i in `grep "-" ./.tmp_pack` ; do
1587 j=`echo $i | sed 's/[-]//'`
1588 DISABLE="$DISABLE $j"
1589 done
1590 pack=
1591 for p in $PACKAGES ; do
1592 addit="t"
1593 for d in $DISABLE ; do
1594 if test "x$p" = "x$d" ; then
1595 addit="f"
1596 fi
1597 done
1598 if test "x$addit" = xt ; then
1599 pack="$pack $p"
1600 fi
1601 done
1602 PACKAGES="$pack"
1603 echo " applying ENABLE settings"
1604 echo "" > ./.tmp_pack
1605 PACKAGES="$PACKAGES $ENABLE"
1606 # Test if each explicitly referenced package exists
1607 for i in $PACKAGES ; do
1608 j=`echo $i | sed 's/[-+]//'`
1609 if test ! -d "$ROOTDIR/pkg/$j" ; then
1610 echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
1611 exit 1
1612 fi
1613 echo $i >> ./.tmp_pack
1614 done
1615 PACKAGES=
1616 for i in `grep -v "-" ./.tmp_pack | sort | uniq` ; do
1617 PACKAGES="$PACKAGES $i"
1618 done
1619 rm -f ./.tmp_pack
1620 echo " packages are: $PACKAGES"
1621
1622 # Check availability of NetCDF and then either build the MNC template
1623 # files or delete mnc from the list of available packages.
1624 echo $PACKAGES | grep ' mnc ' > /dev/null 2>&1
1625 RETVAL=$?
1626 if test "x$RETVAL" = x0 ; then
1627 if test "x$HAVE_NETCDF" != xt ; then
1628 cat <<EOF
1629
1630 *********************************************************************
1631 WARNING: the "mnc" package was enabled but tests failed to compile
1632 NetCDF applications. Please check that:
1633
1634 1) NetCDF is correctly installed for this compiler and
1635 2) the LIBS variable (within the "optfile") specifies the correct
1636 NetCDF library to link against.
1637
1638 Due to this failure, the "mnc" package is now DISABLED.
1639 *********************************************************************
1640
1641 EOF
1642 PACKAGES=`echo $PACKAGES | sed -e 's/mnc//g'`
1643 DISABLE="$DISABLE mnc"
1644 else
1645 ( cd $ROOTDIR"/pkg/mnc" && $MAKE testclean && $MAKE templates ) > make_mnc.errors 2>&1
1646 RETVAL=$?
1647 if test "x${RETVAL}" = x0 ; then
1648 rm -f make_mnc.errors
1649 else
1650 echo "Error: problem encountered while building source files in pkg/mnc:"
1651 cat make_mnc.errors 1>&2
1652 exit 1
1653 fi
1654 fi
1655 fi
1656
1657 echo " applying package dependency rules"
1658 ck=
1659 while test "x$ck" != xtt ; do
1660 i=0
1661 # rtot=${#PNAME[@]}
1662 rtot=$nname
1663 while test $i -lt $rtot ; do
1664
1665 # Is $pname in the current $PACKAGES list?
1666 # pname=${PNAME[$i]}
1667 tmp="pname=\"\$PNAME_$i\""
1668 eval $tmp
1669 pin="f"
1670 for p in $PACKAGES ; do
1671 if test "x$p" = "x$pname" ; then
1672 pin="t"
1673 fi
1674 done
1675
1676 # Is the DNAME entry a (+) or (-) rule ?
1677 tmp="dname=\"\$DNAME_$i\""
1678 eval $tmp
1679 plus="-"
1680 echo $dname | grep '^+' > /dev/null 2>&1
1681 RETVAL=$?
1682 if test "x$RETVAL" = x0 ; then
1683 plus="+"
1684 fi
1685
1686 # Is $dname in the current $PACKAGES list?
1687 dname=`echo $dname | sed -e 's/^[+-]//'`
1688 din="f"
1689 for p in $PACKAGES ; do
1690 if test "x$p" = "x$dname" ; then
1691 din="t"
1692 fi
1693 done
1694
1695 # Do we need to add $dname according to the dependency rules?
1696 if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
1697 in_dis="f"
1698 for dis in $DISABLE ; do
1699 if test "x$dis" = "x$dname" ; then
1700 in_dis="t"
1701 fi
1702 done
1703 if test "x$in_dis" = xt ; then
1704 echo "Error: can't satisfy package dependencies:"
1705 echo " \"$dname\" is required by the dependency rules"
1706 echo " but is disallowed by the DISABLE settings"
1707 exit 1
1708 else
1709 PACKAGES="$PACKAGES $dname"
1710 ck=
1711 fi
1712 fi
1713
1714 # Do we need to get rid of $dname according to the dependency rules?
1715 if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
1716 echo "Error: can't satisfy package dependencies:"
1717 echo " \"$pname\" was requested but is disallowed by"
1718 echo " the dependency rules for \"$dname\""
1719 exit 1
1720 fi
1721 i=`echo "$i + 1" | bc -l`
1722 #i=$(( $i + 1 ))
1723 done
1724 ck=$ck"t"
1725 done
1726 echo " packages are: $PACKAGES"
1727 for i in $PACKAGES ; do
1728 adr="$ROOTDIR/pkg/$i"
1729 if test -d $adr ; then
1730 SOURCEDIRS="$SOURCEDIRS $adr"
1731 INCLUDEDIRS="$INCLUDEDIRS $adr"
1732 if test "x$i" = xautodiff ; then
1733 AUTODIFF_PKG_USED=t
1734 fi
1735 else
1736 echo "Error: the directory \"$adr\" for package $i doesn't exist"
1737 exit 1
1738 fi
1739 done
1740
1741 # Create a list of #define and #undef to enable/disable packages
1742 PACKAGES_DOT_H=PACKAGES_CONFIG.h
1743 # The following UGLY HACK sets multiple "#undef"s and it needs to go
1744 # away. On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
1745 # file would eventually be split up so that all package-related #define
1746 # statements could be separated and handled only by genmake.
1747 names=`ls -1 "$ROOTDIR/pkg"`
1748 all_pack=
1749 DISABLED_PACKAGES=
1750 for n in $names ; do
1751 if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
1752 has_pack="f"
1753 for pack in $PACKAGES ; do
1754 if test "x$pack" = "x$n" ; then
1755 has_pack="t"
1756 break
1757 fi
1758 done
1759 if test "x$has_pack" = xf ; then
1760 undef=`echo "ALLOW_$n" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1761 DISABLED_PACKAGES="$DISABLED_PACKAGES -U$undef"
1762 fi
1763 fi
1764 done
1765 ENABLED_PACKAGES=
1766 for i in $PACKAGES ; do
1767 def=`echo "ALLOW_$i" | sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
1768 ENABLED_PACKAGES="$ENABLED_PACKAGES -D$def"
1769 #eh3 DEFINES="$DEFINES -D$def"
1770
1771 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
1772 case $i in
1773 aim_v23)
1774 ENABLED_PACKAGES="$ENABLED_PACKAGES -DALLOW_AIM"
1775 echo "Warning: ALLOW_AIM is set to enable aim_v23."
1776 ;;
1777 esac
1778 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
1779
1780 done
1781
1782 echo " Adding STANDARDDIRS"
1783 BUILDDIR=${BUILDDIR:-.}
1784 if test "x$STANDARDDIRS" = xUSE_THE_DEFAULT ; then
1785 STANDARDDIRS="eesupp model"
1786 fi
1787 if test "x$STANDARDDIRS" != x ; then
1788 for d in $STANDARDDIRS ; do
1789 adr="$ROOTDIR/$d/src"
1790 if test ! -d $adr ; then
1791 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1792 echo " is correct and that you correctly specified the STANDARDDIRS option"
1793 exit 1
1794 else
1795 SOURCEDIRS="$SOURCEDIRS $adr"
1796 fi
1797 adr="$ROOTDIR/$d/inc"
1798 if test ! -d $adr ; then
1799 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1800 echo " is correct and that you correctly specified the STANDARDDIRS option"
1801 exit 1
1802 else
1803 INCLUDEDIRS="$INCLUDEDIRS $adr"
1804 fi
1805 done
1806 fi
1807
1808 echo " Searching for *OPTIONS.h files in order to warn about the presence"
1809 echo " of \"#define \"-type statements that are no longer allowed:"
1810 CPP_OPTIONS=
1811 CPP_EEOPTIONS=
1812 spaths=". $INCLUDEDIRS"
1813 names=`ls -1 "$ROOTDIR/pkg"`
1814 for i in $spaths ; do
1815 try="$i/CPP_OPTIONS.h"
1816 if test -f $try -a -r $try -a "x$CPP_OPTIONS" = x ; then
1817 echo " found CPP_OPTIONS=\"$try\""
1818 CPP_OPTIONS="$try"
1819 # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1820 for n in $names ; do
1821 test_for_package_in_cpp_options $CPP_OPTIONS $n
1822 done
1823 fi
1824 try="$i/CPP_EEOPTIONS.h"
1825 if test -f $try -a -r $try -a "x$CPP_EEOPTIONS" = x ; then
1826 echo " found CPP_EEOPTIONS=\"$try\""
1827 # New safety test: make sure MPI is not determined by CPP_EEOPTIONS.h
1828 #**** not yet enabled ****
1829 # test_for_mpi_in_cpp_eeoptions $try
1830 #**** not yet enabled ****
1831 CPP_EEOPTIONS="$try"
1832 fi
1833 done
1834 if test "x$CPP_OPTIONS" = x ; then
1835 echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
1836 exit 1
1837 fi
1838
1839 # Here, we build the list of files to be "run through" the adjoint
1840 # compiler.
1841 if test -f ./adSrcFiles.tmp ; then
1842 rm -f ./adSrcFiles.tmp
1843 fi
1844 echo " Creating the list of files for the adjoint compiler."
1845 for i in $SOURCEDIRS ; do
1846 list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
1847 for j in $list_files ; do
1848 cat $i/$j >> adSrcFiles.tmp
1849 done
1850 done
1851
1852 if test ! "x"$FS = "x.f" ; then
1853 cat adSrcFiles.tmp | sed -e "s/\.f/.$FS/g" > adSrcFiles.tmp_f
1854 mv -f adSrcFiles.tmp_f adSrcFiles.tmp
1855 fi
1856
1857 echo
1858 echo "=== Creating the Makefile ==="
1859 echo " setting INCLUDES"
1860 for i in $INCLUDEDIRS ; do
1861 if test ! -d $i ; then
1862 echo "Warning: can't find INCLUDEDIRS=\"$i\""
1863 fi
1864 done
1865
1866 echo " Determining the list of source and include files"
1867 rm -rf .links.tmp
1868 mkdir .links.tmp
1869 echo "# This section creates symbolic links" > srclinks.tmp
1870 echo "" >> srclinks.tmp
1871 printf 'F77_SRC_FILES = ' > F77srclist.tmp
1872 printf 'NON_AD_F77_SRC_FILES = ' > nonADF77srclist.tmp
1873 printf 'C_SRC_FILES = ' > csrclist.tmp
1874 printf 'F90_SRC_FILES = ' > F90srclist.tmp
1875 printf 'H_SRC_FILES = ' > hsrclist.tmp
1876 alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1877 for d in $alldirs ; do
1878 deplist=
1879 sfiles=`( cd $d; echo *.[h,c,F] | grep -v _cb2m)`
1880 sfiles=`( echo $sfiles; cd $d; echo *.F90 | grep -v _cb2m)`
1881 for sf in $sfiles ; do
1882 if test ! -r ".links.tmp/$sf" ; then
1883 if test -f "$d/$sf" ; then
1884 case $d/$sf in
1885 ./$PACKAGES_DOT_H)
1886 ;;
1887 ./AD_CONFIG.h)
1888 ;;
1889 ./FC_NAMEMANGLE.h)
1890 ;;
1891 ./BUILD_INFO.h)
1892 ;;
1893 *)
1894 touch .links.tmp/$sf
1895 deplist="$deplist $sf"
1896 ;;
1897 esac
1898 extn=`echo $sf | $AWK -F. '{print $NF}'`
1899 case $extn in
1900 F)
1901 echo " \\" >> F77srclist.tmp
1902 printf " $sf" >> F77srclist.tmp
1903 basename=${sf%%.F}
1904 isAD=`egrep ^$basename.f'[ ]*' adSrcFiles.tmp`
1905 if test -z "$isAD" ; then
1906 echo " \\" >> nonADF77srclist.tmp
1907 printf " $sf" >> nonADF77srclist.tmp
1908 fi
1909 ;;
1910 F90)
1911 echo " \\" >> F90srclist.tmp
1912 printf " $sf" >> F90srclist.tmp
1913 ;;
1914 c)
1915 echo " \\" >> csrclist.tmp
1916 printf " $sf" >> csrclist.tmp
1917 ;;
1918 h)
1919 echo " \\" >> hsrclist.tmp
1920 printf " $sf" >> hsrclist.tmp
1921 ;;
1922 esac
1923 fi
1924 fi
1925 done
1926 if test "x$deplist" != x ; then
1927 if test "$d" != "." ; then
1928 echo "" >> srclinks.tmp
1929 echo "# These files are linked from $d" >> srclinks.tmp
1930 echo "$deplist :" >> srclinks.tmp
1931 printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp
1932 fi
1933 fi
1934 done
1935 rm -rf .links.tmp
1936 echo "" >> F77srclist.tmp
1937 echo "" >> nonADF77srclist.tmp
1938 echo "" >> csrclist.tmp
1939 echo "" >> F90srclist.tmp
1940 echo "" >> hsrclist.tmp
1941
1942 if test -f $MAKEFILE ; then
1943 mv -f $MAKEFILE "$MAKEFILE.bak"
1944 fi
1945
1946 echo " Writing makefile: $MAKEFILE"
1947
1948 echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
1949 echo "# $MACHINE" >> $MAKEFILE
1950 echo "# This makefile was generated automatically on" >> $MAKEFILE
1951 echo "# $THISDATE" >> $MAKEFILE
1952 echo "# by the command:" >> $MAKEFILE
1953 echo "# $0 $G2ARGS" >> $MAKEFILE
1954 echo "# executed by:" >> $MAKEFILE
1955 echo "# ${THISUSER}@${THISHOST}:${THISCWD}" >> $MAKEFILE
1956
1957 EXE_AD=$EXECUTABLE"_ad"
1958 EXE_FTL=$EXECUTABLE"_ftl"
1959 EXE_SVD=$EXECUTABLE"_svd"
1960
1961 cat >>$MAKEFILE <<EOF
1962 #
1963 # OPTFILE="$OPTFILE"
1964 #
1965 # BUILDDIR : Directory where object files are written
1966 # SOURCEDIRS : Directories containing the source (.F) files
1967 # INCLUDEDIRS : Directories containing the header-source (.h) files
1968 # EXEDIR : Directory where executable that is generated is written
1969 # EXECUTABLE : Full path of executable binary
1970 #
1971 # CPP : C-preprocessor command
1972 # INCLUDES : Directories searched for header files
1973 # DEFINES : Macro definitions for CPP
1974 # MAKEDEPEND : Dependency generator
1975 # KPP : Special preprocessor command (specific to platform)
1976 # KFLAGS : Flags for KPP
1977 # FC : Fortran compiler command
1978 # FFLAGS : Configuration/debugging options for FC
1979 # FOPTIM : Optimization options for FC
1980 # LINK : Command for link editor program
1981 # LIBS : Library flags /or/ additional optimization/debugging flags
1982
1983 ROOTDIR = ${ROOTDIR}
1984 BUILDDIR = ${BUILDDIR}
1985 SOURCEDIRS = ${SOURCEDIRS}
1986 INCLUDEDIRS = ${INCLUDEDIRS}
1987 EXEDIR = ${EXEDIR}
1988 EXECUTABLE = \$(EXEDIR)/${EXECUTABLE}
1989 TOOLSDIR = ${TOOLSDIR}
1990
1991 #eh3 new defines for the adjoint work
1992 AUTODIFF = ${ROOTDIR}/pkg/autodiff
1993 EXE_AD = ${EXE_AD}
1994 EXE_FTL = ${EXE_FTL}
1995 EXE_SVD = ${EXE_SVD}
1996
1997 ENABLED_PACKAGES = ${ENABLED_PACKAGES}
1998 DISABLED_PACKAGES = ${DISABLED_PACKAGES}
1999
2000 # These files are created by Makefile
2001 SPECIAL_FILES = ${PACKAGES_DOT_H} AD_CONFIG.h FC_NAMEMANGLE.h BUILD_INFO.h
2002
2003 EOF
2004
2005 # Note: figure out some way to add Hyades JAM libraries here
2006
2007 cat >>$MAKEFILE <<EOF
2008 # Unix ln (link)
2009 LN = ${LN}
2010 # C preprocessor
2011 CPP = cat \$< | ${S64} | ${CPP}
2012 # Dependency generator
2013 MAKEDEPEND = ${MAKEDEPEND}
2014 # Special preprocessor (KAP on DECs, FPP on Crays)
2015 KPP = ${KPP}
2016 # Fortran compiler
2017 FC = ${FC}
2018 # Fortran compiler
2019 F90C = ${F90C}
2020 # C compiler
2021 CC = ${CC}
2022 # Link editor
2023 LINK = ${LINK} ${LDADD}
2024
2025 # Defines for CPP
2026 DEFINES = ${DEFINES}
2027 # Includes for CPP
2028 INCLUDES = ${INCLUDES}
2029 # Flags for KPP
2030 KFLAGS1 = ${KFLAGS1}
2031 KFLAGS2 = ${KFLAGS2}
2032 # Optim./debug for FC
2033 FFLAGS = ${FFLAGS}
2034 FOPTIM = ${FOPTIM}
2035 # Optim./debug/format for FC
2036 F90FLAGS = ${F90FLAGS}
2037 F90OPTIM = ${F90OPTIM}
2038 F90FIXEDFORMAT = ${F90FIXEDFORMAT}
2039 # Flags for CC
2040 CFLAGS = ${CFLAGS}
2041 # Files that should not be optimized
2042 NOOPTFILES = ${NOOPTFILES}
2043 NOOPTFLAGS = ${NOOPTFLAGS}
2044 # Flags and libraries needed for linking
2045 LIBS = ${LIBS}
2046 # Name of the Mekfile
2047 MAKEFILE=${MAKEFILE}
2048
2049 EOF
2050
2051 cat F77srclist.tmp >> $MAKEFILE
2052 cat nonADF77srclist.tmp >> $MAKEFILE
2053 cat csrclist.tmp >> $MAKEFILE
2054 cat F90srclist.tmp >> $MAKEFILE
2055 cat hsrclist.tmp >> $MAKEFILE
2056
2057 rm -f F77srclist.tmp nonADF77srclist.tmp csrclist.tmp hsrclist.tmp flist.tmp clist.tmp F90srclist.tmp
2058
2059 echo >> $MAKEFILE
2060
2061 # add definitions for preprocessed sources
2062 # and note that not all systems allow case sensitive extensions
2063 # hence the $FS and $FS90 here.
2064 # for fixed format f90 files we use ff90 or FF90 resp
2065 # but these are not expected to be the original source files
2066
2067 echo 'F77_PP_SRC_FILES = $(F77_SRC_FILES:.F=.'$FS')' >> $MAKEFILE
2068 echo 'F90_PP_SRC_FILES = $(F90_SRC_FILES:.F90=.'$FS90')' >> $MAKEFILE
2069 echo >> $MAKEFILE
2070 echo '.SUFFIXES:' >> $MAKEFILE
2071 echo '.SUFFIXES: .o .'$FS' .p .F .c .f'$FS90' .'$FS90' .FF90 .F90' >> $MAKEFILE
2072
2073 cat >>$MAKEFILE <<EOF
2074
2075 # all the source files linked from the various locations:
2076 ALL_LINKED_FILES= \
2077 \$(F77_SRC_FILES) \
2078 \$(C_SRC_FILES) \
2079 \$(H_SRC_FILES) \
2080 \$(F90_SRC_FILES) \
2081 \$(SPECIAL_FILES)
2082
2083 all: depend \$(EXECUTABLE)
2084
2085 depend: \$(ALL_LINKED_FILES)
2086 \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
2087 \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2088 -rm -f makedepend.out
2089
2090 .PHONY: depend
2091
2092 OBJFILES= \$(F77_SRC_FILES:.F=.o) \$(C_SRC_FILES:.c=.o) \$(F90_SRC_FILES:.F90=.o)
2093
2094 \$(EXECUTABLE): \$(OBJFILES)
2095 @echo Creating \$@ ...
2096 \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
2097
2098 output.txt: \$(EXECUTABLE)
2099 @printf 'running ... '
2100 @\$(EXECUTABLE) > \$@
2101
2102 # Special targets (SPECIAL_FILES) which are created by make
2103 ${PACKAGES_DOT_H}:
2104 @echo Creating \$@ ...
2105 @$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) > \$@
2106 AD_CONFIG.h:
2107 @echo Creating \$@ ...
2108 @$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 > \$@
2109 FC_NAMEMANGLE.h:
2110 @echo Creating \$@ ...
2111 echo "$FC_NAMEMANGLE" > \$@
2112
2113 BUILD_INFO.h:
2114 @echo Creating \$@ ...
2115 EOF
2116
2117 test ! "x$THISVER" = x && echo " -echo \"#define THISVER '$THISVER'\" > \$@" >> $MAKEFILE
2118 test ! "x$THISUSER" = x && echo " -echo \"#define THISUSER '$THISUSER'\" >> \$@" >> $MAKEFILE
2119 test ! "x$THISDATE" = x && echo " -echo \"#define THISDATE '$THISDATE'\" >> \$@" >> $MAKEFILE
2120 test ! "x$THISHOST" = x && echo " -echo \"#define THISHOST '$THISHOST'\" >> \$@" >> $MAKEFILE
2121
2122 cat >>$MAKEFILE <<EOF
2123
2124 # The normal chain of rules is ( .F - .$FS - .o )
2125
2126 ## This nullifies any default implicit rules concerning these two file types:
2127 %.o : %.F
2128
2129 .F.$FS:
2130 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2131 .$FS.o:
2132 \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
2133 .F90.$FS90:
2134 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2135 .FF90.f$FS90:
2136 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2137 .$FS90.o:
2138 \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
2139 .f$FS90.o:
2140 \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$(F90FIXEDFORMAT) \$<
2141 .c.o:
2142 \$(CC) \$(CFLAGS) -c \$<
2143
2144 # Special exceptions that use the ( .F - .p - .$FS - .o ) rule-chain
2145 .F.p:
2146 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
2147 .p.$FS:
2148 \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
2149
2150 #=========================================
2151 #=== Cleanup Rules ===
2152
2153 CLEAN: Clean
2154 -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
2155 -find \$(EXEDIR) -name "*.data" -exec rm {} \;
2156 -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
2157 -rm -f \$(EXECUTABLE) output.txt ad_output.txt STD*
2158
2159 Clean: clean cleanlinks
2160 -rm -f *.F
2161 -rm -f \$(SPECIAL_FILES)
2162 -rm -f genmake_state genmake_*optfile genmake_warnings make.log run.log *.bak
2163
2164 clean:
2165 -rm -rf *.o *.$FS *.p *.f$FS90 *.$FS90 *.mod ${RMFILES} work.{pc,pcl} *.template *_mod.h *_mod.F90 *.FF90 *.mod-whirl ad_input*
2166 -rm -rf temp.sed reslice.dat
2167
2168 cleanlinks:
2169 -find . -type l -exec rm {} \;
2170
2171 .PHONY: clean Clean CLEAN
2172
2173
2174 #=========================================
2175 #=== self regeneration ===
2176 # can't call this target "Makefile"
2177 # because unfortunately the genmake script
2178 # invoked here uses
2179 # make itself for checking things and we
2180 # end up in a recursion.
2181
2182 makefile:
2183 $THIS_SCRIPT $G2ARGS
2184
2185 # because the file is called Makefile
2186 .PHONY: makefile
2187
2188 #====================================
2189 #=== Automatic Differentiation ===
2190
2191 ifndef OPENADROOT
2192 \$(error "Error: environment variable OPENADROOT not defined!")
2193 endif
2194
2195 ifndef XAIFSCHEMAROOT
2196 \$(error "Error: environment variable XAIFSCHEMAROOT not defined!")
2197 endif
2198
2199 ifndef XAIFBOOSTERROOT
2200 \$(error "Error: environment variable XAIFBOOSTERROOT not defined!")
2201 endif
2202
2203 EOF
2204
2205 echo " Add the source list for AD code generation"
2206 echo >> $MAKEFILE
2207 printf "AD_FILES = " >> $MAKEFILE
2208 AD_FILES=`cat adSrcFiles.tmp`
2209 for i in $AD_FILES ; do
2210 echo " \\" >> $MAKEFILE
2211 printf " $i" >> $MAKEFILE
2212 done
2213 echo >> $MAKEFILE
2214 rm -f adSrcFiles.tmp
2215
2216 cat >>$MAKEFILE <<EOF
2217
2218
2219 # files to be converted:
2220 # right now there is no quick hack
2221 # to pick these out automatically
2222 # but we will be using the
2223 # canonicalizer anyway
2224 CB2M_F90_SRC_NAMES = \
2225 SIZE \
2226 EEPARAMS \
2227 PARAMS \
2228 BAR2 \
2229 BARRIER \
2230 CD_CODE_VARS \
2231 CG2D \
2232 CG3D \
2233 DFILE \
2234 DYNVARS \
2235 EEIO \
2236 EESUPPORT \
2237 EOS \
2238 EXCH_JAM \
2239 EXCH \
2240 FC_NAMEMANGLE \
2241 FFIELDS \
2242 GAD \
2243 GLOBAL_MAX \
2244 GLOBAL_SUM \
2245 GRID \
2246 MPI_INFO \
2247 SOLVE_FOR_PRESSURE3D \
2248 SOLVE_FOR_PRESSURE \
2249 SURFACE \
2250 tamc \
2251 tamc_keys \
2252 cost \
2253 g_cost \
2254 ctrl \
2255 ctrl_dummy \
2256 ctrl_weights \
2257 optim \
2258 grdchk
2259
2260 .PHONY: adAll
2261 adAll: \$(EXE_AD)
2262
2263 # these are all fixed format:
2264 CB2M_F77_TO_FF90_SRC_FILES=\$(F77_SRC_FILES:.F=_cb2m.FF90)
2265 CB2M_F90_SRC_FILES=\$(addsuffix _mod.FF90, \$(CB2M_F90_SRC_NAMES))
2266 CB2M_F90_PP_SRC_FILES=\$(addsuffix _mod.f$FS90, \$(CB2M_F90_SRC_NAMES))
2267
2268 .PRECIOUS: \$(CB2M_F90_PP_SRC_FILES) \$(NON_AD_F77_SRC_FILES:.F=_cb2m.ff90)
2269
2270 .PHONY: adDepend
2271 #this file is included at the bottom
2272 adDepend: \$(ALL_LINKED_FILES) \$(CB2M_F90_SRC_FILES) \$(CB2M_F77_TO_FF90_SRC_FILES)
2273 \$(MAKEDEPEND) -o .$FS \$(DEFINES) \$(INCLUDES) \$(F77_SRC_FILES)
2274 \$(TOOLSDIR)/f90mkdepend >> \$(MAKEFILE)
2275 -rm -f makedepend.out
2276
2277
2278 OPENAD_SUPPORT_F90_SRC_FILES = \
2279 w2f__types.f90 \
2280 active_module.f90 \
2281 OpenAD_checkpoints.f90 \
2282 OpenAD_dct.f90 \
2283 OpenAD_rev.f90 \
2284 OpenAD_tape.f90
2285
2286 OPENAD_SUPPORT_C_SRC_FILES = \
2287 iaddr.c
2288
2289 AD_OBJ_FILES=\$(OPENAD_SUPPORT_F90_SRC_FILES:.f90=.o) \$(OPENAD_SUPPORT_C_SRC_FILES:.c=.o) all_mods.xb.x2w.w2f.pp.o ad_input_code.w2f.canon.xb.x2w.w2f.rs.pp.o \$(NON_AD_F77_SRC_FILES:.F=_cb2m.o) \$(C_SRC_FILES:.c=.o) \$(F90_SRC_FILES:.F90=.o)
2290
2291 \$(EXE_AD): \$(AD_OBJ_FILES)
2292 @echo Creating \$@ ...
2293 \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$^ \$(LIBS)
2294
2295 # makefile debug rule
2296 openad: ad_input_code.w2f.canon.xb.x2w.w2f.rs.pp.f
2297 .PHONY: openad
2298
2299 CB2MFILES= cb2m1.csh cb2m1.awk cb2m2.bash
2300 # create the module files and change the header files
2301 \$(CB2M_F90_SRC_FILES) \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) : \$(ALL_LINKED_FILES) \$(CB2MFILES)
2302 ./cb2m1.csh \$(CB2M_F90_SRC_NAMES)
2303
2304 # change everybody else to use the module files:
2305 \$(CB2M_F77_TO_FF90_SRC_FILES): \$(addsuffix _mod.h, \$(CB2M_F90_SRC_NAMES)) \$(CB2M_F90_SRC_FILES)
2306 ./cb2m2.bash
2307
2308 # makefile debug rule
2309 small_f: \$(CB2M_F77_PP_SRC_FILES) \$(CB2M_F90_PP_SRC_FILES)
2310 .PHONY: small_f
2311
2312 ad_output.txt: \$(EXE_AD)
2313 @printf 'linking data files ... '
2314 \$(LN) -f ../input_ad/data* ../input_ad/eedata .
2315 \$(LN) -f ../../global_ocean.90x40x15/input/*.bin .
2316 @printf 'running ... '
2317 @./\$(EXE_AD) > \$@
2318
2319 CB2M_AD_FILES=\$(AD_FILES:.f=_cb2m.ff90)
2320 ad_input_code.$FS: ${MODS}/maxMinDefs.f \$(CB2M_AD_FILES)
2321 cat \$^ > \$@
2322
2323 \$(CB2MFILES):
2324 \$(LN) \$(addprefix ${MODS}/, \$(CB2MFILES)) .
2325
2326 # strip all comments and blanks to reduce
2327 # the file size in order to reduce perl's memory requirements
2328 ad_input_code_sf.f : ad_input_code.f
2329 cat \$^ | sed -f ${MODS}/strip.sed | sed -f ${MODS}/stop2print.sed > \$@
2330
2331 # mfef90 preprocessing
2332 # expand statement functions
2333 # expose mfef90 specific substring handling
2334 # add the w2f__types module
2335 ad_input_code_sf.w2f.f: ad_input_code_sf.f mfef90 whirl2f whirl2f_be w2f__types.f90
2336 ./mfef90 -F -N132 \$<
2337 ./whirl2f \$<
2338 cat w2f__types.f90 \$@ > \$@.1
2339 mv \$@.1 \$@
2340
2341 # canonicalizer
2342 ad_input_code_sf.w2f.canon.f: ad_input_code_sf.w2f.f canon.v1.py
2343 python canon.v1.py \$< > \$@
2344
2345 # F -> WHIRL
2346 # note that the canonicalized version cuts off at col 72
2347 # doing this also for string constants which is ok as long
2348 # as we are in fixed mode and cut of exactly there.
2349 # Otherwise mfef90 patches in spaces to fill up to 72 (or 132)
2350 # characters respectively.
2351 ad_input_code_sf.w2f.canon.B: ad_input_code_sf.w2f.canon.f mfef90
2352 ./mfef90 -F \$<
2353
2354 # WHIRL -> XAIF
2355 ad_input_code_sf.w2f.canon.xaif : ad_input_code_sf.w2f.canon.B whirl2xaif
2356 ./whirl2xaif --debug 1 -o \$@ \$<
2357
2358 # XAIF -> XAIF'
2359 ad_input_code_sf.w2f.canon.xb.xaif : ad_input_code_sf.w2f.canon.xaif xaif.xsd xaif_base.xsd xaif_inlinable_intrinsics.xsd xaif_derivative_propagator.xsd xaif_output.xsd openad_adm
2360 ./openad_adm -i \$< -c \${XAIFSCHEMAROOT}/schema/examples/inlinable_intrinsics.xaif -o \$@ -I
2361
2362 # XAIF' -> WHIRL'
2363 ad_input_code_sf.w2f.canon.xb.x2w.B : ad_input_code_sf.w2f.canon.xb.xaif xaif2whirl
2364 ./xaif2whirl --structured ad_input_code_sf.w2f.canon.B \$<
2365
2366 # WHIRL' -> F'
2367 ad_input_code_sf.w2f.canon.xb.x2w.w2f.f: ad_input_code_sf.w2f.canon.xb.x2w.B whirl2f whirl2f_be
2368 ./whirl2f -openad \$<
2369
2370 # undo slice hiding
2371 # insert template directives
2372 ad_input_code_sf.w2f.canon.xb.x2w.w2f.rs.f: ad_input_code_sf.w2f.canon.xb.x2w.w2f.f reslicer.py ${MODS}/insertTemplateDir.bash
2373 python reslicer.py \$< > \$<.1
2374 ${MODS}/insertTemplateDir.bash \$<.1 \$@
2375 rm \$<.1
2376
2377 # postprocess F'
2378 ad_input_code_sf.w2f.canon.xb.x2w.w2f.rs.pp.f: ad_input_code_sf.w2f.canon.xb.x2w.w2f.rs.f multi-pp.pl ${MODS}/ad_inline.f ${MODS}/ad_template.checkpoint.f ${MODS}/ad_template.plain.f ${MODS}/ad_template.split.f
2379 perl multi-pp.pl -inline=${MODS}/ad_inline.f \$<
2380 cat \$@ | sed 's/RETURN//' > \$@.1
2381 mv \$@.1 \$@
2382
2383 # extract all transformed modules
2384 all_mods.xb.x2w.w2f.pp.f: ad_input_code_sf.w2f.canon.xb.x2w.w2f.rs.pp.f
2385 cat \$< | sed -n '/MODULE /,/END MODULE/p' > \$@
2386
2387 # remove the transformed globals module from the
2388 # transformed ad_input_code file
2389 # and remove for now the duplicate variables
2390 ad_input_code.w2f.canon.xb.x2w.w2f.rs.pp.f: ad_input_code_sf.w2f.canon.xb.x2w.w2f.rs.pp.f
2391 cat \$< | sed '/MODULE /,/END MODULE/d' | sed '/^ INTEGER(w2f__i4) DOLOOP_UB/d' > \$@
2392
2393 # setup some links
2394 %.xsd:
2395 \$(LN) \${XAIFSCHEMAROOT}/schema/\$@ .
2396
2397 mfef90:
2398 \$(LN) \${OPENADROOT}/Open64/osprey1.0/targ_ia32_ia64_linux/crayf90/sgi/mfef90 .
2399
2400 # link the support files:
2401 \$(OPENAD_SUPPORT_F90_SRC_FILES) \$(OPENAD_SUPPORT_C_SRC_FILES) :
2402 \$(LN) ${MODS}/\$@ .
2403
2404 whirl2xaif xaif2whirl:
2405 \$(LN) \${OPENADROOT}/OpenADFortTk/OpenADFortTk-i686-Linux/bin/\$@ .
2406
2407 %.pl:
2408 \$(LN) \${OPENADROOT}/OpenADFortTk/OpenADFortTk-i686-Linux/bin/\$@ .
2409
2410 %.py:
2411 \$(LN) \${OPENADROOT}/OpenADFortTk/tools/canonicalize/\$@ .
2412
2413 whirl2f whirl2f_be:
2414 \$(LN) \${OPENADROOT}/Open64/osprey1.0/targ_ia32_ia64_linux/whirl2f/\$@ .
2415
2416 openad_adm:
2417 \$(LN) \${XAIFBOOSTERROOT}/xaifBooster/algorithms/BasicBlockPreaccumulationReverse/test/t \$@
2418
2419 EOF
2420
2421 if test "x$EXEHOOK" != x ; then
2422 printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
2423 fi
2424
2425 echo " Making list of \"exceptions\" that need \".p\" files"
2426 for i in $KPPFILES ; do
2427 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
2428 RETVAL=$?
2429 if test "x$RETVAL" != x0 ; then
2430 echo "Error: unable to add file \"$i\" to the exceptions list"
2431 fi
2432 echo "$base.$FS: $base.p" >> $MAKEFILE
2433 done
2434
2435 echo " Making list of NOOPTFILES"
2436 for i in $NOOPTFILES ; do
2437 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
2438 RETVAL=$?
2439 if test "x$RETVAL" != x0 ; then
2440 echo "Error: unable to add file \"$i\" to the exceptions list"
2441 fi
2442 echo "$base.o: $base.$FS" >> $MAKEFILE
2443 printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
2444 done
2445
2446 echo " Add rules for links"
2447 cat srclinks.tmp >> $MAKEFILE
2448 rm -f srclinks.tmp
2449
2450 printf "\n=== Done ===\n"
2451
2452 # Create special header files
2453 $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"
2454 if test ! -f $PACKAGES_DOT_H ; then
2455 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2456 else
2457 cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H > /dev/null 2>&1
2458 RETVAL=$?
2459 if test "x$RETVAL" = x0 ; then
2460 rm -f $PACKAGES_DOT_H".tmp"
2461 else
2462 mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
2463 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
2464 fi
2465 fi
2466 if test ! -f AD_CONFIG.h ; then
2467 $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
2468 fi
2469
2470
2471 # Write the "state" for future records
2472 if test "x$DUMPSTATE" != xf ; then
2473 printf "" > genmake_state
2474 for i in $gm_state ; do
2475 t1="t2=\$$i"
2476 eval $t1
2477 echo "$i='$t2'" >> genmake_state
2478 done
2479 fi

  ViewVC Help
Powered by ViewVC 1.1.22