ifneq (${KERNELRELEASE},)

# KERNELRELEASE defined: we are being compiled as part of the Kernel
        obj-m :=delay.o hardclip.o biquad.o fir.o vga_ball.o 

else

# We are being compiled as a module: use the Kernel build system

	KERNEL_SOURCE := /usr/src/linux-headers-$(shell uname -r)
        PWD := $(shell pwd)



default: module hello 
hello: hello.o usbkeyboard.o eq_coeff.o eq_coeff_data.o eq_coeff_initialize.o eq_coeff_terminate.o rtGetInf.o rtGetNaN.o rt_nonfinite.o 
	cc $(CFLAGS) -o hello hello.o usbkeyboard.o eq_coeff.o eq_coeff_data.o eq_coeff_initialize.o eq_coeff_terminate.o rtGetInf.o rtGetNaN.o rt_nonfinite.o -lusb-1.0 -pthread -lm

hello.o: hello.c usbkeyboard.h 
usbkeyboard.o: usbkeyboard.c usbkeyboard.h

module:  	
	${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} modules

clean:
	${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
	${RM} hello
	
usbkeyboard.o : usbkeyboard.c usbkeyboard.h


TARFILES = Makefile README delay.h delay.c hello.c hardclip.h hardclip.c biquad.h biquad.c fir.h fir.c vga_ball.h vga_ball.c usbkeyboard.h usbkeyboard.c
TARFILE = lab3-sw.tar.gz
.PHONY : tar
tar : $(TARFILE)

$(TARFILE) : $(TARFILES)
	tar zcfC $(TARFILE) .. $(TARFILES:%=lab3-sw/%)

endif 
