diff --git a/src/drivers/Makefile.raspbian b/src/drivers/Makefile.raspbian index c97eeda..2222e8d 100644 --- a/src/drivers/Makefile.raspbian +++ b/src/drivers/Makefile.raspbian @@ -1,16 +1,12 @@ MODULE:= rtmouse -TARGET:= $(MODULE).ko - -all: $(TARGET) - -$(TARGET): $(MODULE).c - make -C /usr/src/linux M=$(PWD) modules - obj-m:= $(MODULE).o +clean-files:= *.o *.ko *.mod.[co] *~ + +LINUX_SRC_DIR:=/usr/src/linux +VERBOSE:=0 -install: - insmod $(MODULE).ko +rtmouse.ko: rtmouse.c + make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) modules clean: - rm -f *.o *.order *.mod.c *.symvers *.ko - rm -rf .*.cmd .tmp_versions + make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) clean \ No newline at end of file diff --git a/src/drivers/Makefile.ubuntu14 b/src/drivers/Makefile.ubuntu14 index 815b1d6..7844404 100644 --- a/src/drivers/Makefile.ubuntu14 +++ b/src/drivers/Makefile.ubuntu14 @@ -1,15 +1,15 @@ -#Reference: http://www.devdrv.co.jp/linux/kernel26-makefile.htm -TARGET:= rtmouse.ko +MODULE:= rtmouse +obj-m:= $(MODULE).o +clean-files:= *.o *.ko *.mod.[co] *~ -all: ${TARGET} +LINUX_SRC_DIR:=/usr/src/linux-headers-$(shell uname -r) +VERBOSE:=0 rtmouse.ko: rtmouse.c - make -C /usr/src/linux-headers-`uname -r` M=`pwd` V=1 modules + make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) modules clean: - make -C /usr/src/linux-headers-`uname -r` M=`pwd` V=1 clean - -obj-m:= rtmouse.o + make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) clean install: rtmouse.ko cp ../../50-rtmouse.rules /etc/udev/rules.d/ @@ -17,4 +17,4 @@ install: rtmouse.ko uninstall: rm /etc/udev/rules.d/50-rtmouse.rules -clean-files := *.o *.ko *.mod.[co] *~ +#Reference: http://www.devdrv.co.jp/linux/kernel26-makefile.htm \ No newline at end of file diff --git a/utils/build_install.bash b/utils/build_install.bash index 2c2a4d9..03225cb 100755 --- a/utils/build_install.bash +++ b/utils/build_install.bash @@ -1,12 +1,19 @@ #!/usr/bin/env bash +set -eu SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0})/../; pwd) if [ -e /usr/src/linux ]; then + # Raspbian/Raspberry Pi OS $SRC_DIR/utils/build_install.raspbian.bash && exit 0 elif [ "$(ls /usr/src/linux-* 2> /dev/null)" != '' ]; then - $SRC_DIR/utils/build_install.ubuntu14.bash && exit 0 + # Ubuntu + if grep -q "Raspberry Pi 4" /proc/cpuinfo; then + $SRC_DIR/utils/build_install.raspi4ubuntu.bash && exit 0 + else + $SRC_DIR/utils/build_install.ubuntu14.bash && exit 0 + fi else + # Error bash -e $SRC_DIR/utils/print_env.bash "No kernel header files found." fi - diff --git a/utils/build_install.raspbian.bash b/utils/build_install.raspbian.bash index 504387c..19e4c99 100755 --- a/utils/build_install.raspbian.bash +++ b/utils/build_install.raspbian.bash @@ -1,13 +1,19 @@ -#!/bin/bash -vxe +#!/bin/bash -eu -dir=$(dirname $0)/../ -[ ! -e /usr/src/linux ] && { bash -e $dir/utils/print_env.bash "No kernel header files found."; exit 1; } -cd $dir/src/drivers/ +SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0})/../; pwd) + +# check kernel headers +[ ! -e /usr/src/linux ] && { bash -e $SRC_DIR/utils/print_env.bash "No kernel header files found."; exit 1; } + +# build and install the driver +cd $SRC_DIR/src/drivers/ rm Makefile ln -s Makefile.raspbian Makefile make clean make sudo insmod rtmouse.ko + +# initialize the driver sleep 1 sudo chmod 666 /dev/rt* echo 0 > /dev/rtmotoren0 diff --git a/utils/build_install.raspi4ubuntu.bash b/utils/build_install.raspi4ubuntu.bash new file mode 100755 index 0000000..0f52a9e --- /dev/null +++ b/utils/build_install.raspi4ubuntu.bash @@ -0,0 +1,21 @@ +#!/bin/bash -eu + +SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0})/../; pwd) + +# check kernel headers +[ ! -e /usr/src/linux-headers-$(uname -r) ] && { bash -e $SRC_DIR/utils/print_env.bash "No kernel header files found."; exit 1; } + +# build and install the driver +cd $SRC_DIR/src/drivers/ +rm Makefile +ln -s Makefile.ubuntu14 Makefile +make clean +# Update for Raspberry Pi 4 +sed -i -e "s/#define RASPBERRYPI 2/#define RASPBERRYPI 4/g" rtmouse.c +make +sudo insmod rtmouse.ko + +# initialize the driver +sleep 1 +sudo chmod 666 /dev/rt* +echo 0 > /dev/rtmotoren0 diff --git a/utils/build_install.ubuntu14.bash b/utils/build_install.ubuntu14.bash index 206e209..9087335 100755 --- a/utils/build_install.ubuntu14.bash +++ b/utils/build_install.ubuntu14.bash @@ -1,13 +1,19 @@ -#!/bin/bash -vxe +#!/bin/bash -eu -dir=$(dirname $0)/../ -[ ! -e /usr/src/linux-headers-$(uname -r) ] && { bash -e $dir/utils/print_env.bash "No kernel header files found."; exit 1; } -cd $dir/src/drivers/ +SRC_DIR=$(cd $(dirname ${BASH_SOURCE:-$0})/../; pwd) + +# check kernel headers +[ ! -e /usr/src/linux-headers-$(uname -r) ] && { bash -e $SRC_DIR/utils/print_env.bash "No kernel header files found."; exit 1; } + +# build and install the driver +cd $SRC_DIR/src/drivers/ rm Makefile ln -s Makefile.ubuntu14 Makefile make clean make sudo insmod rtmouse.ko + +# initialize the driver sleep 1 sudo chmod 666 /dev/rt* echo 0 > /dev/rtmotoren0