/[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.1 - (show annotations) (download)
Sat Aug 16 14:01:08 2003 UTC (20 years, 7 months ago) by edhill
Branch: MAIN
This is the first version of "genmake2" and "testscript2" (and support files)
that pass all the standard verification tests on faulks.  Since they have new
names, they can be run side-by-side (no known conflicts) with the existing
genmake and testscript versions.  If you get a chance, please try them on your
system and mail the output to <eh3@mit.edu>.

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

  ViewVC Help
Powered by ViewVC 1.1.22