Skip to content

Commit

Permalink
Add use of pkg-config for Linux ncurses link args
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cancel committed Nov 12, 2020
1 parent 35f0f61 commit 9074100
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tool
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9074100

Please sign in to comment.