SUBARCH = $(shell uname -m)
ifeq ($(SUBARCH),x86_64)
EXTRA_CFLAGS +=-mcmodel=kernel -mno-red-zone
endif

# Comment/uncomment the following line to enable/disable debugging
#DEBUG = y


ifeq ($(DEBUG),y)
  DEBFLAGS = -O -g -DKMBC_DEBUG -DKMBC_UNIT_TEST
else
  DEBFLAGS = -O2
endif

EXTRA_CFLAGS += $(DEBFLAGS) -DBUILDING_DRIVER -I$(LDDINC)

TARGET = kmbclow

ifneq ($(KERNELRELEASE),)

kmbclow-objs := KMBC_low_linux.o KMBC_low_mm.o KMBC_low_mmap.o

obj-m	:= kmbclow.o

else

KERNELDIR  ?= /lib/modules/$(shell uname -r)/build
INSTALLDIR ?= /lib/modules/$(shell uname -r)/misc
PWD        := $(shell pwd)

modules:
	$(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD) modules

endif


install:
	install -d $(INSTALLDIR)
	install -c $(TARGET).ko $(INSTALLDIR)

uninstall:
	rm -rf $(INSTALLDIR)/$(TARGET).ko

clean:
	rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions


depend .depend dep:
	$(CC) $(EXTRA_CFLAGS) -M *.c > .depend

ifeq (.depend,$(wildcard .depend))
include .depend
endif
