aboutsummaryrefslogtreecommitdiff
path: root/release/Makefile.vm
blob: 2565a13ef6717ae9a7453601bf719140f8064182 (plain) (blame)
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
#
#
#
# Makefile for building virtual machine and cloud provider disk images.
#

VMTARGETS=	vm-image
VMFORMATS?=	vhd vmdk qcow2 raw
VMSIZE?=	5120m
VMFS?=		ufs
VMFSLIST?=	ufs zfs
SWAPSIZE?=	1g
VMBASE?=	vm

VHD_DESC=	Azure, VirtualPC, Hyper-V, Xen disk image
VMDK_DESC=	VMWare, VirtualBox disk image
QCOW2_DESC=	Qemu, KVM disk image
RAW_DESC=	Unformatted raw disk image

CLOUDWARE_TYPES?= AZURE \
		BASIC-CI \
		BASIC-CLOUDINIT \
		EC2 \
		GCE \
		OCI \
		VAGRANT
AZURE_FORMAT=	vhdf
AZURE_FSLIST?=	ufs zfs
AZURE_DESC=	Microsoft Azure platform image
BASIC-CI_FORMAT=	raw
BASIC-CI_FSLIST?=	ufs
BASIC-CI_DESC=		Image for CI
BASIC-CLOUDINIT_FORMAT=	raw qcow2
BASIC-CLOUDINIT_FSLIST?=	ufs zfs
BASIC-CLOUDINIT_DESC?=	Images for VM with cloudinit disk config support
EC2_FORMAT=	raw
EC2_FSLIST?=	ufs zfs
EC2_FLAVOURS?=	BASE CLOUD-INIT
EC2-BASE_DESC=	Amazon EC2 image
EC2-CLOUD-INIT_DESC=	Amazon EC2 Cloud-Init image
GCE_FORMAT=	raw
GCE_FSLIST?=	ufs zfs
GCE_DESC=	Google Compute Engine image
OCI_FORMAT=	qcow2
OCI_FSLIST?=	ufs
OCI_DESC=	Oracle Cloud Infrastructure image
OPENSTACK_FORMAT=qcow2
OPENSTACK_FSLIST?=	ufs
OPENSTACK_DESC=	OpenStack platform image
VAGRANT_FORMAT=	vmdk
VAGRANT_FSLIST?=	ufs
VAGRANT_FLAVOURS?=	VIRTUALBOX VMWARE
VAGRANT-VIRTUALBOX_DESC=	Vagrant Image for VirtualBox
VAGRANT-VMWARE_DESC=	Vagrant Image for VMWare

.for _CWT in ${CLOUDWARE_TYPES}
. if defined(${_CWT}_FLAVOURS)
.  for _CWF in ${${_CWT}_FLAVOURS}
CLOUDWARE_GEN+=	${_CWT}-${_CWF}
${_CWT}-${_CWF}_FORMAT?=	${${_CWT}_FORMAT}
${_CWT}-${_CWF}_FSLIST?=	${${_CWT}_FSLIST}
${_CWT}-${_CWF}_DESC?=	${${_CWT}_DESC}
.  endfor
. else
CLOUDWARE_GEN+=	${_CWT}
. endif
.endfor
CLOUDWARE?=	${CLOUDWARE_GEN}

.for _V in TYPE BRANCH REVISION
. if !defined(${_V}) || empty(${_V})
${_V}!=	eval $$(awk '/^${_V}=/{print}' ${.CURDIR}/../sys/conf/newvers.sh); echo $$${_V}
. endif
.endfor

emulator-portinstall:
.if !exists(/usr/local/bin/qemu-${TARGET_ARCH}-static)
.if exists(${PORTSDIR}/emulators/qemu-user-static/Makefile)
	env - UNAME_r=${UNAME_r} PATH=$$PATH \
	    make -C ${PORTSDIR}/emulators/qemu-user-static \
	    BATCH=1 WRKDIRPREFIX=/tmp/ports DISTDIR=/tmp/distfiles \
	    all install clean
.else
.if !exists(/usr/local/sbin/pkg-static)
	env ASSUME_ALWAYS_YES=yes pkg bootstrap -y
.endif
	env ASSUME_ALWAYS_YES=yes pkg install -y emulators/qemu-user-static
.endif
.endif
	touch ${.TARGET}

.if ${TARGET_ARCH} != ${MACHINE_ARCH}
.if ( ${TARGET_ARCH} != "i386" ) || ( ${MACHINE_ARCH} != "amd64" )
QEMUSTATIC=/usr/local/bin/qemu-${TARGET_ARCH}-static
QEMUTGT=emulator-portinstall
.endif
.endif
QEMUTGT?=

.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE)
. for _CW in ${CLOUDWARE}
.  if exists(${.CURDIR}/tools/${_CW:tl}.conf) && !defined(${_CW:tu}CONF)
${_CW:tu}CONF?=	${.CURDIR}/tools/${_CW:tl}.conf
.  endif
.  for _FS in ${${_CW:tu}_FSLIST}
.   for _FMT in ${${_CW:tu}_FORMAT}
CLOUDTARGETS+=	cw-${_CW:tl}-${_FS}-${_FMT}
CLEANDIRS+=	cw-${_CW:tl}-${_FS}-${_FMT}
CLEANFILES+=	${_CW:tl}.${_FS}.${_FMT}.img \
		${_CW:tl}.${_FS}.${_FMT} \
		${_CW:tl}.${_FS}.${_FMT}.raw
${_CW:tu}${_FS:tu}${_FMT:tu}IMAGE=	${_CW:tl}.${_FS}.${_FMT}

cw-${_CW:tl}-${_FS}-${_FMT}: ${QEMUTGT}
	mkdir -p ${.OBJDIR}/${.TARGET}
	env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \
		QEMUSTATIC=${QEMUSTATIC} \
		${.CURDIR}/scripts/mk-vmimage.sh \
		-C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} -F ${_FS} \
		-i ${.OBJDIR}/${_CW:tl}.${_FS}.${_FMT}.img -s ${VMSIZE} -f ${_FMT} \
		-S ${WORLDDIR} -o ${.OBJDIR}/${${_CW:tu}${_FS:tu}${_FMT:tu}IMAGE} -c ${${_CW:tu}CONF}
	touch ${.TARGET}
.   endfor
.  endfor

# Hardlinks from "foo.${FMT}" to "foo-${VMFS}.${FMT}".  These can go away once
# all of the cloudware code knows how to handle multiple filesystem images (or
# at least knows the name of the UFS image).
.  for _FMT in ${${_CW:tu}_FORMAT}
CLOUDTARGETS+=	cw-${_CW:tl}-${_FMT}
CLEANFILES+=	${_CW:tl}.${_FMT}
${_CW:tu}${_FMT:tu}IMAGE=	${_CW:tl}.${_FMT}
cw-${_CW:tl}-${_FMT}: cw-${_CW:tl}-${VMFS}-${_FMT}
	ln -f ${${_CW:tu}${VMFS:tu}${_FMT:tu}IMAGE} ${${_CW:tu}${_FMT:tu}IMAGE}
.  endfor

# Targets without a disk format listed are the first disk format on the list
.  for _FS in ${${_CW:tu}_FSLIST}
${_CW:tu}${_FS:tu}IMAGE=	${_CW:tl}.${_FS}.${${_CW:tu}_FORMAT:[1]}
cw-${_CW:tl}-${_FS}: cw-${_CW:tl}-${_FS}-${${_CW:tu}_FORMAT:[1]}
.  endfor
${_CW:tu}IMAGE=	${_CW:tl}.${${_CW:tu}_FORMAT:[1]}
cw-${_CW:tl}:	cw-${_CW:tl}-${${_CW:tu}_FORMAT:[1]}
. endfor
.endif

.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
CLEANFILES+=	vm-image
. for FORMAT in ${VMFORMATS}
.  for FS in ${VMFSLIST}
CLEANDIRS+=	vm-image-${FORMAT}-${FS}
CLEANFILES+=	${FORMAT}.${FS}.img
CLEANFILES+=	${VMBASE}.${FS}.${FORMAT}
.  endfor
. endfor
.endif

vm-base:	vm-image

vm-image:
.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
. for FORMAT in ${VMFORMATS}
.  for FS in ${VMFSLIST}
	mkdir -p ${.OBJDIR}/${.TARGET}-${FORMAT}-${FS}
	env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \
		${.CURDIR}/scripts/mk-vmimage.sh \
		-C ${.CURDIR}/tools/vmimage.subr \
		-d ${.OBJDIR}/${.TARGET}-${FORMAT}-${FS} -F ${FS} \
		-i ${.OBJDIR}/${FORMAT}.${FS}.img -s ${VMSIZE} -f ${FORMAT} \
		-S ${WORLDDIR} -o ${.OBJDIR}/${VMBASE}.${FS}.${FORMAT}
.  endfor
. endfor
.endif
	touch ${.TARGET}

vm-cloudware:	${CLOUDTARGETS}

list-vmtargets:	list-cloudware
	@${ECHO}
	@${ECHO} "Supported virtual machine disk image formats:"
.for FORMAT in ${VMFORMATS:tu}
	@${ECHO} "  ${FORMAT:tl}: ${${FORMAT}_DESC}"
.endfor

list-cloudware:
.if !empty(CLOUDWARE)
	@${ECHO}
	@${ECHO} "Supported cloud hosting provider images:"
. for _CW in ${CLOUDWARE}
	@${ECHO} "  ${_CW:tu}: ${${_CW:tu}_DESC}"
. endfor
.endif

vm-install:
.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
	mkdir -p ${DESTDIR}/vmimages
. for FORMAT in ${VMFORMATS}
.  for FS in ${VMFSLIST}
	cp -p ${VMBASE}.${FS}.${FORMAT} \
		${DESTDIR}/vmimages/${OSRELEASE}-${FS}.${FORMAT}
.  endfor
. endfor
. if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES)
.  for FORMAT in ${VMFORMATS}
.   for FS in ${VMFSLIST}
	# Don't keep the originals.  There is a copy in ${.OBJDIR} if needed.
	${XZ_CMD} ${DESTDIR}/vmimages/${OSRELEASE}-${FS}.${FORMAT}
.   endfor
.  endfor
. endif
	# Compatibility hardlinks from "foo.bar" to "foo-${VMFS}.bar".
. for FORMAT in ${VMFORMATS}
.  if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES)
	ln -f ${DESTDIR}/vmimages/${OSRELEASE}-${VMFS}.${FORMAT}.xz ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT}.xz
.  else
	ln -f ${DESTDIR}/vmimages/${OSRELEASE}-${VMFS}.${FORMAT} ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT}
.  endif
. endfor
	cd ${DESTDIR}/vmimages && sha512 ${OSRELEASE}* > \
		${DESTDIR}/vmimages/CHECKSUM.SHA512
	cd ${DESTDIR}/vmimages && sha256 ${OSRELEASE}* > \
		${DESTDIR}/vmimages/CHECKSUM.SHA256
.endif

vm-release:
.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${VMTARGETS}
.endif

cloudware-release:
.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE)
	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${CLOUDTARGETS}
.endif

.include "${.CURDIR}/Makefile.azure"
.include "${.CURDIR}/Makefile.ec2"
.include "${.CURDIR}/Makefile.firecracker"
.include "${.CURDIR}/Makefile.gce"
.include "${.CURDIR}/Makefile.vagrant"
.include "${.CURDIR}/Makefile.inc1"