-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
81 lines (60 loc) · 2.08 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
CC ?= gcc
AR ?= ar
LINTER ?= clang-format
PROG := ys
DYNAMIC_TARGET := lib$(PROG).so
STATIC_TARGET := lib$(PROG).a
UNIT_TARGET := unit_test
INTEG_TARGET := integ_test
PREFIX := /usr/local
INCDIR := $(PREFIX)/include
LIBDIR := $(PREFIX)/lib
SRCDIR := src
DEPSDIR := deps
TESTDIR := t
LINCDIR := include
SRC := $(wildcard $(SRCDIR)/*.c)
DEPS := $(filter-out $(wildcard $(DEPSDIR)/tap.c/*), $(wildcard $(DEPSDIR)/*/*.c))
OBJ := $(addprefix obj/, $(notdir $(SRC:.c=.o)) $(notdir $(DEPS:.c=.o)))
CFLAGS = -I$(LINCDIR) -I$(DEPSDIR) -g -ggdb -fPIC -Wall -Wextra -pedantic -Wno-missing-braces
LIBS := -lcrypto -lssl -lm -lpcre -lpthread
PLATFORM := $(shell uname)
ifeq ($(findstring Darwin, $(PLATFORM)), Darwin)
LIBS += -L$(INCDIR)
else
CFLAGS += -Wnonnull-compare
endif
all: $(DYNAMIC_TARGET) $(STATIC_TARGET)
$(DYNAMIC_TARGET): $(OBJ)
$(CC) $(CFLAGS) $(OBJ) -shared $(LIBS) -o $(DYNAMIC_TARGET)
$(STATIC_TARGET): $(OBJ)
$(AR) rcs $@ $(OBJ)
obj/%.o: $(SRCDIR)/%.c $(LINCDIR)/lib$(PROG).h | obj
$(CC) $< -c $(CFLAGS) -o $@
obj/%.o: $(DEPSDIR)/*/%.c | obj
$(CC) $< -c $(CFLAGS) -o $@
obj:
mkdir -p obj
install: $(STATIC_TARGET)
mkdir -p ${LIBDIR} && cp -f ${STATIC_TARGET} ${LIBDIR}/$(STATIC_TARGET)
mkdir -p ${INCDIR} && cp -r $(LINCDIR)/lib$(PROG).h ${INCDIR}
uninstall:
rm -f ${LIBDIR}/$(STATIC_TARGET)
rm -f ${INCDIR}/lib$(PROG).h
# Use make -s test 2>/dev/null to see only test results
test:
$(MAKE) unit_test
$(MAKE) integ_test
unit_test: $(STATIC_TARGET)
$(CC) $(wildcard $(TESTDIR)/unit/*.c) $(wildcard $(DEPSDIR)/tap.c/*.c) $(STATIC_TARGET) -I$(LINCDIR) -I$(SRCDIR) -I$(DEPSDIR) $(LIBS) -o $(UNIT_TARGET)
./$(UNIT_TARGET)
$(MAKE) clean
integ_test: $(STATIC_TARGET)
$(CC) $(TESTDIR)/integ/main.c $(wildcard $(TESTDIR)/integ/$(DEPSDIR)/*/*.c) $(STATIC_TARGET) -I$(LINCDIR) -I$(DEPSDIR) $(LIBS) -o $(INTEG_TARGET)
./scripts/integ.bash
$(MAKE) clean
clean:
rm -f $(OBJ) $(STATIC_TARGET) $(DYNAMIC_TARGET) $(UNIT_TARGET) $(INTEG_TARGET) main
lint:
$(LINTER) -i $(SRC) $(wildcard $(TESTDIR)/*/*.c) $(LINCDIR)/lib$(PROG).h
.PHONY: all obj install uninstall test unit_test integ_test clean lint