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