-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
52 lines (41 loc) · 1.16 KB
/
Makefile
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
# uhidctl Makefile
#
UNAME := $(shell uname)
DESTDIR ?=
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
INSTALL := install
INSTALL_DIR := $(INSTALL) -m 755 -d
INSTALL_PROGRAM := $(INSTALL) -m 755
RM := rm -rf
CC ?= gcc
CFLAGS ?= -g -O0
CFLAGS += -Wall -Wextra -std=c99 -pedantic
GIT_VERSION := $(shell git describe --match "v[0-9]*" --abbrev=8 --dirty --tags | cut -c2-)
CFLAGS += -DPROGRAM_VERSION=\"$(GIT_VERSION)\"
ifeq ($(GIT_VERSION),)
GIT_VERSION := $(shell cat VERSION)
endif
HIDAPI := hidapi
ifeq ($(UNAME),Linux)
# Use hidapi-libusb backend on Linux
HIDAPI := hidapi-libusb
# Use hardening options on Linux
LDFLAGS += -Wl,-zrelro,-znow
endif
# Use pkg-config if available
ifneq (,$(shell which pkg-config))
CFLAGS += $(shell pkg-config --cflags ${HIDAPI})
LDFLAGS += $(shell pkg-config --libs ${HIDAPI})
else
# But it should still build if pkg-config is not available (e.g. Linux or Mac homebrew)
LDFLAGS += -l${HIDAPI}
endif
PROGRAM = uhidctl
$(PROGRAM): $(PROGRAM).c
$(CC) $(CFLAGS) [email protected] -o $@ $(LDFLAGS)
install:
$(INSTALL_DIR) $(DESTDIR)$(BINDIR)
$(INSTALL_PROGRAM) $(PROGRAM) $(DESTDIR)$(BINDIR)
clean:
$(RM) $(PROGRAM).o $(PROGRAM).dSYM $(PROGRAM)