ifneq (${KERNELRELEASE},)

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

LDFLAGS += -lusb-1.0

default: module game

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

game: game.c usbkeyboard.c usbkeyboard.h
	${CC} -o game game.c usbkeyboard.c ${LDFLAGS}

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

TARFILES = Makefile README oregon_trail.h oregon_trail.c game.c usbkeyboard.c usbkeyboard.h
TARFILE = lab3-sw.tar.gz
.PHONY : tar
tar : $(TARFILE)

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

endif 
