mirror of
https://github.com/MatMoul/g810-led.git
synced 2024-12-23 01:06: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.*
|
||||
bin/*
|
||||
lib/*
|
||||
.
|
||||
|
@ -45,5 +45,8 @@
|
||||
* Add wireshark dump effects
|
||||
* Improve makefile
|
||||
|
||||
## [pearsonk](https://github.com/pearsonk) :
|
||||
* Implement underlying device IO as a shared library
|
||||
|
||||
## [wextia](https://github.com/wextia) :
|
||||
* Fixed incorrect markdown formatting in README.md
|
||||
|
@ -38,6 +38,14 @@ Fedora :</br>
|
||||
`make` # for hidapi</br>
|
||||
`make LIB=libusb` # for libusb</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>
|
||||
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>
|
||||
`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>
|
||||
|
||||
## 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
|
||||
LDFLAGS=-lhidapi-hidraw
|
||||
endif
|
||||
PROGN=g810-led
|
||||
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
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $^ -o $@ $(LDFLAGS)
|
||||
|
||||
debug: CFLAGS += -g -Wextra -pedantic
|
||||
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:
|
||||
@rm -rf bin
|
||||
@rm -rf lib
|
||||
|
||||
setup:
|
||||
@install -m 755 -d \
|
||||
@ -41,6 +65,15 @@ setup:
|
||||
cp systemd/$(PROGN).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
|
||||
@test -s /etc/$(PROGN)/profile || \
|
||||
cp /etc/$(PROGN)/samples/group_keys /etc/$(PROGN)/profile
|
||||
@ -53,6 +86,12 @@ install: setup
|
||||
systemctl enable $(PROGN) && \
|
||||
systemctl enable $(PROGN)-reboot
|
||||
|
||||
uninstall-lib:
|
||||
@rm -f $(libdir)/lib$(PROGN).so*
|
||||
|
||||
uninstall-dev:
|
||||
@rm -rf $(includedir)/$(PROGN)
|
||||
|
||||
uninstall:
|
||||
@test -s /usr/bin/systemd-run && \
|
||||
systemctl disable $(PROGN) && \
|
||||
|
Loading…
Reference in New Issue
Block a user