forked from vsergeev/c-periphery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
49 lines (31 loc) · 1.16 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
LIB = periphery.a
SRCS = src/gpio.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))
COMMIT_ID := $(shell git describe --abbrev --always --tags --dirty 2>/dev/null || echo "")
CFLAGS += -std=gnu99 -pedantic
CFLAGS += -Wall -Wextra -Wno-unused-parameter -Wno-pointer-to-int-cast $(DEBUG) -fPIC
CFLAGS += -DPERIPHERY_VERSION_COMMIT=\"$(COMMIT_ID)\"
LDFLAGS +=
###########################################################################
.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 $@
###########################################################################
$(OBJECTS): | $(OBJDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(LIB): $(OBJECTS)
ar rcs $(LIB) $(OBJECTS)
$(OBJDIR)/%.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) $(LDFLAGS) -c $< -o $@