Skip to content

Commit

Permalink
More idiomatic build process, plus Arch PKGBUILD
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyst committed Apr 3, 2022
1 parent df048ce commit a0e9d6b
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 24 deletions.
34 changes: 30 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
obj-m := src/hid-nintendo.o
obj-m += hid-nintendo.o

KERNELDIR ?= /lib/modules/$(shell uname -r)/build
KERNEL_RELEASE := $(shell uname -r)
KDIR := /lib/modules/$(KERNEL_RELEASE)/build

OBJ_FILE := $(obj-m)
SRC_FILE := $(OBJ_FILE:.o=.c)
CMD_FILE := .$(OBJ_FILE).cmd
MODNAME := $(OBJ_FILE:.o=)

all default: modules
install: modules_install

modules modules_install help clean:
$(MAKE) -C $(KERNELDIR) M=$(shell pwd) $@
$(OBJ_FILE) $(MODNAME).ko: $(SRC_FILE)

modules modules_install clean $(OBJ_FILE) $(MODNAME).ko:
$(MAKE) -C $(KDIR) M=$(CURDIR) $@

.PHONY: all modules clean install modules_install

load: modules
/usr/bin/modprobe ff_memless
/sbin/insmod $(MODNAME).ko

unload:
/usr/bin/modprobe --remove $(MODNAME)
/usr/bin/modprobe --remove ff_memless

reload: modules
/usr/bin/modprobe --remove $(MODNAME)
/usr/bin/modprobe --remove ff_memless
/usr/bin/modprobe ff_memless
/sbin/insmod $(MODNAME).ko

.PHONY: load unload reload
35 changes: 35 additions & 0 deletions PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Maintainer: Emily Strickland <linux(at)emily(dot)st>

_pkgbase=hid-nintendo-dkms
pkgname=hid-nintendo-dkms
pkgver=v1.3
pkgrel=1
pkgdesc='Nintendo Switch HID driver with NSO controller support'
url=https://github.com/emilyst/hid-nintendo
arch=(any)
license=(GPL)
depends=(dkms)
provides=(hid-nintendo-dkms)
conflicts=(hid-nintendo-nso-dkms)
source=(
Makefile
hid-nintendo.c
hid-ids.h
dkms.conf
)
b2sums=('e638a74c624cb218a21509e8194f02c34254ec2fcd9a740574f2a2f28fe3ef14691e654514cb05b52f94e49aedcdb0583ee1525bb896650f514fb85aafbb34e1'
'0424ac9a5e8ca64ede2b446e238b5935c8afb50f82388d23b96376b9c167dc356a76cb20c71c2ad073abb44080cbcc5cfe4e29ed2443670ae19aa8e1c93a9ef2'
'97e86380aa58ab564a8b03c00610fff66067634f5e31055f90e96ed840ca7bb0ea678cf7ddbf650f4f7b29993ba05c8958680f75db498fec673e89d8b06e7871'
'4ef5422163176e926ffdc3824639eb7cd60297bc5bcafebc035fc71806462dace993ea092cabe6986d62768cfdb7fd29d252a78274084c5afbe22f2ca6ef2dc0')

pkgver() {
git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
}

package() {
install -Dm644 ${source[@]} -t "${pkgdir}"/usr/src/${_pkgbase}-${pkgver}/

sed -e "s/^PACKAGE_NAME=.*$/PACKAGE_NAME=${_pkgbase}/" \
-e "s/^PACKAGE_VERSION=.*$/PACKAGE_VERSION=${pkgver}/" \
-i "${pkgdir}"/usr/src/${_pkgbase}-${pkgver}/dkms.conf
}
31 changes: 20 additions & 11 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,20 @@ This driver should be considered preliminary and not production-ready
Installation
------------

This driver can be installed from source on Linux using DKMS. Before
installation, you should install the Linux kernel headers and DKMS
support. Next, clone the source code.
This driver can be installed from source on Linux using DKMS. If you're
using Arch Linux, see the Package section below.

Before installation, you should install DKMS support. Next, clone the
source code.

git clone https://github.com/emilyst/hid-nintendo
cd hid-nintendo

Then run the following commands as root or using `sudo`.

dkms add .
dkms build hid-nintendo -v 1.2
dkms install hid-nintendo -v 1.2
dkms build hid-nintendo -v 1.3
dkms install hid-nintendo -v 1.3


Uninstallation
Expand All @@ -47,11 +49,22 @@ Uninstallation
To uninstall fully, run the following commands as root or using `sudo`.

modprobe -r hid_nintendo
dkms uninstall -m hid-nintendo -v 1.2
dkms remove -m hid-nintendo -v 1.2
dkms uninstall -m hid-nintendo -v 1.3
dkms remove -m hid-nintendo -v 1.3
rm -rf /usr/src/hid-nintendo-*


Arch Linux package installation
-------------------------------

On Arch Linux, instead of installing from source, it is possible to
build and install the module as a package. Run the following command
without using root permissions. You will be asked to confirm the
installation.

makepkg --clean --cleanbuild --syncdeps --install --force


Attribution
-----------

Expand All @@ -63,10 +76,6 @@ It builds on changes from:

* <https://github.com/nadiaholmquist/linux/tree/hid-nintendo>

For DKMS support, I made reference to:

* <https://github.com/nicman23/dkms-hid-nintendo>

For more background on my NSO support as implemented, see:

* <https://github.com/DanielOgorchock/linux/pull/35>
Expand Down
16 changes: 9 additions & 7 deletions dkms.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
PACKAGE_NAME="hid-nintendo"
PACKAGE_VERSION=1.2
MAKE="make -C $kernel_source_dir M=$dkms_tree/$PACKAGE_NAME/$PACKAGE_VERSION/build/src modules"
CLEAN="make -C $kernel_source_dir M=$dkms_tree/$PACKAGE_NAME/$PACKAGE_VERSION/build/src clean"
BUILT_MODULE_NAME[0]="hid-nintendo"
BUILT_MODULE_LOCATION[0]="src"
DEST_MODULE_LOCATION[0]="/kernel/drivers/hid/"
PACKAGE_NAME="$BUILT_MODULE_NAME-dkms"
PACKAGE_VERSION=v1.3

BUILT_MODULE_NAME="hid-nintendo"
DEST_MODULE_LOCATION="/extra"

CLEAN="make -C $kernel_source_dir M=$dkms_tree/$PACKAGE_NAME/$PACKAGE_VERSION/build clean"
MAKE="make -C $kernel_source_dir M=$dkms_tree/$PACKAGE_NAME/$PACKAGE_VERSION/build modules"

AUTOINSTALL=yes
File renamed without changes.
2 changes: 0 additions & 2 deletions src/hid-nintendo.c → hid-nintendo.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,6 @@ static int __nx_ctlr_hid_send(struct hid_device *hdev, u8 *data, size_t len)

static void nx_ctlr_wait_for_input_report(struct nx_ctlr *ctlr)
{
int ret;

/*
* If we are in the proper reporting mode, wait for an input
* report prior to sending the subcommand. This improves
Expand Down

0 comments on commit a0e9d6b

Please sign in to comment.