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

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

	grp.add_option('--disable-utils-xcf', action='store_true',
		dest='DISABLE_UTILS_XCF', default = False,
		help='disable xash-clang-format wrapper utility [default: %(default)s]')

def configure(conf):
	# wrapper relies on POSIX, disable on Windows for now
	conf.env.DISABLE_UTILS_XCF = conf.options.DISABLE_UTILS_XCF or conf.env.DEST_OS == 'win32'

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

	bld.stlib(source = bld.path.ant_glob(['*.c', '*.h'], excl='main.c'),
		target = 'xcflib',
		features = 'format',
		includes = '.',
		use = 'public werror',
		install_path = None)

	bld.program(source = 'main.c',
		target = 'xash-clang-format',
		features = 'format',
		use = 'xcflib werror',
		install_path = bld.env.BINDIR,
		subsystem = bld.env.CONSOLE_SUBSYSTEM)

	if bld.env.TESTS:
		tests = ['transform', 'config', 'version']

		for name in tests:
			bld.program(features = 'test format',
				source       = 'tests/test_%s.c' % name,
				target       = 'test_xcflib_%s' % name,
				includes     = '.',
				use          = 'xcflib werror',
				install_path = None)
