/[MITgcm]/MITgcm/tools/genmake2
ViewVC logotype

Contents of /MITgcm/tools/genmake2

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.11.2.1 - (show annotations) (download)
Wed Oct 1 18:44:48 2003 UTC (20 years, 6 months ago) by adcroft
Branch: branch-genmake2
Changes since 1.11: +82 -40 lines
Tentative changes to implement new building process and package configuration.
 o no longer creates CPP_OPTIONS.h (#def's now in PACKAGES.h)
 o uses -DALLOW_* on cmd-line
Todo:
 o lots

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

  ViewVC Help
Powered by ViewVC 1.1.22