# This is kbuild makefile for use with kernel build system
#
# Copyright (C) 1997-2017  AudioScience Inc. <support@audioscience.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation;
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# Usage:
# make -C <path-to-kernel-source> SUBDIRS=$PWD modules
# If you used O=<path-to-build-directory> for kernel build, use it here too

ifdef KBUILD_VERBOSE
# then we are coming from the kernel build sytem

snd-asihpi-objs := asihpi.o hpicmn.o hpifunc.o hpidebug.o  hpimsgx.o hpios.o\
		hpi6000.o hpi6205.o hpi6700.o hpidspcd.o hpimsginit.o hpioctl.o

obj-m += snd-asihpi.o

ifeq ($(shell egrep -qw "snd_pcm_stop_xrun" $(realpath $(srctree))/include/sound/pcm.h; echo $$?),0)
	   have-snd-pcm-stop-xrun := 1
else
	   have-snd-pcm-stop-xrun := 0
endif

ifeq ($(shell egrep -qw "pcm_format_to_bits" $(realpath $(srctree))/include/sound/pcm.h; echo $$?),0)
	   have-pcm-format-to-bits := 1
else
	   have-pcm-format-to-bits := 0
endif

ifeq ($(shell egrep -qw "snd_ctl_enum_info" $(realpath $(srctree))/include/sound/control.h; echo $$?),0)
	   have-snd-ctl-enum-info := 1
else
	   have-snd-ctl-enum-info := 0
endif

ifeq ($(shell egrep -qw "snd_card_new" $(realpath $(srctree))/include/sound/core.h; echo $$?),0)
	   have-snd-card-new := 1
else
	   have-snd-card-new := 0
endif

# Allow #include <header>  to get header from this build dir
EXTRA_CFLAGS = -DKERNEL_ALSA_BUILD -I$(M) \
	-DHAVE_SND_PCM_STOP_XRUN=$(have-snd-pcm-stop-xrun) \
	-DHAVE_PCM_FORMAT_TO_BITS=$(have-pcm-format-to-bits) \
	-DHAVE_SND_CTL_ENUM_INFO=$(have-snd-ctl-enum-info) \
	-DHAVE_SND_CARD_NEW=$(have-snd-card-new)

else
# Use the autoconf generated makefile for setup, install, dist targets etc.
include extra.mk
endif
