-
Notifications
You must be signed in to change notification settings - Fork 12
/
Makefile
136 lines (112 loc) · 3.42 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
133
134
135
136
##################################################
# Cross-Platform Makefile for the ev3duder utility
#
# Ahmad Fatoum
# Hochschule Aschaffenburg
# 2015-06-17
##################################################
BIN_NAME = ev3duder
VERSION = 0.4.0
# tip: CC=clang CFLAGS=-Weverything shows all GNU extensions
CFLAGS += -std=gnu99 -Wall -Wextra -DVERSION='"$(VERSION)"'
SRCDIR = src
OBJDIR = build
SRCS = src/main.c src/packets.c src/run.c src/info.c src/up.c src/ls.c \
src/rm.c src/mkdir.c src/mkrbf.c src/dl.c src/listen.c src/send.c \
src/tunnel.c src/tcp.c src/bl_enter.c src/bl_exit.c src/bl_info.c \
src/bl_install.c src/crc32.c src/closehnd.c src/vmexec.c \
src/uf2_helper.c src/uf2_pack.c src/uf2_unpack.c
INC += -Ihidapi/ -Ihidapi/hidapi/
####################
CREATE_BUILD_DIR := $(shell mkdir build 2>&1)
CC ?= gcc
ifeq ($(OS),Windows_NT)
RM ?= del /Q
## Win32
ifneq ($(MAKECMDGOALS),cross)
CFLAGS += -DCONFIGURATION='"HIDAPI/hid.dll"' -DSYSTEM='"Windows"'
# TODO: remove all %zu prints altogether?
CFLAGS += -Wno-unused-value -D__USE_MINGW_ANSI_STDIO=1
SRCS += src/bt-win.c
HIDSRC += hidapi/windows/hid.c
LDFLAGS += -lsetupapi -lws2_32
BIN_NAME := $(addsuffix .exe, $(BIN_NAME))
# CodeSourcery prefix
endif
CROSS_PREFIX = arm-none-linux-gnueabi-g
else
UNAME = $(shell uname -s)
## Linux
ifeq ($(UNAME),Linux)
CFLAGS += -DCONFIGURATION='"HIDAPI/hidraw"' -DSYSTEM='"Linux"'
HIDSRC += hidapi/linux/hid.c
HIDFLAGS += `pkg-config libudev --cflags`
LDFLAGS += `pkg-config libudev --libs` -lrt -lpthread
INSTALL = $(shell sh udev.sh)
# Linaro prefix
CROSS_PREFIX = arm-linux-gnueabi-g
endif
## OS X
ifeq ($(UNAME),Darwin)
ifneq ($(MAKECMDGOALS),cross)
CFLAGS += -DCONFIGURATION='"HIDAPI/IOHidManager"' -DSYSTEM='"OS X"'
HIDSRC += hidapi/mac/hid.c
LDFLAGS += -framework IOKit -framework CoreFoundation
# minot prefix
endif
CROSS_PREFIX = arm-none-linux-gnueabi-g
endif
## BSD
ifeq ($(findstring BSD, $(UNAME)), BSD)
ifneq ($(MAKECMDGOALS),cross)
CFLAGS += -DCONFIGURATION='"HIDAPI/libusb-1.0"' -DSYSTEM='"BSD"'
HIDSRC += hidapi/libusb/hid.c
LDFLAGS += -L/usr/local/lib -lusb -liconv -pthread
INC += -I/usr/local/include
endif
endif
## ALL UNICES
CFLAGS += -DBRIDGE_MODE
SRCS += src/bt-unix.c src/bridge.c
endif
RM ?= rm -f
CROSS_PREFIX ?= arm-linux-gnueabi-g
OBJS = $(SRCS:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
DWS :=
DWS +=
DWS +=
.DEFAULT: all
all: $(BIN_NAME)
$(BIN_NAME): $(OBJS) $(OBJDIR)/hid.o
$(info $(DWS)CCLD$(DWS) $@)
@$(PREFIX)$(CC) $(OBJS) $(OBJDIR)/hid.o $(LDFLAGS) $(LIBS) -o $(BIN_NAME)
# static enables valgrind to act better -DDEBUG!
$(OBJS): $(OBJDIR)/%.o: $(SRCDIR)/%.c
$(info $(DWS)CC$(DWS)$(DWS) $@)
@$(PREFIX)$(CC) -c $< -MMD $(CFLAGS) $(INC) -o $@
-include $(OBJDIR)/*.d
$(OBJDIR)/hid.o: $(HIDSRC)
$(info $(DWS)CC$(DWS)$(DWS) $@)
@$(PREFIX)$(CC) -c $< -o $@ $(INC) $(HIDFLAGS)
debug: CFLAGS += -g
debug: LIBS := $(LIBS)
debug: LIBS +=
debug: $(BIN_NAME)
cross: PREFIX ?= $(CROSS_PREFIX)
cross: CFLAGS += -DCONFIGURATION='"HIDAPI/libusb-1.0"' -DSYSTEM='"Linux"'
cross: HIDSRC += hidapi/libusb/hid.c
cross: HIDFLAGS += `pkg-config libusb-1.0 --cflags`
cross: LDFLAGS += `pkg-config libusb-1.0 --libs` -lrt -lpthread
cross: $(BIN_NAME)
ifneq ($(OS),Windows_NT)
.PHONY: install
install: $(BIN_NAME) 99-ev3duder.rules udev.sh
-@mkdir /usr/lib/ev3duder/
cp $(BIN_NAME) /usr/lib/ev3duder
ln -s /usr/lib/ev3duder/$(BIN_NAME) /usr/bin/ev3
$(INSTALL)
endif
.PHONY: clean
clean:
$(RM) $(BIN_NAME)
cd $(OBJDIR) && $(RM) *.o *.d