From 4df90144ec8e79f04774d9813093f3d51969c3dd Mon Sep 17 00:00:00 2001 From: drlkf Date: Thu, 16 May 2024 20:36:11 +0200 Subject: [PATCH 1/3] feat: add debian build --- .gitignore | 6 ++++ CMakeLists.txt | 24 +++++++++++++ Dockerfile | 10 ++++++ Makefile | 61 ++++++++++++++++++++------------ README.md | 19 ++++++++++ debian/changelog | 5 +++ debian/compat | 1 + debian/control | 14 ++++++++ debian/footswitch-cli.udev | 12 +++++++ debian/rules | 4 +++ common.h => include/common.h | 0 debug.h => include/debug.h | 0 common.c => src/common.c | 0 debug.c => src/debug.c | 0 footswitch.c => src/footswitch.c | 0 scythe.c => src/scythe.c | 0 scythe2.c => src/scythe2.c | 0 17 files changed, 134 insertions(+), 22 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 Dockerfile create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/footswitch-cli.udev create mode 100755 debian/rules rename common.h => include/common.h (100%) rename debug.h => include/debug.h (100%) rename common.c => src/common.c (100%) rename debug.c => src/debug.c (100%) rename footswitch.c => src/footswitch.c (100%) rename scythe.c => src/scythe.c (100%) rename scythe2.c => src/scythe2.c (100%) diff --git a/.gitignore b/.gitignore index 5e3f69c..acbf608 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,9 @@ scythe scythe2 footswitch +obj*/ +*-build-deps_* +debian/files +debian/footswitch-cli/ +debian/footswitch-cli.substvars +debian/*debhelper* diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2811219 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.13) +project(footswitch-cli C) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build) +set(SRCDIR src) + +find_package(PkgConfig) +pkg_check_modules(HIDAPI REQUIRED hidapi-libusb) + +include_directories(${HIDAPI_INCLUDE_DIRS} include) +link_libraries(${HIDAPI_LIBRARIES}) +link_directories(src) + +foreach(exe IN ITEMS footswitch scythe scythe2) + add_executable(${exe}-cli + ${SRCDIR}/common.c + ${SRCDIR}/debug.c + ${SRCDIR}/${exe}.c + ) + + install(TARGETS ${exe}-cli + RUNTIME DESTINATION bin + ) +endforeach() diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9b0aef5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM debian:bookworm + +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update && \ + apt-get install -y devscripts equivs + +COPY . /build +WORKDIR /build +RUN mk-build-deps -i -t 'apt-get -y --no-install-recommends' && \ + dpkg-buildpackage -us -uc -b diff --git a/Makefile b/Makefile index 8167ce2..430aead 100644 --- a/Makefile +++ b/Makefile @@ -1,46 +1,63 @@ -PREFIX = /usr/local -UDEVPREFIX = /etc/udev +PREFIX := /usr/local +UDEVPREFIX := /etc/udev + +TARGETS := \ + footswitch \ + scythe \ + scythe2 + +INCDIR := include +SRCDIR := src +OBJDIR := obj + +COMMONSRC := \ + common.c \ + debug.c + +INSTALL := /usr/bin/install -c +INSTALLDATA := /usr/bin/install -c -m 644 +CFLAGS := -Wall -I$(INCDIR) +UNAME := $(shell uname) -INSTALL = /usr/bin/install -c -INSTALLDATA = /usr/bin/install -c -m 644 -CFLAGS = -Wall -UNAME := $(shell uname) ifeq ($(UNAME), Darwin) - CFLAGS += -DOSX $(shell pkg-config --cflags hidapi) - LDLIBS = $(shell pkg-config --libs hidapi) + CFLAGS += -DOSX $(shell pkg-config --cflags hidapi) + LDLIBS := $(shell pkg-config --libs hidapi) else ifeq ($(UNAME), Linux) - CFLAGS += $(shell pkg-config --cflags hidapi-libusb) - LDLIBS = $(shell pkg-config --libs hidapi-libusb) + CFLAGS += $(shell pkg-config --cflags hidapi-libusb) + LDLIBS := $(shell pkg-config --libs hidapi-libusb) else - LDLIBS = -lhidapi + LDLIBS := -lhidapi endif endif -all: footswitch scythe scythe2 +all: $(OBJDIR) $(TARGETS) + +$(OBJDIR): + mkdir $@ + +$(OBJDIR)/%.o: $(SRCDIR)/%.c + $(CC) $(CFLAGS) -c -o $@ $< -footswitch: footswitch.c common.c debug.c -scythe: scythe.c common.c debug.c -scythe2: scythe2.c common.c debug.c +$(TARGETS): %: $(patsubst %.c, $(OBJDIR)/%.o, $(COMMONSRC)) $(OBJDIR)/%.o + $(CC) $(CFLAGS) -o $@ $^ $(LDLIBS) install: all $(INSTALL) -d $(DESTDIR)$(PREFIX)/bin - $(INSTALL) footswitch $(DESTDIR)$(PREFIX)/bin - $(INSTALL) scythe $(DESTDIR)$(PREFIX)/bin - $(INSTALL) scythe2 $(DESTDIR)$(PREFIX)/bin + for target in $(TARGETS); do \ + $(INSTALL) "$$target" $(DESTDIR)$(PREFIX)/bin; \ + done ifeq ($(UNAME), Linux) $(INSTALL) -d $(DESTDIR)$(UDEVPREFIX)/rules.d $(INSTALLDATA) 19-footswitch.rules $(DESTDIR)$(UDEVPREFIX)/rules.d endif uninstall: - rm -f $(DESTDIR)$(PREFIX)/bin/footswitch - rm -f $(DESTDIR)$(PREFIX)/bin/scythe - rm -f $(DESTDIR)$(PREFIX)/bin/scythe2 + rm -f $(addprefix $(DESTDIR)$(PREFIX)/bin/, $(TARGETS)) ifeq ($(UNAME), Linux) rm -f $(DESTDIR)$(UDEVPREFIX)/rules.d/19-footswitch.rules endif clean: - rm -f scythe scythe2 footswitch *.o + rm -rf $(TARGETS) $(OBJDIR) diff --git a/README.md b/README.md index 6d5f47e..7956a5a 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,25 @@ The same kind of foot switches are used for building the popular [VIM Clutch][2] Building -------- +Debian +------ + +On a debian machine, provided you have `devscripts` and `equivs` installed: + +```bash +mk-build-deps -i +dpkg-buildpackage -us -uc -b +``` + +Or, you can build the package in a Docker container: + +```bash +docker build . +``` + +Other systems +------------- + The programs are using the [hidapi][3] library and should work on Linux and OSX. To build on Linux: sudo apt-get install libhidapi-dev diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..53eb06d --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +footswitch-cli (1.0.0) stable; urgency=medium + + * Initial release. + + -- drlkf Thu, 16 May 2024 19:27:47 +0200 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..9d60796 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +11 \ No newline at end of file diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..b358291 --- /dev/null +++ b/debian/control @@ -0,0 +1,14 @@ +Source: footswitch-cli +Section: utils +Priority: optional +Maintainer: Radoslav Gerganov +Build-Depends: + cmake, + libhidapi-dev, + pkg-config + +Package: footswitch-cli +Description: Command-line tools to configure PCsensor and Scythe foot switches. +Architecture: any +Depends: + libhidapi-libusb0 diff --git a/debian/footswitch-cli.udev b/debian/footswitch-cli.udev new file mode 100644 index 0000000..fdc4f77 --- /dev/null +++ b/debian/footswitch-cli.udev @@ -0,0 +1,12 @@ +# PCsensor +SUBSYSTEMS=="usb", ATTRS{idVendor}=="0c45", ATTRS{idProduct}=="7403", MODE="0666" +SUBSYSTEMS=="usb", ATTRS{idVendor}=="0c45", ATTRS{idProduct}=="7404", MODE="0666" +SUBSYSTEMS=="usb", ATTRS{idVendor}=="413d", ATTRS{idProduct}=="2107", MODE="0666" +SUBSYSTEMS=="usb", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="e026", MODE="0666" +SUBSYSTEMS=="usb", ATTRS{idVendor}=="3553", ATTRS{idProduct}=="b001", MODE="0666" + +# Scythe +SUBSYSTEMS=="usb", ATTRS{idVendor}=="0426", ATTRS{idProduct}=="3011", MODE="0666" + +# Scythe2 +SUBSYSTEMS=="usb", ATTRS{idVendor}=="055a", ATTRS{idProduct}=="0998", MODE="0666" diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..050e29a --- /dev/null +++ b/debian/rules @@ -0,0 +1,4 @@ +#!/usr/bin/make -f + +%: + dh $@ --buildsystem=cmake diff --git a/common.h b/include/common.h similarity index 100% rename from common.h rename to include/common.h diff --git a/debug.h b/include/debug.h similarity index 100% rename from debug.h rename to include/debug.h diff --git a/common.c b/src/common.c similarity index 100% rename from common.c rename to src/common.c diff --git a/debug.c b/src/debug.c similarity index 100% rename from debug.c rename to src/debug.c diff --git a/footswitch.c b/src/footswitch.c similarity index 100% rename from footswitch.c rename to src/footswitch.c diff --git a/scythe.c b/src/scythe.c similarity index 100% rename from scythe.c rename to src/scythe.c diff --git a/scythe2.c b/src/scythe2.c similarity index 100% rename from scythe2.c rename to src/scythe2.c From 7d4302cd1b7934cbba1544bb2de438e66213a57c Mon Sep 17 00:00:00 2001 From: drlkf Date: Fri, 17 May 2024 14:04:34 +0200 Subject: [PATCH 2/3] chore: remove cli suffix in binary names and package name --- .gitignore | 4 ++-- CMakeLists.txt | 6 +++--- debian/changelog | 2 +- debian/control | 4 ++-- debian/{footswitch-cli.udev => footswitch.udev} | 0 5 files changed, 8 insertions(+), 8 deletions(-) rename debian/{footswitch-cli.udev => footswitch.udev} (100%) diff --git a/.gitignore b/.gitignore index acbf608..066d1e3 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,6 @@ footswitch obj*/ *-build-deps_* debian/files -debian/footswitch-cli/ -debian/footswitch-cli.substvars +debian/footswitch/ +debian/footswitch.substvars debian/*debhelper* diff --git a/CMakeLists.txt b/CMakeLists.txt index 2811219..1d0ad13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.13) -project(footswitch-cli C) +project(footswitch C) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build) set(SRCDIR src) @@ -12,13 +12,13 @@ link_libraries(${HIDAPI_LIBRARIES}) link_directories(src) foreach(exe IN ITEMS footswitch scythe scythe2) - add_executable(${exe}-cli + add_executable(${exe} ${SRCDIR}/common.c ${SRCDIR}/debug.c ${SRCDIR}/${exe}.c ) - install(TARGETS ${exe}-cli + install(TARGETS ${exe} RUNTIME DESTINATION bin ) endforeach() diff --git a/debian/changelog b/debian/changelog index 53eb06d..0fecaae 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -footswitch-cli (1.0.0) stable; urgency=medium +footswitch (1.0.0) stable; urgency=medium * Initial release. diff --git a/debian/control b/debian/control index b358291..d13404a 100644 --- a/debian/control +++ b/debian/control @@ -1,4 +1,4 @@ -Source: footswitch-cli +Source: footswitch Section: utils Priority: optional Maintainer: Radoslav Gerganov @@ -7,7 +7,7 @@ Build-Depends: libhidapi-dev, pkg-config -Package: footswitch-cli +Package: footswitch Description: Command-line tools to configure PCsensor and Scythe foot switches. Architecture: any Depends: diff --git a/debian/footswitch-cli.udev b/debian/footswitch.udev similarity index 100% rename from debian/footswitch-cli.udev rename to debian/footswitch.udev From 0444fb3bc50bb9ca35976a2ec722e0fb46c646cf Mon Sep 17 00:00:00 2001 From: drlkf Date: Fri, 17 May 2024 14:11:54 +0200 Subject: [PATCH 3/3] ci: add debian build to github actions --- .github/workflows/build.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 917db4a..3aeca05 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,6 +20,20 @@ jobs: - name: Build run: make + deb-build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Dependencies + run: | + sudo apt-get update + sudo apt-get install -y devscripts equivs + sudo mk-build-deps -i -t 'apt-get -y --no-install-recommends' + - name: Build + run: dpkg-buildpackage -us -uc -b + osx-build: runs-on: macos-latest