rules.mk 8.17 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
Antoine Kaufmann's avatar
Antoine Kaufmann committed
34
TIMESYNC_IMAGE := $(d)output-timesync/timesync
35
COMPRESSED_IMAGES ?= false
36

Antoine Kaufmann's avatar
Antoine Kaufmann committed
37
IMAGES := $(BASE_IMAGE) $(NOPAXOS_IMAGE) $(MEMCACHED_IMAGE) $(HOMA_IMAGE) $(TIMESYNC_IMAGE)
38
39
RAW_IMAGES := $(addsuffix .raw,$(IMAGES))

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

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

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

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

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

68
69
70
71
72
73
# 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

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

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

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

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

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

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

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

Hejing Li's avatar
Hejing Li committed
128
129
130
131
132
133
134
135
136
137
$(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
Antoine Kaufmann's avatar
Antoine Kaufmann committed
138
139
140
141
142
143
$(TIMESYNC_IMAGE): $(packer) $(QEMU) $(BASE_IMAGE) \
    $(addprefix $(d), extended-image.pkr.hcl scripts/install-timesync.sh \
      scripts/cleanup.sh)
	rm -rf $(dir $@)
	cd $(img_dir) && ./packer-wrap.sh base timesync extended-image.pkr.hcl \
	    $(COMPRESSED_IMAGES)
Hejing Li's avatar
Hejing Li committed
144
145
	touch $@

146
$(packer):
147
148
	wget -O $(img_dir)packer_$(PACKER_VERSION)_linux_amd64.zip \
	    https://releases.hashicorp.com/packer/$(PACKER_VERSION)/packer_$(PACKER_VERSION)_linux_amd64.zip
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
	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 $@

169
$(kheader_tar): $(kernel_dir)/vmlinux
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
201
202
203
204
205
206
207
	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
208
209
210
211
212
# HOMA kernel module
$(homa_mod): $(vmlinux)
	$(MAKE) -C $(kernel_dir) M=$(abspath $(homa_dir)) modules
	touch $@

213
214
################################################
# farmem kernel module
215

216
217
218
$(farmem_mod): $(vmlinux)
	$(MAKE) -C $(kernel_dir) M=$(abspath $(farmem_dir)) modules
	touch $@
219

220
221
222
223
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)
224
DISTCLEAN := $(kernel_dir) $(packer) $(bz_image) $(vmlinux) $(kheader_dir) \
225
    $(foreach i,$(IMAGES),$(dir $(i)) $(subst output-,input-,$(dir $(i)))) \
226
227
228
    $(d)packer_cache $(d)kheaders.tar.bz2

include mk/subdir_post.mk