mconf-cfg.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. set -eu
  4. cflags=$1
  5. libs=$2
  6. PKG="ncursesw"
  7. PKG2="ncurses"
  8. if [ -n "$(command -v ${HOSTPKG_CONFIG})" ]; then
  9. if ${HOSTPKG_CONFIG} --exists $PKG; then
  10. ${HOSTPKG_CONFIG} --cflags ${PKG} > ${cflags}
  11. ${HOSTPKG_CONFIG} --libs ${PKG} > ${libs}
  12. exit 0
  13. fi
  14. if ${HOSTPKG_CONFIG} --exists ${PKG2}; then
  15. ${HOSTPKG_CONFIG} --cflags ${PKG2} > ${cflags}
  16. ${HOSTPKG_CONFIG} --libs ${PKG2} > ${libs}
  17. exit 0
  18. fi
  19. fi
  20. # Check the default paths in case pkg-config is not installed.
  21. # (Even if it is installed, some distributions such as openSUSE cannot
  22. # find ncurses by pkg-config.)
  23. if [ -f /usr/include/ncursesw/ncurses.h ]; then
  24. echo -D_GNU_SOURCE -I/usr/include/ncursesw > ${cflags}
  25. echo -lncursesw > ${libs}
  26. exit 0
  27. fi
  28. if [ -f /usr/include/ncurses/ncurses.h ]; then
  29. echo -D_GNU_SOURCE -I/usr/include/ncurses > ${cflags}
  30. echo -lncurses > ${libs}
  31. exit 0
  32. fi
  33. # As a final fallback before giving up, check if $HOSTCC knows of a default
  34. # ncurses installation (e.g. from a vendor-specific sysroot).
  35. if echo '#include <ncurses.h>' | ${HOSTCC} -E - >/dev/null 2>&1; then
  36. echo -D_GNU_SOURCE > ${cflags}
  37. echo -lncurses > ${libs}
  38. exit 0
  39. fi
  40. echo >&2 "*"
  41. echo >&2 "* Unable to find the ncurses package."
  42. echo >&2 "* Install ncurses (ncurses-devel or libncurses-dev"
  43. echo >&2 "* depending on your distribution)."
  44. echo >&2 "*"
  45. echo >&2 "* You may also need to install ${HOSTPKG_CONFIG} to find the"
  46. echo >&2 "* ncurses installed in a non-default location."
  47. echo >&2 "*"
  48. exit 1