-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathMakefile.am
323 lines (273 loc) · 9.16 KB
/
Makefile.am
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# Unikernel Linux
# Copyright (C) 2018-2022 Red Hat Inc., Boston University,
# Ali Raza, Tommy Unger, Eric Munson, Richard W.M. Jones.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
EXTRA_DIST = \
.gitignore \
glibc-build/.gitignore \
libgcc-build/.gitignore \
LICENSE \
README.md
CLEANFILES = \
*~ *.o *.a \
stamp-gcc-prereq \
stamp-h1 \
stamp-glibc-configure \
stamp-libgcc-build \
stamp-libgcc-configure \
ukl-initrd.cpio.xz \
linux/.config \
vmlinuz
clean-local:
-rm -rf glibc-build/* libgcc-build/*
-cd linux && $(MAKE) clean
-cd $(PROGRAM) && $(MAKE) clean
-cd initrd && $(MAKE) clean
-find -name config.cache -delete
min-clean: app-clean kern-clean
app-clean:
-cd libupcall && $(MAKE) clean
-rm UKL.a vmlinuz linux/vmlinux linux/arch/x86/boot/bzImage
-cd $(PROGRAM) && $(MAKE) clean
kern-clean:
-rm vmlinuz
-cd initrd && $(MAKE) clean
-cd linux && $(MAKE) clean && rm .config
DIST_SUBDIRS = dnsmasq hello memcached valkey mpc-bench fio
#----------------------------------------------------------------------
# Build libgcc and static libstdc++.
#
# XXX We only want libgcc. Can we build this in a way which doesn't
# build the whole of gcc?
# C runtime objects.
CRT_OBJS = crtbeginT.o crtend.o libgcc.a libgcc_eh.a
noinst_DATA = $(CRT_OBJS) libstdc++.a
GCC_CFLAGS = -ggdb -O2 -mcmodel=kernel -mno-red-zone
if DEFAULT_PIE
GCC_CFLAGS += -fno-PIC -no-pie -fno-PIE
endif
$(CRT_OBJS): stamp-libgcc-build
stamp-libgcc-build: stamp-libgcc-configure
rm -f $@
cd libgcc-build && $(MAKE) all-gcc
-cd libgcc-build && $(MAKE) all-target-libgcc \
CFLAGS_FOR_TARGET='$(GCC_CFLAGS)' \
CXXFLAGS_FOR_TARGET='$(GCC_CFLAGS)'
# XXX The kernel memory model doesn't support -fpic, but GCC adds it
# unconditionally, even though we used --disable-shared.
$(SED) -i 's/PICFLAG/#PICFLAG/g' \
libgcc-build/x86_64-pc-linux-gnu/libgcc/Makefile
cd libgcc-build && $(MAKE) all-target-libgcc \
CFLAGS_FOR_TARGET='$(GCC_CFLAGS)' \
CXXFLAGS_FOR_TARGET='$(GCC_CFLAGS)'
# libgcc_eh.a is not built automatically when we use --disable-shared,
# but it still builds fine.
cd libgcc-build/x86_64-pc-linux-gnu/libgcc && \
$(MAKE) libgcc_eh.a \
CFLAGS_FOR_TARGET='$(GCC_CFLAGS)' \
CXXFLAGS_FOR_TARGET='$(GCC_CFLAGS)'
cd libgcc-build/x86_64-pc-linux-gnu/libgcc && \
cp $(CRT_OBJS) $(abs_builddir)
touch $@
libstdc++.a: stamp-libgcc-build
rm -f $@
cd libgcc-build && $(MAKE) all-target-libstdc++-v3 \
CFLAGS_FOR_TARGET='$(GCC_CFLAGS)' \
CXXFLAGS_FOR_TARGET='$(GCC_CFLAGS)'
cp libgcc-build/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.a $@
stamp-libgcc-configure: stamp-gcc-prereq
rm -f $@
mkdir -p libgcc-build
cd libgcc-build && \
$(abs_top_srcdir)/gcc/configure \
--prefix=$(abs_builddir) \
--enable-languages=c,c++ \
--disable-nls \
--without-headers \
--with-multilib-list=m64 \
--disable-multilib \
--disable-shared
touch $@
stamp-gcc-prereq:
rm -f $@
cd $(srcdir)/gcc && contrib/download_prerequisites
touch $@
#----------------------------------------------------------------------
# Build glibc.
LIBC_OBJS = libc.a libpthread.a libm.a librt.a libcrypt.a crt1.o crti.o crtn.o
noinst_DATA += $(LIBC_OBJS)
GLIBC_CFLAGS = -g -O2 -fthread-jumps -mcmodel=kernel -mno-red-zone
if DEFAULT_PIE
GLIBC_CFLAGS += -fno-PIC -no-pie -fno-PIE
endif
if ENABLE_BYPASS
GLIBC_CFLAGS += -DUKL_BP
else
GLIBC_CFLAGS += -UUKL_BP
endif
libc.a: stamp-glibc-configure
rm -f $@
# XXX This fails in the iconv subdirectory, and there seems to be
# no way to disable that feature. So instead just continue past
# the failure and hope if libc.a has not been created then the
# build will fail on the next line.
-cd glibc-build && $(MAKE)
cp glibc-build/libc.a $@
libpthread.a: stamp-glibc-configure libc.a
rm -f $@
cd glibc-build && $(MAKE) subdirs=nptl
cp glibc-build/nptl/libpthread.a $@
libm.a: stamp-glibc-configure libpthread.a
rm -f $@
cd glibc-build && $(MAKE) subdirs=math
cp glibc-build/math/libm.a $@
librt.a: stamp-glibc-configure libm.a
rm -f $@
cd glibc-build && $(MAKE) subdirs=rt
cp glibc-build/rt/librt.a $@
libcrypt.a: stamp-glibc-configure libm.a
rm -f $@
cd glibc-build && $(MAKE) subdirs=crypt
cp glibc-build/crypt/libcrypt.a $@
crt1.o crti.o crtn.o: librt.a
rm -f $@
cp glibc-build/csu/$(basename $@).o $@
stamp-glibc-configure:
rm -f $@
mkdir -p glibc-build
cd glibc-build && \
$(abs_top_srcdir)/glibc/configure \
CFLAGS="$(GLIBC_CFLAGS)" \
--prefix=$(abs_builddir) \
--enable-hacker-mode \
--enable-timezone-tools \
--disable-build-nscd \
--disable-default-pie \
--disable-pic \
--disable-pie \
--disable-nscd \
--disable-pt_chown \
--enable-static-nss \
--disable-shared \
--disable-tunables \
--disable-werror \
x86_64-ukl \
build_alias=x86_64-ukl \
host_alias=x86_64-ukl \
target_alias=x86_64-ukl
touch $@
#----------------------------------------------------------------------
# Build Linux kernel linked with UKL.a
noinst_DATA += vmlinuz
initrd/perf: linux/tools/perf/perf
cp $< $@
linux/tools/perf/perf:
$(MAKE) -C $(srcdir)/linux/tools perf
vmlinuz: linux/arch/x86/boot/bzImage
cp $< $@
linux/arch/x86/boot/bzImage: linux/.config UKL.a
$(MAKE) -C $(srcdir)/linux olddefconfig O=$(abs_builddir)/linux
$(MAKE) -C $(srcdir)/linux WERROR=0 O=$(abs_builddir)/linux
$(MAKE) -C $(srcdir)/linux scripts_gdb
linux/.config: saveconfig
rm -f $@
cp $(srcdir)/saveconfig $@
echo CONFIG_UNIKERNEL_LINUX=y >> $@
echo CONFIG_UKL_TLS=y >> $@
echo CONFIG_UKL_ARCHIVE_PATH=$(ARCHIVE) >> $@
echo CONFIG_UKL_NAME=$(TRIGGER) >> $@
if ENABLE_SAME_STACK
echo CONFIG_UKL_SAME_STACK=y >> $@
endif
if ENABLE_USE_RET
echo CONFIG_UKL_USE_RET=y >> $@
endif
if ENABLE_USE_IST_PF
echo CONFIG_UKL_USE_IST_PF=y >> $@
endif
if ENABLE_SHORTCUT
echo CONFIG_UKL_DEEP_SHORTCUT=y >> $@
endif
#----------------------------------------------------------------------
# Compile the program.
if ENABLE_LIBUPCALL
UPCALL_LIB = $(abs_top_builddir)/libupcall/libupcall.a
else
UPCALL_LIB =
endif
$(abs_top_builddir)/libupcall/libupcall.a:
cd $(abs_top_builddir)/libupcall && $(MAKE)
UKL.a: $(PROGRAM)/UKL.a
cp $< $@
$(PROGRAM)/UKL.a: $(CRT_OBJS) $(LIBC_OBJS) $(UPCALL_LIB)
cd $(PROGRAM) && $(MAKE) UKL.a
#----------------------------------------------------------------------
# Per-program configuration and data files (if required).
$(PROGRAM)/data.tar.gz:
rm -f $@
-cd $(PROGRAM) && $(MAKE) data.tar.gz
if ! test -f $@; then tar zcf $@ --no-recursion . ; fi
#----------------------------------------------------------------------
# Build the initramfs
noinst_DATA += ukl-initrd.cpio.xz
ukl-initrd.cpio.xz: $(PROGRAM)/data.tar.gz vmlinuz initrd/perf
cp $(PROGRAM)/data.tar.gz initrd/
$(MAKE) -C $(srcdir)/initrd $@
cp initrd/$@ $@
#----------------------------------------------------------------------
# Boot the unikernel under qemu.
# Non-privileged:
boot: ukl-initrd.cpio.xz vmlinuz
qemu-system-x86_64 \
-cpu host,-smap,-smep -accel kvm -m 4G \
-kernel vmlinuz \
-initrd ./ukl-initrd.cpio.xz \
-nodefaults -nographic -serial stdio \
-append "console=ttyS0 net.ifnames=0 biosdevname=0 clearcpuid=smap,smep mitigations=off mds=off --" \
-net user
# Privileged (probably required if the kernel is expecting incoming
# network connections).
boot-priv: ukl-initrd.cpio.xz vmlinuz
sudo qemu-system-x86_64 \
-cpu host,-smap,-smep -accel kvm -m 4G \
-kernel vmlinuz \
-initrd ./ukl-initrd.cpio.xz \
-nodefaults -nographic -serial stdio \
-append "console=ttyS0 net.ifnames=0 biosdevname=0 clearcpuid=smap,smep mitigations=off mds=off -- 192.168.122.128" \
-net nic -net bridge,br=virbr0
#----------------------------------------------------------------------
# Maintainers only!
# Check no files are missing from EXTRA_DIST rules, and that all
# generated files have been included in the tarball. (Note you must
# have done 'make dist')
maintainer-check-extra-dist:
@zcat $(PACKAGE_NAME)-$(VERSION).tar.gz | tar tf - | sort | \
sed 's,^$(PACKAGE_NAME)-$(VERSION)/,,' > tarfiles
@git ls-files | \
sort > gitfiles
@comm -13 tarfiles gitfiles > comm-out
@echo Checking for differences between EXTRA_DIST and git ...
@cat comm-out
@[ ! -s comm-out ]
@rm tarfiles gitfiles comm-out
@echo PASS: EXTRA_DIST tests
# Commit everything in the current directory and set the commit
# message to the current version number.
maintainer-commit:
git commit -a -m "Version $(VERSION)."
# Tag HEAD with the current version.
maintainer-tag:
git tag -a v$(VERSION) -m "Version $(VERSION)." -f