NO_COLOR=\033[0m
OK_COLOR=\033[32;01m
ERR_COLOR=\033[31;01m

.ONESHELL:

MODULE_NAME = zpcidev

KDIR = /usr/src/linux-headers-$(shell uname -r)

CONFIG_MODULE_SIG=n
TAR = ./build
PWD = $(shell pwd)
obj-m = $(MODULE_NAME).o
$(MODULE_NAME)-objs = pcidev_driver.o pcidev_manage.o

EXTRA_CFLAGS += -Wno-date-time

all: module 
	@echo "$(OK_COLOR) *************** build $(notdir $(CURDIR)) success. \t*************** $(NO_COLOR)\n"
module: clean_ko
	@echo "\n$(OK_COLOR) *************** build $(notdir $(CURDIR)) start. \t*************** $(NO_COLOR)"
	$(MAKE) -C $(KDIR) M=$(PWD) modules 

uninstall:
	$(shell rmmod zpcidev)

install:
	cp $(MODULE_NAME).ko /lib/modules/$(shell uname -r)
	$(shell depmod)
	$(shell modprobe zpcidev)

reinstall: 
	$(shell rmmod zpcidev)
	cp $(MODULE_NAME).ko /lib/modules/$(shell uname -r)
	$(shell depmod)
	$(shell modprobe zpcidev)

clean: clean_ko clean_tmp
clean_ko:
	@rm -rf *.ko *.tmp
clean_tmp:
	@rm -rf *.o .*.cmd *.mod.c *.order *.symvers .*tmp_versions *.mod *.tmp

.PHONY := install reinstall

# install:
# 	@echo "$(OK_COLOR) *************** install $(notdir $(CURDIR)) start. \t*************** $(NO_COLOR)\n"
# 	$(ifneq $(INSTALL_DIR), $(shell ([ -d $(INSTALL_DIR)/$(notdir $(CURDIR)) ] || mkdir -p $(INSTALL_DIR)/$(notdir $(CURDIR))) && cp -r $(CURDIR)/*.ko $(INSTALL_DIR)/$(notdir $(CURDIR))), )
# 	@echo "\n$(OK_COLOR) *************** install $(notdir $(CURDIR)) success. \t*************** $(NO_COLOR)"
