kconfig: use POSIX equality test in check-lxdialog.sh
[firefly-linux-kernel-4.4.55.git] / scripts / kconfig / lxdialog / check-lxdialog.sh
index a3c141b49670f698fa541a44227dc100d89b6a02..9681476b96e7fcf371840d78e17aa85657d327a1 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
@@ -43,21 +51,24 @@ usage() {
        printf "Usage: $0 [-check compiler options|-header|-library]\n"
 }
 
-if [ $# == 0 ]; then
+if [ $# -eq 0 ]; then
        usage
        exit 1
 fi
 
+cc=""
 case "$1" in
        "-check")
                shift
-               compiler="$@"
+               cc="$@"
                check
                ;;
        "-ccflags")
                ccflags
                ;;
        "-ldflags")
+               shift
+               cc="$@"
                ldflags
                ;;
        "*")