1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
CFLAGS += -O2 -Wall
HIDAPI = hidraw
LIBS += -lhidapi-$(HIDAPI)
PYTHON_INCLUDE=$(shell python3-config --includes)
PREFIX=/usr
#Default 32 bit x86, raspberry pi, etc..
LIBDIR = $(PREFIX)/lib
#Catch x86_64 machines that use /usr/lib64 (RedHat)
ifneq ($(wildcard $(PREFIX)/lib64/.),)
LIBDIR = $(PREFIX)/lib64
endif
#Catch debian machines
DEB_HOST_MULTIARCH=$(shell dpkg-architecture -qDEB_HOST_MULTIARCH 2>/dev/null)
ifneq ($(DEB_HOST_MULTIARCH),)
ifneq ($(wildcard $(PREFIX)/lib/$(DEB_HOST_MULTIARCH)/.),)
LIBDIR = $(PREFIX)/lib/$(DEB_HOST_MULTIARCH)
endif
endif
all: usbrelay libusbrelay.so
python: usbrelay libusbrelay.so libusbrelay_py.so
libusbrelay.so: libusbrelay.c libusbrelay.h
$(CC) -shared -fPIC $(CPPFLAGS) $(CFLAGS) $< $(LDFLAGS) -o $@ $(LIBS)
usbrelay: usbrelay.c libusbrelay.h libusbrelay.so
$(CC) $(CPPFLAGS) $(CFLAGS) $< -lusbrelay -L./ $(LDFLAGS) -o $@ $(LIBS)
# Command to generate version number if running from git repo
DIR_VERSION = $(shell basename `pwd`)
GIT_VERSION = $(shell git describe --tags --match '[0-9].[0-9]*' --abbrev=10 --dirty)
# If .git/HEAD and/or .git/index exist, we generate git version with
# the command above and regenerate it whenever any of these files
# changes. If these files don't exist, we use ??? as the version.
gitversion.h: $(wildcard .git/HEAD .git/index)
echo "#define GITVERSION \"$(if $(word 1,$^),$(GIT_VERSION),$(DIR_VERSION))\"" > $@
usbrelay.c libusbrelay.c: gitversion.h
#We build this once directly for error checking purposes, then let python do the real build
libusbrelay_py.so: libusbrelay_py.c libusbrelay.so
$(CC) -shared -fPIC $(PYTHON_INCLUDE) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -L./ -lusbrelay -o $@ $<
python3 setup.py build
clean:
rm -f usbrelay
rm -f libusbrelay.so
rm -f libusbrelay_py.so
rm -rf build
rm -f gitversion.h
install: usbrelay libusbrelay.so
install -d $(DESTDIR)$(LIBDIR)
install -m 0755 libusbrelay.so $(DESTDIR)$(LIBDIR)
install -d $(DESTDIR)$(PREFIX)/bin
install -m 0755 usbrelay $(DESTDIR)$(PREFIX)/bin
install_py: install libusbrelay.so libusbrelay_py.so
python3 setup.py install --prefix=$(DESTDIR)
.PHONY: all clean install
|