/[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.10 - (show annotations) (download)
Fri Sep 26 18:47:59 2003 UTC (15 years, 11 months ago) by adcroft
Branch: MAIN
Changes since 1.9: +3 -3 lines
o Bug fix for following scenario:
  Compiling in  verification/expt/code/  or working with a local real
  file version of CPP_OPTIONS.h then genmake2 fails because it can not find
  a copy of CPP_OPTIONS.h
o also change on screen comment corresponding to changed code
x Note! This breaks the functionality of the original genmake(1) because
  it assumes that a CPP_OPTIONS.h should take priority over a ./CPP_OPTIONS.h

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

  ViewVC Help
Powered by ViewVC 1.1.22