tp_smapi/Makefile

157 lines
5.5 KiB
Makefile
Raw Normal View History

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)
2011-06-03 14:46:28 +04:00
KVER := $(shell uname -r)
2006-08-17 12:51:02 +04:00
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
2007-03-08 02:50:50 +03:00
TP_DIR := drivers/misc
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
2006-04-30 21:46:47 +04:00
DEBUG := 0
2007-03-08 02:50:50 +03:00
ifneq ($(shell [ -f $(KSRC)/include/linux/aio_abi.h ] && echo 1),1)
2007-07-28 07:29:52 +04:00
$(error This driver requires kernel 2.6.19 or newer, and matching kernel sources. You may need to override KVER=$(KVER) or KSRC=$(KSRC) or KBUILD=$(KBUILD) or MOD_DIR=$(MOD_DIR))
2011-06-03 14:46:28 +04:00
endif
2006-06-21 20:32:16 +04:00
.PHONY: default clean modules load unload install patch check_hdaps mk-hdaps.diff
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
2007-03-08 02:50:50 +03:00
modules: $(KSRC) $(patsubst %.o,%.c,$(TP_MODULES))
2006-08-17 12:51:02 +04:00
$(MAKE) -C $(KSRC) 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
rm -f *~ diff/*~ *.orig diff/*.orig *.rej diff/*.rej
2006-08-04 00:42:45 +04:00
rm -f tp_smapi-*-for-*.patch
2006-06-21 20:32:16 +04:00
rm -fr .tmp_versions Modules.symvers diff/hdaps.diff.tmp
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; } )
2006-08-05 06:31:02 +04:00
{ insmod ./thinkpad_ec.ko &&\
2006-04-30 21:46:47 +04:00
insmod ./tp_smapi.ko debug=$(DEBUG) &&\
2011-06-03 14:46:28 +04:00
$(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)
rm -f $(MOD_DIR)/drivers/hwmon/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
2006-08-17 12:51:02 +04:00
$(MAKE) -C $(KSRC) M=$(PWD) O=$(KBUILD) modules_install
2011-06-03 14:46:28 +04:00
depmod -a
2006-04-30 21:46:47 +04:00
2011-06-03 14:46:28 +04:00
#####################################################################
2006-02-10 18:56:21 +03:00
# Generate a stand-alone kernel patch
2011-06-03 14:46:28 +04:00
TP_VER := ${shell sed -ne 's/^\#define TP_VERSION \"\(.*\)\"/\1/gp' tp_smapi.c}
2006-08-04 19:21:10 +04:00
ORG := a
NEW := b
2011-06-03 14:46:28 +04:00
PATCH := tp_smapi-$(TP_VER)-for-$(KVER).patch
BASE_IN_PATCH := 1
SMAPI_IN_PATCH := 1
2006-08-04 19:21:10 +04:00
HDAPS_IN_PATCH := 1
2011-06-03 14:46:28 +04:00
2006-08-04 00:42:45 +04:00
patch:
2007-03-08 02:50:50 +03:00
@TMPDIR=`mktemp -d /tmp/tp_smapi-patch.XXXXXX` &&\
echo "Working directory: $$TMPDIR" &&\
2011-06-03 14:46:28 +04:00
cd $$TMPDIR &&\
mkdir -p $(ORG)/$(TP_DIR) &&\
mkdir -p $(ORG)/$(IDIR) &&\
mkdir -p $(ORG)/drivers/hwmon &&\
cp $(KSRC)/$(TP_DIR)/{Kconfig,Makefile} $(ORG)/$(TP_DIR) &&\
cp $(KSRC)/drivers/hwmon/{Kconfig,hdaps.c} $(ORG)/drivers/hwmon/ &&\
cp -r $(ORG) $(NEW) &&\
\
if [ "$(BASE_IN_PATCH)" == 1 ]; then \
2007-03-08 02:50:50 +03:00
cp $(PWD)/thinkpad_ec.c $(NEW)/$(TP_DIR)/thinkpad_ec.c &&\
cp $(PWD)/thinkpad_ec.h $(NEW)/$(IDIR)/thinkpad_ec.h &&\
2007-07-28 07:29:52 +04:00
perl -i -pe 'print `cat $(PWD)/diff/Kconfig-thinkpad_ec.add` if m/^(endmenu|endif # MISC_DEVICES)$$/' $(NEW)/$(TP_DIR)/Kconfig &&\
2007-03-08 02:50:50 +03:00
sed -i -e '$$aobj-$$(CONFIG_THINKPAD_EC) += thinkpad_ec.o' $(NEW)/$(TP_DIR)/Makefile \
2006-08-04 19:21:10 +04:00
; fi &&\
\
if [ "$(HDAPS_IN_PATCH)" == 1 ]; then \
2007-03-08 02:50:50 +03:00
cp $(PWD)/hdaps.c $(NEW)/drivers/hwmon/ &&\
perl -i -0777 -pe 's/(config SENSORS_HDAPS\n\ttristate [^\n]+\n\tdepends [^\n]+\n)/$$1\tselect THINKPAD_EC\n/' $(NEW)/drivers/hwmon/Kconfig \
2011-06-03 14:46:28 +04:00
; fi &&\
\
if [ "$(SMAPI_IN_PATCH)" == 1 ]; then \
2007-03-08 02:50:50 +03:00
sed -i -e '$$aobj-$$(CONFIG_TP_SMAPI) += tp_smapi.o' $(NEW)/$(TP_DIR)/Makefile &&\
2007-07-28 07:29:52 +04:00
perl -i -pe 'print `cat $(PWD)/diff/Kconfig-tp_smapi.add` if m/^(endmenu|endif # MISC_DEVICES)$$/' $(NEW)/$(TP_DIR)/Kconfig &&\
2007-03-08 02:50:50 +03:00
cp $(PWD)/tp_smapi.c $(NEW)/$(TP_DIR)/tp_smapi.c &&\
mkdir -p $(NEW)/Documentation &&\
perl -0777 -pe 's/\n(Installation\n---+|Conflict with HDAPS\n---+|Files in this package\n---+|Setting and getting CD-ROM speed:\n).*?\n(?=[^\n]*\n-----)/\n/gs' $(PWD)/README > $(NEW)/Documentation/tp_smapi.txt \
2011-06-03 14:46:28 +04:00
; fi &&\
\
2006-06-21 20:32:16 +04:00
{ diff -dNurp $(ORG) $(NEW) > patch \
2011-06-03 14:46:28 +04:00
|| [ $$? -lt 2 ]; } &&\
2006-08-04 19:21:10 +04:00
{ echo "Generated for $(KVER) in $(KSRC)"; echo; diffstat patch; echo; echo; cat patch; } \
2011-06-03 14:46:28 +04:00
> $(PWD)/${PATCH} &&\
rm -r $$TMPDIR
2007-03-08 02:50:50 +03:00
@echo
@diffstat ${PATCH}
2011-06-03 14:46:28 +04:00
@echo -e "\nPatch file created:\n ${PATCH}"
@echo -e "To apply, use:\n patch -p1 -d ${KSRC} < ${PATCH}"
2006-06-21 20:32:16 +04:00
#####################################################################
# Tools for preparing a release. Ignore these.
2006-07-20 03:19:42 +04:00
set-version:
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
2006-07-20 03:19:42 +04:00
2006-09-03 15:24:34 +04:00
TGZ=../tp_smapi-$(VER).tgz
create-tgz:
git-archive --format=tar --prefix=tp_smapi-$(VER)/ HEAD | gzip -c > $(TGZ)
tar tzvf $(TGZ)
echo "Ready: $(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