use pkg-config to detect proper ncurses flags.

Full details at https://bugs.gentoo.org/show_bug.cgi?id=486124 and https://bugs.gentoo.org/show_bug.cgi?id=457530

In gentoo, tinfo is an optional part of ncurses and that causes an issue when pkg-config is not used to detect the proper flags to use ncurses support.  Patch written by Jeroen Roovers.