xref: /freebsd/release/Makefile.vm (revision 55a2a91c5e1bb39dd625ba56597608883fbcb318)
1#
2#
3#
4# Makefile for building virtual machine and cloud provider disk images.
5#
6
7VMTARGETS=	vm-image
8VMFORMATS?=	vhd vmdk qcow2 raw
9.if ${TARGET_ARCH} == riscv64
10VMSIZE?=	6144m
11.else
12VMSIZE?=	5120m
13.endif
14VMFS?=		ufs
15VMFSLIST?=	ufs zfs
16SWAPSIZE?=	1g
17VMBASE?=	vm
18
19VHD_DESC=	Azure, VirtualPC, Hyper-V, Xen disk image
20VMDK_DESC=	VMWare, VirtualBox disk image
21QCOW2_DESC=	Qemu, KVM disk image
22RAW_DESC=	Unformatted raw disk image
23
24CLOUDWARE_TYPES?= AZURE \
25		BASIC-CI \
26		BASIC-CLOUDINIT \
27		EC2 \
28		GCE \
29		OCI \
30		VAGRANT
31AZURE_FORMAT=	vhdf
32AZURE_FSLIST?=	ufs zfs
33AZURE_DESC=	Microsoft Azure platform image
34BASIC-CI_FORMAT=	raw
35BASIC-CI_FSLIST?=	ufs
36BASIC-CI_DESC=		Image for CI
37BASIC-CLOUDINIT_FORMAT=	raw qcow2
38BASIC-CLOUDINIT_FSLIST?=	ufs zfs
39BASIC-CLOUDINIT_DESC?=	Images for VM with cloudinit disk config support
40EC2_FORMAT=	raw
41EC2_FSLIST?=	ufs zfs
42EC2_FLAVOURS?=	BASE CLOUD-INIT
43EC2-BASE_DESC=	Amazon EC2 image
44EC2-CLOUD-INIT_DESC=	Amazon EC2 Cloud-Init image
45GCE_FORMAT=	raw
46GCE_FSLIST?=	ufs zfs
47GCE_DESC=	Google Compute Engine image
48OCI_FORMAT=	qcow2
49OCI_FSLIST?=	ufs
50OCI_DESC=	Oracle Cloud Infrastructure image
51OPENSTACK_FORMAT=qcow2
52OPENSTACK_FSLIST?=	ufs
53OPENSTACK_DESC=	OpenStack platform image
54VAGRANT_FORMAT=	vmdk
55VAGRANT_FSLIST?=	ufs
56VAGRANT_FLAVOURS?=	VIRTUALBOX VMWARE
57VAGRANT-VIRTUALBOX_DESC=	Vagrant Image for VirtualBox
58VAGRANT-VMWARE_DESC=	Vagrant Image for VMWare
59
60.for _CWT in ${CLOUDWARE_TYPES}
61. if defined(${_CWT}_FLAVOURS)
62.  for _CWF in ${${_CWT}_FLAVOURS}
63CLOUDWARE_GEN+=	${_CWT}-${_CWF}
64${_CWT}-${_CWF}_FORMAT?=	${${_CWT}_FORMAT}
65${_CWT}-${_CWF}_FSLIST?=	${${_CWT}_FSLIST}
66${_CWT}-${_CWF}_DESC?=	${${_CWT}_DESC}
67.  endfor
68. else
69CLOUDWARE_GEN+=	${_CWT}
70. endif
71.endfor
72CLOUDWARE?=	${CLOUDWARE_GEN}
73
74.for _V in TYPE BRANCH REVISION
75. if !defined(${_V}) || empty(${_V})
76${_V}!=	eval $$(awk '/^${_V}=/{print}' ${.CURDIR}/../sys/conf/newvers.sh); echo $$${_V}
77. endif
78.endfor
79
80emulator-portinstall:
81.if !exists(/usr/local/bin/qemu-${TARGET_ARCH}-static)
82.if exists(${PORTSDIR}/emulators/qemu-user-static/Makefile)
83	env - UNAME_r=${UNAME_r} PATH=$$PATH \
84	    make -C ${PORTSDIR}/emulators/qemu-user-static \
85	    BATCH=1 WRKDIRPREFIX=/tmp/ports DISTDIR=/tmp/distfiles \
86	    all install clean
87.else
88.if !exists(/usr/local/sbin/pkg-static)
89	env ASSUME_ALWAYS_YES=yes pkg bootstrap -y
90.endif
91	env ASSUME_ALWAYS_YES=yes pkg install -y emulators/qemu-user-static
92.endif
93.endif
94	touch ${.TARGET}
95
96.if ${TARGET_ARCH} != ${MACHINE_ARCH}
97.if ( ${TARGET_ARCH} != "i386" ) || ( ${MACHINE_ARCH} != "amd64" )
98QEMUSTATIC=/usr/local/bin/qemu-${TARGET_ARCH}-static
99QEMUTGT=emulator-portinstall
100.endif
101.endif
102QEMUTGT?=
103
104.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE)
105. for _CW in ${CLOUDWARE}
106.  if exists(${.CURDIR}/tools/${_CW:tl}.conf) && !defined(${_CW:tu}CONF)
107${_CW:tu}CONF?=	${.CURDIR}/tools/${_CW:tl}.conf
108.  endif
109.  for _FS in ${${_CW:tu}_FSLIST}
110.   for _FMT in ${${_CW:tu}_FORMAT}
111CLOUDTARGETS+=	cw-${_CW:tl}-${_FS}-${_FMT}
112CLEANDIRS+=	cw-${_CW:tl}-${_FS}-${_FMT}
113CLEANFILES+=	${_CW:tl}.${_FS}.${_FMT}.img \
114		${_CW:tl}.${_FS}.${_FMT} \
115		${_CW:tl}.${_FS}.${_FMT}.raw
116${_CW:tu}${_FS:tu}${_FMT:tu}IMAGE=	${_CW:tl}.${_FS}.${_FMT}
117
118cw-${_CW:tl}-${_FS}-${_FMT}: ${QEMUTGT}
119	mkdir -p ${.OBJDIR}/${.TARGET}
120	env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \
121		QEMUSTATIC=${QEMUSTATIC} \
122		${.CURDIR}/scripts/mk-vmimage.sh \
123		-C ${.CURDIR}/tools/vmimage.subr -d ${.OBJDIR}/${.TARGET} -F ${_FS} \
124		-i ${.OBJDIR}/${_CW:tl}.${_FS}.${_FMT}.img -s ${VMSIZE} -f ${_FMT} \
125		-S ${WORLDDIR} -o ${.OBJDIR}/${${_CW:tu}${_FS:tu}${_FMT:tu}IMAGE} -c ${${_CW:tu}CONF}
126	touch ${.TARGET}
127.   endfor
128.  endfor
129
130# Hardlinks from "foo.${FMT}" to "foo-${VMFS}.${FMT}".  These can go away once
131# all of the cloudware code knows how to handle multiple filesystem images (or
132# at least knows the name of the UFS image).
133.  for _FMT in ${${_CW:tu}_FORMAT}
134CLOUDTARGETS+=	cw-${_CW:tl}-${_FMT}
135CLEANFILES+=	${_CW:tl}.${_FMT}
136${_CW:tu}${_FMT:tu}IMAGE=	${_CW:tl}.${_FMT}
137cw-${_CW:tl}-${_FMT}: cw-${_CW:tl}-${VMFS}-${_FMT}
138	ln -f ${${_CW:tu}${VMFS:tu}${_FMT:tu}IMAGE} ${${_CW:tu}${_FMT:tu}IMAGE}
139.  endfor
140
141# Targets without a disk format listed are the first disk format on the list
142.  for _FS in ${${_CW:tu}_FSLIST}
143${_CW:tu}${_FS:tu}IMAGE=	${_CW:tl}.${_FS}.${${_CW:tu}_FORMAT:[1]}
144cw-${_CW:tl}-${_FS}: cw-${_CW:tl}-${_FS}-${${_CW:tu}_FORMAT:[1]}
145.  endfor
146${_CW:tu}IMAGE=	${_CW:tl}.${${_CW:tu}_FORMAT:[1]}
147cw-${_CW:tl}:	cw-${_CW:tl}-${${_CW:tu}_FORMAT:[1]}
148. endfor
149.endif
150
151.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
152CLEANFILES+=	vm-image
153. for FORMAT in ${VMFORMATS}
154.  for FS in ${VMFSLIST}
155CLEANDIRS+=	vm-image-${FORMAT}-${FS}
156CLEANFILES+=	${FORMAT}.${FS}.img
157CLEANFILES+=	${VMBASE}.${FS}.${FORMAT}
158.  endfor
159. endfor
160.endif
161
162vm-base:	vm-image
163
164vm-image:	${QEMUTGT}
165.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
166. for FORMAT in ${VMFORMATS}
167.  for FS in ${VMFSLIST}
168	mkdir -p ${.OBJDIR}/${.TARGET}-${FORMAT}-${FS}
169	env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} SWAPSIZE=${SWAPSIZE} \
170		QEMUSTATIC=${QEMUSTATIC} \
171		${.CURDIR}/scripts/mk-vmimage.sh \
172		-C ${.CURDIR}/tools/vmimage.subr \
173		-d ${.OBJDIR}/${.TARGET}-${FORMAT}-${FS} -F ${FS} \
174		-i ${.OBJDIR}/${FORMAT}.${FS}.img -s ${VMSIZE} -f ${FORMAT} \
175		-S ${WORLDDIR} -o ${.OBJDIR}/${VMBASE}.${FS}.${FORMAT}
176.  endfor
177. endfor
178.endif
179	touch ${.TARGET}
180
181vm-cloudware:	${CLOUDTARGETS}
182
183list-vmtargets:	list-cloudware
184	@${ECHO}
185	@${ECHO} "Supported virtual machine disk image formats:"
186.for FORMAT in ${VMFORMATS:tu}
187	@${ECHO} "  ${FORMAT:tl}: ${${FORMAT}_DESC}"
188.endfor
189
190list-cloudware:
191.if !empty(CLOUDWARE)
192	@${ECHO}
193	@${ECHO} "Supported cloud hosting provider images:"
194. for _CW in ${CLOUDWARE}
195	@${ECHO} "  ${_CW:tu}: ${${_CW:tu}_DESC}"
196. endfor
197.endif
198
199vm-install:
200.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
201	mkdir -p ${DESTDIR}/vmimages
202. for FORMAT in ${VMFORMATS}
203.  for FS in ${VMFSLIST}
204	cp -p ${VMBASE}.${FS}.${FORMAT} \
205		${DESTDIR}/vmimages/${OSRELEASE}-${FS}.${FORMAT}
206.  endfor
207. endfor
208. if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES)
209.  for FORMAT in ${VMFORMATS}
210.   for FS in ${VMFSLIST}
211	# Don't keep the originals.  There is a copy in ${.OBJDIR} if needed.
212	${XZ_CMD} ${DESTDIR}/vmimages/${OSRELEASE}-${FS}.${FORMAT}
213.   endfor
214.  endfor
215. endif
216	cd ${DESTDIR}/vmimages && sha512 ${OSRELEASE}* > \
217		${DESTDIR}/vmimages/CHECKSUM.SHA512
218	cd ${DESTDIR}/vmimages && sha256 ${OSRELEASE}* > \
219		${DESTDIR}/vmimages/CHECKSUM.SHA256
220.endif
221
222cloud-install-BASIC-CI:
223	mkdir -p ${DESTDIR}/ciimages
224.for _FS in ${BASIC-CI_FSLIST}
225. for _FMT in ${BASIC-CI_FORMAT}
226	cp -p ${.OBJDIR}/${BASIC-CI${_FS:tu}${_FMT:tu}IMAGE} \
227		${DESTDIR}/ciimages/${OSRELEASE}-BASIC-CI-${_FS}.${_FMT}
228	${XZ_CMD} ${DESTDIR}/ciimages/${OSRELEASE}-BASIC-CI-${_FS}.${_FMT}
229. endfor
230.endfor
231	cd ${DESTDIR}/ciimages && sha512 ${OSRELEASE}* > \
232		${DESTDIR}/ciimages/CHECKSUM.SHA512
233	cd ${DESTDIR}/ciimages && sha256 ${OSRELEASE}* > \
234		${DESTDIR}/ciimages/CHECKSUM.SHA256
235
236cloud-install-BASIC-CLOUDINIT:
237	mkdir -p ${DESTDIR}/vmimages
238.for _FS in ${BASIC-CLOUDINIT_FSLIST}
239. for _FMT in ${BASIC-CLOUDINIT_FORMAT}
240	cp -p ${.OBJDIR}/${BASIC-CLOUDINIT${_FS:tu}${_FMT:tu}IMAGE} \
241		${DESTDIR}/vmimages/${OSRELEASE}-BASIC-CLOUDINIT.${_FS}.${_FMT}
242	${XZ_CMD} ${DESTDIR}/vmimages/${OSRELEASE}-BASIC-CLOUDINIT.${_FS}.${_FMT}
243. endfor
244.endfor
245	cd ${DESTDIR}/vmimages && sha512 ${OSRELEASE}* > \
246		${DESTDIR}/vmimages/CHECKSUM.SHA512
247	cd ${DESTDIR}/vmimages && sha256 ${OSRELEASE}* > \
248		${DESTDIR}/vmimages/CHECKSUM.SHA256
249
250CLOUD_INSTALL_TGTS=
251.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE)
252. for _CW in ${CLOUDWARE}
253.  if target(cloud-install-${_CW})
254CLOUD_INSTALL_TGTS+=	cloud-install-${_CW}
255.  endif
256. endfor
257.endif
258cloud-install:	${CLOUD_INSTALL_TGTS}
259
260.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
261vm-release:	${VMTARGETS}
262.else
263vm-release:
264.endif
265
266.if defined(WITH_CLOUDWARE) && !empty(WITH_CLOUDWARE) && !empty(CLOUDWARE)
267cloudware-release:	${CLOUDTARGETS}
268.else
269cloudware-release:
270.endif
271
272.include "${.CURDIR}/Makefile.azure"
273.include "${.CURDIR}/Makefile.ec2"
274.include "${.CURDIR}/Makefile.firecracker"
275.include "${.CURDIR}/Makefile.gce"
276.include "${.CURDIR}/Makefile.vagrant"
277.include "${.CURDIR}/Makefile.inc1"
278