-
Notifications
You must be signed in to change notification settings - Fork 245
/
Makefile
97 lines (73 loc) · 2.26 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
CC ?= cc
PREFIX ?= /usr/local
BINS = clib clib-install clib-search clib-init clib-configure clib-build clib-update clib-upgrade clib-uninstall
ifdef EXE
BINS := $(addsuffix .exe,$(BINS))
endif
CP = cp -f
RM = rm -f
MKDIR = mkdir -p
INSTALL = install
SRC = $(wildcard src/*.c)
COMMON_SRC = $(wildcard src/common/*.c)
ALL_SRC = $(wildcard src/*.c src/*.h src/common/*.c src/common/*.h test/package/*.c test/cache/*.c)
SDEPS = $(wildcard deps/*/*.c)
ODEPS = $(SDEPS:.c=.o)
DEPS = $(filter-out $(ODEPS), $(SDEPS))
OBJS = $(DEPS:.c=.o)
MAKEFILES = $(wildcard deps/*/Makefile)
HEADERS_BINS = src/common/*.h src/version.h deps/logger/logger.h
export CC
CFLAGS += -std=c99 -Ideps -Wall -Wno-unused-function -U__STRICT_ANSI__
ifdef STATIC
CFLAGS += -DCURL_STATICLIB $(shell deps/curl/bin/curl-config --cflags)
LDFLAGS += -static $(shell deps/curl/bin/curl-config --static-libs)
else
CFLAGS += $(shell curl-config --cflags)
LDFLAGS += $(shell curl-config --libs)
endif
ifneq (0,$(PTHREADS))
ifndef NO_PTHREADS
CFLAGS += $(shell ./scripts/feature-test-pthreads && echo "-DHAVE_PTHREADS=1 -pthread")
endif
endif
ifdef DEBUG
CFLAGS += -g -D CLIB_DEBUG=1 -D DEBUG="$(DEBUG)"
endif
default: all
all: $(BINS)
build: $(BINS)
$(BINS): $(SRC) $(COMMON_SRC) $(MAKEFILES) $(OBJS) $(HEADERS_BINS)
$(CC) $(CFLAGS) -o $@ $(COMMON_SRC) src/$(@:.exe=).c $(OBJS) $(LDFLAGS)
$(MAKEFILES):
$(MAKE) -C $@
%.o: %.c
$(CC) $< -c -o $@ $(CFLAGS) -MMD
clean:
$(foreach c, $(BINS), $(RM) $(c);)
$(RM) $(OBJS)
$(RM) $(AUTODEPS)
cd test/cache && make clean
cd test/package && make clean
install: $(BINS)
$(MKDIR) $(PREFIX)/bin
$(foreach c, $(BINS), $(INSTALL) $(c) $(PREFIX)/bin/$(c);)
uninstall:
$(foreach c, $(BINS), $(RM) $(PREFIX)/bin/$(c);)
test: $(BINS)
@./test.sh
# create a list of auto dependencies
AUTODEPS:= $(patsubst %.c,%.d, $(DEPS)) $(patsubst %.c,%.d, $(SRC))
# include by auto dependencies
-include $(AUTODEPS)
# Format all source files in the repository.
fmt:
@if ! command -v clang-format &> /dev/null; then \
echo "clang-format not found"; \
exit; \
fi
clang-format -i -style=LLVM $(ALL_SRC)
# Install the commit hook.
commit-hook: scripts/pre-commit-hook.sh
cp -f scripts/pre-commit-hook.sh .git/hooks/pre-commit
.PHONY: test all clean install uninstall fmt