Initial public busybox upstream commit
[busybox4maemo] / scripts / kconfig / lxdialog / check-lxdialog.sh
1 #!/bin/sh
2 # Check ncurses compatibility
3
4 # What library to link
5 ldflags()
6 {
7         $cc -print-file-name=libncursesw.so | grep -q /
8         if [ $? -eq 0 ]; then
9                 echo '-lncursesw'
10                 exit
11         fi
12         $cc -print-file-name=libncurses.so | grep -q /
13         if [ $? -eq 0 ]; then
14                 echo '-lncurses'
15                 exit
16         fi
17         $cc -print-file-name=libcurses.so | grep -q /
18         if [ $? -eq 0 ]; then
19                 echo '-lcurses'
20                 exit
21         fi
22         #bbox# exit 1
23         echo '-lcurses'
24         exit
25 }
26
27 # Where is ncurses.h?
28 ccflags()
29 {
30         if [ -f /usr/include/ncurses/ncurses.h ]; then
31                 echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>"'
32         elif [ -f /usr/include/ncurses/curses.h ]; then
33                 echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses/curses.h>"'
34         elif [ -f /usr/include/ncurses.h ]; then
35                 echo '-DCURSES_LOC="<ncurses.h>"'
36         else
37                 echo '-DCURSES_LOC="<curses.h>"'
38         fi
39 }
40
41 # Temp file, try to clean up after us
42 tmp=.lxdialog.tmp
43 trap "rm -f $tmp" 0 1 2 3 15
44
45 # Check if we can link to ncurses
46 check() {
47         echo "main() {}" | $cc -xc - -o $tmp 2> /dev/null
48         if [ $? != 0 ]; then
49                 echo " *** Unable to find the ncurses libraries."          1>&2
50                 echo " *** make menuconfig require the ncurses libraries"  1>&2
51                 echo " *** "                                               1>&2
52                 echo " *** Install ncurses (ncurses-devel) and try again"  1>&2
53                 echo " *** "                                               1>&2
54                 exit 1
55         fi
56 }
57
58 usage() {
59         printf "Usage: $0 [-check compiler options|-header|-library]\n"
60 }
61
62 if [ $# == 0 ]; then
63         usage
64         exit 1
65 fi
66
67 cc=""
68 case "$1" in
69         "-check")
70                 shift
71                 cc="$@"
72                 check
73                 ;;
74         "-ccflags")
75                 ccflags
76                 ;;
77         "-ldflags")
78                 shift
79                 cc="$@"
80                 ldflags
81                 ;;
82         "*")
83                 usage
84                 exit 1
85                 ;;
86 esac