mirror of
https://github.com/MatMoul/g810-led.git
synced 2024-12-23 09:16:11 +00:00
Implement device IO as a shared library
Provide make targets and build configuration to create a shared object for other systems/applications to use to control keyboard LEDs without the need for instantiating the g810-led process. Provide make targets for installing library and development files into environments, such as the current system or package builders. Currently preserves precious behavior of building g810-led binary as statically linked. Provides an alternative build target of "bin-linked" which will create a dynamically linked variant. Signed-off-by: Kevin Pearson <pearson.kevin.m@gmail.com>
This commit is contained in:
parent
d69ce2855f
commit
e5193b5985
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
g810-led.*
|
g810-led.*
|
||||||
bin/*
|
bin/*
|
||||||
|
lib/*
|
||||||
.
|
.
|
||||||
|
@ -45,5 +45,8 @@
|
|||||||
* Add wireshark dump effects
|
* Add wireshark dump effects
|
||||||
* Improve makefile
|
* Improve makefile
|
||||||
|
|
||||||
|
## [pearsonk](https://github.com/pearsonk) :
|
||||||
|
* Implement underlying device IO as a shared library
|
||||||
|
|
||||||
## [wextia](https://github.com/wextia) :
|
## [wextia](https://github.com/wextia) :
|
||||||
* Fixed incorrect markdown formatting in README.md
|
* Fixed incorrect markdown formatting in README.md
|
||||||
|
@ -38,6 +38,14 @@ Fedora :</br>
|
|||||||
`make` # for hidapi</br>
|
`make` # for hidapi</br>
|
||||||
`make LIB=libusb` # for libusb</br>
|
`make LIB=libusb` # for libusb</br>
|
||||||
`sudo make install`</br>
|
`sudo make install`</br>
|
||||||
|
`make install-lib` to install the libg810-led library.</br>
|
||||||
|
`make install-dev` to install the libg810-led library and headers for development.</br>
|
||||||
|
|
||||||
|
## Building the library :</br>
|
||||||
|
The library is built by default when running the `make` (default target "all").</br>
|
||||||
|
|
||||||
|
To specifically build the library as a standalone component: </br>
|
||||||
|
`make lib`</br>
|
||||||
|
|
||||||
## Update :</br>
|
## Update :</br>
|
||||||
Same as install, but your profile and reboot files are preserved.</br>
|
Same as install, but your profile and reboot files are preserved.</br>
|
||||||
|
10
README.md
10
README.md
@ -56,3 +56,13 @@ Linux led controller for Logitech G410, G610, G810 and G910 Keyboards.</br>
|
|||||||
## Samples with pipe (for effects) :</br>
|
## Samples with pipe (for effects) :</br>
|
||||||
`g810-led -pp < profilefile # Load a profile`</br>
|
`g810-led -pp < profilefile # Load a profile`</br>
|
||||||
`echo -e "k w ff0000\nk a ff0000\nk s ff0000\nk d ff0000\nc" | g810-led -pp # Set multiple keys`</br>
|
`echo -e "k w ff0000\nk a ff0000\nk s ff0000\nk d ff0000\nc" | g810-led -pp # Set multiple keys`</br>
|
||||||
|
|
||||||
|
## Building and linking against the libg810-led library :</br>
|
||||||
|
Include in implementing source files.</br>
|
||||||
|
```cpp
|
||||||
|
#include <g810-led/Keyboard.h>
|
||||||
|
```
|
||||||
|
To link, simply provide `-lg810-led` to the build flags.</br>
|
||||||
|
|
||||||
|
To build the g810-led application as a dynamically-linked variant, run the target:</br>
|
||||||
|
`make bin-linked`</br>
|
||||||
|
47
makefile
47
makefile
@ -8,22 +8,46 @@ else
|
|||||||
CPPFLAGS=-Dhidapi
|
CPPFLAGS=-Dhidapi
|
||||||
LDFLAGS=-lhidapi-hidraw
|
LDFLAGS=-lhidapi-hidraw
|
||||||
endif
|
endif
|
||||||
PROGN=g810-led
|
|
||||||
SYSTEMDDIR?=/usr/lib/systemd
|
SYSTEMDDIR?=/usr/lib/systemd
|
||||||
|
|
||||||
.PHONY: all debug clean setup install uninstall
|
prefix?=$(DESTDIR)/usr
|
||||||
|
libdir?=$(prefix)/lib
|
||||||
|
includedir?=$(prefix)/include
|
||||||
|
|
||||||
all: bin/$(PROGN)
|
# Program & versioning information
|
||||||
|
PROGN=g810-led
|
||||||
|
MAJOR=0
|
||||||
|
MINOR=1
|
||||||
|
MICRO=6
|
||||||
|
|
||||||
bin/$(PROGN): src/main.cpp src/helpers/*.cpp src/helpers/*.h src/classes/*.cpp src/classes/*.h
|
APPSRCS=src/main.cpp src/helpers/*.cpp src/helpers/*.h
|
||||||
|
LIBSRCS=src/classes/*.cpp src/classes/*.h
|
||||||
|
|
||||||
|
.PHONY: all debug clean setup install uninstall lib install-lib install-dev
|
||||||
|
|
||||||
|
all: lib/lib$(PROGN).so bin/$(PROGN)
|
||||||
|
|
||||||
|
bin/$(PROGN): $(APPSRCS) $(LIBSRCS)
|
||||||
@mkdir -p bin
|
@mkdir -p bin
|
||||||
$(CC) $(CPPFLAGS) $(CFLAGS) $^ -o $@ $(LDFLAGS)
|
$(CC) $(CPPFLAGS) $(CFLAGS) $^ -o $@ $(LDFLAGS)
|
||||||
|
|
||||||
debug: CFLAGS += -g -Wextra -pedantic
|
debug: CFLAGS += -g -Wextra -pedantic
|
||||||
debug: bin/$(PROGN)
|
debug: bin/$(PROGN)
|
||||||
|
|
||||||
|
lib/lib$(PROGN).so: $(LIBSRCS)
|
||||||
|
@mkdir -p lib
|
||||||
|
$(CC) $(CPPFLAGS) $(CFLAGS) -fPIC -shared -Wl,-soname,lib$(PROGN).so -o lib/lib$(PROGN).so.$(MAJOR).$(MINOR).$(MICRO) $^ $(LDFLAGS)
|
||||||
|
@ln -sf lib$(PROGN).so.$(MAJOR).$(MINOR).$(MICRO) lib/lib$(PROGN).so
|
||||||
|
|
||||||
|
bin-linked: lib/lib$(PROGN).so
|
||||||
|
@mkdir -p bin
|
||||||
|
$(CC) $(CPPFLAGS) $(CFLAGS) $(APPSRCS) -o bin/$(PROGN) $(LDFLAGS) -L./lib -l$(PROGN)
|
||||||
|
|
||||||
|
lib: lib/lib$(PROGN).so
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@rm -rf bin
|
@rm -rf bin
|
||||||
|
@rm -rf lib
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
@install -m 755 -d \
|
@install -m 755 -d \
|
||||||
@ -41,6 +65,15 @@ setup:
|
|||||||
cp systemd/$(PROGN).service $(DESTDIR)$(SYSTEMDDIR)/system && \
|
cp systemd/$(PROGN).service $(DESTDIR)$(SYSTEMDDIR)/system && \
|
||||||
cp systemd/$(PROGN)-reboot.service $(DESTDIR)$(SYSTEMDDIR)/system
|
cp systemd/$(PROGN)-reboot.service $(DESTDIR)$(SYSTEMDDIR)/system
|
||||||
|
|
||||||
|
install-lib: lib
|
||||||
|
@install -m 755 -d $(libdir)
|
||||||
|
@install -m 644 lib/lib$(PROGN).so.$(MAJOR).$(MINOR).$(MICRO) $(libdir)/
|
||||||
|
@ln -sf lib$(PROGN).so.$(MAJOR).$(MINOR).$(MICRO) $(libdir)/lib$(PROGN).so
|
||||||
|
|
||||||
|
install-dev: install-lib
|
||||||
|
@mkdir -p $(includedir)/$(PROGN)/
|
||||||
|
@install -m 644 src/classes/*.h $(includedir)/$(PROGN)
|
||||||
|
|
||||||
install: setup
|
install: setup
|
||||||
@test -s /etc/$(PROGN)/profile || \
|
@test -s /etc/$(PROGN)/profile || \
|
||||||
cp /etc/$(PROGN)/samples/group_keys /etc/$(PROGN)/profile
|
cp /etc/$(PROGN)/samples/group_keys /etc/$(PROGN)/profile
|
||||||
@ -53,6 +86,12 @@ install: setup
|
|||||||
systemctl enable $(PROGN) && \
|
systemctl enable $(PROGN) && \
|
||||||
systemctl enable $(PROGN)-reboot
|
systemctl enable $(PROGN)-reboot
|
||||||
|
|
||||||
|
uninstall-lib:
|
||||||
|
@rm -f $(libdir)/lib$(PROGN).so*
|
||||||
|
|
||||||
|
uninstall-dev:
|
||||||
|
@rm -rf $(includedir)/$(PROGN)
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
@test -s /usr/bin/systemd-run && \
|
@test -s /usr/bin/systemd-run && \
|
||||||
systemctl disable $(PROGN) && \
|
systemctl disable $(PROGN) && \
|
||||||
|
Loading…
Reference in New Issue
Block a user