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