| 1 |
#! /usr/bin/env bash |
| 2 |
# |
| 3 |
# |
| 4 |
|
| 5 |
look_for_makedepend() { |
| 6 |
|
| 7 |
# The "original" makedepend is part of the Imake system that is |
| 8 |
# most often distributed with XFree86 or with an XFree86 source |
| 9 |
# package. As a result, many machines (eg. generic Linux) do not |
| 10 |
# have a system-default "makedepend" available. For those |
| 11 |
# systems, we have two fall-back options: |
| 12 |
# |
| 13 |
# 1) a makedepend implementation shipped with the cyrus-imapd |
| 14 |
# package: ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/ |
| 15 |
# |
| 16 |
# 2) a known-buggy xmakedpend shell script |
| 17 |
# |
| 18 |
# So the choices are, in order: |
| 19 |
# |
| 20 |
# 1) use the user-specified program |
| 21 |
# 2) use a system-wide default |
| 22 |
# 3) locally build and use the cyrus implementation |
| 23 |
# 4) fall back to the buggy local xmakedpend script |
| 24 |
# |
| 25 |
if test "x${MAKEDEPEND}" = x ; then |
| 26 |
which makedepend > /dev/null 2>&1 |
| 27 |
RV0=$? |
| 28 |
cat <<EOF >> genmake_tc.f |
| 29 |
program test |
| 30 |
write(*,*) 'test' |
| 31 |
stop |
| 32 |
end |
| 33 |
EOF |
| 34 |
makedepend genmake_tc.f > /dev/null 2>&1 |
| 35 |
RV1=$? |
| 36 |
if test "x${RV0}${RV1}" = x00 ; then |
| 37 |
MAKEDEPEND=makedepend |
| 38 |
else |
| 39 |
echo " a system-default makedepend was not found." |
| 40 |
|
| 41 |
# Try to build the cyrus implementation |
| 42 |
build_cyrus_makedepend |
| 43 |
RETVAL=$? |
| 44 |
if test "x$RETVAL" != x0 ; then |
| 45 |
MAKEDEPEND='$(TOOLSDIR)/xmakedepend' |
| 46 |
fi |
| 47 |
rm -f ./genmake_cy_md |
| 48 |
fi |
| 49 |
else |
| 50 |
# echo "MAKEDEPEND=${MAKEDEPEND}" |
| 51 |
echo "${MAKEDEPEND}" | grep -i cyrus > /dev/null 2>&1 |
| 52 |
RETVAL=$? |
| 53 |
if test x"$RETVAL" = x0 ; then |
| 54 |
build_cyrus_makedepend |
| 55 |
fi |
| 56 |
fi |
| 57 |
rm -f genmake_tc* |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
build_cyrus_makedepend() { |
| 62 |
rm -f ./genmake_cy_md |
| 63 |
( |
| 64 |
cd $ROOTDIR/tools/cyrus-imapd-makedepend \ |
| 65 |
&& ./configure > /dev/null 2>&1 \ |
| 66 |
&& make > /dev/null 2>&1 |
| 67 |
if test -x ./makedepend.exe ; then |
| 68 |
$LN ./makedepend.exe ./makedepend |
| 69 |
fi |
| 70 |
./makedepend ifparser.c > /dev/null 2>&1 \ |
| 71 |
&& echo "true" |
| 72 |
) > ./genmake_cy_md |
| 73 |
grep true ./genmake_cy_md > /dev/null 2>&1 |
| 74 |
RETVAL=$? |
| 75 |
rm -f ./genmake_cy_md |
| 76 |
if test "x$RETVAL" = x0 ; then |
| 77 |
MAKEDEPEND='$(TOOLSDIR)/cyrus-imapd-makedepend/makedepend' |
| 78 |
return 0 |
| 79 |
else |
| 80 |
echo "WARNING: unable to build cyrus-imapd-makedepend" |
| 81 |
return 1 |
| 82 |
fi |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
find_possible_configs() { |
| 87 |
|
| 88 |
tmp1=`uname`"_"`uname -m` |
| 89 |
tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'` |
| 90 |
tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'` |
| 91 |
tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'` |
| 92 |
tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'` |
| 93 |
tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'` |
| 94 |
PLATFORM=$tmp3 |
| 95 |
echo $PLATFORM | grep cygwin > /dev/null 2>&1 && PLATFORM=cygwin_ia32 |
| 96 |
OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")` |
| 97 |
echo " The platform appears to be: $PLATFORM" |
| 98 |
|
| 99 |
echo "test" > test |
| 100 |
ln -s ./test link |
| 101 |
RETVAL=$? |
| 102 |
if test "x${RETVAL}" = x0 ; then |
| 103 |
LN="ln -s" |
| 104 |
else |
| 105 |
echo "Error: \"ln -s\" does not appear to work on this system!" |
| 106 |
echo " For help, please contact <MITgcm-support@mitgcm.org>." |
| 107 |
exit 1 |
| 108 |
fi |
| 109 |
rm -f test link |
| 110 |
|
| 111 |
if test "x$CPP" = x ; then |
| 112 |
CPP="cpp -traditional -P" |
| 113 |
fi |
| 114 |
|
| 115 |
look_for_makedepend |
| 116 |
|
| 117 |
#================================================================ |
| 118 |
# look for possible C compilers |
| 119 |
tmp="$MITGCM_CC $CC gcc c89 cc c99 mpicc" |
| 120 |
p_CC= |
| 121 |
for c in $tmp ; do |
| 122 |
rm -f ./genmake_hello.c ./genmake_hello |
| 123 |
cat >> genmake_hello.c << EOF |
| 124 |
#include <stdio.h> |
| 125 |
int main(int argc, char **argv) { |
| 126 |
printf("Hello!\n"); |
| 127 |
return 0; |
| 128 |
} |
| 129 |
EOF |
| 130 |
$c -o genmake_hello genmake_hello.c > /dev/null 2>&1 |
| 131 |
RETVAL=$? |
| 132 |
if test "x${RETVAL}" = x0 ; then |
| 133 |
p_CC="$p_CC $c" |
| 134 |
fi |
| 135 |
done |
| 136 |
rm -f ./genmake_hello.c ./genmake_hello |
| 137 |
if test "x${p_CC}" = x ; then |
| 138 |
cat 1>&2 <<EOF |
| 139 |
|
| 140 |
Error: No C compilers were found in your path. Please specify one using: |
| 141 |
|
| 142 |
1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"), |
| 143 |
2) the CC or MITGCM_CC environment variables. |
| 144 |
|
| 145 |
EOF |
| 146 |
exit 1 |
| 147 |
else |
| 148 |
echo " The possible C compilers found in your path are:" |
| 149 |
echo " "$p_CC |
| 150 |
if test "x$CC" = x ; then |
| 151 |
CC=`echo $p_CC | $AWK '{print $1}'` |
| 152 |
echo " Setting C compiler to: "$CC |
| 153 |
fi |
| 154 |
fi |
| 155 |
|
| 156 |
#================================================================ |
| 157 |
# look for possible FORTRAN compilers |
| 158 |
tmp="$MITGCM_FC $FC efc g77 f77 pgf77 pgf95 ifc f90 f95 mpif77 mpf77 mpxlf95" |
| 159 |
p_FC= |
| 160 |
for c in $tmp ; do |
| 161 |
rm -f ./hello.f ./hello |
| 162 |
cat >> hello.f <<EOF |
| 163 |
program hello |
| 164 |
do i=1,3 |
| 165 |
print *, 'hello world : ', i |
| 166 |
enddo |
| 167 |
end |
| 168 |
EOF |
| 169 |
$c -o hello hello.f > /dev/null 2>&1 |
| 170 |
RETVAL=$? |
| 171 |
if test "x${RETVAL}" = x0 ; then |
| 172 |
p_FC="$p_FC $c" |
| 173 |
fi |
| 174 |
done |
| 175 |
rm -f ./hello.f ./hello |
| 176 |
if test "x${p_FC}" = x ; then |
| 177 |
cat 1>&2 <<EOF |
| 178 |
|
| 179 |
Error: No Fortran compilers were found in your path. Please specify one using: |
| 180 |
|
| 181 |
1) an "optfile" on (eg. "-optfile=path/to/OPTFILE"), |
| 182 |
2) a command-line option (eg. "-fc NAME"), or |
| 183 |
3) the FC or MITGCM_FC environment variables. |
| 184 |
|
| 185 |
EOF |
| 186 |
exit 1 |
| 187 |
else |
| 188 |
echo " The possible FORTRAN compilers found in your path are:" |
| 189 |
echo " "$p_FC |
| 190 |
if test "x$FC" = x ; then |
| 191 |
FC=`echo $p_FC | $AWK '{print $1}'` |
| 192 |
echo " Setting FORTRAN compiler to: "$FC |
| 193 |
fi |
| 194 |
fi |
| 195 |
|
| 196 |
if test "x$OPTFILE" = x ; then |
| 197 |
OPTFILE=$ROOTDIR"/tools/build_options/"$PLATFORM"_"$FC |
| 198 |
if test ! -r $OPTFILE ; then |
| 199 |
echo " I looked for the file "$OPTFILE" but did not find it" |
| 200 |
fi |
| 201 |
fi |
| 202 |
if test "x$OPTFILE" = x ; then |
| 203 |
cat 1>&2 <<EOF |
| 204 |
|
| 205 |
Error: No options file was found in: $ROOTDIR/tools/build_options/ |
| 206 |
that matches this platform ("$PLATFORM") and the compilers found in |
| 207 |
your path. Please specify an "optfile" using: |
| 208 |
|
| 209 |
1) the command line (eg. "-optfile=path/to/OPTFILE"), or |
| 210 |
2) the MITGCM_OF environment variable. |
| 211 |
|
| 212 |
If you need help, please contact the developers at <MITgcm-support@mitgcm.org>. |
| 213 |
|
| 214 |
EOF |
| 215 |
exit 1 |
| 216 |
fi |
| 217 |
|
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
AWK=awk |
| 222 |
|
| 223 |
if test "x${ROOTDIR}" = x ; then |
| 224 |
tmp=`echo $PWD | sed -e 's/\// /g' | awk '{print $NR}'` |
| 225 |
if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesup -a -d ../pkg ; then |
| 226 |
ROOTDIR=".." |
| 227 |
else |
| 228 |
for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do |
| 229 |
if test -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ; then |
| 230 |
ROOTDIR=$d |
| 231 |
printf "Warning: ROOTDIR unspecified but there appears to be" |
| 232 |
echo " a copy of MITgcm at \"$ROOTDIR\"" |
| 233 |
break |
| 234 |
fi |
| 235 |
done |
| 236 |
fi |
| 237 |
fi |
| 238 |
|
| 239 |
tmp1=`uname`"_"`uname -m` |
| 240 |
tmp2=`echo $tmp1 | sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'` |
| 241 |
tmp3=`echo $tmp2 | sed -e 's/power macintosh/ppc/'` |
| 242 |
tmp1=`echo $tmp3 | sed -e 's|x86_64|amd64|'` |
| 243 |
tmp2=`echo $tmp1 | sed -e 's/i[3-6]86/ia32/' | sed -e 's/athlon/ia32/'` |
| 244 |
tmp3=`echo $tmp2 | sed -e 's/cray sv1/craysv1/'` |
| 245 |
PLATFORM=$tmp3 |
| 246 |
echo $PLATFORM | grep cygwin > /dev/null 2>&1 && PLATFORM=cygwin_ia32 |
| 247 |
echo " The platform appears to be: $PLATFORM" |
| 248 |
echo " And possible optfiles are: " |
| 249 |
OFLIST=`(cd $ROOTDIR/tools/build_options; ls | grep "^$PLATFORM")` |
| 250 |
for i in $OFLIST ; do |
| 251 |
echo " $i" |
| 252 |
done |
| 253 |
|
| 254 |
find_possible_configs |
| 255 |
|
| 256 |
echo |
| 257 |
echo " The default optfile is: "$PLATFORM"_"$FC |