diff --git a/bin/smartlink b/bin/smartlink
index 36ef004f8dcdca79d7ec21d54060113295968ae2..86e29a1e02d7683169ee64decf53d86107eb7dec 100755
--- a/bin/smartlink
+++ b/bin/smartlink
@@ -5,10 +5,16 @@ shift
 RPATH=""
 LDOPTS=""
 
-#Special for HP-UX
+#Special hack for HP-UX
 LD_PXDB=/dev/null
 export LD_PXDB
 
+#Special hack for SGI
+if test "${SGI_ABI:-}" = ""; then
+  SGI_ABI=-n32
+fi
+export SGI_API
+
 #set -x
 
 while test "$#" != 0; do
@@ -58,11 +64,23 @@ if test x$# != x0 ; then
     shift
   done
 
-  if test -f /usr/bin/uname ; then
+  if test -x /usr/bin/uname ; then
     UNAME=`/usr/bin/uname -sr`
-   else
+  elif test -x /bin/uname ; then
+    UNAME=`/bin/uname -sr`
+  else
     UNAME=unknown
-   fi
+  fi
+
+  case "$LINKER $LDOPTS " in
+    *\ -c\ * | cpp\ * | *\ -E\ *)
+      LINKING=no
+    ;;
+
+    *)
+      LINKING=maybe
+    ;;
+  esac
 
   case "$UNAME" in
    OSF1\ V4.*)
@@ -71,6 +89,11 @@ if test x$# != x0 ; then
    SunOS\ 5.*)
      LDOPTS="$LDOPTS -R$RPATH"
    ;;
+   Linux\ 2.*)
+     if test x$LINKING != xno -a "x$RPATH" != x ; then
+      LDOPTS="$LDOPTS -Wl,-rpath,$RPATH"
+     fi
+   ;;
    *)
     LD_LIBRARY_PATH="$RPATH"
     export LD_LIBRARY_PATH
diff --git a/src/configure.in b/src/configure.in
index 49f8521334a7b9930e5eb33ed55cf21c9c6bd9ec..5db3886b61d426bb90c037a81c00f3a77a716e2a 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -1,4 +1,4 @@
-AC_REVISION("$Id: configure.in,v 1.122 1997/09/22 11:09:27 grubba Exp $")
+AC_REVISION("$Id: configure.in,v 1.123 1997/09/26 01:27:44 hubbe Exp $")
 AC_INIT(interpret.c)
 AC_CONFIG_HEADER(machine.h)
 
@@ -197,7 +197,10 @@ if test $cflags_is_set = no; then
   # IRIX
   # sopt disabled since it takes too long time on interpret.c (>45min on an O�)
   # AC_SYS_OS_COMPILER_FLAG(IRIX,-sopt,sopt)
-  AC_SYS_OS_COMPILER_FLAG(IRIX,-n32,n32)
+
+  # -n32 moved to smartlink so it will affekt cc as well as linker
+  # this way the user can override it by setting LDFLAGS and/or CFLAGS
+  # AC_SYS_OS_COMPILER_FLAG(IRIX,-n32,n32)
   AC_SYS_OS_COMPILER_FLAG(IRIX,-g3,g3)
   AC_SYS_OS_COMPILER_FLAG(IRIX,-fullwarn,fullwarn)
   if test x$with_debug = xyes ; then