2006-02-10 18:56:21 +03:00
|
|
|
ifndef TP_MODULES
|
|
|
|
# This part runs as a normal, top-level Makefile:
|
2006-07-20 03:19:42 +04:00
|
|
|
X:=$(shell false)
|
2013-04-06 17:35:00 +04:00
|
|
|
KVER ?= $(shell uname -r)
|
|
|
|
KBASE ?= /lib/modules/$(KVER)
|
|
|
|
KSRC ?= $(KBASE)/source
|
|
|
|
KBUILD ?= $(KBASE)/build
|
|
|
|
MOD_DIR ?= $(KBASE)/kernel
|
2011-06-03 14:46:28 +04:00
|
|
|
PWD := $(shell pwd)
|
|
|
|
IDIR := include/linux
|
2011-10-26 20:15:26 +04:00
|
|
|
TP_DIR := drivers/platform/x86
|
2006-08-04 19:21:10 +04:00
|
|
|
TP_MODULES := thinkpad_ec.o tp_smapi.o
|
2006-06-21 20:32:16 +04:00
|
|
|
SHELL := /bin/bash
|
2011-06-03 14:46:28 +04:00
|
|
|
|
|
|
|
ifeq ($(HDAPS),1)
|
|
|
|
TP_MODULES += hdaps.o
|
2006-02-10 18:56:21 +03:00
|
|
|
LOAD_HDAPS := insmod ./hdaps.ko
|
2011-06-03 14:46:28 +04:00
|
|
|
else
|
2006-02-10 18:56:21 +03:00
|
|
|
LOAD_HDAPS := :
|
2011-06-03 14:46:28 +04:00
|
|
|
endif
|
|
|
|
|
2008-09-27 21:55:45 +04:00
|
|
|
ifeq ($(FORCE_IO),1)
|
|
|
|
THINKPAD_EC_PARAM := force_io=1
|
|
|
|
else
|
2011-10-26 08:07:27 +04:00
|
|
|
THINKPAD_EC_PARAM :=
|
2008-09-27 21:55:45 +04:00
|
|
|
endif
|
|
|
|
|
2013-04-07 20:45:21 +04:00
|
|
|
ifneq ($(KERNELRELEASE),)
|
|
|
|
obj-m := $(TP_MODULES)
|
|
|
|
else
|
|
|
|
endif
|
|
|
|
|
2006-04-30 21:46:47 +04:00
|
|
|
DEBUG := 0
|
|
|
|
|
2023-08-05 12:25:08 +03:00
|
|
|
.PHONY: default clean modules load unload install check_hdaps \
|
2012-09-23 16:03:18 +04:00
|
|
|
check-ver set-version create-tgz create-rpm
|
2011-06-03 14:46:28 +04:00
|
|
|
export TP_MODULES
|
|
|
|
|
|
|
|
#####################################################################
|
|
|
|
# Main targets
|
|
|
|
|
|
|
|
default: modules
|
|
|
|
|
2006-08-04 19:21:10 +04:00
|
|
|
# Build the modules thinkpad_ec.ko, tp_smapi.ko and (if HDAPS=1) hdaps.ko
|
2008-09-27 21:55:45 +04:00
|
|
|
modules: $(KBUILD) $(patsubst %.o,%.c,$(TP_MODULES))
|
|
|
|
$(MAKE) -C $(KBUILD) M=$(PWD) O=$(KBUILD) modules
|
2011-06-03 14:46:28 +04:00
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -f tp_smapi.mod.* tp_smapi.o tp_smapi.ko .tp_smapi.*.cmd
|
2006-08-04 19:21:10 +04:00
|
|
|
rm -f thinkpad_ec.mod.* thinkpad_ec.o thinkpad_ec.ko .thinkpad_ec.*.cmd
|
2011-06-03 14:46:28 +04:00
|
|
|
rm -f hdaps.mod.* hdaps.o hdaps.ko .hdaps.*.cmd
|
2023-08-05 12:25:08 +03:00
|
|
|
rm -f *~ *.orig *.rej
|
|
|
|
rm -fr .tmp_versions Modules.symvers
|
2011-06-03 14:46:28 +04:00
|
|
|
|
2006-04-01 04:05:35 +04:00
|
|
|
load: check_hdaps unload modules
|
2006-07-20 03:19:42 +04:00
|
|
|
@( [ `id -u` == 0 ] || { echo "Must be root to load modules"; exit 1; } )
|
2008-09-27 21:55:45 +04:00
|
|
|
{ insmod ./thinkpad_ec.ko $(THINKPAD_EC_PARAM) && insmod ./tp_smapi.ko debug=$(DEBUG) && $(LOAD_HDAPS); }; :
|
2006-08-04 00:42:45 +04:00
|
|
|
@echo -e '\nRecent dmesg output:' ; dmesg | tail -10
|
2011-06-03 14:46:28 +04:00
|
|
|
|
|
|
|
unload:
|
2006-07-20 03:19:42 +04:00
|
|
|
@( [ `id -u` == 0 ] || { echo "Must be root to unload modules"; exit 1; } )
|
2011-06-03 14:46:28 +04:00
|
|
|
if lsmod | grep -q '^hdaps '; then rmmod hdaps; fi
|
|
|
|
if lsmod | grep -q '^tp_smapi '; then rmmod tp_smapi; fi
|
2006-08-04 19:21:10 +04:00
|
|
|
if lsmod | grep -q '^thinkpad_ec '; then rmmod thinkpad_ec; fi
|
|
|
|
if lsmod | grep -q '^tp_base '; then rmmod tp_base; fi # old thinkpad_ec
|
2011-06-03 14:46:28 +04:00
|
|
|
|
2006-04-01 04:05:35 +04:00
|
|
|
check_hdaps:
|
|
|
|
ifneq ($(HDAPS),1)
|
|
|
|
@if lsmod | grep -q '^hdaps '; then \
|
|
|
|
echo 'The hdaps driver is loaded. Use "make HDAPS=1 ..." to'\
|
2006-04-08 15:41:28 +04:00
|
|
|
'patch hdaps for compatibility with tp_smapi.'\
|
|
|
|
'This requires a kernel source tree.'; exit 1; fi
|
2006-04-01 04:05:35 +04:00
|
|
|
endif
|
|
|
|
|
2011-06-03 14:46:28 +04:00
|
|
|
install: modules
|
2006-07-20 03:19:42 +04:00
|
|
|
@( [ `id -u` == 0 ] || { echo "Must be root to install modules"; exit 1; } )
|
2006-08-04 19:21:10 +04:00
|
|
|
rm -f $(MOD_DIR)/$(TP_DIR)/{thinkpad_ec,tp_smapi,tp_base}.ko
|
2007-03-08 02:50:50 +03:00
|
|
|
rm -f $(MOD_DIR)/drivers/firmware/{thinkpad_ec,tp_smapi,tp_base}.ko
|
2006-08-04 19:21:10 +04:00
|
|
|
rm -f $(MOD_DIR)/extra/{thinkpad_ec,tp_smapi,tp_base}.ko
|
2011-06-03 14:46:28 +04:00
|
|
|
ifeq ($(HDAPS),1)
|
2011-10-26 08:01:44 +04:00
|
|
|
rm -f $(MOD_DIR)/drivers/platform/x86/hdaps.ko
|
2006-08-04 19:21:10 +04:00
|
|
|
rm -f $(MOD_DIR)/extra/hdaps.ko
|
2011-06-03 14:46:28 +04:00
|
|
|
endif
|
2008-09-27 21:55:45 +04:00
|
|
|
$(MAKE) -C $(KBUILD) M=$(PWD) O=$(KBUILD) modules_install
|
2013-04-06 17:43:17 +04:00
|
|
|
depmod $(KVER)
|
2011-06-03 14:46:28 +04:00
|
|
|
|
2006-04-30 21:46:47 +04:00
|
|
|
|
2011-06-03 14:46:28 +04:00
|
|
|
#####################################################################
|
2006-06-21 20:32:16 +04:00
|
|
|
# Tools for preparing a release. Ignore these.
|
|
|
|
|
2012-09-23 16:03:18 +04:00
|
|
|
TGZ=../tp_smapi-$(VER).tgz
|
|
|
|
|
|
|
|
check-ver:
|
2013-12-12 02:07:16 +04:00
|
|
|
@if [ -z "$(VER)" ]; then \
|
2012-09-23 16:03:18 +04:00
|
|
|
echo "VER is unset"; \
|
|
|
|
echo "run: $(MAKE) $(MAKECMDGOALS) VER=<release version>"; \
|
|
|
|
exit 1 ;\
|
|
|
|
fi
|
|
|
|
|
|
|
|
set-version: check-ver
|
2006-07-20 03:19:42 +04:00
|
|
|
perl -i -pe 's/^(tp_smapi version ).*/$${1}$(VER)/' README
|
2006-08-04 19:21:10 +04:00
|
|
|
perl -i -pe 's/^(#define TP_VERSION ").*/$${1}$(VER)"/' thinkpad_ec.c tp_smapi.c
|
2013-04-07 20:55:20 +04:00
|
|
|
perl -i -pe 's/^(TP_VER := ).*/$${1}$(VER)/' Makefile
|
2013-04-07 21:10:53 +04:00
|
|
|
perl -i -pe 's/^(PACKAGE_VERSION=").*/$${1}$(VER)"/' dkms.conf
|
2016-04-23 20:42:22 +03:00
|
|
|
perl -i -pe 's/^(%define version ).*/$${1}$(VER)/' tp_smapi.spec
|
2006-07-20 03:19:42 +04:00
|
|
|
|
2012-09-23 16:03:18 +04:00
|
|
|
create-tgz: check-ver
|
2011-07-28 21:05:30 +04:00
|
|
|
git archive --format=tar --prefix=tp_smapi-$(VER)/ HEAD | gzip -c > $(TGZ)
|
2006-09-03 15:24:34 +04:00
|
|
|
tar tzvf $(TGZ)
|
|
|
|
echo "Ready: $(TGZ)"
|
|
|
|
|
2012-09-23 16:03:18 +04:00
|
|
|
create-rpm: create-tgz
|
|
|
|
mkdir -p rpmbuild
|
|
|
|
rpmbuild -tb --define "_topdir $$PWD/rpmbuild" $(TGZ)
|
|
|
|
|
|
|
|
|
2011-06-03 14:46:28 +04:00
|
|
|
else
|
|
|
|
#####################################################################
|
2006-02-10 18:56:21 +03:00
|
|
|
# This part runs as a submake in kernel Makefile context:
|
2011-06-03 14:46:28 +04:00
|
|
|
|
2007-07-28 07:29:52 +04:00
|
|
|
EXTRA_CFLAGS := $(CFLAGS) -I$(M)/include
|
|
|
|
obj-m := $(TP_MODULES)
|
2011-06-03 14:46:28 +04:00
|
|
|
|
|
|
|
endif
|