/[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.11 - (hide annotations) (download)
Sat Oct 4 13:56:40 2003 UTC (20 years, 6 months ago) by edhill
Branch: branch-genmake2
Changes since 1.11.2.10: +8 -5 lines
 o fix IEEE handling

1 edhill 1.1 #!/bin/bash
2     #
3 edhill 1.11.2.11 # $Header: /u/u3/gcmpack/MITgcm/tools/genmake2,v 1.11.2.10 2003/10/03 19:49:06 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.11 if test "x$MITGCM_IEEE" != x ; then
331     IEEE=$MITGCM_IEEE
332     fi
333 edhill 1.1
334 edhill 1.5 # The following state can be set directly by command-line switches
335     gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"
336 edhill 1.11.2.10 gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"
337 edhill 1.5
338     # The following state is not directly set by command-line switches
339     gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
340     gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
341     gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"
342 edhill 1.11.2.10 gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
343 edhill 1.5
344 edhill 1.7 gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6"
345 edhill 1.5
346    
347 edhill 1.2 echo
348     echo "=== Processing options files and arguments ==="
349 edhill 1.11.2.10 gm_local="genmake_local"
350     for i in . $MODS ; do
351     if test -r $i/$gm_local ; then
352     source $i/$gm_local
353     break
354     fi
355     done
356 edhill 1.1 echo -n " getting local config information: "
357     if test -e $gm_local ; then
358     echo "using $gm_local"
359     source $gm_local
360 edhill 1.2 # echo "DISABLE=$DISABLE"
361     # echo "ENABLE=$ENABLE"
362 edhill 1.1 else
363     echo "none found"
364     fi
365    
366     # echo "$0::$1:$2:$3:$4:$5:$6:$7:"
367 edhill 1.2 #OPTIONS=
368     #n=0
369     #for i ; do
370     # echo "$i $n"
371     # setvar="OPTIONS[$n]='$i'"
372     # # echo " $setvar"
373     # eval "$setvar"
374     # n=$(( $n + 1 ))
375     #done
376     #parse_options
377    
378     ac_prev=
379     for ac_option ; do
380    
381     # If the previous option needs an argument, assign it.
382     if test -n "$ac_prev"; then
383     eval "$ac_prev=\$ac_option"
384     ac_prev=
385     continue
386     fi
387    
388     ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
389    
390     case $ac_option in
391    
392     -help | --help | -h | --h)
393     usage ;;
394    
395     -nooptfile | --nooptfile)
396     OPTFILE="NONE" ;;
397     -optfile | --optfile | -of | --of)
398 edhill 1.4 ac_prev=OPTFILE ;;
399 edhill 1.2 -optfile=* | --optfile=* | -of=* | --of=*)
400     OPTFILE=$ac_optarg ;;
401    
402     -pdepend | --pdepend)
403 edhill 1.4 ac_prev=PDEPEND ;;
404 edhill 1.2 -pdepend=* | --pdepend=*)
405     PDEPEND=$ac_optarg ;;
406    
407     -pdefault | --pdefault)
408 edhill 1.4 ac_prev=PDEFAULT ;;
409 edhill 1.2 -pdefault=* | --pdefault=*)
410     PDEFAULT=$ac_optarg ;;
411    
412 edhill 1.6 -make | --make | -m | --m)
413     ac_prev=MAKE ;;
414     -make=* | --make=* | -m=* | --m=*)
415     MAKE=$ac_optarg ;;
416    
417     -makefile | --makefile | -ma | --ma)
418 edhill 1.4 ac_prev=MAKEFILE ;;
419 edhill 1.6 -makefile=* | --makefile=* | -ma=* | --ma=*)
420 edhill 1.2 MAKEFILE=$ac_optarg ;;
421    
422     -platform | --platform | -pl | --pl)
423 edhill 1.4 ac_prev=PLATFORM ;;
424 edhill 1.2 -platform=* | --platform=* | -pl=* | --pl=*)
425     PLATFORM=$ac_optarg ;;
426    
427     -rootdir | --rootdir | -rd | --rd)
428 edhill 1.4 ac_prev=ROOTDIR ;;
429 edhill 1.2 -rootdir=* | --rootdir=* | -rd=* | --rd=*)
430     ROOTDIR=$ac_optarg ;;
431    
432     -mods | --mods | -mo | --mo)
433 edhill 1.4 ac_prev=MODS ;;
434 edhill 1.2 -mods=* | --mods=* | -mo=* | --mo=*)
435     MODS=$ac_optarg ;;
436    
437     -disable | --disable)
438 edhill 1.4 ac_prev=DISABLE ;;
439 edhill 1.2 -disable=* | --disable=*)
440     DISABLE=$ac_optarg ;;
441    
442     -enable | --enable)
443 edhill 1.4 ac_prev=ENABLE ;;
444 edhill 1.2 -enable=* | --enable=*)
445     ENABLE=$ac_optarg ;;
446    
447 edhill 1.11.2.10 -standarddirs | --standarddirs)
448     ac_prev=STANDARDDIRS ;;
449     -standarddirs=* | --standarddirs=*)
450     STANDARDDIRS=$ac_optarg ;;
451    
452 edhill 1.2 -noopt | --noopt)
453 edhill 1.4 ac_prev=NOOPT ;;
454 edhill 1.2 -noopt=* | --noopt=*)
455     NOOPT=$ac_optarg ;;
456    
457     # -cpp | --cpp)
458     # ac_prev=cpp ;;
459     # -cpp=* | --cpp=*)
460     # CPP=$ac_optarg ;;
461    
462     -fortran | --fortran | -fc | --fc)
463 edhill 1.4 ac_prev=FC ;;
464 edhill 1.2 -fc=* | --fc=*)
465     FC=$ac_optarg ;;
466    
467     -ieee | --ieee)
468 edhill 1.11.2.11 IEEE=true ;;
469 edhill 1.2 -noieee | --noieee)
470 edhill 1.11.2.11 IEEE= ;;
471 edhill 1.2
472     -mpi | --mpi)
473 edhill 1.11.2.11 MPI=true ;;
474 edhill 1.2 -nompi | --nompi)
475 edhill 1.11.2.11 MPI= ;;
476 edhill 1.2
477     -jam | --jam)
478     JAM=1 ;;
479     -nojam | --nojam)
480     JAM=0 ;;
481    
482 edhill 1.5 -ds | --ds)
483     DUMPSTATE=t ;;
484    
485 edhill 1.2 -*)
486     echo "Error: unrecognized option: "$ac_option
487     usage
488     ;;
489    
490     *)
491     echo "Error: unrecognized argument: "$ac_option
492     usage
493     ;;
494    
495     esac
496    
497 edhill 1.1 done
498    
499 edhill 1.11 if test "x${ROOTDIR}" = x ; then
500     if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
501     ROOTDIR=".."
502     else
503     for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
504     if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
505     ROOTDIR=$d
506     echo -n "Warning: ROOTDIR was not specified but there appears to be"
507     echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
508     break
509     fi
510     done
511     fi
512     fi
513     if test "x${ROOTDIR}" = x ; then
514     echo "Error: Cannot determine ROOTDIR for MITgcm code."
515     echo " Please specify a ROOTDIR using either an options "
516     echo " file or a command-line option."
517     exit 1
518     fi
519     if test ! -d ${ROOTDIR} ; then
520     echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
521     exit 1
522     fi
523    
524 edhill 1.1 echo " getting OPTFILE information: "
525     if test "x${OPTFILE}" = x ; then
526 edhill 1.11 if test "x$MITGCM_OF" = x ; then
527     echo "Warning: no OPTFILE specified so we'll look for possible settings"
528     printf "\n=== Searching for possible settings for OPTFILE ===\n"
529     find_possible_configs
530 edhill 1.1 else
531 edhill 1.11 OPTFILE=$MITGCM_OF
532     fi
533     fi
534     if test "x$OPTFILE" != xNONE ; then
535     if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
536     echo " using OPTFILE=\"$OPTFILE\""
537     source "$OPTFILE"
538     RETVAL=$?
539     if test "x$RETVAL" != x0 ; then
540     echo -n "Error: failed to source OPTFILE \"$OPTFILE\""
541     echo "--please check that variable syntax is bash-compatible"
542 edhill 1.1 exit 1
543     fi
544 edhill 1.11 if test "x$DUMPSTATE" != xf ; then
545 edhill 1.11.2.10 cp -f $OPTFILE "genmake_optfile"
546 edhill 1.11 fi
547     else
548     echo "Error: can't read OPTFILE=\"$OPTFILE\""
549     exit 1
550 edhill 1.1 fi
551     fi
552 edhill 1.8
553     # Check that FC, LINK, CPP, and S64 are defined. If not, complain
554     # and abort!
555     if test "x$FC" = x ; then
556     cat <<EOF 1>&2
557    
558     Error: no Fortran compiler: please specify using one of the following:
559     1) within the options file ("FC=...") as specified by "-of=OPTFILE"
560     2) the "-fc=XXX" command-line option
561 edhill 1.11.2.10 3) the "./genmake_local" file
562 edhill 1.8 EOF
563     exit 1
564     fi
565     if test "x$LINK" = x ; then
566     LINK=$FC
567     fi
568     if test "x$CPP" = x ; then
569 edhill 1.11 CPP="cpp"
570     fi
571     echo "#define A a" | cpp > test_cpp 2>&1
572     RETVAL=$?
573     if test "x$RETVAL" != x0 ; then
574 edhill 1.8 cat <<EOF 1>&2
575    
576 edhill 1.11 Error: C pre-processor "$CPP" failed the test case: please specify using:
577    
578 edhill 1.8 1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
579 edhill 1.11.2.10 2) the "./genmake_local" file
580 edhill 1.11
581 edhill 1.8 EOF
582     exit 1
583 edhill 1.11 else
584     rm -f test_cpp
585 edhill 1.8 fi
586 edhill 1.11 if test "x$MAKEDEPEND" = x ; then
587     MAKEDEPEND=makedepend
588 edhill 1.8 fi
589    
590 edhill 1.2 printf "\n=== Setting defaults ===\n"
591 edhill 1.1 echo -n " Adding MODS directories: "
592     for d in $MODS ; do
593     if test ! -d $d ; then
594 edhill 1.2 echo
595     echo "Error: MODS directory \"$d\" not found!"
596 edhill 1.1 exit 1
597     else
598     echo -n " $d"
599     SOURCEDIRS="$SOURCEDIRS $d"
600     INCLUDEDIRS="$INCLUDEDIRS $d"
601     fi
602     done
603     echo
604    
605     if test "x$MAKEFILE" = x ; then
606     MAKEFILE="Makefile"
607     fi
608     if test "x${PLATFORM}" = x ; then
609     PLATFORM=$p_PLATFORM
610     fi
611    
612     if test "x${EXEDIR}" = x ; then
613     if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then
614     EXEDIR=../exe
615     else
616     EXEDIR=.
617     fi
618     fi
619     if test ! -d ${EXEDIR} ; then
620     echo "Error: the specified EXEDIR (\"$EXEDIR\") does not exist!"
621     exit 1
622     fi
623    
624     if test "x${TOOLSDIR}" = x ; then
625     TOOLSDIR="$ROOTDIR/tools"
626     fi
627     if test ! -d ${TOOLSDIR} ; then
628     echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"
629     exit 1
630     fi
631 edhill 1.11 if test "x$S64" = x ; then
632     S64='$(TOOLSDIR)/set64bitConst.sh'
633     fi
634 edhill 1.1
635     EXECUTABLE=${EXECUTABLE:-mitgcmuv}
636    
637     # We have a special set of source files in eesupp/src which are
638     # generated from some template source files. We'll make them first so
639     # they appear as regular source code
640     if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
641     echo " Making source files in eesupp from templates"
642     $MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1
643     RETVAL=$?
644 edhill 1.2 if test "x${RETVAL}" = x0 ; then
645 edhill 1.1 rm -f make_eesupp.errors
646     else
647     echo "Error: problem encountered while building source files in eesupp:"
648     cat make_eesupp.errors
649     exit 1
650     fi
651     fi
652    
653 edhill 1.2 printf "\n=== Determining package settings ===\n"
654 edhill 1.1 if test "x${PDEPEND}" = x ; then
655     tmp=$ROOTDIR"/pkg/pkg_depend"
656     if test -r $tmp ; then
657     PDEPEND=$tmp
658     else
659     echo "Warning: No package dependency information was specified."
660     echo " Please check that ROOTDIR/pkg/pkg_depend exists."
661     fi
662     else
663     if test ! -r ${PDEPEND} ; then
664     echo "Error: can't read package dependency info from PDEPEND=\"$PDEPEND\""
665     exit 1
666     fi
667     fi
668     echo " getting package dependency info from $PDEPEND"
669     # Strip the comments and then convert the dependency file into
670     # two arrays: PNAME, DNAME
671     cat $PDEPEND | sed -e 's/#.*$//g' \
672 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}' \
673 edhill 1.1 > ./.pd_tmp
674     RETVAL=$?
675     if test ! "x${RETVAL}" = x0 ; then
676     echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
677     exit 1
678     fi
679     source ./.pd_tmp
680     rm -f ./.pd_tmp
681    
682 edhill 1.11.2.3 # Search for default packages. Note that a "$ROOTDIR/pkg/pkg_groups"
683     # file should eventually be added so that, for convenience, one can
684     # specify groups of packages using names like "ocean" and "atmosphere".
685 edhill 1.1 echo -n " checking default package list: "
686 edhill 1.11.2.3 if test "x${PDEFAULT}" = x ; then
687     for i in "." $MODS ; do
688     if test -r $i"/packages.conf" ; then
689     PDEFAULT=$i"/packages.conf"
690     break
691     fi
692     done
693     fi
694 edhill 1.1 if test "x${PDEFAULT}" = x ; then
695     PDEFAULT="$ROOTDIR/pkg/pkg_default"
696     fi
697     if test "x${PDEFAULT}" = xNONE ; then
698     echo "default packages file disabled"
699     else
700     if test ! -r $PDEFAULT ; then
701     echo ""
702     echo "Warning: can't read default packages from PDEFAULT=\"$PDEFAULT\""
703     else
704     echo " using PDEFAULT=\"$PDEFAULT\""
705     # Strip the comments and add all the names
706     def=`cat $PDEFAULT | sed -e 's/#.*$//g' | awk '(NF>0){print $0}'`
707     RETVAL=$?
708     if test "x${RETVAL}" != x0 ; then
709     echo -n "Error: can't parse default package list "
710     echo "-- please check PDEFAULT=\"$PDEFAULT\""
711     exit 1
712     fi
713     for i in $def ; do
714     PACKAGES="$PACKAGES $i"
715     done
716 edhill 1.11.2.4 echo " before group expansion packages are: $PACKAGES"
717     expand_pkg_groups
718     echo " after group expansion packages are: $PACKAGES"
719 edhill 1.1 fi
720     fi
721    
722     echo " applying DISABLE settings"
723     pack=
724     for p in $PACKAGES ; do
725     addit="t"
726     for d in $DISABLE ; do
727     if test "x$p" = "x$d" ; then
728     addit="f"
729     fi
730     done
731     if test "x$addit" = xt ; then
732     pack="$pack $p"
733     fi
734     done
735     PACKAGES="$pack"
736     echo " applying ENABLE settings"
737 adcroft 1.11.2.1 echo "" > ./.tmp_pack
738 edhill 1.1 PACKAGES="$PACKAGES $ENABLE"
739     for i in $PACKAGES ; do
740     if test ! -d "$ROOTDIR/pkg/$i" ; then
741     echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
742     exit 1
743     fi
744     echo $i >> ./.tmp_pack
745     done
746     pack=`cat ./.tmp_pack | sort | uniq`
747     rm -f ./.tmp_pack
748     PACKAGES=
749     for i in $pack ; do
750     PACKAGES="$PACKAGES $i"
751     done
752     echo " packages are: $PACKAGES"
753    
754     echo " applying package dependency rules"
755     ck=
756     while test "x$ck" != xtt ; do
757     i=0
758 edhill 1.2 # rtot=${#PNAME[@]}
759     rtot=$nname
760 edhill 1.1 while test $i -lt $rtot ; do
761    
762     # Is $pname in the current $PACKAGES list?
763 edhill 1.2 # pname=${PNAME[$i]}
764     tmp="pname=\"\$PNAME_$i\""
765     eval $tmp
766 edhill 1.1 pin="f"
767     for p in $PACKAGES ; do
768     if test "x$p" = "x$pname" ; then
769     pin="t"
770     fi
771     done
772    
773     # Is the DNAME entry a (+) or (-) rule ?
774 edhill 1.2 tmp="dname=\"\$DNAME_$i\""
775     eval $tmp
776 edhill 1.1 plus="-"
777 edhill 1.2 echo $dname | grep '^+' > /dev/null 2>&1
778 edhill 1.1 RETVAL=$?
779     if test "x$RETVAL" = x0 ; then
780     plus="+"
781     fi
782    
783     # Is $dname in the current $PACKAGES list?
784 edhill 1.2 dname=`echo $dname | sed -e 's/^[+-]//'`
785 edhill 1.1 din="f"
786     for p in $PACKAGES ; do
787     if test "x$p" = "x$dname" ; then
788     din="t"
789     fi
790     done
791    
792     # Do we need to add $dname according to the dependency rules?
793     if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
794     in_dis="f"
795     for dis in $DISABLE ; do
796     if test "x$dis" = "x$dname" ; then
797     in_dis="t"
798     fi
799     done
800     if test "x$in_dis" = xt ; then
801     echo "Error: can't satisfy package dependencies:"
802     echo " \"$dname\" is required by the dependency rules"
803     echo " but is disallowed by the DISABLE settings"
804     exit 1
805     else
806     PACKAGES="$PACKAGES $dname"
807     ck=
808     fi
809     fi
810    
811     # Do we need to get rid of $dname according to the dependency rules?
812     if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
813     echo "Error: can't satisfy package dependencies:"
814     echo " \"$pname\" was requested but is disallowed by"
815     echo " the dependency rules for \"$dname\""
816     exit 1
817     fi
818     i=$(( $i + 1 ))
819     done
820     ck=$ck"t"
821     done
822     echo " packages are: $PACKAGES"
823     for i in $PACKAGES ; do
824     adr="$ROOTDIR/pkg/$i"
825     if test -d $adr ; then
826     SOURCEDIRS="$SOURCEDIRS $adr"
827     INCLUDEDIRS="$INCLUDEDIRS $adr"
828     else
829     echo "Error: the directory \"$adr\" for package $i doesn't exist"
830     exit 1
831     fi
832     done
833    
834     # This is compatible with the old genmake. The "DISABLE_*" flags
835     # need to be replaced by the "ALLOW_*" flags set below.
836     #
837     # echo -n " Setting package-specific CPP flags: "
838     # pkrm=( mom_fluxform mom_vecinv generic_advdiff )
839     # pkrmdef=( -DDISABLE_MOM_FLUXFORM -DDISABLE_MOM_VECINV -DDISABLE_GENERIC_ADVDIFF -DDISABLE_DEBUGMODE )
840     # echo -n " "
841     # i=0
842     # while test $i -lt "${#pkrm[@]}" ; do
843     # echo "$PACKAGES" | grep "${pk[$i]}" > /dev/null 2>&1
844     # RETVAL=$?
845     # if test "x$RETVAL" = x1 ; then
846     # DEFINES="$DEFINES ${pkdef[$i]}"
847     # echo -n " ${pkdef[$i]}"
848     # fi
849     # i=$(( $i + 1 ))
850     # done
851     # echo
852    
853 adcroft 1.11.2.1 # Create a list of #define and #undef to enable/disable packages
854 edhill 1.11.2.8 PACKAGES_DOT_H=PACKAGES_CONFIG.h
855 edhill 1.11.2.4 cat <<EOF >$PACKAGES_DOT_H".tmp"
856 edhill 1.1 C=== GENMAKE v2 ===
857 edhill 1.11 C The following defines have been set by GENMAKE, so please do not
858     C edit anything below these comments. In general, you should
859 edhill 1.1 C add or remove packages by re-running genmake with different
860     C "-enable" and/or "-disable" options.
861    
862 edhill 1.11.2.6 #ifndef PACKAGES_H
863     #define PACKAGES_H
864    
865 edhill 1.1 C Packages disabled by genmake:
866     EOF
867     # The following UGLY HACK sets multiple "#undef"s and it needs to go
868     # away. On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
869     # file would eventually be split up so that all package-related #define
870     # statements could be separated and handled only by genmake.
871     names=`ls -1 "$ROOTDIR/pkg"`
872     all_pack=
873     for n in $names ; do
874     if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
875     has_pack="f"
876     for pack in $PACKAGES ; do
877     if test "x$pack" = "x$n" ; then
878     has_pack="t"
879     break
880     fi
881     done
882     if test "x$has_pack" = xf ; then
883     undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`
884 edhill 1.11.2.2 echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"
885 adcroft 1.11.2.1 # DEFINES="$DEFINES -U$undef"
886 edhill 1.1
887     #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
888     case $n in
889     mom_fluxform)
890     DEFINES="$DEFINES -DDISABLE_MOM_FLUXFORM"
891     ;;
892     mom_vecinv)
893     DEFINES="$DEFINES -DDISABLE_MOM_VECINV"
894     ;;
895     debug)
896     DEFINES="$DEFINES -DDISABLE_DEBUGMODE"
897     ;;
898     esac
899     #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
900    
901     fi
902     fi
903     done
904 edhill 1.11.2.2 cat <<EOF >>$PACKAGES_DOT_H".tmp"
905 edhill 1.1
906     C Packages enabled by genmake:
907     EOF
908     for i in $PACKAGES ; do
909     def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`
910 edhill 1.11.2.2 echo "#define $def" >> $PACKAGES_DOT_H".tmp"
911     #eh3 DEFINES="$DEFINES -D$def"
912 edhill 1.1
913     #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
914     case $i in
915     aim_v23)
916 edhill 1.11.2.2 echo "#define ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"
917     DEFINES="$DEFINES -DALLOW_AIM"
918 adcroft 1.11.2.1 echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)"
919 edhill 1.1 ;;
920     esac
921     #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
922    
923     done
924 edhill 1.11.2.6 cat <<EOF >>$PACKAGES_DOT_H".tmp"
925    
926     #endif /* PACKAGES_H */
927     EOF
928    
929 edhill 1.11.2.4 if test ! -f $PACKAGES_DOT_H ; then
930 edhill 1.11.2.2 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
931 edhill 1.11.2.4 else
932     cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
933     RETVAL=$?
934     if test "x$RETVAL" = x0 ; then
935     rm -f $PACKAGES_DOT_H".tmp"
936     else
937     mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
938     mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
939     fi
940 edhill 1.11.2.2 fi
941 edhill 1.1
942     echo " Adding STANDARDDIRS"
943     BUILDDIR=${BUILDDIR:-.}
944 edhill 1.11.2.10 if test "x$STANDARDDIRS" = x ; then
945     STANDARDDIRS="eesupp model"
946     fi
947 edhill 1.1 for d in $STANDARDDIRS ; do
948     adr="$ROOTDIR/$d/src"
949     if test ! -d $adr ; then
950     echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
951     echo " is correct and that you correctly specified the STANDARDDIRS option"
952     exit 1
953     else
954     SOURCEDIRS="$SOURCEDIRS $adr"
955     fi
956     adr="$ROOTDIR/$d/inc"
957     if test ! -d $adr ; then
958     echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
959     echo " is correct and that you correctly specified the STANDARDDIRS option"
960     exit 1
961     else
962     INCLUDEDIRS="$INCLUDEDIRS $adr"
963     fi
964     done
965    
966 edhill 1.11.2.2 echo " Searching for CPP_OPTIONS.h in order to warn about the presence"
967     echo " of \"#define ALLOW_PKGNAME\"-type statements:"
968 adcroft 1.11.2.1 CPP_OPTIONS=
969     spaths=". $INCLUDEDIRS"
970     for i in $spaths ; do
971     try="$i/CPP_OPTIONS.h"
972     # echo -n " trying $try : "
973     if test -f $try -a -r $try ; then
974     echo " found CPP_OPTIONS=\"$try\""
975     CPP_OPTIONS="$try"
976     break
977     fi
978     done
979     if test "x$CPP_OPTIONS" = x ; then
980     echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
981     exit 1
982     fi
983     # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
984     names=`ls -1 "$ROOTDIR/pkg"`
985     for n in $names ; do
986     test_for_package_in_cpp_options $CPP_OPTIONS $n
987     done
988    
989 edhill 1.1
990 edhill 1.2 echo
991     echo "=== Creating the Makefile ==="
992 edhill 1.1 echo " setting INCLUDES"
993     for i in $INCLUDEDIRS ; do
994 adcroft 1.11.2.1 if ! test -d $i ; then
995     # INCLUDES="$INCLUDES -I$i"
996     # else
997 edhill 1.1 echo "Warning: can't find INCLUDEDIRS=\"$i\""
998     fi
999     done
1000    
1001     echo " Determining the list of source and include files"
1002     rm -rf .links.tmp
1003     mkdir .links.tmp
1004     echo "# This section creates symbolic links" > srclinks.tmp
1005     echo "" >> srclinks.tmp
1006 cnh 1.3 echo -n 'SRCFILES = ' > srclist.inc
1007     echo -n 'CSRCFILES = ' > csrclist.inc
1008     echo -n 'F90SRCFILES = ' > f90srclist.inc
1009 edhill 1.1 echo -n 'HEADERFILES = ' > hlist.inc
1010 adcroft 1.9 alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1011 edhill 1.1 for d in $alldirs ; do
1012     deplist=
1013     sfiles=`( cd $d; echo *.[h,c,F] )`
1014 cnh 1.3 sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
1015 edhill 1.1 for sf in $sfiles ; do
1016     if test ! -r ".links.tmp/$sf" ; then
1017     if test -f "$d/$sf" ; then
1018     extn=`echo $sf | awk -F '.' '{print $NF}'`
1019     touch .links.tmp/$sf
1020     deplist="$deplist $sf"
1021     case $extn in
1022     F)
1023     echo " \\" >> srclist.inc
1024     echo -n " $sf" >> srclist.inc
1025     ;;
1026 cnh 1.3 F90)
1027     echo " \\" >> f90srclist.inc
1028     echo -n " $sf" >> f90srclist.inc
1029     ;;
1030 edhill 1.1 c)
1031     echo " \\" >> csrclist.inc
1032     echo -n " $sf" >> csrclist.inc
1033     ;;
1034     h)
1035     echo " \\" >> hlist.inc
1036     echo -n " $sf" >> hlist.inc
1037     ;;
1038     esac
1039     fi
1040     fi
1041     done
1042     if test "x$deplist" != x ; then
1043 edhill 1.2 echo "" >> srclinks.tmp
1044     echo "# These files are linked from $d" >> srclinks.tmp
1045 edhill 1.1 echo "$deplist :" >> srclinks.tmp
1046 edhill 1.2 printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp
1047 edhill 1.1 fi
1048     done
1049     rm -rf .links.tmp
1050     echo "" >> srclist.inc
1051     echo "" >> csrclist.inc
1052 cnh 1.3 echo "" >> f90srclist.inc
1053 edhill 1.1 echo "" >> hlist.inc
1054 adcroft 1.11.2.1
1055 edhill 1.1 if test -e $MAKEFILE ; then
1056     mv -f $MAKEFILE "$MAKEFILE.bak"
1057     fi
1058     echo " Writing makefile: $MAKEFILE"
1059     echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
1060     echo "# $MACHINE" >> $MAKEFILE
1061     echo "# This makefile was generated automatically on" >> $MAKEFILE
1062     echo "# $THISDATE" >> $MAKEFILE
1063     echo "# by the command:" >> $MAKEFILE
1064     echo "# $0 $@" >> $MAKEFILE
1065     echo "# executed by:" >> $MAKEFILE
1066     echo "# $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE
1067     cat >>$MAKEFILE <<EOF
1068     #
1069     # BUILDDIR : Directory where object files are written
1070     # SOURCEDIRS : Directories containing the source (.F) files
1071     # INCLUDEDIRS : Directories containing the header-source (.h) files
1072     # EXEDIR : Directory where executable that is generated is written
1073     # EXECUTABLE : Full path of executable binary
1074     #
1075     # CPP : C-preprocessor command
1076     # INCLUDES : Directories searched for header files
1077     # DEFINES : Macro definitions for CPP
1078     # MAKEDEPEND : Dependency generator
1079     # KPP : Special preprocessor command (specific to platform)
1080     # KFLAGS : Flags for KPP
1081     # FC : Fortran compiler command
1082     # FFLAGS : Configuration/debugging options for FC
1083     # FOPTIM : Optimization options for FC
1084     # LINK : Command for link editor program
1085     # LIBS : Library flags /or/ additional optimization/debugging flags
1086    
1087     ROOTDIR = ${ROOTDIR}
1088     BUILDDIR = ${BUILDDIR}
1089     SOURCEDIRS = ${SOURCEDIRS}
1090     INCLUDEDIRS = ${INCLUDEDIRS}
1091     EXEDIR = ${EXEDIR}
1092     EXECUTABLE = \$(EXEDIR)/${EXECUTABLE}
1093     TOOLSDIR = ${TOOLSDIR}
1094    
1095     EOF
1096    
1097     # Note: figure out some way to add Hyades JAM libraries here
1098    
1099     cat >>$MAKEFILE <<EOF
1100     # Unix ln (link)
1101     LN = ${LN}
1102     # C preprocessor
1103     CPP = cat \$< | ${S64} | ${CPP}
1104     # Dependency generator
1105     MAKEDEPEND = ${MAKEDEPEND}
1106     # Special preprocessor (KAP on DECs, FPP on Crays)
1107     KPP = ${KPP}
1108     # Fortran compiler
1109     FC = ${FC}
1110 cnh 1.3 # Fortran compiler
1111     F90C = ${F90C}
1112 edhill 1.1 # Link editor
1113     LINK = ${LINK}
1114    
1115     # Defines for CPP
1116     DEFINES = ${DEFINES}
1117     # Includes for CPP
1118     INCLUDES = ${INCLUDES}
1119     # Flags for KPP
1120     KFLAGS1 = ${KFLAGS1}
1121     KFLAGS2 = ${KFLAGS2}
1122     # Optim./debug for FC
1123     FFLAGS = ${FFLAGS}
1124     FOPTIM = ${FOPTIM}
1125 cnh 1.3 # Optim./debug for FC
1126     F90FLAGS = ${F90FLAGS}
1127     F90OPTIM = ${F90OPTIM}
1128 edhill 1.1 # Flags for CC
1129     CFLAGS = ${CFLAGS}
1130     # Files that should not be optimized
1131     NOOPTFILES = ${NOOPTFILES}
1132     NOOPTFLAGS = ${NOOPTFLAGS}
1133     # Flags and libraries needed for linking
1134     LIBS = ${LIBS} \$(XLIBS)
1135 cnh 1.3 # Name of the Mekfile
1136     MAKEFILE=${MAKEFILE}
1137 edhill 1.1
1138     EOF
1139    
1140 cnh 1.3 cat srclist.inc >> $MAKEFILE
1141     cat csrclist.inc >> $MAKEFILE
1142     cat f90srclist.inc >> $MAKEFILE
1143     cat hlist.inc >> $MAKEFILE
1144     echo 'F77FILES = $(SRCFILES:.F=.f)' >> $MAKEFILE
1145     echo 'F90FILES = $(F90SRCFILES:.F90=.f90)' >> $MAKEFILE
1146     echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
1147 edhill 1.1
1148 cnh 1.3 rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc
1149 edhill 1.1
1150     cat >>$MAKEFILE <<EOF
1151    
1152     .SUFFIXES:
1153 cnh 1.3 .SUFFIXES: .o .f .p .F .c .F90 .f90
1154 edhill 1.1
1155     all: \$(EXECUTABLE)
1156     \$(EXECUTABLE): \$(OBJFILES)
1157     \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
1158     depend:
1159     @make links
1160     \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
1161 edhill 1.7 ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)
1162 edhill 1.1
1163 cnh 1.3 links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)
1164 edhill 1.1
1165 cnh 1.3 small_f: \$(F77FILES) \$(F90FILES)
1166 edhill 1.1
1167     output.txt: \$(EXECUTABLE)
1168     @printf 'running ... '
1169     @\$(EXECUTABLE) > \$@
1170    
1171     clean:
1172 cnh 1.3 -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}
1173 edhill 1.1 Clean:
1174     @make clean
1175     @make cleanlinks
1176 edhill 1.11.2.10 -rm -f Makefile.bak genmake_state genmake_optfile make.log
1177 edhill 1.1 CLEAN:
1178     @make Clean
1179     -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
1180     -find \$(EXEDIR) -name "*.data" -exec rm {} \;
1181     -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
1182 adcroft 1.11.2.1 -rm -f \$(EXECUTABLE) output.txt
1183 edhill 1.1
1184     makefile:
1185     ${0} $@
1186     cleanlinks:
1187     -find . -type l -exec rm {} \;
1188    
1189     # The normal chain of rules is ( .F - .f - .o )
1190     .F.f:
1191     \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1192     .f.o:
1193     \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
1194 cnh 1.3 .F90.f90:
1195     \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1196     .f90.o:
1197     \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
1198 edhill 1.1 .c.o:
1199     \$(CC) \$(CFLAGS) -c \$<
1200    
1201     # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain
1202     .F.p:
1203     \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1204     .p.f:
1205     \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
1206    
1207     EOF
1208 edhill 1.7
1209     if test "x$EXEHOOK" != x ; then
1210     printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
1211     fi
1212 edhill 1.1
1213     echo " Making list of \"exceptions\" that need \".p\" files"
1214     for i in $KPPFILES ; do
1215     base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
1216     RETVAL=$?
1217     if test "x$RETVAL" != x0 ; then
1218     echo "Error: unable to add file \"$i\" to the exceptions list"
1219     fi
1220     echo "$base.f: $base.p" >> $MAKEFILE
1221     done
1222    
1223     echo " Making list of NOOPTFILES"
1224     for i in $NOOPTFILES ; do
1225     base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
1226     RETVAL=$?
1227     if test "x$RETVAL" != x0 ; then
1228     echo "Error: unable to add file \"$i\" to the exceptions list"
1229     fi
1230     echo "$base.o: $base.f" >> $MAKEFILE
1231 edhill 1.2 printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
1232 edhill 1.1 done
1233    
1234     echo " Add rules for links"
1235     cat srclinks.tmp >> $MAKEFILE
1236     rm -f srclinks.tmp
1237    
1238     echo " Adding makedepend marker"
1239 edhill 1.2 printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
1240 edhill 1.1
1241 edhill 1.2 printf "\n=== Done ===\n"
1242 edhill 1.5
1243    
1244     # Write the "state" for future records
1245     if test "x$DUMPSTATE" != xf ; then
1246 edhill 1.11.2.10 echo -n "" > genmake_state
1247 edhill 1.5 for i in $gm_state ; do
1248     t1="t2=\$$i"
1249     eval $t1
1250 edhill 1.11.2.10 echo "$i='$t2'" >> genmake_state
1251 edhill 1.5 done
1252     fi

  ViewVC Help
Powered by ViewVC 1.1.22