-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
110 lines (93 loc) · 3.66 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
.PHONY: all clean distclean help
# Define functions to check undefined variables
check_defined = $(if $(value $(strip $1)),,\
$(error $1 undefined !))
# Check defined variables
$(call check_defined, CONF_TEMPLATE)
# Check if template exist...
ifeq (,$(wildcard $(CONF_TEMPLATE)))
$(error $(CONF_TEMPLATE) not found)
endif
# Templates variables...
export CONF_TEMPLATE_MAKEFILE=$(CONF_TEMPLATE)/Makefile.inc
export CONF_TEMPLATE_FS=$(CONF_TEMPLATE)/fs
export CONF_TEMPLATE_LINUX_CONF=$(CONF_TEMPLATE)/linux-config
export CONF_TEMPLATE_BUSYBOX_CONF=$(CONF_TEMPLATE)/busybox-config
export CONF_TEMPLATE_START=$(CONF_TEMPLATE)/start.sh
export CONF_TEMPLATE_MODULE=$(CONF_TEMPLATE)/vuln.c
-include $(CONF_TEMPLATE_MAKEFILE)
# Check defined variables
$(call check_defined, CONF_LINUX_ARCHIVE)
$(call check_defined, CONF_BUSYBOX_ARCHIVE)
$(call check_defined, CONF_CPUS)
# Root directory
export CONF_ROOT=$(PWD)
# Linux build directory
export CONF_LINUX_BUILD=$(CONF_ROOT)/linux
export CONF_LINUX_BZIMAGE=$(CONF_LINUX_BUILD)/bzImage
export CONF_LINUX_HEADERS=$(CONF_LINUX_BUILD)/build
export CONF_LINUX_SYSTEMMAP=$(CONF_LINUX_BUILD)/System.map
# Busybox build directory
export CONF_BUSYBOX_BUILD=$(CONF_ROOT)/busybox
export CONF_BUSYBOX_DONE=$(CONF_BUSYBOX_BUILD)/build/.done
export CONF_BUSYBOX_INSTALL=$(CONF_BUSYBOX_BUILD)/build/_install
# Initramfs build directory
export CONF_INITRAMFS_BUILD=$(CONF_ROOT)/initramfs
export CONF_INITRAMFS_FINAL=$(CONF_INITRAMFS_BUILD)/initramfs.cpio.gz
# Module build directory
export CONF_MODULE_BUILD=$(CONF_ROOT)/module
export CONF_MODULE_KO=$(CONF_MODULE_BUILD)/vuln.ko
export CONF_MODULE_C=$(CONF_MODULE_BUILD)/vuln.c
# Build directory
export CONF_BUILD=$(CONF_ROOT)/build
export CONF_BUILD_VM=$(CONF_BUILD)/vm-$(shell basename $(CONF_TEMPLATE))
##################################################################
# all rule
##################################################################
all:
make -C $(CONF_INITRAMFS_BUILD) clean
make -C $(CONF_BUILD) clean
mkdir -p $(CONF_BUILD_VM)
cp -a $(CONF_TEMPLATE_FS) $(CONF_INITRAMFS_BUILD)
cp -a $(CONF_TEMPLATE_BUSYBOX_CONF) $(CONF_BUSYBOX_BUILD)/config
cp -a $(CONF_TEMPLATE_LINUX_CONF) $(CONF_LINUX_BUILD)/config
cp -a $(CONF_TEMPLATE_START) $(CONF_BUILD_VM)
cp -a $(CONF_TEMPLATE_MODULE) $(CONF_MODULE_BUILD)
find . -name "*~" -delete
make -C $(CONF_LINUX_BUILD)
make -C $(CONF_BUSYBOX_BUILD)
make -C $(CONF_MODULE_BUILD)
make -C $(CONF_INITRAMFS_BUILD)
make -C $(CONF_BUILD)
@echo ""
@echo "##############################################################"
@echo " Your VM is built in $(CONF_BUILD_VM)"
@echo "##############################################################"
##################################################################
# clean rule
##################################################################
clean:
make -C $(CONF_MODULE_BUILD) clean
make -C $(CONF_LINUX_BUILD) clean
make -C $(CONF_BUSYBOX_BUILD) clean
make -C $(CONF_INITRAMFS_BUILD) clean
make -C $(CONF_BUILD) clean
rm -f *~
##################################################################
# distclean rule
##################################################################
distclean:
make -C $(CONF_MODULE_BUILD) distclean
make -C $(CONF_LINUX_BUILD) distclean
make -C $(CONF_BUSYBOX_BUILD) distclean
make -C $(CONF_INITRAMFS_BUILD) distclean
make -C $(CONF_BUILD) distclean
rm -f *~
##################################################################
# help rule
##################################################################
help:
@echo "make <all> Build the VM"
@echo "make clean Reset some files to start rebuild"
@echo "make distclean Remove all generated files"
@echo "make help Print this help"