-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
70 lines (56 loc) · 2.41 KB
/
Copy pathMakefile
File metadata and controls
70 lines (56 loc) · 2.41 KB
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
69
70
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
CC ?= gcc
CFLAGS ?= -O3 -flto -fno-plt -ffunction-sections -fdata-sections -Wall -Wextra -Wpedantic -Wshadow -Wmissing-prototypes -std=c11
LDFLAGS ?= -flto -fno-plt -Wl,--gc-sections -s
DEPFLAGS ?= -MMD -MP
WERROR ?=
VERSION ?= $(shell sed -n 's/^#define VERSION "\(.*\)"/\1/p' tui.h)
DISTRO ?= generic
ARCH ?= $(shell uname -m)
DIST_DIR ?= dist
DIST_NAME = matebook-gestures-$(VERSION)-linux-$(ARCH)-$(DISTRO)
DIST_DOCS = README.md LICENSE CHANGELOG.md SECURITY.md
CORE_SRCS = keys.c protocol.c config.c presets.c haptics.c uinput.c force.c daemon.c
CORE_OBJS = $(CORE_SRCS:.c=.o)
DEPS = main.d main_daemon.d cli.d tui.d $(CORE_SRCS:.c=.d)
TEST_BIN = tests/test_engine
BIN_CLI = matebook-gestures
BIN_DAEMON = matebook-gestures-daemon
all: $(BIN_CLI) $(BIN_DAEMON)
$(BIN_CLI): main.o cli.o tui.o $(CORE_OBJS)
$(CC) $(LDFLAGS) -o $@ $^ -lncurses
$(BIN_DAEMON): main_daemon.o $(CORE_OBJS)
$(CC) $(LDFLAGS) -o $@ $^
$(TEST_BIN): tests/test_engine.c $(CORE_SRCS)
$(CC) $(CFLAGS) $(WERROR) -D_GNU_SOURCE -I. -o $@ $^
test: $(TEST_BIN)
./$(TEST_BIN)
dist: all test
@test -n "$(VERSION)" || { echo "could not determine VERSION from tui.h" >&2; exit 1; }
rm -rf "$(DIST_DIR)/$(DIST_NAME)"
install -d "$(DIST_DIR)/$(DIST_NAME)/docs"
install -m755 $(BIN_CLI) $(BIN_DAEMON) "$(DIST_DIR)/$(DIST_NAME)/"
install -m644 99-matebook-gestures.rules $(DIST_DOCS) "$(DIST_DIR)/$(DIST_NAME)/"
install -m644 docs/install-and-build.md docs/experimental-features.md "$(DIST_DIR)/$(DIST_NAME)/docs/"
printf '%s\n' \
"matebook-gestures $(VERSION)" \
"Target: $(DISTRO) ($(ARCH))" \
"Built: $$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
> "$(DIST_DIR)/$(DIST_NAME)/BUILD-INFO"
tar -C "$(DIST_DIR)" -czf "$(DIST_DIR)/$(DIST_NAME).tar.gz" "$(DIST_NAME)"
rm -rf "$(DIST_DIR)/$(DIST_NAME)"
%.o: %.c
$(CC) $(CFLAGS) $(WERROR) $(DEPFLAGS) -D_GNU_SOURCE -c -o $@ $<
clean:
rm -f *.o *.d $(BIN_CLI) $(BIN_DAEMON) $(TEST_BIN)
install: $(BIN_CLI) $(BIN_DAEMON)
install -Dm755 $(BIN_CLI) $(DESTDIR)$(BINDIR)/$(BIN_CLI)
install -Dm755 $(BIN_DAEMON) $(DESTDIR)$(BINDIR)/$(BIN_DAEMON)
install -Dm644 99-matebook-gestures.rules $(DESTDIR)/etc/udev/rules.d/99-matebook-gestures.rules
uninstall:
rm -f $(DESTDIR)$(BINDIR)/$(BIN_CLI)
rm -f $(DESTDIR)$(BINDIR)/$(BIN_DAEMON)
rm -f $(DESTDIR)/etc/udev/rules.d/99-matebook-gestures.rules
-include $(DEPS)
.PHONY: all clean dist install test uninstall