/[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.2.12 - (hide annotations) (download)
Sat Oct 4 14:21:58 2003 UTC (15 years, 7 months ago) by edhill
Branch: branch-genmake2
Changes since 1.11.2.11: +2 -1 lines
more IEEE fixes

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

  ViewVC Help
Powered by ViewVC 1.1.22