rules.mk 7.84 KB
Newer Older
Antoine Kaufmann's avatar
Antoine Kaufmann committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Copyright 2021 Max Planck Institute for Software Systems, and
# National University of Singapore
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

23
24
include mk/subdir_pre.mk

25
PACKER_VERSION := 1.7.0
Hejing Li's avatar
Hejing Li committed
26
KERNEL_VERSION := 5.17.7
27
28

BASE_IMAGE := $(d)output-base/base
29
MEMCACHED_IMAGE := $(d)output-memcached/memcached
30
31
32
NOPAXOS_IMAGE := $(d)output-nopaxos/nopaxos
MTCP_IMAGE := $(d)output-mtcp/mtcp
TAS_IMAGE := $(d)output-tas/tas
Hejing Li's avatar
Hejing Li committed
33
HOMA_IMAGE := $(d)output-homa/homa
34
COMPRESSED_IMAGES ?= false
35

Hejing Li's avatar
Hejing Li committed
36
IMAGES := $(BASE_IMAGE) $(NOPAXOS_IMAGE) $(MEMCACHED_IMAGE) $(HOMA_IMAGE)
37
38
RAW_IMAGES := $(addsuffix .raw,$(IMAGES))

39
IMAGES_MIN := $(BASE_IMAGE)
40
41
RAW_IMAGES_MIN := $(addsuffix .raw,$(IMAGES_MIN))

42
43
44
45
46
47
48
img_dir := $(d)
packer := $(d)packer

bz_image := $(d)bzImage
vmlinux := $(d)vmlinux
kernel_pardir := $(d)kernel
kernel_dir := $(kernel_pardir)/linux-$(KERNEL_VERSION)
49
kernel_config := $(kernel_pardir)/config-$(KERNEL_VERSION)
50
kheader_dir := $(d)kernel/kheaders
51
kheader_tar := $(d)kheaders.tar.bz2
52
53
mqnic_dir := $(d)mqnic
mqnic_mod := $(mqnic_dir)/mqnic.ko
54
55
farmem_dir := $(d)farmem
farmem_mod := $(farmem_dir)/farmem.ko
56
57
m5_bin := $(d)m5
guest_init := $(d)/scripts/guestinit.sh
Hejing Li's avatar
Hejing Li committed
58
59
homa_dir := $(d)homa
homa_mod := $(homa_dir)/homa.ko
60

61
62
build-images: $(IMAGES) $(RAW_IMAGES) $(vmlinux) $(bz_image) $(mqnic_mod) \
  $(farmem_mod)
63

64
build-images-min: $(IMAGES_MIN) $(RAW_IMAGES_MIN) $(vmlinux) $(bz_image) \
65
    $(mqnic_mod) $(farmem_mod)
66

67
68
69
70
71
72
# only converts existing images to raw
convert-images-raw:
	for i in $(IMAGES); do \
	    [ -f $$i ] || continue; \
	    $(QEMU_IMG) convert -f qcow2 -O raw $$i $${i}.raw ; done

73
74
75
76
77
78
################################################
# Disk image

%.raw: %
	$(QEMU_IMG) convert -f qcow2 -O raw $< $@

79
80
$(BASE_IMAGE): $(packer) $(QEMU) $(bz_image) $(m5_bin) $(kheader_tar) \
    $(guest_init) $(kernel_config) \
81
82
    $(addprefix $(d), extended-image.pkr.hcl scripts/install-base.sh \
      scripts/cleanup.sh)
83
	rm -rf $(dir $@)
84
85
86
	mkdir -p $(img_dir)/input-base
	cp $(m5_bin) $(kheader_tar) $(guest_init) $(bz_image) $(kernel_config) \
	    $(img_dir)/input-base/
87
	cd $(img_dir) && ./packer-wrap.sh base base base.pkr.hcl \
88
	    $(COMPRESSED_IMAGES)
89
	rm -rf $(img_dir)/input-base
90
91
	touch $@

92
93
94
95
$(MEMCACHED_IMAGE): $(packer) $(QEMU) $(BASE_IMAGE) \
    $(addprefix $(d), extended-image.pkr.hcl scripts/install-memcached.sh \
      scripts/cleanup.sh)
	rm -rf $(dir $@)
96
	cd $(img_dir) && ./packer-wrap.sh base memcached \
97
	    extended-image.pkr.hcl $(COMPRESSED_IMAGES)
98
	rm -rf $(img_dir)/input-base
99
100
	touch $@

101
102
103
$(NOPAXOS_IMAGE): $(packer) $(QEMU) $(BASE_IMAGE) \
    $(addprefix $(d), extended-image.pkr.hcl scripts/install-nopaxos.sh \
      scripts/cleanup.sh nopaxos.config)
104
	rm -rf $(dir $@)
105
106
	mkdir -p $(img_dir)/input-nopaxos
	cp $(img_dir)/nopaxos.config $(img_dir)/input-nopaxos/
107
	cd $(img_dir) && ./packer-wrap.sh base nopaxos extended-image.pkr.hcl \
108
	    $(COMPRESSED_IMAGES)
109
110
	touch $@

111
112
113
$(MTCP_IMAGE): $(packer) $(QEMU) $(BASE_IMAGE) \
    $(addprefix $(d), extended-image.pkr.hcl scripts/install-mtcp.sh \
      scripts/cleanup.sh)
114
	rm -rf $(dir $@)
115
	cd $(img_dir) && ./packer-wrap.sh base mtcp extended-image.pkr.hcl \
116
	    $(COMPRESSED_IMAGES)
117
118
	touch $@

119
120
121
$(TAS_IMAGE): $(packer) $(QEMU) $(BASE_IMAGE) \
    $(addprefix $(d), extended-image.pkr.hcl scripts/install-tas.sh \
      scripts/cleanup.sh)
122
	rm -rf $(dir $@)
123
	cd $(img_dir) && ./packer-wrap.sh base tas extended-image.pkr.hcl \
124
	    $(COMPRESSED_IMAGES)
125
126
	touch $@

Hejing Li's avatar
Hejing Li committed
127
128
129
130
131
132
133
134
135
136
137
138
$(HOMA_IMAGE): $(packer) $(QEMU) $(BASE_IMAGE) \
    $(addprefix $(d), extended-image.pkr.hcl scripts/install-homa.sh \
      scripts/cleanup.sh)
	rm -rf $(dir $@)
	mkdir -p $(img_dir)/input-homa
	cp -r $(homa_dir) \
	    $(img_dir)/input-homa
	cd $(img_dir) && ./packer-wrap.sh base homa extended-image.pkr.hcl \
	$(COMPRESSED_IMAGES)
	rm -rf $(img_dir)/input-homa
	touch $@

139
$(packer):
140
141
	wget -O $(img_dir)packer_$(PACKER_VERSION)_linux_amd64.zip \
	    https://releases.hashicorp.com/packer/$(PACKER_VERSION)/packer_$(PACKER_VERSION)_linux_amd64.zip
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
	cd $(img_dir) && unzip packer_$(PACKER_VERSION)_linux_amd64.zip
	rm -f $(img_dir)packer_$(PACKER_VERSION)_linux_amd64.zip


################################################
# Kernel

$(kernel_dir)/vmlinux: $(kernel_dir)/.config
	$(MAKE) -C $(kernel_dir)
	touch $@

$(vmlinux): $(kernel_dir)/vmlinux
	cp $< $@
	touch $@

# this dependency is a bit stupid, but not sure how to better do this
$(bz_image): $(kernel_dir)/vmlinux
	cp $(kernel_dir)/arch/x86_64/boot/bzImage $@
	touch $@

162
$(kheader_tar): $(kernel_dir)/vmlinux
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
	rm -rf $(kheader_dir)
	mkdir -p $(kheader_dir)
	$(MAKE) -C $(kernel_dir) headers_install INSTALL_HDR_PATH=$(abspath $(kheader_dir)/usr)
	$(MAKE) -C $(kernel_dir) modules_install INSTALL_MOD_PATH=$(abspath $(kheader_dir))
	rm -f $(kheader_dir)/lib/modules/$(KERNEL_VERSION)/build
	ln -s /usr/src/linux-headers-$(KERNEL_VERSION) \
	    $(kheader_dir)/lib/modules/$(KERNEL_VERSION)/build
	rm -f $(kheader_dir)/lib/modules/$(KERNEL_VERSION)/source
	mkdir -p $(kheader_dir)/usr/src/linux-headers-$(KERNEL_VERSION)
	cp -r $(kernel_dir)/.config $(kernel_dir)/Makefile \
	    $(kernel_dir)/Module.symvers $(kernel_dir)/scripts \
	    $(kernel_dir)/include \
	    $(kheader_dir)/usr/src/linux-headers-$(KERNEL_VERSION)/
	mkdir -p $(kheader_dir)/usr/src/linux-headers-$(KERNEL_VERSION)/tools/objtool/
	cp $(kernel_dir)/tools/objtool/objtool \
	    $(kheader_dir)/usr/src/linux-headers-$(KERNEL_VERSION)/tools/objtool/
	mkdir -p $(kheader_dir)/usr/src/linux-headers-$(KERNEL_VERSION)/arch/x86/
	cp -r $(kernel_dir)/arch/x86/Makefile \
	    $(kernel_dir)/arch/x86/Makefile_32.cpu \
	    $(kernel_dir)/arch/x86/Makefile.um \
	    $(kernel_dir)/arch/x86/include \
	    $(kheader_dir)/usr/src/linux-headers-$(KERNEL_VERSION)/arch/x86
	cd $(kheader_dir) && tar cjf $(abspath $@) .

$(kernel_dir)/.config: $(kernel_pardir)/config-$(KERNEL_VERSION)
	rm -rf $(kernel_dir)
	wget -O - https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-$(KERNEL_VERSION).tar.xz | \
	    tar xJf - -C $(kernel_pardir)
	cd $(kernel_dir) && patch -p1 < ../linux-$(KERNEL_VERSION)-timers-gem5.patch
	cp $< $@

################################################
# mqnic kernel module

$(mqnic_mod): $(vmlinux)
	$(MAKE) -C $(kernel_dir) M=$(abspath $(mqnic_dir)) modules
	touch $@

Hejing Li's avatar
Hejing Li committed
201
202
203
204
205
# HOMA kernel module
$(homa_mod): $(vmlinux)
	$(MAKE) -C $(kernel_dir) M=$(abspath $(homa_dir)) modules
	touch $@

206
207
################################################
# farmem kernel module
208

209
210
211
$(farmem_mod): $(vmlinux)
	$(MAKE) -C $(kernel_dir) M=$(abspath $(farmem_dir)) modules
	touch $@
212

213
214
215
216
CLEAN := $(addprefix $(d), mqnic/mqnic.ko mqnic/*.o mqnic/.*.cmd mqnic/*.mod \
    mqnic/mqnic.mod.c mqnic/Module.symvers mqnic/modules.order \
    farmem/farmem.ko farmem/*.o farmem/.*.cmd farmem/*.mod \
    farmem/farmem.mod.c farmem/Module.symvers farmem/modules.order)
217
DISTCLEAN := $(kernel_dir) $(packer) $(bz_image) $(vmlinux) $(kheader_dir) \
218
    $(foreach i,$(IMAGES),$(dir $(i)) $(subst output-,input-,$(dir $(i)))) \
219
220
221
    $(d)packer_cache $(d)kheaders.tar.bz2

include mk/subdir_post.mk