/[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.5 - (hide annotations) (download)
Thu Oct 2 14:27:50 2003 UTC (20 years, 5 months ago) by adcroft
Branch: branch-genmake2
Changes since 1.11.2.4: +2 -2 lines
Since Makefile does not know how to create PACKAGES.h we shouldn't delete it.
Otherwise user had to genmake2 after a make CLEAN.

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

  ViewVC Help
Powered by ViewVC 1.1.22