-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
61 lines (45 loc) · 1.36 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
CFLAGS = -Wall -Wextra -Werror -Wno-gnu-zero-variadic-macro-arguments -pedantic -std=c99 -O2
A_TARGET = build/librebeltls.a
SO_TARGET = $(patsubst %.a,%.so,$(A_TARGET))
BIN_TARGET = bin/rebeltls
TARGETS = $(A_TARGET) $(SO_TARGET) $(BIN_TARGET)
SRCS = $(wildcard src/**/*.c src/*.c)
OBJS = $(SRCS:.c=.o)
DEPS = $(SRCS:.c=.d)
MAIN_OBJ = src/main.o
LIB_OBJS = $(filter-out $(MAIN_OBJ),$(OBJS))
TESTS = $(patsubst %.c,%,$(wildcard test/*.c))
all: $(TARGETS) test
dev: CFLAGS += -g
dev: all
$(TESTS): $(A_TARGET)
test: CFLAGS += -Isrc
test: $(TESTS)
sh ./test/runtests.sh
$(A_TARGET): $(LIB_OBJS)
@mkdir -p build
$(AR) -rcs $@ $(LIB_OBJS)
$(SO_TARGET): $(LIB_OBJS)
@mkdir -p build
$(CC) $(LDFLAGS) $(LDLIBS) -shared -o $@ $(LIB_OBJS)
$(BIN_TARGET): $(MAIN_OBJ) $(A_TARGET)
@mkdir -p bin
$(CC) $(LDFLAGS) $(LDLIBS) -o $@ $(MAIN_OBJ) $(A_TARGET)
-include $(DEPS)
# the black magic after the first line constructs the dep files correctly
%.d: %.c
@$(CC) $(CFLAGS) -MM $*.c >$*.d
@mv -f $*.d $*.d.tmp
@sed -e 's|.*:|$*.o:|' <$*.d.tmp >$*.d
@sed -e 's/.*://' -e 's/\\$$//' <$*.d.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >>$*.d
@$(RM) $*.d.tmp
tags:
ctags -eR .
clean:
$(RM) $(TARGETS) || true
$(RM) $(TESTS) || true
$(RM) $(OBJS) || true
$(RM) $(DEPS) || true
$(RM) *.log || true
find . -name '*.dSYM' | xargs rm -rf
.PHONY: dev test release install tags clean