~rabbits/orca

9074100199d9c82b6ee5ca40606c3e2057092350 — cancel 2 years ago 35f0f61 pkg_config
Add use of pkg-config for Linux ncurses link args

Depending on the Linux distro, ncurses may be built with tinfo as a
separate library that needs to be explicitly linked, or it may not.
Trying to pass -ltinfo when you don't need to might cause a linking
error. Failing to pass -ltinfo when you need to might cause a linking
error. And you might need to pass -ltinfow instead of -ltinfo, or you
might not. And if you get that wrong, you might cause a linking error.

This commit adds use pkg-config to the tool build script, attempting to
discover what args to use. This is only done on Linux. On other
platforms, or if pkg-config returns an error, we use the same hard-coded
options as before: -lncursesw -lformw

This probably adds about 5 or 10 milliseconds to the execution time of
the tool script.
1 files changed, 17 insertions(+), 1 deletions(-)

M tool
M tool => tool +17 -1
@@ 409,7 409,23 @@ build_target() {
          add cc_flags -D_POSIX_C_SOURCE=200809L
        ;;
      esac
      add libraries -lformw -lncursesw
      # Depending on the Linux distro, ncurses might have been built with tinfo
      # as a separate library that explicitly needs to be linked, or it might
      # not. And if it does, it might need to be either -ltinfo or -ltinfow.
      # Yikes. If this is Linux, let's try asking pkg-config what it thinks.
      local curses_flags=0
      if [[ $os == linux ]]; then
        if curses_flags=$(pkg-config --libs ncursesw formw 2>/dev/null); then
          # append flags to array, splitting on spaces
          IFS=" " read -r -a libraries <<< "$curses_flags"
          curses_flags=1
        fi
      fi
      # If we didn't get the flags by pkg-config, just guess. (This will work
      # most of the time, including on Mac with Homebrew, and cygwin.)
      if [[ $curses_flags = 0 ]]; then
        add libraries -lncursesw -lformw
      fi
      if [[ $portmidi_enabled = 1 ]]; then
        add libraries -lportmidi
        add cc_flags -DFEAT_PORTMIDI