#endif # WANT_WIN_CHAIN
ifdef WANT_WIN_TTY
-CURSESLIB = -lncurses -ltinfo
+USE_CURSESLIB=1
endif
ifdef WANT_WIN_CURSES
-CURSESLIB = -lncurses -ltinfo
+ifneq "$(USE_CURSESLIB)" "1"
+USE_CURSESLIB=1
+endif
endif
-ifdef CURSESLIB
+ifeq "$(USE_CURSESLIB)" "1"
+ifndef MAKEFILE_DAT
+ifndef MAKEFILE_UTL
+# If CURSES_UNICODE is defined, we need ncursesw.
+# Without CURSES_UNICODE the following simpler setting works.
+# CURSESLIB = -lncurses -ltinfo
+CURSESLIB = $(shell pkg-config ncursesw --libs || echo -lncursesw)
+CURSESLIB += -ltinfo
+endif #not MAKEFILE_UTL
+endif #not MAKEFILE_DAT
WINLIB += $(CURSESLIB)
-endif
+endif #USE_CURSESLIB
ifdef WANT_WIN_X11
USE_XPM=1