1 #!/usr/bin/bash
2 #
3 # CDDL HEADER START
4 #
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License, Version 1.0 only
7 # (the "License"). You may not use this file except in compliance
8 # with the License.
9 #
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
14 #
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
20 #
21 # CDDL HEADER END
22 #
23 #
24 # Copyright 2011-2012 OmniTI Computer Consulting, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27 # Load support functions
28 . ../../lib/functions.sh
29
30 # First we build the kernel module
31 PROG=illumos-kvm
32 # This is pretty meaningless, and should be "0.5.11" but we messed that up
33 # by starting with "1.0.x" so this'll do. There should be no need to change
34 # this going forward.
35 VER=1.0.5.11
36 # Default to building tip, but site.sh can force a specific commit checkout.
37 COMMIT=$KVM_ROLLBACK
38 SRC_REPO=https://github.com/joyent/illumos-kvm.git
39 if [ -d ${PREBUILT_ILLUMOS:-/dev/null} ]; then
40 logmsg "Using pre-built Illumos at $PREBUILT_ILLUMOS (may need to wait...)"
41 wait_for_prebuilt
42 KERNEL_SOURCE=$PREBUILT_ILLUMOS
43 else
44 KERNEL_SOURCE=/code/omnios-$RELVER/illumos-omnios
45 fi
46 PROTO_AREA=$KERNEL_SOURCE/proto/root_i386
47 PATCHDIR=patches.$PROG
48 PKG=driver/virtualization/kvm
49 SUMMARY="placeholder; reset below"
50 DESC="$SUMMARY"
51
52 # These are the dependencies for both the module and the cmds
53 BUILD_DEPENDS_IPS="archiver/gnu-tar developer/gcc47 developer/versioning/git file/gnu-coreutils"
54
55 # Only 64-bit matters
56 BUILDARCH=64
57
58 # Unset the prefix because we actually DO want things in kernel etc
59 PREFIX=""
60
61 download_source() {
62 logmsg "Obtaining source files"
63 if [[ -d $TMPDIR/$BUILDDIR ]]; then
64 logmsg "--- Removing existing directory for a fresh start"
65 logcmd rm -rf $TMPDIR/$BUILDDIR
66 fi
67 logcmd /bin/git clone $SRC_REPO $TMPDIR/$BUILDDIR || \
68 logerr "--- Failed to clone from $SRC_REPO"
69 if [[ -n "$COMMIT" ]]; then
70 logmsg "--- Setting revision to $COMMIT"
71 pushd $TMPDIR/$BUILDDIR > /dev/null
72 logcmd /bin/git checkout $COMMIT
73 popd > /dev/null
74 fi
75 if [[ -z "$COMMIT" ]]; then
76 pushd $TMPDIR/$BUILDDIR > /dev/null
77 COMMIT=$(git log -1 --format=format:%H)
78 popd > /dev/null
79 fi
80 }
81
82 configure64() {
83 true
84 }
85
86 make_prog() {
87 logmsg "--- make"
88 logcmd $MAKE \
89 KERNEL_SOURCE=$KERNEL_SOURCE \
90 PROTO_AREA=$PROTO_AREA \
91 CC=/opt/gcc-4.4.4/bin/gcc || \
92 logerr "--- Make failed"
93 logcmd cp $KERNEL_SOURCE/usr/src/OPENSOLARIS.LICENSE $SRCDIR/OPENSOLARIS.LICENSE || \
94 logerr "--- failed to copy CDDL from kernel sources"
95 }
96 fix_drivers() {
97 logcmd mv $DESTDIR/usr/kernel $DESTDIR/ || \
98 logerr "--- couldn't move kernel bits into /"
99 }
100
101 init
102 download_source
103 patch_source
104 prep_build
105 build
106 fix_drivers
107 SUMMARY="Illumos KVM kernel driver ($PROG ${COMMIT:0:10})"
108 DESC="KVM is the kernel virtual machine, a framework for the in-kernel acceleration of QEMU."
109 make_package kvm.mog
110 clean_up
111
112 # Next, the utilities (they follow the kernel module version)
113 PROG=illumos-kvm-cmd
114 # Default to building tip, but site.sh can force a specific commit checkout.
115 COMMIT=$KVM_CMD_ROLLBACK
116 SRC_REPO=https://github.com/joyent/illumos-kvm-cmd.git
117 if [ -d $PREBUILT_ILLUMOS:-/dev/null ]; then
118 logmsg "Using pre-built Illumos at $PREBUILT_ILLUMOS (may need to wait...)"
119 wait_for_prebuilt
120 KERNEL_SOURCE=$PREBUILT_ILLUMOS
121 else
122 KERNEL_SOURCE=/code/omnios-$RELVER/illumos-omnios
123 fi
124 KVM_DIR=$TMPDIR/illumos-kvm-$VER
125 PATCHDIR=patches.$PROG
126 PKG=system/kvm
127
128 # Reset a couple of important things
129 BUILDDIR=$PROG-$VER # This must be explicitly reset from the run above
130 PREFIX=/usr
131
132 # Only 64-bit matters
133 BUILDARCH=64
134
135 # Borrowed from Joyent's build.sh within the source
136 # so we can find ctfconvert during 'make install'
137 CTFBINDIR="$KERNEL_SOURCE"/usr/src/tools/proto/root_i386-nd/opt/onbld/bin/i386
138 export CTFBINDIR
139 export PATH="$PATH:$CTFBINDIR"
140
141 make_prog() {
142 CC=/opt/gcc-4.4.4/bin/gcc
143 export KERNEL_SOURCE KVM_DIR PREFIX CC
144 logmsg "--- build.sh"
145 logcmd ./build.sh || \
146 logerr "--- build.sh failed"
147 }
148
149 make_install() {
150 logmsg "--- make install"
151 logcmd $MAKE DESTDIR=${DESTDIR} V=1 install || \
152 logerr "--- Make install failed"
153 }
154
155 download_source
156 patch_source
157 prep_build
158 build
159 SUMMARY="Illumos KVM utilities ($PROG ${COMMIT:0:10})"
160 DESC="KVM is the kernel virtual machine, a framework for the in-kernel acceleration of QEMU."
161 make_package kvm-cmd.mog
162 clean_up
163
164 # Vim hints
165 # vim:ts=4:sw=4:et: