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

def options(opt):
	pass

def configure(conf):
	if not conf.path.find_dir('opusfile') or not conf.path.find_dir('opusfile/src'):
		conf.fatal('Can\'t find opusfile submodule. Run `git submodule update --init --recursive`.')
		return

	if conf.env.COMPILER_CC == 'msvc':
		conf.define('_CRT_SECURE_NO_WARNINGS', 1)
		conf.define('_CRT_SECURE_NO_DEPRECATE', 1)
		conf.define('_CRT_NONSTDC_NO_DEPRECATE', 1)

	if conf.env.DEST_OS == 'android':
		# HACKHACK: set it to 32 here because opusfile can't be built on Android SDK < 24
		# with _FILE_OFFSET_BITS 64 (which it sets automatically in src/internal.h)
		# we are not (????) relying on this part of the API, so it should be harmless
		conf.define('_FILE_OFFSET_BITS', 32)

def build(bld):
	sources = [
		'opusfile/src/info.c',
		'opusfile/src/internal.c',
		'opusfile/src/opusfile.c',
		'opusfile/src/stream.c'
	]

	bld.stlib(
		source = sources,
		target = 'opusfile',
		includes = 'opusfile/include/',
		use = 'ogg opus',
		export_includes = 'opusfile/include/'
	)
