forked from vsergeev/c-periphery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
60 lines (40 loc) · 1.81 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
LIB = periphery.a
SRCS = src/gpio.c src/gpio_cdev_v2.c src/gpio_cdev_v1.c src/gpio_sysfs.c src/led.c src/pwm.c src/spi.c src/i2c.c src/mmio.c src/serial.c src/version.c
SRCDIR = src
OBJDIR = obj
TEST_PROGRAMS = $(basename $(wildcard tests/*.c))
###########################################################################
OBJECTS = $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SRCS))
GPIO_CDEV_V1_SUPPORT := $(shell ! echo -e "#include <linux/gpio.h>\n#ifndef GPIO_GET_LINEEVENT_IOCTL\n#error\n#endif" | $(CC) -E - >/dev/null 2>&1; echo $$?)
GPIO_CDEV_V2_SUPPORT := $(shell ! echo -e "#include <linux/gpio.h>\nint main(void) { GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME; return 0; }" | $(CC) -x c - >/dev/null 2>&1; echo $$?)
GPIO_CDEV_SUPPORT = $(if $(filter 1,$(GPIO_CDEV_V2_SUPPORT)),2,$(if $(filter 1,$(GPIO_CDEV_V1_SUPPORT)),1,0))
COMMIT_ID := $(shell git describe --abbrev --always --tags --dirty 2>/dev/null || echo "")
OPT ?= -O3
CFLAGS += -std=gnu99 -pedantic
CFLAGS += $(OPT)
CFLAGS += -Wall -Wextra -Wno-stringop-truncation $(DEBUG) -fPIC
CFLAGS += -DPERIPHERY_VERSION_COMMIT=\"$(COMMIT_ID)\" -DPERIPHERY_GPIO_CDEV_SUPPORT=$(GPIO_CDEV_SUPPORT)
LDFLAGS +=
ifdef CROSS_COMPILE
CC = $(CROSS_COMPILE)gcc
AR = $(CROSS_COMPILE)ar
endif
###########################################################################
.PHONY: all
all: $(LIB)
.PHONY: tests
tests: $(TEST_PROGRAMS)
.PHONY: clean
clean:
rm -rf $(LIB) $(OBJDIR) $(TEST_PROGRAMS)
###########################################################################
tests/%: tests/%.c $(LIB)
$(CC) $(CFLAGS) $(LDFLAGS) $< $(LIB) -o $@ -lpthread
###########################################################################
$(OBJECTS): | $(OBJDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(LIB): $(OBJECTS)
$(AR) rcs $(LIB) $(OBJECTS)
$(OBJDIR)/%.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) $(LDFLAGS) -c $< -o $@