1 |
#!/bin/bash |
#!/bin/sh |
2 |
# |
# |
3 |
# $Header$ |
# $Header$ |
4 |
# |
# |
104 |
CPP="cpp -traditional -P" |
CPP="cpp -traditional -P" |
105 |
fi |
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 |
# look for possible fortran compilers |
118 |
tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95" |
tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95" |
119 |
p_FC= |
p_FC= |
216 |
cat $1 | sed -e 's/#.*$//g' \ |
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} }' \ |
| $AWK 'BEGIN{nn=0;} (NF>0){ for(i=2;i<=NF;i++){nn++; print "PNAME["nn"]="$1"\nDNAME["nn"]="$i} }' \ |
218 |
> ./.pd_tmp |
> ./.pd_tmp |
219 |
source ./.pd_tmp |
. ./.pd_tmp |
220 |
rm -f ./.pd_tmp |
rm -f ./.pd_tmp |
221 |
|
|
222 |
echo -n "PNAME = "${} |
echo -n "PNAME = "${} |
274 |
exit 1 |
exit 1 |
275 |
} |
} |
276 |
|
|
277 |
#eh3 # This is the generic configuration. |
# Build a CPP macro to automate calling C routines from FORTRAN |
278 |
#eh3 set LN = ( 'ln -s' ) |
get_fortran_c_namemangling() { |
279 |
#eh3 set CPP = ( '/lib/cpp -P' ) |
default_nm="#define FC_NAMEMANGLE(X) X ## _" |
280 |
#eh3 set S64 = ( '$(TOOLSDIR)/set64bitConst.sh' ) |
|
281 |
#eh3 set KPP = ( ) |
cat > genmake_test.c <<EOF |
282 |
#eh3 set FC = ( 'f77' ) |
void tcall( char * string ) { tsub( string ); } |
283 |
#eh3 set LINK = $FC |
EOF |
284 |
#eh3 set MAKEDEPEND = ( 'makedepend' ) |
$MAKE genmake_test.o >> genmake_warnings 2>&1 |
285 |
#eh3 set INCLUDES = ( -I. ) |
RETVAL=$? |
286 |
#eh3 set FFLAGS = ( ) |
if test "x$RETVAL" != x0 ; then |
287 |
#eh3 set FOPTIM = ( ) |
FC_NAMEMANGLE=$default_nm |
288 |
#eh3 set CFLAGS = ( ) |
cat <<EOF>> genmake_errors |
289 |
#eh3 set KFLAGS1 = ( ) |
|
290 |
#eh3 set KFLAGS2 = ( ) |
WARNING: C test compile fails |
291 |
#eh3 set LIBS = ( ) |
WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE' |
292 |
#eh3 set KPPFILES = ( ) |
WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here |
293 |
#eh3 if (! $?NOOPTFILES ) set NOOPTFILES = ( ) |
EOF |
294 |
#eh3 if (! $?NOOPTFLAGS ) set NOOPTFLAGS = ( ) |
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 |
# Set defaults here |
403 |
COMMANDL="$0 $@" |
COMMANDL="$0 $@" |
408 |
KPP= |
KPP= |
409 |
FC= |
FC= |
410 |
LINK= |
LINK= |
411 |
DEFINES="-DWORDLENGTH=4" |
# DEFINES="-DWORDLENGTH=4" |
412 |
|
DEFINES= |
413 |
PACKAGES= |
PACKAGES= |
414 |
ENABLE= |
ENABLE= |
415 |
DISABLE= |
DISABLE= |
434 |
HAVE_SYSTEM= |
HAVE_SYSTEM= |
435 |
HAVE_FDATE= |
HAVE_FDATE= |
436 |
FC_NAMEMANGLE= |
FC_NAMEMANGLE= |
437 |
|
HAVE_CLOC= |
438 |
|
|
439 |
MODS= |
MODS= |
440 |
TOOLSDIR= |
TOOLSDIR= |
497 |
gm_local="genmake_local" |
gm_local="genmake_local" |
498 |
for i in . $MODS ; do |
for i in . $MODS ; do |
499 |
if test -r $i/$gm_local ; then |
if test -r $i/$gm_local ; then |
500 |
source $i/$gm_local |
. $i/$gm_local |
501 |
break |
break |
502 |
fi |
fi |
503 |
done |
done |
504 |
echo -n " getting local config information: " |
echo -n " getting local config information: " |
505 |
if test -e $gm_local ; then |
if test -e $gm_local ; then |
506 |
echo "using $gm_local" |
echo "using $gm_local" |
507 |
source $gm_local |
. $gm_local |
508 |
# echo "DISABLE=$DISABLE" |
# echo "DISABLE=$DISABLE" |
509 |
# echo "ENABLE=$ENABLE" |
# echo "ENABLE=$ENABLE" |
510 |
else |
else |
708 |
if test "x$OPTFILE" != xNONE ; then |
if test "x$OPTFILE" != xNONE ; then |
709 |
if test -f "$OPTFILE" -a -r "$OPTFILE" ; then |
if test -f "$OPTFILE" -a -r "$OPTFILE" ; then |
710 |
echo " using OPTFILE=\"$OPTFILE\"" |
echo " using OPTFILE=\"$OPTFILE\"" |
711 |
source "$OPTFILE" |
. "$OPTFILE" |
712 |
RETVAL=$? |
RETVAL=$? |
713 |
if test "x$RETVAL" != x0 ; then |
if test "x$RETVAL" != x0 ; then |
714 |
echo -n "Error: failed to source OPTFILE \"$OPTFILE\"" |
echo -n "Error: failed to source OPTFILE \"$OPTFILE\"" |
735 |
if test "x${AD_OPTFILE}" != xNONE ; then |
if test "x${AD_OPTFILE}" != xNONE ; then |
736 |
if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then |
if test -f "$AD_OPTFILE" -a -r "$AD_OPTFILE" ; then |
737 |
echo " using AD_OPTFILE=\"$AD_OPTFILE\"" |
echo " using AD_OPTFILE=\"$AD_OPTFILE\"" |
738 |
source "$AD_OPTFILE" |
. "$AD_OPTFILE" |
739 |
RETVAL=$? |
RETVAL=$? |
740 |
if test "x$RETVAL" != x0 ; then |
if test "x$RETVAL" != x0 ; then |
741 |
echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\"" |
echo -n "Error: failed to source AD_OPTFILE \"$AD_OPTFILE\"" |
751 |
fi |
fi |
752 |
fi |
fi |
753 |
|
|
754 |
# Check that FC, LINK, CPP, and S64 are defined. If not, complain |
# Check that FC, LINK, CPP, S64, LN, and MAKE are defined. If not, |
755 |
# and abort! |
# either set defaults or complain and abort! |
756 |
if test "x$FC" = x ; then |
if test "x$FC" = x ; then |
757 |
cat <<EOF 1>&2 |
cat <<EOF 1>&2 |
758 |
|
|
769 |
if test "x$CPP" = x ; then |
if test "x$CPP" = x ; then |
770 |
CPP="cpp" |
CPP="cpp" |
771 |
fi |
fi |
772 |
|
if test "x$MAKE" = x ; then |
773 |
|
MAKE="make" |
774 |
|
fi |
775 |
echo "#define A a" | $CPP > test_cpp 2>&1 |
echo "#define A a" | $CPP > test_cpp 2>&1 |
776 |
RETVAL=$? |
RETVAL=$? |
777 |
if test "x$RETVAL" != x0 ; then |
if test "x$RETVAL" != x0 ; then |
791 |
if test "x$MAKEDEPEND" = x ; then |
if test "x$MAKEDEPEND" = x ; then |
792 |
MAKEDEPEND=makedepend |
MAKEDEPEND=makedepend |
793 |
fi |
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" |
printf "\n=== Checking system libraries ===\n" |
849 |
fi |
fi |
850 |
rm -f genmake_tcomp* |
rm -f genmake_tcomp* |
851 |
|
|
852 |
echo -n " The name mangling convention for $FC is... " |
echo -n " Can we call simple C routines (here, \"cloc()\") using $FC... " |
853 |
if test "x$FC_NAMEMANGLE" = x ; then |
check_HAVE_CLOC |
854 |
FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) X ## _" |
if test "x$HAVE_CLOC" != x ; then |
855 |
fi |
echo "yes" |
|
cat > genmake_tcomp.f <<EOF |
|
|
subroutine tcall( string ) |
|
|
character*(*) string |
|
|
call tsub( string ) |
|
|
end |
|
|
EOF |
|
|
$FC $FFLAGS $DEFINES -c genmake_tcomp.f > genmake_tcomp.log 2>&1 |
|
|
RETVAL=$? |
|
|
if test "x$RETVAL" != x0 ; then |
|
|
cat genmake_tcomp.log >> genmake_errors |
|
|
echo |
|
|
echo "WARNING: test compile fails -- please see \"genmake_errors\"" |
|
|
echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'" |
|
|
echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here." |
|
856 |
else |
else |
857 |
tcall=`nm genmake_tcomp.o | grep tcall | cut -d ' ' -f 3` |
echo "no" |
|
RETVAL=$? |
|
|
if test "x$RETVAL" != x0 ; then |
|
|
echo |
|
|
echo "WARNING: The \"nm\" command failed." |
|
|
echo "WARNING: We'll try to use: FC_NAMEMANGLE='$FC_NAMEMANGLE'" |
|
|
echo "WARNING: Please contact <MITgcm-support@mitgcm.org> if you need help here." |
|
|
else |
|
|
t0=`echo $tcall | sed -e 's|_tcall|_ ## X|g'` |
|
|
nmres=`echo $t0 | sed -e 's|tcall_|X ## _|g'` |
|
|
FC_NAMEMANGLE="#define FC_NAMEMANGLE(X) $nmres" |
|
|
echo "'$FC_NAMEMANGLE'" |
|
|
fi |
|
858 |
fi |
fi |
859 |
echo "$FC_NAMEMANGLE" > FC_NAMEMANGLE.h.template |
echo "$FC_NAMEMANGLE" > FC_NAMEMANGLE.h.template |
860 |
cmp FC_NAMEMANGLE.h FC_NAMEMANGLE.h.template > /dev/null 2>&1 |
cmp FC_NAMEMANGLE.h FC_NAMEMANGLE.h.template > /dev/null 2>&1 |
862 |
if test "x$RETVAL" != x0 ; then |
if test "x$RETVAL" != x0 ; then |
863 |
mv -f FC_NAMEMANGLE.h.template FC_NAMEMANGLE.h |
mv -f FC_NAMEMANGLE.h.template FC_NAMEMANGLE.h |
864 |
fi |
fi |
865 |
rm -f genmake_tcomp* |
rm -f genmake_t* |
866 |
|
|
867 |
|
|
868 |
printf "\n=== Setting defaults ===\n" |
printf "\n=== Setting defaults ===\n" |
917 |
# they appear as regular source code |
# they appear as regular source code |
918 |
if test -r $ROOTDIR"/eesupp/src/Makefile" ; then |
if test -r $ROOTDIR"/eesupp/src/Makefile" ; then |
919 |
echo " Making source files in eesupp from templates" |
echo " Making source files in eesupp from templates" |
920 |
$MAKE -C $ROOTDIR"/eesupp/src/" > make_eesupp.errors 2>&1 |
( cd $ROOTDIR"/eesupp/src/" && $MAKE ) > make_eesupp.errors 2>&1 |
921 |
RETVAL=$? |
RETVAL=$? |
922 |
if test "x${RETVAL}" = x0 ; then |
if test "x${RETVAL}" = x0 ; then |
923 |
rm -f make_eesupp.errors |
rm -f make_eesupp.errors |
954 |
echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\"" |
echo "Error: unable to parse package dependencies -- please check PDEPEND=\"$PDEPEND\"" |
955 |
exit 1 |
exit 1 |
956 |
fi |
fi |
957 |
source ./.pd_tmp |
. ./.pd_tmp |
958 |
rm -f ./.pd_tmp |
rm -f ./.pd_tmp |
959 |
|
|
960 |
# Search for default packages. Note that a "$ROOTDIR/pkg/pkg_groups" |
# Search for default packages. Note that a "$ROOTDIR/pkg/pkg_groups" |
1548 |
\$(TAF) \$(AD_TAF_FLAGS) \$(TAF_EXTRA) ad_input_code.f |
\$(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 |
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) |
ad_taf: ad_taf_output.o \$(OBJFILES) |
1556 |
\$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS) |
\$(LINK) -o ${EXE_AD} \$(FFLAGS) \$(FOPTIM) \$(OBJFILES) ad_taf_output.o \$(LIBS) |
1557 |
|
|