forked from nnewson/km
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
47 lines (36 loc) · 1.73 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
# Project Name (.ko)
PROJECT = km
# Directories
SOURCE_DIRECTORY = src
# Symbol template and output
SYMBOL_TEMPLATE = symbols_template.h
SYMBOL_OUTPUT = symbols.h
#-- The project files --
# Add all the source files
SOURCE_FILES = $(shell ls $(PWD)/$(SOURCE_DIRECTORY)/*.c)
# Create an object file of every c file
OBJECTS = $(patsubst $(PWD)/%.c,%.o,$(SOURCE_FILES))
# Find symbols in System.map
MODULES_SYMBOL = $(shell grep -w modules /boot/System.map-$(shell uname -r) | awk '{print $$1}')
SYSFS_MUTEX_SYMBOL = $(shell grep -w sysfs_mutex /boot/System.map-$(shell uname -r) | awk '{print $$1}')
SYSFS_UNLINK_SIBLING_SYMBOL = $(shell grep -w sysfs_unlink_sibling /boot/System.map-$(shell uname -r) | awk '{print $$1}')
SYSFS_LINK_SIBLING_SYMBOL = $(shell grep -w sysfs_link_sibling /boot/System.map-$(shell uname -r) | awk '{print $$1}')
EXT4_DIR_OPERATIONS_SYMBOL = $(shell grep -w ext4_dir_operations /boot/System.map-$(shell uname -r) | awk '{print $$1}')
EXT4_READDIR_SYMBOL = $(shell grep -w ext4_readdir /boot/System.map-$(shell uname -r) | awk '{print $$1}')
#-- Build the project --
obj-m += $(PROJECT).o
$(PROJECT)-objs = $(OBJECTS)
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
.PHONY : symbols
symbols:
sed -e s/MODULES_SYMBOL/$(MODULES_SYMBOL)/g \
-e s/SYSFS_MUTEX_SYMBOL/$(SYSFS_MUTEX_SYMBOL)/g \
-e s/SYSFS_UNLINK_SIBLING_SYMBOL/$(SYSFS_UNLINK_SIBLING_SYMBOL)/g \
-e s/SYSFS_LINK_SIBLING_SYMBOL/$(SYSFS_LINK_SIBLING_SYMBOL)/g \
-e s/EXT4_DIR_OPERATIONS_SYMBOL/$(EXT4_DIR_OPERATIONS_SYMBOL)/g \
-e s/EXT4_READDIR_SYMBOL/$(EXT4_READDIR_SYMBOL)/g \
$(SOURCE_DIRECTORY)/$(SYMBOL_TEMPLATE) > $(SOURCE_DIRECTORY)/$(SYMBOL_OUTPUT)
.PHONY : clean
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean