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) and try again." 1>&2
  55. echo " *** " 1>&2
  56. exit 1
  57. fi
  58. }
  59. usage() {
  60. printf "Usage: $0 [-check compiler options|-ccflags|-ldflags compiler options]\n"
  61. }
  62. if [ $# -eq 0 ]; then
  63. usage
  64. exit 1
  65. fi
  66. cc=""
  67. case "$1" in
  68. "-check")
  69. shift
  70. cc="$@"
  71. check
  72. ;;
  73. "-ccflags")
  74. ccflags
  75. ;;
  76. "-ldflags")
  77. shift
  78. cc="$@"
  79. ldflags
  80. ;;
  81. "*")
  82. usage
  83. exit 1
  84. ;;
  85. esac