forked from Solo5/solo5
-
Notifications
You must be signed in to change notification settings - Fork 3
/
configure.sh
executable file
·180 lines (164 loc) · 6.31 KB
/
configure.sh
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
#!/bin/sh
# Copyright (c) 2015-2017 Contributors as noted in the AUTHORS file
#
# This file is part of Solo5, a unikernel base layer.
#
# Permission to use, copy, modify, and/or distribute this software
# for any purpose with or without fee is hereby granted, provided
# that the above copyright notice and this permission notice appear
# in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
# AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
# OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
die()
{
echo "$0: $@" 1>&2
exit 1
}
cc_maybe_gcc()
{
${CC} -dM -E - </dev/null | grep -Eq '^#define __GNUC__ [4-9]$'
}
cc_is_clang()
{
${CC} -dM -E - </dev/null | grep -Eq '^#define __clang__ 1$'
}
cc_has_pie()
{
${CC} -dM -E - </dev/null | grep -Eq '^#define __PIE__ [1-9]$'
}
cc_is_gcc()
{
cc_maybe_gcc && ! cc_is_clang
}
ld_is_lld()
{
${LD} --version 2>&1 | grep -q '^LLD'
}
# Allow external override of CC.
# TODO: This needs further work to provide full support for cross-compiling and
# correctly pass through to ukvm-configure where required.
CC=${CC:-cc}
LD=${LD:-ld}
TARGET=$(${CC} -dumpmachine)
[ $? -ne 0 ] &&
die "Error running '${CC} -dumpmachine', is your compiler working?"
case ${TARGET} in
x86_64-*|amd64-*)
TARGET_ARCH=x86_64
;;
aarch64-*)
TARGET_ARCH=aarch64
;;
*)
die "Unsupported compiler target: ${TARGET}"
;;
esac
# Host-provided header files are installed here for in-tree builds. OPAM will
# install these to $(OPAM_INCDIR)/host where they will be picked up by
# pkg-config.
HOST_INCDIR=${PWD}/include-host
case $(uname -s) in
Linux)
# On Linux/gcc we use -nostdinc and copy all the gcc-provided headers.
cc_is_gcc || die "Only 'gcc' 4.x+ is supported on Linux"
CC_INCDIR=$(${CC} -print-file-name=include)
[ -d "${CC_INCDIR}" ] || die "Cannot determine gcc include directory"
mkdir -p ${HOST_INCDIR}
cp -R ${CC_INCDIR}/. ${HOST_INCDIR}
HOST_CFLAGS="-nostdinc"
# Recent distributions now default to PIE enabled. Disable it explicitly
# if that's the case here.
# XXX: This breaks MirageOS in (at least) the build of mirage-solo5 due
# to -fno-pie breaking the build of lib/dllmirage-solo5_bindings.so.
# Keep this disabled until that is resolved.
# cc_has_pie && HOST_CFLAGS="${HOST_CFLAGS} -fno-pie"
# Same for the stack protector, no robust way to detect if this is on by
# default so always disable it.
HOST_CFLAGS="${HOST_CFLAGS} -fno-stack-protector"
BUILD_UKVM="yes"
if [ "${TARGET_ARCH}" = "x86_64" ]; then
BUILD_VIRTIO="yes"
BUILD_MUEN="yes"
else
BUILD_VIRTIO="no"
BUILD_MUEN="no"
fi
;;
FreeBSD)
# On FreeBSD/clang we use -nostdlibinc which gives us access to the
# clang-provided headers for compiler instrinsics. We copy the rest
# (std*.h, float.h and their dependencies) from the host.
cc_is_clang || die "Only 'clang' is supported on FreeBSD"
[ "${TARGET_ARCH}" = "x86_64" ] ||
die "Only 'x86_64' is supported on FreeBSD"
INCDIR=/usr/include
SRCS_MACH="machine/_stdint.h machine/_types.h machine/endian.h \
machine/_limits.h"
SRCS_SYS="sys/_null.h sys/_stdint.h sys/_types.h sys/cdefs.h \
sys/endian.h sys/_stdarg.h"
SRCS_X86="x86/float.h x86/_stdint.h x86/stdarg.h x86/endian.h \
x86/_types.h x86/_limits.h"
SRCS="float.h osreldate.h stddef.h stdint.h stdbool.h stdarg.h"
mkdir -p ${HOST_INCDIR}
mkdir -p ${HOST_INCDIR}/machine ${HOST_INCDIR}/sys ${HOST_INCDIR}/x86
for f in ${SRCS_MACH}; do cp -f ${INCDIR}/$f ${HOST_INCDIR}/machine; done
for f in ${SRCS_SYS}; do cp -f ${INCDIR}/$f ${HOST_INCDIR}/sys; done
for f in ${SRCS_X86}; do cp -f ${INCDIR}/$f ${HOST_INCDIR}/x86; done
for f in ${SRCS}; do cp -f ${INCDIR}/$f ${HOST_INCDIR}; done
HOST_CFLAGS="-nostdlibinc"
BUILD_UKVM="yes"
BUILD_VIRTIO="yes"
BUILD_MUEN="yes"
;;
OpenBSD)
# On OpenBSD/clang we use -nostdlibinc which gives us access to the
# clang-provided headers for compiler instrinsics. We copy the rest
# (std*.h, cdefs.h and their dependencies) from the host.
cc_is_clang || die "Only 'clang' is supported on OpenBSD"
[ "${TARGET_ARCH}" = "x86_64" ] ||
die "Only 'x86_64' is supported on OpenBSD"
if ! ld_is_lld; then
LD='/usr/bin/ld.lld'
echo "using GNU 'ld' is not supported on OpenBSD, falling back to 'ld.lld'"
[ -e ${LD} ] || die "/usr/bin/ld.lld does not exist"
fi
INCDIR=/usr/include
SRCS_MACH="machine/_float.h machine/endian.h machine/cdefs.h machine/_types.h"
SRCS_SYS="sys/_null.h sys/cdefs.h sys/_endian.h sys/endian.h sys/_types.h"
SRCS_AMD64="amd64/_float.h amd64/stdarg.h amd64/endian.h"
SRCS="float.h stddef.h stdint.h stdbool.h stdarg.h"
mkdir -p ${HOST_INCDIR}
mkdir -p ${HOST_INCDIR}/machine ${HOST_INCDIR}/sys ${HOST_INCDIR}/amd64
for f in ${SRCS_MACH}; do cp -f ${INCDIR}/$f ${HOST_INCDIR}/machine; done
for f in ${SRCS_SYS}; do cp -f ${INCDIR}/$f ${HOST_INCDIR}/sys; done
for f in ${SRCS_AMD64}; do cp -f ${INCDIR}/$f ${HOST_INCDIR}/amd64; done
for f in ${SRCS}; do cp -f ${INCDIR}/$f ${HOST_INCDIR}; done
HOST_CFLAGS="-fno-pie -fno-stack-protector -nostdlibinc"
HOST_LDFLAGS="-nopie"
BUILD_UKVM="yes"
BUILD_VIRTIO="yes"
BUILD_MUEN="yes"
;;
*)
die "Unsupported build OS: $(uname -s)"
;;
esac
cat <<EOM >Makeconf
# Generated by configure.sh, using CC=${CC} for target ${TARGET}
BUILD_UKVM=${BUILD_UKVM}
BUILD_VIRTIO=${BUILD_VIRTIO}
BUILD_MUEN=${BUILD_MUEN}
HOST_CFLAGS=${HOST_CFLAGS}
HOST_LDFLAGS=${HOST_LDFLAGS}
TEST_TARGET=${TARGET}
TARGET_ARCH=${TARGET_ARCH}
CC=${CC}
LD=${LD}
EOM