1SUMMARY = "The New Curses library"
2DESCRIPTION = "SVr4 and XSI-Curses compatible curses library and terminfo tools including tic, infocmp, captoinfo. Supports color, multiple highlights, forms-drawing characters, and automatic recognition of keypad and function-key sequences. Extensions include resizable windows and mouse support on both xterm and Linux console using the gpm library."
3HOMEPAGE = "http://www.gnu.org/software/ncurses/ncurses.html"
4LICENSE = "MIT"
5LIC_FILES_CHKSUM = "file://COPYING;md5=6f291ee54551d9d8d992ecd623fe4bc7;endline=27"
6SECTION = "libs"
7DEPENDS = "ncurses-native"
8DEPENDS:class-native = ""
9
10BINCONFIG = "${bindir}/ncurses5-config ${bindir}/ncursesw5-config \
11	${bindir}/ncurses6-config ${bindir}/ncursesw6-config"
12
13inherit autotools binconfig-disabled multilib_header pkgconfig
14
15# Upstream has useful patches at times at ftp://invisible-island.net/ncurses/
16SRC_URI = "git://github.com/ThomasDickey/ncurses-snapshots.git;protocol=https;branch=master"
17
18EXTRA_AUTORECONF = "-I m4"
19
20CACHED_CONFIGUREVARS = "cf_cv_func_nanosleep=yes"
21CACHED_CONFIGUREVARS:append:linux = " cf_cv_working_poll=yes"
22
23# Whether to enable separate widec libraries; must be 'true' or 'false'
24#
25# TODO: remove this variable when widec is supported in every setup?
26ENABLE_WIDEC ?= "true"
27
28# _GNU_SOURCE is required for widec stuff and is not detected automatically
29CPPFLAGS += "-D_GNU_SOURCE"
30
31# natives don't generally look in base_libdir
32base_libdir:class-native = "${libdir}"
33
34# Display corruption occurs on 64 bit hosts without these settings
35# This was derrived from the upstream debian ncurses which uses
36# these settings for 32 and 64 bit hosts.
37EXCONFIG_ARGS = ""
38EXCONFIG_ARGS:class-native = " \
39		--disable-lp64 \
40		--with-chtype='long' \
41		--with-mmask-t='long'"
42EXCONFIG_ARGS:class-nativesdk = " \
43		--disable-lp64 \
44		--with-chtype='long' \
45		--with-mmask-t='long'"
46
47PACKAGES_DYNAMIC = "^${PN}-lib.*"
48
49# Fall back to the host termcap / terminfo for -nativesdk and -native
50# The reality is a work around for strange problems with things like
51# "bitbake -c menuconfig busybox" where it cannot find the terminfo
52# because the sstate had a hard coded search path.  Until this is fixed
53# another way this is deemed good enough.
54EX_TERMCAP = ""
55EX_TERMCAP:class-native = ":/etc/termcap:/usr/share/misc/termcap"
56EX_TERMCAP:class-nativesdk = ":/etc/termcap:/usr/share/misc/termcap"
57EX_TERMINFO = ""
58EX_TERMINFO:class-native = ":/etc/terminfo:/usr/share/terminfo:/usr/share/misc/terminfo:/lib/terminfo"
59EX_TERMINFO:class-nativesdk = ":/etc/terminfo:/usr/share/terminfo:/usr/share/misc/terminfo:/lib/terminfo"
60EX_TERMLIB ?= "tinfo"
61
62# Helper function for do_configure to allow multiple configurations
63# $1 the directory to run configure in
64# $@ the arguments to pass to configure
65ncurses_configure() {
66	mkdir -p $1
67	cd $1
68	shift
69	oe_runconf \
70	        --without-debug \
71	        --without-ada \
72	        --without-gpm \
73	        --enable-hard-tabs \
74	        --enable-xmc-glitch \
75	        --enable-colorfgbg \
76	        --with-termpath='${sysconfdir}/termcap:${datadir}/misc/termcap${EX_TERMCAP}' \
77	        --with-terminfo-dirs='${sysconfdir}/terminfo:${datadir}/terminfo${EX_TERMINFO}' \
78	        --with-shared \
79	        --disable-big-core \
80	        --program-prefix= \
81	        --with-ticlib \
82	        --with-termlib=${EX_TERMLIB} \
83	        --enable-sigwinch \
84	        --enable-pc-files \
85	        --disable-rpath-hack \
86		${EXCONFIG_ARGS} \
87	        --with-manpage-format=normal \
88	        --without-manpage-renames \
89	        --disable-stripping \
90	        "$@" || return 1
91	cd ..
92}
93
94# Override the function from the autotools class; ncurses requires a
95# patched autoconf213 to generate the configure script. This autoconf
96# is not available so that the shipped script will be used.
97do_configure() {
98	#Remove ${includedir} from CPPFLAGS, need for cross compile
99	sed -i 's#-I${cf_includedir}##g' ${S}/configure || die "sed CPPFLAGS"
100
101	# The --enable-pc-files requires PKG_CONFIG_LIBDIR existed
102	mkdir -p ${PKG_CONFIG_LIBDIR}
103	( cd ${S}; gnu-configize --force )
104	ncurses_configure "narrowc" || \
105		return 1
106	! ${ENABLE_WIDEC} || \
107		ncurses_configure "widec" "--enable-widec" "--without-progs"
108
109}
110
111do_compile() {
112        oe_runmake -C narrowc libs
113        oe_runmake -C narrowc/progs
114
115        ! ${ENABLE_WIDEC} || \
116            oe_runmake -C widec libs
117}
118
119# set of expected differences between narrowc and widec header
120#
121# TODO: the NCURSES_CH_T difference can cause real problems :(
122_unifdef_cleanup = " \
123  -e '\!/\* \$Id: curses.wide,v!,\!/\* \$Id: curses.tail,v!d' \
124  -e '/^#define NCURSES_CH_T /d' \
125  -e '/^#include <wchar.h>/d' \
126  -e '\!^/\* .* \*/!d' \
127"
128
129do_test[depends] = "unifdef-native:do_populate_sysroot"
130do_test[dirs] = "${S}"
131do_test() {
132        ${ENABLE_WIDEC} || return 0
133
134        # make sure that the narrow and widec header are compatible
135        # and differ only in minor details.
136        unifdef -k narrowc/include/curses.h | \
137            sed ${_unifdef_cleanup} > curses-narrowc.h
138        unifdef -k widec/include/curses.h | \
139            sed ${_unifdef_cleanup} > curses-widec.h
140
141        diff curses-narrowc.h curses-widec.h
142}
143
144# Split original _install_opts to two parts.
145# One is the options to install contents, the other is the parameters \
146# when running command "make install"
147# Note that install.libs will also implicitly install header files,
148# so we do not need to explicitly specify install.includes.
149# Doing so could in fact result in a race condition, as both targets
150# (install.libs and install.includes) would install the same headers
151# at the same time
152
153_install_opts = " install.libs install.man "
154
155_install_cfgs = "\
156  DESTDIR='${D}' \
157  PKG_CONFIG_LIBDIR='${libdir}/pkgconfig' \
158"
159
160do_install() {
161        # Order of installation is important; widec installs a 'curses.h'
162        # header with more definitions and must be installed last hence.
163        # Compatibility of these headers will be checked in 'do_test()'.
164        oe_runmake -C narrowc ${_install_cfgs} ${_install_opts} \
165                install.progs
166
167        # The install.data should run after install.libs, otherwise
168        # there would be a race issue in a very critical conditon, since
169        # tic will be run by install.data, and tic needs libtinfo.so
170        # which would be regenerated by install.libs.
171        oe_runmake -C narrowc ${_install_cfgs} \
172                install.data
173
174
175        ! ${ENABLE_WIDEC} || \
176            oe_runmake -C widec ${_install_cfgs} ${_install_opts}
177
178        cd narrowc
179
180        # include some basic terminfo files
181        # stolen ;) from gentoo and modified a bit
182        for x in ansi console dumb linux rxvt screen screen-256color sun vt52 vt100 vt102 vt200 vt220 xterm-color xterm-xfree86 xterm-256color
183        do
184                local termfile="$(find "${D}${datadir}/terminfo/" -name "${x}" 2>/dev/null)"
185                local basedir="$(basename $(dirname "${termfile}"))"
186
187                if [ -n "${termfile}" ]
188                then
189                        install -d ${D}${sysconfdir}/terminfo/${basedir}
190                        mv ${termfile} ${D}${sysconfdir}/terminfo/${basedir}/
191                        ln -s /etc/terminfo/${basedir}/${x} \
192                                ${D}${datadir}/terminfo/${basedir}/${x}
193                fi
194        done
195        # i think we can use xterm-color as default xterm
196        if [ -e ${D}${sysconfdir}/terminfo/x/xterm-color ]
197        then
198                ln -sf xterm-color ${D}${sysconfdir}/terminfo/x/xterm
199        fi
200
201        # When changing ${libdir} to e.g. /usr/lib/myawesomelib/ ncurses
202        # still installs '/usr/lib/terminfo', so try to rm both
203        # the proper path and a slightly hardcoded one
204        rm -f ${D}${libdir}/terminfo ${D}${prefix}/lib/terminfo
205
206        # create linker scripts for libcurses.so and libncurses to
207        # link against -ltinfo when needed. Some builds might break
208        # else when '-Wl,--no-copy-dt-needed-entries' has been set in
209        # linker flags.
210        for i in libncurses libncursesw; do
211                f=${D}${libdir}/$i.so
212                test -h $f || continue
213                rm -f $f
214                echo '/* GNU ld script */'  >$f
215                echo "INPUT($i.so.5 AS_NEEDED(-ltinfo))" >>$f
216        done
217
218        # Make sure that libcurses is linked so that it gets -ltinfo
219        # also, this should be addressed upstream really.
220        ln -sf libncurses.so ${D}${libdir}/libcurses.so
221
222        # create libtermcap.so linker script for backward compatibility
223        f=${D}${libdir}/libtermcap.so
224        echo '/* GNU ld script */' >$f
225        echo 'INPUT(AS_NEEDED(-ltinfo))' >>$f
226
227        if [ ! -d "${D}${base_libdir}" ]; then
228            # Setting base_libdir to libdir as is done in the -native
229            # case will skip this code
230            mkdir -p ${D}${base_libdir}
231            mv ${D}${libdir}/libncurses.so.* ${D}${base_libdir}
232            ! ${ENABLE_WIDEC} || \
233                mv ${D}${libdir}/libncursesw.so.* ${D}${base_libdir}
234
235            mv ${D}${libdir}/libtinfo.so.* ${D}${base_libdir}
236            rm ${D}${libdir}/libtinfo.so
237
238            # Use ln -rs to ensure this is a relative link despite absolute paths
239            # (as we can't know the relationship between base_libdir and libdir).
240            ln -rs ${D}${base_libdir}/libtinfo.so.5 ${D}${libdir}/libtinfo.so
241        fi
242        if [ -d "${D}${includedir}/ncurses" ]; then
243            for f in `find ${D}${includedir}/ncurses -name "*.h"`
244            do
245	        f=`basename $f`
246	        test -e ${D}${includedir}/$f && continue
247                ln -sf ncurses/$f ${D}${includedir}/$f
248            done
249        fi
250        oe_multilib_header curses.h
251}
252
253python populate_packages:prepend () {
254    libdir = d.expand("${libdir}")
255    base_libdir = d.expand("${base_libdir}")
256    pnbase = d.expand("${PN}-lib%s")
257    do_split_packages(d, libdir, r'^lib(.*)\.so\..*', pnbase, 'ncurses %s library', prepend=True, extra_depends = '', allow_links=True)
258    if libdir is not base_libdir:
259        do_split_packages(d, base_libdir, r'^lib(.*)\.so\..*', pnbase, 'ncurses %s library', prepend=True, extra_depends = '', allow_links=True)
260}
261
262
263inherit update-alternatives
264
265ALTERNATIVE_PRIORITY = "100"
266
267ALTERNATIVE:ncurses-tools:class-target = "clear reset"
268ALTERNATIVE:ncurses-terminfo:class-target = "st st-256color"
269
270ALTERNATIVE_LINK_NAME[st] = "${datadir}/terminfo/s/st"
271
272ALTERNATIVE_LINK_NAME[st-256color] = "${datadir}/terminfo/s/st-256color"
273
274BBCLASSEXTEND = "native nativesdk"
275
276PACKAGES += " \
277  ${PN}-tools \
278  ${PN}-terminfo-base \
279  ${PN}-terminfo \
280"
281
282FILES:${PN} = "\
283  ${bindir}/tput \
284  ${bindir}/tset \
285  ${bindir}/ncurses5-config \
286  ${bindir}/ncursesw5-config \
287  ${bindir}/ncurses6-config \
288  ${bindir}/ncursesw6-config \
289  ${datadir}/tabset \
290"
291
292# This keeps only tput/tset in ncurses
293# clear/reset are in already busybox
294FILES:${PN}-tools = "\
295  ${bindir}/tic \
296  ${bindir}/toe \
297  ${bindir}/infotocap \
298  ${bindir}/captoinfo \
299  ${bindir}/infocmp \
300  ${bindir}/clear${@['', '.${BPN}']['${CLASSOVERRIDE}' == 'class-target']} \
301  ${bindir}/reset${@['', '.${BPN}']['${CLASSOVERRIDE}' == 'class-target']} \
302  ${bindir}/tack \
303  ${bindir}/tabs \
304"
305
306# 'reset' is a symlink to 'tset' which is in the 'ncurses' package
307RDEPENDS:${PN}-tools = "${PN} ${PN}-terminfo-base"
308
309FILES:${PN}-terminfo = "\
310  ${datadir}/terminfo \
311"
312
313FILES:${PN}-terminfo-base = "\
314  ${sysconfdir}/terminfo \
315"
316
317RSUGGESTS:${PN}-libtinfo = "${PN}-terminfo"
318RRECOMMENDS:${PN}-libtinfo = "${PN}-terminfo-base"
319
320# Putting terminfo into the sysroot adds around 2800 files to
321# each recipe specific sysroot. We can live without this, particularly
322# as many recipes may have native and target copies.
323SYSROOT_DIRS:remove = "${datadir}"
324