-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
89 lines (71 loc) · 2.2 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
SRCDIR = lib
OBJDIR = obj
INCDIR = include
override CFLAGS += -Wall -Werror -Wno-unused-variable -Wno-unused-function -Wno-unused-parameter -Wno-missing-braces -fstack-protector -O3 -g
override INCLUD += -I$(INCDIR)
override LDFLAGS += -shared -Wl,--as-needed
override LDLIBS += -pthread -lrt
# Source and header files
SRC = $(shell find $(SRCDIR) -type f -name '*.c')
INC = $(shell find $(INCDIR) -type f -name '*.h')
OBJ = $(patsubst $(SRCDIR)%,$(OBJDIR)%,$(patsubst %.c, %.o, $(SRC)))
# Target declarations
TARGET_LIB = libnetstack.so
TEST_DIR = tests
NETD_DIR = tools/netd
NETD = $(NETD_DIR)/netd
HTTPGET_DIR = tools/httpget
HTTPGET = $(HTTPGET_DIR)/httpget
LIBNSHOOK_DIR = tools/nshook
LIBNSHOOK = $(LIBNSHOOK_DIR)/libnshook.so
PREFIX = /usr/local
DESTDIR =
export PREFIX DESTDIR
.PHONY: default all build ext tools
default: all
all: build doc
build: $(TARGET_LIB) tools
tools: $(notdir $(NETD)) $(notdir $(LIBNSHOOK)) $(notdir $(HTTPGET))
# Compilation
$(TARGET_LIB): $(OBJ)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
$(OBJDIR)/%.o: $(SRCDIR)/%.c $(INC)
@mkdir -p $(@D)
$(CC) -fPIC $(INCLUD) $(CFLAGS) -c $< -o $@
# Tools
$(notdir $(NETD)): $(NETD)
@ln -sfv $(NETD) $(notdir $(NETD))
$(NETD): $(TARGET_LIB)
@$(MAKE) -C $(NETD_DIR)
$(notdir $(HTTPGET)): $(HTTPGET)
@ln -sfv $(HTTPGET) $(notdir $(HTTPGET))
$(HTTPGET): $(TARGET_LIB)
@$(MAKE) -C $(HTTPGET_DIR)
$(notdir $(LIBNSHOOK)): $(LIBNSHOOK)
@ln -sfv $(LIBNSHOOK) $(notdir $(LIBNSHOOK))
$(LIBNSHOOK): $(TARGET_LIB)
@$(MAKE) -C $(LIBNSHOOK_DIR)
# Misc
.PHONY: test doc install uninstall clean
test: $(TARGET_LIB)
@$(MAKE) -C $(TEST_DIR) all
@$(MAKE) -C $(NETD_DIR) test
doc:
@echo 'No documentation to build yet'
install: $(TARGET_LIB) tools
install -Dm644 $(TARGET_LIB) $(DESTDIR)$(PREFIX)/lib/$(TARGET_LIB)
@$(MAKE) -C $(NETD_DIR) install
@$(MAKE) -C $(LIBNSHOOK_DIR) install
uninstall:
$(RM) $(DESTDIR)/$(PREFIX)/lib/$(TARGET_LIB)
@$(MAKE) -C $(NETD_DIR) uninstall
@$(MAKE) -C $(LIBNSHOOK_DIR) uninstall
clean:
$(RM) -r $(OBJDIR) $(TARGET_LIB)
$(RM) $(notdir $(NETD))
$(RM) $(notdir $(HTTPGET))
$(RM) $(notdir $(LIBNSHOOK))
@$(MAKE) -C $(TEST_DIR) clean
@$(MAKE) -C $(NETD_DIR) clean
@$(MAKE) -C $(HTTPGET_DIR) clean
@$(MAKE) -C $(LIBNSHOOK_DIR) clean