diff --git a/.gitignore b/.gitignore index e31e806..698d71a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ g810-led.* bin/* +lib/* . diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 0c89cb7..e537304 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -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 diff --git a/INSTALL.md b/INSTALL.md index d83547f..85cc50b 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -38,6 +38,14 @@ Fedora :
`make` # for hidapi
`make LIB=libusb` # for libusb
`sudo make install`
+`make install-lib` to install the libg810-led library.
+`make install-dev` to install the libg810-led library and headers for development.
+ +## Building the library :
+The library is built by default when running the `make` (default target "all").
+ +To specifically build the library as a standalone component:
+`make lib`
## Update :
Same as install, but your profile and reboot files are preserved.
diff --git a/README.md b/README.md index 7b6cfed..4c1cbb1 100644 --- a/README.md +++ b/README.md @@ -56,3 +56,13 @@ Linux led controller for Logitech G410, G610, G810 and G910 Keyboards.
## Samples with pipe (for effects) :
`g810-led -pp < profilefile # Load a profile`
`echo -e "k w ff0000\nk a ff0000\nk s ff0000\nk d ff0000\nc" | g810-led -pp # Set multiple keys`
+ +## Building and linking against the libg810-led library :
+Include in implementing source files.
+```cpp +#include +``` +To link, simply provide `-lg810-led` to the build flags.
+ +To build the g810-led application as a dynamically-linked variant, run the target:
+`make bin-linked`
diff --git a/makefile b/makefile index 850dda5..a82f339 100644 --- a/makefile +++ b/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 \ @@ -40,7 +64,16 @@ setup: install -m 755 -d $(DESTDIR)$(SYSTEMDDIR)/system && \ 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 @@ -52,7 +85,13 @@ install: setup systemctl start $(PROGN) && \ 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) && \