ifneq (${KERNELRELEASE},)

# KERNELRELEASE defined: we are being compiled as part of the Kernel
        obj-m := mixer.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)

OBJECTS = bitsandbeats.o usbkeyboard.o
CFLAGS = -Wall

default: module bitsandbeats 

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

clean:
	${MAKE} -C ${KERNEL_SOURCE} SUBDIRS=${PWD} clean
	${RM} bitsandbeats

bitsandbeats: $(OBJECTS)
	cc $(CFLAGS) -o bitsandbeats $(OBJECTS) -lusb-1.0 -pthread

bitsandbeats.o: bitsandbeats.c mixer.h usbkeyboard.h usbhidkeys.h

usbkeyboard.o: usbkeyboard.c usbkeyboard.h

# TARFILES = Makefile README vga_ball.h vga_ball.c hello.c
# TARFILE = lab3-sw.tar.gz
# .PHONY : tar
# tar : $(TARFILE)

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

endif 
