check-lxdialog.sh 2.1 KB
Newer Older
1
#!/bin/sh
2
# SPDX-License-Identifier: GPL-2.0
3 4 5 6 7
# Check ncurses compatibility

# What library to link
ldflags()
{
8 9
	pkg-config --libs ncursesw 2>/dev/null && exit
	pkg-config --libs ncurses 2>/dev/null && exit
10
	for ext in so a dll.a dylib ; do
11 12 13 14 15 16 17 18
		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
19
	exit 1
20 21 22 23 24
}

# Where is ncurses.h?
ccflags()
{
25 26 27 28 29
	if pkg-config --cflags ncursesw 2>/dev/null; then
		echo '-DCURSES_LOC="<ncurses.h>" -DNCURSES_WIDECHAR=1'
	elif pkg-config --cflags ncurses 2>/dev/null; then
		echo '-DCURSES_LOC="<ncurses.h>"'
	elif [ -f /usr/include/ncursesw/curses.h ]; then
30
		echo '-I/usr/include/ncursesw -DCURSES_LOC="<curses.h>"'
31
		echo ' -DNCURSES_WIDECHAR=1'
32
	elif [ -f /usr/include/ncurses/ncurses.h ]; then
33 34
		echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>"'
	elif [ -f /usr/include/ncurses/curses.h ]; then
35
		echo '-I/usr/include/ncurses -DCURSES_LOC="<curses.h>"'
36 37 38 39 40 41 42
	elif [ -f /usr/include/ncurses.h ]; then
		echo '-DCURSES_LOC="<ncurses.h>"'
	else
		echo '-DCURSES_LOC="<curses.h>"'
	fi
}

S
Sam Ravnborg 已提交
43 44 45 46
# Temp file, try to clean up after us
tmp=.lxdialog.tmp
trap "rm -f $tmp" 0 1 2 3 15

47 48
# Check if we can link to ncurses
check() {
J
Jean Delvare 已提交
49
        $cc -x c - -o $tmp 2>/dev/null <<'EOF'
50 51 52
#include CURSES_LOC
main() {}
EOF
53
	if [ $? != 0 ]; then
54 55 56 57
	    echo " *** Unable to find the ncurses libraries or the"       1>&2
	    echo " *** required header files."                            1>&2
	    echo " *** 'make menuconfig' requires the ncurses libraries." 1>&2
	    echo " *** "                                                  1>&2
58 59
	    echo " *** Install ncurses (ncurses-devel or libncurses-dev " 1>&2
	    echo " *** depending on your distribution) and try again."    1>&2
60 61
	    echo " *** "                                                  1>&2
	    exit 1
62 63 64 65
	fi
}

usage() {
66
	printf "Usage: $0 [-check compiler options|-ccflags|-ldflags compiler options]\n"
67 68
}

69
if [ $# -eq 0 ]; then
70 71 72 73
	usage
	exit 1
fi

S
Sam Ravnborg 已提交
74
cc=""
75 76 77
case "$1" in
	"-check")
		shift
78
		cc="$@"
79 80 81 82 83 84
		check
		;;
	"-ccflags")
		ccflags
		;;
	"-ldflags")
85 86
		shift
		cc="$@"
87 88 89 90 91 92 93
		ldflags
		;;
	"*")
		usage
		exit 1
		;;
esac