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