mirror of
https://github.com/mvp/uhubctl.git
synced 2026-05-17 08:26:29 +03:00
Use pkg-config when available
Remove custom handling for different platforms for CFLAGS and LDFLAGS
and prefer using pkg-config when available.
However, this is tested to still build ok on Linux on Mac howebrew
even if pkg-config is not available.
Closes #292, should also simplify issues raised by #142, #147, #289 and 5db248771e.
This commit is contained in:
31
Makefile
31
Makefile
@@ -16,37 +16,24 @@ CFLAGS ?= -g -O0
|
||||
CFLAGS += -Wall -Wextra -std=c99 -pedantic
|
||||
GIT_VERSION := $(shell git describe --match "v[0-9]*" --abbrev=8 --dirty --always --tags | cut -c2-)
|
||||
ifeq ($(GIT_VERSION),)
|
||||
GIT_VERSION := $(shell cat VERSION)
|
||||
GIT_VERSION := $(shell cat VERSION)
|
||||
endif
|
||||
CFLAGS += -DPROGRAM_VERSION=\"$(GIT_VERSION)\"
|
||||
|
||||
# Use hardening options on Linux
|
||||
ifeq ($(UNAME_S),Linux)
|
||||
LDFLAGS += -Wl,-zrelro,-znow -lusb-1.0
|
||||
LDFLAGS += -Wl,-zrelro,-znow
|
||||
endif
|
||||
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
ifneq ($(wildcard /opt/local/include),)
|
||||
# MacPorts
|
||||
CFLAGS += -I/opt/local/include
|
||||
LDFLAGS += -L/opt/local/lib
|
||||
endif
|
||||
# Use pkg-config if available
|
||||
ifneq (,$(shell which pkg-config))
|
||||
CFLAGS += $(shell pkg-config --cflags libusb-1.0)
|
||||
LDFLAGS += $(shell pkg-config --libs libusb-1.0)
|
||||
else
|
||||
# But it should still build if pkg-config is not available (e.g. Linux or Mac homebrew)
|
||||
LDFLAGS += -lusb-1.0
|
||||
endif
|
||||
|
||||
ifeq ($(UNAME_S),FreeBSD)
|
||||
LDFLAGS += -lusb
|
||||
endif
|
||||
|
||||
ifeq ($(UNAME_S),NetBSD)
|
||||
CFLAGS += $(shell pkg-config --cflags libusb-1.0)
|
||||
LDFLAGS += $(shell pkg-config --libs libusb-1.0)
|
||||
endif
|
||||
|
||||
ifeq ($(UNAME_S),SunOS)
|
||||
CFLAGS += $(shell pkg-config --cflags libusb-1.0)
|
||||
LDFLAGS += $(shell pkg-config --libs libusb-1.0)
|
||||
endif
|
||||
|
||||
PROGRAM = uhubctl
|
||||
|
||||
$(PROGRAM): $(PROGRAM).c
|
||||
|
||||
@@ -107,13 +107,14 @@ Compiling
|
||||
=========
|
||||
|
||||
This utility was tested to compile and work on Linux
|
||||
(Ubuntu/Debian, Redhat/Fedora/CentOS, Arch Linux, Gentoo, openSUSE, Buildroot), FreeBSD, NetBSD and Mac OS X.
|
||||
(Ubuntu/Debian, Redhat/Fedora/CentOS, Arch Linux, Gentoo, openSUSE, Buildroot), FreeBSD, NetBSD, SunOS and Mac OS X.
|
||||
|
||||
While `uhubctl` compiles on Windows, USB power switching does not work on Windows because `libusb`
|
||||
is using `winusb.sys` driver, which according to Microsoft does not support
|
||||
[necessary USB control requests](https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f680b63f-ca4f-4e52-baa9-9e64f8eee101).
|
||||
This may be fixed if `libusb` starts supporting different driver on Windows.
|
||||
|
||||
Note that it is highly recommended to have `pkg-config` installed (many platforms provide it by default).
|
||||
First, you need to install library libusb-1.0 (version 1.0.12 or later, 1.0.16 or later is recommended):
|
||||
|
||||
* Ubuntu: `sudo apt-get install libusb-1.0-0-dev`
|
||||
|
||||
Reference in New Issue
Block a user