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