blob: 544ff31339081e6e34ee46e8306790fd84eae9b1 (
plain)
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
|
CC := gcc
CFLAGS = -std=c99 -Wall -Wextra -Wpedantic -g
SRCD := src
OBJD := obj
BIND := bin
FILES = $(shell find $(SRCD)/$(SUBD) -type f)
CSRCS = $(filter %.c, $(FILES))
HSRCS = $(filter %.h, $(FILES))
COBJS = $(CSRCS:$(SRCD)/%.c=$(OBJD)/%.o)
MODULE_TARGET := keylogger.ko
KERNEL_NAME := kernel-$(shell uname -r)
INITFS_NAME := initramfs.img
export
all: daemon client module tests vm
clean:
rm -rf $(BIND)
rm -rf $(OBJD)
daemon client module tests libs:
$(eval TARGET := $($(shell echo $@ | tr 'a-z' 'A-Z')_TARGET))
$(MAKE) $(BIND)/$(if $(TARGET),$(TARGET),$@) SUBD=$@
# generic link
$(BIND)/%: $(COBJS) $(HSRCS)
mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(SFLAGS) $^ -o $@
# generic bulid
$(OBJD)/%.o: $(SRCD)/%.c
mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(SFLAGS) -c $^ -o $@
# build a module
$(BIND)/%.ko: $(CSRCS) $(HSRCS)
mkdir -p $(dir $@); mkdir -p $(OBJD)/$(SUBD)
make -C $(SRCD)/$(SUBD) name=$(@:$(BIND)/%.ko=%)
mv $(SRCD)/$(SUBD)/*.o $(OBJD)/$(SUBD)
mv $(SRCD)/$(SUBD)/*.ko $@
make -C $(SRCD)/$(SUBD) clean
# copy and build the testing files and other shared files (no .c files)
$(BIND)/tests: libs
$(BIND)/tests $(BIND)/libs: $(FILES) $(CSRCS:$(SRCD)/%.c=$(BIND)/%)
mkdir -p $(BIND)/$(SUBD)
find $(SRCD)/$(SUBD) -type f ! -name '*.c' -exec cp {} $(BIND)/$(SUBD) \;
# VM things
vm: vm.sh $(BIND)/$(INITFS_NAME) $(BIND)/$(KERNEL_NAME)
./vm.sh run
$(BIND)/$(INITFS_NAME): $(SRCD)/initramfs-init.sh module
./vm.sh initramfs $@ $^
$(BIND)/$(KERNEL_NAME):
./vm.sh kernel $@
|