/[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.3 - (hide annotations) (download)
Fri Aug 22 20:50:40 2003 UTC (20 years, 7 months ago) by cnh
Branch: MAIN
Changes since 1.2: +35 -14 lines
Changes that should only affect when there are .F90 files present
e.g. ESMF drivers etc...

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

  ViewVC Help
Powered by ViewVC 1.1.22