kconfig: search harder for curses library in check-lxdialog.sh
[sfrench/cifs-2.6.git] / scripts / kconfig / lxdialog / check-lxdialog.sh
index a3c141b49670f698fa541a44227dc100d89b6a02..cdca7388e0f1f982ae0a05994bbb7e22a6ef74b0 100644 (file)
@@ -4,11 +4,16 @@
 # What library to link
 ldflags()
 {
-       if [ `uname` == SunOS ]; then
-               echo '-lcurses'
-       else
-               echo '-lncurses'
-       fi
+       for ext in so a dylib ; do
+               for lib in ncursesw ncurses curses ; do
+                       $cc -print-file-name=lib${lib}.${ext} | grep -q /
+                       if [ $? -eq 0 ]; then
+                               echo "-l${lib}"
+                               exit
+                       fi
+               done
+       done
+       exit 1
 }
 
 # Where is ncurses.h?
@@ -25,10 +30,13 @@ ccflags()
        fi
 }
 
-compiler=""
+# Temp file, try to clean up after us
+tmp=.lxdialog.tmp
+trap "rm -f $tmp" 0 1 2 3 15
+
 # Check if we can link to ncurses
 check() {
-       echo "main() {}" | $compiler -xc -
+       echo "main() {}" | $cc -xc - -o $tmp 2> /dev/null
        if [ $? != 0 ]; then
                echo " *** Unable to find the ncurses libraries."          1>&2
                echo " *** make menuconfig require the ncurses libraries"  1>&2
@@ -48,16 +56,19 @@ if [ $# == 0 ]; then
        exit 1
 fi
 
+cc=""
 case "$1" in
        "-check")
                shift
-               compiler="$@"
+               cc="$@"
                check
                ;;
        "-ccflags")
                ccflags
                ;;
        "-ldflags")
+               shift
+               cc="$@"
                ldflags
                ;;
        "*")