/[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.5 - (show annotations) (download)
Wed Aug 27 22:12:31 2003 UTC (20 years, 6 months ago) by edhill
Branch: MAIN
Changes since 1.4: +33 -127 lines
Small cleanups to genmake2 and its "optfiles".  Initial check-in of
"testreport" which functions similarly to "testscript" but supports
more genmake2 options and emails results to a central address for
automated testing.

1 #!/bin/bash
2 #
3 # $Header: /u/u3/gcmpack/MITgcm/tools/genmake2,v 1.4 2003/08/26 16:22:15 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
12 # Guess possible config options for this host
13 find_possible_configs() {
14
15 p_PLATFORM=`uname`"-"`uname -m`
16 echo "The platform appears to be:"
17 echo " "$p_PLATFORM
18
19 p_LN=
20 echo "test" > test
21 ln -s ./test link
22 RETVAL=$?
23 if test "x${RETVAL}" = x0 ; then
24 p_LN="ln -s"
25 fi
26 rm -f test link
27
28 p_CPP=`which cpp`
29
30 RETVAL=$?
31 if test "x${RETVAL}" = x0 ; then
32 p_LN="ln -s"
33 fi
34 rm -f test link
35
36 # look for possible fortran compilers
37 p_FC=
38 for c in f77 g77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95 ; do
39 which $c > /dev/null 2>&1
40 RETVAL=$?
41 if test "x${RETVAL}" = x0 ; then
42 p_FC="$p_FC $c"
43 fi
44 done
45 echo "Possible FORTRAN compilers appear to be: "
46 if test "x${p_FC}" = x ; then
47 echo " None found!!!"
48 else
49 echo " "$p_FC
50 fi
51
52 # look for possible MPI libraries
53 mpi_libs=
54 mpi_fort=`which mpif77 2>/dev/null`
55 RETVAL=$?
56 if test "x${RETVAL}" = x0 ; then
57 cat >>test.f <<EOF
58 PROGRAM HELLO
59 DO 10, I=1,10
60 PRINT *,'Hello World'
61 10 CONTINUE
62 STOP
63 END
64 EOF
65 eval "$mpi_fort -showme test.f > out"
66 RETVAL=$?
67 if test "x${RETVAL}" = x0 ; then
68 a=`cat out`
69 for i in $a ; do
70 case $i in
71 -*)
72 mpi_libs="$mpi_libs $i" ;;
73 esac
74 done
75 echo "The MPI libs appear to be:"
76 echo " "$mpi_libs
77 fi
78 rm -f test.f out
79 fi
80
81 }
82
83 # Parse the package dependency information
84 get_pdepend_list() {
85
86 # strip the comments and then convert the dependency file into
87 # two arrays: PNAME, DNAME
88 cat $1 | sed -e 's/#.*$//g' \
89 | awk 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \
90 > ./.pd_tmp
91 source ./.pd_tmp
92 rm -f ./.pd_tmp
93
94 echo -n "PNAME = "${}
95 }
96
97
98 # Explain usage
99 usage() {
100 echo
101 echo "Usage: "$0" [OPTIONS]"
102 echo " where [OPTIONS] can be:"
103 echo
104 echo " -help | --help | -h | --h"
105 echo " -nooptfile | --nooptfile"
106 echo " -optfile NAME | --optfile NAME | -of NAME | --of NAME"
107 echo " -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME"
108 echo " -pdepend NAME | --pdepend NAME"
109 echo " -pdepend=NAME | --pdepend=NAME"
110 echo " -pdefault NAME | --pdefault NAME"
111 echo " -pdefault=NAME | --pdefault=NAME"
112 echo " -makefile NAME | -ma NAME"
113 echo " --makefile=NAME | -ma=NAME"
114 echo " -platform NAME | --platform NAME | -pl NAME | --pl NAME"
115 echo " -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"
116 echo " -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"
117 echo " -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME"
118 echo " -mods NAME | --mods NAME | -mo NAME | --mo NAME"
119 echo " -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME"
120 echo " -disable NAME | --disable NAME"
121 echo " -disable=NAME | --disable=NAME"
122 echo " -enable NAME | --enable NAME"
123 echo " -enable=NAME | --enable=NAME"
124 echo " -noopt NAME | --noopt NAME"
125 echo " -noopt=NAME | --noopt=NAME"
126 # echo " -cpp NAME | --cpp NAME"
127 # echo " -cpp=NAME | --cpp=NAME"
128 echo " -fortran NAME | --fortran NAME | -fc NAME | --fc NAME"
129 echo " -fc=NAME | --fc=NAME"
130 echo " -[no]ieee | --[no]ieee"
131 echo " -[no]mpi | --[no]mpi"
132 echo " -[no]jam | --[no]jam"
133 echo
134 echo " and NAME is a string such as:"
135 echo
136 echo " --enable pkg1 --enable 'pkg1 pkg2' --enable 'pkg1 pkg2 pkg3'"
137 echo " -mods=dir1 -mods='dir1' -mods='dir1 dir2 dir3'"
138 echo " -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"
139 echo
140 echo " which, depending upon your shell, may need to be single-quoted"
141 echo " if it contains spaces, dashes, or other special characters."
142 exit 1
143 }
144
145 #eh3 # This is the generic configuration.
146 #eh3 set LN = ( 'ln -s' )
147 #eh3 set CPP = ( '/lib/cpp -P' )
148 #eh3 set S64 = ( '$(TOOLSDIR)/set64bitConst.sh' )
149 #eh3 set KPP = ( )
150 #eh3 set FC = ( 'f77' )
151 #eh3 set LINK = $FC
152 #eh3 set MAKEDEPEND = ( 'makedepend' )
153 #eh3 set INCLUDES = ( -I. )
154 #eh3 set FFLAGS = ( )
155 #eh3 set FOPTIM = ( )
156 #eh3 set CFLAGS = ( )
157 #eh3 set KFLAGS1 = ( )
158 #eh3 set KFLAGS2 = ( )
159 #eh3 set LIBS = ( )
160 #eh3 set KPPFILES = ( )
161 #eh3 if (! $?NOOPTFILES ) set NOOPTFILES = ( )
162 #eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = ( )
163
164 # Set defaults here
165 COMMANDL="$0 $@"
166
167 PLATFORM=
168 LN=
169 S64=
170 KPP=
171 FC=
172 LINK=
173 PACKAGES=
174 ENABLE=
175 DISABLE=
176 MAKEFILE=
177 MAKEDEPEND=
178 PDEPEND=
179 DUMPSTATE=f
180 PDEFAULT=
181 OPTFILE=
182 INCLUDES="-I."
183 FFLAGS=
184 FOPTIM=
185 CFLAGS=
186 KFLAGS1=
187 KFLAGS2=
188 LIBS=
189 KPPFILES=
190 NOOPTFILES=
191 NOOPTFLAGS=
192
193 MODS=
194 TOOLSDIR=
195 SOURCEDIRS=
196 INCLUDEDIRS=
197
198 PWD=`pwd`
199 MAKE=make
200 THISHOSTNAME=`hostname`
201 THISCWD=`pwd`
202 THISDATE=`date`
203 MACHINE=`uname -a`
204
205 # The following state can be set directly by command-line switches
206 gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"
207 gm_s2="FC IEEE MPI JAM DUMPSTATE"
208
209 # The following state is not directly set by command-line switches
210 gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
211 gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
212 gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"
213
214 gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5"
215
216
217 echo
218 echo "=== Processing options files and arguments ==="
219 gm_local="./gm_local"
220 echo -n " getting local config information: "
221 if test -e $gm_local ; then
222 echo "using $gm_local"
223 source $gm_local
224 # echo "DISABLE=$DISABLE"
225 # echo "ENABLE=$ENABLE"
226 else
227 echo "none found"
228 fi
229
230 # echo "$0::$1:$2:$3:$4:$5:$6:$7:"
231 #OPTIONS=
232 #n=0
233 #for i ; do
234 # echo "$i $n"
235 # setvar="OPTIONS[$n]='$i'"
236 # # echo " $setvar"
237 # eval "$setvar"
238 # n=$(( $n + 1 ))
239 #done
240 #parse_options
241
242 ac_prev=
243 for ac_option ; do
244
245 # If the previous option needs an argument, assign it.
246 if test -n "$ac_prev"; then
247 eval "$ac_prev=\$ac_option"
248 ac_prev=
249 continue
250 fi
251
252 ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
253
254 case $ac_option in
255
256 -help | --help | -h | --h)
257 usage ;;
258
259 -nooptfile | --nooptfile)
260 OPTFILE="NONE" ;;
261 -optfile | --optfile | -of | --of)
262 ac_prev=OPTFILE ;;
263 -optfile=* | --optfile=* | -of=* | --of=*)
264 OPTFILE=$ac_optarg ;;
265
266 -pdepend | --pdepend)
267 ac_prev=PDEPEND ;;
268 -pdepend=* | --pdepend=*)
269 PDEPEND=$ac_optarg ;;
270
271 -pdefault | --pdefault)
272 ac_prev=PDEFAULT ;;
273 -pdefault=* | --pdefault=*)
274 PDEFAULT=$ac_optarg ;;
275
276 -makefile | -ma)
277 ac_prev=MAKEFILE ;;
278 --makefile=* | -ma=*)
279 MAKEFILE=$ac_optarg ;;
280
281 -platform | --platform | -pl | --pl)
282 ac_prev=PLATFORM ;;
283 -platform=* | --platform=* | -pl=* | --pl=*)
284 PLATFORM=$ac_optarg ;;
285
286 -rootdir | --rootdir | -rd | --rd)
287 ac_prev=ROOTDIR ;;
288 -rootdir=* | --rootdir=* | -rd=* | --rd=*)
289 ROOTDIR=$ac_optarg ;;
290
291 -mods | --mods | -mo | --mo)
292 ac_prev=MODS ;;
293 -mods=* | --mods=* | -mo=* | --mo=*)
294 MODS=$ac_optarg ;;
295
296 -disable | --disable)
297 ac_prev=DISABLE ;;
298 -disable=* | --disable=*)
299 DISABLE=$ac_optarg ;;
300
301 -enable | --enable)
302 ac_prev=ENABLE ;;
303 -enable=* | --enable=*)
304 ENABLE=$ac_optarg ;;
305
306 -noopt | --noopt)
307 ac_prev=NOOPT ;;
308 -noopt=* | --noopt=*)
309 NOOPT=$ac_optarg ;;
310
311 # -cpp | --cpp)
312 # ac_prev=cpp ;;
313 # -cpp=* | --cpp=*)
314 # CPP=$ac_optarg ;;
315
316 -fortran | --fortran | -fc | --fc)
317 ac_prev=FC ;;
318 -fc=* | --fc=*)
319 FC=$ac_optarg ;;
320
321 -ieee | --ieee)
322 IEEE=1 ;;
323 -noieee | --noieee)
324 IEEE=0 ;;
325
326 -mpi | --mpi)
327 MPI=1 ;;
328 -nompi | --nompi)
329 MPI=0 ;;
330
331 -jam | --jam)
332 JAM=1 ;;
333 -nojam | --nojam)
334 JAM=0 ;;
335
336 -ds | --ds)
337 DUMPSTATE=t ;;
338
339 -*)
340 echo "Error: unrecognized option: "$ac_option
341 usage
342 ;;
343
344 *)
345 echo "Error: unrecognized argument: "$ac_option
346 usage
347 ;;
348
349 esac
350
351 done
352
353 echo " getting OPTFILE information: "
354 if test "x${OPTFILE}" = x ; then
355 echo "Warning: no OPTFILE specified so we'll look for possible settings"
356 printf "\n=== Searching for possible settings for OPTFILE ===\n"
357 find_possible_configs
358 else
359 if test "x$OPTFILE" = xNONE ; then
360 echo " OPTFILE=NONE so we'll try to use default settings"
361 else
362 if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
363 echo " using OPTFILE=\"$OPTFILE\""
364 source "$OPTFILE"
365 RETVAL=$?
366 if test "x$RETVAL" != x0 ; then
367 echo -n "Error: failed to source OPTFILE \"$OPTFILE\""
368 echo "--please check that variable syntax is bash-compatible"
369 exit 1
370 fi
371 if test "x$DUMPSTATE" != xf ; then
372 cp -f $OPTFILE "gm_optfile"
373 fi
374 else
375 echo "Error: can't read OPTFILE=\"$OPTFILE\""
376 exit 1
377 fi
378 fi
379 fi
380
381 printf "\n=== Setting defaults ===\n"
382 echo -n " Adding MODS directories: "
383 for d in $MODS ; do
384 if test ! -d $d ; then
385 echo
386 echo "Error: MODS directory \"$d\" not found!"
387 exit 1
388 else
389 echo -n " $d"
390 SOURCEDIRS="$SOURCEDIRS $d"
391 INCLUDEDIRS="$INCLUDEDIRS $d"
392 fi
393 done
394 echo
395
396 if test "x$MAKEFILE" = x ; then
397 MAKEFILE="Makefile"
398 fi
399 if test "x${PLATFORM}" = x ; then
400 PLATFORM=$p_PLATFORM
401 fi
402
403 if test "x${ROOTDIR}" = x ; then
404 if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
405 ROOTDIR=".."
406 else
407 for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
408 if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
409 ROOTDIR=$d
410 echo -n "Warning: ROOTDIR was not specified but there appears to be"
411 echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
412 break
413 fi
414 done
415 fi
416 fi
417 if test "x${ROOTDIR}" = x ; then
418 echo "Error: Cannot determine ROOTDIR for MITgcm code."
419 echo " Please specify a ROOTDIR using either an options "
420 echo " file or a command-line option."
421 exit 1
422 fi
423 if test ! -d ${ROOTDIR} ; then
424 echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
425 exit 1
426 fi
427
428 if test "x${EXEDIR}" = x ; then
429 if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then
430 EXEDIR=../exe
431 else
432 EXEDIR=.
433 fi
434 fi
435 if test ! -d ${EXEDIR} ; then
436 echo "Error: the specified EXEDIR (\"$EXEDIR\") does not exist!"
437 exit 1
438 fi
439
440 if test "x${TOOLSDIR}" = x ; then
441 TOOLSDIR="$ROOTDIR/tools"
442 fi
443 if test ! -d ${TOOLSDIR} ; then
444 echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"
445 exit 1
446 fi
447
448 EXECUTABLE=${EXECUTABLE:-mitgcmuv}
449
450 # We have a special set of source files in eesupp/src which are
451 # generated from some template source files. We'll make them first so
452 # they appear as regular source code
453 if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
454 echo " Making source files in eesupp from templates"
455 $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1
456 RETVAL=$?
457 if test "x${RETVAL}" = x0 ; then
458 rm -f make_eesupp.errors
459 else
460 echo "Error: problem encountered while building source files in eesupp:"
461 cat make_eesupp.errors
462 exit 1
463 fi
464 fi
465
466 printf "\n=== Determining package settings ===\n"
467 if test "x${PDEPEND}" = x ; then
468 tmp=$ROOTDIR"/pkg/pkg_depend"
469 if test -r $tmp ; then
470 PDEPEND=$tmp
471 else
472 echo "Warning: No package dependency information was specified."
473 echo " Please check that ROOTDIR/pkg/pkg_depend exists."
474 fi
475 else
476 if test ! -r ${PDEPEND} ; then
477 echo "Error: can't read package dependency info from PDEPEND=\"$PDEPEND\""
478 exit 1
479 fi
480 fi
481 echo " getting package dependency info from $PDEPEND"
482 # Strip the comments and then convert the dependency file into
483 # two arrays: PNAME, DNAME
484 cat $PDEPEND | sed -e 's/#.*$//g' \
485 | awk 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
486 > ./.pd_tmp
487 RETVAL=$?
488 if test ! "x${RETVAL}" = x0 ; then
489 echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
490 exit 1
491 fi
492 source ./.pd_tmp
493 rm -f ./.pd_tmp
494
495 echo -n " checking default package list: "
496 if test "x${PDEFAULT}" = x ; then
497 PDEFAULT="$ROOTDIR/pkg/pkg_default"
498 fi
499 if test "x${PDEFAULT}" = xNONE ; then
500 echo "default packages file disabled"
501 else
502 if test ! -r $PDEFAULT ; then
503 echo ""
504 echo "Warning: can't read default packages from PDEFAULT=\"$PDEFAULT\""
505 else
506 echo " using PDEFAULT=\"$PDEFAULT\""
507 # Strip the comments and add all the names
508 def=`cat $PDEFAULT | sed -e 's/#.*$//g' | awk '(NF>0){print $0}'`
509 RETVAL=$?
510 if test "x${RETVAL}" != x0 ; then
511 echo -n "Error: can't parse default package list "
512 echo "-- please check PDEFAULT=\"$PDEFAULT\""
513 exit 1
514 fi
515 for i in $def ; do
516 PACKAGES="$PACKAGES $i"
517 done
518 echo " packages are: $PACKAGES"
519 fi
520 fi
521
522 echo " applying DISABLE settings"
523 pack=
524 for p in $PACKAGES ; do
525 addit="t"
526 for d in $DISABLE ; do
527 if test "x$p" = "x$d" ; then
528 addit="f"
529 fi
530 done
531 if test "x$addit" = xt ; then
532 pack="$pack $p"
533 fi
534 done
535 PACKAGES="$pack"
536 echo " applying ENABLE settings"
537 rm -f ./.tmp_pack
538 PACKAGES="$PACKAGES $ENABLE"
539 for i in $PACKAGES ; do
540 if test ! -d "$ROOTDIR/pkg/$i" ; then
541 echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
542 exit 1
543 fi
544 echo $i >> ./.tmp_pack
545 done
546 pack=`cat ./.tmp_pack | sort | uniq`
547 rm -f ./.tmp_pack
548 PACKAGES=
549 for i in $pack ; do
550 PACKAGES="$PACKAGES $i"
551 done
552 echo " packages are: $PACKAGES"
553
554 echo " applying package dependency rules"
555 ck=
556 while test "x$ck" != xtt ; do
557 i=0
558 # rtot=${#PNAME[@]}
559 rtot=$nname
560 while test $i -lt $rtot ; do
561
562 # Is $pname in the current $PACKAGES list?
563 # pname=${PNAME[$i]}
564 tmp="pname=\"\$PNAME_$i\""
565 eval $tmp
566 pin="f"
567 for p in $PACKAGES ; do
568 if test "x$p" = "x$pname" ; then
569 pin="t"
570 fi
571 done
572
573 # Is the DNAME entry a (+) or (-) rule ?
574 tmp="dname=\"\$DNAME_$i\""
575 eval $tmp
576 plus="-"
577 echo $dname | grep '^+' > /dev/null 2>&1
578 RETVAL=$?
579 if test "x$RETVAL" = x0 ; then
580 plus="+"
581 fi
582
583 # Is $dname in the current $PACKAGES list?
584 dname=`echo $dname | sed -e 's/^[+-]//'`
585 din="f"
586 for p in $PACKAGES ; do
587 if test "x$p" = "x$dname" ; then
588 din="t"
589 fi
590 done
591
592 # Do we need to add $dname according to the dependency rules?
593 if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
594 in_dis="f"
595 for dis in $DISABLE ; do
596 if test "x$dis" = "x$dname" ; then
597 in_dis="t"
598 fi
599 done
600 if test "x$in_dis" = xt ; then
601 echo "Error: can't satisfy package dependencies:"
602 echo " \"$dname\" is required by the dependency rules"
603 echo " but is disallowed by the DISABLE settings"
604 exit 1
605 else
606 PACKAGES="$PACKAGES $dname"
607 ck=
608 fi
609 fi
610
611 # Do we need to get rid of $dname according to the dependency rules?
612 if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
613 echo "Error: can't satisfy package dependencies:"
614 echo " \"$pname\" was requested but is disallowed by"
615 echo " the dependency rules for \"$dname\""
616 exit 1
617 fi
618 i=$(( $i + 1 ))
619 done
620 ck=$ck"t"
621 done
622 echo " packages are: $PACKAGES"
623 for i in $PACKAGES ; do
624 adr="$ROOTDIR/pkg/$i"
625 if test -d $adr ; then
626 SOURCEDIRS="$SOURCEDIRS $adr"
627 INCLUDEDIRS="$INCLUDEDIRS $adr"
628 else
629 echo "Error: the directory \"$adr\" for package $i doesn't exist"
630 exit 1
631 fi
632 done
633
634 # This is compatible with the old genmake. The "DISABLE_*" flags
635 # need to be replaced by the "ALLOW_*" flags set below.
636 #
637 # echo -n " Setting package-specific CPP flags: "
638 # pkrm=( mom_fluxform mom_vecinv generic_advdiff )
639 # pkrmdef=( -DDISABLE_MOM_FLUXFORM -DDISABLE_MOM_VECINV -DDISABLE_GENERIC_ADVDIFF -DDISABLE_DEBUGMODE )
640 # echo -n " "
641 # i=0
642 # while test $i -lt "${#pkrm[@]}" ; do
643 # echo "$PACKAGES" | grep "${pk[$i]}" > /dev/null 2>&1
644 # RETVAL=$?
645 # if test "x$RETVAL" = x1 ; then
646 # DEFINES="$DEFINES ${pkdef[$i]}"
647 # echo -n " ${pkdef[$i]}"
648 # fi
649 # i=$(( $i + 1 ))
650 # done
651 # echo
652
653 echo " Setting package-specific CPP flags in CPP_OPTIONS.h:"
654 CPP_OPTIONS=
655 spaths="$SOURCEDIRS"
656 for i in $spaths ; do
657 try="$i/CPP_OPTIONS.h"
658 # echo -n " trying $try : "
659 if test -f $try -a -r $try ; then
660 echo " found CPP_OPTIONS=\"$try\""
661 CPP_OPTIONS="$try"
662 if test "x$i" != "x." ; then
663 cp -f $CPP_OPTIONS .
664 fi
665 break
666 fi
667 done
668 if test "x$CPP_OPTIONS" = x ; then
669 echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
670 exit 1
671 fi
672 if test -e CPP_OPTIONS.h ; then
673 if test ! -e CPP_OPTIONS.h.bak ; then
674 cp -f CPP_OPTIONS.h CPP_OPTIONS.h.bak
675 fi
676 cat CPP_OPTIONS.h \
677 | awk 'BEGIN{p=1;} ($1=="C===" && $2=="GENMAKE"){p=0;} {if (p==1) print $0}' \
678 > CPP_OPTIONS.h.tmp
679 fi
680 cat <<EOF >>CPP_OPTIONS.h.tmp
681 C=== GENMAKE v2 ===
682 C The following defines have been set by GENMAKE, so please edit
683 C them only if you know what you're doing. In general, you should
684 C add or remove packages by re-running genmake with different
685 C "-enable" and/or "-disable" options.
686
687 C Packages disabled by genmake:
688 EOF
689 # The following UGLY HACK sets multiple "#undef"s and it needs to go
690 # away. On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
691 # file would eventually be split up so that all package-related #define
692 # statements could be separated and handled only by genmake.
693 names=`ls -1 "$ROOTDIR/pkg"`
694 all_pack=
695 for n in $names ; do
696 if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
697 has_pack="f"
698 for pack in $PACKAGES ; do
699 if test "x$pack" = "x$n" ; then
700 has_pack="t"
701 break
702 fi
703 done
704 if test "x$has_pack" = xf ; then
705 undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`
706 echo "#undef $undef" >> CPP_OPTIONS.h.tmp
707
708 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
709 case $n in
710 mom_fluxform)
711 DEFINES="$DEFINES -DDISABLE_MOM_FLUXFORM"
712 ;;
713 mom_vecinv)
714 DEFINES="$DEFINES -DDISABLE_MOM_VECINV"
715 ;;
716 generic_advdiff)
717 DEFINES="$DEFINES -DDISABLE_GENERIC_ADVDIFF"
718 ;;
719 debug)
720 DEFINES="$DEFINES -DDISABLE_DEBUGMODE"
721 ;;
722 esac
723 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
724
725 fi
726 fi
727 done
728 cat <<EOF >>CPP_OPTIONS.h.tmp
729
730 C Packages enabled by genmake:
731 EOF
732 for i in $PACKAGES ; do
733 def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`
734 echo "#define $def" >> CPP_OPTIONS.h.tmp
735
736 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
737 case $i in
738 aim_v23)
739 echo "#define ALLOW_AIM" >> CPP_OPTIONS.h.tmp
740 ;;
741 esac
742 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
743
744 done
745 mv -f CPP_OPTIONS.h.tmp CPP_OPTIONS.h
746
747 echo " Adding STANDARDDIRS"
748 BUILDDIR=${BUILDDIR:-.}
749 STANDARDDIRS=${STANDARDDIRS:-"eesupp model"}
750 for d in $STANDARDDIRS ; do
751 adr="$ROOTDIR/$d/src"
752 if test ! -d $adr ; then
753 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
754 echo " is correct and that you correctly specified the STANDARDDIRS option"
755 exit 1
756 else
757 SOURCEDIRS="$SOURCEDIRS $adr"
758 fi
759 adr="$ROOTDIR/$d/inc"
760 if test ! -d $adr ; then
761 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
762 echo " is correct and that you correctly specified the STANDARDDIRS option"
763 exit 1
764 else
765 INCLUDEDIRS="$INCLUDEDIRS $adr"
766 fi
767 done
768
769
770 echo
771 echo "=== Creating the Makefile ==="
772 echo " setting INCLUDES"
773 for i in $INCLUDEDIRS ; do
774 if test -d $i ; then
775 INCLUDES="$INCLUDES -I$i"
776 else
777 echo "Warning: can't find INCLUDEDIRS=\"$i\""
778 fi
779 done
780
781 echo " Determining the list of source and include files"
782 rm -rf .links.tmp
783 mkdir .links.tmp
784 echo "# This section creates symbolic links" > srclinks.tmp
785 echo "" >> srclinks.tmp
786 echo -n 'SRCFILES = ' > srclist.inc
787 echo -n 'CSRCFILES = ' > csrclist.inc
788 echo -n 'F90SRCFILES = ' > f90srclist.inc
789 echo -n 'HEADERFILES = ' > hlist.inc
790 alldirs=". $SOURCEDIRS $INCLUDEDIRS"
791 for d in $alldirs ; do
792 deplist=
793 sfiles=`( cd $d; echo *.[h,c,F] )`
794 sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
795 for sf in $sfiles ; do
796 if test ! -r ".links.tmp/$sf" ; then
797 if test -f "$d/$sf" ; then
798 extn=`echo $sf | awk -F '.' '{print $NF}'`
799 touch .links.tmp/$sf
800 deplist="$deplist $sf"
801 case $extn in
802 F)
803 echo " \\" >> srclist.inc
804 echo -n " $sf" >> srclist.inc
805 ;;
806 F90)
807 echo " \\" >> f90srclist.inc
808 echo -n " $sf" >> f90srclist.inc
809 ;;
810 c)
811 echo " \\" >> csrclist.inc
812 echo -n " $sf" >> csrclist.inc
813 ;;
814 h)
815 echo " \\" >> hlist.inc
816 echo -n " $sf" >> hlist.inc
817 ;;
818 esac
819 fi
820 fi
821 done
822 if test "x$deplist" != x ; then
823 echo "" >> srclinks.tmp
824 echo "# These files are linked from $d" >> srclinks.tmp
825 echo "$deplist :" >> srclinks.tmp
826 printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp
827 fi
828 done
829 rm -rf .links.tmp
830 echo "" >> srclist.inc
831 echo "" >> csrclist.inc
832 echo "" >> f90srclist.inc
833 echo "" >> hlist.inc
834
835 if test -e $MAKEFILE ; then
836 mv -f $MAKEFILE "$MAKEFILE.bak"
837 fi
838 echo " Writing makefile: $MAKEFILE"
839 echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
840 echo "# $MACHINE" >> $MAKEFILE
841 echo "# This makefile was generated automatically on" >> $MAKEFILE
842 echo "# $THISDATE" >> $MAKEFILE
843 echo "# by the command:" >> $MAKEFILE
844 echo "# $0 $@" >> $MAKEFILE
845 echo "# executed by:" >> $MAKEFILE
846 echo "# $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE
847 cat >>$MAKEFILE <<EOF
848 #
849 # BUILDDIR : Directory where object files are written
850 # SOURCEDIRS : Directories containing the source (.F) files
851 # INCLUDEDIRS : Directories containing the header-source (.h) files
852 # EXEDIR : Directory where executable that is generated is written
853 # EXECUTABLE : Full path of executable binary
854 #
855 # CPP : C-preprocessor command
856 # INCLUDES : Directories searched for header files
857 # DEFINES : Macro definitions for CPP
858 # MAKEDEPEND : Dependency generator
859 # KPP : Special preprocessor command (specific to platform)
860 # KFLAGS : Flags for KPP
861 # FC : Fortran compiler command
862 # FFLAGS : Configuration/debugging options for FC
863 # FOPTIM : Optimization options for FC
864 # LINK : Command for link editor program
865 # LIBS : Library flags /or/ additional optimization/debugging flags
866
867 ROOTDIR = ${ROOTDIR}
868 BUILDDIR = ${BUILDDIR}
869 SOURCEDIRS = ${SOURCEDIRS}
870 INCLUDEDIRS = ${INCLUDEDIRS}
871 EXEDIR = ${EXEDIR}
872 EXECUTABLE = \$(EXEDIR)/${EXECUTABLE}
873 TOOLSDIR = ${TOOLSDIR}
874
875 EOF
876
877 # Note: figure out some way to add Hyades JAM libraries here
878
879 cat >>$MAKEFILE <<EOF
880 # Unix ln (link)
881 LN = ${LN}
882 # C preprocessor
883 CPP = cat \$< | ${S64} | ${CPP}
884 # Dependency generator
885 MAKEDEPEND = ${MAKEDEPEND}
886 # Special preprocessor (KAP on DECs, FPP on Crays)
887 KPP = ${KPP}
888 # Fortran compiler
889 FC = ${FC}
890 # Fortran compiler
891 F90C = ${F90C}
892 # Link editor
893 LINK = ${LINK}
894
895 # Defines for CPP
896 DEFINES = ${DEFINES}
897 # Includes for CPP
898 INCLUDES = ${INCLUDES}
899 # Flags for KPP
900 KFLAGS1 = ${KFLAGS1}
901 KFLAGS2 = ${KFLAGS2}
902 # Optim./debug for FC
903 FFLAGS = ${FFLAGS}
904 FOPTIM = ${FOPTIM}
905 # Optim./debug for FC
906 F90FLAGS = ${F90FLAGS}
907 F90OPTIM = ${F90OPTIM}
908 # Flags for CC
909 CFLAGS = ${CFLAGS}
910 # Files that should not be optimized
911 NOOPTFILES = ${NOOPTFILES}
912 NOOPTFLAGS = ${NOOPTFLAGS}
913 # Flags and libraries needed for linking
914 LIBS = ${LIBS} \$(XLIBS)
915 # Name of the Mekfile
916 MAKEFILE=${MAKEFILE}
917
918 EOF
919
920 cat srclist.inc >> $MAKEFILE
921 cat csrclist.inc >> $MAKEFILE
922 cat f90srclist.inc >> $MAKEFILE
923 cat hlist.inc >> $MAKEFILE
924 echo 'F77FILES = $(SRCFILES:.F=.f)' >> $MAKEFILE
925 echo 'F90FILES = $(F90SRCFILES:.F90=.f90)' >> $MAKEFILE
926 echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
927
928 rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc
929
930 cat >>$MAKEFILE <<EOF
931
932 .SUFFIXES:
933 .SUFFIXES: .o .f .p .F .c .F90 .f90
934
935 all: \$(EXECUTABLE)
936 \$(EXECUTABLE): \$(OBJFILES)
937 \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
938 depend:
939 @make links
940 \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
941 ../../../tools/f90mkdepend >> \$(MAKEFILE)
942
943 links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)
944
945 small_f: \$(F77FILES) \$(F90FILES)
946
947 output.txt: \$(EXECUTABLE)
948 @printf 'running ... '
949 @\$(EXECUTABLE) > \$@
950
951 clean:
952 -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}
953 Clean:
954 @make clean
955 @make cleanlinks
956 -rm -f Makefile.bak
957 CLEAN:
958 @make Clean
959 -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
960 -find \$(EXEDIR) -name "*.data" -exec rm {} \;
961 -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
962 -rm -f \$(EXECUTABLE)
963
964 makefile:
965 ${0} $@
966 cleanlinks:
967 -find . -type l -exec rm {} \;
968
969 # The normal chain of rules is ( .F - .f - .o )
970 .F.f:
971 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
972 .f.o:
973 \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
974 .F90.f90:
975 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
976 .f90.o:
977 \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
978 .c.o:
979 \$(CC) \$(CFLAGS) -c \$<
980
981 # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain
982 .F.p:
983 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
984 .p.f:
985 \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
986
987 EOF
988
989 echo " Making list of \"exceptions\" that need \".p\" files"
990 for i in $KPPFILES ; do
991 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
992 RETVAL=$?
993 if test "x$RETVAL" != x0 ; then
994 echo "Error: unable to add file \"$i\" to the exceptions list"
995 fi
996 echo "$base.f: $base.p" >> $MAKEFILE
997 done
998
999 echo " Making list of NOOPTFILES"
1000 for i in $NOOPTFILES ; do
1001 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
1002 RETVAL=$?
1003 if test "x$RETVAL" != x0 ; then
1004 echo "Error: unable to add file \"$i\" to the exceptions list"
1005 fi
1006 echo "$base.o: $base.f" >> $MAKEFILE
1007 printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
1008 done
1009
1010 echo " Add rules for links"
1011 cat srclinks.tmp >> $MAKEFILE
1012 rm -f srclinks.tmp
1013
1014 echo " Adding makedepend marker"
1015 printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
1016
1017 printf "\n=== Done ===\n"
1018
1019
1020 # Write the "state" for future records
1021 if test "x$DUMPSTATE" != xf ; then
1022 echo -n "" > gm_state
1023 for i in $gm_state ; do
1024 t1="t2=\$$i"
1025 eval $t1
1026 echo "$i='$t2'" >> gm_state
1027 done
1028 fi

  ViewVC Help
Powered by ViewVC 1.1.22