kconfig/lxdialog/check-lxdialog.sh
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Jun 13 23:38:37 2010 +0200 (2010-06-13)
changeset 1983 198a5a6e5239
parent 1229 8864e5255c2d
child 2125 4009fc9c47d5
permissions -rw-r--r--
cc/gcc: baremetal requires a two-pass process

Here, we implement a highly ugly hack. I'm not proud of that one...

To build the libstdc++ library, the compiler requires the C library. In
case we build for non-baremetal, this is normally handled by the final
step, later.

But in the case of bare-metal, we never go through the final step (because
it does not work, and it seems complex enough to make it work), so the
baremetal compilers are issued out of the core step.
     1 #!/bin/sh
     2 # Check ncurses compatibility
     3 
     4 OS=`uname`
     5 
     6 # Under MACOS make sure that the macports-installed version is used.
     7 case "$OS" in
     8 	Darwin) BASEDIR="/opt/local";;
     9 	*)      BASEDIR="/usr";;
    10 esac
    11 
    12 INCLUDEPATH="${BASEDIR}/include"
    13 LIBPATH="${BASEDIR}/lib"
    14 
    15 # What library to link
    16 ldflags()
    17 {
    18 	for ext in so a dylib ; do
    19 		for lib in ncursesw ncurses curses ; do
    20 			if [ -f "${LIBPATH}/lib${lib}.${ext}" ]; then
    21 				echo "-L${LIBPATH} -l${lib}"
    22 				exit
    23 			fi
    24 		done
    25 	done
    26 	exit 1
    27 }
    28 
    29 # Where is ncurses.h?
    30 ccflags()
    31 {
    32 	if [ -f "${INCLUDEPATH}/ncursesw/ncurses.h" ]; then
    33 		echo "-I${INCLUDEPATH} \"-DCURSES_LOC=<ncursesw/ncurses.h>\""
    34 	elif [ -f "${INCLUDEPATH}/ncurses/ncurses.h" ]; then
    35 		echo "-I${INCLUDEPATH} \"-DCURSES_LOC=<ncurses/ncurses.h>\""
    36 	elif [ -f "${INCLUDEPATH}/ncursesw/curses.h" ]; then
    37 		echo "-I${INCLUDEPATH} \"-DCURSES_LOC=<ncursesw/curses.h>\""
    38 	elif [ -f "${INCLUDEPATH}/ncurses/curses.h" ]; then
    39 		echo "-I${INCLUDEPATH} \"-DCURSES_LOC=<ncurses/curses.h>\""
    40 	elif [ -f "${INCLUDEPATH}/ncurses.h" ]; then
    41 		echo "-I${INCLUDEPATH} \"-DCURSES_LOC=<ncurses.h>\""
    42 	elif [ -f "${INCLUDEPATH}/curses.h" ]; then
    43 		echo "-I${INCLUDEPATH} \"-DCURSES_LOC=<curses.h>\""
    44 	else
    45 		exit 1
    46 	fi
    47 }
    48 
    49 # Temp file, try to clean up after us
    50 tmp=.lxdialog.tmp
    51 trap "rm -f $tmp" 0 1 2 3 15
    52 
    53 # Check if we can link to ncurses
    54 check() {
    55         IF=`echo $(ccflags) | sed -e 's/"//g'`
    56         $cc $IF $(ldflags) -xc - -o $tmp 2>/dev/null <<'EOF'
    57 #include CURSES_LOC
    58 main() {}
    59 EOF
    60 	if [ $? != 0 ]; then
    61 	    echo " *** Unable to find the ncurses libraries or the"       1>&2
    62 	    echo " *** required header files."                            1>&2
    63 	    echo " *** 'make menuconfig' requires the ncurses libraries." 1>&2
    64 	    echo " *** "                                                  1>&2
    65 	    echo " *** Install ncurses (ncurses-devel) and try again."    1>&2
    66 	    echo " *** "                                                  1>&2
    67 	    exit 1
    68 	fi
    69 }
    70 
    71 usage() {
    72 	printf "Usage: $0 [-check compiler options|-ccflags|-ldflags compiler options]\n"
    73 }
    74 
    75 if [ $# -eq 0 ]; then
    76 	usage
    77 	exit 1
    78 fi
    79 
    80 cc=""
    81 case "$1" in
    82 	"-check")
    83 		shift
    84 		cc="$@"
    85 		check
    86 		;;
    87 	"-ccflags")
    88 		ccflags
    89 		;;
    90 	"-ldflags")
    91 		shift
    92 		cc="$@"
    93 		ldflags
    94 		;;
    95 	"*")
    96 		usage
    97 		exit 1
    98 		;;
    99 esac