-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
42 lines (31 loc) · 827 Bytes
/
Copy pathMakefile
File metadata and controls
42 lines (31 loc) · 827 Bytes
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
# Makefile
# 内核模块对象文件
obj-m += tinywall.o tinywall_nl.o
# 用户程序编译命令
USER_CMD = ./user_cmd/tinywall_cmd.c
USER_BIN = ./tinywall
# 编译选项
CFLAGS += -Wall
# 默认目标
all: modules user_cmd
# 编译内核模块
modules:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
# 编译用户程序
user_cmd:
gcc $(CFLAGS) -o $(USER_BIN) $(USER_CMD)
# 清理内核模块和用户程序
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
rm -f $(USER_BIN)
# 安装内核模块
install:
sudo insmod $(PWD)/tinywall.ko
sudo insmod $(PWD)/tinywall_nl.ko
# 卸载内核模块
uninstall:
sudo rmmod tinywall_nl
sudo rmmod tinywall
# 快速操作:编译、卸载、安装
shot: all uninstall install
.PHONY: all modules user_cmd clean install uninstall shot