ref: 9074100199d9c82b6ee5ca40606c3e2057092350
parent: 35f0f61cc9bfa2fa4d4830666dafe1c2c7894c74
author: cancel <cancel@cancel.fm>
date: Thu Nov 12 05:48:10 EST 2020
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.
--- a/tool
+++ b/tool
@@ -409,7 +409,23 @@
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
--
⑨