/[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.39 - (show annotations) (download)
Fri Nov 14 19:01:36 2003 UTC (20 years, 4 months ago) by edhill
Branch: MAIN
Changes since 1.38: +81 -32 lines
 o yet another attempt to fix my pervious errors

1 #!/bin/sh
2 #
3 # $Header: /u/u3/gcmpack/MITgcm/tools/genmake2,v 1.38 2003/11/14 12:52:56 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 # 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
70 # Guess possible config options for this host
71 find_possible_configs() {
72
73 tmp1=`uname`"_"`uname -m`
74 tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
75 tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'`
76 PLATFORM=`echo $tmp3 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'`
77 OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")`
78 echo " The platform appears to be: $PLATFORM"
79 # if test "x$OFLIST" = x ; then
80 # echo " No pre-defined options files were found matching this platform"
81 # echo " but examples for other platforms can be found in:"
82 # echo " $ROOTDIR/tools/build_options"
83 # else
84 # echo " Options files (located in $ROOTDIR/tools/build_options) that"
85 # echo " may work with this machine are:"
86 # for i in $OFLIST ; do
87 # echo " $i"
88 # done
89 # fi
90
91 echo "test" > test
92 ln -s ./test link
93 RETVAL=$?
94 if test "x${RETVAL}" = x0 ; then
95 LN="ln -s"
96 else
97 echo "Error: \"ln -s\" does not appear to work on this system!"
98 echo " For help, please contact <MITgcm-support@mitgcm.org>."
99 exit 1
100 fi
101 rm -f test link
102
103 if test "x$CPP" = x ; then
104 CPP="cpp -traditional -P"
105 fi
106
107 # makedepend is not always available
108 if test "x${MAKEDEPEND}" = x ; then
109 which makedepend >& /dev/null
110 RETVAL=$?
111 if test "x${RETVAL}" = x1 ; then
112 echo " makedepend was not found. Using xmakedpend instead."
113 MAKEDEPEND='$(TOOLSDIR)/xmakedepend'
114 fi
115 fi
116
117 # look for possible fortran compilers
118 tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95"
119 p_FC=
120 for c in $tmp ; do
121 rm -f ./hello.f ./hello
122 cat >> hello.f <<EOF
123 program hello
124 do i=1,3
125 print *, 'hello world : ', i
126 enddo
127 end
128 EOF
129 $c -o hello hello.f > /dev/null 2>&1
130 RETVAL=$?
131 if test "x${RETVAL}" = x0 ; then
132 p_FC="$p_FC $c"
133 fi
134 done
135 rm -f ./hello.f ./hello
136 if test "x${p_FC}" = x ; then
137 cat 1>&2 <<EOF
138
139 Error: No Fortran compilers were found in your path. Please specify one using:
140
141 1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"),
142 2) a command-line option (eg. "-fc NAME"), or
143 3) the MITGCM_FC environment variable.
144
145 EOF
146 exit 1
147 else
148 echo " The possible FORTRAN compilers found in your path are:"
149 echo " "$p_FC
150 if test "x$FC" = x ; then
151 FC=`echo $p_FC | $AWK '{print $1}'`
152 fi
153 fi
154
155 for i in $p_FC ; do
156 p_OF=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$i
157 if test -r $p_OF ; then
158 OPTFILE=$p_OF
159 echo " The options file: $p_OF"
160 echo " appears to match so we'll use it."
161 break
162 fi
163 done
164 if test "x$OPTFILE" = x ; then
165 cat 1>&2 <<EOF
166
167 Error: No options file was found in: $ROOTDIR/tools/build_options/
168 that matches this platform ("$PLATFORM") and the compilers found in
169 your path. Please specify an "optfile" using:
170
171 1) the command line (eg. "-optfile=path/to/OPTFILE"), or
172 2) the MITGCM_OF environment variable.
173
174 If you need help, please contact the developers at <MITgcm-support@mitgcm.org>.
175
176 EOF
177 exit 1
178 fi
179
180 # # look for possible MPI libraries
181 # mpi_libs=
182 # mpi_fort=`which mpif77 2>/dev/null`
183 # RETVAL=$?
184 # if test "x${RETVAL}" = x0 ; then
185 # cat >>test.f <<EOF
186 # PROGRAM HELLO
187 # DO 10, I=1,10
188 # PRINT *,'Hello World'
189 # 10 CONTINUE
190 # STOP
191 # END
192 # EOF
193 # eval "$mpi_fort -showme test.f > out"
194 # RETVAL=$?
195 # if test "x${RETVAL}" = x0 ; then
196 # a=`cat out`
197 # for i in $a ; do
198 # case $i in
199 # -*)
200 # mpi_libs="$mpi_libs $i" ;;
201 # esac
202 # done
203 # echo "The MPI libs appear to be:"
204 # echo " "$mpi_libs
205 # fi
206 # rm -f test.f out
207 # fi
208
209 }
210
211 # Parse the package dependency information
212 get_pdepend_list() {
213
214 # strip the comments and then convert the dependency file into
215 # two arrays: PNAME, DNAME
216 cat $1 | sed -e 's/#.*$//g' \
217 | $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \
218 > ./.pd_tmp
219 . ./.pd_tmp
220 rm -f ./.pd_tmp
221
222 echo -n "PNAME = "${}
223 }
224
225
226 # Explain usage
227 usage() {
228 echo
229 echo "Usage: "$0" [OPTIONS]"
230 echo " where [OPTIONS] can be:"
231 echo
232 echo " -help | --help | -h | --h"
233 echo " -nooptfile | --nooptfile"
234 echo " -optfile NAME | --optfile NAME | -of NAME | --of NAME"
235 echo " -optfile=NAME | --optfile=NAME | -of=NAME | --of=NAME"
236 echo " -pdepend NAME | --pdepend NAME"
237 echo " -pdepend=NAME | --pdepend=NAME"
238 echo " -pdefault NAME | --pdefault NAME"
239 echo " -pdefault=NAME | --pdefault=NAME"
240 echo " -make NAME | -m NAME"
241 echo " --make=NAME | -m=NAME"
242 echo " -makefile NAME | -mf NAME"
243 echo " --makefile=NAME | -mf=NAME"
244 echo " -platform NAME | --platform NAME | -pl NAME | --pl NAME"
245 echo " -platform=NAME | --platform=NAME | -pl=NAME | --pl=NAME"
246 echo " -rootdir NAME | --rootdir NAME | -rd NAME | --rd NAME"
247 echo " -rootdir=NAME | --rootdir=NAME | -rd=NAME | --rd=NAME"
248 echo " -mods NAME | --mods NAME | -mo NAME | --mo NAME"
249 echo " -mods=NAME | --mods=NAME | -mo=NAME | --mo=NAME"
250 echo " -disable NAME | --disable NAME"
251 echo " -disable=NAME | --disable=NAME"
252 echo " -enable NAME | --enable NAME"
253 echo " -enable=NAME | --enable=NAME"
254 echo " -standarddirs NAME | --standarddirs NAME"
255 echo " -standarddirs=NAME | --standarddirs=NAME"
256 echo " -noopt NAME | --noopt NAME"
257 echo " -noopt=NAME | --noopt=NAME"
258 # echo " -cpp NAME | --cpp NAME"
259 # echo " -cpp=NAME | --cpp=NAME"
260 echo " -fortran NAME | --fortran NAME | -fc NAME | --fc NAME"
261 echo " -fc=NAME | --fc=NAME"
262 echo " -[no]ieee | --[no]ieee"
263 echo " -[no]mpi | --[no]mpi"
264 echo " -[no]jam | --[no]jam"
265 echo
266 echo " and NAME is a string such as:"
267 echo
268 echo " --enable pkg1 --enable 'pkg1 pkg2' --enable 'pkg1 pkg2 pkg3'"
269 echo " -mods=dir1 -mods='dir1' -mods='dir1 dir2 dir3'"
270 echo " -foptim='-Mvect=cachesize:512000,transform -xtypemap=real:64,double:64,integer:32'"
271 echo
272 echo " which, depending upon your shell, may need to be single-quoted"
273 echo " if it contains spaces, dashes, or other special characters."
274 exit 1
275 }
276
277 # Build a CPP macro to automate calling C routines from FORTRAN
278 get_fortran_c_namemangling() {
279 default_nm="#define FC_NAMEMANGLE(X) X ## _"
280
281 cat > genmake_test.c <<EOF
282 void tcall( char * string ) { tsub( string ); }
283 EOF
284 $MAKE genmake_test.o >> genmake_warnings 2>&1
285 RETVAL=$?
286 if test "x$RETVAL" != x0 ; then
287 FC_NAMEMANGLE=$default_nm
288 cat <<EOF>> genmake_errors
289
290 WARNING: C test compile fails
291 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
292 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
293 EOF
294 return 1
295 fi
296 c_tcall=`nm genmake_test.o | grep tcall | cut -d ' ' -f 3`
297 RETVAL=$?
298 if test "x$RETVAL" != x0 ; then
299 FC_NAMEMANGLE=$default_nm
300 cat <<EOF>> genmake_warnings
301
302 WARNING: The "nm" command failed.
303 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
304 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here
305 EOF
306 return 1
307 fi
308 cat > genmake_tcomp.f <<EOF
309 subroutine tcall( string )
310 character*(*) string
311 call tsub( string )
312 end
313 EOF
314 $FC $FFLAGS $DEFINES -c genmake_tcomp.f >> genmake_warnings 2>&1
315 RETVAL=$?
316 if test "x$RETVAL" != x0 ; then
317 FC_NAMEMANGLE=$default_nm
318 cat <<EOF>> genmake_warnings
319
320 WARNING: FORTRAN test compile fails -- please see "genmake_errors"
321 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
322 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
323 EOF
324 return 1
325 fi
326 f_tcall=`nm genmake_tcomp.o | grep tcall | cut -d ' ' -f 3`
327 RETVAL=$?
328 if test "x$RETVAL" != x0 ; then
329 FC_NAMEMANGLE=$default_nm
330 cat <<EOF>> genmake_warnings
331
332 WARNING: The "nm" command failed.
333 WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'
334 WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here.
335 EOF
336 return 1
337 fi
338
339 c_a=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
340 f_a=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 1 | sed -e 's|Y||'`
341 c_b=`echo $c_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
342 f_b=`echo $f_tcall | sed -e 's|tcall|Y Y|' | cut -d ' ' -f 2 | sed -e 's|Y||'`
343
344 nmangle="X"
345 if test "x$c_a" != "x$f_a" ; then
346 comm="echo x$f_a | sed -e 's|x$c_a||'"
347 a=`eval $comm`
348 nmangle="$a ## $nmangle"
349 fi
350 if test "x$c_b" != "x$f_b" ; then
351 comm="echo x$f_b | sed -e 's|x$c_b||'"
352 b=`eval $comm`
353 nmangle="$nmangle ## $b"
354 fi
355
356 FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) $nmangle"
357
358 # cleanup the testing files
359 rm -f genmake_tcomp.* genmake_test.*
360 }
361
362
363 check_HAVE_CLOC() {
364 get_fortran_c_namemangling
365 cat <<EOF > genmake_tc_1.c
366 $FC_NAMEMANGLE
367 #include <stdio.h>
368 #include <stdlib.h>
369 #include <unistd.h>
370 #include <assert.h>
371 #include <sys/time.h>
372 void FC_NAMEMANGLE(cloc) ( double *curtim )
373 {
374 struct timeval tv1;
375 gettimeofday(&tv1 , (void *)NULL );
376 *curtim = (double)((tv1.tv_usec)+(tv1.tv_sec)*1.E6);
377 *curtim = *curtim/1.E6;
378 }
379 EOF
380 make genmake_tc_1.o >> genmake_tc.log 2>&1
381 RET_C=$?
382 cat <<EOF > genmake_tc_2.f
383 program hello
384 Real*8 wtime
385 external cloc
386 call cloc(wtime)
387 print *," HELLO WORLD", wtime
388 end program hello
389 EOF
390 $FC $FFLAGS -o genmake_tc genmake_tc_2.f genmake_tc_1.o >> genmake_tc.log 2>&1
391 RET_F=$?
392 test -x ./genmake_tc && ./genmake_tc >> genmake_tc.log 2>&1
393 RETVAL=$?
394 if test "x$RETVAL" = x0 ; then
395 HAVE_CLOC=t
396 DEFINES="$DEFINES -DHAVE_CLOC"
397 fi
398 rm -f genmake_tc*
399 }
400
401
402 # Set defaults here
403 COMMANDL="$0 $@"
404
405 PLATFORM=
406 LN=
407 S64=
408 KPP=
409 FC=
410 LINK=
411 # DEFINES="-DWORDLENGTH=4"
412 DEFINES=
413 PACKAGES=
414 ENABLE=
415 DISABLE=
416 MAKEFILE=
417 MAKEDEPEND=
418 PDEPEND=
419 DUMPSTATE=t
420 PDEFAULT=
421 OPTFILE=
422 INCLUDES="-I."
423 FFLAGS=
424 FOPTIM=
425 CFLAGS=
426 KFLAGS1=
427 KFLAGS2=
428 LIBS=
429 KPPFILES=
430 NOOPTFILES=
431 NOOPTFLAGS=
432
433 # DEFINES checked by test compilation
434 HAVE_SYSTEM=
435 HAVE_FDATE=
436 FC_NAMEMANGLE=
437 HAVE_CLOC=
438
439 MODS=
440 TOOLSDIR=
441 SOURCEDIRS=
442 INCLUDEDIRS=
443 STANDARDDIRS=
444
445 PWD=`pwd`
446 MAKE=make
447 AWK=awk
448 THISHOSTNAME=`hostname`
449 THISCWD=`pwd`
450 THISDATE=`date`
451 MACHINE=`uname -a`
452 EXECUTABLE=
453 EXEHOOK=
454 EXEDIR=
455 PACKAGES_CONF=
456 IEEE=
457 if test "x$MITGCM_IEEE" != x ; then
458 IEEE=$MITGCM_IEEE
459 fi
460
461 AUTODIFF_PKG_USED=f
462 AD_OPTFILE=
463 TAF=
464 AD_TAF_FLAGS=
465 FTL_TAF_FLAGS=
466 SVD_TAF_FLAGS=
467 TAF_EXTRA=
468 TAMC=
469 AD_TAMC_FLAGS=
470 FTL_TAF_FLAGS=
471 SVD_TAMC_FLAGS=
472 TAMC_EXTRA=
473
474
475 # The following state can be set directly by command-line switches
476 gm_s1="OPTFILE PDEPEND PDEFAULT MAKEFILE PLATFORM ROOTDIR MODS DISABLE ENABLE NOOPT"
477 gm_s2="FC IEEE MPI JAM DUMPSTATE STANDARDDIRS"
478
479 # The following state is not directly set by command-line switches
480 gm_s3="LN S64 KPP LINK PACKAGES MAKEDEPEND PDEPEND PDEFAULT INCLUDES FFLAGS FOPTIM "
481 gm_s4="CFLAGS KFLAGS1 KFLAGS2 LIBS KPPFILES NOOPTFILES NOOPTFLAGS"
482 gm_s5="TOOLSDIR SOURCEDIRS INCLUDEDIRS PWD MAKE THISHOSTNAME THISDATE MACHINE"
483 gm_s6="EXECUTABLE EXEHOOK EXEDIR PACKAGES_CONF"
484 gm_s7="HAVE_SYSTEM HAVE_FDATE FC_NAMEMANGLE"
485
486 # The following are all related to adjoint/tangent-linear stuff
487 gm_s10="AUTODIFF_PKG_USED AD_OPTFILE TAMC TAF AD_TAMC_FLAGS AD_TAF_FLAGS"
488 gm_s11="FTL_TAMC_FLAGS FTL_TAF_FLAGS SVD_TAMC_FLAGS SVD_TAF_FLAGS"
489 gm_s12="TAF_EXTRA TAMC_EXTRA"
490
491 gm_state="COMMANDL $gm_s1 $gm_s2 $gm_s3 $gm_s4 $gm_s5 $gm_s6 $gm_s7"
492 gm_state="$gm_state $gm_s10 $gm_s11 $gm_s12"
493
494
495 echo
496 echo "=== Processing options files and arguments ==="
497 gm_local="genmake_local"
498 for i in . $MODS ; do
499 if test -r $i/$gm_local ; then
500 . $i/$gm_local
501 break
502 fi
503 done
504 echo -n " getting local config information: "
505 if test -e $gm_local ; then
506 echo "using $gm_local"
507 . $gm_local
508 # echo "DISABLE=$DISABLE"
509 # echo "ENABLE=$ENABLE"
510 else
511 echo "none found"
512 fi
513
514 # echo "$0::$1:$2:$3:$4:$5:$6:$7:"
515 #OPTIONS=
516 #n=0
517 #for i ; do
518 # echo "$i $n"
519 # setvar="OPTIONS[$n]='$i'"
520 # # echo " $setvar"
521 # eval "$setvar"
522 # n=$(( $n + 1 ))
523 #done
524 #parse_options
525 ac_prev=
526 for ac_option ; do
527
528 # If the previous option needs an argument, assign it.
529 if test -n "$ac_prev"; then
530 eval "$ac_prev=\$ac_option"
531 ac_prev=
532 continue
533 fi
534
535 ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
536
537 case $ac_option in
538
539 -help | --help | -h | --h)
540 usage ;;
541
542 -nooptfile | --nooptfile)
543 OPTFILE="NONE" ;;
544 -optfile | --optfile | -of | --of)
545 ac_prev=OPTFILE ;;
546 -optfile=* | --optfile=* | -of=* | --of=*)
547 OPTFILE=$ac_optarg ;;
548
549 -adoptfile | --adoptfile | -ad | --ad)
550 ac_prev=AD_OPTFILE ;;
551 -adoptfile=* | --adoptfile=* | -adof=* | --adof=*)
552 AD_OPTFILE=$ac_optarg ;;
553
554 -pdepend | --pdepend)
555 ac_prev=PDEPEND ;;
556 -pdepend=* | --pdepend=*)
557 PDEPEND=$ac_optarg ;;
558
559 -pdefault | --pdefault)
560 ac_prev=PDEFAULT ;;
561 -pdefault=* | --pdefault=*)
562 PDEFAULT=$ac_optarg ;;
563
564 -make | --make | -m | --m)
565 ac_prev=MAKE ;;
566 -make=* | --make=* | -m=* | --m=*)
567 MAKE=$ac_optarg ;;
568
569 -makefile | --makefile | -ma | --ma)
570 ac_prev=MAKEFILE ;;
571 -makefile=* | --makefile=* | -ma=* | --ma=*)
572 MAKEFILE=$ac_optarg ;;
573
574 -platform | --platform | -pl | --pl)
575 ac_prev=PLATFORM ;;
576 -platform=* | --platform=* | -pl=* | --pl=*)
577 PLATFORM=$ac_optarg ;;
578
579 -rootdir | --rootdir | -rd | --rd)
580 ac_prev=ROOTDIR ;;
581 -rootdir=* | --rootdir=* | -rd=* | --rd=*)
582 ROOTDIR=$ac_optarg ;;
583
584 -mods | --mods | -mo | --mo)
585 ac_prev=MODS ;;
586 -mods=* | --mods=* | -mo=* | --mo=*)
587 MODS=$ac_optarg ;;
588
589 -disable | --disable)
590 ac_prev=DISABLE ;;
591 -disable=* | --disable=*)
592 DISABLE=$ac_optarg ;;
593
594 -enable | --enable)
595 ac_prev=ENABLE ;;
596 -enable=* | --enable=*)
597 ENABLE=$ac_optarg ;;
598
599 -standarddirs | --standarddirs)
600 ac_prev=STANDARDDIRS ;;
601 -standarddirs=* | --standarddirs=*)
602 STANDARDDIRS=$ac_optarg ;;
603
604 -noopt | --noopt)
605 ac_prev=NOOPT ;;
606 -noopt=* | --noopt=*)
607 NOOPT=$ac_optarg ;;
608
609 # -cpp | --cpp)
610 # ac_prev=cpp ;;
611 # -cpp=* | --cpp=*)
612 # CPP=$ac_optarg ;;
613
614 -fortran | --fortran | -fc | --fc)
615 ac_prev=FC ;;
616 -fc=* | --fc=*)
617 FC=$ac_optarg ;;
618
619 -ieee | --ieee)
620 IEEE=true ;;
621 -noieee | --noieee)
622 IEEE= ;;
623
624 -mpi | --mpi)
625 MPI=true ;;
626 -nompi | --nompi)
627 MPI= ;;
628
629 -jam | --jam)
630 JAM=1 ;;
631 -nojam | --nojam)
632 JAM=0 ;;
633
634 -ds | --ds)
635 DUMPSTATE=t ;;
636
637 -taf_extra | --taf_extra)
638 ac_prev=TAF_EXTRA ;;
639 -taf_extra=* | --taf_extra=*)
640 TAF_EXTRA=$ac_optarg ;;
641
642 -tamc_extra | --tamc_extra)
643 ac_prev=TAMC_EXTRA ;;
644 -tamc_extra=* | --tamc_extra=*)
645 TAMC_EXTRA=$ac_optarg ;;
646
647 -*)
648 echo "Error: unrecognized option: "$ac_option
649 usage
650 ;;
651
652 *)
653 echo "Error: unrecognized argument: "$ac_option
654 usage
655 ;;
656
657 esac
658
659 done
660
661 if test -f ./.genmakerc ; then
662 echo
663 echo "WARNING: genmake2 has detected a copy of the old-style \"./.genmakerc\""
664 echo " file. This file format is no longer supported. Please see:"
665 echo
666 echo " http://mitgcm.org/devel_HOWTO/"
667 echo
668 echo " for directions on how to setup and use the new \"genmake2\" input"
669 echo " files and send an email to MITgcm-support@mitgcm.org if you want help."
670 echo
671 fi
672
673 if test "x${ROOTDIR}" = x ; then
674 if test "${PWD##/*/}" = "bin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then
675 ROOTDIR=".."
676 else
677 for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
678 if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
679 ROOTDIR=$d
680 echo -n "Warning: ROOTDIR was not specified but there appears to be"
681 echo " a copy of MITgcm at \"$ROOTDIR\" so we'll try it."
682 break
683 fi
684 done
685 fi
686 fi
687 if test "x${ROOTDIR}" = x ; then
688 echo "Error: Cannot determine ROOTDIR for MITgcm code."
689 echo " Please specify a ROOTDIR using either an options "
690 echo " file or a command-line option."
691 exit 1
692 fi
693 if test ! -d ${ROOTDIR} ; then
694 echo "Error: the specified ROOTDIR (\"$ROOTDIR\") does not exist!"
695 exit 1
696 fi
697
698 echo " getting OPTFILE information: "
699 if test "x${OPTFILE}" = x ; then
700 if test "x$MITGCM_OF" = x ; then
701 echo "Warning: no OPTFILE specified so we'll look for possible settings"
702 printf "\n=== Searching for possible settings for OPTFILE ===\n"
703 find_possible_configs
704 else
705 OPTFILE=$MITGCM_OF
706 fi
707 fi
708 if test "x$OPTFILE" != xNONE ; then
709 if test -f "$OPTFILE" -a -r "$OPTFILE" ; then
710 echo " using OPTFILE=\"$OPTFILE\""
711 . "$OPTFILE"
712 RETVAL=$?
713 if test "x$RETVAL" != x0 ; then
714 echo -n "Error: failed to source OPTFILE \"$OPTFILE\""
715 echo "--please check that variable syntax is bash-compatible"
716 exit 1
717 fi
718 if test "x$DUMPSTATE" != xf ; then
719 cp -f $OPTFILE "genmake_optfile"
720 fi
721 else
722 echo "Error: can't read OPTFILE=\"$OPTFILE\""
723 exit 1
724 fi
725 fi
726
727 echo " getting AD_OPTFILE information: "
728 if test "x${AD_OPTFILE}" = x ; then
729 if test "x$MITGCM_AD_OF" = x ; then
730 AD_OPTFILE=$ROOTDIR/tools/adjoint_options/adjoint_default
731 else
732 AD_OPTFILE=$MITGCM_AD_OF
733 fi
734 fi
735 if test "x${AD_OPTFILE}" != xNONE ; then
736 if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then
737 echo " using AD_OPTFILE=\"$AD_OPTFILE\""
738 . "$AD_OPTFILE"
739 RETVAL=$?
740 if test "x$RETVAL" != x0 ; then
741 echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\""
742 echo "--please check that variable syntax is bash-compatible"
743 exit 1
744 fi
745 if test "x$DUMPSTATE" != xf ; then
746 cp -f $AD_OPTFILE "genmake_ad_optfile"
747 fi
748 else
749 echo "Error: can't read AD_OPTFILE=\"$AD_OPTFILE\""
750 exit 1
751 fi
752 fi
753
754 # Check that FC, LINK, CPP, S64, LN, and MAKE are defined. If not,
755 # either set defaults or complain and abort!
756 if test "x$FC" = x ; then
757 cat <<EOF 1>&2
758
759 Error: no Fortran compiler: please specify using one of the following:
760 1) within the options file ("FC=...") as specified by "-of=OPTFILE"
761 2) the "-fc=XXX" command-line option
762 3) the "./genmake_local" file
763 EOF
764 exit 1
765 fi
766 if test "x$LINK" = x ; then
767 LINK=$FC
768 fi
769 if test "x$CPP" = x ; then
770 CPP="cpp"
771 fi
772 if test "x$MAKE" = x ; then
773 MAKE="make"
774 fi
775 echo "#define A a" | $CPP > test_cpp 2>&1
776 RETVAL=$?
777 if test "x$RETVAL" != x0 ; then
778 cat <<EOF 1>&2
779
780 Error: C pre-processor "$CPP" failed the test case: please specify using:
781
782 1) within the options file ("CPP=...") as specified by "-of=OPTFILE"
783 2) the "./genmake_local" file
784 3) with the CPP environment variable
785
786 EOF
787 exit 1
788 else
789 rm -f test_cpp
790 fi
791 if test "x$MAKEDEPEND" = x ; then
792 MAKEDEPEND=makedepend
793 fi
794 if test "x$LN" = x ; then
795 LN="ln -s"
796 fi
797 echo "test" > genmake_test_ln
798 $LN genmake_test_ln genmake_tlink
799 RETVAL=$?
800 if test "x$RETVAL" != x0 ; then
801 cat <<EOF 1>&2
802
803 Error: The command "ln -s" failed -- please specify a working soft-link
804 command in the optfile.
805
806 EOF
807 exit 1
808 fi
809 rm -f genmake_test_ln genmake_tlink
810
811
812 printf "\n=== Checking system libraries ===\n"
813 echo -n " Do we have the system() command using $FC... "
814 cat > genmake_tcomp.f <<EOF
815 program hello
816 call system('echo hi')
817 end
818 EOF
819 $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
820 RETVAL=$?
821 if test "x$RETVAL" = x0 ; then
822 HAVE_SYSTEM=t
823 DEFINES="$DEFINES -DHAVE_SYSTEM"
824 echo "yes"
825 else
826 HAVE_SYSTEM=
827 echo "no"
828 fi
829 rm -f genmake_tcomp*
830
831 echo -n " Do we have the fdate() command using $FC... "
832 cat > genmake_tcomp.f <<EOF
833 program hello
834 CHARACTER(128) string
835 string = ' '
836 call fdate( string )
837 print *, string
838 end
839 EOF
840 $FC $FFLAGS $DEFINES -o genmake_tcomp genmake_tcomp.f > genmake_tcomp.log 2>&1
841 RETVAL=$?
842 if test "x$RETVAL" = x0 ; then
843 HAVE_FDATE=t
844 DEFINES="$DEFINES -DHAVE_FDATE"
845 echo "yes"
846 else
847 HAVE_FDATE=
848 echo "no"
849 fi
850 rm -f genmake_tcomp*
851
852 echo -n " Can we call simple C routines (here, \"cloc()\") using $FC... "
853 check_HAVE_CLOC
854 if test "x$HAVE_CLOC" != x ; then
855 echo "yes"
856 else
857 echo "no"
858 fi
859 echo "$FC_NAMEMANGLE" > FC_NAMEMANGLE.h.template
860 cmp FC_NAMEMANGLE.h FC_NAMEMANGLE.h.template > /dev/null 2>&1
861 RETVAL=$?
862 if test "x$RETVAL" != x0 ; then
863 mv -f FC_NAMEMANGLE.h.template FC_NAMEMANGLE.h
864 fi
865 rm -f genmake_t*
866
867
868 printf "\n=== Setting defaults ===\n"
869 echo -n " Adding MODS directories: "
870 for d in $MODS ; do
871 if test ! -d $d ; then
872 echo
873 echo "Error: MODS directory \"$d\" not found!"
874 exit 1
875 else
876 echo -n " $d"
877 SOURCEDIRS="$SOURCEDIRS $d"
878 INCLUDEDIRS="$INCLUDEDIRS $d"
879 fi
880 done
881 echo
882
883 if test "x$MAKEFILE" = x ; then
884 MAKEFILE="Makefile"
885 fi
886 if test "x${PLATFORM}" = x ; then
887 PLATFORM=$p_PLATFORM
888 fi
889
890 if test "x${EXEDIR}" = x ; then
891 if test "${PWD##/*/}" = "bin" -a -d ../exe -a $ROOTDIR = .. ; then
892 EXEDIR=../exe
893 else
894 EXEDIR=.
895 fi
896 fi
897 if test ! -d ${EXEDIR} ; then
898 echo "Error: the specified EXEDIR (\"$EXEDIR\") does not exist!"
899 exit 1
900 fi
901
902 if test "x${TOOLSDIR}" = x ; then
903 TOOLSDIR="$ROOTDIR/tools"
904 fi
905 if test ! -d ${TOOLSDIR} ; then
906 echo "Error: the specified $TOOLSDIR (\"$TOOLSDIR\") does not exist!"
907 exit 1
908 fi
909 if test "x$S64" = x ; then
910 S64='$(TOOLSDIR)/set64bitConst.sh'
911 fi
912
913 EXECUTABLE=${EXECUTABLE:-mitgcmuv}
914
915 # We have a special set of source files in eesupp/src which are
916 # generated from some template source files. We'll make them first so
917 # they appear as regular source code
918 if test -r $ROOTDIR"/eesupp/src/Makefile" ; then
919 echo " Making source files in eesupp from templates"
920 ( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1
921 RETVAL=$?
922 if test "x${RETVAL}" = x0 ; then
923 rm -f make_eesupp.errors
924 else
925 echo "Error: problem encountered while building source files in eesupp:"
926 cat make_eesupp.errors
927 exit 1
928 fi
929 fi
930
931 printf "\n=== Determining package settings ===\n"
932 if test "x${PDEPEND}" = x ; then
933 tmp=$ROOTDIR"/pkg/pkg_depend"
934 if test -r $tmp ; then
935 PDEPEND=$tmp
936 else
937 echo "Warning: No package dependency information was specified."
938 echo " Please check that ROOTDIR/pkg/pkg_depend exists."
939 fi
940 else
941 if test ! -r ${PDEPEND} ; then
942 echo "Error: can't read package dependency info from PDEPEND=\"$PDEPEND\""
943 exit 1
944 fi
945 fi
946 echo " getting package dependency info from $PDEPEND"
947 # Strip the comments and then convert the dependency file into
948 # two arrays: PNAME, DNAME
949 cat $PDEPEND | sed -e 's/#.*$//g' \
950 | $AWK 'BEGIN{nn=-1;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME_"nn"="$1"\nDNAME_"nn"="$i}} END{print "nname="nn}' \
951 > ./.pd_tmp
952 RETVAL=$?
953 if test ! "x${RETVAL}" = x0 ; then
954 echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\""
955 exit 1
956 fi
957 . ./.pd_tmp
958 rm -f ./.pd_tmp
959
960 # Search for default packages. Note that a "$ROOTDIR/pkg/pkg_groups"
961 # file should eventually be added so that, for convenience, one can
962 # specify groups of packages using names like "ocean" and "atmosphere".
963 echo -n " checking default package list: "
964 if test "x${PDEFAULT}" = x ; then
965 for i in "." $MODS ; do
966 if test -r $i"/packages.conf" ; then
967 PDEFAULT=$i"/packages.conf"
968 break
969 fi
970 done
971 fi
972 if test "x${PDEFAULT}" = x ; then
973 PDEFAULT="$ROOTDIR/pkg/pkg_default"
974 fi
975 if test "x${PDEFAULT}" = xNONE ; then
976 echo "default packages file disabled"
977 else
978 if test ! -r $PDEFAULT ; then
979 echo ""
980 echo "Warning: can't read default packages from PDEFAULT=\"$PDEFAULT\""
981 else
982 echo " using PDEFAULT=\"$PDEFAULT\""
983 # Strip the comments and add all the names
984 def=`cat $PDEFAULT | sed -e 's/#.*$//g' | $AWK '(NF>0){print $0}'`
985 RETVAL=$?
986 if test "x${RETVAL}" != x0 ; then
987 echo -n "Error: can't parse default package list "
988 echo "-- please check PDEFAULT=\"$PDEFAULT\""
989 exit 1
990 fi
991 for i in $def ; do
992 PACKAGES="$PACKAGES $i"
993 done
994 echo " before group expansion packages are: $PACKAGES"
995 expand_pkg_groups
996 echo " after group expansion packages are: $PACKAGES"
997 fi
998 fi
999
1000 echo " applying DISABLE settings"
1001 pack=
1002 for p in $PACKAGES ; do
1003 addit="t"
1004 for d in $DISABLE ; do
1005 if test "x$p" = "x$d" ; then
1006 addit="f"
1007 fi
1008 done
1009 if test "x$addit" = xt ; then
1010 pack="$pack $p"
1011 fi
1012 done
1013 PACKAGES="$pack"
1014 echo " applying ENABLE settings"
1015 echo "" > ./.tmp_pack
1016 PACKAGES="$PACKAGES $ENABLE"
1017 for i in $PACKAGES ; do
1018 if test ! -d "$ROOTDIR/pkg/$i" ; then
1019 echo "Error: can't find package $i at \"$ROOTDIR/pkg/$i\""
1020 exit 1
1021 fi
1022 echo $i >> ./.tmp_pack
1023 done
1024 pack=`cat ./.tmp_pack | sort | uniq`
1025 rm -f ./.tmp_pack
1026 PACKAGES=
1027 for i in $pack ; do
1028 PACKAGES="$PACKAGES $i"
1029 done
1030 echo " packages are: $PACKAGES"
1031
1032 echo " applying package dependency rules"
1033 ck=
1034 while test "x$ck" != xtt ; do
1035 i=0
1036 # rtot=${#PNAME[@]}
1037 rtot=$nname
1038 while test $i -lt $rtot ; do
1039
1040 # Is $pname in the current $PACKAGES list?
1041 # pname=${PNAME[$i]}
1042 tmp="pname=\"\$PNAME_$i\""
1043 eval $tmp
1044 pin="f"
1045 for p in $PACKAGES ; do
1046 if test "x$p" = "x$pname" ; then
1047 pin="t"
1048 fi
1049 done
1050
1051 # Is the DNAME entry a (+) or (-) rule ?
1052 tmp="dname=\"\$DNAME_$i\""
1053 eval $tmp
1054 plus="-"
1055 echo $dname | grep '^+' > /dev/null 2>&1
1056 RETVAL=$?
1057 if test "x$RETVAL" = x0 ; then
1058 plus="+"
1059 fi
1060
1061 # Is $dname in the current $PACKAGES list?
1062 dname=`echo $dname | sed -e 's/^[+-]//'`
1063 din="f"
1064 for p in $PACKAGES ; do
1065 if test "x$p" = "x$dname" ; then
1066 din="t"
1067 fi
1068 done
1069
1070 # Do we need to add $dname according to the dependency rules?
1071 if test "x$pin" = xt -a "x$plus" = "x+" -a "x$din" = xf ; then
1072 in_dis="f"
1073 for dis in $DISABLE ; do
1074 if test "x$dis" = "x$dname" ; then
1075 in_dis="t"
1076 fi
1077 done
1078 if test "x$in_dis" = xt ; then
1079 echo "Error: can't satisfy package dependencies:"
1080 echo " \"$dname\" is required by the dependency rules"
1081 echo " but is disallowed by the DISABLE settings"
1082 exit 1
1083 else
1084 PACKAGES="$PACKAGES $dname"
1085 ck=
1086 fi
1087 fi
1088
1089 # Do we need to get rid of $dname according to the dependency rules?
1090 if test "x$pin" = xt -a "x$plus" = "x-" -a "x$din" = xt; then
1091 echo "Error: can't satisfy package dependencies:"
1092 echo " \"$pname\" was requested but is disallowed by"
1093 echo " the dependency rules for \"$dname\""
1094 exit 1
1095 fi
1096 i=$(( $i + 1 ))
1097 done
1098 ck=$ck"t"
1099 done
1100 echo " packages are: $PACKAGES"
1101 for i in $PACKAGES ; do
1102 adr="$ROOTDIR/pkg/$i"
1103 if test -d $adr ; then
1104 SOURCEDIRS="$SOURCEDIRS $adr"
1105 INCLUDEDIRS="$INCLUDEDIRS $adr"
1106 if test "x$i" = xautodiff ; then
1107 AUTODIFF_PKG_USED=t
1108 fi
1109 else
1110 echo "Error: the directory \"$adr\" for package $i doesn't exist"
1111 exit 1
1112 fi
1113 done
1114
1115
1116 # Create a list of #define and #undef to enable/disable packages
1117 PACKAGES_DOT_H=PACKAGES_CONFIG.h
1118 cat <<EOF >$PACKAGES_DOT_H".tmp"
1119 C=== GENMAKE v2 ===
1120 C The following defines have been set by GENMAKE, so please do not
1121 C edit anything below these comments. In general, you should
1122 C add or remove packages by re-running genmake with different
1123 C "-enable" and/or "-disable" options.
1124
1125 #ifndef PACKAGES_H
1126 #define PACKAGES_H
1127
1128 C Packages disabled by genmake:
1129 EOF
1130 # The following UGLY HACK sets multiple "#undef"s and it needs to go
1131 # away. On 2003-08-12, CNH, JMC, and EH3 agreed that the CPP_OPTIONS.h
1132 # file would eventually be split up so that all package-related #define
1133 # statements could be separated and handled only by genmake.
1134 names=`ls -1 "$ROOTDIR/pkg"`
1135 all_pack=
1136 for n in $names ; do
1137 if test -d "$ROOTDIR/pkg/$n" -a "x$n" != xCVS ; then
1138 has_pack="f"
1139 for pack in $PACKAGES ; do
1140 if test "x$pack" = "x$n" ; then
1141 has_pack="t"
1142 break
1143 fi
1144 done
1145 if test "x$has_pack" = xf ; then
1146 undef=`echo "ALLOW_$n" | $AWK '{print toupper($0)}'`
1147 echo "#undef $undef" >> $PACKAGES_DOT_H".tmp"
1148 fi
1149 fi
1150 done
1151 cat <<EOF >>$PACKAGES_DOT_H".tmp"
1152
1153 C Packages enabled by genmake:
1154 EOF
1155 for i in $PACKAGES ; do
1156 def=`echo "ALLOW_$i" | $AWK '{print toupper($0)}'`
1157 echo "#define $def" >> $PACKAGES_DOT_H".tmp"
1158 #eh3 DEFINES="$DEFINES -D$def"
1159
1160 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
1161 case $i in
1162 aim_v23)
1163 echo "#define ALLOW_AIM" >> $PACKAGES_DOT_H".tmp"
1164 DEFINES="$DEFINES -DALLOW_AIM"
1165 echo "Warning: ALLOW_AIM is set to enable aim_v23. This is REALLY ugly Jean-Michel :-)"
1166 ;;
1167 esac
1168 #EH3 WARNING : This is an UGLY HACK that needs to be removed!!!
1169
1170 done
1171 cat <<EOF >>$PACKAGES_DOT_H".tmp"
1172
1173 #endif /* PACKAGES_H */
1174 EOF
1175
1176 if test ! -f $PACKAGES_DOT_H ; then
1177 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1178 else
1179 cmp $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1180 RETVAL=$?
1181 if test "x$RETVAL" = x0 ; then
1182 rm -f $PACKAGES_DOT_H".tmp"
1183 else
1184 mv -f $PACKAGES_DOT_H $PACKAGES_DOT_H".bak"
1185 mv -f $PACKAGES_DOT_H".tmp" $PACKAGES_DOT_H
1186 fi
1187 fi
1188
1189 echo " Adding STANDARDDIRS"
1190 BUILDDIR=${BUILDDIR:-.}
1191 if test "x$STANDARDDIRS" = x ; then
1192 STANDARDDIRS="eesupp model"
1193 fi
1194 for d in $STANDARDDIRS ; do
1195 adr="$ROOTDIR/$d/src"
1196 if test ! -d $adr ; then
1197 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1198 echo " is correct and that you correctly specified the STANDARDDIRS option"
1199 exit 1
1200 else
1201 SOURCEDIRS="$SOURCEDIRS $adr"
1202 fi
1203 adr="$ROOTDIR/$d/inc"
1204 if test ! -d $adr ; then
1205 echo "Error: directory $adr not found -- please check that ROOTDIR=\"$ROOTDIR\""
1206 echo " is correct and that you correctly specified the STANDARDDIRS option"
1207 exit 1
1208 else
1209 INCLUDEDIRS="$INCLUDEDIRS $adr"
1210 fi
1211 done
1212
1213 echo " Searching for CPP_OPTIONS.h in order to warn about the presence"
1214 echo " of \"#define ALLOW_PKGNAME\"-type statements:"
1215 CPP_OPTIONS=
1216 spaths=". $INCLUDEDIRS"
1217 for i in $spaths ; do
1218 try="$i/CPP_OPTIONS.h"
1219 # echo -n " trying $try : "
1220 if test -f $try -a -r $try ; then
1221 echo " found CPP_OPTIONS=\"$try\""
1222 CPP_OPTIONS="$try"
1223 break
1224 fi
1225 done
1226 if test "x$CPP_OPTIONS" = x ; then
1227 echo "Error: can't find \"CPP_OPTIONS.h\" in the path list: $spaths"
1228 exit 1
1229 fi
1230 # New safety test: make sure packages are not mentioned in CPP_OPTIONS.h
1231 names=`ls -1 "$ROOTDIR/pkg"`
1232 for n in $names ; do
1233 test_for_package_in_cpp_options $CPP_OPTIONS $n
1234 done
1235
1236
1237 # Here, we build the list of files to be "run through" the adjoint
1238 # compiler.
1239 if test -f ./ad_files ; then
1240 rm -f ./ad_files
1241 fi
1242 echo " Creating the list of files for the adjoint compiler."
1243 for i in $SOURCEDIRS ; do
1244 list_files=`( cd $i && ls -1 *.list 2>/dev/null )`
1245 for j in $list_files ; do
1246 cat $i/$j >> ad_files
1247 done
1248 done
1249
1250 cat <<EOF > adjoint_sed
1251 s/call adopen(/call adopen ( mythid,\\
1252 \& /g
1253 s/call adclose(/call adclose( mythid,\\
1254 \& /g
1255 s/call adread(/call adread ( mythid,\\
1256 \& /g
1257 s/call adwrite(/call adwrite( mythid,\\
1258 \& /g
1259
1260 EOF
1261
1262 echo
1263 echo "=== Creating the Makefile ==="
1264 echo " setting INCLUDES"
1265 for i in $INCLUDEDIRS ; do
1266 if ! test -d $i ; then
1267 # INCLUDES="$INCLUDES -I$i"
1268 # else
1269 echo "Warning: can't find INCLUDEDIRS=\"$i\""
1270 fi
1271 done
1272
1273 echo " Determining the list of source and include files"
1274 rm -rf .links.tmp
1275 mkdir .links.tmp
1276 echo "# This section creates symbolic links" > srclinks.tmp
1277 echo "" >> srclinks.tmp
1278 echo -n 'SRCFILES = ' > srclist.inc
1279 echo -n 'CSRCFILES = ' > csrclist.inc
1280 echo -n 'F90SRCFILES = ' > f90srclist.inc
1281 echo -n 'HEADERFILES = ' > hlist.inc
1282 echo -n 'AD_FLOW_FILES = ' > ad_flow_files.inc
1283 alldirs="$SOURCEDIRS $INCLUDEDIRS ."
1284 for d in $alldirs ; do
1285 deplist=
1286 sfiles=`( cd $d; echo *.[h,c,F] *.flow )`
1287 sfiles=`( echo $sfiles; cd $d; echo *.F90 )`
1288 for sf in $sfiles ; do
1289 if test ! -r ".links.tmp/$sf" ; then
1290 if test -f "$d/$sf" ; then
1291 extn=`echo $sf | $AWK -F '.' '{print $NF}'`
1292 touch .links.tmp/$sf
1293 deplist="$deplist $sf"
1294 case $extn in
1295 F)
1296 echo " \\" >> srclist.inc
1297 echo -n " $sf" >> srclist.inc
1298 ;;
1299 F90)
1300 echo " \\" >> f90srclist.inc
1301 echo -n " $sf" >> f90srclist.inc
1302 ;;
1303 c)
1304 echo " \\" >> csrclist.inc
1305 echo -n " $sf" >> csrclist.inc
1306 ;;
1307 h)
1308 echo " \\" >> hlist.inc
1309 echo -n " $sf" >> hlist.inc
1310 ;;
1311 flow)
1312 echo " \\" >> ad_flow_files.inc
1313 echo -n " $sf" >> ad_flow_files.inc
1314 ;;
1315 esac
1316 fi
1317 fi
1318 done
1319 if test "x$deplist" != x ; then
1320 echo "" >> srclinks.tmp
1321 echo "# These files are linked from $d" >> srclinks.tmp
1322 echo "$deplist :" >> srclinks.tmp
1323 printf "\t\$(LN) %s/\$@ \$@\n" $d >> srclinks.tmp
1324 fi
1325 done
1326 rm -rf .links.tmp
1327 echo "" >> srclist.inc
1328 echo "" >> csrclist.inc
1329 echo "" >> f90srclist.inc
1330 echo "" >> hlist.inc
1331 echo "" >> ad_flow_files.inc
1332
1333 if test -e $MAKEFILE ; then
1334 mv -f $MAKEFILE "$MAKEFILE.bak"
1335 fi
1336 echo " Writing makefile: $MAKEFILE"
1337 echo "# Multithreaded + multi-processing makefile for:" > $MAKEFILE
1338 echo "# $MACHINE" >> $MAKEFILE
1339 echo "# This makefile was generated automatically on" >> $MAKEFILE
1340 echo "# $THISDATE" >> $MAKEFILE
1341 echo "# by the command:" >> $MAKEFILE
1342 echo "# $0 $@" >> $MAKEFILE
1343 echo "# executed by:" >> $MAKEFILE
1344 echo "# $USER@${THISHOSTNAME}:${THISCWD}" >> $MAKEFILE
1345
1346 EXE_AD=$EXECUTABLE"_ad"
1347 EXE_FTL=$EXECUTABLE"_ftl"
1348 EXE_SVD=$EXECUTABLE"_svd"
1349
1350 cat >>$MAKEFILE <<EOF
1351 #
1352 # BUILDDIR : Directory where object files are written
1353 # SOURCEDIRS : Directories containing the source (.F) files
1354 # INCLUDEDIRS : Directories containing the header-source (.h) files
1355 # EXEDIR : Directory where executable that is generated is written
1356 # EXECUTABLE : Full path of executable binary
1357 #
1358 # CPP : C-preprocessor command
1359 # INCLUDES : Directories searched for header files
1360 # DEFINES : Macro definitions for CPP
1361 # MAKEDEPEND : Dependency generator
1362 # KPP : Special preprocessor command (specific to platform)
1363 # KFLAGS : Flags for KPP
1364 # FC : Fortran compiler command
1365 # FFLAGS : Configuration/debugging options for FC
1366 # FOPTIM : Optimization options for FC
1367 # LINK : Command for link editor program
1368 # LIBS : Library flags /or/ additional optimization/debugging flags
1369
1370 ROOTDIR = ${ROOTDIR}
1371 BUILDDIR = ${BUILDDIR}
1372 SOURCEDIRS = ${SOURCEDIRS}
1373 INCLUDEDIRS = ${INCLUDEDIRS}
1374 EXEDIR = ${EXEDIR}
1375 EXECUTABLE = \$(EXEDIR)/${EXECUTABLE}
1376 TOOLSDIR = ${TOOLSDIR}
1377
1378 #eh3 new defines for the adjoint work
1379 AUTODIFF = ${ROOTDIR}/pkg/autodiff
1380 EXE_AD = ${EXE_AD}
1381 EXE_FTL = ${EXE_FTL}
1382 EXE_SVD = ${EXE_SVD}
1383
1384 EOF
1385
1386 # Note: figure out some way to add Hyades JAM libraries here
1387
1388 cat >>$MAKEFILE <<EOF
1389 # Unix ln (link)
1390 LN = ${LN}
1391 # C preprocessor
1392 CPP = cat \$< | ${S64} | ${CPP}
1393 # Dependency generator
1394 MAKEDEPEND = ${MAKEDEPEND}
1395 # Special preprocessor (KAP on DECs, FPP on Crays)
1396 KPP = ${KPP}
1397 # Fortran compiler
1398 FC = ${FC}
1399 # Fortran compiler
1400 F90C = ${F90C}
1401 # Link editor
1402 LINK = ${LINK}
1403
1404 # Defines for CPP
1405 DEFINES = ${DEFINES}
1406 # Includes for CPP
1407 INCLUDES = ${INCLUDES}
1408 # Flags for KPP
1409 KFLAGS1 = ${KFLAGS1}
1410 KFLAGS2 = ${KFLAGS2}
1411 # Optim./debug for FC
1412 FFLAGS = ${FFLAGS}
1413 FOPTIM = ${FOPTIM}
1414 # Optim./debug for FC
1415 F90FLAGS = ${F90FLAGS}
1416 F90OPTIM = ${F90OPTIM}
1417 # Flags for CC
1418 CFLAGS = ${CFLAGS}
1419 # Files that should not be optimized
1420 NOOPTFILES = ${NOOPTFILES}
1421 NOOPTFLAGS = ${NOOPTFLAGS}
1422 # Flags and libraries needed for linking
1423 LIBS = ${LIBS} \$(XLIBS)
1424 # Name of the Mekfile
1425 MAKEFILE=${MAKEFILE}
1426
1427 EOF
1428
1429 cat srclist.inc >> $MAKEFILE
1430 cat csrclist.inc >> $MAKEFILE
1431 cat f90srclist.inc >> $MAKEFILE
1432 cat hlist.inc >> $MAKEFILE
1433 cat ad_flow_files.inc >> $MAKEFILE
1434 echo >> $MAKEFILE
1435 echo 'F77FILES = $(SRCFILES:.F=.f)' >> $MAKEFILE
1436 echo 'F90FILES = $(F90SRCFILES:.F90=.f90)' >> $MAKEFILE
1437 echo 'OBJFILES = $(SRCFILES:.F=.o) $(CSRCFILES:.c=.o) $(F90SRCFILES:.F90=.o)' >> $MAKEFILE
1438
1439 rm -f srclist.inc csrclist.inc hlist.inc flist.tmp clist.tmp f90srclist.inc
1440 rm -f ad_flow_files.inc
1441
1442 cat >>$MAKEFILE <<EOF
1443
1444 .SUFFIXES:
1445 .SUFFIXES: .o .f .p .F .c .F90 .f90
1446
1447 all: \$(EXECUTABLE)
1448 \$(EXECUTABLE): \$(OBJFILES)
1449 \$(LINK) -o \$@ \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) \$(LIBS)
1450 depend:
1451 @make links
1452 \$(MAKEDEPEND) -o .f \$(DEFINES) \$(INCLUDES) \$(SRCFILES)
1453 ${TOOLSDIR}/f90mkdepend >> \$(MAKEFILE)
1454
1455 links: \$(SRCFILES) \$(CSRCFILES) \$(HEADERFILES) \$(F90SRCFILES)
1456
1457 small_f: \$(F77FILES) \$(F90FILES)
1458
1459 output.txt: \$(EXECUTABLE)
1460 @printf 'running ... '
1461 @\$(EXECUTABLE) > \$@
1462
1463 clean:
1464 -cat AD_CONFIG.template > AD_CONFIG.h
1465 -rm -rf *.o *.f *.p *.f90 *.mod ${RMFILES} work.{pc,pcl}
1466 Clean:
1467 @make clean
1468 @make cleanlinks
1469 -rm -f Makefile.bak genmake_state genmake_*optfile make.log
1470 CLEAN:
1471 @make Clean
1472 -find \$(EXEDIR) -name "*.meta" -exec rm {} \;
1473 -find \$(EXEDIR) -name "*.data" -exec rm {} \;
1474 -find \$(EXEDIR) -name "fort.*" -exec rm {} \;
1475 -rm -f \$(EXECUTABLE) output.txt
1476
1477 #eh3 Makefile: makefile
1478 makefile:
1479 ${0} $@
1480 cleanlinks:
1481 -find . -type l -exec rm {} \;
1482
1483 # The normal chain of rules is ( .F - .f - .o )
1484 .F.f:
1485 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1486 .f.o:
1487 \$(FC) \$(FFLAGS) \$(FOPTIM) -c \$<
1488 .F90.f90:
1489 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1490 .f90.o:
1491 \$(F90C) \$(F90FLAGS) \$(F90OPTIM) -c \$<
1492 .c.o:
1493 \$(CC) \$(CFLAGS) -c \$<
1494
1495 # Special exceptions that use the ( .F - .p - .f - .o ) rule-chain
1496 .F.p:
1497 \$(CPP) \$(DEFINES) \$(INCLUDES) > \$@
1498 .p.f:
1499 \$(KPP) \$(KFLAGS1)\$@ \$(KFLAGS2) \$<
1500
1501 #=========================================
1502 #=== Automatic Differentiation Rules ===
1503
1504 TAMC = ${TAMC}
1505 TAF = ${TAF}
1506
1507 TAF_EXTRA = ${TAF_EXTRA}
1508 TAMC_EXTRA = ${TAMC_EXTRA}
1509
1510 EOF
1511
1512 ad_vars="AD_TAMC_FLAGS AD_TAF_FLAGS"
1513 ad_vars="$ad_vars FTL_TAMC_FLAGS FTL_TAF_FLAGS"
1514 ad_vars="$ad_vars SVD_TAMC_FLAGS SVD_TAF_FLAGS"
1515 for i in $ad_vars ; do
1516 name=$i
1517 t1="t2=\$"`echo $i`
1518 eval $t1
1519 printf "%-20s = " $name >> $MAKEFILE
1520 echo $t2 >> $MAKEFILE
1521 done
1522
1523 echo " Add the source list for AD code generation"
1524 echo >> $MAKEFILE
1525 echo -n "AD_FILES = " >> $MAKEFILE
1526 AD_FILES=`cat ad_files`
1527 for i in $AD_FILES ; do
1528 echo " \\" >> $MAKEFILE
1529 echo -n " $i" >> $MAKEFILE
1530 done
1531 echo >> $MAKEFILE
1532 rm -f ad_files
1533
1534 cat >>$MAKEFILE <<EOF
1535
1536 # ... AD ...
1537 adall: ad_taf
1538 adtaf: ad_taf_output.f
1539 adtamc: ad_tamc_output.f
1540
1541 ad_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1542 cmp ad_config.template AD_CONFIG.h || cat ad_config.template > AD_CONFIG.h
1543 @make \$(F77FILES)
1544 @make \$(AD_FLOW_FILES)
1545 cat \$(AD_FLOW_FILES) \$(AD_FILES) > ad_input_code.f
1546
1547 ad_taf_output.f: ad_input_code.f
1548 \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1549 cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f
1550
1551 adtafonly:
1552 \$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f
1553 cat ad_input_code_ad.f | sed -f adjoint_sed > ad_taf_output.f
1554
1555 ad_taf: ad_taf_output.o \$(OBJFILES)
1556 \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS)
1557
1558 ad_tamc_output.f: ad_input_code.f
1559 \$(TAMC) \$(AD_TAMC_FLAGS) \$(TAMC_EXTRA) ad_input_code.f
1560 cat ad_input_code_ad.f | sed -f adjoint_sed > ad_tamc_output.f
1561
1562 ad_tamc: ad_tamc_output.o \$(OBJFILES)
1563 \$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_tamc_output.o \$(LIBS)
1564
1565
1566 # ... FTL ...
1567 ftlall: ftl_taf
1568 ftltaf: ftl_taf_output.f
1569 ftltamc: ftl_tamc_output.f
1570
1571 ftl_input_code.f: \$(AD_FILES) \$(HEADERFILES)
1572 cmp ftl_config.template AD_CONFIG.h || cat ftl_config.template > AD_CONFIG.h
1573 @make \$(F77FILES)
1574 @make \$(AD_FLOW_FILES)
1575 cat \$(AD_FLOW_FILES) \$(AD_FILES) > ftl_input_code.f
1576
1577 ftl_taf_output.f: ftl_input_code.f
1578 \$(TAF) \$(FTL_TAF_FLAGS) \$(TAF_EXTRA) ftl_input_code.f
1579 cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_taf_output.f
1580
1581 ftl_taf: ftl_taf_output.o \$(OBJFILES)
1582 \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_taf_output.o \$(LIBS)
1583
1584 ftl_tamc_output.f: ftl_input_code.f
1585 \$(TAMC) \$(FTL_TAMC_FLAGS) \$(TAMC_EXTRA) ftl_input_code.f
1586 cat ftl_input_code_ftl.f | sed -f adjoint_sed > ftl_tamc_output.f
1587
1588 ftl_tamc: ftl_tamc_output.o \$(OBJFILES)
1589 \$(LINK) -o ${EXE_FTL} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ftl_tamc_output.o \$(LIBS)
1590
1591
1592 # ... SVD ...
1593 svd: svd_taf
1594 svd_taf_f: svd_taf_output.f
1595
1596 svd_input_code.f: \$(SRCFILES)
1597 cmp svd_config.template AD_CONFIG.h || cat svd_config.template > AD_CONFIG.h
1598 @make \$(F77FILES)
1599 @make \$(AD_FLOW_FILES)
1600 cat \$(AD_FLOW_FILES) \$(AD_FILES) > svd_input_code.f
1601
1602 svd_taf_output.f: svd_input_code.f
1603 \$(TAF) \$(SVD_TAF_FLAGS) \$(TAF_EXTRA) svd_input_code.f
1604 cat svd_input_code_ad.f | sed -f adjoint_sed > svd_taf_output.f
1605
1606 svd_taf: svd_taf_output.o \$(OBJFILES)
1607 \$(LINK) -o ${EXE_SVD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) svd_taf_output.o \$(LIBS)
1608
1609
1610 #=========================================
1611
1612 EOF
1613
1614 if test "x$EXEHOOK" != x ; then
1615 printf "\nexehook:\n\t%s\n" $EXEHOOK >> $MAKEFILE
1616 fi
1617
1618 echo " Making list of \"exceptions\" that need \".p\" files"
1619 for i in $KPPFILES ; do
1620 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
1621 RETVAL=$?
1622 if test "x$RETVAL" != x0 ; then
1623 echo "Error: unable to add file \"$i\" to the exceptions list"
1624 fi
1625 echo "$base.f: $base.p" >> $MAKEFILE
1626 done
1627
1628 echo " Making list of NOOPTFILES"
1629 for i in $NOOPTFILES ; do
1630 base=`echo $i | sed -e 's/\/.*\///g' | sed -e 's/\..*$//g'`
1631 RETVAL=$?
1632 if test "x$RETVAL" != x0 ; then
1633 echo "Error: unable to add file \"$i\" to the exceptions list"
1634 fi
1635 echo "$base.o: $base.f" >> $MAKEFILE
1636 printf "\t\$(FC) \$(FFLAGS) \$(NOOPTFLAGS) -c \$<\n" >> $MAKEFILE
1637 done
1638
1639 echo " Add rules for links"
1640 cat srclinks.tmp >> $MAKEFILE
1641 rm -f srclinks.tmp
1642
1643 echo " Adding makedepend marker"
1644 printf "\n\n# DO NOT DELETE\n" >> $MAKEFILE
1645
1646 printf "\n=== Done ===\n"
1647
1648 # Write the "template" files for the adjoint builds
1649 cat >AD_CONFIG.template <<EOF
1650 C WARNING: This file is automatically generated by genmake2 and
1651 C used by the Makefile rules. Please DO NOT EDIT this file
1652 C unless you are CERTAIN that you know what you are doing.
1653
1654 #undef ALLOW_ADJOINT_RUN
1655 #undef ALLOW_TANGENTLINEAR_RUN
1656 #undef ALLOW_ECCO_OPTIMIZATION
1657 EOF
1658 cat >ad_config.template <<EOF
1659 C WARNING: This file is automatically generated by genmake2 and
1660 C used by the Makefile rules. Please DO NOT EDIT this file
1661 C unless you are CERTAIN that you know what you are doing.
1662
1663 #define ALLOW_ADJOINT_RUN
1664 #undef ALLOW_TANGENTLINEAR_RUN
1665 #undef ALLOW_ECCO_OPTIMIZATION
1666 EOF
1667 cat >ftl_config.template <<EOF
1668 C WARNING: This file is automatically generated by genmake2 and
1669 C used by the Makefile rules. Please DO NOT EDIT this file
1670 C unless you are CERTAIN that you know what you are doing.
1671
1672 #undef ALLOW_ADJOINT_RUN
1673 #define ALLOW_TANGENTLINEAR_RUN
1674 #undef ALLOW_ECCO_OPTIMIZATION
1675 EOF
1676 cat >svd_config.template <<EOF
1677 C WARNING: This file is automatically generated by genmake2 and
1678 C used by the Makefile rules. Please DO NOT EDIT this file
1679 C unless you are CERTAIN that you know what you are doing.
1680
1681 #undef ALLOW_ADJOINT_RUN
1682 #undef ALLOW_TANGENTLINEAR_RUN
1683 #undef ALLOW_ECCO_OPTIMIZATION
1684 EOF
1685 cp AD_CONFIG.template AD_CONFIG.h
1686
1687
1688 # Write the "state" for future records
1689 if test "x$DUMPSTATE" != xf ; then
1690 echo -n "" > genmake_state
1691 for i in $gm_state ; do
1692 t1="t2=\$$i"
1693 eval $t1
1694 echo "$i='$t2'" >> genmake_state
1695 done
1696 fi

  ViewVC Help
Powered by ViewVC 1.1.22