#! /usr/bin/env python
# encoding: utf-8

def options(opt):
	grp = opt.get_option_group('Utilities options')

	grp.add_option('--disable-utils-xrcon-tui', action = 'store_true', dest = 'DISABLE_UTILS_XRCON_TUI', default = False,
		help = 'disable terminal client and MCP server for the XRCON remote console [default: %(default)s]')

def configure(conf):
	conf.env.DISABLE_UTILS_XRCON_TUI = conf.options.DISABLE_UTILS_XRCON_TUI

	# needs a terminal, so only Windows and desktop UNIX-likes
	if conf.env.DEST_OS in ['android', 'nswitch', 'psvita', 'ps4', 'dos', 'emscripten', 'wasi'] or conf.env.IOS:
		conf.env.DISABLE_UTILS_XRCON_TUI = True
		return

	if conf.env.DEST_OS == 'sunos':
		conf.check_cc(lib='socket')

def build(bld):
	if bld.env.DISABLE_UTILS_XRCON_TUI:
		return

	source = ['edit.c', 'json.c', 'log_buf.c', 'main.c', 'mcp.c', 'net.c', 'scrollback.c', 'text.c', 'ui.c']
	libs = ['public', 'build_vcs', 'werror', 'yy_thunks']

	if bld.env.DEST_OS == 'win32':
		source += ['sys_win32.c']
		libs += ['WS2_32']
	else:
		source += ['sys_posix.c']
		libs += ['SOCKET']

	bld.program(source = source,
		target   = 'xrcon-tui',
		includes = '.',
		use      = libs,
		install_path = bld.env.BINDIR,
		subsystem = bld.env.CONSOLE_SUBSYSTEM
	)
