# All ncurses, ncursesw, panel, panelw, tic details

############ Legend ##############
# B - bootstrap tic specific
# N - ncurses standard lib
# P - libpanel
# W - ncurses wide lib
# T - reserved for future libtinfo
# t - specific to -DTRACE
##################################

GENHDRS_NWP+=	curses.h
GENHDRS_NWB+=	hashsize.h
GENHDRS_NWB+=	init_keytry.h
GENHDRS_NWP+=	ncurses_def.h
GENHDRS_NWB+=	parametrized.h
GENHDRS_NWP+=	term.h

GENSRCS_NWB+=	codes.c
GENSRCS_NWB+=	comp_captab.c
GENSRCS_NW+=	expanded.c
GENSRCS_NWB+=	fallback.c
GENSRCS_NW+=	lib_gen.c
GENSRCS_NWB+=	lib_keyname.c
GENSRCS_NWB+=	names.c
GENSRCS_NWB+=	unctrl.c

# Headers to install
.if defined(ZNCURSES) || defined(ZTIC)
HEADERS=	curses.h term.h termcap.h unctrl.h
SRCHDRS=	ncurses_dll.h
.endif

# Generators
# Careful! Some of contrib scripts may invoke make_hash and make_keys internally.
ncurses_def.h:	MKncurses_def.sh ncurses_defs
	AWK=awk sh ${NCURSESDIR}/include/MKncurses_def.sh \
	${NCURSESDIR}/include/ncurses_defs > ${.TARGET}

curses.h: $(TERMINFO_CAPS) curses.head curses.tail MKkey_defs.sh
	cat ${.CURDIR}/../include/curses.head | \
	sed -e 's|SET_NEED_WCHAR_H|${SW_WIDEC}|' \
	    -e 's|SET_NCURSES_CH_T|${SW_TYPE}|' > ${.TARGET}.new
	AWK=awk sh ${NCURSESDIR}/include/MKkey_defs.sh $(TERMINFO_CAPS) >> ${.TARGET}.new
.if defined(ENABLE_WIDEC)
	cat ${NCURSESDIR}/include/curses.wide >> ${.TARGET}.new
.endif
	cat ${NCURSESDIR}/include/curses.tail >> ${.TARGET}.new
	mv -f ${.TARGET}.new ${.TARGET}

term.h: MKterm.h.awk edit_cfg.sh Caps
	awk -f ${.CURDIR}/../include/MKterm.h.awk ${TERMINFO_CAPS} > ${.TARGET}.new
	sh ${NCURSESDIR}/include/edit_cfg.sh ${.CURDIR}/../include/ncurses_cfg.h ${.TARGET}.new
	mv -f ${.TARGET}.new ${.TARGET}

.if defined(ZNCURSES) || defined(ZTIC)
hashsize.h: MKhashsize.sh Caps
	sh ${NCURSESDIR}/include/MKhashsize.sh ${TERMINFO_CAPS} > ${.TARGET}

parametrized.h: MKparametrized.sh Caps
	sh ${NCURSESDIR}/include/MKparametrized.sh ${TERMINFO_CAPS} > ${.TARGET}

init_keytry.h: make_keys keys.list
	./make_keys keys.list > ${.TARGET}

make_keys: make_keys.c names.c ncurses_def.h ${VERSION_MAP} ${HEADERS}
	${NXCC} ${NXCFLAGS:N-flto:N-W*} -static ${NCURSESTINFODIR}/make_keys.c ${NXLDLIBS} -o ${.TARGET}

keys.list: MKkeys_list.sh Caps
	sh ${NCURSESTINFODIR}/MKkeys_list.sh ${TERMINFO_CAPS} | LC_ALL=C sort > ${.TARGET}

names.c: MKnames.awk Caps
	awk -f ${NCURSESTINFODIR}/MKnames.awk bigstrings=1 ${TERMINFO_CAPS} > ${.TARGET}

codes.c: MKcodes.awk Caps
	awk -f ${NCURSESTINFODIR}/MKcodes.awk bigstrings=1 ${TERMINFO_CAPS} > ${.TARGET}

comp_captab.c: make_hash MKcaptab.sh MKcaptab.awk Caps
	sh -e ${NCURSESTINFODIR}/MKcaptab.sh awk 1 ${NCURSESTINFODIR}/MKcaptab.awk ${TERMINFO_CAPS} > ${.TARGET}

make_hash: make_hash.c hashsize.h ncurses_def.h ${HEADERS}
	${NXCC} ${NXCFLAGS:N-flto:N-W*} -static -DMAIN_PROGRAM ${NCURSESTINFODIR}/make_hash.c ${NXLDLIBS} -o ${.TARGET}

expanded.c: MKexpanded.sh ${GENHDRS_NWP}
	${NXENV} sh ${NCURSESSERIALDIR}/MKexpanded.sh "${CC}" -E ${NXCFLAGS:N-W*} > ${.TARGET}

fallback.c: MKfallback.sh
	sh ${NCURSESTINFODIR}/MKfallback.sh /usr/share/terminfo ${NCURSESDIR}/misc/terminfo.src > ${.TARGET}

lib_gen.c: MKlib_gen.sh curses.h ncurses_def.h term.h
	${NXENV} sh ${NCURSESBASEDIR}/MKlib_gen.sh "${CC} -E ${NXCFLAGS:N-W*}" awk generated <curses.h > ${.TARGET}

lib_keyname.c: MKkeyname.awk keys.list
	awk -f ${NCURSESBASEDIR}/MKkeyname.awk bigstrings=1 keys.list > ${.TARGET}

unctrl.c: MKunctrl.awk
	echo | awk -f ${NCURSESBASEDIR}/MKunctrl.awk bigstrings=1 > ${.TARGET}
.endif

# Generated
SRCS_ALL+=	${GENHDRS_NWP}
.if defined(ZNCURSES) || defined(ZTIC)
SRCS_ALL+=	${GENHDRS_NWB} ${GENSRCS_NWB}
CLEANFILES+=	${GENHDRS_NWB} ${GENSRCS_NWB}
CLEANFILES+=	make_keys make_hash keys.list
.endif
.if defined(ZNCURSES)
SRCS_ALL+=	${GENSRCS_NW} ${GENHDRS_NW}
CLEANFILES+=	${GENSRCS_NW} ${GENHDRS_NW}
.endif
CLEANFILES+=	${GENHDRS_NWP} term.h.new curses.h.new

# Base
SRCS_NW+=	define_key.c
SRCS_NWB+=	key_defined.c
SRCS_NWB+=	keybound.c
SRCS_NW+=	keyok.c
SRCS_NW+=	legacy_coding.c
SRCS_NW+=	lib_addch.c
SRCS_NW+=	lib_addstr.c
SRCS_NW+=	lib_beep.c
SRCS_NW+=	lib_bkgd.c
SRCS_NW+=	lib_box.c
SRCS_NW+=	lib_chgat.c
SRCS_NW+=	lib_clear.c
SRCS_NW+=	lib_clearok.c
SRCS_NW+=	lib_clrbot.c
SRCS_NW+=	lib_clreol.c
SRCS_NW+=	lib_color.c
SRCS_NW+=	lib_colorset.c
SRCS_NW+=	lib_delch.c
SRCS_NW+=	lib_delwin.c
SRCS_NW+=	lib_dft_fgbg.c
SRCS_NW+=	lib_echo.c
SRCS_NW+=	lib_endwin.c
SRCS_NW+=	lib_erase.c
SRCS_NW+=	lib_flash.c
SRCS_NW+=	lib_freeall.c
SRCS_NW+=	lib_getch.c
SRCS_NW+=	lib_getstr.c
SRCS_NW+=	lib_hline.c
SRCS_NW+=	lib_immedok.c
SRCS_NW+=	lib_inchstr.c
SRCS_NW+=	lib_initscr.c
SRCS_NW+=	lib_insch.c
SRCS_NW+=	lib_insdel.c
SRCS_NW+=	lib_insnstr.c
SRCS_NW+=	lib_instr.c
SRCS_NW+=	lib_isendwin.c
SRCS_NW+=	lib_leaveok.c
SRCS_NW+=	lib_mouse.c
SRCS_NW+=	lib_move.c
SRCS_NW+=	lib_mvwin.c
SRCS_NW+=	lib_newterm.c
SRCS_NW+=	lib_newwin.c
SRCS_NW+=	lib_nl.c
SRCS_NW+=	lib_overlay.c
SRCS_NW+=	lib_pad.c
SRCS_NW+=	lib_printw.c
SRCS_NW+=	lib_redrawln.c
SRCS_NW+=	lib_refresh.c
SRCS_NW+=	lib_restart.c
SRCS_NW+=	lib_scanw.c
SRCS_NW+=	lib_screen.c
SRCS_NW+=	lib_scroll.c
SRCS_NW+=	lib_scrollok.c
SRCS_NW+=	lib_scrreg.c
SRCS_NW+=	lib_set_term.c
SRCS_NW+=	lib_slk.c
SRCS_NW+=	lib_slkatr_set.c
SRCS_NW+=	lib_slkatrof.c
SRCS_NW+=	lib_slkatron.c
SRCS_NW+=	lib_slkatrset.c
SRCS_NW+=	lib_slkattr.c
SRCS_NW+=	lib_slkclear.c
SRCS_NW+=	lib_slkcolor.c
SRCS_NW+=	lib_slkinit.c
SRCS_NW+=	lib_slklab.c
SRCS_NW+=	lib_slkrefr.c
SRCS_NW+=	lib_slkset.c
SRCS_NW+=	lib_slktouch.c
SRCS_NW+=	lib_touch.c
SRCS_NW+=	lib_ungetch.c
SRCS_NW+=	lib_vline.c
SRCS_NW+=	lib_wattroff.c
SRCS_NW+=	lib_wattron.c
SRCS_NW+=	lib_winch.c
SRCS_NW+=	lib_window.c
SRCS_NW+=	nc_panel.c
SRCS_NW+=	new_pair.c
SRCS_NW+=	resizeterm.c
SRCS_NW+=	safe_sprintf.c
SRCS_NWB+=	tries.c
SRCS_NW+=	use_window.c
SRCS_NWB+=	version.c
SRCS_NW+=	vsscanf.c
SRCS_NW+=	wresize.c

# Serial
SRCS_NW+=	hardscroll.c
SRCS_NW+=	hashmap.c
SRCS_NW+=	lib_mvcur.c
SRCS_NW+=	lib_tstp.c
SRCS_NW+=	lib_twait.c
SRCS_NW+=	lib_vidattr.c
SRCS_NW+=	tty_update.c

# Tinfo
SRCS_NWB+=	access.c
SRCS_NWB+=	add_tries.c
SRCS_NWB+=	alloc_entry.c
SRCS_NWB+=	alloc_ttype.c
SRCS_NWB+=	captoinfo.c
SRCS_NWB+=	comp_error.c
SRCS_NWB+=	comp_expand.c
SRCS_NWB+=	comp_hash.c
SRCS_NWB+=	comp_parse.c
SRCS_NWB+=	comp_scan.c
SRCS_NWB+=	comp_userdefs.c
SRCS_NWB+=	db_iterator.c
SRCS_NWB+=	doalloc.c
SRCS_NWB+=	entries.c
SRCS_NWB+=	free_ttype.c
SRCS_NWB+=	getenv_num.c
SRCS_NW+=	hashed_db.c
SRCS_NWB+=	home_terminfo.c
SRCS_NWB+=	init_keytry.c
SRCS_NW+=	lib_acs.c
SRCS_NWB+=	lib_baudrate.c
SRCS_NWB+=	lib_cur_term.c
SRCS_NWB+=	lib_data.c
SRCS_NWB+=	lib_has_cap.c
SRCS_NW+=	lib_kernel.c
SRCS_NW+=	lib_longname.c
SRCS_NWB+=	lib_napms.c
SRCS_NWB+=	lib_options.c
SRCS_NW+=	lib_print.c
SRCS_NWB+=	lib_raw.c
SRCS_NWB+=	lib_setup.c
SRCS_NWB+=	lib_termcap.c
SRCS_NW+=	lib_termname.c
SRCS_NWB+=	lib_tgoto.c
SRCS_NWB+=	lib_ti.c
SRCS_NWB+=	lib_tparm.c
SRCS_NWB+=	lib_tputs.c
SRCS_NWB+=	lib_ttyflags.c
SRCS_NWB+=	name_match.c
SRCS_NW+=	obsolete.c
SRCS_NWB+=	parse_entry.c
SRCS_NWB+=	read_entry.c
SRCS_NWB+=	read_termcap.c
SRCS_NWB+=	strings.c
SRCS_NWB+=	trim_sgr0.c
SRCS_NW+=	use_screen.c
SRCS_NWB+=	write_entry.c

# Trace
SRCS_NWB+=	lib_trace.c
SRCS_NWt+=	lib_traceatr.c
SRCS_NWt+=	lib_tracebits.c
SRCS_NWt+=	lib_tracechr.c
SRCS_NWt+=	lib_tracedmp.c
SRCS_NWt+=	lib_tracemse.c
SRCS_NWt+=	trace_buf.c
SRCS_NWt+=	trace_tries.c
SRCS_NWt+=	trace_xnames.c
SRCS_NWt+=	varargs.c
SRCS_NWB+=	visbuf.c

# Widechar
SRCS_W+=	charable.c
SRCS_W+=	lib_add_wch.c
SRCS_W+=	lib_box_set.c
SRCS_W+=	lib_cchar.c
SRCS_W+=	lib_erasewchar.c
SRCS_W+=	lib_get_wch.c
SRCS_W+=	lib_get_wstr.c
SRCS_W+=	lib_hline_set.c
SRCS_W+=	lib_in_wch.c
SRCS_W+=	lib_in_wchnstr.c
SRCS_W+=	lib_ins_wch.c
SRCS_W+=	lib_inwstr.c
SRCS_W+=	lib_key_name.c
SRCS_W+=	lib_pecho_wchar.c
SRCS_W+=	lib_slk_wset.c
SRCS_W+=	lib_unget_wch.c
SRCS_W+=	lib_vid_attr.c
SRCS_W+=	lib_vline_set.c
SRCS_W+=	lib_wacs.c
SRCS_W+=	lib_wunctrl.c

# Panel
SRCS_P+=	p_above.c
SRCS_P+=	p_below.c
SRCS_P+=	p_bottom.c
SRCS_P+=	p_delete.c
SRCS_P+=	p_hidden.c
SRCS_P+=	p_hide.c
SRCS_P+=	p_move.c
SRCS_P+=	p_new.c
SRCS_P+=	p_replace.c
SRCS_P+=	p_show.c
SRCS_P+=	p_top.c
SRCS_P+=	p_update.c
SRCS_P+=	p_user.c
SRCS_P+=	p_win.c
# only when TRACE
#SRCS_P+=	panel.c

# Sources to compile
.if defined(ZTIC)
SRCS_ALL+=	${SRCS_NWB}
.endif
.if defined(ZTRACE)
SRCS_ALL+=	${SRCS_NWt}
.endif
.if defined(ZNCURSES)
SRCS_ALL+=	${SRCS_NWB}
SRCS_ALL+=	${SRCS_NW}
.endif
.if defined(ZNCURSES) && defined(ENABLE_WIDEC)
SRCS_ALL+=	${SRCS_W}
.endif
.if defined(ZPANEL)
SRCS_ALL+=	${SRCS_P}
.endif

# Sort objects for reproducible libs
SRCS+=	${SRCS_ALL:O}
