00001 _check_cc () {
00002 local _prog=$1 ;
00003 local _args= ;
00004 local _res=1 ;
00005 shift ;
00006 _args="$*" ;
00007 echo -n "Checking if $_prog $_args can create an executable from .c file ... ">&2 ;
00008 echo "int main (int argc, char** argv) { return 0; }" > .___t.c && $_prog $_args -o .___t .___t.c >&2 && test -x .___t && ./.___t && _res=0 ;
00009 rm -f .___t .___t.c 2>&1 1>/dev/null ;
00010 if test $_res = 0 ; then
00011 echo "it can." >&2 ;
00012 else
00013 echo "it can't">&2 ;
00014 fi ;
00015 return $_res ;
00016 };
00017
00018 _check_cxx () {
00019 local _prog=$1 ;
00020 local _args= ;
00021 local _res=1 ;
00022 shift ;
00023 _args="$*" ;
00024 echo -n "Checking if $_prog $_args can create an executable from .cxx file ... ">&2 ;
00025 echo "int main (int argc, char** argv) { return 0; }" > .___t.cxx && $_prog $_args -o .___t .___t.cxx >&2 && test -x .___t && ./.___t && _res=0 ;
00026 rm -f .___t .___t.cxx 2>&1 1>/dev/null ;
00027 if test $_res = 0 ; then
00028 echo "it can." >&2 ;
00029 else
00030 echo "it can't">&2 ;
00031 fi ;
00032 return $_res ;
00033 };
00034
00035 _check_fc () {
00036 local _prog=$1 ;
00037 local _args= ;
00038 local _res=1 ;
00039 shift ;
00040 _args="$*" ;
00041 echo -n "Checking if $_prog $_args can create an executable from .f file ... " >&2 ;
00042 ( echo " " " " " " " " " " " " "program t" ;
00043 echo " " " " " " " " " " " " "implicit none" ;
00044 echo " " " " " " " " " " " " "end" ) > .___t.f && $_prog $_args -o .___t .___t.f >&2 && test -x .___t && ./.___t && _res=0 ;
00045 rm -f .___t .___t.f 2>&1 1>/dev/null ;
00046 if test $_res = 0 ; then
00047 echo "it can." >&2 ;
00048 else
00049 echo "it can't">&2 ;
00050 fi ;
00051 return $_res ;
00052 };
00053
00054
00055
00056 lcg_platform () {
00057
00058 local _cc= ;
00059 local _cc_found=0 ;
00060 local _fc= ;
00061 local _fc_found=0 ;
00062 local _cxx= ;
00063 local _cxx_found=0 ;
00064
00065 LCG_PLATFORM= ;
00066
00067 LCG_CC_VERSION= ;
00068
00069 if test "x${CC}" = "x" ; then
00070 echo "INFO: CC variable is not set." >&2 ;
00071 _cc_file= ;
00072 for _cc in gcc cc ; do
00073 _cc_file=`which ${_cc}` ;
00074 if test "x${_cc_file}" != "x" && test -x ${_cc_file} && _check_cc ${_cc_file} ${CFLAGS} ; then
00075 CC=${_cc_file} ;
00076 break ;
00077 fi ;
00078 done ;
00079 else
00080 echo "WARNING: CC='${CC}', hopefully, you know what you're doing." >&2 ;
00081 _prog=`echo ${CC} | sed 's, .*$,,;'` ;
00082 _args="`echo ${CC} | sed 's,^[^ ][^ ]*\(.*\)$,\1,;'`" ;
00083 _cc=`echo $_prog | sed 's,^.*/\([^\/][^\/]*\)$,\1,;'` ;
00084 echo -n "Trying $_prog ... " >&2 ;
00085 _prog_file=`which ${_prog} 2>/dev/null` ;
00086 if test "x$_prog_file" != "x" && test -x $_prog_file ; then
00087 echo $_prog_file >&2 ;
00088 if ! _check_cc $_prog_file $_args ${CFLAGS} ; then
00089 echo "ERROR: $CC can't create an executable.">&2 ;
00090 CC= ;
00091 else
00092 CC="`echo $_prog_file $_args`" ;
00093 fi ;
00094 else
00095 echo "not found" >&2 ;
00096 CC= ;
00097 fi ;
00098 fi ;
00099
00100 if test "x${CC}" = "x" ; then
00101 echo "ERROR: Can't find C compiler. Setting CC and PATH variables can help." >&2 ;
00102 _cc_found=0 ;
00103 else
00104 _cc_found=1 ;
00105 fi ;
00106
00107 if test "x${FC}" = "x" ; then
00108 echo "INFO: FC variable is not set." >&2 ;
00109 _fc_file= ;
00110 for _fc in g77 gfortran f77 ; do
00111 _fc_file=`which ${_fc}` ;
00112 if test "x${_fc_file}" != "x" && test -x ${_fc_file} && _check_fc ${_fc_file} ${FFLAGS} ; then
00113 FC_=${_fc_file} ;
00114 break ;
00115 fi ;
00116 done ;
00117 else
00118 echo "WARNING: FC='${FC}', hopefully, you know what you're doing." >&2 ;
00119 _prog=`echo ${FC} | sed 's, .*$,,;'` ;
00120 _args="`echo ${FC} | sed 's,^[^ ][^ ]*\(.*\)$,\1,;'`" ;
00121 _fc=`echo $_prog | sed 's,^.*/\([^\/][^\/]*\)$,\1,;'` ;
00122 echo -n "Trying $_prog ... " >&2 ;
00123 _prog_file=`which ${_prog} 2>/dev/null` ;
00124 if test "x$_prog_file" != "x" && test -x $_prog_file ; then
00125 echo $_prog_file >&2 ;
00126 if ! _check_fc $_prog_file $_args ${FFLAGS} ; then
00127 echo "ERROR: $FC can't create an executable.">&2 ;
00128 FC= ;
00129 FC_= ;
00130 else
00131 FC="`echo $_prog_file $_args`" ;
00132 FC_=${FC} ;
00133 fi ;
00134 else
00135 echo "not found" >&2 ;
00136 FC= ;
00137 FC_= ;
00138 fi ;
00139 fi ;
00140
00141 if test "x${FC_}" = "x" ; then
00142 echo "ERROR: Can't find Fortran compiler. Setting FC and PATH variables can help." >&2 ;
00143 _fc_found=0 ;
00144 else
00145 _fc_found=1 ;
00146 fi ;
00147
00148 if test "x${CXX}" = "x" ; then
00149 echo "INFO: CXX variable is not set." >&2 ;
00150 _cxx_file= ;
00151 for _cxx in g++ c++ ; do
00152 _cxx_file=`which ${_cxx}` ;
00153 if test "x${_cxx_file}" != "x" && test -x ${_cxx_file} && _check_cxx ${_cxx_file} ${CXXFLAGS} ; then
00154 CXX=${_cxx_file} ;
00155 break ;
00156 fi ;
00157 done ;
00158 else
00159 echo "WARNING: CXX='${CXX}', hopefully, you know what you're doing." >&2 ;
00160 _prog=`echo ${CXX} | sed 's, .*$,,;'` ;
00161 _args="`echo ${CXX} | sed 's,^[^ ][^ ]*\(.*\)$,\1,;'`" ;
00162 _cxx=`echo $_prog | sed 's,^.*/\([^\/][^\/]*\)$,\1,;'` ;
00163 echo -n "Trying $_prog ... " >&2 ;
00164 _prog_file=`which ${_prog} 2>/dev/null` ;
00165 if test "x$_prog_file" != "x" && test -x $_prog_file ; then
00166 echo $_prog_file >&2 ;
00167 if ! _check_cxx $_prog_file $_args ${CXXFLAGS} ; then
00168 echo "ERROR: $CXX can't create an executable.">&2 ;
00169 CXX= ;
00170 else
00171 CXX="`echo $_prog_file $_args`" ;
00172 fi ;
00173 else
00174 echo "not found" >&2 ;
00175 CXX= ;
00176 fi ;
00177 fi ;
00178
00179 if test "x${CXX}" = "x" ; then
00180 echo "ERROR: Can't find C++ compiler. Setting CXX and PATH variables can help." >&2 ;
00181 _cxx_found=0 ;
00182 else
00183 _cxx_found=1 ;
00184 fi ;
00185
00186 is_gcc() {
00187 local _cc="$*" ;
00188 if test "x`${_cc} --version | grep -i gcc`" != "x" ; then
00189 return 0 ;
00190 else
00191 return 1 ;
00192 fi ;
00193 };
00194
00195 # gcc version
00196 if test "x${CC}" != "x" && is_gcc ${CC} ; then
00197 CC_VERSION=`${CC} --version | head -n 1 | sed "s,^.*(GCC)[ ]*,,;s, .*$,,;"` ;
00198 CC_MAJOR=`echo ${CC_VERSION} | sed "s,\..*$,,;"` ;
00199 CC_MINOR=`echo ${CC_VERSION} | sed "s,^[ ]*[0-9][0-9]*\.,,;"` ;
00200 if test "x${CC_MAJOR}" = "x3" && test "x${CC_MINOR}" = "x2.3" ; then
00201 LCG_CC_VERSION=gcc323 ;
00202 elif test "x${CC_MAJOR}" = "x4" && test "x${CC_MINOR}" = "x0.1" ; then
00203 LCG_CC_VERSION=gcc401 ;
00204 else
00205 LCG_CC_VERSION=gcc${CC_MAJOR}`echo ${CC_MINOR} | sed 's,\..*$,,g;'` ;
00206 fi ;
00207 if test "x$CFLAGS" = "x" ;
00208 then CFLAGS="-O2 -fPIC" ;
00209 else
00210 echo "WARNING: retaining user's CFLAGS='$CFLAGS'">&2 ;
00211 fi ;
00212 if test "x$FCFLAGS" = "x" ; then
00213 if test "x$FFLAGS" != "x" ; then
00214 FCFLAGS="$FFLAGS" ;
00215 echo "WARNING: retaining user's FFLAGS='$FFLAGS'">&2 ;
00216 else
00217 FCFLAGS="-O2 -fPIC -Wuninitialized" ;
00218 fi ;
00219 else
00220 echo "WARNING: retaining user's FCFLAGS='$FCFLAGS'">&2 ;
00221 fi ;
00222 FFLAGS="$FCFLAGS" ;
00223 echo "Note: Set default FFLAGS=FCFLAGS='$FCFLAGS'">&2 ;
00224 if test "x$CXXFLAGS" = "x" ; then
00225 CXXFLAGS="-O2 -fPIC -Wall" ;
00226 else
00227 echo "WARNING: retaining user's CXXFLAGS='$CXXFLAGS'">&2 ;
00228 fi ;
00229 else
00230 LCG_CC_VERSION="${_cc}" ;
00231 echo "WARNING: gcc is not used. Retaining user's CFLAGS, CXXFLAGS, FFLAGS." >&2 ;
00232 fi ;
00233
00234 # distribution
00235 if test "x${LCG_OPSYS}" = "x" ; then
00236 if test -s /etc/redhat-release ; then
00237 _release=`cat /etc/redhat-release` ;
00238 _release_num=`echo ${_release} | sed 's,^.*release[ ][ ]*\([0-9\.][0-9\.]*\) .*$,\1,'` ;
00239 if test "x`echo ${_release} | sed 's,SLC,,;'`" != "x${_release}" ; then
00240 LCG_OPSYS=slc`echo ${_release_num} | sed 's,\([0-9][0-9]*\)\..*$,\1,'`;
00241 elif test "x`echo ${_release} | sed 's,[Rr]ed[Hh]at,,'`" != "x${_release}" ; then
00242 LCG_OPSYS=rh`echo ${_release_num} | sed 's,\.,,g'` ;
00243 else
00244 LCG_OPSYS=Linux ;
00245 fi ;
00246 else
00247 LCG_OPSYS=`uname -s` ;
00248 if test "x${LCG_OPSYS}" = "xDarwin" ; then
00249 Darwin_kernel=`uname -r` ;
00250 if test "x$Darwin_kernel" = "x9.7.0" ; then
00251 osx_version=105 ;
00252 else
00253 osx_version="" ;
00254 fi ;
00255 LCG_OPSYS="osx${osx_version}" ;
00256 fi ;
00257 fi ;
00258 else
00259 echo "WARNING: LCG_OPSYS was set to ${LCG_OPSYS}. Leaving it intact." >&2 ;
00260 fi ;
00261
00262
00263 # arhitecture
00264 if test "x${MACHINE_ARCH}" = "x" ; then
00265 MACHINE_ARCH=`uname -m` ;
00266 fi ;
00267 if test "x`echo ${MACHINE_ARCH} | sed 's,^i.86$,,;'`" != "x${MACHINE_ARCH}" ; then
00268 LCG_MACHINE_ARCH=ia32 ;
00269 elif test ${MACHINE_ARCH} = x86_64 ; then
00270 LCG_MACHINE_ARCH=amd64 ;
00271 else
00272 LCG_MACHINE_ARCH=${MACHINE_ARCH} ;
00273 echo "WARNING: ${LCG_MACHINE_ARCH}: non-x86 machine" >&2 ;
00274 fi ;
00275
00276 if test "x${LCG_OPSYS}" = "xslc5" ; then
00277 # special case for SLC 5
00278 LCG_MACHINE_ARCH=`uname -m`
00279 LCG_PLATFORM=${LCG_MACHINE_ARCH}-${LCG_OPSYS}-${LCG_CC_VERSION}-opt
00280 else
00281 LCG_PLATFORM=${LCG_OPSYS}_${LCG_MACHINE_ARCH}_${LCG_CC_VERSION}
00282 fi
00283
00284 if test "x${FC}" = "x" ; then
00285 echo "INFO: FC variable is not set." >&2 ;
00286 _fc_file= ;
00287 if test "x${CC}" != "x" && is_gcc ${CC} && test "x${CC_MAJOR}" = "x4" ; then
00288 _fc_list="gfortran g77 f77" ;
00289 else
00290 _fc_list="g77 gfortran f77" ;
00291 fi ;
00292 for _fc in $_fc_list ; do
00293 _fc_file=`which ${_fc}` ;
00294 if test "x${_fc_file}" != "x" && test -x ${_fc_file} && _check_fc ${_fc_file} ${FFLAGS} ; then
00295 FC=${_fc_file} ;
00296 break ;
00297 fi ;
00298 done ;
00299 else
00300 echo "WARNING: FC='${FC}', hopefully, you know what you're doing." >&2 ;
00301 _prog=`echo ${FC} | sed 's, .*$,,;'` ;
00302 _args="`echo ${FC} | sed 's,^[^ ][^ ]*\(.*\)$,\1,;'`" ;
00303 _fc=`echo $_prog | sed 's,^.*/\([^\/][^\/]*\)$,\1,;'` ;
00304 echo -n "Trying $_prog ... " >&2 ;
00305 _prog_file=`which ${_prog} 2>/dev/null` ;
00306 if test "x$_prog_file" != "x" && test -x $_prog_file ; then
00307 echo $_prog_file >&2 ;
00308 if ! _check_fc $_prog_file $_args ${FFLAGS} ; then
00309 echo "ERROR: $FC can't create an executable.">&2 ;
00310 FC= ;
00311 else
00312 FC="$_prog_file $_args " ;
00313 fi ;
00314 else
00315 echo "not found" >&2 ;
00316 FC= ;
00317 fi ;
00318 fi ;
00319
00320 if test "x${FC}" = "x" ; then
00321 echo "ERROR: Can't find Fortran compiler. Setting FC and PATH variables can help." >&2 ;
00322 _fc_found=0 ;
00323 else
00324 _fc_found=1 ;
00325 fi ;
00326
00327 if test "x${CXX}" = "x" ; then
00328 echo "INFO: CXX variable is not set." >&2 ;
00329 _cxx_file= ;
00330 for _cxx in g++ c++ ; do
00331 _cxx_file=`which ${_cxx}` ;
00332 if test "x${_cxx_file}" != "x" && test -x ${_cxx_file} && _check_cxx ${_cxx_file} ${CXXFLAGS} ; then
00333 CXX=${_cxx_file} ;
00334 break ;
00335 fi ;
00336 done ;
00337 else
00338 echo "WARNING: CXX='${CXX}', hopefully, you know what you're doing." >&2 ;
00339 _prog=`echo ${CXX} | sed 's, .*$,,;'` ;
00340 _args="`echo ${CXX} | sed 's,^[^ ][^ ]*\(.*\)$,\1,;'`" ;
00341 _cxx=`echo $_prog | sed 's,^.*/\([^\/][^\/]*\)$,\1,;'` ;
00342 echo -n "Trying $_prog ... " >&2 ;
00343 _prog_file=`which ${_prog} 2>/dev/null` ;
00344 if test "x$_prog_file" != "x" && test -x $_prog_file ; then
00345 echo $_prog_file >&2 ;
00346 if ! _check_cxx $_prog_file $_args ${CXXFLAGS} ; then
00347 echo "ERROR: $CXX can't create an executable.">&2 ;
00348 CXX= ;
00349 else
00350 CXX="$_prog_file $_args " ;
00351 fi ;
00352 else
00353 echo "not found" >&2 ;
00354 CXX= ;
00355 fi ;
00356 fi ;
00357
00358 if test "x${CXX}" = "x" ; then
00359 echo "ERROR: Can't find C++ compiler. Setting CXX and PATH variables can help." >&2 ;
00360 _cxx_found=0 ;
00361 else
00362 _cxx_found=1 ;
00363 fi ;
00364
00365
00366 if test $_cc_found = 1 && test $_fc_found = 1 && test $_cxx_found = 1 ; then
00367 return 0 ;
00368 else
00369 return 1 ;
00370 fi ;
00371 }
00372