-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
114 lines (89 loc) · 2.94 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
NAME := ft_nmap
INCLUDE_DIR := include
PATH_SRCS := srcs
PATH_OBJS := objs
HEADERS := $(wildcard $(INCLUDE_DIR)/*.h)
SRCS := $(wildcard $(PATH_SRCS)/*.c)
OBJS := $(SRCS:$(PATH_SRCS)/%.c=$(PATH_OBJS)/%.o)
CC := cc -std=gnu17 -Wall -Wextra -Werror -g3 -I$(INCLUDE_DIR)
RESET := \033[0m
RED := \033[1m\033[31m
GREEN := \033[1m\033[32m
PURPLE := \033[1m\033[35m
define remove_target
@if [ -e "$(1)" ]; then \
rm -rf "$(1)"; \
echo "$(RED)[X] $(1) removed.$(RESET)"; \
fi
endef
# ======= INSIDE VM =======
all: $(NAME)
$(PATH_OBJS):
@mkdir -p $(sort $(dir $(OBJS)))
$(OBJS): $(PATH_OBJS)/%.o: $(PATH_SRCS)/%.c $(HEADERS)
@mkdir -p $(PATH_OBJS)
@$(CC) -c $< -o $@
@echo "$(GREEN)+++ $@$(RESET)"
$(NAME): $(OBJS)
@$(CC) $(OBJS) -o $@ -lpcap -lpthread
@echo "$(PURPLE)$@ is compiled.$(RESET)"
clean:
$(call remove_target,.vscode)
$(call remove_target,garbage/a.out)
$(call remove_target,$(PATH_OBJS))
$(call remove_target,nmap_service_probes)
fclean: clean
$(call remove_target,$(NAME))
re: fclean
@$(MAKE) -s $(NAME)
help: all
@./$(NAME) --version --help
loc:
@echo $(HEADERS) $(SRCS) | sort | xargs wc -l
# ======= OUTSIDE VM =======
clangd:
@echo "CompileFlags:" > .clangd
@echo " Add:" >> .clangd
@echo " - '-x'" >> .clangd
@echo " - 'c-header'" >> .clangd
@echo " - '-std=gnu17'" >> .clangd
@echo " - '-Iinclude'" >> .clangd
@echo " - '-I../include'" >> .clangd
@echo " - '-I$$HOME/.local/include'" >> .clangd
@echo " - '-L$$HOME/.local/lib'" >> .clangd
@echo " - '-lpcap'" >> .clangd
@echo " - '-lpthread'" >> .clangd
.clangd: clangd
setup: clangd
@vagrant up
@vagrant ssh
destroy: fclean
$(call remove_target,.clangd)
vagrant destroy -f || true
rm -rf .vagrant || true
rm -rf *VBox*.log || true
resetup:
@$(MAKE) --no-print-directory destroy
@$(MAKE) --no-print-directory setup
define compile_from_source
@wget -O source.tar.gz $(1)
@mkdir source_dir && tar xvf source.tar.gz -C source_dir --strip-components=1
@cd source_dir && ./configure --prefix=$$HOME/.local && make -j && make install
@rm -rf source_dir source.tar.gz
endef
install_libpcap: clangd
@mkdir -p $$HOME/.local/bin $$HOME/.local/include $$HOME/.local/lib $$HOME/.local/share
$(call compile_from_source,https://ftp.gnu.org/gnu/m4/m4-1.4.19.tar.xz)
$(call compile_from_source,https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz)
$(call compile_from_source,https://ftp.gnu.org/gnu/bison/bison-3.8.2.tar.xz)
$(call compile_from_source,https://www.tcpdump.org/release/libpcap-1.10.4.tar.gz)
uninstall_libpcap:
@rm -rf source_dir source.tar.gz
@rm -rf $$HOME/.local/bin/m4
@rm -rf $$HOME/.local/bin/flex
@rm -rf $$HOME/.local/bin/flex++
@rm -rf $$HOME/.local/include/FlexLexer.h
@rm -rf $$HOME/.local/bin/bison
@rm -rf $$HOME/.local/share/bison
@rm -rf $$HOME/.local/*/*pcap*
.PHONY: all clean fclean re help loc clangd setup destroy resetup install_libpcap uninstall_libpcap