#
# Copyright (c) 2018-2020 TUXEDO Computers GmbH <tux@tuxedocomputers.com>
#
# This file is part of tuxedo-keyboard.
#
# tuxedo-keyboard is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this software.  If not, see <https://www.gnu.org/licenses/>.
#
# edited by onkelho

SHELL := /bin/sh
CC := gcc
KVER ?= $(shell uname -r)
KSRC ?= /lib/modules/$(KVER)/build
FIRMWAREDIR := /lib/firmware/
MAKE := make	
PWD ?= $(shell pwd)
MODDESTDIR := /lib/modules/$(KVER)/kernel/3rdparty/tuxedo
MODNAME_0 := tuxedo_keyboard
MODNAME_1 := clevo_wmi
MODNAME_2 := clevo_acpi
MODNAME_3 := tuxedo_io
MODNAME_4 := uniwill_wmi

CLR_MODULE_FILES := *.mod.c* *.mod* *.o* .*.cmd *.ko* *~ .tmp_versions* modules.order Module.symvers
SYMBOL_FILE := Module.symvers

obj-m :=	tuxedo_keyboard.o \
		clevo_wmi.o \
		clevo_acpi.o \
		tuxedo_io.o \
		uniwill_wmi.o

all: modules

modules:
	make -C $(KSRC) M=$(PWD) modules

install:
	mkdir -p $(MODDESTDIR)
	install -p -D -m 644 $(MODNAME_0).ko $(MODDESTDIR)
	install -p -D -m 644 $(MODNAME_1).ko $(MODDESTDIR)
	install -p -D -m 644 $(MODNAME_2).ko $(MODDESTDIR)
	install -p -D -m 644 $(MODNAME_3).ko $(MODDESTDIR)
	install -p -D -m 644 $(MODNAME_4).ko $(MODDESTDIR)
	xz -f $(MODDESTDIR)/*.ko
	/sbin/depmod -a ${KVER}
	echo "Install tuxedo-keyboard and dependencies SUCCESS"

uninstall:
	modprobe -r $(MODNAME_0)
	modprobe -r $(MODNAME_1)
	modprobe -r $(MODNAME_2)
	modprobe -r $(MODNAME_3)
	modprobe -r $(MODNAME_4)
	rm -f $(MODDESTDIR)/*.ko*
	/sbin/depmod -a ${KVER}
	echo "Uninstall tuxedo-keyboard and dependencies SUCCESS"

.PHONY: modules clean

clean:
	rm -fr Module.symvers ; rm -fr Module.markers ; rm -fr modules.order
	rm -fr *.mod.c *.mod *.o .*.cmd *.ko* *~
	rm -fr .tmp_versions
