.PHONY: all clean

MODULE_NAME := ubernic
obj-m += $(MODULE_NAME).o
$(MODULE_NAME)-y := lms_pcie.o lms_chr.o lms_dma.o lms_dump_dma.o ubernic_ctrl.o lms_ptp_aux.o lms_ptp.o lms_eth.o lms_wr.o lms_ns_v2.o lms_txts.o lms_irq.o lms_bmc.o

# Compiler's flags
ccflags-y += -std=gnu11
ccflags-y += -Wall -Wno-declaration-after-statement
#ccflags-y += -DDEBUG
#ccflags-y += -DVERBOSE_DEBUG
ccflags-y += -I$(src)/..
# ccflags-y += -include include/generated/autoconf.h


PWD := $(shell pwd)
KVER = $(shell uname -r)

$(info $$KVER is ${KVER})

# Kernel headers installed (eg. RHEL's kernel-devel package)
# This variable can be overriden when invoking make.
KDIR ?= /lib/modules/$(KVER)/build # symlink to /usr/src/kernels/$(KVER)

# print utils
bold := $(shell tput bold)
sgr0 := $(shell tput sgr0)

all:
	@touch BUILD_INFO.h
	$(info *********************************************************************)
	$(info ***** Kernel version=${bold}$(KVER)${sgr0})
	$(info *********************************************************************)
	$(MAKE) -C $(KDIR) M=$(PWD) modules

install:
	$(MAKE) -C $(KDIR) M=$(PWD) modules_install

install_show:
	ls -alh /lib/modules/$(KVER)/{extra,weak-updates}

uninstall:
	find /lib/modules/$(KVER) -name "$(MODULE_NAME).ko" -exec rm -f {} \;

# Note that this doesn't invoke the clean target of the kernel Makefile to avoid extra unnecessary
# depencencies for build.sh
clean:
	rm -f Module.markers Module.symvers *.cmd *.o *.mod.c *.o.d BUILD_INFO.h *.ko modules.order
