+lib_flags=
+for opt in -L$libdir @LDFLAGS@ @EXTRA_LDFLAGS@ @LIBS@
+do
+ case $opt in
+ -l*) # LIBS is handled specially below
+ continue
+ ;;
+ -Wl,-z,*) # ignore flags used to manipulate shared image
+ continue
+ ;;
+ -L*)
+ [ -d ${opt##-L} ] || continue
+ case ${opt##-L} in
+ @LD_SEARCHPATH@) # skip standard libdir
+ continue
+ ;;
+ *)
+ 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