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