/[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.10 - (hide annotations) (download)
Fri Oct 3 19:49:06 2003 UTC (16 years, 1 month ago) by edhill
Branch: branch-genmake2
Changes since 1.11.2.9: +28 -11 lines
 o cleanup handling of "genmake_*" files
 o add "-standarddirs" option so that its easy to build the "coupler" that
   JMC uses [which needs to turn off all the files in "eesupp model" and
   add the special "aim_ocn_coupler" which includes its own MAIN()
   implementation]

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

  ViewVC Help
Powered by ViewVC 1.1.22