-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
92 lines (69 loc) · 2.12 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
VERSION=0.6.0
TARGET=mx2000drv
SRCDIR = src
OBJDIR = build
CC = gcc
CFLAGS += -Wall -Wextra
CFLAGS += -Wfloat-equal -Wundef -Wshadow -Wpointer-arith -Wcast-align
CFLAGS += -Wstrict-prototypes -Wwrite-strings -ftrapv -Wpadded
CFLAGS += -fsanitize=address
#CFLAGS += -march=native
CFLAGS += -DVERSION=\"$(VERSION)\"
SFLAGS = -std=c99 -pedantic
INCLUDES = -I.
#LIBS = -lhidapi-libusb
SRCS = $(wildcard $(SRCDIR)/*.c)
OBJS=$(SRCS:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
PREFIX ?= /usr
BINDIR = $(DESTDIR)$(PREFIX)/bin
MANDIR = $(DESTDIR)$(PREFIX)/share/man/man1
BSHDIR = $(DESTDIR)$(PREFIX)/share/bash-completion/completions
ZSHDIR = $(DESTDIR)$(PREFIX)/share/zsh/site-functions
UDVDIR = $(DESTDIR)/etc/udev/rules.d
ifeq ($(OS),Windows_NT)
LIBS =
else
UNAME := $(shell uname -s)
ifeq ($(UNAME),Darwin)
LIBS = -lhidapi
BSHDIR = $(DESTDIR)$(PREFIX)/etc/bash_completion.d
else
LIBS = -lhidapi-libusb # or could use -lhidapi-hidraw
endif
endif
RULES = 99-mx2000.rules
all: CFLAGS += -O2
all: $(TARGET)
debug: CFLAGS += -O0 -g -DDEBUG
debug: $(TARGET)
#automatic recompile when makefile changes
$(OBJS): Makefile
#automatically creates build directory if it doesn't exist
dummy := $(shell test -d $(OBJDIR) || mkdir -p $(OBJDIR))
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) $(INCLUDES) -o $(TARGET) $(OBJS) $(LIBS)
$(OBJS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
$(CC) $(CFLAGS) $(SFLAGS) $(INCLUDES) -c -o $@ $<
install:
install -d -m 755 "$(BINDIR)"
install -d -m 755 "$(MANDIR)"
install -d -m 755 "$(UDVDIR)"
install -d -m 755 "$(BSHDIR)"
install -m 755 $(TARGET) "$(BINDIR)/$(TARGET)"
install -m 644 doc/$(TARGET).1 "$(MANDIR)/$(TARGET).1"
install -m 644 extra/$(RULES) "$(UDVDIR)/$(RULES)"
install -m 644 extra/bash_completion "$(BSHDIR)/$(TARGET)"
#install -m 644 extra/zsh_completion "$(ZSHDIR)/_$(TARGET)"
uninstall:
$(RM) "$(BINDIR)/$(TARGET)"
$(RM) "$(UDVDIR)/$(RULES)"
$(RM) "$(MANDIR)/$(TARGET).1"
$(RM) "$(BSHDIR)/$(TARGET)"
#$(RM) "$(ZSHDIR)/_$(TARGET)"
test:
$(CC) -o test test/*.c
doc:
a2x -v -d manpage -f manpage -a revnumber=$(VERSION) doc/$(TARGET).1.txt
clean:
$(RM) $(OBJS) $(TARGET)
.PHONY: all debug clean install uninstall test doc