-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
86 lines (64 loc) · 1.59 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
DEBUG = 0
CFLAGS = -MMD -std=c11 -I./include/readtrmin/
ifeq ($(DEBUG), 1)
CFLAGS += -g -Wall -Werror -Wextra -DDEBUG
else
CFLAGS += -DNDEBUG -O2
endif
LDFLAGS = -shared
ifeq ($(PREFIX),)
PREFIX := /usr/local
endif
BUILD_DIR = build
SRC_DIR = src
LIB_SRCS = $(SRC_DIR)/readtrmin.c \
$(SRC_DIR)/str_util.c
LIB_HEADER = include
LIB_OBJS = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(LIB_SRCS))
LIB_DEPS = $(patsubst %.o, %.d, $(LIB_OBJS))
TARGET = readtrmin
LIB_NAME = lib$(TARGET).so
LIB_FILE = $(BUILD_DIR)/$(LIB_NAME)
LIB_INSTALL_PATH = $(PREFIX)/lib
LIB_HEADER_PATH = $(PREFIX)/include/readtrmin
all: readtrmin install
.PHONY: clean_all
clean_all: clean
.PHONY: readtrmin
readtrmin: make_build_dir $(LIB_FILE)
.PHONY: make_build_dir
make_build_dir:
@if [ ! -d $(BUILD_DIR) ]; then mkdir $(BUILD_DIR); fi
$(LIB_FILE): $(LIB_OBJS)
$(CC) $(LDFLAGS) -fPIC -o $@ $^
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(CFLAGS) -c $< -o $@
-include ($(LIB_DEPS))
.PHONY: install
install:
@if [ ! -f $(LIB_FILE) ]; then \
echo "installation failed"; \
echo "$(LIB_NAME) not found"; \
echo "run 'make readtrmin' to build it"; \
else \
cp $(LIB_FILE) $(LIB_INSTALL_PATH); \
fi
@if [ ! -d $(LIB_HEADERL_PATH) ]; then \
mkdir $(LIB_HEADER_PATH); \
fi
@cp -r $(LIB_HEADER)/readtrmin $(LIB_HEADER_PATH)
@echo "installation successful"; \
.PHONY: uninstall
uninstall:
$(RM) $(LIB_INSTALL_PATH)/$(LIB_NAME)
$(RM) -r $(LIB_HEADER_PATH)
.PHONY: clean
clean:
$(RM) $(LIB_OBJS) $(LIB_DEPS) $(LIB_FILE)
#test
.PHONY: test
test:
$(MAKE) -C test
.PHONY: test_clean
test_clean:
$(MAKE) clean -C test