check-lxdialog.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. # Check ncurses compatibility
  4. # What library to link
  5. ldflags()
  6. {
  7. pkg-config --libs ncursesw 2>/dev/null && exit
  8. pkg-config --libs ncurses 2>/dev/null && exit
  9. for ext in so a dll.a dylib ; do
  10. for lib in ncursesw ncurses curses ; do
  11. $cc -print-file-name=lib${lib}.${ext} | grep -q /
  12. if [ $? -eq 0 ]; then
  13. echo "-l${lib}"
  14. exit
  15. fi
  16. done
  17. done
  18. exit 1
  19. }
  20. # Where is ncurses.h?
  21. ccflags()
  22. {
  23. if pkg-config --cflags ncursesw 2>/dev/null; then
  24. echo '-DCURSES_LOC="<ncurses.h>" -DNCURSES_WIDECHAR=1'
  25. elif pkg-config --cflags ncurses 2>/dev/null; then
  26. echo '-DCURSES_LOC="<ncurses.h>"'
  27. elif [ -f /usr/include/ncursesw/curses.h ]; then
  28. echo '-I/usr/include/ncursesw -DCURSES_LOC="<curses.h>"'
  29. echo ' -DNCURSES_WIDECHAR=1'
  30. elif [ -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="<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. # Temp file, try to clean up after us
  41. tmp=.lxdialog.tmp
  42. trap "rm -f $tmp" 0 1 2 3 15
  43. # Check if we can link to ncurses
  44. check() {
  45. $cc -x c - -o $tmp 2>/dev/null <<'EOF'
  46. #include CURSES_LOC
  47. main() {}
  48. EOF
  49. if [ $? != 0 ]; then
  50. echo " *** Unable to find the ncurses libraries or the" 1>&2
  51. echo " *** required header files." 1>&2
  52. echo " *** 'make menuconfig' requires the ncurses libraries." 1>&2
  53. echo " *** " 1>&2
  54. echo " *** Install ncurses (ncurses-devel or libncurses-dev " 1>&2
  55. echo " *** depending on your distribution) and try again." 1>&2
  56. echo " *** " 1>&2
  57. exit 1
  58. fi
  59. }
  60. usage() {
  61. printf "Usage: $0 [-check compiler options|-ccflags|-ldflags compiler options]\n"
  62. }
  63. if [ $# -eq 0 ]; then
  64. usage
  65. exit 1
  66. fi
  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