/[MITgcm]/MITgcm/tools/genmake2
ViewVC logotype

Annotation of /MITgcm/tools/genmake2

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (hide annotations) (download)
Fri Sep 5 00:25:42 2003 UTC (20 years, 6 months ago) by edhill
Branch: MAIN
Changes since 1.5: +12 -5 lines
two small changes to fix compilation on the IBM sp4 "bluesky"

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

  ViewVC Help
Powered by ViewVC 1.1.22