forked from Solo5/solo5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathukvm-configure
executable file
·153 lines (128 loc) · 4.03 KB
/
ukvm-configure
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
#!/bin/sh
# Copyright (c) 2015-2017 Contributors as noted in the AUTHORS file
#
# This file is part of ukvm, a unikernel monitor.
#
# 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 "ukvm-configure: error: $@" 1>&2
exit 1
}
if [ "$#" -lt 1 ]; then
cat <<EOM 1<&2
Usage: ukvm-configure SOURCEDIR [ MODULES ... ]
Configures ukvm for your target, enabling the MODULES specified.
Generates a Makefile.ukvm in the current directory. Use the "ukvm-bin" target
to build ukvm.
Options:
SOURCEDIR is the path to the ukvm source
MODULES can be any combination of: net blk gdb
To use a cross-compiler, set the UKVM_CC environment variable.
To build ukvm statically, set the UKVM_STATIC environment variable.
EOM
exit 1
fi
UKVM_CC=${UKVM_CC:-cc}
UKVM_SRC=$(readlink -f $1)
if [ ! -d ${UKVM_SRC} -o ! -f ${UKVM_SRC}/ukvm_core.c ]; then
die "Not a ukvm source directory: ${UKVM_SRC}"
fi
shift
add_cflags ()
{
UKVM_CFLAGS="${UKVM_CFLAGS} $@"
}
add_obj ()
{
for i in "$@"; do
UKVM_OBJS="${UKVM_OBJS} _build-ukvm/${i}"
done
}
add_header ()
{
for i in "$@"; do
UKVM_HEADERS="${UKVM_HEADERS} ${UKVM_SRC}/${i}"
done
}
add_module ()
{
if [ ! -f ${UKVM_SRC}/ukvm_module_$1.c ]; then
die "Invalid module: $1"
fi
enableit="-DUKVM_MODULE_$(echo $1 | tr '[a-z]' '[A-Z]')"
add_obj "ukvm_module_$1.o"
add_cflags "${enableit}"
}
UKVM_CFLAGS=
UKVM_LDFLAGS=
UKVM_LDLIBS=
UKVM_HEADERS=
UKVM_OBJS=
add_obj ukvm_core.o ukvm_elf.o ukvm_main.o
add_header ukvm.h ukvm_guest.h ukvm_cc.h
for module in "$@"; do
[ -z "${module}" ] && continue
add_module ${module}
done
[ -n "${UKVM_STATIC}" ] && UKVM_LDFLAGS="-static"
TARGET=$(${UKVM_CC} -dumpmachine)
[ $? -ne 0 ] &&
die "Error running '${UKVM_CC} -dumpmachine', is your compiler working?"
case ${TARGET} in
x86_64-*linux*)
add_obj ukvm_hv_kvm.o ukvm_hv_kvm_x86_64.o ukvm_cpu_x86_64.o
add_header ukvm_hv_kvm.h ukvm_cpu_x86_64.h
;;
x86_64-*freebsd1[12]*)
add_obj ukvm_hv_freebsd.o ukvm_hv_freebsd_x86_64.o ukvm_cpu_x86_64.o
add_header ukvm_hv_freebsd.h ukvm_cpu_x86_64.h
;;
amd64-*-openbsd6.[3-9])
add_obj ukvm_hv_openbsd.o ukvm_hv_openbsd_x86_64.o ukvm_cpu_x86_64.o
add_header ukvm_hv_openbsd.h ukvm_cpu_x86_64.h
;;
aarch64-*linux*)
add_obj ukvm_hv_kvm.o ukvm_hv_kvm_aarch64.o ukvm_cpu_aarch64.o
add_header ukvm_hv_kvm.h ukvm_cpu_aarch64.h
;;
*)
die "Unsupported compiler target: ${TARGET}"
;;
esac
cat <<EOF> Makefile.ukvm
# Generated by 'ukvm-configure $@'
# Using compiler '${UKVM_CC}', target '${TARGET}'
.BEGIN: ; @echo -e Warning: \$(MAKEFILE) requires GNU make.\\\\nWarning: Attempting to build with \"gmake -f \$(MAKEFILE) \$(.TARGETS)\" for you now. && gmake -f \$(MAKEFILE) \$(.TARGETS)
.PHONY: all
all: ukvm-bin
UKVM_CC=${UKVM_CC}
UKVM_CFLAGS=-Wall -Werror -std=c99 -O2 -g ${UKVM_CFLAGS}
UKVM_LDFLAGS=${UKVM_LDFLAGS}
UKVM_LDLIBS=${UKVM_LDLIBS}
UKVM_OBJS=${UKVM_OBJS}
UKVM_HEADERS=${UKVM_HEADERS}
\$(UKVM_OBJS): \$(UKVM_HEADERS)
_build-ukvm:
mkdir -p _build-ukvm
_build-ukvm/ukvm_%.o: ${UKVM_SRC}/ukvm_%.c \$(MAKEFILE_LIST) | _build-ukvm
\$(UKVM_CC) \$(UKVM_CFLAGS) -c \$< -o \$@
ukvm-bin: \$(UKVM_OBJS) \$(MAKEFILE_LIST)
\$(UKVM_CC) \$(UKVM_LDFLAGS) -o \$@ \$(UKVM_OBJS) \$(UKVM_LDLIBS)
.PHONY: ukvm-clean
ukvm-clean:
rm -rf _build-ukvm
rm -f ukvm-bin
EOF