/[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.3 - (show annotations) (download)
Wed Oct 1 20:47:26 2003 UTC (20 years, 6 months ago) by edhill
Branch: branch-genmake2
Changes since 1.11.2.2: +12 -1 lines
 o search for "packages.conf" in "." and $MODS

1 #!/bin/bash
2 #
3 # $Header: /u/u3/gcmpack/MITgcm/tools/genmake2,v 1.11.2.2 2003/10/01 19:33:01 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 # Search for default packages. Note that a "$ROOTDIR/pkg/pkg_groups"
638 # file should eventually be added so that, for convenience, one can
639 # specify groups of packages using names like "ocean" and "atmosphere".
640 echo -n " checking default package list: "
641 if test "x${PDEFAULT}" = x ; then
642 for i in "." $MODS ; do
643 if test -r $i"/packages.conf" ; then
644 PDEFAULT=$i"/packages.conf"
645 break
646 fi
647 done
648 fi
649 if test "x${PDEFAULT}" = x ; then
650 PDEFAULT="$ROOTDIR/pkg/pkg_default"
651 fi
652 if test "x${PDEFAULT}" = xNONE ; then
653 echo "default packages file disabled"
654 else
655 if test ! -r $PDEFAULT ; then
656 echo ""
657 echo "Warning: can't read default packages from PDEFAULT=\"$PDEFAULT\""
658 else
659 echo " using PDEFAULT=\"$PDEFAULT\""
660 # Strip the comments and add all the names
661 def=`cat $PDEFAULT | sed -e 's/#.*$//g' | awk '(NF>0){print $0}'`
662 RETVAL=$?
663 if test "x${RETVAL}" != x0 ; then
664 echo -n "Error: can't parse default package list "
665 echo "-- please check PDEFAULT=\"$PDEFAULT\""
666 exit 1
667 fi
668 for i in $def ; do
669 PACKAGES="$PACKAGES $i"
670 done
671 echo " packages are: $PACKAGES"
672 fi
673 fi
674
675 echo " applying DISABLE settings"
676 pack=
677 for p in $PACKAGES ; do
678 addit="t"
679 for d in $DISABLE ; do
680 if test "x$p" = "x$d" ; then
681 addit="f"
682 fi
683 done
684 if test "x$addit" = xt ; then
685 pack="$pack $p"
686 fi
687 done
688 PACKAGES="$pack"
689 echo " applying ENABLE settings"
690 echo "" > ./.tmp_pack
691 PACKAGES="$PACKAGES $ENABLE"
692 for i in $PACKAGES ; do
693 if test ! -d "$ROOTDIR/pkg/$i" ; then
694 echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
695 exit 1
696 fi
697 echo $i >> ./.tmp_pack
698 done
699 pack=`cat ./.tmp_pack | sort | uniq`
700 rm -f ./.tmp_pack
701 PACKAGES=
702 for i in $pack ; do
703 PACKAGES="$PACKAGES $i"
704 done
705 echo " packages are: $PACKAGES"
706
707 echo " applying package dependency rules"
708 ck=
709 while test "x$ck" != xtt ; do
710 i=0
711 # rtot=${#PNAME[@]}
712 rtot=$nname
713 while test $i -lt $rtot ; do
714
715 # Is $pname in the current $PACKAGES list?
716 # pname=${PNAME[$i]}
717 tmp="pname=\"\$PNAME_$i\""
718 eval $tmp
719 pin="f"
720 for p in $PACKAGES ; do
721 if test "x$p" = "x$pname" ; then
722 pin="t"
723 fi
724 done
725
726 # Is the DNAME entry a (+) or (-) rule ?
727 tmp="dname=\"\$DNAME_$i\""
728 eval $tmp
729 plus="-"
730 echo $dname | grep '^+' > /dev/null 2>&1
731 RETVAL=$?
732 if test "x$RETVAL" = x0 ; then
733 plus="+"
734 fi
735
736 # Is $dname in the current $PACKAGES list?
737 dname=`echo $dname | sed -e 's/^[+-]//'`
738 din="f"
739 for p in $PACKAGES ; do
740 if test "x$p" = "x$dname" ; then
741 din="t"
742 fi
743 done
744
745 # Do we need to add $dname according to the dependency rules?
746 if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
747 in_dis="f"
748 for dis in $DISABLE ; do
749 if test "x$dis" = "x$dname" ; then
750 in_dis="t"
751 fi
752 done
753 if test "x$in_dis" = xt ; then
754 echo "Error: can't satisfy package dependencies:"
755 echo " \"$dname\" is required by the dependency rules"
756 echo " but is disallowed by the DISABLE settings"
757 exit 1
758 else
759 PACKAGES="$PACKAGES $dname"
760 ck=
761 fi
762 fi
763
764 # Do we need to get rid of $dname according to the dependency rules?
765 if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
766 echo "Error: can't satisfy package dependencies:"
767 echo " \"$pname\" was requested but is disallowed by"
768 echo " the dependency rules for \"$dname\""
769 exit 1
770 fi
771 i=$(( $i + 1 ))
772 done
773 ck=$ck"t"
774 done
775 echo " packages are: $PACKAGES"
776 for i in $PACKAGES ; do
777 adr="$ROOTDIR/pkg/$i"
778 if test -d $adr ; then
779 SOURCEDIRS="$SOURCEDIRS $adr"
780 INCLUDEDIRS="$INCLUDEDIRS $adr"
781 else
782 echo "Error: the directory \"$adr\" for package $i doesn't exist"
783 exit 1
784 fi
785 done
786
787 # This is compatible with the old genmake. The "DISABLE_*" flags
788 # need to be replaced by the "ALLOW_*" flags set below.
789 #
790 # echo -n " Setting package-specific CPP flags: "
791 # pkrm=( mom_fluxform mom_vecinv generic_advdiff )
792 # pkrmdef=( -DDISABLE_MOM_FLUXFORM -DDISABLE_MOM_VECINV -DDISABLE_GENERIC_ADVDIFF -DDISABLE_DEBUGMODE )
793 # echo -n " "
794 # i=0
795 # while test $i -lt "${#pkrm[@]}" ; do
796 # echo "$PACKAGES" | grep "${pk[$i]}" > /dev/null 2>&1
797 # RETVAL=$?
798 # if test "x$RETVAL" = x1 ; then
799 # DEFINES="$DEFINES ${pkdef[$i]}"
800 # echo -n " ${pkdef[$i]}"
801 # fi
802 # i=$(( $i + 1 ))
803 # done
804 # echo
805
806 # Create a list of #define and #undef to enable/disable packages
807 PACKAGES_DOT_H=PACKAGES.h
808 if test -e $PACKAGES_DOT_H ; then
809 cat $PACKAGES_DOT_H \
810 | awk 'BEGIN{p=1;} ($1=="C===" && $2=="GENMAKE"){p=0;} {if (p==1) print $0}' \
811 > $PACKAGES_DOT_H".tmp"
812 fi
813 cat <<EOF >>$PACKAGES_DOT_H".tmp"
814 C=== GENMAKE v2 ===
815 C The following defines have been set by GENMAKE, so please do not
816 C edit anything below these comments. In general, you should
817 C add or remove packages by re-running genmake with different
818 C "-enable" and/or "-disable" options.
819
820 C Packages disabled by genmake:
821 EOF
822 # The following UGLY HACK sets multiple "#undef"s and it needs to go
823 # away. On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
824 # file would eventually be split up so that all package-related #define
825 # statements could be separated and handled only by genmake.
826 names=`ls -1 "$ROOTDIR/pkg"`
827 all_pack=
828 for n in $names ; do
829 if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
830 has_pack="f"
831 for pack in $PACKAGES ; do
832 if test "x$pack" = "x$n" ; then
833 has_pack="t"
834 break
835 fi
836 done
837 if test "x$has_pack" = xf ; then
838 undef=`echo "ALLOW_$n" | awk '{print toupper($0)}'`
839 echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"
840 # DEFINES="$DEFINES -U$undef"
841
842 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
843 case $n in
844 mom_fluxform)
845 DEFINES="$DEFINES -DDISABLE_MOM_FLUXFORM"
846 ;;
847 mom_vecinv)
848 DEFINES="$DEFINES -DDISABLE_MOM_VECINV"
849 ;;
850 debug)
851 DEFINES="$DEFINES -DDISABLE_DEBUGMODE"
852 ;;
853 esac
854 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
855
856 fi
857 fi
858 done
859 cat <<EOF >>$PACKAGES_DOT_H".tmp"
860
861 C Packages enabled by genmake:
862 EOF
863 for i in $PACKAGES ; do
864 def=`echo "ALLOW_$i" | awk '{print toupper($0)}'`
865 echo "#define $def" >> $PACKAGES_DOT_H".tmp"
866 #eh3 DEFINES="$DEFINES -D$def"
867
868 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
869 case $i in
870 aim_v23)
871 echo "#define ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"
872 DEFINES="$DEFINES -DALLOW_AIM"
873 echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)"
874 ;;
875 esac
876 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
877
878 done
879 cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
880 RETVAL=$?
881 if test "x$RETVAL" = x0 ; then
882 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H".bak"
883 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
884 fi
885
886 echo " Adding STANDARDDIRS"
887 BUILDDIR=${BUILDDIR:-.}
888 STANDARDDIRS=${STANDARDDIRS:-"eesupp model"}
889 for d in $STANDARDDIRS ; do
890 adr="$ROOTDIR/$d/src"
891 if test ! -d $adr ; then
892 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
893 echo " is correct and that you correctly specified the STANDARDDIRS option"
894 exit 1
895 else
896 SOURCEDIRS="$SOURCEDIRS $adr"
897 fi
898 adr="$ROOTDIR/$d/inc"
899 if test ! -d $adr ; then
900 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
901 echo " is correct and that you correctly specified the STANDARDDIRS option"
902 exit 1
903 else
904 INCLUDEDIRS="$INCLUDEDIRS $adr"
905 fi
906 done
907
908 echo " Searching for CPP_OPTIONS.h in order to warn about the presence"
909 echo " of \"#define ALLOW_PKGNAME\"-type statements:"
910 CPP_OPTIONS=
911 spaths=". $INCLUDEDIRS"
912 for i in $spaths ; do
913 try="$i/CPP_OPTIONS.h"
914 # echo -n " trying $try : "
915 if test -f $try -a -r $try ; then
916 echo " found CPP_OPTIONS=\"$try\""
917 CPP_OPTIONS="$try"
918 break
919 fi
920 done
921 if test "x$CPP_OPTIONS" = x ; then
922 echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
923 exit 1
924 fi
925 # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
926 names=`ls -1 "$ROOTDIR/pkg"`
927 for n in $names ; do
928 test_for_package_in_cpp_options $CPP_OPTIONS $n
929 done
930
931
932 echo
933 echo "=== Creating the Makefile ==="
934 echo " setting INCLUDES"
935 for i in $INCLUDEDIRS ; do
936 if ! test -d $i ; then
937 # INCLUDES="$INCLUDES -I$i"
938 # else
939 echo "Warning: can't find INCLUDEDIRS=\"$i\""
940 fi
941 done
942
943 echo " Determining the list of source and include files"
944 rm -rf .links.tmp
945 mkdir .links.tmp
946 echo "# This section creates symbolic links" > srclinks.tmp
947 echo "" >> srclinks.tmp
948 echo -n 'SRCFILES = ' > srclist.inc
949 echo -n 'CSRCFILES = ' > csrclist.inc
950 echo -n 'F90SRCFILES = ' > f90srclist.inc
951 echo -n 'HEADERFILES = ' > hlist.inc
952 alldirs="$SOURCEDIRS $INCLUDEDIRS ."
953 for d in $alldirs ; do
954 deplist=
955 sfiles=`( cd $d; echo *.[h,c,F] )`
956 sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
957 for sf in $sfiles ; do
958 if test ! -r ".links.tmp/$sf" ; then
959 if test -f "$d/$sf" ; then
960 extn=`echo $sf | awk -F '.' '{print $NF}'`
961 touch .links.tmp/$sf
962 deplist="$deplist $sf"
963 case $extn in
964 F)
965 echo " \\" >> srclist.inc
966 echo -n " $sf" >> srclist.inc
967 ;;
968 F90)
969 echo " \\" >> f90srclist.inc
970 echo -n " $sf" >> f90srclist.inc
971 ;;
972 c)
973 echo " \\" >> csrclist.inc
974 echo -n " $sf" >> csrclist.inc
975 ;;
976 h)
977 echo " \\" >> hlist.inc
978 echo -n " $sf" >> hlist.inc
979 ;;
980 esac
981 fi
982 fi
983 done
984 if test "x$deplist" != x ; then
985 echo "" >> srclinks.tmp
986 echo "# These files are linked from $d" >> srclinks.tmp
987 echo "$deplist :" >> srclinks.tmp
988 printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp
989 fi
990 done
991 rm -rf .links.tmp
992 echo "" >> srclist.inc
993 echo "" >> csrclist.inc
994 echo "" >> f90srclist.inc
995 echo "" >> hlist.inc
996
997 if test -e $MAKEFILE ; then
998 mv -f $MAKEFILE "$MAKEFILE.bak"
999 fi
1000 echo " Writing makefile: $MAKEFILE"
1001 echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
1002 echo "# $MACHINE" >> $MAKEFILE
1003 echo "# This makefile was generated automatically on" >> $MAKEFILE
1004 echo "# $THISDATE" >> $MAKEFILE
1005 echo "# by the command:" >> $MAKEFILE
1006 echo "# $0 $@" >> $MAKEFILE
1007 echo "# executed by:" >> $MAKEFILE
1008 echo "# $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE
1009 cat >>$MAKEFILE <<EOF
1010 #
1011 # BUILDDIR : Directory where object files are written
1012 # SOURCEDIRS : Directories containing the source (.F) files
1013 # INCLUDEDIRS : Directories containing the header-source (.h) files
1014 # EXEDIR : Directory where executable that is generated is written
1015 # EXECUTABLE : Full path of executable binary
1016 #
1017 # CPP : C-preprocessor command
1018 # INCLUDES : Directories searched for header files
1019 # DEFINES : Macro definitions for CPP
1020 # MAKEDEPEND : Dependency generator
1021 # KPP : Special preprocessor command (specific to platform)
1022 # KFLAGS : Flags for KPP
1023 # FC : Fortran compiler command
1024 # FFLAGS : Configuration/debugging options for FC
1025 # FOPTIM : Optimization options for FC
1026 # LINK : Command for link editor program
1027 # LIBS : Library flags /or/ additional optimization/debugging flags
1028
1029 ROOTDIR = ${ROOTDIR}
1030 BUILDDIR = ${BUILDDIR}
1031 SOURCEDIRS = ${SOURCEDIRS}
1032 INCLUDEDIRS = ${INCLUDEDIRS}
1033 EXEDIR = ${EXEDIR}
1034 EXECUTABLE = \$(EXEDIR)/${EXECUTABLE}
1035 TOOLSDIR = ${TOOLSDIR}
1036
1037 EOF
1038
1039 # Note: figure out some way to add Hyades JAM libraries here
1040
1041 cat >>$MAKEFILE <<EOF
1042 # Unix ln (link)
1043 LN = ${LN}
1044 # C preprocessor
1045 CPP = cat \$< | ${S64} | ${CPP}
1046 # Dependency generator
1047 MAKEDEPEND = ${MAKEDEPEND}
1048 # Special preprocessor (KAP on DECs, FPP on Crays)
1049 KPP = ${KPP}
1050 # Fortran compiler
1051 FC = ${FC}
1052 # Fortran compiler
1053 F90C = ${F90C}
1054 # Link editor
1055 LINK = ${LINK}
1056
1057 # Defines for CPP
1058 DEFINES = ${DEFINES}
1059 # Includes for CPP
1060 INCLUDES = ${INCLUDES}
1061 # Flags for KPP
1062 KFLAGS1 = ${KFLAGS1}
1063 KFLAGS2 = ${KFLAGS2}
1064 # Optim./debug for FC
1065 FFLAGS = ${FFLAGS}
1066 FOPTIM = ${FOPTIM}
1067 # Optim./debug for FC
1068 F90FLAGS = ${F90FLAGS}
1069 F90OPTIM = ${F90OPTIM}
1070 # Flags for CC
1071 CFLAGS = ${CFLAGS}
1072 # Files that should not be optimized
1073 NOOPTFILES = ${NOOPTFILES}
1074 NOOPTFLAGS = ${NOOPTFLAGS}
1075 # Flags and libraries needed for linking
1076 LIBS = ${LIBS} \$(XLIBS)
1077 # Name of the Mekfile
1078 MAKEFILE=${MAKEFILE}
1079
1080 EOF
1081
1082 cat srclist.inc >> $MAKEFILE
1083 cat csrclist.inc >> $MAKEFILE
1084 cat f90srclist.inc >> $MAKEFILE
1085 cat hlist.inc >> $MAKEFILE
1086 echo 'F77FILES = $(SRCFILES:.F=.f)' >> $MAKEFILE
1087 echo 'F90FILES = $(F90SRCFILES:.F90=.f90)' >> $MAKEFILE
1088 echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
1089
1090 rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc
1091
1092 cat >>$MAKEFILE <<EOF
1093
1094 .SUFFIXES:
1095 .SUFFIXES: .o .f .p .F .c .F90 .f90
1096
1097 all: \$(EXECUTABLE)
1098 \$(EXECUTABLE): \$(OBJFILES)
1099 \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
1100 depend:
1101 @make links
1102 \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
1103 ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)
1104
1105 links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)
1106
1107 small_f: \$(F77FILES) \$(F90FILES)
1108
1109 output.txt: \$(EXECUTABLE)
1110 @printf 'running ... '
1111 @\$(EXECUTABLE) > \$@
1112
1113 clean:
1114 -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}
1115 Clean:
1116 @make clean
1117 @make cleanlinks
1118 -rm -f Makefile.bak gm_state gm_optfile make.log PACKAGES.h*
1119 CLEAN:
1120 @make Clean
1121 -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
1122 -find \$(EXEDIR) -name "*.data" -exec rm {} \;
1123 -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
1124 -rm -f \$(EXECUTABLE) output.txt
1125
1126 makefile:
1127 ${0} $@
1128 cleanlinks:
1129 -find . -type l -exec rm {} \;
1130
1131 # The normal chain of rules is ( .F - .f - .o )
1132 .F.f:
1133 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1134 .f.o:
1135 \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
1136 .F90.f90:
1137 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1138 .f90.o:
1139 \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
1140 .c.o:
1141 \$(CC) \$(CFLAGS) -c \$<
1142
1143 # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain
1144 .F.p:
1145 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1146 .p.f:
1147 \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
1148
1149 EOF
1150
1151 if test "x$EXEHOOK" != x ; then
1152 printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
1153 fi
1154
1155 echo " Making list of \"exceptions\" that need \".p\" files"
1156 for i in $KPPFILES ; do
1157 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
1158 RETVAL=$?
1159 if test "x$RETVAL" != x0 ; then
1160 echo "Error: unable to add file \"$i\" to the exceptions list"
1161 fi
1162 echo "$base.f: $base.p" >> $MAKEFILE
1163 done
1164
1165 echo " Making list of NOOPTFILES"
1166 for i in $NOOPTFILES ; do
1167 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
1168 RETVAL=$?
1169 if test "x$RETVAL" != x0 ; then
1170 echo "Error: unable to add file \"$i\" to the exceptions list"
1171 fi
1172 echo "$base.o: $base.f" >> $MAKEFILE
1173 printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
1174 done
1175
1176 echo " Add rules for links"
1177 cat srclinks.tmp >> $MAKEFILE
1178 rm -f srclinks.tmp
1179
1180 echo " Adding makedepend marker"
1181 printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
1182
1183 printf "\n=== Done ===\n"
1184
1185
1186 # Write the "state" for future records
1187 if test "x$DUMPSTATE" != xf ; then
1188 echo -n "" > gm_state
1189 for i in $gm_state ; do
1190 t1="t2=\$$i"
1191 eval $t1
1192 echo "$i='$t2'" >> gm_state
1193 done
1194 fi

  ViewVC Help
Powered by ViewVC 1.1.22