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