diff --git a/tool b/tool index d5a93c0..cba07a8 100755 --- a/tool +++ b/tool @@ -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