/[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.30 - (show annotations) (download)
Tue Nov 11 21:11:06 2003 UTC (16 years, 1 month ago) by edhill
Branch: MAIN
Changes since 1.29: +2 -1 lines
 o have xmakedepend use the genmake2 output in order to select the C
   pre-processor

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

  ViewVC Help
Powered by ViewVC 1.1.22