+lib_flags=
+for opt in -L$libdir @EXTRA_PKG_LDFLAGS@ @LIBS@
+do
+ case $opt in
+ -l*) # LIBS is handled specially below
+ continue
+ ;;
+ -specs*) # ignore linker specs-files which were used to build library
+ continue
+ ;;
+ -Wl,-z,*) # ignore flags used to manipulate shared image
+ continue
+ ;;
+ -Wl,--dynamic-linker*) # ignore ELF interpreter
+ continue
+ ;;
+ -Wl,--as-needed|-Wl,--build-id=*|-Wl,-dT,*|-Wl,-T,*)
+ continue
+ ;;
+ -L*)
+ lib_check=`echo "x$opt" | sed -e 's/^.-L//'`
+ [ -d "$lib_check" ] || continue
+ case "$lib_check" in
+ @LD_SEARCHPATH@) # skip standard libdir
+ if [ "$lib_check" = "$libdir" ]
+ then
+ lib_first=yes
+ IFS_save="$IFS"
+ IFS='|'
+ LIBDIRS="@LD_SEARCHPATH@"
+ for lib_check in $LIBDIRS
+ do
+ if [ -d "$lib_check" ]
+ then
+ if [ "$lib_check" != "$libdir" ]
+ then
+ lib_first=no
+ fi
+ break
+ fi
+ done
+ IFS="$IFS_save"
+ [ $lib_first = yes ] && continue
+ found=no
+ for check in $lib_flags
+ do
+ if [ "x$check" = "x$opt" ]
+ then
+ found=yes
+ break
+ fi
+ done
+ [ $found = yes ] && continue
+ :
+ else
+ continue
+ fi
+ ;;
+ *)
+ found=no
+ for check in $lib_flags
+ do
+ if [ "x$check" = "x$opt" ]
+ then
+ found=yes
+ break
+ fi
+ done
+ [ $found = yes ] && continue
+ ;;
+ esac
+ ;;
+ esac
+ lib_flags="$lib_flags $opt"
+done
+
+# Check if we should specify the tinfo library explicitly so that terminfo
+# functions or curses variables (which also reside in tinfo) can be linked
+# using the -lncurses option.
+NEED_TINFO=no
+if [ "x@TINFO_LIBS@" != "x" ] && \
+ [ "x$TINFO_ARG_SUFFIX" != "x$MAIN_LIBRARY" ]
+then
+ NEED_TINFO=yes