forked from vsergeev/c-periphery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
57 lines (38 loc) · 1.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
LIB = periphery.a
SRCS = src/gpio.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_SUPPORT := $(shell ! echo "\#include <linux/gpio.h>" | $(CC) -E - >/dev/null 2>&1; echo $$?)
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 $@