-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
132 lines (112 loc) · 2.64 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#
# Copyright 2014, 2021-2022 NXP
#
# SPDX-License-Identifier: BSD-3-Clause
#
# NXP USBSIO Library Makefile
#
CC ?= gcc
CXX ?= g++
AR = ar -rcs
UNAME := $(shell uname)
UNAME_M := $(shell uname -m)
VPATH := src
ifeq ($(UNAME), FreeBSD)
SRCS := lpcusbsio.c hid.c
CFLAGS += -Iinclude -Isrc/hid_api/freebsd -fPIC -Wall -c
else
SRCS := lpcusbsio.c hid.c
CFLAGS += -Iinclude -Isrc/hid_api/hidapi -fPIC -Wall -c
endif
dir_guard = @mkdir -p $(@D)
#
# Linux
#
ifeq ($(UNAME), Linux)
# do not forget to
# sudo apt-get install libudev-dev
# sudo apt-get install libusb-1.0-0-dev
# sudo chmod 666 /dev/hidraw* or add udev rule (use lsusb to find out VID/PID)
# KERNEL=="hidraw*", ATTRS{idVendor}=="1fc9", ATTRS{idProduct}=="XXXX", MODE="0666"
BINDIR = linux_$(UNAME_M)
VPATH += src/hid_api/linux
LDFLAGS += -shared
LIBS += `pkg-config libusb-1.0 libudev --libs`
LIBNAME_A = libusbsio.a
LIBNAME_SO = libusbsio.so
endif
ifeq ($(UNAME), FreeBSD)
BINDIR = freebsd_$(UNAME_M)
VPATH += src/hid_api/freebsd
LDFLAGS += -shared
CFLAGS += `pkg-config libusb-1.0 libudev hidapi --cflags`
LDFLAGS += `pkg-config libusb-1.0 libudev hidapi --libs`
LIBNAME_A = libusbsio.a
LIBNAME_SO = libusbsio.so
endif
#
# macOS
#
ifeq ($(UNAME), Darwin)
BINDIR = osx_$(UNAME_M)
VPATH += src/hid_api/mac
LDFLAGS += -dynamiclib
LIBS += -framework IOKit -framework CoreFoundation -framework AppKit
LIBNAME_A = libusbsio.a
LIBNAME_SO = libusbsio.dylib
endif
OBJS = $(SRCS:.c=.o)
#
# Debug build settings
#
DBGDIR = bin_debug/$(BINDIR)
DBGOBJ = obj/debug
DBGLIB_A = $(DBGDIR)/$(LIBNAME_A)
DBGLIB_SO = $(DBGDIR)/$(LIBNAME_SO)
DBGOBJS = $(addprefix obj/debug/, $(OBJS))
DBGCFLAGS = $(CFLAGS) -g -O0 -DDEBUG -D_DEBUG
#
# Release build settings
#
RELDIR = bin/$(BINDIR)
RELOBJ = obj/release
RELLIB_A = $(RELDIR)/$(LIBNAME_A)
RELLIB_SO = $(RELDIR)/$(LIBNAME_SO)
RELOBJS = $(addprefix $(RELOBJ)/, $(OBJS))
RELCFLAGS = $(CFLAGS) -O3 -DNDEBUG
#
# Rules
#
all: release
both: release debug
#
# Debug rules
#
debug: $(DBGLIB_A) $(DBGLIB_SO)
$(DBGLIB_A): $(DBGOBJS)
$(dir_guard)
$(AR) $@ $^
$(DBGLIB_SO): $(DBGOBJS)
$(dir_guard)
$(CC) -o $@ $(LDFLAGS) $^ $(LIBS)
$(DBGOBJ)/%.o: %.c
$(dir_guard)
$(CC) -o $@ $(DBGCFLAGS) $<
#
# Release rules
#
release: $(RELLIB_A) $(RELLIB_SO)
$(RELLIB_A): $(RELOBJS)
$(dir_guard)
$(AR) $@ $^
$(RELLIB_SO): $(RELOBJS)
$(dir_guard)
$(CC) -o $@ $(LDFLAGS) $^ $(LIBS)
$(RELOBJ)/%.o: %.c
$(dir_guard)
$(CC) -o $@ $(RELCFLAGS) $<
clean:
rm -f $(RELOBJS) $(RELLIB_A) $(RELLIB_SO)
rm -f $(DBGOBJS) $(DBGLIB_A) $(DBGLIB_SO)
.PHONY: clean
.PHONY: all