30d9d78
--- trunk/configure	2010/05/13 12:58:02	33500
30d9d78
+++ trunk/configure	2010/05/17 16:43:27	33534
30d9d78
@@ -338,19 +338,26 @@
30d9d78
 
30d9d78
     # Save arguments in logical names
30d9d78
     chklib64=$1
30d9d78
-    logmsg "Checking if $chklib64 is a 64bit library"
30d9d78
+    logmsg "Checking if $chklib64 is a 64-bit library"
30d9d78
     if [ "x`basename $chklib64 .a`" != "x`basename $chklib64`" ]; then
30d9d78
         # we have an archive .a file
30d9d78
         logmsg " objdump -a $chklib64 | grep 'x86-64'"
30d9d78
-        objdump -a $chklib64 | grep 'x86-64' > /dev/null 2>& 1
30d9d78
-        ret=$?
30d9d78
+        if objdump -a $chklib64 | grep 'x86-64' > /dev/null 2>& 1 ; then
30d9d78
+            ret=1
30d9d78
+        fi
30d9d78
     else
30d9d78
-        logmsg " file -L $chklib64 | grep '64-bit'"
30d9d78
-        file -L $chklib64 | grep '64-bit' > /dev/null 2>& 1
30d9d78
-        ret=$?
30d9d78
+        if file -L $chklib64 | grep 'ASCII' > /dev/null 2>& 1 ; then
30d9d78
+            check_link $chklib64
30d9d78
+            ret=$link_result
30d9d78
+        else
30d9d78
+            logmsg " file -L $chklib64 | grep '64-bit'"
30d9d78
+            if file -L $chklib64 | grep '64-bit' > /dev/null 2>& 1 ; then
30d9d78
+                ret=1
30d9d78
+            fi
30d9d78
+        fi
30d9d78
     fi
30d9d78
     logmsg " result: $ret"
30d9d78
-    if test $ret -eq 0 ; then
30d9d78
+    if test $ret -eq 1 ; then
30d9d78
         is_lib64=1
30d9d78
         logmsg " is a 64bit library"
30d9d78
     fi
30d9d78
@@ -637,6 +644,79 @@
30d9d78
 }
30d9d78
 
30d9d78
 #_____________________________________________________________________
30d9d78
+check_link() {
30d9d78
+    # This function will try to link a specific library [$1] in an
30d9d78
+    # optional directory [$2] and test, optionally, for a specified
30d9d78
+    # symbol [$3].
30d9d78
+    # The result of the check is stored in link_result, 1 if true,
30d9d78
+    # 0 otherwise, which should be immediately copied, since the variable
30d9d78
+    # will be overwritten at next invocation of this function.
30d9d78
+
30d9d78
+    # Assert that we got enough arguments
30d9d78
+    if test $# -lt 1 ; then
30d9d78
+        echo "check_link: need at least one argument"
30d9d78
+        link_result=0
30d9d78
+        return 1
30d9d78
+    fi
30d9d78
+
30d9d78
+    # save arguments in logical names
30d9d78
+    linklib="$1"; shift
30d9d78
+    linkdir=""
30d9d78
+    if test $# -ge 1 ; then
30d9d78
+        linkdir="$1"; shift
30d9d78
+    fi
30d9d78
+    linksymbol=""
30d9d78
+    if test $# -ge 1 ; then
30d9d78
+        linksymbol="$1"
30d9d78
+    fi
30d9d78
+
30d9d78
+    if test "x$linksymbol" = "x" ; then
30d9d78
+       if test "x$linkdir" = "x" ; then
30d9d78
+          logmsg " trying to link against $linklib"
30d9d78
+       else
30d9d78
+          logmsg " trying to link against $linkdir $linklib"
30d9d78
+       fi
30d9d78
+       cat <<EOF > conftest.mk
30d9d78
+include config/Makefile.${arch}
30d9d78
+conftest: conftest.c
30d9d78
+	\$(CC) \$(CFLAGS) \$(LDFLAGS) $linkdir $linklib \$< -o \$@
30d9d78
+
30d9d78
+conftest.c:
30d9d78
+	echo "int main() { return 0; }" > \$@
30d9d78
+EOF
30d9d78
+    else
30d9d78
+       if test "x$linkdir" = "x" ; then
30d9d78
+           logmsg " trying to resolve symbol $linksymbol in $linklib"
30d9d78
+       else
30d9d78
+           logmsg " trying to resolve symbol $linksymbol in $linkdir $linklib"
30d9d78
+       fi
30d9d78
+       cat <<EOF > conftest.mk
30d9d78
+include config/Makefile.${arch}
30d9d78
+conftest:conftest.c
30d9d78
+	\$(CC) \$(CFLAGS) \$(LDFLAGS) $linkdir $linklib \$< -o \$@
30d9d78
+
30d9d78
+conftest.c:
30d9d78
+	echo "extern int $linksymbol (); " > \$@
30d9d78
+	echo "int main() { $linksymbol (); return 0; }" >> \$@
30d9d78
+EOF
30d9d78
+    fi
30d9d78
+    $gnumake -f conftest.mk >> $logfile 2>&1
30d9d78
+    if test $? -eq 0 ; then
30d9d78
+        link_result=1
30d9d78
+        logmsg " Link OK"
30d9d78
+    else
30d9d78
+        link_result=0
30d9d78
+        logmsg " Failed code was"
30d9d78
+        cat conftest.mk >> $logfile
30d9d78
+    fi
30d9d78
+    rm -rf conftest.c conftest.mk conftest
30d9d78
+
30d9d78
+    unset linklib
30d9d78
+    unset linkdir
30d9d78
+    unset linksymbol
30d9d78
+}
30d9d78
+
30d9d78
+#_____________________________________________________________________
30d9d78
 check_symbol() {
30d9d78
     # This function will try to locate a symbol [$1] in a specific
30d9d78
     # library [$2] and in a given directory [$3].
30d9d78
@@ -658,6 +738,9 @@
30d9d78
 
30d9d78
     if test "x$symbollib" = "x" ; then
30d9d78
         found_symbol=0
30d9d78
+        unset symbol
30d9d78
+        unset symbollib
30d9d78
+        unset symboldir
30d9d78
         return 1
30d9d78
     fi
30d9d78
 
30d9d78
@@ -721,6 +804,9 @@
30d9d78
     if test "x$symbolfile" = "x" || test ! -r $symbolfile ; then
30d9d78
        found_symbol=0
30d9d78
        logmsg " Symbol not found"
30d9d78
+       unset symbol
30d9d78
+       unset symbollib
30d9d78
+       unset symboldir
30d9d78
        return 1
30d9d78
     fi
30d9d78
 
30d9d78
@@ -732,29 +818,10 @@
30d9d78
     else
30d9d78
         nm $symbolfile 2>&1 | grep "no symbols" > /dev/null 2>&1
30d9d78
         if test $? -eq 0 ; then
30d9d78
-            logmsg " $symbolfile is stripped, trying a link"
30d9d78
-            # stripped library - only safe test is to link against the
30d9d78
-            # library!  However, we do not know what compiler to use
30d9d78
-            # so we can not do the test.  Assume the symbol is in
30d9d78
-            cat <<EOF > conftest.mk
30d9d78
-include config/Makefile.${arch}
30d9d78
-conftest:conftest.c $symbolfile
30d9d78
-	\$(CC) \$(CFLAGS) \$(LDFLAGS) $symbolfile \$< -o \$@
30d9d78
-
30d9d78
-conftest.c:
30d9d78
-	echo "extern int $symbol (); " > \$@
30d9d78
-	echo "int main() { $symbol (); return 0; }" >> \$@
30d9d78
-EOF
30d9d78
-            $gnumake -f conftest.mk >> $logfile 2>&1
30d9d78
-            if test $? -eq 0 ; then
30d9d78
-                found_symbol=1
30d9d78
-                logmsg " Link OK"
30d9d78
-            else
30d9d78
-                found_symbol=0
30d9d78
-                logmsg " Failed code was"
30d9d78
-                cat conftest.mk >> $logfile
30d9d78
-            fi
30d9d78
-            rm -rf conftest.c conftest.mk conftest
30d9d78
+            logmsg " $symbolfile is stripped, trying to link"
30d9d78
+            # stripped library - only safe test is to link against the library
30d9d78
+            check_link $symbolfile "" $symbol
30d9d78
+            found_symbol=$link_result
30d9d78
         else
30d9d78
             found_symbol=0
30d9d78
         fi
30d9d78
@@ -764,6 +831,10 @@
30d9d78
     else
30d9d78
         result "no"
30d9d78
     fi
30d9d78
+
30d9d78
+    unset symbol
30d9d78
+    unset symbollib
30d9d78
+    unset symboldir
30d9d78
 }
30d9d78
 
30d9d78
 #_____________________________________________________________________
30d9d78
@@ -2641,19 +2712,12 @@
30d9d78
         case $platform in
30d9d78
            linux)      shiftlib="$shiftlib -lnsl"
30d9d78
                 for i in "" -ladns ; do
30d9d78
-                    echo "extern rfio_fchmod(); int main() { rfio_fchmod(); return 0; }" > conftest.c
30d9d78
-                    logmsg " Checking if we can link against $shiflib"
30d9d78
-                    logmsg " gcc conftest.c $shiftlibdir $shiftlib $i -o conftest"
30d9d78
-                    gcc conftest.c $shiftlibdir $shiftlib $i -o conftest >> $logfile 2>&1
30d9d78
-                    if test $? -eq 0 ; then
30d9d78
+                    check_link "$shiftlib $i" $shiftlibdir rfio_fchmod
30d9d78
+                    if test $link_result -eq 1 ; then
30d9d78
                         shiftlib="$shiftlib $i" ;
30d9d78
                         break ;
30d9d78
-                    else
30d9d78
-                        logmsg " Failed program was:"
30d9d78
-                        cat conftest.c >> $logfile
30d9d78
                     fi
30d9d78
                 done
30d9d78
-                rm -f conftest.c conftest
30d9d78
                 ;;
30d9d78
            solaris)    shiftlib="$shiftlib -lposix4" ;;
30d9d78
            win32)      shiftincdir="$shiftincdir $shiftincdir/../win32"
30d9d78
@@ -2730,19 +2794,12 @@
30d9d78
         case $platform in
30d9d78
            linux)      castorlib="$castorlib -lnsl"
30d9d78
                 for i in "" -ladns ; do
30d9d78
-                    echo "extern rfio_fchmod(); int main() { rfio_fchmod(); return 0; }" > conftest.c
30d9d78
-                    logmsg " Checking if we can link against $castorlib"
30d9d78
-                    logmsg " gcc conftest.c $castorlibdir $castorlib $i -o conftest"
30d9d78
-                    gcc conftest.c $castorlibdir $castorlib $i -o conftest >> $logfile 2>&1
30d9d78
-                    if test $? -eq 0 ; then
30d9d78
+                    check_link "$shiftlib $i" $shiftlibdir rfio_fchmod
30d9d78
+                    if test $link_result -eq 1 ; then
30d9d78
                         castorlib="$castorlib $i" ;
30d9d78
                         break ;
30d9d78
-                    else
30d9d78
-                        logmsg " Failed program was:"
30d9d78
-                        cat conftest.c >> $logfile
30d9d78
                     fi
30d9d78
                 done
30d9d78
-                rm -f conftest.c conftest
30d9d78
                 ;;
30d9d78
            solaris)    castorlib="$castorlib -lposix4" ;;
30d9d78
            win32)      castorincdir="$castorincdir $castorincdir/../win32"
30d9d78
@@ -3112,44 +3169,19 @@
30d9d78
         enable_hdfs="no"
30d9d78
     else
30d9d78
         case $platform in
30d9d78
-           linux)
30d9d78
-                hdfslib="$hdfslib"
30d9d78
-                for i in "" -ladns ; do
30d9d78
-                    echo 'extern hdfsConnect(const char *, unsigned short); int main() { hdfsConnect("default", 0); return 0; }' > conftest.c
30d9d78
-                    logmsg " Checking if we can link against $hdfslib"
30d9d78
-                    logmsg " gcc conftest.c $hdfslibdir $hdfslib $i -o conftest"
30d9d78
-                    gcc conftest.c $hdfslibdir $hdfslib $i -o conftest >> $logfile 2>&1
30d9d78
-                    if test $? -eq 0 ; then
30d9d78
-                        hdfslib="$hdfslib $i" ;
30d9d78
-                        break ;
30d9d78
-                    else
30d9d78
-                        logmsg " Failed program was:"
30d9d78
-                        cat conftest.c >> $logfile
30d9d78
-                        enable_hdfs="no"
30d9d78
-                    fi
30d9d78
-                done
30d9d78
-                rm -f conftest.c conftest
30d9d78
+            linux)
30d9d78
+                check_link $hdfslib $hdfslibdir hdfsConnect
30d9d78
+                if test $link_result -eq 0 ; then
30d9d78
+                    enable_hdfs="no"
30d9d78
+                fi
30d9d78
 
30d9d78
-                jvmlib="$jvmlib"
30d9d78
-                for i in "" -ladns ; do
30d9d78
-                    echo '#include "jni.h"' > conftest.c
30d9d78
-                    echo 'int main() { JNI_CreateJavaVM(NULL, NULL, NULL); return 0; }' >> conftest.c
30d9d78
-                    logmsg " Checking if we can link against $jvmlib"
30d9d78
-                    logmsg " gcc conftest.c -I$jniincdir -I$jniincdir/linux $jvmlibdir $jvmlib $i -o conftest"
30d9d78
-                    gcc conftest.c -I$jniincdir -I$jniincdir/linux $jvmlibdir $jvmlib $i -o conftest >> $logfile 2>&1
30d9d78
-                    if test $? -eq 0 ; then
30d9d78
-                        jvmlib="$jvmlib $i" ;
30d9d78
-                        break ;
30d9d78
-                    else
30d9d78
-                        logmsg " Failed program was:"
30d9d78
-                        cat conftest.c >> $logfile
30d9d78
-                        enable_hdfs="no"
30d9d78
-                    fi
30d9d78
-                done
30d9d78
-                rm -f conftest.c conftest
30d9d78
+                check_link $jvmlib $jvmlibdir JNI_CreateJavaVM
30d9d78
+                if test $link_result -eq 0 ; then
30d9d78
+                    enable_hdfs="no"
30d9d78
+                fi
30d9d78
                 ;;
30d9d78
         esac
30d9d78
-        echo "HDFS disabled due to failed compile and link test!"
30d9d78
+        echo "HDFS disabled due to failed compile and link test"
30d9d78
     fi
30d9d78
 fi
30d9d78
 check_explicit "$enable_hdfs" "$enable_hdfs_explicit" \