2006-02-10 18:56:21 +03:00
i f n d e f T P _ M O D U L E S
# This part runs as a normal, top-level Makefile:
2011-06-03 14:46:28 +04:00
KVER := $( shell uname -r)
KSRC := /lib/modules/$( KVER) /build
MOD_DIR := /lib/modules/$( KVER) /kernel
PWD := $( shell pwd )
IDIR := include/linux
TP_DIR := drivers/firmware
TP_MODULES := tp_base.o tp_smapi.o
i f e q ( $( 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
e l s e
2006-02-10 18:56:21 +03:00
LOAD_HDAPS := :
2011-06-03 14:46:28 +04:00
e n d i f
2006-04-30 21:46:47 +04:00
DEBUG := 0
2006-04-08 15:41:28 +04:00
i f n e q ( $( shell [ -f $ ( KSRC ) /include /linux /platform_device .h ] && echo 1) , 1 )
$( error This driver requires kernel 2.6.15 or newer.)
2011-06-03 14:46:28 +04:00
e n d i f
2006-04-01 04:05:35 +04:00
.PHONY : default clean modules load unload install patch check_hdaps
2011-06-03 14:46:28 +04:00
export TP_MODULES
#####################################################################
# Main targets
default : modules
# Build the modules tp_base.ko, tp_smapi.ko and (if HDAPS=1) hdaps.ko
modules : $( KSRC ) $( patsubst %.o ,%.c ,$ ( TP_MODULES ) )
$( MAKE) -C $( KSRC) M = $( PWD) modules
clean :
rm -f tp_smapi.mod.* tp_smapi.o tp_smapi.ko .tp_smapi.*.cmd
rm -f tp_base.mod.* tp_base.o tp_base.ko .tp_base.*.cmd
rm -f hdaps.mod.* hdaps.o hdaps.ko .hdaps.*.cmd
rm -f *~ diff/*~ *.orig diff/*.orig *.rej diff/*.rej
rm -f tp_smapi-*-for-*.patch
2006-04-30 21:46:47 +04:00
rm -fr .tmp_versions Modules.symvers
@if [ -f hdaps.c -a hdaps.c.flag -ot hdaps.c ] ; then \
echo 'WARNING: hdaps.c has changed since autogeneration, will not delete.' ; \
else \
rm -f hdaps.c hdaps.c.flag; \
fi
2011-06-03 14:46:28 +04:00
2006-04-01 04:05:35 +04:00
load : check_hdaps unload modules
2006-04-30 21:46:47 +04:00
{ insmod ./tp_base.ko debug = $( DEBUG) && \
insmod ./tp_smapi.ko debug = $( DEBUG) && \
2011-06-03 14:46:28 +04:00
$( LOAD_HDAPS) ; } ; :
2006-04-30 21:46:47 +04:00
@echo -e '\nRecent dmesg output:' ; dmesg | tail -8
2011-06-03 14:46:28 +04:00
unload :
if lsmod | grep -q '^hdaps ' ; then rmmod hdaps; fi
if lsmod | grep -q '^tp_smapi ' ; then rmmod tp_smapi; fi
if lsmod | grep -q '^tp_base ' ; then rmmod tp_base; fi
2006-04-01 04:05:35 +04:00
check_hdaps :
i f n e q ( $( 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
e n d i f
2011-06-03 14:46:28 +04:00
install : modules
rm -f $( MOD_DIR) /$( TP_DIR) /{ tp_base,tp_smapi} .ko
i f e q ( $( HDAPS ) , 1 )
rm -f $( MOD_DIR) /drivers/hwmon/hdaps.ko
e n d i f
$( MAKE) -C $( KSRC) M = $( PWD) modules_install
depmod -a
2006-04-30 21:46:47 +04:00
# Match hdaps.c from kernel tree into local copy.
# (First do a small change in our own patch if kernel 2.6.17.)
2006-04-08 15:41:28 +04:00
hdaps.c : $( KSRC ) /drivers /hwmon /hdaps .c diff /hdaps .diff
2006-04-30 21:46:47 +04:00
cat $( PWD) /diff/hdaps.diff \
| if grep -q 'ret = -ENODEV' $( KSRC) /drivers/hwmon/hdaps.c; then \
perl -pe 'm/^ \t\tret = -ENXIO;/ && s/NXIO/NODEV/' ; else cat; fi \
| patch -d $( KSRC) -p1 -o $( PWD) /hdaps.c
@touch -r hdaps.c hdaps.c.flag
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 }
ORG := linux-$( KVER) -orig
NEW := linux-$( KVER) -patched
PATCH := tp_smapi-$( TP_VER) -for-$( KVER) .patch
BASE_IN_PATCH := 1
SMAPI_IN_PATCH := 1
patch : hdaps .c
TMPDIR = ` mktemp -d /tmp/tp_smapi-patch.XXXXXX` && \
echo " Work directory: $$ TMPDIR " && \
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 \
2006-02-10 18:56:21 +03:00
patch --no-backup-if-mismatch -s -d $( NEW) -i $( PWD) /diff/Kconfig-tp_base.diff -p1 && \
2011-06-03 14:46:28 +04:00
cp $( PWD) /tp_base.c $( NEW) /$( TP_DIR) /tp_base.c && \
cp $( PWD) /tp_base.h $( NEW) /$( IDIR) /tp_base.h && \
cp $( PWD) /hdaps.c $( NEW) /drivers/hwmon/ && \
sed -i -e '$$aobj-$$(CONFIG_TP_BASE) += tp_base.o' $( NEW) /$( TP_DIR) /Makefile \
; fi && \
\
if [ " $( SMAPI_IN_PATCH) " = = 1 ] ; then \
sed -i -e '$$aobj-$$(CONFIG_TP_SMAPI) += tp_smapi.o' $( NEW) /$( TP_DIR) /Makefile && \
cp $( PWD) /tp_smapi.c $( NEW) /$( TP_DIR) /tp_smapi.c && \
patch --no-backup-if-mismatch -s -d $( NEW) /$( TP_DIR) -i $( PWD) /diff/tp_smapi-no_cd.diff -p1 && \
patch --no-backup-if-mismatch -s -d $( NEW) -i $( PWD) /diff/Kconfig-tp_smapi.diff -p1 && \
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 \
; fi && \
\
{ diff -Nurp $( ORG) $( NEW) > patch \
|| [ $$ ? -lt 2 ] ; } && \
{ diffstat patch; echo; echo; cat patch; } \
> $( PWD) /${ PATCH } && \
rm -r $$ TMPDIR
@echo -e " \nPatch file created:\n ${ PATCH } "
@echo -e " To apply, use:\n patch -p1 -d ${ KSRC } < ${ PATCH } "
e l s e
#####################################################################
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
2006-04-08 15:41:28 +04:00
CFLAGS := $( CFLAGS) -I$( M) /include
2006-02-10 18:56:21 +03:00
obj-m := $( TP_MODULES)
2011-06-03 14:46:28 +04:00
e n d i f