/[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.32 - (show annotations) (download)
Wed Nov 12 22:05:47 2003 UTC (20 years, 4 months ago) by edhill
Branch: MAIN
CVS Tags: checkpoint52a_pre
Changes since 1.31: +4 -1 lines
 o add test file cleanup

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

  ViewVC Help
Powered by ViewVC 1.1.22