/[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.14 - (show annotations) (download)
Tue Oct 21 15:29:20 2003 UTC (20 years, 5 months ago) by edhill
Branch: MAIN
Changes since 1.13: +152 -8 lines
 o first version of genmake2 that works with TAF -- note that only the
   "ad_taf" target has been confirmed to work and the others are in
   progress

1 #!/bin/bash
2 #
3 # $Header: $
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 grep -i "#define.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1
17 RETVAL=$?
18 if test "x${RETVAL}" = x0 ; then
19 echo "Error: In $cpp_options there is an illegal line: #define ALLOW_$pkg"
20 exit 99
21 fi
22 grep -i "#undef.*ALLOW_$pkg" $cpp_options > /dev/null 2>&1
23 RETVAL=$?
24 if test "x${RETVAL}" = x0 ; then
25 echo "Error: In $cpp_options there is an illegal line: #undef ALLOW_$pkg"
26 exit 99
27 fi
28 grep -i "#define.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1
29 RETVAL=$?
30 if test "x${RETVAL}" = x0 ; then
31 echo "Error: In $cpp_options there is an illegal line: #define DISABLE_$pkg"
32 exit 99
33 fi
34 grep -i "#undef.*DISABLE_$pkg" $cpp_options > /dev/null 2>&1
35 RETVAL=$?
36 if test "x${RETVAL}" = x0 ; then
37 echo "Error: In $cpp_options there is an illegal line: #undef DISABLE_$pkg"
38 exit 99
39 fi
40 }
41
42 # Read the $ROOTDIR/pkg/pkg_groups file and expand any references to
43 # the package list.
44 expand_pkg_groups() {
45 new_packages=
46 PKG_GROUPS=$ROOTDIR"/pkg/pkg_groups"
47 if test -r $PKG_GROUPS ; then
48 cat $PKG_GROUPS | sed -e 's/#.*$//g' | sed -e 's/:/ : /g' > ./p1.tmp
49 cat ./p1.tmp | awk '(NF>2 && $2==":"){ print $0 }' > ./p2.tmp
50 matched=0
51 for i in $PACKAGES ; do
52 line=`grep "^ *$i" ./p2.tmp`
53 RETVAL=$?
54 if test "x$RETVAL" = x0 ; then
55 matched=1
56 replace=`echo $line | awk '{ $1=""; $2=""; print $0 }'`
57 echo " replacing \"$i\" with: $replace"
58 new_packages="$new_packages $replace"
59 else
60 new_packages="$new_packages $i"
61 fi
62 done
63 PACKAGES=$new_packages
64 rm -f ./p[1,2].tmp
65 else
66 echo "Warning: can't read package groups definition file: $PKG_GROUPS"
67 fi
68 }
69
70 # Guess possible config options for this host
71 find_possible_configs() {
72
73 tmp1=`uname`"_"`uname -m`
74 tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
75 PLATFORM=`echo $tmp2 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
76 OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
77 echo " The platform appears to be: $PLATFORM"
78 # if test "x$OFLIST" = x ; then
79 # echo " No pre-defined options files were found matching this platform"
80 # echo " but examples for other platforms can be found in:"
81 # echo " $ROOTDIR/tools/build_options"
82 # else
83 # echo " Options files (located in $ROOTDIR/tools/build_options) that"
84 # echo " may work with this machine are:"
85 # for i in $OFLIST ; do
86 # echo " $i"
87 # done
88 # fi
89
90 echo "test" > test
91 ln -s ./test link
92 RETVAL=$?
93 if test "x${RETVAL}" = x0 ; then
94 LN="ln -s"
95 else
96 echo "Error: \"ln -s\" does not appear to work on this system!"
97 echo " For help, please contact <MITgcm-support@mitgcm.org>."
98 exit 1
99 fi
100 rm -f test link
101
102 if test "x$CPP" = x ; then
103 CPP="cpp -traditional -P"
104 fi
105
106 # look for possible fortran compilers
107 tmp="$MITGCM_FC $FC g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"
108 p_FC=
109 for c in $tmp ; do
110 rm -f ./hello.f ./hello
111 cat >> hello.f <<EOF
112 program hello
113 do i=1,3
114 print *, 'hello world : ', i
115 enddo
116 end
117 EOF
118 $c -o hello hello.f > /dev/null 2>&1
119 RETVAL=$?
120 if test "x${RETVAL}" = x0 ; then
121 p_FC="$p_FC $c"
122 fi
123 done
124 if test "x${p_FC}" = x ; then
125 cat 1>&2 <<EOF
126
127 Error: No Fortran compilers were found in your path. Please specify one using:
128
129 1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
130 2) a command-line option (eg. "-fc NAME"), or
131 3) the MITGCM_FC environment variable.
132
133 EOF
134 exit 1
135 else
136 echo " The possible FORTRAN compilers found in your path are:"
137 echo " "$p_FC
138 if test "x$FC" = x ; then
139 FC=`echo $p_FC | awk '{print $1}'`
140 fi
141 fi
142
143 for i in $p_FC ; do
144 p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
145 if test -r $p_OF ; then
146 OPTFILE=$p_OF
147 echo " The options file: $p_OF"
148 echo " appears to match so we'll use it."
149 break
150 fi
151 done
152 if test "x$OPTFILE" = x ; then
153 cat 1>&2 <<EOF
154
155 Error: No options file was found in: $ROOTDIR/tools/build_options/
156 that matches this platform ("$PLATFORM") and the compilers found in
157 your path. Please specify an "optfile" using:
158
159 1) the command line (eg. "-optfile=path/to/OPTFILE"), or
160 2) the MITGCM_OF environment variable.
161
162 If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
163
164 EOF
165 exit 1
166 fi
167
168 # # look for possible MPI libraries
169 # mpi_libs=
170 # mpi_fort=`which mpif77 2>/dev/null`
171 # RETVAL=$?
172 # if test "x${RETVAL}" = x0 ; then
173 # cat >>test.f <<EOF
174 # PROGRAM HELLO
175 # DO 10, I=1,10
176 # PRINT *,'Hello World'
177 # 10 CONTINUE
178 # STOP
179 # END
180 # EOF
181 # eval "$mpi_fort -showme test.f > out"
182 # RETVAL=$?
183 # if test "x${RETVAL}" = x0 ; then
184 # a=`cat out`
185 # for i in $a ; do
186 # case $i in
187 # -*)
188 # mpi_libs="$mpi_libs $i" ;;
189 # esac
190 # done
191 # echo "The MPI libs appear to be:"
192 # echo " "$mpi_libs
193 # fi
194 # rm -f test.f out
195 # fi
196
197 }
198
199 # Parse the package dependency information
200 get_pdepend_list() {
201
202 # strip the comments and then convert the dependency file into
203 # two arrays: PNAME, DNAME
204 cat $1 | sed -e 's/#.*$//g' \
205 | awk 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \
206 > ./.pd_tmp
207 source ./.pd_tmp
208 rm -f ./.pd_tmp
209
210 echo -n "PNAME = "${}
211 }
212
213
214 # Explain usage
215 usage() {
216 echo
217 echo "Usage: "$0" [OPTIONS]"
218 echo " where [OPTIONS] can be:"
219 echo
220 echo " -help | --help | -h | --h"
221 echo " -nooptfile | --nooptfile"
222 echo " -optfile NAME | --optfile NAME | -of NAME | --of NAME"
223 echo " -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME"
224 echo " -pdepend NAME | --pdepend NAME"
225 echo " -pdepend=NAME | --pdepend=NAME"
226 echo " -pdefault NAME | --pdefault NAME"
227 echo " -pdefault=NAME | --pdefault=NAME"
228 echo " -make NAME | -m NAME"
229 echo " --make=NAME | -m=NAME"
230 echo " -makefile NAME | -mf NAME"
231 echo " --makefile=NAME | -mf=NAME"
232 echo " -platform NAME | --platform NAME | -pl NAME | --pl NAME"
233 echo " -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"
234 echo " -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"
235 echo " -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME"
236 echo " -mods NAME | --mods NAME | -mo NAME | --mo NAME"
237 echo " -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME"
238 echo " -disable NAME | --disable NAME"
239 echo " -disable=NAME | --disable=NAME"
240 echo " -enable NAME | --enable NAME"
241 echo " -enable=NAME | --enable=NAME"
242 echo " -standarddirs NAME | --standarddirs NAME"
243 echo " -standarddirs=NAME | --standarddirs=NAME"
244 echo " -noopt NAME | --noopt NAME"
245 echo " -noopt=NAME | --noopt=NAME"
246 # echo " -cpp NAME | --cpp NAME"
247 # echo " -cpp=NAME | --cpp=NAME"
248 echo " -fortran NAME | --fortran NAME | -fc NAME | --fc NAME"
249 echo " -fc=NAME | --fc=NAME"
250 echo " -[no]ieee | --[no]ieee"
251 echo " -[no]mpi | --[no]mpi"
252 echo " -[no]jam | --[no]jam"
253 echo
254 echo " and NAME is a string such as:"
255 echo
256 echo " --enable pkg1 --enable 'pkg1 pkg2' --enable 'pkg1 pkg2 pkg3'"
257 echo " -mods=dir1 -mods='dir1' -mods='dir1 dir2 dir3'"
258 echo " -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"
259 echo
260 echo " which, depending upon your shell, may need to be single-quoted"
261 echo " if it contains spaces, dashes, or other special characters."
262 exit 1
263 }
264
265 #eh3 # This is the generic configuration.
266 #eh3 set LN = ( 'ln -s' )
267 #eh3 set CPP = ( '/lib/cpp -P' )
268 #eh3 set S64 = ( '$(TOOLSDIR)/set64bitConst.sh' )
269 #eh3 set KPP = ( )
270 #eh3 set FC = ( 'f77' )
271 #eh3 set LINK = $FC
272 #eh3 set MAKEDEPEND = ( 'makedepend' )
273 #eh3 set INCLUDES = ( -I. )
274 #eh3 set FFLAGS = ( )
275 #eh3 set FOPTIM = ( )
276 #eh3 set CFLAGS = ( )
277 #eh3 set KFLAGS1 = ( )
278 #eh3 set KFLAGS2 = ( )
279 #eh3 set LIBS = ( )
280 #eh3 set KPPFILES = ( )
281 #eh3 if (! $?NOOPTFILES ) set NOOPTFILES = ( )
282 #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = ( )
283
284 # Set defaults here
285 COMMANDL="$0 $@"
286
287 PLATFORM=
288 LN=
289 S64=
290 KPP=
291 FC=
292 LINK=
293 DEFINES="-DWORDLENGTH=4"
294 PACKAGES=
295 ENABLE=
296 DISABLE=
297 MAKEFILE=
298 MAKEDEPEND=
299 PDEPEND=
300 DUMPSTATE=t
301 PDEFAULT=
302 OPTFILE=
303 INCLUDES="-I."
304 FFLAGS=
305 FOPTIM=
306 CFLAGS=
307 KFLAGS1=
308 KFLAGS2=
309 LIBS=
310 KPPFILES=
311 NOOPTFILES=
312 NOOPTFLAGS=
313
314 MODS=
315 TOOLSDIR=
316 SOURCEDIRS=
317 INCLUDEDIRS=
318 STANDARDDIRS=
319
320 PWD=`pwd`
321 MAKE=make
322 THISHOSTNAME=`hostname`
323 THISCWD=`pwd`
324 THISDATE=`date`
325 MACHINE=`uname -a`
326 EXECUTABLE=
327 EXEHOOK=
328 EXEDIR=
329 PACKAGES_CONF=
330 IEEE=
331 if test "x$MITGCM_IEEE" != x ; then
332 IEEE=$MITGCM_IEEE
333 fi
334
335 AUTODIFF_PKG_USED=f
336 AD_OPTFILE=
337
338 # The following state can be set directly by command-line switches
339 gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"
340 gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"
341
342 # The following state is not directly set by command-line switches
343 gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
344 gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
345 gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"
346 gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
347
348 # The following are all related to adjoint/tangent-linear stuff
349 gm_s7="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF DIFF_FLAGS AD_TAMC_FLAGS AD_TAF_FLAGS"
350 gm_s8="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
351 gm_s9=""
352
353 gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7 $gm_s8"
354
355
356 echo
357 echo "=== Processing options files and arguments ==="
358 gm_local="genmake_local"
359 for i in . $MODS ; do
360 if test -r $i/$gm_local ; then
361 source $i/$gm_local
362 break
363 fi
364 done
365 echo -n " getting local config information: "
366 if test -e $gm_local ; then
367 echo "using $gm_local"
368 source $gm_local
369 # echo "DISABLE=$DISABLE"
370 # echo "ENABLE=$ENABLE"
371 else
372 echo "none found"
373 fi
374
375 # echo "$0::$1:$2:$3:$4:$5:$6:$7:"
376 #OPTIONS=
377 #n=0
378 #for i ; do
379 # echo "$i $n"
380 # setvar="OPTIONS[$n]='$i'"
381 # # echo " $setvar"
382 # eval "$setvar"
383 # n=$(( $n + 1 ))
384 #done
385 #parse_options
386 ac_prev=
387 for ac_option ; do
388
389 # If the previous option needs an argument, assign it.
390 if test -n "$ac_prev"; then
391 eval "$ac_prev=\$ac_option"
392 ac_prev=
393 continue
394 fi
395
396 ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
397
398 case $ac_option in
399
400 -help | --help | -h | --h)
401 usage ;;
402
403 -nooptfile | --nooptfile)
404 OPTFILE="NONE" ;;
405 -optfile | --optfile | -of | --of)
406 ac_prev=OPTFILE ;;
407 -optfile=* | --optfile=* | -of=* | --of=*)
408 OPTFILE=$ac_optarg ;;
409
410 -adoptfile | --adoptfile | -ad | --ad)
411 ac_prev=AD_OPTFILE ;;
412 -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
413 AD_OPTFILE=$ac_optarg ;;
414
415 -pdepend | --pdepend)
416 ac_prev=PDEPEND ;;
417 -pdepend=* | --pdepend=*)
418 PDEPEND=$ac_optarg ;;
419
420 -pdefault | --pdefault)
421 ac_prev=PDEFAULT ;;
422 -pdefault=* | --pdefault=*)
423 PDEFAULT=$ac_optarg ;;
424
425 -make | --make | -m | --m)
426 ac_prev=MAKE ;;
427 -make=* | --make=* | -m=* | --m=*)
428 MAKE=$ac_optarg ;;
429
430 -makefile | --makefile | -ma | --ma)
431 ac_prev=MAKEFILE ;;
432 -makefile=* | --makefile=* | -ma=* | --ma=*)
433 MAKEFILE=$ac_optarg ;;
434
435 -platform | --platform | -pl | --pl)
436 ac_prev=PLATFORM ;;
437 -platform=* | --platform=* | -pl=* | --pl=*)
438 PLATFORM=$ac_optarg ;;
439
440 -rootdir | --rootdir | -rd | --rd)
441 ac_prev=ROOTDIR ;;
442 -rootdir=* | --rootdir=* | -rd=* | --rd=*)
443 ROOTDIR=$ac_optarg ;;
444
445 -mods | --mods | -mo | --mo)
446 ac_prev=MODS ;;
447 -mods=* | --mods=* | -mo=* | --mo=*)
448 MODS=$ac_optarg ;;
449
450 -disable | --disable)
451 ac_prev=DISABLE ;;
452 -disable=* | --disable=*)
453 DISABLE=$ac_optarg ;;
454
455 -enable | --enable)
456 ac_prev=ENABLE ;;
457 -enable=* | --enable=*)
458 ENABLE=$ac_optarg ;;
459
460 -standarddirs | --standarddirs)
461 ac_prev=STANDARDDIRS ;;
462 -standarddirs=* | --standarddirs=*)
463 STANDARDDIRS=$ac_optarg ;;
464
465 -noopt | --noopt)
466 ac_prev=NOOPT ;;
467 -noopt=* | --noopt=*)
468 NOOPT=$ac_optarg ;;
469
470 # -cpp | --cpp)
471 # ac_prev=cpp ;;
472 # -cpp=* | --cpp=*)
473 # CPP=$ac_optarg ;;
474
475 -fortran | --fortran | -fc | --fc)
476 ac_prev=FC ;;
477 -fc=* | --fc=*)
478 FC=$ac_optarg ;;
479
480 -ieee | --ieee)
481 IEEE=true ;;
482 -noieee | --noieee)
483 IEEE= ;;
484
485 -mpi | --mpi)
486 MPI=true ;;
487 -nompi | --nompi)
488 MPI= ;;
489
490 -jam | --jam)
491 JAM=1 ;;
492 -nojam | --nojam)
493 JAM=0 ;;
494
495 -ds | --ds)
496 DUMPSTATE=t ;;
497
498 -*)
499 echo "Error: unrecognized option: "$ac_option
500 usage
501 ;;
502
503 *)
504 echo "Error: unrecognized argument: "$ac_option
505 usage
506 ;;
507
508 esac
509
510 done
511
512 if test -f ./.genmakerc ; then
513 echo
514 echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
515 echo " file. This file format is no longer supported. Please see:"
516 echo
517 echo " http://mitgcm.org/devel_HOWTO/"
518 echo
519 echo " for directions on how to setup and use the new \"genmake2\" input"
520 echo " files and send an email to MITgcm-support@mitgcm.org if you want help."
521 echo
522 fi
523
524 if test "x${ROOTDIR}" = x ; then
525 if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
526 ROOTDIR=".."
527 else
528 for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
529 if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
530 ROOTDIR=$d
531 echo -n "Warning: ROOTDIR was not specified but there appears to be"
532 echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
533 break
534 fi
535 done
536 fi
537 fi
538 if test "x${ROOTDIR}" = x ; then
539 echo "Error: Cannot determine ROOTDIR for MITgcm code."
540 echo " Please specify a ROOTDIR using either an options "
541 echo " file or a command-line option."
542 exit 1
543 fi
544 if test ! -d ${ROOTDIR} ; then
545 echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
546 exit 1
547 fi
548
549 echo " getting OPTFILE information: "
550 if test "x${OPTFILE}" = x ; then
551 if test "x$MITGCM_OF" = x ; then
552 echo "Warning: no OPTFILE specified so we'll look for possible settings"
553 printf "\n=== Searching for possible settings for OPTFILE ===\n"
554 find_possible_configs
555 else
556 OPTFILE=$MITGCM_OF
557 fi
558 fi
559 if test "x$OPTFILE" != xNONE ; then
560 if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
561 echo " using OPTFILE=\"$OPTFILE\""
562 source "$OPTFILE"
563 RETVAL=$?
564 if test "x$RETVAL" != x0 ; then
565 echo -n "Error: failed to source OPTFILE \"$OPTFILE\""
566 echo "--please check that variable syntax is bash-compatible"
567 exit 1
568 fi
569 if test "x$DUMPSTATE" != xf ; then
570 cp -f $OPTFILE "genmake_optfile"
571 fi
572 else
573 echo "Error: can't read OPTFILE=\"$OPTFILE\""
574 exit 1
575 fi
576 fi
577
578 echo " getting AD_OPTFILE information: "
579 if test "x${AD_OPTFILE}" = x ; then
580 if test "x$MITGCM_AD_OF" = x ; then
581 AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
582 else
583 AD_OPTFILE=$MITGCM_AD_OF
584 fi
585 fi
586 if test "x${AD_OPTFILE}" != xNONE ; then
587 if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
588 echo " using AD_OPTFILE=\"$AD_OPTFILE\""
589 source "$AD_OPTFILE"
590 RETVAL=$?
591 if test "x$RETVAL" != x0 ; then
592 echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
593 echo "--please check that variable syntax is bash-compatible"
594 exit 1
595 fi
596 if test "x$DUMPSTATE" != xf ; then
597 cp -f $AD_OPTFILE "genmake_ad_optfile"
598 fi
599 else
600 echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
601 exit 1
602 fi
603 fi
604
605 # Check that FC, LINK, CPP, and S64 are defined. If not, complain
606 # and abort!
607 if test "x$FC" = x ; then
608 cat <<EOF 1>&2
609
610 Error: no Fortran compiler: please specify using one of the following:
611 1) within the options file ("FC=...") as specified by "-of=OPTFILE"
612 2) the "-fc=XXX" command-line option
613 3) the "./genmake_local" file
614 EOF
615 exit 1
616 fi
617 if test "x$LINK" = x ; then
618 LINK=$FC
619 fi
620 if test "x$CPP" = x ; then
621 CPP="cpp"
622 fi
623 echo "#define A a" | $CPP > test_cpp 2>&1
624 RETVAL=$?
625 if test "x$RETVAL" != x0 ; then
626 cat <<EOF 1>&2
627
628 Error: C pre-processor "$CPP" failed the test case: please specify using:
629
630 1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
631 2) the "./genmake_local" file
632
633 EOF
634 exit 1
635 else
636 rm -f test_cpp
637 fi
638 if test "x$MAKEDEPEND" = x ; then
639 MAKEDEPEND=makedepend
640 fi
641
642 printf "\n=== Setting defaults ===\n"
643 echo -n " Adding MODS directories: "
644 for d in $MODS ; do
645 if test ! -d $d ; then
646 echo
647 echo "Error: MODS directory \"$d\" not found!"
648 exit 1
649 else
650 echo -n " $d"
651 SOURCEDIRS="$SOURCEDIRS $d"
652 INCLUDEDIRS="$INCLUDEDIRS $d"
653 fi
654 done
655 echo
656
657 if test "x$MAKEFILE" = x ; then
658 MAKEFILE="Makefile"
659 fi
660 if test "x${PLATFORM}" = x ; then
661 PLATFORM=$p_PLATFORM
662 fi
663
664 if test "x${EXEDIR}" = x ; then
665 if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then
666 EXEDIR=../exe
667 else
668 EXEDIR=.
669 fi
670 fi
671 if test ! -d ${EXEDIR} ; then
672 echo "Error: the specified EXEDIR (\"$EXEDIR\") does not exist!"
673 exit 1
674 fi
675
676 if test "x${TOOLSDIR}" = x ; then
677 TOOLSDIR="$ROOTDIR/tools"
678 fi
679 if test ! -d ${TOOLSDIR} ; then
680 echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"
681 exit 1
682 fi
683 if test "x$S64" = x ; then
684 S64='$(TOOLSDIR)/set64bitConst.sh'
685 fi
686
687 EXECUTABLE=${EXECUTABLE:-mitgcmuv}
688
689 # We have a special set of source files in eesupp/src which are
690 # generated from some template source files. We'll make them first so
691 # they appear as regular source code
692 if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
693 echo " Making source files in eesupp from templates"
694 $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1
695 RETVAL=$?
696 if test "x${RETVAL}" = x0 ; then
697 rm -f make_eesupp.errors
698 else
699 echo "Error: problem encountered while building source files in eesupp:"
700 cat make_eesupp.errors
701 exit 1
702 fi
703 fi
704
705 printf "\n=== Determining package settings ===\n"
706 if test "x${PDEPEND}" = x ; then
707 tmp=$ROOTDIR"/pkg/pkg_depend"
708 if test -r $tmp ; then
709 PDEPEND=$tmp
710 else
711 echo "Warning: No package dependency information was specified."
712 echo " Please check that ROOTDIR/pkg/pkg_depend exists."
713 fi
714 else
715 if test ! -r ${PDEPEND} ; then
716 echo "Error: can't read package dependency info from PDEPEND=\"$PDEPEND\""
717 exit 1
718 fi
719 fi
720 echo " getting package dependency info from $PDEPEND"
721 # Strip the comments and then convert the dependency file into
722 # two arrays: PNAME, DNAME
723 cat $PDEPEND | sed -e 's/#.*$//g' \
724 | awk 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
725 > ./.pd_tmp
726 RETVAL=$?
727 if test ! "x${RETVAL}" = x0 ; then
728 echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
729 exit 1
730 fi
731 source ./.pd_tmp
732 rm -f ./.pd_tmp
733
734 # Search for default packages. Note that a "$ROOTDIR/pkg/pkg_groups"
735 # file should eventually be added so that, for convenience, one can
736 # specify groups of packages using names like "ocean" and "atmosphere".
737 echo -n " checking default package list: "
738 if test "x${PDEFAULT}" = x ; then
739 for i in "." $MODS ; do
740 if test -r $i"/packages.conf" ; then
741 PDEFAULT=$i"/packages.conf"
742 break
743 fi
744 done
745 fi
746 if test "x${PDEFAULT}" = x ; then
747 PDEFAULT="$ROOTDIR/pkg/pkg_default"
748 fi
749 if test "x${PDEFAULT}" = xNONE ; then
750 echo "default packages file disabled"
751 else
752 if test ! -r $PDEFAULT ; then
753 echo ""
754 echo "Warning: can't read default packages from PDEFAULT=\"$PDEFAULT\""
755 else
756 echo " using PDEFAULT=\"$PDEFAULT\""
757 # Strip the comments and add all the names
758 def=`cat $PDEFAULT | sed -e 's/#.*$//g' | awk '(NF>0){print $0}'`
759 RETVAL=$?
760 if test "x${RETVAL}" != x0 ; then
761 echo -n "Error: can't parse default package list "
762 echo "-- please check PDEFAULT=\"$PDEFAULT\""
763 exit 1
764 fi
765 for i in $def ; do
766 PACKAGES="$PACKAGES $i"
767 done
768 echo " before group expansion packages are: $PACKAGES"
769 expand_pkg_groups
770 echo " after group expansion packages are: $PACKAGES"
771 fi
772 fi
773
774 echo " applying DISABLE settings"
775 pack=
776 for p in $PACKAGES ; do
777 addit="t"
778 for d in $DISABLE ; do
779 if test "x$p" = "x$d" ; then
780 addit="f"
781 fi
782 done
783 if test "x$addit" = xt ; then
784 pack="$pack $p"
785 fi
786 done
787 PACKAGES="$pack"
788 echo " applying ENABLE settings"
789 echo "" > ./.tmp_pack
790 PACKAGES="$PACKAGES $ENABLE"
791 for i in $PACKAGES ; do
792 if test ! -d "$ROOTDIR/pkg/$i" ; then
793 echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
794 exit 1
795 fi
796 echo $i >> ./.tmp_pack
797 done
798 pack=`cat ./.tmp_pack | sort | uniq`
799 rm -f ./.tmp_pack
800 PACKAGES=
801 for i in $pack ; do
802 PACKAGES="$PACKAGES $i"
803 done
804 echo " packages are: $PACKAGES"
805
806 echo " applying package dependency rules"
807 ck=
808 while test "x$ck" != xtt ; do
809 i=0
810 # rtot=${#PNAME[@]}
811 rtot=$nname
812 while test $i -lt $rtot ; do
813
814 # Is $pname in the current $PACKAGES list?
815 # pname=${PNAME[$i]}
816 tmp="pname=\"\$PNAME_$i\""
817 eval $tmp
818 pin="f"
819 for p in $PACKAGES ; do
820 if test "x$p" = "x$pname" ; then
821 pin="t"
822 fi
823 done
824
825 # Is the DNAME entry a (+) or (-) rule ?
826 tmp="dname=\"\$DNAME_$i\""
827 eval $tmp
828 plus="-"
829 echo $dname | grep '^+' > /dev/null 2>&1
830 RETVAL=$?
831 if test "x$RETVAL" = x0 ; then
832 plus="+"
833 fi
834
835 # Is $dname in the current $PACKAGES list?
836 dname=`echo $dname | sed -e 's/^[+-]//'`
837 din="f"
838 for p in $PACKAGES ; do
839 if test "x$p" = "x$dname" ; then
840 din="t"
841 fi
842 done
843
844 # Do we need to add $dname according to the dependency rules?
845 if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
846 in_dis="f"
847 for dis in $DISABLE ; do
848 if test "x$dis" = "x$dname" ; then
849 in_dis="t"
850 fi
851 done
852 if test "x$in_dis" = xt ; then
853 echo "Error: can't satisfy package dependencies:"
854 echo " \"$dname\" is required by the dependency rules"
855 echo " but is disallowed by the DISABLE settings"
856 exit 1
857 else
858 PACKAGES="$PACKAGES $dname"
859 ck=
860 fi
861 fi
862
863 # Do we need to get rid of $dname according to the dependency rules?
864 if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
865 echo "Error: can't satisfy package dependencies:"
866 echo " \"$pname\" was requested but is disallowed by"
867 echo " the dependency rules for \"$dname\""
868 exit 1
869 fi
870 i=$(( $i + 1 ))
871 done
872 ck=$ck"t"
873 done
874 echo " packages are: $PACKAGES"
875 for i in $PACKAGES ; do
876 adr="$ROOTDIR/pkg/$i"
877 if test -d $adr ; then
878 SOURCEDIRS="$SOURCEDIRS $adr"
879 INCLUDEDIRS="$INCLUDEDIRS $adr"
880 if test "x$i" = xautodiff ; then
881 AUTODIFF_PKG_USED=t
882 fi
883 else
884 echo "Error: the directory \"$adr\" for package $i doesn't exist"
885 exit 1
886 fi
887 done
888
889 # This is compatible with the old genmake. The "DISABLE_*" flags
890 # need to be replaced by the "ALLOW_*" flags set below.
891 #
892 # echo -n " Setting package-specific CPP flags: "
893 # pkrm=( mom_fluxform mom_vecinv generic_advdiff )
894 # pkrmdef=( -DDISABLE_MOM_FLUXFORM -DDISABLE_MOM_VECINV -DDISABLE_GENERIC_ADVDIFF -DDISABLE_DEBUGMODE )
895 # echo -n " "
896 # i=0
897 # while test $i -lt "${#pkrm[@]}" ; do
898 # echo "$PACKAGES" | grep "${pk[$i]}" > /dev/null 2>&1
899 # RETVAL=$?
900 # if test "x$RETVAL" = x1 ; then
901 # DEFINES="$DEFINES ${pkdef[$i]}"
902 # echo -n " ${pkdef[$i]}"
903 # fi
904 # i=$(( $i + 1 ))
905 # done
906 # echo
907
908 # Create a list of #define and #undef to enable/disable packages
909 PACKAGES_DOT_H=PACKAGES_CONFIG.h
910 cat <<EOF >$PACKAGES_DOT_H".tmp"
911 C=== GENMAKE v2 ===
912 C The following defines have been set by GENMAKE, so please do not
913 C edit anything below these comments. In general, you should
914 C add or remove packages by re-running genmake with different
915 C "-enable" and/or "-disable" options.
916
917 #ifndef PACKAGES_H
918 #define PACKAGES_H
919
920 C Packages disabled by genmake:
921 EOF
922 # The following UGLY HACK sets multiple "#undef"s and it needs to go
923 # away. On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
924 # file would eventually be split up so that all package-related #define
925 # statements could be separated and handled only by genmake.
926 names=`ls -1 "$ROOTDIR/pkg"`
927 all_pack=
928 for n in $names ; do
929 if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
930 has_pack="f"
931 for pack in $PACKAGES ; do
932 if test "x$pack" = "x$n" ; then
933 has_pack="t"
934 break
935 fi
936 done
937 if test "x$has_pack" = xf ; then
938 undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`
939 echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"
940 # DEFINES="$DEFINES -U$undef"
941
942 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
943 case $n in
944 mom_fluxform)
945 DEFINES="$DEFINES -DDISABLE_MOM_FLUXFORM"
946 ;;
947 mom_vecinv)
948 DEFINES="$DEFINES -DDISABLE_MOM_VECINV"
949 ;;
950 debug)
951 DEFINES="$DEFINES -DDISABLE_DEBUGMODE"
952 ;;
953 esac
954 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
955
956 fi
957 fi
958 done
959 cat <<EOF >>$PACKAGES_DOT_H".tmp"
960
961 C Packages enabled by genmake:
962 EOF
963 for i in $PACKAGES ; do
964 def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`
965 echo "#define $def" >> $PACKAGES_DOT_H".tmp"
966 #eh3 DEFINES="$DEFINES -D$def"
967
968 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
969 case $i in
970 aim_v23)
971 echo "#define ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"
972 DEFINES="$DEFINES -DALLOW_AIM"
973 echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)"
974 ;;
975 esac
976 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
977
978 done
979 cat <<EOF >>$PACKAGES_DOT_H".tmp"
980
981 #endif /* PACKAGES_H */
982 EOF
983
984 if test ! -f $PACKAGES_DOT_H ; then
985 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
986 else
987 cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
988 RETVAL=$?
989 if test "x$RETVAL" = x0 ; then
990 rm -f $PACKAGES_DOT_H".tmp"
991 else
992 mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
993 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
994 fi
995 fi
996
997 echo " Adding STANDARDDIRS"
998 BUILDDIR=${BUILDDIR:-.}
999 if test "x$STANDARDDIRS" = x ; then
1000 STANDARDDIRS="eesupp model"
1001 fi
1002 for d in $STANDARDDIRS ; do
1003 adr="$ROOTDIR/$d/src"
1004 if test ! -d $adr ; then
1005 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1006 echo " is correct and that you correctly specified the STANDARDDIRS option"
1007 exit 1
1008 else
1009 SOURCEDIRS="$SOURCEDIRS $adr"
1010 fi
1011 adr="$ROOTDIR/$d/inc"
1012 if test ! -d $adr ; then
1013 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1014 echo " is correct and that you correctly specified the STANDARDDIRS option"
1015 exit 1
1016 else
1017 INCLUDEDIRS="$INCLUDEDIRS $adr"
1018 fi
1019 done
1020
1021 echo " Searching for CPP_OPTIONS.h in order to warn about the presence"
1022 echo " of \"#define ALLOW_PKGNAME\"-type statements:"
1023 CPP_OPTIONS=
1024 spaths=". $INCLUDEDIRS"
1025 for i in $spaths ; do
1026 try="$i/CPP_OPTIONS.h"
1027 # echo -n " trying $try : "
1028 if test -f $try -a -r $try ; then
1029 echo " found CPP_OPTIONS=\"$try\""
1030 CPP_OPTIONS="$try"
1031 break
1032 fi
1033 done
1034 if test "x$CPP_OPTIONS" = x ; then
1035 echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
1036 exit 1
1037 fi
1038 # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1039 names=`ls -1 "$ROOTDIR/pkg"`
1040 for n in $names ; do
1041 test_for_package_in_cpp_options $CPP_OPTIONS $n
1042 done
1043
1044
1045 # Here, we build the list of files to be "run through" the adjoint
1046 # compiler.
1047 if test -f ./ad_files ; then
1048 rm -f ./ad_files
1049 fi
1050 echo " Creating the list of files for the adjoint compiler."
1051 for i in $SOURCEDIRS ; do
1052 list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
1053 for j in $list_files ; do
1054 cat $i/$j >> ad_files
1055 done
1056 done
1057
1058 cat <<EOF > adjoint_sed
1059 s/call adopen(/call adopen ( mythid,\\
1060 \& /g
1061 s/call adclose(/call adclose( mythid,\\
1062 \& /g
1063 s/call adread(/call adread ( mythid,\\
1064 \& /g
1065 s/call adwrite(/call adwrite( mythid,\\
1066 \& /g
1067
1068 EOF
1069
1070 echo
1071 echo "=== Creating the Makefile ==="
1072 echo " setting INCLUDES"
1073 for i in $INCLUDEDIRS ; do
1074 if ! test -d $i ; then
1075 # INCLUDES="$INCLUDES -I$i"
1076 # else
1077 echo "Warning: can't find INCLUDEDIRS=\"$i\""
1078 fi
1079 done
1080
1081 echo " Determining the list of source and include files"
1082 rm -rf .links.tmp
1083 mkdir .links.tmp
1084 echo "# This section creates symbolic links" > srclinks.tmp
1085 echo "" >> srclinks.tmp
1086 echo -n 'SRCFILES = ' > srclist.inc
1087 echo -n 'CSRCFILES = ' > csrclist.inc
1088 echo -n 'F90SRCFILES = ' > f90srclist.inc
1089 echo -n 'HEADERFILES = ' > hlist.inc
1090 echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc
1091 alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1092 for d in $alldirs ; do
1093 deplist=
1094 sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
1095 sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
1096 for sf in $sfiles ; do
1097 if test ! -r ".links.tmp/$sf" ; then
1098 if test -f "$d/$sf" ; then
1099 extn=`echo $sf | awk -F '.' '{print $NF}'`
1100 touch .links.tmp/$sf
1101 deplist="$deplist $sf"
1102 case $extn in
1103 F)
1104 echo " \\" >> srclist.inc
1105 echo -n " $sf" >> srclist.inc
1106 ;;
1107 F90)
1108 echo " \\" >> f90srclist.inc
1109 echo -n " $sf" >> f90srclist.inc
1110 ;;
1111 c)
1112 echo " \\" >> csrclist.inc
1113 echo -n " $sf" >> csrclist.inc
1114 ;;
1115 h)
1116 echo " \\" >> hlist.inc
1117 echo -n " $sf" >> hlist.inc
1118 ;;
1119 flow)
1120 echo " \\" >> ad_flow_files.inc
1121 echo -n " $sf" >> ad_flow_files.inc
1122 ;;
1123 esac
1124 fi
1125 fi
1126 done
1127 if test "x$deplist" != x ; then
1128 echo "" >> srclinks.tmp
1129 echo "# These files are linked from $d" >> srclinks.tmp
1130 echo "$deplist :" >> srclinks.tmp
1131 printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp
1132 fi
1133 done
1134 rm -rf .links.tmp
1135 echo "" >> srclist.inc
1136 echo "" >> csrclist.inc
1137 echo "" >> f90srclist.inc
1138 echo "" >> hlist.inc
1139 echo "" >> ad_flow_files.inc
1140
1141 if test -e $MAKEFILE ; then
1142 mv -f $MAKEFILE "$MAKEFILE.bak"
1143 fi
1144 echo " Writing makefile: $MAKEFILE"
1145 echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
1146 echo "# $MACHINE" >> $MAKEFILE
1147 echo "# This makefile was generated automatically on" >> $MAKEFILE
1148 echo "# $THISDATE" >> $MAKEFILE
1149 echo "# by the command:" >> $MAKEFILE
1150 echo "# $0 $@" >> $MAKEFILE
1151 echo "# executed by:" >> $MAKEFILE
1152 echo "# $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE
1153 cat >>$MAKEFILE <<EOF
1154 #
1155 # BUILDDIR : Directory where object files are written
1156 # SOURCEDIRS : Directories containing the source (.F) files
1157 # INCLUDEDIRS : Directories containing the header-source (.h) files
1158 # EXEDIR : Directory where executable that is generated is written
1159 # EXECUTABLE : Full path of executable binary
1160 #
1161 # CPP : C-preprocessor command
1162 # INCLUDES : Directories searched for header files
1163 # DEFINES : Macro definitions for CPP
1164 # MAKEDEPEND : Dependency generator
1165 # KPP : Special preprocessor command (specific to platform)
1166 # KFLAGS : Flags for KPP
1167 # FC : Fortran compiler command
1168 # FFLAGS : Configuration/debugging options for FC
1169 # FOPTIM : Optimization options for FC
1170 # LINK : Command for link editor program
1171 # LIBS : Library flags /or/ additional optimization/debugging flags
1172
1173 ROOTDIR = ${ROOTDIR}
1174 BUILDDIR = ${BUILDDIR}
1175 SOURCEDIRS = ${SOURCEDIRS}
1176 INCLUDEDIRS = ${INCLUDEDIRS}
1177 EXEDIR = ${EXEDIR}
1178 EXECUTABLE = \$(EXEDIR)/${EXECUTABLE}
1179 TOOLSDIR = ${TOOLSDIR}
1180
1181 #eh3 new defines for the adjoint work
1182 AUTODIFF = ${ROOTDIR}/pkg/autodiff
1183
1184 EOF
1185
1186 # Note: figure out some way to add Hyades JAM libraries here
1187
1188 cat >>$MAKEFILE <<EOF
1189 # Unix ln (link)
1190 LN = ${LN}
1191 # C preprocessor
1192 CPP = cat \$< | ${S64} | ${CPP}
1193 # Dependency generator
1194 MAKEDEPEND = ${MAKEDEPEND}
1195 # Special preprocessor (KAP on DECs, FPP on Crays)
1196 KPP = ${KPP}
1197 # Fortran compiler
1198 FC = ${FC}
1199 # Fortran compiler
1200 F90C = ${F90C}
1201 # Link editor
1202 LINK = ${LINK}
1203
1204 # Defines for CPP
1205 DEFINES = ${DEFINES}
1206 # Includes for CPP
1207 INCLUDES = ${INCLUDES}
1208 # Flags for KPP
1209 KFLAGS1 = ${KFLAGS1}
1210 KFLAGS2 = ${KFLAGS2}
1211 # Optim./debug for FC
1212 FFLAGS = ${FFLAGS}
1213 FOPTIM = ${FOPTIM}
1214 # Optim./debug for FC
1215 F90FLAGS = ${F90FLAGS}
1216 F90OPTIM = ${F90OPTIM}
1217 # Flags for CC
1218 CFLAGS = ${CFLAGS}
1219 # Files that should not be optimized
1220 NOOPTFILES = ${NOOPTFILES}
1221 NOOPTFLAGS = ${NOOPTFLAGS}
1222 # Flags and libraries needed for linking
1223 LIBS = ${LIBS} \$(XLIBS)
1224 # Name of the Mekfile
1225 MAKEFILE=${MAKEFILE}
1226
1227 EOF
1228
1229 cat srclist.inc >> $MAKEFILE
1230 cat csrclist.inc >> $MAKEFILE
1231 cat f90srclist.inc >> $MAKEFILE
1232 cat hlist.inc >> $MAKEFILE
1233 cat ad_flow_files.inc >> $MAKEFILE
1234 echo >> $MAKEFILE
1235 echo 'F77FILES = $(SRCFILES:.F=.f)' >> $MAKEFILE
1236 echo 'F90FILES = $(F90SRCFILES:.F90=.f90)' >> $MAKEFILE
1237 echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
1238
1239 rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc
1240 rm -f ad_flow_files.inc
1241
1242 cat >>$MAKEFILE <<EOF
1243
1244 .SUFFIXES:
1245 .SUFFIXES: .o .f .p .F .c .F90 .f90
1246
1247 all: \$(EXECUTABLE)
1248 \$(EXECUTABLE): \$(OBJFILES)
1249 \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
1250 depend:
1251 @make links
1252 \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
1253 ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)
1254
1255 links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)
1256
1257 small_f: \$(F77FILES) \$(F90FILES)
1258
1259 output.txt: \$(EXECUTABLE)
1260 @printf 'running ... '
1261 @\$(EXECUTABLE) > \$@
1262
1263 clean:
1264 -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}
1265 Clean:
1266 @make clean
1267 @make cleanlinks
1268 -rm -f Makefile.bak genmake_state genmake_optfile make.log
1269 CLEAN:
1270 @make Clean
1271 -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
1272 -find \$(EXEDIR) -name "*.data" -exec rm {} \;
1273 -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
1274 -rm -f \$(EXECUTABLE) output.txt
1275
1276 Makefile: makefile
1277 makefile:
1278 ${0} $@
1279 cleanlinks:
1280 -find . -type l -exec rm {} \;
1281
1282 # The normal chain of rules is ( .F - .f - .o )
1283 .F.f:
1284 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1285 .f.o:
1286 \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
1287 .F90.f90:
1288 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1289 .f90.o:
1290 \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
1291 .c.o:
1292 \$(CC) \$(CFLAGS) -c \$<
1293
1294 # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain
1295 .F.p:
1296 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1297 .p.f:
1298 \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
1299
1300 #=========================================
1301 #=== Automatic Differentiation Rules ===
1302
1303 TAMC = ${TAMC}
1304 TAF = ${TAF}
1305
1306 EOF
1307
1308 ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
1309 ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
1310 ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1311 for i in $ad_vars ; do
1312 name=$i
1313 t1="t2=\$"`echo $i`
1314 eval $t1
1315 printf "%-20s = " $name >> $MAKEFILE
1316 echo $t2 >> $MAKEFILE
1317 done
1318
1319 echo " Add the source list for AD code generation"
1320 echo >> $MAKEFILE
1321 echo -n "AD_FILES = " >> $MAKEFILE
1322 AD_FILES=`cat ad_files`
1323 for i in $AD_FILES ; do
1324 echo " \\" >> $MAKEFILE
1325 echo -n " $i" >> $MAKEFILE
1326 done
1327 echo >> $MAKEFILE
1328
1329 cat >>$MAKEFILE <<EOF
1330
1331
1332 ad_input_code.f: \$(F77FILES)
1333 @make \$(AD_FLOW_FILES)
1334 cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f
1335
1336
1337 ad_taf_output.f: ad_input_code.f
1338 \$(TAF) \$(AD_TAF_FLAGS) ad_input_code.f
1339 cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f
1340
1341 ad_taf: ad_taf_output.o \$(OBJFILES)
1342 \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
1343
1344
1345 ad_tamc_output.f: ad_input_code.f
1346 \$(TAMC) \$(AD_TAMC_FLAGS) ad_input_code.f
1347 cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f
1348
1349 ad_tamc: ad_tamc_output.o \$(OBJFILES)
1350 \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
1351
1352
1353 flt_taf_output.f: ad_input_code.f
1354 \$(TAF) \$(FTL_TAF_FLAGS) ad_input_code.f
1355 cat ad_input_code_ad.f | sed -f adjoint_sed > flt_taf_output.f
1356
1357 flt_taf: flt_taf_output.o \$(OBJFILES)
1358 \$(LINK) -o ${EXECUTABLE} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) flt_taf_output.o \$(LIBS)
1359
1360
1361
1362 #=========================================
1363
1364 EOF
1365
1366 if test "x$EXEHOOK" != x ; then
1367 printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
1368 fi
1369
1370 echo " Making list of \"exceptions\" that need \".p\" files"
1371 for i in $KPPFILES ; do
1372 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
1373 RETVAL=$?
1374 if test "x$RETVAL" != x0 ; then
1375 echo "Error: unable to add file \"$i\" to the exceptions list"
1376 fi
1377 echo "$base.f: $base.p" >> $MAKEFILE
1378 done
1379
1380 echo " Making list of NOOPTFILES"
1381 for i in $NOOPTFILES ; do
1382 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
1383 RETVAL=$?
1384 if test "x$RETVAL" != x0 ; then
1385 echo "Error: unable to add file \"$i\" to the exceptions list"
1386 fi
1387 echo "$base.o: $base.f" >> $MAKEFILE
1388 printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
1389 done
1390
1391 echo " Add rules for links"
1392 cat srclinks.tmp >> $MAKEFILE
1393 rm -f srclinks.tmp
1394
1395 echo " Adding makedepend marker"
1396 printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
1397
1398 printf "\n=== Done ===\n"
1399
1400
1401 # Write the "state" for future records
1402 if test "x$DUMPSTATE" != xf ; then
1403 echo -n "" > genmake_state
1404 for i in $gm_state ; do
1405 t1="t2=\$$i"
1406 eval $t1
1407 echo "$i='$t2'" >> genmake_state
1408 done
1409 fi

  ViewVC Help
Powered by ViewVC 1.1.22