# This file is sourced by 'mkconfig'

# Print error if started directly
if test "$CFG_ENABLE_SWITCH" != "1"
then
   printf "Never execute this script manually, it is sourced by 'mkconfig'.\n"
   exit 1
fi


# This function appends a library to LIBS (if it is not already present)
append_library ()
{
   # Check whether library is already there
   LIB_FOUND=0
   for l in $LIBS
   do
      if test "$l" = "-l$1"
      then
         LIB_FOUND=1
         break
      fi
   done
   if test $LIB_FOUND -eq 0
   then
      for l in $LDFLAGS
      do
         if test "$l" = "-l$1"
         then
            LIB_FOUND=1
            break
         fi
      done
   fi
   if test $LIB_FOUND -eq 0
   then
      # Append new library
      LIBS="$LIBS -l$1"
   fi
}


# Most operating systems don't have all the POSIX related code inside libc.
# The list of required additional libraries for different operating systems
# is created here.
case "$($UTIL_UNAME -s)" in
   AIX)
      append_library "m"
      append_library "pthread"
   ;;
   *BSD)
      append_library "m"
      append_library "pthread"
   ;;
   HP-UX)
      append_library "m"
      append_library "pthread"
      # Do not add "xnet", because we use "_HPUX_ALT_XOPEN_SOCKET_API"
   ;;
   IRIX*)
      append_library "m"
      append_library "pthread"
   ;;
   Linux)
      append_library "m"
      append_library "pthread"
   ;;
   SunOS)
      append_library "m"
      append_library "pthread"
      # BSD compatible network stuff (without XSI extension)
      #append_library "socket"
      #append_library "nsl"
      # X/Open compliant network stuff for SUS (with XSI extension)
      append_library "xnet"
      append_library "resolv"
      append_library "rt"
   ;;
esac


# EOF
