/[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.7 - (hide annotations) (download)
Mon Sep 22 19:06:12 2003 UTC (16 years, 2 months ago) by edhill
Branch: MAIN
Changes since 1.6: +11 -3 lines
 - fix absolute path on f90mkdepend
 - add EXEHOOK to the Makefile

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

  ViewVC Help
Powered by ViewVC 1.1.22