# ifneq (${KERNELRELEASE},)

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

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

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

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

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

# endif 

ifneq (${KERNELRELEASE},)

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

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

usbcontroller.o: usbcontroller.c usbcontroller.h
	$(CC) -c usbcontroller.c -o usbcontroller.o

hello.o: hello.c usbcontroller.h
	$(CC) -c hello.c -o hello.o

hello: hello.o usbcontroller.o
	$(CC) hello.o usbcontroller.o -o hello -lusb-1.0

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

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

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

endif
