-
Notifications
You must be signed in to change notification settings - Fork 8
/
makefile
128 lines (85 loc) · 2.34 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
###
### OUTPUT FOLDERS
###
BUILD_DIR=out
BUILD_LIB_DIR=out/lib
###
### TARGETS
###
TARGETS += $(BUILD_DIR)/usb_cdc_device $(BUILD_DIR)/usb_mouse_device
all: $(TARGETS)
###
### COMMON FLAGS AND RULES
###
CFLAGS += -std=c99 \
-pedantic -Wall -Werror -Wextra \
-Wdouble-promotion -Wstrict-prototypes -Wcast-qual \
-Wmissing-prototypes -Winit-self -Wpointer-arith -Wshadow -MMD -MP -O3 \
-fno-var-tracking-assignments -ffunction-sections -fdata-sections
CFLAGS += -D_GNU_SOURCE
$(BUILD_DIR):
@mkdir -p $(BUILD_DIR)
$(BUILD_LIB_DIR):
@mkdir -p $(BUILD_LIB_DIR)
$(BUILD_DIR)/%.o : %.c | $(BUILD_DIR)
@echo " Compiling $(notdir $<)"
@$(COMPILE.c) $(CFLAGS-$@) -o $@ $<
###
### GENERIC DEPENDS
###
SOURCES := $(shell find src/ -iname *.c)
DEPENDS := $(addprefix $(BUILD_DIR)/, $(notdir $(SOURCES:.c=.d)))
-include $(DEPENDS)
###
### BUILD USBIP_SERVER LIBRARY
###
vpath %.c src/lib
CFLAGS += -Isrc/lib -Iinclude
LIBRARY_SOURCES = \
tcpip_server.c \
usbip_device.c \
usbip_protocol.c \
usbip_server.c
LIBRARY_OBJECTS = $(addprefix $(BUILD_DIR)/, $(LIBRARY_SOURCES:.c=.o))
LIBRARY_NAME = libusbip_server.a
LIBRARY_ARCHIVE = $(addprefix $(BUILD_LIB_DIR)/, $(LIBRARY_NAME))
lib: $(LIBRARY_ARCHIVE)
$(LIBRARY_ARCHIVE): $(LIBRARY_OBJECTS) | $(BUILD_LIB_DIR)
@echo " Creating library $(notdir $@)"
@ar cr $@ $^
###
### BUILD USB_CDC DEVICE
###
vpath %.c src/usb_cdc
CFLAGS += -I src/usb_cdc
USB_CDC_SOURCES = \
usb_cdc_device.c
USB_CDC_OBJECTS = $(addprefix $(BUILD_DIR)/, $(USB_CDC_SOURCES:.c=.o))
USB_CDC_OBJECTS += $(LIBRARY_ARCHIVE)
$(BUILD_DIR)/usb_cdc_device: $(USB_CDC_OBJECTS) | $(BUILD_DIR)
@echo " Linking $(notdir $<) to $(notdir $@)"
@$(LINK.o) -Wl,--start-group $^ -Wl,--end-group -o $@
###
### BUILD USB_MOUSE DEVICE
###
vpath %.c src/usb_mouse
CFLAGS += -I src/usb_mouse
USB_MOUSE_SOURCES = \
usb_mouse_device.c
USB_MOUSE_OBJECTS = $(addprefix $(BUILD_DIR)/, $(USB_MOUSE_SOURCES:.c=.o))
USB_MOUSE_OBJECTS += $(LIBRARY_ARCHIVE)
$(BUILD_DIR)/usb_mouse_device: $(USB_MOUSE_OBJECTS) | $(BUILD_DIR)
@echo " Linking $(notdir $<) to $(notdir $@)"
@$(LINK.o) -Wl,--start-group $^ -Wl,--end-group -lm -o $@
###
### CLEAN
###
clean:
rm -rf $(BUILD_DIR)
###
### FORMAT SOURCE FILES WITH CLANG FORMAT
###
format:
@find src/. -iname *.h -o -name *.c | xargs clang-format -i
@find include/. -iname *.h | xargs clang-format -i
git status