-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
87 lines (65 loc) · 1.8 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
## User configuration ##
AR ?= ar
CC ?= gcc
ARFLAGS :=
CCFLAGS ?= -march=native -O2 -pipe
INC_DIR ?= /usr/include
LIB_DIR ?= /usr/lib
LIB := bufio
## Developer configuration ##
ARFLAGS := $(ARFLAGS)
CCFLAGS := $(CCFLAGS) -Werror -Wall -Wextra -Wformat-security \
-Wpedantic -pedantic-errors -std=c18
INC_DIR := $(INC_DIR)/$(LIB)
LIB := lib$(LIB)
SRC_FILES := src/buf_reader.c src/buf_writer.c
HEAD_FILES := src/buf_reader.h src/buf_writer.h
OBJ_FILES := ${SRC_FILES:.c=.o}
SRC_TESTS := tests/test_br.c tests/test_bw.c
OBJ_TESTS := ${SRC_TESTS:%.c=%}
## User targets ##
build: $(LIB).so
build_debug: $(LIB)_debug.so
build_static: $(LIB).a
build_tests: build $(OBJ_TESTS)
test: build_tests
@for f in $(OBJ_TESTS); do \
printf "TEST $$f\n"; \
LD_LIBRARY_PATH=. ./$$f; \
done
install: build
@[ -d $(INC_DIR) ] || mkdir -v -m 755 $(INC_DIR)
@install -v -m 755 $(LIB).so $(LIB_DIR)/
@for f in ${HEAD_FILES:src/%=%}; do \
[ -d $(INC_DIR)/`dirname $$f` ] \
|| mkdir -v -m 755 $(INC_DIR)/`dirname $$f`; \
install -v -m 644 src/$$f $(INC_DIR)/$$f; \
done
@ldconfig
uninstall:
@rm -rf $(INC_DIR) $(LIB_DIR)/$(LIB).so
@ldconfig
clean:
@rm -rf $(LIB).so $(LIB).a $(LIB)_debug.so \
$(OBJ_TESTS) $(OBJ_FILES)
## Developer targets ##
$(LIB).so: $(OBJ_FILES)
@printf "CC $@\n"
@$(CC) $(CCFLAGS) -Xlinker --strip-all -shared -o $@ $^
$(LIB)_debug.so: $(OBJ_FILES)
@printf "CC $@\n"
@$(CC) $(CCFLAGS) -shared -g -o $@ $^
$(LIB).a: $(OBJ_FILES)
@printf "AR $@\n"
@$(AR) $(ARFLAGS) -rcs -o $@ $^
@printf "STRIP $@\n"
@strip --strip-unneeded $@
src/%.o: src/%.c src/%.h
@printf "CC $@\n"
@$(CC) $(CCFLAGS) -c -g -o $@ $<
src/%.o: src/%.c
@printf "CC $@\n"
@$(CC) $(CCFLAGS) -c -g -o $@ $<
tests/%: tests/%.c
@printf "CC $@\n"
@$(CC) $(CCFLAGS) -L. -l${LIB:lib%=%} -o $@ $<