/[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.11 - (hide annotations) (download)
Mon Sep 29 16:15:23 2003 UTC (16 years ago) by edhill
Branch: MAIN
CVS Tags: checkpoint51j_post, checkpoint51f_post, branchpoint-genmake2, checkpoint51h_pre, checkpoint51g_post, checkpoint51i_pre
Branch point for: branch-genmake2
Changes since 1.10: +168 -103 lines
 o added a platform-detection mechanism to guess at the optfile to use
     when none are specified
 o changed some optfile names to reflect the new platform naming
     convention--more work still needed in this area
 o added parsing of MITGCM_* environment variables

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

  ViewVC Help
Powered by ViewVC 1.1.22